![]() |
| ||
| Color Dictionary I have a color data file that gives the color name and its RGB values, for instance like this: I like to create a color dictionary from this file that looks like this: How can I best do that? |
| ||
| Re: Color Dictionary If the data are packaged as neatly as your file shows, then I would recommend using .split() and then eval() to convert the parenthesized string to a tuple: [php] f = open("my_data") colors = {} for line in f: line = line.strip('\n') name, value = line.split(' RGB ') colors[name] = eval(value) # converts string to tuple [/php] Jeff |
| ||
| Re: Color Dictionary Jeff, thanks. I had to change the split separator from ' RGB ' to ' RGB' to make it work. |
| All times are GMT -4. The time now is 6:29 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC