Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39348

Re: working with csv module in python

Date 2013-02-20 06:22 -0500
From Dave Angel <davea@davea.name>
Subject Re: working with csv module in python
References <CAFqGZRG3wVyf6jMBESjr6bmnLhLsT-_BG0xSH_rcpe4Oqb+1nQ@mail.gmail.com> <20130220102601.GD22457@localhost> <CAFqGZRG3RwgdSjDs1xRpv0YdEV0yXxeFJCefhP+w_6DEdwrwPQ@mail.gmail.com> <CAFqGZRGAw95bXdZt5_9KTyD5VSEYRwM=JqKWUVmP+qSnW-PqpQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2107.1361359386.2939.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: working with csv module in python Dave Angel <davea@davea.name> - 2013-02-20 06:22 -0500

csiph-web