1

I've just developed my first python program! In order to learn something more out of it I think the best idea and post it here. I'm just wondering if there is a better way to write this program.

It is a python program that brings "i-ching, the book of mutations" with the translation by Richard Wilhelm, on command line.

The complete project is on github: https://github.com/roorco/CliChing/blob/master/cliching.py

Interesting to note: in order to recognize which hexagram the program extracts, it transforms the hexagram in a binary number. In coding this I suppose I understood how Leibniz discovered the binary number studying I-Ching.

Thanks to this exercise I understood better the classes in Python but still one thing is not clear for me:

if I wrote:

class Line(object):
    def intro():
        ...

and the end of the code I call:

Line().intro() 

the result will be:

TypeError: intro() takes no arguments (1 given)

Why? The only way I figure out is giving a 'x' argument to intro. Other ways are possible?

If you like to, please leave me some feedback.

senshin
  • 9,562
  • 5
  • 44
  • 57
ro_orco
  • 33
  • 7

1 Answers1

0

Methods that are defined within a class need to take self as a parameter. This is basically because they need to know which object the function is operating on. Take a look at these 2 links they do a pretty good job of explaining what self is and why we need to use it.

What is the purpose of self?

https://freepythontips.wordpress.com/2013/08/07/the-self-variable-in-python-explained/

Community
  • 1
  • 1
user3282276
  • 3,395
  • 7
  • 29
  • 47
  • Ok, the question at the end is explained in a duplicate post but you need to know that your answer is there, thanks for point at that. Anyway my first reason to post was to get some sort of feedback on the code. – ro_orco Dec 04 '14 at 01:44