Timeline for answer to Converting a string into a list in Python by Nikola Smiljanić
Current License: CC BY-SA 2.5
Post Revisions
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 30, 2010 at 21:41 | comment | added | dbr |
@SilentGhost True, it makes it clearer what is happening, but list(open("myfile")) is the same as open("myfile").readlines() - by default iterating over a file with use the readlines method
|
|
| Mar 30, 2010 at 13:19 | comment | added | dbr |
You can also just use the list builtin instead of a list comprehension - list(open("myfile.txt")) -> ['1000\n', '2000\n', '3000\n', '4000\n']
|
|
| Mar 30, 2010 at 13:19 | comment | added | Omnifarious | And, if the OP were to need to strip newlines, how would that code look? | |
| Mar 30, 2010 at 13:18 | history | edited | Nikola Smiljanić | CC BY-SA 2.5 |
added 103 characters in body
|
| Mar 30, 2010 at 13:18 | history | edited | dbr | CC BY-SA 2.5 |
Code to code block
|
| Mar 30, 2010 at 13:14 | history | answered | Nikola Smiljanić | CC BY-SA 2.5 |