[Tutor] Some Strange Behavior

Utkarsh Tandon utkarsh.tandon at gmail.com
Sun Mar 25 15:49:05 CEST 2007

Umm, hey everyone

I'm a newbie to the world of programming. The best way to learn anything is
to do it. So I was just trying to make a program
that removed comments from a C program. The program worked but a whitespace
came after every character. Can anyone please tell me the reason for thw

Here is C code I was editing :-
/* Comments............. */
/* Some more comments........ */

    printf("/* Hello, World! */");
    /* Some more comments .......................... */

Here is the program
def main(filename):
    text = open(str(filename), 'r')
    realtext = text.read()
    realtext = list(realtext)
    length = len(realtext)
    string = False

    for i in range (0, length):


            if realtext[i] == '/' and realtext[i + 1] == '*':

                del realtext[i]
                del realtext[i]

                while realtext[i] != '*' and realtext[i+1] != '/':
                    del realtext[i]

                del realtext[i]
                del realtext[i]

        except IndexError:

    filename = str(raw_input('Enter the name of the new file '))

    file = open(str(filename), 'w')
    realtext = str(realtext)

    realtext = realtext.replace('[', "").replace(']', "").replace(',',
"").replace("'", "").replace('\\n', "").replace('\\t', "")

main(str(raw_input('Enter the filename ')))

Here is it's output, notice the unnecesary whitespace after every
   m a i n ( )   {   p r i n t f ( " " ) ;     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070325/087499a9/attachment.htm 

More information about the Tutor mailing list