摘要:
用来理解轮播图的操作原理 阅读全文
摘要:
1 服务端 2 #!/usr/bin/python 3 4 from socket import * 5 import sys 6 import os 7 8 class Node(object): 9 def __init__(self,val,next = None): 10 self.val = val 11 ... 阅读全文
摘要:
1 在TCP层,有个FLAGS字段,这个字段有以下几个标识:SYN, FIN, ACK, PSH, RST, URG. 2 3 其中,对于我们日常的分析有用的就是前面的五个字段。 4 5 它们的含义是: 6 7 SYN表示建立连接, 8 9 FIN表示关闭连接, 10 11 ACK表示响应, 12 13 PSH表示有 DATA数据传输, 14 15 RST表示连接... 阅读全文
摘要:
1 #!/usr/bin/python 2 3 import tornado.httpserver 4 import tornado.ioloop 5 import tornado.options 6 import tornado.web 7 8 from tornado.options import define,options 9 10 define('port',d... 阅读全文
摘要:
1 一、连接数据库 2 格式:mysql -h主机地址 -u用户名 -p用户密码 3 1.1.连接到本机上的MYSQL。 4 首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root -p,回车后提示你输密码. 5 注意用户名前可以有空格也可以没有空格,但是密码前必须没有空格,否则让你重新输入密码。 6 如果刚安装好MYSQL,超级用户ro... 阅读全文
摘要:
1 简单来说,编程中提到的 lambda 表达式,通常是在需要一个函数,但是又不想费神去命名一个函数的场合下使用,也就是指匿名函数。这一用法跟所谓 λ 演算(题目说明里的维基链接)的关系,有点像原子弹和质能方程的关系,差别其实还是挺大的。 2 3 不谈形式化的 λ 演算,只说有实际用途的匿名函数。先举一个普通的 Python 例子:将一个 list 里的每个元素都平方: 4 map( ... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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 阅读全文
摘要:
用 __new__函数实现单例模式,主要思想,当创建第二个对象的时候,返回第一个对象 阅读全文
摘要:
直接运行代码,浏览器输入 localhost:端口号 即可看到效果。 阅读全文
摘要:
简单的Python CGI 在linux平台实现注意:路径是以当前路径为根目录 ,Python文件一般放在/cgi-bin/目录下在linux命令行运行:python -m CGIHTTPServer 8000(端口号默认8000)html文件名设为index.html 测试:本机浏览器 输入 lo 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
1 2 问题一:以下的代码的输出将是什么? 说出你的答案并解释。 3 class Parent(object): 4 x = 1 5 class Child1(Parent): 6 pass 7 class Child2(Parent): 8 pass 9 print Parent.x, Child1... 阅读全文
摘要:
1 #!/usr/bin/python 2 #coding=utf-8 3 #网络爬虫 4 import urllib,re 5 6 def getHtml(url): 7 page=urllib.urlopen(url) #打开一个url 8 html=page.read() #读取全部内容生成一个字符串(对象) 9 return html ... 阅读全文
摘要:
1 #!/usr/bin/python 2 #coding=utf-8 3 #server 4 import socket 5 import sys 6 import os 7 8 server_address = './test' 9 10 #首先确保这个文件不能存在,只是用于本地套接字的通信,如果已经存在则不可以了 11 try: 12 os.unlink... 阅读全文
摘要:
1 #!/usr/bin/python 2 #coding=utf-8 3 #发送端 4 import sys,struct,socket 5 from time import sleep 6 7 message="hello" 8 message1="nihao" 9 10 multicast_group=('224.3.29.73',10003) 11 multic... 阅读全文