-
Notifications
You must be signed in to change notification settings - Fork 0
/
regular_expression_of_py.py
63 lines (58 loc) · 1.67 KB
/
regular_expression_of_py.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import re
search_string = "hello world"
pattern = "hello world"
match = re.match(pattern, search_string)
if match:
print("regex matches")
# import sys
# pattern = sys.argv[1]
# search_string = sys.argv[2]
# match = re.match(pattern, search_string)
# if match:
# template = "'{}' matches pattern '{}'"
# else:
# template = "'{}' does not match pattern '{}'"
# print(template.format(search_string, pattern))
# pattern = "^[a-zA-Z.]+@([a-z.]*\.[a-z]+)$"
# search_string = "[email protected]"
# match = re.match(pattern, search_string)
# if match:
# domain = match.groups()[0]
# print(domain)
from threading import Timer
import datetime
from urllib.request import urlopen
class UpdatedURL:
def __init__(self, url):
self.url = url
self.contents = ''
self.last_updated = None
self.update()
def update(self):
self.contents = urlopen(self.url).read()
self.last_updated = datetime.datetime.now()
self.schedule()
def schedule(self):
self.timer = Timer(3600, self.update)
self.timer.setDaemon(True)
self.timer.start()
def __getstate__(self):
new_state = self.__dict__.copy()
if 'timer' in new_state:
del new_state['timer']
return new_state
def __setstate__(self, data):
self.__dict__ = data
self.schedule()
u = UpdatedURL("http://news.yahoo.com/")
import pickle
serialized = pickle.dumps(u)
class Contact:
def __init__(self, first, last):
self.first = first
self.last = last
@property
def full_name(self):
return("{} {}".format(self.first, self.last))
c = Contact("John", "Smith")
x=json.dumps(c.__dict__)