How to Fix JavaScript Error ...

2010-10-28 Thread neha shena
How to Fix JavaScript Error ...

Javascript error usually appears with a yellow triangle in pop up box
and telling you to debug. A problem with JavaScript embedded in the
..read more 

http://childschooledu.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


How to Fix JavaScript Error ...

2010-10-28 Thread neha shena

How to Fix JavaScript Error ...

Javascript error usually appears with a yellow triangle in pop up box
and telling you to debug. A problem with JavaScript embedded in the
..read more 

http://childschooledu.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling Python from Haskell

2010-10-28 Thread Paul Rubin
For any Haskell fans that might be reading this, here is a blog post
(not by me) about a new package for calling Python code from Haskell
code.  It basically works by connecting the C API's of both languages
together:

  http://john-millikin.com/articles/ride-the-snake/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread Xavier Ho
On 29 October 2010 15:50, Paul Rubin  wrote:

> John Nagle  writes:
> >d1 = set('monday','tuesday')
> >days_off = set('saturday','sunday')
> >if not d1.isdisjoint(days_off) :...
> >This is cheaper than intersection, since it doesn't have to
> > allocate and construct a set. It just tests whether any element in the
> > smaller of the two sets is in the larger one.
>
> I wonder what the complexity is, since the simplest implementation using
> the dict-like features of sets is quadratic.  There is of course an
> obvious n log n implementation involving sorting.
>

I like John Nagle's idea. Presuming isdisjoint() will return upon early
termination criteria, the average case is probably much better than O(n^2).
Best case is near linear, and worse case will probably never happen, because
if you have to cover every day, chances are they overlap. Sorting in this
case is probably not needed. Of course, we're only looking at 7 days a week,
so performance is not an issue.

If I really cared about performance, I would probably use bits and then do a
logical AND operation.

+1 to Nagle from me.

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread Paul Rubin
John Nagle  writes:
>d1 = set('monday','tuesday')
>days_off = set('saturday','sunday')
>if not d1.isdisjoint(days_off) :...
>This is cheaper than intersection, since it doesn't have to
> allocate and construct a set. It just tests whether any element in the
> smaller of the two sets is in the larger one.

I wonder what the complexity is, since the simplest implementation using
the dict-like features of sets is quadratic.  There is of course an
obvious n log n implementation involving sorting.
-- 
http://mail.python.org/mailman/listinfo/python-list


embedding python ImportError: libpyglib PyExc_ImportError

2010-10-28 Thread Oliver Marks

Hi i am a new member on this list and thought if some people may be able
to enlighten me to the error below ?

I am running 64 bit ubuntu 10.10 and python 2.6 in case there are know
issues with this
setup, basically i am embedding python inside a c application i managed
to get this to work i can call functions from the original c program and
the scripts run until i import gtk in the python script this causes the
error below.

I am using the waf build system to build the c program, my knowledge of
c is limited i am more a python programmer which is why i am attempting
the embed python so i can write my plugins in python.

I get the feeling the error is todo with linking but i dont get why i
can import gtk normally in python but not when its embeded ?

Any help or pointers would be appreciated, that might help me get this
solved or better understand what is wrong.

Traceback (most recent call last):
  File "/usr/local/share/geany/plugins/gpykickstart.py", line 4, in

import glib
  File "/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.py", line 22,
in 
from glib._glib import *
ImportError: /usr/lib/libpyglib-2.0-python2.6.so.0: undefined symbol:
PyExc_ImportError
Failed to load the "gpykickstart" module from the
"/usr/local/share/geany/plugins" directory.


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


Re: Python changes

2010-10-28 Thread Stefan Behnel

Teenan, 28.10.2010 21:16:

On Thu, 2010-10-28 at 15:03 -0400, Craig McRoberts wrote:

Thanks for the prompt replies. Sounds like it's time to hit a bookstore.


You could do a lot worse than getting 'Dive into Python' (There's even a
nice new version just for python 3.0)


Yes, and the thing I like most about the Py3 version is that the XML 
chapter has been rewritten completely. It's now based on ElementTree and 
even gives lxml.etree an intro.


http://diveintopython3.org/xml.html

That, if nothing else, is enough of a reason to read it instead of the much 
older Py2 version of the book.


Stefan

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread John Nagle

On 10/28/2010 9:23 AM, John Posner wrote:

On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:

It's clear but tedious to write:

if 'monday" in days_off or "tuesday" in days_off:
doSomething

I currently am tending to write:

if any([d for d in ['monday', 'tuesday'] if d in days_off]):
doSomething

Is there a better pythonic idiom for this situation?



Clunky, but it might prompt you to think of a better idea: convert the
lists to sets, and take their intersection.

-John


   d1 = set('monday','tuesday')
   days_off = set('saturday','sunday')

   if not d1.isdisjoint(days_off) :
...

   This is cheaper than intersection, since it doesn't have to allocate 
and construct a set. It just tests whether any element in the smaller of 
the two sets is in the larger one.


John Nagle

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


Re: How on Factorial

2010-10-28 Thread Stefan Behnel

Arnaud Delobelle, 28.10.2010 20:38:

using ~-n instead of n-1 if obfuscatory and doesn't
even save keystrokes!  (Although it could in other situations, e.g
2*(n-1) can be written 2*~-n, saving two brackets.)


Sure, good call. And look, it's only slightly slower than the obvious code:

$ python3 -m timeit -s "n=30" "2*~-n"
1000 loops, best of 3: 0.0979 usec per loop

$ python3 -m timeit -s "n=30" "2*(n-1)"
1000 loops, best of 3: 0.0841 usec per loop

Stefan

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


Re: factorial of negative one (-1)

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz  wrote:
> I am working with differential equations of the higher roots of negative
> one. (dividing enormous numbers into other enormous numbers to come out with
> very reasonable numbers).
> I am mixing this in to a script for Maya (the final output is graph-able as
> a spiral.)
> I have heard that Sage, would be a good program to do this in, but I'd like
> to try and get this to work in native python if I can.
> The script I am trying to port to Python is; http://pastebin.com/sc1jW1n4.

Unless your code is really long, just include it in the message in the future.
So, for the archive:
indvar = 200;
q = 0;
lnanswer = 0;
for m = 1:150
  lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m))  ;
q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer);
end
lnanswer
q

Also, it helps to point out *what language non-Python code is in*. I'm
guessing MATLAB in this case.

Naive translation attempt (Disclaimer: I don't know much MATLAB):

from math import log, factorial, exp
indvar = 200
q = [0]
lnanswer = 0
for m in range(1, 151):
lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m))
q.append(q[-1] + (1 if m % 2 == 0 else -1) * exp(lnanswer))
print(lnanswer)
print(q)

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: factorial of negative one (-1)

2010-10-28 Thread Xavier Ho
On 29 October 2010 14:41, Bj Raz  wrote:
>
> Since Python can't call functions, I would like to know if there is a work
> around.
>

Python can't call functions? I'm sorry, but I may have misunderstood what
you are trying to say.

I'm not familiar with the mathematical definition of factorial, but if it is
defined for negative integers, the "workaround" should be defined that way,
too, I'd imagine.

Am I missing something here?

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


Re: Why "flat is better than nested"?

2010-10-28 Thread rantingrick
On Oct 27, 8:40 pm, Steven D'Aprano  wrote:

> Although the Zen is written in a light-hearted fashion, it is not
> intended as a joke. Every line in the Zen is genuine advice -- even the
> one about being Dutch. Would it help to write it out in a less light-
> hearted fashion?
>
> When programming in Python, you should:

<...snip...>


Bravo! Bravo!

That eloquently verbose description of the Zen left a tear in my eye
and a patriotic pride in my heart.  Oh Guido, stop moonlighting as
D'Aprano and use your real name again! The second coming of GvR is
upon us!

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


factorial of negative one (-1)

2010-10-28 Thread Bj Raz
I am working with differential equations of the higher roots of negative
one. (dividing enormous numbers into other enormous numbers to come out with
very reasonable numbers).
I am mixing this in to a script for Maya (the final output is graph-able as
a spiral.)
I have heard that Sage , would be a good program
to do this in, but I'd like to try and get this to work in native python if
I can.

The script I am trying to port to Python is; http://pastebin.com/sc1jW1n4.
Since Python can't call functions, I would like to know if there is a work
around.

Thank you
Also; I would also like to know if there is a good way to go about building
Sage for msys.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Discussion board software?

2010-10-28 Thread Andreas Waldenburger
On Fri, 29 Oct 2010 01:28:12 + brad...@hotmail.com wrote:
[fixed top posting]
> --Original Message--
> From: Gnarlodious
> Sender: python-list-bounces+bradenf=hotmail@python.org
> To: Python List
> Subject: Discussion board software?
> Sent: Oct 28, 2010 9:12 PM
> 
> > Is there such a thing as website discussion board software written
> > in Python?
> 
> Not that I'm aware of 

Braden (that is your name, right?), can you please put your reply under
the part of the message you're replying too? And preferably delete all
parts of the message that are not of interest pertinent to your reply?

There are many reasons for and against this practice, but the most
important "for" arguments are

- It enables replies in context.
- It preserves reading order.
- Everyone here uses is, and not using it is confusing. (If some people
  reply above a quote and others don't, it get's confusing faster
  than a George W. Bush speech.)

Thanks,
/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

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


Re: Calling a method from invoking module

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 8:33 PM, Baskaran Sankaran  wrote:
> Sorry for the confusion; fooz(), track() and barz() are all members of their
> respective classes. I must have missed the self argument while creating the
> synthetic example.
>
> Yeah, I realize the mutual import is a bad idea. So, if I merge them into a
> single module (but still retaining the two classes) will work right? I
> guess, it will look like this after merging.
>
> Thanks again
> -b
>
> * foo_bar.py *
>
> class Foo:
>     def fooz(self):
>     print "Hello World"
>     b = Bar()
>     c = b.barz()
>     ...
>
>     def track(self, track_var):
>     count += 1

That line will raise UnboundLocalError. Where's count initialized?

>     return sth2
>
>
> class Bar:
>     def barz(self):
>     track_this = ...
>     if Foo.track(track_this):

You can't call an instance method on a class.

Cheers,
Chris
--
Nitpicker extraordinaire
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-28 Thread alex23
Andreas Waldenburger  wrote:
> No, it wouldn't, hence Stefan's (and your) error. It maps to a specific
> boy. Replacing "that"s where possible, it becomes:
>
> I know that [the] "that" [which] that boy said is wrong.

Ah, I see now: I know that that "that" that _that_ boy said is wrong :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2010-10-28 Thread Andreas Waldenburger
On Wed, 27 Oct 2010 22:47:35 -0700 (PDT) alex23 
wrote:

> On Oct 27, 7:58 pm, Robin Becker  wrote:
> > >> "I know that that that that that boy said is wrong!".
> >
> > well they say nested is hard. How about this break down
> >
> > I know that X that a boy said is wrong. (any boy)
> > I know that X that the boy said is wrong. (a single boy)
> > I know that X that that boy said is wrong. (a specific boy)
> 
> But your original statement maps out to:
> 
> I know that X that that that boy said is wrong.
> 
> So this would apply to a specific 'that boy', hence Stefan's
> question :)

No, it wouldn't, hence Stefan's (and your) error. It maps to a specific
boy. Replacing "that"s where possible, it becomes:

I know that [the] "that" [which] that boy said is wrong.

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.

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


Re: Discussion board software?

2010-10-28 Thread Tim Harig
On 2010-10-29, Gnarlodious  wrote:
> On Oct 28, 7:20 pm, Tim Harig  wrote:
>> On 2010-10-29, Gnarlodious  wrote:
>>
>> > Is there such a thing as website discussion board software written in
>> > Python?
>>
>> Yes.
>
> OK I'll play, what and where?

CMS's written in Python generally have some kind forum functionality or
plugin available.

Plone:
http://www.contentmanagementsoftware.info/plone/forum

Django (look under "Django application components"->"Forums and comments"):
http://code.djangoproject.com/wiki/DjangoResources

http://pyforum.org/

There are few other smaller ones around if you look.  Google is your
friend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Calling a method from invoking module

2010-10-28 Thread Baskaran Sankaran
Sorry for the confusion; fooz(), track() and barz() are all members of their
respective classes. I must have missed the self argument while creating the
synthetic example.

Yeah, I realize the mutual import is a bad idea. So, if I merge them into a
single module (but still retaining the two classes) will work right? I
guess, it will look like this after merging.

Thanks again
-b

* foo_bar.py *

class Foo:
def fooz(self):

print "Hello World"
b = Bar()
c = b.barz()
...

def track(self, track_var):
count += 1
return sth2


class Bar:
def barz(self):

track_this = ...
if Foo.track(track_this):
pass
else:
...
return sth1


On Thu, Oct 28, 2010 at 7:12 PM, Dave Angel  wrote:

> Your example is so vague it's hard to tell what the real requirements are.
>  Foo.track() won't work as coded, since it doesn't have a self argument.  If
> you really meant that, then make it a non-class function, and preferably
> define it in another module, included perhaps by both bar and foo.
>  Similarly, barz() cannot be called, since it wants zero arguments, and
> it'll always get at least one.
>
> If I were you, I'd put both classes into the same module until you get
> their relationship properly understood.  And if they're really so
> intertwined, consider leaving them in the same module.  This isn't java.
>
> In general, it's best not to have two modules importing each other.
>  Generally, you can extract the common things into a separate module that
> each imports.  Failing that, you can have one import the other, and pass it
> whatever object references it'll need to run.  For example, at the end of
> foo.py, you'd have something like
>  bar.Foo = Foo
>
> If you really need to mutually import two modules, the first problem you're
> likely to bump into is if either of them is your script.  In other words,
> you need to have a separate file that's your script, that imports both foo
> and bar.
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter resources (was Re: Tkinter: how to create (modal) dialogs a la tk_dialog?)

2010-10-28 Thread python
Excellent Tkinter tutorials

Fundamentals Of Tkinter Part 1
http://www.dreamincode.net/forums/topic/116314-fundamentals-of-tkinter-part-one/

Fundamentals Of Tkinter Part 2
http://www.dreamincode.net/forums/topic/117474-fundementals-of-tkinter-part-2/

Tkinter, Part 3 - Dialogs
http://www.dreamincode.net/forums/topic/135050-tkinter-part-3-dialogs/

Tkinter, Part 4 - Basic Event Bindings
http://www.dreamincode.net/forums/topic/137447-tkinter-part-4-basic-event-bindings/

...

Excellent Tkinter documentation

List of Python Tkinter documentation
http://wiki.python.org/moin/TkInter

Overview
http://docs.python.org/library/tkinter.html

Full documentation
http://effbot.org/tkinterbook/

...

If you're using Python 2.7/3.1 check out the new ttk (Tile) support for
sexy, native looking user interfaces based on Tkinter (really!)

http://www.tkdocs.com/tutorial/onepage.html

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


Re: Tkinter: how to create (modal) dialogs a la tk_dialog?

2010-10-28 Thread Andrew
On Thu, 28 Oct 2010 13:57:24 + (UTC), Olaf Dietrich wrote:

> Could it be that these parts of Tkinter
> are not particularly extensively documented? (Or am I searching
> with the wrong expressions?)
> Olaf

I've wondered about this too. The tkinter and tkinter.ttk sections of the
documentation seem to have a large number of classes and functions listed
as part of the module but without any more than a line or two about what
they do or how to use them. The last (and only, so far) time I used
tkinter, I often found it more useful to examine Tk documentation to
discover, say, what options or arguments were possible and/or useful, and
then try to translate that into the python/tkinter equivelant.

--

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


Re: Calling a method from invoking module

2010-10-28 Thread Dave Angel

On 2:59 PM, Baskaran Sankaran wrote:

Hi,

I have two classes in separate python modules and I need to access some
methods of the either classes from the other. They are not in base and
derived class relationship.

Please see the example below. Foo imports Bar and inside the Foo class it
creates a Bar obj and then calls Bar.barz(). Now before returning control,
it has to call the track method in Foo.

As I understand, I won't be able to use 'super' in this case, as there is no
inheritance here. Also, I won't be able to move the track method to Bar as I
need to track different bar types.

Any suggestion on how to get this done would be great. Thanks in advance.

Cheers
- b

--

* foo.py *

import bar
class Foo:
 def fooz():
 print "Hello World"
 b = Bar()
 c = b.barz()
 ...

 def track(track_var):
 count += 1
 return sth2


* bar.py *
class Bar:
 def barz():
 track_this = ...
 if Foo.track(track_this):
 pass
 else:
 ...
 return sth1

Your example is so vague it's hard to tell what the real requirements 
are.  Foo.track() won't work as coded, since it doesn't have a self 
argument.  If you really meant that, then make it a non-class function, 
and preferably define it in another module, included perhaps by both bar 
and foo.  Similarly, barz() cannot be called, since it wants zero 
arguments, and it'll always get at least one.


If I were you, I'd put both classes into the same module until you get 
their relationship properly understood.  And if they're really so 
intertwined, consider leaving them in the same module.  This isn't java.


In general, it's best not to have two modules importing each other.  
Generally, you can extract the common things into a separate module that 
each imports.  Failing that, you can have one import the other, and pass 
it whatever object references it'll need to run.  For example, at the 
end of foo.py, you'd have something like

  bar.Foo = Foo


If you really need to mutually import two modules, the first problem 
you're likely to bump into is if either of them is your script.  In 
other words, you need to have a separate file that's your script, that 
imports both foo and bar.


DaveA

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


Re: Why "flat is better than nested"?

2010-10-28 Thread rantingrick
On Oct 25, 10:23 am, Steve Holden  wrote:
> it was
> written by Tim Peters one night during the commercial breaks between
> rounds of wrestling on television.

Tim Peters...a "WrestleMania" fan...who would have guessed?

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


Re: Discussion board software?

2010-10-28 Thread Gnarlodious
On Oct 28, 7:20 pm, Tim Harig  wrote:
> On 2010-10-29, Gnarlodious  wrote:
>
> > Is there such a thing as website discussion board software written in
> > Python?
>
> Yes.

OK I'll play, what and where?

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


Re: Discussion board software?

2010-10-28 Thread bradenf
Not that I'm aware of 

--Original Message--
From: Gnarlodious
Sender: python-list-bounces+bradenf=hotmail@python.org
To: Python List
Subject: Discussion board software?
Sent: Oct 28, 2010 9:12 PM

Is there such a thing as website discussion board software written in
Python?
-- 
http://mail.python.org/mailman/listinfo/python-list



Sent wirelessly from my BlackBerry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Discussion board software?

2010-10-28 Thread Tim Harig
On 2010-10-29, Gnarlodious  wrote:
> Is there such a thing as website discussion board software written in
> Python?

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


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread python
Grant,

>> Tkinter is built-in and available on Windows, Mac, and Linux. If you're
>> using Python 2.7 or 3.1 you can take advantage of Tkinter's ttk (Tile)
>> support for platform native user interfaces.

> You get a native UI using the correct theme even on Linux under Qt or GTk?

That's an excellent question. I don't know. What I can attest to is the 
high quality of ttk's native interface on Windows and Mac (Aqua).

> From what I've read of ttk, it still isn't using native UI elements.
It just has a bunch of its own "themes" that look mostly/sort-of like
native UI elements. Right?

I don't think this statement is accurate. But I'm also no expert on this
topic either. The following links on from my research on the topic of
Python and ttk (Tile):

Here's the basis for the new ttk (Tile) technology (independent of
Python)
http://www.tcl.tk/cgi-bin/tct/tip/48

An excellent ttk tutorial with screenshots and Python code
http://www.tkdocs.com

A presentation titled "Tkinter does not suck"
http://www.slideshare.net/r1chardj0n3s/tkinter-does-not-suck

> Under Linux does ttk automagically pick the theme that looks most like
the current Qt or Gtk theme? On systems where both are installed, how 
does ttk decide whether to look like Qt or Gtk?

I hope someone on this list can answer these questions.

> In addition to looking like native UI elements, does ttk also change
UI behaviors to match native UI elements?  For example will it
automatically use emacs key-bindings for text-entry editing if that's
enabled in my Gtk configuration?

Another excellent question. If you have Python 2.7 or 3.1 you should be
able to answer these questions yourself. The tkdocs.com website 
mentioned above has copy and paste Python code you can use.

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


Re: Land Of Lisp is out

2010-10-28 Thread bradenf
Sounds interesting

--Original Message--
From: Lawrence D'Oliveiro
Sender: python-list-bounces+bradenf=hotmail@python.org
To: Python List
Subject: Re: Land Of Lisp is out
Sent: Oct 28, 2010 7:34 PM

In message 
, kodifik 
wrote:

> On Oct 28, 1:55 am, Lawrence D'Oliveiro 
> wrote:
>
>> Would it be right to say that the only Lisp still in common use is the
>> Elisp built into Emacs?
> 
> Surely surpassed by autolisp (a xlisp derivative inside the Autocad
> engineering software).

How many copies of AutoCAD are there? Given its price, probably something in 
the five or six figures at most.
-- 
http://mail.python.org/mailman/listinfo/python-list



Sent wirelessly from my BlackBerry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread jos...@corporate-world.lisp.de
On 29 Okt., 01:34, Lawrence D'Oliveiro  wrote:
> In message
> , kodifik
> wrote:
>
> > On Oct 28, 1:55 am, Lawrence D'Oliveiro 
> > wrote:
>
> >> Would it be right to say that the only Lisp still in common use is the
> >> Elisp built into Emacs?
>
> > Surely surpassed by autolisp (a xlisp derivative inside the Autocad
> > engineering software).
>
> How many copies of AutoCAD are there? Given its price, probably something in
> the five or six figures at most.

A few million.
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling a method from invoking module

2010-10-28 Thread Baskaran Sankaran
Hi,

I have two classes in separate python modules and I need to access some
methods of the either classes from the other. They are not in base and
derived class relationship.

Please see the example below. Foo imports Bar and inside the Foo class it
creates a Bar obj and then calls Bar.barz(). Now before returning control,
it has to call the track method in Foo.

As I understand, I won't be able to use 'super' in this case, as there is no
inheritance here. Also, I won't be able to move the track method to Bar as I
need to track different bar types.

Any suggestion on how to get this done would be great. Thanks in advance.

Cheers
- b

--

* foo.py *

import bar
class Foo:
def fooz():
print "Hello World"
b = Bar()
c = b.barz()
...

def track(track_var):
count += 1
return sth2


* bar.py *
class Bar:
def barz():
track_this = ...
if Foo.track(track_this):
pass
else:
...
return sth1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread Lawrence D'Oliveiro
In message 
, kodifik 
wrote:

> On Oct 28, 1:55 am, Lawrence D'Oliveiro 
> wrote:
>
>> Would it be right to say that the only Lisp still in common use is the
>> Elisp built into Emacs?
> 
> Surely surpassed by autolisp (a xlisp derivative inside the Autocad
> engineering software).

How many copies of AutoCAD are there? Given its price, probably something in 
the five or six figures at most.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread bradenf
Thanks what is there to learn about each gui tools? 

--Original Message--
From: Alex Hall
To: brad...@hotmail.com
Cc: python-list@python.org
Subject: Re: Create a GUI and EXE for a python app?
Sent: Oct 28, 2010 5:49 PM

There is tkinter or WX for a gui solution. I use wx just because I
already know it and it does what I need it to do, so I see no reason
to switch to a different library to do the same thing.

On 10/28/10, brad...@hotmail.com  wrote:
> Thanks ill give it a try! Anyone know about the GUI then?
>
> --Original Message--
> From: Chris Rebert
> Sender: ch...@rebertia.com
> To: Braden Faulkner
> Cc: python-list@python.org
> Subject: Re: Create a GUI and EXE for a python app?
> Sent: Oct 28, 2010 5:04 PM
>
> On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner 
> wrote:
>> Having trouble with my mail client, so sorry if this goes through more
>> than
>> once.
>> I'm worknig on a simple math program as my first application. I would like
>> to make a cross-platform pretty GUI for it and also package it up in a EXE
>> for distribution on Windows.
>> What are the best and easiest ways I can do this?
>
> For the latter, py2exe:
> http://www.py2exe.org/
>
> Cheers,
> Chris
>
>
>
> Sent wirelessly from my BlackBerry.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap



Sent wirelessly from my BlackBerry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread Grant Edwards
On 2010-10-28, pyt...@bdurham.com  wrote:

> Tkinter is built-in and available on Windows, Mac, and Linux. If you're
> using Python 2.7 or 3.1 you can take advantage of Tkinter's ttk (Tile)
> support for platform native user interfaces.

You get a native UI using the correct theme even on Linux under Qt or GTk?

>From what I've read of ttk, it still isn't using native UI elements.
It just has a bunch of its own "themes" that look mostly/sort-of like
native UI elements.  Right?

Under Linux does ttk automagically pick the theme that looks most like
the current Qt or Gtk theme?

On systems where both are installed, how does ttk decide whether to
look like Qt or Gtk?

In addition to looking like native UI elements, does ttk also change
UI behaviors to match native UI elements?  For example will it
automatically use emacs key-bindings for text-entry editing if that's
enabled in my Gtk configuration?

I don't particularly care what the UI elements _look_ like, as long as
they _act_ like native elements.

-- 
Grant Edwards   grant.b.edwardsYow! I think I am an
  at   overnight sensation right
  gmail.comnow!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread python
Tkinter is built-in and available on Windows, Mac, and Linux. If you're
using Python 2.7 or 3.1 you can take advantage of Tkinter's ttk (Tile)
support for platform native user interfaces.

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


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread Philip Semanchuk

On Oct 28, 2010, at 5:43 PM, brad...@hotmail.com wrote:

> Thanks ill give it a try! Anyone know about the GUI then?

Lots of people know about GUIs, the problem is that it's not a simple subject. 
There's lots of free education on the subject in the list archives. Here's my 
very brief summary of options --

- Tkinter - unsophisticated (-) but built into Python (+++)
- wxPython - rich (+), not built into Python (-)
- pyQT - rich (+), not built into Python (-), many people say it is nicer than 
wxPython
- There are other choices but I know nothing about them.

There may be license issues for you to consider. Also, my very limited 
experience with py2exe is that it is less likely to work the more complicated 
your app is. So if you start adding in wxPython or pyQT or some other GUI, 
py2exe might not be able to bundle your app anymore.

As I intimated, there are many tradeoffs to be considered. If this is your 
first Python app, I'd say keep it simple and stick with Tkinter. Worry about 
the fancy stuff later.


Good luck
Philip



> 
> --Original Message--
> From: Chris Rebert
> Sender: ch...@rebertia.com
> To: Braden Faulkner
> Cc: python-list@python.org
> Subject: Re: Create a GUI and EXE for a python app?
> Sent: Oct 28, 2010 5:04 PM
> 
> On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner  wrote:
>> Having trouble with my mail client, so sorry if this goes through more than
>> once.
>> I'm worknig on a simple math program as my first application. I would like
>> to make a cross-platform pretty GUI for it and also package it up in a EXE
>> for distribution on Windows.
>> What are the best and easiest ways I can do this?
> 
> For the latter, py2exe:
> http://www.py2exe.org/
> 
> Cheers,
> Chris
> 
> 
> 
> Sent wirelessly from my BlackBerry.
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Using nested lists and tables

2010-10-28 Thread Rhodri James

On Thu, 28 Oct 2010 14:30:16 +0100, Zeynel  wrote:


On Oct 28, 2:32 am, robert  wrote:

the reason may be that your text doesn't contain a question (mark).

...

perhaps drill down to a question on python-level.


Thanks, I realize that what I was trying to ask is not too clear. I am
learning to GAE using Python and I want to deploy a simple app. The
app will have a form. The user enters a sentence to the form and
presses enter. The sentence is displayed. The user types in the same
sentence; the sentence is displayed on the same column; the user types
in a different sentence; the different sentence is displayed on the
next column; as long as the user types in the same sentence; the
sentence is displayed on the same column; otherwise it is displayed on
the next column.

Maybe nested lists are not the right tool for this. Any suggestions?


It still really isn't clear what your *question* is here.  Perhaps if
you showed us what you have tried already we might be better able to
divine what problem you're facing?

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


Re: Why "flat is better than nested"?

2010-10-28 Thread Ben Finney
Steven D'Aprano  writes:

> On Wed, 27 Oct 2010 22:45:21 -0700, alex23 wrote:
> > The whole thing could be replaced by a single print """The Zen
> > of...""".
>
> But that would miss the point. It's supposed to be light-hearted.

Yes, and to that end it's also (deliberately, in my view) breaking as
many of the Zen admonishments as it can.

That was my point.

-- 
 \ “To save the world requires faith and courage: faith in reason, |
  `\and courage to proclaim what reason shows to be true.” |
_o__)—Bertrand Russell |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread Alex Hall
There is tkinter or WX for a gui solution. I use wx just because I
already know it and it does what I need it to do, so I see no reason
to switch to a different library to do the same thing.

On 10/28/10, brad...@hotmail.com  wrote:
> Thanks ill give it a try! Anyone know about the GUI then?
>
> --Original Message--
> From: Chris Rebert
> Sender: ch...@rebertia.com
> To: Braden Faulkner
> Cc: python-list@python.org
> Subject: Re: Create a GUI and EXE for a python app?
> Sent: Oct 28, 2010 5:04 PM
>
> On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner 
> wrote:
>> Having trouble with my mail client, so sorry if this goes through more
>> than
>> once.
>> I'm worknig on a simple math program as my first application. I would like
>> to make a cross-platform pretty GUI for it and also package it up in a EXE
>> for distribution on Windows.
>> What are the best and easiest ways I can do this?
>
> For the latter, py2exe:
> http://www.py2exe.org/
>
> Cheers,
> Chris
>
>
>
> Sent wirelessly from my BlackBerry.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread bradenf
Thanks ill give it a try! Anyone know about the GUI then?

--Original Message--
From: Chris Rebert
Sender: ch...@rebertia.com
To: Braden Faulkner
Cc: python-list@python.org
Subject: Re: Create a GUI and EXE for a python app?
Sent: Oct 28, 2010 5:04 PM

On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner  wrote:
> Having trouble with my mail client, so sorry if this goes through more than
> once.
> I'm worknig on a simple math program as my first application. I would like
> to make a cross-platform pretty GUI for it and also package it up in a EXE
> for distribution on Windows.
> What are the best and easiest ways I can do this?

For the latter, py2exe:
http://www.py2exe.org/

Cheers,
Chris



Sent wirelessly from my BlackBerry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner  wrote:
> Having trouble with my mail client, so sorry if this goes through more than
> once.
> I'm worknig on a simple math program as my first application. I would like
> to make a cross-platform pretty GUI for it and also package it up in a EXE
> for distribution on Windows.
> What are the best and easiest ways I can do this?

For the latter, py2exe:
http://www.py2exe.org/

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


Create a GUI and EXE for a python app?

2010-10-28 Thread Braden Faulkner

Having trouble with my mail client, so sorry if this goes through more than 
once. 
I'm worknig on a simple math program as my first application. I would like to 
make a cross-platform pretty GUI for it and also package it up in a EXE for 
distribution on Windows.
What are the best and easiest ways I can do this?Thanks!
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question - parsing MIME(?) strings

2010-10-28 Thread Anssi Saari
Dan M  writes:

> On Thu, 28 Oct 2010 15:05:56 -0500, Dan M wrote:
>
> Ok, I didn't research enough before I posted this. I see now that this 
> *is* indeed a MIME message, and the '?Q' bit says that the next piece is 
> quoted-printable, and that the encoding is defined in RFC2047.
>
> So the question the becomes, do we have a library for reading info like
> this?

The quopri module handles quoted-printable. I've used it to demangle
mail headers. I had a regexp from a perl script available to split
headers, so I just fed the quoted-printable part to
quopri.decodestring, even though quopri.decode should be able to
handle a header directly.

Headers can sometime be encoded in base64 as well, at least in emails.
I don't think it's common in Usenet though. But that can be decoded by
the base64 module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question - parsing MIME(?) strings

2010-10-28 Thread superpollo

Dan M ha scritto:

On Thu, 28 Oct 2010 15:05:56 -0500, Dan M wrote:

Ok, I didn't research enough before I posted this. I see now that this 
*is* indeed a MIME message, and the '?Q' bit says that the next piece is 
quoted-printable, and that the encoding is defined in RFC2047.


So the question the becomes, do we have a library for reading info like
this?




maybe http://docs.python.org/library/email ?

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


Re: Newbie question - parsing MIME(?) strings

2010-10-28 Thread Dan M
On Thu, 28 Oct 2010 15:05:56 -0500, Dan M wrote:

Ok, I didn't research enough before I posted this. I see now that this 
*is* indeed a MIME message, and the '?Q' bit says that the next piece is 
quoted-printable, and that the encoding is defined in RFC2047.

So the question the becomes, do we have a library for reading info like
this?


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


Newbie question - parsing MIME(?) strings

2010-10-28 Thread Dan M
I'm working on a script that grabs messages from a Usenet server and does 
some work with them. All works nicely except for a few issues with the 
data I retrieve.

For example, in one newsgroup I find occasional lines containing bits 
like:
"Re: Mlle. =?ISO-8859-1?Q?Ana=EFs_introdooses_her_ownself=2E?="

Is this some sort of bizarre MIME encoding? Looking at the data I can see 
how what the "=EF" and "=2E" mean, but that stuff after the first = has 
me confused.

And more to the point, is there a python module to handle this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python changes

2010-10-28 Thread Craig McRoberts
Oh, I like to browse brick-and-mortar enough. But it's been forever since I've 
bought something there.

Craig McRoberts

On Oct 28, 2010, at 15:16, Teenan  wrote:

> On Thu, 2010-10-28 at 15:03 -0400, Craig McRoberts wrote:
>> Thanks for the prompt replies. Sounds like it's time to hit a bookstore.
>> 
>> Craig McRoberts
> 
> You could do a lot worse than getting 'Dive into Python' (There's even a
> nice new version just for python 3.0)
> 
> hmmm bookstore.. those are the things they had before Amazon right? ;)
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unix-head needs to Windows-ize his Python script (II)

2010-10-28 Thread Nobody
On Thu, 28 Oct 2010 12:54:03 +1300, Lawrence D'Oliveiro wrote:

>>> Why would you want both CLI and GUI functions in one program?
>> 
>> An obvious example was the one which was being discussed, i.e. the Python
>> interpreter.
> 
> But the Python interpreter has no GUI.

It may have one if you use wx, tkInter, etc. So far as the OS is
concerned, it's all python.exe or pythonw.exe.

>> Forcing a program to choose between the two means that we need both
>> python.exe and pythonw.exe.
> 
> And yet we get by just fine without this dichotomy on more rationally-
> designed operating systems.

For some definitions of "fine". A GUI-based launcher doesn't know whether
the program it's being asked to run actually needs stdin/stdout/stderr.
Either it spawns an xterm (etc) even if it's not necessary, or it doesn't
and the user can't communicate with the program, or it uses some arbitrary
set of heuristics ("does the program link against Xlib?", which fails if
the GUI portion is loaded dynamically).

>> A less obvious example is a program designed to use whatever interface
>> facilities are available. E.g. XEmacs can use either a terminal or a GUI
>> or both.
> 
> And yet it manages this just fine, without Amiga-style invocation hacks, on 
> more rationally-designed operating systems. How is that?

Typically by not letting you usefully run terminal-based programs from
the GUI without first having to explicitly configure the invocation
options (e.g. creating a shortcut with "Use terminal" enabled).

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


Re: Python changes

2010-10-28 Thread Teenan
On Thu, 2010-10-28 at 15:03 -0400, Craig McRoberts wrote:
> Thanks for the prompt replies. Sounds like it's time to hit a bookstore.
> 
> Craig McRoberts

You could do a lot worse than getting 'Dive into Python' (There's even a
nice new version just for python 3.0)

hmmm bookstore.. those are the things they had before Amazon right? ;)


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


Re: Python changes

2010-10-28 Thread Craig McRoberts
Thanks for the prompt replies. Sounds like it's time to hit a bookstore.

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread Arnaud Delobelle
"cbr...@cbrownsystems.com"  writes:

> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
> doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> doSomething
>
> Is there a better pythonic idiom for this situation?

The latter can be written more concisely:

if any(d in days_off for d in ['monday', 'tuesday']):
# do something

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


Re: Python changes

2010-10-28 Thread Neil Cerutti
On 2010-10-28, Craig McRoberts  wrote:
> First off, greetings from a newbie!
>
> Here's the deal. I gained a passable knowledge of Python nearly
> ten years ago. Then I decided a career in the computer sciences
> wasn't for me, and I let it go. Now I find myself back in the
> development arena, and I'd like to pick up Python again. How
> much has it changed in my ten years' absence? I've already
> resigned myself to starting over from the beginning, but are my
> books from that time period even worth using now?
>
> Thanks so much.

Ten years ago puts around the time of Python 2.1. Your books are
indeed useless.

Python's documentation contains an excellent summary of new
features and changes dating back to Python 2.0.

http://docs.python.org/py3k/whatsnew/index.html

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


Re: How on Factorial

2010-10-28 Thread Arnaud Delobelle
Stefan Behnel  writes:

> karmaguedon, 28.10.2010 18:46:
>> On 27 oct, 10:27, Arnaud Delobelle wrote:
>>> Chris Rebert writes:
 This is stunt coding / code golf; no one should actually write
 factorial like that.
>>>
>>> True.  It's far too verbose.  I'd go for something like:
>>>
>>>  f=lambda n:n<=0 or n*f(~-n)
>>>
>>> I've saved a few precious keystrokes and used the very handy ~-
>>> idiom!
>>
>> I didn't know the idiom, nice tip.
>
> Not really. Given that many people won't know it, most readers will
> have a hard time deciphering the above code, so it's best not to do
> this.
>
> Stefan

My reply was obviously tongue in cheek, triggered by Chris Rebert's
"code golf" remark.  using ~-n instead of n-1 if obfuscatory and doesn't
even save keystrokes!  (Although it could in other situations, e.g
2*(n-1) can be written 2*~-n, saving two brackets.)

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


Re: Python changes

2010-10-28 Thread Seebs
On 2010-10-28, Craig McRoberts  wrote:
>I've already resigned
>myself to starting over from the beginning, but are my books from
>that time period even worth using now?

Impression I get is mostly "no".  I think you'll find life overall a lot
better now, though.  Programming languages tend to improve, with some
very notable exceptions.  :P

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread Adam Tauno Williams
On Thu, 2010-10-28 at 10:06 -0700, namekuseijin wrote: 
> On 28 out, 07:02, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:
> > Alain Ketterlin  writes:
> > > Lawrence D'Oliveiro  writes:
> >  Would it be right to say that the only Lisp still in common use is the
> >  Elisp built into Emacs?
> > >>> There is a new version of Lisp called Clojure that runs on the Java
> > >>> Virtual Machine (JVM) that is on the upswing.
> > >> Now is not exactly a good time to build new systems crucially dependent 
> > >> on
> > >> the continuing good health of Java though, is it?
> > > Nonsense. See
> > >http://blogs.sun.com/theaquarium/entry/ibm_and_oracle_to_collaborate
> > Last time I remember a corporation having developed a nice software
> > (NeXTSTEP), Sun joined it to make an "OpenStep", and a few years alter
> > it was over, bought by Apple, and morphed into MacOSX, and none of my
> > NeXTSTEP (or even OpenStep) programs compile anymore on my computers.
> > In the meantime, I switched to Linux.
> great, now you can use GNUStep:
> http://gnustep.org/

Heh, and good luck.  Compatibility between different implementations
stinks, and compatibility between different versions of GNUstep stinks.
And the documentation is hilariously terrible.

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


Python changes

2010-10-28 Thread Craig McRoberts
First off, greetings from a newbie!

Here's the deal. I gained a passable knowledge of Python nearly ten years ago. 
Then I decided a career in the computer sciences wasn't for me, and I let it 
go. Now I find myself back in the development arena, and I'd like to pick up 
Python again. How much has it changed in my ten years' absence? I've already 
resigned myself to starting over from the beginning, but are my books from that 
time period even worth using now?

Thanks so much.

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


PHP MySQL Web Development - Why Do You Need a PHP & MySQL ...

2010-10-28 Thread neha shena
PHP MySQL Web Development - Why Do You Need a PHP & MySQL ...

20 Aug 2010 ... PHP is web development language. PHP stands for
Hypertext Preprocessor. MySQL is an opensource, SQL Relational
Database Management System ...

http://childschooledu.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How on Factorial

2010-10-28 Thread Stefan Behnel

karmaguedon, 28.10.2010 18:46:

On 27 oct, 10:27, Arnaud Delobelle wrote:

Chris Rebert writes:

On Tue, Oct 26, 2010 at 11:25 PM, Geobird wrote:



  I  am a beginner in Python and would ask for a help.



I  was searching for  smaller  version  of  code  to calculate
factorial . Found  this one
def fact(x):
return x>  1 and x * fact(x - 1) or 1



  But I don't  really get how (  x>  1 and x * fact(x - 1))
works .



It exploits short-circuit evaluation
(http://en.wikipedia.org/wiki/Short-circuit_evaluation). This is
stunt coding / code golf; no one should actually write factorial like
that.


True.  It's far too verbose.  I'd go for something like:

 f=lambda n:n<=0 or n*f(~-n)

I've saved a few precious keystrokes and used the very handy ~- idiom!


I didn't know the idiom, nice tip.


Not really. Given that many people won't know it, most readers will have a 
hard time deciphering the above code, so it's best not to do this.


Stefan

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread cbr...@cbrownsystems.com
On Oct 28, 10:05 am, Chris Rebert  wrote:
> On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com
>
>
>
>  wrote:
> > On Oct 28, 9:23 am, John Posner  wrote:
> >> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>
> >> > It's clear but tedious to write:
>
> >> > if 'monday" in days_off or "tuesday" in days_off:
> >> >      doSomething
>
> >> > I currently am tending to write:
>
> >> > if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> >> >      doSomething
>
> >> > Is there a better pythonic idiom for this situation?
>
> >> Clunky, but it might prompt you to think of a better idea: convert the
> >> lists to sets, and take their intersection.
>
> >> -John
>
> > I thought of that as well, e.g.:
>
> > if set(["monday,"tuesday']).intersection(set(days_off)):
> >    doSomething
>
> > but those extra recasts to set() make it unaesthetic to me; and worse
>
> Why not make days_off a set in the first place? Isn't it,
> conceptually, a set of days off?

That makes sense in my example situation; but often this construct
appears on the fly when the list is a preferred to be a list for other
reasons.

>
> > if not set(["monday,"tuesday']).isdisjoint(set(days_off)):
> >    doSomething
>
> > is bound to confuse most readers.
>
> This way is more straightforward:
>
> if set(["monday", "tuesday"]) & days_off:
>

That's much nicer, even if I have to recast days_off as set(days_off).

Cheers - Chas

> Cheers,
> Chris
> --http://blog.rebertia.com

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread nn
On Oct 28, 12:33 pm, "cbr...@cbrownsystems.com"
 wrote:
> On Oct 28, 9:23 am, John Posner  wrote:
>
>
>
> > On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>
> > > It's clear but tedious to write:
>
> > > if 'monday" in days_off or "tuesday" in days_off:
> > >      doSomething
>
> > > I currently am tending to write:
>
> > > if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> > >      doSomething
>
> > > Is there a better pythonic idiom for this situation?
>
> > Clunky, but it might prompt you to think of a better idea: convert the
> > lists to sets, and take their intersection.
>
> > -John
>
> I thought of that as well, e.g.:
>
> if set(["monday,"tuesday']).intersection(set(days_off)):
>     doSomething
>
> but those extra recasts to set() make it unaesthetic to me; and worse
>
> if not set(["monday,"tuesday']).isdisjoint(set(days_off)):
>     doSomething
>
> is bound to confuse most readers.
>
> Cheers - Chjas

If you have Python 2.7 or newer you don't need to recast:

if {"monday", "tuesday"}.intersection(days_off): doSomething

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


Re: Land Of Lisp is out

2010-10-28 Thread namekuseijin
On 27 out, 21:55, Lawrence D'Oliveiro  wrote:
> Would it be right to say that the only Lisp still in common use is the Elisp
> built into Emacs?

Perhaps you should ask Google's Peter Norvig...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread namekuseijin
On 28 out, 07:02, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> Alain Ketterlin  writes:
> > Lawrence D'Oliveiro  writes:
>
>  Would it be right to say that the only Lisp still in common use is the
>  Elisp built into Emacs?
>
> >>> There is a new version of Lisp called Clojure that runs on the Java
> >>> Virtual Machine (JVM) that is on the upswing.
>
> >> Now is not exactly a good time to build new systems crucially dependent on
> >> the continuing good health of Java though, is it?
>
> > Nonsense. See
> >http://blogs.sun.com/theaquarium/entry/ibm_and_oracle_to_collaborate
>
> Last time I remember a corporation having developed a nice software
> (NeXTSTEP), Sun joined it to make an "OpenStep", and a few years alter
> it was over, bought by Apple, and morphed into MacOSX, and none of my
> NeXTSTEP (or even OpenStep) programs compile anymore on my computers.
>
> In the meantime, I switched to Linux.

great, now you can use GNUStep:

http://gnustep.org/

:D

> So now IBM and Oracle join to make an OpenJDK?  

java is sinking, soon enough java programmers will be as rare and well
paid as COBOLlers...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com
 wrote:
> On Oct 28, 9:23 am, John Posner  wrote:
>> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>>
>> > It's clear but tedious to write:
>>
>> > if 'monday" in days_off or "tuesday" in days_off:
>> >      doSomething
>>
>> > I currently am tending to write:
>>
>> > if any([d for d in ['monday', 'tuesday'] if d in days_off]):
>> >      doSomething
>>
>> > Is there a better pythonic idiom for this situation?
>>
>> Clunky, but it might prompt you to think of a better idea: convert the
>> lists to sets, and take their intersection.
>>
>> -John
>
> I thought of that as well, e.g.:
>
> if set(["monday,"tuesday']).intersection(set(days_off)):
>    doSomething
>
> but those extra recasts to set() make it unaesthetic to me; and worse

Why not make days_off a set in the first place? Isn't it,
conceptually, a set of days off?

> if not set(["monday,"tuesday']).isdisjoint(set(days_off)):
>    doSomething
>
> is bound to confuse most readers.

This way is more straightforward:

if set(["monday", "tuesday"]) & days_off:

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread namekuseijin
On 28 out, 06:46, Xah Lee  wrote:
> lol. He said REAL!
>
> how about the 10 Scheme Lisps on JVM? guess they are UNREAL. lol

you know only CL is the real lisp and schmers are just zanny time-
travelling folks as the webcomic depict. :p

> btw, who cross posted this thread to python? i call troll!

glad to be of help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Runtime Error

2010-10-28 Thread Sebastian

Hi all,

I am new to python and I don't know how to fix this error. I only try to 
execute python (or a cgi script) and I get an ouptu like


[...]
'import site' failed; traceback:
Traceback (most recent call last):
File "/usr/lib/python2.6/site.py", line 513, in 
main()
File "/usr/lib/python2.6/site.py", line 496, in main
known_paths = addsitepackages(known_paths)
File "/usr/lib/python2.6/site.py", line 288, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
File "", line 1, in 
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
File "", line 1, in 
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
[...]
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
File "", line 1, in 
File "/usr/lib/python2.6/site.py", line 175, in addsitedir
sitedir, sitedircase = makepath(sitedir)
File "/usr/lib/python2.6/site.py", line 76, in makepath
dir = os.path.abspath(os.path.join(*paths))
RuntimeError: maximum recursion depth exceeded


What is going wrong with my python install? What do I have to change?

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


Re: How on Factorial

2010-10-28 Thread karmaguedon
On 27 oct, 10:27, Arnaud Delobelle  wrote:
> Chris Rebert  writes:
> > On Tue, Oct 26, 2010 at 11:25 PM, Geobird  wrote:
>
> >>  I  am a beginner in Python and would ask for a help.
>
> >> I  was searching for  smaller  version  of  code  to calculate
> >> factorial . Found  this one
> >> def fact(x):
> >>        return x > 1 and x * fact(x - 1) or 1
>
> >>  But I don't  really get how (  x > 1 and x * fact(x - 1))
> >> works .
>
> > It exploits short-circuit evaluation
> > (http://en.wikipedia.org/wiki/Short-circuit_evaluation). This is
> > stunt coding / code golf; no one should actually write factorial like
> > that.
>
> True.  It's far too verbose.  I'd go for something like:
>
>     f=lambda n:n<=0 or n*f(~-n)
>
> I've saved a few precious keystrokes and used the very handy ~- idiom!
>
> --
> Arnaud

I didn't know the idiom, nice tip.
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread Chris Kaynor
On Thu, Oct 28, 2010 at 9:16 AM, cbr...@cbrownsystems.com <
cbr...@cbrownsystems.com> wrote:

> It's clear but tedious to write:
>
> if 'monday" in days_off or "tuesday" in days_off:
>doSomething
>
> I currently am tending to write:
>
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
>doSomething
>

A slightly cleaner form would be:

if any(day in days_off for day in ['Monday', 'Tuesday']):


To make that a bit easier to read:
if any((day in days_off) for day in ['Monday', 'Tuesday']):



>
> Is there a better pythonic idiom for this situation?
>
> Cheers - Chas
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread cbr...@cbrownsystems.com
On Oct 28, 9:23 am, John Posner  wrote:
> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:
>
> > It's clear but tedious to write:
>
> > if 'monday" in days_off or "tuesday" in days_off:
> >      doSomething
>
> > I currently am tending to write:
>
> > if any([d for d in ['monday', 'tuesday'] if d in days_off]):
> >      doSomething
>
> > Is there a better pythonic idiom for this situation?
>
> Clunky, but it might prompt you to think of a better idea: convert the
> lists to sets, and take their intersection.
>
> -John

I thought of that as well, e.g.:

if set(["monday,"tuesday']).intersection(set(days_off)):
doSomething

but those extra recasts to set() make it unaesthetic to me; and worse

if not set(["monday,"tuesday']).isdisjoint(set(days_off)):
doSomething

is bound to confuse most readers.

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


Runtime error

2010-10-28 Thread Sebastian

Hi all,

I am new to python and I don't know how to fix this error. I only try to 
execute python (or a cgi script) and I get an ouptu like


[...]
'import site' failed; traceback:
Traceback (most recent call last):
File "/usr/lib/python2.6/site.py", line 513, in 
main()
File "/usr/lib/python2.6/site.py", line 496, in main
known_paths = addsitepackages(known_paths)
File "/usr/lib/python2.6/site.py", line 288, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
File "", line 1, in 
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
File "", line 1, in 
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
[...]
File "/usr/lib/python2.6/site.py", line 185, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/python2.6/site.py", line 155, in addpackage
exec line
File "", line 1, in 
File "/usr/lib/python2.6/site.py", line 175, in addsitedir
sitedir, sitedircase = makepath(sitedir)
File "/usr/lib/python2.6/site.py", line 76, in makepath
dir = os.path.abspath(os.path.join(*paths))
RuntimeError: maximum recursion depth exceeded


What is going wrong with my python install? What do I have to change?

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


Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread John Posner

On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote:

It's clear but tedious to write:

if 'monday" in days_off or "tuesday" in days_off:
 doSomething

I currently am tending to write:

if any([d for d in ['monday', 'tuesday'] if d in days_off]):
 doSomething

Is there a better pythonic idiom for this situation?



Clunky, but it might prompt you to think of a better idea: convert the 
lists to sets, and take their intersection.


-John



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


Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread cbr...@cbrownsystems.com
It's clear but tedious to write:

if 'monday" in days_off or "tuesday" in days_off:
doSomething

I currently am tending to write:

if any([d for d in ['monday', 'tuesday'] if d in days_off]):
doSomething

Is there a better pythonic idiom for this situation?

Cheers - Chas

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


Re: Land Of Lisp is out

2010-10-28 Thread kodifik
On Oct 28, 3:24 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> .
> On the other hand, AutoCAD allow people to customize it using other
> programming languages than AutoLisp, so I wouldn't expect it to be
> majoritary.

It is just a guess of the relative number of users.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding python in macOS 10.6

2010-10-28 Thread Aahz
[posted & e-mailed]

In article ,
tinau...@libero.it  wrote:
>
>i'm trying to embed python in a c++ code.i'm starting with the example in the 
>tutorial.i've problem with setting up the enveiroment.
>I've installed python with the distributed version (i.e., i did not, as a 
>start, build it myself); i added the library where both python.h and pyconfig 
>are stored and i linked to libpython2.6.a (which is, in the distributed 
>version, an alias).

For Mac you probably want to build Python yourself, but I'm certainly not
an expert.  If you still haven't figured it out, try pythonmac-sig.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using nested lists and tables

2010-10-28 Thread Peter Otten
Zeynel wrote:

> Thank you this is great; but I don't know how to modify this code so
> that when the user types the string 's' on the form in the app he sees
> what he is typing. So, this will be in GAE. 

I've no idea what GAE is. In general the more precise your question is the 
better the answers tend to be. Don't make your readers guess. 

 for row in range(max(len(c) for c in columns)):
>> ... print " | ".join(c[row] if len(c) > row else " "*len(c[0]) for c
>> in columns)
> 
> What is "c" here?
 
Sorry, I was trying to do too much in a single line.

result = [c for c in columns]

is a way to iterate over a list. It is roughly equivalent to

result = []
for c in columns:
result.append(c)

Then, if columns is a list of lists of strings 'c' is a list of strings. 
You normally don't just append the values as you iterate over them, you do 
some calculation. For example

column_lengths = [len(c) for c in columns]

would produce a list containing the individual lengths of the columns.

A simpler and more readable version of the above snippet from the 
interactive python session is

columns = [
['abc', 'abc', 'abc'],
['xy', 'xy'],
["that's all, folks"]]

column_lengths = [len(column) for column in columns]
num_rows = max(column_lengths)
for row_index in range(num_rows):
row_data = []
for column in columns:
# check if there is a row_index-th row in the
# current column
if len(column) > row_index:
value = column[row_index]
else:
# there is no row_index-th row for this
# column; use the appropriate number of
# spaces instead
value = " " * len(column[0])
row_data.append(value)
print " | ".join(row_data)




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


Re: minimal D: need software testers

2010-10-28 Thread Kruptein
On Oct 26, 4:24 pm, a...@pythoncraft.com (Aahz) wrote:
> [posted & e-mailed]
>
> In article 
> <43bd55e3-e924-40b5-a157-b57ac8544...@f25g2000yqc.googlegroups.com>,
>
> Kruptein   wrote:
>
> >I've released the second alpha forminimal-Da program I've written in
> >python which should make developing easier.
> >I need people to test the app on bugs and give ideas.
>
> You should probably explain whatminimal-Dis, I'm certainly not going to
> look at something when I have no clue.
> --
> Aahz (a...@pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> "If you think it's expensive to hire a professional to do the job, wait
> until you hire an amateur."  --Red Adair

Well the problem is that it's hard to give a strict definition to the
application. It is kind of a framework that let the user experience,
the, in
my opinion, easiest way to combine a text-editor,file-manager,ftp and
sql,...  in one window.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How on Factorial

2010-10-28 Thread Xavier Ho
On 29 October 2010 00:13, Dave Angel  wrote:

> From the help:
>
> "The unary ~ (invert) operator yields the bitwise inversion of its plain or
> long integer argument. The bitwise inversion of x is defined as -(x+1). It
> only applies to integral numbers"
>
> Inverting the bits of a floating point number wouldn't make much sense, so
> fortunately it gives an error.
>
> DaveA
>

Very cool, Dave. Thanks for looking that up. =]

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


Re: Land Of Lisp is out

2010-10-28 Thread Emile van Sebille

On 10/28/2010 1:46 AM Xah Lee said...

btw, who cross posted this thread to python? i call troll!

  Xah


+1 QOTW

:)




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


Re: How on Factorial

2010-10-28 Thread Dave Angel

On 10/28/2010 10:01 AM, Xavier Ho wrote:

On 28 October 2010 23:52, Dave Angel  wrote:


The ~- trick only works on two's complement numbers.  I've worked on
machines in the past that used one's complement, and this wouldn't work
there.

DaveA


I imagine this wouldn't work on floating point numbers either.

Cheers,
Xav


From the help:

"The unary ~ (invert) operator yields the bitwise inversion of its plain 
or long integer argument. The bitwise inversion of x is defined as 
-(x+1). It only applies to integral numbers"


Inverting the bits of a floating point number wouldn't make much sense, 
so fortunately it gives an error.


DaveA

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


Re: How on Factorial

2010-10-28 Thread Xavier Ho
On 28 October 2010 23:52, Dave Angel  wrote:

> The ~- trick only works on two's complement numbers.  I've worked on
> machines in the past that used one's complement, and this wouldn't work
> there.
>
> DaveA
>

I imagine this wouldn't work on floating point numbers either.

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


Re: Tkinter: how to create (modal) dialogs a la tk_dialog?

2010-10-28 Thread Olaf Dietrich
Peter Otten <__pete...@web.de>:
> Olaf Dietrich wrote:
> 
>> I'm stuck with a probably simple task: How can I create
>> a user defined dialog (similar to tkFileDialog.askdirectory(),
>> but with my own set of options/selections)?
> 
> Have a look at the SimpleDialog module. A usage example is at the end of the 
> file:

Thanks, that's sufficiently close to what I was looking
for (in particular after changing the layout to vertically
packed buttons). Could it be that these parts of Tkinter
are not particularly extensively documented? (Or am I searching
with the wrong expressions?)

Is there also any "template" dialog that works with a listbox
instead of buttons (or is more similar to the file dialogs)?

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


Re: How on Factorial

2010-10-28 Thread Dave Angel

On 2:59 PM, Xavier Ho wrote:

On 27 October 2010 18:27, Arnaud Delobelle  wrote:


True.  It's far too verbose.  I'd go for something like:

f=lambda n:n<=0 or n*f(~-n)

I've saved a few precious keystrokes and used the very handy ~- idiom!


Huh, I've never seen that one before. Seems to work on both positive and
negative numbers. Is there a caveat to this?

Cheers,
Xav

The ~- trick only works on two's complement numbers.  I've worked on 
machines in the past that used one's complement, and this wouldn't work 
there.


DaveA

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


Re: Using nested lists and tables

2010-10-28 Thread Zeynel
On Oct 28, 9:35 am, Iain King  wrote:
> It's equivalent to:
>
> if columns:
>     if columns[-1][0] == s:
>         dostuff()
>
> i.e. check columns is not empty and then check if the last item
> startswith 's'.

Thanks!

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


Re: Using nested lists and tables

2010-10-28 Thread Iain King
On Oct 28, 2:35 pm, Iain King  wrote:
...
> (a) I don't know if the order of resolution is predicated left-to-
> right in the language spec of if it's an implementation detail
> (b) columns[-1].startswith('s') would be better
>
...

Ignore (b), I didn't read the original message properly.

Iain


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


Re: Using nested lists and tables

2010-10-28 Thread Iain King
On Oct 28, 2:19 pm, Zeynel  wrote:
> On Oct 28, 4:49 am, Peter Otten <__pete...@web.de> wrote:
>
> Thank you this is great; but I don't know how to modify this code so
> that when the user types the string 's' on the form in the app he sees
> what he is typing. So, this will be in GAE. But I have a couple of
> other questions, for learning purposes. Thanks again, for the help.
>
> > ...     if columns and columns[-1][0] == s:
>
> Here, how do you compare "columns" (a list?) and columns[-1][0] (an
> item in a list)?
>

It's equivalent to:

if columns:
if columns[-1][0] == s:
dostuff()

i.e. check columns is not empty and then check if the last item
startswith 's'.

(a) I don't know if the order of resolution is predicated left-to-
right in the language spec of if it's an implementation detail
(b) columns[-1].startswith('s') would be better

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


Re: Using nested lists and tables

2010-10-28 Thread Zeynel
On Oct 28, 2:32 am, robert  wrote:
> the reason may be that your text doesn't contain a question (mark).
...
> perhaps drill down to a question on python-level.

Thanks, I realize that what I was trying to ask is not too clear. I am
learning to GAE using Python and I want to deploy a simple app. The
app will have a form. The user enters a sentence to the form and
presses enter. The sentence is displayed. The user types in the same
sentence; the sentence is displayed on the same column; the user types
in a different sentence; the different sentence is displayed on the
next column; as long as the user types in the same sentence; the
sentence is displayed on the same column; otherwise it is displayed on
the next column.

Maybe nested lists are not the right tool for this. Any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Land Of Lisp is out

2010-10-28 Thread Pascal J. Bourguignon
kodifik  writes:

> On Oct 28, 1:55 am, Lawrence D'Oliveiro  central.gen.new_zealand> wrote:
>> Would it be right to say that the only Lisp still in common use is the Elisp
>> built into Emacs?
>
> Surely surpassed by autolisp (a xlisp derivative inside the Autocad
> engineering software).

I wouldn't bet.  With emacs, you don't have a choice, you need to use
emacs lisp to customize it (even if theorically you could do it with
emacs-cl or some other language implementation written in emacs lisp).

On the other hand, AutoCAD allow people to customize it using other
programming languages than AutoLisp, so I wouldn't expect it to be
majoritary.

-- 
__Pascal Bourguignon__ http://www.informatimago.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using nested lists and tables

2010-10-28 Thread Zeynel
On Oct 28, 4:49 am, Peter Otten <__pete...@web.de> wrote:

Thank you this is great; but I don't know how to modify this code so
that when the user types the string 's' on the form in the app he sees
what he is typing. So, this will be in GAE. But I have a couple of
other questions, for learning purposes. Thanks again, for the help.

> ...     if columns and columns[-1][0] == s:

Here, how do you compare "columns" (a list?) and columns[-1][0] (an
item in a list)?

>>> for row in range(max(len(c) for c in columns)):
> ...     print " | ".join(c[row] if len(c) > row else " "*len(c[0]) for c in
> columns)

What is "c" here?

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


Re: Land Of Lisp is out

2010-10-28 Thread kodifik
On Oct 28, 1:55 am, Lawrence D'Oliveiro  wrote:
> Would it be right to say that the only Lisp still in common use is the Elisp
> built into Emacs?

Surely surpassed by autolisp (a xlisp derivative inside the Autocad
engineering software).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml : remove a node with dom

2010-10-28 Thread alain walter
Hi,
You're right for my post code : I extract it from a more complicated
context.
However, the solution you propose produce the line  not a blank line.
Finally, I've found a good solution by using :

from xml.dom.ext import PrettyPrint
from xml.dom.ext.reader.Sax2 import FromXmlStream

dom = FromXmlStream("my_file")
testRemoving(dom)
PrettyPrint(dom)

def testRemoving(self,dom) :
for node1 in dom.childNodes:
if node1.nodeType == node1.ELEMENT_NODE:
for node in node1.childNodes:
if node.nodeValue == "xxx_toremove_xxx":
dom.removeChild(node1)
testRemoving(node1)



On 28 oct, 13:47, de...@web.de (Diez B. Roggisch) wrote:
> alain walter  writes:
> > Hello,
> > I have many difficulties to manipulate xml routines. I'm working with
> > python 2.4.4 and I cannot change to a more recent one, then I use dom
> > package, why not.
> > In the following code, I'm trying unsuccessfully to remove a
> > particular node. It seems to me that it should be basic, but it's
> > not.
> > Thanks for your help
>
> If you post code, make an attempt for it to be runnable. I had to fix
> numerous simple errors to make it run & actually solve your problem.
>
> from xml.dom.minidom import parse,parseString
> from xml.dom import Node
>
> toxml="""
> 
>    ABB
>       ABB
>       
>          -51.23 4.6501
>          xxx_toremove_xxx
>       
> """
>
> dom = parseString(toxml)
>
> def ApplicationWhitespaceRemoving(ele) :
>    for c in ele.childNodes:
>       if c.nodeType == c.TEXT_NODE:
>          if c.nodeValue == "xxx_toremove_xxx":
>              parent = c.parentNode
>              parent.removeChild(c)
>       elif c.nodeType == ele.ELEMENT_NODE:
>          ApplicationWhitespaceRemoving(c)
>
> ApplicationWhitespaceRemoving(dom)
>
> print dom.toxml()
>
> --
>
> Diez

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


Re: xml : remove a node with dom

2010-10-28 Thread Stefan Behnel

alain walter, 28.10.2010 11:37:

dom = parseString(toxml)
self.ApplicationWhitespaceRemoving(dom)
print toxml

def ApplicationWhitespaceRemoving(self,ele) :
from xml.dom import Node
for c in ele.childNodes:
   if c.nodeType == c.TEXT_NODE:
  if c.nodeValue == "xxx_toremove_xxx":
 ???.removeChild(???)
   elif c.nodeType == ele.ELEMENT_NODE:
  self.ApplicationWhitespaceRemoving(c)


Just a comment on code style here. Functions and procedures should have 
names that strongly refer to a descriptive verb, consequently starting with 
a lower case letter by convention. So a better name for your procedure 
above could be "removeApplicationSpecificWhitespace".


When using constants defined on a module or class, try to refer to them in 
a consistent way, either by importing the names globally into your module 
namespace, or by referencing them from the same namespace (e.g. class 
object) everywhere. Simple, recurrent patterns help in reading your code.


Then, I don't see what the "Node" import is used for, and it looks like 
your function is actually a method (called as self.xxx). When presenting 
code snippets, try to make them consistent, or make it clear that (and 
where) things are missing.


Hope that helps,

Stefan

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


wxpython 2.8 -- timing and latency issues when displaying widgets

2010-10-28 Thread Josef Frank


Dear all,

in an application window (subwindow of a Notebook-control) I'm trying to 
do the following:


1. Create a StaticText control kind of "Please wait until processing has 
finished"

2. Do some processing (e.g. vacuuming an sqlite database)
3. Create a 2nd StaticText control with the message "processing finished"

Naïvely I would expect following behavior:

1st control appears
data processing step runs
after finishing processing the 2nd control appears

but actually the order in execution seems to be a different one:

computer is doing heavy processing
1st control appears
2nd control appears immediately after the 1st without any visible delay

Could someone give a hint, how to change the seeming behavior into the 
intended one?


Thanks in advance Josef

P.S.:
here is the actual code snippet:

def OnVacuum(self,event):
panel=Ntab(self.desktop,"Compact")
	message1=wx.StaticText(panel,-1,"Please wait, database is being 
compacted.",(20,10))

self.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
con=sqlite3.connect(dbname)
cur=con.cursor()
cur.execute("VACUUM;")
cur.close()
con.close()
self.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
	message2=wx.StaticText(panel,-1,"Compacting database has now 
finished",(20,30))


Ntab is a class derived from wx.Panel and a tab of the abovementioned 
wx.Notebook control

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


Re: xml : remove a node with dom

2010-10-28 Thread Diez B. Roggisch
alain walter  writes:

> Hello,
> I have many difficulties to manipulate xml routines. I'm working with
> python 2.4.4 and I cannot change to a more recent one, then I use dom
> package, why not.
> In the following code, I'm trying unsuccessfully to remove a
> particular node. It seems to me that it should be basic, but it's
> not.
> Thanks for your help

If you post code, make an attempt for it to be runnable. I had to fix
numerous simple errors to make it run & actually solve your problem.

from xml.dom.minidom import parse,parseString
from xml.dom import Node


toxml="""

   ABB
  ABB
  
 -51.23 4.6501
 xxx_toremove_xxx
  
"""


dom = parseString(toxml)

def ApplicationWhitespaceRemoving(ele) :
   for c in ele.childNodes:
  if c.nodeType == c.TEXT_NODE:
 if c.nodeValue == "xxx_toremove_xxx":
 parent = c.parentNode
 parent.removeChild(c)
  elif c.nodeType == ele.ELEMENT_NODE:
 ApplicationWhitespaceRemoving(c)


ApplicationWhitespaceRemoving(dom)

print dom.toxml()

--

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


Re: parsing of structured text

2010-10-28 Thread Robert Fendt
On 28 Okt., 05:59, Kushal Kumaran 
wrote:

> Using code someone else has already written would qualify as pythonic, IMO.
>
> http://pypi.python.org/pypi/vobject

That seems to do what I need, thank you. I seem to have been a bit
blind when I looked for existing packages. Of course, using vobject
"only" works efficiently around my problem (i.e., how to formulate
such a parser in the most simple/elegant/pythonic way). ;-)

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


Re: 'NoneType' object has no attribute 'bind'

2010-10-28 Thread Alex Willmer
On Oct 28, 11:24 am, Alex  wrote:
> hi there, I keep getting the message in the Topic field above.
>
> Here's my code:
>
> self.click2=Button(root,text="Click Me").grid(column=4,row=10)
> self.click2.bind("",self.pop2pop)

>From reading the Tkinter docs grid doesn't itself return a control. So
I think you want this:

self.click2 = Button(root, text="Click Me")
self.click2.grid(column=4, row=10)
self.click2.bind("", self.pop2pop)

However, that's totally untested so don't take it as gospel.

> def pop2pop(self,event):
>
>         print("Adsfadsf")
>         newpop=IntVar()
>         newpop=self.PopSize.get();
>
> what am I doing wrong?
>
> cheers,
>
> Alex

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


Re: 'NoneType' object has no attribute 'bind'

2010-10-28 Thread Peter Otten
Alex wrote:

> hi there, I keep getting the message in the Topic field above.
> 
> Here's my code:
> 
> self.click2=Button(root,text="Click Me").grid(column=4,row=10)

Replace the above line to

button = Button(root, text="Click Me")
print "Button() returns", button
grid = button.grid(column=4, row=10)
print ".grid() returns", grid
self.click2 = button

and be enlighted. Then remove the print statements.

> self.click2.bind("",self.pop2pop)
> 
> def pop2pop(self,event):
> 
> print("Adsfadsf")
> newpop=IntVar()
> newpop=self.PopSize.get();
> 
> 
> what am I doing wrong?

If one step doesn't work try to replace it with smaller steps and add print 
statements to find the part that doesn't do what you expected.

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



Re: 'NoneType' object has no attribute 'bind'

2010-10-28 Thread Xavier Ho
On 28 October 2010 20:24, Alex  wrote:

> hi there, I keep getting the message in the Topic field above.
>
> Here's my code:
>
> self.click2=Button(root,text="Click Me").grid(column=4,row=10)
> self.click2.bind("",self.pop2pop)
> what am I doing wrong?
>

Try

self.click2=Button(root,text="Click Me")
self.click2.grid(column=4,row=10)
self.click2.bind("",self.pop2pop)

Chances are, the grid() method modifies the object in-place without
returning a self reference. This is a common getcha.

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


'NoneType' object has no attribute 'bind'

2010-10-28 Thread Alex
hi there, I keep getting the message in the Topic field above.

Here's my code:

self.click2=Button(root,text="Click Me").grid(column=4,row=10)
self.click2.bind("",self.pop2pop)

def pop2pop(self,event):

print("Adsfadsf")
newpop=IntVar()
newpop=self.PopSize.get();


what am I doing wrong?

cheers,

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


Re: How on Factorial

2010-10-28 Thread Xavier Ho
On 27 October 2010 18:27, Arnaud Delobelle  wrote:

> True.  It's far too verbose.  I'd go for something like:
>
>f=lambda n:n<=0 or n*f(~-n)
>
> I've saved a few precious keystrokes and used the very handy ~- idiom!
>

Huh, I've never seen that one before. Seems to work on both positive and
negative numbers. Is there a caveat to this?

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


Re: How on Factorial

2010-10-28 Thread Bj Raz
I'm working on some factorial stuff myself, and I'm running into that issue
that the CPU or ALU (Algorithmic Logical Unit), isn't powerful enough to
compute the numbers I'm trying to produce, including the OS has its own
number crunching limitation for accuracy.

To accurately generate the numbers I want I'd probably need about 200+ 64
bit CPUs or ALUs, thats about 640,000 bit Long.  I can produce about 100
places of accuracy with my i7-950 I think.

@geobird or anyone: does someone have an idea of how to bridge this issue?

Here is what I have in MATLAB currently, I have heard of;
SAGE,
which I've heard is a good alternative to MATLAB.
Here is the script I have from MATLAB; http://pastebin.com/sc1jW1n4, it
takes the natural log of the number huge numbers being generated, and allows
you to work with gigantic numbers more easily.

I don't know how to write this naively into python though without being able
to call functions.
I'm working with differential equations related the the higher roots of -1
(negative one).

On Wed, Oct 27, 2010 at 5:13 AM, Jussi Piitulainen <
jpiit...@ling.helsinki.fi> wrote:

> Geobird writes:
>
> > @ Ulrich : Tx
> > @ Rebert : Appreciate your interpretation.
> >It  made  me think about ternary operation . Say
> >  >>> (a > b) and x or y
> >
> >Are all ternary operations prone to ...( in your words )
> >> It exploits short-circuit evaluation
> >>(http://en.wikipedia.org/wiki/Short-circuit_evaluation ). This is
> >>stunt coding / code golf; no one should actually write factorial
> > like
> >>that.
>
> The purpose of a conditional expression is to select one branch of
> computation and avoid another. Other ternary operations might well
> use the values of all three arguments.
>
> (I agree that no one should write factorial like that, except as
> a joke. I have nothing against (x if (a > b) else y). The trick
> with and and or was used before Python had an actual conditional
> expression.)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


xml : remove a node with dom

2010-10-28 Thread alain walter
Hello,
I have many difficulties to manipulate xml routines. I'm working with
python 2.4.4 and I cannot change to a more recent one, then I use dom
package, why not.
In the following code, I'm trying unsuccessfully to remove a
particular node. It seems to me that it should be basic, but it's
not.
Thanks for your help

toxml="
   ABB
  ABB
  
 -51.23 4.6501
 xxx_toremove_xxx
  
"

from xml.dom.minidom import parse,parseString

dom = parseString(toxml)
self.ApplicationWhitespaceRemoving(dom)
print toxml

def ApplicationWhitespaceRemoving(self,ele) :
   from xml.dom import Node
   for c in ele.childNodes:
  if c.nodeType == c.TEXT_NODE:
 if c.nodeValue == "xxx_toremove_xxx":
???.removeChild(???)
  elif c.nodeType == ele.ELEMENT_NODE:
 self.ApplicationWhitespaceRemoving(c)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is list comprehension necessary?

2010-10-28 Thread Xah Lee
On Oct 27, 5:46 pm, rantingrick  wrote:
> On Oct 26, 4:31 am, Xah Lee  wrote:
>
> > recently wrote a article based on a debate here. (can't find the
> > original thread on Google at the moment)
>
> Hey all you numbskulls who are contributing the annoying off-topic
> chatter about Report Lab need to...
>
> 1) GET A LIFE
> 2) START A NEW THREAD!

:)

when i saw the thread got quietly hijacked to about PDF... it was
funny. But yeah, they need to get a life.

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


  1   2   >