quinngroup / dr1dl-pyspark

Dictionary Learning in PySpark
Apache License 2.0
1 stars 1 forks source link

Use argparse for command-line arguments #1

Closed magsol closed 8 years ago

magsol commented 8 years ago

Finish filling out the command-line arguments in terms of the argparse package in Python.

MOJTABAFA commented 8 years ago

First of all sorry because I'm a beginner in python, actually I've wrote the following code but I dont know why there is some error , I think I should recall the values from somewhere but I need some help:

import argparse import sys

def main():

parser = argparse.ArgumentParser(description='close bug')

parser = argparse.ArgumentParser(description = 'PySpark Dictionary Learning',
    add_help = 'How to use', prog = 'python code1.py <args>')
parser.add_argument("-i", "--input", required = True,
    help = "Input File name.")
parser.add_argument("-d", "--dictionary", required = True,
    help = "Dictionary File name.")
parser.add_argument("-o", "--output", required = True,
    help = "Output File name.")
parser.add_argument("-s", "--summary", required = True,
    help = "Summary File name.")
parser.add_argument("-l", "--length", type = int, required = True,
    help = "Length of the samples.")
parser.add_argument("-P", "--pnumeber", type = int, required = True,
    help = "Number of the samples.")
parser.add_argument("-m", "--mDicatom", type = int, required = True,
    help = "Number of the dictionary atoms.")
parser.add_argument("-e", "--epsilon", type = float, required = True,
    help = "The value of epsilon.")
args = vars(parser.parse_args())

print(args['input'])
print(args['dictionary'])
print(args['output'])
print(args['summary'])

if name == "main": main()

magsol commented 8 years ago

What is the error message?

On Nov 14, 2015, at 20:08, MOJTABAFA notifications@github.com wrote:

First of sorry because I'm a beginner in python, actually I've wrote the following code but I dont know why there is some error , I think I should recall the values from somewhere but I need some help:

import argparse import sys

def main():

parser = argparse.ArgumentParser(description='close bug')

parser = argparse.ArgumentParser(description = 'PySpark Dictionary Learning', add_help = 'How to use', prog = 'python code1.py ') parser.add_argument("-i", "--input", required = True, help = "Input File name.") parser.add_argument("-d", "--dictionary", required = True, help = "Dictionary File name.") parser.add_argument("-o", "--output", required = True, help = "Output File name.") parser.add_argument("-s", "--summary", required = True, help = "Summary File name.") parser.add_argument("-l", "--length", type = int, required = True, help = "Length of the samples.") parser.add_argument("-P", "--pnumeber", type = int, required = True, help = "Number of the samples.") parser.add_argument("-m", "--mDicatom", type = int, required = True, help = "Number of the dictionary atoms.") parser.add_argument("-e", "--epsilon", type = float, required = True, help = "The value of epsilon.")

args = vars(parser.parse_args())

print(args['input']) print(args['dictionary']) print(args['output']) print(args['summary']) if name == "main": main()

— Reply to this email directly or view it on GitHub.

MOJTABAFA commented 8 years ago

The following message is appeared is console( by the way I'm using Python 3.5 and Sublime Text 3) :

usage: python code1.py [-h] -i INPUT -d DICTIONARY -o OUTPUT -s SUMMARY -l LENGTH -P PNUMEBER -m MDICATOM -e EPSILON python code1.py : error: the following arguments are required: -i/--input, -d/--dictionary, -o/--output, -s/--summary, -l/--length, -P/--pnumeber, -m/--mDicatom, -e/--epsilon [Finished in 0.2s with exit code 2]

magsol commented 8 years ago

Read the error message: "the following arguments are required." It's not running because you specified the arguments as required in the Python code, but didn't feed them in when you ran the program.

iPhone'd

On Nov 14, 2015, at 21:21, MOJTABAFA notifications@github.com wrote:

The following message is appeared is console( by the way I'm using Python 3.5 and Sublime Text 3) :

usage: python code1.py [-h] -i INPUT -d DICTIONARY -o OUTPUT -s SUMMARY -l LENGTH -P PNUMEBER -m MDICATOM -e EPSILON python code1.py : error: the following arguments are required: -i/--input, -d/--dictionary, -o/--output, -s/--summary, -l/--length, -P/--pnumeber, -m/--mDicatom, -e/--epsilon [Finished in 0.2s with exit code 2]

— Reply to this email directly or view it on GitHub.

MOJTABAFA commented 8 years ago

yeah Thanks, but how should I feed them during running ? I mean through a function or ?

magsol commented 8 years ago

python scriptname.py -opt1 arg1 -opt2 arg2

And so forth.

On Nov 14, 2015, at 21:26, MOJTABAFA notifications@github.com wrote:

yeah Thanks, but how should I feed them during running ? I mean through a function or ?

— Reply to this email directly or view it on GitHub.

MOJTABAFA commented 8 years ago

Ok Thank you very much , let me check it ...