If I use "string cat {} $value" before returning to python, it is always
a string in python.
Thus, my question is: is there a way in tcl (script level) to say that
an object is a string or other type, and convert it to a string if it is
not?
If I use "string cat {} $value" before returning to python, it is always
a string in python.
do you need the {}
string cat $value
might work just as well.
I'm not familiar with python or tkinter, but if you might be able to use "$value"
if the value is parsed by the tcl command line before it is sent back to the python environment.
Thus, my question is: is there a way in tcl (script level) to say that
an object is a string or other type, and convert it to a string if it is
not?
However Tcl is all about everything is a string except under the covers, and we never look there. It looks like python only looks under the covers though.
Dave B
Is there a tcl command, that will enforce this conversion?
The problem is, that if I access the objects from python's tkinter, and
the problem is that what I get back in python, depends on the tcl
object's internal representation.
Georgios Petasis <[email protected]> wrote:
The problem is, that if I access the objects from python's tkinter, and
the problem is that what I get back in python, depends on the tcl
object's internal representation.
This is really a "bug" wrt "EIAS" inside tkinter.
There are some "brute-force" ways to turn something into a pure string, like prepending a char, and then extracting the substring from it:
[string range x$val 1 end]
though these brute-force ways may cost performance if strings are long.
Also, it is not guaranteed, that some far future version of tcl might
not even recognize that pattern and still reproduce the original object.
Even more brute-force: [join [split $val {}] {}] is likely another big bit slower, as it will create a list of each char, before smashing it back together into a string, but it's damn likely, that this will not be
optimized away, any time thinkable.
Maybe tkinter itself has some C-functions to coerce internal objects to
what is then expected in python... if not, that might be the best place
for them: at the boundary to a not as dynamically typed language.
Στις 6/4/2022 17:17, ο/η Andreas Leitgeb έγραψε:
Georgios Petasis <[email protected]> wrote:
The problem is, that if I access the objects from python's tkinter, andThis is really a "bug" wrt "EIAS" inside tkinter.
the problem is that what I get back in python, depends on the tcl
object's internal representation.
...
Maybe tkinter itself has some C-functions to coerce internal objects to
what is then expected in python... if not, that might be the best place
for them: at the boundary to a not as dynamically typed language.
The solution I gave was to add a command to my C extension, which
exposes Tcl_ConvertToType(). This solves the problem, as it enforces a conversion to type "string".
But I think these commands should be available at the Tcl level. To
check what type an object is, and convert it to another type.
Georgios Petasis <[email protected]> wrote:
Στις 6/4/2022 17:17, ο/η Andreas Leitgeb έγραψε:
Georgios Petasis <[email protected]> wrote:
The problem is, that if I access the objects from python's tkinter, and >>>> the problem is that what I get back in python, depends on the tclThis is really a "bug" wrt "EIAS" inside tkinter.
object's internal representation.
...
Maybe tkinter itself has some C-functions to coerce internal objects to
what is then expected in python... if not, that might be the best place >>> for them: at the boundary to a not as dynamically typed language.
The solution I gave was to add a command to my C extension, which
exposes Tcl_ConvertToType(). This solves the problem, as it enforces a
conversion to type "string".
But I think these commands should be available at the Tcl level. To
check what type an object is, and convert it to another type.
This non-EIAS-based approach is very unlikely to go into Tcl itself.
On the other hand, it seems perfectly right in the context of this language-border, to offer functions for python (or the C code glueing
parts together) to express: "treat this value as a string (or maybe
even numeric value, list, dict) no matter what internal object type
Tcl-side last used for it"
I am not concerned with what python (or any other caller) does. I am
more concerned that I do not have the tools to deal with the situation,
and I have to revert to writing a C extension.
George
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 08:53:11 |
| Calls: | 12,100 |
| Files: | 15,003 |
| Messages: | 6,517,961 |