Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: SamYezi on January 13, 2022, 07:35:45 PM



Title: [Solved] Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: SamYezi on January 13, 2022, 07:35:45 PM
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


Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: n0nce on January 13, 2022, 09:25:16 PM
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 (https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/ecc.py#L24), 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).


Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: NotATether on January 14, 2022, 09:44:39 AM
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.


Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: ABCbits on January 14, 2022, 11:43:36 AM
Picture 1: https://i.stack.imgur.com/njYMU.jpg

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 (https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/ecc.py#L24), 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).


Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: SamYezi on January 15, 2022, 04:58:19 PM
Picture 1: https://i.stack.imgur.com/njYMU.jpg

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 (https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/ecc.py#L24), 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





Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: SamYezi on January 15, 2022, 05:12:45 PM
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




Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: SamYezi on January 15, 2022, 05:33:29 PM
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 (https://github.com/jimmysong/programmingbitcoin/blob/3fba6b992ece443e4256df057595cfbe91edda75/code-ch01/ecc.py#L24), 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


Title: Re: Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: SamYezi on January 17, 2022, 05:43:28 PM
--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  :D :D :D. 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!!


Title: Re: [Solved] Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: n0nce on January 19, 2022, 02:58:10 AM
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
Picture 5: https://i.stack.imgur.com/H89nK.jpg

I think that Jimmy Song here wanted to make readers implement everything in a TDD (https://en.wikipedia.org/wiki/Test-driven_development) 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 (https://bitcointalk.org/index.php?topic=703657.0#post_rules) 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.


Title: Re: [Solved] Programming Bitcoin , Jimmy Song. ecc.py functions aren't working
Post by: SamYezi on January 21, 2022, 06:00:37 PM
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
Picture 5: https://i.stack.imgur.com/H89nK.jpg

I think that Jimmy Song here wanted to make readers implement everything in a TDD (https://en.wikipedia.org/wiki/Test-driven_development) 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 (https://bitcointalk.org/index.php?topic=703657.0#post_rules) 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!!!!!!!!!!!!!!!!!!!