473,770 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

noob question: "TypeError" wrong number of args

Hi guys

Tried searching for a solution to this, but the error message is so
generic, that I could not get any meaningfull results.

Anyways - errormessage:
----------------------------------------------------
TypeError: addFile() takes exactly 1 argument (2 given)
----------------------------------------------------

The script is run with two args "arg1" and "arg2":
----------------------------------------------------
import sys

class KeyBase:
def addFile(file):
print "initialize the base with lines from this file"

print "These are the args"
print "Number of args %d" % len(sys.argv)
print sys.argv
print sys.version_inf o
print sys.version

f = sys.argv[1]
print "f = '%s'" % f
b = KeyBase()

b.addFile(f)
----------------------------------------------------

The output - including error message
(looks like stdout and stderr are a bit out of sync...):
----------------------------------------------------
These are the args
Traceback (most recent call last):

Number of args 3
['C:\\home\\<.. bla bla snip ...>\\bin\\test .py', 'arg1', 'arg2']
(2, 4, 2, 'final', 0)
2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)]
f = 'arg1'

File "C:\Program Files\ActiveSta te Komodo
3.5\lib\support \dbgp\pythonlib \dbgp\client.py ", line 1806, in runMain
self.dbg.runfil e(debug_args[0], debug_args)
File "C:\Program Files\ActiveSta te Komodo
3.5\lib\support \dbgp\pythonlib \dbgp\client.py ", line 1529, in runfile
h_execfile(file , args, module=main, tracer=self)
File "C:\Program Files\ActiveSta te Komodo
3.5\lib\support \dbgp\pythonlib \dbgp\client.py ", line 590, in __init__
execfile(file, globals, locals)
File "C:\home\hbille \projects\bc4ro m\bin\test.py", line 20, in
__main__
b.addFile(f)
TypeError: addFile() takes exactly 1 argument (2 given)
----------------------------------------------------

I'm running this inside ActiveState Komodo on WinXP.

Hope one you wizards can give me pointers to either what I'm doing
wrong or maybe advise me what to modify in my setup.

Thank you!

Regards,
Holger

May 1 '06
42 3460
Marc 'BlackJack' Rintsch a écrit :
(snip)

Okay, let's start with writing a simple text processor for this little
mess::

def b(c):
def d(r, *s, **t):
print '***'
c(r, *s, **t)
return d

What a nice, readable, highly pythonic code...
(snip)
May 3 '06 #31
Edward Elliott <no****@127.0.0 .1> writes:
As long as we're trotting out aphorisms
The ones I quoted were from Python.
import this

how about DRY: Don't Repeat Yourself. The rule couldn't be clearer:
don't repeat your SELF. ;) Yet that's exactly what explicitly
declaring self does, forces me to needlessly repeat what everyone
already knows: methods take the object instance as their first
parameter.


You've misunderstood "don't repeat yourself". It advocates *one*
definition of any given thing in the code. You are advocating *zero*
definitions of 'self' in the code.

--
\ "No wonder I'm all confused; one of my parents was a woman, the |
`\ other was a man." -- Ashleigh Brilliant |
_o__) |
Ben Finney

May 3 '06 #32
Bruno Desthuilliers <bd************ *****@free.quel quepart.fr> writes:
Ben Finney a écrit :
So now you're proposing that this be a special case when a
function is declared by that particular syntax, and it should be
different to when a function is created outside the class
definition and added as a method to the object at run-time.

Thus breaking not only "explicit is better than implicit",


This one can be subject to discussion.


All the assertions in 'import this' are subject to discussion. They're
even contradictory.
but also "special cases aren't special enough to break the rules".


Yeps, I think this is what I don't like here.
Still -1.


I'm not yet ready to vote for Edward's proposition - as you say, it
makes 'def statements into a class statement' a special case, and I
don't like special cases too much (OTOH, there actually *are*
special cases - __new__() being an example) - *but* it's not that
silly either IMHO, and I think this should not be dismissed on a
purely reactional basis.


My basis for rejecting the proposal is that it claims to offer net
simplicity, yet it breaks at least two of the admonishments that
simplify Python.

--
\ "My house is made out of balsa wood, so when I want to scare |
`\ the neighborhood kids I lift it over my head and tell them to |
_o__) get out of my yard or I'll throw it at them." -- Steven Wright |
Ben Finney

May 3 '06 #33
Ben Finney wrote:
Edward Elliott <no****@127.0.0 .1> writes:
As long as we're trotting out aphorisms
The ones I quoted were from Python.
>>> import this


Yes I know where it's from.
You've misunderstood "don't repeat yourself". It advocates *one*
definition of any given thing in the code. You are advocating *zero*
definitions of 'self' in the code.


It's implicitly defined by the language/runtime, so I shouldn't need to
define it in my code. Doing so is duplication of effort, aka DRY. An
implicit definition is not an empty definition. Where do the semantics of
'while' and 'for' come from? Same thing, it's implicit in the language.

May 3 '06 #34
Ben Finney wrote:
My basis for rejecting the proposal is that it claims to offer net
simplicity, yet it breaks at least two of the admonishments that
simplify Python.


As do other features of Python. Or did you forget the follow-up to the
special cases "rule"?

Special cases aren't special enough to break the rules.
Although practicality beats purity.

May 3 '06 #35
Marc 'BlackJack' Rintsch wrote:
Edward Elliott wrote:
I can prove that assertion too: make a simple text processor that reads
Python source code and outputs the same source code with only one change:
insert the string 'self" as the first parameter of every "def
somemethod". Next run the output source code with the normal Python


Okay, let's start with writing a simple text processor for this little
mess::


I didn't even try to wade through that morass of monocharacter variables.
Anyone wanna summarize the point of that code?

May 3 '06 #36
Edward Elliott <no****@127.0.0 .1> writes:
Marc 'BlackJack' Rintsch wrote:
Edward Elliott wrote:
I can prove that assertion too: make a simple text processor that
reads Python source code and outputs the same source code with
only one change: insert the string 'self" as the first parameter
of every "def somemethod". Next run the output source code with
the normal Python


Okay, let's start with writing a simple text processor for this
little mess::


I didn't even try to wade through that morass of monocharacter
variables. Anyone wanna summarize the point of that code?


As I understand it, the point was not what the code does, but to give
a sample input (a Python program) for the "simple text processor" you
described to wade through.

--
\ "I always had a repulsive need to be something more than |
`\ human." -- David Bowie |
_o__) |
Ben Finney

May 3 '06 #37
Ben Finney wrote:
As I understand it, the point was not what the code does, but to give
a sample input (a Python program) for the "simple text processor" you
described to wade through.


Ah, well then, there's no need for a full-blown parser. It should suffice
to recognize a class definition and modify the parameter list of every def
indented one level further than that. Then pick out the static methods and
'undo' those. Can be done in one pass by keeping the class definition in
memory until you've scanned the whole thing, then adding self where needed
as you spit it back out.

Implementation is left as an exercise for the reader. :)

May 3 '06 #38
Ben Finney wrote:
Bruno Desthuilliers <bd************ *****@free.quel quepart.fr> writes:

Ben Finney a écrit :
So now you're proposing that this be a special case when a
function is declared by that particular syntax, and it should be
different to when a function is created outside the class
definition and added as a method to the object at run-time.

Thus breaking not only "explicit is better than implicit",
This one can be subject to discussion.

All the assertions in 'import this' are subject to discussion.


Of course - but that was not the point. I meant that having implicit
self in methods would not break this assertion much more than the
current strange mix of explicit declaration of self + implicit passing
of self.
They're
even contradictory.


That's the nature of Zen, isn't it ?-)

(snip)
I'm not yet ready to vote for Edward's proposition - as you say, it
makes 'def statements into a class statement' a special case, and I
don't like special cases too much (OTOH, there actually *are*
special cases - __new__() being an example) - *but* it's not that
silly either IMHO, and I think this should not be dismissed on a
purely reactional basis.

My basis for rejecting the proposal is that it claims to offer net
simplicity, yet it breaks at least two of the admonishments that
simplify Python.


One could also claim that the current scheme *actually* breaks
explicit-implicit and special-case rules in that the instance is
implicitely passed at call time for the bound methods special case -
which is ok IMHO since practicallity-beats-purity. Also, FWIW, Edward's
proposition can be justified (at least that's Edward's POV) by the first
rule : beautiful is better than ugly !-)

disclaimer : None of this is to be taken as the expression of my own
position on this proposition...

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
May 4 '06 #39
Edward Elliott wrote:
Ben Finney wrote:
As I understand it, the point was not what the code does, but to give
a sample input (a Python program) for the "simple text processor" you
described to wade through.

Ah, well then, there's no need for a full-blown parser. It should suffice
to recognize a class definition and modify the parameter list of every def
indented one level further than that.


won't do :

class CounterExample( object):
if compute_some_co nst_according_t o_phase_of_moon ():
def meth(...):
do_something(se lf, 42)
else:
do_something_el se(self)

Then pick out the static methods and
'undo' those.


don't forget classmethods...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
May 4 '06 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7506
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 someone point me in the right direction please ? The python looks like this : import MySQLdb import MySQLdb.cursors conn = MySQLdb.Connect(host='localhost', user='abc,passwd='def',
7
12719
by: Girish Sahani | last post by:
Hi, Please check out the following loop,here indexList1 and indexList2 are a list of numbers. for index1 in indexList1: for index2 in indexList2: if ti1 == ti2 and not index1 != indexList1.pop(): index1+=1 index2+=1 continue
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.