Python equvilent to batch 'set /a

Custom / CUSTOM
February 7, 2009 at 08:21:39
Specs: Linux i686, 8g
Hi all,

I am migrating a batch program of mine to python so it will run more efficently on my unix machines. I wish to be able to enter varables into my script while it is running. For batch scripts I know the command is

'set /a a='

but i am unaware of the python equivelent of this command. Any help would be appriciated.


See More: Python equvilent to batch set /a

Report •

February 7, 2009 at 09:35:54
Math in python is done natively:

var = 1 + 1
var = var2 + var3
var = var * 15

And so forth, there is loads of information out there a web search will bring many results...

Report •

February 7, 2009 at 16:17:07
thanks but not quite what im looking for. I want to be able to enter varibles within the program, this way i can easily change a varible each time the program runs.

Report •

February 7, 2009 at 16:32:07
Ok then, do you mean the equilivant to set /p var=

var = raw_input("Enter something! ")

Report •

Related Solutions

February 7, 2009 at 19:15:50
ok, that looks like more what im looking for, it asks for input so i enter it but it wont print when i type

print '%d' % var

i get the error,

TypeError: int argument required

any thoughts?

Report •

February 7, 2009 at 19:50:13
Are you trying to print that as a string to screen or print the output of a sum?

Report •

February 7, 2009 at 22:10:31
In python variables are untyped but data is strongly typed.
The data from input or raw_input is going to be string. So,
unless you have done something to recast it as integer, var
holds string data. The print statement print "%d" %(var) uses
the sprintf control for integer data, and is erroring because
var isn't int. You can just "print var" with no sprintf strings
and that will give you something no matter what type of data
you are printing. This is very useful and you will find yourself
using print with no controls all the time.

Report •

Ask Question