I tried to call programs I wrote so that I can have a higher level of python program running a main loop. Then depend upon user input, I would run one of these smaller programs and then return to the main loop for users to choose other programs to run.
For example, my program can call all the game programs in pythonista and let user choose which one to play.
In this regards, I saw sample for calling class module, e.g. there is a sample of dropboxlogin and you can use that kind in dropboxsync like this:
dropboxsync.py
...
import dropboxlogin
...
x = dropboxlogin.get_client()
...
state_download_all(x) # i.e. one can use dropboxlogin as class to produce objects and manipulate them
My question in this situation is how to use dropboxlogin as a program not as class and also how to structure dropboxlogin so that it can be called as a program.
To use Cards.py as an example instead of dropboxlogin (too risky to test), which I have tried a bit. The result is not as expected:
a) calling Cards.py itself
import Cards
Cards
result: the Cards program would run after I exit the program
b) calling Cards as a class
import Cards
x=Cards.Game()
result: same as above
c) call run(Cards.Game())
import Cards
run(Cards.Game())
result: the game run immediately but when I exit the Cards game, the main python crashed and pythonista point to the line "run(Cards.Game())" and said "NameError: name 'run' is not defined
My question is
a) Is there anyway to call Cards.
b) Some of the sample module use run(Cards.Game()), some used if name == 'main" and some have nothing. Can you tell what should I use for developing these independent program for calling by others. In other words, is the Cards program having run(Cards.Game()) is the problem
Another question unrelated to above is that one of the small program would like to play a MP3 (in the background) and display a few photos. Is there anyway to call and play MP3 (even if I download that into my directory, if calling itune is too hard)
Sorry for such newbie questions.
For all your assistance and kind advice.
Dennis