Re: type, object hierarchy?

2008-02-04 Thread Hrvoje Niksic
7stud <[EMAIL PROTECTED]> writes: > --output:-- > (, , ) > > The output suggests that Dog actually is a subclass of type--despite > the fact that issubclass(Dog, type) returns False. What was it in the output that gave you the impression that Dog is a subclass of type? The last entry is only for

Re: type, object hierarchy?

2008-02-04 Thread Hrvoje Niksic
7stud <[EMAIL PROTECTED]> writes: > On Feb 4, 12:49 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >> 7stud <[EMAIL PROTECTED]> writes: >> > --output:-- >> > (, , ) >> >> > The output suggests that Dog actually is a subclass of type--de

Re: Catching a non-Exception object (KeyboardInterrupt)

2008-02-04 Thread Hrvoje Niksic
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 being derived not from Exception, but fro

Re: Why chdir command doesn't work with client.get_transport() ?

2008-02-06 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > However I do understand where your coming from. You are right, I'm a Lotus > Notes user. If I didn't have to use it I wouldn't. If I had access to the > list from where I currently work any other way I would use that. Have you tried www.gmane.org? -- http://mail.pytho

Re: socket script from perl -> python

2008-02-07 Thread Hrvoje Niksic
kettle <[EMAIL PROTECTED]> writes: > # pack $length as a 32-bit network-independent long > my $len = pack('N', $length); [...] > the sticking point seems to be the $len variable. Use len = struct.pack('!L', length) in Python. See http://docs.python.org/lib/module-struct.html for details. -- htt

Re: Why not a Python compiler?

2008-02-07 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Be fair -- he's asking what specific features of Python make it > hard. That's a reasonable question. Indeed. The best explanation I've seen explained goes something like this: imagine a hypothetical Python compiler that achieves native compilation

Re: Why not a Python compiler?

2008-02-08 Thread Hrvoje Niksic
Ryszard Szopa <[EMAIL PROTECTED]> writes: >> The main determinant of Python's performance isn't the interpreter >> overhead, but the amount of work that must be done at run-time and >> cannot be moved to compile-time or optimized away. > > Well, I am still not convinced that Python is intrinsicall

Re: multi-Singleton-like using __new__

2008-02-09 Thread Hrvoje Niksic
Matt Nordhoff <[EMAIL PROTECTED]> writes: > Steven D'Aprano wrote: >> Except that using has_key() means making an attribute lookup, which takes >> time. > > I was going to say that, but doesn't 'in' require an attribute lookup of > some sort too, of __contains__ or whatever? It doesn't. Frequen

Re: sort functions in python

2008-02-09 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > It depends on what you mean by "bubble sort". There are many different > variations of bubble sort, that are sometimes described by names such as > comb sort, cocktail sort, exchange sort, and sometimes merely referred to > bubble sort. I've never

Re: sort functions in python

2008-02-10 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: >> I've never seen anything better than bubble sort being called >> bubble sort. > > What, you didn't read the post you're replying to? I responded to a specific point about combsort being called bubble sort. I agree that generally the line between "bu

Re: OT: Speed of light

2008-02-13 Thread Hrvoje Niksic
Jeff Schwab <[EMAIL PROTECTED]> writes: > Jeroen Ruigrok van der Werven wrote: >> -On [20080212 22:15], Dotan Cohen ([EMAIL PROTECTED]) wrote: >>> Note that Google will give a calculator result for "1 kilogram in >>> pounds", but not for "1 kilogram in inches". I wonder why not? After >>> all, bot

Re: Assignment saves time?

2008-02-15 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > I tested this using the timeit module, and though the difference was > small, I would have expected the first code block to do slightly > worse, Can you post your entire benchmark, so that we can repeat it? When I tried the obvious, I got the expected result: $ pytho

Re: Garbage collection

2008-02-19 Thread Hrvoje Niksic
Simon Pickles <[EMAIL PROTECTED]> writes: > Ken wrote: >> What is your __del__ method doing? >> > Actually, nothing but printing a message when the object is deleted, > just morbid curiosity. > > I've yet to see one of the destructor messages, tho Do your objects participate in reference c

Re: Globals or objects?

2008-02-21 Thread Hrvoje Niksic
Steve Holden <[EMAIL PROTECTED]> writes: > If a function uses a global variable then you have to initialize the > same global variable in another program that uses it: yet another > piece of setup you will forget to do. If the global variable belongs to the module, then it is up to the module to

Re: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Hrvoje Niksic
"Terry Reedy" <[EMAIL PROTECTED]> writes: > "Jeff Schwab" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > [snip discussion of 'with' statements] > > | Yes, this seems to be the Python way: For each popular feature of some > | other language, create a less flexible Python feature

Re: network programming: how does s.accept() work?

2008-02-26 Thread Hrvoje Niksic
7stud <[EMAIL PROTECTED]> writes: > When you surf the Web, say to http://www.google.com, your Web browser > is a client. The program you contact at Google is a server. When a > server is run, it sets up business at a certain port, say 80 in the > Web case. It then waits for clients to contact it.

Re: How about adding rational fraction to Python?

2008-02-26 Thread Hrvoje Niksic
"D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes: > I have not been following Python development that closely lately so > I was not aware of that. I guess I won't be going to Python 3 then. > It's great that Python wants to attract young, new programmers. Too > bad about us old farts I guess. Befor

%x unsigned?

2008-03-14 Thread Hrvoje Niksic
The %x conversion specifier is documented in http://docs.python.org/lib/typesseq-strings.html as "Unsigned hexadecimal (lowercase)." What does "unsigned" refer to? >>> '0x%x' % 10 '0xa' >>> '0x%x' % -10 '0x-a' Is this a bug or is %x misdocumented? -- http://mail.python.org/mailman/listinfo/pyth

Re: finding items that occur more than once in a list

2008-03-18 Thread Hrvoje Niksic
Ninereeds <[EMAIL PROTECTED]> writes: > The dictionary version Chris suggests (and the essentially > equivalent set-based approach) is doing essentially the same thing > in a way, but using hashing rather than ordering to organise the > list and spot duplicates. This is *not* O(n) due to the rate

Re: finding items that occur more than once in a list

2008-03-18 Thread Hrvoje Niksic
Ninereeds <[EMAIL PROTECTED]> writes: > As for the growth pattern, each time you grow the table you have to > redistribute all the items previously inserted to new locations. > Resizes would get rarer as more items are added due to the > exponential growth, but every table resize would take longer

Re: removing all instances of a certain value from a list

2008-03-19 Thread Hrvoje Niksic
Lee Sander <[EMAIL PROTECTED]> writes: > Hi, > I have a float array ( eg [-1.3, 1.22, 9.2, None, 2.3] ) but there are > many missing vlaues which are represented as None. I would like to > remove all such instances in one go. > There is a remove function but it removes only the first instance, is

Re: Inheritance question

2008-03-25 Thread Hrvoje Niksic
Tzury Bar Yochay <[EMAIL PROTECTED]> writes: > given two classes: > > class Foo(object): > def __init__(self): > self.id = 1 > > def getid(self): > return self.id > > class FooSon(Foo): > def __init__(self): > Foo.__init__(self) > self.id = 2 > > def

Re: Inheritance question

2008-03-25 Thread Hrvoje Niksic
Brian Lane <[EMAIL PROTECTED]> writes: > Basically, you can't do what you are trying to do without using a > different variable, ...or abusing the __foo private identifier trick. -- http://mail.python.org/mailman/listinfo/python-list

Re: Does python hate cathy?

2008-03-25 Thread Hrvoje Niksic
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > On Tue, 25 Mar 2008 14:58:51 +, Edward A. Falk wrote: > >> In article <[EMAIL PROTECTED]>, >> Patrick Mullen <[EMAIL PROTECTED]> wrote: >> >>>Then again, I can count the number of times I have ever needed __del__ >>>with no fingers (never

Re: Circular references not being cleaned up by Py_Finalize()

2008-03-26 Thread Hrvoje Niksic
blackpawn <[EMAIL PROTECTED]> writes: > I know the garbage collector is tracking the object because it > properly calls the traverse function but for whatever reason it > never calls the clear function. Does anyone have experience with > circular references and had success with it or the example

Re: Summary of threading for experienced non-Python programmers?

2008-03-28 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > I'm having trouble explaining the benefits and tradeoffs of threads > to my coworkers and countering their misconceptions about Python's > threading model and facilities. They all come from C++ and are used > to thinking of multithreading as a way to harness multiple C

Re: Implementing file reading in C/Python

2009-01-12 Thread Hrvoje Niksic
sturlamolden writes: > On Jan 9, 6:41 pm, Sion Arrowsmith > wrote: > >> You've snipped the bit further on in that sentence where the OP >> says that the file of interest is 2GB. Do you still want to try >> mmap'ing it? > > Python's mmap object does not take an offset parameter. If it did, one >

Re: Why GIL?

2009-01-23 Thread Hrvoje Niksic
Carl Banks writes: > Unfortunately, references on the stack would need to be registered > as well, so "PyObject* p;" might have to be replaced with something > like "Py_DECLARE_REF(PyObject,p);" which magically registers it. > Ugly. Not only registered at the beginning of the function, but also

Re: Why GIL?

2009-01-24 Thread Hrvoje Niksic
Carl Banks writes: > On Jan 23, 11:45 pm, Bryan Olson wrote: >> Carl Banks wrote: >> > Classes in Python are mutable types, usually.  Class instances are >> > (except for the refcount) immutable objects, usually. >> >> There's where we disagree. I assert that class instances are usually >> mutab

Re: Parsing a string into a datetime object

2009-01-24 Thread Hrvoje Niksic
"Mark.Petrovic" writes: > Might someone comment on why %f is not accepted as a valid field > directive in: > from datetime import datetime created="2009-01-24 16:04:55.882788" dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f") > Traceback (most recent call last): > File "", l

Re: Embarrasing questio

2009-02-12 Thread Hrvoje Niksic
Michele Simionato writes: > On Feb 12, 6:22 pm, MRAB wrote: >> Michele Simionato wrote: >> > On Feb 12, 5:07 pm, TechieInsights wrote: >> >> On Feb 12, 9:03 am, Catherine Heathcote >> >> >> wrote: >> >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >> >>> trying to do som

Re: Easier to wrap C or C++ libraries?

2009-02-14 Thread Hrvoje Niksic
"Diez B. Roggisch" writes: > The answer is easy: if you use C, you can use ctypes to create a > wrapper - with pure python, no compilation, no platform issues. The last part is not true. ctypes doesn't work on 64-bit architectures, nor does it work when Python is built with non-gcc Unix compile

Re: How to peek inside a decorated function

2009-02-15 Thread Hrvoje Niksic
Steven D'Aprano writes: > Suppose I have a function f() which I know has been decorated, but I don't > have access to the original undecorated function any longer: > > def reverse(func): > def f(*args): > args = list(args) > args.reverse() > return func(*args) > re

Re: Easier to wrap C or C++ libraries?

2009-02-16 Thread Hrvoje Niksic
Nick Craig-Wood writes: > Christian Heimes wrote: >> Hrvoje Niksic schrieb: >> > "Diez B. Roggisch" writes: >> > >> >> The answer is easy: if you use C, you can use ctypes to create a >> >> wrapper - with pure python, no compilat

Re: os.popen encoding!

2009-02-18 Thread Hrvoje Niksic
"Gabriel Genellina" writes: >> I'm playing with os.popen function. >> a = os.popen("somecmd").read() >> >> If one of the lines contains characters like "è", "æ"or any other it loks >> line this "velja\xe8a 2009" with that "\xe8". It prints fine if i go: >> >> for i in a: >> print i: > > '\xe8

Re: "metaclass conflict" error: where is noconflict ?

2009-02-22 Thread Hrvoje Niksic
"Barak, Ron" writes: > class CopyAndPaste(): CopyAndPaste is an old-style class. Make it a new-style class, and you'll probably be able to inherit from it and wx.Frame without explicitly creating a new metaclass. -- http://mail.python.org/mailman/listinfo/python-list

Re: "metaclass conflict" error: where is noconflict ?

2009-02-22 Thread Hrvoje Niksic
"Barak, Ron" writes: > import wx > > class CopyAndPaste(object): > def __init__(self): > pass > > def set_copy_and_paste(self): > ... > > and CopyAndPaste is being called with: > > ... > class ListControlMeta(wx.Frame, CopyAndPaste): > pass You don't need ListControlMeta at all; just inher

Re: imported method from module evaluates to None in some cases

2008-11-23 Thread Hrvoje Niksic
Andrew <[EMAIL PROTECTED]> writes: > On Nov 20, 6:53 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >> Andrew <[EMAIL PROTECTED]> writes: >> > I'm having a problem in some zope (2.10) code (HTTPResponse.py) where >> > a method that gets imported som

Re: Python surpasses Perl in popularity?

2008-11-26 Thread Hrvoje Niksic
Xah Lee <[EMAIL PROTECTED]> writes: > Bourne Shell, is pretty much replaced by Bash since several years ago. > For example, as far as i know, linuxes today don't have Bourne Shell > anymore. “sh” is just a alias to bash with some compatibility > parameter. That used to be the case, but these days

Re: best way to do this

2008-12-02 Thread Hrvoje Niksic
TP <[EMAIL PROTECTED]> writes: > Hi everybody, > c=[(5,3), (6,8)] > > From c, I want to obtain a list with 5,3,6, and 8, in any order. > I do this: > [i for (i,j) in c] + [ j for (i,j) in c] > [5, 6, 3, 8] > > Is there a quicker way to do this? Quicker? Hard to say. Using itertools el

Re: How to use a Python function that returns a double array in C++.

2008-12-03 Thread Hrvoje Niksic
pieter <[EMAIL PROTECTED]> writes: > I want to use a Python function that returns a double array in C++. Return an array.array('d') object, and use the buffer protocol (for example PyObject_AsReadBuffer()) to get the address of the underlying array of native doubles. -- http://mail.python.org/mai

Re: schizophrenic view of what is white space

2008-12-04 Thread Hrvoje Niksic
MRAB <[EMAIL PROTECTED]> writes: > I'm not sure why the Unicode flag is needed in the API. I reckon > that it should just look at the text that the regular expression is > being applied to: if it's Unicode then follow the Unicode rules, if > not then don't. It might be that using Unicode tables f

Re: var or inout parm?

2008-12-12 Thread Hrvoje Niksic
sturlamolden writes: > On Dec 12, 1:44 pm, "Chris Rebert" wrote: > >> Python begs to differ, as those two statements are both semantically >> identical in this case: > > That is because integers are immutable. When x += 1 is done on an int, > there will be a rebinding. But try the same on say, a

Re: var or inout parm?

2008-12-12 Thread Hrvoje Niksic
sturlamolden writes: > Actually I would consider this to be a bug. The tuple is immutable, > but no mutation of the tuple is ever attempted. That's a common misconception about how += works in Python. It simply *always* rebinds. Once you grok that, everything else follows. -- http://mail.pytho

Re: var or inout parm?

2008-12-12 Thread Hrvoje Niksic
sturlamolden writes: > On Dec 12, 3:08 pm, Marc 'BlackJack' Rintsch wrote: > >> No bug because a mutation *is* attempted. ``a += x`` calls `a.__iadd__` >> which *always* returns the result which is *always* rebound to the name >> `a`. Even with mutable objects where `__iadd__()` simply returns

Re: var or inout parm?

2008-12-12 Thread Hrvoje Niksic
sturlamolden writes: > What? Take a look at the code again: > > mytuple[0] += 1 > > should never attempt an __iadd__ on mytuple. > > A sane parser would see this as: > > tmp = mytuple.__getitem__(0) > tmp = tmp.__iadd__(1) > mytuple.__setitem__(0, tmp) # should this always raise an exception? Wh

Re: var or inout parm?

2008-12-13 Thread Hrvoje Niksic
Marc 'BlackJack' Rintsch writes: > On Sat, 13 Dec 2008 02:20:59 +0100, Hrvoje Niksic wrote: > >> Saner (in this respect) behavior in the tuple example would require >> a different protocol. I don't understand why Python doesn't just >> call __iadd__

Re: cx_Oracle issues

2008-12-15 Thread Hrvoje Niksic
huw_at1 writes: >> > ORA-06502: PL/SQL: numeric or value error: character string buffer too >> > small ORA-06512: at line 1 >> >> This error is a problem with the PL/SQL, not cx_Oracle.  You need to >> debug obj.function to see what kind of data is being accessed and then >> a data analysis of th

Re: C API and memory allocation

2008-12-21 Thread Hrvoje Niksic
Aaron Brady writes: > I hold this is strong enough to put the burden of proof on the > defenders of having 's'. What is its use case? Passing the string to a C API that can't handle (or don't care about) embedded null chars anyway. Filename API's are a typical example. -- http://mail.python.or

Re: How to represent a sequence of raw bytes

2008-12-21 Thread Hrvoje Niksic
"Steven Woody" writes: > What's the right type to represent a sequence of raw bytes. In C, > we usually do > > 1. char buf[200] or > 2. char buf[] = {0x11, 0x22, 0x33, ... } > > What's the equivalent representation for above in Python? import array buf = array.array('b', [0x11, 0x22, ...])

Re: multiprocessing vs thread performance

2008-12-29 Thread Hrvoje Niksic
Roy Smith writes: > In article , > Christian Heimes wrote: > >> You have missed an important point. A well designed application does >> neither create so many threads nor processes. The creation of a thread >> or forking of a process is an expensive operation. You should use a pool >> of thread

Re: Array of dict or lists or ....?

2008-10-07 Thread Hrvoje Niksic
Tim Chase <[EMAIL PROTECTED]> writes: >>>__repr__ = __str__ >> >> I don't know if that's a good practice. > > I've seen it in a couple places, and it's pretty explicit what it's > doing. But what's the point? Simply define __repr__, and both repr and str will pick it up. -- http://mail.pytho

Re: C API with *args and **kw

2008-10-14 Thread Hrvoje Niksic
[ Note that there's a mailing list dedicated to the C API, http://mail.python.org/mailman/listinfo/capi-sig ] Miki <[EMAIL PROTECTED]> writes: > However when running the test: > from kw import kw > kw(default="2") > kw(1) > kw() > > I get "bus error" on the 2'nd call (OS X Python 2.5.2). When

Re: dumping in destructor

2008-10-20 Thread Hrvoje Niksic
Митя <[EMAIL PROTECTED]> writes: > I have a class which I want to save it's data automatically on disc, > when it's destroyed. I have following code: > > from cPickle import dump > > class __Register(object): > def __init__(self): > self.dict = {} > def __del__(self): > fh

Re: what's the python for this C statement?

2008-10-20 Thread Hrvoje Niksic
Michele <[EMAIL PROTECTED]> writes: > Hi there, > I'm relative new to Python and I discovered that there's one single way > to cycle over an integer variable with for: > for i in range(0,10,1) Please use xrange for this purpose, especially with larger iterations. range actually allocates a seque

Re: what's the python for this C statement?

2008-10-21 Thread Hrvoje Niksic
Lie Ryan <[EMAIL PROTECTED]> writes: > On Mon, 20 Oct 2008 12:34:11 +0200, Hrvoje Niksic wrote: > >> Michele <[EMAIL PROTECTED]> writes: >> >>> Hi there, >>> I'm relative new to Python and I discovered that there's one single way >

Re: How to do_size_allocate properly in a gtk.Viewport subclass

2008-10-22 Thread Hrvoje Niksic
Joel Hedlund <[EMAIL PROTECTED]> writes: > I've raised this issue on #pygtk and #gtk+ but with no luck. Note that there's a mailing list dedicated to PyGTK, <[EMAIL PROTECTED]>, so you might also want to ask your question there. -- http://mail.python.org/mailman/listinfo/python-list

Re: Slow comparison between two lists

2008-10-23 Thread Hrvoje Niksic
Jani Tiainen <[EMAIL PROTECTED]> writes: > for addr in list_external: > if addr not in list_internal: > addr.status = 1 # New address > > But in my case running that loop takes about 10 minutes. What I am > doing wrong? The nested loop takes time proportional to the product of the num

Re: Slow comparison between two lists

2008-10-23 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: >> internal = set(list_internal) > ... > > To do that the original poster may have to define a __hash__ and > __eq__ methods in his/her class. You're right. The OP states he implements __eq__, so he also needs a matching __hash__, such as: def __hash__(self, other)

Re: import foo vs. python -m foo

2008-10-28 Thread Hrvoje Niksic
Simon Bierbaum <[EMAIL PROTECTED]> writes: > Hi all, > > what is the difference between saying "import foo" in an interactive > prompt and starting one using "python -m foo"? The -m switch is not > covered in the man page, is it even officially supported? My copy of the man page states: -m modul

Re: Question concerning array.array and C++

2008-11-05 Thread Hrvoje Niksic
[ Please consider posting to the capi-sig list, which is dedicated to answering questions like yours. http://mail.python.org/mailman/listinfo/capi-sig ] Fabio <[EMAIL PROTECTED]> writes: > Consider the object > > array.array('c',[40,40,40]) > > Can I create such an object from within the C++

Re: C extension - new and init functions

2008-11-17 Thread Hrvoje Niksic
Paul Moore <[EMAIL PROTECTED]> writes: > OK, but that allocates the initial buffer, which I will then throw > away. Why don't you use a constructor argument that allows specifying the initial buffer size? > In practice, this isn't a significant issue (the overhead of one > allocation and one de

Re: sorting list of complex numbers

2008-11-19 Thread Hrvoje Niksic
Terry Reedy <[EMAIL PROTECTED]> writes: > Do your tuple destructuring in the first statement in your body and > nothing will break. Unless you were using a lambda, which is quite useful as argument to "sort". -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting list of complex numbers

2008-11-19 Thread Hrvoje Niksic
Terry Reedy <[EMAIL PROTECTED]> writes: > Hrvoje Niksic wrote: >> Terry Reedy <[EMAIL PROTECTED]> writes: >> >>> Do your tuple destructuring in the first statement in your body and >>> nothing will break. >> >> Unless you were using a lambd

Re: imported method from module evaluates to None in some cases

2008-11-20 Thread Hrvoje Niksic
Andrew <[EMAIL PROTECTED]> writes: > I'm having a problem in some zope (2.10) code (HTTPResponse.py) where > a method that gets imported somehow evaluates to None in certain cases > which causes a TypeError exception to be raised (eg: TypeError: > 'NoneType' object is not callable). The code excer

Re: Problem with writing fast UDP server

2008-11-20 Thread Hrvoje Niksic
Krzysztof Retel <[EMAIL PROTECTED]> writes: > But the server only handles 700 -- 870 packets, when it is non- > blocking, and only 670 – 700 received with blocking sockets. What are your other threads doing? Have you tried the same code without any threading? -- http://mail.python.org/mailman/li

Re: how to get all repeated group with regular expression

2008-11-21 Thread Hrvoje Niksic
scsoce <[EMAIL PROTECTED]> writes: > say, when I try to search and match every char from variable length > string, such as string '123456', i tried re.findall( r'(\d)*, '12346' > ) , but only get '6' and Python doc indeed say: "If a group is > contained in a part of the pattern that matched mult

Re: Metaclass conflict TypeError exception: problem demonstration script

2009-02-24 Thread Hrvoje Niksic
"Barak, Ron" writes: > However, when line 7 is in effect (with line 8 commented out), viz.: > > $ cat -n metaclass_test01.py | head > 1 #!/usr/bin/env python > 2 > 3 import sys > 4 import wx > 5 import CopyAndPaste > 6 > 7 class ListControl(wx.Frame, CopyAndPaste): If this is

Re: Proposed implementation for an Ordered Dictionary

2009-02-26 Thread Hrvoje Niksic
Raymond Hettinger writes: > Here's a proposed implementation for Py2.7 and Py3.1: > > http://code.activestate.com/recipes/576669/ Several methods like __contains__() and __getitem__() are not overridden, so their performance is just as fast as a regular dictionary. Methods l

Re: PIL's thumbnail function returns NoneType

2009-03-01 Thread Hrvoje Niksic
Mirat Can Bayrak writes: > Can you try it? it is about me or it is a bug? Neither. im.thumbnail() modifies the existing image object by converting it to a thumbnail. In Python such methods by convention return None. The documentation explicitly mentions that: Also note that this function

Re: Pickle Problem

2009-03-03 Thread Hrvoje Niksic
Fab86 writes: > when trying to pickle them they are displayed like this: > > I14 > .I15200 > .I86000 > . > > But in console simply printing these attributes I get: > > 14 > 15200 > 86000 > > Can anyone help? Can you describe the problem in some detail? Everything seems to be working fi

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Hrvoje Niksic
psykeedelik writes: > """Keys and values are listed in an arbitrary order which is non- > random, varies across Python implementations, and depends on the > dictionary’s history of insertions and deletions.""" > > I hope it does not mean that the key->value mapping is not > guaranteed, but on

Re: Special keyword argument lambda syntax

2009-03-13 Thread Hrvoje Niksic
MRAB writes: sorted(range(9), def key(n): n % 3) > [0, 3, 6, 1, 4, 7, 2, 5, 8] Given the recent pattern of syntactic constructs for expressions using (ternary if, listcomps, genexps), and avoiding the use of colon in expressions, maybe it should be: sorted(range(9), key=n % 3 def key(n)

Re: An ordering question

2009-03-13 Thread Hrvoje Niksic
Kottiyath writes: > Hi, > I have 2 lists > a = [(4, 1), (7, 3), (3, 2), (2, 4)] > b = [2, 4, 1, 3] > > Now, I want to order _a_ (a[1]) based on _b_. > i.e. the second element in tuple should be the same as b. > i.e. Output would be [(3, 2), (2, 4), (4, 1), (7, 3)] [...] > whe

Re: An ordering question

2009-03-13 Thread Hrvoje Niksic
"andrew cooke" writes: > Hrvoje Niksic wrote: >> Kottiyath writes: >> >>> Hi, >>> I have 2 lists >>> a = [(4, 1), (7, 3), (3, 2), (2, 4)] >>> b = [2, 4, 1, 3] >>> >>> Now, I want to order _a_ (a[1])

Re: Can python quickly display results like bash?

2009-03-17 Thread Hrvoje Niksic
Chris Rebert writes: > Ah, I should've thought to google for the sh manpage. Locally, man > sh just gives me the bash manpage again which doesn't list -x :-( Are you sure? On my system the OPTIONS section of bash(1) begins with: In addition to the single-character shell options documented

Re: How to do this in Python?

2009-03-18 Thread Hrvoje Niksic
Luis Zarrabeitia writes: > One could use this: > > with open(filename, "rb") as f: > for buf in iter(lambda: f.read(1000),''): > do_something(buff) This is by far the most pythonic solution, it uses the standard 'for' loop, and clearly marks the sentinel value. lambda may look stra

Re: array next pointer

2009-03-18 Thread Hrvoje Niksic
Armin writes: >> Yep, that's what I meant, I forgot the parameter name. > > Could you give an example of next() with a sentinel and describe its > use case please? I have a little trouble understanding what you > guys mean! See the thread about reading the file in chunks. Instead of: while Tr

Re: Disable automatic interning

2009-03-23 Thread Hrvoje Niksic
George Sakkis writes: > I'm working on some graph generation problem where the node identity > is significant (e.g. "if node1 is node2: # do something) but ideally I > wouldn't want to impose any constraint on what a node is I'm not sure if it helps in your case, but you can easily turn off the

Re: Does __init__ of subclass need the same argument types as __init__ of base class?

2009-03-25 Thread Hrvoje Niksic
Bruno Desthuilliers writes: >> The print command inside the __init__ method isn't executed, so that >> method doesn't seem to start at all. > > this often happens with (usually C-coded) immutable types. The > initializer is not called, only the "proper" constructor (__new__). More specifically,

Re: global name 'self' is not defined - noob trying to learn

2009-03-30 Thread Hrvoje Niksic
mark.sea...@gmail.com writes: > So I want a class ShadowRegister, which just has a value that I can > do get/set bit sel and slice ops. I got that working with __init__. > It was subclass from "object". Then I wanted a RegisterClass that > was a subclass of ShadowRegister, which would read a har

Re: Cyclic GC rules for subtyped objects with tp_dictoffset

2009-03-31 Thread Hrvoje Niksic
[ Questions such as this might be better suited for the capi-sig list, http://mail.python.org/mailman/listinfo/capi-sig ] BChess writes: > I'm writing a new PyTypeObject that is base type, supports cyclic > GC, and has a tp_dictoffset. If my type is sub-typed by a python > class, what exactly

Re: python for loop

2009-03-31 Thread Hrvoje Niksic
Chris Rebert writes: > Among other things, it has the nice property that: > len(some_list[n:m]) == m-n And also that it is intuitive how to represent an empty slice (foo[n:n]). When traversing over sublists, it's also a useful property that foo[a:b] + foo[b:c] == foo. -- http://mail.python.org/

Re: python for loop

2009-04-02 Thread Hrvoje Niksic
Carl Banks writes: > This is unforgiveable, not only changing the indexing semantics of > Python (because a user would have NO CLUE that something underlying > has been changed, and thus it should never be done), but also for > the needless abuse of exec. Then I guess you'd fire Guido, too -- fr

Re: statvfs clearance

2009-04-04 Thread Hrvoje Niksic
Sreejith K writes: > Python's statvfs module contains the following indexes to use with > os.statvfs() that contains the specified information > > statvfs.F_BSIZE > Preferred file system block size. [...] > statvfs.F_NAMEMAX > Maximum file name length. > > Can anyone tell me (or give me s

Re: How to free /destroy object created by PyTuple_New

2009-04-05 Thread Hrvoje Niksic
[ You can also ask questions like this on the specialized capi-sig list; see http://mail.python.org/mailman/listinfo/capi-sig ] grbgooglefan writes: > In my case, my C application has multiple threads & they are accessing > a single Python Interpreter which was initialized by 1st main thread.

Re: How to free /destroy object created by PyTuple_New

2009-04-06 Thread Hrvoje Niksic
grbgooglefan writes: > Regarding PyTuple_New, when I pass this tuple with variable values > set to some evaluation function like PyObject_CallObject, do I need > to increment reference for this tuple & then decrement again after > the call returns? You don't. It is assumed that you already own

Re: Why does Python show the whole array?

2009-04-09 Thread Hrvoje Niksic
John Posner writes: > Q: Has anyone on the python-dev list ever proposed a "string"-module > function that does the job of the "in" operator? Maybe this: > > if test.contains(item) # would return a Boolean value That's a string method, not a function in the string module. If you want a fun

Re: Python C API String Memory Consumption

2009-04-10 Thread Hrvoje Niksic
a...@pythoncraft.com (Aahz) writes: > BTW, note that if you're using Python 2.x, range(100) will cause > a "leak" because ints are never freed. Instead, use xrange(). Note that using xrange() won't help with that particular problem. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python C API String Memory Consumption

2009-04-10 Thread Hrvoje Niksic
Carl Banks writes: > On Apr 9, 11:23 pm, Hrvoje Niksic wrote: >> a...@pythoncraft.com (Aahz) writes: >> > BTW, note that if you're using Python 2.x, range(100) will cause >> > a "leak" because ints are never freed.  Instead, use xrange(). >>

Re: Lambda alternative?

2009-04-16 Thread Hrvoje Niksic
mousemeat writes: > Thank you for everyone's explanations, help and interest on this > one. I have reworked my code as described and promised myself not > to use lambdas ever again (i still think they are an elegant idea, > but if they are incompatible with frequently used modules, then the > in

Re: Lambda alternative?

2009-04-16 Thread Hrvoje Niksic
mousemeat writes: > Correct me if i am wrong, but i can pickle an object that contains a > bound method (it's own bound method). No, you can't: >>> import cPickle as p >>> p.dumps([]) '(l.' >>> p.dumps([].append) Traceback (most recent call last): File "", line 1, in TypeError: expected stri

Re: Lambda alternative?

2009-04-17 Thread Hrvoje Niksic
"J. Cliff Dyer" writes: > On Thu, 2009-04-16 at 13:33 +0200, Hrvoje Niksic wrote: >> mousemeat writes: >> >> > Correct me if i am wrong, but i can pickle an object that contains a >> > bound method (it's own bound method). >> >>

Re: Lambda alternative?

2009-04-18 Thread Hrvoje Niksic
Duncan Booth writes: > import cPickle as p > p.dumps([]) >> '(l.' > p.dumps([].append) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: expected string or Unicode object, NoneType found > > Not the best of examples: [].append is a built-in method rather th

Re: and [True,True] --> [True, True]?????

2009-04-23 Thread Hrvoje Niksic
Peter Otten <__pete...@web.de> writes: > The only "popular" data structure I know that implements its length > like this are strings in C. Linked lists and trees also tend to do the same, with the exception of those that explicitly store their length to optimize length queries. -- http://mail.pyt

Re: Lisp mentality vs. Python mentality

2009-04-25 Thread Hrvoje Niksic
Paul Rubin writes: > "Ciprian Dorin, Craciun" writes: >> A practical example: I have lists that contain strings, but I want >> to compare them in an case-insensitive way... Should I update the >> __eq__ method (for str class) and break almost everything? Can I w

Re: unbinding a global variable in Python

2009-04-30 Thread Hrvoje Niksic
Mark Tarver writes: >> (setq *g* 0) > 0 > >> (boundp '*g*) > t 'foo' in globals() -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange interaction between timeit and recursion

2009-05-04 Thread Hrvoje Niksic
Steven D'Aprano writes: > I don't understand why my recursive function hits the recursion > limit inside the timeit.Timer when it works outside of it. Probably because your test function is at the very edge of the recursion limit, and timeit.Timer triggers it because it calls it at a deeper stac

Re: Python API Functions equivalent to ruby's rb_big2str() and rb_str2cstr()

2009-05-12 Thread Hrvoje Niksic
rahul writes: > Hi Christian, > rb_big2str(Big-Integer, base) of ruby returns string representation > of big-Integer. now, i am able to find equivalent python API function > of rb_str2cstr() of ruby. That would be PyLong_FromString, for the sake of later searches. > so , please help me about

Re: C API: how to replace python number object in place?

2009-05-14 Thread Hrvoje Niksic
vava...@cpu111.math.uwaterloo.ca (Stephen Vavasis) writes: > If x is a C variable of type PyObject*, and I happen to know already > that the object is of a numeric type, say int, is there a way to > change the value of x in place to a different number? In the C/API > documentation I found routine

<    1   2   3   4   5   >