Python Forum
identifying a dictionary with an attribute?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
identifying a dictionary with an attribute?
#1
i will have a dictionary of objects. each object will have some key that identifies it in the big dictionary. the objects are dictionaries, too (so it's a dictionary of dictionaries). when processing an object, there a many functions involved to which a reference to the object will be passed. i would like to also include the object's identity within the object itself. the big question i have is what key to store it under, given that each object could potentially have data items that could conflict with they key chosen to story its identity. the defaultdict is close but not the solution. it stores that default somewhere; it just uses it in a way that is incomparible with this problem. so i'm thinking i could store the identity as an attribute. would this be possible?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It's already there, type (classinfo):
type(object)
to use in conditional
if isinstance(object, type):
    ...
https://docs.python.org/3/library/functions.html#isinstance
Reply
#3
(Oct-03-2018, 02:51 AM)Skaperen Wrote: the object's identity

id(object)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
so how do i set the object's identity? suppose i have an object of type dictionary (any possible key could be used for data) that i want to identify as 'Skaperen'. would i do foo.id = 'Skaperen' or setattr(foo,'id','Skaperen')?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
skaperen = id(object)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
(Oct-04-2018, 01:46 AM)ichabod801 Wrote: skaperen = id(object)
what i want to do is store the identity with the object in a way that some code like a function or class that needs the identity can get it by having nothing more than a reference to the objecr.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
Of course you do. You always want more.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
storing the identity with tho object was my original goal.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Identifying if the program I have is python and then decompiling jpnyc 7 2,229 Jun-02-2022, 10:16 PM
Last Post: jpnyc
  Identifying keywords in text drchips 6 80,812 Mar-29-2022, 12:32 PM
Last Post: snippsat
  trying to put a a filter on identifying a straight CompleteNewb 1 1,637 Dec-01-2021, 11:11 PM
Last Post: CompleteNewb
  Identifying string success flag graham23s 4 3,056 Aug-14-2019, 09:27 PM
Last Post: graham23s
  Error 'object has no attribute' when iterating thru a dictionary mrapple2020 8 6,876 Apr-08-2019, 01:36 AM
Last Post: mrapple2020
  Identifying only specific words in a string GilbyScarChest 2 2,666 Aug-08-2018, 03:22 AM
Last Post: GilbyScarChest
  Empty attribute class dictionary after saving it in a class object dictionary 3dimensions 6 4,796 May-20-2018, 01:57 PM
Last Post: 3dimensions
  Identifying the value of all adjacent elements in an array JoeB 2 8,573 Nov-23-2017, 05:10 PM
Last Post: JoeB
  Identifying object types microphone_head 5 4,375 Oct-01-2017, 02:04 PM
Last Post: buran

Forum Jump:

User Panel Messages

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