Hi, I'm trying to use argparse to enter a name from the command line, but I'm struggling to get it working.I want to take the line passed from the command line (-d) that matches the file name (datbase.csv) and save it in the variable inputargs.snp_database_location.
This is used to enter my load_search_snaps function, as shown in my code below, which opens a file and does the stuff (pseudocode) for it.
import csv, sys, argparse
parser = argparse.ArgumentParser(description='Search a list of variants against the in house database')
parser.add_argument('-d', '--database',
action='store',
dest='snp_database_location',
type=str,
nargs=1,
help='File location for the in house variant database',
default='Error: Database location must be specified')
inputargs = parser.parse_args()
def load_search_snps(input_file):
with open(input_file, 'r+') as varin:
id_store_dictgroup = csv.DictReader(varin)
return result
load_search_snps(inputargs.snp_database_location)
using the command in bash:
python3 snp_freq_V1-0_export.py -d snpstocheck.csv
I get the following error when trying to transfer its regular csv file from the same directory using the command line:
"snp_freq_V1-0_export.py", 33, load_search_snps (input_file, 'r +') varin: TypeError: : ['snpstocheck.csv']
script, . , snp_database_location, , . , ?