Skip to content Skip to sidebar Skip to footer

Difference Between Python Script Output And Python Console Output

I have this .py file: from sys import argv script, filename = argv print 'We're going to erase %r.' % filename print 'If you don't want that, hit CTRL-C (^C).' print 'If you do w

Solution 1:

a) The interpreter prints the output of the commands by default, but your script doesn't do that unless you use the print statement.

print raw_input('?')

b) The '\n' isn't in the string returned from raw_input, but it's anyway captured by the console when you press enter so this is a side effect you get when using raw_input.

printrepr(raw_input('?'))  # You'll get 'f', not 'f\n'

Solution 2:

a) It does return the string, but you're not saving it in a variable. The interactive interpreter will echo the value in that case.

b) The \n is probably part of the input (your typing), though it's hard to know what exactly you mean.

Post a Comment for "Difference Between Python Script Output And Python Console Output"