Maya script error after after converting python 2to3

Maya script error after after converting python 2to3

RebeccaQYQFX7
Observer Observer
2,103 Views
2 Replies
Message 1 of 3

Maya script error after after converting python 2to3

RebeccaQYQFX7
Observer
Observer

Hope someone can help i have converted all my scripts from 2to3 using pythons 2to3.py script but when i try and start some of them im getting this error:

import gw_skinning_io
reload(gw_skinning_io)
gw_skinning_io.save_skinning()
# Error: name 'reload' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# NameError: name 'reload' is not defined #

 

i dont have real experience with python so have no clue where to start to fix this?

0 Likes
2,104 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor

Hi!

 

In python 2 to the import synthax is as follows:

Import Module
relaod(Module)

or

Import Module as M
reload(M)

 

This synthax doesn't work in python 3 there it goes as follows:

Import Module
Import importlib
importlib.reload(Module)

or

Import Module as M
Import importlib
importlib.reload(M)

 

so importing import lib and adding "importlib." infront of your reload statements should fix your issues.

 

But ... the reload statement is used to load in changes into Maya after you already loaded in the Module. This means that the Module that gets loaded has had changes made to it. So normally reload statements aren't found in finished scripts. So alternatively you could problably just get rid of your reload statement and then restart maya and execute the script without them.

 

I hope this helps!

Message 3 of 3

michael--n
Explorer
Explorer

As Kahylan said, you shouldn't be adding a reload to your scripts at all. You might inadvertently reinitialised module members, which can cause issues with global variables and classes.


This gives a good example: https://thingspython.wordpress.com/2010/09/27/another-super-wrinkle-raising-typeerror/

I only put them in the script editor, to reload scripts when I'm testing changes, but not in the scripts themselves.

0 Likes