当前位置:首页 » Python技术

py

2018-09-27 12:32 本站整理 浏览(7)

# >python Sample1.py
# hello, world
class Feature:
'feature'
def __init__(self, att, value):
self._att = att
self._value = value
def att(self):
"att"
return self._att
def value(self):
"value"
return self._value
if __name__ == '__main__':
print("hello, world")
f = Feature("att1", "value of att1")
print(f.att())
print(f.value())
# >python Sample1.py
#
import socket
if __name__ == '__main__':
print("hello, world")
s = socket.socket()
host = socket.gethostname()
s.bind(("localhost", 12345))
s.listen(5)
print("startup...")
while True:
c, addr = s.accept()
print('remote address', addr)
c.send(("hello, world").encode())
c.close()
# >python Sample1.py
#
import socket
if __name__ == '__main__':
print("hello, world")
s = socket.socket()
host = socket.gethostname()
s.connect(("localhost", 12345))
print ((s.recv(1024)).decode())
s.close()