Summary of some differences between python packages and folders
- 2021-12-04 10:51:15
- OfStack
1, 1 or more folders make up a module, and a combination of modules makes up a package published in a public directory.
2. The package must have a __init__ file, otherwise it is a folder.
Instances
import pynvml
pynvml.nvmlInit()
# Here's 1 Yes GPU id
handle = pynvml.nvmlDeviceGetHandleByIndex(1)
meminfo = pynvml.nvmlDeviceGetMemoryInfo(handle)
print(meminfo.total) # No. 1 2 Total memory size of block graphics card
print(meminfo.used)# Here are bytes bytes , so if you want to get a omen, M Is the unit and needs to be divided by 1024**2
print(meminfo.free) # No. 1 2 Remaining memory size of block graphics card
Content extension:
#server.py
from package.modb import funb
from directory.moda import funa
funa()
funb()
import package.modb
import directory.moda
directory.moda.funa()
package.modb.funb()
In python3, whether there is __init__. py file program can be imported and run normally
You cannot import the funa function under the moda. py module without __init__. py in python2
Prompt that a block of moda could not be found
Traceback (most recent call last):
File "/Users/wangjinyu/PycharmProjects/work-practice/packagetest/server.py", line 2, in < module >
from directory.moda import funa
ImportError: No module named directory.moda