On Mon, Nov 17, 2008 at 7:08 PM, Michael Lange <[EMAIL PROTECTED]> wrote: > On Sun, 16 Nov 2008 19:21:34 -0200 > "Guilherme Polo" <[EMAIL PROTECTED]> wrote: > >> On Sun, Nov 16, 2008 at 6:59 PM, Michael Lange <[EMAIL PROTECTED]> wrote: >> > On Sun, 16 Nov 2008 17:18:54 -0200 >> > "Guilherme Polo" <[EMAIL PROTECTED]> wrote: >> > >> >> On Sun, Nov 16, 2008 at 4:59 PM, Vasilis Vlachoudis >> >> <[EMAIL PROTECTED]> wrote: >> >> > Finally I didn't understand, is it a problem of Tkinter or Tk/Tcl? >> >> >> >> It is not really a problem. But if you want to blame someone, go for >> >> Python then. >> >> >> > >> > If you get unexpected and , if the software you write is supposed to run on >> > different platforms, also unpredictable behavior like this I think it *is* >> > a >> > problem. >> >> I meant more in these sense of the conversion raising some exception, >> but it can be seen in that way too sure. But this doesn't depend on >> the platform, all them will show this behaviour. >> > > O.k., by "platform" I actually meant different linux / unix systems with > different versions of Python / Tk installed. > > (...) > >> >> Good for you then :) >> It gets hard to continue arguing about this now, since you apparently >> solved the question on your side and thus won't have real examples of >> this problem, and why it couldn't be solved, anymore (or maybe you do, >> so we can continue on this). > > Using Tk-8.5 it is not too hard to find examples: > >>>> from Tkinter import * >>>> root = Tk() >>>> t = Text(root) >>>> t.pack() >>>> t.insert('end', 'foobar') >>>> i = t.index('end') >>>> i > <textindex object at 0x81e0ba8> >>>> print i > 2.0 >>>> int(i) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: int() argument must be a string or a number, not '_tkinter.Tcl_Obj' >>>> str(i) > '2.0' >
You surely can find examples, but that is not what I was asking for. I was asking for code examples where this conversion would be trouble some. Nevertheless the example is good in the sense to show that Tkinter was "relatively broken" on that method and now it is fixed on python 2.6 (doing an explicit conversion), and I will check if I can backport the fix to the release25-maint so Python 2.5.3 comes with that fixed too. And while this example doesn't really show what I were expecting, it shows what you should do know in your other wrappers (supposing you are using other wrappers to tcl/tk). You know the method index of Text has to give the user a string representing 'line.char', so if it gives you a Tcl_Obj, then just return its string representation. >> >> > The problem is that you never seem >> > to know where the TclObjects appear on Python / Tk versions other than >> > your own. >> > So what else to do? Convert everything Tk returns to string? >> >> No, like I said, who calls into _tkinter should know what kind of >> object to expect so you do the conversion yourself. If you are going >> to return the object to the user, then surely check if it is what you >> are expecting it to be. >> >> Now, I'm sure this can be improved in Python but you have to invest >> some time on it. > > So you mean, the only option to fix this is to write patches for Tkinter.py, > resp. the other modules in lib-tk, so the return values of "broken" methods > are converted from TclObjects into string (or whatever seems adequate)? > Uhm, I never said that was the only option, did I ? But it is surely the easiest way, if you want to stay in Python (.py) code only. And please note that I'm not saying to always leave it as a string, that breaks the point of expecting objects. > Michael > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss