Re: Do more imported objects affect performance

2008-12-02 Thread Nick Craig-Wood
bar.yourclass import YourClass If this spelling causes local name clashes, then spell them import myclass import foo.bar.yourclass and use "myclass.MyClass" and "foo.bar.yourclass.YourClass" Ultimately it is a matter of taste I think! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-02 Thread Nick Craig-Wood
Slaunger <[EMAIL PROTECTED]> wrote: > On 1 Dec., 16:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > I wouldn't use __getattr__ unless you've got lots of attributes to > > overload. ?__getattr__ is a recipe for getting yourself into trouble >

Re: Emacs vs. Eclipse vs. Vim

2008-12-01 Thread Craig Allen
I would never tell someone what editor to use in the same way I wouldn't tell someone what religion to believe in. Which is to say, I would tell my kids or other trusting soul... I used emacs for years, I was eventually convinced to start using nedit, which is quite nice. For an IDE, which I need

Re: How to instantiate in a lazy way?

2008-12-01 Thread Nick Craig-Wood
e first time it will populate itself. If None is a valid value for data then make a sentinel, eg class PayloadOnDemand(object): sentinel = object() def __init__(self, a_file, a_file_position): self._data = self.sentinel self.f = a_file self.file_position = a_file_position @property def data(self): if self._data is self.sentinel: self._data = self.really_read_the_data() return self._data -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Emacs vs. Eclipse vs. Vim

2008-12-01 Thread Nick Craig-Wood
im have all these features, don't know about Eclipse. In fact if I had to pick one feature that a programmer's editor must have it would be keyboard macros. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Do more imported objects affect performance

2008-12-01 Thread Nick Craig-Wood
uot; And here is the test again, actually calling something with the same difference in execution speed :- $ python -m timeit -s 'from os import nice' 'nice(0)' 100 loops, best of 3: 1.21 usec per loop $ python -m timeit -s 'import os' 'os.nice(0)' 100 loops, best of 3: 1.48 usec per loop -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: distinct fcntl flags for stdin and stdout

2008-12-01 Thread Nick Craig-Wood
e 'r' at 0xb7d03020> fd=0 STDOUT ', mode 'w' at 0xb7d03068> fd=1 os.O_NDELAY=0800 stdin: flag=0002 stdout: flag=8001 setting non blocking on stdin... stdin: flag=0802 stdout: flag=8001 removing non blocking on stdin... stdin: flag=0002 stdout: flag=8001 So I suspect your result is because stdin and stdout refer to the same file (eg /dev/tty0 or /dev/pts/25). No idea whether this is correct behaviour or not though! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a directory file descriptor?

2008-11-26 Thread Nick Craig-Wood
opendir(".") print "dir_p = %r" % dir_p dir_fd = dirfd(dir_p) print "dir_fd = %r" % dir_fd print "closed (rc %r)" % closedir(dir_p) Which prints on my linux machine dir_p = dir_fd = 3 closed (rc 0) I don't know why os doesn't wrap - opendir, cl

Re: recommended __future__ imports for 2.5?

2008-11-25 Thread Nick Craig-Wood
'm still waiting to hear that > > from __past__ import division > > will become a reality... ;-) I think that is called using // instead of / which works without any from __future__ import from python 2.2 onwards. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Django Latex Permissions Problem

2008-11-25 Thread Nick Craig-Wood
is directory. I have a feeling that > pdflatex is trying to generate files using some weird access > credentials that dont have access to /tmp/pdfscratch{id} Unlikely - it takes root to change user and I wouldn't have thought any of the files would be setuid. Try chdir to /tmp/pdfscrat

Re: Finding the instance reference of an object

2008-11-19 Thread Craig Allen
I've just come to the conclusion it's not possible to call functions in python, to do so is undefined and indeterminate, like dividing by zero. Henceforth no calling functions for me as clearly it's the devil's playground. -- http://mail.python.org/mailman/listinfo/python-list

Re: compressed serialization module

2008-11-19 Thread Nick Craig-Wood
greg <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > (Note that basic pickle protocol is likely to be more compressible > > than the binary version!) > > Although the binary version may be more compact to > start with. It would be interesting to compar

Re: setting permissions to a file from linux.

2008-11-18 Thread Nick Craig-Wood
hmod(0775, "directory") rather than os.chmod(775, "directory") (leading 0 implies octal) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: compressed serialization module

2008-11-18 Thread Nick Craig-Wood
ot;, "rb") >>> M = pickle.load(f) >>> f.close() >>> M == L True >>> (Note that basic pickle protocol is likely to be more compressible than the binary version!) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-17 Thread Craig Allen
> >> * Do all objects have values? (Ignore the Python > >> docs if necessary.) > > > If one allows null values, I am current thinking yes. > > I don't see a difference between a "null value" > and not having a value. > I think the difference is concrete... an uninitialized variable in C has no va

Re: compressed serialization module

2008-11-17 Thread Nick Craig-Wood
protool. Here's a silly example: > > >>> len(pickle.dumps([1,2,3], pickle.HIGHEST_PROTOCOL)) > 14 > >>> len(pickle.dumps([1,2,3], 0)) > 18 Or even >>> L = range(100) >>> a = pickle.dumps(L) >>> len(a) 496 >>>

Re: Best practise hierarchy for user-defined exceptions

2008-11-17 Thread Nick Craig-Wood
have_overlooked() > do_something_where_I_know_a_ValueError_can_be_raised() > catch ValueError: > handle_the_anticipated_ValueError_from_std_lib() > finally: > > > I will not notice that it was an unanticpated condition in my own > code, which cause

Re: C Function Pointer Wrapping Example not working

2008-11-17 Thread Nick Craig-Wood
a-b; }; >int mymul( int a, int b ) { return a*b; }; > } > > Traceback (most recent call last): >File "", line 1, in >File "test.py", line 7, in > import _test > ImportError: ./_test.so: undefined symbol: binary_op Nowhere in your code is the definition of binary_op - that is why you get a linker error. Is it defined in another C file? If so you need to link it with the swig wrapper before you make the .so -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Good practice when writing modules...

2008-11-16 Thread Nick Craig-Wood
ting things into your local namespace is also the quickest, but that isn't why I do it! There are arguments against doing this, which I'm sure you'll hear shortly ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: C Function Pointer Wrapping Example not working

2008-11-16 Thread Nick Craig-Wood
a look at the code SWIG generates and see if it puts some extern "C" in and match what it does in your code. We used to use SWIG in for python embedding in our C++ project, but we found that using ctypes is a lot easier. You just write C .so/.dll and use ctypes to access them. You can do callbacks and embedding python like this too. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to use a contiguous memory location of n bytes in python

2008-11-14 Thread Nick Craig-Wood
m mmap import mmap >>> a = mmap(-1, 10) >>> a[0] '\x00' >>> a[0] = 'z' >>> a[9] '\x00' >>> a[9]='q' >>> a[9] 'q' >>> del a -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: duck-type-checking?

2008-11-13 Thread Craig Allen
> since both are equally informative when it comes to tracing the faulty > assignment. > steve, they are not equally informative, the assertion is designed to fire earlier in the process, and therefore before much mischief and corruption can be done compared to later, when you happen to hit the m

Re: duck-type-checking?

2008-11-13 Thread Craig Allen
> This is better achived, not by littering the functional code unit with > numerous assertions that obscure the normal function of the code, but > rather by employing comprehensive unit tests *separate from* the code > unit. that doesn't seem to work too well when shipping a library for someone el

Re: Finding the instance reference of an object

2008-11-12 Thread Craig Allen
> arguably even older than that to Lisp. > Firstly, thanks to those that have responded to my part in this debate, I have found it very informative and interesting as I have the entire thread. However, with regard to comments that I led myself astray, I want to reiterate the one thing I find det

Re: why does this call to re.findall() loop forever?

2008-11-10 Thread Nick Craig-Wood
es. Eg http://bugs.python.org/issue1515829 I'd attack this problem using beatifulsoup probably rather than regexps! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-11-04 Thread Craig Allen
On Nov 4, 11:06 am, Joe Strout <[EMAIL PROTECTED]> wrote: > On Nov 4, 2008, at 7:42 AM, Craig Allen wrote: > > > coming from C/C++ Python seemed to me call by reference, for the > > pragmatic reason you said, modificaitons to function arguments do > > affect th

Re: Finding the instance reference of an object

2008-11-04 Thread Craig Allen
> > If the assert statement fails (and it does), then no copy was made and > Python is not call-by-value. > > So Python is not call-by-value, and it's not call-by-reference, so ... > either Python doesn't exist, or it uses a different calling convention. > coming from C/C++ Python seemed to me cal

Re: PYTHON WORKING WITH PERL ??

2008-11-03 Thread Craig Allen
> article:http://www.linuxjournal.com/article/3882 even if it is by Eric Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: PYTHON WORKING WITH PERL ??

2008-11-03 Thread Craig Allen
> article:http://www.linuxjournal.com/article/3882 interesting read, thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Craig Allen
> > Care to say more about what they are, not what they're like? > I'm not the OP and I may be biased by C++, I can imagine the complaints when I say, classes are just structures with function members for working on the structure. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to examine the inheritance of a class?

2008-10-24 Thread Craig Allen
> Thank you, Chris. Class.__bases__ is exactly what I wanted to see. > And I thought I had tried isinstance(), and found it lacking -- but I > just tried it again, and it does what I hoped it would do. While isinstance is no doubt the proper way to access this information, you may have run into

Re: How to examine the inheritance of a class?

2008-10-24 Thread Craig Allen
> > Developer. NOT User. I go around and around on this issue, and have ended up considering anyone using my code a user, and if it's a library or class system, likely that user is a programmer. I don't really think there is a strong distinction... more and more users can do sophisticated configu

Re: dictionary

2008-10-24 Thread Craig Allen
when I was a baby programmer even vendors didn't have documentation to throw out... we just viewed the dissassembeled opcodes to find out how things worked... we never did find out much but I could make the speak click, and we were happy with it. -- http://mail.python.org/mailman/listinfo/python-li

Re: IDE Question

2008-10-15 Thread Craig Allen
it's commercial, but I like WingIDE enough to recommend... I run it on Linux and Mac and it works well. -craig On Oct 15, 7:19 am, "Steve Phillips" <[EMAIL PROTECTED]> wrote: > Hi All, > I am just wondering what seems to be the most popular IDE. The reason > I ask

Re: Python 2.6, GUI not working on vista?

2008-10-09 Thread Craig Allen
as a 20 year observer of microsoft, I have to say this is not amazing at all... and I do not mean that as a random put down of Microsoft. Microsoft often develops things in response to demand... but they don't always fit in their system well, and thus are not really used in the spirit of the demand

Re: Tuple parameter unpacking in 3.x

2008-10-04 Thread Nick Craig-Wood
gt; >>> So just remove the parentheses and you'll be fine. I have to say I prefer named functions, but I haven't done much functional programming def f(ai, bi): return ai * bi ci.addCallback(f) def f(i, s): return field(i + 1), s map(f, enumerate(si))

Re: Advice for a replacement for plone.

2008-09-30 Thread Nick Craig-Wood
jangoproject.com/en/dev/ref/contrib/flatpages/ A bit more of a learning curve but you'll definitely be in charge. Somebody used to Django could set up a flatpages site in 5 minutes probably! It will take you a couple of hours the first time though. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Eggs, VirtualEnv, and Apt - best practices?

2008-09-25 Thread Nick Craig-Wood
to build an rpm and converting to a .deb. The app is then tested with "etch" or whatever. If easy_install could build debs that would be really helpful! > Suggestions on build/rollout tools (like zc.buildout, Paver, etc) would > also be appreciated. Use setup.py to build in

Re: Comparing float and decimal

2008-09-25 Thread Nick Craig-Wood
getcontext().prec += 1 finally: setcontext(oldcontext) print "float(0.1) is", floatToDecimal(0.1) ---- Prints this float(0.1) is 0.155511151231257827021181583404541015625 On my platform Python 2.5.2 (r252:60911, Aug 8 2008, 09:22:44), [GCC 4.3.1] on linux2 Linux 2.6.26-1-686 Intel(R) Core(TM)2 CPU T7200 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python style: exceptions vs. sys.exit()

2008-09-24 Thread Craig Allen
> Why, yes, I am wearing my BOFH hat. How could you tell? > > -- > Tim Rowe evil, but I think you may be a BSEFH, not a BOFH. -- http://mail.python.org/mailman/listinfo/python-list

Re: PyRun_SimpleFile() crashes

2008-09-24 Thread Nick Craig-Wood
that you actually opened the file, ie file_1 != 0. This might be relevant http://effbot.org/pyfaq/pyrun-simplefile-crashes-on-windows-but-not-on-unix-why.htm -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I use a PyObject in C++?

2008-09-24 Thread Nick Craig-Wood
dn't read result from MyModule.SubModule.my_function"); goto out; } my_result = strdup(my_result); /* keep in our own memory */ out:; Py_XDECREF(result); Py_XDECREF(module); return my_result; } -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing float and decimal

2008-09-24 Thread Nick Craig-Wood
t the exact representations leak out anyway (which causes a lot of FAQs in this list), eg >>> 0.1 0.10001 IMHO We should put the exact conversions in for floats to Decimal and Fraction by default and add a new section to the FAQ! In that way people will see floats for what the

Re: Python style: exceptions vs. sys.exit()

2008-09-23 Thread Craig Allen
> The > question is: should the library function be able to just dump to > sys.exit() with a message about the error (like "couldn't open this > file"), or should the exception propagate to the calling program which > handles the issue? > my view is that the exceptions are there precisely to tell

Re: Why are "broken iterators" broken?

2008-09-23 Thread Craig Allen
I'm interested what others think of this because at first I couldn't get it... I have an object which can iterate over its parts... and at first I thought, what? I'm supposed to create a new object every time the user needs to iterate the contents? In the end I interpreted that statement as if "un

Re: What do you call a class not intended to be instantiated

2008-09-23 Thread Craig Allen
> > > Usegrammers? > usegrammers are just those that use grammars, but misspell it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Not fully OO ?

2008-09-23 Thread Craig Allen
> if they want to, but it is *fully* OO in that it includes everything > required to do OO. But maybe the original blogger meant by "fully OO" > what I mean by "Pure OO"? it seems to me this is what was meant... pure OO, AND forced to use it. My personal feeling is that python is multiparadigmed

Re: Not fully OO ?

2008-09-22 Thread Craig Allen
It is clear to me that Python is a multiparadigmed object oriented language. It is clearly possible to write procedural code... that is, Python does not force object oriented syntax or concepts on you and insist you define everything in such a structure. Is the OO it allows full OO, I think so, an

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Craig Allen
> Snce when are "users" ever involved > in programming problems or programming > languages ? > since the begining, the first users are programmers, users of your libraries. -- http://mail.python.org/mailman/listinfo/python-list

Re: dict slice in python (translating perl to python)

2008-09-12 Thread Nick Craig-Wood
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 11 Sep 2008 03:36:35 -0500, Nick Craig-Wood wrote: > > > As an ex-perl programmer and having used python for some years now, I'd > > type the explicit > > > > v1,v2,v3 = mydict['one

Re: Adding environment variables to bash.

2008-09-11 Thread Craig Allen
On Sep 11, 10:25 am, nntpman68 <[EMAIL PROTECTED]> wrote: > >> doesn't exactly work for Python scripts, though: > > >> $ cat env.py > >> #!/usr/bin/env python > >> import os > >> os.environ["TEST"] = "hello" > > >> $ . ./env.py && env | grep TEST > >> import: unable to open X server `'. > >> bash:

Re: dict slice in python (translating perl to python)

2008-09-11 Thread Nick Craig-Wood
= mydict['two'] v3 = mydict['two'] Either is only a couple more characters to type. It is completely explicit and comprehensible to everyone, in comparison to v1,v2,v3 = [ mydict[k] for k in ['one','two','two']] # 52 chars v1,v2,v3 = [

Re: Simple UDP server

2008-09-10 Thread Nick Craig-Wood
#x27;d use select and run asynchronously. http://docs.python.org/lib/module-select.html Actually if I really had to do this I'd use twisted. Right tool for the job! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to record audio from Python on Mac?

2008-09-09 Thread Craig Allen
I want to do this as well, and also some other audio processing via python. I have not tried yet, but much of my research points to pyaudio, PortAudio bindings for python, which is supposed to be multi- platform including Mac OS X, but as I say, I've not tried it yet. Related to this are some exa

Re: creating an (inefficent) alternating regular expression from a list of options

2008-09-09 Thread Nick Craig-Wood
orting it to python but looking at the regular expressions made me feel weak at the knees ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: use str as variable name

2008-09-04 Thread Nick Craig-Wood
27; > a.__argname__= new_value Not quite sure what the above is supposed to achieve > rather than : > > if arg == 'height': >a.height = new_value > elif arg == 'width'; >a.width = new_value > > Can I do this with python ? How ? se

Re: Numeric literal syntax (was: Py 2.6 changes)

2008-09-02 Thread Nick Craig-Wood
inimize programming errors, simple code mistakes > too. And perl also *ducks* -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: When to use try and except?

2008-08-29 Thread Craig Allen
On Aug 29, 7:23 am, cnb <[EMAIL PROTECTED]> wrote: > If I get zero division error it is obv a poor solution to do try and > except since it can be solved with an if-clause. > > However if a program runs out of memory I should just let it crash > right? Because if not then I'd have to write exceptio

Re: Is my thinking Pythonic?

2008-08-21 Thread Craig Allen
generally, I name the members in the Class definition and set them to None there... class Car: speed = None brand = None def __init__(): self.speed = defaultspeed #alternately, and more commonly, get this speed as a initializer argument self.brand = defaultbrand That solves

Re: export sites/pages to PDF

2008-08-12 Thread Nick Craig-Wood
to script that with python. See here for some more info on dcop :- http://www.ibm.com/developerworks/linux/library/l-dcop/ -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A Question about ctypes and a function f(void **)

2008-08-11 Thread Nick Craig-Wood
c_char_p(136692916) >>> s.value 'hello' >>> or use ctypes.memmove to copy the data out to somewhere else. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with global variables

2008-08-09 Thread Nick Craig-Wood
--- class Test(object): def __init__(self): self.foo = [] def goo(self): self.foo.append(2) def moo(self): print self.foo test = Test() >>> from test2 import test >>> test.foo [] >>> test.goo() >>> test.foo [2] >>> test.moo() [2] >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: when does the GIL really block?

2008-08-04 Thread Craig Allen
On Aug 1, 2:28 pm, John Krukoff <[EMAIL PROTECTED]> wrote: > On Thu, 2008-07-31 at 18:27 -0700, Craig Allen wrote: > > I have followed the GIL debate in python for some time. I don't want > > to get into the regular debate about if it should be gotten rid of > >

Re: Interconvert a ctypes.Structure to/from a binary string?

2008-08-04 Thread Nick Craig-Wood
a.x 0 >>> memmove(addressof(a), packet, sizeof(a)) 3083811008L >>> a.x 258 I think the second of those methods is promoted by the ctypes documentation. I'm not sure about the lifetimes of the .contents in the first method! And the reverse >>>

Re: when does the GIL really block?

2008-08-01 Thread Craig Allen
On Aug 1, 12:06 pm, Rhamphoryncus <[EMAIL PROTECTED]> wrote: > On Jul 31, 7:27 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > > > > > I have followed the GIL debate in python for some time. I don't want > > to get into the regular debate about if it should

when does the GIL really block?

2008-07-31 Thread Craig Allen
I have followed the GIL debate in python for some time. I don't want to get into the regular debate about if it should be gotten rid of (though I am curious about the status of that for Python 3)... personally I think I can do multi-threaded programming well, but I also see the benefits of a multi

Re: ActiveState Code (the new Python Cookbook) has been launched

2008-07-28 Thread Nick Craig-Wood
n the old site! Mind telling us how it is implemented? I'm guessing python/django by the url and the fact that you have python stuff on your home pages but I could be wrong! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes - unloading implicitly loaded dlls

2008-07-28 Thread Nick Craig-Wood
ll, but I haven't found any way of doing that. Can anyone offer > my some suggestions? Or, am I S.O.L.? You could try loading C explicitly with ctypes.LoadLibrary() before loading A, then you'll have a handle to unload it before you load B. I think I'd probably split the c

Re: Python Written in C?

2008-07-21 Thread Craig Allen
it's clear to me that the perfect language should exist a priori, coming to being causa sui. Having to actually implement a language is disgusting and unnatural. -- http://mail.python.org/mailman/listinfo/python-list

Re: singletons

2008-07-18 Thread Craig Allen
On Jul 17, 9:04 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Jul 16, 11:20 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > > > Hey, forgive me for just diving in, but I have a question I was > > thinking of asking on another list but it really is a general question > >

Re: singletons

2008-07-17 Thread Craig Allen
On Jul 17, 2:15 am, Uwe Schmitt <[EMAIL PROTECTED]> wrote: > On 17 Jul., 00:20, Craig Allen <[EMAIL PROTECTED]> wrote: > > > > > I have several classes in our system which need to act like > > singletons, they are libraries of data classifications, and other

Re: singletons

2008-07-17 Thread Craig Allen
On Jul 16, 7:01 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED] central.gen.new_zealand> wrote: > In message > <[EMAIL PROTECTED]>, Craig > > Allen wrote: > > ... the ideal is still that > > > tl = TehLibrary() would always return t

Re: singletons

2008-07-16 Thread Craig Allen
al is still that tl = TehLibrary() would always return the same object. -craig On Jul 16, 2:00 pm, castironpi <[EMAIL PROTECTED]> wrote: > On Jul 16, 5:20 pm, Craig Allen <[EMAIL PROTECTED]> wrote: > > > > > Hey, forgive me for just diving in, but I have a question I was &g

singletons

2008-07-16 Thread Craig Allen
Hey, forgive me for just diving in, but I have a question I was thinking of asking on another list but it really is a general question so let me ask it here. It's about how to approach making singletons. Background: I've been programming in python seriously for about a year now, maybe a little lon

Re: Why is recursion so slow?

2008-07-02 Thread Nick Craig-Wood
Rich Harkins <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > [snip] > > By definition any function in a functional language will > > always produce the same result if given the same arguments, so you can > > memoize any function. > > > > Ah, s

Re: Getting sorting order

2008-07-01 Thread Nick Craig-Wood
passing len(x) arguments to zip. So if x = [1,2,3,4] zip(*x) == zip(1,2,3,4) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is recursion so slow?

2008-07-01 Thread Nick Craig-Wood
e here for a python memoize which makes the recursive algorithm run fast... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52201 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: C++ or Python

2008-06-28 Thread Nick Craig-Wood
add a bit of C/C++ if some part of it was running too slowly. If there were existing C/C++ libraries then I'd use ctypes to interface with them. I don't think I ever want to start another large C++ app - been there, done that, got the (mental) scars to prove it ;-) All my humble opinio

Re: Help me on Backspace please

2008-06-26 Thread Craig Radcliffe
Something like this might do the trick: import re f = open("file.txt") old_text = f.readlines() f.close() new_text = [re.sub(r'.\b', '', i) for i in old_text] f = open("file_modified.txt", "w") f.writelines(new_text) I don't know how necessary the separate read and writes are, but it'll be good

Re: calling a .exe from Python

2008-06-25 Thread Nick Craig-Wood
evidentemente.yo <[EMAIL PROTECTED]> wrote: > On 24 jun, 14:32, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Probably what you want is this... > > > > from subprocess import call > > > > rc = call(["mypath/myfile.exe",arg1,arg2])

Re: shorten this: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":

2008-06-25 Thread Nick Craig-Wood
t creates two lists then joins them then throws the whole lot away! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: calling a .exe from Python

2008-06-24 Thread Nick Craig-Wood
robably what you want is this... from subprocess import call rc = call(["mypath/myfile.exe",arg1,arg2]) rc will contain the exit status See the subprocess module for more things you can do -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 vs Perl 6

2008-06-24 Thread Nick Craig-Wood
) Another VM to run python would be nice of course, but we already have jython, ironpython and pypy. Both jython and ironpython use JIT, pypy can compile to native code and you can use psyco for JIT code also in normal python. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig

Re: binary representation of an integer

2008-06-24 Thread Nick Craig-Wood
out.append(hex_to_binary[hex_digit]) ... out = "".join(out).lstrip("0") ... if out == "": ... out = "0" ... return out ... >>> to_binary(0) '0' >>> to_binary(10) '1010' >>> to_binary(100) '1100100' >>> to_binary(1000) '101000' >>> to_binary(1000) '1000101011000111001000110100100010001000' But don't try this ;-) >>> to_binary(-1) Traceback (most recent call last): File "", line 1, in File "", line 4, in to_binary KeyError: '-' -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: MD5 hash for url and utf unicode converting to ascii

2008-06-24 Thread Nick Craig-Wood
t;>> value '\xc9\x11}\x8f?64\x83\xf3\xcaPz\x1d!\xddd' >>> value.encode("hex") 'c9117d8f3f363483f3ca507a1d21dd64' >>> long(value.encode("hex"), 16) 267265642849753964132104960801656397156L >>> > For unicode encoding, I can do, md5.update(value.encode('utf-8')) to > give me ascii values. Yes that would be fine -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: flock seems very unsafe, python fcntl bug?

2008-06-23 Thread Nick Craig-Wood
if not os.path.exists('aaa'): fd = open('aaa', 'w+') else: fd = open('aaa', 'r+') fcntl.flock(fd,fcntl.LOCK_EX) fd.truncate() fd.write(data) fd.close() def check(): fd = open('aaa', 'r') fcntl.flock(fd,fcntl.LOCK_EX) data = fd.read() fd.close() if data not in ("sausage", "potato"): raise AssertionError("Wrong data %r" % data) if os.path.exists("aaa"): os.unlink("aaa") if len(sys.argv) < 2: print "Syntax: %s " % sys.argv[0] raise SystemExit(1) method = globals()["method_"+sys.argv[1]] if os.fork(): while 1: method("sausage") check() else: while 1: method("potato") check() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: how to export functions by name for ctype

2008-06-23 Thread Nick Craig-Wood
vention. I guess you've compiled your DLL with C++ and the above is a C++ mangled name. Either compile it with C, or export the names in an extern "C" { } block. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to catch StopIteration?

2008-06-17 Thread Nick Craig-Wood
numerate(collatz(13)): ... last = x[:i+1] ... print x[:i+1] ... else: ... last.append(1) ... print last ... [13] [13, 40] [13, 40, 20] [13, 40, 20, 10] [13, 40, 20, 10, 5] [13, 40, 20, 10, 5, 16] [13, 40, 20, 10, 5, 16, 8] [13, 40, 20, 10, 5, 16, 8, 4] [13, 40, 20, 10, 5, 16, 8,

Re: sorted or .sort() ?

2008-06-16 Thread Nick Craig-Wood
expensive than computer time, > after all. Good advice with one caveat: sorted() was only introduced in python 2.4 so if your code must run on earlier versions then use list.sort() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: get keys with the same values

2008-06-12 Thread Nick Craig-Wood
'e'] > 2 : ['c'] > 3 : ['b', 'd'] > 4 : ['f'] > Or use the little understood dict.setdefault method which has been with us from time immemorial... >>> d = {'a' : 1, 'b' : 3, 'c' : 2,'d' : 3,'e' : 1,'f' : 4} >>> dd = {} >>> for k, v in d.items(): ... dd.setdefault(v, []).append(k) ... >>> dd {1: ['a', 'e'], 2: ['c'], 3: ['b', 'd'], 4: ['f']} >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Alternative to Decimal type

2008-06-11 Thread Nick Craig-Wood
.mpq(123,1000) >>> b = gmpy.mpq(12,100) >>> a+b mpq(243,1000) >>> a*b mpq(369,25000) >>> a/b mpq(41,40) >>> It is also *very* fast being written in C. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: mysql to sqlite

2008-06-11 Thread Nick Craig-Wood
which was from MSSQL->MySQL). You'll find that different databases have subtly different ways of doing things (eg autoincrement fields on mysql) so you'll most likely need a custom script anyway. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: _POSIX_C_SOURCE

2008-06-09 Thread Nick Craig-Wood
SOURCE" > redefined > > but if i do > > export C_INCLUDE_PATH=/usr/include/python2.4 > > I do not face any compilation issues. > > I would like to know if there is anything i am missing on this. Do it in your code with #define _POSIX_C_SOURCE instead of the Makefile

Re: Web Crawler - Python or Perl?

2008-06-09 Thread Nick Craig-Wood
but once you do you'll be writing a killer crawler ;-) As for Perl - once upon a time I would have done this with perl, but I wouldn't go back now! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: time.clock() or Windows bug?

2008-06-09 Thread Nick Craig-Wood
Theo v. Werkhoven <[EMAIL PROTECTED]> wrote: > The carbonbased lifeform Nick Craig-Wood inspired comp.lang.python with: > > Theo v. Werkhoven <[EMAIL PROTECTED]> wrote: > >> Output: > >> Sample 1, at 0.0 seconds from start; Output power is: 8.967 dBm >

Re: time.clock() or Windows bug?

2008-06-09 Thread Nick Craig-Wood
Tim Roberts <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > >time.clock() uses QueryPerformanceCounter under windows. There are > >some known problems with that (eg with Dual core AMD processors). > > > >See http://m

Re: time.clock() or Windows bug?

2008-06-08 Thread Nick Craig-Wood
ion layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function. I would have said time.time is what you want to use anyway though because under unix time.clock() returns the elapsed CPU time which is not what you want at all! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to kill a thread?

2008-06-07 Thread Nick Craig-Wood
com/ASPN/Cookbook/Python/Recipe/496960 and http://sebulba.wikispaces.com/recipe+thread2 Read the caveats! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to perform a nonblocking read from a process

2008-06-04 Thread Nick Craig-Wood
L or Expect nor does it require C extensions to be compiled. It should work on any platform that supports the standard Python pty module. The Pexpect interface was designed to be easy to use. You'll never get it to work with subprocess like this because of the buffering. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes, function pointers and a lot of trouble

2008-06-04 Thread Nick Craig-Wood
> dwCreationDisposition, > FILE_ATTRIBUTE_NORMAL, > NULL ); use os.read os.write and os.open which will give you OS handles rather than python file objects, ie I think these are a fairly direct interface to CreatFile etc

<    1   2   3   4   5   6   7   8   9   >