Strage behavior

by: mnalevanko, 10 years ago


Hello,

I wonder whether you could help me understand a somewhat strange behavior of my Python shell.

This is a simple code:


with open('test.txt', 'w') as fhandle:
    for a in range(1,11):
        message = '#' + str(a) + '  This is a test message!n'
        fhandle.write(message)


It is quite obvious what this program does. However, when I run these commands from a shell, I see following picture (https://goo.gl/izYbD0).

The program creates the test.txt file. But why do I see the numbers in the shell?

Thank you for your help!



You must be logged in to post. Please login or register an account.



No idea. You shouldn't, and I do not see those numbers when trying it.

-Harrison 10 years ago

You must be logged in to post. Please login or register an account.


I've reinstalled Python on my computer today, moved to 3.5. Can this have any effect?

-mnalevanko 10 years ago

You must be logged in to post. Please login or register an account.


Nah, shouldn't have any impact. You sure there's nothing more in your script or something?

-testytest 10 years ago

You must be logged in to post. Please login or register an account.


Nothing that I am aware of. That's why I decided to post the problem here. Obviously, the numbers show the length of a string that is being added to the text file in the for loop.

But I have no idea why.

-mnalevanko 10 years ago
Last edited 10 years ago

You must be logged in to post. Please login or register an account.

The numbers (in the image) are the lengths of the strings that are generated by the script
does that help?
I don't know where/how you are generating this output, but its not this script!
You won't see any output when you are just writing to a file.

try this in the console:


for a in range(1,11):
    message = '#' + str(a) + '  This is a test message!n'
    print message, len(message)


-knowingpark 10 years ago

You must be logged in to post. Please login or register an account.