Python In blender 2.53

Someone know how i check if my object has a property named something with something value?

This is my code from 2.49 and it dosent work in the blender 2.53

    if obj.has_key("walk") == False:            
        
        obj["walk"] = 5.0

Whould be lovely if someone can help me with this :slight_smile:

if (“walk” in obj) == False:
to convert old scripts use:
\Python3.1\Tools\Scripts\2to3.py

I’m a noob in python, but I think that it would go like:

if [“walk”] in obj == False:
obj[“walk”] = 5.0

Correct me if I’m wrong!

I have been looking on that 2to3 script but i cant understand how to do it. I got a walk script that i want to translate but can someone give me an “tutorial” how to do it? can fix allot of my scripts then.

And thx for the replies :slight_smile:

Nvm :slight_smile: Now i have learnt how to do it :slight_smile:

Place the 2.x script that you want to change in a folder that also contains this script.

import subprocess

python2x_scriptfile = "TheScriptYouWantToConvert.py"

subprocess.call([r"C:\\Python31\\Python.exe",

r"C:\\Python31\\Tools\\Scripts\\2to3.py",

"-w",
python2x_scriptfile])

Open up the script you just made in Python 3 GUI and run it. It will make a backup of the script you converted and overwrite the one with the new code that works in Blender 2.5! Works perfectly!

If you just want to make sure that a property exist suround it with try…except.
This is the fastes method if the property exist in most of the cases.


try:
  way = own["way"]
except:
  # property does not exist
  ...

If the property most likely does not exist use:


if not "way" in own:
  # property does not exist