Click here to Skip to main content
15,312,747 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to make a pogram which can check two files and then return the same things in those two files, I tried to test on numbers but there is a problem which i am facing

Here,s the code:

""" This program will find the overlapping numbers b/w two text files"""

From = input("Enter the File you wanna check from = ").lower()

to = input("Enter the File you wanna check to = ").lower()

def check():
rfrom = open(From, "r")

rto = open(to, "r")


lin1 = rfrom.read()
lin2 = rto.read()


for common in lin1:
if common in lin2 and lin1:
print(common)


check()


In the for i am tryinf to make it check the same numbers b/w two files but instead of iterating through a complete number like 56 it iterates like first 5 and then 6 which causes the problem , please help me in this so the for loop can understand that i have to iterate through a whole number... Not just one by one

What I have tried:

I treid to put commas and tried to convert the lin1 and lin2 at for in lists.I tried to make the 2 files in .py extension but that also didn,t worked
Posted
Updated 7-Jan-19 2:23am

I think regular expressions would help you here.

Regular Expression HOWTO — Python 3.7.2 documentation[^]
   
v2
Comments
Member 14068174 7-Jan-19 8:27am
   
Can you modify the code for me because i don,t know regular expressions.
Slacker007 7-Jan-19 8:45am
   
If you can't learn to do this yourself, you need to drop the class or find a new profession. I will NOT do the work for you. Good luck
Member 14068174 7-Jan-19 9:27am
   
ONE DOESN,T NEEDS TO LEARN EVERYTHING IN ORDER TO BE SUCCESFULL.I THINK YOU DON,T KNOW HOW TO SOLVE THE PROBLEM THAT,S WHY YOU ARE MAKING UP THESE WORDS.NO PROBLEM I CAN UNDERSTAND THAT A GUY CAN SUCK SOMEWHERE.
Richard MacCutchan 7-Jan-19 11:20am
   
Please do not shout.
   
Comments
Member 14068174 7-Jan-19 8:22am
   
I tried it , It doesn,t work
CPallini 7-Jan-19 8:27am
   
You should detail (i.e. what is not working? How do you establish that? And so on...). I am afraid just downvoting won't help you.
Member 14068174 14-Jan-19 1:58am
   
i have already explained that it should check a full number at a time like 56 but it iterates first through 5 and then 6 which then causes the problem. I think you should check the code running from that you will be able to analyse what,s wrong as i am unable to analyse it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900