[Tutor] Conversion question

Wayne srilyk at gmail.com
Tue Jun 16 20:13:58 CEST 2009


On Tue, Jun 16, 2009 at 12:46 PM, <xchimeras at gmail.com> wrote:

> Quick question.  Say I have a string a="Man" and I want to print the string
> in base2.  Is there a python function like there is in perl to do this?
> Thanks in advance for any input


do you mean like this:

 In [23]: int('Man', 2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/wayne/<ipython console> in <module>()

ValueError: invalid literal for int() with base 2: 'Man'

Or do you mean this?
In [24]: mystr = 'some string'

In [25]: mystr.encode('hex')
Out[25]: '736f6d6520737472696e67'

HTH,
Wayne



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090616/22d0d8dc/attachment-0001.htm>


More information about the Tutor mailing list