Roundup Issue Tracker release 1.1.2

2006-04-27 Thread Richard Jones
I'm proud to release version 1.1.2 of Roundup.

Feature:

- server-ctl script uses server configuration file (sf bug 1443805)

Fixed:

- indexing may be turned off for FileClass content now
   (content and type properties are now automatically included in  
the
   FileClass schema where previously the content property was faked  
and
   type was optional)
- reduced frequency of session timestamp update
- progress display in roundup-admin reindex
- bug in menu() permission filter (sf bug 140)
- verbose output during import is optional now (sf bug 1475624)
- escape *all* uses of schema in mysql backend (sf bug 1472120)
- responses to user rego email (sf bug 1470254)
- dangling connections in session handling (sf bug 1463359)
- classhelp popup pagination forgot about type (sf bug 1465836)
- umask is now configurable (with the same 0002 default)
- sorting of entries in classhelp popup (sf bug 1449000)
- allow single digit seconds in date spec (sf bug 1447141)
- prevent generation of new single-digit seconds dates (sf bug 1429390)
- implement close() on all indexers (sf bug 1242477)


If you're upgrading from an older version of Roundup you *must* follow
the Software Upgrade guidelines given in the maintenance  
documentation.

Roundup requires python 2.3 or later for correct operation.

To give Roundup a try, just download (see below), unpack and run::

 python demo.py

Release info and download page:
  http://cheeseshop.python.org/pypi/roundup
Source and documentation is available at the website:
  http://roundup.sourceforge.net/
Mailing lists - the place to ask questions:
  http://sourceforge.net/mail/?group_id=31577


About Roundup
=

Roundup is a simple-to-use and -install issue-tracking system with
command-line, web and e-mail interfaces. It is based on the winning  
design
from Ka-Ping Yee in the Software Carpentry Track design competition.

Note: Ping is not responsible for this project. The contact for this
project is [EMAIL PROTECTED]

Roundup manages a number of issues (with flexible properties such as
description, priority, and so on) and provides the ability to:

(a) submit new issues,
(b) find and edit existing issues, and
(c) discuss issues with other participants.

The system will facilitate communication among the participants by  
managing
discussions and notifying interested parties when issues are edited.  
One of
the major design goals for Roundup that it be simple to get going.  
Roundup
is therefore usable out of the box with any python 2.3+  
installation. It
doesn't even need to be installed to be operational, though a
disutils-based install script is provided.

It comes with two issue tracker templates (a classic bug/feature  
tracker and
a minimal skeleton) and five database back-ends (anydbm, sqlite,  
metakit,
mysql and postgresql).


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

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


Re: MinGW and Python

2006-04-27 Thread Martin v. Löwis
Ross Ridge wrote:
 Nonetheless, Cygwin applications are not generally considered native
 Win32 applications because of the dependency on CYGWIN1.DLL and the
 related environment.  While what you're saying a strictly true, the
 term native Win32 is used to make a distinction between a port of a
 program that doesn't use or require the Cygwin environment from one
 that does.

I know it is common to take that view, but I believe it is wrong, no
matter how you look at it:

- Is winword.exe not a native Win32 library because it uses MSO.DLL?
- A cygwin application does *not* require the Cygwin environment.
  You don't need to invoke it from bash.exe, you don't need
  to install Cygwin to run it, and you don't need a directory structure
  including /usr or /etc to make it work.

 For example, the official version of Python for Windows is
 considered a native Win32 application because it's implemented using
 the Windows APIs directly

That isn't (entirely) true. Python largely doesn't use the Win32 API
directly, but instead, it uses the C library of the C compiler it
was built with. It also uses the Win32 API directly, and more so
in Python 2.5 than in earlier versions, but reliance on the C library
still hasn't been dropped.

For Py3k, perhaps the C library can be dropped entirely: Guido wants
to drop usage of stdio as an implementation of the file object; if
then malloc/free is dropped in favour of a direct implementation
(e.g. based on HeapAlloc), then Python could become a native Win32
application in the sense you defined above.

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


Re: cgi subprocess, cannot get output

2006-04-27 Thread Jakub Piotr Nowak
Dnia 26.04.2006 James Stroud [EMAIL PROTECTED] napisa³/a:
} Jakub Piotr Nowak wrote:
} Hello,
} 
} In the following cgi program, I cannot get subprocess output.
} I print the header, flush stdout to prepare it to new content,
} but variable 'o' is always empty.
} 
} Could somebody help me with that? 
} 
} [...mniam...]
} 
} Best regards,
}
} What kind of script is tinki? I had a bitch of a problem like this with 
} perl and ended up just writing to a file. No idea why I couldn't get the 
} stdout.

Tinki is a natural language parser. It takes a sentence as a
command line argument and prints xml file to stdout. 

Thanks for the hint, I will try... 

Best regards,
-- 
Jakub P. Nowak
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Query regarding support for IPv6 in python

2006-04-27 Thread Heiko Wundram
Am Mittwoch 26 April 2006 17:02 schrieb Pramod TK:
 1. Does python support IPv6? [128 bit IP addresses?]

Yes.

 2. Does it support setting of QoS flags?

Yes. That's a socket option which you can set just as you would set it using C 
(at least under Unix, under Windows: no idea).

 3. Does it support tunneling of IPv6 on a IPv4 network?

No. That's an OS's job. You could, of course, implement a 6in4-tunnel using 
TUN interfaces, completely in Python. But I don't think that's what you want 
to do. And, anyway, your host OS would need IPv6 support for this to work. I 
wouldn't know how you'd go about implementing this on Windows, though.

 4. If an IPv4 address is given, does it support this on a IPv6 network?

Depends on the OS. If the OS supports 6to4, then Python does too (because an 
IPv4-Adress is simply mapped to an IPv6-Network with a certain notation, look 
up the documentation for the 2001::-network on Wikipedia, for example). If 
the OS doesn't, Python doesn't either. This is also an OS job, not a Python 
job.

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


Re: C API []-style access to instance objects

2006-04-27 Thread André Malo
* [EMAIL PROTECTED] wrote:

 Hi,
 
 I am having trouble figuring out how to set up an object to be
 scriptable through the C API.  An example of what I am attempting to
 do:
 
 obj = foo.Foo()
 obj[key]
 Traceback (most recent call last):
   File stdin, line 1, in ?
 TypeError: unsubscriptable object

 
 I've tried defining __getitem__ as a method, but that hasn't worked.
 Is there a tp_field that I am failing to understand, something like
 tp_iter and tp_iternext?

tp_as_mapping is what you're looking for. It takes the pointer to another
structure: PyMappingMethods.

You might want to try the modulator script (comes with the source
distribution of python), which generates some of the basic type methods for
you. It's a bit old, but gives a good start.

nd
-- 
Umfassendes Werk (auch fuer Umsteiger vom Apache 1.3)
  -- aus einer Rezension

http://pub.perlig.de/books.html#apache2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah's Edu Corner: Criticism vs Constructive Criticism

2006-04-27 Thread RobertSzefler
John Bokma wrote:

 harassing Usenet. (Did I just wrote smart?!)

Tell me about bad English :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: begging for a tree implementation

2006-04-27 Thread Sybren Stuvel
Micah enlightened us with:
 I'm looking for a simple abstract-data-type tree.  I would have thought
 there would be a built-in type, but I can't find one.  I just need to
 be able to start from a root node and attach children from there.  I
 could jury-rig one using a dict or some tuples, but I'd like a
 full-featured tree if someone has one implemented.

If you keep things that vague: use a list. See the first element as
the root node. Every node has only one child.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: blob problems in pysqlite

2006-04-27 Thread aldonnelley
Excellent. Got that working. Now, how to get the pickled data out of
the database?

I'm trying to use cPickle.loads(data) (code attached), and I get a:
TypeError: loads() argument 1 must be string, not list

Is there a workaround for this? I've tried converting the List of files
to a String before cPickling it, but the same result (expected). I've
read, in a post of Gerhard's somewhere, about marshal, but I don't see
how this would work for the HTML. (where I have the same problem.)

Cheers, Al.
ps. Tim: Your clean take on my code made me realise that I had stupidly
included quotes in the URL argument passed to sqlite,  ie I'd ended up
with, effectively, DBURL= 'http://www.myhomepage.com;', rather than =
'http://www.myhomepage.com'. It's the little things that matter...
Thanks for your help. Oh, and your 'representative samples' are spot
on!

#code starts
URL = http://www.myhomepage.com;

db = sqlite.connect(ImageInfoDatabase.db)

c = db.cursor()

DBURL = str(URL)
print DBURL
c.execute(select Images from FileURLInfo where URL= ?;, (DBURL,))
KnownFilesResult = c.fetchall()
print KnownFilesResult#where I get a r/w buffer, as expected
cPickle.loads(KnownFilesResult)#where I get the error described
above.

#code ends.

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


Re: begging for a tree implementation

2006-04-27 Thread Rene Pijlman
Micah:
I'd like a full-featured tree

What features?

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


Re: Type-Def-ing Python

2006-04-27 Thread Alex Martelli
[EMAIL PROTECTED] wrote:
   ...
 Brett Cannon's thesis in which he tweaks the compiler and shows that
 type-defing python would not help the compiler achieve a 5% performace
 increase.
 
 Brett Cannon, Localized Type Inference of Atomic Types in Python:
 http://www.ocf.berkeley.edu/~bac/thesis.pdf
 
 I was wondering if anyone had his contact information so that I could
 might ask him for his source code and try to use type-defing as a
 bug-finder.

Brett is active on Python-Dev, so post there and you're likely to get a
response from him -- your subject is not OT for that list, anyway!


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


Re: Speed of shutil.copy vs os.system(copy src dest) in win32

2006-04-27 Thread Tim Roberts
Russell Warren [EMAIL PROTECTED] wrote:

I just did a comparison of the copying speed of shutil.copy against the
speed of a direct windows copy using os.system.  I copied a file that
was 1083 KB.

