Re: Injecting python function in an embedded python engine

2009-04-07 Thread Gabriel Genellina
En Mon, 06 Apr 2009 13:58:12 -0300, Roberto Fichera   
escribió:


I've embedded python v2.6.x engine into my application without any  
problem.

Now I would like to inject some additional functions after importing a
python module.
So, basically I'm importing a python module via PyImport_ImportModule()
function.
The python module is a simple set of functions and I would check if some
functions
does exist or not, than if doesn't I would add it from my C application.
Checking if
a function does exist or not isn't an issue, it works without any
problem, my problem
is only how to inject a new function in an already imported module.


Easy (so I wonder whether I misunderstood your question):

some_module.function_name = new_function_object
or
setattr(some_module, function_name, new_function_object)
or
use PyObject_SetAttr/PyObject_SetAttrString in C code.

--
Gabriel Genellina

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


Re: Incomplete exception tracebacks when importing from zipped modules

2009-04-07 Thread Gabriel Genellina
En Thu, 02 Apr 2009 09:35:53 -0300, arve.knud...@gmail.com  
 escribió:



I can't seem to get complete tracebacks when modules imported from zip
archives raise exceptions. [...]
As you can see, the code for each stack entry is omitted. Is this
normal??


A known problem, at least...
You should be able to find it reported somewhere at http://bugs.python.org

--
Gabriel Genellina

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


Re: Anyone mannaged to access parallel port on windows xp?

2009-04-07 Thread prakash jp
Hi all,

just would like to say that most of the parallel port preexistant code is
usually blinking leds,
which is the not the true reprsentation of the paralle port  behaviour. Here
one needs to
think that data is coming out byte after byte. Now plz look out for the
sequence to
push data byte after byte. One pin to pulse(programatically) for a byte
of data to come
out is the Pin 0, strobe pin, then reset the same to push the next byte of
data.
Latare u r expected to send these data byte in the sequnce that the target
board
requirement. I have done this in c - dos based

regards
Prakash



On Tue, Apr 7, 2009 at 12:09 PM, alejandro wrote:

> I have a switch  that I should connect to the parallel port, but had no
> luck
> with it. Tha guy that made it for me told me that it would be easyer to
> connect via parallel instead the USB
> So did anyone have success? I only get suckess!! :-))
> tryed giveio.sys but it doesn't wort (can't figure out what is it)
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-07 Thread Gabriel Genellina
En Wed, 01 Apr 2009 19:20:43 -0300, Simon Hibbs   
escribió:

On 1 Apr, 21:43, Gary Herron  wrote:

Simon Hibbs wrote:



> I'm trying to dump a snapshot of my application window to the
> clipboard. I can use ImageGrab in PIL to get the screen data into a
> PIL image object, which i have converted to a bitmap using ImageWin,
> but when I try to pass this to the clipboard using -

> win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)

> It fails, telling be that "The object must support the buffer
> interface".


The second argument to SetClipboardData should be a handle to a bitmap  
resource, not a string.

See win32\test\test_clipboard.py for an example.

PS: Hmm, looking at SetClipboardData, seems that a string containing the  
data in the right format *might* work too. But it's easier to use  
LoadImage than building the resource by hand, I think.


--
Gabriel Genellina

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


Re: Anyone mannaged to access parallel port on windows xp?

2009-04-07 Thread alejandro
Now it doesn't throw exceptions but it doesn't work. I tryed to connect a 
LED light to the port and it wan't glow. Do you know a way to check if the 
port work?


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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Gabriel Genellina
En Tue, 07 Apr 2009 20:45:15 -0300, Grant Edwards   
escribió:

On 2009-04-07, Scott David Daniels  wrote:

Grant Edwards wrote:

On 2009-04-07, Scott David Daniels  wrote:

 File "/usr/lib/python2.5/site-packages/ClientForm.py", line  
2016, in add_to_form

   Control.add_to_form(self, form)
   TypeError: unbound method add_to_form() must be called with  
FancyControl instance as first argument (got CheckboxControl  
instance instead)



The monkey-patching only happens after the ClientForm module
has been executed (first import), and the monkey-patching
happens after all of that.  So now the "tack it into the
class" method looks a bit better if you cannot simply add your
requirement to the ClientForm source.


That's obviously the "right thing", but it makes portability
more of an issue (I would have to archive/distribute ClientForm
source and users would have to install the customized version
of ClientForm).

Of course there's always the chance that my version of
monkey-patching will stop working with a different version of
ClientForm.  We'll burn that bridge when we come to it.


What you might use as a half-way measure:

 class Mixin:  # or class Mixin(object) if new-style:
 def __eq__(self, other):
 return (self.type == other.type ...
 def __ne__(self, other):
 return not self.__eq__(other)
 class FancyControl(MixIn, ClientForm.Control): pass
 class FancyCheckboxControl(MixIn, ClientForm.CheckboxControl): pass
 ..
 ClientForm.Control = FancyControl
 ClientForm.CheckboxControl = FancyCheckboxControl


That would work -- but there are probably 8 or 10 different
Control subclasses. It's a bit tedious mixing them all one at a
time, and you need more "inside" information (the names of all
the different subclasses).


New style classes have a __subclasses__() method that could be used to  
find all of them (*at a certain moment*) -- but considering all the  
issues, I think that monkey-patching the base class is the "less bad"  
option in this case...


--
Gabriel Genellina

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


Re: Python syntax

2009-04-07 Thread Lawrence D'Oliveiro
In message , Steve 
Holden wrote:

> Lawrence D'Oliveiro wrote:
>
>> In message <7dd228af-
>> e549-444d-8623-11e951851...@y9g2000yqg.googlegroups.com>, janus99 wrote:
>> 
>>> I messed around with my own comp (windos xp) command prompt ...
>> 
>> Try a Linux command prompt. You'll learn a bit more that way.
>> 
> Great advice when Linux is available, but somewhat fatuous for a Windows
> user.

How hard is it to install Cygwin or download a live CD?

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


Re: Some test fail on my new Python 2.6

2009-04-07 Thread Sorin Schwimmer

I wanted to replace my old Python 2.4 and tcl/tk 8.4 with tcl/tk 8.5.6 and 
Python 2.6, mainly so that I can enjoy ttk. tcl/tk was installed from sources 
without any problem, I started a wish and worked.

Now, for the Python, here are all the issues signaled by make test:

running build
running build_ext
building 'dbm' extension
gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall 
-Wstrict-prototypes -DHAVE_GDBM_NDBM_H -I. -I/install/Python-2.6.1/./Include 
-I. -IInclude -I./Include -I/usr/local/include -I/install/Python-2.6.1/Include 
-I/install/Python-2.6.1 -c /install/Python-2.6.1/Modules/dbmmodule.c -o 
build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/dbmmodule.o
gcc -pthread -shared 
build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/dbmmodule.o 
-L/usr/local/lib -lgdbm -o build/lib.linux-i686-2.6/dbm.so
*** WARNING: renaming "dbm" since importing it failed: 
build/lib.linux-i686-2.6/dbm.so: undefined symbol: dbm_firstkey
building '_tkinter' extension
gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall 
-Wstrict-prototypes -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11R6/include -I. 
-I/install/Python-2.6.1/./Include -I. -IInclude -I./Include 
-I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c 
/install/Python-2.6.1/Modules/_tkinter.c -o 
build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/_tkinter.o
gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall 
-Wstrict-prototypes -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11R6/include -I. 
-I/install/Python-2.6.1/./Include -I. -IInclude -I./Include 
-I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c 
/install/Python-2.6.1/Modules/tkappinit.c -o 
build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/tkappinit.o
gcc -pthread -shared 
build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/_tkinter.o 
build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/tkappinit.o 
-L/usr/X11R6/lib64 -L/usr/X11R6/lib -L/usr/local/lib -lBLT -ltk8.5 -ltcl8.5 
-lX11 -o build/lib.linux-i686-2.6/_tkinter.so
*** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: cannot 
open shared object file: No such file or directory

Failed to find the necessary bits to build these modules:
_sqlite3   bsddb185   sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.


Failed to build these modules:
_tkinter   dbm

running build_scripts
find ./Lib -name '*.py[co]' -print | xargs rm -f
./python -E -tt ./Lib/test/regrtest.py -l
test_aepack
test_aepack skipped -- No module named aepack
test_al
test_al skipped -- No module named al
test_applesingle
test_applesingle skipped -- No module named macostools
test_bsddb185
test_bsddb185 skipped -- No module named bsddb185
test_bsddb3
test_bsddb3 skipped -- Use of the `bsddb' resource not enabled
test_cd
test_cd skipped -- No module named cd
test_cl
test_cl skipped -- No module named cl
test_codecmaps_cn
test_codecmaps_cn skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_hk
test_codecmaps_hk skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_jp
test_codecmaps_jp skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_kr
test_codecmaps_kr skipped -- Use of the `urlfetch' resource not enabled
test_codecmaps_tw
test_codecmaps_tw skipped -- Use of the `urlfetch' resource not enabled
test_curses
test_curses skipped -- Use of the `curses' resource not enabled
test_dbm
test_dbm skipped -- No module named dbm
test_gl
test_gl skipped -- No module named gl
test_httpservers
test test_httpservers failed -- errors occurred; run in verbose mode for details
test_imgfile
test_imgfile skipped -- No module named imgfile
test_kqueue
test_kqueue skipped -- test works only on BSD
test_linuxaudiodev
test_linuxaudiodev skipped -- Use of the `audio' resource not enabled
test_macos
test_macos skipped -- No module named MacOS
test_macostools
test_macostools skipped -- No module named macostools
test_multiprocessing
test_multiprocessing skipped -- OSError raises on RLock creation, see issue 
3111!
test_normalization
test_normalization skipped -- Use of the `urlfetch' resource not enabled
test_ossaudiodev
test_ossaudiodev skipped -- Use of the `audio' resource not enabled
test_pep277
test_pep277 skipped -- test works only on NT+
test_py3kwarn
test_py3kwarn skipped -- test.test_py3kwarn must be run with the -3 flag
test_scriptpackages
test_scriptpackages skipped -- No module named aetools
test_socket
test test_socket failed -- Traceback (most recent call last):
  File "/install/Python-2.6.1/Lib/test/test_socket.py", line 474, in 
testSockName
my_ip_addr = socket.gethostbyname(socket.gethostname())
gaierror: [Errno -2] Name or service not known

test_socketserver
test_socketserver skipped -- Use of the `network' resource not enabled
test_sqlite
test_sqlite skipped -- no sqlite available
test_startfile
test_startfile skipped -- cannot import name startfile
t

Re: Python syntax

2009-04-07 Thread Steve Holden
Lawrence D'Oliveiro wrote:
> In message <7dd228af-
> e549-444d-8623-11e951851...@y9g2000yqg.googlegroups.com>, janus99 wrote:
> 
>> I messed around with my own comp (windos xp) command prompt ...
> 
> Try a Linux command prompt. You'll learn a bit more that way.
> 
Great advice when Linux is available, but somewhat fatuous for a Windows
user.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Watch PyCon on video now!  http://pycon.blip.tv/

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


RELEASED Python 2.6.2 candidate 1

2009-04-07 Thread Barry Warsaw

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'm happy to announce the release of Python 2.6.2 candidate 1.  This  
release contains dozens of bug fixes since Python 2.6.1.  Please see  
the NEWS file for a detailed list of changes.


Barring unforeseen problems, Python 2.6.2 final will be released  
within a few days.


   http://www.python.org/download/releases/2.6.2/NEWS.txt

For more information on Python 2.6 please see

http://docs.python.org/dev/whatsnew/2.6.html

Source tarballs and Windows installers for this release candidate can  
be downloaded from the Python 2.6.2 page:


   http://www.python.org/download/releases/2.6.2/

Bugs can be reported in the Python bug tracker:

   http://bugs.python.org

Enjoy,
Barry

Barry Warsaw
ba...@python.org
Python 2.6/3.0 Release Manager
(on behalf of the entire python-dev team)

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSdwZ0HEjvBPtnXfVAQJTsAP+Krt1F6qGjuk9a7q8HwF2oAWr/peIAfDf
7HGjOpieoyyAKO1ZNqWvxZ1Ftx+I0YHjfk5OKz/1FN9H3eteFU/L5EEbJD1iTSmK
LAOycWWtWJp+OPatqveHZbGr4ap4XON05yMrzlewnnIH0iGnYjMAgxKkwVKA7MwN
BiXDeBPba1A=
=HdKG
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a way to collect twitts with python?

2009-04-07 Thread Aahz
In article ,
Nick Stinemates  wrote:
>
>You mean you don't want to read every detail of someone's life? Damn..

Someone has probably done this already, but I've been tempted to set up
a Twitter feed that lists every time I visit the loo.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lock down Internet Access from Python script?

2009-04-07 Thread Lawrence D'Oliveiro
In message 
<97995159-9dfd-44e5-8c00-441c0699a...@f19g2000yqo.googlegroups.com>, 
roschler wrote:

> I know it's not possible to "sandbox" the Python Interpreter ...

The Google App Engine does exactly that.

How could you do it? My guess is, use some kind of virtualization (if you 
have the hardware) or paravirtualization (if you don't).

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


Re: 3D plotting in a GUI

2009-04-07 Thread Eric Carlson

Baris Demir wrote:

Hi all,

I need to develop a GUI for some scientific data processing operations 
and this GUI should work well with a 3D plotting module, also with NumPy 
and SciPy for sure. I made a search about packages but, there are plenty 
of these modules available. What kind of a package or a package of 
packages might be the best way  for this  work. BTW I do not want to use 
MayaVi. It is too much actually.


Thanks in advance.
BD




The attached example should give you some idea of embedding mayavi (and 
then using the very high-level mlab) and vtk in wxpython apps. This 
example requires wxpython, vtk, numpy, and ETS. If you are really after 
visualization of data, you will need to spend years to get even a 
fraction of the capability of mayavi. On the other hand, rolling out a 
py2exe'd version of a program is currently a major challenge if you need 
ETS.


The mayavi.mlab module is so easy to use and embed that I would 
recommend using it to create a rapid software prototype to compare 
against whatever system you decide to go with. It is designed with a 
seamless interface to numpy/scipy, and provides high-level routines to 
modify low-level properties.


Cheers,
Eric
"""
This example show how to embedded Mayavi in a wx aui notebook, and
also shows how to embed a generic vtk window 

This is a slightly more complex example than the wx_embedding.py one, and
can be used to see how a large wx application can use different
Mayavi views.
"""

from numpy import ogrid, sin

from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import View, Item

from enthought.mayavi.sources.api import ArraySource
from enthought.mayavi.modules.api import IsoSurface

from enthought.tvtk.pyface.scene_editor import SceneEditor
from enthought.mayavi.tools.mlab_scene_model import MlabSceneModel

class MayaviView(HasTraits):

scene = Instance(MlabSceneModel, ())

view = View(Item('scene', editor=SceneEditor(), resizable=True,
show_label=False),
resizable=True)

def __init__(self):
HasTraits.__init__(self)
x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
scalars = sin(x*y*z)/(x*y*z)
src = ArraySource(scalar_data=scalars)
self.scene.engine.add_source(src)
src.add_module(IsoSurface())
#
# Wx Code
import wx
import vtk
from vtk.wx import *
from enthought.mayavi import mlab 
class MainWindow(wx.Frame):

def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Mayavi in a Wx notebook')
self.notebook = wx.aui.AuiNotebook(self, id=-1, 
style=wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_CLOSE_ON_ALL_TABS
| wx.aui.AUI_NB_LEFT)
sizer = wx.BoxSizer()
sizer.Add(self.notebook,1, wx.EXPAND)
self.SetSizer(sizer)

self.mayavi_view = MayaviView()

self.control = self.mayavi_view.edit_traits(
parent=self,
kind='subpanel').control
self.notebook.AddPage(page=self.control, caption='Display 1')
self.mayavi_view2 = MayaviView()

self.control2 = self.mayavi_view2.edit_traits(
parent=self,
kind='subpanel').control
self.notebook.AddPage(page=self.control2, caption='Display 2')
#the following clears the second panel, 
#then shows the output of test_contour3d in the same panel
mlab.clf() #clear the figure in Display 2
mlab.test_contour3d() #add some stuff there
mlab.show_pipeline() #display the mayavi pipeline viewer


#the following creates a VTK window and embeds in our notebook

self.notebook.AddPage(page=wxVTKRenderWindowInteractor.wxVTKRenderWindowInteractor(self,
 -1), caption='VTK Panel')

widget =  self.notebook.GetPage(2)   
widget.Enable(1)   
widget.AddObserver('ExitEvent', lambda o,e,f=self: f.Close())   
ren = vtk.vtkRenderer()   
widget.GetRenderWindow().AddRenderer(ren)   
cone = vtk.vtkConeSource()
cone.SetResolution(8)   
coneMapper = vtk.vtkPolyDataMapper()   
coneMapper.SetInput(cone.GetOutput())   
coneActor = vtk.vtkActor()   
coneActor.SetMapper(coneMapper)   
ren.AddActor(coneActor)   
style = vtk.vtkInteractorStyleTrackballCamera()   
widget._Iren.SetInteractorStyle(style)  

self.Show(True)

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MainWindow(None, wx.ID_ANY)
app.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list


Re: object knows which object called it?

2009-04-07 Thread afriere
On Apr 7, 2:53 am, "R. David Murray"  wrote:

> I think the OO way to do this is to provide a method on A that does the
> right thing:
>
>     def Bfoo_func(self):
>         self.B.foo_func(self)
>
> Or maybe you could look at generic methods, which provide a way
> to do multiple dispatch.
+1

Which dispatch would itself be using methods to pass 'self' to the
receiving object.  Yes this would seem to be the obvious way to
establish two-way communication between objects.  I would be so bold
as to suggest that if the design the OP has adopted is not amenable to
this straightfoward approach, the design needs to be reassessed.
--
http://mail.python.org/mailman/listinfo/python-list


cross platform ping module

2009-04-07 Thread Eugene Yunak
Hi all!

I'm interested in developing a cross platform module that will allow a
simple
'ping' functionality, i mean sending icmp type 8 code 0 and receiving
appropriate answers. This sound like a simple work, but i ask for your
help
with architectural decision.

I can implement icmp communications using raw sockets (possibly, as
an
extension coded in C), or i can use subproccess module, ask system
ping
executable to do the work, and just parse it's output.
There are problems with both solutions.

First one will require root (or equivalent) privileges for the
interpreter to
 work. This is unavoidable, we can just make the program suid, but
sometimes (as to my mind, always) it is not an option. Security
matters, i can't allow each and every untested application to run
with
root privileges. Besides, this will require the user to actually have
root
access to make program suid. I'm unsure about the way something
similar to
suid can be done on windows, too.

Second one just plain looks ugly to me. I don't like the approach at
all. But,
this would avoid all security troubles with suid, because if the user
can run
ping, we can too. And this also mean sysadmin actually allowed the
user
to run ping. On the other hand, this will limit us to icmp types that
concrete
system's ping executable can work with. This means that on some
systems we can use only type 8/ type 0 (i would like to use few others
too).

If i just needed a tool for specific environment, i would have easily
chosen.
But i'm going to create a module that everyone and everywhere could
use.
>From this point of view, calling system ping looks better.

Can you please help me choose the correct way to handle this problem?
Maybe, there are some other possibilities, witch i haven't taken into
account?
Is someone here interested in this functionality, anyway?

Sorry for my poor English.
--
http://mail.python.org/mailman/listinfo/python-list


Re: extract Infobox contents

2009-04-07 Thread Rhodri James
On Tue, 07 Apr 2009 12:46:18 +0100, J. Clifford Dyer  
 wrote:



On Mon, 2009-04-06 at 23:41 +0100, Rhodri James wrote:

On Mon, 06 Apr 2009 23:12:14 +0100, Anish Chapagain
 wrote:

> Hi,
> I was trying to extract wikipedia Infobox contents which is in format
> like given below, from the opened URL page in Python.
>
> {{ Infobox Software
> | name   = Bash

[snip]

> | latest release date= {{release date|mf=yes|2009|02|20}}
> | programming language   = [[C (programming language)|C]]
> | operating system   = [[Cross-platform]]
> | platform   = [[GNU]]
> | language   = English, multilingual ([[gettext]])
> | status = Active

[snip some more]

> }} //upto this line
>
> I need to extract all data between {{ Infobox ...to }}


[snip still more]


You end up with 'infoboxes' containing a list of all the infoboxes
on the page, each held as a list of the lines of their content.
For safety's sake you really should be using regular expressions
rather than 'startswith', but I leave that as an exercise for the
reader :-)



I agree that startswith isn't the right option, but for matching two
constant characters, I don't think re is necessary.  I'd just do:

if '}}' in line:
pass

Then, as the saying goes, you only have one problem.


That would be the problem of matching lines like:

 | latest release date= {{release date|mf=yes|2009|02|20}}

would it? :-)

A quick bit of timing suggests that:

  if line.lstrip().startswith("}}"):
pass

is what we actually want.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Lock down Internet Access from Python script?

2009-04-07 Thread roschler
I know it's not possible to "sandbox" the Python Interpreter like you
can the Java VM, but I'm wondering if there is a way to at least lock
down internet access?  Trying to do it at the O/S service level on
Windows like ZoneAlarm does isn't feasible for me, but I thought there
might be a way to do it at the Python Interpreter level in a way that
would be hard to get around through clever code forming.

My application will be running several out of process Python
Interpreters in a server pool.  My desire is to at least keep authors
from creating a situation where they are downloading Python scripts
from a web server and running them, unless the owner of that station
trusts a particular author enough to grant that kind of access.  Is
there any way to do this that's more bulletproof than trying to
restrict access to known Socket based libraries?  In other words,
something that could stop things at the Socket level rather than
trying to shepherd the situation by preventing the use of certain
modules?

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


Re: object knows which object called it?

2009-04-07 Thread Ricardo Aráoz
Reckoner wrote:
>> hi,
>>
>> I have the following problem: I have two objects, say, A and B, which
>> are both legitimate stand-alone objects with lives of their own.
>>
>> A contains B as a property, so I often do
>>
>> A.B.foo()
>>
>> the problem is that some functions inside of B actually need A
>> (remember I said they were both standalone objects), so I have to
>> often do:
>>
>> A.B.foo_func(A)
>>
>> Which is kind of awkward.
>>
>> Is there some way that B.foo_func() could somehow know that it was
>> called as a property of A in this way?
>>
>> Note that I'm looking for the calling object and NOT the calling
>> function.
>>
>> Thanks in advance.
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>  
Maybe this would work for you?

>>> class B(object) :
... def __init__(self, owner=None) :
... self.owner = owner
... def someMethod(self) :
... print self.owner.name
...
>>> class A(object) :
... def __init__(self, name='class A') :
... self.B = B(owner=self)
... self.name = name
...
>>> instA1 = A('one')
>>> instA2 = A('two')
>>> instA1.B.someMethod()
one
>>> instA2.B.someMethod()
two
>>>




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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Grant Edwards
On 2009-04-07, Scott David Daniels  wrote:
> Grant Edwards wrote:
>> On 2009-04-07, Scott David Daniels  wrote:
>> 
  File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2016, in 
 add_to_form
Control.add_to_form(self, form)
TypeError: unbound method add_to_form() must be called with 
 FancyControl instance as first argument (got CheckboxControl instance 
 instead)
>>> OK, that is one of the problems with monkey-patching.  What happened
>>> is ClientForm apparently defines subclasses of Control such as
>>> CheckboxControl.
>> 
>> Right.  Control is just a base class, and changing it to a
>> "different" class after sub-classes have been defined pulls the
>> rug out from under things.  Had I thought about it for a
>> minute, I should have known that would happen.  The working
>> patch tweaks the class in-place, so it works OK.
>> 
>>> The monkey-patching only happens after the ClientForm module
>>> has been executed (first import), and the monkey-patching
>>> happens after all of that.  So now the "tack it into the
>>> class" method looks a bit better if you cannot simply add your
>>> requirement to the ClientForm source.
>> 
>> That's obviously the "right thing", but it makes portability
>> more of an issue (I would have to archive/distribute ClientForm
>> source and users would have to install the customized version
>> of ClientForm).
>> 
>> Of course there's always the chance that my version of
>> monkey-patching will stop working with a different version of
>> ClientForm.  We'll burn that bridge when we come to it.
>> 
>
> What you might use as a half-way measure:
>
>  class Mixin:  # or class Mixin(object) if new-style:
>  def __eq__(self, other):
>  return (self.type == other.type
>  and self.name == other.name
>  and self.value == other.value
>  and self.disabled == other.disabled
>  and self.readonly == self.readonly)
>
>  def __ne__(self, other):
>  return not self.__eq__(other)
>  ...(including  FancyHTMLForm) ...
>  class FancyControl(MixIn, ClientForm.Control): pass
>  class FancyCheckboxControl(MixIn, ClientForm.CheckboxControl): pass
>  ...
>  ClientForm.HTMLForm = FancyHTMLForm
>  ClientForm.Control = FancyControl
>  ClientForm.CheckboxControl = FancyCheckboxControl

That would work -- but there are probably 8 or 10 different
Control subclasses. It's a bit tedious mixing them all one at a
time, and you need more "inside" information (the names of all
the different subclasses).

-- 
Grant

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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Scott David Daniels

Grant Edwards wrote:

On 2009-04-07, Scott David Daniels  wrote:


 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2016, in 
add_to_form
   Control.add_to_form(self, form)
   TypeError: unbound method add_to_form() must be called with FancyControl 
instance as first argument (got CheckboxControl instance instead)

OK, that is one of the problems with monkey-patching.  What happened
is ClientForm apparently defines subclasses of Control such as
CheckboxControl.


Right.  Control is just a base class, and changing it to a
"different" class after sub-classes have been defined pulls the
rug out from under things.  Had I thought about it for a
minute, I should have known that would happen.  The working
patch tweaks the class in-place, so it works OK.


The monkey-patching only happens after the ClientForm module
has been executed (first import), and the monkey-patching
happens after all of that.  So now the "tack it into the
class" method looks a bit better if you cannot simply add your
requirement to the ClientForm source.


That's obviously the "right thing", but it makes portability
more of an issue (I would have to archive/distribute ClientForm
source and users would have to install the customized version
of ClientForm).

Of course there's always the chance that my version of
monkey-patching will stop working with a different version of
ClientForm.  We'll burn that bridge when we come to it.



What you might use as a half-way measure:

class Mixin:  # or class Mixin(object) if new-style:
def __eq__(self, other):
return (self.type == other.type
and self.name == other.name
and self.value == other.value
and self.disabled == other.disabled
and self.readonly == self.readonly)

def __ne__(self, other):
return not self.__eq__(other)
...(including  FancyHTMLForm) ...
class FancyControl(MixIn, ClientForm.Control): pass
class FancyCheckboxControl(MixIn, ClientForm.CheckboxControl): pass
...
ClientForm.HTMLForm = FancyHTMLForm
ClientForm.Control = FancyControl
ClientForm.CheckboxControl = FancyCheckboxControl

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: 3D plotting in a GUI

2009-04-07 Thread R Fritz
I've been doing 3D modeling for lighting simulation and I found two 
reasonably well-supported solutions: VTK and OpenSceneGraph.  VTK 
generally has a research slant and has what I believe are reasonably 
strong Python bindings.  OSG is closer to VR/AR/Flight Simulation 
applications and the Python bindings are pre-alpha--you'll probably have 
to roll your own for some purposes.  Both are OpenGL based; if you need 
an easy Windows install you'll have to go with something that supports 
DirectX.

If your app is simple, you might just be able to write OpenGL code.

Anyone who knows of other reasonably current libraries, please follow 
up--there are a lot of libraries that don't seem to see much activity, 
and I'm not sure if this is because they are complete or because they 
are not much used.
--
http://mail.python.org/mailman/listinfo/python-list


Re: named pipe and Linux

2009-04-07 Thread akineko
Hello Cameron Simpson,

Thank you for your reply.
I now think the way I did (using fstat()) was a very bad idea (as you
pointed out).
I haven't decided how to fix this yet.
I also considered attaching the message length to the head of the
message.
It will work, too.
I need to a bit more experiment.

Thank you for providing me directions to solve this problem.

Best regards,
Aki Niimura

On Apr 7, 3:26 pm, Cameron Simpson  wrote:
> On 07Apr2009 10:08, akineko  wrote:
> | I'm trying to use named pipes to fuse a Python program and a C
> | program.
> | One side creates pipes using os.mkfifo() and both sides use the same
> | named pipes (one side reads, another side writes). The read side uses
> | select.select() to wait for incoming messages and read the message
> | when select.select() says it is ready.
> | The length of the message is unknown to the read side.
>
> That's a serious flaw in the message protocol.
>
> | I cannot use file.read() because it will block waiting for an EOF.
> | I cannot use file.readline() because how many lines have arrived is
> | unknown.
> | So, I needed to use os.read() with the exact number of characters to
> | read.
>
> No!
>
> You should use os.read() with the maximum size of a message.
> It _should_ return with the number of bytes in the message, provided the
> C program writes messages with a single OS-level write() call.
>
> Forget all the fstat() stuff - it's racy.
>
> Personally, I'd use a thread to just do continuous blocking os.read()s of
> the pipe, and putting the resulting messages on a Queue for collection
> by your main program. If you're the only consumer of a Queue it's safe
> to poll it for emptiness or not, or to use a no-wait get().
>
> All the above is untested, but absent a size in the protocol or other
> ways of parsing message boundaries in data stream, you can only rely on
> the C program writing messages with a single write() and collect using a
> large os.read(), which should return with what is there.
>
> Cheers,
> --
> Cameron Simpson  DoD#743http://www.cskk.ezoshosting.com/cs/
>
> Language... has created the word "loneliness" to express the pain of
> being alone. And it has created the word "solitude" to express the glory
> of being alone. - Paul Johannes Tillich

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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Grant Edwards
On 2009-04-07, Scott David Daniels  wrote:

>>  File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2016, in 
>> add_to_form
>>Control.add_to_form(self, form)
>>TypeError: unbound method add_to_form() must be called with FancyControl 
>> instance as first argument (got CheckboxControl instance instead)
>
> OK, that is one of the problems with monkey-patching.  What happened
> is ClientForm apparently defines subclasses of Control such as
> CheckboxControl.

Right.  Control is just a base class, and changing it to a
"different" class after sub-classes have been defined pulls the
rug out from under things.  Had I thought about it for a
minute, I should have known that would happen.  The working
patch tweaks the class in-place, so it works OK.

> The monkey-patching only happens after the ClientForm module
> has been executed (first import), and the monkey-patching
> happens after all of that.  So now the "tack it into the
> class" method looks a bit better if you cannot simply add your
> requirement to the ClientForm source.

That's obviously the "right thing", but it makes portability
more of an issue (I would have to archive/distribute ClientForm
source and users would have to install the customized version
of ClientForm).

Of course there's always the chance that my version of
monkey-patching will stop working with a different version of
ClientForm.  We'll burn that bridge when we come to it.

-- 
Grant Edwards   grante Yow! BARBARA STANWYCK makes
  at   me nervous!!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: named pipe and Linux

2009-04-07 Thread Lawrence D'Oliveiro
In message <5b5157dd-
ca70-4c6d-8adb-8a4d322fb...@x31g2000prc.googlegroups.com>, akineko wrote:

> The length of the message is unknown to the read side.

I think you want a message-based, not a stream-based, IPC mechanism. Look at 
the docs on msgctl, msgget, msgop and so on.

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


Re: Python syntax

2009-04-07 Thread Lawrence D'Oliveiro
In message <7dd228af-
e549-444d-8623-11e951851...@y9g2000yqg.googlegroups.com>, janus99 wrote:

> I messed around with my own comp (windos xp) command prompt ...

Try a Linux command prompt. You'll learn a bit more that way.

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


Re: named pipe and Linux

2009-04-07 Thread Cameron Simpson
On 07Apr2009 10:08, akineko  wrote:
| I'm trying to use named pipes to fuse a Python program and a C
| program.
| One side creates pipes using os.mkfifo() and both sides use the same
| named pipes (one side reads, another side writes). The read side uses
| select.select() to wait for incoming messages and read the message
| when select.select() says it is ready.
| The length of the message is unknown to the read side.

That's a serious flaw in the message protocol.

| I cannot use file.read() because it will block waiting for an EOF.
| I cannot use file.readline() because how many lines have arrived is
| unknown.
| So, I needed to use os.read() with the exact number of characters to
| read.

No!

You should use os.read() with the maximum size of a message.
It _should_ return with the number of bytes in the message, provided the
C program writes messages with a single OS-level write() call.

Forget all the fstat() stuff - it's racy.

Personally, I'd use a thread to just do continuous blocking os.read()s of
the pipe, and putting the resulting messages on a Queue for collection
by your main program. If you're the only consumer of a Queue it's safe
to poll it for emptiness or not, or to use a no-wait get().

All the above is untested, but absent a size in the protocol or other
ways of parsing message boundaries in data stream, you can only rely on
the C program writing messages with a single write() and collect using a
large os.read(), which should return with what is there.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Language... has created the word "loneliness" to express the pain of
being alone. And it has created the word "solitude" to express the glory
of being alone. - Paul Johannes Tillich
--
http://mail.python.org/mailman/listinfo/python-list


Re: Expression

2009-04-07 Thread Terry Reedy

Lydia wrote:
I am working on calculating one of the fields in a feature class based 
on other 2 fields. The logic is,
A (the resulting field) is calculated from B, but C and D have part of 
the value that could fill the blank of B, which meaning that combine 
three fields of values can make A.
 
Field A is what I need.
 
The data looks like: .
 
A   B   C   D

 2  2
 5  5
 44
 6   6
 
 
 cur = gp.UpdateCursor(data)

row = cur.Next()
gp.CalculateField_management(data, "A", "[B]", "VB", "")


Those indents are wrong, and would cause a syntax error, so this must 
not be the code you actually ran.  When posting, please copy and paste 
instead of retyping.


Does the last line set A from B? Should it be inside the loop?


 while row:
 
cur.UpdateRow(row)


Or does this magically set A from B?

 
if  not(row.GetValue("C") == 'NULL'):


This should be the same as
if row.GetValue("C") != 'NULL':
which I find easier to read.

From what you said before, you only want to set A from C or D if B is 
blank.  If so, this section should be indented under

if row.GetValue("B") == 'NULL':


  row.SetValue("A",row.GetValue("C"));
 
elif not(row.GetValue("D") == 'NULL'):

  row.SetValue("A",row.GetValue("D"));

row = cur.Next()
   
del cur

del row


Again, indent is erroneous.


But the out looks like only B was calculated to A successfully. C&D are 
not in A.


I have no idea why not.  A main way to debug is to insert print 
statements into the code in appropriate places and see if what is 
printed matched what you expect.


I guess there must be something wrong with the code, but I am very new 
to Python, and not familiar with the expression. Could anybody help ?  
PS. I am coding Python with ARCGIS.


I am not familiar with ARCGIS.

tjr

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


Re: 3D plotting in a GUI

2009-04-07 Thread Scott David Daniels

Baris Demir wrote:

Hi all,

I need to develop a GUI for some scientific data processing operations 
and this GUI should work well with a 3D plotting module, also with NumPy 
and SciPy for sure. I made a search about packages but, there are plenty 
of these modules available


Look into VPython. Especially if MayaVi is too much.  It has provisions
for running with cross-eyed and wall-eyed 3-D as well as the cheapo
colored paper glasses and the seriously not cheapo shuttered-glasses /
special display card option.

--Scott David Daniels
scott.dani...@acm.org

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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Scott David Daniels

Grant Edwards wrote:

On 2009-04-07, Grant Edwards  wrote:

On 2009-04-07, Scott David Daniels  wrote:

Grant Edwards wrote:

I realize that technically all methods are added to classes at
"run-time", but what I'm talking about is this:

...

   ClientForm.Control.__eq__ = controlEqual
   ClientForm.Control.__ne__ = controlNotEqual

...


Well, a more standard approach would be:
 class FancyControl(ClientForm.Control):
 def __eq__(self, other):
 return (self.type == other.type
 and self.name == other.name
 and self.value == other.value
 and self.disabled == other.disabled
 and self.readonly == self.readonly)

 def __ne__(self, other):
 return not self.__eq__(other)


I like that, except it doesn't work.  Objects instantiated from
sub-classes of ClientForm.Control break.  I get errors like
this:

   Traceback (most recent call last):
 File "./testit.py", line 141, in 
   f1 = getSocketForm(0)
 File "./testit.py", line 99, in getSocketForm
   return getForm("Socket",n)
 File "./testit.py", line 88, in getForm
   forms = ClientForm.ParseResponse(response,backwards_compat=False)
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 1057, in 
ParseResponse
   return _ParseFileEx(response, response.geturl(), *args, **kwds)[1:]
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 1128, in 
_ParseFileEx
   type, name, attrs, select_default=select_default, index=ii*10)
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2843, in 
new_control
   control.add_to_form(self)
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2016, in 
add_to_form
   Control.add_to_form(self, form)
   TypeError: unbound method add_to_form() must be called with FancyControl 
instance as first argument (got CheckboxControl instance instead)


OK, that is one of the problems with monkey-patching.  What happened
is ClientForm apparently defines subclasses of Control such as
CheckboxControl.  The monkey-patching only happens after the
ClientForm module has been executed (first import), and the
monkey-patching happens after all of that.  So now the "tack it into
the class" method looks a bit better if you cannot simply add your
requirement to the ClientForm source.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: pseudo-code

2009-04-07 Thread r-w

r-w wrote:

If no internet connection:
if have files:
run anyway, with warning
else:
ERROR
else:
if error getting hash/files:
if have files:
run anyway, with warning
else:
ERROR
else:
run


Sorry, guys.

This should have gone to work.

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


Re: with open('com1', 'r') as f:

2009-04-07 Thread Terry Reedy

Lawrence D'Oliveiro wrote:
In message , Delaney, 
Timothy (Tim) wrote:



Lawrence D'Oliveiro wrote:


In message ,
Terry Reedy wrote:


Lawrence D'Oliveiro wrote:


All Python objects are reference-counted.

Nope.  Only in CPython, and even that could change.

Why should it?

Because Guido has said it might some time in the future.


It's still a matter of efficiency, not correctness.


If one wants to *ensure* that the file is closed as soon as it is not 
needed (perhaps because it is one of 100s of files being processed), in 
all versions of Python current and future, then 'with ...' is an easy 
way to do it, while 'open ...' is incorrect.


If one *does not care* about quick closure (perhaps because it is one of 
only a few files and they are all just read or the program will soon end 
(and cause closure anyway), then 'open ...' is both easy and correct.


The latter has typically applied to my work, but I know that is not true 
for everyone.



Once the file object becomes

inaccessible, it is automatically closed. Simple.

Even in CPython, that would not be true now is the object became
involved in or became a dependent of a reference cycle.

And how exactly would that happen with a file object?

Create a cycle of objects, and have one of them reference a file object.


Which was not what was happening in the actual situation at hand.


For the simple toy example, sure.  But in general, anything could happen 
after a file is opened within 'with' block or any other chunk of code.


tjr

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


Re: 3D plotting in a GUI

2009-04-07 Thread Stef Mientki

Baris Demir wrote:

Hi all,

I need to develop a GUI for some scientific data processing operations 
and this GUI should work well with a 3D plotting module, also with 
NumPy and SciPy for sure. I made a search about packages but, there 
are plenty of these modules available. What kind of a package or a 
package of packages might be the best way  for this  work. BTW I do 
not want to use MayaVi. It is too much actually.

What do you mean by "too much actually" ?
What's the GUI you had in mind ?
What kind of scientific data processing do you've in mind ?

cheers,
Stef


Thanks in advance.
BD

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


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


Re: extracting plain text from RTF-file ?

2009-04-07 Thread Stef Mientki

Brent Bloxam wrote:

Stef Mientki wrote:

hello,

I'm looking for a library to extract plain text from RTF-files.
I found these

only RTF generation
http://pyrtf.sourceforge.net/

should be able to parse, but no download files
http://code.google.com/p/pyrtf-ng/


any suggestions ?
thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Checkout from SVN, there's a release tagged as 0.45, but the trunk is 
newer by ~4 months

thanks Brent,
I got some code and examples,
but no example of parsing, only generating ?
Anyone has an example perhaps ?

thnaks,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Request For Comment

2009-04-07 Thread Falcolas
On Apr 7, 12:57 pm, a...@pythoncraft.com (Aahz) wrote:
> How RFC1 got created:
>
> http://www.nytimes.com/2009/04/07/opinion/07crocker.html

Thanks for bring that forward; I thought it was an interesting read
and a nice polite (yet much needed) little jab at status-quo.

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


xml.dom.minidom getElementsByTagName white space issue

2009-04-07 Thread Leonardo lozanne
Hi,
 
I'm getting some XML tags with white spaces from a web service and when I try 
to get them with the getElements ByTagName I'm not able to do so. I'm getting 
an empty list. What I'm doing is:
 
#XML_response is an xml string
xml_msg = xml.dom.minidom.parseString(XML_response)
 
nodes = xml_msg.getElementsByTagName("tag ten")  #tag name is "tag ten" with a 
whitespace
 
It all works fine with tags like tag_seven but NOT for tag names with a white 
space. I've tried some escape chars but it doesnt seems to work. 
 
Does anybody has the escape char sequence I should be using or a work around 
for this? Thanks in advanced for your replies. 


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


PyCon Italy 2009: Early Bird Deadline

2009-04-07 Thread Alan Franzoni
The early-bird registration deadline for PyCon Tre (PyCon Italy 2009) is 
April 13th, just a few days from now.

The conference will take place in Florence from May 8th till May 10th 2009, 
and features guests like Guido Van Rossum, Alex Martelli, Raymond 
Hettinger, Fredrik Lundh and Antonio Cangiano.

Feel free to take a look at the schedule:
http://www.pycon.it/pycon3/schedule/

A simultaneous interpretation service is available for the main track:

http://www.pycon.it/pycon3/non-italians

See you in Florence!


-- 
Alan Franzoni 
-
Remove .xyzz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


PyCon Italy 2009: Early Bird Deadline

2009-04-07 Thread Alan Franzoni
The early-bird registration deadline for PyCon Tre (PyCon Italy 2009) is
April 13th, just a few days from now.

The conference will take place in Florence from May 8th till May 10th 2009,
and features guests like Guido Van Rossum, Alex Martelli, Raymond
Hettinger, Fredrik Lundh and Antonio Cangiano.

Feel free to take a look at the schedule:
http://www.pycon.it/pycon3/schedule/

A simultaneous interpretation service is available for the main track:

http://www.pycon.it/pycon3/non-italians

See you in Florence!


-- 
Alan Franzoni 
-
Remove .xyzz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python syntax

2009-04-07 Thread Dave Angel

janus99 wrote:

well i'm pretty much a newb on python, it's my first comp lang. and
i've been having some diffuclties, i want to get the hang of it and
i'm wondering if u could help me understand the syntax structure.

I messed around with my own comp (windos xp) command prompt and i
currently play a mud, but the python syntax is completly diffrent, i
was wondering if u could expalin how to syntax goes, i've tried the
"hello world" but it keep displaying syntax error, i've tried entering
random commands, e.g find,search, collect,...


  
dorzey's suggestion is good, as is the tutorial available with your 
install.  Look for the file  python-docs-pdf-letter.zip, and inside it 
tutorial.pdf
If you didn't download that yet, you can get it from 
http://docs.python.org/download
I prefer the pdf form, but your preferences may be different.   Just try 
to get one that matches the version of the python you downloaded.



The other thing that you need to learn how to do is to cut & paste in 
your command window.  If you drag the mouse around the command window it 
should highlight some text.  Then you right click to put that on the 
clipboard.  Now you can go to some other program (like your mail 
program) and Ctrl-V to paste it.  If that mode isn't enabled on your 
command windows, fix it, although you can manually use the system menu 
to accomplish the same thing (which I do when I'm using someone else's 
machine).


When you ask for help here, please be specific.  What did you try, and 
exactly what was the error.  For all we know, you weren't even 
successful in getting the python.exe program to run at all.  So it could 
be a path problem, not a language syntax problem.  Here's a sample 
session.  If you can't get this far, show us exactly what you did get.


E:\>c:\ProgFiles\Python26\python.exe
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit 
(Intel)] on

win32
Type "help", "copyright", "credits" or "license" for more information.
>>> "hello world"
'hello world'
>>> 3*12
36
>>> import sys
>>> sys.exit(0)

E:\>






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


Re: Issue with subprocess Module

2009-04-07 Thread Tim Golden

Tim Golden wrote:

So it looks as though the MS docs are simply wrong? I haven't
tried it with ctypes or a native C program, but I can't
see that they should be any different. If I get a chance
later I'll knock something up in C.



OK, copying the standard MS example for creating a process:

http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx

and changing only enough to substitute "c:/temp/t.bat"
for the argv[1], it runs perfectly well. Doesn't answer
the OP's question, but does suggest the docs are wrong.

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


Re: Tkinter, tkFileDialog - how to select multiple files ?

2009-04-07 Thread Steve Offutt
Hmm ... sorry folks - this works for me everywhere except on the
machine I wrote it on ...

Must be some sort of configuration problem...

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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Grant Edwards
On 2009-04-07, Grant Edwards  wrote:
> On 2009-04-07, Scott David Daniels  wrote:
>> Grant Edwards wrote:
>>> I realize that technically all methods are added to classes at
>>> "run-time", but what I'm talking about is this:
> ...
>>
>>>ClientForm.Control.__eq__ = controlEqual
>>>ClientForm.Control.__ne__ = controlNotEqual
> ...
>
>> Well, a more standard approach would be:
>>  class FancyControl(ClientForm.Control):
>>  def __eq__(self, other):
>>  return (self.type == other.type
>>  and self.name == other.name
>>  and self.value == other.value
>>  and self.disabled == other.disabled
>>  and self.readonly == self.readonly)
>>
>>  def __ne__(self, other):
>>  return not self.__eq__(other)

I like that, except it doesn't work.  Objects instantiated from
sub-classes of ClientForm.Control break.  I get errors like
this:

   Traceback (most recent call last):
 File "./testit.py", line 141, in 
   f1 = getSocketForm(0)
 File "./testit.py", line 99, in getSocketForm
   return getForm("Socket",n)
 File "./testit.py", line 88, in getForm
   forms = ClientForm.ParseResponse(response,backwards_compat=False)
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 1057, in 
ParseResponse
   return _ParseFileEx(response, response.geturl(), *args, **kwds)[1:]
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 1128, in 
_ParseFileEx
   type, name, attrs, select_default=select_default, index=ii*10)
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2843, in 
new_control
   control.add_to_form(self)
 File "/usr/lib/python2.5/site-packages/ClientForm.py", line 2016, in 
add_to_form
   Control.add_to_form(self, form)
   TypeError: unbound method add_to_form() must be called with FancyControl 
instance as first argument (got CheckboxControl instance instead)

-- 
Grant Edwards   grante Yow! I want a WESSON OIL
  at   lease!!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


3D plotting in a GUI

2009-04-07 Thread Baris Demir

Hi all,

I need to develop a GUI for some scientific data processing operations 
and this GUI should work well with a 3D plotting module, also with NumPy 
and SciPy for sure. I made a search about packages but, there are plenty 
of these modules available. What kind of a package or a package of 
packages might be the best way  for this  work. BTW I do not want to use 
MayaVi. It is too much actually.


Thanks in advance.
BD

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


Re: Q: "Best" book for teaching

2009-04-07 Thread Mike Driscoll
On Apr 6, 9:37 am, grkunt...@gmail.com wrote:
> I am considering teaching an "introduction to programming" course for
> continuing education adults at a local  community college. These would
> people with no programming experience, but I will require a reasonable
> facility with computers.
>
> What would be a good book to use as the text for the course?
>
> Thanks.

If they ever release it, this book might be good:

http://www.amazon.com/Hello-World-Computer-Programming-Beginners/dp/1933988495/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1239129498&sr=8-1

Zelle's Python Programming book is pretty good (and was written by a
college professor) and I've heard good things about ORielly's Learning
Python by Lutz.

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


Re: Returning different types based on input parameters

2009-04-07 Thread Adam Olsen
On Apr 6, 3:02 pm, George Sakkis  wrote:
> For example, it is common for a function f(x) to expect x to be simply
> iterable, without caring of its exact type. Is it ok though for f to
> return a list for some types/values of x, a tuple for others and a
> generator for everything else (assuming it's documented), or it should
> always return the most general (iterator in this example) ?

For list/tuple/iterable the correlation with the argument's type is
purely superficial, *because* they're so compatible.  Why should only
tuples and lists get special behaviour?  Why shouldn't every other
argument type return a list as well?

A counter example is python 3.0's str/bytes functions.  They're
mutually incompatible and there's no default.


> To take it further, what if f wants to return different types,
> differing even in a duck-type sense? That's easier to illustrate in a
> API-extension scenario. Say that there is an existing function `solve
> (x)` that returns `Result` instances.  Later someone wants to extend f
> by allowing an extra optional parameter `foo`, making the signature
> `solve(x, foo=None)`. As long as the return value remains backward
> compatible, everything's fine. However, what if in the extended case,
> solve() has to return some *additional* information apart from
> `Result`, say the confidence that the result is correct ? In short,
> the extended API would be:
>
>     def solve(x, foo=None):
>         '''
>         @rtype: `Result` if foo is None; (`Result`, confidence)
> otherwise.
>         '''
>
> Strictly speaking, the extension is backwards compatible; previous
> code that used `solve(x)` will still get back `Result`s. The problem
> is that in new code you can't tell what `solve(x,y)` returns unless
> you know something about `y`. My question is, is this totally
> unacceptable and should better be replaced by a new function `solve2
> (x, foo=None)` that always returns (`Result`, confidence) tuples, or
> it might be a justifiable cost ? Any other API extension approaches
> that are applicable to such situations ?

At a minimum it's highly undesirable.  You lose a lot of readability/
maintainability.  solve2/solve_ex is a little ugly, but that's less
overall, so it's the better option.

If your tuple gets to 3 or more I'd start wondering if you should
return a single instance, with the return values as attributes.  If
Result is already such a thing I'd look even with a tuple of 2 to see
if that's appropriate.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with subprocess Module

2009-04-07 Thread Tim Golden

Tim Golden wrote:

Sounds reasonable, but isn't actually true. This works fine:


import subprocess

open ("t.bat", "w").write ("echo hello")
subprocess.Popen ("t.bat")



TJG




Dave Angel wrote:
The docs of Popen() state that it uses CreateProcess() on Windows, so I 
didn't even try it.  


I only knew because I'd answered a similar question
recently and had simply tried it out!

Thanks for informing me it works.  I see now the 
COMSPEC manipulation in _execute_child(), but I'm still puzzled.  When I 
step through, it skips that part because we didn't specify shell= as an 
argument.   It still had not put the cmd.exe /c into the args variable 
when it called CreateProcess().  So is the Python CreateProcess more 
than a thin wrapper around Windows version?


Doesn't look like it. And using win32process.CreateProcess from
pywin32 does exactly the same. (Haven't checked their source
but I doubt they're finicking around with the parameters):


import win32process

open ("t.bat", "w").write ("echo hello")

win32process.CreateProcess (
 None,
 "t.bat",
 None,
 None,
 1,
 0,
 None,
 None,
 win32process.STARTUPINFO ()
)



gives


(, , 6208, 5732)




c:\temp>echo hello
hello







So it looks as though the MS docs are simply wrong? I haven't
tried it with ctypes or a native C program, but I can't
see that they should be any different. If I get a chance
later I'll knock something up in C.



But what about the OP problem?  I now see it runs okay for me, both 
stand-alone and inside Komodo.  But he's getting an exception inside 
make_inheritable(), which is apparently being passed an invalid handle.


Runs OK for me, in Python 2.6 running under XP, SP3.  2.6.1 
(r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]


Works under python 26/25/24 and the current subversion trunk,
and on 3.1 once I'd modified the input to be a bytes string.

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


Request For Comment

2009-04-07 Thread Aahz
How RFC1 got created:

http://www.nytimes.com/2009/04/07/opinion/07crocker.html
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating Linked Lists in Python

2009-04-07 Thread andrew cooke
J-Burns wrote:
> How can I do this? And if I could do this by some other way than using
> linked lists than do tell me about that as well.

replying to this dead thread mainly for anyone using google.  there's now
a python regular expression engine in lepl and the source code can be seen
via http://www.acooke.org/lepl/api/lepl.regexp-module.html

in particular, i found that the critical collection was a map from
interval to values which automatically fragments (i think discussion of
this thread ended up looking at maps).  so, for example, if (1,10) maps to
'foo' then adding (4,5) -> 'bar' gives:

(1,3) -> foo
(4,5) -> foo, bar
(6,10) -> foo

in simple terms that lets you construct transitions for ranges of values -
typically a range of character with a mapped value that is the new state
in the machine.  so if you have a-d going to state 5, and then add d-f
going to state 6, you want d (ie ('d','d')) to go to both 5 and 6 when
constructing a nfa.

that structure is here -
http://www.acooke.org/lepl/api/lepl.regexp.interval-pysrc.html#TaggedFragments
(minimal docs at
http://www.acooke.org/lepl/api/lepl.regexp.interval.TaggedFragments-class.html)

hope that makes sense.  it could probably be more efficient (does an O(n)
scan of all intervals each time a new interval is added so is O(n^2)), but
since this is used in the "compile" part of a regexp, speed may not be as
important as in the "match" phase.

andrew


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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Grant Edwards
On 2009-04-07, Scott David Daniels  wrote:
> Grant Edwards wrote:
>> I realize that technically all methods are added to classes at
>> "run-time", but what I'm talking about is this:
>> 
>>import ClientForm
>> 
>>def controlEqual(self,other):
>>return (self.type == other.type) and \
>>   (self.name == other.name) and \
>>   (self.value == other.value) and \
>>   (self.disabled == other.disabled) and\
>>   (self.readonly == self.readonly)
> Note:
> Here you are checking that self.readonly == self.readonly!

Doh!

> I also dislike the trailing backslashes and over-parenthesizing.
> So, I'd do it like this (using the pare to avoid the backslash):

The paren to avoid the backslashes is a good tip.

>   def controlEqual(self,other):
>   return (self.type == other.type
>   and self.name == other.name
>   and self.value == other.value
>   and self.disabled == other.disabled
>   and self.readonly == self.readonly)

I don't really like to rely on my memory of operator
precidence, but that's a personal problem.

> ...
>>ClientForm.Control.__eq__ = controlEqual
>>ClientForm.Control.__ne__ = controlNotEqual
>>
>>def formEqual(self,other):
>>if len(self.controls) != len(other.controls):
>>return False
>>for (c1,c2) in zip(self.controls,other.controls):
>>if c1 != c2:
>>return False
>>return True
>>
>>def formNotEqual(self,other):
>>return not (self==other)
>>
>>ClientForm.HTMLForm.__eq__ = formEqual
>>ClientForm.HTMLForm.__ne__ = formNotEqual
>
>> It works fine, but it seems like it might be dangerous (or just
>> bad form) to insert methods into existing classes like that.
>> Perhaps it would be safer to make sure that __eq__, __ne__,
>> and __cmp__ don't exist before adding my own?
>
> Well, a more standard approach would be:
>  class FancyControl(ClientForm.Control):
>  def __eq__(self, other):
>  return (self.type == other.type
>  and self.name == other.name
>  and self.value == other.value
>  and self.disabled == other.disabled
>  and self.readonly == self.readonly)
>
>  def __ne__(self, other):
>  return not self.__eq__(other)
>
>  class FancyHTMLForm(ClientForm.HTMLForm):
>  def __eq__(self,other):
>  ...
>
>  def __ne__(self, other):
>  return not self.__eq__(other)
>
> You'd have to make sure FancyControl and FancyClientForm get used in
> the app.

The problem is that my app never instanciates either the
Control or the HTMLForm class: that's all done by module
functions that the app calls, and they don't know about the new
classes without some trickery (e.g. below)

> The latter could be insured by monkey-patching:
>  ...
>  ClientForm.Control = FancyControl
>  ClientForm.HTMLForm = FancyHTMLForm
>
> But substituting monkey-patching

:) How did I not know that phrase until today?

> for class method insertion seems like you are going from one
> quick and dirty technique to a slightly nicer quick and dirty
> technique.

I think like your monkey-patching solution better.  It feels a
bit cleaner.

-- 
Grant Edwards   grante Yow! !  Up ahead!  It's a
  at   DONUT HUT!!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Tkinter, tkFileDialog - how to select multiple files ?

2009-04-07 Thread Steve Offutt
Let me preface by saying that I don't do much Python, however, I am in
my spare time, attempting to become somewhat comfortable with Python/
Tkinter.

I just can't seem to understand what is the problem with this:

--
import Tkinter, tkFileDialog

root = Tkinter.Tk()

files = tkFileDialog.askopenfilenames(parent = root, filetypes =
[('JPEG', '*.jpg'), ('ICON', '*.ico'), ('GIF', '*.gif')], title =
"Select files...", multiple = 1 )

print files
-

Any help greatly appreciated!

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


Re: PyXML and Python-2.6

2009-04-07 Thread Stefan Behnel
Andrew MacKeith wrote:
> The Python.org "SIG for XML Processing in Python" page indicates that
> "The SIG, through the mailing list and the PyXML project hosted on
> SourceForge...".
> 
> The PyXML project on SourceForge " is no longer maintained. ", so
> perhaps the SIG page could be updated.
> 
> Is there a guide to porting projects that depend on PyXML to Python-2.6?

Depending on how large your project is (and how well you encapsulated the
XML code), a partial rewrite using ElementTree or lxml might be worth it.
You'd be rewarded by simple and very fast code.

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


Re: python for loop

2009-04-07 Thread Aahz
In article ,
Lou Pecora   wrote:
>In article 
><5c92e9bd-1fb4-4c01-a928-04d7f6733...@e21g2000yqb.googlegroups.com>,
> Aaron Brady  wrote:
>> 
>> Did I tell you guys that 'natural' has 38 definitions at
>> dictionary.com?
>
>Amazing.  I suggest you pick the one that fits best.

"The wonderful thing about standards is that there are so many to choose
from."
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-07 Thread P.J. Eby

At 04:58 PM 4/7/2009 +0200, M.-A. Lemburg wrote:

On 2009-04-07 16:05, P.J. Eby wrote:
> At 02:30 PM 4/7/2009 +0200, M.-A. Lemburg wrote:
>> >> Wouldn't it be better to stick with a simpler approach and look for
>> >> "__pkg__.py" files to detect namespace packages using that O(1)
>> check ?
>> >
>> > Again - this wouldn't be O(1). More importantly, it breaks system
>> > packages, which now again have to deal with the conflicting file names
>> > if they want to install all portions into a single location.
>>
>> True, but since that means changing the package infrastructure, I think
>> it's fair to ask distributors who want to use that approach to also take
>> care of looking into the __pkg__.py files and merging them if
>> necessary.
>>
>> Most of the time the __pkg__.py files will be empty, so that's not
>> really much to ask for.
>
> This means your proposal actually doesn't add any benefit over the
> status quo, where you can have an __init__.py that does nothing but
> declare the package a namespace.  We already have that now, and it
> doesn't need a new filename.  Why would we expect OS vendors to start
> supporting it, just because we name it __pkg__.py instead of __init__.py?

I lost you there.

Since when do we support namespace packages in core Python without
the need to add some form of magic support code to __init__.py ?

My suggestion basically builds on the same idea as Martin's PEP,
but uses a single __pkg__.py file as opposed to some non-Python
file yaddayadda.pkg.


Right... which completely obliterates the primary benefit of the 
original proposal compared to the status quo.  That is, that the PEP 
382 way is more compatible with system packaging tools.


Without that benefit, there's zero gain in your proposal over having 
__init__.py files just call pkgutil.extend_path() (in the stdlib 
since 2.3, btw) or pkg_resources.declare_namespace() (similar 
functionality, but with zipfile support and some other niceties).


IOW, your proposal doesn't actually improve the status quo in any way 
that I am able to determine, except that it calls for loading all the 
__pkg__.py modules, rather than just the first one.  (And the 
setuptools implementation of namespace packages actually *does* load 
multiple __init__.py's, so that's still no change over the status quo 
for setuptools-using packages.)


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


Re: UnknownTimeZoneError

2009-04-07 Thread Aahz
[posted & e-mailed]

In article <7c101864-308c-468a-9053-819af2f57...@o6g2000yql.googlegroups.com>,
Brian   wrote:
>
>I'm running App Engine with Django. I'm having troubles executing
>timezone conversion via pytz. 

What version of Python are you using?  IIRC, GAE uses Python 2.3.  Do
other timezones work?  I suspect you might get more responses from a GAE
forum.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
--
http://mail.python.org/mailman/listinfo/python-list


Re: Call to PyEval_EvalCodeEx crashes in PyFrame_New with abort

2009-04-07 Thread Aahz
[posted and e-mailed]

In article <72593fd7-4500-4ea9-b54e-1637d07b5...@s12g2000prc.googlegroups.com>,
grbgooglefan   wrote:
>
>I've emabedded Python(2.6) in my C++ application and using on Solaris
>5.10.  When the application calls Py_Eval, it causes an abort &
>application core dumps. But this is at random times & no pattern for
>this.

Given the lack of response, I suggest asking on the capi-sig.  The
likeliest problem is some kind of refcount error when the embedded code
calls back into your application.  Do you ever get problems when you use
pure Python code?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
--
http://mail.python.org/mailman/listinfo/python-list


Re: extracting plain text from RTF-file ?

2009-04-07 Thread Brent Bloxam

Stef Mientki wrote:

hello,

I'm looking for a library to extract plain text from RTF-files.
I found these

only RTF generation
http://pyrtf.sourceforge.net/

should be able to parse, but no download files
http://code.google.com/p/pyrtf-ng/


any suggestions ?
thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


Checkout from SVN, there's a release tagged as 0.45, but the trunk is 
newer by ~4 months

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


extracting plain text from RTF-file ?

2009-04-07 Thread Stef Mientki

hello,

I'm looking for a library to extract plain text from RTF-files.
I found these

only RTF generation
http://pyrtf.sourceforge.net/

should be able to parse, but no download files
http://code.google.com/p/pyrtf-ng/


any suggestions ?
thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


named pipe and Linux

2009-04-07 Thread akineko
Hello everyone,

I'm trying to use named pipes to fuse a Python program and a C
program.
One side creates pipes using os.mkfifo() and both sides use the same
named pipes (one side reads, another side writes). The read side uses
select.select() to wait for incoming messages and read the message
when select.select() says it is ready.

The length of the message is unknown to the read side.
I cannot use file.read() because it will block waiting for an EOF.
I cannot use file.readline() because how many lines have arrived is
unknown.
So, I needed to use os.read() with the exact number of characters to
read.

Under Solaris environment, os.fstat() provides the exact size of the
message that has arrived.
Thus, two processes can communicate each other through the named pipes
without blocking.

However, the above scheme didn't work under Linux.
Linux os.fstat() returns size=0 even the message is pending.
(I think Linux buffers the message in memory while Solaris buffers the
message in a file system)

My question is, how can I make the named pipe scheme work under Linux?
Is there any way to read the message without getting blocked?

I know this is more Linux question than Python question but I believe
many Python programmers are strong Linux programmers.

Any suggestions will be appreciated.

Best regards,
Aki Niimura
--
http://mail.python.org/mailman/listinfo/python-list


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Scott David Daniels

Grant Edwards wrote:

I realize that technically all methods are added to classes at
"run-time", but what I'm talking about is this:

   import ClientForm

   def controlEqual(self,other):
   return (self.type == other.type) and \
  (self.name == other.name) and \
  (self.value == other.value) and \
  (self.disabled == other.disabled) and\
  (self.readonly == self.readonly)

Note:
Here you are checking that self.readonly == self.readonly!
I also dislike the trailing backslashes and over-parenthesizing.
So, I'd do it like this (using the pare to avoid the backslash):
 def controlEqual(self,other):
 return (self.type == other.type
 and self.name == other.name
 and self.value == other.value
 and self.disabled == other.disabled
 and self.readonly == self.readonly)
...

   ClientForm.Control.__eq__ = controlEqual
   ClientForm.Control.__ne__ = controlNotEqual
   
   def formEqual(self,other):

   if len(self.controls) != len(other.controls):
   return False
   for (c1,c2) in zip(self.controls,other.controls):
   if c1 != c2:
   return False
   return True
   
   def formNotEqual(self,other):

   return not (self==other)
   
   ClientForm.HTMLForm.__eq__ = formEqual

   ClientForm.HTMLForm.__ne__ = formNotEqual



It works fine, but it seems like it might be dangerous (or just
bad form) to insert methods into existing classes like that.
Perhaps it would be safer to make sure that __eq__, __ne__,
and __cmp__ don't exist before adding my own?


Well, a more standard approach would be:
class FancyControl(ClientForm.Control):
def __eq__(self, other):
return (self.type == other.type
and self.name == other.name
and self.value == other.value
and self.disabled == other.disabled
and self.readonly == self.readonly)

def __ne__(self, other):
return not self.__eq__(other)

class FancyHTMLForm(ClientForm.HTMLForm):
def __eq__(self,other):
...

def __ne__(self, other):
return not self.__eq__(other)

You'd have to make sure FancyControl and FancyClientForm get used in
the app.  The latter could be insured by monkey-patching:
...
ClientForm.Control = FancyControl
ClientForm.HTMLForm = FancyHTMLForm

But substituting monkey-patching for class method insertion seems like
you are going from one quick and dirty technique to a slightly nicer
quick and dirty technique.


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: On Integration Testing

2009-04-07 Thread Scott David Daniels

Emanuele D'Arrigo wrote:

Hi everybody,

I just finished unit-testing a couple of tightly related modules and
it's now time to test them together to a) check if they do talk to
each other in the ways they should, b) check how fast they can talk to
each other. The problem? Well, the problem is that potentially they
can have some pretty varied conversations!! There are a lot of
different messages that they can exchange, from simple question-answer
messages to more complex [initial request, confirmation requested,
confirmation sent, final response, public announce] sequences of
messages. All this in a one-to-many context, that is one module is
effectively a server and can be connected to zero to N clients.

Right now I do not have a particularly cohesive, consistent approach
to this type of testing. In short, I've never done it before. I'll
start with some simple tests, i.e. adding and removing clients and
sending some simple sequences of messages, maybe pushing up the number
of clients to see how much gets done in, say, a second. But it feels
fairly "unscientific". =)

I've already googled "integration testing" and I'm in the process of
reading a variety of articles. Is there any one that the people of the
python community would like to recommend?


Seems like what you want here is Function tests.  At this point you are
testing the whole system behavior.  I presume the modules are meant to
conspire to produce a result; check that that result is produced.  If
you really have a nice set of unit tests, the integration is testing
against a misunderstanding of the interface. Your functional tests begin
with simple straightforward tests, then push at definitional boundaries.
One thing to vary is client-server interaction lifetime.  Make some
clients slow and others fast in your mix.

Performance testing (seeing how much you can accomplish in a second) is,
I'd argue, a later phase (where you need a good model of actual use).
First, go for correctness under "strange" interactions.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with subprocess Module

2009-04-07 Thread R. David Murray
Tim Golden  wrote:
> tarun wrote:
> > Hello All,
> > 
> > I've a batch file to be  invoke using a python script. The batch file has
> > pause, and the time, I need to send some command to the batch file from my
> > scripts. I placed both, the batch file (test.bat) and the python script
> > (test.py) in the same folder. And executed 'test.py'
> 
> I can't reproduce this in Python 2.6.1. The following is the
> result of cut-and-pasting your test.py & test.bat and running
> them from the command line:
> 
> 
> C:\temp>test.py
> 
> C:\temp>echo "START'
> "START'
> 
> C:\temp>pause
> Press any key to continue . . .
> 
> C:\temp>echo 'END'
> 'END'
> 
> C:\temp>
> 
> 
> 
> which is pretty much which I'd expected. I know there have been quite
> a few changes to the subprocess module between Python 2.5 & 2.6 so
> maybe you need to upgrade. (Failing that, we'd have to work a bit
> harder to pin down a specific bug in the 2.5 code since 2.5 is now
> in bugfix-release mode only, I think).

2.5 is in security-fix-only mode.

--
R. David Murray http://www.bitdance.com

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


Re: Delicious API and urllib2

2009-04-07 Thread Max Erickson
Bill  wrote:

> The delicious api requires http authorization (actually https). A
> generic delicious api post url is "https://
> username:passw...@api.api.del.icio.us/v1/posts/add?url=http://
> example.com/&description=interesting&tags=whatever".
> 

The simplest way is probably to manually add the authentication 
header, as shown here:

http://code.activestate.com/recipes/267197/#c2

This article discusses the above strategy, and a strategy using 
HTTPBasicAuthHandler with a password manager default realm (I think 
getting the realm correct is what has stymied me in my attempts to use 
handlers, rather than injecting the header):

http://www.voidspace.org.uk/python/articles/authentication.shtml 


Max

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


Re: Python C API String Memory Consumption

2009-04-07 Thread Floris Bruynooghe
On Apr 7, 2:10 pm, John Machin  wrote:
> On Apr 7, 9:19 pm, MRAB  wrote:
>
>
>
> > k3xji wrote:
> > > Interestaing I changed malloc()/free() usage with PyMem_xx APIs and
> > > the problem resolved. However, I really cannot understand why the
> > > first version does not work. Here is the latest code that has no
> > > problems at all:
>
> > > static PyObject *
> > > penc(PyObject *self, PyObject *args)
> > > {
> > >    PyObject * result = NULL;
> > >    unsigned char *s= NULL;
> > >    unsigned char *buf = NULL;
> > >    unsigned int v,len,i = 0;
>
> > >    if (!PyArg_ParseTuple(args, "s#", &s, &len))
> > >         return NULL;
>
> > >    buf = (unsigned char *) PyMem_Malloc(len);
> > >    if (buf == NULL) {
> > >            PyErr_NoMemory();
> > >            return NULL;
> > >    }
>
> > >         /* string manipulation. */
>
> > >    result = PyString_FromStringAndSize((char *)buf, len);
> > >    PyMem_Free(buf);
> > >    return result;
> > > }

I assume you're doing a memcpy() somewhere in there...  This is also
safer then your first version since the python string can contain an
embeded \0 and the strdup() of the first version would not copy that.
But maybe you're sure your input doesn't have NULLs in them so it
might be fine.

>
> > In general I'd say don't mix your memory allocators. I don't know
> > whether CPython implements PyMem_Malloc using malloc,
>
> The fantastic manual (http://docs.python.org/c-api/
> memory.html#overview) says: """the C allocator and the Python memory
> manager ... implement different algorithms and operate on different
> heaps""".
>
> > but it's better to
> > stick with CPython's memory allocators when writing for CPython.
>
> for the reasons given in the last paragraph of the above reference.

That document explictly says you're allowed to use malloc() and free()
in extensions.  There is nothing wrong with allocating things on
different heaps, I've done and seen it many times and never had
trouble.

Why the original problem ocurred I don't understand either tough.

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


Re: Best way to start

2009-04-07 Thread Tairic
I was looking for a language that seemed easier to learn and that was
powerful, so I just started learning Python myself. I'm using some
online tutorials and The book "Python Power!" by Matt Telles. Some of
the O'Reilley books looked ok (I spent a while in the bookstore
deciding), but this one was a bit cheaper, and seemed to fit the bill;
it covers most of what I wanted to know, and I found it pretty easy to
read. My only complaint is it doesn't have you spend much time coding,
so I scoured the internet for CS classes with python 'homework' and
did that. Anyways, good luck!
--
http://mail.python.org/mailman/listinfo/python-list


SoHo Book Problem

2009-04-07 Thread David C. Ullrich
Just curious - has anyone else bought the printed
Python 3 Reference Manual published by SoHo Books?

Talking about what they call "Part 2" of their Python
Documentation. I haven't looked in detail - Part 1
seems fine, but the typesetting in Part 2 is totally
screwed up.

I mean totally - on more or less every page there are lines
that are unreadable because there are words printed on top
of each other instead of next to each other!

On the one hand I don't see how the problem could be with
just my copy. On the other hand I don't see how they could
_all_ be like mine - that would mean nobody even _glanced_
at what was coming out of the press. So I'm curious whether
anyone else has a copy.

(I know it's all online. Some people like _books_...)

DU.

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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-07 Thread David Cournapeau
On Tue, Apr 7, 2009 at 11:58 PM, M.-A. Lemburg  wrote:

>>
>> This means your proposal actually doesn't add any benefit over the
>> status quo, where you can have an __init__.py that does nothing but
>> declare the package a namespace.  We already have that now, and it
>> doesn't need a new filename.  Why would we expect OS vendors to start
>> supporting it, just because we name it __pkg__.py instead of __init__.py?
>
> I lost you there.
>
> Since when do we support namespace packages in core Python without
> the need to add some form of magic support code to __init__.py ?

I think P. Eby refers to the problem that most packaging systems don't
like several packages to have the same file - be it empty or not.
That's my main personal grip against namespace packages, and from this
POV, I think it is fair to say the proposal does not solve anything.
Not that I have a solution, of course :)

cheers,

David
>
> My suggestion basically builds on the same idea as Martin's PEP,
> but uses a single __pkg__.py file as opposed to some non-Python
> file yaddayadda.pkg.
>
> Here's a copy of the proposal, with some additional discussion
> bullets added:
>
> """
> Alternative Approach:
> -
>
> Wouldn't it be better to stick with a simpler approach and look for
> "__pkg__.py" files to detect namespace packages using that O(1) check ?
>
> This would also avoid any issues you'd otherwise run into if you want
> to maintain this scheme in an importer that doesn't have access to a list
> of files in a package directory, but is well capable for the checking
> the existence of a file.
>
> Mechanism:
> --
>
> If the import mechanism finds a matching namespace package (a directory
> with a __pkg__.py file), it then goes into namespace package scan mode and
> scans the complete sys.path for more occurrences of the same namespace
> package.
>
> The import loads all __pkg__.py files of matching namespace packages
> having the same package name during the search.
>
> One of the namespace packages, the defining namespace package, will have
> to include a __init__.py file.
>
> After having scanned all matching namespace packages and loading
> the __pkg__.py files in the order of the search, the import mechanism
> then sets the packages .__path__ attribute to include all namespace
> package directories found on sys.path and finally executes the
> __init__.py file.
>
> (Please let me know if the above is not clear, I will then try to
> follow up on it.)
>
> Discussion:
> ---
>
> The above mechanism allows the same kind of flexibility we already
> have with the existing normal __init__.py mechanism.
>
> * It doesn't add yet another .pth-style sys.path extension (which are
> difficult to manage in installations).
>
> * It always uses the same naive sys.path search strategy. The strategy
> is not determined by some file contents.
>
> * The search is only done once - on the first import of the package.
>
> * It's possible to have a defining package dir and add-one package
> dirs.
>
> * The search does not depend on the order of directories in sys.path.
> There's no requirement for the defining package to appear first
> on sys.path.
>
> * Namespace packages are easy to recognize by testing for a single
> resource.
>
> * There's no conflict with existing files using the .pkg extension
> such as Mac OS X installer files or Solaris packages.
>
> * Namespace __pkg__.py modules can provide extra meta-information,
> logging, etc. to simplify debugging namespace package setups.
>
> * It's possible to freeze such setups, to put them into ZIP files,
> or only have parts of it in a ZIP file and the other parts in the
> file-system.
>
> * There's no need for a package directory scan, allowing the
> mechanism to also work with resources that do not permit to
> (easily and efficiently) scan the contents of a package "directory",
> e.g. frozen packages or imports from web resources.
>
> Caveats:
>
> * Changes to sys.path will not result in an automatic rescan for
> additional namespace packages, if the package was already loaded.
> However, we could have a function to make such a rescan explicit.
> """
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Apr 07 2009)
 Python/Zope Consulting and Support ...        http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
> 
> 2009-03-19: Released mxODBC.Connect 1.0.1      http://python.egenix.com/
>
> ::: Try our new mxODBC.Connect Python Database Interface for free ! 
>
>
>   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>           Registered at Amtsgericht Duesseldorf: HRB 46611
>               http://www.egenix.com/company/contact/
> 

Re: New online docs broken?

2009-04-07 Thread Jim Garrison

Ye Liu wrote:

On Apr 6, 6:33 pm, Jim Garrison  wrote:

I notice the online docs (at docs.python.org/3.0/index.html) were
updated today.  It seems some of the top-level pages, like
Tutorial, "Using Python", "Language Reference" are truncated
after the first few paragraphs.


Yea, same here. Hope it's going to be fixed soon.


Still broken.  I've emailed webmaster(at)python.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Scraping a web page

2009-04-07 Thread cgoldberg
> Is there anyway I
> can get almost a screen capture of the page?

I'm not sure exactly what you mean by "screen capture".  But the
webbrowser module in the standard lib might be of some help.  You can
use it to drive a web browser from Python.

to load a page in your browser, you can do something like this:

---
#! /usr/bin/env python

import webbrowser

url = 'http://www.google.com'
webbrowser.open(url)
---

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


RE: Scraping a web page

2009-04-07 Thread Support Desk
If your only interested in the Images, perhaps you want to use wget like:

 

wget -r --accept=jpg,jpeg www.xyz.org

 

or maybe this

 

http://www.vex.net/~x/python_stuff.html

 

BackCrawler   1.1

A crude web spider with only one purpose: mercilessly suck the background
images from all web pages it can find. Understands frames and redirects,
uses MD5 to elimate duplicates. Need web page backgrounds? This'll get lots
of them. Sadly, most are very tacky, and Backcrawler can't help with that.
Requires Threads.

 

 

  _  

From: Ronn Ross [mailto:ronn.r...@gmail.com] 
Sent: Tuesday, April 07, 2009 9:37 AM
To: Support Desk
Subject: Re: Scraping a web page

 

This works great, but is there a way to do this with firefox or something
similar so I can also print the images from the site? 

On Tue, Apr 7, 2009 at 9:58 AM, Support Desk 
wrote:

You could do something like below to get the rendered page.

Import os
site = 'website.com'
X = os.popen('lynx --dump %s' % site).readlines()








-Original Message-
From: Tim Chase [mailto:python.l...@tim.thechases.com]
Sent: Tuesday, April 07, 2009 7:45 AM
To: Ronn Ross
Cc: python-list@python.org
Subject: Re: Scraping a web page

> f = urllib.urlopen("http://www.google.com";)
> s = f.read()
>
> It is working, but it's returning the source of the page. Is there anyway
I
> can get almost a screen capture of the page?

This is the job of a browser -- to render the source HTML.  As
such, you'd want to look into any of the browser-automation
libraries to hook into IE, FireFox, Opera, or maybe using the
WebKit/KHTML control.  You may then be able to direct it to
render the HTML into a canvas you can then treat as an image.

Another alternative might be provided by some web-services that
will render a page as HTML with various browsers and then send
you the result.  However, these are usually either (1)
asynchronous or (2) paid services (or both).

-tkc








 

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


Expression

2009-04-07 Thread Lydia
I am working on calculating one of the fields in a feature class based on other 
2 fields. The logic is, 
A (the resulting field) is calculated from B, but C and D have part of the 
value that could fill the blank of B, which meaning that combine three fields 
of values can make A.

Field A is what I need.

The data looks like: .

A   B   C   D
 2  2
 5  5
 44
 6   6


 cur = gp.UpdateCursor(data)
row = cur.Next()
gp.CalculateField_management(data, "A", "[B]", "VB", "")
   
 while row:

cur.UpdateRow(row)

if  not(row.GetValue("C") == 'NULL'):
  row.SetValue("A",row.GetValue("C"));
  
elif not(row.GetValue("D") == 'NULL'):
  row.SetValue("A",row.GetValue("D"));

row = cur.Next()

del cur
del row

But the out looks like only B was calculated to A successfully. C&D are not in 
A. 

I guess there must be something wrong with the code, but I am very new to 
Python, and not familiar with the expression. Could anybody help ?  PS. I am 
coding Python with ARCGIS.

Thanks a lot.

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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-07 Thread M.-A. Lemburg
On 2009-04-07 16:05, P.J. Eby wrote:
> At 02:30 PM 4/7/2009 +0200, M.-A. Lemburg wrote:
>> >> Wouldn't it be better to stick with a simpler approach and look for
>> >> "__pkg__.py" files to detect namespace packages using that O(1)
>> check ?
>> >
>> > Again - this wouldn't be O(1). More importantly, it breaks system
>> > packages, which now again have to deal with the conflicting file names
>> > if they want to install all portions into a single location.
>>
>> True, but since that means changing the package infrastructure, I think
>> it's fair to ask distributors who want to use that approach to also take
>> care of looking into the __pkg__.py files and merging them if
>> necessary.
>>
>> Most of the time the __pkg__.py files will be empty, so that's not
>> really much to ask for.
> 
> This means your proposal actually doesn't add any benefit over the
> status quo, where you can have an __init__.py that does nothing but
> declare the package a namespace.  We already have that now, and it
> doesn't need a new filename.  Why would we expect OS vendors to start
> supporting it, just because we name it __pkg__.py instead of __init__.py?

I lost you there.

Since when do we support namespace packages in core Python without
the need to add some form of magic support code to __init__.py ?

My suggestion basically builds on the same idea as Martin's PEP,
but uses a single __pkg__.py file as opposed to some non-Python
file yaddayadda.pkg.

Here's a copy of the proposal, with some additional discussion
bullets added:

"""
Alternative Approach:
-

Wouldn't it be better to stick with a simpler approach and look for
"__pkg__.py" files to detect namespace packages using that O(1) check ?

This would also avoid any issues you'd otherwise run into if you want
to maintain this scheme in an importer that doesn't have access to a list
of files in a package directory, but is well capable for the checking
the existence of a file.

Mechanism:
--

If the import mechanism finds a matching namespace package (a directory
with a __pkg__.py file), it then goes into namespace package scan mode and
scans the complete sys.path for more occurrences of the same namespace
package.

The import loads all __pkg__.py files of matching namespace packages
having the same package name during the search.

One of the namespace packages, the defining namespace package, will have
to include a __init__.py file.

After having scanned all matching namespace packages and loading
the __pkg__.py files in the order of the search, the import mechanism
then sets the packages .__path__ attribute to include all namespace
package directories found on sys.path and finally executes the
__init__.py file.

(Please let me know if the above is not clear, I will then try to
follow up on it.)

Discussion:
---

The above mechanism allows the same kind of flexibility we already
have with the existing normal __init__.py mechanism.

* It doesn't add yet another .pth-style sys.path extension (which are
difficult to manage in installations).

* It always uses the same naive sys.path search strategy. The strategy
is not determined by some file contents.

* The search is only done once - on the first import of the package.

* It's possible to have a defining package dir and add-one package
dirs.

* The search does not depend on the order of directories in sys.path.
There's no requirement for the defining package to appear first
on sys.path.

* Namespace packages are easy to recognize by testing for a single
resource.

* There's no conflict with existing files using the .pkg extension
such as Mac OS X installer files or Solaris packages.

* Namespace __pkg__.py modules can provide extra meta-information,
logging, etc. to simplify debugging namespace package setups.

* It's possible to freeze such setups, to put them into ZIP files,
or only have parts of it in a ZIP file and the other parts in the
file-system.

* There's no need for a package directory scan, allowing the
mechanism to also work with resources that do not permit to
(easily and efficiently) scan the contents of a package "directory",
e.g. frozen packages or imports from web resources.

Caveats:

* Changes to sys.path will not result in an automatic rescan for
additional namespace packages, if the package was already loaded.
However, we could have a function to make such a rescan explicit.
"""

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 07 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

2009-03-19: Released mxODBC.Connect 1.0.1  http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services Gmb

Re: PyXML and Python-2.6

2009-04-07 Thread Paul Boddie
On 7 Apr, 16:01, Andrew MacKeith  wrote:
> The Python.org "SIG for XML Processing in Python" page indicates that
> "The SIG, through the mailing list and the PyXML project hosted on
> SourceForge...".
>
> The PyXML project on SourceForge " is no longer maintained. ", so
> perhaps the SIG page could be updated.

I think the SIG pages should be migrated to the Wiki. There seems to
be some work proceeding on this:

http://wiki.python.org/moin/Special_Interest_Groups

> Is there a guide to porting projects that depend on PyXML to Python-2.6?

You could start here:

http://wiki.python.org/moin/PythonXml

Look under "W3C DOM-like libraries" for some candidates. I've
maintained libxml2dom for quite some time because I started out with
PyXML and wanted something whose maintenance was guaranteed, even if
it was me who was going to be doing it.

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


Re: Python syntax

2009-04-07 Thread dorzey
http://wiki.python.org/moin/BeginnersGuide is probably a good place to
start. I found lots of useful info from the links on this page when I
started programming in Python.

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


Re: Adding method to class at run-time: bad style?

2009-04-07 Thread Michele Simionato
On Apr 7, 4:37 pm, Grant Edwards  wrote:
> I realize that technically all methods are added to classes at
> "run-time", but what I'm talking about is this:


Raymond Hettinger solves this problem nicely with a class decorator:
http://code.activestate.com/recipes/576685/
--
http://mail.python.org/mailman/listinfo/python-list


Adding method to class at run-time: bad style?

2009-04-07 Thread Grant Edwards
I realize that technically all methods are added to classes at
"run-time", but what I'm talking about is this:

   import ClientForm

   def controlEqual(self,other):
   return (self.type == other.type) and \
  (self.name == other.name) and \
  (self.value == other.value) and \
  (self.disabled == other.disabled) and\
  (self.readonly == self.readonly)
   
   def controlNotEqual(self,other):
   return not (self==other)
   
   ClientForm.Control.__eq__ = controlEqual
   ClientForm.Control.__ne__ = controlNotEqual
   
   def formEqual(self,other):
   if len(self.controls) != len(other.controls):
   return False
   for (c1,c2) in zip(self.controls,other.controls):
   if c1 != c2:
   return False
   return True
   
   def formNotEqual(self,other):
   return not (self==other)
   
   ClientForm.HTMLForm.__eq__ = formEqual
   ClientForm.HTMLForm.__ne__ = formNotEqual

It works fine, but it seems like it might be dangerous (or just
bad form) to insert methods into existing classes like that.
Perhaps it would be safer to make sure that __eq__, __ne__,
and __cmp__ don't exist before adding my own?

-- 
Grant Edwards   grante Yow! NEWARK has been
  at   REZONED!!  DES MOINES has
   visi.combeen REZONED!!
--
http://mail.python.org/mailman/listinfo/python-list


Python syntax

2009-04-07 Thread janus99
well i'm pretty much a newb on python, it's my first comp lang. and
i've been having some diffuclties, i want to get the hang of it and
i'm wondering if u could help me understand the syntax structure.

I messed around with my own comp (windos xp) command prompt and i
currently play a mud, but the python syntax is completly diffrent, i
was wondering if u could expalin how to syntax goes, i've tried the
"hello world" but it keep displaying syntax error, i've tried entering
random commands, e.g find,search, collect,...

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


Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
MRAB wrote:
> andrew cooke wrote:
>> R. David Murray wrote:
   [...]
   try:
 dimensions.append(float(s))
   except:
 dimensions.append(float(quantization[s]))
>>> No, no, no; never use a bare except! :)
>>
>> can you explain why?  i can't think of any reason why the code would be
>> better catching a specific exception.
>>
>> as a general rule, maybe, but in this particular case i can't see a
>> reason
>> - so i'm not sure if you're just pedantically following rules or if i've
>> missed something i should know.
>>
> A bare exception will catch _any_ exception, even those you didn't
> expect (technical term: "bug" :-)); for example, if you had written:
>
>  try:
>  dimension.append(float(s))
>  except:
>  dimensions.append(float(quantization[s]))
>
> it would silently catch "NameError: name 'dimension' is not defined" and
> perform the fallback action.

true, i hadn't considered coding errors (i was thinking that something
global, like out of memory, would fail again anyway).  andrew

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


Re: Issue with subprocess Module

2009-04-07 Thread Dave Angel

Tim Golden wrote:
Dave 
Angel wrote:

tarun wrote:

Hello All,

I've a batch file to be  invoke using a python script. The batch 
file has
pause, and the time, I need to send some command to the batch file 
from my

scripts. I placed both, the batch file (test.bat) and the python script
(test.py) in the same folder. And executed 'test.py'

(Please find the source files and error below).

*I get the following error:*
Traceback (most recent call last):
  File "", line 74, in run_nodebug
  File "D:\test.py", line 4, in 
proc = subprocess.Popen(my_bat,stdin=subprocess.PIPE)
  File "C:\Python25\lib\subprocess.py", line 588, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\Python25\lib\subprocess.py", line 717, in _get_handles
c2pwrite = self._make_inheritable(c2pwrite)
  File "C:\Python25\lib\subprocess.py", line 746, in _make_inheritable
DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid

*Python Script:*
*test.py*
import subprocess,os
my_bat = os.getcwd()+'\\test.bat'
proc = subprocess.Popen(my_bat,stdin=subprocess.PIPE)
input = '\n'
proc.communicate(input)

*Batch File*
*test.bat*
echo "START'
pause
echo 'END'
Please help me with this issue.

Thanks In Advance,
Tarun

  
subprocess.Popen() is expecting the name of a program, which should 
normally have an extension of .exe   You're handing it a .bat file, 
which is not executable.  It only executes in the context of a 
command interpreter (shell), such as cmd.exe


You can probably do what you want by running "cmd.exe" and passing it 
"test.bat" as a parameter


Sounds reasonable, but isn't actually true. This works fine:


import subprocess

open ("t.bat", "w").write ("echo hello")
subprocess.Popen ("t.bat")



TJG





The docs of Popen() state that it uses CreateProcess() on Windows, so I 
didn't even try it.  Thanks for informing me it works.  I see now the 
COMSPEC manipulation in _execute_child(), but I'm still puzzled.  When I 
step through, it skips that part because we didn't specify shell= as an 
argument.   It still had not put the cmd.exe /c into the args variable 
when it called CreateProcess().  So is the Python CreateProcess more 
than a thin wrapper around Windows version?


Another bug in this program is that it does not include quotes around 
the program name.  If the current directory has a space in it, and an 
appropriately named executable happens to be in the parent directory of 
the one with the space, it'll get run instead of the batch.  For 
example, if the current directory  is   c:\source code\testand 
there's a file in the route calledc:\source.exe then it'll get run.


But what about the OP problem?  I now see it runs okay for me, both 
stand-alone and inside Komodo.  But he's getting an exception inside 
make_inheritable(), which is apparently being passed an invalid handle.


Runs OK for me, in Python 2.6 running under XP, SP3.  2.6.1 
(r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)]



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


Re: Python C API String Memory Consumption

2009-04-07 Thread Benjamin Peterson
Carl Banks  gmail.com> writes:
> However, Python apparently does leak a reference if passed a Unicode
> object; PyArg_ParseTuple automatically creates an encoded string but
> never decrefs it.  (That might be necessary evil to preserve
> compatibility, though.  PyString_AS_STRING does it too.)

Unicode objects cache a copy of themselves as default encoded strings. It is
deallocated when the unicode object its self is.




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


Re: nonlocal in Python 2.6

2009-04-07 Thread Benjamin Peterson
Kay Schluehr  gmx.net> writes:

> 
> I always wondered about the decision to omit the nonlocal statement
> from the Python 2.X series because it seems to be orthogonal to Python
> 2.5. Are there any chances for it to be back ported?

The only reason it was not backported was that either no one provided a patch or
it never got reviewed and applied.




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


PyXML and Python-2.6

2009-04-07 Thread Andrew MacKeith
The Python.org "SIG for XML Processing in Python" page indicates that 
"The SIG, through the mailing list and the PyXML project hosted on 
SourceForge...".


The PyXML project on SourceForge " is no longer maintained. ", so 
perhaps the SIG page could be updated.


Is there a guide to porting projects that depend on PyXML to Python-2.6?

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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-07 Thread P.J. Eby

At 02:30 PM 4/7/2009 +0200, M.-A. Lemburg wrote:

>> Wouldn't it be better to stick with a simpler approach and look for
>> "__pkg__.py" files to detect namespace packages using that O(1) check ?
>
> Again - this wouldn't be O(1). More importantly, it breaks system
> packages, which now again have to deal with the conflicting file names
> if they want to install all portions into a single location.

True, but since that means changing the package infrastructure, I think
it's fair to ask distributors who want to use that approach to also take
care of looking into the __pkg__.py files and merging them if
necessary.

Most of the time the __pkg__.py files will be empty, so that's not
really much to ask for.


This means your proposal actually doesn't add any benefit over the 
status quo, where you can have an __init__.py that does nothing but 
declare the package a namespace.  We already have that now, and it 
doesn't need a new filename.  Why would we expect OS vendors to start 
supporting it, just because we name it __pkg__.py instead of __init__.py?


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


Re: PIL\Tkinter and Transparencies, Rubber Lines, and Dragging Image Objects

2009-04-07 Thread W. eWatson
You got it. That lamda did look a little odd. The white background is opaque 
and the telescope is seen as green. The program will ask for a file. I 
didn't write the code.


Eric Brunel wrote:

W. eWatson wrote:

Basically, I'd like to know how one (broadly, e.g., references in Win-land)
does IP (image processing) and drawing techniques such as rubber lines, and
dragging image objects across the canvas. I know there are some pretty
powerful toolkits out there, but I'd like to limit this to PIL and Tkinter.
If it can't be done with them, then I'll consider other possibilities.  As a
starter, on the topic of transparencies, consider this program that I pulled
off the web and was posted in 1999. It purports to illustrate how one might
produce a transparency.


OK, maybe I'm dumb but:


#!/usr/bin/python
# see http://mail.python.org/pipermail/python-list/1999-May/003388.html
from Tkinter import *
import Image, ImageTk

...

HTH
 - Eric -



--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


RE: Scraping a web page

2009-04-07 Thread Support Desk
You could do something like below to get the rendered page.

Import os
site = 'website.com'
X = os.popen('lynx --dump %s' % site).readlines()







-Original Message-
From: Tim Chase [mailto:python.l...@tim.thechases.com] 
Sent: Tuesday, April 07, 2009 7:45 AM
To: Ronn Ross
Cc: python-list@python.org
Subject: Re: Scraping a web page

> f = urllib.urlopen("http://www.google.com";)
> s = f.read()
> 
> It is working, but it's returning the source of the page. Is there anyway
I
> can get almost a screen capture of the page?

This is the job of a browser -- to render the source HTML.  As 
such, you'd want to look into any of the browser-automation 
libraries to hook into IE, FireFox, Opera, or maybe using the 
WebKit/KHTML control.  You may then be able to direct it to 
render the HTML into a canvas you can then treat as an image.

Another alternative might be provided by some web-services that 
will render a page as HTML with various browsers and then send 
you the result.  However, these are usually either (1) 
asynchronous or (2) paid services (or both).

-tkc







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


Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread R. David Murray

On Tue, 7 Apr 2009 at 09:01, andrew cooke wrote:

R. David Murray wrote:

  [...]
  try:
dimensions.append(float(s))
  except:
dimensions.append(float(quantization[s]))


No, no, no; never use a bare except! :)


can you explain why?  i can't think of any reason why the code would be
better catching a specific exception.

as a general rule, maybe, but in this particular case i can't see a reason
- so i'm not sure if you're just pedantically following rules or if i've
missed something i should know.


What if the user pressed ctl-c right when the float was being converted
and appended?

Never use a bare except unless you have a specific reason to do so,
and there are very few of those.  (Yes, I should have said it that way
to start with, my apologies for going hyperbolic.)  Using because it
doesn't _look_ like it will cause issues is just asking for hard to
track down bugs :).

--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Eval Problem

2009-04-07 Thread J. Cliff Dyer
OK.

You still haven't shown the code where tableTop gets defined, so your
code is unrunnable.  However, I think your problem is that wherever
tableTop lives, it isn't part of your globals or locals in eval.  See
the documentation on evals here:

http://www.python.org/doc/1.4/lib/node26.html

Something like the following might work:

print eval(line, {'tableTop': tableTop})

Cheers,
Cliff

On Tue, 2009-04-07 at 08:38 -0400, Victor Subervi wrote:
> 
> I have excluded the code where I call the separate text files for
> printing normal text. They work. It's my code that I cannot get to
> work. For example, if I take out the "eval" part of the above, it will
> nicely print the commands, such as this:
> 
> tableTop(123,456)
> 
> which is supposed to call said fn. If I place that line in the file
> calling the text files and the bits file it will execute just fine,
> but that inevitably makes my job harder. Ideas?
> TIA,
> Victor

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


Re: Weird Tk Canvas coordinate issue

2009-04-07 Thread Tim Shannon
Here's my actual code, but I've tried to strip out the irrelevant parts, but
it should compile.  FYI, I'm using 2.6 not 3.  The code is basically drawing
a grid with points in it.  I'm fairly new to Python, so constructive
criticism is appreciated.

class Editor:

GSPACE = 80
OFFSET = 50

def __init__(self, master):

#global variables
self.grid = ex_Grid.Grid("", 10, 10)
self.showPaths = IntVar()
self.pathValid = False
self.master = master
self.isSaved = False

master.title("ex_hack Editor")
master.columnconfigure(0, weight=1)
master.rowconfigure(0, weight=1)

vscroll = Scrollbar(master)
hscroll = Scrollbar(master)

self.canvas = Canvas(master,
 height=768,
 width=1024,
 yscrollcommand=vscroll.set,
 xscrollcommand=hscroll.set)

self.canvas.grid(column=0, row=0, sticky="wens")

vscroll.config(command=self.canvas.yview)
hscroll.config(command=self.canvas.xview,
   orient="horizontal")

vscroll.grid(column=1, row=0, stick="ns")
hscroll.grid(column=0, row=1, sticky="we")
   #truncated for brevity


def draw_grid(self):
"""Loads the current grid on the application canvas
as well as into the other fields"""

#print self.OFFSET
self.canvas.delete(ALL)

#draw Border
self.canvas.create_rectangle(self.OFFSET,
 self.OFFSET,
 (self.grid.height * self.GSPACE) +
self.OFFSET,
 (self.grid.width * self.GSPACE) +
self.OFFSET,
 width=2)
self.canvas.create_rectangle(self.OFFSET-4,
 self.OFFSET-4,
 (self.grid.height * self.GSPACE) +
self.OFFSET+4,
 (self.grid.width * self.GSPACE) +
self.OFFSET+4,
 width=2)
#draw limit areas
for l in self.grid.limitAreas:
self.canvas.create_rectangle(self.g2c(l["x1"]) -
(self.GSPACE/4),
 self.g2c(l["y1"]) -
(self.GSPACE/4),
 self.g2c(l["x2"]) +
(self.GSPACE/4),
 self.g2c(l["y2"]) +
(self.GSPACE/4),
 outline="gray",
 fill="gray",
 stipple="gray12")


#draw spaces
for space in self.grid.grid.values():
self.canvas.create_line(self.g2c(space.x),
self.g2c(space.y),
self.g2c(space.x)+1,
self.g2c(space.y)+1,
tags="space")
if not space.is_empty():
self.draw_space(space)


self.canvas.config(scrollregion=self.canvas.bbox(ALL))



def g2c(self, coord):
"""Converts grid locations to their actual coordinates on
the drawing canvas"""

return (coord * self.GSPACE) + self.OFFSET + (self.GSPACE / 2)






On Mon, Apr 6, 2009 at 5:11 PM, John Posner  wrote:

> Tim Shannon wrote:
>
>> I'm new to python, so keep that in mind.
>>  I have a tk Canvas that I'm trying to draw on, and I want to start my
>> drawing at an offset (from 0) location.  So I can tweak this as I code, I
>> set this offset as a class level variable:
>>  def ClassName:
>>OFFSET = 20
>>
>>def __init__(self, master)):
>>self.canvas = Canvas(master)
>>self.canvas.create_rectangle(self.OFFSET,
>> self.OFFSET,
>> 300 + self.OFFSET,
>> 300 + self.OFFSET,
>> width=2)
>>   The weird thing is, it doesn't offset.  If I set my offset to 10, it
>> still starts drawing at 0,0. Here's the really weird part (at least to me),
>> if I put a print line right about my drawing statements to print the value
>> of the offset, it works like it should, and offsets the drawing.
>> If I remove the print line, the offset goes away.
>>  This makes no sense to me.
>>
> Tim Shannon wrote:
>
>> I'm new to python, so keep that in mind.
>>  I have a tk Canvas that I'm trying to draw on, and I want to start my
>> drawing at an offset (from 0) location.  So I can tweak this as I code, I
>> set this offset as a class level variable:
>>  def ClassName:
>>OFFSET = 20
>>
>>def __init__(self, master)):
>>self.canvas = Canvas(master)
>>self.canvas.create_rectangle(self.OFFSET,
>> self.OFFSET,
>> 300 

hashing and collision detection

2009-04-07 Thread Aaron Brady
Hi group,

You are making good on your promise from a year ago: "This is a
helpful group. Give us more to go on, and you are likely to receive
thousands of dollars worth of consulting for free."
http://groups.google.com/group/comp.lang.python/msg/2e2906eaa804812c
- Bryan Olson

I have an idea, which has probably been invented a thousand times, and
is probably a nice smooth round wheel by now, but I didn't know how to
websearch for it, and didn't try.

I am trying to floating-point collide rectangles, axis-oriented, on a
large board.  I thought about having every rectangle participate in a
hash, several units big, and merely testing collisions within high
population hashes.  The pathological case is where rectangles are very
small, and thus will be able to fit too many in a bucket.  I'm willing
to rule it out for now... for-ever.  

Most hash slots will only have zero or one members; therefore, I only
need to check collision in a small fraction of slots: those that have
two or more members.

If slots are too small, moving an object is an expensive operation,
because it will need to add and remove itself from many buckets.  If
slots are too large, too many objects can fit in them, and a simple
rectangle collision will check too many.  But for my purposes, the
balance should be a fairly large plateau.

I am thinking of a simple dictionary, which maps tuples to a list of
members in that slot: { ( 0, 0 ), ( 0, 3 ), ( 0, 6 ), ( 3,
0 ), ... }.  Where space becomes a concern, empty slots can be removed
and re-added to and from the dictionary.

Last note: the entire rectangles participate in the list of members of
a slot, not just their subsegments which reside in the particular
slot.

What are your thoughts?
--
http://mail.python.org/mailman/listinfo/python-list


Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread MRAB

andrew cooke wrote:

R. David Murray wrote:

  [...]
  try:
dimensions.append(float(s))
  except:
dimensions.append(float(quantization[s]))

No, no, no; never use a bare except! :)


can you explain why?  i can't think of any reason why the code would be
better catching a specific exception.

as a general rule, maybe, but in this particular case i can't see a reason
- so i'm not sure if you're just pedantically following rules or if i've
missed something i should know.


A bare exception will catch _any_ exception, even those you didn't
expect (technical term: "bug" :-)); for example, if you had written:

try:
dimension.append(float(s))
except:
dimensions.append(float(quantization[s]))

it would silently catch "NameError: name 'dimension' is not defined" and
perform the fallback action.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with subprocess Module

2009-04-07 Thread MRAB

Tim Golden wrote:

tarun wrote:

Hello All,

I've a batch file to be  invoke using a python script. The batch file has
pause, and the time, I need to send some command to the batch file 
from my

scripts. I placed both, the batch file (test.bat) and the python script
(test.py) in the same folder. And executed 'test.py'


I can't reproduce this in Python 2.6.1. The following is the
result of cut-and-pasting your test.py & test.bat and running
them from the command line:


C:\temp>test.py

C:\temp>echo "START'
"START'

C:\temp>pause
Press any key to continue . . .

C:\temp>echo 'END'
'END'

C:\temp>



which is pretty much which I'd expected. I know there have been quite
a few changes to the subprocess module between Python 2.5 & 2.6 so
maybe you need to upgrade. (Failing that, we'd have to work a bit
harder to pin down a specific bug in the 2.5 code since 2.5 is now
in bugfix-release mode only, I think).

BTW, echo simply echoes whatever follows it, regardless of
(or including) quotes of any sort. So just do: echo START.


I couldn't reproduce it either. I wonder whether one or both of the
files is open in an editor and whether that could cause the problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python C API String Memory Consumption

2009-04-07 Thread John Machin
On Apr 7, 9:19 pm, MRAB  wrote:
> k3xji wrote:
> > Interestaing I changed malloc()/free() usage with PyMem_xx APIs and
> > the problem resolved. However, I really cannot understand why the
> > first version does not work. Here is the latest code that has no
> > problems at all:
>
> > static PyObject *
> > penc(PyObject *self, PyObject *args)
> > {
> >    PyObject * result = NULL;
> >    unsigned char *s= NULL;
> >    unsigned char *buf = NULL;
> >    unsigned int v,len,i = 0;
>
> >    if (!PyArg_ParseTuple(args, "s#", &s, &len))
> >         return NULL;
>
> >    buf = (unsigned char *) PyMem_Malloc(len);
> >    if (buf == NULL) {
> >            PyErr_NoMemory();
> >            return NULL;
> >    }
>
> >         /* string manipulation. */
>
> >    result = PyString_FromStringAndSize((char *)buf, len);
> >    PyMem_Free(buf);
> >    return result;
> > }
>
> In general I'd say don't mix your memory allocators. I don't know
> whether CPython implements PyMem_Malloc using malloc,

The fantastic manual (http://docs.python.org/c-api/
memory.html#overview) says: """the C allocator and the Python memory
manager ... implement different algorithms and operate on different
heaps""".

> but it's better to
> stick with CPython's memory allocators when writing for CPython.

for the reasons given in the last paragraph of the above reference.

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


Re: Re: How can I change size of GUI?

2009-04-07 Thread John Posner



For what definition of 'did not work'? Seems perfectly fine to me. Just try to
add the lines:

root = Tk()
  


Try adding a line like this:

root.geometry("400x300+100+75")

... which means: "make the window 400 pixels wide and 300 pixels high,
with the upperleft corner at point (100,75)"


frm = ScrolledFrame(root)
frm.pack()
root.mainloop()
  

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


Re: Issue with subprocess Module

2009-04-07 Thread Tim Golden

tarun wrote:

Hello All,

I've a batch file to be  invoke using a python script. The batch file has
pause, and the time, I need to send some command to the batch file from my
scripts. I placed both, the batch file (test.bat) and the python script
(test.py) in the same folder. And executed 'test.py'


I can't reproduce this in Python 2.6.1. The following is the
result of cut-and-pasting your test.py & test.bat and running
them from the command line:


C:\temp>test.py

C:\temp>echo "START'
"START'

C:\temp>pause
Press any key to continue . . .

C:\temp>echo 'END'
'END'

C:\temp>



which is pretty much which I'd expected. I know there have been quite
a few changes to the subprocess module between Python 2.5 & 2.6 so
maybe you need to upgrade. (Failing that, we'd have to work a bit
harder to pin down a specific bug in the 2.5 code since 2.5 is now
in bugfix-release mode only, I think).

BTW, echo simply echoes whatever follows it, regardless of
(or including) quotes of any sort. So just do: echo START.

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


Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
R. David Murray wrote:
>>   [...]
>>   try:
>> dimensions.append(float(s))
>>   except:
>> dimensions.append(float(quantization[s]))
>
> No, no, no; never use a bare except! :)

can you explain why?  i can't think of any reason why the code would be
better catching a specific exception.

as a general rule, maybe, but in this particular case i can't see a reason
- so i'm not sure if you're just pedantically following rules or if i've
missed something i should know.

andrew

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


Re: Scraping a web page

2009-04-07 Thread Tim Chase

f = urllib.urlopen("http://www.google.com";)
s = f.read()

It is working, but it's returning the source of the page. Is there anyway I
can get almost a screen capture of the page?


This is the job of a browser -- to render the source HTML.  As 
such, you'd want to look into any of the browser-automation 
libraries to hook into IE, FireFox, Opera, or maybe using the 
WebKit/KHTML control.  You may then be able to direct it to 
render the HTML into a canvas you can then treat as an image.


Another alternative might be provided by some web-services that 
will render a page as HTML with various browsers and then send 
you the result.  However, these are usually either (1) 
asynchronous or (2) paid services (or both).


-tkc





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


nonlocal in Python 2.6

2009-04-07 Thread Kay Schluehr
I always wondered about the decision to omit the nonlocal statement
from the Python 2.X series because it seems to be orthogonal to Python
2.5. Are there any chances for it to be back ported?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Eval Problem

2009-04-07 Thread Victor Subervi
Yes, Python is dynamic, but my server farm, in this era of big business
screwing the client and cutting all services and customer support, uses such
crappy hardware that all normal code breaks, so I am forced to find
work-arounds. Here is more complete code:

ourFile = string.split(__file__, "/")
p = ourFile[len(ourFile) - 1]
p = p[: - 9]
site = ourFile[4]
bitsFile = p + ".bits"
bitties = 0
bits = []

Above, I define a bits file with bits of code that the broken python
interpreter will not evaluate with normal text, so must be separated into
its own file and called line by line and blended with separated files that
quote only text. Pain in the hind end ;)

try:
  file = open(bitsFile, "r")
  for line in file:
if len(line) > 2:
  bits.append(line)
  bitties += 1
except:
  pass
x = 1
while x <= bitties:
  file = open(p + str(x) + ".txt")
  for line in file:
print line
  print eval(bits[x - 1])
  x += 1

I have excluded the code where I call the separate text files for printing
normal text. They work. It's my code that I cannot get to work. For example,
if I take out the "eval" part of the above, it will nicely print the
commands, such as this:

tableTop(123,456)

which is supposed to call said fn. If I place that line in the file calling
the text files and the bits file it will execute just fine, but that
inevitably makes my job harder. Ideas?
TIA,
Victor

On Mon, Apr 6, 2009 at 6:37 PM, J. Clifford Dyer wrote:

> On Mon, 2009-04-06 at 15:11 -0400, Victor Subervi wrote:
> > Hi:
> > I have this code:
> >
> > x = 1
> > while x <= bitties:
> >   file = open(p + str(x) + ".txt")
> >   for line in file:
> > print line
> >   print eval(bits[x - 1])
> >   x += 1
> >
> > which throws this error:
> >
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: Traceback (most recent call
> > last):
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: File
> > "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299,
> > in HandlerDispatch\n result = object(req)
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: File
> > "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line
> > 96, in handler\n imp.load_module(module_name, fd, path, desc)
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: File
> > "/var/www/vhosts/articles.13gems.com/httpdocs/index_frame.py", line
> > 89, in ?\n print eval(bits[1])
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: File "", line 1
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: tableBottom(348,180)
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: ^
> > [Mon Apr 06 12:07:29 2009] [error] [client 190.166.0.221]
> > PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax
> >
>
> Hmm.  That's not the problem I get.  For me, your code raises:
> "NameError: name 'bitties' is not defined"
>
> It's easier for us to help you if you present a self-contained piece of
> code that exhibits the problem you've encountered.  Creating that code
> will often reveal the problem with the original code, and you will have
> solved your own problem.
>
> The other problem with your code is that you are using eval.  Eval leads
> to difficult-to-debug errors, and is usually unnecessary, given the
> dynamic nature of python.  If you need to access a class method using a
> string, you can use getattr.  If you need to dynamically select a
> function based on some condition known in another variable, you can use
> a dictionary to hash into the function.
>
> It's hard to say what might be appropriate for your situation, because
> your code fragment is so... fragmentary.
>
> Cheers,
> Cliff
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


cgi file limit size?

2009-04-07 Thread R. David Murray
davidj411  wrote:
> I am wondering where the limitation of filesize comes from when i
> upload a large file.
> it uploads when the filesize is less than 20 MB (but not if larger).
> the script does not limit the filesize so it is either an HTTP
> specification or a webserver limit, right?
> maybe my connection to the server is timing out during the upload?
> web server is IIS 6.0.
> python is 2.5.2.
> IIS webmapping does not use "-u" b/c nothing works when that option is
> used.

What are you using to do the upload?  What error message do you get?

--
R. David Murray http://www.bitdance.com

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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-07 Thread M.-A. Lemburg
[Resent due to a python.org mail server problem]

On 2009-04-03 22:07, Martin v. Löwis wrote:
>> I'd like to extend the proposal to Python 2.7 and later.
> 
> I don't object, but I also don't want to propose this, so
> I added it to the discussion.
> 
> My (and perhaps other people's) concern is that 2.7 might
> well be the last release of the 2.x series. If so, adding
> this feature to it would make 2.7 an odd special case for
> users and providers of third party tools.

I certainly hope that we'll see more useful features backported
from 3.x to the 2.x series or forward ported from 2.x to 3.x
(depending on what the core developer preferences are).

Regarding this particular PEP, it is well possible to implement
an importer that provides the functionality for Python 2.3-2.7
versions, so it doesn't have to be an odd special case.

>> That's going to slow down Python package detection a lot - you'd
>> replace an O(1) test with an O(n) scan.
> 
> I question that claim. In traditional Unix systems, the file system
> driver performs a linear search of the directory, so it's rather
> O(n)-in-kernel vs. O(n)-in-Python. Even for advanced file systems,
> you need at least O(log n) to determine whether a specific file is
> in a directory. For all practical purposes, the package directory
> will fit in a single disk block (containing a single .pkg file, and
> one or few subpackages), making listdir complete as fast as stat.

On second thought, you're right, it won't be that costly. It
requires an os.listdir() scan due to the wildcard approach and in
some cases, such a scan may not be possible, e.g. when using
frozen packages. Indeed, the freeze mechanism would not even add
the .pkg files - it only handles .py file content.

The same is true for distutils, MANIFEST generators and other
installer mechanisms - it would have to learn to package
the .pkg files along with the Python files.

Another problem with the .pkg file approach is that the file extension
is already in use for e.g. Mac OS X installers.

You don't have those issues with the __pkg__.py file approach
I suggested.

>> Wouldn't it be better to stick with a simpler approach and look for
>> "__pkg__.py" files to detect namespace packages using that O(1) check ?
> 
> Again - this wouldn't be O(1). More importantly, it breaks system
> packages, which now again have to deal with the conflicting file names
> if they want to install all portions into a single location.

True, but since that means changing the package infrastructure, I think
it's fair to ask distributors who want to use that approach to also take
care of looking into the __pkg__.py files and merging them if
necessary.

Most of the time the __pkg__.py files will be empty, so that's not
really much to ask for.

>> This would also avoid any issues you'd otherwise run into if you want
>> to maintain this scheme in an importer that doesn't have access to a list
>> of files in a package directory, but is well capable for the checking
>> the existence of a file.
> 
> Do you have a specific mechanism in mind?

Yes: frozen modules and imports straight from a web resource.

The .pkg file approach requires a directory scan and additional
support from all importers.

The __pkg__.py approach I suggested can use existing importers
without modifications by checking for the existence of such
a Python module in an importer managed resource.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 07 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

2009-03-19: Released mxODBC.Connect 1.0.1  http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Issue with subprocess Module

2009-04-07 Thread Tim Golden

Dave Angel wrote:

tarun wrote:

Hello All,

I've a batch file to be  invoke using a python script. The batch file has
pause, and the time, I need to send some command to the batch file 
from my

scripts. I placed both, the batch file (test.bat) and the python script
(test.py) in the same folder. And executed 'test.py'

(Please find the source files and error below).

*I get the following error:*
Traceback (most recent call last):
  File "", line 74, in run_nodebug
  File "D:\test.py", line 4, in 
proc = subprocess.Popen(my_bat,stdin=subprocess.PIPE)
  File "C:\Python25\lib\subprocess.py", line 588, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\Python25\lib\subprocess.py", line 717, in _get_handles
c2pwrite = self._make_inheritable(c2pwrite)
  File "C:\Python25\lib\subprocess.py", line 746, in _make_inheritable
DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid

*Python Script:*
*test.py*
import subprocess,os
my_bat = os.getcwd()+'\\test.bat'
proc = subprocess.Popen(my_bat,stdin=subprocess.PIPE)
input = '\n'
proc.communicate(input)

*Batch File*
*test.bat*
echo "START'
pause
echo 'END'
Please help me with this issue.

Thanks In Advance,
Tarun

  
subprocess.Popen() is expecting the name of a program, which should 
normally have an extension of .exe   You're handing it a .bat file, 
which is not executable.  It only executes in the context of a command 
interpreter (shell), such as cmd.exe


You can probably do what you want by running "cmd.exe" and passing it 
"test.bat" as a parameter


Sounds reasonable, but isn't actually true. This works fine:


import subprocess

open ("t.bat", "w").write ("echo hello")
subprocess.Popen ("t.bat")



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


Scraping a web page

2009-04-07 Thread Ronn Ross
I'm using the following to scrape a web page: import urllib

f = urllib.urlopen("http://www.google.com";)
s = f.read()

It is working, but it's returning the source of the page. Is there anyway I
can get almost a screen capture of the page?

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


  1   2   >