|
bob dobbs is dead posted:slightly comedy option: make a csv, do a COPY, if your rdbms is chill with that TBH I did think about that. COPY would probably be the fastest way. But it'd only be really useful once, for the bulk load. From then on I'd need to check constraints, do a insert/update etc.
|
# ? Aug 22, 2018 19:17 |
|
|
# ? May 14, 2024 20:24 |
Mark Larson posted:TBH I did think about that. COPY would probably be the fastest way. But it'd only be really useful once, for the bulk load. From then on I'd need to check constraints, do a insert/update etc. You can have really good performance with SQLAlchemy. code:
|
|
# ? Aug 22, 2018 19:20 |
E2: SQLAlchemy should be able to be able to handle inserts with missing keys by default.
cinci zoo sniper fucked around with this message at 19:42 on Aug 22, 2018 |
|
# ? Aug 22, 2018 19:36 |
|
bulk inserts is good as hell on sqlalchemy but still doesnt beat copy, but thats ok cuz it does a lot more than copy rtfm on bulk insert manual in sqlalchemy, it's got all the drat options. and then introspect into the code cuz the manual for sqlalchemy is actually just ok
|
# ? Aug 22, 2018 19:46 |
I mean okay it's not beating metal like COPY sure but if this is the expected performance baseline then Python might not be the right tool for the job.
|
|
# ? Aug 22, 2018 19:50 |
|
SQLAlchemy can handle missing keys automatically as long as it's always the same key that is missing within the same transaction, I think. This isn't particularly pretty but it deals with arbitrary missing keys and replaces them with 0 because of the defaultdict w/ int used.code:
code:
Hollow Talk fucked around with this message at 22:42 on Aug 22, 2018 |
# ? Aug 22, 2018 22:34 |
|
E: nvm, variable assignment in bash isn't as simple as I thought.
Mark Larson fucked around with this message at 02:24 on Aug 23, 2018 |
# ? Aug 23, 2018 02:06 |
|
Which is more Pythonic, collecting and assigning your variables at the top of a function or interleaved and just before you use them? I assume it's in one of the PEPs but my Googling is letting me downPython code:
Python code:
|
# ? Aug 23, 2018 02:18 |
I think you should declare something as close to where it is used as possible.
|
|
# ? Aug 23, 2018 05:27 |
|
I feel like it depends how you're structuring things really. If you have a sequence of steps, where it's do this then this then this, I think it makes sense to do all the setup/config first, so it's not mixed in with the logic and interrupting the flow. You get a nice, readable sequence of actions, especially if you name things well But if you have a bunch of distinct actions, or stuff you want to conceptually separate as pieces of logic to make it easier to follow, it probably makes more sense to keep them self-contained. So you'd assign in the section that's gonna use it, instead of having a bunch of unrelated variables all stuck together at the top of the function It's a judgement call really, and in short functions it probably doesn't matter anyway. I guess my general rule is, do I want to keep all this logic together, or break it up with blank lines? If it's the former then maybe it would be better with the setup pulled out, if it's the latter then maybe I should treat each section like its own, short little function Dunno what's pythonic though
|
# ? Aug 23, 2018 06:21 |
Pythonic code is nice for earning karma on SO, but not much else, in my opinion.
|
|
# ? Aug 23, 2018 07:16 |
|
that sort of stylistic poo poo is for reducing debug surface does it eliminate your responsibility to test the fuckin code? no. does it even reduce the empirical debug surface? usually no. bigger factor is fuckin up a couple dozen times so you run out of ways to gently caress it up and getting the automated tests going and not fuckin up on the automated tests and not fuckin up on the deploy, if theres a deploy
|
# ? Aug 23, 2018 07:44 |
|
Sad Panda posted:Which is more Pythonic, collecting and assigning your variables at the top of a function or interleaved and just before you use them? I assume it's in one of the PEPs but my Googling is letting me down I recommend not concerning yourself with general rules like this. Write code that works and is easy to read; getting distracted by minutiae and absolute standards is a common time-wasting trap. Dominoes fucked around with this message at 08:01 on Aug 23, 2018 |
# ? Aug 23, 2018 07:57 |
bob dobbs is dead posted:that sort of stylistic poo poo is for reducing debug surface Compact code that is easier to reason about != Pythonic code. Latter includes former, but also a load of in my opinion professionally unnecessary philosophy that may or may not align with maintainability and target goals of the codebase. In other words, I think that it is okay to stumble into Pythonic code, but I do reject the notion that you must actively pursue it, as in that it is a deciding factor in what your code ends up being.
|
|
# ? Aug 23, 2018 07:58 |
|
Dominoes posted:I recommend not concerning yourself with general rules like this. Write code that works and is easy to read; getting distracted by minutiae and absolute standards is a common time-wasting trap. best time spent is in exploring for moar bugs
|
# ? Aug 23, 2018 08:05 |
|
I never use pylint in real time because it's super distracting, and I'm too lazy/in a hurry to figure out what I want silenced.
|
# ? Aug 23, 2018 09:31 |
dougdrums posted:I never use pylint in real time because it's super distracting, and I'm too lazy/in a hurry to figure out what I want silenced. I sincerely hope you are the only person who sees your code.
|
|
# ? Aug 23, 2018 11:14 |
|
Your insight to having things installed in certain IDE's working folders (or pathfile in any case) triggered me to check each IDE's settings. I finally found the problem in Anacondas settings. In case anyone ever has the same issue and you think it might be the same thing, what I ended up doing to have the library update is: Go into Anaconda's "Environments" tab and then searching for the library under the "Not installed" filter. Check the radio button of the library and then select "apply". That's it. Now I can access and import the package from any IDE. It's weird that it would prevent that one specific package and not the rest. The rest installed the same way with no issue. Whatever, I'm just glad I can use the package now.
|
# ? Aug 23, 2018 11:51 |
|
cinci zoo sniper posted:I sincerely hope you are the only person who sees your code. ... in real time ... I can be the only person that sees my code, especially with python. Sometimes I just want my computer to do a thing right now, and python is 100% the thing for that. I've slowly started to use python in lieu of grep awk xargs shell script nonsense, it's always an improvement. I find it's tough to get fancy with python's syntax, outside of like comprehensions with multiple binds. Also I don't know perl. E: Seems like my real problem was that I have 'save on focus change' and 'lint on save' both set in my settings. dougdrums fucked around with this message at 14:02 on Aug 23, 2018 |
# ? Aug 23, 2018 13:55 |
|
dougdrums posted:I never use pylint in real time because it's super distracting, and I'm too lazy/in a hurry to figure out what I want silenced.
|
# ? Aug 23, 2018 16:36 |
|
The point of writing pythonic code is the same as the point of PEP8 or the point of the rules in CRA. It's not that any particular rule of PEP8 or particular style of being pythonic is the best way of doing anything. The point is consistency across the industry. If you do things that are not the way most people are used to them then others are going to have a harder time getting up to speed on your code, help you get will be more difficult to come by, tools will help you less, etc... If you're so sure that you won't need any of that then do whatever the f you want. Be careful though, my guess is that the majority of people who think they don't need other people to look at their code or any of the other reasons for consistency are wrong. If you're so hung up on your personal style that you can't just make PEP8 or being pythonic your personal style then you might just have other problems. It's very easy to come up with instances of what is considered pythonic being a less optimal way of doing something, but being optimal in all cases is not the point. Thermopyle fucked around with this message at 17:56 on Aug 24, 2018 |
# ? Aug 24, 2018 17:52 |
My main issue with Pythonic code is two fold - it’s vaguely defined and people are zealous about it. PEP8 or whatever is fine, you chuck it into your toolchain and tick off the boxes on review.
|
|
# ? Aug 24, 2018 18:39 |
|
People are zealous about everything. If you let that put you off from a concept you're going to be missing out on a lot of useful stuff!
|
# ? Aug 24, 2018 20:08 |
|
"Pythonic" is like porn. If it's not pythonic i'll know it when I see it.
|
# ? Aug 24, 2018 20:08 |
Thermopyle posted:People are zealous about everything. If you let that put you off from a concept you're going to be missing out on a lot of useful stuff! I mean from them “perfect is the enemy of good” angle. Thermopyle posted:"Pythonic" is like porn.
|
|
# ? Aug 24, 2018 20:11 |
|
Python is changing dramatically, it always been kinda vague but now in 2018 it's clear that "pythonic" has no meaning whatsoever. (yes, I'm looking at assignment expressions here)
|
# ? Aug 25, 2018 06:41 |
|
I am writing some glue code microservice for a pushbutton deploy thing for our sales people to launch a temporary copy of our product with the customer's company name as the subdomain and attached to a sales-ready db. It is Bootstrap + Flask on Python 3.6-ish, the python portion of the code is maybe 200 lines right now. I can't see this growing much beyond 500 ever. I need to persist the state of this thing somewhere to disk, and retrieve from it; primarily the dns entries, k8s namespaces, clusters ids and aliases, creation time, salesperson/creator, and expiry date. I'm sure I will stuff a couple of other things in there as time goes on. If I were doing this in Go I would use BoltDB (now bbolt). I know Flask meshes very nicely with sqlalchemy and sqlite as a sort of microservice holy-trinity, that seems like gross overkill for storing maybe 5 dicts and a couple of lists worth of data? Am I wrong? I am thinking of going with pickleDB, it has no external dependencies and looks dead-simple. Thoughts/honest brutal feedback?
|
# ? Aug 25, 2018 07:04 |
|
I am trying to figure out how to tell if a given window exists, and can't find any way in Python that works. I have a file named file_1.py, that opens window_1. Only one instance of window_1 is ever open at a time, and it is the main/root window, that cannot be closed without closing down everything else. I have another file named file_2.py, that opens window_2. window_1 has a button on it, that when clicked, opens window_2. That much works. The problem I have is that I want some way to make sure that ONLY one instance of window_2 is ever open at once. This was easy to do in VB.net, but I can't find any way that works in Python. I have found a few pages that claim to do this, but nothing they have works. Like this page: https://stackoverflow.com/questions/17371700/python-tkinter-check-to-see-if-a-window-is-open This method doesn't work, the [open-window2] button still opens multiple instances of window2. Other pages show this method, but it doesn't work either? https://stackoverflow.com/questions/111155/how-do-i-handle-the-window-close-event-in-tkinter If window_2 is created in one function in file_2.py, and the callback function is another function in file_2.py, then,,,,, the IDE won't accept any references in the callback function to window_2, since it is local to another function. And if you declare window_2 as a global in file_2, then it is displayed at the same time that the main window_1 starts up, even though the button to display window_2 was never clicked on... I have also seen pages that claim that you don't destroy windows in python, you just minimize them, iconify them or move them off screen. Is that really the way this matter is usually handled? And even if so, how does that handle the issue of multiple instances of the same window being created?
|
# ? Aug 25, 2018 20:54 |
|
Hadlock posted:I am writing some glue code microservice for a pushbutton deploy thing for our sales people to launch a temporary copy of our product with the customer's company name as the subdomain and attached to a sales-ready db. shelf normal pickle normal files "sqlite competes w/ fopen, not oracle" is true and you're saying it's losing the competition to fopen
|
# ? Aug 25, 2018 21:00 |
|
edmund745 posted:I am trying to figure out how to tell if a given window exists, and can't find any way in Python that works. Create an instance of window 2 and have its GUI be hidden. Then the button just hides/unhides this always-existing window 2.
|
# ? Aug 25, 2018 21:36 |
|
QuarkJets posted:Create an instance of window 2 and have its GUI be hidden. Then the button just hides/unhides this always-existing window 2. God gently caress it all. I did it again.... shortly after I posted, I finally realized from a couple different websites how to do this... I was assuming that you would create a new instance of any child window you wanted, and then destroy() it when you didn't want to see it. Because that's how VC++, VB, Java, etc. does it.... A common problem I am seeing is that a lot of pages are saying how to use some distant, ancient dialect of python. The general ideas might be correct, but the syntax they give is wrong. At least for me? Like this page: https://www.tutorialspoint.com/python/tk_toplevel.htm It says to call .withdraw(), but that doesn't work for me. I had to use wm_withdraw(). And .deiconify() doesn't work either, but wm_deiconify() does. -------- I think my main problem is that I keep trying to look for things that Python simply doesn't have... I looked for a couple hours for a way to check if a given child window was open, and there doesn't seem to be any easy way to do that? The last thing I was trying to do was figure out if there was any way for a Python program to give a list of all the open child windows it had.... and again, there doesn't seem to be any easy way to do that?
|
# ? Aug 25, 2018 22:25 |
|
edmund745 posted:God gently caress it all. I did it again.... shortly after I posted, I finally realized from a couple different websites how to do this... While you could iterate through __globals__ and try to identify the kinds of objects that you want (lol don't do this) what you should do instead is either A) do the thing that I recommended, because then you don't need a list of all of the open child windows because there's only ever 1 child window per parent and it exists so long as its parent exists, the button just hides or reveals it, or B) create your own list of child windows, and every time that the user requests a child window just add it to your list (but I thought you only ever wanted 1? If you want to potentially have more than 1 open then yeah, have the parent keep a list of its children, bing bang boom) To do option A, you'd define a class that controls the main window, and it contains 1 instance of the child window, and when the user hits a button it tells that child window to hide or unhide. That's it. To get extra fancy you wrap a try/except block around the hide/unhide option, to catch cases where the child window has somehow been destroyed and needs to be recreated. No lists of child windows necessary, no lists of anything necessary really, you just have 1 window and 1 child window Note that this hide/unhide idea is something you can do in Java too, it's the thing that makes the most sense when you never want to have more than 1 child window QuarkJets fucked around with this message at 01:41 on Aug 26, 2018 |
# ? Aug 26, 2018 01:34 |
|
I've discovered that I really don't like the asyncio pattern, and it's super-common for any io-bound library. Network programming is inherently non-linear, stop trying to pretend it is (await, threads with blocking IO, etc) So much python meta-magic spent obscuring what's really going on, and in the end you just write poo poo and throw "await" statements when it barfs an error at you. My actual question: Normally, when I have two interacting IO streams, I would put them both on the same event loop, register one with the other (or both through a router) then use calls to initiate an action on the other. However, when one is using loop.add_reader(fd, callback) and the other is parked in an await, how do they interact? Specifically, what happens to the awaiting function when the file-descriptor based one wants something to happen? await read() shouldn't be a problem, but I have no idea what the sequence would be for an await write().
|
# ? Aug 26, 2018 06:30 |
|
I would imagine this is too obscure for anyone to help, but I am having some trouble. I am using Selenium WebDriver with Python, and am trying to click a specific (javascript) link in a tr in a nested table in this old-as-gently caress HTML Here's the HTML: code:
I've been able to find how to capture the contents of a specific <td>, but since the list may be as long as 500 IP blocks, and I do not know the (XXXX) in the delips() so my goal is to find the IP, move over to the final <href>. Note that the number of <td>'s is the same in each line. Any guess on how I would do this?
|
# ? Aug 26, 2018 15:22 |
|
du -hast posted:I would imagine this is too obscure for anyone to help, but I am having some trouble. I'm not sure I 100% follow what you're trying to do, but can you not get what you're after using an xpath like code:
Wallet fucked around with this message at 17:17 on Aug 26, 2018 |
# ? Aug 26, 2018 17:08 |
|
Hadlock posted:I am writing some glue code microservice for a pushbutton deploy thing for our sales people to launch a temporary copy of our product with the customer's company name as the subdomain and attached to a sales-ready db. I like shelve and its in the standard library.
|
# ? Aug 26, 2018 17:12 |
|
QuarkJets posted:...To do option A, you'd define a class that controls the main window, and it contains 1 instance of the child window, and when the user hits a button it tells that child window to hide or unhide. That's it. To get extra fancy you wrap a try/except block around the hide/unhide option, to catch cases where the child window has somehow been destroyed and needs to be recreated. No lists of child windows necessary, no lists of anything necessary really, you just have 1 window and 1 child window... Does it make any difference if you declare the Toplevel widgets inside a class? I was declaring them in the root level of the files. It worked in the first attempt, but when I coped the two .py files into another folder and tried to make something useful out of them, it no longer worked right. Specifically what went wrong was that when the first window opened, it would also open a small phantom window with no attributes set. As long as I left the phantom window alone, the second window would open and close repeatedly. If I closed the phantom window, the second window would also close, and after closing the phantom window (if window-2 was either open or closed at the time) then the second window wouldn't open anymore. ,,,,,,, Also while searching Google for "python try except", I got the Google code challenge! ,,,,,,,,,Or does everybody get these now? I declined to take it. They'd probably just hire me as a contractor, and gently caress that. I aint takin no lousy 100K job where I gotta live in a 300K neighborhood, or face a 4-hour commute.
|
# ? Aug 27, 2018 18:38 |
|
edmund745 posted:Also while searching Google for "python try except", I got the Google code challenge! ,,,,,,,,,Or does everybody get these now? I have googled exactly that previously and didn't get it.
|
# ? Aug 27, 2018 21:37 |
|
CarForumPoster posted:I have googled exactly that previously and didn't get it. I can see the interview now... Google person: "Hello! We're so glad you could meet us today! How is your day going?" me: blah-blah-blah-blah-blah-blah-blah-blah-blah- Google person: "Well! You are certainly talkative for someone who is, uhhh..." (shuffles a three-inch-tall stack of papers) "...you're autistic, aren't you?" me: "oh! , , , , , , , , -um. . . yea! . . ."
|
# ? Aug 27, 2018 23:58 |
|
|
# ? May 14, 2024 20:24 |
|
edmund745 posted:Maybe it's a lifetime average sort of thing? Most of what I do search for is digital electronics (part datasheets) and programming stuff. I've known multiple google engineers and I doubt this would exclude you.
|
# ? Aug 28, 2018 01:28 |