使用 Python 代码中 QTFile 对话返回的目录路径
Using the directory path returned from QTFile Dialogue in Python Code
我正在从 Pyqt 中的 QTFile 对话返回目录路径:
dname = QtGui.QFileDialog.getExistingDirectory(self, 'Open file', '/home')
我返回的路径是这样的:
C:\cygwin64\home\My_workspace\HFATool\raw_files
我想在 python 代码中使用此路径,但它给出了一个斜线被读取为 C:\cygwin64\home\My_workspace\HFATool\raw_files
.
的错误
如何将上述路径中的正斜杠改为反斜杠?
当我使用
dname = dname.replace('\','/')
这给出了词法错误。
你快搞定了。您需要在 replace
参数中使用 \
。
dname = dname.replace('\','/')
这应该可以作为替代品正常工作。
我正在从 Pyqt 中的 QTFile 对话返回目录路径:
dname = QtGui.QFileDialog.getExistingDirectory(self, 'Open file', '/home')
我返回的路径是这样的:
C:\cygwin64\home\My_workspace\HFATool\raw_files
我想在 python 代码中使用此路径,但它给出了一个斜线被读取为 C:\cygwin64\home\My_workspace\HFATool\raw_files
.
如何将上述路径中的正斜杠改为反斜杠? 当我使用
dname = dname.replace('\','/')
这给出了词法错误。
你快搞定了。您需要在 replace
参数中使用 \
。
dname = dname.replace('\','/')
这应该可以作为替代品正常工作。