in reply to Thx, St. Larry, for the Beauty of Sigils

Let me play the devil's advocate here. I agree that the equivalent Perl code would be much easier to read, but why are you using introspection in this context? Shouldn't dicts (similar to Perl hashes) be used when you want access by arbitrary string key?

Replies are listed 'Best First'.
Re^2: Thx, St. Larry, for the Beauty of Sigils
by Eily (Monsignor) on Jul 30, 2019 at 12:53 UTC

    ++. The $obj->$method_name() syntax is basically just a symbolic ref that strict doesn't complain about, and with some extra magic to search in the $obj's package rather than the current one.

    That's more a case of perl giving you more rope than of python hindering correct usage.

      Just yesterday I had to implement a proxy object which delegates calls to other objects.

      getattr() seems to be like Perl's ->can() , but with the difference that you have to check the type in Python by yourself.

      IIRC are classes and objects in Python dicts anyway, which can be accessed via __dict__, though w/o inheritence.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        I suppose that by "check the type" you mean try to use the value and hopefully catch the error if it didn't work :P

        I'm not sure what your point is, are you saying that there are cases where the idiom is useful? Sure, so are some of the things strict complains about, that's what no strict is for. But if you only used it for one object, there's a chance you only used the idiom once right? If a language has a syntax that is a little cumbersome for a bad practice that can be useful in some rare edge cases, that's not really a language flaw.