What are your favorite extensions for VSCODE that make coding in Python easier?
Python extension methods - Stack Overflow
A look into workflow tools - package management in the Python extension for VS Code - Packaging - Discussions on Python.org
VS Code Extensions for Python
Videos
I just learned about autoDocstring last night and I'm blown away how nice this extension is. It makes creating docstrings so much easier and automated. Personally, I'm a fan of Google's style for docstrings so that's what I've set my default to when generating docstrings!
Another favorite extension of mine is this linter: Ruff. However, it is a bit buggy in that it duplicates functions at the bottom of the file, but other than that I love it!
Lastly, this is not an extension, but I love the Black library and auto-saving my .py files with this formatting provider in VSCODE.
I'm curious what this communities' favorite extensions are that make coding in Python easier or automated?
You can just modify the class directly, sometimes known as monkey patching.
def MyMethod(self):
return self + self
MyClass.MyMethod = MyMethod
del(MyMethod)#clean up namespace
I'm not 100% sure you can do this on a special class like str, but it's fine for your user-defined classes.
Update
You confirm in a comment my suspicion that this is not possible for a builtin like str. In which case I believe there is no analogue to C# extension methods for such classes.
Finally, the convenience of these methods, in both C# and Python, comes with an associated risk. Using these techniques can make code more complex to understand and maintain.
I would use the Adapter pattern here. So, let's say we have a Person class and in one specific place we would like to add some health-related methods.
from dataclasses import dataclass
@dataclass
class Person:
name: str
height: float # in meters
mass: float # in kg
class PersonMedicalAdapter:
person: Person
def __init__(self, person: Person):
self.person = person
def __getattr__(self, item):
return getattr(self.person, item)
def get_body_mass_index(self) -> float:
return self.person.mass / self.person.height ** 2
if __name__ == '__main__':
person = Person('John', height=1.7, mass=76)
person_adapter = PersonMedicalAdapter(person)
print(person_adapter.name) # Call to Person object field
print(person_adapter.get_body_mass_index()) # Call to wrapper object method
I consider it to be an easy-to-read, yet flexible and pythonic solution.
Hi everyone, can you share some of the VS Code extensions you use to improve your coding experience? I know the most common extensions, like Prettier, BetterComments and SpellChecker, but I'm sure there are some hidden gems out there, hope you can help me find some! Thank you all
» pip install extensions