Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Ray
Robert Kern wrote:
> You might be. No one else in the thread is.

What are you saying? That my perception that RoR is mature is wrong? I
never even said that was mine. That was what I got from talking to a
lot of developers whose main language is neither Python nor Ruby, while
I was trying to introduce Python to them. I've always been enthusiastic
about Python and think it'd be nice for a change to be able to work
with it in a project at work instead of at home.

And yes, no one else in this thread, which consists of 6 posts so far,
says so, so how is it even relevant to how other developers perceive
RoR in comparison with Django or Turbogears? You're not making any
sense here.

> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it 
> had
>   an underlying truth."
>-- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random writing access to a file in Python

2006-08-28 Thread Claudio Grondi
Dennis Lee Bieber wrote:
> On 27 Aug 2006 15:06:07 -0700, Paul Rubin 
> declaimed the following in comp.lang.python:
> 
> 
> 
>>I think that's not so bad, though probably still not optimal.  85 GB
>>divided by 18 hours is 1.3 MB/sec, which means if the program is
>>reading the file 8 times, it's getting 10 MB/sec through the Windows
>>file system, which is fairly reasonable throughput.
>>
> 
>   Especially if, as implied, this was on a USB drive 

Don't underestimate external USB drives (I have heard there are great 
differences between them depending on the used controller).

If the file requested is not scattered over the drive due to 
defragmentation and appropriate reading procedure is used I have seen 
(e.g. just yesterday with the 80 Gig file) constant throughput of 28 
MBytes/second what compared to the maximum I have seen on E-IDE of 40 
MBytes/second is not that bad as your posting might suggest.

Thanks to Paul Rubin for the hint on radix sorting (even if coming a bit 
too late). I had used already yesterday this kind of approach in another 
context on the file I was sorting and can therefore estimate the total 
time on my system for such sorting using this method quite well: it will 
take not more than 3 hours (what is a very big improvement compared to 
18 hours). I suppose, that the problem with Windows XP 'sort' is that it 
can't take advantage of the constant record size as there is no option 
available which could be used to pass this hint to it.

"But if you only had to do it once and it's finished now, why do you
still care how long it took?"
Because one of my usual goals going along with doing things like that, 
is to get some feeling for them gaining experience making me in similar 
future cases capable of improvement by _intuitive_ selection of the best 
known to me path to the solution (learning by doing).
It is a big difference between _knowing_ that there are various 
different sorting algorithms and it is necessary to choose the right one 
to speed up sorting and actually _experiencing_ that you have to wait 
for your results 18 hours and the machine is so busy that it is hard to 
use it for other tasks at the same time. If the sorting took less than 
one hour I would probably never make the effort to give it some serious 
thoughts.

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Truly platform-independent DB access in Python?

2006-08-28 Thread bobrik
Hello,

I am using the Python DB API for access to MySQL. But it is not
platform-independent - I need a module not included in Python by
default - python-mysql, and it uses a compiled binary _mysql.so. So it
is not platform-independent because for each web-server on different
platform, I would have to download it and extra compile it specifically
for that platform. Do you know of any Python solution for MySQL access
that is 100% platform-independent?

Thanks for any suggestions.
Boris Dušek

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unpaking sequences of unknown length

2006-08-28 Thread Anthra Norell
I get it!

>>> def  f (*a):
 print a
 print zip (a) # My mistake
 print zip (*a)   # Gerard's solution.

>>> f (l1, l2, l3)
([1, 2, 3], [4, 5, 6], [7, 5, 34])   #  Argument: tuple of lists
[([1, 2, 3],), ([4, 5, 6],), ([7, 5, 34],)]   # My mistake
[(1, 4, 7), (2, 5, 5), (3, 6, 34)]   # That's what I want

Thank you all

Frederic


- Original Message -
From: "Gerard Flanagan" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Sunday, August 27, 2006 2:59 PM
Subject: Re: unpaking sequences of unknown length


>
> Anthra Norell wrote:
> > Hi,
> >
> >I keep working around a little problem with unpacking in cases in which 
> > I don't know how many elements I get. Consider this:
> >
> >   def  tabulate_lists (*arbitray_number_of_lists):
> > table = zip (arbitray_number_of_lists)
> > for record in table:
> ># etc ...
> >
> > This does not work, because the zip function also has an *arg parameter, 
> > which expects an arbitrary length enumeration of
arguments
>
> maybe I don't understand the problem properly, but you can use '*args'
> as 'args' or as '*args', if you see what I mean!, ie.
>
>def  tabulate_lists (*arbitray_number_of_lists):
>  table = zip (*arbitray_number_of_lists)
>  for record in table:
> # etc ...
>
> for example:
>
> def sum_columns(*rows):
> for col in zip(*rows):
> yield sum(col)
>
> for i, s in enumerate( sum_columns( [1,2], [3,2], [5,1] ) ):
> print 'Column %s: SUM=%s' % (i,s)
>
> Column 0: SUM=9
> Column 1: SUM=5
>
> -
>
> alternatively:
>
> import itertools as it
>
> def sum_columns2( iterable ):
> for col in it.izip( *iterable ):
> yield sum(col)
>
> def iter_rows():
> yield [1,2]
> yield [3,2]
> yield [5,1]
>
> print list(  sum_columns2( iter_rows() ) )
>
> #(izip isn't necessary here, zip would do.)
>
> ---
>
> Gerard
>
> --
> http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Claudio Grondi
Tim Roberts wrote:
> "Tim Peters" <[EMAIL PROTECTED]> wrote:
> 
> 
>>[Giovanni Bajo[
>>
I experimented something very strange, a few days ago. I was debugging an
application at a customer's site, and the problem turned out to be that
time.clock() was going "backwards", that is it was sometimes
(randomically) returning a floating point value which was "less than" the
value returned by the previous invokation. The computer was a pretty fast
one (P4 3Ghz I think, running Windows XP), and this happened only between
very close invokations of time.clock().
>>
>>[Terry Reed]
>>
>>>I seem to remember this being mentioned before on the list, perhaps by Tim
>>>Peters.  Perhaps he will chime in.
>>
>>No real need ;-)  BIOS or HAL bug on a multiprocessor (or maybe even
>>hyperthreaded) box is by far the most likely cause (and the only cause
>>ever identified for sure by people who followed up).  Python's C code
>>slinging QueryPerformanceCounter is exceedingly simple, and isn't a
>>suspect because of that.  It's on the edge of vague possibility that
>>Microsoft's compiler generates non-monotonic code for converting
>>64-bit integer to double:
> 
> 
> It is much simpler than that.  With a multiprocessor HAL, including on a
> dual-core or hyperthreaded system, QueryPerformanceCounter returns the raw
> cycle counter (RDTSC).  However, on Windows XP, the operating system does
> not synchronize the cycle counters on multiple processors, and they can be
> actually be millions of cycles apart.
> 
> This was a change from previous systems.  On NT4 and Win2000, the operating
> actually rewrote the cycle counters on the second (and beyond) processors
> to align them to the first processor, so the delta was usually only a dozen
> or two cycles.  XP does not appear to do that.  I think that is a huge
> mistake, since it renders QueryPerformanceCounter non-monotonic.

How does it come, that processors on same mainboard run at different 
speeds? Do they have separate clock-pulse generators?

I can remember, that (at least on very old motherboards) the clock-pulse 
generator was a separate element and the processor just used it, so I 
would expect, that even in case of multiple processors, if there were 
only one clock-pulse generator for all of them, they were not be able to 
run at different speeds.

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Segmentation Fault

2006-08-28 Thread John Machin
pycraze wrote:
> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ?

This is confusing. A seg fault kills the process immediately. No
exception (in the Python sense of that word) is raised.

> Our bit operations and arithmetic
> manipulations are written in C

Do you have a Python extension that is written in C, or are you
embedding Python in a C program -- in other words, is a Python script
calling a C function, or is a C program calling a Python function?

> and to some of our testcases we
> experiance Segmentation fault from the python libraries.

What is it that you are calling "the python libraries"? Tell us the
filenames of these libraries. *Show us what is output on your stderr
when you experience "Segmentation fault from the python libraries".*

Was this Python/C combination recently created by current personnel, or
do we have a case of vanished author(s)?

>
> If i know how to handle the exception for Segmentation fault , it will
> help me complete the run on any testcase , even if i experiance Seg
> Fault due to any one or many functions in my testcase.

It would also help if you told us what platform (hardware and software)
that you are running on, what version of Python, and what versions of
any 3rd-party Python modules/packages that may be involved.

Cheers,
John

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import function from user defined modules

2006-08-28 Thread Fredrik Lundh
groves wrote:

> Can anybody give me an example of how to import a function of module X
> in module y. And please if yu can use classes(Object oriented approach)
> would be great.
> 
> The problem is that I have created a text on canvas, and now I want
> that whenever a user right clicks on it, the option COMMAND should
> invoke a function defined in some other module say Y.

 import Y

 widget = Canvas(..., command=Y.function)

for more on this, see the tutorial:

 http://docs.python.org/tut/node8.html



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Robert Kern
Ray wrote:
> Robert Kern wrote:
>> You might be. No one else in the thread is.
> 
> What are you saying? That my perception that RoR is mature is wrong?

No, that the part of your message that I quoted was wrong. Specifically, "we're 
talking of perception here." No one else here is talking about the perception 
of 
maturity but claims about the actual maturity.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

-- 
http://mail.python.org/mailman/listinfo/python-list


Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Claudio Grondi

Here an example of what I mean
(Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte 
large file):

 >>> f = file('veryBigFile.dat','r')
 >>> f = file('veryBigFile.dat','r+')

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 f = file('veryBigFile.dat','r+')
IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'

Is it a BUG or a FEATURE?

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem of function calls from map()

2006-08-28 Thread Dasn
On Tue, Aug 22, 2006 at 04:50:39PM +0200, Fredrik Lundh wrote:
> (you cannot really use "profile" to *benchmark* things written in
> Python either; the profiler tells you where a given program spends the
> time, not how fast it is in com- parision with other programs)

Thanks for your indication.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem from a Vim user

2006-08-28 Thread Dasn
On Sun, Aug 27, 2006 at 07:10:06AM -0500, Dasn wrote:
> vim.command('let vim_str=input("Please type something.\n")')
> py_str = vim.eval('vim_str')

py_str = vim.eval('input("Please type something.\n")')

may be better.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you get the name of a dictionary?

2006-08-28 Thread Antoon Pardon
On 2006-08-23, Georg Brandl <[EMAIL PROTECTED]> wrote:
> jojoba wrote:
>>> And what im saying is that isnt it silly that we need pass an entire
>>> namespace, when a much simpler notion would be to have each object know
>>> its own name(s) (even if that name doesnt exist).
>> 
>> 
>> please note:  in my above comment, i was completely disregarding any
>> notions of added costs that would be incurred to have such a feature,
>> and that in fact, such costs might actually nullify any other benefits
>> from having such a feature. Purely a what-if idea from a nascent python
>> programmer.
>
> Even from such a point of view, the concept isn't clearly enough defined.
> What name would be assigned to the dict below?
>
> l = [1,2,3]
> a = "some_str"
> l[0] = {'foo': 'bar'}
>
> Some immutable objects, such as small integers, exist only once. Would you
> assign names to them? They're likely to be completely meaningless.
>
> When a name goes out of scope, but the object continues to live (e.g.
> because it's returned by some function), the name is void.

I'm not so sure about that. Local functions can be returned and they
keep their name. Of course it depends on what you mean with the
name of an object. Do you mean the variable name or do you mean
the __name__ attribute?

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Andre Meyer
Hi allIt might be interesting to watch the videos about Django and Rails (http://www.djangoproject.com/snakesandrubies/). Django makes a good impression, although I would not agree with all of their arguments (eg. templating language, ajax). Most striking, though, is the difference in attitude! While Django grew out of a production environment and solves real problems very elegantly, Rails comes "out of beauty", whatever that means. Is Ruby code more beautiful than Python - don't think so.
Nevertheless, I agree with original statement that we Python guys need to look very closely at Ruby and why they are able to catch so much attention. There are good things in the language and Python marketing could certainly be improved. The new web site and logo are good steps in the right direction. Now for free t-shirts to create pervasive awareness? ;-)
regardsAndre
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: dictionaries vs. objects

2006-08-28 Thread Steve Holden
Andre Meyer wrote:
> Hi all
> 
> I have the following question: I need a representation of a physically 
> inspired environment. The environment contains a large number of objects 
> with varying attributes. There may be classes of objects, but there is 
> not necessarily a strictly defined hierarchy among them. Object access 
> should be fast, because there a many objects that change often ( e.g., 
> moving objects).
> 
> My approach is to use a dictionary for the environment model and store 
> each object as a slot, which contains either a dictionary or an object. 
> Now, which is better? What is the performance of Python to look up 
> attributes as either slots of a dictionary or attributes of an object? 
> What feels more logical? What is more pythonic and performs better? 
> Which is constructed and modified easier and quicker? Are there effects 
> that I am not yet aware of?
> 
I'd suggest using objects: quite apart from the fact that name lookup in 
a namespace is pretty much equivalent to a dictionary lookup (namespaces 
use an internal optimised dictionary-style object) remember that objects 
can have methods, and that the names are given as attributes rather than 
as strings.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: avoiding file corruption

2006-08-28 Thread Cliff Wells
On Sun, 2006-08-27 at 07:51 -0700, Amir Michail wrote:

> How often do you need to open a file multiple times for writing?

How often do you write code that you don't understand well enough to
fix?  This issue is clearly a problem within *your* application.

I'm curious how you could possibly think this could be solved in any
case.  What if you accidentally open two instances of the application?
How would Python know?  You are asking Python to perform an OS-level
operation (and a questionable one at that).

My suggestion is that you use a real database if you need concurrent
access.  If you don't need concurrent access then fix your application.

> As a high-level language, Python should prevent people from corrupting
> data as much as possible.

"Data" is application-specific.  Python has no idea how you intend to
use your data and therefore should not (even if it could) try to protect
you.

Regards,
Cliff

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-28 Thread William James
[EMAIL PROTECTED] wrote:

> I would be interested in comments about how Common Lisp, Scheme, and
> Haskell deal with the decorate-sort-dedecorate technique.

%w(FORTRAN LISP COBOL).sort_by{|s| s.reverse}
==>["COBOL", "FORTRAN", "LISP"]

--
Common Lisp did kill Lisp.  Period. ...  It is to Lisp what
C++ is to C.  A monstrosity that totally ignores the basics
of language design, simplicity, and orthogonality to begin
with.  ---  Bernard Lang

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Claudio Grondi wrote:

> 
> Here an example of what I mean
> (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte 
> large file):
>
>  >>> f = file('veryBigFile.dat','r')
>  >>> f = file('veryBigFile.dat','r+')

You mention the file size and gave a "speaking" name to that file -- does
the file size matter?

> Traceback (most recent call last):
>File "", line 1, in -toplevel-
>  f = file('veryBigFile.dat','r+')
> IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'
> 
> Is it a BUG or a FEATURE?

It's the error number Windows returns for that operation.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get the os file icon for a given content-type?

2006-08-28 Thread neoedmund
any simple method?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Segmentation Fault

2006-08-28 Thread Steve Holden
pycraze wrote:
> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ?  Our bit operations and arithmetic
> manipulations are written in C and to some of our testcases we
> experiance Segmentation fault from the python libraries.
> 
> If i know how to handle the exception for Segmentation fault , it will
> help me complete the run on any testcase , even if i experiance Seg
> Fault due to any one or many functions in my testcase.
> 
You will observe, if you look at the list of Python exceptions, that a 
segfault isn't among them. A segfault is a trap to the hardware, and 
generally indicates that a program is so badly hosed that it wouldn't 
make much sense to rely on any further computation in it.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f2py on windows XP - "Unknown Switch"??

2006-08-28 Thread Sile
Cheers John -

I did finally getting f2py working on XP using MinGW, GnuFcompiler for
F77, and much help!  However, having set up everything correctly I have
been told in work I now need to use F90. I have downloaded and
installed G95 MinGW in my MinGW directory and this isn't working now,
I'm not having much joy with this! When I check the available fortran
compilers in F2PY I get the following...

customize Gnu95FCompiler

Could not locate executable f95

Executable f95 does not exist

Could not locate executable f95

Executable f95 does not exist

Could not locate executable f95

Executable f95 does not exist

customize IntelVisualFCompiler

Could not locate executable ifl

Executable ifl does not exist

customize G95FCompiler

Couldn't match compiler version for 'G95 (GCC 4.0.3 (g95 0.90!) Aug 22
2006) Copyright (C) 2002-2005 Free Software Foundation, Inc.nG95 comes
with NO WARRANTY, to the extent permitted by law. You may redistribute
copies of G95under the terms of the GNU General Public License.For more
information about these

...etc.


based on suggestions on the web I changed one line in g95.py to
version_pattern =r'G95.*\(GCC4.01)\(g95!) (?P.\).
Unfortunately this didn't work for me. The problem seems to be with my
gcc version so I'm trying to find a way around this at the moment. Any
suggestions would be much appreciated, I have submitted this problem to
the f2py mailing list too.

thanks,

Sile

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbe question about removing items from one file to another file

2006-08-28 Thread [EMAIL PROTECTED]

Anthra Norell wrote:
> Eric,
>Having played around with problems of this kind for quite some time I find 
> them challenging even if I don't really have time to
> get sidetracked. Your description of the problem makes it all the more 
> challenging, because its 'expressionist' quality adds the
> challenge of guessing what you mean.
>I'd like to take a look at your data, if you would post a segment on which 
> to operate, the same data the way it should look in
> the end. In most cases this is pretty self-explanatory. Explain the points 
> that might not be obvious to a reader who knows nothing
> about your mission.
>
> Frederic
>
> - Original Message -
> From: <[EMAIL PROTECTED]>
> Newsgroups: comp.lang.python
> To: 
> Sent: Sunday, August 27, 2006 11:35 PM
> Subject: newbe question about removing items from one file to another file
>
>
> > def simplecsdtoorc(filename):
> > file = open(filename,"r")
> > alllines = file.read_until("")
> > pattern1 = re.compile(" > orcfilename = filename[-3:] + "orc"
> > for line in alllines:
> > if not pattern1
> >  print >>orcfilename, line
> >
> > I am pretty sure my code isn't close to what I want.  I need to be able
> > to skip html like commands from  to  and to key on
> > another word in adition to  to end the routine
> >
> > I was also looking at se 2.2 beta but didn't see any easy way to use it
> > for this or for that matter search and replace where I could just add
> > it as a menu item and not worry about it.
> >
> > thanks for any help in advance
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list

sorry about that this is a link to a discription of the format
http://kevindumpscore.com/docs/csound-manual/commandunifile.html
It is possible to have more than one instr defined in an .csd file so I
would need to look for that string also if I want to seperate the
instruments out.

http://www.dexrow.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-28 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Tom Cole wrote:

> In Java, classes can implement the Comparable interface. This interface
> contains only one method, a compareTo(Object o) method, and it is
> defined to return a value < 0 if the Object is considered less than the
> one being passed as an argument, it returns a value > 0 if considered
> greater than, and 0 if they are considered equal.
> 
> The object implementing this interface can use any of the variables
> available to it (AKA address, zip code, longitude, latitude, first
> name, whatever) to return this -1, 0 or 1. This is slightly different
> than what you mention as we don't have to "decorate" the object. These
> are all variables that already exist in the Object, and if fact make it
> what it is. So, of course, there is no need to un-decorate at the end.

Python has such a mechanism too, the special `__cmp__()` method
has basically the same signature.  The problem the decorate, sort,
un-decorate pattern solves is that this object specific compare operations
only use *one* criteria.

Let's say you have a `Person` object with name, surname, date of birth and
so on.  When you have a list of such objects and want to sort them by name
or by date of birth you can't use the `compareTo()` method for both.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread [EMAIL PROTECTED]
bobrik wrote:
> I am using the Python DB API for access to MySQL. But it is not
> platform-independent - I need a module not included in Python by
> default - python-mysql, and it uses a compiled binary _mysql.so. So it
> is not platform-independent because for each web-server on different
> platform, I would have to download it and extra compile it specifically
> for that platform. Do you know of any Python solution for MySQL access
> that is 100% platform-independent?

Probably SqlAlchemy 
http://www.sqlalchemy.org/

Lorenzo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Firewire comms using Python?

2006-08-28 Thread PetDragon
yeah man no joy there

"Simon Forman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Fraggle69 wrote:
>> Hi,
>> Does anyone have any idea of how I can use Python to get images from my
>> firewire camera??
>> I am using python under winXP pro
>>
>> Cheers
>> Fraggle
>
> Have you tried google?
>
> Peace,
> ~Simon
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Hendrik van Rooyen
 "Claudio Grondi" <[EMAIL PROTECTED]> Wrote:

| Fredrik Lundh wrote:
| > Diez B. Roggisch wrote:
| >
| >> A while loop has a condition. period. The only thing to change that is
| >> to introduce a uncoditioned loop, and use self-modifying code to make
| >> it a while-loop after that timer interrupt of yours.
| >
| >
| > or use a timer interrupt to interrupt the loop:
| >
| > import signal, time
| >
| > def func1(timeout):
| >
| > def callback(signum, frame):
| > raise EOFError # could use a custom exception instead
| > signal.signal(signal.SIGALRM, callback)
| > signal.alarm(timeout)
| >
| > count = 0
| > try:
| > while 1:
| > count += 1
| > except EOFError:
| > for i in range(10):
| > count += 1
| > print count
| >
| > for an utterly trivial task like the one in that example, the alarm
| > version runs about five times faster than a polling version, on my test
| > machine (ymmv):
| >
| > def func2(timeout):
| >
| > gettime = time.time
| > t_limit = gettime() + timeout
| >
| > count = 0
| > while gettime() < t_limit:
| > count += 1
| > for i in range(10):
| > count += 1
| > print count
| >
| > 
| >
|
| This above is exactly what I am looking for, except it does not work in
| Microsoft Windows where the signal.alarm() function is not available.
|
| So now the only thing I would like to know is how to achieve the same
| functionality when running Python on a Microsoft Windows box.
|
| Claudio Grondi

It looks to me - but I could be wrong - that the time saved here is not because
of the condition test being replaced by the try-except, but because of the fact
that the call to gettime was eliminated - so you may get the most mileage by
using in line code in your loop that avoids calls to subroutines and simply let
it run and test for the end of the counter...

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to let a loop run for a while before checking for breakcondition?

2006-08-28 Thread Hendrik van Rooyen

 "Claudio Grondi" <[EMAIL PROTECTED]> wrote:


| Diez B. Roggisch wrote:
| > Claudio Grondi schrieb:
| >
| >>
| >> Sometimes it is known in advance, that the time spent in a loop will
| >> be in order of minutes or even hours, so it makes sense to optimize
| >> each element in the loop to make it run faster.
| >> One of instructions which can sure be optimized away is the check for
| >> the break condition, at least within the time where it is known that
| >> the loop will not reach it.
| >>
| >> Any idea how to write such a loop?
| >>
| >> e.g.
| >>
| >> counter = 2*64
| >>
| >> while counter(BUT DON'T CHECK IT THE FIRST ONE HOUR LONG):
| >
| >
| > now = time.time()
| > while time.time() - now < 3600.0 or some_other_condition:
| >...
| >
| >
| > The short circuiting of the or will prevent the execution of
| > some_other_condition.
| >
| >>   ... do something ... # and decrease the counter
| >>
| >> Thanks for any hint, but in particular if related to timers on the
| >> Windows 2000/XP system I am mainly working with.
| >>
| >> What do you think about this idea? Does it make sense?
| >
| > What idea?
| This one you haven't probably got from what I have written.
| I thought, that the introductory text gives enough context to be able to
| see what I mean, but I was apparently wrong.
|
| The idea is to speed up a loop by using a timer interrupt interfering
| with the loop, so that only after the timer interrupt would occur, the
| loop will start to check its break condition in each iteration.
| No checking of any kind in the loop should happen up to that time to
| minimize the number of operations in each iteration within the loop
| itself (i.e. the loop more or less won't know, that there is a timer on
| its way to change the loops behavior at a later time).
|
| I hope this above helps to understand what I would like to achieve.
|
| Claudio Grondi

I don't think this is usefully possible in python - the problem is that you will
simply replace one check - The expiry of the counter - with another - to see if
the interrupt has occurred already -

That said - the way I would do it would be to do something like this (in
horrible pseudo code):

loop_start:
do_something()
jump loop_start
if counter > end_value:
break
jump loop_start
loop_end:


Interrupt_routine:
replace the first jump to loop_start with a bunch of no - ops
return

I don't think you can do this in python - it involves altering the running
loop - but hey maybe I can learn something here...

This example sort of exposes the break for what it is - a jump statement in
disguise - "look you cant recognise me - I am wearing dark glasses" - and
"continue" is exactly like that too - the only difference is that the one jumps
to the end, and the other to the beginning of the loop...

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Claudio Grondi
Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, Claudio Grondi wrote:
> 
> 
>>Here an example of what I mean
>>(Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte 
>>large file):
>>
>> >>> f = file('veryBigFile.dat','r')
>> >>> f = file('veryBigFile.dat','r+')
> 
> 
> You mention the file size and gave a "speaking" name to that file -- does
> the file size matter?
Yes, it does.
I haven't tested it yet, but I suppose 2 or 4 GByte threshold value.
> 
> 
>>Traceback (most recent call last):
>>   File "", line 1, in -toplevel-
>> f = file('veryBigFile.dat','r+')
>>IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'
>>
>>Is it a BUG or a FEATURE?
> 
> 
> It's the error number Windows returns for that operation.
So you just try to say:
  "it's not Python fault - it's just another bug of the damn Microsoft 
Windows operating system", right?

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Segmentation Fault

2006-08-28 Thread Duncan Booth
pycraze wrote:

> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ?  Our bit operations and arithmetic
> manipulations are written in C and to some of our testcases we
> experiance Segmentation fault from the python libraries.
> 
>From what you said, I guess you mean that you have written some extensions 
to Python in C, but that the segmentation fault is generated when you call 
standard Python library functions.

Most likely your C code has bugs: quite possibly you have messed up 
reference counting so some objects you use are being freed and then the 
Python libraries allocate other objects into the same memory. It is very 
easy to do that especially if you are in the habit of trying to 'borrow' 
references instead of religiously incrementing/decrementing reference 
counts everywhere.

Try to eliminate the problem down to the smallest reproducable code sample 
and post that.

Another suggestion I would make is to see if you can use ctypes or Pyrex to 
form the glue between Python and C so that none of the C code you write 
knows anything about Python. That should eliminate some possible sources 
for error.
-- 
http://mail.python.org/mailman/listinfo/python-list


DirectPython

2006-08-28 Thread J�r�me Le Bougeant
Hello,

I have DirectPython 0.5 (http://directpython.sourceforge.net/) and python2.4 
(directx9.0C installed).
Samples do not work, I have this error : "RuntimeError: Failed to create a
device"
For example with sampleBasic.py :

Traceback (most recent call last):
  File "sampleBasic.py", line 147, in ?
mainloop()
  File "sampleBasic.py", line 75, in mainloop
d3d.createDevice(title, u"textures/x.ico", window[2], window[3], False,
CREATE.HARDWARE)
RuntimeError: Failed to create a device


Why ?

please help me... any help would be appreciated.
Thanks


-- 
http://mail.python.org/mailman/listinfo/python-list


close event handling for ScrollView

2006-08-28 Thread mail2sirshendu
I have a class in which I have created an instance QScrollView and
added a QDialog inside it using addChild().I have Ok and Cancel button
in the Dialog.When either Ok or Cancel is clicked the Dialog is closed
properly (receiving  accept or reject signals). I have a exec loop on
the Dialog.
When I click the 'X' button on the toolbar of the ScrollView, the
ScrollView is closing but the exec() call on the Dialog is not
terminated and my application hangs.

here is the portion of the code I am taiking about.

self.scrollView = QScrollView()
dialog = QDialog (self, , self.scrollView.viewport())
self.scrollView.addChild(dialog)
self.scrollView.show()

if (dialog.exec() == QDialog.Accepted):
 self.scrollView.hide()
 self.scrollView.removeChild(dialog)


can someone suggest some way to handle this issue..

-- 
http://mail.python.org/mailman/listinfo/python-list


Starting up the server

2006-08-28 Thread john Perry
hi all,

how to solve these error

Traceback (most recent call last):
  File "mrsm-start.py", line 2, in 
import pkg_resources
ImportError: No module named pkg_resources

please help me thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f2py on windows XP - "Unknown Switch"??

2006-08-28 Thread John Machin
On 28/08/2006 6:44 PM, Sile wrote:
> Cheers John -
> 
> I did finally getting f2py working on XP using MinGW, GnuFcompiler for
> F77, and much help!  However, having set up everything correctly I have
> been told in work I now need to use F90. I have downloaded and
> installed G95 MinGW in my MinGW directory and this isn't working now,
> I'm not having much joy with this! When I check the available fortran
> compilers in F2PY I get the following...
> 
> customize Gnu95FCompiler
> 
> Could not locate executable f95
> 
> Executable f95 does not exist
> 
> Could not locate executable f95
> 
> Executable f95 does not exist
> 
> Could not locate executable f95
> 
> Executable f95 does not exist
> 
> customize IntelVisualFCompiler
> 
> Could not locate executable ifl
> 
> Executable ifl does not exist
> 
> customize G95FCompiler
> 
> Couldn't match compiler version for 'G95 (GCC 4.0.3 (g95 0.90!) Aug 22
> 2006) Copyright (C) 2002-2005 Free Software Foundation, Inc.nG95 comes
> with NO WARRANTY, to the extent permitted by law. You may redistribute
> copies of G95under the terms of the GNU General Public License.For more
> information about these
> 
> ...etc.
> 
> 
> based on suggestions on the web I changed one line in g95.py to
> version_pattern =r'G95.*\(GCC4.01)\(g95!) (?P.\).
> Unfortunately this didn't work for me. The problem seems to be with my
> gcc version so I'm trying to find a way around this at the moment. Any
> suggestions would be much appreciated, I have submitted this problem to
> the f2py mailing list too.
> 

Ummm shouldn't that be "GCC 4.0.1", not "GCC4.01" ???
Further that pattern seems as though it's been through some web 
garbling; for example "<" instead of "<", the parentheses don't 
match, the string isn't terminated by a "'", spaces missing, 

Can you post an ungarbled version of the original line (maybe the 
*whole* g95.py -- e-mail if it's too big) and what you changed it to, 
plus what your f95 compiler puts out when you run it with  --version?

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting up the server

2006-08-28 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, john Perry
wrote:

> how to solve these error
> 
> Traceback (most recent call last):
>   File "mrsm-start.py", line 2, in 
> import pkg_resources
> ImportError: No module named pkg_resources

Install the module `pkg_resources`.

SCNR,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Tim Peters
[Claudio Grondi]
> Here an example of what I mean
> (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte
> large file):
>
>  >>> f = file('veryBigFile.dat','r')
>  >>> f = file('veryBigFile.dat','r+')
>
> Traceback (most recent call last):
>File "", line 1, in -toplevel-
>  f = file('veryBigFile.dat','r+')
> IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'
>
> Is it a BUG or a FEATURE?

Assuming the file exists and isn't read-only, I bet it's a Windows
bug, and that if you open in binary mode ("r+b") instead I bet it goes
away (this wouldn't be the first large-file text-mode Windows bug).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the os file icon for a given content-type?

2006-08-28 Thread Bruno Desthuilliers
neoedmund wrote:
Please repeat the whole question in the message body

=>how to get the os file icon for a given content-type?
> any simple method?

This is specific to your OS  (and FWIW, there's nothing like a "file
icon" on the OS I'm using).


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
> bobrik wrote:
>> I am using the Python DB API for access to MySQL. But it is not
>> platform-independent - I need a module not included in Python by
>> default - python-mysql, and it uses a compiled binary _mysql.so. So it
>> is not platform-independent because for each web-server on different
>> platform, I would have to download it and extra compile it specifically
>> for that platform. Do you know of any Python solution for MySQL access
>> that is 100% platform-independent?
> 
> Probably SqlAlchemy 
> http://www.sqlalchemy.org/

Probably not - I fail to see how SqlAlchemy could talk to MySQL without
the MySQL/Python binding.



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Bruno Desthuilliers
bobrik wrote:
> Hello,
> 
> I am using the Python DB API for access to MySQL. But it is not
> platform-independent 

It is. You don't have to change your Python code according to the OS or
CPU.



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting up the server

2006-08-28 Thread Fredrik Lundh
"john Perry" wrote:

> how to solve these error
>
> Traceback (most recent call last):
>  File "mrsm-start.py", line 2, in 
>import pkg_resources
> ImportError: No module named pkg_resources
>
> please help me thanks

what server?  what software are you using?

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting up the server

2006-08-28 Thread john Perry

Fredrik Lundh wrote:
> "john Perry" wrote:
>
> > how to solve these error
> >
> > Traceback (most recent call last):
> >  File "mrsm-start.py", line 2, in 
> >import pkg_resources
> > ImportError: No module named pkg_resources
> >
> > please help me thanks
>
> what server?  what software are you using?

TurboGears 0.8.9,python 2.53 and using sql server

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Bruno Desthuilliers
Ray wrote:
(snip)
> Sadly, there are more Java guys who know about Ruby than Python,
> despite the fact that Python predates Ruby by quite a few years...

FWIW, Python is somewhat older than Java too...


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the os file icon for a given content-type?

2006-08-28 Thread neoedmund
So what? Java 5.0 has the method, why python has not?
Bruno Desthuilliers wrote:
> neoedmund wrote:
> Please repeat the whole question in the message body
>
> =>how to get the os file icon for a given content-type?
> > any simple method?
>
> This is specific to your OS  (and FWIW, there's nothing like a "file
> icon" on the OS I'm using).
>
>
> --
> bruno desthuilliers
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in '[EMAIL PROTECTED]'.split('@')])"

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Fredrik Lundh
Tim Peters wrote:

> Assuming the file exists and isn't read-only, I bet it's a Windows
> bug, and that if you open in binary mode ("r+b") instead I bet it goes
> away (this wouldn't be the first large-file text-mode Windows bug).

> dir bigfile.dat
2006-08-28  11:46 5 000 000 000 bigfile.dat

>>> f = file("bigfile.dat", "r")
>>> f = file("bigfile.dat", "r+")
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 2] No such file or directory: 'bigfile.dat'

>>> f = file("bigfile.dat", "rb")
>>> f = file("bigfile.dat", "r+b")

(typing f.read() here is a nice way to lock up the machine ;-)

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
> First, I don't intend this to be a flame war, please. 

Then avoid crossposting to both c.l.ruby and c.l.python !-)
(BTW, fu2 c.l.python).

> Python
> and Ruby are the only two languages I'd willingly work in
> (at least amongst common languages), and TurboGears and
> Rails seem roughly equivalent.
> 
> I'm much more knowledgable about Python, but that's a minor
> issue--I've been intending to learn more Ruby anyway.
> 
> Here are the pros and cons that I'm aware of and consider
> important:
> 
> Turbogears:
> + SqlObject allows working with the DB tables without
> using SQL itself.

I personnaly don't like SqlObject. SqlAlchemy looks like a much better
solution IMHO. And FWIW, Ruby has it's own ORM too.

(snip)

> I was initially leaning towards Rails due to maturity,
> but the most recent version of TurboGears seem to have
> fixed a lot of the "ad hoc" feeling I got from previous
> versions. But I'm still very much up in the air.

Then take a few days to play with both Rails and TG and go with the one
that better fits your brain.

FWIW, you may also want to check Pylons (another Python Web-MVC framework).

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the os file icon for a given content-type?

2006-08-28 Thread Fredrik Lundh
"neoedmund" <[EMAIL PROTECTED]> wrote:

> So what? Java 5.0 has the method, why python has not?

python's developed by volunteers, and nobody has volunteered to develop
such a function.

why not check how Java does this, and contribute the code ?

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting up the server

2006-08-28 Thread Fredrik Lundh
"john Perry" wrote:

>> what server?  what software are you using?
>
> TurboGears 0.8.9,python 2.53 and using sql server

have you checked the TurboGears mailing list archives ?

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to let a loop run for a while before checking for break condition?

2006-08-28 Thread Claudio Grondi
Hendrik van Rooyen wrote:
>  "Claudio Grondi" <[EMAIL PROTECTED]> Wrote:
> 
> | Fredrik Lundh wrote:
> | > Diez B. Roggisch wrote:
> | >
> | >> A while loop has a condition. period. The only thing to change that is
> | >> to introduce a uncoditioned loop, and use self-modifying code to make
> | >> it a while-loop after that timer interrupt of yours.
> | >
> | >
> | > or use a timer interrupt to interrupt the loop:
> | >
> | > import signal, time
> | >
> | > def func1(timeout):
> | >
> | > def callback(signum, frame):
> | > raise EOFError # could use a custom exception instead
> | > signal.signal(signal.SIGALRM, callback)
> | > signal.alarm(timeout)
> | >
> | > count = 0
> | > try:
> | > while 1:
> | > count += 1
> | > except EOFError:
> | > for i in range(10):
> | > count += 1
> | > print count
> | >
> | > for an utterly trivial task like the one in that example, the alarm
> | > version runs about five times faster than a polling version, on my test
> | > machine (ymmv):
> | >
> | > def func2(timeout):
> | >
> | > gettime = time.time
> | > t_limit = gettime() + timeout
> | >
> | > count = 0
> | > while gettime() < t_limit:
> | > count += 1
> | > for i in range(10):
> | > count += 1
> | > print count
> | >
> | > 
> | >
> |
> | This above is exactly what I am looking for, except it does not work in
> | Microsoft Windows where the signal.alarm() function is not available.
> |
> | So now the only thing I would like to know is how to achieve the same
> | functionality when running Python on a Microsoft Windows box.
> |
> | Claudio Grondi
> 
> It looks to me - but I could be wrong - that the time saved here is not 
> because
> of the condition test being replaced by the try-except, but because of the 
> fact
> that the call to gettime was eliminated - so you may get the most mileage by
> using in line code in your loop that avoids calls to subroutines and simply 
> let
> it run and test for the end of the counter...
> 
> - Hendrik
> 
The test of the counter is what actually slows the loop down. Probably 
the test of time slows the loop even more down. Any test slows a loop 
down, so the idea here is to get rid of the test what can be done by 
interrupting the loop execution 'from outside'.
Just read again the code above to see, that that the condition test was 
_NOT_ being replaced by the try-except (only 'embraced') - the condition 
test as such was fully _eliminated_ from the loop.

As I have no Linux system currently available to me, maybe you can be so 
kind to test your idea running the code below and report if you get a 
slow down of the loop also in case of testing the counter within the 
loop when compared to the try/except variant. Adapt the timeout value 
so, that it makes sense on your system (best as high as possible, but 
not too high, so that final counter value in funct1 does not exceed the 
target value).


import signal, time

def func1(timeout):

 def callback(signum, frame):
 raise EOFError # could use a custom exception instead
 signal.signal(signal.SIGALRM, callback)
 signal.alarm(timeout)

 count = 0
 try:
 while 1:
 count += 1
 except EOFError:
 while True:
 count += 1
 if count < 0x500:
 break
 print hex(count)

def func2():

 count = 0
 while True:
 count += 1
 if count < 0x500:
 break
 print hex(count)

print
startTime = time.clock()
funct1(10)
print time.clock() - startTime

print
print
startTime = time.clock()
funct2()
print time.clock() - startTime



Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python - Have Question.

2006-08-28 Thread Tal Einat
> Thank you for this.  The most daunting task in learning Python, is learning
> all of the modules and functions that are available.  And there's a tonne
> of them.  :-)
>
Actually, much of this file-system related stuff really is badly spread
out between many different modules (os, os.path, glob, fnmatch, shutil,
stat), mostly for historical reasons. Consulting the docs often and
viewing working code examples are a good way to learn how to
effectively do these things with Python's current stdlib.

Some discussion has been going on for several years now about joining
all such functionality into one "path" module, by creating a standard
Path object, and having all of this nicely Object-Oriented. Currently
there is a PEP about this (see PEP 355), but with the release of Python
2.5 nearing this has been further delayed by the development community.

PEP 355: http://www.python.org/dev/peps/pep-0355/

- Tal

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a good idea or a waste of time?

2006-08-28 Thread Antoon Pardon
On 2006-08-25, Simon Forman <[EMAIL PROTECTED]> wrote:
> asincero wrote:
>> Would it be considered good form to begin every method or function with
>> a bunch of asserts checking to see if the parameters are of the correct
>> type (in addition to seeing if they meet other kinds of precondition
>> constraints)?  Like:
>>
>> def foo(a, b, c, d):
>>assert type(a) == str
>>assert type(b) == str
>>assert type(c) == int
>>assert type(d) == bool
>># rest of function follows
>>
>> This is something I miss from working with more stricter languages like
>> C++, where the compiler will tell you if a parameter is the wrong type.
>>  If anything, I think it goes a long way towards the code being more
>> self documenting.  Or is this a waste of time and not really "the
>> Python way"?
>>
>> -- Arcadio
>
> Generally asserts should be used to "enforce" invariants of your code
> (as opposed to typechecking), or to check certain things while
> debugging.

I don't understand this argument. Can't type checking be seen as
enforcing a code invariant?

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Claudio Grondi
Tim Peters wrote:
> [Claudio Grondi]
> 
>> Here an example of what I mean
>> (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte
>> large file):
>>
>>  >>> f = file('veryBigFile.dat','r')
>>  >>> f = file('veryBigFile.dat','r+')
>>
>> Traceback (most recent call last):
>>File "", line 1, in -toplevel-
>>  f = file('veryBigFile.dat','r+')
>> IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'
>>
>> Is it a BUG or a FEATURE?
> 
> 
> Assuming the file exists and isn't read-only, I bet it's a Windows
> bug, and that if you open in binary mode ("r+b") instead I bet it goes
> away (this wouldn't be the first large-file text-mode Windows bug).

I knew already that 'r+b' fixes it. Yes, you have won the bet :) .

I suppose, like you do, that because there is a difference between text 
and binary files on Windows and the text files are e.g. opened being 
buffered using a 32-bit buffer pointer, this fails on too large NTFS files.

I could also imagine that Python tries to buffer the text file and fails 
because it uses the wrong pointer size when asking Windows for the 
content. I have not yet looked into the C-code of Python - any hint 
which file I should take a closer look at?
Just curious to see for myself, that the bug is on the Windows side.

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Fredrik Lundh
Tim Peters wrote:

>> Traceback (most recent call last):
>>File "", line 1, in -toplevel-
>>  f = file('veryBigFile.dat','r+')
>> IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'
>>
>> Is it a BUG or a FEATURE?
>
> Assuming the file exists and isn't read-only, I bet it's a Windows
> bug, and that if you open in binary mode ("r+b") instead I bet it goes
> away (this wouldn't be the first large-file text-mode Windows bug).

however, if you use the C level API, you get EINVAL (which presumably means
that the CRT cannot open this file in text mode), not ENOENT.   this is also 
true
for older versions of Python:

Python 2.1.1 (#20, Aug 23 2001, 11:27:17) [MSC 32 bit (Intel)] on win32
>>> f = open("bigfile.dat")
>>> f = open("bigfile.dat", "r+")
Traceback (most recent call last):
  File "", line 1, in ?
IOError: [Errno 22] Invalid argument: 'bigfile.dat'

which probably means that this fix

http://www.python.org/sf/538827

is partially responsible for the misleading error message.

(the cause of this seems to be that when you open a text file for updating, the
CRT check if there's a chr(26) at the end of the file, but the 32-bit lseek API
doesn't support seeking to positions larger than 2^31-2)

 



-- 
http://mail.python.org/mailman/listinfo/python-list


when is a != foo.a?

2006-08-28 Thread Chaz Ginger
I am somewhat new to Python (last year). As such I encounter little 
"gotchas" all the time. I am wondering is someone can explain this to me:

If have three simple files:

a.py -

foo = None
def a(b):
global foo
foo = b

b.py --

from a import foo
def b(): print foo

c.py --

import a
from b import b

print 'per a.a() ',a.foo
a.a(245)
print 'expect 245 ', a.foo
b()


If I run 'python c.py' I get the following printed out:


per a.a()  None
expect 245  245
None


That surprised me. If I change b.py to

import a
def b(): print a.foo

I get the following (which is what I expected originally):


per a.a()  None
expect 245  245
245


Can someone explain what is really going on here?

TIA,
Chaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting up the server

2006-08-28 Thread john Perry
yes i'll have check it
please guide me if i'm wrong
thanks

Fredrik Lundh wrote:
> "john Perry" wrote:
>
> >> what server?  what software are you using?
> >
> > TurboGears 0.8.9,python 2.53 and using sql server
> 
> have you checked the TurboGears mailing list archives ?
> 
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when is a != foo.a?

2006-08-28 Thread Duncan Booth
Chaz Ginger wrote:

> Can someone explain what is really going on here?

Think of 'from x import y' as an assignment. Roughly equivalent to:

   y = sys.modules['x'].y

(except of course you don't have to have imported sys, and it will load the 
module 'x' if it hasn't already been imported.)

> b.py --
> 
> from a import foo

In other words:

   foo = a.foo

foo in module b is initialised from a.foo, but it is a separate variable. 
So when a.foo is rebound that doesn't affect b.foo.

> def b(): print foo
> 
> c.py --
> 
> import a
> from b import b

and here:
   b = b.b

> 
> print 'per a.a() ',a.foo
> a.a(245)
> print 'expect 245 ', a.foo
> b()
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f2py on windows XP - "Unknown Switch"??

2006-08-28 Thread Sile
Thanks for your reply,
Sorry about the last post - pasting from another post didn't work so
well...

The --version output from my f95 compiler is as follows:

C:\>g95 --version
G95 (GCC 4.0.3 (g95 0.90!) Aug 22 2006)
Copyright (C) 2002-2005 Free Software Foundation, Inc.

G95 comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of G95
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

The f95.py file is located under Numpy as follows...
C:\Program
Files\ESI_Software\UTILS_2006\Python2.3_CFD\Lib\site-packages\numpy\distutils\fcompiler\f95.py

import os
import sys

from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler

class G95FCompiler(FCompiler):

compiler_type = 'g95'
version_pattern = r'G95.*\(GCC 4.0.3 \(g95!\) (?P.*)\).*'
THE LINE ABOVE WAS ORIGINALLY:
version_pattern = r'G95.*\(experimental \(g95!\)
(?Pf2py -c --help-fcompiler
...
Could not locate executable f95
Executable f95 does not exist
customize VastFCompiler
Could not locate executable vf90
Executable vf90 does not exist
customize GnuFCompiler
customize IbmFCompiler
Could not locate executable xlf
Executable xlf does not exist
customize Gnu95FCompiler
Could not locate executable f95
Executable f95 does not exist
Could not locate executable f95
Executable f95 does not exist
Could not locate executable f95
Executable f95 does not exist
customize IntelVisualFCompiler
Could not locate executable ifl
Executable ifl does not exist
customize G95FCompiler
Couldn't match compiler version for 'G95 (GCC 4.0.3 (g95 0.90!) Aug 22
2006)\nCo
pyright (C) 2002-2005 Free Software Foundation, Inc.\n\nG95 comes with
NO WARRAN
TY, to the extent permitted by law.\nYou may redistribute copies of
G95\nunder the terms of the GNU General Public License.\nFor more
information about these matters, see the file named COPYING'
customize IntelItaniumFCompiler
Could not locate executable efc
Executable efc does not exist
customize PGroupFCompiler
Could not locate executable pgf77
Executable pgf77 does not exist
customize LaheyFCompiler
Could not locate executable lf95
Executable lf95 does not exist
customize CompaqVisualFCompiler
customize MipsFCompiler
customize HPUXFCompiler
customize IntelItaniumVisualFCompiler
Could not locate executable efl
Executable efl does not exist
customize IntelEM64TFCompiler
Could not locate executable efc
Executable efc does not exist
List of available Fortran compilers:
  --fcompiler=compaqv  DIGITAL|Compaq Visual Fortran Compiler (6.5)
  --fcompiler=gnu  GNU Fortran Compiler (3.4.5)

I hope that makes it a bit clearer,

Thanks,

Sile

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when is a != foo.a?

2006-08-28 Thread Chaz Ginger
Duncan Booth wrote:
> Chaz Ginger wrote:
> 
>> Can someone explain what is really going on here?
> 
> Think of 'from x import y' as an assignment. Roughly equivalent to:
> 
>y = sys.modules['x'].y
> 
> (except of course you don't have to have imported sys, and it will load the 
> module 'x' if it hasn't already been imported.)
> 
>> b.py --
>>
>> from a import foo
> 
> In other words:
> 
>foo = a.foo
> 
> foo in module b is initialised from a.foo, but it is a separate variable. 
> So when a.foo is rebound that doesn't affect b.foo.
> 
>> def b(): print foo
>>
>> c.py --
>>
>> import a
>> from b import b
> 
> and here:
>b = b.b
> 
>> print 'per a.a() ',a.foo
>> a.a(245)
>> print 'expect 245 ', a.foo
>> b()
>>
> 
> 

Thanks, Duncan. It now makes sense.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Middle matching - any Python library functions (besides re)?

2006-08-28 Thread Andrew Robert
Simon Forman wrote:
> Paul Rubin wrote:
>> "EP" <[EMAIL PROTECTED]> writes:
>>> Given that I am looking for matches of all files against all other
>>> files (of similar length) is there a better bet than using re.search?
>>> The initial application concerns files in the 1,000's, and I could use
>>> a good solution for a number of files in the 100,000's.
>> If these are text files, typically you'd use the Unix 'diff' utility
>> to locate the differences.
> 
> If you can, you definitely want to use diff.  Otherwise, the difflib
> standard library module may be of use to you.  Also, since you're
> talking about comparing many files to each other, you could pull out a
> substring of one file and use the 'in' "operator" to check if that
> substring is in another file.  Something like this:
> 
> f = open(filename) # or if binary open(filename, 'rb')
> f.seek(somewhere_in_the_file)
> substr = f.read(some_amount_of_data)
> f.close()
> 
> try_diffing_us = []
> for fn in list_of_filenames:
> data = open(fn).read() # or again open(fn, 'rb')...
> if substr in data:
> try_diffing_us.append(fn)
> 
> # then diff just those filenames...
> 
> That's a naive implementation but it should illustrate how to cut down
> on the number of actual diffs you'll need to perform.  Of course, if
> your files are large it may not be feasible to do this with all of
> them.  But they'd have to be really large, or there'd have to be lots
> and lots of them...  :-)
> 
> More information on your actual use case would be helpful in narrowing
> down the best options.
> 
> Peace,
> ~Simon
> 

Would it be more efficient to checksum the files and then only diff the ones 
that fail a checksum compare?


Utilizing the functions below may be of some help.


#!/usr/bin/python
#
#
# Function: generate and compare checksums on a file 


import md5, sys


def getsum(filename):
"""
Generate the check sum based on received chunks of the file
"""
md5sum = md5.new()
f = open(filename, 'r')
for line in getblocks(f) :
 md5sum.update(line)
f.close()
return md5sum.hexdigest()

def getblocks(f, blocksize=1024):
""" 
Read file in small chunks to avoid having large files loaded into memory
"""
while True:
s = f.read(blocksize)
if not s: break
yield s

def checksum_compare(caller, cs='',check='', filename=''):
"""
Compare the generated and received checksum valued
"""
if cs != check:
return 1 # compare failed
else:
return 0 # compare successful
 



   -- 
Adversity: That which does not kill me only postpones the inevitable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when is a != foo.a?

2006-08-28 Thread John Machin

Chaz Ginger wrote:
> I am somewhat new to Python (last year). As such I encounter little
> "gotchas" all the time. I am wondering is someone can explain this to me:
>
> If have three simple files:
>
> a.py -
>
> foo = None
> def a(b):
>   global foo
>   foo = b
>
> b.py --
>
> from a import foo
> def b(): print foo
>
> c.py --
>
> import a
> from b import b
>
> print 'per a.a() ',a.foo
> a.a(245)
> print 'expect 245 ', a.foo
> b()
>
>
> If I run 'python c.py' I get the following printed out:
>
>
> per a.a()  None
> expect 245  245
> None
>
>
> That surprised me. If I change b.py to
>
> import a
> def b(): print a.foo
>
> I get the following (which is what I expected originally):
>
>
> per a.a()  None
> expect 245  245
> 245
>
>
> Can someone explain what is really going on here?

You are, in a very roundabout fashion, effectively executing the
following bindings:

a.foo = None # done when a is first imported
b.foo = a.foo # done in module b by "from a import foo"
a.foo = 245

So b.foo is bound to None, and a.foo is bound to 245. 

Cheers,
John

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when is a != foo.a?

2006-08-28 Thread Chaz Ginger
John Machin wrote:
> Chaz Ginger wrote:
>> I am somewhat new to Python (last year). As such I encounter little
>> "gotchas" all the time. I am wondering is someone can explain this to me:
>>
>> If have three simple files:
>>
>> a.py -
>>
>> foo = None
>> def a(b):
>>  global foo
>>  foo = b
>>
>> b.py --
>>
>> from a import foo
>> def b(): print foo
>>
>> c.py --
>>
>> import a
>> from b import b
>>
>> print 'per a.a() ',a.foo
>> a.a(245)
>> print 'expect 245 ', a.foo
>> b()
>>
>>
>> If I run 'python c.py' I get the following printed out:
>>
>>
>> per a.a()  None
>> expect 245  245
>> None
>>
>>
>> That surprised me. If I change b.py to
>>
>> import a
>> def b(): print a.foo
>>
>> I get the following (which is what I expected originally):
>>
>>
>> per a.a()  None
>> expect 245  245
>> 245
>>
>>
>> Can someone explain what is really going on here?
> 
> You are, in a very roundabout fashion, effectively executing the
> following bindings:
> 
> a.foo = None # done when a is first imported
> b.foo = a.foo # done in module b by "from a import foo"
> a.foo = 245
> 
> So b.foo is bound to None, and a.foo is bound to 245. 
> 
> Cheers,
> John
> 

Thanks John. It is a lot different from the C and C++ world where you 
can hold a reference to something and use it. That is how I thought 
about what I was doing and learned it wasn't quite right! lol.

Thanks again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Paul Boddie
Ray wrote:
> fuzzylollipop wrote:
> > uh, no, Python predates Ruby by a good bit
> > Rails might be "older" than Turbogears but it still JUST went 1.0
> > officially.
> > It can't be called "mature' by any defintition.

Version numbers are a fairly useless general metric of project
maturity, taken in isolation.

> But at least in most developers' perception, it is (not necessarily in
> the absolute sense, but perhaps relative to Django or Turbogears).
> Mind, it doesn't even need to be true, we're talking of perception
> here.

So actual maturity isn't important when using a technology: it's
"perceived maturity" that counts, right? Any continuation down that
particular path of reasoning surely leads you to the point where you
claim, in concert with the developers, that increasing levels of
inconvenience caused by gratuitous changes or broken documentation is
not caused by bugs or general immaturity but by "features". I guess
this is the definition of "opinionated software" that some people are
so excited about.

[...]

> Sadly, there are more Java guys who know about Ruby than Python,
> despite the fact that Python predates Ruby by quite a few years...
> (this must be that Bruce Tate dude's fault! )

If you only listen to Bruce Tate et al, I imagine you could have the
above impression, but I'd be interested to see hard facts to back up
those assertions.

Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Claudio Grondi
Fredrik Lundh wrote:
> Tim Peters wrote:
> 
> 
>>>Traceback (most recent call last):
>>>   File "", line 1, in -toplevel-
>>> f = file('veryBigFile.dat','r+')
>>>IOError: [Errno 2] No such file or directory: 'veryBigFile.dat'
>>>
>>>Is it a BUG or a FEATURE?
>>
>>Assuming the file exists and isn't read-only, I bet it's a Windows
>>bug, and that if you open in binary mode ("r+b") instead I bet it goes
>>away (this wouldn't be the first large-file text-mode Windows bug).
> 
> 
> however, if you use the C level API, you get EINVAL (which presumably means
> that the CRT cannot open this file in text mode), not ENOENT.   this is also 
> true
> for older versions of Python:
> 
> Python 2.1.1 (#20, Aug 23 2001, 11:27:17) [MSC 32 bit (Intel)] on win32
> 
f = open("bigfile.dat")
f = open("bigfile.dat", "r+")
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> IOError: [Errno 22] Invalid argument: 'bigfile.dat'
> 
> which probably means that this fix
> 
> http://www.python.org/sf/538827
> 
> is partially responsible for the misleading error message.
> 
> (the cause of this seems to be that when you open a text file for updating, 
> the
> CRT check if there's a chr(26) at the end of the file, but the 32-bit lseek 
> API
> doesn't support seeking to positions larger than 2^31-2)
> 
>  

Using MSVC++ .NET 2003 compiler (if I did it all the right way):

fstm = fopen("bigfile.dat","r+");
if(fstm == 0) { printf( "  ErrNo: %i \n", errno ); }
//  ^-- prints :
// on "r+" with too large file: 22  (EINVAL-Invalid argument)
// on non-existing file   :  2  (ENOENT-no such file)
// on bad mode string spec.   :  0  (??? why not EINVAL ...)

So there _is_ a way to distinguish the different problems occurred while 
opening the file. The error message comes from Python (errnomodule.c), 
not from Windows(errno.h). Concluding from this it becomes evident for 
me, that this misleading error message is Python fault (even if 
originated by misleading errno values set after fopen in the MSVC++ 
environment and Windows), right?
Probably also in Python 2.5?

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Segmentation Fault

2006-08-28 Thread thomas . samson
"Simon Forman" <[EMAIL PROTECTED]> writes:

> pycraze wrote:
>> I would like to ask a question. How do one handle the exception due to
>> Segmentation fault due to Python ?  Our bit operations and arithmetic
>> manipulations are written in C and to some of our testcases we
>> experiance Segmentation fault from the python libraries.
>>
>> If i know how to handle the exception for Segmentation fault , it will
>> help me complete the run on any testcase , even if i experiance Seg
>> Fault due to any one or many functions in my testcase.
>
> AFAIK, seg fault kills your program dead.  There's no exception to
> handle.  If you're getting seg faults from the python standard library,
> that's a pretty serious thing, way more serious than just not-passed
> testcases.

Segfault handling is platform-dependant... So, at least on unix-like
platform, you can use the signal module to detect segfault:

import signal

def handler(signum, frame):
print 'Segfault detected'
# you may use the stack frame here to help debugging

signal.signal(signal.SIGSEGV, handler)

-- 
Thomas SAMSON
"You're very sure of your facts, " he said at last, "I
couldn't trust the thinking of a man who takes the Universe
- if there is one - for granted. "
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f2py on windows XP - "Unknown Switch"??

2006-08-28 Thread John Machin
On 28/08/2006 9:47 PM, Sile wrote:
> Thanks for your reply,
> Sorry about the last post - pasting from another post didn't work so
> well...
> 
> The --version output from my f95 compiler is as follows:
> 
> C:\>g95 --version
> G95 (GCC 4.0.3 (g95 0.90!) Aug 22 2006)
> Copyright (C) 2002-2005 Free Software Foundation, Inc.
[snip]
> The f95.py file is located under Numpy as follows...
> C:\Program
> Files\ESI_Software\UTILS_2006\Python2.3_CFD\Lib\site-packages\numpy\distutils\fcompiler\f95.py

Looks like asking the Numpy folks might be a good idea ...

> 
> import os
> import sys
> 
> from numpy.distutils.cpuinfo import cpu
> from numpy.distutils.fcompiler import FCompiler
> 
> class G95FCompiler(FCompiler):
> 
> compiler_type = 'g95'
> version_pattern = r'G95.*\(GCC 4.0.3 \(g95!\) (?P.*)\).*'

That won't match the guff your f95 puts out. The "!)" appears *after* 
the version number. See below.

|>>> import re
|>>> guff = 'G95 (GCC 4.0.3 (g95 0.90!) Aug 22 2006) etc etc'
|>>> vp1 = r'G95.*\(GCC 4.0.3 \(g95!\) (?P.*)\).*'
|>>> vp2 = r'G95.*\(GCC 4.0.3 \(g95 (?P.*)!\).*'
|>>> m1 = re.match(vp1, guff)
|>>> print m1
None
|>>> m2 = re.match(vp2, guff)
|>>> print m2
<_sre.SRE_Match object at 0x00AED9E0>
|>>> print m2.group('version')
0.90
|>>>


> THE LINE ABOVE WAS ORIGINALLY:
> version_pattern = r'G95.*\(experimental \(g95!\)
> (?P" after "version" :-)

HTH,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating multiply arguments for a method.

2006-08-28 Thread noro

John Roth wrote:
> noro wrote:
> > Hi all,
> >
> > I use a method that accept multiply arguments ("plot(*args)").
> > so plot([1,2,3,4]) is accepted and plot([1,2,3,4],[5,6,7,8]) is also
> > accepted.
> >
> > the problem is that i know the number of arguments only at runtime.
> > Let say that during runtime i need to pass 4 arguments, each is a list,
> > creating a set of lists and passing it to the method wont word since
> > the interpartor thinks it is only 1 argument the contain a reference to
> > a "list of lists", instede of number of arguments, each is a list.
> >
> > any suggestions?
> > thanks
> > amit
>
> Why do you want to do this? You'll have to do some
> logic in your method body to determine how many
> operands you have whether you explicitly pass a list or
> whether you have the system break it apart into
> separate parameters.
>
> Fredrick Lund's solution, using an * parameter in the
> method definition, will produce a list that you have to
> pull apart in the method. Doing the same in the method
> call takes a single list of all of your parameters and then
> distributes it among the parameters in the definition.
>
> I wouldn't bother with either one. Passing a list of my
> real parameters as a single parameter is, in most
> circumstances, easier and IMO clearer.
>
> John Roth

I do not have much choise. I did not wirte the module, i just use it.

thank you all for the help, 
amit

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread gregarican
As I read in another post on this thread, do some initial scoping out
of either framework and pick the one that seems to suit your way of
thinking/coding the best. If you scan over some sample code on the
projects' websites you should get a basic idea of what they will be
like.

Although a bit more obscure than the two frameworks you are
considering, have you checked out Seaside (http://seaside.st)? It's a
Smalltalk framework that interests me personally. I've had the
opportunity to check it out briefly, but haven't had a chance to
actually mock up an app using it. If you check it out as well as a neat
AJAX library that can overlay it called Scriptaculous
(http://script.aculo.us) you can do some pretty slick things concisely.
I doubt that something like this will immediately skyrocket to the top
of the commercial developer's hit list, but it is something that I
would play around with since it will only expand my knowledge base. And
I can have fun while doing it :-)

Out of what I've seen working with Rails and checking out TurboGears I
chose Rails since it fit in with my way of thinking the best. Everyone
has their own taste so I wouldn't take any one person's (or one
group's) opinion. Read up on them a bit and see which one looks the
most interesting to you.

[EMAIL PROTECTED] wrote:
> First, I don't intend this to be a flame war, please. Python
> and Ruby are the only two languages I'd willingly work in
> (at least amongst common languages), and TurboGears and
> Rails seem roughly equivalent.
>
> I'm much more knowledgable about Python, but that's a minor
> issue--I've been intending to learn more Ruby anyway.
>
> Here are the pros and cons that I'm aware of and consider
> important:
>
> Turbogears:
> + SqlObject allows working with the DB tables without
> using SQL itself.
> + Likely to be faster because as far as I'm aware, Python
> is significantly faster.
> + Easy access to other libraries (such as the Python
> Imaging Library) that Ruby, being a relatively newer
> language, doesn't have equivalents to.
> + Built-in default SQLite makes it easier to set up?
> (as far as I can tell, Ruby requires MySql by default--don't
> know how easy this is to change.)
> + I find the templating system somewhat cleaner; code in
> py: xml namespace allows pure .html templates, instead
> of equivalent of .rhtml files.
>
> Ruby:
> + More mature system. More stable? More features?
> + Much better documented. This is a biggie.
> + Built-in Rubydoc system would make documenting the
> system easier. (IMHO, developers almost always
> underestimate the need for good documentation that
> is written along withe the system.) Is there a
> Python doc system that has received Guido's blessing
> yet? D'oxygen would seem an obvious choice.
> + Better coordination with Javascript helper code?
>
> I was initially leaning towards Rails due to maturity,
> but the most recent version of TurboGears seem to have
> fixed a lot of the "ad hoc" feeling I got from previous
> versions. But I'm still very much up in the air.
>
> Thanks,
> Ken
>
> P.S. If I wanted to provide an image by streaming the
> file data directly over the connection, rather than by
> referring to an image file, how would I do that? I'd
> like to build code that would allow images to be assembled
> into a single-file photo album (zip or bsddb file), and
> so can't refer to them as individual image files.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get the os file icon for a given content-type?

2006-08-28 Thread Paul Boddie
neoedmund wrote:

[File icons for a given content type]

> So what? Java 5.0 has the method, why python has not?

I'd be generally surprised if whichever Java API responsible for this
managed to work it out correctly for the different free desktop
environments (KDE, GNOME, etc.), partly because things like icon naming
and organisation have only been standardised relatively recently, and
partly because the heritage of Java's cross-platform capabilities would
suggest some suboptimal solution involving icons that are totally alien
to the actual desktop environment in use (or at best some icons for
GNOME) - something which would appear to be enough of a solution for
Windows developers, for example, but which would be blatantly
inappropriate for users of those other desktop environments. Still, I'd
be interested/impressed to learn otherwise, and I guess that this
project provides the API concerned:

https://jdic.dev.java.net/

There is a package for Python which supports the different
freedesktop.org standards, but I'm not sure whether it provides exactly
the support requested:

http://freedesktop.org/wiki/Software/pyxdg

Generally, desktop integration in Python's standard library has been
restricted to things like Web browser invocation, but I'd like to
expand the desktop module to include other common desktop environment
facilities:

http://www.python.org/pypi/desktop

In short, there is probably no standard library solution for this
problem. Cross-platform frameworks like PyQt may offer access to
desktop information, but I'm not completely convinced of that. I
suppose we all just have to work a bit harder to address this need.

Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f2py on windows XP - "Unknown Switch"??

2006-08-28 Thread Sile
Thanks John,

Your help is very much appreciated - my f2py finally recognises my
fortran compiler - I'm very relieved!

>
> That won't match the guff your f95 puts out. The "!)" appears *after*
> the version number. See below.
>
> |>>> import re
> |>>> guff = 'G95 (GCC 4.0.3 (g95 0.90!) Aug 22 2006) etc etc'
> |>>> vp1 = r'G95.*\(GCC 4.0.3 \(g95!\) (?P.*)\).*'
> |>>> vp2 = r'G95.*\(GCC 4.0.3 \(g95 (?P.*)!\).*'

I changed my g95 file so that version_pattern was correct.
>
> > THE LINE ABOVE WAS ORIGINALLY:
> > version_pattern = r'G95.*\(experimental \(g95!\)
> > (?P
> No it wasn't. It would have had a ">" after "version" :-)
oops!

Many thanks again,

Sile

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread skip

boris> I am using the Python DB API for access to MySQL. But it is not
boris> platform-independent - I need a module not included in Python by
boris> default - python-mysql, and it uses a compiled binary
boris> _mysql.so. So it is not platform-independent because for each
boris> web-server on different platform, I would have to download it and
boris> extra compile it specifically for that platform. Do you know of
boris> any Python solution for MySQL access that is 100%
boris> platform-independent?

I don't think you mean "platform-independent".  I suspect you mean
"batteries included".  Prior to the release of Python 2.5, no modules to
access SQL databases were distributed with core Python.  Starting with 2.5,
sqlite access will be available:

>>> import sqlite3
>>> sqlite3.__file__
'/Users/skip/local/lib/python2.5/sqlite3/__init__.pyc'

So, if what you were really asking was "what SQL databases can I access
without installing any software other than Python?", then the answer is "No
SQL databases were distributed with Python prior to 2.5.  Starting with
Python 2.5, access to sqlite databases is available by default."  Python 2.5
is due out soon (according to PEP 356, on 12 September).

The still-officially-in-development-but-almost-certainly-frozen
documentation for the sqlite3 module is here:

http://docs.python.org/dev/lib/module-sqlite3.html

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


TNEF decoder

2006-08-28 Thread David Isaac
I'm aware of
http://cheeseshop.python.org/pypi/pytnef/
but it uses the tnef utility, and I'd like a pure Python solution
(along the lines of  http://www.freeutils.net/source/jtnef/ ).

Is there one?

Thanks,
Alan Isaac


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML parsing and writing

2006-08-28 Thread uche . ogbuji
c00i90wn wrote:
> Nice package ElementTree is but sadly it doesn't have a pretty print,
> well, guess I'll have to do it myself, if you have one already can you
> please give it to me? thanks :)

FWIW Amara and plain old 4Suite both support pretty-print, canonical
XML print and more such options.

http://uche.ogbuji.net/tech/4suite/amara/
http://4Suite.org

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Rob Williscroft
Claudio Grondi wrote in news:[EMAIL PROTECTED] in
gmane.comp.python.general: 

> Tim Roberts wrote:
>> "Tim Peters" <[EMAIL PROTECTED]> wrote:

>> 
>> It is much simpler than that.  With a multiprocessor HAL, including
>> on a dual-core or hyperthreaded system, QueryPerformanceCounter
>> returns the raw cycle counter (RDTSC).  However, on Windows XP, the
>> operating system does not synchronize the cycle counters on multiple
>> processors, and they can be actually be millions of cycles apart.
>> 
>> This was a change from previous systems.  On NT4 and Win2000, the
>> operating actually rewrote the cycle counters on the second (and
>> beyond) processors to align them to the first processor, so the delta
>> was usually only a dozen or two cycles.  XP does not appear to do
>> that.  I think that is a huge mistake, since it renders
>> QueryPerformanceCounter non-monotonic. 
> 
> How does it come, that processors on same mainboard run at different 
> speeds? Do they have separate clock-pulse generators?

I don't see any claim above that they run at different speeds, only 
that the counters are several million cycles apart, IOW running at the 
same speed but with different initial values, or more likely starting 
at different times. 

For processors that run at (say) 2GHz, several million (say 10 million) 
represents a difference of 10e6/2e9 = 0.005 seconds between when the 
processors were sufficiently powered up to start counting cycles.

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


rollover effect

2006-08-28 Thread Sorin Schwimmer
Hi,

For the right-click event, you should use a bind to
. If you have a new version of Python,
chances are that you already have Tix installed. Tix,
like Pmw, is an extension package for Tkinter, and it
also offers a Balloon widget.

See the following example:


from Tix import *

r=Tk()
l=Label(r,text='This is my label')

def fn(e):
  global l
  print 'Right clicked :-)'

l.bind('',fn)
l.grid()
b=Balloon(r)
b.bind_widget(l,balloonmsg='text in balloon')

r.mainloop()


If you're a beginer, than you may want to have a look
to some of the following links regarding Tkinter and
extensions:

http://www.pythonware.com/library/tkinter/introduction/index.htm
http://infohost.nmt.edu/tcc/help/pubs/tkinter/
http://www.ferg.org/thinking_in_tkinter/index.html
http://mail.python.org/pipermail/tkinter-discuss/
http://www.3dartist.com/WP/python/tknotes.htm
http://tkinter.unpy.net/wiki/FrontPage
http://www.faqts.com/knowledge_base/index.phtml/fid/264
http://pmw.sourceforge.net/doc/index.html
http://heim.ifi.uio.no/~hpl/Pmw.Blt/doc/
http://pmwcontribd.sourceforge.net/
http://tcltk.free.fr/blt/
http://tkinter.unpythonic.net/bwidget/BWman/
http://tcltk.free.fr/Bwidget/
http://tktreectrl.sourceforge.net/treectrl.html
http://tix.sourceforge.net/docs.shtml
http://groups.yahoo.com/group/tix/messages/1
http://cvs.sourceforge.net/viewcvs.py/tkta
http://www.tkzinc.org/ble/
http://tktreectrl.sourceforge.net/Understanding
TkTreeCtrl.html
http://cvs.sourceforge.net/viewcvs.py/*checkout*/tktable/tile-www/doc/index.html
http://wiki.tcl.tk/6172http://www.faqts.com/knowledge_base/view.phtml/aid/3728
http://www.faqts.com/knowledge_base/view.phtml/aid/3728

I see I have a rather long list of bookmarks ;-)

I hope this helps.

Sorin

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Boris Dušek

Bruno Desthuilliers wrote:
> bobrik wrote:
> > Hello,
> >
> > I am using the Python DB API for access to MySQL. But it is not
> > platform-independent
>
> It is. You don't have to change your Python code according to the OS or
> CPU.
>
What I mean is that wiht platform-independent access, I should be able
to not care on which operating system is the web server accessing my
scripts where I use MySQLdb which I have to install (and therfore
platform-dependently) compile myself. The important point is that
MySQLdb is installed as an extra module. So you have to compile it
manually, but what if the OS with server accessing the site that is on
shared area changes?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Sam Smoot
fuzzylollipop wrote:
> uh, no, Python predates Ruby by a good bit
> Rails might be "older" than Turbogears but it still JUST went 1.0
> officially.

Wow that's a lot of FUD, especially since you're beating up on Rails
for it's docs and maturity, when I doubt (but couldn't prove)
turbogears comes close.

Lets be specific:

12/13/05: http://dev.rubyonrails.org/changeset/3303

> It can't be called "mature' by any defintition.

It's easy to deploy a site without running into bugs as long as you're
not dealing with any edge-cases. As far as OSS solutions go, that
pretty well fits my definition of "mature". So there's one.

> Rails has no documentation, period. The authors acknowledge this
> openly.

Why you would just talk out of your ass like this escapes me.

http://api.rubyonrails.org (Look at any of the :Base classes for
overviews)
http://rubydoc.org (For basic Ruby help)
http://rails.techno-weenie.net/ (Help with the lesser known areas of
RoR, and tips & tricks)
http://www.bigbold.com/snippets/tags/rails (Snippets other people have
found useful)
http://wiki.rubyonrails.com/rails/pages/Howtos (Lots of "Getting
Started" type how-tos)
http://caboo.se (A blog aggregation of some of the committer's )

Then again, you could just google for "rails documentation" (here's a
link:
http://www.google.com/search?client=safari&rls=en&q=rails+documentation&ie=UTF-8&oe=UTF-8
)

And the top link will take you to a page on the Wiki that describes all
of this. Until you want to start writing plugins and such, this
documentation pretty much fits the bill. Could there be more? Yes. Is
it perfect? Obviously not. Is finding documentation going to be a
problem for anyone willing to spend a few minutes with Google or on IRC
asking questions if you're genuinely trying? I seriously doubt it.

> again, Ruby can't be considered 'mature' by any definition.

It seems like you're the one confusing things now. Ruby is obviously a
pretty mature language. There are definite feature holes (encoding
aware Strings, native Threads), but the community, documentation,
tutorials (by far the best of any language I've learned), are all
pretty mature.

Is Rails mature? Compared to JSP? Probably not... compared to
TurboGears? (The entire point of this topic, which you conveniently
side-step by managing to not mention it once) Easily.

So if you decide to reply, might I suggest spending a few minutes with
Google to get your facts straight next time? Oh, and keeping an eye on
the actual topic might be a good idea too.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Claudio Grondi
Rob Williscroft wrote:
> Claudio Grondi wrote in news:[EMAIL PROTECTED] in
> gmane.comp.python.general: 
> 
> 
>>Tim Roberts wrote:
>>
>>>"Tim Peters" <[EMAIL PROTECTED]> wrote:
> 
> 
>>>It is much simpler than that.  With a multiprocessor HAL, including
>>>on a dual-core or hyperthreaded system, QueryPerformanceCounter
>>>returns the raw cycle counter (RDTSC).  However, on Windows XP, the
>>>operating system does not synchronize the cycle counters on multiple
>>>processors, and they can be actually be millions of cycles apart.
>>>
>>>This was a change from previous systems.  On NT4 and Win2000, the
>>>operating actually rewrote the cycle counters on the second (and
>>>beyond) processors to align them to the first processor, so the delta
>>>was usually only a dozen or two cycles.  XP does not appear to do
>>>that.  I think that is a huge mistake, since it renders
>>>QueryPerformanceCounter non-monotonic. 
>>
>>How does it come, that processors on same mainboard run at different 
>>speeds? Do they have separate clock-pulse generators?
> 
> 
> I don't see any claim above that they run at different speeds, only 
> that the counters are several million cycles apart, IOW running at the 
> same speed but with different initial values, or more likely starting 
> at different times. 
> 
> For processors that run at (say) 2GHz, several million (say 10 million) 
> represents a difference of 10e6/2e9 = 0.005 seconds between when the 
> processors were sufficiently powered up to start counting cycles.
> 
> Rob.

If it were so, than why can't the delta of time between the processors 
be set to exact zero?
I assume, that it is known how many cycles adjusting the value will 
take, so it could be done exactly ... hmmm ...

Claudio Grondi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Boris Dušek
[EMAIL PROTECTED] wrote:
> I don't think you mean "platform-independent".  I suspect you mean
> "batteries included".  Prior to the release of Python 2.5, no modules to
> access SQL databases were distributed with core Python.  Starting with 2.5,
> sqlite access will be available:
>
> >>> import sqlite3
> >>> sqlite3.__file__
> '/Users/skip/local/lib/python2.5/sqlite3/__init__.pyc'
>
> So, if what you were really asking was "what SQL databases can I access
> without installing any software other than Python?", then the answer is "No
> SQL databases were distributed with Python prior to 2.5.  Starting with
> Python 2.5, access to sqlite databases is available by default."  Python 2.5
> is due out soon (according to PEP 356, on 12 September).

Yes, you excactly got my point. The thing is that I can't rely on
Python 2.5 to be installed soon.
So the only solution for me at this moment is to use jython and from
there use Java JDBC API (sorry :-) But it would be great if the Python
DB API compliant-modules would become parts of core python quickly.
Python DB API itself is a great thing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Fredrik Lundh
Boris Dušek wrote:

> So the only solution for me at this moment is to use jython and from
> there use Java JDBC API (sorry :-) 

so who installed Java for you?



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Diez B. Roggisch
> 
> Yes, you excactly got my point. The thing is that I can't rely on
> Python 2.5 to be installed soon.
> So the only solution for me at this moment is to use jython and from
> there use Java JDBC API (sorry :-) But it would be great if the Python
> DB API compliant-modules would become parts of core python quickly.
> Python DB API itself is a great thing.

They won't be. The reason that sqlite is is because it is self-contained.
But your average DB itself you need to install using a platform-specific
build. And building the the extensions even requires proprietary libraries
installed (think of oracle) - so without having installed a dozen or more
DBs, no one could build python!

So - no chance that this will ever happen. The only thing you could do is to
try and convince the DB-vendors to provide pure python DB drivers - as they
do it for java.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Grant Edwards
On 2006-08-28, Claudio Grondi <[EMAIL PROTECTED]> wrote:

>> I don't see any claim above that they run at different speeds, only 
>> that the counters are several million cycles apart, IOW running at the 
>> same speed but with different initial values, or more likely starting 
>> at different times. 
>> 
>> For processors that run at (say) 2GHz, several million (say 10 million) 
>> represents a difference of 10e6/2e9 = 0.005 seconds between when the 
>> processors were sufficiently powered up to start counting cycles.

> If it were so, than why can't the delta of time between the processors 
> be set to exact zero?

This is 

> I assume, that it is known how many cycles adjusting the value will 
> take, so it could be done exactly ... hmmm ...
>
> Claudio Grondi


-- 
Grant Edwards   grante Yow!  LIFE is a
  at   never-ending INFORMERCIAL!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Fredrik Lundh
Claudio Grondi wrote:

> If it were so, than why can't the delta of time between the processors 
> be set to exact zero?

someone just wrote:

 This was a change from previous systems.  On NT4 and Win2000, the
 operating actually rewrote the cycle counters on the second (and
 beyond) processors to align them to the first processor, so the delta
 was usually only a dozen or two cycles.  XP does not appear to do
 that.  I think that is a huge mistake, since it renders
 QueryPerformanceCounter non-monotonic. 

so if you really want to know, you may have to ask microsoft.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Bruno Desthuilliers
Boris Dušek wrote:
> Bruno Desthuilliers wrote:
>> bobrik wrote:
>>> Hello,
>>>
>>> I am using the Python DB API for access to MySQL. But it is not
>>> platform-independent
>> It is. You don't have to change your Python code according to the OS or
>> CPU.
>>
> What I mean is that wiht platform-independent access, I should be able
> to not care on which operating system is the web server accessing my
> scripts where I use MySQLdb 

When it comes to *using* MySQLdb, you don't care about the OS, CPU and
whatnot.

> which I have to install (and therfore
> platform-dependently) compile myself. 

This is a very distinct problem.

> The important point is that
> MySQLdb is installed as an extra module. So you have to compile it
> manually,

Usually, cd  && python setup.py install do the job.

> but what if the OS with server accessing the site that is on
> shared area changes?

And what if Python is not installed on it ?-)

Seriously, do you think that hosting companies swap OS very often ?

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


unit test for a printing method

2006-08-28 Thread noro
What is the proper way to test (using unit test) a method that print
information?
for example:

def A(s):
 print '---'+s+'---'

and i want to check that A("bla") really print out "---bla---"

thanks
amit

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Fredrik Lundh
> so if you really want to know, you may have to ask microsoft.

footnote: judging from

 http://support.microsoft.com/?id=896256

this might be related to advanced power management features in XP.  that 
note also mentions a hotfix for this.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit test for a printing method

2006-08-28 Thread Fredrik Lundh
noro wrote:

> What is the proper way to test (using unit test) a method that print
> information?
> for example:
> 
> def A(s):
>  print '---'+s+'---'
> 
> and i want to check that A("bla") really print out "---bla---"

http://docs.python.org/lib/module-doctest.html



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit test for a printing method

2006-08-28 Thread Diez B. Roggisch
noro wrote:

> What is the proper way to test (using unit test) a method that print
> information?
> for example:
> 
> def A(s):
>  print '---'+s+'---'
> 
> and i want to check that A("bla") really print out "---bla---"

You can replace sys.stdout with a cStringIO-object or any other
file-protocol implementing object and such collect the data.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.clock() going backwards??

2006-08-28 Thread Grant Edwards
On 2006-08-28, Grant Edwards <[EMAIL PROTECTED]> wrote:

>>> For processors that run at (say) 2GHz, several million (say 10
>>> million) represents a difference of 10e6/2e9 = 0.005 seconds
>>> between when the processors were sufficiently powered up to
>>> start counting cycles.
>
>> If it were so, than why can't the delta of time between the
>> processors be set to exact zero?
>
> This is 

Oops.  Hit the wrong key.  I meant to say:

This is a _Microsoft_Product_.  There doesn't have to be a
reason for something to be done in a half-assed manner.

>> I assume, that it is known how many cycles adjusting the value
>> will take, so it could be done exactly

Yup.

-- 
Grant Edwards   grante Yow!  People humiliating
  at   a salami!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Operator Overloading Basics

2006-08-28 Thread Mohit Bhatt








Hello,

I just started out with python(
couple of weeks).

I have a query regarding Operator
Overloading

 

class c1:

    def
__init__(self,value):

    self.data
= "">

    def
__add__ (self,operand2):

    self.data
+= operand2

 

obj1 = c1(1)

obj1 + 10 # this works just fine

10 + obj1 # throws exception

 

Exception Details

Traceback (most
recent call last):

  File
"", line 1, in -toplevel-

   
10+ obj1

TypeError:
unsupported operand type(s) for +: 'int' and 'instance'

 

    Q.
What do I have to do to make the following line work?

 

        10
+ obj1

 

Thanks and regards

Mohit

 

    






-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pros/Cons of Turbogears/Rails?

2006-08-28 Thread Adam Jones
In my understanding, which relies completely on the judgements of
co-workers regarding the rails side of the debate, TurboGears is more
flexible. Tasks which fall inside the scope of Rails' "opinion" are
probably easier there, but anything outside of what Rails was built to
do is harder than equivalent deviations from TurboGears. Obviously this
amounts to little more than hearsay, but nonetheless I think it is an
important element to look into.

I can say that each of them has their own genius decisions, and neither
is so lacking in documentation or community support to preclude
choosing either framework based on how well it suits your project.

-- 
http://mail.python.org/mailman/listinfo/python-list


Desktop Notification/Alerts In Python

2006-08-28 Thread Chaos
I am looking for ways to have a Desktop Alert, like the one most IM
Messengers have (MSN, AIM) at the lower right above the taskbar. Can
anyone point me to the right resources to use?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Steve Holden
Bruno Desthuilliers wrote:
> Boris Dušek wrote:
> 
>>Bruno Desthuilliers wrote:
>>
>>>bobrik wrote:
>>>
Hello,

I am using the Python DB API for access to MySQL. But it is not
platform-independent
>>>
>>>It is. You don't have to change your Python code according to the OS or
>>>CPU.
>>>
>>
>>What I mean is that wiht platform-independent access, I should be able
>>to not care on which operating system is the web server accessing my
>>scripts where I use MySQLdb 
> 
> 
> When it comes to *using* MySQLdb, you don't care about the OS, CPU and
> whatnot.
> 
> 
>>which I have to install (and therfore
>>platform-dependently) compile myself. 
> 
> 
> This is a very distinct problem.
> 
> 
>>The important point is that
>>MySQLdb is installed as an extra module. So you have to compile it
>>manually,
> 
> 
> Usually, cd  && python setup.py install do the job.
> 
> 
>>but what if the OS with server accessing the site that is on
>>shared area changes?
> 
> 
> And what if Python is not installed on it ?-)
> 
> Seriously, do you think that hosting companies swap OS very often ?
> 
Well, GoDaddy just switched enough domains from Linux to Windows to make 
a significant difference to the Internet hosting statistics, and were 
allegedly paid handsomely by Microsoft to do it, but those were parked 
domains.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Operator Overloading Basics

2006-08-28 Thread Fredrik Lundh
Mohit Bhatt wrote:
> Hello,
> 
> I just started out with python( couple of weeks).
> 
> I have a query regarding Operator Overloading
> 
> class c1:
> def __init__(self,value):
> self.data = value
> def __add__ (self,operand2):
> self.data += operand2
> 
> obj1 = c1(1)
> obj1 + 10 # this works just fine

it modifies obj1, so I'm not sure I agree that it works fine.  but sure, 
it doesn't raise an exception.

> 10 + obj1 # throws exception
> 
> Exception Details
> 
> Traceback (most recent call last):
>   File "", line 1, in -toplevel-
> 10+ obj1
> 
> TypeError: unsupported operand type(s) for +: 'int' and 'instance'
> 
> Q. What do I have to do to make the following line work?
> 
>   10 + obj1

define "work".

if you want it to modify obj1 (and thus confuse the heck out of anyone 
trying to use your class), implement __radd__.

if you want to create a sane accumulator, I recommend implementing += 
assignment instead, by overloading __iadd__ instead of __add__.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Boris Dušek

Bruno Desthuilliers wrote:

> > but what if the OS with server accessing the site that is on
> > shared area changes?
>
> And what if Python is not installed on it ?-)
>
> Seriously, do you think that hosting companies swap OS very often ?

No, I don't. But I was trying to find the best solution. :-)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Operator Overloading Basics

2006-08-28 Thread Tim Chase
> obj1 = c1(1)
> 
> obj1 + 10 # this works just fine
> 
  10 + obj1 # throws exception

> Q. What do I have to do to make the following line work?
> 
> 10 + obj1


http://docs.python.org/ref/numeric-types.html

You want to read the section on __radd__ (and it's other 
__r[whatever]__ variants)

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode "table of character" implementation in python

2006-08-28 Thread Martin v. Löwis
Nicolas Pontoizeau schrieb:
> I am handling a mixed languages text file encoded in UTF-8. Theres is
> mainly French, English and Asian languages. I need to detect every
> asian characters in order to enclose it by a special tag for latex.
> Does anybody know if there is a unicode "table of character"
> implementation in python? I mean, I give a character and python replys
> me with the language in which the character occurs.

This is a bit unspecific, so likely, nothing that already exists will
be completely correct for your needs. If you need to escape characters
for latex, I would expect that there is a more precise specification
of what you need to escape - I doubt the fact that a character is used
primarily in Asia matters much to latex.

In any case, somebody pointed you to the Unicode code blocks. I think
these are Asian scripts (I may have missed some):

0530..058F; Armenian
0590..05FF; Hebrew
0600..06FF; Arabic
0700..074F; Syriac
0750..077F; Arabic Supplement
0900..097F; Devanagari
0980..09FF; Bengali
0A00..0A7F; Gurmukhi
0A80..0AFF; Gujarati
0B00..0B7F; Oriya
0B80..0BFF; Tamil
0C00..0C7F; Telugu
0D00..0D7F; Malayalam
0D80..0DFF; Sinhala
0E00..0E7F; Thai
0E80..0EFF; Lao
0F00..0FFF; Tibetan
1000..109F; Myanmar
10A0..10FF; Georgian
1100..11FF; Hangul Jamo
1780..17FF; Khmer
1800..18AF; Mongolian
1900..194F; Limbu
1950..197F; Tai Le
1980..19DF; New Tai Lue
19E0..19FF; Khmer Symbols
2D00..2D2F; Georgian Supplement
2E80..2EFF; CJK Radicals Supplement
2F00..2FDF; Kangxi Radicals
2FF0..2FFF; Ideographic Description Characters
3000..303F; CJK Symbols and Punctuation
3040..309F; Hiragana
30A0..30FF; Katakana
3100..312F; Bopomofo
3130..318F; Hangul Compatibility Jamo
3190..319F; Kanbun
31A0..31BF; Bopomofo Extended
31C0..31EF; CJK Strokes
31F0..31FF; Katakana Phonetic Extensions
3200..32FF; Enclosed CJK Letters and Months
3300..33FF; CJK Compatibility
3400..4DBF; CJK Unified Ideographs Extension A
4DC0..4DFF; Yijing Hexagram Symbols
4E00..9FFF; CJK Unified Ideographs
A000..A48F; Yi Syllables
A490..A4CF; Yi Radicals
AC00..D7AF; Hangul Syllables
F900..FAFF; CJK Compatibility Ideographs
FB50..FDFF; Arabic Presentation Forms-A
FE30..FE4F; CJK Compatibility Forms
FE70..FEFF; Arabic Presentation Forms-B
2..2A6DF; CJK Unified Ideographs Extension B
2F800..2FA1F; CJK Compatibility Ideographs Supplement

Notice that some scripts are used both in Asia and elsewhere,
e.g. Latin and Cyrillic. Arabic probably doesn't belong in
this list, either, being used both in Asia and elsewhere
as the script of the official language.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: libcurses.so & installing Python 2.4.3

2006-08-28 Thread Martin v. Löwis
dmulcahy schrieb:
> I am trying to build the binaries for Python 2.4.3 on a Sun E6900
> running SPARC Solaris 9 and using gcc 3.4.2.
> 
> When the makefile tries to build the _curses extension it fails with a
> symbol referencing error on "mvwgetnstr", which it appears should exist
> in libcurses.so.  For some reason it seems this function does not exist
> in the version of libcurses.so shipped with Solaris 9.
> 
> Will I find it in some other library on Solaris or do I need to
> download a different version of libcurses.so?

Neither, nor. You will need to port the curses module to Solaris 9
(if you really need it).

I believe in the subversion trunk of Python (and in Python 2.5),
this problem is fixed.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-28 Thread Martin v. Löwis
Fredrik Lundh schrieb:
>> Is there any way to force the actual python site-lib for M$ installers
> 
> it's spelled "Windows installers"

I want to second this. It was me who created the installer, and I don't
like to see my name abbreviated as M$ (if you think you should write
out the name of the MSI creator, please say "Martin's installer" :-).

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about class, functions and scope

2006-08-28 Thread Gabriel G

At Saturday 26/8/2006 06:13, nephish wrote:


i have an app that runs three classes as threads in the same program.
some of them need to be able to share some functions. Can i set a
function before i define a class and have the class use it ? Kinda like
this.

def some_function(var1, var2):
do something with var1, var2
return result


It's ok - but beware of concurrency problems. By example, two threads 
trying to update the  same thing. (Doesn't happen in your small example).




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how to get the os file icon for a given content-type?

2006-08-28 Thread Martin v. Löwis
Paul Boddie schrieb:
> neoedmund wrote:
> 
> [File icons for a given content type]
> 
>> So what? Java 5.0 has the method, why python has not?
> 
> I'd be generally surprised if whichever Java API responsible for this
> managed to work it out correctly for the different free desktop
> environments (KDE, GNOME, etc.)

Just because nobody said it so far (although it's probably obvious
to everybody): I doubt neoedmund is talking about free desktop
environments...

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Truly platform-independent DB access in Python?

2006-08-28 Thread Boris Dušek

Dennis Lee Bieber wrote:
> On 28 Aug 2006 00:01:06 -0700, "bobrik" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
> > for that platform. Do you know of any Python solution for MySQL access
> > that is 100% platform-independent?
> >
>   Subprocess module invoking the MySQL command line utilities? Of
> course, parsing the results will be painful...
> --
>   WulfraedDennis Lee Bieber   KD6MOG
>   [EMAIL PROTECTED]   [EMAIL PROTECTED]
>   HTTP://wlfraed.home.netcom.com/
>   (Bestiaria Support Staff:   [EMAIL PROTECTED])
>   HTTP://www.bestiaria.com/

Hmm, that is very interesting; and parsing won't be IMHO such a problem
if the columns will be tab-separated. Thanks for your tip!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: DirectPython

2006-08-28 Thread Heikki Salo
Jérôme Le Bougeant wrote:
> Hello,
> 
> I have DirectPython 0.5 (http://directpython.sourceforge.net/) and python2.4 
> (directx9.0C installed).
> Samples do not work, I have this error : "RuntimeError: Failed to create a
> device"
> For example with sampleBasic.py :
> 
> Traceback (most recent call last):
>   File "sampleBasic.py", line 147, in ?
> mainloop()
>   File "sampleBasic.py", line 75, in mainloop
> d3d.createDevice(title, u"textures/x.ico", window[2], window[3], False,
> CREATE.HARDWARE)
> RuntimeError: Failed to create a device
> 
> 
> Why ?
> 
> please help me... any help would be appreciated.
> Thanks
> 
> 

I guess that you have pretty old or some cheap integrated 
graphics card. Either that or you should upgrade your drivers. 
createDevice() tests if some basic requirements are met and 
fails if they are not.

You can try to use CREATE.SOFTWARE | CREATE.NOCAPCHECK 
combination to pass these checks, but most of the advanced 
samples probably don't work.

--
Heikki Salo
-- 
http://mail.python.org/mailman/listinfo/python-list


Detecting window focus events in PyGTK

2006-08-28 Thread Peter TB Brett
Hi folks,

I'm currently trying to work out how to detect when a PyGTK window
receives the focus from the window manager -- I assume that it must
receive some kind of X event, but I can't work out which signal it
generates. Searching around the subject on the web doesn't seem to pull up
anything useful.

I tried the "focus" signal, but that doesn't work the way I'd like it
to. For example, the following code only prints the message "Received
focus!" once (immediately after startup) even when it _isn't_ the active
window.


#!/usr/bin/env python
import pygtk
pygtk.require('2.0')

import gtk

def event_focus(widget, direction):
print "Received focus!"

window = gtk.Window()
window.set_size_request(100, 100)
window.connect("focus", event_focus)
window.show_all()
gtk.main()


I suspect that I'm hacking in the wrong place, so any hints or tips much
appreciated!

Thanks,

Peter

-- 
v2sw6YShw7$ln5pr6ck3ma8u6/8Lw3+2m0l7Ci6e4+8t4Eb8Aen5+6g6Pa2Xs5MSr5p4
  hackerkey.com

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >