Engineers h3x3r Posted March 5 Engineers Posted March 5 Hi, can somebody please help me out with this? i want to use var "RwShapeIndex" from "i loop" in "j loop" how i can do that if anyone know. Thanks in advance! bs.seek(RwShapeIndexTableOffset, NOESEEK_ABS) for i in range(0, RwVertexInfoCount): RwUnknown_0 = bs.readUShort() RwUnknown_1 = bs.readUShort() RwShapeIndex = bs.readUShort() bs.seek(RwVertexInfoOffset, NOESEEK_ABS) for j in range(0, RwVertexInfoCount): Underline = "_" RwShapeInc = j RwShapeIdxNum = "{:04d}".format(RwShapeIndex) RwShapeIndexTmp = str(RwShapeIdxNum) print(RwShapeIndexTmp)
Engineers h3x3r Posted March 5 Author Engineers Posted March 5 (edited) If you mean something like that > RwShapeIdxNum = "{:04d}".format(RwShapeIndex[i]) it doesn't work. I also created initial var RwShapeIndex = [] Saying > RwShapeIdxNum = "{:04d}".format(RwShapeIndex[i]) TypeError: 'int' object is not subscriptable Edited March 5 by h3x3r
Engineers shak-otay Posted March 5 Engineers Posted March 5 yeah, that's the reason I usually don't use python. There's solutions which say: Quote To fix this error, you need to convert the integer to an iterable data type, for example, a string. but that sounds funny to me.
Engineers h3x3r Posted March 5 Author Engineers Posted March 5 Already tried. No luck... Yeah i like python too... 🙃Anyway thank you for your time.
Engineers Solution Rabatini Posted March 5 Engineers Solution Posted March 5 Did you tried Store RwShapeIndex Values in a List? Somenthing like that? bs.seek(RwShapeIndexTableOffset, NOESEEK_ABS) rw_shape_indices = [] # Create a list to store RwShapeIndex values for i in range(0, RwVertexInfoCount): RwUnknown_0 = bs.readUShort() RwUnknown_1 = bs.readUShort() rw_shape_indices.append(bs.readUShort()) # Append to the list bs.seek(RwVertexInfoOffset, NOESEEK_ABS) for j in range(0, RwVertexInfoCount): Underline = "_" RwShapeInc = j RwShapeIndex = rw_shape_indices[j] #get the value from the list using the j index. RwShapeIdxNum = "{:04d}".format(RwShapeIndex) RwShapeIndexTmp = str(RwShapeIdxNum) print(RwShapeIndexTmp) 2 1
Engineers shak-otay Posted March 5 Engineers Posted March 5 That's funny. Isn't rw_shape_indices a list of ints (shorts) while python claims an array of ints not to be subscriptable? The magic is append - apparently python prefers lists over arrays because these have a fixed size.
Engineers Rabatini Posted March 5 Engineers Posted March 5 59 minutes ago, shak-otay said: That's funny. Isn't rw_shape_indices a list of ints (shorts) while python claims an array of ints not to be subscriptable? The magic is append - apparently python prefers lists over arrays because these have a fixed size. Lists are the default go-to dynamic sequence type in Python because of their flexibility. The append method works naturally on lists, while array.append() requires that the appended value be of the correct type. Many Python libraries and frameworks default to lists for simplicity. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now