Dec-20-2016, 07:49 AM
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)
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)