473,497 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

search between 2 files

I'm newby in Python, and I'm working on a script to manage files.
I have two files, one with a list of domains, and the other with a new
list of domains. I'd like to know if I have a repeated domain in the
new's one. I tried opening with readline(), with readlines(), but truly
I have no idea to countinue.

Have anybody any question?

thanks

Jul 18 '05 #1
4 1073
José wrote:
I'm newby in Python, and I'm working on a script to manage files.
I have two files, one with a list of domains, and the other with a new
list of domains. I'd like to know if I have a repeated domain in the
new's one. I tried opening with readline(), with readlines(), but truly
I have no idea to countinue.

Have anybody any question?


I think it would be something like this (iow, untested):

domainsFile = file(filename, "rw")
domains = f1.readlines()
newDomainsFile = file(filename2, "r")
for domain in newDomainsFile:
....if not domain in domains:
........domains.append(domain)

--
Andres Rosado
Email: an*****@despammed.com
ICQ: 66750646
AIM: pantear
Homepage: http://andres980.tripod.com/

"Oh boo! Boo hoo! Oh! ... don't stop now ... you motorheads're killin'
me."
-- A surprisingly alive Rattrap, "A Better Mousetrap"
Jul 18 '05 #2
On Wed, 04 Feb 2004 13:26:47 +0100, José <jm******@telecable.es>
wrote:
I'm newby in Python, and I'm working on a script to manage files.
I have two files, one with a list of domains, and the other with a new
list of domains. I'd like to know if I have a repeated domain in the
new's one. I tried opening with readline(), with readlines(), but truly
I have no idea to countinue.


You said you wanted to know if you have a repeated domain in the new
one. I am assuming you mean you want to know if there are any domains
in the new list that are not in the old. If you just want to
eliminate duplicates from the new list, independently of the first
list, please clarify.

import sets

old_domains = sets.Set()
for domain in file("olddomains.txt"):
old_domains.add(domain.strip())

new_domains = sets.Set()
for domain in file("newdomains.txt"):
new_domains.add(domain.strip())

if new_domains == old_domains:
print "There are no new domains."
else:
print "The following domains are new:"
print new_domains - old_domains

--dang
p.s.
Or if you like list comprehensions:

import sets

old_domains = sets.Set()
[old_domains.add(domain.strip()) for domain in file("olddomains.txt")]

new_domains = sets.Set()
[new_domains.add(domain.strip()) for domain in file("newdomains.txt")]

if new_domains == old_domains:
print "There are no new domains."
else:
print "The following domains are new:"
print new_domains - old_domains

Jul 18 '05 #3
mmmh, it's not the same, but I try with this indications.

I have a file called "data" from djbdns with different domain, for example:

----------------------
..domain.com:ns.domain.com
+domain.com
+.*domain.com
..domain1.com:ns.domain1.com
+domain.com
+.*domain.com
------------------------

and have a new file for example "list" with new domains

-------------------------
newdomain.com
newdomain1.com
newdomain1.com
-------------------------

I'm programming a little interface in python, and before I modify the
"data" file I'd like to know if I have in the list one domain I have in
data.

Thans


José escribió:
I'm newby in Python, and I'm working on a script to manage files.
I have two files, one with a list of domains, and the other with a new
list of domains. I'd like to know if I have a repeated domain in the
new's one. I tried opening with readline(), with readlines(), but truly
I have no idea to countinue.

Have anybody any question?

thanks


Jul 18 '05 #4
I think with the both solutions it works if I have the files in the same
format, so I think I'll call a script command to have the files in the
same way, and when I learn more python I'll try with regular expressions

:-))

thank you very much
José escribió:
mmmh, it's not the same, but I try with this indications.

I have a file called "data" from djbdns with different domain, for example:

----------------------
.domain.com:ns.domain.com
+domain.com
+.*domain.com
.domain1.com:ns.domain1.com
+domain.com
+.*domain.com
------------------------

and have a new file for example "list" with new domains

-------------------------
newdomain.com
newdomain1.com
newdomain1.com
-------------------------

I'm programming a little interface in python, and before I modify the
"data" file I'd like to know if I have in the list one domain I have in
data.

Thans


José escribió:
I'm newby in Python, and I'm working on a script to manage files.
I have two files, one with a list of domains, and the other with a new
list of domains. I'd like to know if I have a repeated domain in the
new's one. I tried opening with readline(), with readlines(), but
truly I have no idea to countinue.

Have anybody any question?

thanks


Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9524
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
5
2681
by: Mark | last post by:
Hi I have an application (in vb.NET 2005) which holds data in SQL Server and some of the SQL records are simply paths to related files. I would like to be able to do a text search on both the...
9
1700
by: Lloyd Sheen | last post by:
For all those who don't think that a recursive search of files in folders is a good thing in the Microsoft.VisualBasic.FileIO.FileSystem namespace listen to this. I am reorg my mp3 collection. ...
3
3538
by: =?Utf-8?B?UGVycmlud29sZg==?= | last post by:
Not sure where to post this... Found some interesting behavior in Windows Search (Start =Search =All files and folders =search for "A word or phrase in the file:"). This applies to XP and maybe...
0
10705
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.