-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.py
More file actions
31 lines (25 loc) · 755 Bytes
/
String.py
File metadata and controls
31 lines (25 loc) · 755 Bytes
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
'''
Created on 24/ago/2012
@author: fede
'''
class InvalidArgument(ValueError): pass
class InvalidShift(ValueError): pass
class MyString(str):
def __init__(self,val):
if type(val) is not type('a'):
raise InvalidArgument('argument must be string!')
self.str=val
def __str__(self):
return self.str
def __rshift__(self,a):
if a <=0:
raise InvalidShift('shift must be positive!')
self.str=self.str[a:]+self.str[:a]
return self.str
def __lshift__(self,a):
if a <=0:
raise InvalidShift('shift must be positive!')
self.str=self.str[-a:]+self.str[:-a]
return self.str
def __eq__(self,a):
return self.str is a