如何使用变量在 Spyder 控制台中执行 Python 3.3 脚本? [英] how to execute Python 3.3 script in Spyder console with variables?

查看:52
本文介绍了如何使用变量在 Spyder 控制台中执行 Python 3.3 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Spyder 控制台中执行 Python 3.3 脚本,并且该脚本有变量?

how can I execute Python 3.3 script in Spyder console, and that has variables?

我的示例代码 (C:/test/myfile.py) 是

My sample code (C:/test/myfile.py) is

from sys import argv
script, first, second, third = argv
print("The script is called:", script)
print("Your first variable is:", first)
print("Your second variable is:", second)
print("Your third variable is:", third)

我试过 exec(open("C:\test\myfile.py").read()) - 我得到的错误是ValueError:需要超过 1 个值才能解压.我想提供变量first = "1st", second = "2nd",third = "3rd".如何编写 exec() 以便它可以处理输入?

I have tried exec(open("C:\test\myfile.py").read()) - and the error I get is "ValueError: need more than 1 value to unpack. I want to supply the variables first = "1st", second = "2nd", third = "3rd". How can I write the exec() so that it can handle the inputs?

我使用的是 Python 3.3,64 位安装,Windows 操作系统,安装:WinPython.

I'm using Python 3.3, 64-bit installation, Windows OS, installation: WinPython.

推荐答案

你需要去

<代码>运行 >每个文件的配置

(或点击 Ctrl+F6)并在出现的对话框中进行检查

(or hit Ctrl+F6) and in the dialog that it appears you need to check

命令行选项

并在那里写(例如)

1 2 3

关闭此对话框并按 F5 后,您将看到预期的输出.

After closing this dialog and hitting F5, you'll see the output you are expecting.

注意:请记住,这些命令行选项在 Spyder 重新启动之间保存为文件运行配置的一部分,因此如果您想更改它们,您需要按 Ctrl+F6 再次.

Note: Please remember that these command line options are saved between Spyder restarts as part of the file run config, so if you want to change them, you need to hit Ctrl+F6 again.

这篇关于如何使用变量在 Spyder 控制台中执行 Python 3.3 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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