Re: and [True,True] --> [True, True]?????

2009-04-23 Thread Lie Ryan

Gerhard Häring wrote:

len() make it clear
that the argument is a sequence.


Not necessarily. Classes that overrides __len__ may fool that assumption 
(well, in python classes that overrides special functions may do 
anything it is never intended to do).


I often think an "if item:" as "is item workable?". What the exact 
definition of "workable" is just something I don't care, at least until 
I need to debug the code. A container is workable if it contains 
something; most of the time, an empty sequence does not have any value 
(pun intended) and thus unworkable.

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


Re: Presentation software for Python code

2009-04-23 Thread Michael Hoffman

alex23 wrote:


How do you feel about reStructuredText? If you're open to it, I highly
recommend Bruce: http://pypi.python.org/pypi/bruce


That looks like it would be perfect. Unfortunately it doesn't seem to 
work on my Windows laptop:


C:\Documents and 
Settings\Michael\Desktop\bruce-3.2.1>C:\Python25\python.exe bru

ce.pyw ..\bruce-3.2.1-examples\test_bullet_mode.rst
Traceback (most recent call last):
  File "bruce.pyw", line 6, in 
run.main()
  File "bruce-library.zip\bruce\run.py", line 25, in main
  File "bruce-library.zip\bruce\run.py", line 217, in cmd_line
  File "bruce-library.zip\bruce\run.py", line 313, in run
  File "bruce-library.zip\bruce\presentation.py", line 31, in 
start_presentation


  File "bruce-library.zip\bruce\page.py", line 29, in create
  File "bruce-library.zip\bruce\layout.py", line 143, in create
  File "bruce-library.zip\pyglet\graphics\__init__.py", line 348, in add
  File "bruce-library.zip\pyglet\graphics\__init__.py", line 436, in 
_get_domain


  File "bruce-library.zip\pyglet\graphics\vertexdomain.py", line 135, 
in create_

domain
  File "bruce-library.zip\pyglet\graphics\vertexdomain.py", line 174, 
in __init_

_
  File "bruce-library.zip\pyglet\graphics\vertexbuffer.py", line 117, 
in create_

mappable_buffer
  File "bruce-library.zip\pyglet\graphics\vertexbuffer.py", line 383, 
in __init_

_
  File "bruce-library.zip\pyglet\graphics\vertexbuffer.py", line 301, 
in __init_

_
  File "bruce-library.zip\pyglet\gl\lib_wgl.py", line 94, in __call__
  File "bruce-library.zip\pyglet\gl\lib.py", line 63, in MissingFunction
pyglet.gl.lib.MissingFunctionException: glGenBuffers is not exported by 
the avai

lable OpenGL driver.  VERSION_1_5 is required for this functionality.
Exception exceptions.AttributeError: "'VertexDomain' object has no 
attribute 'at
tributes'" in 
=[]>> ignored

I don't understand this. OpenGL Extensions Viewer says I have OpenGL 1.5 
and the glGenBuffers function.

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


Re: and [True,True] --> [True, True]?????

2009-04-23 Thread Lie Ryan

Steven D'Aprano wrote:

On Mon, 20 Apr 2009 15:13:15 -0500, Grant Edwards wrote:



I fail to see the difference between "length greater than 0" and "list
is not empty".  They are, by definition, the same thing, aren't they?


For built-in lists, but not necessarily for arbitrary list-like sequences.


I think a list-like sequence that does not emulate this behavior (False 
when empty, True otherwise) should be considered a buggy implementation 
of the list interface.

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


Re: relation class

2009-04-23 Thread Aaron Brady
On Apr 22, 11:34 pm, Aaron Brady  wrote:
> On Apr 22, 11:52 am, Aaron Brady  wrote:
>
> > On Apr 22, 12:09 am, Chris Rebert  wrote:
>
> > > On Tue, Apr 21, 2009 at 5:51 PM, Aaron Brady  wrote:
> > > > Hi all,
>
> > > > I think Python should have a relation class in the standard library.
> > > > Fat chance.
>
> > > Perhaps I'm not understanding "relation" correctly, but are you not
> > > aware ofhttp://docs.python.org/library/sqlite3.html?
>
> > > Cheers,
> > > Chris
> > > --
> > > I have a blog:http://blog.rebertia.com
> snip
> > It only supports numbers and strings.
>
> snip
>
> My point is that in undirected relations, it's redundant to maintain
> reciprocal membership.
snip
> Here is another sample:
>
> Tree= Relation( ( "parent", "child", "direction" ) )
> nodes= [ object( ) for _ in range( 10 ) ]
> Tree( ( nodes[ 0 ], nodes[ 1 ], "left" ) )
> Tree( ( nodes[ 0 ], nodes[ 2 ], "right" ) )
snip
> 'select' would need the context
> of its caller, which isn't available.
snip

Or, pass 'locals()'.  Actually, I discovered an interesting catch to
'locals()'.  When you don't use a variable that's in an outer scope in
a function, it doesn't appear in 'locals()'.  However, if you just use
it in a blank statement, it magically appears.

>>> def f( ):
... x= []
... def g( ):
... print( locals( ) )
... g( )
...
>>> f( )
{}
>>> def f( ):
... x= []
... def g( ):
... x # empty use of 'x'
... print( locals( ) )
... g( )
...
>>> f( ) # changes the contents of 'locals()'
{'x': []}

Here is what the docs have to say about *that*:

"Free variables are returned by locals() when it is called in a
function block."

Since 'x' doesn't appear in the function, 'g' in this case, it isn't
included in 'g's free variables.  'eval' actually therefore doesn't
return exactly the result of evaluating a string where it's used.

>>> def f( ):
... x= []
... def g( ):
... print( eval( 'x' ) )
... g( )
...
>>> f( )
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 5, in f
  File "", line 4, in g
  File "", line 1, in 
NameError: name 'x' is not defined

The 'eval' function docs do assert otherwise though:

"...the expression is executed in the environment where eval() is
called."

'eval' doesn't obviously keep its contract as shown.

> I think some kind of markers would have to replace any identifiers it
> would use:
>
> recordset= Tree.select( [ "child" ],
>     "parent is %var and direction=='left'", nodes[0] )
snip

The 'sqlite3' module just uses a question mark.  Despite the fact that
variables are separated from exactly where they are used, it has the
advantage, as S. D'Aprano pointed out nearby, of being able to use
queries independently of them, as well as of being legal Python.

If anyone is still reading, there is a further nifty-cool construct
that the 'Relation' class can offer.  Given the earlier definition of
'Tree' as an instance of 'Relation', a new class can combine property
descriptors with the select statement.

class TreeNode:
relation= Tree
left= Relation.getter(
"child", "parent is ? and direction=='left'" )

nodes= [ TreeNode( ) for _ in range( 10 ) ]
record= nodes[ 0 ].left

Getting the 'left' member of an instance of this class is just
syntactic sugar for a long-hand query.  It only returns one field of
an arbitrary element of the recordset.  It only allows one '?' in the
definition, since getter functions only take one argument: self!
Here's the definition of 'getter':

@staticmethod
def getter( field, where ):
def _getter( self ):
return getattr( next(
self.relation.select( '*', where, self ) ), field )
return property( fget= _getter )

It could be an attribute of the module, not specifically of the
Relation class... which might even be advisable.  You could even
combine the 'relation' member into the call to 'getter', so 'getter'
wouldn't have to retrieve it as 'self.relation'.  That has the
disadvantage of increasing repetition of the relation in the class
statement, but enables a class to participate in multiple relations.
Come to think of it, you could write it as 'Tree.getter', and
compromise.  Then 'getter' becomes:

def getter( self, field, where ):
def _getter( ob ):
return getattr( next(
self.select( '*', where, ob ) ), field )
return property( fget= _getter )

and 'TreeNode' becomes:

class TreeNode:
left= Tree.getter(
"child", "parent is ? and direction=='left'" )

You might want 'getter', 'getiter', and 'getone' methods, which return
a set of, an iterator over, and just the field of an arbitrary one of
the matching records respectively.

Proof-of-concept isn't even complete; but nonetheless, pretty cool,
eh?
--
http://mail.python.org/mailman/listinfo/python-list


Re: best way to compare contents of 2 lists?

2009-04-23 Thread bearophileHUGS
Esmail:
> oh, I forgot to mention that each list may contain duplicates.

Comparing the sorted lists is a possible O(n ln n) solution:

a.sort()
b.sort()
a == b

Another solution is to use frequency dicts, O(n):

from itertools import defaultdict
d1 = defaultdict(int)
for el in a:
d1[el] += 1
d2 = defaultdict(int)
for el in b:
d2[el] += 1
d1 == d2

As the arrays (Python lists) become large the second solution may
become faster.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: can't find the right simplification

2009-04-23 Thread Lie Ryan

Stef Mientki wrote:

hello,

I've a program where you can connect snippets of code (which I call a 
"Brick") together to create a program.
To make it easier to create these code snippets, I need some 
simplifications.

For simple parameters ( integer, tupple, list etc)  this works ok,
and is done like this:


class _Simple_Par ( object ) :
   """
   Class to make it more easy to set a Bricks.Par from a control.
   So instead of :
 self.Brick.Par [ self.EP[0] ] = Some_Value
   you can write
 self.P[0] = Some_Value
   """
   def __init__ ( self, control ) :
   self.Control = control
   def __setitem__ ( self, index, value ) :
   i = self.Control.EP [ index ]
   if i :
   self.Control.Brick.Par [ i ] = value

Now I want a similar simplification for the case that Par is a dictionary:
So instead of writing:
 self.Brick.Par [ self.EP[0] ] [ 'Filename' ] = Some_Value

I would like to write:
 self.P[0] [ 'Filename' ] = Some_Value

But I can't figure out how to accomplish that ?

Any suggestions ?

thanks,
Stef Mientki


Do this work?

class _Simple_Par (object):
def __init__(self, control):
##
class P(object):
def __init__(self, parent):
self.parent = parent
def __getitem__(self, key):
return self.parent.Brick.Par[self.parent.EP[key]]

self.P = P(self)
##
self.Control = control

btw, it seems your code violated many of PEP 8 style recommendations.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strange problem when using imp.load_module

2009-04-23 Thread pythoncurious
Well spotted :)
That does seem to be the problem. Adding removal of the .pyc file will
make the tests pass.

I guess that python doesn't use the higher resolution timestamp
you can get from at least Solaris when doing 'stat' on a file.

Thanks for the help.

/Mattias



On Apr 23, 10:28 pm, Arnaud Delobelle  wrote:
>
> My guess is that without the sleep(1), the imp.load_source function will
> use the compiled file 'my_module.pyc' created in test_1 instead of
> compiling the new 'my_module.py' file.
>
>
> HTH
>
> --
> Arnaud

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


DigitalSigner in Python

2009-04-23 Thread Good Z
Hello All, 

I need to digitally sign a document in python. Is there any equivalent 
directory in Python like the DigitalSigner we have in Java.

Best Regards,
Mike


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


Re: Python, MS SQL, and batch inserts

2009-04-23 Thread Lawrence D'Oliveiro
In message , Dennis 
Lee Bieber wrote:

> On Thu, 23 Apr 2009 21:00:48 +1200, Lawrence D'Oliveiro
>  declaimed the following in
> gmane.comp.python.general:
>> 
>> Nothing wrong with that
>> .
> 
> Eeeek! That whole page seems to take pride in violating the common
> recommendations for the use of DB-API compliant database adapters.

Let's see you come up with better solutions.

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


Re: can't find the right simplification

2009-04-23 Thread Peter Otten
Stef Mientki wrote:

> I've a program where you can connect snippets of code (which I call a 
> "Brick") together to create a program.
> To make it easier to create these code snippets, I need some 
> simplifications.
> For simple parameters ( integer, tupple, list etc)  this works ok,
> and is done like this:
> 
> 
> class _Simple_Par ( object ) :
>     """
>     Class to make it more easy to set a Bricks.Par from a control.
>     So instead of :
>       self.Brick.Par [ self.EP[0] ] = Some_Value
>     you can write
>       self.P[0] = Some_Value
>     """
>     def __init__ ( self, control ) :
>         self.Control = control
>     def __setitem__ ( self, index, value ) :
>         i = self.Control.EP [ index ]
>         if i :
>             self.Control.Brick.Par [ i ] = value
> 
> Now I want a similar simplification for the case that Par is a dictionary:
> So instead of writing:
>       self.Brick.Par [ self.EP[0] ] [ 'Filename' ] = Some_Value
> 
> I would like to write:
>       self.P[0] [ 'Filename' ] = Some_Value
> 
> But I can't figure out how to accomplish that ?
> 
> Any suggestions ?

Are you about to confuse your cat, too? Here's the modified example:

class Brick(object):
def __init__(self):
self.Par = [dict(a=1), dict(b=2), dict(c=3)]

class P(object):
def __init__(self, parent):
self.parent = parent
def __getitem__(self, index):
p = self.parent
return p.Brick.Par[p.EP[index]]

class A(object):
def __init__(self):
self.Brick = Brick()
self.EP = [2,1,0]
self.P = P(self)

def demo(self):
print "before:", self.Brick.Par
self.P[0]["yadda"] = "whatever"
print "after:", self.Brick.Par

a = A()
a.demo()

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


(UPDATE) Memory problems (garbage collection)

2009-04-23 Thread Carbon Man
Thanks for the replies. I got my program working but the memory problem 
remains. When the program finishes and I am brought back to the PythonWin 
the memory is still tied up until I run gc.collect(). While my choice of 
platform for XML processing may not be the best one (I will change it later) 
I am still concerned with the memory issue. I can't believe that it could be 
an ongoing issue for Python's xml.dom, but nobody was able to actually point 
to anything in my code that may have caused it? I changed the way I was 
doing string manipulation but, while it may have been beneficial for speed, 
it didn't help the memory problem.
This is more nuts and bolts than perhaps a newbie needs to be getting into 
but it does concern me. What if my program was a web server and periodically 
received these requests? I decided to try something:

if __name__ == '__main__':
replicate = reptorParsing()
replicate.process(filename=os.path.join(os.getcwd(), "request.xml"))
import gc
gc.collect()

Fixed the problem, though I wouldn't know why. Thought it might be something 
to do with my program but...

if __name__ == '__main__':
replicate = reptorParsing()
replicate.process(filename=os.path.join(os.getcwd(), "request.xml"))
del replicate

Did not resolve the memory problem.

Any ideas? 


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


Re: Unicode in writing to a file

2009-04-23 Thread Carbon Man
Thanks yes that did it.

"Peter Otten" <__pete...@web.de> wrote in message 
news:gspmrf$qlq$0...@news.t-online.com...
> Carbon Man wrote:
>
>> Py 2.5
>> Trying to write a string to a file.
>> self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue)
>> cValue contains a unicode character. node.tagName is also a unicode 
>> string
>> though it has no special characters in it.
>> Getting the error:
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in
>> position 22: ordinal not in range(128)
>
> You have to decide in what encoding you want to store the data in your 
> file.
> UTF-8 is usually a good choice. Then open it with codecs.open() instead of
> the built-in open():
>
> import codecs
>
> f = codecs.open(filename, "w", "UTF-8")
> f.write(u"\nentry." + node.tagName + u" = " + cValue)
>
> Peter
> 


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


Re: Configuring pylint for local conventions

2009-04-23 Thread Ben Finney
David Stanek  writes:

> I find that the comments in the file it generates are enough. I
> haven't needed any more documentation than that.

I'll take that as a data point in support of “there is no documentation
for pylint except the configuration file itself”. Thanks.

-- 
 \  “Dvorak users of the world flgkd!” —Kirsten Chevalier, |
  `\rec.humor.oracle.d |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Configuring pylint for local conventions

2009-04-23 Thread David Stanek
On Thu, Apr 23, 2009 at 10:21 PM, Ben Finney  wrote:
> Ben Finney  writes:
>
>> David Stanek  writes:
>>
>> > I believe you just:
>> >   pylint --generate-rcfile > ~/.pylintrc
>> > and then customize that file.
>>
>> This is the part that I'm asking how to do. What documentation is there
>> on this configuration file and recommendations on how to modify it?
>
> For bonus points, I'm actually wanting to know how to configure it per
> *project*, and applying that configuration for all programmers of that
> project. Having one set of coding conventions per *user* seem like a
> recipe for frustration.
>

I find that the comments in the file it generates are enough. I
haven't needed any more documentation than that.

For project specific configuration I just keep a config file[1] in the
project's source repository. Then make my build script[2] specify that
file when I run 'paver lint'.

[1] http://bitbucket.org/dstanek/snake-guice/src/tip/pylint.cfg
[2] http://bitbucket.org/dstanek/snake-guice/src/tip/pavement.py

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
--
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy Performance

2009-04-23 Thread Robert Kern

On 2009-04-23 10:32, timlash wrote:

Still fairly new to Python.  I wrote a program that used a class
called RectangularArray as described here:

class RectangularArray:
def __init__(self, rows, cols, value=0):
   self.arr = [None]*rows
   self.row = [value]*cols
def __getitem__(self, (i, j)):
   return (self.arr[i] or self.row)[j]
def __setitem__(self, (i, j), value):
   if self.arr[i]==None: self.arr[i] = self.row[:]
   self.arr[i][j] = value

This class was found in a 14 year old post:
http://www.python.org/search/hypermail/python-recent/0106.html

This worked great and let me process a few hundred thousand data
points with relative ease.  However, I soon wanted to start sorting
arbitrary portions of my arrays and to transpose others.  I turned to
Numpy rather than reinventing the wheel with custom methods within the
serviceable RectangularArray class.  However, once I refactored with
Numpy I was surprised to find that the execution time for my program
doubled!  I expected a purpose built array module to be more efficient
rather than less.


It depends on how much you refactored you code. numpy tries to optimize bulk 
operations. If you are doing a lot of __getitem__s and __setitem__s with 
individual elements as you would with RectangularArray, numpy is going to do a 
lot of extra work creating and deleting the scalar objects.



I'm not doing any linear algebra with my data.  I'm working with
rectangular datasets, evaluating individual rows, grouping, sorting
and summarizing various subsets of rows.

Is a Numpy implementation overkill for my data handling uses?  Should
I evaluate prior array modules such as Numeric or Numarray?


No.

--
Robert Kern

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

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


Re: Configuring pylint for local conventions

2009-04-23 Thread Ben Finney
Ben Finney  writes:

> David Stanek  writes:
> 
> > I believe you just:
> >   pylint --generate-rcfile > ~/.pylintrc
> > and then customize that file.
> 
> This is the part that I'm asking how to do. What documentation is there
> on this configuration file and recommendations on how to modify it?

For bonus points, I'm actually wanting to know how to configure it per
*project*, and applying that configuration for all programmers of that
project. Having one set of coding conventions per *user* seem like a
recipe for frustration.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\   Brain, but culottes have a tendency to ride up so.” —_Pinky and |
_o__)   The Brain_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyGUI 2.0.4

2009-04-23 Thread rzed
David Robinow  wrote in
news:mailman.4403.1240449918.11746.python-l...@python.org: 

> On Wed, Apr 22, 2009 at 8:50 PM, rzed  wrote:
>> Greg Ewing  wrote in
>> news:49edb69f.7070...@canterbury.ac.nz:
>>
>>> PyGUI 2.0.4 is available:
>>>
>>>    http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/
>>>
[...]
>> I've always only gotten this response when I try to run the
>> blobedit demo:
>>  File "C:\extracted\PyGUI-2.0.4\Demos\BlobEdit\blobedit.py",
>> line 16, in 
>>    from GUI import Application, ScrollableView, Document,
>> Window, FileType, Cursor, rgb
>>  File "C:\Python25\Lib\site-packages\GUI\__init__.py", line 78,
>> in __getattr__
>>    traceback.print_stack()
>> Failed to import 'Application' from Applications
>> Traceback (most recent call last):
>>  File "C:\Python25\Lib\site-packages\GUI\__init__.py", line 69,
>> in __getattr__
>>    module = __import__(modname, self.__dict__, locals(), [name])
>> ImportError: No module named Applications
>>
>> I really don't know what this means. Is it a path issue? There
>> appears to be an Applications.py in GUI\Win32, with an
>> Application class. If there is some change I can make in the
>> code, can anyone tell me what to do? How can I fix it?
>>
[...]
>> --
>> rzed
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> You probably have PyGTK for windows installed.  PyGUI tries
> "Cocoa", "Gtk", and "Win32" in that order.  You can override that
> by: 
> 
> SET PYGUI_IMPLEMENTATION=Win32
> 
> (This is rather awkward.  Perhaps "Win32" should be tried before
> "Gtk"? ) 

Thank you VERY much for an excellent diagnosis and prescription. This 
does get beyond that frustrating barrier. 

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


Re: best way to compare contents of 2 lists?

2009-04-23 Thread John Yeung
Esmail  wrote:
> What is the best way to compare the *contents* of two different
> lists regardless of their respective order? The lists will have
> the same number of items, and be of the same type.

"Best" can mean different things.  Fastest?  Shortest code?  Most
readable?

> David Robinow wrote:
> > set(a) == set(b)    # test if a and b have the same elements
>
> > # check that each list has the same number of each element
> > # i.e.    [1,2,1,2] == [1,1,2,2], but [1,2,2,2] != [1,1,1,2]
> > for elem in set(a):
> >   a.count(elem) == b.count(elem)
>
> Ah .. this part would take care of different number of duplicates
> in the lists. Cool.

It takes care of the duplicates, but so does your initial solution,
which I like best:

> sorted(a)==sorted(b)

This is concise, clear, and in my opinion, the most Pythonic.  It may
well even be the fastest.  (If you didn't have to match up the numbers
of duplicates, the set solution would be most Pythonic and probably
fastest.)

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


Re: Configuring pylint for local conventions

2009-04-23 Thread Ben Finney
David Stanek  writes:

> I believe you just:
> 
>   pylint --generate-rcfile > ~/.pylintrc

That's the easy part, yes.

> and then customize that file.

This is the part that I'm asking how to do. What documentation is there
on this configuration file and recommendations on how to modify it?

-- 
 \“Pinky, are you pondering what I'm pondering?” “Wuh, I think |
  `\   so, Brain, but wouldn't anything lose its flavor on the bedpost |
_o__)   overnight?” —_Pinky and The Brain_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: best way to compare contents of 2 lists?

2009-04-23 Thread Esmail

Hans DushanthaKumar wrote:
'set' comes to mind, 


Yes, I thought about that, but I wasn't sure how to potentially
deal with different number of duplicates in the lists. The post
by David seems to address that issue nicely.


though I'm not sure if there are performance
inplications with large amopunts of data.


Yes, I wonder about these sort of things too, not knowing too
much about how Python does things internally.

Thanks for the suggestion,
Esmail

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


Re: best way to compare contents of 2 lists?

2009-04-23 Thread MRAB

Esmail wrote:

Esmail wrote:

What is the best way to compare the *contents* of two different
lists regardless of their respective order? The lists will have
the same number of items, and be of the same type.

E.g. a trivial example (my lists will be larger),

a=[1, 2, 3]

b=[2, 3, 1]

should yield true if a==b

I suppose I could sort them and then compare them. I.e.,

sorted(a)==sorted(b)


I am wondering if there is a more efficient/preferred way to do so.


oh, I forgot to mention that each list may contain duplicates. So I
suppose this means I would have to sort the two lists and compare them
afterall, unless there's another way?


You could use Raymond Hettinger's Counter class:

http://code.activestate.com/recipes/576611/

on both lists and compare them for equality.
--
http://mail.python.org/mailman/listinfo/python-list


Re: best way to compare contents of 2 lists?

2009-04-23 Thread Esmail

David Robinow wrote:

On Thu, Apr 23, 2009 at 9:31 PM, Esmail  wrote:

What is the best way to compare the *contents* of two different
lists regardless of their respective order? The lists will have
the same number of items, and be of the same type.

E.g. a trivial example (my lists will be larger),

a=[1, 2, 3]

b=[2, 3, 1]

should yield true if a==b

I suppose I could sort them and then compare them. I.e.,

sorted(a)==sorted(b)


I am wondering if there is a more efficient/preferred way to do so.

Thanks,
Esmail

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



set(a) == set(b)# test if a and b have the same elements

# check that each list has the same number of each element
# i.e.[1,2,1,2] == [1,1,2,2], but [1,2,2,2] != [1,1,1,2]
for elem in set(a):
  a.count(elem) == b.count(elem)


Ah .. this part would take care of different number of duplicates
in the lists. Cool.

thanks,
Esmail


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



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


Re: best way to compare contents of 2 lists?

2009-04-23 Thread Esmail

Esmail wrote:

What is the best way to compare the *contents* of two different
lists regardless of their respective order? The lists will have
the same number of items, and be of the same type.

E.g. a trivial example (my lists will be larger),

a=[1, 2, 3]

b=[2, 3, 1]

should yield true if a==b

I suppose I could sort them and then compare them. I.e.,

sorted(a)==sorted(b)


I am wondering if there is a more efficient/preferred way to do so.


oh, I forgot to mention that each list may contain duplicates. So I
suppose this means I would have to sort the two lists and compare them
afterall, unless there's another way?


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


Re: best way to compare contents of 2 lists?

2009-04-23 Thread David Robinow
On Thu, Apr 23, 2009 at 9:31 PM, Esmail  wrote:
> What is the best way to compare the *contents* of two different
> lists regardless of their respective order? The lists will have
> the same number of items, and be of the same type.
>
> E.g. a trivial example (my lists will be larger),
>
> a=[1, 2, 3]
>
> b=[2, 3, 1]
>
> should yield true if a==b
>
> I suppose I could sort them and then compare them. I.e.,
>
> sorted(a)==sorted(b)
>
>
> I am wondering if there is a more efficient/preferred way to do so.
>
> Thanks,
> Esmail
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

set(a) == set(b)# test if a and b have the same elements

# check that each list has the same number of each element
# i.e.[1,2,1,2] == [1,1,2,2], but [1,2,2,2] != [1,1,1,2]
for elem in set(a):
  a.count(elem) == b.count(elem)
--
http://mail.python.org/mailman/listinfo/python-list


RE: sorting two corresponding lists?

2009-04-23 Thread Hans DushanthaKumar
Just being pedantic here :)

[items[x] for x in [i for i in map(values.index, new_values)]]

Is the same as

[items[x] for x in map(values.index, new_values)]



-Original Message-
From: python-list-bounces+hans.dushanthakumar=hcn.com...@python.org
[mailto:python-list-bounces+hans.dushanthakumar=hcn.com...@python.org]
On Behalf Of Esmail
Sent: Friday, 24 April 2009 3:02 AM
To: tiefeng wu
Cc: python-list@python.org
Subject: Re: sorting two corresponding lists?


> My solution, I know the 'zip' version is more elegant, this is just
for 
> fun:)
>  
>  >>> items = ['apple', 'car', 'town', 'phone']
>  >>> values = [5, 2, 7, 1]
>  >>> new_values = sorted(values, reverse = True)
>  >>> new_items = [items[x] for x in [i for i in map(values.index, 
> new_values)]]
>  >>> print(new_values)
> [7, 5, 2, 1]
>  >>> print(new_items)
> ['town', 'apple', 'car', 'phone']
>  >>>
>  

Cool .. always good to know alternative ways of accomplishing
a task.

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


RE: best way to compare contents of 2 lists?

2009-04-23 Thread Hans DushanthaKumar
'set' comes to mind, though I'm not sure if there are performance
inplications with large amopunts of data.

>>> a=[1, 2, 3]
>>> b=[2, 3, 1]
>>> set(a) == set(b)
True



Cheers,
Hans

-Original Message-
From: python-list-bounces+hans.dushanthakumar=hcn.com...@python.org
[mailto:python-list-bounces+hans.dushanthakumar=hcn.com...@python.org]
On Behalf Of Esmail
Sent: Friday, 24 April 2009 11:31 AM
To: python-list@python.org
Subject: best way to compare contents of 2 lists?

What is the best way to compare the *contents* of two different
lists regardless of their respective order? The lists will have
the same number of items, and be of the same type.

E.g. a trivial example (my lists will be larger),

a=[1, 2, 3]

b=[2, 3, 1]

should yield true if a==b

I suppose I could sort them and then compare them. I.e.,

sorted(a)==sorted(b)


I am wondering if there is a more efficient/preferred way to do so.

Thanks,
Esmail

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


Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-23 Thread MRAB

Martin v. Löwis wrote:

MRAB wrote:

Martin v. Löwis wrote:
[snip]

To convert non-decodable bytes, a new error handler "python-escape" is
introduced, which decodes non-decodable bytes using into a private-use
character U+F01xx, which is believed to not conflict with private-use
characters that currently exist in Python codecs.

The error handler interface is extended to allow the encode error
handler to return byte strings immediately, in addition to returning
Unicode strings which then get encoded again.

If the locale's encoding is UTF-8, the file system encoding is set to
a new encoding "utf-8b". The UTF-8b codec decodes non-decodable bytes
(which must be >= 0x80) into half surrogate codes U+DC80..U+DCFF.


If the byte stream happens to include a sequence which decodes to
U+F01xx, shouldn't that raise an exception?


I apparently have not expressed it clearly, so please help me improve
the text. What I mean is this:

- if the environment encoding (for lack of better name) is UTF-8,
  Python stops using the utf-8 codec under this PEP, and switches
  to the utf-8b codec.
- otherwise (env encoding is not utf-8), undecodable bytes get decoded
  with the error handler. In this case, U+F01xx will not occur
  in the byte stream, since no other codec ever produces this PUA
  character (this is not fully true - UTF-16 may also produce PUA
  characters, but they can't appear as env encodings).
So the case you are referring to should not happen.


I think what's confusing me is that you talk about mapping non-decodable
bytes to U+F01xx, but you also talk about decoding to half surrogate
codes U+DC80..U+DCFF.

If the bytes are mapped to single half surrogate codes instead of the
normal pairs (low+high), then I can see that decoding could never be
ambiguous and encoding could produce the original bytes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Configuring pylint for local conventions (was: pyflakes, pylint, pychecker - and other tools)

2009-04-23 Thread David Stanek
On Thu, Apr 23, 2009 at 12:00 PM, Aahz  wrote:
> In article <874owf4gky.fsf...@benfinney.id.au>,
> Ben Finney   wrote:
>>a...@pythoncraft.com (Aahz) writes:
>>>
>>> Second, you can configure pylint to respect your personal style
>>
>>How? I haven't seen any decent documentation on doing so.
>
> Actually, I don't know how, I'm just repeating what was claimed at a
> presentation on pylint.  ;-)  I've traditionally used pychecker myself
> and haven't seen any reason to switch.


I believe you just:

  pylint --generate-rcfile > ~/.pylintrc

and then customize that file.

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
--
http://mail.python.org/mailman/listinfo/python-list


best way to compare contents of 2 lists?

2009-04-23 Thread Esmail

What is the best way to compare the *contents* of two different
lists regardless of their respective order? The lists will have
the same number of items, and be of the same type.

E.g. a trivial example (my lists will be larger),

a=[1, 2, 3]

b=[2, 3, 1]

should yield true if a==b

I suppose I could sort them and then compare them. I.e.,

sorted(a)==sorted(b)


I am wondering if there is a more efficient/preferred way to do so.

Thanks,
Esmail

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


Re: Essential tools for Python development

2009-04-23 Thread Ben Finney
Phillip B Oldham  writes:

> On Apr 22, 5:00 am, Ben Finney  wrote:
> > code each module so that the behaviour is easily introspected and
> > tested from outside the module. If I'm not able to easily introspect
> > the code at an interactive prompt, that's a clear sign that the code
> > interface is poorly designed. So I fix that first.
> 
> Could you give a small example of this approach?

Sure, though the principle is general and applies to many different
situations (there are many more ways to write bad code than ways to
write good code :-)

A common anti-pattern is a swath of code that does too much in one
lump. A contrived example::

def one_man_band():
intermediate_result = (frob * spang) + foo
floop.twiddle(intermediate_result)
floop.juggle()
secondary_result = spam.register(intermediate_result)
return secondary_result

This is difficult to introspect because it's not clearly parameterised,
and it does too many things so it's difficult to trigger only part of
its behaviour for testing.

Depending on the conceptual arrangement of the steps and their actual
semantic meaning, this might work better as::

def frob_and_spang(foo):
result = (frob * spang) + foo
return result

def convert_floop(floop, twiddler):
floop.twiddle(twiddler)
floop.juggle()

def register_spam(spam, entry):
result = spam.register(entry)
return result

def one_man_band():
foo_twiddler = frob_and_spang(foo)
convert_floop(foo_twiddler)
result = register_spam(foo_twiddler)
return result

Rather contrived, but I hope you can see that this approach makes it
much easier to get at any of the steps that comprise ‘one_man_band’ from
outside the module, and introspect them simply by calling small
functions. Debugging is much easier with this design.

This also makes them easier to unit test; in fact, if unit testing is
adopted as a mandatory practice, it's much more likely to result in the
loosely-coupled approach *first* rather than needing to be refactored to
achieve it later.

-- 
 \ “I may disagree with what you say, but I will defend to the |
  `\death your right to mis-attribute this quote to Voltaire.” |
_o__) —Avram Grumer, rec.arts.sf.written, May 2000 |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Presentation software for Python code

2009-04-23 Thread Neal Becker
John Reid wrote:

> 
> 
> Scott David Daniels wrote:
>> Michael Hoffman wrote:
>> You might take a look at Crunchy, and just do up your talk there.
>> Crunchy is a Python program that combines an otherwise static html
>> document with an interactive Python session within a browser
>> http://code.google.com/p/crunchy/
> 
> IPython offers something similar for giving demos. I've found that very
> useful in the past.
> 
Really?  Any pointers?


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


Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-23 Thread James Y Knight


On Apr 22, 2009, at 2:50 AM, Martin v. Löwis wrote:


I'm proposing the following PEP for inclusion into Python 3.1.
Please comment.


+1. Even if some people still want a low-level bytes API, it's  
important that the easy case be easy. That is: the majority of Python  
applications should *just work, damnit* even with not-properly-encoded- 
in-current-LC_CTYPE filenames. It looks like this proposal  
accomplishes that, and does so in a relatively nice fashion.


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


Re: Presentation software for Python code

2009-04-23 Thread alex23
On Apr 24, 3:52 am, Michael Hoffman <4g4trz...@sneakemail.com> wrote:
> Does anyone here have software they would suggest for making a
> presentation that includes Python code? Other than that it would
> probably be mainly bullet points. I'm willing to consider TeX- and
> HTML-based approaches.

How do you feel about reStructuredText? If you're open to it, I highly
recommend Bruce: http://pypi.python.org/pypi/bruce

It also supports embedded interpreters in the presentation, which I've
seen using to good effect at conventions.
--
http://mail.python.org/mailman/listinfo/python-list


Re: can't find the right simplification

2009-04-23 Thread ma
Not sure I understand what is self.P, but look at the __getitem__ and  
__setitem__ overloads


--Sent from my iPhone

On Apr 23, 2009, at 7:10 PM, Stef Mientki   
wrote:



hello,

I've a program where you can connect snippets of code (which I call  
a "Brick") together to create a program.
To make it easier to create these code snippets, I need some  
simplifications.

For simple parameters ( integer, tupple, list etc)  this works ok,
and is done like this:


class _Simple_Par ( object ) :
  """
  Class to make it more easy to set a Bricks.Par from a control.
  So instead of :
self.Brick.Par [ self.EP[0] ] = Some_Value
  you can write
self.P[0] = Some_Value
  """
  def __init__ ( self, control ) :
  self.Control = control
  def __setitem__ ( self, index, value ) :
  i = self.Control.EP [ index ]
  if i :
  self.Control.Brick.Par [ i ] = value

Now I want a similar simplification for the case that Par is a  
dictionary:

So instead of writing:
self.Brick.Par [ self.EP[0] ] [ 'Filename' ] = Some_Value

I would like to write:
self.P[0] [ 'Filename' ] = Some_Value

But I can't figure out how to accomplish that ?

Any suggestions ?

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list

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


Re: Regular expression to capture model numbers

2009-04-23 Thread John Machin
On Apr 24, 1:29 am, Piet van Oostrum  wrote:
> > John Machin  (JM) wrote:
> >JM> On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote:
> >>> Requirements:
> >>>   The text must contain a combination of numbers, alphabets and hyphen
> >>> with at least two of the three elements present.
> >JM> Unfortunately(?), regular expressions can't express complicated
> >JM> conditions like that.
>
> Yes, they can but it is not pretty.
>
> The pattern must start with a letter, a digit or a hyphen.
>
> If it starts with a letter, for example, there must be at least a hyphen
> or a digit somewhere. So let us concentrate on the first one of these
> that occurs in the string. Then the preceding things are only letters
> and after it can be any combination of letters, digits and hyphens. So
> the pattern for this is (when we write L for letters, and d for digits):
>
> L+[-d][-Ld]*.
>
> Similarly for strings starting with a digit and with a hyphen. Now
> replacing L with [A-Za-z] and d with [0-9] or \d and factoring out the
> [-Ld]* which is common to all 3 cases you get:
>
> (?:[A-Za-z]+[-0-9]|[0-9]+[-A-Za-z]|-+[0-9A-Za-z])[-0-9A-Za-z]*
>
> >>> obj = 
> >>> re.compile(r'(?:[A-Za-z]+[-0-9]|[0-9]+[-A-Za-z]|-+[0-9A-Za-z])[-0-9A-Za-z]*')
> >>> re.findall(obj, 'TestThis;1234;Test123AB-x')
>
> ['Test123AB-x']
>
> Or you can use re.I and mention only one case of letters:
>
> obj = re.compile(r'(?:[a-z]+[-0-9]|[0-9]+[-a-z]|-+[0-9a-z])[-0-9a-z]*', re.I)

Understandable and maintainable, I don't think. Suppose that instead
the first character is limited to being alphabetic. You have to go
through the whole process of elaborating the possibilites again, and I
don't consider that process qualifies as "express[ing] complicated
conditions like that".

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


Re: [False,True] and [True,True] --> [True, True]?????

2009-04-23 Thread Lawrence D'Oliveiro
In message , Steven 
D'Aprano wrote:

> On Thu, 23 Apr 2009 13:40:47 +1200, Lawrence D'Oliveiro wrote:
> 
>> In message <25f4735b-52a2-4d53-9097-
>> e623655ca...@k19g2000prh.googlegroups.com>, bdb112 wrote:
>> 
>>> Is there any obvious reason why
>>> [False,True] and [True,True]
>>> gives [True, True]
>> 
>> 
> 
> Any programming feature is subject to errors from people who
> try to guess what it does instead of reading the Fine Manual, and Python
> has no obligation to make every language feature match the random
> preconceptions of every user. Or even some subset of users.



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


Re: http web fetch question

2009-04-23 Thread grocery_stocker
On Apr 23, 3:29 pm, Chris Rebert  wrote:
> On Thu, Apr 23, 2009 at 3:21 PM, grocery_stocker  wrote:
> > Say I have a script that fetches data from a website every hour. Is
> > there a general solution or is the solution operating system specific?
>
> WRT the periodic operation part of your task, there's the `sched`
> module --http://docs.python.org/library/sched.html
>

Maybe I'm being a tad bit dense here, but I don't see how this
schedule mod can be used to fetch data from a website every hour for
10 hours straight and why this is different than using something like
time.sleep().
--
http://mail.python.org/mailman/listinfo/python-list


Re: Presentation software for Python code

2009-04-23 Thread Michael Hoffman

Thanks for the suggestions.


And if you do use Crunchy for a presentation, you might be interested
in the html style used for Crunchy's own talk at the latest Pycon:
http://us.pycon.org/media/2009/talkdata/PyCon2009/012/crunchy_.html


H, I have to click on the next link every time?

The best option might be to use an existing HTML presentation style with 
keyboard shortcuts.

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


Re: Large data arrays?

2009-04-23 Thread John Machin
On Apr 23, 8:22 pm, Ole Streicher  wrote:
> Hi,
>
> for my application, I need to use quite large data arrays
> (100.000 x 4000 values) with floating point numbers where I need a fast
> row-wise and column-wise access (main case: return a column with the sum
> over a number of selected rows, and vice versa).
>
> I would use the numpy array for that, but they seem to be
> memory-resistent. So, one of these arrays would use about 1.6 GB
> memory which far too much. So I was thinking about a memory mapped
> file for that. As far as I understand, there is one in numpy.
>
> For this, I have two questions:
>
> 1. Are the "numpy.memmap" array unlimited in size (resp. only limited
> by the maximal file size)? And are they part of the system's memory
> limit (~3GB for 32bit systems)?
>
> 2. Since I need row-wise as well as column-wise access, a simple usage
> of a big array as memory mapped file will probably lead to a very poor
> performance, since one of them would need to read values splattered
> around the whole file. Are there any "plug and play" solutions for
> that? If not: what would be the best way to solve this problem?
> Probably, one needs to use someting like the "Morton layout" for the
> data. Would one then build a subclass of memmap (or ndarray?) that
> implements this specific layout? How would one do that? (Sorry, I am
> still a beginner with respect to python).

The Morton layout wastes space if the matrix is not square. Your 100K
x 4K is very non-square. Looks like you might want to use e.g. 25
Morton arrays, each 4K x 4K.

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


Re: PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-23 Thread Cameron Simpson
On 24Apr2009 09:27, I wrote:
| If I'm writing a general purpose UNIX tool like chmod or find, I expect
| it to work reliably on _any_ UNIX pathname. It must be totally encoding
| blind. If I speak to the os.* interface to open a file, I expect to hand
| it bytes and have it behave. As an explicit example, I would be just fine
| with python's open(filename, "w") to take a string and encode it for use,
| but _not_ ok for os.open() to require me to supply a string and cross
| my fingers and hope something sane happens when it is turned into bytes
| for the UNIX system call.
| 
| I'm very much in favour of being able to work in strings for most
| purposes, but if I use the os.* interfaces on a UNIX system it is
| necessary to be _able_ to work in bytes, because UNIX file pathnames
| are bytes.

Just to follow up to my own words here, I would be ok for all the
pure-byte stuff to be off in the "posix" module if os.* goes pure
character instead of bytes or bytes+strings.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

... that, in a few years, all great physical constants will have been
approximately estimated, and that the only occupation which will be
left to men of science will be to carry these measurements to another
place of decimals.  - James Clerk Maxwell (1813-1879)
  Scientific Papers 2, 244, October 1871
--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-23 Thread MRAB

tinn...@isbd.co.uk wrote:

It seems to me that mailbox.mbox.add() sets the access time of a mbox
file as well as the modification time.  This is not good for MUAs that
detect new mail by looking to see if the access time is before the
modification time.

Have I done something wrong somewhere or is mailbox.mbox.add() really
as broken as it would appear?


[snip]
The access time is the time it was last accessed, ie read or modified.

The modification time is the time it was last modified.

The access time can never be before the modification time because it
must be accessed in order to be modified!
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-23 Thread Cameron Simpson
On 22Apr2009 08:50, Martin v. L�wis  wrote:
| File names, environment variables, and command line arguments are
| defined as being character data in POSIX;

Specific citation please? I'd like to check the specifics of this.

| the C APIs however allow
| passing arbitrary bytes - whether these conform to a certain encoding
| or not.

Indeed.

| This PEP proposes a means of dealing with such irregularities
| by embedding the bytes in character strings in such a way that allows
| recreation of the original byte string.
[...]

So you're proposing that all POSIX OS interfaces (which use byte strings)
interpret those byte strings into Python3 str objects, with a codec
that will accept arbitrary byte sequences losslessly and is totally
reversible, yes?

And, I hope, that the os.* interfaces silently use it by default.

| For most applications, we assume that they eventually pass data
| received from a system interface back into the same system
| interfaces. For example, and application invoking os.listdir() will
| likely pass the result strings back into APIs like os.stat() or
| open(), which then encodes them back into their original byte
| representation. Applications that need to process the original byte
| strings can obtain them by encoding the character strings with the
| file system encoding, passing "python-escape" as the error handler
| name.

-1

This last sentence kills the idea for me, unless I'm missing something.
Which I may be, of course.

POSIX filesystems _do_not_ have a file system encoding.

The user's environment suggests a preferred encoding via the locale
stuff, and apps honouring that will make nice looking byte strings as
filenames for that user. (Some platforms, like MacOSX' HFS filesystems,
_do_ enforce an encoding, and a quite specific variety of UTF-8 it is;
I would say they're not a full UNIX filesystem _precisely_ because they
reject certain byte strings that are valid on other UNIX filesystems.
What will your proposal do here? I can imagine it might cope with
existing names, but what happens when the user creates a new name?)

Further, different users can use different locales and encodings.
If they do it in different work areas they'll be perfectly happy;
if they do it in a shared area doubtless confusion will reign,
but only in the users' minds, not in the filesystem.

If I'm writing a general purpose UNIX tool like chmod or find, I expect
it to work reliably on _any_ UNIX pathname. It must be totally encoding
blind. If I speak to the os.* interface to open a file, I expect to hand
it bytes and have it behave. As an explicit example, I would be just fine
with python's open(filename, "w") to take a string and encode it for use,
but _not_ ok for os.open() to require me to supply a string and cross
my fingers and hope something sane happens when it is turned into bytes
for the UNIX system call.

I'm very much in favour of being able to work in strings for most
purposes, but if I use the os.* interfaces on a UNIX system it is
necessary to be _able_ to work in bytes, because UNIX file pathnames
are bytes.

If there isn't a byte-safe os.* facility in Python3, it will simply be
unsuitable for writing low level UNIX tools. And I very much like using
Python2 for that.

Finally, I have a small python program whose whole purpose in life
is to transcode UNIX filenames before transfer to a MacOSX HFS
directory, because of HFS's enforced particular encoding. What approach
should a Python app take to transcode UNIX pathnames under your scheme?

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

The nice thing about standards is that you have so many to choose from;
furthermore, if you do not like any of them, you can just wait for next
year's model.   - Andrew S. Tanenbaum
--
http://mail.python.org/mailman/listinfo/python-list


Re: Presentation software for Python code

2009-04-23 Thread André
On Apr 23, 4:16 pm, Scott David Daniels  wrote:
> Michael Hoffman wrote:
> >... Does anyone here have software they would suggest for making a
> > presentation that includes Python code? Other than that it would
> > probably be mainly bullet points. I'm willing to consider TeX- and
> > HTML-based approaches.
>
> You might take a look at Crunchy, and just do up your talk there.
> Crunchy is a Python program that combines an otherwise static html
> document with an interactive Python session within a browser
>      http://code.google.com/p/crunchy/
>
> A demo from an earlier version of Crunchy  (when thedemo was made,
> Firfox only). The basic features of that early version of Crunchy
> are demonstrated in this screencast.
>
>      http://showmedo.com/videos/video?name=143&fromSeriesID=143
>

And if you do use Crunchy for a presentation, you might be interested
in the html style used for Crunchy's own talk at the latest Pycon:
http://us.pycon.org/media/2009/talkdata/PyCon2009/012/crunchy_.html


André Roberge



> --Scott David Daniels
> scott.dani...@acm.org

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


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread David Lyon


On Thu, 23 Apr 2009 14:02:19 -0700, norseman  wrote:
> If you think I'm somehow able to take a look at a plain piece of code
> you posted yesterday and know that it was written 26 years ago on a CP/M
> 2.0 dual HD DS 8" floppy drive system using Microsoft Assembly for the
> Z80 chip, intended as a generic print driver for the IBM Seletric
> converted to operate with computers of the day - you have an unrealistic
> esteem of my abilities.

Funny :-)

A build test under the last 5 significant versions of python interpretors 
would probably pick up the fact that it is dead code

hello:
mov bh,25
mov ah,bh

you had cp/m version 2? - wow

We're all ok... as far as we know

David



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


can't find the right simplification

2009-04-23 Thread Stef Mientki

hello,

I've a program where you can connect snippets of code (which I call a 
"Brick") together to create a program.
To make it easier to create these code snippets, I need some 
simplifications.

For simple parameters ( integer, tupple, list etc)  this works ok,
and is done like this:


class _Simple_Par ( object ) :
   """
   Class to make it more easy to set a Bricks.Par from a control.
   So instead of :
 self.Brick.Par [ self.EP[0] ] = Some_Value
   you can write
 self.P[0] = Some_Value
   """
   def __init__ ( self, control ) :
   self.Control = control
   def __setitem__ ( self, index, value ) :
   i = self.Control.EP [ index ]
   if i :
   self.Control.Brick.Par [ i ] = value

Now I want a similar simplification for the case that Par is a dictionary:
So instead of writing:
 self.Brick.Par [ self.EP[0] ] [ 'Filename' ] = Some_Value

I would like to write:
 self.P[0] [ 'Filename' ] = Some_Value

But I can't figure out how to accomplish that ?

Any suggestions ?

thanks,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-list


mailbox.mbox.add() sets access time as well as modification time

2009-04-23 Thread tinnews
It seems to me that mailbox.mbox.add() sets the access time of a mbox
file as well as the modification time.  This is not good for MUAs that
detect new mail by looking to see if the access time is before the
modification time.

Have I done something wrong somewhere or is mailbox.mbox.add() really
as broken as it would appear?

The snippet of code that adds messages to a mbox is:-

# previous code works out what destDir is (yes, I know it's not actually a 
directory)
dest = mailbox.mbox(destDir, factory=None)
dest.lock() 
dest.add(m)
dest.flush()
dest.unlock()


-- 
Chris Green

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


Re: http web fetch question

2009-04-23 Thread Chris Rebert
On Thu, Apr 23, 2009 at 3:21 PM, grocery_stocker  wrote:
> Say I have a script that fetches data from a website every hour. Is
> there a general solution or is the solution operating system specific?

WRT the periodic operation part of your task, there's the `sched`
module -- http://docs.python.org/library/sched.html

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


Re: http web fetch question

2009-04-23 Thread Jean-Paul Calderone

On Thu, 23 Apr 2009 15:21:21 -0700 (PDT), grocery_stocker  
wrote:

Say I have a script that fetches data from a website every hour. Is
there a general solution or is the solution operating system specific?


General solution to what problem?

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


Re: http web fetch question

2009-04-23 Thread Philip Semanchuk


On Apr 23, 2009, at 6:21 PM, grocery_stocker wrote:


Say I have a script that fetches data from a website every hour. Is
there a general solution or is the solution operating system specific?


It's not OS-specific. See the Python standard library modules urllib,  
urllib2, or just run a command line utility like wget or curl.


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


http web fetch question

2009-04-23 Thread grocery_stocker
Say I have a script that fetches data from a website every hour. Is
there a general solution or is the solution operating system specific?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the best framework or module in Python for a small GUI based application development?

2009-04-23 Thread Peter Decker
On Wed, Apr 22, 2009 at 12:40 PM, John Fabiani  wrote:

> You might consider Dabo (www.dabodev.com) if access to data is required.

You might also consider it if you like a simple, Pythonic UI. I don't
work with databases, and I love Dabo for creating lots of utilities
for interfacing with, say, text processing scripts, data analysis, or
displaying the results of various web services.

-- 

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


Re: first, second, etc line of text file

2009-04-23 Thread Scott David Daniels

Gabriel Genellina wrote:
En Wed, 25 Jul 2007 19:14:28 -0300, James Stroud  
escribió:

Daniel Nogradi wrote:

A very simple question: I currently use a cumbersome-looking way of
getting the first, second, etc. line of a text file:

to_get = [0, 3, 7, 11, 13]
got = dict((i,s) for (i,s) in enumerate(open(textfile)) if i in to_get)
print got[3]
This would probably be the best way for really big files and if you know
all of the lines you want ahead of time.
But it still has to read the complete file (altough it does not keep the 
unwanted lines).
Combining this with Paul Rubin's suggestion of itertools.islice I think 
we get the best solution:
got = dict((i,s) for (i,s) in 
enumerate(islice(open(textfile),max(to_get)+1)) if i in to_get)


or even faster:
wanted = set([0, 3, 7, 11, 13])
with open(textfile) as src:
got = dict((i, s) for (i, s) in enumerate(islice(src,
min(wanted), max(wanted) + 1))
   if i in wanted)
Of course that could just as efficiently create a list as a dict.
Note that using a list rather than a set for wanted takes len(wanted)
comparisons on misses, and len(wanted)/2 on hits, but most likely a
single comparison for a dict whether it is a hit or a miss.

--Scott David Daniels
scott.dani...@acm.org

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


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Jeremy Banks
On Apr 23, 5:23 pm, Terry Reedy  wrote:
> Jeremy Banks wrote:
> > Hi. I'm sure there've been debates about this before, but I can't seem
> > to figure out what to search for to pull them up, so I'm asking here.
>
> > It seems to me that a lot of things could be made much easier if you
> > could use primaries other than basic identifiers for the target of
> > function definitions. For example, if attribute references were
> > allowed I'd be able to do:
>
> >     def foo.bar():
> >         return("I'm a method!")
>
> > If we wanted to get even more liberal (which I don't see as a bad
> > thing, but I could see being found more objectionable by some), we
> > could allow the use of anything that's a valid assignment target. For
> > example:
>
> >     def foo["bar']():
> >         return("I'm a function referenced in a mapping object!")
>
> > In this case I could see there being a problem in that there's nothing
> > to get the function's __name__ from, but that doesn't apply for the
> > first example.
>
> > Many uses of this may not be Pythonic, but I'm sure there are many
> > that are. It just feels like an arbitrary restriction, preventing
> > users from doing something that may be useful.
>
> > Any feedback or direction to previous discussion on the subject would
> > be appreciated. Thanks!
>
> There has been some discussion on py-dev and perhaps python-ideas, but I
> cannot remember any specifics as to why Guido was unpersuaded/negative.
>
> If one regards
>
> def name(params): body
>
> as syntantic sugar for a (somewhat hypothetical) assignment statement
>
> name = make_func('name', "params", "body")
>
> (there is a function_maker function in the new module, though with a
> more complicated interface), then generalizing the target would seem
> reasonable.  The function's __name__ does not seem like an issue:
> "foo.bar" and "foo['bar']" both direct one to the proper definition code.
>
> Counter-argument: class and import are also implied assignments, and
> they also subject to the same limitation.
>
> Counter-counter-argument: a) doing actual assignments with name =
> type('name', bases, dict) and name = __import__('name',...) is more
> feasible, and b) the need for qualified names is less for class and
> probably for import and c) the restriction *could* also be lifted for
> those two statements also.
>
> For some, a plus for this proposal is that is directly binds the
> function to the target without introducing a spurious name into the
> local scope.  It would thus reduce the perceived need for and hence
> pressure for generalized function expressions.  I believe Guido would
> consider this last point a plus if so stated.
>
> I do not believe this recurring idea has been the subject of a PEP.  If
> not, writing one might be a service, should you choose to do so, even if
> rejected.
>
> Terry Jan Reedy

Interesting, thank you very much for your suggestions. I'll try to put
together a draft.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread norseman

David Stanek wrote:

On Thu, Apr 23, 2009 at 1:12 PM, norseman  wrote:

BB's, User Lists, all repositories can make these required before
acceptance.




This is open source. I volunteer my time on the projects that I
maintain. If you don't like the quality or lack of documentations,
tests, etc. Contribute. Or just don't use the software.

What maybe another option is to have a karma rating on PYPI. Maybe
based off of home much you are included in other packages or some
other factors.
 ^

 ..how much..
(nice to know I'm not the only one that does that :)

I find that a useful idea. A good concept for "retro grading".


Whenever I run a team I make it a practice to never make the others do 
something I won't.  I do ask for volunteers to do things I cannot.


Lets start with - what's done is done. (What is out there is there.)
If you think I'm somehow able to take a look at a plain piece of code 
you posted yesterday and know that it was written 26 years ago on a CP/M 
2.0 dual HD DS 8" floppy drive system using Microsoft Assembly for the 
Z80 chip, intended as a generic print driver for the IBM Seletric 
converted to operate with computers of the day - you have an unrealistic 
esteem of my abilities.


If you won't make the request to those supplying things you maintain - I 
have an unrealistic esteem of your efforts in protecting Open Source and 
its use by others.


Fair enough?

Everyone OK?


If ever you are in Sacramento, CA; E-me a note.  There is a pub down the 
way from where I work.  I'll buy you a pint.  While there, perhaps we 
could write that crawler that collects for the "retro grading".



Steve
norse...@hughes.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: value error

2009-04-23 Thread Terry Reedy

Francesco Pietra wrote:

hi:
with script

data = open('134-176_rectified_edited.pdb', 'r')
outp = open('134-176_renumbered.pdb', 'w')

for L in data:
   if L[3] == 'M':
 L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:]
   outp.write(L)


i wanted to modify lines of the type:
ATOM  1 HH31 ACE 1   1.573   1.961   0.769  1.00  0.00   H

to add 133 to column 25, getting 134 there, and so on for next lines 2
-> 135, 3 -> 136, etc.


A side note in addition to solution given: when writing code like this, 
to operate on column-oriented date, which I have done much of, I find it 
helpful to include in the code something like


# Sample line
#   1 2 3 4 5 6
# 012345678901234567890123456789012345678901234567890123456789012345 ...
# ATOM  1 HH31 ACE 1   1.573   1.961   0.769  1.00  0.00

Having done so...
Since slice indexes cut to the left of the corrresponding item index, I 
suspect you actually want

   L = L[:25] + "%4d" % (int(L[25:29])+133) + L[29:]
if the number is currently left-justified in its field (but note that 
%4d will *right*-justify the new number), or

   L = L[:22] + "%4d" % (int(L[22:26])+133) + L[26:]
if the number is currently right-justified.

If the data file is too big to verify correct formatting by eye, I also 
typically did preliminary checks first.  For instance, is every line 
exact the right length.  In this case, you better by sure that there are 
at most 9866 records, so you do not over-flow your four-char field.


Terry Jan Reedy

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


Re: Cython + tuple unpacking

2009-04-23 Thread Stefan Behnel
Hugues Salamin wrote:
> The following code will crash with a segfault when compiled using cython 
> (v0.11)
> 
> def func():
> for (a, b) ,c ,d in zip(zip(range(3), range(3)), range(3), range(3)):
> print a, b
> print c
> print d # This line segfault
> 
> Compilation is done using distutils.
> 
> If the module is imported in python and func is called, I got a segmentation
> fault at the line "print d".

Yes, this works for me in the latest (unstable) developer branch, but fails
in the release branch:

  $ cd cython-unstable
  $ cat rangeloop.pyx
  def func():
  for (a, b) ,c ,d in zip(zip(range(3), range(3)), range(3), range(3)):
  print a, b
  print c
  print d # This line segfault

  $ python2.6 -c 'import pyximport; pyximport.install(); \
 import rangeloop; rangeloop.func()'
  0 0
  0
  0
  1 1
  1
  1
  2 2
  2
  2

  $ cd ../cython-release
  $ python2.6 -c 'import pyximport; pyximport.install(); \
 import rangeloop; rangeloop.func()'
  0 0
  0
  Segmentation fault

Not sure why. I'm moving this to the Cython mailing list, we should be able
to help you there.

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


Re: Strange problem when using imp.load_module

2009-04-23 Thread Arnaud Delobelle
pythoncuri...@gmail.com writes:

> Hi,

Hi, I have a guess at explaining the behaviour you describe - see below.

> I'm having problem when I'm trying to import modules using the
> imp.load_module function.
> At the end of this post there's some code I wrote to illustrate the
> problem.
> The code istself doesn't make much sense, but what I'm trying to do in
> reality is allow people to customize an application by writing a small
> python module. If I find a file in a known location with a known name,
> I'll import it and use some data or function in it.
> I ran into problems when writing unit tests for it.
>
> What happens when run my code is this:
>
> .E
> ==
> ERROR: test_2 (__main__.Test)
> --
> Traceback (most recent call last):
>   File "test_import.py", line 30, in test_2
> getattr(imported, 'y')
> AttributeError: 'module' object has no attribute 'y'
> --
> Ran 2 tests in 0.015s
>
>
> So it seems that test_2 fails. It does pretty much the same thing as
> test_1, but with different data.
> Changing test_2 to check for 'x' instead of 'y' makes it pass, but
> that's not the result I should get.
> So it seems that I still have the module that I imported in test_1.
>
> So, I'm thinking that I might be dealing with some sort of gc issue.
> I add the "time.sleep(1)", (commented in the code) and the tests pass.
> 'y' is found in test_2.
> Replacing the sleep with a gc.collect() makes the test fail again, so
> garbage collection doesn't seem to help.
>
> I've tried it on python 2.6.1 on windows, 2.5.2 in cygwin and 2.6.1 on
> solaris with the same results.
> Could anyone explain what I am missing?
>
> Thanks
> /Mattias
>
> Here's the code:
>
> import unittest
> import tempfile, os, imp, time, gc
>
> module_file_name=os.path.join(tempfile.gettempdir(), 'my_module.py')
>
> def write_module(data):
> f = open(module_file_name, 'w')
> f.write(data)
> f.close()
>
> def import_from_file(path):
> imported_module = imp.load_source(module_file_name, path)
> return imported_module
>
> class Test(unittest.TestCase):
> def tearDown(self):
> os.unlink(module_file_name)
>
> def test_1(self):
> module_data='''x=1'''
> write_module(module_data)
> imported=import_from_file(module_file_name)

This will compile the module and create a 'my_module.pyc' file.

> getattr(imported, 'x')
>
> def test_2(self):
> # time.sleep(1)
> module_data='''y=2'''
> write_module(module_data)
> imported=import_from_file(module_file_name)

My guess is that without the sleep(1), the imp.load_source function will
use the compiled file 'my_module.pyc' created in test_1 instead of
compiling the new 'my_module.py' file.

This would be because the new 'my_module.py' file is created so soon
after the last compilation of the module that they have the same
timestamp, thus fooling imp.load_source into thinking that
'my_module.py' was not modified since its last compilation.

> getattr(imported, 'y')
>
> if __name__ == "__main__":
> unittest.main()

HTH

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


Re: Presentation software for Python code

2009-04-23 Thread John Reid



Scott David Daniels wrote:

Michael Hoffman wrote:
You might take a look at Crunchy, and just do up your talk there.
Crunchy is a Python program that combines an otherwise static html
document with an interactive Python session within a browser
http://code.google.com/p/crunchy/


IPython offers something similar for giving demos. I've found that very 
useful in the past.


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


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Terry Reedy

Jeremy Banks wrote:

Hi. I'm sure there've been debates about this before, but I can't seem
to figure out what to search for to pull them up, so I'm asking here.

It seems to me that a lot of things could be made much easier if you
could use primaries other than basic identifiers for the target of
function definitions. For example, if attribute references were
allowed I'd be able to do:

def foo.bar():
return("I'm a method!")

If we wanted to get even more liberal (which I don't see as a bad
thing, but I could see being found more objectionable by some), we
could allow the use of anything that's a valid assignment target. For
example:

def foo["bar']():
return("I'm a function referenced in a mapping object!")


In this case I could see there being a problem in that there's nothing
to get the function's __name__ from, but that doesn't apply for the
first example.

Many uses of this may not be Pythonic, but I'm sure there are many
that are. It just feels like an arbitrary restriction, preventing
users from doing something that may be useful.

Any feedback or direction to previous discussion on the subject would
be appreciated. Thanks!


There has been some discussion on py-dev and perhaps python-ideas, but I 
cannot remember any specifics as to why Guido was unpersuaded/negative.


If one regards

def name(params): body

as syntantic sugar for a (somewhat hypothetical) assignment statement

name = make_func('name', "params", "body")

(there is a function_maker function in the new module, though with a 
more complicated interface), then generalizing the target would seem 
reasonable.  The function's __name__ does not seem like an issue: 
"foo.bar" and "foo['bar']" both direct one to the proper definition code.


Counter-argument: class and import are also implied assignments, and 
they also subject to the same limitation.


Counter-counter-argument: a) doing actual assignments with name = 
type('name', bases, dict) and name = __import__('name',...) is more 
feasible, and b) the need for qualified names is less for class and 
probably for import and c) the restriction *could* also be lifted for 
those two statements also.


For some, a plus for this proposal is that is directly binds the 
function to the target without introducing a spurious name into the 
local scope.  It would thus reduce the perceived need for and hence 
pressure for generalized function expressions.  I believe Guido would 
consider this last point a plus if so stated.


I do not believe this recurring idea has been the subject of a PEP.  If 
not, writing one might be a service, should you choose to do so, even if 
rejected.


Terry Jan Reedy

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


Strange problem when using imp.load_module

2009-04-23 Thread pythoncurious
Hi,

I'm having problem when I'm trying to import modules using the
imp.load_module function.
At the end of this post there's some code I wrote to illustrate the
problem.
The code istself doesn't make much sense, but what I'm trying to do in
reality is allow people to customize an application by writing a small
python module. If I find a file in a known location with a known name,
I'll import it and use some data or function in it.
I ran into problems when writing unit tests for it.

What happens when run my code is this:

.E
==
ERROR: test_2 (__main__.Test)
--
Traceback (most recent call last):
  File "test_import.py", line 30, in test_2
getattr(imported, 'y')
AttributeError: 'module' object has no attribute 'y'
--
Ran 2 tests in 0.015s


So it seems that test_2 fails. It does pretty much the same thing as
test_1, but with different data.
Changing test_2 to check for 'x' instead of 'y' makes it pass, but
that's not the result I should get.
So it seems that I still have the module that I imported in test_1.

So, I'm thinking that I might be dealing with some sort of gc issue.
I add the "time.sleep(1)", (commented in the code) and the tests pass.
'y' is found in test_2.
Replacing the sleep with a gc.collect() makes the test fail again, so
garbage collection doesn't seem to help.

I've tried it on python 2.6.1 on windows, 2.5.2 in cygwin and 2.6.1 on
solaris with the same results.
Could anyone explain what I am missing?

Thanks
/Mattias

Here's the code:

import unittest
import tempfile, os, imp, time, gc

module_file_name=os.path.join(tempfile.gettempdir(), 'my_module.py')

def write_module(data):
f = open(module_file_name, 'w')
f.write(data)
f.close()

def import_from_file(path):
imported_module = imp.load_source(module_file_name, path)
return imported_module

class Test(unittest.TestCase):
def tearDown(self):
os.unlink(module_file_name)

def test_1(self):
module_data='''x=1'''
write_module(module_data)
imported=import_from_file(module_file_name)
getattr(imported, 'x')

def test_2(self):
# time.sleep(1)
module_data='''y=2'''
write_module(module_data)
imported=import_from_file(module_file_name)
getattr(imported, 'y')

if __name__ == "__main__":
unittest.main()
--
http://mail.python.org/mailman/listinfo/python-list


Re: JOB: Statistical Programmer | LOCATION: London, England, UK

2009-04-23 Thread Aahz
In article ,
Scott David Daniels   wrote:
>jt wrote:
>>
>> JOB: Statistical Programmer  ...
>
>Job postings are not in order here, they are off-topic.
>If you go to
> http://www.python.org/community/jobs/
>You will see a jobs posting board that will happily post your job.

Wrong, there's no Python mentioned in the job ad, therefore the job board
won't accept it.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

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


Re: Cython + tuple unpacking

2009-04-23 Thread Aahz
In article ,
Hugues Salamin   wrote:
>
>The following code will crash with a segfault when compiled using
>cython (v0.11)
>
>def func():
>for (a, b) ,c ,d in zip(zip(range(3), range(3)), range(3), range(3)):
>print a, b
>print c
>print d # This line segfault

Does this crash if you unpack the a,b tuple inside the loop?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

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


Re: Cython + tuple unpacking

2009-04-23 Thread Terry Reedy

Hugues Salamin wrote:

Hello,

The following code will crash with a segfault when compiled using cython (v0.11)

def func():
for (a, b) ,c ,d in zip(zip(range(3), range(3)), range(3), range(3)):
print a, b
print c
print d # This line segfault

Compilation is done using distutils.

If the module is imported in python and func is called, I got a segmentation
fault at the line "print d".

I investigated the error with valgrind and gdb but I still have no clue what is
going on.

I'm on Ubuntu 8.04, Kernel 2.6.24-22-generic


Since this is a Cython, not a Python, problem, report/ask this on the 
Cython list or bug tracker.



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


Re: Using optparse

2009-04-23 Thread Aahz
In article ,
loial   wrote:
>
>A shell script is passing parameters to my python script in the
>following format
>
>-PARAM1 12345 -PARAM2 67890
>
>Can I parse these with optparse  ? If so how?

You might try using shlex instead.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

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


Re: Large data arrays?

2009-04-23 Thread Aahz
In article ,
Ole Streicher   wrote:
>
>for my application, I need to use quite large data arrays 
>(100.000 x 4000 values) with floating point numbers where I need a fast
>row-wise and column-wise access (main case: return a column with the sum 
>over a number of selected rows, and vice versa).
>
>I would use the numpy array for that, but they seem to be
>memory-resistent. So, one of these arrays would use about 1.6 GB
>memory which far too much. So I was thinking about a memory mapped
>file for that. As far as I understand, there is one in numpy.

You probably want to ask on a NumPy or SciPy list:
http://scipy.org/Mailing_Lists
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

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


Re: Windows Shell Extensions - Out of Proc

2009-04-23 Thread Thomas Heller
Ralf schrieb:
>> I think that for whatever reasons, explorer always tries to create
>> shell extensions as InProc.  CoCreateInstance, which is the usual
>> API to create COM instances, allows to specify which one you want.
>>
>> Thomas
> 
> So there is no way to do this, other than to create a "proxy" COM
> object as InProc, which then forwards the requests to my COM object in
> the separate process?

Not that I know of - anyone else?
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: a metacomment on feedback comments

2009-04-23 Thread Aaron Watters
On Apr 23, 11:54 am, Johannes Bauer  wrote:
> To sum it up, I think it's a neat idea, but it's not really intuitive.
> After being quite startled at first it got better after I read the "why
> it's cool" page.

Thanks for taking the time to check it out and comment, Johannes.
I think you bring up a very good point --
some of directive names are confusing.  I will think on renaming
them and I'd love suggestions.  For those who may be interested
please see the comments at the bottom of

http://aaron.oirt.rutgers.edu/myapp/docs/W1200_1200.config_template

for my initial thoughts inspired by J.B's comments.

[BTW: I had to back out a handful of mootools coolnesses
because they broke in horrible ways under IE8 -- I
apologize if you saw a blank page or any other weirdness.]

Thanks again!  -- Aaron Watters
  http://aaron.oirt.rutgers.edu/myapp/docs/W1500.whyIsWhiffCool

===
How do you get to Carnegie Hall?
Practice! Practice!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows Shell Extensions - Out of Proc

2009-04-23 Thread Ralf

> I think that for whatever reasons, explorer always tries to create
> shell extensions as InProc.  CoCreateInstance, which is the usual
> API to create COM instances, allows to specify which one you want.
>
> Thomas

So there is no way to do this, other than to create a "proxy" COM
object as InProc, which then forwards the requests to my COM object in
the separate process?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cleaning out the cobwebs in the PEP cupboard

2009-04-23 Thread Terry Reedy

Larry Hastings wrote:



There are some PEPs that seem to be stuck in a perpetual limbo, never to 
be decided upon.  Some of them seem hopelessly antiquated now--they were 
proposed long ago and the language has moved on.  With every passing day 
it becomes less likely they will ever be Accepted.


Except that two of them, as you note, are de facto accepted.

The only thing I have to added is that after possibly more discussion, 
you send a summary to the PEP editors if they do not see this here.


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


Re: Large data arrays?

2009-04-23 Thread Nick Craig-Wood
Ole Streicher  wrote:
>  Hi Nick,
> 
>  Nick Craig-Wood  writes:
> > mmaps come out of your applications memory space, so out of that 3 GB
> > limit.  You don't need that much RAM of course but it does use up
> > address space.
> 
>  Hmm. So I have no chance to use >= 2 of these arrays simultaniously?
> 
> > Sorry don't know very much about numpy, but it occurs to me that you
> > could have two copies of your mmapped array, one the transpose of the
> > other which would then speed up the two access patterns enormously.
> 
>  That would be a solution, but it takes twice the amount of address
>  space (which seems already to be the limiting factor). In my case (1.6
>  GB per array), I could even not use one array. 

You don't need them mapped at the same time so you could get away with
just one copy mapped.

Also you can map the array in parts and use dramatically less address
space.

>  Also, I would need to fill two large files at program start: one for
>  each orientation (row-wise or column-wise). Depending on the input
>  data (which are also either row-wise or column-wise), the filling of
>  the array with opposite direction would take a lot of time because of
>  the inefficiencies.
> 
>  For that, using both directions probably would be not a good
>  solution. What I found is the "Morton layout" which uses a kind of
>  fractal interleaving and sound not that complicated.

It sounds cool!

>  But I have no idea on how to turn it into a "numpy" style: can I
>  just extend from numpy.ndarray (or numpy.memmap), and which
>  functions/methods then need to be overwritten? The best would be
>  ofcourse that someone already did this before that I could use
>  without trapping in all these pitfalls which occur when one
>  implements a very generic algorithm.

I'd start by writing a function which took (x, y) in array
co-ordinates and transformed that into (z) remapped in the Morton
layout.

Then instead of accessing array[x][y] you access
morton_array[f(x,y)].  That doesn't require any subclassing and is
relatively easy to implement. I'd try that and see if it works first!

Alternatively you could install a 64bit OS on your machine and use my
scheme!

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


Re: Presentation software for Python code

2009-04-23 Thread Scott David Daniels

Michael Hoffman wrote:
... Does anyone here have software they would suggest for making a 
presentation that includes Python code? Other than that it would 
probably be mainly bullet points. I'm willing to consider TeX- and 
HTML-based approaches.


You might take a look at Crunchy, and just do up your talk there.
Crunchy is a Python program that combines an otherwise static html
document with an interactive Python session within a browser
http://code.google.com/p/crunchy/

A demo from an earlier version of Crunchy  (when thedemo was made,
Firfox only). The basic features of that early version of Crunchy
are demonstrated in this screencast.

http://showmedo.com/videos/video?name=143&fromSeriesID=143

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Presentation software for Python code

2009-04-23 Thread John Reid

Michael Hoffman wrote:
Does anyone here have software they would suggest for making a 
presentation that includes Python code? Other than that it would 
probably be mainly bullet points. I'm willing to consider TeX- and 
HTML-based approaches.


I like pygments for formatting python code. It can generate TeX and you 
can use it inline it in your TeX source if you like.


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


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread David Stanek
On Thu, Apr 23, 2009 at 1:12 PM, norseman  wrote:
>
> BB's, User Lists, all repositories can make these required before
> acceptance.
>
>

This is open source. I volunteer my time on the projects that I
maintain. If you don't like the quality or lack of documentations,
tests, etc. Contribute. Or just don't use the software.

What maybe another option is to have a karma rating on PYPI. Maybe
based off of home much you are included in other packages or some
other factors.

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows Shell Extensions - Out of Proc

2009-04-23 Thread Thomas Heller
Ralf schrieb:
> I'm trying to develop Windows Shell Extensions with the Python Win32
> Extensions. Most of the samples are working. However, I have a
> slightly different need: I want the Python COM server to run as a
> separate process ("LocalServer" or "OutOfProc").
> 
> As I understand, both the InProc and LocalServer versions are created
> automatically. So to disable the InProc version, I removed the
> InProc32 key from the registry, for the context menu example
> distributed with the Python Win32 Extensions. However, this removes
> the context menu from Explorer, even though the LocalServer32 key
> remains. I could access the COM objects in the example with a Python
> client, so I have no idea why Explorer can't use the LocalServer
> version.
> 
> Can anyone help with this? I've Google'd for hours, without much
> success. I couldn't even find a good example for any other language,
> only references saying it's possible for C#.

I think that for whatever reasons, explorer always tries to create
shell extensions as InProc.  CoCreateInstance, which is the usual
API to create COM instances, allows to specify which one you want.

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


Presentation software for Python code

2009-04-23 Thread Michael Hoffman
I mean to give a presentation next week to my workgroup on good Python 
programming practice. Last time I did a Python presentation I used 
PowerPoint which was not totally well-suited for the task. In 
particular, formatting code snippets was a pain, and they weren't even 
prettyprinted.


Does anyone here have software they would suggest for making a 
presentation that includes Python code? Other than that it would 
probably be mainly bullet points. I'm willing to consider TeX- and 
HTML-based approaches.

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


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Scott David Daniels

Jeremy Banks wrote: (proposing def (): ...

On Thu, Apr 23, 2009 at 11:52, Gary Herron  wrote:

Try this:
  def foo_bar():
  return(...)
  foo.bar = foo_bar
and this:
  def foo_bar():
  return(...)
  foo["bar"] = foo_bar

I understand that this is possible now, but I just don't see why it's
necessary to do it at all.


I am afraid it will make it too easy to define functions in other
modules remotely, a tempting sharp stick to poke your eye out with.
Note also, that it will not be so easy to find the definition of a
function provided as a argument to a failing function.  Right now
you can get the function name and (with a bit more effort) its module.
Imagine debugging a pile of code that includes a module with:
import random
def random.random():
return .42

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: JOB: Statistical Programmer | LOCATION: London, England, UK

2009-04-23 Thread Scott David Daniels

jt wrote:

JOB: Statistical Programmer  ...

Job postings are not in order here, they are off-topic.
If you go to
http://www.python.org/community/jobs/
You will see a jobs posting board that will happily post your job.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Windows Shell Extensions - Out of Proc

2009-04-23 Thread Ralf
I'm trying to develop Windows Shell Extensions with the Python Win32
Extensions. Most of the samples are working. However, I have a
slightly different need: I want the Python COM server to run as a
separate process ("LocalServer" or "OutOfProc").

As I understand, both the InProc and LocalServer versions are created
automatically. So to disable the InProc version, I removed the
InProc32 key from the registry, for the context menu example
distributed with the Python Win32 Extensions. However, this removes
the context menu from Explorer, even though the LocalServer32 key
remains. I could access the COM objects in the example with a Python
client, so I have no idea why Explorer can't use the LocalServer
version.

Can anyone help with this? I've Google'd for hours, without much
success. I couldn't even find a good example for any other language,
only references saying it's possible for C#.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Large data arrays?

2009-04-23 Thread Scott David Daniels

Ole Streicher wrote:

Nick Craig-Wood  writes:

mmaps come out of your applications memory space, so out of that 3 GB
limit.  You don't need that much RAM of course but it does use up
address space.


Hmm. So I have no chance to use >= 2 of these arrays simultaniously?
... That would be a solution, but it takes twice the amount of address
space (which seems already to be the limiting factor). In my case (1.6
GB per array), I could even not use one array. 


Looks like you are out of luck here.  I believe looking to do this
without managing the I/O yourself is likely to involve someone else's
trade-offs, which likely fail to match your use case.  You might check
gmane.comp.python.scientific.user
which I think is gmane's  mirror of comp.python.scipy.user, but I'm
not certain of the mailing list name.  Certainly the people over there
regularly deal with accessing large data.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread norseman

David Lyon wrote:


On Thu, 23 Apr 2009 07:04:35 -0400, David Stanek 
wrote:

If I use win32com how do you expect me to support Linux? 


Of course not...

What about the many packages on PYPI containing C? 


Exactly. 


What if I decide to write only to Python 3?


Fair enough. But don't forget it is open source.

Let me ask these two questions...

 - What about the use case where somebody likes the code and wants 
   to use it on Python 2.5?


 - Should not that user be able to share back with other 
   Python 2.5 users?



Who will support the other platforms if not the developer?


It's Open Source don't forget

Fact is these days.. developers come and go

If anything my suggestion promotes preserving the resources
of the original developer rather than letting them expire just
because their operating system does

(I'm talking windows here)


Go David!  I like your attitude!!



David


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


==

This topic has been going round and round and yet nobody has actually 
touched the "magic button".


Like whoever started this topic (and the rest of you) I have logged in 
somewhere and looked for Help, Snippets and more.  I find something I 
like and download and it fails miserably.  Thus the perceived "need" for 
some big brother certification thing.


It is far more simple to police ourselves.
The posting needs a DATE. The Help or Comment needs to explicitly 
specify the VERSION(s) it addresses.  The code needs to state OS and 
program and version used to write it.  And from there - user beware.


DATE is supplied for date of posting, but who says that was when the 
contents were created?  The content needs to specify its creation DATE.


VERSION(s) which HELP and COMMENTS were created under/towards/"at time 
of" need explicit noting. Even one liners in postings.


The author of the code needs to state OS (and version of) and the 
compiler/interpreter (and version of) and version the code was written 
to. (was it for a specific only or was the effort to be more general or 
was backward compatibility attempted, is the snippet even supposed to 
run?) As for programming language version compatibility - you the author 
need to download them and do that yourself if you need to know.


There is one other thing that really pisses me off when it's missing.
The idiot puts in the disclaimer but never tells anyone what the hell 
that damn thing is supposed to do.  AAARGGGghhh !!!


BB's, User Lists, all repositories can make these required before 
acceptance.



On the dream list:  It would be nice to have access to an OS (and or 
machine architecture) not in possession for testing compatibility in 
cases where it's an issue.

But then just asking usually gets it done. :)

Today is: 20090423
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread Scott David Daniels

Daniel Fetchinson wrote:

I don't think every package should work on every platform and with
every version of python. But I do think that many developers want to
support more platforms and versions than what they have access to.
Having a test farm would be beneficial to these developers and their
users.


This testing infrastructure should be available to developers who choose
to opt in. Once they run their code and notice that there are errors,
they will go back and fix these errors that otherwise would be
undetected until a real person runs into them. Or they could clearly
state what platform and python versions the code runs on for sure and on
what platforms and python versions the code fails. This would be a great
advantage to developers.

There is a cost here, however.  Core developers and large-userbase packages
like scipy or numpy are self-policing.  However, if you open machine
resources to every Python Package, you will have to police the resource
to make sure that you have provided a platform for malware distributors.
Now few of us think we want to provide that, but very few of us want to
spend the hours reading logs and ... to make sure that is not happening.


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorting two corresponding lists?

2009-04-23 Thread Esmail


My solution, I know the 'zip' version is more elegant, this is just for 
fun:)
 
 >>> items = ['apple', 'car', 'town', 'phone']

 >>> values = [5, 2, 7, 1]
 >>> new_values = sorted(values, reverse = True)
 >>> new_items = [items[x] for x in [i for i in map(values.index, 
new_values)]]

 >>> print(new_values)
[7, 5, 2, 1]
 >>> print(new_items)
['town', 'apple', 'car', 'phone']
 >>>
 


Cool .. always good to know alternative ways of accomplishing
a task.

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


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread Paul Boddie
On 23 Apr, 17:46, Daniel Fetchinson  wrote:
>
> You and I probably have a different approach to posts to c.l.p. I try
> to interpret things in the best possible light and get the most out of
> a suggestion.

There may be merit in the suggestion, but there also has to be
skepticism, even if it is regarded as "stop energy" in certain
circles.

[...]

> That is why the proposal is an important one. Let's say snakebite is
> not suitable for PyPI. What can be done on PyPI that helps developers
> with multiplatform/multiversion testing?

I think that PyPI plays an important role in publicising packages and
getting them out there in their "raw" form, but it's not the centre of
the universe. Maybe the answer doesn't involve PyPI at all or, more
likely, involves PyPI as a peripheral thing from which people acquire
those packages that have to work together on a specific platform. Such
a solution wouldn't have that much to do with PyPI, other than letting
people download large collections of packages very quickly,
potentially from mirror sites, which is something that various GNU/
Linux distribution services permit (and something which seems to have
been a struggle with PyPI).

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


Re: Essential tools for Python development

2009-04-23 Thread Esmail

Alex VanderWoude wrote:


I really like using Winpdb (http://winpdb.org/) which provides a GUI for 
pdb.  It allows you to single-step your code and inspect objects in 
memory.  What exactly is in that silly nextOne variable?  Hey, it's a 
list rather but it's supposed to be a number!  You get the picture.


thanks for the suggestion.

The name made me think that this would be only for the Windows
platform, but it turns out it's multi-platform.

I downloaded the Linux version, but haven't had time to explore it
yet, but plan to.

Esmail

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


Re: Essential tools for Python development

2009-04-23 Thread Esmail

Jeremiah Dodds wrote:


pdb is good if you need to do step-through debugging.

What I normally do in emacs is the following (while working on python 
script, and with the python-mode that comes with emacs22):


C-x 3  #splits the screen into two vertical columns
C-c C-c   #fires up python and sends the current buffer to it
C-x o  #switches to the other column
C-x b Py #switches to the python interactive buffer

This is, I do believe, equivalent to running a script with python -i 
script.py . Drops you into an interactive session where you can interact 
with what you just wrote. Another very handy tool is etags, see the help 
in emacs (You can get to it through C-h i m emacs)


Thanks for the suggestions, I really like using emacs, so I am going to
see how I can integrate it with Python development.
(Unfortunately my Windows version of emacs dosen't seem to be able to
pop into python mode, and I haven't had time to find out why). At this
point I do most of my development under Linux/emacs anyway.

Best,
Esmail
--
http://mail.python.org/mailman/listinfo/python-list


Re: pylab quick reference? (matplotlib)

2009-04-23 Thread Esmail

Arnaud Delobelle wrote:




 python -c 'import pylab;  help(pylab)' > pylab.txt


Do you know pydoc?


From the (shell) command line, try:


$ pydoc pylab # piped through less
$ pydoc pylab > pylab.txt # stored in a file
$ pydoc -w pylab  # Creates a 'pylab.html' file
wrote pylab.html


Ah .. and there I thought I'd impress everyone with my python
command line :-)

I had heard of pydoc before, but am not familiar with (it's on
my list of Python tools to explore), so many thanks for showing
me how to get a nice html formatted page.

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


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Marco Mariani

Jeremy Banks wrote:


I've read those discussion before, but somehow never made the
connection between those and this. I'll give that article a read, it
probably details exactly the perspective I'm looking for. Thank you!


You could also read this:

http://unlimitednovelty.com/2009/03/indentation-sensitivity-post-mortem.html

The author is writing a language for the Erlang VM inspired by Python 
and Ruby. He had some trouble (at the grammar level) in keeping both 
"indentation working like in python" (dear to Guido and many of us) and 
"anonymous blocks" (dear to functional languages).

So he got braces and was happy :-)

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


Re: Supply a plugin interface

2009-04-23 Thread Aahz
In article <75akp8f17g29...@mid.dfncis.de>,
Johannes Bauer   wrote:
>
>the GUI application should now browse the plugin directory and read
>those plugin python files and somehow incorporate (i.e. discover what
>modules are there, instanciate, etc.)
>
>How do I do that at runtime with Python?

You might consider using execfile() but probably __import__ works better
for your purposes.  There's also importlib on PyPI, which is the backport
from 2.7.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

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


Re: Numpy Performance

2009-04-23 Thread Peter Otten
timlash wrote:

> Still fairly new to Python.  I wrote a program that used a class
> called RectangularArray as described here:
> 
> class RectangularArray:
>def __init__(self, rows, cols, value=0):
>   self.arr = [None]*rows
>   self.row = [value]*cols
>def __getitem__(self, (i, j)):
>   return (self.arr[i] or self.row)[j]
>def __setitem__(self, (i, j), value):
>   if self.arr[i]==None: self.arr[i] = self.row[:]
>   self.arr[i][j] = value
> 
> This class was found in a 14 year old post:
> http://www.python.org/search/hypermail/python-recent/0106.html
> 
> This worked great and let me process a few hundred thousand data
> points with relative ease.  However, I soon wanted to start sorting
> arbitrary portions of my arrays and to transpose others.  I turned to
> Numpy rather than reinventing the wheel with custom methods within the
> serviceable RectangularArray class.  However, once I refactored with
> Numpy I was surprised to find that the execution time for my program
> doubled!  I expected a purpose built array module to be more efficient
> rather than less.
> 
> I'm not doing any linear algebra with my data.  I'm working with
> rectangular datasets, evaluating individual rows, grouping, sorting
> and summarizing various subsets of rows.
> 
> Is a Numpy implementation overkill for my data handling uses?  Should
> I evaluate prior array modules such as Numeric or Numarray?  Are there
> any other modules suited to handling tabular data?  Would I be best
> off expanding the RectangularArray class for the few data
> transformation methods I need?
> 
> Any guidance or suggestions would be greatly appreciated!

Do you have many rows with zeros? That might be the reason why your
self-made approach shows better performance.

Googling for "numpy sparse" finds:

http://www.scipy.org/SciPy_Tutorial

Maybe one of the sparse matrix implementations in scipy works for you.

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


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread John Krukoff
On Thu, 2009-04-23 at 12:26 -0300, Jeremy Banks wrote:
> > Things like your suggestion are called "syntactic-sugar"  -- syntax that
> > adds a convenience, but *no* new functionality.  Python has plenty of
> > "syntactic-sugar"s, and more will be added in the future.  To make an
> > argument for such an addition, one would have to describe some compelling
> > (and general) use cases in a well-argued PEP.  You're welcome to try, but be
> > forewarned, most PEP's (especially syntax changing PEPs) don't fly far.
> 
> Thank you very much for the feedback. I might throw something at
> Python-Ideas if I think I can come up with an adequate justification
> and don't come accross a previous similar propsition (though if I do
> miss it I'm sure it will be pointed out to me fairly quickly). I fully
> appreciate the small chance of success, but it certainly couldn't hurt
> to give it a try.
> --
> http://mail.python.org/mailman/listinfo/python-list

You probably want to be searching for multi-line lambda to find the past
decade or so of this argument, as that's where most people who argued
for this came from. But, if you'd just like a bit of discouragement,
here's GvR arguing that there's just no good way to mix statements and
expressions in python:
http://www.artima.com/weblogs/viewpost.jsp?thread=147358

-- 
John Krukoff 
Land Title Guarantee Company

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


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Jeremy Banks
On Thu, Apr 23, 2009 at 13:03, John Krukoff  wrote:
> You probably want to be searching for multi-line lambda to find the past
> decade or so of this argument, as that's where most people who argued
> for this came from. But, if you'd just like a bit of discouragement,
> here's GvR arguing that there's just no good way to mix statements and
> expressions in python:
> http://www.artima.com/weblogs/viewpost.jsp?thread=147358

I've read those discussion before, but somehow never made the
connection between those and this. I'll give that article a read, it
probably details exactly the perspective I'm looking for. Thank you!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Configuring pylint for local conventions (was: pyflakes, pylint, pychecker - and other tools)

2009-04-23 Thread Aahz
In article <874owf4gky.fsf...@benfinney.id.au>,
Ben Finney   wrote:
>a...@pythoncraft.com (Aahz) writes:
>>
>> Second, you can configure pylint to respect your personal style
>
>How? I haven't seen any decent documentation on doing so.

Actually, I don't know how, I'm just repeating what was claimed at a
presentation on pylint.  ;-)  I've traditionally used pychecker myself
and haven't seen any reason to switch.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

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


Re: OT: a metacomment on feedback comments

2009-04-23 Thread Johannes Bauer
Aaron Watters schrieb:

> This was posted just after someone on the same
> computer (somewhere in Texas)
> tried and failed to inject some javascript
> into the page using a comment.

Script-kid moron. Delete and enjoy your life.

> I don't see how this comment is helpful to
> me or anyone reading the page.  How the
> framework confusing?  Why should other readers dismiss
> the project?  Can the documentation
> or implementation be
> improved, or is the whole thing beyond repair
> and if so how or why?  Why do people bother
> to write comments like this one?

Humm... I just checked your framework out and must say that I, too,
found it a little confusing. Especially the meaning of "use-url" seems
awkward since obviously this means more like "use-middleware or
"use-plugin" or "use-module" or even just plain "use" (which would be
IMHO clearer).

When you say "use-url" I first though "Ok, this part of the document
will be shown when the user surfs at the supplied URL". Which is not
what it does.

I also do not understand what the difference between a section and a
use-url ist. It seems "section" just creates a new paragraph and
"use-url" invokes some plugin behaviour - but I'm not sure.

I'm not sure why you chose to use the {{ }} syntax, but I'm guessing
that when you'd have used XML it would be a pain to include manual HTML
formatting - again I am unsure.

To sum it up, I think it's a neat idea, but it's not really intuitive.
After being quite startled at first it got better after I read the "why
it's cool" page.

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <48d8bf1d$0$7510$54022...@news.sunrise.ch>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread Daniel Fetchinson
>> The OP is just thinking out loud that it would be great if developers
>> could count on some help for testing various platforms and versions.
>> And I agree, it would indeed be great.
>>
>
> I think you interpreted the OP differently. As I said before the idea
> is not a bad one, but as a package developer I get to decide which
> platforms and versions my code supports.

Yes, I also think the original idea of the OP is a good one. And I
agree with you that the developers need to be in charge what
platform/version their code supports. Trouble is that currently if
they decide to support multiple versions and platform they don't have
any help from python.org or PyPI. It would be great if after a
developer decided to support some platforms and some versions there
was some infrastructural help in place.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)

2009-04-23 Thread Daniel Fetchinson
> Why? Why should every package on PyPI need to support all those
> Python versions? That should be the decision of the package
> maintainer. If they want to support every version of Python back to
> 1.0, they can, and if they want to only support version 2.5 that's
> fine too.

 Why shouldn't packages support more than one python version?
>>>
>>> They can. That depends on the developer of the package.
>>
>> And if the developer decides to support multiple versions currently
>> there is no infrastructural help that would be available to him. On the
>> other hand, there is infrastructural help available to every developer
>> for distributing their apps: it's PyPI itself. You could ask, why do we
>> need PyPI? Let the developers distribute their code in any way they
>> like, python.org doesn't need to support this.
>
> They don't *need* to support distribution. That they do is a nice-to-
> have, not a must-have -- there are other solutions, like SourceForge. We
> can be grateful for PyPI without believing that it's a must-have.

Nobody believes PyPI is a must-have and for sure I didn't say it is a
must-have. PyPI is nice to have not only for developers but also for
users. A multiplatform/multiversion test farm would also be nice for
developers and users alike.

>> The OP is just thinking out loud that it would be great if developers
>> could count on some help for testing various platforms and versions. And
>> I agree, it would indeed be great.
>
> To me, the OP doesn't seem to be asking "Wouldn't it be good if
> developers could get access to whatever systems they wanted?" and more
> like "Somebody needs to develop this amazing technology that will just
> magically make every package on PyPI work on all these different
> platforms, otherwise the Sky Will Fall". Just look at the subject line:
> the issue is described as "a looming problem", it's suggested that
> packages "might no longer work".

You and I probably have a different approach to posts to c.l.p. I try
to interpret things in the best possible light and get the most out of
a suggestion. You are right, the OP was not formulating his proposal
clearly and didn't use a sophisticated enough language but what is
clear is that at the core of the proposal there is something valuable.
Having a test farm would be very useful and would benefit the python
community.

> He's also worried about the combinational explosion of packages,
> platforms and versions, which to my mind is only a problem if you think
> that every package must work on every platform with every version of
> Python.

I don't think every package should work on every platform and with
every version of python. But I do think that many developers want to
support more platforms and versions than what they have access to.
Having a test farm would be beneficial to these developers and their
users.

> I suspect you're primed to read the OP's suggestion in the most positive
> light, because you're already aware of snakebite, and so you're seeing
> his posts in terms of what snakebite is offering. I had never even heard
> of snakebite before now, so I was seeing it in a very different light.

I swear I didn't read this paragraph when I wrote above that I usually
try to interpret posts in the best possible light! This is actually
very funny, you used the exact same phrase :) But even if you have
never heard of snakebite it is simply beyond my understanding how a
developer can argue against a testing farm like this. You seriously
think it would not be a good idea?


> What's the dire problem you are trying to solve?

 Backward and forward compatability of python package resources.
>>>
>>> That's not a problem, that's a feature.
>>>
>>> What's the *problem* that you are trying to solve? What bad thing will
>>> happen if we don't build your proposed system?
>>
>> I fail to understand what is so mysterious about this. The problem is
>> the following: developer X wants to support python versions a, b, c, d
>> on platforms U, V, W. Developer X has no access to platforms V and W and
>> also has no access to python versions b, c and d. Developer X can not
>> run tests on these platforms and python versions although he really
>> wants to. This situation is what is commonly referred to as a problem.
>
> That's *a* problem.

Yes, a problem, that is why I wrote, a problem.

> It has many solutions, snakebite being just one.

Yes, something integrated into PyPI would be another one.

> Is  it the "looming" problem the OP is concerned about?

What are we worried about, the use of the English language or the
technical merit of a proposal?

>> This testing infrastructure should be available to developers who choose
>> to opt in. Once they run their code and notice that there are errors,
>> they will go back and fix these errors that otherwise would be
>> undetected until a real person runs into them. Or they could clearly
>> state what platform and python versions the code runs

Re: Using optparse

2009-04-23 Thread Piet van Oostrum
> loial  (L) wrote:

>L> A shell script is passing parameters to my python script in the
>L> following format

>L> -PARAM1 12345 -PARAM2 67890

>L> Can I parse these with optparse  ? If so how?

>L> I can't seem to get it to work. It seems to expect --PARAM1 and --
>L> PARAM2

See the doc:

Some other option syntaxes that the world has seen include:
[...]
* a hyphen followed by a whole word, e.g. "-file" [...]

These option syntaxes are not supported by optparse, and they never will be.

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Numpy Performance

2009-04-23 Thread timlash
Still fairly new to Python.  I wrote a program that used a class
called RectangularArray as described here:

class RectangularArray:
   def __init__(self, rows, cols, value=0):
  self.arr = [None]*rows
  self.row = [value]*cols
   def __getitem__(self, (i, j)):
  return (self.arr[i] or self.row)[j]
   def __setitem__(self, (i, j), value):
  if self.arr[i]==None: self.arr[i] = self.row[:]
  self.arr[i][j] = value

This class was found in a 14 year old post:
http://www.python.org/search/hypermail/python-recent/0106.html

This worked great and let me process a few hundred thousand data
points with relative ease.  However, I soon wanted to start sorting
arbitrary portions of my arrays and to transpose others.  I turned to
Numpy rather than reinventing the wheel with custom methods within the
serviceable RectangularArray class.  However, once I refactored with
Numpy I was surprised to find that the execution time for my program
doubled!  I expected a purpose built array module to be more efficient
rather than less.

I'm not doing any linear algebra with my data.  I'm working with
rectangular datasets, evaluating individual rows, grouping, sorting
and summarizing various subsets of rows.

Is a Numpy implementation overkill for my data handling uses?  Should
I evaluate prior array modules such as Numeric or Numarray?  Are there
any other modules suited to handling tabular data?  Would I be best
off expanding the RectangularArray class for the few data
transformation methods I need?

Any guidance or suggestions would be greatly appreciated!

Cheers,

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


Re: Regular expression to capture model numbers

2009-04-23 Thread Piet van Oostrum
> John Machin  (JM) wrote:

>JM> On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote:

>>> Requirements:
>>>   The text must contain a combination of numbers, alphabets and hyphen
>>> with at least two of the three elements present.

>JM> Unfortunately(?), regular expressions can't express complicated
>JM> conditions like that.

Yes, they can but it is not pretty.

The pattern must start with a letter, a digit or a hyphen. 

If it starts with a letter, for example, there must be at least a hyphen
or a digit somewhere. So let us concentrate on the first one of these
that occurs in the string. Then the preceding things are only letters
and after it can be any combination of letters, digits and hyphens. So
the pattern for this is (when we write L for letters, and d for digits):

L+[-d][-Ld]*.

Similarly for strings starting with a digit and with a hyphen. Now
replacing L with [A-Za-z] and d with [0-9] or \d and factoring out the
[-Ld]* which is common to all 3 cases you get:

(?:[A-Za-z]+[-0-9]|[0-9]+[-A-Za-z]|-+[0-9A-Za-z])[-0-9A-Za-z]*

>>> obj = 
>>> re.compile(r'(?:[A-Za-z]+[-0-9]|[0-9]+[-A-Za-z]|-+[0-9A-Za-z])[-0-9A-Za-z]*')
>>> re.findall(obj, 'TestThis;1234;Test123AB-x')
['Test123AB-x']

Or you can use re.I and mention only one case of letters:

obj = re.compile(r'(?:[a-z]+[-0-9]|[0-9]+[-a-z]|-+[0-9a-z])[-0-9a-z]*', re.I)
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Jeremy Banks
> Things like your suggestion are called "syntactic-sugar"  -- syntax that
> adds a convenience, but *no* new functionality.  Python has plenty of
> "syntactic-sugar"s, and more will be added in the future.  To make an
> argument for such an addition, one would have to describe some compelling
> (and general) use cases in a well-argued PEP.  You're welcome to try, but be
> forewarned, most PEP's (especially syntax changing PEPs) don't fly far.

Thank you very much for the feedback. I might throw something at
Python-Ideas if I think I can come up with an adequate justification
and don't come accross a previous similar propsition (though if I do
miss it I'm sure it will be pointed out to me fairly quickly). I fully
appreciate the small chance of success, but it certainly couldn't hurt
to give it a try.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why can function definitions only use identifiers, and not attribute references or any other primaries?

2009-04-23 Thread Gary Herron

Jeremy Banks wrote:

Thanks for your comments.

On Thu, Apr 23, 2009 at 11:52, Gary Herron  wrote:
  

[...]
  

There's no need for a specific addition to the syntax to do this.

Try this:

  def foo_bar():
  return(...)
  foo.bar = foo_bar



[...]
  

and this:

  def foo_bar():
  return(...)
  foo["bar"] = foo_bar




I understand that this is possible now, but I just don't see why it's
necessary to do it at all.

  

In this case I could see there being a problem in that there's nothing
to get the function's __name__ from, but that doesn't apply for the
first example.

  

Not sure what you mean here.



>>> def foo(): pass
...
>>> bar = foo
>>> bar.__name__
'foo'
>>>

If I defined foo.bar it would know that the method name was "bar", but
if I defined foo["bar"] there's be no clear identifier to use for the
function's name. I don't see this as a great problem, since anonymous
functions already exist, but I thought it was worth acknowledging.

To be clear, I don't see this as a serious fault in the language, but
as an unnecessary restriction that makes code a little less direct
than it could be.
  



Things like your suggestion are called "syntactic-sugar"  -- syntax that 
adds a convenience, but *no* new functionality.  Python has plenty of 
"syntactic-sugar"s, and more will be added in the future.  To make an 
argument for such an addition, one would have to describe some 
compelling (and general) use cases in a well-argued PEP.  You're welcome 
to try, but be forewarned, most PEP's (especially syntax changing PEPs) 
don't fly far.




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


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


  1   2   >