Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > sum function

Reply
Thread Tools

sum function

 
 
Mike
Guest
Posts: n/a
 
      10-05-2012
On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote:
> On 10/04/2012 05:29 PM, Mike wrote:
>
> > I get below error

>
> >

>
> > NameError: name 'functools' is not defined

>
> >

>
>
>
> functools is a module in the standard library. You need to import it.
>
>
>
> import functools
>
>
>
>
>
>
>
> --
>
>
>
> DaveA


I imported functools. Now I get the below error please.


Traceback (most recent call last):
File "test.py", line 16, in <module>
total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues())
File "test.py", line 16, in <genexpr>
total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues())
AttributeError: 'list' object has no attribute 'itervalues'

Thanks
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      10-05-2012

I agree with you, Ian. Thanks for all the help. Now I get the below error.

File "test.py", line 17, in <module>
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
File "test.py", line 17, in <genexpr>
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())

Thanks
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      10-05-2012

I agree with you, Ian. Thanks for all the help. Now I get the below error.

File "test.py", line 17, in <module>
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
File "test.py", line 17, in <genexpr>
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())

Thanks
 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      10-05-2012
On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike wrote:
> I agree with you, Ian. Thanks for all the help. Now I get the below error.
>
>
>
> File "test.py", line 17, in <module>
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
>
> File "test.py", line 17, in <genexpr>
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
>
>
>
> Thanks


You have missed the last line of the traceback (error)
 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      10-05-2012
On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike wrote:
> I agree with you, Ian. Thanks for all the help. Now I get the below error.
>
>
>
> File "test.py", line 17, in <module>
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
>
> File "test.py", line 17, in <genexpr>
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
>
>
>
> Thanks


You have missed the last line of the traceback (error)
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      10-05-2012
On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
> Hi All,
>
>
>
> I am new to python and am getting the data from hbase.
>
> I am trying to do sum on the column as below
>
>
>
>
>
> scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
>
> total = 0.0
>
> r = client.scannerGet(scanner)
>
> while r:
>
> for k in (r[0].columns):
>
> total += float(r[0].columns[k].value)
>
> r = client.scannerGet(scanner)
>
>
>
> print total
>
>
>
> Do you know of better (faster) way to do sum?
>
>
>
> Any thoughts please?
>
>
>
> Thanks


Sorry about that. Here you go

Traceback (most recent call last):
File "test.py", line 17, in <module>
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
File "test.py", line 17, in <genexpr>
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
IndexError: list index out of range
 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      10-05-2012
On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote:
> On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
>
> > Hi All,

>
> >

>
> >

>
> >

>
> > I am new to python and am getting the data from hbase.

>
> >

>
> > I am trying to do sum on the column as below

>
> >

>
> >

>
> >

>
> >

>
> >

>
> > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])

>
> >

>
> > total = 0.0

>
> >

>
> > r = client.scannerGet(scanner)

>
> >

>
> > while r:

>
> >

>
> > for k in (r[0].columns):

>
> >

>
> > total += float(r[0].columns[k].value)

>
> >

>
> > r = client.scannerGet(scanner)

>
> >

>
> >

>
> >

>
> > print total

>
> >

>
> >

>
> >

>
> > Do you know of better (faster) way to do sum?

>
> >

>
> >

>
> >

>
> > Any thoughts please?

>
> >

>
> >

>
> >

>
> > Thanks

>
>
>
> Sorry about that. Here you go
>
>
>
> Traceback (most recent call last):
>
> File "test.py", line 17, in <module>
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
>
> File "test.py", line 17, in <genexpr>
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
>
> IndexError: list index out of range


the variable "r" is an empty list
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      10-05-2012
On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote:
> On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote:
>
> > On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:

>
> >

>
> > > Hi All,

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > I am new to python and am getting the data from hbase.

>
> >

>
> > >

>
> >

>
> > > I am trying to do sum on the column as below

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])

>
> >

>
> > >

>
> >

>
> > > total = 0.0

>
> >

>
> > >

>
> >

>
> > > r = client.scannerGet(scanner)

>
> >

>
> > >

>
> >

>
> > > while r:

>
> >

>
> > >

>
> >

>
> > > for k in (r[0].columns):

>
> >

>
> > >

>
> >

>
> > > total += float(r[0].columns[k].value)

>
> >

>
> > >

>
> >

>
> > > r = client.scannerGet(scanner)

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > print total

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > Do you know of better (faster) way to do sum?

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > Any thoughts please?

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > >

>
> >

>
> > > Thanks

>
> >

>
> >

>
> >

>
> > Sorry about that. Here you go

>
> >

>
> >

>
> >

>
> > Traceback (most recent call last):

>
> >

>
> > File "test.py", line 17, in <module>

>
> >

>
> > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())

>
> >

>
> > File "test.py", line 17, in <genexpr>

>
> >

>
> > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())

>
> >

>
> > IndexError: list index out of range

>
>
>
> the variable "r" is an empty list


Here is the actual code.

scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
next_r = functools.partial(client.scannerGet, scanner)
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())


Scanner does have rows.

Are we missing something please?

Thanks
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      10-05-2012
On 10/5/2012 9:47 AM, Mike wrote:
> On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote:
>> On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote:
>>
>>> On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:

>>
>>>

>>
>>>> Hi All,

>>
>>>

>>
>>>>

>>
>>>

>>
>>>>

>>
>>>

>>
>>>>

>>
>>>

>>
>>>> I am new to python and am getting the data from hbase.


If you want as many people as possible to read your posts, stop using a
mail-agent and site that spits in the face of readers by doubling blank
lines each iteration. Alternatives have been discussed previously.

--
Terry Jan Reedy

 
Reply With Quote
 
Ian Kelly
Guest
Posts: n/a
 
      10-05-2012
On Fri, Oct 5, 2012 at 7:39 AM, Mike <> wrote:
> Sorry about that. Here you go
>
> Traceback (most recent call last):
> File "test.py", line 17, in <module>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
> File "test.py", line 17, in <genexpr>
> total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
> IndexError: list index out of range


Maybe the sentinel value is not None as I assumed, and it's
overrunning the end of the data? What does
client.scannerGet return when there is no more data?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What official function should I call to genertate a sum of products in VHDL Weng Tianxiang VHDL 2 03-19-2007 07:25 PM
Packet retransmits and bad check sum on ethereal capture Newbie72 Cisco 4 03-10-2006 01:52 PM
XML - problem with sum function cieron XML 2 05-16-2005 09:21 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
DataGrid: how to have a footer row dynamically sum data Roger Moore ASP .Net 0 07-07-2003 05:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57