Jump to content

  • Log In with Google      Sign In   
  • Create Account


Kurai Tsubasa

Member Since 22 Aug 2013
Offline Last Active Sep 13 2014 02:07 AM

Posts I've Made

In Topic: What is super().__init()

29 July 2014 - 06:34 AM

 

 

 

 

 

Yes i do when learn about the 'basic' of python,but i never learn about class much,since the books i read never using class on their example.But after reading that books and look some example on internet i realize that i must learn about it much ^^

 

For a book, I can recommend 'Learning Python'. But there's also many internet courses, amongst them is http://learnpythonthehardway.org/ which I think is the most appreciated python course on this forum. I'm quite sure it covers basics of OOP and such. Good luck with your education! smile.png

 

In the Python world, LPTHW is great for everything but OOP. It's unanimously agreed that the OOP section in that book is its major downfall.

 

I recommend you just look at examples of programs which use classes, and try writing some OOP programs yourself. OOP is the kind of thing that doesn't really "click" until you start using it yourself.

 

 

 

 

 

In the Python world, LPTHW is great for everything but OOP. It's unanimously agreed that the OOP section in that book is its major downfall.

 

Yeah I could mention I didn't read it, only relied on the opinion I've read here that it is a good tutorial smile.png

 

 

Thank you for the Tutorial actually i already do that but never finished it,but i do learn class from video tutorial and book.So I tried to using the super()__init__() and i figured it what it is for smile.png  but i still curious why we need to pass  *groups inside __init__() in my code when i play around with super i never pass anything inside __init__() because i don't know what it is for(i only know def __init__ or something to init first).This is my last question biggrin.png .Thank you very much

 

__init__ is called a Constructor. It's a function (like any other), with a small twist. It gets called every time you create a new instance of a Class. For example, let's say we want to create a generic enemy class. We want all of the instances of our class to be the same in every regard except their health. A class like that would look something like this:



class Enemy(object):
    def __init__(self, health):
        print "Inside __init__"
        self.health = health

Every time we create a new Enemy, __init__ gets ran with whatever "health" we pass in. Let's create some Enemy objects:



# You pass in what their health should be when creating them
enemy_one = Enemy(10)
enemy_two = Enemy(5)

And here's the program output:



Inside __init__
Inside __init__

When you make a new Object and pass things to it in parenthesis, you're actually passing stuff to the __init__ function.

 

 

Ok,i got it now.Thank you very much for the explanationbiggrin.png


In Topic: What is super().__init()

28 July 2014 - 12:10 AM

 

 

 

Yes i do when learn about the 'basic' of python,but i never learn about class much,since the books i read never using class on their example.But after reading that books and look some example on internet i realize that i must learn about it much ^^

 

For a book, I can recommend 'Learning Python'. But there's also many internet courses, amongst them is http://learnpythonthehardway.org/ which I think is the most appreciated python course on this forum. I'm quite sure it covers basics of OOP and such. Good luck with your education! smile.png

 

In the Python world, LPTHW is great for everything but OOP. It's unanimously agreed that the OOP section in that book is its major downfall.

 

I recommend you just look at examples of programs which use classes, and try writing some OOP programs yourself. OOP is the kind of thing that doesn't really "click" until you start using it yourself.

 

 

 

 

 

In the Python world, LPTHW is great for everything but OOP. It's unanimously agreed that the OOP section in that book is its major downfall.

 

Yeah I could mention I didn't read it, only relied on the opinion I've read here that it is a good tutorial smile.png

 

 

Thank you for the Tutorial actually i already do that but never finished it,but i do learn class from video tutorial and book.So I tried to using the super()__init__() and i figured it what it is for smile.png  but i still curious why we need to pass  *groups inside __init__() in my code when i play around with super i never pass anything inside __init__() because i don't know what it is for(i only know def __init__ or something to init first).This is my last question biggrin.png .Thank you very much


In Topic: What is super().__init()

27 July 2014 - 07:37 AM

Well, you say you are new to programming. Do you know what does inheritance mean?

Yes i do when learn about the 'basic' of python,but i never learn about class much,since the books i read never using class on their example.But after reading that books and look some example on internet i realize that i must learn about it much ^^

 

 

 

Google for inheritance, it is a mechanic on Object Oriented programing that roughly saying makes one class (in your case, Player) have all the methods and private variables of the class that is its parent (in your case Sprite). super there is used to call the init method of the sprite class.

 

Here you can find a better explanation (not my blog): http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/

Thank you it help me understanding about class and super(There is a link in comment),but i still not get used with it,maybe playing around a little bit tomorrow will help me get used to it.

 

 

super(Player, self) says 'give me an object representing the parent class of self', where 'self' is python convention for the current instance. .__init__(...) is calling the constructor on that object, which will be the constructor defined in the parent class.

 

If that doesn't make sense, you'll need to read up on classes and inheritance.

Well,i think i understand that a little.I will play around with it tomorrow so i can really understand it

 

 

It runs the parent class' Constructor. More formally, it gives a version of the Player object which in the form of the Player objects parent class.

I will try to play with it a bit to really understand that

 

 


Well,Thank you everyone to help me.I will try my best biggrin.png 


In Topic: Help me learn Pygame

23 May 2014 - 04:06 AM

I just realized you had said you were reading Invent with Python already, so  my apologies for not fully reading your question >.<.  Hopefully the other links are of help though.

 

But, to your other point about not feeling you fully understand the code, personally, when I'm following tutorials and learning a new language, once I've tried the code as it is, I usually spend some quality time tinkering with it, trying different things until I really understand what it's all doing. I find if I simply copy it over, I don't have a good sense for what it's doing, nor do I really retain much of it. So, I try to alter it, create new things, etc. You can usually get a better sense of how it all fits together by taking the tutorial code and making something new with it.

 

Anyhow, best of luck! smile.png

It's okaysmile.png also programarcadegames it is a great website for learning pygame,thanks for telling me that websitesmile.png and thanks for the advice i should think more deeper and tried the codes that i don't understand line by line and improving a basic codes really helping me.biggrin.png 


In Topic: Help me learn Pygame

22 May 2014 - 04:19 AM

I found these to be helpful:

http://inventwithpython.com/chapters/

http://inventwithpython.com/pygame/chapters/  //you can download a pdf of the book on the site for this and the book above.

http://programarcadegames.com/

 

There is a specific chapter on collision detection:

http://inventwithpython.com/chapter18.html

 

and the pygame.org site has tutorials on it as well:

http://www.pygame.org/wiki/tutorials

 

I'm not certain how up to date the first links are, so

https://fedoraproject.org/wiki/Changes/Python_3_as_Default

https://docs.python.org/3/whatsnew/3.4.html

could be helpful if you run into any problems.

 

It's been a bit since I've used python so perhaps someone else will have a better recommendation smile.png

Good luck!

Thank you very much it help me a lotsmile.png 


PARTNERS