Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (anonymous):

Python: Create new function dedicated to file open? Not sure if it's worth it but... from sys import argv new_file = argv def creation(new_one): new_one = open(new_file, 'w') (Would I need to return new_one?) creation(target) While attempting run, I'll get the error, name 'target' is not defined. What would I need to do to fix this to successfully create a function for file opening? I have no idea how to define target... I could do file i/o but that's only from not using functions. Any hints would be greatly appreciated.

OpenStudy (anonymous):

I was thinking of defining target as the name of the txt file I plan on creating. Will try that after I get back from running. Any input still welcome.

OpenStudy (anonymous):

A simple example in python to open a file file_name=str(raw_input("Enter file name:")) if not file_name.endwiths(".txt"): file_name=file_name + ".txt" def creation(new_file): fp=open(new_file,"w") fp.write("i have opened the file") fp.close() creation(file_name)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!