Says Name Error: global name 'string' is not defined. How do I correct?

2,167 views
Skip to first unread message

Randy Armstrong

unread,
Oct 28, 2012, 8:04:39 PM10/28/12
to pyscr...@googlegroups.com
def main():
 

    print "This program converts a sequence of ASCII numbers into"
    print "the string of text that it represents."
    print

    # get the message to encode

    instring = raw_input("Please enter the ASCII-encoded messages: ")
    #loop through each substring and build ASCII message

    message = ""
    for numStr in string.split(inString):
        asciinum = eval(numstr)    # convert digits to a number
        message = message + chr(asciinum)    # append character to message

    print  "The decoded message is: ", message

main()

 

Andy Milne

unread,
Oct 28, 2012, 10:29:48 PM10/28/12
to pyscr...@googlegroups.com, pyscr...@googlegroups.com
Replace:

string.split

With:

instring.split


--
You received this message because you are subscribed to the Google Groups "PyScripter" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pyscripter/-/MnWtFuyvBeIJ.
To post to this group, send email to pyscr...@googlegroups.com.
To unsubscribe from this group, send email to pyscripter+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyscripter?hl=en.

Randy Armstrong

unread,
Oct 28, 2012, 10:46:38 PM10/28/12
to pyscr...@googlegroups.com
not working, are you able to get it to work?

Andy Milne

unread,
Oct 28, 2012, 11:54:48 PM10/28/12
to pyscr...@googlegroups.com
Fixed the error, but doesn't run as you expect?

What delimiter are you expecting in the input?

Whatever the delimiter is, pass it as the parameter to split.

Randy Armstrong

unread,
Oct 29, 2012, 12:40:33 AM10/29/12
to pyscr...@googlegroups.com
got these programs out of book python programming introduction to computer science 2004 which could be my problem. The first program: text2numbers.py works fine but it's sister program- numbers2text.py take the numbers and turns them back into legible text. and ive done it exactly as the book shows so thats why im puzzled and thinking its just out of date code. Im in my first year with this so if that gives you an indication as to where im at here.Thanks for helping Im just glad someone replied!
 
Randy

Reply all
Reply to author
Forward
0 new messages