Python Forum
Accept Multiple Lines of Input into a User Created File
Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accept Multiple Lines of Input into a User Created File
#1
The problem starts when, from the terminal, as an example, the user cuts and pastes the following:

$thing1
thing2
thing3
thing4
...

When I open the user created file I want to see, as a column:

thing1
thing2
thing3
thing4
...


However, only the first line is accepted into the file. I know I'm using raw_input and it only accepts a single line...so how can I use the code for a user created file and somehow get multiple lines into that file?

I tried sys.stdin as well as trying to open targetfile as f but multi-line input won't get into the user created file.
There are no traceback errors.



#!/usr/bin/python
import os
#import sys

#user creates a file name
targetfile = raw_input('Enter Subject of email here: ')


things_list =

#if user enters input on multiple lines script doesn't send input to targetfilefound, it doesnt quit when type done either
things = raw_input("Enter things, then type 'done' on its own line to quit: \n")

while True:
try:
targetfilefound = open(targetfile , 'w')
targetfilefound.write(raw_input())
targetfilefound.close()
while things != "done":
things_list.append(things)
things = raw_input("")
things_list = ''.join(things_list)

except KeyboardInterrupt:
break
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to revert back to a previous line from user input Sharkenn64u 2 757 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  User input with while loops chizzy101010 2 4,340 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  [solved] how to delete the 10 first lines of an ascii file paul18fr 7 1,631 Aug-07-2024, 08:18 PM
Last Post: Gribouillis
  501 Server cannot accept argument anna17 0 909 Apr-11-2024, 01:08 AM
Last Post: anna17
  How to accept facebook cookies using python selenium? pablo86ad 0 1,280 Apr-06-2024, 09:19 PM
Last Post: pablo86ad
  File is not being created with 'w' argument CAD79 3 1,458 Mar-14-2024, 12:05 PM
Last Post: snippsat
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 2,396 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 1,779 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,909 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 2,253 Dec-25-2022, 03:00 PM
Last Post: askfriends

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020