integer to string?

Ben Finney bignose-hates-spam at
Tue Jun 3 05:02:24 CEST 2003

On Tue, 03 Jun 2003 02:15:27 GMT, Hendrik Reinhold wrote:
> import random
> from random import randrange
> var1 = randrange(0,9)
> capisuite.audio_send(call,my_path+var1+".la")

As you noted, the types conflict.  The type of an object is set when it
is assigned.

The Pythonic way to generate a string from multiple values of different
types is with string formatting:

import random
rand_num = random.randrange( 0, 9 )
audio_file = "%s/" % my_path, rand_num
capisuite.audio_send( call, audio_file )

The '%' is the format operator for strings.


It returns a new string resulting from interpolating the right-hand-side
values into the left-hand-side format string.

 \        "I used to work in a fire hydrant factory. You couldn't park |
  `\                       anywhere near the place."  -- Steven Wright |
_o__)                                                                  | 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B

More information about the Python-list mailing list