newbie class question

2005-11-23 Thread vida00
Hi,
I scouted the ng for someone w/ a similar problem and couldn't find
one, so I might be thinking about this probable non-issue in a wrong
way.

What I am trying to accomplish should be pretty self explanatory when
looking at the following:

>>> class heh(object):
... def __init__(self):
... self.foo='hello'
... def change(self):
... self.foo+=' world'
... def show(self):
... return self.foo
...
... class hih(object):
... def __init(self):
... self.foo=heh.foo()
... def show(self):
... return self.foo
...
>>> x=heh()
>>> x.show()
'hello'
>>> x.change()
>>> x.show()
'hello world'
>>> y=x.hih()
>>> y.show()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 13, in show
AttributeError: 'hih' object has no attribute 'foo'

so, how do I reference heh.foo in its current state (i.e. 'hello
world', not 'hello') from hih?

Thanks,

-Josh.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie class question

2005-11-23 Thread vida00

[EMAIL PROTECTED] wrote:
> Hi,
> I scouted the ng for someone w/ a similar problem and couldn't find
> one, so I might be thinking about this probable non-issue in a wrong
> way.
>
> What I am trying to accomplish should be pretty self explanatory when
> looking at the following:
>
> >>> class heh(object):
> ... def __init__(self):
> ... self.foo='hello'
> ... def change(self):
> ... self.foo+=' world'
> ... def show(self):
> ... return self.foo
> ...
> ... class hih(object):
> ... def __init(self):
> ... self.foo=heh.foo()
> ... def show(self):
> ... return self.foo
> ...
> >>> x=heh()
> >>> x.show()
> 'hello'
> >>> x.change()
> >>> x.show()
> 'hello world'
> >>> y=x.hih()
> >>> y.show()
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 13, in show
> AttributeError: 'hih' object has no attribute 'foo'
>
> so, how do I reference heh.foo in its current state (i.e. 'hello
> world', not 'hello') from hih?
>
> Thanks,
>
> -Josh.

Sorry folks, this is what I meant:

>>> class heh(object):
... def __init__(self):
... self.foo='hello'
... def change(self):
... self.foo+=' world'
... def show(self):
... return self.foo
...
... class hih(object):
... def show(self):
... return heh().foo
...
>>> x=heh()
>>> print x.hih().show()
hello
>>> x.change()
>>> print x.show()
hello world
>>> print x.hih().show()
hello

I want that last one to print 'hello world'

Thanks, and sorry for the confusion.

-- 
http://mail.python.org/mailman/listinfo/python-list


problems binding a dictionary

2005-12-10 Thread vida00
this has to be a very silly thing.

I have a function foo taking a dictionary as parameters. i.e.: def
foo(**kwargs): pass
when I call foo(param1='blah',param2='bleh',param3='blih') everything
is fine.
but when I do:
>>> def foo(**kwargs):
... pass
...
>>> d=dict(param1='blah',param2='bleh',param3='blih')
>>> foo(d)

I get:

Traceback (most recent call last):
  File "", line 1, in ?
TypeError: foo() takes exactly 0 arguments (1 given)

Why? how do I pass the dictionary *d* to foo()?
Thanks,

- Josh.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems binding a dictionary

2005-12-10 Thread vida00

[EMAIL PROTECTED] wrote:
> this has to be a very silly thing.
>
> I have a function foo taking a dictionary as parameters. i.e.: def
> foo(**kwargs): pass
> when I call foo(param1='blah',param2='bleh',param3='blih') everything
> is fine.
> but when I do:
> >>> def foo(**kwargs):
> ... pass
> ...
> >>> d=dict(param1='blah',param2='bleh',param3='blih')
> >>> foo(d)
>
> I get:
>
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: foo() takes exactly 0 arguments (1 given)
>
> Why? how do I pass the dictionary *d* to foo()?
> Thanks,
> 
> - Josh.

I mean, short of defining as foo(*args), or foo(dict).

-- 
http://mail.python.org/mailman/listinfo/python-list