Labeling with Python

2729
5
01-05-2016 07:53 AM
KatyW
by
New Contributor III

I have a screenshot of the Python script I'm trying to create and I'm having a problem.  How do I create a space between two values?  I know how to stack labels but I just need a simple space between the port field and the fibers field.  Can anyone help me with this?!

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

many ways... these are but 2

>>> a = "text" + " " + "more"
>>> a
'text more'
>>> # or
>>> a = "{} {}".format("text","more")
>>> a
'text more'
>>>
KatyW
by
New Contributor III

Thank you!  This will be so helpful for me in the future! 

Cheers!

Katy

0 Kudos
ChrisSmith7
Frequent Contributor

Dan mentioned there's many ways to do this - I thought I'd share another!

>>> myVars = ["spam","eggs"]
>>> " ".join(myVars)
'spam eggs'
DanPatterson_Retired
MVP Emeritus

more.... python mini-format language plus triple quote syntax... useful for printing.

>>> a = "{}\n{}".format("over","under")
>>> b = """
... hello
... goodbye
... """
>>>
>>> print a
over
under
>>>
>>> print b
hello
goodbye
0 Kudos
MitchHolley1
MVP Regular Contributor

Are you inserting this into a Python script and having the script label the features? 

If so, could you please share.  I've been stuck on this problem for a while now.

0 Kudos