python __init__ 构造函数
实例化过程 会执行__init__ 的函数方法
class SQLHelper:
def __init__(self): # self = s1
print("helo")
def fetch(self, sql):
pass
def create(self, sql):
pass
def remove(self, nid):
pass
def modify(self, name):
pass
# 实例化过程 会执行__init__ 的函数方法
s1 = SQLHelper()
'''
helo
'''
未改造前
class SQLHelper:
def __init__(self): # self = s1
print("helo")
self.hhost = "c1.salt.com"
self.uuserane = "alex"
self.pwd = ""
def fetch(self, sql):
pass
def create(self, sql):
pass
def remove(self, nid):
pass
def modify(self, name):
pass
# 实例化过程 会执行__init__ 的函数方法
s1 = SQLHelper()
print(s1.hhost, s1.uuserane, s1.pwd)
'''
helo
c1.salt.com alex 123
'''
改造后
class SQLHelper:
def __init__(self, host, username, pwd): # self = s1
print("helo")
self.hhost = host
self.uuserane = username
self.pwd = pwd
def fetch(self, sql):
print(sql)
def create(self, sql):
pass
def remove(self, nid):
pass
def modify(self, name):
pass
# 实例化过程 会执行__init__ 的函数方法
s1 = SQLHelper("c1.salt.com", "alex", "")
s2 = SQLHelper("c2.salt.com", "mike", "")
s1.fetch("select * from A")
'''
helo
helo
select * from A
'''
python __init__ 构造函数的更多相关文章
- python __init__.py用途
转自http://www.cnpythoner.com/post/2.html Python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时, ...
- python __init__.py
python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时,将事先写好的.py文件拷贝 到当前目录,或者是在sys.path中增加事先写好的 ...
- python字典构造函数dict(mapping)解析
Python字典的构造函数有三个,dict().dict(**args).dict(mapping),当中第一个.第二个构造函数比較好理解也比較easy使用, 而dict(mapping)这个构造函数 ...
- 高产的母猪之 python __init__全解
python __init__.py python 识别是不是一个模块的标准是目录下有无 __init__.py 模糊导入 模糊导入中的*中的模块是由__all__来定义的,__init__.py的 ...
- Python __init__.py 作用详解
__init__.py 文件的作用是将文件夹变为一个Python模块,Python 中的每个模块的包中,都有__init__.py 文件. 通常__init__.py 文件为空,但是我们还可以为它增加 ...
- 摘抄python __init__
注意1.__init__并不相当于C#中的构造函数,执行它的时候,实例已构造出来了. 1 2 3 4 5 class A(object): def __init__(self,name): ...
- Python __init__.py文件的作用
我们经常在python的模块目录中会看到 "__init__.py" 这个文件,那么它到底有什么作用呢? 1. 模块包(module package)标识 如果你是使用pytho ...
- python __init__.py 的作用
__init__.py的主要作用是: . Python中package的标识,不能删除 . 定义__all__用来模糊导入 . 编写Python代码(不建议在__init__中写python模块,可以 ...
- Python __init__.py 文件使用
__init__.py的主要作用是: 1. Python中package的标识,不能删除 2. 定义__all__用来模糊导入 3. 编写Python代码(不建议在__init__中写python模块 ...
随机推荐
- Android学习笔记——Menu(一)
背景: Android3.0(API level 11)开始,Android设备不再需要专门的菜单键. 随着这种变化,Android app应该取消对传统6项菜单的依赖.取而代之的是提供anction ...
- SSL 证书配置nginx
ssl.conf文件: server { listen 443; server_name www.domain.com; # 改为绑定证书的域名 ssl on; ssl_certificate 1_w ...
- 超全面的JavaWeb笔记day03<JS对象&函数>
1.js的String对象(****) 2.js的Array对象 (****) 3.js的Date对象 (****) 获取当前的月 0-11,想要得到准确的月 +1 获取星期时候,星期日是 0 4.j ...
- HTML的设计与应用
<html> <head><!-- 设置网页头标题--> <!-- 不需要在页面中显示的内容写在这个里面 --> <base href=" ...
- ios开发之--使用toolbar调整item之间的间隔
toolbar的item有很多种样式,其实经常使用的就几种, UIBarButtonSystemItemFixedSpace 木棍:可以理解为固定的长度 UIBarButtonSystemItemFl ...
- GIT+ Coding使用方法
1 进入码市 :https://coding.net 注册一个账户 2 创建一个项目: 3 本地window环境.安装git : https://git-scm.com/download/win ...
- console.log()的兼容性
在别人那里看到的,兼容IE8-的console.log的实现,以前没想过. if(typeof console == "undefinde"){ this.console = {l ...
- Android Processes and Threads
Processes and Threads When an application component starts and the application does not have any oth ...
- EUI EXML内部类Skin和ItemRenderer
没认真看过...现在试试... EXMl支持内部类 两种支持做为内部类的:Skin和ItemRenderer 优点: 这种最大的好处就是皮肤如果只用一次,不需要单独写成一个exml文件,只需要写在组件 ...
- mycelipse中关于编码的配置
(1)修改工作空间的编码方式: Window->Preferences->General->Workspace->Text file Encoding在Others里选择需要的 ...