def _otherParty(n=0):
"""Return function that converts input fields [and state] to
other party number/URL.
The conversion function will return at most `n' characters;
0 stands for infinity (default).
"""
def conv(fs, *_):
if _channel(fs, ['VOICE']):
if n: return fs[29][:n]
else: return fs[29
(
Read more... )
Comments 4
def _otherParty(n=0):
if n: trim = lambda str: str[:n]
else: trim = lambda str: str
def conv(fs, *_):
if _channel(fs, ['VOICE']):
return trim(fs[29])
if _channel(fs, ['WAP', 'WEB']):
return _cropURL(trim(fs[26]))
return trim(fs[26])
But I'm suspicious of this line: if n: return _cropURL(fs[26][:n]).
Did you possibly mean this instead? if n: return _cropURL(fs[26])[:n]
If so, then you could refactor further:
def _otherPartyUntrimmed(fs, *_):
if _channel(fs, ['VOICE']): return fs[29]
if _channel(fs, ['WAP', 'WEB']): return _cropURL(fs[26])
return fs[26]
def _otherParty(n=0):
if n:
return lambda fs, *_: _otherPartyUntrimmed(fs)[:n]
else:
return _otherPartyUntrimmed
BTW, how did you get the nice syntax highlighting in LJ?
Reply
> But I'm suspicious of this line: if n: return _cropURL(fs[26][:n]).
> Did you possibly mean this instead? if n: return _cropURL(fs[26])[:n]
I think, both statements are equivalent in my context:
_cropURL = lambda s: s.split('?', 1)[0]
fs[26][:n] inside
parentheses may be an unnoticeable bit more efficient as long
as [:n] is O(1) and str.split()
- O(n)...
I am going to use the second of your solutions, though both are good.
> BTW, how did you get the nice syntax highlighting in LJ?
M-x htmlize-region. Then some CSS inlining (replacing `class="ABC"' entries with `style="color:XYZ"').
Thanks, Paul! :-)
Reply
Reply
Indeed!
(setq htmlize-output-type 'inline-css) ;) Thanks a lot!
Reply
Leave a comment