Print a C string in Python
<p>I want to print a C string using the Python <code>print</code> statement. The array <code>vendorName</code> contains the ASCIIZ C string <code>A ANTHONY &amp; SONS INC</code>. My motivation is to convert the C string to a Python string such that I can use all of the Python string methods. </p>

<p>I have a struct:</p>

<pre><code>class _vendrRecord(Structure):
    _pack_ = 1                                            # pack the struct
    _fields_ = [
        ("vendorName"            ,c_ubyte *(40 + 1)),
        ("ytdPayments"           ,c_ulong),
        ]
</code></pre>

<p>I want to print the string "vendorName" which is ASCIIZ. </p>

<p>I can print it using printf like this:</p>

<pre><code>printf(b"%s\n", vendrRecord.vendorName)
</code></pre>

<p>I have tried this <code>print(vendrRecord.vendorName)</code> but it just prints the address. Based on information from Jamie Nicholl-Shelley, I tried <code>print(cast(vendrRecord.vendorName,c_char_p).value)</code> but that gives <code>b'A ANTHONY &amp; SONS INC'</code>. I want simply <code>A ANTHONY &amp; SONS INC</code> </p>

<p>Note that <code>print(vendrRecord.ytdPayments)</code> prints correctly.</p>