【问题标题】:Result of running code运行代码的结果
【发布时间】:2015-06-02 03:55:24
【问题描述】:

我的应用程序在 VB.Net 中。我有一个文本框。用户编写一段 Python 代码 init。我想运行这段代码。例如,文本框中的代码是这样的:

print 7*7

在 Python 中运行此代码的结果是 49。但是如果用户忘记了空格并写了:

print7*7

在 Python 中运行这段代码的结果是:

Traceback (most recent call last):
  File "vm_main.py", line 33, in <module>
    import main
  File "/tmp/vmuser_jrlbqyaetu/main.py", line 8, in <module>
    print7*7
NameError: name 'print7' is not defined

现在我想将运行代码的结果(错误或正确数据)保存在 VB.Net 中的字符串中。问题:

  1. 代码运行结果的数据类型是什么?
  2. 是否可以访问它?
  3. 可以保存吗?是否可以将其保存在字符串中?如果是,怎么做?

【问题讨论】:

标签: python vb.net string


【解决方案1】:

你可以试试这个:

import sys
f = open('output.txt', 'w')
sys.stdout = f
###############
#your code here
##############

所有输出都将写入ouput?txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多