본문 바로가기

SW 프로그래밍190

파일 쓰기 파일에 새로운 내용 추가하기 쓰기 모드('w')로 파일을 열 때 이미 존재하는 파일을 열면 그 파일의 내용이 모두 사라지게 된다. 하지만 원래 있던 값을 유지하면서 단지 새로운 값만 추가해야 할 경우도 있다. 이런 경우에는 파일을 추가 모드('a')로 열면 된다. 에디터를 켜고 다음 소스 코드를 작성해 보자. # adddata.py f = open("C:/doit/새파일.txt",'a') for i in range(11, 20): data = "%d번째 줄입니다.\n" % i f.write(data) f.close() 위 예는 새파일.txt 파일을 추가 모드('a')로 열고 write를 사용해서 결괏값을 기존 파일에 추가해 적는 예이다. 여기에서 추가 모드로 파일을 열었기 때문에 새파일.txt 파일이 원.. 2019. 12. 3.
python – matplotlib.pyplot으로 이미지 저장 안될때 파이썬 pyplot에서 그래프를 이미지로 저장할수 있다. 그런데 막상 해보면 저장이 안된다. 둘중 하나는 선택하여야 한다. show로 할지 savefig 할지.. 둘중 하나만 된다. 예시(저장 안되는..) import matplotlib.pyplot as plt fig = plt.figure() plt.plot(d,c1[0:100],'b--',d,c2[0:100],'r--',d,c3[0:100],'g--',figure = fig) plt.ylabel("concentration") plt.xlabel("distance") plt.show() plt.savefig('./Results/evol_conc_v'+str(vinit)+'a_'+str(a)+'.png') 이것을 저장하려면 import matplotli.. 2019. 10. 24.
Customizing Matplotlib with style sheets and rcParams #### MATPLOTLIBRC FORMAT ## This is a sample matplotlib configuration file - you can find a copy ## of it on your system in ## site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it ## there, please note that it will be overwritten in your next install. ## If you want to keep a permanent local copy that will not be ## overwritten, place it in the following location: ## unix/linux: ## $HO.. 2019. 10. 24.
문자열을 숫자로 변환; 문자를 정수(int, long), 실수(float)로 바꾸기 MySQL에서 데이터를 가져오면 대부분 문자이다.(varchar) 화면에는 숫자처럼 보이지만 실제는 문자열이다. 이를 통해 그래프를 그리거나 연산을 할수 없다. 간단히 숫자로 변환하는 방법이 있다. #!/usr/bin/python # -*- coding: cp949 -*- # 이 파일의 맨 첫줄에 빈줄이 있으면 # SyntaxError: Non-UTF-8 code starting with '\xbc' in file example3.py on line 6, # but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details # 이런 식의 에러가 납니다. # "정수 문자열"을 정수로 만들어, 플러스 1 하기 s = "123" n =.. 2019. 10. 24.
Python 소스코드 버전 변환 2to3.py C:\Python34\Tools\Scripts\2to3.py 소스파일이 3버전에 맞게 변환되고, 원본은 "파일명.bak"으로 보존된다. python C:\Python34\Tools\Scripts\2to3.py -w 소스파일명 실행예시 D:\workspace\python>python C:\Python34\Tools\Scripts\2to3.py -w greeting.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixe.. 2019. 8. 31.
top 화면 색상 변경하기 1) 설정하기 전 top 화면 2) 설정하기 root 또는 로그인 계정에 .toprc 라는 파일을 생성하고 다음과 같이 값을 넣어줍니다. RCfile for “top with windows” # shameless braggin’ Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0 Def fieldscur=AEHIOQTWKLNMbcdfgjrpsuvyzX winflags=97144, sortindx=10, maxtasks=0 summclr=3, msgsclr=1, headclr=3, taskclr=2 Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX winflags=62777, sortindx=0, maxtasks=0 sum.. 2019. 7. 14.