8000 PythonEngine.Exec scope between classes · Issue #591 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content
PythonEngine.Exec scope between classes #591
Closed
@evandavey

Description

@evandavey

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6
  • Operating System: Windows 10

Details

I am embedding Python using PythonEngine.Exec to run code read from a file which seems to be losing global scope.

string code;
using (var streamReader = new StreamReader(scriptFile, Encoding.UTF8)) {
   code = streamReader.ReadToEnd();
}
 
using (Py.GIL()) {
    PythonEngine.Exec(code)
}

The python code contains two classes:

class Test1():
   pass

class Test2():
   def __init__(self):
       Test1()

Test2()

Error:

NameError: name 'Test1' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0