I watched a YouTube video the other day along the lines of off “10 things Python beginners do they shouldn’t.” I was guilty of most of them!
I think I’ve got the basics down, I understand the built-in syntax, flow, and can work with imported modules and create my own classes but where do I go to learn more of these advanced things I hear on YouTube: generators, lambda functions, asyncio, etc.
Most of the resources I’ve googled are geared at data science and computation, but I’m coding with things like personal data (e.g. about to try making graphs from fitness records) and maker-style electronics projects like we see here.
TLDR; I want to understand some more advanced Python features, and make my code more elegant, “Pythonic” and efficient.
I stumble across most of these features through necessity from project to project, for standout methods I like to write them down so I don’t forget - also I tend to spot them a lot in reverse engineering other people’s code and in other forums/projects such as StackOverflow and occasionally places like W3Schools (Other peoples code is amazing for learning, I’ve ethically acquired a few techniques from @James46717 over the years )
If something does interest you usually there are tutorials around, some better than others - Core, Digikey, Adafruit, Unexpected Maker have some amazing ones that I watch for revision.
And as always if you have questions feel free to pop a post up the forum asking for a hand
On the flip side some of the more ‘advanced’ features can obscurify the workings of a bit of code…
For example this function inside of the HomeStation code…
def sensDict2Vals(self,sensorDict):
sensOut = {}
for i,j in sensorDict.items():
if callable(j):
sensOut[i]=j()
elif type(j) == type([]):
sensOut[i] = sensorDict.get('.'+j[0])()[j[1]]
return sensOut
Very abstracted and not very pythonic but memory efficient for Micropython’s sake.
I haven’t used it for python but I agree with @Liam120347’s recommendation of using W3schools resources. Personally, I find them to be the right balance of complexity for learners but also have great reference documentation if you need to know the best practice.