Python文件结束标记类似于perl的__END__ [英] Python end of file marker similar to perl's __END__
问题描述
大家好,
这只是一个关于python技巧的简单问题。
在perl中,我可以写__END__一个文件和perl解释器将
忽略该行下面的所有内容。这在测试我的
计划时非常方便。 python有类似的东西吗?
谢谢,
Geoffrey
在perl中,我可以在文件中写__END__,perl解释器将
忽略该行下面的所有内容。这在测试我的
计划时非常方便。 python有类似的东西吗?
对不起,不,它没有。
问候,
Martin
8月1日上午5:53,初学者< zyzhu2 ... @ gmail.comwrote:
大家好,
这只是一个关于python技巧的简单问题。
在perl中,我可以在文件中写__END__并且perl翻译将
忽略该行下面的所有内容。这在测试我的
计划时非常方便。 python有类似的东西吗?
谢谢,
Geoffrey
我希望从类似的东西那。您可以在
的时刻做些评论,或者对您的代码进行评论或三重报价
不想运行。
Michele Simionato
2007年8月1日星期三05:44:21 +0000,Michele Simionato写道:
8月1日上午5:53,初学者< zyzhu2 ... @ gmail.comwrote:
>大家好,
这只是关于python技巧的一个非常简单的问题。
在perl中,我可以在文件中写__END__而perl解释器将忽略下面的所有内容那条线。这在测试我的
程序时非常方便。 python有类似的东西吗?
我希望从那样的东西。你目前可以做的是
评论或三重引用你不想运行的代码。
或者,如果在函数体中,你可以插入一个`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
In perl, I can write __END__ in a file and the perl interpreter willignore everything below that line. This is very handy when testing my
program. Does python have something similar?Sorry, no, it doesn''t.
Regards,
Martin
On Aug 1, 5:53 am, beginner <zyzhu2...@gmail.comwrote: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,
GeoffreyI 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
On Wed, 01 Aug 2007 05:44:21 +0000, Michele Simionato wrote:
On Aug 1, 5:53 am, beginner <zyzhu2...@gmail.comwrote:>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?
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__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!