Windows - create text file - (newb)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ernesto

    #1

    Windows - create text file - (newb)

    Can Python be used to create (and/or open, read, and write) a text file
    in Windows (if the path is known) ?

  • Jorge Godoy

    #2
    Re: Windows - create text file - (newb)

    "Ernesto" <erniedude@gmai l.com> writes:
    [color=blue]
    > Can Python be used to create (and/or open, read, and write) a text file
    > in Windows (if the path is known) ?[/color]

    Yes.

    --
    Jorge Godoy <godoy@ieee.org >

    "Quidquid latine dictum sit, altum sonatur."
    - Qualquer coisa dita em latim soa profundo.
    - Anything said in Latin sounds smart.

    Comment

    • Larry Bates

      #3
      Re: Windows - create text file - (newb)

      Yes.

      To open file:

      fp=open(r'C:\di rectory\filenam e.txt','r')

      To open file to write to:

      fp=open(r'C:\di rectory\filenam e.txt','w')

      You probably need to go through the Python tutorial as
      these items are covered.

      -Larry Bates




      Ernesto wrote:[color=blue]
      > Can Python be used to create (and/or open, read, and write) a text file
      > in Windows (if the path is known) ?
      >[/color]

      Comment

      • epost2@gmail.com

        #4
        Re: Windows - create text file - (newb)

        Yes. You could do:

        Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
        [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
        Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
        >>> fileobj=open('~ \myfile.txt','w ')
        >>> fileobj.write(" test")
        >>> fileobj.close()[/color][/color][/color]

        On Windows, for the path to your file, you could write
        r'C:\myfile.txt ' (if C:\ is a place you can write to.)

        also, see the output from
        [color=blue][color=green][color=darkred]
        >>> help("open")[/color][/color][/color]

        Comment

        • Ernesto

          #5
          Re: Windows - create text file - (newb)

          got it . thanks tons. i'm doing the tutorial now.

          Comment

          Working...