Dec-24-2016, 10:26 AM
from sys import * def open_file(filename) print(filename) def run(): open_file(?)what should i write into the question mark to print the filename of the saved and currently opened file in the text editor i am using?
getting current filename of a text editor file for printing file name?
|
Dec-24-2016, 10:26 AM
from sys import * def open_file(filename) print(filename) def run(): open_file(?)what should i write into the question mark to print the filename of the saved and currently opened file in the text editor i am using?
Dec-24-2016, 11:13 AM
So this is what I would do if I got your question aright:
from sys import * def open_file(filename) print(filename) def run(): filename = "AnyFileName" #You maybe want to convert it into a user input via input() open_file(filename)
Dec-24-2016, 12:55 PM
You should run like
def open_file(filename): print('filename: {}'.format(filename)) # If you upgrade to python 3.6: # f"filename {filename}" return open(filename, 'r') # for read # return open(filename, 'w') # for write # Or any other mode (there are many see docs) def run(filename): open_file(filename) if __name__ == '__main__': run('ziggy.txt')You may want to use the tkinter.filedialog see: http://infohost.nmt.edu/tcc/help/pubs/tk...ialog.html
Dec-24-2016, 07:58 PM
You should close the file too, I think
|
|