opening a file
Nobody
nobody at nowhere.com
Mon Jun 20 06:01:19 EDT 2011
On 2011年6月19日 23:00:38 -0700, Tim Hanson wrote:
> This works:
> infile=open('/foo/bar/prog/py_modules/this_is_a_test','r')
>> This doesn't:
> infile=open('~/prog/py_modules/this_is_a_test','r')
>> Can't I work with files using Unix expressions?
The argument is treated literally, just like C's fopen() etc. If you want
substitions, you have to perform them explicitly, e.g.:
infile=open(os.path.expanduser('~/prog/py_modules/this_is_a_test'),'r')
More information about the Python-list
mailing list