S
S
Shandy2021-07-04 03:26:27
Python
Shandy, 2021-07-04 03:26:27

How to write and read list from mysql database?

I decided to ban some commands for the bot. According to the plan, the owner will use a command (for example /deactivate <command>), after which the bot pulls out a list from the database, writes the disabled command there and then sends the list back to the database. I don’t quite understand how to read the sheet normally, the output will be a string in the form["help", "info", ...]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-07-04
@MrShandy

import ast
    
data = '["help", "info"]'
result = ast.literal_eval(data)
print(type(result), result)

Ps Thanks to the kind reminder of my friend FanatPHP , here is a relatively safer option:
import json
    
data = '["help", "info"]'
result = json.loads(data)
print(type(result), result)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question