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

标签 python ios ipad pythonista

我试图使用 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/

相关文章:

iphone - Ipad 应用程序到 Iphone 应用程序

python - 这个数学运算程序是否已经存在?

python - Django一对一模型中的更新/编辑功能

python - Keras:导入错误:没有名为 data_utils 的模块

iOS Corebluetooth 服务从未被发现,但在委托(delegate)方法的广告数据中可见

ipad - 在iPad Pro Simulator [Unity 5.2.2p1]上运行时崩溃

iphone - UINavigationBar 标题在使用自定义字体时被截断

Python打印出 float 或整数

ios - EXC_BAD_ACCESS 属性崩溃的 getter 方法

ios - 在应用程序中解密 Apple Pay 支付 token