I'm very interested to see that the shutil.copy copyfileobj
implementation of hacking through the file and writing a new one is
significantly faster... any clue as to why this is?  I figure I'm
missing something here.

Does os.system launch a cmd shell every time?

Yes.  That's in the documentation.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list of functions question

2006-04-27 Thread Tim Roberts
val bykoski [EMAIL PROTECTED] wrote:

Hi The List:
   I have a modeling app where i'm detecting events (in temporal 
dynamics) applying a set of (boolean) functions - kind of:

event_list = f1 f2 etc.split()  # each fi detects a specific event
i have defs for functions fi, or simple boolean expressions for each, so 
that evList is a list of defs or boolean expressions
for ev in evList:
if ev: # this supposedly is a call ev(t)
   # doing smth with the event

I didn't succeed, though, (blindly) trying various options.
I thought/tried apply() but couldn't get it work.
I'd appreciate pointers to how to handle this kind of
functions or events lists (or objects?) and how to call those
functions in a loop.

If you hadn't tried the string shortcut, it would have worked:

  event_list = [f1, f2, etc]

As it is, event_list is a list of strings, not a list of functions.

Then, when you want to call it, remember that it has to be treated like a
function:

  for ev in event_list:
if ev(t):
  pass

If you REALLY need the list of functions to come from a string, you can
also do:

  event_list = [eval(f) for f in f1 f2 etc.split()]
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules through directory shortcuts on Windows

2006-04-27 Thread Roger Upole
You can use win32file.DeviceIoControl to link directories.
I can post some code to do so if anyone's interested.

   Roger


Brian Quinlan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 Recently, I became responsible for maintaining some Python code, which was 
 organized as follows:

 user/pylib
  ui
  ...
 project2/pylib
  ui
  ...
 project3/pylib
  ui
  ...
 python-packages/user = /user/pylib
 project2 = /project2/pylib
 project3 = /project3/pylib

 The idea is that python-packages is added to sys.path and then every 
 project can import the library package from every other 
 project. NOTE: I think that this structure is crazy but I'm just the poor 
 maintenance programmer.

 Anyway, the problem is that Windows does not have a symlink facility to 
 accommodate this (AFAIK) and the Python import 
 mechanism does not resolve shortcuts.

 Therefore, I wrote a very simple import hook to get around that problem. If 
 you are interested, the code is here:
 http://www.sweetapp.com/shortcut/shortcutimporter.py

 BTW, does anyone else think that this functionality should be part of core 
 Python?

 Cheers,
 Brian 




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


Re: Looking for resources for making the jump from Java to Python easier and more productive

2006-04-27 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 bruno at modulix [EMAIL PROTECTED] wrote:

Lawrence D'Oliveiro wrote:
 In article [EMAIL PROTECTED],
  bruno at modulix [EMAIL PROTECTED] wrote:
 
 
Lawrence D'Oliveiro wrote:

(snip)
I suppose this is an instance of the more general rule: using OO when 
you don't have to.

Lawrence, I'm afraid you're confusing OO with statically-typed
class-based. FWIW, dynamic typing is part of OO since Smalltalk.
 
 
 I wasn't talking about dynamic typing, I was talking about subclassing, 
 which is very much a part of OO.

What you wrote implies (well, at least I understand it that way) that
polymorphic dispatch *not* based on subclassing is not OO. Hence my
reaction : the need to use subclassing (inheritance) for subtyping
(polymorphic dispatch) is not a requirement of object orientation and
has never been - it's only a limitation of languages with declarative
static typing (C++, Java, C# etc).

It's nothing to do with OO, because it's also present in non-OO 
languages.

 Unless you subscribe to the OO is whatever looks like a good 
 programming idea definition http://www.paulgraham.com/reesoo.html.

Not really !-)

One would hope not.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Speed of shutil.copy vs os.system(copy src dest) in win32

2006-04-27 Thread Tim Golden
[Russell Warren]

| I just did a comparison of the copying speed of shutil.copy 
| against the
| speed of a direct windows copy using os.system.  I copied a file that
| was 1083 KB.
| 
| I'm very interested to see that the shutil.copy copyfileobj
| implementation of hacking through the file and writing a new one is
| significantly faster... any clue as to why this is?  I figure I'm
| missing something here.

There are a couple of other options as well which
may or may not be faster. I'd meant to time things
before putting this page up but never got round to
it; maybe I'll give it another go:

http://tgolden.sc.sabren.com/python/win32_how_do_i/copy-a-file.html

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: OOP / language design question

2006-04-27 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Duncan Booth [EMAIL PROTECTED] wrote:

Carl Banks wrote:

 You know, Python's __init__ has almost the same semantics as C++
 constructors (they both initialize something that's already been
 allocated in memory, and neither can return a substitute object). 

There is a significant difference: imagine B is a base type and C a 
subclass of B:

When you create an object of type C in Python, while B.__init__ is 
executing self is an object of type C (albeit without all the attributes 
you expect on your C).

In C++ when the B() constructor is executing the object is an object of 
type B. It doesn't become a C object until the C() constructor is 
executing.

In other words, the object is constructed in Python before any __init__ is 
called, but in C++ it isn't constructed until after all the base class 
constructors have returned.

But if construction is what a constructor does, then you're wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP / language design question

2006-04-27 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Carl Banks [EMAIL PROTECTED] wrote:

bruno at modulix wrote:
 [EMAIL PROTECTED] wrote:
  I was wondering, why you always have to remember to call bases'
  constructors

 pedantic
 s/constructors/__init__/

 the __init__() method is *not* the constructor. Object's instanciation
 is a two-stage process:  __new__() is called first, then __init__().
 /pedantic

You know, Python's __init__ has almost the same semantics as C++
constructors (they both initialize something that's already been
allocated in memory, and neither can return a substitute object).  I
actually think constructors are misnamed in C++, they should be called
initializers (and destructors finalizers).

Constructor is also the term used for the corresponding method in Java.

Is there any OO language that does not use constructor in this sense? 
I don't think there is one. This is standard OO terminology.
-- 
http://mail.python.org/mailman/listinfo/python-list


Direct acces to db unify on unix sco

2006-04-27 Thread luca72
Is it possible or i must use odbc?

Rergards Luca

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


Re: Can you create an instance of a subclass with an existing instance of the base class?

2006-04-27 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Bruno Desthuilliers [EMAIL PROTECTED] wrote:

Sandra-24 a écrit :
 Lawrence D'Oliveiro wrote:
 
In article [EMAIL PROTECTED],
 Sandra-24 [EMAIL PROTECTED] wrote:


Now that is a clever little trick. I never would have guessed you can
assign to __class__, Python always surprises me in it's sheer
flexibility.

That's because you're still thinking in OO terms. 
 
 It's not quite as simple as all that. I agree that people, escpecially
 people with a Java (ew) background overuse OO, when there's often
 simpler ways of doing things.

Nope. I mean : they don't overuse OO, they overuse *classes*. AFAIK, OO 
means *object* oriented - not class oriented.

Oh great. Now we have someone redefining the concept of OO to evade the 
point I was making.

There are OO languages that don't even have a notion of class.

Sounds like stuff I was doing in C (a non-OO language) years ago. Unless 
you want to count C as an OO language, I think you're going to have to 
retract this claim.

 However in this case I'm simply getting an object (an mp_request object
 from mod_python) passed into my function, and before I pass it on to
 the functions that make up and individual web page it is modified by
 adding members and methods to add functionality.

Which is a well-known design pattern called decorator.

If you have to think of it as a design pattern, that means you haven't 
figured out the code reuse angle yet.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Can you create an instance of a subclass with an existing instance of the base class?

2006-04-27 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 bruno at modulix [EMAIL PROTECTED] wrote:

Lawrence D'Oliveiro wrote:
 In article [EMAIL PROTECTED],
  bruno at modulix [EMAIL PROTECTED] wrote:
 
 
Lawrence D'Oliveiro wrote:
(snip)

I think you're taking Python's OO-ness too seriously. One of the 
strengths of Python is that it can _look_ like an OO language without 
actually being OO.

According to which definition of OO ?
 
 Isn't there one?

Your claim that Python _look_ like an OO language without actually
being OO implicitely relies on a definition of OO - or is just
meaningless.

Which nicely evades answering the question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can one query full name (or version) of selected packages at pypi?

2006-04-27 Thread Tim Golden
[Caleb Hattingh]

 My big problem, being in South Africa, is
 that I have to get any distros on cover CDs or order from
 distro-resellers, and they never have Testing or Unstable.   Broadband
 hasn't exactly hit the local market, although things might be looking
 up in a few years or so.

I have no idea how useful the following will be, but I've
bought CDs several times from linuxemporium.co.uk
and they've always been very obliging when I've contacted
them directly for updates etc. Obviously I can't speak for
them, but I don't imagine it's any harder for them to burn
Debian Unstable/Testing than burning any other download.

They're UK-based, but maybe a distributor in your part
of the world might be equally obliging.

TJG

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


Re: begging for a tree implementation

2006-04-27 Thread Ant
Did you not read the first post?

  All the nice methods would be appreciated (getLeaves, isLeaf, isRoot,
 depthfirst, breadthfirst,...)

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


Re: Events in Python?

2006-04-27 Thread Ben Sizer
[EMAIL PROTECTED] wrote:
 It seems like Python doesn't have a standard implementation of an
 event or messaging system. That is really what I was curious about. I
 wanted to check before I implemented something of my own.

What are you comparing it to? Does Java have standard event or
messaging systems? I thought there were only such systems as part of
the GUI libraries. Perhaps you're referring to the Observer interface?
Sometimes a solution that is necessary in Java would be an
overcomplication in Python, and full-blown Observers is probably one
such example.

-- 
Ben Sizer

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


Re: not quite 1252

