Re: PEP 359: The "make" Statement

2006-04-13 Thread OKB (not okblacke)
Nicolas Fleury wrote:

>  I have no idea of the 
> implementation implications, but it would be nice to have the
> capability to override the namespace type to use something else
> than dict, so that it can be filled with symbols one statement at a
> time. 

I agree.  I have sometimes wanted this ability for classes, so that 
class definitions could map assignments onto class attributes in some 
way besides blindly stuffing into a dict.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


A problem with exec statement

2006-04-13 Thread TPJ
I have the following code:

---
def f():

  def g():
a = 'a' # marked line 1
exec 'a = "b"' in globals(), locals()
print "g: a =", a

  a = 'A'   # marked line 2
  exec 'a = "B"' in globals(), locals()
  print "f: a =", a
  g()

f()
---

I don't understand, why its output is:

f: a = A
g: a = a

instead of:

f: a = B
g: a = b

All works as intended, if the marked lines are commented out. I just
don't understand, why. (I suppose I don't understand, how the exec
statement works, or the way Python handles objects, their names and
namespaces...) In my opinion (according to my knowledge about Python),
with or without the marked lines commented, the code should work the
same. Well - I think I have to learn more about Python...

According to my knowledge, the most important are the namespaces: the
local ones, in this case. When Python calls the f function, its
namespace is created. This namespace contains only the g function.
Then the a variable is created (and the "a" name is added to the f
function namespace).

The next statement is the exec one. Since the statement "knows" the
local namespace (obtained from the locals() function), it should
replace the value of the a variable in the local namespace with the
value of the new string "B". I don't understand, why this is not done.

The situation in the g function is similar, the only difference is
that the local namespace contains the "a" name, that refers to a
different Python object.

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


Re: Remove Whitespace

2006-04-13 Thread John Machin
On 14/04/2006 12:51 PM, Felipe Almeida Lessa wrote:
> Em Sex, 2006-04-14 às 12:46 +1000, Steven D'Aprano escreveu:
>> Why would you want to call in the heavy sledgehammer of regular
>> expressions for cracking this peanut?
> 
> And put heavy on that!
> 
> $ python2.4 -mtimeit -s "str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6
> 4 0'" 'str.replace(" ", "")'

Oi! The OP mentioned "whitespace" ...

> 10 loops, best of 3: 3.07 usec per loop
> $ python2.4 -mtimeit -s "str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6
> 4 0'" '"".join(str.split())'
> 10 loops, best of 3: 4.16 usec per loop
> $ python2.4 -mtimeit -s "from re import sub; str = 'D c a V e r \" = d w
> o r d : 0 0 0 0 0 6 4 0'" 'sub("\\s", "", str)'
> 1 loops, best of 3: 23.6 usec per loop
> $ calc 23.6 / 3.07
> ~7.68729641693811074919
> 
> I couldn't be expressed better:
> 
> "Some people, when confronted with a problem, think "I know, I'll use
> regular expressions." Now they have two problems."
>   — Jamie Zawinski, in comp.lang.emacs
> 


C:\junk>python -mtimeit -s "str = 23 * ' X'" "str.replace(' ', '')
10 loops, best of 3: 3.65 usec per loop

C:\junk>python -mtimeit -s "str = 23 * ' X'" "str.replace(' ', 
'').replace('\t', '')
10 loops, best of 3: 4.33 usec per loop

C:\junk>python -mtimeit -s "str = 23 * ' X'; cmap = ''.join(chr(k) for k 
in range(256)); delchars = ' \t'" "str.translate(cmap, delchars)"
100 loops, best of 3: 0.883 usec per loop

0.883 / 3.65 -> 0.242

Some people, in Gadarene flight from regular expressions, don't read far 
enough in the Library Reference Manual :-)
-- 
http://mail.python.org/mailman/listinfo/python-list

wx.DC problem

2006-04-13 Thread python
I’m trying to create a way to pass the wx.dc object between multiple
object, and its mostly working… I can get two different panels to draw to
the same DC but when I scale the window out… it looks like the 2nd panel
is getting blocked by something, im not sure if its a OnPaint problem or
Maybe something with me hiding the second panel. Please help me out here…
thanks…

Attached is my two python scripts that im using… use the test.py to test
the PaintPanel script..import wx

class PaintPanel(wx.Panel):
def __init__(self, parent, id, sub = 0, *args, **kwds):
wx.Panel.__init__(self, parent, id, *args, **kwds)
self.parent = parent
self.sub =sub
self.items = []

if self.sub:
self.parent.AddItem(self)
self.Hide()
else:
pass
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

def AddItem(self, item):
## Add Item
self.items.append(item)

def RemoveItem(self, item):
## Remove Item
for i in self.items:
if(i == item):
self.items.remove(i)

def RemoveAll(self):
## Remove All Items
self.items.clear()

def OnPaint(self, event):
self.sizeX, self.sizeY  = self.GetSize()
print "position is: " + str(self.parent.GetPosition())
print "size is: " + str(self.parent.GetSize())

## Setup Double Buffer DC
buffer = wx.EmptyBitmap(self.sizeX, self.sizeY)
memDC = wx.MemoryDC()
memDC.SelectObject(buffer)
dc = wx.PaintDC(self)
self.PrepareDC(dc)

##memDC.SetBackground(wx.Brush("White"))
##memDC.Clear()

self.Draw(memDC)

memDC.EndDrawing()

## Copy DC from MemoryDC
dc.Blit(0, 0, self.sizeX, self.sizeY,  memDC, 0, 0, wx.COPY, True)

## Clean Up The DC
##del memDC
##del dc

def Draw(self, dc):
## Draw All Attached Items
for item in self.items:
item.Draw(dc)

def OnEraseBackground(self, event):
pass

class PaintItem:
def __init__(self, parent, id, name = ""):
self.parent = parent

self.name = name

self.parent.AddItem(self)
def Draw(self, dc):
self.posX, self.posY  = self.parent.GetPosition()
dc.SetTextForeground("BLUE")
dc.SetFont(wx.Font(50, wx.SWISS, wx.NORMAL, wx.BOLD))
dc.DrawText( self.name, self.posX, self.posY)

if __name__ == "__main__":
app = wx.PySimpleApp(0)
frame = wx.Frame(None, -1, size = (50,50))
frame.SetBackgroundColour((0,0,0))

panel = PaintPanel(frame, -1, size = (50,50))
item = PaintItem(panel, -1, name = "test1")

app.SetTopWindow(frame)
frame.Show()
app.MainLoop()import wx
import PaintPanel

class TestFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)

self.panel = PaintPanel.PaintPanel(self, -1)
self.subPanel= PaintPanel.PaintPanel(self.panel, -1, sub = 1)

item1 = PaintPanel.PaintItem(self.panel, -1, name = "main")
item2 = PaintPanel.PaintItem(self.subPanel, -1, name = "sub")

self.__set_properties()
self.__do_layout()

def __set_properties(self):
self.SetTitle("Test")

def __do_layout(self):
sizer = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer = wx.FlexGridSizer(3, 3, 0, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add(self.subPanel, 1, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)
grid_sizer.Add((20, 20), 0, wx.EXPAND, 0)


grid_sizer.Fit(self.panel)
grid_sizer.SetSizeHints(self.panel)
grid_sizer.AddGrowableRow(0)
grid_sizer.AddGrowableRow(1)
grid_sizer.AddGrowableRow(2)
grid_sizer.AddGrowableCol(0)
grid_sizer.AddGrowableCol(1)
grid_sizer.AddGrowableCol(2)

self.panel.SetAutoLayout(True)
self.panel.SetSizer(grid_sizer)
sizer.Add(self.panel, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer)
sizer.Fit(self)
sizer.SetSizeHints(self)
self.Layout()


class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame = TestFrame(None, -1, "")
frame.SetSize((500,200))
self.SetTopWindow(frame)
frame.Show()
return 1

if __name__ == "__main__":
 

Re: reading files in small chunks?

2006-04-13 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 13:45 +0800, Rajesh Sathyamoorthy escreveu:
> I wanted to know why it is more efficient to read a file in smaller
> chunks ( using file() or open() )?

It's more efficient in some cases, and worse on others. It also depends
on how you implement the read loop. I won't elaborate too much here,
there are loads of sites and books that talk about this topic.

> If this is not done, will this lead to errors in the data read or just
> results in slower performance?

It doesn't corrupt anything, unless you have a buggy hardware.

-- 
Felipe.

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

reading files in small chunks?

2006-04-13 Thread Rajesh Sathyamoorthy
Hi,I wanted to know why it is more efficient to read a file in smaller chunks ( using file() or open() )? If this is not done, will this lead to errors in the data read or just results in slower performance?
Thank You.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: list.clear() missing?!?

2006-04-13 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 09:17 +0400, Sergei Organov escreveu:
> I, as a newcomer, don't have much trouble understanding the binding vs
> the assignment by themselves. What does somewhat confuse is dual role of
> the "=" operator, -- sometimes it means "bind" and other times it means
> "assign", right? For me it seems that the language would be less
> error-prone and easier to grok if these two operations had different
> names/syntax (thinking about lisp "let" vs "set"), though it seems to be
> too drastic change even for Python3000.

The "=" operator *always* binds.

-- 
Felipe.

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

Re: Python editing with emacs/wordstar key bindings.

2006-04-13 Thread BartlebyScrivener
Yes, but for some reason, I get more and better help here with Python
than on xemacs.   Or maybe I've just had bad luck. Something like the
following just leaves me scratching my head. I'm on Windows XP and
never compiled anything that I know of.  I'd rather pay $30 and have
the editor work.

"BartlebyScrivener" <[EMAIL PROTECTED]> writes:
> I tried searching on this but I don't see exactly my error message.
> When I open a php file for editing, I get: "file mode specification
> error: (void-function run-mode-hooks)"

> What line do I need to add to my .init file to make this stop?

You are using .elc files compiled with a different version of Emacs.
Recompile them.

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


Re: list.clear() missing?!?

2006-04-13 Thread Sergei Organov
Peter Hansen <[EMAIL PROTECTED]> writes:
[...]
> Then it's a good reason we had this thread, so you could learn something 
> *crucial* to understanding Python and writing non-buggy code: name 
> binding versus variables which occupy fixed memory locations like in 
> some other languages.  This has to be by far the most frequent area that 
> newcomer's trip up.  But that's another story...

I, as a newcomer, don't have much trouble understanding the binding vs
the assignment by themselves. What does somewhat confuse is dual role of
the "=" operator, -- sometimes it means "bind" and other times it means
"assign", right? For me it seems that the language would be less
error-prone and easier to grok if these two operations had different
names/syntax (thinking about lisp "let" vs "set"), though it seems to be
too drastic change even for Python3000.

-- Sergei.

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


Re: Python editing with emacs/wordstar key bindings.

2006-04-13 Thread Sergei Organov
"BartlebyScrivener" <[EMAIL PROTECTED]> writes:
>>> When all I started looking for was a more robust editor for Python ;-)
>
> Both WingIDE and Komodo Dragon allow for customization of keyboard
> bindings. They aren't free, but they cost only $30.00 or so. Cheap for
> what you get, especially in the case of Komodo because it makes a nice
> editor for many languages--Perl, PHP, HTML etc.
>
> I tried Xemacs several times over the years on Win XP. Something
> usually breaks, and then--yes--you have to learn Lisp to fix it.

No, usually you just need to ask in one of (X)emacs groups/mailing
lists, and get a recipe in about a day, making it similar to learning to
use Python. And that drastically differs from trying to convince those $
companies to fix something for you ;)

-- Sergei.

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


Re: How to create a single executable console application?

2006-04-13 Thread Podi
Alright, pythoneers, here is what I have found from
http://wiki.wxpython.org/index.cgi/CreatingStandaloneExecutables. This
is much easier than the py2exe + nullsoft combo :)

Cheers!

The mcillian installer development is discontinued.

mirror:
http://davidf.sjsoft.com/mirrors/mcmillan-inc/installer_dnld.html

Continued development(not tested yet):
http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi

This works on Win32.
Unzip the Installer in a directory of your choice, and cd there.

Configure the Installer by running:

python Configure.py

Python must be in your PATH for this to work, if it's not, type from
the command prompt: PATH=%PATH%;c:\python23

where c:\python23 must be replaced with the root of your python
installation.
Then, assuming the source code is app.py (placed in c:\source): python
Makespec.py --upx --onefile --noconsole c:\source\app.py
python Build.py  app\app.spec

Replace 'app' everywhere above with your application name.
You will end up with app\app.exe under the Installer dir.This is a one
file .exe containing all the application.
If you don't want a one-file build, suppress the option --onefile
above.
If you don't have upx installed (or don't want to use it), suppress the
option --upx above.
The option --noconsole is needed to produce a windows gui application,
instead of a console one (so the command shell won't pop up when you
run the application).

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


Re: Kross - Start of a Unified Scripting Approach

2006-04-13 Thread Jerry
So, this would be like .Net or Mono, but for KOffice?  Kind of like
AppleScript then?

Sorry, just starting to learn about some of this stuff (CLI, CLR, CIL,
etc...) and am interested in understanding better.

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


Re: PEP 359: The "make" Statement

2006-04-13 Thread Felipe Almeida Lessa
Em Qui, 2006-04-13 às 23:17 -0400, Nicolas Fleury escreveu:
> The callable could have something like a __namespacetype__ that could be 
> use instead of dict.  That type would have to implement __setitem__.

Or the namespace variable could be a list of tuples.

-- 
Felipe.

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

Re: PEP 359: The "make" Statement

2006-04-13 Thread Nicolas Fleury
Steven Bethard wrote:
> Ok, I finally have a PEP number.  Here's the most updated version of the 
> "make" statement PEP.  I'll be posting it shortly to python-dev.
> 
> Thanks again for the previous discussion and suggestions!

I find it very interesting.

My only complaint is that it is limited to things that can be described 
as a namespace, where the order of declaration is lost.  This problem is 
also true with metaclasses, but it is more acceptable since they are for 
classes.

For example, it would be nice to use such a feature to define C 
structures that are to be exported in a binary format without having to 
use a hidden counter or other hacks.  I have no idea of the 
implementation implications, but it would be nice to have the capability 
to override the namespace type to use something else than dict, so that 
it can be filled with symbols one statement at a time.

The callable could have something like a __namespacetype__ that could be 
use instead of dict.  That type would have to implement __setitem__.

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


Re: namespace issue

2006-04-13 Thread Steven D'Aprano
On Thu, 13 Apr 2006 22:59:52 +0200, Daniel Nogradi wrote:

> I would like to give the same name to a keyword argument of a class
> method as the name of a function, with the function and the class
> living in the same namespace and the class method using the
> aforementioned function. 

That's a problem right there. As soon as you find yourself needing to
distinguish between "great_name the function" and "great_name the
argument", you have a potential source of API confusion, no matter how
great the name is.

But if you absolutely must:

def _gn(x):
return x.upper()

great_name = _gn

class myclass:
def mymethod(self, great_name=False):
if great_name:
return _gn('something')
else:
return 'something'




-- 
Steven.

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


Re: Remove Whitespace

2006-04-13 Thread Martin Blais
On 13 Apr 2006 12:32:56 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> re.sub() doesn't do the substitution in place: it returns the resulting
> string. Try this:

In-place substitution is impossible in Python, strings are immutable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remove Whitespace

2006-04-13 Thread Felipe Almeida Lessa
Em Sex, 2006-04-14 às 12:46 +1000, Steven D'Aprano escreveu:
> Why would you want to call in the heavy sledgehammer of regular
> expressions for cracking this peanut?

And put heavy on that!

$ python2.4 -mtimeit -s "str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6
4 0'" 'str.replace(" ", "")'
10 loops, best of 3: 3.07 usec per loop
$ python2.4 -mtimeit -s "str = 'D c a V e r \" = d w o r d : 0 0 0 0 0 6
4 0'" '"".join(str.split())'
10 loops, best of 3: 4.16 usec per loop
$ python2.4 -mtimeit -s "from re import sub; str = 'D c a V e r \" = d w
o r d : 0 0 0 0 0 6 4 0'" 'sub("\\s", "", str)'
1 loops, best of 3: 23.6 usec per loop
$ calc 23.6 / 3.07
~7.68729641693811074919

I couldn't be expressed better:

"Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems."
  — Jamie Zawinski, in comp.lang.emacs

-- 
Felipe.

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

Re: How to create a single executable console application?

2006-04-13 Thread Podi
Alright, pythoneers, here is what I have found from
http://wiki.wxpython.org/index.cgi/CreatingStandaloneExecutables. This
is much easier than the py2exe + nullsoft combo :)

Cheers!

The mcillian installer development is discontinued.

mirror:
http://davidf.sjsoft.com/mirrors/mcmillan-inc/installer_dnld.html

Continued development(not tested yet):
http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi

This works on Win32.
Unzip the Installer in a directory of your choice, and cd there.

Configure the Installer by running:

python Configure.py

Python must be in your PATH for this to work, if it's not, type from
the command prompt: PATH=%PATH%;c:\python23

where c:\python23 must be replaced with the root of your python
installation.
Then, assuming the source code is app.py (placed in c:\source): python
Makespec.py --upx --onefile --noconsole c:\source\app.py
python Build.py  app\app.spec

Replace 'app' everywhere above with your application name.
You will end up with app\app.exe under the Installer dir.This is a one
file .exe containing all the application.
If you don't want a one-file build, suppress the option --onefile
above.
If you don't have upx installed (or don't want to use it), suppress the
option --upx above.
The option --noconsole is needed to produce a windows gui application,
instead of a console one (so the command shell won't pop up when you
run the application).

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


Re: PEP 359: The "make" Statement

2006-04-13 Thread Steven D'Aprano
On Thu, 13 Apr 2006 13:39:14 -0700, gangesmaster wrote:

> "make type" is uber leet

So you're against it then?


-- 
Steven.

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


Weekly Python Patch/Bug Summary

2006-04-13 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  383 open ( -8) /  3156 closed (+14) /  3539 total ( +6)
Bugs:  886 open (-12) /  5759 closed (+28) /  6645 total (+16)
RFE :  210 open ( -5) /   212 closed ( +5) /   422 total ( +0)

New / Reopened Patches
__

socket.py: remove misleading comment  (2006-04-08)
CLOSED http://python.org/sf/1466993  opened by  John J Lee

Many functions in socket module are not thread safe  (2006-04-09)
   http://python.org/sf/1467080  opened by  Maxim Sobolev

fix double free with tqs in standard build  (2006-04-09)
CLOSED http://python.org/sf/1467512  opened by  Neal Norwitz

add Popen objects to _active only in __del__,   (2006-04-10)
CLOSED http://python.org/sf/1467770  opened by  cheops

tkFont: simple fix to error at shutdown  (2006-04-11)
CLOSED http://python.org/sf/1468808  opened by  Russell Owen

Make -tt the default  (2006-04-12)
   http://python.org/sf/1469190  opened by  Thomas Wouters

PyErrr_Display and traceback.format_exception_only behaviour  (2003-12-15)
CLOSED http://python.org/sf/860326  reopened by  tim_one

Alternative to rev 45325  (2006-04-12)
   http://python.org/sf/1469594  opened by  Skip Montanaro

Alternative to rev 45325  (2006-04-12)
   http://python.org/sf/1469594  reopened by  montanaro

Patches Closed
__

socket.py: remove misleading comment  (2006-04-08)
   http://python.org/sf/1466993  closed by  gbrandl

Use dlopen() to load extensions on Darwin, where possible  (2006-03-21)
   http://python.org/sf/1454844  closed by  anthonybaxter

Improved generator finalization  (2006-04-03)
   http://python.org/sf/1463867  closed by  pje

"const int" was truncated to "char"  (2006-03-31)
   http://python.org/sf/1461822  closed by  ocean-city

Mutable Iterators PEP  (03/26/06)
   http://python.org/sf/1459011  closed by  sf-robot

fix double free with tqs in standard build  (2006-04-09)
   http://python.org/sf/1467512  closed by  nnorwitz

clean up new calendar locale usage  (2006-04-03)
   http://python.org/sf/1463288  closed by  doerwalter

Functioning Tix.Grid  (2006-03-31)
   http://python.org/sf/146  closed by  loewis

Link Python modules to libpython on linux if --enable-shared  (2006-02-11)
   http://python.org/sf/1429775  closed by  loewis

add Popen objects to _active only in __del__,   (2006-04-10)
   http://python.org/sf/1467770  closed by  loewis

subprocess: optional auto-reaping fixing os.wait() lossage  (2005-04-21)
   http://python.org/sf/1187312  closed by  loewis

tkFont: simple fix to error at shutdown  (2006-04-11)
   http://python.org/sf/1468808  closed by  gbrandl

PEP 343 draft documentation  (2005-07-07)
   http://python.org/sf/1234057  closed by  ncoghlan

PyErrr_Display and traceback.format_exception_only behaviour  (2003-12-15)
   http://python.org/sf/860326  closed by  gbrandl

Alternative to rev 45325  (2006-04-12)
   http://python.org/sf/1469594  closed by  montanaro

832799 proposed changes  (2003-11-25)
   http://python.org/sf/849262  closed by  loewis

Updated Demo\parser\unpack.py  (2006-03-02)
   http://python.org/sf/1441452  closed by  loewis

New / Reopened Bugs
___

size_t warnings on OSX 10.3  (2006-04-09)
   http://python.org/sf/1467201  opened by  Anthony Baxter

open should default to binary mode on windows  (2006-04-09)
CLOSED http://python.org/sf/1467309  opened by  Adam Hupp

test_ctypes fails on OSX 10.3  (2006-04-10)
   http://python.org/sf/1467450  opened by  Anthony Baxter

Header.decode_header eats up spaces  (2006-04-10)
   http://python.org/sf/1467619  opened by  Mathieu Goutelle

%-formatting and dicts  (2006-04-10)
   http://python.org/sf/1467929  opened by  M.-A. Lemburg

os.listdir on Linux returns empty list on some errors  (2006-04-10)
CLOSED http://python.org/sf/1467952  opened by  Gary Stiehr

re incompatibility in sre  (2000-09-11)
   http://python.org/sf/214033  reopened by  tmick

Hitting CTRL-C while in a loop closes IDLE on cygwin  (2006-04-11)
   http://python.org/sf/1468223  opened by  Miki Tebeka

test_grp test_pwd fail on Linux  (2006-04-11)
CLOSED http://python.org/sf/1468231  opened by  Miki Tebeka

Possible Integer overflow  (2006-04-11)
CLOSED http://python.org/sf/1468727  opened by  ekellinis

SimpleXMLRPCServer doesn't work anymore on Windows  (2006-04-12)
CLOSED http://python.org/sf/1469163  opened by  kadeko

Exception when handling http response  (2006-04-12)
CLOSED http://python.org/sf/1469498  opened by  Richard Kasperski

Build requires already built Python  (2006-04-12)
CLOSED http://python.org/sf/1469548  opened by  Stephan R.A. Deibel

FTP modue functions are not re-entrant,give odd exceptions  (2006-04-12)
   http://python.org/sf/1469557  opened by  Bruce

__dict__   (2006-04-13)
   http://python.org/sf/1469629  opened by  Dobes V

distutils.core: link to list of Trove classifiers  (2006-04-13)
 

Re: Remove Whitespace

2006-04-13 Thread Steven D'Aprano
On Thu, 13 Apr 2006 12:09:32 -0700, Kelvie Wong wrote:

> try this:
> 
> string = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
> import re
> re.sub("\s", "", string)

Why would you want to call in the heavy sledgehammer of regular
expressions for cracking this peanut?

old_s = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'  
new_s = old_s.replace(" ", "")

And if you want to remove all whitespace:

new_s = "".join(old_s.split())



-- 
Steven.

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


setup.py on unix/linux and converting to windows

2006-04-13 Thread AIM
Hi all,

I have a general question and some advice is needed.

Over time, I am running into python modules with setups that are just
made for linux/unix.

I have python installed on windows.  To get these modules into windows,
should I do the following?

(1) Install cygwin.

(2) compile/setup the python modules in the cygwin enviroment.

(3) Copy the new (installed) files to my python on windows environment
(specifically and most likely the site-packages directory.

What do you think about this?

In most cases will this work?

In what cases will this not work?  Sometimes threading will not work?

Thank you very much.

AIM

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


Re: Kross - Start of a Unified Scripting Approach

2006-04-13 Thread Alex Martelli
RM <[EMAIL PROTECTED]> wrote:

> This is from the new KOffice Announcement.
> 
> http://www.koffice.org/announcements/announce-1.5.php
> 
> '''This version of KOffice features a start of a unified scripting
> solution called Kross. Kross provides cross-language support for
> scripting (thus its name) and at present supports Python and Ruby.
> 
> Kross is easy to include into programs previously lacking scripting
> abilities, and is included in this version as a technology preview. So
> far, only Krita and Kexi are improved by means of the Kross engine.We
> would also like to point out that the API might change in the future
> and expect Kross to be fully integrated into KOffice version 2.0.'''
> 
> Interesting isn't it?

An absolutely exellent idea. Most of the potential issues are with the
details (that's where the devil is, right?-)... can't check it out right
now (vacationing in the Grand Canyon, very occasional net access), but
I plan to do so when I'm back home next week!


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


Re: print without newline "halts" program execution

2006-04-13 Thread Jay Parlar

On Apr 13, 2006, at 5:57 PM, Karlo Lozovina wrote:

> Consider this short script:
>
> ---
> from time import time, sleep
>
> st = time()
> print 'Start: %f, ' % st,
> sleep(10)
> sp = time()
> print 'Stop: %f, Duration: %f' % (sp, (st - sp))
> ---
>
> On my environment (Linux, py24), when run, Python first waits 10s, and
> then produces the entire output. How, can I make it print first part
> ('Start: %f, '), then wait 10s, and then append (WITHOUT NEWLINE) that
> second print statement?
>
> I'm writting a script with lot of output which has to go on the same 
> line,
> but I don't want to wait for it to end to see output, I just want it to
> print parts as it's finished with them.
>
> Using sys.stdout.write() produces the same behavior, so what can I do?
> from time import time, sleep
>
>

Your problem is that the 'print' statement is sending the text to 
sys.stdout, and sys.stdout is buffered.

There are other ways to do this, but try this:

from time import time, sleep
import sys

st = time()
print 'Start: %f,'% st,
sys.stdout.flush()
sleep(10)
sp = time()
print 'Stop: %f, Duration: %f' % (sp, (st-sp))


Jay P.

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


print without newline "halts" program execution

2006-04-13 Thread Karlo Lozovina
Consider this short script:

---
from time import time, sleep

st = time()
print 'Start: %f, ' % st,
sleep(10)
sp = time()
print 'Stop: %f, Duration: %f' % (sp, (st - sp))
---

On my environment (Linux, py24), when run, Python first waits 10s, and 
then produces the entire output. How, can I make it print first part 
('Start: %f, '), then wait 10s, and then append (WITHOUT NEWLINE) that 
second print statement?

I'm writting a script with lot of output which has to go on the same line, 
but I don't want to wait for it to end to see output, I just want it to 
print parts as it's finished with them.

Using sys.stdout.write() produces the same behavior, so what can I do?

Thanks a lot in advance.

-- 
 ___Karlo Lozovina - Mosor
|   |   |.-.-. web: http://www.mosor.net || ICQ#: 10667163
|   ||  _  |  _  | Parce mihi domine quia Dalmata sum.
|__|_|__||_|_|
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forms with multiple submit buttons vs 'form' objects with single 'submit' methods

2006-04-13 Thread Paul Rubin
[EMAIL PROTECTED] writes:
>   Here's my question:  Suppose a form has more than one submit button.
> Now the COM 'form' object has a 'submit' method that doesn't take any
> arguments, so how do I tell it which button I want to press?

What difference does it make?  Don't they all do the same thing?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace issue

2006-04-13 Thread Steven Bethard
Daniel Nogradi wrote:
> I would like to give the same name to a keyword argument of a class
> method as the name of a function, with the function and the class
> living in the same namespace and the class method using the
> aforementioned function. So far I've been unsuccesfully trying to go
> along these lines:
> 
> def great_name( x ):
> return x.upper( )
> 
> class myclass:
> def mymethod( self, great_name=False ):
> if great_name:
> return great_name( 'something' )
> else:
> return 'something'
> 

 >>> def great_name(x):
... return x.upper()
...
 >>> class myclass(object):
... def mymethod(self, great_name=False):
... if great_name:
... return globals()['great_name']('something')
... else:
... return 'something'
...
 >>> myclass().mymethod()
'something'
 >>> myclass().mymethod(True)
'SOMETHING'


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


Socket Error: Connection Refused

2006-04-13 Thread niceyama
Dear c.l.p,

I have recently been doing the tutorial of Python and everything is
well, i'm upto the pass section. Anyway, when I try to launch idle now
I get the error message: Socket Error: Connection Refused. I do not
have a firewall, so I don't know what is going on. Also, this comes up
after it:

IDLE's subprocess didn't make the connection. Either IDLE can't start a
subprocess or personal firewall software is blocking the connection.

[OK]


Any help would be appreciate.

Yamas

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


telnet read_sb_data

2006-04-13 Thread Arne
Hello!

Task: Connecting to a unix server and getting the directory list .
OS: XP

Connecting to the server via telnet is no problem.
I also want to get the directory list. I know by using read_all I can get 
all the output (starting from the login up to the end).
1. What I look for is the option to get only certain parts of the output. It 
seems to me that the command "read_sb_data" can do this. The documentation 
says, that I will get the data between the SB/SE pair. But I don't know how 
to invoke the SE command in Unix. Even I don't know the SE command.

2. I thing when this command work I can also get the directory size for each 
directory in root (using df and du Unix commands)
Using os.stat(path) doesen't work on XP, I am always getting a 0 return 
(i.e. (16895, 0L, 3, 1, 0, 0, 0L, 315529200, 315529200, 315529200))

Please be so kind and post a little bit of a code.

Thanks a lot!
Arne


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


BSTR

2006-04-13 Thread Aleksandar Cikota
Hi all,

I'm beginner in Python and need help. I'm writing software for a robotic 
telescope. For CCD camera control we use MaxIm DL (Diffraction Limited). I 
have a problem with CCDCamera.SaveImage.

Error message:
>File "S:MaxImmaxim.py", line 19, in ?
>  CCDCamera.SaveImage('C:/1.fit')
>File "C:ProgrammePython24Libsite-
> packageswin32comclientdynamic.py", line 491, in __getattr__
>  raise pythoncom.com_error, details
> com_error: (-2147352567, 'Ausnahmefehler aufgetreten.',
> (65535, 'MaxIm DL 4', 'Invalid Input', None, 0, 0), None)


Here is the answer that we recieved from Diffraction Limited:
-
For CCDCamera.SaveImage, 'Invalid Input' is reported only if the argument is
not of an acceptable type.  As you are probably aware from looking at the
type library, the filename argument is declared as a variant.  What the type
library doesn't tell you is that the variant must be either a BSTR (unicode
string with header) or a reference to a BSTR.  Specifically, the 'vt' member
of the VARIANT must be either VT_BSTR or VT_BSTR|VT_BYREF.

Does python provide any way of influencing how arguments for COM methods are
created?  If so, you may be able to get this to work.  It may be as simple
as assigning the string to a variable name instead of passing it as a
literal, or perhaps there's something equivalent to a C++ cast operator or a
VB 'type' function (CInt, CStr, etc.).

This problem is likely to affect any MaxIm DL automation method that takes a
string as an argument.
-


Here is the code (Python):

import win32com.client, time
CCDCamera = win32com.client.Dispatch('MaxIm.CCDCamera')
CCDCamera.LinkEnabled = True
if CCDCamera.LinkEnabled == False:
 print 'Failed to start camera.'
exp = int(raw_input('Exposition[sec]: '))
CCDCamera.Expose(exp, 1, 0)
while CCDCamera.ImageReady == False:
 time.sleep
print 'Done'
time.sleep(3)
CCDCamera.SaveImage('C:/1.fit')



The question is, how to convert a String in a BSTR (unicodestring with 
header)?


For your prompt reply, I say thank you in advance.



Best regards,

Aleksandar Cikota


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


Buffer.so,oci.so compilation for DCoracle

2006-04-13 Thread tksri2000
I am trying to compile Buffer.so for oracle 10g. This is as part of
DCoracle installation.

I am following the instructions under src/README.txt.


ORACLE_PATH=.:/opt/oracle/product/10.2.0/bin

Python 2.4.3 (#2, Apr 10 2006, 13:02:28)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-53)] on linux2

I get the follwing error:

make
gcc -pthread -fPIC -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-I/users/sk616655/usr/local/include/python2.4
-I/users/sk616655/usr/local/include/python2.4 @DEFS@
-I/opt/oracle/product/10.2.0/rdbms/demo
-I/opt/oracle/product/10.2.0/network/public
-I/opt/oracle/product/10.2.0/plsql/public -DDCORACLE8 -c ././oci_.c -o
./oci_.o
gcc: cannot specify -o with -c or -S and multiple compilations
*** Error code 1
clearmake: Error: Build script failed for "oci_.o"

zsh: exit 1 clearmake


Help please.

sri

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


Re: List comp bug?

2006-04-13 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>   [f() for f in [lambda: t for t in ((1, 2), (3, 4))]]
> is giving me
>   [(3, 4), (3, 4)]
>
> The equivalent using a generator expression:

List comps were originally designed to be equivalent to for loops with 
nested for loops and if blocks.  Generator expressions are know to be 
slightly different and *not* exactly equivalent due to the new local 
namespace.

>[f() for f in (lambda: t for t in ((1, 2), (3, 4)))]
> is giving me
>[(1, 2), (3, 4)]

Since, when there is a difference, as above, the genex behavior is more 
often the right or expected behavior (as above), Guido is considering 
making the diference go away in 3.0 by making [stuff] == list((stuff)) (ie, 
listcomp == list(genex)).

Terry Jan Reedy 



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


Building Python with the free MS Toolkit compiler

2006-04-13 Thread Paul Moore
I've just added some instructions on how to build Python on Windows
with the free MS Toolkit C++ compiler. They are at
http://wiki.python.org/moin/Building_Python_with_the_free_MS_C_Toolkit.

Most of the credit for this goes to David Murmann, whose posting on
the subject to python-list pointed out the existence of Nant, a free
tool which will read Visual Studio solution files, and inspired me to
see if I could get the process to work.

If anyone finds any problems with the instructions given there, feel
free to let me know (or better still, update the page with your
correction!)

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


Re: namespace issue

2006-04-13 Thread Daniel Nogradi
Ooops, there was a typo in my previous mail:

> in the hope of the del statement only removing the local variable util
  
   ^
the above line should be:

in the hope of the del statement only removing the local variable great_name
  
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forms with multiple submit buttons vs 'form' objects with single 'submit' methods

2006-04-13 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all,
>
>   I'm using pywin to write a script that will commandeer internet
> explorer to go to a certain website, where it will navigate menus, post
> forms, and eventually retrieve certain data.
>
>   Here's my question:  Suppose a form has more than one submit button.
> Now the COM 'form' object has a 'submit' method that doesn't take any
> arguments, so how do I tell it which button I want to press?
>
>   I'll be *unbelievably* grateful, for the rest of my natural life, to
> whomever has the answer to this.
>
>   (Yeah, I realize it's more of a COM question than a Python question.
> If you know of a more suitable group, or a website where such questions
> are dealth with then by all means redirect me.  I'll be exceedingly
> grateful, though perhaps not for the rest of my natural life.)
>
> Neil
>

Perhaps instead of trying to contort IE to your will, you might take a look
at twill.  I think it will do what you need in a much less roundabout way.

-- Paul


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


Re: Python editing with emacs/wordstar key bindings.

2006-04-13 Thread Carl Banks
Thomas Bartkus wrote:
> I do notice that I can invoke wordstar-mode *after* loading the .py file and
> get the whole enchilada.  The Wordstar key bindings with the syntax
> highlighting.
> It just strikes me as odd that key bindings should be reasserted by invoking
> python-mode.

Ah--you're only thinking of syntax highlighting.  Now it makes sense.

Try putting these lines in your .emacs:

(defun use-wordstar-for-python () (wordstar-mode))
(add-hook 'python-mode-hook 'use-wordstar-for-python)

There might be a "right" way to get syntax highlighting without setting
the major mode (if not, there ought to be), but this should do the
trick for you.


Carl Banks

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


Re: Forms with multiple submit buttons vs 'form' objects with single 'submit' methods

2006-04-13 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all,
>
>   I'm using pywin to write a script that will commandeer internet
> explorer to go to a certain website, where it will navigate menus, post
> forms, and eventually retrieve certain data.
>
>   Here's my question:  Suppose a form has more than one submit button.
> Now the COM 'form' object has a 'submit' method that doesn't take any
> arguments, so how do I tell it which button I want to press?
>
>   I'll be *unbelievably* grateful, for the rest of my natural life, to
> whomever has the answer to this.
>
>   (Yeah, I realize it's more of a COM question than a Python question.
> If you know of a more suitable group, or a website where such questions
> are dealth with then by all means redirect me.  I'll be exceedingly
> grateful, though perhaps not for the rest of my natural life.)
>
> Neil
>

Perhaps instead of trying to contort IE to y


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


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Erik Max Francis
Ben Sizer wrote:

> Why is Wikipedia being abused for software promotion and documentation?
> Articles on Wikipedia are supposed to be from a neutral point of view
> and purely informative, not biased or instructive.

Because it's Wikipedia?  This kind of garbage is the inevitable result 
of an "encyclopedia" which anyone can edit.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Sitting in the den and / Looking at the phone as if it owed / Owed me
   a favor -- Blu Cantrell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python editing with emacs/wordstar key bindings.

2006-04-13 Thread John J. Lee
"Carl Banks" <[EMAIL PROTECTED]> writes:
[...]
> >1) When I load a .py file, emacs automatically overrides my wordstar-mode
> > with python-mode, forcing all the keybindings back to emacs native keys.
> > Why?
[...]
> Python and wordstar are both major modes.  When python-mode is loaded,
> it replaces (not sits atop of) wordstar-mode; you can't have two major
> modes loaded at the same time.

Oh, of course -- didn't occur to me that wordstar-mode might be a
major mode.

Thomas, why not simply use the standard emacs provisions for key
rebinding?  Or are the wordstar keys modal or otherwise difficult to
implement that way, as is the case with vi bindings? (but viper does a
great job of that -- I'm using it right now)


[...]
> > Is there a better python-mode script I should be using other than the
> > default that came with emacs?
> 
> I doubt there's one that solves your problem.

Carl is right: changing python-mode is the wrong end to approach this
problem.  Change the keybindings instead.

Like I said, if you're stuck rebinding the keys, try one of the emacs
mailing lists / newsgroups.  Thanks to the kind help of such people
I've been getting away with scandalously little knowledge of my own
.emacs for years, and only just now learning a little elisp. :-)


John

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


namespace issue

2006-04-13 Thread Daniel Nogradi
I would like to give the same name to a keyword argument of a class
method as the name of a function, with the function and the class
living in the same namespace and the class method using the
aforementioned function. So far I've been unsuccesfully trying to go
along these lines:

def great_name( x ):
return x.upper( )

class myclass:
def mymethod( self, great_name=False ):
if great_name:
return great_name( 'something' )
else:
return 'something'

This would fail, because in the namespace of mymethod great_name is a
local variable and is not a callable. So I tried to modify the class
like this:

class myclass:
def mymethod( self, great_name=False ):
great_name_ = great_name
del great_name
if great_name_:
return great_name( 'something' )
else:
return 'something'

in the hope of the del statement only removing the local variable util
but still remembering the great_name function from outside, but this
didn't work either. So my question is if it was possible to do this at
all?

The reason for giving the same name is a usability issue of my module,
I would like both the keyword argument and the function to be visible
by the user and the name I would like to give them describes very well
what they are doing. That is also the reason why I don't want to hide
the great_name function in the class as a method.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to grasp OO : newbie Q?

2006-04-13 Thread BartlebyScrivener
Pretty tough to beat Alan Gauld, but the more examples the merrier for
me, and the infogami has plenty of those. Thanks.

http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm

rpd

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


Re: PEP 359: The "make" Statement

2006-04-13 Thread gangesmaster
"make type" is uber leet

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


ANN: Python cgkit v2.0.0alpha6 & Maya Python package

2006-04-13 Thread Matthias Baas
The sixth alpha release of version 2 of the Python Computer Graphics
Kit is available at http://cgkit.sourceforge.net

This release also comes with a "preview" version of a Maya Python
package that integrates Python into the 3D tool Maya.


What is it?
---

The Python Computer Graphics Kit is a generic 3D package written in
C++ and Python that can be used for a variety of domains such as
scientific visualization, photorealistic rendering, Virtual Reality or
even games. The package contains a number of generic modules that can
be useful for any application that processes 3D data. This includes
new types such as vectors, matrices and quaternions. Furthermore, the
package can read and store 3D models in memory where they can be
manipulated by Python programs. The kit comes with tools that can be
used to display the scene either interactively or by rendering it
offline via a RenderMan renderer.


What's new?
---

- Smoother compilation under OSX

- Some new modules like "glslangparams" to read shader parameters from
an OpenGL 2 shader source file and "hammersley" to generate Hammersley
and Halton points.

- Initial support for Lightwave LWOB files.

- + more bugfixes and enhancements (see the changelog).


Windows binary versions are available for Python 2.3 - 2.5.


For more information, visit:

http://cgkit.sourceforge.net


Feedback is most welcome...

- Matthias -


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


Re: Forms with multiple submit buttons vs 'form' objects with single 'submit' methods

2006-04-13 Thread Tim Williams (gmail)
On 13 Apr 2006 12:26:52 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:Hi all,  I'm using pywin to write a script that will commandeer internet
explorer to go to a certain website, where it will navigate menus, postforms, and eventually retrieve certain data.  Here's my question:  Suppose a form has more than one submit button.Now the COM 'form' object has a 'submit' method that doesn't take any
arguments, so how do I tell it which button I want to press?  I'll be *unbelievably* grateful, for the rest of my natural life, towhomever has the answer to this.
Have a look at ishy_browser,  its in 2 parts at

http://www.ishpeck.net/index.php?P=b1115239318ishpeck

http://www.ishpeck.net/index.php?P=b1115225809ishpeck
HTH :)
-- 
http://mail.python.org/mailman/listinfo/python-list

Announce: Construct's wiki!

2006-04-13 Thread gangesmaster
finally, i opened a wiki for Construct, the "parsing made fun" library.

the project's page: http://pyconstruct.sourceforge.net/
the project's wiki: http://pyconstruct.wikispaces.com/ (anyone can
edit)

so now we have one place where people can share inventory constructs,
questions-and-answers, patches, documentation and more. enjoy.


-tomer

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


Re: function prototyping?

2006-04-13 Thread Burton Samograd
bruno at modulix <[EMAIL PROTECTED]> writes:

> Burton Samograd wrote:
> > "infidel" <[EMAIL PROTECTED]> writes:
> > I'm a C programmer, so I'm doing it in a bit of a C like way;
> > prototype the function, initalize the array using the prototypes, have
> > the functions defined somewhere else and then let the linker work it
> > all out for me.  I was hoping that python had some sort of lazy
> > evaluation scheme for this type of behaviour so that you could defer
> > linkage (or variable evalutation) until runtime, or at least variable
> > reference (through the use of thunks or some sort).  Maybe I was
> > hoping for too much :)
> 
> It's not a problem of "hoping for too much", but a problem of paradigm
> shift. You're actually *thinking* in C, and Python is a *completely
> different* language. You just can't directly transpose C idioms in
> Python - nor could you transpose much Python idioms in C. So you need to
> 'go down a level' and consider the real problem and how to solve it the
> Python way - not how to implement the C-ish solution in Python.

To be honest, I'm trying to do it in a more 'lispish' way (as in emacs
lisp) where the configuration file is written in the implementation
langugage.  Just an interesting experiement really to see if it would
work.  It's been a year and a half since I really used python last so
I'm just getting back up to speed with the idioms so I expect to make
a few mistakes along the way.

Thanks for the help.

-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remove Whitespace

2006-04-13 Thread Jay Parlar

On Apr 13, 2006, at 12:09 PM, Kelvie Wong wrote:

> try this:
>
> string = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
> import re
> re.sub("\s", "", string)
>
> On 4/13/06, david brochu jr <[EMAIL PROTECTED]> wrote:
>

Even easier (if you only want to replace blank spaces, and not all 
whitespace):

string = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
string.replace(" ", "")

Note to the original poster: It's a *bad* idea to call a variable 
'string', as there's already a module in the standard library called 
'string'.

Jay P.

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


Re: Remove Whitespace

2006-04-13 Thread [EMAIL PROTECTED]
re.sub() doesn't do the substitution in place: it returns the resulting
string. Try this:

myString = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
import re 
newString = re.sub("\s", "", myString) 
print newString

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


Forms with multiple submit buttons vs 'form' objects with single 'submit' methods

2006-04-13 Thread neil . fitzgerald
Hi all,

  I'm using pywin to write a script that will commandeer internet
explorer to go to a certain website, where it will navigate menus, post
forms, and eventually retrieve certain data.

  Here's my question:  Suppose a form has more than one submit button.
Now the COM 'form' object has a 'submit' method that doesn't take any
arguments, so how do I tell it which button I want to press?

  I'll be *unbelievably* grateful, for the rest of my natural life, to
whomever has the answer to this.

  (Yeah, I realize it's more of a COM question than a Python question.
If you know of a more suitable group, or a website where such questions
are dealth with then by all means redirect me.  I'll be exceedingly
grateful, though perhaps not for the rest of my natural life.)

Neil

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


Re: function prototyping?

2006-04-13 Thread Peter Otten
Burton Samograd wrote:

> Duncan Booth <[EMAIL PROTECTED]> writes:
> 
>> Burton Samograd wrote:
>> > Is there any way to 'prototype' functions in python, as you would in
>> > C?  Would that be what the 'global' keyword is for, or is there a more
>> > elegant or 'pythonic' way of doing forward references?
>> > 
>> There isn't really such a thing as a forward reference in Python. Always
>> remember that 'def' and 'class' are executable statements:
> 
> Ok, we'll here's what I'm trying to do.  I have a dictionary that I
> would like to initialize in a module file config.py:
> 
> -- config.py -
> global a_fun, b_fun
> dict = {
> 'a': a_fun,
> 'b': b_fun
> }
> --
> 
> where a_fun and b_fun are in fun.py:
> 
> -- fun.py 
> def a_fun(): pass
> def b_fun(): pass
> 
> import config
> def main():
> config.dict['a']()
> config.dict['b']()
> main()
> --
> 
> I like having the module/namespace seperation with the configuration
> variables but I would like to make them easily (re)defined in the
> configuration file by the user.  Does python have the idea of a 'weak'
> reference or lazy style evaluation for the definition of the dict in
> the config file above so I can achive what i'm tryin to do?

I'd say Python has *only* that idea, but as a practical approach the
following might be easiest:

-- config.py --
a = a_fun # As a_fun is nowhere defined, config.py cannot be
  # used stand-alone and may be hard to test.
b = b_fun
def c():
print "c-fun"

-- fun.py --
def a_fun(): print "a-fun"
def b_fun(): print "b-fun"

execfile("config.py") # Think #include 

def main():
a()
b()
c()

if __name__ == "__main__":
main()

A slightly stricter variant avoids cycles by using three modules:

-- fun.py --
def a_fun(): print "a-fun"
def b_fun(): print "b-fun"

-- config.py --
import fun

a = fun.a_fun
b = fun.b_fun

-- main.py --
import config

def main():
config.a()
config.b()

if __name__ == "__main__":
main()

Thanks to the if... guard you could put the main.py code into fun.py, too,
but I suppose it's easier to understand with three files.

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


Re: Looking for thoughts on PyMPI

2006-04-13 Thread M�ta-MCI
Hi!

And a small glance on Candygram (http://candygram.sourceforge.net/) can be 
funny...

@-salutations
-- 
Michel Claveau



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


Re: Remove Whitespace

2006-04-13 Thread Kelvie Wong
try this:

string = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
import re
re.sub("\s", "", string)

On 4/13/06, david brochu jr <[EMAIL PROTECTED]> wrote:
>
> Hi again,
>
> Trying to remove whitespace from a string in a text file.
>
> the string is:
> D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0
>
> how would i go about doing this?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: just one more question about the python challenge

2006-04-13 Thread Jerry
John,

If you are really frustrated with this one (like I was on 14), email me
off-list to get further hints.  I'm willing to help you out.

I wish that someone was around to help me work through some of these.
I really think they are more fun/helpful when you work on them with
another person so if you don't see something in the riddle, they just
might.  For me, this is more about learning python than about solving
the riddles.

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


Re: trying to grasp OO : newbie Q?

2006-04-13 Thread Kent Johnson
John Salerno wrote:
> Couldn't we also say that this issue of namespace scope is a little more 
> specific to Python than OOP in general? I could very easily be wrong, 
> but I wouldn't want the poster to think that this is how OOP works always.

No, the confusion in the OP was between class attributes, instance 
attributes and local variables. This distinction is pretty fundamental 
to OOP.

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


Remove Whitespace

2006-04-13 Thread david brochu jr
Hi again,
 
Trying to remove whitespace from a string in a text file.
 
the string is:
D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0
 
how would i go about doing this?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: function prototyping?

2006-04-13 Thread bruno at modulix
Burton Samograd wrote:
> "infidel" <[EMAIL PROTECTED]> writes:
> 
> 
>>If you want the user to be able to (re)define them in config.py, why
>>not just define them there in the first place?  I may be wrong, but I
>>think "global" means "module level" rather than "interpreter level".
> 
> 
> That's what I'm trying to do but I'm running into problems with
> the function values, since they haven't been defined yet.  
> 
> I'm a C programmer, so I'm doing it in a bit of a C like way;
> prototype the function, initalize the array using the prototypes, have
> the functions defined somewhere else and then let the linker work it
> all out for me.  I was hoping that python had some sort of lazy
> evaluation scheme for this type of behaviour so that you could defer
> linkage (or variable evalutation) until runtime, or at least variable
> reference (through the use of thunks or some sort).  Maybe I was
> hoping for too much :)

It's not a problem of "hoping for too much", but a problem of paradigm
shift. You're actually *thinking* in C, and Python is a *completely
different* language. You just can't directly transpose C idioms in
Python - nor could you transpose much Python idioms in C. So you need to
'go down a level' and consider the real problem and how to solve it the
Python way - not how to implement the C-ish solution in Python.


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


BSTR

2006-04-13 Thread Aleksandar Cikota






 Hi all,
 
I'm beginner in Python and need help. I'm writing software for a robotic telescope. For CCD camera control we use MaxIm DL (Diffraction Limited). I have a problem with CCDCamera.SaveImage.
 
Error message:
>    File "S:MaxImmaxim.py", line 19, in ?>  CCDCamera.SaveImage('C:/1.fit')>    File "C:ProgrammePython24Libsite-> packageswin32comclientdynamic.py", line 491, in __getattr__>  raise pythoncom.com_error, details> com_error: (-2147352567, 'Ausnahmefehler aufgetreten.',> (65535, 'MaxIm DL 4', 'Invalid Input', None, 0, 0), None)
 
 
Here is the answer that we recieved from Diffraction Limited:
-
For CCDCamera.SaveImage, 'Invalid Input' is reported only if the argument isnot of an acceptable type.  As you are probably aware from looking at thetype library, the filename argument is declared as a variant.  What the typelibrary doesn't tell you is that the variant must be either a BSTR (unicodestring with header) or a reference to a BSTR.  Specifically, the 'vt' memberof the VARIANT must be either VT_BSTR or VT_BSTR|VT_BYREF.
 
Does python provide any way of influencing how arguments for COM methods arecreated?  If so, you may be able to get this to work.  It may be as simpleas assigning the string to a variable name instead of passing it as aliteral, or perhaps there's something equivalent to a C++ cast operator or aVB 'type' function (CInt, CStr, etc.).
 
This problem is likely to affect any MaxIm DL automation method that takes astring as an argument.
-
 
 
The question is, how to convert a String in a BSTR (unicodestring with header)?
 
 

For your prompt reply, I say thank you in advance.
 
Best regards,
Aleksandar Cikota
 
 







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

Re: function prototyping?

2006-04-13 Thread bruno at modulix
Burton Samograd wrote:
> bruno at modulix <[EMAIL PROTECTED]> writes:

(snip)

>>*But* is it necessary to have the main() in the same file that defines
>>a_fun and b_fun ? It's quite common (and not only in Python) to use a
>>distinct file for the main(). So you can easily solve your problem by
>>splitting fun.py into fun.py and main.py:
> 
> 
> ah yes, that might be a good idea.  I'm just hacking together a
> prototype right now and I'm thinking in C'isms still,

Yeps. Python is easy to get started with, but when it comes to idioms,
it's definitively not C.

(snip)
> 
>>> Does python have the idea of a 'weak'
>>>reference
>>
>>Yes, but that's something totally different.
> 
> 
> Care to describe?

This is in the fine manual. Look for weakref.

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


Re: function prototyping?

2006-04-13 Thread Burton Samograd
bruno at modulix <[EMAIL PROTECTED]> writes:

> Burton Samograd wrote:
> > Duncan Booth <[EMAIL PROTECTED]> writes:
>
> dont use 'dict' as an identifier, it shadows the builtin dict type.

just an example i jotted down, not real code.

> > 'a': a_fun,
> > 'b': b_fun
> > } 
> > --
> > 
> > where a_fun and b_fun are in fun.py:
> > 
> > -- fun.py 
> > def a_fun(): pass
> > def b_fun(): pass
> 
> Until this point, everything is (almost) fine. You'd just need to
> rewrite config.py so it imports a_fun and b_fun from fun.py:
> 
> #-- config.py -
> import fun
> conf = {
>  'a': fun.a_fun,
>  'b': fun.b_fun
> }
> # --
> 
> But then, we have this :
> 
> > import config
> 
> And then we have a circular import...
> 
> *But* is it necessary to have the main() in the same file that defines
> a_fun and b_fun ? It's quite common (and not only in Python) to use a
> distinct file for the main(). So you can easily solve your problem by
> splitting fun.py into fun.py and main.py:

ah yes, that might be a good idea.  I'm just hacking together a
prototype right now and I'm thinking in C'isms still, so maybe I'll
modularize it a bit more to see if that could solve the problem.  

> > I like having the module/namespace seperation with the configuration
> > variables but I would like to make them easily (re)defined in the
> > configuration file by the user.
> 
> You may want to look at one of the existing configuration modules.

I like the idea of using python as the configuration system, plus this
is giving me a good exercise with learning more of the language so I'm
going to stick with it for a bit, at least until my questions get too
annoying ;-)

> >  Does python have the idea of a 'weak'
> > reference
> 
> Yes, but that's something totally different.

Care to describe?

-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function prototyping?

2006-04-13 Thread Burton Samograd
"infidel" <[EMAIL PROTECTED]> writes:

> If you want the user to be able to (re)define them in config.py, why
> not just define them there in the first place?  I may be wrong, but I
> think "global" means "module level" rather than "interpreter level".

That's what I'm trying to do but I'm running into problems with
the function values, since they haven't been defined yet.  

I'm a C programmer, so I'm doing it in a bit of a C like way;
prototype the function, initalize the array using the prototypes, have
the functions defined somewhere else and then let the linker work it
all out for me.  I was hoping that python had some sort of lazy
evaluation scheme for this type of behaviour so that you could defer
linkage (or variable evalutation) until runtime, or at least variable
reference (through the use of thunks or some sort).  Maybe I was
hoping for too much :)

-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function prototyping?

2006-04-13 Thread infidel
If you want the user to be able to (re)define them in config.py, why
not just define them there in the first place?  I may be wrong, but I
think "global" means "module level" rather than "interpreter level".

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


Re: function prototyping?

2006-04-13 Thread bruno at modulix
Burton Samograd wrote:
> Duncan Booth <[EMAIL PROTECTED]> writes:
> 
> 
>>Burton Samograd wrote:
>>
>>>Is there any way to 'prototype' functions in python, as you would in
>>>C?  Would that be what the 'global' keyword is for, or is there a more
>>>elegant or 'pythonic' way of doing forward references?
>>>
>>
>>There isn't really such a thing as a forward reference in Python. Always 
>>remember that 'def' and 'class' are executable statements:
> 
> 
> Ok, we'll here's what I'm trying to do.  I have a dictionary that I
> would like to initialize in a module file config.py:
> 
> -- config.py -
> global a_fun, b_fun
> dict = {

dont use 'dict' as an identifier, it shadows the builtin dict type.

> 'a': a_fun,
> 'b': b_fun
> } 
> --
> 
> where a_fun and b_fun are in fun.py:
> 
> -- fun.py 
> def a_fun(): pass
> def b_fun(): pass

Until this point, everything is (almost) fine. You'd just need to
rewrite config.py so it imports a_fun and b_fun from fun.py:

#-- config.py -
import fun
conf = {
 'a': fun.a_fun,
 'b': fun.b_fun
}
# --

But then, we have this :

> import config

And then we have a circular import...

*But* is it necessary to have the main() in the same file that defines
a_fun and b_fun ? It's quite common (and not only in Python) to use a
distinct file for the main(). So you can easily solve your problem by
splitting fun.py into fun.py and main.py:

#-- main.py -
import config
def main(*args):
config.dict['a']()
config.dict['b']()

# here we have a python trick:
if __name__ == '__main__':
import sys
sys.exit(main(*sys.argv[1:])
# --


> I like having the module/namespace seperation with the configuration
> variables but I would like to make them easily (re)defined in the
> configuration file by the user.

You may want to look at one of the existing configuration modules.

>  Does python have the idea of a 'weak'
> reference

Yes, but that's something totally different.

(snip)

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


Re: Can't see the forest for the trees - when reading file, only processing first line

2006-04-13 Thread bruno at modulix
News wrote:
> Hi Everyone,
> 
> 
> The attached code creates client connections to websphere queue managers
> and then processes an inquiry against them.
> 
> The program functions when it gets options from the command line.
> 
> It also works when pulling the options from a file.
> 
> My issue is that it only processes the first line of the file.
> 
> Does anyone know why this might be the case?
> 
> The use_file() function should be returning each file line.
> 
> Any help you can provide on this would be greatly appreciated.
> 
> Thanks
> 
> 
(snip)
> 
> #
> # Read a file into a list

Hint : use docstrings for this kind of comments.

> def use_file():
>   myfile = open(options.filename)

1/ options.filename should be passed as an argument. Globals are
definitively evil and should be avoided by all means.

2/ open() may raise an error. You may (or not) want to handle this error
 here.

>   while True:
>   line=myfile.readline()
>   print line

Why this print statement ? debug ?

>   if len(line) == 0:
>   myfile.close()
>   break
>   else:
>   return line

This of course will read only the first line. The return statements
terminates execution of the function. And BTW:

>   myfile.close()  

... This will never execute.

(snip)

> if options.filename is not None:
>   line = use_file()
>   (options,args) = parser.parse_args(line.split())

Using it that way wouldn't work anyway... and may have unexpected
results, since you're overwriting the existing options object.

>   check_params()
> else:
>   check_params()


Since you call check_params() anyway, it would simpler to write it:

if options.filename is not None:
  do_someting_with_options_here()
check_params()


Now for your question:

if options.filename is not None:
  try:
f = open(options.filename)
  except IOError, e:
# stdout is for normal program outputs only,
# error messages should go to stderr
print >> sys.stderr, \
  "failed to open options file %s : %s" \
  % (options.filename, e)
sys.exit(1)
  for line in f:
# pass the existing options object in,
# so it's updated with the new args instead of
# being overwritten
options, args = parser.parse_args(line.split(), options=options)
  f.close()
  del f
check_params()

BTW, check_params() should also takes the options object as argument.
Globals are evil. Definitively. Also, and if I may suggest,
check_options() would be a better name IMVHO.

And while we're at it, you're once again in a bad case of reinventing
the SquareWheel(tm) with the usage() function - optparse takes care of this:
http://docs.python.org/lib/optparse-generating-help.html


(snip)
if options.quiet is False:
You'd better not identity test against True or False. There are lot of
expressions that evaluate to True or False in a boolen context, without
actually *being* neither the True object nor the False object.

-> if not options.quiet:


(snip)

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


Re: function prototyping?

2006-04-13 Thread Burton Samograd
Duncan Booth <[EMAIL PROTECTED]> writes:

> Burton Samograd wrote:
> > Is there any way to 'prototype' functions in python, as you would in
> > C?  Would that be what the 'global' keyword is for, or is there a more
> > elegant or 'pythonic' way of doing forward references?
> > 
> There isn't really such a thing as a forward reference in Python. Always 
> remember that 'def' and 'class' are executable statements:

Ok, we'll here's what I'm trying to do.  I have a dictionary that I
would like to initialize in a module file config.py:

-- config.py -
global a_fun, b_fun
dict = {
'a': a_fun,
'b': b_fun
} 
--

where a_fun and b_fun are in fun.py:

-- fun.py 
def a_fun(): pass
def b_fun(): pass

import config
def main():
config.dict['a']()
config.dict['b']()
main()
--

I like having the module/namespace seperation with the configuration
variables but I would like to make them easily (re)defined in the
configuration file by the user.  Does python have the idea of a 'weak'
reference or lazy style evaluation for the definition of the dict in
the config file above so I can achive what i'm tryin to do?  


-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list.clear() missing?!?

2006-04-13 Thread Raymond Hettinger
[Dan Christensen]
> It's true that this runs at the same speed as the del variants on my
> machine.  That's not too surprising to me, but I still don't
> understand why the del variants are more than 5% faster than the first
> version.

Understanding it involves looking at implementation specific details
such as the overallocation scheme for growing lists and the performance
of your machine's underlying memory allocator.


> Once this is understood, is it something that could be optimized?
> It's pretty common to rebind a variable to a new value, and if
> this could be improved 5%, that would be cool.

Sorry, that's not how the language works.  Something like
"a=range(10)" means:
* build a NEW list for 10 elements
* THEN assign it to the variable "a"
* which THEN reduces the ref count to the previous binding for "a"
* and THEN IF the ref count is zero, free the list previously bound to
"a"

In other words, if "a" is already bound to a large list, then the above
assignment necessarily creates a second, non-overlapping list in
memory.

However, if you write "a=None;a=range(10)", then the original list
gets freed BEFORE the new list is created and the system has a chance
to re-use that large, contiguous block of memory.

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


Re: Can't see the forest for the trees - when reading file, only processing first line

2006-04-13 Thread News
[EMAIL PROTECTED] wrote:
> Suggest keeping it simple:
> 
> def use_file():
>   return open(options.filename).readlines()
> 
> m
> 

Very cool..

Didn't know you could do that.



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


Re: function prototyping?

2006-04-13 Thread Duncan Booth
Burton Samograd wrote:
> Is there any way to 'prototype' functions in python, as you would in
> C?  Would that be what the 'global' keyword is for, or is there a more
> elegant or 'pythonic' way of doing forward references?
> 
There isn't really such a thing as a forward reference in Python. Always 
remember that 'def' and 'class' are executable statements:

def a():
   b()

def b():
   print "b called"

a()

So long as you have executed both def statements before you call the first 
function it will find the second one. In the example above, if you called 
a() before executing 'def b()' the function 'b' wouldn't exist so you 
couldn't call it.
-- 
http://mail.python.org/mailman/listinfo/python-list


function prototyping?

2006-04-13 Thread Burton Samograd
Hi,

Is there any way to 'prototype' functions in python, as you would in
C?  Would that be what the 'global' keyword is for, or is there a more
elegant or 'pythonic' way of doing forward references?

-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter vs PyGTK

2006-04-13 Thread mwt
I've had a good experience with Pygtk. I made a small app called
"Protein Think" that monitors a [EMAIL PROTECTED] client. The front end is
extremely simple - basically a notebook with five small pages. It runs
well and was a breeze to create. Looks much better than Tkinter, if
that matters at all to you.

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


Re: Can't see the forest for the trees - when reading file, only processing first line

2006-04-13 Thread matt
Suggest keeping it simple:

def use_file():
  return open(options.filename).readlines()

m

News wrote:
> Hi Everyone,
>
>
> The attached code creates client connections to websphere queue managers
> and then processes an inquiry against them.
>
> The program functions when it gets options from the command line.
>
> It also works when pulling the options from a file.
>
> My issue is that it only processes the first line of the file.
>
> Does anyone know why this might be the case?
>
> The use_file() function should be returning each file line.
>
> Any help you can provide on this would be greatly appreciated.
>
> Thanks
>
>
> #!/usr/bin/python
> #
> # Programmer: Andrew Robert
> #
> # Function: Generic method to extract information from a queue manager
> #   This script is intended to be run from the command line to
> return values
> #   based on supplied keys
> #
> #   Depending on whether the -d command switch is used or not,
> the output of this script
> #   will go to the screen or be e-mailed
> #
> #   The e-mailer function included in this program is set use
> the generic smtp library
> #   instead of sendmail or procmail.
> #
> #   This is a design decision since the program is intended
> primarily to run
> #   on a Windows platform.
> #
> #
>
>
> #
> #
> #
> #
> def usage():
>   print
> """
> usage: test_orig.py [options]
>
> options:
>   -h, --helpshow this help message and exit
>   -mQMANAGER, --qmanager=QMANAGER
> Queue Manager to inquire against
>   -sHOST, --server=HOST
> Host the que manager resides on
>   -cCHECK, --check=CHECK
> Test object if it is
> less/equal/greater
>   -pPORT, --port=PORT   Port queue manager listens on
>   -oOBJECT, --object=OBJECT
> Queue object being inquired on
>   -kKEY, --key=KEY  object attribute to be inquired
> about
>   -tMTO, --to=MTO   e-mail address the report will go to
>   -q, --quiet   optional - just returns the value
>   -fFILE, --file=FILE   Pull command strings from FILE
>   -d, --display optional - use sends output to
> e-mail
>  """
>
>
> #
> # Trap signal interrupts if they occur
> #
> def signal_handler(signal, frame):
> print 'Signal trapped %s' % signal
> sys.exit(0)
>
>
> #
> # Read a file into a list
> #
> def use_file():
>   myfile = open(options.filename)
>   while True:
>   line=myfile.readline()
>   print line
>   if len(line) == 0:
>   myfile.close()
>   break
>   else:
>   return line
>   myfile.close()
>
>
>
> def check_params():
> if options.report is not None:
>   if options.mto is None:
>   print "\nAsked to send via e-mail but no destination 
> address supplied"
>   usage()
>   sys.exit(1)
> if options.key is None:
>   print"\n\nPlease enter a valid key to inquire upon.\n\nPlease check
> your options and try again"
>   usage()
>   sys.exit(1)
>
> if ( options.port <="1414" ) or ( options.port >="1419" ):
>   print "\n\nAn invalid port number was used. \nValid port numbers
> are 1415,1416,1417, and 1418."
>   print "\nPlease check the port number and try again"
>   usage()
>   sys.exit(1)
>
> #
> #
> # Test return value
> #
> def testval(inc,value):
>   vallen = int(value)
>   if vallen > inc :
> return "\nless than test value\n"
>   elif vallen < inc :
>   return "\nexceeds test value\n"
>   else:
>   return "\nequal to test value\n"
>
>
> # Validate e-mail addresses based on lexical rules set forth in RFC 822
> # Ported from Recipe 3.9 in Secure Programming Cookbook for C and C++ by
> # John Viega and Matt Messier (O'Reilly 2003)
> #
> # If the supplied email address is syntactically valid, isAddressValid()
> # will return 1; otherwise, it will return 0.
> #
> def isAddressValid(addr):
>   #
> # First we validate the name portion ([EMAIL PROTECTED])
> #
> c = 0
> while c < len(addr):
> if addr[c] == '"' and (not c or addr[c - 1] == '.' or addr[c
> - 1] == '"'):
> c = c + 1
> while c < len(addr):
> if addr[c] == '"': break
> if addr[c] == '\\' and addr[c + 1] == ' ':
> c = c + 2
> continue
> if ord(addr[c]) < 32 or ord(addr[c]) >= 127: return 0
> c = c + 1
> else: return 0
> if addr[c] == '@': break
> if addr[c] != '.': return 0
>  

Re: Python editing with emacs/wordstar key bindings.

2006-04-13 Thread BartlebyScrivener
>> When all I started looking for was a more robust editor for Python ;-)

Both WingIDE and Komodo Dragon allow for customization of keyboard
bindings. They aren't free, but they cost only $30.00 or so. Cheap for
what you get, especially in the case of Komodo because it makes a nice
editor for many languages--Perl, PHP, HTML etc.

I tried Xemacs several times over the years on Win XP. Something
usually breaks, and then--yes--you have to learn Lisp to fix it.

rpd

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


Re: list.clear() missing?!?

2006-04-13 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>except that arguments along the line of "if the syntax is not obj.method(),
>it's not OO enough" are likely to be mostly ignored.
>
>(nobody's going to be impressed by yet another "len(obj) isn't OO" variant)

Does that suggest that what's needed is clear(obj) and __clear__
methods? 8-)

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

Re: Can't see the forest for the trees - when reading file, only processing first line

2006-04-13 Thread Heiko Wundram
Am Donnerstag 13 April 2006 19:12 schrieb News:
> The use_file() function should be returning each file line.

How do you think it should do that? There's a return line statement in the 
function which breaks function execution right after having read the first 
line.

Rethink your logic...

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


Can't see the forest for the trees - when reading file, only processing first line

2006-04-13 Thread News
Hi Everyone,


The attached code creates client connections to websphere queue managers
and then processes an inquiry against them.

The program functions when it gets options from the command line.

It also works when pulling the options from a file.

My issue is that it only processes the first line of the file.

Does anyone know why this might be the case?

The use_file() function should be returning each file line.

Any help you can provide on this would be greatly appreciated.

Thanks


#!/usr/bin/python
#
# Programmer: Andrew Robert
#
# Function: Generic method to extract information from a queue manager
#   This script is intended to be run from the command line to
return values
#   based on supplied keys
#
#   Depending on whether the -d command switch is used or not,
the output of this script
#   will go to the screen or be e-mailed
#
#   The e-mailer function included in this program is set use
the generic smtp library
#   instead of sendmail or procmail.
#
#   This is a design decision since the program is intended
primarily to run
#   on a Windows platform.
#
#


#
#
#
#
def usage():
print
"""
usage: test_orig.py [options]

options:
  -h, --helpshow this help message and exit
  -mQMANAGER, --qmanager=QMANAGER
Queue Manager to inquire against
  -sHOST, --server=HOST
Host the que manager resides on
  -cCHECK, --check=CHECK
Test object if it is
less/equal/greater
  -pPORT, --port=PORT   Port queue manager listens on
  -oOBJECT, --object=OBJECT
Queue object being inquired on
  -kKEY, --key=KEY  object attribute to be inquired
about
  -tMTO, --to=MTO   e-mail address the report will go to
  -q, --quiet   optional - just returns the value
  -fFILE, --file=FILE   Pull command strings from FILE
  -d, --display optional - use sends output to
e-mail
 """


#
# Trap signal interrupts if they occur
#
def signal_handler(signal, frame):
print 'Signal trapped %s' % signal
sys.exit(0)


#
# Read a file into a list
#
def use_file():
myfile = open(options.filename)
while True:
line=myfile.readline()
print line
if len(line) == 0:
myfile.close()
break
else:
return line
myfile.close()  



def check_params():
if options.report is not None:
if options.mto is None:
print "\nAsked to send via e-mail but no destination 
address supplied"
usage()
sys.exit(1)
if options.key is None:
print"\n\nPlease enter a valid key to inquire upon.\n\nPlease check
your options and try again"
usage()
sys.exit(1)

if ( options.port <="1414" ) or ( options.port >="1419" ):
print "\n\nAn invalid port number was used. \nValid port numbers
are 1415,1416,1417, and 1418."
print "\nPlease check the port number and try again"
usage()
sys.exit(1)

#
#
# Test return value
#
def testval(inc,value):
vallen = int(value)
if vallen > inc :
return "\nless than test value\n"
elif vallen < inc :
return "\nexceeds test value\n"
else:
return "\nequal to test value\n"


# Validate e-mail addresses based on lexical rules set forth in RFC 822
# Ported from Recipe 3.9 in Secure Programming Cookbook for C and C++ by
# John Viega and Matt Messier (O'Reilly 2003)
#
# If the supplied email address is syntactically valid, isAddressValid()
# will return 1; otherwise, it will return 0.
#
def isAddressValid(addr):
#   
# First we validate the name portion ([EMAIL PROTECTED])
#
c = 0
while c < len(addr):
if addr[c] == '"' and (not c or addr[c - 1] == '.' or addr[c
- 1] == '"'):
c = c + 1
while c < len(addr):
if addr[c] == '"': break
if addr[c] == '\\' and addr[c + 1] == ' ':
c = c + 2
continue
if ord(addr[c]) < 32 or ord(addr[c]) >= 127: return 0
c = c + 1
else: return 0
if addr[c] == '@': break
if addr[c] != '.': return 0
c = c + 1
continue
if addr[c] == '@': break
if ord(addr[c]) <= 32 or ord(addr[c]) >= 127: return 0
if addr[c] in rfc822_specials: return 0
c = c + 1
if not c or addr[c - 1] == '.': return 0

# Next we validate the domain port

Re: Tkinter vs PyGTK

2006-04-13 Thread Lunpa
makes me wonder how useable pygui is now...

I made the mistake of using wxpython a while back... having something
that runs perfectly in windows, and *sorta* works in other platforms
hardly counts as cross platform, imho.  And they wonder why tkinter is
shipped with python while wxpython is not...

Personaly, I would just use Tkinter untill a new gui library comes
along that actualy works in platforms people use, not just the one the
dev prefers.  Setting up gtk in windows can be a daunting task for
some, though for projects that I know probably won't see the anyone
else's machine, I just use pygtk, for consistency with the rest of my
apps.

I guess this was slightly off topic, but I think its also important to
consider who might be using your apps when picking out a gui to use.

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


Re: list.clear() missing?!?

2006-04-13 Thread Fredrik Lundh
Raymond Hettinger wrote:

> Also, in the python-dev world, making something "more OO"  is neither a
> virtue nor a vice.

except that arguments along the line of "if the syntax is not obj.method(),
it's not OO enough" are likely to be mostly ignored.

(nobody's going to be impressed by yet another "len(obj) isn't OO" variant)





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


Re: list.clear() missing?!?

2006-04-13 Thread Raymond Hettinger
> > * the request is inane, the underlying problem is trivial, and the
> > relevant idiom is fundamental (api expansions should be saved for rich
> > new functionality and not become cluttered with infrequently used
> > redundant entries)
>
> Is this sort of editorialising fair, or just a way of not-so-subtly
> encouraging Guido to reject the whole idea, now and forever?

Bah.  Guido is not stupid, nor easily misled.  Both the pros and cons
were quipped with abrupt perjoratives so the bullet points could be
stated succinctly and with a bit of levity.  The translation to
verbose, soft, politically correct statements is self-evident.

"request is inane" --> "A generation of python programmers has found
list clearing to be like other parts of the language that you get used
to very quickly and do not prove to be a problem in practice.  The
request is in the same category as others which challenge api choices
made 16 years ago; in particular, the decision to have compact APIs
where the named methods do not duplicate functionality provided by
syntax using operators and keywords. The request is less of a bug
report and more a rejection of Guido's sense of design and his
subsequent experience using his own language."

"underlying problem is trivial" --> "Books such as the Python Pocket
Reference or Python in a Nutshell are able to cover this idiom with
just a single sentence. Once known and understood, the application of
the current-way-to-do-it is immediate, compact, and effective."

"the existing alternatives are a bit perlish" --> "Both alternatives
involve a bit of inventiveness in combining two ideas (either the del
keyword and its interaction with slicing notation or the assignment of
an emtpy list to a slice).  Each approach has a visual appearance of
being a syntax trick.  The effect contrasts with much of the rest of
the language where it is usually possible to write code is a way that
can be read and understood by non-python programmers.  The existing
solution trades readability for the succinctness of a compact
syntactical idiom."



> A list.clear method will make deleting items from a list more OO,
> consistent with almost everything else you do to lists, and less
> procedural. This is especially true if clear() takes an optional index (or
> two), allowing sections of the list to be cleared, not just the entire
> list.

Don't shoot yourself in the foot here.  If you want to advocate
list.clear(), then you're hurting your chances by pushing for it to
take an optional argument.  Essentially, this amounts to an
unwillingness to use the del-keyword and to duplicate its functionality
with a named method.

Also, in the python-dev world, making something "more OO"  is neither a
virtue nor a vice.   It is better to argue for rich functionality,
succeptibility to errors, or dramatic improvements of existing
real-world code.

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


Re: Initializing defaults to module variables

2006-04-13 Thread Burton Samograd
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:
> since you know the name of the config file you're looking for, you can
> simplify (and unweirdify) your code a bit by changing your config file to
> look like this:
> 
> # File: config.py
> 
> #
> # configuration defaults
> 
> some_param = "value"
> some_other_param = 1
> 
> #
> # get user overrides
> 
> import os
> try:
> execfile(os.path.expanduser("~/.program/config.py"))
> except IOError:
> pass # ignore missing config file, but not syntax errors
> 
> # end of file
> 
> with this in place, you just have to do
> 
> import config
> 
> in any application module than needs to access the configuration
> data.

nice, that looks to be just what I was looking for.  thanks.

-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for thoughts on PyMPI

2006-04-13 Thread Konrad Hinsen
On Apr 13, 2006, at 17:37, Carl J. Van Arsdall wrote:

> Hey, anyone use the PyMPI suite: http://sourceforge.net/projects/ 
> pympi/  ??
>
> I am an engineer doing research with MPI and thought I'd do some  
> digging
> to see if any scripting languages had adopted it yet.  I was just
> looking for general comments and reviews from the community on this
> project, thanks!

There is also PyPAR which is quite similar:
http://datamining.anu.edu.au/~ole/pypar/

Both are high-level interfaces to MPI, i.e. they propose an MPI-like  
message passing interface with the main added value being  
communication of arbitrary Python objects.

There is also a more low-level MPI interface in my ScientificPython  
library:
http://dirac.cnrs-orleans.fr/ScientificPython/ScientificPythonManual/
Scientific_27.html

It handles only strings and arrays, but with almost no overhead. Its  
strong point is its C interface, which makes it possible to write  
parallelized mixed C-Python code and to integrate parallelized C  
libraries into Python projects.

Finally, if you are looking for parallel programming in Python but  
not necessarily an MPI-like approach, consider my BSP interface:
http://dirac.cnrs-orleans.fr/ScientificPython/BSP_Tutorial.pdf

This is what I personally consider the most convenient interface for  
parallel programming in Python. It is built on the BSP (Bulk  
Synchronous Processing) model that works at a higher level than  
message passing: the programmer does not have to worry about  
synchronization, which is a major source of hard-to-track-
down bugs.

Konrad.
--
-
Konrad Hinsen
Laboratoire Léon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: [EMAIL PROTECTED]
-


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


Re: Initializing defaults to module variables

2006-04-13 Thread Fredrik Lundh
Burton Samograd wrote:

> A reply to my own question, but I thought I would share the answer.  I
> got it to work with the following code:
>
> import config
> import sys
> from posix import environ
> sys.path.insert(0, environ["HOME"]+"/.program")
> reload(config)
>
> I have a file in my working directory that contains all the program
> variables with default values called config.py, which is loaded at the
> start, and then the user configuration directory is inserted into the
> load path and then their config.py is loaded, which will then
> overwrite the default values.

since you know the name of the config file you're looking for, you can
simplify (and unweirdify) your code a bit by changing your config file to
look like this:

# File: config.py

#
# configuration defaults

some_param = "value"
some_other_param = 1

#
# get user overrides

import os
try:
execfile(os.path.expanduser("~/.program/config.py"))
except IOError:
pass # ignore missing config file, but not syntax errors

# end of file

with this in place, you just have to do

import config

in any application module than needs to access the configuration data.





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


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Paul Rubin
Roel Schroeven <[EMAIL PROTECTED]> writes:
> /var/www/karrigell1
> /var/www/karrigell2
> 
> How do I configure everything so that they are accessible via
> 
> http://hostname/karrigell1
> http://hostname/karrigell2

You mean you want your apache server to proxy the Karrigell pages?

I usually do that with the rewrite module rather than trying to figure
out how to use mod_proxy directly.  It's been a while, but you'd
say something like:

   RewriteEngine on
   RewriteRule ^/karigell1$ http://localhost:1234/karrigell1 [P]
   RewriteRule ^/karigell2$ http://localhost:1234/karrigell2 [P]

The ^/karigell1$ is a regexp to say what url's to rewrite, the
http://localhost:1234/karrigell1 (etc) is where you'd run your
Karrigell server, and the [P] tells mod_rewrite to proxy the
target url.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style classes and len method

2006-04-13 Thread bruno at modulix
Thomas Girod wrote:
> It's alright I found where my mistake came from. I was misunderstanding
> the meaning of "classmethod", thinking of it as an instance method.

Given that 'instance methods' being most of the time attributes of the
class object, such a confusion is not so surprising !-)

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


Re: Initializing defaults to module variables

2006-04-13 Thread Burton Samograd
Burton Samograd <[EMAIL PROTECTED]> writes:
> Is there a way to create a module namespace and populate it
> before sourcing the file?

A reply to my own question, but I thought I would share the answer.  I
got it to work with the following code:

import config
import sys
from posix import environ
sys.path.insert(0, environ["HOME"]+"/.program")
reload(config)

I have a file in my working directory that contains all the program
variables with default values called config.py, which is loaded at the
start, and then the user configuration directory is inserted into the
load path and then their config.py is loaded, which will then
overwrite the default values.

-- 
burton samograd kruhft .at. gmail
kruhft.blogspot.com www.myspace.com/kruhft  metashell.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Roel Schroeven
Tim Williams (gmail) schreef:
> 
> 
> On 13/04/06, *Tim Williams (gmail)* <[EMAIL PROTECTED] 
> > wrote:
> 
> In Karrigell you could write the host mappings into a karrigell
> script (.ks) application, so you wouldn't  even need to use
> virtual-hosts in the config file.  and of course, you could just
> write a single ..ks  that contains (at least the entry points to )
> all your applications
> 
> 
> 
> Hmm,  out of context this could be misleading so:
> 
> In Karrigell you simply put your application into its own directory  and 
> access it via the  http://domain/app-dirname -  for however many 
> applications you need.  

Yes, assuming you use Karrigell as webserver; but in many situations I 
encounter, Apache is used as webserver and I want to keep it that way. 
In fact I want to keep everything as it is; I just want some URL's to be 
handled by Karrigell (and some others by CherryPy, and some others 
possibly by even another framework), and it would be very nice I could 
place them in a directory under the DocumentRoot, just like I can do 
with PHP for example (not that I like to program in PHP, by the way).


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: new-style classes and len method

2006-04-13 Thread bruno at modulix
Thomas Girod wrote:
> Or maybe I'm mixing up what we call a "classmethod" with what we could
> call an "instance method" ?
> 
That's what I was about to point out !-)

> class Data(list):
> __slots__ = ["width", "height", "label"]
> 
> def __init__(self,width,height,label=None):
> list.__init__(self)
> self.width = width
> self.height = height
> self.label = label
> 
> def clear(cls):
> while len(cls) > 0: del cls[0]
> return
> clear = classmethod(clear)

What about this ?

def clear(self):
  del self[:]

As it's name (and signature) implies, a classmethod works on a class,
not on an instance of the class. Here, you are trying to compute the
length of *class* Data.


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


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Roel Schroeven
Pierre Quentel schreef:
> No, in the document root you create a folder "app1" and put all the
> files for the first application in it, and a folder "app2" for the
> second application
> 
> For http://foo.example.com/app1 the server will search for an index
> file in this directory and serve it. You can also specify the script
> you want : http://foo.example.com/app1/default.py. Same thing for app2
> of course. Absolutely no need to start two instances of the server on
> different ports

I understand that, but I'd like to keep the current situation unchanged 
as much as possible. Currently I have an Apache webserver that serves 
some static content plus some dynamic stuff, with a directory structure 
somewhat like

/var/www/index.html
/var/www/internal
/var/www/phpmyadmin
/var/www/webmail

etc. (/var/www is Apache's DocumentRoot, obviously). Also I regularly 
have some stuff in my homedir

/home//public_html/foo
/home//public_html/bar

to play with stuff.

So, I can't run Karrigell on port 80, since that's already in use by 
Apache. So I need to run Karrigell on another port, and somehow instruct 
Apache to forward some URL's to Karrigell on handle some URL's itself.

For example, suppose I create

/var/www/karrigell1
/var/www/karrigell2

How do I configure everything so that they are accessible via

http://hostname/karrigell1
http://hostname/karrigell2


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


PEP 359: The "make" Statement

2006-04-13 Thread Steven Bethard
Ok, I finally have a PEP number.  Here's the most updated version of the 
"make" statement PEP.  I'll be posting it shortly to python-dev.

Thanks again for the previous discussion and suggestions!


PEP: 359
Title: The "make" Statement
Version: $Revision: 45366 $
Last-Modified: $Date: 2006-04-13 07:36:24 -0600 (Thu, 13 Apr 2006) $
Author: Steven Bethard <[EMAIL PROTECTED]>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 05-Apr-2006
Python-Version: 2.6
Post-History: 05-Apr-2006, 06-Apr-2006


Abstract


This PEP proposes a generalization of the class-declaration syntax,
the ``make`` statement.  The proposed syntax and semantics parallel
the syntax for class definition, and so::

make   :


is translated into the assignment::

 = ("", , )

where  is the dict created by executing .
The PEP is based on a suggestion [1]_ from Michele Simionato on the
python-dev list.


Motivation
==

Class statements provide two nice facilities to Python:

   (1) They are the standard Python means of creating a namespace.  All
   statements within a class body are executed, and the resulting
   local name bindings are passed as a dict to the metaclass.

   (2) They encourage DRY (don't repeat yourself) by allowing the class
   being created to know the name it is being assigned.

Thus in a simple class statement like::

  class C(object):
  x = 1
  def foo(self):
  return 'bar'

the metaclass (``type``) gets called with something like::

 C = type('C', (object,), {'x':1, 'foo':})

The class statement is just syntactic sugar for the above assignment
statement, but clearly a very useful sort of syntactic sugar.  It
avoids not only the repetition of ``C``, but also simplifies the
creation of the dict by allowing it to be expressed as a series of
statements.

Historically, type instances (a.k.a. class objects) have been the only
objects blessed with this sort of syntactic support.  But other sorts
of objects could benefit from such support.  For example, property
objects take three function arguments, but because the property type
cannot be passed a namespace, these functions, though relevant only to
the property, must be declared before it and then passed as arguments
to the property call, e.g.::

 class C(object):
 ...
 def get_x(self):
 ...
 def set_x(self):
 ...
 x = property(get_x, set_x, ...)

There have been a few recipes [2]_ trying to work around this
behavior, but with the new make statement (and an appropriate
definition of property), the getter and setter functions can be
defined in the property's namespace like::

 class C(object):
 ...
 make property x:
 def get(self):
 ...
 def set(self):
 ...

The definition of such a property callable could be as simple as::

 def property(name, args, namespace):
 fget = namespace.get('get')
 fset = namespace.get('set')
 fdel = namespace.get('delete')
 doc = namespace.get('__doc__')
 return __builtin__.property(fget, fset, fdel, doc)

Of course, properties are only one of the many possible uses of the
make statement.  The make statement is useful in essentially any
situation where a name is associated with a namespace.  So, for
example, namespaces could be created as simply as::

 make namespace ns:
 """This creates a namespace named ns with a badger attribute
 and a spam function"""

 badger = 42

 def spam():
 ...

And if Python acquires interfaces, given an appropriately defined
``interface`` callable, the make statement can support interface
creation through the syntax::

 make interface C(...):
 ...

This would mean that interface systems like that of Zope would no
longer have to abuse the class syntax to create proper interface
instances.


Specification
=

Python will translate a make statement::

 make   :
 

into the assignment::

  = ("", , )

where  is the dict created by executing .
The  expression is optional; if not present, an empty tuple
will be assumed.

A patch is available implementing these semantics [3]_.

The make statement introduces a new keyword, ``make``.  Thus in Python
2.6, the make statement will have to be enabled using ``from
__future__ import make_statement``.


Open Issues
===

Does the ``make`` keyword break too much code?  Originally, the make
statement used the keyword ``create`` (a suggestion due to Nick
Coghlan).  However, investigations into the standard library [4]_ and
Zope+Plone code [5]_ revealed that ``create`` would break a lot more
code, so ``make`` was adopted as the keyword instead.  However, there
are still a few instances where ``make`` would break code.  Is there a
better keyword for the statement?

**

Currently, there are not many

Re: just one more question about the python challenge

2006-04-13 Thread John Salerno
JW wrote:

> There are SEVEN pages of clues for level 12.  The most recent post (to
> challenge 1) was on April 11, so the forums are most certainly not
> dead.  

I read those seven pages at least twice and they still don't make much 
sense to me (not to mention that many of the posts are just 
conversational comments anyway, and not hints).

The last post for level 12 was made last year, so I'd call that dead 
enough to be unhelpful.

> passwords.  If this isn't your definition of fun, then you can go on to
> other things with a clear conscious.

Some of them are really fun, some are a pain. But if I had 'other 
things' to use Python on consistently, I would definitely spend more 
time with that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style classes and len method

2006-04-13 Thread Thomas Girod
It's alright I found where my mistake came from. I was misunderstanding
the meaning of "classmethod", thinking of it as an instance method.

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


Re: list.clear() missing?!?

2006-04-13 Thread Fredrik Lundh
Mel Wilson wrote:

> > for item in seq:
> > L.append(item)
>
> Both extend and append have one-line slice equivalents,
> except that the equivalents have to keep referring to
> the length of the list.. (have to keep finding the
> len function.)

fwiw, the *tutorial* defines append and extend in terms of slicing...





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


Re: trying to grasp OO : newbie Q?

2006-04-13 Thread John Salerno
[EMAIL PROTECTED] wrote:
> Thanks guys,
> 
> It is starting to make much more sense. Most documentation I find about
> OO is very academic

Couldn't we also say that this issue of namespace scope is a little more 
specific to Python than OOP in general? I could very easily be wrong, 
but I wouldn't want the poster to think that this is how OOP works always.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Paul Rubin
"Luis M. González" <[EMAIL PROTECTED]> writes:
> I appreciate all the observations regarding Wikipedia's nature, but I
> confess that I'm surprised to see you, "python folks", so annoyed by
> this article.

I think it's more "wikipedia folks" (I'm one) who found the original
version of the article annoying by Wikipedia standards.  Wikipedia is
besieged with hucksters trying to propagate marketing fluff through
the encyclopedia and so they react unfavorably to anything that
resembles that type of material.  The current version is much more
suitable as an encyclopedia article.  It just needs a little bit of
grammar and punctuation cleanup, no big deal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Paul Rubin
"Pierre Quentel" <[EMAIL PROTECTED]> writes:
> For http://foo.example.com/app1 the server will search for an index
> file in this directory and serve it. You can also specify the script
> you want : http://foo.example.com/app1/default.py. Same thing for app2
> of course. Absolutely no need to start two instances of the server on
> different ports

But they're the same Python interpreter and so there's no protection
between one application and another, right?  That might be ok for a
single user running multiple apps, but think of PHP hosting farms that
have thousands of users with separate virtual hosts.  It would be
disastrous if they could see each others' data.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Tim Williams (gmail)
On 13/04/06, Tim Williams (gmail) <[EMAIL PROTECTED]> wrote:
In Karrigell you could write the host mappings into a karrigell script
(.ks) application, so you wouldn't  even need to use virtual-hosts
in the config file.  and of course, you could just write a single
..ks  that contains (at least the entry points to ) all your
applications

Hmm,  out of context this could be misleading so:

In Karrigell you simply put your application into its own
directory  and access it via the  http://domain/app-dirname
-  for however many applications you need.   

Managing different apps through a single .ks script  is just something I have experimented with, but don't use very often.

:)



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

Re: trying to grasp OO : newbie Q?

2006-04-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> It is starting to make much more sense. Most documentation I find about
> OO is very academic

you may find Jay Parlar's new python class tutorial helpful:

http://parlar.infogami.com/pytut_classes_copy

(this is a proposed addition/replacement for the class chapter in the
current tutorial).





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


Re: list.clear() missing?!?

2006-04-13 Thread Steven Bethard
Raymond Hettinger wrote:
> [Steven Bethard]
>> I think these are all good reasons for adding a clear method, but being
>> that it has been so hotly contended in the past, I don't think it will
>> get added without a PEP.  Anyone out there willing to take out the best
>> examples from this thread and turn it into a PEP?
> 
> Something this small doesn't need a PEP.  I'll just send a note to
> Guido asking for a pronouncement.

Thanks.  It'd be nice to have something to refer to the next time this 
comes up.

> Here's a draft list of pros and cons (any changes or suggestions are
> welcome):
> 
> Pros:
> -
> 
> * s.clear() is more obvious in intent
> 
> * easier to figure-out, look-up, and remember than either s[:]=[] or
> del s[:]
> 
> * parallels the api for dicts, sets, and deques (increasing the
> expecation that lists will too)
>
> * the existing alternatives are a bit perlish
> 

I'd snip the one below.  It doesn't really contribute anything, and was 
sarcastic in the first place. ;)

> * the OP is shocked, SHOCKED that python got by for 16 years without
> list.clear()
> 
> 
> Cons:
> -
> 
> * makes the api fatter (there are already two ways to do it)
> 
> * expanding the api makes it more difficult to write classes that can
> be polymorphically substituted for lists
> 
> * learning slices is basic to the language (this lesson shouldn't be
> skipped)
> 
> * while there are valid use cases for re-using lists, the technique is
> already overused for unsuccessful attempts to micro-optimize (creating
> new lists is surprisingly fast)
> 

In fairness, if we're going to drop the "SHOCKED" comment, we should 
drop the first two clauses of the point below (but the "relevant idiom" 
part is clearly a good point).

> * the request is inane, the underlying problem is trivial, and the
> relevant idiom is fundamental (api expansions should be saved for rich
> new functionality and not become cluttered with infrequently used
> redundant entries)

Other than those minor edits, I think you've pretty much gotten 
everything.  I look forward to a pronouncement.

Thanks again!

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


Looking for thoughts on PyMPI

2006-04-13 Thread Carl J. Van Arsdall
Hey, anyone use the PyMPI suite: http://sourceforge.net/projects/pympi/  ??

I am an engineer doing research with MPI and thought I'd do some digging 
to see if any scripting languages had adopted it yet.  I was just 
looking for general comments and reviews from the community on this 
project, thanks!


-carl

-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Pierre Quentel
No, in the document root you create a folder "app1" and put all the
files for the first application in it, and a folder "app2" for the
second application

For http://foo.example.com/app1 the server will search for an index
file in this directory and serve it. You can also specify the script
you want : http://foo.example.com/app1/default.py. Same thing for app2
of course. Absolutely no need to start two instances of the server on
different ports

Pierre

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


quick surface plots

2006-04-13 Thread buchstaebchen
Hi folks,

I need advice in finding an appropriate python module for 3D surface
plots, such as for the visualization of wave-dynamics...I'd prefer
something capable of being embedded in wxpython frames, as matplotlib
is doing pretty well for 2D, however, I couldn't get a hold of
functions like  there.
vpython hasn't any likewise, while mayavi is way to complex (and
doesn't allow quick animation?)

Any recommendation (or some old threads I failed to look for) ?

thanks for any reply and cheers!

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


Re: New Karrigel page in Wikipedia

2006-04-13 Thread Tim Williams (gmail)
On 13/04/06, Roel Schroeven <[EMAIL PROTECTED]> wrote:

Tim Williams (gmail) schreef:> Karrigell will happily run multiple karrigell "applications" on a single> server .  In your example simply by having different applications at
> http://foo.example.com/app1 and 
http://foo.example.com/app2 will do the> trick.But I still need to allocate a port for each one, right? And write
rewrite rules to rewrite the urls:  http://foo.example.com/app1 -> 
http://foo.example.com:port1  
http://foo.example.com/app2 -> http://foo.example.com:port2
:)    No  

it is a common misconception that you need seperate ports on a webserver for different "applications" and / or sites 

Generally (ie not karrigell specific),   for *your* example 
you can run them all on the same port - as http://foo.example.com/app1
and http://foo.example.com/app2 

Generally (ie not karrigell specific), even if you are using different
hostnames in the URLs ie  http://www.mydom1.com and
http://www.mydom2.com you still don't need different
ports,  just use virtual-host (or Host-Headers in IIS ) mappings.

In Karrigell you could write the host mappings into a karrigell script
(.ks) application, so you wouldn't  even need to use virtual-hosts
in the config file.  and of course, you could just write a single
.ks  that contains (at least the entry points to ) all your
applications
HTH :)














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

  1   2   >