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 Forum Addict!

    Joined:
    Oct 3, 2008
    Messages:
    5,018
    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:
    7,629
    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:
    7,629
    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 Very Active Member

    Joined:
    Aug 19, 2014
    Messages:
    169
    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:
    647
    Generally speaking python is fully included in any standard linux, there are no steps required to get it running. 
     
  6. Grench

    Grench Forum Addict!

    Joined:
    Oct 3, 2008
    Messages:
    5,018
    Thank you Levi - those examples were just what I was looking for.
     
  7. directive0

    directive0 Very Active Member

    Joined:
    Apr 8, 2015
    Messages:
    596
    Location:
    Toronto, Canada
    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?
     
  8. levi

    levi Still fresh, damnit!

    Joined:
    Oct 6, 2008
    Messages:
    7,629
    Location:
    Somewhere off the coast of the EU
  9. edgex004

    edgex004 Advanced Member

    Joined:
    Jan 5, 2008
    Messages:
    1,119
    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.
     
  10. rygD

    rygD Nihilistic Mystic

    Joined:
    Feb 28, 2014
    Messages:
    6,147
    Location:
    Everywhere
    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.
     
    directive0 likes this.
  11. directive0

    directive0 Very Active Member

    Joined:
    Apr 8, 2015
    Messages:
    596
    Location:
    Toronto, Canada
    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.
     
    kuru likes this.

Share This Page

Loading...