2006-04-27 Thread John Machin
On 27/04/2006 12:49 AM, Anton Vredegoor wrote:
 Fredrik Lundh wrote:
 
 Anton Vredegoor wrote:

 I'm trying to import text from an open office document (save as .sxw and
  read the data from content.xml inside the sxw-archive using
 elementtree and such tools).

 The encoding that gives me the least problems seems to be cp1252,
 however it's not completely perfect because there are still characters
 in it like \93 or \94. Has anyone handled this before?

 this might help:

 http://effbot.org/zone/unicode-gremlins.htm
 
 Thanks a lot! The code below not only made the strange chars go away, 
 but it also fixed the xml-parsing errors 

What xml-parsing errors were they??

 ... Maybe it's useful to 
 someone else too, use at own risk though.
 
 Anton
 
 from gremlins import kill_gremlins
 from zipfile import ZipFile, ZIP_DEFLATED
 
 def repair(infn,outfn):
 zin  = ZipFile(infn, 'r', ZIP_DEFLATED)
 zout = ZipFile(outfn, 'w', ZIP_DEFLATED)
 for x in zin.namelist():
 data = zin.read(x)
 if x == 'contents.xml':

Firstly, this should be 'content.xml', not 'contents.xml'.

Secondly, as pointed out by Sergei, the data is encoded by OOo as UTF-8 
e.g. what is '\x94' in cp1252 is \u201d which is '\xe2\x80\x9d' in 
UTF-8. The kill_gremlins function is intended to fix Unicode strings 
that have been obtained by decoding 8-bit strings using 'latin1' instead 
of 'cp1252'. When you pump '\xe2\x80\x9c' through the kill_gremlins 
function, it changes the \x80 to a Euro symbol, and leaves the other two 
alone. Because the \x9d is not defined in cp1252, it then causes your 
code to die in a hole when you attempt to encode it as cp1252: 
UnicodeEncodeError: 'charmap' codec can't encode character u'\x9d' in 
position 1761: character maps to undefined

I don't see how this code repairs anything (quite the contrary!), unless 
there's some side effect of just read/writestr. Enlightenment, please.

 zout.writestr(x,kill_gremlins(data).encode('cp1252'))
 else:
 zout.writestr(x,data)
 zout.close()

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


Re: OOP / language design question

2006-04-27 Thread Duncan Booth
Lawrence D'Oliveiro wrote:

In other words, the object is constructed in Python before any
__init__ is called, but in C++ it isn't constructed until after all
the base class constructors have returned.
 
 But if construction is what a constructor does, then you're wrong.
 
I may be wrong (my C++ is getting rusty), but my belief is that if you have 
a base class B and a derived class D, then until the B() constructor has 
returned, the type of the object (as indicated by RTTI or by calling 
virtual methods) is a B. It isn't until after the B constructor has 
returned that the object is changed into a D.

This is different from Python's behaviour where the object is created as 
its final type and then initialised.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Importing modules through directory shortcuts on Windows

2006-04-27 Thread Tim Golden
[Roger Upole]

| You can use win32file.DeviceIoControl to link directories.
| I can post some code to do so if anyone's interested.

I'd certainly be interested...

Thanks
TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Events in Python?

2006-04-27 Thread Ben C
On 2006-04-26, nikie [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

 Here is another non-pythonic question from the Java Developer. (I beg
 for forgiveness...)

 Does Python have a mechanism for events/event-driven programming?

 I'm not necessarily talking about just GUIs either, I'm interested in
 using events for other parts of an application as well.

 If there isn't some sort of event mechanism built into Python, where
 might I find some information about implementing one?

 Maybe I got your question wrong, but why not simply use something like:

 class Sender:
 def __init__(self, event):
 self.event = event

 def raiseEvent(self):
 self.event(Event)

 class Receiver:
 def receiveEvent(self, msg):
 print Received %r % msg

 r = Receiver()
 s = Sender(r.receiveEvent)
 s.raiseEvent()

 You can pass around functions and bound methods, I always found that's
 often a really good substitute for full-blown event mechanisms.

Actually I'd say full-blown event mechanisms are a poor substitute for
passing around bound-methods :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyrex installation on windows XP: step-by-step guide

2006-04-27 Thread Julien Fiore
Thanks for your remark, Sturlamolden.

Is there a free version of the Visual C++ 2003 compiler available on
the web? I have found Visual C++ 2005 Express edition
(http://msdn.microsoft.com/vstudio/express/visualc/). According to
Micrsoft, it replaces VC++2003
(http://msdn.microsoft.com/visualc/vctoolkit2003/). Is VC++2005ee the
good compiler to compile a Pyrex module (or any Python extension) ?
Does it link with msvcr71.dll ?

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


RE: blob problems in pysqlite

2006-04-27 Thread Tim Golden
[EMAIL PROTECTED]

| I'm trying to use cPickle.loads(data) (code attached), and I get a:
| TypeError: loads() argument 1 must be string, not list
| 
| Is there a workaround for this? I've tried converting the 
| List of files
| to a String before cPickling it, but the same result (expected).

OK, This one looks more straightforward. The result of fetchall ()
is a list of tuples (even if it is a list of one tuple and even if
that tuple has only one element). This means that KnownFilesResult 
is a list. cPickle.loads wants a string. You can, obviously, convert 
the list to a string, but that would only result in something like 
[(blah,), (blah,)] which is clearly not what you want.

Depending on what you think you're going to get back, you
either need to use fetchone in place of fetchall, which
will return one tuple -- in this case containing one buffer 
-- or you need to iterate over the list, or unpack it, again 
depending on your expectation of the data.

Here, something like this fragment should work (untested):

.
.
# Iterate over the result set and unpack
#  each tuple into its elements.

KnownFilesResult = c.fetchall ()
for row in KnownFilesResult:
  (pickled_result,) = row
  unpickled_result = cPickle.loads (pickled_result)
  # do things with unpickled result
  
| ps. Tim: Your clean take on my code made me realise that I 
| had stupidly included quotes in the URL argument passed to 
| sqlite ... It's the little things that matter...

By the way, it's a lot easier for others (like me) to help
if you post a self-contained code sample. In both cases,
while your explanation has been lucid enough for me to
see / guess what's going one, I've had to add bits to
your posted code so that they work. It helps if you
add enough to the top of the code to -- in this case --
create the table you're using so that all anyone has
to do is to cut-and-paste the code into an interpreter.

(I realise that I haven't actually done this in return
this time, but that's partly because it might obscure
the point I'm trying to make and partly because it's
a drop-in replacement for your own code).

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: OOP / language design question

2006-04-27 Thread Carl Banks

Lawrence D'Oliveiro wrote:
 In article [EMAIL PROTECTED],
  Carl Banks [EMAIL PROTECTED] wrote:

 bruno at modulix wrote:
  [EMAIL PROTECTED] wrote:
   I was wondering, why you always have to remember to call bases'
   constructors
 
  pedantic
  s/constructors/__init__/
 
  the __init__() method is *not* the constructor. Object's instanciation
  is a two-stage process:  __new__() is called first, then __init__().
  /pedantic
 
 You know, Python's __init__ has almost the same semantics as C++
 constructors (they both initialize something that's already been
 allocated in memory, and neither can return a substitute object).  I
 actually think constructors are misnamed in C++, they should be called
 initializers (and destructors finalizers).

 Constructor is also the term used for the corresponding method in Java.

 Is there any OO language that does not use constructor in this sense?
 I don't think there is one. This is standard OO terminology.

Python?

Yeah, I realize it's common terminology, but I just think it's a poor
name.   That Python doesn't really call __init__ a constructor is good
(I guess it doesn't really call it anything but __init__), because
constructor would be a bad name for it.


Carl Banks

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


Re: list of functions question

2006-04-27 Thread John Machin
On 27/04/2006 10:38 AM, val bykoski wrote:
 Hi The List:
   I have a modeling app where i'm detecting events (in temporal 
 dynamics) applying a set of (boolean) functions - kind of:
 
 event_list = f1 f2 etc.split()  # each fi detects a specific event
 i have defs for functions fi, or simple boolean expressions for each, so 
 that evList is a list of defs or boolean expressions
 for ev in evList:
if ev:# this supposedly is a call ev(t)
   # doing smth with the event
 
I didn't succeed, though, (blindly) trying various options.
 I thought/tried apply() but couldn't get it work.
 I'd appreciate pointers to how to handle this kind of
 functions or events lists (or objects?) and how to call those
 functions in a loop.
thanks,val   

This may be something like what you are trying to achieve:

# untested
def fx(arg):
 pass
def fy(arg):
 pass
def fdefault(arg):
 pass

funcmap = {
'x1': fx,
'x2': fx,
'y' : fy,
}

eventlist = y x2 x2 x1 y.split()
for ev in eventlist:
 efunc = funcmap.get(ev, fdefault)
 if efunc(t): # what is t
 # do something
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: begging for a tree implementation

2006-04-27 Thread Ant
I was looking for a tree implementation a while back, but got no real
pointers. Seems that there are no tree data model modules out there -
which surprises me, since it is such a fundamental data structure.

I ended up using a very basic tree data class - I didn't need all of
the methods you mentioned. Here it is in case that helps at all:

class Node (object):
def __init__(self, data, parent=None):
self.data = data
self.parent = parent
self.children = []

def add_child(self, child):
self.children.append(child)
child.parent = self

Some of those methods you mentioned would be trivial to implement:

def is_root(self):
return not self.parent
def is_leaf(self):
return not self.children

It may also be more pythonic to have 'walk' methods for traversing
trees.

I may start a tree data structure project - it's something I've been
thinking about for a while, and now it's clear that it's not just me
who uses trees as data structures!

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


Re: blob problems in pysqlite

2006-04-27 Thread Gerhard Häring

[EMAIL PROTECTED] wrote:

Excellent. Got that working. Now, how to get the pickled data out of
the database?

I'm trying to use cPickle.loads(data) (code attached), and I get a:
TypeError: loads() argument 1 must be string, not list [...]
[...]
c.execute(select Images from FileURLInfo where URL= ?;, (DBURL,))
KnownFilesResult = c.fetchall()
print KnownFilesResult#where I get a r/w buffer, as expected


No, you actually get a list of 1-tuples and each tuple has one entry: a 
read-write buffer. Because of the way you filled the table, the list is 
of length 1.



cPickle.loads(KnownFilesResult)#where I get the error described
above.


cPickle.loads will only accept a string, not a buffer, so you need to 
convert the buffer to a string first.


So, if you want your code to work, you can use

print cPickle.loads(str(KnownFilesResult[0][0]))

FWIW there are certainly much better ways to solve the task you're 
solving here. Because right now you're pickling and unpickling data into 
a single table in a relational database. Like you're doing this, this 
buys you nothing *and* you get the complexity of relational databases 
and object (de)marshaling.


If you want to go the relational way, you can create multiple tables and 
using foreign-key relations between them instead of stuffing lists into 
columns of a single table by pickling them.


I've attached an example script that can perhaps inspire you.

-- Gerhard
from pysqlite2 import dbapi2 as sqlite

con = sqlite.connect(:memory:)
cur = con.cursor()

# Create schema

cur.executescript(
create table page (
  page_id integer primary key,
  page_url text
);

create table image (
  page_id integer references page(page_id),
  image_url text,
  imagedata blob
);
)

# Insert example data

import urllib

test_data = {
http://python.org/; : [
http://python.org/images/python-logo.gif;,
http://python.org/images/success/nasa.jpg;
],
http://ruby-lang.org/: [
http://www.ruby-lang.org/image/title.gif;
]
}

for url, img_url_list in test_data.items():
cur.execute(insert into page(page_url) values (?), (url,))
page_id = cur.lastrowid

for img_url in img_url_list:
image_data = urllib.urlopen(img_url).read()
cur.execute(
insert into image(page_id, image_url, imagedata) values (?, ?, ?),
(page_id, img_url, sqlite.Binary(image_data)))

# We have a consistent state here, so we commit
con.commit()

# Show the data

cur.execute(
select page_url, image_url, imagedata
from page inner join image using (page_id)
order by page_url
)
for page_url, image_url, imagedata in cur:
print page_url=, page_url
print image_url=, image_url
print len(imagedata)=, len(imagedata)
print - * 50

cur.close
con.close()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Can you create an instance of a subclass with an existing instance of the base class?

2006-04-27 Thread bruno at modulix
Lawrence D'Oliveiro wrote:
 In article [EMAIL PROTECTED],
  Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 
 
Sandra-24 a écrit :

Lawrence D'Oliveiro wrote:


In article [EMAIL PROTECTED],
Sandra-24 [EMAIL PROTECTED] wrote:



Now that is a clever little trick. I never would have guessed you can
assign to __class__, Python always surprises me in it's sheer
flexibility.

That's because you're still thinking in OO terms. 

It's not quite as simple as all that. I agree that people, escpecially
people with a Java (ew) background overuse OO, when there's often
simpler ways of doing things.

Nope. I mean : they don't overuse OO, they overuse *classes*. AFAIK, OO 
means *object* oriented - not class oriented.
 
 
 Oh great. Now we have someone redefining the concept of OO to evade the 
 point I was making.

redefining ? lol...

 
There are OO languages that don't even have a notion of class.
 
 
 Sounds like stuff I was doing in C (a non-OO language) years ago. Unless 
 you want to count C as an OO language, I think you're going to have to 
 retract this claim.

I think I'm not going to retract anything. And I think you should learn
a bit more about prototype-based languages.

 
However in this case I'm simply getting an object (an mp_request object
from mod_python) passed into my function, and before I pass it on to
the functions that make up and individual web page it is modified by
adding members and methods to add functionality.

Which is a well-known design pattern called decorator.
  
 If you have to think of it as a design pattern, that means you haven't 
 figured out the code reuse angle yet.

Please stop saying non-sense and learn the difference between design and
implementation.

-- 
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: OOP / language design question

2006-04-27 Thread bruno at modulix
Lawrence D'Oliveiro wrote:
 In article [EMAIL PROTECTED],
  Carl Banks [EMAIL PROTECTED] wrote:
 
 
bruno at modulix wrote:

[EMAIL PROTECTED] wrote:

I was wondering, why you always have to remember to call bases'
constructors

pedantic
s/constructors/__init__/

the __init__() method is *not* the constructor. Object's instanciation
is a two-stage process:  __new__() is called first, then __init__().
/pedantic

You know, Python's __init__ has almost the same semantics as C++
constructors (they both initialize something that's already been
allocated in memory, and neither can return a substitute object).  I
actually think constructors are misnamed in C++, they should be called
initializers (and destructors finalizers).
 
 
 Constructor is also the term used for the corresponding method in Java.
 
 Is there any OO language that does not use constructor in this sense? 

Smalltalk. Just like Python, it has constructor *and* initializer.

 I don't think there is one. This is standard OO terminology.

Being standard doesn't imply it's accurate.

-- 
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: begging for a tree implementation

2006-04-27 Thread Diez B. Roggisch
 I may start a tree data structure project - it's something I've been
 thinking about for a while, and now it's clear that it's not just me
 who uses trees as data structures!

Oh, people do use them. It's just to easy to cough one up when you need it -
either as nested tuples, lists, dicts or a simple class like yours - which
I needed yesterday and wrote in 2 minutes. And that is tailored to the
needs at hand and not some abstraction that might prevent you from e.g.
using methods like __iter__ or the like with your own semantics.

This is not to discourage you - just don't expect people to greet you as the
next messiah who finally brought one of CS most fundamental data structures
to Python... :)

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


Re: begging for a tree implementation

2006-04-27 Thread Fredrik Lundh
Diez B. Roggisch wrote:

 This is not to discourage you - just don't expect people to greet you as the
 next messiah who finally brought one of CS most fundamental data structures
 to Python... :)

xml.etree was added to Python 2.5 before christmas :-)

/F 



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


How to align the text of a Listbox to the right

2006-04-27 Thread Leonardo da Vinci
Greetings gentlemen and ladies,
I have a question: in Tkinter, how to align a Listbox entry (i.e. a
line of text) to the right?
Google did not show up the answer to my request.
Thanks very much.

L

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


Re: bug in modulus?

2006-04-27 Thread Christophe
[EMAIL PROTECTED] a écrit :
 I think there might be something wrong with the implementation of
 modulus.
 
 Negative float values close to 0.0 break the identity 0 = abs(a % b)
  abs(b).
 
 print 0.0 % 2.0 # = 0.0
 print -1e-010 % 2.0 # =1.99
 
 which is correct, but:
 
 print -1e-050 % 2.0 # = 2.0
 print -1e-050 % 2.0  2.0 # = False
 
 This means I can't use modulus to wrap around before it reaches a
 certain value. I'm using Python 2.4.2 on WindowsXP.
 
 Thanks
 Janto
 

Consider that -1e-050 % 2.0 = 2.0 - 1e-050

Now, test that :
  2.0 - 1e-050 == 2.0
True

Floating point numbers just don't have the required precision to 
represent 2.0 - 1e-050. For your specific problem, if you really want 
the result to be  2.0, the the best you can do is admit that floating 
point operations have errors and return 0.0 when the modulus operation 
equals 2.0.
-- 
http://mail.python.org/mailman/listinfo/python-list


can anyone advise me

2006-04-27 Thread micklee74
why the output of this code :
x = 0
while x  10:
z = 0
print x
x = x + 1
while z  x:
print z,
z = z + 1

is

0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9  ---extra


instead of :
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9

thanks

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


how to free the big list memory

2006-04-27 Thread kyo guan
Python version 2.4.3

 l=range(50*1024*100)

after this code, you can see the python nearly using about 80MB.

then I do this

 del l

after this, the python still using more then 60MB, Why the python don't free my 
memory?

Is there any way to force the python free my memory?

Thanks.

Kyo.

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


Re: blob problems in pysqlite

2006-04-27 Thread aldonnelley
Woohoo!

You rock, Gerhard. That's inspired. I'm sure I can sort this out now.
Both you and Tim have been an enormous help.

Cheers, Al.
(Oh, and Tim: tip noted. I feel bad about not posting complete code- I
do normally (not in python), but can't for this one. Thanks for wading
your way through it anyway.)

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


Re: help

2006-04-27 Thread NavyJay
For such a simple task, I would use MATLAB.
http://www.mathworks.com/products/matlab/

However, if you have to do generic programming in addition to this, I
would use Python with the libraries ImageMagick or Python Image Library
(PIL).  Just search for them and you'll have all the examples you need.

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


Re: I have problems with creating the classic game Wumpus. the file: http://esnips.c

2006-04-27 Thread conny . ledin
This is so great!!! I know i have alot of work left to do and i
probobly wont make it in time which means that i can only get the grade
E on the assignment... But at this stage it feels like ill be happy
with any grade i get, just to have this behind me. Programming is
apparently not my thing. It feels like the movement was the hardest
part of the prog though, IM HOPING!! THANK YOU 

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


Re: how to free the big list memory

2006-04-27 Thread harold
pydoc gc.collect
pydoc xrange

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


Re: can anyone advise me

2006-04-27 Thread Dan Sommers
On 27 Apr 2006 02:48:46 -0700,
[EMAIL PROTECTED] wrote:

 why the output of this code :
 x = 0
 while x  10:
 z = 0
 print x
 x = x + 1
 while z  x:
 print z,
 z = z + 1

 is

 0

Okay, that was x, from the print statement inside the x-loop.

 0 1

And that's z, from the print statement inside the z-loop.  z is 0, and
then when z is 1, it's not less than x, so we're done printing z's.

And then we get the next x.

 0 1 2

And two more z's, 0 and 1, since x is now 2.

And another x.

Since this might be homework, I'll stop at a hint:  you need to think
about when you want each printed line to end, and make sure that you
tell python to end it there.

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
I wish people would die in alphabetical order. -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can anyone advise me

2006-04-27 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 why the output of this code :
 x = 0
 while x  10:
 z = 0
 print x
 x = x + 1
 while z  x:
 print z,
 z = z + 1
 
 is
 
 0
 0 1
 0 1 2
 0 1 2 3
 0 1 2 3 4
 0 1 2 3 4 5
 0 1 2 3 4 5 6
 0 1 2 3 4 5 6 7
 0 1 2 3 4 5 6 7 8
 0 1 2 3 4 5 6 7 8 9
 0 1 2 3 4 5 6 7 8 9  ---extra
 
 
 instead of :
 0
 0 1
 0 1 2
 0 1 2 3
 0 1 2 3 4
 0 1 2 3 4 5
 0 1 2 3 4 5 6
 0 1 2 3 4 5 6 7
 0 1 2 3 4 5 6 7 8
 0 1 2 3 4 5 6 7 8 9
 
 thanks

Hint: You can modify your code a bit to see where the offending extra line
comes from:

x = 0
while x  10:
z = 0
print x + str(x)
x = x + 1
while z  x:
print z + str(z),
z = z + 1

Surprised? Replace the statement responsible for the extra number with a
bare print,  perhaps moving it around somewhat to avoid the extra blank
line -- and when it works rewrite the script with for loops and range() :-)

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


Re: can anyone advise me

2006-04-27 Thread Gerard Flanagan
[EMAIL PROTECTED] wrote:

 why the output of this code :
 x = 0
 while x  10:
 z = 0
 print x
 x = x + 1
 while z  x:
 print z,
 z = z + 1

 is

 0
 0 1
 0 1 2
 0 1 2 3
 0 1 2 3 4
 0 1 2 3 4 5
 0 1 2 3 4 5 6
 0 1 2 3 4 5 6 7
 0 1 2 3 4 5 6 7 8
 0 1 2 3 4 5 6 7 8 9
 0 1 2 3 4 5 6 7 8 9  ---extra


 instead of :
 0
 0 1
 0 1 2
 0 1 2 3
 0 1 2 3 4
 0 1 2 3 4 5
 0 1 2 3 4 5 6
 0 1 2 3 4 5 6 7
 0 1 2 3 4 5 6 7 8
 0 1 2 3 4 5 6 7 8 9


Does the following help?

x = 0
while x  10:
print 'x'
x = x + 1
z = 0
while z  x:
print z,
z = z + 1

x
0 x
0 1 x
0 1 2 x
0 1 2 3 x
0 1 2 3 4 x
0 1 2 3 4 5 x
0 1 2 3 4 5 6 x
0 1 2 3 4 5 6 7 x
0 1 2 3 4 5 6 7 8 x
0 1 2 3 4 5 6 7 8 9


x = 0
while x  10:
print
x = x + 1
z = 0
while z  x:
print z,
z = z + 1

0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9

Gerard

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


Re: can anyone advise me

2006-04-27 Thread looping
try something like this:

x = 0
while x  10:
z = 0
print '-' + str(x) + '-'
x = x + 1
while z  x:
print '.' + str(z) + '.',
z = z + 1

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


help

2006-04-27 Thread kalyanigoli
Hi!

 I am a new user to python. I want to draw a 2D graph with
coordinates data as input. In the graph i want to fill some area and
also include image maps.
Can any one suggest which is the best library to use and some links for
examples.

Thanks in advance. Your help will be most appreciated.

Kalyani

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


[no subject]

2006-04-27 Thread carlosperezs


Hallo !!!
I am new in Python and my doubts are basics.I would like to a window appears
when press a button. This window would have only an advise. Therefore it would
be a simple window. I don't know which window to choose.

Thank you.

--oOo-oOo--

Servicio de acceso ó correo electrónico vía web da Universidade de Vigo
Servicio de acceso al correo electrónico vía web de la Universidad de Vigo

Servicios Informáticos [ http://si.uvigo.es ]
Universidade de Vigo [ http://www.uvigo.es ]

URL: https://correoweb.uvigo.es

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


[no subject]

2006-04-27 Thread UMASANKAR LAKSHMANAN
hi,

I want some simple program for :

timer thread
running program in timer thread
how to get notified when program is closed

Thanks in advance

Regards
Ums

UMASANKAR L.
704-B, SHIVARANJANI APARTMENTS  213, NAGAPRABHA CHAMBERS
ITI LAYOUT, BSK III STAGE   3rd MAIN, 4th CROSS
NEAR VIDYA PEETA CIRCLE CHAMRAJPET
KATHRIGUPPA MAIN ROAD   BANGALORE - 560 018
BANGALORE - 560 085 Ph : 91 80 6601086 Ext : 127
Ph : 91 80 6891454 6602365



__ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


midipy.py on linux

2006-04-27 Thread Will Hurt
Hi
Ive been using midipy in my blender3d python scripts on windowsXP, now
im trying to run them from ubuntu and i cant find the midipy.py module
compiled for linux anywhere. 
Is it possible to complie it under linux and how would i go about doing
it --or--
Is there another module which does the same thing available for linux[ie
i can get raw midi data in as a list] and thats why no-ones bothered to
compile midipy under linux?

Thanks
Will



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


Re: can anyone advise me

2006-04-27 Thread micklee74

Dan Sommers wrote:
 On 27 Apr 2006 02:48:46 -0700,
 [EMAIL PROTECTED] wrote:

  why the output of this code :
  x = 0
  while x  10:
  z = 0
  print x
  x = x + 1
  while z  x:
  print z,
  z = z + 1

  is

  0

 Okay, that was x, from the print statement inside the x-loop.

  0 1

 And that's z, from the print statement inside the z-loop.  z is 0, and
 then when z is 1, it's not less than x, so we're done printing z's.

 And then we get the next x.

  0 1 2

 And two more z's, 0 and 1, since x is now 2.

 And another x.

 Since this might be homework, I'll stop at a hint:  you need to think
 about when you want each printed line to end, and make sure that you
 tell python to end it there.

 Regards,
 Dan

 --
 Dan Sommers
 http://www.tombstonezero.net/dan/
 I wish people would die in alphabetical order. -- My wife, the genealogist


thanks..solved...just removed the print x..

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


Re: Inherit from array

2006-04-27 Thread TG
Hmm ... I'm definitely not a python wizard, but it seems to be quite a
special case that breaks the rules ... unpythonic, isn't it ?

Has anyone seen a PEP on this subject ?

Just in case a troll reads this message : i'm not saying python sucks
or has huge design flaws here ...

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


Re: begging for a tree implementation

2006-04-27 Thread Ant
Damn! Missed the boat ;-)

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


Re: A QFB agent: how to catch C-level crashes and last Python stack ?

2006-04-27 Thread Thomas Heller
robert wrote:
 When employing complex UI libs (wx, win32ui, ..) and other extension 
 libs, nice only Python stack traces remain a myth.
 
 Currently I'm hunting again a rare C-level crash bug of a Python based 
 Windows app with rare user reports - and still in the dark (I get 
 snippets of machine stack traces / screenshots with random mem. access 
 error / python caused the runtime to terminate in an unusual way / ..)
 
 I'd like to hook a kind of quality feedback agent a C-level to enable 
 the user transfer a report (similar to what Mozilla/Netscape has), e.g. 
 in a changed python.exe stub. Next to the machine stack/regs it should 
 grab the relevant last Python thread stack(s), if any, and maybe other 
 useful status and python global vars.
 (There are also Python threads going on. )
 
 Is that possible?
 
 -robert

It looks like this may be what you want.  Quoting from

http://www.usenix.org/events/usenix01/full_papers/beazley/beazley.pdf


In recent years, scripting languages such as Perl,
Python, and Tcl have become popular development tools
for the creation of sophisticated application software.
One of the most useful features of these languages is
their ability to easily interact with compiled languages
such as C and C++. Although this mixed language approach
has many benefits, one of the greatest drawbacks
is the complexity of debugging that results from using
interpreted and compiled code in the same application.
In part, this is due to the fact that scripting language
interpreters are unable to recover from catastrophic errors
in compiled extension code. Moreover, traditional
C/C++ debuggers do not provide a satisfactory degree
of integration with interpreted languages. This paper
describes an experimental system in which fatal extension
errors such as segmentation faults, bus errors, and
failed assertions are handled as scripting language exceptions.
This system, which has been implemented as
a general purpose shared library, requires no modifications
to the target scripting language, introduces no performance
penalty, and simplifies the debugging of mixed
interpreted-compiled application software.


It may be an interesting project to port this to Windows.

Hope that helps,

Thomas

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


Re: Packing a list of lists with struct.pack()

2006-04-27 Thread Fredrik Lundh
Panos Laganakos wrote:

 What I don't understand is what are you doing with *(...), this is
 supposed to pack its contents as a list?

the *arg form treats each value in the arg sequence as a separate argument.
for example,

arg = 1, 2, 3
function(*arg)

is the same thing as

function(1, 2, 3)

when used with a generator expression, *(genexp) simply fetches the arguments
from the generated sequence.

(note that struct.pack expects a format string plus N additional arguments, not
a format string and an N-item sequence)

/F 



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


Re: MinGW and Python

2006-04-27 Thread sturlamolden

Martin v. Löwis wrote:

 That's not how I read it. To me, it says: it can be used by other
 parts of Windows itself (i.e. system-level components), but it is not
 intended to be used by third-party applications (such as Python),
 as these are not system-level components.

That is correct. And it is the reson why the  MinGW team is working on
removing the dependency on this CRT. I

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


searching for an article on name-binding

2006-04-27 Thread Gerard Flanagan
Hello

I'm trying to find a webpage I remember reading which contained a
layman's description of how Python binds names to objects. It used some
ASCII-art illustrations where an arrow represented a 'binding'. Anyone
got a link for that? (Google's not my friend!)

Thanks

Gerard

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


Re: Inherit from array

2006-04-27 Thread bruno at modulix
TG wrote:
 Hmm ... I'm definitely not a python wizard, but it seems to be quite a
 special case that breaks the rules ... 

Yes and no. The primary use case for __new__ was to allow subclassing of
immutable types. array.array is not immutable, but it's still a special
case, in that it enforce type-based restrictions.

I guess that it does so by creating different types based on the
typecode (this is low-level, C stuff), so this can only happen in the
constructor (the object is already created when the initializer is called).

 unpythonic, isn't it ?

Not really - practicallity beats purity !-)

But this should definitively be documented. I don't have time to do so
right now  - anybody willing to take care of this ?


-- 
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: searching for an article on name-binding

2006-04-27 Thread Fredrik Lundh
Gerard Flanagan wrote:

 I'm trying to find a webpage I remember reading which contained a
 layman's description of how Python binds names to objects. It used some
 ASCII-art illustrations where an arrow represented a 'binding'. Anyone
 got a link for that? (Google's not my friend!)

http://www.python.net/crew/mwh/hacks/objectthink.html

/F 



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


urllib.urlopen() with pages that requires cookies.

2006-04-27 Thread Øyvind Østlund
I am trying to visit a limited amount of web pages that requires
cookies. I will get redirected if my application does not handle them.
I am using urllib.urlopen() to visit the pages right now. And I need a
push in the right direction to find out how to deal with pages that
requires cookies. Anyone have any idea how to go about this?



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

Re: MinGW and Python

2006-04-27 Thread sturlamolden

Martin v. Löwis wrote:


  Nonetheless, Cygwin applications are not generally considered native
  Win32 applications because of the dependency on CYGWIN1.DLL and the
  related environment.

 - Is winword.exe not a native Win32 library because it uses MSO.DLL?
 - A cygwin application does *not* require the Cygwin environment.

Cygwin executables are native windows .exe files just like MinGW
executables. They are built by the same compiler, a port of GCC to 32
bit Windows originally written by Mumit Khan. MinGW and Cygwin apps run
at the same speed. However, the CYGWIN1.dll is bloated and an has
unwanted overhead for many system calls. But as such, CYGWIN1.dll is
nothing more than a CRT with extended Linux API support, including
posix and xlib.

The problem is actually *licensing issues* related to CYGWIN1.DLL. It
cannot always be linked. CYGWIN1.DLL can only be used for Open Source
development.

In accordance with section 10 of the GPL, Red Hat permits programs
whose sources are distributed under a license that complies with the
Open Source definition to be linked with libcygwin.a/cygwin1.dll
without libcygwin.a/cygwin1.dll itself causing the resulting program to
be covered by the GNU GPL.

Thus, if you have a commercial closed source application, you need to
use MinGW; that is, you cannot link with libcygwin.a/cygwin1.dll.

I am not sure if Cygwin has link libraries for the Win32 API. Is there
e.g. a libuser32.a for linking with user32.dll? But MinGW has that.

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


Re: MinGW and Python

2006-04-27 Thread sturlamolden

Martin v. Löwis wrote:


  Nonetheless, Cygwin applications are not generally considered native
  Win32 applications because of the dependency on CYGWIN1.DLL and the
  related environment.

 - Is winword.exe not a native Win32 library because it uses MSO.DLL?
 - A cygwin application does *not* require the Cygwin environment.

Cygwin executables are native windows .exe files just like MinGW
executables. They are built by the same compiler, a port of GCC to 32
bit Windows originally written by Mumit Khan. MinGW and Cygwin apps run
at the same speed. However, the CYGWIN1.dll is bloated and an has
unwanted overhead for many system calls. But as such, CYGWIN1.dll is
nothing more than a CRT with extended Linux API support, including
posix and xlib.

The problem is actually *licensing issues* related to CYGWIN1.DLL. It
cannot always be linked. CYGWIN1.DLL can only be used for Open Source
development.

In accordance with section 10 of the GPL, Red Hat permits programs
whose sources are distributed under a license that complies with the
Open Source definition to be linked with libcygwin.a/cygwin1.dll
without libcygwin.a/cygwin1.dll itself causing the resulting program to
be covered by the GNU GPL.

Thus, if you have a commercial closed source application, you need to
use MinGW; that is, you cannot link with libcygwin.a/cygwin1.dll.

I am not sure if Cygwin has link libraries for the Win32 API. Is there
e.g. a libuser32.a for linking with user32.dll? But MinGW has that.

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


Re: can anyone advise me

2006-04-27 Thread egbert
On Thu, Apr 27, 2006 at 02:48:46AM -0700, [EMAIL PROTECTED] wrote:
 why the output of this code :
 x = 0
 while x  10:
 z = 0
 print x
 x = x + 1
 while z  x:
 print z,
 z = z + 1
 
 is
 
 0
 0 1
 0 1 2
 0 1 2 3
 0 1 2 3 4
 0 1 2 3 4 5
 0 1 2 3 4 5 6
 0 1 2 3 4 5 6 7
 0 1 2 3 4 5 6 7 8
 0 1 2 3 4 5 6 7 8 9
 0 1 2 3 4 5 6 7 8 9  ---extra
 
 
 instead of :
 0
 0 1
 0 1 2
 0 1 2 3
 0 1 2 3 4
 0 1 2 3 4 5
 0 1 2 3 4 5 6
 0 1 2 3 4 5 6 7
 0 1 2 3 4 5 6 7 8
 0 1 2 3 4 5 6 7 8 9
 
In your nested loop you are printing an x followed by zero or
more z's, but only after each x, including the first one,
you switch to a new line.
So the last digit on each line is an x, except for the last line,
which are z's printed after the 9 (an x) ending the line above it.

Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


Re: MinGW and Python

2006-04-27 Thread sturlamolden

Martin v. Löwis wrote:


  Nonetheless, Cygwin applications are not generally considered native
  Win32 applications because of the dependency on CYGWIN1.DLL and the
  related environment.

 - Is winword.exe not a native Win32 library because it uses MSO.DLL?
 - A cygwin application does *not* require the Cygwin environment.

Cygwin executables are native windows .exe files just like MinGW
executables. They are built by the same compiler, a port of GCC to 32
bit Windows originally written by Mumit Khan. MinGW and Cygwin apps run
at the same speed. However, the CYGWIN1.dll is bloated and an has
unwanted overhead for many system calls. But as such, CYGWIN1.dll is
nothing more than a CRT with extended Linux API support, including
posix and xlib.

The problem is actually *licensing issues* related to CYGWIN1.DLL. It
cannot always be linked. CYGWIN1.DLL can only be used for Open Source
development.

In accordance with section 10 of the GPL, Red Hat permits programs
whose sources are distributed under a license that complies with the
Open Source definition to be linked with libcygwin.a/cygwin1.dll
without libcygwin.a/cygwin1.dll itself causing the resulting program to
be covered by the GNU GPL.

Thus, if you have a commercial closed source application, you need to
use MinGW; that is, you cannot link with libcygwin.a/cygwin1.dll.

I am not sure if Cygwin has link libraries for the Win32 API. Is there
e.g. a libuser32.a for linking with user32.dll? But MinGW has that.

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


Re: MinGW and Python

2006-04-27 Thread Gerhard Häring
sturlamolden wrote:
 [...] The problem is actually *licensing issues* related to CYGWIN1.DLL. It
 cannot always be linked. CYGWIN1.DLL can only be used for Open Source
 development. [...]

Of course Redhat offers an alternative license that does not have the 
GPL restrictions: http://www.redhat.com/software/cygwin/

Like other annoying companies, they don't tell any rates at their 
website and make you call them up if you're interested. Cowards.

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


RELEASED Python 2.5 (alpha 2)

2006-04-27 Thread Anthony Baxter
On behalf of the Python development team and the Python
community, I'm happy to announce the second alpha release
of Python 2.5.

This is an *alpha* release of Python 2.5. As such, it is not
suitable for a production environment. It is being released to
solicit feedback and hopefully discover bugs, as well as allowing
you to determine how changes in 2.5 might impact you. If you find
things broken or incorrect, please log a bug on Sourceforge.

In particular, note that changes to improve Python's support
of 64 bit systems might require authors of C extensions to change
their code. More information (as well as source distributions and
Windows installers) are available from the 2.5 website:

http://www.python.org/2.5/

Since the first alpha, a host of bug fixes and smaller new features
have been added. See the release notes (available from the 2.5
webpage) for more.

The plan from here is for either one more alpha release, or (more
likely) moving to the beta releases, then moving to a 2.5 final
release around August.  PEP 356 includes the schedule and will be
updated as the schedule evolves.

The new features in Python 2.5 are described in Andrew Kuchling's
What's New In Python 2.5. It's available from the 2.5 web page.

Amongst the language features added include conditional expressions,
the with statement, the merge of try/except and try/finally into
try/except/finally, enhancements to generators to produce a
coroutine kind of functionality, and a brand new AST-based compiler
implementation.

New modules added include hashlib, ElementTree, sqlite3 and ctypes.
In addition, a new profiling module cProfile was added. In addition,
in the second alpha we have the new 'mailbox' module (a product of
last years Google Summer of Code).

Enjoy this new release,
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)


pgpq9NXF2QRxG.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Unpacking a list of strings

2006-04-27 Thread Panos Laganakos
Is there some other practice than reading all the strings and slicing
them later?

They're stored in the form of:
List Group[10]:
char[17] name;

So I thought of doing:
unpacked = unpack('%s' % (10*17), data)

And then slicing the list by a step of 17.

Is there some way to have unpack return a tuple with each element
holding the name (char[17])?

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


Re: print names of dictionaries

2006-04-27 Thread Philippe Martin
Hi,

I do not know if there is a way to overload the instantiation of all objects
in Python but I thought of something like this to fetch any object with its
name:

g_dict = {}


def create_object (v,s):
   p = v
   g_dict[s] = id(p)
   return p

#ex
object = create_object ([1,2,3,4], 'A LIST')

Philippe





Thomas Nelson wrote:

 Here's an OO way that may do what you want:
 class MyD(dict):
 ... def __init__(self,dic,rep):
 ... dict.__init__(self,dic)
 ... self.rep = rep
 ... def __repr__(self):
 ... return self.rep
 ...
 apps = MyD({'alpha':1,'beta':2},'apps')
 apps
 apps
 apps.keys()
 ['alpha', 'beta']
 
 Of course, the easiest way is just to use a tuple (dict,string).
 
 THN

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


Re: print names of dictionaries

2006-04-27 Thread Philippe Martin
OK, totally dumb !

g_dict[s] = p




Philippe Martin wrote:

 Hi,
 
 I do not know if there is a way to overload the instantiation of all
 objects in Python but I thought of something like this to fetch any object
 with its name:
 
 g_dict = {}
 
 
 def create_object (v,s):
p = v
g_dict[s] = id(p)
return p
 
 #ex
 object = create_object ([1,2,3,4], 'A LIST')
 
 Philippe
 
 
 
 
 
 Thomas Nelson wrote:
 
 Here's an OO way that may do what you want:
 class MyD(dict):
 ... def __init__(self,dic,rep):
 ... dict.__init__(self,dic)
 ... self.rep = rep
 ... def __repr__(self):
 ... return self.rep
 ...
 apps = MyD({'alpha':1,'beta':2},'apps')
 apps
 apps
 apps.keys()
 ['alpha', 'beta']
 
 Of course, the easiest way is just to use a tuple (dict,string).
 
 THN

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


Re: list of functions question

2006-04-27 Thread Kent Johnson
val bykoski wrote:
 Hi The List:
I have a modeling app where i'm detecting events (in temporal 
 dynamics) applying a set of (boolean) functions - kind of:
 
 event_list = f1 f2 etc.split()  # each fi detects a specific event
 i have defs for functions fi, or simple boolean expressions for each, so 
 that evList is a list of defs or boolean expressions
 for ev in evList:
 if ev:# this supposedly is a call ev(t)
# doing smth with the event

# Make a list of the actual functions, not their names
# For the events that are expressions, encapsulate them in functions
event_list = [f1, f2, etc]

# Call each one:
for ev in event_list:
   if ev(t):
 # do something

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


Re: can this be done without eval/exec?

2006-04-27 Thread Kent Johnson
Schüle Daniel wrote:
 and now the obvious one (as I thought at first)
 
   lst=[]
   for i in range(10):
 ... lst.append(lambda:i)
 ...
   lst[0]()
 9
   i
 9
  
 
 I think I understand where the problem comes from
 lambda:i seems not to be fully evalutated
 it just binds object with name i and not the value of i
 thus lst[0]() is not 0

The problem is that variables in closures are not bound until the 
variable goes out of scope. So each lambda is bound to the final value of i.
 
 are there other solutions to this problem
 without use of eval or exec?

The workaround is to use a default argument to bind the current value of i:
In [1]: lst = []

In [2]: for i in range(10):
...: lst.append(lambda i=i: i)
...:
...:

In [3]: lst[0]()
Out[3]: 0

In [4]: lst[5]()
Out[4]: 5

A list comp makes this IMO cleaner:
In [5]: lst = [ lambda i=i: i for i in range(10) ]

In [6]: lst[0]()
Out[6]: 0

In [7]: lst[5]()
Out[7]: 5

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


Re: How to align the text of a Listbox to the right

2006-04-27 Thread Eric Brunel
On 27 Apr 2006 02:35:50 -0700, Leonardo da Vinci  
[EMAIL PROTECTED] wrote:

 Greetings gentlemen and ladies,
 I have a question: in Tkinter, how to align a Listbox entry (i.e. a
 line of text) to the right?

In a real Listbox, the answer is simple: you can't.

What are you trying to do? Maybe there is another widget more suited to  
your needs.
-- 
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Packing a list of lists with struct.pack()

2006-04-27 Thread Panos Laganakos
Unfortunately I'm familiar with the generator concept, I'll look into
it though, 'cause it saved me at least once already :)

Thanks mate.

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


Re: searching for an article on name-binding

2006-04-27 Thread Gerard Flanagan

Fredrik Lundh wrote:

 Gerard Flanagan wrote:

  I'm trying to find a webpage I remember reading which contained a
  layman's description of how Python binds names to objects. It used some
  ASCII-art illustrations where an arrow represented a 'binding'. Anyone
  got a link for that? (Google's not my friend!)

 http://www.python.net/crew/mwh/hacks/objectthink.html
 
 /F

That's it! Thanks.

Gerard

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


Re: How to align the text of a Listbox to the right

2006-04-27 Thread Leonardo da Vinci
I have to use a Listbox that shows a list of entries. Every entry is a
char string quite long in size and I cannot set width to a large
value due to limitations of screen resolution. The rightmost part is
more important, so I thought that I could show only the end of the
string by aligning the field to the right.

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


Re: Twisted and Tkinter

2006-04-27 Thread [EMAIL PROTECTED]
Posting that error message would be helpful

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


Re: urllib.urlopen() with pages that requires cookies.

2006-04-27 Thread Fredrik Lundh
Øyvind Østlund wrote:

 I am trying to visit a limited amount of web pages that requires cookies. I
 will get redirected if my application does not handle them. I am using
 urllib.urlopen() to visit the pages right now. And I need a push in the
 right direction to find out how to deal with pages that requires cookies.
 Anyone have any idea how to go about this?

use urllib2 and cookielib.  here's an outline:

import urllib2, cookielib

# set things up
jar = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(jar)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)

data = urllib2.urlopen(someurl).read()

# ...

data = urllib2.urlopen(someotherurl).read()

# ...

# dump cookie jar contents (for debugging)
for cookie in jar:
print cookie

/F



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

String Exceptions (PEP 352)

2006-04-27 Thread Thomas Guettler

Hi,

I like python because it is compatible to old versions. That's way I think
string exceptions should not be deprecated.

I use string exceptions if the condition for an assertion is
to complex:

if foo and bar and i10:
raise if foo and bar i must not be greater than 10

This way I can easily add checkpoints to my code.

Is it too late to change this? Way not make this line

raise ...

behave like this:

raise Exception(...)   

in the future?

I know that catching string exceptions and reading the
string is different from Exception(...). This could
become deprecated.

Please keep Python compatible to old versions.

 Thomas Güttler

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: Twisted and Tkinter

2006-04-27 Thread Chris
Sorry. The error message is normally AttributeError: 'NoneType' object
has no attribute 'sendLine'

[EMAIL PROTECTED] wrote:
 Posting that error message would be helpful

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


Re: String Exceptions (PEP 352)

2006-04-27 Thread infidel
You could also use the assert statement:

 if foo and bar:
... assert i = 10, if foo and bar then i must not be greater than
10
...

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


Re: String Exceptions (PEP 352)

2006-04-27 Thread bruno at modulix
Thomas Guettler wrote:
 Hi,
 
 I like python because it is compatible to old versions. That's way I think
 string exceptions should not be deprecated.
 
 I use string exceptions if the condition for an assertion is
 to complex:
 
 if foo and bar and i10:
 raise if foo and bar i must not be greater than 10

What's wrong with:

assert foo and bar and i  10, \
  if foo and bar i must not be greater than 10



(snip)

 Please keep Python compatible to old versions.

MHO
When there's too much hysterical cruft and warts accumulated from the
past, it's time to throw away and clean up, even if it breaks a lot of
things. Trying to keep compatibility at any price would be just suicidal
IMHO - time to get rid of old warts and come back to simplicity. one
obvious way to do it rules.
/MHO

-- 
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: Twisted and Tkinter

2006-04-27 Thread Fredrik Lundh
Chris wrot:

 Sorry. The error message is normally AttributeError: 'NoneType' object
 has no attribute 'sendLine'

please post the *entire* traceback, including the part that lists
filenames, line numbers, and source code lines.

/F



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


Re: String Exceptions (PEP 352)

2006-04-27 Thread bruno at modulix
bruno at modulix wrote:
 Thomas Guettler wrote:
 
Hi,

I like python because it is compatible to old versions. That's way I think
string exceptions should not be deprecated.

I use string exceptions if the condition for an assertion is
to complex:

if foo and bar and i10:
raise if foo and bar i must not be greater than 10
 
 
 What's wrong with:
 
 assert foo and bar and i  10, \
   if foo and bar i must not be greater than 10
 

oops ! I meant:
if foo and bar:
  assert i  10,  if foo and bar i must not be greater than 10

My bad :(


-- 
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: Editing a function in-memory and in-place

2006-04-27 Thread bruno at modulix
Peter Otten wrote:
(snip)
 
 Can you cheat and just assign another known good func_code object?
def hello(): print hello
 ...
def world(): print world
 ...
def use_it(hello=hello, world=world):
 ... hello()
 ... world()
 ...
use_it()
 hello
 world
world.func_code = hello.func_code
use_it()
 hello
 hello
hello, world
 (function hello at 0x402904fc, function world at 0x40290534)

+1 H2OTW !-)

(NB : H2 - Horrible Hack)

-- 
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: begging for a tree implementation

2006-04-27 Thread Diez B. Roggisch
Fredrik Lundh wrote:

 Diez B. Roggisch wrote:
 
 This is not to discourage you - just don't expect people to greet you as
 the next messiah who finally brought one of CS most fundamental data
 structures to Python... :)
 
 xml.etree was added to Python 2.5 before christmas :-)

Can't wait until etree grows some tree optimization algorithms like AVL or
red-black. Those degenerated XML-documents of mine always annoyed me.. :)

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


A fix to bluepin

2006-04-27 Thread Fulvio
Hello List,

I'm very beginner on programming, I''m studing some fix on the Bluez's 
bluepin, which is rather vague to control the given input.

Code /start:
=
def main(*args):
if len(sys.argv)  2:
print ERR
sys.exit()

dir= sys.argv[1]
bdaddr = sys.argv[2]

if len(sys.argv)  3:
name = sys.argv[3]
else:
name = 

title = Bluetooth PIN Code

# Bluetooth spec recommends automatic strong random PIN generation.
# So eventually we should implement that. 
pin = { PIN:  }

if dir == out:
mesg = Outgoing connection to 
else:
mesg = Incoming connection from 

mesg = mesg + name + [ + bdaddr + ]

if dialog(title, mesg, pin) == DLG_OK:
pin[PIN] = string.strip(pin[PIN])
for i in pin:
if i not in digits:
print ERR
break

if len(pin[PIN]) = 1 and len(pin[PIN]) = 16:
print PIN: + pin[PIN]
else:
print ERR
else:
print ERR

#
main()
=
Code /end:

Assumed that digits is:
  from string import digits  (equal to 1234567890)
(Perhaps I could avoid such import ad assigned directly :-) )
Assumed that the purpose would be to don't print ERR but to return back to 
main.
Therefore may I recursively call main() ?
Does it re-open a new window, if I do so?
Does it re-ask new args?

Thanks for the patience to give some input here
PS. sorry the code is in tabs not in space :-(

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


Re: urllib.urlopen() with pages that requires cookies.

2006-04-27 Thread mwt

Fredrik Lundh wrote:
 Øyvind Østlund wrote:

  I am trying to visit a limited amount of web pages that requires cookies. I
  will get redirected if my application does not handle them. I am using
  urllib.urlopen() to visit the pages right now. And I need a push in the
  right direction to find out how to deal with pages that requires cookies.
  Anyone have any idea how to go about this?

 use urllib2 and cookielib.  here's an outline:

 import urllib2, cookielib

 # set things up
 jar = cookielib.CookieJar()
 handler = urllib2.HTTPCookieProcessor(jar)
 opener = urllib2.build_opener(handler)
 urllib2.install_opener(opener)

 data = urllib2.urlopen(someurl).read()

 # ...

 data = urllib2.urlopen(someotherurl).read()

 # ...

 # dump cookie jar contents (for debugging)
 for cookie in jar:
 print cookie

 /F

How would this outline be changed/expanded if it also needed to handle
basic authentication?

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


writing some lines after reading goes wrong on windows?

2006-04-27 Thread yichao.zhang
Hi all
I can not write anything if I have read something.
the code as:


Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
on win32
IDLE 1.1.3
 a=open('d:\\a','r+')
 a
open file 'd:\a', mode 'r+' at 0x00A147B8
 a.read()
'11\n22\n33\n'
 a.seek(0)
 a.read(1)
'1'
 a.write(a)
 a.seek(0)
 a.read()
'11\n22\n33\n'   # it fails to write after reading

 a.seek(0)
 a.write(a)
 a.seek(0)
 a.read()
'a1\n22\n33\n'  # it writes fine at the beginning of
the file


it fails to write a. but on my debian box, it works fine.
the code on debian as:
 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.
 a=open('/a','r+')
 a
open file '/a', mode 'r+' at 0x4019dd60
 a.read()
'11\n22\n33\n'
 a.seek(0)
 a.read(1)
'1'
 a.write(a)
 a.seek(0)
 a.read()
'1a\n22\n33\n'
 

What's wrong here? is this a bug on windows platform.

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


finding IP address of computer

2006-04-27 Thread Chris
How do I find and print to screen the IP address of the computer my
python program is working on?

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


Re: begging for a tree implementation

2006-04-27 Thread DogWalker
Micah wrote:

 I'm looking for a simple tree implementation: 0-n children, 1 root.
 All the nice methods would be appreciated (getLeaves, isLeaf, isRoot,
 depthfirst, breadthfirst,...)  That's really all I need.  I could code
 one up, but it would take time to debug, and i'm really short on time
 right now.
 
 Thanks!
 Micah
 

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

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


Re: Unpacking a list of strings

2006-04-27 Thread Alex Martelli
Panos Laganakos [EMAIL PROTECTED] wrote:

 Is there some other practice than reading all the strings and slicing
 them later?
 
 They're stored in the form of:
 List Group[10]:
 char[17] name;
 
 So I thought of doing:
 unpacked = unpack('%s' % (10*17), data)
 
 And then slicing the list by a step of 17.
 
 Is there some way to have unpack return a tuple with each element
 holding the name (char[17])?

unpack by formatstring 10*'17s' ...


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


Re: finding IP address of computer

2006-04-27 Thread Gregor Horvath
Chris schrieb:
 How do I find and print to screen the IP address of the computer my
 python program is working on?
 

IP adresses are bound to network interfaces not to computers.
One Computer can have multiple network interfaces.

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread BartlebyScrivener
One way:

 import socket
 socket.getaddrinfo(socket.gethostname(), None)[0][4][0]

It was the first google hit

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


Get all attributes of a com object

2006-04-27 Thread eicwo01
Without to know the names, is it possible to dump all attributes of a
com object?
from win32com.adsi import *
objDom = ADsOpenObject(LDAP:/ ...
print ???all attributes??? of objDom

Thanks
Wolfgang

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


Re: not quite 1252

2006-04-27 Thread Anton Vredegoor
John Machin wrote:

 Firstly, this should be 'content.xml', not 'contents.xml'.

Right, the code doesn't do *anything* :-( Thanks for pointing that out. 
At least it doesn't do much harm either :-|

 Secondly, as pointed out by Sergei, the data is encoded by OOo as UTF-8 
 e.g. what is '\x94' in cp1252 is \u201d which is '\xe2\x80\x9d' in 
 UTF-8. The kill_gremlins function is intended to fix Unicode strings 
 that have been obtained by decoding 8-bit strings using 'latin1' instead 
 of 'cp1252'. When you pump '\xe2\x80\x9c' through the kill_gremlins 
 function, it changes the \x80 to a Euro symbol, and leaves the other two 
 alone. Because the \x9d is not defined in cp1252, it then causes your 
 code to die in a hole when you attempt to encode it as cp1252: 
 UnicodeEncodeError: 'charmap' codec can't encode character u'\x9d' in 
 position 1761: character maps to undefined

Yeah, converting to cp1252 was all that was necessary, like Sergei wrote.

 I don't see how this code repairs anything (quite the contrary!), unless 
 there's some side effect of just read/writestr. Enlightenment, please.

You're quite right. I'm extremely embarrassed now. What's left for me is 
just to explain how it got this bad.

First I noticed that by extracting from content.xml using OOopy's 
getiterator function, some \x94 codes were left inside the document.

But that was an *artifact*, because if one prints something using 
s.__repr__() as is used for example when printing a list of strings 
(duh) the output is not the same as when one prints with 'print s'. I 
guess what is called then is str(s).

Ok, now we have that out of the way, I hope.

So I immediately posted a message about conversion errors, assuming 
something in the open office xml file was not quite 1252. In fact it 
wasn't, it was UTF-8 like Sergei wrote, but it was easy to convert it to 
cp1252, no problem.

Then I also noticed that not all xml-tags were printed if I just 
iterated the xml-tree and filtered out only those elements with a text 
attribute, like 'if x.text: print x'

In fact there are a lot of printable things that haven't got a text 
attribute, for example some items with tag ()s.

When F pointed me to gremlins there was on this page the following text:

quote

Some applications add CP1252 (Windows, Western Europe) characters to 
documents marked up as ISO 8859-1 (Latin 1) or other encodings. These 
characters are not valid ISO-8859-1 characters, and may cause all sorts 
of problems in processing and display applications.

/quote

I concluded that these \x94 codes (which I didn't know about them being 
a figment of my representation yet) were responsible for my iterator 
skipping over some text elements, but in fact the iterator skipped them 
because they had no text attribute even though they were somehow 
containing text.

Now add my natural tendency to see that what I think is the case rather 
than neutrally observing the world as it is into the mix and of course I 
saw the \x94 disappear (but that was because I now was printing them 
straight and not indirectly as elements of a list) and also I thought 
that now the xml-parsing 'errors' had disappeared but that was just 
because I saw some text element appear that I thought I hadn't seen 
before (but in fact it was there all the time).

One man's enlightenment sometimes is another's embarrassment, or so it 
seems. Thanks to you all clearing up my perceptions, and sorry about all 
the confusion I created.

What I want to know next is how to access and print the elements that 
contain text but have no text attribute, that is, if it's not to taxing 
on my badly damaged ego.

Anton







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


Re: finding IP address of computer

2006-04-27 Thread Chris
hehe, works a charm, cheers mate.

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


Re: Twisted and Tkinter

2006-04-27 Thread Chris
Exception in Tkinter callback
Traceback (most recent call last):
  File C:\Python24\lib\lib-tk\Tkinter.py, line 1345, in __call__
return self.func(*args)
TypeError: unbound method sendMessage() must be called with ChatFactory
instance
 as first argument (got nothing instead)

I have simplified the code as well, now attached below:

from twisted.internet import reactor
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.protocols.basic import LineReceiver
from Tkinter import *
from twisted.internet import tksupport

class ChatClient(LineReceiver):

def connectionMade(self):
self.sendLine(Hello server)

def lineReceived(self, line):
print line

def connectionLost(self, reason):
pass


class ChatFactory(ClientFactory):

protocol = ChatClient

def clientConnectionFailed(self, connector, reason):
reactor.stop()

def clientConnectionLost(self, connector, reason):
reactor.stop()

def sendMessage(self):
self.sendLine(Test)

root = Tk()
b1 = Button(root,text=Send)
b1.configure(command=ChatFactory.sendMessage)
b1.pack()
tksupport.install(root)

reactor.connectTCP('localhost',8886,ChatFactory())
reactor.run()

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


  1   2   3   >