摘要:
1 2 1 使用__new__方法 3 Python 4 class Singleton(object): def __new__(cls, *args, **kw): if not hasattr(cls, '_instance'): orig = super(Singleton, cls) cls._instance = orig.__new__(cls, *args, **kw... 阅读全文
posted @ 2017-07-17 16:51
橙云生
阅读(513)
评论(1)
推荐(0)
摘要:
1 %r用rper()方法处理对象 2 3 %s用str()方法处理对象 4 5 有些情况下,两者处理的结果是一样的,比如说处理int型对象。 6 7 例一: 8 9 [python] view plain copy 在CODE上查看代码片派生到我的代码片 10 print "I am %d years old." % 22 11 print "I am %s ye... 阅读全文
posted @ 2017-07-17 16:49
橙云生
阅读(1034)
评论(1)
推荐(0)
摘要:
1 项目目录下的urls.py文件默认有admin的url。 2 1.在项目目录下运行manage.py createsuperuser 按提示创建。 3 2. 在app目录下,编辑admin.py 4 # -*- coding: utf-8 -*- 5 from __future__ import unicode_literals 6 7 from django.co... 阅读全文
posted @ 2017-07-17 16:47
橙云生
阅读(124)
评论(0)
推荐(0)
摘要:
1 #coding=utf-8 2 from __future__ import unicode_literals 3 4 from django.shortcuts import render,render_to_response 5 from django.http import HttpRes 阅读全文
posted @ 2017-07-17 16:46
橙云生
阅读(323)
评论(1)
推荐(0)
摘要:
用 __new__函数实现单例模式,主要思想,当创建第二个对象的时候,返回第一个对象 阅读全文
posted @ 2017-07-17 16:41
橙云生
阅读(161)
评论(1)
推荐(0)
摘要:
直接运行代码,浏览器输入 localhost:端口号 即可看到效果。 阅读全文
posted @ 2017-07-17 16:40
橙云生
阅读(270)
评论(1)
推荐(0)
摘要:
简单的Python CGI 在linux平台实现注意:路径是以当前路径为根目录 ,Python文件一般放在/cgi-bin/目录下在linux命令行运行:python -m CGIHTTPServer 8000(端口号默认8000)html文件名设为index.html 测试:本机浏览器 输入 lo 阅读全文
posted @ 2017-07-17 16:39
橙云生
阅读(329)
评论(1)
推荐(0)
摘要:
1 #!/usr/bin/python 2 #coding=utf-8 3 #发送邮件 4 5 import smtplib 6 from smtplib import SMTP as smtp 7 import getpass 8 9 mail_host="smtp.126.com" 10 mail_user="lijunyong3@126.com" 11 mail_p... 阅读全文
posted @ 2017-07-17 16:37
橙云生
阅读(261)
评论(1)
推荐(0)
摘要:
1 #!/user/bin/python 2 #coding=utf-8 3 4 import ftplib 5 import os 6 import socket 7 8 HOST = 'ftp.kernel.org' 9 DIRN = 'pub/linux/kernel' 10 FILE = 'README' 11 12 def main(): 13 try... 阅读全文
posted @ 2017-07-17 16:36
橙云生
阅读(278)
评论(1)
推荐(0)
摘要:
1 #-*- coding: utf-8 -*- 2 #python2.7x 3 4 from pymongo import MongoClient 5 6 def get_db(): 7 #建立连接 8 client = MongoClient("localhost", 27017) 9 #test,还有其他写法 10 db = clien... 阅读全文
posted @ 2017-07-17 16:34
橙云生
阅读(288)
评论(1)
推荐(0)

浙公网安备 33010602011771号