Cody Brown Cody Brown - 2 months ago 5
Python Question

Python Dictionary Comment Out a Line not Working

I have a python dictionary that I import from another script. For example here is the dictionary that is in another script and loaded in:

def Log():
LogD = {
'Key': [0, 1, 2],
'Key2': [0, 1, 2],
'Key3': [0, 1, 2], # and so on for about 100 records
}
return LogD


And here is the line loading it in:

sys.path.append(r'C:/Whatever')
import Log
LogD = Log.Log()


I import it into my other script do some stuff with it and whatever. I also have a module that comments our a line in the dictionary if I want it to be deleted (ignored). That module finds the line and adds a # comment to the line in the dictionary like so:

def Log():
LogD = {
'Key': [0, 1, 2],
#'Key2': [0, 1, 2],
'Key3': [0, 1, 2], # and so on for about 100 records
}
return LogD


But when I reload the dictionary module, the commented line still appears in the dictionary. No idea why, if I don't load the dictionary as a module and include it in my running script the comment works fine. Any ideas?

Answer

So since no one answered this I have figured it out. Props goes to someone who commented about PYC not indexing correctly. So I added a

os.remove(whatever.pyc) 

after I edit my dictionary and everything works great.

Comments