471,317 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

basic!

111 100+
i have a basic doubt.. i have a program that does a particular task..this prg(2) actually works with the o/p from another program(1). The program 1 gives the o/p in the form of a list that is written to a file.. now my program 2 works fine when i take its input as the o/p file but now i want to string in the prg2 to the prg1.
the program one works on a list called masterList.this is written to a file and taken as i/p

my program 2(which is working fine and independent)has these lines:
Expand|Select|Wrap|Line Numbers
  1. f=file("result.txt")# THIS CONTAINS STUFF FROM MASTERLIST FROM PRG1
  2.  
  3.  
  4.  
  5. a=f.readlines()
  6.  
  7. for i in a:
  8. # do a set of work
  9.  
now, when i string the 2 prg to the first i can just say:
Expand|Select|Wrap|Line Numbers
  1. for line in masterList:
  2. # do a set of work
  3.  
But this doesnt seem to work. but i dont see any difference or mistake
do u see any??
Dec 26 '07 #1
5 993
bvdet
2,851 Expert Mod 2GB
i have a basic doubt.. i have a program that does a particular task..this prg(2) actually works with the o/p from another program(1). The program 1 gives the o/p in the form of a list that is written to a file.. now my program 2 works fine when i take its input as the o/p file but now i want to string in the prg2 to the prg1.
the program one works on a list called masterList.this is written to a file and taken as i/p

my program 2(which is working fine and independent)has these lines:
Expand|Select|Wrap|Line Numbers
  1. f=file("result.txt")# THIS CONTAINS STUFF FROM MASTERLIST FROM PRG1
  2.  
  3.  
  4.  
  5. a=f.readlines()
  6.  
  7. for i in a:
  8. # do a set of work
  9.  
now, when i string the 2 prg to the first i can just say:
Expand|Select|Wrap|Line Numbers
  1. for line in masterList:
  2. # do a set of work
  3.  
But this doesnt seem to work. but i dont see any difference or mistake
do u see any??
Each line from the file will have a trailing newline character.
Dec 26 '07 #2
aboxylica
111 100+
Each line from the file will have a trailing newline character.
you mean it will have a "\n" that will make the diffrence. so what should i do ? add a "\n" to my list? it doesnt really make sense to me!
Dec 27 '07 #3
ilikepython
844 Expert 512MB
i have a basic doubt.. i have a program that does a particular task..this prg(2) actually works with the o/p from another program(1). The program 1 gives the o/p in the form of a list that is written to a file.. now my program 2 works fine when i take its input as the o/p file but now i want to string in the prg2 to the prg1.
the program one works on a list called masterList.this is written to a file and taken as i/p

my program 2(which is working fine and independent)has these lines:
Expand|Select|Wrap|Line Numbers
  1. f=file("result.txt")# THIS CONTAINS STUFF FROM MASTERLIST FROM PRG1
  2.  
  3.  
  4.  
  5. a=f.readlines()
  6.  
  7. for i in a:
  8. # do a set of work
  9.  
now, when i string the 2 prg to the first i can just say:
Expand|Select|Wrap|Line Numbers
  1. for line in masterList:
  2. # do a set of work
  3.  
But this doesnt seem to work. but i dont see any difference or mistake
do u see any??
I dont really understand what you mean. Do you want to add the code from program 2 to program 1 at the end or something else? Also, what is the error message you are getting?
Dec 27 '07 #4
aboxylica
111 100+
I dont really understand what you mean. Do you want to add the code from program 2 to program 1 at the end or something else? Also, what is the error message you are getting?
yes.. i want to add program 2 to program one.. i want to know what difference will
readlines() from an o/p file(containing this masterList) and directly refering to for item in masterList make..
The error can be corrected if i understand this difference
Dec 27 '07 #5
bvdet
2,851 Expert Mod 2GB
you mean it will have a "\n" that will make the diffrence. so what should i do ? add a "\n" to my list? it doesnt really make sense to me!
Expand|Select|Wrap|Line Numbers
  1. for item in masterList:
  2.     ....do stuff....
Expand|Select|Wrap|Line Numbers
  1. lineList = [line.strip() for line in open("filename").readlines()]
  2. for item in lineList:
  3.     ....do stuff....
String method strip() will strip off leading and trailing whitespace characters. In the above examples, masterList and lineList will be equivalent.
Dec 27 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Michael Foord | last post: by
9 posts views Thread by Malcolm | last post: by
56 posts views Thread by Dave Vandervies | last post: by
14 posts views Thread by luis | last post: by
3 posts views Thread by sefe dery | last post: by
10 posts views Thread by trippeer | last post: by
97 posts views Thread by Master Programmer | last post: by
6 posts views Thread by Simon Walsh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.