Why 'string' functions i.e. rstrip, upper, lower are 'not found'.........

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Dec 4 17:51:29 CET 2003

John_Dutcher at urmc.rochester.edu (John F Dutcher) wrote in
news:2c82369d.0312040836.7374c789 at posting.google.com: 

> There must be a 'fundamental' reason why 'string' functions are
> reported as 'not found' even though the 'import string' statement
> is present. If the script has user-defined functions at its beginning
> and I remove them...doing all code inline, the 'not found' error goes
> away. Is there some 'placement of user functions' issue that explains
> why the 'import string' doesn't make the various string functions
> visible when I use various 'def userfunc's in the script ??
> Thanks much,
> John D.
You need to be more specific. What is the *exact* error message you are 
seeing? Cut and paste it, don't paraphrase. If possible, cut the code down 
the the minimum that shows the problem and post it here. Cutting the code 
down also help you isolate the error yourself. If you can't cut the code 
down enough to post, then at least post the code around the area where the 
problem occurs.

The only thing that immediately springs to mind would be that if you 
created a global variable, or a function, that was itself called 'string', 
that would overwrite the variable created by the import statement (think of 
both 'import' and 'def' as being statements that do a variable assignment 
as a side effect).

BTW, you probably want to get to the bottom of this problem to help your 
understanding, but after you've done that you may find it simpler just to 
use the methods that strings have as that way you rarely need to import the 
string module.

Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list