about library os

os 的使用

import os
current_path = os.getcwd() # get the current path
father_path = os.path.dirname(current_path)# the parent path
os.path.dirname(father_path)  # get the grandfather path
os.path.join(current_path, "filename.txt") # the filename.txt path

# judge file exist
if os.path.exists("your file.txt")
	os.remove("your file.txt")
	# or
	os.mkdir("your file.txt")

others:

__import__(module_name)
#__import__() 函数用于动态加载类和函数 。
#如果一个模块经常变化就可以使用 __import__() 来动态载入。

print/format格式化输出

print("height is :{:1.2f}".format(1.70))
print("height: %1.2f"%(1.70))
print("网站名:{name}, 地址 {url}".format(name="菜鸟教程", url="www.runoob.com"))
 
# 通过字典设置参数
site = {"name": "菜鸟教程", "url": "www.runoob.com"}
print("网站名:{name}, 地址 {url}".format(**site))
 
# 通过列表索引设置参数
my_list = ['菜鸟教程', 'www.runoob.com']
print("网站名:{0[0]}, 地址 {0[1]}".format(my_list))  # "0" 是必须的
数值格式输出描述
13{:>10d}. 13右对齐 (默认, 宽度为10)
12{:<10d}13左对齐宽度为10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值