python check if class has function
class A:
def func():
pass
hasattr(A(), 'func')
python check if class has function
class A:
def func():
pass
hasattr(A(), 'func')
how to see if something is in a class in python
#Python
#This is just some code I thought of to add things from a list
#to a file while the list contains items with classes where an
#attrubute is "name"
class stuffs:
def __init__(self,name,other_random_stuff):
self.name = name
self.stuff = other_random_stuff
thing = stuffs("Insert name here",10)
list = ["Some string",10,thing]
file = open("demofile.txt","a")
for item in list:
try:
try:
print("Adding "+str(item.name))
file.write(str(item.name)+"""
""")
except:
print("Adding "+str(item))
file.write(str(item)+"""
""")
except:
print("Sorry, an error occured. Please try again."
file.close()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us