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


Groups > comp.lang.python > #8005 > unrolled thread

Re: opening a file

Started byChris Rebert <clp2@rebertia.com>
First post2011-06-19 23:30 -0700
Last post2011-06-19 23:30 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#8005 — Re: opening a file

FromChris Rebert <clp2@rebertia.com>
Date2011-06-19 23:30 -0700
SubjectRe: opening a file
Message-ID<mailman.175.1308551438.1164.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web