Prepend a line to an existing file in Python
I need to add a single line to the first line of a text file and it looks like the only options available to me are more lines of code than I would expect from python. Something like this:
I need to add a single line to the first line of a text file and it looks like the only options available to me are more lines of code than I would expect from python. Something like this:
list.append()
is the obvious choice for adding to the end of a list. Here’s a reasonable explanation for the missing list.prepend()
. Assuming my list is short and performance concerns are negligible, is