removing spaces when mixing variables / text

Amy G amy-g-art at cox.net
Tue Feb 3 03:44:54 EST 2004


try this instead

while n > 0:
     a = random.randint(1,254)
     b = random.randint(1,254)
     c = random.randint(1,254)
     d = random.randint(1,254)
     print str(a) + "." + str(b) + "." + str(c) + "." + str(d)
     n -= 1


"tgiles" <tgiles at spam.kc.rr.com> wrote in message
news:pan.2004.02.03.08.14.18.542560 at spam.kc.rr.com...
> Hi, all.
>
> I'm YAPN (Yet Another Python Newbie), started messing with it last night
> and so far, so good. Documentation exellent and the people seem friendly
> enough ;)
>
> Ok, I started playing around with random() and decided to write a script
> to generate random dotted quad IP addresses, just to see if I could do it.
>
> Everything is perfect with the glaring exeception of the output. It seems
> as if when one uses the "," in a print statement, you get an empty space
> in between variables and what I want there (namely, the ".").
>
> I've tried it several different ways with no go. Here's the script in all
> her cheesy glory:
>
> import random
> n = 2
> while n > 0:
> a = random.randint(1,254)
> b = random.randint(1,254)
> c = random.randint(1,254)
> d = random.randint(1,254)
> print a,".",b,".",c,".",d
> n = n-1
>
> The output at the moment looks like so:
>
> 179 . 72 . 138 . 272
> 21 . 124 . 83 . 9
>
> When, in a perfect universe it would look like so:
>
> 179.72.138.272
> 21.124.83.9
>
> Thoughts on what critically simple something I missed?
>
> Thanks for the input!
>
> tom





More information about the Python-list mailing list