Re: String to char and decimal number conversion

2011-01-11 Thread Stefan Behnel
SANKAR ., 11.01.2011 01:00: I am reading a Test.txt (see atatchment) file using following code to get the T2: F =open('C:\Test.txt','r') T1 = F.readlines() for i in range(len(T1)): T2 = T1[i].split(',') print(T2) Take a look at the "csv" module in the standard library. Stefan

Re: String to char and decimal number conversion

2011-01-11 Thread Davish Bhardwaj
On Jan 11, 4:02 am, Chris Rebert wrote: > On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . wrote: > > Hello There, > > >    I am from non IT field also new to python programming.Could you > > please help me to solve the following problem? > > > I have a list T1 with following format: > > > T1 = [ '

Re: String to char and decimal number conversion

2011-01-10 Thread SANKAR .
Thanks Alan! -Sankar On Tue, Jan 11, 2011 at 2:50 PM, Alan Meyer wrote: > On 1/10/2011 6:02 PM, Chris Rebert wrote: > >> On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . wrote: >> >>> Hello There, >>> >>> >>>I am from non IT field also new to python programming.Could you >>> please help me to

Re: String to char and decimal number conversion

2011-01-10 Thread Alan Meyer
On 1/10/2011 6:02 PM, Chris Rebert wrote: On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . wrote: Hello There, I am from non IT field also new to python programming.Could you please help me to solve the following problem? I have a list T1 with following format: T1 = [ ' "Field" ' , ' "12.5"

Re: String to char and decimal number conversion

2011-01-10 Thread SANKAR .
Hi Chris , Thanks for your response. I am reading a Test.txt (see atatchment) file using following code to get the T2: F =open('C:\Test.txt','r') T1 = F.readlines() for i in range(len(T1)): T2 = T1[i].split(',') print(T2) Regards Sankar On Tue, Jan 11, 2011 at 10:02 AM, Chris Re

Re: String to char and decimal number conversion

2011-01-10 Thread Chris Rebert
On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . wrote: > Hello There, > >    I am from non IT field also new to python programming.Could you > please help me to solve the following problem? > > I have a list T1 with following format: > > T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" '] > > How do get the

String to char and decimal number conversion

2011-01-10 Thread SANKAR .
Hello There, I am from non IT field also new to python programming.Could you please help me to solve the following problem? I have a list T1 with following format: T1 = [ *' "*Field*" **' , ' "*12.5*" **', ' "*2.5*" ']* * * How do get the list elements without double quote in my output (T

Re: String/Number Conversion

2008-09-06 Thread Scott David Daniels
Andreas Hofmann wrote: I've got some strings, which only contain numbers plus eventually one character as si-postfix (k for kilo, m for mega, g for giga). I'm trying to convert those strings to integers, with this function: Why bother to always switch the case if you only use a few values? Als

Re: String/Number Conversion

2008-09-06 Thread Andreas Hofmann
Thanks a lot, I got it working now. Thanks also to the other guys, your numerous hints were really valuable! Kind regards, Andy John Machin schrieb: On Sep 7, 7:04 am, Andreas Hofmann <[EMAIL PROTECTED]> wrote: Hello Folks! I've got a little problem here, which which really creeps me out at t

Re: String/Number Conversion

2008-09-06 Thread bearophileHUGS
Andreas Hofmann, there are several problems in your code: > if type(value) is str: Better to use isinstance() and to compare it with basestring instead. > value.upper() This does nothing, python strings are immutable, so they don't get changed in-place, so you have to

Re: String/Number Conversion

2008-09-06 Thread John Machin
On Sep 7, 7:29 am, Wojtek Walczak <[EMAIL PROTECTED]> wrote: > On Sat, 06 Sep 2008 23:04:14 +0200, Andreas Hofmann wrote: > >                  if mult is 1: > >                            ^^ > You're testing for identity, not for equality. > Change it to "if mult == 1". Is it alright now? > Althou

Re: String/Number Conversion

2008-09-06 Thread John Machin
On Sep 7, 7:04 am, Andreas Hofmann <[EMAIL PROTECTED]> wrote: > Hello Folks! > > I've got a little problem here, which which really creeps me out at the > moment. > I've got some strings, which only contain numbers plus eventually one > character as si-postfix (k for kilo, m for mega, g for giga).

Re: String/Number Conversion

2008-09-06 Thread Wojtek Walczak
On Sat, 06 Sep 2008 23:04:14 +0200, Andreas Hofmann wrote: Hi, > I've got a little problem here, which which really creeps me out at the > moment. > I've got some strings, which only contain numbers plus eventually one > character as si-postfix (k for kilo, m for mega, g for giga). I'm trying

Re: String/Number Conversion

2008-09-06 Thread josh logan
On Sep 6, 5:04 pm, Andreas Hofmann <[EMAIL PROTECTED]> wrote: > Hello Folks! > > I've got a little problem here, which which really creeps me out at the > moment. > I've got some strings, which only contain numbers plus eventually one > character as si-postfix (k for kilo, m for mega, g for giga).

String/Number Conversion

2008-09-06 Thread Andreas Hofmann
Hello Folks! I've got a little problem here, which which really creeps me out at the moment. I've got some strings, which only contain numbers plus eventually one character as si-postfix (k for kilo, m for mega, g for giga). I'm trying to convert those strings to integers, with this function:

Re: Lossless Number Conversion

2005-08-29 Thread Raymond L. Buvel
Chris Spencer wrote: > Is there any library for Python that implements a kind of universal > number object. Something that, if you divide two integers, generates a > ratio instead of a float, or if you take the square root of a negative, > generates a complex number instead of raising an exception?

Re: Lossless Number Conversion

2005-08-29 Thread Andreas Kostyrka
Am Sonntag, den 28.08.2005, 21:36 + schrieb Chris Spencer: > Is there any library for Python that implements a kind of universal > number object. Something that, if you divide two integers, generates a > ratio instead of a float, or if you take the square root of a negative, > generates a co

Re: Lossless Number Conversion

2005-08-28 Thread [EMAIL PROTECTED]
Chris Spencer wrote: > Is there any library for Python that implements a kind of universal > number object. Something that, if you divide two integers, generates a > ratio instead of a float, or if you take the square root of a negative, > generates a complex number instead of raising an exception

Lossless Number Conversion

2005-08-28 Thread Chris Spencer
Is there any library for Python that implements a kind of universal number object. Something that, if you divide two integers, generates a ratio instead of a float, or if you take the square root of a negative, generates a complex number instead of raising an exception? Lisp has something like

Re: number conversion

2005-04-06 Thread John Machin
On 6 Apr 2005 12:01:23 -0700, [EMAIL PROTECTED] wrote: >I'm writing a program to read in raw data from a WAV file, and write it >to an IT file. I got this to work in C by reading the data into an >array of unsigned chars called "RawDataAry", then converted it to >signed chars by doing the followi

Re: number conversion

2005-04-06 Thread Peter Hansen
[EMAIL PROTECTED] wrote: fmt = str(chunklen) + 'B' fmtsize = struct.calcsize(fmt) rawdata = struct.unpack(fmt, s[:fmtsize]) rawdata = list(rawdata) Then I tried to convert it: charary = array.array('b') charary.fromlist(rawdata) Uh, don't you want to be consistent in your use of signed and unsigned

number conversion

2005-04-06 Thread nicksjacobson
I'm writing a program to read in raw data from a WAV file, and write it to an IT file. I got this to work in C by reading the data into an array of unsigned chars called "RawDataAry", then converted it to signed chars by doing the following: signed char *CharAry = malloc(sizeof(signed char) * fra

Re: pre-check for string-to-number conversion

2005-02-12 Thread 18k11tm001
Yes, I suppose exceptions are the best way to handle this problem. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-check for string-to-number conversion

2005-02-12 Thread Steven Bethard
[EMAIL PROTECTED] wrote: I am reading an ASCII data file and converting some of the strings to integers or floats. However, some of the data is corrupted and the conversion doesn't work. I know that I can us exceptions, but they don't seem like the cleanest and simplest solution to me. You should r

pre-check for string-to-number conversion

2005-02-12 Thread 18k11tm001
I am reading an ASCII data file and converting some of the strings to integers or floats. However, some of the data is corrupted and the conversion doesn't work. I know that I can us exceptions, but they don't seem like the cleanest and simplest solution to me. I would like to simply perform a pre-

Re: pre-check for string-to-number conversion

2005-02-12 Thread Michael Hoffman
[EMAIL PROTECTED] wrote: I know that I can us exceptions, but they don't seem like the cleanest and simplest solution to me. Stop worrying and learn to love exceptions. :) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list