Hey,<br><br>I&#39;m a newbie and this is my first script submission to this email list.<br>I was able to parse out the jobs list into a string: &quot;jobs = [ . . .&quot;<br>However, I can&#39;t make python interpret that string as the command &quot;jobs = [ some list]&quot;
<br><br>#SCRIPT<br><br># open the file and assign it to the variable &quot;thefile&quot;<br>thefile = open(&quot;/home/banter/Desktop/mylist.py&quot;) <br><br># read the file and assign it to the variable &quot;read_thefile&quot;
<br>read_thefile = file.read(thefile)<br><br># make the file&#39;s contents into a string<br>string_thefile = str(read_thefile)<br><br># split that string up into a list<br>splitlist_thefile = string_thefile.split()<br><br>
# index the list to find the placement of the word &#39;jobs&#39;<br>it_starts = splitlist_thefile.index(&#39;jobs&#39;)<br><br># index the list to find the placement of the &#39;]&#39;<br># bug warning: an item in list &quot;job&quot; with a bracket will
<br>#&nbsp;&nbsp;&nbsp; throw off this script<br># Also, there needs to be a comparison between instances of<br># &#39;]&#39; such that the returned index number will be the smallest<br># number that is still larger than &#39;it_starts&#39;
<br>it_almost_ends = splitlist_thefile.index(&#39;]&#39;)<br><br># the ending index number is not good enough<br># we need to add a 1 to the number<br># read this to find out why<br># <a href="http://www.diveintopython.org/native_data_types/lists.html">
http://www.diveintopython.org/native_data_types/lists.html</a><br>it_ends = it_almost_ends + 1<br><br># assign the data that you want to a variable<br># if you have a question about this, then you<br># probably didn&#39;t read the link above
<br>wanted_data = splitlist_thefile[it_starts:it_ends]<br><br># join it all up<br>joined = &quot; &quot;.join(wanted_data)<br><br>print joined<br><br>#END SCRIPT<br><br>So close yet so far away!<br><br>oh, and Alan, are you getting a duplicate copy of this email? I am CCing 
tutor@python and TOing you . . .<br><br>Best,<br><br>Grant Hagstrom<br><br><div><span class="gmail_quote">On 6/1/07, <b class="gmail_sendername">Alan Gauld</b> &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>&quot;Preecha Bundrikwong&quot; &lt;<a href="mailto:preecha88@gmail.com">
preecha88@gmail.com</a>&gt; wrote<br><br>&gt; I have a text file (mylist.py actually), it contains exactly below:<br>&gt; ---------------<br>&gt; # file mylist.py<br>&gt; jobs = [<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;Lions&#39;,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;SysTest&#39;,
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]<br>&gt; ----------------<br>&gt;<br>&gt; I want to write another script and get the list &quot;jobs&quot; from the<br>&gt; above<br>&gt; script.<br><br>Because this is a python file and python files are effectively
<br>modules you can use import:<br><br>import mylist<br>print mylist.jobs<br><br>&gt; Is it possible for me to get the variable &#39;jobs&#39; and its value from<br>&gt; the file<br>&gt; (as a list)? What I&#39;m trying to do now is open the file, readlines
<br>&gt; in a<br>&gt; loop, once it finds the line with &quot;jobs = [&quot;, then start accumulate<br>&gt; (append)<br>&gt; a varible until it hits the line with &quot;]&quot; then stop.<br><br>If it wasn&#39;t a python file (some other language say) then that is
<br>exactly what you would need to do. Programming often makes<br>apparently simple things seem complicated! :-)<br><br>Alan G.<br><br><br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org">
Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>