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


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

Re: opening a file

Started byFlorencio Cano <florencio.cano@gmail.com>
First post2011-06-20 08:14 +0200
Last post2011-06-20 12:08 +0200
Articles 2 — 2 participants

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 Florencio Cano <florencio.cano@gmail.com> - 2011-06-20 08:14 +0200
    Re: opening a file Hans Mulder <hansmu@xs4all.nl> - 2011-06-20 12:08 +0200

#8001 — Re: opening a file

FromFlorencio Cano <florencio.cano@gmail.com>
Date2011-06-20 08:14 +0200
SubjectRe: opening a file
Message-ID<mailman.171.1308550457.1164.python-list@python.org>
> 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?

You can use the glob module:
http://docs.python.org/library/glob.html#module-glob

[toc] | [next] | [standalone]


#8009

FromHans Mulder <hansmu@xs4all.nl>
Date2011-06-20 12:08 +0200
Message-ID<4dff1c1e$0$49041$e4fe514c@news.xs4all.nl>
In reply to#8001
On 20/06/11 08:14:14, Florencio Cano 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?
>
> You can use the glob module:
> http://docs.python.org/library/glob.html#module-glob

The glob module does not do tilde expandsion.
If you want that, you need os.path.expanduser():
http://docs.python.org/library/os.path.html#os.path.expanduser

-- HansM

[toc] | [prev] | [standalone]


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


csiph-web