Re: Jython inherit from Java class

2006-02-11 Thread Mark Fink
Please enlighten me. This seemed so easy yust inherit from a Java class
overwrite one method - done. At the moment I do not know how to proceed
:-((
Jython or jythonc?
==
In general is it better to run programms with the jython interpreter or
is it better to compile them first? I had the impression that the
inheritance does not work with the interpreter. Is that right?

2.1 or 2.2a
===
The programm did not compile with the 2.1 version and Java 1.5. But
with 2.2a it compiled but 2.2a is an alpha version. Assuming the
programm would compile with the Java 1.4 version would it be better
(saver, more stable, performance) to use 2.1 or 2.2a?

Inherit from java baseclass or reimplement the whole thing in jython?
=
All the problems with Jython stated when I wanted to inherit from a
Java baseclass. I wounder if I would have more success when
implementing it in pure Jython. Regarding the inheritance I had an
empty wrapper arround the Java baseclass and 70% of the unit test
passed. But the performance was ~ factor 10 slower than using the base
class directly. Does this mean that there is overhead with the
inheritanc construct and that this implementation path would always be
so slow. On the other hand would a 100% Jython solution be faster?

Mark

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


Re: Scientific Computing with NumPy

2006-02-11 Thread linda.s
On 2/10/06, David M. Cooke <[EMAIL PROTECTED]> wrote:
> "linda.s" <[EMAIL PROTECTED]> writes:
>
> > where to download numpy for Python 2.3 in Mac?
> > Thanks!
> > Linda
>
> I don't know if anybody's specifically compiled for 2.3; I think most
> of the developers on mac are using 2.4 :-)
>
> But (assuming you have the developer tools installed) it's really to
> compile: python setup.py build && python setup.py install.
>
> Do you need Tiger (10.4) or Panther (10.3) compatibility?
>
> --
> |>|\/|<
> /--\
> |David M. Cooke
The confusing thing is python 2.3 comes with mac when you got the
machine. so we need numpy which is OK with python 2.3. is my
understanding right?
Linda
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-11 Thread Peter Hansen
John Salerno wrote:
> Can anyone tell me how complicated it might be to install Python on my 
> server so I can use it for web apps? Is it a one-time process, or 
> something to maintain?

I'm not sure what you would expect to maintain.  Do you expect some kind 
of "bit-rot" to occur, requiring you to periodically rewrite files 
in-place to refresh them (ala "core memory" of ages past)?  ;-)

Generally speaking one needs to maintain software only to upgrade or 
reconfigure it (e.g. adding a new package that you'd like to start using 
in your web apps).

-Peter

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread [EMAIL PROTECTED]
What's wrong with wxPython? (http://www.wxpython.org)
Didn't see it mentioned here.


David Berlin
http://farpy.holev.com - Python GUI Editor

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


Shortest prime number program

2006-02-11 Thread swisscheese
I figured someone out there must have written a minimal code size prime
number generator. I did not find one after a bit of searching around.
For primes up to 100 the best I could do was 70 characters (including
spaces):

r=range(2,99)
m=[x*y for x in r for y in r]
[x for x in r if not x in m]

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


Is there any books such as 'effective python' or else about the performance?

2006-02-11 Thread Kenneth Xie
att, thx.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Legality of using Fonts

2006-02-11 Thread Steven D'Aprano
On Fri, 10 Feb 2006 20:24:34 -0800, Ross Ridge wrote:

> Steven D'Aprano wrote:
>> It is highly unlikely that any judge will be fooled by a mere change in
>> format ("but Your Honour, I converted the TTF file into a bitmap").
> 
> If that were true, almost the entire X11 bitmap font collection would
> be illegal.  Fonts aren't subject copyright, just the hints in most
> outline fonts, which are considered computer programs.

This may come as a shock to you, but the USA is not the entire world, and
the US government's decision to exclude typefaces from copyright
protection is anomalous. In almost the entire rest of the world,
typefaces (the design of a font) are able to be copyrighted, and so are
fonts whether they are bitmapped or outline (with or without hints).


See, for example: http://www.typeright.org/feature4.html

In any case, even in the USA, hinted fonts are copyrightable, and merely
removing the hints (say, by converting to a bitmap) is no more legal than
whiting out the author's name from a book and claiming it as your own.

Of course, like all these issues, the actual decision of a judge and jury
in the USA is uncertain -- who knows whether they will consider a
bitmapped version of a TTF font to be a derivative work or not? So even in
the USA, unless you want to spend big dollars on legal fees, the best
advice is to stick to fonts which are distributed under open licences.



-- 
Steven.

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


Pyserial handobook

2006-02-11 Thread Zarathustra
Hi, where I can find the pyserial handbook??
THanks

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


Re: Scientific Computing with NumPy

2006-02-11 Thread Robert Kern
linda.s wrote:
> where to download numpy for Python 2.3 in Mac?

I don't think anybody has a binary package compiled for you. However, if you
have gcc installed, numpy should build out-of-box.

$ tar zcf ~/downloads/numpy-0.9.4.tar.gz
$ cd numpy-0.9.4
$ python setup.py build
$ sudo python setup.py install --install-scripts=/usr/local/bin

Note: the sudo in that last command is only necessary if your user account does
not have write access to /usr/local/bin

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Too Many if Statements?

2006-02-11 Thread Terry Reedy

"slogging_away" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> SystemError: com_backpatch: offset too large

This message is generated in the backpatch function in Python/compile.c in 
the source tree.  (See below: sorry, tab indents did not survive cut and 
paste operation.)  As the comment says, and the code shows, it patches in a 
2-byte jump offset.  The error is raised if the offset is not 0 after 
beinging divided by 256 twice (ie, by 65536).  This code is called from any 
function that compiles a construct that potentially jumps: for, while, 
if/elif, and short-circuiting logic expressions.

To me, this message indicates not a bug but a mismatch between code demand 
and interpreter capability.  The solution is to reduce the demand.  In the 
present case, changing

for line in file:
  

to

def checkline(line):
  
for line in file:
  checkline(line)

might be sufficient.  If not, break up the  into multiple 
pieces.

Terry Jan Reedy

static void
com_backpatch(struct compiling *c, int anchor)
{
unsigned char *code = (unsigned char *) PyString_AS_STRING(c->c_code);
int target = c->c_nexti;
int dist;
int prev;
for (;;) {
/* Make the JUMP instruction at anchor point to target */
prev = code[anchor] + (code[anchor+1] << 8);
dist = target - (anchor+2);
code[anchor] = dist & 0xff;
dist >>= 8;
code[anchor+1] = dist;
dist >>= 8;
if (dist) {
com_error(c, PyExc_SystemError,
"com_backpatch: offset too large");
break;
}
if (!prev)
break;
anchor -= prev;
}
}




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


Re: Shortest prime number program

2006-02-11 Thread Mitja Trampus
swisscheese wrote:
> I figured someone out there must have written a minimal code size prime
> number generator. I did not find one after a bit of searching around.
> For primes up to 100 the best I could do was 70 characters (including
> spaces):
> 
> r=range(2,99)
> m=[x*y for x in r for y in r]
> [x for x in r if not x in m]

A more straightforward and somewhat shorter solution:

r=range(2,99)
[x for x in r if [x%d for d in r].count(0)<2]

I'm sure it can be made shorter still.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting record with Microsoft Access

2006-02-11 Thread Frank Millman

Steve Holden wrote:
> Albert Leibbrandt wrote:
> >
> > jeffhg582003 wrote:
> >
> >
> >>Hi,
> >>
> >>I am developing a python script which add records to
> >>a microsoft access tables. All my tables have autogenerated number
> >>fields. I am trying to capture the number generated from the insert but
> >>I am not exactly sure how to do that after an insert.
> >>
> > I had to do something similiar in sql server and the experts back then
> > told me that the only way is to write a stored procedure. aparently sql
> > server does not have sequences and I am guessing that access is the same.
> >
> Well the experts were wrong, I suspect. Try
>
>SELECT @@IDENTITY
>
> to return the autonumber key created by the most recent INSERT.
>
> I believe this works for both SQL Server and Access (doesn't anyone use
> Google any more?).
>
> regards
>   Steve
>

I use SELECT IDENT_CURRENT('tablename').

SELECT @@IDENTITY returns the most recent of all inserts. If you have a
complex transaction which triggers inserts into other tables, it may
not return the one you want.

This one allows you to specify the tablename, and it will return the
most recent key inserted into that table.

I got this from the built-in help for SQLServer. I cannot say whether
it works for Access as well.

Frank

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


Re: Too Many if Statements?

2006-02-11 Thread Steve Holden
slogging_away wrote:
> Magnus Lycka wrote:
> 
> 
>>What happens if you run it from the command line instead
>>of IDLE? After all, it might be some problem in IDLE involved
>>here. Even if it doesn't work correctly outside IDLE, I was
>>thinking that IDLE might swallow some kind of error message.
> 
> 
> Excellent suggestion, (behold the power of the command line!).  I ran
> two saved versions of the script that had produced the symptom
> originally described.  The fist seemed to be caused by too many 'if'
> statements, the second by adding another array, but both came up with
> the same system error at the command prompt level shown here:
> 
> SystemError: com_backpatch: offset too large
> 
> This error is not produced with the IDLE console but is seen only when
> executing from the command line.  I'll search around and see if I can
> determine what this means and a possible fix.  Thanks for the
> suggestion!
> 
Now we have seen the real error message it does appear as though this is 
an error in the interpreter triggered by an unusually long source 
program. See

   http://mail.python.org/pipermail/python-list/2004-November/249270.html

for a previous discussion. In that email Diez Roggisch says:

"""I can't believe that a program with 1 lines only adding strings 
can't be written in a more concise way, which would most probably solve 
your problem. So I suggest you post some parts of your code so that we 
can have a look at it and suggest a solution."""

The same applies here.

Clearly it would be a good idea to remove whatever problem is causing 
the error, but in the meantime is there some way your code could be 
written more concisely? Or even split up into multiple modules?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


How to check...

2006-02-11 Thread Lad
Hello,
How can I  check that a string does NOT contain NON English characters?
Thanks
L.

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


Re: Shortest prime number program

2006-02-11 Thread swisscheese
At 58, very nice :-) Building on yours we get 57:
r=range(2,99)
[x for x in r if sum([x%d==0 for d in r])<2]

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


Re: Shortest prime number program

2006-02-11 Thread Ian Bygrave
On Sat, 11 Feb 2006 02:03:46 -0800, swisscheese wrote:

> I figured someone out there must have written a minimal code size prime
> number generator. I did not find one after a bit of searching around.
> For primes up to 100 the best I could do was 70 characters (including
> spaces):
> 
> r=range(2,99)
> m=[x*y for x in r for y in r]
> [x for x in r if not x in m]

I swore I'd never play Python golf.

p,r=[],range(2,99)
while r:p,r=p+r[:1],[x for x in r if x%r[0]]

And the result's in p.

--Ian Bygrave

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


Re: How to check...

2006-02-11 Thread augustus . kling
Hello,

try using regular expressions. I'afraid that i don't have any
documentation right here but i think there is a starting point for a
web search now.

Greetings

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


Re: How to check...

2006-02-11 Thread augustus . kling
Additional info: You will documentation in the Python help utility by
typing the module name 're' or 'sre'

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


Re: two generators working in tandem

2006-02-11 Thread Michael Spencer
john peter wrote:
> I'd like to write two generators: one is a min to max sequence number 
> generator that
>   rolls over to min again once the max is reached. the other is a generator 
> that cycles
>   through N (say, 12) labels. currently, i'm using these generators in nested 
> loops like
>   this:
>
>   seq_numbers = genSeqNum(min,max)
>   for label in genLabel():
>  for some_date in genDate(init):
> for i in xrange(0, LIMIT):
>print label, some_date, i, seq_numbers.next()
>
>   The problem I'm trying to solve is this:
>   when the seq_numbers generator rolls over, the label generator must be 
> advanced
>   to the next one "in tandem". does anyone has any suggestion? thanks for any 
> hepl!
> 
>   
> -
>  Yahoo! Mail
>  Use Photomail to share photos without annoying attachments.
> 
This returns an iterator that 'nests' an arbitrary number of sequences 
(odometer-style).

def nest(*sequences):
 def _nest(outer, inner):
 for outer_item in outer:
 if not isinstance(outer_item, tuple):
 outer_item = (outer_item,)
 for inner_item in inner:
 yield outer_item + (inner_item,)
 return reduce(_nest, sequences)


So, for your use case:

  >>> seq_numbers = range(1,10)
  >>> labels = ["A","B","C"]
  >>> list(nest(labels, seq_numbers))
  [('A', 1), ('A', 2), ('A', 3), ('A', 4), ('A', 5), ('A', 6), ('A', 7), ('A', 
8), ('A', 9), ('B', 1), ('B', 2), ('B', 3), ('B', 4), ('B', 5), ('B', 6), ('B', 
7), ('B', 8), ('B', 9), ('C', 1), ('C', 2), ('C', 3), ('C', 4), ('C', 5), ('C', 
6), ('C', 7), ('C', 8), ('C', 9)]
  >>>


HTH, Michael


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


Re: Shortest prime number program

2006-02-11 Thread Martin v. Löwis
You can save two bytes with
r=range(2,99)
[x for x in r if sum(x%d==0 for d in r)<2]
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with smart pointers

2006-02-11 Thread swell
Hello,
I use the Boost.Python lib for a couple of weeks now and i am
facing a pb.
To sum up i have a small hierarchy of objects and have a factory to
build concrete object. The pb is i think aroud the auto_ptr object that
is not correctly managed by my code ( i use version 1.33 )
I think that the solution is obvious but i can't sort it out. If you
could have a look at this small test


struct X
{
 virtual int fun1() = 0;
 int fun2() { return 2;}
 virtual int fun3() { return -1; }
};

struct Y : public X
{
 int fun1() {return 1;}
 virtual fun3() { return 3; }
};

struct FactY
{
 static std:auto_ptr create() { return std:auto_ptr(new Y());}
};


BOOST_PYTHON_MODULE(hello)
{
 class_("X",no_init);
 class_ >("Y")
  .def("fun1",&Y::fun1)
  .def("fun2",&Y::fun2)
  .def("fun3",&Y::fun3)
 ;

 class_("FactY",no_init)
  .def("create",&FactY::create)
  .staticmethod("create")
 ;
}
 
Many Thx

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


Re: Jython inherit from Java class

2006-02-11 Thread Kent Johnson
Frank LaFond wrote:
> Jython 2.2 Alpha 1 supports Java 1.5

It is also buggy and IIRC has a broken jythonc which is what the OP is 
trying to use.

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


Re: Shortest prime number program

2006-02-11 Thread swisscheese
>You can save two bytes with

56 - nice catch.
55:
r=range(2,99)
[x for x in r if sum(x%d<1 for d in r)<2]

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


Re: Shortest prime number program

2006-02-11 Thread [EMAIL PROTECTED]

swisscheese wrote:
> I figured someone out there must have written a minimal code size prime
> number generator. I did not find one after a bit of searching around.
> For primes up to 100 the best I could do was 70 characters (including
> spaces):
>
> r=range(2,99)
> m=[x*y for x in r for y in r]
> [x for x in r if not x in m]

import gmpy
p=2
while p<99:p=gmpy.next_prime(p)

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


Re: Jython inherit from Java class

2006-02-11 Thread Kent Johnson
Mark Fink wrote:
> Please enlighten me. This seemed so easy yust inherit from a Java class
> overwrite one method - done. At the moment I do not know how to proceed
> :-((

It should be easy.

> Jython or jythonc?
> ==
> In general is it better to run programms with the jython interpreter or
> is it better to compile them first? I had the impression that the
> inheritance does not work with the interpreter. Is that right?

I personally avoid jythonc, I have not had success with it. Others 
apparently have and use it.

Inheritance works fine without jythonc. The limitation in non-compiled 
Jython is in the methods that are visible to Java code. Java code will 
only see methods of a Jython class that are declared in a Java class or 
interface that the Jython class extends or implements.

For example:

Java:

public class Foo {
   public int value() { return 3; }
}

public interface Bar {
   public int anotherValue();
}

Jython:
class Baz(Foo, Bar):
   def value(self): return 5
   def anotherValue(self): return 7
   def somethingCompletelyDifferent(self): return 42

Now, a Java client that has an instance of Baz will be able to call
   baz.value()
   baz.anotherValue()
but
   baz.somethingCompletelyDifferent()
will not be possible even using Java introspection.

OTOH a Jython client will be able to access all three methods of baz.

> 
> 2.1 or 2.2a
> ===
> The programm did not compile with the 2.1 version and Java 1.5. But
> with 2.2a it compiled but 2.2a is an alpha version. Assuming the
> programm would compile with the Java 1.4 version would it be better
> (saver, more stable, performance) to use 2.1 or 2.2a?

IMO Jython 2.2a1 is not near ready for production use. Jython 2.1 is 
very stable and usable.

> Inherit from java baseclass or reimplement the whole thing in jython?
> =
> All the problems with Jython stated when I wanted to inherit from a
> Java baseclass. I wounder if I would have more success when
> implementing it in pure Jython. Regarding the inheritance I had an
> empty wrapper arround the Java baseclass and 70% of the unit test
> passed. But the performance was ~ factor 10 slower than using the base
> class directly. Does this mean that there is overhead with the
> inheritanc construct and that this implementation path would always be
> so slow. On the other hand would a 100% Jython solution be faster?

Inheritance from Java works well and I have never seen performance 
problems like this.

Java JUnit uses introspection to find test methods so it won't find 
methods of a Jython class.

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Chris Mellon
On 2/10/06, Kevin Walzer <[EMAIL PROTECTED]> wrote:
> ...with a twist.
>
> I'm undertaking my first semi-substantial Python GUI application after a
> long time dabbling with the language.
>
> I'm fairly experienced with Tcl/Tk, so Tkinter seems the obvious choice
> to reduce my Python learning curve. However, my Tcl applications
> typically make use of a *lot* of extensions to the core widget set, such
> as BWidgets, tablelist, and Tile.
>
> I've found minimal Tkinter wrappers for all of these extensions, but
> they are all labelled "experimental," lightly documented at best, and
> little-used (as far as I can tell) by Python developers.
>
> So: my question is, would it be more productive for me to wrestle with
> these extensions when there doesn't seem to be much constituency for
> their use, or would it be better/faster/more efficient for me to start
> scaling the wxPython mountain?
>
> For what it's worth, my application has to run on OS X and Windows, and
> will be commercial, so this combination of requirements rules out
> PyGTK/PyQt/just about every other cross-platform GUI toolkit.
>

If you're planning on selling an application, especially to OS X
users, then Tk is absolutely out of the question. It doesn't have even
the slightest resemblence to native behavior, and lacks the polish and
flash that occasionally lets a non-native app get away with it. Given
the limits you've stated, I believe your only options are wxPython and
writting 2 guis using PyWin/PyObjC. The second option requires
knowledge of the native tool sets for the respective platforms, so if
you don't have that I can only suggest wxPython. If you're used to Tk
you will face a learning curve, and you will need to look for or write
replacements for the custom widgets you've been using.

> Advice, especially from those Tkinter devs who look beyond the core
> widget set for their apps, is appreciated!
>
> --
> Kevin Walzer
> iReveal: File Search Tool
> http://www.wordtech-software.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython inherit from Java class

2006-02-11 Thread Kent Johnson
Mark Fink wrote:
> Alan, Kent, many thanks this really helped!
> But there is still a problem I guess with inheritance. I use the java
> testsuit supplied with the original to test the server. If I use the
> Java FitServer the testsuite can be completed. I commented everything
> out from my class and it does not work??

Since you are getting the same error from the Java server and the Jython 
subclass maybe you should figure out the Java problem first? It seems to 
be a problem making a socket connection of some kind.

Kent

> ## And the Java FitServer:
> D:\AUT_TEST>java -cp D:\\AUT_TEST\\fitnesse\\fitnesse.jar fit.FitServer
> localhost 1234 23
> Exception in thread "main" java.net.ConnectException: Connection
> refused: connect
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(Unknown Source)
> at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
> at java.net.PlainSocketImpl.connect(Unknown Source)
> at java.net.SocksSocketImpl.connect(Unknown Source)
> at java.net.Socket.connect(Unknown Source)
> at java.net.Socket.connect(Unknown Source)
> at java.net.Socket.(Unknown Source)
> at java.net.Socket.(Unknown Source)
> at fit.FitServer.establishConnection(Unknown Source)
> at fit.FitServer.establishConnection(Unknown Source)
> at fit.FitServer.run(Unknown Source)
> at fit.FitServer.main(Unknown Source)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shortest prime number program

2006-02-11 Thread Ian Bygrave
On Sat, 11 Feb 2006 12:43:23 +, Ian Bygrave wrote:
> p,r=[],range(2,99)
> while r:p,r=p+r[:1],[x for x in r if x%r[0]]
> 
> And the result's in p.

Well, given a hypothetical new function 'sieve'

def sieve(f,l):
if not l:
return l
head,tail=l[0],l[1:]
def filter_func(x):
return f(x,head)
tail=filter(filter_func,tail)
return [head]+tail

The prime generation can be reduced to:

from operator import *
sieve(mod,range(2,99))

Is there any precedent for such a function, or any other uses?
 
--Ian Bygrave

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Florian Nykrin
Hi Kevin!

I have no experience with Tkinter, but I did some small GUIs with 
wxPython and PyGTK.

wxPython works very well on Windows, but on Linux (Ubuntu/Debian in my 
case) it is very difficult to work with and buggy.
PyGTK-Applications on the other hand maybe do not look totally like 
Windows-Apps, but they work equally good on both systems (and have 
native look when working with Gnome).

I would take a look at PyGTK in combination with Glade, which is what I use.

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


Re: Shortest prime number program

2006-02-11 Thread Ian Bygrave
On Sat, 11 Feb 2006 13:33:58 +, Ian Bygrave wrote:

> Well, given a hypothetical new function 'sieve'

which should have been:

def sieve(f,l):
if not l:
return l
head,tail=l[0],l[1:]
def filter_func(x):
return f(x,head)
tail=filter(filter_func,tail)
return [head]+sieve(f,tail)

> The prime generation can be reduced to:
> 
> from operator import *
> sieve(mod,range(2,99))

--Ian Bygrave

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


Re: is there a better way?

2006-02-11 Thread Charles Krug
On 2006-02-11, Alex Martelli <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>> Problem:
>> 
>> You have a list of unknown length, such as this: list =
>> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
>> the X's are all up front and you know that the item after the last X is
>> an O, or that the list ends with an X.  There are never O's between
>> X's.
>
> If the list is incredibly long, you should use a bisection approach.
> Standard module bisect in the Python library could help, but mostly as
> an _example_, since it unfortunately relies on normal alphabetic order,
> and alphabetically speaking X should come _after_ O, not _before_.
>

Isn't every call to list.index() an O(n) operation?  We certainly want
to avoid multiple calls there if we can.

What happens if your split occurs in the middle of your block of Xs?
Then the split before/after fails --the stated algorithm says, "If the
split is an X, choose the front half," so perhaps the statement was
inprecise?

The only way you'll know if you have an X in a particular block is using
a linear search method, either in Python or with list.index()

If (as the OP seemed to state) we KNOW that there's only one block of
X's in the list:

1. Find the index of the first X
2. Find the index of the last X.
3. Delete the block we've found.

That relies on the underlying language, which means we're working in
"Linear Time in C", more or less.

If we make no such guarantee, then I can do the operation in linear
"Python Time" by scanning the list once, finding each instance and
calling list.del() as I find each block, keeping track of my current
position so I don't have to start over again.

Judging from way the OP worded the question, I'd advise making something
that works and that you understand how it works.

After that, s/he can worry about whether or not its performance is
suboptimal.

How large must the list be before "logarithmic Python algorithm" is
faster than "linear C algorithm"?  I've never measured, but it may be a
question worth exploring if one has a huge pile of data to chew on--like
US Census or UN budget-sized.




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


Re: Is there any books such as 'effective python' or else about the performance?

2006-02-11 Thread Charles Krug
On 2006-02-11, Kenneth Xie <[EMAIL PROTECTED]> wrote:
> att, thx.

A lot of the ideas discussed in Effective C++ et al are things that
Python does for us already.  C++ works at a much lower layer of
abstraction and you need to deal explicitly with freestore for any
nontrivial class.

EC++ is mostly about how NOT to crash your programs.

The Python Cookbook is a "more pythonic" version of the same
idea--proven techniques appropriate to the abstraction level of the
language.

Design Patterns is worth reading as well, but be careful with it.  Many
of the ideas that are difficult to do in C++, Java, Smalltalk, etc
(singletons come to mind) are trivially easy to do in Python because of
how our object model works.

Bruce Eckle's "Thinking in Python" gives a pattern introduction
explaining how things work in Python that can give you a sprinboard to
adapting other patterns from C++ et al.
-- 
http://mail.python.org/mailman/listinfo/python-list


Netstat in python. Does it's possible?

2006-02-11 Thread billie
Hi all. I don't know if Python is good for this kind of jobs but I'm 
wondering if it's possible emulate the "netstat" command in Python.
I'd need to know if a certain executable opened a socket and, in that case, 
I'd like to know what kind of socket it uses (TCP or UDP), its src/dst PORT, 
and the current STATE of the connection (listening, established, SYN 
sent...).

Thanks in advance. 


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


Re: PyGTK

2006-02-11 Thread Dieter Verfaillie
On Thu, 09 Feb 2006 12:38:26 +, Dave Cook wrote:
> 
> particularly the last section on how to create an EXE from your pygtk program.
> 

That recipe isn't optimal with newer gtk versions (starting from 2.8 if I
remember correctly). Look here instead:
http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Grant Edwards
On 2006-02-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> What's wrong with wxPython? (http://www.wxpython.org)

Nothing.  A lot of us use it.

> Didn't see it mentioned here.

I'm sorry, I didn't realize we were supposed to.

You might want to check the wxpython mailing list if you want
to see it mentioned more often.

-- 
Grant Edwards   grante Yow!  Why are these
  at   athletic shoe salesmen
   visi.comfollowing me??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another GUI toolkit question...

2006-02-11 Thread Grant Edwards
On 2006-02-11, Florian Nykrin <[EMAIL PROTECTED]> wrote:

> wxPython works very well on Windows, but on Linux (Ubuntu/Debian in my 
> case) it is very difficult to work with and buggy.

That's odd.  I've been using wxPython for many years on both
Windows and on many distributions and haven't found a bug yet.
I admit that wxWidgets doesn't have the most elegent API in the
world...

-- 
Grant Edwards   grante Yow!  Thousands of days of
  at   civilians... have produced
   visi.coma... feeling for the
   aesthetic modules --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shortest prime number program

2006-02-11 Thread Grant Edwards
On 2006-02-11, swisscheese <[EMAIL PROTECTED]> wrote:
>>You can save two bytes with
>
> 56 - nice catch.
> 55:
> r=range(2,99)
> [x for x in r if sum(x%d<1 for d in r)<2]

And if this were FORTRAN:

r=range(2,99)
[xforxinrifsum(x%d<1fordinr)<2]

;)

-- 
Grant Edwards   grante Yow!  Hmmm... a CRIPPLED
  at   ACCOUNTANT with a FALAFEL
   visi.comsandwich is HIT by a
   TROLLEY-CAR...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial handobook

2006-02-11 Thread Grant Edwards
On 2006-02-11, Zarathustra <[EMAIL PROTECTED]> wrote:

> Hi, where I can find the pyserial handbook??

I don't think there is anything called the "pyserial handbook".
The documentation for pyserial is at http://pyserial.sourceforge.net/

It's the first hit when you google "pyserial".  Shocker, eh?

-- 
Grant Edwards   grante Yow!  .. If I had heart
  at   failure right now,
   visi.comI couldn't be a more
   fortunate man!!
-- 
http://mail.python.org/mailman/listinfo/python-list


encoding problems with pymssql / win

2006-02-11 Thread morris carre

I have a strange problem : some code that fetches queries from an mssql 
database works fine under Idle but the very same code run from a shell 
window obtains its strings garbled as if the encoding codepage was 
modified. This occurs only when using pymssql to connect; if I connect 
through odbc (using the odbc module included in pywin) this problem 
vanishes.

I briefly thought sys.getdefaultencoding() would pin it down but the 
value is "ascii" in all cases.

If anyone has a lead as to what may be happening here or how to solve it 
(apart from using odbc, that is), advice is welcome.

I am using python 2.4.2 and pymssql 0.7.3 under win2k sp4 on the client 
machine, while the server machine has windows server 2003 + sqlserver2k, 
locale is fr_CH. For an example of garbling, I get '\x8a' where I should 
get '\xe8'

TIA, mc
--
(to email use "boris at batiment71 dot ch")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encoding problems with pymssql / win

2006-02-11 Thread morris carre
> (to email use "boris at batiment71 dot ch")

oops, that's "boris at batiment71 dot net"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-11 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Problem:
> 
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.
> 
> I have been using something like this:
> _
> 
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _
> 
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?
> 
> hope this is clear.

  >>> X = "X"
  >>> O = "O"
  >>> def fl(l):
  ...   for i, v in enumerate(l):
  ... if v == O:
  ...   return l[:i]
  ...   return l
  ...
  >>> fl([X,X,X,X,O,O,O])
['X', 'X', 'X', 'X']
  >>> fl([])
[]
  >>> fl([O])
[]
  >>> fl([X])
['X']
  >>>

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Kevin Walzer
[EMAIL PROTECTED] wrote:
> What's wrong with wxPython? (http://www.wxpython.org)
> Didn't see it mentioned here.
> 
> 
> David Berlin
> http://farpy.holev.com - Python GUI Editor
> 
I did mention it...see "scaling the wxPython mountain."


-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-11 Thread Carl Friedrich Bolz
Alex Martelli wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
> 
>>Problem:
>>
>>You have a list of unknown length, such as this: list =
>>[X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
>>the X's are all up front and you know that the item after the last X is
>>an O, or that the list ends with an X.  There are never O's between
>>X's.
> 
> 
> If the list is incredibly long, you should use a bisection approach.
> Standard module bisect in the Python library could help, but mostly as
> an _example_, since it unfortunately relies on normal alphabetic order,
> and alphabetically speaking X should come _after_ O, not _before_.
> 
> But the algorithm is still sound:
> 
> 1. look at the midpoint.
> 2. if it's an X, so are all previous items -- recurse to second half
> 3. if it's an O, so are all following items -- recurse to first half
> 
> Getting all conditions exactly right is tricky (which is why bisect is a
> good model!), but this way you get O(log N) performance for a list of
> length N.
> 
> If N is not too huge, O(N) might be OK, and is, of course, way simpler
> to code!-)
> 

The code would look something like this:

low = 0
high = len(L)
while low < high:
 mid = (low + high) // 2
 if L[mid] == 0:
 high = mid
 else:
 low = mid + 1
list_of_X = L[:low]


Cheers,

