User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
python:index [2014/07/19 22:02]
python:index [2014/07/20 17:48]
Line 11: Line 11:
 <​code=python>​ <​code=python>​
 +# use this like a dictonary (d['​thing'​]) OR an object (d.thing)
 +class DictObject(dict):​
 +    def __getattribute__(self,​k):​ return self[k]
 +    def __setattribute__(self,​k,​v):​ self[k]=v
 from datetime import datetime from datetime import datetime
 def timestamp():​ return"​%Y%m%d-%H%M%S"​) def timestamp():​ return"​%Y%m%d-%H%M%S"​)
Line 122: Line 128:
 <​code=python>​ <​code=python>​
 def recognize_type(v):​ def recognize_type(v):​
-    ​if re.match(r'​\d+$',​v): +    ​try: return float(v) 
-        return int(v) +    except ValueErrorpass 
-    ​if re.match(r'​\d+\.\d*$',​v)+     
-        ​return float(v)+    try: return int(v) 
 +    ​except ValueErrorpass 
     return v     return v
     ​     ​
python/index.txt · Last modified: 2014/07/20 17:48 by tkbletsc