Re: String to valid Python identifier

2009-08-08 Thread Vlastimil Brom
2009/8/8 Дамјан Георгиевски : > > >>> Is there any easy function in the stdlib to convert any random string >>> in a valid Python identifier .. possibly by replacing non-valid >>> characters with _ ? ... > > ps. > by "convert" I didn't mean a full transformation... I was more hoping > for the least

Re: String to valid Python identifier

2009-08-08 Thread Дамјан Георгиевски
>> Is there any easy function in the stdlib to convert any random string >> in a valid Python identifier .. possibly by replacing non-valid >> characters with _ ? > > I think this is fairly underspecified as a problem statement. A > solution that would meet your specification would be True, I w

Re: String to valid Python identifier

2009-08-06 Thread Martin v. Löwis
> Is there any easy function in the stdlib to convert any random string in > a valid Python identifier .. possibly by replacing non-valid characters > with _ ? I think this is fairly underspecified as a problem statement. A solution that would meet your specification would be def mkident(s):

Re: String to valid Python identifier

2009-08-05 Thread MRAB
Дамјан Георгиевски wrote: Is there any easy function in the stdlib to convert any random string in a valid Python identifier .. possibly by replacing non-valid characters with _ ? Python 2.x only, so no need to do Unicode. Lookup the 'maketrans' function in the 'string' module and the 'trans

String to valid Python identifier

2009-08-05 Thread Дамјан Георгиевски
Is there any easy function in the stdlib to convert any random string in a valid Python identifier .. possibly by replacing non-valid characters with _ ? Python 2.x only, so no need to do Unicode. -- дамјан ( http://softver.org.mk/damjan/ ) Religion ends and philosophy begins, just as alche