Python Forum
Repeat keywords at end of every line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repeat keywords at end of every line
#1
Good evening, I would like to read a text file and create an output with the results.
I'm new on python and i'm looking a way to develop this code.
Any suggestion on how to start it ?
  • Check all lines, looking for KEYWORD.
  • Once it finds, copy from pos X to pos Y (fixed position, hard-coded )
  • Write the copied string at end of every line at pos Z (fixed position, hard-coded)
  • if KEYWORD is found again on the next line the steps above...
  • writing everything on the output file.

Output:
abcabc abc abvc canc KEYWORD TOBEREPLIC1 TOBEREPLIC1 asd alskdlask laks dlkal lakslkalkas TOBEREPLIC1 aslddsas laskd laskl lsklklklk asdda TOBEREPLIC1 TOBEREPLIC1 aksjdaks kajsdkajsd askjaksjd a asdasda TOBEREPLIC1 TOBEREPLIC1 aksjaaaaaaaaaaaaaaaaaakjaksjd aasdas TOBEREPLIC1 aksjbbbbbbb b bbbbbbbbbbaksjd adasdas TOBEREPLIC1 abcasdasdasd asdaasd KEYWORD TOBEREPLIC2 TOBEREPLIC2 TOBEREPLIC2 aksjasdasdasdasajsasdasdas a asdsda TOBEREPLIC2 akasssssssssssssssd askjaksjd adasda TOBEREPLIC2 aksjdavvvvvvv sssssssse eeeeeeee ee TOBEREPLIC2
Reply
#2
You received similar (though I would say not the most polite) feedback last time - we'd love to help you with writing your code, but we typically expect you to make an attempt first, especially since this sounds like homework. Given that you were doing Python nearly a year ago, by your previous post, you should be able to come up with at least a little bit of code, and ask a specific question about exactly what's blocking you from the next step.
Reply
#3
your guess is incorrect.. this is not home work...
and please don't feel obligate to contribute with nothing (as you just did).. just don't post nothing...
also.. if you read again.. i'm not asking you code nothing for me... "Any suggestion on how to start it ?"
again... just don't post nothing.. you are doing not more than push away new users from the language...
Reply
#4
None of the below is to say you necessarily won't get the answer you're looking for...

Don't be offended, but we put homework-like questions in the Homework section to discourage people from spoiler answers, since the goal of the forum is education, and not getting programs written. I realize you only asked for how to start, not for code, but sometimes people simply give code answers to questions like this, even though we discourage it. As such...

Your post would fall under Homework and No Effort Questions rules. Your post has not shown effort; you could have said "this is what I think..." for example. While we don't want to discourage people new to the language, coding requires continuous effort be put into learning, and I'll point out a big part of coding is getting started, and playing around with the code. You can't expect other people, for simple programs, to tell you how to get started. Specific questions are great, though.
Reply
#5
Python has duck-typing and for me this is 'assignment type'.

Quote:When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.

--James Whitcomb Riley

I also observe that the description is ambiguous or missing some vital points.

That aside I would recommend break task at hand into smaller subtasks. Something like:

- how to open the file and iterate it row-by-row
- how to determine whether row (string) contains specific substring
- how to copy from position X to position Y
- how to add to the string at specific position, even if it's out of bounds
- how to write to file

All these subtasks are simple enough to solve and combining them all together should give solution.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Repeat question (for loop) rs74 7 6,474 Jun-17-2020, 03:17 PM
Last Post: rs74
  How to repeat input line of code until condition is met Reta 2 3,366 May-14-2019, 10:06 PM
Last Post: nilamo
  Need help with Keywords in Python Zaprios 3 70,096 Mar-23-2017, 07:52 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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