There is an array of several elements, one of the elements takes a null value (that is, there is nothing inside), but the second and subsequent ones have some content, the question is how to address the second element (which contains data) and write the content to a variable? So that later you can write to the newly created form - if you need to, I can explain in a little more detail what kind of form it is.

Actually the array itself

texture.longName ##

and contents

(1) * longName : <None> (2) * longName : objects\pc\lm\mesh\lmcl_cash_koreandress09_body.dds (3) * longName : objects\pc\lm\mesh\lmcl_cash_koreandress07_head.dds 

A texture is a kind of data container, from a file, and to access specific data, it simply indicates the name of the desired element (in my case it is longName). But for example there is still

 * type : ENVIRONMENT 

and if you specify texture.type, it will display ENVIRONMENT, it’s me to ask that there are no questions - what kind of array is this! I'm just not very strong in python, and I don’t understand how to get the value of the second element in a variable, I hope someone will explain!

  • About how to address the second element in the list you have already answered, if you solve some other problem, then it needs to be described in the question. It’s not clear from your comments to Igor’s answer why this second element needs to be checked for None, if it’s not the next task and it’s not None, and how you want to form a form is also not clear. - idle sign
  • @idlesign, Um, there is a problem in my ignorance of python, because I can not understand why the cycle will interfere with the elements - in the form of daeImage.initFrom , in turn, that is, not from an array, but one by one, here’s how [null] , [object], [object1] - so he adds From the beginning of Null to the form, then the cycle repeats and the object is already obstructed in the form, it is understood that null, object, object1, are not initially interfered with the array, but are taken as it is from source data one by one Simply put, there is no access to the first love (after the call) Maybe I can attach more source code For I don’t understand how I can understand it . - LightFusion
  • Unfortunately, after your comment the task did not become clearer. Yes, perhaps you should attach the code, but what needs to be done is to show what you already have (initial data + your work on solving the problem), and to formulate what you want to get at the output. - idle sign
  • pastebin.com/kSmhKkfA I really don’t know how it will help you, for now the call is texture.longName [0: 1], it brings me the first letter of the line (and for the first line _cash_koreandress09_body, and for the second _cash_koreandress07_head, that is, it processes as strings, not as objects), but I need to output the first line with all its contents (that is, _cash_koreandress07_head), the python is just awful ... - LightFusion
  • I didn’t see the texture or initForm in the link. Prints the first letter because you ask him about it: texture.longName [0: 1] - it says to take a character from position 0 to position 1, that is, the first letter. If you need the entire string, refer directly to texture.longName. - idle sign

1 answer 1

Contact as follows:

 texture.longName[1] 

In Python, the square brackets [] are used to index the array, the numbering starts from 0, so the second element has the index 1.

Update 1

Check if the first (i.e. zero) element is None :

 if texture.longName[0] is None: # doing something 

Check whether the array is equal to None (in this case, it is, of course, not an array, but None ):

 if texture.longName is None: # doing something 

Check whether there is the first (that is, zero) element in the array or there is no element (that is, the array is empty):

 if len( texture.longName ) > 0: # doing something 

** Update 2 **

If your data is not presented as an array, but as a string containing elements separated by a comma or in some other way, then you can split the line into a list of elements using the split operation.

  my_str.split(',') 

If splitting is done in a more complex way, and not just a comma, then regular expressions (the re module) and the re.split and re.find functions can be useful to you.

  • # And where should I start checking - if the element is None? # ## Before accessing the record in a new form, this way ## texName = texture.longName if texName is None: texName = texture.longName[1] , or when reversing daeImage.initFrom = texture.longName if daeImage.initFrom is None: daeImage.initFrom = texture.longName[1] ? Or am I missing something else? - LightFusion
  • Apparently the problem is precisely in the appeal to the array in the check, if it calls in such a way if texName is None: then it will go through all the elements, and of course there will be Not None, but how should I apply for the first element, `if texName [1]` - does not work, if declared as a variable `texRname2 = texture.longName [0]` that also does not work? How to be? - LightFusion
  • @LightFusion: Added another update on how to check the first element / array for equality None - Igor Chubin
  • the problem is that the array texture.LongName takes the contents of all elements as a whole line (and therefore when I access the element I get an error - Out of range error), I really don’t really understand how DaeImage.Inifrom understands where to start separating it, Well, as far as I understand it is necessary to change a bit earlier (when the array itself is still filled) - LightFusion
  • @LightFusion: See another update - Igor Chubin