Sunday 15 April 2012

python - String representation of file name -


I have a script that uses argparse to control command line arguments. An argument stdin or a filename can be the original code looks like this:

  import argype P = argparse.ArgumentParser () p.add_argument ('-' input, type = argparse.fileType ('R'), default = '-') args = p.parse_args () for line in args.input: print line   

In the second section of the code, The string representation is required. How do I get a string named this file? I was trying this way, without success:

  str (args.input) repr (args.input)    

Use the file object:

  args.input.name   

This is the file name of the open filebiz, or sys.stdin for .

No comments:

Post a Comment