minus-squareRapidCatLauncher@lemmy.catoProgrammer Humor@programming.dev•exitlinkfedilinkEnglisharrow-up78·22 hours agoThat just gave me the idea that it would be fun to inspect exit a little. Which led me down this path: >>> repr(exit) 'Use exit() or Ctrl-Z plus Return to exit' >>> dir(exit) [(...), 'eof', 'name'] >>> exit.eof, exit.name ('Ctrl-Z plus Return', 'exit') Okay, cool, the “Use exit() etc.” blurb appears because it’s the function’s repr, and the string is assembled from its name and eof properties. Now let’s try to make our own: >>> exit.__class__ <class '_sitebuiltins.Quitter'> >>> gtfo = exit.__class__() TypeError: Quitter.__init__() missing 2 required positional arguments: 'name' and 'eof' Oh Python, you shouldn’t have. >>> gtfo = exit.__class__("a big puff of smoke", "a sneaky skedaddle") >>> gtfo Use a big puff of smoke() or a sneaky skedaddle to exit Beauty! linkfedilink
minus-squareRapidCatLauncher@lemmy.catoA Boring Dystopia@lemmy.world•Bill Gates Bought His Daughter A $16 Million Horse Farm As A Graduation Gift — But Ex-Wife Melinda Says The Kids Were Raised Very 'Middle Class'linkfedilinkEnglisharrow-up5arrow-down1·1 month agoYou’ll love this: https://i.imgur.com/wn5VDPt.jpeg linkfedilink
minus-squareRapidCatLauncher@lemmy.catoProgrammer Humor@programming.dev•This might have some impact on efficiencylinkfedilinkEnglisharrow-up58·edit-22 months agoHidden feature: Defines a tariff.admin.impeach function that increments a global counter and does absolutely nothing else linkfedilink
That just gave me the idea that it would be fun to inspect
exit
a little.Which led me down this path:
>>> repr(exit) 'Use exit() or Ctrl-Z plus Return to exit' >>> dir(exit) [(...), 'eof', 'name'] >>> exit.eof, exit.name ('Ctrl-Z plus Return', 'exit')
Okay, cool, the “Use exit() etc.” blurb appears because it’s the function’s
repr
, and the string is assembled from itsname
andeof
properties.Now let’s try to make our own:
>>> exit.__class__ <class '_sitebuiltins.Quitter'> >>> gtfo = exit.__class__() TypeError: Quitter.__init__() missing 2 required positional arguments: 'name' and 'eof'
Oh Python, you shouldn’t have.
>>> gtfo = exit.__class__("a big puff of smoke", "a sneaky skedaddle") >>> gtfo Use a big puff of smoke() or a sneaky skedaddle to exit
Beauty!