Thread: Make trans ?

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0

    Solved : Make trans ?


    Hi,

    No I don't want to change.. I'd just like to know why I have this error :

    Code:
    trantab = maketrans(intab, outtab) 
    ValueError: maketrans arguments must have same length
    with this code :

    Code:
    def clean(string): 
             intab   = ''     
             outtab  = 'aaaeeeecuoo'    
             trantab = maketrans(intab, outtab)     
    
             return string.strip().replace(' ', '_').translate(trantab)
    It seems to me that they are equal in length no ?

    Thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    434
    Rep Power
    67
    Originally Posted by chaying
    It seems to me that they are equal in length no ?
    Equal in length as strings but not necessarily as sequences of bytes. However its hard to say for sure as we dont know what maketrans() is expecting.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (work laptop), Trisquel GNU/Linux 6.0.1 (mini laptop), Ubuntu 14.04 LTS (server), Android 4.2.1 (tablet), Windows 7 Ultimate (testbed)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0
    Hi, thanks stopping by.
    However its hard to say for sure as we dont know what maketrans() is expecting.
    Actually I don't either. So how could I make this code working ?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    434
    Rep Power
    67
    Originally Posted by chaying
    Actually I don't either. So how could I make this code working ?
    Where does the function come from? AFAIK its not a builtin nor in the standard library so either you should have its source code somewhere or you are importing it from some package that might have documentation.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (work laptop), Trisquel GNU/Linux 6.0.1 (mini laptop), Ubuntu 14.04 LTS (server), Android 4.2.1 (tablet), Windows 7 Ultimate (testbed)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0
    The code comes from there.

    Actually you were right, if one changes to :
    Code:
    intab   = u' .-'.encode('latin1')
    The function functions. After the latin encoding, the length is 1 byte which is what python expects.

    Thanks again for your help, I can see you're always there for the numbs !

IMN logo majestic logo threadwatch logo seochat tools logo