B
B
Bur Ov2022-03-23 02:53:23
Python
Bur Ov, 2022-03-23 02:53:23

How to properly split a string in python?

Good afternoon. What is the correct way to split such a string in Python into an array of data?

(726928131,'Данные','3-и Данные (111), данные','9',NULL,NULL,NULL,NULL,1,'Данные, Данные, Данные', 9,NULL,NULL,2545580,1)

At first I just tried to split by comma, but somewhere there is data in quotes, where there are also commas. Then I tried on the apostrophe, but somewhere it is not there. How then to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vilinyh, 2022-03-23
@burov0798

Do not use regular expressions where they are not needed. Your string is a normal CSV.

import csv

scsv = '''726928131,'Данные','3-и Данные (111), данные','9',NULL,NULL,NULL,NULL,1,'Данные, Данные, Данные', 9,NULL,NULL,2545580,1'''

row = next(csv.reader([scsv], delimiter=','))

print(row)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question