[英]Python user defined modules where to import system modules
我創建了一個模塊: test.py
。 里面看起來像:
import matplotlib.pyplot as plt
N = 5
def test_img(data_loc):
#F = load images from data_loc
def plot_img(im):
# a bunch of other codes
plt.imshow(im)
for i in range(N):
plot_img(F(i))
(1) 要在某處使用它作為import test
或from test import test_img
,我在哪里import matplotlib.pyplot as plt
? 是不是像現在一樣在test.py
里面?
(2) 在這種情況下, plot_img
是否嵌套在test_img
中是否重要,如果它只在test_img
?
(3) 我在哪里聲明常量N
有關系嗎(這是一個例子,我有很多常量)? 如果它在plot_img
中使用怎么辦,我在哪里聲明它?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.