04 2018 档案

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 星河赵 阅读(204) 评论(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 星河赵 阅读(381) 评论(0) 推荐(0) 编辑

查看本机密钥 以及服务器授权密钥 免密码登录
摘要:服务器授权密钥: vim ~/.ssh/authorized_keys 查看本机密钥 cat ~/.ssh/id_rsa.pub 阅读全文

posted @ 2018-04-19 17:35 星河赵 阅读(2183) 评论(0) 推荐(0) 编辑

Mac在Finder中显示/usr、/tmp、/var等隐藏目录
摘要:Finder中默认是不显示/usr、/tmp、/var等隐藏目录的,通过在终端中输入一下命令来另其显示: 之后还需重启Finder,最简单的方法是Alt+鼠标右击屏幕下方的Finder图标,选择“重新开启”即可。 阅读全文

posted @ 2018-04-19 16:18 星河赵 阅读(401) 评论(0) 推荐(0) 编辑

MAC下是用brew安装Redis
摘要:安装brew 在命令行里运行下面的命令,需要等待一段时间。 安装Redis 安装完成后可以是用下面的命令来查看是否安装成功 安装完成后就可以来安装redis了 运行 其他 运行后自动在后台运行,关闭后也会继续运行。可以使用端口检测命令来查看。 阅读全文

posted @ 2018-04-18 20:52 星河赵 阅读(428) 评论(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 星河赵 阅读(3059) 评论(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 星河赵 阅读(292) 评论(0) 推荐(0) 编辑

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

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

OSX系统添加定时任务 Linux crontab命令 定时执行py 文件 任务
摘要:#输出日志 # cpd_$(date +"\%Y-\%m-\%d_\%H").log 按照日期输出日志 OS X是苹果Mac的操作系统。今天遇到了一个想向系统里添加定时任务的问题。比如我想在12点运行一个脚本,而这个时间我又要出去吃饭。这个时候就可以通过增加定时任务的办法来解决。 这里主要提供两种方 阅读全文

posted @ 2018-04-11 19:06 星河赵 阅读(296) 评论(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 星河赵 阅读(15158) 评论(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 星河赵 阅读(293) 评论(0) 推荐(0) 编辑

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

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

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

posted @ 2018-04-04 19:28 星河赵 阅读(3847) 评论(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 星河赵 阅读(428) 评论(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 星河赵 阅读(5142) 评论(0) 推荐(0) 编辑

Mac Terminal菜鸟篇之使用unrar解压rar文件
摘要:在Mac上的归档工具不能够解压rar文件,这时可以使用终端中的unrar来解决问题。 步骤如下: 1.使用Homebrew安装unrar(有关Homebrew的安装和使用见Homebrew) [plain] view plain copy $ brew install unrar ==> Downl 阅读全文

posted @ 2018-04-03 09:52 星河赵 阅读(451) 评论(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 星河赵 阅读(366) 评论(0) 推荐(0) 编辑

linux环境变量设置 以及 source命令 Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程 Linux 设置环境变量
摘要:定制环境变量 环境变量是和Shell紧密相关的,用户登录系统后就启动了一个Shell。对于Linux来说一般是bash,但也可以重新设定或切换到其它的Shell。环境变量文件:/etc/profile。 环境变量是通过Shell命令来设置的,设置好的环境变量又可以被所有当前用户所运行的程序所使用。对 阅读全文

posted @ 2018-04-02 20:24 星河赵 阅读(1405) 评论(0) 推荐(0) 编辑

python URLObject url处理模块
摘要:1、需求来源 给一个url串,例如https://github.com/zacharyvoase/urlobject?spam=eggs#foo,想要截取串中某个部分,比如传输协议(https)、服务器名称、用户名密码、路径信息、后面query等。自己能想到的主要由以下几种方法: (1)正则 (2) 阅读全文

posted @ 2018-04-02 19:09 星河赵 阅读(1380) 评论(0) 推荐(0) 编辑

python 在Unicode和普通字符串 str 之间转换
摘要:unicodestring = u"Hello world" # 将Unicode转化为普通Python字符串:"encode" utf8string = unicodestring.encode("utf-8") asciistring = unicodestring.encode("ascii") isostring = unicodestring.encode("ISO-88... 阅读全文

posted @ 2018-04-02 15:44 星河赵 阅读(10452) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示