问题描述
大家好,
这只是一个关于python技巧的简单问题。
在perl中,我可以写__END__一个文件和perl解释器将
忽略该行下面的所有内容。这在测试我的
计划时非常方便。 python有类似的东西吗?
谢谢,
Geoffrey
对不起,不,它没有。
问候,
Martin
我希望从类似的东西那。您可以在
的时刻做些评论,或者对您的代码进行评论或三重报价
不想运行。
Michele Simionato
我希望从那样的东西。你目前可以做的是
评论或三重引用你不想运行的代码。
或者,如果在函数体中,你可以插入一个`return`语句。在
顶级代码中,调用`sys.exit`(或退出/退出)可以做到这一点。一个
`` raise Exception``也可能会有所帮助,但有时可能会分散注意力。
所以,那里不是通用的解决方案,因为perl有它(我想至少可以在b / b __END__上运行),而且不同的解决方案对于
不同的情况。
Hi All,
This is just a very simple question about a python trick.
In perl, I can write __END__ in a file and the perl interpreter will
ignore everything below that line. This is very handy when testing my
program. Does python have something similar?
Thanks,
Geoffrey
Sorry, no, it doesn''t.
Regards,
Martin
I wished from something like that. What you can do at the
moment, is to comment or triple quote the code you
don''t want to run.
Michele Simionato
I wished from something like that. What you can do at the moment, is to
comment or triple quote the code you don''t want to run.
Or, if in a function body, you could insert a `return` statement. When in
top-level code, invoking `sys.exit` (or exit/quit) can do the trick. A
``raise Exception`` might help, too, but could be kinda distracting
sometimes.
So, there is no general purpose solution as perl has it (I guess that
__END__ works everywhere at least), rather different solutions for
different cases.
这篇关于Python文件结束标记类似于perl的__END__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!