python-module

Python, variable importing between files

别说谁变了你拦得住时间么 提交于 2020-08-17 11:55:28
问题 Preamble: I feel I probably have wasted so much time for a simple situation... Now, I am making a game with pygame, and at some point, I wanted to split files into two, namely main.py and configurations.py in order to make it more readable. Everything was going good, until I ran into this problem. I will share whole code at the bottom, but I want to summarize first: Now first of all, in main.py , I am importing by, from configurations import * now, the game loop on the main.py depends on the

Python imports when scripts are run from different folder (ancestor)

断了今生、忘了曾经 提交于 2020-06-28 04:56:32
问题 I have a large repository with some fixed structure and I have extended it by some folders and python scripts to add extra functionality to it as a whole. The structure looks as follows: toplevelfolder featureA someModuleA.py __ init __.py featureB someModuleB.py __ init __.py application __ init __.py app.py Now someModuleA.py and someModuleB.py can be invoked via app.py but at the same time also have be able to be invoked directly, however this invocation must come from the toplevelfolder

Why ProcessPoolExecutor on Windows needs __main__ guard when submitting function from another module?

大憨熊 提交于 2020-06-27 17:05:40
问题 Let's say I have a program import othermodule, concurrent.futures pool = concurrent.futures.ProcessPoolExecutor() and then I want to say fut = pool.submit(othermodule.foo, 5) print(fut.result()) Official docs say I need to guard these latter two statements with if __name__ == '__main__' . It's not hard to do, I would just like to know why . foo lives in othermodule , and it knows that ( foo.__module__ == 'othermodule' ). And 5 is a literal int. Both can be pickled and unpickled without any

Why does importing a python module not import nested modules?

我与影子孤独终老i 提交于 2020-06-21 03:57:45
问题 If I do this: import lxml in python, lxml.html is not imported. For instance, I cannot call the lxml.html.parse() function. Why is this so? 回答1: Importing a module or package in Python is a conceptually simple operation: Find the .py file corresponding to the import. This involves the Python path and some other machinery, but will result in a specific .py file being found. For every directory level in the import ( import foo.bar.baz has two levels), find the corresponding __init__.py file,