472,354 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
10 2172
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Adam | last post by:
Hi I had Ruby 1.6.8-8 for Windows installed on my WinXP Pro machine prior to installing Python 2.3. After installing Python 2.3, I tried to <----- screen output of python interactive command...
6
by: Avi Berkovich | last post by:
Hello, I was unable to use popen2.popen4 to grab python.exe's (2.3) output, for starts, it doesn't show the version information at the beginning and won't return anything when writing to the...
0
by: Fuzzyman | last post by:
Movable Python has just been released on sourceforge. Movable Python is a frozen distribution of Python. It will run python scripts without needing to be installed. ...
3
by: morris.slutsky | last post by:
So every now and then I like to mess around with hobby projects - I often end up trying to write an OpenGL video game. My last attempt aborted due to the difficulty of automating game elements and...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 385 open (+21) / 3790 closed (+21) / 4175 total (+42) Bugs : 1029 open (+43) / 6744 closed (+43) / 7773 total (+86) RFE : 262 open...
3
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I...
8
by: james.kirin39 | last post by:
Hi everyone, After having used Python on Linux for some time, I now have to do Python coding on Windows. I am big fan of the interactive Python shell to test, eg, regexps. Is there an...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.