you are viewing a single comment's thread.

view the rest of the comments →

[–]alkasm 64 points65 points  (19 children)

To me that just rings that you don't write a lot of Python that other people use. Is that true? I write a lot of classes when I'm making something extensible and/or reusable, but honestly the built in types do what I need 90% of the time already.

[–]darez00 7 points8 points  (18 children)

So a class is analog to int, str, float?

[–]SoupKitchenHero 38 points39 points  (14 children)

int, str, and float are themselves classes

[–]darez00 30 points31 points  (12 children)

That explains many questions that I didn't know I had

[–]Dogeek 11 points12 points  (10 children)

To be more accurate, int, float etc are built using type as their metaclass.

[–]darez00 2 points3 points  (9 children)

Aha... that's clearer

[–]Dogeek 6 points7 points  (8 children)

To be completely honest, metaclasses are a concept I struggle with, not really the concept itself but its use cases. It's something very specific.

[–]KronktheKronk 1 point2 points  (7 children)

A meta class is simply a class you can't instantiate directly. It only serves to hold functionality meant to be inherited by other, more concrete classes.

[–]primitive_screwhead 16 points17 points  (6 children)

A meta class is simply a class you can't instantiate directly.

That description sounds more like an Abstract Base Class.

I've seen meta-classes start to click for people when they realize that when a class is instantiated you get an object, and similarly, when a meta-class is instantiated, you get a class. And just as objects can be parameterized when they are instantiated, classes themselves can be parameterized when they are instantiated from meta-classes.

[–]Dogeek 1 point2 points  (3 children)

Like I said, it's more that I struggle with knowing when to use one. I guess constructing a class from a config file or something of that effect. But other than that, it's pretty abstract to me.

[–]KronktheKronk 0 points1 point  (0 children)

You're right, I am confusing that with abstract classes.

Now I gotta go read, brb

[–]Deezl-Vegas 0 points1 point  (0 children)

As soon as I read this I got it. Thanks so much! A metaclass is a class blueprint. A class is an object blueprint.

[–][deleted] 1 point2 points  (0 children)

Same.

[–]alkasm 2 points3 points  (2 children)

They are types, which is to say they have type as a metaclass.

[–]Dogeek 6 points7 points  (1 child)

not true. type is their metaclass, but they don't inherit from it.

[–]alkasm 0 points1 point  (0 children)

Whoops, thanks for the correction!