D•Scribe
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
unlawfulbooger@lemmy.blahaj.zone to Programmer Humor@lemmy.ml · 1 year ago

On this deserted island I could use some help()

lemmy.blahaj.zone

message-square
13
fedilink
39

On this deserted island I could use some help()

lemmy.blahaj.zone

unlawfulbooger@lemmy.blahaj.zone to Programmer Humor@lemmy.ml · 1 year ago
message-square
13
fedilink
alert-triangle
You must log in or register to comment.
  • EmergMemeHologram@startrek.website
    link
    fedilink
    arrow-up
    4
    ·
    1 year ago

    “exit”

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

    • PlexSheep@feddit.de
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      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
        1
        ·
        1 year ago

        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
        1
        ·
        edit-2
        1 year ago

        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.

  • dauerstaender@feddit.de
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    The Python REPL is fucking good.

    • Andrew@mander.xyz
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

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

      • quantenzitrone@feddit.de
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

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

        the dot at the end of your link breaks it

        • Andrew@mander.xyz
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

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

      • GuybrushThreepwo0d@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        That’s giving me a 404, captain

        • Andrew@mander.xyz
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

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

  • sloppy_diffuser@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    import gravity; gravity = None

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

  • wintermute@feddit.de
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    What’s the name of the Island, Java?

    • oce 🐆@jlai.lu
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Snake island

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.

  • 95 users / day
  • 1.69K users / week
  • 3.14K users / month
  • 9.98K users / 6 months
  • 9 local subscribers
  • 35.9K subscribers
  • 1.44K Posts
  • 21.5K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • UI: unknown version
  • BE: 0.19.9
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org