Fetch values in a doctype - custom script


Is it possible to fetch values wih the field name in .py file instead using the position to fetch values.

Eg if i have name,sex,bood group in doctype. Now im reading the value of name as row[0], sex as row[1] and blood_group as row[2]. But i need to get it as row[‘blood group’].

Is it possible. If possible please help me how to do

if your code is part of class then you can access fields as self.fieldname.

If you are using hooks, then use doc.fieldname.

Else create dictionary Python Dictionary, to achieve desired.