I quite new to OOP (and python as well) So I am building something similar to the Enigma machine. My problem is that: I don't know how to access to the randomizer method's return statement. I need that in order to get a randomized list of characters.
class generators():
global static_alphabet,backup_alphabet,encripting_dict,decripting_dict, mutable_alphabet
static_alphabet=['a','á', 'b', 'c', 'd', 'e','é', 'f', 'g', 'h', 'i','í', 'j', 'k', 'l', 'm', 'n', 'o','ó','ö','ő', 'p', 'q', 'r', 's', 't', 'u','ú','ü','ű','v', 'w', 'x', 'y', 'z',"'",'"','@',':','_','.','-',',','!']
backup_alphabet=['a','á', 'b', 'c', 'd', 'e','é', 'f', 'g', 'h', 'i','í', 'j', 'k', 'l', 'm', 'n', 'o','ó','ö','ő', 'p', 'q', 'r', 's', 't', 'u','ú','ü','ű', 'v', 'w', 'x', 'y', 'z',"'",'"','@',':','_','.','-',',','!']
mutable_alphabet=[]
def randomizer(self):
mutable_alphabet=[]
import random
for element in static_alphabet:
randletter=backup_alphabet[random.randint(0,len(backup_alphabet)-1)]
while randletter==element:
randletter=backup_alphabet[random.randint(0,len(backup_alphabet)-1)]
if randletter!=element:
break
mutable_alphabet.append(randletter)
backup_alphabet.remove(randletter)
return mutable_alphabet
Basically, you are trying to access the return statement inside a function ( def
) inside a class
. While your code does not currently appear to be constructed to take advantage of OOP, here is how you would run that function within the same file:
class generators():
...your code...
gen = generators()
outputArray = gen.randomizer()
# confirm output by printing it out
print( outputArray )
This would need to be placed outside of the class as I tried to illustrate above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.