0
$\begingroup$

How to check whether the list (of vertices) exists?

I want to append a new vertex to a list or create one if it does not exists.

if verts is not exist:
    verts = [[0,0,0]]
    edges = []
    faces = []
else: verts.append([1,1,1])
$\endgroup$
3
$\begingroup$

If you want to test whether a variable exists, you can follow this solution and see if it's in locals() or globals(). So your code would be

if 'verts' in globals() or 'verts' in locals():
    verts.append([1,1,1])
else:
    verts = [[0,0,0]]
    edges = []
    faces = []
$\endgroup$
1
$\begingroup$

You could initialize your list like:

verts = None

...

if verts is not None:
    verts = [[0,0,0]]
    edges = []
    faces = []
else: 
    verts.append([1,1,1])

Also you could initialize everything:

    verts = []
    edges = []
    faces = []

and simply invoke append later on (without having the need to do any tests):

    verts.append([1,1,1])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.