so ive got two scripts thats, where ive imported one into the other. script 1 is a class for the encryption function
class encryption():
def encryption(message):
#code here isnt relevant
def decryption(line_key):
#code isnt relevant
this code works by it self but when the other code from script two tries interacting with it it get the error :
TypeError: encryption() takes no arguments
The code for script two that interacts with script one is :
x1 = entry1.get()
label4 = tk.Label(root, text = encryption.encryption(x1), font = ('helvetica' , 10 , 'bold')
Im really not sure what im doing wrong here.
asked Oct 8, 2020 at 9:24
soap and butter sandwhich
271 silver badge7 bronze badges
1 Answer 1
Oh you have just made a typo. you should pass self to the definition of encryption and decryption functions in your class.
class encryption():
def encryption(self, message):
#code here isnt relevant
def decryption(self, line_key):
#code isnt relevant
answered Oct 8, 2020 at 9:27
Fatemeh Karimi
9972 gold badges16 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
soap and butter sandwhich
now its getting the error of only receiving one argument instead of two so do i have to format how i put the input in in a different way ?
Fatemeh Karimi
I think you don't instantiate your class. you should first instantiate an object of your class, then calling its method. i mean like this:
encrypt = encryption(); encrypt.encryption(message);MisterMiyagi
Note that declaring the "methods" as
classmethod may be more appropriate, if an instance is not meaningful. This would also allow direct usage without instantiation.lang-py
classname to capital letter at first cause it's a good practice.class Encryptionencryption(self, message):? Aclassseems to be the wrong abstraction though, since you appear not to be interested in having an instance. Why not use a module instead?self+instantiation,classmethod, ...), but the general issue appears to be using a class when instances are not meaningful. We cannot really offer the solution until we know what you intended to do. Why do you have a class for this? Do you just want a namespace for theencryption/decryption"functions"? Do you have some other functionality not shown which actually requires a class?