473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

PEP-343 - Context Managment variant

Sorry. I was wrong about "global" statement.
Then examples seems to be even more intricate:

def Synhronised(lock,func):
lock.acquire()
try:
func()
finally:
lock.release()
.....
lock=Lock()
def Here_I_work(*a): return 1 # Stub
def asd(a): return a # Stub

def Some():
local_var1=1
local_var2=2
local_var3=[None]
def Work():
local_var3[0]=Here_I_work(local_var1,local_var2,local_var3)
Synhronised(lock,Work)
return asd(local_var3[0])

FileOpenClose Example:

def FileOpenClose(name,mode,func):
f=file(name,mode)
try:
func(f)
finally:
f.close()

.....

def Another(name):
local_var3=[None]
def Work(f):
local_var3[0]=[[x,y(i)] for i in f]
FileOpenClose(name,'r',Work)
return local_var3[0]

Here we must to declare local_var3 as array, though we using it as scalar.

Following is from previous letter (with correction). Please do not be severe, I'm not great programmer
and my English isn't A and even B graduated.

I think it is possible to introduce(internally) block-object in analogy to lambda-object
(and function-object).
It's difference from function:
it has no true self local variables, all global(free) and local variables it steels from outter
scope. And all local vars, introduced in block are really introduced in outter scope
(i think, during parse state). So its global dicts and local dicts are realy corresponding dicts
of outter scope (so, may be block call would be faster than function call. I don't know)

Syntax can be following:

lock=Lock()
def Some():
local_var1=1
local_var2=2
local_var3=3
Synhronised(lock,block):
local_var3=Here_I_work(local_var1,local_var2,local _var3)
return asd(local_var3)

def Another(name):
FileOpenClose(name,'r',block{f}):
local_var3=[[x,y(i)] for i in f]
return local_var3
And here is sample of returning value:

def Foo(context,proc):
context.enter()
try:
res=proc(context.x,context.y)*2
except Exception,Err:
context.throw(Err)
finally:
context.exit()
return res
....
context=MyContext()
....
def Bar():
result=Foo(context,block{x,y}):
continue x+y
return result

The idea was stolen from Ruby. My be it is not Pythonic.

Aug 5 '05 #1
0 1450

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christoph Becker-Freyseng | last post by:
Hello, recently there was a lot discussion about a new Path-class. So Gerrit Holl started to write a pre-PEP http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html We tried to...
45
by: Edward K. Ream | last post by:
Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently...
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
0
by: Nick Coghlan | last post by:
Anyone playing with the CPython interpreter's new command line switch might have noticed that it only works with top-level modules (i.e. scripts that are directly on sys.path). If the script is...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
8
by: Micah Elliott | last post by:
I also have this living as a wiki <http://tracos.org/codetag/wiki/Pep> if people would like to add comments there. I might try to capture there feedback from this group anyway. First try at a PEP...
2
by: Bryan Olson | last post by:
Though I tried to submit a (pre-) PEP in the proper form through the proper channels, it has disappeared into the ether. In building a class that supports Python's slicing interface, ...
77
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the...
4
by: dustin | last post by:
I've been hacking away on this PEP for a while, and there has been some related discussion on python-dev that went into the PEP: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.