/* 访问计数 */ function record_visitors() { if (is_singular()) { global $post; $post_ID = $post->ID; if($post_ID) { $post_views = (int)get_post_meta($post_ID, 'views', true); if(!update_post_meta($post_ID, 'views', ($post_views+1))) { add_post_meta($post_ID, 'views', 1, true); } } } } add_action('wp_head', 'record_visitors'); Python读取文件时出现UnicodeDecodeError – 芯片版图

Python读取文件时出现UnicodeDecodeError

运行下面code时

with open('style.css','r',encoding='utf-8') as f:
	for line in f:
		print(line)

出现错误

UnicodeDecodeError: 'gbk' codec can't decode byte 0x9d in position 1947: illegal multibyte sequence

将open代码改为

with open('style.css','r',encoding='utf-8') as f:
	for line in f:
		print(line)

发表评论