Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error in Example A-2 of First Edition #10

Closed
CavalcanteLucas opened this issue May 13, 2021 · 0 comments
Closed

Runtime error in Example A-2 of First Edition #10

CavalcanteLucas opened this issue May 13, 2021 · 0 comments

Comments

@CavalcanteLucas
Copy link

CavalcanteLucas commented May 13, 2021

I'm trying to run the Example A-2 (page 689) in the First Edition.
I'm not sure if it's something wrong that I'm doing.. but I read the code 10 times. I'm sure it is the same of the book.

I'm running this code as:

$python example_a_2__generate_array.py

where my Python version is 3.8.5. Then I see this error:

initial sample: 10500000 elements
Traceback (most recent call last):
  File "example_a_2__generate_array.py", line 19, in <module>
    with len(sample) < SAMPLE_LEN:
AttributeError: __enter__

Some reasoning:
I'm not reasigning the open function (as suggested here for one possible cause).

Possible solution:
Maybe line 19 should be replaced by:

if len(sample) < SAMPLE_LEN:

I tried that and got a good looking output:

initial sample: 10500000 elements
complete sample: 10500000 elements
not selected: 500000 samples
  writing not_selected.arr
selected: 10000000 samples
  writing selected.arr

And they seem to have been created correctly:

$ls -la *selected*
-rw-rw-r-- 1 lucas lucas  4000000 mai 13 14:57 not_selected.arr
-rw-rw-r-- 1 lucas lucas 80000000 mai 13 14:57 selected.arr

PS.: Thank you for the book and sharing your knowledge!

@CavalcanteLucas CavalcanteLucas changed the title Runtime error in Example A-2 of Second Edition Runtime error in Example A-2 of First Edition May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant