Remove root handler from logger

2012-05-14 Thread Florian Lindner
Hello,

I configure my logging on application startup like that:

logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile)
ch  = logging.StreamHandler()
ch.setFormatter(logging.Formatter(FORMAT))
logging.getLogger().addHandler(ch)

In one module of my application I want a logger that does not log to logfile 
but to another file. How can I get a logger that is either plain (no handlers 
attached) or remove a handler?

The handlers that are derived from the root logger are not shown in handlers:

(Pdb) logger1.handlers
[]
(Pdb) logging.getLogger().handlers
[, ]

How can I remove the FileHandler and StreamHandler from logger1 without 
affecting the root logger?

logger1.removeHandler() does not work since there are no handlers on logger1.

Thanks,

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


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-14 Thread Andreas Tawn
> p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal 
> interest (or
> perhaps both)?

We do use Python a fair bit, mostly for build systems and data mining, but also 
because it's the built-in script language for Motionbuilder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remove root handler from logger

2012-05-14 Thread Jean-Michel Pichavant

Florian Lindner wrote:

Hello,

I configure my logging on application startup like that:

logging.basicConfig(level = logging.DEBUG, format=FORMAT, filename = logfile)
ch  = logging.StreamHandler()
ch.setFormatter(logging.Formatter(FORMAT))
logging.getLogger().addHandler(ch)

In one module of my application I want a logger that does not log to logfile 
but to another file. How can I get a logger that is either plain (no handlers 
attached) or remove a handler?


The handlers that are derived from the root logger are not shown in handlers:

(Pdb) logger1.handlers
[]
(Pdb) logging.getLogger().handlers
[, at 0x7f3e8f731450>]


How can I remove the FileHandler and StreamHandler from logger1 without 
affecting the root logger?


logger1.removeHandler() does not work since there are no handlers on logger1.

Thanks,

Florian
  
The usual pattern is that the root logger is handling all the events. 
Sub loggers are only raising log events.

Try to stick with this most of the time.

However in your case you need a sub logger to handle its logs in a 
different way. For that you have to add a handler to your sub logger and 
tells it to not sent log event to its parent.
If I remeber correctly, this is done by setting the 'propagate' 
attribute of you logger to 0.


That could look like (not tested):

import logging

root = logging.getLogger()
foo = logging.getLogger('foo')

root.addHandler(logging.StreamHandler())
foo.addHandler(logging.FileHandler('foo.log'))
foo.propagate = 0

Cheers,

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


Re: How to call and execute C code in Python?

2012-05-14 Thread Michael Torrie
On 05/13/2012 11:27 AM, Mark Lawrence wrote:
> Stefan, you appear to have a lot to do with Cython. It would be polite 
> to mention this when replying.
> 

Why?  Do you think this is some sort of weird conflict of interest?  As
anyone who follows this list for several years would know, Cython is a
very tool that more than a few python developers seem to be using to
practically extend python in C.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to call and execute C code in Python?

2012-05-14 Thread Chris Angelico
On Tue, May 15, 2012 at 12:36 AM, Michael Torrie  wrote:
> On 05/13/2012 11:27 AM, Mark Lawrence wrote:
>> Stefan, you appear to have a lot to do with Cython. It would be polite
>> to mention this when replying.
>
> Why?  Do you think this is some sort of weird conflict of interest?  As
> anyone who follows this list for several years would know, Cython is a
> very tool that more than a few python developers seem to be using to
> practically extend python in C.

Or mention it as a mark of authority. If I talk about Cython, it's
with no authority, as I've never used it. When a core Cython developer
mentions it, we can expect the information to be reliable.

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


Extracting DB schema (newbie Q)

2012-05-14 Thread Steve Sawyer
Brand-new to Python (that's a warning, folks)

Trying to write a routine to import a CSV file into a SQL Server
table. To ensure that I convert the data from the CSV appropriately,
I"m executing a query that gives me the schema (data column names,
data types and sizes) from the target table.

What I think I want to do is to construct a dictionary using the
column names as the index value, and a list containing the various
attributes (data type, lenghth, precision).

If this is NOT a good approach (or if there is a better approach),
please issue a dope-slap, ignore the rest of this post and set me
straight.

If this is a good approach, I ran into a problem populating the
dictionary as I couldn't seem to figure out how to make the update()
method work by passing the name property of the row object; I kept
getting a "keyword can't be an expression" error.

What I was able to make work was to construct the command as a string
and run exec(), but seems there shoudl be a more
direct way of updating the dictionary.

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


Re: Extracting DB schema (newbie Q)

2012-05-14 Thread Chris Angelico
On Tue, May 15, 2012 at 2:01 AM, Steve Sawyer  wrote:
> Brand-new to Python (that's a warning, folks)

It's one we're familiar with :) Welcome!

> Trying to write a routine to import a CSV file into a SQL Server
> table. To ensure that I convert the data from the CSV appropriately,
> I"m executing a query that gives me the schema (data column names,
> data types and sizes) from the target table.
>
> What I think I want to do is to construct a dictionary using the
> column names as the index value, and a list containing the various
> attributes (data type, lenghth, precision).

That seems reasonable; I might consider a namedtuple or perhaps
another dictionary, but what you have is usable.

> If this is a good approach, I ran into a problem populating the
> dictionary as I couldn't seem to figure out how to make the update()
> method work by passing the name property of the row object; I kept
> getting a "keyword can't be an expression" error.

Not sure what you're attempting to do; you'd do well to post your code
(preferably a minimal test-case) and the exact traceback. But my guess
is that you're creating a list and then trying to use the update()
method. If that's so, you can simplify it a lot:

columninfo[columnname] = [type, length, precision]

> What I was able to make work was to construct the command as a string
> and run exec(), but seems there shoudl be a more
> direct way of updating the dictionary.

Agreed, you shouldn't normally need to exec to achieve what you want!
But post your failing code and we'll be better able to help.

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


Re: Extracting DB schema (newbie Q)

2012-05-14 Thread Jean-Michel Pichavant

Steve Sawyer wrote:

Brand-new to Python (that's a warning, folks)

Trying to write a routine to import a CSV file into a SQL Server
table. To ensure that I convert the data from the CSV appropriately,
I"m executing a query that gives me the schema (data column names,
data types and sizes) from the target table.

What I think I want to do is to construct a dictionary using the
column names as the index value, and a list containing the various
attributes (data type, lenghth, precision).

If this is NOT a good approach (or if there is a better approach),
please issue a dope-slap, ignore the rest of this post and set me
straight.

If this is a good approach, I ran into a problem populating the
dictionary as I couldn't seem to figure out how to make the update()
method work by passing the name property of the row object; I kept
getting a "keyword can't be an expression" error.

What I was able to make work was to construct the command as a string
and run exec(), but seems there shoudl be a more
direct way of updating the dictionary.

TIA.
  

Please post the exact traceback and the code associated with it.


Using csv.DictReader should allow you to do this in 3 lines, something like:

reader = csv.DictReader('acsvfile.csv')
myDict.update(reader)
uploadDictToDb(myDict)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting DB schema (newbie Q)

2012-05-14 Thread John Gordon
In  Steve Sawyer 
 writes:

> What I think I want to do is to construct a dictionary using the
> column names as the index value, and a list containing the various
> attributes (data type, lenghth, precision).

If you're using just the column name as the dictionary key, make sure
there are no duplicate column names among all your tables.

> If this is a good approach, I ran into a problem populating the
> dictionary as I couldn't seem to figure out how to make the update()
> method work by passing the name property of the row object; I kept
> getting a "keyword can't be an expression" error.

The general syntax for assigning to a dictionary is:

  my_dictionary[key] = value

What are you trying that isn't working?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-14 Thread Karl Knechtel
On Sat, May 12, 2012 at 9:10 AM, Ethan Furman  wrote:
>
> Firstly, __slots__ is a tuple.

I object: conceptually, the "slots" of a class are set in stone, but
the `__slots__` attribute of a class object is just an attribute, and
any iterable (as long as it yields valid identifier names) can be used
when the `__slots__` magic is invoked in the class definition. FWIW,
all the ordinary examples I've seen use a list, although a tuple
arguably makes more sense.

Observe:

>>> class Evil(object):
...   __slots__ = ('a%s' % a for a in range(10))
...
>>> Evil().__slots__
 at 0x01EDFAA8>
>>> list(Evil().__slots__)
[] # the generator was consumed by the metaclass during class creation
>>> dir(Evil())
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__has
h__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__rep
r__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '
a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9'] # yep, the
expected attributes are there, and can be set.
>>> Evil.__slots__ = 42
# no exception

>
> Secondly, this is bad advice.  __slots__ is there as a memory optimization
> for classes that will have thousands of instances and do not need the
> ability to have arbitrary attributes added after creation.

I did explicitly indicate the latter part.

>  __slots__ is an
> advanced feature, and as such is easier to get wrong.  It is *not* there to
> make __str__ nor __repr__ easier to write.

Of course not, but it seems to me that it serves well in this particular case.

 class Test1(object):
> ...     __slots__ = ('item', 'size')
> ...     desc = 'class-only attribute'
> ...
>
 t1 = Test1()
 t1.desc = 'read-only attribute'      # fails because 'desc' is
>                                         # not in __slots__

Well, sure; expecting to modify a class attribute via an instance is a
bit naughty anyway.

 print t1.item                        # fails because 'item' was
>                                         # not set

Well, yes, that's what `__init__` is for; the same line would fail
without `__slots__` and for the same reason. Arguably, this is a
gotcha for people coming from C-like languages who are expecting
`__slots__` to make the class behave as if it had a defined layout,
but there isn't actually any more work involved here.

 class Test2(Test1):
> ...     def __init__(self, price):
> ...         self.price = price
> ...
 t2 = Test2(7.99)          # __slots__ not defined in
>                              # subclass, optimizations lost

Well, yes, but we aren't using it for the optimizations here!

But I see your point; explicit is better than implicit, and our
explicit purpose here is to have an explicit list of the attributes
we're interested in for __str__/__repr__ - which could be any other
named class attribute, without magic associated with it. That said,
`__slots__` is as close to a canonical listing of instance-specific
attributes as we have (`dir()` clearly won't cut it, as we don't want
methods or other class-specific stuff).

--
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-14 Thread Karl Knechtel
On Sat, May 12, 2012 at 10:18 AM, Jean-Daniel
 wrote:
>> Since you say "intervals" in plural here, I assume that they can overlap?
>
> Yes,
>
> For instance, there are the following intervals :
> [[1, 10],
> [4, 7],
> [6, 15],
> [11, 17]]
>
> asking for the intervals including  5, the returned value should be
>
> [[1, 10],
> [4, 7]]
>
> The idea here to make it fast is to have done some preprocessing at
> insertion time, so that not all intervals are processed at query time.
>

How about this:

Set up a list of lists of intervals. Insert the intervals one at a
time thus: for each existing list, check if the new interval overlaps
any existing intervals - you can use the `bisect` module to check for
where the new interval would "fit". If there is no overlap, insert it
into that list at the discovered "insertion point"; otherwise move on
to the next list. If no lists are found that can hold the new
interval, append a new list for it.

Then at query time, you just iterate over the lists, using `bisect`
again to find the unique interval (if any) in each list that spans the
specified point in time.

-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good data structure for finding date intervals including a given date

2012-05-14 Thread Christian Heimes
Am 12.05.2012 14:17, schrieb Jean-Daniel:
> Hello,
> 
> I have a long list of n date intervals that gets added or suppressed
> intervals regularly. I am looking for a fast way to find the intervals
> containing a given date, without having to check all intervals (less
> than O(n)).
> 
> Do you know the best way to do this in Python with the stdlib?
> 
> A variant of the red black trees can do the job quickly [1], is this a
> good enough use case to discuss the inclusion of a red black tree
> implementation in the stdlib?

A more general data structure for spatial search are R-Trees [1]. In few
words R-Tree optimize indexing and containment tests in n dimensions.

Christian

[1] http://en.wikipedia.org/wiki/R-tree

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


Re: dynamically selecting a class to instantiate based on the object attributes.

2012-05-14 Thread Karl Knechtel
On Wed, May 9, 2012 at 7:02 AM, J. Mwebaze  wrote:
>
> During object instantiaton, i would like to use  the specific class, that
> corresponds to the version of the class that was used to create the object.

I don't understand; "the version of the class that was used to create"
**what** object? We're still in the middle of object instantiation!
Where is the version information coming from?

Are you perhaps trying to do something with (un)serialization? Could
you show any relevant code at all?

-- 
~Zahlman {:>
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter: is there a way to switch a widget's master?

2012-05-14 Thread Frederic Rentsch
Hi there,

I would like to prepare a bunch of info text widgets to be displayed in
Toplevel windows at the user's command (when ever he needs directions).
I know how to remove and restore widgets without destroying them in
between. The problem with a Toplevel is that it is a master that comes
and goes, of a Text that is supposed to stay as long as the program
runs. (Building the Text involves reading a file and compiling lots of
edited-in formatting symbols. Repeating this every time the Toplevel is
called seems rather inelegant.) 

toplevel = Toplevel (root, ...)
info_text = MyText (toplevel, ...)
info_text.pack ()
# No problem, except for the inelegant remake of the text on every call.

I tried:

text = MyText (root, ...)
# Later, on user demand
toplevel = Toplevel (root, ...)
info_text.lower (belowThis = toplevel)
info_text.pack ()

This doesn't work! toplevel is empty and text appears in the root
window. Is there a way to switch a widget's master?

Thanks for comments

Frederic




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


Re: dynamically selecting a class to instantiate based on the object attributes.

2012-05-14 Thread Ian Kelly
On Wed, May 9, 2012 at 5:02 AM, J. Mwebaze  wrote:
>
> I have a  bunch of objects of the same type. Each object has a version
> attribute and this refers to source code that was used to make the object.
> SouceCode is maintained in separate files. eg.
> myclass_01.py, myclass_02.py, myclass_03.py, myclass_04.py ..
>
> During object instantiaton, i would like to use  the specific class, that
> corresponds to the version of the class that was used to create the object.
> However i cant know the specific "myclass_??.py" before i read the version
> attribute of the object.
>
> Seems like a situation where i have to partially instantiate the object to
> read the version attribute, and after that continue with instantiaton with
> the specific version of the version..
>
> Is this doeable?

Why can't you read the version before creating the object?

That said, the class's __new__ method can customize what instance is
actually constructed.  Override it to take an optional version
argument (or whatever else you need to pass in to extract the version
from), and use it to select the type that is actually returned.  If
version is omitted, then you would just create the most recent version
as normal.  For example, you might put this in a shared base class:

def __new__(cls, version=None, *args, **kw):
class_dict = {1: myclass_1, 2: myclass_2, 3: myclass_3}
cls = class_dict.get(version, cls)
return object.__new__(cls)

If you're serializing the objects using pickle version 2 or higher,
then you can use a __getnewargs__ method to have it pass the version
argument to __new__ during deserialization:

def __getnewargs__(self):
return (self.version,)

Alternatively, it is possible to change the class of an object after
it has been created:

def __init__(self, version=None):
class_dict = {1: myclass_1, 2: myclass_2, 3: myclass_3}
if version is not None:
self.__class__ = class_dict[version]

You should only do this if you really know what you're doing, as it
can potentially get your objects into weird states that are hard to
debug.

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


Re: Extracting DB schema (newbie Q)

2012-05-14 Thread Steve Sawyer
Thanks, John.

>What are you trying that isn't working?
Typical newbie trick - trying to make things more complicated than
they are. I didn't realize that syntax would establish the key/value
pairs of the dictionary - I thought that would only allow you to
establish the value to correspond to a specified (and pre-exiting)
key, not establish the key as well.

I was establishing the dictionary then trying to use dict.update() to
append key/value pairs.

Thanks - now, given my query that returns the table structure, this
works fine:

table_dict = {}
table_specs = cursor.execute(query_string)
for row in table_specs:
row_dict = {}
row_dict['type'] = row.DataType
row_dict['size'] = row.Length
table_dict[row.name] = row_dict

table_dict['path']['type'] #-> 'nvarchar'
table_dict['path']['size'] # -> 200
table_dict['Artist']['size'] #-> 50

Is this (nesting dictionaries) a good way to store multiple attributes
associated with a single key value?


On Mon, 14 May 2012 17:05:17 + (UTC), John Gordon
 wrote:

>In  Steve Sawyer 
> writes:
>
>> What I think I want to do is to construct a dictionary using the
>> column names as the index value, and a list containing the various
>> attributes (data type, lenghth, precision).
>
>If you're using just the column name as the dictionary key, make sure
>there are no duplicate column names among all your tables.
>
>> If this is a good approach, I ran into a problem populating the
>> dictionary as I couldn't seem to figure out how to make the update()
>> method work by passing the name property of the row object; I kept
>> getting a "keyword can't be an expression" error.
>
>The general syntax for assigning to a dictionary is:
>
>  my_dictionary[key] = value
>
>What are you trying that isn't working?
--Steve--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting DB schema (newbie Q)

2012-05-14 Thread Chris Angelico
On Tue, May 15, 2012 at 5:09 AM, Steve Sawyer  wrote:
> Thanks - now, given my query that returns the table structure, this
> works fine:
>
> table_dict = {}
> table_specs = cursor.execute(query_string)
> for row in table_specs:
>        row_dict = {}
>        row_dict['type'] = row.DataType
>        row_dict['size'] = row.Length
>        table_dict[row.name] = row_dict
>
> table_dict['path']['type'] #-> 'nvarchar'
> table_dict['path']['size'] # -> 200
> table_dict['Artist']['size'] #-> 50
>
> Is this (nesting dictionaries) a good way to store multiple attributes
> associated with a single key value?

There's lots of options. The dictionary works; or you could create a
class for your record - also, check out namedtuple from the
collections module, which is a shortcut to the second option.

# Option 2
class Field:
def __init__(self,datatype,length):
self.datatype=datatype
self.length=length

# Option 3:
import collections
Field=collections.namedtuple('Field',('datatype','length'))

table_dict = {}
table_specs = cursor.execute(query_string)
for row in table_specs:
# Option 1: no need to start with an empty dictionary and then populate it
table_dict[row.name] = {'type': row.DataType, 'size': row.Length}
# Option 2 or 3: your own record type, or a namedtuple
table_dict[row.name] = Field(row.DataType,row.Length)

# Option 1:
table_dict['path']['type'] #-> 'nvarchar'
table_dict['path']['size'] # -> 200
table_dict['Artist']['size'] #-> 50

# Option 2 or 3
table_dict['path'].datatype #-> 'nvarchar'
table_dict['path'].size # -> 200
table_dict['Artist'].size #-> 50

You'll notice that I've used 'datatype' rather than 'type' - the
latter would work, but since 'type' has other meaning (it's the class
that all classes subclass, if that makes sense), I like to avoid using
it.

The choice between these three options comes down to style, so pick
whichever one "feels best" to you.

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


Re-raised exceptions in 2.7.3 -- stack trace missing

2012-05-14 Thread Oliver Beattie
Hi there

I'm tying to investigate a bit of a weird problem here. Basically, I've just 
upgraded Python (from 2.7.2 -> 2.7.3) by way of an OS upgrade (Ubuntu), and now 
all the tracebacks I'm getting sent from my web app are looking like this:

http://dpaste.org/EgKJp/

As you can see, Django is correctly re-raising the exception, but the original 
stack trace is not there by way of sys.exc_info(). I've dug into the code a 
little and it seems fairly simple, exc_info is passed through logging.error 
from sys.exc_info() so I see no reason why this shouldn't work.

Bit perplexing, any idea what could cause this?

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


Re: which book?

2012-05-14 Thread Miki Tebeka
> I am going to learn python for some plot issues. which book or sources, do 
> you recommend please?
The tutorial is pretty good if you already know how to program.
I also heard a lot of good things on "Python Essential Reference".

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


Re: PyTextile Question

2012-05-14 Thread Josh English
On Monday, May 7, 2012 6:13:28 AM UTC-7, dinkyp...@gmail.com wrote:
> 
> Below is a test script that shows one way I've dealt with this issue in the 
> past by reformatting paragraphs to remove embedded line breaks.  YMMV.
> 
> import re, textile
> ...

Wow. Thank you. This works. I'm trying to figure what that regular expression 
does, but I swear it's copying the lines twice. (Clearly, I don't speak re.)

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


Instrumenting a class to see how it is used

2012-05-14 Thread Paul Moore
I'm trying to reverse-engineer some pretty complex code. One thing that would 
help me a lot is if I could instrument a key class, so that I'd get a report of 
when and how each method was called and any properties or attributes were 
accessed during a typical run.

I could do this relatively easily by just adding print calls to each 
method/attribute, but I was wondering - is there a library that does this sort 
of wrapping already? I tried writing my own but got bogged down in infinite 
recursion in _getattribute__ and couldn't see an easy way out.

If anyone has any suggestions, I'd be interested.
Thanks,
Paul.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-14 Thread james hedley
> i have not banned anything, or even alluded to it, whatsoever.  i asked that
> one specific mail not be commented upon

OK, sorry if I misunderstood, but that's still suppression in my book.

> reading your accounts strewn about is interesting, what exactly are *your* 
> motives?  

My motives are as I've stated; I'm a commercial user with products in 
development 
which use Pyjamas and that I have a long-term stake in. With a bit of thought, 
anyone 
should see why I value stability and continued viability. It's a long game but 
the
potential payback to pyjamas could be huge *if* it can keep commercial users on 
board.
This is where the existential threat to pyjamas comes from and why I and many 
others
consider the takeover to be reckless and unjustified.

> Luke is a talented developer, there is no doubt of this, but he is one of the 
> most 
> socially inept persons i have ever encountered

I don't think this is the right place to bash people or even defend them on a 
personal
level.

We get it though. You didn't get along with the guy.

> the idea was to retain Luke

I'm sorry but I don't believe this. Luke can speak for himself of course but 
this is
not how you keep people on-board.

> he decided to play legal threats as the first card 

He's claimed that you lifted data from his server without permission. I'm not 
commenting
on that, but if it's true then this is a massive roadblock in the viability of 
the 
project. I for one don't want to be involved in it. Can you picture the scene 
where a 
developer or businessperaon goes into a meeting with very senior, very 
conservative 
executives trying to pitch a product, and it turns out there are serious legal 
concerns
surrounding the technology platform?

If it isn't true then perhaps you should put people's minds at rest by giving a 
detailed 
explanation of the whole mail server situation, including where the data 
originated, where 
it is now, how it got there and why the accidental mailing of so many people 
occurred.

> indeed, you have witnessed little chatter

I'd invite anyone to review the pyjamas list for the last 7 days before they 
make 
up their minds. Some of the statements I've seen have been regrettable.

> by realizing this is not as black-and-white as you's like it to be. 

I have an ethical objection here, but moreover; it clearly just runs against my
interests to support your actions. I'm not sure you considered the commercial 
users
here, and with respect nor do I really get the impression you've understood it, 
still.

By the way; I'm not associated with Luke at all. I've emailed him off-list a 
few times
this week to discuss some angles to do with my work, but that's it.

In fact, I support Kees' proposition that Pyjamas should seek sponsorship from 
the
Python/Apache/Free Software Foundation. This would resolve questions of 
legitimacy and
leadership.

In my ideal outcome, we could tailor pyjamas more to business use; e.g.
tidying up any license issues, offering a commercial support contract (this 
will help
mitigate the damage done to perceptions of credibility), publishing a commercial
use policy (one of the foundations could offer support with this I hope).

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


Re: Python ABAQUS debugging problem.

2012-05-14 Thread Mahendra
On May 10, 9:31 am, Mahendra  wrote:
> Dear all,
>             I am learning to use python script for running ABAQUS
> (commerical finite element program). I am having a bug in the
> following chunk of code and am not sure what it is. I have three loops
> in my code. The first two loops work fine. The third loop is a
> combination of loop 1 and loop 2. It doesnt work. There is some syntax
> issue which it is not clear to me.
>
> #--#---#
> # Creating a list of moduli for parametric study
> moduli = [ 1000, 500]
>
> #--#---#
> # This loop works fine
>
> for E in moduli:
>     print E
>     lengthE='length'+str(E)
>     print lengthE
> #--#---#
>
> #--#---#
> # This loop works fine.
>
> for E in moduli:
> #   lengthE = 'length'+str(E)
> #       print E
> #       print lengthE
>
> mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E,
> 0.18), ))
>         job.submit()
>         job.waitForCompletion()
>         print 'Completed job for %s E' % (E)
> #--#---#
>
> #--#---#
> # This loop doesnt work.
> # It says syntax error in lengthE = 'length' + str(E)
> #--#---#
> for E in moduli:
>     print E
>         lengthE = 'length' + str(E)
>
> mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E,
> 0.18), ))
>         job.submit()
>         job.waitForCompletion()
> #       print lengthE
>         print 'Completed job for %s E' % (E)
> #--#---#
>
> Any help is deeply appreciated in this regard.
> Sincerely,
> Mahendra.

I think when I pasted the message from the code in this email, the
indentation is little off. I used notepad++ for writing the code. It
didnt show wrong indentation. However, on notepad it is wrongly
indented. The program is working now. Thanks for your time and sorry
for the inconvenience.
Mahendra.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which book?

2012-05-14 Thread d . poreh
On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote:
> > I am going to learn python for some plot issues. which book or sources, do 
> > you recommend please?
> The tutorial is pretty good if you already know how to program.
> I also heard a lot of good things on "Python Essential Reference".

Thanks.
Could you please pass the line for tutorial?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternative to subprocess in order to not wait for calling commands to complete

2012-05-14 Thread Adam Skutt
On May 10, 12:07 pm, ks  wrote:
> Hi All,
>
> From within one Python program, I would like to invoke three other
> Python programs. Usually I would use the subprocess module to invoke
> these sequentially. I now have a use case in which I must invoke the
> first one (not wait for it to complete), then invoke the second
> (similarly not wait for it to complete) and then go on to the third.
>
> I am not sure where I should start looking to be able to do this. I am
> reading about threads and forking and there are many options out
> there. So I was wondering if anyone might have suggestions on where I
> can start.
>

subprocess.Popen objects only block for process termination when you
request it, via wait() or communicate().  As such, if you never call
those methods, you will never block for process termination.  What you
want is essentially the default behavior if you're creating Popen
objects directly (instead of using the call() function).

However, you must call the wait() or poll() methods at least once,
after the subprocess has terminated, to release system resources.
There are many ways to accomplish this, and the best approach depends
on your application.  One simple option is to call poll() once each
time your application goes through its main loop.  Another option is
to use a dedicated thread for the purpose of reaping processes.

Please note that calling Popen.poll() in a loop over many processes
does not scale (each call incurs an expensive system call) and will
cause noticeable CPU consumption with even a handful of processes (3
is just fine, though).  Unfortunately, the subprocess module lacks any
way to wait on multiple processes simultaneously.  This is possible
with operating-system specific code, however.  I would not worry about
it for now, but it may be something you need to consider in the
future.

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


Python ABAQUS debugging problem.

2012-05-14 Thread Mahendra
Dear all,
I am learning to use python script for running ABAQUS
(commerical finite element program). I am having a bug in the
following chunk of code and am not sure what it is. I have three loops
in my code. The first two loops work fine. The third loop is a
combination of loop 1 and loop 2. It doesnt work. There is some syntax
issue which it is not clear to me.

#--#---#
# Creating a list of moduli for parametric study
moduli = [ 1000, 500]

#--#---#
# This loop works fine

for E in moduli:
print E
lengthE='length'+str(E)
print lengthE
#--#---#

#--#---#
# This loop works fine.

for E in moduli:
#   lengthE = 'length'+str(E)
#   print E
#   print lengthE

mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E,
0.18), ))
job.submit()
job.waitForCompletion()
print 'Completed job for %s E' % (E)
#--#---#

#--#---#
# This loop doesnt work.
# It says syntax error in lengthE = 'length' + str(E)
#--#---#
for E in moduli:
print E
lengthE = 'length' + str(E)

mdb.models['Model-1'].materials['Elastic'].elastic.setValues(table=((E,
0.18), ))
job.submit()
job.waitForCompletion()
#   print lengthE
print 'Completed job for %s E' % (E)
#--#---#


Any help is deeply appreciated in this regard.
Sincerely,
Mahendra.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "pakistani girls" "pakistani girls lahore" "pakistani girls phone numbers" "pakistani girls mobile number" "pakistani girls wallpapers" "pakistani girls cell numbers" on www.epakistanigirls.blogsp

2012-05-14 Thread Maha Jabeen
fuck you dude
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/http://numbersofgirlsinpakistan.blogspot.com/
http://numbersofgirlsinpakistan.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Instrumenting a class to see how it is used

2012-05-14 Thread Michele Simionato
This may get you started (warning: not really tested).

$ echo instr.py
from warnings import warn

oget = object.__getattribute__
tget = type.__getattribute__

class Instr(object):

class __metaclass__(type):
def __getattribute__(cls, name):
clsname = tget(cls, '__name__')
warn('accessing %s.%s' % (clsname, name), stacklevel=2)
return tget(cls, name)

def __getattribute__(self, name):
warn('accessing %s.%s' % (self, name), stacklevel=2)
return oget(self, name)


Then change the base classes of the class you want to instrument, i.e.

class MyClass(MyBase) -> class MyClass(MyBase, Instr)

and see what happens. It should work in simple cases.
It will log a lot, so will have to adapt this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Alternative to subprocess in order to not wait for calling commands to complete

2012-05-14 Thread ks
Hi All,

>From within one Python program, I would like to invoke three other
Python programs. Usually I would use the subprocess module to invoke
these sequentially. I now have a use case in which I must invoke the
first one (not wait for it to complete), then invoke the second
(similarly not wait for it to complete) and then go on to the third.

I am not sure where I should start looking to be able to do this. I am
reading about threads and forking and there are many options out
there. So I was wondering if anyone might have suggestions on where I
can start.

Any hints/references would be very helpful!

Thank you,
ks
-- 
http://mail.python.org/mailman/listinfo/python-list


Clicking a sub menu item

2012-05-14 Thread googlewellwisher
Hello,

Im a newbie to automation testing.Im using python scripting in
selenium to automate a website.

Now im facing a difficulty in clicking a submenu item.I have 5 buttons
in the main menu.I am able to click each of the menu button using
self.driver.find_element_by_id("MainMenuButton1").click()

But how can I click the MenuButton1_Submenu button?

For this purpose I think I have to move hover the menu button and wait
for some time, then click the submenus using their ids or whatever
property.Is this the right way to click the sub menu items? If yes can
abybody provide me the code for mouse hover a control?

If this is not the right procedure please provide me with appropriate
code to click on a sub menu item?

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


Re: parallel subprocess.getoutput

2012-05-14 Thread Adam Skutt
On May 11, 8:04 am, Jaroslav Dobrek  wrote:
> Hello,
>
> I wrote the following code for using egrep on many large files:
>
> MY_DIR = '/my/path/to/dir'
> FILES = os.listdir(MY_DIR)
>
> def grep(regex):
>     i = 0
>     l = len(FILES)
>     output = []
>     while i < l:
>         command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' +
> FILES[i]
>         result = subprocess.getoutput(command)
>         if result:
>             output.append(result)
>         i += 1
>     return output
>
> Yet, I don't think that the files are searched in parallel. Am I
> right? How can I search them in parallel?

subprocess.getoutput() blocks until the command writes out all of its
output, so no, they're not going to be run in parallel.  You really
shouldn't use it anyway, as it's very difficult to use it securely.
Your code, as it stands, could be exploited if the user can supply the
regex or the directory.

There are plenty of tools to do parallel execution in a shell, such
as: http://code.google.com/p/ppss/.  I would use one of those tools
first.

Nevertheless, if you must do it in Python, then the most portable way
to accomplish what you want is to:
0) Create a thread-safe queue object to hold the output.
1) Create each process using a subprocess.Popen object.  Do this
safely and securely, which means NOT passing shell=True in the
constructor, passing stdin=False, and passing stderr=False unless you
intend to capture error output.
2) Spawn a new thread for each process.  That thread should block
reading the Popen.stdout file object.  Each time it reads some output,
it should then write it to the queue.  If you monitor stderr as well,
you'll need to spawn two threads per subprocess.  When EOF is reached,
close the descriptor and call Popen.wait() to terminate the process
(this is trickier with two threads and requires additional
synchronization).
3) After spawning each process, monitor the queue in the first thread
and capture all of the output.
4) Call the join() method on all of the threads to terminate them.
The easiest way to do this is to have each thread write a special
object (a sentinel) to the queue to indicate that it is done.

If you don't mind platform specific code (and it doesn't look like you
do), then you can use fcntl.fcntl to make each file-object non-
blocking, and then use any of the various asynchronous I/O APIs to
avoid the use of threads.  You still need to clean up all of the file
objects and  processes when you are done, though.
-- 
http://mail.python.org/mailman/listinfo/python-list


parallel subprocess.getoutput

2012-05-14 Thread Jaroslav Dobrek
Hello,

I wrote the following code for using egrep on many large files:

MY_DIR = '/my/path/to/dir'
FILES = os.listdir(MY_DIR)

def grep(regex):
i = 0
l = len(FILES)
output = []
while i < l:
command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' +
FILES[i]
result = subprocess.getoutput(command)
if result:
output.append(result)
i += 1
return output

Yet, I don't think that the files are searched in parallel. Am I
right? How can I search them in parallel?

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


Newby Python Programming Question

2012-05-14 Thread Coyote
Folks,

I am migrating to Python after a 20+ year career writing IDL programs 
exclusively. I have a really simple question that I can't find the answer to in 
any of the books and tutorials I have been reading to get up to speed.

I have two programs. The first is in a file I named file_utils.py:

   def pwd():
   import os
   print os.getcwd()

The second is in a file I named pwd.py:

   import os
   print os.getcwd()

Here is my question. I am using the Spyder IDE to run these programs. If I type 
these commands, I get exactly what I want, the name of my current directory:

   >>>from file_utils import pwd
   >>>pwd()
   C:\Users\coyote\pyscripts

But, if I "run" the pwd.py script by selecting the "Run" option from the IDE 
menu, the directory is printed *twice* in the output window. Why is that?

Thanks!

Cheers,

David

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


Re: parallel subprocess.getoutput

2012-05-14 Thread Jaroslav Dobrek
Sorry, for code-historical reasons this was unnecessarily complicated.
Should be:


MY_DIR = '/my/path/to/dir'
FILES = os.listdir(MY_DIR)


def grep(regex):
output = []
for f in FILES:
command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + f
result = subprocess.getoutput(command)
if result:
output.append(result)
return output
-- 
http://mail.python.org/mailman/listinfo/python-list


specify end of line character for readline

2012-05-14 Thread Jason
Is there any way to specify the end of line character to use in file.readline() 
?

I would like to use '\r\n' as the end of line and allow either \r or \n by 
itself within the line.

Thanks,

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


Re: which book?

2012-05-14 Thread darnold
On May 10, 4:58 am, d.po...@gmail.com wrote:
> On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote:
> > > I am going to learn python for some plot issues. which book or sources, 
> > > do you recommend please?
> > The tutorial is pretty good if you already know how to program.
> > I also heard a lot of good things on "Python Essential Reference".
>
> Thanks.
> Could you please pass the line for tutorial?

i believe that would be the tutorial at http://docs.python.org/tutorial/
.
-- 
http://mail.python.org/mailman/listinfo/python-list


Sharing Data in Python

2012-05-14 Thread raunakgup90
I have some Pickled data, which is stored on disk, and it is about 100 MB in 
size.

When my python program is executed, the picked data is loaded using the cPickle 
module, and all that works fine.

If I execute the python multiple times using python main.py for example, each 
python process will load the same data multiple times, which is the correct 
behaviour.

How can I make it so, all new python process share this data, so it is only 
loaded a single time into memory?

asked the same question on SO, but could not get any constructive responses.. 
http://stackoverflow.com/questions/10550870/sharing-data-in-python/10551845
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newby Python Programming Question

2012-05-14 Thread Maarten
On Friday, May 11, 2012 5:25:20 PM UTC+2, Coyote wrote:

> I am migrating to Python after a 20+ year career writing IDL programs 
> exclusively. I have a really simple question that I can't find the answer to 
> in any of the books and tutorials I have been reading to get up to speed.

Welcome here.

> I have two programs. The first is in a file I named file_utils.py:
> 
>def pwd():
>import os
>print os.getcwd()

Move the import tot the root level of the file:

import os

def pwd():
print(os.getcwd())

(and print() is a function these days)

> The second is in a file I named pwd.py:
> 
>import os
>print os.getcwd()
> 
> Here is my question. I am using the Spyder IDE to run these programs. If I 
> type these commands, I get exactly what I want, the name of my current 
> directory.
> 
> But, if I "run" the pwd.py script by selecting the "Run" option from the IDE 
> menu, the directory is printed *twice* in the output window. Why is that?

I'd say this is a bug or feature of the IDE. If I use ipython I get:

In [1]: %run mypwd
/nobackup/users/maarten/tmp/coyote

I tried to use Eclipse, but I don't think I'll do that again. I otherwise never 
use an IDE, it makes me confused. I don't know what the IDE is doing. Note that 
there is a standard module (at least on unix/linux) with the name pwd, but I 
guess that the IDE is not confused.

I do recommend you read http://docs.python.org/howto/doanddont.html as a 
starting point to avoid learning some bad habits, especially on importing. You 
probably already found 
https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html

For scripts that are intended to be run from the command line, I use:

#!/usr/bin/env python

import os
def pwd():
return os.getcwd()

if __name__ == "__main__":
print(pwd())

This will allow you to import the module (without side effects) and call the 
function, as well as 'running' the file. This increases the usefullness of the 
module. There are other advantages, especially when the scripts involves (many) 
variables.

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


Re: Scrapy - importing files from local, rather than www

2012-05-14 Thread leomcallister
You can try running Python's web server on the folder (python -m 
SimpleHTTPServer) and point Scrapy to it.

On Monday, May 7, 2012 4:57:22 AM UTC-3, nbw wrote:
> Hi everyone, I'm new to Python (loving it!) and Scrapy. I have a
> question I just can't seem to get my head around. I can get a simple
> Scrapy spider to pick up URLs and download them fine, but the HTML
> files I have are stored locally. The reason for this, is for some
> reason when I "Save As" the pages I get everything, whereas if Scrapy
> runs over them it seems to miss certain areas where there's
> Javascript.
> 
> So, I have them sitting in a directory (C:/scrapy_test) but can't for
> the life of me get Scrapy to find them. Is there anyone who's had this
> problem and solved it, or can help?
> 
> Any help is much appreciated.
> Kind regards,
> nbw

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


Re: Newby Python Programming Question

2012-05-14 Thread Coyote
Maarten writes:

> I do recommend you read http://docs.python.org/howto/doanddont.html as a 
> starting point to avoid learning some bad habits, especially on importing. 
> You probably already found 
> https://www.cfa.harvard.edu/~jbattat/computer/python/science/idl-numpy.html

Yikes! I'm sure that first reference is in English, but I don't have much of an 
idea what it means yet. :-)

I have found the second reference very helpful. I've bookmarked both of these 
for future consideration.

Thanks for your good advice. 

Cheers,

David

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


Re: Newby Python Programming Question

2012-05-14 Thread CM
On May 11, 11:25 am, Coyote  wrote:
> Folks,
>
> I am migrating to Python after a 20+ year career writing IDL programs 
> exclusively. I have a really simple question that I can't find the answer to 
> in any of the books and tutorials I have been reading to get up to speed.
>
> I have two programs. The first is in a file I named file_utils.py:
>
>    def pwd():
>        import os
>        print os.getcwd()
>
> The second is in a file I named pwd.py:
>
>    import os
>    print os.getcwd()
>
> Here is my question. I am using the Spyder IDE to run these programs. If I 
> type these commands, I get exactly what I want, the name of my current 
> directory:
>
>    >>>from file_utils import pwd
>    >>>pwd()
>    C:\Users\coyote\pyscripts
>
> But, if I "run" the pwd.py script by selecting the "Run" option from the IDE 
> menu, the directory is printed *twice* in the output window. Why is that?

I don't know Spyder IDE, but I don't think this should happen; could
there just be a simple mistake?  Because you first refer to the .py
file as 'file_utils.py' but then you refer to the file as
'pwd.py'...which is also the name of your function. Room for
confusion...so could you test this by saving only your one function
(below), give the .py a new name to avoid confusion (like test_pwd.py)
and then running *that* through Spyder IDE?

def pwd():
import os
print os.getcwd()

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


%d not working in re at Python 2.7?

2012-05-14 Thread vacu
I am frustrated to see %d not working in my Python 2.7 re.search, like
this example:

>>> (re.search('%d', "asdfdsf78asdfdf")).group(0)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'NoneType' object has no attribute 'group'


\d works fine:

>>> (re.search('\d+', "asdfdsf78asdfdf")).group(0)
'78'


And google search ignores % in their search, so I failed to find
answer from Python mailing list or web,
Do you have any idea what's problem here?

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


Re: Newby Python Programming Question

2012-05-14 Thread Coyote
CM writes:

> I don't know Spyder IDE, but I don't think this should happen; could
> there just be a simple mistake?  Because you first refer to the .py
> file as 'file_utils.py' but then you refer to the file as
> 'pwd.py'...which is also the name of your function. Room for
> confusion...so could you test this by saving only your one function
> (below), give the .py a new name to avoid confusion (like test_pwd.py)
> and then running *that* through Spyder IDE?
> 
> def pwd():
> import os
> print os.getcwd()

I probably explained the situation badly. I have a file pwd.py with these two 
lines of code in it:

import os
print os.getcwd()

If I start a new Spyder IDL session and "run" this file by choosing RUN from 
the menu bar, the directory is printed twice. This appears to me now to be an 
IDE error, because if I use a runfile command, the directory is printed only 
once, as I expect.

   >>>runfile('pwd.py')
C:\Users\coyote\pyscripts

I've been playing around with a couple of IDEs because I liked the one I used 
with IDL and I wanted to use something similar for Python. The IDLDE was an 
Eclipse variant, but I've tried installing Eclipse before for something else 
and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. 
Unless, of course, I need a good excuse to head over to the Rio for the 
margaritas. :-)

Cheers,

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


tiny script has memory leak

2012-05-14 Thread gry
sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2
[gcc-4_3-branch revision 141291]]
I thought this script would be very lean and fast, but with a large
value for n (like 15), it uses 26G of virtural memory, and things
start to crumble.

#!/usr/bin/env python
'''write a file of random integers.  args are: file-name how-many'''
import sys, random

f = open(sys.argv[1], 'w')
n = int(sys.argv[2])
for i in xrange(n):
print >>f, random.randint(0, sys.maxint)
f.close()

What's using so much memory?
What would be a better way to do this?  (aside from checking arg
values and types, I know...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sharing Data in Python

2012-05-14 Thread Miki Tebeka
> How can I make it so, all new python process share this data, so it is only 
> loaded a single time into memory?
You can have one process as server and client ask for parts of data.
You might be able to do something smart with mmap but I can't think of a way.

I Linux systems, if you first load the data and then fork, the OS will keep all 
the read only data shared.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-14 Thread anthony
On Thursday, May 10, 2012 3:06:47 AM UTC-5, james hedley wrote:
> > i have not banned anything, or even alluded to it, whatsoever.  i asked that
> > one specific mail not be commented upon
> 
> OK, sorry if I misunderstood, but that's still suppression in my book.

James, how can you realistically condemn a simple request with such colorful 
words, now and in previous messages, yet simultaneously claim to support Luke's 
many impositions ...

https://groups.google.com/d/msg/pyjamas-dev/wK8f2XJQvlY/ZTK-9bZ5TisJ
https://groups.google.com/d/msg/pyjamas-dev/wK8f2XJQvlY/xp63LbOYO6oJ

... i could easily drum up a hundred more, if i were both inclined and 
extremely bored.  i have been in contact by other users who claim a similar 
state as yourself, and frankly, everyone save yourself expresses a far more 
genuine interest ... your comments are riddled with dissonance ...

> > reading your accounts strewn about is interesting, what exactly are *your* 
> > motives?  
> 
> My motives are as I've stated; I'm a commercial user with products in 
> development 
> which use Pyjamas and that I have a long-term stake in. With a bit of 
> thought, anyone 
> should see why I value stability and continued viability. It's a long game 
> but the
> potential payback to pyjamas could be huge *if* it can keep commercial users 
> on board.
> This is where the existential threat to pyjamas comes from and why I and many 
> others
> consider the takeover to be reckless and unjustified.

perhaps.  in retrospect i would have approached some aspects a bit differently. 
 interestingly ... things seem to be panning out in ways that will benefit all 
... isn't that right, James?  to be honest though, of all the commercial users 
i'm aware, none have responded as you describe.

this was not a lone wolf operation, and neither are discussions in flight.  i 
think if you temper your reactions, and turn down the volume, you will find 
that things are shaping up rather well ... i am very much aware of the events 
unfolding, as are you.  whilst you paint me the enemy, new paths have been 
opened ... achievement? unlocked!

> > Luke is a talented developer, there is no doubt of this, but he is one of 
> > the most 
> > socially inept persons i have ever encountered
> 
> I don't think this is the right place to bash people or even defend them on a 
> personal
> level.

i'm doing neither.  this is an mere observation after multiple years of 
interaction, and my own research into past endeavors.

> We get it though. You didn't get along with the guy.

well, no, i don't think you get it ... are you paying attention, at all?  i got 
along with him just fine; i've already detailed this elsewhere.

> > the idea was to retain Luke
> 
> I'm sorry but I don't believe this. Luke can speak for himself of course but 
> this is
> not how you keep people on-board.

well, don't then :-(

... but several did, and it's the cross-my-heart-pinky-swear'in truth.  after 
many months of lengthy discussion it felt right.  after 10 minutes of 
reactionary thought it feels less right to you ... that's certainly 
understandable, and maybe even correct.  was it *really* the right thing to do? 
maybe not, this was unprecedented.  already however, great things are in 
motion, and i feel good about the feedback received, outside and in.

> > he decided to play legal threats as the first card 
> 
> He's claimed that you lifted data from his server without permission. I'm not 
> commenting
> on that, but if it's true then this is a massive roadblock in the viability 
> of the 
> project. I for one don't want to be involved in it. Can you picture the scene 
> where a 
> developer or businessperaon goes into a meeting with very senior, very 
> conservative 
> executives trying to pitch a product, and it turns out there are serious 
> legal concerns
> surrounding the technology platform?

unrelated ... the technology is freely available.

> If it isn't true then perhaps you should put people's minds at rest by giving 
> a detailed 
> explanation of the whole mail server situation, including where the data 
> originated, where 
> it is now, how it got there and why the accidental mailing of so many people 
> occurred.

acting as an agent of the organization, i reinstated services people had 
purposefully subscribed to, in accordance with an infrastructure transition.  
these were pre-existing relationships to a service i managed.  alas, i was 
unaware of the reasons to -- or existence of -- joining a list, but opting for 
"nomail" ... thus the state was reset, ie. resuming reception thereto. 
following this realization, all existing members were simply requested to join 
a new list at their willful discretion. data was/is neither leaked nor 
compromised in any way.

if anything, organization leaders failed to register with the Ministry their 
collection of personal data, and also failed to train agents on proper 
handling, if need be.

... that's the official statement, but like i s

Python web-framework+db with the widest scalability?

2012-05-14 Thread Alec Taylor
I am building a project requiring high performance and scalability, entailing:

• Role-based authentication with API-key licensing to access data of specific 
users
• API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP
• "Easily" configurable getters and setters to create APIs accessing the same 
data but with input/output in different schemas

A conservative estimate of the number of tables—often whose queries require 
joins—is: 20.

Which database type—e.g.: NoSQL or DBMS—key-value data store or 
object-relational database—e.g.: Redis or PostgreSQL—and web-framework—e.g. 
Django, Web2Py or Flask—would you recommend?

Thanks for all suggestions,

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


Re: Python web-framework+db with the widest scalability?

2012-05-14 Thread elektrrrus
Hi,

From my experience while NoSQL databases are very fast and scalable, there is 
lack of _good_ support for popular frameworks. I've try with django and 
mongoengine, but results was poor. In my company we're building now large 
api-driven application with django and postgresql as a base. Django has two 
great api engines - piston and tastypie. Consider looking to nosql eg. mongodb 
as caching engine and session storage. Django is mature and stable framework, 
it has some limitations but there are good and documented use cases for doing 
almost everything You may need. Look also at server layer - popular apache and 
cgi-like solutions has very poor performance. Maybe You have use-cases to 
develop with messages queues like celery. 

W dniu sobota, 12 maja 2012 10:32:09 UTC+2 użytkownik Alec Taylor napisał:
> I am building a project requiring high performance and scalability, entailing:
> 
> • Role-based authentication with API-key licensing to access data of specific 
> users
> • API exposed with REST (XML, JSON), XMLRPC, JSONRPC and SOAP
> • "Easily" configurable getters and setters to create APIs accessing the same 
> data but with input/output in different schemas
> 
> A conservative estimate of the number of tables—often whose queries require 
> joins—is: 20.
> 
> Which database type—e.g.: NoSQL or DBMS—key-value data store or 
> object-relational database—e.g.: Redis or PostgreSQL—and web-framework—e.g. 
> Django, Web2Py or Flask—would you recommend?
> 
> Thanks for all suggestions,
> 
> Alec Taylor

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


Re: %d not working in re at Python 2.7?

2012-05-14 Thread Josh McGee
%

On Friday, May 11, 2012 11:58:01 AM UTC-7, vacu wrote:
> I am frustrated to see %d not working in my Python 2.7 re.search, like
> this example:
> 
> >>> (re.search('%d', "asdfdsf78asdfdf")).group(0)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'NoneType' object has no attribute 'group'
> 
> 
> \d works fine:
> 
> >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0)
> '78'
> 
> 
> And google search ignores % in their search, so I failed to find
> answer from Python mailing list or web,
> Do you have any idea what's problem here?
> 
> Thanks a head
> Vacu

%d and %s and such are format strings, not regex.
-- 
http://mail.python.org/mailman/listinfo/python-list


Hashability questions

2012-05-14 Thread Bob Grommes
Noob alert: writing my first Python class library.

I have a straightforward class called Utility that lives in Utility.py.

I'm trying to get a handle on best practices for fleshing out a library.  As 
such, I've done the following for starters:

  def __str__(self):
return str(type(self))

#  def __eq__(self,other):
#return hash(self) == hash(other)

The commented-out method is what I'm questioning.  As-is, I can do the 
following from my test harness:

u = Utility()
print(str(u))
print(hash(u))
u2 = Utility()
print(hash(u2))
print(hash(u) == hash(u2))

However if I uncomment the above _eq_() implementation, I get the following 
output:


Traceback (most recent call last):
  File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in 
print(hash(u))
TypeError: unhashable type: 'Utility'

Process finished with exit code 1

Obviously there is some sort of default implementation of __hash__() at work 
and my implementation of _eq_() has somehow broken it.  Can anyone explain 
what's going on?
-- 
http://mail.python.org/mailman/listinfo/python-list


Are there any instrumentation widgets for wxpython or tkinter?

2012-05-14 Thread Sverre
I searched for widgets used for PLC automation or lab instrumentation
like gauges, led's etc. in the net, but didn't found anything because
of those massive link spam sites. In the case there isn't any
solution, with which toolkit would it be easiest to build gauges?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extracting DB schema (newbie Q)

2012-05-14 Thread james hedley
On Monday, 14 May 2012 17:01:49 UTC+1, Steve Sawyer  wrote:
> Brand-new to Python (that's a warning, folks)
> 
> Trying to write a routine to import a CSV file into a SQL Server
> table. To ensure that I convert the data from the CSV appropriately,
> I"m executing a query that gives me the schema (data column names,
> data types and sizes) from the target table.
> 
> What I think I want to do is to construct a dictionary using the
> column names as the index value, and a list containing the various
> attributes (data type, lenghth, precision).
> 
> If this is NOT a good approach (or if there is a better approach),
> please issue a dope-slap, ignore the rest of this post and set me
> straight.
> 
> If this is a good approach, I ran into a problem populating the
> dictionary as I couldn't seem to figure out how to make the update()
> method work by passing the name property of the row object; I kept
> getting a "keyword can't be an expression" error.
> 
> What I was able to make work was to construct the command as a string
> and run exec(
> ), but seems there shoudl be a more
> direct way of updating the dictionary.
> 
> TIA.

Could you provide some demo code? Something minimal but runnable, which results 
in the error you're getting would be best.
-- 
http://mail.python.org/mailman/listinfo/python-list


Yet another "split string by spaces preserving single quotes" problem

2012-05-14 Thread Massi
Hi everyone,
I know this question has been asked thousands of times, but in my case
I have an additional requirement to be satisfied. I need to handle
substrings in the form 'string with spaces':'another string with
spaces' as a single token; I mean, if I have this string:

s ="This is a 'simple test':'string which' shows 'exactly my'
problem"

I need to split it as follow (the single quotes must be mantained in
the splitted list):

["This", "is",  "a",  "'simple test':'string which'", "shows",
"'exactly my'", "problem"]

Up to know I have written some ugly code which uses regular
expression:

splitter = re.compile("(?=\s|^)('[^']+') | ('[^']+')(?=\s|$)")

temp = [t for t in splitter.split(s) if t not in [None, '']]
print temp
t = []
for i, p in enumerate(temp) :
for x in ([p] if (p[0] == "'" and p[1] == "'") else p.split('
')) :
t.append(x)

But it does not handle "colon" case.
Any hints? Thanks in advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which book?

2012-05-14 Thread Mark Lawrence

On 10/05/2012 10:58, d.po...@gmail.com wrote:

On Wednesday, May 9, 2012 7:13:54 AM UTC-7, Miki Tebeka wrote:

I am going to learn python for some plot issues. which book or sources, do you 
recommend please?

The tutorial is pretty good if you already know how to program.
I also heard a lot of good things on "Python Essential Reference".


Thanks.
Could you please pass the line for tutorial?


google for python tutorial - IIRC first hit is to the tutorial for 
version 2.7.3


--
Cheers.

Mark Lawrence.

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


Re: Need to get Tags and Values from Dom

2012-05-14 Thread james hedley
On Monday, 14 May 2012 01:50:23 UTC+1, TommyVee  wrote:
> I have a very simple XML document that I need to "walk", and I'm using 
> xml.dom.minidom.  No attributes, just lots of nested tags and associated 
> values.  All I'm looking to do is iterate through each of the highest 
> sibling nodes, check what the tag is, and process its value accordingly.  If 
> a node has children, same thing - iterate through the nodes, check the tags 
> and process the values accordingly.  I see where each node object has a 
> "childNodes" attribute, so I can drill down the tree.  But what are the node 
> attributes which indicate Tag and Value?  I thought it would have been 
> nodeName and nodeValue, but that doesn't seem to be.  Does anyone know?
> 
> Thanks in advance, TommyVee

Ah maybe you're confused about how text nodes work in minidom. Every element 
will have a nodeName attribute (not callable) but if you try el.nodeValue on a 
text node you get None. That's because the text is represented by a child node 
with nodeName '#text', so you want (el.nodeName, el.firstChild.nodeValue).

General tips - try the docs: http://docs.python.org/library/xml.dom.minidom.html
and also use dir() a lot on objects when you're learning a new api.

Hope that helps. Disclaimer: haven't used minidom in anger for some time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %d not working in re at Python 2.7?

2012-05-14 Thread Tim Chase
On 05/11/12 13:58, vacu wrote:
> I am frustrated to see %d not working in my Python 2.7 re.search, like
> this example:
> 
 (re.search('%d', "asdfdsf78asdfdf")).group(0)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'NoneType' object has no attribute 'group'
> 
> 
> \d works fine:
> 
 (re.search('\d+', "asdfdsf78asdfdf")).group(0)
> '78'
> 
> Do you have any idea what's problem here?

Because the regexp module doesn't support using "%d" in this way?
I'd be curious is you can point to Python documentation to the contrary.

You know what the problem is, you didn't spell it r"\d+" so I'm not
sure why you're asking.  I've tested as far back as Python2.3 and
"%d" hasn't worked like you seem to expect it to in any of those
versions.

As an aside, use raw strings (as in r"\d+" with the leading "r")
instead of regular strings to ensure escaping applies as you expect
it to.

-tkc


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


Re: %d not working in re at Python 2.7?

2012-05-14 Thread Benjamin Kaplan
On May 14, 2012 7:06 PM, "vacu"  wrote:
>
> I am frustrated to see %d not working in my Python 2.7 re.search, like
> this example:
>
> >>> (re.search('%d', "asdfdsf78asdfdf")).group(0)
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'NoneType' object has no attribute 'group'
>
>
> \d works fine:
>
> >>> (re.search('\d+', "asdfdsf78asdfdf")).group(0)
> '78'
>
>
> And google search ignores % in their search, so I failed to find
> answer from Python mailing list or web,
> Do you have any idea what's problem here?
>
> Thanks a head
> Vacu
> --

There's no problem at all. This is re.search, not scanf. They aren't
supposed to behave the same. In fact, the docs specifically describe how to
simulate scanf using re because python doesn't have a scanf function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hashability questions

2012-05-14 Thread Chris Kaynor
On Sun, May 13, 2012 at 12:11 PM, Bob Grommes  wrote:
> Noob alert: writing my first Python class library.
>
> I have a straightforward class called Utility that lives in Utility.py.
>
> I'm trying to get a handle on best practices for fleshing out a library.  As 
> such, I've done the following for starters:
>
>  def __str__(self):
>    return str(type(self))
>
> #  def __eq__(self,other):
> #    return hash(self) == hash(other)
>
> The commented-out method is what I'm questioning.  As-is, I can do the 
> following from my test harness:
>
> u = Utility()
> print(str(u))
> print(hash(u))
> u2 = Utility()
> print(hash(u2))
> print(hash(u) == hash(u2))
>
> However if I uncomment the above _eq_() implementation, I get the following 
> output:
>
> 
> Traceback (most recent call last):
>  File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in 
>    print(hash(u))
> TypeError: unhashable type: 'Utility'
>
> Process finished with exit code 1
>
> Obviously there is some sort of default implementation of __hash__() at work 
> and my implementation of _eq_() has somehow broken it.  Can anyone explain 
> what's going on?

In Python, the default implementations of __hash__ and __eq__ are set
to return the id of the object. Thus, an object by default compares
equal only to itself, and it hashes the same everytime.

In Python3, if you override __eq__, the default __hash__ is removed,
however it can also be overridden to provide better hashing support.
In Python2, the default removal of __hash__ did not exist, which could
lead to stubble bugs where a class would override __eq__ by leave
__hash__ as the default implementation.

Generally, the default __eq__ and __hash__ functions provide the
correct results, and are nice and convenient to have. From there, the
case where __eq__ is overridden is the next most common, and if it is
overridden, the default __hash__ is almost never correct, and thus the
object should either not be hashable (the default in Python3) or
should also be overriden to produce the correct results.

The rule is that, if two objects return different results from
__hash__, they should never compare equal. The opposite rule also
holds true: if two objects compare equal, they should return the same
value from __hash__.

See http://docs.python.org/reference/datamodel.html#object.__hash__
and http://docs.python.org/reference/datamodel.html#object.__lt__ for
more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-14 Thread Mark Lawrence

On 12/05/2012 08:10, anth...@xtfx.me wrote:

On Thursday, May 10, 2012 3:06:47 AM UTC-5, james hedley wrote:


My nose and my stomach give me a very strong feeling that something is 
very, very wrong with the pyjamas project.  I've personally never used 
it, but given the adverse publicity I wouldn't touch it with a barge pole.


--
Cheers.

Mark Lawrence.

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


Re: Hashability questions

2012-05-14 Thread Chris Rebert
On Sun, May 13, 2012 at 12:11 PM, Bob Grommes  wrote:
> Noob alert: writing my first Python class library.
>
> I have a straightforward class called Utility that lives in Utility.py.
>
> I'm trying to get a handle on best practices for fleshing out a library.  As 
> such, I've done the following for starters:
>
>  def __str__(self):
>    return str(type(self))
>
> #  def __eq__(self,other):
> #    return hash(self) == hash(other)
>
> The commented-out method is what I'm questioning.  As-is, I can do the 
> following from my test harness:
>
> u = Utility()
> print(str(u))
> print(hash(u))
> u2 = Utility()
> print(hash(u2))
> print(hash(u) == hash(u2))
>
> However if I uncomment the above _eq_() implementation, I get the following 
> output:
>
> 
> Traceback (most recent call last):
>  File "/Users/bob/PycharmProjects/BGC/Tests.py", line 7, in 
>    print(hash(u))
> TypeError: unhashable type: 'Utility'
>
> Process finished with exit code 1
>
> Obviously there is some sort of default implementation of __hash__() at work 
> and my implementation of _eq_() has somehow broken it.  Can anyone explain 
> what's going on?

See the 3rd, 5th, and 4th paragraphs of:
http://docs.python.org/dev/reference/datamodel.html#object.__hash__

Also, for future reference, it's advisable to state whether your
question concerns Python 2.x or Python 3.x.

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


Re: %d not working in re at Python 2.7?

2012-05-14 Thread Vacu
Thanks Tim, it is my mis-understanding of usage of %d in Python. After
reading it carefully, it should be used in re.scan.
The reason I made this dump mistake is because I got a script from our
expert and I am totally new on Python, before reading your
email, I hadn't a doubt it is wrong usage and didn't examine document
carefully. I apologize for you time spent on it. -Vacu

On Mon, May 14, 2012 at 4:20 PM, Tim Chase wrote:

> On 05/11/12 13:58, vacu wrote:
> > I am frustrated to see %d not working in my Python 2.7 re.search, like
> > this example:
> >
>  (re.search('%d', "asdfdsf78asdfdf")).group(0)
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > AttributeError: 'NoneType' object has no attribute 'group'
> >
> >
> > \d works fine:
> >
>  (re.search('\d+', "asdfdsf78asdfdf")).group(0)
> > '78'
> >
> > Do you have any idea what's problem here?
>
> Because the regexp module doesn't support using "%d" in this way?
> I'd be curious is you can point to Python documentation to the contrary.
>
> You know what the problem is, you didn't spell it r"\d+" so I'm not
> sure why you're asking.  I've tested as far back as Python2.3 and
> "%d" hasn't worked like you seem to expect it to in any of those
> versions.
>
> As an aside, use raw strings (as in r"\d+" with the leading "r")
> instead of regular strings to ensure escaping applies as you expect
> it to.
>
> -tkc
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to get Tags and Values from Dom

2012-05-14 Thread TommyVee
"james hedley"  wrote in message 
news:11852803.89.1337001575700.JavaMail.geo-discussion-forums@vbmd2...


On Monday, 14 May 2012 01:50:23 UTC+1, TommyVee  wrote:

I have a very simple XML document that I need to "walk", and I'm using
xml.dom.minidom.  No attributes, just lots of nested tags and associated
values.  All I'm looking to do is iterate through each of the highest
sibling nodes, check what the tag is, and process its value accordingly. 
If
a node has children, same thing - iterate through the nodes, check the 
tags

and process the values accordingly.  I see where each node object has a
"childNodes" attribute, so I can drill down the tree.  But what are the 
node

attributes which indicate Tag and Value?  I thought it would have been
nodeName and nodeValue, but that doesn't seem to be.  Does anyone know?

Thanks in advance, TommyVee


Ah maybe you're confused about how text nodes work in minidom. Every element 
will have a nodeName attribute (not callable) but if you try el.nodeValue on 
a text node you get None. That's because the text is represented by a child 
node with nodeName '#text', so you want (el.nodeName, 
el.firstChild.nodeValue).


General tips - try the docs: 
http://docs.python.org/library/xml.dom.minidom.html

and also use dir() a lot on objects when you're learning a new api.

Hope that helps. Disclaimer: haven't used minidom in anger for some time.

Confused?  That's an understatement.  Part of the problem is that it's been 
a long time since I learned DOM and now I'm trying to cram to get this 
program done.


Anyway, your suggestion to access el.firstChild.nodeValue did the trick.

Thanks

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


Re: tiny script has memory leak

2012-05-14 Thread Ian Kelly
On Fri, May 11, 2012 at 3:29 PM, gry  wrote:
> sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2
> [gcc-4_3-branch revision 141291]]
> I thought this script would be very lean and fast, but with a large
> value for n (like 15), it uses 26G of virtural memory, and things
> start to crumble.
>
> #!/usr/bin/env python
> '''write a file of random integers.  args are: file-name how-many'''
> import sys, random
>
> f = open(sys.argv[1], 'w')
> n = int(sys.argv[2])
> for i in xrange(n):
>    print >>f, random.randint(0, sys.maxint)
> f.close()
>
> What's using so much memory?

I don't know, I'm not able to replicate the problem you're reporting.
When I try your script with a value of 15, it runs in under a
second and does not appear to consume any more virtual memory than
what is normally used by the Python interpreter.  I suspect there is
something else at play here.

> What would be a better way to do this?  (aside from checking arg
> values and types, I know...)

I don't see anything wrong with the way you're currently doing it,
assuming you can solve your memory leak issue.

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


Re: Yet another "split string by spaces preserving single quotes" problem

2012-05-14 Thread Tim Chase
On 05/13/12 16:14, Massi wrote:
> Hi everyone,
> I know this question has been asked thousands of times, but in my case
> I have an additional requirement to be satisfied. I need to handle
> substrings in the form 'string with spaces':'another string with
> spaces' as a single token; I mean, if I have this string:
> 
> s ="This is a 'simple test':'string which' shows 'exactly my'
> problem"
> 
> I need to split it as follow (the single quotes must be mantained in
> the splitted list):

The "quotes must be maintained" bit is what makes this different
from most common use-cases.  Without that condition, using
shlex.split() from the standard library does everything else that
you need.  Alternatively, one might try hacking csv.reader() to do
the splitting for you, though I had less luck than with shlex.

> Up to know I have written some ugly code which uses regular
> expression:
> 
> splitter = re.compile("(?=\s|^)('[^']+') | ('[^']+')(?=\s|$)")

You might try

 r = re.compile(r"""(?:'[^']*'|"[^"]*"|[^'" ]+)+""")
 print r.findall(s)

which seems to match your desired output.  It doesn't currently
handle tabs, but by breaking it out, it's easy to modify (and may
help understand what it's doing)

>>> single_quoted = "'[^']*'"
>>> double_quoted = '"[^"]*"'
>>> other = """[^'" \t]+"""  # added a "\t" tab here
>>> matches = '|'.join((single_quoted, double_quoted, other))
>>> regex = r'(?:%s)+' % matches
>>> r = re.compile(regex)
>>> r.findall(s)
['This', 'is', 'a', "'simple test':'string which'", 'shows',
"'exactly my'", 'problem']


Hope this helps,

-tkc






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


Re: tiny script has memory leak

2012-05-14 Thread Chris Angelico
On Sat, May 12, 2012 at 7:29 AM, gry  wrote:
> f = open(sys.argv[1], 'w')

What are you passing as the file name argument? Could that device be
the cause of your memory usage spike?

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


Re: Hashability questions

2012-05-14 Thread Dave Angel
On 05/14/2012 07:38 PM, Chris Kaynor wrote:
> On Sun, May 13, 2012 at 12:11 PM, Bob Grommes  wrote:
>> 
>>
>> The rule is that, if two objects return different results from
>> __hash__, they should never compare equal. The opposite rule also
>> holds true: if two objects compare equal, they should return the same
>> value from __hash__.
>>

You state those as if they were different rules.  Those are
contrapositives of each other, and therefore equivalent.

The inverse would be that two objects with the same __hash__ should
compare equal, and that's clearly not true.



-- 

DaveA

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


Re: Hashability questions

2012-05-14 Thread alex23
On May 14, 5:11 am, Bob Grommes  wrote:
> Obviously there is some sort of default implementation of __hash__()
> at work and my implementation of _eq_() has somehow broken it.
> Can anyone explain what's going on?

It looks like this has changed between Python 2 and 3:

"If a class does not define an __eq__() method it should not define a
__hash__() operation either; if it defines __eq__() but not
__hash__(), its instances will not be usable as items in hashable
collections."

From: http://docs.python.org/dev/reference/datamodel.html#object.__hash__

You should just be able to add a __hash__ to Utility and it'll be fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hashability questions

2012-05-14 Thread Christian Heimes
Am 13.05.2012 21:11, schrieb Bob Grommes:
> Noob alert: writing my first Python class library.
> 
> I have a straightforward class called Utility that lives in Utility.py.
> 
> I'm trying to get a handle on best practices for fleshing out a library.  As 
> such, I've done the following for starters:
> 
>   def __str__(self):
> return str(type(self))
> 
> #  def __eq__(self,other):
> #return hash(self) == hash(other)
> 
> The commented-out method is what I'm questioning.  As-is, I can do the 
> following from my test harness:

By the way, that's a dangerous and broken way to implement __eq__(). You
mustn't rely on hash() in __eq__() if you want to use your object in
sets and dicts. You must implement __hash__ and __eq__ in a way that
takes all relevant attributes into account. The attributes must be read
only, otherwise you are going to break sets and dicts.

Here is a best practice example:

class Example(object):
def __init__(self, attr1, attr2):
self._attr1 = attr1
self._attr2 = attr2

@property
def attr1(self):
return self._attr1

@property
def attr2(self):
return self._attr2

def __eq__(self, other):
if not isinstance(other, Example):
return NotImplemented
return (self._attr1 == other._attr1
and self._attr2 == other._attr2)

def __hash__(self):
return hash((self._attr1, self._attr2))

# optional
def __ne__(self, other):
if not isinstance(other, Example):
return NotImplemented
return not self == other






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


Re: Newby Python Programming Question

2012-05-14 Thread Chris Angelico
On Sat, May 12, 2012 at 8:25 AM, Coyote  wrote:
> I've been playing around with a couple of IDEs because I liked the one I used 
> with IDL and I wanted to use something similar for Python. The IDLDE was an 
> Eclipse variant, but I've tried installing Eclipse before for something else 
> and I'm pretty sure I don't need *that* kind of headache on a Friday 
> afternoon. Unless, of course, I need a good excuse to head over to the Rio 
> for the margaritas. :-)

When it comes to IDEs, I've never really gone for any. My current
setup at work (which I convinced my boss to deploy to all our
developers, himself included) is all open-source: SciTE
(Scintilla-based Text Editor) with a few in-house configurations, a
good makefile, and m4 (plus git for source control). SciTE has syntax
highlighting for all the languages we use, and is set to save and
'make' on press of F7, and the makefile handles everything else.
There's a couple of in-house scripts such as a cache-control script
(looks through our HTML and PHP pages for references to .js files and
adds ?tag to them where tag comes from git) and a rapid deployment
handler, but the upshot is that I edit a file, hit F7, and everything
happens for me. That's about as good as any IDE would give, but
without the overhead of most IDEs.

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


Re: Newby Python Programming Question

2012-05-14 Thread Simon Cropper

On 15/05/12 12:18, Chris Angelico wrote:

On Sat, May 12, 2012 at 8:25 AM, Coyote  wrote:

I've been playing around with a couple of IDEs because I liked the one I used 
with IDL and I wanted to use something similar for Python. The IDLDE was an 
Eclipse variant, but I've tried installing Eclipse before for something else 
and I'm pretty sure I don't need *that* kind of headache on a Friday afternoon. 
Unless, of course, I need a good excuse to head over to the Rio for the 
margaritas. :-)


When it comes to IDEs, I've never really gone for any. My current
setup at work (which I convinced my boss to deploy to all our
developers, himself included) is all open-source: SciTE
(Scintilla-based Text Editor) with a few in-house configurations, a
good makefile, and m4 (plus git for source control). SciTE has syntax
highlighting for all the languages we use, and is set to save and
'make' on press of F7, and the makefile handles everything else.
There's a couple of in-house scripts such as a cache-control script
(looks through our HTML and PHP pages for references to .js files and
adds ?tag to them where tag comes from git) and a rapid deployment
handler, but the upshot is that I edit a file, hit F7, and everything
happens for me. That's about as good as any IDE would give, but
without the overhead of most IDEs.

ChrisA


Sorry for responding to you post Chris but I missed Davids post.

David,

I really like SPE IDE - Stani's Python Editor 
(http://pythonide.stani.be/). It and the bundled packages work really 
well. I note it works on Windows, Mac and Linux.


--
Cheers Simon

   Simon Cropper - Open Content Creator / Website Administrator

   Free and Open Source Software Workflow Guides
   
   Introduction   http://www.fossworkflowguides.com
   GIS Packages   http://www.fossworkflowguides.com/gis
   bash / Pythonhttp://www.fossworkflowguides.com/scripting
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hashability questions

2012-05-14 Thread Ian Kelly
On Mon, May 14, 2012 at 7:50 PM, Christian Heimes  wrote:
> Am 13.05.2012 21:11, schrieb Bob Grommes:
>> Noob alert: writing my first Python class library.
>>
>> I have a straightforward class called Utility that lives in Utility.py.
>>
>> I'm trying to get a handle on best practices for fleshing out a library.  As 
>> such, I've done the following for starters:
>>
>>   def __str__(self):
>>     return str(type(self))
>>
>> #  def __eq__(self,other):
>> #    return hash(self) == hash(other)
>>
>> The commented-out method is what I'm questioning.  As-is, I can do the 
>> following from my test harness:
>
> By the way, that's a dangerous and broken way to implement __eq__(). You
> mustn't rely on hash() in __eq__() if you want to use your object in
> sets and dicts. You must implement __hash__ and __eq__ in a way that
> takes all relevant attributes into account. The attributes must be read
> only, otherwise you are going to break sets and dicts.

Why?  I can't see any purpose in implementing __eq__ this way, but I
don't see how it's "broken" (assuming that __hash__ is actually
implemented somehow and doesn't just raise TypeError).  The
requirement is that if two objects compare equal, then they must have
the same hash, and that clearly holds true here.

Can you give a concrete example that demonstrates how this __eq__
method is dangerous and broken?

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


Re: Need to get Tags and Values from Dom

2012-05-14 Thread Stefan Behnel
TommyVee, 15.05.2012 01:51:
> Confused?  That's an understatement.  Part of the problem is that it's been
> a long time since I learned DOM and now I'm trying to cram to get this
> program done.

Thus my recommendation to use ElementTree. Why go the complicated route
when you can just get your code working without having to learn all of this
again?

Stefan

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


Re: specify end of line character for readline

2012-05-14 Thread Ian Kelly
On Fri, May 11, 2012 at 1:32 PM, Jason  wrote:
> Is there any way to specify the end of line character to use in 
> file.readline() ?
>
> I would like to use '\r\n' as the end of line and allow either \r or \n by 
> itself within the line.

In Python 3 you can pass the argument newline='\r\n' to the open
function when you open the file.  I don't know of anything comparable
in Python 2.
-- 
http://mail.python.org/mailman/listinfo/python-list