print "Hello World"
in Python a few times, and have largely failed. It's simple inline stuff so far, so not much problem. But I'm wanting to group. Consider this Perl code:use subs qw{ myFunction } ; myFunction('x') ; sub myFunction { my $x = shift @_ ; print qq{$x\n} ; }
I open the file in the editor and my function is at the bottom and my logic is on top. This makes it easier to understand the code when it's more than one line of logic and one function.
def myFunction(x): print x myFunction('x')
This is functionally the same. Some might look at the syntax and prefer it. Fine. But if you put
myFunction()
before def myFunction():
, you have an undefined function and an error. Which means you 1) get your logic at the bottom or 2) put your functions into a module, or whatever the term of art is in Python. I'm writing Sikuli, so I don't know exactly how many Python trics I can really do.So, is that it? Must I put my logic at the bottom?
Afraid so.
ReplyDeleteIn python, "def func(x): do stuff" behaves mostly at runtime; it's more like the following in perl:
*func = sub {
my ($x) = @_;
print "$x\n;
};