How do I speedup this loop?
PPNTWIMBXFFC at spammotel.com
Tue Jul 13 09:30:35 CEST 2004
On Tue, 13 Jul 2004 16:48:36 +1000, Unknown <unknown at unknown.invalid>
> I'm getting some output by running a command using os.popen. I need to
> parse the output and transform it in some sense so that it's 'DB
> compatible', (i.e I need to store the output in a database (postgres)
> after escaping some characters).
If you are using Python's DB API 2.0 than this escaping would be done by
>>> import odbc,dbi
>>> con = odbc.odbc("DB_ID/USERNAME/PASSWORD")
>>> cur = con.cursor()
>>> sql = "INSERT INTO output (line) VALUES (?)"
>>> dirty_line = 'Some text with forbidden characters\n\r...'
>>> cur.execute(sql, dirty_line)
So, no need to parse (and afterwards unparse) the ouput - I don't think
that anyone can beat this speed up!
More information about the Python-list