简体   繁体   English

Python plist 解析器 IOError: [Errno 63] 文件名太长:

[英]Python plist parser IOError: [Errno 63] File name too long:

my Python plist parser does not like my long string that is in plist format.我的 Python plist 解析器不喜欢我的 plist 格式的长字符串。

plist_data = plistlib.readPlist(plistString)

plistString is actually the contents of the file I opened. plistString 实际上是我打开的文件的内容。 Oddly enough, putting the input file into the readPlist function works, but I had to do some further formatting of that file within python.奇怪的是,将输入文件放入 readPlist function 是可行的,但我必须在 python 中对该文件进行进一步格式化。

I run that above code and get an IOError: [Errno 63] on the console.我运行上面的代码并在控制台上得到一个IOError: [Errno 63] Not sure how to avoid this?不知道如何避免这种情况? I am guessing the function is looking for "raw" input, instead of a String.我猜 function 正在寻找“原始”输入,而不是字符串。 How do I trick it?我该如何欺骗它?

If you want to read a string as a file, use StringIO .如果要将字符串作为文件读取,请使用StringIO

fakeFile= StringIO.StringOI( plistString )
plist_data = plistlib.readPlist(fakeFile)

It's better not to open and read the pList file.最好不要打开和读取 pList 文件。 plistlib.readPlist does the opening and reading for you. plistlib.readPlist为您打开和阅读。

plistlib.readPlist takes file or file name, not contents. plistlib.readPlist接受文件或文件名,而不是内容。 No surprise you get this error:毫不奇怪,您会收到此错误:

#define ENAMETOOLONG    63      /* File name too long */

Try plistlib.readPlistFromBytes(data) or use StringIO to present your string as a file尝试plistlib.readPlistFromBytes(data)或使用 StringIO 将您的字符串呈现为文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM