sciter-sdk / pysciter

Python bindings for Sciter
https://sciter.com
MIT License
396 stars 40 forks source link

element.value, when finding things, includes quotes #36

Open martinlombana opened 3 years ago

martinlombana commented 3 years ago

When finding an element value, like such:

<body>
 <editbox name="WHATEVER" value="ferpection"/>
</body>
element: Element = root.find_first("[name~=WHATEVER]")
            if element is not None:
                print('element.value-> ', element.value, flush=True)

This alocates the value of "ferpection", to the string. So the string, becomes, actually: '"ferpection"', with the quotes.

Took me a good time to find this and debug my code because I was getting False check returns, because I was comparing the value of the string with the quotes.

Bottomline, I think, when accessing the value of an element, it should not contain the quotes, because they are not part of the value itself. (Unless there is a good reason for it, somehow). But having to remove them myself, seems cumbersome and prone to error...

Thanks!

pravic commented 3 years ago

The code looks strange.

It should be element.get_value() if it's Python.

As for the quotes - str(value) (which is called by print(value)) is used for the string representation of the value hence the quotes. Use repr(value) for debugging and value.get_value() for converting the Sciter value to a corresponding Python type.

So, to sum up: element.get_value().get_value().