0
点赞
收藏
分享

微信扫一扫

必须放在特定的文件夹中才能运行的Python程序


下面的小代码要演示的问题是,可以规定某个Python程序必须放在特定的文件夹(代码中假设必须放到Python安装目录中)中才能运行,移动到其他文件夹之后会拒绝运行。

import os
import sys

#获取当前文件夹或程序所在文件夹
cur = os.getcwd()
#Python安装文件夹
right = sys.prefix

if right != cur:
    print("You must place this program in Python installation directory first, and then run it.")
    exit()
print("OK. Now you can do your intended things.Congratulations.")

举报

相关推荐

0 条评论