dir(re.compile(pattern))
does not return pattern as one of the lists's elements. Namely it returns:
['__copy__', '__deepcopy__', 'findall', 'finditer', 'match', 'scanner', 'search', 'split', 'sub', 'subn']
According to the manual, it is supposed to ... |
The following code
import types
class A:
class D:
pass
class C:
pass
for ...
|
I am trying to sort a list of objects in python, however this code will not work:
import datetime
class Day:
def __init__(self, date, text):
...
|
(Edit: randrange is just random.randrange, I didn't write my own RNG)
I'm trying to create a list of instances of a class I defined. Here's the entire class (by request):
from ...
|
I am working through trying to learn to program in Python and am focused on getting a better handle on how to use Standard and other modules. The dir function ... |
I'm working on my first object oriented bit of python and I have the following:
#!/usr/bin/python
import random
class triangle:
# Angle A To Angle C Connects Side F
# Angle C to Angle ...
|
I have to sort a python list, with multiple attributes. I can do that in ascending order for ALL attributes easily with
L.sort(key=operator.attrgetter(attribute))....
but the problem is, that I have use mixed configurations ... |
|
Given a class such as
class MyClass:
text = "hello"
number = 123
Is there a way in python to inspect MyClass an determine that it has ... |
Is there a way to grab a list of attributes that exist on instances of a class? (This class is just an bland example, it is not my task at ... |
I have a list of fixtures.Each fixture has a home club and a away club attribute.I want to slice the list in association of its home club and away club.The sliced ... |
I have nodes with a list of attributes for each called 'times' in my case.
I made a simple model like this and I get KeyError'times'. I need my graph save each ... |
I am looking for an appropriate data structure in Python for processing variably structured forms. By variably structured forms I mean that the number of form fields and the types of ... |
Every example of list or set usage in Python seems to include trivial cases of integers but I have two lists of objects where the name attribute defines whether two objects ... |
Consider the following python class:
class Event(Document):
name = StringField()
time = DateField()
location = GeoPointField()
def __unicode__(self):
return self.name
Now I create a list of ... |
I have a list of lists (which could have been tuples, but I digress) in a format such as:
[12, 'tall', 'blue', 1]
[15, 'tall', 'black', 3]
[13, 'tall', 'blue', 8]
[9, 'short', 'blue', 3]
[1, ...
|
I have a list with a single string that contains non-ascii characters. My goal is to get rid of the non-ascii characters and convert the list to a string.
Every ... |
I have some elements in a list in one class. I want them sorted in a new list, and they have to be sorted by an attribute from another class.
Can ... |
i have a list of unicode objects and want to encode them to utf-8.
But encoding doesnt seems to works.
the code is here :
>>> tmp = [u' test context']
>>> tmp.encode('utf-8')
Traceback ...
|
I would like to display the attributes of a give object and was wondering if there was a python function for it.
For example if I had an object from the following ... |
I'm trying to iterate through a list, workerl of instances of a class I defined, worker, and based on one of the class attributes, isemployed, grab 5 of those and call ... |
The full example code:
for typeA in typeAlist:
if typeA in [typeB.typeA for typeB in typeBlist]:
return typeB
Obviously that doesn't work, but it feels like there would be ... |
How would you do this for an instance of xml.etree.cElementTree.Element?
$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on ...
|
I have two list.
List1 contain objects and each object has node1 property.
List2 contain lists of node which are the properties of objects stored in list1.
I want to create separate list which ... |
I try to list all the attributes of an object in Python pdb.
Let's say I want to list all the attributes and all methods of sys.stderr.
How can I do that?
... |
So I have an object:
class Particle(object):
def __init__(self, x, y, vx, vy, ax, ay):
self._x = int(x)
...
|
|
Hi, (I'm not very experienced in Python and coming from C/C++) What would be the best way to implement the following. I have a list L of items I. Each I has an integer attribute p. I have figured out how to sort the list according to p's: L.sort(key=attrgetter('p')) Now I'd like to loop several times over all items with the ... |
|
|
|
[Solved] AttributeError: 'list' object has no attribute by brando56894 Thu May 06, 2010 7:19 pm I wrote this program as a final project for one of my college classes and it was initially in one big file. After I submitted it I wanted to break it down and put the function declarations in separate files from the main program. I ... |
I think it has to do with the list, not the class. You are using a pointer to the same list. This is the statement in error self.data = dt use either self.data = dt[:] ## self.data is a copy not a pointer or if the list is always empty self.data = [] ## new list |
from datetime import datetime from operator import itemgetter class Item(object): def __init__(self, title, date): self.title = title self.date = date items = [Item('A', datetime(2001, 4, 15)), Item('B', datetime(2000, 3, 7)), ... |