Skip to content

Instantly share code, notes, and snippets.

@andrzejkrzywda
Created April 7, 2010 21:59
Show Gist options
  • Save andrzejkrzywda/359519 to your computer and use it in GitHub Desktop.
Save andrzejkrzywda/359519 to your computer and use it in GitHub Desktop.
def get_file_from_disk(self):
first_time = False
if not os.path.exists(CONFIG_DIR):
os.mkdir(CONFIG_DIR)
first_time = True
if not os.path.exists(DIARY_FILE):
file = open(DIARY_FILE, 'w')
file.close()
first_time = True
return open(DIARY_FILE, 'r'), first_time
----------
PIERWSZY KROK
def get_file_from_disk(self):
if is_first_time()
os.mkdir(CONFIG_DIR)
file = open(DIARY_FILE, 'w')
file.close()
return file, True
else
return open(DIARY_FILE, 'r'), False
def is_first_time(self):
return not os.path.exists(CONFIG_DIR) or not os.path.exists(DIARY_FILE)
-----
DRUGI KROK
---
def get_file_from_disk(self):
if is_first_time():
return open(create_diary_file(), 'r'), True
else
return open(DIARY_FILE, 'r'), False
#ruby to byloby tak:
# return is_first_time() ? (open(create_diary_file(), 'r'), True) : (open(DIARY_FILE, 'r'), False)
def create_diary_file(self):
os.mkdir(CONFIG_DIR)
file = open(DIARY_FILE, 'w')
file.close()
return file
def is_first_time(self):
return not os.path.exists(CONFIG_DIR) or not os.path.exists(DIARY_FILE)
----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment