help please

2005-02-12 Thread gargonx
would anyone like to help to fugure out this problem i'm having here's
a portion of my code:

"""
I have three dictionaries along with this(you can probally spot what
they are), but just in case here are some testers:
"""
std = {
   "b":"bo"
}

ext = {
"aa":"i"
}

punc = {
",":"!"
}
"""
when i run this i get :

UnboundLocalError: local variable 't2' referenced before assignment

"""

OrigText="ba, baa bo."

t2=""

def Proc(text): # "text" is some random text or use OrigText
for word in text:
for letter in word:
if letter in std.keys():
letter=std[letter]
t2=t2+letter  # the problem is referene to this
elif letter in ext.keys():
letter=ext[letter]
t2=t2+letter
elif letter in punc.keys():
letter=punc[letter]
t2=t2+letter

can anyone figure out why t2 is not being used properly?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-12 Thread gargonx
This works much better, aside from the fact that it does'nt work for
the std dictionary. the letters used from here stay the same. that
dictionary looks like this:

std = {
"A":"Z",
"Z":"A",
"B":"Y",
"Y":"B",
"C":"X",
"X":"C",
"E":"V",
"V":"E",
"H":"S",
"S":"H",
"M":"N",
"N":"M"
}

what could be causing this?

i did figure out that if you reverse the k,v you are able to get it but
that doesn't turn up the results i need

def proc(text):
 result = []
 for word in text:
 for k, v in replacements:
 word = word.replace(v,k) #here i reversed them
 result.append(word)
 return ''.join(result)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-12 Thread gargonx
Thanks that works very well

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread gargonx
yes the items in std are always single to single, and ext single to
double. basicly the ext are refernce to the std itmes. the second
character in ext is a number depending on how far it is from the item
in std. this is just a simple encoding program.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread gargonx
Well that seems to work like a champion, but my prob then would be; how
do i get the double character values of ext to turn back to the single
character keys. The reversed (decode if you will). Thanks a lot Steve
this has been a great learning!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-13 Thread gargonx
let's take the word "dogs"

   ext = dict("D":"V1",  "O":"M1", "G":"S1")
   std = dict("S":"H")

encode("DOGS") # proc()
we'll get: "V1M1S1H"

let's say i want to do just the opposite
word: "V1M1S1H"
decode("V1M1S1H")
#how do i decode "V1" to "D", how do i keep the "V1" together?
and get: "DOGS"

#everything gets changed to uppercase

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-20 Thread gargonx
I think there's a problem with the code:

 py> decode_replacements.update([(std[key], key) for key in std])
 py> decode_replacements.update([(ext[key], key) for key in ext])

when i run this i get an error:
 AttributeError: keys

I can't get that figured out

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help please

2005-02-20 Thread gargonx
Even if i put it in exactly the way you did:

>>> import re
>>> charmatcher = re.compile(r' [A-Z] [\d]?')
>>>
>>> ext = dict(D="V1", O="M1", G="S1")
>>> std = dict(S="H")
>>>
>>> decode_replacements ={}
>>> decode_replacements.update([(std[key], key) for key in std])
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: keys

-- 
http://mail.python.org/mailman/listinfo/python-list


Why no string return?

2008-03-11 Thread gargonx
Say i have the two methods:

def ReturnMethod(request, x):
if request is True:
return x
else: print "No String for you...False!"

def SendMethod(request):
xstring = "Some text"
ReturnMethod(request, xstring)

SendMethod(True)

Why does ReturnMethod not return the string x? I do believe it is
returning with a NoneType.
Any help would be greatly obliged

Thanks, Josh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why no string return?

2008-03-11 Thread gargonx
On Mar 12, 4:45 am, Adonis Vargas <[EMAIL PROTECTED]
bellsouth.net> wrote:
> gargonx wrote:
> > Say i have the two methods:
>
> > def ReturnMethod(request, x):
> > if request is True:
> > return x
> > else: print "No String for you...False!"
>
> > def SendMethod(request):
> > xstring = "Some text"
> > ReturnMethod(request, xstring)
>
> > SendMethod(True)
>
> > Why does ReturnMethod not return the string x? I do believe it is
> > returning with a NoneType.
> > Any help would be greatly obliged
>
> > Thanks, Josh
>
> That is because request is bound a string (str) object. You are probably
> testing for null so it should look like:
>
>  if request:
>  return x
>  else:
>  print "No String for you...False!"
>
> Hope this helps.
>
> Adonis

Still no return of string. The null testing is not really the deal.
that could be replaced with anything EG:

def ReturnMethod(request, x):
if request is 'random':
return x
else: print "No String for you...False!"

def SendMethod(request):
xstring = "Some text"
ReturnMethod(request, xstring)

SendMethod('random')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why no string return?

2008-03-11 Thread gargonx
On Mar 12, 5:10 am, Frank Millman <[EMAIL PROTECTED]> wrote:
> gargonx wrote:
> > Say i have the two methods:
>
> > def ReturnMethod(request, x):
> > if request is True:
> > return x
> > else: print "No String for you...False!"
>
> > def SendMethod(request):
> > xstring = "Some text"
> > ReturnMethod(request, xstring)
>
> > SendMethod(True)
>
> > Why does ReturnMethod not return the string x? I do believe it is
> > returning with a NoneType.
> > Any help would be greatly obliged
>
> > Thanks, Josh
>
> ReturnMethod() is executed, but you do nothing with the result.
>
> Try one of the following -
>
> def SendMethod(request):
> xstring = "Some text"
> print ReturnMethod(request, xstring)
>
> def SendMethod(request):
> xstring = "Some text"
> return ReturnMethod(request, xstring)
>
> HTH
>
> Frank Millman

Thanks Frank the latter worked for my purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list