|
I'm with the cops, you're all busted
|
# ¿ Feb 24, 2019 17:53 |
|
|
# ¿ May 16, 2024 08:19 |
|
You mean just running a bit of code to check it works or to generate some output quickly? You can do that with shift+return in VS Code too
|
# ¿ Mar 2, 2019 21:23 |
|
Arguably the loop version is the most explicit and clean - loop over an iterable until you find an element that matches the predicate, then move on. Creating a generator just to call next on it once works, but it feels hacky to me Not the first time I've thought itertools needs a first function tbh
|
# ¿ Mar 13, 2019 01:08 |
|
Typically in other languages first (or whatever) takes a predicate and an iterable and returns the first item that matches. It works like filter only it's explicitly for a single item, and you don't need to wrangle some result sequence to grab what you actually want. So you get a very simple, neat, explicit call that either returns a result or some default/missing value, or even throws an exception (depending on the implementation obv) I mean yeah you could just write it yourself but it's a nice thing to have, and it's very common baka kaba fucked around with this message at 01:58 on Mar 13, 2019 |
# ¿ Mar 13, 2019 01:55 |
|
I think you're meant to use time.monotonic for basic scheduling, that might be the easiest way of calculating elapsed real time if I were doing this I'd use your short-sleep polling method, but with a little more logic around it. If the next beat is extremely close (like your expected sleep period might cross it) it might be better to play it early. Or maybe calculate a more accurate sleep period to aim for the exact time you need to hit. If you overshoot, make sure you play the beat - it should never actually skip one, even 600bpm is a beat every 100ms, you shouldn't be locked out of your process for that long surely? Also make sure your scheduling is completely separate from the actual time your beats get played. If you start at time 0, and you have beats at 0.5s, 1s, 1.5s etc, and your second beat comes out late at 0.51s, make sure your next beat time is calculated at 1s, not 0.51 + 0.5, y'know? So you have a constant pulse scheduled, and if a beat is inaccurate it doesn't affect the others that follow. You're probably already doing this but it's worth mentioning, you don't want timing errors compounding ALSO I see you're using Qt I think? Have you tried using QTimer which they recommend over the sleep methods? Or using Qt's Priority values to create a high-priority worker thread (or just bump the priority of the main thread, might be a bad idea though, you'd have to test it I don't know Qt)
|
# ¿ Mar 30, 2019 01:52 |
|
Rocko Bonaparte posted:If we want something to play with in that regards, I recently had a list of strings that I wanted to iterate in groups of fours. Generally there's some mish-mash of syntax in itertools to do that, but they all were kind of wonky. It smelled like something with a functional solution (ie "Do this to every group of four elements of this list") but expressing it was gross. ime functional languages tend to have a built-in function that does this, I don't think python does yet - whenever I try to use it in a functional way it always feels a little half-baked to me. Probably because it was designed with stuff like comprehensions and generator expressions that encourage pure functional behaviour (take an input and iterate over it to produce a new output), so all the other things feel a bit like an afterthought to try and expand that. (I know map and filter have been in there forever, but a lot of the time it's like... why not just use a generator or comprehension?) look at partition in the link SurgicalOntologist posted anyhow
|
# ¿ Apr 4, 2019 20:28 |
|
Honestly when I got a new computer I just installed straight python, I used Anaconda before but the combination of having multiple library sources to worry about (conda, pip) and the fact their virtual environment stuff still didn't work with the standard windows terminal made me think it's just not worth the hassle apparently they have some hacky script to make powershell work now, that runs a copy of python every time you open a PS terminal whether you're using conda or not
|
# ¿ Apr 5, 2019 01:49 |
|
mr_package posted:How are you organizing your @dataclass objects? If each instance is essentially a row from a database, is there a good way to order/organize them? e.g. if I just shove everything into a List I need to iterate through to try and find the specific instance I'm looking for. There's probably a smarter way? If you think about it though, the primary key in a database row is part of the organisational system, so it makes sense to have it as the key in the dictionary. It's what you're using to identify and reference a particular data object And sometimes that primary key is also part of the data object, like an ISBN, instead of just an internal identifier the database is using. So in that case, it makes sense to also have it in the object you're storing in the dictionary. Chances are the thing that ends up accessing it will want to make use of that attribute, but won't necessarily have access to the dictionary. And maybe you might want to change that implementation anyway - but the data should stay the same, right? Store what you need to store So yeah you're storing the same piece of data twice, but imo that's ok, it makes sense sometimes! You'll probably want to write something that enforces that consistency - maybe a class that holds the dictionary internally, and adds stuff by automatically reading the key from your data and using that to add an item, so you never interact with the dict directly. It depends if end users care about the ID or not - I'm guessing they supply it for lookups? (If you really care about this redundancy you could have a fetch method that adds the key to the returned data, so you store it separately but the user gets the whole thing) Also don't forget if the IDs are in sequential order you can just index into a list instead, if that works for you
|
# ¿ May 11, 2019 07:03 |
|
Well by "end user" I really meant whatever's calling it (should have said client). So say your web app goes "hey I need that list of languages" and your Python code goes "here ya go, each one has an ID". If the web app is doing something like displaying all the languages, letting the user pick one, and then passing the relevant ID back to your Python code, that ID is sort of temporary - it's like getting a menu of options and going "yeah, the third one", once you get the thing you wanted you don't really need to remember what its position was anymore, right? Whereas if you're gonna need to reference that ID again later somewhere, it makes sense to bundle it up as an attribute of the Language, since it's more of a persistent reference and the way you actually specify which object you want - it's acting more like a database, the primary key is part of the data (even if the user doesn't ever see it). It depends on exactly what you're doing, but by the sound of it the ID is probably gonna be a persistent reference, right? If the duplication bothers you, imagine you have Languages with an ID field, and you're storing them in a list. That's basically a database table. You can search it just fine, looking at the ID field, but for speed in a database you might want to build an index, which is basically another table that holds the key (so you now have a copy in two places) and a pointer to the data in the first table. That combo of index and data table is sort of what a dictionary is, so it's not that weird to have the key present in the lookup and the data itself! Like I said you could separate the key out for storage, and recombine it with the data when it's retrieved, but that's extra complexity that needs to be worth it baka kaba fucked around with this message at 19:24 on May 11, 2019 |
# ¿ May 11, 2019 19:21 |
|
Maybe "batteries included" isn't the best idea because those batteries are usually crappy and get discarded quickly?? Make it easier for people to add their own quality batteries
|
# ¿ May 20, 2019 01:04 |
|
A for loop basically iterates over a bunch of items, handing you each item in turn. So in the body of the loop, you do something with the current item, and when you run the loop it will basically do that thing with all the items. so you want something like Python code:
e- lookit all them replies
|
# ¿ Jun 25, 2019 20:11 |
|
Use a for loop, look at each name, build up a total
|
# ¿ Jun 25, 2019 20:22 |
|
Mycroft Holmes posted:wait poo poo thats the next question, i'm stuck on the find a number of letters instance nobody just wants to give you the answer but Python code:
|
# ¿ Jun 25, 2019 20:40 |
|
|
# ¿ May 16, 2024 08:19 |
|
Mycroft Holmes posted:except that answer fails You probably need to convert each name and your input letter to lowercase (or whatever, just so there's no mismatch) because 'e' won't match 'E'
|
# ¿ Jun 25, 2019 21:04 |