![](/img/trans.png)
[英]Im trying to reduce brackets in math equations down to one number using a recursive function and I keep getting a list index out of range error
[英]Im trying to Send a random number though a email but i keep getting a error
我的代码是用于通过电子邮件发送生成号码的电子邮件代码
msg = ('The number is',random.randrange(300,400),'Enjoy')
但是我得到这个错误:
Traceback (most recent call last):
line 30, in <module>
server.sendmail(fromaddr, toaddrs, msg)
File "C:\Python34\lib\smtplib.py", line 793, in sendmail
(code, resp) = self.data(msg)
File "C:\Python34\lib\smtplib.py", line 532, in data
q = _quote_periods(msg)
File "C:\Python34\lib\smtplib.py", line 168, in _quote_periods
return re.sub(br'(?m)^\.', b'..', bindata)
File "C:\Python34\lib\re.py", line 175, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
您的味精是一个元组,您可以使用字符串的format()
定义味精:
>>> import random
>>> msg = ('The number is',random.randrange(300,400),'Enjoy')
>>> print msg
('The number is', 300, 'Enjoy')
>>> msg = 'The number is {0}, Enjoy'.format(random.randrange(300, 400))
>>> msg
'The number is 325, Enjoy'
您需要将msg
转换为字符串,例如通过使用字符串格式运算符:
msg = 'The number is %d. Enjoy!' % random.randrange(300, 400)
目前, msg
是一个元组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.