How to use the extensions.xlist function in extensions

To help you get started, we’ve selected a few extensions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pannous / tensorflow-ocr / extensions.py View on Github external
def method_missing(xs, name, *args, **kwargs):  # [2.1,4.8].int=[2,5]
		if len(xs) == 0: return None
		try:
			method = getattr(xs.first(), name)
		except:
			# if str(name) in globals():
			method = globals()[str(name)]  # .method(m)
		if not callable(method):
			properties = xlist(map(lambda x: getattr(x, name), xs))
			return xlist(zip(xs, properties))
		# return properties
		return xlist(map(lambda x: method(args, kwargs), xs))  # method bound to x
github pannous / angle / angle / netbase.py View on Github external
# data = codecs.open(file, "r", "utf-8", errors='ignore').read()
		# data = open(file,'rb').read()
		data = open(file).read()
		if not isinstance(data,unicode) and not isinstance(data,str):
			data=data.decode("UTF8", 'ignore')
		# FUCK PY3 !!!  'str' object has no attribute 'decode'
		# 	grr PYTHON MADNESS!!
		# http://stackoverflow.com/questions/5096776/unicode-decodeutf-8-ignore-raising-unicodeencodeerror#5096928
		try:
			# data = json.loads(data)
			data = json.loads(data)
		except Exception as ex:
			print(ex)
			os.remove(file)
			# return Node(id=-666, name="ERROR")
		nodes = extensions.xlist()
		# noinspection PyTypeChecker
		for result in data['results']:
			# print(result)
			node = Node(result)
			nodes.append(node)
			if instances:
				nodes.append(self._all(node.id, False, True, reload))
				nodes.append(node.instances)
		self.caches[name] = nodes
		# find_best(nodes)
		return nodes
github pannous / tensorflow-ocr / extensions.py View on Github external
def examples(self):
		return xlist(self.synsets.flatten.map('hyponyms').flatten().map('words').flatten.uniq.map('to_s'))
github pannous / angle / angle / power_parser.py View on Github external
def drop_comments():
	in_comment_block = False
	in_comment_line = False
	i = 0
	prev = ""
	for token in extensions.xlist(the.tokenstream):
		is_beginning_of_line = token[2][1] == 0  # 1??
		# line = token[4]
		str = token[1]
		token_type = token[0]
		if str == "//" or str == "#":
			x_comment(token)
			in_comment_line = True
		elif str == '\n':
			in_comment_line = False
		elif prev == "*" and str.endswith("/"):
			x_comment(token)
			in_comment_block = False
		elif in_comment_block or in_comment_line:
			x_comment(token)
		elif prev == "/" and str.startswith("*"):
			i = i - 1  # drop prev_token too!!
github pannous / angle / angle / extensions.py View on Github external
def ls(mypath="."):
	from extensions import xlist
	return xlist(os.listdir(expanduser(mypath)))
github pannous / tensorflow-ocr / extensions.py View on Github external
def method_missing(xs, name, *args, **kwargs):  # [2.1,4.8].int=[2,5]
		if len(xs) == 0: return None
		try:
			method = getattr(xs.first(), name)
		except:
			# if str(name) in globals():
			method = globals()[str(name)]  # .method(m)
		if not callable(method):
			properties = xlist(map(lambda x: getattr(x, name), xs))
			return xlist(zip(xs, properties))
		# return properties
		return xlist(map(lambda x: method(args, kwargs), xs))  # method bound to x
github pannous / tensorflow-ocr / extensions.py View on Github external
def item(self, nr):  # -1 AppleScript style ! BUT list[0] !
		return self[xlist(self).fix_int(nr)]
github pannous / tensorflow-ocr / extensions.py View on Github external
def values(self):
		return xlist(map(lambda x: x.value, self).join(", "))  # leave [] which is not compatible with C