Skip to content

Commit

Permalink
add some code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozhen committed Jun 30, 2016
1 parent 5f556c0 commit 040e0d1
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions frame/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
常量
"""

import util.decorate as decorate


@decorate.singleton
class Constants(object):

def __init__(self):
import configparser
self.parser = configparser
print("init")
pass

def get(self):

pass

constants = Constants
File renamed without changes.
14 changes: 14 additions & 0 deletions frame/head.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
爬虫头
"""

import configparser


class Head(object):

def __init__(self):
pass

def get_config(self):
pass
8 changes: 8 additions & 0 deletions frame/insect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
爬虫
"""


class Insect(object):
def __init__(self):
pass
7 changes: 0 additions & 7 deletions insect/head.py

This file was deleted.

3 changes: 0 additions & 3 deletions insect/insect.py

This file was deleted.

Empty file added test/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash python


import frame.constants as cons

if __name__ == '__main__':
constants = cons.constants
constants2 = cons.Constants()
constants3 = cons.Constants()
16 changes: 16 additions & 0 deletions util/decorate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
装饰器
"""


def singleton(cls, *args, **kw):
"""
使用singleton装饰器后,该类成为单例类
"""
instances = {}

def _singleton():
if cls not in instances:
instances[cls] = cls(*args, **kw)
return instances[cls]
return _singleton

0 comments on commit 040e0d1

Please sign in to comment.