[Python-au] Iron Python Byte Array / String question

Kinsley Turner kingsleyturner at westpac.com.au
Fri Aug 25 04:00:28 CEST 2006

Just for the record:

> def receive(self):
>     rx_buffer = '*' * 1024
>     rx_buffer = System.BitConverter.GetBytes(rx_buffer.ToCharArray())
>     bytes_rx  = System.Net.Sockets.Socket.Receive(self.socket,rx_buffer)
>     if (bytes_rx > 0):
>         encoder = System.Text.UTF8Encoding()
>         self.incoming_message += encoder.GetBytes(rx_buffer)  ### LINE 
>         print "MESSAGE ["+self.incoming_message+"]"
> However, I can't convert the byte array back to any kind of string:

System.Text.Encoding.Default.GetString(<byte array object>) 
seems to work.

I'm a bit miffed I couldn't just use str(<byte array>),
this doesn't explain why System.Text.UTF8Encoding.GetBytes() 
didn't work either (neither did ASCIIEncoding).


(obnoxious non-removable corporate .sig follows, my apologies)

Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately.

It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments.

This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency.

Westpac Banking Corporation ABN 33 007 457 141.

More information about the python-au mailing list