473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

numbers to string

>>y
[116, 114, 121, 32, 116, 104, 105, 115]
>>z=''.join(chr(yi) for yi in y)
z
'try this'

What is an efficient way to do this if y is much longer?
(A numpy solution is fine.)

Thanks,
Alan Isaac
Oct 25 '06 #1
4 1096
David Isaac wrote:
>>>y
[116, 114, 121, 32, 116, 104, 105, 115]
>>>z=''.join(chr(yi) for yi in y)
z
'try this'

What is an efficient way to do this if y is much longer?
(A numpy solution is fine.)
With numpy, something like the following:
>>from numpy import *
y = [116, 114, 121, 32, 116, 104, 105, 115]
a = array(y, dtype=uint8)
z = a.tostring()
z
'try this'

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 25 '06 #2
"David Isaac" <ai*****@verizon.netwrites:
>y
[116, 114, 121, 32, 116, 104, 105, 115]
>z=''.join(chr(yi) for yi in y)
z
'try this'

What is an efficient way to do this if y is much longer?
import array
z = array.array('B',y).tostring()
Oct 25 '06 #3
David Isaac wrote:
>>>y
[116, 114, 121, 32, 116, 104, 105, 115]
>>>z=''.join(chr(yi) for yi in y)
z
'try this'

What is an efficient way to do this if y is much longer?
(A numpy solution is fine.)
Here's another numpy solution just for fun:

import numpy
z = numpy.array(y,dtype='u1').view('S%d' % len(y))[0]
-Travis

Oct 25 '06 #4
Robert Kern wrote:
>>from numpy import *
y = [116, 114, 121, 32, 116, 104, 105, 115]
a = array(y, dtype=uint8)
z = a.tostring()
z
'try this'

Very nice! Thanks also to Paul and Travis!
Alan Isaac
Oct 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Lilja | last post by:
Hello, I'm working on my C++ homework and I have a question about the following function. It's part of my code the handles command line arguments. Here's the code: static void...
3
by: Stewart Allen | last post by:
Hi there I'm trying to find part serial numbers between 2 numbers. The user selects a part number from a combo box and then enters a range of serial numbers into 2 text boxes and the resulting...
2
by: pesso | last post by:
I have a string that contains the following: string s = "130,41,43,178,41,17,6,78,244,35,202,144,115"; They are comma separated byte numbers, and I need to initialize my byte array with them....
4
by: Sam Kong | last post by:
Hello! I wonder if there's a good way to make a function that calculates 2 big numbers (whole numbers) expressed as strings and return a result string with the value of a number? For example:...
4
by: Tony WONG | last post by:
i have a number of forms with fax numbers to come up into arrays and then combine to string. after that i design the flow 1. break the string to array now the string looks like this...
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
5
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
9
by: =?Utf-8?B?ZGg=?= | last post by:
If there's bunch of hex numbers: 0xA6, 0xD9, 0x00, 0xAA, 0x00, and 0x62, how to construct a string ("string" in C#) with those hex numbers? Thanks!
3
by: Smokey Grindel | last post by:
Alright so I have a string... that can be anything like this then have a number like 102.34m, yes there is a m behind it to say "this is money", no I didn't design the spec thats just how data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.