Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8000 > unrolled thread
| Started by | Tim Hanson <tjhanson@yahoo.com> |
|---|---|
| First post | 2011-06-19 23:00 -0700 |
| Last post | 2011-06-20 11:01 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | Tim Hanson <tjhanson@yahoo.com> |
|---|---|
| Date | 2011-06-19 23:00 -0700 |
| Subject | opening a file |
| Message-ID | <mailman.170.1308550055.1164.python-list@python.org> |
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?
[toc] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-06-20 11:01 +0100 |
| Message-ID | <pan.2011.06.20.10.00.23.375000@nowhere.com> |
| In reply to | #8000 |
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')
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web