Re: Tk.quit() now working!

2006-01-31 Thread Mikael Olofsson
Fredrik Lundh wrote:
>>how do you run your Tkinter program ?

al pacino wrote:
> like? i was testing it in windows (interactive interpreter)

What Fredrik probably means is: Did you by any chance start it from 
IDLE? In that case it will not work. It doesn't for me. The reason - 
I've been told - is that IDLE itself is a tkinter application.

If you instead start it by simply double-clicking on its icon, as you 
would start anything else in Windows, it should work as expected. It 
does for me, on Win XP Pro.

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


Re: OT: Re: Using non-ascii symbols

2006-01-31 Thread Runsun Pan
>From 1387-1814, a ~430 years period, that's quite a long time.
About the total recountable history of Taiwan... :)

In her 400 some history Taiwan has been occupied by several
foreign powers, including Dutch, Tsing Dynasty from China, Japan,
and KMT party from China again. The long time fight against foreign
powers were all futile, resulted in a 'macro-personality' of getting used
to be slaves.

The mentality of being slaves is that when you have the chance to
play master yourself, you still look up to the old master to either get
approval or beg for mercy. This resulted in a bizzard situation in current
Taiwan that even a local-based, democratic government was elected,
the old foreign power is still the underground power that truly control
all aspects of Taiwan. They reject whatever policies the democratic
government plan. Many nation-wide constructions that the old power
planned and supported when they were in power, they turn their positions
into rejecting those them.

The slave mentality of the public is something that help those old power
to paralize the society. With that, a language reform to reduce the cultural
influence of the foreign power is therefore hopeless in Taiwan (at least
currently).

Maybe Norwegians have some sort of that mentality too ? Considering
that they rather to elect people from the old foreign power ...


On 1/29/06, Magnus Lycka <[EMAIL PROTECTED]> wrote:
> Runsun Pan wrote:
> > The simplified chinese exists due to the call for modernization of
> > language decades ago. That involved the 'upside-down' of almost
> > entire culture
> This is in some ways quite the opposite compared to Nynorsk
> in Norway, which was an attempt to revive the old and pure
> Norwegian, after being dominated (in politics as well as in
> grammar) by Denmark from 1387-1814. (I guess it was a
> complicating factor that the end of the union with Denmark
> led to a union with Sweden. The Norwegians probably had some
> difficulties deciding what neighbour they disliked most. When
> they broke out of the union with Sweden in 1905, they actually
> elected a Danish prince to be their king.) Anyway, only a
> fraction of the Norwegians use Nynorsk today, and the majority
> still speak the Danish-based bokmål. On the other hand, the
> spelling of bokmål has also been modernized a lot, with a
> series of spelling reforms of both languages.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread Christoph Zwerschke
thakadu schrieb:
> I have used PyMeld (http://www.entrian.com/PyMeld/) which is one of
> very few that gives a 100% separation of code and presentation, in fact
> PyMeld is not strictly speaking a template system at all.

Yes, it is more like XIST that I mentioned in another post.
The reason why this is slower than native templates seems clear: You 
convert the whole page to objects in memory, and then serialize 
everything back to HTML. If you are only filling in a few words, then 
native templates will be surely much more effective. But if you are 
messing around with the structure of your page, inserting and adding 
elements, then PyMeld will be probably a better way.

Here are two wiki pages listing template engines:

http://wiki.python.org/moin/WebProgramming
http://pythonwiki.pocoo.org/Template_Engines (German)

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


Re: triple quoted strings as comments

2006-01-31 Thread Duncan Booth
dmh2000 wrote:

> example
> 
> def fun(self):
>   """doc comment
>   comment line 2
>   """
> 
>   x = 1
>   y = 2
> 
>   """does this triple quoted string used as a  comment
>   cause something to happen at runtime beyond
>   just skipping over it? Such as allocation of memory for a string
>   or worse yet garbage collection? or not?
>   """
>   z = x + y
> 

How to find out for yourself:

>>> def fun(self):
  """doc comment
  comment line 2
  """

  x = 1
  y = 2

  """does this triple quoted string used as a  comment
  cause something to happen at runtime beyond
  just skipping over it? Such as allocation of memory for a string
  or worse yet garbage collection? or not?
  """
  z = x + y

  
>>> import dis
>>> dis.dis(fun)
  6   0 LOAD_CONST   1 (1)
  3 STORE_FAST   2 (x)

  7   6 LOAD_CONST   2 (2)
  9 STORE_FAST   1 (y)

 14  12 LOAD_FAST2 (x)
 15 LOAD_FAST1 (y)
 18 BINARY_ADD  
 19 STORE_FAST   3 (z)
 22 LOAD_CONST   3 (None)
 25 RETURN_VALUE
>>> 

Further inspection shows that it hasn't even saved that second string as a 
constant:

>>> print fun.func_code.co_consts
('doc comment\n  comment line 2\n  ', 1, 2, None)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beta.python.org content

2006-01-31 Thread Steve Holden
robin wrote:
> Steve Holden <[EMAIL PROTECTED]> wrote:
> 
> 
>>How does
>>
>>  http://beta.python.org/about/beginners/
>>
>>look?
> 
> 
> There are several things wrong with the interface.
> 
> First, I count seven ways of formatting a link. This is approximately
> five too many and can be fixed as follows.
> 
> "For Beginners" is italicised, supposedly to indicate it is the page
> we are currently on. This overloads the normal expected meaning of
> italics with something unexpected. And what is the point of a link to
> the current page? This should be plain text.
> 
> "About" is a top-level menu which has been expanded; to indicate this
> there is a yellow bar. This is not necessary since the viewer can see
> the menu is expanded. :-)
> 
> The menu items underneath an expanded heading should be in the same
> format, but offset. Same format says "menu"; offset says "child."
> 
> The last menu items are in different formats yet again (typeface and
> size). I see no reason for this.
> 
> Once this has been done there will be but two different ways of
> formatting a link: a menu and a link in the page body.
> 
> In terms of page space, the horizontal bar at the top seems wasted.
> Perhaps the vertical bar is all that is needed? The other elements
> could be relocated.
> 
> The menu is structured with a list and formatted with CSS. Good!
> 
> Given that there is already a hierarchical organisation of the content
> voa the collapsing menu bar, I do not think that another
> representation of this is required above the main page text. I would
> ditch the link trail.
> 
> Overall, the look is very "safe corporate". I myself would have gone
> for a funkier (though still elegant) look. The energy of the Python
> community is not being communicated. The vim of the language is
> diluted. This is not playing to Python's strengths.
> 
> Yes, i have been known to do this for a living. Had I been aware
> earlier, I would have been happy to help with the redesign. How can I
> now?
> 
I'm sure Tim Parkin will be happy to discuss this with you, as he is 
also involved on the design side.

I was mostly looking for content criticism, but anything that helps is a 
Good Thing.

> P.S. I am not averse to the new logo. It is professional, clean, and
> symbolic. Maybe there are more ideal choices but we have to get beyond
> little green cartoon snakes eventually.

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

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


Dr. Dobb's Python-URL! - weekly Python news and links (Jan 30)

2006-01-31 Thread Magnus Lycka
QOTW:  "[The state pattern] can be very confusing for newbies and peoples
having no experience with *dynamic* languages, and I guess control-freaks
and static-typing-addicts would runaway screaming.  But I like it anyway
!-)" - bruno desthuilliers

"[D]ubious Python hacks that should never be used in production code are
fun, which is what c.l.p. is all about!" - Michael Hoffman


After four years, the Roundup Issue Tracker version 1.0 is released.
Congratulations!
http://roundup.sourceforge.net/

The Myghty web and templating framework also reaches version 1.0.
"Myghty is a Python Server Page templating and web framework
designed for large-scale, high availability websites and
applications.  Its conceptual design and template syntax is derived
from HTML::Mason, the widely used mod_perl web application platform."
http://www.myghty.org/

The latest ActivePython release adds support for Mac OS X/x86, Windows/x64
and Linux/x86_64.
http://www.activestate.com/Products/ActivePython/

PyWeek, The Python Game Programming Challenge, returns.
http://www.pyweek.org/

How to have both a GUI event loop and a listener socket in
the same program...

http://groups.google.com/group/comp.lang.python/browse_frm/thread/13c10335c0a132a5

As Bruno said, some will probably run away screaming, but
you can actually change the class of an instance.

http://groups.google.com/group/comp.lang.python/browse_frm/thread/cb581d34561d266d

Sometimes there are several ways of doing very simple things,
such as picking out an item from a set with only one element.
Some ways are faster than others...

http://groups.google.com/group/comp.lang.python/browse_frm/thread/d0b74bdd22a58d0

Last week people used Python for sudoku. Now it's poker!

http://groups.google.com/group/comp.lang.python/browse_frm/thread/1a9bac6ae511c1c7

Is it time for unicode in Python operators and names yet?

http://groups.google.com/group/comp.lang.python/browse_frm/thread/5f4cb622ffa9316a

Python continues to be a good "choice for beginners."
http://www.ariel.com.au/a/teaching-programming.html

How do we know if there is any input for us in sys.stdin?

http://groups.google.com/group/comp.lang.python/browse_frm/thread/6fd2168cde0fd89a



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a w

Re: Collecting IP range

2006-01-31 Thread Heiko Wundram
yawgmoth7 wrote:
> Well, since range() won't take a normal IP(Such as 127.0.0.1). and,
> you can't take it as 127001(Since socket.connect() won't take that).
> What would you suggest as a better way to approach this?

Use a recipe for that. Have a look at:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466286
and
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466298

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


test whether 2 objects are equal

2006-01-31 Thread Yves Glodt
Hello,


I need to compare 2 instances of objects to see whether they are equal 
or not, but with the code down it does not work (it outputs "not equal")


#!/usr/bin/python

class Test:
var1 = ''
var2 = ''

test1 = Test()
test1.var1 = 'a'
test1.var2 = 'b'

test2 = Test()
test2.var1 = 'a'
test2.var2 = 'b'

if test1 == test2:
print "equal"
else:
print "not equal"




What am I doing wrong...?


best regards,
Yves


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


Re: Costly object creation (was : Having Trouble with Scoping Rules)

2006-01-31 Thread bruno at modulix
Charles Krug wrote:
> List:
> 
> I've a module that's not doing what I expect.  My guess is that I don't
> quite understand the scoping rules the way I should.
> 
> I have an object that's costly to create.  My thought was to create it
> at the module level like this:

(snip)

> What's the correct way to do this?
> 
See other answers in this thread for how to solve the UnboundLocalError
problem.

Now about your *real* problem - which is nothing new -, you may want to
read about some known solutions:

http://en.wikipedia.org/wiki/Singleton_pattern
http://en.wikipedia.org/wiki/Proxy_pattern
http://en.wikipedia.org/wiki/Lazy_initialization
http://en.wikipedia.org/wiki/Memoization

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


Request for suggesstions and comments

2006-01-31 Thread Vivek Kumar
Hi all,

 I have to write a network server (sort of) and I am
looking for your valuable comments. Currently I have
written a prototype in VB6 but it can only handle up
to 30 or so clients. I need to upgrade the application
so that it can handle up to 1000-1500 clients at a
time (later if every thing works fine then hoping for
5000-6000 client). The scenario is as follows.

1. An server application (above mentioned app) will be
listening on a particular port for client connection.
The client will be connecting to it using TCP
protocol.
2. The server will be continuously sending a trigger
pulse to all the clients connected on this port (say
every 3 sec).
3. Each client (in my case another app written in VB6)
will be sending a string of approx. 70-75 chars every
1 sec.
4. Each string will contain a start and an end char.

5. Each string will contain some data eg. first 4 char
acc. id, next 10 char user name etc.

6. As the data may come in small chunks (due to the
nature of network and buffering), it will be the
server's responsibility to buffer incoming data and
look for valid strings in buffer.

7. Once the server software find a valid string in
buffer, it should extract the valid string from the
buffer and parse it (extract the data in the string)
and insert into a database server with timestamps (in
my case SQL Server 2k).

8. The server will also have to send the valid string
to two other ports (one for showing status in GUI) and
second to a remote client which will further parse the
data and do some processing on the data (currently
written in VB). There can be around 20-30 such
clients. For GUI there will be around 5-10 clients.

9. The remote clients to whom the valid string is
being sent can also send some data to be sent back to
the clients from whom we are receiving data per sec.
For this the remote client will send data to the
server and the servers responsibility will be again to
parse this data and send it to the appropriate client
on the other side. This string can also be intended
for broadcasting, in that case we may need to send
data to all the clients on other side.

This is a general view for the application. Now here
are the issues on which I am requesting your comments
and suggestions.

Q. Is it possible to write an application for this
kind of server activity in Python? I mean whether
Python will be suitable for this kind of high activity
load, real time app?

Q. How much time it can take (approx.) to develop such
kind of server?

Q. Do we need multi threading? If so, then whether the
Socket modules will be safe to use with multi
threading?

Q. What modules for networking (socket ?), database
access etc should I use?

Currently as I am just planning about the solutions so
I don't have much of questions in my mind. But if it
is possible to write this kind of app in Python easily
(relative to C family of language ;) , then surely I
will have some more questions for experts out there ;)
.

As for me, I have written some small scripts in
Python. I have used Tk for GUI, PostgreSQL and Mysql
for my Database, some CGI programming with apache,
reporting using reportlab. But that was a long time
back (some 2 yrs back). After that I joined one
organization working on M$ platforms. So, since then I
am working in VB6 only. But I am confident that after
7-10 days of study I can again start working with
Python (Which is of course my favorite language :) .

Eagerly waiting for your comments and suggestions.

TIA,
Vivek Kumar




__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beta.python.org content

2006-01-31 Thread Fredrik Lundh
"robin" wrote:

> Overall, the look is very "safe corporate". I myself would have gone
> for a funkier (though still elegant) look. The energy of the Python
> community is not being communicated. The vim of the language is
> diluted. This is not playing to Python's strengths.
>
> Yes, i have been known to do this for a living. Had I been aware
> earlier, I would have been happy to help with the redesign. How
> can I now?

you can either try joining the beta.python.org cathedral (good luck), or drop by
the skunkworks (http://effbot.org/zone/pydotorg.htm) and help me whip together
some nice templates.

(if I could pick a style, I'd go for something that has some visual connection 
to the
existing site style, but reworked for 2006 and today's Python universe).

 



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


finding the intersection of a list of Sets

2006-01-31 Thread Suresh Jeevanandam
I have a list of sets in variable lsets .

Now I want to find the intersection of all the sets.

r = lsets[0]
for s in r[0:]:
r = r & s

Is there any other shorter way?

Thanks in advance,
Suresh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: test whether 2 objects are equal

2006-01-31 Thread Fredrik Lundh
Yves Glodt wrote

> I need to compare 2 instances of objects to see whether they are equal
> or not, but with the code down it does not work (it outputs "not equal")
>
> #!/usr/bin/python
>
> class Test:
> var1 = ''
> var2 = ''
>
> test1 = Test()
> test1.var1 = 'a'
> test1.var2 = 'b'
>
> test2 = Test()
> test2.var1 = 'a'
> test2.var2 = 'b'
>
> if test1 == test2:
>print "equal"
> else:
>print "not equal"
>
> What am I doing wrong...?

you haven't told Python how you want Test instances to be compared.

http://docs.python.org/ref/comparisons.html

http://docs.python.org/ref/customization.html
(look for __lt__ etc, as well as __cmp__ )

 



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


Re: A simple question string.replace

2006-01-31 Thread bruno at modulix
Haibao Tang wrote:
> I have a two-column data file like this
> 1.12.3
> 2.211.1
> 4.31.1
> ...
> Is it possible to substitue all '1.1' to some value else without using
> re.

I suppose that you don't want '11.1' to be affected.

raw_data="""
1.12.3
2.211.1
4.31.1
"""

data = filter(None, [line.strip().split() \
 for line in raw_data.split('\n')])
processed = [[item == '1.1' and 'X.X' or item for item in pair] \
  for pair in data]
result = "\n".join(["\t".join(pair) for pair in processed])

Not sure this is the fastest solution...

BTW, may I ask why you don't want to use regexp ?


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


Re: Marked-Up Text Viewer for Python/Tkinter

2006-01-31 Thread Eric Brunel
On Mon, 30 Jan 2006 15:20:50 -0800, James Stroud <[EMAIL PROTECTED]> wrote:

> Hello All,
>
> I'm wondering if there is something that already exists that can take  
> marked up text in some format (hopefully reStructuredText or HTML) and  
> can convert it into something that can be displayed with Tkinter (maybe  
> with Text), either dynamically or otherwise. Minimal functionality would  
> be simple formatting and hyperlink callbacks.

I'd say you could what you want within the (now apparently dead) Grail web  
browser at:
http://grail.sourceforge.net/
since it is written in Python and uses Tkinter for its GUI.

Unfortunately, their download link seems to be dead. Maybe you can get it  
somewhere else?

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Marked-Up Text Viewer for Python/Tkinter

2006-01-31 Thread Claudio Grondi
Eric Brunel wrote:
> On Mon, 30 Jan 2006 15:20:50 -0800, James Stroud <[EMAIL PROTECTED]> wrote:
> 
>> Hello All,
>>
>> I'm wondering if there is something that already exists that can take  
>> marked up text in some format (hopefully reStructuredText or HTML) 
>> and  can convert it into something that can be displayed with Tkinter 
>> (maybe  with Text), either dynamically or otherwise. Minimal 
>> functionality would  be simple formatting and hyperlink callbacks.
> 
> 
> I'd say you could what you want within the (now apparently dead) Grail 
> web  browser at:
> http://grail.sourceforge.net/
> since it is written in Python and uses Tkinter for its GUI.
> 
> Unfortunately, their download link seems to be dead. Maybe you can get 
> it  somewhere else?
> 
> HTH
via
   http://sourceforge.net/project/showfiles.php?group_id=6416
   http://prdownloads.sourceforge.net/grail/grail-0.6.tgz?download
e.g. at
   http://heanet.dl.sourceforge.net/sourceforge/grail/grail-0.6.tgz


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


Re: Newbie question: Unicode hiccup on reading file i just wrote

2006-01-31 Thread Darcy
Fredrik Lundh wrote:
> Diez B. Roggisch wrote:
>>Just don't do any fancy encoding stuff at all, a simple
>>rrr=xml.dom.minidom.parseString(open("tt.xml").read())
>>should do.
> or
> rrr = xml.dom.minidom.parse("tt.xml")

thanks a lot guys -- both approaches work a treat.

in particular: diez, thanks for explaining what was going on from 
python's perspective
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding the intersection of a list of Sets

2006-01-31 Thread Peter Otten
Suresh Jeevanandam wrote:

> I have a list of sets in variable lsets .
> Now I want to find the intersection of all the sets.
> 
> r = lsets[0]
> for s in r[0:]:
> r = r & s

Try to post working examples.

> Is there any other shorter way?

>>> sets = map(set, "abc bcd cde".split())
>>> reduce(set.intersection, sets)
set(['c'])

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


Re: test whether 2 objects are equal

2006-01-31 Thread Rene Pijlman
Yves Glodt:
>I need to compare 2 instances of objects to see whether they are equal 
>or not, 

This prints "equal":

class Test(object):
def __init__(self):
self.var1 = ''
self.var2 = ''
def __eq__(self,other):
return self.var1 == other.var1 and self.var2 == other.var2

test1 = Test()
test1.var1 = 'a'
test1.var2 = 'b'

test2 = Test()
test2.var1 = 'a'
test2.var2 = 'b'

if test1 == test2:
print "equal"
else:
print "not equal"

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Marked-Up Text Viewer for Python/Tkinter

2006-01-31 Thread Fuzzyman
I've played with grail. It does still work (basically).

I needed to put the grail directory in my ``site-packages`` folder and
create a 'grail.pth' file with the entry ``grail``.

Extracting the Tkinter widget, and exposing an API, would be tricky -
but I'm sure lots of people would use it. It's only HTML 2 though.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Unicode strings and ascii regular expressions

2006-01-31 Thread Fuzzyman

Fredrik Lundh wrote:
> Fuzzyman wrote:
>
> > Can someone confirm that compiled regular expressions from ascii
> > strings will always (and safely) yield unicode values when matched
> > against unicode strings ?
[snip..]
>
> ascii patterns work just fine on unicode strings.  the engine doesn't care
> what string type you use for the pattern, and it always returns slices of
> the target string, so you get back what you pass in.
>

Thanks - that's what I hoped. :-)

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 

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


Re: VB to Python migration

2006-01-31 Thread Magnus Lycka
Josh wrote:
> I understand what you are saying, and I'm sure the tasks our program 
> does could be made much cleaner. But, implementing an ERP which is 
> basically what we have, is a large project and the users need (or maybe 
> just want) access to lots of information.

I'm not pretending to know what this system does in detail, but the
fact that you need to access a lot of information doesn't imply that
you need lots of different user interfaces. I think e.g. wordprocessors,
spreadsheet programs and SQL monitors etc are proof of that.

I suppose that you need to present a lot of differnt kinds of data,
and that you need to provide various search parameters etc for
different data sets, but this sounds like something that might be
very few screens that adapt to some kind of meta-data, perhaps XML
descriptions or small "configuration files" containing som simple
Python data structures and possibly input validation routines etc.
Maybe this information should even be in the database?

The problem arises if there is behavior in the application that
varies with data, but with Python, it's certainly possible to handle
that to some extent even if these screens are driven by database
content.

BTW, I guess DABO http://dabodev.com/ is intended just for this kind
of application, but I doubt it was ever used for a project of this
size, it's fairly new... Never used it myself...

Whatever you use for your user interface, I suggest that you use
a multi-tier approach, and a very thin user interface layer. In my
opinion that makes testing much easier. I'd recommend that you use
a proper test tool and employ a test-driven approach.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread Peter Hansen
Christoph Zwerschke wrote:
> thakadu schrieb:
> 
>>I have used PyMeld (http://www.entrian.com/PyMeld/) which is one of
>>very few that gives a 100% separation of code and presentation, in fact
>>PyMeld is not strictly speaking a template system at all.
> 
> Yes, it is more like XIST that I mentioned in another post.
> The reason why this is slower than native templates seems clear: You 
> convert the whole page to objects in memory, and then serialize 
> everything back to HTML. If you are only filling in a few words, then 
> native templates will be surely much more effective. But if you are 
> messing around with the structure of your page, inserting and adding 
> elements, then PyMeld will be probably a better way.

Unless I'm misremembering, PyMeld is special amongst the "total 
decoupling of code and presentation" crowd in that it does *not* convert 
the whole page to objects in memory, but instead performs its operations 
using regular-expression substitution, and serializing back to HTML is a 
trivial operation since it's already serialized.

I'm sure the extra overhead versus simple % substitution is noticeable, 
but I have to say I was surprised to hear that it was measured at two 
orders of magnitude slower.  I thought better performance (versus the 
"manipulate in-memory as DOM" approach) was one of its advantages.

-Peter

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


Re: templates

2006-01-31 Thread Richie Hindle

[Christoph]
> The reason why [PyMeld] is slower than native templates seems clear: You 
> convert the whole page to objects in memory, and then serialize 
> everything back to HTML.

[Peter]
> Unless I'm misremembering, PyMeld is special amongst the "total 
> decoupling of code and presentation" crowd in that it does *not* convert 
> the whole page to objects in memory, but instead performs its operations 
> using regular-expression substitution, and serializing back to HTML is a 
> trivial operation since it's already serialized.

Peter is right for PyMeld, Christoph is right for PyMeldLite (which is a
variant of PyMeld used by Spambayes, and only works with valid XHTML).

The performance of PyMeld therefore depends on how much work you make it do -
if you insert a couple of values into a page, it's very fast.  If you do lots
and lots of operations on the whole of a large page, it can be very slow
because it's doing complex regular expression operations on a large string.
(It works this way because two of its design goals were to only touch the
parts of the page you ask it to touch, and to work with arbitrary, possibly
invalid, HTML.)

Incidentally, I'm changing PyMeld's license from Sleepycat to BSD, making it
free for use in closed source projects.  (I'll get around to updating the
website RSN 8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Marked-Up Text Viewer for Python/Tkinter

2006-01-31 Thread André
James Stroud wrote:
> Hello All,
>
> I'm wondering if there is something that already exists that can take
> marked up text in some format (hopefully reStructuredText or HTML) and
> can convert it into something that can be displayed with Tkinter (maybe
> with Text), either dynamically or otherwise. Minimal functionality would
> be simple formatting and hyperlink callbacks.
>
> Any guidance or suggestions would be appreciated.
>
> Thank you in advance for your help.
>
> James
If you're willing to use wxPython instead of Tkinter, you could have
access to a simple browser class that supports a number of html tags
(but no styles).  

André

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


Re: Python vs C for a mail server

2006-01-31 Thread Antoon Pardon
Op 2006-01-30, Magnus Lycka schreef <[EMAIL PROTECTED]>:
> Donn Cave wrote:
>> If we give him credit for having some idea of what he's talking about,
>> then we could perhaps read his "encourages" as "makes trivially easy."
>> These two languages are in such different levels with introspection
>> that it seems kind of disingenuous to me to make this argument, frankly.
>
> My impression when I compare Python with e.g. Java is this:
> Java is designed to make to difficult to do the wrong thing.
> Python is designed to make it easy to do the right thing.

That seems to depend on which part of the community you are
talking to. Some do argue that some features shouldn't be
included in the language because the risk of bugs by those
who don't understand how to use it properly, is too high.

That even seems to be the way the BDFL feels about things.

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


Re: dynamic class instantiation

2006-01-31 Thread Ognen Duzlevski
Kent Johnson <[EMAIL PROTECTED]> wrote:
> Ognen Duzlevski wrote:
> > Say I got "page" as a string. How do I go about 
> > instantiating a class from this piece of information? To make it 
> > more obvious how do I create the page() class based on the "page" 
> > string I have? 

> Use getattr().

Hi Kent, this is exactly what I was looking for. I can't believe I didn't think
of getattr() myself! ;(

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


Re: test whether 2 objects are equal

2006-01-31 Thread Yves Glodt
Rene Pijlman wrote:
> Yves Glodt:
>> I need to compare 2 instances of objects to see whether they are equal 
>> or not, 
> 
> This prints "equal":

thank you!

Have a nice day,
Yves

> class Test(object):
> def __init__(self):
> self.var1 = ''
>   self.var2 = ''
> def __eq__(self,other):
>   return self.var1 == other.var1 and self.var2 == other.var2
> 
> test1 = Test()
> test1.var1 = 'a'
> test1.var2 = 'b'
> 
> test2 = Test()
> test2.var1 = 'a'
> test2.var2 = 'b'
> 
> if test1 == test2:
>   print "equal"
> else:
>   print "not equal"
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


backreference in regexp

2006-01-31 Thread Schüle Daniel
X-Enigmail-Version: 0.76.5.0
X-Enigmail-Supports: pgp-inline, pgp-mime
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello @all,

 >>> p = re.compile(r"(\d+) = \1 + 0")
 >>> p.search("123 = 123 + 0")

'search' returns None but I would expect it to
find 123 in group(1)

Am I using something that is not supported by Python
RegExp engine or what is the problem with my regexp?

Regards, Daniel

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


Re: backreference in regexp

2006-01-31 Thread Fredrik Lundh
Schüle Daniel wrote:

> Hello @all,
>
> >>> p = re.compile(r"(\d+) = \1 + 0")
> >>> p.search("123 = 123 + 0")
>
> 'search' returns None but I would expect it to
> find 123 in group(1)
>
> Am I using something that is not supported by Python
> RegExp engine or what is the problem with my regexp?

plus matches one or more instances of the previous item.  to make
it match a plug sign, you have to escape it:

p = re.compile(r"(\d+) = \1 \+ 0")





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

Re: Having Trouble with Scoping Rules

2006-01-31 Thread Charles Krug
On 2006-01-31, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> def ExpensiveObject():
> global _expensiveObject
> if _expensiveObject is None:
> _expensiveObject = "A VERY Expensive object"
> print "CREATED VERY EXPENSIVE OBJECT"
> return _expensiveObject
>
> if __name__ == "__main__":
> print _expensiveObject
> print ExpensiveObject()
> print ExpensiveObject()
> print ExpensiveObject()
>
> which prints
>
> None
> CREATED VERY EXPENSIVE OBJECT
> A VERY Expensive object
> A VERY Expensive object
> A VERY Expensive object
>
> and works perfectly fine if you import it from another module:
>

Ah, I had another error that broke it on import.  Testing with a
dictionary showed me the "creates another object" error.  Using a string
constant for that was just a "between the ears" problem that would have
shown me the error much quicker.

Thanks.

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


Help with XML-SAX program ... it's driving me nuts ...

2006-01-31 Thread mitsura
Hi,

I need to read a simle XML file. For this I use the SAX parser. So far
so good.
The XML file consist out of number of "Service" object with each object
a set of attributes.

I read through the XML file and for each "" entry I create a
new service object.
When I am in the "" part of the XML file and I encounter
"" then I store these attributes into a Python dictionary.
At the end of the "" tag I create the actual object and pass
the attributes directory to it.
The strange thing is that for some reason, the attributes for all the
objects are being updated. I don't understand why this happens.

I included the code and a example of the XML file (kd.xml)
The output should be:
Obj:  name2 attribs:  {}
Obj:  name attribs:  {attrib1, val1, atttrib1.1, val1.1}
Obj:  name1 attribs:  {attrib2, val 2}

but it is:
Obj:  name2 attribs:  {}
Obj:  name attribs:  {}
Obj:  name1 attribs:  {}

It's driving me nuts. I have spend hours going through this very simple
code, but I can't find what's wrong.
Any help is really very much appreciated.

With kind regards,

Kris
XML File (kd.xml):
"


  
name
label
/opt/OV/www/htdocs/ito_op/images/service.32.gif

  

1

 Attrib1
 Val1


 Attrib1.1
 Val1.1

  
  
name1
label1
/opt/OV/www/htdocs/ito_op/images/service.32.gif

  

1

 Attrib2
 val 2

  
  
name2
label2
/opt/OV/www/htdocs/ito_op/images/service.32.gif

  

1
  

"
Program:
"
import  sys
import  string
import  images
import  os
import  cStringIO
import  xml.sax


from wxPython.wx import *
from Main import opj
from xml.sax.handler import *
from xml.sax import make_parser

class ServiceObj:

def __init__(self,name):

# Serivce object properties
self.name = name
self.attributes = {}

class OpenSNXML(ContentHandler):

# Service Object Tags
inService   = 0
inServiceAttribute  = 0
inServiceName   = 0
inAttributeName = 0
inAttributeValue= 0


objName = ""
objLabel= ""

attribs = {}
attribName  = ""
attribValue = ""

def startElement(self, name, attrs):

if name == "Service":
self.inService = 1

if self.inService == 1:
if name == "Attribute":
print "Attribute start"
self.inServiceAttribute = 1

if name == "Name" and ( self.inServiceAttribute == 0 ):
self.inServiceName = 1

if name == "Name" and (self.inServiceAttribute == 1):
self.inAttributeName = 1

if name == "Value" and (self.inServiceAttribute == 1):
self.inAttributeValue = 1

def characters(self, characters):
if self.inServiceName == 1:
self.objName = self.objName + characters

if self.inAttributeName == 1:
#print "Attribute Name: ", characters
self.attribName = self.attribName + characters

if self.inAttributeValue == 1:
#print "Attribute Value: ", characters
self.attribValue = self.attribValue + characters

def endElement(self, name):
mD = 1

if name == "Service":

self.inService = 0

# If the object already exists, update the existing 
object
if AllServiceObjectsFromXMLFile.has_key(self.objName):
#print "Object: ", self.objName, " already 
defined in exists in
dir"
obj = AllServiceObjectsFromXMLFile[self.objName]
else:
obj = ServiceObj(self.objName)

obj.attributes = self.attribs

AllServiceObjectsFromXMLFile[self.objName] = obj

del obj

self.objName = ""
self.attribs.clear()

if name == "Attribute":
self.inServiceAttribute = 0
print "Attrib name: ", self.attribName
print "Attrib value: ", self.attribValue

self.attribs[self.attribName] = self.attribValue
self.attribName = ""
self.attribValue = ""

print "Attrib dir: ", self.attribs
print "Attribute stop"

if name == "Name":
self.inServiceName = 0
 

Re: Help with XML-SAX program ... it's driving me nuts ...

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

> I need to read a simle XML file. For this I use the SAX parser. So far
> so good. The XML file consist out of number of "Service" object with
> each object a set of attributes.

> The strange thing is that for some reason, the attributes for all the
> objects are being updated. I don't understand why this happens.

you're using the same dictionary for all Service elements:

obj.attributes = self.attribs

adds a reference to the attribs dictionary; it doesn't make a copy (if it
did, your code wouldn't work anyway).

changing

self.attribs.clear()

to

self.attribs = {} # use a new dict for the next round

fixes this.

> It's driving me nuts. I have spend hours going through this very simple
> code, but I can't find what's wrong.

simple?  fwiw, here's the corresponding ElementTree solution:

import elementtree.ElementTree as ET

for event, elem in ET.iterparse("kd.xml"):
if elem.tag == "Service":
d = {}
for e in elem.findall("Attribute"):
d[e.findtext("Name")] = e.findtext("Value")
print elem.findtext("Name"), d

(tweak as necessary)

 



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


Introspection with classes

2006-01-31 Thread Kirk McDonald
Me again! Same project as before, if you're playing along at home.

The Everything Engine model (which I am blatantly copying in my project) 
is that everything in the engine is a 'node,' and that every node can be 
stored to and read from the database. Since this is the backend for a 
website, minimizing hits on the database is a worthy goal. Thus, it is 
paramount that reading in any given subclass of the base 'Node' class 
take (optimally) one query. (A simple, yet fairly simple-minded design 
-- and my first stab at the problem -- would be to have each subclass 
read in its own data after calling its parent's -- or parents'! -- read 
method(s). This has the disadvantage of cluttering a lot of code with 
database queries and making it quite difficult to create new subclasses.)

Here's a rough sketch of what I'm doing at the moment. I've invested 
enough time into it at this point that I've totally lost track of 
whether it's a good idea, and I would please like someone to tell me.

Every node has certain attributes. In this outline, let's say these are 
the node's unique id number, its title, and the id number of its owner.

class Node:
 dbInfo = { 'title': ['node', 'title',""]
'owner_id' : ['node', 'owner_id', None] }

 def __init__(self):
 self.default()

 def default(self):
 self.node_id = None
 for k, v in self.dbInfo.items():
 setattr(self, k, v[2])

 def read(self, db, node_id):
 # construct a database query from the table/column info in
 # dbInfo

 def commit(self, db):
 # write the current values to the db

 def insert(self, db):
 # insert a new node using the current values

 def nuke(self, db):
 # remove the node from the db, then:
 self.default()

So, simple enough. (The real version has signifigantly more stuff going 
on, as well as a permission system, but I have elided these for the sake 
of clarity.) By doing that dance with dbInfo, I can easily subclass Node.

Say we want a new node that holds some text. We just need to add a new 
attribute like so:

class Document(Node):
 dbInfo = {}
 dbInfo.update(Node.dbInfo)
 dbInfo['content'] = ['docs', 'text', ""]

... and that's it. That's the whole Document class. (Well, the real 
version has a render method that takes the content, parses it in 
interesting ways, and writes it to the client, but that's simple, too.) 
The shortness of this class is why this strikes me as a good idea.

The other advantage is I can make use of multiple inheritance. First, 
say we have a class that just holds a dictionary:

class DictNode(Node):
 dbInfo = {}
 dbInfo.update(Node.dbInfo)
 dbInfo['stuff'] = ['dictnode', 'dict', {}]

(Assume a mechanism is provided to automatically pickle the dictionary, 
which there is.)

Now say I want a nodetype that's just a document with a dictionary 
attached. This is almost exactly how the User class is implemented: the 
document holds the user's "homenode," which is just a brief bio or 
whatever the user wants to put in there, and the dictionary holds the 
user's settings. They snap together like Legos. It looks just like this:

class User(Document, DictNode):
 dbInfo = {}
 dbInfo.update(Document.dbInfo)
 dbInfo.update(DictNode.dbInfo)

If the User class wanted its own attributes (say, a password), they 
would just get added to the end.

This is my third stab at the problem (the first was mentioned above, the 
second was basically the same as this but dbInfo was an instance 
variable instead of a class variable which, uh, was sort of dumb).

Coming from C++, I'm still wrapping my brain around Python's 
introspection abilties. Can I generalize this more? Am I missing some 
idiom or language feature that would benefit me? Where's my time machine?

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


Re: backreference in regexp

2006-01-31 Thread Schüle Daniel
thank you, I completely forgot that + is one of metacharacters

Regards, Daniel

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


File permissions script vs shell

2006-01-31 Thread jdlists
I'm running python on windows and have a program that watches a
directory and acts on files as they come into the directory.  After
processing is complete, i delete the file, or in this case attempt
to

In the script version I repeatedly get OSError exceptions stating
permission denied when trying to delete or rename

My exception print out...
Files system said no: [Errno 13] Permission denied:
u'D:\\Data\\00-0C-41-DD-87-E5.xml'

But i can go into the python shell and execute...

fileString = 'D:\\Data\\00-0C-41-DD-87-E5.xml'
import os
os.unlink(fileString)

and the file deletes fine

Any ideas?  This is on my development windows xp box and i'm the only
user.

Thanks
Jeff

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


Re: Costly object creation (was : Having Trouble with Scoping Rules)

2006-01-31 Thread Charles Krug
On 2006-01-31, bruno at modulix <[EMAIL PROTECTED]> wrote:
> See other answers in this thread for how to solve the UnboundLocalError
> problem.
>
> Now about your *real* problem - which is nothing new -, you may want to
> read about some known solutions:
>
> http://en.wikipedia.org/wiki/Singleton_pattern
> http://en.wikipedia.org/wiki/Proxy_pattern
> http://en.wikipedia.org/wiki/Lazy_initialization
> http://en.wikipedia.org/wiki/Memoization
>

No, I'm already quite certain that this is a Singleton--pythonically a
module-level instance of Something--I'm not thinking of it as "lazy
instantiated" 'cuz it's initialized at startup, but I suppose it
qualifies.

I considered using a Borg for this, but discarded the idea as "too
complicated for my needs--this will be easier to implement . . . "

Which I suppose it would be if I knew how correctly to use the "global"
keyword.

I don't need to restrict the actual class to One Instance so much as I'd
prefer that to be the default behavior.  I can't think of a reason why
I'd want to subclass this, so I can't say whether it makes sense to
Borg/Highlander/Singleton it or not.  For now, I'll Do The Simplest
Thing That Might Work and figure YAGNI (or IAGNI, I guess).

Thanks for the help.

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


Re: simple perl program in python gives errors

2006-01-31 Thread morris carre
[EMAIL PROTECTED] a écrit :
> I am a little annoyed at why such a simple program in Perl  is causing
> so much difficulty for python, i.e:
> 
> $a += 20 * 14;
> 
> print $a;
> 

a = 20 * 14
print a



where's the problem ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with XML-SAX program ... it's driving me nuts ...

2006-01-31 Thread mitsura
Thanks for the feedback!
I will certainly look at the elementtree stuff (I am new to Python so I
still need to find my way around)

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


Re: File permissions script vs shell

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

> I'm running python on windows and have a program that watches a
> directory and acts on files as they come into the directory.  After
> processing is complete, i delete the file, or in this case attempt
> to
>
> In the script version I repeatedly get OSError exceptions stating
> permission denied when trying to delete or rename
>
> My exception print out...
> Files system said no: [Errno 13] Permission denied:
> u'D:\\Data\\00-0C-41-DD-87-E5.xml'
>
> But i can go into the python shell and execute...
>
> fileString = 'D:\\Data\\00-0C-41-DD-87-E5.xml'
> import os
> os.unlink(fileString)
>
> and the file deletes fine
>
> Any ideas?  This is on my development windows xp box and i'm the only
> user.

did you close the file correctly after processing it ?

>>> f = open("somefile.txt", "w")
>>> import os
>>> os.remove("somefile.txt")
Traceback (most recent call last):
  File "", line 1, in ?
OSError: [Errno 13] Permission denied: 'somefile.txt'
>>> f.close()
>>> f = open("somefile.txt", "r")
>>> os.remove("somefile.txt")
Traceback (most recent call last):
  File "", line 1, in ?
OSError: [Errno 13] Permission denied: 'somefile.txt'
>>> f.close()
>>> os.remove("somefile.txt")
>>>

 



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


quoting strings

2006-01-31 Thread Michal Duda
Hi,

is any equivalent to perl "quotemeta" function in python?


I know that I can use this on string: r'\\test'
but I need to do this on the variable

Thanks in advance

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


Re: quoting strings

2006-01-31 Thread Fredrik Lundh
Michal Duda wrote:

> is any equivalent to perl "quotemeta" function in python?

s = re.escape(s)

> I know that I can use this on string: r'\\test'
> but I need to do this on the variable

your example is a string literal, which isn't really the same thing as
a RE pattern in Python.

 



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


Re: templates

2006-01-31 Thread has

Christoph Zwerschke wrote:
> thakadu schrieb:
> > I have used PyMeld (http://www.entrian.com/PyMeld/) which is one of
> > very few that gives a 100% separation of code and presentation, in fact
> > PyMeld is not strictly speaking a template system at all.
>
> Yes, it is more like XIST that I mentioned in another post.
> The reason why this is slower than native templates seems clear: You
> convert the whole page to objects in memory, and then serialize
> everything back to HTML.

PyMeld's not a good example to judge DOM-style templating by: the main
reason it's a poor performer is its implementation is very inefficient.
There's a couple of third-party redesigns kicking about the web if you
want to search for them; I've not tried them myself but I imagine
performance is one of the issues they address.

It is true that DOM-style templating engines will still tend to be a
bit slower at rendering than a macro-style templating engine even when
all else is equal, but that's a price you always pay for choosing a
dynamic over a static approach.

For example, I once did some quick-n-dirty comparisons for my own
HTMLTemplate engine [1] which is fairly well optimised pure Python
code, and reckon its performance on typical insertion and iteration
tasks is maybe 1/2 - 1/3 of Cheetah's. (IIRC, PyMeld ran up to 100x
slower in those particular tests due to its naive algorithms.)

OTOH, you have to remember that HTML rendering is only one small
component in the overall application, so you really have to consider
this against the performance of the rest of the application to know if
a 2-3x difference in rendering speed makes a significant difference or
not. Chances are the biggest bottlenecks will lie elsewhere. Besides,
if pedal-to-the-metal performance is your primary concern, you should
probably be writing everything in C++ anyway.


> If you are only filling in a few words, then
> native templates will be surely much more effective. But if you are
> messing around with the structure of your page, inserting and adding
> elements, then PyMeld will be probably a better way.

I dunno; DOM-style engines work fine even for simple jobs, while the
big macro-style engines can do a lot of fancy stuff too. I think the
major difference is that the DOM-style engines do things much more
simply. For example, HTMLTemplate's codebase, API and documentation are
maybe a tenth the size of Cheetah's. Rather than trying to provide
every possible feature users might ever want themselves (c.f.
Greenspun's Tenth Rule), they keep out of the way as much as possible
and let the original language provide for the user's needs.

HTH

--

[1] http://freespace.virgin.net/hamish.sanderson/htmltemplate.html

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


Re: triple quoted strings as comments

2006-01-31 Thread Jeffrey Schwab
Steve Holden wrote:
> dmh2000 wrote:
> 
>> I recently complained elsewhere that Python doesn't have multiline
>> comments.
> 
> 
> Personally I think it's a win that you couldn't find anything more 
> serious to complain about :-)

+1 QOTW
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: determinant

2006-01-31 Thread Tuvas
I am using Windows, using Python 2.4. Perhaps I just did the import
statement wrong? I've never installed a library in Windows before,
perhaps I did something wrong there too.. But anyways, it just doesn't
seem to work. The import statements were:

import Matrix, LinearAlgebra

Neither seem to work. Thanks for the help!

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


Re: test whether 2 objects are equal

2006-01-31 Thread bruno at modulix
Yves Glodt wrote:
> Hello,
> 
> 
> I need to compare 2 instances of objects to see whether they are equal
> or not, but with the code down it does not work (it outputs "not equal")
> 
> 
> #!/usr/bin/python
> 
> class Test:
> var1 = ''
> var2 = ''

Take care, this creates two *class* variables var1 and var2. For
*instance* variables, you want:

class Test:
  def __init__(self, var1='', var2=''):
self.var1 = var1
self.var2 = var2


> test1 = Test()
> test1.var1 = 'a'
> test1.var2 = 'b'

This creates instances variables var1 and var2 for test1 (shadowing
class variables).

(snip the rest, see other posts in this thread)

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


Re: determinant

2006-01-31 Thread Tuvas
Never mind, I realized I was using a bit of code way too old. I just
needed to change the import statements to:

import numpy.matrix
import numpy.linalg

Thanks for the help!

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


Re: about spawn flag

2006-01-31 Thread Sinan Nalkaya
thank you but also i need a pid.also react like an os.P_NOWAIT.
if i summarize,
child proccess immediately returns the pid, if child exits also
returns the exit/error code :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about spawn flag

2006-01-31 Thread Fredrik Lundh
Sinan Nalkaya wrote:

> thank you but also i need a pid.also react like an os.P_NOWAIT.
> if i summarize,
> child proccess immediately returns the pid, if child exits also
> returns the exit/error code :)

import subprocess

http://docs.python.org/lib/module-subprocess.html

 



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


Re: test whether 2 objects are equal

2006-01-31 Thread Yves Glodt
bruno at modulix wrote:
> Yves Glodt wrote:
>> Hello,
>>
>>
>> I need to compare 2 instances of objects to see whether they are equal
>> or not, but with the code down it does not work (it outputs "not equal")
>>
>>
>> #!/usr/bin/python
>>
>> class Test:
>> var1 = ''
>> var2 = ''
> 
> Take care, this creates two *class* variables var1 and var2. For
> *instance* variables, you want:

Thanks for making me aware. I'll have to read more about classes in 
python... ( As you can see I'm still new to it ;-)

btw, this is the best list I've ever joined, very helpful and nice ppl.

Have a nice day!
Yves

> class Test:
>   def __init__(self, var1='', var2=''):
> self.var1 = var1
> self.var2 = var2
> 
> 
>> test1 = Test()
>> test1.var1 = 'a'
>> test1.var2 = 'b'
> 
> This creates instances variables var1 and var2 for test1 (shadowing
> class variables).
> 
> (snip the rest, see other posts in this thread)
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Omniorb event channel question

2006-01-31 Thread Attila Rajmund Nohl
Hello!

I'm using python 2.3.5 on Linux with omniORB 2.6. I'm trying to create
an object that shall listen on an event channel, but the registration
doesn't work. My code is:

class EventListener(CosEventComm.PushConsumer):

def __init__(self):
pass

def push(self, data):
print data.typecode().kind()
print data.typecode().name()

def disconnect_push_consumer(self):
pass

[... initalize the ORB ...]

channel = orb.getRootInterface(channelname)
chadmin = channel.for_consumers()
supplier = chadmin.obtain_push_supplier()
listener = EventListener()
supplier.connect_push_consumer(listener)

Unfortunately I get the following error at this point:
omniORB.CORBA.BAD_PARAM  
Traceback (most recent call last)

test.py 
 70 supplier = chadmin.obtain_push_supplier()
 71 listener = EventListener()
---> 72 supplier.connect_push_consumer(listener)
 73 
 74 

CosEventChannelAdmin_idl.py
in connect_push_consumer(self, *args)
122 
123 def connect_push_consumer(self, *args):
--> 124 return _omnipy.invoke(self, "connect_push_consumer",
_0_CosEventChannelAdmin.ProxyPushSupplier._d_connect_push_consumer, args)
125 
126 __methods__ = ["connect_push_consumer"] + 
_0_CosEventComm._objref_PushSupplier.__methods__

BAD_PARAM: Minor: BAD_PARAM_WrongPythonType, COMPLETED_NO.

What am I missing? The ORB works otherwise.

Bye,NAR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File permissions script vs shell

2006-01-31 Thread jdlists
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > I'm running python on windows and have a program that watches a
> > directory and acts on files as they come into the directory.  After
> > processing is complete, i delete the file, or in this case attempt
> > to
> >
> > In the script version I repeatedly get OSError exceptions stating
> > permission denied when trying to delete or rename
> >
> > My exception print out...
> > Files system said no: [Errno 13] Permission denied:
> > u'D:\\Data\\00-0C-41-DD-87-E5.xml'
> >
> > But i can go into the python shell and execute...
> >
> > fileString = 'D:\\Data\\00-0C-41-DD-87-E5.xml'
> > import os
> > os.unlink(fileString)
> >
> > and the file deletes fine
> >
> > Any ideas?  This is on my development windows xp box and i'm the only
> > user.
>
> did you close the file correctly after processing it ?
>
> >>> f = open("somefile.txt", "w")
> >>> import os
> >>> os.remove("somefile.txt")
> Traceback (most recent call last):
>   File "", line 1, in ?
> OSError: [Errno 13] Permission denied: 'somefile.txt'
> >>> f.close()
> >>> f = open("somefile.txt", "r")
> >>> os.remove("somefile.txt")
> Traceback (most recent call last):
>   File "", line 1, in ?
> OSError: [Errno 13] Permission denied: 'somefile.txt'
> >>> f.close()
> >>> os.remove("somefile.txt")
> >>>
>
> 

That was correct...i started to see it just after posting, the open
file was hidden behind the 4Suite library via the FromUri method.
Reading the xml file as a string and passing it to fromString instead
and closing the file myself solved this.

Jeff

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


Re: templates

2006-01-31 Thread thakadu
I would like to give a few more specifics about my "benchmarking". The
web page had about 10  simple fields and a table of roughly 30 table
rows. The method of generation the table rows was exactly the same as
the example in the PyMeld documentation ie you create the Meld, you
make a copy of a prototypr row instance, you generate your new rows,
which may have replaceable fields inside them, and finally you replace
the single prototype row with all the new rows you have generated. The
same test using the same data with Cheetah and native templates
resulted in (on an oldish 600Mhz box):
PyMeld: +-300ms
Cheetah: +-30ms
Native %s: +- 5ms
On newer hardware obviously the times will be very different but this
particular application has to be able to scale to very large tables.
I did not try PyMeldLite because the HTML I am using is exactlty that:
HTML and not XHTML. Again I am not criticising PyMeld, I love its
simplicity and clean api and the code is easily understandable so I
will probably take a look at it again at some time. Also its great that
it works with any snippet of HTML code it does not even have to be
valid HTML and I get a lot of invalid HTML from the designers.
Regarding Cheetah, I was using Cheetah 1.0. There is a 2.0 Release
Candidate out but I didnt want to be using anything in RC status for a
production site.

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


Re: Omniorb event channel question

2006-01-31 Thread Diez B. Roggisch
> channel = orb.getRootInterface(channelname)
> chadmin = channel.for_consumers()
> supplier = chadmin.obtain_push_supplier()
> listener = EventListener()
> supplier.connect_push_consumer(listener)

Not sure, but I guess you want a 

listener._this()

here.

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


Re: simple perl program in python gives errors

2006-01-31 Thread Dan Lowe

On Jan 31, 2006, at 8:28 AM, morris carre wrote:

> [EMAIL PROTECTED] a écrit :
>>
>> $a += 20 * 14;
>> print $a;
>
> a = 20 * 14
> print a
>
> where's the problem ?

Not sure if you typo'd that, but that should read:

a += 20 * 14
print a

  -dan

-- 
I am not a vegetarian because I love animals; I am a vegetarian because
I hate plants.-A. Whitney Brown


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


Re: Fuzzy Lookups

2006-01-31 Thread Gregory Piñero
> Thanks for that, I'll have a look. (So many packages, so little
> time...)

Yes, there's a standard library for everything it seems!  Except for a
MySQL api :-(

> > I wrote a script to delete duplicate mp3's by filename a few years
> > back with this.  If anyone's interested in seeing it, I'll post a blog
> > entry on it.  I'm betting it uses a similiar algorithm your functions.
>
> I would be very interested it seeing that.

Done, see:
http://www.blendedtechnologies.com/removing-duplicate-mp3s-with-python-a-naive-yet-fuzzy-approach/60

If anyone would be kind enough to improve it I'd love to have these
features but I'm swamped this week!

- MD5 checking for find exact matches regardless of name
- Put each set of duplicates in its own subfolder.



>
>


--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread Richie Hindle

[thakadu]
> The method of generation the table rows was exactly the same as
> the example in the PyMeld documentation

Did you try using toFormatString() to speed it up?  See
http://www.entrian.com/PyMeld/doco.html

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding the intersection of a list of Sets

2006-01-31 Thread Raymond Hettinger
[Peter Otten]
> >>> sets = map(set, "abc bcd cde".split())
> >>> reduce(set.intersection, sets)
> set(['c'])

Very nice.  Here's a refinement:

>>> sets.sort(key=len)
>>> reduce(set.intersection, sets[1:], sets[0])
set(['c'])

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


Re: Mail Delivery (failure [EMAIL PROTECTED])

2006-01-31 Thread info
Hemos recibido su correo, en breve nos pondremos en contacto con ustedes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread has
thakadu wrote:
> I did not try PyMeldLite because the HTML I am using is exactlty that:
> HTML and not XHTML.

FWIW, HTMLTemplate is pretty lax and not restricted to XHTML. The only
XML-ish requirement is that elements need to be properly closed if
they're to be used as template nodes, e.g. ...
and , not ... and . Otherwise, it should cope with pretty much any old
markup as long as HTMLParser can make sense of it.

> and I get a lot of invalid HTML from the designers

You might consider throwing HTMLTidy  at
it.

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


Re: determinant

2006-01-31 Thread Raymond Hettinger
[Tuvas]
> I am trying to find a nice function that quickly determines the
> determanant in python. Anyone have any recommendations? I've heard
> about numpy, but I can't get it to work (It doesn't seem to like the
> import Matrix statement...). Thanks!

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

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


[no subject]

2006-01-31 Thread Thomas McGrath III
Hello,

I have a real newbie question here. New to Python, and am trying to  
learn it on  Mac and WinXP.

On the Mac I find Python already installed and I downloaded the  
package. I tested the version in Terminal by typing 'python' and get  
Python 2.3.5 (#1, Mar 20 2005, 20:38:20). - Looks fine to me.

On WinXP I open a command line and type 'python' and get 'PYTHON' is  
not recognized as an internal or external command,
operable program or batch file.

So I downloaded the Python 2.4.2 install package and installed it in XP.

I go to a command line prompt and type 'python' and still get the  
error. - not good.

However if I execute the python.exe as found in the download folder I  
get python in a command line looking window. But not at the regular c  
prompt.

If I drag the python.exe to the command line C:\DOCUME~1\THOMAS~1> it  
then gives me the correct 2.4.2 info.

I expected after the install that at the regular prompt I could type  
'python' and it would show up like on the mac side.

Is this normal or did I do something wrong during install?

Any newbie help is appreciated,

Tom



Thomas J McGrath III
[EMAIL PROTECTED]

Lazy River Software™ - http://www.lazyriversoftware.com

Lazy River Metal Art™ - http://www.lazyriversoftware.com/metal.html

Meeting Wear™ - http://www.cafepress.com/meetingwear

Semantic Compaction Systems - http://www.minspeak.com

SCIconics, LLC - http://www.sciconics.com/sciindex.html







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


Re: indentation messing up my tuple?

2006-01-31 Thread infidel
tuple is the name of the built-in type, so it's not a very good idea to
reassign it to something else.

(food + drink + '\n') is not a tuple, (food + drink + '\n',) is

There's no reason to use tuples here, just do this:

data.append(food + drink)
f.write('\n'.join(data))

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


Question about idioms for clearing a list

2006-01-31 Thread Steven Watanabe
I know that the standard idioms for clearing a list are:

  (1) mylist[:] = []
  (2) del mylist[:]

I guess I'm not in the "slicing frame of mind", as someone put it, but 
can someone explain what the difference is between these and:

  (3) mylist = []

Why are (1) and (2) preferred? I think the first two are changing the 
list in-place, but why is that better? Isn't the end result the same?

Thanks in advance.
--
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templates

2006-01-31 Thread thakadu
Yes I looked at that but I did not benchmark it. Basically it seems to
convert the Meld or part of a Meld into a %s template in any case and I
already knew that %s performace was very good. So if I had used PyMeld
combined with %s then sure it would be much faster but I wanted to
benchmark a pure PyMeld approach against a pure %s approach.

You are right thought that this could significantly speed things up if
one was prepared to use a dual approach (less clean but I would still
use it if it was convenient).

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


Re: Python vs C for a mail server

2006-01-31 Thread Randall Parker
Alex Martelli wrote:

> The "but without declaration it can't be self-documenting" issue is a
> red herring.  Reading, e.g.:
>
> int zappolop(int frep) { ...
>
> gives me no _useful_ "self-documenting" information about the role and
> meaning of frep, or zappolop's result.  The code's author must obviously
> add a little comment here to clarify -- and in that little comment,
> adding the information about type, if at all relevant, is an obvious
> task.

Yes, one can use such simple types that the types do not tell you that
much. They do tell you something though. The arg and return types are
not list structures for example. They aren't floats either.

However, C/C++ at least provide a way to make types tell you far more.
For example, one could declare enum types:

typedef enum MyArgType
{
   // a bunch of enum const names here
} MyArgType;
typedef enum MyResultType
   // another bunch of enum const names
} MyResultType;

Then your example above becomes

MyResultType zappolop(MyArgType frep) { ...

 and that's a lot more insightful.

I return objects in Python and in C++. In C++ I can see what their
types are right on the m method signature. In Python I've got to write
a comment on the line above it. If I change what type I return and
forget to change the comment then the code isn't correctly documented
anymore. I've done recently and found out with a runtime error while
testing the Python. In C++ if I'd changed the return type the compiler
would have told me if I didn't use it that way somewhere else.

There are a lot of stages at which to reduce the chance of bugs. While
coding an editor can give you more help with code completion if you
have more static typing. At compile time the compiler can tell you
about errors if it knows the types you are using.

I use PyChecker and PyLint and while they are incredibly helpful (and
I'm grateful to their authors just as I am to Python's developers) they
do not tell me as much as Borland's C++ compiler does. I get more
runtime errors with my Python code than with my C++ code.

Still, I find Python useful and better than C++ in some situations.
But I wish it provided better options for allowing me to indicate types
so that more errors could get caught sooner and so that editor code
completion could be smarter.

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


psycopg2

2006-01-31 Thread Jane Goldman

Hello,

I bigginer Python programmer. I am working on web application that access 
PostgreSQL on backend. After I imported PSYCOPG2 module in my program I 
started to get unwanded debug output into my web bowser. It is something 
like that:


initpsycopg: initializing psycopg 2.0b6.2 (dec dt ext pq3) typecast_init: 
initializing NUMBER typecast_new: new type at = 00962920, refcnt = 1 
typecast_new: typecast object created at 00962920 typecast_add: object at 
00962920, values refcnt = 2 typecast_add: adding val: 20 typecast_add: 
adding val: 23 typecast_add: adding val: 21 typecast_add: adding val: 701 
typecast_add: adding val: 700 typecast_add: adding val: 1700 typecast_add: 
base caster:  typecast_init: initializing LONGINTEGER typecast_new: 
new type at = 00962960, refcnt = 1 typecast_new: typecast object created at 
00962960 typecast_add: object at 00962960, values refcnt = 2 typecast_add:


and so on ...

I use Cheetah template to generate HTML code. I run Active python 2.4 in 
Windows XP enviroment.


Any help how to stop get this garbage in my web browser would be highly 
appreciated.


_
Powerful Parental Controls Let your child discover the best the Internet has 
to offer.  
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
 Start enjoying all the benefits of MSN® Premium right now and get the 
first two months FREE*.


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

Re: Question about idioms for clearing a list

2006-01-31 Thread Tim Chase
> I know that the standard idioms for clearing a list are:
> 
>   (1) mylist[:] = []
>   (2) del mylist[:]
> 
> I guess I'm not in the "slicing frame of mind", as someone put it, but 
> can someone explain what the difference is between these and:
> 
>   (3) mylist = []
> 
> Why are (1) and (2) preferred? I think the first two are changing the 
> list in-place, but why is that better? Isn't the end result the same?

A little example will demonstrate:

>>> x = [1,2,3,4,5]
>>> y = x
>>> z = x
>>> x = []
>>> y
[1, 2, 3, 4, 5]
*   >>> z
[1, 2, 3, 4, 5]
>>> y[:]=[]
*   >>> z
[]

[*] note the differences in the results of "z", even though we've 
never touched "z" explicitly

By using

x = []

you set x, but you do not clear the list that other items (y & z) 
reference.  If you use either of the two idioms you describe, you 
effect all items that reference that list.

-tim




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


Re: path to python in WinXP

2006-01-31 Thread Tim Chase
> I have a real newbie question here. 

Well, as a starter, it would be helpful if you included a 
Subject: line in your mail...my spam filters flagged it and I 
almost tossed it in my bit-bucket because the subject was empty. :*)

> On WinXP I open a command line and type 'python' and get 'PYTHON' is  
> not recognized as an internal or external command,
> operable program or batch file.
> 
> So I downloaded the Python 2.4.2 install package and installed it in XP.
> 
> I go to a command line prompt and type 'python' and still get the  
> error. - not good.

The general problem is that in your cmd.exe/command.com 
environment, you don't have your PATH variable set up to point to 
the location in which the python executable is found.

If you want to do it for a single dos session, you can do the 
following:

   c:\> path %path%;c:\path\to\python\exe

This will add the location of the python exe (in this example, 
it's in "c:\path\to\python\exe" folder...adjust accordingly for 
your install) to your path.

For a more persistant solution, go to your system properties and 
dig around for the "Environment variables" button.  I've got 
Win2k here, not XP, so I don't know the exact sequence, but here 
it is on Win2k

winkey+break   (pulls up the system properties)
"advanced" tab
"environment variables" button

On that screen, you should see the "Path" in the "System 
variables" list.  Edit it to include the above path to your 
python binaries.  Start a new command-prompt.

Voila!

Alternatively, instead of running python directly, you should 
also be able to run

c:\> start python

which will likely start it in a new window.

-tim





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


Re: templates

2006-01-31 Thread thakadu
I haven't got around to trying HTMLTemplate yet but it is on my list of
things to do. It would be great to see how it compares in perfomance
and simplicity to PyMeld and other DOM approaches.

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


Re: Python vs C for a mail server

2006-01-31 Thread Randall Parker
Jay,

The point of doing compile time and test time checking is the same
reason militaries use layered defenses: More problems get caught. I've
written tons of software tests and architected a testing system for an
entire aircraft. I've also watched lots of errors get by tests.

Also, compile time errors get caught sooner. They get caught before
tests even get written.

Plus, tests become just another layer that needs testing. They also
become another layer that can get out of synch with the rest of the
software.

As for casting away type safety: Sure, you can make C/C++ type unsafe.
But that's optional. You can use the type safety if you want to. Most
peope use the compiler's type checking because it is more effort to
cast away type checking than it is to use it.

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


Re: StringIO proposal: add __iadd__

2006-01-31 Thread Raymond Hettinger
[Raymond Hettinger]
> > The StringIO API needs to closely mirror the file object API.
> > Do you want to change everything that is filelike to have +=
> > as a synonym for write()?

[Paul Rubin]
> Why would they need that?

Polymorphism

> StringIO objects have getvalue() but other
> file-like objects don't.  What's wrong with __iadd__ being another
> StringIO-specific operation?

The getvalue() method isn't a synonym for another method in the file
object API. Its design capitalizes on properties unique to StringIO
(direct access to the full buffer without rewinding the file pointer).

In contrast, the __iadd__() method is a synonym for write(). Its use
cases are the same for both StringIO and file objects.

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


Re: finding the intersection of a list of Sets

2006-01-31 Thread Raymond Hettinger
That should have been:

>>> sets.sort(key=len)
>>> reduce(set.intersection, sets)

The only refinement was the pre-sort based on set length.

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


Re: Python vs C for a mail server

2006-01-31 Thread Peter Hansen
Randall Parker wrote:
> The point of doing compile time and test time checking is the same
> reason militaries use layered defenses: More problems get caught. I've
> written tons of software tests and architected a testing system for an
> entire aircraft. I've also watched lots of errors get by tests.

Hmm... with that analogy, I would have to say that most people who 
strongly advocate static typing and compiler tests are really relying 
solely on their perimeter guards.  They seem to think that provides 
sufficient defense, and forget to finish the fortress walls.  That is, 
they often don't do adequate tests.

Those of us who have really strong fortress walls might sometimes be 
willing to forego the perimeter guard, perhaps unwisely, but at least we 
know immediately when we're under attack.

> Plus, tests become just another layer that needs testing. They also
> become another layer that can get out of synch with the rest of the
> software.

Not if you are doing test-driven development, at least.  In that case by 
definition if you're out of sync, it's the code which is failing the 
test because the test defines what the code should be doing.

-Peter

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


Re: Question about idioms for clearing a list

2006-01-31 Thread Diez B. Roggisch
Steven Watanabe wrote:

> I know that the standard idioms for clearing a list are:
> 
>   (1) mylist[:] = []
>   (2) del mylist[:]
> 
> I guess I'm not in the "slicing frame of mind", as someone put it, but
> can someone explain what the difference is between these and:
> 
>   (3) mylist = []
> 
> Why are (1) and (2) preferred? I think the first two are changing the
> list in-place, but why is that better? Isn't the end result the same?

No. Consider this simple example:

class Foo(object):
   def __init__(self, all_my_thingies):
   self.all_my_thingies = all_my_thingies


things = [1,2,3,4,5]

f = Foo(things)

things = [] # I've been robbed

print f.all_my_thingies # or not?


The reason is that l = [] just rebinds a new object (a list, but it could be
anything) to a name, while l[:] = [] will alter the object _referred_ to by
l. That is a HUGE difference!


Diez



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


PyGILState_Release + Python2.3 = Segmentation Fault

2006-01-31 Thread Kirill Simonov
Hi,

Could someone tell me why my extension module works under Python 2.4, but 
fails with Segmentation Fault under Python 2.3? Here is the stripped version:


#include 

static PyObject *
test_gil(PyObject *self)
{
PyGILState_STATE gs;

Py_BEGIN_ALLOW_THREADS

gs = PyGILState_Ensure();

PyGILState_Release(gs);

Py_END_ALLOW_THREADS

Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef test_gil_methods[] = {
{"test_gil", (PyCFunction)test_gil, METH_NOARGS},
{NULL}
};

PyMODINIT_FUNC
init_test_gil(void) {
(void)Py_InitModule("_test_gil", test_gil_methods);
}
===

I've tested it with Debian Sid and Ubuntu Breezy.

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


Re: Python vs C for a mail server

2006-01-31 Thread Jay Parlar

Randall Parker wrote:
> Alex Martelli wrote:
>
>> The "but without declaration it can't be self-documenting" issue is a
>> red herring.  Reading, e.g.:
>>
>> int zappolop(int frep) { ...
>>
>> gives me no _useful_ "self-documenting" information about the role and
>> meaning of frep, or zappolop's result.  The code's author must 
>> obviously
>> add a little comment here to clarify -- and in that little comment,
>> adding the information about type, if at all relevant, is an obvious
>> task.
>
> Yes, one can use such simple types that the types do not tell you that
> much. They do tell you something though. The arg and return types are
> not list structures for example. They aren't floats either.
>
> However, C/C++ at least provide a way to make types tell you far more.
> For example, one could declare enum types:
>
> typedef enum MyArgType
> {
>// a bunch of enum const names here
> } MyArgType;
> typedef enum MyResultType
>// another bunch of enum const names
> } MyResultType;
>
> Then your example above becomes
>
> MyResultType zappolop(MyArgType frep) { ...
>
>  and that's a lot more insightful.
>
Except once a type starts to get a little bit complicated, you're not 
going to be able to "keep it in your head", and you'll have to go back 
to the C++ definition of the type anyway when you want to know what it 
does. Much like you'd have to go back to the Python source of a class. 
(This is of course assuming that you put a comment in your Python code 
saying that a certain kind of class is expected. I find it's obvious 
about 80% of the time what's expected).


> I return objects in Python and in C++. In C++ I can see what their
> types are right on the m method signature. In Python I've got to write
> a comment on the line above it. If I change what type I return and
> forget to change the comment then the code isn't correctly documented
> anymore. I've done recently and found out with a runtime error while
> testing the Python. In C++ if I'd changed the return type the compiler
> would have told me if I didn't use it that way somewhere else.

Yeah, but you can't *just* change the type you're returning, and expect 
to be done. You'll also have to change the source code of the function 
to actually return something of that type. And you'll have to change 
all the places where the function is called, to make sure that the 
caller is storing the result in an appropriately typed variable.

Often times in Python, the thing you're returning is useful because of 
duck-typing, not because it's actually of a particular class. Maybe in 
some piece of code, you're returning a file() object, and all the 
callers really care about is the ability to do a read() and write() on 
that object.

Maybe later in the lifecycle of your program, you no longer store 
things in the filesystem directly, but in a database. You'd have to 
change your function such that it no longer returns a file() object, 
but some object that instead is connecting to a database. But you still 
only need to call read() and write() on it.

Well guess what: The *only* code you'll have to change is inside the 
function returning the object, none of the callers would have to 
change. That's completely different from C++, where you'll have to 
change not only the return type and the function, but you'll also have 
to change every single calling function to be aware of this new db 
object. And not just how the callers store the returned object, but 
also how they use that object. That's a LOT of work, for really no 
gain.

And that's the ENTIRE point (as I see it) of the Python typing system. 
Usually you know what you want to do, and you shouldn't have to fight 
to do it.

If you haven't heard the term "duck typing" before, Wikipedia has a 
decent page on it, and a simple Google search will return many more 
results.

> There are a lot of stages at which to reduce the chance of bugs. While
> coding an editor can give you more help with code completion if you
> have more static typing. At compile time the compiler can tell you
> about errors if it knows the types you are using.
>

Yeah, but it can only tell you about type errors, and those aren't 
really critical. They're the kind of error that takes a second to fix 
when found. Yet *how much* time is often spent fighting with a compiler 
to make it accept the types you actually want to use?

> I use PyChecker and PyLint and while they are incredibly helpful (and
> I'm grateful to their authors just as I am to Python's developers) they
> do not tell me as much as Borland's C++ compiler does. I get more
> runtime errors with my Python code than with my C++ code.
>

That's to be expected, but the time needed to get to a runtime error is 
so much less in Python (especially if you've got good unit/integration 
tests). I recommend you bring IPython into your development tools, so 
you can easily import small parts of your code and hand test them in 
isolation.

> Still, I find Python useful and better

Unicode Support for ConfigObj (config file reader) Now in SVN

2006-01-31 Thread Fuzzyman
Hello All,

I've added (optional) unicode support for ConfigObj. This is now
available from SVN.

You can specify an encoding to decode the config file on reading. This
maps to an encoding attribute on the ConfigObj instance that is also
used for writing (and can be changed).

You can find it in the SVN repository at :


https://svn.rest2web.python-hosting.com/branches/configobj4/pythonutils/

For details of the unicode support, read my blog entry at :


http://www.voidspace.org.uk/python/weblog/arch_d7_2006_01_28.shtml#e204

This seems to work fine on the files I've tested it with, but unicode
support is hard to get completely right. I'd appreciate it if anyone
coul;d check it out and try to break it. :-)

There are two remaining questions before I do a beta release. Both
relate to the handling of BOM. Again see the blog.

Comments/opinions sought.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/configobj.html

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


Re: Request for suggesstions and comments

2006-01-31 Thread [EMAIL PROTECTED]
Hi, the advice is free, so tkae it for what it's worth.
Q. Is it possible to write an application for this
kind of server activity in Python? I mean whether
Python will be suitable for this kind of high activity
load, real time app?  - Absolutely, Look at Zope or Cheetah for
examples of fairly large
python based app servers.  That doesn't mean something written quickly
from scratch will work well.

Q. How much time it can take (approx.) to develop such
kind of server?
Very hard to say, I've written similar server code for a peer to peer
tool - haven't touched the server portion in a while - and I learned a
lot more about how python threads really work doing it.  complete
half-assed estimate - min 1 week, max 1 month.

Q. Do we need multi threading? If so, then whether the
Socket modules will be safe to use with multi
threading?
Q. What modules for networking (socket ?), database
access etc should I use?
This is an answer for both questions above, yes you'll need
multithreading.  Best idiom, each client gets a thread. and whatever
else you need(your pinger thread)  The socket modules are not entirely
thread safe.  I don't remember the problems, but they were there, and
relatively solvable, if I recall corretly, most issues were
non-critical in that they resulted in a bad shutdown, but didn't impact
the server while running..  As for modules, I worked most with
TCPSocketServer(?? is this the right name?  bad bad memory - don't have
the code here :)  But I think you for this it may be easier to use the
XMLRPC server.  A lot more is done for you than the more primative
SocketServers.  This is a particularly good route to go, if you know
XMLRPC already, or plan to add browser only clients in the future.

And on another note, welcome to Python - I switched from java, as my
most productive language, after visiting a client.  They needed a tool
built in a hurry.  Some ugly XML parsing that I knew would take about a
week to write.  Long story short, my first day with Python I wrote a
functional version of the XML code in 3 hours, and got a deliverable
version of the code written the next day.   And one more hint-  I just
switched from the TK based tKinter to wxPython - and I don't think I'm
going back.

Hope this helps.

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


DispatchWithEvents & PumpWaitingMessages

2006-01-31 Thread puff
I'm working on a com automation project involving IE (yes, I know
about Pamie).  I connect to IE through DispatchWithEvents, start a
navigation, and then loop calling PumpWaitingMessages.  I see the
events OK and all is well.  At some point it is clear that the
navigation is complete (at least insofar as IE is no longer generating
events).  The code then goes off and does something else for a bit NOT
making calls to PumpWaitingMessages.  A bit later, it is time to do
another navigation.  Now my question.

The web page may have had some script that did stuff such as modifying
the DOM, changing the status line, navigating to another URL, closing
IE, etc. while messages were NOT being pumped.  What happened to the
messages?  Are they queued waiting for the next PumpWaitingMessages
call or what?

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


Re: wxPython Conventions

2006-01-31 Thread [EMAIL PROTECTED]
I'm also fairly new to wxPython, but I've done GUI's in a variety of
languages.I'm not sure about putting the systray - haven't had to
do it.  But your second question, put it in it's own class.  For
desktop apps I almost allways do a limited M/V/C pattern - M/VC - ok so
I mung the view and controller together.  Doing that made it easy for
me to replace tKinter with a newer wxGUI, and if a new toolkit comes
out - It'll be easy to move.  Since I'm a newbie to wxPython - I've
keep having to change my event handling due to ignorant usage - when
making these mistakes, it's a lot easier to nuke and recreate a widget,
or event path if your data and functions are in separate classes.  Now
as for attaching the class, I'm not sure how you've modelled your
software.  Performace considerations are also a real factor - if
performance is not a driving factor, and the program is simple enough -
just let each widget have a reference to the objects it talks to.

Ie, I have a package named GMailAccount, which contains a
GMailAccountInformation class.  Now when you create the widget for
getting this text, maybe a wx.Panel with a couple of textctrl, assign
the widget a GMailAccountInformation.

When performance starts to matter, probably want to go to some object
caching scheme in a model class, and have the widgets interface with
that - but now we're getting into a full M/V/C - and I haven't had to
do that yet in my playing with wx.

Hope this helps.

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


import datetime

2006-01-31 Thread shaboo
Hi Guys,

I have just installed Python2.4.2 on our HP-UX system. But when I try
to import datetime modlue I get the following error

~~~
>>> from datetime import datetime
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named datetime
~~

Am I missing any path? because I tried to import 'textwrap module and
that import worked fine. 

Any help will be appreciated.

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


Re: Python vs C for a mail server

2006-01-31 Thread Jens Theisen
Jay wrote:

> You can do both, but why? *Especially* in a language like C++, where
> thanks to pointers and casting, there really isn't any type safety
> anyway. How much time in your C/C++ code is spent casting and trying to
> trick the compiler into doing something that it thinks you shouldn't be
> doing?

Not much frankly. Though I have no doubt that there is a lot of code that  
does, but more so in older C++ code.

> How does type safety tell you anything about the current usage of your
> program?

Quite a bit; of course, it's doesn't cover everything and clearly testing  
the semantics is still needed, but a lot of what code is used in what way  
is described by the type system. And I admit that I'm used to use the type  
system as documentation of what's going on.

> And unit tests *might* not tell about the current usage, but
> integration tests certainly do.

Of course tests will cover a lot what static typing does and more. I'm  
just claiming that they can support each other.

> I don't think I've ever seen anyone advocating calling a function like
> getattr(obj "foo" + "bar")(). You can do some very powerful things with
> getattr, thanks to Python's dynamic nature, but I don't think anyone is
> recommending calling a function like that.

A lot of people got me wrong on that, please see Paul's postings. I really  
didn't mean that literally.

> And is that fear based simply on "feeling", or on actual experience.

The former, that's why I did start this branch of the thread, though I'm  
already regretting it.

> Because in all of my own industry experience, it's been MUCH easier to
> jump into someone else's Python code than someone else's C++ code (and
> at my last job, I had to do a lot of both). I find Python to be much
> more self-documenting, because there's not so much scaffolding all over
> the place obfuscating the true intention of the code.

That really depends on who's code you're looking at, as in any language. I  
can believe there are more C++ obfuscaters out there than ones for Python.

I usually have little problems jumping into C++ code of other people but  
the principle reason for that will be that the people I'm working with  
have a very clean and expressive coding style.

> You need to look at doctest:
> http://docs.python.org/lib/module-doctest.html
> With doctest, tests are EXACTLY where the code is. I've used doctest
> with incredibly successful results, in industry.

That's indeed a good point for Python.

> Reference counting by itself is not necessarily sufficient (because of
> circular references). That's why even Python, with its reference
> counting based system, has additional capabilities for finding circular
> references.

Whenever I encountered the need for circular references it was because an  
object, that was in some sense owned by another, needed a pointer back to  
it's owner. That solved easily with non-owning C-style pointers or weak  
pointers.

If you have an example where this is not sufficient, I'd be *very* keen on  
hearing it (it may be easy, I don't know).

> I believe that Alex's official job title at Google is "Uber Technical
> Lead". I'm sure I'll quickly be corrected if that's wrong, but trust me
> (and everyone else who's spent significant time reading c.l.p.) that
> Alex Martelli knows what he's talking about.

You seem to be thinking that I was ironic. That was certainly not my  
intention. I was just trying to minimise the amount of flames I'll be  
getting.

> A lot of your arguments are the very typical arguments that people levy
> against Python, when they're first around it. And that's fine, most
> people go through that. They are taught programming in C++ or Java, and
> that that *that* is the way you're supposed to program. Then they see
> that Python does things in different ways, and automatically assume
> that Python is doing it wrong.

I'm sorry to hear this, and whilst I'm certainly lacking experience in  
Python, I'm not one of those people.

> All I can say is that if you spend time with Python (and more
> importantly, read quality, well-established Python code that's already
> out there), you'll see and understand the Python way of doing things.

I will.

Jens


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


Re: Python vs C for a mail server

2006-01-31 Thread Jens Theisen
Paul wrote:

> Or should I be looking for some other context here?

Three people were looking at the wrong one, thanks for putting this right.

I really should not have given my point that briefly.

Jens

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


Re: Python vs C for a mail server

2006-01-31 Thread Randall Parker
But languages that share some weakness typically do not share it
equally. Three languages can have some way to do X (which some might
find undesirable while others find it great) but two of the languages
might make it easy to solve problems without ever doing X while the
third language might make it impossible or at least very difficult to
solve problems without doing X.

C++ provides ways to be type unsafe. Does that mean that C++ is type
unsafe period? Most code in C++ is going to be type safe. Some
programmers will never do dangerous casting. Others will do bad things
with casts.

I really think one has to factor in probabilities rather than state
comparisons between languages in simpler terms.

I also think that the number of ways problem domains differ that affect
language choice varry in a lot more ways than, say, whether they have
garbage collection built in. Maybe in Google where the coding is
primarily for servers the need or lack thereof for explicit control
over memory allocation is by itself reason enough to say yes or no to
C++. But in other companies solving very different sets of problems
(e.g. embedded devices with no operating system or embedded devices
with limited RAM or limited CPU or an OS with few languages available)
a lot of other factors play in the equation.

Alex Martelli wrote:

> The context is: can any other language be different in this respect?
> Only by not allowing *any* way to get symbols dynamically, and therefore
> by substantially reducing the real-world cases in which it's usable.
> C++ (with dlopen/dlsym and equivalent libraries on other platforms, with
> dynamic_cast, ...) and Java (with 'reflection' etc) do afford this
> functionality, albeit in more cumbersome ways than Python.  Therefore,
> if the inability to verify that a function named 'foobar' is in fact
> never called anywhere is a weakness, it's a weakness shared by all of
> these languages.  The originator of this thread appeared to assume that
> it was a weakness of Python and not of C++...
> 
> 
> Alex

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


Re: Fuzzy Lookups

2006-01-31 Thread Kent Johnson
Gregory Piñero wrote:
> Ok, ok, I got it!  The Pythonic way is to use an existing library ;-)
> 
> import difflib
> CloseMatches=difflib.get_close_matches(AFileName,AllFiles,20,.7)
> 
> I wrote a script to delete duplicate mp3's by filename a few years
> back with this.  If anyone's interested in seeing it, I'll post a blog
> entry on it.  I'm betting it uses a similiar algorithm your functions.

A quick trip to difflib.py produces this description of the matching 
algorithm:

   The basic
   algorithm predates, and is a little fancier than, an algorithm
   published in the late 1980's by Ratcliff and Obershelp under the
   hyperbolic name "gestalt pattern matching".  The basic idea is to find
   the longest contiguous matching subsequence that contains no "junk"
   elements (R-O doesn't address junk).  The same idea is then applied
   recursively to the pieces of the sequences to the left and to the
   right of the matching subsequence.

So no, it doesn't seem to be using Levenshtein distance.

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


Re: Question about idioms for clearing a list

2006-01-31 Thread Xavier Morel
Steven Watanabe wrote:
> I know that the standard idioms for clearing a list are:
> 
>   (1) mylist[:] = []
>   (2) del mylist[:]
> 
> I guess I'm not in the "slicing frame of mind", as someone put it, but 
> can someone explain what the difference is between these and:
> 
>   (3) mylist = []
> 
> Why are (1) and (2) preferred? I think the first two are changing the 
> list in-place, but why is that better? Isn't the end result the same?
> 
> Thanks in advance.
> --
> Steven.

The solution (1) and (2) clear the content of the list (replace the 
content of the list by an empty list for (1), or delete the content of 
the list for (2) while the solution (3) creates a new list and binds the 
old name to the new list. This means that you don't actually modify 
(clear) the initial list.

Just try it out:

 >>> a = range(10)
 >>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 >>> b = a
 >>> b
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 >>> c = a
 >>> c
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 >>> a.append(10) # assert that a, b and c point to the same list
 >>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 >>> b
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 >>> c
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 >>> b = []
 >>> b
[]
 >>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 >>> del c[:]
 >>> c
[]
 >>> a
[]
 >>>

Here we can see that using method (3) on b didn't modify the content of 
a (even though we asserted that they were the same list).
Using method (2) on c, the other hand, did modify the content of a.

This is because method (3) on b actually created a new list and bound 
"b" (as a name) to that new list, without modifying the list "b" used to 
be bound to (which is the one "a" and "c" are still bound to).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fuzzy Lookups

2006-01-31 Thread Gregory Piñero
I wonder which algorithm determines the similarity between two strings better?

On 1/31/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Gregory Piñero wrote:
> > Ok, ok, I got it!  The Pythonic way is to use an existing library ;-)
> >
> > import difflib
> > CloseMatches=difflib.get_close_matches(AFileName,AllFiles,20,.7)
> >
> > I wrote a script to delete duplicate mp3's by filename a few years
> > back with this.  If anyone's interested in seeing it, I'll post a blog
> > entry on it.  I'm betting it uses a similiar algorithm your functions.
>
> A quick trip to difflib.py produces this description of the matching
> algorithm:
>
>The basic
>algorithm predates, and is a little fancier than, an algorithm
>published in the late 1980's by Ratcliff and Obershelp under the
>hyperbolic name "gestalt pattern matching".  The basic idea is to find
>the longest contiguous matching subsequence that contains no "junk"
>elements (R-O doesn't address junk).  The same idea is then applied
>recursively to the pieces of the sequences to the left and to the
>right of the matching subsequence.
>
> So no, it doesn't seem to be using Levenshtein distance.
>
> Kent
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython on the Palm OS?

2006-01-31 Thread gregarican
Khalid Zuberi wrote:

> While someone has recently done some work to get Jython working with > J2ME
> (reference below), I think its targetted at Pocket PC class devices (CDC spec)
> as opposed to palm (CLDC as far as i know).
>
 >  http://thread.gmane.org/gmane.comp.lang.jython.devel/1826

Thanks for the link. Since my app isn't too complex I am going to try
to deploy it using SuperWaba on the Palm OS. I downloaded an Eclipse
plug-in for in and see there's an XMLRPC extension available for
SuperWaba as well. This the communications method I use for my app so
we'll see how it goes!

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


Why checksum? [was Re: Fuzzy Lookups]

2006-01-31 Thread Steven D'Aprano
On Tue, 31 Jan 2006 10:51:44 -0500, Gregory Piñero wrote:

> http://www.blendedtechnologies.com/removing-duplicate-mp3s-with-python-a-naive-yet-fuzzy-approach/60
> 
> If anyone would be kind enough to improve it I'd love to have these
> features but I'm swamped this week!
> 
> - MD5 checking for find exact matches regardless of name 
> - Put each set of duplicates in its own subfolder.

This isn't a criticism, it is a genuine question. Why do people compare
local files with MD5 instead of doing a byte-to-byte compare? Is it purely
a caching thing (once you have the checksum, you don't need to read the
file again)? Are there any other reasons?


-- 
Steven.

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

Re: Why checksum? [was Re: Fuzzy Lookups]

2006-01-31 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> This isn't a criticism, it is a genuine question. Why do people compare
> local files with MD5 instead of doing a byte-to-byte compare? Is it purely
> a caching thing (once you have the checksum, you don't need to read the
> file again)? Are there any other reasons?

It's not just a matter of comparing two files.  The idea is you have
10,000 local files and you want to find which ones are duplicates
(i.e. if files 637 and 2945 have the same contents, you want to
discover that).  The obvious way is make a list of hashes, and sort
the list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about idioms for clearing a list

2006-01-31 Thread bearophileHUGS
Diez B. Roggisch:
> The reason is that l = [] just rebinds a new object (a list, but it could be
> anything) to a name, while l[:] = [] will alter the object _referred_ to by
> l. That is a HUGE difference!

In my programs I have seen that there is another practical difference
between version 1 and 3:
(1) mylist[:] = []
(3) mylist = []
If you create a big mylist again and again many times, the version 1
uses the memory more efficiently (probably less work for the garbage
collector), and the program can be (quite) faster (this is true in some
implementations different from CPython too).

Bye,
bearophile

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


Re: Python module for LX200 telescope command set

2006-01-31 Thread Alan Kennedy
[RayS]
> I've begun a Python module to provide a complete interface to the Meade 
> LX200 command set:

and

> History: after searching for such a thing, I had found only:
> http://72.14.203.104/search?q=cache:hOgO7H_MUeYJ:phl3pc02.phytch.dur.ac.uk/~jrl/source/source_code.html+lx200.py&hl=en&gl=us&ct=clnk&cd=1
>  
> 
> from University of Durham, but the code is not available...
> and
> http://cvs.sourceforge.net/viewcvs.py/projgalileo/lx200/lx200.py?rev=1.4
> from the Galileo project, but which only has a subset and is aimed at 
> their needs, mostly. Some of the Galileo code looks useful, and so I 
> might want to make use of at least some of the methodology, even if only 
> to get their interest as well.

Do you know about ASCOM?

"The primary goal of the ASCOM Initiative is to provide software driver 
technology that will help bring about a rebirth of science in amateur 
astronomy by making instruments scriptable via standard low-level 
scripting interfaces."

http://ascom-standards.org/faq.html

IIUC, ASCOM is a set of Windows COM objects which provides a 
standardised API for controlling telescopes. Since it uses Windows COM, 
you should be able to control it easily from python using the excellent 
win32 extensions.

Python for Windows Extensions
http://starship.python.net/crew/mhammond/

 From this page

http://ascom-standards.org/nr-11Jun01.html

comes the statement

"""
Telescopes currently supported are the Meade LX200 and Autostar, 
Celestron NexStar, Vixen SkySensor 2000, Software Bisque Paramount (via 
TheSky), a number of mounts that support subsets of the LX200 serial 
protocol (Astro-Physics, Bartels, etc.), and many research-grade 
telescopes that use the Astronomy Control Language (ACL). Products that 
support telescope control via ASCOM are Starry Night by SPACE.com, MaxIm 
DL V3 by Cyanogen Productions, and ACP2 by DC3 Dreams.
"""

HTH,

-- 
alan kennedy
--
email alan:  http://xhaus.com/contact/alan
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: pynakotheka v1.0.1

2006-01-31 Thread Iñigo Serna
Hello out there,

I'm really pleased to announce the second public release of Pynakotheka.

Pynakotheka is a simple GPL-licensed python script which generates
static HTML photo albums to be added to web sites or to be burnt in CDs.
It includes some templates and it's easy to create more.

It depends on python, CheetahTemplate, EXIF and PIL.

Read more and download it from:

http://inigo.katxi.org/devel/pynakotheka

or http://www.terra.es/personal7/inigoserna/pynakotheka


Changes from v1.0 to v1.0.1
===
* distutils support. Now you can install pynakotheka
* added a man page
* fixed some typos in templates


Of course, all comments, suggestions etc. are welcome.


Best regards,
-- 
Iñigo Serna <[EMAIL PROTECTED]>
Katxijasotzaileak


signature.asc
Description: Esta parte del mensaje está firmada	digitalmente
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: import datetime

2006-01-31 Thread Lee Harr
> I have just installed Python2.4.2 on our HP-UX system. But when I try
> to import datetime modlue I get the following error
>
> ~~~
 from datetime import datetime
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named datetime
> ~~
>
> Am I missing any path? because I tried to import 'textwrap module and
> that import worked fine. 
>


You may have more than one version of Python. What does it
say when you first start it from a command line? Mine says:

$ python
Python 2.3.5 (#2, Sep  4 2005, 22:01:42)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


If it is not python 2.4 like you expected, you could try
running it as python2.4 and see if the modules are there.

If it is already 2.4, try this:

import sys
sys.path

and see which paths are being searched. Look around in
there and see if the datetime module is where it is
supposed to be.

Beyond that, you should probably ask on an HP-UX list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: VB to Python migration

2006-01-31 Thread Josh
Magnus Lycka wrote:
  > I suppose that you need to present a lot of differnt kinds of data,
> and that you need to provide various search parameters etc for
> different data sets, but this sounds like something that might be
> very few screens that adapt to some kind of meta-data, perhaps XML
> descriptions or small "configuration files" containing som simple
> Python data structures and possibly input validation routines etc.
> Maybe this information should even be in the database?

This all makes sense. Being hamstrung by the VB model has hampered our 
thinking in areas like this I think. Having a smaller number of dynamic, 
data driven screens is good for maintainability anyways.

> The problem arises if there is behavior in the application that
> varies with data, but with Python, it's certainly possible to handle
> that to some extent even if these screens are driven by database
> content.
> 
> BTW, I guess DABO http://dabodev.com/ is intended just for this kind
> of application, but I doubt it was ever used for a project of this
> size, it's fairly new... Never used it myself...

I have looked through the DABO website and it looks very promising. By 
the looks of it, the authors come from the same type of background 
(Windows RAD application) as we are coming from. I'll have to download 
it and give it a run for it's money.

> Whatever you use for your user interface, I suggest that you use
> a multi-tier approach, and a very thin user interface layer. In my
> opinion that makes testing much easier. I'd recommend that you use
> a proper test tool and employ a test-driven approach.

This is what we're planning on. If the user interface is as thin as 
possible, that allows easily porting it to a web app etc.

As for the testing, that's something we'll need to learn about. I've 
read some articles about test driven programming in relation to extreme 
programming. Can you give me links to any good sites explaining how this 
all works? (Off list may be better for these off-topic links)

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


Re: test whether 2 objects are equal

2006-01-31 Thread Bruno Desthuilliers
Yves Glodt a écrit :
> bruno at modulix wrote:
> 
>> Yves Glodt wrote:
>>
(snip)

>>> #!/usr/bin/python
>>>
>>> class Test:
>>> var1 = ''
>>> var2 = ''
>>
>>
>> Take care, this creates two *class* variables var1 and var2. For
>> *instance* variables, you want:
> 
> 
> Thanks for making me aware. I'll have to read more about classes in 
> python... ( As you can see I'm still new to it ;-)

I don't remember what's your background, but if you come from 
C++/Java/..., then yes, definitevely, you need to learn more about 
Python's object model. The class variable/instance variable confusion is 
a common gotcha.

BTW, better use 'new-style' classes (that is - for short-, classes that 
inherit at least from 'object' or any other new-style class), ie:

class NewStyle(object):
   # this is a new-style class
   pass

class NewStyleToo(NewStyle):
   # this is a new-style class too
   pass

class OldStyle:
   # this is a deprecated old-style class


> btw, this is the best list I've ever joined, very helpful and nice ppl.

Yes, this is definitively a nice place !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


how to parse structured text file?

2006-01-31 Thread Petr Jakes
I have a file which contains data in the format shown in the sample
bellow.
How can I parse it to get following:
(14,trigger,guard,do_action,15)

Thanks a lot for your postings
Petr Jakes

type:
4
bgrColor:
255 255 255
fgrColor:
0 0 0
objId:
16
Num.Pts:
2
177 104
350 134
objStartId:
14
objEndId:
15
eventName:
trigger
eventCond:
guard
eventAction:
do_action

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


Re: how to parse structured text file?

2006-01-31 Thread Petr Jakes
Sorry I was not precise enough in my description.

In the file, there is of course more sections starting with the keyword


type:

I would like to only analyze sections which start with the sequence:

type:
4

Petr jakes

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


Re: instance references?

2006-01-31 Thread Scott David Daniels
Scott David Daniels wrote:
> Alex Martelli wrote: (in effect)
>>aptbase.drawables = weakref.WeakValueDictionary()
>> then in each __init__
>>aptbase.drawables[len(aptbase.drawables)] = self
>> then in show:
>>for o in aptbase.drawables.values():
>># render it
 >
> The keys you are choosing are probably not a good idea.
> Problem demo:
>a,b,c = Something(), Something(), Something()
>b = None
>d = Something()  # overwrites the d entry.

In a tiny demo of what exactly the problem is, I managed to
mess up the comment.
 a, b, c = Something(), Something(), Something()
 b = None
 d = Something()  # overwrites the _c_ entry.

Silly me.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >