[Baypiggies] Is this a conversion problem? Can I get help to resolve this please?

Alex Martelli aleax at google.com
Tue Aug 26 22:26:32 CEST 2008


You should really study some of the basics of Python -- e.g. via the
mailing list http://mail.python.org/mailman/listinfo/tutor or any of
the other resources listed at
http://wiki.python.org/moin/BeginnersGuide -- this mailing list is for
the Bay Area Python Interest Group and not particularly suitable for
your questions.  In this case, you're appending to your list reg items
that are lists of strings (with one item only in each sublist,
apparently) and you apparently want to convert that list of lists of
strings to a list of integers -- and give no indication whatsoever
about what you mean to happen when one of the sublists has more than
one item (i.e. any of the text lines in file ask_it.txt [apart from
the first four] has more than one word), or any of the words are not a
correct representation for an integer, and so forth.  If you know the
"more than one word in a line" can never happen, then it makes no
sense to have that "datas = line.split()" call -- why are you
splitting unless >1 word is possible?!

http://www.catb.org/~esr/faqs/smart-questions.html is a document
really worth studying (quite apart from Python, ANY time you need to
ask technical questions) and it includes worthy quotes such as "What
we are, unapologetically, is hostile to people who seem to be
unwilling to think or to do their own homework before asking
questions. People like that are time sinks — they take without giving
back, and they waste time we could have spent on another question more
interesting and another person more worthy of an answer."


Alex

On Tue, Aug 26, 2008 at 1:02 PM, David Elsen <elsen.david08 at gmail.com> wrote:
> Hi all,
>
> I have a test script as follows:
>
> import os
> import string
> cmd = './testtool  dump'
> res = os.popen(cmd).read()
> #print res
> #fout = open("ask_it.txt", "w")
> #fout.write(res)
> #fout.close
> reg_reset_val = []
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
> reg_reset_val.append(0xdeadfeed)
>
> print 'reg default values'
> for index, item in enumerate(reg_reset_val):
>  print index, item
>
> fin = open ("ask_it.txt", "r")
> i = 0
> reg = []
> linelist = fin.readlines()
> lines = len(linelist)
> for line in linelist:
>  i = i +1
>  if (i >= 5): # First four lines are bogus
>   datas = line.split()
>   reg.append(datas)
>   if i == lines:
>    break
> print 'the reg list is'
> for j, item in enumerate(reg):
>  print j, item
> print 'reg[0]'
> print reg[0]
> print 'reg_reset_val[0]0x%x'%reg_reset_val[0]
> #print reg_reset_val[0]
> if (reg[0] == reg_reset_val[0]):
>  print 'test passed'
> else:
>  print 'test failed'
>
>
> Calling to driver via IOCTL Control Memory Dump buf addr = 0x804d008.
> Returned from calling driver via IOCTL.
> IOCTL CTL Mem Dump char count
> Control Memory Dump:  Address 0xf8812000
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> 0xdeadfeed
> I am expecting the "reg[0]" and "reg_reset_val[0]" to be the same. But
> reg[0] is list and has ['0xdeadfeed'] in it and reg_reset_val[0] has
> 0xdeadfeed in it. How can I convert the reg[0] to make it normal 0xdeadfeed.
>
> Thanks,
> David
>
>
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>


More information about the Baypiggies mailing list