467,074 Members | 867 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

Python windows interactive.

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?

Oct 30 '06 #1
  • viewed: 1907
Share:
10 Replies
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.

Oct 30 '06 #2
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

Oct 30 '06 #3
"notejam" <no*****@sbcglobal.netwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>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
Oct 30 '06 #4
notejam wrote:
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
Oct 30 '06 #5
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?

Larry Bates wrote:
notejam wrote:
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
Oct 30 '06 #6
Try this, assuming you're in IDLE.

http://hkn.eecs.berkeley.edu/~dyoo/p...tro/index.html

You can enter as many lines as you want in the interpreter. Then press
ENTER twice to get the result.

Or try here if you're looking for some tutorials.

http://tinyurl.com/w7wgp

rd

Oct 31 '06 #7
At Monday 30/10/2006 21:15, notejam wrote:
>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
Oct 31 '06 #8
notejam wrote:
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?
>>import urllib
f = urllib.urlopen("http://www.google.com")
data = f.read()
print data
<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...
<font size=-2>&copy;2006 Google</font></p></center></body>
</html>
>>>
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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 31 '06 #9

"notejam" <no*****@sbcglobal.netTop posted:
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

Oct 31 '06 #10
notejam wrote:
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.
>>import urllib
def gettitle(url):
.... f = urllib.urlopen(url)
.... s = f.read()
.... i = s.find("<title>")
.... j = s.find("</title>", i)
.... return s[i+7:j]
....
>>gettitle("http://www.python.org")
'Python Programming Language -- Official Website'
>>gettitle("http://www.cnn.com")
'CNN.com - Breaking News, U.S., World, Weather, Entertainment &amp;
Video News'
>>sites = ["http://news.bbc.co.uk", "http://reddit.com",
.... "http://www.fbi.gov"
.... ]
>>for site in sites:
.... print gettitle(site)
....
BBC NEWS | News Front Page
reddit.com: what's new online
Federal Bureau of Investigation - Home Page
>>>
etc.

</F>

Oct 31 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Adam | last post: by
6 posts views Thread by Avi Berkovich | last post: by
reply views Thread by Fuzzyman | last post: by
3 posts views Thread by morris.slutsky@gmail.com | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
8 posts views Thread by james.kirin39@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.