Python NameError: name 'file' is not defined

4.7K    Asked by JamesLeeming in Python , Asked on Mar 9, 2021

I am trying to run a speech to text script and here is a part of that code where I am getting an 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 following error:

NameError: name 'file_name' is not defined

Answered by James Leeming

You can solve nameerror: name 'file' is not defined issue and the right data type for a destination in argpasrse module is a string. So, to solve the issue you need to pass a string in the arguments.

Below is the code for the same:-

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


Your Answer

Interviews

Parent Categories