[Tutor] Re: Tutor digest, Vol 1 #293 - 3 msgs

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Mon, 24 Apr 2000 09:43:26 -0700 (PDT)


> Please tell me how to convert an int to a string.
> I'm trying to do the following:
> 
>     block_number = 1
>     file_name = 'temp.file'
>     output = open(file_name + '.$' + block_number + '$', 'wb')
> 
> This didn't work. I was hoping that it would create 
> a file called 'temp.file.$1$'.

Python doesn't automatically convert your block_number into a string ---
you can make it a string by surrounding it with back-quotes, as follows:

     block_number = 1
     file_name = 'temp.file'
     output = open(file_name + '.$' + `block_number` + '$', 'wb')

You can also use the str() function to string convert.