Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
object class
#3
object does not have __dict__ attribute, thus its instantiations can't be updated
In [1]: dir(object)
Out[1]:
['__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__']

(May-01-2017, 04:14 PM)Larz60+ Wrote: Seems to me you should have received this error immediately:
Error:
>>> x.name = 'Fred' Traceback (most recent call last):  File "<stdin>", line 1, in <module> NameError: name 'x' is not defined >>>
here, was x already declared

What was the type of your x
In [4]: class X(object):
   ...:     pass
   ...:

In [5]: x = X()

In [6]: x.name = 'Fred'

In [7]: '__dict__' in dir(X)
Out[7]: True
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
object class - by ichabod801 - May-01-2017, 01:36 PM
RE: object class - by Larz60+ - May-01-2017, 04:14 PM
RE: object class - by volcano63 - May-01-2017, 04:16 PM
RE: object class - by ichabod801 - May-01-2017, 04:38 PM
RE: object class - by volcano63 - May-01-2017, 04:56 PM
RE: object class - by nilamo - May-01-2017, 04:54 PM
RE: object class - by buran - May-01-2017, 05:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing out incidence values for Class Object SquderDragon 3 436 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  error in class: TypeError: 'str' object is not callable akbarza 2 655 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 5,046 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  AttributeError class object has no attribute list object scttfnch 5 3,612 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  Python Class and Object Parameters JoeDainton123 5 2,990 Sep-02-2020, 10:43 AM
Last Post: JoeDainton123
  Multiprocessing, class, run and a Queue Object SeanInColo 0 1,592 Jul-12-2020, 05:36 PM
Last Post: SeanInColo
  Hi, need help with class, object Houston222 1 1,883 Apr-04-2020, 01:55 PM
Last Post: buran
  class returns NoneType Object istemihan 0 2,320 Aug-12-2019, 11:47 AM
Last Post: istemihan
  Object and type class Uchikago 2 2,305 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE
  Return a value when I equal an object from a class ihouses 4 3,086 Jul-10-2019, 02:44 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020