0

In python I need to convert TextBuffer into GtkSourceBuffer. How Do I achieve this ?

drahnr
  • 6,782
  • 5
  • 48
  • 75
Sagar
  • 2,315
  • 7
  • 25
  • 34
  • I guess you mean `GtkTextBuffer`, right? – drahnr Mar 21 '14 at 11:12
  • Yes that's what I means. – Sagar Mar 21 '14 at 12:16
  • possible duplicate of [Cast base class to derived class python (or more pythonic way of extending classes)](http://stackoverflow.com/questions/3464061/cast-base-class-to-derived-class-python-or-more-pythonic-way-of-extending-class) – drahnr Mar 21 '14 at 12:19
  • 2
    the actual question is: what are you trying to achieve? a `SourceBuffer` is a `TextBuffer`, so you can pass any instance of the former to any method or signal of the latter. you cannot do the opposite, obviously, or you'd be violating the substitution principle of the type system. – ebassi Mar 21 '14 at 13:39

1 Answers1

0

You could just do

txtbuf.__class__ = GtkSourceBuffer

which should work as long as txtbuf actually is an instance of type GtkSourceBuffer.

drahnr
  • 6,782
  • 5
  • 48
  • 75