Created
June 16, 2014 11:50
-
-
Save mashcom/5705815f2993b83f24e3 to your computer and use it in GitHub Desktop.
files io basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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