<div dir="ltr"><br><br><div class="gmail_quote">On Thu, Jul 31, 2008 at 8:07 AM, S Python <span dir="ltr">&lt;<a href="mailto:spython01@gmail.com">spython01@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr"><div>Hi Everyone,</div>
<div>&nbsp;</div>
<div>I am trying to read a comma-delimitted list (&quot;aaa&quot;,&quot;bbb&quot;,&quot;ccc&quot;) from a text file and assign those values to a list, x, such that:</div>
<div>&nbsp;</div>
<div>x&nbsp;= [&quot;aaa&quot;, &quot;bbb&quot;, &quot;ccc&quot;]</div>
<div>&nbsp;</div>
<div>The code that I have come up with looks like this:</div>
<div>&nbsp;</div>
<div>&gt;&gt;&gt; x = []<br>&gt;&gt;&gt; f = open(r&#39;c:\test.txt&#39;, &#39;r&#39;)<br>&gt;&gt;&gt; x.extend(f.readlines())<br>&gt;&gt;&gt; x<br>[&#39;&quot;aaa&quot;,&quot;bbb&quot;,&quot;ccc&quot;&#39;]</div>
<div>&nbsp;</div>
<div>If you look closely, there is an extra pair of single quotes (&#39;) that encapsulates the string.&nbsp; Therefore, len(x) returns 1, instead of 3.&nbsp; Is there a function to &quot;separate&quot; this list out?&nbsp; I hope my question makes sense.</div>


<div>&nbsp;</div>
<div>Thanks in advance.</div>
<div>&nbsp;</div>
<div>Samir</div>
<div>&nbsp;</div></div></blockquote><div>This is an answer by a novice, and it may not be the best around;<br>Why don&#39;t you first get rid of the quotation marks and then split on the comma:<br><br>&gt;&gt;&gt; f = open(r&#39;c:\test.txt&#39;, &#39;r&#39;).read().replace(&#39;&quot;&#39;, &#39;&#39;)<br>
&gt;&gt;&gt; x = []<br>&gt;&gt;&gt; x.extend(f.split(&quot;,&quot;))<br>&gt;&gt;&gt; x<br>[&#39;aa&#39;, &#39; bb&#39;, &#39; cc&#39;]<br>&gt;&gt;&gt; len(x)<br>3<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr"><div></div>
<div>&nbsp;</div></div>
<br>_______________________________________________<br>
Tutor maillist &nbsp;- &nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد الغزالي<br>&quot;No victim has ever been more repressed and alienated than the truth&quot;<br>
<br>Emad Soliman Nawfal<br>Indiana University, Bloomington<br><a href="http://emnawfal.googlepages.com">http://emnawfal.googlepages.com</a><br>--------------------------------------------------------<br>
</div>