我正在使用PyCharm(Python 3)编写一个Python函数,它接受一个字典作为参数attachment={}
.
def put_object(self, parent_object, connection_name, **data):
...
def put_wall_post(self, message, attachment={}, profile_id="me"):
return self.put_object(profile_id, "feed", message=message, **attachment)
Run Code Online (Sandbox Code Playgroud)
在IDE中,attachment={}
为黄色.将鼠标移到它上面会显示警告.
默认参数值是可变的
此检查检测何时在参数的默认值中检测到可变值作为列表或字典.
默认参数值仅在函数定义时计算一次,这意味着修改参数的默认值将影响函数的所有后续调用.
这意味着什么,我该如何解决?
在python中,如何判断变量是否为bool类型,python 3.6使用
for i in range(len(data)):
for k in data[i].keys():
if type(data[i][k]) is types.BooleanType:
data[i][k] = str(data[i][k])
row.append(data[i][k])
#row.append(str(data[i][k]).encode('utf-8'))
writer.writerow(row)
row = []
Run Code Online (Sandbox Code Playgroud)
但它错误:
if type(data[i][k]) is types.BooleanType:
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud) python程序如下,报错:
文件“C:\Python\PyCharmProject\FaceBookCrawl\group_download.py”,第 31 行,在 getFeed 参数中 += "&since=" + SINCE.strftime("%s")
ValueError: Invalid format string
程序好像SINCE.strftime("%s")
错了,怎么解决?
SINCE = datetime.datetime.now() - datetime.timedelta(DAYS)
params = "?fields=permalink_url,from,story,type,message,link,created_time,updated_time,likes.limit(0).summary(total_count),comments.limit(0).summary(total_count)"
#Default paging limit
params += "&&limit=" + DEFAULT_LIMIT
#Time-based limit
params += "&since=" + SINCE.strftime("%s")
graph_url = GRAPH_URL_PREFIX + group + "/feed" + params
Run Code Online (Sandbox Code Playgroud)