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


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

Re: opening a file

Started byPaul Scott <pscott209@gmail.com>
First post2011-06-20 08:29 +0200
Last post2011-06-20 08:29 +0200
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.


Contents

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

#8004 — Re: opening a file

FromPaul Scott <pscott209@gmail.com>
Date2011-06-20 08:29 +0200
SubjectRe: opening a file
Message-ID<mailman.174.1308551386.1164.python-list@python.org>

[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

[toc] | [standalone]


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


csiph-web