opening a file

T

Tim Hanson

Using linux and Python 2.6, learning how to work with files from a Windows
oriented textbook:

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?
 
N

Nobody

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')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,423
Latest member
henerygril

Latest Threads

Top