Skip to main content

Posts

Showing posts with the label Python

Generate universally unique ID in Python

In my previous post, I discussed how to generate GUID (Windows world) or the standard equivalent UUID to generate a guaranteed unique identifier from Python. I didn't know that their is a CPython library that can do this in a more platform neutral way. Just today, I came across the module uuid. uuid is now part of the standard Python library but as to when, I am not sure. One thing I am certain, it is there in Python 2.5.1. Below is a sample code to generate a UUID version 4 . import uuid print uuid . uuid4 () If you want to know more about UUID and the standards using it, please pay a visit to Wikipedia - UUID . ~ts~

Generate GUID in Python running in Windows

GUID can be useful as a primary key for a databases and also for the records or rows of data that needs to be unique. There are a lot of tools that can generate a GUID but in this quickie blog, I am documenting how to generate a GUID using Python in Windows. To generate a GUID, import the code below: import pythoncom _guid = pythoncom . CreateGuid () _guid_str = str ( _guid ) print "%s GUID is %d long" %( _guid_str , len ( _guid_str )) ~ts~

Grab screen capture programatically

Pre-requisite: Python 2.5 for Windows Python Imaging Library ( PIL ). Install Python 2.5 for Microsoft Windows. Make sure that you have administrative rights to be able to install the application properly. After having verified that Python is installed and working, install Python Imaging Library. See below for a sample of screen capture python script. #--<-start code here->-- import ImageGrab ; img = ImageGrab . grab () img . save ( "D:\\test.jpg" ) #--<-end code here->-- ~ts~

List Microsoft Windows products installed in a system

I develop a short python script to display Microsft Corporation software that is installed on a system. This script can be modifed easily to check for all installed OS hotfixes if need be. See below for the script: <---code----- import _winreg import sys hkcu = _winreg . ConnectRegistry ( None , _winreg . HKEY_LOCAL_MACHINE ) m_key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" m_UnInstall = _winreg . OpenKey ( hkcu , r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ) _index = 0 while True :      try :          m_subkey = _winreg . EnumKey ( m_UnInstall , _index )          m_newkey = m_key + "\\" + m_subkey          m_RegistryKey = _winreg . OpenKey ( hkcu , m_newkey )          try :              if _winreg . QueryValueEx ( m_RegistryKey , r"Publisher" )[ 0 ] == r"Microsoft Corporation" :                                   print _winreg . QueryValueEx ( m_RegistryKey , r"DisplayNam

Python 2.5 install issue on some Windows XP machines

I have installed Python 2.5 from ActiveState on two machines now and each one was working pretty nice. But on one of my machines PythonWin refused to load, see below for the message: --------------------------- Python for Win32 --------------------------- The application can not locate win32ui.pyd (or Python) (126) The specified module could not be found. --------------------------- OK Searching in ASPN network I found out that this is an open issue, see 68141 . The good thing with this bug is that the workaround is quite simple if you have a working installation. Just copy pythoncom25.dll and pywintypes25.dll into c:\windows\system32 of the machine that PythonWin does not work. What if you don't have a working machine? Well, low and behold, I have it for you. Download it here . I'll be more than thankful if anyone can report to me that this issue is already fixed so that I can update this blog. Another work-around is to install pythonwin on top of currently installed vers