newbee

Duncan Booth duncan.booth at invalid.invalid
Wed Aug 13 06:59:43 EDT 2014


Peter Otten <__peter__ at web.de> wrote:

> 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.
> 

All of the above should work just fine on a Pi. The only thing I thing 
you could have added is that you also have the option of using Idle to 
edit and run Python programs. If you are running Raspian on your Pi then 
you will find an icon to run Idle sitting on the initial desktop. 
There's an introduction to using Idle on the Raspberry Pi at 
http://www.raspberrypi.org/documentation/usage/python/


-- 
Duncan Booth



More information about the Python-list mailing list