Home
User Guide
DB Recovery
Download
Documents
FAQ
Books
About Me
C programs
python programs
Stats
Python file operation - Writing into a file
#this function will open/create a file and write into it
def file_open(filename):
	"""create a file and write into it"""
	print 'opening the file:',filename 
	try:
		fo=open(filename,'w+'); # open the file
	except:
		print 'Error in program'
	else:
		fo.write("Linux Programmers Paradise\n");
		fo.close();

#get file name from keyboard
name = raw_input ('whats  the file name?\n')
print 'file name is : ',name,'.'
#call the function
file_open(name);



Powered by
Open Source Programmers