Is there a way to take a priori knowledge out of field definitions?

2006-09-10 Thread Hendrik van Rooyen
Hi,

It is possible to build a system where the fields are "self defining" : -

One way is to keep a dictionary of tags and descriptors, and to keep "the data"
in a dictionary using the same tags as keys, with values - an oversimplified
example:

DefinitionDict = {1:'Quantity',2:'Price',3:'Value'}

DataItemDict = {1:10,2:3.50,3:35.00}

This is conceptually not much different to putting headers on columns in a
database table or a spreadsheet, with the data item being a row, or to HT or
XML.

Now obviously the definitions need not be single valued strings, but could be
multivalues, for use at different times, such as for gui displaying, for
printing, etc, and could also hold type information, as most databases do.

Up to this point, there is no a priori human knowledge mixed in with the data
that has not been written down.

However, when we want to make say a validation rule, such as Quantity times
Price must equal Value, then we are using a priori knowledge about the data to
formulate this.

At this point, if a routine is written to check that DataItemDict[1] multiplied
by DataItemDict[2] is indeed equal to DataItemDict[3], then we are casting the
meanings into stone, and the flexibility of the structure is to a large extent
lost.

Now if I want to make a system where these sort of rules, as well as more
complicated ones, are also definable - Is there a way to do it simply and
cleanly - a way to expand the DefinitionDict so that it contains all of what we
know about the structure and relationships of and between the items of data?

It seems to me that if this could be done, then it could be used to dynamically
generate the routines needed for validation, update, etc...

But my brain strains when I try to think about how to do it...

- Hendrik

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


Problems with email.Generator.Generator

2006-09-10 Thread Chris Withers
Hi All,

The following piece of code is giving me issues:

from email.Charset import Charset,QP
from email.MIMEText import MIMEText
charset = Charset('utf-8')
charset.body_encoding = QP
msg = MIMEText(
 u'Some text with chars that need encoding: \xa3',
 'plain',
 )
msg.set_charset(charset)
print msg.as_string()

Under Python 2.4.2, this produces the following output, as I'd expect:

MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="utf-8"

Some text with chars that need encoding: =A3

However, under Python 2.4.3, I now get:

Traceback (most recent call last):
   File "test_encoding.py", line 14, in ?
 msg.as_string()
   File "c:\python24\lib\email\Message.py", line 129,
in
as_string
 g.flatten(self, unixfrom=unixfrom)
   File "c:\python24\lib\email\Generator.py", line 82,
in flatten
 self._write(msg)
   File "c:\python24\lib\email\Generator.py", line 113,
in _write
 self._dispatch(msg)
   File "c:\python24\lib\email\Generator.py", line 139,
in
_dispatch
 meth(msg)
   File "c:\python24\lib\email\Generator.py", line 182,
in
_handle_text
 self._fp.write(payload)
UnicodeEncodeError: 'ascii' codec can't encode
character
u'\xa3' in position 41:
  ordinal not in range(128)

This seems to be as a result of this change:

http://svn.python.org/view/python/branches/release24-maint/Lib/email/Generator.py?rev=42272&r1=37910&r2=42272

...which is referred to as part of a fix for this bug:

http://sourceforge.net/tracker/?func=detail&aid=1409455&group_id=5470&atid=105470

Now, is this change to Generator.py in error or am I doing something wrong?

If the latter, how can I change my code such that it works as I'd expect?

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Flash Python

2006-09-10 Thread SamFeltus
Comical new updated link

http://sonomasunshine.com/sonomasunshine/index_sunshine.php?pagename=ufo_and_more

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


Re: Simple regex with whitespaces

2006-09-10 Thread John Machin
[EMAIL PROTECTED] wrote:
> Hello,
>
>   I cannot figure out a way to find a regular expression that would
> match one and only one of these two strings:
>
> s1 = '  how are you'
> s2 = 'hello world   how are you'
>
>   All I could come up with was:
> patt = re.compile('^[ ]*([A-Za-z]+)[  ]+([A-Za-z]+)$')
>
>   Which of course does not work. I cannot express the fact: sentence
> have 0 or 1 whitespace, separation of group have two or more
> whitespaces.
>
> Any suggestion ? Thanks a bunch !
> Mathieu

1. A "word" is one or more non-whitespace charaters -- subpattern is
\S+
2. A "sentence" is one or more words separated by a single white space
IOW a word followed by zero or more occurrences of  whitespace+word --
so a sentence will be matched by \S+(\s\S+)*
3. Leading and trailing runs of whitespace should be ignored -- use \s*
4. You will need to detect the case of 0 sentences (all whitespace)
separately -- I trust you don't need to be told how to do that :-)
5. Don't try to match two or more sentences; match one sentence, and
anything that fails must 0 or 2+ sentences.

So :

|>>> s1 = '  how are you'
|>>> s2 = 'hello world   how are you'
|>>> pat = r"^\s*\S+(\s\S+)*\s*$"
|>>> import re
|>>> re.match(pat, s1)
|<_sre.SRE_Match object at 0x00AED9E0>
|>>> re.match(pat, s2)
|>>> re.match(pat, '  ')
|>>> re.match(pat, ' a b')
|>>> re.match(pat, ' a b')
|<_sre.SRE_Match object at 0x00AED8E0>
|>>> re.match(pat, ' ab')
|<_sre.SRE_Match object at 0x00AED920>
|>>> re.match(pat, ' a')
|<_sre.SRE_Match object at 0x00AED9E0>
|>>> re.match(pat, 'a')
|<_sre.SRE_Match object at 0x00AED8E0>
|>>>

HTH,
John

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


Re: CPython keeps on getting faster

2006-09-10 Thread George Sakkis
John Machin wrote:

> Here are some data points that illustrate the improvement in speed
> since 2.1 for one (probably atypical) application: rummaging through a
> 120MB Microsoft Excel spreadsheet file using the xlrd package.
>
> The time shown is the number of seconds required to open the file and
> parse out all data content -- heavy usage of struct.unpack(). The only
> code that is conditional on the Python version is where it defines
> things to stop 2.1 barfing, like a dummy class called "object" .
>
> 2.1.3: 117
> 2.2.3:  95
> 2.3.5:  75
> 2.4.3:  62
> 2.5c1:  49
>
> Other info:
> xlrd version: 0.6.0a2 -- coming soon to a cheese shop near you :-)
> OS: Windows XP SP2
> CPU:
> PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel
> HumanSpeak: Intel dual-core Pentium (R) 4, nominal speed is
> 3.20Ghz
> Memory: 1 Gb (enough to avoid swapping)
>
> Well done, core devs!
>
> FWIW, IronPython 1.0.60816 does it in 132 seconds. For avoidance of
> doubt (and flak!) I'd like to clarify that IMHO the mere existence of
> IronPython merits plaudits. I do however trust that it will similarly
> become faster over time. And nobody mentioned the possibility of an
> 188% increase in memory usage, which may well be partially explained by
> this:
>
> DOS prompt>\ironpython\ipy
> IronPython 1.0.60816 on .NET 2.0.50727.42
> Copyright (c) Microsoft Corporation. All rights reserved.
> >>> str is unicode
> True

This might also explain in part the relative slowness you noticed.
OTOH, IronPython on Mono is around 20% faster than cPython 2.4 and
2.5c1 running pystone on my laptop (~50K pystones/sec for IronPython,
~41K  pystones/sec for cPython; not significant difference between 2.4
and 2.5c1). Just adding a datapoint from a completely different
environment:

CPU: Pentium-M 730 (1.6GHz)
Memory: 512 MB
OS: Ubuntu Dapper (6.06 LTS Dapper Drake)
Python2.4: 2.4.3 (#2, Apr 27 2006, 14:43:58) [GCC 4.0.3 (Ubuntu
4.0.3-1ubuntu5)]
Python2.5: 2.5c1 (r25c1:51305, Aug 18 2006, 19:18:03) [GCC 4.0.3
(Ubuntu 4.0.3-1ubuntu5)]
IronPython: 1.0.2444 on .NET 2.0.50727.42
Mono JIT compiler version 1.1.17
TLS:   normal
GC:Included Boehm (with typed GC)
SIGSEGV:   normal
Disabled:  none

George

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


Re: Simple regex with whitespaces

2006-09-10 Thread James Stroud
[EMAIL PROTECTED] wrote:
> Hello,
> 
>   I cannot figure out a way to find a regular expression that would
> match one and only one of these two strings:
> 
> s1 = '  how are you'
> s2 = 'hello world   how are you'
> 
>   All I could come up with was:
> patt = re.compile('^[ ]*([A-Za-z]+)[  ]+([A-Za-z]+)$')
> 
>   Which of course does not work. I cannot express the fact: sentence
> have 0 or 1 whitespace, separation of group have two or more
> whitespaces.
> 
> Any suggestion ? Thanks a bunch !
> Mathieu
> 


py> import re
py> s1 = '  how are you'
py> s2 = 'hello world   how are you'
py> s3 = 'group herenow here but not here   but now here'
py> patt_2plus = re.compile(r'(?:(?:\S+(?:\s|$))+(?:\s+|$)){2,}')
py> patt_3plus = re.compile(r'(?:(?:\S+(?:\s|$))+(?:\s+|$)){3,}')

positive tests:

py> patt_2plus.search(s2).group(0)
'hello world   how are you'
py> patt_2plus.search(s3).group(0)
'group herenow here but not here   but now here'
py> patt_3plus.search(s3).group(0)
'group herenow here but not here   but now here'



negative tests:

py> patt_3plus.search(s2).group(0)
Traceback (most recent call last):
   File "", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'group'
py> patt_3plus.search(s1).group(0)
Traceback (most recent call last):
   File "", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'group'
py> patt_2plus.search(s1).group(0)
Traceback (most recent call last):
   File "", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'group' 



James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


PyPy with a smaller PVM for the full Python?

2006-09-10 Thread Casey Hawthorne
Currently PyPy is working toward compiling to C a restricted subset of
Python, called RPython.

Would it be possible for PyPy to "compile" the full subset of Python
by also using a lot smaller version of the PVM (Python Virtual
Machine) to go with the "compiled" code?
So, the user would be running the C object code and also a smaller
PVM!

Or would this completely remove or severely reduce any speed advantage
of the compiled code?


Similarly, for JPython (which is at Python 2.2?), could one also use a
lot smaller accompanying PVM with the JPython source code and JVM to
use Python 2.5 in its entirety?

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


win32service (wxpython) -- i cannot install service

2006-09-10 Thread kkt49
# vim: et sw=4 ts=8 sts

from wxPython.wx import *
import sys, os, time
import pywintypes
import win32serviceutil
import win32service
import win32event
import win32process

ID_ABOUT = 101
ID_EXIT = 102

# the max seconds we're allowed to spend backing off
BACKOFF_MAX = 300
# if the process runs successfully for more than BACKOFF_CLEAR_TIME
# seconds, we reset the backoff stats to their initial values
BACKOFF_CLEAR_TIME = 30
# the initial backoff interval (the amount of time we wait to restart
# a dead process)
BACKOFF_INITIAL_INTERVAL = 5

class Service(win32serviceutil.ServiceFramework):
""" A class representing a Windows NT service that can manage an
instance-home-based Zope/ZEO/ZRS processes """

# The comment below is mostly irrelevant if you're running a
standalone
# SchoolBell server, I think. -TEH

# The PythonService model requires that an actual on-disk class
declaration
# represent a single service.  Thus, the below definition of
start_cmd,
# must be overridden in a subclass in a file within the instance
home for
# each instance.  The below-defined start_cmd (and
_svc_display_name_
# and _svc_name_) are just examples.

# To use this script with SchoolTool, just replace "SchoolBell"
# with "SchoolTool" in the variables below.
# You'll also need to change 'Python24' to 'Python23' if that's
# what you've got.  -TEH

#cmd_str = os.environ["moin_service"]

#_svc_name_ = r'moin_service'
#_svc_display_name_ = r'moin_service'
#start_cmd = r"c:\mmde\moin.exe"
info = ['', '', '']

def __init__(self):
self._svc_name = info[0]
self._svc_display_name_ = info[1]
self.start_cmd = info[2]

win32serviceutil.ServiceFramework.__init__(self)

# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.redirectOutput()

def __init__(self, args):
self._svc_name = info[0]
self._svc_display_name_ = info[1]
self.start_cmd = info[2]

win32serviceutil.ServiceFramework.__init__(self, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.redirectOutput()

def redirectOutput(self):
#pass
sys.stdout.close()
sys.stderr.close()
sys.stdout = NullOutput()
sys.stderr = NullOutput()

def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop
process.
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

# TODO:  This TerminateProcess call doesn't make much sense:
it's
# doing a hard kill _first_, never giving the process a chance
to
# shut down cleanly.  Compare to current Zope2 service code,
which
# uses Windows events to give the process a chance to shut down
# cleanly, doing a hard kill only if that doesn't succeed.

# stop the process if necessary
try:
win32process.TerminateProcess(self.hZope, 0)
except pywintypes.error:
# the process may already have been terminated
pass
# And set my event.
win32event.SetEvent(self.hWaitStop)

# SvcStop only gets triggered when the user explictly stops (or
restarts)
# the service.  To shut the service down cleanly when Windows is
shutting
# down, we also need to hook SvcShutdown.
SvcShutdown = SvcStop

def createProcess(self, cmd):
return win32process.CreateProcess(
None, cmd, None, None, 0, 0, None, None,
win32process.STARTUPINFO())

def SvcDoRun(self):
# indicate to Zope that the process is daemon managed
(restartable)
# os.environ['ZMANAGED'] = '1'

# daemon behavior:  we want to to restart the process if it
# dies, but if it dies too many times, we need to give up.

# we use a simple backoff algorithm to determine whether
# we should try to restart a dead process:  for each
# time the process dies unexpectedly, we wait some number of
# seconds to restart it, as determined by the backoff interval,
# which doubles each time the process dies.  if we exceed
# BACKOFF_MAX seconds in cumulative backoff time, we give up.
# at any time if we successfully run the process for more thab
# BACKOFF_CLEAR_TIME seconds, the backoff stats are reset.

# the initial number of seconds between process start attempts
backoff_interval = BACKOFF_INITIAL_INTERVAL
# the cumulative backoff seconds counter
backoff_cumulative = 0

import servicemanager

# log a service started message
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SER

Re: Simple regex with whitespaces

2006-09-10 Thread Mark Peters
>   Which of course does not work. I cannot express the fact: sentence
> have 0 or 1 whitespace, separation of group have two or more
> whitespaces.
>
> Any suggestion ? Thanks a bunch !
How about this:

>>> import re
>>> s = 'hello world   how are you'
>>> re.split(r"\s{2,}",s)
['', 'hello world', 'how are you']

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


Re: Looking for the Perfect Editor

2006-09-10 Thread Dick Moores
At 06:30 PM 9/10/2006, Kent Johnson wrote:
>Dick Moores wrote:
>
> > I downloaded Python (7) from
> > http://www.textpad.com/add-ons/synn2t.html and put the file
> > PythonV2.4.syn in C:\Program Files\TextPad 4\system .
> >
> > However, no syntax highlighting is showing up. so I must have done
> > something wrong. Do I have to do something other than put
> > PythonV2.4.syn in C:\Program Files\TextPad 4\system ?
>
>One more step - make a new Document Class for Python (in the prefs).
>Associate it with *.py, turn on syntax highlighting and select the
>syntax file you downloaded.

OK. Done.

> > Also, why do you use TextPad instead of IDLE?
>
>You're kidding, right?

No. Tell me, please. Macros? Comparing files? What else?

Dick



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


Re: Python on handhelds

2006-09-10 Thread Paul Rubin
"Nick" <[EMAIL PROTECTED]> writes:
> I have never programmed in Python a day in my life. My group is working
> on developing an application on the Dell Axim hand held that has a
> tight deadline. I have heard that Python is particularly advantageous
> in rapid prototyping and deployment. I would like to lean this way if I
> can. Does anyone know if I can run Python on the Dell Axim handheld. It
> runs Windows CE. If so, what all is needed to make this possible.

Someone did a WinCE port a while back, but I don't think it's actively
used much.  The approach might be reasonable if you're an expert with
some time on your hands, but for a newcomer with an onrushing
deadline, you may be better off using whatever you're already using
(VB or whatever), and keeping Python in mind for some future project.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python on handhelds

2006-09-10 Thread Nick

Hi all,

I have never programmed in Python a day in my life. My group is working
on developing an application on the Dell Axim hand held that has a
tight deadline. I have heard that Python is particularly advantageous
in rapid prototyping and deployment. I would like to lean this way if I
can. Does anyone know if I can run Python on the Dell Axim handheld. It
runs Windows CE. If so, what all is needed to make this possible.
Thanks


Nick../

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


Simple regex with whitespaces

2006-09-10 Thread mathieu . malaterre
Hello,

  I cannot figure out a way to find a regular expression that would
match one and only one of these two strings:

s1 = '  how are you'
s2 = 'hello world   how are you'

  All I could come up with was:
patt = re.compile('^[ ]*([A-Za-z]+)[  ]+([A-Za-z]+)$')

  Which of course does not work. I cannot express the fact: sentence
have 0 or 1 whitespace, separation of group have two or more
whitespaces.

Any suggestion ? Thanks a bunch !
Mathieu

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


CPython keeps on getting faster

2006-09-10 Thread John Machin
Here are some data points that illustrate the improvement in speed
since 2.1 for one (probably atypical) application: rummaging through a
120MB Microsoft Excel spreadsheet file using the xlrd package.

The time shown is the number of seconds required to open the file and
parse out all data content -- heavy usage of struct.unpack(). The only
code that is conditional on the Python version is where it defines
things to stop 2.1 barfing, like a dummy class called "object" .

2.1.3: 117
2.2.3:  95
2.3.5:  75
2.4.3:  62
2.5c1:  49

Other info:
xlrd version: 0.6.0a2 -- coming soon to a cheese shop near you :-)
OS: Windows XP SP2
CPU:
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel
HumanSpeak: Intel dual-core Pentium (R) 4, nominal speed is
3.20Ghz
Memory: 1 Gb (enough to avoid swapping)

Well done, core devs!

FWIW, IronPython 1.0.60816 does it in 132 seconds. For avoidance of
doubt (and flak!) I'd like to clarify that IMHO the mere existence of
IronPython merits plaudits. I do however trust that it will similarly
become faster over time. And nobody mentioned the possibility of an
188% increase in memory usage, which may well be partially explained by
this:

DOS prompt>\ironpython\ipy
IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> str is unicode
True

Cheers,
John

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


Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
George Sakkis wrote:
> I prefer the the simple global statements if they aren't
> that many, otherwise the assignment of the module to self is also fine.

I replied to this article, and then canceled the reply (but that never
works), thinking you were criticizing the general concept of "module as
a singleton" and not just my approach.  I should learn to read.  I
apologize for the misunderstanding.

I do agree my implementation is a little hacky, although IMHO it feels
to fit in with the way classes work better, which appeals to me but
probably not most people :).  For one thing, the methods have the
explicit self argument, like regular classes.  For another, it uses a
decorator to affect the binding of the modules.  In regular classes,
functions are instance methods by default, and become class methods or
static methods with a decorator.  I like to think of modules as having
a special metaclass that treats functions as static methods by default,
and uses a decorator to get an instance method.  (Even though that
isn't remotely how it works, it fits how it would work if you were
implementing modules based on classes.)

Having said that, I've no problem with Kamilche's approach.  The real
evil in my mind is using lots of global statements, and anything you
can do to stay away from that is a good thing.


Carl Banks

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


Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks

George Sakkis wrote:
> Carl Banks wrote:
> > I don't see any major problem with it.  In fact, I think it's a very
> > good idea to do this, rather than use global statements, when using
> > module as a singleton class.
> >
> > I recently made the same transition myself, though I solved it a bit
> > differently.  I used a decorator to pass the module as the first
> > argument (actually it passes a proxy to module's global dict, since the
> > module itself isn't accesible from the function object).
> >
> > def modmethod(func):
> > class modproxy(object):
> > __getattribute__ = func.func_globals.__getitem__
> > __setattr__ = func.func_globals.__setitem__
> > self = modproxy()
> > def call_with_module(*args,**kwargs):
> > return func(self,*args,**kwargs)
> > call_with_module.func_name = func.func_name
> > return call_with_module
> >
> > @modmethod
> > def MyRoutine(self):
> > self.var = 1
> >
> > MyRoutine()
> > print var
>
> This looks quite hackish, both the implementation and the usage;

Once again, the function MyRoutine is intended to be called from
another module.  The usage I have here is just an example demonstrating
that var is in the module's dict.  Please keep this in mind when
criticizing usage.  The intended usage would be something like this
(from another module):

from xxx import yyy
yyy.MyRoutine()

As far as the caller is concerned, yyy could be a module using globals,
a module with this "hack", or a class instance, or something else.  It
doesn't matter; usage is the same in all three cases.

As for the implementation...

> most
> people would get confused when they didn't find var's assignment at
> global scope. I prefer the the simple global statements if they aren't
> that many, otherwise the assignment of the module to self is also fine.

For ordinary modules that might have one or two serial number counters
or debug flags or whatnot, I agree.  For modules that have lots of
state and act more like class instances than modules, the massive
amounts of globals are ugly and error prone.  In that case you should
either use a regular class, or tolerate the "hack"; don't use a bunch
of globals.

I think a simple comment at the top could take care of any confusion
about what's happening.  Since it mimics how a class works, it won't be
anything completely new.

YMMV.

Carl Banks

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


Re: Looking for the Perfect Editor

2006-09-10 Thread Steve Holden
Dick Moores wrote:
> At 01:10 PM 9/8/2006, Doug Stell wrote:
> 
>>Try www.TextPad.com. I've used it for years and love it. It
>>understands many programming language constructs and can be taught to
>>understand python so that things show up in color.
> 
> 
> Any tips on how to teach TextPad to understand python?
> 
The procedure is explained in "How do I create a new document class to 
do syntax highlighting?" on page

   http://www.textpad.com/support/faq/config.html

You can download an appropriate .syn file from

   http://www.textpad.com/add-ons/synn2t.html

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Two ethernet cards/networks (still)

2006-09-10 Thread Steve Holden
Bob Greschke wrote:
> "Steve Holden" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>Bob Greschke wrote:
>>The reason that "binding to a specific address is almost never used for a 
>>client" is because it's the server destination address that the network 
>>layer will use to determine which interface is used to communicate with a 
>>specific server host.
>>
>>Suppose your network setup looks like this:
>>
>>
>>+---++ Network A
>>|
>>|
>>|
>>| 192.168.12.34/24
>>|
>>   +++
>>   | |
>>   | |
>>   | YOUR HOST   |
>>   | |
>>   | |
>>   +++
>>|
>>| 201.46.34.22/24
>>|
>>|
>>|
>>+---+--+-+ Network B
>>   |
>>   +
>>  +++
>>  |  router |
>>  |   to internet   |
>>  +-+
>>
>>If your client program tries to communicate with, say, 192.168.12.18 then 
>>by the IP network layer will automatically select network A as the medium, 
>>since the destination is local to that network. If you then want to 
>>communicate the results to 201.46.34.118 then network B will be used, 
>>again because the destination is local to that network (its first 24 bits 
>>are the same as the first 24 bits of the destination).
>>
>>In this case the router on network B will almost certainly be the default 
>>route for the host, as it's the way to everywhere else.
>>
>>This isn't really Python-related, so I hope it answers your question!
>>
>>regards
>> Steve
>>-- 
>>Steve Holden   +44 150 684 7255  +1 800 494 3119
>>Holden Web LLC/Ltd  http://www.holdenweb.com
>>Skype: holdenweb   http://holdenweb.blogspot.com
>>Recent Ramblings http://del.icio.us/steve.holden
>>
> 
> 
> Nice explanation!  Thanks!  You mean I don't have to do anything special?? 
> That sounds suspiciously easy. :)
> 
> To muddy the water a little the equipment I want to get info from (some 
> seismic digitizing/recording equipment) comes back to us from the field with 
> the IP addresses set to whatever that last user needed.  What we do now is 
> put the unit(s) on the bench, connect them to the private network and use a 
> broadcast address (like 255.255.255.255) and a specific port number to query 
> and see who is connected.  Then we (a program) can get in (login, basically) 
> and reset the all of the IPs to the same subnet to proceed with checkout, 
> calibration, etc.  We have to disconnect from (or disable the card for) the 
> outside network when we do this discovery or else the program discovers all 
> of these instruments that we have running in the building (monitoring a 
> seismic pier, in people's offices, etc.).  I'm guessing here we will still 
> need to do this?  It's not a biggie, but finding a way to not have to do 
> this was what started this whole thing.  Once the program knows which 
> instruments it found on the private network it doesn't matter.  It will only 
> work on those ones.
> 

Ah, so you want to do a limited broadcast over a single interface (the 
one for the private network) to avoid having to disable the other 
interface? That's a different kettle of fish.

I suspect you could do it by binding the local socket to a single 
address, but I'd need to play around to get it right. Maybe someone else 
has already done this?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Looking for the Perfect Editor

2006-09-10 Thread Kent Johnson
Dick Moores wrote:

> I downloaded Python (7) from 
> http://www.textpad.com/add-ons/synn2t.html and put the file 
> PythonV2.4.syn in C:\Program Files\TextPad 4\system .
> 
> However, no syntax highlighting is showing up. so I must have done 
> something wrong. Do I have to do something other than put 
> PythonV2.4.syn in C:\Program Files\TextPad 4\system ?

One more step - make a new Document Class for Python (in the prefs). 
Associate it with *.py, turn on syntax highlighting and select the 
syntax file you downloaded.

> 
> Also, why do you use TextPad instead of IDLE?

You're kidding, right?

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


Re: Refactoring Dilemma

2006-09-10 Thread George Sakkis
Carl Banks wrote:
> Kamilche wrote:
> > '''
> > I'm in the middle of a refactoring dilemma.
> > I have several singletons that I'm turning into modules, for ease of
> > access.
> > The usual method is noted as 'Module 1' below.
> > The new method is noted as 'Module 2'.
> > Is there any reason NOT to do this that I may be unaware of?
> > It's easier than remembering to declare global variables at the top of
> > the function.
> > '''
> >
> > # --- Module 1.py 
> > # Normal module processing
> > var = 0
> >
> > def MyRoutine():
> > global var
> > var = 1
> >
> > MyRoutine()
> > print var
> >
> >
> > # --- Module 2.py 
> > # 'Self' module processing
> > import sys
> > var = 0
> > self = sys.modules[__name__]
> >
> > def MyRoutine():
> > self.var = 1
> >
> > MyRoutine()
> > print var
>
> I don't see any major problem with it.  In fact, I think it's a very
> good idea to do this, rather than use global statements, when using
> module as a singleton class.
>
> I recently made the same transition myself, though I solved it a bit
> differently.  I used a decorator to pass the module as the first
> argument (actually it passes a proxy to module's global dict, since the
> module itself isn't accesible from the function object).
>
> def modmethod(func):
> class modproxy(object):
> __getattribute__ = func.func_globals.__getitem__
> __setattr__ = func.func_globals.__setitem__
> self = modproxy()
> def call_with_module(*args,**kwargs):
> return func(self,*args,**kwargs)
> call_with_module.func_name = func.func_name
> return call_with_module
>
> @modmethod
> def MyRoutine(self):
> self.var = 1
>
> MyRoutine()
> print var

This looks quite hackish, both the implementation and the usage; most
people would get confused when they didn't find var's assignment at
global scope. I prefer the the simple global statements if they aren't
that many, otherwise the assignment of the module to self is also fine.

George

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


Bloomberg

2006-09-10 Thread domer
Hi everyone,

I was wondering if somebody knows how to extract intraday
fields(price,volume,trades) from Bloomberg in order to calculate the
VWAP. 

Appreciate any help

Kind regards,

Domer

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


Re: Javadoc style python manual?

2006-09-10 Thread xiong . xu . cn
Thanks for all replies regard with this question!
I think I will get used to python help system:)
Maybe I will look into epydoc, too...

-Xiong

Michele Simionato 写道:

> Ben Sizer wrote:
> > Michele Simionato wrote:
> > > Ben Sizer wrote:
> > > > I agree that the Python docs aren't quite as effective as reference
> > > > material due to the lack of simple function and method lists though.
> > >
> > > http://docs.python.org/lib/modindex.html, pydoc and ipython are more
> > > than enough for me.
> >
> > modindex is comprehensive but too 'flat'. Sometimes you want to see all
> > of one object's methods and properties listed together.
> >
> > I was unaware of pydoc until this thread; its existence seems to be
> > buried, somewhat. Looking at pydoc.org (assuming that is a good example
> > of it in use), it looks more like what the original poster and I might
> > want, but sadly it's still very inconsistent, with many things
> > undescribed.
> >
> > --
> > Ben Sizer
>
> Don't miss IPython, too.
>
> $ ipython
> Python 2.4.1 (#2, Aug 25 2005, 18:20:57)
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.6.15 -- An enhanced Interactive Python.
> ?   -> Introduction to IPython's features.
> %magic  -> Information about IPython's 'magic' % functions.
> help-> Python's own help system.
> object? -> Details about 'object'. ?object also works, ?? prints more.
>
> In [1]: import email.FeedParser
>
> In [2]: email.FeedParser.FeedParser?
> Type:   classobj
> String Form:email.FeedParser.FeedParser
> Namespace:  Interactive
> File:   /usr/lib/python2.4/email/FeedParser.py
> Docstring:
> A feed-style parser of email.
>
> Constructor information:
> Definition: email.FeedParser.FeedParser(self, _factory= email.Message.Message at 0xb77f5ddc>)
> Docstring:
> _factory is called with no arguments to create a new message obj
>
>
> In [3]: help(email.FeedParser.FeedParser)
> Help on class FeedParser in module email.FeedParser:
>
> class FeedParser
>  |  A feed-style parser of email.
>  |
>  |  Methods defined here:
>  |
>  |  __init__(self, _factory=)
>  |  _factory is called with no arguments to create a new message
> obj
>  |
>  |  close(self)
>  |  Parse all remaining data and return the root message object.
>  |
>  |  feed(self, data)
>  |  Push more data into the parser.
>
>
> In [4]: email.FeedParser.FeedParser??
> Type:   classobj
> String Form:email.FeedParser.FeedParser
> Namespace:  Interactive
> File:   /usr/lib/python2.4/email/FeedParser.py
> Source:
> class FeedParser:
> """A feed-style parser of email."""
>
> def __init__(self, _factory=Message.Message):
> """_factory is called with no arguments to create a new message
> obj"""
> self._factory = _factory
> self._input = BufferedSubFile()
> self._msgstack = []
> self._parse = self._parsegen().next
> self._cur = None
>  ...
>
> Unfortunately, the nice colors of IPython are lost in the post :-(
> 
>   Michele Simionato

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

Re: ANN: Pocoo (bulletin board software) 0.1 beta released

2006-09-10 Thread [EMAIL PROTECTED]

Georg Brandl wrote:
> We're pleased to announce that
>
>   Pocoo 0.1 (beta) was released today (Sept. 10, 2006).
>
> Pocoo  is a bulletin board software (aka. message 
> board)
> written in Python, adhering to the WSGI standard. In the long term, it is 
> meant
> to compete with systems like phpBB.
>

Python needs good forums :) I'm writing my own forum app also, called
"MyghtyBoard" - http://code.google.com/p/diamanda/ using Django :)
[check the screenshots].

python isn't PHP -> most python powered sites use a framework (from
zope to web.py) so it would nice if the script could be easily "plugged
in" to popular python frameworks (users, permissions, forum data) :)

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


Re: Is it just me, or is Sqlite3 goofy?

2006-09-10 Thread [EMAIL PROTECTED]

Dennis Lee Bieber wrote:
> Guess I lied...
>
> On Sat, 09 Sep 2006 05:22:20 GMT, Dennis Lee Bieber
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>   Talking to myself again, I see...
>
> 
> rs = cr.execute("""insert into invoice_1
> (CustNo, Title, Author, Year, Price)
> values (?,?,?,?,?)""",
> r)
>
> Whoops, r => rv, though the exceptions raised made it moot
>
> rs = cr.execute("""insert into invoice_2
> (CustNo, Title, Author, Year, Price)
> values (?,?,?,?,?)""",
> r)
>
> Same comment
>
>   Out of curiousity, I converted to using MySQL(db) as a test. As
> expected, the pre-insert validation code worked with same results (well,
> the price was declared decimal, and Python 2.4 appears to handle that as
> a Decimal("value") on return )
>
>   Now, taking out the pre-validation and type conversion, supplying
> all data as it came from the CSV file:
>
> -=-=-=-=-=-=-
> Inserting:
> ['066', '101 Ways to Start A Fight', 'some Irish gentleman', '1919',
> '19.95']
> ['032', 'A Sale of Two Titties', 'Charles Dikkens', '1855', '20.00']
> ['001', 'Olsens Standard Book of British Birds (Expurgated)"', 'Olsen',
> 'None', '99.95']
> ['066', 'Ethel the Aardvark Goes Quantity Surveying', 'None', '1975',
> '9.99']
> ['032', 'David Coperfield', 'Edmund Wells', '1955', '3.95']
> ['>68', 'Strawmen and Dorothy', '', '2006', '49.89']
> ['033', "The Emperor's Old Clothes", 'Grimm Hound', '1887', 'Priceless']
>
> Select all from Invoice_1 (CustNo is CHARACTER)
> (1L, '066', '101 Ways to Start A Fight', 'some Irish gentleman', 1919L,
> Decimal("19.95"))
> (2L, '032', 'A Sale of Two Titties', 'Charles Dikkens', 1855L,
> Decimal("20.00"))
> (3L, '001', 'Olsens Standard Book of British Birds (Expurgated)"',
> 'Olsen', 0L, Decimal("99.95"))
> (4L, '066', 'Ethel the Aardvark Goes Quantity Surveying', 'None', 1975L,
> Decimal("9.99"))
> (5L, '032', 'David Coperfield', 'Edmund Wells', 1955L, Decimal("3.95"))
> (6L, '>68', 'Strawmen and Dorothy', '', 2006L, Decimal("49.89"))
> (7L, '033', "The Emperor's Old Clothes", 'Grimm Hound', 1887L,
> Decimal("0.00"))
>
> Select all from Invoice_2 (CustNo is INTEGER)
> (1L, 66L, '101 Ways to Start A Fight', 'some Irish gentleman', 1919L,
> Decimal("19.95"))
> (2L, 32L, 'A Sale of Two Titties', 'Charles Dikkens', 1855L,
> Decimal("20.00"))
> (3L, 1L, 'Olsens Standard Book of British Birds (Expurgated)"', 'Olsen',
> 0L, Decimal("99.95"))
> (4L, 66L, 'Ethel the Aardvark Goes Quantity Surveying', 'None', 1975L,
> Decimal("9.99"))
> (5L, 32L, 'David Coperfield', 'Edmund Wells', 1955L, Decimal("3.95"))
> (6L, 0L, 'Strawmen and Dorothy', '', 2006L, Decimal("49.89"))
> (7L, 33L, "The Emperor's Old Clothes", 'Grimm Hound', 1887L,
> Decimal("0.00"))
> -=-=-=-=-=-=-
>
>   How interesting... With MySQL/MySQLdb I did NOT get exceptions or
> error results on inserting bad numeric data supplied as character string
> format (ie, as read from the CSV). Instead, MySQL SILENTLY converted
> them to ZEROS
>
>   A price of "Priceless" becomes Decimal("0.00").
>
>   The Customer number of ">68" became 0L
>
>
>   Which would one rather have to work with -- a database that copied
> invalid numerics as string literals (which, in my mind, makes it much
> easier to correct the data later, using "update  set field = correct
> where field = invalid") or a database that silently converts them all to
> 0 values. (Of course, I now expect to have a rejoinder about "Using a
> REAL database instead of MySQL" -- but unless said person wishes to
> start making the same comments about SQLite on at least as regular a
> basis, I believe the objection itself is invalid for this example).
>
> (Apparently we have fallen afoul of this clause from the old
> O'Reilly/MySQL black/brown book: "When asked to store a value in a
> numeric column that is outside the column type's allowable range, MySQL
> clips the value to the appropriate endpoint of the range and stores the
> resulting value instead." -- seems character data "clips" to zero.
>

Are you saying that MySQL is goofy? ;-)

Based on these replies, I'm pulling back and retrenching.

As I said before, I'm not entering 500,000 records by writing
INSERT statements for each record, so reading csv files is
a more realistic test. Nevertheless, I am still convinced that
the documentation (or lack thereof) is mainly responsible for
my confusion. I was, after all, mimicing the examples given
(which still have errors).

I think an explanation of how Sqlite3 differs from SQL and
a better set of examples is still warranted.

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


Re: Looking for the Perfect Editor

2006-09-10 Thread Dick Moores
At 02:15 PM 9/10/2006, Kent Johnson wrote:
>Dick Moores wrote:
> > At 01:10 PM 9/8/2006, Doug Stell wrote:
> >> Try www.TextPad.com. I've used it for years and love it. It
> >> understands many programming language constructs and can be taught to
> >> understand python so that things show up in color.
> >
> > Any tips on how to teach TextPad to understand python?
>Download and install the Python syntax highlighting definition from the
>TextPad website.

Thanks very much, Kent. I've been using TextPad for 10 years and 
never considered using it for Python.

I downloaded Python (7) from 
http://www.textpad.com/add-ons/synn2t.html and put the file 
PythonV2.4.syn in C:\Program Files\TextPad 4\system .

>I make a tool to run the front window in Python. Here are the values
>from the preferences window for the tool:
>
>Command: C:\Python24\python.exe
>Parameters: -u $File
>Init fldr: $FileDir
>
>regex to match output:
>^.*"([^"]+)", *line ([0-9]+)
>
>with File: 1, Line: 2

After fumbling around, I believe I've made the tool, using your 
values, except I used E:\Python24\python.exe instead of 
C:\Python24\python.exe .

I also associated .py with TextPad. I'm now able to open a Python 
script with TextPad, and execute it with  Ctrl+4.

However, no syntax highlighting is showing up. so I must have done 
something wrong. Do I have to do something other than put 
PythonV2.4.syn in C:\Program Files\TextPad 4\system ?

Also, why do you use TextPad instead of IDLE?

Thanks,

Dick Moores


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


Re: ANN: Pocoo (bulletin board software) 0.1 beta released

2006-09-10 Thread Felipe Almeida Lessa
10 Sep 2006 16:17:08 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid>:
> So, I think it's not worth thinking about writing yet another BBS
> unless it can handle a Slashdot-sized load on a commodity PC.

Python is slow. Psyco helps, but you should use C instead.

And yes, I am kidding =)

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


Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
George Sakkis wrote:
> Kamilche wrote:
> > '''
> > I'm in the middle of a refactoring dilemma.
> > I have several singletons that I'm turning into modules, for ease of
> > access.
> > The usual method is noted as 'Module 1' below.
> > The new method is noted as 'Module 2'.
> > Is there any reason NOT to do this that I may be unaware of?
> > It's easier than remembering to declare global variables at the top of
> > the function.
> > '''
> >
> > # --- Module 1.py 
> > # Normal module processing
> > var = 0
> >
> > def MyRoutine():
> > global var
> > var = 1
> >
> > MyRoutine()
> > print var
> >
> >
> > # --- Module 2.py 
> > # 'Self' module processing
> > import sys
> > var = 0
> > self = sys.modules[__name__]
> >
> > def MyRoutine():
> > self.var = 1
> >
> > MyRoutine()
> > print var
>
>
> What's wrong with
> 
> def MyRoutine():
>  return 1
>
> var = MyRoutine()
> 
> ?


Kamilche simplified things in his example that obscured the main use
case.  Short story is, var is considered a state of the module, and
MyRoutine() is designed to be called from outside the module to modify
the state.  Your suggestion can only modify the state of the module
from within, so it won't do.

More detailed discussion:

A common piece of advice when people ask "how can I implement a
singleton in Python" is to use a module.  A module, after all, is a
singleton object.

But there's a big problem using a module as a singleton: you need to
use then global statement to rebind module-level variables.  Which
means that if you want your module to have lots of modifyable state,
most likely you'll have to use a bunch global statements.  And that's a
major pain in the neck when you have to do it a lot and in many
functions.

In these cases, it would be nice if a module could access its own state
in the same way that an instance does, that is, as an attribute.  My
approach of using a decorator to pass in a module proxy, and Kamilche's
approach  of binding the module object to self, both accomplish this.
Internally, the module behaves very much like a class instance.
Functions in the module act almost exactly like bound methods, and
module-level variables act like instance attributes.  The difference
between writing a module and a singleton class thus becomes mostly a
matter of indentation.

In fact, when I made a major switch from using singleton classes to
modules, I was able to change it by dedenting once, and pasting a
@modmethod decoration above each method, with very few other changes.

Carl Banks

Carl Banks

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


Re: ANN: Pocoo (bulletin board software) 0.1 beta released

2006-09-10 Thread Paul Rubin
Georg Brandl <[EMAIL PROTECTED]> writes:
> Pocoo  is a bulletin board software
> (aka. message board) written in Python, adhering to the WSGI
> standard. In the long term, it is meant to compete with systems like
> phpBB.

You too, huh?  I've also always wanted to write one of those.  Mine
would be performance-intensive.  I've never understood why the phpBB,
vBulletin, etc. systems that I use bog down so much.  It's a very
serious problem--the bigger boards I hang out on all have to use
multiple servers, resulting in big hosting bills ($1000's per month),
so they have to take advertising, hold fundraisers all the time, etc.
But the raw hardware really needed if the software were any good,
including adequate bandwidth, should fit within the cheap
managed-hosting servers (typically a 1U rack-mounted single processor
Celeron box for $100 a month or so) or on a VPS for smaller loads
($50/month or less).  That means the hosting fees can be paid out of
pocket by a few donors, getting rid of all kinds of fundraising
headaches and increasing organizational and content flexibility a lot.

So, I think it's not worth thinking about writing yet another BBS
unless it can handle a Slashdot-sized load on a commodity PC.  For
very large loads it should be able to use multiprocessor hardware
effectively (an 8-core Athlon server costs as much today as an entry
level engineering workstation of the 1990's).  I've even played with
the idea of using MPI for this ("imagine a Beowulf cluster of...")
which would let you couple multiple boxes together with ordinary LAN
hardware, letting you scale straightforwardly to hundreds of cpu's.  I
think it should be possible to do all this, using a system still
written mostly in Python.

My suggestions:

1) ditch the SQL back end, or at least don't depend on it.  Someone
had the clever idea of using an NNTP back end, using a news server (or
a network of them) as a message store.  That gets you all kinds of
features for free.  Otherwise, keep all messages in an mmap'd disk
file that can be shared in memory between multiple processes.  Adding
messages would append to the file, and to some kind of log that would
reconstruct in-memory structures in the event of server restart.
You'd also need some IPC synchronization scheme.  

2) Look at the architecture of WebCrossing and also of OKWS (www.okws.org). 

3) Hmm I had some more, I'll keep thinking.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ghostscript interface

2006-09-10 Thread Andrew MacIntyre
defcon8 wrote:
> Does a ghostscript interface for python exist? I have searched google
> quite a bit and all I have been able to find are command line hacks
> from within python. Thanks in advance for any useful help.

I'm not aware of a specific interface to the Ghostscript API, but it is
trivial to implement one with ctypes (included with 2.5).

-- 
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring Dilemma

2006-09-10 Thread Carl Banks
Kamilche wrote:
> '''
> I'm in the middle of a refactoring dilemma.
> I have several singletons that I'm turning into modules, for ease of
> access.
> The usual method is noted as 'Module 1' below.
> The new method is noted as 'Module 2'.
> Is there any reason NOT to do this that I may be unaware of?
> It's easier than remembering to declare global variables at the top of
> the function.
> '''
>
> # --- Module 1.py 
> # Normal module processing
> var = 0
>
> def MyRoutine():
> global var
> var = 1
>
> MyRoutine()
> print var
>
>
> # --- Module 2.py 
> # 'Self' module processing
> import sys
> var = 0
> self = sys.modules[__name__]
>
> def MyRoutine():
> self.var = 1
>
> MyRoutine()
> print var

I don't see any major problem with it.  In fact, I think it's a very
good idea to do this, rather than use global statements, when using
module as a singleton class.

I recently made the same transition myself, though I solved it a bit
differently.  I used a decorator to pass the module as the first
argument (actually it passes a proxy to module's global dict, since the
module itself isn't accesible from the function object).

def modmethod(func):
class modproxy(object):
__getattribute__ = func.func_globals.__getitem__
__setattr__ = func.func_globals.__setitem__
self = modproxy()
def call_with_module(*args,**kwargs):
return func(self,*args,**kwargs)
call_with_module.func_name = func.func_name
return call_with_module

@modmethod
def MyRoutine(self):
self.var = 1

MyRoutine()
print var

One problem with my decorator is it makes stack traces a little
bloated. (Also attribute errors are raised as KeyError, but that's
easily fixable.)  Other than that, I've been running it for awhile
without any problems.  I doubt your approach would have many problems,
either. 


Carl Banks

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


ANN: Pocoo (bulletin board software) 0.1 beta released

2006-09-10 Thread Georg Brandl
We're pleased to announce that

  Pocoo 0.1 (beta) was released today (Sept. 10, 2006).

Pocoo  is a bulletin board software (aka. message board)
written in Python, adhering to the WSGI standard. In the long term, it is meant
to compete with systems like phpBB.

It provides an advanced plugin system with a component architecture which
allows other developers to modify Pocoo to their liking without the need to
touch existing source code. Building upon SQLAlchemy, Pocoo is able to
use either MySQL, SQLite, Oracle or Postgres as the storage backend.

The 0.1 release is not meant to be feature complete. It's more like a preview
to show off what's already there. If you like the idea, *feel free to join us!*


Features


Currently implemented:

  * Support for either flat or threaded post view
  * URLs are very readable, furthermore one URL works for both flat and
threaded view
  * Support for JSONRPC and XmlHTTPRequest to dynamically fetch data where
useful while having a fallback for non-JS users
  * Very powerful plugin system
  * Extensible authentication system
  * WSGI compliancy
  * Database support for MySQL, Sqlite, Postgres, Oracle
  * BBCode/rst/safehtml parsers for markup
  * Javascript editors for the markup
  * Avatar support
  * User profiles and settings

Planned features

... can be found in the Idea Pool at http://trac.pocoo.org/wiki/IdeaPool.


Download


Download the release at .


Cheers,
Georg Brandl, on behalf of the Pocoo Team
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode / cx_Oracle problem

2006-09-10 Thread John Machin
Richard Schulman wrote:
> On Sun, 10 Sep 2006 11:42:26 +0200, "Diez B. Roggisch"
> <[EMAIL PROTECTED]> wrote:
>
> >What does print repr(mean) give you?
>
> That is a useful suggestion.
>
> For context, I reproduce the source code:
>
> in_file = codecs.open("c:\\pythonapps\\mean.my",encoding="utf_16_LE")
> connection = cx_Oracle.connect("username", "password")
> cursor = connection.cursor()
> for row in in_file:
> id = row[0]
> mean = row[1]
> print "Value of row is ", repr(row)#debug line
> print "Value of the variable 'id' is ", repr(id)   #debug line
> print "Value of the variable 'mean' is ", repr(mean)   #debug line
> cursor.execute("""INSERT INTO mean (mean_id,mean_eng_txt)
> VALUES (:id,:mean)""",id=id,mean=mean)
>
> Here is the result from the print repr() statements:
>
> Value of row is  u"\ufeff(3,'sadness, lament; sympathize with,
> pity')\r\n"
> Value of the variable 'id' is  u'\ufeff'
> Value of the variable 'mean' is  u'('
>
> Clearly, the values loaded into the 'id' and 'mean' variables are not
> satisfactory but are picking up the BOM.

Well of course they're "unsatisfactory" and this is absolutely nothing
to do with Oracle and cx_Oracle.

row is a string of characters. row[0] is the BOM. Read my lips (from a
previous thread):

"""
Use utf_16 -- it will strip off the BOM for you.
"""
and again:
"""
| >>> codecs.open('guff.utf16le', 'r', encoding='utf_16').read()
| u'abc\n\rdef\n\rghi' # Look, Mom, no BOM!
"""

row[1] is the first ***character*** of what looks suspiciously like the
Python representation of a tuple:

"""(3,'sadness, lament; sympathize with, pity')"""

Who wrote that like that??? If it is at all under your control, do it
like this:
Encode each Unicode text field in UTF-8. Write the file as a CSV file
using Python's csv module. Read the CSV file using the same module.
Decode the text fields from UTF-8.

You need to parse the incoming line into column values (the csv module
does this for you) and then convert each column value from
string/Unicode to a Python type that is compatible with the Oracle type
for that column.

My guess (not having used cx_Oracle) is that the error is happening
because the column "id" has a numeric type and you are trying to jam a
Unicode string into it. IOW, nothing to do with the "mean" column
(yet!).

BTW, I've managed to decode that "eng" means English not engineering
and "mean" means meaning i.e. not average and not stingy. Holy
obfuscation, Batman!

HTH,
John

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


Re: get the en of a program running in background

2006-09-10 Thread oripel
Module 'subprocess' may be a better fit for you than fork+exec.
Here's an example with a signal handler
(1) use subprocess, don't fork and exec
(2) maybe this will help:

---
import signal, subprocess

# define the signal handler
def logsignal(signum, frame):
   print "Caught signal"

# register the signal handler for SIGCHLD
signal.signal(signal.SIGCHLD, logsignal)

# run the subprocess in the background
subprocess.Popen(["sleep", "3"])

# Do more stuff
---

The signal handler will be called when the child process ends. Just
register your own handler.

You only need to register the handler once.
If you need this for a single run only, or need different behavior for
different subprocesses, have your signal handler re-register the old
handler (see the docs for module 'signal').

A note about the example: if you run it as is, the parent process will
end before the child process does. Add a call to 'os.wait()' to have it
wait for the child. In your GUI you probably won't want it.

Hope this helps.

awalter1 wrote:
> Hi,
> I develop a graphical user interface (with pyGTK) where a click on a
> button shall launch a program P in background. I want to get the end of
> this program P but I don't want that my HMI be freezed while P is
> running.
> I try to use fork examplesI found on the web, but it seems to not run
> as expected.
> I am not familiar with these techniques in unix as well as python.
> But I suppose that my needs are usual, despite that I don't find
> anything on the web ...
> Is someone can give me a standard way to call a background program,
> wait its end, with an IHM still active ?
> 
> Thank a lot for any idea.

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


Re: Method resolution for super(Class, obj).

2006-09-10 Thread Bruno Desthuilliers
ddtl a écrit :
> On 7 Sep 2006 10:42:54 -0700, in comp.lang.python you wrote:
> 
> 
>>Let's examine what the mro order is for class D:
>>
>D.mro()
>>
>>[, , ,
>>>n__.A'>, ]
>>
>>When you call d.met(), the call dispatches to the D.met() method.
>>After printing out 'D.met', you use super() to get the next class in
>>the mro order, and call that class's met method.
>>
>>As shown with the mro(), the class after D is B.  So B.met() is called.
>>Normally, we would be done.  But take a look at B's method!
>>
>>
>>>class B(A):
>>>def met(self):
>>>print 'B.met'
>>>super(B,self).met()
>>
>>B.met calls super, and invokes the next met method!  So, the code does
>>exactly what you've asked it to do, and searches for the next class
>>after B in the mro list: class C.
> 
> 
> But when super(B,self).met() is invoked, isn't it supposed to look
> at MRO order of *B*, 

No. It's supposed to look at the MRO of self for what comes after B.

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


Re: Unicode / cx_Oracle problem

2006-09-10 Thread Diez B. Roggisch
> Value of the variable 'id' is  u'\ufeff'
> Value of the variable 'mean' is  u'('

So they both are unicode objects - as I presumed.


> It's very hard to figure out what to do on the basis of complexities
> on the order of
> 
> http://download-east.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25108/xedev_global.htm#sthref1042
> 
> (tiny equivalent http://tinyurl.com/fnc54

Yes, that is somewhat intimidating.

> But I'm not even sure I got that far. My problems so far seem prior:
> in Python or Python's cx_Oracle driver. To be candid, I'm very tempted
> at this point to abandon the Python effort and revert to an all-ucs2
> environment, much as I dislike Java and C#'s complexities and the poor
> support available for all-Java databases.

That actually doesn't help you much I guess - just because JDBC will 
convert java's unicode strings to byte strings behind the curtains, you 
will lose all encoding information nonetheless - especially if the DB 
itself isn't running an encoding that will allow for all possible 
unicode characters to be represented.

>> Then you need to encode the unicode string before passing it - something 
>> like this:
>>
>> mean = mean.encode("latin1")
> 
> I don't see how the Chinese characters embedded in the English text
> will carry over if I do that.

Me neither, but how could I have foreseen that? So use something else 
instead - utf-8 for example, or whatever the oracle connection will grok.

I think you should read up on what unicode and encodings are, and how 
they work in python, and unfortunately how they do work in oracle. 
Because even if you use java - not understanding how things are 
connected will hit you in the neck at some point.

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


Re: Looking for the Perfect Editor

2006-09-10 Thread Kent Johnson
Dick Moores wrote:
> At 01:10 PM 9/8/2006, Doug Stell wrote:
>> Try www.TextPad.com. I've used it for years and love it. It
>> understands many programming language constructs and can be taught to
>> understand python so that things show up in color.
> 
> Any tips on how to teach TextPad to understand python?

Download and install the Python syntax highlighting definition from the 
TextPad website.

I make a tool to run the front window in Python. Here are the values 
from the preferences window for the tool:

Command: C:\Python24\python.exe
Parameters: -u $File
Init fldr: $FileDir

regex to match output:
^.*"([^"]+)", *line ([0-9]+)

with File: 1, Line: 2

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


Re: [Fwd: Problems with PyGridTableBase]

2006-09-10 Thread [EMAIL PROTECTED]
Hopefully this helps keep your post alive..  I looked all over the
internet for examples written with wxgrid and wxgrid with python and
haven't realy found out how to add the other functions to a
boa-constructor program there just isn't anything except the simple
example incuded with boa.  This is as far as I got and I am not sure I
am very close (with my example trying to add the extra functions to the
class instead of inheriting it from grid)

#Boa:Frame:Frame3

import wx
import wx.grid

def create(parent):
return Frame3(parent)

[wxID_FRAME3, wxID_FRAME3BUTTON1, wxID_FRAME3GRID1,
wxID_FRAME3TEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(4)]

class Frame3(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME3, name='', parent=prnt,
  pos=wx.Point(401, 118), size=wx.Size(367, 585),
  style=wx.DOUBLE_BORDER, title=u'')
self.SetClientSize(wx.Size(361, 579))

self.grid1 = wx.grid.Grid(id=wxID_FRAME3GRID1, name='grid1',
  parent=self, pos=wx.Point(8, 16), size=wx.Size(80, 392),
  style=wx.WANTS_CHARS | wx.TRANSPARENT_WINDOW |
wx.MINIMIZE_BOX | wx.DOUBLE_BORDER | wx.VSCROLL)

self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME3TEXTCTRL1,
name='textCtrl1',
  parent=self, pos=wx.Point(112, 16), size=wx.Size(232,
392),
  style=wx.TE_LINEWRAP, value=u'')
self.textCtrl1.SetThemeEnabled(False)
self.textCtrl1.SetCursor(wx.CROSS_CURSOR)

self.button1 = wx.Button(id=wxID_FRAME3BUTTON1, label=u'exit',
  name='button1', parent=self, pos=wx.Point(72, 440),
  size=wx.Size(136, 23), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
  id=wxID_FRAME3BUTTON1)

def __init__(self, parent):
self._init_ctrls(parent)
self.grid1.CreateGrid(0, 1)

def OnButton1Button(self, event):
self.Close()
def update_instument_list(csndname):
csdInstrumentList(csndname) #needs to have a file variable..
noinlist=0
for number in range(0,noinlist):
 self.grid1.AppendRows(1)
 self.grid1.SetCellValue(number,0,instrlist[number])

http://www.dexrow.com



Mario Lacunza wrote:
> - Mensaje reenviado 
> De: Mario Lacunza <[EMAIL PROTECTED]>
> Para: Lista Python Ing 
> Asunto: Problems with PyGridTableBase
> Fecha: Sat, 09 Sep 2006 00:03:20 -0500
>
> Hello,
>
> I attach two files:frmClientes and frmClientesNE.
>
> frmClientes charge a Grid with resume Costumers data: Name, Commercial
> ID, address, etc. and edition options.
>
> frmClientes in
>
> Line 178
> def OnBtnNuevoButton(self, event):
>
> call to frmClientesNE. Its append a new record to the database and clear
> all controls and when I close it, the grid in frmClientes: grClte must
> be recharge with the new data, but that dont work. Only work when a
> Delete some record.
>
> I couldnt send yours a runable .py version, because both of them files
> pickup data from a Firebird's database.
>
> I try to implement the wxPython Demo model: Grid_MegaExample, follow
> that my class Grilla must be:
>
> Line 224:
> class Grilla(Grid.Grid):
>
> but for the Boa Constructors controls creation I couldnt inherit from
> Grid.Grid, thats my problem, I need your help I try for two days and
> nothing :-( ... some ideas??
>
> Thanks in advance!!
>
> ==
> FILE: FRMCLIENTES.PY
> ==
>
> # -*- coding: utf8 -*-#
> #Boa:Frame:frmClientes
>
> __version__='0.5'
> __autor__='Mario Lacunza Vasquez <[EMAIL PROTECTED]>'
>
> import wx
> import wx.grid
> import modGlobals
> from Conectar import Conectar
> import errores
>
> def create(parent):
> return frmClientes(parent)
>
> [wxID_FRMCLIENTES, wxID_FRMCLIENTESBRNSALIR, wxID_FRMCLIENTESBTNBORRAR,
>  wxID_FRMCLIENTESBTNEDIT, wxID_FRMCLIENTESBTNNUEVO,
> wxID_FRMCLIENTESGRCLTE,
>  wxID_FRMCLIENTESLBLTITULO, wxID_FRMCLIENTESPANEL1,
> ] = [wx.NewId() for _init_ctrls in range(8)]
>
> class frmClientes(wx.Frame):
> def _init_coll_fsGrid_Growables(self, parent):
> # generated method, don't edit
>
> parent.AddGrowableRow(0)
>
> def _init_coll_fsGrid_Items(self, parent):
> # generated method, don't edit
>
> parent.AddWindow(self.grClte, 0, border=2, flag=wx.EXPAND |
> wx.ALL)
>
> def _init_coll_fsBtn_Items(self, parent):
> # generated method, don't edit
>
> parent.AddWindow(self.btnNuevo, 0, border=2, flag=wx.EXPAND |
> wx.ALL)
> parent.AddWindow(self.btnEdit, 0, border=2, flag=wx.EXPAND |
> wx.ALL)
> parent.AddWindow(self.btnBorrar, 0, border=2, flag=wx.EXPAND |
> wx.ALL)
> parent.AddWindow(self.brnSalir, 0, border=2, flag=wx.EXPAND |
> wx.ALL)
>
> def _init_coll_fsTit_Items(self, parent):
> # generated method, don

Re: Is it just me, or is Sqlite3 goofy?

2006-09-10 Thread Paul Boddie
Dennis Lee Bieber wrote:
>
>  Talking to myself again, I see...

Not quite. ;-)

[...]

>  How interesting... With MySQL/MySQLdb I did NOT get exceptions or
> error results on inserting bad numeric data supplied as character string
> format (ie, as read from the CSV). Instead, MySQL SILENTLY converted
> them to ZEROS
>
>  A price of "Priceless" becomes Decimal("0.00").
>
>  The Customer number of ">68" became 0L

This kind of thing is "classic" MySQL behaviour.

>  Which would one rather have to work with -- a database that copied
> invalid numerics as string literals (which, in my mind, makes it much
> easier to correct the data later, using "update  set field = correct
> where field = invalid") or a database that silently converts them all to
> 0 values. (Of course, I now expect to have a rejoinder about "Using a
> REAL database instead of MySQL" -- but unless said person wishes to
> start making the same comments about SQLite on at least as regular a
> basis, I believe the objection itself is invalid for this example).

Given subsequent research into SQLite's affinity modes and their
presumed status as future features, the solution in that database
system's case is to apply validation in the driver/module or through
driver extensions, and there is apparently some flexibility in the
pysqlite2 modules for changing the way data types are handled, although
a cursory inspection of the documentation doesn't appear to suggest a
convenient, ready-made solution.

As for MySQL, the situation is possibly more awkward: one expects the
database system to complain about certain things, which it probably
does from time to time, but it would seem wasteful to duplicate
whatever validation the database system does do just to cover those
situations where the system misbehaves.

Paul

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


Re: Unicode / cx_Oracle problem

2006-09-10 Thread Richard Schulman
On Sun, 10 Sep 2006 11:42:26 +0200, "Diez B. Roggisch"
<[EMAIL PROTECTED]> wrote:

>What does print repr(mean) give you?

That is a useful suggestion.

For context, I reproduce the source code:

in_file = codecs.open("c:\\pythonapps\\mean.my",encoding="utf_16_LE")
connection = cx_Oracle.connect("username", "password")
cursor = connection.cursor()
for row in in_file:
id = row[0]
mean = row[1]
print "Value of row is ", repr(row)#debug line
print "Value of the variable 'id' is ", repr(id)   #debug line
print "Value of the variable 'mean' is ", repr(mean)   #debug line
cursor.execute("""INSERT INTO mean (mean_id,mean_eng_txt)
VALUES (:id,:mean)""",id=id,mean=mean)

Here is the result from the print repr() statements:

Value of row is  u"\ufeff(3,'sadness, lament; sympathize with,
pity')\r\n"
Value of the variable 'id' is  u'\ufeff'
Value of the variable 'mean' is  u'('

Clearly, the values loaded into the 'id' and 'mean' variables are not
satisfactory but are picking up the BOM.

>... 
>The oracle NLS is a sometimes tricky beast, as it sets the encoding it 
>tries to be clever and assigns an existing connection some encoding, 
>based on the users/machines locale. Which can yield unexpected results, 
>such as "Dusseldorf" instead of "Düsseldorf" when querying a german city 
>list with an english locale.

Agreed.

>So - you have to figure out, what encoding your db-connection expects. 
>You can do so by issuing some queries against the session tables I 
>believe - I don't have my oracle resources at home, but googling will 
>bring you there, the important oracle term is NLS.

It's very hard to figure out what to do on the basis of complexities
on the order of

http://download-east.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25108/xedev_global.htm#sthref1042

(tiny equivalent http://tinyurl.com/fnc54

But I'm not even sure I got that far. My problems so far seem prior:
in Python or Python's cx_Oracle driver. To be candid, I'm very tempted
at this point to abandon the Python effort and revert to an all-ucs2
environment, much as I dislike Java and C#'s complexities and the poor
support available for all-Java databases.

>Then you need to encode the unicode string before passing it - something 
>like this:
>
>mean = mean.encode("latin1")

I don't see how the Chinese characters embedded in the English text
will carry over if I do that.

In any case, thanks for your patient and generous help.

Richard Schulman
Delete the antispamming 'xx' characters for email reply
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two ethernet cards/networks (still)

2006-09-10 Thread Bob Greschke

"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Bob Greschke wrote:
> The reason that "binding to a specific address is almost never used for a 
> client" is because it's the server destination address that the network 
> layer will use to determine which interface is used to communicate with a 
> specific server host.
>
> Suppose your network setup looks like this:
>
>
> +---++ Network A
> |
> |
> |
> | 192.168.12.34/24
> |
>+++
>| |
>| |
>| YOUR HOST   |
>| |
>| |
>+++
> |
> | 201.46.34.22/24
> |
> |
> |
> +---+--+-+ Network B
>|
>+
>   +++
>   |  router |
>   |   to internet   |
>   +-+
>
> If your client program tries to communicate with, say, 192.168.12.18 then 
> by the IP network layer will automatically select network A as the medium, 
> since the destination is local to that network. If you then want to 
> communicate the results to 201.46.34.118 then network B will be used, 
> again because the destination is local to that network (its first 24 bits 
> are the same as the first 24 bits of the destination).
>
> In this case the router on network B will almost certainly be the default 
> route for the host, as it's the way to everywhere else.
>
> This isn't really Python-related, so I hope it answers your question!
>
> regards
>  Steve
> -- 
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb   http://holdenweb.blogspot.com
> Recent Ramblings http://del.icio.us/steve.holden
>

Nice explanation!  Thanks!  You mean I don't have to do anything special?? 
That sounds suspiciously easy. :)

To muddy the water a little the equipment I want to get info from (some 
seismic digitizing/recording equipment) comes back to us from the field with 
the IP addresses set to whatever that last user needed.  What we do now is 
put the unit(s) on the bench, connect them to the private network and use a 
broadcast address (like 255.255.255.255) and a specific port number to query 
and see who is connected.  Then we (a program) can get in (login, basically) 
and reset the all of the IPs to the same subnet to proceed with checkout, 
calibration, etc.  We have to disconnect from (or disable the card for) the 
outside network when we do this discovery or else the program discovers all 
of these instruments that we have running in the building (monitoring a 
seismic pier, in people's offices, etc.).  I'm guessing here we will still 
need to do this?  It's not a biggie, but finding a way to not have to do 
this was what started this whole thing.  Once the program knows which 
instruments it found on the private network it doesn't matter.  It will only 
work on those ones.

Thanks!

Bob


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


Re: New SourceForge project: Diet Python!!!

2006-09-10 Thread Peter Beattie
TOFU sucks!

The Eternal Squire wrote:
> Best interface for roguelike gaming.
> 
> Jarek Zgoda wrote:
>> The Eternal Squire napisa³(a):
>>
>>> Diet Python is a flavor of Python with allegro, multiarray, umath,
>>> calldll, npstruct and curses builtin, all else nonessential to language
>>> ripped out. Total size < 3MB, 1% of PSF Python. Diet Python helps keep
>>> clients thin :)
>> Why do you think curses are essential? I'd rip out them too, they have
>> no use on Windows.
>>
>> -- 
>> Jarek Zgoda
>> http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring Dilemma

2006-09-10 Thread George Sakkis
Kamilche wrote:
> '''
> I'm in the middle of a refactoring dilemma.
> I have several singletons that I'm turning into modules, for ease of
> access.
> The usual method is noted as 'Module 1' below.
> The new method is noted as 'Module 2'.
> Is there any reason NOT to do this that I may be unaware of?
> It's easier than remembering to declare global variables at the top of
> the function.
> '''
>
> # --- Module 1.py 
> # Normal module processing
> var = 0
>
> def MyRoutine():
> global var
> var = 1
>
> MyRoutine()
> print var
>
>
> # --- Module 2.py 
> # 'Self' module processing
> import sys
> var = 0
> self = sys.modules[__name__]
>
> def MyRoutine():
> self.var = 1
>
> MyRoutine()
> print var


What's wrong with

def MyRoutine():
 return 1

var = MyRoutine()

?

George

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


Re: makepy, ADO and dynamic.py

2006-09-10 Thread Roger Upole

"Chris Curvey" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> I'm trying to track down a performance issue in my Windows code, and
> hotshot is telling me that the most time and calls are spent in these
> methods
>
>   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>75975 63982.7790.842 124464.4191.638
> c:\python24\lib\site-packages\win32com\client\dynamic.py:285(_make_method_)
>71294 47871.4240.671 50629.2240.710
> c:\python24\lib\site-packages\win32com\client\__init__.py:444(_ApplyTypes_)
>
> If I understand correctly, running makepy on the appropriate COM class
> should get rid of the dynamic stuff and let it be called directly.  I
> use ADODB to talk to my database server, and I've run makepy for
> "Microsoft Active X Data Objects 2.8 Library" [1] and on "Microsoft
> ActiveX Data Objects Recordset 2.8 Library", but I'm still seeing the
> call to the dynamic.py class.
>
> Am I right that seeing the calls in "dynamic.py" implies that I'm
> running "makepy" on the wrong thing?  Any idea what I should be running
> makepy on?
>
> [1] I seem to have a bunch of versions of "Microsoft ActiveX Data
> Objects Library", is there a chance that another ADO library is being
> used?
>

The most reliable way to make sure the generated support is used is
to call win32com.client.gencache.EnsureDispatch.  If a typelib can
be found, the corresponding python module will be created if it doesn't
already exist.

   Roger


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


get the en of a program running in background

2006-09-10 Thread awalter1
Hi,
I develop a graphical user interface (with pyGTK) where a click on a
button shall launch a program P in background. I want to get the end of
this program P but I don't want that my HMI be freezed while P is
running.
I try to use fork examplesI found on the web, but it seems to not run
as expected.
I am not familiar with these techniques in unix as well as python.
But I suppose that my needs are usual, despite that I don't find
anything on the web ...
Is someone can give me a standard way to call a background program,
wait its end, with an IHM still active ?

Thank a lot for any idea.

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


downloading eggs

2006-09-10 Thread Bryan
i'm trying to just download the turbogears eggs without installing it.  i've 
read the turbogear install instructions and the easy_install help.


from the easy_install web site:

If you have another machine of the same operating system and library versions 
(or if the packages aren't platform-specific), you can create the directory of 
eggs using a command like this:

easy_install -zmaxd somedir SomePackage



i tried this:


C:\python\turbogears>easy_install -zmaxd TurboGears TurboGears
Processing TurboGears
error: Couldn't find a setup script in TurboGears


C:\python\turbogears>easy_install -zmaxd . TurboGears
Processing TurboGears
error: Couldn't find a setup script in TurboGears



on the turbogears mailing list, someone posted this:

You could even do "easy_install -zmaxd TurboGears" at home to just
download the files and then bring in the files on a usb key and then
"easy_install -f . TurboGears" from the usb drive.


i tried this:

C:\python\turbogears>easy_install -zmaxd TurboGears
error: No urls, filenames, or requirements specified (see --help)


i copied the ez_setup.py file from turbogears and tried the commands against 
that script but it didn't work.  i'm using setuptools-0.6c2 if that is helpful 
to anyone.


thanks,

bryan



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


Tkinter listbox:get

2006-09-10 Thread Sorin Schwimmer
lb.curselection() won't return an integer, but a tuple of strings. Also, a StringVar receives a new value with the set() method. So, you'll have to write something like:idx=lb.curselection()StringValue.set(lb.get(int(idx[0])))This will grab the first value from the tuple, convert it in integer, and pass it to lb.get() to extract the line in your Listbox, and set it in your Entry via the StringVar. If
 you allow multiple selections from your Listbox, you may have more than one value in idx, and you'll have to decide how you intend to process them.Check any of these (or both):http://www.pythonware.com/library/tkinter/introduction/index.htmhttp://infohost.nmt.edu/tcc/help/pubs/tkinter/They're both easy to follow, and you'll save more time, than asking one little think at a time, and then waiting for someone to answer.Good luck!Sorin-- 
http://mail.python.org/mailman/listinfo/python-list

Refactoring Dilemma

2006-09-10 Thread Kamilche
'''
I'm in the middle of a refactoring dilemma.
I have several singletons that I'm turning into modules, for ease of
access.
The usual method is noted as 'Module 1' below.
The new method is noted as 'Module 2'.
Is there any reason NOT to do this that I may be unaware of?
It's easier than remembering to declare global variables at the top of
the function.
'''

# --- Module 1.py 
# Normal module processing
var = 0

def MyRoutine():
global var
var = 1

MyRoutine()
print var


# --- Module 2.py 
# 'Self' module processing
import sys
var = 0
self = sys.modules[__name__]

def MyRoutine():
self.var = 1

MyRoutine()
print var

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


wxPython, how to autoresize a frame?

2006-09-10 Thread David
Dear all,

In a wxPyhton frame I make a group of controls hiding by pressing a button
and i want the whole frame to resize accordingly.

The test GUI I wrote is structured like this:

frame
  |
  +-sizer0 (BoxSizer, 1 slot)
  |
  +-panel (style=wx.EXPAND)
  |
  +-sizer1 (BoxSizer vertical, 2 slots)
  |
  +-sizer2 (FlexGridSizer, 2x2)
  |   |
  |   +-controls to hide
  |
  +-button


The problem is that, when sizer2 containig hidden controls collapses to
zero dimensions, the panel resizes, but sizer1 and sizer0 don't!
Consequently the frame does not want to autoresize.

You con dowload the code here:
http://www.box.net/public/evfxs7cp5j

Someone con help me?

Thanks

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


Algorithm Question

2006-09-10 Thread Andrew McLean
This really an algorithm question more that a Python question, but it 
would be implemented in Python

I have a list of strings, A. I want to find a set of strings B such that 
for any "a in A" there exists "b in B" such that b is a sub-string of a. 
But I also want to minimise T = sum_j t_j where

t_j = count of the number of elements in A which have b[j] as a sub-string

My guess is that finding the smallest possible T satisfying the 
constraint would be hard. However, for my application just keeping it 
reasonably small would help.

In my case the list A contains over two million addresses.

The (top down) heuristic approach I am tempted to employ is to start by 
dividing the entries in A into sets of tokens, then take the union of 
all these sets as a starting point for B. Then I would try to trim B by

1. looking for elements that I could remove while still satisfying the 
constraint

2. replacing two elements by a common sub-string if that reduced T

Anyway. It occurred to me that this might be a known problem. Any 
pointers gratefully received.

- Andrew

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


Re: Looking for the Perfect Editor

2006-09-10 Thread John Bokma
"urielka" <[EMAIL PROTECTED]> wrote:

> use Eclipse!!!

Q: how can I do x with A
A: use B!!! OMG LOLLZZ111!!!11eleven


-- 
John   MexIT: http://johnbokma.com/mexit/
   personal page:   http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks,
In Python 2.5 there are also functools.wraps and
functools.update_wrapper:
http://docs.python.org/dev/whatsnew/pep-309.html

George Sakkis wrote:
> oripel wrote:
> > Thanks Paddy - you're showing normal use of function attributes.
> > They're still hidden when wrapped by an uncooperative decorator.
>
> The decorator module may be helpful in defining cooperative decorators:
> http://www.phyast.pitt.edu/~micheles/python/documentation.html
> 
> George

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


Re: OT: What encoding is this?

2006-09-10 Thread skip

I appreciate all the useful feedback on my request.  For some reason Safari
initially refused to display the page properly with iso-8859-1, and after a
bit more poking around with it eventually dropped a note to the list.  I
eventually discovered that Firefox has a much larger set of encodings to
choose from.  I don't know why Safari didn't display it properly the first
time.  It eventually did.

Skip

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


Re: egg and modpython

2006-09-10 Thread Bruno Desthuilliers
Wensheng a écrit :
> I installed pysqlite2 using easy_install.
> and got this when using it from modpython:
> --
> Mod_python error: "PythonHandler etc.modpython"
> 
> Traceback (most recent call last):
> 
(snip)
> 
> ExtractionError: Can't extract file(s) to egg cache
> 
> The following error occurred while trying to extract file(s) to the
> Python egg
> cache:
> 
>   [Errno 13] Permission denied: '/var/www/.python-eggs'
> 
> The Python egg cache directory is currently set to:
> 
>   /var/www/.python-eggs
> 
> Perhaps your account does not have write access to this directory?  You
> can
> change the cache directory by setting the PYTHON_EGG_CACHE environment
> variable to point to an accessible directory.
> 
> 
> Can peak developers fix this please?

Why should they "fix" something that's
1/ documented
-> http://peak.telecommunity.com/DevCenter/EggFormats#zip-file-issues
2/ not a an egg specific issue
3/ really just a configuration/permission problem

(snip)

> in the mean time, I just have to use old "download, unzip/untar &&
> python setup.py install" way.

No - you have to read the manual and fix you configuration. FWIW, the 
above traceback gives far enough clues (it's even written in all letters).

Or you may read easy_install's doc to avoid installing zipped eggs:
http://peak.telecommunity.com/DevCenter/EasyInstall#compressed-installation

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


Re: Ghostscript interface

2006-09-10 Thread John Purser
On Sun, 2006-09-10 at 08:14 -0700, defcon8 wrote:
> Does a ghostscript interface for python exist? I have searched google
> quite a bit and all I have been able to find are command line hacks
> from within python. Thanks in advance for any useful help.
> 

I'm not sure what you mean by a "Ghostscript interface".  Ghostscript is
a program.  Yes, you can run it from Python using the same methods you
run any other program from Python but I'd hardly call that an
"interface".

If you're looking for a python postscript generator I believe a google
search will turn up a number of products.

If you're looking for a python .pdf generator you might want to check
out:
http://www.reportlab.org/

John Purser

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


Ghostscript interface

2006-09-10 Thread defcon8
Does a ghostscript interface for python exist? I have searched google
quite a bit and all I have been able to find are command line hacks
from within python. Thanks in advance for any useful help.

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


Re: Looking for the Perfect Editor

2006-09-10 Thread Morten Juhl Johansen
mystilleef wrote:
> I recommend Scribes.
> 
> http://scribes.sf.net

Scribes looks good. Does it need any Gnome components except what is
mentioned @ http://scribes.sourceforge.net/documentation.html#requirements ?

Yours,
Morten
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: What encoding is this?

2006-09-10 Thread Morten Juhl Johansen
Martin v. Löwis wrote:
> Neil Hodgson schrieb:
>>> http://www.loppen.dk/side.php?navn=getin
>> More pages without declarations are produced on Windows so
>> I'd guess that its Windows-1252. To tell, look for prices in Euros ("€")
>> on the site.
> 
> Ah, but they still use krones in Denmark :-)
> 
> Regards,
> Martin

True. Yes, it is Danish.
The specific Danish characters æøå are visible with several encodings.
(I write this characters in unicode here).
And there are no prices on that page, since it describes the hardware
available at the small concert place Loppen.

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

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread George Sakkis
oripel wrote:
> Thanks Paddy - you're showing normal use of function attributes.
> They're still hidden when wrapped by an uncooperative decorator.

The decorator module may be helpful in defining cooperative decorators:
http://www.phyast.pitt.edu/~micheles/python/documentation.html

George

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


Re: pyExcelerator question - dates map to floats?

2006-09-10 Thread skip

John> Check out my "xlrd" package.
John> http://cheeseshop.python.org/pypi/xlrd/0.5.2

Very nice.  Thanks for the pointer.  I threw away about 75% of the
xls-to-csv converter I wrote using pyExcelerator.  And it worked with Python
2.3 without having to comment out all the decorators.

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


Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks Paddy - you're showing normal use of function attributes.
They're still hidden when wrapped by an uncooperative decorator.

Paddy wrote:
> oripel wrote:
> > Hi,
> >
> > I'm trying to attach some attributes to functions and methods, similar
> > to Java annotations and .NET attributes.
> > I also want to use a convenient decorator for it, something along the
> > lines of
> >
> > @attr(name="xander", age=10)
> > def foo():
> >   ...
> >
> > Assigning attributes to the function will work, as will assigning keys
> > and values to a dictionary in an attribute. But if there are more
> > decorators in the way, this could fail:
> >
> > @onedec
> > @attr(...)
> > @twodec
> > def foo():
> >   ...
> >
> > Given 'foo' now, how do I find the attributes?
> >
> > Assigning to a global attribute registry (some interpreter-global
> > dictionary), although less desirable, might have been acceptable, but
> > then how do I identify the function after it's been wrapped in more
> > decorators?
> >
> > Also, it may be nice to have the following work as well:
> >
> > @attr(name="Xander")
> > @attr(age=10)
> > @somedec
> > @attr(hobby="knitting")
> > def foo():
> >   ...
> >
> >
> > Any thoughts? Am I rehashing something old that my search skills didn't
> > uncover?
> >
> > Thanks!
> > Ori.
>
> I wrote up my investigation into function attributes and decorators on
> my blog:
>
> http://paddy3118.blogspot.com/2006/05/python-function-attributes.html
> http://paddy3118.blogspot.com/2006/05/function-attributes-assigned-by.html
> 
> What do you think?
> 
> - Paddy.

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


Re: Secure Postgres access

2006-09-10 Thread [EMAIL PROTECTED]
Paul Rubin wrote:
> Reid Priedhorsky <[EMAIL PROTECTED]> writes:
> > B) Work machine. Run by others, many users. I'd like to also run my
> > database client (Python) here.
>
> Well, just how much do you distrust that machine?  If you think it's
> totally pwned by attackers who will stop at nothing to subvert your
> client, you shouldn't run the client there.

I got the impression that he didn't trust other normal users on the box
but that root wasn't hostile.

> > What I'd like is functionality similar to what Subversion does with
> > "svn+ssh://" URLs: an SSH tunnel that accepts only one connection and
> > doesn't have race conditions.
[SNIP]
> And even if you have an SSH mode that accepts just one connection,
> since your db app is separate and has to connect to the
> forwarding port after you use a separate program open the port,
> how do you stop someone else from grabbing it first?

(I think that's what he meant by "doesn't have race conditions".)

> That seems to mean one of:
>
>   2) authentication through SCM_CREDENTIALS on a PF_UNIX socket

That looks like the best option of those you list.

> Actually, looking at the doc for ssh-agent(1), it looks like it might
> do something like #2 above.  If I understand it, you would run your db
> client as something like
>
>ssh-agent your-client &

That's cool, I'm looking for something similar, thanks!

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


Re: Looking for the Perfect Editor

2006-09-10 Thread urielka
use Eclipse!!!
it is not a editor but it is the best free IDE out there.
for python use Pydev(pydev.sf.net) plugin:it got
EVERYTHING:completteion,debuging(with thread support)you can`t work
without a debugger for serious projects.
for Web Develop use Aptana(aptana.com) another plugin for eclipse,in
eairly stages but it is very amazing support most of open source
javascript library with auto-complete and outline of code.
Scribes look very nice for a editor i will try it for lightweight
editing.

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


Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks!

Now I see it's accepted to assume nice decorators that update __dict__.
At least until __decorates__ or something similar is added...

fumanchu wrote:
> oripel wrote:
> > I'm trying to attach some attributes to functions and methods, similar
> > to Java annotations and .NET attributes.
> > ...
> > Assigning attributes to the function will work, as will assigning keys
> > and values to a dictionary in an attribute. But if there are more
> > decorators in the way, this could fail:
> >
> > @onedec
> > @attr(...)
> > @twodec
> > def foo():
> >   ...
> >
> > Given 'foo' now, how do I find the attributes?
> > ...
> > Any thoughts? Am I rehashing something old that my search skills didn't
> > uncover?
>
> There are past discussions about this; google for "python-dev decorator
> metadata". For example:
> http://thread.gmane.org/gmane.comp.python.devel/77506/focus=77507
>
>
> Robert Brewer
> System Architect
> Amor Ministries
> [EMAIL PROTECTED]

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


Re: No ValueError for large exponents?

2006-09-10 Thread Felipe Almeida Lessa
2006/9/6, Robin Becker <[EMAIL PROTECTED]>:
> enigmadude wrote:
> > As many have heard, IronPython 1.0 was released. When I was looking
> > through the listed differences between CPython and IronPython, the
> > document mentioned that using large exponents such as 10 **
> > 735293857239475 will cause CPython to hang, whereas IronPython will
> > raise a ValueError. Trying this on my own machine, it did indeed seem
> > to cause CPython to hang. In cases such as this, should this be
> > considered a bug in the CPython implementation that needs to be fixed?
> > Or is there a reason for this, such as consideration of future changes
> > and language definition vs language implementation, etc.?
> >
> I suspect the hang may be python actually trying to work out the
> 1 followed by 735293857239475 zeroes. Perhaps IronPython has a forward
> looking algorithm that knows when to give up early.

I think that IronPython does the same as the .Net runtime does. Look
at boo's output:

$ booish
Welcome to booish, an interpreter for the boo programming language.

Running boo 0.7.5.2013.

The following builtin functions are available:
dir(Type): lists the members of a type
help(Type): prints detailed information about a type
load(string): evals an external boo file
globals(): returns the names of all variables known to the interpreter

Enter boo code in the prompt below.
>>> 10**100
1E+100
>>> 10**100
∞
>>> 10**735293857239475
ERROR: Error reading from 'input3': 'Value too large or too small.'.
>>> (10**100).GetType()
System.Double

Well, it's a double on boo instead of a very long int as in Python. I
don't know if in IronPython it's the same.

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

Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread oripel
Thanks bearophile,

I prefer not to use docstrings for metadata.

1. Not interfering with the other accepted docstring uses may be
difficult (doctests, epydoc)

2. It's impractical for attributes generated by code:

@attr(reference_profile_stats=pstats.Stats("foo.profile"))
def foo():
  ...

Regards,
Ori.

[EMAIL PROTECTED] wrote:
> oripel:
>
> Maybe this is a silly suggestion, the docstring is already overloaded,
> but it may be used for this too:
>
> def foo():
> """
> ...
> ...
> @ATTR name="Xander"
> @ATTR age=10
> @ATTR hobby="knitting"
> """
> ...
>
> (Or somethins similar without the @). Later you can retrive the
> attributes from the docstring, for example using a verbose RE like:
> r"\s* @ATTR \s+ (\w*) \s* = \s* (.*)"
> And you use it to create a dict of attributes.
> The decorators you apply to foo() must keep its docstring too.
> 
> Bye,
> bearophile

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


Re: pyExcelerator question - dates map to floats?

2006-09-10 Thread skip

John> Check out my "xlrd" package.
John> http://cheeseshop.python.org/pypi/xlrd/0.5.2

...

John,

Thank you.  I wasn't aware of it.  I'd seen mention of pyExcelerator a few
times recently.  All I need is to read Excel spreadsheets anyway.  I will
check it out.

I'm up for reading a good rant. ;-)

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


Re: Unicode / cx_Oracle problem

2006-09-10 Thread Diez B. Roggisch
Richard Schulman schrieb:
>>>  cursor.execute("""INSERT INTO mean (mean_id,mean_eng_txt)
>>>  VALUES (:id,:mean)""",id=id,mean=mean)
>>> ...
>>>  "cx_Oracle.NotSupportedError: Variable_TypeByValue(): unhandled data
>>> type unicode"
>>>
>>> But when I try putting a codecs.BOM_UTF16_LE in various plausible
>>> places, I just end up generating different errors.
> 
> Diez:
>> Show us the alleged plausible places, and the different errors. 
>> Otherwise it's crystal ball time again.
> 
> More usefully, let's just try to fix the code above. Here's the error
> message I get:
> 
> NotSupportedError: Variable_TypeByValue(): unhandled data type unicode
> 
> Traceback (innermost last):
> 
> File "c:\pythonapps\LoadMeanToOra.py", line 1, in ?
>   # LoadMeanToOra reads a UTF-16LE input file one record at a time
> File "c:\pythonapps\LoadMeanToOra.py", line 23, in ?
>   cursor.execute("""INSERT INTO mean (mean_id,mean_eng_txt)
> 
> What I can't figure out is whether cx_Oracle is saying it can't handle
> Unicode for an Oracle nvarchar2 data type or whether it can handle the
> input but that it needs to be in a specific format that I'm not
> supplying.

What does

print repr(mean)

give you?

It _looks_ to me (don't have an orcacle available right now) as if it is 
  a unicode object. That you have to consider as some abstract string 
representation. Which means it has to be encoded in some way before sent 
over the wire. There might exist db-api bindings that can deal with 
them, by applying a default encoding or somehow figuring out what 
encoding the DB expects. But I don't see any references to unicode in 
pep 249, so I presume you can't rely on that - which seems to be the 
case here.

The oracle NLS is a sometimes tricky beast, as it sets the encoding it 
tries to be clever and assigns an existing connection some encoding, 
based on the users/machines locale. Which can yield unexpected results, 
such as "Dusseldorf" instead of "Düsseldorf" when querying a german city 
list with an english locale.

So - you have to figure out, what encoding your db-connection expects. 
You can do so by issuing some queries against the session tables I 
believe - I don't have my oracle resources at home, but googling will 
bring you there, the important oracle term is NLS.

Then you need to encode the unicode string before passing it - something 
like this:

mean = mean.encode("latin1")

That should help.

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


Re: How to insert an email-link into wxPython's HtmlWindow

2006-09-10 Thread [EMAIL PROTECTED]

Thanks. It works now.

--Kneo

[EMAIL PROTECTED] wrote:
> Hello. I don't know if this topic is appropriate in this group (and my
> English is not good).
>
> My problem is here:
>
> I created a HtmlWindow in wxPython, then I wrote some code and set it
> to the page-text. In these code there was a line " href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]" (where "name" was my
> real username). Then I showed this HtmlWindow and I thought there would
> be a mail-sending box when I clicked on the "[EMAIL PROTECTED]" link (like
> when I clicked it in a web browser). But there just came a "Python
> Error"-titled dialog: Unable to open requested HTML document
> mailto:[EMAIL PROTECTED] What should I do to solve this problem?
> 
> (My OS is WinXP.)
> 
> Thanks.

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


Re: Function metadata (like Java annotations) in Python

2006-09-10 Thread Paddy
oripel wrote:
> Hi,
>
> I'm trying to attach some attributes to functions and methods, similar
> to Java annotations and .NET attributes.
> I also want to use a convenient decorator for it, something along the
> lines of
>
> @attr(name="xander", age=10)
> def foo():
>   ...
>
> Assigning attributes to the function will work, as will assigning keys
> and values to a dictionary in an attribute. But if there are more
> decorators in the way, this could fail:
>
> @onedec
> @attr(...)
> @twodec
> def foo():
>   ...
>
> Given 'foo' now, how do I find the attributes?
>
> Assigning to a global attribute registry (some interpreter-global
> dictionary), although less desirable, might have been acceptable, but
> then how do I identify the function after it's been wrapped in more
> decorators?
>
> Also, it may be nice to have the following work as well:
>
> @attr(name="Xander")
> @attr(age=10)
> @somedec
> @attr(hobby="knitting")
> def foo():
>   ...
>
>
> Any thoughts? Am I rehashing something old that my search skills didn't
> uncover?
>
> Thanks!
> Ori.

I wrote up my investigation into function attributes and decorators on
my blog:

http://paddy3118.blogspot.com/2006/05/python-function-attributes.html
http://paddy3118.blogspot.com/2006/05/function-attributes-assigned-by.html

What do you think?

- Paddy.

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


Re: OT: What encoding is this?

2006-09-10 Thread Martin v. Löwis
Neil Hodgson schrieb:
>> http://www.loppen.dk/side.php?navn=getin
>
> More pages without declarations are produced on Windows so
> I'd guess that its Windows-1252. To tell, look for prices in Euros ("€")
> on the site.

Ah, but they still use krones in Denmark :-)

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


Re: Can I make unicode in a repr() print readably?

2006-09-10 Thread Martin v. Löwis
Terry Hancock schrieb:
> Is it possible to define some combination of __repr__, __str__,
> and/or __unicode__ so that the unicode() wrapper isn't necessary
> in this statement:

I'm not aware of a way of doing so.

> Or, put another way, what exactly does 'print' do when it gets
> a class instance to print? It seems to do the right thing if
> given a unicode or string object, but I cant' figure out how to
> make it do the same thing for a class instance.

It won't. PyFile_WriteObject checks for Unicode objects, and whether
the file has an encoding attribute set, and if so, encodes the
Unicode object.

If it is not a Unicode object, it falls through to PyObject_Print,
which first checks for the tp_print slot (which can't be set in
Python), then uses PyObject_Str (which requires that the __str__
result is a true byte string), or PyObject_Repr (if the RAW
flag isn't set - it is when printing). PyObject_Str first checks
for tp_str; if that isn't set, it falls back to PyObject_Repr.

> And I understand that I might want that if I'm working in
> an ASCII-only terminal.  But it's a big help to be able to
> read/recognize the labels when I'm working with localized
> encodings, and I'd like to save the extra typing if I'm
> going to be looking at a lot of these

You can save some typing, of course, with a helper function:

def p(o):
  print unicode(o)

I agree that this is not optimal; contributions are welcome.
It would probably be easiest to drop the guarantee that
PyObject_Str returns a true string, or use _PyObject_Str
(which does not make this guarantee) in PyObject_Print.
One would have to think what the effect on backwards
compatibility is of such a change.

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


Re: search and replace in a file :: newbie help

2006-09-10 Thread techie2go
thanks , i got it

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


Re: No ValueError for large exponents?

2006-09-10 Thread enigmadude
Georg Brandl wrote:
> enigmadude wrote:
> > As many have heard, IronPython 1.0 was released. When I was looking
> > through the listed differences between CPython and IronPython, the
> > document mentioned that using large exponents such as 10 **
> > 735293857239475 will cause CPython to hang, whereas IronPython will
> > raise a ValueError.
>
> What message does that value error have?
>
> If it's a memory issue, the operation should raise MemoryError (at
> least in CPython).
>
> Georg

I haven't run IronPython yet, but the "Differences" document says that
IronPython would raise a ValueError. It wasn't any more specific than
that. As far as CPython, I didn't wait long enough for it to raise a
MemoryError if it was going to raise one at all. From a user point of
view, CPython appeared to hang for about one minute, slowly raising CPU
usage and RAM usage, before I finally decided to just kill the process.
I don't know whether or not it would have completed 5 minutes later or
whether it would hang indefinitely, I haven't tested it. Although I may
be overreacting, I would wonder about the ramifications of something
like this hanging the interpreter (possible vector for DOS attack on an
webapp server, or even the machine itself if it balloons RAM usage?).
I'm not trying to be a doomsayer or anything, but I just want to know
how CPython handles extreme cases like this.

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