Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: parse VARIANT (?)
    primarykey
    data
    text
    <p>I have to read a file in python that uses <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa380072%28v=vs.85%29.aspx" rel="nofollow">Microsoft <code>VARIANT</code></a> (I think - I really don't know much about Microsoft code :S). <strong>Basically I want to know if there are python packages that can do this for me.</strong></p> <p>To explain - the file I'm trying to read is just a whole bunch of <code>{ 2-byte integer, &lt;data&gt; }</code> repeated over and over, where the 2-byte integer specifies what the <code>&lt;data&gt;</code> is.</p> <p>The 2-byte integer corresponds to the Microsoft data types in VARIANT: <code>VT_I2</code>, <code>VT_I4</code>, etc, and based on the type I can write code to read in and coerce <code>&lt;data&gt;</code> to an appropriate Python object.</p> <p>My current attempt is along the following lines:</p> <pre><code>while dtype = file.read(2): value = None # translate dtype (I've put in VT_XX myself to match up with Microsoft) if dtype == VT_I2: value = file.read(2) elif dtype == VT_I4: value = file.read(4) # ... and so on for other types # append value to the list of values # return the values we read return values </code></pre> <p>The thing is, I'm having trouble working out how to convert some of the bytes to the appropriate Python object (for example <code>VT_BSTR</code>, <code>VT_DECIMAL</code>, <code>VT_DATE</code>). However before I try further, I'd like to know <strong>if there are any existing python packages that do this logic for me (i.e. take in a file object/bytes and parse it into a set of python objects, be they float, int, dates, strings, ...).</strong></p> <p>It just seems like this is a fairly common thing to do. However, I've been having difficulty looking for packages to do it because not knowing anything about Microsoft code, I don't have the terminology to do the appropriate googling. (<strong>If it is relevant, I am running LINUX</strong>).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload