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: 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 To: Florencio Cano In-Reply-To: References: <201106192300.38697.tjhanson@yahoo.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --=-8NP3qtnTWQJ11+IkJCX+ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 2011-06-20 at 08:14 +0200, Florencio Cano wrote: > > This works: > > infile=3Dopen('/foo/bar/prog/py_modules/this_is_a_test','r') > > > > This doesn't: > > infile=3Dopen('~/prog/py_modules/this_is_a_test','r') > > > > Can't I work with files using Unix expressions? >=20 > 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. --=20 -- Paul http://www.paulscott.za.net http://twitter.com/paulscott56 http://www.chisimba.com --=-8NP3qtnTWQJ11+IkJCX+ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAABAgAGBQJN/ujDAAoJEDSS+OcjMBmy2xoH/1fGMfvd9XycELnRWS3f2Vcd 1Zy416I8ByxdnWEb+GJgupWTxwIE4ucYdmCIie8QI8Co351RnvsTaClex6qhWY9O qA8lMEDoFbgJKYhjU5n2jmFLActNDKqyet8RNq81ALrM0i4Mf0jHJwnv31RPdBPD EAK3weh+yE/don5pV6bSsVrFAqN7TUsA8IVPQ7i9+BeZMMXm1J090yYbfQPeuGa4 6TG7KCjDReMy+DcaMQSTi+DJ7gU5wkaTqp1bEwUyM5Ire/+apVP1+qo7NwDGTsVM Dzk2Ct/dBgHexNvgCMpmeNgOL7zLuJihB6iaYYf07JwmPtA0GNoQo81Rf5jnoAk= =W6yn -----END PGP SIGNATURE----- --=-8NP3qtnTWQJ11+IkJCX+--