[python-perl] Translation review?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TSO

    #1

    [python-perl] Translation review?

    Hi there,



    I've recently tried to translate some Perl code into Python - code is below.


    Is there a more Pythonic form?


    Also, is there a good reason why there are plans to remove lambda from the language?


    yrs complements-of-the-season-ly...






    ==== START OF CODE








    ## 2005-04-01 - TSO
    ## with apologies to Erudil

    import sys,math;[


    vars()
    .__setitem__(
    "ham", lambda(spam):(" ").
    join([chr(( spam/144**i)%(02*72) )
    for(i)in xrange( int(math.log(sp am**0.5,
    12)+1))])),[(lambda* spam:globals(). update({}
    ..__class__([spam])))( ham(spam),eval( ham(__spam))
    )for(spam,__spa m)in[ (47631497714,0x 3A305499C7D37),
    (47159984399, 2337674),(32749 9859,2336509),( 8901
    +34553*10000, 2402179),(63034 05375459,229561 2),(11+
    7540504603011, 303839094),(95, 2295612),(75405 04603011,
    303839094),(95, 0x16241495E6D60 314676F55F45E4D 3F906),(216*
    10529,0x1053924 DE35309345),(0x 6DB401B64DC,0x2 62efd)]]and(_)
    (ham(231280211) ,[bacon(spam,ham( 0x65936781522)) ()for(spam)in
    crispy(bacon(ba con((bacon(eggs ,ham(0x1051936D 9600B6F4F)))(0)
    ,ham(6296985467 094)),ham(39012 977847621407307 7203)))]+[bacon(
    ham(32),ham(484 73858995))()]),_(ham(110),(l ovely)(Spam(che ese
    ,SPAM))),_(ham( 231280211),[[int((lambda spam:bacon(baco n(ham
    (32),ham(484738 58995))(),ham(3 30651610))([ham(6961)[bacon((
    spam),ham(+9066 98009388057))()]for(spam)in(spa m)]))(spam+
    spam_),2)for(sp am,spam_)in(lam bda(spam):[(spam)for(spam)
    in(_spam)(spam[::2],spam[1::2])])(list(_spam(*s pam)))]
    for(spam) in(lambda(spam) :list(_spam(spa m[::2],spam
    [1::2])))([(spam+ham (32)*n)[:n]for(
    spam)in(SPAM) ])])or(Spam)((
    bacon)( bacon(eggs,ham
    (7233055643059
    )),ham(224343
    + 11402701*10**
    6+ 30804988*10**
    14) ),[(spam)for
    spam in(_spam)(*[
    (ham( 668732698837
    )%(spam_ ,_spam),ham(
    668732698 *1000+837)%(
    _spam,spam_ ))for(_spam,
    spam_)in(_spam) (*Spam(lambda
    (spam_,_spam): [bacon(bacon
    (ham(32),ham( 0xB494463B3)
    )(),ham(610+ 330651000))(
    [_spam[spam]for(spam)in(spa m)[::spam_
    *-2+1]])for(spam)in(SP AM)],Ham([ham
    (0x40BA541813CE CF0323A994C40AA 00)
    ,ham(4128534887 83846916352+
    20980637114201* 10**21
    )])))])])]

    == END OF CODE
  • Steve Holden

    #2
    Re: [python-perl] Translation review?

    Traceback (most recent call last):
    File "<stdin>", line 19, in ?
    IOError: [Errno 2] No such file or directory: '<stdin>'

    (in both Windows 2.4 and Cygwin 2.4)

    regards
    Steve

    TSO wrote:[color=blue]
    > Hi there,
    >
    >
    >
    > I've recently tried to translate some Perl code into Python - code is below.
    >
    >
    > Is there a more Pythonic form?
    >
    >
    > Also, is there a good reason why there are plans to remove lambda from the language?
    >
    >
    > yrs complements-of-the-season-ly...
    >
    >
    >
    >
    >
    >
    > ==== START OF CODE
    >
    >
    >
    >
    >
    >
    >
    >
    > ## 2005-04-01 - TSO
    > ## with apologies to Erudil
    >
    > import sys,math;[
    >
    >
    > vars()
    > .__setitem__(
    > "ham", lambda(spam):(" ").
    > join([chr(( spam/144**i)%(02*72) )
    > for(i)in xrange( int(math.log(sp am**0.5,
    > 12)+1))])),[(lambda* spam:globals(). update({}
    > .__class__([spam])))( ham(spam),eval( ham(__spam))
    > )for(spam,__spa m)in[ (47631497714,0x 3A305499C7D37),
    > (47159984399, 2337674),(32749 9859,2336509),( 8901
    > +34553*10000, 2402179),(63034 05375459,229561 2),(11+
    > 7540504603011, 303839094),(95, 2295612),(75405 04603011,
    > 303839094),(95, 0x16241495E6D60 314676F55F45E4D 3F906),(216*
    > 10529,0x1053924 DE35309345),(0x 6DB401B64DC,0x2 62efd)]]and(_)
    > (ham(231280211) ,[bacon(spam,ham( 0x65936781522)) ()for(spam)in
    > crispy(bacon(ba con((bacon(eggs ,ham(0x1051936D 9600B6F4F)))(0)
    > ,ham(6296985467 094)),ham(39012 977847621407307 7203)))]+[bacon(
    > ham(32),ham(484 73858995))()]),_(ham(110),(l ovely)(Spam(che ese
    > ,SPAM))),_(ham( 231280211),[[int((lambda spam:bacon(baco n(ham
    > (32),ham(484738 58995))(),ham(3 30651610))([ham(6961)[bacon((
    > spam),ham(+9066 98009388057))()]for(spam)in(spa m)]))(spam+
    > spam_),2)for(sp am,spam_)in(lam bda(spam):[(spam)for(spam)
    > in(_spam)(spam[::2],spam[1::2])])(list(_spam(*s pam)))]
    > for(spam) in(lambda(spam) :list(_spam(spa m[::2],spam
    > [1::2])))([(spam+ham (32)*n)[:n]for(
    > spam)in(SPAM) ])])or(Spam)((
    > bacon)( bacon(eggs,ham
    > (7233055643059
    > )),ham(224343
    > + 11402701*10**
    > 6+ 30804988*10**
    > 14) ),[(spam)for
    > spam in(_spam)(*[
    > (ham( 668732698837
    > )%(spam_ ,_spam),ham(
    > 668732698 *1000+837)%(
    > _spam,spam_ ))for(_spam,
    > spam_)in(_spam) (*Spam(lambda
    > (spam_,_spam): [bacon(bacon
    > (ham(32),ham( 0xB494463B3)
    > )(),ham(610+ 330651000))(
    > [_spam[spam]for(spam)in(spa m)[::spam_
    > *-2+1]])for(spam)in(SP AM)],Ham([ham
    > (0x40BA541813CE CF0323A994C40AA 00)
    > ,ham(4128534887 83846916352+
    > 20980637114201* 10**21
    > )])))])])]
    >
    > == END OF CODE[/color]


    --
    Steve Holden +1 703 861 4237 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/

    Comment

    • Michele Simionato

      #3
      Re: Translation review?

      This is spectacular! :)
      Is there a way to make it to work from environments (such as emacs)
      where stdin is special?

      Michele Simionato

      Comment

      Working...