Re: Dynamic list name from a string

2010-12-28 Thread DevPlayer

# dynamic_named_obj.py
# comp.lang.python
# 2010-12 Dec-28
# Topic: Dynamic list name from a string Options
# attempts to answer OP's question
# DevPlayer  - not a solution I'd use


# TO Original Poster OP:

# Start from the bottom OPTION, the one you requested.
# Work your way up and see how it gets simpler and
# simpler to do what you want. Dynamically named
# references start to look pointless.

# I hope I addressed your question and hopefully shown
# you the right direction and right reasons to avoid
# using dynamically made named references.
# But I could be wrong in your case.


import time

class DataStore(object):
"""A namespace similar to a module global scope."""

#def concatenate( one, two):
#"""Function to concatonate two lists."""
#return list( one + two)

# =
class Animal(object):
"""A base class for no real reason."""
def __init__(self, name):
self.name = name
self.date = time.clock()

# -
class Bear(Animal):
def __init__(self, name):
super(Bear, self).__init__(name)

class BearCub(Bear):
def __init__(self, name):
super(BearCub, self).__init__(name)

# -
class Doe(Animal):
def __init__(self, name):
super(Doe, self).__init__(name)

class Fawn(Doe):
def __init__(self, name):
super(Fawn, self).__init__(name)


# An alternate namespace instead of module global
ns = DataStore()

OPTION = "BETTER YET"

if OPTION == "BETTER YET":
# don't name your lists, just make the global_list and use it
# no intermediary lists needed really.

ns.Animals = [
# -- 1st set of classes
Bear("bob"),
Bear("bill"),
BearCub("obo"),
BearCub("Bill jr."),

# -- 2nd set of classes
Doe("DoeADear"),
Doe("AFemaleDear"),
Fawn("Ray"),
Fawn("Adropof"),
]

for animal in ns.Animals:
kind = animal.__class__.__name__
name = animal.name
date = animal.date
print kind, name, date

# make a sorted, by date, list of bears
old_bears = [obj for obj in ns.Animals if type(obj) is Bear]
old_bears.sort(None, key=lambda animal: animal.date)
ns.bears = old_bears

# or sort all animals by date
animals = [obj for obj in ns.Animals]
animals.sort(None, key=lambda animal: animal.date)

# then get just bears
bears = [obj for obj in animals if type(obj) is Bear]


elif OPTION == "BETTER":
# don't name your lists, trust in checking if objects have
attributes
# that matter

ns.Animals = {
# -- 1st set of classes
"bob": Bear("bob"),
"Bill": Bear("bill"),
"obo": BearCub("obo"),
"Bill jr.": BearCub("Bill jr."),

# -- 2nd set of classes
"DoeADear": Doe("DoeADear"),
"AFemaleDear": Doe("AFemaleDear"),
"Ray": Fawn("Ray"),
"Adropof": Fawn("Adropof"),
}

print ns.Animals['bob'].date

# make a sorted list of objects based on an attribute -like date
# sort by date for just bears
# http://wiki.python.org/moin/HowTo/Sorting
# look at Operator Module Functions too

# make a sorted, by date, list of bears
old_bears = [obj for obj in ns.Animals.values() if type(obj) is
Bear]
old_bears.sort(None, key=lambda animal: animal.date)
ns.bears = old_bears

# or sort all animals by date
animals = [obj for obj in ns.Animals.values()]
animals.sort(None, key=lambda animal: animal.date)

# then get just bears
bears = [obj for obj in animals if type(obj) is Bear]


elif OPTION == "SOSO1":
# alternative to dynamically named references (object attributes)
# Each item in global_dict is a sub dict

ns.Animals = {}
# -- 1st set of classes
ns.Animals[ Bear ] =  {"bob": Bear("bob"), "Bill": Bear("Bill")}
ns.Animals[ BearCub ] = {"obo": BearCub("obo"), "Bill jr.":
Bearcub("Bill jr.")}
# -- 2nd set of classes
ns.Animals[ Doe ] = {"DoeADear": Doe("DoeADear"), "AFemaleDear":
Doe("AFemaleDear")}
ns.Animals[ Fawn ] = {"Ray": Fawn("Ray"), "Adropof":
Fawn("Adropof")}

print ns.Animals[Bear]["bob"].date
print ns.Animals[BearCub]["Bill jr."].date

elif OPTION == "SOSO2":
# alternative to dynamically named references (object attributes)
# don't use names at all -
# Each item in a dict is a list of objects
# use class itself as key (not class name)

ns.Animals = {}
# -- 1st set of classes
ns.Animals[ Bear ] =  [Bear("bob"), Bear("Bill")]
ns.Animals[ BearCub ] = [BearCub("obo"), Bearcub("Bill jr.")]
# -- 2nd set of classes
ns.Animals[ Doe ] = [Doe("DoeADear"), Doe("AFemaleDear")]
ns.Animals[ Fawn ] = [Fawn("Ray"), Fawn("Adropof")]

print ns.Animals[Bear][0].date

elif OPTION == "SOSO3":
# alternative to dynamically named references (object attributes)
# use class __name__ as key

ns.Animals = {}
# 

Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Rami Chowdhury
On Wed, Dec 29, 2010 at 00:45, Christian Heimes  wrote:
> Am 28.12.2010 21:16, schrieb Hrvoje Niksic:
>> Christian Heimes  writes:
>>
>>> Also this code is going to use much more memory than an ordinary tuple
>>> since every instance of InternedTuple has a __dict__ attribute. This
>>> code works but I had to move the cache outside the class because of
>>> __slots__.
>>
>> Wouldn't it work inside the class as well?  __slots__ applies to
>> instances, not to classes themselves.  In Python 3.1:
>
> You are right as long as you don't try to rebind the variable. I
> recalled that class attributes of classes with __slots__ behave slightly
> different than ordinary classes. For example you can't have a writeable
> slot and class default values at the same time.
>
 class Example2(object):
> ...     __slots__ = ()
> ...     _cache = {}
> ...
 Example2()._cache
> {}
 Example2()._cache = {}
> Traceback (most recent call last):
>  File "", line 1, in 
> AttributeError: 'Example2' object attribute '_cache' is read-only

Forgive me if I'm misunderstanding, but if you want to cache instances
of a class, surely

>> Example2()._cache = {}

would defeat the purpose, at least for that instance of Example2? The
slot seems writeable enough, after all

>> Example2()._cache['foo'] = 'bar'

seems to work?


-- 
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
+44-7581-430-517 / +1-408-597-7068 / +88-0189-245544
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Christian Heimes
Am 28.12.2010 21:16, schrieb Hrvoje Niksic:
> Christian Heimes  writes:
> 
>> Also this code is going to use much more memory than an ordinary tuple
>> since every instance of InternedTuple has a __dict__ attribute. This
>> code works but I had to move the cache outside the class because of
>> __slots__.
> 
> Wouldn't it work inside the class as well?  __slots__ applies to
> instances, not to classes themselves.  In Python 3.1:

You are right as long as you don't try to rebind the variable. I
recalled that class attributes of classes with __slots__ behave slightly
different than ordinary classes. For example you can't have a writeable
slot and class default values at the same time.

>>> class Example2(object):
... __slots__ = ()
... _cache = {}
...
>>> Example2()._cache
{}
>>> Example2()._cache = {}
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Example2' object attribute '_cache' is read-only

Christian

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


Re: round in 2.6 and 2.7

2010-12-28 Thread Terry Reedy

On 12/28/2010 4:47 PM, Martin v. Loewis wrote:

"Float-to-string and string-to-float conversions are correctly rounded.
The round() function is also now correctly rounded."


The second line was written to be parallel to the first, but the first 
is slightly ambiguous in that 'conversions' can refer to either process 
(not rounded, correctly or otherwise ;-) or result. However the 
parallelism does not does as 'round() function' is the instrument of the 
process and definitly not the result.


...


I see. Shouldn't it say then "The round() function
gives/produces/returns correctly rounded results now", instead of saying
that
the round function *is* correctly rounded? ISTM that the round
function cannot be rounded (correctly or not):


In 2.7 "Float-to-string and string-to-float conversion results are 
correctly rounded, as are the results of the round() function."


--
Terry Jan Reedy

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


Re: Replacing Greenlets with Threads or Processes

2010-12-28 Thread Nathanael Abbotts
On Tuesday, December 28, 2010 5:04:48 PM UTC, Emile van Sebille wrote:
> On 12/28/2010 8:07 AM Nathanael Abbotts said...
> > That thread seems to deal with mixing them. I want to replace them
> > completely - is that possible (with either threads or processes)?
> 
> Are you working with pycsp?  the info at 
> http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says:
> 
> "The API is implemented in four versions: Threads, processes, greenlets 
> and net. All implementations share an almost identical API making it 
> trivial to switch from one implementation to another. "
> 
> Emile

Unfortunately not. I wish I was! That sounds brilliant. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language Detection Library/Code

2010-12-28 Thread Katie T
On Tue, Dec 28, 2010 at 12:42 AM, Shashwat Anand
 wrote:
> Regarding dictionary lookup+n-gram approach I didn't quite understand what
> you wanted to say.

Run through trigram analysis first, if it identified multiple
languages as being matches within the error margin then split the text
into words, and look up each word in the respective dictionaries to
get a second opinion.

Katie
-- 
CoderStack
http://www.coderstack.co.uk/python-jobs
The Software Developer Job Board
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keeping track of the N largest values

2010-12-28 Thread Miki
> I'm processing a stream of N numbers and want to keep track of the K 
> largest.  There's too many numbers in the stream (i.e. N is too large) 
> to keep in memory at once.  K is small (100 would be typical).
> ...

deque can be bounded by maxsize, might fit the bill:
>>> from collections import deque
>>> d = deque([], 3)
>>> for i in range(10): d.append(i)
>>> d
deque([7, 8, 9], maxlen=3)
>>> 


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


Re: round in 2.6 and 2.7

2010-12-28 Thread Martin v. Loewis
>> "Float-to-string and string-to-float conversions are correctly rounded.
>> The round() function is also now correctly rounded."
>>
>> Not sure that this is correct English; I think it means that the
>> round() function is now correct.
> 
> Well, the correct result of the example the OP gave would be 9.9
> exactly.  But since 9.9 isn't exactly representable as a Python float,
> we necessarily get an approximation.  The language above is intended
> to convey that it's the 'correctly rounded' approximation

I see. Shouldn't it say then "The round() function
gives/produces/returns correctly rounded results now", instead of saying
that
the round function *is* correctly rounded? ISTM that the round
function cannot be rounded (correctly or not):

py> round(round)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: a float is required

But then, I'm not a native speaker (of English).

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


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Hrvoje Niksic
Christian Heimes  writes:

> Also this code is going to use much more memory than an ordinary tuple
> since every instance of InternedTuple has a __dict__ attribute. This
> code works but I had to move the cache outside the class because of
> __slots__.

Wouldn't it work inside the class as well?  __slots__ applies to
instances, not to classes themselves.  In Python 3.1:

>>> class Foo(tuple):
...   __slots__ = ()
...   _cache = {}
... 
>>> Foo._cache# works as expected
{}
>>> Foo()._cache  # and so does this
{}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: O'Reilly Python Certification

2010-12-28 Thread J. Altman
On 2010-12-16, Steve Holden  wrote:
> Each lesson required you to complete a practical assignment. You submit
> these assignments for evaluation, and do not proceed to the next lesson
> until your assignment reaches a satisfactory standard. Thus, less
> experienced students will tend to have more interaction with their tutors.
>
> A class will typically have between twelve and sixteen lessons. There
> are also quizzes and a final practical project.
>
> regards
>  Steve

I have a general question.

Does it seem odd that a certificate in Python, an Open Source
language; taught at O'Reilly, which offers an Open Source Programming
Certificate and is something like waist-deep in Open Source
publishing; is offered to the world at large but only (IIUC) if one
runs some version of Windows by MS?

Based on what I am given to understand from my correspondence with
OST, it seems that I *must* install an instance of Windows to take the
certificate's courses.

Not that I particularly want to bash MS, but I am running FreeBSD, and
have Python 2.x and 3.x installed; I can call either IDE; and I am
competent at the shell, I think sufficiently, to manage coding at the
shell.

Is it normal for people in CS courses at the University and/or
certificate level to learn a given language under Windows?

Or is it just me who thinks it odd that an OS like FreeBSD won't
(apparently, I stress) work with the O'Reilly Sandbox?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread John Nagle

On 12/27/2010 3:05 AM, Ulrich Eckhardt wrote:

Hi!

I'm trying to solve a computational problem and of course speed and size is
important there.


Then you probably shouldn't be using CPython.


Apart from picking the right algorithm, I came across an
idea that could help speed up things and keep memory requirements down. What
I have is regions described by min and max coordinates. At first, I just
modeled these as a simple class containing two values for each axis.


There are more effective techniques for that.  In game physics
collision detection systems, it's common to use axis-ordered lists
of bounding boxes to partition objects.  This still works even when
the ranges overlap.  Look up "I-Collide" for a classic implementation.

> Am I looking in the wrong direction? Is there some better approach?
> Please
> don't tell me to use C, as I'm specifically interested in
> learning Python,
> I'm pretty sure I could have solved the problem quickly in
> C++ otherwise.

CPython is a naive interpreter which does dictionary
lookups for every variable and attribute access.  If you're doing
fast manipulation of linked data structures in CPython, performance
is going to suck.

Check out Shed Skin 0.7, which is a much faster Python
system.  It's limited, but for the kind of data structure work
you're doing, all the features you should need already work.

John Nagle


In a second step, I derived this class from tuple instead of object. Some
code then moved from __init__ to __new__ and some code that modified these
objects had to be changed to replace them instead. The upside to this is
that they can be used as keys in sets and dicts, which isn't the case for
mutable types[1].

What I'm now considering is to only allow a single instance of these objects
for each set of values, similar to interned strings. What I would gain is
that I could safely compare objects for identity instead of equality. What
I'm not yet sure is how much overhead that would give me and/or how to keep
it low. The idea is to store each instance in a set and after creating a new
object I would first look up an equal object in the global set and return
that instead, otherwise add the new one.

The problem I foresee is that if I define equality as identity, this lookup
when creating will never eliminate duplicates. If I only fall back to
equality comparison for non-identical objects, I would probably sacrifice
most of the gain. If I build a dict mapping between the values and the
actual objects, I would have doubled the required memory and uselessly store
the same values twice there.


Cheers!

Uli


[1] Somebody correct me if I'm wrong, but I believe I could have defined a
hashing function for the type and thus allowed its use in a set or dict,
right? However, goofing up because you accidentally modified an object and
changed its hash value is something I don't want to risk anyway.



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


Re: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA)

2010-12-28 Thread Anurag Chourasia
Dear all,

I am required to use the Private Key from that XML below to generate a
digital signature.

The public key can then be used to validate the generated signature.

http://stuvel.eu/rsa does not support PKCS#1 and hence I am required to look
for alternates.

Please let me know if there is something else out there that could help meet
my requirement.

Regards,
Anurag

On Tue, Dec 28, 2010 at 6:36 AM, Adam Tauno Williams  wrote:

> On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote:
> > Hi All,
>
> > I have a requirement to digitally sign a XML Document using SHA1+RSA
> > or SHA1+DSA
> > Could someone give me a lead on a library that I can use to fulfill
> > this requirement?
>
>   Never used it though.
>
> > The XML Document has values such as
> > -BEGIN RSA PRIVATE KEY-
> > MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ
> > n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG
> > 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT
> > AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s
> > AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd
> > g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc
> > Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -END RSA PRIVATE
> > KEY-
> > -BEGIN PUBLIC KEY-
> > MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu
> > w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -END
> > PUBLIC KEY-
>
> Is this any kind of standard or just something someone made up?  Is
> there a namespace for the document?
>
> It seems quite odd that the document contains a *private* key.
>
> If all you need to do is parse to document to retrieve the values that
> seems straight-forward enough.
>
> > And the XML also has another node that has a Public Key with Modules
> > and Exponents etc that I apparently need to utilize.
> > 
> >   1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD
> > +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ==
> >   Aw==
> > 
>
> > I am a little thin on this concept and expecting if you could guide me
> > to a library/documentation that I could utilize.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to programmatically exit from wsgi's serve_forever() loop

2010-12-28 Thread python
Hi Ian,

You are correct - I missed the following 2 nuances:

# need to set poll_interval in order to recognize shutdown request
httpd.serve_forever(poll_interval=0.5)

# shutdown request must be initiated from ANOTHER thread or will block
import threading
threading.Thread(target=httpd.shutdown).start()

Thank you for your help - really appreciated!

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


Re: Replacing Greenlets with Threads or Processes

2010-12-28 Thread Emile van Sebille

On 12/28/2010 8:07 AM Nathanael Abbotts said...

That thread seems to deal with mixing them. I want to replace them
completely - is that possible (with either threads or processes)?


Are you working with pycsp?  the info at 
http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says:


"The API is implemented in four versions: Threads, processes, greenlets 
and net. All implementations share an almost identical API making it 
trivial to switch from one implementation to another. "


Emile

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


Re: mutiprocessing, manager, list & threading ?

2010-12-28 Thread John Nagle

On 12/28/2010 1:38 AM, mika.sa...@wipsl.com wrote:

Hi,

   Testing if I could be able to use multiprocessing BaseManager to manage
list of instance pointers between processes. If my intance inherits
Thread, I get pickling error about _thread.lock.


The "multiprocessing" module works by running completely separate
programs which communicate by copying data back and forth through
pipes or sockets.  You can't share thread locks.  (There's a gimmick
that lets you put an array of fixed type and size in shared memory,
but that's very limited, because Python's locking doesn't really
understand multiprocessing.)

If you need to access a list from several processes, have
one process own the list, and use a Manager from the multiprocessing
module to create a proxy to access the list from the other processes.
Note that this is slower than regular list access.  But if you just
need to have a to-do list that feeds multiple processes, that's a way
to do it.

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


Re: Replacing Greenlets with Threads or Processes

2010-12-28 Thread Nathanael Abbotts
That thread seems to deal with mixing them. I want to replace them completely - 
is that possible (with either threads or processes)?

Some loss of functionality isn't a problem, as the code only seems to use the 
most basic features of Greenlets.

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


Re: Trying to parse a HUGE(1gb) xml file

2010-12-28 Thread Roy Smith
In article ,
 "BartC"  wrote:

> Still, that's 27 times as much as it need be. Readability is fine, but why
> does the full, expanded, human-readable textual format have to be stored on
> disk too, and for every single instance?

Well, I know the answer to that one.  The particular XML feed I'm 
working with is a dump from an SQL database.  The element names in the 
XML are exactly the same as the column names in the SQL database.

The difference being that in the database, the string 
"Parental-Advisory" appears in exactly one place, in some schema 
metadata table.  In the XML, it appears (doubled!) once per row.

It's still obscene.  That fact that I understand the cause of the 
obscenity doesn't make it any less so.

Another problem with XML is that some people don't use real XML tools to 
write their XML files.  DTD?  What's that?  So you end up with tag soup 
that the real XML tools can't parse on the other end.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing Greenlets with Threads or Processes

2010-12-28 Thread Nathanael Abbotts
Processes are better for me - the application is already multiprocessing based.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to parse a HUGE(1gb) xml file

2010-12-28 Thread Sherm Pendley
"BartC"  writes:

>> Roy Smith, 28.12.2010 00:21:
>>> To go back to my earlier example of
>>>
>>>  FALSE
>>>
>
> Isn't it possible for XML to define a shorter alias for these tags? Isn't
> there a shortcut available for  in simple examples like
> this (I seem to remember something like this)?

Yes, you can define your own entities in a DTD:

  FALSE">
  TRUE">

Later, in your document:

  &paf;
  &pat;

Although, this is a bit of a contrived example - if space is such a
major concern, one wouldn't be so wasteful of it to begin with, but
might instead use a short tag form whose value attribute defaults to
"FALSE".

  
  

Later, in your document:

  
  

To save even more space, one could instead define a "pa" attribute as
part of the "movie" element, with a default value that would then take
no space at all:

  

Later, in your document:

  
  

When you see someone doing stupid things with a tool, it's usually not
the tool's fault. Far more often, it's someone using the wrong tool for
the task at hand, or using the right tool the wrong way.

> And why not use 1 and 0 for TRUE and FALSE?

Sounds reasonable in general, although a parental advisory would more
often be a range of possible values (G, PG, R, MA, etc.) rather than a
boolean.

sherm--

-- 
Sherm Pendley
   
Cocoa Developer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing Greenlets with Threads or Processes

2010-12-28 Thread Emile van Sebille

On 12/28/2010 6:59 AM Nathanael Abbotts said...

I need to replace the use of 'greenlets' in an application with threads or 
processes, but as I've never used greenlets, I don't know where to start when 
replacing them.
Could anyone explain to me how I can do this?


Looks like your choice may be limited to processes...

http://groups.google.com/group/pycsp/browse_thread/thread/45209957e27e0293/b67445b092872750?q=python+greenlets

Emile

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


hi

2010-12-28 Thread phani indra

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


Re: while True or while 1

2010-12-28 Thread Francesco

hehehehehehe...

On 17/12/2010 2.01, Steven D'Aprano wrote:

On Thu, 16 Dec 2010 23:34:21 +, BartC wrote:


In terms of a more realistic function (admittedly still a little
contrived, as the loop would be written differently), I tried this:

def p2(n):
   p=1
   while True:
 if n<=p: return p
 p<<=1
   return 0

for i in xrange(100):
   x=p2(i)

p2() calculates the smallest power of 2>= it's operand.

Using while True as shown, it took 3.4 seconds. Using While 1, it took
2.6 seconds (Python 2.5).



Right. And a saving of 0.8 microseconds per iteration is a micro-
optimization which is likely to be invisible in any real situation.

I mean, yes, you saved almost an entire second. Wow. Save another 179 of
them and you'll almost have enough time to make yourself a coffee.

Bart, we get it. Nobody denies that the optimization is real, only that
it is generally meaningful. Who cares whether it takes 2 seconds or 4
seconds to generate one million results if the rest of the application
takes 3 minutes to run?

*If* your application is such that saving 0.8 microseconds per iteration
actually is useful, AND your loop has to be written as a while True loop,
then this *may* be a useful micro-optimization to save 0.8 microseconds
per iteration. That's a vanishingly tiny proportion of all code written.
If your code happens to meet those conditions, then by all means use
"while 1". Or move to Python 3, where "while True" has the same
optimization performed.

But in general, such micro-optimizations are not terribly useful. If you
shave off 1 second off a program that runs in 3 seconds, chances are
nobody is even going to notice. Two seconds or three, who cares? Either
way, it's too short to do anything else, and not long enough to matter.
If you shave off an hour off a program that takes 20 hours, who is going
to care?

But so long as it doesn't introduce bugs, or make maintenance harder, or
add complexity, such micro-optimizations don't harm either.



HEY! That was MY argument! ;-))

Newsgroups: comp.lang.python
Subject: Re: If/then style question
Date: Tue, 21 Dec 2010 20:54:02 +0100

I'd bet you would stress your point Steven! But you don't need to persuade me, 
I do already agree.
I just meant to say that, when the advantage is little, there's no need to 
rewrite a working function.
And that with modern CPUs, if tests take so little time, that even some 
redundant one is not so much of a nuisance.
in your working example, the "payload" is just a couple of integer calculations, that take very little time too. So the overhead due 
to redundant if tests does show clearly. And also in that not-really-real situation, 60% overhead just meant less than 3 seconds. 
Just for the sake of discussion, I tried to give both functions some plough to pull, and a worst-case situation too:


>>> t1 = Timer('for x in range(100): print func1(0),',
...  'from __main__ import func1')
>>>
>>> t2 = Timer('for x in range(100): print func2(0),',
...  'from __main__ import func2')
>>>
>>> min(t1.repeat(number=1, repeat=1))
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
53.011015366479114
>>> min(t2.repeat(number=1, repeat=1))
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
47.55442856564332

that accounts for a scant 11% overhead, on more than one million tests per 
cycle.

That said,  let's make really clear that I would heartily prefer func2 to func1, based both on readability and speed. Thank you for 
having spent some time playing with me!

Francesco

On 19/12/2010 1.05, Steven D'Aprano wrote:
> Well, let's try it with a working (albeit contrived) example. This is
> just an example -- obviously I wouldn't write the function like this in
> real life, I'd use a while loop, but to illustrate the issue it will do.
>
> def func1(n):
>  result = -1
>  done = False
>  n = (n+1)//2
>  if n%2 == 1:
>  result = n
>  done = True
>  if not done:
>  n = (n+1)//2
>  if n%2 == 1:
>  result = n
>  done = True
>  if not done:
>  n = (n+1)//2
>  if n%2 == 1:
>  result = n
>  done = True
>  if not done:
>  for i in range(100):
>  if not done:
>  n = (n+1)//2
>  if n%2 == 1:
>  result = n
>  done = True
>  return result
>
>
> def func2(n):
>  n = (n+1)//2
>  if n%2 == 1:
>  return n
>  n = (n+1)//2
>  

Replacing Greenlets with Threads or Processes

2010-12-28 Thread Nathanael Abbotts
I need to replace the use of 'greenlets' in an application with threads or 
processes, but as I've never used greenlets, I don't know where to start when 
replacing them. 
Could anyone explain to me how I can do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Christian Heimes
Am 28.12.2010 15:11, schrieb Steven D'Aprano:
> # Untested
> class InternedTuple(tuple):
> _cache = {}
> def __new__(cls, *args):
> t = super().__new__(cls, *args) 
> return cls._cache.setdefault(args, t)
> def __eq__(self, other):
> return self is other
> def __ne__(self, other):
> return self is not other

The code doesn't work, you have to change super().__new__(cls, *args) to
super().__new__(cls, args). Don't ask me why. I'm surprised, too.

>>> InternedTuple(1)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in __new__
TypeError: 'int' object is not iterable


Also this code is going to use much more memory than an ordinary tuple
since every instance of InternedTuple has a __dict__ attribute. This
code works but I had to move the cache outside the class because of
__slots__.

_ituple_cache = {}

class ituple(tuple):
__slots__ = () # no __dict__

def __new__(cls, *args):
cached = _ituple_cache.get(args)
if cached is not None:
return cached
self = _ituple_cache[args] = super(ituple, cls).__new__(cls, args)
return self

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


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Stefan Behnel

Steven D'Aprano, 28.12.2010 15:11:

On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote:


Steven D'Aprano wrote:

class InternedTuple(tuple):

... _cache = {}
... def __new__(cls, *args):
... t = super().__new__(cls, *args)
... return cls._cache.setdefault(t, t)


That looks good. The only thing that first bothered me is that it
creates an object and then possibly discards it again. However, there is
no way around that, since at least the key to the dict must be created
for lookup. Since key and value are the same here, this is even for
free.

What I also found was that with the above, I can't provide __eq__ and
__ne__ that just check for identity. If I do, the lookup in setdefault()
will never find an existing tuple and I will never save memory for a
single object.


If all you want is to save memory, you don't need to change the __eq__
method. But if you still want to, try this:

# Untested


Yep, that' the problem. ;)



class InternedTuple(tuple):
 _cache = {}
 def __new__(cls, *args):
 t = super().__new__(cls, *args)
 return cls._cache.setdefault(args, t)
 def __eq__(self, other):
 return self is other
 def __ne__(self, other):
 return self is not other


What Ulrich meant, was: doing this will actually kill the caching, because 
the first time the comparison is called is when looking up the tuple while 
adding it to the interning dict. Since the new tuple is, well, new, it will 
not be equal (read: identical) to any cached tuple, thus resulting in a new 
entry regardless of its content.


Stefan

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


Re: NameError: global name 'btn_Matlab' is not defined ?

2010-12-28 Thread Steven D'Aprano
On Tue, 28 Dec 2010 14:34:19 +0100, Stef Mientki wrote:

> hello,
> 
> Never seen this before and I've no explanation whatsoever (Python 2.6)
> 
> I've some dynamic generated code,
> one of objects generated is a wx.Button, called 'btn_Matlab'.

How do you generate the code?

What code is generated? What does it do?


> After the code is generated, I can see that the button is created in the
> local namespace
>  
>print locals()['btn_Matlab']
> 
>  0x3602d28> >
> 
> but if I try to print the button (at exactly the same location), I get
> an error
> 
> print btn_Matlab
> 
> NameError: global name 'btn_Matlab' is not defined ?
> 
> Why isn't the compiler first checking the local namespace ? any clues ?


My guess is that you've declared btn_Matlab as global, and then 
dynamically created a local with the same name using exec or similar.



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


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Steven D'Aprano
On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote:

> Steven D'Aprano wrote:
> class InternedTuple(tuple):
>> ... _cache = {}
>> ... def __new__(cls, *args):
>> ... t = super().__new__(cls, *args) 
>> ... return cls._cache.setdefault(t, t)
> 
> That looks good. The only thing that first bothered me is that it
> creates an object and then possibly discards it again. However, there is
> no way around that, since at least the key to the dict must be created
> for lookup. Since key and value are the same here, this is even for
> free.
> 
> What I also found was that with the above, I can't provide __eq__ and
> __ne__ that just check for identity. If I do, the lookup in setdefault()
> will never find an existing tuple and I will never save memory for a
> single object.

If all you want is to save memory, you don't need to change the __eq__ 
method. But if you still want to, try this:


# Untested
class InternedTuple(tuple):
_cache = {}
def __new__(cls, *args):
t = super().__new__(cls, *args) 
return cls._cache.setdefault(args, t)
def __eq__(self, other):
return self is other
def __ne__(self, other):
return self is not other



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


NameError: global name 'btn_Matlab' is not defined ?

2010-12-28 Thread Stef Mientki
hello,

Never seen this before and I've no explanation whatsoever (Python 2.6)

I've some dynamic generated code,
one of objects generated is a wx.Button, called 'btn_Matlab'.

After the code is generated, I can see that the button is created in the local 
namespace
 
   print locals()['btn_Matlab']

 >

but if I try to print the button (at exactly the same location), I get an error

print btn_Matlab

NameError: global name 'btn_Matlab' is not defined ?

Why isn't the compiler first checking the local namespace ?
any clues ?

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


Re: etl tool!!!!!

2010-12-28 Thread Adam Tauno Williams
On Tue, 2010-12-28 at 07:57 -0500, krishna kumar wrote:
> Is there any efficient etl tool developed in python? 

What does "efficient" mean to you?

I work on a Python workflow solution that I use to do ETL.



-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: etl tool!!!!!

2010-12-28 Thread Stefan Sonnenberg-Carstens

Am 28.12.2010 13:57, schrieb krishna kumar:

Is there any efficient etl tool developed in python?

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


etl tool!!!!!

2010-12-28 Thread krishna kumar
Is there any efficient etl tool developed in python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to parse a HUGE(1gb) xml file

2010-12-28 Thread BartC



"Stefan Behnel"  wrote in message
news:mailman.335.1293516506.6505.python-l...@python.org...

Roy Smith, 28.12.2010 00:21:

To go back to my earlier example of

 FALSE

using 432 bits to store 1 bit of information, stuff like that doesn't
happen in marked-up text documents.  Most of the file is CDATA (do they
still use that term in XML, or was that an SGML-ism only?).  The markup
is a relatively small fraction of the data.  I'm happy to pay a factor
of 2 or 3 to get structured text that can be machine processed in useful
ways.  I'm not willing to pay a factor of 432 to get tabular data when
there's plenty of other much more reasonable ways to encode it.


If the above only appears once in a large document, I don't care how much
space it takes. If it appears all over the place, it will compress down to
a couple of bits, so I don't care about the space, either.

It's readability that counts here. Try to reverse engineer a binary format
that stores the above information in 1 bit.


The above typically won't get much below 2 bytes (as one character plus a
separator, eg. in comma-delimited-format). So it's more like 27:1, if you're
going to stay with a text format.

Still, that's 27 times as much as it need be. Readability is fine, but why
does the full, expanded, human-readable textual format have to be stored on
disk too, and for every single instance?

What if the 'Parental-Advisory' tag was even longer? Just how long do these
things have to get before even the advocates here admit that it's getting
ridiculous?

Isn't it possible for XML to define a shorter alias for these tags? Isn't
there a shortcut available for  in simple examples like
this (I seem to remember something like this)?

And why not use 1 and 0 for TRUE and FALSE? Even the consumer appliances in
my house have 1 and 0 on their power switches! With the advantage that they 
are internationally recognised.


--
Bartc 


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


Re: Python - NAWIT / Community

2010-12-28 Thread Steven D'Aprano
On Tue, 28 Dec 2010 04:10:15 -0800, flebber wrote:

> Tony Robbins "Acheiving a goal is simple, decide what your goal is, set
> out towards it and consistently review whether you are getting closer or
> further from your goal and take action immediately."

Writing bug-free code is simple: decide what you want your code to do, 
write code to do it, and consistently review whether you are getting more 
or fewer bugs, and take action immediately.


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


Re: Interning own classes like strings for speed and size?

2010-12-28 Thread Ulrich Eckhardt
Steven D'Aprano wrote:
 class InternedTuple(tuple):
> ... _cache = {}
> ... def __new__(cls, *args):
> ... t = super().__new__(cls, *args)
> ... return cls._cache.setdefault(t, t)

That looks good. The only thing that first bothered me is that it creates an 
object and then possibly discards it again. However, there is no way around 
that, since at least the key to the dict must be created for lookup. Since 
key and value are the same here, this is even for free.

What I also found was that with the above, I can't provide __eq__ and __ne__ 
that just check for identity. If I do, the lookup in setdefault() will never 
find an existing tuple and I will never save memory for a single object.


Thanks!

Uli

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


Re: Python - NAWIT / Community

2010-12-28 Thread flebber
On Dec 28, 11:10 pm, flebber  wrote:
> On Dec 28, 10:37 pm, Adam Tauno Williams 
> wrote:
>
>
>
> > On Tue, 2010-12-28 at 03:24 -0800, flebber wrote:
> > > On Dec 28, 10:16 pm, Adam Tauno Williams 
> > > wrote:
> > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote:
> > > > > Is pydev actively being developed and for who? SPE is a great idea but
> > > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus
> > > > > none of these projects seem community centric.
> > > > Why not just check the repo and see the real answer for yourself?  It is
> > > > Open Source after all.
> > > > 
> > > Yes you can answer questions, but have you really? Your answer seems
> > > to be things are open source so who cares about community.
> > > > Many projects accept donations via PayPal.  Sourceforge supports this.
> > > Of course any fool can throw his/her money away thats no challenge why
> > > even use Paypal, I could have fun and by 10 bottles of vino and hand
> > > them out to recovering alcoholics.
> > > Don't answer things just for the sake of it, if you have nothing
> > > producive to say about furthering python and its community then say
> > > that.
>
> > I provided two concrete points, thank you:
>
> > (1) Is a project actively developed?  Look at the repo. That is the
> > answer to the question [this isn't necessarily obvious to those new to
> > Open Source].
> > (1.1.) "Is PyDev a potential unifying force amoung IDEs?"  Which is the
> > implied question - that is up to the OP and others who do/do-not
> > contribute to it.
> > (2) How can I donate cash? There is a fairly standard mechanism for
> > that.
>
> > Otherwise I think the OP's thoughts on "community" and how Open Source
> > works are somewhat flawed.  "Community" is a manifestation of people
> > *doing* things; it does *not* arise out of people being concerned about
> > things [since "doing" is quite apparently not a natural result of
> > "concern". Concern is like watching TV.  Doing is getting out of the
> > chair.]
>
> Fair point.
>
> You have mistaken somewhat what I intended, partly my fault due to the
> verbosity. I wanted gaugue feedback on others perception of the
> current status quo. I am happy personally currently, currently being
> the main word.
>
> "Community" is a manifestation of people
>
> > *doing* things; it does *not* arise out of people being concerned about
> > things
>
> But concern is derived from interaction and observation and like fear
> and joy tells us we need to take an action. If someone chooses to sir
> idly by good for them I haven't the time or inclination personally.
>
> Tony Robbins "Acheiving a goal is simple, decide what your goal is,
> set out towards it and consistently review whether you are getting
> closer or further from your goal and take action immediately."
>
> From a language perspective going to python 3 this definitely seems to
> be occurring well and strongly lead.
>
> Sometimes the fault in open source is the lack of a crystalized and
> shared goal and proper infrastructure.Gentoo as an example. Could
> get to they were going because they didn't share the same vision of
> what it was.
>
> I meant no attack by reviewing, just a somewhat newbies observations
> of python.

Edit Gentoo couldn't get to where they were going because of lack of
vision and a shared goal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python - NAWIT / Community

2010-12-28 Thread flebber
On Dec 28, 10:37 pm, Adam Tauno Williams 
wrote:
> On Tue, 2010-12-28 at 03:24 -0800, flebber wrote:
> > On Dec 28, 10:16 pm, Adam Tauno Williams 
> > wrote:
> > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote:
> > > > Is pydev actively being developed and for who? SPE is a great idea but
> > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus
> > > > none of these projects seem community centric.
> > > Why not just check the repo and see the real answer for yourself?  It is
> > > Open Source after all.
> > > 
> > Yes you can answer questions, but have you really? Your answer seems
> > to be things are open source so who cares about community.
> > > Many projects accept donations via PayPal.  Sourceforge supports this.
> > Of course any fool can throw his/her money away thats no challenge why
> > even use Paypal, I could have fun and by 10 bottles of vino and hand
> > them out to recovering alcoholics.
> > Don't answer things just for the sake of it, if you have nothing
> > producive to say about furthering python and its community then say
> > that.
>
> I provided two concrete points, thank you:
>
> (1) Is a project actively developed?  Look at the repo. That is the
> answer to the question [this isn't necessarily obvious to those new to
> Open Source].
> (1.1.) "Is PyDev a potential unifying force amoung IDEs?"  Which is the
> implied question - that is up to the OP and others who do/do-not
> contribute to it.
> (2) How can I donate cash? There is a fairly standard mechanism for
> that.
>
> Otherwise I think the OP's thoughts on "community" and how Open Source
> works are somewhat flawed.  "Community" is a manifestation of people
> *doing* things; it does *not* arise out of people being concerned about
> things [since "doing" is quite apparently not a natural result of
> "concern". Concern is like watching TV.  Doing is getting out of the
> chair.]

Fair point.

You have mistaken somewhat what I intended, partly my fault due to the
verbosity. I wanted gaugue feedback on others perception of the
current status quo. I am happy personally currently, currently being
the main word.

"Community" is a manifestation of people
> *doing* things; it does *not* arise out of people being concerned about
> things

But concern is derived from interaction and observation and like fear
and joy tells us we need to take an action. If someone chooses to sir
idly by good for them I haven't the time or inclination personally.

Tony Robbins "Acheiving a goal is simple, decide what your goal is,
set out towards it and consistently review whether you are getting
closer or further from your goal and take action immediately."

>From a language perspective going to python 3 this definitely seems to
be occurring well and strongly lead.

Sometimes the fault in open source is the lack of a crystalized and
shared goal and proper infrastructure.Gentoo as an example. Could
get to they were going because they didn't share the same vision of
what it was.

I meant no attack by reviewing, just a somewhat newbies observations
of python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to parse a HUGE(1gb) xml file

