简体   繁体   中英

positional error with date from datetime module in python

I am working on a little game inside of blender 3.3.3, i have the month and day coming in as variables and I am using the date function so that I can figure out what day in the week it is. I have it written out date_year=date(1843,month,day) month and day are both variables that bring in a integer. But everytime I run it it gives me this error

Traceback (most recent call last):
  File "D:\Documents\PythonScripts\Oregan Trail\oregantrail.py", line 312, in <module>
    date_list=date(days_traveled)
  File "D:\Documents\PythonScripts\Oregan Trail\oregantrail.py", line 298, in date
    date_year=date(1843,month,day)
TypeError: date() takes 1 positional argument but 3 were given

date() uses 3 arguments so I don't see why it is doing this. I tried it out in a test file and it works fine. Could it have anything to do with this being inside a function?

You've made a function in oregantrail.py called date() which takes only one argument. You should rename that function, or maintain the datetime namespace to prevent the collision.

Observe:

>>> from datetime import date
>>> date # class
<type 'datetime.date'>
>>> def date():
...     pass
...
>>> date # now your functino
<function date at 0x0000000001F5FC88>

Should instead be:

import datetime

then

date_year = datetime.date(1843, month, day)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM