首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python subprocess.Popen

Python subprocess.Popen
EN

Stack Overflow用户
提问于 2014-07-23 21:18:27
回答 1查看 100关注 0票数 0

我有下面的代码,它从网络抓取中获取数据。我刚学会了如何使用

代码语言:javascript
复制
subprocess.Popen

我正试图利用我的主动性,以及其他类似问题的答案--如何使用

代码语言:javascript
复制
subprocess.Popen

要执行下面的脚本,将webscrape数据放到我的插入字段中,每30秒左右更新一次。但这是行不通的。请你指出正确的方向好吗?

代码语言:javascript
复制
import xlrd
import subprocess
from Tkinter import *
import urllib2
from ttk import *
import Tkinter as tk

class Application(Frame):
    """GUI to display results of 'equity get'"""
    
    def __init__(self, master):
        """initialise the Frame"""
        Frame.__init__(self,master)
        self.grid()
        self.create_widgets()
 
    def create_widgets(self):
        """Create button, text and entry Widget"""
        """what it is i.e. label"""
        
        url = "https://......."
        request= urllib2.Request(url)
        handle = urllib2.urlopen(request)
        content = handle.read()
        splitted_page = content.split("<.......">", 1);
        splitted_page = splitted_page24[1].split("</.......>", 1)

        self.data = Label(self, text ="Data")
        self.data1 = Entry(self, width = 10)
        self.data1.insert(0,splitted_page[0])

        self.data.grid(column = 1, row = 1)
        self.data1.grid(column = 2, row = 1)
        self.data1.grid(column = 3, row = 1)            

        a = 0
        while a < 10:
            a += 1
            time.sleep(15)
        while True:
            out =   subprocess.Popen(["C:\Users\.....\Desktop\Py\python.exe","C:\Users\.....\Desktop\..\Python27\.....\tester.py"])

app = Application(root)
root.title("reload test")
root.geometry("700x300")
root.mainloop()

我得到的错误是错误编号22:引用在

代码语言:javascript
复制
     (["C:\Users\.....\Desktop\Py\python.exe","C:\Users\.....\Desktop\..\Python27\.....\tester.py"])

然后,多个命令行窗口打开,显示相同的错误,我必须关闭计算机来停止它!

我用“r”前缀修改了对我的文件的引用如下:

代码语言:javascript
复制
([r"C:\Users\.....\Desktop\..\Python27\.....\tester.py"])

但是删除了python.exe调用,因为它只是调用命令行窗口。现在,我收到以下错误消息:

代码语言:javascript
复制
Traceback (most recent call last):
File "C:\Users\....\Desktop\Py\Python27\.....\tester.py", line 46, in <module>
app = Application(root)
File "C:\Users\......\Desktop\Py\Python27\.....\tester.py", line 18, in __init__
self.create_widgets()
File "C:\Users\.....\Desktop\Py\Python27\......\tester.py", line 44, in create_widgets
out = subprocess.Popen([r"C:\Users\Isaac\Desktop\Py\Python27\.....\tester.py"])
File "C:\Users\.....\Desktop\Py\lib\subprocess.py", line 672, in __init__
errread, errwrite)
File "C:\Users\.....\Desktop\Py\lib\subprocess.py", line 882, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-23 22:01:20

Python使用反斜杠引用字符,比如\n = newline和\t = tab。

使用r前缀生成一个原始字符串文本,就像Windows:

代码语言:javascript
复制
out =  subprocess.Popen([r"C:\Users\.....\Desktop\Py\python.exe", r"C:\Users\.....\Desktop\..\Python27\.....\tester.py"])
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24921182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档