tag:blogger.com,1999:blog-8550962.post327042159640767593..comments2024-01-27T21:10:48.750-08:00Comments on PyDev adventures: Pydev & Python 3.0Fabio Zadroznyhttp://www.blogger.com/profile/04202246218394712738noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-8550962.post-72987701004081428192008-12-16T11:27:00.000-08:002008-12-16T11:27:00.000-08:00I guess I'm missing something here. Why are tryin...I guess I'm missing something here. Why are trying to make a single Pydev lib that works in 2.x and 3.x??<BR/><BR/>Fork it alreadyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8550962.post-71483297666833197252008-11-14T08:35:00.000-08:002008-11-14T08:35:00.000-08:00Actually, you can't define a print function... (at...Actually, you can't define a <STRONG>print</STRONG> function... (at least not the same name), but you could define another function (say <STRONG>prn</STRONG>) to do it and use it everywhere (maybe put it in the builtins), but the name <STRONG>print</STRONG> is banned for supporting python 2 and 3 (note that I'm not saying that it cannot be done, it's just that the actual print name should be something considered banned for anyone interested in supporting python 2 and 3)Fabio Zadroznyhttps://www.blogger.com/profile/04202246218394712738noreply@blogger.comtag:blogger.com,1999:blog-8550962.post-40669015093825890732008-11-14T06:04:00.000-08:002008-11-14T06:04:00.000-08:00Python is a *dynamic* language.Conditionally defin...Python is a *dynamic* language.<BR/><BR/>Conditionally define a print function that works like the python 3.0 print function, then use that. In the event that the actual python 3.0 print function is available, your new def print isn't evaluated, so done and done.<BR/><BR/>This is just the same thing we have been doing for years, like how you had ot do try: from Set import set.Unknownhttps://www.blogger.com/profile/17384832497203522795noreply@blogger.comtag:blogger.com,1999:blog-8550962.post-29815738106113439552008-11-14T02:33:00.000-08:002008-11-14T02:33:00.000-08:00Just to say my specific case for using print (or a...Just to say my specific case for using print (or at least needing the output on stdout):<BR/><BR/>1. To configure the interpreter there's a python script that's run with the selected interpreter to gather info from it (builtins, version and pythonpath), so, supporting all the python versions is a necessity in this case, and, the <STRONG>from __future__ import print_function</STRONG> won't work... (on older versions)<BR/><BR/>2. Tracing calls, debugging calls, and I need to support some modified versions of xml-rpc (to support old versions) that gave prints... and (until now) the single thing that broke it is that it used print.<BR/><BR/>Is really changing the print statement to a logging call really something that was difficult to do? I never got such a request (or that impression) for Pydev... If that was really so difficult, certainly having something in your environment to change the print statement to a log call would be better than breaking the language at that level... (although, now that this is becoming something forced from the python world... changing print to sys.stdout.write is a real necessity)<BR/><BR/>@pantsgolem: I think it's different because that used to be something used extensively and I believe most people would say that it's support was extremely good (and now print cannot be used in any python version for anyone that needs to support more than 1 version)<BR/><BR/>@chphilli: Changes in the grammar don't come for free for Pydev -- it uses its own grammar, which is actually a forked and enhanced version of the jython grammar, so, I have to go on and update it to support grammar changes (but it goes on par with any grammar change, so, that's something really expected and it's not really a concern at that level)Fabio Zadroznyhttps://www.blogger.com/profile/04202246218394712738noreply@blogger.comtag:blogger.com,1999:blog-8550962.post-21299248931067381862008-11-13T21:04:00.000-08:002008-11-13T21:04:00.000-08:00I haven't looked to closely at this, but if py...I haven't looked to closely at this, but if python3k uses a print() function, couldn't you make code forward compatible by putting parens around your string, like this:<BR/><BR/>C:\Users\dobes>python<BR/>>>> print ('this is a test')<BR/>this is a test<BR/><BR/>Since print is used only for debugging 99% of the time, this is probably a reasonable solution for most people using print currently.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8550962.post-84289465121020937022008-11-13T20:25:00.000-08:002008-11-13T20:25:00.000-08:00I think the thing to note here is that, for the mo...I think the thing to note here is that, for the most part, libraries <B>shouldn't be using print</B> anyways. In my opinion, print (whether as a statement, or as a function) is reserved as an application level tool. <BR/><BR/>Instead, libraries should be using the logging module, which allows the application that uses it to determine exactly how and where they want the output to be formatted. As an application developer, a library using the print statement mucks with my intended output, leaving me with little options to deal with the problem.<BR/><BR/>That said, I've been there -- you're working on a library class, using print to debug and then eventually realize that you need to convert all those statements to logging calls -- oops! The nice thing about the new syntax is that I don't have to do that anymore. When I'm ready, I just locally replace the print function with a function that redirects to logging and I'm done.<BR/><BR/>I haven't looked into PyDev itself, so I'm not sure how much this will affect you -- since you're using the interpreter, don't you get these differences (mostly) for free? If I configure a project I wrote in 3.0-syntax to use a 2.x interpreter, it <I>should</I> fail.Chrishttps://www.blogger.com/profile/05755072772135183636noreply@blogger.comtag:blogger.com,1999:blog-8550962.post-16749165200917503472008-11-13T20:05:00.000-08:002008-11-13T20:05:00.000-08:00I don't think I follow. Python 3 source files won...I don't think I follow. Python 3 source files won't run in a Python 2 interpreter, but that's the entire point. How is the print function different than any of the other backwards-incompatible changes?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8550962.post-48712704765972237412008-11-13T19:45:00.000-08:002008-11-13T19:45:00.000-08:00You should be able to import the next print functi...You should be able to import the next print function from the "__future__" module. There's also a command-line switch ('-3') to enable Python 3.0 compatibility testing.<BR/><BR/>Documentation is at <A HREF="http://docs.python.org/whatsnew/2.6.html#pep-3105-print-as-a-function" REL="nofollow">http://docs.python.org/whatsnew/2.6.html#pep-3105-print-as-a-function</A> as well as <A HREF="http://docs.python.org/library/future_builtins.html" REL="nofollow">http://docs.python.org/library/future_builtins.html</A>.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8550962.post-23466175837462131102008-11-13T19:14:00.000-08:002008-11-13T19:14:00.000-08:00I fully agree with this post !I always used to sta...I fully agree with this post !<BR/><BR/>I always used to start introduction to Python for scientists by "No worries, it's a scalable language, no need for a blunt 'public static void main' right from the the start, just 'print "Hello world !"' will do it at the beginning.<BR/><BR/>Then you'll see the language will scale up with your needs/skills to a full blown OO language that can achieve almost anything you can think of.<BR/><BR/>On my side, I guess I'll hack the interpreter to re-introduce print before deployment to my users...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8550962.post-45097919322269163812008-11-13T18:43:00.000-08:002008-11-13T18:43:00.000-08:00Steve Holden has a very nice write-up about the "P...Steve Holden has a very nice write-up about the "Python 3 Blues"<BR/><BR/>http://holdenweb.blogspot.com/2008/11/dont-use-python-30-really.htmlmanuel moe ghttps://www.blogger.com/profile/04878149837118503541noreply@blogger.comtag:blogger.com,1999:blog-8550962.post-55648056047899819932008-11-13T18:41:00.000-08:002008-11-13T18:41:00.000-08:003toAny2 is what is missingPython 3 will be the mos...3toAny2 is what is missing<BR/><BR/>Python 3 will be the most "expressive" version of Python, having straightforward and correct ways to write most tasks (especially i18n, and playing with strings of bytes)<BR/><BR/>I would wait until Python 3 is ready (or, if you wish, support Python 3 exclusively through 2to3)<BR/><BR/>When Python 3 becomes the preferred way to code, the community will have to make 3toAny2 tools, out of necessity.manuel moe ghttps://www.blogger.com/profile/04878149837118503541noreply@blogger.com