[Tutor] Python function argument passing problem

Manoj Rout manojrout70 at gmail.com
Thu Jan 9 01:33:37 CET 2014


Hi,






I have been working with python from last couple of weeks. As I am new to
python I have a problem with my work. So can you please look into the below
code.





import re

with open('C:\\Users\\Manoj\\Desktop\\XMC1100_rm_v1.0.6_SVD.xml','r') as
xmlfile:

                svdlines = xmlfile.readlines()

                def func_register(num):

                                for num,svdline in enumerate(svdlines):

                                                if '<register>' in svdline:

                                                                start =
num+1

                                                                break

                                for num,svdline in
enumerate(svdlines[start:]):

                                                if '</register>' in svdline:

                                                                end = num+1

                                                                end =
start+end

                                                                break

                                count=0

                                for num,svdline in
enumerate(svdlines[start:end]):

                                                if '<name>' in svdline:

                                                                count +=1

                                                                if count ==
1:


Registername = re.findall('name>([^ ]*)<',svdline)


print "Register Name is:",Registername

                                                if '<addressOffset>' in
svdline:


OffsetAddress_SVD = re.findall('addressOffset>([^ ]*)<',svdline)

                                                                print
"OffsetAddress is :",OffsetAddress_SVD

                                                if '<resetValue>' in
svdline:


resetvalue_SVD = re.findall('resetValue>([^ ]*)<',svdline)

                                                                print
"resetValue in SVD is :",resetvalue_SVD

                                                                end=end+1

                                                                print end







   Here I want to define a recursive function func_register  which will
take the whole contents  of file and file pointer position  in  first
iteration  and do the assigned work. After first iteration  it will update
the file pointer position . Then in second iteration it should start from
that particular position of that file .



                                I have written the above code and this code
will work if it is not inside the function. i. e outside the “def
func_register()”. So could you please help me iin this and also I have
added the file .







Thanks and regards,

Manoj Kumar Rout
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140109/351a4c9f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: XMC1100_rm_v1.0.6_SVD.xml
Type: text/xml
Size: 781731 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20140109/351a4c9f/attachment-0001.xml>


More information about the Tutor mailing list