Bitcoin Forum
May 12, 2024, 04:16:32 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [Solved] Programming Bitcoin , Jimmy Song. ecc.py functions aren't working  (Read 211 times)
SamYezi (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 79


View Profile
January 13, 2022, 07:35:45 PM
Last edit: January 17, 2022, 05:44:30 PM by SamYezi
Merited by hugeblack (4), Welsh (1), ABCbits (1)
 #1

Programming Bitcoin book, Jimmy Song. Chapter 1 ecc.py functions aren't recognized even though the ecc.py (the source file of the functions) is in the same folder as the file in which the Functions are being called
Picture 1: https://i.stack.imgur.com/njYMU.jpg
Picture 2: https://i.stack.imgur.com/ZTg8R.jpg
Picture 3: https://i.stack.imgur.com/nNuTL.jpg
Picture 4: https://i.stack.imgur.com/eje4Q.jpg
The functions are written:
Picture 5: https://i.stack.imgur.com/hLQPM.jpg
Picture 6: https://i.stack.imgur.com/jdEcZ.jpg
Picture 7: https://i.stack.imgur.com/sMnoC.jpg


I start the Jupyter notebook every time by typing these commands in the command prompt
Picture 8: https://i.stack.imgur.com/pSAZa.jpg

Code:
@echo on
cd C:\programmingbitcoin\programmingbitcoin

virtualenv -p C:\programmingbitcoin\programmingbitcoin\.venv\Scripts\python.exe .venv

.venv\Scripts\activate.bat

jupyter notebook
REM DO NOT CLOSE THE COMMAND PROMPT! THAT WOULD SHUTDOWN THE JUPYTER!
pause

and keep the command prompt running

Picture 9: https://i.stack.imgur.com/3VE7D.jpg

as I said, These files are in the same folder
Picture 10: https://i.stack.imgur.com/QX8Ia.jpg

The installation guide to Jupyter Notebook:
https://www.oreilly.com/library/view/programming-bitcoin/9781492031482/preface01.html#setting_up
The book's github:
https://github.com/jimmysong/programmingbitcoin

The steps to installation and starting the Jupyter Notebook I got from that guide

The question is:
What seems to be the problem here?

Why is this question being asked? There's the possibility that the problem may be systematic across the whole repository. To prevent further errors, it would be good to solve everything in advance.
The odd thing is that for the 1st time these functions were working, but after I've restarted the Jupyter notebook, they stopped doing so
The question is also posted on StackOverflow: https://stackoverflow.com/questions/70701871/programming-bitcoin-jimmy-song-ecc-py-functions-arent-working
1715487392
Hero Member
*
Offline Offline

Posts: 1715487392

View Profile Personal Message (Offline)

Ignore
1715487392
Reply with quote  #2

1715487392
Report to moderator
1715487392
Hero Member
*
Offline Offline

Posts: 1715487392

View Profile Personal Message (Offline)

Ignore
1715487392
Reply with quote  #2

1715487392
Report to moderator
1715487392
Hero Member
*
Offline Offline

Posts: 1715487392

View Profile Personal Message (Offline)

Ignore
1715487392
Reply with quote  #2

1715487392
Report to moderator
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5829


not your keys, not your coins!


View Profile WWW
January 13, 2022, 09:25:16 PM
Merited by ABCbits (6), Welsh (4), hugeblack (4)
 #2

Your installation is fine; it all looks like it's running fine.
The errors appear because it's your task to implement the functions so that the tests (who output the errors you're seeing) 'pass'.
As we can see in the code, the __ne__ function is simply not implemented yet and a NotImplementedError error is raised. You are meant to remove this line and implement the function's functionality. That's the whole task here.

Spoiler: Here, in the answers.py file, you can see the solution to the exercise 1:
https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/answers.py#L126

As I suspected, you're meant to simply implement the __ne__ function. So no, there are no systematic errors, it's the whole repo's purpose to give you programming problems to solve, which then result in working tests (and no error messages).

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1596
Merit: 6735


bitcoincleanup.com / bitmixlist.org


View Profile WWW
January 14, 2022, 09:44:39 AM
 #3

In the second picture, it says that test_add() is not defined. You should make sure that function actually exists by running its cell first, if the function is something you meant to write yourself and not copy from a book somewhere.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
ABCbits
Legendary
*
Offline Offline

