Re: pyqt and Eric 3

2005-04-28 Thread Phil Thompson
On Thursday 28 April 2005 3:46 am, ChrisH wrote:
 In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] says...

  Are there any Eric 3 users out there?
 
  I've been thinking about trying it.
 
  Also, if I write scripts for internal use only at my company, do I have
  to purchase a Qt or pyqt license?
 
  Thanks for the info!
  Chris

 Oops.. I forgot to say I'm writing code for Windows.

Until the GPL versions of Qt4 and PyQt4 are available for Windows (and eric 
has been ported to it) you will need Qt and PyQt licenses.

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


Re: Which IDE is recommended?

2005-04-28 Thread Ville Vainio
 pydev == Brian Beck [EMAIL PROTECTED] writes:

pydev * PyDev isn't yet mature enough to make it practical for me

What version? PyDev has increased in maturity quite a bit lately.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


dynamically generating temporary files through python/cgi

2005-04-28 Thread poisondart
Is there a way to dynamically generate temporary files (such as an
html, xml or text file) in Python?

I'm not sure if I'm explaining myself clearly as I've no clue how to
describe this mechanism. I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time. These
files usually have some phony string for their filenames...like it's
been md5 hashed or something.

Is there a group of library functions that allow this? I imagine that
if i manually go and allocate a bunch of timers to monitor files, it
would be really expensive in load. Or perhaps is this a client-side
mechanism?

Thanks,
- poisondart

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


Re: Which IDE is recommended?

2005-04-28 Thread bruno modulix
Dave Cook wrote:
(snip)
Once upon a time emacs was considered bloated,
That was when 640ko ought to be enough ?-)
but it's tiny compared to eclipse.
Yeps. And a *lot* faster. And in not that much bigger than Vim in fact...
--
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for 
p in '[EMAIL PROTECTED]'.split('@')])
--
http://mail.python.org/mailman/listinfo/python-list


bytecode non-backcompatibility

2005-04-28 Thread Maurice LING
Martin v. Löwis wrote:
Maurice LING wrote:
I've emailed to catelog-sig mailing list and is still waiting to hear
something. Currently, I have no idea of the structure of PyPI. I hope I
can hear from them soon and generate some starting points...

Posting questions is not the only way to find answers. The source code
of PyPI is available: sf.net/projects/pypi.
Regards,
Martin

I've browsed the source codes of PyPI in sf.net, nothing pops up as very 
useful to me... I reckoned that sitting in here or hoping for replies 
from catelog-sig isn't going to help much.

On that, I've prototyped a very simple proof-of-concept of what I have 
in mind, regarding a Fink-like tool for Python's 3rd party libraries 
management. Please bear in mind that this is a proof-of-concept 
prototype, really bare bones. It can be found in 'centipyde' module in 
sf.net/projects/ib-dwb. In case the CVS hadn't updated by the time 
someone reads this, the directory layout is this:

../centipyde
../centipyde/centipyde.py
../centipyde/pgkinfo
../centipyde/pgkinfo/ply15.info
ply15.info contains the following text (pretty much modelled against Fink):
package=ply15
maintainer=.
dependencies=.
downloadurl=http://systems.cs.uchicago.edu/ply/ply-1.5.tar.gz
prebuildscript=tar zxvf ply-1.5.tar.gz
sourcedir=ply-1.5
buildscript=python setup.py build
installscript=sudo python setup.py install
centipyde.py is the following:
=

Author: Maurice H.T. Ling [EMAIL PROTECTED]
Copyright (c) 2005 Maurice H.T. Ling
Date created : 28th April 2005

PKGINFOPATH = 'pkginfo'
INSTALL_LOG = 'install.log'
import os
import string
import sys
def install_package(package_name):
f = open(os.getcwd() + os.sep + PKGINFOPATH + os.sep + package_name 
+ '.info', 'r')
install_info = {}
for line in f.readlines():
line = string.split(line, '=')
if line[1][-1] == os.linesep:
install_info[line[0]] = string.strip(line[1][:-1])
else: install_info[line[0]] = string.strip(line[1])
f.close()
print Package Installation Information:  + str(install_info)

os.system('curl -O ' + str(install_info['downloadurl']))
preinstall = []
preinstall = string.split(install_info['prebuildscript'], ';')
for cmd in preinstall: os.system(cmd)
cwd = os.getcwd()
print cwd
os.chdir(os.path.join(os.getcwd(), install_info['sourcedir']))
print os.getcwd()
buildscript = []
buildscript = string.split(install_info['buildscript'], ';')
for cmd in buildscript: os.system(cmd)
installscript = []
installscript = string.split(install_info['installscript'], ';')
for cmd in installscript: os.system(cmd)
if sys.argv[1] == 'install':
install_package(sys.argv[2])
=
When I run python centipyde.py install ply15, PLY1.5 gets downloaded 
from David Beazley's website, uncompressed and installed into the 
site-package.

All comments and code donations are welcomed.
Cheers
Maurice
--
http://mail.python.org/mailman/listinfo/python-list


Re: regex over files

2005-04-28 Thread Robin Becker
Skip Montanaro wrote:
..
I'm not sure why the mmap() solution is so much slower for you.  Perhaps on
some systems files opened for reading are mmap'd under the covers.  I'm sure
it's highly platform-dependent.  (My results on MacOSX - see below - are
somewhat better.)
I'll have a go at doing the experiment on some other platforms I have 
available. The problem is certainly paging related. Perhaps the fact 
that we don't need to write dirty pages is moot when the system is 
actually writing out other processes' pages to make room for the 
incoming ones needed by the cpu hog. I do know that I cannot control 
that in detail. Also it's entirely possible that file caching/readahead 
etc etc can skew the results.

All my old compiler texts recommend the buffered read approach, but that 
might be because mmap etc weren't around. Perhaps some compiler expert 
can say? Also I suspect that in a low level language the minor overhead 
caused by the book keeping is lower than that for the paging code.

Let me return to your original problem though, doing regex operations on
files.  I modified your two scripts slightly:
..
I took the file from Bengt Richter's example and replicated it a bunch of
times to get a 122MB file.  I then ran the above two programs against it:
% python tscan1.py splitX
n=2112001 time=8.88
% python tscan0.py splitX
n=2139845 time=10.26
So the mmap'd version is within 15% of the performance of the buffered read
version and we don't have to solve the problem of any corner cases (note the
different values of n).  I'm happy to take the extra runtime in exchange for
simpler code.
Skip
I will have a go at repeating this on my system. Perhaps with Bengt's 
code in the buffered case as that would be more realistic.

It has been my experience that all systems crawl when driven into the 
swapping region and some users of our code seem anxious to run huge 
print jobs.
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyqt and Eric 3

2005-04-28 Thread lbolognini
http://kscraft.sourceforge.net/convert_xhtml.php?doc=pyqt-windows-install.xhtml

Lorenzo

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


Re: interactive web graphics

2005-04-28 Thread Maksim Kasimov

java are also wide-spread browser plugin with interactive and multimedia
capabilities,
and java-applets can be written with python (jython)

Diez B. Roggisch [EMAIL PROTECTED] wrote:
news:[EMAIL PROTECTED]

 you are after _might_ be done using macromedia flash - as that is a
 wide-spread browser plugin with interactive and multimedia capabilities.
 But how to do it in flash I've no idea - after all I'm a pythoneer.



 Alternatively, SVG might be an option - but I'm not sure if its mature and
 powerful enough.

 --
 Regards,

 Diez B. Roggisch


--
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]


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


Re: Which IDE is recommended?

2005-04-28 Thread Brian Beck
Ville Vainio wrote:
 What version? PyDev has increased in maturity quite a bit lately.

PyDev 0.9.2 with Eclipse 3.0.2. It's a nice effort currently, but some
of my issues are:

* Code completion doesn't work properly for me, and I have no idea why.
I have to type the '.' then ADD A SPACE, *then* press Ctrl+Space. If I
type Ctrl+Space after the dot, nothing happens. So basically it's not
very useful, because I'd have to go back and get rid of the stupid space.

* Code completion isn't nearly as fast as WingIDE.

* Auto-indentation could be smarter, such as dedenting after a 'return'
statement.

* The Problems view finds 52 errors in a file with 0.

* Run As doesn't dump me into an interactive shell.

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which IDE is recommended?

2005-04-28 Thread Brian Beck
Oh yeah, and what's with not being able to configure the code completion
key sequence. How about *no* key sequence? That's the way every other
IDE I've used does it. This is more like semi-automatic code completion.

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which IDE is recommended?

2005-04-28 Thread Brian Beck
Brian Beck wrote:
What version? PyDev has increased in maturity quite a bit lately.

I realize 0.9.3 is the latest release, but the installation fails
through the Eclipse updater:

Unable to complete action for feature PyDev for Eclipse due to errors.
  Unable to create file
/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py.
[/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py
(No such file or directory)]

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically generating temporary files through python/cgi

2005-04-28 Thread Michael Hoffman
poisondart wrote:
I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time...
Is there a group of library functions that allow this?
No.
The easiest way, in my mind would be to store the files in a directory 
according to the hour they were requested, for example, a file generated 
between 2 p.m. and 3 p.m. today:

http://www.example.com/temp/20050428T14/d41d8cd98f00b204e9800998ecf8427e.html
Then you can have a cron job that runs every hour that deletes 
everything in the temp directory generated 24 hours ago.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question about python code distribution...

2005-04-28 Thread Stephen Prinster
[EMAIL PROTECTED] wrote:
 Hi,
 
 I am sure that this question might have come up repeatedly. Companies
 may not want to distribute their python code in source form. Even
 though pyc files are one option, it gets inconvenient to distribute
 bunch of them . If there is some way to bundle pyc files (akin to
 .jar), it would be really nice. I understand that pyc files are not
 hard to decompile (from my reading of previous posts) and module
 startup times may be longer if they have to be read from an archive.
 Neverthless, an option to distribute in the form of an archive is
 attractive. Has this ever been considered for Python? If one were to
 consider it, what would be pros and cons of such approach?
 
 Any comments are appreciated.
 
 Thanks,
 Raghu.
 

Looks like it's in the works:
http://peak.telecommunity.com/DevCenter/PythonEggs

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


Re: Which IDE is recommended?

2005-04-28 Thread Brian Beck
Brian Beck wrote:
 I realize 0.9.3 is the latest release, but the installation fails
 through the Eclipse updater:
 
 Unable to complete action for feature PyDev for Eclipse due to errors.
   Unable to create file
 /opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py.
 [/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py
 (No such file or directory)]

Okay, sorry for spamming the newsgroup so much, but I installed 0.9.3
properly and the same issues I mentioned before persist. Code completion
for imports or locals don't work at all -- the space thing was PyDev
just listing all the built-ins, with none of my modules or locals
included in the list.

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which IDE is recommended?

2005-04-28 Thread Ville Vainio
 Brian == Brian Beck [EMAIL PROTECTED] writes:

Brian Oh yeah, and what's with not being able to configure the
Brian code completion key sequence. How about *no* key sequence?
Brian That's the way every other IDE I've used does it. This is
Brian more like semi-automatic code completion.

It works like that for me. 

I type:

import os
os.wait a second

And I get the list of completions. 

Perhaps you are just being impatient?

Also, make sure that Preferences/pydev/code completion has
Autocomplete on '.' box checked.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which IDE is recommended?

2005-04-28 Thread Ville Vainio
 Brian == Brian Beck [EMAIL PROTECTED] writes:


Brian Okay, sorry for spamming the newsgroup so much, but I
Brian installed 0.9.3 properly and the same issues I mentioned
Brian before persist. Code completion for imports or locals don't
Brian work at all -- the space thing was PyDev just listing all
Brian the built-ins, with none of my modules or locals included
Brian in the list.

This is another thing that works fine for me. Have you tried starting
with an empty file to see whether there is something in your source
file that trips up pydev?

Whining at the pydev mailing list might work as well.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which IDE is recommended?

2005-04-28 Thread Brian Beck
Ville Vainio wrote:
 Perhaps you are just being impatient?
 
 Also, make sure that Preferences/pydev/code completion has
 Autocomplete on '.' box checked.

Yeah, that option is enabled. I actually just discovered that it does
work in the example you give and for other modules in the standard
library. But calls to standard library modules only occur maybe twice in
any of my big scripts... the problem is I've been trying code completion
with third-party modules and local classes, which still doesn't work.

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: interactive web graphics

2005-04-28 Thread Fuzzyman
Hello Michael,

Eckhoff, Michael A wrote:
 Hello,

 I failed to locate a list for pygtk, so I thought I'd
 ask my question here. Is it possible to write CGI
 scripts that bring up a GUI (as in GTK+, QT, Tk, ...)
 or an openGL display that is windowed inside a web
 browser?

 The answer would seem to me to be no, since the
 client could be Windows or Linux. I'd like to
 display some pretty graphics (scientific visualisation),
 but web applications are not my background.

 I would like a form with progress bars, but I guess
 that would have to be implemented in some special way.
 Sorry if these questions are ill-posed; I am just
 getting my feet wet with python.


There is a simpler, but still non-trivial, way of adding server-client
interactivity - using javascript. If you are just moving square bars
around you could use the javascript XML http request functions and
dynamically change the images (including using PIL - and maybe some of
the graph generating stuff from 'pythonweb' web modules - to
dynamically generate images server side).

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python


 Thanks,
 Michael E

 PS Congratulations for having such wonderful documentation
 on all things python.

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


Setting win32 console title from Python

2005-04-28 Thread runes
Hi,
I'm trying to set the title of the console window (CMD.EXE) in Windows.
I want it set to the basename of the current directory and it should
stay after the script has finished.

Now, the console title is easily set with the DOS-command 'title
NewTitle'. But I'd like to do this from a Python script.

os.system('title NewTitle') will not do, because it spawns a new
process.

win32api.SetConsoleTitle('NewTitle') will not do either, because the
NewTitle is reset as soon as the script finishes.

Chris Gonnerman's WConio
http://newcenturycomputers.net/projects/wconio.html
has a settitle() method and
WConio.settitle(NewTitle) does what I want, but not under CMD.EXE,
only COMMAND.EXE.

Any ideas?

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


Re: (PHP or Python) Developing something like www.tribe.net

2005-04-28 Thread Mir Nazim
Ok I get your point.
Well actually my application is small in the begining, but then may be
will a large one when we want to add more features.

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


Re: Problem with sending a variable(python) while using html

2005-04-28 Thread Kent Johnson
Hansan wrote:
Hi.
Sorry forgot to post a non-working example
That could be
print a href=script.py?id=, variable,  ', some text  input 
type=hidden name=eventid value='''+str(variable_name)+''/a

I know that it isnt very creative, but I am having a hard time getting html 
to work together with python.

When the link some text is clicked I want to send both the first variable 
called variable and the second one(variable_name) to the script (script.py)
As Hal pointed out you need to put both variables into the link. Also, you should be url-encoding 
your values using urllib.quote_plus(); otherwise variable values containing characters like = will 
cause trouble. So for the link I would use

from ulrlib import quote_plus
link = a href='script.py?id=%seventid=%s' % (quote_plus(str(variable)), 
quote_plus(str(variable_name)))

Then you may need urllib.unquote_plus() on the reading end depending on the 
server.
Kent
--
http://mail.python.org/mailman/listinfo/python-list


Re: (PHP or Python) Developing something like www.tribe.net

2005-04-28 Thread remi
 CherryPy and Quixote are for programming in the small

May I ask why you say that ?
Just because a framework is light and easy doesn't mean it doesn't
scale well ...

 I have not idea how they scale in the large.

Well, I do :-)
Among many other sites, CherryPy powers the BackOffice system of a big
cinema chain in the UK. The web app gets hammered all day long by
hundreds of users whose work is completely dependent on this web app.
It has 500 different web forms (everything is data driven) and the code
is about 30K lines of python/cherrypy code (if the code wasn't
data-driven it would be a *lot* more ...).

If it gets accepted, there will be a talk about this system at
EuroPython ...

Remi.

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


Re: delete will assure file is deleted?

2005-04-28 Thread TZOTZIOY
On Wed, 27 Apr 2005 17:28:04 +0200, rumours say that Fredrik Lundh
[EMAIL PROTECTED] might have written:

 import errno
 
 try:
   ...
 except OSError, exc:
 if exc.errno == errno.ENOENT: # file inexistant
  ...
 elif exc.errno == errno.EPERM: # no permissions
  ...

make that

elif exc.errno in (errno.EACCES, errno.EPERM): # no permissions

Yep, you're right (you wouldn't be a bot otherwise, right?-)

BTW I remember a post last summer about subclassing OSError (found it:
http://groups.google.com.gr/groups?selm=87llgxuyf5.fsf%40pobox.com --not
exactly what I remembered, but close.)

I think throwing subclasses of OSError based on errno would make life
easier --always assuming that Python requires POSIX conformance on all
platforms.  I will give it a try RSN...
-- 
TZOTZIOY, I speak England very best.
Be strict when sending and tolerant when receiving. (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Internet Explorer, COM+, Javascript and Python

2005-04-28 Thread Roger Upole
Something like this should be close:

import win32com.client, pythoncom
ie=win32com.client.Dispatch('internetexplorer.application')
ie.Visible=1
ie.Navigate('somepagewithjavascript.html')
id=ie.Document.Script._oleobj_.GetIDsOfNames('somejsfunction')
res=ie.Document.Script._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_METHOD, 
True, parameter or tuple of parameters )

   hth
   Roger


Ishpeck [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I need to make IE execute javascript in a web page with COM+ and
 Python.

 Similarly to the way they do it in this article. . .

 http://www.codeproject.com/com/jscalls.asp
 



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


Re: Which IDE is recommended?

2005-04-28 Thread Ville Vainio
 Brian == Brian Beck [EMAIL PROTECTED] writes:

Brian Ville Vainio wrote:
 Perhaps you are just being impatient?
 
 Also, make sure that Preferences/pydev/code completion has
 Autocomplete on '.' box checked.

Brian Yeah, that option is enabled. I actually just discovered
Brian that it does work in the example you give and for other
Brian modules in the standard library. But calls to standard
Brian library modules only occur maybe twice in any of my big
Brian scripts... the problem is I've been trying code completion
Brian with third-party modules and local classes, which still
Brian doesn't work.

From the faq at http://pydev.sourceforge.net/faq.html:

How do I set the PYTHONPATH for code completion to work in my project?


To set the PYTHONPATH for code completion purposes, you have to right
click your project root, choose properties-PyDev PYTHONPATH and set
it. The Restore PYTHONPATH button should get your enviroment
PYTHONPATH and automatically set it. If it does not work, check python
interpreter is correctly set (see questions above).

Does this help?

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sending a variable(python) while using html

2005-04-28 Thread Hansan
Thanks for you help, it is working now :D

Take care


Kent Johnson [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hansan wrote:
 Hi.

 Sorry forgot to post a non-working example

 That could be
 print a href=script.py?id=, variable,  ', some text  input 
 type=hidden name=eventid value='''+str(variable_name)+''/a

 I know that it isnt very creative, but I am having a hard time getting 
 html to work together with python.

 When the link some text is clicked I want to send both the first 
 variable called variable and the second one(variable_name) to the script 
 (script.py)

 As Hal pointed out you need to put both variables into the link. Also, you 
 should be url-encoding your values using urllib.quote_plus(); otherwise 
 variable values containing characters like = will cause trouble. So for 
 the link I would use

 from ulrlib import quote_plus
 link = a href='script.py?id=%seventid=%s' % 
 (quote_plus(str(variable)), quote_plus(str(variable_name)))

 Then you may need urllib.unquote_plus() on the reading end depending on 
 the server.

 Kent 


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


Re: How remove directories with the content in the platform independent way?

2005-04-28 Thread Andy Leszczynski
Jason Mobarak wrote:
There's also the shutil module, which is platform independant.
http://docs.python.org/lib/module-shutil.html
...see the rmtree function
Thanks, this is what I was looking for.
A.
--
http://mail.python.org/mailman/listinfo/python-list


Getting a list of classes in the current module/auto introspection

2005-04-28 Thread Andy Leszczynski
Hi,
I have a following problem. Let's say there is a module which could be 
imported or run as __main__. It is going to contain hundreds of classes, 
something like that:

import moduleA
from moduleB import *
class A:
pass
class B:
pass
class C:
pass
[...]
I would like to be able to get references (or names) of all of them but 
excluding stuff from moduleA and module B. Is there any pythonic/elegant 
way to do that?

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


Re: dynamically generating temporary files through python/cgi

2005-04-28 Thread Michael Hoffman
Michael Hoffman wrote:
The easiest way, in my mind would be to store the files in a directory 
according to the hour they were requested, for example, a file generated 
between 2 p.m. and 3 p.m. today:

http://www.example.com/temp/20050428T14/d41d8cd98f00b204e9800998ecf8427e.html 
Depending on the filesystem you use, generating thousands of files in a 
single directory might be somewhat inefficient. So you might want to 
make subdirectories based on the MD5 digest instead, like this:

http://www.example.com/temp/20050428T14/d4/1d/8cd98f00b204e9800998ecf8427e.html 

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


Re: Ron Grossi: God is not a man

2005-04-28 Thread Mike brown
 4) I doubt seriously whether God plays a guitar, since guitars are made by 
 men, for men.  His Son could theoretically play a guitar.  Perhaps He does. 
 Perhaps He doesn't.  Only the Father and His Holy Angels know.


Perlse.

Do you really take this stuf seriously ?

It's like the ancient discussion about how many angels can dance on the
head of a pin, a lot of bullshit.

Sorry in advance to the believers amongst us, but these God Botherers
annoy the crap out of me.

Believe what you want to, but leave me alone.

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


Re: Setting win32 console title from Python

2005-04-28 Thread Duncan Booth
runes wrote:
 I'm trying to set the title of the console window (CMD.EXE) in Windows.
 I want it set to the basename of the current directory and it should
 stay after the script has finished.
 
 Any ideas?
 
I don't think you can do that.

Whenever you start an application from the command prompt the title is 
modified by appending a dash and the name of the program you started. When 
the application terminates the title is reset (to remove the name of the 
running program). So any change to the title will only last until the next 
time CMD.EXE prompts for input. The exception is that any title set using 
the TITLE command becomes the reset title for that command prompt.

I can think of only one way round this, which is to run your python program 
from a batch file and find some way to pass the desired title back to the 
batch file where you can set it with the TITLE command. For example, you 
could write the title to a temporary file, or if your program doesn't 
produce much other output print it to stdout and parse the program output 
using a for command:

e.g. This sets the title to the current time:
 
C:\FOR /F tokens=* %i in (
More? 'python -c from time import *; print asctime(localtime())'
More? ) DO @TITLE %i

C:\

Obvious notes: In a batch file you would double the % characters, and you 
don't type C:\ or More? as these are the prompts from CMD.EXE. Also this 
won't work on really old versions of CMD.EXE or with COMMAND.COM.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shutting down twisted reacotr

2005-04-28 Thread Operation Latte Thunder
Jason  Mobarak [EMAIL PROTECTED] wrote:
 Why do you want to do this in a thread? What's wrong with
 reactor.callLater?
 
 import time
 from twisted.internet import reactor
 
 def shutdown():
 
time.sleep(3)
print stopping
reactor.callFromThread(reactor.stop)
 
 reactor.callInThread(shutdown)
 reactor.run()

In the app I am playing with, I have a thread that reads from the console.
When it terminates, I wanted it to shut down the reactor and couldn't use
callLater.  However, callFromThread worked perfectly.   I guess I need to
look at the docs some more to understand why its necessary 

-- 
[EMAIL PROTECTED]   | Roma Invicta!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can .py be complied?

2005-04-28 Thread monkey
Thx very much, I got the point now ( ;

 The latter.  It's not completely self contained, there is an
 ..exe and some dll files that need to be distributed together.
 It's explained very clearly by the py2exe web site:

   http://starship.python.net/crew/theller/py2exe/

 Never used google before?  Just go to www.google.com and type
 in py2exe.  Click search.  It's the first hit.

 -- 
 Grant Edwards   grante Yow!  Is something
VIOLENT
   at   going to happen to a
visi.comGARBAGE CAN?


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


Re: Can .py be complied?

2005-04-28 Thread Pajo
I've just tried to build both console and windows exe and
it works just fine

monkey wrote:
Thx very much, I got the point now ( ;

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


Re: Question about python code distribution...

2005-04-28 Thread Larry Bates
You didn't say what platform, but if it is Windows take a
look at Inno Installer.  It is a complete installation
framework that allows you to package everything into a
single setup.exe file.  I use a combination of py2exe and
Inno to do my apps that are to be distributed.  Nothing
could be simpler.

-Larry Bates

[EMAIL PROTECTED] wrote:
 Hi,
 
 I am sure that this question might have come up repeatedly. Companies
 may not want to distribute their python code in source form. Even
 though pyc files are one option, it gets inconvenient to distribute
 bunch of them . If there is some way to bundle pyc files (akin to
 .jar), it would be really nice. I understand that pyc files are not
 hard to decompile (from my reading of previous posts) and module
 startup times may be longer if they have to be read from an archive.
 Neverthless, an option to distribute in the form of an archive is
 attractive. Has this ever been considered for Python? If one were to
 consider it, what would be pros and cons of such approach?
 
 Any comments are appreciated.
 
 Thanks,
 Raghu.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (PHP or Python) Developing something like www.tribe.net

2005-04-28 Thread Michele Simionato
talking about programming in the large and in the small

Well, let me specialize my sentence

 CherryPy and Quixote are for programming in the small

in

 CherryPy and Quixote are good for programming in the small

meaning that these frameworks help you when programming in the small.
This statement does NOT imply that they get in your way when you
program
in the large. I just lack the experience in programming in the large
with
CherryPy and/or Quixote.

Also, let me specify what I mean by programming in the large:
if a single person can grasp the application, and the application
can be implemented by a single team, then you are programming
in the small.

You are programming in the large only when you have many independent
team of developers and you have coordination problems. In this
situation
a component architecture is supposed to help (and maybe it does, I lack

the field experience to give an opinion), whereas when working in the
small a component architecture can just get in your way.

It is easy to evaluate a framework in the small: it is enough
to ask to self the question how much time did it take to me to write
my first Web site in that framework starting from zero?. OTOH, to
evaluate a framework for programming in the large takes years of
experience and practice, and I will not hazard any opinion ;)

Still, I believe it is possible to have a frameworks which is
scalable both in the small and in the large. Look for instance
at the programming language spectrum: Java was intended to program
in the large and it is pretty bad when programming in the small;
Perl, on the other hand, was meant to program in the small and does
not scale at all in the large. However, Python works equally well
both in the large and in the small. So, I think there is no
contraddiction between large and small, in theory. But in practice
there is, so I use Zope at work and Quixote at home ;)


Michele Simionato

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


Re: Ron Grossi: God is not a man

2005-04-28 Thread MC05

Donald L McDaniel [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 4) I doubt seriously whether God plays a guitar, since guitars are made by 
 men, for men.  His Son could theoretically play a guitar.  Perhaps He 
 does. Perhaps He doesn't.  Only the Father and His Holy Angels know.

So then Lucifer was a wicked bass player whose sex and drugs and rock n roll 
alientated the rest of the band and was fired? 


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


Re: mysql.h: No such file or directory when building MySQL-python

2005-04-28 Thread Andy Dustman
[EMAIL PROTECTED] wrote:

 I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2:
...
 gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -march=i386
 -mcpu=i686 -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.3 -c
 _mysql.c -o build/temp.linux-i686-2.3/_mysql.o -I'/usr/include/mysql'
 _mysql.c:41:19: mysql.h: No such file or directory
...
 My server configuration:
 ---
 [ ]# /usr/local/mysql/bin/mysql_config
   --cflags[-I'/usr/local/mysql/include/mysql']
 --libs  [-L'/usr/local/mysql/lib/mysql' -lmysqlclient
 -lz -lcrypt -lnsl -lm]
 --socket[/tmp/mysql.sock]
 --port  [3306]
 --version   [3.23.58]
...
 Any suggestion? Thank you very much.

Fedora's mysql_config puts quotes around the directory names, which
confuses things. Try MySQL-python-1.2.1c1. I don't think this entirely
solves the problem, but I think I know how to fix it for 1.2.1c2. But
try it and report your results here:

https://sourceforge.net/tracker/index.php?func=detailaid=1146226group_id=22307atid=374932

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


Re: Setting win32 console title from Python

2005-04-28 Thread jay graves
Hmm.

From an interactive interpreter this works for me.

import os
os.system('title Jay')

but the title returns to its previous value when I Ctrl-Z out of the
process.

If I save this as a file and run it, it seems to work without spawning
a new window but resets it the title after the program finishes like
above.

import os
os.system('title Jay')
x = raw_input()

You mention that the SetConsoleTitle api resets itself after the script
finishes so I'm assuming that 'title' command is just calling the same
api under the covers.

What is your requirement specifically?  I do something similar but in a
different way but it might not be what you are after.

I have a 'projects' directory where I keep all of my work.  I have
written a small python script 'p.py' that I call like this

p [s|e|*] projectname

the 's' is for shell
the 'e' is for explorer window
the '*' is for both shell and explorer

If there is only one argument, I assume it is the project name and I
default the other argument to 'e'.

if the projectname doesn't have any wildcard characters, I append a '*'
and glob my project directory with that value.  if the glob call only
returns a single value, I go ahead and do what was requested (open a
shell or explorer window to that directory)  if there is more than one
value returned, I present a numbered menu of project directories that
match and wait for input on which one to open.

The point to all this, is that when I open a shell from p.py I use this
command.
os.system(r'start %s /D%s\%s' % (proj,directory,proj))

This spawns a new cmd window with the title of my project name.
Spawning the process with the correct name from the beginning seems to
do the trick.
But like I said, I don't really know your exact requirements.

HTH.
...
jay

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


Re: Getting a list of classes in the current module/auto introspection

2005-04-28 Thread Michele Simionato
Any class has a .__module__ attribute giving the name
of the module where the class was defined, so you
need something like

[c for c in globals() if inspect.isclass(c) and c.__module__ ==
__main__]

   Michele Simionato

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


Re: Can .py be complied?

2005-04-28 Thread beliavsky
IMO the fact that so many people ask

How can I create executables in Python on Windows

indicates that standard batteries included Windows Python
distribution is missing a vital battery. There are tools such as
py2exe, but this functionality should be built-in, so that a newbie to
Python can just download it, type

python -o foo.exe foo.py

at the command line, and get an executable, without any further effort.

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


Re: pyqt and Eric 3

2005-04-28 Thread Brian Elmegaard
[EMAIL PROTECTED] writes:

 http://kscraft.sourceforge.net/convert_xhtml.php?doc=pyqt-windows-install.xhtml

Which, afaics, unfortunately requires either that you have msvc or
that you compile python and every addon with mingw :-(

-- 
Brian (remove the sport for mail)
http://www.et.dtu.dk/staff/be/be.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast plotting?

2005-04-28 Thread Paul F. Kunz
William Park [EMAIL PROTECTED] writes:

 Russell E. Owen [EMAIL PROTECTED] wrote:
  Can anyone recommend a fast cross-platform plotting package for 2-D 
  plots?
  
  Our situation:
  We are driving an instrument that outputs data at 20Hz. Control is via 
  an existing Tkinter application (which is being extended for this new 
  instrument) that runs on unix, mac and windows. We wish to update 5-10 
  summary plots at approximately 2 Hz and will be offering controls to 
  control the instrument and the plots, preferably (but not necessarily) 
  mixed in with the plots.
 
 That's 10-20 plots per second.  The only GUI plotter that I know is
 'gnuplot', and I don't know if it will spit out anything at 10-20Hz.
 For character plots (like old days terminal), it has speed but ugly to
 look at.
 
   HippoDraw is quite fast and scriptable from Python

http://www.slac.stanford.edu/grp/ek/hippodraw
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting win32 console title from Python

2005-04-28 Thread runes
 Whenever you start an application from the command prompt the title
is
 modified by appending a dash and the name of the program you started.
When
 the application terminates the title is reset (to remove the name of
the
 running program). So any change to the title will only last until the
next
 time CMD.EXE prompts for input. The exception is that any title set
using
 the TITLE command becomes the reset title for that command prompt.

Thanks Duncan!  That sounds reasonable. What I do today is actually
using a .BAT file and read the name from a temp file created by a
python script. It works, but it's slow and the batchfile-language
gives me the creep ;-)

I'll try to find out why it does work in command.exe/WConio though.

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


Job openings for scientifically-oriented programmers

2005-04-28 Thread bior_jobs
Positions:  Scientific Programmers

Location:  Department of Radiation Oncology, Division of Bioinformatics
and Outcomes Research, Washington University School of Medicine, St.
Louis, Missouri

Our newly created Division of Bioinformatics and Outcomes Research has
immediate openings for scientifically-oriented programmers.  We are
developing software systems for clinical and research use, including
storage and visualization of three-dimensional image datasets as well
as radiation therapy dose distributions (see our web-page at
http://radium.wustl.edu/cerr). The successful candidates would be
involved in various projects which require software development,
possibly including image visualization, data re-formatting,
optimization techniques, parallel processing, database construction,
and other aspects of radiation therapy treatment planning and outcomes
research.  Strong computational and mathematical skills are needed.
The Dept. of Radiation Oncology has a large clinical service in the use
of radiation to treat cancer, as well as a large, active, academic
group involved in a full range of radiotherapy research activities.
Helpful experience would include scientific programming (any language),
matrix language programming (Python, Fortran90, Matlab, IDL, PVWave, or
similar), related course work, and a strong interest in scientific
programming.  Beginning salary depends on experience and background.
The positions begin as soon as July 1, 2005.

Interested candidates should e-mail a resume, including GPAs if
recently graduated or still a student.  Contact:  Joseph Deasy, Ph.D.,
Associate Professor of Radiation Oncology and Director, Division of
Bioinformatics and Outcomes Research, Dept. of Radiation Oncology,
Washington University School of Medicine, at the email address:
[EMAIL PROTECTED]  Washington University School of Medicine is an
equal opportunity, affirmative action employer, and we encourage
minorities to apply.

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


anybody have a CGIXMLRPCRequestHandler example?

2005-04-28 Thread ccurvey
I see the ones in the docs, but I really (apparently) need some usage
notes.  Something as simple as an echo would probably do the trick.

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


Re: Setting win32 console title from Python

2005-04-28 Thread runes
Hi Jay. It seems like my requirement is a light edition of your. I like
having many console windows open, and to make it easier to switch
between them, I like to name them.  Todays solution is rather tedious

- a batch file that calls a python script that isolates the directory
name and stores it in temp file the batch file reads and use as
argument in the title command.

It works fine, but I dislike the combination and the entire concept of
having to create a temporary file for such a small task. The batch
language is probably the most terrible scripting environment ever
created ;-)

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


Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? GOOGLE·NEWSGROUP·POST·152

2005-04-28 Thread Please
Report to [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED], [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can .py be complied?

2005-04-28 Thread steve.leach
python -o foo.exe foo.py
at the command line, and get an executable, without any further effort.
Hence making the resulting program useless to users of most operating 
systems.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread Cameron Laird
In article [EMAIL PROTECTED],
Eric Brunel [EMAIL PROTECTED] wrote:
On 26 Apr 2005 13:37:29 -0700, infidel [EMAIL PROTECTED] wrote:

 from Tkinter import Tk, Button

 def say_hello(event):
 print 'hello!'
 print event.widget['text']

 root = Tk()
 button1 = Button(root, text='Button 1')
 button1.bind('Button-1', say_hello)
 button1.pack()
 button2 = Button(root, text='Button 2')
 button2.bind('Button-1', say_hello)
 button2.pack()
 root.mainloop()

Unfortunately, making a binding to Button-1 on Button widgets does not
have the same behavior as setting their 'command' option. The binding
will fire when the button is *pressed*; the command will be called when
the button is *released*. So, binding to ButtonRelease-1 instead of
Button-1 make things a little better, but still does not have the same
effect, since ButtonPress and ButtonRelease events are balanced: the
widget getting the ButtonRelease event is always the same as the one
getting the ButtonPress event. So if the mouse button is pressed inside
the Button, then the mouse pointer goes out of it, and then the mouse
button is released, the Button will still get the ButtonRelease event
and fire the binding. This is not the normal behavior for a button and
this is not the behavior you get via the 'command' option (just try
it...).

So having a different function for each button or using tiissa's
solution is definitely better.
.
.
.
Without unraveling my own confusion about who has said what to whom, does
everyone realize that Tkinter bind()ings inherently can access the widgets
which generate their events?  Please refer to Table 7-2 in URL:
http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm 
(and thank Fredrik, once again, for his marvelous work in putting this
material online).
-- 
http://mail.python.org/mailman/listinfo/python-list


anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
I see lambda is going away, so I want to use something that will be 
around for awhile.

All I want to do is provide an inline function as an argument to 
another function.

For example, let's say I have a function which binds a key to a function 
call. I want to do something simple in this function call, and I have 
a lot of bindings, so I don't want to have a ton of tiny little 
functions scattered around:

def setVarTo1():
foo.var = 1
def setVarTo2():
foo.var = 2
bind('a', setVarTo1)
bind('b', setVarTo2)
Instead, I'd like to do something like this:
bind('a', foo.var = 1)
bind('b', foo.var = 2)
What's the recommended way to do something like this?
Note that the bind function is implemented in C, and I am embedding 
the interpreter.

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


Re: Setting win32 console title from Python

2005-04-28 Thread jay graves
Cool.  Let me know if you want a copy of p.py (in all of it's
hard-coded glory).
I can easily put it under Public Domain and you can copy whatever you
want out of it.
...
jay

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


Re: Job openings for scientifically-oriented programmers

2005-04-28 Thread Joe Deasy
Email was scrambled by google:
Correct email address is:  bior _jobs  @ yahoo.com
(remove spaces).
I apologize for that.
- Joe Deasy

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


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Michael Hoffman
Paul Miller wrote:
 I see lambda is going away, so I want to use something that will be 
 around for awhile.

 All I want to do is provide an inline function as an argument to
 another function.

That's what lambda does. But it's going away, you'll have to use def 
when it does, unless the language designers come up with something better.

For example, let's say I have a function which binds a key to a function 
call. I want to do something simple in this function call, and I have 
a lot of bindings, so I don't want to have a ton of tiny little 
functions scattered around:

def setVarTo1():
foo.var = 1
def setVarTo2():
foo.var = 2
bind('a', setVarTo1)
bind('b', setVarTo2)
If a lot of the bindings are actually setting variables, you could do 
something like this:

def attrsetter(obj, name, 1):
def _return_func(value):
return setattr(obj, name, value)
return _return_func
Instead, I'd like to do something like this:
bind('a', foo.var = 1)
bind('b', foo.var = 2)
bind('a', attrsetter(foo, var, 1))
bind('a', attrsetter(foo, var, 2))
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why Python does *SLICING* the way it does??

2005-04-28 Thread Bjrn Lindstrm
Antoon Pardon [EMAIL PROTECTED] writes:

 The problem is that the fields in lst are associated
 with a number that is off by one as they are normally
 counted. If I go and ask my colleague which field
 contains some specific data and he answers:
 the 5th, I have to remind my self I want lst[4]

 This is often a cause for errors.

It sounds like you should wrap that list in an object more reminding of
the source data, then.

-- 
Bjrn Lindstrm [EMAIL PROTECTED]
Student of computational linguistics, Uppsala University, Sweden
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting win32 console title from Python

2005-04-28 Thread Duncan Booth
runes wrote:

 Hi Jay. It seems like my requirement is a light edition of your. I like
 having many console windows open, and to make it easier to switch
 between them, I like to name them.  Todays solution is rather tedious
 
 - a batch file that calls a python script that isolates the directory
 name and stores it in temp file the batch file reads and use as
 argument in the title command.
 
 It works fine, but I dislike the combination and the entire concept of
 having to create a temporary file for such a small task. The batch
 language is probably the most terrible scripting environment ever
 created ;-)

As I showed in my other post you can parse program output without using a 
temporary file.
 
If all you want to do is to run a script which sets the title when CMD.exe 
starts, that is actually quite easy:

 c:\temp\startcmd.py 
import os
print Python startup
os.execv('c:\\windows\\system32\\cmd.exe',
 [/D, /C, title, CMD -  + os.getcwd()]
-

Then run regedit and find the key 
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun

edit it and insert the name of your script (in this example 
c:\temp\startcmd.py).

Now whenever you start a new command processor the script will set the 
title and CMD will NOT reset it. It seems that if you set the title from a 
subprocess when CMD is starting it will accept your change.

Warning: don't use os.system from the startcmd.py script as that would run 
CMD.exe without the /D flag which would run the script recursively as it 
starts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
Michael Hoffman wrote:
That's what lambda does. But it's going away, you'll have to use def 
when it does, unless the language designers come up with something better.
Yeah, I'm using lamda now it works nicely/cleanly.
If a lot of the bindings are actually setting variables, you could do 
something like this:

def attrsetter(obj, name, 1):
def _return_func(value):
return setattr(obj, name, value)
return _return_func
bind('a', attrsetter(foo, var, 1))
bind('a', attrsetter(foo, var, 2))
Ah, perfect. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Dave Benjamin
Michael Hoffman wrote:
Paul Miller wrote:
  I see lambda is going away, so I want to use something that will be 
  around for awhile.
 
  All I want to do is provide an inline function as an argument to
  another function.

That's what lambda does. But it's going away, you'll have to use def 
when it does, unless the language designers come up with something better.

For example, let's say I have a function which binds a key to a 
function call. I want to do something simple in this function call, 
and I have a lot of bindings, so I don't want to have a ton of tiny 
little functions scattered around:

def setVarTo1():
foo.var = 1
def setVarTo2():
foo.var = 2
bind('a', setVarTo1)
bind('b', setVarTo2)

If a lot of the bindings are actually setting variables, you could do 
something like this:

def attrsetter(obj, name, 1):
def _return_func(value):
return setattr(obj, name, value)
return _return_func
I think you meant to write something like this:
def attrsetter(obj, name, value):
def _return_func():
return setattr(obj, name, value)
return _return_func
Or, if you want to delay binding of the value parameter:
def attrsetter(obj, name):
def _return_func(value):
return setattr(obj, name, value)
return _return_func
Cheers,
Dave
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which IDE is recommended?

2005-04-28 Thread Brian Beck
Ville Vainio wrote:
 Does this help?

Not really, my PYTHONPATH is fine. I found out that modules imported in
the format import mx work fine, but from mx import DateTime doesn't
work -- it will still only auto-complete when I type mx. instead of
realizing that it's in the local scope now. So it's fine all the modules
fine, just placing them wrong in the auto-complete search tree, or
however it works.

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Which IDE is recommended?

2005-04-28 Thread Matt
Sorry about that Frank. You have to create a project (New -- Project)
and add your file to it then Run--Run. This is a bug that slipped past
because we do all of our development using projects and hadn't even
tried the obvious: open file and run. That fix has made its way to the
wx folks, but hasn't been released yet.

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


Re: Which IDE is recommended?

2005-04-28 Thread Matt
Franz,

To ask for help otherwise, use the forums link from
http://sourceforge.net/projects/activegrid/

--Matt

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


split question

2005-04-28 Thread alexk
I've a simple question. Why the following:

words = [EMAIL PROTECTED]@^%[wordA] [EMAIL PROTECTED].split('[EMAIL 
PROTECTED]*()_+-=[]{},./')

doesn't work? The length of the result vector is 1.

I'm using ActivePython 2.4

Alex

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


Re: split question

2005-04-28 Thread Grant Edwards
On 2005-04-28, alexk [EMAIL PROTECTED] wrote:
 I've a simple question. Why the following:

 words = [EMAIL PROTECTED]@^%[wordA] [EMAIL PROTECTED].split('[EMAIL 
 PROTECTED]*()_+-=[]{},./')

 doesn't work?

But it does work.  Your input string (the one on the left) does
not contain the delimiter string you're passing to the split()
method.  The argument to split() is a delimiter string not a
set of delimter characters.

 The length of the result vector is 1.

Yup :)

-- 
Grant Edwards   grante Yow!  This MUST be a good
  at   party -- My RIB CAGE is
   visi.combeing painfully pressed up
   against someone's MARTINI!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ron Grossi: God is not a man

2005-04-28 Thread Donald L McDaniel
MC05 wrote:
 Donald L McDaniel [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

 4) I doubt seriously whether God plays a guitar, since guitars are
 made by men, for men.  His Son could theoretically play a guitar. Perhaps 
 He does. Perhaps He doesn't.  Only the Father and His Holy
 Angels know.

 So then Lucifer was a wicked bass player whose sex and drugs and rock
 n roll alientated the rest of the band and was fired?

1) Lucifer was an angel who rebelled against God, not a member of a human 
rock 'n roll band.
2) Since Lucifer is an angel, I doubt seriously whether he can play a bass 
guitar or other musical instrument. As I said in my last post, musical 
instruments are made by men for men, not angels.
3) Since Lucifer is an angel, he does not engage in sexual relations. 
(Christ tells us that angels don't engage in sexual relations by His Own 
Words.)
4) Drugs and rock 'n roll are created by men for men, not angels.  And the 
green plants of the Earth were created by a Gracious God for His beloved 
creations, the men of the Earth.
5) Lucifer was not a member of a rock 'n roll band.  He is a spirit, not a 
man.
6) While we are on the subject of rock 'n roll, any such band which contains 
horns is pure crap anyway (or seriously living in the dark ages).  Horns 
don't belong in rock 'n roll bands.  Rock 'n roll has advanced light-years 
beyond Elvis.  It is the 21st Century, not the 20th.

-- 
Donald L McDaniel
Please reply to the original thread,
so that the thread may be kept intact.
== 


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


Re: creating very small types

2005-04-28 Thread Bengt Richter
On Thu, 28 Apr 2005 05:07:34 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:

... some not quite correct code ;-/
(I copy/pasted and created an illusion. My code dict has no EOS, so
I decode pad zero bits as code that a single zero stands for ('a' in this case)
so that was an oversight. I should have extended the coding some more or 
reserved
perhaps 'F' as EOString, and tested for EOS in the decode stream.


This is revised, sorry.
You can make a 'way more efficient decoder as an exercise ;-)
Hint: if you make a dict of all the 2**width integers as keys where
width is your widest code (4 here for 2**4), then you can do a single
mask of 2**width-1 and look up the translation to (char, codewidth) directly,
according to the codewidth least significant bits, if you make all the states
of the other bits into keys that map to the same (char,codewidth).
So for example all the even values of out 2**16 would have to map to ('a', 1)
and all the values with 2 LSBs of 01 (of which there are 4) would map to ('b',2)
and so forth. Thus the incrementing of width and trying one thing after
another is not necessary. I think that will work ...

Well, now Andrea has something to do ;-)
 trivcodec.py 
#trivcodec.py
EOS = ''
import itertools
def encode(stream):
outchar = count = 0
for char in itertools.chain(stream, [EOS]):
bits, width = codes[char]
outchar |= (bitscount)
count += width
while count = 8:
yield chr(outchar0xff)
outchar = 8
count -= 8
if count:
yield chr(outchar)

def decode(stream):
codebuf = count = 0
width = 1; char = None
for codebyte in stream:
codebyte = ord(codebyte)
codebuf |= (codebytecount)
count += 8
if widthcount:
continue
while width = count:
code = (codebuf((1width)-1), width)
if code not in chars:
width += 1
continue
char = chars[code]
if char == EOS: break
yield char
codebuf = width
count -= width
width = 1
if char == EOS: break
width = 1 

#trivial encoding dict: a=0 b=01 C=0011 D=0111 E=1011 EOS=
codes = {'a':(0x00,1), 'b':(0x01, 2), 
 'C':(0x3+0x4*0,4), 'D':(0x3+0x4*1,4),
 'E':(0x3+0x4*2,4), EOS:(0x3+0x4*3,4)}
chars = dict([(v,k) for k,v in codes.items()]) # reverse

def test(*tests):
if not tests: tests = ['abaDECbaabbD']
for charstream in tests:
print
codestream = ''.join(list(encode(charstream)))
print '%r [%s] -(encode)- %r [%s]' % (
charstream, len(charstream), codestream, len(codestream))
recovered = ''.join(list(decode(codestream)))
print '%r [%s] -(decode)- %r [%s]' % (
codestream, len(codestream), recovered, len(recovered))
 
if __name__ == '__main__':
import sys
test(*sys.argv[1:])


Result:
Not really. Tack enough a's on the recovered chars to account for zero fill
of the last encoded byte ;-/

[22:02] C:\pywk\clppy24 trivcodec.py

'abaFECbaabbDF' [13] -(encode)- '\xf2;Q\xf7' [4]
'\xf2;Q\xf7' [4] -(decode)- 'abaFECbaabbDF' [13]

Fine, because the [4] bytes were totally filled.

[22:02] C:\pywk\clppy24 trivcodec.py  a b C D E F

'a' [1] -(encode)- '\x00' [1]
'\x00' [1] -(decode)- 'a' [1]
Not so fine. There is no character serving as EOS mark.

'b' [1] -(encode)- '\x01' [1]
'\x01' [1] -(decode)- 'b' [1]

'C' [1] -(encode)- '\x03' [1]
'\x03' [1] -(decode)- 'C' [1]

'D' [1] -(encode)- '\x07' [1]
'\x07' [1] -(decode)- 'D' [1]

'E' [1] -(encode)- '\x0b' [1]
'\x0b' [1] -(decode)- 'E' [1]

'F' [1] -(encode)- '\x0f' [1]
'\x0f' [1] -(decode)- 'F' [1]

That really produced:

[ 8:03] C:\pywk\clppy24  trivcodec.py a b C D E F

'a' [1] -(encode)- '\x00' [1]
'\x00' [1] -(decode)- '' [8]

'b' [1] -(encode)- '\x01' [1]
'\x01' [1] -(decode)- 'baa' [7]

'C' [1] -(encode)- '\x03' [1]
'\x03' [1] -(decode)- 'C' [5]

'D' [1] -(encode)- '\x07' [1]
'\x07' [1] -(decode)- 'D' [5]

'E' [1] -(encode)- '\x0b' [1]
'\x0b' [1] -(decode)- 'E' [5]

'F' [1] -(encode)- '\x0f' [1]
'\x0f' [1] -(decode)- 'F' [5]

So we need to assign a code as the EOS.
And probably translate that to '' as the return char,
and end on that.

So now it does (having given up  for EOS instead of F):

[10:22] C:\pywk\clppy24  trivcodec.py

'abaDECbaabbD' [12] -(encode)- 'r;Q\xf7' [4]
'r;Q\xf7' [4] -(decode)- 'abaDECbaabbD' [12]

[10:22] C:\pywk\clppy24  trivcodec.py a b C D E

'a' [1] -(encode)- '\x1e' [1]
'\x1e' [1] -(decode)- 'a' [1]

'b' [1] -(encode)- '=' [1]
'=' [1] -(decode)- 'b' [1]

'C' [1] -(encode)- '\xf3' [1]
'\xf3' [1] -(decode)- 'C' [1]

'D' [1] -(encode)- '\xf7' [1]
'\xf7' [1] -(decode)- 'D' [1]

'E' [1] -(encode)- '\xfb' [1]
'\xfb' [1] -(decode)- 'E' [1]

Goes to show you, eh? Slice and 

Re: Python or PHP?

2005-04-28 Thread Alan Little
Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]...
 John Bokma wrote:
  Alan Little wrote:
  
  
 Steve Holden [EMAIL PROTECTED] wrote:
 
 
 Your statement then becomes
 
 select * from foo where bar=1; drop table foo
 
 which is clearly not such a good idea.
 
 I'm sure Steve is very well aware of this and was just providing a
 simple and obvious example, nevertheless it might be worth pointing
 out that anyody who connects their web application to their database
 as a user that has DROP TABLE privileges, would clearly be in need of
 a lot more help on basic security concepts than just advice on
 choosing a programming language.
  
  
  True. But how does it stop someone who uses inserts? (I exclude the case 
  inserts are not needed).

Inserts are indeed not needed, if you really don't want to allow them.
The web app user connects to a schema that has no direct write
privileges on anything. Instead it has execute permissions on stored
procedures in another schema that do the writes. In Oracle, at any
rate, the stored procedure then runs with the privileges of the schema
it is in, but the calling user doesn't need or get those privileges.
Over the top in many cases, but it's an extra layer of defence if you
want it.

  
  
 This goes back to the point somebody made earlier on in the thread -
 many web applications can be implemented as fairly simple wrappers
 around properly designed databases. Properly designed includes
 giving some thought to table ownership and privileges.
  
  
  One should stop SQL injection always, no matter if the database takes care 
  of it or not. There is no excuse (like, yeah, but I set up the privileges 
  right) for allowing SQL injection, ever.

Wasn't suggesting that for a moment.

  
 Correct. If a thing can't go wrong, it won't.
 
 In security several levels of defense are better than just one, so 
 database authorization and SQL injection removal should be considered 
 complimentary techniques of a belt and braces (US: belt and 
 suspenders) approach.
 
 regards
   Steve

I completely agree of course. Do both.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: split question

2005-04-28 Thread Michael Spencer
alexk wrote:
I've a simple question. Why the following:
words = [EMAIL PROTECTED]@^%[wordA] [EMAIL PROTECTED].split('[EMAIL 
PROTECTED]*()_+-=[]{},./')
doesn't work? The length of the result vector is 1.
I'm using ActivePython 2.4
Alex
Do you mean, why doesn't it split on every character in '[EMAIL 
PROTECTED]*()_+-=[]{},./' ?
Help on built-in function split:
split(...)
S.split([sep [,maxsplit]]) - list of strings
Return a list of the words in the string S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator.
sep as a whole is the delimeter string
If you want to split on any of the characters in your sep string, use a regexp:
Perhaps:
  import re
  splitter = re.compile([EMAIL PROTECTED]*()_+-= ]+) #note escapes for []
  splitter.split([EMAIL PROTECTED]@^%[wordA] [EMAIL PROTECTED])
 ['', 'wordA', 'wordB', '']
 
is closer to what you had in mind
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ron Grossi: God is not a man

2005-04-28 Thread MC05

Donald L McDaniel [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 MC05 wrote:
  Donald L McDaniel [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
  4) I doubt seriously whether God plays a guitar, since guitars are
  made by men, for men.  His Son could theoretically play a guitar.
Perhaps
  He does. Perhaps He doesn't.  Only the Father and His Holy
  Angels know.
 
  So then Lucifer was a wicked bass player whose sex and drugs and rock
  n roll alientated the rest of the band and was fired?

 1) Lucifer was an angel who rebelled against God, not a member of a human
 rock 'n roll band.
 2) Since Lucifer is an angel, I doubt seriously whether he can play a bass
 guitar or other musical instrument. As I said in my last post, musical
 instruments are made by men for men, not angels.
 3) Since Lucifer is an angel, he does not engage in sexual relations.
 (Christ tells us that angels don't engage in sexual relations by His Own
 Words.)
 4) Drugs and rock 'n roll are created by men for men, not angels.  And the
 green plants of the Earth were created by a Gracious God for His beloved
 creations, the men of the Earth.
 5) Lucifer was not a member of a rock 'n roll band.  He is a spirit, not a
 man.
 6) While we are on the subject of rock 'n roll, any such band which
contains
 horns is pure crap anyway (or seriously living in the dark ages).  Horns
 don't belong in rock 'n roll bands.  Rock 'n roll has advanced light-years
 beyond Elvis.  It is the 21st Century, not the 20th.

As it is the 21st Century one would think your beliefs as outlined and
enumerated would be considered even MORE dark age than horns in rock n
roll.


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


OOP

2005-04-28 Thread demon_slayer2839
Hey yall,
I'm new to Python and I love it. Now I can get most of the topics
covered with the Python tutorials I've read but the one thats just
stumping me is Object Orientation. I can't get the grasp of it. Does
anyone know of a good resource that could possibly put things in focus
for me? Thanks.

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


Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread tiissa
Cameron Laird wrote:
In article [EMAIL PROTECTED],
Eric Brunel [EMAIL PROTECTED] wrote:
Unfortunately, making a binding to Button-1 on Button widgets does not
have the same behavior as setting their 'command' option.
Without unraveling my own confusion about who has said what to whom, does
everyone realize that Tkinter bind()ings inherently can access the widgets
which generate their events?
I don't know about everyone, but I can assume that's definitively the 
case of infidel (who precisely based the solution you quoted on this) 
and Eric Brunel.

But that may not be the topic at hand. Indeed, the main point is that, 
according to Eric, bind() and command don't behave in the exact same way.

And the OP asked about having a reference on the widget using the 
command callback (that, contrary to event-binded callbacks, don't get 
passed any argument).

So far, the OP is proposed the choice to either use the event/bind 
mecanism or use different callbacks for his different buttons (either 
with the method I proposed or not).
--
http://mail.python.org/mailman/listinfo/python-list


Re: OOP

2005-04-28 Thread beliavsky
[EMAIL PROTECTED] wrote:
 Hey yall,
 I'm new to Python and I love it. Now I can get most of the topics
 covered with the Python tutorials I've read but the one thats just
 stumping me is Object Orientation. I can't get the grasp of it. Does
 anyone know of a good resource that could possibly put things in
focus
 for me?

Maybe Part VI, Classes and OOP, of the book Learning Python, 2nd
edition, by Lutz and Ascher. Both the motivation for OOP and its
implementation in Python are discussed, in about 100 pages.

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


Re: split question

2005-04-28 Thread alexk
Yes, all of you are right. Thank you all for your answers - I'll use a
regex.

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


Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread googleboy
I'd be just such a newbie; I don't understand why it would matter if I
left the book instance referencing itself

However these wonderful responses have gotten me a very long way
towards my goal.  I just have a couple of quick questions.

firstly,  I am trying hard to figure out how to create a new file with
the list rather than print to standard out.  I haev done this:

for book in books:
print book # just to be sure it works as I expect
sort1 = open(r'D:\path to\sort1.csv', 'w+')
print  sort1, book
sort1.close()

and this creates the file as I expect, however it creates it populated
with only the information of the final book in the sorted list. I am
guessing I need to figure out how to append as part of this loop,  but
the only info I have found so far suggests this should append by
default?

Secondly,  I am wondering how I can get a search algorithm that will
search by multiple fields here,  so that I can (as one example) sort
the books out by author and then date,  to present a list of the book
grouped by authors and having each group presented in a chronological
order,   or by author and title, grouping all the books up into authors
presenting each group alphabetically by title.  Or by publisher and
date,  or by publisher and code

I have tried things like

books.sort(key = operator.attrgetter(author), key =
operator.attrgetter(title) and
books.sort(key = operator.attrgetter(author, title)

but they both give errors.

Is this where using cmd functions instead of keys becomes necessary?

Thanks!

googleboy

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


Re: OOP

2005-04-28 Thread Charles Krug
On 28 Apr 2005 10:34:44 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Hey yall,
 I'm new to Python and I love it. Now I can get most of the topics
 covered with the Python tutorials I've read but the one thats just
 stumping me is Object Orientation. I can't get the grasp of it. Does
 anyone know of a good resource that could possibly put things in focus
 for me? Thanks.
 

Learning Python (Lutz/Ascher) has a good discussion of the basics.

Unfortunately, most of the OOP writings I've read fall into two
catagories:  Trivial examples where you say, But why Bother?? and
examples that you don't understand until you've some OO design under
your belt and can understand what it's all good for.

Objects are, at the end of the day, data and the accompanying methods.
Once you've read the various tutorials take a stab at converting a
problem you know well into objects.

You'll get it wrong at first.  Most everyone does.  Don't sweat it.
Eventually, you'll just get it.

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


Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Philippe C. Martin
How about using the csv module instead of splitting ?


[EMAIL PROTECTED] wrote:

 What you want I guess is to read first all lines of the file into a
 string as you did, and then let the split method split it based on
 newlines only - see example below.
 
 Then you use split again to put all elements of one line into another
 list - split it on commas.
 
 Now you can define sortfunctions for all columns you want to sort, e.g.
 like below - and use those to compare elements. You get a script like:
 -#!/usr/bin/env python
 -
 -def cmp_index(a, b, ndx):
 -   if a[ndx]  b[ndx]:
 -return -1
 -elif a[ndx]  b[ndx]:
 -   return 1
 -else:
 -return 0
 -
 -def cmp_0(a, b):
 -return cmp_index(a, b, 0)
 -
 -def cmp_1(a, b):
 -return cmp_index(a, b, 1)
 -
 -s = 'Kikker en Eend,Max Veldhuis\nDikkie Dik,Jet Boeke\nRuminations on
 C++,Andrew Koenig  Barbara Moo'
 -s = s.split('\n')
 -l = []
 -for i in s:
 -l.append(i.split(','))
 -
 -l.sort(cmp_0)
 -print l
 -l.sort(cmp_1)
 -print l
 
 with output like:
 [EMAIL PROTECTED]:~ $ ./test.py
 [['Dikkie Dik', 'Jet Boeke'], ['Kikker en Eend', 'Max Veldhuis'],
 ['Ruminations on C++', 'Andrew Koenig  Barbara Moo']]
 [['Ruminations on C++', 'Andrew Koenig  Barbara Moo'], ['Dikkie Dik',
 'Jet Boeke'], ['Kikker en Eend', 'Max Veldhuis']]
 [EMAIL PROTECTED]:~ $

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


why import wx doesn't work?

2005-04-28 Thread monkey
I just learn to make a blank windows frame with python and wxpython. I found
the statment import wx cannot work as the original from wxPython.wx
import *. I see in the readme file of wxpython that if I install it as the
default one, I can use import wx instead of the long one. What is wrong?
The code pasted below:

import wx   # the default is from wxPython.wx import *, I change it and it
just can't work.

class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, Hello from wxPython)
frame.Show(true)
self.SetTopWindow(frame)
return true

app = MyApp(0)
app.MainLoop()


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


Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread infidel
Here's a slight variation of tiissa's solution that gives the callable
a reference to the actual widget instead of just it's name:

from Tkinter import Tk, Button

class say_hello:
def __init__(self, widget):
self.widget = widget
def __call__(self):
print 'Hello,', self.widget['text']

def run():
root = Tk()
b1 = Button(root, text='Button 1')
b1.configure(command=say_hello(b1))
b1.pack()
b2 = Button(root, text='Button 2')
b2.configure(command=say_hello(b2))
b2.pack()
root.mainloop()

run()

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


Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Steven Bethard
googleboy wrote:
firstly,  I am trying hard to figure out how to create a new file with
the list rather than print to standard out.  I haev done this:
for book in books:
print book # just to be sure it works as I expect
sort1 = open(r'D:\path to\sort1.csv', 'w+')
print  sort1, book
sort1.close()
and this creates the file as I expect, however it creates it populated
with only the information of the final book in the sorted list.
You're reopening the file on each iteration of the loop.  I think you 
want to open it only once, before the loop, e.g.

sort1_file = open(r'D:\path to\sort1.csv', 'w+')
for book in books:
sort1_file.write('%s\n' % book) # same as print  sort1, book
sort1_file.close()
Note that the opening and closing of the file is outside the loop.
Secondly,  I am wondering how I can get a search algorithm that will
search by multiple fields here,  so that I can (as one example) sort
the books out by author and then date,  to present a list of the book
grouped by authors and having each group presented in a chronological
order,   or by author and title, grouping all the books up into authors
presenting each group alphabetically by title.  Or by publisher and
date,  or by publisher and code
I have tried things like
books.sort(key = operator.attrgetter(author), key =
operator.attrgetter(title) and
books.sort(key = operator.attrgetter(author, title)
but they both give errors.
The problem is that operator.attrgetter only accepts a single attribute. 
 Basically, attrgetter looks something like:

def attrgetter(attr_name):
def func(obj):
return getattr(obj, attr_name)
return func
So attrgetter can't really solve your problem.  However, you can create 
a similar function that should do the job.  Something like (untested):

def get_key(*attr_names):
def key(book):
return [getattr(book, name) for name in attr_names)]
return key
Then you should be able to do something like:
books.sort(key=get_key(author, title))
The trick is that the inner function, 'key', looks up a sequence of 
attributes on the book object, instead of just a single attribute like 
attrgetter does.

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


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Michael Hoffman
Dave Benjamin wrote:
I think you meant to write something like this:
def attrsetter(obj, name, value):
def _return_func():
return setattr(obj, name, value)
return _return_func
Sure did. Sorry.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Lonnie Princehouse
 I'd be just such a newbie; I don't understand why it would matter if
I
 left the book instance referencing itself

It's just kind of sloppy and unnecessary to have self.self

 firstly,  I am trying hard to figure out how to create a new file
with
 the list rather than print to standard out.  I haev done this:

I think you want 'a' instead of 'w+' as the file's mode.  You can also
open and close the file outside of the loop; it would be more
efficient.

 Secondly,  I am wondering how I can get a search algorithm that will
 search by multiple fields here,  so that I can (as one example) sort
 the books out by author and then date,  to present a list of the book
 grouped by authors and having each group presented in a chronological
 order,   or by author and title, grouping all the books up into
authors
 presenting each group alphabetically by title.  Or by publisher and
 date,  or by publisher and code

So far, we've been using the key parameter of list.sort.  If you want
sort criteria more complicated than a single attribute, you can sort
based on a custom comparison function.Comparison functions compare
two objects (let's call them A and B), and return one of three possible
values:

A is greater than B  = 1
A is less than B = -1
A and B are equal = 0

The built-in function cmp can be used to compare objects; behavior is
defined for built-in types:

cmp(0, 1) = -1
cmp(Zylophone, Abstract) = 1   # alphabetical ordering for strings
cmp( [1,2,3], [1,2,3] ) = 0  # compare sequence elements from left to
right

So another way to do a sort-by-author for your books would be:

  def compare_authors(book1, book2):
  return cmp(book1.author, book2.author)

   books.sort(compare_authors)

A more complicated comparison function might nest two others:

  def compare_dates(book1, book2):
  # Assuming that your dates are either numerical or are strings
for which
  # alphabetical sorting is identical to chronological...
  return cmp(book1.date, book2.date)

  def compare_author_and_date(book1, book2):
   different_authors = compare_authors(book1, book2)
   if different_authors:  # different authors
   return different_authors
   else:  # same author.  sort by date.
   return compare_dates(book1, book2)
  
  books.sort(compare_author_and_date)

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


Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread Cameron Laird
In article [EMAIL PROTECTED],
tiissa  [EMAIL PROTECTED] wrote:
.
.
.
So far, the OP is proposed the choice to either use the event/bind 
mecanism or use different callbacks for his different buttons (either 
with the method I proposed or not).

Thanks, Tissa.  Is there general understanding that use different
callbacks ... can be implemented as parametrize the same callback
with a widget-specific value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Cameron Laird
In article [EMAIL PROTECTED],
Peter Hansen  [EMAIL PROTECTED] wrote:
Paul Miller wrote:
 For example, let's say I have a function which binds a key to a function 
 call. I want to do something simple in this function call, and I have 
 a lot of bindings, so I don't want to have a ton of tiny little 
 functions scattered around:
 
 def setVarTo1():
 foo.var = 1
 def setVarTo2():
 foo.var = 2
 
 bind('a', setVarTo1)
 bind('b', setVarTo2)
 
 Instead, I'd like to do something like this:
 
 bind('a', foo.var = 1)
 bind('b', foo.var = 2)
 
 What's the recommended way to do something like this?

This meets your requirements as stated:

def temp():
foo.var = 1

bind('a', temp)

def temp():
foo.var = 2

bind('b', temp)

del temp


-Peter

Ewww!  *When* is lambda going bye-bye?  I apparently
haven't been paying close enough attention.  Among other
considerations, I still instruct people to use lambda for
plenty of specific cases.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting the sender widget's name in function (Tkinter)

2005-04-28 Thread tiissa
Cameron Laird wrote:
In article [EMAIL PROTECTED],
tiissa  [EMAIL PROTECTED] wrote:
So far, the OP is proposed the choice to either use the event/bind 
mecanism or use different callbacks for his different buttons (either 
with the method I proposed or not).
Is there general understanding that use different
callbacks ... can be implemented as parametrize the same callback
with a widget-specific value?
Tough questions thou ask! Again I can't answer about general 
understanding. ;)

However, having myself proposed such a solution in this very thread (and 
hinted about it in the above sentence), I do hope most people (at least 
those interested in this issue) will be aware of this kind of trick 
(without any restriction on the actual implementation). :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
Michael Hoffman wrote:
Dave Benjamin wrote:
I think you meant to write something like this:
def attrsetter(obj, name, value):
def _return_func():
return setattr(obj, name, value)
return _return_func

Sure did. Sorry.
You guys have been very helpful!
While on the subject, is there an equivalent for methodcaller?
ie. if I want to bind a function which calls a specific method of an 
object with a specific parameter?

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


Re: Setting win32 console title from Python

2005-04-28 Thread runes
Hi Duncan, sorry, I was unprecise.  I'm thinking of a script, called
t.py  that can be used in the console  like an ordinary command. Som if
I change directory from S:\scripts to d:\projects and execute the
script  the title changes to projects etc.

I have that functionality today with a combination of a python script
and a batch file. I just wondered if I could use python all the way.
Apparently I cannot.

Here are the scripts:


-- DirInPath:\t.bat 
@echo off
:: reads bare directory name from file
:: created by external Python script
set DIR_FILE_NAME=DOS_IS_TERRIBLE.tmp
PyBareDir.py %DIR_FILE_NAME%

for /F eol=; %%t in (%DIR_FILE_NAME%) do (
title %%t
)

del /Q /F DOS_IS_TERRIBLE.tmp



-- DirInPath:\PyBareDir.py 
# extracts bare directory name and  writes
# it to file with name given as argument.

from os import getcwd
from os.path import basename
import sys

try:
saveAsName = sys.argv[1]
lastDir = basename(getcwd())
XWwz(saveAsName, 'w+').write(lastDir + '\n;')
except:
print PyBareDir failed:, sys.exc_info()[1]

---

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


embedding an interactive console

2005-04-28 Thread Paul Miller
I did this YEARS ago with Python 1.5, and I recall it being slightly 
painful. I have an embedded Python interpreter and I want to provide an 
interactive console (implemented in my GUI application with a Qt 
TextEdit widget). I can handle the GUI part of it, but I'm wondering 
what the latest Python method of implementing this is.

I note the documentation for InteractiveConsole, which is implemented in 
Python. Is there any example code for using this from within C/C++ code 
to emulate the command-line interpreter inside a GUI app?

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


Can't run BLT program more than once?

2005-04-28 Thread Todd Krein
I'm running activestate Python 2.4 for windows, and the latest BLT,
under XP. I'm using pythonWin as my environment.

When I run my plotting program the first time, it works just fine. If I
exit out (normally), and then run it again from PythonWin, I get the
following error. It's as if something isn't getting properly
re-initialized. If I quit out of PythonWin, and relaunch it, I can run
the program again, once. Any ideas?



Error: 1
TclError Exception in Tk callback
  Function: bound method PathEval.doOpenTrace of __main__.PathEval
instance at 0x0127AC60 (type: type 'instancemethod')
  Args: ()
Traceback (innermost last):
  File C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBase.py, line 1747, in
__call__
None
  File
C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py,
line 89, in doOpenTrace
self.doPlotTrace()  # go plot the thing
  File
C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py,
line 117, in doPlotTrace
self.graph = Pmw.Blt.Graph(tkRoot)   # make a new
graph area
  File C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBlt.py, line 260, in
__init__
None
  File C:\Python24\lib\lib-tk\Tkinter.py, line 1861, in __init__
self.tk.call(
TclError: invalid command name ::blt::graph

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


Can'r run BLT twice?

2005-04-28 Thread Todd Krein
I'm running PythonWin on XP. When I run my plotter program the first
time, it works fine. The second time I run it, I get the following
error. If I exit PythonWin, and restart, I can again run it once. Any
ideas?

Error: 1
TclError Exception in Tk callback
  Function: bound method PathEval.doOpenTrace of __main__.PathEval
instance at 0x0127AC60 (type: type 'instancemethod')
  Args: ()
Traceback (innermost last):
  File C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBase.py, line 1747, in
__call__
None
  File
C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py,
line 89, in doOpenTrace
self.doPlotTrace()  # go plot the thing
  File
C:\NBU\perforce\hardware\test\home_survey\data\home_007\raw_data\KitchenToDen\AMPLITUDE\PathEval.py,
line 117, in doPlotTrace
self.graph = Pmw.Blt.Graph(tkRoot)   # make a new
graph area
  File C:\Python24\lib\Pmw\Pmw_1_2\lib\PmwBlt.py, line 260, in
__init__
None
  File C:\Python24\lib\lib-tk\Tkinter.py, line 1861, in __init__
self.tk.call(
TclError: invalid command name ::blt::graph

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


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Dave Benjamin
Paul Miller wrote:
Michael Hoffman wrote:
Dave Benjamin wrote:
I think you meant to write something like this:
def attrsetter(obj, name, value):
def _return_func():
return setattr(obj, name, value)
return _return_func

Sure did. Sorry.

You guys have been very helpful!
While on the subject, is there an equivalent for methodcaller?
ie. if I want to bind a function which calls a specific method of an 
object with a specific parameter?
You could use a combination of bound methods and the curry function 
defined in the Python Cookbook:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
The examples in the discussion do just that.
Dave
--
http://mail.python.org/mailman/listinfo/python-list


Re: Internet Explorer, COM+, Javascript and Python

2005-04-28 Thread J Correia

Roger Upole [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Something like this should be close:

 import win32com.client, pythoncom
 ie=win32com.client.Dispatch('internetexplorer.application')
 ie.Visible=1
 ie.Navigate('somepagewithjavascript.html')
 id=ie.Document.Script._oleobj_.GetIDsOfNames('somejsfunction')
 res=ie.Document.Script._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_METHOD,
 True, parameter or tuple of parameters )

hth
Roger

Yes, that definitely works.  Only one minor correction:  it seems that to
pass multiple parameters you need to pass them sequentially seperated by
commas instead of in a tuple, i.e.
res=ie.Document.Script._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_METHOD,
True, param1, param2, param3, . )

Useful test sitefor above code:
http://www.cpplab.com/Articles/JSCalls/TestPage/JSCallTestPage.htm

HTH,



 Ishpeck [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 I need to make IE execute javascript in a web page with COM+ and
  Python.
 
  Similarly to the way they do it in this article. . .
 
  http://www.codeproject.com/com/jscalls.asp
 



 == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==
 http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
 = East and West-Coast Server Farms - Total Privacy via Encryption
=



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


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Michael Hoffman
Paul Miller wrote:
While on the subject, is there an equivalent for methodcaller?
ie. if I want to bind a function which calls a specific method of an 
object with a specific parameter?

def funccaller(func, *args, **kwargs):
def _return_func():
return func(*args, **kwargs)
return _return_func
class Test1(object):
def __init__(self, x):
self.x = x
def method(self, a, b, c):
return self.x + a + b + c
t1 = Test1(42)
funccaller_result = funccaller(t1.method, 3, 4, c=5)
funccaller_result()
And this time I actually tested it, and it works! ;)
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Dave Benjamin
Dave Benjamin wrote:
You could use a combination of bound methods and the curry function 
defined in the Python Cookbook:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
The examples in the discussion do just that.
Also, in the CVS version of Python, there's a new module called 
functional with a function called partial that does the same thing 
as far as I can tell. So, in the future, this function will probably be 
available in the standard library.

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


Re: why import wx doesn't work?

2005-04-28 Thread Peter Hansen
monkey wrote:
I just learn to make a blank windows frame with python and wxpython. I found
the statment import wx cannot work as the original from wxPython.wx
import *. I see in the readme file of wxpython that if I install it as the
default one, I can use import wx instead of the long one. What is wrong?
The code pasted below:
import wx   # the default is from wxPython.wx import *, I change it and it
just can't work.
class MyApp(wxApp):
...
Assuming you've installed a version of wxPython that is recent enough 
that import wx works (it's really unclear from what you've written 
above), then the problem you are facing is not using the namespace that 
you've now imported.  Do this instead:

class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(NULL, -1, 
Note that wx. before everything from wxPython...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically generating temporary files through python/cgi

2005-04-28 Thread Tiziano Bettio
poisondart wrote:
Is there a way to dynamically generate temporary files (such as an
html, xml or text file) in Python?
I'm not sure if I'm explaining myself clearly as I've no clue how to
describe this mechanism. I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time. These
files usually have some phony string for their filenames...like it's
been md5 hashed or something.
Is there a group of library functions that allow this? I imagine that
if i manually go and allocate a bunch of timers to monitor files, it
would be really expensive in load. Or perhaps is this a client-side
mechanism?
Thanks,
- poisondart
 

hi there
first of you could use the tempfile
import tempfile
tempfile.mktemp('.thefileendingudlike')
i never really studied the cgi capability of python but for example in 
php there is the posibility to serve a request with a mime formated 
response such as html, gif, pdf, and so on. so if u want to generate 
content dynamically u wouldn't need to store those files but generate 
and send em on request without having to destroy them later on..

hope this is helpful
cheers
tc
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Dave Benjamin
Cameron Laird wrote:
In article [EMAIL PROTECTED],
Peter Hansen  [EMAIL PROTECTED] wrote:
This meets your requirements as stated:
def temp():
  foo.var = 1
bind('a', temp)
def temp():
  foo.var = 2
bind('b', temp)
del temp
Ewww!  *When* is lambda going bye-bye?  I apparently
haven't been paying close enough attention.  Among other
considerations, I still instruct people to use lambda for
plenty of specific cases.
Well, IMNSHO, it's an empty threat that's been looming on the horizon 
for several years now. ;) Most recently, Guido mentioned his desire to 
remove the keyword in his post on Artima, which resulted in a huge debate:

http://www.artima.com/weblogs/viewpost.jsp?thread=98196
Note that in the OP's question, as with Peter's example above, you still 
can't do it with lambda alone, since you can't mix expressions with 
assignment. Nonetheless, lambda is nice for delaying binding, and 
combined with a helper function that sets attributes, it can produce the 
most concise solution:

bind('a', lambda: setattr(foo, 'var', 1))
bind('b', lambda: setattr(foo, 'var', 2))
The usual response is that you probably want to make a class anyway, and 
use bound methods for this type of stuff. But I find that in GUI/async 
programming, often you need a little dab of glue to connect events 
between objects, and lambda provides a nice way to avoid 
over-abstracting the problem.

We'll see how this all pans out in the next few years. I'm not too fond 
of removing features from a language for purely aesthetic reasons, but 
lambda's really stuck in a syntactic quandry due to the 
statement/expression dichotomy, so I can understand to some extent 
Guido's desire to remove it.

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


Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
Michael Hoffman wrote:
Paul Miller wrote:
While on the subject, is there an equivalent for methodcaller?
ie. if I want to bind a function which calls a specific method of an 
object with a specific parameter?

def funccaller(func, *args, **kwargs):
def _return_func():
return func(*args, **kwargs)
return _return_func
...
And this time I actually tested it, and it works! ;)
Wow! Amazing. Yer right, it works!
Man, I LOVE this language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a bug?

2005-04-28 Thread Aahz
In article [EMAIL PROTECTED],
Fredrik Lundh [EMAIL PROTECTED] wrote:

mapping += to extend is a design mistake (I guess someone got a
little carried away).

There were two use cases that drove augmented assignment (I know you know
this -- but other people probably do not):

reallylongvariablename = reallylongvariablename + 1
hugearray = hugearray + tinyarray

The latter was particularly coming from the Numeric types.  The docs
probably should clarify that augmented assignment is *NOT* necessarily
the same as ``foo = foo + bar`` when ``foo`` is a mutable type.  You can
argue that you disagree with mapping ``+=`` to ``extend()``, but I don't
think it's fair for you to flatly claim that it's a design mistake.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

It's 106 miles to Chicago.  We have a full tank of gas, a half-pack of
cigarettes, it's dark, and we're wearing sunglasses.  Hit it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working with method-wrapper objects

2005-04-28 Thread Dr. Peer Griebel
Peer Dr. Griebel wrote:
I think I was a little bit unspecific in my last mail.
I would like to see some description about method-wrapper and
wrapper_descriptor objects.  I dont' understand the following behaviour:

type([].__str__)
type 'method-wrapper'
type(object.__str__)
type 'wrapper_descriptor'
type(object().__str__)
type 'method-wrapper'
import inspect
inspect.isroutine([].__str__)
False
inspect.isroutine(object.__str__)
True
inspect.isroutine(object().__str__)
False
Why has [].__str__ a different type than object.__str__?
Why is object.__str__ a routine while object().__str__ not?
And one again my question: Can I extract some more information about a
methed-wrapper object. E.g. can I somehow determine the arg spec?
Thanks
  Peer
Isn't there anybody who has something to say about the issue?
I think it's not only a problem with inspect. It is aproblem about old 
style classes vs. new style classes. It seems that the support for new 
style classes is not complete (yet).

Some more investigation shows that also the module types is not 
universally usable. E.g. InstanceType is only usabel for instances of 
old classes. How do I test for instances of new classes?

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


Re: Can .py be complied?

2005-04-28 Thread jfj
[EMAIL PROTECTED] wrote:
IMO the fact that so many people ask
How can I create executables in Python on Windows
indicates that standard batteries included Windows Python
distribution is missing a vital battery. There are tools such as
py2exe, but this functionality should be built-in, so that a newbie to
Python can just download it, type
python -o foo.exe foo.py
at the command line, and get an executable, without any further effort.

Since this is about windows and windows users just want everything in
.exe form (no matter if it also contains spyware), and they don't care
about the size of it (they just want the damn exe) and since there is
zero chance that python will be included in the next windows
distribution but these people still want the exe (they do, really),
I think I have a convenient solution to give it to them.
/* small program in C in self extracting archive
 */
if (have_application (Python)) {
  have_python:
  system (python.exe my_application.py)
} else {
  printf (This software requires python. Wait until all the
necessary components are being installed\n);
  download_python_from_python_org();
  system (install_python.exe);
  goto have_python;
}
Seriously, people who want executables wouldn't notice the difference.
jfj
--
http://mail.python.org/mailman/listinfo/python-list


Re: regex over files

2005-04-28 Thread Skip Montanaro

Bengt To be fairer, I think you'd want to hoist the re compilation out
Bengt of the loop.

The re module compiles and caches regular expressions, so I doubt it would
affect the runtime of either version.

Bengt But also to be fairer, maybe include the overhead of splitting
Bengt correctly, at least for the simple case regex in my example -- or
Bengt is a you-goofed post for me in the usenet forwarding queues
Bengt somewhere still? ;-)

I was just too lazy to incorporate (something like) your change.  You will
note that I was also lazy enough to simply steal your X file. wink

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


  1   2   >