python-3.x - print something at import only
问题描述
I have a script for which I want something ("This is the script version 1.0" in the example below) to be printed only when imported (or reloaded). Basically, my script has several functions and one class, but somehow (since I upgraded to python 3.8 actually), the first message in the code is printed several time while executing functions in the class. So is there a way to check when I first import the module? The script is basically like this:
import numpy as np
print('This is the script version 1.0')
def func1():
blah blah
def func2():
blah blah
class Open:
def __init__(self, others):
blah blah
def func3(self)
blah blah
def func4():
blah blah
def func5():
blah blah
解决方案
推荐阅读
- c# - 如何在 C# 中查找哪个 TcpClient 发送了消息
- docker - Docker 文件夹创建和 Kubernetes Volume
- excel - 在不同模块 VBA 中使用的变量
- c - 提供所需输出然后异常终止的函数
- mongodb - Mongodb 与 docker-compose - 创建用户
- c++ - 如何使用c ++中的共享指针通过istream传递本地streambuf
- angular - 使用依赖注入将函数从一个组件传递到另一个组件
- spring-security - 如何即时刷新反应式 Spring Security 应用程序
- javascript - 在 Reactjs 中使用 CSSTransition 和 Group Transition 时没有动画
- javascript - 对 maps.google.com 进行大量(可能约为 100000)的 api 调用会导致 getaddrinfo ENOTFOUND 错误