Skip to content

Instantly share code, notes, and snippets.

@mashcom
Created June 16, 2014 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mashcom/5705815f2993b83f24e3 to your computer and use it in GitHub Desktop.
Save mashcom/5705815f2993b83f24e3 to your computer and use it in GitHub Desktop.
files io basic
#read file
# calculate trajetory
# @author: Mashoko Blessing
# @ http://www.facebook.com/blessing.mashcom
# @mashcom digimedia http://www.hookd-up.com
import os
def isFileAvailable(myfile):
if(os.path.isfile(myfile)):
return True
else:
return False
def openAndWrite(mytext,myfile):
f= open(myfile,"a") #a if for appending
f.write(mytext)
return True
def readFile(myfile):
f = open(myfile,"r")
text = f.read()
return text
def scanDir():
return os.listdir("/")
#specify full path to text file
myfile ="mashcom.txt"
#checking availability
isFileAvailable(myfile)
print("file available starting to write, please enter your text and press ENTER to save ")
mytext ="hello this is you text"
#writing to file
openAndWrite(mytext, myfile)
print("text appended to file successfully")
#reading from file
print(readFile(myfile))
#reading directories
print(scanDir())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment