|
Spyder's the only editor I've found that lets you easily run individual snippets of code - something I find remarkable in conjunction with its low popularity.
|
# ? Mar 2, 2019 00:39 |
|
|
# ? Jun 5, 2024 05:13 |
|
Option + Shift + E in PyCharm. Use it all the time.
|
# ? Mar 2, 2019 00:56 |
|
vikingstrike posted:Option + Shift + E in PyCharm. Use it all the time.
|
# ? Mar 2, 2019 01:34 |
Dominoes posted:Spyder's the only editor I've found that lets you easily run individual snippets of code - something I find remarkable in conjunction with its low popularity. I run interactive console in Pycharm and just code cells there, you can delineate them with #%% in code.
|
|
# ? Mar 2, 2019 08:38 |
|
Dominoes posted:Spyder's the only editor I've found that lets you easily run individual snippets of code - something I find remarkable in conjunction with its low popularity. I...can't say I've ever really wanted to do this on some sort of priority level wherein I'd even think about adding it to a list of things my IDE needs to do. Now it's got me wondering what the difference in our workflows is that makes this A Thing.
|
# ? Mar 2, 2019 19:56 |
Am I the only one that never executes anything from my ide other than linting?
|
|
# ? Mar 2, 2019 21: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 |
|
Bundy posted:Am I the only one that never executes anything from my ide other than linting? Probably not, but if your ide supports it then you may as well use it cause it's useful
|
# ? Mar 2, 2019 21:43 |
|
Thermopyle posted:I...can't say I've ever really wanted to do this on some sort of priority level wherein I'd even think about adding it to a list of things my IDE needs to do. Now it's got me wondering what the difference in our workflows is that makes this A Thing. Dominoes fucked around with this message at 22:20 on Mar 2, 2019 |
# ? Mar 2, 2019 22:17 |
QuarkJets posted:Probably not, but if your ide supports it then you may as well use it cause it's useful Eh, I've always got a term window with tabs active in my venv anyway and my users are unlikely to be running my app from their ide. I use pycharm atm and I always find the execution area to be odd. One thing I do miss from Spyder is the ipython integration, that is very tight and I did use it a lot there, but adapted to the terminal window approach after making the switch to pycharm for all the other good ide stuff it has over Spyder.
|
|
# ? Mar 2, 2019 23:47 |
|
I spend a lot of time writing one-off scripts for work and idle is still great at that. Cmd up a virtualenv, write a hundred lines of code and convert to exe for someone else to deal with. Maybe you can do that faster in another ide but idle is 'fast enough'. Vscode owns otherwise, though
|
# ? Mar 3, 2019 02:55 |
|
Bundy posted:Am I the only one that never executes anything from my ide other than linting? Occasionally I'll use the terminal in vscode to double check something, or if it happens to be the only terminal visible, run manage.py but it's more of a convenience thing I will, on great occasion, bust out python comand like to sanity check syntax, or troubleshoot syntax, like a reporting/SQL jockey, but max once a month I could never use an IDE without a linter, it's especially painful to load someone else's code with a bunch of warnings + trailing whitespace garbage sprinkled everywhere.
|
# ? Mar 3, 2019 08:27 |
|
What can make importlib get stuck in a loop? I'm rather confused. I've got a piece of code that uses two threads. One is for Flask and it has a dropdown menu which I use to pick tasks. When the option is selected, it runs this code.. Python code:
The only time it doesn't work? If the task that I'm trying to import contains either of these two lines... Python code:
"Timeout waiting for response on 115" I have also tried Python code:
Sad Panda fucked around with this message at 17:04 on Mar 3, 2019 |
# ? Mar 3, 2019 17:01 |
|
I am (as an exercise) converting one of my C# programs to Python. Some of it is pretty straightforward, but in my C# program I use several static classes for things that I don't need to instantiate and i don't feel like passing around from method to method. The program I am converting is a tool that builds software models of Firewalls from configuration files stored on a TFTP server. To speed things up (especially since more than half of my team of engineers is in India), I cache copies of the config files locally. I use a static class called FileManager to manage access to the configuration files. The manager determines whether the local files are current and if not copies current versions to the cache directory, and maintains a dictionary of files which are managed. I'm using a singleton model to create the classes in python: Python code:
|
# ? Mar 4, 2019 23:42 |
|
LongSack posted:Am I barking up the wrong tree? Before i get too far down this path (there are 13 ...Manager classes in total) - is there a better way? Am i thinking too much in C#? I'd write a bunch of modules with free functions instead of a bunch of singleton classes.
|
# ? Mar 4, 2019 23:55 |
|
Nippashish posted:I'd write a bunch of modules with free functions instead of a bunch of singleton classes. ^ if you're passing a dictionary around just do that. dictionaries and python are like peanut butter and jelly creating a class is my last resort when I can't think of a meaningful way to organize the data
|
# ? Mar 5, 2019 00:26 |
|
Nippashish posted:I'd write a bunch of modules with free functions instead of a bunch of singleton classes. Jumping off of this: I'm working on an AWS Lambda app that interfaces with a few different APIs to implement the logic. These APIs are standing in for what would typically be a database with normalized relations. User information comes in via a webhook and I need to look up related data from different services using information from the webhook. Right now it's a tangle of making different API calls to get all the information I need because of all these different APIs I need to talk to in a single request. E.g. design: Python code:
code:
I've typically worked with the Django ORM and a bit of SQLAlchemy, but I don't have the luxuries of either here. Fluue fucked around with this message at 01:32 on Mar 5, 2019 |
# ? Mar 5, 2019 01:04 |
|
Nippashish posted:I'd write a bunch of modules with free functions instead of a bunch of singleton classes. OK, here my newbness comes through. What is a free function? Google is not being helpful. Is it just a function in a module that’s not part of a class?
|
# ? Mar 5, 2019 01:10 |
|
LongSack posted:OK, here my newbness comes through. What is a free function? Google is not being helpful. Is it just a function in a module that’s not part of a class? Yep! A regular function you would import from the module.
|
# ? Mar 5, 2019 01:16 |
|
Fluue posted:Yep! A regular function you would import from the module. What happens if a module is imported multiple times? Like my FirewallManager module needs to reference the FileManager module to get access to the configuration files, but other modules do too. In my C# code, the guts of the FileManager is two Dictionary<string, ManagedFileInfo>, one for remote files (those on the TFTP server), and the other for local (cached) files. It’s critical that there is only one set of those dictionaries.
|
# ? Mar 5, 2019 01:46 |
|
LongSack posted:What happens if a module is imported multiple times?
|
# ? Mar 5, 2019 03:30 |
|
cool. spent 2 hours trying to bugfix and ran headfirst into an Actual Bug in 3.7. https://github.com/boppreh/keyboard/issues/186 while i'm here, here's a quick and dirty way to add keypress filtering to any program (that works regardless of active window, much better than cv.waitkey), and also how I discovered the bug in the first place. Only an issue if you're already threading, I think, but solvable if you're willing to edit python libs. code:
|
# ? Mar 5, 2019 05:11 |
|
Does anyone know what the proper way of annotating different return types for a function overloaded with typing.overload? I have this for example: code:
It's fine with me doing this as well: code:
This seems to be fine as well: code:
The mypy docs give me the impression that this is what the Literal construct is suppose to help me do, but all of the examples are for the case where b is not optional, but instead like e.g. either a float or a str. Boris Galerkin fucked around with this message at 14:10 on Mar 11, 2019 |
# ? Mar 11, 2019 13:48 |
|
If Foo is a list of Bar, which is better to get a specific Bar from Foo?Python code:
Python code:
|
# ? Mar 12, 2019 05:20 |
|
https://stackoverflow.com/questions/3013449/list-comprehension-vs-lambda-filter either, really. combination of personal taste and 'what else are you doing'. could also make a generator out of it (example further down) it's worth nothing that this very similar question raises a good point: https://stackoverflow.com/questions/7125467/find-object-in-list-that-has-attribute-equal-to-some-value-that-meets-any-condi code:
quote:The naive loop-break version, is perfectly Pythonic -- it's concise, clear, and efficient. just about anything works
|
# ? Mar 12, 2019 05:47 |
|
I never would have expected to see someone describe that loop-breaking example as pythonic I mean I'm cool with it but it just makes me question (again) what "pythonic" means
|
# ? Mar 13, 2019 00:10 |
|
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 |
|
What would you envision the difference between next and first being?
|
# ? Mar 13, 2019 01:14 |
|
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 |
|
Pythonic just means anything you don't personally think is bad form that has acceptable performance. It's all relative imo. PEP 20 is dumb. Anyone wnho has time to muse about these things at such high level should get back to work. Also I believe the two forms posted above have different evaluation semantics. (iter vs. for/break) I'd probably use filter in most cases personally, unless bar.names are not unique then next. Next tends to be an alias for "first" in my head. dougdrums fucked around with this message at 03:09 on Mar 13, 2019 |
# ? Mar 13, 2019 03:01 |
|
I was using futurizer to try to migrate some code from Python 2.7 to 2.7-3.6 compatibility. Something that screwed things up was a bunch of imports for builtins.str that it inserted:code:
I understand in Python 3 that string handling has gotten a little bit fussier due to a more thorough go at Unicode support, but this doesn't appear to be about that at first glance.
|
# ? Mar 14, 2019 03:57 |
|
Is there a click equivalent to argparse's "add_argument_group" feature for documenting the --help text? With argparse I can add argument groups to get optional arguments to show up in separate headers: code:
code:
|
# ? Mar 14, 2019 09:56 |
|
Having a weird Django problem. Appears to be intermittent, spent several hours trying to track it down this week and last. Followed the django girls blog tutorial as a model, has been working great for months. When I create a "blog post" record it gets a model.active=true, and then my main index page shows a summary view of each blog post, where each model has model active=True. I have an edit, and a couple of other pages that modify the "blog post" record, those all use standard views. You post (POST) a form to the view, and then it redirects you to either the (GET) full blog post/record view, or the main index page, depending. Works great, 200s all day everyday. POST, GET. 200. POST, GET. 200. POST, GET. 200. Then I have a delete page... This works intermittently. Most of the time you save the form and in the background it sets model.active=False and also calls a function that runs custom code. So you POST the form to the delete view, it sets False and runs custom code... Then it is supposed to send you to do a GET of the main index page... But instead the django log is showing a second POST and debug logging is showing the custom code function (and indeed, the entire if post, then run this portion of the view) getting called a second time. Since there is at least one non-idempotent thing in that function, it throws an error and returns a 500 to the end user, even though the code ran correctly the first time on the first POST. POST, POST. 500. POST, POST. 500 etc I traced the call in Chrome developer mode, it is not posting twice. POST only happens once from the client side. As far as I can tell, this second POST I am seeing in the logs is happening from inside Django and it's not a user double clicking on the post button. I've also verified the urls.py looks good and there's no obvious call backs to the view from inside the function. Also pylint is reporting no errors. And this is the only view exhibiting the double post behavior. I even rebuilt the view from scratch and I'm still seeing the behavior. What's super weird is that my version 0.6.46 magically started working fine (single POST, 200) last night around 3am, so I crowned it 0.7.0 and moved forward with fixing other problems, got up to 0.7.6 and then retested the delete function and it had stopped working again. Rolled back to the 0.6.46 container (EXACT same code, no new migrations added) and it was still seeing the double POST/500 error ha;lp Hadlock fucked around with this message at 18:27 on Mar 14, 2019 |
# ? Mar 14, 2019 18:06 |
|
Hadlock posted:Django. There's a Django thread. I don't have time or energy to really read or think about your post right now, but maybe someone there will.
|
# ? Mar 14, 2019 19:55 |
|
pmchem posted:Spyder is a really great, open source / free, lightweight, python-native piece of software that needs more appreciation in the community. I love it. We had a push towards pycharm from the engineering team, due to the support for refactoring, super easy venv management and pep8 warnings. Did support it for a while. But for data science, Spyder really is king. Super fast prototyping, no manual reloads of user defined libraries. In Spyder I feel like I never need to reset console/reload data. And for data science, reloading data is always a major hassle. Pycharm kinda hates that workflow even with scientific mode. Pycharm might be better if I'm building an application meant to last. But for a kaggle competition or a quick data analysis, Spyder is faster.
|
# ? Mar 14, 2019 21:12 |
I don’t have any PyCharm problems working as data scientist, but then again I’m quite used to it and never really in a hurry like implied by a Kathleen competition or similar. I’ve tried trying Spyder a bunch of times, but I guess it’s just not for me.
|
|
# ? Mar 14, 2019 22:38 |
|
I’m discovering that I’m not a real fan of significant white space. Using Spyder makes it easy, but explicit block openers and closers would prevent this bug:Python code:
|
# ? Mar 15, 2019 02:42 |
|
LongSack posted:I’m discovering that I’m not a real fan of significant white space. Using Spyder makes it easy, but explicit block openers and closers would prevent this bug:
|
# ? Mar 15, 2019 03:36 |
|
Is there any way to emulate/force the windows copy function without pressing ctrl c? As in not even using keyboard or pyautogui to press them virtually
|
# ? Mar 18, 2019 16:07 |
|
|
# ? Jun 5, 2024 05:13 |
|
Meyers-Briggs Testicle posted:Is there any way to emulate/force the windows copy function without pressing ctrl c? As in not even using keyboard or pyautogui to press them virtually 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 have a synchronous REST convenience wrapper for one of our internal systems that started out to make my life easier and turned into an sdk that's now used in a variety of things, some of which I have no idea about. I'm putting together a service that will heavily use this, and I'd like to use the starlette based FastAPI, but I'm not sure how to go about making an async version of the same package while leaving the sync functionality as it is. I've looked at a few things, like detecting whether or not the caller is sync/async and branching from there but has anyone else encountered this? I'm just not sure how to begin thinking about this, and I'm not necessarily aware of anything else that's a both-at-once kind of a deal. Edit: Or just any better way to approach this in general. Frequent Handies fucked around with this message at 03:00 on Mar 19, 2019 |
# ? Mar 19, 2019 02:47 |