목록프로그래밍/Python (11)
yongyong-e
from pyqtgraph import examples as pge pge.run()
Installation$ sudo apt-get install python3-pyqt5 $ sudo apt-get install pyqt5-dev-tools $ sudo apt-get install qttools5-dev-tools $ pip3 install pyqt5Configuring to run from terminal $ qtchooser -run-tool=designer -qt=5
1) PPA 추가$ sudo add-apt-repository ppa:jonathonf/python-3.6 2) 업데이트 및 설치$ sudo apt-get update $ sudo apt-get install python3.6
1) 가상환경 모듈 설치# python 2.7$ pip install virtualenv # python 3.5$ pip3 install virtualenv 2) 가상환경 생성$ virtualenv 가상환경이름 # python 2.7 환경생성 $ virtualenv 가상환경이름 --python=python2.7 # python 3.5 환경생성$ virtualenv 가상환경이름 --python=python3.5 3) 가상환경 활성화/비활성화# 활성화$ source 가상환경이름/bin/activate # 비활성화$ deactivate 4) 패키지 관리# 설치된 패키지 저장$ pip freeze > requirements.txt # 저장된 패키지 설치$ pip install -r requirements.txt
SUMMARY문자열에서 중복되는 문자없이 유일한 문자들만 존재하는지 판별하는 함수를 만들어보자. Code# unique_str.py def unique_string(str): if len(str) > 256: return False hash = [False] * 256 for ch in str: if hash[ord(ch)] is True: return False else: hash[ord(ch)] = True return True print('문자열을 입력하세요.') str = input() print(unique_string(str))
SUMMARYpython에서 문자열을 뒤집는 함수를 만들어보자. Code# reverse_str.py # solve_1 def reverse_string(str): return str[::-1] # solve_2 def reverse_stack(str): stack = [] for ch in str: stack.append(ch) result = "" while len(stack) > 0: result += stack.pop() return result print('뒤집을 문자열을 입력하세요.') str = input() print(reverse_stack(str))
threading을 사용하여 여러 클라이언트와 연결이 가능하도록 구현 # Server# serverTest4.py import socket from threading import Thread HOST = socket.gethostname() PORT = 50000 ADDR = (HOST, PORT) BUFF_SIZE = 1024 class ClientThread(Thread): def __init__(self,host,port,sock): Thread.__init__(self) self.host = host self.port = port self.sock = sock print ("(Check the new thread) "+host+":"+str(port)) def run(self): filename=..
local server에서 local client로 파일전송 구현 및 앞선 코드변경 # Server# serverTest3.py import socket HOST = socket.gethostname() PORT = 50000 ADDR = (HOST, PORT) BUFF_SIZE = 1024 serverSocket = socket.socket() serverSocket.bind(ADDR) serverSocket.listen(5) print ('Server waiting...') while True: clientSocket, addr = serverSocket.accept() print ('Connection from', addr) data = clientSocket.recv(BUFF_SIZE) print..
client에서 server로 접속 시 파일전송 구현 # Server# serverTest2.py from socket import * import struct HOST = '192.168.0.10' PORT = 50000 ADDR = (HOST, PORT) BUFF_SIZE = 1024 FILE_NAME = 'clientFile.jpg' FILE_LEN = 0 serverSocket = socket(AF_INET, SOCK_STREAM) serverSocket.bind(ADDR) serverSocket.listen(5) clientSocket, addr = serverSocket.accept() FILE_SIZE = clientSocket.recv(8) FILE_SIZE = struct.unpack('..
# Server# serverTest.py from socket import * HOST = '192.168.0.10' PORT = 50005 ADDR = (HOST, PORT) BUFF_SIZE = 1024 serverSocket = socket(AF_INET, SOCK_STREAM) serverSocket.bind(ADDR) serverSocket.listen(5) clientSocket, addr = serverSocket.accept() client_msg = clientSocket.recv(BUFF_SIZE) print('client : ', client_msg.decode()) server_msg = 'server message' clientSocket.send(server_msg.encode..