ANN: Leo 4.4 b4 released

2006-04-21 Thread Edward K. Ream
Leo 4.4 beta 4 is now available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This version fixes a long-standing MacOS bug.  It is likely to be the last 
beta release before 4.4 rc1.  This release also adds several new commands 
and contains a script for updating leoSettings.leo.

Warning: The previous beta was not widely distributed.  Please do some 
testing in your environment before recommending this version of Leo to 
others, (such as your students).

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name, with tab completion.

- Many new commands, including cursor and screen movement, basic character, 
word and paragraph manipulation, and commands to manipulate buffers, the 
kill ring, regions and rectangles. You can use Leo without using a mouse.

- Flexible key bindings and input modes. You can emulate the operation of 
Emacs, Vim, or any other editor.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Autocompletion and calltips.

- Dozens of other new features and bug fixes since Leo 4.3.3.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward

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


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: Pyrex 0.9.4.1

2006-04-21 Thread greg
Pyrex 0.9.4.1 is now available:

   http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

This is a very minor update to correct a tab/space
problem in the distutils extension.

What is Pyrex?
--

Pyrex is a language for writing Python extension modules.
It lets you freely mix operations on Python and C data, with
all Python reference counting and error checking handled
automatically.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Strategy Design Pattern

2006-04-21 Thread Alex Martelli
Daniel  Santa Cruz [EMAIL PROTECTED] wrote:
   ...
 I'm at a loss at how I can do this with Python, any pointers would be
 more than welcomed!

Check out my homepage, www.aleax.it, you'll find several PDFs for my
various presentations over the years: many have to do with DPs and
Python, and I specifically addressed Strategy in a couple of them.


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


Re: Activating Batch Files from Python

2006-04-21 Thread Atanas Banov

Jeff Groves wrote:

 How would I do that? As I've said, I haven't found a Python command
 that lets you send multiple commands to the same shell yet. If I could,
 my problem would be solved.

any reason why you cannot create a temp .bat, consisting of:

setvar.bat
prog1.exe
prog2.exe

and then execute it form perl?

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


Re: perspective on ruby

2006-04-21 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Edward Elliott [EMAIL PROTECTED] wrote:

The fact that even 
numeric literals are objects make me suspicious of Ruby as a 
general-purpose language though.

Isn't Python going that way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac

2006-04-21 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 ie does the first instance of the package a.b.c effectively mask out
 the others so that if a.b.c.common occurs first in the PYTHONPATH then
 a.b.c.project1 will never be found as the a.b.c package is only
 loaded from the a.b.c.common folder?

By default, yes. But there's a way around this limitation:

http://docs.python.org/lib/module-pkgutil.html 

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


Re: newbie OO question

2006-04-21 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Jeremy Winters [EMAIL PROTECTED] wrote:

 from SegmentValue import *

I remember in the old days a computing support guy saying he refused to 
help any users with FORTRAN questions unless they had an IMPLICIT NONE 
in every program block.

The corresponding rule nowadays would be no help to Java or Python 
programmers who use wildcard imports.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I call a python method from the XML-RPC client in Java?

2006-04-21 Thread Johnny deBris
[EMAIL PROTECTED] wrote:
 Hi all,
 I have created a XML-RPC model (with server and client) written in
 Java.
 I want to call the methods in another XML-RPC model written in
 Python.
 I know that in Java, I can use like
 xmlrpc_client.excute(handler_name.method, param) to call the
 methods in my xml-rpc server written in java.
But how can I call the methods in Python? I cannot creat a handler
 in my Python XML-RPC server.
 
Not sure what you mean by 'creating a handler in your Python RPC
server', but if you just want to use the Python XMLRPC library to make a
call to an XMLRPC server, there's an example in the documentation:

http://docs.python.org/lib/xmlrpc-client-example.html

Hope that helps.

Cheers,

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


Re: proposed Python logo

2006-04-21 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Michael Tobis [EMAIL PROTECTED] wrote:

Is this the right room for an argument?

http://geosci.uchicago.edu/~tobis/snake.png

Too rigid-looking somehow. I think get rid of the straight right-angle 
lines.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Activating Batch Files from Python

2006-04-21 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 Jeff Groves [EMAIL PROTECTED] wrote:

How about sourcing it from a shell, then using that same shell instance
to run the programs?

How would I do that? As I've said, I haven't found a Python command
that lets you send multiple commands to the same shell yet. If I could,
my problem would be solved.

What about os.popen? Otherwise there's the usual fork/exec thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I call a python method from the XML-RPC client in Java?

2006-04-21 Thread Eric Brunel
On 20 Apr 2006 11:31:23 -0700, [EMAIL PROTECTED] wrote:

 Hi all,
 I have created a XML-RPC model (with server and client) written in
 Java.
 I want to call the methods in another XML-RPC model written in
 Python.
 I know that in Java, I can use like
 xmlrpc_client.excute(handler_name.method, param) to call the
 methods in my xml-rpc server written in java.
But how can I call the methods in Python? I cannot creat a handler
 in my Python XML-RPC server.

I'm not quite sure I understand the question. You seem to say that you  
have both a client and a server in Java, and Python server. That means one  
client and 2 servers, right? Are both servers up and running? IOW, do you  
have a problem to *call* the Python server from the Java client, or to  
*write* the Python server? Can you post some code (maybe not the full one,  
but a simpler version showing what you're trying to do and what does not  
work)?
-- 
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a subprocess qns

2006-04-21 Thread Lawrence D'Oliveiro
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:

i wanted to start execute a command and put it in the background. i am
using Unix.
Usually i start this command using something like this :
/path/somecmd   with the  to put it to background.

Even if it's in the background with , it is still liable to get 
killed with a SIGHUP signal when you log off.

To stop this, you need to make sure the process is in its own process 
session group, by using the setsid system call. Not sure if there's any 
standard Python binding for this: but there is a setsid command that you 
could use from the shell.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py.test munging strings in asserts?

2006-04-21 Thread Johnny deBris
Timothy Grant wrote:
 
 granted the left side of that equality could be messed up due to
 create_output() NOT doing the right thing. But the right side is
 simply the contents of the variable text so WHY is the first part of
 the path being substituted with ...?
 
Some grepping on '...' revealed that there's some string munging going
on in py/code/safe_repr.py, In py/test/terminal/terminal.py, in
TerminalSession, there's a method 'repr_locals' that uses it, I guess
you have to override that or something if you want to change this
behaviour...

Cheers,

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


OT: Mozart (was Re: perspective on ruby)

2006-04-21 Thread Dave Benjamin
On Thu, 20 Apr 2006, Alex Martelli wrote:

 Edward Elliott [EMAIL PROTECTED] wrote:
   ...
 course in C++ doesn't cut it, the curriculum should either use different
 languages fitted to each task or emphasize a single language with broad
 abilities (picking the best programming model for each task).  Java is

 The only single language I could see fitting that role is Mozart,
 deliberately designed to be SUPER-multi-paradigm -- not even Lisp and
 Scheme (the only real competition) can compare.

I agree that Mozart/Oz is probably the most ambitiously multi-paradigm 
language out there, and anyone interested in some real mind expansion 
should really check out the excellent book, Concepts, Techniques, and 
Models of Computer Programming by Peter Van Roy and Seif Haridi.

However, my impression of Mozart/Oz so far can be summed up like this: 
You can have any paradigm you want, as long as it's concurrent. The 
degree to which out-parameters are used (in the form of dataflow 
variables) is very unusual for OO or FP, and this is a source of both 
amazement and confusion for me. It's clearly possible to program in many 
styles, but you still need to adapt your thinking to the Mozart way.

Also worth a mention is Alice ML, which runs on the Mozart system but is 
statically typed, type-inferred, very similar to SML but with concurrency 
support (lazies and futures), typesafe marshalling, and packages, which 
allow for dynamically-typed interfaces between modules.

-- 
.:[ dave benjamin -( ramen/sp00 )- http://spoomusic.com/ ]:.
one man's constant is another man's variable - alan perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


python-mysql on Windows -- How to?

2006-04-21 Thread Chris Seymour
Can anybody provide any guidance on what I will need to do get
mysql-python setup on my win xp workstation?  I have Mysql 4.1
installed and activepython 2.4.3 installed.

What do I need to do to install/setup mysql-python?

Thanks.

Chris

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


Re: Strategy Design Pattern

2006-04-21 Thread Kay Schluehr
Daniel  Santa Cruz wrote:
 Hello all,

 I've been trying to go over my OO Patterns book, and I decided to try
 to implement them in Python this time around.  I figured this would
 help me learn the language better.

I guess it might help clarifying what OO is about since you see what
happens when you try to transform solutions across languages with very
different type systems.

 Well, I've gotten stuck with my first go at OO patterns with Python.  I
 guess it goes without say that some of the stuff that are taken for
 granted in most of the books (ie. Interfaces, Abstract classes) don't
 really apply to Python per say, but the idea behind the patterns can be
 extracted out still.  In the specific case of the Strategy pattern, I
 think the goal is to abstract out of the class an algorithm that can
 then be reused by some of the inherited classes.  This way we don't
 repeat ourselves.  Maybe I got this all wrong...

Well, yes, I disagree ;) From my point of view the StrategyPattern is
used to decouple the consumer/client/user of an algorithm from it's
implementation. If you need variations of the implementation of your
algo you don't want variations in the user. It's not about a tower of
abstractions in the Strategy itself. Those abstractions are there for
the purpose of enabling polymorphism.

If you want a straightforward translation you start with a Strategy
class and derive strategies from it:

class Strategy(object):
def Evaluate(self):
 raise NotImplementedError# making it abstract

class StrategyA(Strategy):
def Evaluate(self):
 print Evaluate StrategyA

class StrategyB(Strategy):
def Evaluate(self):
 print Evaluate StrategyB

This is very clean OO but you don't actually need the Strategy base
class because Pythons type system does not enforce a well known type at
compile time. In some sense also the StrategyX classes are overhead
because you can pass the Evaluate methods directly to the consumer:
functions are always first class objects. So the Strategy might be
reduced to:

def EvaluateA(self):
 print Evaluate StrategyA

def EvaluateB(self):
 print Evaluate StrategyB

def consumer(evaluate):
 evaluate()

 consumer(EvaluateB)
Evaluate StrategyB

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


Property In Python

2006-04-21 Thread sushant . sirsikar
Hi,
  I want to know how we can write Properties in Pyhton.Any one knows
good doc for this one?
Thanks

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


Re: Property In Python

2006-04-21 Thread gangesmaster
class person(object):
def _get_age(self):
return self.__age
age = property(_get_age) # a read-only property

def _get_name(self):
return self.__name
def _set_name(self, value):
self.__name = value
name = property(_get_name, _set_name)

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


Re: a subprocess qns

2006-04-21 Thread Ben C
On 2006-04-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 hi
 i wanted to start execute a command and put it in the background. i am
 using Unix.

If you use subprocess, or even os.spawn, it should be portable and work
on all systems (although the docs list some restrictions).

 Usually i start this command using something like this :
 /path/somecmd   with the  to put it to background.

You can still do that: os.system(/bin/mycmd ), or use
subprocess.Popen with True in its shell parameter. os.system invokes the
shell, so this is not portable-- you must have a shell in which  means
what you want (it works at least on bash and probably on some other Unix
shells).

 i looked at the subprocess module docs and came across this statement
 Replacing os.spawn*
 ---
 P_NOWAIT example:
 pid = os.spawnlp(os.P_NOWAIT, /bin/mycmd, mycmd, myarg)
==
 pid = Popen([/bin/mycmd, myarg]).pid


 Can i ask if P_NOWAIT means the same as  ?? so if it is, then  this
 statement

I think it does.

 pid = os.spawnlp(os.P_NOWAIT, /bin/mycmd, mycmd, myarg)

 will put mycmd into background and return to the caller...?

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


Re: Strategy Design Pattern

2006-04-21 Thread Ben Sizer
Daniel  Santa Cruz wrote:
 Well, I've gotten stuck with my first go at OO patterns with Python.  I
 guess it goes without say that some of the stuff that are taken for
 granted in most of the books (ie. Interfaces, Abstract classes) don't
 really apply to Python per say, but the idea behind the patterns can be
 extracted out still.

In the original Design Patterns book, the authors pointed out that
although patterns are generally language-agnostic, the need for
formalised patterns to achieve a given goal is not. One example is
inheritance - if you're programming in C then you'd need a formal
pattern to model inheritance effectively, but in many other languages
it's built in. It may be the case that Python gives you the tools to
make some other patterns effectively redundant.

 In the specific case of the Strategy pattern, I
 think the goal is to abstract out of the class an algorithm that can
 then be reused by some of the inherited classes.  This way we don't
 repeat ourselves.  Maybe I got this all wrong...

The goal is to allow an object to have a certain behaviour which uses
an algorithm you can change by changing the object that performs that
algorithm. It essentially means you can change the algorithm later
without changing the object.

In Python, this is quite simple - decide upon an interface that the
algorithm should provide, and then assign an object that implements
that interface to your object. The object will then pass its data to
the interface methods on whichever algorithm object it's been given.

 To aid commenters... we can use the example used in Head First Design
 Patterns.  I've implemented this simple patter in Java and .NET... now
 in python.  I can't draw UML here, so I'll try to pseudo talk what the
 example has:

 Abstract Base Class: Duck
 + FlyBehavior _fly
 + swim()
 + fly() - calls _fly.fly()

 Interface: FlyBehavior
 + fly()

 Concrete Interface FlyHigh (implements FlyBehavior):
 + fly()

 Concrete Class Duck1 (Inherits Duck):
 + Constructor: _fly = new FlyHigh()

In this example, you can just assign a FlyHigh function to your Duck1 -
no Duck or FlyBehavior classes needed. The pattern is almost pointless
in situations like this when your language allows you to quickly and
easily assign functions between objects. However if, as is common, you
need more than 1 function in the interface, you can put them in an
object and assign that.

class FlyHigh(object):
def TakeOff(self, bird):
print take off to fly high
def Land(self, bird):
print land from flying high

class FlyLow(object):
def TakeOff(self, bird):
print take off to fly low
def Land(self, bird):
print land from flying low

class Duck(object):
def __init__(self, flyingBehavior):
self.flyBehavior = flyingBehavior
def TakeOff(self):
self.flyBehavior.TakeOff(self)
def Land(self):
self.flyBehavior.Land(self)

lowFlyingDuck = Duck(FlyLow())
highFlyingDuck = Duck(FlyHigh())


Note that I don't claim the above code is necessarily optimal (or even
correct!) but it should show that half of the Strategy pattern
boilerplate is unnecessary in Python. You can even use certain Python
tricks to automatically delegate calls on Duck to the behavior classes
without typing those out individually, for example.

-- 
Ben Sizer

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


Re: Strategy Design Pattern

2006-04-21 Thread Gerard Flanagan
Daniel  Santa Cruz wrote:
 Hello all,

 I've been trying to go over my OO Patterns book, and I decided to try
 to implement them in Python this time around.  I figured this would
 help me learn the language better.

 Well, I've gotten stuck with my first go at OO patterns with Python.  I
 guess it goes without say that some of the stuff that are taken for
 granted in most of the books (ie. Interfaces, Abstract classes) don't
 really apply to Python per say, but the idea behind the patterns can be
 extracted out still.  In the specific case of the Strategy pattern, I
 think the goal is to abstract out of the class an algorithm that can
 then be reused by some of the inherited classes.  This way we don't
 repeat ourselves.  Maybe I got this all wrong...

 I'm at a loss at how I can do this with Python, any pointers would be
 more than welcomed!


This is my understanding of the Strategy Pattern:

(Perhaps I have a SudokuSolver class that will solve *any* Sudoku
puzzle, but it's very slow for simple puzzles because of some
unavoidable overhead related only to the more difficult puzzles - so I
want to try a simpler but faster method first, if it doesn't succeed
then use the more complex method.)

class SudokuGrid(object):
def __init__(self, solver=None):
self.grid = [[-1]*9]*9
if solver is not None:
self.solver = solver
else:
self.solver = SimpleSudokuSolver()

def solve(self):
self.solver.sudoku = self
self.solver.solve()

class SimpleSudokuSolver(object):
sudoku = None
def solve(self):
print 'solving %s ...simple algorithm...' % repr(self.sudoku)

class DifficultSudokuSolver(object):
sudoku = None
def solve(self):
print 'solving %s ...difficult algorithm...' %
repr(self.sudoku)

s = SudokuGrid()

s.solve()

s.solver = DifficultSudokuSolver()

s.solve()

solving __main__.SudokuGrid object at 0x0117D390 ...simple
algorithm...
solving __main__.SudokuGrid object at 0x0117D390 ...difficult
algorithm...

HTH

Gerard

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


Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac

2006-04-21 Thread bruno at modulix
alisonken1 wrote:
 As to the question fail to see how version control relates to
 code/test separation, the original poster asked several questions, one
 of which was production/testing code separation.
 
 Along with the separation (so while you're testing new functionality,
 you don't break production files), a properly setup CVS allows you to
 do this by importing files from a production branch into your testing
 branch 

Ok, get it - you're talking about branching,  when the OP talked about
unit testing, which is something totally different.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search files in a directory

2006-04-21 Thread bruno at modulix
Gary Herron wrote:
 david brochu jr wrote:
 
 Hello,
  
 I need to open every file in a directory and search for a string. What
 module is needed to do this and how would I go about searching each file?

[bash] find /path/to/dir -exec grep -le searched string {} \;

Ho, you meant : doing this in Python ?-)


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Property In Python

2006-04-21 Thread bayerj
 print property.__doc__
property(fget=None, fset=None, fdel=None, doc=None) - property
attribute

fget is a function to be used for getting an attribute value, and
likewise
fset is a function for setting, and fdel a function for del'ing, an
attribute.  Typical use is to define a managed attribute x:
class C(object):
def getx(self): return self.__x
def setx(self, value): self.__x = value
def delx(self): del self.__x
x = property(getx, setx, delx, I'm the 'x' property.)

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


Re: Strategy Design Pattern

2006-04-21 Thread bruno at modulix
Daniel Santa Cruz wrote:
 Hello all,
 
 I've been trying to go over my OO Patterns book, and I decided to try
 to implement them in Python this time around.  I figured this would
 help me learn the language better.
 
 Well, I've gotten stuck with my first go at OO patterns with Python.  I
 guess it goes without say that some of the stuff that are taken for
 granted in most of the books (ie. Interfaces, Abstract classes) don't
 really apply to Python per say, but the idea behind the patterns can be
 extracted out still. 

A good part of the GoF patterns are meant to add flexibility to static
languages - translating them directly in a dynamic language may not be
such a good idea. Regarding abstract base classes (Java's interfaces
being a special case of abc), they are mostly used in static languages
to provide support for polymorphic dispatch. This is not needed in
Python, where polymorphic dispatch is not tied to inheritance.

FWIW, it's still possible to have abc in Python:

class Abc(object):
  def abstractMethod(self, args):
raise NotImplementedError(Abc is an abstract class)

 In the specific case of the Strategy pattern, I
 think the goal is to abstract out of the class an algorithm that can
 then be reused by some of the inherited classes.  This way we don't
 repeat ourselves.  Maybe I got this all wrong...

The first part (abstract an algorithm out of the class) is ok. The real
goal is to allow to dynamically select the algorithm to use based on
runtime conditions (ie: user prefs, platform-specific stuff, size of a
file, phase of the moon, whatnot...).

 I'm at a loss at how I can do this with Python, any pointers would be
 more than welcomed!

Hint 1: Python's functions are objects
Hint 2: Dynamically attaching a method to an object (ie : not to the
whole class) is easy as pie (search this group...).
Hint 3: Any object having a __call__() method is callable.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


threading, how to?

2006-04-21 Thread akrapus
Hi,

I am trying to understand how to use threading in Python. I get
threading as a concept, but not the implementation.

In order to start threading, do you call it as a separate function,
which will then be applied to the rest of the code (functions) or do
you open threading in each function. This all can probably be answered
by 'How python threads different functions'?

Hope if somebody can drop me a few lines. I've been trying with
different tutorials, but still do not understand.

Cheers,

Stevan

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


Re: the whole 'batteries included' idea

2006-04-21 Thread Ben Sizer
John Salerno wrote:
 Pardon my naivety, you would think maybe I'd understand this by now, but
 I've always kind of wondered about it. I've been curious why one of the
 biggest points used to promote Python is that it has batteries
 included. True, this is a great feature, but the way it's been used
 seems to suggest that other languages *don't* have this benefit. And
 maybe they don't, in their own way.

 So my question is, what is the difference between Python's 'batteries'
 (standard modules), and C#'s framework?

I can't speak for C#'s framework but Python has a lot of modules that
other languages may not, such as zip/bzip archive handling, unit
testing, database interface modules, pretty much any network protocol
you might need, both types of XML handling, etc. For many tasks, it's
complete as-is, and that's a point worth selling.

I don't think it's as good as some people make out, though. Multimedia
support is poor - OpenGL support should have gone in many, many
versions ago, and presumably one of the trillion incarnations of
libraries for fast mathematics should have gone in too in order to
enable that. PyGame could possibly have gone in too (not sure about the
license however).

-- 
Ben Sizer

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


Re: Thanks from the Java Developer

2006-04-21 Thread Kent Johnson
Alex Martelli wrote:
 Ant [EMAIL PROTECTED] wrote:
 
 Python ruined my life.

Python ruined me for Java coding too.

 At least in the Bay Area, the jobmarket for Python programmers is wild,
 right now -- firms such as Google, Pixar, BitTorrent, IronPort, etc,
 etc, all hungry for Pythonistas -- BayPIGgies mailing list bitching over
 too many job-offer posts, and the nuisance of all those recruiters
 haunting our monthly meetings and how much time they take, ...!!!

Hmm...eagerly awaiting this phenomenon to reach the Boston area. Python 
seems to be mostly used for QA around here.

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


Re: proposed Python logo

2006-04-21 Thread Ant
Sorry dude, but it looks like a hairdryer! Imagine it at 16x16 pixels
or smaller, and it'll look like little more than a circle with two
sticks. The current image scales well.

I think that the current logo is fine. Much more professional than the
old image. The + formation is positive enough, and it has a yin-yang
feel to it which to me conjures up the image of balance, not
divisiveness.

JM2PW

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


Re: threading, how to?

2006-04-21 Thread Sergei Organov
akrapus [EMAIL PROTECTED] writes:

 Hi,

 I am trying to understand how to use threading in Python. I get
 threading as a concept, but not the implementation.

 In order to start threading, do you call it as a separate function,
 which will then be applied to the rest of the code (functions) or do
 you open threading in each function. This all can probably be answered
 by 'How python threads different functions'?

Python doesn't automatically thread anything. Threading in Python is
manual. The idea is that you run your own function in a separate thread
of execution that you create. All the functions that you call from the
mentioned function (and those that they call, etc.) will then run in
those thread of execution.

You can create as many threads (probably up to some limit) as you wish
and call either the same function from them, or different functions,
depending on your application requirements.

-- Sergei.

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


are docstrings for variables a bad idea?

2006-04-21 Thread jelle
That's basically the idea...
Often i find myself annotating what variables actually stand for, so to
refer back to the code in half a year or so.

 # check if ID's or coords
self.pointIDs = ptIDs
self.coords   = [tuple(RS.PointCoordinates(i)) for i in ptIDs]

# map ids/coords and coords/ids
self.pointID_2_Coord, self.coord_2_pointID = {}, {}
for id, coord in zip(self.pointIDs,self.coords):

self.coord_2_pointID[coord] = id
self.pointID_2_Coord[id]= coord

# initiate kdtree
self.kdTREE = kdtree.kdtree(3)
for i in self.coords:
self.kdTREE.addPoint(i)

# break down interfaceCrvID
self.segments = list(RS.ExplodeCurves(interfaceCrvID))

# dictionary with a midpoint for each segment
self.segmentCoords = {}
for i in self.segments:
self.segmentCoords[i] = list(RS.CurveMidPoint(i))

and so on...
Please don't say that naming variables properly suffices for any
skilled programmer... really...

When programming a more complex class, it would be quite helpful that
these annotations would pop-up as a docstring.
Often I find myself referring back to a module containing the class to
read back what data the variable holds exactly. A time consuming
activity that could be seriously sped up by a proper IDE
(I'm on SPE, thanks Stani!)

Would that make sense to anyone?

cheers,

-jelle

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


Re: threading, how to?

2006-04-21 Thread akrapus
Thanks for reply.

So would it be implemented as follows:

Func 1
Func 2
Func 3

Thread for Func 1
Thread for Func 2
Thread for Func 3

Cheers

Stevan

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


Re: threading, how to?

2006-04-21 Thread Diez B. Roggisch
akrapus wrote:

 Thanks for reply.
 
 So would it be implemented as follows:
 
 Func 1
 Func 2
 Func 3
 
 Thread for Func 1
 Thread for Func 2
 Thread for Func 3

Could be, but the you woul most probably subclass threading.Thread and
override the run-method.

However, often it is done like this:

def some_threaded_function():
while though_shalt_work():
 do_work()


for i in xrange(THRAD_NUM):
t = threading.Thread(target=some_threaded_function)
t.start()


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


Re: threading, how to?

2006-04-21 Thread Sergei Organov
akrapus [EMAIL PROTECTED] writes:

 Thanks for reply.

 So would it be implemented as follows:

 Func 1
 Func 2
 Func 3

 Thread for Func 1
 Thread for Func 2
 Thread for Func 3

Yes, if you wish to run every of your 3 functions in a separate thread.

-- Sergei.

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread Diez B. Roggisch
jelle wrote:

 That's basically the idea...
 Often i find myself annotating what variables actually stand for, so to
 refer back to the code in half a year or so.
 
  # check if ID's or coords
 self.pointIDs = ptIDs
 self.coords   = [tuple(RS.PointCoordinates(i)) for i in ptIDs]

You aren't annotating variables - you describe what the next lines are
supposed to do, possibly involving new variables. Nothing new here...

I don't know for sure what you mean by pop up as doc-string - I guess you
want them magically merged into the functions doc string, at least inside
your editor? That sure could be done - but I personally don't think that is
too useful. Because you lose context. It might be that a particular comment
only applies inside an if-statement. So at least indention should be
preserved. But then - why not just look at the source...

IMHO commenting the parameters and results of a function is what someone
needs who skims the docs for enlightenment. I don't care _how_ a function
works, but _what_ it does. If I need the former, there is nothing that
works beside looking at the source - of course good comments ease the task
of understanding what's going on.

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


Joining stdout stderr of subprocess ?

2006-04-21 Thread robert

when I run a command

myapp 21


yet:

#!python
print os.popen(myapp 21).read()

the stderr stuff comes all after the stdout stuff.
How can I get ahold of all the out and err joined synchronously in the 
order, it is created ?


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


Re: Looking for a programming resource for newbees

2006-04-21 Thread bruno at modulix
bambooforest wrote:
 Hi all,
 
 I'm from a Linguistics background and am new(er) to programming. Could
 someone recommend a book or resource that teaches programming aspects
 with Python? Python I hear is a very appropriate language for handling
 text and language processing.

You may want to have a look at David Mertz's Text Processing in Python
 I'm searching for a resource that examines programming from a case
 study like perspective. Such as, you're faced with problem of type X -
 and here's how you should look at it to break it down to form an
 optimal solution (e.g. because this type or problem is handled well
 with this type of data structure, etc.).
 
 I've looked at the online Python tutorial at python.org and resources
 like O'Reilly's Python in a Nutshell, but they seem to teach you
 language syntax and concepts like data types, or assume you already
 know how to program. I'm searching for something that teaches
 programming. 

Learning to program usually imply learning the syntax and concepts of at
least one language.

Like with natural languages, there are some concepts that are difficult
if not impossible to express in some languages - so sometime you need to
learn a new language if you want to grasp the concept. Some other
concepts you'll find, one way of another, in almost any language, so for
more advanced books/tutorials/whatever, knowledge of these concepts is a
prerequisite - just like a book on grammar suppose that the reader knows
at least how to read and write, what's a verb, a sentence, a word, etc...

Also, like natural languages, programming languages also have idioms,
and learning these idioms is a non-trivial part of learning a language.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: send cookie on request with urllib2

2006-04-21 Thread itay_k
ok.
i will explain what exactly i wanna do.

i want to simulate the following client-side script with python:
body
img name=Pic

script
document.cookie=name=tom;
document.images[Pic].src=temp2.html
/script

what that happen here, is when this page loading, the browser loads
temp2.html with HTTP header:
Cookie: name=tom;

this cookie does not come for the server, this is temporary cookie that
sending from the client to the server.
this cookie doesnt save on disk at all.

is it possible to implements this at python??

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


Re: python-mysql on Windows -- How to?

2006-04-21 Thread BartlebyScrivener
Chris,

I'm no expert, but this keeps coming up and the last several people
have had better luck with mxODBC.

http://tinyurl.com/fmp3y

But if you're set on MySql-Python someone will jump in to help.

rick

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


Re: threading, how to?

2006-04-21 Thread Iain King
akrapus wrote:
 Thanks for reply.

 So would it be implemented as follows:

 Func 1
 Func 2
 Func 3

 Thread for Func 1
 Thread for Func 2
 Thread for Func 3

 Cheers

 Stevan

Here's how I'm doing it, using the thread module (there's a higher
level class-based module: threading, but I'm more comfortable with the
simple one):

import thread, time

class ThreadDemo:
def __init__(self):
self.data = []
self.lock = thread.allocate_lock()
self.alive = False


def Start(self):
self.alive = True
thread.start_new_thread(self.Process, (None,))


def Stop(self):
self.alive = False


def Process(self, dummy=None):
while self.alive:
self.lock.acquire()
self.data.sort()
self.lock.release()
time.sleep(0.05)


def Add(self, value):
self.lock.acquire()
self.data.append(value)
self.lock.release()

 from ThreadDemo import ThreadDemo
 demo = ThreadDemo()
 demo.Start()
 demo.Add(1)
 demo.Add(5)
 demo.Add(2)
 demo.data
[1, 2, 5]
 demo.Add(3)
 demo.data
[1, 2, 3, 5]
 demo.Stop()
 demo.Add(4)
 demo.data
[1, 2, 3, 5, 4]

Use the lock whenever you are going to modify data which is shared
between more than one thread.  Using time.sleep stops the thread from
hogging CPU cycles.  You only need to sleep a few milliseconds.  The
thread will clean itself up as soon as it's function (in this case
Process) finishes.  The ugly (None,) tuple in the start_new_thread /
dummy=None Process parameter are because the start_new_thread function
demands a tuple of arguments, even when none are required.
see http://www.python.org/doc/current/lib/module-thread.html for more
info.

Iain

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


Re: threading, how to?

2006-04-21 Thread [EMAIL PROTECTED]
Here's a recipe I used a lot:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65448

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


Re: PyLint 0.11 / astng 0.16

2006-04-21 Thread vj
It does. In my case I'm thinking of embedding pylint to check user
scripts which are written in python.

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


RE: proposed Python logo

2006-04-21 Thread Michael Yanowitz
   How about having something from Monty Python in the logo rather
than something snakelike. Python was named after Monty Python and not
the snake. Snakes also don't appear friendly to me.
  I used to have rats as pets. Snakes are murderers of rats. Which I
do find strange that there is a rat on the cover of Learning Python
by Oreilly but a Python snake on the Progamming Python by Oreilly
book.
   I think something from Monty Python (I haven't watched it recently
to know what would be ideal) would be more appropriate than an ugly
reptile which is usually associated with evil and our reason for leaving
the Garden of Eden.

  (Take me serious or not, I don't care, this is just my opinion,
but with a little humor.)

Thanks in advance:


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Ant
Sent: Friday, April 21, 2006 6:31 AM
To: python-list@python.org
Subject: Re: proposed Python logo


Sorry dude, but it looks like a hairdryer! Imagine it at 16x16 pixels
or smaller, and it'll look like little more than a circle with two
sticks. The current image scales well.

I think that the current logo is fine. Much more professional than the
old image. The + formation is positive enough, and it has a yin-yang
feel to it which to me conjures up the image of balance, not
divisiveness.

JM2PW


  I would like to see a Python Logo
-- 
http://mail.python.org/mailman/listinfo/python-list


BackgroundCall as Pythonic Thread - Re: threading, how to?

2006-04-21 Thread robert
akrapus wrote:

 Hi,
 
 I am trying to understand how to use threading in Python. I get
 threading as a concept, but not the implementation.
 
 In order to start threading, do you call it as a separate function,
 which will then be applied to the rest of the code (functions) or do
 you open threading in each function. This all can probably be answered
 by 'How python threads different functions'?
 
 Hope if somebody can drop me a few lines. I've been trying with
 different tutorials, but still do not understand.

It think many Python newcomers have similar questions (and confusion 
worries about those other answers).

Maybe thats because they bought the thread/threading.Thread/Queue stuff 
and confusion from Java, C++ and that like.( And even encourages that 
throw-and-pray .join()

This recipe offers BackgroundCall, which (example) you can probably 
understand fuildly within a second:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491280

Thus, you could forget about the technical term thread.
As you write yoursef ..call it as a separate function..: Thats how 
(new) Python programmers think naturally ?


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


ANN: Pyrr 0.1 - Lexer and LR(1)-Parser Generator for Python

2006-04-21 Thread Heiko Wundram
Hi list!

Not long ago I was looking for an easy to use, but powerful parser and lexer 
generating tool for Python, and to my dismay, I found quite a number of 
Python projects implementing an (LA)LR(1) parser generator, but none of them 
seemed quite finished, or even pythonic.

As I required a parser generator for Python for one of my work projects, I set 
out to write (yet another one), and currently am at (release-)version 0.1 for 
Pyrr.ltk and ptk.

An example for Pyrr.ltk and ptk usage implementing a (very) simple calculator:


# -*- coding: iso-8859-15 -*-

from ltk import LexerBase, IgnoreMatch
from ptk import ParserBase
from operator import add, sub, mul, div

class NumLexer(LexerBase):

def number(self,value):
number - r/[0-9]+/
return float(value)

def ws(self,*args):
ws - r/\\s+/
raise IgnoreMatch

def ops(self,op):
addop - /+/
 - /-/
   mulop - /*/
 - r/\\//
return op

class NumParser(ParserBase):
/mulop/: left
   /addop/: left
__start__ = term

def term(self,value1,op,value2):
term - term /addop/ term
- term /mulop/ term
return {+:add,-:sub,*:mul,/:div}[op](value1,value2)

def value(self,value):
term - /number/
return value

print NumParser.parse(NumLexer.tokenize(3 + 4 - 123 / 23))


Grammar rules and lexemes are specified in docstrings, where lines not 
matching a definition of a rule or lexeme are ignored. The resulting lexer 
and parser class is, thus, very much self-documenting, which was one of my 
biggest goals for the project.

I'm currently in the process of writing documentation for both packages (and 
especially documenting the extensions to BNF-grammars that Pyrr.ptk allows, 
such as your usual RE-operators ?, *, + and {x,y}, and forward arguments, and 
documenting the stateful lexer support that Pyrr.ltk implements), but I 
thought that I'd release early and often, so that people interested in this 
project might have a look at it now to input suggestions and extensions that 
they'd like me to add to make this a fully featured Python parser generating 
toolkit which might be offered as a Python package.

Anyway, the sources can be downloaded (via subversion) from:

http://svn.modelnine.org/svn/Pyrr/trunk

where I'll check in the documentation that I've written so far and a Python 
distutils distribution over the weekend, and make sure that I don't check in 
brocken code from now on. And, Pyrr.* is Python 2.4 only at the moment, and I 
have no plans to make it backwards-compatible, but if you're interested in 
backporting it, feel free to mail me patches.

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


python equivalent of VB code sample

2006-04-21 Thread mirandacascade
Situation is this:
1) must write application that does the following:
 a) creates an xml document, the contents of which, is a request
transaction
 b) send xml document to destination; I am assuming that a process
at destination side processes the request and sends back a response
 c) the application I'm writing must receive response and then
examine contents of response
2) hope to write client application in python
3) was provided VB code sample that does steps 1a, 1b and 1c; the
sample code is:

' section of code that builds the string sXML; the contents of which
is a request transaction
set objXML = Server.CreateObject(MSXML2.ServerXMLHTTP)
 'Bank table image address field, location of Comm Admin.
sServer = Session(ImageAddress)
 'NT AUTH
' note: I believe the next 2 lines in this post are really one line in
VB code that wrapped
' because they didn't fit on one line in the post
objXML.open
POST,sServer,false,Session(WebServerUserAuth),Session(WebServerPassword)
objXML.send sXML
sXMLRs = objXML.responseText

It appears as though much of the work is handled within methods and
properties of the objXML object:
 a) the open method appears to establish the connection with the
destination side
 b) the send method appears to handle both sending the request and not
returning control back to program until a response has been provided
 c) the .responseText property appears to be the contents of the
response

My questions are:
1) is it possible to develop a python script that does the equivalent
of the code sample above?
2) is the code sample above an example of what's referred to as an
'HTTP POST'?
3) I looked in the python documentation that describes urllib, urllib2
and httplib; am I looking in the right place?
4) are there other places I should be looking, particularly if I am
seeking samples of python code that are functionally similar to the
sample code above?

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


Re: Joining stdout stderr of subprocess ?

2006-04-21 Thread Duncan Booth
robert wrote:

 
 when I run a command
 
 myapp 21
 
[ I guess you meant to say here that the stdout, stderr output was 
interleaved ]
 
 yet:
 
 #!python
 print os.popen(myapp 21).read()
 
 the stderr stuff comes all after the stdout stuff.
 How can I get ahold of all the out and err joined synchronously in the 
 order, it is created ?
 
I think what is happening here is that in the first case the output is to a 
terminal, so myapp doesn't buffer its output. In the second case the output 
isn't going to a terminal so myapp is buffering it and only produces output 
when the buffer is full. Probably there isn't sufficient stderr output to 
force any out until myapp terminates, so you get it all at the end.

Probably the only way to get the output interleaved is to change myapp so 
that it doesn't buffer its output or so it sends all of its output to a 
single stream.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: quick surface plots

2006-04-21 Thread buchstaebchen

Thanks folks...

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


Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac

2006-04-21 Thread Fabio Zadrozny
COMMONsrca.b.c.commontesta.b.c.common
Ok, first thing... it won't work becaus as soon as python finds the first a.b.c.common it will bail on the other... That's the default approach for java, becase it will give you access to module-level things declared as 'default', that otherwise you wouldn't have access (in python all are grown-ups, so that's not necessary) and it won't bail out in the first match. So, in python, you'd probably do something as: test/test.a.b.c.common or create a tests dir as src/a.b.c.common.tests (I guess there are other solutions, but those 2 seem more appealing to me -- coming from a java background).
I believe you'd be able to keep that structure and play with the pythonpath if you wanted, but it could be too brittle in the end, and lead to hard-to-discover problems.Cheers,Fabio

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

Re: Joining stdout stderr of subprocess ?

2006-04-21 Thread Piet van Oostrum
 robert [EMAIL PROTECTED] (R) wrote:

R when I run a command

R myapp 21


R yet:

R #!python
R print os.popen(myapp 21).read()

R the stderr stuff comes all after the stdout stuff.
R How can I get ahold of all the out and err joined synchronously in the
R order, it is created ?


Make sure that myapp writes it synchronously. Probably myapp has it
buffered, so it writes out at the end of the run. It is not caused by
python. 

-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: are docstrings for variables a bad idea?

2006-04-21 Thread jelle
---I don't know for sure what you mean by pop up as doc-string - I
guess you
want them magically merged into the functions doc string, at least
inside
your editor? That sure could be done - but I personally don't think
that is
too useful. Because you lose context.---

point taken. perhaps only variables declared in the __init__ should be
made available as a doc string.

---IMHO commenting the parameters and results of a function is what
someone
needs who skims the docs for enlightenment---

these are two completely different things:

f = instanceSomeClass() - 'pops up the __init__ doc string in your
IDE'

now, when this class is instanced, i think this could be useful:

f.someComplexMethod - 'pops up the variable docstring'

I'm all for DRY -dont repeat yourself-, but DHORYEBNPTMTRYCEBPTSWTITDS
-don't have others repeat your efforts by not providing the means to
reuse your code efficiently by providing them sparsely with the
information to do so-

could have some place in complex classes that are often subclassed.
having the right information at the right time to do so would be quite
a help.
be fair: do you perfectly well know how to subclass a class without
(extensively) reading it back?

perhaps a variable doc here and there would make this slightly easier.

-jelle

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


Re: proposed Python logo

2006-04-21 Thread Gerard Flanagan
Michael Yanowitz wrote:
 How about having something from Monty Python in the logo rather
 than something snakelike. Python was named after Monty Python and not
 the snake. Snakes also don't appear friendly to me.
   I used to have rats as pets. Snakes are murderers of rats. Which I

Never mind rats, have you seen the Google ads for this thread?


http://www.salfordadvertiser.co.uk/news/s/211/211961_goodness_snake.html


http://www.dailyrecord.co.uk/news/tm_objectid=16959435method=fullsiteid=66633headline=python-back-on-the-telly--name_page.html

!!!-)

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


Re: python equivalent of VB code sample

2006-04-21 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
 Situation is this:
 1) must write application that does the following:
  a) creates an xml document, the contents of which, is a request
 transaction
  b) send xml document to destination; I am assuming that a process
 at destination side processes the request and sends back a response
  c) the application I'm writing must receive response and then
 examine contents of response
 2) hope to write client application in python
 3) was provided VB code sample that does steps 1a, 1b and 1c; the
 sample code is:
 
 ' section of code that builds the string sXML; the contents of which
 is a request transaction
 set objXML = Server.CreateObject(MSXML2.ServerXMLHTTP)
  'Bank table image address field, location of Comm Admin.
 sServer = Session(ImageAddress)
  'NT AUTH
 ' note: I believe the next 2 lines in this post are really one line in
 VB code that wrapped
 ' because they didn't fit on one line in the post
 objXML.open
 POST,sServer,false,Session(WebServerUserAuth),Session(WebServerPassword)
 objXML.send sXML
 sXMLRs = objXML.responseText
 

This code is dealing with XMLHTTP request.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: are docstrings for variables a bad idea?

2006-04-21 Thread bearophileHUGS
Docstrings for variables seems a new interesting idea to me, but I
don't know how much useful it can be. Do you mean something like this?

 rcar_speed = 25
 print rcar_speed
25
 print rcar_speed.__doc__
int(x[, base]) - integer
...
 rcar_speed.__ndoc__ = Speed of the red car, km/h
...

Can you show me some examples of its possible usefulness?

Bye,
bearophile

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


Re: proposed Python logo

2006-04-21 Thread BartlebyScrivener
No matter what you do, Python is going to sum up the image of a
powerful snake. I suppose you could change the name to Monty, if you
wanted more humor and more of a reference to Monty Python, or maybe
Bring Out Your Dead.

Personally I like the snake associations and the notion that you're
joining a cult where everybody speaks in Parseltongue.

http://en.wikipedia.org/wiki/Priori_Incantatem#Speaking_parseltongue

rd

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


Read and extract text from pdf

2006-04-21 Thread Julien ARNOUX
Hi,
I have a problem :), I just want to extract text from pdf file with
python. There is differents libraries for that but it doesn't work...

pyPdf and  pdfTools, I don't know why but it doesn't works with some
pdf... For example space chars are delete in the text..
Pdf playground : I don't understand how it work.

If you have an idea, a tutorial, a library or anything who can help me
to do that.

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread Diez B. Roggisch
jelle wrote:

 ---I don't know for sure what you mean by pop up as doc-string - I
 guess you
 want them magically merged into the functions doc string, at least
 inside
 your editor? That sure could be done - but I personally don't think
 that is
 too useful. Because you lose context.---
 
 point taken. perhaps only variables declared in the __init__ should be
 made available as a doc string.
 
 ---IMHO commenting the parameters and results of a function is what
 someone
 needs who skims the docs for enlightenment---

On a related note: for someone who's goal is more clarity in coding, your
style of quoting is thwarting that efforts.
 
 these are two completely different things:
 
 f = instanceSomeClass() - 'pops up the __init__ doc string in your
 IDE'
 
 now, when this class is instanced, i think this could be useful:
 
 f.someComplexMethod - 'pops up the variable docstring'

I feared that you meant that - but wasn't sure. This is one of the
often-requested-yet-they-will-never-come features of IDEs for python, as
this would mean that you'd have type-information available on f. Consider
this simple example:

f = someRandomlyInstatiatedObject()

Now what is e.g. f.C-space to show? 

Additionally, if you typed f.foo yourself, is it foo of Foo, or foo of
FooSubclass, or foo of the totally unrelated Badabum?

 
 I'm all for DRY -dont repeat yourself-, but DHORYEBNPTMTRYCEBPTSWTITDS
 -don't have others repeat your efforts by not providing the means to
 reuse your code efficiently by providing them sparsely with the
 information to do so-
 
 could have some place in complex classes that are often subclassed.
 having the right information at the right time to do so would be quite
 a help.

This is sort of a tautology and applies to pretty much everything in life :) 

 be fair: do you perfectly well know how to subclass a class without
 (extensively) reading it back?

Sure you have to. but then you read the source.
 
 perhaps a variable doc here and there would make this slightly easier.

I'm still not seeing what you are really after. Python has no variable
declarations, so there is no natural point to put these, as it is e.g. in
JAVA. Gathering inline comments by some heuristics like the following
statement has a assignment might be feasible to implement, yet I fail to
see the usefulness for that, at least for methods in general.
 The exception from this would be the constructor, as sensible design
usually makes all instance variables known there - so something that
mangles

def __init__(self):
# know where your foo is
self.foo = 'here'

might be of interest. But then - it often enough happens that in some method
after some obscure logic some instance variable gets created.

Don't get me wrong: I'm all in favor of commenting code. But your wish for
semi-automatic doc-generation doesn't appeal to me. Now as I'm not the one
and only one to decide about this, if you come up with a reasonable
proposal how to document variables  how to make this available (in way
more technical terms than just wouldn't it be nice to have) you might
convince some IDE-authors to adopt I gues.

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


Re: Read and extract text from pdf

2006-04-21 Thread Rene Pijlman
Julien ARNOUX:
I have a problem :), I just want to extract text from pdf file with
python. There is differents libraries for that but it doesn't work...

pyPdf and  pdfTools, I don't know why but it doesn't works with some
pdf...

Text can be represented in different ways in PDF: as tagged text, bitmap
and vector images, and even algorithms (IIRC). Most tools will only be
able to retrieve text represented as tagged text. So some tools may work
on some texts in some files and fail on others.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


what has python added to programming languages? (lets be esoteric, shall we ;)

2006-04-21 Thread Wildemar Wildenburger
Over the time I've seen lots of remarks about python that read like a 
lot like lists in lisp or like the hashtable in java or any other 
form of like feature in language.

Are there any concepts that python has not borrowed, concepts that were 
not even inspired by other languages? I'm just interested if it is 
merely a best-of collection of language features or if there are 
actually inventions that have not - or hardly - existed in programming 
before python?

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


ANN: Leo 4.4 b4 released

2006-04-21 Thread Edward K. Ream
Leo 4.4 beta 4 is now available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This version fixes a long-standing MacOS bug.  It is likely to be the last 
beta release before 4.4 rc1.  This release also adds several new commands 
and contains a script for updating leoSettings.leo.

Warning: The previous beta was not widely distributed.  Please do some 
testing in your environment before recommending this version of Leo to 
others, (such as your students).

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name, with tab completion.

- Many new commands, including cursor and screen movement, basic character, 
word and paragraph manipulation, and commands to manipulate buffers, the 
kill ring, regions and rectangles. You can use Leo without using a mouse.

- Flexible key bindings and input modes. You can emulate the operation of 
Emacs, Vim, or any other editor.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Autocompletion and calltips.

- Dozens of other new features and bug fixes since Leo 4.3.3.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward

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



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


Re: Leo 4.4 b4 released

2006-04-21 Thread Edward K. Ream
Correction: Leo's cvs repository has been moved to tigris:

http://leo.tigris.org/source/browse/leo/

Edward

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



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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread jelle
didn't you just do that ;')

such variables docstrings would help one to speed up understanding an
API, and more importantly, could reduce assumptions you make on what a
variable means.
who's the mother of assumptions again?

i'm not evangalizing at all that each and every variable should be
documented!
but one cannot deny there is a certain degree of entropy in the
understanding of classes you even wrote yourself. so variables
docstrings could be very helpful notes to oneself and others.

imagine you wrote a python script that runs a FEM simlation overnight,
relating drag to speed.

rcar.speed - 'resulting velocity to rcar.drag'

these little notes could help you not to make the same false assumption
you've overcome a year ago, and are likely to make again.

also in cases (most) where you are not the sole operator on a class,
these little hints can be appreciated.

a variables doctring should never be longer than 2 lines to be any good
likely.
ok.
3

-jelle

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread Roy Smith
In article [EMAIL PROTECTED],
 jelle [EMAIL PROTECTED] wrote:

 When programming a more complex class, it would be quite helpful that
 these annotations would pop-up as a docstring.

I'm currently working with a OO database system that lets you attach a doc 
string not just to classes, but also to attributes, relationships, pretty 
much anything.  It's very useful.

That being said, I'm not sure how such a thing would work in Python.  In 
what I'm used to, the doc strings are attached to the variable declarations 
in the class definition, so there's just one copy of the string per class.  
Python doesn't work that way.  In Python, if I were to write:

class GeographicCoordinate:
def __init__ (self, lat, long):
self.lat = lat Latitude in degrees (positive North), per WGS84
self.long = long Longitude in degrees (positive West), per WGS84

each *instance* of GeographicCoordinate gets a self.lat and a self.long 
created in it, with no relationship between the attributes of one instance 
and another.  Where would the doc strings go?  The only logical place would 
be to have one copy per instance, which would be very wasteful.

On the other hand, since strings get interned, maybe it wouldn't be so bad.

On the third hand, I guess the doc strings could get attached to the 
class's __slots__, which would immediately lead to more but that's not 
what __slots__ was intended for arguments :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Michele Simionato
Wildemar Wildenburger wrote:
 Over the time I've seen lots of remarks about python that read like a
 lot like lists in lisp or like the hashtable in java or any other
 form of like feature in language.

 Are there any concepts that python has not borrowed, concepts that were
 not even inspired by other languages? I'm just interested if it is
 merely a best-of collection of language features or if there are
 actually inventions that have not - or hardly - existed in programming
 before python?

 wildemar

1. One of the strenght of Python is that it does not try to be
particularly original, most of
the times it just borrows the good features from other languages
without borrowing the
warts.

2. If you ask in a Lisp newsgroup, they will tell you that they
invented everything that it is
cool now (in any language) over 40  years ago. They are also mostly
right ;)

  Michele Simionato

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


Re: python-mysql on Windows -- How to?

2006-04-21 Thread Chris Seymour
HI Rick,
I did some searching on SourceForge and found a Windows installer for
the mysql-python 1.2.0.  (MySQL-python.exe-1.2.0.win32-py2.4.zip). I
unzipped and ran this installer and seem to be all set.  I will keep
testing.

Thanks.

Chris

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread jelle

Hi Diez,

please take note, this suggestion does not nessecarily apply to
programmers such as you  myself of course for whom any python code is
as transparant  as the API's we write ;')



I feared that you meant that - but wasn't sure. This is one of the
often-requested-yet-they-will-never-come features of IDEs for python,
as
this would mean that you'd have type-information available on f.
Consider
this simple example:

f = someRandomlyInstatiatedObject()

Now what is e.g. f.C-space to show?


why is this ambigious at all?
am i seriously overlooking something?

class jelle:
def __init__(self):
'''
we've been having this for a while, just the helpful
constructor docstring
'''
'''relates drag to speed'''
self.terribleNamedMethod = 'of a programmer i will not
disclose'

j = jelle() shows the proper docstring al'right

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


Does wxWindow.MakeModal(True) work for all Windows or just frames?

2006-04-21 Thread mw
I am using wxPython 2.6.3.0

As far as I can tell from the documentation (www.wxpython.org),
MakeModal() should work for all windows, but when I do some practical
tests, I can only get it to work for frames.

Can anyone confirm what the status of this method is.
Is it intended to work for all windows or just for frames?
If it is intended to work for all windows, does anyone have some sample
code to make a window within a frame modal (personally, I want to make
a grid modal).

/Magnus

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread Michele Simionato
Notice that class attributes can already be annoted (properties have a
docstring). BTW
in Python 2.5 you have a convenient way to define readonly attributes
(for instance
constants) and give them a docstring. Here is an example:

class C(object):
@property
def pi(self):
'pi is 3.14159'
return 3.14159

c = C()

print c.pi

help(C.pi) # gives you the docstring


   Michele Simionato

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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Carl Banks
Wildemar Wildenburger wrote:
 Are there any concepts that python has not borrowed, concepts that were
 not even inspired by other languages? I'm just interested if it is
 merely a best-of collection of language features or if there are
 actually inventions that have not - or hardly - existed in programming
 before python?

Nesting by indentation


Carl Banks

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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread dadapapa
It's true that most features of python are intentionally borrowed from
other languages. If I can think of anything that I believe to be
specific to python, I would say it is the combination of high level
datatypes together with an extremely simple syntax. Actually, this
combination often results in idioms that --- although adapted from
other languages --- are seldom as clear as in python. Examples for this
are one-liners like

 x,y = y,x
 a,b,c = f(x)
 for key in my_dict : do_some_thing_with(my_dict[key])

It might be that Guido adapted such notations from ABC, a language I am
not familiar with, but as far as I know, the syntactic sugar for high
level datatypes is one thing that
distinguishes python from other languages.

- harold -

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread jelle

class GeographicCoordinate:
def __init__ (self, lat, long):
self.lat = lat Latitude in degrees (positive North), per
WGS84
self.long = long Longitude in degrees (positive West), per
WGS84


Thanks for your example Roy, that illustrates well what I'm after:
self.lat = lat ellipsoid reference: WGS84\nGRS 80 no longer supported

It does exactly what its intended to do: i had no clue what the World
Geodetic System and would have asserted my input with a GRS80_2_WGS84
function

Little notes to avoid major mistakes.

class landClimateOrbiter(NASA):

self.speed = self.unit * x

Just imagine 'feet' would have popped up when typing self.unit

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


ANN: Pyrex 0.9.4.1

2006-04-21 Thread greg
Pyrex 0.9.4.1 is now available:

   http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

This is a very minor update to correct a tab/space
problem in the distutils extension.

What is Pyrex?
--

Pyrex is a language for writing Python extension modules.
It lets you freely mix operations on Python and C data, with
all Python reference counting and error checking handled
automatically.

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread jelle
Hi Michele,

Thanks for pointing that out, cool!

I would argue -even- that is too much programming effort.
Like method docstring, variables docstrings should be effortless to
write.

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


Re: are docstrings for variables a bad idea?

2006-04-21 Thread Diez B. Roggisch
jelle wrote:

 
 why is this ambigious at all?
 am i seriously overlooking something?


Yes. A full example is this:

import random

class A:
  I'm A
  
  pass

class B:
   I'm B
  
  pass

def factory():
if random.random() = .5:
return A()
return B()


o = factory()


Now what is the IDE to show at o for the docstring?


The point is: pythons dynamic nature allows for _runtime_ checks of this
only. Now the special-case of classes can be worked around with a static
analyzer to some extent - because ususally, import statements are easy
enough to spot and resolve statically.

But using __import__ even that can be obfuscated. Now I'm not saying that
this should suppress all efforts to have IDEs more supportive. Yet a class
is a declaration, as is a method - can be parsed easily. But e.g. setting
an instance variable by means of setattr(self, name, value) instead of
self.name = value is perfectly legal, often wanted and totally opaque to
any IDE trying to give support.

Diez




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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Iain King

Wildemar Wildenburger wrote:
 Over the time I've seen lots of remarks about python that read like a
 lot like lists in lisp or like the hashtable in java or any other
 form of like feature in language.

 Are there any concepts that python has not borrowed, concepts that were
 not even inspired by other languages? I'm just interested if it is
 merely a best-of collection of language features or if there are
 actually inventions that have not - or hardly - existed in programming
 before python?

 wildemar

I find slice notation consistent and elegant - did it come form another
language?

Iain

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


Re: what has python added to programming languages? (lets beesoteric, shall we ; )

2006-04-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 Examples for this are one-liners like

 x,y = y,x
 a,b,c = f(x)
 for key in my_dict : do_some_thing_with(my_dict[key])

 It might be that Guido adapted such notations from ABC, a language I am
 not familiar with

something like:

PUT (x, y) IN y, x
PUT f x y IN y, x
FOR key IN keys my_dict:
DO_SOME_THING_WITH my_dict[key]
/F 



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


Re: Does wxWindow.MakeModal(True) work for all Windows or just frames?

2006-04-21 Thread mw
I found a post Re: modal controls that addresses more or less the
same issue:

http://blog.gmane.org/gmane.comp.python.wxpython/month=20041101

Still, any additional input would be more than welcome.

/Magnus

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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread BartlebyScrivener
In the Tutorial, the BFDL says:

Strings can be subscripted (indexed); like in C, the first character of
a string has subscript (index) 0. There is no separate character type;
a character is simply a string of size one. Like in Icon, substrings
can be specified with the slice notation: two indices separated by a
colon.

http://www.python.org/doc/current/tut/node5.html#SECTION00512

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


Re: proposed Python logo

2006-04-21 Thread Michael Tobis
 Too rigid-looking somehow.

Hey, I'm an amateur...  There are lots of variations on the concept I
can think of. I want someone with a lot of design talent  *and a little
familiarity with the language* to take enough interest to have a go at
it.

At least (unlike the tadpoles) it has some resonance with the product
it's trying to represent.

mt

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


Re: proposed Python logo

2006-04-21 Thread Grant Edwards
On 2006-04-21, Michael Tobis [EMAIL PROTECTED] wrote:

 Too rigid-looking somehow.

 Hey, I'm an amateur...  There are lots of variations on the concept I
 can think of. I want someone with a lot of design talent  *and a little
 familiarity with the language* to take enough interest to have a go at
 it.

 At least (unlike the tadpoles) it has some resonance with the product
 it's trying to represent.

Not that I'm disagreeing, but how to you rate resonance with
the product?

-- 
Grant Edwards   grante Yow!  ... the MYSTERIANS
  at   are in here with my
   visi.comCORDUROY SOAP DISH!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what has python added to programming languages? (lets beesoteric, shall we ; )

2006-04-21 Thread Fredrik Lundh
Iain King wrote:

 I find slice notation consistent and elegant - did it come form another
 language?

Icon:

http://www.cs.arizona.edu/icon/

see e.g.

http://infohost.nmt.edu/tcc/help/lang/icon/substring.html
http://infohost.nmt.edu/tcc/help/lang/icon/positions.html

/F 



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


Re: Joining stdout stderr of subprocess ?

2006-04-21 Thread Nick Craig-Wood
robert [EMAIL PROTECTED] wrote:
  when I run a command
 
  myapp 21

Try

  myapp 21 | cat

and see what you get.  You should get the same output as the python.

  #!python
  print os.popen(myapp 21).read()
 
  the stderr stuff comes all after the stdout stuff.
  How can I get ahold of all the out and err joined synchronously in the 
  order, it is created ?

You need to either

1) change myapp to fflush() more often

2) investigate the python pty module to fool the app into thinking it
is talking to a terminal

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: are docstrings for variables a bad idea?

2006-04-21 Thread Ziga Seilnacht
jelle wrote:
 Hi Michele,

 Thanks for pointing that out, cool!

 I would argue -even- that is too much programming effort.
 Like method docstring, variables docstrings should be effortless to
 write.

I don't know what exactly do you mean with variable docstrings, but
if you just want to add docstrings to instance's data attributes, you
can use something like this:


This module is useful for documenting data attributes. Example:

 class C(object):
... foo = attr('a common attribute in examples')
... bar = attr('this one has a name for nicer errors', 'bar')
... baz = attr('and this one has a default value', default=1)
... def __init__(self, foo=None, bar=None, baz=None):
... if foo is not None:
... self.foo = foo
... if bar is not None:
... self.bar = bar
... if baz is not None:
... self.baz = baz
...
 C.foo
attr(doc='a common attribute in examples', name='', default=NoDefault)
 C.foo.__doc__
'a common attribute in examples'
 C.bar.__doc__
'this one has a name for nicer errors'
 C.baz.__doc__
'and this one has a default value'
 c = C()
 c.foo
Traceback (most recent call last):
  ...
AttributeError: 'C' object has no attribute ''
 c.bar
Traceback (most recent call last):
  ...
AttributeError: 'C' object has no attribute 'bar'
 c.baz
1
 d = C(1, 2, 3)
 d.foo
1
 d.bar
2
 d.baz
3



class Marker(object):

def __init__(self, representation):
self.representation = representation

def __repr__(self):
return self.representation


_NoDefault = Marker('NoDefault')


class attr(object):

def __init__(self, doc='', name='', default=_NoDefault):
self.__doc__ = doc
self.name = name
self.default = default

def __repr__(self):
s = attr(doc=%r, name=%r, default=%r)
return s % (self.__doc__, self.name, self.default)

def __get__(self, obj, objtype):
if obj is None:
return self
if self.default is _NoDefault:
msg = %r object has no attribute %r
raise AttributeError(msg % (objtype.__name__, self.name))
return self.default


if __name__ == '__main__':
import doctest
doctest.testmod()

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


Re: How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespac

2006-04-21 Thread ToddLMorgan
Thanks everyone for their assistance.

I have managed to achieve all that I set out to do:
- separation between src and test folders
- now successfully sharing code between projects
- running unittest s and suites
- avoiding namespace collisions

The solution involved the following (if anyone else is interested)
- ammending all my __init__.py packages so that they included the
following:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

as per Peter Otten's suggestion

- refactoring all the code so that the imports and froms conformed to
the new package structure (a.b.c.common, a.b.c.app1 etc) and physically
moving all the required files

- ammending the PYTHONPATH so that the src and test directories for
each project is included at the time of running

ie
PYTHONPATH=COMMON/src;COMMON/test;APP1/src;APP1/test;APP2/src;APP2/test

Of course the /test entries are only required for testing and not
runtime but you get the idea.

I understand that flatter package structures are apparently the python
way (http://dirtsimple.org/2004/12/python-is-not-java.html) but I like
a nice little small little related package of functionality when I am l
carving up a complex problem so I'm happy to incur any extra
performance penalty in dict lookups.

thanks again

Todd

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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Alex Martelli
Wildemar Wildenburger [EMAIL PROTECTED] wrote:

 Over the time I've seen lots of remarks about python that read like a
 lot like lists in lisp or like the hashtable in java or any other 
 form of like feature in language.

Since Python was released well before Java, saying that a feature in
Python is like a feature in Java normally doesn't mean that Python
imitated Java there -- it's either separate reinvention, or both of them
imitating another language.


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


how to append to a list twice?

2006-04-21 Thread John Salerno
If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] 
(where each item is repeated twice after the first one), how might I do 
that most efficiently?

Right now I have this:

series = [100]
for x in range(10):   # just for testing
 series.append(series[-1] - 1)

But of course that only does it once, and I don't want to have to copy 
and paste the append line. Perhaps there's a better way than this.

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


Re: win32com.client.constants - AttributeError

2006-04-21 Thread kbperry
how do I do this?  Where is the Word object library?

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


Re: proposed Python logo

2006-04-21 Thread RK
That's a good try...

Can we get some street pros?

http://www.graffitifonts.com/

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


Re: how to append to a list twice?

2006-04-21 Thread Paul McGuire
John Salerno [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...]
 (where each item is repeated twice after the first one), how might I do
 that most efficiently?

 Right now I have this:

 series = [100]
 for x in range(10):   # just for testing
  series.append(series[-1] - 1)

 But of course that only does it once, and I don't want to have to copy
 and paste the append line. Perhaps there's a better way than this.

 Thanks.

series = [100]
for x in range(10):   # just for testing
 series.extend([series[-1] - 1]*2)


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


Re: how to append to a list twice?

2006-04-21 Thread Gerard Flanagan

John Salerno wrote:
 If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...]
 (where each item is repeated twice after the first one), how might I do
 that most efficiently?

 Right now I have this:

 series = [100]
 for x in range(10):   # just for testing
  series.append(series[-1] - 1)

 But of course that only does it once, and I don't want to have to copy
 and paste the append line. Perhaps there's a better way than this.

 Thanks.

series = [100]

for i in range(1,10):
series.extend([100-i]*2)

print series

[100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 92,
91, 91]

Gerard

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


Re: how to append to a list twice?

2006-04-21 Thread Alex Martelli
John Salerno [EMAIL PROTECTED] wrote:

 If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...]
 (where each item is repeated twice after the first one), how might I do
 that most efficiently?
 
 Right now I have this:
 
 series = [100]
 for x in range(10):   # just for testing
  series.append(series[-1] - 1)
 
 But of course that only does it once, and I don't want to have to copy
 and paste the append line. Perhaps there's a better way than this.

def makeseries(N):
  series = [N]
  append = series.append
  for tailer in xrange(N-1, -1, -1):
append(tailer)
append(tailer)
  return series

series = makeseries(100)

assuming that by most efficiently you mean fastest, this might come
close; you'll want to also time an alternative where makeseries is a
generator which just yields the values, and the last assignment becomes
series=list(makeseries(100)).


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


Re: how to append to a list twice?

2006-04-21 Thread Tim Chase
 If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] 
 (where each item is repeated twice after the first one), how might I do 
 that most efficiently?
 
 Right now I have this:
 
 series = [100]
 for x in range(10):   # just for testing
  series.append(series[-1] - 1)

Well, you can do something like

def foo(start):
 count = 0
 while 1:
 yield start - ((count + 1) / 2)
 count += 1

which is pretty efficient in the matter.  If you just need 
the results, you can do something like

series = [100]
for _ in range(10):
 series.extend([x[-1]-1]*2)

Both should get you what you want, and one or the other may 
be better depending on the scenario in which you want to use it.

-tkc




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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Michael Tobis
Although somewhat more elegant, Python slices follow Matlab's slice
notation. In simpler cases they are identical.

mt

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


Re: how to append to a list twice?

2006-04-21 Thread [EMAIL PROTECTED]
Not sure if this is simpler or better, but here's a way to do it with a
generator:

value = 100
count = 0

def valueGen():
global value
global count
while(value = 0):
if(value == 100):
yield value
value -= 1
else:
if(count  1):
yield value
else:
yield value
value -= 1

count = count + 1

series = []
gen= valueGen()

for item in gen:
print item
series.append(item)

print series

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


Re: ANN: Pyrr 0.1 - Lexer and LR(1)-Parser Generator for Python

2006-04-21 Thread Norman Shelley
FWIW: This has a similiar look/feel to how sabbey wrapped dparser.
http://staff.washington.edu/sabbey/py_dparser/

Heiko Wundram wrote:
 Hi list!
 
 Not long ago I was looking for an easy to use, but powerful parser and lexer 
 generating tool for Python, and to my dismay, I found quite a number of 
 Python projects implementing an (LA)LR(1) parser generator, but none of them 
 seemed quite finished, or even pythonic.
 
 As I required a parser generator for Python for one of my work projects, I 
 set 
 out to write (yet another one), and currently am at (release-)version 0.1 for 
 Pyrr.ltk and ptk.
 
 An example for Pyrr.ltk and ptk usage implementing a (very) simple calculator:
 
 
 # -*- coding: iso-8859-15 -*-
 
 from ltk import LexerBase, IgnoreMatch
 from ptk import ParserBase
 from operator import add, sub, mul, div
 
 class NumLexer(LexerBase):
 
 def number(self,value):
 number - r/[0-9]+/
 return float(value)
 
 def ws(self,*args):
 ws - r/\\s+/
 raise IgnoreMatch
 
 def ops(self,op):
 addop - /+/
  - /-/
mulop - /*/
  - r/\\//
 return op
 
 class NumParser(ParserBase):
 /mulop/: left
/addop/: left
 __start__ = term
 
 def term(self,value1,op,value2):
 term - term /addop/ term
 - term /mulop/ term
 return {+:add,-:sub,*:mul,/:div}[op](value1,value2)
 
 def value(self,value):
 term - /number/
 return value
 
 print NumParser.parse(NumLexer.tokenize(3 + 4 - 123 / 23))
 
 
 Grammar rules and lexemes are specified in docstrings, where lines not 
 matching a definition of a rule or lexeme are ignored. The resulting lexer 
 and parser class is, thus, very much self-documenting, which was one of my 
 biggest goals for the project.
 
 I'm currently in the process of writing documentation for both packages (and 
 especially documenting the extensions to BNF-grammars that Pyrr.ptk allows, 
 such as your usual RE-operators ?, *, + and {x,y}, and forward arguments, and 
 documenting the stateful lexer support that Pyrr.ltk implements), but I 
 thought that I'd release early and often, so that people interested in this 
 project might have a look at it now to input suggestions and extensions that 
 they'd like me to add to make this a fully featured Python parser generating 
 toolkit which might be offered as a Python package.
 
 Anyway, the sources can be downloaded (via subversion) from:
 
 http://svn.modelnine.org/svn/Pyrr/trunk
 
 where I'll check in the documentation that I've written so far and a Python 
 distutils distribution over the weekend, and make sure that I don't check in 
 brocken code from now on. And, Pyrr.* is Python 2.4 only at the moment, and I 
 have no plans to make it backwards-compatible, but if you're interested in 
 backporting it, feel free to mail me patches.
 
 --- Heiko.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposed Python logo

2006-04-21 Thread Simon Brunning
On 4/21/06, Michael Yanowitz [EMAIL PROTECTED] wrote:
I think something from Monty Python (I haven't watched it recently
 to know what would be ideal) would be more appropriate than an ugly
 reptile which is usually associated with evil and our reason for leaving
 the Garden of Eden.

+1. I'd like some variation of http://tinyurl.com/gj74k used as a logo.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to append to a list twice?

2006-04-21 Thread John Salerno
Paul McGuire wrote:
 John Salerno [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...]
 (where each item is repeated twice after the first one), how might I do
 that most efficiently?

 Right now I have this:

 series = [100]
 for x in range(10):   # just for testing
  series.append(series[-1] - 1)

 But of course that only does it once, and I don't want to have to copy
 and paste the append line. Perhaps there's a better way than this.

 Thanks.
 
 series = [100]
 for x in range(10):   # just for testing
  series.extend([series[-1] - 1]*2)
 
 

Interesting. I tried the *2 method twice, but I kept getting weird 
results, I guess because I was using append and not extend. I thought 
extend added lists to lists, but obviously that's not the case here.

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


Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread utabintarbo
Why does Python have to add anything, if it makes that which came
before more easily accessible/usable? Perhaps that is its innovation.
Is that not sufficient?

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


Re: how to append to a list twice?

2006-04-21 Thread Fredrik Lundh
Alex Martelli wrote:

  But of course that only does it once, and I don't want to have to copy
  and paste the append line. Perhaps there's a better way than this.

 def makeseries(N):
   series = [N]
   append = series.append
   for tailer in xrange(N-1, -1, -1):
 append(tailer)
 append(tailer)

But Now You've Violated The DRY Principle!!!

/F



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


Re: how to append to a list twice?

2006-04-21 Thread Tim Chase
 Interesting. I tried the *2 method twice, but I kept
 getting weird results, I guess because I was using append
 and not extend. I thought extend added lists to lists,
 but obviously that's not the case here.


In the above example, it *is* add[ing] lists to lists. 
Note the set of brackets:

series = [100]
for x in range(10):   # just for testing
   series.extend([series[-1] - 1]*2)

You have a one-element series:

[series[-1] - 1]

that gets duplicated using the overloading of the 
multiplication (duplication) operator:

[...] * 2

This yields a two-element list.  This list then gets passed 
to extend(), to add those two elements to the original list.

If you used append() instead of extend(), it would be 
something like

[100, [99, 99], [98, 98],...]

-tkc




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


  1   2   3   >