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


Groups > comp.lang.python > #8004

Re: opening a file

Subject Re: opening a file
From Paul Scott <pscott209@gmail.com>
References <201106192300.38697.tjhanson@yahoo.com> <BANLkTi=qVbrJUjfmrb9FDv+2rADzHDZEPA@mail.gmail.com>
Date 2011-06-20 08:29 +0200
Newsgroups comp.lang.python
Message-ID <mailman.174.1308551386.1164.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mon, 2011-06-20 at 08:14 +0200, 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

Regardless of the module that you use, you should also be using
os.path.join() to create paths. I never rely on hard coded paths
(especially since most of my code needs to run on multiple OS). In the
above example, you can easily put together a fairly complex path as
well, using os.path.join('foo', 'bar', 'prog', 'py_modules', ... ) which
will take care of what you need.

Not sure about regular python, but certainly in the wx GUI toolkit,
there is a wx.StandardPaths.Get() function which will get the user's
home or standard path where you can store all sorts of config data etc
in a hidden directory as well.

-- 
-- Paul

http://www.paulscott.za.net
http://twitter.com/paulscott56
http://www.chisimba.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: opening a file Paul Scott <pscott209@gmail.com> - 2011-06-20 08:29 +0200

csiph-web