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
  File is not being created with 'w' argument CAD79 3 323 Mar-14-2024, 12:05 PM
Last Post: snippsat
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 991 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 869 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,025 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 1,033 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,031 Dec-11-2022, 07:39 PM
Last Post: snippsat
  accept command line argument mg24 5 1,242 Sep-27-2022, 05:58 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 1,837 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 1,138 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  How to write the condition for deleting multiple lines? Lky 3 1,100 Jul-10-2022, 02:28 PM
Last Post: Lky

Forum Jump:

User Panel Messages

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