[Tutor] Fastest way to iterate through a file

Alan Gauld alan.gauld at btinternet.com
Fri Jul 6 01:03:46 CEST 2007

"elis aeris" <hunter92383 at gmail.com>

>I need some of a something to be imported into python


> these are the functions I need, anyway know anything that might do 
> any of
> the following?

Assuming you are still talking about Windows XP...

> suppose the class' name is autowindow:

What kind of class? No such class exists so are you
proposing to create it? Is it based on a Windows object?

Remember python is a programming language not a GUI toolkit.
If you want to do things to a GUI you need a toolkit. It might
be linked to the native Win32 API through winall or ctypes or
it might be a cross platform toolkit like Tkinter or wxPython,
but its not part of Python.

> autowindow.gainfocus(handle)
> put the window of that handle into focus.

The Win32 SetFocus function does that.

> import autowindow
> autowindow.imagechecksum()
> autowindow.imagechecksum("c:\image\image.bmp")
> autowindow.areachecksum()
> sum = autowindow.areachecksum(x1,y1,x2,y2) absolute screen 
> coordinate

Its unlikely any GUI toolkit will do that, it sounds more like
a job for a graphics toolkit like PIL.

> autowindow.getmousepos()

Mouse events carry the x/y coordinates.
Just trap any mouse move and it will tell you where it is.

> autowindow.restart()
> autowindow.shutdown()

This is hardware dependant, some computers won;t allow it.
But on Windows you can try using the API as described on this page
(which I found with a simple google search on Win32 restart shutdown)


> autowindow.winexist()
> true/false = autowindow.winexist()
> handle or window name. (no class wanted!)

FindWindow will effectively do this.

> autowindow.listwindows()

EnumWindows does this for you

We discussed both of these recently.

> autowindow.GainFocus()

You already asked for this.

> autowindow.KeyboardEvent(text)

Yep, all toolkits allow you to trap a keyboard event.
Most distinguish between key down and key up as well
as the generic keypress.

Or if you want to simulate a keyboard event you can use
PostMessage. Again we discussed this recently.

> autowindow.KeyboardEvent("Python rocks!", keyholddelay )
> keyholddelay = miliseconds.

No idea what this is supposed to be/do.

> autowindow.mouseclick(button, clicks)
> autowindow.MouseEvent(x, y, button, clicks)
> autowindow.mousemove()
> autowindow.mousemove(x,y, speed)
> autowindow.winMove(x, y)
> autowindow.winResize(x, y)
> autowindow.winMinimize()
> autowindow.winMaximize()
> autowindow.winClose()

These are all standard event types.

> they all take handle

And if you want to simulate them use PostMessage

> autowindow.listwindows()
> autowindow.listwindows("window name")
> returns a list of handles if multiple

You are repeating yourself again.

> autowindow.hotkey()
> autowindow.hotkey(keyboard key, function)
> keyboard key = any key on keyboard
> function = function to start

Not sure, there may be a Windows function for this but
I haven't seen it...

> auntwindow.run ( /source/exe.exe, "image.bmp" )

Try ExecFile
or WinExec

> autowindow.msgbox("window name", "window message", box_number )

Standard windows MsgBox function

Have you actually tried looking for these on MSDN for yourself.
They are standard windows functions. They are mapped into Python
by the toolkirs but the basic functions are pure windows and
documented in MSDN.

Recall I  recommended reading the web page on how to ask smart
questions? One of the key points is not to ask the same questions
multiple times of the same audience - and especially not in the
same message!

Also provide some context abvout why you need the information.
What you are trying to achieve etc. Othewise you will get the same
level of vagueness back that you provide.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list