Skip to main content
added 8 characters in body
Source Link
johnnyRose
  • 7.5k
  • 18
  • 43
  • 61

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

    def __init__(self, name='', street='', city='', state='', zip=''):
        self.name=name
        self.street=street
        self.city=city
        self.state=state
        self.zip=zip

###### code below is outside of class User #####

    def make(name='', street='', city='', state='', zip='', count=0):
        dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

    def __init__(self, name='', street='', city='', state='', zip=''):
        self.name=name
        self.street=street
        self.city=city
        self.state=state
        self.zip=zip

def make(name='', street='', city='', state='', zip='', count=0):
    dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

    def __init__(self, name='', street='', city='', state='', zip=''):
        self.name=name
        self.street=street
        self.city=city
        self.state=state
        self.zip=zip

###### code below is outside of class User #####

    def make(name='', street='', city='', state='', zip='', count=0):
        dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

added 44 characters in body
Source Link
Loïc Faure-Lacroix
  • 13.8k
  • 7
  • 74
  • 103

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

class User():

    def __init__(self, name='', street='', city='', state='', zip=''):
        self.name=name
        self.street=street
        self.city=city
        self.state=state
        self.zip=zip 

def make(name='', street='', city='', state='', zip='', count=0):
    dic[count]=User(name='', street='', city='', state='', zip='')

def make(name='', street='', city='', state='', zip='', count=0): dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

def __init__(self, name='', street='', city='', state='', zip=''):
    self.name=name
    self.street=street
    self.city=city
    self.state=state
    self.zip=zip

def make(name='', street='', city='', state='', zip='', count=0): dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

    def __init__(self, name='', street='', city='', state='', zip=''):
        self.name=name
        self.street=street
        self.city=city
        self.state=state
        self.zip=zip 

def make(name='', street='', city='', state='', zip='', count=0):
    dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

added 613 characters in body
Source Link
johnnyRose
  • 7.5k
  • 18
  • 43
  • 61

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

def __init__(self, name='', street='', city='', state='', zip=''):
    self.name=name
    self.street=street
    self.city=city
    self.state=state
    self.zip=zip

def make(name='', street='', city='', state='', zip='', count=0): dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

I have a dictionary with objects being stored as values. How might I access and print the attributes of a particular object? For example,

dict={0:obj0, 1:obj1, 2:obj2, 3:obj3}

I want to print obj1.attribute. I have tried:

print (dict[key]).attribute

to no avail. I cannot just access the object directly because I have not assigned it to a variable. This program automatically generates objects and places them in dict with an automatically generated key, which spares me manual assignment of an arbitrary amount of values. If anyone knows a better way to phrase this question, please go ahead. Thank you so much!

EDIT: My dictionary's name is not 'dict', nor is my attribute named 'attribute.' These are used simply for clarity.

EDIT: OK, here's what's going on. I'm using Tkinter to retrieve contact information through entry fields. I'm using that input to create an object with attributes name, address, etc. So,

class User():

def __init__(self, name='', street='', city='', state='', zip=''):
    self.name=name
    self.street=street
    self.city=city
    self.state=state
    self.zip=zip

def make(name='', street='', city='', state='', zip='', count=0): dic[count]=User(name='', street='', city='', state='', zip='')

Is there a reason that "dic[0].name" would return an empty string?

added 120 characters in body
Source Link
johnnyRose
  • 7.5k
  • 18
  • 43
  • 61
Loading
added 8 characters in body
Source Link
Loïc Faure-Lacroix
  • 13.8k
  • 7
  • 74
  • 103
Loading
Source Link
johnnyRose
  • 7.5k
  • 18
  • 43
  • 61
Loading