Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit652b31b

Browse files
committed
add 单例import方法
1 parenta8af392 commit652b31b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎Readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,25 @@ class MyClass:
453453
...
454454
```
455455

456+
###4 import方法
457+
458+
作为python的模块是天然的单例模式
459+
460+
```python
461+
# mysingleton.py
462+
classMy_Singleton(object):
463+
deffoo(self):
464+
pass
465+
466+
my_singleton= My_Singleton()
467+
468+
# to use
469+
from mysingletonimport my_singleton
470+
471+
my_singleton.foo()
472+
473+
```
474+
456475
##17 Python中的作用域
457476

458477
Python 中,一个变量的作用域总是由在代码中被赋值的地方所决定的。

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp