strings problem

Peter Abel p-abel at t-online.de
Fri Jul 4 17:18:28 EDT 2003


"Jimmy verma" <jim_938 at hotmail.com> wrote in message news:<mailman.1057340587.28530.python-list at python.org>...
> Hello *.*
> 
> Can you please tell me how can i have the output in no's, instead of string 
> from this program:
> 
> #/usr/bin/python
> import re
> import string
> 
> def csNumEncode(num):
>     if(num>=-107 and num<=107):
>         return chr(num+139)
>     elif(num>=108 and num<=1131):
>         return chr(((num-108)/256)+247) + chr((num-108)%256)
>     else:
>         print 'do nothing'
> 
> re_num = re.compile("\-?[0-9]+(\.[0-9]+)?")
> 
> 
> def CompileCS(source):
>   result=''
>   for tkn in re.split('[ \n\t]+', source):
>     print "Token: %s"%tkn
>     if re_num.match(tkn):
>         result = result + csNumEncode(string.atoi(tkn))
>     else:
>         raise SyntaxError, "%s is invalid operator"%tkn
>   return result
> 
> src1 = '50  800'
> 
> t = CompileCS(src1)
> 
> print t
> 
> 
> 
> The output is
> 
> Token: 50
> Token: 800
> \275\371\264
> 
> 

I didn't check every line of your script.
Maybe in some earlier lines you can do some manipulation of data.

> Instead of this i want the output should be in no's like this:
> bdF9B4

But concerning the output the following two lines can do what you want:
>>> yourOutput='\275\371\264'
>>> print '%02x%02X%02X'%tuple(map(ord,yourOutput))
bdF9B4


> 
> Your suggestions will be welcomed.
> 
> Thanks a lot.
> 
> Regards,
> Jim
> 
> _________________________________________________________________
> Looking for love? Yearning for friendship? http://www.msn.co.in/Romance/ 
> You're in the right place.

Regards
Peter




More information about the Python-list mailing list