2016-12-27 88 views
-1

我正在Python中編寫腳本以生成強力詞表。我已經可以連接字符串只,但我不能在決賽中的每個單詞的串聯一些隨機數,因爲它說,我不能連接海峽和int對象...無法連接字符串與整數

代碼:

wList = [] 

words = raw_input("[+]Insert the words that you wish: ") 
outputFile = raw_input("[+]Insert the path to save the file: ") 

wordList = words.split(",") 

for x in wordList: 
    for y in wordList: 
     wList.append(x + y) 
     wList.append(y + x) 
     wList.append(x + "-" + y) 
     wList.append(y + "-" + x) 
     wList.append(x + "_" + y) 
     wList.append(y + "_" + x) 
     wList.append(x + "@" + y) 
     wList.append(y + "@" + x) 


for num in wordList: 
    for num2 in wordList: 
     for salt in range(1,10): 
      wList.append(num + num2 + int(salt)) 
      wList.append(num2 + num + int(salt)) 
+1

https://docs.python.org/3/library/functions.html#func-str – wwii

回答

0

您只能連接string與Python中的另一個string

更改最後兩行下面:

wList.append(num + num2 + str(salt)) 
wList.append(num2 + num + str(salt)) 
+0

它的工作原理!解決這個問題非常簡單,但我對Python非常感興趣。謝謝 –

1

在Python中+操作後sequence電話concatsequence操作前,無論是運營商之後。 python stringsequenceconcat函數僅適用於兩個相同類型的序列,即兩個字符串或兩個數組。在你的代碼中,你使用這個運算符爲stringint

您需要更改所有使用整數串連字符串的位置。這裏有兩種可能的方法來做到這一點。

您可以將所有整數轉換爲字符串。例如:

wList.append(str(x) + "-" + str(y)) 

或者您可以使用%格式化。例如:

wList.append("%d-%d"%(x, y))