Home > OS >  Calculate result without entering python shell
Calculate result without entering python shell

Time:11-24

Is it possible to calculate an expression using python but without entering python shell? What I want to achieve is to use python in a following manner:

tail file.txt -n `python 123*456`

instead of having to calculate 123*456 in a separate step.

CodePudding user response:

I don't understand your question: you say "I would like to do something using Python", but when you show what you want to do, Python seems not to be needed for achieving that.

Let me show you: what you want to achieve, can be done as follows:

tail -f file.txt -n $((123*456))

The $((...)) notation is capable of performing integer calculations, as you can imagine.

Is this what you are looking for, or are you really forced to use Python, and if so, why do you think that?

CodePudding user response:

You can try the -c option. For e.g, tail test_log.txt -n `python -c "print(1 2)"`

  • Related