morseCodeM={".-":"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",
" / ":" "}
def morseToText(inp):
out=""
while(inp!=" "):
for i in morseCodeM:
if(inp.find(i)!=-1): <-----------------------
out=out+morseCodeM[i]
inp2=list(inp)
inp2[inp.find(i):inp.find(i)+(len(i)-1)]=""
inp="".join(inp2)
return outI honestly don't know whats wrong it just gives the error :"AttributeError: 'function' object has no attribute 'find'" on the line with the arrow .
edit: the code is about converting morse code to text
Answer
The reason it fails is thanks to the __dict__ method. Since the removal of it, everything works fine.
Of course this leads to the next question: How to define custom dict functions for those classes
I couldn't find an answer to this but still want to offer a solution: Define a custom function that takes the required obj as a parameter and then puts the wanted fields into a dict. Not the most elegant solution IMO but it works.
I have removed __dict__, and created get_dict(self) to make my dict through the object without my constructor get problems.
Error with BertTokenizerFast: AttributeError - 'function' object has no attribute 'get'
final project - AttributeError: 'function' object has no attribute 'method' - CS50 Stack Exchange
Don't know how to fix AttributeError: 'function' object has no attribute 'pk' when trying to create new users from registration form
function has no attribute
Videos
hi all, I've started using Tkinter to create a login and register system. The register system works fine but when it comes to logging in once the user has entered their details and presses login I get this error message
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "main.py", line 20, in login_verify
password1=password_verify.get()
AttributeError: 'function' object has no attribute 'get'Im not sure whats causing this error message and why the same error message isn't being called with username_verify.get()
here is my code
from tkinter import *
import os
def register_user():
username_info = username.get()
password_info = password.get()
file = open(username_info, "w")
file.write(username_info+"\n")
file.write(password_info)
file.close()
username_entry.delete(0, END)
password_entry.delete(0, END)
Label(screen1, text= "Registration succesful", fg = "green", font = ("Calibri", 11)).pack()
def login_verify():
username1=username_verify.get()
password1=password_verify.get()
username_entry1.delete(0, END)
password_entry1.delete(0, END)
list_of_files = os.listdir()
if username1 in list_of_files:
file = open(username1, "r")
verify = file1.read().splitlines()
if password1 in verify:
print("login success")
else:
print("Incorrect Password")
else:
print("User not found")
def password_verify():
print("working...")
def register():
global screen1
screen1= Toplevel(screen)
screen1.title("Register")
screen1.title("Register")
screen1.geometry("300x250")
global username
global password
global username_entry
global password_entry
username = StringVar()
password = StringVar()
Label(screen1, text="Please enter your details below").pack()
Label(screen1, text ="").pack()
Label(screen1, text="username * ").pack()
global username_entry
global password_entry
username_entry=Entry(screen1, textvariable = username)
username_entry.pack()
Label(screen1, text="Password * ").pack()
password_entry=Entry(screen1, textvariable = password)
password_entry.pack()
Label(screen1, text= "").pack()
Button(screen1, text = "Register", width = "10", height = "1", command = register_user).pack()
def login():
global screen2
screen2 = Toplevel(screen)
screen2.title("Login")
screen2.geometry("300x250")
Label(screen2, text="Please Login").pack()
Label(screen2, text ="").pack()
global username_verify
global password_verify
username_verify=StringVar()
passsword_verify=StringVar()
global username_entry1
global password_entry1
Label(screen2, text="username * ").pack()
username_entry1 = Entry(screen2, textvariable=username_verify)
username_entry1.pack()
Label(screen2, text= "").pack()
Label(screen2, text="Password * ").pack()
password_entry1 = Entry(screen2, textvariable=password_verify)
password_entry1.pack()
Label(screen2, text= "").pack()
Button(screen2, text = "Login", width = 10, height = 1, command = login_verify).pack()
def main_screen():
global screen
screen=Tk()
screen.geometry("300x250")
screen.title("Seller 3.2.5")
Label(text="Seller 3.2.5", bg="grey", width="300", height="2", font=("Calibri", 13)).pack()
Button(text="Login", height="2", width="30", command = login).pack()
Label(text="").pack()
Button(text="Register", height="2", width="30", command = register).pack()
screen.mainloop()
main_screen()any help would be greatly appreciated
I am getting :
AttributeError: 'function' object has no attribute 'get' while saving onetoone relation in django?
While implementing login-signup application.
My project contains two models CustomUser and UserProfile, having OneToOne relation between them.
When user registers in site first he redirected to form for CustomUser model and when he hit the submit button he will again redirected to another form for UserProfile and then login form.But when i am submitting the UserProfile form it shows the error.
view for CustomUser form:-
def user_registration(request):
if request.method == "POST":
fm = UserCreationForm(request.POST)
if fm.is_valid():
fm.save()
return HttpResponseRedirect('/addprofile/')
else:
fm = UserCreationForm()
return render(request, 'signup.html', {'form': fm})view for UserProfile Form:-
def create_profile(request):
if request.method == "POST":
print(request.POST)
fm = ProfileForm(requests.post)
if fm.is_valid():
instance = fm.save(commit=False)
instance.user = request.user
instance.save()
return HttpResponseRedirect('/login/')
else:
fm = ProfileForm()
return render(request, "profileform.html", {'form': fm})
Full error trace:-
Internal Server Error: /addprofile/
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Admin\Desktop\project\EVCFinder\user\views.py", line 26, in create_profile
if fm.is_valid():
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 175, in is_valid
return self.is_bound and not self.errors
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 170, in errors
self.full_clean()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 372, in full_clean
self._clean_fields()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 384, in _clean_fields
value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\widgets.py", line 263, in value_from_datadict
return data.get(name)
AttributeError: 'function' object has no attribute 'get'
[10/Jul/2021 18:31:13] "POST /addprofile/ HTTP/1.1" 500 83734
Not Found: /favicon.ico
[10/Jul/2021 18:31:13,237] - Broken pipe from ('127.0.0.1', 53626)Thanks In Advance