ANN:NewEdit 3.2 Released

2006-01-17 Thread limodou
What's it?


It's an Editor based on wxPython. NewEdit uses Mixin and Plugin
technique as its architecture. Most of its classes can be extended via
mixin and plugin components, and finally become an integrity class at
creating the instance. So NewEdit is very dynamic. You can write the
new features in new files, and hardly need to modify the existing
code. And if you want to extend the existing classes, you could write
mixins and plugins, and this will be bound to the target class that I
call Slot Class. This technique will make the changes centralized
and easily managed.

What are its features?


   *  Cross platform
 o  based on wxPython, so it can run anywhere that wxPython
works, such as: Windows, Linux.
 o   Unicode support.
   *  Most features of wxStyledTextCtrl(Scintilla)
 o   Syntax highlighting, support Python, c/c++, html, plain
text, perl, ruby, css, javascript
 o   Folding
 o   Brace Matching
 o   ...
   *  Extended selection
 o   Extended word selection -- You can press
Ctrl+?MouseDoubleClick to select a word including '.'
 o   Matched selection -- Select text in quoted chars like:
(), [], {}, '', .
   *  Other editing extension
 o   Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and
more. You can duplicate above or below char, word, line
 o   Quoting text -- Add some quoted chars before and after
selected text, just as: , '', (), [], {}, and
 o   Text convertion and view -- python - html, reStructured
Text - html, textile - html, and you can output or view
 o   Utf-8 encoding auto detect
 o   Changing document encoding
 oAuto backup
 oLast session support -- It'll save all the filenames as
closed, and reopen the files as next started.
 oSmart judge the indent char -- It'll auto guess the
indent char, and sets it.
 oFinding in files
 oBookmark support
   *  Python support
 obuilt-in python interactive window based on ?PyShell,
support Unicode
 oAuto completion
 o   Function syntax calltips
 o   Run, run with argument, stop python source
 o   Auto change current path
 o   Python class browser
   *  Code snippets
 o  You can manage your code snippets with categories, and
each category can have many items. Every item will represent a code
snippet. You can insert an item just by double-clicking on it. It even
supports importing and exporting.
   *  Simple project support
 o  Can create a special file _project, so every file and
folder under the folder which has the _project can be considered as a
whole project.
   *  Extension mechanism
 o  Script -- You can write easy script to manipulate the all
resource of NewEdit, just like: text conversion, etc.
 o  Plugin -- Customized function. More complex but more
powerful. Can easily merge with NewEdit, and can be managed via menu.
 o  Shell command -- Add often used shell commands, and execute them.
   *  Ftp support
 o  You can edit remote files through ftp. You can add,
rename, delete, upload, download file/directory.
   *  Multilanguage support
 o  Currently supports two languages: English and Chinese,
which can be auto-detected.
   *  Shipped plugins(must be configed as used them before)
 o  Document links -- Python documentation and wxPython documentation.
 o  Many plugins can be found at NewEdit wiki page.
   *  Shipped scripts
 o  Many scripts can be found at NewEdit wiki page.
   *  Wizard (New)
 o You can make your own wizard template. The wizard can
input user data, combine with template, and output the result. And
wizard also support code framework created. This feature will help you
improving coding efficiency.
   *  Direcotry Browser(New)
 o   Browse multiple directories, and you can really add,
delete, rename directories and files. Double click will open the file
in Editor window.
   *  AutoComPlete(acp)(New)
 o   Suport user autocomplete file, it can help to input code
very helpful and functional. Just like EditPlus, but may be more
powerful.

Where to download it?


download lastest version 3.2:
http://wiki.woodpecker.org.cn/moin/NewEdit?action=AttachFiledo=gettarget=newedit_3.2.zip
also have windows installer:
http://wiki.woodpecker.org.cn/moin/NewEdit?action=AttachFiledo=gettarget=NewEdit3.2.exe
wiki: http://wiki.woodpecker.org.cn/moin/NewEdit
svn: http://cvs.woodpecker.org.cn/svn/woodpecker/newedit
maillist: http://groups.google.com/group/NewEdit

If you have any problem as using NewEdit, welcome to join the NewEdit
maillist to discuss.

Hope fun!

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
 

ANN: Leo 4.4b1 released

2006-01-17 Thread Edward K. Ream
Leo 4.4 beta 1 is now available at:

http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

The code is stable; there are no known serious bugs. Some features are 
incomplete.

Leo is a text editor, data organizer, project manager and much more.  See: 
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name, with tab completion.

- Many new commands, including cursor and screen movement, basic character, 
word and paragraph manipulation, and commands to manipulate buffers, the 
kill ring, regions and rectangles.  You can use Leo without using a mouse.

- Flexible key bindings and input modes.  You can emulate the operation of 
Emacs, Vim, or any other editor.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Dozens of other new features and bug fixes since Leo 4.3.3.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream
January 17, 2006

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: PyDev 0.9.8.7 released

2006-01-17 Thread Fabio Zadrozny
Hi All,

PyDev - Python IDE (Python Development Enviroment for Eclipse) version 
0.9.8.7 has been released.

Check the homepage (http://pydev.sourceforge.net/) for more details.

Details for Release: 0.9.8.7:
Major highlights:

* The debugger tracing was turned off (this was a bug in 0.9.8.6 and 
could make debugging much slower)
* Fixed jython shell (and extended it to get better information on 
code-completion).
* Changed the interpreter configuration so that it is 
backwards-compatible from now on...(but the current interpreters will be 
lost and will need to be configured)
* Breakpoints can have conditionals(this was contributed by Achim 
Nierbeck, and was actually provided in release 0.9.8.6, but I forgot to 
put it in the release notes)
* Some other bugfixes are also in this build.

Cheers,

Fabio

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

PyDev - Python Development Enviroment for Eclipse
pydev.sf.net
pydev.blogspot.com

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: OT: excellent book on information theory

2006-01-17 Thread Terry Hancock
On Mon, 16 Jan 2006 15:31:58 -
Grant Edwards [EMAIL PROTECTED] wrote:
 That made me smile on a Monday morning (not an
 insignificant accomplishment).  I noticed in the one
 footnote that the H.P. book had been translated into
 American.  I've always wondered about that.  I noticed
 several spots in the H.P. books where the dialog seemed
 wrong: the kids were using American rather than British
 English.  I thought it rather jarring.

translated into American, I'm sure refers to the American
version of the book, which is titled Harry Potter and the
Sourceror's Stone.

I find that bizarre.  There is no mythological
basis for a Sourceror's Stone, but the Philosopher's
Stone, was of course the mythical Alchemists' goal of a 
catalyst for converting lead into gold (it had other
properties, IIRC).

Apparently the publisher was of the opinion that American
children just aren't cultured enough to know about that,
even though I knew the reference when I was 12.  I am
really, really insulted by that.

They even went so far as to shoot two versions of every
scene in the movie that referred to the stone so that it
would agree with the book. AFAICT, you cannot purchase
the original movie or book within the United States, and
due to the Evil Conspiracy of region-coding, I couldn't
watch the British DVD even if I were to import it (Well,
yeah I could, but it would be painful, and probably illegal,
do to that other Evil Conspiracy, the DMCA -- don't let
your country pass a law like this).

Now I don't suppose I should really get my nose all out
of joint over this sort of thing, but it's symbolic of
a lot of things that are wrong with the world right now.

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Arithmetic sequences in Python

2006-01-17 Thread Gregory Petrosyan
Some ideas:

1) Let [a,b .. c] be  *ordinary list* !
Just like [1,2,3]. Are there any questions why 3 is included in
[1,2,3]? IMO it's more correct to think about [first, next .. last] as
about syntax for list creation, but not as about
syntax-to-replace-range-function. (And, because it's an ordinary
list, you could iterate through it in usual way: for each element of
list do...)

2) [5 .. 0] - [5,4,3,2,1,0]
So, if next is omited, let the default step be 1 if first  last
and -1 otherwise.

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


SMPP implementation in python

2006-01-17 Thread Alvin A. Delagon
Greetings!

Does anyone know a good reference on how to implement SMPP in python. I 
can't find any besides NET::SMPP in perl and I don't want to get my 
hands for that. Thanks in advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Arithmetic sequences in Python

2006-01-17 Thread Antoon Pardon
Op 2006-01-16, Alex Martelli schreef [EMAIL PROTECTED]:
 Paul Rubin http://[EMAIL PROTECTED] wrote:

 Steven D'Aprano [EMAIL PROTECTED] writes:
  For finite sequences, your proposal adds nothing new to existing
  solutions like range and xrange.
 
 Oh come on, [5,4,..0] is much easier to read than range(5,-1,-1).

 But not easier than reversed(range(6)) [[the 5 in one of the two
 expressions in your sentence has to be an offbyone;-)]]

Why don't we give slices more functionality and use them.
These are a number of ideas I had. (These are python3k ideas)

1) Make slices iterables. (No more need for (x)range)

2) Use a bottom and stop variable as default for the start and
   stop attribute. top would be a value that is greater than
   any other value, bottom would be a value smaller than any
   other value.

3) Allow slice notation to be used anywhere a value can be
   used.

4) Provide a number of extra operators on slices.
   __neg__ (reverses the slice)
   __and__ gives the intersection of two slices
   __or__ gives the union of two slices

5) Provide sequences with a range (or slice) method.
   This would provide an iterator that iterates over
   the indexes of the sequences. A slice could be
   provided


  for i in xrange(6):

would then become

  for i in (0:6):

for a reversed sequence

  for i in reversed(xrange(6)):

would become

  for i in - (0:6):


  for i, el in enumerate(sequence):

would become

  for i in sequence.range():
el = sequence[i]

But the advantage is that this would still work when
someone subclasses a list so that it start index
is an other number but 0.

If you only wanted every other index one could do
the following

  for i in sequence.range(::2):

which would be equivallent to

  for i in sequence.range()  (::2):

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


_bsddb on NetBSD

2006-01-17 Thread Miki Tebeka
Hello All,

I can't seem to build Python2.4.2 with bsddb on NetBSD.
bsddb seems to be missing from the pkg_add installation as well.

Any ideas?

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


Addressing a COM port from Python

2006-01-17 Thread Doru-Catalin Togea
Hi!

I am writing some tests and I need to place calls through the modem. Is 
there an API for addressing the COM ports on my machine, so that I can 
issue AT-commands to the modem?

If this can not be done from Python, I am sure it can be done from 
C/C++/Java. Any tutorials/examples that you know of? Maybe calling C from 
Python?

I am working on Win XP Pro, with Activestate Python 2.4.

Thanks,
Catalin

-- 

  == 
  We are what we repeatedly do.  
   Excellence, therefore, is not an act  
  but a habit.   
  == 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exec a string in an embedded environment

