A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-May/053204.html below:

[Python-Dev] Generating nested data structures with blocks

[Python-Dev] Generating nested data structures with blocks [Python-Dev] Generating nested data structures with blocksWalter Dörwald walter at livinglogic.de
Mon May 2 18:06:58 CEST 2005
Reading PEP 340, it seems to me that blocks could be used for generating 
nested data structures:

def blist(list):
	def enter(parent=None):
		if parent:
			parent.append(self)
		yield self

x = blist()
block x.enter() as x:
	x.append(1)
	block blist().enter(x) as x:
		x.append(2)
	x.append(3)

print x

this should print [1, [2], 3]

For this to work, the scope of the block variable has to end with the 
end of the block. Currently the PEP leaves this unspecified.

Bye,
    Walter Dörwald
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4