Python, Recursive Functions and Returns

Written by mattanimation. Posted in Python, Uncategorized

So, I found out the other other day that if you want to have a value returned when using a recursive function you must include the return line in each instance of the return. Example:

Incorrect way:

 def cleanMyString(self, url):
      returnURL = ''
      if ':' in str(url.encode('utf-8')):
           fixMe = url.replace(':', '_')
           self.clean(fixMe)
      elif '$' in str(url.encode('utf-8')):
           fixMe = url.replace('$', '-')
           self.clean(fixMe)
      else:
            returnURL = url
           return returnURL

The result of this method is None unless the string did not match any of the conditions to re-curse.

Correct way:

 def cleanMyString(self, url):
      returnURL = ''
      if ':' in str(url.encode('utf-8')):
           fixMe = url.replace(':', '_')
           return self.clean(fixMe)
      elif '$' in str(url.encode('utf-8')):
           fixMe = url.replace('$', '-')
           return self.clean(fixMe)
      else:
          returnURL = url
          return returnURL

 

so we can see that instead of calling the function directly we need to put return in front, otherwise we get a return value of None.

Ignore what I said about QT in Maya

Written by mattanimation. Posted in Uncategorized

Well I was reading this post by Nathan Horne of Naughty Dog and read this :

How to load a designer file
  • DO NOT USE cmds.loadUi!!!
    • seriously, don’t.. forget it exists, now.
    • Who ever wrote it needs to be punched in the mouth.

 

This abruptly caught my attention. The article itself had already convinced me to want to use PySide and PyQt to code UIs but left me on the fence wether to use the QTDesigner or not, until I read this. Either way it is a very good read, take a look and listen to the experts!

The New Site

Written by mattanimation. Posted in Uncategorized

Well I finally got around to creating a new layout for my site. The old one was in flash and I didn’t feel like trying to program in all the functionality these fancy wordpress sites have like posting like this and nice back end user interface. Enjoy the new content!