1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Dismiss Notice

Pandora Python on Pandora - most simple example?

Discussion in 'Python / PyGame' started by Grench, Nov 23, 2015.

  1. Grench

    Grench Hardcore Member

    Joined:
    Oct 3, 2008
    Messages:
    4,579
    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!
     
    Tags:
  2. levi

    levi Still fresh, damnit!

    Joined:
    Oct 6, 2008
    Messages:
    6,815
    Location:
    Somewhere off the coast of the EU
    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.
     
  3. levi

    levi Still fresh, damnit!

    Joined:
    Oct 6, 2008
    Messages:
    6,815
    Location:
    Somewhere off the coast of the EU
    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!
     
  4. Willhelm

    Willhelm Member

    Joined:
    Aug 19, 2014
    Messages:
    130
    Location:
    Munich
    do you have a Kodi Mediacenter in your network? Kodi addons can be written in Python :D
     
    Last edited by a moderator: Nov 24, 2015
  5. Elw3

    Elw3 ¯\_(ツ)_/¯

    Joined:
    Jul 21, 2013
    Messages:
    596
    Generally speaking python is fully included in any standard linux, there are no steps required to get it running. 
     
  6. Grench

    Grench Hardcore Member

    Joined:
    Oct 3, 2008
    Messages:
    4,579
    Thank you Levi - those examples were just what I was looking for.
     

Share This Page

Loading...