Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!reader02.news.zen.co.uk.POSTED!not-for-mail From: Nobody Subject: Re: opening a file Date: Mon, 20 Jun 2011 11:01:19 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 15 Organization: Zen Internet NNTP-Posting-Host: a8df57b8.news.zen.co.uk X-Trace: DXC=:BY8[jMhB_okIQlb@g3\?fYjZGX^207Pk`@HC;obNQ<`Sf8^TaoTcjZU1>>UPh X-Complaints-To: abuse@zen.co.uk Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8008 On Sun, 19 Jun 2011 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')