|
huh interesting. even more interesting that the sqlalchemy docs don't even mention this: https://docs.sqlalchemy.org/en/14/orm/mapping_columns.html So if you want your column name to be "id," this is preferred? Python code:
|
# ? Mar 10, 2022 00:52 |
|
|
# ? May 14, 2024 19:39 |
|
teen phone cutie posted:huh interesting. even more interesting that the sqlalchemy docs don't even mention this: Yeah, in general you want to avoid reusing any already used variable names from the standard library. IDEs should warn you about this if you're using one, so naming something list, id, type, etc should all give a warning because you're overwriting it. In theory you can do it, but it can cause weird behavior or straight up bigger problems so it's a good idea to avoid it whenever possible. It's kind of wild that they just don't mention it in their docs, but welp.
|
# ? Mar 10, 2022 01:34 |
|
It's probably fine on a class, if not a bit of a code smell - PyCharm correctly flags a global variable shadowing the builtin, but doesn't care at all in a class. I think the idea being that you'd always access it as object.id instead of just plain id.
|
# ? Mar 10, 2022 02:06 |
|
It's perfectly normal (even documented as such) in Django models to just name the field `id`, for what its worth. It also automatically adds a field called id to any model that doesn't otherwise specify a pkey.
The March Hare fucked around with this message at 07:22 on Mar 10, 2022 |
# ? Mar 10, 2022 07:20 |
|
Protocol7 posted:It's probably fine on a class, if not a bit of a code smell - PyCharm correctly flags a global variable shadowing the builtin, but doesn't care at all in a class. Oh, hey that's a good point actually, I hadn't considered that.
|
# ? Mar 10, 2022 08:15 |
|
VSCode doesn't flag using builtins as variable names. I have to catch it myself based on different syntax highlighting. The reason I don't suffix _id to the FK fields is because I'm using a backref on the parent tables with the name <field>_id, which sticks that field on the child table. Now, taking another look at the SQLA docs, I'm not even sure why I'm doing that. Realistically, I don't think I'm ever gonna be querying backwards, from a child to its parent; I'll only be determining children from the parent.
|
# ? Mar 10, 2022 14:21 |
|
I'm trying to piece together a script to automatically adjust screen brightness settings based on a user's location. So far I have it working with hardcoded lat/long values, but I'd like the user to input a city / state and it accurately determines the intended location (lat/long is required for sunset module) or at least offers a set of possible matching cities before converting to coordinates. Is there an API or package that can do this? I'm thinking Google Maps could probably handle it but maybe there's a better approach.
Sleepy Robot fucked around with this message at 23:39 on Mar 10, 2022 |
# ? Mar 10, 2022 22:35 |
|
Sleepy Robot posted:I'm trying to piece together a script to automatically adjust screen brightness settings based on a user's location. So far I have it working with hardcoded lat/long values, but I'd like the user to input a city / state and it accurately determines the intended location (lat/long is required for sunset module) or at least offers a set of possible matching cities before converting to coordinates. Is there an API or package that can do this? I'm thinking Google Maps could probably handle it but maybe there's a better approach. https://openweathermap.org/price looks like it has a free tier, which depending on how much calls you're making should be fine. Ninja Edit: https://openweathermap.org/api/geocoding-api it has a geocoding api, it's not just for weather. Ninja Edit 2: https://geopy.readthedocs.io/en/stable/ It looks like there's a python library for interacting with geocoding apis too, which might save you a little work.
|
# ? Mar 11, 2022 01:26 |
|
Geodjango can be a world of suffering sometimes. Trying to install an app on a Centos 7 machine, and dear god are the dependencies killing me. For various reasons involving people in suits who dont understand technology I cant dockerize it, and this archaic shitful distribution lacks pretty much everything. Worst off, the part that I need most, GEOS, is just a recursive wall of suffering in terms of C/C++ dependencies. Hell, even the version of CMAKE is too old. Boss better like this poo poo or I'll start flipping cop cars and going berk.
|
# ? Mar 11, 2022 03:01 |
|
Can you use singularity? IIRC it's part of the EPEL and should be much easier to sell cybersecurity people on than Docker. Singularity is unlike Docker in that it's made for environments where users don't have any special permissions outside of their home areas, e.g. multi-user HPC systems where a group may get very mad if you let some other group have access to their data. You can create a singularity container from a docker container, or it's very easy to write your own singularity build script that uses a docker container as its base image.
|
# ? Mar 11, 2022 09:19 |
|
I want my users to have the option to create a job by the following process: Export NAV job card to Excel > Send exported workbook from Excel to jobcreate@company.com > Automatically import that job card with pandas.read_excel() to the database I can't find anything relevant on actually receiving mail with Flask-Mail and doing something with attachments. Anyone have any idea?
|
# ? Mar 11, 2022 17:05 |
|
Flask-mail's documentation seems to imply its use is only for sending emails, you'd probably have to parse the email some other way. Fortunately the email builtin package looks like it might handle that. https://docs.python.org/3/library/email.examples.html
|
# ? Mar 11, 2022 17:16 |
|
I suppose that's something I'll have to look at in the future, thank you As of now, the base plan is to have the ability to upload that saved .XLSB file on a page and parse it that way. I took care of the ability to read in a job card today, pandas makes that loving easy once you're familiar with the structure of the exported data.
|
# ? Mar 11, 2022 18:45 |
|
I'm trying to rewrite this old work script (it wasn't working because it was written for an earlier version of Python) and want to complain about this:code:
|
# ? Mar 11, 2022 21:16 |
|
Ytlaya posted:I'm trying to rewrite this old work script (it wasn't working because it was written for an earlier version of Python) and want to complain about this: This is academics writing code.
|
# ? Mar 11, 2022 21:24 |
|
Now I’m curious. I would solve that problem by turning the lists into sets and subtracting the second from the first. Is there a way that’s more simple than that?
|
# ? Mar 11, 2022 21:56 |
|
If you have unique ids that would scream set difference to me, which is what you said yeah edit: there's of course like 2 dozen other things that are wrong with it, but, i guess one of the nice things about python is that you can fall back to list index nonsense if you didnt bother to read any of the documentation 12 rats tied together fucked around with this message at 22:03 on Mar 11, 2022 |
# ? Mar 11, 2022 22:00 |
|
12 rats tied together posted:If you have unique ids that would scream set difference to me, which is what you said yeah Agreed on set difference - sets are great for when you're trying to do unique IDs of things, and you can use them pretty lazily to just dedupe a list. (as long as comparison/etc is possible between the list objects, etc etc. There are edge cases.) code:
code:
|
# ? Mar 11, 2022 22:20 |
|
given that the only (presented) desire is to produce the resulting set, I'd probably use a set comprehension which reduces it to one line:Python code:
Python code:
- only if the items are not equal, - and the GeneList item is smaller than(?) the Names item - save it and return it What possible application could this have? The first time we hit an item pair that fails the equality test we start either only walking GeneList or only walking Names, it seems like that goes out of sync instantly and then does absolutely nothing until it catches back up? why not just always walk both lists?
|
# ? Mar 11, 2022 23:20 |
|
If those are strings I think it means lexically-previous not shorter, like “a” < “b” == True and “b” < “a” == False
|
# ? Mar 12, 2022 02:13 |
|
Question: How to replace all regex reserved characters with . in a list of strings? For example replace ( with . Goal: Filter a DataFrame to a list of matching company names, even when regex characters appear in the names. Reproduce Error: Python code:
I thought this would work: code:
EDIT: Annnnd 10 seconds after posting I thought of just escaping them which I should've been doing to begin with. I am dumb. Solution: [re.escape(name) for name in good_names] CarForumPoster fucked around with this message at 15:48 on Mar 16, 2022 |
# ? Mar 16, 2022 15:43 |
|
When you realize that you can use regex to extract information that's always been a pain in the rear end to parse from a shittily-configured string that serves as some sort of inscrutable machine-friendly code. Like dealing with 53.125X63.X.,35,STD,1/2" FL,W,EQUAL,G/G 5/16,CL,NO GRID,SS PACKAGE,DBL,SWEEP,1816K-BOXED,LSILL sucks rear end. But I can at least use regex to find things like the glass strength, colors, etc. since they're all predictable values.
|
# ? Mar 16, 2022 17:24 |
|
stupid python question: we have a script where we want to add retry limits on errors for a particular action. there's a bunch of different exceptions that could be causing an error at this point. I'm looking for a way to increment the retry count on any exception, then continue to handle specific exceptions differently, rather than having to add the retry count increment to each specific except statement original code:
code:
|
# ? Mar 16, 2022 18:08 |
|
this might be ugly or have weird edge cases (something to do with modules and period-separated namespaced exceptions? cant remember, might be confusing it with something else), but i'd probably either use isinstance(e, SomeException) (if you want to catch subclasses as well) or type(e).__name__ == 'SomeException' if you need to be precise exceptions: code:
code:
code:
boofhead fucked around with this message at 19:14 on Mar 16, 2022 |
# ? Mar 16, 2022 19:04 |
|
CarForumPoster posted:Goal: Filter a DataFrame to a list of matching company names, even when regex characters appear in the names. Escaping the list and building the regexp at runtime is code smell at best, and exploitable at worst.
|
# ? Mar 16, 2022 19:15 |
|
ExcessBLarg! posted:Why not make a set of matching company names and test for membership? Its old code tech debt for an infrequent issue. This bit is for a web scraper that runs once a day on a win10 machine, so refactoring = time I could be poo poo posting.
|
# ? Mar 16, 2022 19:24 |
|
boofhead posted:this might be ugly or have weird edge cases (something to do with modules and period-separated namespaced exceptions? cant remember, might be confusing it with something else), but i'd probably either use isinstance(e, SomeException) (if you want to catch subclasses as well) or type(e).__name__ == 'SomeException' if you need to be precise this will work great, thank you
|
# ? Mar 16, 2022 20:11 |
|
I...did it. After a full day of trying to figure out just how the gently caress I wanted to handle it, two days in the REPL testing concepts and in actual coding and I can parse both CSV and XML data from our primary window supplier. The relevant class determines the file type, extracts relevant data, and places it in a nice dictionary for the actual calculators to do the work. I'm kinda glad I decided to refactor from the ground up. I don't think I'm even going to touch the Flask end of things until I have all my back-end math classes in place. Somehow loving around with regex and pandas is less painful than HTML and CSS to make things look loving nice. EDIT: "Success" in this case is that aside from the two expected differences between the CSV and XML output files, they are otherwise identical. The only things that should be and indeed are different are the path to the file and the actual data (in one case, the dataframe containing the CSV data and in the other the XML text itself). D34THROW fucked around with this message at 20:45 on Mar 16, 2022 |
# ? Mar 16, 2022 20:42 |
|
Wait so I read somewhere that Troika Games coded their titles in Python? So "Vampire: The Masquerade - Bloodlines", "Arcanum", and "Temple of Elemental Evil" were all coded in Python and not like some form of C like almost every other game?
|
# ? Mar 16, 2022 20:57 |
|
iirc Eve Online is coded in some hosed up 1.X fork of Python
|
# ? Mar 17, 2022 02:01 |
|
punk rebel ecks posted:Wait so I read somewhere that Troika Games coded their titles in Python? I would bet they're using Python for game logic, nobody is insane enough to do a 3d engine in Python. Games tend to have a more comfortable language for logic, whether something custom like UnrealScript in unreal engine 1-3 or a more widely used language like Lua. EVE online used stackless python for their game logic. I don't know if they still do, but I wouldn't be surprised if it's some horrifying variant.
|
# ? Mar 17, 2022 02:24 |
Twerk from Home posted:I would bet they're using Python for game logic, nobody is insane enough to do a 3d engine in Python. For some reason I got the mental image of Tom Scott going AUTOHOTKEY
|
|
# ? Mar 17, 2022 11:46 |
|
Why would Python be bad for building a 3D game engine?
|
# ? Mar 17, 2022 17:16 |
|
Developing a whole engine in Python could be difficult because it's an interpreted language rather than compiled. For the scripting, it's one thing. A whole-rear end engine is another. Given, once you run it, it does compile to CPython and get cached, but it still has to get interpreted and poo poo. It's also hella slow compared to lower-level languages. This Quora topic had some good answers.
|
# ? Mar 17, 2022 17:51 |
|
It's a fine language to use for a 3d engine but like most other things that are python but need to be performant, you have to put a lot of work into having as little of it execute in the interpreter as possible. Since Python is simultaneously so slow and so popular, a lot of stuff exists for this that you generally don't have to think about. For example, you can write Panda3D in python but most of your hot path runs as C++ or GLSL/Cg anyway.
|
# ? Mar 17, 2022 18:00 |
|
D34THROW posted:Developing a whole engine in Python could be difficult because it's an interpreted language rather than compiled. For the scripting, it's one thing. A whole-rear end engine is another. I’ve just started learning Java and was wondering why I have to do things like put “int” in front of a number to state it’s a number rather than simply not putting quotes around it. Or why I need curly brackets everywhere. I thought it was just obtuse but I realize after reading that Quora post it’s likely to increase speed as the language has to do “less checks”.
|
# ? Mar 17, 2022 18:18 |
|
QuarkJets posted:iirc Eve Online is coded in some hosed up 1.X fork of Python the backend is IIRC, I would be surprised if the frontend was or still is after all these years, given that that's a relatively easy overhaul (emphasis on "relative")
|
# ? Mar 17, 2022 18:40 |
|
IMHO the best resource for learning more about that concept in <15 minutes is to read the section on the stack vs the heap in the rust book's ownership chapter. After that you can read the python documentation on memory management for some insight into at least one dimension of Python's slowness.
|
# ? Mar 17, 2022 18:44 |
|
Ever have those moments when you look back at your old code, or how you used to do things, and have a look on your face? Last time I did this dance, I input a shitton of data manually into the DB from flask shell. Now, I'm putting everything in an Excel file, sheet names matching the class names and column names matching the field names for the ORM interfaces, and I'm just gonna use dataframes to read it all into the DB. That way, when I inevitably gently caress something up and have to DROP TABLE *, I don't have to spend an hour retyping poo poo.
|
# ? Mar 17, 2022 19:14 |
|
|
# ? May 14, 2024 19:39 |
|
punk rebel ecks posted:I’ve just started learning Java and was wondering why I have to do things like put “int” in front of a number to state it’s a number rather than simply not putting quotes around it. Or why I need curly brackets everywhere. fwiw compiled languages like C++ later added an "auto" variable type that automatically assigns some other type that can be inferred during compilation, and templates exist specifically because it's dumb to have to redefine a function for every valid type that it can use.
|
# ? Mar 17, 2022 20:55 |