subclassing built-in types

G

Gabriel Cooper

I have data in lists of dictionaries with an accompanying array that I
would like to be able to treat as a normal array of strings so that it
will work with predefined functions that work with such, but I would
also like to have the ability to add and manipulate attributes, such as
each field's padding for output of the corresponding data:

(Running on RHFC2)

Python 2.3.3 (#1, May 7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
[...]
IDLE 1.0.2 def __init__(self, thestring, padding=0, *args,**kargs):
str.__init__(self,thestring, *args,**kargs)
self.padding = padding


Traceback (most recent call last):
File "<pyshell#205>", line 1, in -toplevel-
x = myString("hello",40)
TypeError: str() takes at most 1 argument (2 given)
(in other words, I can do it in two steps, not one. I also tried
UserString and string as superclasses.)
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top