Skip to content

Instantly share code, notes, and snippets.

View jasonbot's full-sized avatar
🥉

Jason Scheirer jasonbot

🥉
View GitHub Profile
@jasonbot
jasonbot / gist:5162544
Created March 14, 2013 15:55
All the modules bundled with Anaconda
['ArgImagePlugin',
'BaseHTTPServer',
'Bastion',
'BdfFontFile',
'BmpImagePlugin',
'BufrStubImagePlugin',
'CGIHTTPServer',
'Canvas',
'ConfigParser',
'ContainerIO',
@jasonbot
jasonbot / daupdatedicts.py
Last active March 24, 2020 19:39
Update cursor with dictionary rows
def rows_as_update_dicts(cursor):
colnames = cursor.fields
for row in cursor:
row_object = dict(zip(colnames, row))
yield row_object
cursor.updateRow([row_object[colname] for colname in colnames])
with arcpy.da.UpdateCursor(r'c:\data\world.gdb\world_cities', ['CITY_NAME']) as sc:
for row in rows_as_update_dicts(sc):
row['CITY_NAME'] = row['CITY_NAME'].title()
@jasonbot
jasonbot / rowsasnamedtuples.py
Created July 12, 2012 19:37
Get namedtuples instead of lists from an arcpy.da SearchCursor
import collections
def rows_as_namedtuples(cursor):
col_tuple = collections.namedtuple('Row', cursor.fields)
for row in cursor:
yield col_tuple(*row)
with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc:
for row in rows_as_namedtuples(sc):
print sc.CITY_NAME
@jasonbot
jasonbot / rowsasdicts.py
Last active January 31, 2019 20:41
Get dicts instead of lists from an arcpy.da SearchCursor
def rows_as_dicts(cursor):
colnames = cursor.fields
for row in cursor:
yield dict(zip(colnames, row))
with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc:
for row in rows_as_dicts(sc):
print row['CITY_NAME']
@jasonbot
jasonbot / textmetrics.py
Created January 31, 2012 21:50
Get the width and height (in inches) of a string using the Win32 CTypes APIs.
import ctypes
import ctypes.wintypes
class Constants(object):
"Container for constants found in win32 headers"
WS_OVERLAPPED = 0x00000000L
WS_POPUP = 0x80000000L
WS_CHILD = 0x40000000L
WS_MINIMIZE = 0x20000000L
WS_VISIBLE = 0x10000000L