> I *must* do:
>
> with device_open() as device:
>device.do_something()
>
> Nevertheless, I _need_ to have a class
> where the device is opened in the __init__()
> and used in some methods.
>
> Any ideas?
Perhaps take a look at contextlib.ExitStack and see if you can do something
with it.
Read the Fine context manager documentation.
What “with with_expression as var” does is effectively:
ob = with_expression
var = ob.__enter__()
And then at the end of the with, does a
ob.__exit__()
(With some parameters to __exit__, that could just be None, None, None for the
simplest case).
N
On 26/11/2023 18.50, Dieter Maurer wrote:
Piergiorgio Sartor wrote at 2023-11-25 22:15 +0100:
...
Apparently, the "with" context manager is not usable
in classes, at least not with __init__() & co.
You can use `with` in classes -- with any context manager.
However, you would usually not use `w
On 27/11/23 5:03 pm, Grant Edwards wrote:
I should probably have written "how to fool that into
working when he's not using a 'with' statement"
It should be possible to run the context protocol yourself.
Something like (warning, untested):
class MyDeviceWrapper:
def __init__(self
On 27/11/23 9:03 am, Stefan Ram wrote:
Above, "have" is followed by another verb in "have been",
so it should be eligible for a contraction there!
Yes, "been" is the past participle of 'to be", so "I've been" is
fine.
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
On 2023-11-27, Grant Edwards via Python-list wrote:
> On 2023-11-26, Dieter Maurer via Python-list wrote:
>
>> If you do not have this case (e.g. usually if you open the file
>> in a class's `__init__`), you do not use a context manager.
>
> He knows that. The OP wrote that he wants to use that
On 2023-11-26, Dieter Maurer via Python-list wrote:
> If you do not have this case (e.g. usually if you open the file
> in a class's `__init__`), you do not use a context manager.
He knows that. The OP wrote that he wants to use that can
_only_ be used by a context manager, but he wants that us
Piergiorgio Sartor wrote at 2023-11-25 22:15 +0100:
> ...
>Apparently, the "with" context manager is not usable
>in classes, at least not with __init__() & co.
You can use `with` in classes -- with any context manager.
However, you would usually not use `with` with a file you have opened
in `__ini
On 24/08/2023 06.11, dn via Python-list wrote:
On 24/08/2023 03.41, Jason Friedman via Python-list wrote:
with Database() as mydb:
conn = mydb.get_connection()
cursor = conn.get_cursor()
cursor.execute("update table1 set x = 1 where y = 2")
cursor.close()
cursor = conn.get_cursor()
cursor.execut
On 24/08/2023 03.41, Jason Friedman via Python-list wrote:
I want to be able to write code like this:
with Database() as mydb:
conn = mydb.get_connection()
cursor = conn.get_cursor()
cursor.execute("update table1 set x = 1 where y = 2")
cursor.close()
cursor = conn.get_cursor()
cursor.execute("u
From: Python-list on
behalf of Rob Gaddi
Sent: Thursday, March 15, 2018 12:47 PM
To: python-list@python.org
Subject: Re: Context manager on method call from class
> from contextlib import contextmanager.
>
> Then you just use the @contextmanager decorator on a function, have it
On 03/15/2018 11:17 AM, Joseph L. Casale wrote:
I have a class which implements a context manager, its __init__
has a signature and the __enter__ returns an instance of the
class.
Along with several methods which implement functionality on
the instance, I have one method which itself must open a
On Fri, Jan 19, 2018 at 5:00 PM, wrote:
> Hello,
>
> Thank you for your mail. I will answer as fast as possible.
If you're going to subscribe to a mailing list, PLEASE disable your
autoresponder.
Otherwise, messages like this will get marked as Spam, and your legit
mail will end up getting tarr
On Fri, 19 Jan 2018 16:49:49 +1100, Chris Angelico wrote:
[...]
> 1) Context manager was called from global scope, and needs access to
> globals() or locals() as returned in the caller
A! /facepalm
Of course the caller can just pass locals() to the context manager. Why
didn't I think o
On Fri, Jan 19, 2018 at 3:48 PM, Steven D'Aprano
wrote:
> I want to define a context manager in one module:
>
> # a.py
> def CM:
> def __enter__(self):
> return self
> def __exit__(self, *args):
> pass
>
>
> Then call it from another module:
>
> # b.py
> import a
> with a.C
> On Feb 3, 2017, at 8:10 AM, Antonio wrote:
>
> From: Antonio
> Sent: Friday, February 3, 2017 1:02 PM
> To: python-list@python.org
> Subject: Context
>
> I have python version 3.6.0 installed into my desktop)windows 7) but the
> menu/context (file,edit..etc) i
On 03/10/2016 07:59 PM, Neal Becker wrote:
sohcahto...@gmail.com wrote:
On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote:
Is there a way to ensure resource cleanup with a construct such as:
x = load (open ('my file', 'rb))
Is there a way to ensure this file gets closed?
Paul Rubin writes:
> Jussi Piitulainen writes:
>> return ModeIO(f.read())
>
> These suggestions involving f.read() assume the file contents are small
> enough to reasonably slurp into memory. That's unlike the original
> where "load" receives a stream and might process it piecewise.
If y
Jussi Piitulainen writes:
> return ModeIO(f.read())
These suggestions involving f.read() assume the file contents are small
enough to reasonably slurp into memory. That's unlike the original
where "load" receives a stream and might process it piecewise.
--
https://mail.python.org/mailma
Chris Angelico writes:
> On Fri, Mar 11, 2016 at 5:33 AM, Neal Becker wrote:
>> Is there a way to ensure resource cleanup with a construct such as:
>>
>> x = load (open ('my file', 'rb))
>>
>> Is there a way to ensure this file gets closed?
>
> Yep!
>
> def read_file(fn, *a, **kw):
> with ope
On Fri, 11 Mar 2016 05:33 am, Neal Becker wrote:
> Is there a way to ensure resource cleanup with a construct such as:
>
> x = load (open ('my file', 'rb))
>
> Is there a way to ensure this file gets closed?
Depends on what you mean by "ensure". Have load() call the file's close
method may be g
On Fri, Mar 11, 2016 at 5:33 AM, Neal Becker wrote:
> Is there a way to ensure resource cleanup with a construct such as:
>
> x = load (open ('my file', 'rb))
>
> Is there a way to ensure this file gets closed?
Yep!
def read_file(fn, *a, **kw):
with open(fn, *a, **kw) as f:
return f.
On 10/03/2016 18:33, Neal Becker wrote:
Is there a way to ensure resource cleanup with a construct such as:
x = load (open ('my file', 'rb))
Is there a way to ensure this file gets closed?
I don't see how there can be. Surely you must split it into two lines
to use the context manager via
On Thu, Mar 10, 2016 at 11:59 AM, Neal Becker wrote:
> sohcahto...@gmail.com wrote:
>
>> On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote:
>>> Is there a way to ensure resource cleanup with a construct such as:
>>>
>>> x = load (open ('my file', 'rb))
>>>
>>> Is there a way to e
sohcahto...@gmail.com wrote:
> On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote:
>> Is there a way to ensure resource cleanup with a construct such as:
>>
>> x = load (open ('my file', 'rb))
>>
>> Is there a way to ensure this file gets closed?
>
> with open('my file', 'rb')
On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote:
> Is there a way to ensure resource cleanup with a construct such as:
>
> x = load (open ('my file', 'rb))
>
> Is there a way to ensure this file gets closed?
with open('my file', 'rb') as f:
x = load(f)
--
https://mail.p
On Sun, 13 Sep 2015 09:27 am, Ned Batchelder wrote:
> On Thursday, September 10, 2015 at 8:44:01 PM UTC-4, Denis McMahon wrote:
>> On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote:
>>
>> > If I did this thing, would people follow me down the street booing and
>> > jeering and throwing th
On Thursday, September 10, 2015 at 8:44:01 PM UTC-4, Denis McMahon wrote:
> On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote:
>
> > If I did this thing, would people follow me down the street booing and
> > jeering and throwing things at me?
>
> Yes
>
> >>> x = func()
> >>> x
> >>> func
On 10/09/2015 18:54, Steven D'Aprano wrote:
I have a function which is intended for use at the interactive interpreter,
but may sometimes be used non-interactively. I wish to change it's output
depending on the context of how it is being called.
If the function is being called as if it were a pr
On Friday, September 11, 2015 at 12:53:28 AM UTC+5:30, Grant Edwards wrote:
> On 2015-09-10, Steven D'Aprano wrote:
>
> > I have a function which is intended for use at the interactive interpreter,
> > but may sometimes be used non-interactively. I wish to change it's output
> > depending on the
On Friday, September 11, 2015 at 12:53:28 AM UTC+5:30, Grant Edwards wrote:
> On 2015-09-10, Steven D'Aprano wrote:
>
> > I have a function which is intended for use at the interactive interpreter,
> > but may sometimes be used non-interactively. I wish to change it's output
> > depending on the
On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote:
> If I did this thing, would people follow me down the street booing and
> jeering and throwing things at me?
Yes
>>> x = func()
>>> x
>>> func()
>>> print x == func()
>>> assert x == func()
Would you expect the last two calls to func(
On Thu, Sep 10, 2015, at 16:15, Akira Li wrote:
> There are cases when it might be justified to alter the behavior e.g.,
> *colorama* allows to strip ANSI codes (e.g., disable colored output) if
> stdout is not a tty or *win-unicode-console* make sys.stdout to use
> WriteConsoleW() to write Unicode
On 2015-09-10, Akira Li <4kir4...@gmail.com> wrote:
> Grant Edwards writes:
>
>> On 2015-09-10, Steven D'Aprano wrote:
>>
>>> I have a function which is intended for use at the interactive interpreter,
>>> but may sometimes be used non-interactively. I wish to change it's output
>>> depending on
Grant Edwards writes:
> On 2015-09-10, Steven D'Aprano wrote:
>
>> I have a function which is intended for use at the interactive interpreter,
>> but may sometimes be used non-interactively. I wish to change it's output
>> depending on the context of how it is being called.
>
> [...]
>
> Sounds
On 2015-09-10, Steven D'Aprano wrote:
> I have a function which is intended for use at the interactive interpreter,
> but may sometimes be used non-interactively. I wish to change it's output
> depending on the context of how it is being called.
[...]
Sounds like an excellent way to waste someb
Steven D'Aprano writes:
> I want the function to know its own context.
> I don't mind if it is CPython only, or if it is a bit expensive.
That sounds crazy but if it's really what you want, you can probably
fake it by examining the control stack using the backtrace module. I
remember doing some
Oops, missing print:
On 10.09.2015 20:45, Sven R. Kunze wrote:
On 10.09.2015 20:34, Sven R. Kunze wrote:
You are right. I turned out to me harder that I first thought.
My initial guess was like: use AST. But now I see, it would be hard
to get the source code.
So, what actually could work, w
On 10.09.2015 20:34, Sven R. Kunze wrote:
You are right. I turned out to me harder that I first thought.
My initial guess was like: use AST. But now I see, it would be hard to
get the source code.
So, what actually could work, would be faking the interactive
interpreter wrapping it up and th
In a message of Fri, 11 Sep 2015 03:54:14 +1000, "Steven D'Aprano" writes:
>def func():
>do_stuff()
>if procedure: # FIXME what goes here???
>return "Awesome"
>else:
>return 999
>
>Now I can do this:
>
>
>x = func()
>assert x == 999
>
>L = [1, 2, func(), 4]
>assert L[2
On Fri, Sep 11, 2015 at 3:54 AM, Steven D'Aprano wrote:
> If the function is being called as if it were a procedure or command, that
> is the return result is just ignored, I want to return one thing. But if it
> is being called where the return result goes somewhere, I want to return
> something
On 10.09.2015 20:14, Ben Finney wrote:
"Sven R. Kunze" writes:
http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode
I'm pretty sure Steven knows full well the answer to that question,
which is not anything like the one he asked. Would you care to read the
question
On 10.09.2015 20:12, Ben Finney wrote:
First thing in the morning I will purchase a head of cabbage and store
it in a warm place to make it rot, on the off chance you find some
obscure way to achieve your benighted goal, just so I can be first in
line to throw it as you pass.
Well, go ahead. An
I need to add: you need to look up the stack to see if you have been
called by __main__ and if __main__.__file__ is missing.
Implementation: I would write decorator for your func.
Best,
Sven
PS: did I say it would probably be a bad idea? If not, it would probably
be a bad idea.
PPS: what is
"Sven R. Kunze" writes:
> http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode
I'm pretty sure Steven knows full well the answer to that question,
which is not anything like the one he asked. Would you care to read the
question he did ask?
--
\ “The optimist
Steven D'Aprano writes:
> I have a function which is intended for use at the interactive
> interpreter, but may sometimes be used non-interactively. I wish to
> change it's output depending on the context of how it is being called.
> […]
>
> x = func()
> assert x == 999
>
> L = [1, 2, func(), 4]
http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode
On 10.09.2015 19:54, Steven D'Aprano wrote:
I have a function which is intended for use at the interactive interpreter,
but may sometimes be used non-interactively. I wish to change it's output
depending on the con
On Sat, Jul 12, 2014 at 8:37 AM, Cameron Simpson wrote:
> On 11Jul2014 14:37, Chris Angelico wrote:
>>
>> Does C-level code have to check this flag before comparing
>> nans,
>
>
> If you mean:
>
> float x, y;
> [...]
> if (x == y) {
> action...
> }
>
> then no.
>
>
>> or is this appli
On 11Jul2014 14:37, Chris Angelico wrote:
On Fri, Jul 11, 2014 at 11:17 AM, Roy Smith wrote:
In article ,
Cameron Simpson wrote:
[... context manager changing NaN comparisons ...]
I'm a bit wary of anything that makes a global, even if temporary,
change to comparisons' behaviours. What hap
On 10Jul2014 17:34, Ethan Furman wrote:
On 07/10/2014 05:20 PM, Cameron Simpson wrote:
Here's an alternative proposal that doesn't involve a new operator.
[snip float-context manager stuff]
Decimal has a context manager like that already (I don't know if it
supports allowing NaNs to equal ea
On Fri, Jul 11, 2014 at 11:17 AM, Roy Smith wrote:
> In article ,
> Cameron Simpson wrote:
>
>> Q: How many user support people does it take to change a light bulb?
>> A: We have an exact copy of the light bulb here and it seems to be
>> working fine. Can you tell me what kind of system you
In article ,
Cameron Simpson wrote:
> Q: How many user support people does it take to change a light bulb?
> A: We have an exact copy of the light bulb here and it seems to be
> working fine. Can you tell me what kind of system you have?
So, what are we talking about here? my_lightbulb ==
On 07/10/2014 05:20 PM, Cameron Simpson wrote:
I posted this the other day and haven't seen a response, not even a scathing
rejection...
Here's an alternative proposal that doesn't involve a new operator.
[snip float-context manager stuff]
Decimal has a context manager like that already (I
On 12/19/2012 09:51 AM, Bart Thate wrote:
> Think of sending JSON over the wire, reconstruct an object with it and then
> let the object figure out what it can and cannot do in this external
> environment.
Probably the better way to do it is to formally define an API that lets
an object discover t
Thanks for your response Chris !
Ha ! the job of the mad man is todo the things the are not "advisable" and
see what gives. Like why it is not advisable and, if possible, their are
ways to achieve things that are previously overseen.
i already do a lot of travelling of the callstack to see from
On Thu, 20 Dec 2012, Chris Angelico wrote:
On Thu, Dec 20, 2012 at 2:57 AM, Bart Thate wrote:
I want in a function or method determine the context of my caller and adapt
the functionality accordingly.
First off, please don't! Your code will be *extremely* confusing.
Usually, the best way to
On Thu, Dec 20, 2012 at 2:57 AM, Bart Thate wrote:
> Hi All !
>
> Is is possible and if yes, is it more easily possible (i am thinking f_back
> maybe) to get the context of the caller when in a function ?
>
> Like to which variable name is this object assigned ?
>
> Or whatever of the callers cont
Hi Ben,
On 31/08/2012 03:36, Ben Finney wrote:
That way, I can set ‘sys.dont_write_bytecode’ to the value I need in
this part of the code, knowing that however the code continues the
previous value of that setting will be restored to whatever it was
before I touched it.
Have I re-invented a con
Peter Otten <__pete...@web.de> writes:
> You should wrap yield in a try ... finally. You might allow setting
> the new value in the manager (untested):
Thank you, both good advice.
I would still like to know if Python already has something to make this
unnecessary.
--
\ “Compulsory unifi
Ben Finney wrote:
> I have written a context manager to save and restore a name binding::
>
> import contextlib
>
> @contextlib.contextmanager
> def preserve_value(namespace, name):
> """ A context manager to preserve, then restore, the specified
> binding.
>
>
Prasad, Ramit wrote:
>> Prasad, Ramit wrote:
>>
>> > So I have a context manager used to catch errors
>> >
>> > def __exit__( self, exceptionClass, exception, tracebackObject ):
>> > if isinstance( exception, self.exceptionClasses ):
>> > #do something here
>> >
>> > Normally excepti
On Thu, Mar 15, 2012 at 2:25 PM, Prasad, Ramit
wrote:
>> > ...
>> > (, "'A' object has no attribute 'x'",
>> )
>> > AttributeError: 'A' object has no attribute 'x'
>> >
>> > As you can see, I am getting a string while you are not.
>>
>>Ian Kelly said:
>> Looks like a version difference. I don't h
> > ...
> > (, "'A' object has no attribute 'x'",
> )
> > AttributeError: 'A' object has no attribute 'x'
> >
> > As you can see, I am getting a string while you are not.
>
>Ian Kelly said:
> Looks like a version difference. I don't have Python 2.6 handy to
> test on, but I get a str in Python 2
On Thu, Mar 15, 2012 at 1:10 PM, Prasad, Ramit
wrote:
>> Prasad, Ramit wrote:
>>
>> > So I have a context manager used to catch errors
>> >
>> > def __exit__( self, exceptionClass, exception, tracebackObject ):
>> > if isinstance( exception, self.exceptionClasses ):
>> > #do something
> Prasad, Ramit wrote:
>
> > So I have a context manager used to catch errors
> >
> > def __exit__( self, exceptionClass, exception, tracebackObject ):
> > if isinstance( exception, self.exceptionClasses ):
> > #do something here
> >
> > Normally exception would be the exception insta
Prasad, Ramit wrote:
> So I have a context manager used to catch errors
>
> def __exit__( self, exceptionClass, exception, tracebackObject ):
> if isinstance( exception, self.exceptionClasses ):
> #do something here
>
> Normally exception would be the exception instance, but for
> A
Terry Reedy wrote:
it is normal to look for special methods on the class (and superclasses)
> of an object rather than starting with the object itself.
I suspect there was a deliberate change to correct an anomaly, though
this might have been done as part of some other change.
It's a necess
On 9/22/2011 6:21 AM, Gavin Panella wrote:
On Python 2.6 and 3.1 the following code works fine:
class Foo(object):
@classmethod
def __enter__(cls):
print("__enter__")
@classmethod
def __exit__(cls, exc_type, exc_value, traceback):
Mel wrote:
> This seems to work:
>
>
>
> class MetaWith (type):
> @classmethod
> def __enter__(cls):
> print("__enter__")
>
> @classmethod
> def __exit__(cls, exc_type, exc_value, traceback):
> print("__exit__")
>
> class With (object):
> __metaclass__ = Met
Gavin Panella wrote:
> Hi,
>
> On Python 2.6 and 3.1 the following code works fine:
>
> class Foo(object):
>
> @classmethod
> def __enter__(cls):
> print("__enter__")
>
> @classmethod
> def __exit__(cls, exc_type, exc_value, traceback):
>
Am 22.09.2011 12:21 schrieb Gavin Panella:
Hi,
On Python 2.6 and 3.1 the following code works fine:
class Foo(object):
@classmethod
def __enter__(cls):
print("__enter__")
@classmethod
def __exit__(cls, exc_type, exc_value, traceback):
On Aug 26, 10:15 am, Carl Banks wrote:
> Well, it wouldn't be a "can I rebind a variable using a with-
> statement" thread if someone didn't post a solution that they thought
> worked, but didn't test it on local variables.
I'm not going to deny it was pretty stupid... though in my defense,
I'm n
On Aug 25, 1:07 pm, Evan Driscoll wrote:
> On Aug 25, 2:33 pm, Evan Driscoll wrote:
>
> > I want to make a context manager that will temporarily change the
> > value of a variable within the scope of a 'with' that uses it. This is
> > inspired by a C++ RAII object I've used in a few projects. Ide
Evan Driscoll schrieb:
On Aug 25, 3:47 pm, Evan Driscoll wrote:
So here is my simplified version that only works for globals:
So I think this works if (1) you only use changed_value in the same
module as it's defined in (otherwise it picks up the globals from the
module it's defined in, which
On Aug 25, 3:47 pm, Evan Driscoll wrote:
> So here is my simplified version that only works for globals:
So I think this works if (1) you only use changed_value in the same
module as it's defined in (otherwise it picks up the globals from the
module it's defined in, which is almost certainly not
On Aug 25, 3:25 pm, "Diez B. Roggisch" wrote:
> Modifying locals isn't really allowed - it might stop working with
> certain implementations of python.
>
> And to be honest - I don't really see a use-case for your whole
> approache. Why don't you want to introduce a new name?
Wow, this actually w
Evan Driscoll schrieb:
On Aug 25, 2:33 pm, Evan Driscoll wrote:
I want to make a context manager that will temporarily change the
value of a variable within the scope of a 'with' that uses it. This is
inspired by a C++ RAII object I've used in a few projects. Ideally,
what I want is something l
On Aug 25, 3:07 pm, Evan Driscoll wrote:
> Okay, so I think I actually got this with some consultation with a
> friend. Critiques?
This is wrong; it's not quite working right. It does with the example
I posted, but not in a more thorough test.
I'm still ignoring the "you can't do this" answers f
Evan Driscoll schrieb:
(If you don't want to read the following, note that you can answer my
question by writing a swap function.)
I want to make a context manager that will temporarily change the
value of a variable within the scope of a 'with' that uses it. This is
inspired by a C++ RAII objec
On Aug 25, 2:33 pm, Evan Driscoll wrote:
> I want to make a context manager that will temporarily change the
> value of a variable within the scope of a 'with' that uses it. This is
> inspired by a C++ RAII object I've used in a few projects. Ideally,
> what I want is something like the following:
On 8/25/2009 12:33 PM Evan Driscoll said...
So my question is: is what I want possible to do in Python?
Probably not with immutables (as in your example) -- maybe otherwise.
Emile
--
http://mail.python.org/mailman/listinfo/python-list
> > If there is a function which triggers a one-shot switch, I like
> > to have a way to find out if it has already been triggered, I
> > prefer to have the function tell me if it triggered the switch
> > or not, but I would not want that to be by raising an exception.
>
> In this case, though, we'
Duncan Booth wrote:
Ben Finney wrote:
MRAB writes:
Gunter Henriksen wrote:
If there is a function which triggers a one-shot switch, I like to
have a way to find out if it has already been triggered, I prefer
to have the function tell me if it triggered the switch or not, but
I would not wa
Gunter Henriksen writes:
> If there is a function which triggers a one-shot switch, I like to
> have a way to find out if it has already been triggered, I prefer to
> have the function tell me if it triggered the switch or not, but I
> would not want that to be by raising an exception.
In this c
Ben Finney wrote:
> MRAB writes:
>
>> Gunter Henriksen wrote:
>> > If there is a function which triggers a one-shot switch, I like to
>> > have a way to find out if it has already been triggered, I prefer
>> > to have the function tell me if it triggered the switch or not, but
>> > I would not
MRAB writes:
> Gunter Henriksen wrote:
> > If there is a function which triggers a one-shot switch, I like to
> > have a way to find out if it has already been triggered, I prefer to
> > have the function tell me if it triggered the switch or not, but I
> > would not want that to be by raising an
Gunter Henriksen wrote:
Anyone else?
If there is a function which triggers a one-shot switch, I
like to have a way to find out if it has already been triggered,
I prefer to have the function tell me if it triggered the switch
or not, but I would not want that to be by raising an exception.
Th
> Anyone else?
If there is a function which triggers a one-shot switch, I
like to have a way to find out if it has already been triggered,
I prefer to have the function tell me if it triggered the switch
or not, but I would not want that to be by raising an exception.
--
http://mail.python.org/ma
Carl Banks writes:
> I don't think this is anything more than a trivial consideration,
Okay, thank you.
Anyone else?
--
\ “All television is educational television. The question is: |
`\ what is it teaching?” —Nicholas Johnson |
_o__)
On May 16, 8:20 pm, Ben Finney wrote:
> Carl Banks writes:
> > There's already precedent for what to do in the Python library.
>
> > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
> > [GCC 4.3.2] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> f = op
Carl Banks writes:
> There's already precedent for what to do in the Python library.
>
> Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> f = open('somefile')
> >>> f.close()
> >>> f.close()
>
On May 16, 5:50 pm, Ben Finney wrote:
> Ideas? How should this be addressed both Pythonically and respecting the
> intent of PEP 3143?
There's already precedent for what to do in the Python library.
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright",
On Mar 26, 1:34 pm, MRAB wrote:
> TP wrote:
> > Hi everybody,
>
> > This example gives strange results:
>
> >
> > def foo( l = [] ):
>
> > l2 = l
> > print l2
> > for i in range(10):
> > if i%2 == 0:
> > l2.append( i )
> > yield i
> >
>
> >
TP wrote:
Hi everybody,
This example gives strange results:
def foo( l = [] ):
l2 = l
print l2
for i in range(10):
if i%2 == 0:
l2.append( i )
yield i
[i for i in ut.foo()]
[]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[i for i in ut.foo()]
[0
Floris Bruynooghe <[EMAIL PROTECTED]>:
> I was wondering when it was worthwil to use context managers for
> file. Consider this example:
>
> def foo():
> t = False
> for line in file('/tmp/foo'):
> if line.startswith('bar'):
> t = True
> break
> return
On Jun 16, 8:24 am, Bruno Desthuilliers wrote:
>
> IIRC (please someone correct me if I'm wrong), proper release of file
> resources as soon as the file object gets out of scope is not garanteed
> in the language spec and is implementation dependant.
Right. Resources are freed in CPython right af
Floris Bruynooghe a écrit :
Hi
I was wondering when it was worthwil to use context managers for
file. Consider this example:
def foo():
t = False
for line in file('/tmp/foo'):
if line.startswith('bar'):
t = True
break
return t
What would the benefit
Laszlo Nagy wrote:
>> I'm still thinking there is a better way to do it, and would
>> appreciate any ideas.
>
> Everything can be implemented with goto and arrays.
But is that really better?
Regards,
Björn
--
BOFH excuse #174:
Backbone adjustment
--
http://mail.python.org/mailman/list
> I'm still thinking there is a better way to do it, and would appreciate
> any ideas.
>
Everything can be implemented with goto and arrays.
http://entrian.com/goto/
:-P
--
http://mail.python.org/mailman/listinfo/python-list
Jean-Paul Calderone wrote:
> On 12 Jan 2007 06:17:01 -0800, [EMAIL PROTECTED] wrote:
> >I'm happily using context managers and co-routines, and would like to
> >use both at the same time, e.g.
>
> Python has generators, not co-routines.
They may be called generators, but I'm using them as co-routi
1 - 100 of 101 matches
Mail list logo