Passing Arguments To Python Script From Command Line
I am really new to python and pandas, I am trying to execute a python script using arguments in the command line but I got an error, here is my script #!/usr/bin/python import sy
Solution 1:
sys.argv[0]
is the name of the script, i.e. merge_files.py
. You can see this by inserting print(sys.argv)
at the beginning of your script. Try increasing all your indices by 1.
Solution 2:
The first argument sys.argv[0]
is the name of the script.
sys.argv: The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not).
Please look here for more details.
#!/usr/bin/python
import sys, pandas as pd
df1 = pd.read_table(sys.argv[1], sep="\t", header=0)
df2 = pd.read_table(sys.argv[2], sep="\t", header=0)
df_merge = pd.merge(left=df1, right=df2, left_on=sys.arg[3], right_on=sys.arg[4])
df_merge.to_csv(sys.arg[5], sep="\t")
This should work.
Solution 3:
increase all your indexes by 1, because sys.argv[0]
- is a name of the python script.
I.e.
df1 = pd.read_table(sys.argv[1], sep="\t", header=0)
df2 = pd.read_table(sys.argv[2], sep="\t", header=0)
and so on
Post a Comment for "Passing Arguments To Python Script From Command Line"