Let's Learn Python #17 - Type Class Creation, Metaclass

preview_player
Показать описание
This week, I cover how to create classes using the Type method and the Metaclass.

Please leave me a comment or question below! Like and Subscribe to show your support! :D

=========================================

Music by Juto: Link Coming Soon!

=========================================
--- SUPER TUTORIAL LIST!!! ---

PLAYLISTS

=========================================
Рекомендации по теме
Комментарии
Автор

cls refers to the class we are passing in, i believe.

I'm glad to hear you are using other sources as well! Always a good practice!

Anchor_Rainbow
Автор

I love these tutorials, they are helping me a lot. I do however wish that you would show some more "real world" applications for some of these things instead of just creating and printing out simple words. Other than that LOVE THESE :)

BradleyCarls
Автор

Ever since #14 I've started getting confused and disheartened in learning through these videos.

I felt like I understood clearly the reasoning behind everything you were typing up until this point - I was able to apply it to my own programs!

From lesson #15 you have started suddenly pulling these __***___ phrases out of nowhere (unless I overlooked you explaining it) and using things like 'super' and I think that's where I've gotten lost.

I no longer can see how I can apply these myself. I've continued on by just listening to #15-17 in the hopes that it all tied together and I would see the connection but I'm more confused by each ep.

Is it a case of powering through? because #24 with UI creation sounds brilliant but everything from #15-23 sounds daunting.

I'm just curious if any other absolute beginners are in the same boat as myself?

EDIT: ...and apologies that it's such a negative comment - from #1-14 you have been an incredible teacher!

MarkAlterBridge
Автор

I'm glad I could help you, it's all you though! Keep up the great work! :)

Anchor_Rainbow
Автор

In 4:55 you say that those two ways of creating x are the same, but their results are actually quite different.
The first one creates x as an instance variable (x resides in the __dict__ of an instance).
The second one creates x as a class variable (x resides in the __dict__ of the class).

rnelert
Автор

These are REALLY helping me. you should get tons of more views. thank you tons :D

WhatsRagePlaying
Автор

Just wanted to point out that `MyClass` is not quite equivalent to `TypeClass` (@ 5:27). In `MyClass`, x is an instance variable (only exists in an object once the class is instantiated), while for TypeClass x is a class attribute (available on the class without instantiation).

omgdd
Автор

Thank you!! This is so helpful for my programming class this semester!

zowlambda
Автор

I'm a bit confused as to what Super in Singleton is calling... What is it calling exactly?
also the first arguement of super is Singleton as MyClass is of type Singleton right?

notia
Автор

Thank you very much.  BUtI am a little bit confused here.
So the metaclass is the weird to inherit from  other class?

hjyssg
Автор

Hi. I'm getting the same error that a few others that are commenting here are getting:
File "C:/Python34/Python Testing/SingletonMetaClassExample.py", line 13, in <module>
    print(m.x)
AttributeError: 'MyClass' object has no attribute 'x'

Do you know why, or what I need to do differently to keep this error from happening?

ActorReneGarcia
Автор

Hello great channel. Can you make a video about using it with pyqt5 ? Like i want to implement the same construct to different qt type objects :)!
Thanks

workflowinmind
Автор

i'm using linux python 2.7.5. When i used type() to create TypeClass as I followed your video, and then created 'printHam()' and stitch this function into the dictionary. I then instantiated an object of TypeClass and invoke obj.printHam(), I got the "ham" string printed.... but an additional None followed after the print... and i did not see that showing in your video.. any ideas here? thanks

daixtr
Автор

sir can you explain what does this mean
t.printham()
TypeError: printham() takes 0 positional arguments but 1 was given

gurueng
Автор

Is there a way to make that “x” an instance variable instead of it being an attribute of a class within type() creation method?

Makumazaan
Автор

Passing {"x":5} to type creates x at the class level whereas assigning self.x in __init__ populates the instance __dict__ (vs. the __class__ dict). In other words, those two ways of creating a class were not parallel. Better if the original defined x = 5 at the class level.

kirbyurner
Автор

Couldn't seem to get the metaclass example working in python 3.4.3 .
" AttributeError: 'MyClass' object has no attribute 'x' "

Zetzitsen
Автор

I found that defining the class
class MyClass(object): ....
as class MyClass():.... has alltogether ddifferent efffect on calling type() on the instance variable. Why is that ?

jubinkuriakose
Автор

how the cls has an attribute _instances in cls._instances??

nehalkamal
Автор

Whoa so instead of func-ception I'm getting a class-ception feel here (love your sense of humor). So if I got this right, instead of self we have cls and cls refers to the metaclass, which the Singleton class is? (I'm printing out the further reading material!) As a sidenote, I think its awesome how the "move over self (in this case cls) one step to the parens on the left" mnemonic/trick still works here.

DKyousai
welcome to shbcf.ru