Skip to content

Instantly share code, notes, and snippets.

@shouhei
Created December 24, 2015 12:51
Show Gist options
  • Select an option

  • Save shouhei/732d7fdd85becb6bf7a1 to your computer and use it in GitHub Desktop.

Select an option

Save shouhei/732d7fdd85becb6bf7a1 to your computer and use it in GitHub Desktop.
simple python todo
import tempfile
import os
if "__main__" == __name__:
with open("sample.todo") as file:
raw_data = file.read()
data_list = raw_data.split("\n")
if data_list[4]:
del data_list[4]
temp_file_name = str(tempfile.mkstemp()[1])
with open(temp_file_name, "w") as temp_file:
for data in data_list:
temp_file.write(data + "\n")
os.rename(temp_file_name, "sample.todo")
if "__main__" == __name__:
with open("sample.todo","r") as file:
data_raw = file.read()
data_list = data_raw.split("\n")
for data in data_list:
print(data)
if "__main__" == __name__:
with open("sample.todo","a") as file:
file.writelines("new todo"+"\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment