|
Deadite posted:I’m pretty new to python, and I didn’t think to just download the code and import it that way. Python is great about having a library for everything. There's a joke you can import anything you need in Python. Also means you need to import to do most things as common functions like HTTP, PDF, databases, etc. get abstracted away. It could be done in code using the base python code but would be more complicated then just getting the source code. IMO if someone has done the work previously, best to be lazy and use that. No sense in reinventing the wheel twice.
|
# ? Dec 2, 2019 05:48 |
|
|
# ? May 28, 2024 00:36 |
|
I'd like to do realtime reporting on thousands of network tasks being processed, possibly using websockets to push updates to a browser. They're part of a big batch i need to keep tabs on. I'm not sure how to reason about this. Reading about concurrent.futures made me want to use those, but I'm not sure how to tally updates on the current state of the system, considering each task can have a few states (likely common stuff like "pending", "failed" and "done") How can a simple network task inform the rest of the system of its state in an elegant way ? Maybe have each task update its state to a redis instance, but then I'd need something to watch over Redis and push updates when they happen (avoiding polling would be nice).
|
# ? Dec 2, 2019 12:50 |
|
So no matter what I do, PyCharm gives me the error "AttributeError: 'InputHookManager' object has no attribute '_stdin_file'" whenever I try to import from a sublibrary like with "import matplotlib.pyplot as plt" or "from scipy.signal import argrelextrema" Turns out I don't need those libraries in particular right now but maybe I will in the future. I tried some google searchs, including the one that changed some global variables or updated pycharm, and they don't seem to be working (and again it's not exclusive to matplotlib...). Any suggestions?
|
# ? Dec 2, 2019 17:57 |
|
Hemingway To Go! posted:So no matter what I do, PyCharm gives me the error "AttributeError: 'InputHookManager' object has no attribute '_stdin_file'" whenever I try to import from a sublibrary like with "import matplotlib.pyplot as plt" or "from scipy.signal import argrelextrema" Just to be clear, is it PyCharm or Python giving you this error? (I only ask because I don't know your experience level and newbies often have a hard time distinguishing between their IDE and the programming language)
|
# ? Dec 2, 2019 19:36 |
|
New PyCharm out today. Best features for me: interactive widgets in jupyter notebooks, TypedDict and Literal support, completion for when you're typing file paths into strings.
|
# ? Dec 2, 2019 20:49 |
|
Thermopyle posted:Just to be clear, is it PyCharm or Python giving you this error? (I only ask because I don't know your experience level and newbies often have a hard time distinguishing between their IDE and the programming language) Going into python3 on terminal and typing the commands in gives no errors. pycharm gives the error, and all googling seems to indicate the error is pycharm's. Also cannot figure out how to sudo apt-get upgrade pycharm3. Right clicking it for details from the menu says it literally cannot find pycharm-community_pycharm-community.desktop, dpkg -l |grep "pycharm" gives nothing either. (it launchs despite being some kind of phantom app)
|
# ? Dec 2, 2019 21:33 |
|
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.
|
# ? Dec 2, 2019 21:43 |
|
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 |
|
Hemingway To Go! posted:Going into python3 on terminal and typing the commands in gives no errors. pycharm gives the error, and all googling seems to indicate the error is pycharm's. Do you have the correct interpreter selected for your project?
|
# ? Dec 2, 2019 21:59 |
|
Yeah. Says it has the libraries installed. Just has errors when I try to use them. Again using the same commands from the terminal has no problem.
|
# ? Dec 2, 2019 22:52 |
|
Hemingway To Go! posted:Yeah. Says it has the libraries installed. Just has errors when I try to use them. Again using the same commands from the terminal has no problem. Weird stuff. Like you said there's not much on Google about this. Maybe try it the trial Pro version of PyCharm?
|
# ? Dec 2, 2019 23:06 |
|
Feel like your PyCharm installation is broken somehow, not necessarily your code or environment.Hemingway To Go! posted:"AttributeError: 'InputHookManager' object has no attribute '_stdin_file'" e: same issue (I think) on StackOverflow: https://stackoverflow.com/questions/57260720/unable-to-execute-the-code-matplotlib-pyplot-as-plt-in-pycharm-attributeerror with a response from a dev in the comments linking to a bug report that's five years old, not fixed and I can't really tell if that's still the same problem you're having? KICK BAMA KICK fucked around with this message at 23:18 on Dec 2, 2019 |
# ? Dec 2, 2019 23:13 |
|
Hemingway To Go!: I voted on the issue for you. Hopefully it gets some attention sooner rather than later.
|
# ? Dec 2, 2019 23:28 |
|
Just uninstalled and reinstalled pycharm and it still cannot deal with matplotlib. Will see if I cannot find a python Dev irl for help.
|
# ? Dec 3, 2019 00:04 |
unpacked robinhood posted:I'd like to do realtime reporting on thousands of network tasks being processed, possibly using websockets to push updates to a browser. They're part of a big batch i need to keep tabs on. This is a complicated thing, but you'll probably need to use some kind of simple redis queue system, something like this: http://peter-hoffmann.com/2012/python-simple-queue-redis-queue.html Have your events post their completions to a couple of different queues, and have a couple of different daemons polling these queues, grabbing events, and updating whatever it is you want to view the events with. If you've got a lot of things going on simultaneously, some kind of supervisorctl-style process manager will be really helpful.
|
|
# ? Dec 3, 2019 20:11 |
|
Hemingway To Go! posted:Just uninstalled and reinstalled pycharm and it still cannot deal with matplotlib. Will see if I cannot find a python Dev irl for help. Did you try creating a new environment and configuring pycharm to use it?
|
# ? Dec 3, 2019 20:33 |
|
I'm working on a Jupyterhub app and I'm looking for the best way to convert a flowchart created in an image editing package (indifferent to which, have looked at draw.io, which works with Jupyter out of the box) into a python data structure to be passed to another app/db. Users can wire up a basic diagram which becomes some kind of output (once again, open to how to do this), and which is processed by another visualisation app. Can be a manual process, not necessarily dynamic hooks or whatever, it's just to help out the non-coders to start a new template. Any ideas on where to start? Edit: Graphviz https://graphviz.readthedocs.io/en/stable/ does the kind of thing I'm thinking, albeit without a GUI drawing interface. LuckySevens fucked around with this message at 11:10 on Dec 4, 2019 |
# ? Dec 4, 2019 11:07 |
|
LuckySevens posted:I'm working on a Jupyterhub app and I'm looking for the best way to convert a flowchart created in an image editing package (indifferent to which, have looked at draw.io, which works with Jupyter out of the box) into a python data structure to be passed to another app/db. Users can wire up a basic diagram which becomes some kind of output (once again, open to how to do this), and which is processed by another visualisation app. Can be a manual process, not necessarily dynamic hooks or whatever, it's just to help out the non-coders to start a new template. I've used (~1 year ago) graphviz to display inline decision trees generated by sklearn. I imagine a flowchart is possible as well. I recall the binary being fucky to install but not much else about it other than it got it done.
|
# ? Dec 4, 2019 22:08 |
|
I just got feedback on a homework assignment and I need to see if I'm crazy or not. The task was read a JSON list of cars into Python and create a dictionary and a list of each car in the JSON file and certain attributes like horsepower or mileage. My code's below. The feedback was 'overcomplicated, check these commits.' The code examples he gave all explicitly wrote out each variable to some form. One was close to what I did, just wrote out the dictionary key instead of calling it as a stored variable. The other two created the list first, and then referenced the place in the list to create the dictionary. I can see how their entries are more straightforward and just work, but if I needed to grab another variable, it'd take a minute to update everything successfully, maybe 2 if it required a different amount of nested JSON than I had built. Also, if I'm the TA looking at something like 45 different people's code for the same task I'd want them to not throw curveballs whenever possible. \/\/\/ durf code:
Coco13 fucked around with this message at 00:41 on Dec 6, 2019 |
# ? Dec 5, 2019 23:58 |
|
Coco13 posted:I just got feedback on a homework assignment and I need to see if I'm crazy or not. The task was read a JSON list of cars into Python and create a dictionary and a list of each car and certain attributes like horsepower or mileage. I created an array of the JSON variables: [["Engine_Information","Engine_Statistics","Horsepower"], ["Fuel_Information", "Highway_mpg"], ["Fuel_Information", "City_mpg"]]. For each JSON car entry iterated over that array to create my dictionary and list to get the information, using the last entry of the JSON as my dictionary key: cardictionary[json_variable[1]] = json_car[json_variable[0]][json_variable[1]] I can't understand what your saying you did or what you're saying they're wanting you to do. Provide code in code tags dude!
|
# ? Dec 6, 2019 00:34 |
|
The way you're grouping the data is weird, but maybe that's related to the assignment requirements. It's hard to tell from your example what the input and expected output formats are. Using collection len to determine how to categorize seems fragile. I recommend avoiding using types in var names.
|
# ? Dec 6, 2019 01:19 |
|
Also, don't put more than you need in the with open block. Here's one way to do this, where we assume the JSON is organized in a clean way. Notice how I'm defining data structures first? It makes it clear what the result should look like, and what we're accomplishing.Python code:
Tangent: Do I need @classmethod in the above code near the top? What does it do besides provide the cls argument, which could just be the class's name. Dominoes fucked around with this message at 02:08 on Dec 6, 2019 |
# ? Dec 6, 2019 01:32 |
|
classmethod makes it still work as expected if subclassed and those attributes are overridden but the method isn’t. Just one of those low cost abstraction things that helps prevent you from loving up things you didn’t anticipate or were like, there’s never going to be a reason someone would do that, which of course inevitably happens, imo. I wasn't thinking about the fact that it was an Enum. I think in this case it doesn't make any actual difference, but I'd still use a classmethod anywhere I'm using only the class as some kind of ironclad law that I can't think of a sane counterexample for at the moment and I'm sure someone will provide. breaks fucked around with this message at 02:21 on Dec 6, 2019 |
# ? Dec 6, 2019 01:54 |
|
I just discovered numpy.piecewise and I'm having a hard time understanding why it exists or why I should use it.code:
code:
Boris Galerkin fucked around with this message at 13:39 on Dec 6, 2019 |
# ? Dec 6, 2019 09:07 |
|
Boris Galerkin posted:I just discovered numpy.piecewise and I'm having a hard time understanding why it exists or why I should use it. The first one doesn't work if x is an array, but the second one does (or would, with a few modifications) The lambdas aren't redefined multiple times, they're just defined once and passed to piecewise as function objects. The difference is that applying foo to every element of an array would require multiple calls to foo, whereas piecewise is defined to operate on the entire array, not just one element. QuarkJets fucked around with this message at 10:51 on Dec 6, 2019 |
# ? Dec 6, 2019 10:48 |
|
What is the proper way to make it work with arrays anyway? I always get that "truth value of an array… use a.any() or a.all()" error and I never know how to deal with that and the message just isn't helpful. Passing np.arange(-10, 11, 1) to both functions as written raises the same error.
|
# ? Dec 6, 2019 10:57 |
|
Boris Galerkin posted:What is the proper way to make it work with arrays anyway? I always get that "truth value of an array… use a.any() or a.all()" error and I never know how to deal with that and the message just isn't helpful. Passing np.arange(-10, 11, 1) to both functions as written raises the same error. Python code:
|
# ? Dec 6, 2019 11:03 |
|
CarForumPoster posted:I've used (~1 year ago) graphviz to display inline decision trees generated by sklearn. I imagine a flowchart is possible as well. I recall the binary being fucky to install but not much else about it other than it got it done. Worth a look ay, thanks!
|
# ? Dec 6, 2019 11:09 |
|
Dominoes posted:The way you're grouping the data is weird, but maybe that's related to the assignment requirements. It's hard to tell from your example what the input and expected output formats are. Using collection len to determine how to categorize seems fragile. I recommend avoiding using types in var names. A: Thanks! B: The if/then for the elements of carinfo is the part I wish I could change the most, but didn't have an inkling on how. C: The grouping is because of the requirements. They are: quote:Step 1 - Initialize the following 2 instance variables: Which, thinking about it a little more, is really odd because the lesson was on making classes in Python. So, the examples were a robot class, and building individual robots, and the homework was to take all these cars and make one object that had all these cars as a list and dictionary instance variables.
|
# ? Dec 6, 2019 13:28 |
|
QuarkJets posted:
Got it, thanks. Also thanks for fixing the third condition for me . Would it make any sense/difference to define those three lambdas as functions? Python code:
|
# ? Dec 6, 2019 13:47 |
|
breaks posted:classmethod makes it still work as expected if subclassed and those attributes are overridden but the method isn’t.
|
# ? Dec 6, 2019 15:14 |
|
Next tangent: Is there a standard/idiomatic way to do do the from_str method/constructor I posted? Ie, an analog of __str__, but does the inverse. Is there a different way you would have written that method?
Dominoes fucked around with this message at 05:55 on Dec 8, 2019 |
# ? Dec 8, 2019 05:52 |
|
__repr__ is supposed to be that...aka the output of repr is supposed to be what you need to construct the object if at all possible.
|
# ? Dec 8, 2019 05:59 |
|
Boris Galerkin posted:Got it, thanks. Also thanks for fixing the third condition for me . Totally! I actually never use lambdas in my own code, personal preference
|
# ? Dec 8, 2019 06:17 |
|
CarForumPoster posted:I've used (~1 year ago) graphviz to display inline decision trees generated by sklearn. I imagine a flowchart is possible as well. I recall the binary being fucky to install but not much else about it other than it got it done. Love using graphviz. No drag and drop GUI, but its built as code (like an SVG) so it can be checked in and versioned. Meant to look into getting it incorporated to doc strings, but haven't gotten that far yet. Ideally you could put in a module or class level flow diagram for more complicated business logic and have it built and added to any output documentation as an image.
|
# ? Dec 8, 2019 08:13 |
|
amethystdragon posted:Love using graphviz. No drag and drop GUI, but its built as code (like an SVG) so it can be checked in and versioned. I have some experience in doing what you described. I made a dot file 'subway map' that walks through the parts of the code being touch during a typical execution scenario. The generated SVG figures are imported by the markdown documentation files. Everything is just text checked into the repo, with figures generated at build time by the makefiles. Some cool features: - URL link attributes on nodes/edges: you can click on nodes in the generated SVG figure to jump to the Doxygen documentation of said class or method. As long as the name doesn't change, it will not break the link. - Viewports: you can zoom into specific rectangles of your figure, e.g. to zoom into the context around the specific method you are describing in the documentation. I rigged up a script to take a list of nodes, fetch their coordinates and generate a viewport enveloping those coordinates. IIRC you can use dot files with Doxygen, but I have not tried putting it in docstrings.
|
# ? Dec 11, 2019 15:23 |
|
If Thread subclasses A, B and C hold a reference to a shared object, things are fine if only thread A ever writes to the object, while others only read from it, right ?
|
# ? Dec 13, 2019 11:42 |
|
unpacked robinhood posted:If Thread subclasses A, B and C hold a reference to a shared object, things are fine if only thread A ever writes to the object, while others only read from it, right ? quote:things are fine Depends on what you mean by "fine"
|
# ? Dec 13, 2019 23:21 |
|
I've been trying to teach myself python and I've been going through the assignments at [practice python]. This is problem 4 (return factors of given number) and I see that there are one line list comprehension solutions and even better ways of doing it in a for loop but after trying and failing I don't see how just copying the solution and saving it in a file on my laptop would really teach me anything. I just can't figure out why my code here doesn't work. It only outputs a list containing the original number.If anyone could tell me what is wrong here I would really appreciate it. At first I had my poo poo set up wrong and it was running it in 2.7 but once I fixed that it seems that this works the same (ie, it doesn't) in 3.6. code:
|
# ? Dec 15, 2019 03:16 |
|
|
# ? May 28, 2024 00:36 |
|
bigperm posted:I've been trying to teach myself python and I've been going through the assignments at [practice python]. This is problem 4 (return factors of given number) and I see that there are one line list comprehension solutions and even better ways of doing it in a for loop but after trying and failing I don't see how just copying the solution and saving it in a file on my laptop would really teach me anything. You've got your operation reversed, you should be checking numb % n == 0 (e.g 10 % 2 == 0 but 2 % 10 does not)
|
# ? Dec 15, 2019 03:20 |