source: geniuswebcore/geniusweb/utils.py@ 67

Last change on this file since 67 was 67, checked in by Bart Vastenhouw, 3 years ago

Added SAOP and simplerunner to GeniusWebPython. Several minor fixes.

File size: 721 bytes
RevLine 
[67]1'''
2A few simple but often needed tools.
3'''
4from typing import TypeVar, Optional
5
6
7def toStr(d:dict)->str:
8 '''
9 prettyprint dict, using str (not repr) for elements in dict.
10 This tostring function looks similar to how java prints it,
11 '''
12 return "{"+ (", ".join([str(k)+"="+str(v) for (k,v) in d.items()]))+"}"
13
14
15def toTuple(d:dict) -> tuple:
16 '''
17 Converts dict into tuples of tuples. Used mainly to compute hash
18 '''
19 return tuple([(k,v) for (k,v) in d.items()])
20
21T = TypeVar('T')
22def val(v:Optional[T])->T:
23 '''
24 @return the value contained in the optional.
25 Raises exception if the value is None.
26 '''
27 if not v:
28 raise ValueError("Value is not set")
29 return v
Note: See TracBrowser for help on using the repository browser.