Pymel / Python Coding

Category: python

Dictionaries, Pickle and Python

### data sample from country-capitals.csv United Arab Emirates,Abu Dhabi,24.4666666667,54.366667,AE,Asia Nigeria,Abuja,9.0833333333,7.533333,NG,Africa Parse a .csv file and create a Dictionary. import pymel.core as pm dataPath = “C:/country-capitals.csv” f = open(dataPath) line = f.readline() mapDict = {} while line: parts = line.split(“,”) countryObject = parts[0].strip() cityObject = parts[1].strip() latObject = parts[2].strip() lonObject = parts[3].strip() mapDict[countryObject]=[cityObject,latObject,lonObject] line = f.readline()…

Normalized Values

Sometimes its helpful to have a data range scaled into another range aka normalised. I’ve used this for things like having numbers scale into a color ramp that works in the 0-1 range inputVal = 2.1 minVal = 1.2 maxVal = 4.5 normalizedValue = (inputVal – minVal) / (maxVal – minVal) print normalizedValue In this…