Skip to content

04 - pymel and rss and strings

If you want to use any of these examples in RSS, you should be able to just call it like this:

python
# the original line
[ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]

# in RSS friendly form
python = "[ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]"
# the original line
[ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]

# in RSS friendly form
python = "[ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]"

Something I've never been clear on is if we import pymel by default for rss. Some say we do, others say we don't. Best not to risk it, import it yourself:

python
# the original line with the pymel import line
from pymel import *
[ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]


# in RSS form, you can join lines together with a semi colon:
python = "from pymel import *; [ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]"
# the original line with the pymel import line
from pymel import *
[ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]


# in RSS form, you can join lines together with a semi colon:
python = "from pymel import *; [ x.maxDist.set(10) for x in ls(type='phxRayShadow') ]"

Quoting strings

A tricky thing (which isn't tricky) is if you have stuff in single or double quotes. Python treats them both the same:

python
foo = 'this is a string'
bar = "this is also a string"
foo = 'this is a string'
bar = "this is also a string"

but make sure they match!

python
foo = 'this is broken" # start of line has a single quote, end of line is a double quote
foo = 'this is broken" # start of line has a single quote, end of line is a double quote

the reason python offers this is so that if you need to have a string that has one type of quote, just wrap it in the other kind of quote:

python
foo = "who said you can't use single quotes in strings? They're fine!"
bar = 'and i can use "air quotes" here too, all good'
foo = "who said you can't use single quotes in strings? They're fine!"
bar = 'and i can use "air quotes" here too, all good'

god forbid you need to have a string with both single and double quotes, but if you do, python's got you covered. use triple-quotes!

python
foo = """I can't believe I can do "this" with python!"""
bar = '''works with "single quotes" and "double quotes" too.'''
foo = """I can't believe I can do "this" with python!"""
bar = '''works with "single quotes" and "double quotes" too.'''

Python eh? It's amazing.