|
Probably using a remote debugger, I imagine.
|
# ¿ Apr 6, 2019 13:55 |
|
|
# ¿ May 13, 2024 04:29 |
|
Loezi posted:Today I learned about https://docs.python.org/3/library/contextlib.html#contextlib.suppress and Basically anything where you're dealing with a resource that should eventually be released can use it. Off the top of my head, sqlite connections, thread Locks, and socket servers all can make use of the "with" statement, which is essentially shorthand for the traditional try-finally block that you would use to ensure an open resource is released when it is no longer needed. In more concrete terms, any object which implements the __enter__ and __exit__ methods is a context manager, and will work with "with". susan b buffering fucked around with this message at 09:47 on Apr 13, 2019 |
# ¿ Apr 13, 2019 09:35 |
|
mr_package posted:When working with relational data, do you keep it in relational format or just flatten it all? I'm pulling a bunch of stuff out of a database and the tables are all normalized correctly, and I'm not sure whether to keep the small id:text tables. So for example, each item has a "language_code" parameter, in the database it might be 1/2/3 for en-US/fr-FR/de-DE but I could easily pull that out and have it be "en-US" instead of 1 and not even maintain this separate table at all. Advantages of being more human readable might outweigh the bloat and slowness of trying to update all 5k items if we changed to "en_us" or something. I tend to keep things relational by having my DB models represented as classes with relevant methods for accessing related objects. So in your case, I'd have something like: code:
You can even add a @property decorator above the method so it can be accessed as Text().lang. I would recommend looking into ORM and datamapper design patterns for more ideas.
|
# ¿ May 10, 2019 02:44 |
|
mr_package posted:Thanks that is something I was thinking about too-- keep the schema as-is and then just try to provide a clean interface (if only to myself) to it. I probably would, but I also try and keep my models fairly agnostic of where the actual data is coming from. Common properties would come from a base class/mix-ins or sometimes stored in an object/dict passed into the instance. When it comes to serialization, I'm definitely doing a bit of flattening. 2-column id:text tables are probably just going to be represented as the text. Related tables with more fields get an object(take care if your db structure allows for recursive dependencies ) and/or locator uri if this is being served as a REST API. I personally try and avoid de-normalizing an already normalized database, especially as a shortcut to what my bespoke ORM should handle in code anyways. I totally believe you can make an educated decision to do so and be fine. For instance, with the lang table you mentioned in the first post, one could argue that since language tags are already standardized, keeping them in a separate table is excessive. OTOH that sort of table structure can be a real benefit if you need to track down / prevent typos or other invalid data. I've actually been doing basically the opposite of what you've been doing, which is writing a wrapper for a REST api I pull data from pretty regularly, which will probably end up in a sqlite database. I made heavy use of dataclasses, which I highly recommend looking into(namedtuples, too). Here's my base model class and one of the child classes. Python code:
susan b buffering fucked around with this message at 19:06 on May 10, 2019 |
# ¿ May 10, 2019 18:57 |
|
The PEP for a local packages directory at least seems like a promising step forward.
|
# ¿ Jun 6, 2019 04:00 |
|
KICK BAMA KICK posted:None of those books/videos look like the standard "learn Python" recommendations (IDK anything about those fields so I'm not sure if the ones specifically about like Pandas would be relevant to your interests). But PyCharm is the most common IDE for Python, and I think some of the features the Professional edition adds do relate to math/scientific/data libraries like NumPy, which I'm guessing you'd find yourself using at some point, so those licenses in the bundles are a great value (like $89 for a year standard but maybe you can swing an educational discount?). My suggestion: set the reminder on that bundle, install the free edition of PyCharm, start learning from whatever resource you find/someone else here recommends, and if you think you're gonna keep using it grab that 6-month Professional license at the $20 tier, can't lose at that price. PyCharm Pro is free for students (along with the rest of their IDEs).
|
# ¿ Sep 14, 2019 22:49 |
|
Lambdas must evaluate to a value, which is why that doesn’t work. lambda: None would probably work.
|
# ¿ Nov 12, 2019 21:14 |
|
I tend to use NamedTuples from the typing module for data containers, and DataClasses for when I need a bit more than that. I’ll probably use typed dicts more with APIs. Haven’t really had a chance to mess with them yet. Dominoes posted:Lists of tuples sounds like trouble, since you're relying on indexes, which have no semantic meaning. You can use the functional API to achieve what you want. The below is equivalent to what you posted. I chose the space-delimited form for the second argument, but a sequence or mapping can be used instead. Python code:
susan b buffering fucked around with this message at 02:00 on Nov 21, 2019 |
# ¿ Nov 21, 2019 01:51 |
|
QuarkJets posted:Does pycharm have the ability to do a project-level replacement of .format strings with f-strings? It can definitely do it on single lines but I can't seem to find the ability to do it globally and Google isn't helping. I think you can use code inspections to do this. On my phone so can’t check.
|
# ¿ Dec 2, 2019 21:58 |
|
The one click droplet on DO is hilariously out of date last I checked, but a $5 droplet can run django just fine. I’d recommend gunicorn for your WSGI server along with nginx. The gunicorn docs have a guide for this. Also definitely use a virtual env. Deployment can be somewhat tricky but it’s worth figuring out. You can also just run it locally until you feel more comfortable.
|
# ¿ Jan 21, 2020 15:44 |
|
yeah, you're gonna have a much better time keeping the script simple and letting an external runner send you an email when the script fails. if anything, you may want to do some logging to help diagnose any issues that come up. if you use systemd timers instead of cron then logging is simply a matter of printing log events to stdout
|
# ¿ Feb 18, 2020 22:21 |
|
You can use NetworkX to draw graphs with matplotlib, but the docs for this will tell you to use a dedicated tool like graphviz. graphviz is a separate executable but the graphviz python module will call it for you to render graphs, so you don't need to feed it anything manually.
|
# ¿ Feb 20, 2020 20:32 |
|
Zero Gravitas posted:Is there a way to create pandas dataframes in a class object? (I think thats the term.) code:
code:
|
# ¿ Mar 15, 2020 15:32 |
|
CarForumPoster posted:I've never thought to use a df in a class before, good example. Yeah, concat is right. I hadn’t really thought of doing what the OP is doing either. The closest I’ve come is having a method return a dataframe, with the data coming from a sqlite database.
|
# ¿ Mar 15, 2020 17:16 |
|
Think I'm fully onboard the attrs train now. The ability to define a converter function for attributes is extremely convenient when dealing with nested data structures.
|
# ¿ Mar 28, 2020 22:32 |
|
Splitting up the work that way should be fairly ideal in terms of speed-up. Number 2 might be possible but I wouldn’t count on it being simple if it is. You would have a much better time if those series were stored in an array like a pandas dataframe or just a plain numpy 2d array, even if just for the computation you’re doing. I’d also recommend looking into using Numba for what you’re doing instead of joblib. It’s a JIT compiler that also handles threading and works particularly well with numpy arrays.
|
# ¿ Apr 9, 2020 23:29 |
|
TheKingofSprings posted:Python is remotely sshing into a raspberry pi and launching half a GStreamer pipeline which sends a video stream to the computer running python. It then opens up a receiver pipeline using subprocess.Popen which is where the latency is getting measured and printed to stdout. The only option Im using is shell=True right now. It'd be helpful if you could post the code in question, or a minimal, working example. There are a lot of ways that the subprocessing module can be used that can result in deadlocking.
|
# ¿ May 6, 2020 05:08 |
|
2013 lurker rereg posted:Doesn't pycharm pro include datagrip? I was surprised at how much I liked it once I got pro through work--i used SQL all the time in my "analytics" world, but being able to mock the DB easily and validate things was super nice. All of Jetbrains IDEs contain the features of DataGrip, yeah.
|
# ¿ Jul 2, 2020 00:58 |
|
Mirconium posted:I mean, I appreciate Python as much as the next guy, and most of my coding is in Python, but at that point wouldn't it just be easier to go to a fully typed language? I don’t see how it would be easier to learn a new language + ecosystem than to add type annotations to your Python code.
|
# ¿ Oct 17, 2020 02:52 |
|
It also gets easier to use with each release. 3.9 added the ability to type hint collections without importing them from the typing module. So you can do list[int] instead of typing.List[int].
|
# ¿ Oct 17, 2020 03:00 |
|
Rocko Bonaparte posted:Has anybody here used threading.local? I can (and probably will) do some experiments before getting into it, but I'm trying to understand its caveats and gotchas. I am in a situation where I need to pass in some context to a callback. The system that uses that callback is stateless and doesn't need to worry about thread safety. However, the callback I'm using is contextual so I need different state between threads. I'm trying to figure out how I might manage that state. Threading.local creates an object whenever you call it, so you should assign that object to a variable and then store local data as attributes on it. That object will persist as long as you need it, but calling threading.local again will just give you a new object.
|
# ¿ Nov 3, 2020 22:21 |
|
mystes posted:It's part of the python standard now but the normal python interpreter doesn't check it. You can use it with mypy or an ide for type checking. Also used for dataclasses and namedtuples(via typing.NamedTuple). I think attrs also supports using them in class definitions now.
|
# ¿ Jan 28, 2021 20:02 |
|
musicbrainz picard is built using Python and PyQt and it’s no more difficult to install and use than any other software I’ve used
|
# ¿ Apr 10, 2021 20:55 |
|
I think there might be legitimate use cases for a decorator on __init__, but I can’t think of any good reason to use @classmethod there.
|
# ¿ May 24, 2021 22:06 |
|
Gin_Rummy posted:I gotcha. So could I leverage the Python from the actual wave generator/sequencer portion onto a JS GUI, or am I looking at redoing my entire "app?" If you care about the latency between the UI and the actual sound generating parts of the synth then you'll probably want to rewrite the whole thing in JS. The Web Audio API actually has some pretty decent building blocks for audio synthesis, so it probably won't be as tough as you think.
|
# ¿ Sep 2, 2021 00:33 |
|
CarForumPoster posted:Y’all are nuts saying rebuild it in JS. Assuming the compute time for this is 10sec or less, Plotly dash single page app deployed to heroku. Easy peasy, don’t even need to ditch your QT GUI if you do it right, just import the function. Use boto3 to upload to S3. What the gently caress are you talking about? A synthesizer is real-time audio. If you’re talking about seconds then you’re in a completely different universe than the op.
|
# ¿ Sep 2, 2021 04:48 |
|
CarForumPoster posted:Yea I guess I didn’t understand what the requirements of a synthesizer were. Socially appropriate reaction btw. Lol maybe don’t open your post with “y’all are nuts” when making assertions about a domain you have no knowledge of if you’re looking for a polite response.
|
# ¿ Sep 2, 2021 06:00 |
|
I think his python book is good because after trying it twice in high school I gave up on learning to code and talked to girls instead
|
# ¿ Jul 25, 2023 13:54 |
|
BAD AT STUFF posted:I would love to have a place to bitch about Azure Data Factory, so I'm all for a data engineering thread. when i was hired at my current job i was started out on an ADF project and i jumped to something else as soon as the opportunity presented itself
|
# ¿ Dec 28, 2023 23:56 |
|
|
# ¿ May 13, 2024 04:29 |
|
Having not used Flask with PyCharm, I'd check the run configuration. You can at the very least probably set up a more specific binding in there if it isn't already what you want.
|
# ¿ Mar 13, 2024 13:19 |