On 2006-10-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Tim Chase:
>> In practice, however, for such small strings as the given
>> whitelist, the underlying find() operation likely doesn't put a
>> blip on the radar. If your whitelist were some huge document
>> that you were searching repeat
Tim Chase:
> In practice, however, for such small strings as the given
> whitelist, the underlying find() operation likely doesn't put a
> blip on the radar. If your whitelist were some huge document
> that you were searching repeatedly, it could have worse
> performance. Additionally, the find()
You should use the s.translate()
It's 100x faster:
#Creates the translation table
ValidChars = ":./,^0123456789abcdefghijklmnopqrstuvwxyz"
InvalidChars = "".join([chr(i) for i in range(256) if not
chr(i).lower() in ValidChars])
TranslationTable = "".join([chr(i) for i in range(256)])
def valid_f
Matthew Warren wrote:
>>> import re
>>> badfilename='£"%^"£^"£$^ihgeroighroeig3645^£$^"knovin98u4#346#1461461'
>>> valid=':./,^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '
>>> goodfilename=re.sub('[^'+valid+']',' ',badfilename)
to create arbitrary character sets, it's usually
>
> Hi I'm writing a python script that creates directories from user
> input.
> Sometimes the user inputs characters that aren't valid
> characters for a
> file or directory name.
> Here are the characters that I consider to be valid characters...
>
> valid =
> ':./,^0123456789abcdefghijklmno
On 2006-10-17, Edgar Matzinger <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On 10/17/2006 06:22:45 PM, SpreadTooThin wrote:
>> valid =
>> ':./,^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '
>>
>
> not specifying the OS platform, these are not all the
> characters that may occur in a fil
>> If you're doing it on a time-critical basis, it might help to
>> make "valid" a set, which should have O(1) membership testing,
>> rather than using the "in" test with a string. I don't know
>> how well the find() method of a string performs in relationship
>> to "in" testing of a set. Test an
On 2006-10-17, Tim Chase <[EMAIL PROTECTED]> wrote:
> If you're doing it on a time-critical basis, it might help to
> make "valid" a set, which should have O(1) membership testing,
> rather than using the "in" test with a string. I don't know
> how well the find() method of a string performs in re
Hi,
On 10/17/2006 06:22:45 PM, SpreadTooThin wrote:
> valid =
> ':./,^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '
>
not specifying the OS platform, these are not all the characters
that may occur in a filename: '[]{}-=", etc. And '/' is NOT valid.
On a unix platform. And
> Sometimes the user inputs characters that aren't valid
> characters for a file or directory name. Here are the
> characters that I consider to be valid characters...
>
> valid =
> ':./,^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '
Just a caveat, as colons and slashes can gi
SpreadTooThin wrote:
> Hi I'm writing a python script that creates directories from user
> input.
> Sometimes the user inputs characters that aren't valid characters for a
> file or directory name.
> Here are the characters that I consider to be valid characters...
>
> valid =
> ':./,^0123456789a
I would suggest something like string.maketrans
http://docs.python.org/lib/node41.html. I don't remember exactly how
it works, but I think it's something like
>>> invalid_chars = "abc"
>>> replace_chars = "123"
>>> char_map = string.maketrans(invalid_chars, replace_chars)
>>> filename = "abc123.t
12 matches
Mail list logo