第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

TypeError: 'int' 對(duì)象在 Autotyper 中不可迭代

TypeError: 'int' 對(duì)象在 Autotyper 中不可迭代

ITMISS 2021-11-30 19:21:36
我正在嘗試創(chuàng)建一個(gè)使用用戶輸入的自動(dòng)打字機(jī)。對(duì)于第一行,自動(dòng)打字機(jī)按預(yù)期工作,但在第二行,出現(xiàn)錯(cuò)誤。我想知道是不是因?yàn)槲易龅睦猓窟@是我的完整代碼:import timeimport randomfrom goto import with_gotokeyboard = Controller()class label(Exception): passprint('======Welcome to Autotyper v0.5 Currently still in development. We have a maximum of 4 lines, for bugs/suggestions email: alexanderhan00@gmail.com======')while True:    line1 = input("Please enter your first line:  ")    line2 = input("Please enter your second line, type none if you don't have one:  ")    if line2 == "none":        break    line3 = input("Please enter your third line, type none if you don't have one:  ")    if line3 == "none":        break    line4 = input("Please enter your fourth line, This is the last line!!  ")    breakhours = input("How many hours would you like to run this?     ")retry = input("How long will it take until new message?(Seconds)     ")timeout = round(time.time())future = round(time.time()) + int(60)*int(60)*int(hours)x = 5print('Move cursor to target')while x > 0:    print(int(x)*'.')    time.sleep(1)    x = x-1runs = 0while True:    random.seed()    random1 = random.randint(0,10)    for char in line1:        keyboard.press(char)        keyboard.release(char)        time.sleep(0.1)    keyboard.press(Key.shift)    keyboard.press(Key.enter)    keyboard.release(Key.shift)    keyboard.release(Key.enter)    try:        line2 = 1    except NameError:        break    else:        for char in line2:            keyboard.press(char)            keyboard.release(char)            time.sleep(0.1)        keyboard.press(Key.shift)        keyboard.press(Key.enter)        keyboard.release(Key.shift)        keyboard.release(Key.enter)    runs = runs + 1    if timeout > future or runs == hours*60:        break    print("Random Seconds Added:")    print(int(random1))    print("Time to next entry:")    for y in range(int(retry) + int(random1)):        print(int(retry) + int(random1 - y))        time.sleep(1)非常感謝任何幫助,謝謝!我是社區(qū)的新手。
查看完整描述

1 回答

?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊

錯(cuò)誤是因?yàn)檫@段代碼:


try:

    line2 = 1

except NameError:

    break

else:

    for char in line2:

        keyboard.press(char)

        keyboard.release(char)

        time.sleep(0.1)

之后line2 = 1,line2不再包含用戶輸入的行,而是包含整數(shù)1。for char in line2將不再有效,因?yàn)槟鸁o法遍歷整數(shù)。


我認(rèn)為您正在嘗試使用該try/except塊來判斷用戶是否為line2. 但是賦值永遠(yuǎn)不會(huì)報(bào)告 a NameError,只有在嘗試讀取尚未賦值的變量時(shí)才會(huì)出現(xiàn)該錯(cuò)誤。此外,讀取輸入的代碼始終分配給line2,因此您不會(huì)收到錯(cuò)誤消息。如果您為前幾行輸入,則可能未設(shè)置的變量是line3and 。line4none


每當(dāng)您發(fā)現(xiàn)自己創(chuàng)建的變量具有這樣的順序名稱時(shí),您可能應(yīng)該使用列表而不是單獨(dú)的變量。以下是讀取所有輸入行的方法:


lines = []

while True:

    line = input("Please enter your next line, type 'none' if you don't have one")

    if line == "none":

        break

    lines.append(line)

當(dāng)你想輸入它們時(shí):


random.seed()

while time.time() < future and runs < hours*60:

    for line in lines:

        for char in line:

            keyboard.press(char)

            keyboard.release(char)

            time.sleep(0.1)

        keyboard.press(Key.shift)

        keyboard.press(Key.enter)

        keyboard.release(Key.shift)

        keyboard.release(Key.enter)

    runs += 1

    print("Random Seconds Added:")

    print(int(random1))

    print("Time to next entry:")

    for y in range(int(retry) + int(random1)):

        print(int(retry) + int(random1 - y))

        time.sleep(1)

另一個(gè)問題是您timeout在循環(huán)期間從未更新,它始終是它開始的時(shí)間。


查看完整回答
反對(duì) 回復(fù) 2021-11-30
  • 1 回答
  • 0 關(guān)注
  • 245 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)