Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python – Convert string to list

I am working at a "cloud server" for myself. I have a tool to list files which are on the server.

flist = os.listdir("C:/Server")
conn.send(bytes("str(flist), "UTF-8")) 

This sends a list to the client, the client converts it to a string. (something like this: [' Arcer.exe', 'Launcher.exe', 'Document.txt']) Now how can I convert the string back into a list?

string = "[' Arcer.exe', 'Launcher.exe', 'Document.txt']"
list = []
list = string.convert #pseudo method
print(list[0]) #Arcer.exe
print(list[1]) #Launcher.exe

Answer*

Draft saved
Draft discarded
Cancel
1
  • 1
    Note that the last won't work if any of the strings have a comma in them. Commented Oct 13, 2018 at 19:57

lang-py

AltStyle によって変換されたページ (->オリジナル) /