Re: Evaluation of variable as f-string

2023-02-07 Thread Chris Angelico
On Wed, 8 Feb 2023 at 05:30, Stefan Ram wrote: > > Rob Cliffe writes: > >Does that mean that it is not possible to have a (built-in) function > >that would construct and return a dictionary of all available variables > >and their values? If it were possible, it could be useful, and there > >woul

Re: Evaluation of variable as f-string

2023-02-07 Thread Chris Angelico
On Wed, 8 Feb 2023 at 02:12, Rob Cliffe wrote: > > [re-sending this to both the list and to Chris, as a prior send to the > list only was bounced back] > On 31/01/2023 22:33, Chris Angelico wrote: > > > >> Thanks for clarifying. > >> Hm. So 'x' is neither in locals() nor in globals(). Which star

Re: Evaluation of variable as f-string

2023-02-07 Thread Rob Cliffe via Python-list
[re-sending this to both the list and to Chris, as a prior send to the list only was bounced back] On 31/01/2023 22:33, Chris Angelico wrote: Thanks for clarifying. Hm. So 'x' is neither in locals() nor in globals(). Which starts me wondering (to go off on a tangent): Should there be a nonlo

Re: Evaluation of variable as f-string

2023-01-31 Thread Chris Angelico
On Wed, 1 Feb 2023 at 09:14, Rob Cliffe via Python-list wrote: > With great respect, Chris, isn't it for the OP (or anyone else) to > decide - having been warned of the various drawbacks and limitations - > to decide if it's a terrible idea *for him*? He's entitled to decide > that it's just what

Re: Evaluation of variable as f-string

2023-01-31 Thread Rob Cliffe via Python-list
On 27/01/2023 23:41, Chris Angelico wrote: On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list wrote: Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. The exact same points have already been made, but not listened to.

Re: Evaluation of variable as f-string

2023-01-29 Thread Peter J. Holzer
On 2023-01-29 10:18:00 +0100, Johannes Bauer wrote: > Am 29.01.23 um 05:27 schrieb Thomas Passin: > > IOW, perhaps there is a more practical way to accomplish what you want. > > Except that we don't know what that is. > > Well, I don't know. I pretty much want a generic Python mechanism that > all

Re: Evaluation of variable as f-string

2023-01-29 Thread Thomas Passin
On 1/29/2023 6:09 AM, Christian Gollwitzer wrote: Am 28.01.23 um 02:56 schrieb Thomas Passin: On 1/27/2023 5:10 PM, Christian Gollwitzer wrote: Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angril

Re: Evaluation of variable as f-string

2023-01-29 Thread Johannes Bauer
Am 29.01.23 um 05:27 schrieb Thomas Passin: Well, yes, we do see that.  What we don't see is what you want to accomplish by doing it, and why you don't seem willing to accept some restrictions on the string fragments so that they will evaluate correctly. I'll have to accept the restrictions.

Re: Evaluation of variable as f-string

2023-01-29 Thread Christian Gollwitzer
Am 28.01.23 um 02:56 schrieb Thomas Passin: On 1/27/2023 5:10 PM, Christian Gollwitzer wrote: Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not:

Re: Evaluation of variable as f-string

2023-01-29 Thread Johannes Bauer
Am 29.01.23 um 02:09 schrieb Chris Angelico: The exact same points have already been made, but not listened to. Sometimes, forceful language is required in order to get people to listen. An arrogant bully's rationale. Personally, I'm fine with it. I've been to Usenet for a long time, in which

To gateway or not to gateway a specific person (was: Evaluation of variable as f-string)

2023-01-29 Thread Peter J. Holzer
On 2023-01-29 15:47:47 +1100, Chris Angelico wrote: > On Sun, 29 Jan 2023 at 14:36, Stefan Ram wrote: > > (This message was written for Usenet. If you read it in a > > mailing list or the Web, it has been stolen from Usenet.) > > I'm curious as to the copyright protections available to you, b

Re: Evaluation of variable as f-string

2023-01-28 Thread Thomas Passin
On 1/28/2023 2:50 PM, Johannes Bauer wrote: Am 28.01.23 um 02:51 schrieb Thomas Passin: This is literally the version I described myself, except using triple quotes. It only modifies the underlying problem, but doesn't solve it. Ok, so now we are in the territory of "Tell us what you are tryi

Re: Evaluation of variable as f-string

2023-01-28 Thread Chris Angelico
On Sun, 29 Jan 2023 at 14:36, Stefan Ram wrote: > > Johannes Bauer writes: > >I have a string. I want to evaluate it as if it were an f-string. I.e., > >there *are* obviously restrictions that apply (namely, the syntax and > >semantics of f-strings), but that's it. > > (This message was written

Re: Evaluation of variable as f-string

2023-01-28 Thread Chris Angelico
On Sun, 29 Jan 2023 at 11:56, Johannes Bauer wrote: > > Am 28.01.23 um 00:41 schrieb Chris Angelico: > > On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list > > wrote: > >> > >> Whoa! Whoa! Whoa! > >> I appreciate the points you are making, Chris, but I am a bit taken > >> aback by such forc

Re: Evaluation of variable as f-string

2023-01-28 Thread Chris Angelico
On Sun, 29 Jan 2023 at 11:53, Johannes Bauer wrote: > I don't want to have to care about what quotation is used inside the > string, as long as it could successfully evaluate using the f-string > grammar. > Not possible. An f-string can contain other f-strings, and it is entirely possible to use

Re: Evaluation of variable as f-string

2023-01-28 Thread Johannes Bauer
Am 27.01.23 um 23:10 schrieb Christian Gollwitzer: Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not: x = { "y": "z" } s = "-> {x['y']}" print(s

Re: Evaluation of variable as f-string

2023-01-28 Thread Johannes Bauer
Am 28.01.23 um 00:41 schrieb Chris Angelico: On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list wrote: Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. The exact same points have already been made, but not listened t

Re: Evaluation of variable as f-string

2023-01-28 Thread Johannes Bauer
Am 28.01.23 um 02:51 schrieb Thomas Passin: This is literally the version I described myself, except using triple quotes. It only modifies the underlying problem, but doesn't solve it. Ok, so now we are in the territory of "Tell us what you are trying to accomplish". And part of that is why y

Re: Evaluation of variable as f-string

2023-01-28 Thread Peter J. Holzer
On 2023-01-27 21:31:05 +0100, Johannes Bauer wrote: > > But if you really REALLY know what you're doing, just use eval() > > directly. > > I do, actually, but I hate it. Not because of the security issue, not > because of namespaces, but because it does not reliably work: > > >>> s = "{\"x\" * 4}

Re: Evaluation of variable as f-string

2023-01-28 Thread Peter J. Holzer
On 2023-01-27 21:43:09 +0100, Johannes Bauer wrote: > x = { "y": "z" } > s = "-> {x['y']}" > print(s.format(x = x)) > Traceback (most recent call last): > File "", line 1, in > KeyError: "'y'" > > This. Does. Not. Work. > > I want to pass a single variable as a dictionary and access its member

Re: Evaluation of variable as f-string

2023-01-28 Thread Peter J. Holzer
On 2023-01-27 20:56:49 -0500, Thomas Passin wrote: > On 1/27/2023 5:10 PM, Christian Gollwitzer wrote: > > Am 27.01.23 um 21:43 schrieb Johannes Bauer: > > > x = { "y": "z" } > > > s = "-> {x['y']}" > > > print(s.format(x = x)) > > > Traceback (most recent call last): > > >    File "", line 1, in

RE: Evaluation of variable as f-string

2023-01-27 Thread avi.e.gross
-Original Message- From: Python-list On Behalf Of Stefan Ram Sent: Friday, January 27, 2023 4:31 PM To: python-list@python.org Subject: Re: Evaluation of variable as f-string Johannes Bauer writes: >>Johannes Bauer writes: >>>x = { "y": "z" } >>>s =

Re: Evaluation of variable as f-string

2023-01-27 Thread Thomas Passin
On 1/27/2023 5:10 PM, Christian Gollwitzer wrote: Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not: x = { "y": "z" } s = "-> {x['y']}" print(s.

Re: Evaluation of variable as f-string

2023-01-27 Thread Thomas Passin
On 1/27/2023 3:33 PM, Johannes Bauer wrote: Am 25.01.23 um 20:38 schrieb Thomas Passin: x = { "y": "z" } s = "-> {target}" print(s.format(target = x['y'])) Stack overflow to the rescue: No. Search phrase:  "python evaluate string as fstring" https://stackoverflow.com/questions/47339121/h

Re: Evaluation of variable as f-string

2023-01-27 Thread Christian Gollwitzer
Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not: x = { "y": "z" } s = "-> {x['y']}" print(s.format(x = x)) Traceback (most recent call last):

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 27.01.23 um 20:18 schrieb Chris Angelico: All you tell us is what you're attempting to do, which there is *no good way to achieve*. Fair enough, that is the answer. It's not possible. Perhaps someone will be inspired to write a function to do it. 😎 See, we don't know what "it" is, so it

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 23.01.23 um 17:43 schrieb Stefan Ram: Johannes Bauer writes: x = { "y": "z" } s = "-> {x['y']}" print(s.format(x = x)) x = { "y": "z" } def s( x ): return '-> ' + x[ 'y' ] print( s( x = x )) Except this is not at all what I asked for. The string "s" in my example is just that, an exampl

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
Am 25.01.23 um 20:38 schrieb Thomas Passin: x = { "y": "z" } s = "-> {target}" print(s.format(target = x['y'])) Stack overflow to the rescue: No. Search phrase:  "python evaluate string as fstring" https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string de

Re: Evaluation of variable as f-string

2023-01-27 Thread Johannes Bauer
members in there. x = { "y": "z" } s = "-> {x['y']}" print(s.format(x = x)) Traceback (most recent call last): File "", line 1, in KeyError: "'y'" I also want to be able to say things like {'x' * 100}, which .for

Re: Evaluation of variable as f-string

2023-01-27 Thread Thomas Passin
On 1/27/2023 5:54 PM, Rob Cliffe via Python-list wrote: Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. I generally agree with asking for what the intent is. In this case it seems pretty clear that the OP wants to use the

Re: Evaluation of variable as f-string

2023-01-27 Thread Chris Angelico
On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list wrote: > > Whoa! Whoa! Whoa! > I appreciate the points you are making, Chris, but I am a bit taken > aback by such forceful language. The exact same points have already been made, but not listened to. Sometimes, forceful language is require

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. On 27/01/2023 19:18, Chris Angelico wrote: On Sat, 28 Jan 2023 at 05:31, Rob Cliffe via Python-list wrote: On 23/01/2023 18:02, Chris Angelico wrote: Maybe, rather than ask

Re: Evaluation of variable as f-string

2023-01-27 Thread Chris Angelico
On Sat, 28 Jan 2023 at 05:31, Rob Cliffe via Python-list wrote: > On 23/01/2023 18:02, Chris Angelico wrote: > > Maybe, rather than asking for a way to treat a string as code, ask for > > what you ACTUALLY need, and we can help? > > > > ChrisA > Fair enough, Chris, but still ISTM that it is reason

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
On 23/01/2023 18:02, Chris Angelico wrote: On Tue, 24 Jan 2023 at 04:56, Johannes Bauer wrote: Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? ... This is supposedly for security reasons. However, when trying to emulate this be

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
On 25/01/2023 19:38, Thomas Passin wrote: Stack overflow to the rescue: Search phrase:  "python evaluate string as fstring" https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string def effify(non_f_str: str):     return eval(f'f"""{non_f_str}"""') print(ef

Re: Evaluation of variable as f-string

2023-01-25 Thread Thomas Passin
On 1/25/2023 1:26 PM, Antoon Pardon wrote: Op 23/01/2023 om 17:24 schreef Johannes Bauer: Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? I.e., what I want is to be able to do this: x = { "y": "z" } print(f"-> {x['y']}") This p

Re: Evaluation of variable as f-string

2023-01-25 Thread Antoon Pardon
Op 23/01/2023 om 17:24 schreef Johannes Bauer: Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? I.e., what I want is to be able to do this: x = { "y": "z" } print(f"-> {x['y']}") This prints "-> z", as expected. But consider: x

Re: Evaluation of variable as f-string

2023-01-23 Thread Chris Angelico
On Tue, 24 Jan 2023 at 04:56, Johannes Bauer wrote: > > Hi there, > > is there an easy way to evaluate a string stored in a variable as if it > were an f-string at runtime? > > ... > > This is supposedly for security reasons. However, when trying to emulate > this behavior that I wanted (and know

Evaluation of variable as f-string

2023-01-23 Thread Johannes Bauer
Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? I.e., what I want is to be able to do this: x = { "y": "z" } print(f"-> {x['y']}") This prints "-> z", as expected. But consider: x = { "y": "z" } s = "-> {x['y']}" print(s.format(

Re: ANN: JavaScrypthon 0.5, now with embedded evaluation of transpiled code

2016-11-28 Thread Eric S. Johansson
On 11/28/2016 2:02 PM, Amirouche Boubekki wrote: > Also, FWIW users are looking for a Javascript replacement that is real > Python, not another coffeescript. does this count? http://brython.info/ -- https://mail.python.org/mailman/listinfo/python-list

Re: ANN: JavaScrypthon 0.5, now with embedded evaluation of transpiled code

2016-11-28 Thread Amirouche Boubekki
On Sat, Nov 26, 2016 at 7:21 PM Alberto Berti < azazel+python-annou...@arstecnica.it> wrote: > Hi all, > Héllo! > i'm pleased to announce that JavaScripthon 0.5 has been released to > PyPI. JavaScrypthon can translate a subset of Python 3.5 code to ES6 > JavaScript producing beautiful and lean

Re: List comprehensions and evaluation of elements therein

2015-09-23 Thread Ian Kelly
On Wed, Sep 23, 2015 at 12:12 PM, James Harris wrote: > A list comprehension has various components. Anyone know when each of the > elements is evaluated? In the form > > [v0 for v0 in expr0 if expr1] > > If v0 appears in expr0 or expr1 the evaluation order matters. > > I think of the above as be

List comprehensions and evaluation of elements therein

2015-09-23 Thread James Harris
A list comprehension has various components. Anyone know when each of the elements is evaluated? In the form [v0 for v0 in expr0 if expr1] If v0 appears in expr0 or expr1 the evaluation order matters. I think of the above as being a rewrite of results = [] for v0 in expr0: if expr1:

Re: Delayed evaluation of expressions

2014-03-26 Thread Rustom Mody
On Thursday, March 27, 2014 4:15:19 AM UTC+5:30, Marko Rauhamaa wrote: > Chris Angelico : > > You prove here that Python has first-class expressions in the same way > > that 80x86 assembly language has garbage collection. Sure, you can > > implement it using the primitives you have, but that's not

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Steven D'Aprano
ducing delayed evaluation to the discussion. But having raised it, I do think it is an important and useful feature. Python already has it in various ad hoc places, such as list comps and generator expressions, ternary if, and/or, and it came up again recently in the PEP for try...except express

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Rustom Mody
On Thursday, March 27, 2014 5:13:21 AM UTC+5:30, Steven D'Aprano wrote: > On Thu, 27 Mar 2014 09:24:49 +1100, Chris Angelico wrote: > > wrote: > >> Now actual python > >> def sumjensen(i_get, i_set,lower,upper,exp): > >> tot = 0 > >> i_set(lower) > >> while i_get() <= upper: > >>

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Terry Reedy
I agree that we have not been understanding each other. From you original post that I responded to: The thing is, we can't just create a ∑ function, because it doesn't work the way the summation operator works. The problem is that we would want syntactic support, so we could write something like

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Steven D'Aprano
On Thu, 27 Mar 2014 09:24:49 +1100, Chris Angelico wrote: > On Thu, Mar 27, 2014 at 4:32 AM, Rustom Mody > wrote: >> Now actual python >> >> def sumjensen(i_get, i_set,lower,upper,exp): >> tot = 0 >> i_set(lower) >> while i_get() <= upper: >> tot += exp_get() >> i_set(

Re: Delayed evaluation of expressions

2014-03-26 Thread Marko Rauhamaa
Chris Angelico : > You prove here that Python has first-class expressions in the same way > that 80x86 assembly language has garbage collection. Sure, you can > implement it using the primitives you have, but that's not support. I was more reminded of STL and Boost. For example: std::for_each

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Chris Angelico
On Thu, Mar 27, 2014 at 4:32 AM, Rustom Mody wrote: > Now actual python > > def sumjensen(i_get, i_set,lower,upper,exp): > tot = 0 > i_set(lower) > while i_get() <= upper: > tot += exp_get() > i_set(i_get() + 1) > return tot > > > i=0 > a=[3,4,5] > i_get = lambda :

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Rustom Mody
On Wednesday, March 26, 2014 11:02:04 PM UTC+5:30, Rustom Mody wrote: > On Wednesday, March 26, 2014 9:35:53 PM UTC+5:30, Steven D'Aprano wrote: > > On Wed, 26 Mar 2014 00:30:21 -0400, Terry Reedy wrote: > > > One passes an unquoted expression in code by quoting it with either > > > lambda, paired

Re: Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Rustom Mody
On Wednesday, March 26, 2014 9:35:53 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 26 Mar 2014 00:30:21 -0400, Terry Reedy wrote: > > On 3/25/2014 8:12 PM, Steven D'Aprano wrote: > >> On Tue, 25 Mar 2014 19:55:39 -0400, Terry Reedy wrote: > >>> On 3/25/2014 11:18 AM, Steven D'Aprano wrote: >

Delayed evaluation of expressions [was Re: Time we switched to unicode?]

2014-03-26 Thread Steven D'Aprano
ation detail, not a language requirement, and it doesn't apply to all delayed expressions: py> dis("1/x if x else y") 1 0 LOAD_NAME0 (x) 3 POP_JUMP_IF_FALSE 14 6 LOAD_CONST 0 (1) 9 LOAD_NAME

Re: lazy evaluation of a variable

2012-06-18 Thread rantingrickjohnson
On Sunday, June 17, 2012 6:01:03 PM UTC-5, Steven D'Aprano wrote: > One day, in my Copious Spare Time, I intend to write a proper feature > request and/or PEP for such a feature. Obviously the absolute earliest > such a feature could be introduced is Python 3.4, about 18 months from > now. (Alt

Re: lazy evaluation of a variable

2012-06-18 Thread Gelonida N
On 06/17/2012 11:35 PM, Gelonida N wrote: Hi, I'm not sure whether what I ask for is impossible, but would know how others handle such situations. I'm having a module, which should lazily evaluate one of it's variables. Meaning that it is evaluated only if anybody tries to use this variable.

Re: lazy evaluation of a variable

2012-06-17 Thread Terry Reedy
On 6/17/2012 5:35 PM, Gelonida N wrote: I'm having a module, which should lazily evaluate one of it's variables. If you literally mean a module object, that is not possible. On the other hand, it is easy to do with class instances, via the __getattr__ special method or via properties. At

Re: lazy evaluation of a variable

2012-06-17 Thread Jose H. Martinez
Another option would be to refactor your function so that it is a generator expression using the yield keyword. On Sun, Jun 17, 2012 at 7:40 PM, Peter Otten <__pete...@web.de> wrote: > Gelonida N wrote: > > > I'm having a module, which should lazily evaluate one of it's variables. > > Meaning th

Re: lazy evaluation of a variable

2012-06-17 Thread Peter Otten
Gelonida N wrote: > I'm having a module, which should lazily evaluate one of it's variables. > Meaning that it is evaluated only if anybody tries to use this variable. > > At the moment I don't know how to do this and do therefore following: > > > ### mymodule.py ### > var = None > > d

Re: lazy evaluation of a variable

2012-06-17 Thread Steven D'Aprano
On Mon, 18 Jun 2012 07:44:47 +1000, Cameron Simpson wrote: > On 17Jun2012 23:35, Gelonida N wrote: | I'm having > a module, which should lazily evaluate one of it's variables. | Meaning > that it is evaluated only if anybody tries to use this variable. > > If it were an object member you could u

Re: lazy evaluation of a variable

2012-06-17 Thread Cameron Simpson
On 17Jun2012 23:35, Gelonida N wrote: | I'm having a module, which should lazily evaluate one of it's variables. | Meaning that it is evaluated only if anybody tries to use this variable. If it were an object member you could use a property. Does it need to be a module global? In related news, c

lazy evaluation of a variable

2012-06-17 Thread Gelonida N
Hi, I'm not sure whether what I ask for is impossible, but would know how others handle such situations. I'm having a module, which should lazily evaluate one of it's variables. Meaning that it is evaluated only if anybody tries to use this variable. At the moment I don't know how to do thi

Re: Postpone evaluation of argument

2012-02-11 Thread 88888 Dihedral
在 2012年2月11日星期六UTC+8上午7时57分56秒,Paul Rubin写道: > Righard van Roy > writes: > > I want to add an item to a list, except if the evaluation of that item > > results in an exception. > > This may be overkill and probably slow, but perhaps most in the spirit > that y

Re: Postpone evaluation of argument

2012-02-11 Thread Jussi Piitulainen
Righard van Roy writes: > Hello, > > I want to add an item to a list, except if the evaluation of that item > results in an exception. > I could do that like this: > > def r(x): > if x > 3: > raise(ValueError) > > try: > list.

Re: Postpone evaluation of argument

2012-02-10 Thread Paul Rubin
Righard van Roy writes: > I want to add an item to a list, except if the evaluation of that item > results in an exception. This may be overkill and probably slow, but perhaps most in the spirit that you're asking. from itertools import chain def r(x):

Re: Postpone evaluation of argument

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 3:01 PM, Righard van Roy wrote: > Hello, > > I want to add an item to a list, except if the evaluation of that item > results in an exception. > I could do that like this: > > def r(x): >    if x > 3: >        raise(ValueError) > >

Postpone evaluation of argument

2012-02-10 Thread Righard van Roy
Hello, I want to add an item to a list, except if the evaluation of that item results in an exception. I could do that like this: def r(x): if x > 3: raise(ValueError) try: list.append(r(1)) except: pass try: list.append(r(5)) except: pass This looks rather clum

Re: Compile time evaluation of dictionaries

2011-03-14 Thread Terry Reedy
On 3/14/2011 10:21 AM, Gerald Britton wrote: Any idea why Python works this way? I see that, in 3.2, an optimization was done for sets (See "Optimizations" at http://docs.python.org/py3k/whatsnew/3.2.html) though I do not see anything similar for dictionaries. 1/ because no one would ever s

Compile time evaluation of dictionaries

2011-03-14 Thread Gerald Britton
Jean-Michel Pichavan wrote: >> Today I noticed that an expression like this: >> >> "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": >> "can be as bad as one"} >> >> could be evaluated at compile time, but is not: >> >> [snip] >> Any idea why Python works this way? I see that,

Re: Compile time evaluation of dictionaries

2011-03-14 Thread Jean-Michel Pichavant
Gerald Britton wrote: Today I noticed that an expression like this: "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": "can be as bad as one"} could be evaluated at compile time, but is not: dis(compile( ... '"one:%(one)s two:%(two)s" % {"one": "is the lonelies

Re: Compile time evaluation of dictionaries

2011-03-11 Thread Steven D'Aprano
On Thu, 10 Mar 2011 11:23:32 -0500, Gerald Britton wrote: > Today I noticed that an expression like this: > > "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": > "can be as bad as one"} > > could be evaluated at compile time, but is not: [...] > Any idea why Python works this

Re: Compile time evaluation of dictionaries

2011-03-11 Thread John Nagle
On 3/10/2011 8:23 AM, Gerald Britton wrote: Today I noticed that an expression like this: "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": "can be as bad as one"} could be evaluated at compile time, but is not: CPython barely evaluates anything at compile time.

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Steven D'Aprano
On Thu, 10 Mar 2011 16:27:17 -0800, Chris Rebert wrote: > 3. %-formatting is "obsolete and may go away in future versions of > Python." (See > http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting- operations > ) There is an awful lot of opposition to that. If it ever happens,

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Chris Rebert
On Thu, Mar 10, 2011 at 4:15 PM, Steven D'Aprano wrote: > On Thu, 10 Mar 2011 17:40:40 -0500, Terry Reedy wrote: >> On 3/10/2011 11:23 AM, Gerald Britton wrote: >>> Today I noticed that an expression like this: >>> >>> "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": >>> "can

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Steven D'Aprano
On Thu, 10 Mar 2011 17:40:40 -0500, Terry Reedy wrote: > On 3/10/2011 11:23 AM, Gerald Britton wrote: >> Today I noticed that an expression like this: >> >> "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": >> "can be as bad as one"} >> >> could be evaluated at compile time, bu

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Terry Reedy
On 3/10/2011 11:23 AM, Gerald Britton wrote: Today I noticed that an expression like this: "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": "can be as bad as one"} could be evaluated at compile time, but is not: In fact, it could be evaluated at writing time ;-). This wou

Compile time evaluation of dictionaries

2011-03-10 Thread Gerald Britton
Today I noticed that an expression like this: "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": "can be as bad as one"} could be evaluated at compile time, but is not: >>> dis(compile( ... '"one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": "can be as bad a

using trace to do 'in place' evaluation of variables

2010-12-07 Thread Edward Peschko
All, I've been using the trace module for python (as per http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html), and would very much like to have a feature there that I've implemented for perl already. Namely, I would like output in the format as described on t

Re: Performance evaluation of HTTPS library

2010-10-14 Thread Antoine Pitrou
On Thu, 14 Oct 2010 05:06:30 -0700 (PDT) Ashish wrote: > > One more question: If I run the tool from multicore machine, will > python3.1 or 3.2 be able to actually use multicore? or it will be > running only on one core? Only partly. Pure Python code is serialized (by the Global Interpreter Lock

Re: Performance evaluation of HTTPS library

2010-10-14 Thread Ashish
On Oct 13, 6:12 pm, Antoine Pitrou wrote: > On Wed, 13 Oct 2010 05:27:29 -0700 (PDT)Ashish wrote: > > > Well, CBSocket is socket implementation that calls my callback on > > data. > > Both my classes AsyncHTTPSConnection and AsyncHTTPConnection use it > > and use it the same way ( self.sock = CBS

Re: Performance evaluation of HTTPS library

2010-10-13 Thread Antoine Pitrou
On Wed, 13 Oct 2010 05:27:29 -0700 (PDT) Ashish wrote: > > Well, CBSocket is socket implementation that calls my callback on > data. > Both my classes AsyncHTTPSConnection and AsyncHTTPConnection use it > and use it the same way ( self.sock = CBSocket(sock2) ). > The implemetation of AsyncHTTPCon

Re: Performance evaluation of HTTPS library

2010-10-13 Thread Ashish
On Oct 13, 3:19 pm, Antoine Pitrou wrote: > On Wed, 13 Oct 2010 02:12:21 -0700 (PDT) > > Ashish wrote: > > > > > Is the client machine at 100% CPU when you do that? > > > > With HTTP, I see client CPU at appx. 97%. However with HTTPS, it stays > > > at 53-55%. > > And is the server at 100% CPU th

Re: Performance evaluation of HTTPS library

2010-10-13 Thread Ashish
On Oct 13, 2:36 pm, Stefan Behnel wrote: > Ashish Vyas, 12.10.2010 14:40: > > > When I send request using HTTP, I am able to reach 1 transaction (request > > sent, > > response rcvd and validated.) per second from 20 parallel connections > > easily. > > Average response time shown is about 0.15

Re: Performance evaluation of HTTPS library

2010-10-13 Thread Antoine Pitrou
On Wed, 13 Oct 2010 02:12:21 -0700 (PDT) Ashish wrote: > > > > > Is the client machine at 100% CPU when you do that? > > > > With HTTP, I see client CPU at appx. 97%. However with HTTPS, it stays > > at 53-55%. And is the server at 100% CPU then? If the client is not at 100% CPU, it shouldn't be

Re: Performance evaluation of HTTPS library

2010-10-13 Thread Stefan Behnel
Ashish Vyas, 12.10.2010 14:40: When I send request using HTTP, I am able to reach 1 transaction (request sent, response rcvd and validated.) per second from 20 parallel connections easily. Average response time shown is about 0.15 seconds. However, when I send request using HTTPS, I am seeing tha

Re: Performance evaluation of HTTPS library

2010-10-13 Thread Ashish
On Oct 13, 11:11 am, Ashish wrote: > On Oct 12, 6:33 pm, Antoine Pitrou wrote:> On Tue, 12 > Oct 2010 05:40:43 -0700 (PDT) > > > Ashish Vyas wrote: > > > Another observation that I have made is with 10 parallel HTTPS connection > > > each > > > trying 1 transaction per second from 2 different

Re: Performance evaluation of HTTPS library

2010-10-12 Thread Ashish
On Oct 12, 6:33 pm, Antoine Pitrou wrote: > On Tue, 12 Oct 2010 05:40:43 -0700 (PDT) > > Ashish Vyas wrote: > > Another observation that I have made is with 10 parallel HTTPS connection > > each > > trying 1 transaction per second from 2 different machines (effectively same > > load > > on serv

Re: Performance evaluation of HTTPS library

2010-10-12 Thread Antoine Pitrou
On Tue, 12 Oct 2010 05:40:43 -0700 (PDT) Ashish Vyas wrote: > > I have made a tool for load testing of my company's web-server product. The > tool > is written using Python 3.1. > [...] > > So I feel HTTPS is blocking my test if I want to achieve higher TPS > (transactions per second.) than

Re: Performance evaluation of HTTPS library

2010-10-12 Thread Antoine Pitrou
On Tue, 12 Oct 2010 05:40:43 -0700 (PDT) Ashish Vyas wrote: > Another observation that I have made is with 10 parallel HTTPS connection > each > trying 1 transaction per second from 2 different machines (effectively same > load > on server), the response time is again reducing to .17 secs. > H

Performance evaluation of HTTPS library

2010-10-12 Thread Ashish Vyas
Hi All I have made a tool for load testing of my company's web-server product. The tool is written using Python 3.1. The tool basically does a HTTP or HTTPS post, gets response and parses the response, does the response validation against expected response and maintains the stats of average

Re: remote evaluation of Python code typed in html webpage frame

2010-01-16 Thread André
On Jan 15, 11:47 am, dmitrey wrote: > Thank you for the link, but I meant what is appropriate soft to be > installed on my server to do things like that. > Also, for my purposes it's better to have some text with possibility > of reexecuting after some minor code changes than python interpreter >

Re: remote evaluation of Python code typed in html webpage frame

2010-01-16 Thread r0g
Anand Vaidya wrote: > On Jan 16, 12:26 am, r0g wrote: Diez >> The Web2py framework works a bit like that, although it's not quite as >> simplistic as what you describe. May be worth a look though. >> >> Roger. > > > Hi r0g, > > web2py is a web-app framework (very similar to django, pylons

Re: remote evaluation of Python code typed in html webpage frame

2010-01-16 Thread Anand Vaidya
On Jan 16, 12:26 am, r0g wrote: > >> Diez > > The Web2py framework works a bit like that, although it's not quite as > simplistic as what you describe. May be worth a look though. > > Roger. Hi r0g, web2py is a web-app framework (very similar to django, pylons etc) and it does not execute user

Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread r0g
dmitrey wrote: > Thank you for the link, but I meant what is appropriate soft to be > installed on my server to do things like that. > Also, for my purposes it's better to have some text with possibility > of reexecuting after some minor code changes than python interpreter > command prompt. > Rega

Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread dmitrey
Thank you for the link, but I meant what is appropriate soft to be installed on my server to do things like that. Also, for my purposes it's better to have some text with possibility of reexecuting after some minor code changes than python interpreter command prompt. Regards, D. On 15 янв, 16:41,

Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread Diez B. Roggisch
Am 15.01.10 15:16, schrieb dmitrey: hi all, what's the simplest way to create a webpage with a frame for Python code to be typed in (as a plain text, or, better, as a highlighted text or something like scite or any other easy python IDE, capable of automatic indentations), and then pressing a but

remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread dmitrey
hi all, what's the simplest way to create a webpage with a frame for Python code to be typed in (as a plain text, or, better, as a highlighted text or something like scite or any other easy python IDE, capable of automatic indentations), and then pressing a button to evaluate it using a remote serv

a evaluation of Google-code-prettify

2009-06-21 Thread Xah Lee
For those of you interested in the Google tech of syntax coloring source code in html on the fly using javascript, i've spent few hours for a evaluation. See: • Google-code-prettify Examples http://xahlee.org/js/google-code-prettify/index.html Xah ∑ http://xahlee.org/ ☄ -- http://mail.pytho

Re: Evaluation of Truth Curiosity

2006-09-21 Thread James Stroud
Everyone wrote: > [something intelligent] Ah, clarity. My confusion can undoubtedly be traced to a non-existent formal training in computer programming. Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: Evaluation of Truth Curiosity

2006-09-21 Thread Christophe
James Stroud a écrit : > Hello All, > > I'm curious, in > > py> 0 | (1 == 1) > 1 > py> False | (1 == 1) > True > > What is the logic of the former expression not evaluating to True (or > why the latter not 1?)? Is there some logic that necessitates the first > operand's dictating the result of

Re: Evaluation of Truth Curiosity

2006-09-21 Thread Fredrik Lundh
James Stroud wrote: > I'm curious, in > > py> 0 | (1 == 1) > 1 > py> False | (1 == 1) > True > > What is the logic of the former expression not evaluating to True (or > why the latter not 1?)? Is there some logic that necessitates the first > operand's dictating the result of the evaluation? O

  1   2   >