Sponsored Content
Full Discussion: python and string.find
Top Forums Shell Programming and Scripting python and string.find Post 302075862 by penguin-friend on Wednesday 7th of June 2006 09:40:08 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
XmDropSiteConfigureStackingOrder(library call)							    XmDropSiteConfigureStackingOrder(library call)

NAME
XmDropSiteConfigureStackingOrder -- A Drag and Drop function that reorders a stack of widgets that are registered drop sites SYNOPSIS
#include <Xm/DragDrop.h> void XmDropSiteConfigureStackingOrder( Widget widget, Widget sibling, Cardinal stack_mode); DESCRIPTION
XmDropSiteConfigureStackingOrder changes the stacking order of the drop site specified by widget. The stacking order controls the manner in which drag-under effects are clipped by overlapping siblings, regardless of whether they are active. The stack mode is relative either to the entire stack, or to another drop site within the stack. The stack order can be modified only if the drop sites are siblings in both the widget and drop site hierarchy, and the widget parent of the drop sites is registered as a composite drop site. widget Specifies the drop site to be restacked. sibling Specifies a sibling drop site for stacking operations. If specified, then widget is restacked relative to this drop site's stack position. stack_mode Specifies the new stack position for the specified widget. The values are XmABOVE and XmBELOW. If a sibling is specified, then widget is restacked as follows: XmABOVE The widget is placed just above the sibling. XmBELOW The widget is placed just below the sibling. If the sibling parameter is not specified, then widget is restacked as follows: XmABOVE The widget is placed at the top of the stack. XmBELOW The widget is placed at the bottom of the stack. For a complete definition of DropSite and its associated resources, see XmDropSite(3). RELATED
XmDropSite(3), XmDropSiteRetrieve(3), and XmDropSiteQueryStackingOrder(3). XmDropSiteConfigureStackingOrder(library call)
All times are GMT -4. The time now is 05:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy