Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8003
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: opening a file |
| Date | 2011-06-19 23:24 -0700 |
| Organization | > Bestiaria Support Staff < |
| References | <201106192300.38697.tjhanson@yahoo.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.173.1308551085.1164.python-list@python.org> (permalink) |
On Sun, 19 Jun 2011 23:00:38 -0700, Tim Hanson <tjhanson@yahoo.com>
declaimed the following in gmane.comp.python.general:
> 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?
I'd suspect not -- if that "Unix expression" really means a SHELL
expression...
The command shell is responsible for translating the ~ into whatever
it represents (home directory?).
Inside a Python script, you'll need to use the os.environ module to
retrieve the environment variable that represents the same information,
and join them yourself.
infile = open(os.path.join(os.environ["HOME"], "prog/.../...test"), "r")
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: opening a file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-06-19 23:24 -0700
csiph-web