python中function takes exactly_Python error TypeError: function takes exactly 1 argument (5 given)
问题
Traceback (most recent call last):
File "wdd.py", line 164, in
file.write("temperature is ", temperature, "wet is ", humidity, "%\n")
TypeError: function takes exactly 1 argument (5 given)
Python:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 26 14:24:43 2014
@author: pi
"""
import smtplib
import RPi.GPIO as gpio
import time
gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)
time.sleep(1)
data=[]
def delay(i): #20*i usdelay
a=0
for j in range(i):
a+1
j=0
#start work
gpio.setup(7,gpio.OUT)
#gpio.output(12,gpio.HIGH)
#delay(10)
gpio.output(7,gpio.LOW)
time.sleep(0.02)
gpio.output(7,gpio.HIGH)
i=1
i=1
#wait to response
gpio.setup(7,gpio.IN)
gpio.setup(15,gpio.OUT)
gpio.setup(16,gpio.OUT)
while gpio.input(7)==1:
continue
while gpio.input(7)==0:
continue
while gpio.input(7)==1:
continue
#get data
while j<40:
k=0
while gpio.input(7)==0:
continue
while gpio.input(7)==1:
k+=1
if k>100:break
if k<3:
data.append(0)
else:
data.append(1)
j+=1
print "Sensor is working"
#get temperature
humidity_bit=data[0:8]
humidity_point_bit=data[8:16]
temperature_bit=data[16:24]
temperature_point_bit=data[24:32]
check_bit=data[32:40]
humidity=0
humidity_point=0
temperature=0
temperature_point=0
check=0
for i in range(8):
humidity+=humidity_bit[i]*2**(7-i)
humidity_point+=humidity_point_bit[i]*2**(7-i)
temperature+=temperature_bit[i]*2**(7-i)
temperature_point+=temperature_point_bit[i]*2**(7-i)
check+=check_bit[i]*2**(7-i)
tmp=humidity+humidity_point+temperature+temperature_point
print "temperature is " , temperature,"*C"
print "wet is ",humidity, "%"
import smtplib
import RPi.GPIO as GPIO
import time
if check == tmp:
print "temperature is ", temperature,"wet is ",humidity,"%"
#file = open("wdd.txt","w")
#file.write ("temperature is ", temperature, "wet is ", humidity, "%\n")
#file.close()
#print "temperature is ", temperature,"wet is ",humidity,"%"
while True:
#check.close()
if temperature>28:
#while temperature>29:
# continue
GPIO.output(15,True)
file = open("wdd.txt", "w")
file.write("The fan 1 was turn on\n")
file.close()
# print "1"
break
#continue
# time.sleep(2)
while True:
if temperature<24:
#continue
GPIO.output(15, False)
file = open("wdd.txt", "w")
file.write("The fan 1 was turn off\n")
file.close()
#print "2"
break
#continue
# time.sleep(2)
while True:
if humidity>89:
#check.close()
#continue
GPIO.output(16,True)
file = open("wdd.txt", "w")
file.write("The fan 2 was turn on\n")
file.close()
#print "3"
break
#continue
# time.sleep(2)
while True:
if humidity<80:
#check.close()
#continue
GPIO.output(16, False)
file = open("wdd.txt", "w")
file.write("The fan 1 was turn off\n")
file.close()
#print "4"
break
#continue
# k time.sleep(2)
# print "a"
else:
print "something is worong"
if check == tmp:
# print "temperature is ", temperature,"wet is ",humidity,"%"
file = open("wdd.txt","w")
file.write("temperature is ", temperature, "wet is ", humidity, "%\n")
file.close()
#print "temperature is ", temperature,"wet is ",humidity,"%"
回答1:
file.write() only takes one argument, a string. You've given it five instead:
file.write("temperature is ", temperature, " wet is ", humidity, "%\n")
Make that one string:
file.write("temperature is " + str(temperature) + " wet is " + str(humidity) + "%\n")
or use string formatting:
file.write("temperature is {} wet is {}%\n".format(temperature, humidity))
file.write() does not act like a print statement.
来源:https://stackoverflow.com/questions/23766383/python-error-typeerror-function-takes-exactly-1-argument-5-given
python中function takes exactly_Python error TypeError: function takes exactly 1 argument (5 given)相关推荐
- Python中出现 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 12-13
Python中出现 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 12-13: t ...
- Python类传参报错-TypeError:takes 2 positional arguments but 3 were given
Error: 今天写了个类,通过requests传入url和headers来获取接口返回的数据,函数写好了但是出现了报错问题: TypeError:takes 2 positional argumen ...
- python 调用super()初始化报错“TypeError: super() takes at least 1 argument”
在python中有如下代码: class father():def __init__(self,age):self.age = age;def get_age(self):print(self.age ...
- 解决Python中sum函数出现的TypeError: unsupported operand type(s) for +: 'int' and 'list'错误问题
当在Python中运行sum函数时,会出现"TypeError: unsupported operand type(s) for +: 'int' and 'list'"这样的问题 ...
- 解决Python中出现的Memory Error的问题
最近刚刚学习Python,用的软件是PyCharm.在手打了一个基于物品的推荐算法,并且跑一个20000+的数据集时,出现了Memory Error错误.一开始以为是代码问题,后面才发现自己的内存已经 ...
- opencv python cv2.threshold()函数报错 TypeError: Expected cv::UMat for argument 'mat'
错误信息: 解决办法: 原来cv2.threshold()函数有俩返回值,我这只用了一个接收... 改成俩就好了: 参考文章1:图像阈值处理cv2.threshold()函数(python) 参考文章 ...
- python中def fun(a、b=200)_python中的函数的参数和可变参数
最近在搞python的过程中需要用到给函数传可变参数..所以去网上找前人的帖子学习了一下 刚学用Python的时候,特别是看一些库的源码时,经常会看到func(*args, **kwargs)这样的函 ...
- python中函数的可变参数_Python中函数的参数定义和可变参数
转自:http://www.cnblogs.com/tqsummer/archive/2011/01/25/1944416.html 刚学用Python的时候,特别是看一些库的源码时,经常会看到fun ...
- python中可变参数args传入函数时储存的类型是_[转载]Python中函数的参数定义和可变参数*args与**args...
Python中函数的参数定义和可变参数 *args与**args区别 刚学用Python的时候,特别是看一些库的源码时,经常会看到func(*args, **kwargs)这样的函数定义,这个*和** ...
最新文章
- Python基础19-面向对象基础
- 关于ASP.NET MVC的一些工作中遇到的问题
- Tomcat服务器的常用配置
- Linux内存buffer和cache的区别
- easyui-window窗口不遮挡_眼睛是心灵的窗口、佩戴舒适又时尚的米家防蓝光护目镜 Pro...
- 产品优化成果过关?监控数据说了算
- 如何使用WCF调试器WcfTestClient.exe
- AI算法连载18:统计之EM 迭代算法
- mfc 子窗体 按钮不触发_VBA与Excel入门——用户窗体1
- cad2016中选择全图字体怎么操作_抖音上的书单都是用啥做的,抖音书单图片怎么做...
- asp.net web开发框架_Python之Web开发框架学习 发送电子邮件
- ubuntu vim保存退出命令_【学员分享】程序员效率神器,最常用VIM插件安装大全...
- bert处理英文的词根处理
- 13.字符串,结构,联合
- server2008实验之七 利用FSRM实现文件服务器精确管理.
- 驾考维语版本-维语驾考手机电脑版-民语驾考网
- 2015年数学建模-A影子定位
- 背英语句子,来巧记单词
- Dubbo-Adaptive实现解析
- unexpected char: '\' @ line 3, column 133. s\react-native-gestu
热门文章
- MYSQL如何制作资产负债表_【WebFOCUS使用技巧】 资产负债表的实现方法
- 访问网页出现503服务器,503错误,详细教您网页出现503错误怎么解决
- 软件测试之柠檬班python全栈自动化50期测试笔记
- 2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
- Node.js npm 使用介绍
- 《疯狂农场》带来的启示
- Kafka 命令行工具 kcat/kafkacat
- unity获取电磁笔压感_电磁笔的分类和特性
- matlab模拟线圈电磁场,利用MATLAB的PDE工具箱对电场和磁场进行模拟
- 一个简单有趣的爬虫-----爬取百度翻译功能