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


Groups > comp.lang.python > #8004

Re: opening a file

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <pscott209@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'sorts': 0.04; '(especially': 0.07; 'paths': 0.07; '+0200,': 0.09; 'content-type:multipart/signed': 0.09; 'gui': 0.14; 'subject:file': 0.14; 'wrote:': 0.14; 'coded': 0.16; 'content- type:application/pgp-signature': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname piece:signature': 0.16; 'filename:fname:signature.asc': 0.16; 'module:': 0.16; 'paths.': 0.16; 'subject:opening': 0.16; 'received:74.125.82.174': 0.16; 'received:mail-wy0-f174.google.com': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; "user's": 0.23; 'code': 0.24; 'certainly': 0.25; 'function': 0.25; 'paul': 0.28; 'cc:addr:python.org': 0.30; 'fairly': 0.30; 'module': 0.30; 'config': 0.30; 'url:library': 0.31; "can't": 0.32; "skip:' 10": 0.32; '...': 0.34; 'regular': 0.34; 'regardless': 0.34; 'example,': 0.35; 'there': 0.35; 'store': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'url:docs': 0.37; 'put': 0.37; 'url:python': 0.38; 'received:74.125.82': 0.38; 'received:74.125': 0.38; 'url:org': 0.38; 'run': 0.38; 'but': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'should': 0.39; 'header :Mime-Version:1': 0.39; 'unix': 0.40; 'easily': 0.60; 'url:net': 0.63; 'home': 0.69; 'care': 0.72
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:from:to:cc:in-reply-to:references :content-type:date:message-id:mime-version:x-mailer; bh=BbTnrTE3cZ3Nc1O+aQw8sixll/L1ehrPzr/bl8L0xaU=; b=Ch8jSq3qhP/D8N6Rob0ZXIFcP8M8dyD9ByQkAG8DedRB9TrxVtFq0zpwmIoo5arCR7 b1vuMldlgXupQPZPrnYrcJrSvnN9bB9mubupeHsck/XUTacG6IyRgZHZlKy6t6M0MEUW hWWUbMhmMxbbX/e+eM4BbAyMjOFAyUVlKeqeg=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer; b=POXsPfRHbLl2IvEgme9/L6QQzxXWgHTemi09AIkjvDe33ewpXdTJAA1ByjftuN4iuT eQ7cKlFhF2EOmS0bfAK+pYg/ucap38Hr+/KyOzGoyxyGFz1OIwQTBUsR2Vl+xlyRpAEg U6k92jriVCHtvw8yEqQJ+946mDZMvoFyRofys=
Subject Re: opening a file
From Paul Scott <pscott209@gmail.com>
To Florencio Cano <florencio.cano@gmail.com>
In-Reply-To <BANLkTi=qVbrJUjfmrb9FDv+2rADzHDZEPA@mail.gmail.com>
References <201106192300.38697.tjhanson@yahoo.com> <BANLkTi=qVbrJUjfmrb9FDv+2rADzHDZEPA@mail.gmail.com>
Content-Type multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-8NP3qtnTWQJ11+IkJCX+"
Date Mon, 20 Jun 2011 08:29:24 +0200
Mime-Version 1.0
X-Mailer Evolution 2.32.2
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.174.1308551386.1164.python-list@python.org> (permalink)
Lines 54
NNTP-Posting-Host 82.94.164.166
X-Trace 1308551386 news.xs4all.nl 49039 [::ffff:82.94.164.166]:35813
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8004

Show key headers only | 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