随笔分类 - Python相关
1
摘要:在XXXXXX.py顶部,增加这样两行 import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
阅读全文
摘要:from PIL import Image # 导入PIL的Image包import osgif_file_name = "test.gif" # 把gif图赋值给gif_file_nameim = Image.open(gifFileName) # 使用Image的open函数打开test.gif
阅读全文
摘要:只需要一句代码name = result_name.encode('utf-8').decode('unicode_escape')
阅读全文
摘要:设置中文化 LANGUAGE_CODE = 'zh-hans' 设置中国时区TIME_ZONE = 'Asia/Shanghai' 设置APP INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.cont
阅读全文
摘要:创建项目 django-admin startproject mysite 创建APP $ python manage.py startapp app_label 运行项目 $ python manage.py runserver 你应该会看到如下输出: Performing system chec
阅读全文
摘要:1、操作Excel 1)Openpyxl 地址:https://pypi.org/project/openpyxl/ 文档:https://openpyxl.readthedocs.io/en/stable/ 2、操作网络请求 1)requests 地址:https://pypi.org/proje
阅读全文
摘要:临时使用 pip install 包名 -i https://mirrors.aliyun.com/pypi/simple/ 以后都使用阿里云的源 pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
阅读全文
摘要:类型转换 1 函数 描述 2 int(x [,base ]) 将x转换为一个整数 3 long(x [,base ]) 将x转换为一个长整数 4 float(x ) 将x转换到一个浮点数 5 complex(real [,imag ]) 创建一个复数 6 str(x ) 将对象 x 转换为字符串 7
阅读全文
摘要:Random — Generate pseudo-random numbers Source code: Lib/random.py This module implements pseudo-random number generators for various distributions. F
阅读全文
摘要:下面介绍下random中常见的函数。 前提:需要导入random模块 >>>import random 1、random.random random.random() 用于生成一个0到1的随机符小数: 0 <= n < 1.0 >>> random.random() # Random float x
阅读全文
摘要:itertools Python的内建模块itertools提供了非常有用的用于操作迭代对象的函数。 首先,我们看看itertools提供的几个“无限”迭代器: >>> import itertools>>> natuals = itertools.count(1)>>> for n in natu
阅读全文
摘要:Map函数: 原型:map(function, sequence),作用是将一个列表映射到另一个列表, 使用方法: def f(x): return x**2 l = range(1,10) map(f,l) Out[3]: [1, 4, 9, 16, 25, 36, 49, 64, 81] Red
阅读全文
摘要:urllib — Open arbitrary resources by URL Note The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and
阅读全文
摘要:urllib2 — extensible library for opening URLs Note The urllib2 module has been split across several modules in Python 3 named urllib.request and urlli
阅读全文
摘要:Python 提供了两个基本的 socket 模块。 第一个是 Socket,它提供了标准的 BSD Sockets API。 第二个是 SocketServer, 它提供了服务器中心类,可以简化网络服务器的开发。 下面讲的是Socket模块功能 1、Socket 类型 socket(family,
阅读全文
摘要:Python 官方关于 Socket 的函数请看 http://docs.python.org/library/socket.html 基本上,Socket 是任何一种计算机网络通讯中最基础的内容。例如当你在浏览器地址栏中输入 www.oschina.net 时,你会打开一个套接字,然后连接到 ww
阅读全文
摘要:Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你节省数小时甚至数天的工作时间. 这篇文档介绍了BeautifulSoup4中所有主要特性,并切有小例子.让我来
阅读全文
摘要:迫不及待了吗?本页内容为如何入门Requests提供了很好的指引。其假设你已经安装了Requests。如果还没有, 去 安装 一节看看吧。 首先,确认一下: ·Requests 已安装 ·Requests是 最新的 让我们从一些简单的示例开始吧。 发送请求 使用Requests发送网络请求非常简单。
阅读全文
摘要:#-*-coding:utf-8-*- #1、字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First'} pr
阅读全文
1