3

Using an iPad, I'm attempting to import a text file from the Internet in order to utilize in Python MOOC exercise "hangman" from 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.

Thing is, these seem not easy options on an iPad. I managed to copy and paste the hangman.py file into a new Pythonista file, but....

  • how to handle the large text file?
  • Where do I store it as a text file, find it, then import it into this iPad program?

No problem on Windows. Apple does not allow a file.open() type operation.

Luke Taylor
  • 8,631
  • 8
  • 54
  • 92
user3308780
  • 45
  • 1
  • 3
  • I apologize for the improper format. Love the site, but don't ever post. – user3308780 Feb 09 '15 at 18:11
  • 1
    I neglected to thank you @Sathya for editing my original post. Comparing your edited version to my original is embarrassing. Yours is cleaner, more to the point. Will do better next time. Thanks again. – user3308780 Feb 09 '15 at 23:51

1 Answers1

3

One way you could do this if you don't have access to a Mac/PC, i.e. entirely on your iPad in Pythonista:

  • Copy the URL of the text file in Safari (tap and hold the link)

  • In Pythonista, switch to the interactive prompt (swipe from right to left)

  • Enter the following two lines:

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

You could also write these two lines in a regular script instead of using the interactive prompt. But you'll probably just need this once.

omz
  • 53,243
  • 5
  • 129
  • 141