Python 3.4 plistlib doesn't work (str vs bytes errors) -
so, started on new toy project , decided i'd use python 3 first time...
in [1]: import plistlib in [2]: open("/volumes/thunderbay/current/music/itunes/itunes library.xml") itl: library = plistlib.load(itl) ...: --------------------------------------------------------------------------- typeerror traceback (most recent call last) <ipython-input-3-6459a022cb71> in <module>() 1 open("/volumes/thunderbay/current/music/itunes/itunes library.xml") itl: ----> 2 library = plistlib.load(itl) 3 /usr/local/cellar/python3/3.4.3_1/frameworks/python.framework/versions/3.4/lib/python3.4/plistlib.py in load(fp, fmt, use_builtin_types, dict_type) 984 fp.seek(0) 985 info in _formats.values(): --> 986 if info['detect'](header): 987 p = info['parser'] 988 break /usr/local/cellar/python3/3.4.3_1/frameworks/python.framework/versions/3.4/lib/python3.4/plistlib.py in _is_fmt_xml(header) 556 557 pfx in prefixes: --> 558 if header.startswith(pfx): 559 return true 560 typeerror: startswith first arg must str or tuple of str, not bytes
hmm ok, let's give hint:
in [3]: open("/volumes/thunderbay/current/music/itunes/itunes library.xml") itl: library = plistlib.load(itl, fmt=plistlib.fmt_xml) ...: --------------------------------------------------------------------------- typeerror traceback (most recent call last) <ipython-input-4-ef5f06b44ec2> in <module>() 1 open("/volumes/thunderbay/current/music/itunes/itunes library.xml") itl: ----> 2 library = plistlib.load(itl, fmt=plistlib.fmt_xml) 3 /usr/local/cellar/python3/3.4.3_1/frameworks/python.framework/versions/3.4/lib/python3.4/plistlib.py in load(fp, fmt, use_builtin_types, dict_type) 995 996 p = p(use_builtin_types=use_builtin_types, dict_type=dict_type) --> 997 return p.parse(fp) 998 999 /usr/local/cellar/python3/3.4.3_1/frameworks/python.framework/versions/3.4/lib/python3.4/plistlib.py in parse(self, fileobj) 323 self.parser.endelementhandler = self.handle_end_element 324 self.parser.characterdatahandler = self.handle_data --> 325 self.parser.parsefile(fileobj) 326 return self.root 327 typeerror: read() did not return bytes object (type=str)
plistlib
in standard library, problems above have feeling has not been converted python 3?
i wondering if decision try python 3 on 2.7 going prove masochistic , pointless...
oh yes, actual question: possible open xml plist file plistlib
in python 3.4.3?
surely i'm missing obvious here perhaps... noticed py2 version of plistlib
(which works!) has different interface, has modified code of library inclusion py3...
thanks @j presper eckert giving me clue for...
i found article:
http://python-notes.curiousefficiency.org/en/latest/python3/text_file_processing.html#the-binary-option
which suggests answer open file in binary mode, tried , works!
with open("/volumes/thunderbay/current/music/itunes/itunes library.xml", 'rb') itl: library = plistlib.load(itl)
Comments
Post a Comment