How to maintain legacy Python codebases?
Skills:
Python for Data60%
Key Takeaways
Maintaining legacy Python codebases using strategies such as keeping the code on life support or upgrading to a newer version of Python, utilizing tools like virtual machines and linters
Full Transcript
how can you maintain a legacy Python code basis great question by a reader in this video I'm gonna give some thoughts around the topic so let's define what a legacy Python code base is so generally when people refer to legacy code they mean code that has aged a little bit you know we're talking about an older code base maybe this is some code written in python 2.5 2.6 Python 2 in general or maybe it's you know it's even older it's a system that's kind of hobbling along on Python 1 and it's never been upgraded to the latest version of the language and so now you've been assigned the task to maintain a code base like that in general I think you have two choices there either keep it on life support keep it running as is don't upgrade to a newer version of Python or option 2 you're gonna upgraded to a newer version of Python your going to take the code you're gonna make some refactoring and you're gonna make it work you're gonna take the existing code base and gonna make it work on a more recent version of Python or on the latest version of Python even so these are kind of the two options that you have really right and there are a couple of strategies you can you can apply to to each of them so if you want to maintain the existing code base which in a lot of cases will make the most sense or will make a lot of sense like generally it is very hard to rewrite an existing code base without introducing bugs and so upgrading a Python one code base to Python 3 if it's a lot of code that could be a very very stressful a very very tough project not saying it doesn't make sense but it is often very hard to make a real good business case for doing that you know if you're asking me like what would I do as a sort of idealistic developer totally I would upgrade it and rewrite it in Python 3 and make it super nice and you know add linters and everything but sometimes that is not the smartest business decision you know if this thing generates value maybe you don't want to touch it when you want to focus on something else or your employer wants you to focus on something else so you know if you have to maintain a legacy code base then that's that's just a reality of it and you can do some things to make your life a little bit easier if you're maintaining a legacy Python code base so maybe you can package the whole thing up into virtual machines or at least you don't have to worry about future OS updates breaking your application you know maybe maybe you can do things like that that basically seal this thing off and kind of preserve it and keep it hobbling along and hopefully you don't have to make too many changes to it now if you're going the other route and you want to take an existing code base and upgrade it to the latest version of Python then that's an entirely different game right then you're likely rewriting at least parts of the application to make it work with newer versions of Python you don't always have to go all the way and let's say upgrade from from python 2.2 to python 3.7 or 3.6 whatever the latest version is at the time sometimes it can just make sense to go to the latest version of python 2 for example you know it's a lot more work to go from python 2.2 to python 3 compared to going from python 2.2 to python 2.7 and python 2 is going to be around for a long time so if you're on 2.7 then you know that gives you some more mileage out of the existing code base without having to make more drastic changes and really those I think are the two main options that you have for maintaining a legacy Python code base either keep it around make it bearable or upgraded to the latest version or a newer version of Python all right I hope this was helpful if you've got any tips to share and how to work with legacy Python code bases then please leave a comment below if you've got a request for a video that you'll like me to make on Python or Safa development in future and please also leave a comment and I'll try and cover that in a future video all right thanks so much for listening and happy Python eek
Original Description
https://dbader.org/python-tricks ► Use these new Python features to modernize your code base
Question from a newsletter member: "How to maintain legacy Python codebases?" In this video I'll lay out two strategies you can use when working with legacy code (Python 1.x, Python 2.x).
Got another question? Leave a comment with your Python or general software dev question on this video and I'll try to cover it question in one of the next "#PythonQ&A" videos.
FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery
SUBSCRIBE TO THIS CHANNEL: https://dbader.org/youtube
* * *
► Python Developer MUGS, T-SHIRTS & MORE: https://nerdlettering.com
► PythonistaCafe – A peer-to-peer learning community for Python developers: https://www.pythonistacafe.com
FREE Python Coding Tutorials & News:
» Python Tutorials: https://dbader.org
» Python News on Twitter: https://twitter.com/@dbader_org
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Real Python · Real Python · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A better Python REPL – bpython vs python interpreter
Real Python
Introducing large-type.com – A Utility Website
Real Python
Reading Hacker News Without Wasting Tons of Time
Real Python
Forward References and Python 3 Type Hints
Real Python
Using Sublime Text as your Git Editor
Real Python
Python Code Linting and Auto-Complete for Sublime Text
Real Python
Make your Python Code More Readable with Custom Exceptions
Real Python
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
How to Use Sublime Text from the Command Line
Real Python
Rename Variables with Multiple Selection in Sublime Text
Real Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
Sublime Text Whitespace Settings for Python Development
Real Python
Function Argument Unpacking in Python
Real Python
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
Using "get()" to Return a Default Value from a Python Dict
Real Python
A Python Shorthand for Swapping Two Variables
Real Python
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
Setting up Sublime Text for Python Developers
Real Python
Sublime Text + Python Guide Overview
Real Python
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
Type-Checking Python Programs With Type Hints and mypy
Real Python
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
My Python Code Looks Ugly and Confusing – Help!
Real Python
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
Programmer Portfolio – Example and Walkthrough
Real Python
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
How to Build Your Public Speaking Skills as a Developer
Real Python
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
Cool New Features in Python 3.6
Real Python
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
Emulating switch/case Statements in Python with Dictionaries
Real Python
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
A Crazy Python Dictionary Expression ?!
Real Python
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
Optional Arguments in Python With *args and **kwargs
Real Python
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
Installing Python Packages with pip and virtualenv / venv
Real Python
"For Each" Loops in Python with enumerate() and range()
Real Python
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
Python Tutorial: List Comprehensions Step-By-Step
Real Python
Leveraging Python's Implicit "return None" Statements
Real Python
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
Writing automated tests for Python command-line apps and scripts
Real Python
How to find great Python packages on PyPI, the Python Package Repository
Real Python
Immutable vs Mutable Objects in Python
Real Python
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
My Experience at PyCon 2017 in Portland
Real Python
Pylint Tutorial – How to Write Clean Python
Real Python
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python
More on: Python for Data
View skill →
🎓
Tutor Explanation
DeepCamp AI