Re: copy on write

2012-02-02 Thread Hrvoje Niksic
Steven D'Aprano writes: > Perhaps you are thinking that Python could determine ahead of time > whether x[1] += y involved a list or a tuple, and not perform the > finally assignment if x was a tuple. Well, maybe, but such an approach > (if possible!) is fraught with danger and mysterious errors e

Re: round down to nearest number

2012-02-11 Thread Hrvoje Niksic
Terry Reedy writes: > On 2/9/2012 8:23 PM, noydb wrote: >> So how would you round UP always? Say the number is 3219, so you want (//100+1)*100 > 3400 Note that that doesn't work for numbers that are already round: >>> (3300//100+1)*100 3400# 3300 would be correct I'd go with Chri

Re: Porting the 2-3 heap data-structure library from C to Python

2012-03-07 Thread Hrvoje Niksic
Alec Taylor writes: > The source-code used has been made available: > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c > > I plan on wrapping it in a class. You should get acquainted with the Python/C API, which is the standard

Re: Porting the 2-3 heap data-structure library from C to Python

2012-03-10 Thread Hrvoje Niksic
Stefan Behnel writes: >> which is the standard way of extending Python with high-performance >> (and/or system-specific) C code. > > Well, it's *one* way. Certainly not the easiest way, neither the most > portable and you'll have a hard time making it the fastest. I didn't say it was easy, but

Re: Python and Lisp : car and cdr

2011-06-19 Thread Hrvoje Niksic
Ethan Furman writes: >> def car(L): >> return L[0] >> def cdr(L): >> return L[1] > > IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ? Not for the linked list implementation he presented. >> def length(L): >> if not L: return 0 >> return 1 + length(cdr(L)) > > Ho

Re: How does CO_FUTURE_DIVISION compiler flag get propagated?

2011-07-02 Thread Hrvoje Niksic
Terry writes: > Future division ("from __future__ import division") works within > scripts executed by import or execfile(). However, it does not work > when entered interactively in the interpreter like this: > from __future__ import division a=2/3 Are you referring to the interactive

Re: Possible File iteration bug

2011-07-14 Thread Hrvoje Niksic
Billy Mays writes: > Is there any way to just create a new generator that clears its > closed` status? You can define getLines in terms of the readline file method, which does return new data when it is available. def getLines(f): lines = [] while True: line = f.readline()

Re: Convert '165.0' to int

2011-07-22 Thread Hrvoje Niksic
Frank Millman writes: > int(float(x)) does the job, and I am happy with that. I was just > asking if there were any alternatives. int(float(s)) will corrupt integers larger than 2**53, should you ever need them. int(decimal.Decimal(s)) works with numbers of arbitrary size. -- http://mail.pytho

Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Hrvoje Niksic
Neil Cerutti writes: > On 2011-07-29, Dennis Lee Bieber wrote: >> Fine... So normpath it first... >> > os.path.normpath(r'C:/windows').split(os.sep) >> ['C:', 'windows'] That apparently doesn't distinguish between r'C:\windows' and r'C:windows'. On Windows the first is an absolute pat

Re: Use-cases for alternative iterator

2011-03-10 Thread Hrvoje Niksic
Steven D'Aprano writes: > I've never seen this second form in actual code. Does anyone use it, > and if so, what use-cases do you have? Since APIs that signal end-of-iteration by returning a sentinel have fallen out of favor in Python (with good reason), this form is rare, but still it's sometim

Re: generator / iterator mystery

2011-03-13 Thread Hrvoje Niksic
Dave Abrahams writes: list(chain( *(((x,n) for n in range(3)) for x in 'abc') )) > [('c', 0), ('c', 1), ('c', 2), ('c', 0), ('c', 1), ('c', 2), ('c', 0), ('c', > 1), ('c', 2)] > > Huh? Can anyone explain why the last result is different? list(chain(*EXPR)) is constructing a tuple out of

Re: What other languages use the same data model as Python?

2011-05-03 Thread Hrvoje Niksic
Steven D'Aprano writes: > "Python's data model is different from other languages" > > which is perfectly correct, if you think of C as "other languages". But > it's equally correct to say that Python's data model is the same as other > languages. As I understand it, Python and Ruby have the sam

Re: __dict__ attribute for built-in types

2011-10-27 Thread Hrvoje Niksic
candide writes: > But beside this, how to recognise classes whose object doesn't have a > __dict__ attribute ? str, list and others aren't classes, they are types. While all (new-style) classes are types, not all types are classes. It's instances of classes (types created by executing the "cla

Re: __dict__ attribute for built-in types

2011-10-28 Thread Hrvoje Niksic
candide writes: > Le 28/10/2011 00:57, Hrvoje Niksic a écrit : > >> was used at class definition time to suppress it. Built-in and >> extension types can choose whether to implement __dict__. >> > > Is it possible in the CPython implementation to write something

Re: Dictionary sorting

2011-11-04 Thread Hrvoje Niksic
Ben Finney writes: > Tim Chase writes: > >> On 11/03/11 16:36, Terry Reedy wrote: >> > CPython iterates (and prints) dict items in their arbitrary internal >> > hash table order, which depends on the number and entry order of the >> > items. It is a bug to depend on that arbitrary order in any w

Re: Server Questions (2 of them)

2011-11-20 Thread Hrvoje Niksic
Andrew writes: > How to do you create a server that accepts a set of user code? [...] Look up the "exec" statement, the server can use it to execute any code received from the client as a string. Note "any code", though; exec runs in no sandbox and if a malicious client defines addition(1, 2) t

Re: unpack('>f', b'\x00\x01\x00\x00')

2011-12-01 Thread Hrvoje Niksic
Chris Rebert writes: > C does not have a built-in fixed-point datatype, so the `struct` > module doesn't handle fixed-point numbers directly. The built-in decimal module supports fixed-point arithmetic, but the struct module doesn't know about it. A bug report (or patch) by someone who works wi

Re: order independent hash?

2011-12-02 Thread Hrvoje Niksic
Chris Angelico writes: >> The hash can grow with (k,v) pairs accumulated in the run time. >> An auto memory management mechanism is required for a hash of a non-fixed >> size of (k,v) pairs. > > That's a hash table In many contexts "hash table" is shortened to "hash" when there is no ambiguity.

Re: order independent hash?

2011-12-04 Thread Hrvoje Niksic
Terry Reedy writes: >> [Hashing is] pretty much mandated because of the __hash__ protocol. > > Lib Ref 4.8. Mapping Types — dict > "A mapping object maps hashable values to arbitrary objects." > > This does not say that the mapping has to *use* the hash value ;-). > Even if it does, it could use

Re: order independent hash?

2011-12-07 Thread Hrvoje Niksic
Chris Angelico writes: > 2011/12/5 Hrvoje Niksic : >> If a Python implementation tried to implement dict as a tree, >> instances of classes that define only __eq__ and __hash__ would not >> be correctly inserted in such a dict. > > Couldn't you just make a t

Re: order independent hash?

2011-12-08 Thread Hrvoje Niksic
Tim Chase writes: > From an interface perspective, I suppose it would work. However one > of the main computer-science reasons for addressing by a hash is to > get O(1) access to items (modulo pessimal hash structures/algorithms > which can approach O(N) if everything hashes to the same > value/

Re: order independent hash?

2011-12-09 Thread Hrvoje Niksic
Steven D'Aprano writes: > Except for people who needed dicts with tens of millions of items. Huge tree-based dicts would be somewhat slower than today's hash-based dicts, but they would be far from unusable. Trees are often used to organize large datasets for quick access. The case of dicts wh

Re: unzip function?

2012-01-18 Thread Hrvoje Niksic
Neal Becker writes: > python has builtin zip, but not unzip > > A bit of googling found my answer for my decorate/sort/undecorate problem: > > a, b = zip (*sorted ((c,d) for c,d in zip (x,y))) > > That zip (*sorted... > > does the unzipping. > > But it's less than intuitively obvious. > > I'm thi

Re: while True or while 1

2012-01-23 Thread Hrvoje Niksic
Dave Angel writes: > I do something similar when there's a portion of code that should > never be reached: > > assert("reason why I cannot get here") Shouldn't that be assert False, "reason why I cannot get here"? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-29 Thread Hrvoje Niksic
Douglas Alan <[EMAIL PROTECTED]> writes: > I think you overstate your case. Lispers understand iteration > interfaces perfectly well, but tend to prefer mapping fuctions to > iteration because mapping functions are both easier to code (they > are basically equivalent to coding generators) and eff

Re: Looking for an interpreter that does not request internet access

2007-06-29 Thread Hrvoje Niksic
James Alan Farrell <[EMAIL PROTECTED]> writes: > Hello, > I recently installed new anti-virus software and was surprised the > next time I brought up IDLE, that it was accessing the internet. > > I dislike software accessing the internet without telling me about it, > especially because of my slow

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-29 Thread Hrvoje Niksic
Douglas Alan <[EMAIL PROTECTED]> writes: >>> The downside is that they are not quite as flexible as iterators >>> (which can be hard to code) and generators, which are slow. > >> Why do you think generators are any slower than hand-coded iterators? > > Generators aren't slower than hand-coded ite

Re: Memory leak issue with complex data structure

2007-07-05 Thread Hrvoje Niksic
Alan Franzoni <[EMAIL PROTECTED]> writes: > I have a serious "leak" issue; even though I clear all those sets > and I delete all the references I can have to the current namespace, > memory is not freed. Maybe the memory is freed (marked as available for further use by Python), just not released

Re: What is the most efficient way to test for False in a list?

2007-07-09 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: but what is your best way to test for for False in a list? [...] >>> status = all(list) >> Am I mistaken, or is this no identity test for False at all? > > You are mistaken. > all take an iterable and returns if each value of it is true. Testing

Re: Per thread data

2007-07-09 Thread Hrvoje Niksic
Will McGugan <[EMAIL PROTECTED]> writes: > Is there a canonical way of storing per-thread data in Python? mydata = threading.local() mydata.x = 1 ... http://docs.python.org/lib/module-threading.html -- http://mail.python.org/mailman/listinfo/python-list

Re: What is the most efficient way to test for False in a list?

2007-07-09 Thread Hrvoje Niksic
Paul McGuire <[EMAIL PROTECTED]> writes: >> >>> False in [3, 2, 1, 0, -1] >> >> True# no False here>>> all([3, 2, 1, 0, -1]) >> >> False # false value present, not necessarily False > > I think if you want identity testing, you'll need to code your own; I'm aware of that, I simply pointed o

Re: os.wait() losing child?

2007-07-12 Thread Hrvoje Niksic
Nick Craig-Wood <[EMAIL PROTECTED]> writes: >> I think your polling way works; it seems there no other way around this >> problem other than polling or extending Popen class. > > I think polling is probably the right way of doing it... It requires the program to wake up every 0.1s to poll for

Re: os.wait() losing child?

2007-07-12 Thread Hrvoje Niksic
Jason Zheng <[EMAIL PROTECTED]> writes: > greg wrote: >> Jason Zheng wrote: >>> Hate to reply to my own thread, but this is the working program >>> that can demonstrate what I posted earlier: >> I've figured out what's going on. The Popen class has a >> __del__ method which does a non-blocking wai

Re: os.wait() losing child?

2007-07-12 Thread Hrvoje Niksic
Nick Craig-Wood <[EMAIL PROTECTED]> writes: >> This can still be a problem for applications that call wait in a >> dedicated thread, but the program can always ignore the processes >> it doesn't know anything about. > > Ignoring them isn't good enough because it means that the bit of > code whi

Re: os.wait() losing child?

2007-07-13 Thread Hrvoje Niksic
Jason Zheng <[EMAIL PROTECTED]> writes: > Hrvoje Niksic wrote: >>> greg wrote: >> Actually, it's not that bad. _cleanup only polls the instances that >> are no longer referenced by user code, but still running. If you hang >> on to Popen instances, the

Re: How to create new files?

2007-07-13 Thread Hrvoje Niksic
Robert Dailey <[EMAIL PROTECTED]> writes: > class filestream: > def __init__( self, filename ): > self.m_file = open( filename, "rwb" ) [...] > So far, I've found that unlike with the C++ version of fopen(), the > Python 'open()' call does not create the file for you when opene

Re: Question about PyDict_SetItemString

2007-07-13 Thread Hrvoje Niksic
lgx <[EMAIL PROTECTED]> writes: >From Google results, I find some source code write like that. But >some code write like below: > > obj = PyString_FromString("value"); > PyDict_SetItemString(pDict,"key",obj); > Py_DECREF(obj); > > So, which one is correct? The latter is correct. While PyDict_Ge

Re: os.wait() losing child?

2007-07-13 Thread Hrvoje Niksic
Jason Zheng <[EMAIL PROTECTED]> writes: >>> Nope it still doesn't work. I'm running python 2.4.4, tho. >> That explains it, then, and also why greg's code didn't work. You >> still have the option to try to run 2.5's subprocess.py under 2.4. > Is it more convenient to just inherit the Popen class

Re: Implementaion of random.shuffle

2007-07-16 Thread Hrvoje Niksic
Steve Holden <[EMAIL PROTECTED]> writes: > So it would appear that the developers chose the Knuth algorithm > (with a slight variation) for *their* implementation. Now you have > to ask yourself whether your surmise is genuinely correct (in which > case the documentation may contain a bug) or whet

Re: Accessing Python variables in an extension module

2007-07-16 Thread Hrvoje Niksic
MD <[EMAIL PROTECTED]> writes: > 2) Is there anyway to find the type of the object in C using something > like a switch statement? I was looking for something like this >switch type(object) { > STRING: "This is a string object"; > break; > INTEGER: "This is an integer

Re: Implementaion of random.shuffle

2007-07-17 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > In the case of CPython, the current implementation uses the Mersenne > Twister, which has a huge period of 2**19937. However, 2081! is > larger than that number, which means that at best a list of 2081 > items or longer can't be perfectly shuffled (not

Re: Semantics of file.close()

2007-07-17 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes: > You should take a look at the man pages for close(2) and write(2) (not > fclose). Generally you will only get an error in C if you try to close > a file that isn't open. In Python you don't even have to worry about > that -- if you close a regular file

Re: Semantics of file.close()

2007-07-18 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes: >> But the writes are buffered, and close causes the buffer to be >> flushed. file.close can throw an exception just like fclose, but >> it will still ensure that the file is closed. > > Is this buffering being done by Python or the kernel? It is done i

Re: Interpreting os.lstat()

2007-07-19 Thread Hrvoje Niksic
Adrian Petrescu <[EMAIL PROTECTED]> writes: > I checked the online Python documentation at > http://python.org/doc/1.5.2/lib/module-stat.html > but it just says to "consult the documentation for your system.". The page you're looking for is at http://www.python.org/doc/current/lib/os-file-dir.ht

Re: class C: vs class C(object):

2007-07-20 Thread Hrvoje Niksic
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > In particular, old-style classes are noticeably faster than > new-style classes for some things (I think it was attribute lookup > that surprised me recently, possibly related to the property > stuff...) Can you post an example that we can benchma

Re: subprocess (spawned by os.system) inherits open TCP/UDP/IP port

2007-07-20 Thread Hrvoje Niksic
alf <[EMAIL PROTECTED]> writes: > still would like to find out why it is happening (now FD_CLOEXEC > narrowed may yahooing/googling searches). While realize that file > descriptors are shared by forked processes it is still weird why the > port moves to the child process once parent gets killed. w

Multiple regex match idiom

2007-05-09 Thread Hrvoje Niksic
I often have the need to match multiple regexes against a single string, typically a line of input, like this: if (matchobj = re1.match(line)): ... re1 matched; do something with matchobj ... elif (matchobj = re2.match(line)): ... re2 matched; do something with matchobj ... elif (matchobj = re

Re: Reading a file and resuming reading.

2007-05-25 Thread Hrvoje Niksic
"Karim Ali" <[EMAIL PROTECTED]> writes: > - > while not eof <- really want the EOF and not just an empty line! > readline by line > end while; > - for line in open_file: ... It will stop on EOF, not on empty line. > But also, in cas

Re: Puzzled by "is"

2007-08-09 Thread Hrvoje Niksic
Grzegorz Słodkowicz <[EMAIL PROTECTED]> writes: >> Seriously, it's just an optimization by the implementers. There is >> no need for more than one empty tuple, since tuples can never be >> modified once created. >> >> But they decided not to create (1, ) in advance. They probably knew >> that hard

Re: Fatest standard way to sum bytes (and their squares)?

2007-08-12 Thread Hrvoje Niksic
Erik Max Francis <[EMAIL PROTECTED]> writes: > So far the fastest way I've found is using the `sum` builtin and > generators:: > > ordinalSum = sum(ord(x) for x in data) > ordinalSumSquared = sum(ord(x)**2 for x in data) For ordinalSum, using imap is almost twice as fast: $ python -m

Re: Fatest standard way to sum bytes (and their squares)?

2007-08-13 Thread Hrvoje Niksic
Erik Max Francis <[EMAIL PROTECTED]> writes: > Hrvoje Niksic wrote: > >> For ordinalSum, using imap is almost twice as fast: >> $ python -m timeit -s 'data=[chr(x) for x in xrange(256)]' >> 'sum(ord(x) for x in data)' >> 1 loops, best

Re: File Read Cache - How to purge?

2007-08-21 Thread Hrvoje Niksic
Signal <[EMAIL PROTECTED]> writes: > 2. Is there anyway to somehow to take advantage of this "caching" by > initializing it without reading through the entire file first? > > 3. If the answer to #2 is No, then is there a way to purge this > "cache" in order to get a more accurate result in my rout

Re: python 2.5.1 segfault, multithreading & dual core issue?

2007-08-21 Thread Hrvoje Niksic
Paul Sijben <[EMAIL PROTECTED]> writes: > I am running a multi-threaded python application in a dual core > intel running Ubuntu. [...] Judging from the stack trace, this patch has a good chance of fixing your problem: http://mail.python.org/pipermail/python-dev/2007-August/074232.html -- h

Re: How to optimise this code?

2007-08-21 Thread Hrvoje Niksic
Christof Winter <[EMAIL PROTECTED]> writes: > To get rid of the if statements, replace __init__ function with: > > def __init__(self, tc): > functionToCall = eval("self.testCase%s" % tc) Or functionToCall = getattr(self, "testCase" + tc) eval can introduce unwanted side effects. --

Re: File Read Cache - How to purge?

2007-08-21 Thread Hrvoje Niksic
Nick Craig-Wood <[EMAIL PROTECTED]> writes: > If you are running linux > 2.6.18 then you can use > /proc/sys/vm/drop_caches for exactly that purpose. > > http://www.linuxinsight.com/proc_sys_vm_drop_caches.html That URL claims that you need to run "sync" before dropping the cache, and so do oth

Re: File Read Cache - How to purge?

2007-08-22 Thread Hrvoje Niksic
Steve Holden <[EMAIL PROTECTED]> writes: >> That URL claims that you need to run "sync" before dropping the >> cache, and so do other resources. I wonder if that means that >> dropping the cache is unsafe on a running system. > > Good grief. Just let the operating system do its job, for Pete's >

Re: File Read Cache - How to purge?

2007-08-22 Thread Hrvoje Niksic
Nick Craig-Wood <[EMAIL PROTECTED]> writes: >> > http://www.linuxinsight.com/proc_sys_vm_drop_caches.html >> >> That URL claims that you need to run "sync" before dropping the cache, >> and so do other resources. I wonder if that means that dropping the >> cache is unsafe on a running syste

Re: Does shuffle() produce uniform result ?

2007-08-24 Thread Hrvoje Niksic
tooru honda <[EMAIL PROTECTED]> writes: > I have read the source code of the built-in random module, > random.py. After also reading Wiki article on Knuth Shuffle > algorithm, I wonder if the shuffle method implemented in random.py > produces results with modulo bias. It doesn't have modulo bias

Re: Registering a python function in C

2007-08-31 Thread Hrvoje Niksic
fernando <[EMAIL PROTECTED]> writes: > Could someone post an example on how to register a python function as > a callback in a C function? If I understand correctly, your C function receives a Python function (as a function object of type PyObject *), which you need to call from C. To do that, c

Re: fcntl problems

2007-08-31 Thread Hrvoje Niksic
"mhearne808[insert-at-sign-here]gmail[insert-dot-here]com" <[EMAIL PROTECTED]> writes: > I think I'm still confused. What Miles tried to tell you is that you should call fcnt.flock from both PA and PB. In the example you posted, you failed to call it from PB. No lock call, so no locking happen

Re: Printing lists in columns

2007-09-04 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: >> for row in izip_longest(*d, fillvalue='*'): >> print ', '.join(row) >> >> HTH > > I thought that but when I tried it I recieved a > "Syntax Error: Invalid Syntax" > with a ^ pointing to fillvalue :S Python isn't too happy about adding individual keyword arguments

Re: creating really big lists

2007-09-05 Thread Hrvoje Niksic
Dr Mephesto <[EMAIL PROTECTED]> writes: > I would like to create a pretty big list of lists; a list 3,000,000 > long, each entry containing 5 empty lists. My application will > append data each of the 5 sublists, so they will be of varying > lengths (so no arrays!). > > Does anyone know the most e

Re: creating really big lists

2007-09-06 Thread Hrvoje Niksic
Dr Mephesto <[EMAIL PROTECTED]> writes: > I need some real speed! Is the speed with the GC turned off sufficient for your usage? -- http://mail.python.org/mailman/listinfo/python-list

Re: Autogenerate functions (array of lambdas)

2007-09-06 Thread Hrvoje Niksic
Chris Johnson <[EMAIL PROTECTED]> writes: > What I want to do is build an array of lambda functions, like so: > > a = [lambda: i for i in range(10)] Use a factory function for creating the lambdas. The explicit function call will force a new variable binding to be created each time, and the lamb

Re: Generating a unique identifier

2007-09-08 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Should garbage-collecting 16 million strings really take 20+ > minutes? It shouldn't. For testing purposes I've created a set of 16 milion strings like this: s = set() for n in xrange(1600): s.add('somerandomprefix' + str(n)) # prefix makes t

Re: MemoryError on reading mbox file

2007-09-12 Thread Hrvoje Niksic
Christoph Krammer <[EMAIL PROTECTED]> writes: > I have to convert a huge mbox file (~1.5G) to MySQL. Have you tried commenting out the MySQL portion of the code? Does the code then manage to finish processing the mailbox? -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically removing methods in new-style classes

2007-09-12 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > I am trying unsuccessfully to remove some methods from an instance, You can't remove the method from an instance because the method is stored in its class. > With the older python classes I could have done: > self.__class__.__dict__[''test1"] to achieve the desire

Re: class that keeps track of instances

2007-09-17 Thread Hrvoje Niksic
<[EMAIL PROTECTED]> writes: > 1) New instance has to have a property called 'name' > 2) When instance is attemped to created, e.g., x=kls(name='myname'), and > there already exists an instance with obj.name =='myname', that > pre-existing instance is returned, instead of making new one. > 3) A c

Re: super() doesn't get superclass

2007-09-18 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > If a class X is in the MRO of call Y, then X is a superclass of Y. I > agree that the documentation for super is somewhat misleading (and > obviously wrong), but it still *give access to* (at least one of) > the superclass(es). I believe the confu

Re: super() doesn't get superclass

2007-09-19 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: > Hrvoje Niksic <[EMAIL PROTECTED]> writes: > >> class X(Y): >> def foo(self): >> super(X, self).foo() >> >> ...there is in fact no guarantee that super() calls a superclass of >> X. However, it

Re: super() doesn't get superclass

2007-09-19 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: > Evan is claiming that "the next class in the MRO _is_ a superclass", > apparently by his definition or some other that I've not seen. The definition of superclass is not the issue, the issue is "superclass *of which class*"? You expect super(A, self) to i

Re: super() doesn't get superclass

2007-09-19 Thread Hrvoje Niksic
Michele Simionato <[EMAIL PROTECTED]> writes: > On Sep 19, 12:36 pm, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: > >> The next class in the MRO *is* a superclass of the *instance*. Else it >> wouldn't be in the MRO !-) > > Bruno, there is no such a thing as a superclass in a multiple > inherita

Re: super() doesn't get superclass

2007-09-19 Thread Hrvoje Niksic
Michele Simionato <[EMAIL PROTECTED]> writes: > On Sep 19, 1:16 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >> Your arguments against the superclass term seem to assume that there >> is only a single superclass to a particular class. > > If you say "the&q

Re: super() doesn't get superclass

2007-09-20 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: >> The definition of superclass is not the issue, the issue is >> "superclass *of which class*"? You expect super(A, self) to iterate >> only over superclasses of A, even when self is an instance of a >> subtype of A. > > Yes. Those are the specific paramete

Re: __contains__() : Bug or Feature ???

2007-09-21 Thread Hrvoje Niksic
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > I need to overload the operator in and let him return an object > ... It seems it is not a behavior Python expect : Python expects it all right, but it intentionally converts the value to a boolean. The 'in' operator calls PySequence_Contains, wh

Re: __contains__() and overload of in : Bug or Feature ???

2007-09-21 Thread Hrvoje Niksic
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: >> The string "yop" evaluates to the boolean value True, as it is not >> empty. > > Does it means that when overloading an operator, python just > wrap the call to the method and keep control of the returned > values ??? In case of 'in' operator, it

Re: Calling constructor but not initializer

2007-09-21 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I can construct an empty instance in the __new__ constructor, and I > can initialize an non-empty instance in the __init__ initializer, > but I can't think of any good way to stop __init__ from being called > if the instance is empty. In pseudo-code, I

Re: sorting a list numbers stored as strings

2007-09-25 Thread Hrvoje Niksic
"Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> writes: > Yep - appears I must have been misremembering from another language > (dunno which) Tcl -- http://mail.python.org/mailman/listinfo/python-list

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Hrvoje Niksic
Steven Bethard <[EMAIL PROTECTED]> writes: > With this is the implementation, I'm definitely -1. Not because it's a > bad implementation, but because if the iteration is always doing a > sort, then there's no reason for a separate data structure. Agreed. A true sorted dict would keep its keys so

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-26 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes: > I that's the point though: you can't write one implementation that has good > performance for all patterns of use An implementation of sorted dict using a balanced tree as the underlying data structure would give decent performance in all the mentioned

Re: the address of list.append and list.append.__doc__

2007-09-26 Thread Hrvoje Niksic
HYRY <[EMAIL PROTECTED]> writes: > This works, but I think the key of DOC is too long, so I want to use > the id of list.append.__doc__ as the key; or use the id of > list.append: Using the id is not a good idea because id's are not permanent. Using list.append as the hash key will work and will

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-26 Thread Hrvoje Niksic
Mark Summerfield <[EMAIL PROTECTED]> writes: > On 26 Sep, 09:51, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >> Duncan Booth <[EMAIL PROTECTED]> writes: >> > I that's the point though: you can't write one implementation >> > that has good perf

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-26 Thread Hrvoje Niksic
Paul Hankin <[EMAIL PROTECTED]> writes: >> An implementation of sorted dict using a balanced tree as the >> underlying data structure would give decent performance in all the >> mentioned use cases. For example, red-black trees search, insert, >> and delete in O(log n) time. > > But dicts do sear

Re: ~ bit-wise unary operator

2007-09-26 Thread Hrvoje Niksic
Ladislav Andel <[EMAIL PROTECTED]> writes: > Hello, why ~ bit-wise unary operator returns -(x+1) and not bit > inversion of the given integer? On 2s-complement architectures, -(x+1) *is* bit inversion of the given integer. > example: > a = 7978 > a = ~a > python returns -7979 > > but I need to g

Re: PyObject_CallObject: difference between functions and class methods

2007-09-27 Thread Hrvoje Niksic
[ Note that there is now a mailing list dedicated to the C API: http://mail.python.org/mailman/listinfo/capi-sig ] mauro <[EMAIL PROTECTED]> writes: > I am trying to call within a C extension a Python function provided as > an argument by the user with: PyObject_Call(). The C extension should > w

Re: Cross-platform time out decorator

2007-09-27 Thread Hrvoje Niksic
Joel <[EMAIL PROTECTED]> writes: > I found the solution : > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569 > describes a solution based on threads. I tested it and it works > perfectly. Note that, unlike the original alarm code, it doesn't really interrupt the timed-out method, it

Re: Cross-platform time out decorator

2007-09-27 Thread Hrvoje Niksic
Joel <[EMAIL PROTECTED]> writes: >> Note that, unlike the original alarm code, it doesn't really interrupt >> the timed-out method, it just returns the control back to the caller, >> using an exception to mark that a timeout occurred. The "timed out" >> code is still merrily running in the backgr

Re: Cross-platform time out decorator

2007-09-27 Thread Hrvoje Niksic
"Chris Mellon" <[EMAIL PROTECTED]> writes: > You can use ctypes and the Python API to raise a Python exception in > the thread. How, by changing the thread's exception state? -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I overload the compare (cmp()) function for a Lists ([]) index function?

2007-09-28 Thread Hrvoje Niksic
xkenneth <[EMAIL PROTECTED]> writes: > Looking to do something similair. I'm working with alot of timestamps > and if they're within a couple seconds I need them to be indexed and > removed from a list. > Is there any possible way to index with a custom cmp() function? > > I assume it would be som

Re: Limits on search length

2007-10-01 Thread Hrvoje Niksic
Daryl Lee <[EMAIL PROTECTED]> writes: > I am trying to locate all lines in a suite of files with quoted > strings of particular lengths. A search pattern like r'".{15}"' > finds 15-character strings very nicely. But I have some very long > ones, and a pattern like r'".{272}"' fails miserably, ev

Re: Reentrancy of Python interpreter

2007-10-01 Thread Hrvoje Niksic
Brad Johnson <[EMAIL PROTECTED]> writes: > I have a place where I execute a Python command that calls into C++ > code which then in turn calls back into Python using the same > interpreter. I get a fatal error which is "PyThreadStage_Get: no > current thread." Does the C++ code call into the inte

Re: s.split() on multiple separators

2007-10-02 Thread Hrvoje Niksic
Antoon Pardon <[EMAIL PROTECTED]> writes: > It may be convincing if you only consider natural numbers in > ascending order. Suppose you have the sequence a .. b and you want > the reverse. If you work with included bounds the reverse is just b > .. a. If you use the python convention, things beco

Re: enumerate overflow

2007-10-03 Thread Hrvoje Niksic
Raymond Hettinger <[EMAIL PROTECTED]> writes: > [Paul Rubin] >> I hope in 3.0 there's a real fix, i.e. the count should promote to >> long. > > In Py2.6, I will mostly likely put in an automatic promotion to long > for both enumerate() and count(). It took a while to figure-out how > to do this w

Re: migrating to packages

2007-10-03 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > I will expose my case quicly. > The MYCLASES.py file contains the A class, so i can use > from MYCLASES import A > a = () > > Using the "package mode" (wich looks fine BTW), having the simple > MYCLASES/ > __init__.py > A.py > > forces my (i guess) to use the

Re: migrating to packages

2007-10-04 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > it's quite common to use the __init__.py of the package (as > explained by Ben) as a facade to the internal organization of the > package, so you can change this internal organization without > breaking client code. We agree on that. It is the OP

Re: migrating to packages

2007-10-04 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: >> We agree on that. It is the OP who *wants* to access his modules >> directly without ever naming the package. > > To be exact, he wants to reorganize it's source code (splitting a > file that's getting too big AFAICT) You're right, I misread his

Re: migrating to packages

2007-10-05 Thread Hrvoje Niksic
Gerardo Herzig <[EMAIL PROTECTED]> writes: > If the original MYCLASSES.py has 5 different classes ,say A,B,C,D,E > , each one has to be imported (as A and B) in order to be used for > the client code. The thing is, there are more than 5 classes, and > looks like a lot of unnecesary work to me, sin

Re: remove list elements..

2007-10-05 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > I do this use FOR easly but the speed very imported for me. I want > to the fastest method please help me. Can you post the code snippet that was too slow for you? Are the lists sorted? -- http://mail.python.org/mailman/listinfo/python-list

Re: Don't use __slots__

2007-10-08 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Well, I've read the thread, and I've read the thread it links to, > and for the life of me I'm still no clearer as to why __slots__ > shouldn't be used except that: [...] > But is there actually anything *harmful* that can happen if I use > __slots__?

Re: Singleton

2007-10-10 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > Now when I run the 'run.py', it will print two different numbers. > sys.modules tells me that 'mod1' is imported as both 'one.mod1' and > 'mod1', which explains the result. If I were you, I'd make sure that the module duplicate problem is resolved first, for example by

  1   2   3   4   5   >