Carl Friedrich Bolz

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Kevin Walzer
Florian Nykrin wrote:
> Hi Kevin!
> 
> I have no experience with Tkinter, but I did some small GUIs with
> wxPython and PyGTK.
> 
> wxPython works very well on Windows, but on Linux (Ubuntu/Debian in my
> case) it is very difficult to work with and buggy.
> PyGTK-Applications on the other hand maybe do not look totally like
> Windows-Apps, but they work equally good on both systems (and have
> native look when working with Gnome).
> 
> I would take a look at PyGTK in combination with Glade, which is what I
> use.
> 
> Regards, Florian.
Unfortunately, PyGTK does not run natively on the Mac (it's X11 only).


-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Netstat in python. Does it's possible?

2006-02-11 Thread Sybren Stuvel
billie enlightened us with:
> Hi all. I don't know if Python is good for this kind of jobs but I'm
> wondering if it's possible emulate the "netstat" command in Python.

On Linux, you can read /proc for that info, iirc.

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


Re: Martin Franklin's Tkinter/Tile wrapper--where'd it go?

2006-02-11 Thread Kevin Walzer
Kevin Walzer wrote:
> I believe Martin Franklin wrote a Tile.py wrapper for the Tk/Tile
> extension, which adds theming to the core Tk widget set. It used to
> reside here:
> 
> http://mfranklin.is-a-geek.org/docs/Tile/index.html
> 
> That server seems to be down. Anyone know if the wrapper is available
> elsewhere? Or if someone else has written a Tile wrapper?
> 
According to Mr. Franklin the site should be back online very soon.


-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-11 Thread Carl Friedrich Bolz
Hi!

[EMAIL PROTECTED] wrote:
> Problem:
> 
> You have a list of unknown length, such as this: list =
> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> the X's are all up front and you know that the item after the last X is
> an O, or that the list ends with an X.  There are never O's between
> X's.
> 
> I have been using something like this:
> _
> 
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _
> 
> But this seems ugly to me, and using "while" give me the heebies.  Is
> there a better approach?

Depends on what you mean with "better". I (heavily inspired by the 
bisect module) came up with:

low = 0
high = len(L)
while low < high:
 mid = (low + high) // 2
 if L[mid] == 0:
 high = mid
 else:
 low = mid + 1
storage = L[:low]

This has the advantage to be more efficient compared to other 
approaches, which of course only matters if your list is big. It still 
features a "while" loop, though.

> hope this is clear.

It is not entirely clear what the X is supposed to be. I assumed that it 
can be anything except 0.

Cheers,

Carl Friedrich

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


Re: appending to a list via properties

2006-02-11 Thread Carl Banks
Lonnie Princehouse wrote:
> Here's a curious hack I want to put up for discussion.  I'm thinking of
> writing a PEP for it.

A minor library change wouldn' t need a PEP.

> Observation
> -
> I found myself using this construct for assembling multiple lists:
>
> foo = []
> qux = []
>
> while some_condition:
>a, b = calculate_something()
>foo.append(a)
>qux.append(b)
>
> Not elegant!

I don't agree; however:

> class better_list (list):
> tail = property(None, list.append)

This is an impressive, spiffy little class.

> Well?

I suspect it's too sneaky and not commonly useful enough to get serious
consideration for the standard library.  But definitely submit it to
Python Cookbook:
http://aspn.activestate.com/ASPN/Python/Cookbook/

Carl Banks


P.S. to get rid of temporary variables while using regular lists:

growing_lists = foo,qux
while some_condition:
for (s,x) in zip(growing_list,calculate_something()):
list.append(s,x)

No I don't really recommend it.

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Peter Decker
On 2/10/06, Kevin Walzer <[EMAIL PROTECTED]> wrote:

> I'm undertaking my first semi-substantial Python GUI application after a
> long time dabbling with the language.
>
...
> So: my question is, would it be more productive for me to wrestle with
> these extensions when there doesn't seem to be much constituency for
> their use, or would it be better/faster/more efficient for me to start
> scaling the wxPython mountain?

If you're going cross-platform, then wxPython is the toolkit to use.
It looks and works correctly on all platforms.

I worked with wxPython for a couple of years, and constantly struggled
with the ugle, C++ style syntax, and then discovered Dabo. Dabo is a
full 3-tier application framework, and its UI tier wraps wxPython. So
while you're using wxPython when you use dabo.ui, you're writing
clean, Pythonic code. I found that after playing around with Dabo for
a little bit, I could write apps that worked without constantly going
to the docs to look up some obscure constant or event name. The
authors are also extremely helpful, so if write your app using Dabo,
I'm sure that you'll have tons of support.

http://dabodev.com

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another GUI toolkit question...

2006-02-11 Thread Lawrence Oluyede
Kevin Walzer <[EMAIL PROTECTED]> writes:

> Unfortunately, PyGTK does not run natively on the Mac (it's X11 only).

There's some work in progress:
http://developer.imendio.com/wiki/Gtk_Mac_OS_X

-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to invoke a tkinter menu *itself*

2006-02-11 Thread Edward K. Ream
> I've spent a pleasant hour or so trying to bring up a top-level Tk menu at 
> the same spot as it would appear if I had actually clicked the menu.  That 
> is, I want to bring up a menu from the keyboard.

I'm going to investigate how to locate the 'button' that forms the anchor 
for the menu.  This button *is* (or should be) packed (or placed), so it 
should know its own location.

Anyone know how to do find a menu's button?

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html
 


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


Re: Netstat in python. Does it's possible?

2006-02-11 Thread Martin v. Löwis
billie wrote:
> Hi all. I don't know if Python is good for this kind of jobs but I'm 
> wondering if it's possible emulate the "netstat" command in Python.

As a general recommendation, use strace(1) to answer this kind of
question. Run "strace -o tmp netstat", then inspect tmp to find out
how netstat obtained the information it reported.

As Sybren suggests, this can all be answered from /proc. For a
process you are interested in, list /proc//fd (using os.listdir),
then read the contents of all links (using os.readlink). If the link
value starts with "[socket:", it's a socket. Then search
/proc/net/tcp for the ID. The line containing the ID will have
the information you want.

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


Re: Legality of using Fonts

2006-02-11 Thread Ross Ridge

Steven D'Aprano wrote:
> In any case, even in the USA, hinted fonts are copyrightable, and merely
> removing the hints (say, by converting to a bitmap) is no more legal than
> whiting out the author's name from a book and claiming it as your own.

That's an absurd comparison. By making a bitmap font from an hinted
outline font you're only copying the typeface, you're not copying the
hints, the computer program, that's the only part of the font that's
subject copyright.  If a book consisted of two parts, the first a play
by Shakespeare, and the second a commentary of that play, and someone
copied only the first part, they'd be doing nothing illegal.


 Ross Ridge

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


Re: Shortest prime number program

2006-02-11 Thread dickinsm

swisscheese wrote:
>
> r=range(2,99)
> m=[x*y for x in r for y in r]
> [x for x in r if not x in m]

How about:

[2]+[x for x in range(1,99) if 2**x%x==2]

Mark

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


Re: [ANN] functional 0.5 released

2006-02-11 Thread Neal Becker
I just installed from .tar.gz on fedora FC5 x86_64.  I ran into 1 small
problem:

sudo python setup.py install --verbose
running install
running bdist_egg
running egg_info
writing functional.egg-info/PKG-INFO
writing top-level names to functional.egg-info/top_level.txt
reading manifest file 'functional.egg-info/SOURCES.txt'
writing manifest file 'functional.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.4/functional.so ->
build/bdist.linux-x86_64/egg
creating stub loader for functional.so
byte-compiling build/bdist.linux-x86_64/egg/functional.py to functional.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
writing functional.egg-info/native_libs.txt
copying functional.egg-info/SOURCES.txt ->
build/bdist.linux-x86_64/egg/EGG-INFO
copying functional.egg-info/native_libs.txt ->
build/bdist.linux-x86_64/egg/EGG-INFO
copying functional.egg-info/PKG-INFO ->
build/bdist.linux-x86_64/egg/EGG-INFO
copying functional.egg-info/top_level.txt ->
build/bdist.linux-x86_64/egg/EGG-INFO
copying functional.egg-info/zip-safe ->
build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/functional-0.5-py2.4-linux-x86_64.egg' and adding
'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing functional-0.5-py2.4-linux-x86_64.egg
Removing 
/usr/lib64/python2.4/site-packages/functional-0.5-py2.4-linux-x86_64.egg
Copying functional-0.5-py2.4-linux-x86_64.egg
to /usr/lib64/python2.4/site-packages

Installed 
/usr/lib64/python2.4/site-packages/functional-0.5-py2.4-linux-x86_64.egg

Because this distribution was installed --multi-version or --install-dir,
before you can import modules from this package in an application, you
will need to 'import pkg_resources' and then use a 'require()' call
similar to one of these examples, in order to select the desired version:

pkg_resources.require("functional")  # latest installed version
pkg_resources.require("functional==0.5")  # this exact version
pkg_resources.require("functional>=0.5")  # this version or higher

Processing dependencies for functional==0.5

What's all this about multi-version?  Did I do something wrong?

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


Re: How to check...

2006-02-11 Thread Daniel Marcel Eichler
Lad wrote:

>How can I  check that a string does NOT contain NON English characters?

try:
foobar.encode('ascii')
except:
bla

or use string.ascii_letters and enhance it.


mfg

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Robert Hicks
Wow you are so wrong about Tk on OSX. Soon this is just not going to be
the case at all for any of the system Tcl/Tk runs on. The Tcl folks
have come out with a package called "Tile" that is going to be rolled
in. It gives you native L&F on OSX, Windows, Linux.

Robert

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


Re: How to check...

2006-02-11 Thread John Zenger
This should be just a matter of determining how your string is encoded 
(ASCII, UTF, Unicode, etc.) and checking the ord of each character to 
see if it is in the contiguous range of English characters for that 
encoding.  For example, if you know that the string is ASCII or UTF-8, 
you could check ord for each character and confirm it is less than 128.

Lad wrote:
> Hello,
> How can I  check that a string does NOT contain NON English characters?
> Thanks
> L.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a better way?

2006-02-11 Thread Alex Martelli
Charles Krug <[EMAIL PROTECTED]> wrote:

> On 2006-02-11, Alex Martelli <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> >> Problem:
> >> 
> >> You have a list of unknown length, such as this: list =
> >> [X,X,X,O,O,O,O].  You want to extract all and only the X's.  You know
> >> the X's are all up front and you know that the item after the last X is
> >> an O, or that the list ends with an X.  There are never O's between
> >> X's.
> >
> > If the list is incredibly long, you should use a bisection approach.
> > Standard module bisect in the Python library could help, but mostly as
> > an _example_, since it unfortunately relies on normal alphabetic order,
> > and alphabetically speaking X should come _after_ O, not _before_.
> 
> Isn't every call to list.index() an O(n) operation?  We certainly want
> to avoid multiple calls there if we can.

Why should we have ANY call to index whatsoever?

> What happens if your split occurs in the middle of your block of Xs?
> Then the split before/after fails --the stated algorithm says, "If the
> split is an X, choose the front half," so perhaps the statement was
> inprecise?

What statement?  What are you TALKING about?!  What I said, and you
don't quote, was:

> > 2. if it's an X, so are all previous items -- recurse to second half

how can you POSSIBLY read this as "choose the front half"?!  I say to
recurse (iteration works, too, but it's even trickier to code) to the
SECOND half, to find the first-if-any non-'X'.

> The only way you'll know if you have an X in a particular block is using
> a linear search method, either in Python or with list.index()

Reread markscala's problem statement: all the Xs are up front followed
by 0 or more Os.  So, the list is L = ['X']*N + ['O']*M for unknown N>=0
and M>=0.  All we have to do is find N and M (if we know either, the
other is immediately computed, since N+M==len(L) and len() is O(1)).

> If (as the OP seemed to state) we KNOW that there's only one block of
> X's in the list:
> 
> 1. Find the index of the first X

Why would we do that?  He stated, very clearly, and you and I have both
been quoting:

> >> You know
> >> the X's are all up front 

So why would we do any work to find out what we altrady know?

> 2. Find the index of the last X.

Yep, the only certain task, and it's O(log(N+M)).

> 3. Delete the block we've found.

And the deletion is definitely linear time (and trivial), of course.  I
was focusing on the only interesting part, (2).

> Judging from way the OP worded the question, I'd advise making something
> that works and that you understand how it works.
> 
> After that, s/he can worry about whether or not its performance is
> suboptimal.

And indeed, part of what I said (and again you're snipping it rather
than quoting it was:

> > If N is not too huge, O(N) might be OK, and is, of course, way simpler
> > to code!-)

However, even though the O(N) in the deletion subtask would appear to
justify this shortcut, I think the task is way too trivial to justify a
linear-time approach to point 2 -- the obvious N = L.count('X'), of
course.  It seems likely that the whole purpose of the exercise
(probably homework) is to have the student identify and develop a
bisection (a notoriously tricky-to-code thing).


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


Re: Shortest prime number program

2006-02-11 Thread Christoph Zwerschke
[EMAIL PROTECTED] schrieb:
> How about:
> 
> [2]+[x for x in range(1,99) if 2**x%x==2]

If the range goes beyond 340, it also gives non-primes...

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Steve Holden
Robert Hicks wrote:
> Wow you are so wrong about Tk on OSX. Soon this is just not going to be
> the case at all for any of the system Tcl/Tk runs on. The Tcl folks
> have come out with a package called "Tile" that is going to be rolled
> in. It gives you native L&F on OSX, Windows, Linux.
> 
This is good news if it happens, but right now it's just another dose of 
"real soon now".

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Shortest prime number program

2006-02-11 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote:
> swisscheese wrote:
> 
>>r=range(2,99)
>>m=[x*y for x in r for y in r]
>>[x for x in r if not x in m]
> 
> 
> How about:
> 
> [2]+[x for x in range(1,99) if 2**x%x==2]

43.

I'll be chewing on this one for a while.  Thank you. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shortest prime number program

2006-02-11 Thread swisscheese
> [2]+[x for x in range(1,99) if 2**x%x==2]

42 - brilliant!
41:
[2]+[x for x in range(1,99)if 2**x%x==2]
... although it appears Christoph is right that it's not scalable.

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


Re: Shortest prime number program

2006-02-11 Thread bearophileHUGS
This is a little shorter :-)

[2]+[x for x in range(2,99)if 2**x%x==2] 

Bye,
bearophile

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Kevin Walzer
Chris Mellon wrote:

> 
> If you're planning on selling an application, especially to OS X
> users, then Tk is absolutely out of the question. It doesn't have even
> the slightest resemblence to native behavior, and lacks the polish and
> flash that occasionally lets a non-native app get away with it. Given
> the limits you've stated, I believe your only options are wxPython and
> writting 2 guis using PyWin/PyObjC. The second option requires
> knowledge of the native tool sets for the respective platforms, so if
> you don't have that I can only suggest wxPython. If you're used to Tk
> you will face a learning curve, and you will need to look for or write
> replacements for the custom widgets you've been using.
> 

Do these screenshots look "non-native" to you?

http://www.wordtech-software.com/ireveal-mac.png
http://www.wordtech-software.com/ireveal-windows.png
http://www.wordtech-software.com/ireveal-linux.png

This application was developed in Tcl/Tk.

I think Tkinter is lagging behind Tk itself in terms of its advances
with theming and native look and feel, especially on OS X and Win XP.
Certainly a lot of Python developers don't seem well-informed about the
work that has been done to bring Tk back into the modern age. The
wrappers I mentioned above (some at a site that is offline but should be
back online shortly, I'm told) are bleeding-edge in Tkinter terms but
reflect work that started a couple of years ago in Tk. (The extension is
called "Tile" and will be part of the Tk core when it's released at v. 8.5).

That doesn't mean wxPython is out of the question. What I'm trying to
figure out is whether I will be up and running faster with Tkinter +
Tile (leaving me mainly to improve my proficiency with Python itself and
translate Tk into a Python idiom) or whether I should learn wxPython,
with its vastly different GUI paradigm, as well as Python.

If Tkinter + Tile + Bwidgets + Tablelist does the job, as I think it may
(and as it does with regular Tcl/Tk), then I will probably stick with
that. And perhaps I can then contribute some documentation somewhere on
how to use the Tile widgets in a Tkinter application, complete with
screen shots and working code for others to use. Such documentation is
sorely lacking right now.

The vast range of available GUI toolkits is one thing that partially
offsets Python's many virtues as a programming language. I realize I was
stepping into a fire swamp by even broaching the question. However, the
application I'm envisioning (accessing web services from a desktop GUI)
will benefit from the abundant Python libraries/wrappers that have
already been written, which are mostly lacking (or which would require
me to roll my own) in Tcl.


-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another GUI toolkit question...

2006-02-11 Thread Kevin Walzer
Steve Holden wrote:
> Robert Hicks wrote:
>> Wow you are so wrong about Tk on OSX. Soon this is just not going to be
>> the case at all for any of the system Tcl/Tk runs on. The Tcl folks
>> have come out with a package called "Tile" that is going to be rolled
>> in. It gives you native L&F on OSX, Windows, Linux.
>>
> This is good news if it happens, but right now it's just another dose of
> "real soon now".
> 
> regards
>  Steve

Not true. It's already available. I've shipped three open-source and one
commercial application making use of Tile.

The Tkinter wrapper is here:

http://mfranklin.is-a-geek.org/docs/Tile/index.html

The server is down at the moment but is supposed to be back online shortly.

-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shortest prime number program

2006-02-11 Thread swisscheese
> 42
Make that 41 and 40.

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


Re: appending to a list via properties

2006-02-11 Thread Alex Martelli
Carl Banks <[EMAIL PROTECTED]> wrote:
   ...
> > class better_list (list):
> > tail = property(None, list.append)
> 
> This is an impressive, spiffy little class.

Yes, nice use of property.

> growing_lists = foo,qux
> while some_condition:
> for (s,x) in zip(growing_list,calculate_something()):
> list.append(s,x)
> 
> No I don't really recommend it.

Why not?  Seems OK.  Maybe simplified to:

while some_condition:
for alist, anitem in zip((foo, qux), calculate_something()):
alist.append(anitem)

If you want to hoist for performance, you can hoist more:

appenders = foo.append, qux.append
while some_condition:
for appender, anitem in zip(appenders, calculate_something()):
appender(anitem)


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


Jython socket typecasting problems

2006-02-11 Thread Mark Fink
I try to port a server application to Jython. At the moment I use
Jython21\Lib\socket.py
Currently I do face problems with casting the string "localhost" to the
desired value:
D:\AUT_TEST\workspace\JyFIT>jython fit/JyFitServer2.py localhost 1234
23
['fit/JyFitServer2.py', 'localhost', '1234', '23']
localhost
Traceback (innermost last):
  File "fit/JyFitServer2.py", line 146, in ?
  File "fit/JyFitServer2.py", line 31, in run
  File "fit/JyFitServer2.py", line 96, in establishConnection
  File "D:\AUT_TEST\Jython21\Lib\socket.py", line 135, in connect
TypeError: java.net.Socket(): 1st arg can't be coerced to
java.net.InetAddress or String

The cast to Integer for the port does not work either:

D:\AUT_TEST\workspace\JyFIT>jython fit/JyFitServer2.py "" 1234 23
['fit/JyFitServer2.py', '', '1234', '23']

Traceback (innermost last):
  File "fit/JyFitServer2.py", line 146, in ?
  File "fit/JyFitServer2.py", line 31, in run
  File "fit/JyFitServer2.py", line 96, in establishConnection
  File "D:\AUT_TEST\Jython21\Lib\socket.py", line 135, in connect
TypeError: java.net.Socket(): 2nd arg can't be coerced to int

This is the code section of my server class (I cut this from a Python
example):
def establishConnection(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((self.host, self.port))
Do I have to use explicit typecasting? How can this be achieved?

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Kevin Walzer
Peter Decker wrote:
> On 2/10/06, Kevin Walzer <[EMAIL PROTECTED]> wrote:
> 
>> I'm undertaking my first semi-substantial Python GUI application after a
>> long time dabbling with the language.
>>
> ...
>> So: my question is, would it be more productive for me to wrestle with
>> these extensions when there doesn't seem to be much constituency for
>> their use, or would it be better/faster/more efficient for me to start
>> scaling the wxPython mountain?
> 
> If you're going cross-platform, then wxPython is the toolkit to use.
> It looks and works correctly on all platforms.
> 
> I worked with wxPython for a couple of years, and constantly struggled
> with the ugle, C++ style syntax, and then discovered Dabo. Dabo is a
> full 3-tier application framework, and its UI tier wraps wxPython. So
> while you're using wxPython when you use dabo.ui, you're writing
> clean, Pythonic code. I found that after playing around with Dabo for
> a little bit, I could write apps that worked without constantly going
> to the docs to look up some obscure constant or event name. The
> authors are also extremely helpful, so if write your app using Dabo,
> I'm sure that you'll have tons of support.
> 
> http://dabodev.com
> 
> --
> 
> # p.d.

Dabo looks interesting, but isn't it mainly for database applications?
Has any other kind of application been developed with it? Also, it seems
very Windows/Linux-centric. Is anyone using it on OS X?

-- 
Kevin Walzer
iReveal: File Search Tool
http://www.wordtech-software.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: appending to a list via properties

2006-02-11 Thread Carl Banks

Alex Martelli wrote:
> Carl Banks <[EMAIL PROTECTED]> wrote:
>...
> > > class better_list (list):
> > > tail = property(None, list.append)
> >
> > This is an impressive, spiffy little class.
>
> Yes, nice use of property.
>
> > growing_lists = foo,qux
> > while some_condition:
> > for (s,x) in zip(growing_list,calculate_something()):
> > list.append(s,x)
> >
> > No I don't really recommend it.
>
> Why not?  Seems OK.  Maybe simplified to:

Well, for this simple case I guess.  If you have a lot of lists, or
you're trying to write a general multiple list appender, it would be
fine.

Carl Banks

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


Re: any way to customize the is operator?

2006-02-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
Lonnie Princehouse <[EMAIL PROTECTED]> wrote:
>
>> Why did you want to customize "is"?
>
>Well, mostly out of principle ;-)
>
>But also because I'm wrapping a C library which passes around C structs
>which are wrapped in shim C++ classes for a Boost.Python layer.  Boost
>Python does a marvelous job of translating between Python and C++ data
>types; when a C structure is returned, it magically translates that
>structure into a Python wrapper.   The problem is that a _new_ Python
>wrapper is created every time a pointer is returned, even if a  wrapper
>already exists for that particular pointer.

Then you need to fix Boost.Python.  This cannot and will not get fixed at
the Python level -- how can Python possibly know that they are the same
objects?
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython socket typecasting problems

2006-02-11 Thread Diez B. Roggisch
> This is the code section of my server class (I cut this from a Python
> example):
> def establishConnection(self):
> self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> self.socket.connect((self.host, self.port))
> Do I have to use explicit typecasting? How can this be achieved?

There is no such thing as explicit casting in python. You can coerce 
values to values of another type - e.g. float("1.0"), and there are some 
"magic" methods to support that (for that example __float__)

However, that doesn't seem to be your problem. You just pass the wrong 
arguments, which makes the jython wrapping punke on you as only certain 
types can be dealt with.

To me this looks as if you are supposed to do it like this:

self.socket.connect(self.host, self.port)

Note the missing parentheses.

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


Re: by reference

2006-02-11 Thread dirvine
Many thanks I will do so in the future.

David

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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Peter Decker
On 2/11/06, Kevin Walzer <[EMAIL PROTECTED]> wrote:

> Dabo looks interesting, but isn't it mainly for database applications?
> Has any other kind of application been developed with it? Also, it seems
> very Windows/Linux-centric. Is anyone using it on OS X?

The Dabo demo comes with several games written that have no database
stuff at all. According to the developers (one of whom develops on OS
X, to answer your other question), they started out creating a tool
for database apps, but the response has been so strong on the UI side
that they've spent most of their time making the dabo.ui module able
to be used by iteself.

I don't do any development work with databases, and I've used Dabo for
several internal apps. The stuff I used to write in wxPython I now
write in Dabo.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another GUI toolkit question...

2006-02-11 Thread Peter Decker
On 2/11/06, Kevin Walzer <[EMAIL PROTECTED]> wrote:

> Also, it seems
> very Windows/Linux-centric. Is anyone using it on OS X?

I almost forgot: take a look at this screencast:

http://leafe.com/screencasts/sizers2.html

It's the second part of a demonstration on using sizers in the Dabo
visual designer tool. The first part was done on Linux, and the saved
file was copied over unchanged to OS X, where the demo was completed.

--

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PySizeof: almost useful

2006-02-11 Thread Alex Martelli
Ian Leitch <[EMAIL PROTECTED]> wrote:
   ...
> 2. I'm at a loss as how to calculate the size of a long object -- any tips?

#include "longintrepr.h" (from the Python sources).  Then, given a
PyLongObject *l, abs(l->ob_size) is the number of "digits", each taking
SHIFT bits.

> Many thanks to anyone bored enough to review this code.

Sorry, I don't have the time, but I hope the above tip can be useful.


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


Re: Yet another GUI toolkit question...

2006-02-11 Thread Chris Mellon
On 2/11/06, Kevin Walzer <[EMAIL PROTECTED]> wrote:
> Chris Mellon wrote:
>
> >
> > If you're planning on selling an application, especially to OS X
> > users, then Tk is absolutely out of the question. It doesn't have even
> > the slightest resemblence to native behavior, and lacks the polish and
> > flash that occasionally lets a non-native app get away with it. Given
> > the limits you've stated, I believe your only options are wxPython and
> > writting 2 guis using PyWin/PyObjC. The second option requires
> > knowledge of the native tool sets for the respective platforms, so if
> > you don't have that I can only suggest wxPython. If you're used to Tk
> > you will face a learning curve, and you will need to look for or write
> > replacements for the custom widgets you've been using.
> >
>
> Do these screenshots look "non-native" to you?

Yes, actually.  But thats not the point, and a trivial dialog isn't
enough to really judge Tile anyway.

>
> http://www.wordtech-software.com/ireveal-mac.png
> http://www.wordtech-software.com/ireveal-windows.png
> http://www.wordtech-software.com/ireveal-linux.png
>
> This application was developed in Tcl/Tk.
>
> I think Tkinter is lagging behind Tk itself in terms of its advances
> with theming and native look and feel, especially on OS X and Win XP.
> Certainly a lot of Python developers don't seem well-informed about the
> work that has been done to bring Tk back into the modern age. The
> wrappers I mentioned above (some at a site that is offline but should be
> back online shortly, I'm told) are bleeding-edge in Tkinter terms but
> reflect work that started a couple of years ago in Tk. (The extension is
> called "Tile" and will be part of the Tk core when it's released at v. 8.5).
>
> That doesn't mean wxPython is out of the question. What I'm trying to
> figure out is whether I will be up and running faster with Tkinter +
> Tile (leaving me mainly to improve my proficiency with Python itself and
> translate Tk into a Python idiom) or whether I should learn wxPython,
> with its vastly different GUI paradigm, as well as Python.
>

That depends almost totally on you and your skills, doesn't it? I'm an
unabashed fan of wxPython, so naturally I lean that way, but I
wouldn't deny that is has a learning curve. It's famous "C++ like API"
has seen vast improvement in the last few releases, by the way, and is
much more pythonic than a lot of people seem to believe  - no more
from wxPython import *, for example. I certainly find it's API more
pythonic than Tkinters.

> If Tkinter + Tile + Bwidgets + Tablelist does the job, as I think it may
> (and as it does with regular Tcl/Tk), then I will probably stick with
> that. And perhaps I can then contribute some documentation somewhere on
> how to use the Tile widgets in a Tkinter application, complete with
> screen shots and working code for others to use. Such documentation is
> sorely lacking right now.
>
> The vast range of available GUI toolkits is one thing that partially
> offsets Python's many virtues as a programming language. I realize I was
> stepping into a fire swamp by even broaching the question. However, the
> application I'm envisioning (accessing web services from a desktop GUI)
> will benefit from the abundant Python libraries/wrappers that have
> already been written, which are mostly lacking (or which would require
> me to roll my own) in Tcl.
>

I can't possibly see how an available range of GUI toolkits is a
detriment to a *language*. I can see (but don't neccesarily agree)
that is detrimental to a desktop environment or whatever, but not a
language. By that standard C is the worst language to ever exist, C++
only marginally better, and stuff like Visual FoxPro the best of all.

>
>
> --
> Kevin Walzer
> iReveal: File Search Tool
> http://www.wordtech-software.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ordered sets operations on lists..

2006-02-11 Thread Alex Martelli
Raymond Hettinger <[EMAIL PROTECTED]> wrote:
   ...
> The intersection step is unnecessary, so the answer can be simplified a
> bit:
> 
> >>> filter(set(l2).__contains__, l1)
> [5, 3]
> >>> filter(set(l1).__contains__, l2)
> [3, 5]

...and if one has time to waste, "setification" being only an
optimization, it can also be removed: filter(l2.__contains__, l1) etc
(very slow for long lists, of course).

Personally, I'd always use (depending on guesses regarding lengths of
lists) [x for x in l1 if x in l2] or the setified equivalent, of course.


Alex


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


Re: only a simple xml reader value

2006-02-11 Thread uche . ogbuji
[EMAIL PROTECTED] wrote:
> The only thing I must read is the response I get from a EPP server.
> A response like this:
>
> 
> http://www.eurid.eu/xml/epp/epp-1.0";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns:contact="http://www.eurid.eu/xml/epp/contact-1.0";
> xmlns:domain="http://www.eurid.eu/xml/epp/domain-1.0";
> xmlns:eurid="http://www.eurid.eu/xml/epp/eurid-1.0";
> xmlns:nsgroup="http://www.eurid.eu/xml/epp/nsgroup-1.0";
> xsi:schemaLocation="http://www.eurid.eu/xml/epp/epp-1.0 epp-1.0.xsd
> http://www.eurid.eu/xml/epp/contact-1.0 contact-1.0.xsd
> http://www.eurid.eu/xml/epp/domain-1.0 domain-1.0.xsd
> http://www.eurid.eu/xml/epp/eurid-1.0 eurid-1.0.xsd
> http://www.eurid.eu/xml/epp/nsgroup-1.0 nsgroup-1.0.xsd">
> 
> 
> Command completed successfully; ending session
> 
> 
> 
> c-and-a.eu
>  c-and-a_1
> 25651602
> 2005-11-08T14:51:08.929Z
> 
> 
> 
> 
> 

So to get the msg, you can do:

print doc.getElementsByTagName('msg')[0].toxml()

But to get the domain:name you have to use the declared namespace:

print
doc.getElementsByTagNameNS('http://www.eurid.eu/xml/epp/domain-1.0',
'name')[0].toxml()

Or you can make life a bit easier with Amara [1]:

import amara
doc = amara.parse(theXML)
print doc.response.result.msg #to get the text content
print doc.response.result.msg.xml() #to get the XML source for that
element
print doc.response.resData.appData.name
print doc.response.resData.appData.name.xml()

[1] http://uche.ogbuji.net/tech/4Suite/amara/

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


Re: Legality of using Fonts

2006-02-11 Thread Chris Mellon
On 2/11/06, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Fri, 10 Feb 2006 20:24:34 -0800, Ross Ridge wrote:
>
> > Steven D'Aprano wrote:
> >> It is highly unlikely that any judge will be fooled by a mere change in
> >> format ("but Your Honour, I converted the TTF file into a bitmap").
> >
> > If that were true, almost the entire X11 bitmap font collection would
> > be illegal.  Fonts aren't subject copyright, just the hints in most
> > outline fonts, which are considered computer programs.
>
> This may come as a shock to you, but the USA is not the entire world, and
> the US government's decision to exclude typefaces from copyright
> protection is anomalous. In almost the entire rest of the world,
> typefaces (the design of a font) are able to be copyrighted, and so are
> fonts whether they are bitmapped or outline (with or without hints).
>
>
> See, for example: http://www.typeright.org/feature4.html
>
> In any case, even in the USA, hinted fonts are copyrightable, and merely
> removing the hints (say, by converting to a bitmap) is no more legal than
> whiting out the author's name from a book and claiming it as your own.
>

This is absolutely wrong. It is perfectly legal to extract the
non-copyrightable elements of a copyrighted work (the typeface itself,
in this case) and do whatever you want with it.

> Of course, like all these issues, the actual decision of a judge and jury
> in the USA is uncertain -- who knows whether they will consider a
> bitmapped version of a TTF font to be a derivative work or not? So even in
> the USA, unless you want to spend big dollars on legal fees, the best
> advice is to stick to fonts which are distributed under open licences.
>

I'd say this is a case that isn't uncertain at all. The lack of
protection for typefaces is not a loophole or unclear convention -
Congress and the copyright office explicitly refuse to extend
copyright protection to typefaces. The loophole, in fact, is the
protection of hinted fonts, which are only protected to the degree
that they are "computer programs", because they are *not* protectable
as fonts, period. Saying it is uncertain is not intellectually honest,
in my opinion.

Now, I personally feel that this is a case where Congress made a poor
decision on all counts - TTF files are a prime example of programs
that should not be copyrightable (mechanical implementation), and
typefaces should be. But that's not the state of affairs in the US.

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


Re: Determining an operating system's default browser

2006-02-11 Thread Jorgen Grahn
On 10 Feb 2006 03:51:01 -0800, Paul Boddie <[EMAIL PROTECTED]> wrote:
> John McMonagle wrote:
>> On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote:
>> > You don't have to determine it.  Just os.startfile('page1.html')
>> > and let the OS figure it out.
>>
>> Works great for Windows - not available on Unix though.
>
> Take a look at the desktop module for similar functionality for KDE,
> GNOME and the Mac OS X desktop environment (as well as Windows, of
> course):

Note that those do not, of course, work on all Unices.

On my machines, there is One Correct Way of doing these things, and that's
to look in the MIME support/configuration files (~/.mailcap, and so on),
first for the user, then system-wide. Something there might tell you what
program should handle text/html content.

This mechanism is widespread under Unix, I think ... but I don't know if
there is a general interface to it, or a Python interface.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rethinking the Python tutorial

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

AdSR

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


python 2.5 and hashlib

2006-02-11 Thread rtilley
Is there a road map for python a 2.5 releases yet? I'd like to begin 
testing the new hashlib module with some old scripts I have that 
currently use the md5 and sha modules.

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


Re: Determining an operating system's default browser

2006-02-11 Thread Paul Boddie
Jorgen Grahn wrote:
>

[desktop module]

> Note that those do not, of course, work on all Unices.

Correct: they work only for the stated desktop environments.

> On my machines, there is One Correct Way of doing these things, and that's
> to look in the MIME support/configuration files (~/.mailcap, and so on),
> first for the user, then system-wide. Something there might tell you what
> program should handle text/html content.

Indeed. Thanks for reminding me about mailcap/metamail - I used them in
a project about ten years ago, and I suppose not having any
opportunities to use them in the intervening period probably pushed
them to the back of my mind.

> This mechanism is widespread under Unix, I think ... but I don't know if
> there is a general interface to it, or a Python interface.

Here's an example:

import mailcap
command, entry = mailcap.findmatch(mailcap.getcaps(), "text/html")

Here's another more comprehensive set of examples:

http://effbot.org/librarybook/mailcap.htm

Sadly, when considering my KDE desktop's default browser, inquiring the
application for HTML files yields Mozilla Firefox from my mailcap file.
What I've discovered is that the issue of an URL-opening application is
often quite separate from an appropriate application to open a file of
a given type. Perhaps I should call desktop.open something like
desktop.urlopen instead, since that name arguably describes the purpose
of the function more accurately.

Paul

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


simple math question

2006-02-11 Thread John Salerno
Hi all. I'm just starting out with Python, so I'm a little slow right 
now. :)

Can someone explain to me why the expression 5 / -2 evaluates to -3, 
especially considering that -2 * -3 evaluates to 6?

I'm sure it has something to do with the negative number and the current 
way that the / operator is implemented, but why doesn't it evaluate to 
-2 instead?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing python on a server?

2006-02-11 Thread John Salerno
Dennis Lee Bieber wrote:
> On Sat, 11 Feb 2006 01:02:46 -0500, John Salerno
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>> Yikes, that's all the stuff I don't know. Maybe this is over my head 
>> right now.
> 
>   Let's start with something simple then... Do you have admin (root)
> privileges on this server machine -- or is it a machine belonging to
> some ISP and you are hoping to add Python/CGI capability?

I guess it might be the latter. What I want is to add Python capability 
to the server where my website is running, so that I can write Python 
web apps and incorporate them into my HTML files.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any books such as 'effective python' or else about the performance?

2006-02-11 Thread Jorgen Grahn
On Sat, 11 Feb 2006 07:54:46 -0600, Charles Krug <[EMAIL PROTECTED]> wrote:
> On 2006-02-11, Kenneth Xie <[EMAIL PROTECTED]> wrote:
>> att, thx.
>
> A lot of the ideas discussed in Effective C++ et al are things that
> Python does for us already.  C++ works at a much lower layer of
> abstraction

Yes.

> and you need to deal explicitly with freestore for any
> nontrivial class.

Not true.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Clearing the screen

2006-02-11 Thread mwt
I'm doing some python programming for a linux terminal (just learning).
When I want to completely redraw the screen, I've been using
os.system("clear")
This command works when using python in terminal mode, and in IDLE.
However, when running a little .py file containing that command, the
screen doesn't clear. 

What to do?

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


Re: Netstat in python. Does it's possible?

2006-02-11 Thread Jorgen Grahn
On Sat, 11 Feb 2006 16:28:06 +0100, Martin v. Löwis <[EMAIL PROTECTED]> wrote:
> billie wrote:
>> Hi all. I don't know if Python is good for this kind of jobs but I'm 
>> wondering if it's possible emulate the "netstat" command in Python.
>
> As a general recommendation, use strace(1) to answer this kind of
> question. Run "strace -o tmp netstat", then inspect tmp to find out
> how netstat obtained the information it reported.

Good idea.

There might still be a problem for people doing things like this: netstat
might use unstable or non-public APIs to find the things it lists. This is
fine because it's typically your OS vendor who have to handle that (ship
another netstat when the /proc or /sys file system layout changes, etc).

If it works like that, you can access the APIs fine from Python -- but you
cannot write a portable 'pynetstat' without a lot of effort and maintenance.

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clearing the screen

2006-02-11 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-11 às 12:04 -0800, mwt escreveu:
> I'm doing some python programming for a linux terminal (just learning).
> When I want to completely redraw the screen, I've been using
> os.system("clear")
> This command works when using python in terminal mode, and in IDLE.
> However, when running a little .py file containing that command, the
> screen doesn't clear. 
> 
> What to do?

There's one escape sequence that does what you want.

I am *not* sure if this solution is the correct one, but:

$ clear | hd
  1b 5b 48 1b 5b 32 4a  |.[H.[2J|
0007
$ python
Python 2.3.5 (#2, Nov 20 2005, 16:40:39)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print
chr(0x1b)+chr(0x5b)+chr(0x48)+chr(0x1b)+chr(0x5b)+chr(0x32)+chr(0x4a),
>>> # Clears the screen!

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

Re: simple math question

2006-02-11 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-11 às 14:52 -0500, John Salerno escreveu:
> Hi all. I'm just starting out with Python, so I'm a little slow right 
> now. :)
> 
> Can someone explain to me why the expression 5 / -2 evaluates to -3, 
> especially considering that -2 * -3 evaluates to 6?
> 
> I'm sure it has something to do with the negative number and the current 
> way that the / operator is implemented, but why doesn't it evaluate to 
> -2 instead?

It has to do with floating point operations. If you evaluate 5 / -2.0 or
5.0 / -2 you will have -2.5. It gives you -3 because of rounding to
integers. Look:

>>> round(-2.5)
-3.0
>>> round(+2.5)
3.0

This behavior is because -round(x) should be equal to round(-x).

Cya,
Felipe.

-- 
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

  -- Sun Tzu, em "A arte da guerra"

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

Re: python 2.5 and hashlib

2006-02-11 Thread Alex Martelli
rtilley <[EMAIL PROTECTED]> wrote:

> Is there a road map for python a 2.5 releases yet? I'd like to begin 
> testing the new hashlib module with some old scripts I have that 
> currently use the md5 and sha modules.

http://python.org/peps/pep-0356.html -- but it's still a draft, being
discussed in the last few days on python-dev.


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


Re: simple math question

2006-02-11 Thread James Stroud
John Salerno wrote:
> Hi all. I'm just starting out with Python, so I'm a little slow right 
> now. :)
> 
> Can someone explain to me why the expression 5 / -2 evaluates to -3, 
> especially considering that -2 * -3 evaluates to 6?
> 
> I'm sure it has something to do with the negative number and the current 
> way that the / operator is implemented, but why doesn't it evaluate to 
> -2 instead?

Its an integer expression.

Try '5.0/-2' or '5/-2.0' or 'float(5)/-2' or '5/float(-2)' and compare 
'5/-2' to '5/2'.

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


Re: simple math question

2006-02-11 Thread Rinzwind
'/' is a floor division (1/2 == 0) unless validated by a from
__future__ import division.

So:
5/2=2.5 -> nearest lowest non-decimal number makes it 2.
5/-2=-2.5 -> nearest lowest non-decilmal number makes it -3

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


Re: simple math question

2006-02-11 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes:
> Can someone explain to me why the expression 5 / -2 evaluates to -3,
> especially considering that -2 * -3 evaluates to 6?
> 
> I'm sure it has something to do with the negative number and the
> current way that the / operator is implemented, but why doesn't it
> evaluate to -2 instead?

Well, -2 * -2 is 4, which is not especially better than 6.  The
reason for choosing -3 instead of -2 is so that if b is positive,
then a%b is non-negative even if a is negative.  That is, the
motivating case is (-5 % 2) which is done the same way as (5 % -2).

You want (b*(a/b) + a%b)==a at all times.  If (-5 / 2) = -3, then you
need (-5 % 2) = -1.  But if (-5 / 2) = -2, then (-5 % 2) = +1.
Since a%b is positive, you can use it as a list index, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many if Statements?

2006-02-11 Thread Terry Reedy

"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Clearly it would be a good idea to remove whatever problem is causing
> the error,

The problem (see my post of the com_backpatch code) is writing a compound 
statement (here a for loop) with a body so large as to require a jump of 
more than 64K bytes in the compiled bytecode (ie, from the test at the top 
of the loop to the code that follows after the loop).  Until the jump limit 
is raised (likely a long wait ;-), the OP must factor some of the code out 
of the loop.

Terry Jan Reedy





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


Re: python 2.5 and hashlib

2006-02-11 Thread rtilley
Alex Martelli wrote:
> http://python.org/peps/pep-0356.html -- but it's still a draft, being
> discussed in the last few days on python-dev.

Thank you, that's exactly what I was looking for!
-- 
http://mail.python.org/mailman/listinfo/python-list


Is python very slow compared to C

2006-02-11 Thread diffuser78
I have just started to learn python. Some said that its slow. Can
somebody pin point the issue.

Thans

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


Re: Is python very slow compared to C

2006-02-11 Thread rtilley
[EMAIL PROTECTED] wrote:
> I have just started to learn python. Some said that its slow. Can
> somebody pin point the issue.

It depends on what you are doing. Much of Python is just wrapped C. So 
many things are very fast.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >