On Fri, 13 Mar 2015 5:55 PM Panupat Chongstitwattana <panup...@gmail.com>
wrote:

Is there a list of available except type? For example if I'm doing

try:
    os.makedir(dir)
except .....:
    pass

Where can I find out what error to catch apart from trying it out?


docs are your friend:
https://docs.python.org/2/library/os.html

"Note All functions in this module raise OSError in the case of invalid or
inaccessible file names and paths, or other arguments that have the correct
type, but are not accepted by the operating system."

Usually either the module or specific function docstring should explain the
exceptions that can be raised

On Wednesday, March 11, 2015 at 8:22:06 PM UTC+7, elrond79 wrote:

>From a functional standpoint, there isn't a difference. There may be a
performance difference, but unless you're making thousands, I wouldn't
worry about it.

Generally speaking, if I usually expect it to exist, and want to use it as
a PyNode if it does, I'll do the try/except thing.  One note though - you
should probably do:

try:
    pmc.PyNode(string)
except pmc.MayaNodeError:
    print "something"

It's bad practice to have blanket except statements** - particularly if
you're "expecting" a certain type of error. Get in the habit of having
targeted try excepts, and you'll save yourself from headaches down the road.

- Paul

**There are always exceptions, of course - for instance, if you're running
an app and don't want an unknown error to bring everything to a halt, it
can make sense to have some generic high-level try/except statements.  And
in those cases, you'll probably want to at least print some sort of warning
or traceback, or maybe log it to an error log, or email a bug report, etc.
Also, even then, it's better to do "except Exception as e:" or "except
Exception:" instead of "except:", because the latter will catch strange
things you almost certainly don't want to - ie, if the user presses ctrl-c,
or even if you've explicitly tried to call sys.exit!



On Wed, Mar 11, 2015 at 12:32 AM, Panupat Chongstitwattana <
panu...@gmail.com> wrote:

 Ah thank you. Such a silly mistake :(

Is there any draw back if I don't check objExists but instead go for this?

try:
    PyNode(string)
except:
    print "something"

On Wednesday, March 11, 2015 at 2:02:06 PM UTC+7, Justin Israel wrote:

 You have a typo between the two ways you format the string :

tmpname = "%smaster_crtl" % sel.namespace()
tmp = "%smaster_ctrl" % selects[0].namespace()

crtl vs ctrl

On Wed, 11 Mar 2015 7:02 PM Panupat Chongstitwattana <panu...@gmail.com>
wrote:

  Hi.

I ran into another problem. objExists is returning different result when I
put it in a for loop.

selects = pmc.selected()

for sel in selects:
    tmpname = "%smaster_crtl" % sel.namespace()
    print tmpname
    print pmc.objExists(tmpname)
#
SC05A_0110_ECh_LoopAnim_v002:SC05A_0020_Extra_Cheer_LoopAnim_v001:exMaleHair001:master_ctrl
# False

tmp = "%smaster_ctrl" % selects[0].namespace()
print tmp
print pmc.objExists(tmp)
#
SC05A_0110_ECh_LoopAnim_v002:SC05A_0020_Extra_Cheer_LoopAnim_v001:exMaleHair001:master_ctrl
# True

What could be the cause of this?


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/8f3151a3-7a9b-4fdc-8721-f8cb60d35c10%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/8f3151a3-7a9b-4fdc-8721-f8cb60d35c10%40googlegroups.com?utm_medium=email&utm_source=footer>
.

For more options, visit https://groups.google.com/d/optout.



-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/7d8ad41f-3f98-43ca-946a-1d5f14ab4b50%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/7d8ad41f-3f98-43ca-946a-1d5f14ab4b50%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2msq_rgPtZDdFRNY5RLNtaN_vziBy5B4%3DtEFoHm%3DHz0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to