2006-01-17 Thread Tommy Ryding
No it didn't help me :(

the foo_ptr that is returned from PyRun_String is not a callable
object. Therefor I can't call it from PyObject_Call.


I would like to do the exact same procedure as I do when the code is
located in a module (file).

pModule = PyImport_Import(pName);
Py_DECREF(pName);

if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, inArg-funcName);
/* pFunc is a new reference */

if (pFunc  PyCallable_Check(pFunc)) {


It must be possible to import a module written inside a string with a
similar approach. The ultimate solution would be to change the
PyImport_Import() call to something that creates an object from a
string

Now some of you think why not have the code inside a file. We need to
create encrypted script files, thats why.

I hope someone can help me //Tommy

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


Re: Addressing a COM port from Python

2006-01-17 Thread Fredrik Lundh
Doru-Catalin Togea wrote:

 I am writing some tests and I need to place calls through the modem. Is
 there an API for addressing the COM ports on my machine, so that I can
 issue AT-commands to the modem?

 If this can not be done from Python, I am sure it can be done from
 C/C++/Java. Any tutorials/examples that you know of? Maybe calling C from
 Python?

http://pyserial.sourceforge.net/

/F 



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


Re: Addressing a COM port from Python

2006-01-17 Thread Miki Tebeka
Hello Catalin,

 I am writing some tests and I need to place calls through the modem. Is 
 there an API for addressing the COM ports on my machine, so that I can 
 issue AT-commands to the modem?
 
 If this can not be done from Python, I am sure it can be done from 
 C/C++/Java. Any tutorials/examples that you know of? Maybe calling C 
 from Python?
 
 I am working on Win XP Pro, with Activestate Python 2.4.
http://pyserial.sourceforge.net/

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


Re: exec a string in an embedded environment

2006-01-17 Thread Tommy Ryding
I can't post that much of what I have done but some questions might
answer if you e-mail me the question to my gmail.com address.
[EMAIL PROTECTED]

//Tommy

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


Re: Web application design question (long)

2006-01-17 Thread bruno at modulix
Fried Egg wrote:
 I must not express myself very clearly.
 
 I don't need any help with the disassociated text algorithm.  What I
 need is a framework for data processing web apps,

If that's your main need, and you want to use a RDBMS, then you may want
to have a look at turbogears
http://turbogears.org/


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


Re: Arithmetic sequences in Python

2006-01-17 Thread Paul Rubin
Gregory Petrosyan [EMAIL PROTECTED] writes:
 2) [5 .. 0] - [5,4,3,2,1,0]
 So, if next is omited, let the default step be 1 if first  last
 and -1 otherwise.

So what do you want [a..b] to do?  Dynamically decide what direction
to go?  Ugh!
-- 
http://mail.python.org/mailman/listinfo/python-list


EOF occurred in violation of protocol

2006-01-17 Thread Glauco
Hi all,
I have an urgent issue using some WebServices in ZSI and python 2.3.3.
The Server Was obviously an ISS and today all my comunication end  with:

File /opt/sfera/python2.3.3/lib/python2.3/socket.py, line 73, in ssl
 return _realssl(sock, keyfile, certfile)
socket.sslerror: (8, 'EOF occurred in violation of protocol')


I'm in trouble because i've tryed some workaround on httplib.py and 
socket.py but they don't work never.


Some soggestion or workaround for bypass this problem?

Thank you anyway.
Glauco
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Arithmetic sequences in Python

2006-01-17 Thread Gregory Petrosyan
Hmm, and why not? Or you realy hate such behaviour?

Note, everything I post here is just some ideas I want to discuss, and
to make these ideas better after discussion. And this particular idea
needs to be discussed, too.

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


Re: Addressing a COM port from Python

2006-01-17 Thread Nick Craig-Wood
Doru-Catalin Togea [EMAIL PROTECTED] wrote:
  I am writing some tests and I need to place calls through the modem. Is 
  there an API for addressing the COM ports on my machine, so that I can 
  issue AT-commands to the modem?

http://pyserial.sourceforge.net/

Works well in my experience
-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket Programming HOWTO example

2006-01-17 Thread Manlio Perillo
Steve Holden ha scritto:
 [...]
 I can see you have changed the example a little (because I know that
 Gordon's original didn't have comments in Italian). 

The example cames from italian translation of the howto:
http://python.it/doc/howto/Socket/sockets-it/sockets-it.html




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


Re: Shrinky-dink Python (also, non-Unicode Python build is broken)

2006-01-17 Thread Giovanni Bajo
Neil Hodgson wrote:

 - There will be some opposition to the obvious policy of keeping
 the bare minimum inside the DLL because of inefficiencies in the
 Python build system.

 It is also non-optimal for those that do want the full set of
 modules as separate files can add overhead for block sizing (both on
 disk and in memory, executables pad out each section to some block
 size), by requiring more load-time inter-module fixups

I would be surprised if this showed up in any profile. Importing modules can
already be slow no matter external stats (see programs like mercurial that,
to win benchmarks with C-compiled counterparts, do lazy imports). As for the
overhead at the border of blocks, you should be more worried with 800K of CJK
codecs being loaded in your virtual memory (and not fully swapped out because
of block sizing) which are totally useless for most applications.

Anyway, we're picking nits here, but you have a point in being worried. If I
ever write a PEP, I will produce numbers to show beyond any doubt that there is
no performance difference.

 , and by not
 allowing the linker to perform some optimizations. It'd be worthwhile
 seeing if the DLL would speed up or shrink if whole program
 optimization was turned on.

There is no way whole program optimization can produce any advantage as the
modules are totally separated and they don't have direct calls that the
compiler can exploit.
-- 
Giovanni Bajo


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


Re: Class __init__ trouble

2006-01-17 Thread SkyRanger
So any one have ideas how to solve this problem???

I think my problem in code that adds new methods in class. Every time i
add new methods it adds on single class or maybe globally.

How to make it correctly???

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


ANN: Firedrop2 0.1.3 the Python Blog Client

2006-01-17 Thread Fuzzyman
Firedrop2 has had a new release and a complete docs overhaul.

The release is a minor update, but the new tutorial will take you from
downloading and installing, through setting up your blog to making
entries.

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

What's New ?
==

The new release contains a fix so that wxfiredrop.py can be run outside
the installed directory.

* Introduction  Download
* Getting Started
* Configuring Firedrop2
* Basic Templating
* Making Entries

For news and information, use the `Firedrop2 Mailing List
http://groups.google.com/group/firedrop2/`_

What is Firedrop2 ?
==

Firedrop2 is a cross-platform blogging tool written in Python. It keeps
your blog source files on your computer, making it a clientside tool.
This means you control your blog, and can easily move it from one
server to another, with no risk of losing data. It also means you can
manage your blog offline.

It is fully open source, and has all the features you expect from a
modern blogging program :

* RSS feed generation
* Categories
* Automatic archive generation
* A powerful set of plugins, including spell checker and emailer
* Entries can be made in text, HTML, ReST, textile or sextile markup
* HTML templating system and macros for all sorts of tricks
* Built in FTP capability for uploading your blog to a server
* Because it's written in Python, it is easy to extend Firedrop or
create new plugins for it

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


Re: MVC Help

2006-01-17 Thread Fredrik Lundh
Sbaush [EMAIL PROTECTED] wrote:

 The View must be only the clickable button
 The Control must be the event listener on the button
 The Model must be the action of the button.

 If we can complete this MVC simple implementation we could publish this like
 a MVC SIMPLE TUTORIAL because with only a button this could explain the
 MVC Observer based Architecture.

if you think that an action is a good model, you've probably already lost 
track
of what MVC really is.

if you want something simple, I suggest using a simple model that's updated by
a simple user action.  here's a straightforward WCK example, which uses a click
counter as the model.  note that the test script creates a single model 
instance,
and displays it in multiple views.

from WCK import Widget, Controller, Observable
from WCK import FOREGROUND, FONT # platform default

class MyModel(Observable):

count = 0

def increment(self):
self.count += 1
self.notify(None) # notify observers

class MyController(Controller):

def create(self, handle):
handle(ButtonRelease-1, self.handle_button_release_1)

def handle_button_release_1(self, event):
# update the model
model = event.widget.model
if model:
model.increment()

class MyView(Widget):

model = None
ui_controller = MyController

def _notify(self, event, data):
# called by the model via the observable mixin
self.ui_damage() # update myself

def setmodel(self, model):
# install new model
assert isinstance(model, Observable)
if self.model:
self.model.removeobserver(self._notify)
self.model = model
self.model.addobserver(self._notify)

def ui_handle_repair(self, draw, x0, y0, x1, y1):
# repair widget contents
if not self.model:
return
font = self.ui_font(FOREGROUND, FONT)
text = str(self.model.count)
draw.text((10, 10), text, font)

def ui_handle_destroy(self):
# cleanup (called when the widget is destroyed)
if self.model:
self.model.removeobserver(self._notify)

if __name__ == __main__:
# try it out

from Tkinter import Tk

root = Tk()

model = MyModel()

view = MyView(root, background=light blue)
view.pack(side=left)

view.setmodel(model)

another_view = MyView(root, background=light yellow)
another_view.pack(side=left)

another_view.setmodel(model) # shares the same model!

if 0:
# enable this to illustrate external updates to the model
def tick():
model.increment()
root.after(1000, tick)
tick() # start ticking

root.mainloop()

/F 



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


Re: About socket threading

2006-01-17 Thread Steve Holden
Kr z wrote:
 Hi,
 
 Do anyone know the Python source codes on how the client can send/pump
 a lot of threads to the server class?
 
It isn't that difficult. Here's a basic threading framework that allows 
you to vary the number of threads fairly easily. Then you just have to 
make sure that each thread doesn't interfere with the others. Hope this 
helps.

The run() method is the network client tasks you want to run.

I have used this scheme with a 200-SMTP-client setup and it worked very 
well, with the worker threads communication back to the master thread 
using Queue.Queue.


import time, threading, random

class MyThread(threading.Thread):
  Each thread picks a 'random' integer between 0 and 19 and reports
 in once per second for that many seconds.
 

 def run(self):
 iterations = random.randint(0, 19)
 print Thread, self.getName(), starting, iterations, 
iterations
 for i in range(iterations):
 print, self.getName(), is reporting 
 time.sleep(1)
 print self.getName(), is DONE

def test():
 threadList = []

 # Create 5 MyThread() threads
 for i in range(5) :
 thread = MyThread()
 threadList.append(thread)

 # Start all threads
 for thread in threadList:
 thread.start()

 # As long as we have more than just the 'main' thread running, 
print out
 # a status message
 while threading.activeCount()  1 :
 print str(threading.activeCount()), threads running including 
main
 time.sleep(1)

if __name__ == '__main__':
 test()


regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Sudoku solver: reduction + brute force

2006-01-17 Thread ago
  But to inflate my ego beyond the known universe, here is my solver
 (that solves the avove mentioned grid reasonably fast). I suppose the
 only difference is that is uses 3, rather than 2, rules to simplify
 before starting tree-like search.

Thanks for the nice problem and the nice post.

The issue with my code was not due to the reduction algorithms used.

In fact we used exactly the same set of rules, my Cell.solve was
equivalent to your Clean1 method and my Cell.skim was equivalent to
your Clean3 method (except that my algorithm was only doing for (o1,
o2) in ((out1,out2),), but it did not make any difference in most
cases).

The real problem was due to an external loop inside my
solveByBruteForce which was absolutely useless. I fixed that and now
everything seems ok. It can solve the mentioned grid in about half the
time.

You can see my amended code in the link above.

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


Re: Class __init__ trouble

2006-01-17 Thread SkyRanger
Problem was solved by adding classes into new separate modules.

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


Re: MVC Help

2006-01-17 Thread Sbaush
Thanks!!Is there a wx example? 2006/1/17, Fredrik Lundh [EMAIL PROTECTED]:
Sbaush [EMAIL PROTECTED] wrote: The View must be only the clickable button The Control must be the event listener on the button The Model must be the action of the button.
 If we can complete this MVC simple implementation we could publish this like a MVC SIMPLE TUTORIAL because with only a button this could explain the MVC Observer based Architecture.
if you think that an action is a good model, you've probably already lost trackof what MVC really is.if you want something simple, I suggest using a simple model that's updated bya simple user action.here's a straightforward WCK example, which uses a click
counter as the model.note that the test script creates a single model instance,and displays it in multiple views.from WCK import Widget, Controller, Observablefrom WCK import FOREGROUND, FONT # platform default
class MyModel(Observable):count = 0def increment(self):self.count += 1self.notify(None) # notify observersclass MyController(Controller):def create(self, handle):
handle(ButtonRelease-1, self.handle_button_release_1)def handle_button_release_1(self, event):# update the modelmodel = event.widget.modelif model:
model.increment()class MyView(Widget):model = Noneui_controller = MyControllerdef _notify(self, event, data):# called by the model via the observable mixin
self.ui_damage() # update myselfdef setmodel(self, model):# install new modelassert isinstance(model, Observable)if self.model:self.model.removeobserver
(self._notify)self.model = modelself.model.addobserver(self._notify)def ui_handle_repair(self, draw, x0, y0, x1, y1):# repair widget contentsif not self.model:
returnfont = self.ui_font(FOREGROUND, FONT)text = str(self.model.count)draw.text((10, 10), text, font)def ui_handle_destroy(self):# cleanup (called when the widget is destroyed)
if self.model:self.model.removeobserver(self._notify)if __name__ == __main__:# try it outfrom Tkinter import Tkroot = Tk()model = MyModel()
view = MyView(root, background="" blue)view.pack(side=left)view.setmodel(model)another_view = MyView(root, background="" yellow)another_view.pack(side=left)
another_view.setmodel(model) # shares the same model!if 0:# enable this to illustrate external updates to the modeldef tick():model.increment()
root.after(1000, tick)tick() # start tickingroot.mainloop()/F--http://mail.python.org/mailman/listinfo/python-list
-- Sbaush
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: magical expanding hash

2006-01-17 Thread Giovanni Bajo
James Stroud wrote:

 I need a magical expanding hash with the following properties:

 * it creates all intermediate keys

 meh['foo']['bar] = 1

 -- works even if meh['foo'] didn't exist before

 * allows pushing new elements to leaves which are arrays

 meh['foo']['list]  elem1
 meh['foo']['list]  elem2

 * allows incrementing numeric leaves

 meh['foo']['count'] += 7

 * serializable

 I have such a class in ruby.  Can python do that?



 Is this too magical?


 class meh(dict):
def __getitem__(self, item):
  if self.has_key(item):
return dict.__getitem__(self, item)
  else:
anitem = meh()
dict.__setitem__(self, item, anitem)
  return anitem

Actually what the OP wants is already a method of dict, it's called
setdefault(). It's not overloaded by [] because it's believed to be better to
be able to say I want auto-generation explicitally rather than implicitly: it
gives the user more power to control, and to enforce stricter rules.

 class meh(dict):
...  def __getitem__(self, item):
...   return dict.setdefault(self, item, meh())
...
 a = meh()
 a[foo][bar] = 2
 a[foo][dup] = 3
 print a[foo][bar]
2
 print a
{'foo': {'dup': 3, 'bar': 2}}


So I advise using this class, and suggest the OP to try using setdefault()
explicitally to better understand Python's philosophy.

BTW: remember that setdefault() is written setdefault() but it's read
getorset().
-- 
Giovanni Bajo


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


Re: PDA Implementations

2006-01-17 Thread gregarican
Mike Meyer wrote:

 On an unrelated topic, you might take a look at Symbian
 devices. They've released a version of Python 2.3 for it.

  mike

Thanks for the information. That might be worth checking out for sure.
My project might be slightly delayed. I'm 37 yo and am recovering from
chicken pox. Having this at this age is a little more severe it seems
:-(

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


Re: OT: excellent book on information theory

2006-01-17 Thread Steve Holden
Grant Edwards wrote:
 On 2006-01-16, Tim Peters [EMAIL PROTECTED] wrote:
 
 
http://www.inference.phy.cam.ac.uk/mackay/itila/Potter.html

[Grant Edwards]

That made me smile on a Monday morning (not an insignificant
accomplishment).  I noticed in the one footnote that the H.P.
book had been translated into American.  I've always wondered
about that.  I noticed several spots in the H.P. books where
the dialog seemed wrong: the kids were using American rather
than British English.  I thought it rather jarring.

You should enjoy:

   http://www.hp-lexicon.org/about/books/differences.html
 
 
 Very interesting.  And rather sad that editors think the
 average Amermican reader too dim-witted to figure out (in
 context, even) that a car park is a parking lot and a
 dustbin is a trash can.
 
They know that the average American could work it out. They also know 
that the average American doesn't like to do anything remotely like hard 
thinking, hence they make these changes so the books don't read like 
foreign literature.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: magical expanding hash

2006-01-17 Thread Diez B. Roggisch
 
 BTW: remember that setdefault() is written setdefault() but it's read
 getorset().

I can only second that. The misleading name has - well, mislead me :)

Regards,

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


ANN: Leo 4.4b1 released

2006-01-17 Thread Edward K. Ream
Leo 4.4 beta 1 is now available at:

http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

The code is stable; there are no known serious bugs. Some features are 
incomplete.

Leo is a text editor, data organizer, project manager and much more.  See: 
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name, with tab completion.

- Many new commands, including cursor and screen movement, basic character, 
word and paragraph manipulation, and commands to manipulate buffers, the 
kill ring, regions and rectangles.  You can use Leo without using a mouse.

- Flexible key bindings and input modes.  You can emulate the operation of 
Emacs, Vim, or any other editor.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Dozens of other new features and bug fixes since Leo 4.3.3.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream
January 17, 2006

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


ANN:NewEdit 3.2 Released

2006-01-17 Thread limodou
What's it?


It's an Editor based on wxPython. NewEdit uses Mixin and Plugin
technique as its architecture. Most of its classes can be extended via
mixin and plugin components, and finally become an integrity class at
creating the instance. So NewEdit is very dynamic. You can write the
new features in new files, and hardly need to modify the existing
code. And if you want to extend the existing classes, you could write
mixins and plugins, and this will be bound to the target class that I
call Slot Class. This technique will make the changes centralized
and easily managed.

What are its features?


   *  Cross platform
 o  based on wxPython, so it can run anywhere that wxPython
works, such as: Windows, Linux.
 o   Unicode support.
   *  Most features of wxStyledTextCtrl(Scintilla)
 o   Syntax highlighting, support Python, c/c++, html, plain
text, perl, ruby, css, javascript
 o   Folding
 o   Brace Matching
 o   ...
   *  Extended selection
 o   Extended word selection -- You can press
Ctrl+?MouseDoubleClick to select a word including '.'
 o   Matched selection -- Select text in quoted chars like:
(), [], {}, '', .
   *  Other editing extension
 o   Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and
more. You can duplicate above or below char, word, line
 o   Quoting text -- Add some quoted chars before and after
selected text, just as: , '', (), [], {}, and
 o   Text convertion and view -- python - html, reStructured
Text - html, textile - html, and you can output or view
 o   Utf-8 encoding auto detect
 o   Changing document encoding
 oAuto backup
 oLast session support -- It'll save all the filenames as
closed, and reopen the files as next started.
 oSmart judge the indent char -- It'll auto guess the
indent char, and sets it.
 oFinding in files
 oBookmark support
   *  Python support
 obuilt-in python interactive window based on ?PyShell,
support Unicode
 oAuto completion
 o   Function syntax calltips
 o   Run, run with argument, stop python source
 o   Auto change current path
 o   Python class browser
   *  Code snippets
 o  You can manage your code snippets with categories, and
each category can have many items. Every item will represent a code
snippet. You can insert an item just by double-clicking on it. It even
supports importing and exporting.
   *  Simple project support
 o  Can create a special file _project, so every file and
folder under the folder which has the _project can be considered as a
whole project.
   *  Extension mechanism
 o  Script -- You can write easy script to manipulate the all
resource of NewEdit, just like: text conversion, etc.
 o  Plugin -- Customized function. More complex but more
powerful. Can easily merge with NewEdit, and can be managed via menu.
 o  Shell command -- Add often used shell commands, and execute them.
   *  Ftp support
 o  You can edit remote files through ftp. You can add,
rename, delete, upload, download file/directory.
   *  Multilanguage support
 o  Currently supports two languages: English and Chinese,
which can be auto-detected.
   *  Shipped plugins(must be configed as used them before)
 o  Document links -- Python documentation and wxPython documentation.
 o  Many plugins can be found at NewEdit wiki page.
   *  Shipped scripts
 o  Many scripts can be found at NewEdit wiki page.
   *  Wizard (New)
 o You can make your own wizard template. The wizard can
input user data, combine with template, and output the result. And
wizard also support code framework created. This feature will help you
improving coding efficiency.
   *  Direcotry Browser(New)
 o   Browse multiple directories, and you can really add,
delete, rename directories and files. Double click will open the file
in Editor window.
   *  AutoComPlete(acp)(New)
 o   Suport user autocomplete file, it can help to input code
very helpful and functional. Just like EditPlus, but may be more
powerful.

Where to download it?


download lastest version 3.2:
http://wiki.woodpecker.org.cn/moin/NewEdit?action=AttachFiledo=gettarget=newedit_3.2.zip
also have windows installer:
http://wiki.woodpecker.org.cn/moin/NewEdit?action=AttachFiledo=gettarget=NewEdit3.2.exe
wiki: http://wiki.woodpecker.org.cn/moin/NewEdit
svn: http://cvs.woodpecker.org.cn/svn/woodpecker/newedit
maillist: http://groups.google.com/group/NewEdit

If you have any problem as using NewEdit, welcome to join the NewEdit
maillist to discuss.

Hope fun!

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newcomer question wrt variable scope/namespaces

2006-01-17 Thread Gary Duzan
Florian Daniel Otel wrote:
 Gary,
 
 First of all, many  thanks for the reply. Do I understand it correctly
 that actually the rule has to be refined as pertaining  to the (so
 called) immutable types (like e.g.  integers, tuples/strings)
 whereas lists and dictionaries are mutable types and the said
 scoping rule does not apply ?

The rule has to do with modifying namespaces. Setting a variable to 
a value modifies the variable's binding in its namespace; it doesn't 
matter whether the variable references a mutable or immutable type:

=
$ python
Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type help, copyright, credits or license for more information.
  a = 1
  b = [1,2,3]
  def foo():
... a = 9
...
  def bar():
... b = [7,8,9]
...
  foo()
  print a
1
  bar()
  b
[1, 2, 3]
 
=

Note that there is no error, but the binding affect each function's 
local namespace instead of the global one. However, modifying a mutable 
type, in this case a list, is not a namespace binding operation, i.e., 
it doesn't make the variable point to a different object. Since you only 
need to access a variable's contents to modify the object to which it 
refers, you can do this:

=
  def blah():
... b[2] = 6
...
  blah()
  b
[1, 2, 6]
 
=

It is easy to think that the scoping rules give you read-only behavior, 
but with mutable objects it just isn't correct.

Gary Duzan
Motorola CHS

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


Re: OT: excellent book on information theory

2006-01-17 Thread Max Erickson
Steve Holden [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Grant Edwards wrote:
 On 2006-01-16, Tim Peters [EMAIL PROTECTED] wrote:
 
 
http://www.inference.phy.cam.ac.uk/mackay/itila/Potter.html

[Grant Edwards]

That made me smile on a Monday morning (not an insignificant
accomplishment).  I noticed in the one footnote that the H.P.
book had been translated into American.  I've always wondered
about that.  I noticed several spots in the H.P. books where
the dialog seemed wrong: the kids were using American rather
than British English.  I thought it rather jarring.

You should enjoy:

   http://www.hp-lexicon.org/about/books/differences.html
 
 
 Very interesting.  And rather sad that editors think the
 average Amermican reader too dim-witted to figure out (in
 context, even) that a car park is a parking lot and a
 dustbin is a trash can.
 
 They know that the average American could work it out. They also know 
 that the average American doesn't like to do anything remotely like
 hard thinking, hence they make these changes so the books don't read
 like foreign literature.
 
 regards
   Steve

A rather less cynical interpretation is that they are attempting to make
a children's book accessible to as many children as possible, i.e., the
youngest readers as is practical. I don't mean to disparage the book by
calling it a children's book, I have read and enjoyed several of them,
but the target audience for the books is clearly kids. 

max




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


Re: Decimal ROUND_HALF_EVEN Default

2006-01-17 Thread Tim Peters
[LordLaraby]
 If 'bankers rounding' is HALF_ROUND_EVEN, what is HALF_ROUND_UP?

Not banker's rounding ;-).  Same answer if you had said ROUND_HALF_UP
instead (which  I assume you intended) -- most of these don't have
cute names.

 I confess to never having heard the terms.

ROUND_HALF_UP etc are symbolic constants in Python's `decimal` module;
see the docs.

 I usually do: Y = int(X + 0.5) scaled to proper # of decimal places.
 Which type of rounding is this? If either.

If you meant what you said, it's not rounding at all, because it's
insane for negative inputs.  For example, int(-2 + 0.5) = int(-1.5) =
-1, and no _rounding_ method changes an exact integer (like -2) to a
_different_ exact integer (like -1).

If you were assuming X = 0.0, then int(X+0.5) coincides with
ROUND_HALF_UP on that domain.  For X  0.0, ROUND_HALF_UP works like
int(X-0.5).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver: reduction + brute force

2006-01-17 Thread Anton Vredegoor
ago wrote:

 You can see my amended code in the link above.

Thanks, I will look into it sometime. At the moment I'm at a library
computer, which severely limits my Python options. Meanwhile I have
been thinking about the sudoku problem, maybe it will prompt you, me or
someone else to make some kind of other implementation which would
resemble what I am thinking about now.

Imagine a sudoku representation which is inside a 9x9x9 cube. The
values in the cubes' cells are just 1 or 0. The height of a '1' is
determined by the value in the original (flat) sudoku grid. There are
81 filled cells in the cube, just like in a sudoku solution. If one
would look at the cube from a side it would always be the case that a
filled cell at some depth inside the cube would block your line of
vision wichever column one would be looking at. In a way a sudoku is a
special case of a magic square, and a magic square can be transformed
to this view, and this way it can be seen as the solution to the
problem of making a cube not transparent by filling the minimum number
of cells.

Now such a cube can be mirrored in 48 ways and it would still be the
same 'kind' of solution. Also it would be possible to swap horizontal
layers at will and still have some kind of solution that is the 'same'
in some way. One could also swap vertical layers iff (and only if) one
would stay inside a 3-block group of layers. On the other hand it would
be possible to swap complete 3-block groups of layers (if I'm still
making sense) and maybe there are other symmetries that would leave the
original solution somewhat intact.

Suppose one would be able to generate all these possible symmetries and
only use the 'smallest' representation of the original position, this
'hash code' would consist of just letting Python sort  the possible
'same' cubes and selecting the smallest. It could be used to prevent us
from computing the same cube twice since we could check if we already
saw something with the same hash code.

Now to the optimization part. If we find empty cells in the cube where
there are only few positions in the same row, column, or depth
available, we can limit the search space considerably because cutting
off leaves early is most profitable. Maybe it would even pay off to
consider complete layers and selecting possible fillable cells that
have minimal fillable layers' sums.

Sorry, I guess I'm getting a little bit pataforical here, expect my
Python script any day now :-). It will be implemented as a sparse
matrix based on sets of triplets (3-tuples) where for example tuple
(0,0,0) will mean that the cell with x , y and z coordinate having
value '0', is filled (virtually has a '1' inside, the 'unfilled' cells
in the cube (the zeros) are not represented).

I wonder if I still make sense, it's hard to stay programming Python
without a computer to correct my thinking. Can someone write an
implementation to check my ideas?

Anton

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


Hi, about socket programming and threading

2006-01-17 Thread Kr z
Hi All!I wonder if anyone knows the simple code structure for a multithreaded web serverhandling multiple clientsat the same time?Thanx!Regards.KrzGet an advanced look at the new version of  MSN Messenger. 

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

Re: problem of types:

2006-01-17 Thread Larry Bates
Laurent wrote:
 I do not understand why he is talking me about 'str', no str given!!!
 
 I have this:
 
 -
 
 def to_float(elt):
   if type(elt) is list:
 return map(to_float, elt)
   else:
 return float(elt)
 
 def Denombrement(A,b,c,type):
   .
   .
   .
   A = to_float(A)
   b = to_float(b)
   c = to_float(c)
   .
   .
   .
 
 if __name__ == '__main__':
   A = [[1,0],[0,1]]
   b = [2,2]
   c = [1,1]
   type = 'min'
 
   Denombrement(A, b, c, type)
 
 ---
 
 And this error msg:
 -
 Traceback (most recent call last):
   File ./Denombrement.py, line 160, in ?
 Denombrement(A, b, c, type)
   File ./Denombrement.py, line 31, in Denombrement
 A = to_float(A)
   File ./Denombrement.py, line 10, in to_float
 if type(elt) is list:
 TypeError: 'str' object is not callable
 
 --
 
 Changing 'list' to 'type(list)' don't change anything
 

Your string variable type is masking the built-in type
function. You should avoid variables with names like
type, list, str, tuple, ... (e.g. built-ins).  As they
will mask the built-ins from your program.

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


Re: ConfigParser: writes a list but reads a string?

2006-01-17 Thread Larry Bates
Terry Carroll wrote:
 It looks like ConfigParser will accept a list to be writing to the
 *.ini file; but when reading it back in, it treats it as a string.
 
 Example:
 
 ###
 import ConfigParser
 def whatzit(thingname, thing):
print thingname, value:, thing
print thingname, length:, len(thing)
print thingname, type(thing)
 
 cfgfile = cfgtest.ini
 config1 = ConfigParser.ConfigParser()
 config1.add_section(test)
 
 t1 = range(1,11)
 config1.set(test, testlist, t1)
 outfile=open(cfgfile,w)
 config1.write(outfile)
 outfile.close()
 
 config2 = ConfigParser.ConfigParser()
 config2.read(cfgfile)
 t2 = config2.get(test,testlist)
 
 whatzit(t1, t1)
 whatzit(t2, t2)
 
 ###
 
 Output is:
 
   t1 value: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
   t1 length: 10
   t1 type 'list'
   t2 value: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
   t2 length: 31
   t2 type 'str'
 
 That is, t1 is a list of length 10, consisting of:
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 
 and is written out; but t2 is read back in as a string 
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 of length 31.
 
 It took me a while to figure this out, since they looked identical in
 print statements.
 
 Is there a pythonic way to read in a list from a .INI file with
 ConfigParser?  Is this expected behavior for ConfigParser?  I would
 not expect this conversion; rather, an exception when trying to write
 the list if the list is not supported.
 

To read lists from .INI files I use following:

listvalues=INI.get(section, option).split(',')

where INI is an instance of ConfigParser

There is the problem of if list items contain commas.

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


Re: Decimal ROUND_HALF_EVEN Default

2006-01-17 Thread Rocco Moretti
LordLaraby wrote:
 If 'bankers rounding' is HALF_ROUND_EVEN, what is HALF_ROUND_UP? I
 confess to never having heard the terms.

There was a Slashdot article on rounding a short while back:

http://developers.slashdot.org/article.pl?sid=06/01/05/1838214
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: PyDev 0.9.8.7 released

2006-01-17 Thread Fabio Zadrozny
Hi All,

PyDev - Python IDE (Python Development Enviroment for Eclipse) version 
0.9.8.7 has been released.

Check the homepage (http://pydev.sourceforge.net/) for more details.

Details for Release: 0.9.8.7:
Major highlights:

* The debugger tracing was turned off (this was a bug in 0.9.8.6 and 
could make debugging much slower)
* Fixed jython shell (and extended it to get better information on 
code-completion).
* Changed the interpreter configuration so that it is 
backwards-compatible from now on...(but the current interpreters will be 
lost and will need to be configured)
* Breakpoints can have conditionals(this was contributed by Achim 
Nierbeck, and was actually provided in release 0.9.8.6, but I forgot to 
put it in the release notes)
* Some other bugfixes are also in this build.

Cheers,

Fabio

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

PyDev - Python Development Enviroment for Eclipse
pydev.sf.net
pydev.blogspot.com

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


forced spaces when inserting a variable between strings

2006-01-17 Thread mjteigen
I'm very new at Python, but have been trying it in conjunction with
CGI. I've encountered a problem that I'm pretty sure is a trivial one,
but I don't know enough Python to work it out. Here's an example.
Imagine that I have a file named 5.jpg in the same directory as this
Python script:

   print content-type: text/html\n
   number = 5
   print img src=,number,.jpg

My goal is print out 'img src=5.jpg'. However, when I view the
source on the generated html page, I see this:

   img src= 5 .jpg

In other words, that 5 has a space tacked on either side of it, and
of course a browser can't find the file. Is there a way I can avoid the
tacking of spaces on either side of a variable inserted between two
strings?

TIA :-)
--
m j teigen

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


Re: forced spaces when inserting a variable between strings

2006-01-17 Thread snoe
You can use:

print img src=%s.jpg % (number)
or
print img src=+str(number)+.jpg

or a number of others, but for short strings one of these two generally
work fine.

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


rational numbers

2006-01-17 Thread Schüle Daniel
Hello NG,

recently I was using Scheme and Ruby and was really nicely surprised
to find there support for the computing with rational numbers

for example this how it works in Ruby

mond:/pool/PROG/ruby # irb
irb(main):001:0
irb(main):002:0* require mathn
= true
irb(main):003:0 r = Rational(1,3)
= 1/3
irb(main):004:0 p = Rational(1,5)
= 1/5
irb(main):005:0 r+p
= 8/15
irb(main):007:0 (r+p)**2
= 64/225
irb(main):008:0

does anybody know modules which make rational numbers available?
and are there considerations to add them to the core, like
complex numbers (maybe in Python 3)

Regards, Daniel

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


Re: forced spaces when inserting a variable between strings

2006-01-17 Thread Stephen Illingworth
mjteigen wrote:

 My goal is print out 'img src=5.jpg'. However, when I view the
 source on the generated html page, I see this:
 
img src= 5 .jpg
 
 In other words, that 5 has a space tacked on either side of it, and
 of course a browser can't find the file. Is there a way I can avoid the
 tacking of spaces on either side of a variable inserted between two
 strings?

Yes, use placeholders. In your example,

print img src=\%d.jpg\ % (number,)

http://www.python.org/dev/doc/devel/lib/typesseq-strings.html
http://diveintopython.org/native_data_types/formatting_strings.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decimal ROUND_HALF_EVEN Default

2006-01-17 Thread 3c273
Thanks to all! Interesting reading.

Louis


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


Re: forced spaces when inserting a variable between strings

2006-01-17 Thread Xavier Morel
mjteigen wrote:
 I'm very new at Python, but have been trying it in conjunction with
 CGI. I've encountered a problem that I'm pretty sure is a trivial one,
 but I don't know enough Python to work it out. Here's an example.
 Imagine that I have a file named 5.jpg in the same directory as this
 Python script:
 
print content-type: text/html\n
number = 5
print img src=,number,.jpg
 
 My goal is print out 'img src=5.jpg'. However, when I view the
 source on the generated html page, I see this:
 
img src= 5 .jpg
 
 In other words, that 5 has a space tacked on either side of it, and
 of course a browser can't find the file. Is there a way I can avoid the
 tacking of spaces on either side of a variable inserted between two
 strings?
 
 TIA :-)
 --
 m j teigen
 
1- Use sys.stdout.write(), it doesn't add any kind of formatting to the data
2- You may also use string interpolation, either in sys.stdout.write or 
in print
3- I'd suggest you to use a templating system in order to separate the 
displayed data and the retrieval/computations of said data, and prevent 
from mixing logic and presentation in your scripts (which always leads 
to an unmaintainable system)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: magical expanding hash

2006-01-17 Thread Paul Rubin
Diez B. Roggisch [EMAIL PROTECTED] writes:
  BTW: remember that setdefault() is written setdefault() but it's read
  getorset().
 
 I can only second that. The misleading name has - well, mislead me :)

Hmm,

   x[a][b][c][d] = e# x is a magic dict

becomes

   x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e

if I understand correctly.  Ugh.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Testing complex new syntax

2006-01-17 Thread Carl Friedrich Bolz
Hi!

[EMAIL PROTECTED] wrote:
 I have some significantly extended syntax for Python that I need to
 create a reference implementation for. My new syntax includes new
 keywords, statements and objects that are sort of like classes but not
 really. The implementation is all possible using standard Python, but
 the implementation isn't the point of what I'm doing. Speed and having
 an extra step to run a program are not issues that I need to be
 concerned with.
 I'd like to create a preprocessor if possible, because it would
 probably be easier than implementing the changes in the interpreter. I
 could just drop in standard Python code that provides the functionality
 when I encounter a part of my extended syntax. Modifying the
 interpreter, on the other hand, sounds like it would be pretty nasty,
 even though I have experience in interpreter hacking already.
 So my question is: what's the easiest way to implement a preprocessor
 system in Python? I understand I could use the tokenize module, but
 that would still require a lot of manual parsing of the Python syntax.
 Is it possible to use any of the parser module facilities to accomplish
 this without them choking on the unknown syntax? Or, alternatively,
 would modifying the interpreter ultimately be easier?
 

I cannot really say much about how easy it would be to just write a 
preprocessor. However, I think what you are trying to do could be done 
reasonably easy with the PyPy project:

http://codespeak.net/pypy

PyPy is an implementation of a Python interpreter written in Python. 
(Disclaimer: I am a PyPy developer). It has a quite flexible 
parser/bytecode compiler that could probably be tweaked to support your 
new syntax (especially if the new constructs can be mapped to standard 
python). Feel free to ask question on the pypy developer mailing list:

http://codespeak.net/mailman/listinfo/pypy-dev

Cheers,

Carl Friedrich Bolz

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


Re: rational numbers

2006-01-17 Thread Paul Rubin
Schüle Daniel [EMAIL PROTECTED] writes:
 does anybody know modules which make rational numbers available?

Try gmpy.mpq (google for gmpy).

 and are there considerations to add them to the core, like
 complex numbers (maybe in Python 3)

I don't think it's been discussed much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: rational numbers

2006-01-17 Thread Paul Rubin
Schüle Daniel [EMAIL PROTECTED] writes:
 does anybody know modules which make rational numbers available?
 and are there considerations to add them to the core, like
 complex numbers (maybe in Python 3)

I think it's not likely.  In Scheme, (/ 5 2) is the rational number
5/2, while in current Python, 5/2 is the integer 2.  If Python got
native rationals, we'd expect something similar.  But it's been
publicly announced that in Python 3, 5/2 will be the floating point
number 2.5.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert Active Directory Object to string

2006-01-17 Thread Fredrik Lundh
Dirk Hagemann wrote:

 When I receive data from Microsoft Active Directory it is an
ad_object and has the type unicode. When I try to convert it to a
 string I get this error:
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in
 position 26: ordinal not in range(128)

 This is caused by characters like the german ä, ö or ü.

 But I (think I) need this as a string. Is there a simple solution???

A Unicode string is also a string.

If you want an 8-bit string, you need to decide what encoding you want to
use.  Common encodings are us-ascii (which is the default if you convert from
unicode to 8-bit strings in Python), ISO-8859-1 (aka Latin-1), and UTF-8.
For example, if you want Latin-1 strings, you can use one of.

s = u.encode(iso-8859-1) # fail if some character cannot be converted
s = u.encode(iso-8859-1, replace) # instead of failing, replace with ?
s = u.encode(iso-8859-1, ignore) # instead of failing, leave it out

If you want an ascii string, replace iso-8859-1 above with ascii.

If you want to output the data to a web browser or an XML file, you can use

import cgi
s = cgi.escape(u).encode(ascii, xmlcharrefreplace)

/F 



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

Re: rational numbers

2006-01-17 Thread Carsten Haese
On Tue, 2006-01-17 at 11:22, Paul Rubin wrote:
 Schüle Daniel [EMAIL PROTECTED] writes:
  does anybody know modules which make rational numbers available?
 
 Try gmpy.mpq (google for gmpy).
 
  and are there considerations to add them to the core, like
  complex numbers (maybe in Python 3)
 
 I don't think it's been discussed much.

Somebody must have discussed it. There is a rejected PEP for adding a
Rational type to python:

http://www.python.org/peps/pep-0239.html

-Carsten


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


Convert Active Directory Object to string

2006-01-17 Thread Dirk Hagemann
Hi!

When I receive data from Microsoft Active Directory it is an
ad_object and has the type unicode. When I try to convert it to a
string I get this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in
position 26: ordinal not in range(128)

This is caused by characters like the german ä, ö or ü.

But I (think I) need this as a string. Is there a simple solution???

regards
Dirk

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


Find and slice problem

2006-01-17 Thread jont999
Hi guys, been going around in circles with this so I hope you can help!

My current situation is I'm using Grinder and Jython to test pages, but
the log on process is giving me some headaches. After entering the
correct username and password, you then need to enter 3 characters from
the security phrase. I'm attempting to read the HTML to find out with
characters I need (e.g. 1st, 3rd and 6th char) then look up those
values in the security phrase, but I'm getting stuck on the following
function:

code

def getValue(page,delimEnd) :
EndVar = page.find(delimEnd)
thisVar =  page[EndVar-1:EndVar]
return thisVar

/code

unique code I'm using as a delimeter
:/strong/td
  td class=producttableinnerborder/td
  td/td

  tdselect name=char1
/unique code I'm using as a delimeter

the specific number I require proceeds the ':' at the start of the
code.

What I'm attemping to pass in is some multiline HTML(above) and pick up
the proceeding character, but it seems to be reading from the end of
the HTML instead! I've only been using this setup for a couple of days
so it's probably something simple, anyone care to enlighten me?

cheers,

Jon

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


Looking for standalone Python

2006-01-17 Thread Twig
Hello,

I have a need to have python on intranet server for other users to 
create a common tool base for working community (SW). So that workers 
can take it in use just by mapping the drive adding dirs to paths.

Need to have all standard modules at the same place, so there would not 
be any local installations required.

Is this possible? Easy?

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


HTML library

2006-01-17 Thread Ron Griswold








Hi Folks,



Can someone point me in the direction of an html library
that generates html text for you. For example, if I
had a tuple of tuples, Id like a function that would create a table for
me. Ive looked through the standard library and it only seems to have
html parsers. I need to go the other way ;)



Thanks,



Ron Griswold

Character TD

R!OT Pictures

[EMAIL PROTECTED]








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

Re: SMPP implementation in python

2006-01-17 Thread Todd Whiteman
SMPP, are you referring to the Short Message Peer to Peer protocol?

If so, I implemented this in python some 4 years ago for SMPP v3.4, I 
have the source code, which I might release LGPL if interested.

Cheers,
Todd

Alvin A. Delagon wrote:
 Greetings!

 Does anyone know a good reference on how to implement SMPP in python. I 
 can't find any besides NET::SMPP in perl and I don't want to get my 
 hands for that. Thanks in advance!
   

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


chi-squared tests in python?

2006-01-17 Thread Matthew Vernon
Hi,

I'd like to be able to use the chi-squared test in my code. Currently,
I can output look up [this value] in a chi-squared table with [x]
degrees of freedom, but that's obviously a little sub-optimal. I
notice that numarray has a chi_square function, but that just gives
you random numbers from a chi-squared distribution with a set number
of degrees of freedom - not really what I want.

Does there exist python code to do this? preferably something vaguely
standard? 

Thanks,

Matthew
ps: given the batteries included philosphy, there's a remarkable dearth 
of stats in python...
-- 
Matthew Vernon MA VetMB LGSM MRCVS
Farm Animal Epidemiology and Informatics Unit
Department of Veterinary Medicine, University of Cambridge
http://www.cus.cam.ac.uk/~mcv21/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for standalone Python

2006-01-17 Thread Szabolcs Nagy
 Is this possible?
yes: movable python
http://www.voidspace.org.uk/python/movpy/introduction.html

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


Re: Looking for standalone Python

2006-01-17 Thread Twig
Szabolcs Nagy wrote:
Is this possible?
 
 yes: movable python
 http://www.voidspace.org.uk/python/movpy/introduction.html
 

Thanks! Also found this:

http://arctrix.com/nas/python/standalone.html
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: HTML library

2006-01-17 Thread Ron Griswold
Hi Cliff,

Looks like xist is exactly what I'm looking for. 

Thank you,

Ron Griswold
Character TD
R!OT Pictures
[EMAIL PROTECTED]


-Original Message-
From: Cliff Wells [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 17, 2006 9:33 AM
To: Ron Griswold
Cc: python-list@python.org
Subject: Re: HTML library

On Tue, 2006-01-17 at 09:28 -0800, Ron Griswold wrote:
 Hi Folks,
 
  
 
 Can someone point me in the direction of an html library that
 generates html text for you. For example, if I had a tuple of tuples,
 I'd like a function that would create a table for me. I've looked
 through the standard library and it only seems to have html parsers. I
 need to go the other way ;)
 

The two best things I know of are Nevow's Stan and XIST.  Since I
started using Stan, I've vowed to never write another line of XML.


http://divmod.org/trac/wiki/DivmodNevow

http://www.livinglogic.de/Python/xist/


Regards,
Cliff


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


Re: _bsddb on NetBSD

2006-01-17 Thread Laszlo Zsolt Nagy
Miki Tebeka wrote:

Hello All,

I can't seem to build Python2.4.2 with bsddb on NetBSD.
bsddb seems to be missing from the pkg_add installation as well.
  

Please look at the message that you get when you execute

pkg_add -r python

You will see that tkinter, bsddb, gdbm and some other libs are available 
as separate packages.

Did you try

pkg_add -r py24_bsddb
pkg_add -r py24_gdbm


Best,

   Les

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


Re: HTML library

2006-01-17 Thread Cliff Wells
On Tue, 2006-01-17 at 09:28 -0800, Ron Griswold wrote:
 Hi Folks,
 
  
 
 Can someone point me in the direction of an html library that
 generates html text for you. For example, if I had a tuple of tuples,
 I’d like a function that would create a table for me. I’ve looked
 through the standard library and it only seems to have html parsers. I
 need to go the other way ;)
 

The two best things I know of are Nevow's Stan and XIST.  Since I
started using Stan, I've vowed to never write another line of XML.


http://divmod.org/trac/wiki/DivmodNevow

http://www.livinglogic.de/Python/xist/


Regards,
Cliff

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

Re: chi-squared tests in python?

2006-01-17 Thread Robert Kern
Matthew Vernon wrote:
 Hi,
 
 I'd like to be able to use the chi-squared test in my code. Currently,
 I can output look up [this value] in a chi-squared table with [x]
 degrees of freedom, but that's obviously a little sub-optimal. I
 notice that numarray has a chi_square function, but that just gives
 you random numbers from a chi-squared distribution with a set number
 of degrees of freedom - not really what I want.
 
 Does there exist python code to do this? preferably something vaguely
 standard? 

Yes, in Scipy.

  from scipy.stats import chi2

  # one-sided Chi^2 test
  pval = 1 - chi2.cdf(value, dof)

http://new.scipy.org/Wiki
[This URL will be http://www.scipy.org in a week or so, I hope.]

 Matthew
 ps: given the batteries included philosphy, there's a remarkable dearth 
 of stats in python...

I think Chi^2 tests fall distinctly in the third-party library category, 
myself.

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter

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


Re: magical expanding hash

2006-01-17 Thread Steven Bethard
Paul Rubin wrote:
 Hmm,
 
x[a][b][c][d] = e# x is a magic dict
 
 becomes
 
x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e
 
 if I understand correctly.  Ugh.

Agreed.  I really hope that Python 3.0 applies Raymond Hettinger's 
suggestion Improved default value logic for Dictionaries from
 http://wiki.python.org/moin/Python3%2e0Suggestions

This would allow you to make the setdefault() call only once, instead of 
on every lookup:

 class meh(dict):
 def __init__(self, *args, **kwargs):
 super(meh, self).__init__(*args, **kwargs)
 self.setdefault(function=meh)

STeVe

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


Re: Preventing class methods from being defined

2006-01-17 Thread Bengt Richter
On Mon, 16 Jan 2006 18:55:43 -0800, David Hirschfield [EMAIL PROTECTED] wrote:

Thanks for this, it's a great list of the ways it can be done. Here's a 
Actually, your way is yet another ;-)

bit more insight into the arrangement I'm trying to get:

restrict = True
Why a global value? If it is to affect class instantiation, why not pass it
or a value to the constructor, e.g., C(True) or C(some_bool)?


class A(object):
   ^--should that be R?
_restrict = [test]
   
def _null(self, *args, **kws):
raise Exception,not allowed to access
   
def test(self):
print test restricted
   
def __init__(self):
if restrict:
for f in self._restrict:
setattr(self,f,self._null)
I assume you know that you are using a bound method attribute
on the instance to shadow the method of the class, for a per-instance
effect as opposed to an all-instances shared effect.

   
class C(R):
def __init__(self):
super(C,self).__init__()
   
def test(self):
print test from c


In this design, calling c.test() where c is an instance of C will raise 
an exception. Now, the only thing I'd like is to not have to fill out 
that _restrict list like that, but to have some function or something 
that let's me say which methods are restricted in the same way you 
define class methods or properties, i.e.:

class A(object):
_restrict = []
   
def _null(self, *args, **kws):
raise Exception,not allowed to access
   
def test(self):
print test restricted
restrict(test)
 this does some magic to insert test into the _restrict list


I can't really find a way to make that work with descriptors, and it 
can't just be a function call, because I won't know what object to get 
the _restrict list from. Is there a way to refer to the class that is 
being defined when calling a function or classmethod?
So, ideas on how to accomplish that...again, greatly appreciated.

You can do it with a decorator, though it doesn't really do decoration,
just adding the decoratee to the associated _restrict list. You don't
have to factor out mkrdeco if you'r'e only defining the restrict decorator
in one class.

I changed A to R, and made the global restriction flag a constructor argument,
but you can easily change that back, either by using the global restricted
in R.__init__ as a global, or by passing it explicitly like c = C(restricted).

  def mkrdeco(rlist):
 ... def restrict(f):
 ... rlist.append(f.func_name)
 ... return f
 ... return restrict
 ...
  class R(object):
 ... _restrict = []
 ... restrict = mkrdeco(_restrict)
 ... def _null(self, *args, **kws):
 ... raise Exception,not allowed to access
 ... def __init__(self, restricted):
 ... if restricted:
 ... for f in self._restrict:
 ... setattr(self,f,self._null)
 ... @restrict
 ... def test(self):
 ... print test restricted
 ...
  class C(R):
 ...def __init__(self, restricted=False):
 ...super(C,self).__init__(restricted)
 ...
 ...def test(self):
 ...print test from c
 ...
  c = C(True)
  c.test()
 Traceback (most recent call last):
   File stdin, line 1, in ?
   File stdin, line 5, in _null
 Exception: not allowed to access
  c2 = C(False)
  c2.test()
 test from c
  vars(c)
 {'test': bound method C._null of __main__.C object at 0x02EF3C4C}
  vars(c2)
 {}
  R._restrict
 ['test']
 
Still don't know what real application problem this is solving, but that's ok 
;-)

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


Re: SQLObject connection pooling

2006-01-17 Thread jeff . lewis
Hi Jake,

When establishing a new connection using sqlobject, there is a param
called cache that has a default val of True.  See

http://sqlobject.org/SQLObject.html#declaring-the-class

For more info, potential gotchas, etc, check out

http://wiki.sqlobject.org/connections.html
http://pythonpaste.org/archives/message/20051128.204519.6c759047.en.html
http://trac.turbogears.org/turbogears/wiki/SqlobjectCaching

Cheers,

Jeff

[EMAIL PROTECTED] wrote:
 Hello.  Does SQLObject provide connection pooling?  If so, is it
 automatic or do I have to do something to manage it?  If not, how do
 people generally solve this problem?
 
 Thanks for any help.
 
 - Jake

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


Re: Preventing class methods from being defined

2006-01-17 Thread David Hirschfield

bit more insight into the arrangement I'm trying to get:

restrict = True


Why a global value? If it is to affect class instantiation, why not pass it
or a value to the constructor, e.g., C(True) or C(some_bool)?

  

For reasons unrelated to this problem, the class that does this magic 
can't take any parameters to its __init__ method.

class A(object):


   ^--should that be R?
  

Yes, it should. Damn you Copy and Paste!

   _restrict = [test]
  
   def _null(self, *args, **kws):
   raise Exception,not allowed to access
  
   def test(self):
   print test restricted
  
   def __init__(self):
   if restrict:
   for f in self._restrict:
   setattr(self,f,self._null)


I assume you know that you are using a bound method attribute
on the instance to shadow the method of the class, for a per-instance
effect as opposed to an all-instances shared effect.

  

Yes, that's true...it shouldn't really matter for my usage. What would I 
do to make this an all-instances-shared thing?

  
class C(R):
   def __init__(self):
   super(C,self).__init__()
  
   def test(self):
   print test from c


In this design, calling c.test() where c is an instance of C will raise 
an exception. Now, the only thing I'd like is to not have to fill out 
that _restrict list like that, but to have some function or something 
that let's me say which methods are restricted in the same way you 
define class methods or properties, i.e.:

class A(object):
   _restrict = []
  
   def _null(self, *args, **kws):
   raise Exception,not allowed to access
  
   def test(self):
   print test restricted
   restrict(test)
    this does some magic to insert test into the _restrict list


I can't really find a way to make that work with descriptors, and it 
can't just be a function call, because I won't know what object to get 
the _restrict list from. Is there a way to refer to the class that is 
being defined when calling a function or classmethod?
So, ideas on how to accomplish that...again, greatly appreciated.



You can do it with a decorator, though it doesn't really do decoration,
just adding the decoratee to the associated _restrict list. You don't
have to factor out mkrdeco if you'r'e only defining the restrict decorator
in one class.

I changed A to R, and made the global restriction flag a constructor argument,
but you can easily change that back, either by using the global restricted
in R.__init__ as a global, or by passing it explicitly like c = C(restricted).

  def mkrdeco(rlist):
 ... def restrict(f):
 ... rlist.append(f.func_name)
 ... return f
 ... return restrict
 ...
  class R(object):
 ... _restrict = []
 ... restrict = mkrdeco(_restrict)
 ... def _null(self, *args, **kws):
 ... raise Exception,not allowed to access
 ... def __init__(self, restricted):
 ... if restricted:
 ... for f in self._restrict:
 ... setattr(self,f,self._null)
 ... @restrict
 ... def test(self):
 ... print test restricted
 ...
  class C(R):
 ...def __init__(self, restricted=False):
 ...super(C,self).__init__(restricted)
 ...
 ...def test(self):
 ...print test from c
 ...
  c = C(True)
  c.test()
 Traceback (most recent call last):
   File stdin, line 1, in ?
   File stdin, line 5, in _null
 Exception: not allowed to access
  c2 = C(False)
  c2.test()
 test from c
  vars(c)
 {'test': bound method C._null of __main__.C object at 0x02EF3C4C}
  vars(c2)
 {}
  R._restrict
 ['test']
 
Still don't know what real application problem this is solving, but that's ok 
;-)

Regards,
Bengt Richter
  

I'm using python 2.3.3 here, so no go on the nice decorator, but I can 
definitely use the concept to make it work, thanks.
-David

-- 
Presenting:
mediocre nebula.

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


Re: Can't compile

2006-01-17 Thread llothar
Here i jump into this thread.
With this option the configure script runs well.
But then i get a compile error in  complexobject.

I'm using Solaris in  32-Bit Mode on my AthlonX2.

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


Re: Socket Programming HOWTO example

2006-01-17 Thread Bryan Olson
I mis-phrased:
 The code passes
 'self' to __init__, but not to any of the others methods.

Of course I meant that the formal parameter for self is missing.

   class mysocket:
 
 '''classe solamente dimostrativa
   - codificata per chiarezza, non per efficenza'''
 def __init__(self, sock=None):
 if sock is None:
 self.sock = socket.socket(
 socket.AF_INET, socket.SOCK_STREAM)
 else:
 self.sock = sock
 def connect(host, port):
 self.sock.connect((host, port))
 def mysend(msg):
[...]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: magical expanding hash

2006-01-17 Thread braver
Nice.  What about pushing to leaves which are arrays, or incrementing
leaves which are numbers?  If the array leaf didn't exist, or a number
wasn't set yet,  must create an empty array and push the element from
the RHS into it, and += must init the leaf to 0 and add the RHS to it.
Here's the corresponding ruby:

# ruby!

class MagicalExpandingHash  Hash
  def initialize(*params)
if params.first.is_a? MagicalExpandingHash
  @parentObj, @parentKey = params[0..1]
  params = params[2..-1]
end
super(*params) { |h,k|
  h[k] = MagicalExpandingHash.new(self,k)
}
  end
  def (elem)
if @[EMAIL PROTECTED]
  @[EMAIL PROTECTED] = [ elem ]
else
  raise ArgumentError, Can't push onto populated index, caller
end
  end
  def +(elem)
unless elem.is_a? Numeric
  raise ArgumentError, Can't add a non-Numeric value, caller
end
if @[EMAIL PROTECTED]
  @[EMAIL PROTECTED] = elem
else
  raise ArgumentError, Can't add to populated index, caller
end
  end

  def to_hash
h = Hash.new
self.each_pair {|k,v| h[k]=(v.class==self.class)? v.to_hash : v }
return h
  end

  def from_hash(h)
h.each_pair {|k,v| self[k]=(v.is_a? Hash) ?
self.class.new.from_hash(v) : v}
  end

  def marshal_dump
self.to_hash
  end
  def marshal_load(h)
from_hash(h)
  end
end

# examples
if $0 == __FILE__
  meh = MagicalExpandingHash.new

  meh['usa']['france']  'tocqueville'
  meh['usa']['france']  'freedom fries'
  meh['life']['meaning'] += 42

  puts meh.inspect
  # = {usa={france=[tocqueville, freedom fries]},
life={meaning=42}}
end

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


Re: Decimal ROUND_HALF_EVEN Default

2006-01-17 Thread Bengt Richter
On 16 Jan 2006 20:36:12 -0800, Raymond Hettinger [EMAIL PROTECTED] wrote:

LordLaraby wrote:
 If 'bankers rounding' is HALF_ROUND_EVEN, what is HALF_ROUND_UP? I
 confess to never having heard the terms.

The terms are defined in the docs for the Context object:
http://docs.python.org/lib/decimal-decimal.html

The rounding option is one of:
--
ROUND_CEILING (towards Infinity),
ROUND_DOWN (towards zero),
ROUND_FLOOR (towards -Infinity),
ROUND_HALF_DOWN (to nearest with ties going towards zero),
ROUND_HALF_EVEN (to nearest with ties going to nearest even integer),
ROUND_HALF_UP (to nearest with ties going away from zero), or
ROUND_UP (away from zero).


 I usually do: Y = int(X + 0.5) scaled to proper # of decimal places.
 Which type of rounding is this? If either.

The interpreter shows that ties are rounded down towards zero:

 [int(x + 0.5) for x in range(-5, 6)]
[-4, -3, -2, -1, 0, 0, 1, 2, 3, 4, 5]

Or more explicitly:
  for x in xrange(-5,6): print 'int(%2s + 0.5) == int(%4s) = 
  %2s'%(x,x+.5,int(x+.5))
 ...
 int(-5 + 0.5) == int(-4.5) = -4
 int(-4 + 0.5) == int(-3.5) = -3
 int(-3 + 0.5) == int(-2.5) = -2
 int(-2 + 0.5) == int(-1.5) = -1
 int(-1 + 0.5) == int(-0.5) =  0
 int( 0 + 0.5) == int( 0.5) =  0
 int( 1 + 0.5) == int( 1.5) =  1
 int( 2 + 0.5) == int( 2.5) =  2
 int( 3 + 0.5) == int( 3.5) =  3
 int( 4 + 0.5) == int( 4.5) =  4
 int( 5 + 0.5) == int( 5.5) =  5

So one must be careful not to use int to convert relative screen positions to 
relative pixel deltas
to add to some pixel screen position, even when it's a single add that can't 
accumulate error or
round differentely after the add.

I guess one would want
  for x in xrange(-5,6): print 'int(math.floor(%4s)) = 
  %2s'%(x+.5,int(math.floor(x+.5)))
 ...
 int(math.floor(-4.5)) = -5
 int(math.floor(-3.5)) = -4
 int(math.floor(-2.5)) = -3
 int(math.floor(-1.5)) = -2
 int(math.floor(-0.5)) = -1
 int(math.floor( 0.5)) =  0
 int(math.floor( 1.5)) =  1
 int(math.floor( 2.5)) =  2
 int(math.floor( 3.5)) =  3
 int(math.floor( 4.5)) =  4
 int(math.floor( 5.5)) =  5

Which ISTM is the way some other int conversions have worked, but I can't 
recall the context ATM.
I.e., just trim the fractional bits from the theoretical fixed point twos 
complement number, which
always subtracts those positive-value fractional bits algebraically.

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


time scheduling in ptyhon

2006-01-17 Thread jiri . juranek
Hello,
i am learning python so this will be propably a stupid
question/problem, so sorry ;)

I need schedule some jobs, times of this jobs are read from database.
So i would like to periodically(every hour) run some python script(or
leave runnig some script which will every hour start some method) which
will read times for jobs from database and schedule that jobs. I am
looking for the simplest solution,  i have some ideas but i dont know
how they are difficult and if they are possible in python.
Thanks for all notes/advice/samples/links/modules


JJ

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


Re: SMPP implementation in python

2006-01-17 Thread Damjan
You can see some code here http://pysmpp.sourceforge.net/ but it's not
complete... it need much more work.

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


Re: time scheduling in ptyhon

2006-01-17 Thread Grant Edwards
On 2006-01-17, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 I need schedule some jobs, times of this jobs are read from database.
 So i would like to periodically(every hour) run some python script

$ man cron

 (or leave runnig some script which will every hour start some
 method) which will read times for jobs from database and
 schedule that jobs.

Sounds like you're duplicating the function of cron.

 I am looking for the simplest solution, i have some ideas but
 i dont know how they are difficult and if they are possible in
 python. Thanks for all notes/advice/samples/links/modules

-- 
Grant Edwards   grante Yow!  Where does it go when
  at   you flush?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running DOS App on win32 via python over ssh

2006-01-17 Thread James Stroud
Peter Hansen wrote:
 James Stroud wrote:
 
 I am helping someone write a python script to run their DOS 
 application through an SSH terminal. It seems that this program wants 
 to access a DOS shell and send output there. If running remotely, this 
 causes a problem because it locks up the program. The program seems 
 (to me) to be looking for some non-existant DOS shell to send its 
 output to. How might I emulate this shell (or whatever it is) with 
 python? I have tried several flavors of python (Enthought, 
 ActiveState, etc.). I have tried win32pipe.popen[1-4], and many other 
 things that I can't even remember now. 
 
 
 What makes you think there's any DOS shell involved?  Many DOS 
 programs didn't write to stdout, but drew directly into screen memory 
 with BIOS calls and such.  Are you sure this is a more generic command 
 line program that just writes to stdout or the console?
 
 -Peter
 

I honestly have no idea what this program is trying to do or whether a 
DOS shell is involved. I'm just assuming based on the behavior. The 
behavior is that if I start x-windows from the main cygwin terminal, and 
then I run the program from xterm in x-windows, the output goes to the 
main cygwin terminal from which I started x-windows. The output does not 
go to the x-terminal. I assume that this bizarre behavior has something 
to do with the fact that it freezes when running over SSH.

Also, FWIW, I believe the program was written in pascal and compiled 
with turbo-pascal. The source is not available, though.

This is yet another reason why all thing microsoft suck!

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


Re: StringVar() IntVar() vs. Dictionary of same

2006-01-17 Thread Bob Greschke
Paul Rubin http://[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Bob Greschke [EMAIL PROTECTED] writes:
 Just roughly what do you think the effect would be?

 Either extremely slight or else nonexistent.

I kinda thought so.  Thanks!

Bob


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


Bounce messages

2006-01-17 Thread Grant Edwards
Whould whoever is gatewaying c.l.p postings to a mailing list
_please_ remove the return addresses on the postings so we
don't have to put up with bounce messages everytime we post?

-- 
Grant Edwards   grante Yow!  Everywhere I look
  at   I see NEGATIVITY and
   visi.comASPHALT...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: magical expanding hash

2006-01-17 Thread Paul Rubin
braver [EMAIL PROTECTED] writes:
 Nice.  What about pushing to leaves which are arrays, or incrementing
 leaves which are numbers?  If the array leaf didn't exist, or a number
 wasn't set yet,  must create an empty array and push the element from
 the RHS into it, and += must init the leaf to 0 and add the RHS to it.

Are you trying to simulate Ruby syntax or just implement those functions?
Implementing the functions is easy enough.  If you want Ruby syntax,
use Ruby.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: magical expanding hash

2006-01-17 Thread braver
Actually, the behavior is important to translate perl into ruby.  Can
it be implemented in python looking similarly?

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


Using CGI to interface with an XML-RPC server

2006-01-17 Thread Rob Cowie
Hi all,

Assume I have a working XML-RPC server that runs persistently and
correctly accepts remote calls, executes the relevant code and outputs
the XML-RPC result. This is fine when using an XML-RPC client.

However, I wish to provide a web user interface. I gather it is
possible to use PHP as an XML-RPC client but I am unable to do so
because of artificially imposed server constraints. All I am able to
use is good the old CGI.

Is it possible to create python CGI scripts that accept form data in
the usual way, package them as an XML-RPC request, call the server,
receive the response then format this response into valid HTML to be
emitted to the client? Is this desirable (what I mean is... is there an
easier way?).

Is there a better way to use a web browser as what is essentially an
XML-RPC client?

FYI, I know that is seems like using XML-RPC in this case is
pointless.. it isn't, some users do indeed use the server as intended.

Cheers,

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


Re: chi-squared tests in python?

2006-01-17 Thread Rob Cowie
 Matthew
 ps: given the batteries included philosphy, there's a remarkable dearth
 of stats in python...

I think Chi^2 tests fall distinctly in the third-party library category, 
myself.

I don't know... I've often thought the Standard Library should include
a stats package.

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


Re: magical expanding hash

2006-01-17 Thread Steve Holden
Steven Bethard wrote:
 Paul Rubin wrote:
 
Hmm,

   x[a][b][c][d] = e# x is a magic dict

becomes

   x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e

if I understand correctly.  Ugh.
 
 
 Agreed.  I really hope that Python 3.0 applies Raymond Hettinger's 
 suggestion Improved default value logic for Dictionaries from
  http://wiki.python.org/moin/Python3%2e0Suggestions
 
 This would allow you to make the setdefault() call only once, instead of 
 on every lookup:
 
  class meh(dict):
  def __init__(self, *args, **kwargs):
  super(meh, self).__init__(*args, **kwargs)
  self.setdefault(function=meh)
 
 STeVe
 
In fact, why not go one better and also add a default keyword 
parameter to dict()?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: magical expanding hash

2006-01-17 Thread Paul Rubin
braver [EMAIL PROTECTED] writes:
 Actually, the behavior is important to translate perl into ruby.  Can
 it be implemented in python looking similarly?

It's kind of bizarre in Python to use  as a mutation operator, but I
guess you could do it.  Sort of like 'cout  hello world' in C++.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time scheduling in ptyhon

2006-01-17 Thread utabintarbo
http://sourceforge.net/projects/pycron/

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


Re: magical expanding hash

2006-01-17 Thread braver
Exactly,  as in C++/ruby streams.  But notice the extra checks needed
to see whether we want a new leaf which is an array or a number, or we
create an intermediate hash level.  Would the checks look the same in
python?

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


Re: magical expanding hash

2006-01-17 Thread Fredrik Lundh
braver wrote

 Exactly,  as in C++/ruby streams.  But notice the extra checks needed
 to see whether we want a new leaf which is an array or a number, or we
 create an intermediate hash level.  Would the checks look the same in
 python?

we?

trust me, the number of people who think it's a good idea to write perl

/F



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


Re: Indentation/whitespace

2006-01-17 Thread Dave Hansen
On 16 Jan 2006 20:41:24 -0800 in comp.lang.python, thakadu
[EMAIL PROTECTED] wrote:

Yes, thats what you have to do. And that was my original point, you
cannot just paste and go, you have to first reformat.

My heart bleeds.

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't compile

2006-01-17 Thread Fredrik Lundh
llothar wrote:

 Here i jump into this thread.
 With this option the configure script runs well.
 But then i get a compile error in  complexobject.

so what did the compiler say ?

have you tried googling for relevant portions of the error message ?

could this be the problem you're seeing ?

http://www.python.org/sf/1276509

(see the comments for a workaround)

/F



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


Re: magical expanding hash

2006-01-17 Thread Paul Rubin
braver [EMAIL PROTECTED] writes:
 Exactly,  as in C++/ruby streams.  But notice the extra checks needed
 to see whether we want a new leaf which is an array or a number, or we
 create an intermediate hash level.  Would the checks look the same in
 python?

You could check what is being shifted and make a new leaf of the
appropriate type.  If you put a number there though, you wouldn't be
able to then add more nodes beneath that number.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Testing complex new syntax

2006-01-17 Thread astromog
Carl Friedrich Bolz wrote:
 I cannot really say much about how easy it would be to just write a
 preprocessor. However, I think what you are trying to do could be done
 reasonably easy with the PyPy project:

 http://codespeak.net/pypy

 PyPy is an implementation of a Python interpreter written in Python.
 (Disclaimer: I am a PyPy developer). It has a quite flexible
 parser/bytecode compiler that could probably be tweaked to support your
 new syntax (especially if the new constructs can be mapped to standard
 python).

It looks like the lack of thread support means I can't just use PyPy by
itself, unfortunately. But the tokeniser, lexer, parser and AST builder
could do what I need with modification, then I could walk the generated
AST and produce standard Python code from that. How easy would it be to
separate these parts out from the rest of PyPy?

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


Re: Shrinky-dink Python (also, non-Unicode Python build is broken)

2006-01-17 Thread Neil Hodgson
Larry Hastings:

 As for future development of Windows-specific Python features...
 doesn't that generally happen in modules, rather than the Python
 interpreter, these days?  Either in Mark Hammond's pywin32 (what used
 to be called win32all), or perhaps done in Python using ctypes.
 There haven't been any changes to the three Windows-specific modules
 (msvcrt, winreg, and winsound) mentioned in any What's New in Python
 2.x document, and 2.0 came out more than five years ago.

It is in the built-in modules providing OS features that there 
should be more use of Unicode. Unicode system calls are more accurate 
and have fewer limitations than ANSI system calls. Examples are allowing 
Unicode in sys.argv and os.environ or for file paths where the ANSI 
versions are limited to less than 260 characters.

Are you willing to monitor and fix new Py_USING_UNICODE issues or 
are you proposing just to produce a patch now and then expect 
contributors to maintain this feature?

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


Re: New Python.org website ?

2006-01-17 Thread [EMAIL PROTECTED]
Tim Parkin wrote:
 [EMAIL PROTECTED] wrote:
  JW wrote:
 Very strange.  With FF 1.0.7, I can just get the buttons to violate the
 next column if I ViewPage StyleLarge Text, but I wouldn't have noticed
 it unless Tim had pointed it out.  Tim's gifs are much worse than what
 I see. WIth ViewPage StyleBasic Page Style, it looks really good.
 
 
  Mine looks like Tim's gifs, with Basic Page Style.
 I've got an old copy of the html and tried to fix the general problem.
 It's currently on another website

 http://pyyaml.org/downloads/masterhtml/

Works for me, and Large Text style is larger than Basic Page Style for
me as well. FF1.5.  Also looks fine in my decrepit old version of
konquerer.

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


Re: magical expanding hash

2006-01-17 Thread Fredrik Lundh
braver wrote

 Exactly,  as in C++/ruby streams.  But notice the extra checks needed
 to see whether we want a new leaf which is an array or a number, or we
 create an intermediate hash level.  Would the checks look the same in
 python?

we?

trust me, the number of people who think it's a good idea to write perl-
inspired ruby and run that code in a python interpreter is very limited.

and even if you succeed in persuading someone else to write the code
for you, don't you think your users will find out pretty quickly that python's
not ruby ?

/F



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


Re: New Python.org website ?

2006-01-17 Thread Tim Chase
I've got an old copy of the html and tried to fix the general problem.
It's currently on another website

http://pyyaml.org/downloads/masterhtml/

This seems to no longer have the problem and scales nicely no 
matter which font-size I use.  Good work!

-tim




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


Re: magical expanding hash

2006-01-17 Thread braver
The point of this exercise is to compare how either ruby or python can
implement perl's default behavior when dealing with hashes.  Since
these are bread and butter of scripting, having a MEH class handy can
enable fast semantically equivalent translation.  This can be
beneficial for demonstrating feasibility of migrating to python.
Instead of debating philosophical justifications, I rather wonder
what's the most appropriate pythonic way to solve the problem as stated.

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


Converting TIFF files to PDF and/or JPEG

2006-01-17 Thread sophie_newbie
Hey guys,

As part of a college project I'm trying to write a script to convert
TIFF images downloaded from the US patent office site, www.uspto.gov.

The tiff images are encoded using CCITT Group 4 compression and appear
to throw an error when i try to save them using the Image library:

 im.save(outfile, PDF)


It looks like this odd compression format is not supported, or am i
wrong?

I know its a long shot but would anyone have a different solution?

Sophie.

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


Re: magical expanding hash

2006-01-17 Thread Fredrik Lundh
braver wrote:

 The point of this exercise is to compare how either ruby or python can
 implement perl's default behavior when dealing with hashes.  Since
 these are bread and butter of scripting, having a MEH class handy can
 enable fast semantically equivalent translation.  This can be
 beneficial for demonstrating feasibility of migrating to python.

if you want to write perl code, why migrate to some other language ?

 Instead of debating philosophical justifications, I rather wonder
 what's the most appropriate pythonic way to solve the problem
 as stated.

write python code.

/F



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


  1   2   >