Python Forum

Full Version: Find string return different string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I need to find the string inside TFile, and once the string is located I need to return the string 9 cells below it. TFile contains only one column. I'm not sure if I'm on the right path here, or totally off. I'm not sure how to go about what to add under if StringFound. I just know if string is found return string 9 cells down.

TFile=pd.read_excel(Train, usecols="B")

String=pd.read_excel(input_file, usecols="A",nrows=1,header=None,squeeze=True).str.slice(start=28,stop=-2).to_string(index=False).strip()

   def FindXlCell(String):
     StringFound = FindXlCell(String, TFile.iter_rows(min_col=1, max_col=1))
     if StringFound:
incomplete code -- Cannot be run as presented.
A few other things:

1. Your indentation is a mess, so Python should be raising an IndentationError about it.

2. On line 6, it looks like you're trying to call your function recursively and that doesn't make sense because you'd just end up in infinite recursion. That won't happen anyway, because you're trying to call the function with two arguments but the signature says it only takes one (line 5). Python doesn't let you overload functions in the same way that say, Java does.