如何从正在运行的Python脚本中提取文本? [英] How can I extract text from a running Python script?

查看:84
本文介绍了如何从正在运行的Python脚本中提取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是使用python的新手,但愿意学习。我的编程技巧很少,但我又愿意学习。


其次,我有一个从远程传感器接收数据的脚本(给我)。数据发布到正在运行的python脚本,每个数据条目占用一行。

我需要获取数据以记录,绘制图形,并最终将其叠加到图像上。有没有办法实时做到这一点?


我知道能够将数据保存为文本文件,然后将其导入Microsoft Excel,但这将是不能实时工作。我的最终目标是随时查看网站上的数据。


有什么建议吗?

First, I''m completely new to using python, but willing to learn. I have very little programming skills, but again, I''m willing to learn.

Second, I have a script (given to me) that receives data from a remote sensor. The data posts to a running python script, each data entry occupying one line.

I need to get the data out to log it, graph it, and ultimately overlay it onto an image. Is there a way to do this in real time?

I''m aware of the ability to save the data as a text file, then import it into Microsoft Excel, but this will not work in real time. My end goal is to see the data on a web site at any time.

Any suggestions?

推荐答案


首先,我是使用python的全新,但愿意学习。我的编程技巧很少,但我又愿意学习。


其次,我有一个从远程传感器接收数据的脚本(给我)。数据发布到正在运行的python脚本,每个数据条目占用一行。

我需要获取数据以记录,绘制图形,并最终将其叠加到图像上。有没有办法实时做到这一点?


我知道能够将数据保存为文本文件,然后将其导入Microsoft Excel,但这将是不能实时工作。我的最终目标是随时查看网站上的数据。


有什么建议吗?
First, I''m completely new to using python, but willing to learn. I have very little programming skills, but again, I''m willing to learn.

Second, I have a script (given to me) that receives data from a remote sensor. The data posts to a running python script, each data entry occupying one line.

I need to get the data out to log it, graph it, and ultimately overlay it onto an image. Is there a way to do this in real time?

I''m aware of the ability to save the data as a text file, then import it into Microsoft Excel, but this will not work in real time. My end goal is to see the data on a web site at any time.

Any suggestions?



你好,Alligatorr。

你来对了地方,因为我们非常愿意教导(我们生活在它)。

虽然可以得到文本对于正在运行的脚本,不太可能正在修改正在运行的脚本。原因如下:

  • Python在执行之前被编译(不可见)。
  • 如果第1点不正确,修改脚本将是非常糟糕的设计。


  • 如果您可以选择看起来正在编写数据并将其粘贴到此处的脚本部分,我们可以帮助您了解即时的。
    If you can pick out the part of the script that looks like it is writing the data and paste it here, we can help you get at it in real time.



    感谢Bartonc。


    据我所知,它只是一个打印字样。用于在屏幕上显示数据的命令。没有涉及花哨的代码。


    我不需要把它写到屏幕上,而是需要把它放到可以随时间绘制图形的地方。这就是目标。

    Thanks Bartonc.

    From what I can tell, it is simply a "print" command that displays the data on the screen. There is no fancy code involved.

    Instead of writing it to the screen, I need to get it to something where I can graph it over time. That''s the goal.



    感谢Bartonc。


    据我所知,它只是一个打印字样。用于在屏幕上显示数据的命令。没有涉及花哨的代码。


    我不需要把它写到屏幕上,而是需要把它放到可以随时间绘制图形的地方。那就是目标。
    Thanks Bartonc.

    From what I can tell, it is simply a "print" command that displays the data on the screen. There is no fancy code involved.

    Instead of writing it to the screen, I need to get it to something where I can graph it over time. That''s the goal.



    打印实际上在一个名为stdout的文件对象上调用write()。

    任何可以打印的东西(一种很好的测试方式) )只需使用>>重定向print语句的输出即可记录。 operator:

    Printing actually calls write() on a file-like object called stdout.
    Anything that can be printed (an excellent way of testing) can be logged simply by redirecting the output of the print statement with the >> operator:

    展开 | 选择 | Wrap | 行号


    这篇关于如何从正在运行的Python脚本中提取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