« first day (4243 days earlier)      last day (688 days later) » 

6:54 AM
good lord it's not only the walrus being meh, the match expression active trips over people that might try to use it, ran head first into this...
I am really not impressed.
 
7:21 AM
Up until now, python has always... well, executed all the code you write. For example, str() always meant the same thing as ''. The match statement is the first thing that breaks this rule
 
 
1 hour later…
8:37 AM
People: "why doesn't Python have a switch statement?"
Python: "here you go 🤪"
 
 
1 hour later…
9:53 AM
@AndrasDeak--СлаваУкраїні Only if the did the same thing with 4.0 :P
 
 
2 hours later…
11:44 AM
Wow, so match is awful too huh
Feb 1, 2018 at 20:07, by vaultah
A great deal of recent Python features motivates me to spend more time learning other languages
 
it's probably great if you know its quirks and don't think it's switch :P
 
Let's be honest here, new features don't really do us any harm. Nobody's forcing us to use them, and by the time we see them in other people's code, we're already familiar with them. The real victims are the people who will start learning python in a few years, because it's becoming an increasingly complex language.
 
@AndrasDeak--СлаваУкраїні I knew it's different from switch, but I still haven't read the PEP and the documentation for it. match behavior from that Q&A seems unreasonable regardless
 
I've never had a use for match yet
have found a few uses for the walrus operator though
(mostly either relating to re or a dict.get...)
if cusref := order_metadata.get('_purchase_order_number', '').strip():
    base['CustomerOrderNumber'] = f'{cusref} - TCTP{order_id}'
I think that works out being quite elegant for instance
 
yeah, restricting asspressions to such header lines would make me only dislike them rather than hate them with a passion
 
11:58 AM
@Aran-Fey in that case they may decide to learn a different language, which could become the next "most popular language for X" as a result
Which would harm "us"
 
I guess
 
 
2 hours later…
2:09 PM
I'm really confused about that error in the match statement. Why should it crash out if other branches are unreachable?
The cases should be exhaustive and, while it "probably" isn't what you intended, is that justification for an error? If I made a mess of my if/else such that else would never be evaluated - that's not a crashing error
 
Pretty sure it only triggers in blatantly incorrect cases like case some_variable_name:, in which case it'll definitely save some people a lot of debugging trouble
 
I can definitely see the utility of a check like that but it's odd that it codes against a footgun. I bet after a little more thought I'd come up with other examples of similar safety nets but having only just looked at match that seems somewhat exceptional
 
2:28 PM
Actually, I can't think of any examples where the logical flow of your code could throw an exception, other than exceeding the boundaries of the language itself e.g. comparing incompatible types or something
I suppose, though, closing down ordering of mixed collections like a list of int and string from Python 2->3 constitutes a "this could work but it isn't what you wanted to do" error
 
 
1 hour later…
3:47 PM
For the sake of consistency, they should make if True: f() <newline> else: g() raise a SyntaxError too
Along with any other expression that can be deduced to be truthy by the bytecode optimizer. It already converts if True: f() to just f(), so the foundation is ready to go
 
if True: can be handy for debugging purposes though
 
Reasonable. Perhaps, then, unreachable matches can be handy for debugging as well. (disclaimer: I have spent five seconds total thinking about this)
 
Yeah, they probably can. But match has something that if doesn't, which is... confusing syntax
 
Yeah. Case in point: looking at stackoverflow.com/questions/67525257/… a second time, I see that I misread what was causing the issue.
Not that "Kevin was confused by X" is strong evidence that X is confusing. There are many many counterexamples.
I am often confused by things such as magnets, triangles, and spinning tops
Mere children's toys, all of them
 
 
1 hour later…
5:19 PM
wow... never seen
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)
before
 
5:39 PM
Is there a canonical for "how do I send data from a web page form submission to a Python program on the server?" I mean, something not specific to a web framework, but something that either explains the *need for* a web framework, or else does something really bare bones and NIH-syndrome.

Or do we have to close them all as "seeking a library recommendation", even though OP wouldn't have *expected* a library to be needed?
(this will definitely be a "part 2" topic in my book)
@JonClements I wish I had internet that was reliably capable of running into that :(
 
@Karl do you mean a page that's sending data to something hosted in Python or using Python to submit a form?
 
The question doesn't really make sense without a framework, does it? Python doesn't submit the form, it receives and handles it. And how you do that depends on the framework.
 
the former. The specific question prompting me is stackoverflow.com/questions/71860765/…
(assuming I have properly read OP's intent)
 
I'd close that as unclear tbh
 
although it seems like OP is also interested in doing the latter eventually: stackoverflow.com/questions/72425793/opening-html-with-python
@Aran-Fey the question as is, yes (and in fact I already voted that way), but I'm sure I've seen the topic come up before and I'm sure it's possible in principle to ask in a way that can't be called unclear (or too broad)
if I search for example stackoverflow.com/search?q=%5Bpython%5D+%5Bhtml%5D+form, I get results for both tasks @JonClements describes, and generally stuff specific to either Flask or Django.
 
5:47 PM
surprised there's none for fastapi these days :)
 
6:01 PM
maybe it's too easy to use so it doesn't cause problems ;)
 
I love how mods remove my code snippet answer because I didn't credit where I found it from.

Therefor preventing anyone who ever stumble on that question to have an answer.
 
(more realistically, it's less than 4 years old and still in 0.x versions; Django is turning 17 soon)
@GaryOak there are standards here for answers, as described in stackoverflow.com/help/how-to-answer. Plagiarism is a serious concern, because the site claims a Creative Commons license on everything posted. We have to care about copyrighted content and about copyright being asserted by others. Also, a code snipped by itself is generally not a satisfactory answer.
We do not publish answers just because it might possibly be of use to someone else. In particular, we don't do it just because it helps the OP. We are trying to build a high-quality, searchable repository. Most new questions should not be answered at all, because they either are duplicates or are too low quality to help out with that goal. In particular, most of what we get is requests for debugging help, and it is rare that one of these has a good, new question at the core.
Usually the best case is that someone notices a pattern in how new programmers get stuck in their debugging, figures out the underlying problem, refines it into a question that can be given a searchable title, and then we get a new canonical. This is a very difficult process.
 
6:19 PM
He was asking for a way to have "total orders" listed on WordPress's WooCommerce Dashboard widget.

That can be done with the snippet I posted.

It's from an opensource github project, was updated 1 month ago and I used it myself to test before posting since it's not a bad thing to add.
Deleting a functional answer because there's no credits seems completely counterproductive.

I don't need the answer removed to read the mod team message about plagiarism.
Just comment/edit the source/credits
Dont delete the thing
Anyways, unrelated to python, just venting.
 
I can't possibly comment any further without knowing which question you're talking about. [I'm also not a mod; I don't know if any mods are present currently; and many things get done here through a democratic process rather than mods taking action.]
 
Let me finish reading what you wrote
before shooting my other foot
@KarlKnechtel Ok but isn't the upvote system made to determine what is and isn't a valuable Question?
Why overkill it
Also, maybe the phrasing is a bit different and will be indexed on google for different keywords.
Bringing new people finding the good answer on StackOverflow
 
@KarlKnechtel sometimes there is :p
 
stretches
 
6:36 PM
@GaryOak please go back to talking about Python, or venting elsewhere
 
What would be the best way to count cards at blackjack in python
 
7:08 PM
Design question. I have an ocr module that provides a standardized API for multiple 3rd-party OCR engines (for example Tesseract). The user can import a specific engine like import ocr.engines.tesseract, but they can also just import ocr and use the convenience functions in that module, which will pick a suitable engine on the user's behalf. (For example, import ocr; ocr.read(some_image).)
The problem is what should happen if no OCR engine is available. I don't want to make import ocr fail with an ImportError, because of reasons. Should I just throw an exception in ocr.read()? Or should I re-design the module and force the user to do something like import ocr.default_engine? Or something else that I haven't thought of?
 
As an interested user, I would like having the error outputed in stdout if import ocr fails, with the appropriate message: "No OCR engines are available, please import manually (ocr.engines.tesseract)"
 
@Aran-Fey is there any functionality that can still be used without a backend?
 
Yes. Just because the library can't find a backend that doesn't mean it's not there. If the user knows where their Tesseract executable is, they can pass that path to the TesseractEngine constructor
@GaryOak Stdout isn't how a library should communicate with a programmer. I could throw a warning or an exception though
 
in that case it makes sense to raise in the convenience function
basically raise on the first step that would actually need the backend
 
Ok cool, I'm also leaning towards that design
 
7:21 PM
@Aran-Fey I misread your first sentence.
 
 
1 hour later…
8:38 PM
"I don't want to make import ocr fail with an ImportError, because of reasons." What reasons are these? if there are other useful things that `import ocr` can provide, *without any engine being found*, then I endorse the idea of putting the engine-requiring convenience stuff in a sub-module. (Instead of naming it after the idea that it picks an engine for you, name it after the provided functionality.)

otherwise I don't see a reason not to raise the exception.
> If the user knows where their Tesseract executable is, they can pass that path to the TesseractEngine constructor

I'm a little confused here. I assume the idea is that `ocr.engines.tesseract` defines a class, but the class acts as a wrapper for an executable that will be started off as a separate process?
it's not clear to me how the default implementation, in that case, is deciding where to look for the executable, or how it's choosing an engine
the other question is: does the default setup have to choose an implementation ahead of time, or can it wait until ocr.read etc. is called?
(you might take some inspiration here from the design of the standard library random module)
 
@KarlKnechtel Yes, that's exactly right. You provide the path, so the module can still do something useful. That's why I can't have import ocr throw an error
How it's choosing an engine or where it's looking for the exe isn't relevant. It doesn't have to choose an engine at import time; it can wait until the first call to ocr.read. I don't see a reason to do that, though
 
9:12 PM
If you like, I can try to show an example of the code organization as a Gist on Github.
 
Of the random module? It turns bound methods into global functions, right?
 
yes, but I have in mind a way to take the idea a little further.
 
9:27 PM
Ah, I see, I've done something similar. I defined an abstract base class, and for every abstract method it has I create a wrapper function like that
 
The reason for deferring is that you don't really have options besides deferring it or raising the exception on import. If you try to load the implementation eagerly, and it fails, and you don't raise an exception.... then what? nothing happens until a method is used... at that point, wouldn't it be better to try to look for an implementation than to fail automatically?
(I suppose you can also try to look for an implementation eagerly... but if it didn't work the first time, why would it work the second time?)
 
I basically do something like
try:
    from .engines import default_engine
    create_global_functions()
except ImportError:
    create_dummy_functions()
 
that's also a useful technique, but do keep in mind that, at this point, it's transparent to the user whether dummy functions were created. What will they do when encountered?
this gets into general philosophical territory about exception handling. (I've had times where I had to argue rather vigorously for just ignoring an exception, because it was a mobile environment with nowhere to log anything, and because the exception came from failing to play a sound so that there were no meaningful recovery steps to take)
(but with OCR, I think I'm going to be rather upset if I try to OCR something and get an empty string back, and the reason is because I put the underlying executable in the wrong place, and not because there isn't any text in the image.)
 
What do you mean by encountered? If you try to call a dummy function, you get an exception
 
yeah
people who know ahead of time that they have a custom setup, and have to specify a path, will not really be able to use the convenience interface anyway - you can't really pass arguments to the module-import process.
so the system you describe overall sounds reasonable.
in my related case, I was actually writing my redesign of random, because of the various things I didn't like about it. :) I had it in mind that the default convenience implementation should use SystemRandom when available, and I quickly realized that it would have to switch to an ordinary Random instance as a fallback otherwise. I also determined in that case that it would be better to do the loading eagerly.
 
9:39 PM
@KarlKnechtel Yeah. I thought about adding a way for the user to set the default engine, so they can use the convenience interface if they want, but ultimately I don't see a point
 
Potentially that could be done with an environment variable or hard-coded config file, I suppose.
 
 
2 hours later…
11:49 PM
stackoverflow.com/questions/72428020 any better duplicate for this?
stackoverflow.com/questions/2983139/… oh, that was already linked within my original hit :)
 

« first day (4243 days earlier)      last day (688 days later) »