newbee

Peter Otten __peter__ at web.de
Wed Aug 13 05:57:51 EDT 2014


Frank Scafidi wrote:

> I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
> programmer back in the 60's & 70's and Python is similar. I am struggling
> with some very fundamental things that I am not finding in the
> documentation. Can someone help me with the basics like how do I save a
> program I've written, reload it in Python, list the program once it's
> loaded? How do I edit a program? Are these command line functions?

You can use any text editor to write a python script. A simple editor which 
might be present ont the Pi is called "nano". It shows the hotkeys to store 
the text and quit the editor, and thus should be self-explanatory:

$ nano helloworld.py

Once you have written your simple script you can look at it with the "cat" 
command:

$ cat helloworld.py 
#!/usr/bin/env python
print "Hello world"

Invoke it with:

$ python helloworld.py 
Hello world

You can also make your script "executable" which means that the first line 
controls which program is used to run it:

$ chmod +x helloworld.py 
$ ./helloworld.py 
Hello world
$

If the script is in a directory listed in the PATH environment variable you 
can omit the path (the "./" in the above example):

$ mv helloworld.py ~/bin
$ helloworld.py 
Hello world

PS: I ran the above demo on a Linux system, but not on the Raspberry Pi, so 
if something doesn't work as shown above it's probably due to the difference 
between the two systems.





More information about the Python-list mailing list