putchar(8)

Discussion in 'Python' started by gervaz, Oct 16, 2009.

  1. gervaz

    gervaz Guest

    Hi all, is there in python the equivalent of the C function int putchar
    (int c)? I need to print putchar(8).

    Thanks, Mattia
     
    gervaz, Oct 16, 2009
    #1
    1. Advertising

  2. 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)
     
    Jason Tackaberry, Oct 16, 2009
    #2
    1. Advertising

  3. gervaz

    Dave Angel Guest

    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
     
    Dave Angel, Oct 17, 2009
    #3
  4. On Fri, 16 Oct 2009 15:17:38 -0400, Jason Tackaberry <>
    declaimed the following in gmane.comp.python.general:

    > 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)


    Note that print is going to also put out a new-line ending...

    To JUST put out the single byte will require using the plain file
    I/O method:

    sys.stdout.write("\x08")

    --
    Wulfraed Dennis Lee Bieber KD6MOG
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Oct 17, 2009
    #4
  5. gervaz

    Dave Angel Guest

    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
     
    Dave Angel, Oct 17, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Confused User

    Need to write putchar for embedded system

    Confused User, Jul 1, 2005, in forum: C Programming
    Replies:
    5
    Views:
    524
    Old Wolf
    Jul 9, 2005
  2. John den Haan

    disable putchar line-wrapping?

    John den Haan, Feb 18, 2007, in forum: C Programming
    Replies:
    7
    Views:
    387
    Gordon Burditt
    Feb 19, 2007
  3. Replies:
    9
    Views:
    596
    SM Ryan
    Oct 20, 2007
  4. c gordon liddy

    || putchar(ch == '\177' ? '?' : ch | 0100) == EOF)

    c gordon liddy, Mar 28, 2008, in forum: C Programming
    Replies:
    8
    Views:
    434
    David Thompson
    Apr 7, 2008
  5. gervaz

    putchar(8)

    gervaz, Oct 16, 2009, in forum: Python
    Replies:
    0
    Views:
    367
    gervaz
    Oct 16, 2009
Loading...

Share This Page