Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading