Re: Usage of main()

2009-09-03 Thread Simon Brunning
2009/9/4 Manuel Graune :
> How come the main()-idiom is not "the standard way" of writing a
> python-program (like e.g. in C)?

Speaking for myself, it *is* the standard way to structure a script. I
find it more readable, since I can put my main function at the very
top where it's visible, with the classes and functions it makes use of
following in some logical sequence.

I suspect that this is the case for many real-world scripts. Perhaps
it's mainly in books and demos where the extra stuff is left out so
the reader can focus on what the writer is demonstrating?

> And in addition: Can someone please explain why the first version
> is so much slower?

Access to globals is slower than access to a function's locals.

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


Re: Usage of main()

2009-09-03 Thread r
On Sep 4, 12:55 am, Manuel Graune  wrote:
(snip)

> How come the main()-idiom is not "the standard way" of writing a
> python-program (like e.g. in C)?

Why use a nested function when you already *in* main? thats like
declaring variables when your compiler could just use some simple
logic...

'2.7' -> string because wrapped in quotes
2 -> integer because is in set{0123456789} && no quotes!
1.23 -> because all digits && has a period

...or using "{" and "}" instead of INDENT and DEDENT.

Python removes the unnecessary cruft and redundancy that is C, and
puts the burden on your machine!

http://www.python.org/dev/peps/pep-0020/

> And in addition: Can someone please explain why the first version
> is so much slower?

leave that one for someone else...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Usage of main()

2009-09-03 Thread Sean DiZazzo
On Sep 3, 10:55 pm, Manuel Graune  wrote:
> Hello everyone,
>
> the standard structure of a python-program which is taught in all of
> the books I on python I read by now is simply something like:
>
> #!/usr/bin/python
> print "Hello, world!"
> ^D
>
> While reading about structuring a larger code-base, unit-testing, etc
> I stumbled on the idiom
>
> #!/usr/bin/python
> def main():
>     print "Hello, world"
> if __name__ == "__main__":
>    main()
> ^D
>
> While experimenting with this I found that the second version in most
> cases is *a lot* faster than the simple approach. (I tried this both
> on Linux and Windows) I found this even in cases where the code con-
> sists simply of something like
>
> j=0
> for i in xrange(100):
>     j+=i
> print j
>
> How come the main()-idiom is not "the standard way" of writing a
> python-program (like e.g. in C)?
> And in addition: Can someone please explain why the first version
> is so much slower?
>
> Regards,
>
> Manuel
>
> --
> A hundred men did the rational thing. The sum of those rational choices was
> called panic. Neal Stephenson -- System of the 
> worldhttp://www.graune.org/GnuPG_pubkey.asc
> Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99

I'm trying to come up with an answer for you, but I can't...

The if __name__ == "__main__": idiom *is* the standard way to write
python programs, but it's not there to speed up programs.  It's there
so that your program can be executed differently whether it is called
as a runnable script from the command line, or if it is imported.
When you import a module, "__name__" is equal to the name of the
module, but when you execute it, it's "__name__" is "__main__"  If you
are importing a library, you generally don't want it to fire off a
bunch of processing until you call the needed functions/methods. I
also use it as a testing ground, and a sort of loose documentation for
my modules.  I put stuff in there that shows and tests a general use
of the module, but when I actually import and use it, I definitely
don't want that code to run!

What are you using to test the scripts?  I could be completely wrong,
but I find it hard to believe that the second version is much (if any)
faster than the first.  Then again, I don't know much about the
internals...

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


Usage of main()

2009-09-03 Thread Manuel Graune

Hello everyone,

the standard structure of a python-program which is taught in all of
the books I on python I read by now is simply something like:

#!/usr/bin/python
print "Hello, world!"
^D

While reading about structuring a larger code-base, unit-testing, etc
I stumbled on the idiom

#!/usr/bin/python
def main():
print "Hello, world"
if __name__ == "__main__":
   main()
^D

While experimenting with this I found that the second version in most
cases is *a lot* faster than the simple approach. (I tried this both
on Linux and Windows) I found this even in cases where the code con-
sists simply of something like

j=0
for i in xrange(100):
j+=i
print j

How come the main()-idiom is not "the standard way" of writing a
python-program (like e.g. in C)?
And in addition: Can someone please explain why the first version
is so much slower?

Regards,

Manuel

-- 
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with multiprocessing

2009-09-03 Thread Tennessee
> Yes, to use the multiprocessing module, you must make your script
> importable, so runtime statements should go into a __main__
> conditional.  This way, when multiprocessing imports the module for each
> of its threads, the actual runtime code only gets executed once in the
> parent thread, which has the lock.  At least, that is what I think is
> happening.

Oh, that makes total sense. Thanks to both of you!

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


Re: The future of Python immutability

2009-09-03 Thread John Nagle

Gabriel Genellina wrote:
En Thu, 03 Sep 2009 15:03:13 -0300, John Nagle  
escribió:



 Python's concept of immutability is useful, but it could be more
general.

 Immutability is interesting for threaded programs, because
immutable objects can be shared without risk.  Consider a programming
model where objects shared between threads must be either immutable or
"synchronized" in the sense that Java uses the term.  Such programs
are free of most race conditions, without much programmer effort to
make them so.


In the current CPython implementation, every object has a reference 
count, even immutable ones. This must be a writable field - and here you 
have your race condition, even for immutable objects.


   That's an implementation problem with CPython.  I'm looking at this as
a language design issue.  Shed Skin, which is garbage-collected, doesn't
have that problem.  Look ahead to a new generation of Python implementations
that go fast and use multiprocessors effectively.

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


Re: how to edit .wsgi file extebtions with IDLE on windows

2009-09-03 Thread Gabriel Genellina

En Sat, 29 Aug 2009 20:29:43 -0300, gert  escribió:

On Aug 29, 11:16 pm, "Gabriel Genellina" 
wrote:
En Sat, 29 Aug 2009 17:14:14 -0300, gert   
escribió:

> On Aug 29, 9:31 pm, Chris Rebert  wrote:
>> On Sat, Aug 29, 2009 at 5:40 AM, gert wrote:
>> > On Aug 29, 6:43 am, "Gabriel Genellina" 
>> > wrote:
>> >> En Fri, 28 Aug 2009 15:31:31 -0300, gert   
>> escribió:



>> >> > I can't figure out how to enable the .py shell and syntax  
>> >> > highlighting
>> >> > for .wsgi file extensions using IDLE for windows ?



Thanks. Can you make a ispythonsource menu option in the next
python3.x release? There are many examples of txt, xml or wsgi files
having python parts in them.


Please file a feature request at http://bugs.python.org/
I think a "This is a python file, apply syntax highlighting" menu option
is feasible, but doing the same only for part of a file is a lot harder.

--
Gabriel Genellina

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


Re: using queue

2009-09-03 Thread Tim Arnold
"Jan Kaliszewski"  wrote in message 
news:mailman.895.1251958800.2854.python-l...@python.org...
> 06:49:13 Scott David Daniels  wrote:
>
>> Tim Arnold wrote:
>
>>> (1) what's wrong with having each chapter in a separate thread? Too 
>>> much going on for a single processor?
>
>> Many more threads than cores and you spend a lot of your CPU switching
>> tasks.
>
> In fact, python threads work relatively the best with a powerful single
> core; with more cores it becomes being suprisingly inefficient.
>
> The culprit is Pythn GIL and the way it [mis]cooperates with OS
> scheduling.
>
> See: http://www.dabeaz.com/python/GIL.pdf
>
> Yo
> *j
>
> -- 
> Jan Kaliszewski (zuo) 

I've read about the GIL (I think I understand the problem there)--thanks. In 
my example, the actual job called for each chapter ended up being a call to 
subprocess (that called a different python program). I figured that would 
save me from the GIL problems since each subprocess would have its own GIL.

In the words of Tom Waits, " the world just keeps getting bigger when you 
get out on your own".  So I'm re-reading now, and maybe what I've been doing 
would have been better served by the multiprocessing package.

I'm running python2.6 on FreeBSD with a dual quadcore cpu. Now my questions 
are:
(1) what the heck should I be doing to get concurrent builds of the 
chapters, wait for them all to finish, and pick up processing the main job 
again? The separate chapter builds have no need for communication--they're 
autonomous.
(2) using threads with the target fn calling subprocess, a bad idea?
(3) should I study up on multiprocessing package and/or pprocessing?

thanks for your inputs,
--Tim 


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


REMINDER: PyCon 2010: Call for Proposals

2009-09-03 Thread Aahz
Call for proposals -- PyCon 2010 -- 
===

Due date: October 1st, 2009

Want to showcase your skills as a Python Hacker? Want to have
hundreds of people see your talk on the subject of your choice? Have some
hot button issue you think the community needs to address, or have some
package, code or project you simply love talking about? Want to launch
your master plan to take over the world with python?

PyCon is your platform for getting the word out and teaching something
new to hundreds of people, face to face.

Previous PyCon conferences have had a broad range of presentations,
from reports on academic and commercial projects, tutorials on a broad
range of subjects and case studies. All conference speakers are volunteers
and come from a myriad of backgrounds. Some are new speakers, some
are old speakers. Everyone is welcome so bring your passion and your
code! We're looking to you to help us top the previous years of success
PyCon has had.

PyCon 2010 is looking for proposals to fill the formal presentation tracks.
The PyCon conference days will be February 19-22, 2010 in Atlanta,
Georgia, preceded by the tutorial days (February 17-18), and followed
by four days of development sprints (February 22-25).

Online proposal submission is open now! Proposals  will be accepted
through October 1st, with acceptance notifications coming out on
November 15th. For the detailed call for proposals, please see:

 

For videos of talks from previous years - check out:



We look forward to seeing you in Atlanta!
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does this group have so much spam?

2009-09-03 Thread r

*ahem*! You guy's do remember this thread (?at one time in history?)
was about spam on this list, right? Not internet connection fees. ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does this group have so much spam?

2009-09-03 Thread Terry Reedy

Steven D'Aprano wrote:

According to the theory "increased usage leads to higher prices", we 
should be paying more for Internet access now than we were in 1999, and 
hugely more that from the early 90s when there were hardly any Internet 
users. 


You are confusing historical changed with contemporaneous alternatives.

Suppose that all over the world, people coordinated so that one in three 
households paid ISPs while a neighbor on each side piggybacked (and 
perhaps paid the paying househould their one-third share).  Do you 
really think that would have no effect on the pricing and availability 
of internet service?


tjr

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


Re: Try Except Problem

2009-09-03 Thread Albert Hopkins
On Tue, 2009-09-01 at 13:45 -0500, Victor Subervi wrote:
> Hi: I have this code:

[blah]

It's  hard to tell because:

 1. You posted code in HTML format, which is really hard to read
 2. Even when viewed as plain text, you use non-standard indentation
which is really hard to read
 3. You used a blank except: clause that catches all exceptions.
This is not good programming practice and makes it difficult to
debug
 4. You didn't reduce your code down to the basic problem, or at
least provide an alternative code snippet that others can try to
duplicate
 5. You didn't show the actual output or provide what inputs were
used.


In short, it basically looks like you typed or copied some code that is
not well written, discovered it doesn't work and expect the list to
debug your program for you.

Help us help you.



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


Pydev 1.5.0 (Pydev Extensions open sourced)

2009-09-03 Thread Fabio Zadrozny
Hi All,

Today, Aptana is proud to announce that Pydev and Pydev Extensions
have become a single plugin, with all the available contents open
source (and freely available for anyone) in the 1.5.0 release (it's
the same as 1.4.8 but with all the code open source).

With that, Aptana believes in providing a better service and growth
path for Pydev (which will still be actively maintained by Aptana),
enabling anyone to provide contributions to the previously closed
source product, while providing its Cloud customers a better service.

Note for those already using Pydev or Pydev Extensions:

The update site has been changed (see:
http://www.pydev.org/download.html for more details) and if you had
a previous install of Pydev Extensions, you need to uninstall it
before installing the new version of Pydev.

Note for developers:

Pydev is now available under git (at github), and its previously used
subversion will be disabled. Instructions on getting the source code
from the new location is available at:
http://www.pydev.org/developers.html

Best Regards,

--
Fabio Zadrozny

Aptana
http://aptana.com

Pydev - Python Development Environment for Eclipse
http://pydev.org
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logging contents of IRC channel

2009-09-03 Thread devaru
On Sep 1, 9:56 am, alex23  wrote:
> On Sep 1, 3:23 am, devaru  wrote:
>
> > I am new to Python. I want to log the activities in an IRC channel.
> > Any pointers regarding this would be of great help.
>
> It would help us if you could explain why the answers weren't suitable
> that you were given when you first[1] asked this question...
>
> [1]:http://groups.google.com/group/comp.lang.python/browse_frm/thread/448...


_
@Paul Rubin: This is small experimental project and I assure you that
i will not invade anyone's privacy.

@alex23: My bad, I didn't check the solutions that were provided in
the earlier thread (http://groups.google.com/group/comp.lang.python/
browse_frm/thread/448c0b476047f898).
I'll be trying out the solutions and let this community know.

Right now I'm using irclib.py.
@Jonathan Gardner: I would be connecting to an IRC channel through a
bot.
Storing data would not be problem. I'll either store it in a file or
in database.

Thanks everyone for the reply :-).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An assessment of the Unicode standard

2009-09-03 Thread r
On Sep 1, 9:48 am, steve  wrote:
(snip)
> I think you are confusing simplicity with uniformity.
>
> Uniformity is not always good. Sure standardizing on units of measure and
> airline codes is good, but expecting everyone to speak one language is akin to
> expecting everyone to wear one type of clothing or expecting everyone to drive
> just one type of automobile -- those kind of rules works well in a small sets
> where doing so fulfills a purpose (in the army, hospitals or taxi service, for
> instance).

Thanks for bringing good arguments to this thread. But let me argue
your talking points a bit.

You seem to think that a single language somehow infringes upon the
freedoms of individuals and you argue this by making parallels to
personal taste's like like cars, clothing, hairstyles, etc. I am an
American so i deeply believe in the right of individuals to freedom of
speech, freedom of expression. Freedom of everything AS long as your
freedoms don't cancel-out others freedoms.

I am also not advocating the outlawing or "frowning upon" of any non-
official language, quite the contrary. I AM saying that there must be
*ONE* language that is taught in schools throughout the world as the
very first language a child and *ONE* language that is used for
official business of governments and corporations throughout the
world. HOWEVER, individuals will still have the freedom to speak/write/
curse in any other language their heart desires. But with the great
language unity, all peoples will be able to communicate fluently
through the universal language while keeping their cultural identity.
Can you not see the beauty in this system?

Like i said, i believe in individual freedom, but you and i are also
children of the Human race. There are some responsibilities we must
keep to Human-kind as a whole. Universal communication is one of them.
Universal freedom is another. An neither of these responsibilities
will hold back individualism.

> To put it another way, it is better to create data structures to deal with
> variable length names rather than mandating that everybody has names < 30 
> chars.

You need to understand that language is for communication and
expression of ideas, and that is it. It is really not as glamorous as
you make it seem. It is simple a utility and nothing more...

> This might come as a bit of shock for you, but evolution awards those who are
> capable of adapting to complexity rather then those who expect things to be
> uniform. You, dear friend, and those who yearn for uniformity are the ones on
> the path to extinction.

No evolution awards those that benefit evolution. You make it seem as
evolution is some loving mother hen, quite the contrary! Evolution is
selfish, greedy, and sometimes evil. And it will endure all of us...

remember the old cliche "Nice guys finish last"?
-- 
http://mail.python.org/mailman/listinfo/python-list


Adjacency lists with sqlalchemy...

2009-09-03 Thread Just Another Victim of the Ambient Morality
I'm desperately trying to declare an adjacency list table with 
declarative_base() but I can't figure it out.  Strangely, all the 
documentation avoids declarative_base() like the plague and does everything 
the hard way.  What the hell is this thing for if we're not supposed to use 
it?
If anyone can show me how to declaratively create ORM adjacency list or 
explain to me why this can't be done, I'd be very grateful.
Thank you! 


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


Re: An assessment of the Unicode standard

2009-09-03 Thread Chris Jones
On Tue, Sep 01, 2009 at 03:16:03PM EDT, r wrote:

[..]

> Bring on the metric system Terry, i have been waiting all my life!!
> 
> Now, if we can only convince those 800 million Mandarin Chinese
> speakers... *ahem* Do we have a Chinese translator in the house?
> 
> :-)

"Between the idea
 And the reality
 Between the motion
 And the act
 Falls the Shadow"

And further on..

"This is the way the world ends
 Not with a bang but a whimper."

 T. S. Eliot, "The Hollow Men"

The very worst about you rant is that you may be the harbinger, a sign
of things to come. 

A loud steady voice told him that "By this as your standard, you will
conquer".

'nuff said.. have a good night.

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


Re: Python community buildbot page still 503

2009-09-03 Thread exarkun

On 06:23 pm, mar...@v.loewis.de wrote:

If I am not mistaken http://python.org/dev/buildbot/community/all/ has
been down since python.org had its harddrive issues.

Anyone know a time line on getting it back up and running.


This service is, unfortunately, unmaintained. It broke when I upgraded
the buildbot master to a new code base, and nobody upgraded the 
buildbot

configuration file.

So I have now removed it from the web server configuration, and put a
notice on the web site.


Um.  Where should I have been watching to get some warning about this? 
And now that I know, can you tell me what I need to do to restore it?


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


Try Except Problem

2009-09-03 Thread Victor Subervi
Hi:
I have this code:

 try:
  cursor.execute('select salesperson, office, cell, fax, home, email,
assistant from general where salesperson="%s";' % (catch))
  stuff = cursor.fetchone()
  test = raw_input('You have selected salesperson %s. Is that correct? (hit
\'enter\' for affirmative, enter anything else for negative): ' % (catch))
  if len(test) == 0:
salesperson, office, cell, fax, home, email, assistant = new[i][0],
new[i][1], new[i][2], new[i][3], new[i][4], new[i][5], new[i][6]
print 'one'
except:
  print 'two'
  salesperson = raw_input('Please enter the sales person\'s name: ')
  office = raw_input('Please enter the sales person\'s office number: ')
  cell = raw_input('Please enter the sales person\'s cell number: ')
  fax = raw_input('Please enter the sales person\'s fax number: ')
  home = raw_input('Please enter the sales person\'s home number: ')
  email = raw_input('Please enter the sales person\'s email address: ')
  assistant = raw_input('Please enter the name of the sales person\'s
assistant: ')
Now, both "one" and "two" get printed! So it's running the try AND the
except!! Why???
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: possible attribute-oriented class

2009-09-03 Thread Ken Newton
On Thu, Sep 3, 2009 at 4:30 PM, Steven D'Aprano <
st...@remove-this-cybersource.com.au> wrote:

> On Thu, 03 Sep 2009 15:46:01 -0700, Ken Newton wrote:
>
> > I have created the following class definition with the idea of making a
> > clean syntax for non-programmers to created structured data within a
> > python environment.
>
> What do you expect non-programmers to do with this class, without
> programming? How can they even use it?
>

A couple extra details: The users are scientists, and technically
sophisticated.
They are used to specifying complicated sets of parameters and this
structured
form matches the way they are used to thinking about their work. Though they
are not programmers, they can define expressions to represent the desired
calculations for this project and occasionally write small programs in the
course
of their work. However, they will not like a long learning curve and will
want to be
isolated from most of the details in good programming design (error
handling,
creating supporting infrastructure, etc.)  In this case, Python will be used
as
a scripting language with most of the details specified by simple function
expressions
or defining structured data or specifying (linear) sequences of actions.

...
> > The expected use would have all items in the structure be simple python
> > types or AttrClass types. Code written in python could walk the
> > structure in a simple way to locate any desired values. Code in a C/C++
> > extension should also be able to walk the structure to use any value in
> > the structure.
>
> I don't see the purpose of it. Nested data structures are generally
> harder for people to understand than non-nested ones, hence the Python
> Zen: "flat is better than nested". For example, a list is easier to grasp
> than a tree. This especially applies to non-programmers.
>
> I don't see how this is simple enough for non-programmers, or useful for
> programmers. For programmers, just nest objects:
>
> class Parrot(object):
>pass
>
> obj = Parrot()
> obj.x = 1
> obj.y = Parrot()
> obj.y.z = 2
> obj.y.z.zz = Parrot()


This is close to what I started with when I started exploring this idea.
But I felt I needed a way to create some additional support, that is
the str and repr functions.  These structures will be created and
populated once and saved in a python source file, which will be
loaded from the embedding C++ program.  The (scientist) users will
need a way to review the structure and current values while
interactively changing a few of the values to observe their effect on
the system.  My recursive __str__() and __repr__() functions were
intended to provide that support.


> > class AttrClass(object):
> > """AttrClass lets you freely add attributes in nested manner"""
>
> You don't actually need a special class for that, unless you're providing
> extra functionality. A bare subclass of object will let you freely add
> attributes in a nested manner.
>
> It seems to me that you're combining two different sets of functionality,
> but only describing one. The first is, nested attributes -- but you get
> that for free with any class. The second is the ability to set (but
> strangely not retrieve!) attributes using dictionary-like syntax. But
> that's implied by the code, you haven't mentioned it in your description
> or documentation.
>
>
> > def __init__(self):
> > pass
>
> If the __init__ method doesn't do anything, you don't need it.


Good point. This was a placeholder. My intention was to add some
code to initialize the class from a dict. But didn't get around to
implementing that. Or the ideas I tried (couple years ago) didn't work.



> > def __setitem__(self, key, value):
> > return self.__dict__.__setitem__(key, value)
>
> Simpler to just say:
>
> def __setitem__(self, key, value):
> self.__dict__[key] = value
>
> You don't strictly need the return, because methods return None by
> default, and dict.__setitem__ always returns None (unless it raises an
> exception).
>

Now, I can't remember why I ended up with my strange syntax.  Unless
it was related to the fact that I started doing this in IronPython and this
made it work better in that context or on the C# side of things.  I'm now
planning this for a CPython embedding situation.  And, perhaps as  you
pointed out, the __setitem__ isn't needed at all in the code I showed.


>
> This method allows you to set attributes using dict syntax:
>
>instance['key'] = 123  # same as instance.key = 123
>
> But you don't have corresponding __getitem__ or __delitem__ methods, so
> you can't do these:
>
>value = instance['key']  # fails
>del instance['key']  # fails


The getitem and delete behaviors are not expected to be common uses.
But if I continue with this approach, should be implemented for
completeness.

> def __repr__(self):
> > return "%s(%s)" % (self.__class__.__name__,
> > self.__dict__.__repr__())
>
> This strongly implies that you should be able to

Re: Question about apply

2009-09-03 Thread MRAB

jorma kala wrote:

Hi,
I'm using apply to pass keyword arguments as a dictionary  to a funcion 
at runtime (which keyword arguments to pass is only known at runtime)
apply is very handy for this, because it takes a dictionary of keyword 
arguments directly


def f1(a=None,b=None,c=None):
pass
   
   
kw={'a':1}


apply(f1,[],kw)

But I read in the doc that apply is deprecated.
What is the non-deprecated way of doing this?


To pass a list as arguments use:

func(*arg_list)

To pass a dict as keyword arguments use:

func(**arg_dict)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Annoying octal notation

2009-09-03 Thread MRAB

Albert van der Horst wrote:

In article <6b5ea596-d1e3-483d-ba79-7b139d3c7...@z24g2000yqb.googlegroups.com>,
Bearophile   wrote:

MRAB:


'_': what if in the future we want to allow them in numbers for clarity?

Hettinger says it's hard (= requires too many changes) to do that and
Python programs don't have big integer constants often enough, so
probably that improvement will not see the light.

In the meantime in a Python program of mine I have put a small bug,
writing 100 instead of 1000. Now in Python I write
10*1000*1000, because I try to learn from my bugs. In D I enjoy
writing 10_000_000.


Forth is one of the few language that could accept
10,000,000 easily  (Because numbers or any token is required too be
separated by whitespace). I have added that to my ciforth.
Especially useful doing number theoretic things and large pointers
in a 64 bit language it is pleasant to have a separator like that.
Even 32 bit :   0008,,0050,4CE0

Also:
In Forth you can add interpreting words, so you can add a facility CD :
CD C:/prog/forth
that does a directory change.
If this has been loaded it is natural to use 0CD to
prevent the CD word from kicking in (definitions
trump numbers in Forth.) Before you know it, you're in
the habit of prefixing all hex numbers by 0 if they don't
start with a decimal digit:
   0DEAD 0BEEF

So for me there is nothing natural about "leading zero means
octal".


[snip]
In Modula-2, a hexadecimal literal starts with a digit and ends with
"H", for example: 0FFH. Using a leading zero to indicate a certain
base doesn't seem natural to me either.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does this group have so much spam?

2009-09-03 Thread Steven D'Aprano
On Thu, 03 Sep 2009 16:01:26 -0700, Ethan Furman wrote:

> Steven D'Aprano wrote:
>> On Thu, 03 Sep 2009 12:19:48 -0700, Ethan Furman wrote:
>> 
>> 
>>>Steven D'Aprano wrote:
>>>
On Thu, 03 Sep 2009 04:01:54 -0400, Terry Reedy wrote:



>ISP's price residential service based on average fixed cost and
>average usage. Multiple homes using one connection push those
>averages up.


Is that meant to be a problem?

When people buy more, the unit price they are paying falls, but the
total price they pay generally goes up. E.g. we've recently upgraded
our business link from AUD$150 per month for 60GB to $190 for 100GB.
The per GB price is less, but the total we pay is more -- and the ISP
doesn't have to do much extra work for that extra money.





>>>The difference is that you *upgraded* your service and so incurred a
>>>greater total cost.  If my neighbor lets the rest of the neighborhood
>>>use his wireless, while I do not, yet my prices go up because on
>>>average more usage is happening, I am paying more but not getting more.
>> 
>> 
>> Incorrect -- you are getting all the downloads you make yourself, plus
>> the warm fuzzy feeling of happiness from the knowledge that other
>> people are making downloads you have paid for.
>> 
>> Of course, if you've *unintentionally* left your wi-fi open, perhaps
>> "cold feelings of dread and horror" would be more appropriate, but
>> we're talking about the situation where folks deliberately leave their
>> wi-fi open for whatever reason.
>> 
>> 
>> 
> Read a little closer, Steven -- *my* wi-fi is *closed*, it's my neighbor
> (in theory) who has his open, and all that extra usage is making *my*
> rate go up -- no warm fuzzies, only irritation.


Okay, that makes zero sense at all.

If your neighbour left his wi-fi closed, but just downloaded twice as 
much stuff, would you be irritated? What if he gets a roommate and they 
share the same account?

What's the difference between "my neighbour is personally downloading 
twice as much stuff" and "my neighbour is letting other people to 
download stuff, doubling total usage on his account"?

Your argument supposes that open wi-fi will lead to increased average 
usage, which in turn will lead to higher prices, neither of which are 
obviously true.

If I'm leaching off my neighbour's open network, chances are that I'll be 
using my own account less, so the average will tend to remain about the 
same. Even if I download more than I otherwise would have, because I'm 
not paying for it, the difference will be offset due to inconvenience: I 
can't control when my neighbour has his account on or off, or bounce the 
router if there's a problem. If I have to pick up my laptop and 
physically walk outside and park in the street to access his open wi-fi 
network, forget it, I'll use my own account.

According to the theory "increased usage leads to higher prices", we 
should be paying more for Internet access now than we were in 1999, and 
hugely more that from the early 90s when there were hardly any Internet 
users. That's nonsensical. I don't know about you, but I'm paying about 
the same for ADSL access now as I would have paid for dial-up access in 
the late 90s. The explosion of Internet use has lead to more competition, 
lower prices and lower costs. In the late 1990s, I was paying something 
like AUD$35 a month for dial-up access just for myself. With inflation, 
that's about equal to $45 in today's prices. Now I'm paying $60 for ADSL 
access, for two people, that is, about $30 per person -- less than I was 
paying for dial-up in 1999.

Even though the total amount I'm paying has increased, the cost per 
person, or per megabyte, is lower than it was in the 90s. My total cost 
has increased because my circumstances have changed, not because the 
service is more expensive. That contradicts the prediction "more usage 
leads to higher prices", and as far as I'm concerned, pretty much refutes 
the hypothesis.



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


Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-03 Thread Ben Finney
MacRules  writes:

> What I am looking for is this.
>
> Oracle DB in data center 1 (LA, west coast)
> MSSQL DB in data center 2 (DC, east coast)
> So network bandwidth is an issue

Okay, that's a brief description but is clearer than we had before.

> I prefer to have gzip fist and
> deliver the data.

Forget about gzip for now; just concentrate on the *problem* to be
solved, and don't assume a particular technique. There are other ways of
addressing limited bandwidth.

> I need 2 python daemons or a web service here in the future.

Again, don't assume a particular technique until it's demonstrated that
it's better than alternatives; default to a simple implementation first.

Nothing in your description speaks to a need for a daemon. What it
sounds like you need is two programs, one running at each end of a
network connection. Whether they are daemons or not is irrelevant.

> I will enter the Oracle table name, user id and password.
> So the task is dump out Oracle data (Linux) and insert that to MSSQL.

That's the core of the problem to be solved, in my view. For now, forget
about limited network bandwidth or how these processes will run.

Are you able to get your particular data out of the one system and into
the other, successfully? What have you tried so far to do this, and what
exactly went wrong?

> Take the Oracle data file, and let the daemon connects to MSSQL (with
> pyodbc) and load the data in.

What was the result of this on your specific data set? If you have
issues related to Oracle or MS servers, or their implementations of SQL,
you'll need to seek assistance in forums specific to those products.

-- 
 \  “If you get invited to your first orgy, don't just show up |
  `\ nude. That's a common mistake. You have to let nudity |
_o__)  ‘happen.’” —Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: possible attribute-oriented class

2009-09-03 Thread Steven D'Aprano
On Thu, 03 Sep 2009 15:46:01 -0700, Ken Newton wrote:

> I have created the following class definition with the idea of making a
> clean syntax for non-programmers to created structured data within a
> python environment.

What do you expect non-programmers to do with this class, without 
programming? How can they even use it?


... 
> The expected use would have all items in the structure be simple python
> types or AttrClass types. Code written in python could walk the
> structure in a simple way to locate any desired values. Code in a C/C++
> extension should also be able to walk the structure to use any value in
> the structure.

I don't see the purpose of it. Nested data structures are generally 
harder for people to understand than non-nested ones, hence the Python 
Zen: "flat is better than nested". For example, a list is easier to grasp 
than a tree. This especially applies to non-programmers.

I don't see how this is simple enough for non-programmers, or useful for 
programmers. For programmers, just nest objects:

class Parrot(object):
pass

obj = Parrot()
obj.x = 1
obj.y = Parrot()
obj.y.z = 2
obj.y.z.zz = Parrot()




> class AttrClass(object):
> """AttrClass lets you freely add attributes in nested manner"""

You don't actually need a special class for that, unless you're providing 
extra functionality. A bare subclass of object will let you freely add 
attributes in a nested manner.

It seems to me that you're combining two different sets of functionality, 
but only describing one. The first is, nested attributes -- but you get 
that for free with any class. The second is the ability to set (but 
strangely not retrieve!) attributes using dictionary-like syntax. But 
that's implied by the code, you haven't mentioned it in your description 
or documentation.


> def __init__(self):
> pass

If the __init__ method doesn't do anything, you don't need it.


> def __setitem__(self, key, value):
> return self.__dict__.__setitem__(key, value)

Simpler to just say:

def __setitem__(self, key, value):
self.__dict__[key] = value

You don't strictly need the return, because methods return None by 
default, and dict.__setitem__ always returns None (unless it raises an 
exception).


This method allows you to set attributes using dict syntax:

instance['key'] = 123  # same as instance.key = 123

But you don't have corresponding __getitem__ or __delitem__ methods, so 
you can't do these:

value = instance['key']  # fails
del instance['key']  # fails



> def __repr__(self):
> return "%s(%s)" % (self.__class__.__name__,
> self.__dict__.__repr__())

This strongly implies that you should be able to create a new instance 
using that format:

AttrClass({'key': 123, 'another_key': 456})

but that fails. As a general rule, the repr() of a class should (if 
possible) work correctly if passed to eval(). This doesn't. That's not 
entirely wrong, but it is unusual and confusing.




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


Re: Video?

2009-09-03 Thread Che M
On Sep 3, 4:11 pm, David C Ullrich  wrote:
> Not at all important, just for fun (at least for me):
>
> It seems to me, looking at various docs, that wxWidgets
> includes a "media control" that can play video files, but
> it's not included in wxPython. (There's something in
> wxPython with a promising name but it seems to be just audio.)

It is included with wxPython.  But if you look in the overview
in the demo, it it says:

"wx.MediaCtrl is not currently available on unix systems."

So there's your problem, I think.  On Win, it plays a video in
the demo.

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


Re: Why does this group have so much spam?

2009-09-03 Thread Ethan Furman

Steven D'Aprano wrote:

On Thu, 03 Sep 2009 12:19:48 -0700, Ethan Furman wrote:



Steven D'Aprano wrote:


On Thu, 03 Sep 2009 04:01:54 -0400, Terry Reedy wrote:




ISP's price residential service based on average fixed cost and average
usage. Multiple homes using one connection push those averages up.



Is that meant to be a problem?

When people buy more, the unit price they are paying falls, but the
total price they pay generally goes up. E.g. we've recently upgraded
our business link from AUD$150 per month for 60GB to $190 for 100GB.
The per GB price is less, but the total we pay is more -- and the ISP
doesn't have to do much extra work for that extra money.






The difference is that you *upgraded* your service and so incurred a
greater total cost.  If my neighbor lets the rest of the neighborhood
use his wireless, while I do not, yet my prices go up because on average
more usage is happening, I am paying more but not getting more.



Incorrect -- you are getting all the downloads you make yourself, plus 
the warm fuzzy feeling of happiness from the knowledge that other people 
are making downloads you have paid for.


Of course, if you've *unintentionally* left your wi-fi open, perhaps 
"cold feelings of dread and horror" would be more appropriate, but we're 
talking about the situation where folks deliberately leave their wi-fi 
open for whatever reason.





Read a little closer, Steven -- *my* wi-fi is *closed*, it's my neighbor 
(in theory) who has his open, and all that extra usage is making *my* 
rate go up -- no warm fuzzies, only irritation.


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


Re: Why does this group have so much spam?

2009-09-03 Thread Steven D'Aprano
On Thu, 03 Sep 2009 12:19:48 -0700, Ethan Furman wrote:

> Steven D'Aprano wrote:
>> On Thu, 03 Sep 2009 04:01:54 -0400, Terry Reedy wrote:
>> 
>> 
>>>ISP's price residential service based on average fixed cost and average
>>>usage. Multiple homes using one connection push those averages up.
>> 
>> 
>> Is that meant to be a problem?
>> 
>> When people buy more, the unit price they are paying falls, but the
>> total price they pay generally goes up. E.g. we've recently upgraded
>> our business link from AUD$150 per month for 60GB to $190 for 100GB.
>> The per GB price is less, but the total we pay is more -- and the ISP
>> doesn't have to do much extra work for that extra money.
>> 
>> 
>> 
>> 
> The difference is that you *upgraded* your service and so incurred a
> greater total cost.  If my neighbor lets the rest of the neighborhood
> use his wireless, while I do not, yet my prices go up because on average
> more usage is happening, I am paying more but not getting more.

Incorrect -- you are getting all the downloads you make yourself, plus 
the warm fuzzy feeling of happiness from the knowledge that other people 
are making downloads you have paid for.

Of course, if you've *unintentionally* left your wi-fi open, perhaps 
"cold feelings of dread and horror" would be more appropriate, but we're 
talking about the situation where folks deliberately leave their wi-fi 
open for whatever reason.



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


The Python: Rag September issue available

2009-09-03 Thread Bernie
The September issue of The Python: Rag is available at:

http://www.pythonrag.org

A monthly, free, community run, Python magazine - issues are in pdf 
format, intended for anyone interested in Python, without being 
particularly serious.  If you have anything you would like to say about 
Python, please contribute.
-- 
http://mail.python.org/mailman/listinfo/python-list


possible attribute-oriented class

2009-09-03 Thread Ken Newton
I have created the following class definition with the idea of making
a clean syntax for non-programmers to created structured data within a
python environment.

I would appreciate comments on this code. First, is something like
this already done? Second, are there reasons for not doing this?  If
this seems OK, how could I clean up the string conversion to have
indented format.

The expected use would have all items in the structure be simple
python types or AttrClass types. Code written in python could walk the
structure in a simple way to locate any desired values. Code in a
C/C++ extension should also be able to walk the structure to use any
value in the structure.

class AttrClass(object):
"""AttrClass lets you freely add attributes in nested manner"""

def __init__(self):
pass
def __setitem__(self, key, value):
return self.__dict__.__setitem__(key, value)
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, self.__dict__.__repr__())
def __str__(self):
ll = ['{']
for k,v in self.__dict__.iteritems():
ll.append("%s : %s" % (k, str(v)))
return '\n'.join(ll) + '}'

def test():
atr = AttrClass()
atr.first = 1
atr.second = 2
atr.third = 'three'

atrsub = AttrClass()
atrsub.aaa = 'AAA'
atrsub.bbb = 'BBB'

atr.fourth = atrsub
atr.fifth = 5

print atr
print
print repr(atr)
print
print atr.fourth.aaa
=
 test() gives the following output:

{
second : 2
fifth : 5
fourth : {
aaa : AAA
bbb : BBB}
third : three
first : 1}

AttrClass({'second': 2, 'fifth': 5, 'fourth': AttrClass({'aaa': 'AAA',
'bbb': 'BBB'}), 'third': 'three', 'first': 1})

AAA


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


Re: The future of Python immutability

2009-09-03 Thread Gabriel Genellina
En Thu, 03 Sep 2009 15:03:13 -0300, John Nagle   
escribió:



 Python's concept of immutability is useful, but it could be more
general.

 Immutability is interesting for threaded programs, because
immutable objects can be shared without risk.  Consider a programming
model where objects shared between threads must be either immutable or
"synchronized" in the sense that Java uses the term.  Such programs
are free of most race conditions, without much programmer effort to
make them so.


In the current CPython implementation, every object has a reference count,  
even immutable ones. This must be a writable field - and here you have  
your race condition, even for immutable objects.


--
Gabriel Genellina

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


Re: issue with grep command

2009-09-03 Thread Rhodri James

On Thu, 03 Sep 2009 19:51:20 +0100, Jul  wrote:


in tcsh terminal i have the following line of code

cat fileName.txt | grep "a"

which extracts all the instances of "a" from the file in the
terminal..

however when i am trying to create a txt while, i am unable to do so
for some reason..this is the syntaxt i am using --

cat fileName.txt | frep "a" > a.txt


file then appears in the folder, however, it can no be opened because
"the file is not in the right format"..

does anybody know how to correct this problem?

thanks so much


This has sod all to do with Python, but I have to ask: *what* complains
that "the file is not in the right format"?  Also, I don't think you
meant "frep" that second time, but your typing is sufficiently awful
I can't be sure.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: The future of Python immutability

2009-09-03 Thread Paul Rubin
Stefan Behnel  writes:
> Read again what he wrote. In a language with only immutable data types
> (which doesn't mean that you can't efficiently create modified versions of
> a data container), avoiding race conditions is trivial. The most well known
> example is clearly Erlang. Adding "synchronised" data structures to that
> will not make writing race conditions much easier.

Nonetheless, Erlang is subject to all kinds of traditional threading
problems such as deadlocks.  Haskell's use of software transactional
memory may(?) avoid some of the problems but at a performance cost.
-- 
http://mail.python.org/mailman/listinfo/python-list


Different results for request() vs putrequest()

2009-09-03 Thread John Gordon
According to the documentation, these two sections of code should be
equivalent:

  conn = httplib.HTTPSConnection(host)
  conn.putrequest("POST", url)
  conn.putheader("Proxy-Authorization", myProxy)
  conn.putheader("Content-Length", "%d" % len(body))
  conn.endheaders()
  conn.send(body)

vs

  headers = { "Proxy-Authorization": myProxy }
  conn = httplib.HTTPSConnection(host)
  conn.request("POST", url, body, headers)

And yet they are not.  The first section works, but I get an
"HTTP/1.1 401 Unauthorized" error from the second.

Anyone know why?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: First release of pyfsevents

2009-09-03 Thread Nicolas Dumazet
On Sep 3, 10:33 pm, a...@pythoncraft.com (Aahz) wrote:
> I'm curious why you went with FSEvents rather than kqueue.  My company
> discovered that FSEvents is rather coarse-grained: it only tells you that
> there has been an event within a directory, it does *not* tell you
> anything about the change!

It depends what you want to do with your events. In my case, knowing
that an event occurred in a directory is sufficient because I already
know the state of the directory.
If you look in the examples/ folder, (watcher) you'll find that with
very little work, you can maintain a directory snapshot in memory and
compare it against the new state of the directory to know exactly what
happened, when necessary.

kqueue has the limitation that kern.kq_calloutmax is usually set at
4096. Meaning that one could not use this on a big (Mercurial)
repository with 5k files. FSEvents on the other hand saves us the
trouble to have to register each file individually.
Also, I am not quite sure if we can use kqueue to register a
directory, to be warned when a file is created in this directory.



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


Re: Video?

2009-09-03 Thread Avell Diroll

David C Ullrich wrote:
...

Is that correct? If so is there some other standard Python
windowing kit that does include some sort of video functionality?

(Talking Ubuntu Linux if it matters.)


I don't know about video and wxpython, but gstreamer has some python 
bindings (python-gst0.10 on jaunty).

You may find a nice intro here:
http://pygstdocs.berlios.de/


Hope this helped

Ju
--
True friends stab you in the front.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Subclassing list and splicing

2009-09-03 Thread Kreso
Kreso  wrote:
[...]
> I would prefer that resulting object m belonged to myclist class.

I forgot to add that mylist instances in my case have some attributes (that's
why I need special container class in the first place) which should be
preserved after splicing.
  In my simple understaning of python it looks to me that list splicing
has to involve copying (i.e. cannot be done only by referencing), and since 
base class 'list' doesn't know anything about mylist attributes, I will 
certainly 
have to override list's __getslice__ method, right? The only question
is how to re-use as much of the 'lists' methods as possible, so that
at list I don't need to write the code for copying of contained
elements.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First release of pyfsevents

2009-09-03 Thread Aahz
[posted to c.l.py with cc in e-mail, reply to group preferred]

In article ,
Nicolas Dumazet   wrote:
>
>I am proud to announce the first release of pyfsevents, a C extension
>providing a Python interface to the FSEvents API.
>FSEvents is an Apple framework for Mac OS X >=3D 10.5 allowing
>monitoring of file system events on Mac OS platforms.

I'm curious why you went with FSEvents rather than kqueue.  My company
discovered that FSEvents is rather coarse-grained: it only tells you that
there has been an event within a directory, it does *not* tell you
anything about the change!

http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemTechnology/SystemTechnology.html#//apple_ref/doc/uid/TP40001067-CH207-SW4
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: issue with grep command

2009-09-03 Thread Albert Hopkins
On Thu, 2009-09-03 at 11:51 -0700, Jul wrote:

[Stuff about tcsh and grep deleted]

What on earth does this have to do with Python?

-a


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


Re: Python for 64bit Linux version

2009-09-03 Thread Albert Hopkins
On Thu, 2009-09-03 at 13:30 -0500, Bhanu Srinivas Mangipudi wrote:
> 
> I just want to that s there a 64 bit Linux version for python ? if yes
> can you provide me any links for it.I could find a 64bit windows
> version but could not find Linuux version

If you are using a 64bit Linux distribution then likely that
distribution already comes with Python and likely that Python is already
64bit.

Else you can always download the source from python.org yourself and
compile it.

-a


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


Re: Qstrings to Strings

2009-09-03 Thread David Boddie
On Thursday 03 September 2009 21:01, Stefan Behnel wrote:

> Helvin wrote:
>> Just wanted to say, to convert qstrings (or integers for that matter)
>> to strings, use the str() function.
>> 
>> http://learnwithhelvin.blogspot.com/2009/09/qstrings-and-strings.html
> 
> Hmmm, will that return a Unicode string? A byte string would be rather
> inappropriate in most cases. I guess the unicode() function is the right
> thing to use here (or the str() function in Py3 - no idea if that's
> supported by Qt by now).

PyQt4.5 supports Python 3, so I imagine that str() will be what you would
use with that combination. For Python 2, unicode() is probably what most
people want.

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


Video?

2009-09-03 Thread David C Ullrich
Not at all important, just for fun (at least for me):

It seems to me, looking at various docs, that wxWidgets
includes a "media control" that can play video files, but
it's not included in wxPython. (There's something in
wxPython with a promising name but it seems to be just audio.)

Is that correct? If so is there some other standard Python
windowing kit that does include some sort of video functionality?

(Talking Ubuntu Linux if it matters.)

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


Re: Python for 64bit Linux version

2009-09-03 Thread Grant Edwards
On 2009-09-03, Jochen Schulz  wrote:
> Bhanu Srinivas Mangipudi:
>>
>> I just want to that s there a 64 bit Linux version for python
>> ?
>
> Yes.
>
>> if yes can you provide me any links for it.I could find a
>> 64bit windows version but could not find Linuux version
>
> I am currently too lazy to look it up for you on python.org
> (if it is there), but your AMD64 distribution has most likely
> packaged it for you already.

Actually, I find it rather surprising that it's not already
installed. All the distros I've used in the past decade or so
included Python as part of their base install set.

-- 
Grant Edwards   grante Yow! I'm wet!  I'm wild!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The future of Python immutability

2009-09-03 Thread Stefan Behnel
John Nagle wrote:
> With this mechanism, multi-thread programs with shared data
> structures can be written with little or no explicit locking by
> the programmer.  If the restrictions are made a bit stricter,
> strict enough that threads cannot share mutable unsynchronized data,
> removal of the "global interpreter lock" is potentially possible.
> This is a route to improved performance on modern multi-core CPUs.

The main problem with this is that the existing data structures are, well,
there. You can't replace them without breaking all existing Python code,
i.e. without basically inventing a new language. If that's required for
removing the GIL, I doubt that it will ever be done.

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


Re: obscure problem using elementtree to make xhtml website

2009-09-03 Thread Rami Chowdhury

basically any tag that can
have content in html you had better close the html way (),
or IE will see it as unclosed and will not display the rest of the
page after the tag (or do something else unexpected). Not a bug in IE
(this time), which is correctly parsing the file as html.


... which is obviously not the correct thing to do when it's XHTML.


Not correct, of course, but AFAIK it's a very common hack indeed.

If the goal is to produce XHTML that will work as text/html, have you  
considered using one of the myriad templating libraries? IIRC a lot (if  
not most) of them support "HTMLish" output for precisely that reason.


On Thu, 03 Sep 2009 12:09:22 -0700, Stefan Behnel   
wrote:



Lee wrote:

basically any tag that can
have content in html you had better close the html way (),
or IE will see it as unclosed and will not display the rest of the
page after the tag (or do something else unexpected). Not a bug in IE
(this time), which is correctly parsing the file as html.


... which is obviously not the correct thing to do when it's XHTML.

Stefan




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: The future of Python immutability

2009-09-03 Thread Stefan Behnel
Nigel Rantor wrote:
> My comment you quoted was talking about Java and the use of
> synchronized. I fthat was unclear I apologise.

Well, it was clear. But it was also unrelated to what the OP wrote. He was
talking about the semantics of "synchronized" in Java, not the use.

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


Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-03 Thread MacRules

Martin P. Hellwig wrote:

MacRules wrote:


What I am looking for is this.

Oracle DB in data center 1 (LA, west coast)
MSSQL DB in data center 2 (DC, east coast)
So network bandwidth is an issue, I prefer to have gzip fist and 
deliver the data.


If bandwidth is really an issue, you should send compressed delta's.



I need 2 python daemons or a web service here in the future.
I will enter the Oracle table name, user id and password.
So the task is dump out Oracle data (Linux) and insert that to MSSQL.


That is assuming the table is the same and the columns of the table have 
 the same type with the same restrictions and don't even get me started 
about encoding differences.





I can try first with 1 daemon python. Take the Oracle data file, and 
let the daemon connects to MSSQL (with pyodbc) and load the data in.


I think that you are underestimating your task, I would recommend to 
'design' your application first using an UML like approach, whether you 
need one, two or bazillion daemons should not be a design start but a 
consequence of the design.


Anyway here is a sum up and some further pointers to take in regard for 
your design:

- Can I do delta's? (if yes how do I calculate them)
- Are the tables comparable in design
  Specifically if there is a limit on the character width, does Oracle 
and MS-SQL think the same about newlines? (one versus two characters)

- How about encoding, are you sure it works out right?
- Is ATOMIC an issue
- Is latency an issue, that is how long may the tables be out of sync
- Can it be manual or is it preferably automatic
  How about a trigger in the database that sets the sync going, if that 
is too much burden how about a trigger that set a flag on the disk and a 
scheduled job that reads that flag first

- Is security an issue, do I need an encrypted channel

In the past I've wrote a program that had the same starting point as you 
had, over time it grew in design to be a datawarehouse push/pull central 
server with all other databases as an agency. The only reason I wrote it 
was because the more standard approach like business objects data 
integrator was just way too expensive and oracles solutions didn't play 
nice with PostgreSQL (though over time this issue seemed to be resolved).




You understand my issue clearly. For now, I only look for 1 time event, 
I do not need push/pull yet.


For a good push/pull + compression + security + real time in mind, you 
can sell it for decent money.


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


Re: The future of Python immutability

2009-09-03 Thread Nigel Rantor

Stefan Behnel wrote:

Nigel Rantor wrote:

John Nagle wrote:

Immutability is interesting for threaded programs, because
immutable objects can be shared without risk.  Consider a programming
model where objects shared between threads must be either immutable or
"synchronized" in the sense that Java uses the term.
Such programs are free of most race conditions, without much
programmer effort to make them so.

I disagree. They are not free of most race conditions, and it still
takes a lot of effort. Where did you get this idea from? Have you been
reading some Java primer that attempts to make it sound easy?


Read again what he wrote. In a language with only immutable data types
(which doesn't mean that you can't efficiently create modified versions of
a data container), avoiding race conditions is trivial. The most well known
example is clearly Erlang. Adding "synchronised" data structures to that
will not make writing race conditions much easier.


My comment you quoted was talking about Java and the use of 
synchronized. I fthat was unclear I apologise.


Please feel free to read the entirety of my post before replying.

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


Re: The future of Python immutability

2009-09-03 Thread Stefan Behnel
Nigel Rantor wrote:
> 
> John Nagle wrote:
>> Immutability is interesting for threaded programs, because
>> immutable objects can be shared without risk.  Consider a programming
>> model where objects shared between threads must be either immutable or
>> "synchronized" in the sense that Java uses the term.
>> Such programs are free of most race conditions, without much
>> programmer effort to make them so.
> 
> I disagree. They are not free of most race conditions, and it still
> takes a lot of effort. Where did you get this idea from? Have you been
> reading some Java primer that attempts to make it sound easy?

Read again what he wrote. In a language with only immutable data types
(which doesn't mean that you can't efficiently create modified versions of
a data container), avoiding race conditions is trivial. The most well known
example is clearly Erlang. Adding "synchronised" data structures to that
will not make writing race conditions much easier.

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


Re: Why does this group have so much spam?

2009-09-03 Thread Ethan Furman

Steven D'Aprano wrote:

On Thu, 03 Sep 2009 04:01:54 -0400, Terry Reedy wrote:



ISP's price residential service based on average fixed cost and average
usage. Multiple homes using one connection push those averages up.



Is that meant to be a problem?

When people buy more, the unit price they are paying falls, but the total 
price they pay generally goes up. E.g. we've recently upgraded our 
business link from AUD$150 per month for 60GB to $190 for 100GB. The per 
GB price is less, but the total we pay is more -- and the ISP doesn't 
have to do much extra work for that extra money.






The difference is that you *upgraded* your service and so incurred a 
greater total cost.  If my neighbor lets the rest of the neighborhood 
use his wireless, while I do not, yet my prices go up because on average 
more usage is happening, I am paying more but not getting more.


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


Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-03 Thread Martin P. Hellwig

MacRules wrote:


What I am looking for is this.

Oracle DB in data center 1 (LA, west coast)
MSSQL DB in data center 2 (DC, east coast)
So network bandwidth is an issue, I prefer to have gzip fist and deliver 
the data.


If bandwidth is really an issue, you should send compressed delta's.



I need 2 python daemons or a web service here in the future.
I will enter the Oracle table name, user id and password.
So the task is dump out Oracle data (Linux) and insert that to MSSQL.


That is assuming the table is the same and the columns of the table have 
 the same type with the same restrictions and don't even get me started 
about encoding differences.





I can try first with 1 daemon python. Take the Oracle data file, and let 
the daemon connects to MSSQL (with pyodbc) and load the data in.


I think that you are underestimating your task, I would recommend to 
'design' your application first using an UML like approach, whether you 
need one, two or bazillion daemons should not be a design start but a 
consequence of the design.


Anyway here is a sum up and some further pointers to take in regard for 
your design:

- Can I do delta's? (if yes how do I calculate them)
- Are the tables comparable in design
  Specifically if there is a limit on the character width, does Oracle 
and MS-SQL think the same about newlines? (one versus two characters)

- How about encoding, are you sure it works out right?
- Is ATOMIC an issue
- Is latency an issue, that is how long may the tables be out of sync
- Can it be manual or is it preferably automatic
  How about a trigger in the database that sets the sync going, if that 
is too much burden how about a trigger that set a flag on the disk and a 
scheduled job that reads that flag first

- Is security an issue, do I need an encrypted channel

In the past I've wrote a program that had the same starting point as you 
had, over time it grew in design to be a datawarehouse push/pull central 
server with all other databases as an agency. The only reason I wrote it 
was because the more standard approach like business objects data 
integrator was just way too expensive and oracles solutions didn't play 
nice with PostgreSQL (though over time this issue seemed to be resolved).


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: obscure problem using elementtree to make xhtml website

2009-09-03 Thread Stefan Behnel
Lee wrote:
> basically any tag that can
> have content in html you had better close the html way (),
> or IE will see it as unclosed and will not display the rest of the
> page after the tag (or do something else unexpected). Not a bug in IE
> (this time), which is correctly parsing the file as html.

... which is obviously not the correct thing to do when it's XHTML.

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


Re: The future of Python immutability

2009-09-03 Thread Nigel Rantor


John Nagle wrote:

Python's concept of immutability is useful, but it could be more
general.

In the beginning, strings, tuples, and numbers were immutable, and
everything else was mutable.  That was simple enough.  But over time,
Python has acquired more immutable types - immutable sets and immutable
byte arrays.  Each of these is a special case.

Python doesn't have immutable objects as a general concept, but
it may be headed in that direction.  There was some fooling around
with an "immmutability API" associated with NumPy back in 2007, but
that was removed.  As more immutable types are added, a more general
approach may be useful.

Suppose, for discussion purposes, we had general "immutable objects".
Objects inherited from "immutableobject" instead of "object" would be
unchangeable once "__init__" had returned.  Where does this take us?

Immutability is interesting for threaded programs, because
immutable objects can be shared without risk.  Consider a programming
model where objects shared between threads must be either immutable or
"synchronized" in the sense that Java uses the term.


Yes, this is one of the reasons I am currently learning Haskell, I am 
not yet anywhwere near proficient but the reason I am looking into FP is 
because of some of the claims of the FP community, particularly Erlang, 
regarding the benefits of pure FP with respect to multi-threading.


It's a shame this post came right now since I'm not really up-to-speed 
enough with Haskell to comment on it with repsect to multi-threading.



I program Perl, Java and C++ for my day job, I've spent a lot of time 
making multithreaded programs work correctly and have even experienced 
the POE on a large project. So my comments below are based on experience 
of these languages.



> Such programs are free of most race conditions, without much
> programmer effort to make them so.

I disagree. They are not free of most race conditions, and it still 
takes a lot of effort. Where did you get this idea from? Have you been 
reading some Java primer that attempts to make it sound easy?


Java "synchronized" turned out to be a headache partly because 
trying to

figure out how to lock all the "little stuff" being passed around
a headache.  But Java doesn't have immutable objects.  Python does,
and that can be exploited to make thread-based programming cleaner.


This is nothing to do with Java, any multithreaded language that has 
mutable shared state has exactly the same problems. Can we talk about 
threading rather than Java please? Additionally Java provides a lot more 
than monitors (synchronized) for controlling multiple threads.


Java does have immutable objects. Strings in Java are immutable for 
example. As are the object-based numeric types, Bytes, Characters etc.


There are lots and lots of immutable types in Java and you can make your 
own by creating a class with no mutator methods and declaring it "final".



The general idea is that synchronized objects would have built in
locks which would lock at entry to any function of the object and
unlock at exit.  The lock would also unlock at explicit waits.  A
"Queue" object would be a good example of a synchronized object.

With this mechanism, multi-thread programs with shared data
structures can be written with little or no explicit locking by
the programmer.  If the restrictions are made a bit stricter,
strict enough that threads cannot share mutable unsynchronized data,
removal of the "global interpreter lock" is potentially possible.
This is a route to improved performance on modern multi-core CPUs.


Right, this is where I would love to have had more experience with Haksell.

Yes, as soon as you get to a situation where no thread can access shared 
state that is mutable your problems go away, you're also getting no work 
done becasue the threads, whilst they may be performing lots of 
interesting calculations have no way of allowing the rest of the 
program, or operating system, know about it.


You can, today, in any language that provides threads, make any number 
of threaded programs that do not contain any race conditions, it's just 
that most of them are terribly dull and uninteresting.


I'd love for someone from the Haskell/Erlang/ pure FP community 
provide some canonical example of how this is acheived in pure FP. I'll 
get there soon but I'm not going to skip ahead in my reading, I'm still 
trying to learn the basics.


So, in response to your point of trying to get an immutable API so that 
Python can easily have multi-threaded programs that do not present race 
conditions I would say the following:


That is not the challenge, that's the easy part. The challenge is 
getting useful information out of a system that has only been fed 
immutable objects.


Regards,

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


Re: Qstrings to Strings

2009-09-03 Thread Stefan Behnel
Helvin wrote:
> Just wanted to say, to convert qstrings (or integers for that matter)
> to strings, use the str() function.
> 
> http://learnwithhelvin.blogspot.com/2009/09/qstrings-and-strings.html

Hmmm, will that return a Unicode string? A byte string would be rather
inappropriate in most cases. I guess the unicode() function is the right
thing to use here (or the str() function in Py3 - no idea if that's
supported by Qt by now).

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


issue with grep command

2009-09-03 Thread Jul
in tcsh terminal i have the following line of code

cat fileName.txt | grep "a"

which extracts all the instances of "a" from the file in the
terminal..

however when i am trying to create a txt while, i am unable to do so
for some reason..this is the syntaxt i am using --

cat fileName.txt | frep "a" > a.txt


file then appears in the folder, however, it can no be opened because
"the file is not in the right format"..

does anybody know how to correct this problem?

thanks so much
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for 64bit Linux version

2009-09-03 Thread Jochen Schulz
Bhanu Srinivas Mangipudi:
>
> I just want to that s there a 64 bit Linux version for python ?

Yes.

> if yes can you provide me any links for it.I could find a 64bit
> windows version but could not find Linuux version

I am currently too lazy to look it up for you on python.org (if it is
there), but your AMD64 distribution has most likely packaged it for you
already.

J.
-- 
The houses of parliament make me think of school bullies.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-03 Thread MacRules

Ben Finney wrote:

MacRules  writes:


Are you a Python expert?


This group has many Python experts, and even more people who can no
doubt help you if you are able to articulate what you need help with.

To help dispel a possible misunderstanding: Don't expect to have a
one-on-one conversation with a single devoted correspondent here. We
prefer to have these discussions in a manner open for contributions from
everyone, to maximise the benefit for future readers and the chance of
correcting errors.


Can you show me the basic coding to get a Daemon (pass through insert
data) up and insert to the backend MySQL?


This doesn't make a whole lot of sense to me; it sounds like a
conflation of two separate problems that would be best tackled
separately. Can you re-phrase it, perhaps by describing the problem
you're actually trying to solve?

On the topic of implementing a daemon process in Python, there is the
‘python-daemon’ library http://pypi.python.org/pypi/python-daemon>
which I hope you will find useful. If you can describe what you're
actually trying to do, perhaps it will be clearer whether this library
is a good fit.



What I am looking for is this.

Oracle DB in data center 1 (LA, west coast)
MSSQL DB in data center 2 (DC, east coast)
So network bandwidth is an issue, I prefer to have gzip fist and deliver 
the data.


I need 2 python daemons or a web service here in the future.
I will enter the Oracle table name, user id and password.
So the task is dump out Oracle data (Linux) and insert that to MSSQL.


I can try first with 1 daemon python. Take the Oracle data file, and let 
the daemon connects to MSSQL (with pyodbc) and load the data in.

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


Re: Entry Level Python Jobs

2009-09-03 Thread Zaphod
On Thu, 03 Sep 2009 06:36:24 -0700, koranthala wrote:

> 
> Also, I think topcoder.com is a good place for him. I have not used them
> much, but their business plan -- of asking medium to difficult questions
> every week, and contacting people who solves them with jobs -- is quite
> sound.
> Try that too.

I got my first consulting job in a similar fashion.  Local newspaper ad 
said the first consultant who could answer their questions got the job.  
I was the only one that responded correctly and despite my Biochem degree 
was off doing my first commercial application (purchase order system for 
a local Credit Union).
-- 
http://mail.python.org/mailman/listinfo/python-list


Python for 64bit Linux version

2009-09-03 Thread Bhanu Srinivas Mangipudi
Hello Every one,
I just want to that s there a 64 bit Linux version for python ? if yes can
you provide me any links for it.I could find a 64bit windows version but
could not find Linuux version

Your help is appriciated.

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


The future of Python immutability

2009-09-03 Thread John Nagle

Python's concept of immutability is useful, but it could be more
general.

In the beginning, strings, tuples, and numbers were immutable, and
everything else was mutable.  That was simple enough.  But over time,
Python has acquired more immutable types - immutable sets and immutable
byte arrays.  Each of these is a special case.

Python doesn't have immutable objects as a general concept, but
it may be headed in that direction.  There was some fooling around
with an "immmutability API" associated with NumPy back in 2007, but
that was removed.  As more immutable types are added, a more general
approach may be useful.

Suppose, for discussion purposes, we had general "immutable objects".
Objects inherited from "immutableobject" instead of "object" would be
unchangeable once "__init__" had returned.  Where does this take us?

Immutability is interesting for threaded programs, because
immutable objects can be shared without risk.  Consider a programming
model where objects shared between threads must be either immutable or
"synchronized" in the sense that Java uses the term.  Such programs
are free of most race conditions, without much programmer effort to
make them so.

Java "synchronized" turned out to be a headache partly because trying to
figure out how to lock all the "little stuff" being passed around
a headache.  But Java doesn't have immutable objects.  Python does,
and that can be exploited to make thread-based programming cleaner.

The general idea is that synchronized objects would have built in
locks which would lock at entry to any function of the object and
unlock at exit.  The lock would also unlock at explicit waits.  A
"Queue" object would be a good example of a synchronized object.

With this mechanism, multi-thread programs with shared data
structures can be written with little or no explicit locking by
the programmer.  If the restrictions are made a bit stricter,
strict enough that threads cannot share mutable unsynchronized data,
removal of the "global interpreter lock" is potentially possible.
This is a route to improved performance on modern multi-core CPUs.

John Nagle

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


Re: Subclassing list and splicing

2009-09-03 Thread Emile van Sebille

On 9/3/2009 10:10 AM Kreso said...

I am subclassing list class and it basically works, but I don't
understand why after splicing these mylist objects I don't get
returned mylist objects. What I get are list objects:



I would prefer that resulting object m belonged to myclist class.
How to obtain such behaviour? Must I somehow implement __getslice__
method myself?



Yep -- something like:

class mylist(list):
def __init__(self,val=None):
if val is None:
list.__init__(self)
else:
list.__init__(self,val)
def __getslice__(self,slstart,slend,slstep=None):
return mylist(self[slstart:slend:slstep])


Emile


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


Re: match braces?

2009-09-03 Thread John Nagle

lallous wrote:

Hello

In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly "statements blocks").

I am finding it difficult to see blocks and/or jump from end to start
with some IDE hotkeys, when coding in Python. Any advise?


   Write more subroutines.

   If indentation gets deep enough that you have problems following
your own code, it's time to break some of the code out as another
function.

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


Re: Algorithms as objects?

2009-09-03 Thread Kreso
Bearophile  wrote:
> Please, can't you just use a bit of functional-style programming? Like
> creating nested functions on the fly, etc.

I thought about it but I believe that in the future some parts of the
code will be reimplemented in C/C++, so I try to keep it simple.

In the end the hint to learn about "strategy pattern" led me to
construct the program in the way I liked.

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


Subclassing list and splicing

2009-09-03 Thread Kreso

I am subclassing list class and it basically works, but I don't
understand why after splicing these mylist objects I don't get
returned mylist objects. What I get are list objects:


class mylist(list):

def __init__(self):
list.__init__(self)


k = mylist()
k.append(1)
k.append(2)
k.append(3)
print type(k)  # prints  as expected
m = k[:1]
print type(m)  # prints   ???


I would prefer that resulting object m belonged to myclist class.
How to obtain such behaviour? Must I somehow implement __getslice__
method myself?

(It's python 2.5.2, BTW)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print syntax

2009-09-03 Thread Robert Kern

On 2009-09-03 11:50 AM, Benjamin Kaplan wrote:

On Thu, Sep 3, 2009 at 12:22 PM,  wrote:

I am new to python, working by way through 'Core Python Programming'. I can
find no description of using print with the built-in type for formatting. I
think I have got some [most?] of it from Chun, google, and python.org. My
comment is - it should not be that hard to find. I would suggest a link from
the print syntax section.

What is seems to be is:

  print "format-spec" % (variable-list)

I assume the '%' is required token.


The % has absolutely nothing to do with the print statement. The (old)
formatting syntax is based on the C printf syntax but it's actually
the modulo operator on a string, not a piece of the print statement.
The documentation for it is in the documentation for strings.


Namely:

http://docs.python.org/library/stdtypes.html#string-formatting

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: print syntax

2009-09-03 Thread Benjamin Kaplan
On Thu, Sep 3, 2009 at 12:22 PM,  wrote:
> I am new to python, working by way through 'Core Python Programming'. I can
> find no description of using print with the built-in type for formatting. I
> think I have got some [most?] of it from Chun, google, and python.org. My
> comment is - it should not be that hard to find. I would suggest a link from
> the print syntax section.
>
> What is seems to be is:
>
>  print "format-spec" % (variable-list)
>
> I assume the '%' is required token.
>

The % has absolutely nothing to do with the print statement. The (old)
formatting syntax is based on the C printf syntax but it's actually
the modulo operator on a string, not a piece of the print statement.
The documentation for it is in the documentation for strings.

>
>
> _
> Douglas Denault
> http://www.safeport.com
> d...@safeport.com
> Voice: 301-217-9220
>  Fax: 301-217-9277
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recursive decorator

2009-09-03 Thread Ethan Furman

Michele Simionato wrote:

On Sep 3, 12:19 am, Ethan Furman  wrote:


Greetings, List!

The recent thread about a recursive function in a class definition led
me back to a post about bindfunc from Arnaud, and from there I found
Michele Simionato's decorator module (many thanks! :-), and from there I
began to wonder...

from decorator import decorator

@decorator
def recursive1(func, *args, **kwargs):
return func(func, *args, **kwargs)

@recursive1
def factorial1(recurse, n):
if n < 2:
return 1
return n * recurse(n-1)

factorial(4)
TypeError: factorial1() takes exactly 2 arguments (1 given)



What are you trying to do here? I miss why you don't use the usual
definition of factorial.
If you have a real life use case which is giving you trouble please
share. I do not see
why you want to pass a function to itself (?)

M. Simionato


Factorial is an example only.

The original thread by Bearophile:
  http://mail.python.org/pipermail/python-list/2009-May/711848.html

A similar thread from kj (where scopes is the actual problem):
  http://mail.python.org/pipermail/python-list/2009-August/725174.html

Basic summary:  the recursive decorator (the one you snipped, not the 
one showing above), is a replacement for the bindfunc decorator, and 
preserves the signature of the decorated function, minus the 
self-referring first parameter.  It solves kj's problem (although there 
are arguably better ways to do so), and I think helps with Bearophiles 
as well.  As a bonus, the tracebacks are more accurate if the function 
is called incorrectly.  Consider:


In [1]: def recursive(func):
   ...: def wrapper(*args, **kwargs):
   ...: return func(wrapper, *args, **kwargs)
   ...: return wrapper
   ...:

In [2]: @recursive
   ...: def factorial(recurse, n):
   ...: if n < 2:
   ...: return 1
   ...: else:
   ...: return n * recurse(n-1)
   ...:

In [3]: factorial(1, 2)  # in incorrect call

TypeError  Traceback (most recent call last)

C:\pythonlib\ in ()

C:\pythonlib\ in wrapper(*args, **kwargs)

TypeError: factorial() takes exactly 2 arguments (3 given)
 ^
   mildly confusing /


versus the error with the new decorator:


In [2]: factorial(4, 5)  # another incorrect call

TypeError  Traceback (most recent call last)

C:\pythonlib\ in ()

TypeError: factorial() takes exactly 1 argument (2 given)
 

This latter error matches how factorial actually should be called, both 
in normal code using it, and in the function itself, calling itself.


So that's the why and wherefore.  Any comments on the new decorator 
itself?  Here it is again:


def recursive(func):
"""
recursive is a signature modifying decorator.
Specifially, it removes the first argument, so
that calls to the decorated function act as if
it does not exist.
"""
argspec = inspect.getargspec(func)
first_arg = argspec[0][0]
newargspec = (argspec[0][1:], ) + argspec[1:]
fi = decorator.FunctionMaker(func)
old_sig = inspect.formatargspec( \
formatvalue=lambda val: "", *argspec)[1:-1]
new_sig = inspect.formatargspec( \
formatvalue=lambda val: "", *newargspec)[1:-1]
new_def = '%s(%s)' % (fi.name, new_sig)
body = 'return func(%s)' % old_sig
def wrapper(*newargspec):
return func(wrapper, *newargspec)
evaldict = {'func':func, first_arg:wrapper}
return fi.create(new_def, body, evaldict, \
 doc=fi.doc, module=fi.module)

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


print syntax

2009-09-03 Thread doug
I am new to python, working by way through 'Core Python Programming'. I can find 
no description of using print with the built-in type for formatting. I think I 
have got some [most?] of it from Chun, google, and python.org. My comment is - 
it should not be that hard to find. I would suggest a link from the print syntax 
section.


What is seems to be is:

  print "format-spec" % (variable-list)

I assume the '%' is required token.



_
Douglas Denault
http://www.safeport.com
d...@safeport.com
Voice: 301-217-9220
  Fax: 301-217-9277
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating slice notation from string

2009-09-03 Thread Bob van der Poel
On Sep 2, 8:52 pm, Steven D'Aprano
 wrote:
> On Wed, 02 Sep 2009 17:32:09 -0700, Bob van der Poel wrote:
>
> > Actually, nither this or Jan's latest is working properly. I don't know
> > if it's the slice() function or what (I'm using python 2.5). But:
>
> > x = [1,2,3,4,5]
> > slice_string="2"
> > items = [int(n) if n else None for n in slice_string.split(":")]
> > [slice(*items)]
> > [1, 2]
>
> It's not clear what is input and what is output. I'm *guessing* that the
> first four lines are input and the fifth is output.
>
> By the way, nice catch for the "else None". But why are you wrapping the
> call to slice() in a list in the fourth line?
>
> I can't replicate your results. I get the expected results:
>
> >>> slice_string="2"
> >>> items = [int(n) if n else None for n in slice_string.split(":")]
> >>> [slice(*items)]
>
> [slice(None, 2, None)]
>
> exactly the same as:
>
> >>> slice(2)
>
> slice(None, 2, None)
>
> Testing this, I get the expected result:
>
> >>> x = [1,2,3,4,5]
> >>> x[slice(*items)]
>
> [1, 2]
>
> which is exactly the same if you do this:
>
> >>> x[:2:]
>
> [1, 2]
>
> > not the expected:
>
> > [3]
>
> Why would you expect that? You can't get that result from a slice based
> on 2 only. Watch:
>
> >>> x[2::]
> [3, 4, 5]
> >>> x[:2:]
> [1, 2]
> >>> x[::2]
>
> [1, 3, 5]
>
> There is no slice containing *only* 2 which will give you the result you
> are asking for. You would need to do this:
>
> >>> x[2:3]
>
> [3]
>
> Perhaps what you are thinking of is *indexing*:
>
> >>> x[2]
>
> 3
>
> but notice that the argument to list.__getitem__ is an int, not a slice,
> and the result is the item itself, not a list.
>
> To get the behaviour you want, you need something more complicated:
>
> def strToSlice(s):
>     if ':' in s:
>         items = [int(n) if n else None for n in s.split(':')]
>     else:
>         if s:
>             n = int(s)
>             items = [n, n+1]
>         else:
>             items = [None, None, None]
>     return slice(*items)
>
> > Things like -1 don't work either.
>
> They do for me:
>
> >>> slice_string="2:-2"
> >>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> >>> items = [int(n) if n else None for n in slice_string.split(":")]
> >>> x[ slice(*items) ]
> [3, 4, 5, 6, 7, 8]
> >>> x[2:-2]
>
> [3, 4, 5, 6, 7, 8]
>
> > I'm really not sure what's going on, but I suspect it's the way that
> > slice() is getting filled when the slice string isn't a nice one with
> > each ":" present?
>
> I think you're confused between __getitem__ with a slice argument and
> __getitem__ with an int argument.
>
> --
> Steven

Yes, you're right ... I'm confused on what results I expect! Sorry
about that ... now that another day has passed it's all a bit more
clear.

I need to print out a number of these messages and write some test
code.

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


Re: win32pipe

2009-09-03 Thread Tim Golden

Hans Müller wrote:

Hello,

I'd like to play a little with named pipes on windows.
For this purpose google told me there is a win32pipe module.

My python2.6 on windows doesn't know it - so where can I get ?
Does it belong to the std. python for windows or is it a separate
package ?


It's part of the pywin32 package:

 http://sourceforge.net/projects/pywin32/

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


win32pipe

2009-09-03 Thread Hans Müller

Hello,

I'd like to play a little with named pipes on windows.
For this purpose google told me there is a win32pipe module.

My python2.6 on windows doesn't know it - so where can I get ?
Does it belong to the std. python for windows or is it a separate
package ?

Thank a lot,

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


Re: match braces?

2009-09-03 Thread Joshua Judson Rosen
Grant Edwards  writes:
>
> On 2009-09-03, Ben Finney  wrote:
> > Tim Chase  writes:
> > >
> > > Any editor worth its salt will offer indentation-based folding (I know
> > > vim does, and I would be astonished if emacs didn't.
> >
> > Emacs calls that ???hide/show???, and the ???hs-minor-mode??? can
> > be enabled for any buffer (and can thus of course be automatically
> > enabled on defined conditions, e.g. whenever a Python buffer is
> > detected).
> >
> > Learn more at http://www.emacswiki.org/cgi-bin/wiki/HideShow>.
> 
> There's only one problem: it doesn't work out-of-the-box.  At
> least it never has for me.  The only thing it knows how to hide
> is the entire body of a function definition.  I never want to
> do that.  What I want to do is hide/unhide the blocks within
> if/then/else or loops so that the control flow is clearer.
> Emacs hs-minor-mode won't do that (at least not for me).

Hm. I wasn't aware of hs-minor-mode. But I've often used
set-selective-display (C-x $), which hides all lines that are indented
more than ARG columns (and un-hides them if you don't give an argument).

But to fulfill the specific request of moving up to the top of a given
block, there's also a `python-beginning-of-block' command in
python-mode (bound to C-c C-u). If you set the mark (C-SPC) before you
do python-beginning-of-block, then you can use `C-x C-x' or `C-u SPC'
to jump back where you were.


-- 
Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: obscure problem using elementtree to make xhtml website

2009-09-03 Thread Lee
I went with a space, but a comment is a better idea.

I only mention the 

Re: Question about apply

2009-09-03 Thread jorma kala
Many thanks!!



On Thu, Sep 3, 2009 at 4:21 PM, Gary Herron wrote:

>  jorma kala wrote:
>
>>
>> Hi,
>> I'm using apply to pass keyword arguments as a dictionary  to a funcion at
>> runtime (which keyword arguments to pass is only known at runtime)
>> apply is very handy for this, because it takes a dictionary of keyword
>> arguments directly
>>
>> def f1(a=None,b=None,c=None):
>>pass
>> kw={'a':1}
>>
>> apply(f1,[],kw)
>>
>> But I read in the doc that apply is deprecated.
>> What is the non-deprecated way of doing this?
>> Many thanks
>>
>>
> Use the double-star syntax:
>
> f1(**kw)
>
>
> Gary Herron
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about apply

2009-09-03 Thread Gary Herron

jorma kala wrote:


Hi,
I'm using apply to pass keyword arguments as a dictionary  to a 
funcion at runtime (which keyword arguments to pass is only known at 
runtime)
apply is very handy for this, because it takes a dictionary of keyword 
arguments directly


def f1(a=None,b=None,c=None):
pass
   
   
kw={'a':1}


apply(f1,[],kw)

But I read in the doc that apply is deprecated.
What is the non-deprecated way of doing this?
Many thanks



Use the double-star syntax:

f1(**kw)


Gary Herron

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


Re: Annoying octal notation

2009-09-03 Thread James Harris
On 3 Sep, 15:54, Albert van der Horst 
wrote:
> In article ,
> Derek Martin   wrote:
>
>
>
>
>
> >--W1uEbMXJ1Mj4g6TI
> >Content-Type: text/plain; charset=iso-8859-1
> >Content-Disposition: inline
>
> >On Mon, Aug 24, 2009 at 05:03:28PM +, Steven D'Aprano wrote:
> >> On Mon, 24 Aug 2009 11:21:46 -0500, Derek Martin wrote:
> >> > since the old syntax is prevalent both within and without the
> >> > Python community, making the change is, was, and always will be a
> >> > bad idea.
>
> >> Octal syntax isn't prevalent *at all*, except in a small number of
> >> niche areas.
>
> >Steven, don't be obtuse.  Where octal is used in programming, the
> >leading zero is prevalent.
>
> That is not the point. Octal is not prevalent. Leading zero's have
> a mathematical sound meaning. The convention is changed because
> every new user to Python will fall once into this trap.
> For a person not familiar with C or the like this will be a
> hair pulling, nail byting, head banging situation.
> A mathematician might even think he is gone mad.
>
> Regarding you, you will probably have noticed by now that it is
> going to change, so you will not pull your hair, byte your nails

The first time you wrote, "byte your nails," I thought you meant it as
a pun. But since you've mentioned it twice

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


Re: Annoying octal notation

2009-09-03 Thread James Harris
On 3 Sep, 15:35, Grant Edwards  wrote:

...

> >>> Obviously I can't speak for Ken Thompson's motivation in creating this
> >>> feature, but I'm pretty sure it wasn't to save typing or space on
> >>> punchcards. Even in 1969, hex was more common than octal, and yet hex
> >>> values are written with 0x. My guess is that he wanted all numbers to
> >>> start with a digit, to simplify parsing, and beyond that, it was just his
> >>> programming style -- why call the copy command `copy` when you could call
> >>> it `cp`? (Thompson was the co-inventor of Unix.)
>
> >>Maybe it was because they were working on minicomputers, not mainframes,
> >>so there was less processing power and storage available.
>
> > Not just any minicomputers: PDP11. Octal notation is friendly with
> > the PDP11 instruction set.
>
> Indeed.  Octal was the way that all of the DEC PDP-11 sw tools
> displayed machine code/data.

True. Octal was default in Macro-11 and what surprises me is that when
I used it it seemed natural to think in octal (or, preferably, hex)
rather than decimal.

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


Re: Annoying octal notation

2009-09-03 Thread James Harris
On 3 Sep, 14:26, Albert van der Horst 
wrote:
> In article <6031ba08-08c8-416b-91db-ce8ff57ae...@w6g2000yqw.googlegroups.com>,
> James Harris   wrote:
> 
>
>
>
> >So you are saying that Smalltalk has r where
> >r is presumably for radix? That's maybe best of all. It preserves the
> >syntactic requirement of starting a number with a digit and seems to
> >have greatest flexibility. Not sure how good it looks but it's
> >certainly not bad.
>
> >  0xff & 0x0e | 0b1101
> >  16rff & 16r0e | 2r1101
>
> >Hmm. Maybe a symbol would be better than a letter.
>
> Like 0#ff  16#ff ?

Yes, that looks better.

> That is ALGOL68. It is incredible how many of it has become
> vindicated over time. (Yes, nineteen hundred sixty eight was
> the year that language was conceived.)

Yes, and its predecessor Algol 60 was a masterful advance in
programming languages. It set up standards we still use today.

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


Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-03 Thread Ben Finney
MacRules  writes:

> Are you a Python expert?

This group has many Python experts, and even more people who can no
doubt help you if you are able to articulate what you need help with.

To help dispel a possible misunderstanding: Don't expect to have a
one-on-one conversation with a single devoted correspondent here. We
prefer to have these discussions in a manner open for contributions from
everyone, to maximise the benefit for future readers and the chance of
correcting errors.

> Can you show me the basic coding to get a Daemon (pass through insert
> data) up and insert to the backend MySQL?

This doesn't make a whole lot of sense to me; it sounds like a
conflation of two separate problems that would be best tackled
separately. Can you re-phrase it, perhaps by describing the problem
you're actually trying to solve?

On the topic of implementing a daemon process in Python, there is the
‘python-daemon’ library http://pypi.python.org/pypi/python-daemon>
which I hope you will find useful. If you can describe what you're
actually trying to do, perhaps it will be clearer whether this library
is a good fit.

-- 
 \ “If you're not part of the solution, you're part of the |
  `\  precipitate.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about apply

2009-09-03 Thread jorma kala
Hi,
I'm using apply to pass keyword arguments as a dictionary  to a funcion at
runtime (which keyword arguments to pass is only known at runtime)
apply is very handy for this, because it takes a dictionary of keyword
arguments directly

def f1(a=None,b=None,c=None):
pass


kw={'a':1}

apply(f1,[],kw)

But I read in the doc that apply is deprecated.
What is the non-deprecated way of doing this?
Many thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating slice notation from string

2009-09-03 Thread Falcolas
On Sep 2, 3:55 pm, bvdp  wrote:
> I'm trying to NOT create a parser to do this  and I'm sure that
> it's easy if I could only see the light!
>
> Is it possible to take an arbitrary string in the form "1:2", "1",
> ":-1", etc. and feed it to slice() and then apply the result to an
> existing list?
>
> For example, I have a normal python list. Let's say that x = [1,2,3,4]
> and I have a string, call it "s', in the format "[2:3]". All I need to
> do is to apply "s" to "x" just like python would do.
>
> I can, of course, convert "x" to a list with split(), convert the 2
> and 3 to ints, and then do something like: x[a:b] ... but I'd like
> something more general. I think the answer is in slice() but I'm lost.
>
> Thanks.

You might also consider looking at the operator module, which provides
to potentially useful methods - itemgetter and getslice. Neither will
directly use the string containing the bare slice notation, however
they do provide another alternative to directly using eval.

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


Re: Python on the Web

2009-09-03 Thread Bruno Desthuilliers

John Nagle a écrit :
(snip)
MySQLdb is available only up to Python 2.5.  


Huh ???


Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/var/lib/python-support/python2.6/MySQLdb/__init__.py:34: 
DeprecationWarning: the sets module is deprecated

  from sets import ImmutableSet
>>> cnx = MySQLdb.connect(db='cress', user='cress', passwd='cress')
>>> cursor = cnx.cursor()
>>> cursor.execute("SELECT id_article, titre FROM spip_articles")
28L
>>> for row in cursor:
... print row
...
(1L, '01. Sensibilisation')
(2L, '02. Gestation')
(3L, '03. Lancement')
(4L, '04. D\xe9veloppement')
(5L, '01. Sensibilisation')
(6L, '02. Gestation')
(7L, '03. Lancement')
(8L, '04. D\xe9veloppement')
(9L, '01. Sensibilisation')
(10L, '02. Gestation')
(11L, '03. Lancement')
(12L, '04. D\xe9veloppement')
(13L, 'Nouvel article')
(14L, 'Nouvel article')
(15L, '01. Les principes fondateurs d\x92une coop\xe9rative')
(16L, '02. C\x92est quoi une COOPERATIVE ?')
(17L, '10. Les principes fondamentaux de l\x92Economie sociale et 
solidaire')

(18L, '20. Les familles de l\x92Economie sociale et solidaire ')
(19L, 'Article 1')
(20L, 'Article 2')
(21L, 'Article 3')
(22L, 'Article 4')
(23L, 'Article 5')
(24L, 'Lancement du nouveau site de la CRESS')
(25L, 'Mise \xe0 jour des Formations')
(26L, "La CRESS au Salon de l'Emploi")
(27L, '01. Pr\xe9sentation')
(28L, '20. Les formations universitaires BAC +3')
>>> cursor.close()
>>> cnx.close()
>>>

Seems to work just fine here...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Annoying octal notation

2009-09-03 Thread Grant Edwards
On 2009-09-03, Albert van der Horst  wrote:
> In article ,
> MRAB   wrote:
>>Steven D'Aprano wrote:
>
>>> Obviously I can't speak for Ken Thompson's motivation in creating this
>>> feature, but I'm pretty sure it wasn't to save typing or space on
>>> punchcards. Even in 1969, hex was more common than octal, and yet hex
>>> values are written with 0x. My guess is that he wanted all numbers to
>>> start with a digit, to simplify parsing, and beyond that, it was just his
>>> programming style -- why call the copy command `copy` when you could call
>>> it `cp`? (Thompson was the co-inventor of Unix.)
>>>
>>Maybe it was because they were working on minicomputers, not mainframes,
>>so there was less processing power and storage available.
>
> Not just any minicomputers: PDP11. Octal notation is friendly with
> the PDP11 instruction set.

Indeed.  Octal was the way that all of the DEC PDP-11 sw tools
displayed machine code/data.

-- 
Grant Edwards   grante Yow! My CODE of ETHICS
  at   is vacationing at famed
   visi.comSCHROON LAKE in upstate
   New York!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: obscure problem using elementtree to make xhtml website

2009-09-03 Thread Lee
I went with a space, but a comment is a better idea.

I only mention the 

Re: match braces?

2009-09-03 Thread Grant Edwards
On 2009-09-03, Ben Finney  wrote:
> Tim Chase  writes:
>
>> Any editor worth its salt will offer indentation-based folding (I know
>> vim does, and I would be astonished if emacs didn't.
>
> Emacs calls that ???hide/show???, and the ???hs-minor-mode??? can be enabled 
> for
> any buffer (and can thus of course be automatically enabled on defined
> conditions, e.g. whenever a Python buffer is detected).
>
> Learn more at http://www.emacswiki.org/cgi-bin/wiki/HideShow>.

There's only one problem: it doesn't work out-of-the-box.  At
least it never has for me.  The only thing it knows how to hide
is the entire body of a function definition.  I never want to
do that.  What I want to do is hide/unhide the blocks within
if/then/else or loops so that the control flow is clearer.
Emacs hs-minor-mode won't do that (at least not for me).

ISTR that you are supposed to be able to get it working by
replacing python-mode with some after-market version and then
patching the hide-show code or something like that -- but I've
never been brave enough (or bored enough) to attempt it.

-- 
Grant Edwards   grante Yow! Not SENSUOUS ... only
  at   "FROLICSOME" ... and in
   visi.comneed of DENTAL WORK ... in
   PAIN!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python on the Web

2009-09-03 Thread Bruno Desthuilliers

Ed Singleton a écrit :

On Aug 26, 4:17 am, alex23  wrote:

Frameworks created for the sake of creating a framework, as opposed to
those written to meet a defined need, tend to be the worst examples of
masturbatory coding.


Indeed, but masturbation is perfectly healthy and acceptable, and we
all do it every now and then.  It is however, much like the framework
in question, best kept private and not made public.



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


Re: python daemon - compress data and load data into MySQL by pyodbc

2009-09-03 Thread David Smith
MacRules wrote:
> Sean DiZazzo wrote:
>> On Sep 2, 8:36 pm, MacRules  wrote:
>>> Hi,
>>>
>>> I installed Python daemon, pyodbc module to access the back-end DB
>>> server.
>>>
>>> My setup is like this
>>>
>>> load data job -> Python Daemon A, port 6000 -> Python Daemon B, port
>>> 7000 -> MySQL
>>>
>>> Daemon A will perform data compression, such as GZIP, and send over data
>>> to Daemon B.
>>> Daemon B will perform data uncompression, GUNZIP, and insert records to
>>> MySQL or MSSQL or Oracle.
>>>
>>> Where should I start this to code this?
>>> Can someone give me a hint, as detail as possible here?
>>>
>>> I am a python newbie.
>>>
>>> Thanks for all the help I can get,
>>
>> Start by reading the tutorial.  http://docs.python.org/tutorial/
>>
>> ~Sean
> Are you a Python expert?
> Can you show me the basic coding to get a Daemon (pass through insert
> data) up and insert to the backend MySQL?
> 

You've asked a rather large and non-specific question.  What avenues
have you explored so far?  Can you describe the problem this is designed
to solve?

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


Re: Modifying a textfile

2009-09-03 Thread konstantin
On Sep 3, 2:21 pm, Olli Virta  wrote:
> Hi!
>
> So I got this big textfile. It's full of data from a database. About
> 150 or
> more rows or lines in a textfile.
> There's three first rows that belong to the same subject. And then
> next
> three rows belong to another subject and so on, to the end of the
> file.
>
> What I need to do, is put the three rows that goes together and belong
> to
> certain subject, on a one line in the output textfile. And the next
> three
> rows again on a one new line. And that goes with the rest of the data
> to
> the end of the new file.
>
> Can't figure out a working loop structure to handle this.
>
>  Thanks! OV

Straightforward generator version.

src = file('test_in.txt', 'r')
dst = file('test_out.txt', 'w')

def reader(src):
count, lines = 0, ''
for line in src:
if count < 2:
lines += line.strip()
count += 1
else:
yield lines + line
count, lines = 0, ''
if lines:
yield lines + '\n'

for lines in reader(src):
dst.write(lines)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: obscure problem using elementtree to make xhtml website

2009-09-03 Thread David Smith
Lee wrote:
> Elementtree (python xml parser) will transform markup like
> 
> 
> 
> into
> 
> 
> 
> which is a reasonable thing to do for xml (called minimization, I
> think).
> 
> But this caused an obscure problem when I used it to create the xhtml
> parts of my website,
> causing Internet Explorer to display nearly blank pages. I explain the
> details at
> 
> http://lee-phillips.org/scripttag/
> 
> and am writing here as a heads-up to anyone who might be using a
> workflow similar to mine: writing documents in xml and using python
> and elementtree to transform those into xhtml webpages, and using the
> standard kludge of serving them as text/html to IE, to get around the
> latter's inability to handle xml. I can't be the only one (and I doubt
> this problem is confined to elementtree).
> 
> 
> Lee Phillips

It's not just Elementtree that does this .. I've seen others libraries
(admittedly in other languages I won't mention here) transform empty
tags to the self-terminating form.  A whitespace text node or comment
node in between *should* prevent that from happening.  AFAIK, the only
tag in IE xhtml that really doesn't like to be reduced like that is the
 tag.  Firefox seems to be fine w/ self-terminating