Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 2, 2021. It is now read-only.
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Runtime error in Example A-2 #52

Open
@CavalcanteLucas

Description

@CavalcanteLucas

I'm trying to run theExample 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 is3.8.5. Then I see this error:

initial sample: 10500000 elementsTraceback (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 theopen function (as suggestedhere 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 elementscomplete sample: 10500000 elementsnot selected: 500000 samples  writing not_selected.arrselected: 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp