Re: creating classes with mix-ins

2009-05-11 Thread Carl Banks
pend(value) A metaclass is probably overkill to assign the wrapped blog methods. I probably wouldn't even bother with the decorator, and just write the loop after the class definition. Then you can use MetaBlog directly for klass. class MetaBlog(object): ... for what in attr_list: setattr(MetaBlog, what, boilerplate(what)) If it were the kind of thing I found myself doing often I'd refactor into a decorator. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-10 Thread Carl Banks
On May 10, 12:40 pm, namekuseijin wrote: > Carl Banks wrote: > > Now, maybe readability concerns don't matter to you personally, but it > > does matter to the OP, who is trying to advocate functional > > programming but is having difficulty because most purely fun

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-09 Thread Carl Banks
On May 9, 10:57 am, namekuseijin wrote: > Carl Banks wrote: > > On May 8, 7:19 pm, namekuseijin wrote: > >> On May 8, 10:13 pm, Carl Banks wrote: > >> In Haskell, Lisp and other functional programming languages, any extra > >> syntax gets converted into

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-08 Thread Carl Banks
On May 8, 7:19 pm, namekuseijin wrote: > On May 8, 10:13 pm, Carl Banks wrote: > > > On May 8, 5:47 pm, namekuseijin wrote: > > > > My point is that when all you do is call functions, syntax is > > > irrelevant.  You call functions pretty much in the same

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-08 Thread Carl Banks
nothing but calling functions". [snip irrelevant stuff about office scripting] Carl Banks (**) Python does using indentation to nest, of course, but not at the expression level. -- http://mail.python.org/mailman/listinfo/python-list

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-08 Thread Carl Banks
On May 8, 1:56 pm, namekuseijin wrote: > Carl Banks escreveu: > > > 2. However, functional programming is cryptic at some level no matter > > how nice you make the syntax. > > When your program is nothing but function definition and function > application, synta

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-08 Thread Carl Banks
2. However, functional programming is cryptic at some level no matter how nice you make the syntax. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Public attributes with really private data

2009-05-08 Thread Carl Banks
futile to try to stop access entirely. There's just too many back doors. I would suggest that there really isn't much point in anything more complex than your first solution, which was to validate with properties and to store the value in a separate attribute. Respectable programmers won't lightly bypass your validation if they see that you've taken steps to enforce it. OTOH, once a programmer, respectable or not, decides to override your protection, they are not likely to be stopped by something more complex. So there is no point in making it more complex. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Call a function when a thread exits

2009-05-07 Thread Carl Banks
of myfun and cleanup, def mycleanfun(): try: myfun() finally: cleanup() t = threading.Thread(target=mycleanfun) t.start() Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess.Popen howto?

2009-05-07 Thread Carl Banks
ith the shell? On Windows what if I want a subprocess without a console from a Python program in a console. Stuff like that. I still use os.system for Q&D stuff, but now use subprocess for everything else since I prefer thorough to short and sweet. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Threading and GIL

2009-05-07 Thread Carl Banks
x27;t quite tell if that's what you're doing, then be aware that it is very tricky to do right and most think it to be a bad idea. If you don't allow the thread you're killing to clean up it can deadlock, and even if you do, you have to be careful to clean up properly and you have to

Re: Threading and GIL

2009-05-06 Thread Carl Banks
have the GIL when creating or deleting threads. In fact, I can't think of any reason why it wouldn't work to ensure a GIL state first thing after the thread starts and to release it right before the thread ends. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: call function of class instance with no assigned name?

2009-05-06 Thread Carl Banks
ayer) player.brain.add_handlers( keyboardHandler(player.brain,responder), joystickHandler(player.brain,responder), fovHandler(player.brain), ) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: call function of class instance with no assigned name?

2009-05-06 Thread Carl Banks
o be a factory function. > Sorry, your pseudo-code is so far from real code that I can't figure out > what you're doing.  So I guess I can't be any help till something else > turns up to make it clearer.  Maybe it's just me. I think it's you--and probably a lot of other people who haven't ever written games. No offense. As someone who's written games before I will tell you that George's pseudo-code is not far from real code. His overall approach is fairly typical of how games handle input, although there are some problems in the details. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Self function

2009-05-05 Thread Carl Banks
On May 5, 12:51 am, Steven D'Aprano wrote: > On Mon, 04 May 2009 23:09:25 -0700, Carl Banks wrote: > > In Python the One Obvious Way is iteration when possible, recursion when > > necessary. > > There's nothing "obvious" about solving the 8 Queens probl

Re: Self function

2009-05-05 Thread Carl Banks
On May 4, 8:26 pm, Steven D'Aprano wrote: > On Mon, 04 May 2009 16:33:13 -0700, Carl Banks wrote: > > On May 4, 4:06 pm, bearophileh...@lycos.com wrote: > >> Carl Banks: > > >> >1. Singly-linked lists can and should be handled with iteration.< > >

Re: Self function

2009-05-04 Thread Carl Banks
On May 4, 8:22 pm, Steven D'Aprano wrote: > On Mon, 04 May 2009 15:51:15 -0700, Carl Banks wrote: > > All > > recursion does it make what you're doing a lot less readable for almost > > all programmers. > > What nonsense. It's not nonsense for a singly-l

Re: Self function

2009-05-04 Thread Carl Banks
On May 4, 4:06 pm, bearophileh...@lycos.com wrote: > Carl Banks: > > >1. Singly-linked lists can and should be handled with iteration.< > > I was talking about a binary tree with list-like topology, of course. "(every node has 1 child, and they are chained)" Tha

Re: Self function

2009-05-04 Thread Carl Banks
pology like a single linked list (every node has > 1 child, and they are chained) is a true binary tree still. 1. Singly-linked lists can and should be handled with iteration. All recursion does it make what you're doing a lot less readable for almost all programmers. 2. You should be u

Re: Is there any way this queue read can possibly block?

2009-04-30 Thread Carl Banks
t;          return                                 # done > > "self.inqueue" is a Queue object.  The intent here is to drain the > queue, then return.  Is there any way this can possibly block or hang? Yes, but it'll be waiting to acquire the semaphore which Queues normally don't

Re: Python Noob - a couple questions involving a web app

2009-04-30 Thread Carl Banks
I looked at Django hoping to write a personal little app to manage some personal data. It turns out I didn't have to write an app at all. Django comes with a spiffy and versatile content editor, all I had to do was input the database schema and configure the data entry fields. I figure you and your bosses can do the same thing to manage your private Wolverine image stash. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic emptiness checking

2009-04-29 Thread Carl Banks
n a boolean context. I think a better answer to this question is: "The Zen of Python is not called the Cold Hard Rules of Python"; in this case the language goes against this particluar Zen as it does in many other places. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Numpy compatibility issue (python 2.6)

2009-04-29 Thread Carl Banks
n in this case, and that the workaround should be pretty easy (I doubt any numbers but one are typed out, and it should be no problem to special-case that), it should be fixed there. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Carl Banks
On Apr 26, 3:03 pm, Paul Rubin <http://phr...@nospam.invalid> wrote: > Carl Banks writes: > > Which is "communicating with the rest of the program periodically". > > > Presumably you have to protect objects to share them?  There you go: > > anytime you try

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Carl Banks
On Apr 26, 2:38 pm, Paul Rubin <http://phr...@nospam.invalid> wrote: > Carl Banks writes: > > Say you are running a thread and you want the power to be able to kill > > it at any time.  The thread is either communicating with the rest of > > the program periodically, o

Re: Lisp mentality vs. Python mentality

2009-04-26 Thread Carl Banks
On Apr 26, 5:40 am, Vsevolod wrote: > On Apr 25, 9:06 am, Carl Banks wrote: > > Carl Banks, who might be exaggerating > > > ...a little. > > I think you're exaggerating. Go ask this question in c.l.l and the > first answer you'll get is mismatch.

Re: Lisp mentality vs. Python mentality

2009-04-25 Thread Carl Banks
On Apr 25, 6:05 pm, Mark Wooding wrote: > Carl Banks writes: > > Graham, for his part, doesn't seem to appreciate that what he does is > > beyond hope for average people, and that sometimes reality requires > > average people to write programs. > > I think he

Re: __import__ function broken in 2.6

2009-04-25 Thread Carl Banks
(Given that Python's importing framework is so complicated, though, one wonders whethter sticking to a design ideal is worth it.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python list handling and Lisp list handling

2009-04-25 Thread Carl Banks
On Apr 25, 12:07 am, Mark Tarver wrote: > On 25 Apr, 05:01, Carl Banks wrote: > > > > > On Apr 24, 8:19 am, Mark Tarver wrote: > > > > This page says that Python lists are often flexible arrays > > > >http://www.brpreiss.com/books/opus7/html/pa

Re: Lisp mentality vs. Python mentality

2009-04-25 Thread Carl Banks
ive way... Should I update the > __eq__ method (for str class) and break almost everything? The practical way to deal with this issue is to write your own function when you encounter a situation where == doesn't suffice. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Lisp mentality vs. Python mentality

2009-04-25 Thread Carl Banks
On Apr 25, 12:36 am, John Yeung wrote: > On Apr 25, 2:06 am, Carl Banks wrote: > > > In answering the recent question by Mark Tarver, I think I finally hit > > on why Lisp programmers are the way they are (in particular, why they > > are often so hostile to the "The

Lisp mentality vs. Python mentality

2009-04-24 Thread Carl Banks
ays to deal with that... ...and so on until eyelids can no longer stay open Python programmer: a == b. Next question. Carl Banks, who might be exaggerating ...a little. -- http://mail.python.org/mailman/listinfo/python-list

Re: python list handling and Lisp list handling

2009-04-24 Thread Carl Banks
st be doing things the hard way. Whatever you're trying to do with cons, car, and cdr, chances are Python has a high-level way to do it built in that performs a lot better. Then again, Lispers seem to like to reimplement high-level operations from low-level primitives every time they need i

Re: WINXP vs. LINUX in threading.Thread

2009-04-22 Thread Carl Banks
problem is, during most of the delay wxYield can't be called becaust the function gethostbyname is blocking. I think Diez is correct. To avoid the freeze, one should spawn a thread, and when it completes it should notify the GUI thread by pushing an event or scheduling an idle call. Functions that do that are usually thread-safe. (A permanent worker thread might be better but it would involve a lot more synchronization.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PyModerator, serverFiles.py:13: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha

2009-04-22 Thread Carl Banks
ay replace "import sha" with "import hashlib" and "sha.new" with "hashlib.sha1", and any other changes that might be necessary (unlikely). See the documentation for hashlib. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: using python logo at startup

2009-04-21 Thread Carl Banks
e.com/recipes/120687/ Also, no matter how spiffy the Python logo is, you should always give the user an option to disable it. (A lot of people like to start an app and do something else while it's loading, and splash screens are highly irritating when doing this.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Programming in Python with a view to extending in C at a later date.

2009-04-21 Thread Carl Banks
they can serve as a base for Python classes. That way, if you have a class and you want to implement a few methods in C while leaving the rest in Python, you can factor out all the C methods into a base class written in C. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: The Python standard library and PEP8

2009-04-19 Thread Carl Banks
y); I'm just saying there is a rationale behind it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: unpythonic use of property()?

2009-04-17 Thread Carl Banks
On Apr 17, 4:00 pm, Scott David Daniels wrote: > Carl Banks wrote: > > On Apr 17, 10:21 am, J Kenneth King wrote: > >> Consider: > > >> code: > >> > > >> clas

Re: cPickle and subclassing lists?

2009-04-17 Thread Carl Banks
, doing that will cause funny things to happen when pickling. If you're doing that, consider the reload function instead (although it has it's own problems). I'd highly recommend against pickling an instance of a class that isn't defined in, and loaded from, a regular module.

Re: unpythonic use of property()?

2009-04-17 Thread Carl Banks
lly, some people think read-only attributes are unpythonic. I think that's ridiculous, although in general I'd advise against making attributes read-only willy-nilly. But there's a time and place for it. Last thing I'll advise is don't get too hung up on terms like "Pythonic". Treat such labels are more of a red flag and get people who throw out the term to explain why. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: any(), all() and empty iterable

2009-04-14 Thread Carl Banks
to two answers. The valid answer to the above question could be "I don't have any books", neither yes nor no. The closest thing to that you can get in Python is to raise an exception. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python C API String Memory Consumption

2009-04-10 Thread Carl Banks
lp with that particular problem. I think it will because with xrange the integers will not all have to exist at one time, so Python doesn't have to increase the size of the integer pool to a million. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How come I can't get get my background thread to output anything?

2009-04-09 Thread Carl Banks
; m-net% > > > > I was expecting to see > > > > person  was here > >  Never mind. When i add while 1:pass like in the following > > thread.start_new_thread(domsg, ("person",2)) > while 1 : pass > > the code works as expected Whoa, there, chief, you don't want to do that. It'll cause a busy loop and run one of your CPUs to 100%. Instead, use the theading module and the join method: import threading thr = threading.Thread(target=domsg,args=("person",2)) thr.start() # do whatever in the main thread thr.join() Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How to import a module so that the current globals are available to the module?

2009-04-09 Thread Carl Banks
nable, and there are some libraries that are based strongly on callbacks (which is the term for what you're trying to do). However, few if any libraries try to determine the callback automatically; you have to explicity pass the function/object to call back to. Carl Banks -- http://mail.python

Re: numpy.where

2009-04-09 Thread Carl Banks
On Apr 9, 2:58 am, Neil Crighton wrote: > Carl Banks gmail.com> writes: > > > > >>> condition = (min_time <= time) & (time <= max_time) > > > >>> new_time = time[condition] > > > >>> new_energy = energy[condition] &

Re: numpy.where

2009-04-09 Thread Carl Banks
me = time[condition] > >>> new_energy = energy[condition] Won't work: condition is an array of ones and zeros, but you need to index the arrays with indices. So, add a call to nonzero to get the indices of the elements. elements = nonzero(logical_and(min_time<=time,max_time>=time)) new_time = time[elements] new_energy = energy[elements] Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python C API String Memory Consumption

2009-04-07 Thread Carl Banks
ak a reference if passed a Unicode object; PyArg_ParseTuple automatically creates an encoded string but never decrefs it. (That might be necessary evil to preserve compatibility, though. PyString_AS_STRING does it too.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread Carl Banks
hat, in turn, suggests he might as well not even bother sending the discrete values to the clustering algorithm, but instead to call it for each unique set of discretes. (However, I could imagine the marginal cost of more dimensions is less than that of multiple runs; I've been dealing with such a case at work.) I'll leave it to the OP to decide. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: in place list modification necessary? What's a better idiom?

2009-04-06 Thread Carl Banks
Points) A couple general pointers: * Don't ever use i to represent a string. Programmers expect i to be an integer. i,j,k,l,m, and n should be integers, in fact. u,v,w,x,y, and z should be floats. You should stick to this convention whenever possible, but definitely never use i for anything but an integer. * set is built into Python now; unless you're using an older version (2.3 I think) you should use set instead of Set. * The Python style guide (q.g.) recommends that variables use names such as column_index rather than columnIndex. The world won't end if you don't follow it but if you want to be Pythonic that's how. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How to go about. On read/write locks

2009-04-06 Thread Carl Banks
rom writing > alltogether. You could implement some kind of fair ordering where whoever requests a lock first is guaranteed to get it first, but I can't think of a way to do that without requiring all readers to acquire two locks. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How to go about. On read/write locks

2009-04-06 Thread Carl Banks
and not adding or removing them, Diez is correct. (Someone more familiar with dict internals might want to verify.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: A design problem I met again and again.

2009-04-03 Thread Carl Banks
a() session.stop() Any methods that are callable any time, you can retain in the big class, or put in a base class of all the sessions. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 382: Namespace Packages

2009-04-02 Thread Carl Banks
hat we'll start seeing all kinds of packages with names like: com.dusinc.sarray.ptookkit.v_1_34_beta.btree.BTree The current lack of global package namespace effectively prevents bureaucratic package naming, which in my mind makes it worth the cost. However, I'd be willing to believe th

Re: A design problem I met again and again.

2009-04-02 Thread Carl Banks
ve a problem. There's nothing wrong with large classes per se, it's just a red flag. If you have all these functions that really all operate on only one piece of data, and really all do different things, then a large class is fine. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python for loop

2009-04-02 Thread Carl Banks
On Apr 1, 11:28 pm, Hrvoje Niksic wrote: > 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

Re: python for loop

2009-04-01 Thread Carl Banks
ty of zero actually mean? (That's a sincere question.) I think people were being facetious. To me the first item in the list is x[0]--ordinal does not match cardinal. However, I don't use ordinals much when talking about list items; I'll say item 2, not third item. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python for loop

2009-04-01 Thread Carl Banks
#x27;radd', 'rmul': >         exec "def __%s__(*r): return List1(list.__%s__(*r))" % (op, op) > > l1 = List1(range(10)) > l2 = List1("Python rules") > > I'll let you play with l1 and l2. If I were your boss and you ever pulled something like this, your ass would be so fired. 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. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Beazley on Generators

2009-04-01 Thread Carl Banks
ty to run coroutines in Matlab would make my working life a lot easier right now. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: A design problem I met again and again.

2009-04-01 Thread Carl Banks
em calls, but never mind that. Ordinarily a bunch of functions operating on common data should be organized as a class.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python for loop

2009-04-01 Thread Carl Banks
On Apr 1, 7:08 am, Lada Kugis wrote: > On Wed, 1 Apr 2009 00:40:17 -0700 (PDT), Carl Banks > > > > > > wrote: > > >Lada, > > >I am also an engineer, and I can tell your idea of intuitive is not > >universal, even among engineers.  I certainly do not

Re: python for loop

2009-04-01 Thread Carl Banks
ulled when interfacing C to Fortran. Python is zero-based, and you are going to have a much better experience if you don't fight it. I assure you that it is really not that hard to cope with indices being off by one from what you have written down. Really. I have to interface two lang

Re: Python Goes Mercurial

2009-04-01 Thread Carl Banks
n-dev was so severe GvR backtracked on his decision. Trying to appease a least common denominator, he changed his mind and Python is going with SCCS instead. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Carl Banks
On Mar 31, 6:39 pm, Kay Schluehr wrote: > On 1 Apr., 00:38, Carl Banks wrote: > > > On Mar 31, 12:08 pm, Kay Schluehr wrote: > > > > > And your proposal is? > > > > I have still more questions than answers. > > > That's obvious. >

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Carl Banks
to make sweeping negative judgments once you have the answers, though.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: please include python26_d.lib in the installer

2009-03-31 Thread Carl Banks
On Mar 31, 12:50 pm, Compie wrote: > On 27 mrt, 17:01, Carl Banks wrote: > > > OTOH, it's possible that SWIG and Python just happen to use the same > > macro to indicate debugging mode.  So I think you raise a valid point > > that this can be problematic.  Perhaps so

Re: Any way to use a range as a key in a dictionary?

2009-03-27 Thread Carl Banks
On Mar 27, 1:06 pm, Duncan Booth wrote: > Carl Banks wrote: > > On Mar 27, 11:20 am, Paul Rubin <http://phr...@nospam.invalid> wrote: > >> Carl Banks writes: > >> > >      if x in theDict: > >> > >           print x, v > > >> &

Re: Any way to use a range as a key in a dictionary?

2009-03-27 Thread Carl Banks
On Mar 27, 11:20 am, Paul Rubin <http://phr...@nospam.invalid> wrote: > Carl Banks writes: > > >      if x in theDict: > > >           print x, v > > > Where does v come from? > > Oops, pasted from original.  Meant of course "print x, theDict[x]"

Re: please include python26_d.lib in the installer

2009-03-27 Thread Carl Banks
e macro to indicate debugging mode. So I think you raise a valid point that this can be problematic. Perhaps something like _Py_DEBUG should be used instead. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Any way to use a range as a key in a dictionary?

2009-03-27 Thread Carl Banks
that the OP asked about what to do with the the other 65526 values suggests that he only wanted to use intervals to fill in the gaps between meaningful values (thus having complete coverage over the 16-bit integer range). An interval tree would not be a good approach for that situation. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Any way to use a range as a key in a dictionary?

2009-03-26 Thread Carl Banks
;w", 4363: "n", 8953: "k" } d.get(1) -> "s" d.get(56) -> "w" d.get(10) -> None d.get(10,"x") -> "x" Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-25 Thread Carl Banks
A) == 0" test and no other. This is to allow interaction with numpy, which doesn't work with the "if not A" test. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-25 Thread Carl Banks
of generators, but I now find that > those will have boolean value 'true' whether or not they have > something to generate, so they will go wrong under either method. Yes, but notice that one of them goes wrong by raising an exception, whereas the other goes wrong by failing silently

Re: What way is the best to check an empty list?

2009-03-25 Thread Carl Banks
27;t need to do something else in the case of no items. But in that case you have no choice but to iterate and see if any items are produced. There are some iterables for which no if-test at all works. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Relative Imports, why the hell is it so hard?

2009-03-25 Thread Carl Banks
On Mar 25, 1:07 am, Kay Schluehr wrote: > On 25 Mrz., 05:56, Carl Banks wrote: > > > > > > > On Mar 24, 8:32 pm, Istvan Albert wrote: > > > > On Mar 24, 9:35 pm, Maxim Khitrov wrote: > > > > > Works perfectly fine with relative imports. >

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Carl Banks
d at least it has the blessing of the language designers so it won't unceremoniously break at some point. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: pickle.load() extremely slow performance

2009-03-20 Thread Carl Banks
f = open('dirlisting.dat','rb') try: f.seek(0,2) size = f.tell() f.seek(0,0) m = mmap.mmap(f.fileno(),size,access=mmap.ACCESS_READ) try: dir_listing = pickle.loads(m) finally: m.close() finally: f.close() Pickling the output left as an exercise. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem--Extending the behavior of an upstream package

2009-03-10 Thread Carl Banks
On Mar 10, 9:33 pm, a...@pythoncraft.com (Aahz) wrote: > In article > <60848752-2c3f-4512-bf61-0bc11c919...@i20g2000prf.googlegroups.com>, > Carl Banks   wrote: > > > > >The problem comes when a different part of the upstream package also > >subclasses or creat

Re: "/a" is not "/a" ?

2009-03-09 Thread Carl Banks
hat you can avoid ever having to use the "is" operator, be my guest. As for me, I do program in the sort of areas where identity testing is common, and I don't care to define ids just to test for identity alone, so for me "is" is useful. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: wxPython fast and slow

2009-03-08 Thread Carl Banks
On Mar 8, 12:35 pm, iu2 wrote: > On Mar 8, 1:42 pm, Carl Banks wrote: > > > > > On Mar 8, 1:52 am, iu2 wrote: > > > > On Mar 6, 6:52 pm, Mike Driscoll wrote: > > > > > ... > > > > Can you post a sample application so we can try to figure

Re: wxPython fast and slow

2009-03-08 Thread Carl Banks
med_callback_of_some_sort( self.draw_frame,0.005) def draw_frame(self): self.square.SetPosition((self.square_pos, 30)) self.square_pos += 1 if self.square_pos < 200: wx.set_timed_callback_of_some_sort( self.draw_frame,0.005) As for why it works fine in PyScripter but not when started from Explorer, well, let's just say that when you abuse callbacks like you did, you shouldn't expect reasonable behavior. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: speeding up reading files (possibly with cython)

2009-03-08 Thread Carl Banks
#x27;) # do stuff with split_values finally: gc.enable() Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: RELEASED Python 3.1 alpha 1

2009-03-07 Thread Carl Banks
schedule details: > >      http://www.python.org/dev/peps/pep-0361/ I see that Brett Canon's importlib has finally made it into Python standard library. Congrats there (if you still read this list), I am struggling with Python's arcane import semantics (for something ridiculously silly) now and I feel your pain. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: how to prevent python import from looking into the current directory

2009-03-06 Thread Carl Banks
inction between “absolute” and > “relative” imports http://www.python.org/dev/peps/pep-0328/>. He might, but it won't help him with his problem. Relative imports aren't involved in this situation. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: "/a" is not "/a" ?

2009-03-06 Thread Carl Banks
e same object they created themselves, or is an object guaranteed by a library or the langauge to never change, irrespective of whether the object is mutable or not. At no point on the learning curve is the distinction of when to use "is" or not ever mutability. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

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

2009-03-05 Thread Carl Banks
and values() match in order) Just as an example, if you are using a third-party library function that demands side-by-side inputs in respective lists, you could make use of it. That's not a good interface, IMHO, but if you have to use such a library, and you want to supply key-value pairs, then you can use keys and values seperately. populate_database(d.keys(),d.values()) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: random module gives same results across all configurations?

2009-03-04 Thread Carl Banks
nned fake-random sequence. Sometimes random sequences are used to generate data, and you might want to give the user power to regenerate the same data by seeding the PRNG with the same seed. (A well-known example is "Free Cell", where the game number is just an RNG seed.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: random module gives same results across all configurations?

2009-03-03 Thread Carl Banks
ou can subclass random.Random to do it. (See the source code to random.py for example.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What's so wrong about execfile?

2009-03-02 Thread Carl Banks
On Mar 2, 8:43 am, John Nagle wrote: > Carl Banks wrote: > > On Feb 27, 7:21 pm, Sammo wrote: > >> Given that execfile has been removed in py3k, I want to understand > >> exactly why. > > >> Okay, I get that execfile is bad from the following thread:

Re: setting PYTHONPATH to override system wide site-packages

2009-02-28 Thread Carl Banks
On Feb 28, 9:18 pm, per wrote: > On Feb 28, 11:53 pm, per wrote: > > > > > On Feb 28, 11:24 pm, Carl Banks wrote: > > > > On Feb 28, 7:30 pm, per wrote: > > > > > hi all, > > > > > i recently installed a new version of a package usi

Re: setting PYTHONPATH to override system wide site-packages

2009-02-28 Thread Carl Banks
ot; at your csh prompt? Is the module you're trying to import there? You approach should work. These are just suggestions on how to diagnose the problem; we can't really help you figure out what's wrong without more information. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: OTish: convince the team to drop VBScript

2009-02-28 Thread Carl Banks
self well, and it might have even been a real issue. Python is not, unfortunately, the easiest language to deploy applications in. I don't think there is any deployment difficulty so great that I would ever chose VBscript, but opinions might differ. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: What's so wrong about execfile?

2009-02-27 Thread Carl Banks
d safer ways to do this (use getattr, setattr, globals, and locals built-ins). And if you find yourself using them a lot, it's a red flag that you should be using dicts instead. - Don't ever pass any data to exec or eval that you didn't either write, or thoroughly inspect, yourself. Especially don't pass it any data you received over the network. You have to be the super extreme expert that Steven described, and own a lot of liability insurance, befor you can do that. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: A tale of two execs

2009-02-24 Thread Carl Banks
if I wanted that type of > functionality I would have to use os.dup, fork, exec, which meant > reinventing the wheel.  I overcame the issue of dealing with msvcrt > and _subprocess under windows by requiring python24 or greater under > windows. Distributing the interpreter doesn't

Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Carl Banks
de I don't need, too, and I never concern myself with them, so it's probably a misplaced irk. Go ahead and use it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: To unicode or not to unicode

2009-02-21 Thread Carl Banks
On Feb 19, 6:57 pm, Ron Garret wrote: > I'm writing a little wiki that I call µWiki.  That's a lowercase Greek > mu at the beginning (it's pronounced micro-wiki).  It's working, except > that I can't actually enter the name of the wiki into the wiki itself > because the default unicode encoding on

Re: numpy.memmap advice?

2009-02-19 Thread Carl Banks
On Feb 19, 10:36 am, Lionel wrote: > On Feb 19, 9:51 am, Carl Banks wrote: > > > > > > > On Feb 19, 9:34 am, Lionel wrote: > > > > On Feb 18, 12:35 pm, Carl Banks wrote: > > > > > On Feb 18, 10:48 am, Lionel wrote: > > >

Re: numpy.memmap advice?

2009-02-19 Thread Carl Banks
On Feb 19, 10:00 am, sturlamolden wrote: > On 19 Feb, 03:13, Carl Banks wrote: > > > The offset parameter of mmap itself would be useful to map small > > portions of gigabyte-sized files, and maybe numpy.memmap can take > > advantage of that if the user passes an offset

Re: numpy.memmap advice?

2009-02-19 Thread Carl Banks
On Feb 19, 9:34 am, Lionel wrote: > On Feb 18, 12:35 pm, Carl Banks wrote: > > > > > > > On Feb 18, 10:48 am, Lionel wrote: > > > > Thanks Carl, I like your solution. Am I correct in my understanding > > > that memory is allocated

Problem--Extending the behavior of an upstream package

2009-02-18 Thread Carl Banks
n--or not--I'll post some things I've considered, including a few approaches I've actually implemented. But I don't want to taint everyone's ideas just yet.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

<    3   4   5   6   7   8   9   10   11   12   >