class Samadateconverter:
def __init__(self, y , m , d ):
self.y = y
self.m = m
self.d = d
def gregorian_to_hijri(self):
# Calculate the Julian Day Number (JDN) for the Gregorian date
jdn = int((1461 * (self.y + 4800 + int((self.m - 14) / 12))) / 4) + int((367 * (self.m - 2 - 12 * int((self.m - 14) / 12))) / 12) - int((3 * int((self.y + 4900 + int((self.m - 14) / 12)) / 100)) / 4) + self.d - 32075
# Calculate the Hijri calendar date from the JDN
h = int((jdn - 1948440 + 10632) / 10631)
year = int((h + 10307) / 1335)
month = ((h - 1) % 12) + 1
day = jdn - 1948440 - int((year * 354) + int((3 + (11 * year)) / 30)) - int((month - 1) * 29.5) + 1
return (year, month, day)
然后在另一个文件中我称之为
from class_converter import Samadateconverter
Samadateconverter.gregorian_to_hijri(1233,5,7)
and its gave my this errore gregorian_to_hijri()takes 1 positional argument but 3 were given
3条答案
按热度按时间of1yzvn41#
你必须先创建一个类的示例,然后才能调用你的方法:
输出:
ibps3vxo2#
你的函数被定义为只接受一个参数:
self
当
Samadateconverter
对象的示例上调用gregorian_to_hijri()
时,self
会自动传入。当这样做时,给函数任何参数都会导致这个错误。如果我没有阅读错,你希望你的Samadateconverter
对象保存值:您应该将代码更改为:
olmpazwi3#
这会起作用的