The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 parser error when using lr.result()
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

wies_ph

Germany
1 Posts

Posted - 09/10/2021 :  05:03:15 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'd like to use the lr.result() function for ending my linear fit. When I use report everything worksout, although I don't want all these linear fit sheets.
My code is exactly as the example, except the for-loop.

for i in range(wks_all.cols):
lr = op.LinearFit()
lr.set_data(wks_all, 0, i)
rr = lr.result()
b = rr['Parameters']['Slope']['Value']
b_err = rr['Parameters']['Slope']['Error']

When I run my script i get the following error message (fit.py is the program i use):


Traceback (most recent call last):
File "<string>", line 6, in <module>
File "C:\Users\wies_ph\Documents\OriginLab\Anwenderdateien\fit.py", line 64, in <module>
rr = lr.result()
File "C:\ProgramData\OriginLab\98\PyPackage\Py3\originpro\analysis.py", line 263, in result
dd = lt_tree_to_dict(trOut)
File "C:\ProgramData\OriginLab\98\PyPackage\Py3\originpro\utils.py", line 599, in lt_tree_to_dict
tr = ET.fromstring(xml)
File "C:\PROGRA~1\ORIGIN~1\ORIGIN~1\Python38.zip\xml\etree\ElementTree.py", line 1321, in XML
xml.etree.ElementTree.ParseError: unclosed token: line 2, column 4214

Does anyone know why this is or how i can fix it? I hope it's just not me being stupid. ;)
Thank you

cpyang

USA
1406 Posts

Posted - 09/10/2021 :  4:32:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, we can see there is an issue when using this in a loop, but can you try having the lr class outside like this?

import originpro as op
wks_all = op.find_sheet()
lr = op.LinearFit()
for i in range(wks_all.cols):
    if i==0:
        continue
    print(f'col({i+1}):')
    lr.set_data(wks_all, 0, i)
    rr = lr.result()
    b = rr['Parameters']['Slope']['Value']
    b_err = rr['Parameters']['Slope']['Error']
    print(f'slope={b}+-{b_err}')

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000