[Tutor] Encoding
Max S.
maxskywalker1 at gmail.com
Fri Nov 18 15:05:44 CET 2011
Well, I am assuming that by this you mean converting user input into a
string, and then extracting the numerals (0-9) from it. Next time, please
tell us your version of Python. I'll do my best to help with this. You
might try the following:
the_input = input("Insert string here: ") # change to raw_input in python 2
after = ""
for char in the_input:
try:
char = int(char)
except:
after += char
If other symbols might be in the string ($, @, etc.), then you might use
the_input = input('Insert string here: ') # change to raw_input in python 2
after = ''
not_allowed = '1234567890-=!@#$%^&**()_+,./<>?`~[]{}\\|'
for char in the_input:
if char in not_allowed:
pass
else:
after += char
This method requires more typing, but it works with a wider variety of
characters. Hopefully this helped.
On Thu, Nov 17, 2011 at 8:45 PM, Nidian Job-Smith <nidianjs at hotmail.com>wrote:
>
> Hi all,
>
> In my programme I am encoding what the user has in-putted.
>
> What the user inputs will in a string, which might a mixture of letters
> and numbers.
>
> However I only want the letters to be encoded.
>
>
> Does any-one how I can only allow the characters to be encoded ??
>
> Big thanks,
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111118/6f7b25cb/attachment.html>
More information about the Tutor
mailing list