python—存储数据,和测试

json.dump(),json.load

json.dump()存储数据,
“”"
filename = “F:\pycharm\project\ReadWrite\numbers.json”
numbers = [1, 2, 3, 4, 6, 7]
with open(filename, ‘w’) as f_obj:
json.dump(numbers, f_obj)

#json.load读取数据
with open(filename) as f_load:
new_number = json.load(f_load)
print(new_number)

断言方法

方法用途
assertEqual(a,b)核实a==b
self.assertNotEqual(a,b)核实a!=b
assertTrue(x)核实 x为True
self.assertFalse(x)核实 x为False
self.assertIn(item,list)核实item在list中
assertNotIn(item,list)核实item不在list中

city.py

def get_city(countries, citys):
	my_city = countries + ' ' + citys
	return my_city.title()
my_countries_citys = get_city("china",'xuzhou')
print(my_countries_citys)

text_city

import unittest
from city import get_city
class TextCity(unittest.TestCase):
	def text_cty_country(self):
		formtted_city = get_city('china', 'xuzhou')
		self.assertEqual(formtted_city, 'Chian Xuzhou')
unittest.main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值