为指定目录的指定后缀文件首行添加“#coding:utf-8”
来源:互联网 发布:霍华德新秀体测数据 编辑:程序博客网 时间:2024/05/01 13:44
为了使用中文需要在py文件的首行添加“#coding:utf-8”,为了方便,我们一次性为我们的工作目录的所有py文件都添加上:
#!/bin/bashfunction scandir() { local cur_dir parent_dir workdir workdir=$1 cd ${workdir} if [ ${workdir} = "/" ] then cur_dir="" else cur_dir=$(pwd) fi for dirlist in $(ls ${cur_dir}) do if test -d ${dirlist};then cd ${dirlist} scandir ${cur_dir}/${dirlist} $2 cd .. else local filename=$dirlist if [[ ${filename:(-${#2})} = $2 ]] then exist=`cat $filename | sed -n '1p'| grep '#coding:utf-8'` if [[ -z $exist ]] then echo "modifying file:"$filename sed -i 1'i\#coding:utf-8' $filename fi fi fi done}if test -d $1then scandir $1 $2elif test -f $1then echo "you input a file but not a directory,pls reinput and try again" exit 1else echo "the Directory isn't exist which you input,pls input a new one!!" exit 1fi
执行如:
./add_utf8.sh /usr/lib/python2.7/dist-packages/nova/ .py
0 0
- 为指定目录的指定后缀文件首行添加“#coding:utf-8”
- Python的编码注释# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-的主要作用是指定文件编码为utf-8, 因为一般默认的是ASCII码,如果要在
- 定期清理 2周前 指定目录 指定层级 指定后缀 的文件
- 列出指定目录下后缀是.mp3的所有文件
- 使用FilenameFilter来找出目录下指定后缀的文件
- bat 删除指定目录下带后缀的文件
- mk拷贝后缀相同的文件到指定目录命令
- 统计指定目录下,指定文件后缀的文件代码行数,并排序
- 关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
- 关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
- 【整理】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
- 关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
- (好文转发)关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
- 关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
- 获取指定的目录下面的指定的后缀的文件
- javase——递归获取指定目录下(包括子目录)指定后缀的文件的文件名
- 获取指定目录下(包括子目录)的指定后缀的文件
- 从目录中查找指定后缀文件内的指定字符串
- 欢迎使用CSDN-markdown编辑器
- SecureCRT访问Linux中文乱码问题
- c# string类型和json之间的相互转换
- 如何在S函数中对变量或者输入信号进行求导
- Java中文件与目录管理
- 为指定目录的指定后缀文件首行添加“#coding:utf-8”
- 蓝鸥Unity入门Input类学习笔记
- 【C#】61. 并行查询的异常处理 PLINQ Exception
- Android基础总结+SQlite数据库【申明:来源于网络】
- windows下搭载tomcat运行环境
- Linux 常用命令
- ios 时区,时间格式NSDate
- Spark源码解析之小分区合并
- Ionic2 定义全局变量方法