<br><br><div class="gmail_quote">On Fri, Mar 13, 2009 at 5:01 PM, Daniel Sidorowicz <span dir="ltr"><<a href="mailto:dsi1289@gmail.com">dsi1289@gmail.com</a>></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 class="im"><div>For instructions open file named README</div></div><div class="im"><div>Enter control-C to quit</div></div><div>Traceback (most recent call last):</div><div>  File "main.py", line 57, in <module></div>
<div>    main()         </div>
<div>  File "main.py", line 16, in main</div><div>    S = L.split()</div><div class="im"><div>AttributeError: 'list' object has no attribute 'split'</div><div> </div></div><div>So there's my whole trace back error.</div>

<div><br></div><div>I somewhat understand what your are talking about,</div><div>expect when I do readline it will only run the function with the first line of my file abc.txt </div><div>which includes all the variables i need to pass in.</div>

<div><br></div><div>My file abc.txt looks like;</div><div>0 0 0</div><div>0 0 1</div><div>1 0 1</div><div>that's just an example.</div><div><br></div><div>Now I need it to save each line as a a string so I can run with in my program.</div>

<div><br></div><div>Thanks for being helpful.</div></blockquote><div><br>You're going to want to loop through L. Every element in L is a string, and you can call split on each individual element. Since this is a homework assignment, I don't want to give too much away. Try looking at the docs if you don't understand how to use lists.<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></div><div><div></div><div class="h5"><br><div class="gmail_quote">On Fri, Mar 13, 2009 at 3:17 PM, Benjamin Kaplan <span dir="ltr"><<a href="mailto:benjamin.kaplan@case.edu" target="_blank">benjamin.kaplan@case.edu</a>></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;"><br><br><div class="gmail_quote"><div><div></div><div>On Fri, Mar 13, 2009 at 4:06 PM, Daniel Sidorowicz <span dir="ltr"><<a href="mailto:dsi1289@gmail.com" target="_blank">dsi1289@gmail.com</a>></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;">
Hello I need some hello I need some help with a programing<div>project, I'm fairly new to programming so I do find it slightly confusing.</div><div><br></div><div>Here is my code for my main function which</div><div>

passes my variable from a text file,</div>

<div>however when i run it I get the error code:</div><div><br></div><div><div>import math</div><div>import quadroot</div><div>                     </div><div>def main():</div><div>        print "\n--------------------------------------------\n"</div>



<div>        print "Daniel Sidorowicz \n", "325 \n", "MCS 260, Spring 2009 \n", "mp1id325"</div><div>        print "For instructions open file named README"</div><div>        print "Enter control-C to quit"</div>



<div>        infile = open("abc.txt",'r')   </div><div>        L = infile.readlines()</div><div>        S = L.split()</div><div>        print S</div><div>        infile.close()</div><div>        outfile = open("output.txt",'a')</div>



<div>        eq = "ax^2.0 + bx + c = 0\n"</div><div>                       </div><div>        for line in L:</div><div>                      </div><div>                coef= a,b,c = (float(S[0]),float(S[1]),float(S[2]))</div>



<div>                print coef</div><div>                print "\n--------------------------------------\n"</div><div>                d = b**2.0 - 4.0*a*c</div><div><br></div><div>                if a != 0:</div>



<div>                    if d == 0.0 :</div><div>                     outfile.write(eq)</div><div>                     outfile.write(str(quadroot.root1(a,b,c,d)))</div><div>                    elif d > 0.0 :</div><div>



                     outfile.write(eq)</div><div>                     outfile.write(str(quadroot.root2(a,b,c,d)))</div><div>                    elif d < 0.0 :</div><div>                     outfile.write(eq)</div><div>



                     outfile.write(str(quadroot.root3(a,b,c,d)))</div><div>                    else :</div><div>                      "Never get here!"</div><div>                elif a ==  0 :</div><div>                   if b != 0:</div>



<div>                     outfile.write(eq)</div><div>                     outfile.write(str(quadroot.root5(b,c)))</div><div>                   else:</div><div>                      if c == 0:</div><div>                       outfile.write(eq)</div>



<div>                       outfile.write(str(quadroot.root6()))</div><div>                      else:</div><div>                         outfile.write(eq)</div><div>                         outfile.write(str(quadroot.root4(a,b,c,d)))</div>



<div>                else:</div><div><div>                  "Never get here!" </div><div><br></div><div>        outfile.close()   </div><div>                    </div><div>main()</div></div></div><div><br></div>



<div><div><span style="font-weight: bold;">AttributeError: 'list' object has no attribute 'split'</span></div><div><br></div><div>Can someone please explain/clarify this issue to me thanks!</div>
</div>
</blockquote></div></div><div><br>First of all, that's not the entire traceback. The entire traceback should include a line number that corresponds to the line "S=L.split()". Look at the error message- it says you are trying to access the split attribute of a list object, which doesn't exist. So, L is a list and it doesn't have a split method. Here is the documentation for file.readlines :<br>


<br>readlines(...)<br>    readlines([size]) -> list of strings, each a line from the file.<br>    <br>    Call readline() repeatedly and return a list of the lines so read.<br>    The optional size argument, if given, is an approximate bound on the<br>


    total number of bytes in the lines returned.<br><br>So by calling readlines, you already have a list where each element is a single line in the file. What you want to do from there depends on the structure of the file. Look at the documentation for list and str if you can't figure out what to do. Also, use the interactive prompt to mess around with the types before you try writing the program.<br>


<br><a href="http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange" target="_blank">http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange</a><br>

<br> </div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br>
</blockquote></div><br>
</div></div></blockquote></div><br>