In this part we will talk about Python String module.
import string
print string.center("abc",5,"-")
# -abc-
print string.ljust("abc",5,"-")
#abc--
print string.rjust("ab...
Python format character tuple list and dist each other
#-*-coding:utf-8-*-
#1、字典
dict = {'name': 'Zara', 'age': 7, 'class': 'First'}
#字典转为字符串,返回: {'age': 7, 'name': 'Zara', ...
Use urllib urllib2 requests download files from url
Way 1:
import urllib
print "downloading with urllib"
url = 'http://www.pythontab.com/test/demo.zip'
print "downl...
Windows如何使用Python操作摄像头
用过USB摄像头的都知道,你需要使用鼠标来操作它,比如截个图,录个像什么的,要点N次鼠标,对于我们那些不喜欢多次点击鼠标的人来说,这是一件很boring的事情,所以,本文将教你如何使用Python来操作摄像头。
这里,我们需要三个Python库: VideoCapture, PIL 和 pygame...
快速排序算法,堆排序算法,归并排序,二分查找算法,DFS,BFS,Dijkstra算法,动态规划算法,朴素贝叶斯分类算法
###算法一:快速排序算法
快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下,排序 n 个项目要Ο(n log n)次比较。在最坏状况下则需要Ο(n2)次比较,但这种状况并不常见。事实上,快速排序通常明显比其他Ο(n lo...
What are useful CLI tools for Linux system admins
System administrators (sysadmins) are responsible for day-to-day operations of production systems and services. One of the crit...
How to use Python datetime and time
Time method often used1.Get now time:
Use time method, get the now Timestamp
In [42]: time.time()
Out[42]: 1408066927.208922
Change timesta...
pygeoipmap.py
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function, unicode_literals, with_statement
import argparse
import requests
import json
import ...
How to export Excel from Database in Django 1.7
Install xlwt
pip install xlwt
Create Database Item
Export Excel in Views
def export_item_list(request):
wb=xlwt.Workbook...
Two ways replace character in Python
python 字符串替换 是python 操作字符串的时候经常会碰到的问题,这里简单介绍下字符串替换方法。python 字符串替换可以用2种方法实现:1是用字符串本身的方法。2用正则来替换字符串
下面用个例子来实验下:a = ‘hello word’把a字符串里的word替换为p...