3 Simple Questions About Python/IDLE

O

Omar

1) why don't python / idle use numbered lines in their scripting, like
basic? how do you keep track of large batches of code without them?

2) in IDLE, how do you save a program such that it can be run, say from
windows the "run" function?

3) are most of you doing your script editing in IDLE or something more
fully featured?

4) how are you importing previously written blocks of code into your
code? cut and paste? what is the best way to organize snippets of
code?

thanks, peeps
 
C

Claudio Grondi

Omar said:
1) why don't python / idle use numbered lines in their scripting, like
basic? how do you keep track of large batches of code without them?

2) in IDLE, how do you save a program such that it can be run, say from
windows the "run" function?

3) are most of you doing your script editing in IDLE or something more
fully featured?

4) how are you importing previously written blocks of code into your
code? cut and paste? what is the best way to organize snippets of
code?

thanks, peeps
1) Python is very different from what you expect being experienced in
programming with Basic. My recommendation: don't hesitate to take the
time to read the Python manual.
2) Double click on saved Python script (hope you are able to save a
file? Haven't you detected that you can edit and run a file in IDLE?)
3) Plain text editor or IDLE are good. For more see Python website -
there are plenty options to choose from.
4) using 'import' (see recommendation in 1))

Claudio Grondi
 
O

Omar

thanks.

i have saved and double clicked as suggested. when I save and double
click a simple "hello program", the b&w python shell briefly comes up,
then disappears. is this how it should work?
 
D

Diez B. Roggisch

Omar said:
thanks.

i have saved and double clicked as suggested. when I save and double
click a simple "hello program", the b&w python shell briefly comes up,
then disappears. is this how it should work?

Yes. because when your program terminates, the shell terminates. Or
would you prefer it sticking around, cluttering screen space?

If you want it to stay, make your program require a key-press in the
end. something like this:

raw_input("press return")


Diez
 
L

Larry Bates

Omar said:
thanks.

i have saved and double clicked as suggested. when I save and double
click a simple "hello program", the b&w python shell briefly comes up,
then disappears. is this how it should work?
Yes, that is how it should work. Program is doing what you
told it to. print "hello program" and exit (which closes the window).
If you want it to pause put something after the print like:

t=raw_input('Hit return to continue')

This way the program will pause until you hit return.

Good luck.

-Larry Bates
 
L

Larry Bates

Omar said:
thank you genteman.

however, its not working :(

I resaved it, but same thing.
Please post some code so we can actually do something more than
read your mind. You can also run the program from a shell
instead of from idle to see what happens.

-Larry Bates
 
O

Omar

sure...

I'm saving it as "helloworld11", then double clicking the icon I saved
it as.
 
O

Omar

okay...

I got to work using the SCITE editor with

print "hello world" # here we are once again
raw_input("press return")

cool!
 
J

John Purser

Omar,

The '>>>' were causing the problem I would guess. Those are the
interactive interpreter's prompts, not python. Saving a python session
like that is a starting place for creating code, not the finished
product.

You might also want to save the file as "helloworld11.py" before double
clicking it.

Again, these problems indicate that you're not ready to even start
coding until you've read a good intro text.

John Purser
 
D

Dennis Lee Bieber

1) why don't python / idle use numbered lines in their scripting, like
basic? how do you keep track of large batches of code without them?
Because BASIC was created in the days of paper teletypes with
minimal editors. In BASIC, you would correct a line by retyping it with
the line number and the interpreter was responsible for "reordering" the
lines in memory. You could actually type a program in from last line to
first (ie, upside down) and it would run.

NO other language that I know of uses line numbers to control source
code order. Heck, Visual BASIC doesn't use line numbers either (I don't
recall if AmigaBASIC required them either).

All other languages require one to use a text editor to create a
source file, and one uses the functions of the text editor to make sure
the source code is in the correct order.
2) in IDLE, how do you save a program such that it can be run, say from
windows the "run" function?
You don't enter the program in the console window (that's the one
with the >>> prompt). {At least, I seem to recall that being the first
window to come up with IDLE back when I tried it, but now I'm just
getting the IDLE editor window, and the console has to be explicitly
requested}

I don't use the "start/run" function for such... I either just
double-click the .py file (or .pyw if it is a GUI program that doesn't
need a command line shell), or I open a command line shell
(start/programs/accesories/command prompt -- if you haven't create a
shortcut on the start menu itself) and type "python whatever.py" {note,
I /can/ run them with just "whatever.py" but prefer not to -- Windows
has some glitch on how command line arguments and redirection are
handled}
3) are most of you doing your script editing in IDLE or something more
fully featured?
I've always installed the ActiveState version, and use PythonWin for
editing. For a simple editor, one could use SciTE...
4) how are you importing previously written blocks of code into your
code? cut and paste? what is the best way to organize snippets of
code?
In logical modules that one imports...

import snippet_module
snippet_module.function_x(some, argument)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
N

Neil Cerutti

Because BASIC was created in the days of paper teletypes with
minimal editors. In BASIC, you would correct a line by retyping it with
the line number and the interpreter was responsible for "reordering" the
lines in memory. You could actually type a program in from last line to
first (ie, upside down) and it would run.

NO other language that I know of uses line numbers to control
source code order. Heck, Visual BASIC doesn't use line numbers
either (I don't recall if AmigaBASIC required them either).

(Nope.)
 
S

Steve Holden

Dennis said:
Because BASIC was created in the days of paper teletypes with
minimal editors. In BASIC, you would correct a line by retyping it with
the line number and the interpreter was responsible for "reordering" the
lines in memory. You could actually type a program in from last line to
first (ie, upside down) and it would run.

NO other language that I know of uses line numbers to control source
code order. Heck, Visual BASIC doesn't use line numbers either (I don't
recall if AmigaBASIC required them either).
Well, there was Focal. Focal used floating-point line numbering, making
it much easier to squeeze extra lines in at any point int he program.

regards
Steve
 
G

Gabriel Genellina

I'm working through a tutorial,
http://swaroopch.info/text/Byte_of_Python:Control_Flow, and I sorta
can't get through the tutorial without overcoming these little
speedbumps. This is why I'm asking these questions.

Have you read the Python tutorial which comes with the documentation?
You can read it online at <http://docs.python.org/tut/tut.html>



Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top