Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8008

Re: opening a file

From Nobody <nobody@nowhere.com>
Subject Re: opening a file
Date 2011-06-20 11:01 +0100
Message-Id <pan.2011.06.20.10.00.23.375000@nowhere.com>
Newsgroups comp.lang.python
References <mailman.170.1308550055.1164.python-list@python.org>
Organization Zen Internet

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

opening a file Tim Hanson <tjhanson@yahoo.com> - 2011-06-19 23:00 -0700
  Re: opening a file Nobody <nobody@nowhere.com> - 2011-06-20 11:01 +0100

csiph-web