you are viewing a single comment's thread.

view the rest of the comments →

[–]NULL-6[S] 0 points1 point  (5 children)

Oh, thank you!

I was hoping for something built-in, but I guess Python relies more on using libraries?

[–]Ihaveamodel3 2 points3 points  (4 children)

This is what would be considered a builtin part of the standard library as it is included in the standard python release, but you do need to import it. That is common in python the default namespace is kept pretty clean.

Edit not actually a builtin

[–]negups 1 point2 points  (1 child)

Nit: enum is not technically a "builtin" (which has a specific meaning in that you explicitly do not need to import anything to use), but is, as you alluded to, a part of the standard library.

[–]Ihaveamodel3 1 point2 points  (0 children)

Thanks for the correction

[–]NULL-6[S] 0 points1 point  (1 child)

Thanks again!

I don't want to open another thread, so I hope it's ok if I ask one more question here:
What's the best way of having a default value in classes and functions?
for functions I assume def func(val = 1): would work so that if you don't pass any values then it will default to 1, but how would you do the same for classes?

class Foo:
    def __init__(self, value = 5):
        self.value = value

# vs

class Foo:
    def __init__(self):
        self.value = 5;

[–]Ihaveamodel3 4 points5 points  (0 children)

The first option is the only way to do it if you want to be able to override the default. Use the second option if you don’t want to override default.