python equivalent for fputc

Fredrik Lundh fredrik at pythonware.com
Wed Aug 30 23:45:42 EDT 2006


Putty wrote:

> I'm porting a program a friend wrote in C over to Python and I've run
> into a little hang-up.  The C program writes characters out to a file.
> I'm 99% sure that a conversion is going on here as well.  I know for a
> fact that it's taking a number and turning it into a character.

that's what fputc does, of course -- it takes an integer and writes
it as a character to the given stream.

    f = fopen(filename, "w");
    fputc(c, f);
    fclose(f)

becomes

    f = open(filename, "w")
    f.write(chr(value))
    f.close()

</F>






More information about the Python-list mailing list