You are on page 1of 12

Open in app

Get unlimited access to all of Medium for less than $1/week. Become a member

25 signs of an experienced Python developer


Amit Singh Rathore · Follow
Published in Dev Genius
4 min read · Feb 3

Listen Share More

Practices that make a good python developer

This is Part I, click here for Part II

1. Using a virtual environment: This shows that you isolate environments to avoid
issues with dependencies and package versions. Also if we stick to requirements
& constraints files, it shows that we care about how the app should be run in
another place.
pip install -r requirements.txt -c constraints.txt

2. Using type hints: Type hints make our code more readable. This helps with ease
of maintenance and also debugging.
def demo(x: type_x, y: type_y, z: type_z= 100) -> type_return :

3. Proper exception handling: Catching specific exceptions makes it easy to


understand what went wrong in our code. Bare except clause catches all the
exceptions, including SystemExit and KeyboardInterrupt. But both are not the
same and should be handled differently.

4. Using Context managers: This helps in resource management and avoids


dangling connections or file handles.
with open("demo.txt", mode="w") as file:

5. Using if __name__ == “main” : This avoids unnecessary objects while doing


imports of the script.
6. Using comprehension: Comprehension makes code less verbose and efficient.
another_list = [ x for item in iterable]

7. Enumerate: Manually handling indexes when we don’t need conditional


skipping of elements enumerate is easy to work and faster.
for idx, num in enumerate(nums)

8. Using zip (itertools): While working with multiple list zip method simplifies the
iteration and items are available straight out of the box.
for item1, item2 in zip(list1, list2) . Zip is only indicative, knowing other
functions from itertools gives an idea that the coder is aware of tools that
simplify the process.

9. Proper indentation: Following a consistent indentation (four spaces) helps in


readability. Also, it makes life easier if the script is being read from text editors
or file io streams.

10. Using else with for & while: This is the pythonic way of telling that all items
were processed in their natural course.

11. Using the in keyword to check membership in Dictionary keys.


if key in my_dict:

12. Using the items method when working with dictionaries: This is a more
pythonic way of accessing the key and item rather than looping over keys and
then accessing value with get or subscript.
for key, val in my_dict.items()

13. Using dict.get() method: This avoids error when the key is not present and
also allows us to return a default value when the key is not present.

14. Using the isinstance keyword when doing type equality of objects: Comparing
object type with will give wrong results in case of inherited objects.

15. Using is for equality with singleton: Using is to check None, True & False . The
is operator checks if the two items reference the same object (i.e. present in
the same memory location). The == operator checks for value equality.

16. Using the “or”, “and”, “not” keyword when working with Boolean values: This
helps in deciding the correct flow of operations. Also using and over or helps in
the early breaking of code where we have too many false compared to true. In
OR, conditions are checked till it keep encountering false, moment it receives a
true it break, in AND as soon as the false condition is met the rest condition are
not checked. Note: If you need to be sure of all conditions evaluate to true or any
one is true you can use any and all function over iterable list of boolean
values.

17. Using generators: Generators save memory and improve performance.


(expression for item in iterable)

18. Using functional programming techniques (like map, reduce, and filter): This
makes code efficient.
squared = map(lambda x : x*x, [1, 2, 3]) This is faster than running a for loop.
Also map loads each item one by one, unlike for loop which loads all items in
memory, this makes it more memory efficient. Although we should prefer
generator as far as possible.

19. Using Decorators: This helps in writing reusable code. Decorators like @retry

@properties @lru_cache etc help in extending the functionality of code. There are
frameworks like Flask which has @route decorator. Airflow has @task operator.

20. Using the right built-in libraries: Using the right built-in packages can reduce a
lot of boilerplate code. Also since specific packages are efficient at doing thing
specific tasks. It makes sense to use the right packages. E.g. os vs pathlib &
os.system vs subprocess .

21. Using correct naming conventions: The PEP-8 is a popular guideline among
Python programmers, which tells us how to name our variables, classes, and
functions properly.

22. Sticking to a style guide: Sticking to your chosen rules makes refactoring
moments like a breeze and its easier to understand later on.

23. Using Docstring and comment: Docstring help in making user understand what
the function/module intends to do. Its input, output, and their types, sample
values. Also, it helps if we put single-line comments before and expression of
what it signifies.

24. Iterable Unpacking: first, second, third = [ ‘first’, ‘second’ , ‘third’]


25. Using logging instead of print: Logging allows us to have consistent messages
and it also allows us to suppress/filter messages by setting the correct log level.

Python Programming

More from the list: "Reading list"


Curated by Poojith Talla

Bex… in Towards Data Sci…

130 ML Tricks And


Resources Curated…
· 48 min read · Jul 31

View list

Follow

Written by Amit Singh Rathore


2.5K Followers · Writer for Dev Genius

Staff Data Engineer @ Visa — Writes about Cloud | Big Data | ML

More from Amit Singh Rathore and Dev Genius


Amit Singh Rathore in Dev Genius

PySpark Styleguide
Common practices to make PySpark code elegant

3 min read · Aug 9

48 1

P. Rehan in Dev Genius

Become An Expert: Backend Projects That Define Senior Developers


Moving from being a mid-level developer to a senior-level developer is like leveling up in a
video game.

5 min read · Jul 27

770 3

Apache SeaTunnel in Dev Genius

ELT is dead, and EtLT will be the end of modern data processing
architecture
When talking about data processing, people often abbreviate it as “ETL.” However, if we look
closely, data processing has undergone several…

11 min read · Jul 27

344 4
Amit Singh Rathore in Dev Genius

SQL & PySpark Mapping


Equivalent commands in PySpark for common SQL statements

5 min read · Aug 7

75

See all from Amit Singh Rathore

See all from Dev Genius

Recommended from Medium


Anthony D. Mays

How to Practice LeetCode Problems (The Right Way)


tl;dr: You’re doing it wrong. Use “The Six Steps” any time you practice LeetCode questions,
preferably with another person. Keep an…

· 13 min read · May 10, 2022

1.2K 9

Evenword
Creating a Machine Learning Based Web Application Using Django
Deploy your Machine Learning model on the web using Python’s famous Django framework
and increase its visibility.

8 min read · Feb 21

124 3

Lists

Coding & Development


11 stories · 102 saves

General Coding Knowledge


20 stories · 210 saves

It's never too late or early to start something


13 stories · 71 saves

ChatGPT
21 stories · 109 saves

Shubhadeep Chattopadhyay

Best practices for Clean Code


Clean code is a set of programming practices that emphasize the readability, maintainability,
and simplicity of code. Writing clean code is…

7 min read · Mar 3

784 23

Kimberly Shyu in Modern Women

Female STEM Leaders: Persevere


Stand your ground. Catalyze frustration into a powerful move for your team. Forgive, but do not
forget. The world needs you.

· 4 min read · Jul 28

1.3K 32
Denat Hoxha

Sharing Data Between Microservices


Robust distributed systems embrace eventual consistency to share data between their
services.

7 min read · Oct 24, 2022

1.1K 25

Tiexin Guo in 4th Coffee


10 New DevOps Tools to Watch in 2023
With less than two months left in 2022, today, I’d like to look at some new (relatively) DevOps
tools we might want to follow in 2023.

· 9 min read · Nov 2, 2022

1.3K 24

See more recommendations

You might also like