variable being weirdly deleted

Posted by calccrypto on Stack Overflow See other posts from Stack Overflow or by calccrypto
Published on 2010-12-26T03:28:46Z Indexed on 2010/12/26 3:54 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

im having a weird problem with one variable: its not being recognized but its still printing. i would post my code, but it is massive. the basic idea is:

# pseudocode
def function(stuff):
    <do stuff>
    # These are the only 2 conditions
    if tag == 3:
       pka = <a string>

    if tag == 4:
       pka = <a string>
       print pka # (1)

    print pka  # (2)
    <do stuff not modifying pka>
    print pka  # (3)

    if pka == 'RSA':
       <do stuff>
    elif pka == 'DSA':
       <do stuff>

my code will error at (2). however, it will print out (1), (2), and (3), all of which are the same. is there any general explanation of why this is happening? if my code is really needed, i will post it, but otherwise, i would rather not due to its size

update: now the code will error at the if statement after (3), saying UnboundLocalError: local variable 'pka' referenced before assignment even though (1),(2),(3) just printed

© Stack Overflow or respective owner

Related posts about python

Related posts about error