Make sure what data type is really being returned by part.getpayload() .  Perhaps it is already in a suitable for when you get it?<br><br>The Python 2.x language method of loading a binary blob of memory is to use the built in function &quot;buffer&quot;<br>

 <br>s = &#39;this is a string&#39;<br>b = buffer(s)<br><br>&quot;b&quot; will be accepted my a byte arrary in most cases.<br><br>but make sure that what you have is a legal ASCII string.  CPython stores &quot;strings&quot; in ASCII and &quot;unicode&quot; differently. Iron Python stores &quot;strings&quot; in unicode, and buffer() tries to be smart about hiding that fact, in order to act like CPython in the easy cases.  The above will work the same in either IronPython or CPython.<br>

<br>On the other hand, in CPython:<br>u =  u&#39;this is a unicode string&#39;<br>b = buffer(u)<br>will produce a blob twice (or four times) as long as the above, since it stores all 16 (or 32) bits of  the character code.<br>

(IronPython seems to store them internally in UTF-8 or some similar code.)  To convert to &quot;proper&quot; 8-bit codes you must use something like:<br><br>u = u&#39;unicode string&#39;<br>b = buffer(u.encode(&#39;latin-1&#39;))<br>

<br>Python 3.x removes the problem by defining all character strings as unicode (as IronPython does now), and providing a byte() function, in which each 8 byte is treated as an integer, rather than a character. That will make things simpler in the future.<br>

--<br>VC<br><br><br><br><div class="gmail_quote">On Wed, Nov 11, 2009 at 8:14 AM, matan keret <span dir="ltr">&lt;<a href="mailto:matan504@gmail.com">matan504@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div dir="ltr"><div>hi, </div>
<div> </div>
<div>I have the following code which gets an image from an email.</div>
<div>after getting it i need to pass it as a byteArray (byte[] in C#) to a C# function.</div>
<div>i tried all sorts of things but no luck. I&#39;m using ironPython 2.0.3</div>
<div> </div>
<div>the important parts of the code are: </div>
<div> </div>
<div># getting the image from the e-mail</div>
<div>image = part.get_payload()</div>
<div> </div>
<div># my try to cast the str into a byteArray</div>
<div>byteArray = BitConverter.GetBytes(image.ToCharArray())</div>
<div> </div>
<div> </div>
<div>this last line returns 1 byte and doesn&#39;t seem to do the job.</div>
<div>is there any <span style="font-family: Arial; color: rgb(0, 0, 153);"><font color="#000000">equivalent to the &#39;bytearray(image)&#39; function in CPython?</font></span></div>
<div><span style="font-family: Arial; color: rgb(0, 0, 153);"><font color="#000000"></font></span> </div>
<div><span style="font-family: Arial; color: rgb(0, 0, 153);"><font color="#000000">thanks,</font></span></div>
<div><span style="font-family: Arial; color: rgb(0, 0, 153);"><font color="#000000">Matan</font></span></div>
<div> </div></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>