[BangPypers] help me to fix this error

Sidharth Kuruvila sidharth.kuruvila at gmail.com
Tue Oct 20 11:21:49 CEST 2009


Hi,

Could you print the error message too. I don't have python 3 so i
can't run the code you posted.

A couple of quick pointers.

You don't need this line `#!/usr/bin/python`. That's for telling a
unix shell to use python to run the remaining code.

Yo don't need this line `from string import maketrans` because you
aren't using the string module.

Never do this `str = "this is string example....wow!!!";` You are
overwriting str which is the type object for strings in python.
Shouldn't be an issue in your code. But it's generally bad coding to
change built-in functions and variables. Use another variable name.

You can find out what methods are available on an object using the dir
function, `dir("hello")` will tell you the methods available for the
str objects. help("hello") will give you help on str objects.

Regards,
Sidharth



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);
> ------------------------------------------------------------
> 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
>
>



-- 
I am but a man.


More information about the BangPypers mailing list