Linked Questions
158 questions linked to/from How can I read and process (parse) command line arguments?
785
votes
11
answers
998k
views
How do I access command line arguments? [duplicate]
I use python to create my project settings setup, but I need help getting the command line arguments.
I tried this on the terminal:
$python myfile.py var1 var2 var3
In my Python file, I want to use ...
382
votes
15
answers
420k
views
What's the best way to parse command line arguments? [duplicate]
What's the easiest, tersest, and most flexible method or library for parsing Python command line arguments?
34
votes
4
answers
185k
views
Command line input in Python [duplicate]
Is it possible to run first the program then wait for the input of the user in command line.
e.g.
Run...
Process...
Input from the user(in command line form)...
Process...
31
votes
5
answers
59k
views
How can I process command line arguments in Python? [duplicate]
What would be an easy expression to process command line arguments if I'm expecting anything like 001 or 999 (let's limit expectations to 001...999 range for this time), and few other arguments passed,...
25
votes
6
answers
36k
views
Can sys.argv handle optional arguments? [duplicate]
from sys import argv
script, lira_cbt, [eur_hedge] = argv
if eur_hedge == None:
#Do x
else:
#Do y
I want it to be able to run with just lira_cbt as an argument (doing x), or with both ...
15
votes
3
answers
69k
views
Pass arguments from cmd to python script [duplicate]
I write my scripts in python and run them with cmd by typing in:
C:\> python script.py
Some of my scripts contain separate algorithms and methods which are called based on a flag.
Now I would like ...
10
votes
3
answers
54k
views
Python: pass arguments to a script [duplicate]
I have a working code to print random lines from a csv column.
#!/usr/bin/python
import csv
from random import shuffle
filename = 'example.csv'
col = 2
sample = 100
with open(filename, 'r') as f:
...
4
votes
3
answers
18k
views
handling an empty (sys.argv[1]) [duplicate]
I am writing a script that controls volume. The name of the script is vv , and it expects one argument. for example vv .9 where .9 is the level you want to set the volume. That program works as ...
4
votes
2
answers
17k
views
Passing directory to python script as command line argument [duplicate]
I am trying to pass a particular directory to a python script and later use that directory in the script . the Directory can be located anywhere.
for example, the script should run on the command ...
1
vote
4
answers
6k
views
How can I run a python code with input on Linux terminal? [duplicate]
I have a file named myadd.py that contains only the following function:
def myadd(a,b):
return a+b
How can I run it on Linux terminal?
I am looking for something easy like this:
python myadd 2,3
...
2
votes
3
answers
882
views
how to execute a python script file with an argument? [duplicate]
Possible Duplicate:
Command Line Arguments In Python
Example:
itp.threads[0].memload(r"c:\FistForSOCAD_PASS.bin","0x108000P")
itp.threads[0].cv.cip = "0x108000"
itp.go()
itp.halt()
I would like ...
1
vote
2
answers
8k
views
Pass command line argument to python script [duplicate]
I have a file.py that I want to pass base_url to when called, so that base_url variable value can be dynamic upon running python file.py base_url='http://google.com' the value of http://google.com ...
1
vote
4
answers
2k
views
How can I give parameters to a function of a python script through the command-line? [duplicate]
Currently this is my python script (TagGen) which has one function:
def SJtag(file,len_tag):
import csv
reader = csv.reader(open(file), dialect='excel-tab' )
for row in reader:
...
1
vote
3
answers
2k
views
send --port argument to python [duplicate]
I have this code:
#!flask/bin/python
import subprocess
import types
from flask import Flask, jsonify, make_response, abort, request, url_for
app = Flask(__name__)
@app.route('/v1/kill/process/<...
1
vote
2
answers
2k
views
Passing arguments to a python program from the command line, anything better than sys.argv? [duplicate]
I have a python script that I'd like to run from the terminal, and it takes about 10 numerical arguments. So far the only way i can think of passing the arguments to the program is as follows:
python ...