gpt4 book ai didi

python - 如何使用 Pythonista 在 iPad air 2 上存储、查找然后导入文本文件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:07 26 4
gpt4 key购买 nike

我试图使用 iPad 从 Internet 导入一个文本文件,以便在 Python MOOC 练习“hangman”中使用 edx:

For this problem, you will need the code files ps3_hangman.py and words.txt. Right-click on each and hit "Save Link As". Be sure to save them in same directory. Open and run the file ps3_hangman.py without making any modifications to it, in order to ensure that everything is set up correctly.

事实是,在 iPad 上这些选项似乎并不容易。我设法将 hangman.py 文件复制并粘贴到一个新的 Pythonista 文件中,但是......

  • 如何处理大文本文件?
  • 我在哪里将它存储为文本文件,找到它,然后将它导入到这个 iPad 程序中?

在 Windows 上没问题。 Apple 不允许 file.open() 类型的操作。

最佳答案

如果您无法访问 Mac/PC,您可以这样做的一种方法,即完全在 Pythonista 中的 iPad 上:

  • 在 Safari 中复制文本文件的 URL(点击并按住链接)

  • 在 Pythonista 中,切换到交互式提示(从右向左滑动)

  • 输入以下两行:

import urllib
urllib.urlretrieve('<paste copied url here>', 'words.txt')

您也可以将这两行写在常规脚本中,而不是使用交互式提示。但您可能只需要一次。

关于python - 如何使用 Pythonista 在 iPad air 2 上存储、查找然后导入文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28403267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com