Multiple if _name_ in python -


i'd write code execute function 2 following categories:

  1. single file
  2. multiple files

what's construct it? i'm thinking multiple if _name__.

#!/usr/bin/env python  def main(filename)     # 1 file.  if __name__ = '__main__'    single_filename = "file.txt"    main(single_filename)  # if _name__ ?? # multiple_files = ['file1.txt', 'file2.txt'] # file in multiple files: #    main(file) 

later i'd use argparse allow user decide whether want run on single file or multiple files.

if understand correctly needs, think best way test on arguments passed program.

def main(f):     pass  if __name__ == '__main__':     files = sys.argv[1:] # first argument name of program     f in files:         main(f) 

in cmd line, may run

python bar.py file1 file2 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -