【发布时间】:2021-09-08 04:35:19
【问题描述】:
所以我想在没有完整路径的情况下从文件中读取内容,我该怎么做? 我当前的代码
import json
file1= 'C:\\Users\\klaus\\OneDrive\\Desktop\\Script\\Mediamarktp.json'
with open(file1, 'r') as handle:
json_out = json.load(handle)
profile_name = ['Profile1']
data = [x for x in json_out if x['profilename'] in profile_name]
email = (data[0]['email'])
password = (data[0]['password'])
website = (data[0]['website'])
precart = (data[0]['precart']=='True')
profilename1 = (data[0]['profilename1'])
proxy = (data[0]['proxy']=='True')
print(email)
print(password)
print(precart)
file1 目前 = 'C:\Users\klaus\OneDrive\Desktop\Script\Mediamarktp.json' 但我希望我的脚本只需查找 = '\Script\Mediamarktp.json' 即可打开它 喜欢
file1 = 'C:\\*\\Script\\Mediamarktp.json'
我该怎么做?
【问题讨论】:
-
期望您的程序扫描整个文件系统以寻找与您的路径后缀匹配的一个路径是不合理的。