Question

Locked

python programming language

By jairuskagondu ·
i have been trying some programming using python 2.5.5 on windows but my problem is that i cant save ,retrieve and execute my codes.....to come up with a window,what am i missing?

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Does this help you?. :)

How to Save..

> I tried but its not working. Here's a code for sum of two numbers. Now
> how do i save it?
>
>>>> #! /usr/bin/env python
> ...
>>>> def sum(x,y):
> ... return x+y
> ...
>>>> x=int(raw_input('Enter a number: '))
> Enter a number: 35
>>>> y=int(raw_input('Enter a number: '))
> Enter a number: 7
>>>> print 'sum is', sum(x,y)
> sum is 42

You *don't* write your program inside Python; the interactive prompt is
just for testing a few lines of code. Instead, use another program (a text
editor) to create a file containing your source code, save it using a name
like test1.py, and run it from a shell prompt using: python test1.py

Retrieve ext. variables in python program.

Trying to convert TCL code to python.

Have a property file from where I read some VAR's. Looks like this:
EARPROJECT = sgs-procDist
APPNAME = SGSProcedure

In my TCL code I confirm the existence of the VAR = f.ex EARPROJECT by
using code:

if { ([info exists APPNAME] && [info exists STAGEDIR] && [info exists
EARPROJECT] && [info exists EARDESTINATION]) } {
Does anyone know and equalent way to confirm a Variable from the same
property file using PYTHON code ???
You can read it with the module ConfigParser

how to run a code in python.

The Python interpreter is usually installed as /usr/local/bin/python . Putting /usr/local/bin in your Unix shell's search path makes it possible to start it by typing the command:

python


You may be able to check where the python is installed by typing "which python".
(Note. In the same way you can start CDAT typing "cdat" at a command line).

You can put all your commands in a file with the extension 'file_name.py' and run it by
typing:

python file_name.py


Note that there is a difference between "python file" and "python <file". In the latter case, input requests from the program, such as calls to input() and raw_input(), are satisfied from file. Since this file has already been read until the end by the parser before the program starts executing, the program will encounter end-of-file immediately. In the former case (which is usually what you want) they are satisfied from whatever file or device is connected to standard input of the Python interpreter.

When a script file is used, it is sometimes useful to be able to run the script and enter interactive mode afterwards. This can be done by passing -i before the script. (This does not work if the script is read from standard input, for the same reason as explained in the previous paragraph.)

Python scripts can be made directly executable, like shell scripts, by putting the line (assuming the python path as used in the example above)

#! /usr/local/bin/python

at the beginning of the script and giving the file an executable mode. The "#!" must be the first two characters of the file. On some platforms, this first line must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or Windows ("\r\n") line ending. Note that the hash, or pound, character, "#", is used to start a comment in Python.

The script can be given a executable mode, or permission, using the chmod command:

$ chmod +x myscript.py

http://www2-pcmdi.llnl.gov/cdat/tips_and_tricks/python_tips/running_code.html
..................................

Please post back if you have any more problems or questions.

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums