cd 到用户定义的路径
我想知道你是否可以帮助我完成我的新 python 程序。我最近在 GUI 中添加了一个浏览按钮,使事情变得更加“用户友好”。我告诉 python 仅在要求用户浏览文件时接受 *.pvt 文件...现在,我想知道如何告诉 python 采用用户浏览到的路径并打开 cmd 窗口[使用 subprocess. Popen("cmd.exe")] 并 cd 到该用户定义的路径..有什么想法吗???
这就是我到目前为止所拥有的...
def OnAbout3(self, event):
"""
Browse for file
"""
wildcard = "Select File (*.pvt)|*.pvt"
dialog = wx.FileDialog(None, "Choose a file",
wildcard=wildcard,
style=wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPaths()
#######this is where i wanted to do something like this:
subprocess.Popen("cmd.exe")
#I wished cmd could simply cd to the variable, path
os.system('cd path')
dialog.Destroy()
所以,显然,这不会 cd 到路径。我该怎么做?
I was wondering if you could help me with my new python program. I recently added a browse button to the GUI to make things more "user-friendly." I told python to only accept *.pvt files when the user is asked to browse for a file... Now, I am left wondering how to tell python to take the path the user browsed to and open a cmd window[using subprocess.Popen("cmd.exe")] and cd to that user defined path.. any ideas???
here's what i have so far...
def OnAbout3(self, event):
"""
Browse for file
"""
wildcard = "Select File (*.pvt)|*.pvt"
dialog = wx.FileDialog(None, "Choose a file",
wildcard=wildcard,
style=wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPaths()
#######this is where i wanted to do something like this:
subprocess.Popen("cmd.exe")
#I wished cmd could simply cd to the variable, path
os.system('cd path')
dialog.Destroy()
so, obviously, this doesn't cd to path. how can i do this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过此操作:
这是基于这样的假设:您实际上并不想要 cd,而是希望设置当前工作目录 - 这是 cd 的后置条件...
检查
subprocess
模块更多精彩参数和示例!Did you try this:
This is based on the assumption, that you don't really want to
cd
, but instead want the current working directory to be set - which is the post condition ofcd
...Check the
subprocess
module for more awesome parameters and examples!