Message45679
| Author |
josiahcarlson |
| Recipients |
| Date |
2004年03月30日.07:10:54 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
Logged In: YES
user_id=341410
I'm curious to know if anyone would object to optional
minimum or maximum or both arguments, or even some
additional methods that would result in a potentially
constrained string output from long.tostring()?
If I were to split the functionality into three methods,
they would be as follows...
def atleast(long, atl):
if atl < 0:
raise TypeError("atleast requires a positive integer
for a minimum length")
a = long.tostring()
la = len(a)
return (atl-la)*'\o' + a
def atmost(long, atm):
if atm < 0:
raise TypeError("atleast requires a positive integer
for a minimum length")
a = long.tostring()
la = len(a)
return a[:atm]
def constrained(long, atl, atm):
if atm < atl:
raise TypeError("constrained requires that the
maximum length be larger than the minimum length")
if atl < 0 or atm < 0:
raise TypeError("constrained requires that both
arguments are positive")
a = long.tostring()
la = len(a)
return ((atl-la)*'\o' + a)[:atm]
I personally would find use for the above, would anyone else
have use for it? |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 15:36:54 | admin | link | issue923643 messages |
| 2007年08月23日 15:36:54 | admin | create |
|