Answers for "check exist object instance class python"

5

python check if class has function

class A:
  def func():
    pass
hasattr(A(), 'func')
Posted by: Guest on July-03-2020
0

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()
Posted by: Guest on January-23-2022

Code answers related to "check exist object instance class python"

Python Answers by Framework

Browse Popular Code Answers by Language