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

Example code issue #52

Closed
tedx opened this issue May 17, 2021 · 3 comments
Closed

Example code issue #52

tedx opened this issue May 17, 2021 · 3 comments

Comments

@tedx
Copy link

tedx commented May 17, 2021

There are several syntax error in some of the example code. Here's a version that works:

import io
import ijson

Open a file

fo = open("foo.txt", "rb")
print ("Name of the file: ", fo.name)

line = fo.read(10)

Close opened file

fo.close()

parse_events = ijson.parse(io.BytesIO(b'["skip", {"a": 1}, {"b": 2}, {"c": 3}]'))
while True:
prefix, event, value = next(parse_events)
if value == "skip":
break
for obj in ijson.items(parse_events, 'item'):
print(obj)

@rtobar
Copy link

rtobar commented May 18, 2021

@tedx your version of the example code seems to be a variation of that under the "Intercepting events" section of the documentation, but I don't think there was any problem with the original. Can you clarify what was the issue? Your version also unnecessarily opens and reads a file, so I don't understand why it's there.

Other code examples in the documentation are "incomplete" in the sense they assume certain functions exist, but the examples are only for demonstration purposes and are not meant to be fully runnable code.

@tedx
Copy link
Author

tedx commented May 19, 2021

The original code cut and pasted from https://github.com/ICRAR/ijson has a syntax error in that there is no colon at the end of:
for obj in ijson.items(parse_events, 'item')
and does not execute. I was just playing with the example and add some unnecessary code I should have been more careful about what I pasted into my original comment.

rtobar added a commit that referenced this issue May 19, 2021
This was reported in #52.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
@rtobar
Copy link

rtobar commented May 19, 2021

@tedx that was pretty clear now, thanks :), I just pushed a fix for that.

@rtobar rtobar closed this as completed May 19, 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

2 participants