# -*- coding: utf-8 -*-
# encoding = utf-8
import unittest
import random class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
# 初始化一个递增序列
self.seq = range(10) def runTest(self):
# 从序列seq中随机选择一个元素
element = random.choice(self.seq)
# 验证随机元素是否确实属于列表中
self.assertIn(element, self.seq) class TestDictValueFormatFunctions(unittest.TestCase):
def setUp(self):
# 初始化一个递增序列,self.seq是个迭代器
self.seq = range(10)
self.lis = list(self.seq) def test_shuffle(self):
# 随机打乱原seq的顺序
random.shuffle(self.lis)
# 对打乱的seq进行升序排列
# sort(self.seq)
self.lis.sort()
# 验证重新排列后的seq时候和原seq序列一致
self.assertEqual(self.lis, list(range(10))) if __name__ == '__main__':
unittest.main() pycharm运行上述代码时,提示编码问题,因为代码中并没有中文,所以查看pycharm 的file encodings设置
file-》setting-》file encodings;把 Global Encoding、Project Encoding和下面的Default encoding for properties files 均设置成UTF-8,
最好file-》setting for new project也进行如上设置
最后,我运行的时候还是提示这个问题,再次新建了一个.py文件代码copy进去 再次运行,问题消失。
相关文章
- UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 2: illegal multibyte sequence
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 9: illegal multibyte sequence
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 199: illegal multibyte sequence
- Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence
- python 读取文件时报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence
- python3安装xadmin出现 UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 3444: illegal multibyte sequence
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 120: illegal multibyte sequence
- python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence
- python打开文件失败,报错'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
- 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence