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