Can this be reversed (Tkinter)?
Dave K
dk123456789 at hotmail.com
Fri Jan 2 19:51:04 EST 2004
On Fri, 2 Jan 2004 12:49:08 -0800 in comp.lang.python, "mark"
<mark at diversiform.com> wrote:
>I am looking at the format used by root.geometry(). The string returned
>from root.geometry() is "%dx%d+%d+%d". Is there a quick and painless
>way to extract the values from that string (i.e., "100x150+25+25" =>
>(100,150,25,25))?
>
>- Mark
For that particular string, I can think of 2 one-liners:
>>> s='100x150+25+25'
>>> print tuple([int(x) for x in s.replace('x', '+').split('+')])
(100, 150, 25, 25)
>>> print tuple([int(x) for y in s.split('x') for x in y.split('+')])
(100, 150, 25, 25)
For more general use, the regular expression "\d+" will match positive
integers:
>>> s='100x150+25+25/(34*7);12-34*(56%78/9)'
>>> import re
>>> print tuple([int(x) for x in re.findall('\d+', s)])
(100, 150, 25, 25, 34, 7, 12, 34, 56, 78, 9)
Dave
More information about the Python-list
mailing list