Click " Python Shared House " above to follow

Reply to " Resources " to get Python learning materials

this

day

chicken

soup

The article hates life, and the charm is gratifying.

Hello everyone, I'm Pippi.

I. Introduction

A few days ago in the Python exchange Baiyin group [Mortals are not annoying], I asked a question to Pythondeal with, as shown in the figure below.

picture

Second, the realization process

Here [Mr. Yu Liang] gave an idea and code, which encodes the object into a string, and  json.dumps()converts the sum in and into the type in the process. Therefore, the parentheses of the tuple are converted to the square brackets of the array.pythonJsonpythonlisttuplejsonarray

f-stringUse the write file directly , and when you read it below eval, it will be restored to pythonthe listtype in .

draw_data = [{"tm": 275, "ab": [(753, 747), (755, 749)], "a""0.607514""b""0.425784""lW": 2, "cr""#1795ff""pg": 27},
             {"tm": 281, "ab": [(713, 755)], "a""0.574740""b""0.430732""lW": 2, "cr""#ee4844""pg": 27}]

with open(f'draw.json''w') as f1:
    f1.write(f'{draw_data}')
with open(f'draw.json''r') as f2:
    data = eval(f2.read())
    print(type(data))
    print(data)

The running result is shown in the following figure:

picture

Solve the fans' problems smoothly!

3. Summary

Hello everyone, I'm Pippi. This article mainly takes stock of a Pythonstring processing problem. The article gives specific analysis and code implementation for this problem, helping fans to solve the problem smoothly.

Finally, I would like to thank the fans [Mortals are not annoying] for asking questions, [Mr. Yu Liang] and [Luna] for their ideas and code analysis, and [dcpeng], [Feng Cheng], [such creatures], and [Cat Pharmacist Kelly] Participate in learning exchanges.

If you encounter any problems during the learning process, please feel free to contact me to solve them (my WeChat: pdcfighting). At the request of fans, I have created some high-quality Pythonpaid learning exchange groups. Welcome everyone to join my Pythonlearning exchange group!

pictureIf you have any questions, please add me as a friend, and I will pull you into the Python learning exchange group to discuss and learn together.

picture

--- -- --- --- --- -- ---  End  --- -- --- -- --- --- -- -

Recommended articles in the past:

picture

Welcome everyone to like , leave a message, forward, reprint, thank you for your companionship and support

If you want to join the Python learning group, please reply in the background [ join the group ]

Thousands of waters and thousands of mountains are always love, can you click [ Watching ]