Python -跨平台文件路径

通常我使用mac来编写脚本,但现在我在Windows上遇到了一个问题。

有没有好的方法让路径为跨平台做好准备?

def load_json(store):
    storename = store
    
    with open('./stores/' + store +'.json' ,'r') as store:
        data = store.read()
    
    object = json.loads(data)

在Windows上,即时消息收到错误

[Errno 2] No such file or directory: './stores/alternate.json'

转载请注明出处:http://www.sywsjj.net/article/20230330/1785879.html