Python argparse error NameError name file is not defined

0 votes

I am trying to run a speech to text script and here is a part of that code where I am getting error:

import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-f', dest=file, type=string)
args = parser.parse_args()

print args.file

But I am getting the folllowing error:

NameError: name 'file_name' is not defined
Nov 28, 2018 in Python by digger
• 26,700 points
7,845 views

1 answer to this question.

0 votes

The right datatype for destination in argpasrse module is string. So, you need to pass a string.

parser.add_argument('-f', dest="file", type=string)

answered Nov 28, 2018 by Omkar
• 69,130 points

Related Questions In Python

0 votes
1 answer

Python error "Python NameError: global name 'Thread' is not defined"

There is a built-in function with the ...READ MORE

answered May 31, 2019 in Python by Riya
3,913 views
–1 vote
1 answer

Python error saying "NameError: name 'email' is not defined"

you need to define the variable email READ MORE

answered Nov 29, 2019 in Python by Casper
• 160 points
3,684 views
0 votes
1 answer

Python Error saying "NameError: global name 'true' is not defined"

It's a very small mistake. Change true ...READ MORE

answered Jun 17, 2019 in Python by Vinayak
9,345 views
0 votes
1 answer

Error:Python NameError: name 'include' is not defined

Hello @kartik, On the basis of your information provided ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,720 points
2,693 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,059 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,573 views
0 votes
3 answers

Python error "NameError: name 'sr' is not defined"

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19, 2020 in Python by rahul
• 360 points
33,314 views
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,130 points
266 views