简体   繁体   English

如何执行以特定代码行开头的python文件?

[英]How do I execute a python file beginning in a specific code line?

I have a simulation in python which I have run, but half way to the end I got an error. 我已经在python中运行了一个模拟,但是到最后一半我遇到了一个错误。 I have already fixed the error. 我已经解决了错误。 Now I want to execute the same file, but beginning in the line of the error. 现在,我想执行相同的文件,但从错误所在的行开始。 How can I do that? 我怎样才能做到这一点? Execfile, as far as I looked doesn't do that... 就我看来,Execfile并没有这样做...

You don't. 你不知道

The easiest solution would be to comment out all the intervening lines, or put them inside an if False: block. 最简单的解决方案是注释掉所有中间的行,或将它们放入if False:块中。

You could also simply save the appropriate portion of the code into a new file and run that instead. 您也可以简单地将代码的适当部分保存到新文件中,然后运行该文件。

Any of these operations should be trivial in most editors. 这些操作中的任何一个在大多数编辑器中都是微不足道的。

put the line in a class then just call that class. 将该行放在一个类中,然后只需调用该类即可。 This is what I would do rather than commenting out the lines.. 这是我要做的,而不是注释掉界线。

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

相关问题 如何执行python文件中的所有代码? - How do I execute all the code inside a python file? 如何从 yml 文件执行 python 代码? - How do I execute python code from yml file? 如何从python的输入文件中选择特定行 - How do I choose a specific line from a input file in python 如何从 python 中的文本文件中删除特定行 - How do I remove a specific line from a text file in python 如何使用 Python 覆盖 CSV 文件中的特定行 - How do I overwrite a specific line in a CSV file with Python 如何在python脚本中执行这行代码,就像是命令行一样? - How do I execute this line of code in a python script as if it were command line? 如何逐行读取文件并仅在python中打印具有特定字符串的行? - How do I read a file line by line and print the line that have specific string only in python? 当格式特定时,如何使用 Python 逐行读取文本文件 - how do i read a text file in line-by-line using Python when the formatting is specific 如何使用 Python 中的行为命令执行 1 个特定功能文件? - How do I execute 1 specific feature file using behave command in Python? 我可以知道这行特定的代码是什么意思吗,我如何将它放入 Python 的 for 循环中 - Can I know what does this specific line of code means and how do i put it in a for loop in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM