473,383 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 1075
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

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

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
9
by: Malcolm | last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC interpreter. The question is, how is it most useful? At the moment I have a function int basic(const char *script,...
56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
3
by: sefe dery | last post by:
hi ng, i try to create a asp.net 1.0 website on windows server 2003(Servername: ServerX) with iis 6.0. PROBLEM: The user should login with his windows credentials in basic.aspx and...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
10
by: trippeer | last post by:
I have the source code to an old BASIC program that a friend of mine would like to run online. I am a beginner at JS, but I think that it would be a good choice for the project. My background is in...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
6
by: Simon Walsh | last post by:
I'm an Electronics student in college and I'm currently working on a project. I was given a circuit diagram for my project, from which I had to design a printed circuit board to be sent off and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.