PythonistL wrote: > In my program I use something like this: > > ######### > .... > ... > > for Field in manipulator.fields:
s/F/f/ it's an instance, not a class (Python's convention is to use CamelCase for classes and all_lowers for instances). > #do something > print Field > ..... > ...... > ######### > print Field there > can print the correct value that is e.g. > <input type="text" id="id_Pieces_4" class="vIntegerField" > name="Pieces_4" size="4" value="" maxlength="4" /> > > but because Field is an instance I can not use that in > further processing e.g. > string.replace(Field ,'id=','disabled id=') <OT> use 'disabled="disabled"' (xhtml compatibility) </OT> And : this is not "because field is an instance", this is "because field is not a string" (hint: *everything* in Python is an instance). > Is there any solution to my problem that is how to replace any text in > the Field? s/'text in the field'/'string generated by the field's __str__() method'/ <disclaimer> Sorry if I look overly pedantic, but correct naming is the prerequisite to correct understanding. </disclaimer> Depends on what you're trying to achieve. If you want to get the text generated by the field's __str__() method, modify this text, then use it, you can do something like: tags = [] for field in manipulator.fields: tags.append(str(field).replace('id=', 'disabled="disabled" id=') But this won't impact the field object itself, so further calls to field.__str__ will be as usual. Another solution would be to subclass Fields classes and write your own manipulators, but this would require a lot of (boring) work. Yet another solution solution (and a far better one IMHO) is to take advantage of Python's delegation mechanisms and use the decorator pattern (nb : not tested): class DisabledField(object): def __init__(self, field): self._field = field def __str__(self): return str(self._field).replace('id=', 'disabled="disabled" id=') def __getattr__(self, name): return getattr(self._field, name) for id, field in enumerate(manipulator.fields): manipulator.fields[id] = DisabledField(field) Then you can use your manipulator as usual. My 2 cents... -- bruno desthuilliers développeur [EMAIL PROTECTED] http://www.modulix.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---