![]() |
|
[Python] Python printing to file - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Python printing to file (/showthread.php?tid=6173600) |
Python printing to file - Will Patterson - Sep 21, 2021 I'm stuck on this homework assignment that I have. Below are the instructions for it Quote:You are an English major who has been given assignment to analyze Dr. King's I finished the first 2 steps in the assignment which is in the code below: Code # Open the fileHow would I open and create a new file and put the first paragraph of the MLK speech into it? I believe we are supposed to use a while loop to do that Thanks! RE: Python printing to file - Donkey Death Jam - Sep 21, 2021 Code # Create the file with the 'w' option and alias the handleAdd this to the bottom of your current code and it should work. RE: Python printing to file - Will Patterson - Sep 21, 2021 (Sep 21, 2021 02:52 PM)Donkey Death Jam Wrote: Would there be another way to do it without using Quote: # Substring the from start to the newline index Also, I appreciate the help :) RE: Python printing to file - Donkey Death Jam - Sep 21, 2021 (Sep 21, 2021 03:04 PM)Will Patterson Wrote: Would there be another way to do it without using There are many ways to do it. If you want an explicit loop, you can do: Code # Create the file with the 'w' optionRE: Python printing to file - Able. - Sep 25, 2021 use open() in python. You can use open with close, or use with open(). You can do searches on it. |