bunch icon indicating copy to clipboard operation
bunch copied to clipboard

Auto-translate keys invalid for property access?

Open techtonik opened this issue 13 years ago • 3 comments

It is not documented what happens if Bunch() is expanded using dictionary notation with an element, which key is invalid for property access?

techtonik avatar Jan 30 '12 14:01 techtonik

Can you give an example? I don't think I follow.

dsc avatar Feb 23 '12 01:02 dsc

@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_

luckydonald avatar Jan 06 '15 18:01 luckydonald