페이지

2019년 12월 24일 화요일

python simple http server ( web server )

현재 디렉토리를 웹서버로 만들어주는 명령입니다.

커맨드창에서 다음 명령을 실행합니다.


python -m SimpleHTTPServer


포트를 지정할 수 있습니다.

python -m SimpleHTTPServer 9000


Serving HTTP on 0.0.0.0 port 9000 ...

과 같은 메시지가 나오면 작동하는 것입니다.



https://docs.python.org/2/library/simplehttpserver.html

2019년 8월 10일 토요일

python mysql mysqlclient MySQLdb

설치

pip install mysqlclient


모듈 로드

import MySQLdb


데이터베이스 연결

connection = MySQLdb.connect(
    user="username",
    passwd="password",
    host="localhost",
    db="dbname",
    charset="utf8"
)

커서 추출

cursor = connection.cursor()

업데이트 쿼리

# create table note ( title varchar(100), content text )
cursor.execute("insert into note(title, content) values(%s,%s)", ("a", "b"))
connection.commit()

조회 쿼리

sql = "select * from note where title=%s"
cursor.execute(sql, ('a',))

for row in cursor.fetchall():
    print(row)  # ('a', 'b')

Dict 커서로 변경

cursor = connection.cursor(MySQLdb.cursors.DictCursor)

cursor.execute(sql, ('a',))
for row in cursor.fetchall():
    print(row)  # {'title': 'a', 'content': 'b'}
    print(row['title'], row['content'])     # a b

연결 종료

connection.close()

2019년 4월 24일 수요일

(Roundcube) Mailbox doesn't exist: trash

(Roundcube) Mailbox doesn't exist: trash

지운 편지함이 없는 상태에서 메일을 지우면 위와 같이 에러가 발생합니다.

폴더 관리에서 Trash 폴더를 생성해주면 해결됩니다.