Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to extract filename ?
#1
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)
Reply
#2
Use f.name
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
(Dec-20-2016, 11:19 AM)Ofnuts Wrote: Use f.name

thanks,i will try,i will come back if there is still error
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020