Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8003 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2011-06-19 23:24 -0700 |
| Last post | 2011-06-19 23:24 -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.
Re: opening a file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-06-19 23:24 -0700
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2011-06-19 23:24 -0700 |
| Subject | Re: opening a file |
| Message-ID | <mailman.173.1308551085.1164.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web