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


Groups > comp.lang.python > #8005

Re: opening a file

References <201106192300.38697.tjhanson@yahoo.com>
Date 2011-06-19 23:30 -0700
Subject Re: opening a file
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.175.1308551438.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Jun 19, 2011 at 11:00 PM, Tim Hanson <tjhanson@yahoo.com> wrote:
> 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?

As Dennis explained, no. At least, not directly. Python doesn't run
filepaths through the shell for expansion.

However, you can use os.path.expanduser() to make ~-paths work:
http://docs.python.org/library/os.path.html#os.path.expanduser

Cheers,
Chris

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


Thread

Re: opening a file Chris Rebert <clp2@rebertia.com> - 2011-06-19 23:30 -0700

csiph-web