Python Forum
How to deal with more than 1 input in a line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to deal with more than 1 input in a line
#1
Hi, can i know how to deal with line that sometimes have 1 input but sometimes have more. Is there any hint on what can i used to deal with this. I have few files, where the inputs varies.

Example:
file_a.txt
input a, b, c, d

file_b.txt
input a
input b

file_c.txt
input a,b,d,e,f,g,add,summ
I am planning to create a script that can list out the input one by one, line by line.

Example output:
out_a.txt
input a 
input b 
input c 
input d

out_b.txt
input a
input b

out_c.txt
input a
input b
input d
input e
input f
input g
input add
input summ
I am currently manage to work with line that only have one input by using if else condition:
if "input" in line:
     f0.write(line)
Reply
#2
You need to do three things:
  • Get the text after the word 'input'. String indexing would work for this.
  • Split that text into a list on the comma (text.split(',')).
  • Output each word in the list using a for loop.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Receive Input on Same Line? johnywhy 8 607 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  How to deal with self and __init__ in function MrFloyd_telomerase 1 1,708 Apr-26-2021, 08:15 PM
Last Post: buran
  How to input & output parameters from command line argument shantanu97 1 2,506 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 3,271 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  how to deal with problem of converting string to int usthbstar 1 1,932 Jan-05-2021, 01:33 PM
Last Post: perfringo
  Multi-line console input lizze 4 2,283 Dec-26-2020, 08:10 AM
Last Post: lizze
  bad input line 3 how t fix it youssef210 2 2,655 Aug-27-2020, 04:57 PM
Last Post: nilamo
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,368 Jul-22-2020, 04:34 PM
Last Post: issac_n
  Taking Multiple Command Line Argument Input bwdu 6 3,925 Mar-29-2020, 05:52 PM
Last Post: buran
  How to make input goto a different line mxl671 2 2,422 Feb-04-2020, 07:12 PM
Last Post: Marbelous

Forum Jump:

User Panel Messages

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