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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -