omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    class instances

    Pythonista
    3
    3
    1838
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • snarl_barx231
      snarl_barx231 last edited by

      I'm just learning python and oop in particular so I've got some basic questions.

      Why doesn't this work:

      class Foo:
      def init(self, x, y):
      self.x = x
      self.y = y

      bar = Foo(42, 7) <------ here i get the error "this constructor takes no arguments"

      print bar.x

      hmmmmmm....for some reason this post was stripped of indentation

      Thanks!

      1 Reply Last reply Reply Quote 0
      • Gcarver166
        Gcarver166 last edited by

        I think you need def init(self, x, y):. Looks like you only have 1 underscore on each side of init.

        1 Reply Last reply Reply Quote 0
        • pudquick51
          pudquick51 last edited by

          @Gcarver is correct. The init method for a class has two underscores on each side.

          @snarl_barx - If you want to preserve your indentation, next time start a block of code with <b><PRE></b> and end it with <b></PRE></b> and it will end up looking like this:

          <pre>class Foo:
          def init(self, x, y):
          self.x = x
          self.y = y</pre>

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors