This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def locate_usb(): | |
| import win32file | |
| drive_list = [] | |
| drivebits=win32file.GetLogicalDrives() | |
| for d in range(1,26): | |
| mask=1 << d | |
| if drivebits & mask: | |
| # here if the drive is at least there | |
| drname='%c:\\' % chr(ord('A')+d) | |
| t=win32file.GetDriveType(drname) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### http://georgik.sinusgear.com/2011/01/07/how-to-dump-post-request-with-python/ | |
| import SimpleHTTPServer | |
| import SocketServer | |
| import logging | |
| import cgi | |
| PORT = 8000 | |
| class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://forthescience.org/blog/2013/08/15/how-to-convert-a-qstring-to-unicode-object-in-python-2/ | |
| I had this problem to solve, and I tried to find the safest way. This program illustrates the solution | |
| from PyQt4 import QtCore, QtGui | |
| import sys | |
| app = QtGui.QApplication(sys.argv) | |
| ed = QtGui.QLineEdit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var normalizarTexto = function(texto){ | |
| var accents = { | |
| 'à':'a','á':'a','â':'a','ã':'a','ä':'a','å':'a','æ':'e','è':'e','é':'e','ê':'e','ë':'e','ì':'i', | |
| 'í':'i','î':'i','ò':'o','ó':'o','ô':'o','ö':'o','ù':'u','ú':'u','û':'u','ü':'u','ñ':'n' | |
| }; | |
| texto = texto.toLowerCase(); | |
| texto = texto.replace(/[àáâãäåæèéêëìíîòóôöùúûüñ]/gi, function(m){return accents[m];}); | |
| texto = texto.replace(/\s/gi,""); | |
| return texto; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| encodings = ['utf-8', 'windows-1250', 'windows-1252' ...etc] | |
| for e in encodings: | |
| try: | |
| fh = codecs.open('file.txt', 'r', encoding=e) | |
| fh.readlines() | |
| fh.seek(0) | |
| except UnicodeDecodeError: | |
| print('got unicode error with %s , trying different encoding' % e) | |
| else: | |
| print('opening the file with encoding: %s ' % e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import zipfile | |
| import StringIO | |
| class InMemoryZip(object): | |
| def __init__(self): | |
| # Create the in-memory file-like object for working w/imz | |
| self.in_memory_zip = StringIO.StringIO() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def HTML2Text(html): | |
| class _HTMLParser(HTMLParser): | |
| def __init__(self): | |
| HTMLParser.__init__(self) | |
| self._text = [] | |
| def handle_data(self, data): | |
| append = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| To have a 'read-only' property in a class you can make use of the @property decoration, you'll need to inherit from object when you do so to make use of the new-style classes. | |
| Example: | |
| >>> class A(object): | |
| ... def __init__(self, a): | |
| ... self.__a = a | |
| ... @property | |
| ... def a(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Author: Dev Mehta / dpmehta02@gmail.com | |
| Description: Create a simple bag-of-words. Accepts a csv of strings, writes a BoW to a CSV named 'matrix.csv.' | |
| Usage: python bagOfWords.py | |
| """ | |
| import textmining | |
| def main(): | |
| # https://pypi.python.org/pypi/textmining |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| pattern = re.compile("http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?") | |
| print pattern.search("no link") | |
| print pattern.search("http://www.youtube.com/watch?v=ueYkNy66nuU") | |
| print pattern.search("http://www.youtube.com/movie/dentro-del-laberinto-ve") | |
| print re.search("http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?", "http://www.youtube.com/watch?v=ueYkNy66nuU") |