unreferenced (???) variable; prob. simple

  • Thread starter Halfdan Holger Knudsen
  • Start date
H

Halfdan Holger Knudsen

goodday all - here's a snippet of code that just doesn't seem to work...at
all! But I haven't got the faintest idea why I keep getting an unref.
local var. error. Take a look - I know I can get good help here. And PS:
Thanks beforehand.

If you're wondering - it's an attempt at a (crude) reproduction of the string.split() functionality for learning purposes.

----------------------

#! /usr/bin/env python

import string
begind = 0
endind = 0

def stripfunc():
inpstr = raw_input('String to strip: ')
length = len(inpstr)
spacelst = list(string.whitespace)
print spacelst
for a in range(length):
if inpstr[a] not in spacelst:
begind = a
break
break
for b in range(1, length+1):
if inpstr[-b] not in spacelst:
endind = length-b
break
break
stripstring = inpstr[begind:(endind+1)]
print stripstring
print begind
print endind

if __name__ == '__main__':
stripfunc()
 
P

Patrick Useldinger

goodday all - here's a snippet of code that just doesn't seem to work...at
all! But I haven't got the faintest idea why I keep getting an unref.
local var. error. Take a look - I know I can get good help here. And PS:
Thanks beforehand.
begind = 0
endind = 0
These variables are not know inside the function. The best solution is
to declare them as local variables in the function, as they really are
only of use in there, i.e.:

def stripfunc()
begind=0
endind=0
[... here goes the rest ...]

-PU
 
T

Terry Reedy

Halfdan Holger Knudsen said:
goodday all - here's a snippet of code that just doesn't seem to work...at
all! But I haven't got the faintest idea why I keep getting an unref.
local var. error.

When asking a question about 'why do I get this error message', please
copy and paste the complete error message, including the traceback.

TJR
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top