bunch
bunch copied to clipboard
Auto-translate keys invalid for property access?
It is not documented what happens if Bunch() is expanded using dictionary notation with an element, which key is invalid for property access?
Can you give an example? I don't think I follow.
@dsc Maybe something like
bunched["3"] = "foo";
bunched.3 # is not valid syntax.
bunched["foo'quotes'bar"] = "hua"
bunched.foo'quotes'bar # does not work either.
bunched["lol2345"] = "rickrolled."
bunched.lol2345 # works.
Maybe replace all wrong characters with _ and prefix strings starting with a number with int_?
Regex for the former could be (generating only one _ for multible illegal characters:
import re
unallowed_in_variable_name = re.compile('[\W]+')
var_name = unallowed_in_variable_name.sub('_', name)
# {'foo-2.4;"':'foo'} becomes bunched.foo_2_4_