John
John

Reputation: 21

running a script from github

I've been learning python for a few weeks, so please be easy on me. I'm running a script from github

https://github.com/arosen93/ptable_trends/

Really not sure what I'm doing wrong - I should just need to edit this line

parser.add_argument('filename',type=str,help='Filename (with extension) of ''CSV-formatted data')

change to;

parser.add_argument('C:/Users/PycharmProjects/periodictable/ionization_energies.csv',type=str,help='Filename (with extension) of 'CSV-formatted data')

Constantly get error messages

main.py: error: the following arguments are required: C:/Users/LE403 mk2/PycharmProjects/periodictable/ionization_energies.csv

Upvotes: 2

Views: 44

Answers (1)

Schwern
Schwern

Reputation: 165200

tl;dr: You should run ptable_trends.py --filename C:/Users/PycharmProjects/periodictable/ionization_energies.csv from your command line. You should not have to edit the code.

parser.add_argument tells the program what arguments it accepts.

parser.add_argument('filename',type=str,help='Filename (with extension) of '
        'CSV-formatted data')

This calls the add_argument method of the class ArgumentParser from the argparse library. It says the program takes the argument --filename which is a string and the help message about that argument tells you it is a "Filename (with extension) of CSV-formatted data".

If you write in your main.py...

parser.add_argument('C:/Users/PycharmProjects/periodictable/ionization_energies.csv',type=str,help='Filename (with extension) of 'CSV-formatted data')

That says your main.py takes an argument of --C:/Users/PycharmProjects/periodictable/ionization_energies.csv which is a string to a "Filename (with extension) of 'CSV-formatted data" which doesn't make any sense.


There is an escaped quote in the original, the `''`.
>>> 'Filename (with extension) of ''CSV-formatted data'
'Filename (with extension) of CSV-formatted data'

You lost the escape.

>>> 'Filename (with extension) of 'CSV-formatted data'
  File "<stdin>", line 1
    'Filename (with extension) of 'CSV-formatted data'
                                   ^
SyntaxError: invalid syntax

Your quotes are "unbalanced". The quote should probably be removed entirely.

Upvotes: 1

Related Questions