【问题标题】:How to fix: TypeError: _get_unique_zone() missing 1 required positional argument: 'shortcut_id_y'?如何修复:TypeError:_get_unique_zone() 缺少 1 个必需的位置参数:'shortcut_id_y'?
【发布时间】:2021-10-02 17:20:37
【问题描述】:

我对 Python 还是很陌生,正在尝试编写一个可以根据经度计算位置实时时间的代码。

它已经工作了,但是现在,它需要参数self 填充。我定义了self,现在解决了,但现在如果我尝试使用offset(City, self=tf),它会给我这个错误:

  Traceback (most recent call last):

  File "C:\Users\Marvi\PycharmProjects\pythonProject1\main.py", line 55, in <module>
    GMTcor = time_in - offset(City, self=tf) * 60 + realTime
  File "C:\Users\Marvi\PycharmProjects\pythonProject1\main.py", line 45, in offset
    tz_target = timezone(tf.certain_timezone_at(self,lat=target['lat'], lng=target['lng']))
  File "C:\Users\Marvi\anaconda3\envs\pythonProject1\lib\site-packages\timezonefinder\timezonefinder.py", line 744, in certain_timezone_at
    timezone = self._get_unique_zone(shortcut_id_x, shortcut_id_y)
TypeError: _get_unique_zone() missing 1 required positional argument: 'shortcut_id_y'

我不知道如何解决它...请帮助我! 整个代码都在这里:(我知道它很乱)

from geopy.geocoders import Nominatim
from datetime import timedelta
from pytz import timezone
import pytz
import datetime
from timezonefinder import TimezoneFinder

address = input("Insert place: ")
geolocator = Nominatim(user_agent="Time Correction Calculator")
location = geolocator.geocode(address)
print(location.address)

t = input("Insert time (hh:mm): ")
(h, m) = t.split(':') 
time_in = int(h) * 60 + int(m) 


date_input = input("Insert date (dd.mm.yyyy): ")

utc = pytz.utc
tf = TimezoneFinder

def offset(target, self):
    today = datetime.datetime.strptime(date_input, '%d.%m.%Y') # reading of date_in and Splitting it
    tz_target = timezone(tf.certain_timezone_at(self,lat=target['lat'], 
    lng = target['lng'])) # Searching timezone by coordinates
    today_target = tz_target.localize(today)
    today_utc = utc.localize(today)
    return (today_utc - today_target).total_seconds() / 3600 # Calculating the timezone in hours

City = dict({'lat' : location.latitude, 'lng' : location.longitude})

realTime : float = location.longitude * 4 # Longitude to minutes
realTime = round(realTime)

Correction = time_in - offset(City, self=tf) * 60 + realTime # Calculating the real time in minutes
print(str(timedelta(hours = GMTcor / 60))[:-3]) # printing the real Time

【问题讨论】:

    标签: python arguments position


    【解决方案1】:

    在按坐标搜索时区时尝试编辑一行:25。

    换行:25

    tz_target = timezone(tf.certain_timezone_at(self,lat=target['lat'], lng=target['lng'])) # Searching timezone by coordinates
    

    与:

    tz_target = timezone(tf().certain_timezone_at(lat=target['lat'], lng=target['lng'])) # Searching timezone by coordinates
    

    您需要使用TimezoneFinder 的对象调用certain_timezone_at(),而不是从类引用中调用它。

    例如tf().certain_timezone_at(lat=target['lat'], lng=target['lng'])

    另外,调用对象级方法时不需要传递self。这将由 python 解释器隐式传递。

    看看这个代码差异。

    【讨论】:

    • 您好,谢谢您的回复!不幸的是,它不起作用。它以前完全一样,但是有更新或smth并且它坏了。如果我删除自我,我会收到此错误:TypeError: certain_timezone_at() missing 1 required positional argument: 'self'
    • 嘿,我刚刚编辑了我的答案。还有一些其他问题。请看一下。但是,您需要在使用GMTcor 时修复导入错误。这是一个不同的问题。
    • 非常感谢!它终于奏效了! :DD
    猜你喜欢
    • 2021-12-17
    • 1970-01-01
    • 2013-07-06
    • 2019-06-25
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多