- 浏览: 126827 次
- 性别:
- 来自: 广州
最新评论
-
wkl17:
好文,完阅,实用
MySQL5.7的备份与恢复简介和使用mysqldump备份MySQL数据库
文章列表
vi /root/.pythonstartup
import sys
import readline
import rlcompleter
import atexit
import os
readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.regis ...
[root@localhost ~]# yum groupinstall "Development Tools" -y
[root@localhost ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum install python-pip -y
[root@localhost ~]# yum install -y python-devel openssl-devel libxslt-devel libxml2-devel
...
Python-redis基本命令
- 博客分类:
- redis
1、String 操作
redis中的String在在内存中按照一个name对应一个value来存储
set()
#在Redis中设置值,默认不存在则创建,存在则修改
r.set('name', 'zhangsan
python-redis 管道
- 博客分类:
- redis
redis默认在执行每次请求都会创建(连接池申请连接)和断开(归还连接池)一次连接操作,如果想要在一次请求中指定多个命令,则可以使用pipline实现一次请求指定多个命令,并且默认情况下一次pipline 是原子性操作
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import redis
pool = redis.ConnectionPool(host='192.168.0.110', port=6379)
r = redis.Redis(connection_pool=pool)
pipe = r.pipeline(tran ...
python-redis 连接
- 博客分类:
- redis
提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用官方的语法和命令,Redis是StrictRedis的子类
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import redis
r = redis.Redis(host='192.168.0.88', port=6379,db=0)
r.set('name', 'zhangsan') #添加
print (r.get('name')) #获取
edis-py使用connection pool ...
3》启动和停止Redis
直接启动
redis-server
redis-server /ect/redis.conf
停止Redis
shutdown
结束Redis的进程也可以
3.命令返回值
1》状态回复
ping
SET test 'this is a test'
2》错误回复
错误回复以error开始
(error) ERR unknown command 'TESTERROR'
3》整数回复:
以interger 数值
(integer) 2
4》字符串回复
GET test
(nil)代表 ...
python-redis订阅者和发布
- 博客分类:
- redis
#发布者:
>>> import redis
>>> rc= redis.Redis()
>>> rc.publish('test01','hello word')
1L
>>> rc.publish('test01','hello words')
1L
#订阅者
>>> import redis
>>> rc= redis.Redis()
>>> ps=rc.pubsub()
>>> p ...
python装饰器之类内部成员装饰
- 博客分类:
- python
class TestA(object):
def __init__(self,name):
self.name=name
def tryit(func):
def _tryit(*args,**xargs):
args[0].funcA()
try:
return func(*args,**xargs)
finally:args[0].funcB()
return _tryit
def funcA(self):
print 'hello',self.name
...
django(8):简单配置admin页
- 博客分类:
- django
[root@localhost project0904]# vim app0904/admin.py
from django.contrib import admin
from app0904.models import Student,Teacher,Group
# Register your models here.
admin.site.register(Student)
admin.site.register(Teacher)
admin.site.register(Group)
[root@localhost project0904]# python m ...
[root@localhost project0904]# vim app0904/models.py
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class Teacher(models.Model):
id=models.IntegerField(primary_key=True)
name=models.CharField(max_length=50)
class Meta:
db_table= ...
django(6)过滤器及自定义过滤器
- 博客分类:
- django
{% extends 'base.html' %}
{% block title%}studentlist{%endblock%}
{% block content%}
{%for student in studentList%}
<li>{{student.id |add:'8'|floatformat:"2" }},{{student.name|upper}},{{student.age}},{{student.sex}}</li>
{%empty%}
sorry
{% endfor %}
{% endblo ...
django(5):数据库模型models
- 博客分类:
- django
创建学生类
vim app0904/models.py
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class Student(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
age=models.IntegerField()
sex=mo ...
django(4):传递参数
- 博客分类:
- django
from django.http import HttpResponse
def hello(request):
return HttpResponse('HELLO WORD')
def helloParam(request,p1):
return HttpResponse('Hello ,%s' %p1)
def helloParams(request,p1,p2):
return HttpResponse('Hello,p1:%s,p2:%s' %(p1,p2))
def hello1(request,id,name):
return ...
python多线程(3)生存者消费模型
- 博客分类:
- python多线程
import threading,time
import Queue
import random
q=Queue.Queue()
def Chan(name):
for i in range(5):
q.put(i)
print '%s shengchan %s baozi' %(name,i)
time.sleep(random.randrange(5))
def Chi(name):
count=0
while count < 5:
d=q.get()
print '%s chichic ...
python多线程(2)加锁
- 博客分类:
- python多线程
import threading,time
number = 0
lock = threading.RLock() #定义锁
def run(num):
lock.acquire() #加
global number
number+=1
print number
lock.release() #释放
for i in range(5):
t=threading.Thread(target=run,args=(i,))
t.start()