[Tutor] python launcher
Peter Otten
__peter__ at web.de
Tue Sep 2 02:37:34 CEST 2014
Jan Karel Schreuder wrote:
> Until now I have used IDLE to write and run programs. I decided it was
> time to do it the hard way and use only a Terminal and a plain text
> editor, TextWrangler. I have Python 3.4.1 and OS 10.8.5. When I run the
> script by calling for the interpreter in the terminal with the script as
> the parameter (e.g. python3 shares.py), it runs fine. This is the output:
>
> corrupt record.....removed
> corrupt record.....removed
> corrupt record.....removed
> ['description', 'symbol', 'current price', 'number of units']
> List shares
> Buy shares
> Sell shares
> Update prices
> ridfx 21.98 833.592135342 18322.36
> dodfx 46.99 390.964829507 18371.44
> dfsvx 36.87 499.060771965 18400.37
> pplix 15.42 1189.216568817 18337.72
> total 73431.89
>
> However, when I run it by using the Python Launcher, this is the result:
>
> corrupt record.....removed
> corrupt record.....removed
> corrupt record.....removed
> ['description', 'symbol', 'current price', 'number of units']
> ('\t\t\t', 'List shares')
> ('\t\t\t', 'Buy shares')
> ('\t\t\t', 'Sell shares')
> ('\t\t\t', 'Update prices')
> ('ridfx', '21.98', '833.592135342', 18322.36)
> ('dodfx', '46.99', '390.964829507', 18371.44)
> ('pplix', '15.42', '1189.216568817', 18337.72)
> ('dfsvx', '36.87', '499.060771965', 18400.37)
> ('total', 73431.89)
> Exit status: 0
> logout
>
> [Process completed]
>
> Why the difference ? All the output was taken care of by the Print
> function.
In Python 3 print is a function, so
print(1, 2)
will invoke print with two arguments and display
1 2
In Python 2 print is a statement, to display the two numbers you have to
write
print 1, 2
while in
print(1, 2)
(1, 2) is interpreted as a single argument and the tuple
(1, 2)
is printed. I'm not familiar with the Mac, so I don't know how to convince
the "launcher" to use Python 3 instead of Python 2. I'd try adding
#!/usr/bin/env python3
as the first line of your script.
More information about the Tutor
mailing list