Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19508
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Weird newbie question |
| Date | 2012-01-26 22:35 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <jfskf3$ahg$1@reader1.panix.com> (permalink) |
| References | <mailman.5138.1327615560.27778.python-list@python.org> |
In <mailman.5138.1327615560.27778.python-list@python.org> Matty Sarro <msarro@gmail.com> writes:
> Hey everyone. I'm running into a funky error as I work through "Learn
> Python the Hard Way." What's weird is both idle and the python
> interpreter in idle spit out an error about syntax, but when I run the
> same script from the command line it works just fine, with no issue.
> I'm not sure if its an issue with IDLE or if I'm doing something
> wrong.
> Here's the book's code:
> from sys import argv
> script, filename = argv
> txt = open(filename)
> print "Here's your file %r:" % filename
> print txt.read()
> print "Type the filename again:"
> file_again = raw_input("> ")
> txt_again = open(file_again)
> print txt_again.read()
> Here's my code:
> from sys import argv
> script,filename=argv
> txt=open(filename)
> print "Here is your file %r:" % filename
> print txt.read()
> print "I'll also ask you to type it again:"
> file_again=raw_input("> ")
> txt_again=open(file_again)
> print txt_again.read()
> IDLE is saying that my error is on line 4, at the second set of
> quotation marks. Since I can't get the error from the command line, I
> can't actually see what the syntax error is that it's complaining
> about. Any advice would really be appreciated, thank you!!
This may be a Python version mismatch error.
In python version 2.x (and 1.x for that matter), "print" is a statement,
but it was changed to be a function in python version 3.x.
In other words, in python 2.x you can say this:
print x
print "hello there"
But in python 3.x you have to do it a little differently:
print(x)
print("hello there")
It sounds like your IDLE is running python 3, but your command line is
running python 2.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Weird newbie question Matty Sarro <msarro@gmail.com> - 2012-01-26 17:05 -0500
Re: Weird newbie question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-26 22:27 +0000
Re: Weird newbie question John Gordon <gordon@panix.com> - 2012-01-26 22:35 +0000
Re: Weird newbie question Rick Johnson <rantingrickjohnson@gmail.com> - 2012-01-26 14:53 -0800
Re: Weird newbie question Matty Sarro <msarro@gmail.com> - 2012-01-26 20:51 -0500
csiph-web