일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 맛집
- MySQL
- javascript
- Unity
- node.js
- Excel
- urllib
- MS-SQL
- pandas
- 함수
- 라즈베리파이
- flutter
- 리눅스
- 유니티
- ASP
- IOS
- GIT
- Linux
- port
- PyQt
- PER
- mssql
- PyQt5
- 날짜
- swift
- sqlite
- python
- 다이어트
- tensorflow
- ubuntu
목록python (161)
아미(아름다운미소)
특정 디렉토리 내의 파일 갯수를 얻어와야 하는 경우 아래와 같은 코드를 이용합니다. os.walk('절대경로').next() 는 배열로 아래와 같은 형식을 취합니다. os.walk('절대경로').next()[0] ==> 디렉토리 경로 os.walk('절대경로').next()[1] ==> 디렉토리 내의 디렉토리 개수 os.walk('절대경로').next()[2] ==> 디렉토리 내의 파일 개수 - 특정 디렉토리 내의 파일 갯수 예제 import os print len(os.walk('디렉토리_절대경로').next()[2])
함수 : 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 "그런 이름의 파일은 없습니다..
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')
Playing mp3 song on python - Navigation Bar import os os.system('start path/to/player/executable path/to/file.mp3')
파일을 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
1. JSONJSON은 JavaScript Object Notation의 약자로서 JavaScript 문법에 영향을 받아 개발된 Lightweight한 데이타 표현 방식입니다. JSON은 데이타를 교환하는 한 포맷으로서 그 단순함과 유연함 때문에 널리 사용되고 있습니다. 특히 웹 브라우져와 웹서버 사이에 데이타를 교환하는데 많이 사용되고 있습니다. 가장 많이 사용되는 JSON 포맷은 Key-Value Pair의 컬렉션입니다. Python은 기본적으로 JSON 표준 라이브러리(json)를 제공하고 있는데, "import json" 을 사용하여 JSON 라이브러리를 사용할 수 있습니다. (주: Python 2.6 이상). JSON 라이브러리를 사용하면, Python 타입의 Object를 JSON 문자열로 변..
파이썬에서 파일을 다운로드하는 방법- Python 2에서 파일을 다운로드하는 방법 import urllib urllib.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3") (Python 3+에서는 'import urllib.request'와 urllib.request.urlretrieve를 사용하십시오) - 파이썬에서 파일을로드하는 방법(진행 표시 줄) import urllib2 url = "http://download.thinkbroadband.com/10MB.zip" file_name = url.split('/')[-1] u = urllib2.urlopen(url) f = open(file_name, 'wb') meta = u.info()..