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 5 1800
shawn a wrote: 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.
In article <11**********************@g43g2000cwa.googlegroups .com>, bo****@gmail.com wrote: 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.
shawn a <bo******@gmail.com> wrote:
... 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
Dennis Lee Bieber wrote: On Sun, 11 Dec 2005 22:00:55 -0500, shawn a <bo******@gmail.com> declaimed the following in comp.lang.python:
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?
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.==================================== 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...
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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
thanks for all your input. Ive gotten it to work thanks!
--shawn
On 12/12/05, Steve Holden <st***@holdenweb.com> wrote: Dennis Lee Bieber wrote: On Sun, 11 Dec 2005 22:00:55 -0500, shawn a <bo******@gmail.com> declaimed the following in comp.lang.python:
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.makeoneurl()
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.==================================== 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....
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 -- 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Achim Domma |
last post by:
Hi,
I'm using MySQLdb with Python 2.3 on windows. Querying a database seems to
work fine, but inserting does not. If I try something like this:
cursor.execute("insert into Webpages (Url)...
|
by: Manoj |
last post by:
Hi ,
I have written a simple program usinga class.
But it not compiling.The error i get is
my = myclass("Paul", "John")
TypeError: this constructor takes no arguments
I checked some previous...
|
by: ‘5ÛHH575-UAZWKVVP-7H2H48V3 |
last post by:
(see end of message for example code)
When an instance has a dynamically assigned instance method, deepcopy
throws a TypeError with the message "TypeError: instancemethod
expected at least 2...
|
by: shearichard |
last post by:
Hi - I have written some python to insert a row into a table using
MySQLDB. I have never before written SQL/Python using embedded
parameters in the SQL and I'm having some difficulties. Could...
|
by: Randall Parker |
last post by:
Using Python 2.4.2 on Windows 2000 in SPE.
Getting:
TypeError: 'str' object is not callable
on this line:
TmpErrMsg1 = "State machine %s " (StateMachineName)
In Winpdb 1.0.6 the...
|
by: Paul Du Bois |
last post by:
Using win32 python 2.4.1, I have a minimal test program:
def generate():
raise TypeError('blah')
yield ""
print "\n".join((generate()))
Executing the program gives:
|
by: VK |
last post by:
I was getting this effect N times but each time I was in rush to just
make it work, and later I coudn't recall anymore what was the original
state I was working around. This time I nailed the...
|
by: est |
last post by:
>>import md5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\pickle.py", line 1366, in dumps
Pickler(file, protocol).dump(obj)
File...
|
by: James Mills |
last post by:
On Fri, Oct 31, 2008 at 8:49 AM, mark floyd <emfloyd2@gmail.comwrote:
Mark, this is correct behavior. You have
3 positional arguments in the function
definition. You _must_ aupply _all_ 3
of...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |