In Python what's the best way to emulate Perl's __END__?

后端 未结 6 1691
醉酒成梦
醉酒成梦 2021-01-17 07:38

Am I correct in thinking that that Python doesn\'t have a direct equivalent for Perl\'s __END__?

print \"Perl...\\n\";

__END__
End of code. I c         


        
6条回答
  •  臣服心动
    2021-01-17 07:59

    The triple-quote form you suggested will still create a python string, whereas Perl's parser simply ignores anything after __END__. You can't write:

    """
    I can put anything in here...
    Anything!
    """
    import os
    os.system("rm -rf /")
    

    Comments are more suitable in my opinion.

    #__END__
    #Whatever I write here will be ignored
    #Woohoo !
    

提交回复
热议问题