MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat
18 19 20 21 22 23 24
25 26 27 28 29 30  
AprMay Jun
Jul Aug Sep
Oct Nov Dec

Wed, Apr 07, 2021 9:34 pm

Iterating over a PHP associative array by key

The PHP scripting language provides associative arrays that allow one to associate a key in the array to a value; each key in the array must be unique. E.g., I can create an array of United States presidents that uses the presidents' names as the keys and their political party affiliation as the value for each key. I could then iterate through the array by key and show the corresponding value for each key as in the example PHP code.

[/languages/php] permanent link

Sat, Sep 12, 2020 7:48 pm

Codes for Short and Long Vowels in Latin

If you wish to insert vowels used in Latin in a document, such as a Microsoft Word or WordPad document, on a Microsoft Windows system to indicate vowel length, i.e., whether the vowel should be pronounced as a long or short vowel, you can use the Unicode values shown in the table below — Unicode is an encoding standard for characters in most of the world's writing systems. For Latin, a macron, which is a diacritic mark, is placed above the letter to indicate a long vowel. Sometimes a breve may also be used to indicate a short vowel. In addition to the Unicode codes, the corresponding Hypertext Markup Language (HTML) code is listed as well for displaying the characters in a web page.

To insert the characters using a Windows keyboard on a system running the Microsoft Windows operating system, type the numeric code (the numbers are hexadecimal numbers so "A" through "F" represent the numbers 10 through 15) and then hit Alt-x, i.e., hit the "Alt" and "x" keys simultaneously, after entering the numeric code. Note, you needed to have a space before the number you enter, otherwise if you attempt to put "ē" in "fēmina," by typing "f" with "0113" immediately after it, the "f0113" will be replaced with a small box with a question mark within it. So place a space after the "f," type 0113, hit Alt-x, then when ē appears, remove the space before it. Also note that though Microsoft Word supports this method of entering vowels with a diacritic mark in a document not all Microsoft Office applications allow you to enter Unicode characters by this method. E.g., for Microsoft Powerpoint, you will need to use the Character Map method of entering such characters, instead.

[ More Info ]

[/languages] permanent link

Fri, Apr 19, 2019 10:01 pm

Extract images from a PDF file with Python

You can use the PyMuPDF module with Python to extract images from a PDF file. You can install PyMuPDF using the pip package manager with the command pip install PyMuPDF . You can determine if it is already installed with the command pip list | grep PyMuPDF or pip freeze | grep PyMuPDF.

# pip list | grep PyMuPDF
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Ple
ase upgrade your Python as Python 2.7 won't be maintained after that date. A fut
ure version of pip will drop support for Python 2.7.
PyMuPDF                          1.14.13
# pip freeze | grep PyMuPDF
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Ple
ase upgrade your Python as Python 2.7 won't be maintained after that date. A fut
ure version of pip will drop support for Python 2.7.

The code for the file is in

[ More Info ]

[/languages/python] permanent link

Sat, Aug 18, 2018 10:16 pm

Determine Python installed modules/packages

If you need to determine the packages/modules/ libraries installed for Python on a system, you can do so by obtaining a Python command prompt and issuing the help("modules") command.

$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")

Please wait a moment while I gather a list of all available modules...

2018-08-18 15:31:45.666 Python[74959:5231860] Cannot find executable for CFBundle 0x
7fe335602be0 </System/Library/Frameworks/Message.framework> (not loaded)
AVFoundation        _TE                 dircache            profile
Accounts            _Win                dis                 pstats
AddressBook         __builtin__         distutils           pty
AppKit              __future__          dl                  pwd
AppleScriptKit      _abcoll             doctest             py2app
AppleScriptObjC     _ast                dumbdbm             py_compile
Audio_mac           _bisect             dummy_thread        pyclbr
Automator           _builtinSuites      dummy_threading     pydoc
BaseHTTPServer      _codecs             easy_install        pydoc_data
Bastion             _codecs_cn          email               pyexpat
CFNetwork           _codecs_hk          encodings           pylab
CFOpenDirectory     _codecs_iso2022     ensurepip           pyparsing
CGIHTTPServer       _codecs_jp          errno               pytz
Canvas              _codecs_kr          exceptions          quopri
Carbon              _codecs_tw          fcntl               random
Cocoa               _collections        filecmp             re
CodeWarrior         _csv                fileinput           readline
Collaboration       _ctypes             findertools         repr
ColorPicker         _ctypes_test        fnmatch             resource
ConfigParser        _curses             formatter           rexec
Cookie              _curses_panel       fpformat            rfc822
CoreData            _elementtree        fractions           rlcompleter
CoreFoundation      _functools          ftplib              robotparser
CoreGraphics        _hashlib            functools           runpy
CoreLocation        _heapq              future_builtins     sched
CoreText            _hotshot            gc                  scipy
Dialog              _io                 genericpath         select
DictionaryServices  _json               gensuitemodule      sets
DocXMLRPCServer     _locale             gestalt             setuptools
EasyDialogs         _lsprof             getopt              sgmllib
EventKit            _markerlib          getpass             sha
ExceptionHandling   _multibytecodec     gettext             shelve
Explorer            _multiprocessing    glob                shlex
FSEvents            _osx_support        grp                 shutil
FileDialog          _pyio               gzip                signal
Finder              _random             hashlib             site
FixTk               _scproxy            heapq               six
Foundation          _socket             hmac                smtpd
FrameWork           _sqlite3            hotshot             smtplib
HTMLParser          _sre                htmlentitydefs      sndhdr
IN                  _ssl                htmllib             socket
InputMethodKit      _strptime           httplib             sqlite3
InstallerPlugins    _struct             ic                  sre
InstantMessage      _symtable           icglue              sre_compile
JavaScriptCore      _sysconfigdata      icopen              sre_constants
LatentSemanticMapping _testcapi           idlelib             sre_parse
LaunchServices      _threading_local    ihooks              ssl
MacOS               _tkinter            imageop             stat
Message             _warnings           imaplib             statvfs
MimeWriter          _weakref            imghdr              string
MiniAEFrame         _weakrefset         imp                 stringold
Nav                 abc                 importlib           stringprep
Netscape            aepack              imputil             strop
OSATerminology      aetools             inspect             struct
OpenDirectory       aetypes             io                  subprocess
OpenSSL             aifc                itertools           sunau
PixMapWrapper       altgraph            json                sunaudio
PreferencePanes     antigravity         keyword             symbol
PubSub              anydbm              lib2to3             symtable
PyObjCTools         applesingle         linecache           sys
PyPDF2              appletrawmain       locale              sysconfig
QTKit               appletrunner        logging             syslog
Quartz              argparse            macerrors           tabnanny
Queue               argvemulator        macholib            tarfile
ScreenSaver         array               macostools          telnetlib
ScriptingBridge     ast                 macpath             tempfile
ScrolledText        asynchat            macresource         terminalcommand
SearchKit           asyncore            macurl2path         termios
ServiceManagement   atexit              mailbox             test
SimpleDialog        audiodev            mailcap             textwrap
SimpleHTTPServer    audioop             markupbase          this
SimpleXMLRPCServer  autoGIL             marshal             thread
Social              base64              math                threading
SocketServer        bdb                 matplotlib          time
StdSuites           bdist_mpkg          md5                 timeit
StringIO            bgenlocations       mhlib               tkColorChooser
SyncServices        binascii            mimetools           tkCommonDialog
SystemConfiguration binhex              mimetypes           tkFileDialog
SystemEvents        bisect              mimify              tkFont
Tix                 bonjour             mmap                tkMessageBox
Tkconstants         bsddb               modulefinder        tkSimpleDialog
Tkdnd               bsddb185            modulegraph         toaiff
Tkinter             buildtools          multifile           token
UserDict            bundlebuilder       multiprocessing     tokenize
UserList            bz2                 mutex               trace
UserString          cPickle             netrc               traceback
WebKit              cProfile            new                 ttk
_AE                 cStringIO           nis                 tty
_AH                 calendar            nntplib             turtle
_App                cfmfile             ntpath              types
_CF                 cgi                 nturl2path          unicodedata
_CG                 cgitb               numbers             unittest
_CarbonEvt          chunk               numpy               urllib
_Cm                 cmath               objc                urllib2
_Ctl                cmd                 olefile             urlparse
_Dlg                code                opcode              user
_Drag               codecs              operator            uu
_Evt                codeop              optparse            uuid
_File               collections         os                  videoreader
_Fm                 colorsys            os2emxpath          warnings
_Folder             commands            parser              wave
_Help               compileall          pdb                 weakref
_IBCarbon           compiler            pickle              webbrowser
_Icn                contextlib          pickletools         whichdb
_LWPCookieJar       cookielib           pimp                wsgiref
_Launch             copy                pip                 xattr
_List               copy_reg            pipes               xdrlib
_Menu               crypt               pkg_resources       xlrd
_Mlte               csv                 pkgutil             xml
_MozillaCookieJar   ctypes              platform            xmllib
_OSA                curses              plistlib            xmlrpclib
_Qd                 datetime            popen2              xxsubtype
_Qdoffs             dateutil            poplib              zipfile
_Qt                 dbhash              posix               zipimport
_Res                dbm                 posixfile           zlib
_Scrap              decimal             posixpath           zope
_Snd                difflib             pprint              

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".

>>> exit()

[ More Info ]

[/languages/python] permanent link

Mon, Jun 11, 2018 10:43 pm

Finding text within lines in a file with PHP

