I don't understand this syntax error

A

Antoon Pardon

I'm probably looking right over it, but for the moment
I'm stumped. Can someone explain what is wrong. I'm running
python 2.5.2 here

This is the code:

class vslice(object):

def __init__(self, fun):
self.fun = fun

def __getitem__(self, inx):
if not isinstance(inx, tuple):
inx = inx,
return self.fun(*inx)

@vslice
class IdSet(object):
def __init__(self, *args):
self.lst = [(sl.start, sl.stop) for sl in args]

def __contains__(self, item):
for low, high in self.lst:
if low <= item < high:
return True
return False

def __str__(self):
return '[' + ', '.join('%d:%d' % sl for sl in self.lst) + ']'

#IdSet = vslice(IdSet)

idset = IdSet[1:3, 6:9]

print idset

for i in xrange(10):
print i, i in idset


This is the error I get:

File "vslice.py", line 12
class IdSet(object):
^
SyntaxError: invalid syntax
 
P

Peter Otten

Antoon said:
I'm probably looking right over it, but for the moment
I'm stumped. Can someone explain what is wrong. I'm running
python 2.5.2 here

This is the code:
@vslice
class IdSet(object):

Class decorators require Python 2.6

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top