create a text file

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

    #1

    create a text file

    I'm writing a script to list all of my music files' id3 tags
    to a comma delimited file. The only part I'm missing seems
    like it should be the simplest. I haven't used Python for
    the last couple of years. My question is this:

    When I use os.open(<file_v ariable>,"w"), I get an error
    message, TypeError: an integer is required. Has
    something changed? Did I miss something???

    Thanks,

    -------------------> S Cook
  • Fredrik Lundh

    #2
    Re: create a text file

    Stan Cook wrote:
    [color=blue]
    > I'm writing a script to list all of my music files' id3 tags
    > to a comma delimited file. The only part I'm missing seems
    > like it should be the simplest. I haven't used Python for
    > the last couple of years. My question is this:
    >
    > When I use os.open(<file_v ariable>,"w"), I get an error
    > message, TypeError: an integer is required. Has
    > something changed? Did I miss something???[/color]

    the function is called "open", not "os.open".

    there's an open function in the os module, but that's doing something
    slightly different (see the library reference documentation for details
    if you're curious).

    </F>

    Comment

    • Bruno Desthuilliers

      #3
      Re: create a text file

      Stan Cook a écrit :[color=blue]
      > I'm writing a script to list all of my music files' id3 tags to a comma
      > delimited file. The only part I'm missing seems like it should be the
      > simplest. I haven't used Python for the last couple of years. My
      > question is this:
      >
      > When I use os.open(<file_v ariable>,"w"), I get an error message,
      > TypeError: an integer is required. Has something changed? Did I miss
      > something???[/color]

      You want open() (the builtins one), not os.open().

      Also, if you want to deal with csv files, you may want to check the csv
      module (if you don't use it already).

      Comment

      • per9000

        #4
        Re: create a text file

        Hi,

        This is what I often do:

        somekindofoutpu t = ''
        somekindofoutpu t += somefunk(somear g) + '\n'

        # w is for writing
        myfile = open('theoutfil e',w)
        myfile.write(so mekindofoutput)
        myfile.close()

        also see
        The official home of the Python Programming Language

        or some other documentation

        /P9k

        Comment

        • Max Erickson

          #5
          Re: create a text file

          "per9000" <per9000@gmail. com> wrote:
          [color=blue]
          > # w is for writing
          > myfile = open('theoutfil e',w)[/color]

          That won't work, the second argument to open needs to be a string:

          myfile = open('theoutfil e', 'w')


          max

          Comment

          • Fredrik Lundh

            #6
            Re: create a text file

            Max Erickson wrote:
            [color=blue][color=green]
            >> # w is for writing
            >> myfile = open('theoutfil e',w)[/color]
            >
            > That won't work, the second argument to open needs to be a string:[/color]

            w = 'w'

            </F>

            Comment

            • Stan Cook

              #7
              Re: create a text file

              Fredrik Lundh wrote:[color=blue]
              > Stan Cook wrote:
              >[color=green]
              >> I'm writing a script to list all of my music files' id3 tags to a
              >> comma delimited file. The only part I'm missing seems like it should
              >> be the simplest. I haven't used Python for the last couple of years.
              >> My question is this:
              >>
              >> When I use os.open(<file_v ariable>,"w"), I get an error
              >> message, TypeError: an integer is required. Has something
              >> changed? Did I miss something???[/color]
              >
              > the function is called "open", not "os.open".
              >
              > there's an open function in the os module, but that's doing something
              > slightly different (see the library reference documentation for details
              > if you're curious).
              >
              > </F>
              >[/color]
              Thanks, I found it.

              Comment

              Working...