[ANN] Leipzig Python User Group - Meeting, May 8, 2007, 08:00pm

2007-05-02 Thread Stefan Schwarzer
=== Leipzig Python User Group ===

We will meet on May 8 at 08:00pm at the training center of
Python Academy in Leipzig, Germany
( http://www.python-academy.com/center/find.html ).

Philippe Morath will give a talk titled:

Mobiltelefonprogrammierung mit Python - Python für
die S60 Plattform

(Mobile phone programming with Python - Python for
the S60 platform)

He will start with a short introduction to mobile phone
programming, explain the installation of Python on the S60
platform and in the emulator, and show some simple examples of
Python for mobile phones.

Further information about the S60 mobile phone can be found at
http://www.s60.com .

Food and soft drinks are provided. Please send a short
confirmation mail to [EMAIL PROTECTED], so we can prepare
appropriately.

Everybody who uses Python, plans to do so or is interested in
learning more about the language is encouraged to participate.

While the meeting language will be mainly German, we will provide
English translation if needed.

Current information about the meetings are at
http://www.python-academy.com/user-group .

Stefan

=== Leipzig Python User Group ===

Wir treffen uns am Dienstag, 08.05.2007 um 20:00 Uhr im
Schulungszentrum der Python Academy in Leipzig
( http://www.python-academy.de/Schulungszentrum/anfahrt.html ).

Philippe Morath wird einen Vortrag halten:

Mobiltelefonprogrammierung mit Python - Python für
die S60 Plattform

Nach einer kurzen Einführung in die Mobiltelefonprogrammierung
wird die Installation von Python für S60 auf dem Mobiltelefon und
im Emulator der S60 Plattform erläutert. Weiterhin werden einige
einfache Beispiele für Python auf dem Mobiltelefon gezeigt.

Informationen über das S60-Mobiltelefon gibt es unter
http://www.s60.com .

Für das leibliche Wohl wird gesorgt. Eine Anmeldung unter
[EMAIL PROTECTED] wäre nett, damit wir genug Essen
besorgen können.

Willkommen ist jeder, der Interesse an Python hat, die Sprache
bereits nutzt oder nutzen möchte.

Aktuelle Informationen zu den Treffen sind unter
http://www.python-academy.de/User-Group zu finden.

Viele Grüße
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: os.path.join

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 01:23:45 -0300, Elliot Peele [EMAIL PROTECTED]  
escribió:

 On Tue, 2007-05-01 at 19:27 -0700, 7stud wrote:
 On May 1, 7:36 pm, Elliot Peele [EMAIL PROTECTED] wrote:
  Why does os.path.join('/foo', '/bar') return '/bar' rather than
  '/foo/bar'? That just seems rather counter intuitive.
 
  Elliot

 join(path1[, path2[, ...]])
 Join one or more path components intelligently. If any component is an
 absolute path, all previous components (on Windows, including the
 previous drive letter, if there was one) are thrown away...

 Yes, but that still doesn't answer my question as to why os.path.join
 works that way. I understand that that is how it is written, but why?

It's not *how* it is written, but the current documentation for  
os.path.join:
http://docs.python.org/lib/module-os.path.html#l2h-2176
It appears that the function docstring (used by the help system) is too  
terse here.

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


Re: os.path.join

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 02:31:43 -0300, [EMAIL PROTECTED] escribió:

 A better question is why this doesn't work.

 pathparts = [/foo, bar]
 os.path.join(pathparts)
 ['/foo', 'bar']

 This should return a string in my opinion.

I think it's a bug, but because it should raise TypeError instead.
The right usage is os.path.join(*pathparts)

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


Re: While we're talking about annoyances

2007-05-02 Thread Tim Roberts
Michael Hoffman [EMAIL PROTECTED] wrote:

Hint: if you find yourself using a decorate-sort-undecorate pattern, 
sorted(key=func) or sequence.sort(key=func) might be a better idea.

Is it?  I thought I remember reading on this very list some years ago that
the performance of sequence.sort became much, much worse when a key
function was supplied.

I've tended to favor the Schwarzian transform (decorate-sort-undecorate)
because of that.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with inspect.getfile

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 02:53:55 -0300, elventear [EMAIL PROTECTED]  
escribió:

 Found the offending code. I was importing between files that were at
 the same level of the hierarchy without using absolute references.
 Coded worked fine, but inspect didn't. Was this gaffe on my part? Or
 was inspect supposed to handle it?

Could you provide an example?

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


Re: ScrolledText?

2007-05-02 Thread half . italian
On May 1, 3:12 pm, nik [EMAIL PROTECTED] wrote:
 I've been trying to get the scrollbar and text box always going to the
 last line and have been completely unsuccessful.

 I've tried, ScrolledText, text.see, and text.yview_pickplace without
 success

 for instance this was the last setup:

  self.text = ScrolledText(master, relief=RIDGE)
  self.text.grid(column=1, row=2, columnspan=10,\
 rowspan=5, pady=10, sticky=NSEW)

 with this text entry:

  self.text.insert(END, ins)
  self.text.yview_pickplace(end)

 Can anybody please tell me what I might be doing wrong, or an example
 that works, so that I can see what's going wrong.

 Thanks,
 Nik

try...

self.text.yview_moveto(1)

~Sean

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


Re: While we're talking about annoyances

2007-05-02 Thread Steven D'Aprano
On Wed, 02 May 2007 06:10:54 +, Tim Roberts wrote:

 Michael Hoffman [EMAIL PROTECTED] wrote:

Hint: if you find yourself using a decorate-sort-undecorate pattern, 
sorted(key=func) or sequence.sort(key=func) might be a better idea.
 
 Is it?  I thought I remember reading on this very list some years ago that
 the performance of sequence.sort became much, much worse when a key
 function was supplied.

You're probably thinking of a comparison function:

sequence.sort(cmp=lambda x, y: cmp(y, x)) 

is a slow way of sorting a sequence in reverse order. The fast
way is the two liner:

sequence.sort() 
sequence.reverse() 

Faster(?) still is:

sequence.sort(reverse=True)


 I've tended to favor the Schwarzian transform (decorate-sort-undecorate)
 because of that.

That's what the key= argument does. cmp= is slow because the comparison
function is called for EVERY comparison. The key= function is only called
once per element.



-- 
Steven D'Aprano 


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


Re: Python user group in Portland, OR?

2007-05-02 Thread bradallen
It looks like there are a lot of folks in the Portland area at
meetup.com who have expressed an interest in a meetup group. In hopes
of attracting those, I went ahead and shelled out the bucks to start a
meetup site for a Portland Python user group:

http://python.meetup.com/183/




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


Re: os.path.join

2007-05-02 Thread half . italian
On May 1, 11:10 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Wed, 02 May 2007 02:31:43 -0300, [EMAIL PROTECTED] escribió:

  A better question is why this doesn't work.

  pathparts = [/foo, bar]
  os.path.join(pathparts)
  ['/foo', 'bar']

  This should return a string in my opinion.

 I think it's a bug, but because it should raise TypeError instead.
 The right usage is os.path.join(*pathparts)

 --
 Gabriel Genellina

Wow.  What exactly is that * operator doing?  Is it only used in
passing args to functions?  Does it just expand the list into
individual string arguments for exactly this situation?  Or does it
have other uses?

~Sean

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


Re: Why are functions atomic?

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 01:42:17 -0300, Martin v. Löwis [EMAIL PROTECTED]  
escribió:

 Michael schrieb:
 A bit more info, but still no clear picture about why functions are
 mutable but have immutable copy symantics.  There are arguments why
 functions should be immutable, but the decision was to make user-
 defined functions mutable.  My question is still: why the present
 ummutable copy symantics?

 The answer is really really simple. The implementation of copy predates
 mutability. When the copy code was written, functions *were* immutable.
 When functions became mutable, the copy code was not changed, and
 nobody noticed or complained.

Likely scenario, but not true. Support for copying user functions was  
added on 2.5 (see  
http://svn.python.org/view/python/trunk/Lib/copy.py?rev=42573r1=38995r2=42573)
  
and functions were mutable since a long time ago. On previous versions,  
functions could be pickled but not copied.
The same thing happens for classes: they are mutable too, but copy  
considers them immutable and returns the same object. This is clearly  
stated on the documentation (but the module docstring is still outdated).

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


Re: os.path.join

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 04:03:56 -0300, [EMAIL PROTECTED] escribió:

 On May 1, 11:10 pm, Gabriel Genellina [EMAIL PROTECTED]
 wrote:

 The right usage is os.path.join(*pathparts)

 Wow.  What exactly is that * operator doing?  Is it only used in
 passing args to functions?  Does it just expand the list into
 individual string arguments for exactly this situation?  Or does it
 have other uses?

When calling a function, it is used to pass a sequence as positional  
arguments. Similarly, **values is used to pass a dictionary as keyword  
arguments.
When defining a function, *args receives the remaining positional  
arguments not already bound to another parameter; and **kwargs receives  
the remaining keyword arguments not already bound to another parameter.  
[There is nothing special on the *args and **kwargs names, only the * and  
** are important]
See section 4.7 on the Python Tutorial  
http://docs.python.org/tut/node6.html#SECTION00670 and  
specially section 4.7.4 Unpacking Argument Lists.
For a more technical description (but sometimes necesary) read the Python  
Reference Manual http://docs.python.org/ref/calls.html

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


Re: os.path.join

2007-05-02 Thread Ant
On May 2, 8:03 am, [EMAIL PROTECTED] wrote:
 On May 1, 11:10 pm, Gabriel Genellina [EMAIL PROTECTED]
...
  I think it's a bug, but because it should raise TypeError instead.
  The right usage is os.path.join(*pathparts)
...
 Wow.  What exactly is that * operator doing?  Is it only used in
 passing args to functions?  Does it just expand the list into
 individual string arguments for exactly this situation?  Or does it
 have other uses?

It's used for unpacking a collection into arguments to a function.
It's also used at the other end for receiving a variable length set of
arguments. i.e.

 x = (1,3)
 def add(a, b):
return a + b

 add(*x)
4
 def add(*args):
return reduce(int.__add__, args)

 add(1,2,3,4,5,6)
21
 add(*x)
4

The same sort of thing holds for keyword arguments:

 def print_kw(**kw):
 for k in kw:
 print kw[k]


 print_kw(a=1, b=2)
1
2
 d = {'a': 1, 'b': 10, 'c': 100}
 print_kw(**d)
1
100
10


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


Re: Tcl-tk 8.5?

2007-05-02 Thread James Stroud
Méta-MCI wrote:
 Hi!
 
 
 See http://wiki.tcl.tk/10630
 
 Any plan to integrate Tcl 8.5 in standard Python?
 
 
 
 @+
 
 MCI
 

Better would be to outegrate it and instead use another gui kit as the 
standard.

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


Re: Dynamic File Name Open()

2007-05-02 Thread Tim Golden
Robert Rawlins - Think Blue wrote:
 I'm trying to open a file using open() but the name of the file is created
 dynamically as a variable, but also has part of a static path. For instance,
 the file may be called 'dave' and will always be in '/my/files/here/'.

Well that's an absolutely normal way of doing
things, so if my toy example below doesn't make
things clear, you'd better post a code fragment
and/or some traceback.

code
import os, sys

path = c:/temp
for filename in [chas.txt, dave.txt]:
   f = open (os.path.join (path, filename))
   print filename
   print f.read ()
   print
   f.close ()

/code

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


Re: Killing Threads

2007-05-02 Thread Tim Golden
Robert Rawlins - Think Blue wrote:
 I've got an application which I've fearfully placed a couple of threads into
 however when these threads are running it seems as if I try and quite the
 application from the bash prompt it just seems to freeze the SSH client.
 I've also seen that if I have my app running in the background on the system
 then my 'reboot' no longer works, it just hangs after saying it's going to
 shut down.

You really need to post code fragments: it makes it much
easier to see what you've actually done, rather than the
guess which I'm making :)

You probably need to setDaemon (True) on your threads
after you've created them and before they run. That
tells the OS: don't bother waiting for these ones to
finish if the program exits. (At least I think that's
what it does; I don't use threads all that much)

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


Re: os.path.join

2007-05-02 Thread half . italian
On May 2, 12:36 am, Ant [EMAIL PROTECTED] wrote:
 On May 2, 8:03 am, [EMAIL PROTECTED] wrote:

  On May 1, 11:10 pm, Gabriel Genellina [EMAIL PROTECTED]
 ...
   I think it's a bug, but because it should raise TypeError instead.
   The right usage is os.path.join(*pathparts)
 ...
  Wow.  What exactly is that * operator doing?  Is it only used in
  passing args to functions?  Does it just expand the list into
  individual string arguments for exactly this situation?  Or does it
  have other uses?

 It's used for unpacking a collection into arguments to a function.
 It's also used at the other end for receiving a variable length set of
 arguments. i.e.

  x = (1,3)
  def add(a, b):

 return a + b

  add(*x)
 4
  def add(*args):

 return reduce(int.__add__, args)

  add(1,2,3,4,5,6)
 21
  add(*x)

 4

 The same sort of thing holds for keyword arguments:

  def print_kw(**kw):

  for k in kw:
  print kw[k]

  print_kw(a=1, b=2)

 1
 2 d = {'a': 1, 'b': 10, 'c': 100}
  print_kw(**d)

 1
 100
 10

Thank you both.

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


Re: Killing Threads

2007-05-02 Thread Diez B. Roggisch
 You probably need to setDaemon (True) on your threads
 after you've created them and before they run. That
 tells the OS: don't bother waiting for these ones to
 finish if the program exits. (At least I think that's
 what it does; I don't use threads all that much)

Actually all it does is to tell the at_exit-handler that it's ok to 
terminate even though there are still some threads. The OS isn't 
concerned with this.

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


Re: regexp match string with word1 and not word2

2007-05-02 Thread Flyzone
On 30 Apr, 20:00, Steven Bethard [EMAIL PROTECTED] wrote:
 Well then it seems like you might want to rethink this rule-file
 approach since your problem is clearly not amenable to regular expressions.
[cut]
 That said, here's a regexp that might work::
  ((?!two:).)*one((?!two:).)*
 That makes a negative lookahead assertion at each character in the string.

But match again something so don't work like i wanted.

Maybe a right approach will be another if after the first one? Like:
   for y in range(0, len(skip_lst) ):
 if (re.search(skip_lst[y], line)):
 if
(re.search(skip_lst_negative[y], line)):
   skip=1
   break
and in the rule-file, i could add a new column and check to do the if
just if the second column is not empty.

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


RE: Killing Threads

2007-05-02 Thread Robert Rawlins - Think Blue
Thanks for this Diez and Tim,

I'll take a look into this today, sorry for not posting any code fragments,
its not so much a fragment as it is a bloody great big monster :-D

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Diez B. Roggisch
Sent: 02 May 2007 09:05
To: python-list@python.org
Subject: Re: Killing Threads

 You probably need to setDaemon (True) on your threads
 after you've created them and before they run. That
 tells the OS: don't bother waiting for these ones to
 finish if the program exits. (At least I think that's
 what it does; I don't use threads all that much)

Actually all it does is to tell the at_exit-handler that it's ok to 
terminate even though there are still some threads. The OS isn't 
concerned with this.

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

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


DiffLib Question

2007-05-02 Thread whitewave
Hi Guys,
I'm a bit confused in difflib. In most cases, the differences
found  using difflib works well but when I have come across the
following set of text:

 d1 = '''In addition, the considered problem does not have a meaningful 
 traditional type of adjoint
... problem even for the simple forms of the differential equation and
the nonlocal conditions. Due to these facts, some serious difficulties
arise in the application of the classical methods to such a
problem.'''
 d2 = '''In addition, the considered problem does not have a meaningful 
 traditional type of
... adjoint problem even for the simple forms of the differential
equation and the nonlocal conditions. Due
... to these facts, some serious difficulties arise in the application
of the classical methods to such a
... problem. '''

Using this line of code:

 a = difflib.Differ().compare(d1,d2)
 dif =[]
 for i in a:
... dif.append(i)
... s = ''.join(dif)

I get the following output:

'  I  n a  d  d  i  t  i  o  n  , t  h  e c  o  n  s  i
d  e  r  e  d p  r  o  b  l  e  m d  o  e  s n  o  t
h  a  v  e a m  e  a  n  i  n  g  f  u  l t  r  a  d  i
t  i  o  n  a  l t  y  p  e o  f-  + \n  a  d  j  o  i  n  t+
+ p+ r+ o+ b+ l+ e+ m+  + e+ v+ e+ n+  + f+ o+ r+  + t+ h+ e+  + s+ i+
m+ p+ l+ e+  + f+ o+ r+ m+ s+  + o+ f+  + t+ h+ e+  + d+ i+ f+ f+ e+ r
+ e+ n+ t+ i+ a+ l+  + e+ q+ u+ a+ t+ i+ o+ n+  + a+ n+ d+  + t+ h+ e
+  + n+ o+ n+ l+ o+ c+ a+ l+  + c+ o+ n+ d+ i+ t+ i+ o+ n+ s+ .+  + D+
u+ e  \n+ t+ o+  + t+ h+ e+ s+ e+  + f+ a+ c+ t+ s+ ,+  + s+ o+ m+ e+
+ s+ e+ r+ i+ o+ u+ s+  + d+ i+ f+ f+ i+ c+ u+ l+ t+ i+ e+ s+  + a+ r+
i+ s+ e+  + i+ n+  + t+ h+ e+  + a+ p+ p+ l+ i+ c+ a+ t+ i+ o+ n+  + o
+ f+  + t+ h+ e+  + c+ l+ a+ s+ s+ i+ c+ a+ l+  + m+ e+ t+ h+ o+ d+ s
+  + t+ o+  + s+ u+ c+ h+  + a+ \n  p  r  o  b  l  e  m-  - e- v- e-
n-  - f- o- r-  - t- h- e-  - s- i- m- p- l- e-  - f- o- r- m- s-  -
o- f-  - t- h- e-  - d- i- f- f- e- r- e- n- t- i- a- l-  - e- q- u-
a- t- i- o- n-  - a- n- d-  - t- h- e-  - n- o- n- l- o- c- a- l-  -
c- o- n- d- i- t- i- o- n- s  .   - D- u- e-  - t- o-  - t- h- e- s-
e-  - f- a- c- t- s- ,-  - s- o- m- e-  - s- e- r- i- o- u- s-  - d-
i- f- f- i- c- u- l- t- i- e- s-  - a- r- i- s- e-  - i- n-  - t- h-
e-  - a- p- p- l- i- c- a- t- i- o- n-  - o- f-  - t- h- e-  - c- l-
a- s- s- i- c- a- l-  - m- e- t- h- o- d- s-  - t- o-  - s- u- c- h-
- a-  - p- r- o- b- l- e- m- .'

How come the rest of the text after the adjoint word is marked as an
additional text (while others is deleted) while in fact those text are
contained in both d1 and d2?The only difference is that it has a
newline. I'm I missing something? Is there a way for me to disregard
the newlines and spaces?

Python 2.3
WINXP

Thanks.
Jen

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


Re: DiffLib Question

2007-05-02 Thread Michele Simionato
On May 2, 10:46 am, whitewave [EMAIL PROTECTED] wrote:
 Is there a way for me to disregard
 the newlines and spaces?

 Python 2.3
 WINXP

 Thanks.
 Jen

HTH:

 help(difflib.Differ.__init__)
Help on method __init__ in module difflib:

__init__(self, linejunk=None, charjunk=None) unbound difflib.Differ
method
Construct a text differencer, with optional filters.

The two optional keyword parameters are for filter functions:

- `linejunk`: A function that should accept a single string
argument,
  and return true iff the string is junk. The module-level
function
  `IS_LINE_JUNK` may be used to filter out lines without visible
  characters, except for at most one splat ('#').  It is
recommended
  to leave linejunk None; as of Python 2.3, the underlying
  SequenceMatcher class has grown an adaptive notion of noise
lines
  that's better than any static definition the author has ever
been
  able to craft.

- `charjunk`: A function that should accept a string of length 1.
The
  module-level function `IS_CHARACTER_JUNK` may be used to filter
out
  whitespace characters (a blank or tab; **note**: bad idea to
include
  newline in this!).  Use of IS_CHARACTER_JUNK is recommended.


 Michele Simionato

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


Re: DiffLib Question

2007-05-02 Thread whitewave
Hi,
Thank you for your reply. But I don't fully understand what the
charjunk and linejunk is all about. I'm a bit newbie in python using
the DiffLib. I'm I using the right code here? I will I implement the
linejunk and charjunk using the following code?

 a = difflib.Differ().compare(d1,d2)
 dif =[]
 for i in a:

... dif.append(i)
... s = ''.join(dif)

Thanks
Jen

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


Re: Want to build a binary header block

2007-05-02 Thread Nick Craig-Wood
Bob Greschke [EMAIL PROTECTED] wrote:
  This is the idea
 
 Block = pack(240s, )
 Block[0:4] = pack(H, W)
 Block[4:8] = pack(H, X)
 Block[8:12] = pack(B, Y)
 Block[12:16] = pack(H, Z))
 
  but, of course, Block, a str, can't be sliced.

You could do this (note anonymous mappings require python 2.5)

 from mmap import mmap
 from struct import pack
 W,X,Y,Z=1,2,3,4
 Block = mmap(-1, 1024)
 Block[0:2] = pack(H, W)
 Block[4:6] = pack(H, X)
 Block[8:9] = pack(B, Y)
 Block[12:14] = pack(H, Z)
 Block[0:16]
'\x00\x01\x00\x00\x00\x02\x00\x00\x03\x00\x00\x00\x00\x04\x00\x00'


You might also want to consider Construct

  http://construct.wikispaces.com/

From the web page: Construct is a python library for parsing and
building of data structures (binary or textual). It is based on the
concept of defining data structures in a declarative manner, rather
than procedural code: more complex constructs are composed of a
hierarchy of simpler ones. It's the first library that makes parsing
fun, instead of the usual headache it is today.

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


Re: Comparing bitmap images for differences?

2007-05-02 Thread [EMAIL PROTECTED]
On May 1, 3:42 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 With that, you can approach your problem. What is usually done is that a
 sequence of background images is sampled  an average is built. Then the
 actual image is subtracted from that image, with an epsilon to account
 for noise.

Thanks for the tip for an algorithm - I can see how that could work
really nicely (and it gives me some ideas for other things, too!)
Thanks also for the link to the OpenCV bindings.  I'll give 'em a try
and see what happens.

Regards,
  Matthew.

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


What do people use for code analysis.

2007-05-02 Thread Steven W. Orr
Lots of code, calls to, calls by, inheritance, multiple tasks, etc.

What do people use to figure out what's happening?

TIA

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparing bitmap images for differences?

2007-05-02 Thread [EMAIL PROTECTED]
On May 1, 7:15 pm, 3c273 [EMAIL PROTECTED] wrote:
 This might get you started.http://tinyurl.com/7qexl

Wow, I thought briefly along those lines but then thought No, it
can't possibly be that easy :-)  It looks like the approach given in
that link could benefit hugely from using numpy to treat the bitmaps
as arrays to speed up processing but that should be pretty
straightforward.  I'll give it a try as-is and then look at
optimisation if required.  Saying that, and thinking about the itch
I'm trying to scratch here, I think I could also safely ignore the
borders of the image so that would reduce the processing requirements
anyway.  Add in a FIFO file buffer so I can do pre/post-event image
capture plus a spot of SMTP mail alerting and the job's done!

Thanks again.
  Matthew.

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


Calling Exe from Python

2007-05-02 Thread muhamad.abbas
Hello Folks,

This is what i am required to do.
Call an executable from my python script, and when the executable is
finished running, i should continue with my python script.

I have tried os.exec() but it calls the executable and never returns
to the calling python script.
I tried os.fork it will start an independent process,
since logic of my program depends on the results of executable.

I am unable to figure, how to do it.
Hope you folks would help me.

~JinBaba

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


Re: What do people use for code analysis.

2007-05-02 Thread Daniel Nogradi
 Lots of code, calls to, calls by, inheritance, multiple tasks, etc.

 What do people use to figure out what's happening?

This is a pretty cool project just for that:

http://codeinvestigator.googlepages.com/codeinvestigator

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


Calling Exe from Python

2007-05-02 Thread M Abbas
Hello Folks,

This is what i am required to do.
Call an executable from my python script, and when the executable is
fininshed running, i should continue with my python script.

I have tried os.exec() but it calls the executable and never returns
to the calling python script.
I tried os.fork it will start an independent process,
since logic of my program depends on the results of executable.

I am unable to figure, how to do it.
Hope you folks would help me.

~JinBaba

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


Re: Problem with PyQt4

2007-05-02 Thread [EMAIL PROTECTED]
On Apr 30, 10:32 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Hi,

 I am having some serious problems with PyQT4,
 when i run pyqt script, I always get 'Segmentation fault'.

 the script is simple:
 ==
 %less qttest.py
 from PyQt4 import QtGui, QtCore
 import sys

 if __name__ == '__main__':
 app = QtGui.QApplication(sys.argv)
 w = QtGui.QMainWindow()
 w.show()
 app.exec_()
 ==

 When I run it , it crashes.
 ==
 %python qttest.py
 Segmentation fault (core dumped)
 =

 And the output with '-v' argument is :
 =
 %python -v qttest.py
 # installing zipimport hook
 import zipimport # builtin
 # installed zipimport hook
 # /usr/local/lib/python2.4/site.pyc matches /usr/local/lib/python2.4/
 site.py
 import site # precompiled from /usr/local/lib/python2.4/site.pyc
 # /usr/local/lib/python2.4/os.pyc matches /usr/local/lib/python2.4/
 os.py
 import os # precompiled from /usr/local/lib/python2.4/os.pyc
 import posix # builtin
 # /usr/local/lib/python2.4/posixpath.pyc matches /usr/local/lib/
 python2.4/posixp
 ath.py
 import posixpath # precompiled from /usr/local/lib/python2.4/
 posixpath.pyc
 # /usr/local/lib/python2.4/stat.pyc matches /usr/local/lib/python2.4/
 stat.py
 import stat # precompiled from /usr/local/lib/python2.4/stat.pyc
 # /usr/local/lib/python2.4/UserDict.pyc matches /usr/local/lib/
 python2.4/UserDic
 t.py
 import UserDict # precompiled from /usr/local/lib/python2.4/
 UserDict.pyc
 # /usr/local/lib/python2.4/copy_reg.pyc matches /usr/local/lib/
 python2.4/copy_re
 g.py
 import copy_reg # precompiled from /usr/local/lib/python2.4/
 copy_reg.pyc
 # /usr/local/lib/python2.4/types.pyc matches /usr/local/lib/python2.4/
 types.py
 import types # precompiled from /usr/local/lib/python2.4/types.pyc
 # /usr/local/lib/python2.4/warnings.pyc matches /usr/local/lib/
 python2.4/warning
 s.py
 import warnings # precompiled from /usr/local/lib/python2.4/
 warnings.pyc
 # /usr/local/lib/python2.4/linecache.pyc matches /usr/local/lib/
 python2.4/lineca
 che.py
 import linecache # precompiled from /usr/local/lib/python2.4/
 linecache.pyc
 import encodings # directory /usr/local/lib/python2.4/encodings
 # /usr/local/lib/python2.4/encodings/__init__.pyc matches /usr/local/
 lib/python2
 .4/encodings/__init__.py
 import encodings # precompiled from /usr/local/lib/python2.4/encodings/
 __init__.
 pyc
 # /usr/local/lib/python2.4/codecs.pyc matches /usr/local/lib/python2.4/
 codecs.py
 import codecs # precompiled from /usr/local/lib/python2.4/codecs.pyc
 import _codecs # builtin
 # /usr/local/lib/python2.4/encodings/aliases.pyc matches /usr/local/
 lib/python2.
 4/encodings/aliases.py
 import encodings.aliases # precompiled from /usr/local/lib/python2.4/
 encodings/a
 liases.pyc
 # /usr/local/lib/python2.4/encodings/gb2312.pyc matches /usr/local/lib/
 python2.4
 /encodings/gb2312.py
 import encodings.gb2312 # precompiled from /usr/local/lib/python2.4/
 encodings/gb
 2312.pyc
 dlopen(/usr/local/lib/python2.4/lib-dynload/_codecs_cn.so, 2);
 import _codecs_cn # dynamically loaded from /usr/local/lib/python2.4/
 lib-
 dynload /
 _codecs_cn.so
 dlopen(/usr/local/lib/python2.4/lib-dynload/_multibytecodec.so, 2);
 import _multibytecodec # dynamically loaded from /usr/local/lib/
 python2.4/lib-
 dy nload/
 _multibytecodec.so
 Python 2.4.3 (#2, Oct 15 2006, 05:32:11)
 [GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
 Type help, copyright, credits or license for more information.
 import PyQt4 # directory /usr/local/lib/python2.4/site-packages/PyQt4
 # /usr/local/lib/python2.4/site-packages/PyQt4/__init__.pyc matches /
 usr/local/
 l ib/
 python2.4/site-packages/PyQt4/__init__.py
 import PyQt4 # precompiled from /usr/local/lib/python2.4/site-packages/
 PyQt4/__i
 nit__.pyc
 dlopen(/usr/local/lib/python2.4/site-packages/PyQt4/QtGui.so, 2);
 dlopen(/usr/local/lib/python2.4/site-packages/sip.so, 2);
 import sip # dynamically loaded from /usr/local/lib/python2.4/site-
 packages/
 sip. so
 dlopen(/usr/local/lib/python2.4/site-packages/PyQt4/QtCore.so, 2);
 import PyQt4.QtCore # dynamically loaded from /usr/local/lib/python2.4/
 site-pack
 ages/PyQt4/QtCore.so
 import PyQt4.QtGui # dynamically loaded from /usr/local/lib/python2.4/
 site-packa
 ges/PyQt4/QtGui.so
 Segmentation fault (core dumped)
 %python -v qttest.py
 # installing zipimport hook
 import zipimport # builtin
 # installed zipimport hook
 # /usr/local/lib/python2.4/site.pyc matches /usr/local/lib/python2.4/
 site.py
 import site # precompiled from /usr/local/lib/python2.4/site.pyc
 # /usr/local/lib/python2.4/os.pyc matches /usr/local/lib/python2.4/
 os.py
 import os # precompiled from 

Re: Calling Exe from Python

2007-05-02 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], M Abbas wrote:

 This is what i am required to do.
 Call an executable from my python script, and when the executable is
 fininshed running, i should continue with my python script.
 
 I have tried os.exec() but it calls the executable and never returns
 to the calling python script.
 I tried os.fork it will start an independent process,
 since logic of my program depends on the results of executable.

Take a look at `os.system()` or the `subprocess` module.

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


Leaving Python List

2007-05-02 Thread Gurpreet Singh
This mail is to confirm that i want to leave the
python list.



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


Re: relative import broken?

2007-05-02 Thread Alan Isaac
Alex Martelli [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 So what do you think the answer should be?

Well I'm clearly not seeing into the depths of this,
so I'm not going to propose anything.  But to stick
close to my example, I am not clear why a script
when executed could not do imports relative to
__file__.  This seems like natural behavior to me.

Thanks,
Alan Isaac


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


Re: Dynamic File Name Open()

2007-05-02 Thread tahiriman
On May 2, 7:47 am, Tim Golden [EMAIL PROTECTED] wrote:
 Robert Rawlins - Think Blue wrote:

  I'm trying to open a file using open() but the name of the file is created
  dynamically as a variable, but also has part of a static path. For instance,
  the file may be called 'dave' and will always be in '/my/files/here/'.

 Well that's an absolutely normal way of doing
 things, so if my toy example below doesn't make
 things clear, you'd better post a code fragment
 and/or some traceback.

 code
 import os, sys

 path = c:/temp
 for filename in [chas.txt, dave.txt]:
f = open (os.path.join (path, filename))
print filename
print f.read ()
print
f.close ()

 /code

 TJG


you have to look at the method open(string path, string mode)
properties
so, you can change the argument, string path,  dynamicly

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


Need Help in Preparing for Study of Python by Forrester Research

2007-05-02 Thread Jeff Rush
Forrester Research is doing a study on dynamic languages and has asked that
Python be represented.  As advocacy coordinator I've volunteered to drive
this, collecting answers from the community and locating representatives to
participate in interviews.

The goal of the study is to:

 - identify the criteria to use for evaluating such languages
 - identify the relevant choices of dynamic languages
 - identify how the different dynamic languages stack up
 - examine where dynamic languages work best

Initially, they'd like feedback (not yet the answers themselves) from us
regarding their proposed evaluation criteria - questions to add or that give
no value, rewording to make them more clear.  I've posted their draft
criteria, which came as a spreadsheet at:

  http://dfwpython.org/uploads/ForresterPrep/DynamicLanguagesCriteria.xls

Later, between May 8 and 25, the researchers will need to interview via 1-hour
telephone calls, several developers with experience using Python.  And they
want to also interview one person with an executive viewpoint, able to
describe relevant background, positioning, value proposition, customer base,
and strategic vision.

And later they would also like snippets of Python code that illustrate the
power of Python, and I hope to call upon community members to help in
producing that.  The snippets do not have to be originally written and can be
pulled from existing projects.

But those steps come later.  For now let's focus on analysis of the evaluation
criteria at the above URL.  Time is short as they'd like that feedback by May
3, so please get any responses to me as soon as possible.  And be thinking who
would best represent the executive view of Python in an interview.

Thanks for your help,

Jeff Rush
Advocacy Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why are functions atomic?

2007-05-02 Thread Carsten Haese
On Tue, 2007-05-01 at 22:21 -0700, Michael wrote:
 Is there a reason for using the closure here?  Using function defaults
 seems to give better performance:[...]

It does? Not as far as I can measure it to any significant degree on my
computer.

 This is definitely one viable solution and is essentially what I had
 in mind, but I did not want to have to carry the generator arround
 with me:

I don't know what you mean by carry it around. Just put it in a module
and import it where you need it.

An overriding theme in this thread is that you are greatly concerned
with the speed of your solution rather than the structure and
readability of your code. How often is your function going to get called
and how much of a performance benefit are you expecting?

-Carsten


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


Re: More urllib timeout issues.

2007-05-02 Thread Facundo Batista
John Nagle wrote:

  I took a look at Facundo Batista's work in the tracker, and he
 currently seems to be trying to work out a good way to test the
 existing SSL module.  It has to connect to something to be tested,

Right now, test_socket_ssl.py has, besides the previous tests, the
capability of executing openssl's s_server and connect to him.

I'm lees than a SSL begginer, so I do not have the knowledge to make
interesting tests, I just made the obvious ones...

If you know SSL, you can take that code and add new tests very easily.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: More urllib timeout issues.

2007-05-02 Thread Facundo Batista
Steve Holden wrote:

 1) There is work afoot to build timeout arguments into network libraries 
 for 2.6, and I know Facundo Batista has been involved, you might want to 
 Google or email Facundo about that.

Right now (in svn trunk) httplib, ftplib, telnetlib, etc, has a timeout
argument.

If you use it, the socket timeout will be set (through s.settimeout()).
What behaviour has the socket after setting it the timeout, is beyond of
these changes, though.

BTW, I still need to make the final step here, that is adding a timeout
argument to urllib2.urlopen().

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: What do people use for code analysis.

2007-05-02 Thread Steven W. Orr
On Wednesday, May 2nd 2007 at 12:48 +0200, quoth Daniel Nogradi:

= Lots of code, calls to, calls by, inheritance, multiple tasks, etc.
=
= What do people use to figure out what's happening?
=
=This is a pretty cool project just for that:
=
=http://codeinvestigator.googlepages.com/codeinvestigator

I looked at codeinvestigator  but it looks like it doesn't do what I want.

I saw something about source navigator having python support. Have people 
used it? Does that work well?

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What do people use for code analysis.

2007-05-02 Thread Laurent Pointal
Steven W. Orr a écrit :
 Lots of code, calls to, calls by, inheritance, multiple tasks, etc.
 
 What do people use to figure out what's happening?
 
 TIA
 
I've collected some links over time:

http://www.limsi.fr/Individu/pointal/python.html#liens-metaprog

You may look at
# depgraph - graphe de dépendances entre modules
# coverage - a Python module that measures code coverage during Python
execution
# pycover - a python coverage tool
# pycount - métrique de lignes sources Python
# depgraph - generating python module dependency graphs
# pycallgraph - génération du graphe d'appels pour les programmes Python
(nécessite GraphViz).

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


pack/unpack zero terminated string

2007-05-02 Thread tmp123
Hello,

Thanks for your time.

After review the struct documentation, it seems there are no option
to pack/unpack zero terminated strings.

By example, if the packed data contains: byte + zero terminated string
+ zero terminated string + byte, it seems no possible to unpack it
using struct.

Please, has someone any hint or pointer to another librarian to be
used?

Thanks.

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


Re: pack/unpack zero terminated string

2007-05-02 Thread Laurent Pointal
tmp123 a écrit :
 Hello,
 
 Thanks for your time.
 
 After review the struct documentation, it seems there are no option
 to pack/unpack zero terminated strings.
 
 By example, if the packed data contains: byte + zero terminated string
 + zero terminated string + byte, it seems no possible to unpack it
 using struct.
 
 Please, has someone any hint or pointer to another librarian to be
 used?

May look at ctypes and its c_char_p type

Documentation says:
http://python.net/crew/theller/ctypes/reference.html#fundamental-data-types

c_char_p
 Represents the C char * datatype, which must be a pointer to a 
zero-terminated string. The constructor accepts an integer address, or a 
string.

Note: its in standard libraries from Python 2.5.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While we're talking about annoyances

2007-05-02 Thread Michael Hoffman
Steven D'Aprano wrote:
 On Wed, 02 May 2007 06:10:54 +, Tim Roberts wrote:

 I've tended to favor the Schwarzian transform (decorate-sort-undecorate)
 because of that.
 
 That's what the key= argument does. cmp= is slow because the comparison
 function is called for EVERY comparison. The key= function is only called
 once per element.

Right. Using sort(key=keyfunc) is supposed to be faster than 
decorate-sort-undecorate. And I think it is clearer too.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pack/unpack zero terminated string

2007-05-02 Thread Laurent Pointal
tmp123 a écrit :
 Hello,
 
 Thanks for your time.
 
 After review the struct documentation, it seems there are no option
 to pack/unpack zero terminated strings.
 
 By example, if the packed data contains: byte + zero terminated string
 + zero terminated string + byte, it seems no possible to unpack it
 using struct.
 
 Please, has someone any hint or pointer to another librarian to be
 used?

May look at xstruct too

http://www.sis.nl/python/xstruct/xstruct.shtml

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


open(output/mainwindow.h,'w') doesn't create a folder for me

2007-05-02 Thread noagbodjivictor
Hello
I have done python for some time now. I'm forgetting things.

This is the faulty line : outfile = open(output/mainwindow.h,'w')

I thought it would have created the folder ouput and the file
mainwindow.h for me but it's throwing an error

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


Re: open(output/mainwindow.h,'w') doesn't create a folder for me

2007-05-02 Thread Michael Hoffman
[EMAIL PROTECTED] wrote:
 Hello
 I have done python for some time now. I'm forgetting things.
 
 This is the faulty line : outfile = open(output/mainwindow.h,'w')
 
 I thought it would have created the folder ouput and the file
 mainwindow.h for me but it's throwing an error

No, you have to create the folder first. Try os.makedirs()
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open(output/mainwindow.h,'w') doesn't create a folder for me

2007-05-02 Thread noagbodjivictor
On May 2, 10:06 am, Michael Hoffman [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  Hello
  I have done python for some time now. I'm forgetting things.

  This is the faulty line : outfile = open(output/mainwindow.h,'w')

  I thought it would have created the folder ouput and the file
  mainwindow.h for me but it's throwing an error

 No, you have to create the folder first. Try os.makedirs()
 --
 Michael Hoffman

Thanks Mike

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


Writing a nice formatted csv file

2007-05-02 Thread redcic
Hi all,

I use the csv module of Python to write a file. My code is of the
form :

cw = csv.writer(open(out.txt, wb))
cw.writerow([1,2,3])
cw.writerow([10,20,30])

And i get an out.txt file looking like:
1,2,3
10,20,30

Whereas what I'd like to get is:
1,2,3,
10,  20,   30

which is more readable.

Can anybody help me to do so ?

Thanks,

Cédric

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


Re: Python un-plugging the Interpreter

2007-05-02 Thread Jorgen Grahn
On Wed, 25 Apr 2007 08:05:01 +0200, Hendrik van Rooyen [EMAIL PROTECTED] 
wrote:
 Jorgen Grahn [EMAIL PROTECTED] wrote:
...
 I doubt it. (But I admit that I am a bit negative towards thread
 programming in general, and I have whined about this before.)
 

 I find this last statement interesting, because it differs so much
 from my own attitude - getting a thread running was one of the
 first things I did when I started getting to grips with python.

 Do you mind whining some more - maybe I can learn 
 something - threads seem to me to make a lot of things so 
 much easier and more natural, as I see them as sequences
 that run at the same time,  and I find this immensely useful
 for all sorts of things, as it enables me to think in a simple
 linear fashion about parts of complicated things.

It's the other way around for me -- using a threaded design looks
superficially more linear, but all the complexity is still there, and
then some. I mean, threads are well known for causing surprising and
hard-to-track-down (and hard to trigger!) bugs and performance
problems.

(I'm comparing with the Unix select() call, and I assume the APIs I
want to use are designed to work with select(). i.e. use select()able
file descriptors.)

 And if you
 add queues, you have something in your hand that you can 
 do quite fancy stuff with in a robust, simple manner...

 *grin* before I discovered the queue module, I was using
 named pipes to communicate between threads...

 So you could say I am a threading freak if you want to, and 
 I won't argue.

 But I would like to hear the opposite viewpoint..

Good. My viewpoint is due to my Unix background (but I'm not
insinuating that all Unix users dislike threads).

Eric Raymond's The Art of Unix Programming sums up the threading
criticism, I think:

http://catb.org/~esr/writings/taoup/html/multiprogramchapter.html

/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org  R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it possible to determine what a function needs for parameters -

2007-05-02 Thread rh0dium
Hi all,

Below is a basic threading program. The basic I idea is that I have a
function which needs to be run using a queue of data.  Early on I
specified my function needed to only accept basic parameters ( no
postional *args or *kwargs ) but now I am re-writing it and I want to
accept these.  Is there anyway to determine what parameters are needed
by a given function and format the arguments given appropriately.  My
problem is that I feel my Kludgesection is just that - a kludge.
While it works for most cases it won't work for all (Try running this
on function4 for example...).  I guess I have a problem with multiple
if statements and I think it should just look to see what parameters
are accepted and format them appropriately. Thoughts?

If I am really screwing this up - please help me get back on the right
track. I appreciate all of the help I get and it's great to learn from
the experts.

import random
import threading
import Queue

class WorkerB(threading.Thread):

def __init__(self, *args, **kwargs):
self.id = kwargs.get('id', 0)
self.requestQ = kwargs.get('requestQ', None)
self.function = kwargs.get('function', None)
threading.Thread.__init__(self, name=self.__class__.__name__
+.+str(self.id))

def run(self):
while 1:
input = self.requestQ.get()
if input is None: break

# How do I look at the function and determine what it
requires then apply that as an input?

#   Start Kludge --
tu=dic=False
if isinstance(input, tuple):
try:
if isinstance(input[0], tuple): tu = True
elif isinstance(input[0], list): tu=True
except: pass
try:
if isinstance(input[1], dict):dic = True
except: pass
if tu and dic:
print   -Tuple and list found
result = self.function(*input[0], **input[1])
elif tu and not dic:
print   -Tuple found
result = self.function(*input[0])
elif isinstance(input, list):
print   -list only found
result = self.function(*input)
else:
print   -Unknown
result = self.function(input)

#   End Kludge --

def function1(arg1):
print arg1

def function2(*a ):
print args, a

def function3(*a, **kw):
print args, a
print kwargs, kw

def function4(arg1, *a, **kw):
print arg1
print args, a
print kwargs, kw

def main():


lod = 2
myQ=Queue.Queue()

# A basic example
print \n== Example 1
for x in range(lod):myQ.put( random.random() )
myQ.put(None)
a=WorkerB(requestQ=myQ, function=function1).start()

# Throw at is some args
print \n== Example 2
for x in range(lod):myQ.put([a,b,c])
myQ.put(None)
a=WorkerB(requestQ=myQ, function=function2).start()

# Throw at it both args and kwargs
print \n== Example 3
for x in range(lod):myQ.put(((1,2,3),
{input:random.random(),loglevel:10}))
myQ.put(None)
a=WorkerB(requestQ=myQ, function=function3).start()

# Throw at it both args and kwargs
print \n== Example 4 Does nothing!!
for x in range(lod):myQ.put((alpha,(1,2,3),
{input:random.random(),loglevel:10}))
myQ.put(None)
a=WorkerB(requestQ=myQ, function=function4).start()


if __name__ == '__main__':
main()

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


Refreshing imported modules

2007-05-02 Thread noagbodjivictor
I have the python interperter opened while editing a module. The
problem is that when I make changes, the module is not refreshed
whenever I import it again. I have to re-launch the interpreter, is
there a way to shortcut this?

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


Re: Writing a nice formatted csv file

2007-05-02 Thread Sebastian Bassi
On 2 May 2007 07:14:04 -0700, redcic [EMAIL PROTECTED] wrote:
 And i get an out.txt file looking like:
 1,2,3
 10,20,30
 Whereas what I'd like to get is:
 1,2,3,
 10,  20,   30
 which is more readable.

The idea behind csv module is to produce and read csv files that are
machine readable rather than human readable, so I think you should
write the file by hand to take into account those whitespace.



-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Club de la razón (www.clubdelarazon.org)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Writing a nice formatted csv file

2007-05-02 Thread 7stud
On May 2, 8:14 am, redcic [EMAIL PROTECTED] wrote:
 Hi all,

 I use the csv module of Python to write a file. My code is of the
 form :

 cw = csv.writer(open(out.txt, wb))
 cw.writerow([1,2,3])
 cw.writerow([10,20,30])

 And i get an out.txt file looking like:
 1,2,3
 10,20,30

 Whereas what I'd like to get is:
 1,2,3,
 10,  20,   30

 which is more readable.

 Can anybody help me to do so ?

 Thanks,

 Cédric

cvs files are constructed for efficient processing not formatting so
that you can read them easier.  If you want a formatted file, then
construct one.

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


Re: Writing a nice formatted csv file

2007-05-02 Thread redcic
Well then how can I format a file ?

Thanks for your help,

Cédric

On 2 mai, 16:26, 7stud [EMAIL PROTECTED] wrote:
 On May 2, 8:14 am, redcic [EMAIL PROTECTED] wrote:



  Hi all,

  I use the csv module of Python to write a file. My code is of the
  form :

  cw = csv.writer(open(out.txt, wb))
  cw.writerow([1,2,3])
  cw.writerow([10,20,30])

  And i get an out.txt file looking like:
  1,2,3
  10,20,30

  Whereas what I'd like to get is:
  1,2,3,
  10,  20,   30

  which is more readable.

  Can anybody help me to do so ?

  Thanks,

  Cédric

 cvs files are constructed for efficient processing not formatting so
 that you can read them easier.  If you want a formatted file, then
 construct one.


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


Re: Writing a nice formatted csv file

2007-05-02 Thread dustin
On Wed, May 02, 2007 at 07:28:32AM -0700, redcic wrote:
 Well then how can I format a file ?

for row in rows:
print .join([ %-6s % (%d, % cell) for cell in row ])

The %-6s formats each column to be no less than six characters long;
the %d, formats the number with a comma after it.

This won't be quite what you want, since you've comma-aligned all of the
fields after the first, but it should be readable.

   Whereas what I'd like to get is:
   1,2,3,
   10,  20,   30
 
   which is more readable.
snip
 
  cvs files are constructed for efficient processing not formatting so
  that you can read them easier.  If you want a formatted file, then
  construct one.
snip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with inspect.getfile

2007-05-02 Thread elventear
On May 2, 1:12 am, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Wed, 02 May 2007 02:53:55 -0300, elventear [EMAIL PROTECTED]  
 escribió:

  Found the offending code. I was importing between files that were at
  the same level of the hierarchy without using absolute references.
  Coded worked fine, but inspect didn't. Was this gaffe on my part? Or
  was inspect supposed to handle it?

 Could you provide an example?

Simple example

My PYTHONPATH points to /python

I have the following:

/python/packages
__init.py__
/containers
__init.py__
module1.py
module2.py

So basically module2 depends on module1. So within module2.py I was I
was doing import module1 instead of import
packages.containers.module1. My code ran ok, but the functions in
the inspect module weren't able to handle it (getfile was the source
of the problem).

Thanks.

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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread Bruno Desthuilliers
rh0dium a écrit :
 Hi all,
 
 Below is a basic threading program. The basic I idea is that I have a
 function which needs to be run using a queue of data.  Early on I
 specified my function needed to only accept basic parameters ( no
 postional *args or *kwargs ) but now I am re-writing it and I want to
 accept these.  Is there anyway to determine what parameters are needed
 by a given function and format the arguments given appropriately. 

Yes - using inspect.getargspec. I don't have example code at hand yet, 
but it's not really complicated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While we're talking about annoyances

2007-05-02 Thread Alex Martelli
Michael Hoffman [EMAIL PROTECTED] wrote:

 Steven D'Aprano wrote:
  On Wed, 02 May 2007 06:10:54 +, Tim Roberts wrote:
 
  I've tended to favor the Schwarzian transform (decorate-sort-undecorate)
  because of that.
  
  That's what the key= argument does. cmp= is slow because the comparison
  function is called for EVERY comparison. The key= function is only called
  once per element.
 
 Right. Using sort(key=keyfunc) is supposed to be faster than 
 decorate-sort-undecorate. And I think it is clearer too.

Right, and speed comparisons are pretty easy (just make sure to copy the
list within the loop to compare like with like:-)...:

brain:~ alex$ python -mtimeit -s'L=range(-3,5)' 'X=L[:]; X.sort(lambda
x, y: cmp(abs(x), abs(y)))'
10 loops, best of 3: 13 usec per loop

brain:~ alex$ python -mtimeit -s'L=range(-3,5)' 'X=[(abs(x),x) for x in
L]; X.sort(); X=[x for _,x in X]'
10 loops, best of 3: 7.85 usec per loop

brain:~ alex$ python -mtimeit -s'L=range(-3,5)' 'X=L[:];
X.sort(key=abs)' 
10 loops, best of 3: 4.23 usec per loop

The intrinsic DSU done by key= is clearly superior on all scores.

The semantics are subtly different: it guarantees to never compare
anything _except_ the key (because that's typically what one wants), so,
make sure they key includes everything you may ever want compared.


Alex


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


Re: Why are functions atomic?

2007-05-02 Thread Alex Martelli
Michael [EMAIL PROTECTED] wrote:

 Is there a reason for using the closure here?  Using function defaults
 seems to give better performance:

What measurements show you that...?

brain:~ alex$ cat powi.py
def powerfactory1(exponent):
   def inner(x):
  return x**exponent
   return inner

def powerfactory2(exponent):
   def inner(x, exponent=exponent):
  return x**exponent
   return inner

brain:~ alex$ python -mtimeit -s'import powi; p=powi.powerfactory1(3)'
'p(27)'
100 loops, best of 3: 0.485 usec per loop

brain:~ alex$ python -mtimeit -s'import powi; p=powi.powerfactory2(3)'
'p(27)'
100 loops, best of 3: 0.482 usec per loop


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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread Chris Mellon
On 2 May 2007 07:22:07 -0700, rh0dium [EMAIL PROTECTED] wrote:
 Hi all,

 Below is a basic threading program. The basic I idea is that I have a
 function which needs to be run using a queue of data.  Early on I
 specified my function needed to only accept basic parameters ( no
 postional *args or *kwargs ) but now I am re-writing it and I want to
 accept these.  Is there anyway to determine what parameters are needed
 by a given function and format the arguments given appropriately.  My
 problem is that I feel my Kludgesection is just that - a kludge.
 While it works for most cases it won't work for all (Try running this
 on function4 for example...).  I guess I have a problem with multiple
 if statements and I think it should just look to see what parameters
 are accepted and format them appropriately. Thoughts?

 If I am really screwing this up - please help me get back on the right
 track. I appreciate all of the help I get and it's great to learn from
 the experts.

 import random
 import threading
 import Queue

 class WorkerB(threading.Thread):

 def __init__(self, *args, **kwargs):
 self.id = kwargs.get('id', 0)
 self.requestQ = kwargs.get('requestQ', None)
 self.function = kwargs.get('function', None)
 threading.Thread.__init__(self, name=self.__class__.__name__
 +.+str(self.id))

 def run(self):
 while 1:
 input = self.requestQ.get()
 if input is None: break

 # How do I look at the function and determine what it
 requires then apply that as an input?

 #   Start Kludge --
 tu=dic=False
 if isinstance(input, tuple):
 try:
 if isinstance(input[0], tuple): tu = True
 elif isinstance(input[0], list): tu=True
 except: pass
 try:
 if isinstance(input[1], dict):dic = True
 except: pass
 if tu and dic:
 print   -Tuple and list found
 result = self.function(*input[0], **input[1])
 elif tu and not dic:
 print   -Tuple found
 result = self.function(*input[0])
 elif isinstance(input, list):
 print   -list only found
 result = self.function(*input)
 else:
 print   -Unknown
 result = self.function(input)

 #   End Kludge --

 def function1(arg1):
 print arg1

 def function2(*a ):
 print args, a

 def function3(*a, **kw):
 print args, a
 print kwargs, kw

 def function4(arg1, *a, **kw):
 print arg1
 print args, a
 print kwargs, kw

 def main():


 lod = 2
 myQ=Queue.Queue()

 # A basic example
 print \n== Example 1
 for x in range(lod):myQ.put( random.random() )
 myQ.put(None)
 a=WorkerB(requestQ=myQ, function=function1).start()

 # Throw at is some args
 print \n== Example 2
 for x in range(lod):myQ.put([a,b,c])
 myQ.put(None)
 a=WorkerB(requestQ=myQ, function=function2).start()

 # Throw at it both args and kwargs
 print \n== Example 3
 for x in range(lod):myQ.put(((1,2,3),
 {input:random.random(),loglevel:10}))
 myQ.put(None)
 a=WorkerB(requestQ=myQ, function=function3).start()

 # Throw at it both args and kwargs
 print \n== Example 4 Does nothing!!
 for x in range(lod):myQ.put((alpha,(1,2,3),
 {input:random.random(),loglevel:10}))
 myQ.put(None)
 a=WorkerB(requestQ=myQ, function=function4).start()


 if __name__ == '__main__':
 main()



This is far more work than you need. Push an (args, kwargs) tuple into
your arguments queue and call self.function(*args, **kwargs).
-- 
http://mail.python.org/mailman/listinfo/python-list


I need help speeding up an app that reads football scores and generates rankings

2007-05-02 Thread jocknerd
About 10 years ago, I wrote a C app that would read scores from
football games and calculate rankings based on the outcome of the
games.  In fact, I still use this app.  You can view my rankings at
http://members.cox.net/jocknerd/football.

A couple of years ago, I got interested in Python and decided to
rewrite my app in Python.  I got it to work but its painfully slow
compared to the C app.  I have a file containing scores of over 1500
high school football games for last season.  With my Python app, it
takes about 3 minutes to process the rankings.  With my C app, it
processes the rankings in less than 15 seconds.

The biggest difference in my two apps is the C app uses linked lists.
I feel my Python app is doing too many lookups  which is causing the
bottleneck.

I'd love some feedback regarding how I can improve the app.  I'd like
to drop the C app eventually.  Its really ugly.  My goal is to
eventually get the data stored in PostgreSQL and then have a Django
powered site to process and display my rankings.

You can download the source code from 
http://members.cox.net/jocknerd/downloads/fbratings.py
and the data file from http://members.cox.net/jocknerd/downloads/vhsf2006.txt

Thanks!

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


Re: Python un-plugging the Interpreter

2007-05-02 Thread Jorgen Grahn
On Tue, 24 Apr 2007 07:49:46 -0700, Alex Martelli [EMAIL PROTECTED] wrote:
 Jorgen Grahn [EMAIL PROTECTED] wrote:
...
  Perhaps the current wave of dual-core and quad-core CPUs in cheap
  consumer products would change people's perceptions -- I wonder...
 
 Maybe it would change /perceptions/, but would normal users suddenly
 start running things that are (a) performance-critical, (b) written in
 Python and (c) use algorithms that are possible to parallellize?

 That depends on what normal means.

I used your phrase cheap consumer products to the max -- defining
normal users as people who wouldn't have used an SMP machine two
years ago, and don't actively choose dual core today (or choose it
because they like HP's tandem bike ads).

 For the common definition (users
 that don't _write_ programs), it would depend on what ``developers''
 release to the world.

 I doubt it. (But I admit that I am a bit negative towards thread
 programming in general, and I have whined about this before.)

 I'm no big fan of threading either, believe me.  But with multi-core
 CPUs onrushing, exploiting them requires either that or multiple
 processes [...]

Yes. But that's where the current concurrent programming craze seems
so odd to me. It's as if the reasoning goes:

  New machines are multi-core; thus we have to find first a reason,
  then a way to exploit them, on the process level.

Personally, I'm rarely CPU bound in my work, so I have a hard time
finding that reason. I doubt even Windows users are CPU bound, except
when a program hangs at 100% CPU.

When I get a multi-core CPU eventually, those other CPUs will mostly
do kernel-space tasks, offload things like rendering windows and doing
ssh encryption/compression, and let me type make -j2 to compile my C
source code faster. No threading is needed for those things. (And even
if it was, I doubt anyone would rewrite either the Linux kernel, X11,
ssh or make in Python ;-)

BR,
/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org  R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a nice formatted csv file

2007-05-02 Thread Jon Clements
On 2 May, 15:14, redcic [EMAIL PROTECTED] wrote:
 Hi all,

 I use the csv module of Python to write a file. My code is of the
 form :

 cw = csv.writer(open(out.txt, wb))
 cw.writerow([1,2,3])
 cw.writerow([10,20,30])

 And i get an out.txt file looking like:
 1,2,3
 10,20,30

 Whereas what I'd like to get is:
 1,2,3,
 10,  20,   30

 which is more readable.

 Can anybody help me to do so ?

How about pre-formatting the columns before hand before using
something like:

# List of formatting to apply to each column (change this to suit)
format = ['%03d', '%10s', '%10s']

data = [1, 10, 100]
print [fmt % d for fmt,d in zip(format,data)]

Results in: ['001', '10', '   100']

Then write that using the CSV module.

hth

Jon.





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


Re: Writing a nice formatted csv file

2007-05-02 Thread Dave Borne
 Whereas what I'd like to get is:
 1,2,3,
 10,  20,   30

(without trying this myself first...)
You might  try setting up a csv dialect with a delimiter of ',\t' then
using a reader that can set tab stops for display.

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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread rh0dium
 This is far more work than you need. Push an (args, kwargs) tuple into
 your arguments queue and call self.function(*args, **kwargs).

No see I tried that and that won't work.

I'm assuming what you are referring to is this (effectively)

Q.put(((),{a:foo, b:bar}))

input = Q.get()
self.function( *input[0], **input[1])

This will obviously fail if several conditions aren't met - hence the
kludge.  Am I missing something here?





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


Re: What do people use for code analysis.

2007-05-02 Thread Mike Brenner
On the one hand, I would like better graphical code
analysis tools. On the other hand, I would
like to mention a different kind of code analysis.

A Return on Investment (ROI) philosophy would
analyze the code by how much it costs to change the code.

To do this, you can add up all the costs.

The main cost pays for analyzing the dataflows
to determine the impact of the change.

The secondary costs pays for the backlogs,
the things that you put off paying for in the past:

- the number of branches in the code not covered by automatic tests,
- the number of API parameters without tested examples,
- the dataflows without documented preconditions and postconditions,
- the hours of developer overtime not being paid,
- the cost of opening up the configuration management to a change,
- the number of platform-dependent features,
- the number of reviewer comments not kept, etc.

Notice that such things as code size, inheritance,
multiple tasks, calls, etc., don't add cost!

Code costs almost nothing compared to the true value,
the data and the dataflows.

Mike Brenner



Steven wrote:
  Lots of code, calls to, calls by, inheritance, multiple tasks, etc.
  What do people use to figure out what's happening?

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


Re: regexp match string with word1 and not word2

2007-05-02 Thread Ant
On May 2, 9:17 am, Flyzone [EMAIL PROTECTED] wrote:
 On 30 Apr, 20:00, Steven Bethard [EMAIL PROTECTED] wrote:
...
 Maybe a right approach will be another if after the first one? Like:
for y in range(0, len(skip_lst) ):
  if (re.search(skip_lst[y], line)):
  if
 (re.search(skip_lst_negative[y], line)):
skip=1
break
 and in the rule-file, i could add a new column and check to do the if
 just if the second column is not empty.

This is quite a common approach for this sort of matching problem -
having includes and excludes patterns, and having the test return True
if the include matches but not the exclude. Trying to roll the two
into one requires pretty unreadable regexes if it is possible at all...

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


Re: I need help speeding up an app that reads football scores and generates rankings

2007-05-02 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], jocknerd wrote:

 The biggest difference in my two apps is the C app uses linked lists.
 I feel my Python app is doing too many lookups  which is causing the
 bottleneck.

Then replace those linear searches you wrote in Python with a dictionary.

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


Active Directory: how to delete a user from a group?

2007-05-02 Thread Dirk Hagemann
Hi!

Does anyone has experience with manipulating MS Active Directory
objects? I'd like to delete some users from a group, but so far I
couldn't find anything about this.
There is some good stuff about retrieving data out of the AD (thanks
to Tim Golden!), but how can I manipulate or change AD objects like
users, computers and groups with Python? Is there somewhere a
documentation or some code?

Dirk

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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread Gary Herron
rh0dium wrote:
 This is far more work than you need. Push an (args, kwargs) tuple into
 your arguments queue and call self.function(*args, **kwargs).
 

 No see I tried that and that won't work.
   
Won't work?  How does it fail?
 I'm assuming what you are referring to is this (effectively)

 Q.put(((),{a:foo, b:bar}))

 input = Q.get()
 self.function( *input[0], **input[1])

 This will obviously fail if several conditions aren't met - hence the
 kludge.  Am I missing something here?

   
Obviously?  Conditions?  What conditions? 

We do things like this constantly, and in fact, it *does* work.

Please tell us how it fails, or what is unsatisfactory about it. 

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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread Chris Mellon
On 2 May 2007 08:13:12 -0700, rh0dium [EMAIL PROTECTED] wrote:
  This is far more work than you need. Push an (args, kwargs) tuple into
  your arguments queue and call self.function(*args, **kwargs).

 No see I tried that and that won't work.

 I'm assuming what you are referring to is this (effectively)

 Q.put(((),{a:foo, b:bar}))

 input = Q.get()
 self.function( *input[0], **input[1])

 This will obviously fail if several conditions aren't met - hence the
 kludge.  Am I missing something here?


Assuming that the caller correctly pushes arguments, how can this fail?
-- 
http://mail.python.org/mailman/listinfo/python-list


ignorance and intolerance in computing communties

2007-05-02 Thread Xah Lee
Today, a motherfucker Christophe Rhodes (aka Xof in irc://chat.freenode.net/lisp
) kicked banned me.
Here's the few relevant excerpt. (full, unedited excerpt will be
published if there is a public interest)

Begin excerpt:

[5:31am] xahlee k, here is a simple problem but rather tedious to do
it correctly.
...
[5:32am] xahlee given a unit vector A={a1,a2}, write a function
AngleA, such that it returns the positive angle from {1,0} to A.
[5:33am] xahlee mathematically this is simple, but to implement it
is rather cumbersome, with many if statements.
[5:34am] xahlee also, anyone who has implemented this will know trig
well.
[5:34am] xahlee i wonder if there's already in some library in lisp.
(i doubt it)
[5:36am] pjb xahlee: (acos (scalar-product A #(1 0)))

...

[6:34am] xahlee can anyone show me the source code of a function
that convert a complex number (a1 b2) to it's polar representation?
[6:35am] Xof (defun polarize (complex) (values (abs complex) (phase
complex)))
[6:35am] Xof wait, why am I replying to the troll?
[6:36am] fax :/
[6:36am] Jasko even the mighty Xof is not immune!
[6:36am] tritchey Xach: you were right, he HAS turned into mary
poppins.
[6:36am] xahlee well... what is the source code for your “phase”?
[6:36am] Xach xahlee: it is, as kmp once said, given from god
[6:36am] Xof clhs phase
[6:36am] specbot http://www.lispworks.com/reference/HyperSpec/Body/f_phase.htm
[6:36am] LiamH joined the chat room.
[6:36am] fax xahlee: you know enough maths to write an
impllementation
[6:36am] froydnj piso: ah...hmmm
[6:37am] fax xahlee: if its a CLHS function, then how its actually
written will be implementation specific
[6:37am] fax er CL not CLHS
[6:37am] xahlee as i described, i'm interested in the algorithm of
the implementation, not what it means.
[6:37am] xahlee «can anyone show me the source code of a function
that convert a complex number (a1 b2) to it's polar representation?»
[6:37am] Xof all of that is true, but there's quite a good
suggestion for how to implement it on the page I got from specbot
[6:37am] fax xahlee: afaik there is no way to calculate it without
conditionals
[6:38am] Xof xahlee: and that's what you got
[6:38am] fax you can do 4 dot products, or atan.. however you do it
you have to handle cases
[6:38am] xahlee fax: thanks fax! only you come thru understand the
question and not being a troll.
[6:38am] Xof (atan y x)
[6:38am] xahlee the others so far, e.g. xof and pjb in particular,
just wanted to troll.
[6:38am] Xof look, ma, no conditionals
[6:38am] fax xahlee: more than just me gave you some info..
[6:39am] Xof was promoted to operator by ChanServ.
[6:39am] Xof set a ban on *!
[EMAIL PROTECTED]
[6:39am] You were kicked from the chat room by Xof. (now go away,
please)


--

Christophe Rhodes has unjustly kicked banned me about 3 times in the
past year in #lisp. Basically, making it impossible for me to use the
service provided by freenode.net in way. Today's incident, is actually
the most lenient. In the past ~3 times, he simply kick banned me
within few minutes i joined the #lisp channel.

Christophe Rhodes is one example of a power-struggling tech geeker in
the computing industry. Incidents like this, happens frequently in
just about all computer forums where almost all members are
exclusively male.

I want to bring this to the public attention (in this case, in the
lisp community). Because, it is motherfuckers like these, that does
society harm, and they all pretent to be saints and justice holders.

---

Some notes about the math problem discussed in the topic:

As i have indicated in my post, it is non-trivial to implement a
function that returns the positive angle of a vector. For example, it
can be done with sign checking of the coordinate components (in total
4 cases, which can be done as 2 levels of nesting if, or simply 4
if.), and or the evaluation of Min[Abs[ArcCos[x],Abs[ArcSin[x]]], or
use clever ways with dot product, or ArcTan. It is not a trivial to
know which algorithm is in general more efficient. (this is important,
since finding the angle of a vector is a basic function, that may
needs to be called millions times directly or indirectly) Further,
consider the inverse trig function, it is likely 99.99% of people with
a PH D in math wouldn't know how these are actually implemented. So,
the question of whether calling one of the inverse trig function is
more robust or efficient than another is a open question. And, besides
the algorithmic level, the question also entails how the language
actually implement the inverse trig functions.

Besides efficiency concerns, there's also robustness concerns. For
example, if the 2 vectors are {1,0} and {0,1}, a simplistic
implementation will result in division by 0 or similar errors.
Checking whether one of them lies on the x or y axis means more if
statements, as well the non-trivial problem of determining if two
numbers are equal. (e.g. is 0.01 considered equal to 0.0001 )

My 

Re: Active Directory: how to delete a user from a group?

2007-05-02 Thread Tim Golden
Dirk Hagemann wrote:
 Hi!
 
 Does anyone has experience with manipulating MS Active Directory
 objects? I'd like to delete some users from a group, but so far I
 couldn't find anything about this.
 There is some good stuff about retrieving data out of the AD (thanks
 to Tim Golden!), but how can I manipulate or change AD objects like
 users, computers and groups with Python? Is there somewhere a
 documentation or some code?

I freely admit I don't do too much changing of AD objects,
but my module should at least support the methods for doing
things. Some examples in Active Directory Cookbook:

   http://techtasks.com/code/viewbook/2

To delete a user, apparently:

code
import active_directory
user = active_directory.find_user (name-of-user)
# or user = active_directory.AD_object (user-moniker)
user.DeleteObject (0)
/code

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


Re: Any way to refactor this?

2007-05-02 Thread John Salerno
Bruno Desthuilliers wrote:

  From a purely efficiency POV, there are some obviously possible 
 improvements. The first one is to alias visual.cylinder, so you save on 
 lookup time. The other one is to avoid useless recomputation of 
 -hatch_length and hatch_length*2.
 
 def _create_3D_xhatches():
 cy = visual.cylinder
 for x in xrange(-axis_length, axis_length + 1):
 if x == 0: continue
 b = -hatch_length
 c = hatch_length*2
 cy(pos=(x, b, 0), axis=(0, c, 0), radius=hatch_radius)
 cy(pos=(x, 0, b), axis=(0, 0, c), radius=hatch_radius)
 cy(pos=(b, x, 0), axis=(c, 0, 0), radius=hatch_radius)
 cy(pos=(0, x, b), axis=(0, 0, c), radius=hatch_radius)
 cy(pos=(b, 0, x), axis=(c, 0, 0), radius=hatch_radius)
 cy(pos=(0, b, x), axis=(0, c, 0), radius=hatch_radius)

Doesn't this call to cy still call the function multiple times?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Active Directory: how to delete a user from a group?

2007-05-02 Thread Tim Golden
Tim Golden wrote:
 Dirk Hagemann wrote:
 Hi!

 Does anyone has experience with manipulating MS Active Directory
 objects? I'd like to delete some users from a group, but so far I
 couldn't find anything about this.
 There is some good stuff about retrieving data out of the AD (thanks
 to Tim Golden!), but how can I manipulate or change AD objects like
 users, computers and groups with Python? Is there somewhere a
 documentation or some code?
 
 I freely admit I don't do too much changing of AD objects,
 but my module should at least support the methods for doing
 things. Some examples in Active Directory Cookbook:
 
http://techtasks.com/code/viewbook/2

Sorry, you wanted to remove a user *from a group*. Misread.

Translated from http://techtasks.com/code/viewbookcode/1626

code
import active_directory
group = active_directory.find_group (name-of-group)
# or group = active_directory.AD_object (group-moniker)

user = active_directory.find_user (name-of-user)
# or user = active_directory.AD_object (user-moniker)

group.Remove (user.path ())

/code

Obviously, for something this simple using an extra module
is overkill. You might as well:

code
import win32com.client

group = win32com.client.GetObject (group-moniker)
group.Remove (user-moniker)

/code

NB I haven't tried these, I've just translated them
from the Cookbook site!

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


ascii to unicode line endings

2007-05-02 Thread fidtz
The code:

import codecs

udlASCII = file(c:\\temp\\CSVDB.udl,'r')
udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16)

udlUNI.write(udlASCII.read())

udlUNI.close()
udlASCII.close()

This doesn't seem to generate the correct line endings. Instead of
converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as  0x0D/
0x0A

I have tried various 2 byte unicode encoding but it doesn't seem to
make a difference. I have also tried modifying the code to read and
convert a line at a time, but that didn't make any difference either.

I have tried to understand the unicode docs but nothing seems to
indicate why an seemingly incorrect conversion is being done.
Obviously I am missing something blindingly obvious here, any help
much appreciated.

Dom

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


Re: ascii to unicode line endings

2007-05-02 Thread Jean-Paul Calderone
On 2 May 2007 09:19:25 -0700, [EMAIL PROTECTED] wrote:
The code:

import codecs

udlASCII = file(c:\\temp\\CSVDB.udl,'r')
udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16)

udlUNI.write(udlASCII.read())

udlUNI.close()
udlASCII.close()

This doesn't seem to generate the correct line endings. Instead of
converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as  0x0D/
0x0A

I have tried various 2 byte unicode encoding but it doesn't seem to
make a difference. I have also tried modifying the code to read and
convert a line at a time, but that didn't make any difference either.

I have tried to understand the unicode docs but nothing seems to
indicate why an seemingly incorrect conversion is being done.
Obviously I am missing something blindingly obvious here, any help
much appreciated.

Consider this simple example:

   import codecs
   f = codecs.open('test-newlines-file', 'w', 'utf16')
   f.write('\r\n')
   f.close()
   f = file('test-newlines-file')
   f.read()
  '\xff\xfe\r\x00\n\x00'
  

And how it differs from your example.  Are you sure you're examining
the resulting output properly?

By the way, \r\0\n\0 isn't a unicode line ending, it's just the UTF-16
encoding of \r\n.

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


Re: DiffLib Question

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 06:26:13 -0300, whitewave [EMAIL PROTECTED] escribió:

 Thank you for your reply. But I don't fully understand what the
 charjunk and linejunk is all about. I'm a bit newbie in python using
 the DiffLib. I'm I using the right code here? I will I implement the
 linejunk and charjunk using the following code?

Usually, Differ receives two sequences of lines, being each line a  
sequence of characters (strings). It uses a SequenceMatcher to compare  
lines; the linejunk argument is used to ignore certain lines. For each  
pair of similar lines, it uses another SequenceMatcher to compare  
characters inside lines; the charjunk is used to ignore characters.
As you are feeding Differ with a single string (not a list of text lines),  
the lines it sees are just characters. To ignore whitespace and  
newlines, in this case one should use the linejunk argument:

def ignore_ws_nl(c):
   return c in  \t\n\r

a = difflib.Differ(linejunk=ignore_ws_nl).compare(d1,d2)
dif = list(a)
print ''.join(dif)

   I  n a  d  d  i  t  i  o  n  , t  h  e c  o  n  s  i  d  e   
r  e
d p  r  o  b  l  e  m d  o  e  s n  o  t h  a  v  e  
a m
  e  a  n  i  n  g  f  u  l t  r  a  d  i  t  i  o  n  a  l t  y   
p  e
   o  f-  +
   a  d  j  o  i  n  t-
+p  r  o  b  l  e  m e  v  e  n f  o  r t  h  e s  i   
m  p
l  e f  o  r  m  s o  f t  h  e d  i  f  f  e  r  e  n  t   
i  a
  l e  q  u  a  t  i  o  n a  n  d t  h  e n  o  n  l  o   
c  a  l
  c  o  n  d  i  t  i  o  n  s  . D  u  e-  +
   t  o t  h  e  s  e f  a  c  t  s  , s  o  m  e s  e  r   
i  o
u  s d  i  f  f  i  c  u  l  t  i  e  s a  r  i  s  e i  n  
t  h
  e a  p  p  l  i  c  a  t  i  o  n o  f t  h  e c  l  a   
s  s  i
   c  a  l m  e  t  h  o  d  s t  o s  u  c  h a-  +
   p  r  o  b  l  e  m  .+

I hope this is what you were looking for.

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


Re: I need help speeding up an app that reads football scores andgenerates rankings

2007-05-02 Thread Terry Reedy

jocknerd [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| About 10 years ago, I wrote a C app that would read scores from
| football games and calculate rankings based on the outcome of the
| games.  In fact, I still use this app.  You can view my rankings at
| http://members.cox.net/jocknerd/football.
|
| A couple of years ago, I got interested in Python and decided to
| rewrite my app in Python.  I got it to work but its painfully slow
| compared to the C app.  I have a file containing scores of over 1500
| high school football games for last season.  With my Python app, it
| takes about 3 minutes to process the rankings.  With my C app, it
| processes the rankings in less than 15 seconds.

A ratio of 12 to 1 is not bad.  However

| The biggest difference in my two apps is the C app uses linked lists.
| I feel my Python app is doing too many lookups  which is causing the
| bottleneck.

You have to do as many lookups as you have to do, but looking up teams by 
name in a linear scan of a list is about the slowest way possible.  Replace 
'teamlist' with a dict 'teams' keyed by team name.  Replace 
'lookupTeam(team)' by 'if team not in teams: addTeam(team)' and delete the 
lookupTeam function.  Similarly 'lookupTeamRate(team)' becomes 
'teams[team]['grate'] (and delete function).  And 
'updateTeamRate(team,rate)' becomes teams[team]['rate'] = rate' (and delete 
function.  And similarly for updateTeamRating and anything else using 
teamlist.  In many places, multiple lookups in teams could be eliminated. 
For instance, 'team1 = teams[g['team1']].  Then use 'team1' to manipulate 
its rating and other attributes.

| You can download the source code from 
http://members.cox.net/jocknerd/downloads/fbratings.py
| and the data file from 
http://members.cox.net/jocknerd/downloads/vhsf2006.txt

Minor point.  Multiple functions do 'localvar = expression; return 
localvar'.   The simpler 'return expression' will be slightly faster. 
Your comments and function name eliminate any documentary need for the 
otherwise useless local var.

Function calls are relatively slow in Python.  So calling
def totalPtsGame (score1, score2): return score1 + score2
is slower than simply adding the scores 'in place'.

Terry Jan Reedy


You can also, people say, use the profiler to find where time is going. 



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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread rh0dium
On May 2, 7:49 am, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:

 Yes - using inspect.getargspec. I don't have example code at hand yet,
 but it's not really complicated.

Viola!! Hey this works!!  Now I have modified my code to do this - way
cool (still kind of a mess though)

args, varargs, varkw, defs =
inspect.getargspec(self.function)
# Deal with just some args
if varargs is None and varkw is None:
result=self.function(input)
# Deal with *args
if varkw is None and varargs is not None and len(args) 
0:
result=self.function(input[0:-1], *input[-1])
if varkw is None and varargs is not None and len(args)==0:
result=self.function(*input[0])
# Deal with *kwargs
if varkw is not None and varargs is not None and len(args)
 0:
result=self.function(input[0:-2], *input[-2],
**input[-1])
if varkw is not None and varargs is not None and
len(args)==0:
result=self.function(*input[-2], **input[-1])
if varkw is not None and varargs is None and len(args) 
0:
result=self.function(input[0:-1], **input[-1])
if varkw is not None and varargs is None and len(args) ==
0:
result=self.function(**input[0])

Now this worked until I threw a function which looked like this

def func5( input1, input2, input3 )
pass

So it barfed because of this..

if varargs is None and varkw is None:
   result=self.function(input)

but all of the parameters were lumped as a list so input1 contained
them all...
A small tweak turned into this..
if varargs is None and varkw is None:
if isinstance(input, tuple):
result=self.function(*input)
else:
result=self.function(input)

But now I suppose I need to do this for all of them but that will
break my other logic...

Yuck - I have to be missing something here.


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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread rh0dium
On May 2, 8:25 am, Gary Herron [EMAIL PROTECTED] wrote:
 rh0dium wrote:
  This is far more work than you need. Push an (args, kwargs) tuple into
  your arguments queue and call self.function(*args, **kwargs).

  No see I tried that and that won't work.

 Won't work?  How does it fail? I'm assuming what you are referring to is 
 this (effectively)

  Q.put(((),{a:foo, b:bar}))

  input = Q.get()
  self.function( *input[0], **input[1])

  This will obviously fail if several conditions aren't met - hence the
  kludge.  Am I missing something here?

 Obviously?  Conditions?  What conditions?

 We do things like this constantly, and in fact, it *does* work.

 Please tell us how it fails, or what is unsatisfactory about it.

 Gary Herron

Good - It looks like I am the one who is clueless..

If I do this:

def funcA(input):
   pass

Then I run the code
for x in range(lod):myQ.put(random.random())
myQ.put(None)
a=WorkerB(requestQ=myQ, function=funcA).start()

This will fail because there isn't an input[1]

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


Re: Need Help in Preparing for Study of Python by Forrester Research

2007-05-02 Thread Jim
What does it pay?

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


Re: I need help speeding up an app that reads football scores and generates rankings

2007-05-02 Thread Arnaud Delobelle
On May 2, 4:00 pm, jocknerd [EMAIL PROTECTED] wrote:
 About 10 years ago, I wrote a C app that would read scores from
 football games and calculate rankings based on the outcome of the
 games.  In fact, I still use this app.  You can view my rankings 
 athttp://members.cox.net/jocknerd/football.

 A couple of years ago, I got interested in Python and decided to
 rewrite my app in Python.  I got it to work but its painfully slow
 compared to the C app.  I have a file containing scores of over 1500
 high school football games for last season.  With my Python app, it
 takes about 3 minutes to process the rankings.  With my C app, it
 processes the rankings in less than 15 seconds.

 The biggest difference in my two apps is the C app uses linked lists.
 I feel my Python app is doing too many lookups  which is causing the
 bottleneck.

 I'd love some feedback regarding how I can improve the app.  I'd like
 to drop the C app eventually.  Its really ugly.  My goal is to
 eventually get the data stored in PostgreSQL and then have a Django
 powered site to process and display my rankings.

 You can download the source code 
 fromhttp://members.cox.net/jocknerd/downloads/fbratings.py
 and the data file fromhttp://members.cox.net/jocknerd/downloads/vhsf2006.txt

 Thanks!

A simple improvement is to change your list of teams('teamlist') to a
dictionary of teams (call it say 'teamdict') mapping team names to
teams.

You have lots of
#Some code
for row in teamlist:
if teamname == row['name']:
#Do something with row

These can all be replaced with:
   #Some code
   row = teamdict[teamname]
   #Do something with row

(Although I wouldn't call it 'row' but rather 'team')

That may speed up your code significantly.

Moreover you can make the main loop (in calcTeamRatings) faster by
avoiding looking up a team each time you need some info on it.

Finally I would change your schedule list to a list of tuples rather
than a list of dictionaries: each game in the schedule would be a
tuple (team1, team2, ratio) and wouldn't include the actual team
scores as you don't seem to use them in your calcTeamRatings function
(that means moving the ratio calculation into the loop that creates
the schedule)

Disclaimer: I only looked at your code superficially and I don't claim
to understand it !

HTH

--
Arnaud

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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread Chris Mellon
On 2 May 2007 09:41:56 -0700, rh0dium [EMAIL PROTECTED] wrote:
 On May 2, 8:25 am, Gary Herron [EMAIL PROTECTED] wrote:
  rh0dium wrote:
   This is far more work than you need. Push an (args, kwargs) tuple into
   your arguments queue and call self.function(*args, **kwargs).
 
   No see I tried that and that won't work.
 
  Won't work?  How does it fail? I'm assuming what you are referring to is 
  this (effectively)
 
   Q.put(((),{a:foo, b:bar}))
 
   input = Q.get()
   self.function( *input[0], **input[1])
 
   This will obviously fail if several conditions aren't met - hence the
   kludge.  Am I missing something here?
 
  Obviously?  Conditions?  What conditions?
 
  We do things like this constantly, and in fact, it *does* work.
 
  Please tell us how it fails, or what is unsatisfactory about it.
 
  Gary Herron

 Good - It looks like I am the one who is clueless..

 If I do this:

 def funcA(input):
pass

 Then I run the code
 for x in range(lod):myQ.put(random.random())
 myQ.put(None)
 a=WorkerB(requestQ=myQ, function=funcA).start()

 This will fail because there isn't an input[1]



Thats because you put the wrong value into the arguments queue.
For this use case, we define the arguments queue as being a source of 2-tuples,
with an argument list and a kwargs dict. So you have to do:

for x in range(lod):
myQ.put((random.random(), {}))

(don't be afraid of indentation and newlines - I started to modify
your source to provide a working example and got frustrated
reformatting it so I could read it)

Since you've now defined the external interface for your system (pass
it a queue of argument, kwargs tuples and a callable) it's the
responsibility of the caller to correctly satisfy that interface.
-- 
http://mail.python.org/mailman/listinfo/python-list


Time functions

2007-05-02 Thread HMS Surprise

I wish to generate a datetime string that has the following format.
'05/02/2007 12:46'. The leading zeros are required.

I found '14.2 time' in the library reference and have pulled in
localtime. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

Thanks,

jvh (whose newbieism is most glaring)

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


Re: Is it possible to determine what a function needs for parameters -

2007-05-02 Thread Steven D'Aprano
On Wed, 02 May 2007 07:22:07 -0700, rh0dium wrote:

 Hi all,
 
 Below is a basic threading program. The basic I idea is that I have a
 function which needs to be run using a queue of data.  Early on I
 specified my function needed to only accept basic parameters ( no
 postional *args or *kwargs ) but now I am re-writing it and I want to
 accept these.  Is there anyway to determine what parameters are needed
 by a given function and format the arguments given appropriately.

Is this meant to be just a programming exercise to see how clever you can
be? It's okay if it is, but if it is meant to be something useful,
well, I can't imagine ever being in a situation where I know I have
to pass arguments (say) 4, 5, Hello, and None to a function, but not
know whether they should be positional arguments or keyword arguments.

Or, to put it another way... the usual procedure is for the developer
(that's you) to read the function API to find out what arguments the
function expects, and how it expects them, and then the developer
modifies the parameters used accordingly.



-- 
Steven.

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


Re: Time functions

2007-05-02 Thread HMS Surprise
On May 2, 12:00 pm, HMS Surprise [EMAIL PROTECTED] wrote:
 I wish to generate a datetime string that has the following format.
 '05/02/2007 12:46'. The leading zeros are required.

 I found '14.2 time' in the library reference and have pulled in
 localtime. Are there any formatting functions available or do I need
 to make my own? Perhaps there is something similar to C's printf
 formatting.

 Thanks,

 jvh (whose newbieism is most glaring)

Oops, it appears I overlooked strftime.

Regrets,

jvh

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


Re: Time functions

2007-05-02 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], HMS Surprise
wrote:

 I wish to generate a datetime string that has the following format.
 '05/02/2007 12:46'. The leading zeros are required.
 
 I found '14.2 time' in the library reference and have pulled in
 localtime. Are there any formatting functions available or do I need
 to make my own? Perhaps there is something similar to C's printf
 formatting.

You mean like `time.strftime()`!?  :-)

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


Re: I need help speeding up an app that reads football scores and generates rankings

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 12:16:56 -0300, Marc 'BlackJack' Rintsch  
[EMAIL PROTECTED] escribió:

 In [EMAIL PROTECTED], jocknerd  
 wrote:

 The biggest difference in my two apps is the C app uses linked lists.
 I feel my Python app is doing too many lookups  which is causing the
 bottleneck.

 Then replace those linear searches you wrote in Python with a dictionary.

As an example: using a Team object instead of a dictionary, and using  
teamlist (not a good name now) as a dictionary of Team objects indexed by  
name:

def lookupTeam (teamname):
team = teamlist.get(teamname)
if team is None:
teamlist[teamname] = team = Team(teamname)
return team

def updateTeamStats (tname1, score1, tname2, score2):
team1 = lookupTeam (tname1)
team2 = lookupTeam (tname2)

team1.pf += score1
team1.pa += score2
if (score1  score2):
team1.won += 1
elif (score1  score2):
team1.lost += 1
else:
team1.tied += 1

team2.pf += score2
team2.pa += score1
if (score1  score2):
team2.won += 1
elif (score1  score2):
team2.lost += 1
else:
team2.tied += 1

Then you should realize that those last two blocks are too similar, and  
you can make a function of it. And then you realize that in fact they act  
on a Team object, so you should make a Team method...

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


Re: Leaving Python List

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 08:27:43 -0300, Gurpreet Singh  
[EMAIL PROTECTED] escribió:

 This mail is to confirm that i want to leave the
 python list.

Goodbye!

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


Re: ScrolledText?

2007-05-02 Thread nik
Great thank you for the help, we got it working.

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


Re: Any way to refactor this?

2007-05-02 Thread Steven D'Aprano
On Wed, 02 May 2007 11:37:14 -0400, John Salerno wrote:

 Bruno Desthuilliers wrote:
 
  From a purely efficiency POV, there are some obviously possible 
 improvements. The first one is to alias visual.cylinder, so you save on 
 lookup time. The other one is to avoid useless recomputation of 
 -hatch_length and hatch_length*2.
 
 def _create_3D_xhatches():
 cy = visual.cylinder
 for x in xrange(-axis_length, axis_length + 1):
 if x == 0: continue
 b = -hatch_length
 c = hatch_length*2
 cy(pos=(x, b, 0), axis=(0, c, 0), radius=hatch_radius)
 cy(pos=(x, 0, b), axis=(0, 0, c), radius=hatch_radius)
 cy(pos=(b, x, 0), axis=(c, 0, 0), radius=hatch_radius)
 cy(pos=(0, x, b), axis=(0, 0, c), radius=hatch_radius)
 cy(pos=(b, 0, x), axis=(c, 0, 0), radius=hatch_radius)
 cy(pos=(0, b, x), axis=(0, c, 0), radius=hatch_radius)
 
 Doesn't this call to cy still call the function multiple times?

I'm not sure I understand what you mean, but here goes anyway...

Well, yes, but you have to call it six times per loop, with six different
sets of arguments, that's why there are six calls to it. I don't think
there's any way to reduce that (although if there is, the Original Poster
would probably love to hear about it).

Bruno's code has two micro-optimizations. The first is to avoid
looking up visual.cylinder each time (six times the number of loops) and
instead only look it up once. If axis_length is (say) 100, you save 1200
name look-ups of arbitrary complexity.

(Perhaps visual inherits from Klass, which inherits from Spam, which
inherits from Parrot, which inherits from Foo, which inherits from Bar,
which has a method cylinder. Name look-ups can be time consuming.)

The second is to avoid calculating -hatch_length and hatch_length*2 for
each call, but to calculate them only once per loop. Again, only a
micro-optimization, but arithmetic in Python is more work than in (say) C,
because of the whole object oriented framework. So if you can avoid having
to look up hatch_length.__mul__ repeatedly, you may see a small but
significant time saving.


-- 
Steven.

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


Re: Time functions

2007-05-02 Thread HMS Surprise
On May 2, 12:03 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 In [EMAIL PROTECTED], HMS Surprise
 wrote:

  I wish to generate a datetime string that has the following format.
  '05/02/2007 12:46'. The leading zeros are required.

  I found '14.2 time' in the library reference and have pulled in
  localtime. Are there any formatting functions available or do I need
  to make my own? Perhaps there is something similar to C's printf
  formatting.

 You mean like `time.strftime()`!?  :-)

 Ciao,
 Marc 'BlackJack' Rintsch

Thanks for posting.

I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

thanx,
jvh

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


gpp (conditional compilation)

2007-05-02 Thread [EMAIL PROTECTED]
I'm trying to use the gpp utility (Gnu points to 
http://en.nothingisreal.com/wiki/GPP)
to do conditional compilation in Python, and I'm running into a
problem: the same '#' character introduces Python comments and is used
by default to introduce #ifdef etc. lines.

Here's an example of what I'm trying to do:

#ifdef DEBUG
   stderr.write(variable is...) #details of msg omitted
#endif

I'm using the following args to gpp:
   +s \ \ \ +s \' \' \'  +c \\\# \\n -n
The result is that the #ifdef and #endif lines get treated as
comments, rather than instructions to gpp to keep or omit the lines in
between.

I tried just omitting the +c arg, but then I get msgs at the end of
each file saying
  Input ended while scanning a comment/string
apparently because I use apostrophes inside comments, and gpp thinks
those are unterminated strings.

I can think of some work-arounds, like don't use apostrophes inside
comments, or don't use single-quoted strings (or define them for
gpp) or use a different char for the first char of a gpp macro.
But I'd rather not...

Does anyone have a set of gpp args that plays well with Python?  (Or
makefiles, where I presume the same problem comes up.)

   Mike Maxwell
   CASL/ U MD

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


Re: how to use Dispatch to open an application in win32com.client

2007-05-02 Thread Peter Fischer
Hello,

I also use the COM API via python to dispatch an application. My
problem now is that I want to dispatch a second instance of this
application (Google Earth by the way). But when I invoke dispatch
the second time, nothing happens although using another variable to
store the returned value:

GE_1 =  win32com.client.Dispatch(GoogleEarth.ApplicationGE)

GE_2 =  win32com.client.Dispatch(GoogleEarth.ApplicationGE)

(import and while not .IsInitialized() statements omitted for brevity)

Does anyone know how to start a second, third, and so on, instance of
the application?

You would help me very much since I am new to this and have no clue
where to look at documentation for that.

Best regards,

Peter.
   
-
Ahhh...imagining that irresistible new car smell?
 Check outnew cars at Yahoo! Autos.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: gpp (conditional compilation)

2007-05-02 Thread dustin
On Wed, May 02, 2007 at 10:37:40AM -0700, [EMAIL PROTECTED] wrote:
 I'm trying to use the gpp utility (Gnu points to 
 http://en.nothingisreal.com/wiki/GPP)
 to do conditional compilation in Python, and I'm running into a
 problem: the same '#' character introduces Python comments and is used
 by default to introduce #ifdef etc. lines.

The hacks you'll need to wrap gpp in to get it to work will make your
head spin.

I'm not sure what brought you to gpp, but if you're looking for a basic
macro-processing language suitable for the kinds of tasks the C
preprocessor performs, I would recommend M4.  GNU has an implementation
of the language, and it's actually quite widely used as the basis for
the GNU autotools suite.  It is incredibly flexible (enough so that its
learning curve is a bit steep, but not too bad), but that flexibility
enables it to work with just about any underlying language.

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


Re: gpp (conditional compilation)

2007-05-02 Thread Duncan Booth
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 I'm trying to use the gpp utility (Gnu points to
 http://en.nothingisreal.com/wiki/GPP) to do conditional compilation in
 Python, and I'm running into a problem: the same '#' character
 introduces Python comments and is used by default to introduce #ifdef
 etc. lines. 
 
 Here's an example of what I'm trying to do:
 
 #ifdef DEBUG
stderr.write(variable is...) #details of msg omitted
 #endif
 

Why do you want conditional compilation. Is there anything wrong with:

if __debug__:
stderr.write(variable is...) #details of msg omitted

If you run Python with the -O command line option the code protected by the 
if statement will be optimised out.

For most other purposes where you might use conditional compilation just 
adding 'if' statements to execute at runtime (or try/except) will do the 
same purpose:

if sys.platform=='win32':
   def foo():
   ... something ...
else:
   def foo():
    something different ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gpp (conditional compilation)

2007-05-02 Thread John Nagle
[EMAIL PROTECTED] wrote:
 I'm trying to use the gpp utility (Gnu points to 
 http://en.nothingisreal.com/wiki/GPP)
 to do conditional compilation in Python, and I'm running into a
 problem: the same '#' character introduces Python comments and is used
 by default to introduce #ifdef etc. lines.

Just use an if statement.  The Python interpreter is so slow
it won't matter.

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


Re: Python un-plugging the Interpreter

2007-05-02 Thread John Nagle
Jorgen Grahn wrote:
 On Wed, 25 Apr 2007 08:05:01 +0200, Hendrik van Rooyen [EMAIL PROTECTED] 
 wrote:
 
Jorgen Grahn [EMAIL PROTECTED] wrote:

 Eric Raymond's The Art of Unix Programming sums up the threading
 criticism, I think:
 
 http://catb.org/~esr/writings/taoup/html/multiprogramchapter.html

 What that really reflects is that threads came late to UNIX.
The locking primitives weren't standardized for years, signals took
a decade to settle down, interprocess message passing was weak and
still is, and some parts of the context, like the current directory,
are per-process while they should be per-thread.  To this day,
threading remains an afterthought in the UNIX/Linux/C world.

 This really isn't a Python topic, but if you want to see threading
and interprocess communication done right, look at QNX 6.
True message passing, well defined semantics for thread cancellation,
the ability to time out any system call that blocks, and defined
atomic operations are all there.  All the thread machinery that has to
work right is well worked out and well documented.

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


Re: Time functions

2007-05-02 Thread Matimus
On May 2, 10:21 am, HMS Surprise [EMAIL PROTECTED] wrote:
 On May 2, 12:03 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:

  In [EMAIL PROTECTED], HMS Surprise
  wrote:

   I wish to generate a datetime string that has the following format.
   '05/02/2007 12:46'. The leading zeros are required.

   I found '14.2 time' in the library reference and have pulled in
   localtime. Are there any formatting functions available or do I need
   to make my own? Perhaps there is something similar to C's printf
   formatting.

  You mean like `time.strftime()`!?  :-)

  Ciao,
  Marc 'BlackJack' Rintsch

 Thanks for posting.

 I think I have an import misconception.

 I use
 import from time localtime, strftime
 t = strftime('%m/%d/%Y %H:%M', localtime())

 This works. How would one use it with the module name pre-pended?

 thanx,
 jvh

I would think that what you have written there shouldn't work at
all...

it would need to be:

[code]
from time import localtime, strftime
[/code]

to use the prepended module name just do this instead:

[code]
import time
t = time.strftime('%m/%d/%Y %H:%M', time.localtime())
[/code]

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


  1   2   3   >