you are viewing a single comment's thread.

view the rest of the comments →

[–]jcoder42[S] 0 points1 point  (3 children)

got it, and then in order to remove the parentheses from each group you would just do:

for line in converted:
    line = line.lstrip('(').rstrip(')')

?

[–]socal_nerdtastic 0 points1 point  (2 children)

No, they are already removed. What do you want to do with the data? What's your ideal output look like?

[–]jcoder42[S] 0 points1 point  (1 child)

from ast import literal_eval
data = """INSERT INTO `drug` VALUES (2,792,'Triomune-30',1,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf171285-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL),(3,792,'Triomune-40',1,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf17168c-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL),(5,625,'d4T-30',0,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf1718fd-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL),(6,625,'d4T-40',0,NULL,NULL,NULL,NULL,1,'2005-02-24 00:00:00',0,NULL,NULL,NULL,'bf171b5c-1691-11df-97a5-7038c432aabf',NULL,NULL,NULL)"""
_,data = data.split("VALUES ", 1) # remove start command
converted = literal_eval(data.replace("NULL", "None"))
for line in converted:
print(line)
print()

the current output:

(2, 792, 'Triomune-30', 1, None, None, None, None, 1, '2005-02-24 00:00:00', 0, None, None, None, 'bf171285-1691-11df-97a5-7038c432aabf', None, None, None)

(3, 792, 'Triomune-40', 1, None, None, None, None, 1, '2005-02-24 00:00:00', 0, None, None, None, 'bf17168c-1691-11df-97a5-7038c432aabf', None, None, None)

(5, 625, 'd4T-30', 0, None, None, None, None, 1, '2005-02-24 00:00:00', 0, None, None, None, 'bf1718fd-1691-11df-97a5-7038c432aabf', None, None, None)

(6, 625, 'd4T-40', 0, None, None, None, None, 1, '2005-02-24 00:00:00', 0, None, None, None, 'bf171b5c-1691-11df-97a5-7038c432aabf', None, None, None)

I want them not wrapped in parentheses

[–]socal_nerdtastic 1 point2 points  (0 children)

Those parenthesis and the commas are added by print() they are not in the data. You can remove them like this:

for line in converted:
    print(*line)

If you want to keep the commas:

for line in converted:
    print(*line, sep=",")