TypeError: no arguments expected

S

shawn a

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.makeoneurl()

====================================
make_ou_class.py:

class makeoneurl:
def __init__():
self.commandline()

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.commandline()

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

Traceback (innermost last):
File "mkoneurl.py", line 5, in ?
run = make_ou_class.makeoneurl()
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
 
B

bonono

shawn said:
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.makeoneurl()

====================================
make_ou_class.py:

class makeoneurl:
def __init__():
self.commandline()

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.commandline()

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

Traceback (innermost last):
File "mkoneurl.py", line 5, in ?
run = make_ou_class.makeoneurl()
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!!
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.
 
R

Roy Smith

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.

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.
 
A

Alex Martelli

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

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

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


Alex
 
D

Dennis Lee Bieber

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.makeoneurl()

Okay, you've just defined a "run" object that contains an instance
of "makeoneurl"... What do you expect it to do?
====================================
make_ou_class.py:
Well, first off... You need to /supply/ a placeholder for "self".
ALL methods of a class receive the instance as the first argument. So...
class makeoneurl:
def __init__():
def __init__(self):
self.commandline()

def commandline():
def commandline(self):
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):
def ou(self, params):
print "hello world"
self.commandline()

Error is rather misleading until you think about it... You are
invoking the __init__ method (implicitly) when you create the instance.
As a method, it is being passed an argument -- the instance itself --
but you defined it to NOT expect any arguments.
--
 
S

Steve Holden

Dennis said:
Okay, you've just defined a "run" object that contains an instance
of "makeoneurl"... What do you expect it to do?
Let's get the terminology right: sloppy terminology leads to sloppy
thinking. The statement binds the name "run" to a newly-created
"make_one_url" instance. Remember, "run" isn't an object, it's a
reference to an object like all Python names.
Well, first off... You need to /supply/ a placeholder for "self".
ALL methods of a class receive the instance as the first argument. So...
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".[...]

regards
Steve
 
S

shawn a

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

--shawn

Dennis said:
Okay, you've just defined a "run" object that contains an instance
of "makeoneurl"... What do you expect it to do?
Let's get the terminology right: sloppy terminology leads to sloppy
thinking. The statement binds the name "run" to a newly-created
"make_one_url" instance. Remember, "run" isn't an object, it's a
reference to an object like all Python names.
Well, first off... You need to /supply/ a placeholder for "self".
ALL methods of a class receive the instance as the first argument. So....
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".[...]

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top