A python file access sample code.
#!/usr/bin/python
#This is a simple file access program
#Created by Dls
s='\n \nThis is a simple text editor.\nCreated to learn python file access methods.\n\n'
print s
print ('What do you want to do ?\n')
print ('r -- press to read a file\n')
print ('w-- press to write to a file or make a new file \n')
print('q-- Quit')
while True :
res=raw_input('Enter your choise (r/w/q)?')
if(res=='r' or res=='R'):
print('Welcome to read a file.')
fp=raw_input("Please enter a file name :")
print fp
f=open(fp,'r')
print f
print f.read()
f.close()
elif(res=='w' or res=='W'):
print('Welcome to writer')
fp=raw_input('plese enter a file name :')
wr=raw_input('Enter your data to write to the file :')
f=open(fp,'a')
f.write(wr)
f.close
print('The writing to file is done.')
elif(res=='q' or res=='Q'):
print('Bye')
break
To run this you need python interpreter.This has basic file access methods of Python...
I'm also still learning python.
#This is a simple file access program
#Created by Dls
s='\n \nThis is a simple text editor.\nCreated to learn python file access methods.\n\n'
print s
print ('What do you want to do ?\n')
print ('r -- press to read a file\n')
print ('w-- press to write to a file or make a new file \n')
print('q-- Quit')
while True :
res=raw_input('Enter your choise (r/w/q)?')
if(res=='r' or res=='R'):
print('Welcome to read a file.')
fp=raw_input("Please enter a file name :")
print fp
f=open(fp,'r')
print f
print f.read()
f.close()
elif(res=='w' or res=='W'):
print('Welcome to writer')
fp=raw_input('plese enter a file name :')
wr=raw_input('Enter your data to write to the file :')
f=open(fp,'a')
f.write(wr)
f.close
print('The writing to file is done.')
elif(res=='q' or res=='Q'):
print('Bye')
break
To run this you need python interpreter.This has basic file access methods of Python...
I'm also still learning python.
0 Response to "A python file access sample code."
Post a Comment