일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- MySQL
- pandas
- sqlite
- GIT
- Excel
- javascript
- 날짜
- python
- PyQt5
- PER
- swift
- 맛집
- Unity
- node.js
- 유니티
- PyQt
- 라즈베리파이
- IOS
- MS-SQL
- ubuntu
- port
- flutter
- Linux
- 함수
- mssql
- urllib
- tensorflow
- ASP
- 리눅스
- 다이어트
목록랭귀지/python (244)
아미(아름다운미소)
함수 : os.path.isfile() , os.path.isdir() 디스크에 특정 파일명의 파일이 실제로 존재하는지, 또는 특정 디렉토리명의 디렉토리가 정말로 있는지 알아내는 방법입니다. os.path.isfile() 함수는, 지정한 패스가 파일이고 실제로 존재할 때에만 참을 반환하기에, 파일이 존재하는지 알아내는 용도로 사용할 수 있습니다. os.path.isdir()은 디렉토리(폴더)에 적용됩니다. 파일/폴더 존재 여부 알아내기 예제 스크립트 파일명: sample.py #!/usr/bin/python # -*- coding: utf-8 -*- import os if os.path.isfile("sample.txt"): print "파일 있습니다" else: print "그런 이름의 파일은 없습니다..
python2.7 에서 한글폴더 읽기 Python 2.7.14 windows7 #-*- encoding: utf8 -*- import os for f in os.listdir(u's:/한글폴더'): print(f) python 3.7.0 (3버전 이상)에서는 encoding , u 상관없이 잘 읽어옵니다.
Python: ftplib를 이용해 FTP server에서 다운로드받기 import ftplib path = 'pub/path/' filename = 'sample.txt' ftp = ftplib.FTP("Server IP") ftp.login("UserName", "Password") ftp.cwd(path) ftp.retrbinary("RETR " + filename, open(filename, 'wb').write) ftp.quit()
[ftplib] python ftp file upload import ftplib filename = "sample.png" ftp = ftplib.FTP() ftp.connect("111.111.111.111","21") #Ftp 주소 Connect(주소 , 포트) ftp.login("id", "password") #login (ID, Password) ftp.cwd("/forder/Test") #파일 전송할 Ftp 주소 (받을 주소) os.chdir(r"D:\\FTP_TEST\\img") #파일 전송 대상의 주소(보내는 주소) my_file = open(filename, 'rb') #Open( ~ ,'r')
1 단계: 연결 합니다 pymssql.connect 함수는 SQL Database에 연결 하는 데 사용 됩니다. import pymssql conn = pymssql.connect(host='yourserver IP', user='youruserid', password='yourpassword', database='dbname') 2 단계: 쿼리를 실행 합니다. (SELECT 예제) import pymssql conn = pymssql.connect(host='yourserver IP', user='youruserid', password='yourpassword', database='dbname') cursor = conn.cursor() cursor.execute('SELECT c.CustomerID,..
Python 이미지 파일 확인하기 이미지 파일들의 집합을 빠르게 확인하는 단순한 스크립트입니다. import os, sys import Image size = 128, 128 for infile in sys.argv[1:]: outfile = os.path.splitext(infile)[0] + ".thumbnail" if infile != outfile: try: im = Image.open(infile) im.thumbnail(size) im.save(outfile, "JPEG") except IOError: print "cannot create thumbnail for", infile
JPEG 섬네일 생성하기 import os, sys import Image size = 128, 128 for infile in sys.argv[1:]: outfile = os.path.splitext(infile)[0] + ".thumbnail" if infile != outfile: try: im = Image.open(infile) im.thumbnail(size) im.save(outfile, "JPEG") except IOError: print "cannot create thumbnail for", infile
파일을 JPEG으로 변환하기 import os, sys import Image size = 128, 128 for infile in sys.argv[1:]: outfile = os.path.splitext(infile)[0] + ".thumbnail" if infile != outfile: try: im = Image.open(infile) im.thumbnail(size) im.save(outfile, "JPEG") except IOError: print "cannot create thumbnail for", infile splitext(p) pathname에서 확장자를 분리합니다. 확장자는 점(.) 뒤에 있는 텍스트 입니다. "(root, ext)"를 반환하고, ext는 비어 있을 수도 있습니다. 두..
urllib2를 사용하여 요청하기 전에 프록시 를 설정할 수 있습니다 . proxy = urllib2.ProxyHandler({'http': '127.0.0.1'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) urllib2.urlopen('http://www.google.com')
Python을 사용하여 XML 파싱 XML: PYTHON: from xml.dom import minidom xmldoc = minidom.parse('items.xml') itemlist = xmldoc.getElementsByTagName('item') print(len(itemlist)) print(itemlist[0].attributes['name'].value) for s in itemlist: print(s.attributes['name'].value) OUTPUT : 4 item1 item1 item2 item3 item4