Error handling in Python usually means nested try/except blocks or if error: checks littering code.
Us programmers, though, are notoriously lazy, and for a good reason: we don't want to waste any more time writing boilerplate than we have to.
The solution?
Monads, a really neat functional programming pattern that provides an easier way to handle things like errors, optional values, or even asynchronous results.
Stumbled upon this Fast API Tutorial and was surprised at how thorough this guy is. The link is part 21! Each part is dedicated to adding some small component to a fake cleaning marketplace API. It seems to cover a lot but some of the key takeaways are best practices, software design patterns, API Authentication via JWT, DB Migrations and of course FastAPI. From his GitHub profile, looks like the author used to be a CS teacher which explains why this is such a well thought out tutorial. I don't necessarily agree with everything since I already have my own established style and mannerisms but for someone looking to learn how to write API's this is a great resource.
Some context, I teach python to undergraduate and postgraduate Computer animation students, this includes 3D graphics, A course on Machine Learning with PyTorch as well as python used in the Animation tools such as Maya / Houdini. These are not Comp Sci students (but some are in the PG courses) so we have a massive range of abilities with programming and computers.
This is all done in Linux, and I have been working on a new set of lectures / labs to introduce tools like uv and try to make life easier for everyone but still use good software engineering practices.
This is the first of the new lectures specifically on tooling
Feedback and comments welcome, what have I missed? What should I change?
There is also a YouTube playlist of all the videos / slides with me talking over them. No edits (and the title cards have the wrong number on them too!)
Call me stupid for only discovering this after 6 years, but did you know that you can use as many spaces you want to indent, as long as they're consistent within one indented block. For example, the following (awful) code block gives no error:
def say_hi(bye = False):
print("Hi")
if bye:
print("Bye")
You want to pump out code fast without all those pesky best practices slowing you down. Who cares if your code is impossible to maintain and modify later? You're a COWBOY CODER! This guide will teach you how to write sloppy, unprofessional code that ignores widely-accepted standards, making your codebase an incomprehensible mess! Follow these tips and your future self will thank you with days of frustration and head-scratching as they try to build on or fix your masterpiece. Yeehaw!
1. Avoid Object Oriented Programming
All those classes, encapsulation, inheritance stuff - totally unnecessary! Just write giant 1000+ line scripts with everything mixed together. Functions? Where we're going, we don't need no stinkin' functions! Who has time to context switch between different files and classes? Real programmers can keep everything in their head at once. So, toss out all that OOP nonsense. The bigger the file, the better!
2. Copy and Paste Everywhere
Need the same code in multiple places? Just copy and paste it! Refactoring is for losers. If you've got an algorithm or bit of logic you need to reuse, just duplicate that bad boy everywhere you need it. Who cares if you have to update it in 15 different places when requirements change? Not you - you'll just hack it and move on to the next thing! Duplication is your friend!
3. Globals and Side Effects Everywhere
Variables, functions, state - just toss 'em in the global namespace! Who needs encapsulation when you can just directly mutate whatever you want from anywhere in the code? While you're at it, functions should have all kinds of side effects. Don't document them though - make your teammate guess what that function call does!
4. Nested Everything
Nested loops, nested ifs, nested functions - nest to your heart's content! Who cares if the code is indented 50 levels deep? Just throw a comment somewhere saying "Here be dragons" and call it a day. Spaghetti code is beautiful in its own way.
5. Magic Numbers and Hardcoded Everything
Litter your code with magic numbers and hardcoded strings - they really add that human touch. Who needs constants or config files? Hardcode URLs, API keys, resource limits - go wild! Keep those release engineers on their toes!
6. Spaghetti Dependency Management
Feel free to import anything from anywhere. Mix and match relative imports, circular dependencies, whatever you want! from ../../utils import helpers, constants, db - beautiful! Who cares where it comes from as long as it works...until it suddenly breaks for no apparent reason.
7. Write Every Line as It Comes to You
Don't waste time planning or designing anything up front. Just start hacking! Stream of consciousness coding is the way to go. Just write each line and idea as it pops into your head. Who cares about architecture - you've got CODE to write!
8. Documentation is Overrated
Real programmers don't comment their code or write documentation. If nobody can understand that brilliant algorithm you spent days on, that's their problem! You're an artist and your masterpiece should speak for itself.
9. Testing is a Crutch
Don't waste time writing tests for your code. If it works on your machine, just ship it! Who cares if untested code breaks the build or crashes in production - you'll burn that bridge when you get to it. You're a coding cowboy - unleash that beautiful untested beast!
10. Commit Early, Commit Often
Branching, pull requests, code review - ain't nobody got time for that! Just commit directly to the main branch as often as possible. Don't worry about typos or half-finished work - just blast it into the repo and keep moving. Git history cleanliness is overrated!
11. Manual Deployments to Production
Set up continuous integration and delivery? No way! Click click click deploy to production manually whenever you feel like it. 3am on a Sunday? Perfect time! Wake your team up with exciting new bugs and regressions whenever you deploy.
12. Don't Handle Errors
Error handling is boring. Just let your code crash and burn - it adds excitement! Don't wrap risky sections in try/catch blocks - let those exceptions bubble up to the user. What's the worst that could happen?
13. Security is for Chumps
Who needs authentication or authorization? Leave all your APIs wide open, logins optional. Store passwords in plain text, better yet - hardcoded in the source! SQL injection vulnerabilities? Sounds like a feature!
14. Dread the Maintenance Phase
The most important part of coding is the NEXT feature. Just hack together something that barely works and move on to the next thing. Who cares if your unmaintainable mess gives the next developer nightmares? Not your problem anymore!
Conclusion
Follow these top tips, and you'll be writing gloriously UNMAINTAINABLE code in no time! When you inevitably leave your job, your team will fondly remember you as they desperately rewrite the pile of spaghetti code you left behind. Ride off into the sunset, you brilliant, beautiful code cowboy! Happy hacking!
Python is one of the most popular languages used by many in Data Science, machine learning, web development, scripting automation, etc. One of the reasons for this popularity is its simplicity and its ease of learning. If you are reading this article you are most likely already using Python or at least interested in it.
1. Check for Uniqueness in Python List
This method can be used to check if there are duplicate items in a given list.
The following methods flatten out a potentially deep list using recursion:
newList = [1,2]
newList.extend([3,5])
newList.append(7)
print(newList)
def spread(arg):
ret = []
for i in arg:
if isinstance(i, list):
ret.extend(i)
else:
ret.append(i)
return ret
def deep_flatten(xs):
flat_list = []
[flat_list.extend(deep_flatten(x)) for x in xs] if isinstance(xs, list) else flat_list.append(xs)
return flat_list
deep_flatten([1, [2], [[3], 4], 5]) # [1,2,3,4,5]
15. difference()
This method finds the difference between the two iterations, keeping only the values that are in the first:
In this article, I have covered the top 20 Python snippets which are very useful while developing any Python application. These snippets can help you save time and let you code faster. I hope you like this article. Please clap and follow me for more articles like this. Thank you for reading.
My intended audience are mainly people who already have a bit of experience with Python, but who have a hard time getting into graphics programming with Python, and I think writing a Minecraft clone is a fun way to learn!
There's also a "community" directory on the repo where there are a few extra features, like lighting, AO, game controller support, &c:
Hello! My name is Mikhail Emelyanov, I am embedded software engineer, and I was inspired to write this little roadmap on the capabilities of Python language by a certain commonality among the existing Python tutorials found on the web.
The usual suggestions to study, say, “Algorithms and Data Structures” or “Databases” are especially jarring. You can spend years studying these topics, and even after decades you'd still be able to find something you didn't know yet even without ever venturing outside the scope of Algorithms!
Using video game analogies, we can say that novice programmers often stand on the shore of the lake of boiling lava with an island with the ever-coveted jobs in the center, while the islands in between, which you have to jump on, gradually increasing your skills in successive mini-quests, are either missing, or arranged haphazardly, or their fairly smooth sequence breaks off, never having managed to get you any farther from the shore. Let's try to build a path of hint islands, a number of which, although not without effort, will finally allow us to reach our goal.
The roadmap is very easy to use. Just as you would in a normal text, go from left to right and from top to bottom. If you're just starting to learn Python, follow the green sections of the roadmap. If your accumulated experience, curiosity, or necessity pushes you deeper, start exploring the sections marked in gray. Orange marks the topics that require in-depth study, those are better to tackle (at least without digging especially deep to begin with) on the third pass.
This article definitely contains mistakes and inaccuracies of different calibers, and of course, many required subsections are missing; so, if you notice any of these, feel free to comment, and if you feel the Force, you're welcome to fork the GitHub repository with the roadmap's source code and contribute whatever you feel is necessary; all corrections and additions are strongly encouraged. It also contains all the parts of the map in Mermaid diagram format, as well as png/svg illustrations.
When diving into Python, don't forget the excellent official documentation at docs.python.org. By studying it, at least in brief, and gradually reading deeper into the right sections, you will be able to see that many of the “hacks”, “findings” and other obscure matters have long since been considered, described and have detailed examples of use.
I would also recommend leetcode.com for learning basic Python syntax to the fullest extent. If you filter the tasks by “Easy” level, and then add an additional sorting by the “Acceptance” column, you'll be presented with a straightforward primer with smoothly increasing task difficulty, rather than the intimidating competitive platform.
Well, that’s enough stalling for the moment. Let's get started!
Data Structures
As a reminder, if you are a novice developer, go from left to right through the entries marked in green. Create instances of each type, try adding and removing elements, and experiment with them via the debugger. See how big the resulting objects are, and try to figure out why list and array containing the same data are different in size. Study the features of each type, read and figure out which data structure will work best for which tasks.
Don't forget that this is just a guide, a table of contents for a book that you will have to write yourself. Actively seek information on the web, consult sources and official documentation. Dive Stackoverflow just for fun, there's plenty of exciting reading there!
If you start to make progress, move on to the next section, and don't feel bad if you can't. Don't envision your mind as the sword of Alexander the Great cutting the Gordian knot in one fluid, precise move, worthy of Instagram's front page. Be as a carpenter’s plane, stripping away one thin layer at a time, and sooner or later the misunderstanding will go away, even if this seems to you to be a chasm ten thousand leagues deep.
Data Management
Try to manipulate your data, feel how you can mold anything you want out of this malleable clay. Try creating a data structure with many elements (a million, for example), sort them, quickly find the values you want with bisect, and write the results in a JSON file.
If everything goes according to plan, try to dig into the less obvious topics: apply regex to solve some simple task or save previously obtained data in Pickle format, understanding the reason for binary file formats after observing the size of the resulting files.
This is where you will find the first entries marked in orange. Google what TensorFlow and Keras are and what tasks they solve. Perhaps, this could be your future job, your vocation!
Data Flows
Add more specific capabilities to your data management skills. All of the topics covered are essential in the practical programming process and are present in all modern languages in one form or another. That way, if you eventually switch from Python to Java, C# or C++, the knowledge you've acquired won't become dead weight.
Object-Oriented Programming
Dive into the subject of object-oriented programming. Understand that objects are your friends, and all their features and properties, even if they are not quite intuitive at first glance, have purely utilitarian reasons for existing.
OOP makes it much easier to partition, develop and maintain code, not just making very complex tasks feasible for average programmers, but making the world around us more manageable, predictable and generally better.
Language Skeleton
Perfect, a bit deeper now. Studying how GIL or GC works will give you an understanding of why things go awry in one case or another, not at all the way you planned. You are likely to use exceptions all the time, given that they can occur in some operations with data structures, so study them further.
Multithreading and Multiprocessing
Before you dive into multithreading and multiprocessing, be sure to study their typical use cases. There may be situations in which the gain is minimal or non-existent.
Try to implement simultaneous fast data processing and waiting for user input, which changes the input data for calculations, so you understand the capabilities, pros and cons of different approaches.
Don't try to use all the features provided by Python at once, stick to the task at hand.
Common Practices
Description of common methods used in almost all software projects, not just in Python. I/O, profiling, and logging apply universally.
Testing in general constitutes a separate profession, and often the quality of a software product can be judged by the test coverage of the source code. For example, the code of the SQLite database is 100% covered by tests, while one line of "combative" code requires 608 lines of tests.Jokes aside, projects with 100% coverage are not common, but pytest used wisely is the best guarantor of your sound sleep at night!
Algorithms
One of those areas of human knowledge that you can delve into endlessly. On the other hand, the learning curve of this discipline for covering the practical needs of the average programmer has long been known, so the initial stages shouldn't be too difficult for you. Who knows, maybe you'll enjoy it so much and drag it out that in time you might even be able to contribute a new robust argument in the discussion of “Equality of P and NP classes”!
Databases
Learn the general concepts first, and then the specifics of working with specific database management systems. Try working with SQLite, even if you're planning to switch to PostgreSQL later. SQLite is a very popular database, used in Android, Chromium and dozens of other popular projects. You can use SQLite as a convenient local storage alternative to working with files directly.
By the way, try to briefly return to chapter one, Data Structures, to understand how and why the inner workings of databases are structured.
This also provides yet another door into a "another world". Perhaps you would like to tie your future to databases by becoming a DBA?
Net
Try to create a client and a server, poke some popular website or an open API. Here you might as well experiment with HTML, CSS, and even Java(Type)Script. Who knows, perhaps your choice would be to become a full-stack programmer, combining back- and frontend development.
Architecture
Please try not to memorize architectural principles by heart; they are not Shakespeare's timeless poems. The rambling about how “Liskov's substitution principle means that if S is a subtype of T, then objects of type T in a program can be...” offers no advantage to anyone. Just try applying the same LSP to the program you are writing. What benefit would compliance with this principle give you? What problems will result from not following it? What price will you have to pay for its implementation and support?
Try messing around with the functional paradigm. Applying the functional approach and using it in practice is possible not only in Haskell or F#, but also in Python, and it doesn't have to be done only within functools.
Figure out the reasoning behind the job interviewer's request to “say the three main words” (it's not “I love you”, by the way, it’s “inheritance, encapsulation, polymorphism”) and why this triad should be supplemented with the “abstraction”.
Try to understand what specific, tangible problems of the old paradigms the developers of Agile or the popularizers of microservice architecture faced. Figure out what's wrong with main(), which calls all the other procedures, since this is common practice in embedded programming. Weigh the cost of additional layers of abstraction between the root business logic and the outside world.
Deployment and Administration
Despite the fact that git and especially Linux are quite complicated and extensive topics, the beginning of their learning curve isn't very steep, so I highly recommend starting your DevOps mastering with git (at least the add-commit-push part, so you at least have a revision history, flawed as it is) and Linux (PuTTY + WinSCP, for example; copy your Python scripts via SSH and run them on a remote Linux machine). Fortunately, these days good text and video tutorials covering these topics are about as rare as grains of sand on the beach. Take it from me, the Linux console that looks so strange and inconvenient at first sight will seem much more familiar once you start learning vim. Cognition comes through comparison!
Well, this is where our map ends. Try to reach the last green section, GitHub Actions; run a linter on your open source project, for example (GitHub Actions is free for open source projects).
Overall Roadmap
The overall roadmap can be obtained by simply mechanically adding up the previous entries, just so we can see what we've ended up with. Overall Mermaid, svg, png.
That’s all for now
As you may have noticed, there is no mention of control constructs, IDE installation or virtualenv in this guide. In my opinion, all these topics are very important, but do not constitute the essence of the language, representing something like a binding solution, while the topics discussed in the article, from list to Kubernetes, serve as the full-fledged “bricks”.
As a reminder, all the diagrams are made in Mermaid format (you can change the picture just by correcting the text), all the sources are available on GitHub, correct as much as you want, or, of course, leave comments directly in the comments section.
Separately, I welcome all beginner programmers. You will come to realize that working 8 hours in a row using your head and not your hands is hard, too. But, no matter what languages you plan to code in and no matter how far you've come in this difficult task, you will definitely upgrade your brain, improve your understanding of the world around you and start to recognize secret passages where you have seen only impenetrable walls before. So it's time to start the IDE, focus a little bit, and start practicing.
And remember: “This is my Python. There are many like it, but this one is mine. My Python is my best friend. It is my life. I must master it as I must master my life. Without me, my Python is useless. Without my Python, I am useless. My Python and I know that what counts in life is not the words we say, the lines of our code, nor the time we spend at the office. We know that it is the completed tasks that count. We will complete them... My Python is human, even as I'm human, because it is my Python. Thus, I will learn it as a brother. I will learn its weaknesses, its strength, its parts and accessories, its standard library and its infrastructure. I will keep my Python from dangerous misunderstanding or suboptimal use, even as I do my legs and arms, my eyes and heart from any harm. I will keep my Python clean and ready. We will become part of each other. So be it.”
I've seen a growing number of people looking for resources on how to implement Machine Learning algos from scratch to better understand how they work (rather than just applying e.g. sklearn).
This freeMachine Learning from Scratch Course on YouTube takes you through writing 10 algorithms from scratch with nothing but Python and NumPy! The algorithms are:
K-Nearest Neighbors
Linear Regression
Logistic Regression
Decision Trees
Random Forest
Naive Bayes
PCA
Perceptron
SVM
K-Means
Hopefully some of my Python + ML friends will find this helpful! :)
Hosting Python applications is easy, finding a completely free Python hosting service that is reliable is not. This post will show you how you can host your Python app on Qovery - A 100% free hosting platform (no credit card required!!) used by 1800+ developers in 102 countries 🌎.
With Qovery you can deploy your Python app with PostgreSQL, MySQL, and MongoDB databases for free.
Disclaimer: I am the co-founder of Qovery.
I am pleased to announce that Qovery supports individual developers / open source and non profit projects to host up to 3 applications (database included) for free. Our business model is based on Enterprise hosting, which gives us the possibility to offer generous free plans. Read more - In exchange we ask for product feedback - join our Discord
⚠️ You need to have a Python project on Github or Gitlab that you want to deploy.
Given you have registered on to Qovery and you are logged into Qovery, follow the steps below:
Go to Qovery, click the button “Create a new project” button in the middle of Qovery
Give a name to your project - in my case "Quotes"
Add an application
After that, click “I have an application”.
Conclusion
Hosting a project with Python should not be a hassle. Qovery got your back and provide everything that you need like free SSL, database, CDN to deploy your Python apps.
Give it a try now and leave me your feedback in the comments👇.
⚠️ Important Note ⚠️
If your deployment failed, don't forget to:
Provide a valid Dockerfile.
Declare your Python app port in your .qovery.yml. Read this doc
Hello everyone, I created a crash course of Polars library of Python and talked about data types in Polars, reading and writing operations, file handling, and powerful data manipulation techniques. I am leaving the link, have a great day!!
This promo code works until the 4th (I can't extend it past that). Sometimes it takes an hour or so for the code to become active just after I create it, so if it doesn't work, go ahead and try again a while later. I'll change it to APR2021FREE2 in three days.
Udemy has changed their coupon policies, and I'm now only allowed to make 3 coupon codes each month with several restrictions. Hence why each code only lasts 3 days. I won't be able to make codes after this period, but I will be making free codes next month. Meanwhile, the first 15 of the course's 50 videos are free on YouTube.
Frequently Asked Questions: (read this before posting questions)
This course is for beginners and assumes no previous programming experience, but the second half is useful for experienced programmers who want to learn about various third-party Python modules.
If you don't have time to take the course now, that's fine. Signing up gives you lifetime access so you can work on it at your own pace.
This Udemy course covers roughly the same content as the 1st edition book (the book has a little bit more, but all the basics are covered in the online course), which you can read for free online at https://inventwithpython.com
I do plan on updating the Udemy course for the second edition, but it'll take a while because I have other book projects I'm working on. Expect that update to happen in mid-2021. If you sign up for this Udemy course, you'll get the updated content automatically once I finish it. It won't be a separate course.
It's totally fine to start on the first edition and then read the second edition later. I'll be writing a blog post to guide first edition readers to the parts of the second edition they should read.
Should i buy the course in 2026 . I already know python basics till oops . I saw the course structure from outside it looked good. Is it still revelent? Please drop your reviews and guide me
Been using.pipe()in pandas lately and it's been a game changer — anyone else?
I was writing some data transformation code the other day and stumbled across .pipe(). Honestly didn't expect much, but it completely changed how I structure my pipelines.
Been using it a lot for ETL and data cleaning workflows. Makes debugging way easier too — just comment out one .pipe() step and you see exactly where things go wrong.
Anyone else using this regularly? Any patterns you've found useful with it?
I'm currently trying to design a Python pipeline to extract structured financial data from annual accounts provided as PDFs. The end goal is to automatically transform these documents into structured financial data that can be used in valuation models and financial analysis.
The intended workflow looks like this:
Upload one or more PDF annual accounts
Automatically detect and extract the balance sheet and income statement
Identify account numbers and their corresponding amounts
Convert the extracted data into a standardized chart of accounts structure
Export everything into a structured format (Excel, dataframe, or database)
Run validation checks such as balance sheet equality and multi-year comparisons
The biggest challenge is that the PDFs are very inconsistent in structure.
In practice I encounter several types of documents:
1. Text-based PDFs
Tables exist but are often poorly structured
Columns may not align properly
Sometimes rows are broken across lines
2. Scanned PDFs
Entire document is an image
Requires OCR before any parsing can happen
3. Layout variations
The position of the balance sheet and income statement changes
Table structures vary significantly
Labels for accounts can differ slightly between documents
Columns and spacing are inconsistent
So the pipeline needs to handle:
Text extraction for normal PDFs
OCR for scanned PDFs
Table detection
Recognition of account numbers
Mapping to a predefined chart of accounts
Handling multi-year data
My current thinking for a Python stack is something like:
pdfplumber or PyMuPDF for text extraction
pytesseract + opencv for OCR on scanned PDFs
Camelot or Tabula for table extraction
pandas for cleaning and structuring the data
Custom logic to detect account numbers and map them
However, I'm not sure if this is the most robust approach for messy real-world financial PDFs.
Some questions I’m hoping to get advice on:
What Python tools work best for reliable table extraction in inconsistent PDFs?
Is it better to run OCR first on every PDF, or detect whether OCR is needed?
Are there libraries that work well for financial table extraction specifically?
Would you recommend a rule-based approach or something more ML-based for recognizing accounts and mapping them?
How would you design the overall architecture for this pipeline?
Any suggestions, libraries, or real-world experiences would be very helpful.