Issue 36653: Dictionary Key is without ' ' quotes (original) (raw)
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/.tcl', 'args'), 'sub': ('/home/.tcl', 'args')}
To do this, I am using the following class definition and functions: class ProcOne(object): def init(self, name): self.name = name
def __repr__(self):
return self.name
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/.tcl', 'args'), sub: ('/home/.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.
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
https://mail.python.org/mailman/listinfo/tutor
Stackoverflow, Reddit's /rlearnpython, and more. You should check with other, more experienced programmers before reporting things as bugs.
Thank you.