In <02a54597$0$20629$c3e8...@news.astraweb.com> Steven D'Aprano
writes:
>On Wed, 26 Aug 2009 10:57:32 +, kj wrote:
>> Recursion! One of the central concepts in the theory of
>> functions! This is shown most clearly by the following elaboration of
>> my ori
In <02a54597$0$20629$c3e8...@news.astraweb.com> Steven D'Aprano
writes:
>http://docs.python.org/reference/executionmodel.html
>It is also discussed in the PEP introducing nested scopes to Python:
>http://www.python.org/dev/peps/pep-0227/
>It's even eluded to in the tutorial:
>http://docs.pyt
In Ethan Furman
writes:
>Going back through the archives I found Arnaud's post with this decorator:
>def bindfunc(f):
> def boundf(*args, **kwargs):
> return f(boundf, *args, **kwargs)
> return boundf
>If you use it on your fact function like so...
>class Demo(object):
>
In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch"
writes:
>But if you insist on the above methodology, you can do this:
>class Demo(object):
>def fact(n):
>def inner(n):
>if n < 2:
>return 1
>else:
>return n * inner(n
In <2a7gm6-9h@satorlaser.homedns.org> Ulrich Eckhardt
writes:
>kj wrote:
>> class Demo(object):
>> def fact_iter(n):
>> ret = 1
>> for i in range(1, n + 1):
>> ret *= i
>> return ret
&g
In Jean-Michel Pichavant
writes:
>kj wrote:
>> I think I understand the answers well enough. What I *really*
>> don't understand is why this particular "feature" of Python (i.e.
>> that functions defined within a class statement are forbidden from
>>
In Jean-Michel Pichavant
writes:
>in foo.py:
>a = 5
>b = a # works fine
>
>def foo(self):
> e = 5
> f = e #works fine
>It may be solved by creating the class upon the "class" statement. If
>the class A object is created, then c is added as a property of that
>object, th
In <02a6427a$0$15633$c3e8...@news.astraweb.com> Steven D'Aprano
writes:
>On Thu, 27 Aug 2009 09:09:21 +0200, Hendrik van Rooyen wrote:
>> On Wednesday 26 August 2009 17:45:54 kj wrote:
>>> In <02a54597$0$20629$c3e8...@news.astraweb.com> Steven D'Aprano
&
In <4a967b2f$0$19301$426a7...@news.free.fr> Bruno Desthuilliers
writes:
>The only thing one is entitled to expect when learning a new language is
>that the language's implementation follows the language specs.
In fact, the official docs, when they discuss scopes, are off to
a bad start:
Nam
Miles Kaufmann writes:
>On Aug 26, 2009, at 1:11 PM, kj wrote:
>> I think I understand the answers well enough. What I *really*
>> don't understand is why this particular "feature" of Python (i.e.
>> that functions defined within a class statement
In Ethan Furman
writes:
>kj wrote:
>> Miles Kaufmann writes:
>>>...because the suite
>>>namespace and the class namespace would get out of sync when different
>>>objects were assigned to the class namespace:
>>
>>
>>>
At work we want to implement a webapp using Google's GWT, and we're
debating whether to use the standard GWT approach with Java, or to
try Pyjamas. There's no great love here for Java, but there's the
concern that Pyjamas will not be able to deliver the full power
and/or convenience of standard
I'm having a hard time getting the hang of Python's package/module
scheme. I'd like to find out what's considered best practice when
dealing with the scenario illustrated below.
The quick description of the problem is: how can I have two nested
modules, spam.ham and spam.ham.eggs?
Suppose I h
In kj writes:
>I'm having a hard time getting the hang of Python's package/module
>scheme. I'd like to find out what's considered best practice when
>dealing with the scenario illustrated below.
>The quick description of the problem is: how can I have t
In "Rami Chowdhury"
writes:
>> An implication of all this is that if now I wanted to create a new
>> module x.y.z.w, this means that the previously "leaf"-module x.y.z
>> would become "non-leaf". In other words, I'd have to:
>>
>> 1. create the new directory x/y/z
>> 2. *rename* the file x/y/z
I'm looking for the "best-practice" way to define application-global
read-only switches, settable from the command line. The best
example I can think of of such global switch is the built-in variable
__debug__. This variable is visible everywhere in a program, and
broadly affects its operation
I want to send a POST request and have the returned content put
directly into a file. Is there a way to do this easily in Python?
I've been looking at the documentation for urllib2, but I can't
see a direct way to do this, other than saving the returned contents
to an in-memory variable and wri
In <7gdgslf2ogf8...@mid.uni-berlin.de> "Diez B. Roggisch"
writes:
>kj schrieb:
>> I want to send a POST request and have the returned content put
>> directly into a file. Is there a way to do this easily in Python?
>> I've been looking at the docum
In Ethan Furman
writes:
>I've seen a couple cool recipes implementing WORM* attributes if you
>wanted to ensure that your settings were not re-set.
>Steven D'Aprano wrote one with a class name of ConstantNamespace, you
>can search on that if you're interested. I'd include the code, but I
There's something wonderfully clear about code like this:
# (1)
def spam(filename):
for line in file(filename):
do_something_with(line)
It is indeed pseudo-codely beautiful. But I gather that it is not
correct to do this, and that instead one should do something l
In <02b2e6ca$0$17565$c3e8...@news.astraweb.com> Steven D'Aprano
writes:
>(3) For quick and dirty scripts, or programs that only use one or two
>files, relying on the VM to close the file is sufficient (although lazy
>in my opinion *wink*)
It's not a matter of laziness or industriousness, but
Is there some standardized way (e.g. some "official" module of such
limit constants) to get the smallest positive float that Python
will regard as distinct from 0.0?
TIA!
kj
--
http://mail.python.org/mailman/listinfo/python-list
In Mark
Dickinson writes:
>On Sep 7, 3:47=A0pm, kj wrote:
>> Is there some standardized way (e.g. some "official" module of such
>> limit constants) to get the smallest positive float that Python
>> will regard as distinct from 0.0?
>>
>>
In Mark
Dickinson writes:
>The smallest positive subnormal value
>is usually 2**-1074. If you want something that would still work
>if Python ever switched to using IEEE 754 binary128 format (or some
>other IEEE 754 format), then
>sys.float_info.min * 2**(1-sys.float_info.mant_dig)
Hmmm. Th
I'm trying to write a function, sort_data, that takes as argument
the path to a file, and sorts it in place, leaving the last "sentinel"
line in its original position (i.e. at the end). Here's what I
have (omitting most error-checking code):
def sort_data(path, sentinel='.\n'):
tmp_fd, tmp
In Mike
Driscoll writes:
>On Sep 15, 2:26=A0pm, kj wrote:
>> I'm trying to write a function, sort_data, that takes as argument
>> the path to a file, and sorts it in place, leaving the last "sentinel"
>> line in its original position (i.e. at the end). =A0
Upon re-reading my post I realize that I left out some important
details.
In kj writes:
>I'm trying to write a function, sort_data, that takes as argument
>the path to a file, and sorts it in place, leaving the last "sentinel"
>line in its original position (i.e. at t
In Chris Rebert
writes:
>On Tue, Sep 15, 2009 at 12:26 PM, kj wrote:
>> I'm trying to write a function, sort_data, that takes as argument
>> the path to a file, and sorts it in place, leaving the last "sentinel"
>> line in its original position (i.e. at t
I'm trying to get the hang of Python's OO model, so I set up this
conceptually simple problem of creating a new file-like class to
read a certain type of file. The data in this type of file consists
of multiline "chunks" separated by lines consisting of a single
".".
My first crack at it looks
In Steven D'Aprano
writes:
>On Wed, 16 Sep 2009 21:56:09 +, kj wrote:
>...
>> I thought at first that I could achieve this by overriding __getattr__:
>>
>> def __getattr__(self, attribute):
>> return self.fh.__getattr__(attribute)
>>
In Dive Into Python, Mark Pilgrim offers the function openAnything
that can open for reading "anything" (i.e. local files or URLs).
I was wondering if there was already in the standard Python library
an "official" version of this, that could not only open (for reading)
regular files and URLs, b
I've often come across the idea that good Python style deals with
potential errors using an EAFP ("easier to ask forgiveness than
permission") strategy rather than a LBYL ("look before you leap")
strategy.
For example, LBYL would look like this:
if os.path.isfile(some_file):
os.unlink(some
In <254eac4d-ce19-4af9-8c6a-5be8e7b0f...@u16g2000pru.googlegroups.com> Sean
DiZazzo writes:
>On Sep 18, 11:54=A0am, kj wrote:
>> I've often come across the idea that good Python style deals with
>> potential errors using an EAFP ("easier to ask forgiveness than
In <579a15bf-83c0-4228-9079-bbaac1222...@o13g2000vbl.googlegroups.com> Marius
Gedminas writes:
>On Sep 4, 9:29=A0pm, kj wrote:
>> The only solution I can come up with is to define a "dummy module",
>> say _config.py, which contains only upper-case variabl
In MRAB
writes:
>If, for example, you're
>going to copy a file, it's a good idea to check beforehand that there's
>enough space available for the copy.
How do you do that?
TIA,
kynn
--
http://mail.python.org/mailman/listinfo/python-list
My Python code is filled with assignments of regexp objects to
globals variables at the top level; e.g.:
_spam_re = re.compile('^(?:ham|eggs)$', re.I)
Don't like it. My Perl-pickled brain wishes that re.compile was
a memoizing method, so that I could use it anywhere, even inside
tight loops, w
In Robert Kern
writes:
>kj wrote:
>>
>> My Python code is filled with assignments of regexp objects to
>> globals variables at the top level; e.g.:
>>
>> _spam_re = re.compile('^(?:ham|eggs)$', re.I)
>>
>> Don't like it. My
In MRAB
writes:
>kj wrote:
>> In MRAB
>> writes:
>>
>>> If, for example, you're
>>> going to copy a file, it's a good idea to check beforehand that there's
>>> enough space available for the copy.
>>
>> How do yo
I've come across mentions of a mythical class of logging handlers
called DBHandler, but I can't find it anywhere.
Could someone please point me in the right direction?
(FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)
TIA!
kynn
--
http://mail.python.org/mailman/listinfo/pyth
In <7hsukcf2tqht...@mid.uni-berlin.de> "Diez B. Roggisch"
writes:
>kj schrieb:
>> I've come across mentions of a mythical class of logging handlers
>> called DBHandler, but I can't find it anywhere.
>>
>> Could someone please point me in th
In Vinay
Sajip writes:
>See my answer to a question on Stack Overflow, which has the source
>code for a simple handler which writes to a database using the Python
>DB-API 2.0:
>http://stackoverflow.com/questions/935930/creating-a-logging-handler-to-connect-to-oracle/1014450#1014450
>Although
The docs for divmod include the following:
divmod(a, b)
...For floating point numbers the result is (q, a % b), where q
is usually math.floor(a / b) but may be 1 less than that. ...
I know that floating point math can sometimes produce "unexpected"
results, so the above caveat is n
In Robert Kern
writes:
>On 2009-09-24 14:40 PM, kj wrote:
>>
>> The docs for divmod include the following:
>>
>> divmod(a, b)
>> ...For floating point numbers the result is (q, a % b), where q
>> is usually math.floor(a / b) but may be
Hi! Does anyone know of an easy way to convert a Unicode string into an image
file (either jpg or png)?
TIA!
~k
--
http://mail.python.org/mailman/listinfo/python-list
In Benjamin Kaplan
writes:
>On Fri, Aug 27, 2010 at 8:01 PM, kj wrote:
>>
>>
>> Hi! =A0Does anyone know of an easy way to convert a Unicode string into a=
>n image file (either jpg or png)?
>>
>Do you mean you have some text and you want an image containing t
Does anyone know of a Python module for *moderate* "time-stretching"[1]
an MP3 (or AIFF) file?
FWIW, the audio I want to time-stretch is human speech.
TIA!
~K
[1] By "moderate time stretching" I mean, for example, taking an
audio that would normally play in 5 seconds, and stretch it so that
i
The following attempt to get a list of partial sums fails:
>>> s = 0
>>> [((s += t) and s) for t in range(1, 10)]
File "", line 1
[((s += t) and s) for t in range(1, 10)]
^
SyntaxError: invalid syntax
What's the best way to get a list of
ne reply; rather,
I'm interested in reading people's take on the question and their
way of dealing with those functions they consider worthy of the
standard library.)
kj
--
http://mail.python.org/mailman/listinfo/python-list
of the local variable x.
I also tried a hack using eval:
for v in ('spam', 'ham', 'eggs'):
eval "%s = init('%s')" % (v, v)
but the "=" sign in the eval string resulted in a "SyntaxError:
invalid syntax".
Is there any way to use a loop to set a whole bunch of local
variables (and later refer to these variables by their individual
names)?
TIA!
kj
--
http://mail.python.org/mailman/listinfo/python-list
looked to me like a rather un-Pythonic hack, but seeing there
in the venerable collections module suggested to me that maybe this
is actually the best way to achieve this effect in Python. Is this
so? If not, please let me know of a better way.
TIA!
kj
--
http://mail.python.org/mailman/listinfo/python-list
27;, '5'])},
'B': set(['6', '7', '8'])}
I'm looking for a good algorithm for computing a hash key for
something like this? (Basically I'm looking for a good way to
combine hashkeys.)
Thanks!
kj
--
http://mail.python.org/mailman/listinfo/python-list
s).
If you had something else in mind, please let me know.
~kj
--
http://mail.python.org/mailman/listinfo/python-list
In de...@web.de (Diez B. Roggisch) writes:
>kj writes:
>> The short version of this question is: where can I find the algorithm
>> used by the tuple class's __hash__ method?
>Surprisingly, in the source:
>http://google.com/codesearch/p?hl=de#-2BKs-LW4I0/trunk/python
nternals at our local Python club.
Thanks,
~kj
--
http://mail.python.org/mailman/listinfo/python-list
lementation of t() to have a simple test
for mutability. Is there one?
Thanks!
~kj
--
http://mail.python.org/mailman/listinfo/python-list
t methods to the delegate (since in this case frozendict.__getattr__
wouldn't be called).
The handling of comparison methods is particularly horrific and
inefficient.
If "Beautiful is better than ugly", I sure how there's another way
that is a lot more beautiful than this one.
TIA!
~kj
--
http://mail.python.org/mailman/listinfo/python-list
popitem setdefault '
'update').split():
exec """
def %s(self, *a, **k):
cn = self.__class__.__name__
raise TypeError("'%%s' object is not mutable" %% cn)
""" % method
def __hash__(self):
r
In <4cae667c$0$29993$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano
writes:
>On Fri, 08 Oct 2010 00:23:30 +, kj wrote:
>Because it's always better to use a well-written, fast, efficient,
>correct, well-tested wheel than to invent your own slow, incorrect
&
n again,
just looking at the voodoo that goes into algorithms for computing
hashes fills me with despair. As much as I dislike it, sooner or
later I'll have to go on faith.
~kj
--
http://mail.python.org/mailman/listinfo/python-list
In kj writes:
>At any rate, using your [i.e. Arnaud's] suggestions in this and
>your other post, the current implementation of frozendict stands
>at:
>class frozendict(dict):
>for method in ('__delitem__ __setitem__ clear pop popitem setdefault '
>
In "Jonas H."
writes:
>On 10/08/2010 02:23 AM, kj wrote:
>Here's my implementation suggestion:
>class frozendict(dict):
> def _immutable_error(self, *args, **kwargs):
> raise TypeError("%r object is immutable" % self.__class__.__name__)
t frozensets had a consistent
order (i.e. frozensets that were equal according to '==' would be
iterated over in the same order), but now I'm not sure that this
is the case. (Granted, semantically, there's nothing in the
definition of a frozenset that would imply a consistent
Without some knowledge of the Python internals,
I don't see how this follows.
More specifically, it is not obvious to me that, for example,
hash(frozenset((,)))
would be identical to
hash(frozenset((hash(),)))
but this identity has held every time I've checked it. Similarly
for other more complicated variations on this theme.
Anyway, thanks for the code. It's very useful.
~kj
--
http://mail.python.org/mailman/listinfo/python-list
h function is (or appears to be) idempotent on integers
(long or not), even though it is not the identity on the integers.
Thanks to Steven for the counterexamples to show the latter. I've
learned tons from this exchange.
~kj
--
http://mail.python.org/mailman/listinfo/python-list
ime, so by now I've developed what can only be described
as a phobia to it. I probably need professional help at this point.
~kj
--
http://mail.python.org/mailman/listinfo/python-list
body can serve as a docstring.
What's the best way to achieve what I'm trying to do?
(Of course, all these acrobatics are hardly worth the effort for
the simple example I give above. In the actual situation I'm
dealing with, however, there are a lot more docstrings and global
variabl
MRAB, Peter: thanks for the decorator idea!
~kj
--
http://mail.python.org/mailman/listinfo/python-list
In kj writes:
>MRAB, Peter: thanks for the decorator idea!
As an afterthought, is there any way to extend this general idea
to other docstrings beyond function docstrings?
I imagine that the decorator idea works well for method docstrings
too (though I have not tried any of this yet).
;
The permissions of the file in question are all OK (0555); likewise,
the permissions of all the prefix subpaths leading to this file
are fine.
(For all I know, it is possible that, even though the libeng.dylib
file matches "_engClose", this is only a fragment of a longer symbol
name.)
In Emile van Sebille
writes:
>On 10/16/2010 2:15 PM kj said...
>>
>>
>>
>> The following interaction (in OS X) summarizes the situation:
>>
>> % echo $DYLD_LIBRARY_PATH
>> /Applications/MATLAB_R2010a.app/bin/maci64
>> % grep -r _engCl
In <8hujfsfb9...@mid.individual.net> Gregory Ewing
writes:
>kj wrote:
>> The hardest case is "module docstrings".
>Actually, that one's quite easy, just assign to __doc__.
>__doc__ = "This is a %s docstring" % "made-up"
D'oh! Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
(As I said, this happens only under some shells (e.g. emacs shell),
so YMMV.)
Does anyone know how can I suppress this annoying feature?
TIA!
~kj
--
http://mail.python.org/mailman/listinfo/python-list
In Jed Smith
writes:
>On Tue, Oct 19, 2010 at 1:37 PM, kj wrote:
>> % stty -echo
>That doesn't do what you think it does.
Gee, thanks. That really helped. I'll go talk to my guru now,
and meditate over this.
--
http://mail.python.org/mailman/listinfo/python-list
In Jed Smith
writes:
>On Tue, Oct 19, 2010 at 2:35 PM, kj wrote:
>> In Jed Smith smith.org> writes:
>>
>>>On Tue, Oct 19, 2010 at 1:37 PM, kj wrote:
>>
>>>> % stty -echo
>>
>>>That doesn't do what you think it does.
>>
stuff, so it is unlikely that
there's a clean solution; I'm hoping, however, that there may be
a way to fool python into doing the right thing; after all, this
strange behavior only happens under the Emacs shell; I don't observe
it under, e.g., Terminal or xterm.)
TIA!
~kj
--
http://mail.python.org/mailman/listinfo/python-list
In Lawrence D'Oliveiro
writes:
>In message , kj wrote:
>> I tried to fix the problem by applying the equivalent of "stty
>> -echo" within a python interactive session, but discovered that
>> this setting is immediately (and silently) overwritten.
>That
ing more Mathematica-like in Python would be
appreciated.
TIA!
kj
--
http://mail.python.org/mailman/listinfo/python-list
explicitly call
del on objects that should be gc'd?
TIA!
~kj
--
http://mail.python.org/mailman/listinfo/python-list
In "The Zen of Python", one of the "maxims" is "flat is better than
nested"? Why? Can anyone give me a concrete example that illustrates
this point?
TIA!
~kj
PS: My question should not be construed as a defense for "nested".
I have no particular pref
In
rantingrick writes:
>On Oct 25, 5:07=A0am, kj wrote:
>> In "The Zen of Python", one of the "maxims" is "flat is better than
>> nested"? =A0Why? =A0Can anyone give me a concrete example that illustrate=
>s
>> this point?
>Simpl
In Steve Holden
writes:
>On 10/25/2010 10:47 AM, rantingrick wrote:
>> On Oct 25, 5:07 am, kj wrote:
>>> In "The Zen of Python", one of the "maxims" is "flat is better than
>>> nested"? Why? Can anyone give me a concrete exa
In Terry Reedy
writes:
>On 10/25/2010 3:11 PM, kj wrote:
>> Well, it's pretty *enshrined*, wouldn't you say?
>No.
> > After all, it is part of the standard distribution,
>So is 'import antigravity'
Are you playing with my feelings?
% python
Pyt
In Steve Holden
writes:
>The answer is probably the same as you will see if you try
> from __future__ import braces
>That feature *is* available in Python 2.6 ;-)
Now, that's hilarious.
kj
--
http://mail.python.org/mailman/listinfo/python-list
In Steve Holden
writes:
>On 10/26/2010 2:44 PM, kj wrote:
>> In Steve Holden
>> writes:
>>
>>> The answer is probably the same as you will see if you try
>>
>>> from __future__ import braces
>>
>>> That feature *is* availa
301 - 384 of 384 matches
Mail list logo