471,328 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,328 software developers and data experts.

difference between IDLE and command line

New to Python, and just had something strange happen.

I've been running my new code in IDLE running in windows. My IDLE
version shows as 1.2.1, Python version displaying in IDLE is 2.5.1.

I have been editing my code in UltraEdit then testing in IDLE by
choosing open, then F5. I didn't see an easy way to refresh in IDLE, so
each edit I've been closing the file (not IDLE itself), then opening
again. Since IDLE does not keep track of what directory I last opened
from, this gets tedious, so I decided to run my code from the command line.

Here's where it got interesting for me. From the command line, I'm in
the directory containing my source, I execute via "python mycode.py", I
receive an error in my code. Specifically, it's erroring because I have
a copyright character in a string that I am outputting via the
file.write method. The error has to do with no encoding declared.

What surprised me is that this code runs with no problems in IDLE.

Should I expect different execution behavior between IDLE and a command
prompt?

Oh, and executing python all by itself in the command prompt shows the
same version as what is displayed in IDLE.

Nov 2 '07 #1
2 5259
En Fri, 02 Nov 2007 13:38:07 -0300, Jim Hendricks
<ji*@bizcomputinginc.comescribió:
New to Python, and just had something strange happen.

I've been running my new code in IDLE running in windows. My IDLE
version shows as 1.2.1, Python version displaying in IDLE is 2.5.1.

I have been editing my code in UltraEdit then testing in IDLE by
choosing open, then F5. I didn't see an easy way to refresh in IDLE, so
each edit I've been closing the file (not IDLE itself), then opening
again. Since IDLE does not keep track of what directory I last opened
from, this gets tedious, so I decided to run my code from the command
line.

Here's where it got interesting for me. From the command line, I'm in
the directory containing my source, I execute via "python mycode.py", I
receive an error in my code. Specifically, it's erroring because I have
a copyright character in a string that I am outputting via the
file.write method. The error has to do with no encoding declared.

What surprised me is that this code runs with no problems in IDLE.
Since version 2.4, Python *requires* an explicit encoding declaration at
the start of the file, when it contains a string literal outside the ASCII
range (0 to 127). See
<http://www.python.org/doc/2.3/whatsnew/section-encodings.html>
That IDLE doesn't require an encoding (and assumes something, perhaps
latin-1, I don't know) is an unfortunate bug (already reported, I think).

--
Gabriel Genellina

Nov 3 '07 #2
Jim Hendricks wrote:
I have been editing my code in UltraEdit then testing in IDLE by
choosing open, then F5. I didn't see an easy way to refresh in IDLE, so
each edit I've been closing the file (not IDLE itself), then opening
again. Since IDLE does not keep track of what directory I last opened
from, this gets tedious, so I decided to run my code from the command line.
Tip: IDLE has a recent files list, under the File menu. Use Alt-f Alt-
r to access it quickly.

Tip #2: You can run a script in IDLE from the command line: IDLE -r
<script file>. This will open an IDLE shell, run the script in it, and
afterwards become interactive. Very useful for debugging etc.

- Tal
reduce(lambda m,x:[m[i]+s[-1] for i,s in enumerate(sorted(m))],
[[chr(154-ord(c)) for c in '.&-&,l.Z95193+179-']]*18)[3]

Nov 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Paul M | last post: by
16 posts views Thread by Kerry Neilson | last post: by
6 posts views Thread by Kevin Walzer | last post: by
13 posts views Thread by John Salerno | last post: by
3 posts views Thread by Rob | last post: by
3 posts views Thread by writser | last post: by
2 posts views Thread by Russ P. | last post: by
6 posts views Thread by Andreas Tawn | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.