python - process_file(sys.argv[1]) IndexError: list index out of range -


This is the code with which I work with practical programming:

  import sys 'Input' file for the row in the input file = open (file name, 'r') '' '' '' Open, read and print file '' '' input_file: line = line.stip () print Line input_file.close () After importing this module into IDLE and passing a text file argument through process_file (), I get this error : (___name__ == "__main__": process_file (sys.argv [1])  

traceback (most recent call final): the file " Lt; pyshell # 8 & gt; ", line1, & lt; module & gt; Process_file (" data.txt ") file" C: \ Python26 \ read_file_2.py ", in line 14, process_file process_file (sys.argv [1]) Index Error: List index out of range

How can I get this program done without getting this error? Any help is appreciated.

It looks like you

 < Code> if __name__ == "__man__": process_file (sys.argv [1])  

block process_file at the same indentation level as the rest , So when you call process_file from any other module, it is being run; I suspect that your problem may be happening - it is unrelated, so if < / Code> def in line with


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -