-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.py
38 lines (25 loc) · 844 Bytes
/
misc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import collections
class curry:
"""Handles arguments for callback functions."""
def __init__(self, callback, *args, **kw):
self.callback = callback
self.args = args
self.kw = kw
def __call__(self):
return self.callback(*self.args, **self.kw)
def islistlike(listobj):
return isinstance(listobj, (list, tuple, collections.UserList))
def getstarterdir():
return getscriptpath(sys.argv[0])
def getscriptpath(script):
return os.path.dirname(os.path.realpath(script))
def obj2str(obj):
"""For debugging
Get a string, containing the attributes and their values of the
given object.
"""
return "\n".join(f"{attr}\t{getattr(obj, attr)}" for attr in dir(obj))