Weird newbie question
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Jan 26 17:27:11 EST 2012
On Thu, 26 Jan 2012 17:05:57 -0500, Matty Sarro wrote:
> 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.
Either you are mistaken about it being the same script, or you have two
versions of Python installed, Python 2.x and Python 3.x.
My guess is that you have two versions installed, and when you run IDLE
you are running Python 3, and when you run the script from the command
line you are running Python 2.
> I'm
> not sure if its an issue with IDLE or if I'm doing something wrong.
>
> Here's the book's code:
Irrelevant. Unless you think that somehow your computer is running the
code in the book instead of the code in your computer?
> 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.
Line four is not the second set of quotation marks. It is the first set
of quotation marks.
Please show the ENTIRE error displayed, including the full traceback, and
not just the message. That is, everything starting from "Traceback (most
recent call last)" to the end. Please copy and paste the full error, do
not summarise or paraphrase it.
> Since I can't get the error from the command line,
Earlier you said that the script works correctly when you run it 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!!
(1) Inside IDLE, type this:
import sys
sys.version
What does it show?
(2) Show us the exact command you give on the command line that
successfully runs the script.
There may be more questions later, but this will do to start.
--
Steven
More information about the Python-list
mailing list