• 0 Posts
  • 42 Comments
Joined 1 year ago
cake
Cake day: December 30th, 2023

help-circle




  • This is what I would come up with:

    try:
        if len(foo) == 0:
        ...
    except TypeError:
        ...
    

    There is no need to add a None check, as foo being None should be considered as a faulty input. Avoiding the possibility of foo being None from the beginning using static checks or testing is of course the preferred solution. But in reality we do not work in such optimal environments, at least I can say that from the perspective of data science, where often procedural, untested code is produced that runs only a few times. But I get your point and I think both paths are viable, but I am also okay with being in the wrong here,


  • I am not saying it’s better, just that I don’t like the proposed way :) I would argue that being “pythonic” has even less value than the Zen, which I quoted because it’s true, not because it is some strict rule (which it isn’t anyway).

    You could argue I also need to write that extra code for the if not case, as I explicitly have to check if it is None if my program somewhere further down expects only lists.

    Hunting for those sweet milliseconds is a popular game in the Python community ;) if this mechanism is that important for your program, you should definitely use it, I would do as well!















  • Nice I guess it’s time to check if my daily used libraries have stable 3.12 releases already.

    I guess the free-threaded mode and the JIT compiler will be the most important features from what I read, but their significance is out of my expertise.

    My absolute favorite with this update is the new REPL! It features Multiline-editing and a paste mode for easier pasting code. It also added the spaces automatically in my example.

    Sometimes I want to make some quick tests on some data in the terminal without installing IPython to my environment first, this is great news!

    This new error message will also be very useful for beginners and relieve StackOverflow:

    AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/numpy.py' if it has the same name as a third-party module you intended to import)