This website works better with JavaScript.
Home
Help
Sign In
tmeissner
/
learning-by-doing
Watch
1
Star
0
Fork
0
Code
Issues
0
Pull Requests
0
Releases
0
Wiki
Activity
Browse Source
example for useful use of property function
master
T. Meissner
10 years ago
parent
b0a6f0240f
commit
427eac2f82
1 changed files
with
18 additions
and
0 deletions
Unified View
Diff Options
Show Stats
Download Patch File
Download Diff File
+18
-0
python_3_oop/chapter05/webpage.py
+ 18
- 0
python_3_oop/chapter05/webpage.py
View File
@ -0,0 +1,18 @@
from
urllib.request
import
urlopen
import
time
class
WebPage
:
def
__init__
(
self
,
url
)
:
self
.
url
=
url
self
.
_content
=
None
@property
def
content
(
self
)
:
now
=
time
.
time
(
)
if
not
self
.
_content
:
print
(
"
Retrieving new page...
"
)
self
.
_content
=
urlopen
(
self
.
url
)
.
read
(
)
print
(
"
Got page in {} seconds
"
.
format
(
time
.
time
(
)
-
now
)
)
return
self
.
_content
Write
Preview
Loading…
Cancel
Save