Re: [Tutor] Issues In Terminal

2010-09-28 Thread Alan Gauld


Marc Tompkins marc.tompk...@gmail.com wrote


The parentheses are optional in 2.6, mandatory in 3.  In 2.6, print 
and

print() are alternate ways to invoke the print statement


Not strictly true. They often give the same results but not always,
see a recent thread on this. In particular


print ('a','b')


is quite different to


print 'a','b'


But that shouldn't be an issue for 'hello world'

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-28 Thread Wayne Werner
On Tue, Sep 28, 2010 at 5:02 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 Marc Tompkins marc.tompk...@gmail.com wrote



  The parentheses are optional in 2.6, mandatory in 3.  In 2.6, print and
 print() are alternate ways to invoke the print statement


 Not strictly true. They often give the same results but not always,
 see a recent thread on this. In particular

  print ('a','b')


 is quite different to

  print 'a','b'


 But that shouldn't be an issue for 'hello world'


And of course if you're on 2.6+ you can always add

from __future__ import print_function

and that will help prepare you for the eventual migration to 3+

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Issues In Terminal

2010-09-26 Thread Bill DeBroglie

Hello all,

Totally new to this stuff and community so I very much appreciate the  
help and apologize in advance for asking what might be a stupid  
question... Oh, and I'm new to the lingo too!!


I'm having issues running Python in Terminal. When I run code through  
the interpreter I get:


Python 2.6.5 (r236:73959, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5943)] on darwin
Type help, copyright, credits or license for more information.
 print(Hello World)
Hello World

Which is great, but when I try and run the same code in the Terminal  
by calling a program I've written (print(hello world) again) I get  
the following:


matthews-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
	./chapter_2.py: line 4: syntax error near unexpected token `Hello  
World'

./chapter_2.py: line 4: `print(Hello World)'

I'm using a Mac OS X 10.5.8. I had previously downloaded Python 2.6.5  
AND 3.1 and had them both on this computer simultaneously but was  
having trouble with 3.1 crashing. I have since put both in the trash  
but obviously still have 2.6.5 on my system, I assume that was the  
version pre-installed on this Mac.


Any guidance at all would be much appreciated-- I'm totally lost and  
have spent hours trying to figure this out.


bdb
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread David Hutto
On Sun, Sep 26, 2010 at 5:55 PM, Bill DeBroglie
bill.debrog...@gmail.com wrote:
 Hello all,

 Totally new to this stuff and community so I very much appreciate the help
 and apologize in advance for asking what might be a stupid question... Oh,
 and I'm new to the lingo too!!

 I'm having issues running Python in Terminal. When I run code through the
 interpreter I get:

        Python 2.6.5 (r236:73959, Mar 24 2010, 01:32:55)
        [GCC 4.0.1 (Apple Inc. build 5943)] on darwin
        Type help, copyright, credits or license for more
 information.
         print(Hello World)
        Hello World

 Which is great, but when I try and run the same code in the Terminal by
 calling a program I've written (print(hello world) again) I get the
 following:

        matthews-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
        ./chapter_2.py: line 4: syntax error near unexpected token `Hello
 World'
        ./chapter_2.py: line 4: `print(Hello World)'

Pretty sure it's the parentheses, but I'm not an expert. In python 3 you use
print(), in 2.6 you either use import from __futur__ or print string here.


 I'm using a Mac OS X 10.5.8. I had previously downloaded Python 2.6.5 AND
 3.1 and had them both on this computer simultaneously but was having trouble
 with 3.1 crashing. I have since put both in the trash but obviously still
 have 2.6.5 on my system, I assume that was the version pre-installed on this
 Mac.

 Any guidance at all would be much appreciated-- I'm totally lost and have
 spent hours trying to figure this out.

 bdb
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread David Hutto
On Sun, Sep 26, 2010 at 6:03 PM, David Hutto smokefl...@gmail.com wrote:
 On Sun, Sep 26, 2010 at 5:55 PM, Bill DeBroglie
 bill.debrog...@gmail.com wrote:
 Hello all,

 Totally new to this stuff and community so I very much appreciate the help
 and apologize in advance for asking what might be a stupid question... Oh,
 and I'm new to the lingo too!!

 I'm having issues running Python in Terminal. When I run code through the
 interpreter I get:

        Python 2.6.5 (r236:73959, Mar 24 2010, 01:32:55)
        [GCC 4.0.1 (Apple Inc. build 5943)] on darwin
        Type help, copyright, credits or license for more
 information.
         print(Hello World)
        Hello World

 Which is great, but when I try and run the same code in the Terminal by
 calling a program I've written (print(hello world) again) I get the
 following:

        matthews-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
        ./chapter_2.py: line 4: syntax error near unexpected token `Hello
 World'
        ./chapter_2.py: line 4: `print(Hello World)'

 Pretty sure it's the parentheses, but I'm not an expert. In python 3 you use
 print(), in 2.6 you either use import from __futur__ or print string here.

