TypeError: no arguments expected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shawn a

    TypeError: no arguments expected

    I havet these 2 files in the same dir. This is code im writing to learn pythong
    mkoneurl.py:
    #! /usr/bin/env python

    import make_ou_class

    run = make_ou_class.m akeoneurl()

    =============== =============== ======
    make_ou_class.p y:

    class makeoneurl:
    def __init__():
    self.commandlin e()

    def commandline():
    com = raw_input(":")
    #Parse out any params and aguements - reg expressions
    #params[] array to hold paramters
    params = 0
    if com == "ou":
    self.ou(params)
    else:
    print com + " unknown command."

    def ou(params):
    print "hello world"
    self.commandlin e()

    =============== =============== =============== ==
    when i run the script like this: python mkoneurl.py
    I get this error:

    Traceback (innermost last):
    File "mkoneurl.p y", line 5, in ?
    run = make_ou_class.m akeoneurl()
    TypeError: no arguments expected

    Ive looked around for this exeption but nothing ive read has help in
    this situation.
    Any of your thoughts are greatly apprectiated. THANK!!

    --shawn
  • bonono@gmail.com

    #2
    Re: TypeError: no arguments expected


    shawn a wrote:[color=blue]
    > I havet these 2 files in the same dir. This is code im writing to learn pythong
    > mkoneurl.py:
    > #! /usr/bin/env python
    >
    > import make_ou_class
    >
    > run = make_ou_class.m akeoneurl()
    >
    > =============== =============== ======
    > make_ou_class.p y:
    >
    > class makeoneurl:
    > def __init__():
    > self.commandlin e()
    >
    > def commandline():
    > com = raw_input(":")
    > #Parse out any params and aguements - reg expressions
    > #params[] array to hold paramters
    > params = 0
    > if com == "ou":
    > self.ou(params)
    > else:
    > print com + " unknown command."
    >
    > def ou(params):
    > print "hello world"
    > self.commandlin e()
    >
    > =============== =============== =============== ==
    > when i run the script like this: python mkoneurl.py
    > I get this error:
    >
    > Traceback (innermost last):
    > File "mkoneurl.p y", line 5, in ?
    > run = make_ou_class.m akeoneurl()
    > TypeError: no arguments expected
    >
    > Ive looked around for this exeption but nothing ive read has help in
    > this situation.
    > Any of your thoughts are greatly apprectiated. THANK!!
    >[/color]
    put "self" as the first argument in all instance methods of that class.
    "self" is just a convention, referring to the object instance, not a
    language feature as in other language like javascript. You can call it
    "me" too if you prefer.

    Comment

    • Roy Smith

      #3
      Re: TypeError: no arguments expected

      In article <1134357067.699 971.145850@g43g 2000cwa.googleg roups.com>,
      bonono@gmail.co m wrote:
      [color=blue]
      > put "self" as the first argument in all instance methods of that class.
      > "self" is just a convention, referring to the object instance, not a
      > language feature as in other language like javascript. You can call it
      > "me" too if you prefer.[/color]

      But please don't call it "me". The convention to call the first argument
      "self" is so universal, calling it anything else is just going to make your
      code more difficult for anybody else to read.

      Comment

      • Alex Martelli

        #4
        Re: TypeError: no arguments expected

        shawn a <boris317@gmail .com> wrote:
        ...[color=blue]
        > Ive looked around for this exeption but nothing ive read has help in
        > this situation.
        > Any of your thoughts are greatly apprectiated. THANK!![/color]

        Add "self" as the first or only parameters to all methods.

        Re-read the tutorial -- you're missing very crucial parts of it.


        Alex

        Comment

        • Steve Holden

          #5
          Re: TypeError: no arguments expected

          Dennis Lee Bieber wrote:[color=blue]
          > On Sun, 11 Dec 2005 22:00:55 -0500, shawn a <boris317@gmail .com>
          > declaimed the following in comp.lang.pytho n:
          >
          >[color=green]
          >>I havet these 2 files in the same dir. This is code im writing to learn pythong
          >>mkoneurl.py :
          >>#! /usr/bin/env python
          >>
          >>import make_ou_class
          >>
          >>run = make_ou_class.m akeoneurl()[/color]
          >
          >
          > Okay, you've just defined a "run" object that contains an instance
          > of "makeoneurl "... What do you expect it to do?
          >[/color]
          Let's get the terminology right: sloppy terminology leads to sloppy
          thinking. The statement binds the name "run" to a newly-created
          "make_one_u rl" instance. Remember, "run" isn't an object, it's a
          reference to an object like all Python names.[color=blue]
          >[color=green]
          >>============= =============== ========
          >>make_ou_class .py:
          >>[/color]
          >
          > Well, first off... You need to /supply/ a placeholder for "self".
          > ALL methods of a class receive the instance as the first argument. So...
          >[/color]
          Again you need to be a little careful here, since we now have class
          methods and static methods to cloud the picture. So it would be more
          accurate to say that "instance methods are all automatically called with
          a reference to the instance as the first argument; it is conventional to
          use the name 'self' to refer to the instance".[color=blue]
          >[/color]
          [...]

          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC www.holdenweb.com
          PyCon TX 2006 www.python.org/pycon/

          Comment

          • shawn a

            #6
            Re: TypeError: no arguments expected

            thanks for all your input. Ive gotten it to work thanks!

            --shawn

            On 12/12/05, Steve Holden <steve@holdenwe b.com> wrote:[color=blue]
            > Dennis Lee Bieber wrote:[color=green]
            > > On Sun, 11 Dec 2005 22:00:55 -0500, shawn a <boris317@gmail .com>
            > > declaimed the following in comp.lang.pytho n:
            > >
            > >[color=darkred]
            > >>I havet these 2 files in the same dir. This is code im writing to learnpythong
            > >>mkoneurl.py :
            > >>#! /usr/bin/env python
            > >>
            > >>import make_ou_class
            > >>
            > >>run = make_ou_class.m akeoneurl()[/color]
            > >
            > >
            > > Okay, you've just defined a "run" object that contains an instance
            > > of "makeoneurl "... What do you expect it to do?
            > >[/color]
            > Let's get the terminology right: sloppy terminology leads to sloppy
            > thinking. The statement binds the name "run" to a newly-created
            > "make_one_u rl" instance. Remember, "run" isn't an object, it's a
            > reference to an object like all Python names.[color=green]
            > >[color=darkred]
            > >>============= =============== ========
            > >>make_ou_class .py:
            > >>[/color]
            > >
            > > Well, first off... You need to /supply/ a placeholder for "self".
            > > ALL methods of a class receive the instance as the first argument. So....
            > >[/color]
            > Again you need to be a little careful here, since we now have class
            > methods and static methods to cloud the picture. So it would be more
            > accurate to say that "instance methods are all automatically called with
            > a reference to the instance as the first argument; it is conventional to
            > use the name 'self' to refer to the instance".[color=green]
            > >[/color]
            > [...]
            >
            > regards
            > Steve
            > --
            > Steve Holden +44 150 684 7255 +1 800 494 3119
            > Holden Web LLC www.holdenweb.com
            > PyCon TX 2006 www.python.org/pycon/
            >
            > --
            > http://mail.python.org/mailman/listinfo/python-list
            >[/color]

            Comment

            Working...