Re: Importlib behaves differently when importing pyd file

2022-11-18 Thread Jach Feng
Dieter Maurer 在 2022年11月17日 星期四凌晨1:12:20 [UTC+8] 的信中寫道:
> Jach Feng wrote at 2022-11-15 22:52 -0800: 
> >My working directory d:\Works\Python\ has a package 'fitz' looks like this: 
> > 
> >fitz\ 
> >__init__.py 
> >fitz.py 
> >utils.py 
> >_fitz.pyd 
> > 
> >There is a statement in fitz.py: 
> >return importlib.import_module('fitz._fitz') 
> > 
> >It works fine under Python 3.4 interpreter: 
>  import fitz 
>  
> > 
> >But under Python 3.8 I get an exception: 
>  import fitz 
> >Traceback(... 
> >... 
> >... 
> >ImportError: DLL load failed while importing _fitz 
> 
> The Python C-API is Python version dependent. 
> Your `_fitz.pyd` may need to be recreated for Python 3.8.
It seems that I have to install pymupdf to use fitz. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Passing information between modules

2022-11-18 Thread Tobiah

On 11/18/22 02:53, Stefan Ram wrote:

   Can I use "sys.argv" to pass information between modules
   as follows?

   in module A:

import sys
sys.argv.append( "Hi there!" )

   in module B:

import sys
message = sys.argv[ -1 ]


Kind of seems like a code smell.  I think you would normally
just inject the dependencies like:

module_b.do_thing("Hi there!")

If you really want to have a module-global space,
you could just create a module globals.py, and
import that in every module that needs to share globals.
You can just do globals.message = "Hi there!" and
from another module do print globals.message.






--
https://mail.python.org/mailman/listinfo/python-list


Re: Passing information between modules

2022-11-18 Thread Thomas Passin

On 11/18/2022 10:19 AM, Tobiah wrote:

On 11/18/22 02:53, Stefan Ram wrote:

   Can I use "sys.argv" to pass information between modules
   as follows?

   in module A:

import sys
sys.argv.append( "Hi there!" )

   in module B:

import sys
message = sys.argv[ -1 ]


Kind of seems like a code smell.  I think you would normally
just inject the dependencies like:

 module_b.do_thing("Hi there!")

If you really want to have a module-global space,
you could just create a module globals.py, and
import that in every module that needs to share globals.
You can just do globals.message = "Hi there!" and
from another module do print globals.message.


The module can even create the message or variable dynamically.  I have 
one that, when it is loaded, asks git for the branch and changeset hash 
the code's working directory is using.  This module is imported by 
others that use the branch and changeset data in one way or another.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Passing information between modules

2022-11-18 Thread Axy via Python-list

On 18/11/2022 10:53, Stefan Ram wrote:

   Can I use "sys.argv" to pass information between modules
   as follows?

   in module A:

import sys
sys.argv.append( "Hi there!" )

   in module B:

import sys
message = sys.argv[ -1 ]


This idea has a couple of flaws so can be regarded as bad.

However, if nothing else works (including suggested globals.py module), 
then os.environ could be a better way.


Axy.

--
https://mail.python.org/mailman/listinfo/python-list