<div dir="ltr"><div>Hi Joshua,</div>
<div> </div>
<div>Got it. Thanks. I am misiing the "seek" part.</div>
<div> </div>
<div>Thanks again,</div>
<div>David<br><br></div>
<div class="gmail_quote">On Tue, Aug 26, 2008 at 4:14 PM, Joshua Gallagher <span dir="ltr"><<a href="mailto:joshua.gallagher@gmail.com">joshua.gallagher@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi David,<br><br>When you read and write into a file, you read and write at offsets.<br>You can think of the offset as a moving cursor in the file. In other<br>
words, if you create a new file and write 10 bytes in, your cursor is<br>10-bytes into the file. If you perform another write, the write<br>starts at byte 10. By extension, if your cursor is at byte 10 of this<br>new file and you do a read, there's nothing at the end of the file to<br>
read.<br><br>If you've written to a file and want to reread it without closing it<br>you need to seek (<a href="http://docs.python.org/lib/bltin-file-objects.html" target="_blank">http://docs.python.org/lib/bltin-file-objects.html</a>)<br>
if you have a file object or lseek<br>(<a href="http://docs.python.org/lib/os-fd-ops.html" target="_blank">http://docs.python.org/lib/os-fd-ops.html</a>) if you have a file<br>descriptor.<br><font color="#888888"><br>Joshua<br>
</font>
<div>
<div></div>
<div class="Wj3C7c"><br><br><br>On Tue, Aug 26, 2008 at 3:56 PM, David Elsen <<a href="mailto:elsen.david08@gmail.com">elsen.david08@gmail.com</a>> wrote:<br>> Alex,<br>><br>> Thank you for your reply.<br>
><br>> Actually I had modified the text file before posting. It has four words in<br>> one line seperated by space. I was using the split with space to get all<br>> four words from a line. I was appending one word to my list (list of<br>
> strings).<br>><br>> I was wondering once I am using split function whether it converts the<br>> "numbers" from my text file to some particular formats. I was trying to cast<br>> the split output with "map", "long" etc, but it gives the error message<br>
> that for it can not accept the non-string input.<br>><br>> I tried to look around for split reference, but nowhere got its return type<br>> format information. It seems like string ['0xdeadfeed']. But it does not<br>
> seem to be. If it is really string type, why cast from "map", "int", or<br>> "long" is giving me error message.<br>><br>> I apologize for becoming the time sink. I am ready to become the time<br>
> source.<br>><br>> I have one more question though related to my same script. Please forgive me<br>> about this. If I am trying to write my text file in the same script and then<br>> tring to read back. For some reason, read file handle does not have any<br>
> data.<br>><br>> But if I have written to the text file and saved it and then trying to open<br>> it in read mode, I am able to read the data. Is there any delay required<br>> after writing the data to a file?<br>
><br>> Thanks,<br>> David<br>><br>> Thanks again,<br>> David<br>><br>><br>><br>><br>><br>><br>> On Tue, Aug 26, 2008 at 1:26 PM, Alex Martelli <<a href="mailto:aleax@google.com">aleax@google.com</a>> wrote:<br>
>><br>>> You should really study some of the basics of Python -- e.g. via the<br>>> mailing list <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a> or any of<br>
>> the other resources listed at<br>>> <a href="http://wiki.python.org/moin/BeginnersGuide" target="_blank">http://wiki.python.org/moin/BeginnersGuide</a> -- this mailing list is for<br>>> the Bay Area Python Interest Group and not particularly suitable for<br>
>> your questions. In this case, you're appending to your list reg items<br>>> that are lists of strings (with one item only in each sublist,<br>>> apparently) and you apparently want to convert that list of lists of<br>
>> strings to a list of integers -- and give no indication whatsoever<br>>> about what you mean to happen when one of the sublists has more than<br>>> one item (i.e. any of the text lines in file ask_it.txt [apart from<br>
>> the first four] has more than one word), or any of the words are not a<br>>> correct representation for an integer, and so forth. If you know the<br>>> "more than one word in a line" can never happen, then it makes no<br>
>> sense to have that "datas = line.split()" call -- why are you<br>>> splitting unless >1 word is possible?!<br>>><br>>> <a href="http://www.catb.org/~esr/faqs/smart-questions.html" target="_blank">http://www.catb.org/~esr/faqs/smart-questions.html</a> is a document<br>
>> really worth studying (quite apart from Python, ANY time you need to<br>>> ask technical questions) and it includes worthy quotes such as "What<br>>> we are, unapologetically, is hostile to people who seem to be<br>
>> unwilling to think or to do their own homework before asking<br>>> questions. People like that are time sinks — they take without giving<br>>> back, and they waste time we could have spent on another question more<br>
>> interesting and another person more worthy of an answer."<br>>><br>>><br>>> Alex<br>>><br>>> On Tue, Aug 26, 2008 at 1:02 PM, David Elsen <<a href="mailto:elsen.david08@gmail.com">elsen.david08@gmail.com</a>><br>
>> wrote:<br>>> > Hi all,<br>>> ><br>>> > I have a test script as follows:<br>>> ><br>>> > import os<br>>> > import string<br>>> > cmd = './testtool dump'<br>
>> > res = os.popen(cmd).read()<br>>> > #print res<br>>> > #fout = open("ask_it.txt", "w")<br>>> > #fout.write(res)<br>>> > #fout.close<br>>> > reg_reset_val = []<br>
>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>
>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>
>> > reg_reset_val.append(0xdeadfeed)<br>>> > reg_reset_val.append(0xdeadfeed)<br>>> ><br>>> > print 'reg default values'<br>>> > for index, item in enumerate(reg_reset_val):<br>
>> > print index, item<br>>> ><br>>> > fin = open ("ask_it.txt", "r")<br>>> > i = 0<br>>> > reg = []<br>>> > linelist = fin.readlines()<br>>> > lines = len(linelist)<br>
>> > for line in linelist:<br>>> > i = i +1<br>>> > if (i >= 5): # First four lines are bogus<br>>> > datas = line.split()<br>>> > reg.append(datas)<br>>> > if i == lines:<br>
>> > break<br>>> > print 'the reg list is'<br>>> > for j, item in enumerate(reg):<br>>> > print j, item<br>>> > print 'reg[0]'<br>>> > print reg[0]<br>
>> > print 'reg_reset_val[0]0x%x'%reg_reset_val[0]<br>>> > #print reg_reset_val[0]<br>>> > if (reg[0] == reg_reset_val[0]):<br>>> > print 'test passed'<br>>> > else:<br>
>> > print 'test failed'<br>>> ><br>>> ><br>>> > Calling to driver via IOCTL Control Memory Dump buf addr = 0x804d008.<br>>> > Returned from calling driver via IOCTL.<br>
>> > IOCTL CTL Mem Dump char count<br>>> > Control Memory Dump: Address 0xf8812000<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>
>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > 0xdeadfeed<br>>> > I am expecting the "reg[0]" and "reg_reset_val[0]" to be the same. But<br>
>> > reg[0] is list and has ['0xdeadfeed'] in it and reg_reset_val[0] has<br>>> > 0xdeadfeed in it. How can I convert the reg[0] to make it normal<br>>> > 0xdeadfeed.<br>>> ><br>
>> > Thanks,<br>>> > David<br>>> ><br>>> ><br>>> ><br>>> > _______________________________________________<br>>> > Baypiggies mailing list<br>>> > <a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
>> > To change your subscription options or unsubscribe:<br>>> > <a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>>> ><br>
><br>><br>> _______________________________________________<br>> Baypiggies mailing list<br>> <a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>> To change your subscription options or unsubscribe:<br>
> <a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>><br></div></div></blockquote></div><br></div>