For a weekly status report, I need to determine the number of work requests that are approved and awaiting implementation. The list of requests in that state is contained in a webpage that contains other information, including requests that are in various other states, such as those awaiting approval. I normally download the webpage containing the information to run scripts against it to extract other information from the page, so I decided to create a PHP script that would display just the list of requests awaiting implementation and produce a count of those requests in that state. On the source webpage the line on the page that marks the start of the section of the page containing the requests that are approved and awaiting implementation contains the text "Requests Waiting Implementation". The HTML code on the page that marks the end of that section contains and ending div tag. So I created the two PHP variables below to hold the two strings I need to search for within the file.

$startString = "Requests Waiting Implementation";
$endString = "</div>";

[ More Info ]

[/languages/php] permanent link

Fri, May 18, 2018 10:56 pm

Installing new packages for WinPython

To install a new package/module under WinPython, double-click on WinPython Command Prompt in the directory where you installed WinPython to open a command prompt window.

WinPython installation directory

At the command prompt window type pip install pkgname where pkgname is the name of the package you wish to install. If the package is already present, you will see the message "requirement already satisfied."

[ More Info ]

[/languages/python] permanent link

Sun, May 13, 2018 9:55 pm

WinPython - Python for Microsoft Windows

If you wish to run Python on a Microsoft Windows system, you can use WinPython. The first window you will see when run run the downloaded installation file is one for the license agreement, which notes "WinPython components are distributed as they were received from their copyright holder, under their own copyright and/or license, and without any linking with each other." WinPython itself uses the MIT license. Once you accede to the license, you will be prompted for a destination folder. By default that will be a WinPython directory created beneath the directory where you're running the downloaded file from, but you can change the location. When the installation has been completed, a window will appear where you can click on a Finish button to exit from the installation program.

[ More Info ]

[/languages/python] permanent link

Mon, Feb 19, 2018 11:24 pm

xlrd and hidden worksheets

I use the xlrd module in Python scripts to extract data from Excel workbooks. You can use the Python xlrd module to list the worksheets in a workbook and you can use the xlrd.sheet "visibility" value to determine whether a sheet is hidden and, if it is hidden, whether a user can unhide the sheet. The value should be either 0, 1, or 2 with the numbers having the following meaning:

Visibility of the sheet:

0 = visible
1 = hidden (can be unhidden by user -- Format -> Sheet -> Unhide)
2 = "very hidden" (can be unhidden only by VBA macro)

[ More Info ]

[/languages/python/excel] permanent link

Wed, Feb 14, 2018 9:31 pm

Extracting embedded Microsoft Office files from an Excel spreadsheet

I work with Excel workbooks on my MacBook Pro laptop that have embedded PowerPoint slides on some worksheets. The workbooks, which I need to review, are created by others. When I review them, I extract information from the Excel workbooks to an SQLite database with Python and also have begun extracting information embedded by Object Linking and Embedding (OLE) into files as noted in Extracting the contents of a directory in a zipfile using Python. Some of the embedded files are PowerPoint files, but when they are extracted they have a .bin extension, which I can't open in PowerPoint without changing the filename extension from .bin to .ppt. To automate the renaming process, I created a Python script, that will extract the embedded information to files in an "embedded" directory beneath the current working directory and then rename any .bin files that are PowerPoint files to have a .ppt extension. The script is shown below.

[ More Info ]

[/languages/python/excel] permanent link

Sat, Feb 10, 2018 10:55 pm

Extracting the contents of a directory in a zipfile using Python

A Microsoft Excel file with an .xlsx or .xlsm filename extension is an Office Open XML (OpenXML) zipped, XML-based file. The OpenXML format was developed by Microsoft for spreadsheets, charts, presentations and word processing documents. If you change the file extension to .zip by renaming the file, you can extract the contents of the zip file as you would with any other zip file - see Zipping and unzipping Excel xlsx files. Excel workbooks can contain other documents embedded within them using Object Linking and Embedding (OLE) technology - see Using olefile to obtain metadata from an OLE CDF V2 file. I often need to extract an embedded PowerPoint slide or Visio diagram from Excel .xlsm files, so I've been renaming the files to zip files and unzipping them as I would other zip files, but, since I want to automate the process and extract just specific embedded files for further processing within a Python script, I created the script below to extract the embedded files, which are contained within a xl/embeddings subdirectory within the .xlsm zip files. The script uses the zipfile module to deal with the zip files. Python's OS module is used to check for the existence of the destination directory and create it, if it doesn't yet exist.


import os, zipfile

dirToExtract = "xl/embeddings/"
destinationDir = "embedded"
infile = raw_input("Enter zipfile: ")
archive = zipfile.ZipFile(infile)

if not os.path.exists(destinationDir):

for file in archive.namelist():
    if file.startswith(dirToExtract):
        archive.extract(file, destinationDir)

The script prompts for the file to be unzipped and then extracts just the "xl/embeddings" folder and the files contained within it to a new directory it will create within the current working directory. The new directory will be named "embedded". After extracting the contents of the "xl/embeddings" directory to the newly created "embedded" folder, I had the the files below in the case of the particular .xlsm file I used for this example.

[ More Info ]

[/languages/python/excel] permanent link

Once You Know, You Newegg AliExpress by

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo