Benji York <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > Disagree -- far more people THINK they're clever, than really ARE
> > clever. According to a recent article in the Financial Times, over 40%
> > of a typical financial firm's employees firmly b
from) statements are exceptions to this.
import x.y
binds or rebinds name x "on the fly", as well as attribute y of x.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
er), that's what it should do if it allowed the
following name to be a compound one, too.
Unfortunately, none of this suggests that it's reasonable to have
def x.y(z): ...
mean the same as
def y(x, z): ...
and I have no idea of how it would generalize to def x.y.z(t): ...
(while import x.y.z generalizes in a pretty obvious way wrt import x.y).
So, I'm not supporting the OP's idea; just rejecting the specific
objections to it.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
'' similarly. But, as I
said, "I'm not supporting the OP's idea; just rejecting the specific
objections to it". For once, I have a hard time articulating exactly why
I'd dislike such semantics for hypothetic syntax "def x.y", besides
minor points such as the difficulties wrt generalizing to "def x.y.z"...
but I do know which objections are NOT the ones which make me feel such
dislike!-)
Alex
--
http://mail.python.org/mailman/listinfo/python-list
<[EMAIL PROTECTED]> wrote:
...
> your idea. Could you summarize how exactly "f(x,y=z)" should be
> resolved, i.e. where it should look for "f"?
Lexically: local scope, outer functions outwards, globals, builtins.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ooks in superclass namespaces.
Nope:
>>> class B:
... def f(self): print 'b.f'
...
>>> class A(B): pass
...
>>> a=A()
>>> a.__class__.f(a)
b.f
>>>
Inheritance applies in any lookup of an attribute in a class, just as
well as on an instance of the class.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
elegating the building to a method or
function frees your application from such hardwiring and lets
it be concentrated (if needed at all) in one spot (the factory).
[[With the "registry" pattern you may even be able to remove
any hardwiring, but that's a pretty advanced and subtle idea]].
Alex
--
http://mail.python.org/mailman/listinfo/python-list
re another beast - much more useful than
> > staticmethods)
>
> Does it make any noticeable difference in efficiency, or does nobody
> care much about efficiency in Python?
Some of us do, at few but crucial moments; that's why we have timeit.py
to let you measure the perfo
m), with your use of:
input(raw_input(...
which means "get a string from the user and use it as a prompt to get
any value from the user" (a very peculiar usage).
The difference between `int' and `input' is rather enormous.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
bsolutely unrelated to that spot in the tutorial.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
06
>>> print mm
2
>>> print dd
5
>>>
As you see, these are integers (so, for example, mm is not '02' but just
2). Pretty easy to make them into strings, of course, if you want.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
and
kwds, since it's a rare need. Also, map returns a list, not a tuple, so
it's bordering on the absurd to think that your dreamed-for rmap would
be designed to return a tuple rather than a list -- you still have to
call tuple on the result, any way you build it.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
but im trying to
> mirgrate for windows to linux.
Python runs on Windows, Linux, Mac (where it comes with the OS, but then
that's also true of many Linux distros), and elsewhere.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
o access such JVM bytecode, use Jython instead.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
he binary value of its
k-th byte is ord(s[k]).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
attribute.
> My worry is that if '\n' *doesn't* signify a line break on the Mac,
It does, since a few years, since MacOSX is version of Unix to all
practical intents and purposes.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Brian Blais <[EMAIL PROTECTED]> wrote:
> someone might accidentally do damage to their system with an unchecked eval.
Nah, it takes malice and deliberation to damage a system from an eval.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
metadata associated with them showing the line-ending in use ?
Not in the filesystems I'm familiar with (they did use to, in
filesystems used on VMS and other ancient OSs, but that was a very long
time ago).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
hese last three statement into a
def remix(wrapped, fun): ...
""" return a function like 'wrapped' but w/name and defaults fm 'fun'
"""
...same 3 statements as above, from w = ... onwards...
Alex
--
http://mail.python.org/mailman/listinfo/python-list
So why don't you use Windows XP then? It's just like what you are using
now, but even more awesome!
--
http://mail.python.org/mailman/listinfo/python-list
gt; determines it ?
It doesn't. Python doesn't even try to guess: nor would any other
sensible programming language.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
getstate/setstate are
generally the best approach. An equally good alternative here, omit
setstate and just:
def __getstate__(self): return dict(lst=self.lst)
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ws several PEPs approved but not implemented for Python
2.5; take a look and write the development mailing list,
python-dev@python.org, to volunteer to implement one of them.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
great use case for async (even-driven) programming;
use Twisted (or even build on top of asyncore) and you'll easily
saturate your network bandwidth with modest CPU demands.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
or something like that. Goo...can't remember.
>
> See http://www-db.stanford.edu/~backrub/google.html
Yeah, I've heard of them, too.
> They've also employed some clever Python programmers, such as Greg
> Stein, Alex Martelli (isn't he a bot?) and some obscure du
John J. Lee <[EMAIL PROTECTED]> wrote:
...
> I wonder if that little outfit has considered open-sourcing any of
> their web client code?
What they've open-sourced so far is listed at
<http://code.google.com/projects.html> -- of these, the only
crawl/spider is Könguló,
der to use in such a
way, than either set or collections.deque? (For dict, I can see the
rationale for not having an 'addkey', even though the presence of class
method 'fromkeys' weakens that rationale... but for list, I cannot see
any reason that makes sense to me).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
st
> of the developers on mac are using 2.4 :-)
However, what comes with MacOSX is STILL 2.3 (specifically 2.3.5 with
Tiger).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ns exactly right is tricky (which is why bisect is a
good model!), but this way you get O(log N) performance for a list of
length N.
If N is not too huge, O(N) might be OK, and is, of course, way simpler
to code!-)
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Charles Krug <[EMAIL PROTECTED]> wrote:
> On 2006-02-11, Alex Martelli <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> >> Problem:
> >>
> >> You have a list of unknown length, such as this: list =
>
nt to hoist for performance, you can hoist more:
appenders = foo.append, qux.append
while some_condition:
for appender, anitem in zip(appenders, calculate_something()):
appender(anitem)
Alex
--
http://mail.python.org/mailman/listinfo/python-list
taking
SHIFT bits.
> Many thanks to anyone bored enough to review this code.
Sorry, I don't have the time, but I hope the above tip can be useful.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
s time to waste, "setification" being only an
optimization, it can also be removed: filter(l2.__contains__, l1) etc
(very slow for long lists, of course).
Personally, I'd always use (depending on guesses regarding lengths of
lists) [x for x in l1 if x in l2] or the setified equiva
a draft, being
discussed in the last few days on python-dev.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Xavier Morel <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > Carl Banks <[EMAIL PROTECTED]> wrote:
> >...
> >>> class better_list (list):
> >>> tail = property(None, list.append)
> >> This is an impress
it yourself?
Yes, it is a point worth making, since the lack of hoisting is a
frequent cause of performance loss.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
imetools.Message instance whose headers have metadata (such as content
type information).
If that doesn't fit your needs well, you may study the sources of
urllib.py in your Python's library source directory, to see exactly what
it's doing and code your own modified version.
Alex
Alex
--
http://mail.python.org/mailman/listinfo/python-list
World , how are you today?"
>
> Have googled, and worked my way through the first 7 chapters of Byte of
> Python, but to no avail...
Use string formatting:
print 'Hello %s, how are you today?' % strName
Alex
--
http://mail.python.org/mailman/listinfo/python-list
rh0dium <[EMAIL PROTECTED]> wrote:
...
> Why doesn't this work as expected.. I expect that the the lines within
> the sections will get modified - permanently. It is modifying them
> during the first section but they never get saved to the new values..
> Can anyone help me and even better expl
you can get leaner and faster code
by redoing it all in C, can't you?"
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ot;!-)
> -- just bought "cookbook" and "nutshell" moments ago btw
Nice coincidence, and thanks!-)
Alex
--
http://mail.python.org/mailman/listinfo/python-list
f. This way, f is the filename, m a message object useful for
metadata (e.g., content type).
Otherwise looks fine.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ls. However, there doesn't appear to be further spreading of such
object models; "big" new languages like C# (and indeed the whole
underlying CLR framework, which also forced the semantics of VB) are
strongly class-based.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Frank Potter <[EMAIL PROTECTED]> wrote:
...
> Does google supply some webservice to programmers? I did see
Yep, see http://www.google.com/apis/index.html .
Alex
--
http://mail.python.org/mailman/listinfo/python-list
John Bokma wrote:
> Al Balmer <[EMAIL PROTECTED]> wrote:
>
> > have for a long time, and I can understand that it would be better if
> > everyone filtered or ignored him,
>
> The best would be if everybody instead of posting replies would complain
> to his ISP and Usenet provider. Xah is a major an
ggest compiling the code and examining the names used in the code
object (co_names attribute of the code object which compile returns) --
refuse to execute the code if it mentions, defines or uses any special
name (starting and ending with two underscores). That, plus removing
almost all builtins as you do here, should be a good start.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
easure cases of interest.
If you don't (not especially) then the first solution looks neat,
elegant, readable, and concise.
But never build up substantial strings with a loop of += of small
strings: that's O(N squared) and will MAKE you care about performance
even where you otherwise wouldn't!-)
Alex
--
http://mail.python.org/mailman/listinfo/python-list
<[EMAIL PROTECTED]> wrote:
> hi
> how can i get the number of days since epoch using the time module?
> or do i have to manually do the arithmetic?
Try the datetime module -- better suited to computing days, than the
time module, IMHO.
Alex
--
http://mail.python.org/mailman/
<[EMAIL PROTECTED]> wrote:
> hi
>
> i have a file something like this
>
> abcdefgh
> ijklmnopq
> 12345678
> rstuvwxyz
> .
> .
> .
> 12345678
> .
>
> whenever i search the file and reach 12345678, how do i get the line
> just above and below ( or more than 1 line above/below) the
as far as I can tell. However, when I
> type python at the command line, I get "command not found" so,
>
> 2) How do I get OS X to recognize python at the command line?
Edit a ~/.bashrc file to add /usr/local/bin to your PATH.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
.
> Remember Donald Knuth's quote.
> "Premature optimization is the root of all evil in programming".
I believe Knuth himself said he was quoting Tony Hoare, and indeed
referred to this as "Hoare's dictum".
Alex
--
http://mail.python.org/mailman/listinfo/python-list
? SSL is fully implemented in Twisted, AFAIK. Is the example at
<http://twistedmatrix.com/projects/core/documentation/examples/echoserv_
ssl.py> at all unclear or mysterious, for example?
Alex
--
http://mail.python.org/mailman/listinfo/python-list
of the attributes are properties,
slots or weirder descriptors yet.
For plain vanilla class instances, though,
self.__dict__.update(settings)
may be sufficient.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
wadays. Please eliminate three.
PS: I am *not* a crackpot!
Alex
--
http://mail.python.org/mailman/listinfo/python-list
anguage, and it's not interpreted.
OK, but then we should change <http://python.org/doc/Summary.html>,
which starts with "Python is an interpreted, interactive,
object-oriented programming language." -- if "it's not interpreted",
then why is this crucial page o
esperate task to try to count them all...:-(
Alex
--
http://mail.python.org/mailman/listinfo/python-list
wrote:
> [EMAIL PROTECTED] (Alex Martelli) wrote:
>
> >Edit a ~/.bashrc file to add /usr/local/bin to your PATH.
>
> Hi Alex,
>
> Easier said than done for a non-unix expert. Correct me if I am wrong. Bash
> looks at the contents of the PATH variable to decided wh
#x27;s own Python (2.3.5) will be trivial -- stay tuned!
Alex
--
http://mail.python.org/mailman/listinfo/python-list
bruno at modulix <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> >...
> >>>There are very good web framework for java and ruby ,
> >>>Is there one for python ?
> >>
> >
hefile.read(3) in a loop, move to the next file
when the current one is exhausted. What part of this is giving you
problems?
Alex
--
http://mail.python.org/mailman/listinfo/python-list
want in Python is by overriding
__getattr__ (which gets called when other normal lookup procedures fail
and would, absent __getattr__, raise AttributeError), not by trying to
install as the __dict__ something whose type isn't exactly __dict__.
Other approaches may work, but they depend on implem
tive;-). No reason for programming languages, or other formal
languages, to follow natural language down this destructive path.
In any case, the point is crucial: since Python will never do something
as abysmal as introducing a closed interval rather than a semiopen one,
the same kind of people who now
so far.
__slots__ is not a method, so it falls outside that purpose as stated.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
st PC _I_ owned had 4K of RAM (the cheaper model only had 1K, but
I splurged for the big one) -- Sinclair ZX80. But I didn't run Python
on it (indeed I soon swapped it for one with very similar HW but Forth
instead of Basic, called the "Jupiter Ace": Forth's force has always
be
the idea, to the point
that I never got around to it -- gmpy includes a lot of functionality
for bit-level manipulation, but still only with immutable bitlists
(mapped into gmpy.mpz instances).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
DO get recompiled) rather than relying on
semidecent unittests is scant consolation -- there's still no bound to
the amount of work that may be needed to repair the wreckage.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Peter Hansen <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > Zefria <[EMAIL PROTECTED]> wrote:
> >...
> >>this special case I'm expecting each "carrier" to have up to 150
> >>fighters, and 3 to 5 carriers for each of the tw
ion on slicing:
> >
> > "substrings can be specified with the slice notation: two indices
> > separated by a colon"
> >
> Fredrik, how would you use slices to split a string by groups of 3
> characters?
I can't answer for him, but maybe:
on the Python bug
tracker (http://sourceforge.net/bugs/?group_id=5470) somebody will (look
into it, for sure, and hopefully fix it in time for 2.4.3).
Thanks,
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
> Hi,
> Is there any gain in performance because of augmented assignments.
>
> x += 1 vs x = x+1
>
> Or are both of them the same.
Just *MEASURE*, man!
helen:~/apy alex$ python -mtimeit -s'x=0.0'
th
whines about it); Python is clearly much better off if such people run
away to Ruby, with its (expletive deleted) a..b AND a...b syntaxes just
to ensure maximum confusion;-).
> 2. How could a stride be included in this notation?
The natural way would be (x to y by z), I think.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
the words I
had written. Nevertheless, in your honor, I guess I will redundantly
change the ONCE into JUST ONCE in the second edition (I do strive for
maximum conciseness in the Nutshell, but I guess I can spare one extra
four-letter word, even though this is the only time I ever heard anybody
expres
f some text to fail to see potential issues
with the text, which may trip some readers but appears to be perfect to
the author -- that's why two heads are better than one, and N>2 even
better than two!-).
So, again, thanks.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
t could be the
other way 'round) -- I don't remember how it indicates a step. I do
think this is a wart (lack of visual or mnemonic distinction), though
I'm sure Ruby enthusiasts would not agree.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Mu.
--
http://mail.python.org/mailman/listinfo/python-list
make the
nesting structure of items of _aux more obvious. Of course, each of
these has a variant using sorted instead of sort, and for those you
could use izip from itertools rather than built-in zip, and do
everything within one single statement, etc, etc.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
<[EMAIL PROTECTED]> wrote:
> I am using the print function in my python script.
> Can you please tell me what can I do to redirect the output to an file?
f = open('aaargh', 'w')
print>>f, 'killew wabbit'
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ode string when you're done,
x = unicode(int(x) / 10)
should work. If you want x to become an integer, omit the unicode call
around the int(x)/10 expression.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ormance indeed, thanks!
Except it rejects a w that's JUST an underscore, while it would accept a
w that's just a letter, which seems weird to me. Using 'a' as the
second argument of the replace call, as somebody else suggested, appears
to produce a more sensible uniformity.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
Crutcher <[EMAIL PROTECTED]> wrote:
...
> No, I don't disagree that people do this. The history of "Zen and the
> Art of X" dates from "Zen and the Art of Motorcycle Repair", which is
That's Maintenance, not Repair. Subtle but important distinction.
Ron Adam <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Your solution Steven Bethard looks very intelligent, here is a small
> > speed test, because sorting a list according another one is a quite
> > common operation.
> > (Not all solutions are r
dden to
perform any assignment on a function-call.
If you're keen on these semantics, use for example
f().extend([4])
which IS quite legal (or, if you know the RHS list has only one item,
f().append(4) is clearer and more effective).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ce, you cannot substitute a function call,
nor a constant (literal) list (nor any of several other possible
literals and other expressionforms).
Wherever Python just needs a value, not a rebindable whatever, then of
course you can supply that value in whatever syntax form suits you best,
includin
emented during Pycon, i.e., today).
Personally, I would keep pushing back against this approach even after
I'd gone to the trouble of implementing it more solidly -- in no way is
clarity served by having magic local variables appear out of the blue
(or, rather, the black of black magic). However, whether something CAN
be done, and whether it SHOULD be done, are separate issues.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
', or any other such approach, will suffice.
But of course, then the method's body would have to use _.one rather
than var_one, _.two rather than var_two, and _.empty_list rather than
empty_list (what a strange name -- does it STAY empty throughout the
method's execution?!). To me this
(d.keys())
AND to be faster (would be pretty weird if it weren't faster...!).
E.g., ...:
helen:~ alex$ python -mtimeit -s'd=dict(enumerate("tarazoplay"))'
'sorted(d.keys())'
10 loops, best of 3: 6.82 usec per loop
helen:~ alex$ python -mtimeit -s'd=dict
grammers who
fully know what they're doing, so nobody at the time took the trouble of
building such strong fences around it (it wouldn't save us many of the
huge stream of questions and misunderstandings we're getting all the
time about it, anyway).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
MrJean1 <[EMAIL PROTECTED]> wrote:
> An example of the RARE use case may be this particular one
>
> <http://mail.python.org/pipermail/python-list/2004-May/220513.html>
A benchmark is not a use case.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
LLY be false (and ditto
for true). In set terms, say, "all integers x such that x>x" would be
an *intrinsically* empty set, while "all dogs that are in this house
right now" would be a set which *just happens* to be empty -- they
aren't "one and the same, the sole
Ben Finney <[EMAIL PROTECTED]> wrote:
...
> The Python parser knows what to do when a comparison returns
> NotImplemented.
The parser has nothing to do with it, but the bytecode interpreter sure
does;-).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
", line 184, in init_application_name
ns_info['CFBundleName'] = GApplications.application_name
TypeError: object does not support item assignment
That's when I try (after installing PyGUI):
helen:~/Desktop/PyGUI-1.6/Demos alex$ python blobedit.py
MacOSX, XCode, Python and PyObjC all at the latest
e. Someday, range will behave like xrange automagically,
...
> Thanks. Yes, this will be a problem for iterations in the order of 10**5 and
> upwards only, and those are rare in most applications. So my question was
And not crucial when they happen, mostly:
helen:~ alex$ python -mtimeit -s'
gene tani <[EMAIL PROTECTED]> wrote:
...
> There's a couple Alex M slideshows and a couple discussions of
> Creational/Structural / Behavioral patterns
>
> http://www.strakt.com/docs/ep04_pydp.pdf
And more of my stuff (including slideshows on Design Patterns in Pyth
uing tasks -- unless either firms, such
as Enthought, or volunteers, commit to such tasks, they won't "just
happen".
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ill one. Could you
maybe use /dev/random or the like? Cfr
<http://world.std.com/~cme/P1363/ranno.html> for an introduction to the
subject. (For speed, you may want to look into gmpy.sf.net, but that's
quite a separate issue from the strength of your random numbers).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
ed thread waits and fills the queue again). [[Alternatively you
could subclass Queue and override the hook-method _get, which always
gets called in a properly locked and thus serialized condition; but that
may be considered a reasonably advanced task, since such subclassing
isn't documented in the reference library, only in Queue's sources]].
Alex
--
http://mail.python.org/mailman/listinfo/python-list
code
> repeated each time I need it, but I think it's dumb that
> it's that complicated.
If you need many immutable classes, inject __setattr__ etc into them
(via metaclass or otherwise).
Alex
--
http://mail.python.org/mailman/listinfo/python-list
t; Why catch an error only to re-raise it?
To avoid the following handler[s] -- a pretty common idiom.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
to idiomatic
Python itself.
Therein, of course, lies the danger -- over-relying on this adapter may
mean you never really learn to "think the Python way" and thus to code
idiomatic Python, even when that would be most appropriate (i.e., in
most cases). Still, Python _is_ a "consen
(and Smalltalk), but I do not see it
as a question of rigor and consistency at all -- e.g., I do not perceive
Smalltalk as less rigorous or consistent than C++, on the contrary.
So, I agree with your choice, and I think I understand your motivations,
but I do not entirely share your motivations, personally speaking.
Alex
--
http://mail.python.org/mailman/listinfo/python-list
1301 - 1400 of 2602 matches
Mail list logo