Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
def dict_lower(dictionary):
"""Takes a dict with string keys and makes them all lower case"""
for key,value in dictionary.items():
if isinstance(key,str):
if key.lower() not in dictionary:
dictionary[key.lower()] = value
dictionary.pop(key)
return dictionary
Right now this does nothing, however if I comment out "if isinstance(key,str)" it works perfectly.
#This works perfectly
def dict_lower(dictionary):
"""Takes a dict with string keys and makes them all lower case"""
for key,value in dictionary.items():
#if isinstance(key,str):
if key.lower() not in dictionary:
dictionary[key.lower()] = value
dictionary.pop(key)
return dictionary
I can't figure out why isinstance doesn't want to recognize key as a string, when it seems to be behaving as one everywhere else.
Last edited by Tess on Thu Dec 01, 2022 12:46 pm, edited 1 time in total.
How do you call that function?
And try to print actual object class before checking it. Then look in console to see what do you have. If you ever see something strange, usually you want to add a ton of print statements displaying everything you might need about processes that happen inside.
I added "print key" and "print type(key)" to the beginning of the for loop. For each one it printed the string fine and then <type 'str'> after it. So key seems to be a string, isinstance just doesn't want to accept it
I also added print "Made it here" right inside isinstance and it never printed...
def dict_lower(dictionary):
"""Takes a dict with string keys and makes them all lower case"""
for key,value in dictionary.items():
print key #This prints the string fine
print type(key) #This prints <type 'str'>
if isinstance(key,str):
print "Made it here" #This never prints
if key.lower() not in dictionary:
dictionary[key.lower()] = value
dictionary.pop(key)
return dictionary
Try to check for (str, pystr, future.utils.text_type) - that's it, tuple of three types. IIRC RenPy replaces standard string as part of Python3 compatibility fixes.
If it works, figure out concrete type you want. My bet is on pystr.