Bottom Page

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 why is my dictionary not recognized as such
I am still a newbie but learning fast. However, Python is still surprising me in strange ways. Here is my code
supported_drivers = {"SQLite" : 1,
                    "Sybase" : 3,
                    "SQLserver" : 7,
                    "Oracle" : 8 ,
                    "MongoDB" : 10,
                    "DynamoDB" : 11
print (vars(supported_drivers))
and here is the result:
Traceback (most recent call last):
File "Z:\projects\xxx\", line 58, in <module>
print (vars(supported_drivers))
TypeError: vars() argument must have __dict__ attribute.

OK, so why is my, seemingly a dictionary, not a dictionary?

Thank you all
remove vars:
supported_drivers = {"SQLite" : 1,
                    "Sybase" : 3,
                    "SQLserver" : 7,
                    "Oracle" : 8 ,
                    "MongoDB" : 10,
                    "DynamoDB" : 11
print (supported_drivers)
{'SQLite': 1, 'Sybase': 3, 'SQLserver': 7, 'Oracle': 8, 'MongoDB': 10, 'DynamoDB': 11}
or as elements:
for key, value in supported_drivers.items():
    print('{}, {}'.format(key, value))
SQLite, 1 Sybase, 3 SQLserver, 7 Oracle, 8 MongoDB, 10 DynamoDB, 11
Because vars isn't looking for a dictionary, it's looking for something with a __dict__ attribute, which dictionaries don't have. The vars function is for things like classes and instances.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Thank you all
I must admit that Python comparisons and matches begin to drive me nuts:
       self.driver_id = supported_drivers[self.driver] if self.driver in supported_drivers else None
        print (self.driver, "\n", supported_drivers)

        print (self.driver, "  ", self.dbengine, "  ", self.driver_id, "\n\n")
        if 'Sybase' == self.driver:
            print ('Sybase', ' is equal ', self.driver)
            if self.dbengine == 'ASE':
                self.driver_id = 4
            elif self.dbengine == 'IQ':
                self.driver_id = 5
            elif self.dbengine != '':
                print(self.driver, "\n\n")
            print ('Sybase', ' is not equal ', self.driver)

{'SQLite': 1, 'Sybase': 3, 'SybaseASE': 4, 'SybaseIQ': 5, 'SQLserver': 7, 'Oracle': 8, 'MongoDB': 10, 'DynamoDB': 11}
'Sybase' 'BLA' None

Sybase is not equal 'Sybase'

as you see, self.driver is 'Sybase' and it is IN supported_drivers, yet Python says it is NOT.
And then it is NOT EQUAL to 'Sybase'...
What the heck is going here?

Now I do compare strings unless you tell me that in Python a string is also not a string under certain circumstances

Thank you
Print the type of "Sybase" and self.driver. You may be comparing one type to another which is never equal.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Convert List of Dictionary to dictionary of dictionary list in python kk230689 2 152 Apr-27-2019, 03:13 AM
Last Post: perfringo
  pyserial-master installed bbut not recognized elwolv1 0 192 Jan-04-2019, 08:37 PM
Last Post: elwolv1
  How do I calculate the smallest value that is recognized as a difference when compari AFoeee 1 527 Oct-28-2018, 10:48 PM
Last Post: Gribouillis
  'videodigest' is not recognized as an internal or external command MM2018 2 426 Oct-12-2018, 02:43 PM
Last Post: MM2018
  Empty attribute class dictionary after saving it in a class object dictionary 3dimensions 6 992 May-20-2018, 01:57 PM
Last Post: 3dimensions
  Changing values in a dictionary within a dictionary swannhouse 2 611 Apr-25-2018, 11:59 PM
Last Post: swannhouse
  Class attribute not recognized\working J125 1 1,371 Dec-19-2016, 01:05 AM
Last Post: Yoriz
  Dictionary value not recognized marciokoko 1 1,245 Nov-16-2016, 04:01 PM
Last Post: snippsat
  Need to refer to Value of a key of a dictionary nested within a dictionary xepicxmonkeyx 14 3,904 Oct-06-2016, 07:35 PM
Last Post: wavic

Forum Jump:

Users browsing this thread: 1 Guest(s)