but I don't want to print the trailing ".0"

Dan Jacobson jidanni at dman.ddts.net
Thu May 1 18:40:54 EDT 2003


What is the "in crowd" method to enhance s.py so I don't have to use
sed to get what I want?
$ cat s.py
steps=(1500,1250,1000,625,500)
for i in steps:
    print i/100.0 #how do I enhance this line, please? what %f thingy?
$ python s.py
15.0
12.5
10.0
6.25
5.0
$ python s.py|sed 's/\.0$//' #gives what I want
15
12.5
10
6.25
5

I'm looking for the concise %f etc. solution, not some masking tape
covered string surgery exhortation.  Yes I did "man 3 printf" but I
lack the cells to swap it all in to my Limited Edition brain.

By the way, any dumbness here?:
for arg in sys.argv[1:]: #no --help yet, never mind.
    freq=string.atof(arg)
    remainder=int(round(freq*1000))%9
    if not remainder: ...

pydoc string says string.atof is obsolete it seems, oh, I see, I am
supposed to use float(), ok, I wish it said that there on pydoc string.
How about int(round( ? Looks goofy.

BTW, I believe I'm doing this to avoid this wackyness: 
$ python -c 'a= 3.3*100000;print a,a % 500'
330000.0 0.0 #OK
$ python -c 'a=33.3*100000;print a,a % 500'
3330000.0 500.0 #Yuck

BTW,
$ python -Qwarnall someotherprog.py
someotherprog.py:34: DeprecationWarning: classic float division
  print arg + ":", step/100.0
OK, then can it or somebody tell me how it prefers me to change it?
If I have the .0 trailing aren't I safe for decades to come?
-- 
http://jidanni.org/ Taiwan(04)25854780




More information about the Python-list mailing list