omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. Steven183

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 2
    • Best 0
    • Controversial 0
    • Groups 0

    Steven183

    @Steven183

    0
    Reputation
    501
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Steven183 Unfollow Follow

    Latest posts made by Steven183

    • RE: Read / Write to text file within the Pythonista library

      By the way, is pasted code recognized automatically on the forum? I can't figure out how to preserve indents :(

      Edit: Thanks pudquick!

      <PRE>with open('hello.txt', 'w+') as f:
      f.write('Hello world')
      f.seek(0)
      y = f.read()
      print y</PRE>

      With this format, the file will automatically close after the indent block. If you want to avoid this, use the following format:

      <PRE>x = open('hello.txt', 'w+')
      x.write('Hello world')
      x.seek(0)
      z = x.read()
      print z
      x.close()</PRE>

      I used w+ because I wanted to read and write from the same file without closing and reopening it. In general, use 'a' to append (as opposed to writing over), 'r' to read, and 'w' to write.

      posted in Pythonista
      Steven183
      Steven183
    • RE: Read / Write to text file within the Pythonista library

      You seem to be able to use the standard Python read/write:

      http://pastebin.com/f43A7j5M

      It seems that this file can then be accessed by any script within your library.

      posted in Pythonista
      Steven183
      Steven183