Hey guys, literally just starting off on python, just making a simple menu based system to read/write files and delete a file to get used to calling functions and working with the file system etc.
For some reason the code won't write to the file I have on my system, not sure what I'm doing wrong.
All help or constructive criticism about how I'm going about this would be much appreciated.
import os
def writer_func():
file_targ=raw_input("Enter file path and name: ")
texty=raw_input("Enter text: ")
file_targ=str('file_targ')
fob=open('file_targ','w')
fob.write('texty')
fob.close()
print '%s' % texty
print " Main Menu"
print "1) Write a file"
print "2) Read a file"
print "3) Delete a file"
main_menu=raw_input('Enter options [1-3] : ')
main_menu=int(main_menu)
if main_menu == 1:
print ("You chose to write a file")
writer_func()
elif main_menu == 2:
print ("You chose to read a file")
reader_func()
elif main_menu == 3:
print ("You chose to delete a file")
deleter
else:
print ("Invalid choice")
exit
I notice you are using a pre-version 3.x.x version of Python, 2.5.x to 2.7.x perhaps...
May I suggest you install a late version 3.x.x, as the syntax and function usages can
be much different, perhaps 3.3.x. (Note the latest alpha release is 3.4.0a3.)...
"print" is no longer a statement but a function for example and "raw_input" no longer
exists. These are but two examples...
Good luck with Python however as it is a superb language for general purpose use and
has an enormous number of libraries to use for just about every application one will
ever encounter...
EDIT:
Strange as it may seem however I have _dumped_ Python in preference to shell scripting...