@@ -228,6 +228,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true,
228228Assembly assembly = Assembly . GetExecutingAssembly ( ) ;
229229// add the contents of clr.py to the module
230230string clr_py = assembly . ReadStringResource ( "clr.py" ) ;
231+
231232Exec ( clr_py , module_globals , locals . Reference ) ;
232233
233234LoadSubmodule ( module_globals , "clr.interop" , "interop.py" ) ;
@@ -237,14 +238,22 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true,
237238// add the imported module to the clr module, and copy the API functions
238239// and decorators into the main clr module.
239240Runtime . PyDict_SetItemString ( clr_dict , "_extras" , module ) ;
241+
242+ // append version
243+ var version = typeof ( PythonEngine )
244+ . Assembly
245+ . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( )
246+ . InformationalVersion ;
247+ using var versionObj = Runtime . PyString_FromString ( version ) ;
248+ Runtime . PyDict_SetItemString ( clr_dict , "__version__" , versionObj . Borrow ( ) ) ;
249+
240250using var keys = locals . Keys ( ) ;
241251foreach ( PyObject key in keys )
242252{
243- if ( ! key . ToString ( ) ! . StartsWith ( "_" ) || key . ToString ( ) ! . Equals ( "__version__" ) )
253+ if ( ! key . ToString ( ) ! . StartsWith ( "_" ) )
244254{
245- PyObject value = locals [ key ] ;
255+ using PyObject value = locals [ key ] ;
246256Runtime . PyDict_SetItem ( clr_dict , key . Reference , value . Reference ) ;
247- value . Dispose ( ) ;
248257}
249258key . Dispose ( ) ;
250259}