String slices

Peter Otten __peter__ at web.de
Fri Aug 9 10:49:24 EDT 2019


Paul St George wrote:

> In the code (below) I want a new line like this:
> 
> Plane rotation X: 0.0
> Plane rotation Y: 0.0
> Plane rotation Z: 0.0
> 
> But not like this:
> 
> Plane rotation X:
> 0.0
> Plane rotation Y:
> 0.0
> Plane rotation Z:
> 0.0
> 
> Is it possible?

> print(
> 
> "Plane rotation X:",bpy.data.objects["Plane"].rotation_euler[0],
> 
> "Plane rotation Y:",bpy.data.objects["Plane"].rotation_euler[1],
> 
> "Plane rotation Z:",bpy.data.objects["Plane"].rotation_euler[2],
> 
> file=outstream, sep="\n"
> 
> )

Explanation: The newlines between all positional args of print() are caused 
by the sep="\n" keyword argument. 

You probably got the idea from my

x, y, z = bpy.data.objects["Plane"].rotation_euler
print(
    "Plane rotation X:", x,
    "Plane rotation Y:", y,
    "Plane rotation Z:", z,
    file=outstream, sep="\n"
)

in the other thread where I introduced the bug when trying to simplify my 
original suggestion (which I didn't post)

print(
    f"Plane rotation X: {x}",
    f"Plane rotation Y: {y}",
    f"Plane rotation Z: {z}",
    file=outstream, sep="\n"
)

But as Dan says, use separate print() calls.




More information about the Python-list mailing list