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

后端 未结 6 1761
醉酒成梦
醉酒成梦 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:52

    The

    __END__
    block in perl dates from a time when programmers had to work with data from the outside world and liked to keep examples of it in the program itself.

    Hard to imagine I know.

    It was useful for example if you had a moving target like a hardware log file with mutating messages due to firmware updates where you wanted to compare old and new versions of the line or keep notes not strictly related to the programs operations ("Code seems slow on day x of month every month") or as mentioned above a reference set of data to run the program against. Telcos are an example of an industry where this was a frequent requirement.

    Lastly Python's cult like restrictiveness seems to have a real and tiresome effect on the mindset of its advocates, if your only response to a question is "Why would you want to that when you could do X?" when X is not as useful please keep quiet++.

提交回复
热议问题