[python-win32] win32api documentation
Tim Golden
mail at timgolden.me.uk
Tue Oct 13 18:33:10 CEST 2009
J wrote:
> And it does indeed work. We're using the latest 2.6, and so far
> everything has worked well. NumberOfCores and
> NumberOfLogicalProcessors does just what I hoped they would do, so now
> I have a small bit of n00b code:
>
> print "Getting processor information now...\n"
I suspect you're coming from a C background? Or something
similar. Python's a very versatile language and tries to
help you avoid boilerplate. So you can do things like this:
<code>
import wmi
c = wmi.WMI ()
numProcs = len (c.Win32_Processor ())
print "Number ...:", numProcs
# or
print "Number ...: %s" % numProcs
</code>
and likewise for your other print statement. (Watch out:
print has become a function in Python 3.x). The percent-s
thing works just like sprintf in C only with a Python touch:
you can use a more restrictive %d %2.3f etc. but if you put
%s, Python calls your object's __str__ method which will usually
generate what you expect to see.
> numProcs = len(c.Win32_Processor ())
> print "Number of Processor Packages found: " + str(numProcs)
> for p in c.Win32_Processor ():
> print "Number of processor cores: " + str(p.NumberOfCores)
> print "Number of Logical processors: " + str(p.NumberOfLogicalProcessors)
> if p.NumberOfCores != p.NumberOfLogicalProcessors :
> print "HyperThreading seems to be enabled."
>> This is definitely the place to look for this kind of information:
>>
>> http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx
>>
>> unfortunately, some of the useful information like NumberOfCores
>> and NumberOfLogicalProcessors seems to be available only on the
>> very latest releases. Might be an issue for you?
>
> THANKS! Once again, you're wisdom blows my mind ;-) and your link-fu.
I blush. But in fact (he says, giving away all his secrets) my
magic incantation was simply this:
http://www.google.co.uk/search?q=site%3Amicrosoft.com+win32_processor
Of course, I have done that once or twice before ;)
>> Glad it's been useful. I'm just releasing a new version of the
>> Python module which includes a little web server whichi lets you
>> browse around the classes to a limited extent. If you're interested,
>> let me know.
>
> Sure... it'd be neat to play with. Like I've said before, this is
> going to be actually useful, but I'm doing it out of boredom and as a
> learning experience more than I am doing it to benefit work or
> anything like that. They don't pay me enough to really want to work
> for their benefit ;-)
I'll put a release notice out in the next day or two and let you
know where you can get hold of it.
> I have run into another issue though with the various Memory classes...
[... snip rather specific Memory stuff ...]
I'm afraid I've no particular insight here. I'm sure I can Google
around a bit to see, but I'm sure you can too...
Keep posting to the list and let's see if someone else has
an idea.
TJG
More information about the python-win32
mailing list