Re: WindowsXP/ CTypes - How to convert ctypes array to a string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Lundh

    Re: WindowsXP/ CTypes - How to convert ctypes array to a string?

    dudeja.rajat@gm ail.com wrote:
    I've used CTYPES module to access a function from a dll. This function
    provides me the version of the dll. This information is accessible to
    me as an array of 4 long inetegers. information as :
    2, 1, 5, 0
    >
    I want to display these elements concatenated as "v2.1.5.0". This
    string ( I'm thinking of writing the above 4 array elements to a
    string) is to be displayed as label in a GUI ( the GUI used is Tk)
    >
    Please suggest how can I write these elements to a string to get me
    the desired results as "v2.1.5.0". And, is writing to a string is
    right way?
    any special reason why you're not reading replies to your previous post?

    here's what I wrote last time.

    expecting that Python/ctypes should be able to figure out that you
    want an array of 4 integers printed as a dot-separated string is a
    bit optimistic, perhaps. but nothing that a little explicit string
    formatting cannot fix:
    >>from ctypes import *
    >>versionArr = c_long * 4
    >>version = versionArr(1, 2, 3, 4)
    >>"%d.%d.%d.% d" % tuple(version)
    '1.2.3.4'

    inserting a "v" in the format string gives you the required result:
    >>"v%d.%d.%d.%d " % tuple(version)
    'v1.2.3.4'

    </F>

Working...