How to deal with python 32bit memory error

2012-07-24 Thread Sammy Danso
Hello Experts,
I am having a 'memory error', which suggest that I 
have run out of memory, but I am not sure this is the case as I have 
considerable amount of memory unused on my computer. 

A little 
search suggest this is a limitation of python 32 and an option is to 
have a 64bit. I however have other plug-ins, which are tied to the 32bit
 so this is not the best option in my case. 

I was wondering whether there is an elegant way to dealing with this without 
installing a 6bit version of python.

Thanks very much in advance.
Sammy-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with how to combine two csv files

2012-05-10 Thread Sammy Danso





Hi JM and All,
Thank you all very much for your response and help. I managed to work out the 
problem eventually. But my code is ridiculously long compared to what you have 
just offered here. I think your code is elegant and should be much faster.  
Thanks  a lot
Sammy 
 
Below is my code. 
 
 outputfile = codecs.open(csvfile3, 'wb')
 inputfile1 =  codecs.open(csvfile1, 'rb')
 inputfile2 = codecs.open(csvfile2, 'rb')
 
    
 dictreader2 = csv.DictReader(inputfile2)
 dictreader1 = csv.DictReader(inputfile1)
 mergedDict = {}
 
 mergedDictb = {}
 matchedlistA = []
 matchedlistB = []
 matchedlist = []
 cnt = 0
 cntb = 0
 for dictline1 in dictreader1:
 cnt  += 1
 print cnt
 mergedDict = dictline1.copy()
 mergedDict['UniqID']=  cnt
  matchedlistA.append(mergedDict)
 
    
 for dictline2 in dictreader2:
  cntb  += 1
  mergedDictb = dictline2.copy()
  mergedDictb['UniqID']=  cntb
  matchedlistB.append(mergedDictb)
 
   
 for dictline1 in matchedlistA: 
    for dictline2 in matchedlistB: 
    if dictline1['UniqID'] == dictline2['UniqID']: 
    entry = dictline1.copy() 
    entry.update(dictline2)
    matchedlist.append(entry) 
 
 

--- On Wed, 5/9/12, Jean-Michel Pichavant  wrote:


From: Jean-Michel Pichavant 
Subject: Re: Help with how to combine two csv files
To: "Sammy Danso" 
Cc: python-list@python.org
Date: Wednesday, May 9, 2012, 11:23 AM


Sammy Danso wrote:
> Hello Experts,
> I am new to python and I have been trying to merge two csv files, and upon 
> several hours of unsuccessful attempts, I have decided to seek for help.
>  the format of the file is as follows. file A has  columns a, b, c and values 
>1,2,3 for several rows. File B also has columns d,e and values 4,5  for same 
>number of rows as A. the files however do not have any unique column between 
>the two.
> I want an output file C to have columns  a,b,c,d,e with values 1,2,3,4,5
>  I would be very grateful for your help with some code.
>  Thanks very much,
> Sammy
> 
Post some code so we may point at your problem.

The solution is easy, the code very small.
Something like (pseudo code):

import csv
writer = csv.writer(file3)
for index, row in enumerate(csv.reader(file1)):
   writer.writerow(row + csv.reader(file2)[index])

JM
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with how to combine two csv files

2012-04-29 Thread Sammy Danso





Hello Experts,
I am new to python and I have been trying to merge two csv files, and upon 
several hours of unsuccessful attempts, I have decided to seek for help.
 
the format of the file is as follows. file A has  columns a, b, c and values 
1,2,3 for several rows. File B also has columns d,e and values 4,5  for same 
number of rows as A. the files however do not have any unique column between 
the two. 
I want an output file C to have columns  a,b,c,d,e with values 1,2,3,4,5
 
I would be very grateful for your help with some code.
 
Thanks very much,
Sammy-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterating over list with one mising value

2012-02-07 Thread Sammy Danso










Hi Expert,
Thanks for your responses and help. thought I should provide more information 
for clarity.
 
Please find the error message below for more information 
 
   for (key, value) in wordFreq2:
ValueError: need more than 1 value to unpack
 
this is a sample of my data
 
['with', 3, 'which', 1, 'were', 2, 'well', 1, 'water', 1, 'was', 4, 'two', 1, 
'to', 2, 'through', 1, 'thlabour', 1, 'these', 1, 'theat', 1, 'the', 8, 
'tetanus', 1, 'started', 1, 'size', 1, 'scent', 1, 'respectively', 1, 
'received', 1, 'problems', 2, 'prince', 1, 'pregnancy', 1, 'poured', 1, 
'peace', 1, 'pains', 1, 'painless', 1, 'out', 1, 'of', 1, 'noseat', 1, 'nose', 
2, 'no', 2, 'maternity', 1, 'malformation', 1, 'made', 1, 'lower', 1, 
'labour/delivery', 2, 'kintampo', 1, 'into', 1, 'injections', 1, 'in', 3, 'i', 
2, 'hospital', 1, 'home', 1, 'him', 1, 'having', 1, 'had', 2, 'green', 1, 
'gave', 1, 'flowing', 2, 'encountered', 1, 'eleven', 1, 'during', 3, 
'district', 1, 'difficulty', 1, 'cord', 1, 'consecutive', 1, 'colour', 1, 
'cleared', 1, 'child', 1, 'checkups', 1, 'came', 1, 'but', 2, 'breathing', 2, 
'breath', 1, 'blood', 2, 'bleeding', 1, 'birth', 4, 'before', 1, 'bad', 1, 
'average', 1, 'at', 2, 'assist', 1, 'artificial', 1, 'around', 2, 'antenatal',
 1, 'and', 5, 'an', 1, 'ambrical', 1, 'air', 1, 'abdominal', 1, '600am', 1, 
'100pm', 1, '', 3, 'other']
 
What I would like to do is to pad the last value 'other' with a default so I 
can iterate sucessfully
 
my desired ouput is the format below in a text file.
with 3
which 3
were 2
..
.
. 
other
  

Thanks again.
Sammy

--- On Tue, 2/7/12, Dave Angel  wrote:


From: Dave Angel 
Subject: Re: iterating over list with one mising value
To: "Sammy Danso" 
Cc: python-list@python.org
Date: Tuesday, February 7, 2012, 2:46 PM


On 02/07/2012 07:27 AM, Sammy Danso wrote:
> Hello experts,
> I am having trouble accessing the content of my list.
> my list content has 2-pair value with the exception of one which has single 
> value. here is an example  ['a', 1, 'b', 1, 'c', 3, 'd']
>   I am unable to iterate through list to access invidual value pairs
>   I get an error message saying ' the list should more than 1 value pairs'. I 
>guess because 'd' has no value. How do I solve this problem?
>   Your help would be much appreciated.
>   Thanks
> Sammy
The real answer is to figure out how it gets into that state.  Is the input 
file invalid?  Or you have a device that sometimes skips one?

But if you're stuck with the data in that list:

If the list is of odd size, truncate it.  Then your loop should not run into an 
uneven pair.

Of course if you actually posted the code, or even the real and complete error 
message, we might be able to make other suggestions.



-- 
DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


iterating over list with one mising value

2012-02-07 Thread Sammy Danso
Hello experts,
I am having trouble accessing the content of my list. 
my list content has 2-pair value with the exception of one which has single 
value. here is an example  ['a', 1, 'b', 1, 'c', 3, 'd']
 
I am unable to iterate through list to access invidual value pairs
 
I get an error message saying ' the list should more than 1 value pairs'. I 
guess because 'd' has no value. How do I solve this problem?
 
Your help would be much appreciated.
 
Thanks
Sammy
___
http://www.comp.leeds.ac.uk/scsod/-- 
http://mail.python.org/mailman/listinfo/python-list