I come from Java, and I want to do some data transfer objects (DTOs) like this:
class ErrorDefinition():
code = ''
message = ''
exception = ''
class ResponseDTO():
sucess = True
errors = list() # How do I say it that it is directly of the ErrorDefinition() type, to not import it every time that I'm going to append an error definition?
Or is there a better way to do this?
Lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
A list can be defined as a collection of values or items of different types. The items in the list are separated with the comma (,) and enclosed with the square brackets [].
List is a collection data type. It allows multiple values to be stored within the same field.
The type() function is used to get the type of an object. Python type() function syntax is: type(object) type(name, bases, dict)
You can type a list as python 3.8.4
https://docs.python.org/3/library/typing.html
from typing import List
vector:List[float] = list()
or
from typing import List
vector:List[float] = []
Python is dynamically typed however https://www.python.org/dev/peps/pep-0484/ Typing makes it easier to read code, easier understand it, make efficient use of your IDE tooling and create higher quality software. I guess that's why it's in the PEP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With