SAGF
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
unlawfulbooger@lemmy.blahaj.zone to Programmer Humor@lemmy.ml · 2 年前

On this deserted island I could use some help()

lemmy.blahaj.zone

message-square
32
link
fedilink
1.17K

On this deserted island I could use some help()

lemmy.blahaj.zone

unlawfulbooger@lemmy.blahaj.zone to Programmer Humor@lemmy.ml · 2 年前
message-square
32
link
fedilink
alert-triangle
You must log in or # to comment.
  • EmergMemeHologram@startrek.websitedeleted by creator
    link
    fedilink
    arrow-up
    66
    ·
    2 年前

    “exit”

    ✈️: Use exit() or Ctrl-D (I.e. EOF) to exit

    • PlexSheep@feddit.de
      link
      fedilink
      arrow-up
      15
      ·
      2 年前

      I mean if they can see that we type exit and show us this message, why could they not just start the exiting when we type exit?

      • Zron@lemmy.world
        link
        fedilink
        arrow-up
        21
        arrow-down
        2
        ·
        2 年前

        Because exit might be a variable you use to determine if you should exit. exit() is a function that actually does the exiting.

        It’s the difference between pointing at a jogger and saying “run” and actually running after them.

        • Bronco1676@lemmy.ml
          link
          fedilink
          arrow-up
          17
          ·
          2 年前

          If you have a variable called exit you’ve overwritten the function in that scope, and won’t be able to execute it.

          e.g.

          >>> exit=1
          >>> exit()
          Traceback (most recent call last):
            File "", line 1, in 
          TypeError: 'int' object is not callable
          >>>
          
          • EmergMemeHologram@startrek.websitedeleted by creator
            link
            fedilink
            arrow-up
            17
            ·
            2 年前

            Reminds me of setting pi = 3 in my friends matlab subroutines in school.

          • peopleproblems@lemmy.world
            link
            fedilink
            arrow-up
            5
            ·
            2 年前

            wow it does do that. cool

      • WhiskyTangoFoxtrot@lemmy.world
        link
        fedilink
        arrow-up
        15
        arrow-down
        1
        ·
        2 年前

        Guessing at what the programmer wants instead of implementing consistent behaviour is what Javascript does. Do you want Python to become Javascript?

        • tetris11@lemmy.ml
          link
          fedilink
          arrow-up
          5
          ·
          2 年前

          Just once I want '1' + '2' to equal '3'. Is that so much to ask?

          • Metype @lemmy.world
            link
            fedilink
            English
            arrow-up
            7
            ·
            2 年前

            You want to remove the string concatenation operator? Cause that’ll do it

            • tetris11@lemmy.ml
              link
              fedilink
              arrow-up
              9
              ·
              2 年前

              I think every language needs a please operator, which acts to enforce human expectation of a statement:

              '1'  + '1'            ## evaluates to '11'
              please '1' + '1' ## evaluates to '2'
              
              • PlexSheep@feddit.de
                link
                fedilink
                arrow-up
                4
                ·
                2 年前

                I kinda like that

          • wewbull@feddit.uk
            link
            fedilink
            English
            arrow-up
            5
            ·
            2 年前

            Yes. Yes it is.

      • Bronco1676@lemmy.ml
        link
        fedilink
        arrow-up
        7
        ·
        2 年前

        This is the code (Github link):

        class Quitter(object):
            def __init__(self, name, eof):
                self.name = name
                self.eof = eof
            def __repr__(self):
                return 'Use %s() or %s to exit' % (self.name, self.eof)
            def __call__(self, code=None):
                # Shells like IDLE catch the SystemExit, but listen when their
                # stdin wrapper is closed.
                try:
                    sys.stdin.close()
                except:
                    pass
                raise SystemExit(code)
        

        What happens is that the python repl calls __repr__ automatically on each variable/statement that you type into the repl (except assignments e.g. x = 1). But this basically only happens in the repl. So “executing” only exit wouldn’t work in a python script as it is not calling __repr__ automatically, so better you learn how to do it right than using just exit in your python scripts and scratching your head why it works in the repl but not in your code.

      • eluvatar@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        2 年前

        Because python has strong opinions

  • sloppy_diffuser@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    41
    ·
    2 年前

    import gravity; gravity = None

    edit: of course there is an xkcd: https://xkcd.com/353/.

    • MajorHavoc@lemmy.world
      link
      fedilink
      arrow-up
      22
      ·
      2 年前

      Incidentally, for anyone who hasn’t typed ‘import antigravity’ into an interactive Python terminal…you should - as Dr Seuss says, “These things are fun, and fun is good.”

      • tetris11@lemmy.ml
        link
        fedilink
        arrow-up
        8
        ·
        2 年前

        I love how it contains exactly one function: from antigravity import geohash

        Hell, this is the entire antigravity library:

        import webbrowser
        import hashlib
        
        webbrowser.open("https://xkcd.com/353/")
        
        def geohash(latitude, longitude, datedow):
            '''Compute geohash() using the Munroe algorithm.
        
            >>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
            37.857713 -122.544543
        
            '''
            # https://xkcd.com/426/
            h = hashlib.md5(datedow, usedforsecurity=False).hexdigest()
            p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h[16:32])]
            print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:]))
        

        He literally gets a 32-bit hash, uses the first half of it as the latitude decimal, and the second half of it as the longitude decimal,

      • 0ops@lemm.ee
        link
        fedilink
        arrow-up
        6
        ·
        2 年前

        NO WAY

    • jcg@halubilo.social
      link
      fedilink
      arrow-up
      3
      ·
      2 年前

      You now start flying away

      And so does everything else, including all the AIR

  • wintermute@feddit.de
    link
    fedilink
    arrow-up
    17
    ·
    2 年前

    What’s the name of the Island, Java?

    • oce 🐆@jlai.lu
      link
      fedilink
      arrow-up
      7
      ·
      2 年前

      Snake island

  • Vespair@lemm.ee
    link
    fedilink
    arrow-up
    11
    arrow-down
    1
    ·
    2 年前

    See it’s funny because we name things after other things

  • dauerstaender@feddit.de
    link
    fedilink
    arrow-up
    6
    ·
    2 年前

    The Python REPL is fucking good.

    • Fedora@lemmy.haigner.me
      link
      fedilink
      arrow-up
      1
      ·
      2 年前

      I see you’ve never used a Lisp REPL before.

    • Andrew@mander.xyz
      link
      fedilink
      arrow-up
      3
      arrow-down
      3
      ·
      2 年前

      No, it’s not: https://github.com/prompt-toolkit/ptpython.

      • GuybrushThreepwo0d@programming.dev
        link
        fedilink
        arrow-up
        5
        ·
        2 年前

        That’s giving me a 404, captain

        • MightyGalhupo@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          2 年前

          Not to me

          • BaardFigur@lemmy.worlddeleted by creator
            link
            fedilink
            arrow-up
            1
            ·
            2 年前

            deleted by creator

        • Andrew@mander.xyz
          link
          fedilink
          arrow-up
          2
          ·
          2 年前

          You can search it yourself. The PYPI package is ptpython.

      • quantenzitrone@feddit.de
        link
        fedilink
        arrow-up
        2
        ·
        2 年前

        https://github.com/prompt-toolkit/ptpython

        the dot at the end of your link breaks it

        • Andrew@mander.xyz
          link
          fedilink
          arrow-up
          3
          ·
          2 年前

          On Sync it works fine. Moreover, it should work on other clients too. You better open a ticket.

  • Crul@lemm.ee
    link
    fedilink
    arrow-up
    5
    ·
    2 年前

    Source: Help – The Jenkins

    RSS Feed: https://thejenkinscomic.wordpress.com/feed/

    • unlawfulbooger@lemmy.blahaj.zoneOP
      link
      fedilink
      arrow-up
      2
      ·
      2 年前

      Thanks!

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 5 users / day
  • 690 users / week
  • 1.6K users / month
  • 5.69K users / 6 months
  • 1 local subscriber
  • 42K subscribers
  • 1.91K Posts
  • 34.5K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.mldeleted by creator
  • cat_programmer@lemmy.ml
  • BE: 0.19.18
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org