Skip to content

Instantly share code, notes, and snippets.

@mashcom mashcom/files.py
Created Jun 16, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.