Skip to content

print() builtin uses printf() instead of sys.stdout #209

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

Closed
pfalcon opened this issue Jan 22, 2014 · 4 comments
Closed

print() builtin uses printf() instead of sys.stdout #209

pfalcon opened this issue Jan 22, 2014 · 4 comments

Comments

@pfalcon
Copy link
Contributor

pfalcon commented Jan 22, 2014

Python defines print() in terms of using sys.stdout python object for output (http://docs.python.org/3.3/library/functions.html#print) uPy currently uses libc function printf(). This may lead to different buffering and garbled output.

@dpgeorge
Copy link
Member

Agree. There needs to be a way of doing this in a portable way (that works on unix and stm, for example). That means stm needs to define a sys.stdout object. Probably the best thing to do is provide file descriptors in the stm port with 0,1,2 mapping to std in,out,err as usual. Then the same file code (currently in unix/) can be used.

@pfalcon
Copy link
Contributor Author

pfalcon commented Jan 25, 2014

file descriptors in the stm port with 0,1,2 mapping to std in,out,err as usual.

From Python perspective, no need to use to mimic it down to numbers. Just an object which implements read/write C-level protocol, it can wrap FIL* or some serial object just as well.

Then the same file code (currently in unix/) can be used.
Well, good deal of the code is actually in py/stream.c . With that, and taking unix/file.c, it can be implemented without any double indirection (but with some duplication, but that can be refactored too).

@pfalcon
Copy link
Contributor Author

pfalcon commented Jan 25, 2014

All in all, there's known workaround - just don't mix print() and sys.write(), and good fix will require some thinking (one thought is that ->print() should be provided with both stream interface for efficient out, and printf interface for convenience).

So, this is more of "known issue", not something to work on right away (IMHO).

@pfalcon
Copy link
Contributor Author

pfalcon commented Jul 20, 2014

Resolved.

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