if statements

Alex Martelli aleax at aleax.it
Fri Jan 18 18:12:48 CET 2002


"maximilianscherr" <MaximilianScherr at T-Online.de> wrote in message
news:mailman.1011364768.32194.python-list at python.org...
    ...
>     xmlstr = "<?xml version='1.0'?>"
>     xmlstr = xmlstr +"<config"
>     xmlstr = xmlstr +"last_server=\"0\""
    [snipped lots of other xmlstr = xlmstr + ...]

Don't do that.  That's wasting a LOT of performance.  NEVER build up
a big string with a zillion s = s + ... (or s += ... which turns out
to be the same thing).  You could do:

    xmlstr = ( "<?xml version='1.0'?>"
        + "<config"
        + "last_server=\"0\""

and so on, just close the ) when done to terminate the logical line.

Or, more generally:
    xmlpieces = ["<?xml version='1.0'?>"]
    xmlpieces.append("<config")
    xmlpieces.append("last_server=\"0\"")

and so on, then, when done:
    xmlstr = ''.join(xmlpieces)

Either approach is vastly preferable.


> def launch():
>     savecheck()                       <---ok heres my big question
>     ie = os.popen("ilaunch.exe", "w") <---how can i start that prog
>     ie.write("L")                     <---(normal windows one) and
>     ie.close()                        <---send a keyboard input to
>                                       <---it like "l", cause it has
<---a button binding for launch

You need the win32all extensions (or ActiveState's ActivePython,
that comes with win32all already added) and the Windows Scripting
Host (WSH) component from Microsoft.  See
http://aspn.activestate.com/ASPN/Mail/Message/activepython/544878
for a good example of using the SendKeys method of the WSH object
WScript.Shell.


> def close():<---would this overwrite
>     savecheck()<-the normal file.close()
>     window.quit()

It would override it only if it was a method of a class
inheriting from file, and only for instances of that class.


Alex






More information about the Python-list mailing list