Re: Library for text substitutions with calculations?

2020-12-15 Thread Terry Reedy

On 12/15/2020 11:25 AM, Bob Gailer wrote:

On Tue, Dec 15, 2020, 10:42 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:


On 2020-12-15 at 16:04:55 +0100,
Jan Erik Moström  wrote:


I want to do some text substitutions but a bit more advanced than what
string.Template class can do. I addition to plain text substitution I

would

like to be able to do some calculations:

$value+1 - If value is 16 this would insert 17 in the text. I would also
like to subtract.


val = 2


print(f'{val+3}')

5


For more, see 
https://docs.python.org/3/reference/lexical_analysis.html#f-strings



--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Library for text substitutions with calculations?

2020-12-15 Thread Bob Gailer
On Tue, Dec 15, 2020, 10:42 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:

> On 2020-12-15 at 16:04:55 +0100,
> Jan Erik Moström  wrote:
>
> > I want to do some text substitutions but a bit more advanced than what
> > string.Template class can do. I addition to plain text substitution I
> would
> > like to be able to do some calculations:
> >
> > $value+1 - If value is 16 this would insert 17 in the text. I would also
> > like to subtract.
>
> val = 2

print(f'{val+3}')

5

Bob Gailer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Library for text substitutions with calculations?

2020-12-15 Thread 2QdxY4RzWzUUiLuE
On 2020-12-15 at 16:04:55 +0100,
Jan Erik Moström  wrote:

> I want to do some text substitutions but a bit more advanced than what
> string.Template class can do. I addition to plain text substitution I would
> like to be able to do some calculations:
> 
> $value+1 - If value is 16 this would insert 17 in the text. I would also
> like to subtract.

[...]

A lot of libraries for making web pages can do things like that; a
starting point is .

HTH,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Library for text substitutions with calculations?

2020-12-15 Thread Jan Erik Moström
I want to do some text substitutions but a bit more advanced than what 
string.Template class can do. I addition to plain text substitution I 
would like to be able to do some calculations:


$value+1 - If value is 16 this would insert 17 in the text. I would also 
like to subtract.


$value+1w - In this case value would be a date, this would add a week to 
that date, similar for year, month, hours. Also subtract.


The exact syntax isn't important.

In other words I would like to define

example1 = 12
example2 = 2020-12-15

and then some text:

Hello world $example1+10 and a date $example+1w

would result in

Hello world 22 and a date 2020-12-22

Is there some library that can do something like this?

I probably searching using the wrong keywords because I can't find 
anything.


= jem
--
https://mail.python.org/mailman/listinfo/python-list