473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I find the total in an object?

I am building a music store example in python. I am trying to find a way of displaying the total of all of the sales of all of the music.

Everything is stored in objects in a list trackList. Track is the object so track.sales returns the sales of particular track.

This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. def totalSales(trackList):
  2.     for track in trackList:
  3.         total = sum(track.sales)
  4.     print total
I'm really struggling so any help would be great.
Jul 1 '10 #1
2 1552
Glenton
391 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. def totalSales(trackList):
  2.     total=0
  3.     for track in trackList:
  4.         total += track.sales
  5.     print total
  6.  
Jul 2 '10 #2
Thanks, works perfectly.
Jul 2 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Poplar Reader | last post by:
Following a crash while using one of out Microsoft Access databases, the following message appears everytime we try to open it. "The Microsoft Jet Database engine could not find the object...
8
by: chippy | last post by:
Hi, I've a VB script that creates a Access object in a word doc. Here is the full script. It works for all but the Export. Which always fails with a 3011 error. If I do the same in Access as a...
1
by: meryline | last post by:
hi, iam new to c#, can any one tell me how to find the total number characters entered in a textbox. like in vb.net i find it using len(textbox.text) . iam trying to implement the same in c# sharp...
4
by: drago | last post by:
Hi guys, I will be quick this time... Just want to know how we can calculate generic values in the same column. I am using invoice form with a services subform . I have a column of 'total' in subform...
0
by: Orgil | last post by:
Hi all, I have just writing a program named "DayBook". I am using MS Access 2003 database and Microsoft .NET C# 2005 (with framework 2.0). MS Access 2003, MS .NET C# 2005 and dotNetFramework2.0...
10
by: Sami Ward | last post by:
I have an an MSAccess data project front end linked to an SQL Server Database. I keep getting Error number 7874: database cannot find the object tblname when I look however the table is there. I...
1
by: gravikrishna | last post by:
hello sir pls tell me the code of my question how do u find total text of a html page in .net
2
by: DeelynBaNi | last post by:
HI all..i have this excel file created during export data from sql server. When i try to import this error occured "external data is not in the correct format' something like that. After i did some...
9
by: john20 | last post by:
Hi All, How can i find the total 'Count' of a particular character's occurance in a string. means i want to find the count of '<' in a string. can you please help to find that. Thanks
2
by: karimufeed | last post by:
I am working on an access project for pension calculation. I want to find total length of service between two dates. i.e. if the Date of entry into service is 15/3/1980 and the date of retirement...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.