Re: Suggested coding style

2011-09-26 Thread DevPlayer
By the way OP Passiday the title of the topic is "Suggested coding
style".

Are you suggesting a coding style or asking for a Python coding style
or are you asking what IS the Python coding style.

If you are asking what is the Python coding style. Google The Zen of
Python. It's pretty much the dictum of coding style and referred to
alot by many Pythoneers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggested coding style

2011-09-26 Thread DevPlayer
On Sep 25, 11:41 pm, Chris Angelico  wrote:
> On Mon, Sep 26, 2011 at 12:59 PM, Tim Johnson  wrote:
> > BTW: If you like ranting as a spectator sport, I have found the
> >  Common Lisp newsgroup to be among the most spectacular. But that's
> >  just me.
>
> I do, actually, but I don't need to add another newsgroup. Rick
> provides plenty of material here, and I can easily sate myself in just
> a few other places that I frequent. It's quite amusing to watch those
> holy wars erupt...
>
> And every once in a while, they actually prove quite educative. I'm
> not sure how it happens, nor how to trigger it - hmm, perhaps this
> should be the subject of a scientific paper. "On ranting newsgroups
> and how to make them productive".
>
> ChrisA

I think intellectual growth from rants works like this:

Ranter: Bla bla, bad logic, poor facts, some point.
Others: Bla bla you rant Mr Ranter, some logic, few facts, same point.
Ranter: bad mouthing
Others: bad mouthing back
Ranter: Bla Bla, I don't rant, better logic counter facts, lots of
opinion (to not get called a ranter)
Others: Bla bla, You do rant Ranter, good counter logic and facts,
same point (some reason needs to put Ranter "in his place")
Ranter: Super Bla, long winded logic with some strong points, random
but accurate facts out the wazzu (tries to save face)
Others: Acknowleges Ranters point are accurate but claims they don't
apply
Ranter: makes case his points do.
Others: agrees to disagree, silently picks mute Ranter,
Ranter: picks a new topic and starts over.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: install packages with pip to older Python versions

2011-09-26 Thread alex23
On Sep 27, 6:39 am, Jabba Laci  wrote:
> So, how can I install packages for a specific version of Python (here,
> v2.5)? With 2.7 I use "sudo pip install ".

It's amazing what you can find when you look at the documentation:
http://www.pip-installer.org/en/latest/index.html

"You can use pip install --upgrade SomePackage to upgrade to a newer
version, or pip install SomePackage==1.0.4 to install a very specific
version."

However, if you're not using virtualenv, I'd recommend looking at it
as well: http://pypi.python.org/pypi/virtualenv
-- 
http://mail.python.org/mailman/listinfo/python-list


Race condition deadlock in communicate when threading?

