Sunday, 1 March 2015

Python print function


There is some useful tricks in python (3.x) to print objects.

Alternatively , you can code 3.x print function calls in code to be run by 2.x, by enabling the function call variant with statement like the following coded at the top  of a script , or anyware in an interactive session:

from __future__ import print function

For example here is an exmaple to sepretare print object and to log data into file :

from __future__ import print_function

x = 'Beka'
y = 99
w = '[item]'

print(x,y,w,sep='...')
print(x,y,w,file=open('log3.txt','a')) ## log into file





No comments: