parsing csv files class

alex goretoy aleksandr.goretoy at gmail.com
Sun Dec 28 01:25:05 CET 2008


How would I change this to work with numpy: (Would it be more feasible for
storing big files? 300-30,000 records)
 for row in reader:
                    self.buffer.append(row)
                    s,a=[],{}

                    for j in range(len(self.buffer[0])):
                        a[self.buffer[0][j]]=row[j]
                    self.bufferp.append(a)
                    i+=1
                self.total = i-1

Instead of doing self.buffer.append(row)

would I initialize numpy like this: self.buffer=numpy.array() and then in
the loop do:
self.buffer.append(row) ? How do I achieve the same for lower code, where it
appends to a dict with header of each column? Thank you.

On Sat, Dec 27, 2008 at 5:31 PM, alex goretoy
<aleksandr.goretoy at gmail.com>wrote:

> I might as well add a UnicodeReader and UnicodeWriter and support for
> passing delimiter in from other classes.  At the same time. Anyone have a
> good csv class I can pick thru? I'm planning on posting my mysql adn curl
> classes that I use in my projects I just want to make them better and have
> less error.
>
>
> On Sat, Dec 27, 2008 at 5:18 PM, alex goretoy <aleksandr.goretoy at gmail.com
> > wrote:
>
>> It's main concern is to grab the file into the buffer for use in other
>> classes. The self.soc.me_him is just so I know when its ENTERING or EXITING
>> in that function when I run it in terminal. It's prints it in color. My main
>> concern right now is to add error handling. I'm still learning how to use
>> assert and yield, but I got try,except down pat.  All this class does is
>> grabs the file either from http or local storage into a buffer and I use
>> that in other classes. I want to add support for creating creating csv as
>> well. I read the doc on csv and  will try some things out soon. Thanks for
>> helping me.
>>
>>
>> On Sat, Dec 27, 2008 at 2:15 PM, Gabriel Genellina <
>> gagsl-py2 at yahoo.com.ar> wrote:
>>
>>> En Sat, 27 Dec 2008 11:02:13 -0200, Gary M. Josack <gary at byoteki.com>
>>> escribió:
>>>
>>>> alex goretoy wrote:
>>>>
>>>
>>>  I know it's messy with all those self.soc.* functions, but it works in
>>>>> one of my current project. I just want to make it more pythonic I also want
>>>>> to add capability for makeing csv file if I give it input like:
>>>>> 1234,something nice, hey this is something nice
>>>>> 2468,something else, something else
>>>>>
>>>>
>>>                 reader = csv.reader(file(filename, "rb"))
>>>>>                try:
>>>>>                    for row in reader:
>>>>>                        self.buffer.append(row)
>>>>>                        s,a=[],{}
>>>>>
>>>>
>>>  Do you know that there is a csv module in the standard library already?
>>>>
>>>
>>> I'd say he already knows, he even used it in the code.
>>>
>>> To Alex G.: I didn't understand what's the purpose of this class.
>>> Probably you want to do too much things in the same place; looks like it has
>>> multiple concerns, and that's not a good idea usually.
>>>
>>> --
>>> Gabriel Genellina
>>>
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>>
>> --
>> А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
>> а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
>>
>>
>>
>> --
>> А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
>> а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
>>
>
>
>
> --
> А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
> а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
>



-- 
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081227/e9ad70f2/attachment.html>


More information about the Python-list mailing list