python-3.x - 如何处理方法需要 1 个位置参数但在功能代码中给出了 2 个?
问题描述
我制作了一个非常小的函数来使用 API 清除 Google 日历。该API通常有效。来自Google Developer pages的参考代码如下:
service.calendars().clear('primary').execute()
我的功能是这样的:
def clear_gcal(service):
someCal = '''my_calendar_address'''
service.calendars().clear(someCal).execute()
print("Some Google Cal cleared")
使用有效的服务变量运行它(我也使用它添加到日历中,没有错误,我得到“TypeError:method() 需要 1 个位置参数,但给出了 2 个”。我找到的所有解决方案都在 OOP 中使用 self ,但我的代码只是功能性的(我更喜欢这种方式),那么我该如何处理这个看似很常见的错误类型?谢谢,
Traceback (most recent call last):
File "<ipython-input-87-d7bf7ff34210>", line 1, in <module> runfile('C:/Users/b017646/ExportCal/main.py', wdir='C:/Users/b017646/ExportCal')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/b017646/ExportCal/main.py", line 17, in <module> gcal.clear_gcal(service)
File "C:\Users\b017646\ExportCal\gcal.py", line 48, in clear_gcal service.calendars().clear(deaCal).execute()
TypeError: method() takes 1 positional argument but 2 were given
格雷格斯DK
解决方案
问题:
您没有calendarId
正确提供参数。
解决方案:
你应该这样做:
service.calendars().clear(calendarId='primary').execute()
参考:
推荐阅读
- php - 使用 PHP、SQL 和 HTML 从导出的 Excel 表中编辑单元格类型
- python - 在python中将固定点转换为浮点数的问题
- google-apps-script - 每次都不会记住并运行外部函数的代码
- javascript - Vuetify 如何在 v-btn 中获取工作链接
- c++ - 通过基类引用参数返回派生对象
- c# - OpenIddict ASP.NET Core 服务器不能用作默认方案处理程序
- python - 根据列值将单列拆分为两列
- assembly - 最快的轮询循环 - 如何修剪 1 个 CPU 周期?
- python - 解析 Content-Disposition 标头的可靠方法
- spring - Spring 按参数名称自动装配不适用于 FtpMessageHandlerSpec