473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ConfigObj quoting issues

Hi,

I am using ConfigObj to write email addresses, as a list. I am using
email module functions to extract email addresses:

to_address = header.get_all('To', [])
address_list = getaddresses(to_address)
to = map(lambda address: '"'+address[0]+'"
<'+address[1]+'>' ,address_list)
conf_obj['to'] = to

But quite often I am getting the error "cannot be safely quoted.".
This error is because of the presence of \', \", \n etc.

I had to do the following to make it work.
address[i].replace("\'",'').replace('\"','').replace('\n','' )

[making list_all=False doesn't work properly(it fails when the first
character is a double quote). ]

I don't want to do the above, as it modifies the email address (name).
In brief, my question is how to save a list of strings which might
have quotes, double quotes to a file using ConfigObj.

Any idea what is to be done.

Thanks
Roopesh
Jun 27 '08 #1
1 976
On 14:25, martedì 03 giugno 2008 Roopesh wrote:
This error is because of the presence of \', \", \n etc.

I had to do the following to make it work.
address[i].replace("\'",'').replace('\"','').replace('\n','' )
it's rather ugly :)
I suggest use re module as follow:

import re
address[i] = re.sub('(`|"|\n)',re.MULTILINE,address[i])

if you've a big chunck of email it'd be fine to compile the regex.

match = re.compile(`|"|\n)
address[i] = match.sub(address[i])

I think there would be a problem with unicode email addresses. But I doubt
the existance of unicode addresses nowadays.
Unsure for the syntax, pls check
http://www.python.org/doc/2.4/lib/re-syntax.html
^^^ according your version, but they're quitethe
same

--
Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fuzzyman | last post by:
A few functions I'm 'making available' (FWIW) and also a new project I'm starting.... http://www.voidspace.org.uk/atlantibots/pythonutils.html Slight updates to ConfigObj and StandOut (simple...
4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
22
by: Jane Withnolastname | last post by:
I have been using the charset windows-1252 for a while, but it was pointed out to someone else in this group recently that it's a Microsoft creation (I'm sure I'm getting my facts wrong or skewed)...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
0
by: Fuzzyman | last post by:
The response to pythonutils__ was very good. Especially the odict__ module (ordered dictionary) - it's had over one hundred and fifty downloads already. Thanks to some useful user feedback, Nicola...
27
by: Ron Adam | last post by:
Hi, I found the following to be a useful way to access arguments after they are passed to a function that collects them with **kwds. class namespace(dict): def __getattr__(self, name): return...
0
by: Fuzzyman | last post by:
Hello All, I've added (optional) unicode support for ConfigObj. This is now available from SVN. You can specify an encoding to decode the config file on reading. This maps to an encoding...
1
by: Bruce | last post by:
I assume that you know the module configobj. I use it like this: I have a config_file : ] a = 1 b = 2 ] a = 3 b = 1
7
by: Steven W. Orr | last post by:
Python has a number of "quoting" 'options' to help """with times when""" one way may be more convenient than another. In the world of shell scripting, I use a technique that I call minimal...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.