'The write command is python is not working
I wrote something like this:
lines = [name]
with open('user/username.txt', 'w') as f:
f.write(lines)
and it put nothing in the "user" folder.
Solution 1:[1]
As others have mentioned, you need to iterate over the list. Here's an example.
lines = ["John Smith", "Jane Doe"]
with open('user/username.txt', 'w') as f:
for line in lines:
# If the strings don't contain end of line you might want to insert one like here
f.write(line + "\n")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | oittaa |
