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

J

John F Dutcher

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

Michael Hudson

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

If you do

to get at, eg, maketrans, you need to do

Cheers,
mwh
 
D

Duncan Booth

(e-mail address removed) (John F Dutcher) wrote in

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top