python string formatting problems in shelf popup menu commands...

156 views
Skip to first unread message

Brian Eyre

unread,
Jun 18, 2014, 6:38:46 PM6/18/14
to python_in...@googlegroups.com
Hi,

I was getting intermittent syntax errors from code entered into the popup menu of a shelf button, and have narrowed it down to an issue with using '%' in string formatting. Example:

text = 'working'
print 'why is this command not %s'%text

I'm wondering if this is a known issue, or if anyone has a solution?

Cheers!

Brian.





Justin Israel

unread,
Jun 18, 2014, 9:52:36 PM6/18/14
to python_in...@googlegroups.com

Can see a reason  for that to fail.  Does it just say syntax error?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/284cbc26-51e7-4fcd-9e5f-ddbbc4eba3d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony Tan

unread,
Jun 19, 2014, 7:45:01 AM6/19/14
to python_in...@googlegroups.com
Just playing with it here (Win, Maya 2012/x64) it comes up with a TypeError: not enough arguments for format string. I've not really used much % string formatting so I'm at a mild loss, but the same code works fine in say, IDLE, so I've a half guess it's how the code block is being passed through to the python interpreter 

Hm, in fact, I'll bet my hat on that - trying this:

print "This really should work, %s"%("right")

Gives me a *KeyError*. Traceback as follows:

#   File "<string>", line 2, in pythonFormat
# KeyError: u"'right'" //
# Error: invalid syntax
#  File "<maya console>", line 2
#  
#    ^
# SyntaxError: invalid syntax #

So whatever is mangling the text in the UI editor to get it into a python interpreter is doing something a tad odd to the string. Short answer appears to be not to use % based formatting, alas.




Anthony Tan

unread,
Jun 19, 2014, 8:02:05 AM6/19/14
to python_in...@googlegroups.com
Aaand of course, couldn't resist playing instead of cooking dinner for myself. Trying this:

print r"what does %s do?"

and I get:

what does {'1': u'False'} do?


Bah.




On 19 Jun 2014, at 11:52, Justin Israel <justin...@gmail.com> wrote:

Brian Eyre

unread,
Jun 19, 2014, 1:10:18 PM6/19/14
to python_in...@googlegroups.com
Thanks folks,

Yeah, it seems to be an issue purely with the shelf popup menu text entry field.  The code works fine in in the single and double-click fields for the same button, and in the script editor.  Weird.

I guess I'll just have to refrain  from using that type of formatting..


On Thursday, June 19, 2014 5:02:05 AM UTC-7, Anthony Tan wrote:
Aaand of course, couldn't resist playing instead of cooking dinner for myself. Trying this:

print r"what does %s do?"

and I get:

what does {'1': u'False'} do?


Bah.




On 19 Jun 2014, at 11:52, Justin Israel <justin...@gmail.com> wrote:

Can see a reason  for that to fail.  Does it just say syntax error?

On Jun 18, 2014 3:38 PM, "Brian Eyre" <brian...@googlemail.com> wrote:
Hi,

I was getting intermittent syntax errors from code entered into the popup menu of a shelf button, and have narrowed it down to an issue with using '%' in string formatting. Example:

text = 'working'
print 'why is this command not %s'%text

I'm wondering if this is a known issue, or if anyone has a solution?

Cheers!

Brian.






--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Jun 19, 2014, 3:49:40 PM6/19/14
to python_in...@googlegroups.com
Yea just sounds like you are getting unexpected types which you are then applying to the string formatting. 


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d8bc1841-61ef-4b6a-a212-aed4dec53620%40googlegroups.com.

Юрий Сивальнев

unread,
Jun 20, 2014, 5:58:04 PM6/20/14
to python_in...@googlegroups.com
That way it works 
print "what does {0} do?".format('some thing')
Reply all
Reply to author
Forward
0 new messages