Python windows interactive.

N

notejam

I am trying to get started with a interactive version of Python for
windows and need some help.
I have played with the tutorial, and now want to write a program.

In basic language, I could write something like
10 print "hello"
20 print "Jim"

and if I run it I would get
hello
Jim

How do I do sometihing simple like that in python?
How do I enter line numbers, or if none, what do I do.
Can the interpreter load a text file with my program in it?
How do I list a program or the parts of a program I am interested in
looking at?

How do I run a python program?
 
R

robfalck

edit a plain text file, just type one line


print "hello, world"


Now save that one-line text file as "hello.py". From the command line,
in the same directory, type:

python hello.py


And it should run your script. Python doesnt require line numbers.

Happy coding.
 
A

abcd

How do I do sometihing simple like that in python?

print "hello"
print "Jim"
How do I enter line numbers, or if none, what do I do.

no line numbers needed
Can the interpreter load a text file with my program in it?

read in a text file:
data = open("something.txt").read()
How do I list a program or the parts of a program I am interested in
looking at?

say you want to know what you can do with a list....
x = [1,2,3,4,5]

dir(x)
help(x)
help(x.append)
How do I run a python program?

create a file, type some code. then to at the end of the file (put
this)...

if __name__ == "__main__":
# call your functions here

this will let you run it from command line like this:
c:> python foo.py
 
P

Paul McGuire

notejam said:
I am trying to get started with a interactive version of Python for
windows and need some help.
I have played with the tutorial, and now want to write a program.

In basic language, I could write something like
10 print "hello"
20 print "Jim"

and if I run it I would get
hello
Jim

How do I do sometihing simple like that in python?
How do I enter line numbers, or if none, what do I do.
Can the interpreter load a text file with my program in it?
How do I list a program or the parts of a program I am interested in
looking at?

How do I run a python program?
Hmmm, exactly how much have you "played with the tutorial"? I think if you
go back and play some more, you will answer many of these questions for
yourself.

In fact, you should find Python to be quite friendly to your past
experience. For example, if you take your basic language example, remove
the line numbers (Python doesn't use them, and many modern Basics don't
either), and just enter the same print statements at the Python command
line, you should get the exact same output.

Python editing doesn't require a specialized development environment (the
way VisualBasic does, for example). Python programs are simply text files,
usually saved with a .py extension, that you create, view, print, list, etc.
using any plain text editor. (Note: Windows WordPad does not fall in this
category - like a slimmed-down version of Word, WordPad inserts many special
binary characters for text formatting, which is not at all Python-friendly.)

If you use a simple text editor like notepad, enter those same two lines
above (remember, without the line numbers) in a text file, name it
"HelloJimThisIsYourFirstPythonProgram.py", then open a console window, set
your working directory to the same directory where you saved
HelloJimThisIsYourFirstPythonProgram.py, and enter at the command line:
"python HelloJimThisIsYourFirstPythonProgram.py" (leave off the quotes, they
are just there in this message to show you what to type), you should get the
same output. And voila! you have run your Python program.

I've left out a lot, because there is quite a bit of meat in the tutorials
already available. Also, there are more tutorials than just the official
one, google about a bit and you should find quite a bit of entry-level
material.

Lastly, before posting again, please review the Python FAQ's at
http://www.python.org/doc/faq/. Don't be another one to exclaim "Shoot! I
wish I'd checked the FAQ's before posting that newbie question that everyone
is tired of hearing again and again!"

Best of luck to you in your new Python adventure!
-- Paul
 
L

Larry Bates

notejam said:
I am trying to get started with a interactive version of Python for
windows and need some help.
I have played with the tutorial, and now want to write a program.

In basic language, I could write something like
10 print "hello"
20 print "Jim"

and if I run it I would get
hello
Jim

How do I do sometihing simple like that in python?
How do I enter line numbers, or if none, what do I do.
Can the interpreter load a text file with my program in it?
How do I list a program or the parts of a program I am interested in
looking at?

How do I run a python program?
Start with the tutorial here:

http://docs.python.org/tut/tut.html

Your program in python would be:

print "hello"
print "jim"

You don't have line numbers in Python

Yes the interpreter can load a text file with your program.
A good "beginners" version of Python for windows is:

http://www.activestate.com/Products/ActivePython/?tn=1

It has an easy to use interpreter window with both your
program and interactive prompt open on the screen.

To run a program you click run icon. To run outside the
interpreter you type python programname.py

-Larry
 
N

notejam

Thanks everyone for the help. I got a simple two line program to work
from a text file.
Can not figure out how to write more than one line in interpreter mode.
Is that all interpreter is good for, testing one liners? I have it
run the program everytime I hit return, and can not figure out how to
enter multiple lines of code. I can do multiple lines in text file, so
no problem, but I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?
 
G

Gabriel Genellina

Thanks everyone for the help. I got a simple two line program to work
from a text file.
Can not figure out how to write more than one line in interpreter mode.
Is that all interpreter is good for, testing one liners? I have it
run the program everytime I hit return, and can not figure out how to
enter multiple lines of code. I can do multiple lines in text file, so
no problem, but I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?

The command-line interpreter (python.exe), in interactive mode, is
just for testing purposes: one or two lines or code.
You could write your program in a file (using notepad by example),
save it with filename.py, and run it using: python filename.py
There are some integrated environments for working in python. IDLE
already comes with your Python installation. For Windows you can get
PythonWin <http://sourceforge.net/projects/pywin32/>


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
S

Steve Holden

notejam said:
Thanks everyone for the help. I got a simple two line program to work
from a text file.
Can not figure out how to write more than one line in interpreter mode.
Is that all interpreter is good for, testing one liners? I have it
run the program everytime I hit return, and can not figure out how to
enter multiple lines of code. I can do multiple lines in text file, so
no problem, but I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?
The interactive interpreter is mostly for experimentation, but of course
its advantage is that you can test out complex functionality imported
from modules and packages. Want to know what's on the Google home page?
<html><head><meta http-equiv="content-type" content="text/html;
charset=ISO-8859
-1"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif}
..h{font-size:20px}
..q{color:#00c}
--></style>
<script>
<!--
function sf(){document.f.q.focus();}
// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b
alink=#ff0000 onload=sf() topmargin=3 marginheight=3><center><div
align=right nowrap style="padding-bottom:4px" width=100%><font size=-1> ...

You can also define funcitons and classes, and write multi-line
statements interactively once you learn the conventions, but once
functionality "hardens" into something of five lines or more that you
want to experiment with you will find it's usually easier to edit a
script or program in a text file and run it. This is even more the case
when you start to use "test-driven development", something we shoudl all
aspire to.

regards
Steve
 
H

Hendrik van Rooyen

notejam said:
Thanks everyone for the help. I got a simple two line program to work
from a text file.
Can not figure out how to write more than one line in interpreter mode.
Is that all interpreter is good for, testing one liners? I have it
run the program everytime I hit return, and can not figure out how to
enter multiple lines of code. I can do multiple lines in text file, so
no problem, but I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?

the interactive interpreter remembers the stuff you type.

so you can assign values to variables, and refer to them later.
you can define functions and call them later

that is enough to start with.

try it - you will like it...

- Hendrik
 
F

Fredrik Lundh

notejam said:
Can not figure out how to write more than one line in interpreter mode.

press return between the lines. if you get a "..." prompt, keep adding
more lines to the current statement. press return an extra time to end
the multiline-statement.
Is that all interpreter is good for, testing one liners? I have it
run the program everytime I hit return

no, it executes the *current statement* when you press return. a
program consists usually consists of many statements.
and can not figure out how to enter multiple lines of code.

if you'd entered a statement that actually consisted of multiple lines,
you'd noticed (try entering an "if"-statement, for example).
I am jsut wondering can a program with 2 or more lines
be wrote from the interpreter mode?

Type "help", "copyright", "credits" or "license" for more information..... f = urllib.urlopen(url)
.... s = f.read()
.... i = s.find("<title>")
.... j = s.find("</title>", i)
.... return s[i+7:j]
....'CNN.com - Breaking News, U.S., World, Weather, Entertainment &amp;
Video News'
.... "http://www.fbi.gov"
.... ].... print gettitle(site)
....
BBC NEWS | News Front Page
reddit.com: what's new online
Federal Bureau of Investigation - Home Page
etc.

</F>
 

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

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top