Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'script,': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'linux': 0.11; 'subject:file': 0.14; '"r")': 0.16; '2.6,': 0.16; 'bieber': 0.16; 'declaimed': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'expression"': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'os.environ': 0.16; 'received:66.245': 0.16; 'received:dsl.mindspring.com': 0.16; 'received:mindspring.com': 0.16; 'received:wlfraed': 0.16; 'subject:opening': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'shell': 0.19; 'command': 0.19; 'variable': 0.21; 'yourself.': 0.22; 'oriented': 0.23; 'suspect': 0.25; 'url:home': 0.25; 'windows': 0.26; 'lee': 0.29; 'module': 0.30; 'sun,': 0.30; 'environment': 0.30; "can't": 0.32; 'represents': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'skip:" 20': 0.33; '-0700,': 0.35; 'using': 0.35; 'charset :us-ascii': 0.36; 'received:org': 0.38; 'subject:: ': 0.38; "i'd": 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'unix': 0.40; 'really': 0.40; 'information,': 0.63; 'dennis': 0.77; '(home': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: opening a file Date: Sun, 19 Jun 2011 23:24:34 -0700 Organization: > Bestiaria Support Staff < References: <201106192300.38697.tjhanson@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: user-11fae1t.dsl.mindspring.com X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 29 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308551086 news.xs4all.nl 49042 [::ffff:82.94.164.166]:59291 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8003 On Sun, 19 Jun 2011 23:00:38 -0700, Tim Hanson declaimed the following in gmane.comp.python.general: > Using linux and Python 2.6, learning how to work with files from a Windows > oriented textbook: > > 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? I'd suspect not -- if that "Unix expression" really means a SHELL expression... The command shell is responsible for translating the ~ into whatever it represents (home directory?). Inside a Python script, you'll need to use the os.environ module to retrieve the environment variable that represents the same information, and join them yourself. infile = open(os.path.join(os.environ["HOME"], "prog/.../...test"), "r") -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/