|
Frequent Handies posted:There's a good answer on Stackoverflow using pywin32clipboard and another answer lower down using ctypes that doesn't require additional imports. I used the first answer ages ago to do some clipboard work. I wish it were that simple. My problem is I'm trying to write a (perfectly legitimate) path of exile script that gets item data. Normally when you hover over an item and press ctrl-C, the item's data is copied to your clipboard. Unfortunately that ctrl-c functionality is shared between a few very popular utilities, so I wondered if I could force windows to 'copy' unknown text without pressing the keys. I've used some of those answers in the past, and if I knew what I wanted any of those answers would have worked
|
# ? Mar 19, 2019 03:18 |
|
|
# ? Jun 5, 2024 07:16 |
|
There's probably some glue code module that will allow you to access a .net function to accomplish your goal either directly or via powershell
|
# ? Mar 19, 2019 03:48 |
|
This is a bit Python but probably more Windows. I'll ask here and move to the Windows threat if I get nothing. I've written some Python to use PyAutoGUI/Pillow/OpenCV to do some image finding and clicking. I run that on my server as my main computer is a Mac and PyAutoGUI just goes funny with a Retina display. I use Windows Remote Desktop to remote in and when the session is open it goes on its merry way. The problem is, if I close Remote Desktop it stops working. I can leave a normal Selenium script running, and it will happily scrape without the Remote Desktop window being open, but Pillow doesn't. The relevant part of the error that it throws is... Python code:
|
# ? Mar 19, 2019 07:45 |
|
In a Python 3.7 script, I’m using Argparse to deal with command line args before passing them to an API. I have 1 positional argument that is the method the API should invoke, and the rest are arguments to that method. Unfortunately since the variety of methods the API accepts don’t necessarily have many args in common, the number of .add_argument() calls I’m making is going way up- nothing wrong with that in itself but it’s disorganized and in that state there’s nothing stopping one from passing a method to the API with args it doesn’t use. Right offhand I see two ways to mitigate/clean this up: 1, parse the args in two passes, first getting the method and any universal args, then using the method name to create an argument parser with just the args specific to that method ignoring the rest. 2, create some kind of data structure that maps argument to the methods it pertains to, and also the info that needs to go into add_argument(), allowing me to get the method from sys.argv[1] and then iterate over my data structure calling add_argument() and filling in the data for those records that match up with the method #1 seems to be what Python intends, by way of sub parsers, but then you’d still have the same argument being handled in multiple places, and that seems less than optimal. I feel like 2# is the most thorough solution but also kind of convoluted the yeti fucked around with this message at 17:40 on Mar 19, 2019 |
# ? Mar 19, 2019 17:15 |
|
the yeti posted:In a Python 3.7 script, I’m using Argparse to deal with command line args before passing them to an API. I have 1 positional argument that is the method the API should invoke, and the rest are arguments to that method. Have you tried using subparser? I think it will help. It lets you create a different set of arguments for different values of a positional command: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_subparsers
|
# ? Mar 19, 2019 17:44 |
|
Sad Panda posted:I'm assuming the problem is that Windows will still run calculations but won't generate an output if RDP is not on. Can anyone think of a creative solution? Is there a Python way to virtualise a monitor? Is there a way to make Windows not do this? Either way try pyvirtualdisplay, I'm pretty sure it was written for this purpose. Joke option get another monitor and duplicate displays then use a webcam pointed at it to capture input.
|
# ? Mar 19, 2019 17:54 |
|
Spaz Medicine posted:Have you tried using subparser? I think it will help. It lets you create a different set of arguments for different values of a positional command: I was prob editing while you replied quote:#1 seems to be what Python intends, by way of sub parsers, but then you’d still have the same argument being handled in multiple places, and that seems less than optimal. I like that functionality a lot to be sure! I’m just not sure how to handle say, if 8 of 25 methods have a ‘—start_date’ arg —that’s 8 times it’s repeated.
|
# ? Mar 19, 2019 18:06 |
|
This might be an opportunity to switch to a more modern argument parsing library, such as the popular click, or my personal favorite, docopt. They each have their own solution to this kind of thing. Check them out and see if they appeal. I would hate to use argparse for anything complicated.
|
# ? Mar 19, 2019 18:16 |
|
the yeti posted:I was prob editing while you replied You can create some argument parser which contains the repeated arguments (make sure to pass add_help=False), and the use the parents argument of the add_parser method to automatically include them. It can still get pretty ugly, but AFAIK that's the best way to handle it with Argparse.
|
# ? Mar 19, 2019 18:16 |
|
SurgicalOntologist posted:This might be an opportunity to switch to a more modern argument parsing library, such as the popular click, or my personal favorite, docopt. They each have their own solution to this kind of thing. Check them out and see if they appeal. I would hate to use argparse for anything complicated. You know somehow it never occurred to me to investigate third party libraries for this, I’ll take a look!
|
# ? Mar 19, 2019 19:56 |
|
Sad Panda posted:This is a bit Python but probably more Windows. I'll ask here and move to the Windows threat if I get nothing. I'm a little fuzzy on the details here, but IIRC, you can do something like running Windows in a VM on your server. Something about how you can configure that makes Windows think you're connected locally, but actually you're connected with VNC. Maybe that bit of info will help you figure it out...
|
# ? Mar 19, 2019 20:01 |
Seconding the click suggestion for the cli arg thing.
|
|
# ? Mar 19, 2019 21:11 |
|
Meyers-Briggs Testicle posted:I'm a bit confused at this setup. You want to capture your macs screen but instead rdp from a windows server? And you're running imagegrab on the rdp window of the mac? Poorly explained. I'll try again. I've got some Python code. It uses Pillow, OpenCV and PyAutoGUI to do some clicking based on images. At the moment, it is running on an ESXi Windows 10 server that I connect to from a Macbook using Microsoft Remote Desktop. If the Remote Desktop window is open (on my Mac) then it plays wonderfully. If the Remote Desktop window is closed, it fails and throws the OSError that I posted earlier. I assume there is some check that is run that tells Windows that there's not really a display that it is outputting to. I had a quick look at PyVirtualDispaly and it seems that it is *nix only. Sad Panda fucked around with this message at 23:09 on Mar 19, 2019 |
# ? Mar 19, 2019 22:44 |
|
Thanks, goons! I need to try Click out sometime, but I don't think I wrote this app in a way that would make it easy to integrate, compared to docopt where I (think I) just need to write a helpfile and generate a parser I can drop in in place of the one I have.
|
# ? Mar 19, 2019 23:33 |
|
Sad Panda posted:Poorly explained. I'll try again. try mss for capturing images, from my quick test it doesn't care if you have monitors plugged in or if you specify a screencapture outside what actually exists https://python-mss.readthedocs.io/examples.html e: you still use the same processing code, those examples are pretty good at showing you how to transfer your code over
|
# ? Mar 20, 2019 01:19 |
|
Sad Panda posted:Poorly explained. I'll try again. It's been awhile since I've had to care, but if I'm remembering right, when you drop your remote desktop session, that desktop stops existing and all the OS resources that were allocated for it get freed. A desktop is a thing in Window's object model and participates in a bunch of stuff for both security and resources. Example: the administrator password prompt runs on its own desktop. You can't send or receive messages from windows on it from the default interactive desktop, they don't share clipboards, etc... I think video memory will also be deallocated, so probably your immediate problem is that there isn't any buffer to screen grab from anymore. When you log back in, memory gets allocated again and all windows get told to repaint themselves.
|
# ? Mar 20, 2019 05:53 |
|
Meyers-Briggs Testicle posted:try mss for capturing images, from my quick test it doesn't care if you have monitors plugged in or if you specify a screencapture outside what actually exists That is a good point that I hadn't thought of. The scraping script that I have that works takes screenshots of things like error messages and does that just wonderfully when the Remote Desktop window is closed... so if I work out how to use PyAutoGUI/OpenCV with an image taken by MSS instead of captured by Pillow it might work. edit - Nope. Tried that. MSS takes a shot but it is 1920x1080 of black. Selenium itself is able to take shots however. Sad Panda fucked around with this message at 22:28 on Mar 20, 2019 |
# ? Mar 20, 2019 22:00 |
|
I'm writing a CRUD app and need to decide on my data storage format. I've started with XML but both native xml and lxml are really bad to work with. I've read the XPATH docs for lxml a hundred times and still cannot search the tree for a specific node. Should I just use JSON instead? YAML? I've used Python's json library before and IIRC converting to a dictionary was really easy, and once you have that working with the data is really easy. It's frustrating because the data I'm working with formats well into XML. But my productivity is in the toilet fighting with lxml. Is there a point where it clicks, if I keep at it?
|
# ? Mar 22, 2019 00:14 |
|
I don't think anyone has used XML in a greenfield project in years, for forward compatibility you should look at using json. XML has some advantages (it's fully extensible) but most users don't need that level of complexity. With JSON you're all wired up by default to work with pretty much any RESTful API on the planet out of the box, batteries included. I haven't seen XML on any greenfield project built after 2012 or so. Parsing JSON didn't really click with me until I read the manual for (tangentally related) jq: https://stedolan.github.io/jq/manual/#Basicfilters There is also yq (yaml) documentation: http://mikefarah.github.io/yq/ Parsing XML was a real struggle for me, as was json, but I was re(re-re-re)-reading the jq docs and suddenly json parsing just clicked for me. Is there any reason why you can't store the data in a db using an ORM. Unless you need to export the doc for external users? Then you can just export to JSON or whatever crazy XML file you need to email to your peers. Hadlock fucked around with this message at 01:08 on Mar 22, 2019 |
# ? Mar 22, 2019 01:03 |
I’m not quite sure what your troubles with XML are, guys, but then again half of my work is built upon interacting with data providers that send us giant XMLs so I just had to accommodate that resort. Either way, if you need XML on a greenfield project you will know that you needed it - I would just make piles of poo poo in JSON and then rewrite into something else if necessary.
|
|
# ? Mar 22, 2019 07:07 |
|
Just speaking for myself I did, and sometimes still do get tripped up by the extra complexities of XML as a tree of elements when 99% of the time I’m just de/serializing a list of objects and their attributes
|
# ? Mar 22, 2019 14:08 |
|
mr_package posted:I'm writing a CRUD app and need to decide on my data storage format. I've started with XML but both native xml and lxml are really bad to work with. I've read the XPATH docs for lxml a hundred times and still cannot search the tree for a specific node. Should I just use JSON instead? YAML? I've used Python's json library before and IIRC converting to a dictionary was really easy, and once you have that working with the data is really easy. Why just those options? Is sqlite not needs-suiting?
|
# ? Mar 22, 2019 15:31 |
|
https://repl.it/site/blog/gfx?ref=updates PyGame in the browser. It's hilarious how they do this. They're running X Windows over VNC through websockets right into your browser.
|
# ? Mar 22, 2019 16:53 |
|
I was kind of assuming once the tree was parsed I could reference specific nodes in the ElementTree by id or whatever and then modify as needed. I wanted to use the ElementTree as the main data object and avoid converting into Python objects. The problem I'm finding is I keep needing to loop over the tree, this seems so inefficient. Maybe it's ok? But with JSON I can build a nested dictionary that reads/writes easily and is super easy to work with. Here's simple XML example: code:
code:
Note: wrote both these by hand, may be small mistake, but hopefully gets the point of what I'm working with across. Thermopyle posted:Why just those options?
|
# ? Mar 22, 2019 17:57 |
mr_package posted:I was kind of assuming once the tree was parsed I could reference specific nodes in the ElementTree by id or whatever and then modify as needed. I wanted to use the ElementTree as the main data object and avoid converting into Python objects. The problem I'm finding is I keep needing to loop over the tree, this seems so inefficient. Maybe it's ok? But with JSON I can build a nested dictionary that reads/writes easily and is super easy to work with. code:
cinci zoo sniper fucked around with this message at 19:16 on Mar 22, 2019 |
|
# ? Mar 22, 2019 19:12 |
|
code:
|
# ? Mar 22, 2019 19:16 |
MariaDB and I think postgres let you easily implement versioning on tables. I personally go to json, SQL and toml for most of my needs.
|
|
# ? Mar 22, 2019 19:17 |
While you can have temporal views on tables in PostgreSQL, which I would highly recommend over MariaDB in general, that is a really overkill solution for most problems, imo.
|
|
# ? Mar 22, 2019 19:20 |
|
Thanks this is actually helping a lot. e.g. once I have the node matching id attribute I can do a relative search using "./strings/*[contains(@xml:lang,'en-US')]" to get just the specific string element. Also one of the mistakes I made was reading *some xpath operation* returned a list and assuming it was a list of text; the searches here are returning lists of Elements which is obviously more useful. JSON still looks like the better/simpler way for this but I'm still on the fence. Since I'll still need to read/write some XML as part of this project I might as well try and get good at it, rather than adding another file type just because it's easier. With a little practice xpath doesn't seem so horrible (no worse than regex or SQL right?) but it helps so much to have a working query to start from. Thanks again!
|
# ? Mar 22, 2019 23:49 |
|
Bundy posted:MariaDB and I think postgres let you easily implement versioning on tables. I personally go to json, SQL and toml for most of my needs. If it's a simple CRUD app and you don't need truly high concurrency, and you need a DB, use sqlite. It's a single file, which can of course be versioned. There's also sqldiff which lets you diff two sqlite databases. If you don't need an RDBMS, then just store your poo poo in a json file. Even if you don't need a relational DB, use sqlite. There are times when it's even faster than writing to the filesystem.
|
# ? Mar 22, 2019 23:50 |
mr_package posted:Thanks this is actually helping a lot. e.g. once I have the node matching id attribute I can do a relative search using "./strings/*[contains(@xml:lang,'en-US')]" to get just the specific string element. Also one of the mistakes I made was reading *some xpath operation* returned a list and assuming it was a list of text; the searches here are returning lists of Elements which is obviously more useful. Imo SQL>XPath>RegExp, but guess how those rank in terms of my experience? In all fairness though, SQL is rather straightforward, provided that you are working with PostgreSQL 10+, MySQL 8, recent-ish MSSQL or close derivatives of thereof. The real hairy shitshow is MySQL 5, because you need to reinvent windows functions and whatnot on the go.
|
|
# ? Mar 23, 2019 00:44 |
Although MySQL 8 still has lmao-tier poo poo, like preferred char->int conversion method being Select charfield+0 as intfield from foo
|
|
# ? Mar 23, 2019 00:48 |
|
I've been using PyCharm as an IDE but the sluggishness of it is starting to wear on me. If I wanted something just as fully featured but faster should I be going with VS code or Atom?
|
# ? Mar 24, 2019 08:55 |
Boris Galerkin posted:I've been using PyCharm as an IDE but the sluggishness of it is starting to wear on me. If I wanted something just as fully featured but faster should I be going with VS code or Atom? There literally is nothing as fully featured as PyCharm, it’s undisputedly the best-in-class universal Python IDE. Many people, however, don’t need all the batteries that come included with it, and in that case I’d heavily recommend VSCode or ST3 over Atom - I don’t think there is an actual irl use case where Atom should be recommended, especially over VSCode - Python or otherwise. Just for the sake of curiosity, what do you find sluggish about PyCharm?
|
|
# ? Mar 24, 2019 09:49 |
|
I'm not sure if it's a PyCharm thing or a Java thing, but every time I use PyCharm on my laptop (MBP) when it's unplugged my whole computer just feels like it grinds to a halt and the entire system is slower in general. I don't have any measurements to back any of this up of course but force quitting PyCharm and then using my laptop to do other unrelated things feels snappier without PyCharm running in the background. Then there's also the feeling that PyCharm is just a mess of features cobbled together and getting help/information about something is seemingly impossible for me. Don't get me wrong it's a great tool--when it works without issues. But right now for example, I'm trying to type up some documentation in an rst file. rst files require 3 space indentations, which I've configured in a global .editorconfig file. I can see that PyCharm is reading this file correctly because the bottom status bar tells me that my Makefile has tabs and a regular bash script has 2 spaces, both of which are also configured in the same .editorconfig file. For whatever unknown reason though, it doesn't want to apply my 3 space rule to any of the rst files I'm editing. For yet another unknown reason, another instance of PyCharm that I've opened a different project in does correctly apply my 3 space rule to the rst files in that window. So I have two instances of PyCharm running side by side, both reading the same exact .editorconfig file, yet only one of them is working properly. Why? Who knows. But it's small things like this (in addition to the perceived slowness) that just keep coming up all too often and I'd just rather have something that "just works."
|
# ? Mar 24, 2019 12:28 |
|
Boris Galerkin posted:I've been using PyCharm as an IDE but the sluggishness of it is starting to wear on me. If I wanted something just as fully featured but faster should I be going with VS code or Atom? VScode has sort of replaced Atom as best open source code editor. Sublime is another good option but I haven't heard anything about it in probably a year. I don't know if I would call them fully fledged IDE though. VScode is my go to code editor though. The last time I saw anyone using Atom in the wild was 2017. Edit: mildly interesting article from visual studio magazine (visual studio, not VScode): https://visualstudiomagazine.com/blogs/data-driver/2018/12/2018-vs-code.aspx Hadlock fucked around with this message at 13:50 on Mar 24, 2019 |
# ? Mar 24, 2019 13:33 |
That indentation thing sounds really weird yeah, unless there is some project-specific settings fuckery. Although I want to point out that iirc ReST spec does not actually ask for 3 space indentation - it should also work with tab indentation or any number of spaces that is >2, so long that it's consistently applied.
|
|
# ? Mar 24, 2019 13:37 |
|
IntelliJ IDEs have known performance issues with Retina displays and I've been unable to use them as my daily driver because of it. Noticable lag moving the cursor around or typing, and even worse lag resizing or using GUI elements.
|
# ? Mar 24, 2019 13:46 |
necrotic posted:IntelliJ IDEs have known performance issues with Retina displays and I've been unable to use them as my daily driver because of it. Noticable lag moving the cursor around or typing, and even worse lag resizing or using GUI elements. This could explain plenty about sluggishness, I've yet to use any of IntelliJ stuff on a Mac - I only have to deal with the mess that Windows HiDPI scaling is for various GUI frameworks. Hadlock posted:VScode has sort of replaced Atom as best open source code editor. Sublime is another good option but I haven't heard anything about it in probably a year. I don't know if I would call them fully fledged IDE though. VScode is my go to code editor though. The last time I saw anyone using Atom in the wild was 2017. Thankfully it would take a mismanagement to eclipse Ballmer's to kill Visual Studio proper (I'd off myself if I had to go back to RStudio for doing R work).
|
|
# ? Mar 24, 2019 18:11 |
|
|
# ? Jun 5, 2024 07:16 |
|
I will spend any amount of money on computer hardware to continue using Jetbrains IDEs. (though, I use VS Code effectively for a lot of stuff that is just a few hundred lines/one-off/throwaway) I will note, that I'm using PyCharm at this very moment with VS Code also open on another monitor and they're basically indistinguishable from each other performance-wise (once they're running. PyCharm takes ages to load since one of the updates in the past 6 months) on my i5-4670k from 2013, 32GB of RAM, and Windows 10. Thermopyle fucked around with this message at 18:14 on Mar 24, 2019 |
# ? Mar 24, 2019 18:12 |