putchar(8)

Dave Angel davea at ieee.org
Sat Oct 17 06:48:10 EDT 2009



Dave Angel wrote:
>
> Jason Tackaberry wrote:
>> On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote:
>>  
>>> Hi all, is there in python the equivalent of the C function int putchar
>>> (int c)? I need to print putchar(8).
>>>     
>>
>>  
>>>>> print '\x08'
>>>>>         
>>
>> or:
>>
>>  
>>>>> print chr(8)
>>>>>         
>>
>>
>>
>>   
> If I recall correctly, putchar() takes an int value 0-255 and outputs 
> a single character to stdout.  So the equivalent would be:
>
> sys.stdout.write(char(c))
>
> print does other stuff, which you presumably do not want.
>
> DaveA
>
>
>
Oops.  Instead of char(), I meant to type chr().


sys.stdout.write(chr(c))

chr() is a built-in that converts an integer to a single character.

DaveA



More information about the Python-list mailing list