Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 4:49 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: go for the lowest common denominator: print(some single string) which works happily in all versions of Python. Whenever I have used print in my code, it has been with a redirection. Then you're probably not using sys.stdout.write but some other file object's write method. Also, I find it highly unusual that you never use print in its most basic and intended form. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Chris Angelico ros...@gmail.com: Then you're probably not using sys.stdout.write but some other file object's write method. Correct, sys.stderr.write would have been a more accurate choice. Also, I find it highly unusual that you never use print in its most basic and intended form. Printing to the stdout (hardcoded) is a relatively rare need. Mostly, I've used print for diagnostic messages, and whenever I've had to create actual output, I've parameterized the target object. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Friday, March 21, 2014 11:38:42 AM UTC+5:30, Marko Rauhamaa wrote: Chris Angelico : Then you're probably not using sys.stdout.write but some other file object's write method. Correct, sys.stderr.write would have been a more accurate choice. Also, I find it highly unusual that you never use print in its most basic and intended form. Printing to the stdout (hardcoded) is a relatively rare need. Mostly, I've used print for diagnostic messages, and whenever I've had to create actual output, I've parameterized the target object. Hear Hear! Ive no opinion on whether python 2 or 3 print is better. However I believe that people trying to help noobs would be actually more helpful if they indicated that using prints all over code is not kosher. Then whats the use/sense of print?? Debugging... -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 21/03/2014 02:18, Chris Angelico wrote: On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith r...@panix.com wrote: In article 532b8f0d$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The rule of three applies here: anything you do in three different places ought to be managed by a function. I prefer the rule of two :-) The way I explain it is: Three is a rule of thumb. Sometimes it's blatantly obvious at two, and other times you need four or five similar pieces of code before you can see which part should become the function. If the code's absolutely identical and reasonably long/complex, then yes, two's all you need, but how often is that? Usually it's similar, rather than congruent... err I mean identical. That's where the third usage comes in. Or if it's maybe 2-3 lines, used in two places, it doesn't necessarily need to be a function. Again, a third usage is a strong hint that it should be broken out. The rule doesn't say that anything that *isn't* in three places yet should *not* be broken out. :) ChrisA Everybody, and especially Antipodeans, knows that there is no rule 6 and by definition what rule 7 is :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, 21 Mar 2014 09:40:40 +, Mark Lawrence wrote: On 21/03/2014 02:18, Chris Angelico wrote: On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith r...@panix.com wrote: In article 532b8f0d$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The rule of three applies here: anything you do in three different places ought to be managed by a function. I prefer the rule of two :-) The way I explain it is: Three is a rule of thumb. Sometimes it's blatantly obvious at two, and other times you need four or five similar pieces of code before you can see which part should become the function. If the code's absolutely identical and reasonably long/complex, then yes, two's all you need, but how often is that? Usually it's similar, rather than congruent... err I mean identical. That's where the third usage comes in. Or if it's maybe 2-3 lines, used in two places, it doesn't necessarily need to be a function. Again, a third usage is a strong hint that it should be broken out. The rule doesn't say that anything that *isn't* in three places yet should *not* be broken out. :) ChrisA Everybody, and especially Antipodeans, knows that there is no rule 6 and by definition what rule 7 is :) Im sticking with rule 4 -- https://mail.python.org/mailman/listinfo/python-list
running python 2 vs 3
Dumb noob questions: I've installed python 3.3 on my Slack box, which by default comes with python 2.7. I know how to fire up the different IDLE environments, but how do I differentiate between the scripts? IOW, up till now, I've used .py on all my 2.7 files. How do I know not to run a .py in python3 or visa versa? Or do I? What's the excepted convention for differentiating between the two? nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
notbob not...@nothome.com: I've installed python 3.3 on my Slack box, which by default comes with python 2.7. I know how to fire up the different IDLE environments, but how do I differentiate between the scripts? IOW, up till now, I've used .py on all my 2.7 files. How do I know not to run a .py in python3 or visa versa? Or do I? What's the excepted convention for differentiating between the two? That's a bit of a sore spot. On a linux box, the initial line of the script indicates the interpreter: #!/usr/bin/env python2 for Python 2.x #!/usr/bin/env python3 for Python 3.x. All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 2014-03-20, Marko Rauhamaa ma...@pacujo.net wrote: That's a bit of a sore spot. On a linux box, the initial line of the script indicates the interpreter: #!/usr/bin/env python2 for Python 2.x #!/usr/bin/env python3 for Python 3.x. All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. Ahhh! now a shabang I understand. So, I guess the only way, short of looking at the actual file, is to include the version in the filename. Can I safely assume I can run all 2.7 files w/o a shebang (which I have not, so far, and was wondering how I got away with that) and only include a py3 shebang in the py3 files, yes/no? nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 9:58 AM, notbob wrote: I've installed python 3.3 on my Slack box, which by default comes with python 2.7. I know how to fire up the different IDLE environments, but how do I differentiate between the scripts? hi notbob, the two (or more) IDLE environments run very nicely side-by-side. If you access your scripts from the same directory (I do not) there really is no problem. The reason is that the .pyc files created for python2.x are only used by python2. The .pyc files for python3.x are kept (by a naming convention) in __pycache__ , so there really is no problem. Having said that, the only problem is that your script for python3 might not run in python2 (for various reasons) but the problem is not that the scripts are contained in the same folder. I keep my python2 scripts in one folder ~/Documents/Python2/ and my python3 scripts in another one ~/Documents/Python3/ I add the two folders in the python paths browser (using site-packages) so that when I start IDLE for python2 it pulls its scripts from ~/Documents/Python2/ and when I start IDLE for python3 it pulls its scripts from ~/Documents/Python3/ There are *many* ways to organize this. Often I have to maintain two scripts (packages) one for each version. Although, I try to make my scripts run in both environments. Often I have IDLE(2) ane IDLE(3) running and testing at the same time on the same box. This works very well. marcus -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, Mar 20, 2014 at 11:00 AM, notbob not...@nothome.com wrote: Ahhh! now a shabang I understand. So, I guess the only way, short of looking at the actual file, is to include the version in the filename. Can I safely assume I can run all 2.7 files w/o a shebang (which I have not, so far, and was wondering how I got away with that) and only include a py3 shebang in the py3 files, yes/no? If I understand your question: you're probably better off putting a shebang line in all of the files that you intend to run directly. Use /usr/bin/env python2 for your Python 2 scripts, /usr/bin/env python3 for your Python 3 scripts, and /usr/bin/env python for scripts that can run under either interpreter. You can also be more version-specific if you need to; use python2.7, python3.3, etc. as necessary. That way, you can invoke the script directly and the right interpreter will run it. If you're specifying the interpreter in your command (by calling python scriptname.py, etc), the shebang won't mean anything anyway. -- Zach -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 2014-03-20, Zachary Ware zachary.ware+pyl...@gmail.com wrote: If you're specifying the interpreter in your command (by calling python scriptname.py, etc), the shebang won't mean anything anyway. DOH! I was following you, fine, until that last sentence. Then how should I invoke the scripts? as your example is exactly how I've been doing it with 2.7, as per Learn Python the Hard Way. Simply ./scriptname.py from the appropriate directory (assuming I keep both vers in separate dirs)? nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 2014-03-20, Mark H Harris harrismh...@gmail.com wrote: not) there really is no problem. The reason is that the .pyc files created for python2.x are only used by python2. Lordy, what hath I wrought!? ;) What the heck is a .pyc file and how are they created? Actually, I can see it's a compiled binary, but I where did it come from? I went back to my ~/python/ dir and noticed one .pyc file out of 15 .py files I created from following Learning Python the Hard Way. No one said anything about creating a binary. I know I discovered how to create/edit python scripts from IDLE. Is that it? I've been using gedit and emacs up till now. Seems the file with the .pyc file is the one I edited in IDLE. Is that why LPtHW eschews IDLE for gedit? Why do I feel like I've really stepped in it? ;) nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 4:23 AM, notbob not...@nothome.com wrote: On 2014-03-20, Mark H Harris harrismh...@gmail.com wrote: not) there really is no problem. The reason is that the .pyc files created for python2.x are only used by python2. Lordy, what hath I wrought!? ;) What the heck is a .pyc file and how are they created? Actually, I can see it's a compiled binary, but I where did it come from? I went back to my ~/python/ dir and noticed one .pyc file out of 15 .py files I created from following Learning Python the Hard Way. No one said anything about creating a binary. I know I discovered how to create/edit python scripts from IDLE. Is that it? I've been using gedit and emacs up till now. Seems the file with the .pyc file is the one I edited in IDLE. Is that why LPtHW eschews IDLE for gedit? Why do I feel like I've really stepped in it? ;) You should be able to completely ignore .pyc files, most of the time. The only thing to remember is that you should delete them any time you delete the corresponding .py files. They're a cached version that Python will use to speed up imports, nothing more. Nowadays they'll be pushed away into a separate directory, which makes them easier for you to ignore. This is a good thing. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 4:10 AM, notbob not...@nothome.com wrote: On 2014-03-20, Zachary Ware zachary.ware+pyl...@gmail.com wrote: If you're specifying the interpreter in your command (by calling python scriptname.py, etc), the shebang won't mean anything anyway. DOH! I was following you, fine, until that last sentence. Then how should I invoke the scripts? as your example is exactly how I've been doing it with 2.7, as per Learn Python the Hard Way. Simply ./scriptname.py from the appropriate directory (assuming I keep both vers in separate dirs)? That's a fine way to do it. Zachary is mentioning an alternative, and showing that the shebang doesn't hurt (it's a comment to Python), so go ahead and put the shebang in all your scripts. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 12:23 PM, notbob wrote: What the heck is a .pyc file and how are they created? Actually, I can see it's a compiled binary, but I where did it come from? The world according to me: python is an interpreter (vs compiler) which converts your source code into tokens and then into a bytecode. The process takes time. So, the solution is to place the tokenized stuff into a .pyc file so that the process does not have to be repeated unless, of course, the source has changed since the last .pyc file create. It used to be that the .pyc files went into the same dir as the source (that's how it works for python2) but now with python3 they go into a directory in your source tree called __pycache__, and they are named based on python version (a way better scheme for sure). If you wanted to you could run your python scripts from the .pyc file alone. In other words, you may import as long as the .pyc file exists and the source does not need to be there. Some folks use this (not recommended) trick to hide or obfuscate their source from their users). marcus -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Chris Angelico ros...@gmail.com: Nowadays they'll be pushed away into a separate directory, which makes them easier for you to ignore. This is a good thing. Still, I don't think Python should go and soil my directories without an explicit permission. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Mark H Harris harrismh...@gmail.com: If you wanted to you could run your python scripts from the .pyc file alone. In other words, you may import as long as the .pyc file exists and the source does not need to be there. Some folks use this (not recommended) trick to hide or obfuscate their source from their users). I've seen it done, but at least in those Python 2 days the pyc format changed between minor releases of Python, so Python itself had to be shipped with the pyc files. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 03/20/2014 10:10 AM, notbob wrote: On 2014-03-20, Zachary Ware zachary.ware+pyl...@gmail.com wrote: If you're specifying the interpreter in your command (by calling python scriptname.py, etc), the shebang won't mean anything anyway. DOH! I was following you, fine, until that last sentence. Then how should I invoke the scripts? as your example is exactly how I've been doing it with 2.7, as per Learn Python the Hard Way. Simply ./scriptname.py from the appropriate directory (assuming I keep both vers in separate dirs)? nb If you mark your script as executable (chmod ...) and include the shebang line, and place it in a directory included in your search path (mine is ~/bin), then you run it as you run any installed program: Just type it's name followed by any command line args. I usually remove the .py portion of the name as I copy it into my bin directory so it really does look like any other installed program. If you need to be in a specific directory when you run it, then perhaps you should consider a bit of a rewrite to remove this constraint. Gary Herron -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 1:47 PM, Marko Rauhamaa wrote: Mark H Harris harrismh...@gmail.com: If you wanted to you could run your python scripts from the .pyc file alone. In other words, you may import as long as the .pyc file exists and the source does not need to be there. Some folks use this (not recommended) trick to hide or obfuscate their source from their users). I've seen it done, but at least in those Python 2 days the pyc format changed between minor releases of Python, so Python itself had to be shipped with the pyc files. Python3 still makes no guarantees about the compatibility of bytecode (and therefore .pyc files) across versions of Python, so if you want to run from pure .pyc files, you have to be sure to use the same version of Python that produced the files. --Ned. Marko -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 20/03/2014 15:21, Marko Rauhamaa wrote: notbob not...@nothome.com: I've installed python 3.3 on my Slack box, which by default comes with python 2.7. I know how to fire up the different IDLE environments, but how do I differentiate between the scripts? IOW, up till now, I've used .py on all my 2.7 files. How do I know not to run a .py in python3 or visa versa? Or do I? What's the excepted convention for differentiating between the two? That's a bit of a sore spot. On a linux box, the initial line of the script indicates the interpreter: #!/usr/bin/env python2 for Python 2.x #!/usr/bin/env python3 for Python 3.x. All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. Marko The above is also true on windows via the 'Python launcher for windows' see http://legacy.python.org/dev/peps/pep-0397/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
In bp0lohf7aq...@mid.individual.net notbob not...@nothome.com writes: On 2014-03-20, Zachary Ware zachary.ware+pyl...@gmail.com wrote: If you're specifying the interpreter in your command (by calling python scriptname.py, etc), the shebang won't mean anything anyway. DOH! I was following you, fine, until that last sentence. Then how should I invoke the scripts? as your example is exactly how I've been doing it with 2.7, as per Learn Python the Hard Way. Simply ./scriptname.py from the appropriate directory (assuming I keep both vers in separate dirs)? There are two ways (at least!) to run a python script: 1. Execute the python interpreter manually, supplying the python script name as an arugment, like so: python myscript.py python2 otherscript.py python3 yetanotherscript.py This lets you choose on-the-fly which version of python is being used to interpret the script. 2. Execute the python script directly by just typing its name, like so: myscript.py ./otherscript.py /other/directory/yetanotherscript.py Depending on your operating system, this may require: a. Permissions on the script file be set to allow execution; b. A 'shebang' entry as the first line in the file which specifies the program that shall be executed; -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Le 20/03/2014 16:21, Marko Rauhamaa a écrit : All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. With Arch-Linux, python is python3... -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 12:47 PM, Marko Rauhamaa wrote: I've seen it done, but at least in those Python 2 days the pyc format changed between minor releases of Python, so Python itself had to be shipped with the pyc files. hi Marko, yeah, I have not done this; being that the concept is contrary to my principles and sensibilities these days. So, 1) no intellectual property 2) no software idea patents 3) no obfuscated code 4) ship the source, or don't ship anything/ In my view coding (and all other aspects of computer science including software engineering) is a liberal art; it should be open, free (libre), and available to everyone. People learn best by doing, and the do best by reading what others have done before them. marcus -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/2014 11:21 AM, Marko Rauhamaa wrote: On a linux box, the initial line of the script indicates the interpreter: #!/usr/bin/env python2 for Python 2.x #!/usr/bin/env python3 for Python 3.x. All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. Marko I presume it would still be a good idea to test both python interpreters against any script that you didn't knowingly write with a feature that will only work in one of the two python versions. If it works fine in both - and many will, then use: #!/usr/bin/env python Only use the python2 or python3 versions if you really have a reason to do so. Yes? No? Alan -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Alan Meyer amey...@yahoo.com: I presume it would still be a good idea to test both python interpreters against any script that you didn't knowingly write with a feature that will only work in one of the two python versions. If it works fine in both - and many will, then use: #!/usr/bin/env python Only use the python2 or python3 versions if you really have a reason to do so. Yes? No? No. Even if you managed to do that, it would mean getting the worst of both worlds. The language dialects are too far apart. When you start your Python project, you decide between Python 2 and Python 3 and go all in. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 2:53 PM, Alan Meyer wrote: #!/usr/bin/env python Only use the python2 or python3 versions if you really have a reason to do so. It gets tricky for distribution (you need docs for your distros, imho) because #!/usr/bin/env python means different things on different systems. I actually have three major versions of python2 and 2 major versions of python3 on my primary system at this point. On my machine python2.6 is python. That is because that system shipped with 2.6 and many of the subsystem stuff depends on python2.6 / When I call python2 that means python2.7.6 / When I call python3 that means python3.3.4 / I can also call python2.7, which is 2.7.2 / You get the idea. There is no one set rule, because there are many distros (gnu/linux) that use python at various versions, and they all us different setups. Really , you need an install script to snoop out the configurables. marcus -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 20/03/2014 20:08, Marko Rauhamaa wrote: Alan Meyer amey...@yahoo.com: I presume it would still be a good idea to test both python interpreters against any script that you didn't knowingly write with a feature that will only work in one of the two python versions. If it works fine in both - and many will, then use: #!/usr/bin/env python Only use the python2 or python3 versions if you really have a reason to do so. Yes? No? No. Even if you managed to do that, it would mean getting the worst of both worlds. The language dialects are too far apart. When you start your Python project, you decide between Python 2 and Python 3 and go all in. Marko I do not agree that the dialects are too far apart, not that it really matters. There are several libraries available to enable code to run under both versions. The starter is 2to3 which had been in the standard library for what seems like an eternity to me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 3:07 PM, Eric Jacoboni wrote: Le 20/03/2014 16:21, Marko Rauhamaa a écrit : All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. With Arch-Linux, python is python3... Yes, and they have been told many times that this was foolish and wrong, but it persists, much to our pain. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 4:08 PM, Marko Rauhamaa wrote: Alan Meyer amey...@yahoo.com: I presume it would still be a good idea to test both python interpreters against any script that you didn't knowingly write with a feature that will only work in one of the two python versions. If it works fine in both - and many will, then use: #!/usr/bin/env python Only use the python2 or python3 versions if you really have a reason to do so. Yes? No? No. Even if you managed to do that, it would mean getting the worst of both worlds. The language dialects are too far apart. When you start your Python project, you decide between Python 2 and Python 3 and go all in. Plenty of people have adopted a dual-support strategy, with one code base that supports both Python 2 and Python 3. The six module can help a great deal with this. Marko -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Mark Lawrence breamore...@yahoo.co.uk: The starter is 2to3 which had been in the standard library for what seems like an eternity to me. No problem there. It helps you transition from python2 to python3. However, python3 is here and you should be able to write genuine python3 code with the appropriate bytes and string facilities. It would be very confusing to try to mix the two regimes. I must say, though, that Python3 destroyed print forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, Mar 20, 2014 at 8:21 AM, Marko Rauhamaa ma...@pacujo.net wrote: notbob not...@nothome.com: I've installed python 3.3 on my Slack box, which by default comes with python 2.7. I know how to fire up the different IDLE environments, but how do I differentiate between the scripts? IOW, up till now, I've used .py on all my 2.7 files. How do I know not to run a .py in python3 or visa versa? Or do I? What's the excepted convention for differentiating between the two? That's a bit of a sore spot. On a linux box, the initial line of the script indicates the interpreter: #!/usr/bin/env python2 for Python 2.x #!/usr/bin/env python3 for Python 3.x. All tutorials will tell you to start it with #!/usr/bin/env python Actually, I formerly used /usr/bin/env, but have recently (within the last couple of years) stopped. This is because the env trick doesn't play nicely with top IME. Also, it's a trick. -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, Mar 20, 2014 at 3:30 PM, Marko Rauhamaa ma...@pacujo.net wrote: I must say, though, that Python3 destroyed print forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. To each their own :). I can't stand using 'print' as a statement. It's a very nice trick to be able to write a script, think oh, all those prints should really be sending that output somewhere else, and then instead of changing every individual print, just define a different 'print' function at the top of the file (which may be as simple as `print = functools.partial(print, file=sys.stderr)` or `print = logging.debug`). -- Zach -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Ned Batchelder n...@nedbatchelder.com: Plenty of people have adopted a dual-support strategy, with one code base that supports both Python 2 and Python 3. The six module can help a great deal with this. I wonder how easy the resulting code is to the eyes and how easy it is for the casual maintainer to accidentally break the delicate balance. In a word, I wouldn't go there. Stay with Python2 as long as you must and then, migrate and leave it behind. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 20/03/2014 20:30, Marko Rauhamaa wrote: Mark Lawrence breamore...@yahoo.co.uk: The starter is 2to3 which had been in the standard library for what seems like an eternity to me. No problem there. It helps you transition from python2 to python3. However, python3 is here and you should be able to write genuine python3 code with the appropriate bytes and string facilities. It would be very confusing to try to mix the two regimes. I must say, though, that Python3 destroyed print forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. Not for me, I was using from __future__ import print_function for years so got used to typing those two extra brackets, plus print very kindly inserts the newlines for me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Dan Stromberg drsali...@gmail.com: Actually, I formerly used /usr/bin/env, but have recently (within the last couple of years) stopped. This is because the env trick doesn't play nicely with top IME. Also, it's a trick. I'm not sure I like it either, but it's a standard idiom in Pythonland. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 4:42 PM, Marko Rauhamaa wrote: Ned Batchelder n...@nedbatchelder.com: Plenty of people have adopted a dual-support strategy, with one code base that supports both Python 2 and Python 3. The six module can help a great deal with this. I wonder how easy the resulting code is to the eyes and how easy it is for the casual maintainer to accidentally break the delicate balance. In a word, I wouldn't go there. Stay with Python2 as long as you must and then, migrate and leave it behind. This is fine advice for applications, but tools, libraries, and frameworks may want to support more than one version at the same time. It's an extreme case, but the latest released version of coverage.py supports Python 2.3 through 3.3 with one code base. To do it, there's a compatibility layer (akin to six). Then you stay away from features that aren't available on all versions. In a few places, you might need to have version checks, and the code can get a little idiomatic to continue to work. It's a tradeoff: you have to decide for yourself whether the effort is worth the benefit. I was glad to be able to drop support for 2.3, 2.4, and 2.5, and now only support 2.6-3.4 in coverage.py. Marko -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Mark Lawrence breamore...@yahoo.co.uk: On 20/03/2014 20:30, Marko Rauhamaa wrote: I must say, though, that Python3 destroyed print forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. Not for me, I was using from __future__ import print_function for years so got used to typing those two extra brackets, plus print very kindly inserts the newlines for me. That very realization helped me wean myself from print. Its sole raison d'être is the insertion of the newline, which it would be nicer to micromanage anyway; that's how it's done in other programming languages as well: C, perl, guile, ... (Well, ok, echo is the exception.) Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Ned Batchelder n...@nedbatchelder.com: It's an extreme case, but the latest released version of coverage.py supports Python 2.3 through 3.3 with one code base. To do it, there's a compatibility layer (akin to six). Then you stay away from features that aren't available on all versions. In a few places, you might need to have version checks, and the code can get a little idiomatic to continue to work. Well, with proper care, I suppose the same code base could support perl as well. ;) Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, Mar 20, 2014 at 1:59 PM, Marko Rauhamaa ma...@pacujo.net wrote: Well, with proper care, I suppose the same code base could support perl as well. ;) Go even farther; how about C, PHP, and bash? I'm sure if you tried, you could mix in some Python as well. http://en.wikipedia.org/wiki/Polyglot_(computing) Chris -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 2014-03-20, Mark H Harris harrismh...@gmail.com wrote: When I call python2 that means python2.7.6 / When I call python3 that means python3.3.4 / I can also call python2.7, which is 2.7.2 / You get the idea. There is no one set rule, because there are many distros (gnu/linux) that use python at various versions, and they all us different setups. Really , you need an install script to snoop out the configurables. Weeping Chryst on the cross!!. No wonder the latest O'Reilly book, Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python is easy. ;) nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 4:59 PM, Marko Rauhamaa wrote: Ned Batchelder n...@nedbatchelder.com: It's an extreme case, but the latest released version of coverage.py supports Python 2.3 through 3.3 with one code base. To do it, there's a compatibility layer (akin to six). Then you stay away from features that aren't available on all versions. In a few places, you might need to have version checks, and the code can get a little idiomatic to continue to work. Well, with proper care, I suppose the same code base could support perl as well. ;) I'm not sure how to take this comment. I feel like you are mocking my choice. I wanted to make coverage.py available to as broad an audience as possible, something that I think is worthwhile. Yes, there was an engineering cost, but the tradeoff was worth it. Marko -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 2014-03-20, Ned Batchelder n...@nedbatchelder.com wrote: On 3/20/14 3:07 PM, Eric Jacoboni wrote: With Arch-Linux, python is python3... Yes, and they have been told many times that this was foolish and wrong, but it persists, much to our pain. I've read that 2.7 is the defacto std for python (default on Slack 14.1). I installed py3 on Slack box cuz I'd gotten the little Programming the Raspberry Pi book, which is a pretty good lil' book, clarifying many confusing (to me) python issues. Only prob is, it's fer python 3x. I guess I coulda kept the two platforms separate, but then raspi has 2X and 3x, also, so I guess I need to get this issue straight in my feeble geezer head, right outta the gate. I'm plum grateful to all you kind folks who are taking the time to educate this slow ol' curmudgeon. ;) nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 20/03/2014 20:50, Marko Rauhamaa wrote: Mark Lawrence breamore...@yahoo.co.uk: On 20/03/2014 20:30, Marko Rauhamaa wrote: I must say, though, that Python3 destroyed print forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. Not for me, I was using from __future__ import print_function for years so got used to typing those two extra brackets, plus print very kindly inserts the newlines for me. That very realization helped me wean myself from print. Its sole raison d'être is the insertion of the newline, which it would be nicer to micromanage anyway; that's how it's done in other programming languages as well: C, perl, guile, ... (Well, ok, echo is the exception.) Marko The end keyword argument to the print function defaults to newline but you can make it anything you like, see http://docs.python.org/3/library/functions.html#print -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 4:28 PM, notbob wrote: No wonder the latest O'Reilly book, Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python is easy. ;) nb Python is easy, but its not simple. Python is elegant, and full of art, but it has no paucity of constructs, types, and opportunities for confusion. My goal for designing SimplyPy (for instance)is to present the beautiful heart of python (as Mark Summerfield calls it) and subsume the complexities of the fulness of python within a simple interface, BUT without limiting it. Python is easy enough to teach children (I've done it), but its complete and elegant enough for the most scientific of professionals. You do not need to know the fulness of python in order to use it. It is possible (even elegant) to use python (in a Rexx style) not at all recognized as pythonized code, and yet very very simple and powerful. The beauty of python, in my view, is the flexibility and extensibility of the namespace with something more than the minimalist approach of Lisp, BUT with the elegance of the language called python. Get Mark Summerfield's Programming Python 3. Its really quite good, and in my opinion better that the O'Reilly book, especially for new users. Just an opinion of course. marcus -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/2014 1:23 PM, notbob wrote: What the heck is a .pyc file and how are they created? .pyc contained compiled bytecode. They are created when, and only when, you import a module. Imported library files are often big and stable, so their compiled forms get cached. Top-level scripts are typically short and often volotile. They may be as short as from start import run; run() in order to have as much as possible stored in compiled form. This has nothing to do with Idle. I went back to my ~/python/ dir and noticed one .pyc file out of 15 .py files I created from following Learning Python the Hard Way. That must be the only one you imported. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/2014 3:07 PM, John Gordon wrote: There are two ways (at least!) to run a python script: 1. Execute the python interpreter manually, supplying the python script name as an arugment, like so: python myscript.py python2 otherscript.py python3 yetanotherscript.py This lets you choose on-the-fly which version of python is being used to interpret the script. 2. Execute the python script directly by just typing its name, like so: myscript.py ./otherscript.py /other/directory/yetanotherscript.py Depending on your operating system, this may require: a. Permissions on the script file be set to allow execution; b. A 'shebang' entry as the first line in the file which specifies the program that shall be executed; c. An association between '.py' and some version of python. 3. Use the python launcher py.exe with version selection. py -2 myscript.py py -3 myscript.py As far as I know, this is only for Windows at present. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 03/20/2014 11:10 AM, notbob wrote: On 2014-03-20, Zachary Ware zachary.ware+pyl...@gmail.com wrote: If you're specifying the interpreter in your command (by calling python scriptname.py, etc), the shebang won't mean anything anyway. DOH! I was following you, fine, until that last sentence. Then how should I invoke the scripts? as your example is exactly how I've been doing it with 2.7, as per Learn Python the Hard Way. Simply ./scriptname.py from the appropriate directory (assuming I keep both vers in separate dirs)?' If you want to run a script with python3, just invoke the python3 interpreter: python3 blah.py -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
notbob not...@nothome.com: Weeping Chryst on the cross!!. No wonder the latest O'Reilly book, Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python is easy. ;) It's not that bad. There are two principal dialects: python2 and python3. Take the oldest python version you have to support and write your code for that version. Python documentation carefully explains what language and library facilities are available in whichever version. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 2014-03-20, Terry Reedy tjre...@udel.edu wrote: That must be the only one you imported. So it is. Thank you. nb -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Ned Batchelder n...@nedbatchelder.com: On 3/20/14 4:59 PM, Marko Rauhamaa wrote: Well, with proper care, I suppose the same code base could support perl as well. ;) I'm not sure how to take this comment. I feel like you are mocking my choice. I wanted to make coverage.py available to as broad an audience as possible, something that I think is worthwhile. Yes, there was an engineering cost, but the tradeoff was worth it. I can't judge if your particular choice was the right one. My only point is that python2 and python3 are so far apart as to be regarded as independent languages. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, 20 Mar 2014 22:30:57 +0200, Marko Rauhamaa wrote: To avoid nausea, I write sys.stdout.write() in all Python3 code. Now that's funny. I-know-I-shouldn't-respond-to-obvious-trolling-but-I-can't-help-myself-ly yrs, -- Steven D'Aprano -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 20/03/2014 22:23, Marko Rauhamaa wrote: Ned Batchelder n...@nedbatchelder.com: On 3/20/14 4:59 PM, Marko Rauhamaa wrote: Well, with proper care, I suppose the same code base could support perl as well. ;) I'm not sure how to take this comment. I feel like you are mocking my choice. I wanted to make coverage.py available to as broad an audience as possible, something that I think is worthwhile. Yes, there was an engineering cost, but the tradeoff was worth it. I can't judge if your particular choice was the right one. My only point is that python2 and python3 are so far apart as to be regarded as independent languages. And I still say this is complete nonsense. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 7:08 AM, Marko Rauhamaa ma...@pacujo.net wrote: Alan Meyer amey...@yahoo.com: I presume it would still be a good idea to test both python interpreters against any script that you didn't knowingly write with a feature that will only work in one of the two python versions. If it works fine in both - and many will, then use: #!/usr/bin/env python Only use the python2 or python3 versions if you really have a reason to do so. Yes? No? No. Even if you managed to do that, it would mean getting the worst of both worlds. The language dialects are too far apart. When you start your Python project, you decide between Python 2 and Python 3 and go all in. They're not that far apart. It's not difficult to write code that runs happily on both. However, it does mean you can't take advantage of Python 3 features, so it's probably better to write for one or the other, unless you specifically want wide distribution. For your own projects, just put whichever you need. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 9:23 AM, Marko Rauhamaa ma...@pacujo.net wrote: Ned Batchelder n...@nedbatchelder.com: On 3/20/14 4:59 PM, Marko Rauhamaa wrote: Well, with proper care, I suppose the same code base could support perl as well. ;) I'm not sure how to take this comment. I feel like you are mocking my choice. I wanted to make coverage.py available to as broad an audience as possible, something that I think is worthwhile. Yes, there was an engineering cost, but the tradeoff was worth it. I can't judge if your particular choice was the right one. My only point is that python2 and python3 are so far apart as to be regarded as independent languages. They're definitely not independent languages. The biggest change is str/unicode-bytes/str, and you can get part of that in Python 2.6/2.7 with from __future__ import unicode_literals. You may still run into problems with some functions that expect str and won't take unicode (or vice versa), but it's easy to make code that runs across both versions that way. Then toss in from __future__ import print_function and happily use the expanded features of print, or go for the lowest common denominator: print(some single string) which works happily in all versions of Python. I've written code that runs on 2.6+/3.2+. (Or maybe it's 3.1+; whichever version Debian Squeeze ships with.) It's pretty easy. It's certainly a lot easier than writing code that runs as either Pike or C++, for instance. THOSE are independent languages. (And yes, I've written that sort of code. Had a #define block up the top to handle some naming differences, and then restricted myself to a *really* narrow set of common operations. Was a neat way to prove correctness, though.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, 20 Mar 2014 21:28:43 +, notbob wrote: On 2014-03-20, Mark H Harris harrismh...@gmail.com wrote: When I call python2 that means python2.7.6 / When I call python3 that means python3.3.4 / I can also call python2.7, which is 2.7.2 / You get the idea. There is no one set rule, because there are many distros (gnu/linux) that use python at various versions, and they all us different setups. Really , you need an install script to snoop out the configurables. Weeping Chryst on the cross!!. No wonder the latest O'Reilly book, Learning Python, 5th ed, is 1600 pgs. I coulda swore someone sed python is easy. ;) This has nothing to do with Python. It has to do with the way executables (applications) are mapped to file names on Unix and Unix-like systems. And that in turn is not terribly different from the way that it works on Windows as well. When you type python at the command prompt, your system locates an executable named python, then runs it. If you wanted to be annoying, you could alias or link the python name to a completely different language. Or use a different name altogether: steve@orac:~$ alias snake=python steve@orac:~$ snake Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type help, copyright, credits or license for more information. This has nothing to do with Python, it's the way Linux works. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, 20 Mar 2014 16:26:39 -0400, Ned Batchelder wrote: On 3/20/14 3:07 PM, Eric Jacoboni wrote: Le 20/03/2014 16:21, Marko Rauhamaa a écrit : All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. With Arch-Linux, python is python3... Yes, and they have been told many times that this was foolish and wrong, but it persists, much to our pain. How bizarre. I've been looking forward with great pleasure to Fedora moving to Python 3 as the standard system Python, expecting that this move from one of the big distros will start a chain reaction of others doing the same thing. Perhaps Arch-Linux is guilty of being prematurely Python 3, a little like those people hauled up to explain themselves to the House Unamerican Activities Committee to explain why they were a premature anti-fascist. I have no idea what our pain you are referring to, or who our refers to. In the three or five years or so since Arch-Linux moved to Python 3 by default, I don't recall ever seeing even a single email from somebody confused by Arch-Linux's move, not here, or on the tutor mailing list, or on Python-Dev or Python-Ideas. Nor have I seen any signs of difficulty or confusion on Python-related blogs, or StackOverflow. That's not to say that there has been absolutely none at all. The Internet is a big place, and I daresay I've missed something. But given how small the Arch-Linux share of the Linux space is, I would be astonished if their move caused more than a tiny little ripple. Perhaps a paper-cut worth of pain. I expect that there have been far more angry words written over this issue than the actual consequences of the move itself. Unless you're in the unfortunate situation of having to migrate and maintain scripts across a network of mixed Linux distros including some that are Arch-Linux, it's difficult to see exactly what pain they could be causing even in principle. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, 20 Mar 2014 16:53:25 -0400, Ned Batchelder wrote: On 3/20/14 4:42 PM, Marko Rauhamaa wrote: Ned Batchelder n...@nedbatchelder.com: Plenty of people have adopted a dual-support strategy, with one code base that supports both Python 2 and Python 3. The six module can help a great deal with this. I wonder how easy the resulting code is to the eyes and how easy it is for the casual maintainer to accidentally break the delicate balance. In a word, I wouldn't go there. Stay with Python2 as long as you must and then, migrate and leave it behind. This is fine advice for applications, but tools, libraries, and frameworks may want to support more than one version at the same time. +1 Actually, even applications may want to support multiple versions. If I have a Python script that does something, I might not want to tie it to one specific version. In principle there's not much difference between this will run under Python 2.6 and 2.7 and this will run under Python 2.7 and 3.3. In practice, it's a little trickier to cross the 2/3 barrier than the 2.6/2.7 barrier. But it is still quite achievable, with a little extra effort. But you know that even better than I -- I take my hat off to you for supporting all the way back to Python 2.3, that is far more dedicated than I am. In my experience, such as it is, the hard part about writing code that works from 2.4 to 3.4 is not the 3 versions but the 2.4 and 2.5 versions. It's an extreme case, but the latest released version of coverage.py supports Python 2.3 through 3.3 with one code base. To do it, there's a compatibility layer (akin to six). Then you stay away from features that aren't available on all versions. In a few places, you might need to have version checks, and the code can get a little idiomatic to continue to work. It's a tradeoff: you have to decide for yourself whether the effort is worth the benefit. I was glad to be able to drop support for 2.3, 2.4, and 2.5, and now only support 2.6-3.4 in coverage.py. Sounds like your experience agrees with mine. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, 20 Mar 2014 22:50:45 +0200, Marko Rauhamaa wrote: Mark Lawrence breamore...@yahoo.co.uk: On 20/03/2014 20:30, Marko Rauhamaa wrote: I must say, though, that Python3 destroyed print forever for me. To avoid nausea, I write sys.stdout.write() in all Python3 code. Not for me, I was using from __future__ import print_function for years so got used to typing those two extra brackets, plus print very kindly inserts the newlines for me. That very realization helped me wean myself from print. Its sole raison d'être is the insertion of the newline, which it would be nicer to micromanage anyway; that's how it's done in other programming languages as well: C, perl, guile, ... (Well, ok, echo is the exception.) echo is not the exception. *Many* languages handle the newline when printing: Pascal, Ruby, Io, Dylan, Haskell, Rebol, Tcl, Perl6, Java, Ocaml, ... either add a newline by default, or provide two functions for printing, one which adds newline and one which doesn't. The rule of three applies here: anything you do in three different places ought to be managed by a function. Printing a newline at the end of a line of output is *incredibly* common. Any language which fails to provide a print-with-newline function is, frankly, sub-standard. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 8:32 PM, Steven D'Aprano wrote: On Thu, 20 Mar 2014 16:26:39 -0400, Ned Batchelder wrote: On 3/20/14 3:07 PM, Eric Jacoboni wrote: Le 20/03/2014 16:21, Marko Rauhamaa a écrit : All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. With Arch-Linux, python is python3... Yes, and they have been told many times that this was foolish and wrong, but it persists, much to our pain. How bizarre. I've been looking forward with great pleasure to Fedora moving to Python 3 as the standard system Python, expecting that this move from one of the big distros will start a chain reaction of others doing the same thing. Perhaps Arch-Linux is guilty of being prematurely Python 3, a little like those people hauled up to explain themselves to the House Unamerican Activities Committee to explain why they were a premature anti-fascist. My understanding is that Fedora's move will not include making the word python mean Python 3. Their move means that Python 3 will be installed by default, and that their Python programs that are part of the distro will be Python 3 programs. They can still refer to it as python3. I have no idea what our pain you are referring to, or who our refers to. In the three or five years or so since Arch-Linux moved to Python 3 by default, I don't recall ever seeing even a single email from somebody confused by Arch-Linux's move, not here, or on the tutor mailing list, or on Python-Dev or Python-Ideas. Nor have I seen any signs of difficulty or confusion on Python-related blogs, or StackOverflow. In the #python IRC channel, there's a steady flow of people who run programs they find online, and they get a syntax error on print, and we say, Arch? and they say, yup. Perhaps I overstated the amount of pain. But Arch's move prompted a PEP to be written explaining what the word python should mean: http://python.org/dev/peps/pep-0394/ Note that they say there that for the time being the word python should mean Python 2, anticipating that eventually it will be OK to change it to Python 3. But I think that change would always cause confusion, and we should not change it over. I understand that this is a controversial view, and don't hold it strongly enough to defend it. :) That's not to say that there has been absolutely none at all. The Internet is a big place, and I daresay I've missed something. But given how small the Arch-Linux share of the Linux space is, I would be astonished if their move caused more than a tiny little ripple. Perhaps a paper-cut worth of pain. It caused enough of a ripple to get PEP 394 written so that people wouldn't do it again. I expect that there have been far more angry words written over this issue than the actual consequences of the move itself. Unless you're in the unfortunate situation of having to migrate and maintain scripts across a network of mixed Linux distros including some that are Arch-Linux, it's difficult to see exactly what pain they could be causing even in principle. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
In article 532b8f0d$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The rule of three applies here: anything you do in three different places ought to be managed by a function. I prefer the rule of two :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 11:32 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Perhaps Arch-Linux is guilty of being prematurely Python 3... I have no idea what our pain you are referring to, or who our refers to. In the three or five years or so since Arch-Linux moved to Python 3 by default, I don't recall ever seeing even a single email from somebody confused by Arch-Linux's move, not here, or on the tutor mailing list, or on Python-Dev or Python-Ideas. Nor have I seen any signs of difficulty or confusion on Python-related blogs, or StackOverflow. That's not to say that there has been absolutely none at all. There definitely has been a little. Scripts that began with a python shebang and assumed 2.x would suddenly fail on Arch. But not a huge amount of confusion. I expect that there'll be a progressive shift - more distros will start shipping 3.x under the name python, so script authors will be more and more aware of the difference, and before long we'll settle on explicit use of python2 or python3 for anything that matters. Think of the bug reports: Your program doesn't work on Ubuntu 14.04, but change the shebang and it'll work, without breaking it for anything else. Easy fix. And then once Debian and Red Hat move to 3.x as the default system Python, everyone'll use python2 for 2.7 (by that time, I doubt 2.6 or earlier will be supported much anywhere) and python for 3.x, and the transition will be complete. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 11:59 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The rule of three applies here: anything you do in three different places ought to be managed by a function. Printing a newline at the end of a line of output is *incredibly* common. Any language which fails to provide a print-with-newline function is, frankly, sub-standard. I wouldn't go that far. There are plenty of languages where the default (printf, write, werror, etc) doesn't add the newline, and I wouldn't call the *language* sub-standard for that. But yes, it does bug me now and then. I use my say function to produce one or more lines of output in Gypsum, and it guarantees complete lines (because the system works with lines, not streams of characters); and then if I use the werror function to write to stderr, I have to remember to add the newline. However, I think Py2's print statement has way too many weirdnesses - the trailing comma (reminiscent of BASIC, where I never liked it either), the whole soft space concept, etc. Py3's print function, with the keyword end=, is a lot better, though still a tad verbose. (I don't know of any solution to that.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/14 9:06 PM, Ned Batchelder wrote: On 3/20/14 8:32 PM, Steven D'Aprano wrote: On Thu, 20 Mar 2014 16:26:39 -0400, Ned Batchelder wrote: On 3/20/14 3:07 PM, Eric Jacoboni wrote: Le 20/03/2014 16:21, Marko Rauhamaa a écrit : All tutorials will tell you to start it with #!/usr/bin/env python which will start python2 on all (?) existing linux distros, but is expected to start python3 within the next decade. With Arch-Linux, python is python3... Yes, and they have been told many times that this was foolish and wrong, but it persists, much to our pain. How bizarre. I've been looking forward with great pleasure to Fedora moving to Python 3 as the standard system Python, expecting that this move from one of the big distros will start a chain reaction of others doing the same thing. Perhaps Arch-Linux is guilty of being prematurely Python 3, a little like those people hauled up to explain themselves to the House Unamerican Activities Committee to explain why they were a premature anti-fascist. My understanding is that Fedora's move will not include making the word python mean Python 3. Their move means that Python 3 will be installed by default, and that their Python programs that are part of the distro will be Python 3 programs. They can still refer to it as python3. From http://fedoraproject.org/wiki/Changes/Python_3_as_Default : Users shouldn't notice any changes, ... /usr/bin/python will still point to Python 2 and depending on result of discussions with FPC, yum install python-foo will still install Python 2 version of the package. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 03/20/2014 05:37 PM, Steven D'Aprano wrote: In my experience, such as it is, the hard part about writing code that works from 2.4 to 3.4 is not the 3 versions but the 2.4 and 2.5 versions. +1000! (yes, that's factorial ;) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith r...@panix.com wrote: In article 532b8f0d$0$29994$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The rule of three applies here: anything you do in three different places ought to be managed by a function. I prefer the rule of two :-) The way I explain it is: Three is a rule of thumb. Sometimes it's blatantly obvious at two, and other times you need four or five similar pieces of code before you can see which part should become the function. If the code's absolutely identical and reasonably long/complex, then yes, two's all you need, but how often is that? Usually it's similar, rather than congruent... err I mean identical. That's where the third usage comes in. Or if it's maybe 2-3 lines, used in two places, it doesn't necessarily need to be a function. Again, a third usage is a strong hint that it should be broken out. The rule doesn't say that anything that *isn't* in three places yet should *not* be broken out. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Friday, March 21, 2014 2:23:25 AM UTC+5:30, Ned Batchelder wrote: On 3/20/14 4:42 PM, Marko Rauhamaa wrote: Ned Batchelder : Plenty of people have adopted a dual-support strategy, with one code base that supports both Python 2 and Python 3. The six module can help a great deal with this. I wonder how easy the resulting code is to the eyes and how easy it is for the casual maintainer to accidentally break the delicate balance. In a word, I wouldn't go there. Stay with Python2 as long as you must and then, migrate and leave it behind. This is fine advice for applications, but tools, libraries, and frameworks may want to support more than one version at the same time. It's an extreme case, but the latest released version of coverage.py supports Python 2.3 through 3.3 with one code base. To do it, there's a compatibility layer (akin to six). Then you stay away from features that aren't available on all versions. In a few places, you might need to have version checks, and the code can get a little idiomatic to continue to work. It's a tradeoff: you have to decide for yourself whether the effort is worth the benefit. I was glad to be able to drop support for 2.3, 2.4, and 2.5, and now only support 2.6-3.4 in coverage.py. Ned is talking to (and from) a lib-writer perspective Marko is talking from noob perspective (which is what the OP looks like) Good to choose our hats appropriately -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/2014 3:07 PM, John Gordon wrote: There are two ways (at least!) to run a python script: On 21/03/2014 8:05 AM, Terry Reedy wrote: 3. [...] Our chief weapon is... -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Thu, 20 Mar 2014 21:06:24 -0400, Ned Batchelder wrote: In the #python IRC channel, there's a steady flow of people who run programs they find online, and they get a syntax error on print, and we say, Arch? and they say, yup. When you install random programs you find online without going through your package manager, you have no guarantee that all the dependencies will be met. Particularly of third-party libraries, but also of standard Python libraries too: http://bytes.com/topic/python/answers/448757-how-enable-rotor-python-2-4-2-a If your script uses xreadlines, rotor, or mpz, using python to refer to both pre-2.4 and post-2.4 will cause breakage. Likewise, I've seen Python 2.6 break applications because it removed string exceptions. So I'm not seeing anything out of the ordinary with Arch: any version change has the possibility to break scripts. Python 3 is just more obvious because of the change to print, which I daresay is a little more common than rotor... Arch happens to be at the bleeding edge of that, bless them, but if you use Arch, that's what you're letting yourself into. You know what they say -- even Slackware users think Arch users are nuts :-) I've also seen scripts broken because the script used a hard-coded path to the Python executable, like /usr/bin/python or /usr/local/bin/python. Or because they've hard-coded the version number. Or because they didn't hard-code the version number. I haven't seen scripts broken because env has moved, but I guess that's only a matter of time. Frankly, hash-bang lines are a dirty hack, and like all dirty hacks, they work really well until they suddenly don't. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On Fri, Mar 21, 2014 at 2:16 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I haven't seen scripts broken because env has moved, but I guess that's only a matter of time. That usage is extremely common, and isn't it also specified by POSIX? I think that's about as dependable as you can get. Course, it does depend on the user's $PATH... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
Chris Angelico ros...@gmail.com: go for the lowest common denominator: print(some single string) which works happily in all versions of Python. Whenever I have used print in my code, it has been with a redirection. Marko -- https://mail.python.org/mailman/listinfo/python-list