我在Gtk2中使用文件选择。我想在python中使用Bash Command(stat“some directory”)。 在这段代码中,文件目录保存在“text”变量中。 但它不起作用。我不想使用python-built stat()方法。
#!/usr/bin/python
import pygtk
import gtk
import os
class fileselection:
def file_ok_sel(self,w):
print("%s " % self.filew.get_filename())
text=self.filew.get_filename()
print(text)
os.system("stat os.listdir("text")")
#print(os.stat(text))
#os.system("stat os.dir(text)")
def destroy(self,widget):
gtk.main_quit()
def __init__(self):
self.filew=gtk.FileSelection("File selection")
self.filew.connect("destroy",self.destroy)
self.filew.ok_button.connect("clicked",self.file_ok_sel)
self.filew.cancel_button.connect("clicked",lambda w:self.filew.destroy())
self.filew.set_filename("penguin.png")
self.filew.show()
def main():
gtk.main()
return 0
if __name__=="__main__":
fileselection()
main()
答案 0 :(得分:1)
os.system('stat' + ' '.join(os.listdir(text)))
您还应该考虑使用subprocess
模块:https://docs.python.org/2/library/subprocess.html#module-subprocess