Thursday, 15 March 2012

How to parse file as an argument to python function? -



How to parse file as an argument to python function? -

currently, have next script multiple sub tasks , want create each sub task function , provide same file input functions.

current :

import sys open(sys.argv[1], 'r') my_file: print(my_file.append()) print(my_file.split())

want:

import sys def append(file) return; def split(file) return; def main() append(file) split(file) main()

so want pass file/dir name @ run time.

thanks.

or can utilize argparse, in orderto solve problem

https://docs.python.org/dev/library/argparse.html

python function

No comments:

Post a Comment