擅长:python、mysql、java
<p>因为<code>alarm</code>不是字符串/文本,所以不能将其直接写入文件。您可以通过将<code>alarm.getName()</code>和<code>alarm.getState()</code>放入列表中,并使用分隔符<code>","</code>将它们作为字符串连接起来来实现这一点。然后你可以把它写进一个文件</p>
<pre><code>my_file = open('D:\send_file3.txt','w')
my_file.write('from call import Client\n')
my_file.write('account_sid = "test"\n')
my_file.write('auth_token = "test"\n')
my_file.write('client = Client(account_sid, auth_token)\n')
my_file.write('message =client.api.account.messages.create(to="+6140000000",
from_="+614000000000", body=" ')
for alarm in alarms:
myfile.write(",".join([alarm.getName(), alarm.getState()]))
</code></pre>