On Mar 2, 10:36 pm, Simon King <simon.k...@uni-jena.de> wrote: > Is there a standard Python function ("is_identifier" or so) that tests > whether a string in whatever encoding is an identifier?
A possibly somewhat heavyhanded approach: sage: import tokenize,StringIO sage: S="QQ['t'], a, a_2, for" sage: list((a[0],a[1]) for a in tokenize.generate_tokens(StringIO.StringIO(S).readline)) [(1, 'QQ'), (51, '['), (3, "'t'"), (51, ']'), (51, ','), (1, 'a'), (51, ','), (1, 'a_2'), (51, ','), (1, 'for'), (0, '')] It does do the token splitting according to python rules and marks most "special" characters. Surprisingly, the tokenizer doesn't mark a reserved word like for yet, though. -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org