Python class coding

Discussion in 'General Chat' started by maskedcerf, May 11, 2016.

Tags:
  1. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    Twas indeed sarcasm ^^
     
  2. Teddywonka

    Teddywonka A wonka that wonks a wonk

    Joined:
    Nov 18, 2015
    Messages:
    232
    Likes Received:
    173
    Reading List:
    Link
    So this one is a class personnage that define about the hero and how much damage it can take or deal with the enemy by displaying text and images.
    am i right about this?
     
  3. negritis

    negritis The Mathematician

    Joined:
    Dec 28, 2015
    Messages:
    3,346
    Likes Received:
    1,212
    Reading List:
    Link
    well i don't know if you tested the functionality, but not sure if printing works that way, at least i use it differently
    and the indentation is messed up again :D

    but i suggest you to use pycharm as your IDE and pylint to check if your code is readable enough
    belive me those are important

    also i suggest you to watch Uncle Bob's clean code videos
     
  4. The Darkness

    The Darkness 『False God』

    Joined:
    Dec 28, 2015
    Messages:
    3,407
    Likes Received:
    4,551
    Reading List:
    Link
    I assume it is picture of your slong, no thank you. I would not willingly subject myself to that kind of imagery.
     
    Astaroth, Nyarlathotep and Westeller like this.
  5. Liyus

    Liyus Laksha's Desu~ Cat

    Joined:
    Nov 10, 2015
    Messages:
    4,216
    Likes Received:
    4,757
    Reading List:
    Link
    i'm thickskinned do care for sarcasm:sneaky:
     
  6. Teddywonka

    Teddywonka A wonka that wonks a wonk

    Joined:
    Nov 18, 2015
    Messages:
    232
    Likes Received:
    173
    Reading List:
    Link
    I second the motion.
    You can make the code cleaner and easier to read and understand in people's eyes by proper spaces between lines and other coding standards.
     
  7. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    oh thanks that was useful ^^ i didn't know of those XD
    yep ^^
    XD oh well congrats~
    no no it say that I M FREEEEEEENCH AND PROUD OF IT
     
  8. Alvastar

    Alvastar Well-Known Member

    Joined:
    Nov 15, 2015
    Messages:
    645
    Likes Received:
    619
    Reading List:
    Link
    If you're looking for how to incorporate classes using a GUI and other game-related functions, it's easier to follow along a tutorial. Here is a site with a variety of games written in python.

    The biggest advice I can give you when writing in python is to treat it as pseudo-code, as that was how it was intended. When you start incorporating bad habits from C, Java, and PHP, that's where you end up in a mess at a later date.

    Also, you might consider using underscores between words in your variable names. Most people who use python do so instead of using abbreviations, camelcase, or having the whole thing in lowercase with multiple words. It's also easier to peruse when viewing code. In addition, consider using spacing between the ", +, and = where you can. Some functions don't allow for it, but it's easier to peruse your code as well as figure out what added by you versus a function or module. Again, this is just some helpful advice I've found that keeps me in the pseudo-code mind-set, and saves a fair amount of time later when test-cases are incorporated into the project.

    Edit: And to those suggesting IDEs, I strongly recommend SublimeText. It's extremely easy to use and saves quite a bit of time. The beta is free, by the way.
     
    maskedcerf likes this.
  9. Westeller

    Westeller Smokin' Sexy Style!! Staff Member

    Joined:
    Apr 3, 2016
    Messages:
    8,176
    Likes Received:
    24,960
    Reading List:
    Link
    It doesn't. You were right not to look. :confused:
     
    Nyarlathotep likes this.
  10. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    also the print is different because i want the text to be in the windows ^^ not in the console
     
  11. Cupcake Ninja

    Cupcake Ninja [Kind Sage][Lord Benevolence][ The Great Paragon]

    Joined:
    Nov 19, 2015
    Messages:
    5,991
    Likes Received:
    8,159
    Reading List:
    Link
    ...O.0

    you can code, bro?

    well...that was unexpected, coming from you. I underestimated you.
     
  12. Serene Moon Over Silent Waters

    Serene Moon Over Silent Waters Well-Known Member

    Joined:
    Nov 8, 2015
    Messages:
    28
    Likes Received:
    26
    Reading List:
    Link
    So I can help, since I code in python and can Google translate well.

    For def.__init__, don't name one of the arguments vie=20. Considering that you keep setting vie to different values, it makes no sense to say that you want it at 20.

    In addition, personnage should have both getter and setter functions.

    Also, I'm not entirely sure whether it's legal to initialize an object of a class in the class it's being written in. Especially the init function, since that seems to create an infinite loop.

    You also have a bunch of stray functions, considering you seem to be initializing enemi objects in a function, and after the Hero is initialized. Remove those, as they should probably belong to child classes.
     
    maskedcerf and Westeller like this.
  13. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    thanks ^^
    ah thanks a lot XD but what are getter and setter?
    humpf a pervert must have a lot of skill MOUAHAHAHAHAHAHAHAH
     
  14. Grenore

    Grenore 《Member》

    Joined:
    Apr 18, 2016
    Messages:
    1,241
    Likes Received:
    465
    Reading List:
    Link
    do you not use ''curly brackets'' in your code.
    after looking at i noticed it, that although you're using ''if statements'', but the code used in the ''if statements'' should be inside a curly brackets, yet i don't see you're using any of the ''curly brackets''.
     
  15. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    i don't even know what a curly brackets is XD
     
  16. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    oh that? thats for C or C++ if i'm not wrong
     
  17. Grenore

    Grenore 《Member》

    Joined:
    Apr 18, 2016
    Messages:
    1,241
    Likes Received:
    465
    Reading List:
    Link
    curly brackets = { }
    nope, its not only used for c++, curly brackets used in all type of coding, for start and end
    start = {
    end = }
    and everything should be inside it
     
    maskedcerf likes this.
  18. Seigin

    Seigin [Lolicon][GenderBender Banzai!]

    Joined:
    Jan 22, 2016
    Messages:
    1,131
    Likes Received:
    934
    Reading List:
    Link
    I cant code buy i have surplus of skills.... in various meanings ( ͡° ͜ʖ ͡°)
     
  19. maskedcerf

    maskedcerf DCLXVI

    Joined:
    Oct 22, 2015
    Messages:
    1,770
    Likes Received:
    2,329
    Reading List:
    Link
    oh i didn't know XD
    MUEHEHEHEHEHEHEHEHEHEH
     
    Little Dragon likes this.
  20. Koinye Best

    Koinye Best Well-Known Member

    Joined:
    Feb 12, 2016
    Messages:
    150
    Likes Received:
    227
    Reading List:
    Link
    I was gonna post a snake charmer meme but nah too lazy...