Earlier quoted context omitted.
This is nitpicking, but this is a good usecase for the := operator: if not (API_KEY := os.getenv("API_KEY")): ... For internal tools I just let os.environ["API_KEY"] raise a KeyError. It's descriptive enough.
no one uses walrus
I'm switching to Python and actually liking it
511–520 of 718 posts
Re: I'm switching to Python and actually liking it
#512> Not only because the syntax is more human-friendly, but also because the Python interpreter is natively integrated in all Unix distros That's kind of very optimistic evaluation - literally anything beyond "import json" will likely lead you into the abyss of virtual envs. Running something created with say Python 3.13.x on Ubuntu 22.04 or even 24.04 (LTSs) / Rocky 9 and the whole can of worms opened. things like vir…
this is solved by uv
Re: I'm switching to Python and actually liking it
#513Earlier quoted context omitted.
Even slightly better is to first check both if not API_KEY and not CHANNEL_ID: print("Missing both YOUTUBE_API_KEY and YOUTUBE_CHANNEL_ID.") exit(1) if not API_KEY: print("Missing YOUTUBE_API_KEY.") exit(1) if not CHANNEL_ID: print("Missing YOUTUBE_CHANNEL_ID.") exit(1) That way you don't end up fixing one just come back and be told you're also missing another requirement
Even better would be to only check each once and buffer the decision: valid = True if not API_KEY: print("Missing YOUTUBE_API_KEY.") valid = False if not CHANNEL_ID: print("Missing YOUTUBE_CHANNEL_ID.") valid = False if not valid: exit(1) This way you only check each value once (because your logic might be more complicated than just checking it's not set, maybe it can be wrongly formatted) and you still get to do wha…
Re: I'm switching to Python and actually liking it
#514Earlier quoted context omitted.
Well that explains why you think pip is broken
Because I went to the official pip "getting started" docs and did exactly what it says? It's bad even in venv though, like not managing your requirements.txt or installing conflicting stuff. The web is full of questions about this, with answers that involve installing some other thing.
but yes, pip predates the paradigm of package managers managing your dependency file instead of you managing your dependency file and then invoking the package manager
Re: I'm switching to Python and actually liking it
#515Earlier quoted context omitted.
Java shops are certainly where I've witnessed the most disdain for Python. IME the strongest feelings tend to come from people who didn't actually have any significant experience with Python, and perhaps don't even have much practical experience with any language that isn't Java. So they tended to consider it to be objectively inferior purely because it's interpreted and dynamically typed. At a previous job I did man…
> Java, for its part, can also accumulate a lot of dynamic language-style performance losses to pointer chasing and run-time type lookups (and GC churn) if you're not careful about how you use generics. The worst thing about Java is the average quality of Java programmer.The same could probably be said about Python. However I think that there are fewer Python programmers trying to write AbstractFactoryFactory than in…
Re: I'm switching to Python and actually liking it
#516Maybe I'm the only one that finds Python simultaneously verbose and lacking? Either you need 500 dependencies to do something in a simple way, or you need dozens (if not hundreds) of lines to do trivial things. I avoid writing Python because there's so much bullshit to add. Much prefer Perl, I can actually get things done quickly. Python feels like programming for the sake of programming.
> Much prefer Perl, I can actually get things done quickly Python lets you just nest data structures without having to twist your brain. You want a tuple in a list in a dictionary value: you just write it down and can access it with a unified notation. Bam. No reference madness and thinking about contexts. It's a big part of what I typically need to get things done quickly and understand how I did it 5 years later. T…
That was about the time I stopped using Perl for any new projects. I never wanted to go back.
Re: I'm switching to Python and actually liking it
#517Earlier quoted context omitted.
This isn't really unique to the walrus operator, it's just a general python quirk (albeit one I find incredibly annoying). `for i in range(5): ...` will leave `i` bound to 4 after the loop.
Oddly enough, "except" variables don't remain bound! try: x = int('cat') except Exception as e: pass print(e) # So, it appears Python actually has three variable scopes (global, local, exception block)?
https://stackoverflow.com/questions/24271752
https://docs.python.org/3/reference/compound_stmts.html#exce...
Re: I'm switching to Python and actually liking it
#518Earlier quoted context omitted.
Neophytes take notice. Attention to details like this is what separates truly great programmers from merely good ones. That said, for scripts reusable by others you should use command line arguments . Environment variables in lieu of command line arguments is a huge code smell.
You don't generally want API keys accidentally recorded into someone's bash history.
Re: I'm switching to Python and actually liking it
#519Maybe I'm the only one that finds Python simultaneously verbose and lacking? Either you need 500 dependencies to do something in a simple way, or you need dozens (if not hundreds) of lines to do trivial things. I avoid writing Python because there's so much bullshit to add. Much prefer Perl, I can actually get things done quickly. Python feels like programming for the sake of programming.
Could you share an example, where Perl is quicker to use and more powerful?
Perl falls apart when you need structure and even small projects. For short scripts meant to do what you would use Bash for, it's a godsend. Safer, more portable, less friction.
Re: I'm switching to Python and actually liking it
#520Earlier quoted context omitted.
> it's default This point is true; the ecosystem simply can't change overnight. uv is getting there, I hope. > it always works the same everywhere `uv` works the same, everywhere? > it actually writes down the deps `uv add` does that, too. > I don't have to manually switch between them (or set up fancy bashrc triggers) like venvs. You don't have to do that with `uv`, either?
Hope they make uv default then. It's nice, but I have to separately create a project with it, and regular python commands don't work with it, both of which go back to it not being default. But even that won't fix all the old projects.