python and string.find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting python and string.find
# 1  
Old 06-07-2006
Error python and string.find

Hi all,

I'm not sure if this is the right forum, but i'll give it a try.
Here is my problem:
i have two files having basically the same things in it (hostnames):
File 1
mituap01
mituap02
mituap03

File 2:
mituap01
mituap04
mituap05

my goal is to get a .py out to check if pcs' in file1 are in file2.
The beginning of my code is this:
Code:
import os
import sys
import string
site=""
print "tri des pc\n"

def create_new(pc,site,soc):
	log=file("C:\\travail\\new\\" + site + "_" +soc+ "_new.txt",'a')
	log.write(pc + "\n")
	

def maj2min(site):
	file_aas=site + "_aas.txt"
	file_tfc=site + "_tfc.txt"
	aas_file=file(file_aas, 'r')
	tfc_file=file(file_tfc, 'r')
	
	for pc in aas_file.readlines():
		pc=pc.lower()
		pc=pc.replace("\n","")
		create_new(pc,site,"aas")
	for pc in tfc_file.readlines():
		pc=pc.lower()
		pc=pc.replace("\n","")
		create_new(pc,site,"tfc")

def tri_pc(site):
	pc_tfc=file("C:\\travail\\new\\" + site + "_tfc_new.txt").readlines()
	pc_aas=file("C:\\travail\\new\\" + site + "_aas_new.txt").readlines()
	for pc in pc_tfc:
			pc=pc.strip("\n")
			print pc
			string.find(pc,pc_aas)
			#if string.find(pc,pc_aas) <> -1:
			#	print "erreur\n"
			#for name in pc_aas:
			#    name=name.strip("\n")
			#    print name
			#    if name<>pc:
			#        print pc
				#else:
				#    print "non liste" + pc
					
						
				
			#pc=pc.strip("\n")
			#pc.find(pc_aas,pc)
			#if pc.find(pc_aas,pc) <> -1:
			#    print pc_tfc+ "pc non trouve\n"
	
def go(site):
	maj2min(site)
	tri_pc(site)

go("milan")
#go("rome")
#go("turin")
#go("aquila")

Where am i wrong in the string.find code?
All help will be greatly appreciated...


Jason
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue Spliting String in Python

I have a string like below Note: I have have a single to any number of comma "," seperated string assigned to jdbc_trgt variable. I need to split jdbc_trgt using comma(,) as the delimiter. I tried the below but it fails as i dont know how can i read each split string iterately. for... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Python replace string

Hi, I have a python variable with a value like this : string = "abc.de.fghijk.com:zyz.ab.fgfijk.com:abc.ef.fghijk.com" They are hostnames separated by the special character ":" . From this string I want to make a list with values : (2 Replies)
Discussion started by: ctrld
2 Replies

3. Shell Programming and Scripting

Find string in file and find the all records by string

Hello I would like to get know how to do this: I got a big file (about 1GB) and I need to find a string (for instance by grep ) and then find all records in this file based on a string. Thanks for advice. Martin (12 Replies)
Discussion started by: mape
12 Replies

4. Shell Programming and Scripting

Convert int to string in python

Hi, I have column 5 in a file which contains string like this for ex. RP11-125O5.2 SLCO1B1 CAPN1 FRMPD2 TXNL4B So I do by data = )] ValueError: invalid literal for int() with base 10: 'R' Can someday tell me how to convert this column into int successfully. Thank You in... (7 Replies)
Discussion started by: rossi
7 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Programming

Python pickle.loads(string)

Will this sentence return the decode of the string? Why I put a string in it but the system say: invaild load key (1 Reply)
Discussion started by: Henryyy
1 Replies

7. Shell Programming and Scripting

python - string encoding error

I'm trying to pull a google calendar (successful) and then put the contents into a mysql db (almost successful). On one of the field I keep getting an encode error: #!/usr/bin/python from xml.etree import ElementTree import gdata.calendar.data import gdata.calendar.client import... (12 Replies)
Discussion started by: unclecameron
12 Replies

8. Shell Programming and Scripting

Find text containing paths and replace with a string in all the python files

I have 100+ python files in a single directory. I need to replace a specific path occurrence with a variable name. Following are the find and the replace strings: Findstring--"projects\\Debugger\\debugger_dp8051_01\\debugger_dp8051_01.cywrk" Replacestring--self.projpath I tried... (5 Replies)
Discussion started by: noorsam
5 Replies

9. Shell Programming and Scripting

Python String <--> Number

My question is so simple: A = raw_input("A ") if A == '56': VAR = (A + 54)/13 else: print "other operations" if I write in input 5656565656 i want to make some arithmetic operations if the first input is 56XXX but the output is TypeError: cannot concatenate 'str' and... (2 Replies)
Discussion started by: kazikamuntu
2 Replies

10. Shell Programming and Scripting

Python - Scan for string

Hi i have a variable 'reform' and store the lines like reform= { record string(8) ID; string(4) PRD; date("YYMMDD", split = "800101") DateofManufact; string(4) PRDC_MODULE_NUM; string(1) END_OF_RECORD = "\n"; } I need to search for the character "\n"in the above variable... (1 Reply)
Discussion started by: dhanamurthy
1 Replies
Login or Register to Ask a Question