代码行太长,python无法解释?

2024-03-28 09:22:37 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在用win32做一些工作com客户端模块。我做了一些网络垃圾来制作大量枚举的数据帧。webscrapping是成功的,但是一个模块将不会加载,除非我注释掉行。你知道吗

我对代码做了gist,因为其中有几行几乎是13k个字符长。你知道吗

我尝试import office_reverse_enumerations.py时的错误是

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe2 in position 0: unexpected end of data

在17号线。如果我把第17行注释掉,就行了。你知道吗

我通过编程生成了那行,好吧,所有的行。你知道吗

一个例子是

enum_file.write(f"{enum_names[idx][df_idx]}_reverse = pd.DataFrame.from_dict({df_r_enum.to_dict()})\n")
>>> import office_reverse_enumerations
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Delengowski-Mobile\Documents\Gits\power_point_generator\office_reverse_enumerations.py", line 17

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe2 in position 0: unexpected end of data

Here是我用来生成文件的代码。你知道吗


Tags: 模块代码inpyimportunicodeerrorenum
2条回答

您的文本包含以下内容:

>>> text[16700:16900]
"ith no border and callout line segments forming a U-shape', 183: 'Line inverse', 166: 'Division symbol  \xc3\x83\xc2\xb7', 167: 'Equivalence symbol  =', 164: 'Subtraction symbol  -', 165: 'Multiplication symbol  "

我希望一旦你知道了位置和内容,你就能解决这个问题()

另外,可疑部分是:166: 'Division symbol \xc3\x83\xc2\xb7'

使用open写入文本文件而不指定encoding时,将使用依赖于系统的默认编码(可以使用locale.getpreferredencoding(False)检索)。你知道吗

Python代码文件应该是UTF-8编码的,因此解决方案是在编写代码文件时在open函数中显式指定encoding="utf-8"。你知道吗

相关问题 更多 >