473,385 Members | 1,483 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,385 software developers and data experts.

How do I create lists in classes in Python?

I want to operate a local list in a class in Python. I can not do that:
Expand|Select|Wrap|Line Numbers
  1. class cCompetition:
  2.     lcPersonAll = []
  3.  
  4.     def AddPerson(self, cPersonNew):
  5.         lcPersonAll.append(cPersonNew)
  6.  
  7. cCompetition1 = cCompetition()
  8. cCompetition1.AddPerson("Smith")
However, global list is possible.
Jan 9 '17 #1
1 1370
dwblas
626 Expert 512MB
It has to be an instance object of the class (self). Since this is in most tutorials, start with one that you like https://wiki.python.org/moin/BeginnersGuide/Programmers For an example of using a list in a class, see "Objects and Stuff" at http://hetland.org/writing/instant-python.html You have a class, not an instance, object --> difference http://www.tutorialspoint.com/python...es_objects.htm (empCount vs self.name & self.salary)
Jan 9 '17 #2

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

Similar topics

2
by: Markus | last post by:
Hello, I've written a couple of Python scripts on OS X that I would like to start from the Finder by doing a double-click on them. I guess I have to create a Package. Does anybody know an...
7
by: qwweeeit | last post by:
Hi all, beeing almost a newbie, I am trying to learn from experts. For that reason I am collecting examples of Python sources (and Pythonic way of programming...) on a CD, ready to be searched....
0
by: Samuel | last post by:
Introduction ------------ Spiff Guard is a library for implementing access lists in Python. It provides a clean and simple API and was implemented with performance and security in mind. It was...
3
by: this is kiran | last post by:
how can i insert an element at first in linked lists
25
by: Licheng Fang | last post by:
I mean, all the class instances that equal to each other should be reduced into only one instance, which means for instances of this class there's no difference between a is b and a==b. Thank...
1
by: Fizzics | last post by:
This is my first post here at Bytes. I have been trolling it, mostly with the help of Google searches, for some time now. I have done about all of the searching and reading that I really know how to...
7
by: fekioh | last post by:
Hello, I need to store data in large lists (~e7 elements) and I often get a memory error in code that looks like: f = open('data.txt','r') for line in f: list1.append(line.split(','))...
1
by: Monish30 | last post by:
Hi Friends, I want to start a new project in MVC 3 just want to know which is the best way to create Model Classes. Linq , Entity Framework or any else. This project is very big so before...
7
by: PythonB15 | last post by:
Hi all, I am hoping you can help me. I have a data structure which consists of a game players name and their scores, I have use lists within lists (2D): results = , , ] What I want to do is...
3
by: shanavas | last post by:
Hi All, I have been searching for a sample/basis python script which would create/generate a xml file out of oracle database. I don't have previous experience with Python. could you please help me...
1
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: 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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.