how to extract filename ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: how to extract filename ? (/thread-1277.html) |
how to extract filename ? - hsunteik - Dec-20-2016 How to extract filename from the result the tkinter command asksaveasfile give? example: from tkinter.filedialog import asksaveasfile def saveascodimefile(): f=asksaveasfile(mode='w',defaultextension='.codime') print(f) saveascodimefile() result: <_io.TextIOWrapper name='c:\Users\User\Desktop\project teik\shortcut\codime interpreter/goo.codime' mode='w' encoding='cp1252'> how to extract goo.codime from the above result? what i have tried: from tkinter.filedialog import asksaveasfile import os.path def saveascodimefile(): f=asksaveasfile(mode='w',defaultextension='.codime') filename=os.path.basename(f) print(filename) saveascodimefile() error: i forgot the exact error, but i has something to do with io.TextIOWrapper and len <2 (something like that) RE: how to extract filename ? - Ofnuts - Dec-20-2016 Use f.name
RE: how to extract filename ? - hsunteik - Dec-20-2016 (Dec-20-2016, 11:19 AM)Ofnuts Wrote: Use thanks,i will try,i will come back if there is still error |