python - Pymel: How do I extract these vector floats from a complex .TXT file? -


i having trouble wrapping head around how extract float values complex text file in pymel. not programmer, artist, in need of creating script specific workflow process , have beginner level knowledge of python.

my goal: create objects in 3d space (x,y,z) coordinates parsed specific text file program.

ex. of text file:

point 1 8.740349 -4.640922 103.950059
point 2 8.520906 3.447561 116.580496
point 3 4.235010 -7.562914 99.632423
etc., etc

there's more space in text file between point #'s , vector floats.

i want create dictionary use create objects in 3d program.

for example,

mydictionary = {(point 1),[8.740349,-4.640922,103.950059]), etc. }.

this code snippet far:

def createlocators(): global filepath  global markernum global markercoord   print "getting farther! :)" open(filepath,'r') readfile:     line in readfile:                    if "point" in line:                          types = line.split('                                                            ')             markernum = [type[1] type in types]             markercoord = [type[2] type in types]             print markernum, markercoord 

as can see in code, space between information long. figure if can remove space can 2 data sets easier work with. there many more lines in text document don't care about, hence if statement filter lines start "point". when run createlocator() test see if it's splitting lines 2 lists runs fine, print looks empty me.

ex.

[' '] [' ']

i've tried googling , searching answers here on so, , searching both pymel , regular python documentation i'm doing wrong or better approaches, have admit extent of knowledge ends here.

what doing wrong? there better , more efficient way extract data need i'm missing?

thanks reading!

first, not want splitting on massive string of spaces. in fact want use line.split() no arguments, split apart text on kind, , amount, of whitespace. i.e:

>>> 'a b      c\t\n\t   d'.split() ['a', 'b', 'c', 'd'] 

then, assuming format you've shown correct, should need need types[2:5], i.e. second, third, , fourth elements of types, coordinates.

beyond this, should not using capital names local variables, , should not using global variables. use function arguments instead, , rename types split_line or something.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -