在Python中,我有一個腳本的這一部分:和我試圖插入兩個變量的時間和日期,但我得到一個錯誤
ip = ['10.25.128.225', '10.25.128.223', '10.25.128.224', '10.25.128.241']
time = time.strftime("%H:%M:%S")
date = time.strftime("%d/%m/%Y")
for address in ip:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((address, 9999))
if result != 0:
print('There is an issue with the {} address at {} on {} '.format(address, time, date))
每當我運行的代碼,但是,我得到錯誤:
date = time.strftime("%d/%m/%Y")
AttributeError: 'str' object has no attribute 'strftime'
我想我必須建立一個數據類型,但我仍然是一種新的python /編程。有什麼想法嗎?謝謝!
命名你的時間變量不同 - 它陰影'時間'模塊 –