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
 All Forums
 Origin Forum for Programming
 Forum for Python
 parser error when using lr.result()

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
wies_ph Posted - 09/10/2021 : 05:03:15 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 09/10/2021 : 4:32:51 PM
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}')


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000