pep

Cartopy python Package (PEP 517) wheel building

Cartopy python Package (PEP 517) wheel building Question: I am trying to make a program with tropycal but it shows a wheel building error for a package dependency. Called Cartopy. Pip3 Error: ERROR: Could not build wheels for cartopy which use PEP 517 and cannot be installed directly. I tried a solution from another StackOverflow …

Total answers: 2

Why is my function not working in vscode when it works in jupyternote book?

Why is my function not working in vscode when it works in jupyternote book? Question: I am new to python and have recently started to study it full-time. I have been using vscode to type out my code I would run the script and it would show my output in the terminal window. However, I …

Total answers: 2

Zen of Python 'Explicit is better than implicit'

Zen of Python 'Explicit is better than implicit' Question: I’m not sure if this is an opinionated question or if it is me misunderstanding what ‘implicit’ and ‘explicit’ really means in the context of Python. a = [] # my understanding is that this is implicit if not a: print("list is empty") # my understanding …

Total answers: 3

Data Classes vs typing.NamedTuple primary use cases

Data Classes vs typing.NamedTuple primary use cases Question: Long story short PEP-557 introduced data classes into Python standard library, that basically can fill the same role as collections.namedtuple and typing.NamedTuple. And now I’m wondering how to separate the use cases in which namedtuple is still a better solution. Data classes advantages over NamedTuple Of course, …

Total answers: 6

How to annotate variadic parameters in Python using typing annotations?

How to annotate variadic parameters in Python using typing annotations? Question: How to annotate parameters of the variadic function? Example: def foo(*args): # Each arg expected to be of type T … Are there any typing annotations for that? Asked By: kuza || Source Answers: tl;dr Basically args treated as a homogeneous tuple and kwds …

Total answers: 2

proper formatting of python multiline [ for in ] statement

proper formatting of python multiline [ for in ] statement Question: How should i format a long for in statement in python ? for param_one, param_two, param_three, param_four, param_five in get_params(some_stuff_here, and_another stuff): I have found that i can brake a for in statement only with a backslash : for param_one, param_two, param_three, param_four, param_five …

Total answers: 2

E731 do not assign a lambda expression, use a def

E731 do not assign a lambda expression, use a def Question: I get this pep8 warning whenever I use lambda expressions. Are lambda expressions not recommended? If not why? Asked By: Kechit Goyal || Source Answers: The recommendation in PEP-8 you are running into is: Always use a def statement instead of an assignment statement …

Total answers: 5

Python PEP: blank line after function definition?

Python PEP: blank line after function definition? Question: I can’t find any PEP reference to this detail. There has to be a blank line after function definition? Should I do this: def hello_function(): return ‘hello’ or shoud I do this: def hello_function(): return ‘hello’ The same question applies when docstrings are used: this: def hello_function(): …

Total answers: 4

Triple-double quote v.s. Double quote

Triple-double quote v.s. Double quote Question: What is the preferred way to write Python doc string? """ or " In the book Dive Into Python, the author provides the following example: def buildConnectionString(params): """Build a connection string from a dictionary of parameters. Returns string.""" In another chapter, the author provides another example: def stripnulls(data): "strip …

Total answers: 4