I want to be able to take a string like below and pull out the first parameter (id) and then use that to print it out. I have been looking into split for python, but I usually have to split 2 or 3 times before getting something usable.
Here is an example of the strings I am trying to parse:
EntryError(u"(sqlite3.IntegrityError) UNIQUE constraint failed:
role.name, role.domain_id [SQL: u'INSERT INTO table1 (id, name,
domain_id, extra) VALUES (?, ?, ?, ?)'] [parameters: ('id',
'fake1name', '<<null>>', '{}')]",)
I have tries things like:
e = e.split("\'")
e = e.split(",")
But this gives me weird strings that have to further be parsed. Is there an easier way to always pull the id from "[parameters: ('id', 'fake1name', '<<null>>', '{}')]"?
Here's the code I have:
except exception.EntryError as e:
query = str(e)
# example of me using split to try and reduce the string
parsedstr = query.split("[")
parsedstr = parsedstr.split("\'")
# This will give me id like I want but it doesn't seem efficient
# prints: id
print parsedstr[1]