Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed1.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; 'skip:[ 20': 0.04; '"""': 0.07; 'feature.': 0.09; 'filename': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'python': 0.11; 'filenames.': 0.16; 'notation': 0.16; 'path.': 0.16; 'read(self,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:python': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'skip:p 40': 0.19; '>>>': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'method': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'to:addr:python- list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'read': 0.60; "you'll": 0.62; 'more': 0.64; 'worth': 0.66; 'jul': 0.74; 'touch': 0.74; 'configparser': 0.84; 'silently': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: python backup script Date: Tue, 07 May 2013 08:18:11 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084ab28.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367907512 news.xs4all.nl 15935 [2001:888:2000:d::a6]:35600 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44875 Chris Angelico wrote: > It's also worth noting that the ~/ notation is a shell feature. You > may or may not be able to use it in config.read(). The latter. Combined with """ read(self, filenames) method of ConfigParser.ConfigParser instance Read and parse a filename or a list of filenames. Files that cannot be opened are silently ignored; this is ... """ you'll get no configuration at all. You have to apply os.path.expanduser() to get a valid path. $ cd $ touch tmp.config $ cd / $ python Python 2.7.2+ (default, Jul 20 2012, 22:15:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from ConfigParser import ConfigParser >>> p = ConfigParser() >>> p.read("~/tmp.config") [] >>> import os >>> p.read(os.path.expanduser("~/tmp.config")) ['/home/peter/tmp.config']