【问题标题】:Read files in Ubuntu using python3 [closed]使用 python3 在 Ubuntu 中读取文件 [关闭]
【发布时间】:2022-11-15 21:53:37
【问题描述】:

我将一些数据提取到我的 Ubuntu 服务器中,现在它们存储在/home/ubuntu/test_file/data/test.json
我想用 Python 打开它们并写入 MySQL 数据库,但找不到正确的路径。下面是我的代码

input_file = open(r'~\test_file\data\test.json', encoding='utf-8')

有人可以帮我吗?

【问题讨论】:

  • 你为什么要在你的路径中使用反斜杠??另请注意,Python 不会像 shell 那样扩展 ~
  • @ThierryLathuille 因为我使用反斜杠在 vscode 中编写它并且它有效。好的,谢谢你的帮助

标签: python ubuntu amazon-ec2


【解决方案1】:

我没有足够的声誉来发表评论,但你的斜杠是不是走错了路?不应该是:

〜/whatever/path/you/have/test.json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-10
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 2020-09-15
    • 2013-04-16
    相关资源
    最近更新 更多