hy

Access attribute and method names with slashes or asterisks defined in Hy from Python


If I were to do the following:

(setv a/b 12)

How would I access the variable in Python, such as from a regular python module, or simply using (py)?

(py "print(a/b)")

Solution

  • With mangling:

    => (setv a/b 12)
    => a/b
    12
    => (hy.mangle "a/b")
    "hyx_aXsolidusXb"
    => hyx_aXsolidusXb
    12
    => (py "print(hyx_aXsolidusXb)")
    12
    => (py "print(globals()[hy.mangle('a/b')])")
    12