Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19504 > unrolled thread
| Started by | Matty Sarro <msarro@gmail.com> |
|---|---|
| First post | 2012-01-26 17:05 -0500 |
| Last post | 2012-01-26 20:51 -0500 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | Matty Sarro <msarro@gmail.com> |
|---|---|
| Date | 2012-01-26 17:05 -0500 |
| Subject | Weird newbie question |
| Message-ID | <mailman.5138.1327615560.27778.python-list@python.org> |
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!!
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-01-26 22:27 +0000 |
| Message-ID | <4f21d33f$0$29968$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #19504 |
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
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2012-01-26 22:35 +0000 |
| Message-ID | <jfskf3$ahg$1@reader1.panix.com> |
| In reply to | #19504 |
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"
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2012-01-26 14:53 -0800 |
| Message-ID | <da8502b0-4764-4bdc-9d3b-73ab9c5df1cf@k10g2000yqk.googlegroups.com> |
| In reply to | #19504 |
On Jan 26, 4:05 pm, Matty Sarro <msa...@gmail.com> wrote:
> 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. [...]
Forget about line 4 because line 2 is a problem waiting to happen
(PEP8 formating added for clarity)
Line2: script, filename = argv
Is this a case of the blind leading the blind?
[toc] | [prev] | [next] | [standalone]
| From | Matty Sarro <msarro@gmail.com> |
|---|---|
| Date | 2012-01-26 20:51 -0500 |
| Message-ID | <mailman.5146.1327629112.27778.python-list@python.org> |
| In reply to | #19509 |
The issue was a version mismatch. When installing python on windows,
it installs a shortcut so when you right click, you can edit things in
IDLE. I had installed python 3 after installing 2.7, so it apparently
changed the extension.
As for not showing tracebacks, I couldn't. When I ran the program from
the command line, it ran the version 2.7 python because that's the one
I have set in my $PATH. However when I was editing it in IDLE, it
would highlight the second set of quotation marks in the statement and
simply spit out an error saying "Invalid Syntax." There was no
traceback because IDLE wouldn't run the program in the interpreter
that opens along side the editor.
Re-opening the file in the 2.7 version of IDLE removed any issues.
Thanks for your help everyone.
On Thu, Jan 26, 2012 at 5:53 PM, Rick Johnson
<rantingrickjohnson@gmail.com> wrote:
> On Jan 26, 4:05 pm, Matty Sarro <msa...@gmail.com> wrote:
>
>> 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. [...]
>
> Forget about line 4 because line 2 is a problem waiting to happen
> (PEP8 formating added for clarity)
>
> Line2: script, filename = argv
>
> Is this a case of the blind leading the blind?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web