Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
John Machin wrote:

> Are you suggesting a rework of the manual instead of inserting a X in
> the offending py_DECREF?

are you suggesting slowing things down just because of a bug in the 
documentation ?   you cannot return an uninitialized list object to 
Python anyway, so there's no need to add extra checks to a function 
that's *documented* to be the equivalent of a *Python-level* sequence 
assignment.

the "I spent time debugging this, so now everyone should suffer" 
approach doesn't strike me as very Pythonic.



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


Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
Jack Diederich wrote:

> It is handy for functions that take a mutable list as an argument.

an *existing*, and properly *initialized*, mutable sequence.  PyList_New 
doesn't give you such an object.



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


Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
Jack Diederich wrote:

>> For avoidance of doubt: the change is to use Py_XDECREF, yes/no?
> 
> Yes.

not necessarily: the bug is that you're using an uninitialized object in 
a context that expects an initialized object.  might be a better idea to 
raise a SystemError exception.



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


Re: Adding a char inside path string

2006-08-17 Thread Tim Williams
On 17/08/06, Sybren Stuvel <[EMAIL PROTECTED]> wrote:
> Dennis Lee Bieber enlightened us with:
> >   What happens when you get a pathname that looks like:
> >
> > \\who\cares\common.exe\program.exe
>
> Is that possible on Windows? At one point, I named a directory
> "www.something.com" and then it wouldn't open, because it was an
> invalid .COM file...

It is possible on XP.   I just created this structure

C:\Documents and Settings\TW\Desktop\test\test.com\test.exe\test
space\data\data.txt

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


Looking For mp3 ID Tag Module

2006-08-17 Thread Tim Daneliuk
I have DAGS and generally nosed around the net but cannot quite find what
I need.  I am looking for a platform-independent Python module that would
permit me to write mp3 ID tags conformant to the latest spects.  I am
currently calling 'mp3info' from my Python script, but that program is limited
to the older ID tags that are severely limited in length and thus truncate
the description strings I am providing.

Ideas anyone?
-- 

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/
-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython GUI update with data from a MySQL database

2006-08-17 Thread Alina Ghergu
Hi there,

I'm currently developing a GUI for a network monitor. I have to plot
data taken from a MySQL database. For GUI I use wxPython, for plotting
Matplotlib. The plotting has to be realtime,  so
I have to query the database periodically. I don't have enough
experience in programming and I would need some advice about the best
approach in this matter.

I tried to solve it using wx.Timer but from time to time MySQL server
doesn't repond to queries. I use one db connection for all my queries.
I also tried a threads approach but because I don't know how to use
them the result was worse.

Any sugestion will be highly apreciated.

Alina

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


Re: trouble understanding inheritance...

2006-08-17 Thread Steven D'Aprano
On Wed, 16 Aug 2006 12:53:12 -0700, KraftDiner wrote:

>> > Well how does one select which class baseClass really is when you
>> > contruct the object?
>> > What am I missing?
>> >
>> > a = typeA()
>> > b = typeB()
>> > c = baseClass(a)
>>
>> a = typeA()
>> b = typeB()
>>
>> You're done. Stop there.
>>
> I can see that this might work...
> c = [a, b]
> for c in [a,b]:
>c.getName()
> 
> but when does baseClass ever get used?
> Why did i even have to define it?

So that you don't duplicate code. That's it.

Here is a basic example. I have a class Foo with a method foo() that
returns "foo", and a second class Foos which is *almost* the same except
method foo() takes an argument and returns that number of foos.

class BaseClass():
def foo(self):
return "foo"

class Foo(BaseClass):
def foo(self):
return self.__class__.foo() # call the parent class method

class Foos(BaseClass):
def foo(self, n):
return self.__class__.foo() * n


Obviously in this case, there is no real need for BaseClass -- Foos could
inherit from Foo. But in more complex cases, you might need something like
this.

Hope this helps.


-- 
Steven D'Aprano 

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


Re: wxPython GUI update with data from a MySQL database

2006-08-17 Thread Krzysztof Stachlewski
"Alina Ghergu" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Hi,

> I have to query the database periodically. I don't have enough
> experience in programming and I would need some advice about the best
> approach in this matter.
>
> I tried to solve it using wx.Timer but from time to time MySQL server
> doesn't repond to queries. I use one db connection for all my queries.

What is the error returned from MySQL when it is not responding to queries?

Stach


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


Re: PySequence_SetItem

2006-08-17 Thread John Machin

Fredrik Lundh wrote:
> John Machin wrote:
>
> > Are you suggesting a rework of the manual instead of inserting a X in
> > the offending py_DECREF?
>
> are you suggesting slowing things down just because of a bug in the
> documentation ?

Not explicitly; not intentionally.

>  you cannot return an uninitialized list object to
> Python anyway, so there's no need to add extra checks to a function
> that's *documented* to be the equivalent of a *Python-level* sequence
> assignment.

1. It's also documented as being the recommended way of filling up a
list after PyList_New.

2. So you'd rather not change the code, and just let it segfault if
someone calls it (or PyObject_SetItem) instead of PyList_SetItem?

>
> the "I spent time debugging this, so now everyone should suffer"
> approach doesn't strike me as very Pythonic.

That's the wildest leap from scant evidence to a wrong conclusion  that
I've seen for quite a while :-)

Anyway, having had a look at the code:

#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)

I have to say that I'm truly sorry, I wasn't aware  that that little
"skip if zero" chunk of code was up there with cancer, AIDS and bombs
-- I'll pull my head in and not refer to the topic again.

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


Re: hide python code !

2006-08-17 Thread Steven D'Aprano
On Wed, 16 Aug 2006 13:39:10 -0700, danielx wrote:

> Steven D'Aprano wrote:
>> On Tue, 15 Aug 2006 09:00:16 -0700, Ben Sizer wrote:
>>
>> > Yes, in much the same way that there is no point ever locking your
>> > doors or installing burglar alarms, as a determined thief will
>> > eventually steal your belongings.
>>
>> That's an utterly pointless and foolish analogy.
>>
>> (1) If a thief breaks into your house and steals your TV, you no longer
>> have a TV. If a developer sees your code, you still have your code, *even
>> if they subsequently copy it*. You haven't lost your code, it is just no
>> longer secret. Since secrecy is rarely valuable in and of itself, you've
>> lost nothing.
> 
> But haven't you lost your control over the code? If you were trying to
> sell a program (regardless of whether this is a good way to make money
> from it), hasn't your ability to do so been undercut? This is the loss.

Maybe so. And if a competitor creates a better product than yours, hasn't
your ability to sell your program been undercut too?

Either scenario has NOTHING to do with thieves breaking into your house
and locks on doors. The analogy is bogus. Undercutting your ability to
sell a product is not theft, and compiling source code to machine code is
not analogous to a lock on the door.


>> Yes, I've heard all the stories about "valuable algorithms" and the like.
>> Some of them might even be true. But for 99+% of code, spending even one
>> cent to keep it secret is just wasting money.
> 
> That may be true, but for someone who has determined that the hiding
> the code would be best, it would seem to be quite a good investment.

Whether it "seems" to be a good investment is quite different from whether
it *is* a good investment.

If they ask me for advice, I'll tell them that they're almost certainly
wasting their time, that their algorithm almost certainly isn't as
valuable as they think, and that if they disagree, well, Python supports
.pyc files, there are tools like py2exe which will put their Python code
inside an exe file, there is a Python obfuscator, and a few other tricks.
If none of those things are good enough for them, then Python is not the
language they want to be using.

As for the rest of your post, it is mostly irrelevant. However, I will
answer one last point:

[snip]

> Even if we don't take the "twice" figure literally, I imagine
> that most of us would agree that the amount that the bar can be raise
> is considerable and not insignificant.

I dispute that "most of us" agree that the bar can be raised a
considerable amount. It is my position that in the real world, as opposed
to the fantasies of amateur programmers, compiling code is virtually NO
BARRIER to your competitors understanding your algorithm.

Perhaps you would like to consider how it is that black-hat hackers and
virus writers can analyse Microsoft Windows for vulnerabilities and
security holes *without access to the source code*? 

(And by the way: your suggestion that Microsoft has very few workers is
wrong. Microsoft has approximately 60,000 employees, and that almost
certainly doesn't include the many sub-contractors they hire.
http://www.networkworld.com/news/financial/microsoft.html ) 



-- 
Steven D'Aprano 

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


Re: Looking For mp3 ID Tag Module

2006-08-17 Thread Iñigo Serna
Hi Tim,

try mutagen. http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen

Regards,
Iñigo


On 8/17/06, Tim Daneliuk <[EMAIL PROTECTED]> wrote:
> I have DAGS and generally nosed around the net but cannot quite find what
> I need.  I am looking for a platform-independent Python module that would
> permit me to write mp3 ID tags conformant to the latest spects.  I am
> currently calling 'mp3info' from my Python script, but that program is limited
> to the older ID tags that are severely limited in length and thus truncate
> the description strings I am providing.
>
> Ideas anyone?
> --
> 
> Tim Daneliuk [EMAIL PROTECTED]
> PGP Key: http://www.tundraware.com/PGP/
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython GUI update with data from a MySQL database

2006-08-17 Thread Alina Ghergu

Krzysztof Stachlewski wrote:
> "Alina Ghergu" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> Hi,
>
> > I have to query the database periodically. I don't have enough
> > experience in programming and I would need some advice about the best
> > approach in this matter.
> >
> > I tried to solve it using wx.Timer but from time to time MySQL server
> > doesn't repond to queries. I use one db connection for all my queries.
>
> What is the error returned from MySQL when it is not responding to queries?
>
> Stach

Hi Stach,

The error is "Lost connection to MySQL server during query".

Alina

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


Re: hide python code !

2006-08-17 Thread Paul Boddie
danielx wrote:
>
> But we have only considered the economics of such a decision. Even if
> there is no market value to a work, a person has an understandable
> desire to exercise the rights of ownership over a work, given the
> amount of personal investment one makes in producing it.

There are other motivations, too. An author might wish that their work
convey a particular message and that others should not be able to make
derived works which distort or contradict that message. However, there
are various established principles of fair use which limit the author's
control over such derived works.

[...]

> I think the above idea is frequently missed in discussions about
> copyrights/patents in the open source world. There, the focus seems to
> be on the marketability granted by protections (legal or physical). The
> post I am responding to illustrates this focus. Do we believe an author
> forfeits ownership of a work merely by sharing it? As a matter of
> conscience, I don't believe the answer can be imposed on anyone. Every
> person must answer this for him or herself.

As we've mentioned above, one crucial issue is control over published
works and over the potentially related works of others. With software,
such control is mediated by the licence which is often prominent, even
unavoidable when using proprietary software; thus, people using or
distributing software should be aware of the licence which applies to
the work. In contrast, works in areas such as popular music are not
prominently "labelled" with licensing information if you're listening
to that music playing on the radio, television, in a public space, and
so on. This apparent "promiscuity" with such works leads people to
believe that they are freely exchangeable and that the author is not
exercising control, even if that isn't really the case due to the
framework established by the recording industry for broadcasters.

So, people perceive an apparent lack of control as some kind of lack of
ownership, that the work has, by being shared in an apparently
unconditional way, become part of their common culture - a sentiment or
an understanding that can presumably be traced back throughout the
history of human culture itself. At the opposite end of the spectrum of
control, when mechanisms of control are used to restrict the
distribution of derived works or the production of coincidentally
related works, is it unfair that people wish to disregard such
apparently counter-intuitive mechanisms? An interesting example in
popular culture was the legal argument about whether silence
constitutes an original work
(http://news.bbc.co.uk/1/hi/entertainment/music/2133426.stm), but
things like patents affect the ability of others to create works in a
fashion that can be much harder to predict.

Paul

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


Re: Curried class methods?

2006-08-17 Thread Antoon Pardon
On 2006-08-17, Scott Lamb <[EMAIL PROTECTED]> wrote:
> I'm trying to dynamically generate class methods which have access to
> some state passed in at creation time. (Basically as a workaround to
> twisted's trial not having a way to dynamically add stuff. Plain
> unittest seems to have TestSuite, but the trial runner doesn't know
> about it.)
>
> My first attempt might better illustrate this -
>
> class Foo:
> def generalized(self, ctx):
> print 'my ctx is %r' % ctx
>
> for i in ['a','b','c']:
> setattr(Foo, i, lambda self: self.generalized(i))
>
> foo = Foo()
> foo.a()
> foo.b()
> foo.c()
>
> but this prints "my ctx is c" three times; I'd hoped for a, b, c, of
> course. After reading
>, I
> think I understand why this is - "i" doesn't actually get added to each
> new function's context; they just reference the global one. Even if I
> do this:

Try this instead as the for loop

for i in ['a','b','c']:
setattr(Foo, i, lambda self, a=i: self.generalized(a))

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


[廣告]徵人~兼職工作全職收入(可在家工作)

2006-08-17 Thread
Part-time job Full-time income
美商高科技生化公司加州百大企業來台拓展亞太市場
誠徵兼職人員,每日2~3小時,月入1萬~3萬

若你對網路工作有興趣,請至下列網站留下資料
請詳閱網站的內容並填寫履歷
索取電子書~便會有輔導員與你聯絡

98.to/專兼職工作

若你不是認真的請勿填寫,我們會經過篩選
請不要浪費你填寫履歷及我們觀看履歷的時間

--
夫兵者不祥之器物或惡之故有道者不處君子居則貴左用兵則貴右兵者不祥之器非君子
之器不得已而用之恬淡為上勝而不美而美之者是樂殺人夫樂殺人者則不可得志於天下
矣吉事尚左凶事尚右偏將軍居左上將軍居右言以喪禮處之殺人之眾以哀悲泣之戰勝以
喪禮處之道常無名樸雖小天下莫能臣侯王若能守之萬物將自賓天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦將知止知止可220-137-45-9.dynamic.hinet.net海
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
John Machin wrote:

> 1. It's also documented as being the recommended way of filling up a
> list after PyList_New.

since it doesn't work in any existing Python release, it's hardly "recommended".

the Python documentation has never been formally binding; if the documentation
doesn't match the code, it's usually the documentation that's flawed.

> 2. So you'd rather not change the code, and just let it segfault if
> someone calls it (or PyObject_SetItem) instead of PyList_SetItem?

as I said, you're using an API that's designed for use on *properly initialized*
objects on an object that *hasn't been initialized*.  if you're going to patch 
all
places where that can happen, you might as well rewrite the entire interpreter.

the documentation is broken, and *must* be fixed.  catching this specific case
in the code is a lot less important; it's just one of many possible errors you 
can
make when writing C-level code.  there's simply no way you can catch them
all.

 



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


Re: Compiling wxPython app for Windows; Single EXE

2006-08-17 Thread ajaksu
GHUM wrote:
> and with py2exe:
> Changes in 0.6.1:
>
> * py2exe can now bundle binary extensions and dlls into the
>   library-archive or the executable itself.  This allows to
>   finally build real single-file executables.
>
>   The bundled dlls and pyds are loaded at runtime by some special
>   code that emulates the Windows LoadLibrary function - they are
>   never unpacked to the file system.
>
> this "they are never unpacked to the file system" is the USP of py2exe
> to me at the moment.

Thank you very much, Harald, this is very important. As I mentioned,
PyInstaller single file has a bad start up time... your information is
enough for me to dive in py2exe for good :)

Biased or not, you may have performed one more conversion ;)
Daniel

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


Re: MySQLdb installation error

2006-08-17 Thread hiaips

What I'm getting at is that it looks like one of these arch flags needs
to be removed, as a previous poster said. I remember having a similar
issue with an arch flag when installing some Python module (don't
remember whether it was MySQLdb or not), and I fixed it by installing
the Universal SDK that comes with XCode on OS 10.4. If this is not an
option for you (and it sounds as though it may not be), you might also
try editing the Makefile to remove the flag corresponding to the
architecture that does not match your system.

"uname -a" should tell you which architecture you're on as well as what
version of the OS you're running.

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


PythonCard question

2006-08-17 Thread DarkBlue
Is it possible to create pythoncard textField components 
dynamically during run time ?

Something on the lines of

pseudo code :

def make_textfield(length,topleftposx,topleftposy):
doit

self.make_textfield(120,20,20)

  
Thanks for any ideas.


   

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


Read Picasa metadata using Python?

2006-08-17 Thread Thomas W
I know this is slightly off-topic, but since Python is hot at Google
and several key members from the python community works there, I was
hoping to get some help on this subject.

I want to create a small app that reads my Picasa-metadata related to a
specified image and uploads my image and metadata to my
Flickr.com-account ( as far as I know Picasa only support Blogger ).

Anyway, if there are any other app allready reading Picasa metadata
with Flickr-support that you know of that would save me alot of
work/hassle. Still, Picasa is great, but I would really like access to
my own metadata outside Picasa and I want to use python to do it.

Thanks in advance,
Thomas

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



Re: OT: p-gal website

2006-08-17 Thread ajaksu
John Bokma wrote:
> "ajaksu" <[EMAIL PROTECTED]> wrote:
>
> > Don't :)
> > Even Firefox developers will tell you to avoid this. Develop for
> > standards compliant browsers (including Firefox) by testing against
> > the standards. Neither your HTML or CSS pass validation, both due to
> > minor, easy-to-fix issues.
>
> If you actually read those "standards" you will know that the documents
> itself are called Recommendations or Working drafts. Why someone
> recommends to follow documentation but isn't even able to name them as
> they are named in the documentation itself is beyond me.

Hi John, sorry about the delay (been offline for a couple of days).

First I'd like to point out that I didn't mean to be rude or attack
Paolo, I invested some time trying to diagnose the problems with his
site and in fact I'm kinda working for him this morning :)

Then, I'd ask you to read his post, as it was the first use of
standard: "standard compliance problem".

And to answer your question, I recommend to follow standards because
that's how I call the mixed bag of Recommendations, some of which are
also Specifications, allowing for the inclusion of both significant
Standards and standards. I guess I must've been bitten by the buzzword
bug, sorry it that offends you. But I'm not the only one (TM).

> This is the W3C Markup Validation Service, a free service that checks Web
> documents in formats like HTML and XHTML for conformance to W3C
> Recommendations and other standards.
> http://validator.w3.org/
This seems to imply that W3C considers Recommendations to be standards
(sorry if I'm mistaken, my English is not that good).

> Support for open Web standards in Firefox ensures you can get the most
> out of this emerging class of Web-based tools.
> http://www.mozilla.com/firefox/
I guess this is why we were using that word, given the Firefox context.

So I might be "able to name them as they are named in the
documentation(sic) itself", but I'd rather try to help than offer
qwerty sacrifices to the Holy Dictionary and His trolly followers ;)

Daniel

> The Web Standards Project is a grassroots coalition fighting for standards
> which ensure simple, affordable access to web technologies for all.
> http://www.webstandards.org/

> While Opera is well capable of showing standards-compliant pages correctly,
> not all web pages are compliant.
> http://www.opera.com/docs/specs/doctype/

> (A)uthors are forced to choose between writing valid, standards-compliant
> documents and providing content that renders properly on the browsers of
> most visitors.
> http://en.wikipedia.org/wiki/XHTML

> Although the rise of web standards has done much to alleviate the plight of
> web developers, browsers may still have sharply different opinions on one
> bit of CSS or JavaScript.
> http://www.quirksmode.org/browsers/intro.html

> Standard
> A specification for hardware or software that is either widely used and
> accepted (de facto) or is sanctioned by a standards organization (de jure).
> http://www.answers.com/standard&r=67

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


Re: PythonCard question

2006-08-17 Thread [EMAIL PROTECTED]

DarkBlue wrote:
> Is it possible to create pythoncard textField components
> dynamically during run time ?
>
> Something on the lines of
>
> pseudo code :
>
> def make_textfield(length,topleftposx,topleftposy):
> doit
>
> self.make_textfield(120,20,20)
>
>
> Thanks for any ideas.

The noresource.py sample that ships with PythonCard shows how to add
components at runtime.

HTH

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


Re: Python form Unix to Windows

2006-08-17 Thread Harry George
"Simon Forman" <[EMAIL PROTECTED]> writes:
[snip]
> Simplest way: Run the app in windows, see what breaks (probably less
> than you might think), fix it.
> 
> I have written large apps that required less than a dozen, or no,
> changes to move between windows and *nix.  YMMV
> 
> Peace,
> ~Simon
> 

I agree with this-- just try it.  When I've helped others move code, I
found the biggest problem was when they had hardcoded file paths instead of
using os.path mechanisms.

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Grid Question

2006-08-17 Thread ajaksu
Jordan wrote:
> Hey Peoples,
> I'm wonderg if there is a way to make a subclass of wx.grid.Grid in
> which the coloumn labels for the grid appear on the bottom of the grid
> instead of the top.

Hi Jordan :)

Not quite what you want, but I'm about to try faking labels in a grid.
The reason is that I want more control regarding rendering the labels
(using simple checkboxes and other features). So I'll try to get the
first row to display as "headers". If that works, would it help you?
And would you append rows frequently?

Just FWIW, I recall reading that a grid is composed of some base
elements (scrolled window and something else), so you might try to
follow that lead. But jean-michel has two good points: it could be
easier to use 2 grids and http://wxpython.org/maillist.php would give
you better answers :)

Cheers,
Daniel

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


The Semicolon Wars as a software industry and human condition

2006-08-17 Thread Xah Lee
Of interest:

• The Semicolon Wars, by Brian Hayes. 2006.
 http://www.americanscientist.org/template/AssetDetail/assetid/51982

in conjunction to this article, i recommend:

• Software Needs Philosophers, by Steve Yegge, 2006
http://xahlee.org/Periodic_dosage_dir/_p/software_phil.html

• What Languages to Hate, Xah Lee, 2002
http://xahlee.org/UnixResource_dir/writ/language_to_hate.html

  Xah
  [EMAIL PROTECTED]
∑ http://xahlee.org/

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

List match

2006-08-17 Thread OriginalBrownster
Hi there:

I know this probably is a very easy thing to do in python, but i wanted
to compare 2 lists and generate a new list that does not copy similar
entries. An example below

list= ["apple", "banana", "grape"]
list2=["orange","banana", "pear"]

now I want to compare these lits and generate a third list after
comparison

list3 would be ["apple", "banana","grape","orange", "pear"]

hence the double entry would not show up?

Is there a way to do this??

Stephen

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


Re: List match

2006-08-17 Thread Richie Hindle

[Stephen]
> [...] compare 2 lists and generate a new list that does not copy similar
> entries. An example below
> 
> list= ["apple", "banana", "grape"]
> list2=["orange","banana", "pear"]
> 
> now I want to compare these lits and generate a third list after
> comparison
> 
> list3 would be ["apple", "banana","grape","orange", "pear"]

Use sets:

>>> from sets import Set as set  # For compatibility with Python 2.3
>>> one = ["apple", "banana", "grape"]
>>> two = ["orange","banana", "pear"]
>>> print list(set(one) | set(two))
['grape', 'apple', 'orange', 'pear', 'banana']

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


iTunes Search Algorithm/Data Structure?

2006-08-17 Thread Bill Mill
Hello all,

What data structure would you use to implement something analogous to
the iTunes search? I imagine that it must be a tree of some sort, but I
can't figure out an easy structure for it.

Requirements (in case you haven't used it):

You are given 4 rows in a list view:
[["alpha, "beta"], ["delta", "gamma"], ["foo", "bar"], ["etc", "etc"]]

and a search text box.

Typing "a" in the list box leaves rows 0, 1 and 2 in the list box,
because some element in each of those rows has an "a" in it. Typing
"am" leaves only row 1, since "gamma" has the substring "am" in it.

The key here is that this works instantaneously as you type, even with
very large lists with many elements per row. I'd like the employee list
in my current application to be similarly filtered, but I don't quite
see how.

Thoughts?

-Bill Mill
bill.mill at gmail.com
billmill.org

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


2.4.3, unittest and socket logging

2006-08-17 Thread Chris Curvey
Hi all,

I just upgraded to 2.4.3 (from 2.4.1) on Windows.  Now each time I run
my unit tests, they always throw this error at the end of the test run:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "c:\python24\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
  File "c:\python24\lib\logging\__init__.py", line 1333, in shutdown
h.close()
  File "c:\python24\lib\logging\handlers.py", line 448, in close
logging.Handler.close(self)
  File "c:\python24\lib\logging\__init__.py", line 674, in close
del _handlers[self]
KeyError: 

The classes that are being tested do use socket handlers for logging,
but I'm not sure if I should have been expecting this error, or what I
should be doing to make it stop.  (It's not critical, but it sure is
annoying.)

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


RELEASED Python 2.5 (release candidate 1)

2006-08-17 Thread Anthony Baxter
On behalf of the Python development team and the Python
community, I'm happy to announce the first RELEASE CANDIDATE
of Python 2.5.

This is not yet the final release - it is not suitable for
production use. It is being released to solicit feedback
and hopefully expose bugs, as well as allowing you to
determine how changes in 2.5 might impact you. As a release
candidate, this is one of your last chances to test the new
code in 2.5 before the final release. *Please* try this
release out and let us know about any problems you find.

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

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

As of this release, Python 2.5 is now in *feature freeze*.
Unless absolutely necessary, no functionality changes will
be made between now and the final release of Python 2.5.

The plan now is to let the release candidate shake out any
last-minute bugs in Python 2.5, leading to a 2.5 final
release in early September. PEP 356 includes the schedule
and will be updated as the schedule evolves. At this
point, any testing you can do would be greatly, greatly
appreciated.

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

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

New modules added include hashlib, ElementTree, sqlite3,
wsgiref, uuid and ctypes. In addition, a new profiling
module cProfile was added.

Enjoy this new release,
Anthony

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


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

Re: List match

2006-08-17 Thread [EMAIL PROTECTED]

OriginalBrownster wrote:
> Hi there:
>
> I know this probably is a very easy thing to do in python, but i wanted
> to compare 2 lists and generate a new list that does not copy similar
> entries. An example below
>
> list= ["apple", "banana", "grape"]
> list2=["orange","banana", "pear"]
>
> now I want to compare these lits and generate a third list after
> comparison
>
> list3 would be ["apple", "banana","grape","orange", "pear"]
>
> hence the double entry would not show up?
>
> Is there a way to do this??
>
> Stephen

How about:

list3 = list1 + [item for item in list2 if item not in list1]

print list3:

['apple', 'banana', 'grape', 'orange', 'pear']

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


Re: List match

2006-08-17 Thread [EMAIL PROTECTED]

OriginalBrownster wrote:
> Hi there:
>
> I know this probably is a very easy thing to do in python, but i wanted
> to compare 2 lists and generate a new list that does not copy similar
> entries. An example below
>
> list= ["apple", "banana", "grape"]
> list2=["orange","banana", "pear"]
>
> now I want to compare these lits and generate a third list after
> comparison
>
> list3 would be ["apple", "banana","grape","orange", "pear"]
>
> hence the double entry would not show up?
>
> Is there a way to do this??
>
> Stephen

How about:

list3 = list1 + [item for item in list2 if item not in list1]

print list3:

['apple', 'banana', 'grape', 'orange', 'pear']

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


py2exe and COM problem

2006-08-17 Thread Naytie
I seem to have a problem with a generated .exe file made with py2exe. I
wrote a python program that creates tables in a Word document and
adjusts the size of the tables and then inputs text into each cell
using COM. Everything works well and I do not get errors using Boa
constructor. However when I run the .exe file I get an error:

File ">", line 3, in SetWidth
pywintypes.com_error: (-2147352561, 'Parameter not optional.', None,
None)

which is a reference to

w.Selection.Tables(1).Columns(1).SetWidth(ColumnWidth=35)

w is an object created with win32 com

w = win32com.client.Dispatch('Word.Application')

I am assuming the 'Parameter not optional' may be saying that I cannot
change the width. This is the correct code that I took from VB. Can
anyone help? I am using Python 2.4 and MS Word 2000.

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


Re: The Semicolon Wars as a software industry and human condition

2006-08-17 Thread DJ Stunks
Xah Lee wrote:
> Of interest:
>
> · The Semicolon Wars, by Brian Hayes. 2006.
>  http://www.americanscientist.org/template/AssetDetail/assetid/51982
>
> in conjunction to this article, i recommend:
>
> · Software Needs Philosophers, by Steve Yegge, 2006
> http://xahlee.org/Periodic_dosage_dir/_p/software_phil.html
>
> · What Languages to Hate, Xah Lee, 2002
> http://xahlee.org/UnixResource_dir/writ/language_to_hate.html

speak of the devil...

-jp

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


Re: Read Picasa metadata using Python?

2006-08-17 Thread jay graves
Thomas W wrote:
> Anyway, if there are any other app allready reading Picasa metadata
> with Flickr-support that you know of that would save me alot of
> work/hassle. Still, Picasa is great, but I would really like access to
> my own metadata outside Picasa and I want to use python to do it.

I've looked at this in the past but I never got further than the
exploration stage.
I'm not at my home machine so this is from memory.
I found all of the data in XML format in the Application Data folder in
your personal directory.
(i.e. C:\Documents and Settings\jgraves\Application Data\Google\Picasa
(probably not exactly right))

Also there is a Google Groups for Picasa and it might have some
pointers in the archives.
http://groups.google.com/group/Picasa?lnk=gschg&hl=en

Have fun!

...
Jay Graves

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


Re: Printing n elements per line in a list

2006-08-17 Thread Neil Cerutti
On 2006-08-15, unexpected <[EMAIL PROTECTED]> wrote:
> If have a list from 1 to 100, what's the easiest, most elegant
> way to print them out, so that there are only n elements per
> line.
>
> So if n=5, the printed list would look like:
>
> 1 2 3 4 5
> 6 7 8 9 10
> 11 12 13 14 15
> etc.
>
> My search through the previous posts yields methods to print
> all the values of the list on a single line, but that's not
> what I want. I feel like there is an easy, pretty way to do
> this. I think it's possible to hack it up using while loops and
> some ugly slicing, but hopefully I'm missing something

I can't resist putting in my oar: 

def print_per(seq, n, isep=" ", rsep="\n"):
"""Print the items in seq, splitting into records of length n.

Trailing records may be shorter than length n."""
t = len(seq)
for i in xrange(n, t+1, n):
print isep.join(map(str, seq[i-n:i]))+rsep,
t = t % n
if t > 0:
print isep.join(map(str, seq[-t:]))+rsep,

That's probably similar to some of the other mostly
non-functional solutions posted.

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


Re: Adding a char inside path string

2006-08-17 Thread Grant Edwards
On 2006-08-17, Sybren Stuvel <[EMAIL PROTECTED]> wrote:
> Dennis Lee Bieber enlightened us with:
>>  What happens when you get a pathname that looks like:
>>
>> \\who\cares\common.exe\program.exe
>
> Is that possible on Windows?

Sure.  Why wouldn't it be?

> At one point, I named a directory "www.something.com" and then
> it wouldn't open, because it was an invalid .COM file...

Works fine for me.  I just created both directories and plain
text files named something.exe and www.something.com and both
worked fine under WinMe and WinXP.

-- 
Grant Edwards   grante Yow!  Well, I'm on the
  at   right planet---everyone
   visi.comlooks like me!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "wxmsw26uh_vc.dll not found" when using wxAgg backend

2006-08-17 Thread ajaksu
Hi Sam,

Sam wrote:
> I've installed matplotlib recently because I want to add graphing
> functionality to a GUI that i'm making.
Have you considered wxmpl? I'm leaning towards using it, " Painless
matplotlib embedding in wxPython" sounds good (and it even works). More
information and downloads at http://agni.phys.iit.edu/~kmcivor/wxmpl/

> - the following error box pops up: "This application has failed to
> start because wxmsw26uh_vc.dll was not found. Reinstalling the
> application may fix this problem."
Matplotlib mailing list should give you better answers on this, but
I'll try my best :)

I have wx-2.6-msw-ansi and my DLL is wxmsw26h_vc.dll, so it seems
wxmsw26Uh_vc.dll means the Unicode version. Matplotlib examples do work
here and including "# -*- coding: utf-8 -*-" in the demo source causes
no problem.

Have you ever installed a Unicode version of wxPython? The file wx.pth
in Lib/site-packages/ should point to your default wx version (a single
line with the directory name), does it? The configuration file
matplotlibrc (in Lib\site-packages\matplotlib\mpl-data\ and somewhere
in your profile) might have something weird causing this, worth a check
IMHO.

If these don't solve the problem, installing an older wxPython might
work around any version conflicts that could exist.

Hoping this helps,
Daniel

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


Re: The Semicolon Wars as a software industry and human condition

2006-08-17 Thread jmckitrick
What's more of a waste of time:

1.  The 30 minutes he took to write his vacuous essay.
2.  The 15 seconds it took to skim it and see nothing worth reading.
3.  The 30 seconds it took to write this post.

Tough call.

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


Re: How to delete a directory tree in FTP

2006-08-17 Thread T

That looks useful.  Thanks!

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


Re: List match

2006-08-17 Thread Richard Brodie

"OriginalBrownster" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> I know this probably is a very easy thing to do in python, but i wanted
> to compare 2 lists and generate a new list that does not copy similar
> entries. An example below
>
> list= ["apple", "banana", "grape"]
> list2=["orange","banana", "pear"]

Other people have already posted solutions but I'll add a couple of
comments:

1. Avoid calling lists 'list', you will break the list built-in function.

2. You don't specify whether the lists are ordered. If there is no
significance to the order of the items, it may be more appropriate
to use sets throughout. Then the answer is just: set3 = set1 | set2. 


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


1. Re: hide python code ! (enigmadude)

2006-08-17 Thread Ronny Abraham
Actually the reason you want to have one layer of encryption isn't to
prevent someone from understanding what you wrote, it's so that if some
company decides to "acquire" your code, they can't claim that you had
it in the public domain.

I think even the most pathetic encryption can serve this purpose.

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

Re: iTunes Search Algorithm/Data Structure?

2006-08-17 Thread Diez B. Roggisch
Bill Mill schrieb:
> Hello all,
> 
> What data structure would you use to implement something analogous to
> the iTunes search? I imagine that it must be a tree of some sort, but I
> can't figure out an easy structure for it.
> 
> Requirements (in case you haven't used it):
> 
> You are given 4 rows in a list view:
> [["alpha, "beta"], ["delta", "gamma"], ["foo", "bar"], ["etc", "etc"]]
> 
> and a search text box.
> 
> Typing "a" in the list box leaves rows 0, 1 and 2 in the list box,
> because some element in each of those rows has an "a" in it. Typing
> "am" leaves only row 1, since "gamma" has the substring "am" in it.
> 
> The key here is that this works instantaneously as you type, even with
> very large lists with many elements per row. I'd like the employee list
> in my current application to be similarly filtered, but I don't quite
> see how.
> 
> Thoughts?


Use an index. You can create one for each character, tuples of 
characters and so on that are contained in a word. That makes finding 
the entries a dict lookup + throwing the results together, filtering 
doubles.

I guess you can stop using indices at 3 or 4 characters, and then 
linearily search through the rest of the possibilities linearily.

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


Re: The Semicolon Wars as a software industry and human condition

2006-08-17 Thread Iain King

Xah Lee wrote:
> Of interest:
>
> • The Semicolon Wars, by Brian Hayes. 2006.
>  http://www.americanscientist.org/template/AssetDetail/assetid/51982
>
> in conjunction to this article, i recommend:
>
> • Software Needs Philosophers, by Steve Yegge, 2006
> http://xahlee.org/Periodic_dosage_dir/_p/software_phil.html
>
> • What Languages to Hate, Xah Lee, 2002
> http://xahlee.org/UnixResource_dir/writ/language_to_hate.html
>
>   Xah
>   [EMAIL PROTECTED]
> ∑ http://xahlee.org/

I'm confused - I thought Xah Lee loved Perl?  Now he's bashing it?
Huh?

Iain

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

Re: The Semicolon Wars as a software industry and human condition

2006-08-17 Thread J�rgen Exner
Iain King wrote:
> Xah Lee wrote:
>> Of interest:
>>
>> . The Semicolon Wars, by Brian Hayes. 2006.
>>  http://www.americanscientist.org/template/AssetDetail/assetid/51982
>>
>> in conjunction to this article, i recommend:
>>
>> . Software Needs Philosophers, by Steve Yegge, 2006
>> http://xahlee.org/Periodic_dosage_dir/_p/software_phil.html
>>
>> . What Languages to Hate, Xah Lee, 2002
>> http://xahlee.org/UnixResource_dir/writ/language_to_hate.html
>>
>>   Xah
>>   [EMAIL PROTECTED]
>> ? http://xahlee.org/
>
> I'm confused - I thought Xah Lee loved Perl?  Now he's bashing it?

He only loves himself.
Aside of that:


 +---+ .:\:\:/:/:.
 |   PLEASE DO NOT   |:.:\:\:/:/:.:
 |  FEED THE TROLLS  |   :=.' -   - '.=:
 |   |   '=(\ 9   9 /)='
 |   Thank you,  |  (  (_)  )
 |   Management  |  /`-vvv-'\
 +---+ / \
 |  |@@@  / /|,|\ \
 |  |@@@ /_//  /^\  \\_\
   @x@@x@|  | |/ WW(  (   )  )WW
   \/|  |\|   __\,,\ /,,/__
\||/ |  | |  jgs (__Y__)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==

jue


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


sqlite3 or mysqldb?

2006-08-17 Thread John Salerno
I did a little experimentation with MySQL, and yesterday I was reading 
up on SQLite. Since they both use the SQL language, does this mean that 
the queries you write will be the same for both modules? I'm sure there 
are slight differences for how you connect to DBs, but since they both 
use the same DB API 2.0, and both use SQL, I was wondering how easily 
you could 'switch' them out if you needed to go from one to the other.

(I know there are slight differences between the two in terms of SQL 
commands understood, but I'm mainly referring to the most important 
things, like simply accessing and changing DB information.)

I was using mysqldb just because MySQL seems to be a pretty big 
standard, but now that sqlite3 is coming with Python 2.5, I might 
switch, since it seems to be easier to use.

(And again, I'm such an amateur programmer that really I'm using these 
things just to learn them. It's not like I control my company's entire 
employee records or anything.)   :)

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


Python2.5 RC1 vs sgmlop.c

2006-08-17 Thread Robin Becker
I have a segfault problem in Python2.5 RC1 (win32) when using the venerable 
extension sgmlop.c.

In case that was just because our copy was very old I downloaded a later source 
from http://pyxml.cvs.sourceforge.net, but that code (version 1.14 loewis) 
still 
suffers from this problem.

The problem occurs after a call to free at line so I'm guessing something has 
changed related to allocations. Is there some magic going on which redefines 
malloc/realloc etc etc? I'm fairly sure the object in question (-->buffer) 
isn't 
passed directly to python so I would have thought that malloc/realloc/free were 
appropriate. Another parser attribute does hold an array of pointers to python 
objects, but again I don't think that should be a problem.

Has anyone got any clue what the problem might be or a fixed version of the 
code?
-- 
Robin Becker

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


Re: sqlite3 or mysqldb?

2006-08-17 Thread Paul Boddie
John Salerno wrote:
> I did a little experimentation with MySQL, and yesterday I was reading
> up on SQLite. Since they both use the SQL language, does this mean that
> the queries you write will be the same for both modules?

They should be, but database system producers tend to enjoy varying the
syntax for their own reasons.

> I'm sure there are slight differences for how you connect to DBs, but since 
> they both
> use the same DB API 2.0, and both use SQL, I was wondering how easily
> you could 'switch' them out if you needed to go from one to the other.

If you write using a conservative, standardised dialect of SQL, you
should be able to move between database systems without too many
difficulties. The first challenge, then, is to make sure you're aware
of what is standard and what the vendor has made up. Although MySQL 5.x
supports much more of the relevant standards than previous release
series, the manuals are very bad at telling you what they've made up
and what actually works on other systems. I therefore recommend that
you also consult other database system manuals, notably the PostgreSQL
manual which I have found to be more coherent.

> (I know there are slight differences between the two in terms of SQL
> commands understood, but I'm mainly referring to the most important
> things, like simply accessing and changing DB information.)

There's plenty of scope for writing non-standard SQL even in the most
common operations. Moreover, defining tables can be awkward because the
set of supported data types and the names used can vary in a seemingly
unnecessary fashion between systems.

> I was using mysqldb just because MySQL seems to be a pretty big
> standard, but now that sqlite3 is coming with Python 2.5, I might
> switch, since it seems to be easier to use.

You can consider MySQL a pseudostandard, but ignoring the actual SQL
standards will cause you difficulties if you decide you want to adopt a
different kind of database system later on. With respect to
portability, I've found sqlite3 and PostgreSQL to be surprisingly
compatible with regard to the SQL both database systems support, and I
can certainly recommend that combination wholeheartedly.

Paul

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


modify element of a list.

2006-08-17 Thread KraftDiner
Hi I have a list of Ojbects... I want to change one of the objects in
the list for a new object
How do I replace an existing object with a new one and maintain the
list order..

This is what I have...

def setAttribute(self, desc, value):
   n = anObject(desc, value)
   for o in self.Objects:
  if o.getDescription() == desc:
 self.Objects.replace(o, n) #Replace o with n?
 return
   self.Objects.append(n)

It's the replace in place that I don't know how to do...

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


Re: List match

2006-08-17 Thread Stargaming
Richie Hindle schrieb:
> [Stephen]
> 
>>[...] compare 2 lists and generate a new list that does not copy similar
>>entries. An example below
>>
>>list= ["apple", "banana", "grape"]
>>list2=["orange","banana", "pear"]
>>
>>now I want to compare these lits and generate a third list after
>>comparison
>>
>>list3 would be ["apple", "banana","grape","orange", "pear"]
> 
> 
> Use sets:
> 
> 
from sets import Set as set  # For compatibility with Python 2.3
one = ["apple", "banana", "grape"]
two = ["orange","banana", "pear"]
print list(set(one) | set(two))
> 
> ['grape', 'apple', 'orange', 'pear', 'banana']
> 

Why using Set two times, when you can do it with one call?

 >>> list(set(one + two))

According to my benchmarks, this was five times faster than calling it 
twice and use |.

There are also a few more good approaches uniquifying lists at 
http://www.peterbe.com/plog/uniqifiers-benchmark

Regards,
Stargaming

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


Re: Python2.5 RC1 vs sgmlop.c

2006-08-17 Thread Robin Becker
Robin Becker wrote:
> I have a segfault problem in Python2.5 RC1 (win32) when using the venerable 
> extension sgmlop.c.
..
> Has anyone got any clue what the problem might be or a fixed version of the 
> code?
I think this is PyObject_NEW mixed with PyMem_DEL, I thought that had already 
come in so wasn't looking hard enough.

-- 
Robin Becker

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


Re: Python2.5 RC1 vs sgmlop.c

2006-08-17 Thread Steve Holden
Robin Becker wrote:
> I have a segfault problem in Python2.5 RC1 (win32) when using the venerable 
> extension sgmlop.c.
> 
> In case that was just because our copy was very old I downloaded a later 
> source 
> from http://pyxml.cvs.sourceforge.net, but that code (version 1.14 loewis) 
> still 
> suffers from this problem.
> 
> The problem occurs after a call to free at line so I'm guessing something has 
> changed related to allocations. Is there some magic going on which redefines 
> malloc/realloc etc etc? I'm fairly sure the object in question (-->buffer) 
> isn't 
> passed directly to python so I would have thought that malloc/realloc/free 
> were 
> appropriate. Another parser attribute does hold an array of pointers to 
> python 
> objects, but again I don't think that should be a problem.
> 
> Has anyone got any clue what the problem might be or a fixed version of the 
> code?

I'm guessing this might be to do with the changes that have been made to 
enable 64-bit readiness in the code, but I couldn't suggest specifics.

Suspect all pointers and integers first :-)

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

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


Re: The Semicolon Wars as a software industry and human condition

2006-08-17 Thread Ken Tilton


Xah Lee wrote:

> 
> • What Languages to Hate, Xah Lee, 2002
> http://xahlee.org/UnixResource_dir/writ/language_to_hate.html

Nonsense. This is technology, not religion. Technologists in fact have a 
responsibility to identify and use the best tools available.

Xah, you are getting soft in your old age. :)

hth, kenny

-- 
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: modify element of a list.

2006-08-17 Thread Pierre Quentel
Hi,

The most simple is to use the index of the element in the list :

def setAttribute(self, desc, value):
   n = anObject(desc, value)
   for i,o in enumerate(self.Objects):
  if o.getDescription() == desc:
 self.Objects[i] = n
 return 
   self.Objects.append(n)

Pierre

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


Re: Python2.5 RC1 vs sgmlop.c

2006-08-17 Thread Robin Becker
Steve Holden wrote:
> Robin Becker wrote:
...
>> Has anyone got any clue what the problem might be or a fixed version of the 
>> code?
> 
> I'm guessing this might be to do with the changes that have been made to 
> enable 64-bit readiness in the code, but I couldn't suggest specifics.
> 
> Suspect all pointers and integers first :-)
.
Indeed Steve, but it was in fact PyMem_DEL vs PyObject_NEW. Just replaced three 
PyMem_DEL's with PyObject_FREE and things now work again. The free I suspected 
wasn't involved at all.
-- 
Robin Becker

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


Re: modify element of a list.

2006-08-17 Thread Steve Holden
KraftDiner wrote:
> Hi I have a list of Ojbects... I want to change one of the objects in
> the list for a new object
> How do I replace an existing object with a new one and maintain the
> list order..
> 
> This is what I have...
> 
> def setAttribute(self, desc, value):
>n = anObject(desc, value)
>for o in self.Objects:
>   if o.getDescription() == desc:
>  self.Objects.replace(o, n) #Replace o with n?
>  return
>self.Objects.append(n)
> 
> It's the replace in place that I don't know how to do...
> 
There are a number of ways. I suspect the simplest would be (untested):

def setAttribute(self, desc, value):
 n = anObject(desc, value)
 for i, o in enumerate(self.Objects):
 if o.getDescription() == desc:
 self.Objects[i] = n
 return
 self.Objects.append(n)

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

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


Re: Curried class methods?

2006-08-17 Thread Carl Banks
Scott Lamb wrote:
> I'm trying to dynamically generate class methods which have access to
> some state passed in at creation time. (Basically as a workaround to
> twisted's trial not having a way to dynamically add stuff. Plain
> unittest seems to have TestSuite, but the trial runner doesn't know
> about it.)
>
> My first attempt might better illustrate this -
>
> class Foo:
> def generalized(self, ctx):
> print 'my ctx is %r' % ctx
>
> for i in ['a','b','c']:
> setattr(Foo, i, lambda self: self.generalized(i))
>
> foo = Foo()
> foo.a()
> foo.b()
> foo.c()
>
> but this prints "my ctx is c" three times; I'd hoped for a, b, c, of
> course.

def build(j):
   setattr(Foo, j, lambda self: self.generalized(j))
for i in ["a","b","c"]:
   build(i)

Each call of the the build function creates its own cell "j" that the
lambda references.


Carl Banks

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


Re: Python2.5 RC1 vs sgmlop.c

2006-08-17 Thread skip

Robin> Just replaced three PyMem_DEL's with PyObject_FREE and things now
Robin> work again.

Can you send me a patch?

Thx,

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


Re: Looking For mp3 ID Tag Module

2006-08-17 Thread Tim Daneliuk
Iñigo Serna wrote:
> Hi Tim,
> 
> try mutagen. http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen
> 
> Regards,
> Iñigo

Many thanks - this looks promising...

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe and COM problem

2006-08-17 Thread Naytie
I figured it out. I can change the table column by selecting it through
the table, e.g.

column = table.Columns(1)

column.Width = 150

etc etc

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


Python for arcgis

2006-08-17 Thread subramanian2003

Hello All,

  From where can I get the python tutorial for arcgis customisation?.

Bye,
Subramanian.
Sign Up for your FREE eWallet at www.wallet365.com

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


where can i get older version of python?

2006-08-17 Thread chppatel
does any one know where can I get older version of python for windows?

I am looking for versions between 2.0 and 2.2.

thanks for your help

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


Re: where can i get older version of python?

2006-08-17 Thread beliavsky

[EMAIL PROTECTED] wrote:
> does any one know where can I get older version of python for windows?
>
> I am looking for versions between 2.0 and 2.2.

http://www.python.org/download/releases/

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


Re: where can i get older version of python?

2006-08-17 Thread calchp

[EMAIL PROTECTED] wrote:
> does any one know where can I get older version of python for windows?
>
> I am looking for versions between 2.0 and 2.2.
>
> thanks for your help

This site might be useful http://www.oldapps.com/Python.php

http://www.oldapps.com/

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


Re: Python2.5 RC1 vs sgmlop.c

2006-08-17 Thread Robin Becker
[EMAIL PROTECTED] wrote:
> Robin> Just replaced three PyMem_DEL's with PyObject_FREE and things now
> Robin> work again.
> 
> Can you send me a patch?
> 
> Thx,
> 
> Skip
On its way
-- 
Robin Becker

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


Re: OT: p-gal website

2006-08-17 Thread John Bokma
"ajaksu" <[EMAIL PROTECTED]> wrote:

> And to answer your question, I recommend to follow standards because
> that's how I call the mixed bag of Recommendations, some of which are
> also Specifications, allowing for the inclusion of both significant
> Standards and standards. I guess I must've been bitten by the buzzword
> bug, sorry it that offends you. But I'm not the only one (TM).

True, but if one follows a document, shouldn't one name it according to 
how it's named in the document itself? To me, the answer is yes. 
Especially if people start to claim that "ISO HTML" and HTML 4.01 are 
identical standards.

A lot of people call Python, Perl, etc. *just* scripting languages, not 
real programming languages (whatever that may be). Should we join their 
ranks or educate?

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


Re: trouble understanding inheritance...

2006-08-17 Thread Jason
KraftDiner wrote:
> c = [a, b]
> for c in [a,b]:
>c.getName()
>
> but when does baseClass ever get used?
> Why did i even have to define it?
>

One reason for using base classes are for logical reasons.  Oranges and
Apples are different, but they are both fruits.  Python has both
unicode strings and 8-bit ASCII strings.  Both are strings and share a
common base class: the 'basestring' class.

A second reason is for code sharing.  Let's say Python's string class
does everything you want already... except for one little thing.  You
want the split method to return a list with some extra information.
Why re-invent the wheel trying to implement the other string methods
when you can reuse everything that's already been done?

>>> class MyString(str):
...   def split(self):
... "Perform some extra work this version of split"
... wordList = str.split(self)  # Call the original method
... return ['Extra'] + wordList + ['Information']  # Do additional
work!
...
>>>

In Python, we often rely on duck typing.  "If it looks like a duck,
quacks like a duck, it's a duck."  If we can treat it like a string, we
can consider it a string.  If we can't treat it like a string, Python
will let us know by raising an exception.  We can catch this exception
and try something different, or let the exception stop the program and
let the user know something went wrong.

Duck typing allows us to re-use code very efficiently.  I'll
demonstrate it with a function and the class defined above.

>>> def GetWords(stringValue):
...   "Print the list of words in a string"
...   print 'Words are: %s' % stringValue.split()
...
>>> stringValue = str('Hello, world!')
>>> unicodeValue = unicode('These are different strings')
>>> myStringValue = MyString('good, hopefully useful')
>>>
>>> GetWords(stringValue)
Words are: ['Hello,', 'world!']
>>> GetWords(unicodeValue)
Words are: [u'These', u'are', u'different', u'strings']
>>> GetWords(myStringValue)
Words are: ['Extra', 'good,', 'hopefully', 'useful', 'Information']
>>>

As shown above, the GetWords() function works fine with my new string
class.  Any methods that I didn't redefine keep their old behavior.
For example, I didn't define the upper() method in MyString, but I can
still use it:

>>> stringValue.upper()
'HELLO, WORLD!'
>>> myStringValue.upper()
'GOOD, HOPEFULLY USEFUL'
>>>

While we rely on duck typing in Python, we occassionally want special
behavior for certain types of data.  Currently, you can pass anything
into the GetWords() function that has a method named 'split'.  It does
not have to be a string:

>>> class NotAString(object):
...   def split(self):
... return 'I am not a string!'
...
>>> otherDataValue = NotAString()
>>> GetWords(otherDataValue)
Words are: I am not a string!
>>>

Sometimes, we want some specialized behavior.  Lists, tuples, and
strings all act like sequences (meaning, you can get their length and
use them in for-loops).  Often, though, you'll want to treat strings
differently.  You can check the type directly, or you can check by
using the isinstance() built-in function.  isinstance() checks to see
if a variable is an instance of a class or any of its subclasses.

Remember the first reason given, of using a base class to logically
organize other classes?  This is it in practice.  I'll demonstrate
below:

>>> def CheckOnlyBuiltinStrings(stringValue):
...   "Tells us whether or not stringValue is a str or unicode string."
...   if type(stringValue) is str  or  type(stringValue) is unicode:
... print 'A built-in string type: %s' % stringValue
...   else:
... print 'Not a built-in string type: %s' % stringValue
...
>>> def CheckAllStrings(stringValue):
...   "Tells us whether or not stringValue is a string."
...   # The basestring class is a superclass for all string classes.
...   if isinstance(stringValue, basestring):
... print 'Is a string: %s' % stringValue
...   else:
... print 'Not a string: %s' % stringValue
...
>>> CheckOnlyBuiltinStrings(stringValue)
A built-in string type: Hello, world!
>>> CheckOnlyBuiltinStrings(unicodeValue)
A built-in string type: These are different strings
>>> CheckOnlyBuiltinStrings(myStringValue)
Not a built-in string type: good, hopefully useful
>>>
>>> CheckAllStrings(stringValue)
Is a string: Hello, world!
>>> CheckAllStrings(unicodeValue)
Is a string: These are different strings
>>> CheckAllStrings(myStringValue)
Is a string: good, hopefully useful
>>> CheckAllStrings(42)
Not a string: 42
>>>

How do you know when you should use type() checks, when you should use
isinstance(), and when you should just try to use the data?  That
depends, and there have been many lively debates on this subject in the
newsgroup.  I recommend that you should only use as much type checking
as needed, and the less is better.

A bit long, but I hope this helps you out.

--Jason

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


Subprocess confusion: how file-like must stdin be?

2006-08-17 Thread Cameron Laird
Question:
  import subprocess, StringIO

  input = StringIO.StringIO("abcdefgh\nabc\n")
  # I don't know of a compact, evocative, and
  # cross-platform way to exhibit this behavior.
  # For now, depend on cat(1).
  p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, 
stdin = response)

Why this is a question:
A.  it tosses an AttributeError.
B.  I *expected* it to do the equivalent of
  cat << HERE 
  abcdefgh
  abc
  HERE

In http://docs.python.org/dev/lib/node530.html >, I read "Valid
values are ... an existing file object ..."  Even though StringIO is
a "file-like object", it lacks a fileno.  Is there a way to get what
I'm after?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PySequence_SetItem

2006-08-17 Thread Jack Diederich
On Thu, Aug 17, 2006 at 02:35:11PM +0200, Fredrik Lundh wrote:
> John Machin wrote:
> 
> > 1. It's also documented as being the recommended way of filling up a
> > list after PyList_New.
> 
> since it doesn't work in any existing Python release, it's hardly 
> "recommended".
> 
> the Python documentation has never been formally binding; if the documentation
> doesn't match the code, it's usually the documentation that's flawed.
> 
> > 2. So you'd rather not change the code, and just let it segfault if
> > someone calls it (or PyObject_SetItem) instead of PyList_SetItem?
> 
> as I said, you're using an API that's designed for use on *properly 
> initialized*
> objects on an object that *hasn't been initialized*.  if you're going to 
> patch all
> places where that can happen, you might as well rewrite the entire 
> interpreter.
> 
> the documentation is broken, and *must* be fixed.  catching this specific case
> in the code is a lot less important; it's just one of many possible errors 
> you can
> make when writing C-level code.  there's simply no way you can catch them
> all.
> 
This was my initial reaction and I'll reluctantly go back to it.  The docs
describe a bad practice - no one ever uses an abstract API to initialize the
concrete type they just created.  For bonus points the example would have always
segfaulted (at least back to 2.2, I didn't check 1.5).

While it feels uneven that other types can't get this kind of segfault the
fact that no one else has ever run accross it makes the point moot.

Unrelated, it looks like PySequence_* doesn't have much reason to live now
that iterators are everywhere.  In the core it mainly used to do the equiv of

def listize(ob):
  if (type(ob) in (list, tuple)):
return ob
  else:
return list(iter(ob))

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


Re: hide python code !

2006-08-17 Thread danielx
Steven D'Aprano wrote:
> On Wed, 16 Aug 2006 13:39:10 -0700, danielx wrote:
>
> > Steven D'Aprano wrote:
> >> On Tue, 15 Aug 2006 09:00:16 -0700, Ben Sizer wrote:
> >>
> >> > Yes, in much the same way that there is no point ever locking your
> >> > doors or installing burglar alarms, as a determined thief will
> >> > eventually steal your belongings.
> >>
> >> That's an utterly pointless and foolish analogy.
> >>
> >> (1) If a thief breaks into your house and steals your TV, you no longer
> >> have a TV. If a developer sees your code, you still have your code, *even
> >> if they subsequently copy it*. You haven't lost your code, it is just no
> >> longer secret. Since secrecy is rarely valuable in and of itself, you've
> >> lost nothing.
> >
> > But haven't you lost your control over the code? If you were trying to
> > sell a program (regardless of whether this is a good way to make money
> > from it), hasn't your ability to do so been undercut? This is the loss.
>
> Maybe so. And if a competitor creates a better product than yours, hasn't
> your ability to sell your program been undercut too?

Creating a better product is a legitimate activity (that's what the
market system is trying to promot after all (not saying the market
system is right, but it is relevant since many people believe in it)).
The whole question is whether copying your code is legitimate. Drawing
an analogy from art and clearly patent-able products, it seems software
might fall into the same category of protectable products. Again, this
is the question at hand.

>
> Either scenario has NOTHING to do with thieves breaking into your house
> and locks on doors. The analogy is bogus. Undercutting your ability to
> sell a product is not theft, and compiling source code to machine code is
> not analogous to a lock on the door.
>
>
> >> Yes, I've heard all the stories about "valuable algorithms" and the like.
> >> Some of them might even be true. But for 99+% of code, spending even one
> >> cent to keep it secret is just wasting money.
> >
> > That may be true, but for someone who has determined that the hiding
> > the code would be best, it would seem to be quite a good investment.
>
> Whether it "seems" to be a good investment is quite different from whether
> it *is* a good investment.
>
> If they ask me for advice, I'll tell them that they're almost certainly
> wasting their time, that their algorithm almost certainly isn't as
> valuable as they think, and that if they disagree, well, Python supports

So it's your opinion against the author's, no? And the decision is up
to the author, and not you, no?

> .pyc files, there are tools like py2exe which will put their Python code
> inside an exe file, there is a Python obfuscator, and a few other tricks.
> If none of those things are good enough for them, then Python is not the
> language they want to be using.

That seems good, but you also seem to have something against the whole
idea of stronger protections for Python. I don't think loose
protections has to be an inherent feature of Python.

>
> As for the rest of your post, it is mostly irrelevant. However, I will
> answer one last point:
>
> [snip]
>
> > Even if we don't take the "twice" figure literally, I imagine
> > that most of us would agree that the amount that the bar can be raise
> > is considerable and not insignificant.
>
> I dispute that "most of us" agree that the bar can be raised a
> considerable amount. It is my position that in the real world, as opposed
> to the fantasies of amateur programmers, compiling code is virtually NO
> BARRIER to your competitors understanding your algorithm.

Anyone willing to take a good survey? Until then, I think we can just
disagree over that point.

>
> Perhaps you would like to consider how it is that black-hat hackers and
> virus writers can analyse Microsoft Windows for vulnerabilities and
> security holes *without access to the source code*?

Yes, but wouldn't it be much easier for those vulnerabilities to be
discovered if the code were released? Black-hats also have to advantage
that MS announces vulnerabilities for them, which they take advantage
of during the period where people are patching their windows.

>
> (And by the way: your suggestion that Microsoft has very few workers is
> wrong. Microsoft has approximately 60,000 employees, and that almost
> certainly doesn't include the many sub-contractors they hire.
> http://www.networkworld.com/news/financial/microsoft.html )

I'd say that's not a large number (I was more or less aware that ms has
ten's of thousands of emploees), but obviously you'd disagree with
that...

> 
> 
> 
> -- 
> Steven D'Aprano

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


New to python

2006-08-17 Thread Gallagher, Tim (NE)
Hello all, 
I am new to python and I have a few questions.  I am an old Perl hacker
been using Perl for many years.  I wanted to give python a try, I am
happy with it so far.  
Question:
1. Is there a repository that I can go to for modules? Perl has CPAN and
I was wondering what the Python equivalent was.

I guess that I had a few more that I cannot think of right now.

Thanks

Tim


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


Dynamic objects

2006-08-17 Thread Mark Shewfelt
Hello,

I have implemented a series of classes representing a Building, its
respective Equipment, and then various Components of that equipment
like so (as you'll be able to tell, I'm a newbie):

class Building:
 equipment = {}
 def AddEquipment( name, data ):
  equipment[ name ] = Equipment( data )

class Equipment:
 components = {}
 def AddComponent( name, data ):
   components[ name ] = Component( data )

class Component:
 data = ""

These classes are used like so:

test = Building()
test.AddEquipment( "equipment 1", data )
test.AddEquipment( "equipment 2", data )
test.equipment["equipment 1"].AddComponent( "component 1", data )
test.equipment["equipment 1"].AddComponent( "component 2", data )
test.equipment["equipment 2"].AddComponent( "component 3", data )

But it appears as though the instance of "equipment 1" has ALL of the
components in its components dictionary. I was hoping that the
test.equipment["equipment 1"].components dictionary would only have
those components that were assigned to "equipment 1".

I have implemented __init__  functions for all of the classes, but all
they do is initialize some data that I haven't shown here.

I think I'm trying to use a C++ way of doing this (without the new
operator) so if anyone would be so kind as to help with the Python way
of doing this sort of thing I will be eternally grateful.

Cheers,

Mark Shewfelt

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


Re: RELEASED Python 2.5 (release candidate 1)

2006-08-17 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: ANN: Pybots -- Python Community Buildbots

2006-08-17 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: New to python

2006-08-17 Thread Gabe

Gallagher, Tim (NE) wrote:
> 1. Is there a repository that I can go to for modules? Perl has CPAN and
> I was wondering what the Python equivalent was.

You can try the CheeseShop.  You can locate it here:
http://cheeseshop.python.org/pypi.  Also, you might want to look into
the new .egg format for downloading modules (it's like 'gem' from ruby,
if you're familiar with that.)

Good Luck,
Gabe

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


Re: Dynamic objects

2006-08-17 Thread Tim


Mark Shewfelt wrote:
> Hello,
>
> I have implemented a series of classes representing a Building, its
> respective Equipment, and then various Components of that equipment
> like so (as you'll be able to tell, I'm a newbie):
>
> class Building:
>  equipment = {}
>  def AddEquipment( name, data ):
>   equipment[ name ] = Equipment( data )
>
> class Equipment:
>  components = {}
>  def AddComponent( name, data ):
>components[ name ] = Component( data )
>
> class Component:
>  data = ""
>
> These classes are used like so:
>
> test = Building()
> test.AddEquipment( "equipment 1", data )
> test.AddEquipment( "equipment 2", data )
> test.equipment["equipment 1"].AddComponent( "component 1", data )
> test.equipment["equipment 1"].AddComponent( "component 2", data )
> test.equipment["equipment 2"].AddComponent( "component 3", data )
>
> But it appears as though the instance of "equipment 1" has ALL of the
> components in its components dictionary. I was hoping that the
> test.equipment["equipment 1"].components dictionary would only have
> those components that were assigned to "equipment 1".
>
> I have implemented __init__  functions for all of the classes, but all
> they do is initialize some data that I haven't shown here.
>
> I think I'm trying to use a C++ way of doing this (without the new
> operator) so if anyone would be so kind as to help with the Python way
> of doing this sort of thing I will be eternally grateful.
>
> Cheers,
>
> Mark Shewfelt
>
>   
I don't see how your examples could work, helps if you post the actual code.
Try these classes, I think they accomplish what your trying to do.

class Building:
def __init__(self, data = ''):
self.data = data
self.equipment = {}
def AddEquipment(self, name, data ):
self.equipment[ name ] = Equipment( data )

class Equipment:
def __init__(self, data = ''):
self.data = data
self.components = {}
def AddComponent(self, name, data ):
self.components[ name ] = Component( data )

class Component:
def __init__(self, data):
self.data = data

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


Re: hide python code !

2006-08-17 Thread danielx

Paul Boddie wrote:
> danielx wrote:
> >
> > But we have only considered the economics of such a decision. Even if
> > there is no market value to a work, a person has an understandable
> > desire to exercise the rights of ownership over a work, given the
> > amount of personal investment one makes in producing it.
>
> There are other motivations, too. An author might wish that their work
> convey a particular message and that others should not be able to make
> derived works which distort or contradict that message. However, there
> are various established principles of fair use which limit the author's
> control over such derived works.
>
> [...]
>
> > I think the above idea is frequently missed in discussions about
> > copyrights/patents in the open source world. There, the focus seems to
> > be on the marketability granted by protections (legal or physical). The
> > post I am responding to illustrates this focus. Do we believe an author
> > forfeits ownership of a work merely by sharing it? As a matter of
> > conscience, I don't believe the answer can be imposed on anyone. Every
> > person must answer this for him or herself.
>
> As we've mentioned above, one crucial issue is control over published
> works and over the potentially related works of others. With software,
> such control is mediated by the licence which is often prominent, even
> unavoidable when using proprietary software; thus, people using or
> distributing software should be aware of the licence which applies to
> the work. In contrast, works in areas such as popular music are not

While I agree with most of your post, I think the point should be made
that eula's don't hold up very well in US courts:

http://en.wikipedia.org/wiki/EULA#Enforceability

> prominently "labelled" with licensing information if you're listening
> to that music playing on the radio, television, in a public space, and
> so on. This apparent "promiscuity" with such works leads people to
> believe that they are freely exchangeable and that the author is not
> exercising control, even if that isn't really the case due to the
> framework established by the recording industry for broadcasters.
>
> So, people perceive an apparent lack of control as some kind of lack of
> ownership, that the work has, by being shared in an apparently

Extremely interesting point! This should really motivate people to
answer the question I posed earlier: Does an author of software forfeit
his rights to the code if he shares his program (ie, reliquishes
_complete_ protection over the code)?

Let's say this happens: I want to sell some software, but I'm affraid
people will just copy it. So I prototype it in Python (or whatever
programming language) and never release the program. Based on that, I
design a chip (I know this is nearly impossible, but we are doing a
mental experiment), which does exactly the same thing.

First of all, the chip can be reverse engineered (of course, with MUCH
greater difficulty than the equivalent code). Should I still be worried
that my invention will be copied?

A second point to consider: The chip is patentable (I think this is the
case legally, as well as in the court of public opinion), so what about
the equivalent code?

> unconditional way, become part of their common culture - a sentiment or
> an understanding that can presumably be traced back throughout the
> history of human culture itself. At the opposite end of the spectrum of
> control, when mechanisms of control are used to restrict the
> distribution of derived works or the production of coincidentally
> related works, is it unfair that people wish to disregard such
> apparently counter-intuitive mechanisms? An interesting example in
> popular culture was the legal argument about whether silence
> constitutes an original work
> (http://news.bbc.co.uk/1/hi/entertainment/music/2133426.stm), but
> things like patents affect the ability of others to create works in a
> fashion that can be much harder to predict.
> 
> Paul

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


Re: Dynamic objects

2006-08-17 Thread Mark Shewfelt
Thanks a lot Tim!

My __init__ functions didn't set the dictionaries like you did below
(e.g. self.equipment = {} ).

Newbie mistake - won't make that one again.

Thanks again,

Mark


Tim wrote:
> Mark Shewfelt wrote:
> > Hello,
> >
> > I have implemented a series of classes representing a Building, its
> > respective Equipment, and then various Components of that equipment
> > like so (as you'll be able to tell, I'm a newbie):
> >
> > class Building:
> >  equipment = {}
> >  def AddEquipment( name, data ):
> >   equipment[ name ] = Equipment( data )
> >
> > class Equipment:
> >  components = {}
> >  def AddComponent( name, data ):
> >components[ name ] = Component( data )
> >
> > class Component:
> >  data = ""
> >
> > These classes are used like so:
> >
> > test = Building()
> > test.AddEquipment( "equipment 1", data )
> > test.AddEquipment( "equipment 2", data )
> > test.equipment["equipment 1"].AddComponent( "component 1", data )
> > test.equipment["equipment 1"].AddComponent( "component 2", data )
> > test.equipment["equipment 2"].AddComponent( "component 3", data )
> >
> > But it appears as though the instance of "equipment 1" has ALL of the
> > components in its components dictionary. I was hoping that the
> > test.equipment["equipment 1"].components dictionary would only have
> > those components that were assigned to "equipment 1".
> >
> > I have implemented __init__  functions for all of the classes, but all
> > they do is initialize some data that I haven't shown here.
> >
> > I think I'm trying to use a C++ way of doing this (without the new
> > operator) so if anyone would be so kind as to help with the Python way
> > of doing this sort of thing I will be eternally grateful.
> >
> > Cheers,
> >
> > Mark Shewfelt
> >
> >
> I don't see how your examples could work, helps if you post the actual code.
> Try these classes, I think they accomplish what your trying to do.
>
> class Building:
> def __init__(self, data = ''):
> self.data = data
> self.equipment = {}
> def AddEquipment(self, name, data ):
> self.equipment[ name ] = Equipment( data )
>
> class Equipment:
> def __init__(self, data = ''):
> self.data = data
> self.components = {}
> def AddComponent(self, name, data ):
> self.components[ name ] = Component( data )
>
> class Component:
> def __init__(self, data):
> self.data = data

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


Py2Exe and sys.argv : The Lost Arguments

2006-08-17 Thread Thomas W
I've created a simple script like so :

import sys
import wx

app = wx.PySimpleApp()
dlg = wx.MessageDialog(None, "%s" % sys.argv, 'A Message Box',
wx.YES_NO | wx.ICON_QUESTION)
retCode = dlg.ShowModal()
app.MainLoop()

If I run this on the command line like
python testcmd.py /somefile.ext /anotherfile.ext

it displays a messagebox with a stringformatted list containing
testcmd.py, somefile.ext and anotherfile.ext.

Then I "compile" the script using py2exe, generate a file called
testcmd.exe and select the same two files in Explorer, right click,
"Open with ...", browse to testcmd.exe and proceed. Now the dialogbox
only shows two items in the list; testcmd.exe and one of the files I
selected. Why?

Is it impossible to compile a script using py2exe and pass selected
items in Explorer to my script? It works fine when called on the
command line so it might be something related to Explorer but I'm
completly lost.

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


Re: Dynamic objects

2006-08-17 Thread Larry Bates
Mark Shewfelt wrote:
> Hello,
> 
> I have implemented a series of classes representing a Building, its
> respective Equipment, and then various Components of that equipment
> like so (as you'll be able to tell, I'm a newbie):
> 
> class Building:
>  equipment = {}
>  def AddEquipment( name, data ):
>   equipment[ name ] = Equipment( data )
> 
> class Equipment:
>  components = {}
>  def AddComponent( name, data ):
>components[ name ] = Component( data )
> 
> class Component:
>  data = ""
> 
> These classes are used like so:
> 
> test = Building()
> test.AddEquipment( "equipment 1", data )
> test.AddEquipment( "equipment 2", data )
> test.equipment["equipment 1"].AddComponent( "component 1", data )
> test.equipment["equipment 1"].AddComponent( "component 2", data )
> test.equipment["equipment 2"].AddComponent( "component 3", data )
> 
> But it appears as though the instance of "equipment 1" has ALL of the
> components in its components dictionary. I was hoping that the
> test.equipment["equipment 1"].components dictionary would only have
> those components that were assigned to "equipment 1".
> 
> I have implemented __init__  functions for all of the classes, but all
> they do is initialize some data that I haven't shown here.
> 
> I think I'm trying to use a C++ way of doing this (without the new
> operator) so if anyone would be so kind as to help with the Python way
> of doing this sort of thing I will be eternally grateful.
> 
> Cheers,
> 
> Mark Shewfelt
> 
With the way you defined Building multiple buildings would share
equipment dictionary as it is defined as a class variable and you
want an instance variable (I'm pretty sure).  You probably wanted
(not tested):

class Building:
def __init__(self):
self.equipment = {}

def AddEquipment(name, data):
equipment[name]=Equipment(data)

same for Equipment class and Component class.

class Equipment:
def __init__(self):
self.components={}

def AddComponent(name, data):
components[name]=Component(data)


class Component:
def __init__(self, data)
self.data=data


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


Re: sqlite3 or mysqldb?

2006-08-17 Thread andychambers2002
> I was using mysqldb just because MySQL seems to be a pretty big
> standard, but now that sqlite3 is coming with Python 2.5, I might
> switch, since it seems to be easier to use.

Yes and No.  Sqlite takes less to configure and manage but you have to
consider your needs for concurrent processing.  If memory/disk space is
no object then I would stick to mysql.

If its learning SQL that you want, you should try postgres.  It has a
very
interesting "RULE" system that you can play with.

Regards,
Andy

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


CGI script running not completely in HTML

2006-08-17 Thread Yong Wang
Hi, All:
I have written a python CGI script to run in html web page. When I access to
the html page, it only runs part of the script, then abort because the late 
part of
the script is involved in database access, it is slow. I wonder whether there 
is 
a way to control html running speed so that it can wait for CGI script to 
complete
execution, then write the results to html page ? 
Thanks a lot .

  Yong

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


FrontPage COM Object Model

2006-08-17 Thread iman gowhari
I want to get frontpage web and page object models with this code.
OnPageNew works properly but when I click on the page nothing happen.

from win32com.client import DispatchWithEvents
import time, pythoncom, msvcrt

class FrontPageEvents:
def __init__(self):
print 'FrontPageEvents'
def OnPageNew(self, page):
DispatchWithEvents(f.ActiveDocument, PageEvents)

class PageEvents:
def __init__(self):
print 'PageEvents'
def onclick(self):
print 'onclick'

f=DispatchWithEvents("FrontPage.Application", FrontPageEvents)
while not msvcrt.kbhit():
pythoncom.PumpWaitingMessages()
time.sleep(.2)
msvcrt.getch()

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


Re: CGI script running not completely in HTML

2006-08-17 Thread Christoph Haas
On Thursday 17 August 2006 21:50, Yong Wang wrote:
> I have written a python CGI script to run in html web page. When I
> access to the html page, it only runs part of the script, then abort
> because the late part of the script is involved in database access, it
> is slow. I wonder whether there is a way to control html running speed
> so that it can wait for CGI script to complete execution, then write the
> results to html page ?

You could use

 output = ''
 output += 'Something else to print'

instead of

 print 'Something else to print'

And finally use

 print output

Or to use that more efficiently use a list of strings and append to that 
list. That's probably faster than creating another immutable string time 
and again. And finally you just ' '.join(outputlist) and print that.

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


Problem installing Python 2.4.3 on FreeBSD 5.3-RELEASE-p31

2006-08-17 Thread james
I have a problem installing Pyhton 2.4.3, running "./configure
--with-threads=no" completes, but gives the warning:

configure: WARNING: curses.h: present but cannot be compiled
configure: WARNING: curses.h: check for missing prerequisite
headers?
configure: WARNING: curses.h: see the Autoconf documentation
configure: WARNING: curses.h: section "Present But Cannot Be
Compiled"
configure: WARNING: curses.h: proceeding with the preprocessor's result
configure: WARNING: curses.h: in the future, the compiler will take
precedence

Running "make" then gives the error:

gcc -shared build/temp.freebsd-5.3-RELEASE-p31-i386-2.4/_cursesmodule.o
-L/usr/local/lib -lncursesw -o
build/lib.freebsd-5.3-RELEASE-p31-i386-2.4/_curses.so
Segmentation fault (core dumped)
*** Error code 139

I assume this is related to the configure warning... ?  Same error with
just a standard "./configure" and "make".

Any help would be great :)

Regards,
James

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


Re: Defining our own types?

2006-08-17 Thread tobiah
> suppose I type:
> ip = 123.45.67.89

This is probably far from what you want,
but I would do something like this:


class ip(list):

def __init__(self, ip):

bytes = ip.split('.')
for x in range(4):
self.append(bytes[x])

def __repr__(self):

return '.'.join(self)


localhost = ip('192.168.1.1')

print localhost
print localhost[2]
***
192.168.1.1
1

That way at least you can get at the value
in both of the meaningful ways, and you can
probably think of more methods, like applying
netmasks, etc...


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


Re: trouble understanding inheritance...

2006-08-17 Thread Ant
Try running the following example - it should help clear up what is
going on:

class Base:
def __init__(self):
print "Initializing base"
def shouldBeImplemented(self):
raise NotImplementedError
def hasDefaultImplementation(self):
print "Wey Hey!"

class A(Base):
def shouldBeImplemented(self):
print "Has been implemented!"

class B(Base):
def __init__(self):
Base.__init__(self)
print 'Initializing B'

class C(Base):
def __init__(self):
print "Initializing C"
def hasDefaultImplementation(self):
print "Boo Hoo!"

base = Base()
print "\n--- A "
a = A()
a.shouldBeImplemented()
print "\n--- B "
b = B()
b.hasDefaultImplementation()
print "\n--- C "
c = C()
c.hasDefaultImplementation()
c.shouldBeImplemented()

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


Re: New to python

2006-08-17 Thread bearophileHUGS
Tim Gallagher:
> I am new to python and I have a few questions.  I am an old Perl hacker
> been using Perl for many years.  I wanted to give python a try, I am
> happy with it so far.

In some places and jobs Perl is the only scripting language used still,
but It seems there are other people like you that are slowly
evaporating from the Perl community and trying Python and Ruby.
Welcome, and feel free to ask what you need.

Bye,
bearophile

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


Re: CGI script running not completely in HTML

2006-08-17 Thread Tim
Yong Wang wrote:
> Hi, All:
> I have written a python CGI script to run in html web page. When I access 
> to
> the html page, it only runs part of the script, then abort because the late 
> part of
> the script is involved in database access, it is slow. I wonder whether there 
> is 
> a way to control html running speed so that it can wait for CGI script to 
> complete
> execution, then write the results to html page ? 
> Thanks a lot .
>
>   Yong
>
>   
Yong,

Are you reffering to your browser connection to web server timing out 
waiting for query to complete?

I had some long running scripts that would do that so I used a timer 
thread to print comments to the browser  IE: .  Brute 
force approach but it worked using IE with apache.  If I remember right 
you have to call sys.stdout.flush() to force the write over socket to 
happen right away. 

Tim


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


Re: CGI script running not completely in HTML

2006-08-17 Thread Steve Holden
Yong Wang wrote:
> Hi, All:
> I have written a python CGI script to run in html web page. When I access 
> to
> the html page, it only runs part of the script, then abort because the late 
> part of
> the script is involved in database access, it is slow. I wonder whether there 
> is 
> a way to control html running speed so that it can wait for CGI script to 
> complete
> execution, then write the results to html page ? 
> Thanks a lot .
> 
>   Yong
> 
Most servers impose some sort of CPU limit on CGI processes (though 
typically this defaults to a value of 30 seconds or more). If you really 
are going past your server's default(?) limit you really need to either 
tweak the limit up on the server (at least for that script) or 
reconsider whether the application is suitable for CGI in the first place.

What kind of "slow" are we talking about here? A minute? Ten minutes?

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

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


Re: How to fill a form

2006-08-17 Thread John J. Lee
Sulsa <[EMAIL PROTECTED]> writes:

> On Tue, 15 Aug 2006 03:37:02 -
> Grant Edwards <[EMAIL PROTECTED]> wrote:
> 
> > On 2006-08-15, Sulsa <[EMAIL PROTECTED]> wrote:
> > 
> > > I want to fill only one smiple form so i would like not to use
> > > any non standard libraries.
> > 
> > Then just send the HTTP "POST" request containing the fields
> > and data you want to submit.
> 
> but i don't know how to post these data if i knew there there would
> be no topic.

Something like this (UNTESTED, and I can never remember all the
details, which are fiddlier than they may look):

import urllib, urllib2
query = urllib.urlencode([
("username", "sulsa"), ("password", "sulsa"),
("redirect", ""), ("login", "Login"),
])
r = urllib2.urlopen("http://example.com/login.php";, query)
print r.read()


Note that urllib and urllib2 both, as their main job in life, open
URLs.  urllib also has miscellaneous functions related to URLs &c.  I
use urllib2 above because I know it better and because it can handle
some stuff that urllib doesn't (it's designed more for extensibility
than is urllib).


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


Re: sqlite3 or mysqldb?

2006-08-17 Thread Jarek Zgoda
John Salerno napisał(a):

> I did a little experimentation with MySQL, and yesterday I was reading
> up on SQLite. Since they both use the SQL language, does this mean that
> the queries you write will be the same for both modules? I'm sure there
> are slight differences for how you connect to DBs, but since they both
> use the same DB API 2.0, and both use SQL, I was wondering how easily
> you could 'switch' them out if you needed to go from one to the other.
> 
> (I know there are slight differences between the two in terms of SQL
> commands understood, but I'm mainly referring to the most important
> things, like simply accessing and changing DB information.)
> 
> I was using mysqldb just because MySQL seems to be a pretty big
> standard, but now that sqlite3 is coming with Python 2.5, I might
> switch, since it seems to be easier to use.
> 
> (And again, I'm such an amateur programmer that really I'm using these
> things just to learn them. It's not like I control my company's entire
> employee records or anything.)   :)

To learn SQL SQLite should be enough - it has all the basics, just as
MySQL, while it doesn't require any server/client configuration
(encoding configuration in MySQL is real PITA). But if you want any
"serious SQL", go with any freely available *real SQL server*, like
Firebird or PostgreSQL. I'd consider Firebird, as it's pretty lightweight.

In theory, switching from one db backend to another should go without
problem (at least at ANSI SQL level), but usually requires much work, so
it's rather rare practice. While basics, like DML or DDL syntax, remain
similar, often particular backends require specific tweaks and
optimizations to get desired level of efficiency. You know, this part of
application is a bottleneck.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI script running not completely in HTML

2006-08-17 Thread Steve Holden
Yong Wang wrote:
> Hi Steve:
>The propblem I run into is about one minute. The CGI script is not 
> completed to run and aborted.
> If I run the python script in backend solaris machine, the script needs about 
> one minute for database
> access.
> Thanks,
> 
> Yong
>  
In which case you probably need to tweak the server timeout setting. 
Nothing you can do from Python (except possibly make your CGI run faster).

regards
  Steve
> 
>>Yong Wang wrote:
>>
>>>Hi, All:
>>>I have written a python CGI script to run in html web page. When I 
>>> access to
>>>the html page, it only runs part of the script, then abort because the late 
>>>part of
>>>the script is involved in database access, it is slow. I wonder whether 
>>>there is 
>>>a way to control html running speed so that it can wait for CGI script to 
>>>complete
>>>execution, then write the results to html page ? 
>>>Thanks a lot .
>>>
>>>  Yong
>>>
>>
>>Most servers impose some sort of CPU limit on CGI processes (though 
>>typically this defaults to a value of 30 seconds or more). If you really 
>>are going past your server's default(?) limit you really need to either 
>>tweak the limit up on the server (at least for that script) or 
>>reconsider whether the application is suitable for CGI in the first place.
>>
>>What kind of "slow" are we talking about here? A minute? Ten minutes?
>>
>>regards
>>  Steve
>>-- 
>>Steve Holden   +44 150 684 7255  +1 800 494 3119
>>Holden Web LLC/Ltd  http://www.holdenweb.com
>>Skype: holdenweb   http://holdenweb.blogspot.com
>>Recent Ramblings http://del.icio.us/steve.holden
>>
>>-- 
>>http://mail.python.org/mailman/listinfo/python-list
>>
> 
> 
> 
> 
> 


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


Re: CGI script running not completely in HTML

2006-08-17 Thread Tim Chase
> In which case you probably need to tweak the server timeout
> setting. Nothing you can do from Python (except possibly make
> your CGI run faster).

Or have Python send a better SQL statement that would run 
faster...a little SQL mojo goes a long way.

The OP failed (as far as my thread-dabbling has noticed) to 
specify what sort of SQL is being run.  If full table results are 
being returned just to be discarded, or there are more efficient 
ways of doing things in the SQL, one would be better off doing it 
on the server and letting it return a single finely-honed 
result-set.  With some insight into the SQL statement(s), one 
might be able to find glaring bottlenecks.

-tkc



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


Interactive display of trace.py output?

2006-08-17 Thread djaquay
I've been using trace.py to get code coverage results for my unit tests, and
like it.  Now I'm trying to use it for code coverage of the GUI parts of my
wxPython-based program, and I realized how nice it would be to be able to see
what lines I'd covered and what remained to be exercised, without having to
stop the trace to get the output updated.

It occurred to me that accepting the "--trace" output from trace.py as input to
another program would allow that other program to show a source file and show
what lines remain to be tested as you're performing the tests.  It also
occurred to me that someone may have already done this.

Does such a thing exist, or do I get to write it?

Thanks,
Dave (djaquay at yahoo, dot-com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py2Exe and sys.argv : The Lost Arguments

2006-08-17 Thread Larry Bates
I entered the following simple program, compiled with py2exe (2.4)
and ran it the way you describe with two files selected and it
did what you said (e.g. only shows ays.argv[0] and sys.argv[1]):

import sys
print sys.argv
x=raw_input('Press return to continue')

Under 2.5 it didn't work at all (not sure why).

Funny thing is that if I select two .txt files and do a Open With
Notepad, Explorer only opens one of them.  So I think it is
Explorer that is throwing away the extra arguments.  Otherwise
I would expect it to open multiple notepad instances.

-Larry Bates


Thomas W wrote:
> I've created a simple script like so :
> 
> import sys
> import wx
> 
> app = wx.PySimpleApp()
> dlg = wx.MessageDialog(None, "%s" % sys.argv, 'A Message Box',
> wx.YES_NO | wx.ICON_QUESTION)
> retCode = dlg.ShowModal()
> app.MainLoop()
> 
> If I run this on the command line like
> python testcmd.py /somefile.ext /anotherfile.ext
> 
> it displays a messagebox with a stringformatted list containing
> testcmd.py, somefile.ext and anotherfile.ext.
> 
> Then I "compile" the script using py2exe, generate a file called
> testcmd.exe and select the same two files in Explorer, right click,
> "Open with ...", browse to testcmd.exe and proceed. Now the dialogbox
> only shows two items in the list; testcmd.exe and one of the files I
> selected. Why?
> 
> Is it impossible to compile a script using py2exe and pass selected
> items in Explorer to my script? It works fine when called on the
> command line so it might be something related to Explorer but I'm
> completly lost.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curried class methods?

2006-08-17 Thread Scott Lamb
Thanks, Antoon and Carl. Just tried your solutions - both work and are
much cleaner than mine.

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


re.sub() backreference bug?

2006-08-17 Thread jemminger
using this code:

import re
s = 'HelloWorld19-FooBar'
s = re.sub(r'([A-Z]+)([A-Z][a-z])', "\1_\2", s)
s = re.sub(r'([a-z\d])([A-Z])', "\1_\2", s)
s = re.sub('-', '_', s)
s = s.lower()
print "s: %s" % s

i expect to get:
hello_world19_foo_bar

but instead i get:
hell☺_☻orld19_fo☺_☻ar

(in case the above doesn't come across the same, it's:
hellX_Yorld19_foX_Yar, where X is a white smiley face and Y is a black
smiley face !!)

is this a bug, or am i doing something wrong?

tested on
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32

and
Python 2.4.4c0 (#2, Jul 30 2006, 15:43:58) [GCC 4.1.2 20060715
(prerelease) (Debian 4.1.1-9)] on linux2

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

Re: hide python code !

2006-08-17 Thread Gerhard Fiedler
On 2006-08-17 16:27:46, danielx wrote:

> A second point to consider: The chip is patentable (I think this is the
> case legally, as well as in the court of public opinion), 

No. A chip is not patentable. In your scenario, the /idea/ behind the
chip's functionality may be patentable, but for a patent it doesn't matter
whether the idea is realized as a custom chip or as software running on a
standard computer.

Differently from copyright (which is about a specific form), patents are
about ideas. They must have a realization (ie. you must be able to show
that it can work), but the patent encompasses all realizations of the
described idea. (It may of course be non-trivial to determine whether a
given modification has been described in the patent or not...)

Gerhard

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


Re: re.sub() backreference bug?

2006-08-17 Thread Tim Chase
> s = re.sub(r'([A-Z]+)([A-Z][a-z])', "\1_\2", s)
> s = re.sub(r'([a-z\d])([A-Z])', "\1_\2", s)
> i expect to get:
> hello_world19_foo_bar
> 
> but instead i get:
> hell☺_☻orld19_fo☺_☻ar


Looks like you need to be using "raw" strings for your 
replacements as well:

s = re.sub(r'([A-Z]+)([A-Z][a-z])', r"\1_\2", s)
s = re.sub(r'([a-z\d])([A-Z])', r"\1_\2", s)

This should allow the backslashes to be parsed as backslashes, 
not as escape-sequences (which in this case are likely getting 
interpreted as octal numbers)

-tkc



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

  1   2   >