Hi there,
I'm having this problem with using translate() - I have a line in my code like: k.translate(None,':.-') , being called from a function, which works flawlessly under v2.6.4 but throwing in TypeError when run under v2.5

Traceback (most recent call last):
  File "./wakeONlan", line 94, in <module>
    WakeOnLan(k.translate(None,':.-'))
TypeError: expected a character buffer object

What does this error actually mean? And how can make it portable? Some serious reason, v2.5 can't be upgraded on the server at the moment. Any help would be greatly appreciated. Cheers!!!

Recommended Answers

All 2 Replies

The python 2.6 documentation says that the first argument None in str.translate is new in 2.6. Previously, the first argument had to be a string of 256 characters (translation table). I suppose you should write something like

import sys
if sys.version_info < (2, 6):
    table = ''.join(chr(i) for i in xrange(256))
else:
    table = None

k.translate(table,':.-')

Thanks Gribouillis, it works just fine. Cheers!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.