2011-09-26 Thread Atherun
In python 2.6.4 I have a fairly complex system running (copying and
pasting it would be quite difficult).  At its core there are builders
that inherit from threading.Thread.  I have some builders that run
external tasks via popen and read output using communicate.  I have
the ability to run any number of builders in parallel. All of this
uses logging as well, where each builder has their own logger they
create from the base logger i.e. logging.getLogger("Logger.
%s"%self.Name).

When running several threads in parallel that each call popen and
communicate functions, python just hangs, about 95% of the time.  All
of it, parent threads, any threads I started before I got to this
step, it just stops responding.  Stepping through it with pdb trying
to find the deadlock will always make it work, killing the external
app I called via popen, after it has hung, will make it move along as
well. Looking at the stack traces using the code found
http://code.activestate.com/recipes/577334-how-to-debug-deadlocked-multi-threaded-programs/
the threads stop running with the following stacks, this is the last
output from the tracer before it stops responding.:

File: "c:\src\extern\python\lib\threading.py", line 497, in
__bootstrap
  self.__bootstrap_inner()
File: "c:\src\extern\python\lib\threading.py", line 525, in
__bootstrap_inner
  self.run()
File: "c:\src\extern\python\lib\threading.py", line 477, in run
  self.__target(*self.__args, **self.__kwargs)
File: "c:\src\extern\python\lib\subprocess.py", line 877, in
_readerthread
  buffer.append(fh.read())

And

out, err = proc.communicate("change: new\ndescription: %s
\n"%changelistDesc)
File: "c:\src\extern\python\lib\subprocess.py", line 689, in
communicate
  return self._communicate(input)
File: "c:\src\extern\python\lib\subprocess.py", line 903, in
_communicate
  stdout_thread.join()
File: "c:\src\extern\python\lib\threading.py", line 637, in join
  self.__block.wait()
File: "c:\src\extern\python\lib\threading.py", line 237, in wait
  waiter.acquire()

I'm trying to track this down so I can eliminate it for good as it
pops up in multiple places from time to time.

Any tips would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QA Engineering/ Python/ Contract/ Austin, TX

2011-09-26 Thread Chris Rebert
On Mon, Sep 26, 2011 at 1:56 PM, TOM  wrote:
> Tom Gugger
> Independent Recruiter
> tgug...@bex.net
>
> US Citizens or Greencard
> On Site
>
>
> QA Engineering/ Python/ Contract/ Austin, TX
>
> This is an immediate start, such as next week. I need three
> contractors

Such postings belong on the Python jobs board
(http://www.python.org/community/jobs/ ), not
python-list/comp.lang.python.

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


QA Engineering/ Python/ Contract/ Austin, TX

2011-09-26 Thread TOM
Tom Gugger
Independent Recruiter
tgug...@bex.net

US Citizens or Greencard
On Site


QA Engineering/ Python/ Contract/ Austin, TX

This is an immediate start, such as next week. I need three
contractors
for a 4--6 month contract in Austin, TX for Quality Assurance
Engineers.
The location is Austin, TX.

This is an automation project.

Must Have — Good Network domain knowledge such as TCP/IP.

Must Have --- experience testing  Data, Voice, and IPTV traffic.

Must Have --- Strong Python

A Plus --- Fanfare

Please make sure all the required skills show on the resume. If
interested and
qualified, email resume to tgug...@bex.net.
-- 
http://mail.python.org/mailman/listinfo/python-list


install packages with pip to older Python versions

2011-09-26 Thread Jabba Laci
Hi,

I have Python 2.7 on my system. Today I wanted to try Google App
Engine but it runs on Python 2.5 at Google so I installed this version
on my machine next to v2.7 to avoid compatibility problems. However,
when I start the Python shell v2.5 and try to import something from
the GAE SDK (for instance "from google.appengine.ext import webapp"),
I get an error: "ImportError: No module named webob". (Note that with
v2.7 I don't have this problem.)

So, how can I install packages for a specific version of Python (here,
v2.5)? With 2.7 I use "sudo pip install ".

Thanks,

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


Re: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Ian Kelly
On Mon, Sep 26, 2011 at 2:11 PM, Tim Chase
 wrote:
> On 09/26/11 13:57, Prasad, Ramit wrote:
>>>
>>> It seems it's time to start reading about argparse
>>
>> FYI, it only appears on Python 2.7+
>
> However I believe it can be uneventfully copied and run under several
> versions earlier (likely back to 2.5, perhaps to 2.4 -- I no longer have 2.4
> at my fingertips to test).

For older versions it would be best to use the Google project, which I
think is still maintained and backported:

http://code.google.com/p/argparse/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Tim Chase

On 09/26/11 13:57, Prasad, Ramit wrote:

It seems it's time to start reading about argparse

FYI, it only appears on Python 2.7+


However I believe it can be uneventfully copied and run under 
several versions earlier (likely back to 2.5, perhaps to 2.4 -- I 
no longer have 2.4 at my fingertips to test).


-tkc



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


Re: Wrote a new library - Comments and suggestions please!

2011-09-26 Thread Jon Clements
On Sep 26, 12:23 pm, Tal Einat  wrote:
> The library is called RunningCalcs and is useful for running several
> calculations on a single iterable of values.
>
> https://bitbucket.org/taleinat/runningcalcs/http://pypi.python.org/pypi/RunningCalcs/
>
> I'd like some input on how this could be made more useful and how to
> spread the word about it.
>
> The library contains the base RunningCalc class and implementations of
> sub-classes for common calculations: sum, min/max, average, variance &
> standard deviation, n-largest & n-smallest. Additionaly a utility
> function apply_in_parallel() is supplied which makes running several
> calculations on an iterable easy (and fast!).
>
> Straight-forward example:
>
> mean_rc, stddev_rc = RunningMean(), RunningStdDev()
> for x in values:
>     mean_rc.feed(x)
>     stddev_rc.feed(x)
> mean, stddev = mean_rc.value, stddev_rc.value
>
> Examples using apply_in_parallel():
>
> mean, stddev = apply_in_parallel(values, [RunningMean(),
> RunningStdDev()])
> five_smallest, five_largest = apply_in_parallel(values,
> [RunningNSmallest(5), RunningNLargest(5)])
>
> Comments and suggestions would be highly appreciated!

You may not of heard of it, but the SAS language has something called
PROC FREQ... I'm imagining that maybe this is where you should be
taking this. Sorry I can't comment on the code, as I haven't really
got time, but have a look! (I'd be willing to invest sometime with
you, if you agree that's where something like this should be going...)

Cheers,

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


Re: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Paul Rudin
"Prasad, Ramit"  writes:

> This email is confidential...

Probably a bad idea to post it to a world readable mailing list then :)
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Prasad, Ramit
> It seems it's time to start reading about argparse
FYI, it only appears on Python 2.7+

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5 zlib trouble

2011-09-26 Thread Benjamin Kaplan
On Mon, Sep 26, 2011 at 2:16 PM, Jesramz  wrote:
>
> I appreciate all the help, but I am still a little confused. Sorry,
> I'm a lay person.
>
> Should I download zlib1g-dev and install it to get the zlib module?
>
> and Alter the configure script to avoid future issues?
>
> Also about getting zlib I found the following:
>
> "I was able to recompile zlib
>
> $./configure --shared
>
> then recompile Python 2.5.1; I am now able to import the zlib module.
>
> cheers
>
> -sg"
>
> Does this mean that while in the zlib folder run ./configure shared
> and then install python?
> --

Not quite. This person was talking about configuring zlib, not Python.
Just about every Linux program out there has a ./configure file- it's
part of GNU Autotools, which many programs use as an easy way to
compile and install their software. Since the version of zlib on
Ubuntu Natty doesn't work for Python 2.5, this person just compiled
their own zlib (calling ./configure --shared; make; make install from
the zlib *source* folder that they downloaded) and then compiled their
own Python version (from the Python source folder that they
downloaded)


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


Re: Python 2.5 zlib trouble

2011-09-26 Thread Jesramz

I appreciate all the help, but I am still a little confused. Sorry,
I'm a lay person.

Should I download zlib1g-dev and install it to get the zlib module?

and Alter the configure script to avoid future issues?

Also about getting zlib I found the following:

"I was able to recompile zlib

$./configure --shared

then recompile Python 2.5.1; I am now able to import the zlib module.

cheers

-sg"

Does this mean that while in the zlib folder run ./configure shared
and then install python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Weekly

2011-09-26 Thread Rahul
Hi Everyone,

I have started a free weekly newsletter called Python Weekly which
includes curated news, articles, new releases, software & tools,
events, jobs etc about Python and related technologies. It's a great
way to keep abreast of what's happening in Python land. You can
subscribe to it here, http://www.pythonweekly.com/

Regards
Rahul Chaudhary
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting bits in large string / bit vector

2011-09-26 Thread Ian Kelly
On Sep 26, 2011 1:49 AM,  wrote:
> Is there an equivalent command in python that would immediately provide
the number of set bits in a large bit vector/string

Besides what others have said, if you expect the number of bits set to be
small, you might just use a set.

bits = set()
# set bit 1000
bits.add(1000)
# clear bit 200
bits.discard(200)
# test bit 1000
if 1000 in bits:
pass
# get number of bits set
len(bits)

All of these operations are O(1), but if you expect to set a very large
number of bits, then the space trade-off may not be practical.

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


Re: Counting bits in large string / bit vector

2011-09-26 Thread casevh
On Sep 26, 12:56 am, Nizamov Shawkat 
wrote:
> > Is there an equivalent command in python that would immediately provide the
> > number of set bits in a large bit vector/string
>
> You might be able to achieve this using numpy boolean array and, e.g,
> the arithmetic sum function or something similar.
> There is also another library  http://pypi.python.org/pypi/bitarray
> which resembles numpy's bit array.
>
> Hope it helps,
> S.Nizamov

You can also use gmpy or gmpy2.

>>> a=gmpy2.mpz(123)
>>> bin(a)
'0b011'
>>> gmpy2.hamdist(a,0)
6
>>>

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


Wrote a new library - Comments and suggestions please!

2011-09-26 Thread Tal Einat
The library is called RunningCalcs and is useful for running several
calculations on a single iterable of values.

https://bitbucket.org/taleinat/runningcalcs/
http://pypi.python.org/pypi/RunningCalcs/

I'd like some input on how this could be made more useful and how to
spread the word about it.


The library contains the base RunningCalc class and implementations of
sub-classes for common calculations: sum, min/max, average, variance &
standard deviation, n-largest & n-smallest. Additionaly a utility
function apply_in_parallel() is supplied which makes running several
calculations on an iterable easy (and fast!).

Straight-forward example:

mean_rc, stddev_rc = RunningMean(), RunningStdDev()
for x in values:
mean_rc.feed(x)
stddev_rc.feed(x)
mean, stddev = mean_rc.value, stddev_rc.value

Examples using apply_in_parallel():

mean, stddev = apply_in_parallel(values, [RunningMean(),
RunningStdDev()])
five_smallest, five_largest = apply_in_parallel(values,
[RunningNSmallest(5), RunningNLargest(5)])


Comments and suggestions would be highly appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counting bits in large string / bit vector

2011-09-26 Thread Arnaud Delobelle
 b = numpy.zeros(10**7, dtype=bool)
 for x in 3, 4, 6: b[10**x] = True
> ...
 b.sum()
> 3

Without numpy:

>>> counts = [bin(i).count('1') for i in range(256)]
>>> bytes = b"hello python"*10
>>> len(bytes)*8
960
>>> sum(map(counts.__getitem__, bytes))
480

Pretty fast as well.

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


Re: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Gelonida N
On 09/26/2011 11:10 AM, Chris Rebert wrote:
> On Mon, Sep 26, 2011 at 1:55 AM, Gelonida N  wrote:
>> Hi,
>>
>> So far I used optparse.OptionParser for parsing command line arguments
>> for my python scripts. So far I was happy, with a one level approach,
>> where I get only one help text
>>
>> Now I'd like to create a slightly different python script and wondered
>> which approach / module might be best for implementing the parsing and
>> generation of help texts.
> 
>> then if I typed ./sh.py  -h
>> I'd like to get the helptext for the specified command.
> 
> http://docs.python.org/library/argparse.html
> 
> It is capable of handling sub-commands and the display of
> subcommand-specific help text.
> 
Thanks a lot.
It seems it's time to start reading about argparse

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


Re: Counting bits in large string / bit vector

2011-09-26 Thread Peter Otten
bmacin...@comcast.net wrote:

> In Perl I can create a large bit vector as follows:

> vec($bitmap,1000,1) = 0;# this will create a bit string of all
> zeros

> To set bits I may using commands like:

>  vec($bitmap,1000, 1) = 1  # turn on bit 1000
>  vec($bitmap,1, 1) = 1# turn on bit 1
>  vec($bitmap,100, 1) = 1 # turn on bit 1000

> which would set three bits in the string $bitmap - Note: in perl I don't
> even have to declare $bitmap until I use it in the vec command.
> Anyway there is a very cool perl command which return the number of bits
> set in a large bitmap string instantly.
 
> The command is:

>  $setbits = unpack("%32b*", $bitmap);

> Which in this case would store the number 3 in $setbits

> Is there an equivalent command in python that would immediately provide
> the number of set bits in a large bit vector/string
> I know I could loop through but when you have 10,000,000 or 100,000,000
> bits, the looping takes quite a while the perl unpack is instant.

With numpy:

>>> b = numpy.zeros(10**7, dtype=bool)
>>> for x in 3, 4, 6: b[10**x] = True
...
>>> b.sum()
3

I don't know how it's implemented, but it seems to be quite fast.

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


Re: Hierarchical commnd line parsing / help texts

2011-09-26 Thread Chris Rebert
On Mon, Sep 26, 2011 at 1:55 AM, Gelonida N  wrote:
> Hi,
>
> So far I used optparse.OptionParser for parsing command line arguments
> for my python scripts. So far I was happy, with a one level approach,
> where I get only one help text
>
> Now I'd like to create a slightly different python script and wondered
> which approach / module might be best for implementing the parsing and
> generation of help texts.

> then if I typed ./sh.py  -h
> I'd like to get the helptext for the specified command.

http://docs.python.org/library/argparse.html

It is capable of handling sub-commands and the display of
subcommand-specific help text.

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


Hierarchical commnd line parsing / help texts

2011-09-26 Thread Gelonida N
Hi,

So far I used optparse.OptionParser for parsing command line arguments
for my python scripts. So far I was happy, with a one level approach,
where I get only one help text

Now I'd like to create a slightly different python script and wondered
which approach / module might be best for implementing the parsing and
generation of help texts.

Please look at my example (let's emulate a shell in python)

$ ./sh.py
or
$ ./sh.py -h
Should create the top level help text and list possible commands
.e.g.
ls
rm
cat
and list some commands with potential sub commands
.e.g.
net
db


then if I typed ./sh.py  -h
I'd like to get the helptext for the specified command.

For some more complex commands I'd even like to be able to type


/sh.py   -h


Ideally, I would like to be able to parse generic options before
commands / sub commands and less generic options after the commands


./sh.py -v ls -a


Thanks in advance for suggestions



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


Re: Counting bits in large string / bit vector

2011-09-26 Thread Nizamov Shawkat
> Is there an equivalent command in python that would immediately provide the
> number of set bits in a large bit vector/string
>

You might be able to achieve this using numpy boolean array and, e.g,
the arithmetic sum function or something similar.
There is also another library  http://pypi.python.org/pypi/bitarray
which resembles numpy's bit array.

Hope it helps,
S.Nizamov
-- 
http://mail.python.org/mailman/listinfo/python-list


Counting bits in large string / bit vector

2011-09-26 Thread bmacinnis
In Perl I can create a large bit vector as follows:

 

vec($bitmap,1000,1) = 0;# this will create a bit string of all zeros

 

To set bits I may using commands like:

 

 vec($bitmap,1000, 1) = 1  # turn on bit 1000

 vec($bitmap,1, 1) = 1# turn on bit 1

 vec($bitmap,100, 1) = 1 # turn on bit 1000

 

which would set three bits in the string $bitmap - Note: in perl I don't
even have to declare $bitmap until I use it in the vec command.

 

Anyway there is a very cool perl command which return the number of bits set
in a large bitmap string instantly. 

The command is:

 

 $setbits = unpack("%32b*", $bitmap);

 

 

Which in this case would store the number 3 in $setbits

 

 

Is there an equivalent command in python that would immediately provide the
number of set bits in a large bit vector/string

 

I know I could loop through but when you have 10,000,000 or 100,000,000
bits, the looping takes quite a while the perl unpack is instant.

 

Thanks for any help you could provide

 

 

 

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