Pandora Python on Pandora - most simple example?


Grench

Forum Addict!
Joined
Oct 3, 2008
Messages
6,629
So - I've decided to poke around and maybe learn some Python.  I would like to use my Pandora as my learning environment.  The catch - I'm unsure with the simple platform use steps needed to do the most simple of tasks.  Most of the online how-to guides assume Windows, some Linux, none Linux on Pandora.


From what I can tell from the forums here, some Python bits are included in the current OS.  Will I need to install any additional pieces to get up and running?


Could anyone give a truly step by step guide to how to make and run the most rudimentary of Python programs in the Pandora's environment?  I.e. Hello world! or favorite color quiz simple - but emphasize how to make that happen using nothing but the Pandora.  It's using Python on Pandora environment that is more important here - not the nuances of programming in Python in general.


Thank you!
 
A simple helloworld python program is easy.  Open up a new file in your favourite text editor, and in it put:

Code:
#!/usr/bin/env python

print "Hello world!"

Then save that as helloworld.py.  That first line isn't really part of the program, it just tells the shell (or whatever you use to run it) what the file is and how to run it.


Your next problem is finding anything to actually run it.  AFAICT, Thunar (the Pandora's default file manager) isn't configured to run files by default, and is more likely to just open your file in a text editor when you click on it.  There are ways to configure it, but for now I'll suggest you open a terminal.  If you want to use Thunar, you can navigate to the folder containing the file you just saved, right click and choose 'open terminal here'.


In that terminal, first run these commands

Code:
chmod u+x helloworld.py

./helloworld.py

That first line marks the file as executable, and only needs to be done once per new file, while the second actually runs it.  You can run it as often as you want using that command, provided your terminal is in the right directory.
 
A favourite colour quiz is quite simple too.  Put this in a file instead:

Code:
#!/usr/bin/env python

fav_colour=input("What's your favourite colour?")

print "Your favourite colour is", fav_colour

Then just follow the same instructions as before.  Tada!
 
do you have a Kodi Mediacenter in your network? Kodi addons can be written in Python :D
 
Last edited by a moderator:
Generally speaking python is fully included in any standard linux, there are no steps required to get it running. 
 
Thank you Levi - those examples were just what I was looking for.
 
Sorry to revive a dead thread but it seems like the ideal place for my query.

I have some Python/Pygame projects I'd like to put up on the Pandora repo eventually but I'd like to learn how exactly to package my games as PNDs. Can someone direct me where I could learn more about that?
 
Do your games run with the version of python included in SZ? If so, packaging is super easy. Otherwise you either need to include the newer version of python in your PND or have your pnd mount/use the version in the wxpython pnd.
 
I can't believe this thread has been around for almost two years and no one with a snake has posted a picture of the most simple example.
 
Do your games run with the version of python included in SZ? If so, packaging is super easy. Otherwise you either need to include the newer version of python in your PND or have your pnd mount/use the version in the wxpython pnd.
Yep I just checked and so far my game runs on the pandora as is!


Thanks for showing me the wiki. I can't believe I didn't look there. So typical. I'm looking forward to having something to share.
 
Back
Top