首页 > 解决方案 > 安装模块python的真实位置

问题描述

我安装了social.py

社会.py代码:

import os
social_dir = os.getdir()
arr = os.listdir()

我在这个目录中执行 python:/home/facts/Documents/FactsDigital/

import sys
from social import social_dir, arr
print(social_dir)
print(arr)
>>> /home/facts/Documents/FactsDigital/
>>> "files python running cmd location"

如何获取真实目录的 arr 而不是执行代码的位置?

标签: python

解决方案


1)获取正在执行的文件的真实路径。

导入操作系统

打印(os.path.realpath(__file__))

2) 获取正在执行的文件的目录。

导入操作系统

打印(os.path.dirname(os.path.realpath(__file__)))


推荐阅读