Reputation: 29
I am trying to streamline a process to generate some reports. Right now, users have to enter information into several prompts. To speed things up, I was curious if it's possible to parse multiple lines from user input. Basically, just copy all of the writeups and paste them in the terminal and have it parsed out, then boom, report. An example of what they would input is shown below:
number
title
string
string(tags)
A brief summary of what is being researched
sources
Ideally, after the input is accepted, I would store each line in a temp variable then concat them and store them in a single list entry. That would look like this:
[(number,title,string,string(tag),A brief summary of what is being researched,source),(entry2),(entry3),etc...]
Ive pasted some the working code below that will accept multiple lines until a blank character is seen:
end_of_art = ""
while True:
line = input()
if line.strip() in end_of_art:
break
text += "s," % line
UPDATE
So I was able to get it working the way I needed, but now I am getting this empyt string added to the end of my list.
Heres the new working code:
a_sources = {}
text = ""
while True:
line = input()
if not line.strip():
articles.append(text)
break
elif "//end//" in line:
text += "%s" % a_sources
articles.append(text) #append to articles list
text = "" #clear the temp text var
a_sources = {} #clear source dict var
elif validators.url(line):
atemp = validate_source(extract(line).domain)
a_sources.update({atemp:line})
#text += "%s," % a_sources
elif line:
text += "%s," % line
Output:
["1,Title 1,string,Tags,This is just junk text,{'Google': 'http://google.com'}", '']
Upvotes: 0
Views: 445
Reputation: 168
You could go by some sort of looping input. EX:
user_inputs = []
recent_input = None
while recent_input != "":
recent_input = str(input())
user_inputs.append(recent_input)
The catch is is that you input would need an empty line at the end of it. So rather than:
"a"
"b"
"c"
You'd want:
"a"
"b"
"c"
""
Upvotes: 1