[Numpy-discussion] Porting strategy for py3k

Christopher Barker Chris.Barker@noaa....
Thu Apr 23 11:23:12 CDT 2009


Ryan May wrote:
> On Thu, Apr 23, 2009 at 9:52 AM, David Cournapeau <cournape@gmail.com 
>     But replacing print is not as easy as reduce. Things like print
>     "yoyo", a do not work, for example.
> 
> I think the point is that you can just change it to print("yoyo") which 
> will work in both python 2.x and 3.x.

I think he meant:

print "yoyo", a

which can not be translated by adding parens:

 >>> print "yoyo", a
yoyo [ 1.  1.  1.]
 >>> print ("yoyo", a)
('yoyo', array([ 1.,  1.,  1.]))


I suppose we can write something like:

def new_print(*args):
    print (" ".join([str(s) for s in args]))

 >>> new_print("yoyo", a)
yoyo [ 1.  1.  1.]


Though I'm a bit surprised that that's not how the print function is 
written in the first place (maybe it is in py3k -- I'm testing on 2.5)

-Chris




-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list