Re: unpickle from URL problem

2007-10-10 Thread Hrvoje Niksic
Alan Isaac <[EMAIL PROTECTED]> writes: > I upload to a server. > I try to unpickle from the URL. No luck. Try it: > x1, x2 = > pickle.load(urllib.urlopen('http://www.american.edu/econ/notes/hw/example1')) > > I change the filetype to unix. I upload again. > I try to unpickle from the URL. Now

Re: unpickle from URL problem

2007-10-10 Thread Hrvoje Niksic
Alan Isaac <[EMAIL PROTECTED]> writes: > Hrvoje Niksic wrote: >> The first upload breaks the file. You uploaded it in (presumably >> FTP's) text mode, which changes \n -> \r\n. But you download it using >> http, which specifies no such conversion in the opposi

Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > Right, the paragraph is actually pretty clear after a second > reading. I find it surprising nonetheless, as it's easy to forget > to return a result when you're implementing a method that does an > in-place operation, like __iadd__: I've recently been bitten by that,

Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes: > Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > >> I've recently been bitten by [rebinding the var to what __iadd__ >> returns], and I don't understand the reasoning behind __iadd__'s >> design. I mea

Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > Simply not to introduce special cases I guess. If you write ``x.a > += b`` then `x.a` will be rebound whether an `a.__iadd__()` exists > or not. Otherwise one would get interesting subtle differences with > properties for example. If `x.a`

Re: Static variable vs Class variable

2007-10-17 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes: > Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > >> The current implementation of += uses __add__ for addition and >> __iadd__ for addition that may or may not be in-place. I'd like to >> know the rationale for th

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Hrvoje Niksic
Paul Hankin <[EMAIL PROTECTED]> writes: > On Oct 17, 10:03 pm, Debajit Adhikary <[EMAIL PROTECTED]> wrote: >> How does "a.extend(b)" compare with "a += b" when it comes to >> performance? Does a + b create a completely new list that it assigns >> back to a? If so, a.extend(b) would seem to be fast

Re: Appending a list's elements to another list using a list comprehension

2007-10-18 Thread Hrvoje Niksic
Paul Hankin <[EMAIL PROTECTED]> writes: > Not to me: I can never remember which of a.append and a.extend is > which. Interesting, with me it's the other way around. Maybe it's because I used Python before extend was available. > Falling back to a = a + b is exactly what you want. Not if you wa

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > 173.000 dict elements and it tooks 2.2 seconds this very big time > for my project If you're generating the string from Python, use cPickle instead. Much faster: >>> import time >>> d = dict((i, i+1) for i in xrange(17)) >>> len(d) 17 >>> s=repr(d)

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > import cPickle as pickle > a="{2:3,4:6,2:7}" > s=pickle.dumps(a, -1) > g=pickle.loads(s); > print g > '{2:3,4:6,2:7}' > > Thank you very much for your answer but result is a string ?? Because you gave it a string. If you give it a dict, you'll get a dict:

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > I select where id=56 and 100.000 rows are selecting but this took 2 > second. (very big for my project) > I try cache to speed up this select operation.. > And create a cache table: > id-1 | all > 56{68:66, 98:32455, 62:655} If you use Python to create

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > Sorry i can't understand :( > Yes my database already has data in the "{..}" format and i select > this and i want to use it for dictionary.. But, do you use Python to create that data? If so, simply convert it to pickle binary format instead of "{...}".

Re: Convert string to command..

2007-10-18 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > > When you load it, convert the string to dict with cPickle.loads > > instead of with eval. > > Yes i understand and this very very good ;) Good! :-) > psycopg2.ProgrammingError: invalid byte sequence for encoding "UTF8": > 0x80 > HINT: This error can a

Re: Convert string to command..

2007-10-19 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: >> Use a different column type for cache2's column, one more appropriate >> for storing binary characters (perhaps BYTEA for Postgres). Don't >> forget to also use a bind variable, something like: >> >> cursor.execute("INSERT INTO cache2 VALUES (?)", a) >> >>

Re: Convert string to command..

2007-10-19 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > If you're generating the string from Python, use cPickle instead. > Much faster: [...] >>>> t0 = time.time(); d2 = eval(s); t1 = time.time(); t1-t0 > 1.5457899570465088 >>>> t0 = time.time(); d

Re: class vs type

2007-10-19 Thread Hrvoje Niksic
"Colin J. Williams" <[EMAIL PROTECTED]> writes: > In Python Types and Objects, Shalabh Chaturvedi says (in the Python > 3.0 documentation - New Style Classes) > > "The term class is traditionally used to imply an object created by > the class statement. However, classes are now synonymous with > t

Re: Going past the float size limits?

2007-10-26 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > The calculation looks like this > > A = 0.35 > T = 0.30 > C = 0.25 > G = 0.10 > > and then I basically continually multiply those numbers together. I > need to do it like 200,000+ times but that's nuts. I can't even do it > 1000 times or the number rounds off to 0.0. I

Re: A class question

2007-10-29 Thread Hrvoje Niksic
Donn Ingle <[EMAIL PROTECTED]> writes: > Is there a way I can, for debugging, access the instance variable name from > within a class? > E.g: > Class X: > def debug(self): > print "My instance var is %s" % (some magic Python stuff) As others have answered, an instance can live in many variabl

Re: A class question

2007-10-29 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: >> As others have answered, an instance can live in many variables, > > "be bound to many names" would be more accurate IMHO. Technically more accurate maybe (but see below), but I was responding to a beginner's post, so I was striving for ease of u

Re: A class question

2007-10-29 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > The problem is that your formulation implies (to me at least) that the > variable is actually a kind of container for the object. I really didn't expect it to be read that way, especially since the sentence claims that the same instance can reside

Re: setting variables in outer functions

2007-10-29 Thread Hrvoje Niksic
Tommy Nordgren <[EMAIL PROTECTED]> writes: > Given the following: > def outer(arg) > avar = '' > def inner1(arg2) > # How can I set 'avar' here ? I don't think you can, until Python 3: http://www.python.org/dev/peps/pep-3104/ Currently the (ugly) solution is to change variabl

Re: A class question

2007-10-29 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: >> It seems to me that in recent times more Python beginners come from >> a Java background than from a C one. > > Java does have "container" variables for primitive types, and even > for "references", Java's variables are more than names - they do >

Re: A class question

2007-10-30 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: >> While Java's variable declarations bear a superficial (syntactical) >> similarity to C, their semantics is in fact equivalent to the >> object-reference semantics we know in Python. They implicitly refer >> to objects allocated on the heap and,

Re: Automatic Generation of Python Class Files

2007-10-30 Thread Hrvoje Niksic
Fuzzyman <[EMAIL PROTECTED]> writes: > We recently had to change an object pipeline from new style classes > to old style. A lot of these objects were being created and the > *extra overhead* of new style classes was killing us. :-) Can you please expand on this? What extra overhead of new-style

Re: why did these companies choose Tcl over Python

2007-10-30 Thread Hrvoje Niksic
chewie54 <[EMAIL PROTECTED]> writes: >Mentor Graphics ModelTech VHDL and Verilog simulator >Synopsys Design Compiler and Primetime Static Timing Analyzer >Actel FPGA tools. How old are these tools? Tcl has been around as an extension language for a long time, longer than most curren

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Hrvoje Niksic
jelle <[EMAIL PROTECTED]> writes: > the subject pretty much says it all. > if I check a string for for a substring, and this substring isn't found, > should't the .find method return 0 rather than -1? How would you treat the case of 'something' being at the beginning of the string? After all, f

Re: why did these companies choose Tcl over Python

2007-10-31 Thread Hrvoje Niksic
Roy Smith <[EMAIL PROTECTED]> writes: > We also had lots of hooks into C code. Doing that is trivial in Tcl. Yes, > I know you can extend/embed Python, but it's a LOT easier in Tcl. > Embedding a Tcl interpreter in a C program is literally one line of > code. Have you tried both or just Tcl?

Re: 3 number and dot..

2007-10-31 Thread Hrvoje Niksic
Abandoned <[EMAIL PROTECTED]> writes: > Hi.. > I want to do this: > for examle: > 12332321 ==> 12.332.321 > > How can i do? I'm surprised that no one has proposed a regex solution, such as: >>> import re >>> re.sub(r'\d{1,3}(?=(?:\d{3})+$)', r'\g<0>.', str(1234567)) '1.234.567' -- http://mail.p

Re: 3 number and dot..

2007-10-31 Thread Hrvoje Niksic
Paul McNett <[EMAIL PROTECTED]> writes: > Chris Mellon has given you the best response: use the locale module > for this. It may be the best choice as far as reuse is concerned, but it's not without serious drawbacks. For one, the locale model doesn't really allow forcing of the separators. Som

Re: setting variables in outer functions

2007-10-31 Thread Hrvoje Niksic
"Chris Mellon" <[EMAIL PROTECTED]> writes: > I have no idea why someone who already has a working, object system > would want to implement their own on top of closures. This subthread is getting ridiculous -- closures are *not* useful only for implementing object systems! The object system thing

Re: setting variables in outer functions

2007-11-01 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes: > In real life code methods are used to implement callbacks When I said "closures are used ...", I wasn't trying to be preachy about how I think callbacks should be implemented, just explaining the use (and usefulness) of *closures*. I'm not saying closur

Re: PyCheck for a classes defined in python and user data in PyObject_HEAD

2007-11-02 Thread Hrvoje Niksic
Note that there is a mailing list dedicated to the Python/C API, http://mail.python.org/mailman/listinfo/capi-sig [EMAIL PROTECTED] writes: > issue #2 I'm in a situation when i don't really need to extend > python with any classes of my own but i do have extra luggage for > the python data structu

Re: Populating huge data structures from disk

2007-11-06 Thread Hrvoje Niksic
"Michael Bacarella" <[EMAIL PROTECTED]> writes: > cPickle with protocol 2 has some promise but is more complicated because > arrays can't be pickled. This is not true: >>> import array >>> a = array.array('L') >>> a.extend(xrange(10)) >>> a array('L', [0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L]) >>

Re: Populating huge data structures from disk

2007-11-06 Thread Hrvoje Niksic
"Chris Mellon" <[EMAIL PROTECTED]> writes: > It is a little annoying that there's no way to pre-allocate an > array. It doesn't over-allocate, either, so building on a few bytes > at a time is pretty much worst case behavior. The fine source says: array_resize(arrayobject *self, Py_ssize_t news

Re: What colour model does the image use in PIL

2007-11-07 Thread Hrvoje Niksic
Johny <[EMAIL PROTECTED]> writes: > I would need to apply a threshold value to the image, where > everything above a certain brightness level becomes white, and > everything below the level becomes black. How can I do that with > PIL? I think you're supposed to use the "point" method, but I don'

Re: What colour model does the image use in PIL

2007-11-07 Thread Hrvoje Niksic
Johny <[EMAIL PROTECTED]> writes: > I use PIL and with it im.getpixel((x,y)) to find out the colour of a > pixel. But how can I find out in which color model the the return > value is? im.mode gives you a string such as 'RGBA' or 'CMYK'. im.getbands() returns a tuple such as ('R', 'G', 'B', 'A'

Re: Using python as primary language

2007-11-09 Thread Hrvoje Niksic
"Martin Vilcans" <[EMAIL PROTECTED]> writes: >> If by 'this' you mean the global interpreter lock, yes, there are good >> technical reasons. All attempts so far to remove it have resulted in an >> interpeter that is substantially slower on a single processor. > > Is there any good technical reaso

Re: defaultdict and dict?

2007-11-09 Thread Hrvoje Niksic
Davy <[EMAIL PROTECTED]> writes: > In Python 2.5 document, defaultdict is called high performance > container. From document, we can know defaultdict is subclass of dict. > So, why defaultdict have higher performance than dict? I don't think the "high performance" attribute is supposed to mean th

Re: Using python as primary language

2007-11-12 Thread Hrvoje Niksic
"Martin Vilcans" <[EMAIL PROTECTED]> writes: > But if Python gets slow when you add fine-grained locks, then most > certainly it wouldn't get so slow if the locks were very fast, > right? Given the sheer number of increfs and decrefs happening, they should be impossibly fast (meaning: nonexistent

Re: Populating a dictionary, fast

2007-11-12 Thread Hrvoje Niksic
Paul Rubin writes: > Michael Bacarella <[EMAIL PROTECTED]> writes: >> If only it were so easy. > > I think I know what's going on, the dictionary updates are sending the > GC into quadratic behavior. Try turning off the GC: > > import gc > gc.disable() This is

Re: Populating a dictionary, fast

2007-11-12 Thread Hrvoje Niksic
Michael Bacarella <[EMAIL PROTECTED]> writes: > $ uname -a > Linux xxx 2.6.9-22.ELsmp #1 SMP Sat Oct 8 21:32:36 BST 2005 x86_64 x86_64 > x86_64 GNU/Linux > > We've also tried it on this version (on a different machine): > > $ uname -a > Linux yyy 2.6.18-8.el5 #1 SMP Thu Mar 15 19:46:53 EDT 2007 x

Re: Some "pythonic" suggestions for Python

2007-11-12 Thread Hrvoje Niksic
Loic Mahe <[EMAIL PROTECTED]> writes: > Chris M write : >> Multi-return value lambda? Just so you know, there is no concept of >> returning more than one value from a function. > > I wrote: >> * multi return value lambda > > I meant: multiple return statement, not return multiple values > > pseudo

Re: Moving from java to python.

2007-11-12 Thread Hrvoje Niksic
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > def __init__(self, connections = None, uid = None): You can use connections=(), so you don't need the "if" below. In fact, you can further write: for node, weight in connections: self._connected.append(node) self._weigh

Re: Iterator for circulating a list

2007-11-13 Thread Hrvoje Niksic
"BJörn Lindqvist" <[EMAIL PROTECTED]> writes: > L = somelist > > idx = 0 > while True: > item = L[idx] > # Do something with item > idx = (idx + 1) % len(L) > > wouldn't it be cool if there was an itertool like this: > > def circulate(L, begin = 0, step = 1): > idx = begin > wh

Re: Populating a dictionary, fast [SOLVED]

2007-11-13 Thread Hrvoje Niksic
Francesc Altet <[EMAIL PROTECTED]> writes: > I don't know exactly why do you need a dictionary for keeping the > data, but in case you want ultra-fast access to values, there is no > replacement for keeping a sorted list of keys and a list with the > original indices to values, and the proper list

Re: Populating a dictionary, fast [SOLVED SOLVED]

2007-11-14 Thread Hrvoje Niksic
Aaron Watters <[EMAIL PROTECTED]> writes: > On Nov 12, 12:46 pm, "Michael Bacarella" <[EMAIL PROTECTED]> wrote: >> >> > It takes about 20 seconds for me. It's possible it's related to >> > int/long >> > unification - try using Python 2.5. If you can't switch to 2.5, try >> > using string keys inst

Re: no __len__ attribute in NodeList or the list base?

2007-11-15 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > i extract class object from an instance of NodeList (minicompat.py) > like so > PyObject *pclass = PyObject_GetAttrString( nodelistinsance, > "__class__"); > but > PyObject_GetAttrString(pclass, "__len__") > returns NULL. Are you sure about that? >>> import xml.dom.m

Re: Populating a dictionary, fast [SOLVED SOLVED]

2007-11-15 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: >>> Someone please summarize. >> >> Yes, that would be good. > > On systems with multiple CPUs or 64-bit systems, or both, creating and/or > deleting a multi-megabyte dictionary in recent versions of Python (2.3, > 2.4, 2.5 at least) takes a LONG time

Re: Populating a dictionary, fast [SOLVED SOLVED]

2007-11-16 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Can you post minimal code that exhibits this behavior on Python 2.5.1? >> The OP posted a lot of different versions, most of which worked just >> fine for most people. > > Who were testing it on single-CPU, 32 bit systems. Still, I'd like to see a te

Re: struct,long on 64-bit machine

2007-11-19 Thread Hrvoje Niksic
Neal Becker <[EMAIL PROTECTED]> writes: > What's wrong with this? > type(struct.unpack('l','\00'*8)[0]) > > > Why I am getting 'int' when I asked for 'long'? C longs are converted to Python integers; see the table on http://docs.python.org/lib/module-struct.html. If you really need the Python l

Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Hrvoje Niksic
blaine <[EMAIL PROTECTED]> writes: > Python Code: > G = > long(2333938645766150615511255943169694097469294538730577330470365230748185729160097289200390738424346682521059501689463393405180773510126708477896062227281603) > P = > long(7897383601534681724700886135766287333879367007236994792380

Re: eof

2007-11-22 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: >>> Language comparisons are sometimes good. They are best when >>> they are free of FUD. >> >> So why Python's IO cannot yield f.eof() as easily as Ruby's can? :) > > Because that requires buffering, something that affects speed. I don't get it, Py

Re: eof

2007-11-22 Thread Hrvoje Niksic
braver <[EMAIL PROTECTED]> writes: > On Nov 22, 6:10 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Granted, they aren't part of the stdlib - but then, lots >> of things aren't. > > As Hendrik noticed, I can't even add my own f.eof() if I want to > have buffering -- is that right? You can,

Re: 100% CPU Usage when a tcp client is disconnected

2007-11-22 Thread Hrvoje Niksic
Tzury Bar Yochay <[EMAIL PROTECTED]> writes: > The following is a code I am using for a simple tcp echo server. > When I run it and then connect to it (with Telnet for example) if I > shout down the telnet the CPU tops 100% of usage and saty there > forever. Can one tell what am I doing wrong? I

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Hrvoje Niksic
samwyse <[EMAIL PROTECTED]> writes: > create a hash that maps your keys to themselves, then use the values > of that hash as your keys. The "atom" function you describe already exists under the name "intern". -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Sun, 25 Nov 2007 01:38:51 +0100, Hrvoje Niksic wrote: > >> samwyse <[EMAIL PROTECTED]> writes: >> >>> create a hash that maps your keys to themselves, then use the values of >>> that hash

Re: How to Teach Python "Variables"

2007-11-26 Thread Hrvoje Niksic
greg <[EMAIL PROTECTED]> writes: > none wrote: >> IIRC, I once saw an explanation how Python doesn't have >> "variables" in the sense that, say, C does, and instead has bindings >> from names to objects. > > If you're talking to C programmers, just tell them that Python > variables always cont

Re: Global variables within classes.

2007-11-27 Thread Hrvoje Niksic
Kevac Marko <[EMAIL PROTECTED]> writes: > When changing default value, is there any way to change class > attribute and all referenced attributes too? > > class M: > name = u"Marko" > > a, b = M(), M() > a.name = u"Kevac" > print M.name, a.name, b.name > -> Marko Kevac Marko > > Is there any w

Re: Very basic, sorting a list ???

2007-11-29 Thread Hrvoje Niksic
Stef Mientki <[EMAIL PROTECTED]> writes: > although I find it rather non-intuitive. > I didn't expect a copy, but a reference to itself wouldn't be asked > too much ? If you didn't expect a copy, why rely on the return value? You could simply continue using the sorted list. Your first post says

Re: Oh no, my code is being published ... help!

2007-11-30 Thread Hrvoje Niksic
"Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: > No, writing this way will confound the 2to3 tool. Why? print("foo") is a perfectly valid Python 2 statement. Maybe it's simply a matter of fixing the tool. -- http://mail.python.org/mailman/listinfo/python-list

Re: python newbie - question about lexical scoping

2007-12-02 Thread Hrvoje Niksic
"Matt Barnicle" <[EMAIL PROTECTED]> writes: >> i have a class dict variable that apparently holds its value across >> instantiations of new objects.. [...] > ok, i see... python has a concept i'm not accustomed to I don't doubt that Python managed to confuse you here, but in this case there is n

Re: Overriding member methods in __init__

2007-12-03 Thread Hrvoje Niksic
c james <[EMAIL PROTECTED]> writes: >> class YesNo(object): >>def __init__(self, which): >> self.which = which >> >>def __call__(self, val): >> return (self.no, self.yes)[self.which](val) >> >>def yes(self, val): >> print 'Yes', val >> >>def no(self, val): >>

Re: python 2.5 - f=open('a_file.txt','w') gives [Errno 2]

2007-12-03 Thread Hrvoje Niksic
dirkheld <[EMAIL PROTECTED]> writes: > I don't have a file called 'a_file.txt' > I want to create that file and write some data to it. How exactly are you starting the Python interpreter? "No such file or directory" on file creation can happen when you try to create a file in a directory that ha

Re: An Object's Type

2007-12-06 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > So ask yourself: in which way will the final result be different > from would very probably happens without the "typecheking code" ? In > *both* cases, you end up with a runtime exception. The idea behind such type checks is to make sure type erro

Re: I'm missing something here with range vs. xrange

2007-12-11 Thread Hrvoje Niksic
"Joe Goldthwaite" <[EMAIL PROTECTED]> writes: > To do a range(100) > > 1. Allocate a big chunk of memory > 2. Fill the memory with the range of integers > 3. Setup an index into the memory array > 4. Every time the program asks for the next item, bump > the mem

Re: Are Python deques linked lists?

2007-12-11 Thread Hrvoje Niksic
Neil Cerutti <[EMAIL PROTECTED]> writes: > Anyhow, implementing linked lists in Python is not challenging, but > they don't work well with Python iterators, which aren't suitable > for a linked list's purposes--so you have to give up the happy-joy > for loop syntax in favor of Python's frowny-sad

Re: Is a "real" C-Python possible?

2007-12-11 Thread Hrvoje Niksic
sturlamolden <[EMAIL PROTECTED]> writes: > On 10 Des, 23:54, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > >> Or a lack of time and money. Lisp is one of the older programming >> languages around, and at a time had BigBucks(tm) invested on it to try >> and make it practically usable. > > Yes.

Re: Are Python deques linked lists?

2007-12-11 Thread Hrvoje Niksic
Duncan Booth <[EMAIL PROTECTED]> writes: >> I do have one last question about a doubly-linked list. Would you >> have to perform any tricks (del statements) to get the garbage >> collector to collect every node, or will it just work? > > It should just work. Fortunately that's trivial to verify:

Re: programming container object

2007-12-17 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: >> In any case, it is not possible, because the instance method cannot >> know whether its result is being assigned to a name or just thrown >> away. > > This isn't entirely correct - there _are_ ways to know. > > http://aspn.activestate.com/ASPN/Cook

Re: checking a string against multiple patterns

2007-12-18 Thread Hrvoje Niksic
tomasz <[EMAIL PROTECTED]> writes: > here is a piece of pseudo-code (taken from Ruby) that illustrates the > problem I'd like to solve in Python: [...] I asked the very same question in http://groups.google.com/group/comp.lang.python/browse_frm/thread/3e8da954ff2265e/4deb5631ade8b393 It seems tha

Re: Changing intobject to use int rather than long

2007-12-18 Thread Hrvoje Niksic
Clarence <[EMAIL PROTECTED]> writes: > When you move your application to a 64-bit system in order to get a > bigger address space to store your millions/billions of integers in > RAM, but they get twice as big, you don't gain very much. I don't think changing the underlying type will help at all.

Re: Why custom objects take so much memory?

2007-12-18 Thread Hrvoje Niksic
jsanshef <[EMAIL PROTECTED]> writes: > That means every object is around 223 bytes in size That's too > much considering it only contains a string with a maximum size of 7 > chars. The list itself consumes 4 MB because it stores 1 million PyObject pointers. It possibly consumes more due to o

Re: Why custom objects take so much memory?

2007-12-19 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Tue, 18 Dec 2007 21:13:14 +0100, Hrvoje Niksic wrote: > >> Each object takes 36 bytes itself: 4 bytes refcount + 4 bytes type ptr + >> 4 bytes dict ptr + 4 bytes weakptr + 12 bytes gc overhead. That's not >>

Re: Changing intobject to use int rather than long

2007-12-21 Thread Hrvoje Niksic
"Terry Reedy" <[EMAIL PROTECTED]> writes: > "Christian Heimes" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | Terry Reedy wrote: > | > Good idea. I think people who moved to 64 bits to get 64 bits would be > | > upset if they did not ;-). > | > | Windows X64 users still get 32

Re: Details about pythons set implementation

2008-01-04 Thread Hrvoje Niksic
Achim Domma <[EMAIL PROTECTED]> writes: > I'm interested in details about how sets are implemented in python. > They seem to be quite fast and I found some remarks who state, that > the implementation is highly optimized. I need to implemented sets > in C/C++ and need a starting point on how to do

Re: popen question

2008-01-08 Thread Hrvoje Niksic
Robert Latest <[EMAIL PROTECTED]> writes: > If 'slow' or some other program does buffered output, how come I can > see its output line-by-line in the shell? stdio uses different buffering strategies depending on the output type. When the output is a TTY, line buffering is used; when the output g

Re: popen question

2008-01-08 Thread Hrvoje Niksic
Robert Latest <[EMAIL PROTECTED]> writes: >> If you see lines one by one, you are in luck, and you can fix things >> on the Python level simply by avoiding buffering in popen. If not, >> you will need to resort to more advanced hackery (e.g. fixing stdio >> using LD_PRELOAD). > > Do I really? Aft

Re: Open a List of Files

2008-01-08 Thread Hrvoje Niksic
Fredrik Lundh <[EMAIL PROTECTED]> writes: > BJ Swope wrote: > >> the code looks ok. please define "not working". >> >> Yep, defining "not working" is always helpful! :) >> >> I want to have all 3 files open at the same time. I will write to >> each of the files later in my script but just th

Re: use fileinput to read a specific line

2008-01-08 Thread Hrvoje Niksic
Fredrik Lundh <[EMAIL PROTECTED]> writes: > From what I can tell, Java's GC automatically closes file streams, > so Jython will behave pretty much like CPython in most cases. The finalizer does close the reclaimed streams, but since it is triggered by GC, you have to wait for GC to occur for the

Re: "Canonical" way of deleting elements from lists

2008-01-09 Thread Hrvoje Niksic
Robert Latest <[EMAIL PROTECTED]> writes: > From a list of strings I want to delete all empty ones. This works: > > while '' in keywords: keywords.remove('') If you're looking for a quick (no quadratic behavior) and convenient way to do it, you can do it like this: keywords = [s for s in key

Re: "Canonical" way of deleting elements from lists

2008-01-09 Thread Hrvoje Niksic
Hrvoje Niksic <[EMAIL PROTECTED]> writes: > If you're looking for a quick (no quadratic behavior) and convenient > way to do it, you can do it like this: > > keywords = [s for s in keywords if s != ''] It now occurred to me that a good compromise between conven

Re: for loop without variable

2008-01-09 Thread Hrvoje Niksic
Mike Meyer <[EMAIL PROTECTED]> writes: > It sounds to me like your counter variable actually has meaning, It depends how the code is written. In the example such as: for meaningless_variable in xrange(number_of_attempts): ... the loop variable really has no meaning. Rewriting this code on

Re: Python too slow?

2008-01-11 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > fact 1: CPython compiles source code to byte-code. > fact 2: CPython executes this byte-code. > fact 3: Sun's JDK compiles source code to byte-code. > fact 4: Sun's JDK executes this byte-code. > > Care to prove me wrong on any of these points ? Do

Re: Learning Python via a little word frequency program

2008-01-11 Thread Hrvoje Niksic
Mike Meyer <[EMAIL PROTECTED]> writes: > On 11 Jan 2008 03:50:53 -0800 Paul Rubin <"http://phr.cx"@NOSPAM.invalid> > wrote: > >> rent <[EMAIL PROTECTED]> writes: >> > keys = freq.keys() >> > keys.sort(key = freq.get, reverse = True) >> > for k in keys: >> > print "%-10s: %d" % (k, freq[k]) >

Re: Newbie Q: modifying SQL statements

2008-01-11 Thread Hrvoje Niksic
"Faber J. Fedor" <[EMAIL PROTECTED]> writes: > On 10/01/08 22:53 -0500, Mike Meyer wrote: >> Personally, I think it would be more pythonic to not try and use two >> different APIs to walk the list of jobs (... One Way To Do it): >> >> def __call__(self, where=None): >> q = "select * from %s"

Re: about sort a list with integer key

2008-01-13 Thread Hrvoje Niksic
lotrpy <[EMAIL PROTECTED]> writes: > if i want sort each line by the first part,(it's a integer, in fact). > don't know how to do it with itemgetter. > key = int(itemgetter(0)) is wrong, key = lambda x:int(x[0]) works. > but s.b. told me itemgetter execute more quickly . Use lambda when it works

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: > What one is "in reality" calling is the '__new__' method of the Person > class. That function, in turn, is creating a new Person instance, and > calling the '__init__' method of the newly-created instance. Finally, > the '__new__' method returns that insta

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Wildemar Wildenburger <[EMAIL PROTECTED]> writes: > Jeroen Ruigrok van der Werven wrote: >> To restate it more correctly: __init__ is akin to a constructor. >> > No. See Hrvoje Niksic's reply (and Ben Finney's to which it was a > reply). > > __init__() /initializes/ an instance (automatically afte

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Mel <[EMAIL PROTECTED]> writes: >> I don't understand the purpose of this "correction". After all, >> __init__ *is* the closest equivalent to what other languages would >> call a constructor. > > Nevertheless, __init__ doesn't construct anything. Only if by "construct" you mean "allocate". __

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
"Reedick, Andrew" <[EMAIL PROTECTED]> writes: >> Only if by "construct" you mean "allocate". __init__ starts out >> with an empty object and brings it to a valid state, therefore >> "constructing" the object you end up with. That operation is >> exactly what other languages call a constructor. >

Re: __init__ explanation please

2008-01-14 Thread Hrvoje Niksic
Ben Finney <[EMAIL PROTECTED]> writes: > Hrvoje Niksic <[EMAIL PROTECTED]> writes: > >> Wildemar Wildenburger <[EMAIL PROTECTED]> writes: >> > __init__() /initializes/ an instance (automatically after >> > creation). It is called, /after/

Re: __init__ explanation please

2008-01-15 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > So while it's true that __init__ is the closest equivalent to what > C++ and Java (and possibly a couple "other languages") call a > constructor, it doesn't imply that you should refer to it as "the > constructor". As Neil Cerutti points out, there

Re: no pass-values calling?

2008-01-15 Thread Hrvoje Niksic
"J. Peng" <[EMAIL PROTECTED]> writes: > we create a new list and assign it to x for future use. How to > destroy the before list [1,2,3]? does python destroy it > automatically? Yes, Python detects that the older list is no longer in use (if that is indeed the case), and destroys it automaticall

Re: assigning values in python and perl

2008-01-16 Thread Hrvoje Niksic
"J. Peng" <[EMAIL PROTECTED]> writes: > $ cat t1.py > def test(x): > x = [4,5,6] > > a=[1,2,3] > test(a) > print a > > $ python t1.py > [1, 2, 3] > > $ cat t1.pl > sub test { > my $ref = shift; > @$ref = (4,5,6); > } @$ref = (4, 5, 6) intentionally assigns to the same list pointed to

Re: Is this a bug, or is it me?

2008-01-17 Thread Hrvoje Niksic
"Neil Cerutti" <[EMAIL PROTECTED]> writes: > You cannot access a class's class variables in it's class-statement > scope, since the name of the type is not bound until after the class > statement is completed. But they are still available as locals, so you can access them using their names, like

Re: Is this a bug, or is it me?

2008-01-17 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > Hello all, > For some reason, the following does not work : > > > class C: > TYPES = [None] > DICT = {} > for Type in TYPES: > DICT.update((E,Type) for E in [1]) > NameError: global name 'Type' is not defined > > > What do you think? Is this a b

Re: raw_input(), STRANGE behaviour

2008-01-26 Thread Hrvoje Niksic
Dox33 <[EMAIL PROTECTED]> writes: > Thanks for your reply. Since I momentarily do not have the ability > to build a new python executable, I would like to ask for your help > in this case. Are you able to supply me with a corrected version? You can simply choose not to use raw_input, and use sy

Re: file write question

2008-01-26 Thread Hrvoje Niksic
"Robb Lane (SL name)" <[EMAIL PROTECTED]> writes: > ... or just leave it till it's done? > I don't need to use the file contents until the script is done > (although it would be nice... just to check it while it's working), Use flush() to force the contents out at opportune times without closing

Re: post variable

2008-01-28 Thread Hrvoje Niksic
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > so the output is always the POST retrieven at first. So the page > keeps on printing the POST variable retrieven at first even thought > i might have reloaded the page 1000 times. Is there any way to > "empty" the POST variable, so that at reload n

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-30 Thread Hrvoje Niksic
Paul Rubin writes: > Quadratic time!! Yowch!! Back to the future: > > def rocket_science(xs): >for x in xs: > if x != 99: > yield x > > a[:] = list(rocket_science(a)) I call "useless use of list"! a[:] = rocket_science(a) :-) -- http://mail.python

<    1   2   3   4   5   >