python - 安装模块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 而不是执行代码的位置?
解决方案
1)获取正在执行的文件的真实路径。
导入操作系统
打印(os.path.realpath(__file__))
2) 获取正在执行的文件的目录。
导入操作系统
打印(os.path.dirname(os.path.realpath(__file__)))
推荐阅读
- php - 在插入 mysql 之前将一个撇号替换为另一个撇号
- python - for loop stats.linregress 中的条件语句
- android - 将 android studio proyect 连接到另一个 firebase 帐户
- c - 雷区C矩阵
- php - 如何仅显示包含特定值的所有文章?
- javascript - 如何设置动态document.title?
- r - 在密度向量上调用 sapply?
- c++ - 矩阵报告 Mismatched free() / delete / delete []
- sas - SAS Proc Freq 2 路表删除行和列总计
- c# - 将 PPK 文件硬编码到我的代码中是否安全?