473,703 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1106
David Isaac wrote:
>>>y
[116, 114, 121, 32, 116, 104, 105, 115]
>>>z=''.join(ch r(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*****@verizo n.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(ch r(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,d type='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
2740
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 extract_numbers(const char* optarg, vector<string>& numbers) { const char* str = optarg; while(true)
3
3273
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 query should find every machine that has that part number between the serial number range. The problem is that the serial number stored is a text field and the results are not what they should be.
2
3292
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. Looks like I need a loop or something. What would be the best way to take a comma separated string to initialize a byte array using cs?
4
1816
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: string MyAdd(string s1, string s2); s = MyAdd("10", "20"); //=> returns "30"
4
2729
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 12345678,23456789,34567890... 2. check record-2 again record-1, check record-3 again record-2 & record-1 check record-4 again record-3 & record-2 & record-1 and so on... (if duplicated, drop it)
17
4619
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 23578 the label would say: Sumof odd number is: 15 Sum of even number is: 10 any ideas?
5
3293
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 "special" because they are easily translated into words. You've been asked to create a list of phone numbers that are directly mappable to words by searching a dictionary for every 7 or 10 letter word that maps on to the phone lettering scheme: ...
9
4514
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
2527
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 comes in... well I had a regex that replaces all those m's in a string where there is a number before it with no m... so its just the string with 102.34... well this worked fine until we got negative money! so now when its -102.34m it still has the...
0
8755
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8667
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9116
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9013
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7860
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2063
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.