Activity: 2870
Merit: 7492


Crypto Swap Exchange


View Profile
January 14, 2022, 11:43:36 AM
Merited by hugeblack (4), n0nce (1)
 #4


The errors appear because it's your task to implement the functions so that the tests (who output the errors you're seeing) 'pass'.
As we can see in the code, the __ne__ function is simply not implemented yet and a NotImplementedError error is raised. You are meant to remove this line and implement the function's functionality. That's the whole task here.

FYI, chapter 1 of the book also state you need to open ecc.py to start the exercise. I can see this confuse some people though, since i expected explicit instruction such as "To solve exercise 1, you need to open ecc.py and edit __ne__ function".

You can see this in action in the code that accompanies this book. Once you’ve set up Jupyter Notebook (see [setting_up]), you can navigate to code-ch01/Chapter1.ipynb and run the code to see the results. For the next exercise, you’ll want to open up ecc.py by clicking the link in the Exercise 1 box. If you get stuck, please remember that the answers to every exercise are in [appendix_solutions].



Spoiler: Here, in the answers.py file, you can see the solution to the exercise 1:
https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/answers.py#L126

As I suspected, you're meant to simply implement the __ne__ function. So no, there are no systematic errors, it's the whole repo's purpose to give you programming problems to solve, which then result in working tests (and no error messages).

I can confirm copying the answer to ecc.py (rather than trying add function to imported object) works (passed the test).

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
SamYezi (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 79


View Profile
January 15, 2022, 04:58:19 PM
 #5


The errors appear because it's your task to implement the functions so that the tests (who output the errors you're seeing) 'pass'.
As we can see in the code, the __ne__ function is simply not implemented yet and a NotImplementedError error is raised. You are meant to remove this line and implement the function's functionality. That's the whole task here.

FYI, chapter 1 of the book also state you need to open ecc.py to start the exercise. I can see this confuse some people though, since i expected explicit instruction such as "To solve exercise 1, you need to open ecc.py and edit __ne__ function".

You can see this in action in the code that accompanies this book. Once you’ve set up Jupyter Notebook (see [setting_up]), you can navigate to code-ch01/Chapter1.ipynb and run the code to see the results. For the next exercise, you’ll want to open up ecc.py by clicking the link in the Exercise 1 box. If you get stuck, please remember that the answers to every exercise are in [appendix_solutions].



Spoiler: Here, in the answers.py file, you can see the solution to the exercise 1:
https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/answers.py#L126

As I suspected, you're meant to simply implement the __ne__ function. So no, there are no systematic errors, it's the whole repo's purpose to give you programming problems to solve, which then result in working tests (and no error messages).

I can confirm copying the answer to ecc.py (rather than trying add function to imported object) works (passed the test).

Yeah, I've been aware of ecc.py and answers.py . The functions were implemented into ecc.py from the beginning

To be safe I copied and pasted functions from answers.py into ecc.py . The problem still persists
Picture 1: https://i.stack.imgur.com/Cihsv.jpg
Picture 2: https://i.stack.imgur.com/tlIig.jpg
Picture 3: https://i.stack.imgur.com/gQHf9.jpg

Importing answers.py itself into doesn't do anything
Picture 4: https://i.stack.imgur.com/kHf5w.jpg

Copying and pasting the functions themselves in the program does not help as well
Picture 5: https://i.stack.imgur.com/H89nK.jpg

Sorry for the delayed response



SamYezi (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 79


View Profile
January 15, 2022, 05:12:45 PM
 #6

In the second picture, it says that test_add() is not defined. You should make sure that function actually exists by running its cell first, if the function is something you meant to write yourself and not copy from a book somewhere.

test_ne() test_add() and test_sub() are defined
Picture 1: https://i.stack.imgur.com/ROZ4n.jpg

Unfortunately, they are still not working
Picture 2: https://i.stack.imgur.com/jI4qa.jpg
Picture 3: https://i.stack.imgur.com/LUiAs.jpg


SamYezi (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 79


View Profile
January 15, 2022, 05:33:29 PM
 #7

Your installation is fine; it all looks like it's running fine.
The errors appear because it's your task to implement the functions so that the tests (who output the errors you're seeing) 'pass'.
As we can see in the code, the __ne__ function is simply not implemented yet and a NotImplementedError error is raised. You are meant to remove this line and implement the function's functionality. That's the whole task here.

Spoiler: Here, in the answers.py file, you can see the solution to the exercise 1:
https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/answers.py#L126

As I suspected, you're meant to simply implement the __ne__ function. So no, there are no systematic errors, it's the whole repo's purpose to give you programming problems to solve, which then result in working tests (and no error messages).

I tried to do what you've recommended, but It still doesn't work
The functions are implemented.
Please see my replies above

btw
Sorry for the delayed response
SamYezi (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 79


View Profile
January 17, 2022, 05:43:28 PM
 #8

--snip--
I can confirm copying the answer to ecc.py (rather than trying add function to imported object) works (passed the test).

Yeah, I've been aware of ecc.py and answers.py . The functions were implemented into ecc.py from the beginning

To be safe I copied and pasted functions from answers.py into ecc.py . The problem still persists
Picture 1: https://i.stack.imgur.com/Cihsv.jpg
Picture 2: https[Suspicious link removed]rcise 1 only ask you to edit def __ne__ on ecc.py, so you don't need to modify cell Exercise 1 on Chapter1.ipynb. Just run the cell and see whether you passed the test or not.

https://i.ibb.co/8P9PTjF/111.png

LMAO, this is really a silly mistake  Cheesy Cheesy Cheesy. I thought that I was supposed to call these functions, from ecc.py to Chapter1.ipynb, and then use the functions to solve specific problems.....

but Anyway, the tests are running OK, just like in the screenshot you've provided....

Thanks!!
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5829


not your keys, not your coins!


View Profile WWW
January 19, 2022, 02:58:10 AM
Merited by ABCbits (2)
 #9

I see you solved your issue, however there was one thing I want to point out.
The Python error messages actually tell you a lot about what's going wrong, to the point where I could figure out some of the issues completely statically. One example is where it's telling you that the function __add__ is not defined. We can see in your code that your indents are all over the place, putting the __add__ function within the __ne__ function, so it's invisible (nonexistent) from the outside.
Quote
To be safe I copied and pasted functions from answers.py into ecc.py . The problem still persists
Picture 1: https://i.stack.imgur.com/Cihsv.jpg
Picture 2: https://i.stack.imgur.com/tlIig.jpg
Picture 3: https://i.stack.imgur.com/gQHf9.jpg

Also here, it directly tells you your indent is off and you seem just not to read these error messages. They exist for a reason.
Quote

I think that Jimmy Song here wanted to make readers implement everything in a TDD way, which is a very good idea and teaches learners a lot about the language itself and how to develop cleanly. You make use of the test framework by writing tests beforehand according to spec / concept, then develop until your tests are all 'green'.



Also, it's actually a rule here not to write consecutive posts, but merging them instead, by the way.
32. Posting multiple posts in a row (excluding bumps and reserved posts by the thread starter) is not allowed.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
SamYezi (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 79


View Profile
January 21, 2022, 06:00:37 PM
 #10

I see you solved your issue, however there was one thing I want to point out.
The Python error messages actually tell you a lot about what's going wrong, to the point where I could figure out some of the issues completely statically. One example is where it's telling you that the function __add__ is not defined. We can see in your code that your indents are all over the place, putting the __add__ function within the __ne__ function, so it's invisible (nonexistent) from the outside.
Quote
To be safe I copied and pasted functions from answers.py into ecc.py . The problem still persists
Picture 1: https://i.stack.imgur.com/Cihsv.jpg
Picture 2: https://i.stack.imgur.com/tlIig.jpg
Picture 3: https://i.stack.imgur.com/gQHf9.jpg

Also here, it directly tells you your indent is off and you seem just not to read these error messages. They exist for a reason.
Quote

I think that Jimmy Song here wanted to make readers implement everything in a TDD way, which is a very good idea and teaches learners a lot about the language itself and how to develop cleanly. You make use of the test framework by writing tests beforehand according to spec / concept, then develop until your tests are all 'green'.



Also, it's actually a rule here not to write consecutive posts, but merging them instead, by the way.
32. Posting multiple posts in a row (excluding bumps and reserved posts by the thread starter) is not allowed.


Thank you for the tip!!!!!!!!!!!!!!!!!!!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!