Title: Dictionary Key is without ' ' quotes
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: PushkarVaity, ezio.melotti, mrabarnett, steven.daprano
Priority: normal Keywords:

Created on 2019-04-17 22:34 by PushkarVaity, last changed 2019-04-17 23:43 by steven.daprano. This issue is now closed.

Messages (3)
msg340452 - (view) Author: (PushkarVaity) Date: 2019-04-17 22:34
I am using Python 3.7 with anaconda install.
I am trying to write out a dictionary with similar key's.

for ex: proc_dict = {'add': ('/home/file.tcl', 'args'), 'add': ('/home/file2.tcl', 'args'), 'sub': ('/home/file2.tcl', 'args')}

To do this, I am using the following class definition and functions:
    class ProcOne(object):
        def __init__(self, name):
   = name

        def __repr__(self):

I am writing out the dictionary in the following way:
proc_dict[ProcOne(proc_name)] = (full_file, proc_args)

Now, the dictionary key as shown in the example at top is of string type. proc_name is the variable holding this string.

The values are tuples. Both elements in the tuple are strings.

When the dictionary is finally written out, the format is as below:
proc_dict = {add: ('/home/file.tcl', 'args'), add: ('/home/file2.tcl', 'args'), sub: ('/home/file2.tcl', 'args')} 

Please note the difference from the first example.
The key values don't have a ' ' quote in spite of being a string variable type. 

Since the string quotes are missing, it is very difficult to do post processing on this dictionary key.

I am a student and I though that this is an issue because now I am not able to compare the key value with a normal string because of the missing quotes. The in or not in checking operations do not evaluate to true/false because of the missing quotes.

Please let me know if this has never been reported before as I am just a novice programmer and would be a big boost to my morale :-) 
Also, please let me know if this issue was already known or wasn't an issue at all.
msg340457 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2019-04-17 23:26
That should be:

        def __repr__(self):
            return repr(

Not a bug.
msg340458 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-04-17 23:43
Hi PushkarVaity, and welcome!

I hope that Matthew's suggestion fixes your code for you, but please remember that this is a bug tracker for bugs in the Python language and standard library, not a help desk.

As a beginner, 99.9% of the times you think that you have found a bug in Python, you haven't, it will be a bug in your own code. There are many forums where you can ask for help with your code, such as the tutor mailing list

Stackoverflow, Reddit's /rlearnpython, and more. You should check with other, more experienced programmers before reporting things as bugs.

Thank you.
Date User Action Args
2019-04-17 23:43:13steven.dapranosetnosy: + steven.daprano
messages: + msg340458
2019-04-17 23:26:44mrabarnettsetstatus: open -> closed
resolution: not a bug
messages: + msg340457

stage: resolved
2019-04-17 22:34:23PushkarVaitycreate