method gets overwritten?!

Alexander Skwar usenet-posting.zu.askwar at spamgourmet.com
Fri Mar 14 13:30:48 CET 2003


Hi!

Consider the following class:

import gettext
class xhcClass:
	def untranslated(self, text):
		print "untranslated\n"
		return text
	def txt(self, txt):
		print "txt\n"
		return _(txt)
	def __init__(self):
		print "__init__\n"
		try:
			t = gettext.translation(domain = 'xhc',
						localedir = 'locale',
						languages = ["de"])
			t.install()
		except IOError:
			import __builtin__
			__builtin__.__dict__['_'] = self.untranslated


Now I do:

>>> x = xhcClass()
__init__

>>>
>>> print _
<bound method GNUTranslations.gettext of <gettext.GNUTranslations
instance at 0x008BB658>>

>>> print x.txt("Exit")
txt

Beenden
>>> s = x.txt("Exit")
txt

>>> s
'Beenden'
>>> print _
Beenden
>>> print x.txt("Exit")
txt

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 7, in txt
TypeError: 'str' object is not callable

Uhm, why do I get this error?  Why is _ overwritten with a string?  _ got
defined by t.install() in xhcClass.__init__().  And it got overwritten,
as soon as I executed "s" (on a line by itself).

What's happening here?

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
and
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2

Alexander Skwar
-- 
BOFH excuse #387:

Your computer's union contract is set to expire at midnight.





More information about the Python-list mailing list