Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing commandline arguments to QPython

I am running a simple client-server program written in python, on my android phone using QPython and QPython3. I need to pass some commandline parameters. How do I do that?

like image 707
Pacu Avatar asked Feb 03 '26 20:02

Pacu


1 Answers

I found a couple of way of running a script that I imported from my Linux laptop.

If I put frets.py in the script3 directory, and create this script in the same directory:

import sys, os
dir = '/storage/emulated/0/com.hipipal.qpyplus/scripts3/'
os.chdir(dir)        
def callfrets(val):
    os.system(sys.executable+" frets.py " + val)
while True:
    val = input('$:')
    if val:
        callfrets(val)
    else:
        break

I can run the program with the same commandline inputs that I used in Linux, getting output on the console. Just invoke this script from the editor or the programs menu.

I also found (after getting some argparse errors) that I can get to a usable Linux shell by quiting the Python console with sys.exit(1):

import sys
sys.exit(1)

drops me into the shell with the / directory. Changing directory

cd /storage/emulated/0/Download  # or to the scripts3 directory

lets me run that original script directly

python frets.py -a ...

This shell has the necessary permisions and $PATH (/data/data/com.hipipal.qpy3/files/bin).

(I had problems getting this working on my phone, but updating Qpython3 took care of that.)

like image 54
hpaulj Avatar answered Feb 06 '26 20:02

hpaulj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!