tags:

views:

94

answers:

2

I'm having a somewhat odd problem with Python(2.6.2) that I've come to the conclusion is a bug in the Vista port (I cant replicate it in XP or Linux).

I have a list of users, encrypted passwords, and their host that I am storing in a larger list (it's acting as a sort of database).

This all works fine and dandy, except for that there is an inconsistency in how a single user's data is stored and how the group is stored.

created by the 'create_user' method

['localhost', 'demo', 'demouserpasswordhash']

created by the 'create_database' method

['\xff\xfel\x00o\x00c\x00a\x00l\x00h\x00o\x00s\x00t\x00', '\x00d\x00e\x00m\x00o\x00', '\x00d\x00e\x00m\x00o\x00u\x00s\x00e\x00r\x00p\x00a\x00s\x00s\x00w\x00o\x00r\x00d\x00h\x00a\x00s\x00h\x00\r\x00\n']

I don't understand why it's doing this, given how simple the code for it is:

# ----- base functions

def create_user ( user_data ):
    return user_data.split(":")

def show_user ( user_data ):
    print "Host: ", user_data[0]
    print "Username: ", user_data[1]
    print "Password: ", user_data[2]
    print

def create_database ( user_list ):
    database = []
    for user in user_list:
        database.append( create_user( user ) )
    return database

def show_database( database ):
    for row in database:
        show_user( row )

# ----- test area

users = open( "users.txt" )


test_user = create_user( "localhost:demo:demouserpasswordhash" )
db = create_database( users )

print db[0]
print test_user

# -----

Anyone have any similar experiences with this or is it just me?

+6  A: 

Your file users.txt is in UTF-16, but you're opening it as ASCII.

Either change it to ASCII, or open it like this:

import codecs
users = codecs.open( "users-16.txt", "r", "utf-16" )
RichieHindle
I <3 you. Thanks.
Josh Sandlin
+1  A: 

Try replacing

create_user( user )

with

create_user( user.decode("utf16") )
Otto Allmendinger
I think most of the problem came from me using Wordpad to write the textfile. I redid it in Emacs and it worked just fine.
Josh Sandlin