473,898 Members | 4,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2312
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*****@sbcglo bal.netwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.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
"HelloJimThisIs YourFirstPython Program.py", then open a console window, set
your working directory to the same directory where you saved
HelloJimThisIsY ourFirstPythonP rogram.py, and enter at the command line:
"python HelloJimThisIsY ourFirstPythonP rogram.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><me ta http-equiv="content-type" content="text/html;
charset=ISO-8859
-1"><title>Googl e</title><style><!--
body,td,a,p,.h{ font-family:arial,sa ns-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%><fon t 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*****@sbcglo bal.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2368
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 line -----> Python 2.3 (#46, Jul 29 2003, 18:54:32) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from Tkinter import * >>> root = Tk()
6
3588
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 stdin pipe, it seems that if I give it some error nous expression, the pipe would return the exception data, though nothing else comes through. A friend of mine also tried this using win32api on delphi, and got the same result.
0
1926
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. http://sourceforge.net/projects/movpy http://www.voidspace.org.uk/python/movpy Fancy trying out Python 2.4 without installing it ? Want a distribution of python you can carry around on a flash card ? Need to test scripts with several versions of python ? Movable Python may...
3
2084
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 creating a good level editor - I basically needed a scripting language to control the C modules of the game and, after a half-assed attempt or two to make my own, I just gave up. So naturally this seems like a job for Python. Embedding Python...
0
1996
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 ( +4) / 291 closed ( +4) / 553 total ( +8) New / Reopened Patches ______________________
3
3961
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 am fairly happy using IDLE, the debugger is unintuitive to me and I wanted a project manager and a better variable/ class browser and also the potential to edit/run other languages such as R and Tex/Latex. Windows and LINUX compatibility is...
8
5592
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 interactive Python shell on Windows that supports: - easy copy-pasting to/from an editor? (as opposed to the cumbersome "mark", "copy" and then "paste" sequence that any terminal on Windows
0
9994
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9842
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11265
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10956
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6079
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3309
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.