Skip to content

FIX py3ing some print statements #3821

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

Merged
merged 2 commits into from
Jun 21, 2013
Merged

Conversation

hayd
Copy link
Contributor

@hayd hayd commented Jun 9, 2013

I just grepped where there was python 2 print statement. There are still some in vbench/scripts/ez_setup and sphinxext/src (as well as in the rst docs), but these are all all from the main codebase.

grep "print [^(]" . -r

I don't know how to deal with the print >>buf, empty etc. (or whether we need to, I've only labelled there's only the two of these).... ?

I found one by trying to use py3 before building, where I got a print e syntax error.

@cpcloud
Copy link
Member

cpcloud commented Jun 9, 2013

print >>buf, empty writes empty to buf (sans newline iirc) so u can translate the call to

buf.write(empty)

i'm not sure if 2to3 catches the print >>buf, empty...i've gotten these syntax errors before and i'm not sure why 2to3 doesn't convert them, probably better to just do what ur doing and replace them...

@cpcloud
Copy link
Member

cpcloud commented Jun 9, 2013

also there are quite a few of these

try:
    lotz_of_teh_codez
except Exception, e:
    moar_codez

which is a syntax error in py3, but somehow they never trigger errors...

@jreback
Copy link
Contributor

jreback commented Jun 9, 2013

I think p to. 3 conversion changes these around so they work
put a pdb right before - they code looks different

@cpcloud
Copy link
Member

cpcloud commented Jun 9, 2013

but for some reason the print e ones don't...but only on occasion...i haven't spent any time investigating. when i uninstalled pandas and then reinstalled (vagrant precise32 box python 3) it worked fine...

@hayd
Copy link
Contributor Author

hayd commented Jun 9, 2013

You'd think it would kick up a fuss immediately on looking at the file, rather than complain when it hits that line... weird.

I'll replace those two lines with buf.write(empty) for "completeness".

@cpcloud
Copy link
Member

cpcloud commented Jun 9, 2013

@hayd can u throw a context manager in there if there isn't one :)

@jtratner
Copy link
Contributor

@cpcloud If you really want to make everything python 3 compatible, try running 2to3 with the -w switch, it'll write everything in place. Then you can see all the places that get changed. You could search for every instance of except in the files and commit them as a change :) When Armin Ronacher began porting Flask, Werkzeug and Jinja2, he decided to make the entire code base compatible with Python 3 without the 2to3 tool (and skipped 3.0 and 3.1 compatibility altogether, because of unicode issues).

@cpcloud
Copy link
Member

cpcloud commented Jun 10, 2013

there's so much annoying crap surrounding the python 2/3 issue. there's also so much extra kludge just to keep things compatible with both versions. and then you have to deal with cases in which the 2to3 tool doesn't work. i wish everyone would just move to python 3 and stop talking about it so that folks could solve real problems. of course most of science python people use 2.7 so that i unrealistic at the moment.

i think probably using function print and not using the cryptic 'print >> file, thing_to_print_to_file' (what are we trying to do here, emulate cat? ;) are reasonable conventions to adopt, i know i always forget about function print cuz i'm so used to using it as a stmt...

@hayd
Copy link
Contributor Author

hayd commented Jun 21, 2013

@cpcloud updated with buf.write should be good to merge...

@hayd
Copy link
Contributor Author

hayd commented Jun 21, 2013

Aaargh the buf.write doesn't work in py3, think I should just drop that, it's clearly being tested anyway (so not needed) - will remove this last commit.

@cpcloud
Copy link
Member

cpcloud commented Jun 21, 2013

what doesn't work?

@hayd
Copy link
Contributor Author

hayd commented Jun 21, 2013

buf.write(empty) as a replacement for print >>buf, empty

but the good news is this was working in python 3 before anyhow (since changing it made previously passing tests fail).

hayd added a commit that referenced this pull request Jun 21, 2013
FIX py3ing some print statements
@hayd hayd merged commit fd34eab into pandas-dev:master Jun 21, 2013
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

Successfully merging this pull request may close these issues.

4 participants