pythonnet icon indicating copy to clipboard operation
pythonnet copied to clipboard

Add ability to set python module file string instead of it always being None

Open bmello4688 opened this issue 3 years ago • 3 comments

Environment

  • Pythonnet version: Latest
  • Python version: 3.7+
  • Operating System: All
  • .NET Runtime: All

Details

  • Describe what you were trying to get done.

    When creating a python module from a string (PyModule FromString) the file parameter is always set to None. If I want to create a virtual package structure in memory I need to be able to set file to a specified file structure.

bmello4688 avatar Dec 08 '22 14:12 bmello4688

You have to set it yourself, that's how it works in the C-API as well: https://docs.python.org/3/c-api/module.html#c.PyModule_NewObject

filmor avatar Dec 08 '22 16:12 filmor

Sorry, I just saw your PR (#2044), is this not the same as just setting __file__ explicitly on the PyModule object?

filmor avatar Dec 08 '22 16:12 filmor

Yes, it is the same thing. It just seems a bit clunky that it is initially set to none then I have to overwrite it with the correct file structure.

bmello4688 avatar Dec 08 '22 17:12 bmello4688