Hrvoje Niksic [EMAIL PROTECTED] wrote:
Michael Goerz [EMAIL PROTECTED] writes:
when I try to catch ctrl+c with
except KeyboardInterrupt:
pychecker tells me
Catching a non-Exception object (KeyboardInterrupt)
Looks like a pychecker bug. It might be confused by KeyboardInterrupt
Simon Pickles [EMAIL PROTECTED] wrote:
Is is possible to access the refcount for an object?
import sys
sys.getrefcount(42)
6
Ideally, I am looking to see if I have a refcount of 1 before calling del
That's a pointless exercise: you probably don't understand what del does.
All that del does
Berteun Damman [EMAIL PROTECTED] wrote:
On Tue, 29 Jan 2008 09:23:16 -0800 (PST), [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
If you're going to delete elements from
a list while iterating over it, then do
it in reverse order:
Why so hard? Reversing it that way creates a copy, so you might
rndblnch [EMAIL PROTECTED] wrote:
On Jan 25, 9:01 pm, Duncan Booth [EMAIL PROTECTED] wrote:
rndblnch [EMAIL PROTECTED] wrote:
the following example should also
work:
size = Point(width=23, height=45)
w, h = size
So you want the unpacking to depend on how the Point was initialised
rndblnch [EMAIL PROTECTED] wrote:
(sorry, draft message gone to fast)
i.e. is it possible to write such a function:
def f(**kwargs):
skipped
return result
such as :
f(x=12, y=24) == ['x', 'y']
f(y=24, x=12) == ['y', 'x']
what i need is to get the order of the keyword
rndblnch [EMAIL PROTECTED] wrote:
the following example should also
work:
size = Point(width=23, height=45)
w, h = size
So you want the unpacking to depend on how the Point was initialised!
Aaargh!
--
http://mail.python.org/mailman/listinfo/python-list
Kristian Domke [EMAIL PROTECTED] wrote:
foo = (not f and 1) or 0
In this case f may be None or a string.
If I am not wrong here, one could simply write
foo = not f
Yes, it sounds pretty silly, and not just on the level you spotted.
The only difference between the two expressions is
Steven D'Aprano [EMAIL PROTECTED] wrote:
On Wed, 23 Jan 2008 09:30:28 +, Duncan Booth wrote:
Kristian Domke [EMAIL PROTECTED] wrote:
foo = (not f and 1) or 0
In this case f may be None or a string.
If I am not wrong here, one could simply write
foo = not f
Yes, it sounds
Mel [EMAIL PROTECTED] wrote:
oyster wrote:
why the following 2 prg give different results? a.py is ok, but b.py
is 'undefiend a'
I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC
v.1310 32 bit (Intel)] on win32
#a.py
def run():
if 1==2:# note, it
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
On Mon, 21 Jan 2008 17:08:46 -0200, Gabriel Genellina wrote:
The future statement is another example, even worse:
if 0:
from __future__ import with_statement
with open(xxx) as f:
print f
In Python =2.5 it's a compile time
Chris [EMAIL PROTECTED] wrote:
You could always pre-pad the lists you are using before using the zip
function, kinda like
def pad(*iterables):
max_length = 0
for each_iterable in iterables:
if len(each_iterable) max_length: max_length =
len(each_iterable)
for
Hendrik van Rooyen [EMAIL PROTECTED] wrote:
It would have been nice, however, to have gotten something like:
TypeError - This routine needs a tuple.
instead of the silent in line calling of the routine in question,
while failing actually to start a new thread.
Given that the
iu2 [EMAIL PROTECTED] wrote:
file a3.py:
from a1 import the_number
import a2
...
Why doesn't it work in the first version of a3.py?
Think of 'import a2' as being the same as:
a2 = __import__('a2')
and 'from a1 import the_number' as roughly the same as:
the_number =
Gary Herron [EMAIL PROTECTED] wrote:
hakim ouaras wrote:
Hi,
I am begining with python, I want to know what is the utility and how
to use the expression NotImplementedError.
Thak you for your answers
Hakim
It's meant to be used to mark a procedure that you intend to write,
but have
John Nagle [EMAIL PROTECTED] wrote:
I'm printing out each entry in gc.garbage after a garbage collection in
DEBUG_LEAK mode, and I'm seeing many entries like
cell at 0x00F7C170: function object at 0x00FDD6B0
That's the output of repr. Are cell objects created only from
external C
abhishek [EMAIL PROTECTED] wrote:
Hi group any idea on HOW TO HANDLE POINTERS FROM NON-LOCAL HEAPS??
Yes, it indicates you haven't read
http://catb.org/~esr/faqs/smart-questions.html
--
http://mail.python.org/mailman/listinfo/python-list
Bruno Desthuilliers [EMAIL PROTECTED]
wrote:
You want:
return bears(n - 42)
Actually, no he doesn't. He needs to explore all options when the first
attempt fails. But I'm not going to write his homework for him.
--
http://mail.python.org/mailman/listinfo/python-list
erik gartz [EMAIL PROTECTED] wrote:
Hi. I'd like to be able to write a loop such as:
for i in range(10):
pass
but without the i variable. The reason for this is I'm using pylint
and it complains about the unused variable i. I can achieve the above
with more lines of code like:
i = 0
Fredrik Lundh [EMAIL PROTECTED] wrote:
Giampaolo Rodola' wrote:
To flush a list it is better doing del mylist[:] or mylist = []?
Is there a preferred way? If yes, why?
The latter creates a new list object, the former modifies an existing
list in place.
The latter is shorter, reads
cesco [EMAIL PROTECTED] wrote:
Hi,
say I have a string like the following:
s1 = 'hi_cat_bye_dog'
and I want to replace the even '_' with ':' and the odd '_' with ','
so that I get a new string like the following:
s2 = 'hi:cat,bye:dog'
Is there a common recipe to accomplish that? I can't
[EMAIL PROTECTED] wrote:
Duncan Booth:
I tried to measure this with timeit, and it looks like the 'del' is
actually quite a bit faster (which I find suprising).
Yes, it was usually faster in my benchmarks too. Something similar is
true for dicts too. I think such timings are influenced
Simon Willison [EMAIL PROTECTED] wrote:
How can I tell Python I know this says it's a unicode string, but I
need you to treat it like a bytestring?
Can you not just fix your xml file so that it uses the same encoding as it
claims to use? If the xml says it contains utf8 encoded data then it
Fredrik Lundh [EMAIL PROTECTED] wrote:
ET has already decoded the CP1252 data for you. If you want UTF-8, all
you need to do is to encode it:
u'Bob\x92s Breakfast'.encode('utf8')
'Bob\xc2\x92s Breakfast'
I think he is claiming that the encoding information in the file is
incorrect and
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Hi,
Is there a string function to trim all non-ascii characters out of a
string?
Let say I have a string in python (which is utf8 encoded), is there a
python function which I can convert that to a string which composed of
only ascii characters?
Michael Sparks [EMAIL PROTECTED] wrote:
To be clear - I REALLY didn't like the fact that generators were
single layer when I first saw them - it seemed a huge limitation.
(Indeed as huge a limitation as only having single level function
calls, or only single layer of nesting for namespaces,
Akihiro KAYAMA [EMAIL PROTECTED] wrote:
Thanks for your replies.
But current Python generator specification requires me:
def f1():
for x in foo(f2, foo): yield x
for x in foo(f2, foo): yield x
# XXX v = ... (I don't know how to do this)
for x in foo(f2, v=%s world % v,
Michael Sparks [EMAIL PROTECTED] wrote:
Duncan Booth wrote:
Unfortunately generators only save a single level of stack-frame, so
they are not really a replacement for fibers/coroutines. The OP
should perhaps look at Stackless Python or Greenlets. See
On the surface of things, the single
William McBrine [EMAIL PROTECTED] wrote:
Hi all,
I'm pretty new to Python (a little over a month). I was wondering -- is
something like this:
s = re.compile('whatever')
def t(whatnot):
return s.search(whatnot)
for i in xrange(1000):
print t(something[i])
significantly
Arnaud Delobelle [EMAIL PROTECTED] wrote:
I am not really familiar with ruby but these fibers seem to be some
sort of coroutines. Since python 2.5, generators can be sent values,
this can be used to implement what you want. I have had a got at it
for fun and this is what I came up with:
Matias Surdi [EMAIL PROTECTED] wrote:
I have the following code:
--
import new
class A:
def a(self):
print Original
def other(cad):
return cad + modified
def replace_method(method):
def b(self,*args,**kwargs):
result =
thebjorn [EMAIL PROTECTED] wrote:
It would have been nice to be able to write
class Foo(object):
@property
def expensive(self):
self.expensive = insert expensive db call here
return self.expensive
but apparently I can't set [that] attribute :-(
You can set and
[EMAIL PROTECTED] wrote under the subject line Is this a
bug in int()?:
int('0x', 16)
0
I think it is a general problem in the tokenizer, not just the 'int'
constructor. The syntax for integers says:
hexinteger ::= 0 (x | X) hexdigit+
but 0x appears to be accepted in source code as an
tomasz [EMAIL PROTECTED] wrote:
Is there an alternative to it? Am I missing something? Python doesn't
have special variables $1, $2 (right?) so you must assign the result
of a match to a variable, to be able to access the groups.
Look for repetition in your code and remove it. That will
ram [EMAIL PROTECTED] wrote:
Here's a little issue I run into more than I like: I often need to
unpack a sequence that may be too short or too long into a fixed-size
set of items:
a, b, c = seq # when seq = (1, 2, 3, 4, ...) or seq = (1, 2)
What I usually do is something like this:
[EMAIL PROTECTED] wrote:
I'm using IDLE for my Python programming. I can't seem to solve one
issue though. Whenever I try to indent a region of code, I simply
select it and hit the tab key, as I usually do in most editors, like
GEdit or Geany on Linux, for instance, and it works fine. But,
Russell [EMAIL PROTECTED] wrote:
I've searched the Language
Reference and was not able to find any info regarding the structure of
this code fragment:
int(text) if text.isdigit() else text
http://docs.python.org/whatsnew/pep-308.html
--
http://mail.python.org/mailman/listinfo/python-list
Christian Heimes [EMAIL PROTECTED] wrote:
Python 2.6 and 3.0 have a more Pythonic way for the problem:
class A(object):
@property
def foo(self):
return self._foo
@foo.setter
def foo(self, value)
self._foo = value
@foo.deletter
def foo(self)
weheh [EMAIL PROTECTED] wrote:
John and Martin,
Thanks for your help. However, I have identified the culprit to be
with Apache and the command:
AddDefaultCharset utf-8
which forces my browser to utf-8 encoding.
It looks like your suggestions to change charset were incorrect. My
weheh [EMAIL PROTECTED] wrote:
Hi Duncan, thanks for the reply.
FWIW, the code you posted only ever attempted to set the character
set encoding using an html meta tag which is the wrong place to set
it. The encoding specified in the HTTP headers always takes
precedence. This is why
the
[EMAIL PROTECTED] wrote:
So the data us there, but the sql only works part of the time. My SQL
works if my database is in SQL Server, but not sqlite. Is my SQL
malformed? Is it something about dates in sqlite? Or is it something
else?
Your dateworked field seems to have strings rather than
sturlamolden [EMAIL PROTECTED] wrote:
On 9 Des, 23:34, Christian Heimes [EMAIL PROTECTED] wrote:
http://antoniocangiano.com/2007/11/28/holy-shmoly-ruby-19-smokes-pyth
...
The Ruby developers are allowed to be proud. They were able to
optimize some aspects of the implementation to get one
Peter Otten [EMAIL PROTECTED] wrote:
Only if you try to modify the list from both of them.
One deletion is enough to trigger the assertion:
Yes, but the assertion isn't intended to be the complete code.
Or you just rule that delete(x) must occur immediately after x =
next().
My
Neil Cerutti [EMAIL PROTECTED] wrote:
If you put an instrumented iterator through, say, reversed or
sorted, you'd lose the ability to use it to modify the list
I think that is kind of irrelevant. reversed doesn't take an iterator, it
requires a sequence and returns an iterator. sorted will
massimo s. [EMAIL PROTECTED] wrote:
1) Is there a good tutorial, example collection etc. on the csv module
that I'm missing?
Yes, see http://docs.python.org/lib/csv-examples.html
2) Is there an alternative csv read/write module?
No but feel free to write your own
3) In case anyone else is
Neil Cerutti [EMAIL PROTECTED] wrote:
Python's iterators are unsuitable for mutating the linked list
while iterating--the only major application of linked lists.
Wrapping in a generator won't allow you to use for loop syntax,
unless I'm missing something, which has often happened.
It is
Peter Otten [EMAIL PROTECTED] wrote:
Neil Cerutti wrote:
On 2007-12-10, Duncan Booth [EMAIL PROTECTED] wrote:
def test():
ll = LinkedList([random.randint(1,1000) for i in range(10)])
for el in ll:
if el.value%2==0:
ll.delete(el)
print [el.value for el
Michael Sparks [EMAIL PROTECTED] wrote:
I'm interested in writing a simple, minimalistic, non persistent (at
this stage) software transactional memory (STM) module. The idea being
it should be possible to write such a beast in a way that can be made
threadsafe fair easily.
For those who
[EMAIL PROTECTED] wrote:
def lookupdmo(domain):
lines = open('/etc/virtual/domainowners','r').readlines()
lines = [ [y.lstrip().rstrip() for y in x.split(':')] for x in
lines]
lines = [ x for x in lines if len(x) == 2 ]
d = dict()
for line in lines:
Matt Nordhoff [EMAIL PROTECTED] wrote:
Using two list comprehensions mean you construct two lists, which sucks
if it's a large file.
Only if it is very large. You aren't duplicating the data except for
entries with whitespace round them. If there isn't a lot of whitespace then
the extra
Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-12-07, Duncan Booth [EMAIL PROTECTED] wrote:
from __future__ import with_statement
def loaddomainowners(domain):
with open('/etc/virtual/domainowners','r') as infile:
I've been thinking I have to use contextlib.closing for
auto-closing
Terry Jones [EMAIL PROTECTED] wrote:
Duncan Booth wrote:
You can use Python's bytecode disassembler to see what actually gets
executed here:
def fn_outer(v):
a=v*2
def fn_inner():
print V:%d,%d % (v,a)
fn_inner()
import dis
dis.dis(fn_outer)
2
George Sakkis [EMAIL PROTECTED] wrote:
Even more amazing is the rate C++ is losing ground:
http://www.tiobe.com/tiobe_index/C__.html
Given that the ratings are relative it may simply indicate that C++ is
standing still while the others run ahead.
--
c james [EMAIL PROTECTED] wrote:
Thanks, I was trying to eliminate another level of indirection with a
test at each invocation of __call__
Try using different subclasses for each variant:
class YesNo(object):
def __new__(cls, which, *args, **kw):
if cls is YesNo:
John Machin [EMAIL PROTECTED] wrote:
Hmmm ... the encode is documented as Produce a string that is
suitable as Unicode literal in Python source code, but it *isn't*
suitable. A Unicode literal is u'blah', this gives just blah. Worse,
it leaves the caller to nut out how to escape apostrophes
slomo [EMAIL PROTECTED] wrote:
print line
\u0050\u0079\u0074\u0068\u006f\u006e
But I want to get a string:
\u0050\u0079\u0074\u0068\u006f\u006e
How do you make it?
line.decode('unicode-escape')
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rudin [EMAIL PROTECTED] wrote:
You have to understand that the default value for v - an empty list -
is made at compile time
Not at compile time: the default value is created at runtime when the def
statement is executed.
--
http://mail.python.org/mailman/listinfo/python-list
Iain King [EMAIL PROTECTED] wrote:
FTR, I won't be using this :) I do like this syntax though:
class Vector:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def abs(self):
using self:
return math.sqrt(.x*.x + .y*.y +
Ton van Vliet [EMAIL PROTECTED] wrote:
It would boil down to choice: explicit/speed vs implicit/readability
No, it would boil down to explicit+speed+readability+maintainability vs
implicit+error prone.
It would mean that as well as the interpreter having to search the
instance to work out
Sorin Schwimmer [EMAIL PROTECTED] wrote:
For instance, lenghty_function() executes, when an
external event triggers cancel(), which is supposed to
abruptly stop lengthy_function(), reset some variables
and exit immediately.
def lenghty_function(some, arguments, abort=lambda: False):
braver [EMAIL PROTECTED] wrote:
In many cases, you want to do this:
for line in f:
do something with the line, setup counts and things
if line % 1000 == 0 or f.eof(): # eof() doesn't exist in Python
yet!
use the setup variables and things to process the chunk
My control
Boris Borcic [EMAIL PROTECTED] wrote:
Duncan Booth wrote:
import itertools
def chunks(f, size):
iterator = iter(f)
def onechunk(line):
yield line
for line in itertools.islice(iterator, size-1):
yield line
for line in iterator:
yield
Borse, Ganesh [EMAIL PROTECTED] wrote:
2) my this code got compiled but when running, I got an error from
Py_CompileString, as below. Why is it so?
File string, line 1
if ( (size 1000) (vol (0.001 * ADV)) (prod==Stock)):
print OK ^
SyntaxError: invalid syntax
But when I
Frank Stutzman [EMAIL PROTECTED] wrote:
I did some poking and proding and it seems that there is something in
the
head clause that is causing the problem. Heck if I can see what it
is.
Maybe Beautifulsoup believes the incorrect encoding in the meta tags?
--
Bjoern Schliessmann [EMAIL PROTECTED] wrote:
Benjamin wrote:
Python is has duck typing. If it quacks like a duke, it's duck.
How do dukes quack, exactly? :)
Regards,
They quack with a North-eastern Scottish accent of course.
The following excerpt from Scots: Practical Approaches
Donn Ingle [EMAIL PROTECTED] wrote:
Hi,
I have seen strange looking things in various Python code like:
staticmethod and also lines starting with an @ sign, just before
method defs - I can't find an example right now.
I have Python 2.5 installed with it's docs, but I can't find any
Janne Härkönen [EMAIL PROTECTED] wrote:
$ python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type help, copyright, credits or license for more information.
class X:
... def x(self):
...pass
...
class Y(X):
...
New submission from Duncan Booth:
The following code throws a SystemError exception. cell_get_contents in
Objects\cellobject.c should check for a null op-ob_ref value and throw
an appropriate exception.
def oops():
def f(): cell
f.func_closure[0].cell_contents
cell
posted for you yesterday. See message
http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/83c10e0c67e566d8/a605259c41c78fa0?lnk=gstq=duncan+booth#a605259c41c78fa0
--
http://mail.python.org/mailman/listinfo/python-list
Davy [EMAIL PROTECTED] wrote:
For example, I have dic that includes n=4 elements, I want m=2 keys
have the largest values)
dic = {0:4,3:1,5:2,7:8}
So, the the largest values are [8,4], so the keys are [7,0].
Is there any fast way to implement this algorithm?
Any suggestions are welcome!
Jeff [EMAIL PROTECTED] wrote:
Why are you doing that with key-value pairs? Why not with the array
module or lists?
The original poster asked about a problem with key-value pairs. I just
answered his question.
--
http://mail.python.org/mailman/listinfo/python-list
Donn Ingle [EMAIL PROTECTED] wrote:
class Stack:
list = []
Okay, this has me a little weirded-out. How is this different from
putting it in:
def __init__(self):
self.list = []
?
I see from tests that it is different, but I don't quite grok it. Who
owns the list ref?
The
Prepscius, Colin \(IT\) [EMAIL PROTECTED] wrote:
The last argument to new.function takes a closure, which is a tuple of
cell objects. Does anybody know how to create those cell objects 'by
hand'?
def newcell():
def f(): cell
return f.func_closure[0]
cell = None
Scott David Daniels [EMAIL PROTECTED] wrote:
To quote a poster at
http://www.thescripts.com/forum/thread22741.html,
While we are at it, I also don't understand why sequences can't be
used as indices. Why not, say, l[[2,3]] or l[(2, 3)]? Why a special
slice concept? Isn't that unpythonic?
Steven D'Aprano [EMAIL PROTECTED] wrote:
Besides, if you want this behaviour, you can add it yourself:
class mylist(list):
# Untested!
def __getitem__(self, index):
if type(index) is list:
return [self[i] for i in index]
return super(mylist,
Frank Samuelson [EMAIL PROTECTED] wrote:
It's also not clear how you expect this to work with anything more
complex than a single expression. How do you handle statements and
multiple returns?
def foo(x, y):
L = []
try:
if x[y] % 2:
print x, y
Wildemar Wildenburger [EMAIL PROTECTED] wrote:
maybe something like this could help:
def tupleize(non_tuple):
try:
return tuple(tupleize(thing) for thing in non_tuple)
except TypeError:
# non_tuple is not iterable
return non_tuple
Just don't try
Paul McGuire [EMAIL PROTECTED] wrote:
On Nov 6, 4:08 am, Dustan [EMAIL PROTECTED] wrote:
On Nov 6, 3:58 am, Duncan Booth [EMAIL PROTECTED] wrote:
Wildemar Wildenburger [EMAIL PROTECTED] wrote:
maybe something like this could help:
def tupleize(non_tuple):
try
Steven D'Aprano [EMAIL PROTECTED] wrote:
Not quite, because that will also convert strings to tuples, which may
not be what you want for a general solution.
I take it you didn't actually try the original code then. Converting
strings to tuples is not something it did.
That works for all
metaperl.com [EMAIL PROTECTED] wrote:
Per http://docs.python.org/lib/defaultdict-examples.html
It seems that there is a default factory which initializes each key to
1. So by the end of train(), each member of the dictionary model will
have value = 1
But why wouldnt he set the value to
Steven D'Aprano [EMAIL PROTECTED] wrote:
As far as I know, all it would take to allow modules to be callable
would be a single change to the module type, the equivalent of:
def __call__(self, *args, **kwargs):
try:
# Special methods are retrieved from the class, not
#
Steven D'Aprano [EMAIL PROTECTED] wrote:
Then if foo is a class, we probably all agree that bar is a method of
foo.
There are funny edge cases (e.g. bar might be an attribute with a
__call__ method) but in general, yes, bar would be a method of foo.
But that 'funny edge case' is exactly
Paul Rubin http://[EMAIL PROTECTED] wrote:
Duncan Booth [EMAIL PROTECTED] writes:
modules are not special in any way, except that you cannot subclass
them. Oops, sorry I got that wrong. Modules are not special in any
way, they can have methods as well as functions:
I've felt for a long
Jean-Paul Calderone [EMAIL PROTECTED] wrote:
The T1000 isn't a very good machine for general server purposes. It
has advantages when running software with a lot of hardware-level
parallelism, but Zope isn't such a piece of software.
Zope can scale well on multi-processor machines, but you
Bjoern Schliessmann [EMAIL PROTECTED]
wrote:
Jim Hendricks wrote:
I see the global keyword that allows access to global vars in a
function, what I'm not clear on is does that global need to be
declared in the global scope,
You can't just declare in Python, you always define objects (and
Hrvoje Niksic [EMAIL PROTECTED] wrote:
In real-life code, closures are used to implement callbacks with
automatic access to their lexical environment without the need for the
bogus additional void * argument one so often sees in C callbacks,
and without communication through global variables.
gooli [EMAIL PROTECTED] wrote:
Hi,
I'm using urllib to get html pages from the web but my computer is
behind a proxy.
The proxy is automatically configured in Internet Explorer via a
proxy.pac file (http://en.wikipedia.org/wiki/Proxy_auto-config).
From what I can see in the urllib
Dustan [EMAIL PROTECTED] wrote:
On Oct 30, 11:29 am, Duncan Booth [EMAIL PROTECTED]
wrote:
Neil Cerutti [EMAIL PROTECTED] wrote:
It's allows a standard programming idiom which provides a
primitive form of object oriented programming using closures to
represent state.
def account
Neil Cerutti [EMAIL PROTECTED] wrote:
But if I'm wrong about the performance benefits then I guess I'm
still in the dark about why len is a builtin. The only compelling
thing in the linked explation was the signatures of the guys who
wrote the artible. (Guido does admit he would, hate to lose
Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-10-31, Duncan Booth [EMAIL PROTECTED] wrote:
Obviously it isn't an absolute thing: lists and dictionaries do
have other methods in the user namespace, so the decision to
keep len out of that namespace is partly a judgement call, and
partly
Neil Cerutti [EMAIL PROTECTED] wrote:
It's allows a standard programming idiom which provides a
primitive form of object oriented programming using closures to
represent state.
def account(opening_balance):
balance = opening_balance
def get_balance():
nonlocal balance
return
J. Clifford Dyer [EMAIL PROTECTED] wrote:
How do you interpret:
help(__import__)
Help on built-in function __import__ in module __builtin__:
__import__(...)
__import__(name, globals={}, locals={}, fromlist=[], level=-1) -
module
...
help(int)
Help on class int in module
TYR [EMAIL PROTECTED] wrote:
To do anything with it, you then need to create a cursor object by
calling foo's method cursor (bar = foo.cursor).
Perhaps this would work better if you actually try calling foo's method?
bar = foo.cursor()
Without the parentheses all you are doing is
Armando Serrano Lombillo [EMAIL PROTECTED] wrote:
Why does Python give an error when I try to do this:
len(object=[1,2])
Traceback (most recent call last):
File pyshell#40, line 1, in module
len(object=[1,2])
TypeError: len() takes no keyword arguments
but not when I use a normal
Bruno Desthuilliers [EMAIL PROTECTED]
wrote:
In the second case, the name of the argument *is* 'object'. Which is not
the case for the builtin len (which, fwiw, has type
'builtin_function_or_method', not 'function', so inspect.getargspec
couldn't tell me more).
ot
While we're at it,
J. Clifford Dyer [EMAIL PROTECTED] wrote:
I think you are being a little bit unfair here: help(len) says:
len(...)
len(object) - integer
Return the number of items of a sequence or mapping.
which implies that the argument to len has the name 'object'
(although in fact it
stef mientki [EMAIL PROTECTED] wrote:
hello,
The next piece of code bothers me:
ptx, pty, rectWidth, rectHeight = self._point2ClientCoord (p1, p2 )
dc.SetClippingRegion ( ptx, pty, rectWidth, rectHeight )
Because I want to write it in 1 line,
and without the use of
Anand [EMAIL PROTECTED] wrote:
On Oct 26, 5:31 pm, Pradeep Jindal [EMAIL PROTECTED] wrote:
Can you tell any specific use case for doing this?
I have many implementaions of a db interface.
SimpleDB - simple implementation
BetterDB - optimized implementation
CachedDB - an implementation
[EMAIL PROTECTED] wrote:
[cut]
Without a better example or explanation of what you are trying to do
it is difficult
You're right.
Actually i'm parsing an xml file using pyrxp, which returns something
like this:
(tagName, attributes, list_of_children, spare)
Where list_of_children
beginner [EMAIL PROTECTED] wrote:
It is really convenient to use nested functions and lambda
expressions. What I'd like to know is if Python compiles fn_inner()
only once and change the binding of v every time fn_outer() is called
or if Python compile and generate a new function object every
Alexandre Badez [EMAIL PROTECTED] wrote:
Thanks for your try Cliff, I was very confused :P
More over I made some mistake when I post (to make it easiest).
Here is my real code:
with
dArguments = {
'argName' : {
'mandatory' : bool, # True or False
[...], # other field we do
701 - 800 of 1755 matches
Mail list logo