小编Bry*_*hai的帖子

如何读取中文txt文件(Python)

我有一个名为“chinchars.txt”的 .txt 文件。在里面,我有一行包含这两个字符:

\n\n

\xe8\x8a\x82\xe6\x97\xa5

\n\n

我如何读取这个文本文件并将其返回给字符?\n使用此代码:

\n\n
inputFile = open(\'chinchars.txt\').readlines()\n
Run Code Online (Sandbox Code Playgroud)\n\n

它输出这个错误:

\n\n
UnicodeDecodeError: \'charmap\' codec can\'t decode byte 0x8f in position \n18: character maps to <undefined>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我相信我需要以某种方式“解码”这些字符。这将如何实现?

\n

python decode file utf-8 python-3.x

6
推荐指数
1
解决办法
1万
查看次数

如何在Yagmail中插入图片?(Python)

我有一个 Yagmail 脚本,我想发送一封格式如下的电子邮件:

你好!下面是一张图片。

图片.png

再见!

但是,我的脚本只是将图像一直发送到电子邮件底部。这是我的代码:

img = "img.PNG"
body = "Hello! Below is a picture." + img + "Goodbye!"

contents = [body, img]
yag.send("receiver@gmail.com", "Subject", contents)
Run Code Online (Sandbox Code Playgroud)

您将如何使用可以将图像放置在文本块之间的格式发送电子邮件?帮助是appriced!

python email smtp image yagmail

5
推荐指数
1
解决办法
688
查看次数

标签 统计

python ×2

decode ×1

email ×1

file ×1

image ×1

python-3.x ×1

smtp ×1

utf-8 ×1

yagmail ×1