opening a file

Hans Mulder hansmu at xs4all.nl
Mon Jun 20 06:08:30 EDT 2011


On 20/06/11 08:14:14, Florencio Cano 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?
>
> You can use the glob module:
> http://docs.python.org/library/glob.html#module-glob

The glob module does not do tilde expandsion.
If you want that, you need os.path.expanduser():
http://docs.python.org/library/os.path.html#os.path.expanduser

-- HansM




More information about the Python-list mailing list