2010-12-28 Thread Adam Tauno Williams
On Tue, 2010-12-28 at 07:08 +0100, Stefan Behnel wrote:
> Roy Smith, 28.12.2010 00:21:
> > To go back to my earlier example of
> >  FALSE
> > using 432 bits to store 1 bit of information, stuff like that doesn't
> > happen in marked-up text documents.  Most of the file is CDATA (do they
> > still use that term in XML, or was that an SGML-ism only?).  The markup
> > is a relatively small fraction of the data.  I'm happy to pay a factor
> > of 2 or 3 to get structured text that can be machine processed in useful
> > ways.  I'm not willing to pay a factor of 432 to get tabular data when
> > there's plenty of other much more reasonable ways to encode it.
> If the above only appears once in a large document, I don't care how much 
> space it takes. If it appears all over the place, it will compress down to 
> a couple of bits, so I don't care about the space, either.

+1

> It's readability that counts here. Try to reverse engineer a binary format 
> that stores the above information in 1 bit.

I think a point many of the arguments against XML miss is the HR cost of
custom solutions.  Every time you come up with a cool super-efficient
solution it has to be weighed against the increase in the tool-stack
[whereas XML is, essentially, built-in] and
nobody-else-knows-about-your-super-cool-solution [1].  IMO, tool-stack
bloat is a *big* problem in shops with an Open Source tendency.  Always
tossing the new and shiny thing [it's free!] into the bucket for some
theoretical benefit. [This is an unrecognized benefit to expensive
software - it creates focus].  Soon the bucket is huge and maintaining
it becomes a burden.

[1] The odds you sufficiently documented your super-cool-solution is
probably nil.

So I'm one of those you'd have to make a *really* good argument *not* to
use XML.  XML is known, the tools are good, the knotty problems are
solved [thanks to the likes of SAX, lxml / ElementTree, and
ElementFlow].  If the premise argument is "bloat" I'd probably dismiss
it out of hand since removing that bloat will necessitate adding bloat
somewhere else; that somewhere else almost certainly being more
expensive.

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


Re: Python - NAWIT / Community

2010-12-28 Thread Adam Tauno Williams
On Tue, 2010-12-28 at 03:24 -0800, flebber wrote:
> On Dec 28, 10:16 pm, Adam Tauno Williams 
> wrote:
> > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote:
> > > Is pydev actively being developed and for who? SPE is a great idea but
> > > is Stan still developing? Pyscripter is good but not 64 capable. Plus
> > > none of these projects seem community centric.
> > Why not just check the repo and see the real answer for yourself?  It is
> > Open Source after all.
> > 

> Yes you can answer questions, but have you really? Your answer seems
> to be things are open source so who cares about community.
> > Many projects accept donations via PayPal.  Sourceforge supports this.
> Of course any fool can throw his/her money away thats no challenge why
> even use Paypal, I could have fun and by 10 bottles of vino and hand
> them out to recovering alcoholics.
> Don't answer things just for the sake of it, if you have nothing
> producive to say about furthering python and its community then say
> that.

I provided two concrete points, thank you:

(1) Is a project actively developed?  Look at the repo. That is the
answer to the question [this isn't necessarily obvious to those new to
Open Source].
(1.1.) "Is PyDev a potential unifying force amoung IDEs?"  Which is the
implied question - that is up to the OP and others who do/do-not
contribute to it.
(2) How can I donate cash? There is a fairly standard mechanism for
that.

Otherwise I think the OP's thoughts on "community" and how Open Source
works are somewhat flawed.  "Community" is a manifestation of people
*doing* things; it does *not* arise out of people being concerned about
things [since "doing" is quite apparently not a natural result of
"concern". Concern is like watching TV.  Doing is getting out of the
chair.]


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


Re: Python - NAWIT / Community

2010-12-28 Thread flebber
On Dec 28, 10:24 pm, flebber  wrote:
> On Dec 28, 10:16 pm, Adam Tauno Williams 
> wrote:
>
>
>
> > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote:
> > > Can't help thinking they open sourced Pydev so they could bench it.
>
> > So?  That isn't uncommon at all;  to Open Source when you've moved on.
>
> > > I started thinking that the only consistent env each python person has
> > > is idle as it ships in the install.
>
> > There is a plethora of Python IDE's [personally I use Monodevelop, which
> > supports Python, and is fast and stable].
>
> > > Sometimes we can contribute with money and sometimes with time, if I
> > > was to contribute money to ensure that I and all new coming python
> > > programmers could have a first class development environment to use
> > > what would I donate to? At the moment no particular group seems
> > > applicable.
>
> > Many projects accept donations via PayPal.  Sourceforge supports this.
>
> > > Is pydev actively being developed and for who? SPE is a great idea but
> > > is Stan still developing? Pyscripter is good but not 64 capable. Plus
> > > none of these projects seem community centric.
>
> > Why not just check the repo and see the real answer for yourself?  It is
> > Open Source after all.
> > 
>
> > > Maybe its just my wish, maybe something already exists, but to my mind
> > > why is there not a central python community ide or plugin setup like
> > > pydev or using pydev(since currently it is very good - to me), which I
> > > know or at least could confidently donate time or money to further
> > > python.
>
> > You could checkout the code of any Python IDE and hack on it.
>
> > > I think a community plugin architecture which contained components
> > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a
> > > place I can contribute time as my skills grow and confidently donate
> > > money knowing I am assisting the development of community tools and
> > > packages we all can use.
>
> > So just do it.
>
> Yes you can answer questions, but have you really? Your answer seems
> to be things are open source so who cares about community.
>
> > Many projects accept donations via PayPal.  Sourceforge supports this.
>
> Of course any fool can throw his/her money away thats no challenge why
> even use Paypal, I could have fun and by 10 bottles of vino and hand
> them out to recovering alcoholics.
>
> Don't answer things just for the sake of it, if you have nothing
> producive to say about furthering python and its community then say
> that.

My apologise I didn't mean to be that aggressive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python - NAWIT / Community

2010-12-28 Thread flebber
On Dec 28, 10:16 pm, Adam Tauno Williams 
wrote:
> On Tue, 2010-12-28 at 02:26 -0800, flebber wrote:
> > Can't help thinking they open sourced Pydev so they could bench it.
>
> So?  That isn't uncommon at all;  to Open Source when you've moved on.
>
> > I started thinking that the only consistent env each python person has
> > is idle as it ships in the install.
>
> There is a plethora of Python IDE's [personally I use Monodevelop, which
> supports Python, and is fast and stable].
>
> > Sometimes we can contribute with money and sometimes with time, if I
> > was to contribute money to ensure that I and all new coming python
> > programmers could have a first class development environment to use
> > what would I donate to? At the moment no particular group seems
> > applicable.
>
> Many projects accept donations via PayPal.  Sourceforge supports this.
>
> > Is pydev actively being developed and for who? SPE is a great idea but
> > is Stan still developing? Pyscripter is good but not 64 capable. Plus
> > none of these projects seem community centric.
>
> Why not just check the repo and see the real answer for yourself?  It is
> Open Source after all.
> 
>
> > Maybe its just my wish, maybe something already exists, but to my mind
> > why is there not a central python community ide or plugin setup like
> > pydev or using pydev(since currently it is very good - to me), which I
> > know or at least could confidently donate time or money to further
> > python.
>
> You could checkout the code of any Python IDE and hack on it.
>
> > I think a community plugin architecture which contained components
> > like pydev, pyscripter, eclipse and eggs/pypm packages would give a
> > place I can contribute time as my skills grow and confidently donate
> > money knowing I am assisting the development of community tools and
> > packages we all can use.
>
> So just do it.

Yes you can answer questions, but have you really? Your answer seems
to be things are open source so who cares about community.

> Many projects accept donations via PayPal.  Sourceforge supports this.

Of course any fool can throw his/her money away thats no challenge why
even use Paypal, I could have fun and by 10 bottles of vino and hand
them out to recovering alcoholics.

Don't answer things just for the sake of it, if you have nothing
producive to say about furthering python and its community then say
that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python - NAWIT / Community

2010-12-28 Thread Adam Tauno Williams
On Tue, 2010-12-28 at 02:26 -0800, flebber wrote:
> Can't help thinking they open sourced Pydev so they could bench it. 

So?  That isn't uncommon at all;  to Open Source when you've moved on.

> I started thinking that the only consistent env each python person has
> is idle as it ships in the install.

There is a plethora of Python IDE's [personally I use Monodevelop, which
supports Python, and is fast and stable].

> Sometimes we can contribute with money and sometimes with time, if I
> was to contribute money to ensure that I and all new coming python
> programmers could have a first class development environment to use
> what would I donate to? At the moment no particular group seems
> applicable.

Many projects accept donations via PayPal.  Sourceforge supports this.

> Is pydev actively being developed and for who? SPE is a great idea but
> is Stan still developing? Pyscripter is good but not 64 capable. Plus
> none of these projects seem community centric.

Why not just check the repo and see the real answer for yourself?  It is
Open Source after all.


> Maybe its just my wish, maybe something already exists, but to my mind
> why is there not a central python community ide or plugin setup like
> pydev or using pydev(since currently it is very good - to me), which I
> know or at least could confidently donate time or money to further
> python.

You could checkout the code of any Python IDE and hack on it.

> I think a community plugin architecture which contained components
> like pydev, pyscripter, eclipse and eggs/pypm packages would give a
> place I can contribute time as my skills grow and confidently donate
> money knowing I am assisting the development of community tools and
> packages we all can use.

So just do it.

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


Python - NAWIT / Community

2010-12-28 Thread flebber
I just wanted to put out a question about IDE's but this is NAWIT -
not another which ide thread.

My question relates to community contribution. My concern arose when
recently installing the pydev.org extensions in Eclipse. Now as far as
my understanding goes the licensing on both is open source GPL.
However Pydev became open source as part of aptana's acquistion, and
for the moment pydev can be installed as part of the Aptana studio 2/3
releases individually as a plugin, but moving on if you vist the
aptana site there is sweet little about python on their site, their
site is dominated by Radrails.

Can't help thinking they open sourced Pydev so they could bench it. So
I started thinking that the only consistent env each python person has
is idle as it ships in the install.

Sometimes we can contribute with money and sometimes with time, if I
was to contribute money to ensure that I and all new coming python
programmers could have a first class development environment to use
what would I donate to? At the moment no particular group seems
applicable.

Is pydev actively being developed and for who? SPE is a great idea but
is Stan still developing? Pyscripter is good but not 64 capable. Plus
none of these projects seem community centric.

Maybe its just my wish, maybe something already exists, but to my mind
why is there not a central python community ide or plugin setup like
pydev or using pydev(since currently it is very good - to me), which I
know or at least could confidently donate time or money to further
python.

This could apply to many python area's does python use easy_install or
pypm, well if you want camelot or zope (unless you have business
edition) its easy_install, but you wont find an ide with built in egg
or pypm support? Why every Ruby ide has gems manager, and for that
fact look at netbeans, the ide is good but support for python is
mentioned on a far flung community page where some developers are
trying to maintain good python support. PS they seem to be doing a
good job, but a review of the mailing list archives shows little
activity.

One could say that activestate puts in good support but then they do
not provide an ide within the means of the average part time person
retailing its main edition at over $300, Pycharm a good ide at $99 but
then where is my money going.

I think a community plugin architecture which contained components
like pydev, pyscripter, eclipse and eggs/pypm packages would give a
place I can contribute time as my skills grow and confidently donate
money knowing I am assisting the development of community tools and
packages we all can use. No need to reinvent the wheel most things
already exist, for example apt-get & rpm style package management time
tested and could be easily used to manage python eggs for example.

Anyway I have had my 2 cents, if someone is contributing more than I
know, and this wasn't intended to dimnish anyone's effort, just
wanting to look to growing and fostering a stronger python community.

Sayth



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


mutiprocessing, manager, list & threading ?

2010-12-28 Thread mika . saari
Hi,

  Testing if I could be able to use multiprocessing BaseManager to manage
list of instance pointers between processes. If my intance inherits
Thread, I get pickling error about _thread.lock.

  I found  Steven Bethard's recipe for this kind of problem in
http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods,
but I do not to get the idea how to copyreg the _thread.lock.

  Is it even possible to save instance pointer to list which is
synchronized between separate processes ?

  Thanks a lot,
-Mika


Client side code:

from multiprocessing.managers import BaseManager
from threading import Thread, Lock

class ListManager(BaseManager):
pass

class Testing(Thread):
def __init__(self):
Thread.__init__(self)

def nothing(self):
print("Nothing")

ListManager.register('get_list')
ListManager.register('Testing',Testing)
m = ListManager(address=('', 5), authkey=b'abc')
m.connect()

list1 = m.get_list()
test = Testing()
print("TEST:",test)
list1.append(test)
print("TEST:",test)


Error:
---
Traceback (most recent call last):
  File "mpclit.py", line 23, in 
list1.append(test)
  File "", line 2, in append
  File "/usr/local/lib/python3.1/multiprocessing/managers.py", line 735,
in _callmethod

conn.send((self._id, methodname, args, kwds))
  File "/usr/local/lib/python3.1/pickle.py", line 1358, in dumps
Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle : attribute lookup __main__.release
failed


References:
--
http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods

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


hai how are you

2010-12-28 Thread sakthivel vel
webpage : http://123maza.com/35/city149/
-- 
http://mail.python.org/mailman/listinfo/python-list


hai

2010-12-28 Thread sakthivel vel
webpage : http://123maza.com/35/city149/
-- 
http://mail.python.org/mailman/listinfo/python-list