[Tutor] Starting a browser instance and passing a parameter to it.

2007-11-28 Thread Don Taylor
I am trying to start a browser from within a Python program and I want 
it to show a local file on my system and I want to pass a parameter to 
that browser page that will be picked up by some Javascript embedded in 
the page.

I have this code:

import webbrowser
webbrowser.open("file:///D:/EclipseWS/XML-RPCTesting/webbrowser.htm?open=8001")

when executed it does bring up the web-page ok, but the parameter 
(?open=8001) is lost.  If I try the same thing with an http url then it 
works as expected.  However, I do not want to run a web-server on my 
machine.

Is there any way I can get a browser to display a web-page from a 
file-based url and pass a parameter to the code running in that page?

FWIW.  I am trying to use a web page as the GUI for a Python program. 
The Python program is started in the usual way and it initiates its web 
page GUI.  The Javascript in the web page then communicates with the 
Python program using XML-RPC.  The parameter I need to pass is the port 
number to be used for this communication.

I am currently using WinXP/Firefox but I want this to work on all 
platforms and browser combos.

TIA.


Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a browser instance and passing a parameter to it.

2007-11-29 Thread Don Taylor
Alan Gauld wrote:

> What are you using for the XML-RPC server? Doesn't that need to be a
> web server of some sort anyhow? XML-RPC communicates using http...
> 

I am using simpleXMLRPCServer.  Yes, XML-RPC does use http as its 
transport protocol, but it does not have to run in the context of a 
web-server.  You can run XML-RPC 'under' CGI but that costs a lot in 
performance (continual re-loads) and, more importantly, forces a REST 
model on to the XML-RPC server.  I am treating XML-RPC as a socket 
server that happens to use http for its transport.

> You seem to be making a fairly easy task very complicated.
> 

Yes, quite possibly.  Just for fun, I am experimenting with ways to 
build portable desktop GUI applications - where portability includes 
independence from window managers.  I am trying to use a browser as the 
window manager for a (Python) application.

 > Remember that portable JavaScript is quite hard to write due to
 > browser
 > differences.

I plan to use something like Google Web Toolkit for the browser-side 
code.  GWT (and many others tools and libraries) abstracts away browser 
differences.  I don't plan to manipulate the browser DOM directly.

Sadly, the Pyjamas project has died - Pyjamas promised to be like GWT, 
but used Python instead of Java for writing the ui code.

Thx.  Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a browser instance and passing a parameter toit.

2007-11-29 Thread Don Taylor
Alan Gauld wrote:

> Have you considered writing a small Java applet (maybe using Jython to 
> do so?)
> that could communicate with the Javascript and send the XML-RPC stuff 
> to
> your server?
>

Well, I am on a Procrustean bed here - Java is not available on one of 
my target platforms.


> In fact, if JavaScript can send the 
> XML-RPC
> you wouldn't need the applet, just get the JavaScript code send the 
> message
> to fetch the parameter from the server once the page is loaded. Hmm,

I can do that in JavaScript as soon as I know the port used for the 
XML-RPC server...

> but you
> want to pass the port number... So until you get that you  are 
> stuck...Hmmm
> that probably isn't going to work! :-)
> 

No, I don't think so but I have a couple of ideas to try.

First is to construct the apps opening web-page on the fly in the 
XML-RPC server before the server instantiates the page.  I can generate 
some custom Javascript in this page that has the port number embedded 
within it.  Then the Javascript can store it in a cookie or pass it on 
to the next page as a parameter.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a browser instance and passing a parameter toit.

2007-11-29 Thread Don Taylor
Don Taylor wrote:

> 
> First is to construct the apps opening web-page on the fly in the 
> XML-RPC server before the server instantiates the page.  I can generate 
> some custom Javascript in this page that has the port number embedded 
> within it.  Then the Javascript can store it in a cookie or pass it on 
> to the next page as a parameter.
> 

Ok, this worked for me.  From a Python application, I constructed a file 
containing:



   
 
   <!--
 
location.replace("file:///D:/EclipseWS/XML-RPCTesting/webbrowser.htm?port=8001");
   //-->
 

 Redirector
   
   
   Re-directing ...
   


used webbrowser.open to fire it up in a browser.  This file immediately 
redirects as above and includes the ?port=8001 in the url on the target 
page.  I am able to extract the port number using a bit of Javascript in 
the final page.

So, I think that bit will work for me.

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a browser instance and passing a parameter to it.

2007-11-29 Thread Don Taylor
Kent Johnson wrote:

> I can't decide if this is brilliant or crazy or both :-)

Definitely crazy, but I hope both.

In addition, I want to be able to run these apps on a Nokia Internet 
Tablet...
> 
> I guess what you get from XMLRPC is an almost-free way to expose 
> functions to the browser. 

Yes, you got it.  Well, free as in a ~30 ms round-trip overhead.

But it forces you to build the UI entirely in
> javascript.

Yes, that is rather sad.

> 
> I wonder if you wouldn't be better off starting with a simple web server 
> such as CherryPy and building a standard web application on that...you 

Too big, too heavy, too RESTy and you have to maintain your own state.

I also want this to look and install like a genuine desktop application. 
  To start it you just double-click the server which then initiates the 
browser.  To shut it down, you just close the browser window and the 
server (eventually) goes away on its own.

> would be swimming with the stream then, instead of across it.

No fun in that.

> 
>  > I plan to use something like Google Web Toolkit for the browser-side
>  > code.  GWT (and many others tools and libraries) abstracts away browser
>  > differences.  I don't plan to manipulate the browser DOM directly.
> 
> GWT is targeted to Java developers, probably something like Dojo or YUI 
> would be more appropriate.
>

Well, my choice is between Java and Javascript.  GWT is nice because it 
has really good Eclipse-based tool-chain including a debugger.  It also 
generates pretty tight Javascript code.Dojo or YUI mean wrestling 
directly with Javascript and its not so good tool-chain.  However, I am 
probably going to try more than one approach to see what I like best.

Pyjamas would have been nice as it was a port of GWT that had a Python 
to Javascript compiler instead of a Java to Javascript compiler.  Sadly, 
the project seems to have disappeared from the web.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a browser instance and passing a parameter to it.

2007-11-29 Thread Don Taylor
Eric Brunson wrote:

> Definitely,  or even just CGIHTTPServer.
> 

No, I don't think so.  I am not a RESTafarian.  :-)

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting a browser instance and passing a parameter to it.

2007-11-30 Thread Don Taylor
Eric Brunson wrote:
> Don Taylor wrote:
>> Eric Brunson wrote:
>>
>>   
>>> Definitely,  or even just CGIHTTPServer.
>>>
>>> 
>> No, I don't think so.  I am not a RESTafarian.  :-)
>>   
> 
> Forgive my inexperience with the SimpleXMLRPCServer, but I didn't think 
> it provided state any more than any other connection oriented server?  
> Am I wrong about that?
> 

Eric:

I am sorry about being flippant in my earlier reply to you - I am not 
really that religious about this stuff.  I am just interested in using 
xml-rpc or json-rpc as a way to glue a browser UI onto a stand-alone 
Python application.

As I understand it, a web-server like Apache is a connection-oriented 
server and so is a stand-alone XML-RPC server.  Both open a port and 
listen for, and respond to, requests on that port until they are 
terminated.

A CGI server application behind Apache, however, is effectively a 
connectionless server.  It accepts one request at a time from any 
client, processes that request, and sends a response to the requester.

A server application embedded within an XML-RPC server (as a set of 
function or method calls) is still connection-oriented.  There is only 
one process running.

If you create a stand-alone SimpleXMLRPCServer (that is not behind a 
web-server, but having its own socket service) then you can write 
service routines that work almost as if those routines were part of the 
client's process.  If the service routine saves something, opens a file 
or whatever, then the next time the client calls that server the state 
is still there.  You could write service routines to open a file, write 
to it and close it.  If you called these routines in order from the 
client then they would do just what you expected.  (This is assuming the 
server only has one client - which is what I am doing).  The server runs 
as a long-running process - it runs until it is terminated.

If you contrast that with a CGI web server application then the server 
application is short-lived - it exists only for the duration of a single 
transaction with its client. Because it can have no memory of what 
happened on previous instantiations it must somehow pass state back at 
the end of a transaction so that the web client can re-send it to the 
server the next time that the client wants some work done.  Cookies and 
url rewriting are a couple of techniques for passing state back and 
forth between client and server.

All of the above is a gross simplification, is probably bs and I am sure 
is stuff that you know better than I do.

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] function signatures for callbacks

2006-03-21 Thread Don Taylor
I have a piece of code that wants a callback from a client:

The code looks like this right now:

class pawprints:
 def __init__(self, callback_fun = None)
 ...


at the client calling site I have something like this:

def printme(modulename, codename, lineno, line):
 ...

paws = pawprints(callback_fun = printme)
 ...


My questions:

1) Is this the correct way to do this (the code does seem to work OK).

2) If so, then is there a way to specify the function signature at 
callback site rather than the client site?

It seems backwards to me because because if I get the function 
definition wrong in the client site then I get a traceback to the 
callback site - which is meant to be an opaque library that the client 
should not have to know about.

Thanks,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function signatures for callbacks

2006-03-24 Thread Don Taylor
Danny:

Thanks for this, I think that I can use this idea.

When I first read your response I did not see how it helped me, but now 
I realise that it allows me to add some context to the exception message.

I don't suppose that I can change the traceback to point at the 
definition of f2 instead of shout() but I can give a better hint to the 
user at why this went wrong.

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



Re: [Tutor] function signatures for callbacks

2006-03-24 Thread Don Taylor
Danny Yoo wrote:

> 
> ###
> ## Pseudocode for sending 'x' to every listener (untested)
> class CallbackError(Exception):
> pass
> 
> for l in self.listeners:
> try:
> l(x)
> except Exception, e:
> raise CallbackError, ("%s failed" % l.__name__, e)
> ###
> 
Danny:

Ok I tried this and it is good.

I don't think that I need the _internal_shout anymore as this code 
already wraps the exception handling and I can decide what I want to 
display in the above except statement.

Unless I am missing something?

Thanks again,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Doctest, object references and the use of ellipses

2006-04-01 Thread Don Taylor
Hi:

I am trying to use Doctest and am having trouble using the ellipsis 
feature when trying to match an object reference.

Here is the code:

 def add_change_listener(self, listener):
 '''

 Returns list of listeners just for testing.
 >>> def mock_listener():
 ...pass
 >>> model = Model()
 >>> model.add_change_listener(mock_listener) #doctest: +ELLIPSIS
 []

 '''

 self.listeners.append(listener)
 return self.listeners

This is what I get back:

Trying:
 model.add_change_listener(mock_listener) #doctest: +ELLIPSIS
Expecting:
 []
**
File "D:\ProgrammingProjects\MVCExperiments\src\mvcmodel.py", line 14, 
in __main__.Model.add_change_listener
Failed example:
 model.add_change_listener(mock_listener) #doctest: +ELLIPSIS
Expected:
 []
Got:
 []

As far as I can tell from the Doctest documentation this test should 
have passed.

Any help on what I am doing wrong would be much appreciated.

Thanks,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Doctest, object references and the use of ellipses

2006-04-01 Thread Don Taylor
Kent Johnson wrote:
> Don Taylor wrote:
> 
>>Hi:
>>
>>I am trying to use Doctest and am having trouble using the ellipsis 
>>feature when trying to match an object reference.
> 
> 
> What version of Python are you using? The ELLIPSIS comment was added in 
> Python 2.4.
> 

I am using 2.4.2

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python tutor

2006-04-01 Thread Don Taylor
Noufal Ibrahim wrote:
> Greetings all,
>Are there any programs for python that offer an "interactive" tutorial?
> Something on the lines of the builtin emacs tutorial (which is


While it is not really what you had in mind, I have just discovered the 
Python Challenge - and it is a lot of fun.

http://www.pythonchallenge.com/

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python tutor

2006-04-01 Thread Don Taylor
Alan Gauld wrote:

> 
> I tried at one stage producing JavaScripted versions of the code in my
> tutor where you could step through the code with the active line being
> highlighted in colour - like a debugger. But after struggling for ages to 
> get
> one short example to work it seemed too much like hard work!
> 

I found this site the other day and I thought that it would not be too 
difficult to generalize this technique into a simple tool for authoring 
tutorials.

http://www.jorendorff.com/toys/

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Doctest, object references and the use of ellipses

2006-04-01 Thread Don Taylor
Tim Peters wrote:

> That "should work", provided there aren't differences in whitespace
> that are invisible to us in this medium.  For example, if, in your
> source file, there's actually a (one or more) trailing space on your
> line of expected output, then it would _not_ match the actual output. 
> Try adding +REPORT_NDIFF to your #doctest options; that will point out
> all differences (including whitespace).


Oh, thank you!

Yes, there was a trailing whitespace.  And yes I did read the manual 
that warned about this but I guess it did not register deep enough into 
my reptile brain (you know, the Python brain).

I will try not to do this again (and I probably won't).

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Version of a .pyc file

2006-04-18 Thread Don Taylor
I want like to write a script to scan all of the .pyc on my pythonpath 
to find out if they were built with Python 2.3 or 2.4.

How can I tell if a .pyc file was built with 2.3 or 2.4?

Thanks,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Version of a .pyc file

2006-04-19 Thread Don Taylor
Terry Carroll wrote:

>>How can I tell if a .pyc file was built with 2.3 or 2.4?
> 
> 
> There's a "Magic Number" in the first 2 or 4 bytes, (depending on whether 
> you consider the \r\n part of the MN).
> 
> 
f = open("pycfile.pyc", "rb")
magictable = {'\x3b\xf2\r\n': "2.3", '\x6d\xf2\r\n' : "2.4"}
magic = f.read(4)
release = magictable.get(magic,"unknown")
print "Python release:", release
> 
> Python release: 2.4
> 

I have used Terry's code to write a script to find all of the the .pyc 
files on my system that were compiled with the 2.3 version of the 
compiler, and I have removed these files.

But my underlying problem still occurs: somewhere somebody is calling 
for the 2.3 version of the Python vm .dll and not finding it.  This is 
happening under Pydev/Eclipse and my only recourse is to blow Eclipse 
away using Task Manager.

So maybe I have  a .pyd file somewhere that is a 2.3 extension.

Is there a way to examine .pyd files to see if they were built for 
Python 2.3?

Finally, are there any other possible file extension types that I should 
be looking at?

Thanks,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Version of a .pyc file

2006-04-20 Thread Don Taylor
Kent Johnson wrote:
> Don Taylor wrote:
> 
>>Finally, are there any other possible file extension types that I should 
>>be looking at?
> 
> 
> .pyo is like a .pyc but compiled with optimizations on.
> 
Hi Kent:

No, I really meant a .pyd file which is Python's name for a .dll which 
conforms to the Python requirements to be a Python extension written in 
C/C++.

But, I should check my .pyo files as well so thanks for this.

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Version of a .pyc file

2006-04-20 Thread Don Taylor
Terry Carroll wrote:
> On Wed, 19 Apr 2006, Don Taylor wrote:
> 
> 
>>But my underlying problem still occurs: somewhere somebody is calling 
>>for the 2.3 version of the Python vm .dll and not finding it.  This is 
>>happening under Pydev/Eclipse and my only recourse is to blow Eclipse 
>>away using Task Manager.
> 
> 
> Don --
> I've had some pretty good luck using Process Explorer, freeware from 
> SysInternals, to locate processes that are using a particular file or DLL 
> and shutting them down.  I don't know how well that will work for you, 
> because it might just ID Eclipse as the culprit, with no further 
> information, and you already know that.  But its tree view may give you 
> more info.
> 
> It's a great utility in any event.
> 
> http://www.sysinternals.com/Utilities/ProcessExplorer.html
> 
> I'm gathering from the reference to DLLs that you're running under 
> Windows.  If I misunderstand, ignore this; Process Explorer is for Windows.
> 

Terry:

Yes I am using Windows so I will take a look at Process Explorer.

Thanks,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI

2006-04-21 Thread Don Taylor
Eric Walker wrote:

> Ok,
> If I can get it for free, I might as well go with say wxPython. Thanks

However, you really should spend a few bucks buying the recently 
published "wxPython In Action" book by Noel Rappin and Robin Dunn (the 
designer of wxPython).  It will save you lots of time.

You also might like to check out wxGlade which is a FOSS GUI designer 
for wxPython.  It will play happily with your chosen editor.  I have 
tried most of the available GUI designers and liked this one the best 
although is is a little brittle.

http://wxglade.sourceforge.net/

Another _very_ promising system is Dabo but this is not quite ready for 
prime-time.  I think that Dabo is going to be a dynamite system for 
building GUI db apps.

http://dabodev.com/

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Version of a .pyc file

2006-04-21 Thread Don Taylor
Terry Carroll wrote:

> I've had some pretty good luck using Process Explorer, freeware from 

That did it, and it was a .pyd file that was giving me problems, thanks 
once again Terry.

Process Explorer is _very_ nice and will certainly stay on my machine.


Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A Python idiom that I don't get

2006-04-25 Thread Don Taylor
I am trying to get some existing CPython 2.4 code working under Jython 
(2.1) and I am puzzled by a line in the following function.  It seems to 
be a Python 2.4 idiom that is opaque to me.

The line is:
 prefix = os.path.commonprefix(filter( bool, lines ))

and I don't understand what that 'bool' is doing.  Or rather, I think 
that I see what it is doing, but I am not sure - and I don't much like it.

filter is the built-in filter and it requires a callable returning a 
bool as the first argument.  It seems that 'bool' without arguments is a 
callable that always evaluates to True (or at least non-zero) so this 
'bool' always returns True.  Is this really true (sic) by intention or 
is it just an implemenation artifact?

I tried replacing 'bool' with 'True' but that won't work because True is 
not callable.

I replaced 'bool' with 'lambda True: True' as in:
 prefix = os.path.commonprefix(filter( lambda True: True, lines ))
and that does seem to work - and pass its unit tests.

Have I got this right and can I replace 'bool' with the lambda expression?

Or is there a clearer way to do this?

Thanks,


Don.

The full function is:

def find_common( lines ):
 """find and return a common prefix to all the passed lines.
 Should not include trailing spaces
 """

 if not lines: return ""

 # get the common prefix of the non-blank lines. This isn't the most
 # efficient way of doing this by _far_, but it _is_ the shortest
 prefix = os.path.commonprefix(filter( bool, lines ))
 if not prefix: return ""

 # this regular expression will match an 'interesting' line prefix
 matched = re.match("(\s*\w{1,4}>|\W+)", prefix)
 if not matched: return ""

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A Python idiom that I don't get

2006-04-26 Thread Don Taylor
w chun wrote:
> it sounds like you did not develop the original code.  it seems to
> work... why are you trying to replace it?  are you refactoring?

No it is not my code. I am trying to get it running in Jython which does 
not support the bool function.  I may refactor it after I get it working 
in Jython, but right now I have added the following function to my module:

def bool(value):
 if value:
 return 1
 return 0

and this seems to work and lets me leave the original source code 
untouched for now.


> i like both of these better... they will perform better than with
> bool().  of the two, it would be interesting to study which one's
> faster... and why.
>

Performance is not really important but I will try some instrumentation 
on this code.

FWIW.  I am trying to write a Jython extension to the Pydev/Eclipse IDE 
that will re-wrap selected comment blocks and docstrings.  Pydev now 
supports extensions written in Jython - see: http://pydev.sourceforge.net/

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Refactoring

2006-05-11 Thread Don Taylor
Philip Smith wrote:
> This is a subject which seems to pop up periodically so apoliogies but I 
> wonder whether anyone can help:
>  
> a)Is there yet an alternative Python refactoring tool to bicycle 
> repair man (bike)?
>  

Find and Replace ;-)


> b)If not is there any documentation on the appropriate use of bike?  
> I can't seem to get to grips with it unaided.
>  

BRM is nicely integrated into Eclipse/Pydev but BRM itself is incomplete 
and brittle, I only trust it to make changes in the current module.

There does not seem to be any prospect of an update to BRM any time soon.

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: eclipseplugin for python

2006-05-11 Thread Don Taylor
shivayogi kumbar wrote:
> 
> 
> I downloaded  python plugin for eclipse by directly downloading zip file 
> and extracting under eclipse folder; because it could not update via 
> PROXY. It was suggested to update plugins from eclipse IDE only. I am 
> unable to use that plugin(Python) in eclipse. Is it a problem of proxy 
> or any other? I want to know how to configure eclipse to adapt to python.
> Let me know latest version of eclipse and python plugin.
> Thanks.
>

I don't know about your proxy question - that sounds like a question for 
the Eclipse folks.

I have installed the Pydev from the .zip file and as long you have 
unpacked it and moved the contents into the correct folders under 
Eclipse then it should work fine.

Read this and follow it carefully and you should be OK:
http://www.fabioz.com/pydev/manual_101_install.html

The .zip install procedure is about halfway down.

If you still have problems then try asking Fabio Zadrozny on the Pydev 
user list.  He is always very helpful.

http://sourceforge.net/forum/forum.php?forum_id=293649
or
pydev-users@lists.sourceforge.net

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Data hiding in Python.

2006-12-18 Thread Don Taylor
I am working my way through 'wxPython in Action' by Noel Rappin and 
Robin Dunn and came across this comment about data hiding in their 
explanation of the MVC pattern:

".. the View... should never get to see the private internals of the 
Model.  Admittedly, this is difficult to enforce in Python, but one way 
to help enforcement it is to create an abstract Model class that defines 
the API that the View can see.  Subclasses of the Model can either act 
as proxies for an internal class that can be changed, or can simply 
contain the internal workings themselves.  The first option is more 
structured, the second easier to implement."

I like the idea of data hiding but Googling 'Python data hiding' yields 
lots of discussion to the effect that it cannot/should not be done.

So what do the authors mean?  They do not give any examples of this 
technique (at least not so far as I have read in the book) so I have 
been trying to figure something out.  And then, is it worth the trouble?

Any suggestions?  Preferably with code fragments.

Here is what I have got so far:

A calling module:
-caller.py-

import model

if __name__ == '__main__':
 model.methodA() # test a method call interface
 testInstance = model.TestClass() #test a class generation interface
 testInstance.methodB() # test a method call within the new class
---

The actual model module, which does not contain any (or much) 
implementation code:
-model.py--

import innermodel

__implementation = innermodel.Implementation()

def methodA():
 "Example of a method interface."
 __implementation.methodA()

def TestClass():
 "Example of a class interface."
 return __implementation.TestClass()

---

and then the actual implementation code:
-innermodel.py-

class Implementation:
 def __init__(self):
 print "Implementation initializing..."

 def methodA(self):
 print "Implementation methodA called."

 class TestClass:
 def __init__(self):
 print "TestClass initializing..."

 def methodB(self):
 print "TestClass methodB called."
---

I am not sure if this is what they mean, and if so which is this - a 
proxy for an internal class that can be changed, or does it simply 
contain the internal workings.

It seems to provide some degree of data hiding, but perhaps too much? 
You cannot figure out from the model.py file what are the available 
methods for the TestClass class.  I guess that these could be documented 
in the TestClass docstring.

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MVC/MVP examples of how to implement it

2006-12-18 Thread Don Taylor
Basil Shubin wrote:
> Hi friends!
> 
> I have read articles about MVC/MVP, but still can't get a clue to how 
> implement it in really working application :-( Because I better 
> understand with ready to use examples, can you provide link to free 
> python+GUI application which implements MVC/MVP design?
> 
This is the best description - by far - that I have seen for the MVC 
pattern.

http://groups.google.ca/group/comp.lang.python/msg/f8990a2c666a793c?hl=en&;

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MVC/MVP examples of how to implement it

2006-12-19 Thread Don Taylor
Basil Shubin wrote:
> Hi friends!
> 
> I have read articles about MVC/MVP, but still can't get a clue to how 
> implement it in really working application :-( Because I better 
> understand with ready to use examples, can you provide link to free 
> python+GUI application which implements MVC/MVP design?
> 
Here is another example of MVP in Python/wxPython.

http://wiki.wxpython.org/index.cgi/ModelViewPresenter

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What is a mixin class?

2007-01-17 Thread Don Taylor
I have a vague idea what a mixin class is, I would like to get a better 
handle on it.

It is a term that is used quite often in Python circles, but I can't 
find a definition.

I guess that because of multiple inheritance Python does not need a 
formal way of specifying mixin classes so I presume that there is some 
conventional interpretation/coding that is followed for mixin classes.

So, what constitutes a mixin class and what are the conventional ways to 
denote them in code?

Don.

I notice that Ruby has single inheritance plus mixin classes so maybe 
somebody who knows Ruby could throw some light on in what way a mixin is 
different from normal superclass.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is a mixin class?

2007-01-17 Thread Don Taylor
Don Taylor wrote:
> I have a vague idea what a mixin class is, I would like to get a better 
> handle on it.
> 

Thanks for the information and the links, I have a much better idea 
about mix-ins now.  I also found the following informative:

http://www.linuxjournal.com/article/4540
and
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498124

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Multi-line code that uses \ in doctest

2007-02-06 Thread Don Taylor
When I try to use something like:

 >>> hexStringNums = ('1', '2', '3', '4', '5', '6',\
...  '7', '8', '9','0')

or:

 >>> for hexString in hexStrings:
... for x in hexString:
... if ((not x in hexStringChars) and
... (not x in hexStringNums)):
... print hexString+ \
... " is not a hex string."
... break

in doctest (Python 2.4) I get an invalid syntax error around the line 
continuation marker, e.g.

Failed example:
 hexStringNums = ('1', '2', '3', '4', '5', '6',... 
'7', '8', '9','0')
Exception raised:
 Traceback (most recent call last):
   File "C:\PYTHON24\lib\doctest.py", line 1243, in __run
 compileflags, 1) in test.globs
   File "", line 1
  hexStringNums = ('1', '2', '3', '4', '5', '6',... 
  '7', '8', '9','0')
^
  SyntaxError: invalid syntax

I can fix this by not using \ line continuations, but is there a way to 
get doctest to parse these lines as I expect?


Thanks,


Don Taylor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What should go in a module?

2007-02-07 Thread Don Taylor
I am looking for advice on module size.

When I first came upon Python my initial thought was to package very
closely-related things into modules. Modules would be small, and may
contain a single class or function.  An application would consist of
lots of modules.

Now I am wondering if this is the best strategy.   Is it better to 
package everything together into a single module and use separate 
modules only when that code might usefully be shared between different 
applications.

I am really just asking about applications here, not libraries or 
frameworks.

TIA.

Don.





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Generating pdf files in epydoc on Windows

2007-02-09 Thread Don Taylor
Does anyone know what is needed to install to get epydoc to generate pdf 
files on Windows.  Besides epydoc itself of course.

Thanks,

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Visual Basic versus Python.. What to choose??

2007-02-20 Thread Don Taylor
Asrarahmed Kadri wrote:

> I want to develop an application which uses a database and some forms to 
> enter/modify the database.
> The application should also generate reports based on some fields.
>  
> What should I be using? Python or VB...

That is both a religious question, and fighting words...
>  
> I want to use Python.. IN that case, what should be my choice for the 
> Database..
>

Ahhh, that is ok then.

Assuming this is not a web-based application, then take a look at the 
Dabo framework:

http://dabodev.com/

It supports MySQL, PostgreSQL, Firebird and SQLite backends at the moment.

Take a look through the screencasts to get an idea about what Dabo can 
do for you.

http://dabodev.com/documentation

Don.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor