[BangPypers] help me to fix this error

Senthil Kumar M msenthil008 at gmail.com
Tue Oct 20 12:18:20 CEST 2009


this works fine.thank you

On Tue, Oct 20, 2009 at 3:38 PM, ashok raavi <ashok.raavi at gmail.com> wrote:

>
>
> On Tue, Oct 20, 2009 at 3:24 PM, Senthil Kumar M <msenthil008 at gmail.com>wrote:
>
>> See this link. I have tried this site but could not find what is the
>> mistake.Thats why I send it here.ok?
>>
>> http://docs.python.org/dev/3.0/library/stdtypes.html?highlight=maketrans#str.maketrans
>>
>>
>> On Tue, Oct 20, 2009 at 3:14 PM, Anand Balachandran Pillai <
>> abpillai at gmail.com> wrote:
>>
>>>
>>>
>>> On Tue, Oct 20, 2009 at 3:11 PM, Senthil Kumar M <msenthil008 at gmail.com>wrote:
>>>
>>>> from string import maketrans
>>>> intab = "aeiou"
>>>> outtab = "12345"
>>>> trantab = maketrans(intab,outtab)
>>>> st = "this is string example....wow!!!";
>>>>  print(st.translate(trantab))
>>>> ------------------------------------------------------
>>>>
>>>> I got this error,
>>>>
>>>> Traceback (most recent call last):
>>>>   File "C:\Python30\fullpath.py", line 4, in <module>
>>>>     trantab = maketrans(intab,outtab)
>>>>   File "C:\Python30\lib\string.py", line 55, in maketrans
>>>>     raise TypeError("maketrans arguments must be bytes objects")
>>>> TypeError: maketrans arguments must be bytes objects
>>>>
>>>
>>> Spend some time learning Python and use this list only for help on
>>> things which you can't figure out even after trying. Don't use the list
>>> as a help() on paste every other Python exception thrown by the
>>> interpreter,
>>> expecting someone to spoon feed your Python trip.
>>>
>>> In this case, check out the Python documentation on string module.
>>>
>>>
>>>
>>>
>>>>
>>>>
>>>>
>>>> On Tue, Oct 20, 2009 at 2:59 PM, Anand Balachandran Pillai <
>>>> abpillai at gmail.com> wrote:
>>>>
>>>>>
>>>>>
>>>>> On Tue, Oct 20, 2009 at 2:40 PM, Senthil Kumar M <
>>>>> msenthil008 at gmail.com> wrote:
>>>>>
>>>>>> ----------------------------------------------------------
>>>>>> #!/usr/bin/python
>>>>>>
>>>>>> from string import maketrans
>>>>>> intab = "aeiou"
>>>>>> outtab = "12345"
>>>>>> trantab = intab.maketrans(outtab)
>>>>>>
>>>>>> str = "this is string example....wow!!!";
>>>>>> print str.translate(trantab);
>>>>>>
>>>>>
>>>>>  "print" is a function from python 3.0. Change this to,
>>>>>  print (str.translate(trantab))
>>>>>
>>>>>  And you don't need semi-colons in Python. Semi-colons
>>>>>  are used only to separate 2 expressions in the same line.
>>>>>  Something like
>>>>>
>>>>>  x=2; print x
>>>>>
>>>>>  Here they are superfluous.
>>>>>
>>>>>  And I think "outtab" should be a dict, not string... but I am not
>>>>> sure.
>>>>>
>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> Thanks for the response.
>>>>>> I changed the code as above
>>>>>> this code too shows an error.
>>>>>>
>>>>>>
>>>>>> On Tue, Oct 20, 2009 at 2:23 PM, Sidharth Kuruvila <
>>>>>> sidharth.kuruvila at gmail.com> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>> This looks like it's because python's strings have change in python
>>>>>>> 3.
>>>>>>> The characters used to be 8bit bytes but now they are 16 bits wide.
>>>>>>>
>>>>>>> A quick google tells me that str now has a method called maketrans so
>>>>>>> s1.maketrans(s2) should work.
>>>>>>>
>>>>>>> I'm guessing you are using a tutorial written for one of the older
>>>>>>> versions of python. I'd suggest you either find a python 3 based
>>>>>>> tutorial or use an older version of python, maybe python 2.6.
>>>>>>>
>>>>>>> ps Can you cut and paste the code into the mail next time, images are
>>>>>>> a pain to work with.
>>>>>>>
>>>>>>> Regards,
>>>>>>> Sidharth
>>>>>>>
>>>>>>> On Tue, Oct 20, 2009 at 1:52 PM, Senthil Kumar M <
>>>>>>> msenthil008 at gmail.com> wrote:
>>>>>>> >
>>>>>>> > I am using python IDLE (python3.0.1) . I dont know why this error
>>>>>>> comes ? I
>>>>>>> > am a new user to python.
>>>>>>> >
>>>>>>> > the link of the image snapshot is
>>>>>>> > http://img197.imageshack.us/img197/3405/pythonshell.png
>>>>>>> >
>>>>>>> > --
>>>>>>> > ********************
>>>>>>> > M.Senthil Kumar
>>>>>>> > ********************
>>>>>>> >
>>>>>>> > _______________________________________________
>>>>>>> > BangPypers mailing list
>>>>>>> > BangPypers at python.org
>>>>>>> > http://mail.python.org/mailman/listinfo/bangpypers
>>>>>>> >
>>>>>>> >
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> I am but a man.
>>>>>>> _______________________________________________
>>>>>>> BangPypers mailing list
>>>>>>> BangPypers at python.org
>>>>>>> http://mail.python.org/mailman/listinfo/bangpypers
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> ********************
>>>>>> M.Senthil Kumar
>>>>>> ********************
>>>>>>
>>>>>> _______________________________________________
>>>>>> BangPypers mailing list
>>>>>> BangPypers at python.org
>>>>>> http://mail.python.org/mailman/listinfo/bangpypers
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> --Anand
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> BangPypers mailing list
>>>>> BangPypers at python.org
>>>>> http://mail.python.org/mailman/listinfo/bangpypers
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> ********************
>>>> M.Senthil Kumar
>>>> ********************
>>>>
>>>> _______________________________________________
>>>> BangPypers mailing list
>>>> BangPypers at python.org
>>>> http://mail.python.org/mailman/listinfo/bangpypers
>>>>
>>>>
>>>
>>>
>>> --
>>> --Anand
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> BangPypers mailing list
>>> BangPypers at python.org
>>> http://mail.python.org/mailman/listinfo/bangpypers
>>>
>>>
>>
>>
>> --
>> ********************
>> M.Senthil Kumar
>> ********************
>>
>> _______________________________________________
>> BangPypers mailing list
>> BangPypers at python.org
>> http://mail.python.org/mailman/listinfo/bangpypers
>>
>>
> from string import maketrans
>
> as the error message suggests arguments to maketrans must be byte object
>
> intab = b"aeiou"
> outtab = b"12345"
>
>
> trantab = maketrans(intab, outtab)
>
> st = "this is string example....wow!!!";
> print(st.translate(trantab))
>
>
>
> --
> ashok raavi
>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
>


-- 
********************
M.Senthil Kumar
********************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20091020/980020f2/attachment-0001.htm>


More information about the BangPypers mailing list