Re: f-string error message

2023-08-30 Thread Random832 via Python-list
On Sun, Aug 27, 2023, at 17:19, Rob Cliffe via Python-list wrote: > I understand that this is an error: I'm telling the f-string to expect > an integer when in fact I'm giving it a Decimal. > And indeed f"{x:3}" gives ' 42' whether x is an int or a Decimal. > However, to my mind it is not the form

Re: f-string syntax deficiency?

2023-06-06 Thread Mark Bourne via Python-list
Roel Schroeven wrote: Op 6/06/2023 om 16:08 schreef Chris Angelico: On Wed, 7 Jun 2023 at 00:06, Neal Becker wrote: > > The following f-string does not parse and gives syntax error on 3.11.3: > > f'thruput/{"user" if opt.return else "cell"} vs. elevation\n' > > However this expression, which is

Re: f-string syntax deficiency?

2023-06-06 Thread Roel Schroeven via Python-list
Op 6/06/2023 om 16:48 schreef Chris Angelico via Python-list: On Wed, 7 Jun 2023 at 00:42, Roel Schroeven wrote: > (Recently there has been an effort to provide clearer and more useful > error messages; this seems to be a case where there is still room for > improvement: "SyntaxError: invalid sy

Re: f-string syntax deficiency?

2023-06-06 Thread Chris Angelico via Python-list
On Wed, 7 Jun 2023 at 00:42, Roel Schroeven wrote: > (Recently there has been an effort to provide clearer and more useful > error messages; this seems to be a case where there is still room for > improvement: "SyntaxError: invalid syntax" doesn't immediately remind me > of that fact that 'return'

Re: f-string syntax deficiency?

2023-06-06 Thread Roel Schroeven
Op 6/06/2023 om 16:41 schreef Roel Schroeven: 'return' being a keyowrd is definitely going to be the problem. *keyword -- "Don't Panic." -- Douglas Adams, The Hitchhiker's Guide to the Galaxy -- https://mail.python.org/mailman/listinfo/python-list

Re: f-string syntax deficiency?

2023-06-06 Thread Roel Schroeven
Op 6/06/2023 om 16:08 schreef Chris Angelico: On Wed, 7 Jun 2023 at 00:06, Neal Becker wrote: > > The following f-string does not parse and gives syntax error on 3.11.3: > > f'thruput/{"user" if opt.return else "cell"} vs. elevation\n' > > However this expression, which is similar does parse cor

Re: f-string syntax deficiency?

2023-06-06 Thread Chris Angelico
On Wed, 7 Jun 2023 at 00:06, Neal Becker wrote: > > The following f-string does not parse and gives syntax error on 3.11.3: > > f'thruput/{"user" if opt.return else "cell"} vs. elevation\n' > > However this expression, which is similar does parse correctly: > > f'thruput/{"user" if True else "cell

Re: F-string usage in a print()

2022-05-24 Thread Cameron Simpson
On 25May2022 00:13, Kevin M. Wilson wrote: >Cameron, I have a misunderstanding here, the 'f-string' is used when >the str() is not...isn't it! No, f-strings (format strings) are just a convenient way to embed values in a string. The result is a string. In days of yore the common formatting met

Re: F-string usage in a print()

2022-05-24 Thread Cameron Simpson
On 24May2022 21:14, Kevin M. Wilson wrote: >future_value = 0 >for i in range(years): ># for i in range(months): > future_value += monthly_investment > future_value = round(future_value, 2) > # monthly_interest_amount = future_value * monthly_interest_rate > # future_value += monthly_intere

Re: F-string usage in a print()

2022-05-24 Thread Mats Wichmann
On 5/24/22 15:14, Kevin M. Wilson via Python-list wrote: > future_value = 0 > for i in range(years): > # for i in range(months): >future_value += monthly_investment >future_value = round(future_value, 2) ># monthly_interest_amount = future_value * monthly_interest_rate ># future_val

Re: F-string usage in a print()

2022-05-24 Thread Paul Bryan
Try something like: print(f"Year = {years}, Future value = {future_value}") On Tue, 2022-05-24 at 21:14 +, Kevin M. Wilson via Python-list wrote: > future_value = 0 > for i in range(years): > # for i in range(months): >    future_value += monthly_investment >    future_value = round(future_va

Re: F-string usage in a print()

2022-05-24 Thread MRAB
On 2022-05-24 22:14, Kevin M. Wilson via Python-list wrote: future_value = 0 for i in range(years): # for i in range(months): future_value += monthly_investment future_value = round(future_value, 2) # monthly_interest_amount = future_value * monthly_interest_rate # future_value +=

Re: f-string not referenced in library

2019-02-20 Thread Calvin Spealman
The string library is a utility set of functions with common string operations and that documentation is about the specific library, not the concept of strings or their syntax and other features in the language itself. For more about f-strings and other string behaviors, read the documentation on s

Re: f-string anomaly

2018-05-14 Thread Lele Gaifax
Ken Kundert writes: > Lele, > I am using Python3.6. d has to be an object of mydict. My bad, sorry, I completely missed the premise :-|. ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@m

Re: f-string anomaly

2018-05-14 Thread Ken Kundert
Lele, I am using Python3.6. d has to be an object of mydict. Here is the code that exhibits the problem: import sys, os from inform import error, os_error class mydict(dict): def __format__(self, template): print('Template:', template) return

Re: f-string anomaly

2018-05-14 Thread MRAB
On 2018-05-14 20:24, Lele Gaifax wrote: Ken Kundert writes: Lele, I'm afraid I was unclear. The ... in the code snippet was intended to imply that these lines were appended to the end of the original code, where d was defined. Ok, but then I get a different behaviour: Python 3.6.5

Re: f-string anomaly

2018-05-14 Thread Lele Gaifax
Ken Kundert writes: > Lele, > I'm afraid I was unclear. The ... in the code snippet was intended > to imply that these lines were appended to the end of the original code, > where d was defined. Ok, but then I get a different behaviour: Python 3.6.5 (default, May 11 2018, 13:30:17)

Re: f-string anomaly

2018-05-14 Thread Ken Kundert
Lele, I'm afraid I was unclear. The ... in the code snippet was intended to imply that these lines were appended to the end of the original code, where d was defined. -Ken On 05/14/2018 12:30 AM, Lele Gaifax wrote: > Ken Kundert writes: > >> I tried adding k and v to the local namespace: >>

Re: f-string anomaly

2018-05-14 Thread Thomas Jollans
On 2018-05-14 04:08, Terry Reedy wrote: > On 5/13/2018 3:22 PM, Ken Kundert wrote: > > Please do not double post. > >> I am seeing an unexpected difference between the behavior of the string >> format method and f-strings. > > Read > https://docs.python.org/3/reference/lexical_analysis.html#form

Re: f-string anomaly

2018-05-14 Thread Lele Gaifax
Ken Kundert writes: > I tried adding k and v to the local namespace: > > ... > k = 6 > v = 9 > print(f'Email: {d:{{k}} {{v}}}') > > I still got: > > NameError: name 'k' is not defined This is not what I get: Python 3.6.5 (default, May 11 2018, 13:30:17) [GCC 7.3.0]

Re: f-string anomaly

2018-05-13 Thread Ken Kundert
Terry, Thanks for your response. I apologize about the double posting. I am well aware how doing so is bad form. My double posting was unintentional; it occurred when my news reader misbehaved. What I did in my code was to put double braces inside the format_spec, which the syntax specificati

Re: f-string anomaly

2018-05-13 Thread Terry Reedy
On 5/13/2018 3:22 PM, Ken Kundert wrote: Please do not double post. I am seeing an unexpected difference between the behavior of the string format method and f-strings. Read https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals carefully. Here is an example:

Re: f-string

2017-12-08 Thread Chris Angelico
On Tue, Dec 5, 2017 at 6:37 PM, Ned Batchelder wrote: > On 12/5/17 7:16 PM, Steve D'Aprano wrote: >> compile('f"{spam} {eggs}"', '', 'single') > > $ python3.6 > Python 3.6.3 (default, Octâ 4 2017, 06:03:25) > [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin > Typ

Re: f-string

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 11:54 am, John Pote wrote: [...] > Ran above test file and got, > >>python36 compiletest.py > at 0x02120E40, file "", line 1> > > > SPAM scrambled Thanks everyone, that's what I wanted to see. -- Steve â £Cheer up,â Ø they said, â £things could be worse.â Ø So I ch

Re: f-string

2017-12-08 Thread Chris Angelico
On Wed, Dec 6, 2017 at 8:24 PM, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > >> On Wed, Dec 6, 2017 at 11:54 AM, John Pote >> wrote: >>> >>> On 06/12/2017 00:16, Steve D'Aprano wrote: Anyone got a handy copy of Python 3.6 available to test something for m

Re: f-string

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 11:54 AM, John Pote > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test something for me? >>> >>> What does compile('f"{spam} {eggs}"', '', 'single') r

Re: f-string

2017-12-08 Thread John Pote
On 06/12/2017 00:16, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first.

Re: f-string

2017-12-08 Thread Ned Batchelder
On 12/5/17 7:16 PM, Steve D'Aprano wrote: > compile('f"{spam} {eggs}"', '', 'single') $ python3.6 Python 3.6.3 (default, Octâ 4 2017, 06:03:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin Type "help", "copyright", "credits" or "license" for more information.

Re: f-string

2017-12-08 Thread MRAB
On 2017-12-06 00:16, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and eggs first. >

Re: f-string

2017-12-08 Thread Chris Angelico
On Wed, Dec 6, 2017 at 11:54 AM, John Pote wrote: > > On 06/12/2017 00:16, Steve D'Aprano wrote: >> >> Anyone got a handy copy of Python 3.6 available to test something for me? >> >> What does compile('f"{spam} {eggs}"', '', 'single') return? >> >> What does eval()'ing the above compiled object do

Re: f-string

2017-12-08 Thread Chris Angelico
On Wed, Dec 6, 2017 at 11:16 AM, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and

Re: f-string

2017-12-06 Thread Chris Angelico
On Wed, Dec 6, 2017 at 8:24 PM, Steve D'Aprano wrote: > On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > >> On Wed, Dec 6, 2017 at 11:54 AM, John Pote >> wrote: >>> >>> On 06/12/2017 00:16, Steve D'Aprano wrote: Anyone got a handy copy of Python 3.6 available to test something for m

Re: f-string

2017-12-06 Thread Steve D'Aprano
On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote: > On Wed, Dec 6, 2017 at 11:54 AM, John Pote > wrote: >> >> On 06/12/2017 00:16, Steve D'Aprano wrote: >>> >>> Anyone got a handy copy of Python 3.6 available to test something for me? >>> >>> What does compile('f"{spam} {eggs}"', '', 'single') r

Re: f-string

2017-12-05 Thread Steve D'Aprano
On Wed, 6 Dec 2017 11:54 am, John Pote wrote: [...] > Ran above test file and got, > >>python36 compiletest.py > at 0x02120E40, file "", line 1> > > > SPAM scrambled Thanks everyone, that's what I wanted to see. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered

Re: f-string

2017-12-05 Thread Chris Angelico
On Wed, Dec 6, 2017 at 11:54 AM, John Pote wrote: > > On 06/12/2017 00:16, Steve D'Aprano wrote: >> >> Anyone got a handy copy of Python 3.6 available to test something for me? >> >> What does compile('f"{spam} {eggs}"', '', 'single') return? >> >> What does eval()'ing the above compiled object do

Re: f-string

2017-12-05 Thread John Pote
On 06/12/2017 00:16, Steve D'Aprano wrote: Anyone got a handy copy of Python 3.6 available to test something for me? What does compile('f"{spam} {eggs}"', '', 'single') return? What does eval()'ing the above compiled object do? If necessary, you may have to define spam and eggs first. Thanks

Re: f-string

2017-12-05 Thread Chris Angelico
On Wed, Dec 6, 2017 at 11:16 AM, Steve D'Aprano wrote: > Anyone got a handy copy of Python 3.6 available to test something for me? > > What does compile('f"{spam} {eggs}"', '', 'single') return? > > What does eval()'ing the above compiled object do? If necessary, you may have > to define spam and

Re: f-string

2017-12-05 Thread Ned Batchelder
On 12/5/17 7:16 PM, Steve D'Aprano wrote: compile('f"{spam} {eggs}"', '', 'single') $ python3.6 Python 3.6.3 (default, Oct  4 2017, 06:03:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin Type "help", "copyright", "credits" or "license" for more information.

Re: f-string

2017-12-05 Thread MRAB
On 2017-12-06 00:16, Steve D'Aprano wrote: Anyone got a handy copy of Python 3.6 available to test something for me? What does compile('f"{spam} {eggs}"', '', 'single') return? What does eval()'ing the above compiled object do? If necessary, you may have to define spam and eggs first. Thanks