Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit81681c3

Browse files
committed
Add demo for decorator
1 parent8b1b1fe commit81681c3

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

‎Decorators/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Decorators</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

‎Decorators/.pydevproject

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_pathpropertyname="org.python.pydev.PROJECT_SOURCE_PATH">
4+
<path>/${PROJECT_DIR_NAME}/src</path>
5+
</pydev_pathproperty>
6+
<pydev_propertyname="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.6</pydev_property>
7+
<pydev_propertyname="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
8+
</pydev_project>

‎Decorators/src/decoratorsdemo.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'''
2+
Created on Aug 6, 2017
3+
4+
@author: Aditya
5+
6+
'''
7+
8+
classGOT:
9+
def__init__(self,**kargs):
10+
self.properties=kargs
11+
12+
defwhat(self):
13+
print('GOT is Game of Thrones!!')
14+
15+
defpurpose(self):
16+
print('GOT tells the story of 7 kingdoms and the ruler of those kingdoms.')
17+
18+
defget_properties(self):
19+
returnself.properties
20+
21+
defget_property(self,key):
22+
returnself.properties.get(key,None)
23+
24+
@property
25+
defkingdom_animal(self):
26+
returnself.properties.get('kingdom_animal',None)
27+
28+
@kingdom_animal.setter
29+
defkingdom_animal(self,a):
30+
self.properties['kingdom_animal']=a
31+
32+
@kingdom_animal.deleter
33+
defkingdom_animal(self):
34+
delself.properties['kingdom_animal']
35+
36+
defmain():
37+
print('''Decorators in python are used to create accessor methods for variables.''')
38+
houseStark=GOT(kingdom_animal='Wolf',location='North')
39+
print(houseStark.get_properties())
40+
print(houseStark.get_property('kingdom_animal'))
41+
print(houseStark.get_property('location'))
42+
43+
print('\nDemo of Decorators:')
44+
print('Getter:',houseStark.kingdom_animal)
45+
46+
delhouseStark.kingdom_animal
47+
48+
print(houseStark.kingdom_animal)
49+
50+
houseStark.kingdom_animal='Lion'
51+
print(houseStark.kingdom_animal)
52+
53+
54+
if__name__=='__main__':main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp