Re: Submitting change requests through correct channels

2006-12-05 Thread Fredrik Lundh
Ben Finney wrote:

> I hope that, instead, it's possible to perform the research needed to
> describe the requested change, submit it as an email or online form

are you perhaps volunteering to help setup and monitoring such a sub- 
mission channel ?

it's a certain amount of work to keep out the spammers and scammers, as 
should be obvious for anyone who's looked at an unmonitored wiki or bug 
tracker (or looked at his mail program's spam folder), but nothing that 
cannot be fit into a reasonably structured developer's daily routine.



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


The del statement

2006-12-05 Thread Marco Aschwanden
Hi

I was wondering whether the del statment was going to stay in Python3000?

It is a bit awkward to use the del statement where a method call would do  
the same without the need for a new keyword.

del list[elem]
del map[elem]

Where

list.del(elem)
map.del(elem)

would achieve the same result (and I think, this is what happens in the  
backend).

The same discussion was done for the "external" len-function (list.len()  
vs. len(list)).

I don't dare to say that the del-keyword is superflous, but I would like  
to know the pros and cons of the external keyword approach.

Greetings,
Marco

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


Re: The del statement

2006-12-05 Thread Fredrik Lundh
Marco Aschwanden wrote:

> Where
> 
> list.del(elem)
> map.del(elem)
> 
> would achieve the same result (and I think, this is what happens in the  
> backend).

so what about

 del x

?

> The same discussion was done for the "external" len-function (list.len()  
> vs. len(list)).

for the curious, guido's rationale for len() can be found here:

   http://preview.tinyurl.com/y6vavp



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


Re: No module named _db2

2006-12-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> For some reason the _db2 module cannot be imported. Have you had this
> issue before?

my guess is that _db2 is a binary driver module used by the DB2.py 
module.  did you follow the installation instructions carefully ?
have you looked for _db2.so or _db2module.so files on your machine ?



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


Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol [EMAIL PROTECTED] referenced in function _make_buildinfo2

2006-12-05 Thread f rom


- Forwarded Message 
From: Josiah Carlson <[EMAIL PROTECTED]>
To: f rom <[EMAIL PROTECTED]>; [EMAIL PROTECTED]
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved 
external symbol [EMAIL PROTECTED] referenced in function _make_buildinfo2


Ask on [email protected] .

 - Josiah

f rom <[EMAIL PROTECTED]> wrote:
> I am trying to debug a segfault which I can not pin down with a simple pytjon 
> script. 
> For this I have downloaded the free Microsoft visual express c++.
> However I am having problems building python2.5.
> Anyone have experience with this ?  
> 
> 1>-- Rebuild All started: Project: make_buildinfo, Configuration: Debug 
> Win32 --
> 1>Deleting intermediate and output files for project 'make_buildinfo', 
> configuration 'Debug|Win32'
> 1>Compiling...
> 1>make_buildinfo.c
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(43) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(47) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(63) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(66) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(69) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(72) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(73) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(81) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(83) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(84) : warning C4996: 'strcat' was 
> declared deprecated
> 1>c:\program files\microsoft visual studio 8\vc\include\string.h(78) 
> : see declaration of 'strcat'
> 1>Message: 'This function or variable may be unsafe. Consider using 
> strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See 
> online help for details.'
> 1>d:\python-2.5\pcbuild8\make_buildinfo.c(88) : warning C4996: 'unlink' was 
> declared deprecated
> 1>c:\program

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread [EMAIL PROTECTED]


Fredrik Lundh  wrote:

> import os
> for line in os.popen("grep pattern *.txt"):
> print line,
>
> also see os.system and subprocess.
>
> note that if you want to write portable code, you can implement your own
> "grep" using the "re" module:

> 

Also, for a wrapper around popen, try commands:

  import commands

  pattern = raw_input('pattern to search? ')
  print commands.getoutput('grep %s *.txt' % pattern)

Pete

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


Re: Opening colour BMPs with PIL

2006-12-05 Thread Fredrik Lundh
Craig wrote:

> I'm trying to open colour BMPs using PIL and I'm getting the following
> errors.

what program did you use to produce those BMP files?  can you prepare 
reasonably small samples using the same program and post them somewhere?



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


Re: Printing unix Line endings from Windows.

2006-12-05 Thread Ant

Larry Bates wrote:

> Ant wrote:
...
> > Is there any way of doing this without having to post-process the file
> > in binary mode (a-la the crlf.py script)
...
> You can write to a new file and create your own line endings.
> When done, delete the original file and rename the output file.

How can I create my own line endings? I've tried setting os.linesep =
"\n",  (and to \x0a). I've tried things like:

print "xxx yyy \n",
print "xxx uuu \x0a",
filehandle.write("xxx \n")
filehandle.write("xxx \x0a")

and all of these give me a nice windows-style crlf!

Surely there must be a way to do this ...

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


Re: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol [EMAIL PROTECTED] referenced in function _make_buildinfo2

2006-12-05 Thread Fredrik Lundh
f rom wrote:

>> 1>make_buildinfo.obj : error LNK2019: unresolved external symbol [EMAIL 
>> PROTECTED] referenced in function _make_buildinfo2
>> 1>make_buildinfo.obj : error LNK2019: unresolved external symbol [EMAIL 
>> PROTECTED] referenced in function _make_buildinfo2

you need to link with Advapi32.dll; see:

http://msdn.microsoft.com/library/en-us/sysinfo/base/regqueryvalueex.asp



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


Re: The del statement

2006-12-05 Thread Marco Aschwanden
> so what about
>
>  del x

Ups. I never used it for an object. So far I only used it for deletion of  
elements of a container. In that case del has two purposes:

1. Deletes an item from a container (and of course destructs it) -->  
list.remove(elem)
2. Calls the destructor of an object --> list.destruct()

One statement and two distinct purposes. Why not having two "standard"  
function (for containers we have a remove-function) and all objects have a  
destruct-function. Still no need for a del keyword.

A del keyword that calls the destructor... well that is okay (it could be  
handled without). I am used to see the del keyword in opposition to the  
new keyword (which does not exist/is implicit in Python).

The del keyword for removing an element in a container is a bit awkward to  
me.

I am not as knowledgeable about languages as you are and I am hoping  
people like you can enlighten me about the language decision taken.

> for the curious, guido's rationale for len() can be found here:
>
>http://preview.tinyurl.com/y6vavp

Thanks for the hint.
Marco

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


Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Also, for a wrapper around popen, try commands:
> 
>   import commands
> 
>   pattern = raw_input('pattern to search? ')
>   print commands.getoutput('grep %s *.txt' % pattern)

that's not quite as portable as the other alternatives, though.  "grep" 
is at least available for non-Unix platforms, but "commands" requires a 
unix shell.

for Python 2.5 and later, you could use:

def getoutput(cmd):
from subprocess import Popen, PIPE, STDOUT
p = Popen(cmd, stdout=PIPE, stderr=STDOUT,
   shell=isinstance(cmd, basestring))
return p.communicate()[0]

print getoutput(["grep", pattern, glob.glob("*.txt")])

which, if given a list instead of a string, passes the arguments
right through to the underlying process, without going through the
shell (consider searching for "-" or ";rm" with the original code).



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


Re: decorators question

2006-12-05 Thread Duncan Booth
"king kikapu" <[EMAIL PROTECTED]> wrote:

> Hmmm...ok...it calls the decorator but when ?? It (the runtime) loads
> the .py file and start to call every decorator
> it finds on it, regardless of the existance of code that actually calls
> the decorated functions ??
> I understand thet Python does not call the decoratated functiond but it
> ends up this way...

Try this code to help you understand what is going on:

--- t.py 
import inspect

def adecorator(f):
print "decorating", f.__name__, inspect.getargspec(f)
return f

def makeargument(n):
print "makeargument", n, "called"
return n

print "for loop coming up"
for i in range(3):
print "in for loop, iteration", i
@adecorator
def fn(x=makeargument(i)):
print "fn called, x=", x
print "end of iteration", i

print "now call fn"
fn()
print "done"
-

Run it and the output shows you clearly when each element executes.

Note in particular that the def statement inside the loop executes every 
time through the loop and each time it creates a new function (which 
differs only in the default argument value), the default argument is 
evaluated when the def executes, NOT when the function is called.
The decorator is called after the def executes and before the next 
statement.
At the end of the for loop we are left only with the last definition of fn: 
the others are overwritten during the loop.

The output looks like this:

C:\temp>t.py
for loop coming up
in for loop, iteration 0
makeargument 0 called
decorating fn (['x'], None, None, (0,))
end of iteration 0
in for loop, iteration 1
makeargument 1 called
decorating fn (['x'], None, None, (1,))
end of iteration 1
in for loop, iteration 2
makeargument 2 called
decorating fn (['x'], None, None, (2,))
end of iteration 2
now call fn
fn called, x= 2
done
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing unix Line endings from Windows.

2006-12-05 Thread Fredrik Lundh
Ant wrote:

> How can I create my own line endings? I've tried setting os.linesep =
> "\n",  (and to \x0a). I've tried things like:
> 
> print "xxx yyy \n",
> print "xxx uuu \x0a",
> filehandle.write("xxx \n")
> filehandle.write("xxx \x0a")
> 
> and all of these give me a nice windows-style crlf!
> 
> Surely there must be a way to do this ...

endline normalization is done by the file object, on the way out.  to 
switch this off, open the output file in binary mode ("wb").



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


Re: sending string or list to a function

2006-12-05 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Or, just always send the function a list. If you have one string, send
> it a list containing that one string.

Or, if a single string is more common and the lists are short or generated
only for the function call, have the function accept a variable number of
arguments:

>> def my_function(*items):
... print " ".join(items)
...
>>> my_function("alpha")
alpha
>>> my_function("alpha", "beta")
alpha beta
>>> items = ["alpha", "beta", "gamma"]
>>> my_function(*items)
alpha beta gamma

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


Re: The del statement

2006-12-05 Thread Fredrik Lundh
Marco Aschwanden wrote:

> 2. Calls the destructor of an object --> list.destruct()

"del name" only removes the name from the current namespace, it doesn't 
destroy the object:

 http://effbot.org/pyref/del

the actual destruction is handled by the garbage collector, when the 
time is right.

 > The del keyword for removing an element in a container is a bit
 > awkward to me.

do you find the x[i] syntax for calling the getitem/setitem methods a 
bit awkward too?  what about HTTP's use of "GET" and "POST" for most 
about everything ? ;-)



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


RE: Filename too long error

2006-12-05 Thread Tim Golden
[Moqtar]

| I am trying to walk a directory and print the file and its modified
| time. When the path is longer then 259 characters i get an error
| "Filename too long". I guess these is because windows limitation on
| path length.
| 
| My code:
| 

[... snip code ...]

| 
| Traceback (most recent call last):
|   File "C:\Python24\hello.py", line 17, in -toplevel-
| ModifiedTime=os.path.getmtime(fullpath)
|   File "C:\Python24\lib\ntpath.py", line 233, in getmtime
| return os.stat(filename).st_mtime
| OSError: [Errno 38] Filename too long
| 
| Is there a way to find the modified time of long path?

There was a thread on similar lines a while back:

http://tinyurl.com/y2tfoh (points to Google Groups)

In short, Python 2.5 now uses the Win32 API which
allows for longer names; until then you might have
to call it yourself directly, which is not too onerous.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Printing unix Line endings from Windows.

2006-12-05 Thread John Machin

Ant wrote:
> Larry Bates wrote:
>
> > Ant wrote:
> ...
> > > Is there any way of doing this without having to post-process the file
> > > in binary mode (a-la the crlf.py script)
> ...
> > You can write to a new file and create your own line endings.
> > When done, delete the original file and rename the output file.
>
> How can I create my own line endings? I've tried setting os.linesep =
> "\n",  (and to \x0a). I've tried things like:
>
> print "xxx yyy \n",
> print "xxx uuu \x0a",
> filehandle.write("xxx \n")
> filehandle.write("xxx \x0a")
>
> and all of these give me a nice windows-style crlf!
>
> Surely there must be a way to do this ...

and there is: open your output file in binary mode; then it won't
convert every \n to \r\n.

writing:
| >>> f = open('unixlf.txt', 'wb')
| >>> f.write('foo\n')
| >>> f.write('bar\n')
| >>> f.close()

checking:
| >>> f = open('unixlf.txt', 'rb')
| >>> x = f.read()
| >>> x
| 'foo\nbar\n'
| >>> len(x)
| 8

BTW:
| >>> '\n' is '\x0a'
| True

HTH,
John

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


Re: The del statement

2006-12-05 Thread Marco Aschwanden
> do you find the x[i] syntax for calling the getitem/setitem methods a
> bit awkward too?  what about HTTP's use of "GET" and "POST" for most
> about everything ? ;-)

No. I like the x[i] syntax. I use it in every second row of my code and  
getting an item like:

x.getitem(i)

would be a viable (in this case clumsy) way but here I find the introduced  
syntax justified.
del on the other hand is used sparingly througout my code. If no del  
keyword would exist, it wouldn't disturb me.

Marco



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


Python regular expression

2006-12-05 Thread Wehrdamned
Hi,

As I understand it, python uses a pcre engine to work with regular
expression.
My question is, then, why expressions like :

>>> re.compile('asd|(?-i:QWE)', re.I)
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/sre.py", line 180, in compile
return _compile(pattern, flags)
  File "/usr/lib/python2.4/sre.py", line 227, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of pattern

don't work? They are ok in perl... 

Thanks in advance.

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


Re: Printing Barcodes from webapp?

2006-12-05 Thread John J. Lee
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:

> On 04 Dec 2006 12:41:59 +, [EMAIL PROTECTED] (John J. Lee) declaimed the
> following in comp.lang.python:
> 
> > digits, through complicated encodings (my colleague Robin tells me US
> > postal bar codes were a particular pain), up to funny-looking 2D "bar"
> 
>   Really? I seem to recall coding a GW-BASIC/Epson MX-80 compatible
> routine to take a zip-code and produce the bar-code for it, on a TRS-80
> Mod 4. Wasn't for my use -- a co-worker wanted it (and had the "manual"
> of markings allowed on an envelope).

Apparently there's a new US postal barcode, a "four state" barcode.
Presumably you drew the older simpler ones back when you were using
the TRS-80...


John

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


Re: About alternatives to Matlab

2006-12-05 Thread Jon Harrop
sturlamolden wrote:
> Little is as efficient as well-written ISO C99 (not to be confused with
> C++ or ANSI C).

OCaml and F# are almost as fast as C++ in this case. I suspect most other
modern languages are.

> So I assume you make sure that the cache is
> prefetched and exploited optimally for your CPU in your C code?

No. My implementations are all unoptimised.

> How fast is fast enough? And how much suffering am I willing to endure
> to achieve that speed?

No suffering: The other implementations are all shorter, simpler and faster
than the Python.

> Bad Fortran 95 can easily be 25% lower than well-tuned C99. But how
> much time was saved writing and debugging the code?

A lot of effort was saved by not having to shoehorn the solution into numpy.

> I value my own time more than a few extra CPU cycles.

Then you won't write code like this in Python.

> Also never underestimate the truth in Knuth's claim that premature
> optimization is the root of all evil in computer programming.

Indeed, only the Python was optimised.

> NumPy can be slower than equivalent C by an order of magnitude. But
> still, that may be more than fast enough. The beauty of NumPy is really
> the way it allows arrays of numerical data to be created and
> manipulated within Python, not the speed of python code using NumPy
> objects. We have already seen that NumPy is faster than the most recent
> version of Matlab, the most expensive commercial tool on the marked;
> which means, it is as fast as you can expect a numerical scripting tool
> to be, but sure, there is still room for improvement.

Price aside, Matlab is clearly the wrong tool for the job here.

> In a numerical scripting language it is certainly not true that several
> slicing operations is slower than a single big for-loop. That is due to
> the overhead involved when the interpreter is invoked. The performance
> is to a large extent determined by the amount of interpreter
> invocations. That is why it is preferred to "vectorize" NumPy code
> using slicing, repmat, reshapes, etc., rather than looping with a
> pythonic for-loop. Even if you have to iterate over the memory several
> times, array slicing will still be a lot faster than a pythonic
> for-loop.

Yes. You have to suffer in Python if you want to approach performance that
can be reached with ease in most other languages in the case of this
benchmark (and probably most benchmarks).

>> Indeed, this algorithm could be written concisely using pattern matching
>> over linked lists. I wonder if that would be as fast as using BLAS from
>> Python.
> 
> Pattern matching on linked lists? For wavelet transforms? Seriously?

Sure. Here's a list-based implementation in OCaml:

let h x0 x1 x2 x3 = h0 *. x0 +. h1 *. x1 +. h2 *. x2 +. h3 *. x3
let g x0 x1 x2 x3 = g0 *. x0 +. g1 *. x1 +. g2 *. x2 +. g3 *. x3

let rec d4_even s d t a = match t, a with
  | [x0; x1; x2; x3], x4::x5::x6::_ ->
  h x0 x1 x2 x3::h x2 x3 x4 x5::s, g x1 x2 x3 x4::g x3 x4 x5 x6::d
  | x0::x1::(x2::x3::x4::_ as t), a ->
  d4_even (h x0 x1 x2 x3 :: s) (g x1 x2 x3 x4 :: d) t a

let rec d4 = function
  | [_; _; _; _] as a -> [a, []]
  | a -> (fun (s, _ as h) -> h :: d4 s) (d4_even [] [] a a)

That's about 3x slower than the Python.

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: global name 'self' is not defined

2006-12-05 Thread Evan
Hi Dennis, to answer your questions:

1) So far as I can see ipython generates .pyc files.
2) This morning I ran the scripts, and got the same problem using
ipython as in my earlier post.  I then deleted the .pyc file, ran the
calling script and this time it works.  I then replaced the .pyc file I
had deleted, expecting to have the problem again, but no.
3) I've tried your suggestion, and it works fine.

A few questions: Why does python use the double underscore (__main__ or
if __name__)?  I've only been using python for about 3 weeks, and I see
this syntax a lot, but haven't found an explanation for it so far?
Also, as I understand , the .pyc files should be updated every time you
change and run the equivalent .py file?

Thanks, Evan

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


Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Nick Craig-Wood
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>  Also, for a wrapper around popen, try commands:
> 
>import commands
> 
>pattern = raw_input('pattern to search? ')
>print commands.getoutput('grep %s *.txt' % pattern)

What if I entered "; rm -rf * ;" as my pattern?

Don't ever pass user input (from file/web/raw_input) to the shell if
you want to write a secure program!

If you use subprocess then you can use a sequence of args to bypass
the shell rather than a string to be passed to the shell.  That will
get over lots of shell escaping problems too.  Eg

from subprocess import Popen, PIPE
from glob import glob
pattern = raw_input('pattern to search? ')
files = glob("*.txt")
output = Popen(["grep", pattern] + files, stdout=PIPE).communicate()[0]
print output

You can also use subprocess to read the return code of the command and
its stderr both of which you'll need if you are programming
defensively!

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-URL! - weekly Python news and links (Dec 4)

2006-12-05 Thread Paul Boddie
Terry Reedy wrote:
> "Paul Boddie" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >The One Laptop Per Child developers and testers briefly consider Python
> >development environments (in the context of things Alan Kay presented at
> >EuroPython 2006):
> >
> > http://mailman.laptop.org/pipermail/devel/2006-November/003176.html
>
> But the only thing about Python here is "(Is somebody going
> to write a Python development environment for children?)"

Yes, it's a bit tenuous, but the context and further discussion is
where the interesting stuff is. At EuroPython, Alan Kay gave a keynote
which focused a lot on the Etoys and Squeak body of work, which is
where users (with children particularly in mind) can experiment with
different ideas in an interactive graphical environment based on
autonomous objects with editable behaviour. Since Squeak is an
image-based environment, a lot of the "view source" functionality comes
for free, whereas Python, despite its apparent similarities with
Smalltalk and Lisp, doesn't appear to have quite the same level of
convenient support for both live editing of objects and process
persistence.

The next message in the thread referenced above mentions Pygame, which
is where a lot of people believe such work should be done with Python.
Perhaps the Python density in that thread isn't great - it's not a
bunch of core developers agonising over C API minutiae - but the
significance of the project along with the issues involved is certainly
worth exploring.

> >E..and the best way to try the latest Python-related developments
> >in the OLPC project:
> >http://mail.python.org/pipermail/edu-sig/2006-December/007441.html
>
> And this has no obvious relation to its description

The Sugar environment is the user interface for the OLPC project. If
you look at the "human interface guidelines", you'll see the following:

"To enable such layered exploration, OLPC has written much of what can
be in Python, a scripting language, to enable children to view the
source code."

One of the more discussed topics in various places outside the Python
"mainstream" recently was whether it was convenient to try out the
Sugar environment without having the OLPC hardware. The referenced
message attempts to provide some clarity in the matter, but once again
it's the further discussion that adds extra value, I think.

Paul

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


win32 com problem

2006-12-05 Thread Mike P
I've got a slight problem when running an excel macro from python using
the win32.com.client module, in that it says it can't load the DLL file
(it doesn't say which one)

and gives me the following error message

Traceback (most recent call last):
  File "", line 93, in ?
  File ">", line 14, in Run
  File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line
258, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType,
argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
'Microsoft Office Excel', "The macro 'CTP.xla!sheet1.CTP' cannot be
found.", 'C:\\Program Files\\Microsoft
Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None)


Anybody have any ideas what this means?

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


Python Contractor Required

2006-12-05 Thread Rakesh Thakrar
I am looking for a Python Developer for a 1 year long contract.  The
role will be based in the South West - UK.

I will consider candidates with either personal or commercial experience
of Python.

Please do not hesitate to contact if you require any further
information.

___
Rakesh Thakrar 
Manager 
Microcom 
Recruitment Division 
2 Adelaide Street 
St. Albans 
Herts, AL3 5BH 
Tel: 01727 752000 
Mob: 079 7094 3227 
Fax: 01727 752018 
www.microcom-recruitment.com
 
Permanent and Contract IT Recruitment Specialists

 
  

The views expressed in this e-mail are not necessarily the views of 
European Recruitment Network Ltd, its directors, officers or employees 
make no representation or accept any liability for its accuracy or 
completeness unless expressly stated to the contrary. 
This e-mail, and any attachments are strictly confidential and intended 
for the addressee(s) only. 
The content may also contain legal, professional or other privileged 
information. Unless expressly stated to the contrary, no contracts may 
be concluded on behalf of European Recruitment Network Ltd by means of 
e-mail communication. You may report the matter by calling us on +44 (0)

1727 752000. 
Please ensure you have adequate virus protection before you open or 
detach any documents from this transmission. European Network 
Recruitment Ltd does not accept any liability for viruses. 
 
European Recruitment Network Ltd is registered in England: Company 
number: 
5651508. 
Registered Office: Greener House, 66-68 Haymarket, London, SW1Y 4RF 
 


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

Re: win32 com problem

2006-12-05 Thread John Machin

Mike P wrote:
> I've got a slight problem when running an excel macro from python using
> the win32.com.client module, in that it says it can't load the DLL file

Does it? All I see is a message that it can't find a macro.

> (it doesn't say which one)

What happens when you run the macro from the Excel UI?

Have you tried using makepy?

>
> and gives me the following error message
>
> Traceback (most recent call last):
>   File "", line 93, in ?

??? It might help if you showed us the code that you are executing.

>   File ">", line 14, in Run
>   File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line
> 258, in _ApplyTypes_
> result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType,
> argTypes) + args)
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
> 'Microsoft Office Excel', "The macro 'CTP.xla!sheet1.CTP' cannot be
> found.", 'C:\\Program Files\\Microsoft
> Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None)
> 
> 
> Anybody have any ideas what this means?

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


Re: win32 com problem

2006-12-05 Thread Mike P
Thanks for the quick reply,

the code i am running is the following

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
ppt = win32com.client.Dispatch("PowerPoint.Application")
ppt.Visible = 1 #open MS Powerpoint
xl.Visible = 1 #open MS Excel
xl.Workbooks.Open('%s/working_output.xls' % (working_dir))
xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\CTP.xla')
ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic
files\\Basic Template.ppt')
xl.Application.Workbooks("working_output").Activate
xl.Application.Run("CTP.xla!sheet1.CTP")

I'm running via SPSS V15 which has a python plugin, i was previousky
running in V14 using the exact same code with no problems?

Thanks again 

Mike

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


Re: win32 com problem

2006-12-05 Thread John Machin

Mike P wrote:
> Thanks for the quick reply,
>
> the code i am running is the following
>
> import win32com.client
> xl = win32com.client.Dispatch("Excel.Application")
> ppt = win32com.client.Dispatch("PowerPoint.Application")
> ppt.Visible = 1 #open MS Powerpoint
> xl.Visible = 1 #open MS Excel
> xl.Workbooks.Open('%s/working_output.xls' % (working_dir))
> xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic
> files\\CTP.xla')

Does this file contain a sheet named "sheet1"? Maybe it should be
"Sheet1"; I can never remember what is case-sensitive and what's not
:-)

If so, does that sheet contain a macro called "CTP"?

> ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic
> files\\Basic Template.ppt')
> xl.Application.Workbooks("working_output").Activate
> xl.Application.Run("CTP.xla!sheet1.CTP")

See above questions.

>
> I'm running via SPSS V15 which has a python plugin, i was previousky
> running in V14 using the exact same code with no problems?

Have you asked SPSS about the CTP.xla file (which I guess is supplied
by them)?

Don't expect so fast a response this time -- it's sleep time in this
timezone :-)

Cheers,
John

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


Re: Python regular expression

2006-12-05 Thread Roberto Bonvallet
Wehrdamned wrote:
> As I understand it, python uses a pcre engine to work with regular
> expression.
[...]
> My question is, then, why expressions like :
 re.compile('asd|(?-i:QWE)', re.I)
[...]
> don't work? They are ok in perl... 

>From http://docs.python.org/lib/module-re.html:

This module provides regular expression matching operations
*similar* to those found in Perl.

Similar != the same.  See http://docs.python.org/lib/re-syntax.html for
details about valid syntax for regular expressions in Python.

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


Re: Interface Designer

2006-12-05 Thread Ed Leafe
On Dec 4, 2006, at 5:41 PM, Gabriel Genellina wrote:

>> I'm starting to program in python, i need a soft  "interface  
>> designer" and adapt this interface to python. Somebody can help me  
>> with this?
>> Sorry, my english is very bad.
>
> Mine too. I don't understand what you want - what do you mean by  
> "interface designer"?

If by chance a visual tool for designing the user interface of an  
app is needed, then there are two good choices, both of which are  
based on the wxPython toolkit. One would be PythonCard (http:// 
pythoncard.sourceforge.net/), which features a simple, quick tool for  
laying out controls and binding code to them. The other is the Dabo  
Class Designer (of which I am the author; see URL in my sig), which  
gives you a choice of sizer-based layout or absolute positioning for  
laying out your GUI designs, as well as a simplified, more Pythonic  
API than wxPython provides.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


Re: Printing unix Line endings from Windows.

2006-12-05 Thread Ant

John Machin wrote:

> Ant wrote:
...
> > filehandle.write("xxx \n")
> > filehandle.write("xxx \x0a")
> >
> > and all of these give me a nice windows-style crlf!
> >
> > Surely there must be a way to do this ...
>
> and there is: open your output file in binary mode; then it won't
> convert every \n to \r\n.
...
> | >>> '\n' is '\x0a'
> | True

(and F wrote something very similar.)

Cheers guys. Shame that fileinput doesn't take an argument to specify
the write mode when  'inplace'  is True, because it is otherwise makes
editing multiple files in place very simple.

Is it worth me submitting a patch to fileinput which can take an
optional write mode parameter?

Cheers,

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


Re: The del statement

2006-12-05 Thread Dustan

Marco Aschwanden wrote:
> > do you find the x[i] syntax for calling the getitem/setitem methods a
> > bit awkward too?  what about HTTP's use of "GET" and "POST" for most
> > about everything ? ;-)
>
> No. I like the x[i] syntax. I use it in every second row of my code and
> getting an item like:
>
> x.getitem(i)

That's spelled "x.__getitem__(i)". Still prefer the method call?

> would be a viable (in this case clumsy) way but here I find the introduced
> syntax justified.
> del on the other hand is used sparingly througout my code. If no del
> keyword would exist, it wouldn't disturb me.

"del x[i]" calls "x.__delitem__(i)". I can't say specifically what
list.__delitem__ does, but looking it up in IDLE (l is an instance of
list):

>>> l.remove

>>> l.__getitem__

>>> l.__delitem__


It seems that list.__delitem__ is a different type than the rest,
called method-wrapper. I can only guess from this point; someone else
is bound to know about this.

> Marco

I can see some builtin functions leaving, but the del keyword isn't
exactly unimportant. Looking at the documentation on the del statement:

http://docs.python.org/ref/del.html

There is no note saying that del is deprecated. That really doesn't
mean anything; it could always become deprecated in the future, but it
doesn't seem likely.

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


Coding standards without control?

2006-12-05 Thread editormt
A recent poll asked if programming standards are used by development
organisations... and if they are controlled.

None: 20%
Yes, but without control: 49%
Yes, with control: 31%

Participants: 369

Source: Methods & Tools (http://www.methodsandtools.com)

A majority of the participating organisations have coding standards...
and a majority does not control them ;o) What is the situation at your
location? Does this lack of control really hurt?

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


Re: About alternatives to Matlab

2006-12-05 Thread Jon Harrop
Filip Wasilewski wrote:
> Besides of that this code is irrelevant to the original one and your
> further conclusions may not be perfectly correct. Please learn first
> about the topic of your benchmark and different variants of wavelet
> transform, namely difference between lifting scheme and dwt, and try
> posting some relevant examples or use other topic for your benchmarks.

Your lifting implementation is slightly longer and slower than the
non-lifting one but its characteristics are identical. For n=2^25 I get:

1.88s C++ (816 non-whitespace bytes)
2.00s OCaml (741 b)
2.33s F# (741 b)
9.83s Your Python (1,002 b)

The original python was 789 bytes.

> Neglecting this issues, I wonder if it is equally easy to juggle
> arbitrary multidimensional arrays in a statically typed language and do
> operations on selected axis directly from the interactive interpreter
> like in the NumPy example from my other post -
> http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ?
> I don't know much OCaml so it would be great if you could elaborate on
> this.

It is probably just as easy. Instead of dynamic typing you have parametric
polymorphism. If you want to make your function generic over arithmetic
type then you can pass in the arithmetic operators.

>> 0.56s C++ (direct arrays)
>> 0.61s F# (direct arrays)
>> 0.62s OCaml (direct arrays)
>> 1.38s OCaml (slices)
>> 2.38s Python (slices)
>> 10s Mathematica 5.1
>>
>> Note that all implementations are safe (e.g. C++ uses a.at(i) instead of
>> a[i]).
> 
> So why not use C++ instead of all others if the speed really matters?
> What is your point here?

1. Benchmarks should not just include two inappropriate languages.
2. Speed aside, the other languages are more concise.

> Could you please share full benchmark code, so we could make
> conclusions too?

I'll paste the whole programs at the end...

> I would like to get to know about your benchmark 
> methodology. I wonder if you are allocating the input data really
> dynamically or whether it's size is a priori knowledge for the
> compiler.

The knowledge is there for the compiler to use but I don't believe any of
them exploit it.

>> In this specific context (discrete wavelet transform benchmark), I'd have
>> said that speed was the most important thing after correctness.
> 
> Not necessarily, if you are doing research with different kinds of
> wavelets and need a general, flexible and easily adaptable tool or just
> the computation speed is not considered a bottleneck.

Brevity is probably next.

> Language speed is a great advantage, but if it always was the most
> important, people would talk directly to the CPUs or knit DSP chips in
> theirs backyards whenever they need to solve a calculation problem.

Sure.

> Please don't make this discussion heading towards `what is the fastest
> way of doing d4 transform and why OCaml rules` instead of `what is the
> optimal way of doing things under given circumstances and still have a
> free afternoon ;-)`.

Comments like that seem to be based on the fundamental misconception that
writing C++ like this is hard.

> Different tasks need different, well-balanced 
> measures. Neither Python nor OCalm nor any other language is a panacea
> for every single problem.

Absolutely. OCaml is as good as the next (compiled) language in this case.
Python and Matlab seem to be particularly bad at this task.

Here's my complete OCaml:

let a = sqrt 3. and b = 4. *. sqrt 2.
let h0, h1, h2, h3 =
  (1. +. a) /. b, (3. +. a) /. b, (3. -. a) /. b, (1. -. a) /. b
let g0, g1, g2, g3 = h3, -.h2, h1, -.h0

let rec d4_aux tmp a n =
  let n2 = n lsr 1 in
  for i=0 to n2-2 do
tmp.(i) <- a.(i*2)*.h0+.a.(i*2+1)*.h1+.a.(i*2+2)*.h2+.a.(i*2+3)*.h3;
tmp.(i+n2) <- a.(i*2)*.g0+.a.(i*2+1)*.g1+.a.(i*2+2)*.g2+.a.(i*2+3)*.g3;
  done;
  tmp.(n2-1) <- a.(n-2)*.h0 +. a.(n-1)*.h1 +. a.(0)*.h2 +. a.(1)*.h3;
  tmp.(2*n2-1) <- a.(n-2)*.g0 +. a.(n-1)*.g1 +. a.(0)*.g2 +. a.(1)*.g3;
  Array.blit tmp 0 a 0 n;
  if n > 4 then d4_aux tmp a (n lsr 1)

let d4 a =
  let tmp = Array.make (Array.length a) 0. in
  d4_aux tmp a (Array.length a)

let () =
  print_endline "Generating test data...";
  let x = Array.init (1 lsl 25) (fun _ -> Random.float 1.) in
  print_endline "Benchmarking...";
  let t1 = Sys.time() in
  ignore(d4 x);
  Printf.printf "Elapsed time is %.6f seconds\n" (Sys.time() -. t1)

and C++:

#include 
#include 
#include 
#include 

using namespace std;

double a = sqrt(3), b = 4 * sqrt(2);
double h0 = (1 + a) / b, h1 = (3 + a) / b, h2 = (3 - a) / b, h3 = (1 - a) /
b;
double g0 = h3, g1 = -h2, g2 = h1, g3 = -h0;

void d4(vector &a) {
  vector tmp(a.size());
  for (int n = a.size(); n >= 4; n >>= 1) {
int half = n >> 1;

for (int i=0; i a(1 << 25);
  for (int i=0; ihttp://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ensure a variable is divisible by 4

2006-12-05 Thread geskerrett
Nick Craig-Wood wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >  I am sure this is a basic math issue, but is there a better way to
> >  ensure an int variable is divisible by 4 than by doing the following;
> >
> >  x = 111
> >  x = (x /4) * 4
>
> You should use // for future compatibility which is guaranteed to be
> an integer division whereas / isn't (see "from __future__ import
> division")
>
> Eg
>
>   (x // 4) * 4
>
> For the particular case of 4 being 2**2, you might consider
>
>   x & ~0x3
>
> which is a common idiom.
>

Thanks for the tip about integer division and I will experiment with
your other suggestion.

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


Re: Coding standards without control?

2006-12-05 Thread Soni Bergraj
editormt wrote:
> A majority of the participating organisations have coding standards...
> and a majority does not control them ;o) What is the situation at your
> location? Does this lack of control really hurt?

"""A Foolish Consistency is the Hobgoblin of Little Minds"""

from: http://www.python.org/dev/peps/pep-0008/

Python makes coding standards obsolete;)

-- 
Soni Bergraj
http://www.YouJoy.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


memory error with matplot

2006-12-05 Thread lisa . engblom
Hi,

I am using matplotlib with python to generate a bunch of charts.  My
code works fine for a single iteration, which creates and saves 4
different charts.  The trouble is that when I try to run it for the
entire set (about 200 items) it can run for 12 items at a time.  On the
13th, I get an error from matplotlib that says it can't access data.
However, if I start the program at the point it failed before it works
fine and will create the charts for the next 12 before failing.  I
assume that I am not closing the files properly somehow or otherwise
misallocating memory.  I tried just reimporting pylab each iteration,
but that didn't help.  This is the function that creates a chart:

#create and save the figure
def CreateFigure(state, facility, unit, SO2, increment, year, P99):
size = len(SO2)

#Create Plot
figure(1, figsize=(10,8))
bar(range(1, size+2), SO2, width=0.1, color='k')
grid(True)
xlim(0,size)
ylim(0, 1.1*SO2[-1])
ylabel('SO2 [lb/hr]')
heading = ConstructFigName(state, facility, unit, increment, year)
title(heading)

#set handles
xticklines = getp(gca(), 'xticklines')
xgridlines = getp(gca(), 'xgridlines')
xticklabels = getp(gca(), 'xticklabels')
yticklines = getp(gca(), 'yticklines')

#set properties
setp(xticklines, visible=False)
setp(xgridlines, visible=False)
setp(xticklabels, visible=False)
setp(yticklines, visible=False)

axhspan(P99, P99, lw=3, ec='r', fc='r')
ax = gca()
#P99 = str(P99)
P99 = '%0.1f' % P99
text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr',
transform=ax.transAxes)

figpath = ConstructFigPath(state, facility, unit, increment, year)
savefig(figpath)
close()

Can you see the problem?

thanks,
-Lisa

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


Re: memory error with matplot

2006-12-05 Thread Tommy Grav

It is hard to know what is wrong when we do not know how the
wrapper around the function works. The error could also be in
ConstructFigName or ConstructFigPath. Also please send the
specific error message when asking for help as that significantly
helps in tracking down the error.

Cheers
   Tommy

[EMAIL PROTECTED]
http://homepage.mac.com/tgrav/
 
-

"Any intelligent fool can make things bigger, more complex, and
more violent. It takes a touch of genius -- and a lot of courage --
to move in the opposite direction" -- Albert Einstein




On Dec 5, 2006, at 8:12 AM, [EMAIL PROTECTED] wrote:


Hi,

I am using matplotlib with python to generate a bunch of charts.  My
code works fine for a single iteration, which creates and saves 4
different charts.  The trouble is that when I try to run it for the
entire set (about 200 items) it can run for 12 items at a time.  On  
the

13th, I get an error from matplotlib that says it can't access data.
However, if I start the program at the point it failed before it works
fine and will create the charts for the next 12 before failing.  I
assume that I am not closing the files properly somehow or otherwise
misallocating memory.  I tried just reimporting pylab each iteration,
but that didn't help.  This is the function that creates a chart:

#create and save the figure
def CreateFigure(state, facility, unit, SO2, increment, year, P99):
size = len(SO2)

#Create Plot
figure(1, figsize=(10,8))
bar(range(1, size+2), SO2, width=0.1, color='k')
grid(True)
xlim(0,size)
ylim(0, 1.1*SO2[-1])
ylabel('SO2 [lb/hr]')
heading = ConstructFigName(state, facility, unit, increment, year)
title(heading)

#set handles
xticklines = getp(gca(), 'xticklines')
xgridlines = getp(gca(), 'xgridlines')
xticklabels = getp(gca(), 'xticklabels')
yticklines = getp(gca(), 'yticklines')

#set properties
setp(xticklines, visible=False)
setp(xgridlines, visible=False)
setp(xticklabels, visible=False)
setp(yticklines, visible=False)

axhspan(P99, P99, lw=3, ec='r', fc='r')
ax = gca()
#P99 = str(P99)
P99 = '%0.1f' % P99
text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr',
transform=ax.transAxes)

figpath = ConstructFigPath(state, facility, unit, increment, year)
savefig(figpath)
close()

Can you see the problem?

thanks,
-Lisa

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






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

Re: Why not just show the out-of-range index?

2006-12-05 Thread stdazi
Usually, when I make some coding mistake (index out of range - in this
case) I just care to fix the mistake and I usually don't mind to
inspect by how much the index was overflowed. It really seems like a
feature that should be embedded in some Python debugger than a feature
in the interpreter itself.

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


Re: Why not just show the out-of-range index?

2006-12-05 Thread Soni Bergraj
stdazi wrote:
> It really seems like a
> feature that should be embedded in some Python debugger than a feature
> in the interpreter itself.
+1
-- 
Soni Bergraj
http://www.YouJoy.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ensure a variable is divisible by 4

2006-12-05 Thread Max M
[EMAIL PROTECTED] skrev:
> Nick Craig-Wood wrote:
>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>>  I am sure this is a basic math issue, but is there a better way to
>>>  ensure an int variable is divisible by 4 than by doing the following;
>>>
>>>  x = 111
>>>  x = (x /4) * 4

X *= 4

;-)


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ensure a variable is divisible by 4

2006-12-05 Thread Paul Rudin
Max M <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] skrev:
>> Nick Craig-Wood wrote:
>>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
  I am sure this is a basic math issue, but is there a better way to
  ensure an int variable is divisible by 4 than by doing the following;

  x = 111
  x = (x /4) * 4
>
> X *= 4
>
> ;-)
>


x=4

:)


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


Re: Multiple FTP download using Muliti thread

2006-12-05 Thread johnny
It works using ftp.microsoft.com. But where does it put the downloaded
files? can I specify a download folder location?

Justin Ezequiel wrote:
> johnny wrote:
> > When I run the following script, with host and password and username
> > changed, I get the following errors:
> > raise error_temp, resp
> > error_temp: 421 Unable to set up secure anonymous FTP
> >
> > Dose the host should allow 4 simultaneous login at a time?
> > 
> 
> does it work using ftp.microsoft.com?
> 
> post your code

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


Re: Multiple FTP download using Muliti thread

2006-12-05 Thread johnny
It places the ftp downloaded contents on the same folder as the this
ftp python script.  How do I set a diffrent download folder location?

johnny wrote:
> It works using ftp.microsoft.com. But where does it put the downloaded
> files? can I specify a download folder location?
>
> Justin Ezequiel wrote:
> > johnny wrote:
> > > When I run the following script, with host and password and username
> > > changed, I get the following errors:
> > > raise error_temp, resp
> > > error_temp: 421 Unable to set up secure anonymous FTP
> > >
> > > Dose the host should allow 4 simultaneous login at a time?
> > >
> > 
> > does it work using ftp.microsoft.com?
> > 
> > post your code

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


Re: Why not just show the out-of-range index?

2006-12-05 Thread Thomas Ploch
stdazi wrote:
> Usually, when I make some coding mistake (index out of range - in this
> case) I just care to fix the mistake and I usually don't mind to
> inspect by how much the index was overflowed. It really seems like a
> feature that should be embedded in some Python debugger than a feature
> in the interpreter itself.
> 

I read the whole thread and this is more or less the first post which
actually has a good thing to say without saying any bad thing about anyone.

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


PythonTidy

2006-12-05 Thread Chuck Rhode
That went well.  PythonTidy has been looked at at least 10**2 times,
and I have received a couple of complaints, which I hope I have
addressed satisfactorily -- plenty good enough for a beta test.  The
basic concept stands.

PythonTidy.py cleans up, regularizes, and reformats the text of
Python scripts:

  http://www.LacusVeris.com/PythonTidy/PythonTidy.python

What next?  Is it appropriately submitted to the Cheese Shop?

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 3° — Wind W 8 mph
-- 
http://mail.python.org/mailman/listinfo/python-list

Does this always go right

2006-12-05 Thread Carl . Wolff
Hello

question about copy vs deepcopy used in multithreaded context:

suppose the following program below: 

the original dictionary is modified after the thread is started, the 
thread works on a copied and deepcopied version of the original 
dictionary. Is the dictionary named "originalcopy" isolated from changes 
in original in multithreaded context?

The program reports no errors but I want to be really sure about this

Thanks
Carl.






original = {}
originalcopy = {}
originaldeepcopy = {}

class checker(threading.Thread):
  def __init__(self):
threading.Thread.__init__(self)
pass
  def run(self):
while True:
  for i in originaldeepcopy:
if originalcopy[i] == originaldeepcopy[i]:
  pass
else:
  print "error", originalcopy[i], "Not equal to", 
originaldeepcopy[i]

i = 0 
while i<1000:
  original[i] = i
  i = i + 1

originalcopy = copy.copy(original)
originaldeepcopy = copy.deepcopy(original)

test = checker()
test.start()

time.sleep(0.5)
 
while True: 
  i = 0
  while i<1000:
original[i] = i*2
i = i + 1
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: About alternatives to Matlab

2006-12-05 Thread Mark Morss
I doubt that anyone would dispute that even as boosted by Numpy/Scipy,
Python will almost certainly be notably slower than moderately
well-written code in a compiled language.  The reason Numpy exists,
however, is not to deliver the best possible speed, but to deliver
enough speed to make it possible to solve large numerical problems with
the powerful and flexible Python language.  As observed by Hans
Latangen in _Python Scripting for Computational Science_, 2nd ed.,
Springer 2005, scientific computing is more than number crunching:

"Very often programming is about shuffling data in and out of different
tools, converting one data format to another, extracting numerical data
from a text, and administering numerical experiments involving a large
number of data files and directories.  Such tasks are much faster to
accomplish in a language like Python than in Fortran, C, C++ or Java."

He might well have mentioned the importance of developing nice-looking
reports once the analysis is complete, and that development is simpler
and more flexible in Python than a compiled language.

In principle, I agree that heavy-duty number-crunching, at least if it
has to be repeated again and again, should be accomplished by means of
a compiled language.  However, if someone has to solve many different
problems just one time, or just a few times (for example if you are an
engineering consultant), there is an excellent argument for using
Python + Numpy.  Unless it affects feasibility, I opine, computational
speed is important primarily in context of regular production, e.g.,
computing the daily "value at risk" in a commodity trading portfolio,
or making daily weather predictions.

I am aware of the power and flexibility of the OCaml language, and
particularly that an OCaml user can easily switch back and forth
between interpreted and compiled implementation.  I'm attacted to OCaml
and, indeed, I'm in the process of reading Smith's (unfortunately not
very well-written) _Practical OCaml_.  However, I also understand that
OCaml supports only double-precision implementation of real numbers;
that its implementation of arrays is a little clunky compared to
Fortran 95 or Numpy (and I suspect not as fast as Fortran's); and that
the available libraries, while powerful, are by no means as
comprehensive as those available for Python.  For example, I am unaware
of the existance of an HDF5 interface for OCaml.

In summary, I think that OCaml is an excellent language, but I think
that the question of whether to use it in preference to Python+Numpy
for general-purpose numerical analysis must rest on much more than its
computational speed.

Jon Harrop wrote:
> Filip Wasilewski wrote:
> > Besides of that this code is irrelevant to the original one and your
> > further conclusions may not be perfectly correct. Please learn first
> > about the topic of your benchmark and different variants of wavelet
> > transform, namely difference between lifting scheme and dwt, and try
> > posting some relevant examples or use other topic for your benchmarks.
>
> Your lifting implementation is slightly longer and slower than the
> non-lifting one but its characteristics are identical. For n=2^25 I get:
>
> 1.88s C++ (816 non-whitespace bytes)
> 2.00s OCaml (741 b)
> 2.33s F# (741 b)
> 9.83s Your Python (1,002 b)
>
> The original python was 789 bytes.
>
> > Neglecting this issues, I wonder if it is equally easy to juggle
> > arbitrary multidimensional arrays in a statically typed language and do
> > operations on selected axis directly from the interactive interpreter
> > like in the NumPy example from my other post -
> > http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ?
> > I don't know much OCaml so it would be great if you could elaborate on
> > this.
>
> It is probably just as easy. Instead of dynamic typing you have parametric
> polymorphism. If you want to make your function generic over arithmetic
> type then you can pass in the arithmetic operators.
>
> >> 0.56s C++ (direct arrays)
> >> 0.61s F# (direct arrays)
> >> 0.62s OCaml (direct arrays)
> >> 1.38s OCaml (slices)
> >> 2.38s Python (slices)
> >> 10s Mathematica 5.1
> >>
> >> Note that all implementations are safe (e.g. C++ uses a.at(i) instead of
> >> a[i]).
> >
> > So why not use C++ instead of all others if the speed really matters?
> > What is your point here?
>
> 1. Benchmarks should not just include two inappropriate languages.
> 2. Speed aside, the other languages are more concise.
>
> > Could you please share full benchmark code, so we could make
> > conclusions too?
>
> I'll paste the whole programs at the end...
>
> > I would like to get to know about your benchmark
> > methodology. I wonder if you are allocating the input data really
> > dynamically or whether it's size is a priori knowledge for the
> > compiler.
>
> The knowledge is there for the compiler to use but I don't believe any of
> them exploit it.
>
> >> In this specific context (discrete wavelet transfor

Re: About alternatives to Matlab

2006-12-05 Thread Mark Morss
Hans >Langtangen<, rather.
Mark Morss wrote:
> I doubt that anyone would dispute that even as boosted by Numpy/Scipy,
> Python will almost certainly be notably slower than moderately
> well-written code in a compiled language.  The reason Numpy exists,
> however, is not to deliver the best possible speed, but to deliver
> enough speed to make it possible to solve large numerical problems with
> the powerful and flexible Python language.  As observed by Hans
> Latangen in _Python Scripting for Computational Science_, 2nd ed.,
> Springer 2005, scientific computing is more than number crunching:
>
> "Very often programming is about shuffling data in and out of different
> tools, converting one data format to another, extracting numerical data
> from a text, and administering numerical experiments involving a large
> number of data files and directories.  Such tasks are much faster to
> accomplish in a language like Python than in Fortran, C, C++ or Java."
>
> He might well have mentioned the importance of developing nice-looking
> reports once the analysis is complete, and that development is simpler
> and more flexible in Python than a compiled language.
>
> In principle, I agree that heavy-duty number-crunching, at least if it
> has to be repeated again and again, should be accomplished by means of
> a compiled language.  However, if someone has to solve many different
> problems just one time, or just a few times (for example if you are an
> engineering consultant), there is an excellent argument for using
> Python + Numpy.  Unless it affects feasibility, I opine, computational
> speed is important primarily in context of regular production, e.g.,
> computing the daily "value at risk" in a commodity trading portfolio,
> or making daily weather predictions.
>
> I am aware of the power and flexibility of the OCaml language, and
> particularly that an OCaml user can easily switch back and forth
> between interpreted and compiled implementation.  I'm attacted to OCaml
> and, indeed, I'm in the process of reading Smith's (unfortunately not
> very well-written) _Practical OCaml_.  However, I also understand that
> OCaml supports only double-precision implementation of real numbers;
> that its implementation of arrays is a little clunky compared to
> Fortran 95 or Numpy (and I suspect not as fast as Fortran's); and that
> the available libraries, while powerful, are by no means as
> comprehensive as those available for Python.  For example, I am unaware
> of the existance of an HDF5 interface for OCaml.
>
> In summary, I think that OCaml is an excellent language, but I think
> that the question of whether to use it in preference to Python+Numpy
> for general-purpose numerical analysis must rest on much more than its
> computational speed.
>
> Jon Harrop wrote:
> > Filip Wasilewski wrote:
> > > Besides of that this code is irrelevant to the original one and your
> > > further conclusions may not be perfectly correct. Please learn first
> > > about the topic of your benchmark and different variants of wavelet
> > > transform, namely difference between lifting scheme and dwt, and try
> > > posting some relevant examples or use other topic for your benchmarks.
> >
> > Your lifting implementation is slightly longer and slower than the
> > non-lifting one but its characteristics are identical. For n=2^25 I get:
> >
> > 1.88s C++ (816 non-whitespace bytes)
> > 2.00s OCaml (741 b)
> > 2.33s F# (741 b)
> > 9.83s Your Python (1,002 b)
> >
> > The original python was 789 bytes.
> >
> > > Neglecting this issues, I wonder if it is equally easy to juggle
> > > arbitrary multidimensional arrays in a statically typed language and do
> > > operations on selected axis directly from the interactive interpreter
> > > like in the NumPy example from my other post -
> > > http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ?
> > > I don't know much OCaml so it would be great if you could elaborate on
> > > this.
> >
> > It is probably just as easy. Instead of dynamic typing you have parametric
> > polymorphism. If you want to make your function generic over arithmetic
> > type then you can pass in the arithmetic operators.
> >
> > >> 0.56s C++ (direct arrays)
> > >> 0.61s F# (direct arrays)
> > >> 0.62s OCaml (direct arrays)
> > >> 1.38s OCaml (slices)
> > >> 2.38s Python (slices)
> > >> 10s Mathematica 5.1
> > >>
> > >> Note that all implementations are safe (e.g. C++ uses a.at(i) instead of
> > >> a[i]).
> > >
> > > So why not use C++ instead of all others if the speed really matters?
> > > What is your point here?
> >
> > 1. Benchmarks should not just include two inappropriate languages.
> > 2. Speed aside, the other languages are more concise.
> >
> > > Could you please share full benchmark code, so we could make
> > > conclusions too?
> >
> > I'll paste the whole programs at the end...
> >
> > > I would like to get to know about your benchmark
> > > methodology. I wonder if you are allocating the input data really

Re: logo design

2006-12-05 Thread Xah Lee
Logo LISP

Xah Lee, 2006-12

Ken Tilton wrote:

«Small problem. You forget that Ron Garret wants us to change the
name of Common Lisp as the sure-fire way to make it more popular (well,
hang on, he says it is necessary, not sufficient. Anyway...) I do not
think we can safely pick a new logo until we have our new name.»

Changing a language's name is not something that can be easily done,
and is unnatural and takes concerted effort, and is very difficult for
it to be successful.

However, creating a (universally recognized) logo for the language, is
easily done, and in fact the use of a logo or some representative image
is inevitable and wide-spread, willy-nilly.

For example, although there are no official logos for lisp, but as you
know, there are several logos or images of various forms that are
already used widely, either to represent lisp the language family, or
to represent the Common Lisp language. And, for various Scheme
implementation, they almost all had a logo of their own. Example:

above: The “twisty AI font” LISP logo. Used by http://lisp.org/ as
early is 2001.

above: The “earth in parenthesis” logo, used by http://lisp.org/ as
of 2006-12.

above: Conrad Barski's “alien technology” lisp web-badges (source
↗), which appeared in 2005.

above: Manfred Spiller's “lizard” lisp web-badge (source ↗),
which appeared in 2005.

As these examples shows, that the use of a logo is needed in practice.
However, it wouldn't help if there are one hundred different logos to
represent the same thing. The point of logos, is to have a memorable,
graphical representation. In modern, capitalistic, societies filled
with information, the use of logos is inevitable. Just look around you
at this very moment, you probably can identify tens of logos, and for
each logo, you probably recognize what they represent. Logos, is merely
a graphical representation of a entity, whose textual analogous
counterpart are names.

Since there is a need for logos, we might as well get together and
agree to have one official logo for lisp the language. That way, it
solidifies the purpose of the logos in use.

Note that, although we have the beautiful “lisp lizard” and
“alien technology” graphics, but because of their graphic content
and in particular the embedded slogan, they do not fit as a logo, but
more as web-badges.

Web-badges serve slightly different purpose than logos. It is more for
the purpose of promotion, than representation. For the same reason,
there are mascots. For example, Java the language, has a official logo
of a smoking coffee cup, but also has a mascot of a penguin named
“Duke”.

above: The official Java logo, and its mascot.

The World Wide Consortium organization (http://www.w3.org/) also has a
logo, and it has various web-badges for its various web technology
validation services.

above: The official logo of the The World Wide Consortium organization,
and the web-badge of its XHTML validation.

The history of Python community's logo is a good example of the
eventual recognition of a need for a unified, official logo.

above: Old, widely used but not officially blessed logo for Python,
used up to 2005.

above: Various logos, application icon, and badges that has been used
for Python.

above: Official Python logo of “double snakes”, inaugurated in
2005.


This post is archived at:
http://xahlee.org/UnixResource_dir/writ/logo_lisp.html

  Xah
  [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: Multiple FTP download using Muliti thread

2006-12-05 Thread Fredrik Lundh
johnny wrote:

> It places the ftp downloaded contents on the same folder as the this
> ftp python script.  How do I set a diffrent download folder location?

by prepending a directory name to the filename in the open(p, 'wb') call.



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


Re: global name 'self' is not defined

2006-12-05 Thread Fredrik Lundh
Evan wrote:

> A few questions: Why does python use the double underscore (__main__ or
> if __name__)?  I've only been using python for about 3 weeks, and I see
> this syntax a lot, but haven't found an explanation for it so far?

to quote the language reference, "System-defined names. These names are 
defined by the interpreter and its implementation (including the 
standard library)".  see:

 http://effbot.org/pyref/reserved-identifier-classes



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


Re: Why not just show the out-of-range index?

2006-12-05 Thread Aahz
In article <[EMAIL PROTECTED]>,
Fredrik Lundh  <[EMAIL PROTECTED]> wrote:
>
>(maybe I should stop using a threaded newsreader to read this group; 
>it's obvious that nobody else ever bothers to check what subthread a 
>message is appearing in.)

Hey!  I've been using trn3.6 for more than fifteen years, and what's good
enough for me is good enough for you!
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Member of the Groucho Marx Fan Club  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Monitoring number of smtp bytes sent through python e-mail socket

2006-12-05 Thread BJ Swope

BTW, I noticed a bunch of new line characters in your test message.

If you ever send mail to a qmail server it will be rejected because rfc 821
says that new line characters cannot occur without a carriage return.  So
change all those \n's to \r\n's ;)
--
We are all slave to our own paradigm. -- Joshua Williams
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Printing unix Line endings from Windows.

2006-12-05 Thread Fredrik Lundh
Ant wrote:

> Is it worth me submitting a patch to fileinput which can take an
> optional write mode parameter?

absolutely.



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


Re: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol [EMAIL PROTECTED] referenced in function _make_buildinfo2

2006-12-05 Thread etaoinbe
I have added advapi32 &user32. This is my current result :

I am quite surprised there are so many issues with the solution file
that comes with python25.
I remember py23 built out of the box :(

1>-- Build started: Project: make_versioninfo, Configuration: Debug
Win32 --
2>-- Build started: Project: make_buildinfo, Configuration: Debug
Win32 --
1>Linking...
2>Linking...
1>Embedding manifest...
2>Embedding manifest...
2>Build log was saved at
"file://d:\Python-2.5\PCbuild8\x86-temp-release\make_buildinfo\BuildLog.htm"
2>make_buildinfo - 0 error(s), 0 warning(s)
1>Performing Custom Build Step
1>Performing Post-Build Event...
1>Build log was saved at
"file://d:\Python-2.5\PCbuild8\x86-temp-debug\make_versioninfo\BuildLog.htm"
1>make_versioninfo - 0 error(s), 0 warning(s)
3>-- Build started: Project: python, Configuration: Debug Win32
--
3>Linking...
3>Embedding manifest...
4>-- Build started: Project: pythoncore, Configuration: Debug Win32
--
3>Build log was saved at
"file://d:\Python-2.5\PCbuild8\x86-temp-debug\python\BuildLog.htm"
3>python - 0 error(s), 0 warning(s)
4>generate buildinfo
4>cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL
-D_DEBUG -MDd ..\Modules\getbuildinfo.c -Fogetbuildinfo.o -I..\Include
-I..\PC
4>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
4>Copyright (C) Microsoft Corporation.  All rights reserved.
4>getbuildinfo.c
4>Linking...
4>   Creating library .\./python25_d.lib and object .\./python25_d.exp
5>-- Build started: Project: w9xpopen, Configuration: Debug Win32
--
5>Linking...
4>config.obj : error LNK2001: unresolved external symbol _init_types
4>getversion.obj : error LNK2019: unresolved external symbol
_Py_GetBuildInfo referenced in function _Py_GetVersion
4>posixmodule.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _win32_startfile
4>posixmodule.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _win32_startfile
4>sysmodule.obj : error LNK2019: unresolved external symbol
__Py_svnversion referenced in function _svnversion_init
4>./python25_d.dll : fatal error LNK1120: 5 unresolved externals
4>Build log was saved at
"file://d:\Python-2.5\PCbuild8\x86-temp-debug\pythoncore\BuildLog.htm"
4>pythoncore - 6 error(s), 0 warning(s)
5>Embedding manifest...
5>Build log was saved at
"file://d:\Python-2.5\PCbuild8\x86-temp-debug\w9xpopen\BuildLog.htm"
5>w9xpopen - 0 error(s), 0 warning(s)
6>-- Build started: Project: _ctypes, Configuration: Debug Win32
--
7>-- Build started: Project: _msi, Configuration: Debug Win32
--
7>Linking...
6>Linking...
7>   Creating library .\./_msi.lib and object .\./_msi.exp
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _uuidcreate
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _uuidcreate
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _uuidcreate
6>   Creating library .\./_ctypes_d.lib and object .\./_ctypes_d.exp
7>_msi.obj : error LNK2019: unresolved external symbol _FCIDestroy
referenced in function _fcicreate
7>_msi.obj : error LNK2019: unresolved external symbol _FCIFlushCabinet
referenced in function _fcicreate
7>_msi.obj : error LNK2019: unresolved external symbol _FCIAddFile
referenced in function _fcicreate
7>_msi.obj : error LNK2019: unresolved external symbol _FCICreate
referenced in function _fcicreate
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _msiobj_dealloc
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _record_getfieldcount
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _record_cleardata
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _msierror
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _msierror
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _msierror
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _record_setstring
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _record_setstream
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function _record_setinteger
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function
_summary_getproperty
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function
_summary_getpropertycount
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in function
_summary_setproperty
7>_msi.obj : error LNK2019: unresolved external symbol
[EMAIL PROTECTED] referenced in fun

Re: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol [EMAIL PROTECTED] referenced in function _make_buildinfo2

2006-12-05 Thread Fredrik Lundh
etaoinbe wrote:

> I have added advapi32 &user32. This is my current result :
> 
> I am quite surprised there are so many issues with the solution file
> that comes with python25.
> I remember py23 built out of the box :(

python 2.5 also builds out of the box, if you're using an ordinary 
visual studio installation, instead of an incomplete "express" edition 
of unknown quality.



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


suppresing error pop-ups in Win32 app

2006-12-05 Thread Bart Ogryczak
Hi,
I'm developing mixed Python/C app which runs on WinNT server. When
something fails in Python, that´s not a problem, prints a traceback to
the log and thats it. When something fails within the C code, the error
message window pops up. To kill it I´ve got to access server with VNC.

I´ve tried to create a python module written in C, which uses
SetUnhandledExceptionFilter(). Although it works suppressing error
pop-up in C applications, somehow it doesn´t work for me, when it´s
called from the python module.
Have you got any suggestions how to suppress those annoying message
boxes?

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


py2exe / Tkinter problem

2006-12-05 Thread maryannj
I've got a python GUI working with Tkinter, and I need to package it as
an executable file, preferably a single file.  I've got py2exe working
without the 'bundle_files' option, but when I add that option in
("bundle_files": 1), the built executable gives me the following error:

---
Fatal Python error: Interpreter not initialized (version mismatch?)

This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.
---

This happens when the compiled Python executes the line "from Tkinter
import *".

Any ideas?  I've been trawling Google and Usenet all day...

M-A

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


Re: decorators question

2006-12-05 Thread king kikapu
>you're not listening.  

Be sure that i do...The fact that i come from another world does not
mean that i am not listening, just that i find as strange some (new)
things.
Thank you all guys, i know what is happening now...

Thanks again!

kikapu

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


Re: The del statement

2006-12-05 Thread Sion Arrowsmith
Marco Aschwanden <[EMAIL PROTECTED]> wrote:
[ ... ]
>> so what about
>>
>>  del x
>
>Ups. I never used it for an object. So far I only used it for deletion of  
>elements of a container. In that case del has two purposes:
>
>1. Deletes an item from a container (and of course destructs it) -->  
>list.remove(elem)
>2. Calls the destructor of an object --> list.destruct()
>
>One statement and two distinct purposes.

Leaving aside the discussion about whether Python has destructors or
not, you are mistaken on two counts:

1. del *is not responsible for an object being destroyed*. That is
done by the garbage collector.

2. del is only ever used to "delete an item from a container". It's
just that in the plain "del x" case, the container is implicitly the
current namespace. (In any case, it's not really "deleting an item
from a container", it's removing a reference to the item from the
container.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: win32 com problem

2006-12-05 Thread Mike P
No Problem,

Thanks for your help so far,  i've sent this problem off to SPSS as it
seems it doesn't work on a work colleagues machine either

Thanks for your time though

Mike

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


PyPy Leysin Winter Sports Sprint (8-14th January 2007)

2006-12-05 Thread Carl Friedrich Bolz
=
 PyPy Leysin Winter Sports Sprint (8-14th January 2007)
=
.. image:: http://www.ermina.ch/002.JPG

The next PyPy sprint will be in Leysin, Switzerland, for the fourth
time.  This sprint will be the final public sprint of our EU-funded
period, and a kick-off for the final work on the upcoming PyPy 1.0
release (scheduled for mid-February).

The sprint is the last chance for students looking for a "summer" job
with PyPy this winter! If you have a proposal and would like to
work with us in the mountains please send it in before 15th December
to "pypy-tb at codespeak.net" and cross-read this page:

   http://codespeak.net/pypy/dist/pypy/doc/summer-of-pypy.html

--
Goals and topics of the sprint
--

* Like previous winter, the main side goal is to have fun in winter
  sports :-) We can take a couple of days off for ski; at this time of
  year, ski days end before 4pm, which still leaves plenty of time
  to recover (er, I mean hack).

* Progress on the JIT compiler, which we are just starting to scale to
  the whole of PyPy. `[1]`_

* Polish the code and documentation of the py lib, and eventually
  release it.

* Work on prototypes that use the new features that PyPy enables:
  distribution `[2]`_ (based on transparent proxying `[3]`_),
  security `[4]`_, persistence `[5]`_, etc. `[6]`_.

.. _[1]: http://codespeak.net/pypy/dist/pypy/doc/jit.html
.. _[2]: http://codespeak.net/svn/pypy/dist/pypy/lib/distributed/
.. _[3]: http://codespeak.net/pypy/dist/pypy/doc/proxy.html
.. _[4]: http://codespeak.net/pypy/dist/pypy/doc/project-ideas.html#security
.. _[5]:
http://codespeak.net/pypy/dist/pypy/doc/project-ideas.html#persistence
.. _[6]: http://codespeak.net/pypy/dist/pypy/doc/project-ideas.html

---
Location & Accomodation
---

Leysin, Switzerland, "same place as before".  Let me refresh your
memory: both the sprint venue and the lodging will be in a very spacious
pair of chalets built specifically for bed & breakfast:
http://www.ermina.ch/.  The place has a baseline ADSL Internet connexion
(600Kb) with wireless installed.  You can of course arrange your own
lodging anywhere (so long as you are in Leysin, you cannot be more than a
15 minute walk away from the sprint venue), but I definitely recommend
lodging there too -- you won't find a better view anywhere else (though you
probably won't get much worse ones easily, either :-)

I made pre-reservations in the Chalet, so please *confirm* quickly that
you are coming so that we can adjust the reservations as appropriate.
The rate so far has been 60 CHF a night all included in 2-person rooms,
with breakfast.  There are larger rooms too (less expensive, possibly
more available too) and the possibility to get a single room if you
really want to.

Please register by svn:


http://codespeak.net/svn/pypy/extradoc/sprintinfo/leysin-winter-2007/people.txt

or on the pypy-sprint mailing list if you do not yet have check-in rights:

  http://codespeak.net/mailman/listinfo/pypy-sprint

You need a Swiss-to-(insert country here) power adapter.  There will be
some Swiss-to-EU adapters around - bring a EU-format power strip if you
have one.

---
Exact times
---

Officially, 8th-14th January 2007.  Both dates are flexible, you can
arrive or leave earlier or later, though it is recommended to arrive on
the 7th (if many people arrive on the 6th we need to check for
accomodation availability first).  We will give introductions and
tutorials on the 8th, in the morning if everybody is there, or in the
afternoon otherwise.

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


Re: Why not just show the out-of-range index?

2006-12-05 Thread Russ
stdazi wrote:
> Usually, when I make some coding mistake (index out of range - in this
> case) I just care to fix the mistake and I usually don't mind to
> inspect by how much the index was overflowed. It really seems like a
> feature that should be embedded in some Python debugger than a feature
> in the interpreter itself.

Then why have the interpreter generate error messages at all? I think
it makes sense to make the interpreter as self-contained as possible,
within reason, so you don't depend on a debugger any more than
necessary.

And it's not that I care "how much the index was overflowed." It's that
something unexpected happened, and I want a clue what it was. I'll need
to find out somehow anyway. What is the next logical step if not to
find out what the out-of-range index was?

Having said that, I reiterate that I don't know the implementation
difficulty, so I defer on the decision as to whether it is worth
implementing or not.

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


Re: About alternatives to Matlab

2006-12-05 Thread Mark Morss
Carl,

I agree with practically everything you say about the choice between
Python and functional languages, but apropos of Ocaml, not these
remarks:

>
> In the same way that a screwdriver can't prevent you from driving a
> nail.  Give me a break, we all know these guys (Haskell especially) are
> designed to support functional first and other paradigms second.  Way
> second.  That's quite enough imposing for me.
> ...
> And let's face it, functional
> languages are (or seem to be) all about purity.

As you will see if you look at some OCaml references (there are a
number that are available on the OCaml website) that OCaml goes a very
long way toward facilitating imperative, procedural methods.  It's
possible to write perfectly good code in OCaml and not use functional
methods.  The OCaml people are fond of saying "OCaml isn't pure."
Indeed, the need for speed is one very good reason to choose and
imperative style over a functional one.


Carl Banks wrote:
> Jon Harrop wrote:
> > Carl Banks wrote:
> > >> 0.56s C++ (direct arrays)
> > >> 0.61s F# (direct arrays)
> > >> 0.62s OCaml (direct arrays)
> > >> 1.38s OCaml (slices)
> > >> 2.38s Python (slices)
> > >> 10s Mathematica 5.1
> > > [snip]
> > >> 1.57s Python (in-place)
> > >
> > > So,
> > > optimized Python is roughly the same speed as naive Ocaml
> > > optimized Ocaml is roughly the same speed as C++
> >
> > Absolutely not:
> >
> > Optimized Python is 14% slower than badly written OCaml.
>
> I'd call that roughly the same speed.  Did you use any sort of
> benchmark suite that miminized testing error, or did you just run it
> surrounded by calls to the system timer like I did?  If the latter,
> then it's poor benchmark, and 10% accuracy is better than you can
> expect.  (Naive tests like that tend to favor machine code.)
>
> > Given the problem,
> > rather than the Python solution, nobody would write OCaml code like that.
> >
> > Unoptimised but well-written OCaml/C/C++ is 2.5-2.8x faster than the fastest
> > Python so far whilst also requiring about half as much code.
>
> Frankly, I have a hard time believing anyone would naively write the
> Ocaml code like the optimized version you posted.  You'd know better
> than I, though.
>
> > Optimising the C++ by hoisting the O(log n) temporary array allocations into
> > one allocation makes it another 20% faster. I'm sure there are plenty more
> > optimisations...
> >
> > >> There aren't any complicated types in the above code. In fact, there are
> > >> only two types: float and float array.
> > >
> > > You're vastly underestimating the complexity of numpy objects.  They
> > > have an awful lot going on under the covers to make it look simple on
> > > the surface.  There's all kinds of type-checking and type-conversions.
> > > A JIT that folds loops together would have to have knowledge of that
> > > process, and it's a lot of knowledge to have.  That is not easy.
> >
> > My suggestion doesn't really have anything to do with numpy. If you had such
> > a JIT you wouldn't use numpy in this case.
> >
> > That's my point, using numpy encouraged the programmer to optimise in the
> > wrong direction in this case (to use slices instead of element-wise
> > operations).
>
> Ok, I can see that.  We have a sort of JIT compiler, psyco, that works
> pretty well but I don't think it's as fast for large arrays as a good
> numpy solution.  But it has more to deal with than a JIT for a
> statically typed language.
>
> > >> I was referring to the slicing specifically, nothing to do with
> > >> functional programming. My F# and OCaml code are now basically identical
> > >> to the C++ code.
> > >
> > > It is pretty strong thing to say that anything is fundamentally bad
> > > just because it's not fast as something else.  Fundamental badness
> > > ought to run deeper than some superficial, linear measure.
> >
> > The slice based approach is not only slower, it is longer, more obfuscated
> > and more difficult to optimise. That doesn't just apply to Python and
> > numpy, it also applies to Matlab, Mathematica etc.
> >
> > Which begs the question, if you were writing in a compiled language like F#
> > would you ever use slices?
>
> If I was writing in F#?  I absolutely would, because some problems are
> most cleanly, readably, and maintainably done with slices.  I don't
> have any speed-lust, and I don't waste time making things fast if they
> don't need to be.  I would rather spend my time designing and
> implementing the system, and optimizing things that actually need it.
> I don't want to spend my time tracking down some stupid indexing error.
>
> If it was critical for it to be fast, then I'd pull out the stops and
> write it as efficiently as possible.  In my experience, a typical
> middle size program will have half a dozen or so subroutines where it's
> critical to be as fast as possible.
>
> Will any other F# people do it?  I don't know if they all have
> speed-lust, or if they'd all deliberately avoid slicing to prove some

[ANN] argparse 0.3 - Command-line parsing library

2006-12-05 Thread Steven Bethard
Announcing argparse 0.3
---

argparse home:
http://argparse.python-hosting.com/

argparse single module download:
http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw

argparse bundled downloads at PyPI:
http://www.python.org/pypi/argparse/

About this release
==

This release moves argparse's development status from Pre-Alpha to
Alpha. The API is basically stable, though reasonable change requests
will still be considered.

New in this release
===

* The '--' pseudo-argument can now be used to terminate the arg list
of an optional::

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-x', nargs='+')
>>> parser.add_argument('y')
>>> parser.parse_args('-x X1 X2 X3 -- Y'.split())
Namespace(x=['X1', 'X2', 'X3'], y='Y')

About argparse
==

The argparse module is an optparse-inspired command line parser that
improves on optparse by:

* handling both optional and positional arguments
* supporting parsers that dispatch to sub-parsers
* producing more informative usage messages
* supporting actions that consume any number of command-line args
* allowing types and actions to be specified with simple callables
instead of hacking class attributes like STORE_ACTIONS or
CHECK_METHODS

as well as including a number of other more minor improvements on the
optparse API. To whet your appetite, here's a simple program that sums
its command-line arguments and writes them to a file::

parser = argparse.ArgumentParser()
parser.add_argument('integers', type=int, nargs='+')
parser.add_argument('--log', type='outfile', default=sys.stdout)
args = parser.parse_args()
args.log.write('%s\n' % sum(args.integers))
args.log.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Linear regression in NumPy

2006-12-05 Thread Jianzhong Liu

Hello, Guys,

I have a question about the linear_least_squares in Numpy.

My linear_least_squares cannot give me the results.

I use Numpy1.0. The newest version. So I checked online and get your 
guys some examples.


I did like this.

[EMAIL PROTECTED] 77] ~ >> py
Python 2.4.3 (#1, May 18 2006, 07:40:45)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.

from Numeric import *
from LinearAlgebra import linear_least_squares
from Matrix import *
y = Matrix([[1], [2], [4]])
x = Matrix([[1, 1], [1, 2], [1, 3]])
print y

Matrix([[1],
  [2],
  [4]])

x

Matrix([[1, 1],
  [1, 2],
  [1, 3]])

print linear_least_squares(x, y)


Here my Numpy stops. and never give me a result. THis is the problem of 
Numpy or sth wrong.


Can you guys give me a LinearAlgebra.py so that I can have a try?

Thanks,

John 

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

Re: Thread error

2006-12-05 Thread Salvatore Di Fazio
Dennis Lee Bieber ha scritto:

>   Ah, sorry... Warned you that I didn't test...
>
>   Duplicate the block of lines with the .join() calls. Put this block
> just before them, but after the threading.Thread calls, and change the
> .join() to .start()

Tnx Dennis I resolved yesterday after the post.
I tried to delete the post :)
Anyway tnx

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


Re: Why not just show the out-of-range index?

2006-12-05 Thread rurpy

Russ wrote:
> Folks,
>
> I'm truly sorry that so many feathers got ruffled in this thread. Let's
> see if I can put this thing to rest gracefully.

I too am tired of this and I apologize to you
(Russ) for jumping into it and for this (hopefullly
last) followup.  But the same thing happened here
a short time ago and in that incident too, someone
who made a suggestion was attacked and charged
unjustifiably with rudeness.

In neither that case nor this did anyone protest
the unjustness and hypocrisy that was blatant.
So this time I could not sit idly and watch.

To summarize the "insults" subtread (for closure)

An observation was made about a suboptimal error
message and a suggestion about how to improve it
made in good faith.  (Even harebrained suggestions
deserve a non-insulting explanation of why they're
not a good idea, and this was not harebrained.)

This resulted in a suggestion to "submit a patch".

The response was (correctly) that it was not
a viable suggestion.  (characterized by "silly"
hardly a strong epithet on usenet), that it would
be "trivial" to fix and should "take 2 minutes" by
someone with the requisite experience (obviously
an opinion, not a claim, since the OP said in
the same post that he was unfamiliar with Python
internals).

Obviously it takes more than two minutes.  This
was a usenet post for god's sake, not a PhD
dissertation.  And "trivial" is used almost as slang
by many computer and science types and means
"very easy" (as if you didn't know).

o it is reasonable to question the description
  "trivial" and ask what actually would need
  to be done. It is not reasonable to be
  insulted by it.
o Anyone who honestly interprets "two minutes"
  as 120 seconds should seek clinical help.
  A reasonable reading if this is that "it would
  take someone who works on Python internals
  regularly orders of magnitude less time than
  me, and with a higher probability of getting
  it right."  Sorry folks. that is a factually
  true statement.  Nothing to do with your time
  is less valuable than mine.  More imaginary
  insults.

The OP was blameless in this thread and this
was another case the regulars here overreacting
to imagined (or deliberately misinterpreted)
"insults" that were not there.

One can speculate that this serves a purpose
of suppressing interference from "outsiders"
in the development process.  Or maybe it is
just the alpha dogs asserting their authority.
Either way, it should not be allowed to pass 
uncriticised.

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


About the 79 character line recommendation

2006-12-05 Thread Steve Bergman
As I study Python, I am trying to develop good, Pythonic, habits.  For
one thing, I am trying to keep Guido's the style guide in mind.

And I know that it starts out saying that it should not be applied in
an absolute fashion.

However, I am finding that the 79 character line prescription is not
optimal for readability.

Certainly, cutting back from the length of lines that I used to use has
*helped* readability.  But if I triy very hard to apply 79, I think
readability suffers.  If this were just something that was an issue
occasionally, I would just put it off to "know when to break the
rules".  However, find myself going to 90 to 100 characters very
frequently.  Now, if it were just me, I'd shoot for < 100.  However,
the Python philosophy includes making code easier for others to read,
as well.

So, I was wondering what more accomplished Python programmers thought
about this.

While I'm on this general topic, the guide mentions a pet peeve about
inserting more than one space to line up the "=" in assignment
statements.  To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit.  Comments?

Thanks,
Steve Bergman

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


Re: PythonTidy

2006-12-05 Thread Thomas Heller
Chuck Rhode schrieb:
> That went well.  PythonTidy has been looked at at least 10**2 times,
> and I have received a couple of complaints, which I hope I have
> addressed satisfactorily -- plenty good enough for a beta test.  The
> basic concept stands.

Sure.
There is still one major issue.  pythonTidy uses open(input-file, "rb") to
open the Python module to tidy up.  That does not work on Windows,
at least if the file has (as it should) "\r\n" newlines.
I suggest you open the file with open(input-file, "rU").

For output, PythonTidy generates "\n" line endings, this should also be changed
on Windows.

And another wish from me:
PythonTidy outputs strings with single quotes, while my own style is to
use double quotes (I don't think that pep8 prefers one over the other).
Is it possible to customize this?

> PythonTidy.py cleans up, regularizes, and reformats the text of
> Python scripts:
> 
>   http://www.LacusVeris.com/PythonTidy/PythonTidy.python
> 
> What next?  Is it appropriately submitted to the Cheese Shop?
> 

Of course.

Thomas

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


Re: About the 79 character line recommendation

2006-12-05 Thread sam

Steve Bergman wrote:
> As I study Python, I am trying to develop good, Pythonic, habits.  For
> one thing, I am trying to keep Guido's the style guide in mind.
>
> And I know that it starts out saying that it should not be applied in
> an absolute fashion.
>
> However, I am finding that the 79 character line prescription is not
> optimal for readability.
>
> Certainly, cutting back from the length of lines that I used to use has
> *helped* readability.  But if I triy very hard to apply 79, I think
> readability suffers.  If this were just something that was an issue
> occasionally, I would just put it off to "know when to break the
> rules".  However, find myself going to 90 to 100 characters very
> frequently.  Now, if it were just me, I'd shoot for < 100.  However,
> the Python philosophy includes making code easier for others to read,
> as well.
>
> So, I was wondering what more accomplished Python programmers thought
> about this.
>
> While I'm on this general topic, the guide mentions a pet peeve about
> inserting more than one space to line up the "=" in assignment
> statements.  To me, lining them up, even if it requires quite a few
> extra spaces, helps readability quite a bit.  Comments?
>
> Thanks,
> Steve Bergman

I prefer to use 132 char per line, and like you I line up the = sign
for readability.
The reason for this convention arises from the fact that I am Dyslexic,
and this convention helps me double check my typing.

Sam Schulenburg

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


Re: Multiple FTP download using Muliti thread

2006-12-05 Thread johnny
I am getting the following error:

raise error_temp, resp
error_temp: 421 Unable to set up secure anonymous FTP

Here is the code:

import ftplib, posixpath, threading
from TaskQueue import TaskQueue

def worker(tq):
while True:
host, e = tq.get()

c = ftplib.FTP(host)
c.connect()
try:
c.login()
p = posixpath.basename(e)
fp = open('H:/eclipse/workspace/src/ftp_download/' + p,
'wb')
try: c.retrbinary('RETR %s' % e, fp.write)
finally: fp.close()
finally: c.close()

tq.task_done()

if __name__ == '__main__':
q = TaskQueue()
#host = 'ftp.microsoft.com'
host = 'mysite.com'
c = ftplib.FTP(host)
c.connect()
try:
#c.login()
c.login("[EMAIL PROTECTED]","temppass" )

#folder = '/deskapps/kids/'
folder = ''
for n in c.nlst(folder):
#if n.lower().endswith('.exe'):
#q.put((host, n))
 if n.lower().endswith('.jpg'):
q.put((host, n))
 elif n.lower().endswith('.jpeg'):
q.put((host, n))

finally: c.close()

numworkers = 4
for i in range(numworkers):
t = threading.Thread(target=worker, args=(q,))
t.setDaemon(True)
t.start()

q.join()
print 'Done.'


Justin Ezequiel wrote:
> johnny wrote:
> > When I run the following script, with host and password and username
> > changed, I get the following errors:
> > raise error_temp, resp
> > error_temp: 421 Unable to set up secure anonymous FTP
> >
> > Dose the host should allow 4 simultaneous login at a time?
> > 
> 
> does it work using ftp.microsoft.com?
> 
> post your code

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


Re: logo design

2006-12-05 Thread Diez B. Roggisch
> 
> Web-badges serve slightly different purpose than logos. It is more for
> the purpose of promotion, than representation. For the same reason,
> there are mascots. For example, Java the language, has a official logo
> of a smoking coffee cup, but also has a mascot of a penguin named
> “Duke”.

http://java.sun.com/features/1999/05/duke_gallery.html

"""
Duke doesn't like bad code, working out, or being called a troll, a tooth,
or a penguin.
"""

As usual a shining example of Xah Lee not getting even the most basic facts
right.

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

Re: About the 79 character line recommendation

2006-12-05 Thread Stephen Hansen

On 5 Dec 2006 09:55:20 -0800, Steve Bergman <[EMAIL PROTECTED]> wrote:


However, I am finding that the 79 character line prescription is not
optimal for readability.



For me, 79 characters per line... would basically make my code a LOT
harder for me to read and manage.

I mean, a basic structure for a LOT of the code I end up working on is:

class foo:
   def myMethod(self, arg1):
   try:
   try:
   connection = ConnectionQueue.get()
   ...
   finally:
   ConnectionQueue.put(connection)
   except:
   logging.exception("foo::myMethod(%s) unknown error" % arg1)

At that point, i've lost 17-characters before I even start... Even some with
just a very simple SQL statement ends up with text at 85ish characters.

I might be biased, but my screen goes otu to about 200 characters-- and I'm
not writing an open source app :) If I was, I might be more inclined to
doing things in a more generally-readable way... but in my office scenario,
I don't have to worry about people who are only reading to 79 characters.
You have to evaluate your environment/audience, both current and of what it
may be in the future.

As a rule, if it's over about 125 characters, I try to split it up into
different lines.

While I'm on this general topic, the guide mentions a pet peeve about

inserting more than one space to line up the "=" in assignment
statements.  To me, lining them up, even if it requires quite a few
extra spaces, helps readability quite a bit.  Comments?



I like lining up the equal statements/other punctuation for things that are
all the "same". Like, if I'm using building up an event table w/ wxWidgets,
I'll have all the arguments in the self.Bind(...) line up because then it's
easier to scan for me.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Linear regression in NumPy

2006-12-05 Thread Jon
> I have a question about the linear_least_squares in Numpy.

Not quite sure what is going on, it looks like there could be some
confusion as to linear_least_squares is expecting as an argument of
some Numeric arrays and what you are supplying (a Matrix) is perhaps
not close enough to being the same thing.

Up-to-date versions for all this are all in "numpy" nowadays and the
numpy mailing list is perhaps a better place to ask:
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Anyway, I've pasted in an example using Numeric and LinearAlgebra,
which you seem to have on your system. They still work fine. Not sure
what the "Matrix" package is that you are using?

HTH,

Jon

example:

C:\>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from Numeric import *
>>> from LinearAlgebra import linear_least_squares
>>> a=array( [[1, 1], [1, 2], [1, 3]] )
>>> y=array( [ 1,2,4] )   # note 1 D
>>> a
array([[1, 1],
   [1, 2],
   [1, 3]])
>>> y
array([1, 2, 4])
>>> linear_least_squares(a,y)
(array([-0.6667,  1.5   ]), array([ 0.1667]), 2, array([
4.07914333,  0.60049122]))
>>>

# Is this what you expect as output???

Jianzhong Liu wrote:
> Hello, Guys,
>
> I have a question about the linear_least_squares in Numpy.
>
> My linear_least_squares cannot give me the results.
>
> I use Numpy1.0. The newest version. So I checked online and get your
> guys some examples.
>
> I did like this.
>
> [EMAIL PROTECTED] 77] ~ >> py
> Python 2.4.3 (#1, May 18 2006, 07:40:45)
> [GCC 3.3.3 (cygwin special)] on cygwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from Numeric import *
> >>> from LinearAlgebra import linear_least_squares
> >>> from Matrix import *
> >>> y = Matrix([[1], [2], [4]])
> >>> x = Matrix([[1, 1], [1, 2], [1, 3]])
> >>> print y
> Matrix([[1],
>[2],
>[4]])
> >>> x
> Matrix([[1, 1],
>[1, 2],
>[1, 3]])
> >>> print linear_least_squares(x, y)
>
> Here my Numpy stops. and never give me a result. THis is the problem of
> Numpy or sth wrong.
>
> Can you guys give me a LinearAlgebra.py so that I can have a try?
> 
> Thanks,
> 
> John

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


Subprocess with a Python Session?

2006-12-05 Thread Calvin Spealman
No matter what I do I cant get the following code to do what I expect.
I hadn't used subprocess t o read and write to pipes of a
still-running app, and I just can't seem to get it right. What gives?

import subprocess

p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
p.stdin.write('print 10\n')
assert p.stdout.readline() == '10\n'

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess with a Python Session?

2006-12-05 Thread Fredrik Lundh
Calvin Spealman wrote:

> No matter what I do I cant get the following code to do what I expect.
> I hadn't used subprocess t o read and write to pipes of a
> still-running app, and I just can't seem to get it right. What gives?
> 
> import subprocess
> 
> p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
> p.stdin.write('print 10\n')

+ p.stdin.close()

> assert p.stdout.readline() == '10\n'



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


Re: About the 79 character line recommendation

2006-12-05 Thread John Machin
Steve Bergman wrote:
[snip]
> However, I am finding that the 79 character line prescription is not
> optimal for readability.
>
> Certainly, cutting back from the length of lines that I used to use has
> *helped* readability.  But if I triy very hard to apply 79, I think
> readability suffers.  If this were just something that was an issue
> occasionally, I would just put it off to "know when to break the
> rules".  However, find myself going to 90 to 100 characters very
> frequently.  Now, if it were just me, I'd shoot for < 100.  However,
> the Python philosophy includes making code easier for others to read,
> as well.
>

Are you taking advantage of all the various options for line
continuation besides \ that exist in Python, like (a) automatic
concatenation of adjacent string literals (b) automatic continuation
until () [] or {} are balanced? Example using both:

fprintf(self.logfile,
"WARNING *** Conflict between "
"std format code %d and its format string %r\n",
fmtcode, unistrg)

Aside: In this most noble of languages, fprintf() has a one-line
implementation:

def fprintf(f, fmt, *args):
f.write(fmt % args)

>
> While I'm on this general topic, the guide mentions a pet peeve about
> inserting more than one space to line up the "=" in assignment
> statements.  To me, lining them up, even if it requires quite a few
> extra spaces, helps readability quite a bit.  Comments?

Merely aligning the = would annoy the crap out of me. However if the
RHS of a bunch of *related* assignments could be made clearer by
inserting extra space, *and* they were more complicated than the
following trivial example of what I mean, I'd do it.
red = c & 0xff
green = (c >> 8) & 0xff
blue = (c >> 16) & 0xff
c.f.
red   =  c& 0xff
green = (c >>  8) & 0xff
blue  = (c >> 16) & 0xff

Cheers,
John

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


Re: Linear regression in NumPy

2006-12-05 Thread Robert Kern
Jianzhong Liu wrote:
> Hello, Guys,
> 
> I have a question about the linear_least_squares in Numpy.
> 
> My linear_least_squares cannot give me the results.
> 
> I use Numpy1.0. The newest version. So I checked online and get your
> guys some examples.

The package name for numpy 1.0 is "numpy", not "Numeric". See this page for an
explanation of the names and the history of the two packages:

  http://www.scipy.org/History_of_SciPy

The examples you say are for Numeric, not numpy. You can get up-to-date examples
from here:

  http://www.scipy.org/Documentation

And please join us on numpy-discussion if you have any more questions.

  http://www.scipy.org/Mailing_Lists

-- 
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: Ensure a variable is divisible by 4

2006-12-05 Thread John Machin

Paul Rudin wrote:
> Max M <[EMAIL PROTECTED]> writes:
>
> > [EMAIL PROTECTED] skrev:
> >> Nick Craig-Wood wrote:
> >>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>   I am sure this is a basic math issue, but is there a better way to
>   ensure an int variable is divisible by 4 than by doing the following;
> 
>   x = 111
>   x = (x /4) * 4
> >
> > X *= 4
> >
> > ;-)
> >
>
>
> x=4
> 
> :)

Ensure x is divisible by *any* non-zero integer:

x = 0

:-O

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


Re: Subprocess with a Python Session?

2006-12-05 Thread Calvin Spealman
On 12/5/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Calvin Spealman wrote:
>
> > No matter what I do I cant get the following code to do what I expect.
> > I hadn't used subprocess t o read and write to pipes of a
> > still-running app, and I just can't seem to get it right. What gives?
> >
> > import subprocess
> >
> > p = subprocess.Popen("python", stdout=subprocess.PIPE, 
> > stdin=subprocess.PIPE)
> > p.stdin.write('print 10\n')
>
> + p.stdin.close()
>
> > assert p.stdout.readline() == '10\n'
>
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I know I can do that, but I am specifically trying to not close the
pipe or terminate the process. I need to write additional statements,
read additional output, etc.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subprocess with a Python Session?

2006-12-05 Thread Shane Hathaway
Calvin Spealman wrote:
> No matter what I do I cant get the following code to do what I expect.
> I hadn't used subprocess t o read and write to pipes of a
> still-running app, and I just can't seem to get it right. What gives?
> 
> import subprocess
> 
> p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
> p.stdin.write('print 10\n')
> assert p.stdout.readline() == '10\n'

Make sure the pipes are unbuffered.  Launch the process with "python -u" 
and flush() the streams after writing.  (That's the issue I've 
encountered when doing this before.)

Shane

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


Re: logo design

2006-12-05 Thread Ken Tilton


Xah Lee wrote:
> Logo LISP
> 
> Xah Lee, 2006-12
> 
> Ken Tilton wrote:
> 
> «Small problem. You forget that Ron Garret wants us to change the
> name of Common Lisp as the sure-fire way to make it more popular (well,
> hang on, he says it is necessary, not sufficient. Anyway...) I do not
> think we can safely pick a new logo until we have our new name.»
> 
> Changing a language's name is not something that can be easily done,
> and is unnatural and takes concerted effort, and is very difficult for
> it to be successful.
> 
> However, creating a (universally recognized) logo for the language, is
> easily done, and in fact the use of a logo or some representative image
> is inevitable and wide-spread, willy-nilly.
> 
> For example, although there are no official logos for lisp, but as you
> know, there are several logos or images of various forms that are
> already used widely, either to represent lisp the language family, or
> to represent the Common Lisp language. And, for various Scheme
> implementation, they almost all had a logo of their own. Example:
> 
> above: The “twisty AI font” LISP logo. Used by http://lisp.org/ as
> early is 2001.
> 
> above: The “earth in parenthesis” logo, used by http://lisp.org/ as
> of 2006-12.
> 
> above: Conrad Barski's “alien technology” lisp web-badges (source
> ↗), which appeared in 2005.
> 
> above: Manfred Spiller's “lizard” lisp web-badge (source ↗),
> which appeared in 2005.
> 
> As these examples shows, that the use of a logo is needed in practice.
> However, it wouldn't help if there are one hundred different logos to
> represent the same thing. The point of logos, is to have a memorable,
> graphical representation. In modern, capitalistic, societies filled
> with information, the use of logos is inevitable. Just look around you
> at this very moment, you probably can identify tens of logos, and for
> each logo, you probably recognize what they represent. Logos, is merely
> a graphical representation of a entity, whose textual analogous
> counterpart are names.
> 
> Since there is a need for logos, we might as well get together and
> agree to have one official logo for lisp the language. That way, it
> solidifies the purpose of the logos in use.
> 
> Note that, although we have the beautiful “lisp lizard” and
> “alien technology” graphics, but because of their graphic content
> and in particular the embedded slogan, they do not fit as a logo, but
> more as web-badges.
> 
> Web-badges serve slightly different purpose than logos. It is more for
> the purpose of promotion, than representation. For the same reason,
> there are mascots. For example, Java the language, has a official logo
> of a smoking coffee cup,..

A subtle execution of the tip of a tongue pressed against the upper 
teeth with sprays of spittle coming out either side probably is not what 
you had in mind.

Hmmm. Then we change the spelling to Lithp, and never have to hear that 
stupid joke again. Our slogan can be "Thay it loud, thay it proud."*, 
and we already have the frickin lambda.

hth,kt

Or "Out With Lithp!".

k

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: About the 79 character line recommendation

2006-12-05 Thread Virgil Dupras
Steve Bergman wrote:
> As I study Python, I am trying to develop good, Pythonic, habits.  For
> one thing, I am trying to keep Guido's the style guide in mind.
>
> And I know that it starts out saying that it should not be applied in
> an absolute fashion.
>
> However, I am finding that the 79 character line prescription is not
> optimal for readability.
>
> Certainly, cutting back from the length of lines that I used to use has
> *helped* readability.  But if I triy very hard to apply 79, I think
> readability suffers.  If this were just something that was an issue
> occasionally, I would just put it off to "know when to break the
> rules".  However, find myself going to 90 to 100 characters very
> frequently.  Now, if it were just me, I'd shoot for < 100.  However,
> the Python philosophy includes making code easier for others to read,
> as well.
>
> So, I was wondering what more accomplished Python programmers thought
> about this.
>
> While I'm on this general topic, the guide mentions a pet peeve about
> inserting more than one space to line up the "=" in assignment
> statements.  To me, lining them up, even if it requires quite a few
> extra spaces, helps readability quite a bit.  Comments?
>
> Thanks,
> Steve Bergman

I also think that limiting code to 80 columns often hinders
readability. I personally try to limit my code to 100 columns. The end
result is pretty nice.

However, I'm all for the "flat is better than nested" philosophy, even
when nested is under 100 columns.

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


RE: About the 79 character line recommendation

2006-12-05 Thread Olivier Langlois
Hi,

There was a coding standard where I worked and the intention behind this
requirement was to make the code printer friendly. Printing code source
with lines longer than 80 chars greatly hinder readability on paper.

Greetings,
Olivier Langlois
http://www.olivierlanglois.net
> 
> I also think that limiting code to 80 columns often hinders
> readability. I personally try to limit my code to 100 columns. The end
> result is pretty nice.
> 
> However, I'm all for the "flat is better than nested" philosophy, even
> when nested is under 100 columns.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ensure a variable is divisible by 4

2006-12-05 Thread david brochu jr

You can use the modulous "%" to check for a remainder of division. If no
remainder is found you know the number is divisible by 4.

Ex:

x = 111

if x%4 == 0:
  print "X is divisible by 4"

-- Forwarded message --
From: "John Machin" <[EMAIL PROTECTED]>
To: [email protected]
Date: 5 Dec 2006 11:26:49 -0800
Subject: Re: Ensure a variable is divisible by 4

Paul Rudin wrote:

Max M <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] skrev:
>> Nick Craig-Wood wrote:
>>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
  I am sure this is a basic math issue, but is there a better way to
  ensure an int variable is divisible by 4 than by doing the

following;


  x = 111
  x = (x /4) * 4
>
> X *= 4
>
> ;-)
>


x=4

:)


Ensure x is divisible by *any* non-zero integer:

x = 0

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

Re: Multiple FTP download using Muliti thread

2006-12-05 Thread johnny
Ok I fixed it. Needed to put in username, and password in the c.login
inside while True loop.

while True:
host, e = tq.get()

c = ftplib.FTP(host)
c.connect()
try:
c.login()
p = posixpath.basename(e)
fp = open('H:/eclipse/workspace/src/ftp_download/' + p,
'wb')

johnny wrote:
> I am getting the following error:
>
> raise error_temp, resp
> error_temp: 421 Unable to set up secure anonymous FTP
>
> Here is the code:
>
> import ftplib, posixpath, threading
> from TaskQueue import TaskQueue
>
> def worker(tq):
> while True:
> host, e = tq.get()
>
> c = ftplib.FTP(host)
> c.connect()
> try:
> c.login()
> p = posixpath.basename(e)
> fp = open('H:/eclipse/workspace/src/ftp_download/' + p,
> 'wb')
> try: c.retrbinary('RETR %s' % e, fp.write)
> finally: fp.close()
> finally: c.close()
>
> tq.task_done()
>
> if __name__ == '__main__':
> q = TaskQueue()
> #host = 'ftp.microsoft.com'
> host = 'mysite.com'
> c = ftplib.FTP(host)
> c.connect()
> try:
> #c.login()
> c.login("[EMAIL PROTECTED]","temppass" )
>
> #folder = '/deskapps/kids/'
> folder = ''
> for n in c.nlst(folder):
> #if n.lower().endswith('.exe'):
> #q.put((host, n))
>  if n.lower().endswith('.jpg'):
> q.put((host, n))
>  elif n.lower().endswith('.jpeg'):
> q.put((host, n))
>
> finally: c.close()
>
> numworkers = 4
> for i in range(numworkers):
> t = threading.Thread(target=worker, args=(q,))
> t.setDaemon(True)
> t.start()
>
> q.join()
> print 'Done.'
>
>
> Justin Ezequiel wrote:
> > johnny wrote:
> > > When I run the following script, with host and password and username
> > > changed, I get the following errors:
> > > raise error_temp, resp
> > > error_temp: 421 Unable to set up secure anonymous FTP
> > >
> > > Dose the host should allow 4 simultaneous login at a time?
> > >
> > 
> > does it work using ftp.microsoft.com?
> > 
> > post your code

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


Re: Does this always go right

2006-12-05 Thread Gabriel Genellina

At Tuesday 5/12/2006 12:04, [EMAIL PROTECTED] wrote:


question about copy vs deepcopy used in multithreaded context:

suppose the following program below:

the original dictionary is modified after the thread is started, the 
thread works on a copied and deepcopied version of the original 
dictionary. Is the dictionary named "originalcopy" isolated from 
changes in original in multithreaded context?


The program reports no errors but I want to be really sure about this


For your simple test dictionary, copy and deepcopy behaves 
identically. If you wish, you should test using values that are 
containers themselves.
With or without threads, modifying original (with the current 
contents) would never modify originalcopy neither originaldeepcopy, 
so you aren't testing anything here.

Try rewriting your test.


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: About the 79 character line recommendation

2006-12-05 Thread Steve Bergman
Thanks for the responses.

The point about 132 columns is good.  Pretty much any printer will
handle that today, though I reserve the right to change my mind about
the utility of 17cpi print after I'm 50. Hopefully, all printers will
be at least 1200dpi by then.  ;-)

---

Yes, I dislike "\" for continuation, and use the implicit continuation
between parentheses, braces, etc. wherever possible.  I don't mind
breaking up comma separated values like function method arguments, but
I very much dislike breaking at an "=" sign.

(BigLong VariableName
 = BigLongMethodCallWithALotOfArguments)

Come to think of it, though, I'm working mostly in TurboGears (web
devel framework) which may not represent python code in general all
that well wrt line length.  Lot's of lines that are harder to break up
than in some other environments, perhaps.

---

I'm finding 100 to be a nice balance.  It forces me not to be lazy and
allow really long lines, but allows me to format so as to make the
meaning most clear.

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


Copy vs Deepcopy in multithreaded contexts

2006-12-05 Thread Carl . Wolff
Helloquestion about copy vs deepcopy used in multithreaded context:suppose the following program below:the original dictionary is modified after the thread is started, the thread works on a copied and deepcopied version of the original dictionary. Is the dictionary named "originalcopy" isolated from changes in original in multithreaded context?The program reports no errors but I want to be really sure about thisThanksCarl.original = {}originalcopy = {}originaldeepcopy = {}class checker(threading.Thread):  def __init__(self):    threading.Thread.__init__(self)    pass  def run(self):    while True:  for i in originaldeepcopy:    if originalcopy[i] == originaldeepcopy[i]:  pass    else:  print "error", originalcopy[i], "Not equal to", originaldeepcopy[i]i = 0  while i<1000:  original[i] = i  i = i + 1originalcopy = copy.copy(original)originaldeepcopy = copy.deepcopy(original)test = checker()test.start()time.sleep(0.5) while True:    i = 0  while i<1000:    original[i] = i*2    i = i + 1 -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Cross-platform issue with wxRadioBox

2006-12-05 Thread eugene . gokhvat
I have updated my script to use wx.RadioButton instead, which works
perfectly on my mac again, but now the submit button doesn't show up on
the pc and I can't click in the netid field on the pc either. any
ideas?

# BEGIN CODE

import wx;

SUBMIT_BUTTON = wx.ID_HIGHEST + 10;

class regFrame(wx.Frame):
   def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title,
  pos=(100, 100), size=(800, 600));

fileDialog = wx.FileDialog(self, "Select a file to which to write",
   style = wx.SAVE | wx.OVERWRITE_PROMPT,
   wildcard="*.txt|Text");
if(fileDialog.ShowModal() != wx.ID_OK):
print "No file specified - closing";
self.Close();
return;
write_file = fileDialog.GetPath();

self.write_file = open(write_file, "a");

# init main frame with menu and status bars

self.panel = wx.Panel ( self, -1 )

menuBar = wx.MenuBar();
fileMenu = wx.Menu();

fileMenu.Append(wx.ID_ABOUT, "&About\tAlt-A", "About this program");
fileMenu.AppendSeparator();
fileMenu.Append(wx.ID_EXIT, "&Quit\tAlt-Q", "Quit this program");
menuBar.Append(fileMenu, "&File");
self.SetMenuBar(menuBar);

self.CreateStatusBar();

self.ctrl_sizer = wx.GridBagSizer(5, 15);

# build the controls

instructions = "  Enter your netid and size in the " + \
"boxes below and press the 'Submit Order' button to place " + \
"your order.";

self.instruction_text = wx.StaticText(self, -1, instructions);
self.id_text = wx.StaticText(self, -1, "  netid");
self.id_input = wx.TextCtrl(self, -1, "", size=(160, -1));
self.size_text = wx.StaticText(self, -1, "size");
self.submit_button = wx.Button(self, SUBMIT_BUTTON, "Submit Order");

# put the controls into a grid

self.ctrl_sizer.Add(self.instruction_text, (0, 0),
span=(1, 3), flag=wx.EXPAND);

self.ctrl_sizer.Add(self.id_text,(1, 0), flag=wx.EXPAND);
self.ctrl_sizer.Add(self.size_text,  (1, 1), flag=wx.EXPAND);
self.ctrl_sizer.Add(self.id_input,   (2, 0), flag=wx.HORIZONTAL);

# TO MODIFY THE LIST OF SIZES, CHANGE THIS:
self.valid_sizes = ['4XLT', '3XLT', '2XLT', '2XL', 'XLT',
'XL', 'LT', 'L', 'M', 'S', 'XS', 'XXS'];
first_size = 1;
size_count = 0;
self.button_array = [];
for this_size in self.valid_sizes:
this_button = '';
if first_size:
this_button = wx.RadioButton(self.panel, -1, this_size,
 style=wx.RB_GROUP);
first_size = 0;
else:
this_button = wx.RadioButton(self.panel, -1, this_size);
self.button_array.append(this_button);
self.ctrl_sizer.Add(this_button, (size_count+2, 1));
size_count += 1;

self.ctrl_sizer.Add(self.submit_button,  (2, 2), flag=wx.HORIZONTAL);

self.SetSizer(self.ctrl_sizer);
self.ctrl_sizer.Fit(self);
# register event handling functions
wx.EVT_MENU(self,   wx.ID_ABOUT, self.OnAbout);
wx.EVT_MENU(self,   wx.ID_EXIT,  self.OnExit);
wx.EVT_BUTTON(self, SUBMIT_BUTTON, self.OnSubmit);

   def OnAbout(self, evt):
return;

   def OnExit(self, evt):
if(self.write_file):
self.write_file.close();
self.Close();

   def OnSubmit(self, evt):
selected_index = -1;
this_index = 0;
for this_button in self.button_array:
if this_button.GetValue():
selected_index = this_index;
this_index += 1;

# make sure the user selected something
if selected_index == -1:
wx.MessageBox("You must select a size to place your order",
  "Please select a size",
  wx.ICON_EXCLAMATION);
return;

# build a tab-delimited-text line of the data and write it
save_fields = [self.id_input.GetValue(),
   self.valid_sizes[selected_index]];
save_str = "\t".join(save_fields);

# ask for validation before we save
dialog_str = "Are you sure this is correct?" + \
"\n  Netid: " + save_fields[0] + \
"\n  Size: " + save_fields[1];
if(wx.MessageBox(dialog_str, "Confirm Order",
 wx.YES_NO | wx.ICON_EXCLAMATION)
   == wx.YES):
# write it out and flush the buffer to make sure it's on disk
self.write_file.write(save_str + "\n");
self.write_file.flush();
wx.MessageBox("Your order has been saved. Thanks!");
# reset the controls for the next user
self.id_input.SetValue('');
 

Re: About the 79 character line recommendation

2006-12-05 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Steve Bergman
wrote:

> While I'm on this general topic, the guide mentions a pet peeve about
> inserting more than one space to line up the "=" in assignment
> statements.  To me, lining them up, even if it requires quite a few
> extra spaces, helps readability quite a bit.  Comments?

That may help readability a little bit but if one of the lines will be
changed the other lines have to be changed too which results in a diff
that masks the "real" change a bit.  If just one line changes it's easier
to read and follow diffs from version control systems.

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


pyopengl glShaderSourceARB error

2006-12-05 Thread joroy
Hi all,

I think this is ctypes related but how can I call the glShaderSourceARB
function?

The function have this header:

glShaderSourceARB( GLhandleARB(shaderObj), GLsizei(count),
POINTER(arrays.GLcharARBArray)(string), GLintArray(length) ) -> None

I call the function with someting like: glShaderSourceARB(self._object,
1, sourceString, 1)

The error is
"expected LP_GLcharArray instance instead of str"

In fact I don't have any information on how to use this function.
This is the last version of pyopengl available on the CVS
(PyOpenGL-3.0.0a5-py2.5.egg)

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


Internet Gambling Losses Refunded

2006-12-05 Thread Stephen . Egan
Greetings,
I came across your ad via Google Search and wanted to inquire about your 
services. I am hoping to recover my losses from online gaming

Please Contact me as soon as possible

Regards,
Steve Egan

Disclaimer
"The information in this email is confidential and may be legally privileged. 
It is intended solely for the addressee and access to this email by anyone else 
is unauthorized. If you are not the intended recipient, any disclosure, 
copying, distribution or any action taken or omitted to be taken in reliance on 
it, is prohibited and may be unlawful.  When addressed to our clients, any 
opinions or advice contained in this email are subject to the terms and 
conditions expressed in the governing client engagement letter or contract."

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

Re: Ensure a variable is divisible by 4

2006-12-05 Thread MRAB

Jonathan Smith wrote:
> > <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >> I am sure this is a basic math issue, but is there a better way to
> >> ensure an int variable is divisible by 4 than by doing the following;
> >>
> >> x = 111
> >> x = (x /4) * 4
> >>
> >> Just seems a bit clunky to me.
>
>
> if ( x % 4 ) == 0:
>   whatever # x is divisible by 4
>
> modulus is your friend :)
>
> -smithj


It's "modulo"; "modulus" is a different operation.


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


newb: Join two string variables

2006-12-05 Thread johnny
How do I join two string variables?
I  want to do:  download_dir + filename.
download_dir=r'c:/download/'
filename =r'log.txt'

I want to get something like this:
c:/download/log.txt

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


Mod_python vs. application server like CherryPy?

2006-12-05 Thread Vincent Delporte
Hi

I'm still a newbie when it comes to web applications, so would like
some help in choosing a solution to write apps with Python: What's the
difference between using running it through mod_python vs. building an
application server using Python-based tools like CherryPy, Quixote,
Draco, etc.?

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


Re: newb: Join two string variables

2006-12-05 Thread Fuzzyman

johnny wrote:
> How do I join two string variables?
> I  want to do:  download_dir + filename.

That should do it. :-)

You can concatenate strings using the plus operator. For large number
of strings it is very inefficient. (Particularly in versions of Python
pre 2.4 or in IronPython.)

For these situations it is better to collect the strings in a list and
then join them using :

''.join(list_of_strings)

But for just two strings, plus is fine.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> download_dir=r'c:/download/'
> filename =r'log.txt'
> 
> I want to get something like this:
> c:/download/log.txt

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


  1   2   >