0

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
3
  • I don't know about anyone but I think you gotta change your class name to capital letter at first cause it's a good practice. class Encryption Commented Oct 8, 2020 at 9:26
  • 2
    A methods always receives the instance as the first argument. Did you mean to declare encryption(self, message):? A class seems to be the wrong abstraction though, since you appear not to be interested in having an instance. Why not use a module instead? Commented Oct 8, 2020 at 9:27
  • So there are several possible ways to "fix" this (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 the encryption/decryption "functions"? Do you have some other functionality not shown which actually requires a class? Commented Oct 8, 2020 at 9:56

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

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 ?
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);
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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.