• JATth@lemmy.world
    link
    fedilink
    arrow-up
    17
    ·
    edit-2
    2 months ago

    Python is just a pile of dicts/hashtables under the hood. Even the basic int type is actually a dict of method names:

    x = 1
    print(dir(x))
    ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', ... ]
    

    PS: I will never get away from the fact that user-space memory addresses are also basically keys into the page table, so it is hashtables all the way down - you cannot escape them.

  • demesisx@infosec.pub
    link
    fedilink
    English
    arrow-up
    17
    ·
    2 months ago

    This is why I decided to learn Nix. I built dev environment flakes that provision the devshell for any language I intend to use. I actually won’t even bother unless I can get something working reliably with Nix. ;)

    For example, here’s a flake that I use for my Python dev environment to provide all needed wiring and setup for an interactive Python web scraper I built:

    
    {
      description = "Interactive Web Scraper";
    
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable";
        utils.url = "github:numtide/flake-utils";
      };
    
      outputs = { self, nixpkgs, utils }: utils.lib.eachSystem ["x86_64-linux"] (system: let
        pkgs = import nixpkgs { system = system; };
      in rec {
        packages = {
          pyinputplus = pkgs.python3Packages.buildPythonPackage rec {
            pname = "pyinputplus";
            version = "0.2.12";
            src = pkgs.fetchPypi {
              inherit pname version;
              sha256 = "sha256-YOUR_SHA256_HASH_HERE";
            };
          };
    
          pythonEnv =
            pkgs.python3.withPackages (ps: with ps; [ webdriver-manager openpyxl pandas requests beautifulsoup4 websocket-client selenium packages.pyinputplus ]);
        };
    
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.chromium
            pkgs.undetected-chromedriver
            packages.pythonEnv
          ];
    
          shellHook = ''
            export PATH=${pkgs.chromium}/bin:${pkgs.undetected-chromedriver}/bin:$PATH
          '';
        };
      });
    }
    
    
      • demesisx@infosec.pub
        link
        fedilink
        English
        arrow-up
        12
        ·
        2 months ago

        It feels like magic. I think of it as the glue that makes almost all of my software work together seamlessly. I can’t wait to use it for one-click deployments of my software on a server or high-availability cluster.

    • elliot_crane@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      2 months ago

      This is basically what I’ve been telling people for years. Prototype in Python to get the concepts down, then when you’re serious about the project, write it in a serious language.

      • Swedneck@discuss.tchncs.de
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        2 days ago

        python is IMO the closest thing we have to a platonic ideal scripting language: it’s pseudocode that actually runs and you can just slap together libraries with minimal mental effort until it works.
        Great for gently getting into programming so you quickly see results without having to learn arcane incantations, and for writing small tool programs; not so great for writing a kernel in.

  • GTG3000@programming.dev
    link
    fedilink
    arrow-up
    9
    ·
    2 months ago

    Man, the variable scoping thing is insidious. It will never not be weird to me that ifs and loops don’t actually create a new scope.

    And then you try to do a closure and it tells you you didn’t import anything yet.

    • MashedTech@lemmy.worldOP
      link
      fedilink
      arrow-up
      9
      ·
      2 months ago

      Of course! Why didn’t I think about that? Maybe I could also switch some other parts of the code to Lisp?

    • tiredofsametab@fedia.io
      link
      fedilink
      arrow-up
      2
      ·
      2 months ago

      I still sometimes bang out small perl scripts for things that are too annoying/complex for command prompt and shell scripts but not worth writing something in, say, Go. I never learned python which is probably why I never use that.

      • OpenStars@discuss.online
        link
        fedilink
        English
        arrow-up
        2
        arrow-down
        1
        ·
        2 months ago

        People keep saying Python, despite how it (1) sucks, and (2) is super annoying to keep up to date, with package management and the like, unlike Perl that is more stable. Though Python is also easy to use and powerful and extensible.

        But I think each language type is what it is and has its own set of tradeoffs and balances. Unix is hyper-stable and secure but limited, Perl is powerful but requires discipline to use to full effect, and these days most people don’t bother to learn it. Python is… “common”, is perhaps the best way to put it:-). C/C++ is even more powerful, the latter bloated, and blamed for most memory management issues (although really, how much of that is merely bad programming practice? Okay, so it allows such though).

        And now Rust is the new hot thing.:-)

        • tiredofsametab@fedia.io
          link
          fedilink
          arrow-up
          2
          ·
          2 months ago

          I enjoyed working with Rust once I got into its workflow. The borrow checker and lifetimes suck for people not used to the concepts. The funny thing about languages with lots of safety features is when people just unsafe things, an option in many languages to give oneself plenty of rope for a self-hanging (or, “footguns” is the hip new way of saying that).

          • OpenStars@discuss.online
            link
            fedilink
            English
            arrow-up
            2
            ·
            2 months ago

            I’m guessing it says “either I’m being forced to use this language or it’s the only related one I know how to use, but only halfway”:-)