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


Groups > comp.lang.python > #44875

Re: python backup script

From Peter Otten <__peter__@web.de>
Subject Re: python backup script
Date 2013-05-07 08:18 +0200
Organization None
References <b586db98-78b2-40a6-9e1c-3d8b939657c8@googlegroups.com> <CAPTjJmoZWzQSDV4sE8nVq8bSeyx0M8UDCkxkmLbaOz2TXqxtBg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1396.1367907512.3114.python-list@python.org> (permalink)

Show all headers | View raw


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']

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 12:01 -0700
  Re: python backup script Jerry Hill <malaclypse2@gmail.com> - 2013-05-06 15:11 -0400
    Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 12:20 -0700
      Re: python backup script Matt Jones <matt.walker.jones@gmail.com> - 2013-05-06 14:46 -0500
        Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 13:37 -0700
          Re: python backup script Matt Jones <matt.walker.jones@gmail.com> - 2013-05-06 16:08 -0500
  Re: python backup script Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> - 2013-05-06 23:44 +0200
    Re: python backup script Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> - 2013-05-06 23:48 +0200
      Re: python backup script mina@socialassets.org - 2013-05-06 15:12 -0700
        Re: python backup script John Gordon <gordon@panix.com> - 2013-05-06 22:15 +0000
          Re: python backup script Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> - 2013-05-07 21:11 +0200
        Re: python backup script MRAB <python@mrabarnett.plus.com> - 2013-05-06 23:28 +0100
      Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 15:15 -0700
  Re: python backup script Chris Angelico <rosuav@gmail.com> - 2013-05-07 08:12 +1000
    Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 15:40 -0700
      Re: python backup script Chris Angelico <rosuav@gmail.com> - 2013-05-07 08:51 +1000
      Re: python backup script MRAB <python@mrabarnett.plus.com> - 2013-05-06 23:52 +0100
  Re: python backup script Peter Otten <__peter__@web.de> - 2013-05-07 08:18 +0200

csiph-web