목록랭귀지 (525)
아미(아름다운미소)
python 숫자 출력에서 천(1000) 단위마다 콤마를 출력 1. format 지정 - 파이썬 2.7 이상 value = 123456789 print "{:,}".format(value) 2. locale모듈 사용 : import locale print locale.setlocale(locale.LC_ALL, 'en_US') print locale.format("%d", 123456789, grouping=True)
How can I set default values to QDoubleSpinBoxpyqt spinbox set value from PyQt5.QtWidgets import * from PyQt5 import uic form_class = uic.loadUiType("test.ui")[0] class test(QMainWindow, form_class): def __init__(self): super().__init__() self.setupUi(self) self.price1.setValue(4000) if __name__ == "__main__": app = QApplication(sys.argv) testWindow = test() testWindow.show() app.exec_()
5 초간 휴면 상태의 스레드를 사용할 수 있습니다. import threading, time def worker(): i = 0 while (True): print 'do something ... ' + str(time.time()) time.sleep(5) i += 1 if i > 5: break t = threading.Thread(target=worker) print time.time() t.start() print time.time()
파이썬에서 round를 이용한 소수점 반올림 print(round(3.4444)) 결과 : 3.0 print(round(3.4444, 2)) 결과 : 3.44 print(round(3.5)) 결과 : 4.0 print(round(3.5555, 2)) 결과 : 3.56 print('%.2f' % 2.555) 결과 : 2.56
python sqlite -> MySQLdb 변환시 error not all arguments converted during string formatting sqllite cursor.execute("INSERT INTO image(num1, num2, filename, ext, thumbnail, image) VALUES(?, ?, ?, ?, ?, ?);" , (num1, num2, _name, _ext, _thumb, _image)) MySQLdb cursor.execute(""" INSERT INTO image (num1, num2, filename, ext, thumbnail, image) VALUES (%s, %s, %s, %s, %s, %s)""" , (num1, num2, _name, _ex..
pymysql 설치 pip install PyMySQL 예)import pymysql db = pymysql.connect(host='test.synology.me', port=3307, user='testid', passwd='testpw', db='testdb', charset='utf8') try: with db.cursor() as cursor: sql = ''' CREATE TABLE TEST ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, model_num VARCHAR(10) NOT NULL, model_type VARCHAR(10) NOT NULL, PRIMARY KEY(id) ); ''' cursor.execut..
How to use the pandas to get the current time - pandas 설치 C:\ProgramData\Anaconda3\envs\py35>pip install install pandas=0.18.1 #-*- coding: utf-8 -*- ''' Created on 2018. 10. 30. @author: bhm ''' #판다를 사용하여 현재 시간을 얻는 방법. import pandas as pd print (pd.datetime.now()) print (pd.datetime.now().date()) print (pd.datetime.now().year) print (pd.datetime.now().month) print (pd.datetime.now().day) print ..
Python으로 SQLite에서 행의 존재를 확인하는 방법row = cursor.fetchone() if row is None: ... # row is not present else: ... # row is presentsimplerow = cursor.fetchone() if row: print "row is present" else: print "row is not present"
[python] os.startfile Windows 특정 프로그램을 실행하는 방법 Windows를 사용하는 경우 Explorer에서 파일을 두 번 클릭하거나 DOS "start"명령에 대한 인수로 파일 이름을 지정하는 것과 같은 역할을합니다.확장명과 관련된 응용 프로그램이있는 경우 해당 파일이 열립니다 . filepath = 'test.txt' import os os.startfile(filepath) 예: import os os.startfile('test.txt') 메모장이 .txt 파일과 연결된 경우 textfile.txt가 메모장과 함께 열립니다.
pyinstaller설치하기사이트 pyinstaller exe 파일 만들기 exe 파일을 만드려고 하는 python 폴더로 갑니다. 가령 원하는 python 파일 myPython 폴더에 있는 myProject.py라고 하면, cmd창에서 다음과 같이 입력하면 됩니다. d:\myPython> pyinstall.exe myProject.py단일 파일로 만들기만약 myProject.py를 하나의 exe파일로 만드려고 하면 -F 옵션을 추가하면 됩니다. d:\myPython> pyinstall.exe -F myProject.py콘솔창 숨기기 옵션만약 console창을 숨기고 싶으면 다음과 같은 --noconsole 옵션을 추가하면 됩니다. d:\myPython> pyinstaller -F --noconsole ..