I mean __future__ .


 I'm using a Mac OS X 10.5.8. I had previously downloaded Python 2.6.5 AND
 3.1 and had them both on this computer simultaneously but was having trouble
 with 3.1 crashing. I have since put both in the trash but obviously still
 have 2.6.5 on my system, I assume that was the version pre-installed on this
 Mac.

 Any guidance at all would be much appreciated-- I'm totally lost and have
 spent hours trying to figure this out.

 bdb
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Marc Tompkins
On Sun, Sep 26, 2010 at 2:55 PM, Bill DeBroglie bill.debrog...@gmail.comwrote:

 Which is great, but when I try and run the same code in the Terminal by
 calling a program I've written (print(hello world) again) I get the
 following:

matthews-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
./chapter_2.py: line 4: syntax error near unexpected token `Hello
 World'
./chapter_2.py: line 4: `print(Hello World)'

 I'm using a Mac OS X 10.5.8. I had previously downloaded Python 2.6.5 AND
 3.1 and had them both on this computer simultaneously but was having trouble
 with 3.1 crashing. I have since put both in the trash but obviously still
 have 2.6.5 on my system, I assume that was the version pre-installed on this
 Mac.



I think that's a shell issue, not specifically a Python issue.  You need to
include a line at the top of the script to tell the OS how to find the
Python interpreter.  Try adding this line at the beginning:

 #!/usr/bin/env python

 Your default Python install probably is NOT installed at /usr/bin/python,
but there should be a symbolic link there that points to the actual
location.  If not, you'll need to adjust things a bit.

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Marc Tompkins
On Sun, Sep 26, 2010 at 3:04 PM, David Hutto smokefl...@gmail.com wrote:

  Pretty sure it's the parentheses, but I'm not an expert. In python 3 you
 use
  print(), in 2.6 you either use import from __futur__ or print string
 here.

 I mean __future__ .


The parentheses are optional in 2.6, mandatory in 3.  In 2.6, print and
print() are alternate ways to invoke the print statement; in 3 the print
statement has been replaced by the print() function.  If you want to use the
function instead of the statement, you must do this:

from __future__ import print_function

 but I'm pretty sure that's not the OP's issue.


-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Steven D'Aprano
On Mon, 27 Sep 2010 07:55:40 am Bill DeBroglie wrote:
[...]
 Which is great, but when I try and run the same code in the Terminal
 by calling a program I've written (print(hello world) again) I get
 the following:

How do you call the program?

At the shell prompt, if you call:

python name_of_my_program.py

does it work?

Looking at the error you get, it looks like OS-X is treating the program 
as a shell script, not a Python script:

   matthews-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
   ./chapter_2.py: line 4: syntax error near unexpected token `Hello
 World'
   ./chapter_2.py: line 4: `print(Hello World)'

That's not a Python error message, so it's probably a shell error. You 
need to teach the shell how to treat it, either by explicitly calling 
python, as above, or by inserting a hash-bang line at the very top of 
the script:

#!/usr/bin/env python


should do it.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Bill DeBroglie


On Sep 26, 2010, at 6:06 PM, Marc Tompkins wrote:

On Sun, Sep 26, 2010 at 2:55 PM, Bill DeBroglie bill.debrog...@gmail.com 
 wrote:
Which is great, but when I try and run the same code in the Terminal  
by calling a program I've written (print(hello world) again) I get  
the following:


   matthews-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
   ./chapter_2.py: line 4: syntax error near unexpected token  
`Hello World'

   ./chapter_2.py: line 4: `print(Hello World)'

I'm using a Mac OS X 10.5.8. I had previously downloaded Python  
2.6.5 AND 3.1 and had them both on this computer simultaneously but  
was having trouble with 3.1 crashing. I have since put both in the  
trash but obviously still have 2.6.5 on my system, I assume that was  
the version pre-installed on this Mac.



I think that's a shell issue, not specifically a Python issue.  You  
need to include a line at the top of the script to tell the OS how  
to find the Python interpreter.  Try adding this line at the  
beginning:

#!/usr/bin/env python

Is this what you mean?

	matthew-parrillas-macbook:Dawson_Book matthewparrilla$ #!/usr/bin/env  
python

matthew-parrillas-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
	./chapter_2.py: line 1: syntax error near unexpected token `Hello  
World'

./chapter_2.py: line 1: `print(Hello World)'

If so, obviously still no dice.

Your default Python install probably is NOT installed at /usr/bin/ 
python, but there should be a symbolic link there that points to the  
actual location.  If not, you'll need to adjust things a bit.


--
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Bill DeBroglie


On Sep 26, 2010, at 6:18 PM, Marc Tompkins wrote:

On Sun, Sep 26, 2010 at 3:04 PM, David Hutto smokefl...@gmail.com  
wrote:
 Pretty sure it's the parentheses, but I'm not an expert. In python  
3 you use
 print(), in 2.6 you either use import from __futur__ or print  
string here.


I mean __future__ .

The parentheses are optional in 2.6, mandatory in 3.  In 2.6, print  
and print() are alternate ways to invoke the print statement; in 3  
the print statement has been replaced by the print() function.  If  
you want to use the function instead of the statement, you must do  
this:

from __future__ import print_function
but I'm pretty sure that's not the OP's issue.



Yes, not a parenthesis issue (happens whether I use them or not, I've  
tried both ways).



--
www.fsrtechnologies.com


By the way guys, thank you so much for the help. I'm sort of learning  
this on my own and don't know where to go when I hit a wall like this...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Marc Tompkins
On Sun, Sep 26, 2010 at 3:24 PM, Bill DeBroglie bill.debrog...@gmail.comwrote:


 Is this what you mean?

 matthew-parrillas-macbook:Dawson_Book matthewparrilla$ #!/usr/bin/env
 python
 matthew-parrillas-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
 ./chapter_2.py: line 1: syntax error near unexpected token `Hello World'
 ./chapter_2.py: line 1: `print(Hello World)'

 If so, obviously still no dice.

 No, I meant that you should edit your .py file and add

 #!/usr/bin/env python

as the first line, THEN try to run it.

Right now what's happening is that you're handing a line of Python script to
the shell and asking it to run it; the shell is telling you (oh-so-politely)
what the hell is this?  You need to give it a clue.

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Bill DeBroglie


On Sep 26, 2010, at 6:29 PM, Marc Tompkins wrote:

On Sun, Sep 26, 2010 at 3:24 PM, Bill DeBroglie bill.debrog...@gmail.com 
 wrote:


Is this what you mean?

	matthew-parrillas-macbook:Dawson_Book matthewparrilla$ #!/usr/bin/ 
env python

matthew-parrillas-macbook:Dawson_Book matthewparrilla$ ./chapter_2.py
	./chapter_2.py: line 1: syntax error near unexpected token `Hello  
World'

./chapter_2.py: line 1: `print(Hello World)'

If so, obviously still no dice.

No, I meant that you should edit your .py file and add
#!/usr/bin/env python
as the first line, THEN try to run it.


BINGO!


Right now what's happening is that you're handing a line of Python  
script to the shell and asking it to run it; the shell is telling  
you (oh-so-politely) what the hell is this?  You need to give it a  
clue.


Thank you for the translation. So I need to do this with every .py  
file? My friend who was helping me (he's only been at this a few  
months) doesn't need to do this. Is that possible or is he just  
misleading me?




--
www.fsrtechnologies.com


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Steven D'Aprano
On Mon, 27 Sep 2010 08:37:08 am Bill DeBroglie wrote:
  No, I meant that you should edit your .py file and add
  #!/usr/bin/env python
  as the first line, THEN try to run it.

 BINGO!

  Right now what's happening is that you're handing a line of Python
    script to the shell and asking it to run it; the shell is telling
  you (oh-so-politely) what the hell is this?  You need to give it
  a clue.

 Thank you for the translation. So I need to do this with every .py  
 file?

Only if you want to run them without specifying Python on the command 
line.


You can always call python first:

python name-of-my-script.py


instead of just 

name-of-my-script.py



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-26 Thread Dave Angel



On 2:59 PM, Bill DeBroglie wrote:

snip

No, I meant that you should edit your .py file and add
#!/usr/bin/env python
as the first line, THEN try to run it.


BINGO!


Right now what's happening is that you're handing a line of Python 
script to the shell and asking it to run it; the shell is telling you 
(oh-so-politely) what the hell is this?  You need to give it a clue.


Thank you for the translation. So I need to do this with every .py 
file? My friend who was helping me (he's only been at this a few 
months) doesn't need to do this. Is that possible or is he just 
misleading me?




Two times you wouldn't need such a line:

1) in Windows, where file extension determines what the shell will do 
with the file
2) when you explicitly run the script by naming the python executable, 
such as:


   python  chapter_2.py



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor