Re: Reading Java byte[] data stream over standard input

2008-05-19 Thread Giles Brown
On 19 May, 06:11, sapsi [EMAIL PROTECTED] wrote:
 Hello,
 I am using HadoopStreaming using a BinaryInputStream. What this
 basically does is send a stream of bytes (  the java type is : private
 byte[] bytes) to my python program.

 I have done a test like this,
 while 1:
 x=sys.stdin.read(100)
 if x:
 print x
 else:
 break

 Now, the incoming data is binary(though mine is actually merely ascii
 text) but the output is not what is expected. I expect for e.g

 all/86000/114.310.151.209.60370-121.110.5.176.113\n62485.9718
 118.010.241.12 60370 128.210.5.176

 However i get a 1 before all and a 4 just after \n and before the 6.

 My question is : how do i read binary data(Java's byte stream) from
 stdin?
 Or is this actually what i'm getting?

 Thanks
 Sapsi

In the past I've sent binary data to a java applet reading
DataInputStream using xdrlib from the standard library.  I'd expect
that it would work in the reverse direction so I suggest you have a
look at that.

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


Re: select.poll() and WSAPoll

2008-05-06 Thread Giles Brown
On 6 May, 14:18, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On Tue, 6 May 2008 08:36:28 -0400, inhahe [EMAIL PROTECTED] wrote:
 select.poll isn't supported on Windows, because Windows doesn't have such a
 feature, or at least it didn't until Vista.  Vista implements the same thing
 but called  WSAPoll, an article is here
 http://blogs.msdn.com/wndp/archive/2006/10/26/WSAPoll.aspx
 I hope that the next edition of Python supports select.poll on Vista, or at
 least that someone writes a third-party module fo it. As much as I'd love to
 do it myself, it's probably beyond me.. i've never used poll before nor
 written a Python extension.  also, i don't have Vista.
 Thanks

 If you use Twisted, then you can use I/O Completion Ports, which are even
 better than WSAPoll, and your code will also work with KQueue on BSD or
 EPoll on Linux without any changes. :)

 Jean-Paul

The current docs describe the I/O Completion Ports reactor as
extremely experimental.

http://twistedmatrix.com/projects/core/documentation/howto/choosing-reactor.html#auto8

Is that overly conservative or is it as bleeding edge as it sounds?

(IIRC there have been caveats like this on the Windows reactors for
a while)

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


Re: Can one get for x in y to work for non builtin classes?

2008-03-02 Thread Giles Brown
On Mar 2, 2:08 pm, Preben Randhol randhol
[EMAIL PROTECTED] wrote:
 On Sun, 2 Mar 2008 15:06:17 +0100

 Preben Randhol [EMAIL PROTECTED] wrote:
 class dbase(list):

 Sorry the definition of the class is:

 class dbase(object):

 it doesn't derive from the list class.

 Preben

http://docs.python.org/lib/typeiter.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: COM server and EXE

2008-01-08 Thread Giles Brown
On 8 Jan, 11:04, Teja [EMAIL PROTECTED] wrote:
 On Jan 8, 3:33 pm, Teja [EMAIL PROTECTED] wrote:



  Hi All,

  I have a Python COM server. I need to deploy it on various sytems.
  When I run the COM server from
  python its showing an output  Registered : sample.lib

  If I try to use the COM obj from a VB client like:

  obj = CreateObject(sample.lib)

  Its working fine without any errors

  Now I am trying to convert this COM server to an exe through py2exe
  and after I run the exe, I am
  getting the same output  Registered : sample.lib

  But If I try to use the COM obj from a VB client like

  obj = CreateObject(sample.lib)

  A console pops up saying  Registered : sample.lib and VB application
  hangs there.
  Its throwing a VB error that ActiveX object cannot be
  created..etc etc

  Any suggestions please...

  Regards,
  Tejovathi

 Here is my sample COM server and py2exe setup file

 testCOM.py

 import win32com.client
 import os.path
 import shutil
 from win32api import Sleep
 import string
 import os
 import sys
 import pythoncom

 class FirstEx:

 _reg_clsid_ = {A6DE9DF8-5EBF-48E6-889E-C71CB84CFF2C}
 pythoncom.frozen = 1
 if hasattr(sys, 'importers'):
 # In the py2exe-packed version, specify the module.class
 # to use. In the python script version, python is able
 # to figure it out itself.
 _reg_class_spec_ = __main__.FirstEx
 _reg_desc_ = My first COM server
 _reg_progid_ = SAMPLE.Lib
 _public_methods_ = ['init', 'Version']
 _public_attrs_ = ['softspace', 'noCalls']
 _readonly_attrs_ = ['noCalls']
 _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER

 def __init__(self):
 self.softspace = 1
 self.noCalls = 0

 def Version(self):
 self.noCalls = self.noCalls + 1

 # insert softspace number of spaces
 return Version: 0.0.1

 if __name__=='__main__':
 import sys
 if hasattr(sys, 'importers'):
 # running as packed executable.
 if '--register' in sys.argv[1:] or '--unregister' in
 sys.argv[1:]:
 # --register and --unregister work as usual
 import win32com.server.register
 win32com.server.register.UseCommandLine(FirstEx)
 else:
 # start the server.
 from win32com.server import localserver
 localserver.main()
 else:
 import win32com.server.register
 win32com.server.register.UseCommandLine(FirstEx)

  Here is my setup file:

 #Start here
 from distutils.core import setup
 import py2exe

 setup(options = {py2exe: {compressed: 1,
   optimize: 2,
   ascii: 1,
   bundle_files: 1}},
 zipfile = None,
 com_server = [win32com.servers.interp],
 console = [testCOM.py])
 #End here

 Here is my VB code:

 Sub subRoutine()
 Dim connection As Object
 Dim returnvalue1 As String
 Dim returnvalue2 As String
 Dim flag3 As Boolean

 Set connection = CreateObject(SAMPLE.Lib)
 returnvalue1 = connection.Version()
 MsgBox (returnvalue1)
 End Sub

 The non exe version of the COM server ie. directlly running the
 testCOM.py registers the library properly and

 in the VB application, the message box displays the version as 0.0.1.

 But, after I create the EXE file using the setup.py file and run it,
 it registers the library.

 When I run the VB application, it hangs at the line

 Set connection = CreateObject(SAMPLE.Lib)

 and displays.  ACTIVEX cannot create the object

 Any suggestions please

A quick suggestion (didn't read very carefully sorry).
Make sure you register it with --debug and use the pythonwin tools-
trace collector debugging tool.
See if you get any joy.  It may be you missed some vital library in
your py2exe
that causes a start-up time failure.

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


Re: Converting Excel time-format (hours since 1.1.1901)

2007-12-07 Thread Giles Brown
On 7 Dec, 13:20, Dirk Hagemann [EMAIL PROTECTED] wrote:
 Hello,

 From a zone-file of a Microsoft Active Directory integrated DNS server
 I get the date/time of the dynamic update entries in a format, which
 is as far as I know the hours since january 1st 1901.
 For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
 Excel I use this:
 =01.01.1901+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0)  (put
 3566839 in field A1 and switch the format of the result-field to the
 corresponding date-time format).

 You might guess what I need now: I want to calculate this somehow in
 python.

 Sorry, but I couldn't find anything in the module time or something
 else to get this calculated.

 Does anyone know how to convert this time in python to something
 usable or how to convert this formula in python?

 Thanks a lot and regards
 Dirk

Something is a bit off here...


 import datetime
 timezero=datetime.datetime(1901, 1, 1)
 timezero+datetime.timedelta(hours= 3566839)
datetime.datetime(2307, 11, 27, 7, 0)


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


Re: securing a python execution environment...

2007-11-19 Thread Giles Brown
On 19 Nov, 11:16, Chris Withers [EMAIL PROTECTED] wrote:
 Hi All,

 I'm trying to build a secure execution environment for bits of python
 for two reasons:

 - to allow users of the system to write scripts in python without
 circumventing the application's security model

 - to allow the system to have an environment where security is handled
 without having to do explicit checks in every piece of example code.

 This second point is better demonstrated by an example:

 Bad:

   from security import check,AccessDenied
   if check(someobj,'someattr'):
 print someattr
   else:
 raise AccessDenied(can't access 'someattr')
 Traceback (most recent call last):
File stdin, line ?, in ?
 AccessDenied: can't access 'someattr'

 Good:

   someobj.someattr
 Traceback (most recent call last):
File stdin, line ?, in ?
 AccessDenied: can't access 'someattr'

 Now, I think I can get a lot of this from Zope 3's security proxy
 objects, however I need to find a way to limit the importing of modules
 to, for example, prevent people importing the method that unwraps the
 proxy objects ;-)

 Have other people bumped into this problem?
 What solutions do people recommend?

 cheers,

 Chris

 --
 Simplistix - Content Management, Zope  Python Consulting
 -http://www.simplistix.co.uk

Maybe this is of interest?
http://codespeak.net/pypy/dist/pypy/doc/sandbox.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which persistence is for me?

2007-11-01 Thread Giles Brown
On 1 Nov, 11:47, Neal Becker [EMAIL PROTECTED] wrote:
 I need to organize the results of some experiments.  Seems some sort of
 database is in order.

 I just took a look at DBAPI and the new sqlite interface in python2.5.  I
 have no experience with sql.  I am repulsed by e.g.:
 c.execute(insert into stocks
   values ('2006-01-05','BUY','RHAT',100,35.14))

 ewww.  How unpythonic.  I don't want to use a string to specify what
 function to execute.  I want to call a function (c.insert?).

 Is there some other interface/database that I might like better?

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

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


Re: interfacing Python interpreter with a VB6 frontend

2007-10-03 Thread Giles Brown
On 3 Oct, 11:07, Anonymous [EMAIL PROTECTED] wrote:
 I am trying something which appears (so far), that many other people
 have not yet tried before - since I can't find any useful related
 material despite several days of searching various sites/blogs etc.

 I want to use VB6 as a front end for building a small GUI console that
 accepts python commands at the command line and executes them, returning
 any results to the VB6 window.

 This requires several steps, but the one I am having most problem
 finding info on is the ff:

 1. using/interacting the Python interpreter from VB6

 Any pointers/demos etc are very welcome - and if this has already been
 done, please let me know, so I can learn from what someone else has done

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

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


Re: VB frontend to Python COM backend

2007-07-06 Thread Giles Brown
On 6 Jul, 06:58, nik [EMAIL PROTECTED] wrote:
 I have a VB6 application that I would like to attach to a python
 communications application.

 I have come across several discussions on using VB with a Python COM
 back-end, but no starting point. I haven't had anymore luck with
 google at finding out what this method is called and where to find
 more information or examples on it. I would really appreciate it if
 someone could point me in the right direction for using python objects
 from VB.

 Thank you,
 Nik

Try this for starters...

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Giles


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


Re: Postpone creation of attributes until needed

2007-06-11 Thread Giles Brown
On 11 Jun, 11:10, Frank Millman [EMAIL PROTECTED] wrote:
 On Jun 11, 11:47 am, Phil Thompson [EMAIL PROTECTED]
 wrote:



  On Monday 11 June 2007 10:24 am, Frank Millman wrote:

   Hi all

   I have a small problem. I have come up with a solution, but I don't
   know if it is a) safe, and b) optimal.

   I have a class with a number of attributes, but for various reasons I
   cannot assign values to all the attributes at __init__ time, as the
   values depend on attributes of other linked classes which may not have
   been created yet. I can be sure that by the time any values are
   requested, all the other classes have been created, so it is then
   possible to compute the missing values.

  Properties...

  @property
  def z(self):
  return self.x * self.y

 In my simple example I showed only one missing attribute - 'z'. In
 real life I have a number of them, so I would have to set up a
 separate property definition for each of them.

 With my approach, __getattr__ is called if *any* of the missing
 attributes are referenced, which seems easier and requires less
 maintenance if I add additional attributes.

 Another point - the property definition is called every time the
 attribute is referenced, whereas __getattr__ is only called if the
 attribute does not exist in the class __dict__, and this only happens
 once. Therefore I think my approach should be slightly quicker.

 Frank

You could treat the property access like a __getattr__ and use it
to trigger the assignment of instance variables.  This would mean that
all future access would pick up the instance variables.  Following a
kind
class variable access causes instance variable creation pattern
(anyone
know a better name for that?).

You may want to construct a little mechanism that sets up these
properties
(a loop, a list of attribute names, and a setattr on the class?).

If you've got to allow access from multiple threads and aren't happy
that
the calculations being idempotent is going to be sufficient (e.g. if
the calculations are really expensive) then you need some kind of
threading
lock in your (one and only?) lazy loading function.

Ok.  Enough lunchtime diversion (I should get some fresh air).

Giles

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


Re: Decorator question

2007-05-23 Thread Giles Brown
On 23 May, 14:46, Steven W. Orr [EMAIL PROTECTED] wrote:
 I just discovered decorators. Very cool. My question is that I can't
 figure out how to make a decorator not be restricted to a function so it
 would also work on a method.

 Here's my code:

 def g(expr):
  def rpt(func):
  def wrapper(t):
  for ii in range(expr):
  print ii,
  func(t)
  wrapper.__name__ = func.__name__
  wrapper.__dict__ = func.__dict__
  wrapper.__doc__ = func.__doc__
  return func
  return wrapper
  return rpt

 @g(20)
 def f(s):
  print 's=%s'%s
 f('Hello')

 It works fine, but now I want to apply the same decorator to a class
 method.

 class KK:
  # @g(20) This obviously doesn't work.
  def f(self, s):
  print 's= %s'%s

 k = KK()
 k.f('Hello')

 Is there a trick I need?

 TIA

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

For this kind of decorator where you don't
care about the values of the arguments you
could just use *args (and perhaps **kwargs too)?

def g(expr):
 def rpt(func):
 def wrapper(*args, **kwargs):
 for ii in range(expr):
 print ii,
 func(*args, **kwargs)
 wrapper.__name__ = func.__name__
 wrapper.__dict__ = func.__dict__
 wrapper.__doc__ = func.__doc__
 return func
 return wrapper
 return rpt

Giles

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


Re: NOOOOB

2007-05-22 Thread Giles Brown
On 22 May, 11:29, jolly [EMAIL PROTECTED] wrote:
 Hey guys,

 I want to begin python. Does anyone know where a good starting point
 is?

 Thanks,
 Jem

My suggestion is have a look at www.python.org and see if you can find
what you're looking for.

Giles

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


Re: How to build a Windows service using win32?

2007-03-08 Thread Giles Brown
On 7 Mar, 16:45, Gregor Mosheh [EMAIL PROTECTED] wrote:
 Giles Brown wrote:
  Yeah.  You've cleverly decided to simplify the smallest
  possible python service by removing the
  if __name__ == '__main__':

 Ha ha. :)
 Seriously, though, I removed that long after it was failing to work, and
 have since replaced it and it didn't affect a thing.

Thats didn't affect a thing in the sense of it was still broken but
so it didn't *affect a thing* when something else about it was
broken? Yeah?

For the record I'm pretty confident that the if __name__ ==
'__main__': is necessary to stop the module attempting to handle the
command line with the pythonservice.exe looks to import the service
class when you start the service via the SCM.

Anyway you've got it working now so thats the main thing.

Giles

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


Re: SQLAlchemy and Oracle Functions?

2007-03-08 Thread Giles Brown
On 8 Mar, 22:19, Greg Copeland [EMAIL PROTECTED] wrote:
 I'm using SQLAlchemy and have a need to call an Oracle function; which
 is not the same as a stored procedure.  Can this be done directory or
 indirectly with SQLAlchemy?  If so, can someone please provide an
 example?  If not, how do I obtain the raw cx_Oracle cursor so I can
 use callfunc directly on that?

 Thanks,

 Greg

http://www.sqlalchemy.org/docs/sqlconstruction.myt#sql_whereclause_functions
?

SQLAlchemy has its own google group

http://groups.google.co.uk/group/sqlalchemy

You could try asking there too.

Giles

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


Re: How to build a Windows service using win32?

2007-03-07 Thread Giles Brown
On 7 Mar, 10:25, Gregor Mosheh [EMAIL PROTECTED] wrote:
 I'm trying to write a Win32 service. The following is straight from Python
 Programming on Win32 and it doesn't work. Is that book out of date; is
 there a new way to do services? I searched Google for hours trying to find
 any other method, and have been beating on this one for 5 more hours.

 The present error is:

 C:\Testerpython tester.py debug
 Debugging service Tester - press Ctrl+C to stop.
 Error 0xC004 - Python could not import the service's module

 type 'exceptions.ImportError': No module named service

 The code is:

 import win32serviceutil, win32service, win32event

 class Service(win32serviceutil.ServiceFramework):
 _svc_name_ = EDMS-to-CG
 _svc_display_name_ = EDMS-to-CG Syncer
 _svc_description_  = Uploaded the EDMS database to Cartograph

 def __init__(self, args):
 win32serviceutil.ServiceFramework.__init__(self, args)
 self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

 def SvcStop(self):
 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
 win32event.SetEvent(self.hWaitStop)

 def SvcDoRun(self):
 pausetime = 60 * 1000
 while True:
 stopsignal = win32event.WaitForSingleObject(self.hWaitStop,
 pausetime)
 if stopsignal == win32event.WAIT_OBJECT_0: break
 self.runOneLoop()

 def runOneLoop(self):
 import servicemanager
 servicemanager.LogInfoMsg('Running')

 win32serviceutil.HandleCommandLine(Service)

Yeah.  You've cleverly decided to simplify the smallest possible
python service by removing the

if __name__ == '__main__':

bit from the script ;)

Try adding it back it.  It worked for me.


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


Re: _ssl.pyd is buggy?

2007-02-14 Thread Giles Brown
On 14 Feb, 00:17, Giles Brown [EMAIL PROTECTED] wrote:
 Something I always found useful is to use the win32traceutil to set up
 the trace debugging tool.
 You can then see the output in the pythonwin trace collector tool.
 This is very useful for
 Python services and COM servers.

 Best of luck,
 Giles

Eh?  Wrong thread. Damn the new google groups interface!

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


Re: _ssl.pyd is buggy?

2007-02-13 Thread Giles Brown
Something I always found useful is to use the win32traceutil to set up
the trace debugging tool.
You can then see the output in the pythonwin trace collector tool.
This is very useful for
Python services and COM servers.

Best of luck,
Giles

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


Re: ctypes.com.IUnknown

2007-02-04 Thread Giles Brown
On 3 Feb, 20:36, Robin Becker [EMAIL PROTECTED] wrote:
 I find that ctypes.com has disappeared from the ctypes extension bundled
 with Python 2.5. I think I only need the IUnknown, I was playing with
 building a dialog using venster, but it needs IUnknown, STDMETHOD,
 HRESULT, GUID from ctypes.com. Any ideas what should replace those or is
 venster now too old to bother with.
 --
 Robin Becker

What about downloading the spin-off library?
http://sourceforge.net/projects/comtypes/

(I think this was created to move the com stuff out of ctypes?)

Giles

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


Re: Bad Code (that works) help me re-write!

2006-10-11 Thread Giles Brown
Matthew Warren wrote:
 I have the following piece of code,
snip
No doubt you will get some kind soul to suggest some things, but if you
want really good
answers I think you need explain why you want this command file (as
opposed to using
say a python script itself).  Are you attempting to create a simpler
syntax than Python?
A restricted set of operations?

Giles

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


Re: How do I read Excel file in Python?

2006-10-06 Thread Giles Brown
John Machin wrote:
 [EMAIL PROTECTED] wrote:
 excel_date = 38938.0
 python_date = datetime.date(1900, 1, 1) + 
 datetime.timedelta(days=excel_date)
 python_date
datetime.date(2006, 8, 11)
  
   Err, that's the wrong answer, isn't it? Perhaps it shoud be
   datetime.date(1900, 1, 29)?
 
  Actually was about to post same solution and got same results. (BTW
  Simon, the OP date is Aug 9th, 2006).  Scratched head and googled for
  excel date calculations... found this bug where it treats 1900 as leap
  year incorrectly:
  http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
 
  Plus it treats 1 jan 1900 as day 1, not 0 so just subtract 2 in the
  calc:
  python_date = datetime.date(1900, 1, 1) + 
  datetime.timedelta(days=excel_date - 2)
   python_date
  datetime.date(2006, 8, 9)
 

 ... and 2006-08-09 is only the correct answer if the spreadsheet was,
 when last saved, using the 1900 (Windows) date system, not the 1904
 (Macintosh) date system.

John,
Just for me own curiosity, is this Excel concept of date numbers same
as the OLE
concept (see http://msdn2.microsoft.com/en-us/library/82ab7w69.aspx or
search MFC DATE on MSDN).

I put in some test cases for conversion code here:
   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496683

But would be interested to add any additional info on variations on
this theme.

Cheers,
Giles

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


Re: How to avoid a warning message box when sending email via Outlook

2006-08-31 Thread Giles Brown
Tim Golden wrote:

 [Dermot Doran]

 | I'm very new to using win32com!  I just want to send an email
 | message via Outlook.  However, I keep getting an annoying
 | message box (generated by Outlook) indicating that my program
 | could be a virus.  Does anybody know how to get around this?

 As far as I've ever been able to tell, you're stuck with it.
 Obviously, in a sense, since otherwise any would-be virus /
 zombie program would simply turn the option off before using
 Outlook to send out its emails!

Can't remember the details, but last time  I looked (a year ago) you
could avoid this if you changed a setting for the user at the exchange
server.  I found this out by doing a bit of googling and
can't remember what I did, but managed to solve the same problem.

Giles

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


Re: how do you get the name of a dictionary?

2006-08-25 Thread Giles Brown
jojoba wrote:
 Does anyone know how to find the name of a python data type.
 Conside a dictionary:
 Banana = {}

 Then, how do i ask python for a string representing the name of the
 above dictionary (i.e. 'Banana')?

As many people have already said this question doesn't really make
sense, but
I thought I'd add my explanation of why in the hope that it might
help...

Think of python objects as being like mobile phones.  They only really
have a number.
Asking what their name is like asking for the name of a mobile phone
(bluetooth excepted).
A particular mobile phone only has a name when entered into the address
book (aka
namespace) of another mobile (or whatever) and the choice of name is
down to the owner of the address book.

Now I'm going to eat my cake.

Giles

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


Re: hi,every body. a problem with PyQt.

2006-05-24 Thread Giles Brown
The tool to create a python script from a Qt designer .ui file is
called pyuic.

I suggest you have a google for pyqt tutorial pages.

I found this one for example:
http://wiki.python.org/moin/JonathanGardnerPyQtTutorial

Regards,
Giles

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


Re: A C-like if statement

2006-02-23 Thread Giles Brown
But maybe we're talking about string methods so to get an exception
we'd want to use index instead of find.

Giles

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


Re: How to move optparse from main to function?

2006-02-23 Thread Giles Brown
Doesn't the module documentation ...

http://docs.python.org/lib/optparse-putting-it-all-together.html

... tell you what you need?

Giles

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


Re: Is it possible to use python to unit test C++ code?

2005-12-22 Thread Giles Brown
I have used the Python version of this:

http://cxxtest.sourceforge.net/

unit testing framework successfully (but not heavily).

Hth,
Giles Brown

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


Re: Would this be Guido's pen?

2005-09-26 Thread Giles Brown
Yeah and of course
http://www.masterlock.com/promos/python/8413python_lock.shtml is
Guido's security cable too. 

Giles

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


Re: Software bugs aren't inevitable

2005-09-16 Thread Giles Brown

Michael Sparks wrote:
 The problem that these sorts of approaches don't address is the simple
 fact that simple creating a formal spec and implementing it, even if
 you manage to create a way of automating the test suite from the spec
 *doesn't guarantee that it will do the right thing*.
snip
 As a result I'd say that the subject Software bugs aren't inevitable
 is not true.

I think you can argue (I would) that any behaviour that is in the
specification this isn't right is not a software bug, but a
specification error.  This obviously puts the focus on specification
errors, but standard development processes don't guarantee the absence
of specification errors either.

Btw, I'm not arguing that this type of approach is widely applicable,
but the you'll always face specification errors argument isn't well
reasoned I think.  

Cheers,
Giles

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Giles Brown
Paddy wrote:
 I was wondering what Praxis thought of Python, and how good it would be
 if a Praxis engineer gave a critique of Python as a part of a flow for
 producing low bug-count software.

I used to work at Praxis about 4 years ago and Perl was their scripting
language of choice at that time as I recall :)

 This is rather like how doctest can check the test and expected result
 given in a doc-string against the implementation given in the function;
 indeed I wrote up such an example at work and circulated it amongst the
 resident perl mongers. - Gosh it fealt good :-)

I am probably a bit out of date with this and never used it in anger,
but there are basically two levels of annotation.

The first is data flow and is used to specify what variables affect
what.  That is, you may specify for a function that the resulting
variable z is affected by the values of variable x and y (thats the
basic idea, there is a bit more to it of course).  The toolset checks
that your code matches your annotations.  It relies on not having the
different names for the same variable (not something you can guarantee
in Python really :).

The next level of annotations is for proving your code matches a
specification in Z.  So your annotations are part of that proof and can
again be checked automatically.


 So, How do I get feedback from Praxis, Do they already read
 comp.lang.py?

Are there no email links on: http://www.praxis-his.com/sparkada/ ?

Hth,
Giles Brown


 
 Cheers,  Paddy.

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


Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
For my sins I'm a MS Windows user at work and apart from that I have a
small problem ...

I like to write python scripts to do small tasks and then double click
on them from the file explorer to run them.

Unfortunately I'm not perfect and sometimes I make mistakes and have
unhandled exceptions or syntax errors when running the scripts.  The
default behaviour is to shut down the command window which leaves you
no chance of reading the exception.

In the past I have created .bat wrapper files that just call the python
interpreter, but it is a bit tedious to have to create a matching .bat
file for every script.  So I came up with the following approach...

1. Copy python.exe to pythoncmd.exe
2. Add a bit of stuff to sitecustomize.py
3. Add a special first line to every python script and give it a .cmd
extension.

The stuff added to sitecustomize.py (actually I created a
sitecustomize.py for this) is:

import sys
import os

if os.path.basename(sys.executable) == 'pythoncmd.exe':

def cmdexcepthook(*args):
sys.__excepthook__(*args)
# Let use confirm/inspect error
os.system('pause')

sys.excepthook = cmdexcepthook


The special first line is:

@pythoncmd -x %~f0 %*  exit /b

(In the python.org FAQ for windows it says
@setlocal enableextensions  python -x %~f0 %*  goto :EOF
but since I have no idea which is right I chose the simpler looking
one)

This approach does require pythoncmd.exe to by in your %PATH% but I
think that is reasonable ;)

I am a bit disappointed I couldn't think of a way of deciding if I was
running a .cmd file in sitecustomize.py so that I could just use the
normal python.exe.  Using a renamed interpreter .exe is just a trick
for detecting when I am running .cmd files, but it means that the
script won't run on another machine that hasn't had the python.exe
copied to pythoncmd.exe on it.  Which is a shame.

So my question.  Is there a better way?  I'm not really happy with this
approach.  Should I stop worrying and go and play my new ukulele?
Answers please.

Giles

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


Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Nah.  You're missing my point.  I only want the command window not to
be closed if there is an *exception*.  Picky I know, but there you go.

Giles

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


Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Thanks for your replies.

I think we might have a miscommunication here as (to my understanding)
neither of your replies actually solve my problem.

After all, the function raw_input is just another way of blocking until
user input.  I was already doing that using os.system('pause').

To recap, what I'm looking for is a way of setting up specific scripts
(not every script) so that when I double click on it, it runs, but if
there is an exception (even a SyntaxError in the top level script) I
get a traceback in a window that doesn't disappear immediately.

The tricky elements of this are:
1) It can't be done using code in the script itself (such as using an
import statement) because in the presence of a SyntaxError the import
statement is never run.  This is why I was looking at sitecustomize.py
2) I don't want to do unusual exception/atexit hooking for every script
and so need to be able to detect when I am running one of these .cmd
type scripts.

I hope this clarifies things.  I had hoped that my question was worded
sufficiently well to indicate this wasn't a straight-down-the-line
newbie question (I've been programming in Python for seven years now).
Obviously it wasn't.  My apologies.

Giles

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


Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Hi Larry,
I mentioned how I am already using sys.excepthook in my initial
posting.
What I'm looking for is:
1) Is there any better way of solving the problem than setting
sys.excepthook in sitecustomize.py?
2) Or is there a better way of detecting when I am running a .cmd based
script than the method I proposed?
Hope this clears up what I'm asking for.
Thanks,
Giles

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


Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Hooray! We have a winner!

Thanks Duncan.  Your improved shell line will do the job very nicely.
:)

(btw, the problem with import sethook at the top of the script is
that syntax errors in the top-level will prevent the import from being
run meaning we don't get our traceback anymore.)

Giles

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


Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Addendum - forgot to mention that the problem with checking the
extension of sys.argv[0] is that sys.argv[0] is not set until after
sitecustomize.py is run (and it needs to be in sitecustomize.py not an
imported module due to the top-level SyntaxError problem mentioned in
my other post).

Cheers again for your elegant solution.
Giles

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


Re: odbc and python

2005-06-03 Thread Giles Brown
MM wrote:
 Are there any other odbc packages other than the win32all and mxodbc
 ones? The win32all odbc.pyd can't access table structure info like
 SQLColumns, and mxobdc requires a commercial license which is
 unjustifiable for this tiny project. Any other OS alternatives for
 win32?. Thanks.

You could potentially make the ODBC calls using ctypes a la:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303667

Not tried this myself and imagine it could be a bit tedious.

Cheers,
Giles

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


Re: how to config a comserver in a customize dll?

2005-05-23 Thread Giles Brown
But just to muddy the waters, using py2exe you can package your COM
server as a .dll in its own right.

Cheers,
Giles Brown

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