Programming Python

General programming chat and advice for beginners

7 posts
by tomc » Fri Aug 31, 2012 5:12 pm
Pardon my naivete' (sp), but what is the simplest environment to write, debug and write python code on the rPi? In the graphical environment? In the command line environment?

I ulitmately require some I2C and UART stuff, but for now, just to write/debug/run some simple loops either in command line or x mode would be helpful.

Thank you,
Posts: 10
Joined: Thu Aug 30, 2012 11:47 pm
Location: US (Detroit)
by toxibunny » Fri Aug 31, 2012 5:27 pm
Simplest? Idle. If you're at the stage where you have to ask, then Idle is the one for you :)

Just remember to deliberately add the .py extension while saving, otherwise your colour coding might disappear.
note: I may or may not know what I'm talking about...
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm
by tomc » Fri Aug 31, 2012 6:47 pm
Hmmmm....perhaps my question was poorly posed; I was referring to the environment on the rPi, not necessarily the room I'm in !! :)

More specifically: What is the recommended editor(s)? How does one then invoke the interpreter to run the code which has been saved with

Thank you,
Posts: 10
Joined: Thu Aug 30, 2012 11:47 pm
Location: US (Detroit)
by tomc » Fri Aug 31, 2012 7:04 pm
Duh! Think I now better understand your reply! I'll try it out!

Thanks again,
Posts: 10
Joined: Thu Aug 30, 2012 11:47 pm
Location: US (Detroit)
by BlackJack » Fri Aug 31, 2012 7:04 pm
@tomc: IDLE is the name of the editor that belongs to the standard Python installation. If you installed the Raspbian image from the Raspberry Pi homepage there should be icons on the desktop for the IDLEs of Python 2 and Python 3.

Many Python programmers use their favourite text editor. There are many editors to choose from, so it is hard to tell which one to use except the own favourite choice.

Running Python programs works the same way as running any other „scripting language”s programs on Linux. Section two of the tutorial in the Python documentation has more information on this.
Code: Select all
while not self.asleep():
    sheep += 1
Posts: 288
Joined: Sat Aug 04, 2012 8:28 am
by gordon77 » Sat Sep 01, 2012 7:49 pm
I've recently been though the same process as yourself having never used Linux or Python before.

To start Pyhton double click on IDLE (this will open Python 2.7, as IDLE3 will open Python 3.2.3, I don't know all the reasons for both but they do have differences).

When the screen opens click on 'File' then 'New window', and when the new screen opens type your script in there. To run it click on 'Run', then 'Run module'. It will ask you to save it if you haven't already.
Posts: 2744
Joined: Sun Aug 05, 2012 3:12 pm
by Jim JKla » Sat Sep 01, 2012 8:06 pm
In Python 2 there were some ways of doing some things more than one way in Python 3 they tried to make it so that there fewer places where these multiple choices existed.

The aim was to simplify the code by removing some of the old ways of doing things.

It is said that they hope Python 3 will become the standard and any one truly conversant in Python 2 will know all of the ways python 2 has to do any particular job

The philosophy behind this is explained here

But basiclly the threw out some of the older long winded ways of doing things and tightened up the language.

If you learn on 3 it should work on 2 if you learn on 2 you may learn some things that will be obsolete on 3 but you will have learned ways to cucumvent these issues.

So if you learn only on Python 3 and you look at code witten using Python 2 you may see some things and think what the hell is that about, that will be a bit of old code and chances are you will be easily able to work out what is wrong and stich in the Python 3 fix. ;)

Some nutters will be able to write code that does both with one method commented out and all you will need to do is reverse the commenting. Coders with this level of copedence should be locked up for the safety of us mere mortals. :D

Confused you will be :D
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick
User avatar
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK