A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/301995.html below:

File processing

File processingJeremy Jones zanesdad at bellsouth.net
Fri Sep 23 08:38:47 EDT 2005
Gopal wrote:

>Thanks for the reference. However, I'm not understanding how to use it.
>Could you please provide with an example? Like I open the file, read
>line and give it to parser?
>
>Please help me.
>
>  
>
I had thought of recommending what Peter Hansen recommended - just 
importing the text you have as a Python module.  I don't know why I 
recommended ConfigParser over that option.  However, if you don't like 
what Peter said and would still like to look at ConfigParser, here is a 
very simple example.  Here is the config file I created from your email:

jmjones at qiwi  8:36AM configparser % cat foo.txt
[main]
PROJECT_ID = "E4208506"
SW_VERSION = "18d"
HW_VERSION = "2"


Here is me running ConfigParser from a Python shell:

In [1]:  import ConfigParser

In [2]:  p = ConfigParser.ConfigParser()

In [3]:  p.read("foo.txt")
Out[3]:  ['foo.txt']

In [4]:  p.get("main", "PROJECT_ID")
Out[4]:  '"E4208506"'


Note that the value of ("main", "PROJECT_ID") is a string which contains 
double quotes in it.  If you take Peter's advice, you won't have that 
problem; the config file will preserve your types for you.

HTH,

- JMJ

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4