python 不执行函数_不执行python的函数

问题1是您定义了一个函数(“def”是“define”的缩写),但您没有调用它。def new_directory(): # define the function

if not os.path.exists(current_sandbox):

os.mkdir(current_sandbox)

new_directory() # call the function

问题2(还没有击中你)是你在使用一个全局(current_sandbox)时应该使用一个参数——在后一种情况下,你的函数通常是有用的,甚至可以从另一个模块调用。问题3是不规则缩进——使用缩进1将导致任何必须阅读您的代码(包括您自己)的人发疯。坚持4,使用空格,而不是制表符。def new_directory(dir_path):

if not os.path.exists(dir_path):

os.mkdir(dir_path)

new_directory(current_sandbox)

# much later

new_directory(some_other_path)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值