0

I want to make a script that extract two columns from file-1 and them write them into file-2. However, If file-2 already contains columns, and want the new columns to be written on the side (of the current columns), and not at the bottom. My current script appends the "new" columns at the bottom of the current ones, instead of doing it on the side. How can I add the new columns on the side a not at the bottom?. Someone suggested CSV module, and I tried, but I could not figure out how to do it.

Here is my current code

https://dl.dropbox.com/u/63216126/paula.txt

Here is the output file if I run the script once

https://dl.dropbox.com/u/63216126/try2.txt

Here is the output file if I run the script twice (Keep in mind this is not want I want)

https://dl.dropbox.com/u/63216126/try3.txt

Here is how I want the output to look after running the script three times

https://dl.dropbox.com/u/63216126/try.txt

Here are two input samples

https://dl.dropbox.com/u/63216126/file5.txt

https://dl.dropbox.com/u/63216126/file6.txt

I hope what I want to do is clear. Thanks a lot for the help.

Justme
  • 85
  • 1
  • 6
  • 14

1 Answers1

1

sys.argv is a list. You can get the number of arguments with len(sys.argv), and iterate through them like so:

for arg in sys.argv[1:]:
    do_something(arg)
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
  • Thanks a million, I still have one more question. In my script I take an input file, search for a keyword, then copy two lists (word1 and word2) and then write them into a new file "opennew.write (word1 + " " + word2 + "\n")" how can I make the code so it saves "word1" and "word2" from argv[1], then "word3" and "word4" from argv[2], and so on, to then use something to write into the new file using the format "opennew.write (word1 + " " + word2 + " " + word3 + " " + word4 +....... +"\n")" ? Thanks for the help – Justme Nov 30 '12 at 19:29
  • Take a look at the [itertools](http://docs.python.org/2/library/itertools.html) module. It has API for iterating over python iterable in various ways. I think the function `tee()` is what you are looking for (if I understood correctly and you want to itertate two words at a time). – StoryTeller - Unslander Monica Nov 30 '12 at 19:36
  • I thought on an easier way to do this, by making one input file at the time, but that the new to list to be written in the new file on the side of the previous ones, not at the bottom. Any suggestion? – Justme Nov 30 '12 at 20:25
  • @henrymartinez Please edit your question and add exactly what you want to accomplish, along with what you tried. I'm not sure I follow,and the comments aren't really the place to elaborate. – StoryTeller - Unslander Monica Nov 30 '12 at 20:29
  • Thanks Dima for the reply. I edited my question, and I hope is more clear now. Thanks a lot for the help. I change the initial question, since I think it would be easier this new way. Once again. Thanks – Justme Nov 30 '12 at 22:53