Unicode error in wx_gdi ?

2005-03-04 Thread Erik Bethke
Hello All,

I still shaking out my last few bugs in my tile matching game:

I am now down to one stumper for me:
 1) when I initialize wxPython
 2) from an exe that I have created with py2exe
 3) when the executable is located on the desktop as opposed to
somewhere on C or D directly
 4) when My Desktop is not written in ascii but instead Korean hangul

I get this error:

Traceback (most recent call last):
  File "shanghai.py", line 13, in ?
  File "wxPython\__init__.pyc", line 10, in ?
  File "wxPython\_wx.pyc", line 3, in ?
  File "wxPython\_core.pyc", line 15, in ?
  File "wx\__init__.pyc", line 42, in ?
  File "wx\_core.pyc", line 10994, in ?
  File "wx\_gdi.pyc", line 2443, in ?
  File "wx\_gdi.pyc", line 2340, in Locale_AddCatalogLookupPathPrefix
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbf in position
26: ordinal not in range(128)

Granted this may seem like an obscure error, but the net effect is that
I cannot use wxPython for my games and applications as many of my users
will place the executable directly on their desktop and the path of the
desktop contains non-ascii paths.

What do i do from here?  Do I go into wx_gdi.py and fix it so that it
uses unicode instead of ascii?  I have not yet made any changes to
other people's libraries...

Any help would be much appreciated,
-Erik

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


Re: file.getvalue() with _ or other characters

2005-03-04 Thread martijn
srry I needed some sleep.
it works oke.

But if you want to answer a question.

I use this code:
--
import StringIO
import re
import urllib2,htmllib, formatter

class mvbHTMLParser(htmllib.HTMLParser):
def __init__(self, formatter, verbose=0):
htmllib.HTMLParser.__init__(self,formatter,verbose)

def getContent(url):
try:
line = urllib2.urlopen(url)
htmlToText(line.read().lower())
except IOError,(strerror):
print strerror

def htmlToText(html):
file = StringIO.StringIO()
f = formatter.AbstractFormatter(formatter.DumbWriter(file))
p = mvbHTMLParser(f)
p.feed(html)
p.close()

print file.getvalue()

getContent('http://www.zquare.nl/test.html')
--
then the output is:
text_text
a_link[1]

that's oke but how to delete [n]
like this? : del = re.compile(r'[0-9]',).sub

Thanks for the fast helping,
GC-Martijn

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


Re: PEP 246 revision

2005-03-04 Thread Magnus Lie Hetland
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
>
>
>I had a look at the new reference implementation of PEP 246
>(Object Adaptation) and I feel uneasy with one specific point
>of this new version. I don't fully understand why it checks
>if *the type of* the protocol has a method "__adapt__":
>
>...
># (c) then check if protocol.__adapt__ exists & likes obj
>adapt = getattr(type(protocol), '__adapt__', None)
>...
>
>As a consequence of this change, you can't define a protocol
>as a class that implements __adapt__ anymore.

How about an instance of such a class?

>class Protocol(object):
>def __adapt__(self, obj):
>...

If you instantiate this class, the object's type will have the
__adapt__ attribute...

This is the way it works with other special methods (i.e.
__foo__-methods) in Python, too. Instead of looking in the object (or
class) in question, Python checks the *type* of the object (or class).
That's the general rule -- no reason to make an exception here. (In
fact, there is every reason *not* to make an exception, IMO.)

A good example of why this makes sense is the __call__ method. Imagine
what would happen if Python looked for this in the object itself,
instead of in the type of the object... Now imagine we defined this
class:

  class Foo(object):
  def __call__(self):
  print "Howdy!"

If, under the "new lookup rule", we tried to instantiate this class,
we'd get:

  >>> foo = Foo()
  Howdy!

... and no instance. We're calling the Foo-object, and the
__call__-method we defined gets called.

Instead, of course, Python has the wisdom to check the *type* of the
object for such special calls -- and thus uses object.__call__
instead, which (obviously) instantiates the class just like we want it
to.

So: The scenario needn't be as complex as in your example, as long as
you use instances instead of classes as protocols.

(I guess the case could be made for using classes as protocols, but I
suspect the case would be mainly syntactical...)

- M

-- 
Magnus Lie Hetland   Time flies like the wind. Fruit flies
http://hetland.org   like bananas. -- Groucho Marx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file.getvalue() with _ or other characters

2005-03-04 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> class mvbHTMLParser(htmllib.HTMLParser):
> def __init__(self, formatter, verbose=0):
> htmllib.HTMLParser.__init__(self,formatter,verbose)

  def anchor_end(self):
  self.anchor = None

[...]

> then the output is:
> text_text
> a_link[1]
> 
> that's oke but how to delete [n]
> like this? : del = re.compile(r'[0-9]',).sub

Overriding the anchor_end() method as shown above will suppress the [n]
suffix after links.

Peter

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


curses & disable readline & replace stdin

2005-03-04 Thread Brano Zarnovican
Hi !

I'd like to init curses and still have working Python interactive
command line. I found that you can replace stdin/stdout/stderr
like this:

#!/usr/bin/python -i

import curses
import sys
import atexit

# this doesn't help, anyway
#del sys.modules['readline']

# global variable (curses window)
stdscr = None

class FakeStdIO(object):

  def write(self, str):
global stdscr
stdscr.addstr(str)
stdscr.refresh()

  def readline(self):
print "$ ",
return stdscr.getstr()

stdscr = curses.initscr()
atexit.register(curses.endwin)
curses.echo()

f = FakeStdIO()
sys.stdin  = f
sys.stdout = f
sys.stderr = f

print 'Hello, curses !'# <-- this works

l = sys.stdin.readline()   # <-- this also works fine

# <-- interactive Python prompt doesn't echo imput

It looks that '>>>' prompt is using the readline module, which
is not using sys.stdin at all.

Q: Can you prevent python interpreter to use readline module
  (even when it is available), *without* recompiling python ?

I think it should be possible to write a module in C to access
Python internals. But can you do it "from python" ?

The other option is to make readline somehow work with curses.
This is however not what I intended.

Platform: Linux Mandrake, Python 2.3.5

Thanks,

BranoZ

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


Re: Text To Speech with pyTTS

2005-03-04 Thread Hans Georg Krauthaeuser
Peter wrote:
I released a new version of the Windows installer for Python 2.3 that
includes the missing _TTSFast.pyd file.

Unfortunenately, the file TTSFast.py is missing, not _TTSFast.pyd.
Hans Georg
--
http://mail.python.org/mailman/listinfo/python-list


Wishful thinking : unix to windows script?

2005-03-04 Thread John Leslie
Or does anyone have a python script which takes a standard unix
command as an argument and runs the pyton/windows equivalent on
windows?
-- 
http://mail.python.org/mailman/listinfo/python-list


Fast 2d brown/pink noise generation?

2005-03-04 Thread Mathias
Dear NG,
I'm looking for a fast way to produce 2d-noise images with 1/f or 1/f^2 
spectrum. I currently generate the noise via inverse FFT, but since I 
need lots of data (~10^7 for a monte carlo simulation) it needs to be 
really fast. Does someone know a faster way than my approach?

- Dimensionality is between 20x20 and 100x100
- The spectrum doesn't need to be exactly pink/brown, an approximation
   is fine.
- Implementation in either matlab or scientific python (LAPACK anyway)
Thanks a lot for hints, literature, algorithms!
   Mathias
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-04 Thread bruno modulix
Gary Nutbeam wrote:
I count zpt as xml because page templates can operate in html or xml mode.
I can understand this, but from a practical POV, ZPT are mainly (x)html 
templates. A valid (x)html page is a valid ZPT too. This has nothing in 
common with the hundreds of complicated XML conf files needed by most 
J2EE app servers.

This is not a troll. It is a lot of work in Zope to create interfaces to
relational data for anything more than simple data models. 

It's a lot less work in Maypole or Rails,
I've never worked with any of them, so I can't tell. It's also true that 
most of what I've done with Zope so far relies mostly on the ZODB, RDBMS 
 connections being merely used as a bridge to share data with other 
systems. Still, I didn't have any problem with Zope/RDBMS integration so 
far.

but I don't want to go back to
writing in Perl, 
!-)
or needing to learn Ruby.
A nice language, but yes, there can be practical reasons to stick with 
Python.

(snip)
--
bruno desthuilliers
ruby -e "print '[EMAIL PROTECTED]'.split('@').collect{|p| 
p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows bat file question

2005-03-04 Thread Duncan Booth
Peter Hansen wrote:

> Unfortunately, Google makes it hard to search for such things,
> but after a while I was able to dig up this master reference:
> 
> http://www.microsoft.com/resources/documentation/windows/xp/all/proddoc
> s/en-us/percent.mspx 

You will find even more information if you try 'set /?' or 'for /?' at a 
command prompt. As you say, you can now do quite complicated scripting in 
command files but it needs masochism second only to Perl programming.

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


Re: Communication between python scripts

2005-03-04 Thread Stephen Toledo-Brown
Heiko Wundram wrote:
Am Dienstag, 1. März 2005 21:54 schrieb Chris:
Is there a preferred method for having different scripts on different
computers communicate with each other?

You have several options at your disposal.

6) do something else which doesn't come to my mind just now. ;)
The main one missing seems to be using asynchronous middleware - either 
database or Messsage Queuing. e.g. there's pymqi for a Python interface 
to WebSphereMQ, or there are some lighter-weight open-source 
alternatives if you don't need that level of robustness.

Note that between all these alternatives, there are 2 fundamentally 
different categories: synchronous (sockets, RPC) or asynchronous (email, 
ftp, MQ, etc). Getting that first decision right is much more important 
than choosing between the methods within each category because 
synchronous vs. asynchronous affects your basic app design, whereas 
refactoring between different synchronous methods or between 
asynchronous methods, is relatively easy.
--
Steve Toledo-Brown
Speaking for myself only.
Domain: uk.ibm.com
--
http://mail.python.org/mailman/listinfo/python-list


"Static" python program

2005-03-04 Thread Daniel Frickemeier
Hi,

I have a strange problem.

I´m developing a small python-program wiht the mysql-python-module.
The program should run on a server without any mysql-installation. 
Is there any posibility to "kompile" a python with static libaries?

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


Python glade tute

2005-03-04 Thread somesh
hello,
I wrote a small tute for my brother to teach him python + glade,
plz see, and suggest to make it more professional ,
In tute I discussed on Glade + Python for developing Applications too
rapidly as ppls used to work on win32 platform with VB.

http://www40.brinkster.com/s4somesh/glade/index.html


somesh

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


[announcement] - python graph library

2005-03-04 Thread Maxim Khesin
Hello Folks,
I recently started working on a graph-algorithms library in Python. What 
makes this one different from the other couple of libs that are 
available is a heavy influence from the C++ Boost Graph Library. There 
are IMO a lot of good ideas there, so I am attempting to translate the 
spirit of it into Python without loosing the Pythonness :). There is no 
official code release so far, but I have been blogging ideas and code 
snippets here: http://pythonzweb.blogspot.com/. Your comments are most 
welcome (you can leave them right on the blog).I also wanted to tap your 
opinion on naming this thing. There is (duh) already PyGL and PGL names 
associated with python (but not graph libs) floating around, but as they 
are not so well-known as far as I can tell I do not mind taking them on 
and stealing the name. What do you guys think?
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie, help with pythonpath

2005-03-04 Thread Eduardo Suarez
What do i need to add to the path? I have already tried the same with 
the PYTHONPATH variable.

Thanks in advance,
-Eduardo
[otto:eduardo/ 501]$ python
Python 2.3.5 (#2, Feb  9 2005, 00:38:15)
[GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/usr/local/pygtkglext-1.0.1')
>>> import gtk.gtkgl
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib')
>>> import gtk.gtkgl
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3')
>>> import gtk.gtkgl
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>> 
sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages')
>>> import gtk.gtkgl
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>> 
sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk 
-2.0')
>>> import gtk.gtkgl Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>> 
sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk 
-2.0/gtk')
>>> import gtk.gtkgl Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>> 
sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk 
-2.0/gtk/gtkgl')
>>> import gtk.gtkgl Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named gtkgl
>>>

Chmouel Boudjnah wrote:
Eduardo Suarez wrote:
I'm trying to set the python path variable so i can use them, but i 
haven't got it. Any hint?

sys.path.append('/usr/blah/blah/blah/directory')
--
http://mail.python.org/mailman/listinfo/python-list


Re: There's GOT to be a better way!

2005-03-04 Thread [EMAIL PROTECTED]
Good call.  I was just trying to be generic in my quickly put-together
example.  It's been a while since I've used Python so these things I
easily forget :)

'object' here would be more aptly named 'MyObject'.

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


Re: Unicode error in wx_gdi ?

2005-03-04 Thread Serge Orlov
Erik  Bethke wrote:
> Hello All,
>
> I still shaking out my last few bugs in my tile matching game:
>
> I am now down to one stumper for me:
>  1) when I initialize wxPython
>  2) from an exe that I have created with py2exe
>  3) when the executable is located on the desktop as opposed to
> somewhere on C or D directly
>  4) when My Desktop is not written in ascii but instead Korean hangul
>
> I get this error:
>
> Traceback (most recent call last):
>   File "shanghai.py", line 13, in ?
>   File "wxPython\__init__.pyc", line 10, in ?
>   File "wxPython\_wx.pyc", line 3, in ?
>   File "wxPython\_core.pyc", line 15, in ?
>   File "wx\__init__.pyc", line 42, in ?
>   File "wx\_core.pyc", line 10994, in ?
>   File "wx\_gdi.pyc", line 2443, in ?
>   File "wx\_gdi.pyc", line 2340, in Locale_AddCatalogLookupPathPrefix
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xbf in position
> 26: ordinal not in range(128)
>
> Granted this may seem like an obscure error,

Thanks to your explanation, it doesn't look very obscure. I think
the code in wxpython either uses sys.path[0] or __file__. Python
still keeps byte strings in there because of backward compatibility.


> What do i do from here?  Do I go into wx_gdi.py and fix it so that it
> uses unicode instead of ascii?  I have not yet made any changes to
> other people's libraries...

You should contact wxpython people for proper cross platform fix,
meanwhile you can fix that particular error on windows
by changing sys.path[0] into
sys.path[0].decode(sys.getfilesystemencoding())
or do the same thing for __file__. If there are a lot of similar
problems, you can call sys.setdefaultencoding('mbcs') at the start of
your program as last resort. Don't tell anyone I suggested that :)
and remember that sys.setdefaultencoding is removed in site.py,
changing default encoding can mask encoding bugs and make those
bugs hard to trace.

  Serge.

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


Re: Python glade tute

2005-03-04 Thread dimitri pater
nice start!
screenshots would improve it a lot

greetz,
Dimitri


On 4 Mar 2005 03:31:34 -0800, somesh <[EMAIL PROTECTED]> wrote:
> hello,
> I wrote a small tute for my brother to teach him python + glade,
> plz see, and suggest to make it more professional ,
> In tute I discussed on Glade + Python for developing Applications too
> rapidly as ppls used to work on win32 platform with VB.
> 
> http://www40.brinkster.com/s4somesh/glade/index.html
> 
> somesh
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Please visit dimitri's website: www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating module skeleton from unit tests

2005-03-04 Thread Edvard Majakari

Greetings, fellow Pythonistas!

I'm about to create three modules. As an avid TDD fan I'd like to create
typical 'use-cases' for each of these modules. One of them is rather large,
and I wondered if it would be easy enough to create a code skeleton out of
unit test module.

Consider the following, though contrived, unit test code snippet:

==

import player

class TestClass:

def setup_method(self, meth):

self.obj = player.Player('Fred the Adventurer')

def test_name(self):

assert self.obj.name == 'Fred the Adventurer'

def test_inventory(self):

# player always starts with a dagger
assert self.obj.inventory == {'dagger': [(1, 4)]}

# dagger is an initial weapon
assert self.obj.weapon_type == 'dagger'

# add sword to player and wield it
self.obj.add_item('sword', (1, 8))

# wield the first sword in the backbag
self.obj.wield('sword')

assert self.obj.weapon_type == 'sword'

assert self.obj.inventory == {'dagger': [(1, 4)], 'sword': [(1, 8)] }

def test_level(self):

cur_level = self.obj.level

self.obj.level_up()

assert cur_level + 1 = self.obj.level

def test_hitpoints(self):

start_hp = 30
sword_damage = 6

assert self.obj.hitpoints == start_hp

self.obj.damage(sword_damage)

assert self.obj.hitpoints == start_hp - sword_damage

==

Now it would be nice if I could do

$ python test2skel.py test_player.py

$ cat player.py

class Player:

  def __init__(self, str): # constructor was called with a string,
   # so we create init with str arg

  # self.weapon_type was compared to string and no parenthesis were
  # used, so the best guess is it's an attribute

  self.weapon_type = None

  # ditto for inventory, name and hitpoints

  self.inventory = None

  self.name = None

  self.hitpoints = None


  def add_item(self, str, tpl):
  # add_item() was called with a string arg and a tuple

  pass

  def damage(self, obj):
  # damage() was called with an argument

  def wield(self, obj):
  # wield was called with an arg

  def level_up(self):
  # level_up() was called without args


Now I'm thinking of at least three possible ways to implement that, all of
which may not be very sensible, but what I could come up with:

1. Try to run the test case and capture exceptions. Trying to import player 
   and failing means there is no module player.py. The script could create a
   file player.py. Running the tests again imply there's an attribute Player
   which seems like a method call or class (both are 'called' in the same
   way). Nothing is created, but an ambiguous state is set for Player: it's
   either a class or module method. Later calls for Player instance remove the
   ambiguity and then we know it's a class, and as such the class skeleton
   is created. Proceeding this way a skeleton could probably be created by
   catching Import/Attribute errors and so forth.

2. Parse the test cases module as Python code, and extract all possible
   information therein. Probably the best-working method, but needs Python
   parser and some serious semantic logic. Probably the most obvious but also
   hardest(?) way to do it.

3. Parse the test case as a text file, and extract only necessary
   information. Eg. creating needed module files is probably very easy: for
   practical purposes, you could just grep "import " and "from
import " to find out what module files need to be
   created. Hackish and not elegant but would probably work for custom
   purposes well enough (especially if we restrict ourselves to only lines
   starting with 'import module' statements in the test module). However,
   eg. associating an instance method call with the class used in object
   creation would be quite hard, if the parser is just a simple one.

4. Use a completely different approach, eg. create a module skeleton using a
   custom markup (easily generated from many graphical design tools) and use
   that for creating both the test skeleton and module itself. However, it
   wouldn't be TDD because then you'd be designing the module the usual way

Also remember that the program wouldn't need to be very clever. A strict
coding standard can be assumed, and eg. the fact that all classes are in
CamelCase would help in deducing whether foo.Bar() is a method call or
Bar-class object instantiation (methods are always lower_case_with_underscore,
according to PEP 8 we try to follow).

What do you think? I know that probably the best way to go on is just do it
the old way (ie. code both the test and module by hand), or look for more
intelligent IDEs. 

For what it's

Re: Python glade tute

2005-03-04 Thread P
somesh wrote:
hello,
I wrote a small tute for my brother to teach him python + glade,
plz see, and suggest to make it more professional ,
In tute I discussed on Glade + Python for developing Applications too
rapidly as ppls used to work on win32 platform with VB.
http://www40.brinkster.com/s4somesh/glade/index.html
I would work through a concrete example, with screenshots.
Have a look at: http://www.pixelbeat.org/talks/pygtk
You may get ideas from other tutorials here:
http://www.awaretek.com/tutorials.html
Pádraig.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating module skeleton from unit tests

2005-03-04 Thread Peter Maas
Edvard Majakari schrieb:
Greetings, fellow Pythonistas!
I'm about to create three modules. As an avid TDD fan I'd like to create
typical 'use-cases' for each of these modules. One of them is rather large,
and I wondered if it would be easy enough to create a code skeleton out of
unit test module.
I think this is too difficult, because there are many ways to write
code (even skeletons) for a use case. An easier approach would
be to write the skeleton manually, embed the test cases in the doc
strings and generate the test code from the doc strings. If I
remember correctly IBM has published something to generate unit
tests from code. Python has a doctest module to support testing
derived from doc strings. This can be combined with unit tests.
> The problem can be solved more easily if you design the module
skeleton first, then the tests and then the logic for the skeleton
- you would be creating tests before the code, but many people
> wouldn't regard it as TDD then.
You shouldn't care if your approach works for you.
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wishful thinking : unix to windows script?

2005-03-04 Thread Steve Holden
John Leslie wrote:
Or does anyone have a python script which takes a standard unix
command as an argument and runs the pyton/windows equivalent on
windows?
This would seem to be a request of overkill of the worst kind, given the 
existing availability of tools like Cygwin (www.cygwin.com) and, more 
recently, CoLinux (www.colinux.org).

Why do it in Python when it's better done already?
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Fast 2d brown/pink noise generation?

2005-03-04 Thread Mathias
Dear NG,
I'm looking for a fast way to produce 2d-noise images with 1/f or 1/f^2 
spectrum. I currently generate the noise via inverse FFT, but since I 
need lots of data (~10^7 for a monte carlo simulation) it needs to be 
really fast. Does someone know a faster way than my approach?

- Dimensionality is between 20x20 and 100x100
- The spectrum doesn't need to be exactly pink/brown, an approximation
   is fine.
- Implementation in either matlab or scientific python (LAPACK anyway)
Thanks a lot for hints, literature, algorithms!
   Mathias
--
http://mail.python.org/mailman/listinfo/python-list


win32 COM and data types / direction

2005-03-04 Thread Alexander Eisenhuth
Hello everybody,
i wonder how the win32 COM extension handles different C-int types 
(short, int, long). Another question for me is weather the 
"out-direction" of parameter is supported "out of the box" ?

To clarify look at the methode "FunWithTwoInts"
--
#SimpleCOMServer.py - A sample COM server - almost as small as they come!
#
# We expose a single method in a Python COM object
class PythonUtilities:
_public_methods_ = [ 'FunWithTwoInts' ]
_reg_progid_ = "PythonDemo.Utilities"
# NEVER copy the following ID!
# Use "print pythoncom.CreateGuid( )" to make a new one
_reg_clsid_  = "{40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}"
def FunWithTwoInts(self, inShort, inInt, outSum):
print "got as short:%d as int:%d sum:%d" % (inShort, inInt, outSum)
outSum = inShort + inInt
# Add code so that when this script is run by
# Python.exe, it self-registers
if __name__=='__main_  _':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
--
Does anybody have experiences in this ?
Any help/hints are very welcome.
Alexander
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wishful thinking : unix to windows script?

2005-03-04 Thread Patrick Useldinger
John Leslie wrote:
Or does anyone have a python script which takes a standard unix
command as an argument and runs the pyton/windows equivalent on
windows?
There's not always an equivalent command.
-pu
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating module skeleton from unit tests

2005-03-04 Thread Fabio Zadrozny
I think that the best approach I saw to this was in the Eclipse java 
ide... You can basically go on the declaration of

self.obj = player.Player('Fred the Adventurer')
press Ctrl+1 and it adds a suggestion to create the class Player.
Then go to
assert self.obj.name == 'Fred the Adventurer'
press Ctrl+1 and it adds suggestion: Declare field name in class 
Player... and so on for methods...  (true, you still have to go and 
press some Ctrl+1s, but that should be fairly easy, especially if you 
had some hints on what is missing... Python has a very dynamic nature, 
but most of it can still be done...

I think that most Python IDEs are still not in the same level, but some 
day they might get there...
Being the maintaner of PyDev (http://pydev.sf.net), I think it will get 
there someday, true, lots of work to make it happen, right now only few 
things in Ctrl+1 are available like that (still, some already are)... 
and that's the way things work... nothing's always perfect (but at least 
they evolve).

Regards,
Fabio
Peter Maas wrote:
Edvard Majakari schrieb:
Greetings, fellow Pythonistas!
I'm about to create three modules. As an avid TDD fan I'd like to create
typical 'use-cases' for each of these modules. One of them is rather 
large,
and I wondered if it would be easy enough to create a code skeleton 
out of
unit test module.

I think this is too difficult, because there are many ways to write
code (even skeletons) for a use case. An easier approach would
be to write the skeleton manually, embed the test cases in the doc
strings and generate the test code from the doc strings. If I
remember correctly IBM has published something to generate unit
tests from code. Python has a doctest module to support testing
derived from doc strings. This can be combined with unit tests.
> The problem can be solved more easily if you design the module
skeleton first, then the tests and then the logic for the skeleton
- you would be creating tests before the code, but many people
> wouldn't regard it as TDD then.
You shouldn't care if your approach works for you.

--
Fabio Zadrozny
--
Software Developer
ESSS - Engineering Simulation and Scientific Software
www.esss.com.br
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python glade tute

2005-03-04 Thread adamc
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2005-03-04, somesh <[EMAIL PROTECTED]> wrote:
> hello,
> I wrote a small tute for my brother to teach him python + glade,
> plz see, and suggest to make it more professional ,
> In tute I discussed on Glade + Python for developing Applications too
> rapidly as ppls used to work on win32 platform with VB.
>
> http://www40.brinkster.com/s4somesh/glade/index.html
>
>
> somesh
>
Somesh, 

I've been meaning to start a small simple collection of documents that 
teaches the basics of python to younger (age 7-12) children. I have 
two kids who aren't yet old enough to read properly (although they've 
made a start) but I want to get some basic docs ready for when they're 
ready to start. 

I've looked around at other docs, but I don't think that they are great 
for ordinary kids of this age (but I'm sure some will get something out 
of it). The docs I want to produce will run in small chunks but with 
quick resultsi, heavy on screenshots (where applicable) and have a 
younger look and feel about them than some of the official documents. 
All the documents should also be supported by face-to-face interaction 
(like a day programming with dad!)

I notice that your documents are specific to gui creation and glade, 
and I'm not sure how old your brother is, but do you want to collaborate 
on this? Anyone else think this might be worth while distributing? 

Adam

- -- 
http://www.monkeez.org
PGP key: 7111B833
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCKG7TLeLM1Z6tVakRAiUSAJ9yaxNBk0YnqB7ES20eMLKL6U1ymACfcSHA
VCZ81mc86bS0wK39ah/as5U=
=dhNY
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python glade tute

2005-03-04 Thread dimitri pater
hello,
I would certainly want to collaborate on writing Python tutorial for
kids (I've got a small kids myself (7, 5, 3)). I already wrote some
tutorials that make heavy use of screenshots (serpia.com) but they are
for big kids like us ;-)
Please contact me, maybe we can work something out. I'd be more than
happy to host the tutorials *and* help you with writing them.

bye,
Dimtiri


On Fri, 04 Mar 2005 08:21:16 -0600, adamc <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On 2005-03-04, somesh <[EMAIL PROTECTED]> wrote:
> > hello,
> > I wrote a small tute for my brother to teach him python + glade,
> > plz see, and suggest to make it more professional ,
> > In tute I discussed on Glade + Python for developing Applications too
> > rapidly as ppls used to work on win32 platform with VB.
> >
> > http://www40.brinkster.com/s4somesh/glade/index.html
> >
> >
> > somesh
> >
> Somesh,
> 
> I've been meaning to start a small simple collection of documents that
> teaches the basics of python to younger (age 7-12) children. I have
> two kids who aren't yet old enough to read properly (although they've
> made a start) but I want to get some basic docs ready for when they're
> ready to start.
> 
> I've looked around at other docs, but I don't think that they are great
> for ordinary kids of this age (but I'm sure some will get something out
> of it). The docs I want to produce will run in small chunks but with
> quick resultsi, heavy on screenshots (where applicable) and have a
> younger look and feel about them than some of the official documents.
> All the documents should also be supported by face-to-face interaction
> (like a day programming with dad!)
> 
> I notice that your documents are specific to gui creation and glade,
> and I'm not sure how old your brother is, but do you want to collaborate
> on this? Anyone else think this might be worth while distributing?
> 
> Adam
> 
> - --
> http://www.monkeez.org
> PGP key: 7111B833
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.0 (GNU/Linux)
> 
> iD8DBQFCKG7TLeLM1Z6tVakRAiUSAJ9yaxNBk0YnqB7ES20eMLKL6U1ymACfcSHA
> VCZ81mc86bS0wK39ah/as5U=
> =dhNY
> -END PGP SIGNATURE-
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Please visit dimitri's website: www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Static" python program

2005-03-04 Thread Pink
Daniel  Frickemeier wrote:

> Hi,
> 
> I have a strange problem.
> 
> I´m developing a small python-program wiht the mysql-python-module.
> The program should run on a server without any mysql-installation.
> Is there any posibility to "kompile" a python with static libaries?
MySQL distributions (at least on Linux systems) are usually split into
server and client packages. If you install the mysql-client package on the
server, you'll have all you need (libs and stuff) to access a remote server
- without the mysql server itself.
Not sure about the windows, although I would guess that the installer let's
you choose which parts to install (client libs/tools, server or both).

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


python upgrade process...

2005-03-04 Thread bruce
hi...

i currently have a rh8.0 server that is a little messed up!! i need to know
what's the best/right process to upgrade to the latest python/mod_python,
and any associated libs

i need to make sure that i don't break the gnome/httpd, or any other python
dependent app...

currently i have different versions on the box, but it appears when i do a
$>python, i get the older version... which is not what i need/want!!!

so, i'm asking, what's the best process for doing an update.

i've tried 'yum update' but it gives some sort of baseurl error... 'apt-get'
doesn't seem to work either... however. if you suggest that these tools
would be the best approach, would these tools actually get all required
dependencies/etc...

thanks..

bruce


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


Re: Wishful thinking : unix to windows script?

2005-03-04 Thread Grant Edwards
On 2005-03-04, Patrick Useldinger <[EMAIL PROTECTED]> wrote:
> John Leslie wrote:
>
>> Or does anyone have a python script which takes a standard unix
>> command as an argument and runs the pyton/windows equivalent on
>> windows?
>
> There's not always an equivalent command.

If you install cygwin there almost always is.

-- 
Grant Edwards   grante Yow!  What I need is a
  at   MATURE RELATIONSHIP with a
   visi.comFLOPPY DISK...
-- 
http://mail.python.org/mailman/listinfo/python-list


Geneator/Iterator Nesting Problem - Any Ideas? 2.4

2005-03-04 Thread ChaosKCW
Hi

Using Python 2.4 I am trying to procduce a generator which will return
the results of dbi SQL statement using fetchmany for performance.

So instead of fetching one record for each call, I will fetch batches
of X (eg 100) and yeild each record in turn.

For reasons of pure asthetics and my own learning I wanted it to look
like this:


def resultsetbatchgen(cursor, size=100):
for results in (recordbatch for recordbatch in
cursor.fetchmany(size)):
for rec in results:
yield rec


Problem is this this gives spurious results. To understand the problem
if I excute the following in the console I get the correct results:


>>> cur.execute()
>>> recs = (recordbatch for recordbatch in cur.fetchmany(1000))
>>> sum(map(lambda x: 1, (rec for rec in recs)))
1000


This is PERFECT! 1000 is what I expected. but now lets nest this inside
another for construct like so


>>> cur.execute()
>>> for results in (recordbatch for recordbatch in
cur.fetchmany(1000)):
... print sum(map(lambda x: 1, (rec for rec in results)))
76
76
76
76
76
76
76
76
...


Now it thinks each batch size is 76 ... ? This completly wrong, and
baffling.

The commands are exactly the same as far as I can tell, the only
difference is that it is now nested wihtin another for loop?

Any help would be greatly aprpeciated.

PS a working but far less elegant version of this below but I would
like to understand why teh above doesnt work and doesnt work
consitantly:

def resultsetbatch(cursor, size=100):
results = cursor.fetchmany(size)
while results <> []:
for rec in results:
yield rec
results = cursor.fetchmany(size)

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


Re: Call variable as a function

2005-03-04 Thread Nick Coghlan
Steve Holden wrote:
There's always a way:
 >>> def test():
...   print "hello"
...
 >>> var = "test"
 >>> eval("%s()" % var)
hello
I'd go with locals() for the simple case of a name lookup:
Py> def test():
...   print "Hi there!"
...
Py> var = "test"
Py> locals()[var]()
Hi there!
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python glade tute

2005-03-04 Thread Harlin Seritt
Not to make light of your tutorial but it can use some editing (the
English grammar and spelling is below par). I understand that most
likely English is not your first language. Given that, I think you did
a great job. If you like, email me back and I'll be glad to help out
with that, but I can only do it if I can get my hands on the source of
your docs (not sure if you're using some type of doc tool -- it does
appear that way).

I must say, I thought your tutorial was very good. I despise RAD tools
but you almost had me convinced to give PyGTK and Glade a shot ;-)

Regards,

Harlin

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


Re: Setting default option values for Tkinter widgets

2005-03-04 Thread [EMAIL PROTECTED]
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.

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


[Numeric] column vector faster than row vector in mat multiply?

2005-03-04 Thread Zhang Le
Hi,
  I did a small benchmark of matrix-vector multiply operation using
Numeric module. I'm a bit suprised to find matrix*col-vector is much
faster than row-vector*matrix. I wonder whether other people have
observed this fact too, and why?

  Below is the code I used, with output from my machine.

python bench.py
running 1000 iterations of matrix multiply of row 1000-vector
10.5609340668 sec
running 1000 iterations of matrix operation of column 1000-vector
4.11953210831 sec

-code begin-
import random
import time
from Numeric import *

n = 1000
k = 1000

r = array([ random.gauss(0, 1) for i in range(n)])
c = array([ [random.gauss(0, 1)] for i in range(n)])

M = zeros((n, n), Float)
for i in range(n):
for j in range(n):
M[i][j] = random.gauss(0, 1)

print 'running %d iterations of matrix multiply of row %d-vector' % (k,
n)
t = time.time()
for i in xrange(k):
matrixmultiply(r,  M)
print time.time()-t, 'sec'

print 'running %d iterations of matrix operation of column %d-vector' %
(k, n)
t = time.time()
for i in xrange(k):
matrixmultiply(M, c)
print time.time()-t, 'sec'

--code end--


Zhang Le

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


Re: Wishful thinking : unix to windows script?

2005-03-04 Thread Steven Bethard
Grant Edwards wrote:
On 2005-03-04, Patrick Useldinger <[EMAIL PROTECTED]> wrote:
John Leslie wrote:

Or does anyone have a python script which takes a standard unix
command as an argument and runs the pyton/windows equivalent on
windows?
There's not always an equivalent command.

If you install cygwin there almost always is.
Also worth mentioning: GnuWin32
http://gnuwin32.sourceforge.net/
Especially useful if you just want a few specific tools (and not an 
entire OS).

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


(no subject)

2005-03-04 Thread python-list-bounces+archive=mail-archive . com
#! rnews 2494
Newsgroups: comp.lang.python
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wns13feed!worldnet.att.net!12.120.4.37!attcg2!ip.att.net!xyzzy!nntp
From: Jeff Sandys <[EMAIL PROTECTED]>
Subject: Re: Delete first line from file
X-Nntp-Posting-Host: e515855.nw.nos.boeing.com
Content-Type: text/plain; charset=iso-8859-1
Message-ID: <[EMAIL PROTECTED]>
Sender: [EMAIL PROTECTED] (Boeing NNTP News Access)
Content-Transfer-Encoding: 8bit
Organization: juno
X-Accept-Language: en
References: <[EMAIL PROTECTED]>
Mime-Version: 1.0
Date: Fri, 4 Mar 2005 16:15:55 GMT
X-Mailer: Mozilla 4.79 [en]C-CCK-MCD Boeing Kit  (Windows NT 5.0; U)
Xref: news.xs4all.nl comp.lang.python:365744
Lines: 71

Here is a non-destructive way keeping track of the 
current file position when closing the file and 
re-open the file where you left off.  You can 
always use seek(0) to go back to the beginning.

# -- start of myfile class
class myfile(file):
myfiles = {}
def __init__(self, fname, *args):
file.__init__(self, fname, *args)
if self.name in myfile.myfiles:
pos = myfile.myfiles[fname]
else:
pos = 0
return self.seek(pos)
def close(self):
myfile.myfiles[self.name] = self.tell()
file.close(self)
#  end of myfile class

Below is an example with a simple four line file.

PythonWin 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
on win32.
Portions Copyright 1994-2001 Mark Hammond ([EMAIL PROTECTED]) -
see 'Help/About PythonWin' for further copyright information.
>>> f = open("C:/Pydev/test.txt")
>>> f.readlines()
['line one\n', 'line two\n', 'line three\n', 'last line\n']
>>> ### short four line file
>>> f.close()
>>> from myfile import myfile
>>> f = myfile("C:/Pydev/test.txt")
>>> f.readline()
'line one\n'
>>> f.readline()
'line two\n'
>>> f.close()
>>> ### test, is the file really closed?
>>> f.readline()
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: I/O operation on closed file
>>> f = myfile("C:/Pydev/test.txt")
>>> f.readline()
'line three\n'
>>> ### reopened file starts where it left off
>>> f.readline()
'last line\n'
>>> f.close()
>>> f = myfile("C:/Pydev/test.txt")
>>> f.seek(0)
>>> ### return to the beginning of the file
>>> f.readline()
'line one\n'
>>> 

This turned out really cool,
thanks for the good question,
Jeff Sandys


"Tor Erik Sønvisen" wrote:
> 
> Hi
> 
> How can I read the first line of a file and then delete this line, so that
> line 2 is line 1 on next read?
> 
> regards
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geneator/Iterator Nesting Problem - Any Ideas? 2.4

2005-03-04 Thread Steven Bethard
ChaosKCW wrote:
For reasons of pure asthetics and my own learning I wanted it to look
like this:

def resultsetbatchgen(cursor, size=100):
for results in (recordbatch for recordbatch in
cursor.fetchmany(size)):
for rec in results:
yield rec

Note that this is equivalent to:
def resultsetbatchgen(cursor, size=100):
for results in cursor.fetchmany(size):
for rec in results:
yield rec
That is, your generator expression isn't really doing anything.
cur.execute()
recs = (recordbatch for recordbatch in cur.fetchmany(1000))
sum(map(lambda x: 1, (rec for rec in recs)))
1000
This should be equivalent to
...
>>> recs = iter(cur.fetchmany(1000))
>>> len(list(recs))
cur.execute()
for results in (recordbatch for recordbatch in cur.fetchmany(1000)):
... 	print sum(map(lambda x: 1, (rec for rec in results)))
This is now equivalent to:
>>> cur.execute()
>>> for rec in cur.fetchmany(1000):
... print len(list(results))
Note that you're counting the number of elements in record, which I'm 
guessing is 76?

I'm thinking you want to do something like:
def resultsetbatchgen(cursor, size=100):
while True:
results = cursor.fetchmany(size)
if not results:
break
for rec in results:
yield rec
I don't actually know how you tell when there isn't anything more to 
fetch, but if it returns an empty list, you could also write this like:

def resultsetbatchgen(cursor, size=100):
for results in iter(lambda: cursor.fetchmany(size), [])
for rec in results:
yield rec
HTH,
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Making things more functional in Python

2005-03-04 Thread gf gf
Is there a better, more FP style, more Pythonic way to
write this:

def compute_vectors(samples, dset):
vectors = {}
for d in dset:
vectors[d] = [sample.get_val(d) for sample in
samples]
return vectors

Namely, I'd like to get rid of the initilization
(vectors = {}) and also the loop  Yet, I'd hate to put
an assignment into Python's FP list comprehensions.

Ideally, I'd like something like this:
vectors.dict_add({d:result}) for [sample.get_val(d)
for sample in samples for d in dset].  

Is there anything like that?  Am I missing the
picture?

Thanks.

PS If possible, please cc me on all responses, thanks.




__ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making things more functional in Python

2005-03-04 Thread Michael Hoffman
gf gf wrote:
Is there a better, more FP style, more Pythonic way to
write this:
def compute_vectors(samples, dset):
vectors = {}
for d in dset:
vectors[d] = [sample.get_val(d) for sample in
samples]
return vectors
Namely, I'd like to get rid of the initilization
(vectors = {}) and also the loop
Generate the whole dictionary on the fly with a Python 2.4 generator
expression:
dict((d, [sample.get_val(d) for sample in samples]) for d in dset)
Whether this is "better" or not I think mainly hinges on which
one you ahve an easier time understanding later. Personally I would
prefer this version, but it's easy to get carried away trying to
functionalize things to the point that a procedural version is much
easier to understand.
Yet, I'd hate to put an assignment into Python's FP list
> comprehensions.
Indeed it's not possible to have an assignment in a list comprehension.
(Unless it's a side-effect due to a function called by the list
comprehension.)
Ideally, I'd like something like this:
vectors.dict_add({d:result}) for [sample.get_val(d)
for sample in samples for d in dset].  
You can't use the name "vectors" without first initializing it
somehow!
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Making things more functional in Python

2005-03-04 Thread Steve Holden
gf gf wrote:
Is there a better, more FP style, more Pythonic way to
write this:
def compute_vectors(samples, dset):
vectors = {}
for d in dset:
vectors[d] = [sample.get_val(d) for sample in
samples]
return vectors
Namely, I'd like to get rid of the initilization
(vectors = {}) and also the loop  Yet, I'd hate to put
an assignment into Python's FP list comprehensions.
Ideally, I'd like something like this:
vectors.dict_add({d:result}) for [sample.get_val(d)
for sample in samples for d in dset].  

Is there anything like that?  Am I missing the
picture?
Thanks.
PS If possible, please cc me on all responses, thanks.
The logical thing to use would be
return dict([(d, sample.getval(d)) for d in dset for sample in samples])
which (I think) should work from 2.2 onwards.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Setting default option values for Tkinter widgets

2005-03-04 Thread Steve Holden
[EMAIL PROTECTED] wrote:
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.
So, are you using Windows?
[EMAIL PROTECTED] /c/Python24/Lib/site-packages
$ python -c 'print "".join([chr(154 - ord(c)) for c in 
"U(17zX(%,5.z5(17l8(%,5.Z*(93-965$l7+-"])'
Eric Brunel [EMAIL PROTECTED]

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Making things more functional in Python

2005-03-04 Thread Bill Mill
On Fri, 4 Mar 2005 08:36:49 -0800 (PST), gf gf
<[EMAIL PROTECTED]> wrote:
> Is there a better, more FP style, more Pythonic way to
> write this:
> 
> def compute_vectors(samples, dset):
> vectors = {}
> for d in dset:
> vectors[d] = [sample.get_val(d) for sample in
> samples]
> return vectors
> 
> Namely, I'd like to get rid of the initilization
> (vectors = {}) and also the loop  Yet, I'd hate to put
> an assignment into Python's FP list comprehensions.

Well, I guess it's a little more FP, but whether it's (IMHO) way
*less* pythonic:

return dict([(d, [sample.get_val(d) for sample in samples]) 
  for d in dset])

it should work, but is untested and really ugly. I don't see what's
wrong with your code that you need to compress it. It's blindingly
obvious what your code does, which is a good thing. My list comp, on
the other hand, is seven kinds of confusing for a reader.

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: winnt win32process.createProcess with stdout to file ?

2005-03-04 Thread david . humpherys
Aweseome! Many many thanks Roger ! You've made my day.

The last thing that you may be able to help with...
I'm using
win32api.TerminateProcess(hProcess,3)
to kill this process if it gets outta hand...
but when i do so.. it seems that the stdout/stderr don't capture the
output.

here's my last chunk of code.
again.. thank you so much.

hProcess, hThread, dwProcessId, dwThreadId =
win32process.CreateProcess \
( None, self.RENDER_STRING, sa, sa, 1,
win32con.NORMAL_PRIORITY_CLASS, None, None, startInfo)

while self.exitCode == 259:
if self.stop:
print "kill da process"
win32api.TerminateProcess(hProcess,3)

self.exitCode = 
win32process.GetExitCodeProcess(hProcess)
time.sleep(2)

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


Re: Geneator/Iterator Nesting Problem - Any Ideas? 2.4

2005-03-04 Thread ChaosKCW
Hi

Thanks this was very helpfull.

Your final solution seems like the best (most elegant). I was trying to
avoid the ugly while loops with breaks and this final one certainly
does that. 

Thanks for your help .

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


Re: Wishful thinking : unix to windows script?

2005-03-04 Thread Patrick Useldinger
Grant Edwards wrote:
If you install cygwin there almost always is.
If you install cygwin there's no need for what the OP describes.
-pu
--
http://mail.python.org/mailman/listinfo/python-list


Re: get textual content of a Xml element using 4DOM

2005-03-04 Thread uche . ogbuji
I suggest using minidom or pxdom [1] rather than 4DOM.  If you insist
on using 4DOM, xml.dom.ext.Print(node) or xml.dom.ext.PrettyPrint(node)
does what you want.

--Uche

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


Re: get textual content of a Xml element using 4DOM

2005-03-04 Thread uche . ogbuji
I suggest using minidom or pxdom [1] rather than 4DOM.  If you insist
on using 4DOM, xml.dom.ext.Print(node) or xml.dom.ext.PrettyPrint(node)
does what you want.

[1] http://www.doxdesk.com/software/py/pxdom.html

--Uche

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


Re: best XSLT processor?

2005-03-04 Thread uche . ogbuji
Steve Holden:

"I don't know what news reader you are using, but I wonder if I could
ask
you to retain just a little more context in your posts. If they were
personal emails I would probably be able to follow the thread, but in a
newsgroup it's always helpful when I see a comment such as your above
if
I know what the heck you are talking about ;-)."

I'm using Google Groups.  I'd assumed it maintains quoting, but I guess
not.  Looks as if I'll have to ditch it, which makes things awkward
because I don't have time to follow this NG in its entirety: I prefer
to just search weekly for "Python XML".

--Uche

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


Re: Making things more functional in Python

2005-03-04 Thread Michael Hoffman
Steve Holden wrote:
return dict([(d, sample.getval(d)) for d in dset for sample in samples])
That won't do what the original code does. This sets dict[d] to
samples[-1].getval(d) instead of [sample.getval(d) for sample in samples].
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Making things more functional in Python

2005-03-04 Thread Steve Holden
Michael Hoffman wrote:
Steve Holden wrote:
return dict([(d, sample.getval(d)) for d in dset for sample in samples])

That won't do what the original code does. This sets dict[d] to
samples[-1].getval(d) instead of [sample.getval(d) for sample in samples].
My bad, I didn;t look closely enbough to see the need for the nested 
comprehensions.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Downloadable python-dev archive February 2005 contains only one mail?

2005-03-04 Thread tlesher
Yes; it seems that the "advance" post by effbot messed up the
archiving.

If you get
http://mail.python.org/pipermail/python-dev/2005-February.txt (without
the .gz suffix), you'll get the whole archive.

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


Re: Is there way to determine which class a method is bound to?

2005-03-04 Thread Victor Ng
So I went digging through the documentation more and found the following:

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

There's a section titled "User-defined methods" which covers all the
im_self, im_class attributes and what they are responsible for.

vic

On 25 Feb 2005 10:42:06 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Another way is to make a simple metaclass, setting an attribute (like
> defining_class, or something) on each function object in the class
> dictionary.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
---
"Never attribute to malice that which can be adequately explained by
stupidity."  - Hanlon's Razor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to run IDLE Under Windows

2005-03-04 Thread maxwell
Peter Otten wrote:
> Perhaps your configuration files contain bad data:
>
> # IDLE reads several config files to determine user preferences.
This
> # file is the default config file for general idle settings.
...
> # On Windows2000 and Windows XP the .idlerc directory is at
> #   Documents and Settings\\.idlerc

I have a similar problem: I can't run the Python IDLE app (i.e. the
file pythonw.exe), on either of two different machines.  However, I'm
using WinXP (and Python 2.4), and there is no .idlerc directory as
listed above.  One of hte machines had a .idlerc file under the Python
dir, and renaming it didn't help.  I just ran a search on the entire
hard drive of the other machine, and the only .idlerc dir is in my
CygWin home directory.  Since I'm not trying to run idle from a CygWin
bash shell etc., I don't think it's looking there.  (Just to make sure,
I renamed that dir...no luck.)

I uninstalled and re-installed Python 2.4, no change.  When I try to
run pythonw.exe, there is no indication that anything happens.  CPU
usage jumps for a  fraction of a second, then nothing.

I tried running 'idle' under CygWin, and it gives the following error
(lengthy traceback omitted, let me know if I should include that too):

  C:\cygwin\bin\python2.4.exe (2904): *** unable to remap
  C:\cygwin\bin\cygssl-0.9.7.dll to same address as parent
  (0x74) != 0x75
  2 [main] python2.4 3080 fork_parent: child 2904 died waiting
  for dll loading

Any other ideas why IDLE won't run?

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


[Job - Part Time - Local] Seeking Python Coder in South Alabama area.

2005-03-04 Thread John F.
Startup company in Fairhope, AL is seeking a strong python programmer
in the Mobile, AL or Eastern Shore, AL area to assist in the
development of legal practice management systems.  Candidate must
reside in the area. Position will be initially part time.  Must be
proficient with Freebsd/Postgresql/Python/WxGlade(WxPython).  Must have
real world experience and be ready to contribute effectively.  Please
send resume to HikenbootsAtyahoo.com

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


Re: Setting default option values for Tkinter widgets

2005-03-04 Thread Kent Johnson
Steve Holden wrote:
[EMAIL PROTECTED] wrote:
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.
So, are you using Windows?
If you interchange single and double quotes it works on Windows too
python -c "print ''.join([chr(154 - ord(c)) for c in 
'U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-'])"
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Easy way to check modules for python version compatibility?

2005-03-04 Thread Stephen Toledo-Brown
Given some Python source, is there any tool which can tell the mimimum 
level of Python required to run that source? If I distribute some code, 
I need to be able to say which level of Python users require to run it.

--
Steve Toledo-Brown
Speaking for myself only.
Humans please use domain uk.ibm.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wishful thinking : unix to windows script?

2005-03-04 Thread Max Erickson
you might also want to take a look at
http://unxutils.sourceforge.net/
where are the tools are available in a single zip file.

max

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


Q: Module Shared Data

2005-03-04 Thread CatManDo
Disclaimer #1: I am a Python newbie, and I appreciate the vast
documentation at python.org -- some of which I expect has the answer to
my question if I can find it.

I am working on a custom computational fluid dynamics code.  I will
create one or more compiled Python modules in C/C++ to provide new
types and functions for manipulating those types.  I have a *lot* of
data.  Efficiency requires that the new data structures be shared
freely within the scope of the module, without directly exposing the
data to the standard Python runtime environment.

Stated another way, I need the data to persist in virtual memory across
seprate invocations of functions in the module(s) and to be accessible
only through methods explicitly provided by the module(s).

How can I do this?  What are some good examples to study?

Disclaimer #2: I am a aware that strong opinions exist about closing
off data from users.  But it's a requirement for this application.  I
don't like it, but I need the job!

Thanks for your time
CatManDo

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


Re: Easy way to check modules for python version compatibility?

2005-03-04 Thread [EMAIL PROTECTED]
I do not think there's a direct way of telling it - but you can try to
catch a DeprecationWarning, that is issued by most code deprecated
modules

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


Re: greedy match wanted

2005-03-04 Thread alexk
Thanks, I'll try your solution.
Alex.

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


Re: Unable to run IDLE Under Windows

2005-03-04 Thread Steve Holden
[EMAIL PROTECTED] wrote:
Peter Otten wrote:
Perhaps your configuration files contain bad data:
# IDLE reads several config files to determine user preferences.
This
# file is the default config file for general idle settings.
...
# On Windows2000 and Windows XP the .idlerc directory is at
#   Documents and Settings\\.idlerc

I have a similar problem: I can't run the Python IDLE app (i.e. the
file pythonw.exe), on either of two different machines.  However, I'm
using WinXP (and Python 2.4), and there is no .idlerc directory as
listed above.  One of hte machines had a .idlerc file under the Python
dir, and renaming it didn't help.  I just ran a search on the entire
hard drive of the other machine, and the only .idlerc dir is in my
CygWin home directory.  Since I'm not trying to run idle from a CygWin
bash shell etc., I don't think it's looking there.  (Just to make sure,
I renamed that dir...no luck.)
In this case it's possible (and this is just a guess) that you are both 
running with what are called "roaming profiles". In this case your 
".idlerc" file may appear somewhere on a network drive that's 
automatically mapped rather than a subdirectory of C:\Documents and 
Settings.

You should be able to find it under XP with the command
echo %HOMEPATH%
Take a look in that directory and see if there's an .idlerc.
I uninstalled and re-installed Python 2.4, no change.  When I try to
run pythonw.exe, there is no indication that anything happens.  CPU
usage jumps for a  fraction of a second, then nothing.
You wouldn't expect anything - pythonw.exe is the no-console 
interpreter, so if you don;t give it a program to run it will terminate 
pretty much immediately, and if the program doesn't use windowing then 
you won't see anything happen even if you *do* run something.

I presume you *can* run python.exe :-)
If so then try running IDLE with python -v to get more information about 
what's going on.

I tried running 'idle' under CygWin, and it gives the following error
(lengthy traceback omitted, let me know if I should include that too):
  C:\cygwin\bin\python2.4.exe (2904): *** unable to remap
  C:\cygwin\bin\cygssl-0.9.7.dll to same address as parent
  (0x74) != 0x75
  2 [main] python2.4 3080 fork_parent: child 2904 died waiting
  for dll loading
This is a known issue with Cygwin. Fortunately you can fix it with the 
rebaseall command. You could try the following steps to fix Cygwin, 
which is currently unable to load a DLL at the same address in a forked 
sub-process. Note this is voodoo, so no guarantees ...

1. Close all Cygwin windows (and stop Cygwin services, if any are running).
2. In a new standard Cygwin command interpreter window run
  rebaseall -v
That should be it.
Any other ideas why IDLE won't run?
Well, that's a few things to think about, anyway.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


__contains__ inconsistencies between Python 2.2 and 2.3

2005-03-04 Thread Anand S Bisen
Hello
I have been developing a code that works pretty well on my python 2.3 
and now when i am running it on my server where it is programmed to run 
it's giving me errors. I have been using __contains__ method and it 
fails on python 2.2

For example
(Python 2.3)
>> x="Hello World"
>> print x.__contains__("Hello")
True
(Python 2.2)
>>> x="Hello world"
>>> print x.__contains__("Hello")
Traceback (most recent call last):
 File "", line 1, in ?
TypeError: 'in ' requires character as left operand
Is there any woraround for this or what am i doing wrong in 2.2 ?
Thanks
ASB
--
http://mail.python.org/mailman/listinfo/python-list


Re: __contains__ inconsistencies between Python 2.2 and 2.3

2005-03-04 Thread Steven Bethard
Anand S Bisen wrote:
For example
(Python 2.3)
 >> x="Hello World"
 >> print x.__contains__("Hello")
True
(Python 2.2)
 >>> x="Hello world"
 >>> print x.__contains__("Hello")
Traceback (most recent call last):
 File "", line 1, in ?
TypeError: 'in ' requires character as left operand
Is there any woraround for this or what am i doing wrong in 2.2 ?
IIRC, until Python 2.3, __contains__ only accepted strings of length 1. 
 Before Python 2.3, I think you needed to do something like:

py> x = 'Hello world'
py> x.find('Hello') != -1
True
py> x.find('wrld') != -1
False
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: __contains__ inconsistencies between Python 2.2 and 2.3

2005-03-04 Thread Steve Holden
Anand S Bisen wrote:
Hello
I have been developing a code that works pretty well on my python 2.3 
and now when i am running it on my server where it is programmed to run 
it's giving me errors. I have been using __contains__ method and it 
fails on python 2.2

For example
(Python 2.3)
 >> x="Hello World"
 >> print x.__contains__("Hello")
True
(Python 2.2)
 >>> x="Hello world"
 >>> print x.__contains__("Hello")
Traceback (most recent call last):
 File "", line 1, in ?
TypeError: 'in ' requires character as left operand
Is there any woraround for this or what am i doing wrong in 2.2 ?
Thanks
Any use of double-underscores is an indication that magic is at work. In 
this case the __contains__ method is intended to be called by the 
interpreter when you write

x in s
The __contains__ method was extended for strings in 2.3 so that 
construct could be used as a test to see whether s contained x as a 
substring. Before that, as the error message explains, it will only test 
to see whether a single character is contained in the string (by analogy 
with

1 in [3, 4, 5, 2]
in case you are interested).
So you'll need to use the .find() string method and say
if x.find("Hello") != -1:
... you found "Hello"
because your ISP appears to be using an older version of Python than you.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Numeric] column vector faster than row vector in mat multiply?

2005-03-04 Thread Terry Reedy

"Zhang Le" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>  I did a small benchmark of matrix-vector multiply operation using
> Numeric module. I'm a bit suprised to find matrix*col-vector is much
> faster than row-vector*matrix. I wonder whether other people have
> observed this fact too,

Yes, common knowledge in numerical analysis community.  Using the faster 
direction for a particular system as much as possible is part of tuning 
linear algebra software.

> and why?

I presume that Numeric, like Python, stores matrices by row.  So M*v 
multiplies contiguous rows by a contiguous vector.  Multiplying a vector by 
non-contiguous columns requires requires skipping thru the matrix, which 
may require more computation and generate more cache misses and page 
faults.

Terry  J. Reedy



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


enum question

2005-03-04 Thread M.N.A.Smadi
does python support a C-like enum statement where one can define a 
variable with prespesified range of values?

thanks
m.smadi
--
http://mail.python.org/mailman/listinfo/python-list


Re: Communication between python scripts

2005-03-04 Thread [EMAIL PROTECTED]
Another reason NOT to use XML-RPC:

PSF-2005-001 - SimpleXMLRPCServer.py allows unrestricted traversal
http://python.org/security/PSF-2005-001/

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


Re: win32 COM and data types / direction

2005-03-04 Thread Thomas Heller
Alexander Eisenhuth <[EMAIL PROTECTED]> writes:

> Hello everybody,
>
> i wonder how the win32 COM extension handles different C-int types
> (short, int, long). Another question for me is weather the
> "out-direction" of parameter is supported "out of the box" ?
>
> To clarify look at the methode "FunWithTwoInts"
> --
> #SimpleCOMServer.py - A sample COM server - almost as small as they come!
> #
> # We expose a single method in a Python COM object
> class PythonUtilities:
>  _public_methods_ = [ 'FunWithTwoInts' ]
>  _reg_progid_ = "PythonDemo.Utilities"
>
>  # NEVER copy the following ID!
>  # Use "print pythoncom.CreateGuid( )" to make a new one
>  _reg_clsid_  = "{40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}"
>
>  def FunWithTwoInts(self, inShort, inInt, outSum):
>   print "got as short:%d as int:%d sum:%d" % (inShort, inInt, outSum)
>   outSum = inShort + inInt
>
> # Add code so that when this script is run by
> # Python.exe, it self-registers
> if __name__=='__main_  _':
>  print "Registering COM server..."
>  import win32com.server.register
>  win32com.server.register.UseCommandLine(PythonUtilities)
> --
> Does anybody have experiences in this ?

Since there is no type library, the client code has to guess.  And it
will pass the server whatever the client calls with.  That could even be
a string or anything else - but why not try it out?

*IF* there is a type library that the server implements, you will get
and return what it describes.

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


Re: winnt win32process.createProcess with stdout to file ?

2005-03-04 Thread Roger Upole
TerminateProcess doesn't give it a chance to exit normally
and do any cleanup that would happen if it exited itself.
It may not have been able to flush its file buffers, etc.
Does the executable have any way to signal it to exit ?

 Roger


<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Aweseome! Many many thanks Roger ! You've made my day.
>
> The last thing that you may be able to help with...
> I'm using
> win32api.TerminateProcess(hProcess,3)
> to kill this process if it gets outta hand...
> but when i do so.. it seems that the stdout/stderr don't capture the
> output.
>
> here's my last chunk of code.
> again.. thank you so much.
>
> hProcess, hThread, dwProcessId, dwThreadId =
> win32process.CreateProcess \
> ( None, self.RENDER_STRING, sa, sa, 1,
> win32con.NORMAL_PRIORITY_CLASS, None, None, startInfo)
>
> while self.exitCode == 259:
> if self.stop:
> print "kill da process"
> win32api.TerminateProcess(hProcess,3)
>
> self.exitCode = win32process.GetExitCodeProcess(hProcess)
> time.sleep(2)
> 




== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with variabels in Tkinter

2005-03-04 Thread Svennglenn
I have a problem with a program i'm
making in Tkinter.
The code is avaliable at:
http://paste.plone.org/943

When i'm running the program and enters a value and press the
button in the dialog window that comes up when a press the
button "Lägg till spelare" (add a player in swedish)
I get this error message:
NameError: global name 'entry' is not defined



Does anyone know what the problem is?

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


Integer From A Float List?!?

2005-03-04 Thread andrea_gavana
Hello NG,

I was wondering if there is a way to obtain, from a list of floats,
a list of integers without loops. Probably is a basic question, but I can't
find an answer... I have had my eyes blinded by Matlab for years, but now
that I discovered Python+wxPython there seems to be no limit on what one
can do with these 2 tools. Anyway, following the Matlab style, I would like
to do something like this:

matrix = [1.5, 4.3, 5.5]
integer_matrix = int(matrix)   (float for Matlab)

(In Matlab, "integer_matrix" is always a double anyway, here I would like
only to show the vector-matrix operation).

Obviously, Python complains about:

Traceback (most recent call last):
  File "", line 1, in ?
TypeError: int() argument must be a string or a number

I would like to avoid loops because, having been blinded by Matlab vector-matrix
abilities (and corresponding SLOW for-while loops operations), I tend to
think that also Python will be slow if I use loops.

Does anyone have a suggestion (or maybe could anyone show me that I'm wrong
about loops?)

Thanks you a lot.

Andrea. 

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


Python 2.4 removes None data type?

2005-03-04 Thread [EMAIL PROTECTED]
I just read in the 'What's New in Python 2.4' document that the None
data type was converted to a constant:
http://python.org/doc/2.4/whatsnew/node15.html

"""
# None is now a constant; code that binds a new value to the name
"None" is now a syntax error.
"""

So, what's the implications of this?  I find the lack of explanation a
little puzzling, since I've written code that compares a variable's
type with the 'None' type.  For example, a variable would be
initialized to 'None' and if it went through a loop unchanged, I could
determine this at the end by using a conditional type(var) ==
type(None).  What will type(None) return now?

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


Re: Integer From A Float List?!?

2005-03-04 Thread Bill Mill
On Fri, 4 Mar 2005 22:35:48 +0100, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello NG,
> 
> I was wondering if there is a way to obtain, from a list of floats,
> a list of integers without loops. Probably is a basic question, but I can't
> find an answer... I have had my eyes blinded by Matlab for years, but now
> that I discovered Python+wxPython there seems to be no limit on what one
> can do with these 2 tools. Anyway, following the Matlab style, I would like
> to do something like this:
> 
> matrix = [1.5, 4.3, 5.5]
> integer_matrix = int(matrix)   (float for Matlab)

You're going to have to use loops. I don't know how Matlab can do it
without them, unless it maintains the matrix as a list of floats and
simply *views* it as a list of ints. More likely, it simply hides the
loop away from you. Anyway, here's some ways to do it:

preferable: int_matrix = [int(x) for x in matrix]
old way: int_matrix = map(int, matrix)
explicit:
int_matrix = []
for x in matrix:
int_matrix.append(int(x))

Any of these methods should be neither really slow nor really fast,
but the list comprehension should be the fastest (I think). Anyway, if
you're going to be doing lots of large matrices, and want some of your
old matlab stuff, check out numpy and numarray at
http://numeric.scipy.org/ .

Also, somebody was recently posting on here about a python <-> matlab
bridge that they developed; you should search the archives for that
(it was in february, I think).

And, finally, when doing scientific stuff, I found IPython
(http://ipython.scipy.org/) to be an invaluable tool. It's a much
improved Python interpreter.

Peace
Bill Mill
bill.mill at gmail.com

> 
> (In Matlab, "integer_matrix" is always a double anyway, here I would like
> only to show the vector-matrix operation).
> 
> Obviously, Python complains about:
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: int() argument must be a string or a number
> 
> I would like to avoid loops because, having been blinded by Matlab 
> vector-matrix
> abilities (and corresponding SLOW for-while loops operations), I tend to
> think that also Python will be slow if I use loops.
> 
> Does anyone have a suggestion (or maybe could anyone show me that I'm wrong
> about loops?)
> 
> Thanks you a lot.
> 
> Andrea.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Suspicious header

2005-03-04 Thread phil
everything I post to this list bounces awaiting moderator
approval, due to suspicious header.
COuld someone tell me what's wrong.  I'm on lots of list
with no problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 removes None data type?

2005-03-04 Thread Tim Peters
[EMAIL PROTECTED]
> I just read in the 'What's New in Python 2.4' document that the None
> data type was converted to a constant:
> http://python.org/doc/2.4/whatsnew/node15.html
>
> """
> # None is now a constant; code that binds a new value to the name
> "None" is now a syntax error.
> """
> 
> So, what's the implications of this?

No implications, for any sane code.  You can no longer do things like this:

>>> None = 2
SyntaxError: assignment to None

That's all.

> I find the lack of explanation a little puzzling, since I've written code that
> compares a variable's type with the 'None' type.  For example, a variable
> would be initialized to 'None' and if it went through a loop unchanged, I 
> could
> determine this at the end by using a conditional type(var) == type(None).

Python's None is a singleton, meaning that there is a single, unique
instance of type type(None).  So in the case you describe, it's
correct, and idiomatic, to test

 if var is None:

instead.  Checking type(var) against type(None) will still work, but
was never the best way to do it.

If you have an expression like

var = None

that's fine.  You're not changing the binding of name "None" there,
you're changing the binding of name "var".

>  What will type(None) return now?

That hasn't changed:

>>> type(None)

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


Re: Python 2.4 removes None data type?

2005-03-04 Thread Gary D. Duzan
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>I just read in the 'What's New in Python 2.4' document that the None
>data type was converted to a constant:
>http://python.org/doc/2.4/whatsnew/node15.html
>
>"""
># None is now a constant; code that binds a new value to the name
>"None" is now a syntax error.
>"""
>
>So, what's the implications of this?  I find the lack of explanation a
>little puzzling, since I've written code that compares a variable's
>type with the 'None' type.  For example, a variable would be
>initialized to 'None' and if it went through a loop unchanged, I could
>determine this at the end by using a conditional type(var) ==
>type(None).  What will type(None) return now?

   Empirically, NoneType, same as before. The change you refer to is
to prevent the user from doing silly things like:

==
Python 2.3.4 (#1, Feb  8 2005, 13:07:40)
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(None)

>>> None="fred"
:1: SyntaxWarning: assignment to None
>>> None
'fred'
>>> type(None)

>>> 
==
Python 2.4 (#1, Mar  4 2005, 16:55:16)
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(None)

>>> None="Fred"
SyntaxError: assignment to None
>>> type(None)

>>> 
==

   So your idiom should still work. Note that since there is only
one NoneType instance (i.e. None), you can just test for "var is None"
and save yourself some work.

Gary Duzan
BBN Technologies


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


Re: Suspicious header

2005-03-04 Thread James Stroud
This was happening to me for a while but stopped. I think it has to do with 
your mail server. Perhaps you could find another. If you are at a company, 
you might want to talk to your sysadmin and see if he can change the mail 
program. How did you get this latest message through? You know, with the 
proper email client you can have identities and such that have "from" and 
"return addresses" that are completely unrelated to the mail server you are 
using, if you would rather the mail list did not know about your most favored 
address.

James

On Friday 04 March 2005 01:56 pm, phil wrote:
> everything I post to this list bounces awaiting moderator
> approval, due to suspicious header.
> COuld someone tell me what's wrong.  I'm on lots of list
> with no problem.

-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
-- 
http://mail.python.org/mailman/listinfo/python-list


survey

2005-03-04 Thread Dave Zhu
Hello All,

Is there any survey on scripting languages? I would
like to get information on several scripting languages
including Python, Perl, Ruby, Tcl, etc.

Thanks

Dave




__ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 removes None data type?

2005-03-04 Thread Warren Postma
[EMAIL PROTECTED] wrote:
I just read in the 'What's New in Python 2.4' document that the None
data type was converted to a constant:
http://python.org/doc/2.4/whatsnew/node15.html
Implication: A long standing wart in Python now gone.  Its time to 
gloat. Are there any really evil glitches LEFT in Python? Now go look at 
  Perl and come back and say "Thank-deity-of-my-choice-I'm-using-Python".

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


Indexing strings

2005-03-04 Thread Fred
Hi everybody

I am searching for a possibility, to find out, what the index for a
certain lettyer in a string is.
My example:

for x in text:
   if x == ' ':
  list = text[:  # There I need the index of the space the
program found during the loop...

Is there and possibility to find the index of the space???
Thanks for any help!
Fred
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get textual content of a Xml element using 4DOM

2005-03-04 Thread Frank Abel Cancio Bello
Hi:

PrettyPrint or Print return the value to the console, and i need keep this 
value in a string variable to work with it, how can i do this?

thanks to Uche

Frank Abel

-Original Message-
From: [EMAIL PROTECTED]
To: [email protected]
Date: 4 Mar 2005 09:23:07 -0800
Subject: Re: get textual content of a Xml element using 4DOM

> I suggest using minidom or pxdom [1] rather than 4DOM.  If you insist
> on using 4DOM, xml.dom.ext.Print(node) or xml.dom.ext.PrettyPrint(node)
> does what you want.
> 
> [1] http://www.doxdesk.com/software/py/pxdom.html
> 
> --Uche
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 




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


Re: Problem with variabels in Tkinter

2005-03-04 Thread Steve Holden
Svennglenn wrote:
I have a problem with a program i'm
making in Tkinter.
The code is avaliable at:
http://paste.plone.org/943
When i'm running the program and enters a value and press the
button in the dialog window that comes up when a press the
button "Lägg till spelare" (add a player in swedish)
I get this error message:
NameError: global name 'entry' is not defined

Does anyone know what the problem is?
You define entry in the local namespace of laggtillspare() and then try 
to reference it from bekraftspelare(), where it is neither local nor global.

That's why most Tkinter-based designs define a class for each window. 
The instance's namespace can then be used by all methods as a shared 
namespace. Instead of entry you would refer to self.entry in two methods 
of the same instance.

If you don't know what I'm talking about, take a look at some simple 
Tkinter examples. It should start to make sense after you've pored over 
the code for an house or so ...

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Indexing strings

2005-03-04 Thread Patrick Useldinger
Fred wrote:
I am searching for a possibility, to find out, what the index for a
certain lettyer in a string is.
My example:
for x in text:
   if x == ' ':
  list = text[:  # There I need the index of the space the
program found during the loop...
Is there and possibility to find the index of the space???
Thanks for any help!
Fred
Use the index method, e.g.: text.index(' ').
What exactly do you want to do?
-pu
--
http://mail.python.org/mailman/listinfo/python-list


Re: Indexing strings

2005-03-04 Thread Steve Holden
Fred wrote:
Hi everybody
I am searching for a possibility, to find out, what the index for a
certain lettyer in a string is.
My example:
for x in text:
   if x == ' ':
  list = text[:  # There I need the index of the space the
program found during the loop...
Is there and possibility to find the index of the space???
Thanks for any help!
Fred
Perhaps you need something at a higher level (though you could use 
text.find(" ") for the first occurrence). I suspect you might want 
split(). Fred, meet split(). split(), meet Fred.

 >>> s = "The quick brown python swallows the lazy mongoose"
 >>> s.split()
['The', 'quick', 'brown', 'python', 'swallows', 'the', 'lazy', 'mongoose']
 >>> s.split(None)
['The', 'quick', 'brown', 'python', 'swallows', 'the', 'lazy', 'mongoose']
 >>> s.split(None, 3)
['The', 'quick', 'brown', 'python swallows the lazy mongoose']
 >>> s.split(None, 1)
['The', 'quick brown python swallows the lazy mongoose']
 >>>
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Gordon McMillan installer and Python 2.4

2005-03-04 Thread David Bolen
[EMAIL PROTECTED] (Svein Brekke) writes:

> Has anyone else succeded in using McMillans installer on 2.4?
> Thanks for any help.

I have a feeling that it may be related to the fact that the starter
modules (run*.exe) were built with VC6, which matches with Python
builds up to 2.3, but not 2.4 (which is built with VC7).  So you're
probably running into a mismatch between C runtime libraries.

Since it sounds like you have VS 2003 available to you, you might try
rebuilding the appropriate run*.exe (the source is in the installer
tree beneath the source directory).  VS 2003 should auto-convert the
.dsw/.dsp files but there's at least one dependency (zlib) that you
might have to build separately and handle manually (e.g., update the
project to locate your particular zlib library).

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


Re: Python 2.4 removes None data type?

2005-03-04 Thread Steve Holden
Warren Postma wrote:
[EMAIL PROTECTED] wrote:
I just read in the 'What's New in Python 2.4' document that the None
data type was converted to a constant:
http://python.org/doc/2.4/whatsnew/node15.html

Implication: A long standing wart in Python now gone.  Its time to 
gloat. Are there any really evil glitches LEFT in Python? Now go look at 
  Perl and come back and say "Thank-deity-of-my-choice-I'm-using-Python".


Remaining warts that won't disappear:
print >> file, stuff
@decorator
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Indexing strings

2005-03-04 Thread Fred
> Use the index method, e.g.: text.index(' ').
> What exactly do you want to do?

That was exactely what I was searching for. I needed a program, that
chopped up a string into its words and then saves them into a list. I
think I got this done...
Thanks for the help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 removes None data type?

2005-03-04 Thread Michael Hoffman
Warren Postma wrote:
Implication: A long standing wart in Python now gone.  Its time to 
gloat. Are there any really evil glitches LEFT in Python? Now go look at 
Perl and come back and say "Thank-deity-of-my-choice-I'm-using-Python".
The fact that True and False are not constants?
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 removes None data type?

2005-03-04 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> I just read in the 'What's New in Python 2.4' document that the None
> data type was converted to a constant:
> http://python.org/doc/2.4/whatsnew/node15.html
> 
> """
> # None is now a constant; code that binds a new value to the name
> "None" is now a syntax error.
> """
> 
> So, what's the implications of this?  I find the lack of explanation a
> little puzzling, since I've written code that compares a variable's
> type with the 'None' type.  For example, a variable would be
> initialized to 'None' and if it went through a loop unchanged, I could
> determine this at the end by using a conditional type(var) ==
> type(None).  What will type(None) return now?

Just out of curiosity, *why* did you test against type(None).  What did it 
buy you compared to the simpler var == None'?

In any case, it looks like it does the right thing:

Python 2.4 (#1, Jan 17 2005, 14:59:14) 
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2
Type "help", "copyright", "credits" or "license" for more information.
>>> type (None)

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


Re: creating .NET clients with python

2005-03-04 Thread John J. Lee
Guy Robinson <[EMAIL PROTECTED]> writes:

> Can anyone confirm if there is a python library that can allow me to
> create .NET clients in python.
> 
> My understanding is both IronPython and python for .NET can't create
> python .net clients?

IIUC, IronPython can, but it's not ready for production work yet (and
won't be for some while yet, I imagine).


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


Re: survey

2005-03-04 Thread George Sakkis
"Dave Zhu" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello All,
>
> Is there any survey on scripting languages? I would
> like to get information on several scripting languages
> including Python, Perl, Ruby, Tcl, etc.
>
> Thanks
>
> Dave


After a little googling, that's what I found:

http://citeseer.nj.nec.com/article/prechelt00empirical.html
http://www.sensi.org/~ak/impit/studies/report.pdf

George


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


Re: tkinter entry eat chars?

2005-03-04 Thread Harlin Seritt
You can use the textvariable option for the Entry widget. Set a bind event
for this widget that when any key pressed the StringVar() will be polled via
StringVar().get(). You do some checking for certain chars you don't want
entered and then delete them as they occur.

Harlin

"phil" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> In a Tkinter entry field (or Pmw entry)
> how could I eat charactres?
>
> Say a certain char is keyed in. Say &
> I notice in the event handler for .
> I don't want any more charactres to display or
> be in the field until I handle a see, in the
> event handler, another character. Say ?
>
> Can the event handler somehow destroy the char?
>
> Thanks
>


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


Re: windows bat file question

2005-03-04 Thread Alan Gauld
On 4 Mar 2005 10:18:08 GMT, Duncan Booth
<[EMAIL PROTECTED]> wrote:
> You will find even more information if you try 'set /?' or 'for /?' at a 
> command prompt. As you say, you can now do quite complicated scripting in 
> command files but it needs masochism second only to Perl programming.

And using WSH is so much easier, even JavaScript and VBScript are
pleasant compared to CMD language... And of course Python can be
used if appropriately installed, but then you'd probably just use
Python!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Explicit or general importing of namespaces?

2005-03-04 Thread Harlin Seritt
I think the bottom line on this is using your own sense of risk/reward with
each given module imported. Some modules (Tkinter comes to mind) it makes
sense to pollute while others it doesn't.

Harlin



"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Peter Mayne wrote:
> > Peter Hansen wrote:
> >> and it's still a bad idea in almost all cases anyway
> >
> > Since I've been playing with PyQt lately...
> >
> > Is qt not one of the "almost all" cases? From the limited number of
> > examples I've seen, it seems to be common to do
> >
> > from qt import *
>
> This sort of thing seems common amongst large frameworks such
> as PyQt or wxPython.  This is unfortunate, IMHO, though it isn't
> really a serious concern for most users.
>
> I'm grateful that the most recent versions of wxPython have
> abandoned that approach in favour of a nice clean "import wx",
> and as far as I can tell the code does not suffer as a result,
> and gains substantially in clarity.  Maybe the "qt" module
> defines far fewer names than the "wx" module does, but I for
> one am glad not to have to worry that I won't accidentally
> conflict with the hundreds that are there (in wx), nor to
> worry that my code lacks in readability.
>
> > Since most of the imported names start with "Q", are called QLabel,
> > QSlider, etc, and are generally recognisable in context, this would seem
> > to be a reasonable case of namespace pollution.
> >
> > I'm certainly not arguing with the general premise, just wondering if qt
> > is one of the sensible exceptions.
>
> If not sensible, at least fairly widely accepted, not a serious
> impediment to effective use, and definitely not without precedent.
>
> -Peter


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


Re: enum question

2005-03-04 Thread Larry Bates
Not completely sure I understand (my C is weak).
But you can do:

x=range(9)

x's contents will be
[0,1,2,3,4,5,6,7,8]

or

x=range(12,25)

x's conetnst will be
[12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]

if you mean a way to limit x's contents to a predefined
list of values, you need to write a class for that and
override the __setattr__ method to limit.  Quick
example:

class a:
def __setattr__(self, attr, x):
if x in range(10): self.__dict__[attr]=x
else:
print "error, x not in ", str(range(10))

>>> x=a()
>>> x.value=11
error, x not in  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x.value=8
>>>

Larry Bates


M.N.A.Smadi wrote:
> does python support a C-like enum statement where one can define a
> variable with prespesified range of values?
> 
> thanks
> m.smadi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: survey

2005-03-04 Thread Alan Gauld
On Fri, 4 Mar 2005 14:14:05 -0800 (PST), Dave Zhu
<[EMAIL PROTECTED]> wrote:

> Is there any survey on scripting languages? I would
> like to get information on several scripting languages
> including Python, Perl, Ruby, Tcl, etc.

There are several such comparisons on the web but most will
naturally reflect the authors personal preferences. The Python
web site has pointers to a couple and I'm sure that Perl , Tcl
and Ruby sites will have their own.

My own personal perspective is that I like Perl for one line
hacks and string processing, I like Tcl because I like the
underlying concepts and Tcl programs are often shorter than
others. I like Ruby mainly for a few of its nice features and I
like Python because I can read it when I'm finished!

Those are the things that influence me, not detailed lists of
features. I like all of the languages you mention and uise them
for different jobs. Vive la difference...

Oh yes, and don't forget to include Lisp/Scheme/Guile in 
your considerations... :-)

Alan G
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby on Rails or Perl's Maypole..is there a Python equivalent

2005-03-04 Thread John J. Lee
Gary Nutbeam <[EMAIL PROTECTED]> writes:
> D H wrote:
[...]
> > Check out Castle on Rails for .NET/Mono.  It is still in early
> > development, but you can use it with C#, VB, or boo, and I'm sure
> > eventually with IronPython as well.
> 
> Thanks for the feedback. I should have been more specific though and
> mentioned this has done on Linux (client and server).

Mono runs on Linux.


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


Re: urllib2 meta-refresh

2005-03-04 Thread John J. Lee
JanC <[EMAIL PROTECTED]> writes:

> Artificial Life schreef:
> 
> > urllib2 does not seem to be able to handle META-REFRESH in an html
> > document. I just get back the html to the page that is supposed to
> > forward me to the intended page. Any way around this? 
> 
> Have a look at the HTTPRefreshProcessor in ClientCookie:
> 

Be sure to read all the notes under "Notes about ClientCookie, urllib2
and cookielib" on this page:

http://wwwsearch.sourceforge.net/ClientCookie/


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


  1   2   >