我正在使用python发送电子邮件.现在,我想通过电子邮件从列表中发送条目,但我遇到一个错误,说"TypeError:无法连接'str'和'list'对象",我不知道调试它.以下是我的代码.我仍然是这种语言的新手(3周)所以我有一点背景.
import smtplib
x = [2, 3, 4] #list that I want to send
to = '' #Recipient
user_name = '' #Sender username
user_pwrd = '' #Sender Password
smtpserver = smtplib.SMTP("mail.sample.com",port)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login(user_name,user_pwrd)
#Header Part of the Email
header = 'To: '+to+'\n'+'From: '+user_name+'\n'+'Subject: \n'
print header
#Msg
msg = header + x #THIS IS THE PART THAT I WANT TO INSERT THE LIST THAT I WANT TO SEND. the type error occurs in this line
#Send Email
smtpserver.sendmail(user_name, …Run Code Online (Sandbox Code Playgroud) 我正在改写剧本从蟒蛇到Ç.我对C.比较新.
我在PYTHON中有一个包含这个值的变量:
x = [chr(113),chr(80),chr(191),chr(70)]
y = "".join(x)
Run Code Online (Sandbox Code Playgroud)
这将返回y的这个值:
y = qP¿F #this is string
Run Code Online (Sandbox Code Playgroud)
现在我要解压缩这个变量,将它存储到变量z以获得我想要的结果.像这样:
z = struct.unpack("<f",y)
print z[0] #unpack returns a tuple of size 1
Run Code Online (Sandbox Code Playgroud)
我得到的价值是:
x = 24488.2207
Run Code Online (Sandbox Code Playgroud)
这对我来说是正确的.
我想知道C中是否有相同的功能可用于此?
我有一个数组
unsigned char array_a[4] = {0x00,0x00,0x08,0x4D};
unsigned char val[4];
float test;
Run Code Online (Sandbox Code Playgroud)
我想要做的是组合所有元素并将其存储到val以使其为0x0000084D并将其转换为浮动,即2125.
我试过memcpy
memcpy(val,array_a,4);
val[4] = '\0';
Run Code Online (Sandbox Code Playgroud)
但仍然不行.