Re: Amara: Where's my attribute?

2006-07-04 Thread AdSR
[EMAIL PROTECTED] wrote:
> What is the actual problem you're trying to solve?  If you just want to
> force a namespace declaration in output (this is sually to support
> QNames in content) the most well-known XML hack is to create a dummy
> attribute with the needed prefix and namespace.  But this does not work
> when you're trying to force a default namespace declaration.  Then
> again, you generally can't use QNames in content with a default
> namespace declaration.  So my guess is that you somehow got way off the
> rails in your problem-solving, and you'll need to provide mre
> background if you want help.

I wanted to remove documentation elements from some XML Schema files.
The problem showed when I tried to use the stripped schemas, because
the namespace declaration for user-defined types was missing. Of
course, since these types are named and referred to in attribute
*values*, Amara had no way to know that the namespace declaration was
still needed (didn't matter if default or non-default). This is more a
problem of how XML Schema is defined against XML namespace rules, since
XML Schena uses namespaces in a context of which XML parsers aren't
normally aware.

> BTW, I recommend upgrading to Amara 1.1.7.  That branch will soon be
> 1.2, and I consider it more mature than 1.0 at this point.  The API's
> also easier:

I know, especially the insert-before/after feature :) But I ran into a
problem that I describe below and you advertised 1.0 as "stable
version", so I switched immediately.

The problem can be reproduced like this:

>>> import amara
>>> amara.parse('http://www.w3.org/2001/XMLSchema.xsd')
START DTD xs:schema -//W3C//DTD XMLSCHEMA 200102//EN XMLSchema.dtd
http://www.w3.org/2001/datatypes.dtd:99:23: Attribute 'id' already
declared
http://www.w3.org/2001/datatypes.dtd:122:23: Attribute 'id' already
declared
http://www.w3.org/2001/datatypes.dtd:130:27: Attribute 'id' already
declared
...some 40 more lines like this and then Python crashes (Windows shows
the bug-reporting dialog)

Thanks for your interest,

AdSR

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


Re: Amara: Where's my attribute?

2006-06-29 Thread AdSR
Fredrik Lundh wrote:
> [cut]
> the documents are 100% identical in XML infoset terms, so what's the problem 
> here ?

Looks like the problem is somewere else, after all: Some software
relies on these "unused" xmlns attributes, most notably XML Schema
tools. Which is unfortunate, because xmlns attributes indeed have the
full right to receive special treatment.

> > I see that people have reported similar problems with other XML toolkits, 
> > so I guess this is a
> > general namespace ugliness.
>
> lack of namespace understanding, more likely.

May I suggest a saying: Never attribute to lack of knowledge what you
can attribute to confusing signals :)

Yours truly,
AdSR

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


Amara: Where's my attribute?

2006-06-29 Thread AdSR
Hi,

I'm having a problem with the Amara toolkit. Try this:

>>> from amara import binderytools
>>> raw = 'http://example.com/namespace"; 
>>> xmlns:pq="http://pq.com/ns2"/>'
>>> rwd = binderytools.bind_string(raw)
>>> print rwd.xml()

http://pq.com/ns2"/>

What happened to the xmlns attribute? Does anyone know a solution to
this? The only workaround I found is to:

>>> rwd.test.xml_set_attribute(u'xmlns', u'http://example.com/namespace')
u'xmlns'
>>> print rwd.xml()

http://pq.com/ns2";
xmlns="http://example.com/namespace"/>

but it only helps if you know what to patch.

My setup:

Python 2.4.3
4Suite 1.0b3
Amara 1.0

I see that people have reported similar problems with other XML
toolkits, so I guess this is a general namespace ugliness.

Regards,

AdSR

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


Re: Python is fun (useless social thread) ;-)

2006-06-21 Thread AdSR
John Salerno wrote:
> Did you have to learn it for a job?

No, although it became useful once I learnt it.

> Or did you just like what you saw and decided to learn it for fun?

I saw Bruce Eckel mention it in "Thinking in Java, 2nd ed." as
"something that was slowly becoming his favorite programming language".
How would *you* react to that? :)

> Also, how did you go about learning it? (i.e., like I described above, I
> started with the main stuff then moved on to the different available
> frameworks)

I started with the tutorial, although I didn't read it end-to-end. Then
I toyed a little with DB API (MySQLdb). It came useful some two weeks
after installing Python, when I was doing some DB refactoring in the
(Java) app I was working on at the time. Compared to JDBC, Python DB
API is very lightweight, which also taught me how not to overdesign.

Later I learnt Tkinter when I wrote a tool for some admin tasks on that
DB. I was to lazy to do it in Java.

> Was there any necessity in the specifics you learned, or did you just
> dabble in something (e.g. wxPython) for fun?

See above.

> Are there still some things you feel you need to learn or improve?

Metaclasses and other magic, if I ever need that stuff. Otherwise,
design and algorithms - these are not Python-specific, but Python can
be a useful learning tool here.

> Additional comments/complains here:   :)

Every XML API for Python that I tried sucks in one way or another. Try
manipulating a document with multiple namespaces, you'll know. Not that
I ever saw any XML API in any language that would do everything I
expected from it correctly. Ergo, XML sucks. :)

Cheers,

AdSR

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


Re: Mutual interdependency problem

2006-06-07 Thread AdSR
Jeremy Sanders wrote:
> I'm getting problems with modules with interdependencies when using the
> import form "import foo.bar as bar".
>
> [snip]
>
> Maybe the "from foo import *" style in __init__.py is a bad idea, but it
> allows you to expose a flat namespace without having to put all the code
> into one file. Then naturally you need mutual interdependencies, and then
> it breaks! I can work around it by removing the "as XXX" parts on the
> import statement, but it gets annoying having to specify the full path.

What worries me is that you have two modules that import each other.
Are you sure you can't do it any other way?

AdSR

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


Re: what are you using python language for?

2006-06-07 Thread AdSR
I'm using Python for:

* log analysis
* test tools
* data massaging
* prototyping

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


Re: ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-05 Thread AdSR
Laurent Pointal wrote:
> [for those who dont read clp.announce]
>
> The Python Quick Reference Card (PQRC) aims to provide a printable quick
> reference documentation for the Python language and some of its main
> standard libraries (currently for Python 2.4).
> [etc.]

Great job, Laurent! If this is version 0.55, I can't wait for 1.0. Keep
up the good work.

BTW, it would be great if something like this came with Python
installation. No more sifting through library TOC/index, "where did I
see this stuff" :)

AdSR

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


Re: Rethinking the Python tutorial

2006-02-11 Thread AdSR
I think you guys are up to something. We need some way to aggregate,
update, and extend not just tutorials but all kinds of informatory
material on Python. The Python Wiki is a good place for all that,
although it hasn't become anything resembling a Wikipedia so far.

AdSR

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


Re: fairly large webapp: from Java to Python. experiences?

2006-02-05 Thread AdSR
Giovanni Bajo wrote:
> Also Python code is pretty bare-metal, so that
> file.write or socket.write go to the syscall immediately. Try that in Java and
> you'll find 30 layers of complex abstractions for doubtful benefits and 
> obvious
> slowness.

+1 QOTW
(I'd recommend the whole post but it might be too long.)

Cheers,

AdSR

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


Re: subprocess problem in cygwin with Tkinter

2006-01-05 Thread AdSR
Stewart Midwinter wrote:
> [...]
> I'm using this version of Cygwin:
> $ uname -a
> CYGWIN_NT-5.1 Mulata 1.5.18(0.132/4/2) 2005-07-02 20:30 i686 unknown unknown 
> Cyg
> win
> [...]
> When I run the same command in a Tkinter app, I get an exception:
>
> [EMAIL PROTECTED] /cygdrive/c/programs/pipeworksb/lib/python/popt
> $ python test_subprocess.py
> d:\cygwin\bin\python2.4.exe (7752): *** unable to remap 
> d:\cygwin\bin\tk84.dll t
> o same address as parent(0x18C4) != 0x18C5
>   9 [main] python 4696 fork_parent: child 7752 died waiting for dll 
> loading
> [...]
> any ideas?

This is a dll problem that sometimes happens in Cygwin. Run 'rebaseall'
to fix this.

HTH,
AdSR

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


Re: def a((b,c,d),e):

2005-04-18 Thread AdSR
> Thanks for pointing this out. However I see no atrocity potential
here
> -- what did you have in mind?

Bad choice of words. I meant obfuscated, something like

def z(((a, b), (c, d)), e, f):
pass

but much worse. But it looks like there is nothing unusual about it
after all. Oh, well...

AdSR

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


Re: def a((b,c,d),e):

2005-04-18 Thread AdSR
> Yes, but usually not so much in function arguments but more in
> list-comprehensions or other places where unpacking was useful. I
love the
> feature - I just don't have nested enough data to use it more :)

I use tuple unpacking in its typical uses, it's one of the first
language features I learned about. Somehow it never occurred to me that
you could use it in function arguments this way - I only knew  f(*args,
**kwargs) style in this context. That's what I made the whole fuss
about...

AdSR

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


Re: def a((b,c,d),e):

2005-04-18 Thread AdSR
> if you think this is an "atrocity", maybe programming isn't for you.

My resume might suggest otherwise but I guess that's not the main topic
here. Maybe I got carried away -- this one took me completely by
surprise.

Anyway, this gets interesting:

def z(((a, b), (c, d)), (e, f)):
pass

although I see that it could be perfectly valid in some contexts.

Cheers,

AdSR

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


def a((b,c,d),e):

2005-04-18 Thread AdSR
Fellow Pythonistas,

Please check out

http://spyced.blogspot.com/2005/04/how-well-do-you-know-python-part-3.html

if you haven't done so yet. It appears that you can specify a function
explicitly to take n-tuples as arguments. It actually works, checked
this myself. If you read the reference manual at
http://docs.python.org/ref/function.html
really carefully, you will find that it is indeed part of the language
spec, but it's a likely candidate for the least advertised Python
feature. Small wonder since it looks like one of those language
features that make committing atrocities an order of magnitude easier.

Has anyone actually used it in real code?

Cheers,

AdSR

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


Re: python3: 'where' keyword

2005-01-08 Thread AdSR
Nick Coghlan wrote:
Killer app for this keyword:
class C(object):
  x = property(get, set) where:
def get(self):
  return "Silly property"
def set(self, val):
  self.x = "Told you it was silly"
Hey, this is super-elegant!
AdSR
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-07 Thread AdSR
Andrey Tatarinov wrote:
Hi.
It would be great to be able to reverse usage/definition parts in 
haskell-way with "where" keyword. Since Python 3 would miss lambda, that 
would be extremly useful for creating readable sources.

Usage could be something like:
 >>> res = [ f(i) for i in objects ] where:
 >>> def f(x):
 >>> #do something
I don't know haskell, but it looks SQL-ish to me (only by loose 
association). And it's not that unpythonic - it resembles

>>> res = [x for x in sequence if x.isOk()]
or
 >>> print words[3], words[5] where:
 >>> words = input.split()
Here's a shorter version:
>>> print input.split()[3:5:2]
(Does it qualify as obfuscated Python code? :) )
- defining variables in "where" block would restrict their visibility to 
one expression

- it's more easy to read sources when you know which part you can skip,
Yes, I like the readability of it, too.
compare to
 >>> def f(x):
 >>> #do something
 >>> res = [ f(i) for i in objects ]
in this case you read definition of "f" before you know something about 
it usage.
When I first read your post, I thought "Well, just one more of those 
Py3k ideas that appear on c.l.py every day." But as I look at the latter 
example, I think you have just scratched my itch. The same thing has 
bugged me more than once in my code.

I think this idea is of the same kind as the @decorator syntax. Guido 
moved an operation to a point in the code where it was more visible. You 
moved an operation to a more local context where (pun not intended) it 
really belongs.

I'm usually rather conservative about Python syntax (@decorators, 
absolute/relative imports, if-else operator), but this one could appear 
in Python tomorrow and that would be too far in the future for me ;)

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


Re: Working with recordsets

2005-01-07 Thread AdSR
[EMAIL PROTECTED] wrote:
Hi.
I have one recorset that I would like to pass to 2 functions, one is
for create an CSV file and the other one is to create a HTML file. The
problem is that the recordset is totally read in the first function,
and then when I pass it to the second funtion the recordset is in the
last record.
I've read docs, but I think that one cursor doesn't have something
like movefirst() method. Anybody have an idea to solve this?
Thank's.
Try loading the whole recordset with the fetchall() method and use the 
resulting sequence in your functions. It won't be memory-efficient but 
it will be easy to do.

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