2015-09-25 59 views
0

我想在GUI中使用os.system來運行命令行來幫助我們低技能的辦公室工作人員。我正在使用os.system ..因爲我在子進程中遇到了很多麻煩。我很接近,但我得到我的目錄路徑的一個奇怪的輸出..Python和PYQT目錄是

def selectFile(self): 


    self.listWidget.clear() # In case there are any existing elements in the list 
    directory = QtGui.QFileDialog.getExistingDirectory(self, "Pick a folder") 
    print directory 


    for file_name in os.listdir(directory): 
     if file_name.endswith(".csv"): 
      self.listWidget.addItem(file_name) 
      print (file_name) 
    self.directory = directory 





def osconvertfile(self): 


    directoryPath = self.directory 
    print directoryPath 

    cmd = ('python /Users/eeamesX/work/data-scripts/longFileScripts/createXMLFromCSVSept.py ' 
      +str(directoryPath)) 
    print cmd 
    os.system(cmd) 

我正由於./添加上的錯誤或錯誤的目錄..

.//Users/eeamesX/work/data/Sept_1_upload/priority_2/transcriptsAudoSplits/09012015_331_male3_r1_seg1/ 

任何方式解決這個問題??

回答

1

你有沒有嘗試使用os.path.normpathos.path.abspath

def osconvertfile(self): 
    directoryPath = os.path.abspath(os.path.normpath(self.directory)) 
    print directoryPath 

    cmd = 'python /Users/eeamesX/work/data-scripts/longFileScripts/createXMLFromCSVSept.py %s' directoryPath 
    print cmd 
    os.system(cmd) 
+0

我用這個得到一個錯誤,initial_slashes = path.startswith(「/」) AttributeError的:「QString的」對象有沒有屬性「startswith」 – Anekdotin

+0

因爲你沒有迴應我認爲,讓你用正確的答案。我弄明白了。 :) – Anekdotin

+0

如果您使用的是PyQt4,則需要使用'path.startsWith(...)':http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html。如果您使用的是PyQt5,則'QString'會自動轉換爲python'str' –