0

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'}", '']
2
  • 1
    what is the question Commented Feb 12, 2020 at 14:39
  • how would i go about parsing the data and storing it into a list with multiple lines Commented Feb 12, 2020 at 16:08

1 Answer 1

1

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"

""

Sign up to request clarification or add additional context in comments.

3 Comments

This helped a little
would you know how to get rid of the blank entry at the end of the list?
Google can help you with that one ;) But you should be able to do list.pop() or del list[-1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.