|
C2C - 2.0 posted:I just finished building a project for my class; it's essentially a Tkinter interface with a bunch of inputs for my music collection that saves the inputs to a .json file. I can’t tell exactly what the issue is from what you’ve posted, but the line code:
The error message tells you that at some point in the invocation it tried to call a render() method on some object, but that object turned out to be None instead of what it was expecting so it couldn’t continue. Unfortunately that’s not enough information to solve the issue - python is sadly notorious for unhelpful error messages like this. Also the show() function in that snippet looks like it was originally a member function that you copy pasted from some class defined elsewhere. That is almost certainly the wrong thing to do, though as I mentioned above that function isn’t currently doing anything in your code.
|
# ? Mar 1, 2023 00:02 |
|
|
# ? May 15, 2024 03:29 |
|
C2C - 2.0 posted:Here's the error I'm getting: big picture suggestion here for when you're asking for troubleshooting help: try first to simplify the problem as much as possible. here's a heavily simplified version that exhibits the same error: notice how this no longer requires us to understand what's in your 'music.json' (that would've been my first guess for a NoneType attribute error), and including the stack trace helps narrow down the problem anyway, after poking around a bit, I think code:
code:
if you do want the inline plot, it seems like you need to specify that at Network initialization for the template to be set properly? code:
|
# ? Mar 1, 2023 00:22 |
|
DoctorTristan posted:python is sadly notorious for unhelpful error messages like this. Whoa, that is not my experience at all. The problem is not that the message is vague, in fact the message states exactly what the problem was and the specific line that led to the problem is in the printed traceback but was just left out of the post. This is way more useful than the C standard of simply seg faulting. The problem here is that the OP left out most of the traceback
|
# ? Mar 1, 2023 01:56 |
|
The error messages are not very helpful, if you don't look at them.
|
# ? Mar 1, 2023 01:58 |
|
QuarkJets posted:Whoa, that is not my experience at all. The problem is not that the message is vague, in fact the message states exactly what the problem was and the specific line that led to the problem is in the printed traceback but was just left out of the post. This is way more useful than the C standard of simply seg faulting. The problem here is that the OP left out most of the traceback Yeah, 100% agreed; Python's error messages aren't Rust-level, but they're still pretty drat good and the traceback is almost always enough to figure out what's going on. This one immediately tells you that there's an issue where it's attempting to call a render method on something it expects to be there, but is a None instead. The library you're using shouldn't let a NoneType get that far without throwing a more specific error first, but that's not Python's fault. While I'm soapboxing a little bit; this is also an excellent example of when a debugger would be super handy. Whatever IDE you're using should have one in this day and age (and if you're going to skip using an IDE, then you better learn to love PDB for debugging) and should call up a debug session exactly where the error occurs, allowing you to look over the stack and see what is assigned to what. Zoracle Zed posted:if you do want the inline plot, it seems like you need to specify that at Network initialization for the template to be set properly? Yeah this should 100% be caught by PyVis and throw an error. I might even look into raising a PR for this issue since I'm trying to get more into OSS. Falcon2001 fucked around with this message at 02:17 on Mar 1, 2023 |
# ? Mar 1, 2023 02:06 |
|
Jabor posted:The error messages are not very helpful, if you don't look at them.
|
# ? Mar 1, 2023 03:23 |
|
Seventh Arrow posted:Not even the SQL thread? Zoracle Zed posted:just guessing but I bet your SQL driver is (correctly, imo) not interpolating the tss variable here: Python code:
|
# ? Mar 1, 2023 03:51 |
|
I've been using python since the 1990s. And the thing still finds new ways to delight me in the "how did I somehow not know about this amazing thing?" way. code:
|
# ? Mar 1, 2023 07:45 |
|
Everything in itertools is delightful. Basically a standard library module tailor-made for trivializing coding interview screens.
|
# ? Mar 1, 2023 07:52 |
|
QuarkJets posted:Whoa, that is not my experience at all. The problem is not that the message is vague, in fact the message states exactly what the problem was and the specific line that led to the problem is in the printed traceback but was just left out of the post. This is way more useful than the C standard of simply seg faulting. The problem here is that the OP left out most of the traceback Maybe I’m projecting my own experience of using pandas and its truly incomprehensible traces, but I frequently find that the combination of dUcK tYpInG plus a general design approach in third-party libraries of throwing as late as possible means that the trace points to something long after the bug that actually caused the error. Here I agree it’s fairly easy for an experienced python person to figure out, though I really wish argument validation in top-level functions were more widespread than it currently is.
|
# ? Mar 1, 2023 13:54 |
It took me a long time to realize that the whole stack trace is useful, not just the last few lines. Like you'll have 30 lines in a trace; the first 14 are nested calls in native code, the last 14 are library code, and the one right in the middle is YOUR code where the issue is. e: Python 3.11 now does highlighting with ^^^^^^^^^^ marks to show extremely clearly where it's breaking Data Graham fucked around with this message at 14:12 on Mar 1, 2023 |
|
# ? Mar 1, 2023 14:06 |
Hey y'all, sorry for the previous mystery post. The instructor in the class really hammered away at looking at the actual error instead of the entire traceback. I was looking thru the PyVis documents yesterday evening and came across their "Getting Started" example which is rather simple:Python code:
code:
Python code:
I also found a single mention of this issue on StackOverflow that indicated the show function located in the package's network.py file can be edited to change the defaults, but I think I'm gonna' keep my hands off of it for now and just pass the arguments in the script. Thanks for everyone's help and constructive criticism!
|
|
# ? Mar 1, 2023 14:35 |
|
duck monster posted:I've been using python since the 1990s. Like, I recently discovered (through Trey Hunner’s newsletter) a way of avoiding a common for/break pattern. Let’s say you want to assign foo to the first item in an iterable that meets some criterion (such as the first even number), and if you don’t find it, then assign it to None. The verbose implementation is: code:
code:
Seems like Python always has a way of simplifying really ugly code.
|
# ? Mar 1, 2023 14:56 |
|
C2C - 2.0 posted:Hey y'all, sorry for the previous mystery post. The instructor in the class really hammered away at looking at the actual error instead of the entire traceback. Sometimes you have to look at both, they give you different information; the error tells you what went wrong (a None was encountered) and the traceback tells you where
|
# ? Mar 1, 2023 17:54 |
|
C2C - 2.0 posted:Adding "notebook=False" to the .show() method fixed it. As an aside, I was looking at the official PyVis docs and perusing the individual methods in the library & there's a link to the source code in the library for each one. Here's the source code for .show(): Yeah, that really sucks; their tutorial assumes the user is running in a notebook without stating that assumption. Yuck, you should send them a note about this; it'd be so easy to update the tutorial a little. This is another major part of software development: documentation is sometimes deceptive
|
# ? Mar 1, 2023 18:10 |
More questions: I used Pandas to create a DataFrame from my .json file and am working on learning MatplotLib to create graphs from the .json data. Some of the fields in the .json (like 'bpm', 'year', et. al.) are integers but they're saved as strings in the .json file. Short of going back and editing the .json file itself, is there a way to order the strings that are actually integers in either ascending or descending order? Right now, my x- and y-axes are displaying the values in the order (I assume) they're appearing in the DataFrame. Would using int() on those strings then creating a function to order them be possible? Here's one of the graphs as-is with the DataFrame ordering (again, I assume): (Some of the .json entries don't have BPM values yet as I haven't calculated all of them; thus the initial empty BPM value on the x-axis)
|
|
# ? Mar 1, 2023 20:56 |
|
I am trying to parallelize (using the joblib module) some code which involves querying a database (the query I had issues with earlier). Python code:
code:
|
# ? Mar 1, 2023 22:07 |
|
C2C - 2.0 posted:More questions: You can use df['column_name'].astype(int) to convert the entries in a column to integers (note this will throw an error if any row entry in that column cannot be converted into an integer, e.g., if the entry is 'dog').
|
# ? Mar 1, 2023 22:08 |
|
Jose Cuervo posted:I am trying to parallelize (using the joblib module) some code which involves querying a database (the query I had issues with earlier). first: sqlite (afaik) isn't great for parallel writing, so this is only worth doing if each task is only reading from the database. second: the error you have there says "TypeError: cannot pickle 'sqlite3.Cursor' object". Can you see how to rearrange some things so the cursor object doesn't need to be shared between the jobs running in parallel?
|
# ? Mar 1, 2023 22:21 |
|
Zoracle Zed posted:first: sqlite (afaik) isn't great for parallel writing, so this is only worth doing if each task is only reading from the database. The queries are only reading from the database. And yes, I actually do not need to share the cursor but I did not realize that until you pointed it out, thanks!
|
# ? Mar 1, 2023 22:35 |
|
C2C - 2.0 posted:More questions: Gonna build a question on your question because I realized that I have no idea why I don't use matplotlib. Is there a reason specifically why matplotlib is your choice for viz? My go to has always been more high level packages, and I'm particularly fond of Altair or plotly or seaborne. Throw your JSON into a pandas dataframe and then just declare your chart type and which columns to encode as x and y markers is just so easy. Though I guess if your JSON is heavily nested then you'd have to flatten it or remodel it to work easily in a pandas df. Is there more interesting control that comes from matplotlib that makes it worth it? I'm really into data viz, soI've been debating to learn d3js or maybe it's higher level bindings in vega, but man I really wish I didn't have to get out of Python to do interactive and dynamic viz stuff so always on the look out for something better. Oysters Autobio fucked around with this message at 03:45 on Mar 2, 2023 |
# ? Mar 2, 2023 03:41 |
Jose Cuervo posted:You can use df['column_name'].astype(int) to convert the entries in a column to integers (note this will throw an error if any row entry in that column cannot be converted into an integer, e.g., if the entry is 'dog'). Ended up fixing it at the root of my app pipeline. My cataloging app was calling get() on all the .json fields for my Add Entry and Update Entry functions, so I just wrapped the necessary values as int(some_value.get()). Now I don't have to do anything with the .json other than convert it to a DataFrame. Your suggestion did lead me to looking further into the Pandas docs and that's a ton of interesting reading since my class lightly touched on DataFrame manipulation and I reckon we didn't cover even 1/3 of just the DataFrame methods.
|
|
# ? Mar 2, 2023 03:52 |
Oysters Autobio posted:Gonna build a question on your question because I realized that I have no idea why I don't use matplotlib. I'm not the one who could answer this as I have zero programming background and just started learning Python a few months ago. For my part, MatplotLib (specifically matplotlib.pyplot) was the first visualization library that was touched on in my class. Else that, we also did a handful of visualization sections using Plotly. Any other viz libraries (NetworkX, PyVis,) have just been me exploring. I'm in the final projects phase of the class, but other than core Python concepts, we only lightly touched on APIs, scraping, visualization, Numpy, et. al. While I'm doing my projects for the class, I'm going back to certain sections and doing a deeper dive into stuff that really interested me. I'm attempting to change careers after decades & it's somewhat disheartening that Python is everywhere & tons of folks are amazing at it. So I'm trying to shore up as much knowledge as I can before being brave enough to fill out job applications that are just going to be deleted
|
|
# ? Mar 2, 2023 03:59 |
|
Zugzwang posted:You could instead do this as a one-liner: Thank you for this. What I'd been doing in the past (when I was quite sure that the element I wanted would be in the list, and only exactly once) was use list comprehension and just tack a [0] at the end, but this is a bit more elegant. I just used it to filter through a list of GitHub release assets to find the right file to install during a pipeline run.
|
# ? Mar 3, 2023 19:09 |
Yeah, I hear the Kill Bill klaxon in my head whenever I see [0] IndexError waiting to happen.
|
|
# ? Mar 3, 2023 19:14 |
|
A friend pointed out to me that I don't need the default value in next, especially when the next step in my code (loading the URL I found) would fail if the default value happened, so I just took that out. It'll cause a StopIteration exception which I'm not handling, but what it really means is something is messed up with the project I'm reading from and I'll need to fix my code regardless.
|
# ? Mar 3, 2023 20:07 |
|
Oysters Autobio posted:Gonna build a question on your question because I realized that I have no idea why I don't use matplotlib. Seaborn is mostly a convenient wrapper around matplotlib with a less obtuse/ambiguous interface. It's quite handy but sometimes you end up needing to fiddle directly with matplotlib objects, change rcparams, etc. beyond what seaborn does. Also, you might find yourself needing to use a library that calls matplotlib directly so it doesn't hurt to get familiar with it.
|
# ? Mar 4, 2023 04:52 |
|
FISHMANPET posted:A friend pointed out to me that I don't need the default value in next, especially when the next step in my code (loading the URL I found) would fail if the default value happened, so I just took that out. It'll cause a StopIteration exception which I'm not handling, but what it really means is something is messed up with the project I'm reading from and I'll need to fix my code regardless. Data Graham posted:Yeah, I hear the Kill Bill klaxon in my head whenever I see [0] Zugzwang fucked around with this message at 06:17 on Mar 4, 2023 |
# ? Mar 4, 2023 06:08 |
|
Thanks for the answers about matplotlib. Would love any suggestions folks might have on courses, books, videos or other learning content where I can start learning a bit more about actual Python development beyond the basics of understanding dicts, and loops and etc. and something thats focused in the data analytics, engineering or science domain. I'm very interested in learning more design patterns, but particularily what I would love is to find tutorials that teach a given design pattern but with tutorials and examples that are more align with data related domains like data engineering, data analytics or data science. A lot of the stuff I've been able to find sort of seem more angled towards building a web app for like, a company or inventory system or something, but I'm interested in learning how I could apply these patterns for building out applications that fit my day to day. I'm a data analyst (though more like BI analyst in terms of actual job functions) who's main deliverable is basically tableau dashboards and maybe other ad-hoc visualisations or reports in Jupyter. But, like many places, my infrastructure is a shitshow/joke so its just a bunch of csv files being emailed around. Would love to learn how to actually build applications that could make my life or my teams life a bit better. Like, there's only like maybe 3-4 different csv structures we get in each dashboard product we make, so sure I could bring each one in and use pandas to clean it up each and every time, but it seems like it'd be worth the effort (and more interesting frankly) to make an actual tool rather than only learning python for one-off stuff. I'd love to do a tutorial that taught some design patterns that had you build one program end-to-end along with tests and the like. I've seen some that are for like, making a to-do list, but im having trouble finding examples that are like, okay we're gonna build a small app to automate cleaning a csv, or more advanced like, building a pipeline that takes data from these databases/APIs, does some things to it, then sends it to this database. Oysters Autobio fucked around with this message at 22:21 on Mar 4, 2023 |
# ? Mar 4, 2023 22:16 |
|
I don't have suggestions for books but if you start working through one and have any questions at all feel free to ask them here
|
# ? Mar 4, 2023 23:06 |
|
“Beyond the Boring Stuff with Python” and “Practices of the Python Pro” are both great books that are about how to write good Python in general. Wes McKinney’s (creator of pandas) book is online for free too: https://wesmckinney.com/book/ Also, check out polars (the package) for data analysis. It’s a newer DataFrame library written in Rust. It isn’t a full replacement for everything pandas does, but in general, it’s comically faster. Zugzwang fucked around with this message at 23:26 on Mar 4, 2023 |
# ? Mar 4, 2023 23:13 |
|
FWIW it sounds like you're looking more for courses than books since you want like a tutorial thing. I can't recommend any in particular but Udemy has a bunch. I once had access to PluralSight through my employer and those were all pretty great too, but I wouldn't pay for it out of pocket.
|
# ? Mar 6, 2023 07:53 |
|
Thanks, yeah I think my ask is a bit too hyper specific so I'll widen my question just a bit better. Other than SA, what other social media or platforms are people using for learning python and programming in general? I've been really frustrated lately that my go to learning strategy is still opening up Google first. With Google I realized that I just keep finding the same SEO-padding blogs that actually say next to nothing in terms of actually useful tutorials. Just feels like they're all either banal generalities about why x is better than y. And because of the SEO algo, every single startup, open source project or even indie devs have to min-max social media marketing with just banal blog posts about how "LoFi-SQL is totally the best new approach. LoFi-SQL is a database approach adopted in repos like <OPs_Project>". Reddit and HN feel the same way because the useful threads are buried deep in scattered posts. Say what you want about megathreads but at least they're oriented around categories and topics. Reddit et al just feels like having to sort through endless small megathreads generated by the same repos, or on the other hand lurkers who are just trying to figure out wtf is LoFi-SQL and why it's part of the neomodern data stack. Any good subreddits, forums, bulletin boards, or hell I'll get into listserv or mailing lists or w/e but just some places where people actually discuss how they do stuff in python. Can't believe this dumb web 1.0 comedy forum has some of the best technical resources I've been able to find, so I'll take any suggestion even if it's a sub forum for New York renters that happens to have a decent tech community. Oysters Autobio fucked around with this message at 17:10 on Mar 6, 2023 |
# ? Mar 6, 2023 16:56 |
|
I did freecodecamp when it was just javascript and it was well designed, they have a bunch of other stuff now including some python courses: https://www.freecodecamp.org/learn
|
# ? Mar 6, 2023 17:00 |
|
Oysters Autobio posted:Thanks, yeah I think my ask is a bit too hyper specific so I'll widen my question just a bit better. I've also hung out in the Python discord community which seems to be pretty reasonable in terms of people asking questions and walking through stuff. For just learning algorithms / etc, I'm a fan of code kata style approaches (such as leetcode or codewars), but it sounds like those are pretty low-level compared to what you're asking about.
|
# ? Mar 6, 2023 17:14 |
|
I really like Al Sweigart’s book Automate the Boring Stuff with Python. It’s “here are the basics of Python, now here are a bunch of very useful things you can do with it.” It’s available for free at https://automatetheboringstuff.com For further education, the YouTube channel ArjanCodes is great.
|
# ? Mar 6, 2023 17:15 |
|
my #1 suggestion would be to start contributing to open source projects you're already using. 1) If it's a project you use and like, presumably the people who maintain it know a whole bunch of stuff about python you could learn 2) Having a pre-existing project to contribute to removes a lot of "where do I even begin?" blank-page syndrome 3) In addition to language-specific skills, getting better at source control and collaborative programming is useful everywhere 4) It can genuinely feel good to contribute -- you might make the world an infinitesimally better place! Oysters Autobio posted:With Google I realized that I just keep finding the same SEO-padding blogs that actually say next to nothing in terms of actually useful tutorials. this poo poo sucks so bad and it's depressing how it's never going to get better
|
# ? Mar 6, 2023 17:21 |
|
Falcon2001 posted:I've also hung out in the Python discord community which seems to be pretty reasonable in terms of people asking questions and walking through stuff. Oh hey both of these are awesome resources too, thanks for sharing. Someone should setup an open source project that assigns issue tickets and WIPs as code kata challenges that independently look random but actually combine to build a codebase, lol. Definitely very useful for reusability and practice. Zoracle Zed posted:my #1 suggestion would be to start contributing to open source projects you're already using. I've wanted to do this but feeling a bit intimidated and overly anxious (which is silly now that I say it outloud I know) about looking like an idiot when submitting a MR. Worried my Python abilities aren't "meta" enough for actually contributing it somewhere. But, you're right actually. Plus if its something I think I could use at work then it actually might be significantly easier to try and build inu a couple features I might find useful into an existing codebase rather than trying to re-make whatever edge-case and being intimidated by the whole initial setup. And yeah SEO really is sad. Like, the "dead internet" theory as a literal actual existing thing is paranoid conspiracy theory (everyone's a bot!! 🤖) but as a way to look at Google advertising-driven content its pretty much allegorical to websites creating this padded blog poo poo to game the SEO algo. I'm sure in the last few years some of these are either sped up or assisted by NLP generation of some kind. It's sadly only going to get worse I imagine. Oysters Autobio fucked around with this message at 17:52 on Mar 6, 2023 |
# ? Mar 6, 2023 17:37 |
|
Oysters Autobio posted:I've wanted to do this but feeling a bit intimidated and overly anxious (which is silly now that I say it outloud I know) about looking like an idiot when submitting a MR. Worried my Python abilities aren't "meta" enough for actually contributing it somewhere. But, you're right actually. Plus if its something I think I could use at work then it actually might be significantly easier to try and build inu a couple features I might find useful into an existing codebase rather than trying to re-make whatever edge-case and being intimidated by the whole initial setup. yeah! don't forget you can dip your toes in the water by adding or improving documentation, something that pretty much every project ever will welcome with open arms. I like to start contributing to a new project with small PRs anyway, it's nice to feel out the maintainers a bit -- how fast they respond, how detailed their feedback, how stringent they are on formatting issues, etc.
|
# ? Mar 6, 2023 17:57 |
|
|
# ? May 15, 2024 03:29 |
|
When researching and learning new areas for which I have few other sources, I like to search for "<topic> best practices" It filters out lots of article spam in favour of material with lessons drawn from experience and expertise. Could be something to consider.
|
# ? Mar 6, 2023 18:18 |