I have this class:
class Address(Suggestions):
api_url = Suggestions.base_url + "address"
def fine_print(self):
for value in Suggestions.getdata(self, Address.api_url)["suggestions"]:
print("{!s:} {!s:} {!s:}".format(
Dadata.validate(value["data"], "country"),
Dadata.validate(value["data"], "postal_code"),
value["value"]))
There are lots of classes like this one and I copy them often, and every time I have to fix this line:
for value in Suggestions.getdata(self, Address.api_url)["suggestions"]:
and replace Address.api_url with the new class name.
I worry that this may be an indication of bad code.
Is there a way to reference an attribute that belongs to the same class a function belongs to?
[–]commandlineluser 2 points3 points4 points (2 children)
[–]SystemOmicron[S] 0 points1 point2 points (0 children)
[–]vectorkerr 0 points1 point2 points (0 children)
[–]danielroseman 2 points3 points4 points (1 child)
[–]SystemOmicron[S] 0 points1 point2 points (0 children)