본문 바로가기

Python7

Python List 연산 예제 # 리스트 아이템 중복 갯수 계산하기 ​ a=[1,2,3,4] b=[2,3,4,5] d=[8] ​ e = [item for item in d if item in b] print(len(e)) 1 ​ f = [item for item in a if item in b] print(len(f)) 3 ​ c = [item for item in a if item not in b] print(len(a)-len(c)) 0 ​ c = [item for item in d if item not in b] print(len(d)-len(c)) 1 ​ 추가 : 아래는 집합으로 변형해서 처리한다. ## 비교 list 정의 x = [1, 2, 3, 4, 5, 6] y = [9, 8, 7, 6, 5, 6] ​ ##########.. 2019. 11. 10.
python file example 개행문자 \r 없애기 How to Remove Carrige Return in Text File using Python. DOS 또는 Windows에서 작성한 text file을 linux에 가져가면, 텍스트 문자열 끝에 '\r'이 추가로 붙어서 간다. 이를 vi에서 제거할 떄는 1,$s/^V^M// 이런 명령으로 제거할 수 있지만, 파일이 많을 때는 이렇게 제거하는 것이 불편하기 때문에 Python으로 코드를 작성해보았다. ​ iimport os sdir = '~/darknet/IHCIMGS/img/' flist = os.listdir(sdir) for fn in flist: #print (fn) if fn[-4:] == '.txt': fpath = sdir + fn print(fpath) text_file = open(f.. 2019. 10. 5.
pronterface Graph 박스 부분 gui/_init_.py : # ControlsSizer 속에서 controls_panel에 그래프 영역을 그린다. controls_sizer = ControlsSizer(self, controls_panel, mini_mode = mini) ​ constrols.py : # ControlsSizer 속에서 add_extra_controls를 호출하면 그 속에 그래프 추가가 있다. ​ constrols.py : add_extra_controls(self, root, parentpanel, None) # 이 속에서 그래프 영역이 지정된다. ​ if root.display_graph: root.graph = Graph(parentpanel, wx.ID_ANY, root) add("tempgraph", roo.. 2019. 10. 5.
wxPython GUI 만들기 설명 이 예제는 class Excmaple(wx.Frame): 선언에 붙어있는 것이라서 ​ Panel에 Sizer를 지정할건데, 일단 Panel 생성, 여기서 self는 당연히 Frame이 되는 것이다. panel = wx.Panel(self) ​ Vertical Sizer를 만들자. vbox = wx.BoxSizer(wx.VERTICAL) # 내용물이 수직 채워짐 ​ Panel에 TextCtrl, CheckBox를 등록한다. tc = wx.TextCtrl(panel, style=wx.TE_MULTILINE) 이런식으로 ​ Sizer에 tc를 등록한다. hbox3 = wx.BoxSizer(wx.HORIZONTAL) 이런식으로 생성된 box에 아래처럼 tc2를 Sizer에 넣어준다. hbox3.Add(tc2, .. 2019. 10. 5.