Re: working with csv module in python

Discussion in 'Python' started by Dave Angel, Feb 20, 2013.

  1. Dave Angel

    Dave Angel Guest

    On 02/20/2013 06:01 AM, inshu chauhan wrote:
    >
    > <snip>
    >>
    >> For simple concating the files , I tried the following code :

    >
    > import glob
    >
    > with open(r"C:\Users\inshu.chauhan\Desktop\test2.arff", "w") as w:
    > print w
    > for f in glob.glob(r"C:\Users\inshu.chauhan\Desktop\For
    > Model_600\*.arff"):


    You forgot to open file f. f is a string, naming a single file.

    > g = f.read()
    > w.write(g)
    >
    >
    > But I think I am having an obvious error :
    >
    > <open file 'C:\Users\inshu.chauhan\Desktop\test2.arff', mode 'w' at
    > 0x01B64F40>
    >
    > Traceback (most recent call last):
    > File "C:\Users\inshu.chauhan\Desktop\Concatfiles.py", line 6, in <module>
    > g = f.read()
    > AttributeError: 'str' object has no attribute 'read'
    >
    > Here I am trying to refer the files stored in my folder by 'f', Why read()
    > is not working ?
    >
    >
    >



    --
    DaveA
    Dave Angel, Feb 20, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Ortmann
    Replies:
    4
    Views:
    554
    Skip Montanaro
    Jul 2, 2003
  2. jliu66
    Replies:
    0
    Views:
    483
    jliu66
    Oct 19, 2007
  3. Roland Koebler

    Re: working with csv module in python

    Roland Koebler, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    116
    Roland Koebler
    Feb 20, 2013
  4. Peter Otten

    Re: working with csv module in python

    Peter Otten, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    154
    Peter Otten
    Feb 20, 2013
  5. Dave Angel

    Re: working with csv module in python

    Dave Angel, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    129
    Dave Angel
    Feb 20, 2013
Loading...

Share This Page