我在python中有以下代码
import Tkinter,tkFileDialog top=Tkinter.Tk() from tkFileDialog import askopenfilename dirname = tkFileDialog.askdirectory(parent=top)当我打印dirname时,它显示为正常,并给出
F:/Project/Dropbox/My Mtech Main Project/Programming Folder/SPIDER/Ubuntu Spyder/但是,当我访问dirname,否则,即...在命令窗口中的类型dirname我得到以下输出,
u"F:/Project/Dropbox/My Mtech Main Project/Programming Folder/SPIDER/Ubuntu Spyder/"我怎么能避免这个你,所以我可以使用dirname作为另一个操作的输入,如读取波形文件等。现在我得到了错误,因为你。
i have a following code in python
import Tkinter,tkFileDialog top=Tkinter.Tk() from tkFileDialog import askopenfilename dirname = tkFileDialog.askdirectory(parent=top)when i print the dirname it appears as normal,and gives
F:/Project/Dropbox/My Mtech Main Project/Programming Folder/SPIDER/Ubuntu Spyder/But when i acess the dirname,otherwise, ie.. like type dirname in command windows i got the following output,
u"F:/Project/Dropbox/My Mtech Main Project/Programming Folder/SPIDER/Ubuntu Spyder/"How can i avoid this u ,so that i can use the dirname as an input to another operation like, read a wavefile etc. Now i got the error becuase of that u.
最满意答案
那么path之前的u就是为了表明字符串是unicode type
您可以使用函数type(data)检查type(data) (检查dirname )
Unicode strings are expressed as instances of the unicode type one of Python's repertoire of built-in types更多信息在这里
如果您想避免这种情况,只需更改类型即可。
import Tkinter,tkFileDialog top=Tkinter.Tk() from tkFileDialog import askopenfilename dirname = str(tkFileDialog.askdirectory(parent=top))希望有所帮助
Well the u before the path is just to show that the string is of unicode type
you can check the type of data by using the function type(data) (check for dirname)
Unicode strings are expressed as instances of the unicode type one of Python's repertoire of built-in typesmore information here
In case you want to avoid this just change the type.
import Tkinter,tkFileDialog top=Tkinter.Tk() from tkFileDialog import askopenfilename dirname = str(tkFileDialog.askdirectory(parent=top))hope that helps
更多推荐
发布评论