随笔分类 -  Python常用方法

上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页

收藏了一些好的文章以及教程 Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年。 Python是纯粹的自由软件, 源代码和解释器CPython遵循 GPL(GNU General Public License)协议[1] 。
python 字符串编码 str和unicode 区别以及相互转化 decode('utf-8') encode('utf-8')
摘要: 阅读全文

posted @ 2018-06-04 14:01 星河赵 阅读(643) 评论(0) 推荐(0)

Python 操作redis 常用方法
摘要:Python 操作redis 1.字符串 2.列表 3.集合 4.散列 阅读全文

posted @ 2018-06-01 19:11 星河赵 阅读(549) 评论(0) 推荐(0)

关于Python中深拷贝与浅拷贝的理解(一)---概念
摘要:输出为:a = [1, 2, 3, 4, ['a', 'b', 'c'], 5] b = [1, 2, 3, 4, ['a', 'b', 'c'], 5] c = [1, 2, 3, 4, ['a', 'b', 'c']] d = [1, 2, 3, 4, ['a', 'b']] 阅读全文

posted @ 2018-05-28 17:08 星河赵 阅读(133) 评论(0) 推荐(0)

python2 和 python3 区别
摘要:python2 阅读全文

posted @ 2018-05-21 18:21 星河赵 阅读(173) 评论(0) 推荐(0)

使用pip安装包提示TLS证书错误解决办法
摘要:最近有不少同学在使用pip安装python包的时候,经常会出现以下类似的错误: 出现这个错误的原因是python.org已经不支持TLSv1.0和TLSv1.1了。更新pip可以解决这个问题。但是如果使用传统的python -m pip install --upgrade pip的方式,还是会出现那 阅读全文

posted @ 2018-05-21 10:12 星河赵 阅读(746) 评论(0) 推荐(0)

Python 连接数据库 mysql
摘要:python 连接 数据库 阅读全文

posted @ 2018-05-13 00:01 星河赵 阅读(225) 评论(0) 推荐(0)

Python进行URL解码
摘要:所用模块:urllib 所用函数:urllib.unquote() 案例 输出 问题扩展 urllib.unquote()目的是对url编码进行解码,与该函数对应的是编码函数urllib.quote() 通常如果一样东西需要编码,说明这样东西并不适合传输。原因多种多样,如Size过大,包含隐私数据。 阅读全文

posted @ 2018-05-03 10:44 星河赵 阅读(4330) 评论(0) 推荐(0)

Python 执行linux 命令
摘要:2.os.popen # 该方法不但执行命令还返回执行后的信息对象 popen(command [, mode='r' [, bufsize]]) -> pipeOpen a pipe to/from a command returning a file object. tmp = os.popen 阅读全文

posted @ 2018-05-02 14:25 星河赵 阅读(522) 评论(0) 推荐(0)

python unicode to str and str to unicode
摘要:@staticmethod def unicode2str(p_unicode): v = p_unicode.encode('unicode-escape').decode('string_escape') if p_unicode is not None else None return v @staticmethod def... 阅读全文

posted @ 2018-04-27 18:09 星河赵 阅读(212) 评论(0) 推荐(0)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 1: ordinal not in range(128)
摘要:使用codecs模块 codecs模块能在处理字节流的时候提供很大帮助。你可以用定义的编码来打开文件并且你从文件里读取的内容会被自动转化为Unicode对象。 试试这个: 阅读全文

posted @ 2018-04-20 19:42 星河赵 阅读(388) 评论(0) 推荐(0)

python用zipfile模块打包文件或是目录、解压zip文件实例
摘要:#!/usr/bin/env python # -*- coding: utf-8 -*- from zipfile import * import zipfile #解压zip文件 def unzip(): source_zip="c:\\update\\SW_Servers_20120815.zip" target_dir="c:\\update\\" ... 阅读全文

posted @ 2018-04-18 12:37 星河赵 阅读(3071) 评论(0) 推荐(0)

python 发送邮件 带附件
摘要:# coding:utf-8 # __author__ = 'Mark sinoberg' # __date__ = '2016/5/26' # __Desc__ = 实现发送带有各种附件类型的邮件 import urllib, urllib2 import smtplib from email.mime.multipart import MIMEMultipart fro... 阅读全文

posted @ 2018-04-17 18:57 星河赵 阅读(300) 评论(0) 推荐(0)

python 类的继承
摘要:XNginxLog.py 注意:Python2 父类 XNginxLog(object) 必须要加object XAdNginxLog.py 使用 log_obj = XAdNginxLog(p_line=line) 阅读全文

posted @ 2018-04-11 19:38 星河赵 阅读(165) 评论(0) 推荐(0)

python 创建txt并且写入做追加
摘要:import os def create_str_to_txt(self,date,str_data): """ 创建txt,并且写入 """ path_file_name = './report/action_{}.txt'.format(date) if not os.path.exists(path_file_name): with ... 阅读全文

posted @ 2018-04-10 16:42 星河赵 阅读(15169) 评论(0) 推荐(1)

git 常用命令以及解决问题方法
摘要:1. 创建分支: git branch test 2.切换分支: git checkout test 或切换为主分支 git checkout master 3.查看当前分支 git branch -va 4. 如:当前分支为test 要合并dev分支 git merge dev 后确保没问题 切换 阅读全文

posted @ 2018-04-08 18:18 星河赵 阅读(298) 评论(0) 推荐(0)

替换python字典中的key值
摘要: 阅读全文

posted @ 2018-04-08 11:49 星河赵 阅读(2538) 评论(0) 推荐(0)

python匹配两个字符串中间的字符串
摘要:问题:使用python正则如何匹配两字符串中间的字符串解决:使用re模块的findall,注意,re.match是只能从开头匹配的方法: 这样就可以匹配到script标签中的代码了 阅读全文

posted @ 2018-04-04 19:28 星河赵 阅读(3856) 评论(0) 推荐(0)

Python 部署 flask 用uwsgi和nginx
摘要:安装uwsgi nginx 具体方法请百度 1.在项目目录下建立.ini文件 xad_uwsgi.ini 2配置nginx文件 在此路径下建立对应文件如果没有请自行创建 xadconf.test.com为二级域名 /etc/nginx/sites-enabled/xadconf.test.com 3 阅读全文

posted @ 2018-04-03 19:11 星河赵 阅读(435) 评论(0) 推荐(0)

[Python] 利用commands模块执行Linux shell命令
摘要:用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要函数: 1. commands.getoutput('shell command') 执行shell 阅读全文

posted @ 2018-04-03 11:48 星河赵 阅读(5158) 评论(0) 推荐(0)

python 字典格式嵌套,相同项做叠加
摘要:all_dict = {} for tg_id in ['com.qq_a','com.qq_b','com.qq_c','com.qq_c']: tmp_dict = all_dict.get(tg_id,{'times':0}) tmp_dict['times'] += 123 all_dict[tg_id] = tmp_dict print(all_dict)... 阅读全文

posted @ 2018-04-02 21:22 星河赵 阅读(374) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页

导航