[Tutor] find

Pijus Virketis virketis@fas.harvard.edu
Tue, 04 Dec 2001 21:43:27 -0500


--=====================_172160196==_.ALT
Content-Type: text/plain; charset="us-ascii"


>
> cute redhead
> Traceback (most recent call last):
>   File "C:\Python21\Tools\idle\amembership.py", line 10, in ?
>     find(t2,red[0[1]])
> NameError: name 'find' is not defined
>
> am I barking up the right tree?


Well, if I were you, I'd be barking up that very same tree as well, John. :)
However, your barking would be much more fruitful, if you imported the string
module before using find(). So, at the beginning of your code, add the
following:

import string

Then, you can say something like this:

string.find("tree", "re")               #checks if "re" is in "tree"

Do not forget the module name and the dot before find()! You need it, because
find() is in the string module namespace, so if you were omit string.*, Python
would look in the global namespace for "find" and it (probably) would not be
there. Hence the error message: "name 'find' is not defined." This comes in
particularly handy when you DO actually define some "find" object of your own,
and then import the string module. Python keeps your find and the
string.find()
completely separate. The term for it is namespace separation. There's
definitely more to it, but I think this should get you started.

Cheers, 

-P
------------------------------------------------------------
PGP PUBLIC KEY: www.fas.harvard.edu/~virketis/links
My weblog: www.fas.harvard.edu/~virketis

--=====================_172160196==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<blockquote type=cite cite>cute redhead<br>
Traceback (most recent call last):<br>
&nbsp; File &quot;C:\Python21\Tools\idle\amembership.py&quot;, line 10,
in ?<br>
&nbsp;&nbsp;&nbsp; find(t2,red[0[1]])<br>
NameError: name 'find' is not defined<br>
<br>
<b>am I barking up the right tree?</b></blockquote><br>
Well, if I were you, I'd be barking up that very same tree as well, John.
:) However, your barking would be much more fruitful, if you imported the
string module before using find(). So, at the beginning of your code, add
the following:<br>
<br>
import string<br>
<br>
Then, you can say something like this:<br>
<br>
string.find(&quot;tree&quot;,
&quot;re&quot;)<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>#checks
if &quot;re&quot; is in &quot;tree&quot;<br>
<br>
Do not forget the module name and the dot before find()! You need it,
because find() is in the string module namespace, so if you were omit
string.*, Python would look in the global namespace for &quot;find&quot;
and it (probably) would not be there. Hence the error message: &quot;name
'find' is not defined.&quot; This comes in particularly handy when you DO
actually define some &quot;find&quot; object of your own, and then import
the string module. Python keeps your find and the string.find()
completely separate. The term for it is namespace separation. There's
definitely more to it, but I think this should get you started.<br>
<br>
Cheers, <br>
<br>
-P<br>
<div>------------------------------------------------------------</div>
<div>PGP PUBLIC KEY:
<a href="http://www.fas.harvard.edu/~virketis/links" EUDORA=AUTOURL>www.fas.harvard.edu/~virketis/links</a></div>
<div>My weblog:
<a href="http://www.fas.harvard.edu/~virketis" EUDORA=AUTOURL>www.fas.harvard.edu/~virketis</a></div>
</html>

--=====================_172160196==_.ALT--