Python中文注释报错解决方法

使用Python脚本的时候,代码中一旦有了中文注释便会报错,类似如下内容:

SyntaxError: Non-ASCII character '\xe8' in file ch.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

原因

如果文件里有非ASCII字符,需要在第一行或第二行指定编码声明。

解决方法

在第一行或是第二行加入这么一句

# -- coding: utf-8 --

完美解决。

参考链接


Python 中文注释报错解决方法

Apache中设置来自移动端的请求强制重定向到HTTPS规避运营商的页面劫持

最近中国移动的流量劫持到了令人发指的地步,凡是没有使用HTTPS的网址都会被劫持,非常影响用户体验。如下图所示(右下角):

继续阅读Apache中设置来自移动端的请求强制重定向到HTTPS规避运营商的页面劫持

Windows 10,ubuntu 16.04双系统安装后修复grub引导的方法

原本电脑上已经有了Windows 10ubuntu 16.04双系统,一次磁盘克隆之后(更换硬盘),引导界面消失了,只能进入Windows 10系统,无法进入ubuntu 16.04

具体的修复办法如下:

继续阅读Windows 10,ubuntu 16.04双系统安装后修复grub引导的方法

Windows 10禁用PIN, 图片以及密码登录

If you want a logon password to secure your Windows 10, you can create a password, add a PIN code, and set up a Picture password for your user account. However, sometimes password may bring much inconvenience so that you don't want any password. In this case, just don't set up any password or disable password logon. Now here we show how to disable PIN, Picture and Password logon in Windows 10.

继续阅读Windows 10禁用PIN, 图片以及密码登录

华为WS832修复(ubuntu 16.04.5系统下进行操作)

华为WS832已经损坏了很长时间了,一直提示是没有插上网线,明显是WAN口损坏了。跟华为的售后扯皮了几个月,华为拒绝维修,更换政策又非常的不合理,最后的解决方案就只剩下自己维修这一条路了。

继续阅读华为WS832修复(ubuntu 16.04.5系统下进行操作)

Ubuntu 17.10/18.04使用内置指纹识别(联想T440内置Synaptics Validity Sensors)

最近想在自己的联想T440机器上启用内置的指纹识别,具体的执行命令如下:

$ sudo add-apt-repository ppa:fingerprint/fingerprint-gui

$ sudo apt update

$ sudo apt install libbsapi policykit-1-fingerprint-gui fingerprint-gui

$ sudo apt-get install fprintd libpam-fprintd

$ sudo apt install fprint-demo

继续阅读Ubuntu 17.10/18.04使用内置指纹识别(联想T440内置Synaptics Validity Sensors)

ubuntu 16.04系统上开启PHP7的OpCache

目前使用的阿里云服务器是通过阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS升级上来的,升级之后,一直没有开启PHP 7.0OpCache。以前感觉性能还够用,最近发现有些卡顿现象,因此想到开启OpCache

开启命令如下(PHP-FPM模式):

$ sudo apt install php7.0-opcache

$ sudo phpenmod opcache

# PHP-FPM模式的配置文件
$ FILEPATH="/etc/php/7.0/fpm/php.ini"


# Enable the opcache.
$ SEARCH=";opcache.enable=0"
$ REPLACE="opcache.enable=1"
$ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH


# Set the amount of memory we can use for caching.
# The production server has oooooodles of RAM.
$ SEARCH=";opcache.memory_consumption=64"
$ REPLACE="opcache.memory_consumption=256"
$ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH


# increase the number of files to cache
$ SEARCH=";opcache.max_accelerated_files=2000"
$ REPLACE="opcache.max_accelerated_files=1000000"
$ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH


# Don't bother revalidating files for a long time because
# they should never change.
# Obviously you need to undo this in dev.
$ SEARCH=";opcache.validate_timestamps=1"
$ REPLACE="opcache.validate_timestamps=3000"
$ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH

#重启服务
$ sudo service php7.0-fpm restart

网站响应速度有明显的飞跃。

参考链接