简体   繁体   English

在iPython控制台中运行代码的中间部分

[英]Run middle part of code in iPython console

I want to run middle part of code, for example, from line 30 to 90 in train.py in iPython console. 我想在iPython控制台中的train.py中运行代码的中间部分,例如,从30行到90行。 Does anyone knows how to do that? 有谁知道该怎么做?

I know how to this command %run -d -b 90 script.py can run from line 1 to line 90, but not from 30 to 90. 我知道如何执行此命令%run -d -b 90 script.py可以从第1行运行到第90行,但不能从30运行到90。

The command you're running doesn't really do exactly what you say it does. 您正在运行的命令并没有真正按照您说的去做。 It runs the program under the control of pdb and sets a break point at line 90. So you could continue execution if you wanted. 它在pdb的控制下运行程序,并在第90行设置一个断点。因此,您可以根据需要继续执行。

You can load up functions, classes or specific lines using %load , but that won't run the commands under control of pdb . 您可以使用%load加载函数,类或特定行,但不会在pdb控制下运行命令。

eg. 例如。

%load -r 30-90 script.py

Will be transformed into the those lines, which you can then either run directly, or edit before running. 将转换为这些行,然后可以直接运行它们,也可以在运行前进行编辑。

To load specific functions or classes from the file you can use -s 要从文件中加载特定的函数或类,可以使用-s

%load -s MyClass script.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM