Re: Counting Python threads vs C/C++ threads

2019-07-21 Thread Peter J. Holzer
x27; to see things broken down > by CPU core (there are 32 of them, probably counting hyperthreads as > different cores), but the CPU use is in the teens or so. If you had many CPU-bound Python threads, then with 32 cores each core might show as 3 % busy (the sum of the threads can't u

Re: Counting Python threads vs C/C++ threads

2019-07-17 Thread Thomas Jollans
On 17/07/2019 09.58, Barry Scott wrote: > >> On 16 Jul 2019, at 20:48, Dan Stromberg wrote: >> >> >> >> A question arises though: Does threading.active_count() only show Python >> threads created with the threading module? What about threads created with >> the thread module? > Only pythons t

Re: Counting Python threads vs C/C++ threads

2019-07-17 Thread Barry Scott
cess using 100% CPU? > Nope. CPU utilization and disk use are both low. Then your problem is latency. You need to find the slow operation. > We've been going into top, and then hitting '1' to see things broken down by > CPU core (there are 32 of them, probably counting hype

Re: Counting Python threads vs C/C++ threads

2019-07-16 Thread Dan Stromberg
CPU-bound Python threads causing the problem > > (because of the threading+GIL thing). > > Does top show the process using 100% CPU? > Nope. CPU utilization and disk use are both low. We've been going into top, and then hitting '1' to see things broken down by CPU core (

Re: Counting Python threads vs C/C++ threads

2019-07-16 Thread Barry Scott
I'm going to assume you are on linux. On 16 Jul 2019, at 18:35, Dan Stromberg wrote: > > I'm looking at a performance problem in a large CPython 2.x/3.x codebase > with quite a few dependencies. > > I'm not sure what's causing the slowness yet. The CPU isn't getting hit > hard, and I/O on the

Counting Python threads vs C/C++ threads

2019-07-16 Thread Dan Stromberg
I'm looking at a performance problem in a large CPython 2.x/3.x codebase with quite a few dependencies. I'm not sure what's causing the slowness yet. The CPU isn't getting hit hard, and I/O on the system appears to be low - but throughput is poor. I'm wondering if it could be CPU-bound Python thr

Re: Efficient counting of results

2017-10-20 Thread Steven D'Aprano
On Fri, 20 Oct 2017 09:05:15 -0800, Israel Brewster wrote: > On Oct 19, 2017, at 5:18 PM, Steve D'Aprano > wrote: >> What t1 and t2 are, I have no idea. Your code there suggests that they >> are fields in your data records, but the contents of the fields, who >> knows? > > t1 and t2 are *indepen

Re: Efficient counting of results

2017-10-20 Thread MRAB
On 2017-10-20 18:05, Israel Brewster wrote:[snip] In a sense, in that it supports my initial approach. As Stefan Ram pointed out, there is nothing wrong with the solution I have: simply using if statements around the calculated lateness of t1 and t2 to increment the appropriate counters. I was

Re: Efficient counting of results

2017-10-20 Thread Israel Brewster
On Oct 19, 2017, at 5:18 PM, Steve D'Aprano wrote: > What t1 and t2 are, I have no idea. Your code there suggests that they are > fields in your data records, but the contents of the fields, who knows? t1 and t2 are *independent* timestamp fields. My apologies - I made the obviously false assump

Re: Efficient counting of results

2017-10-19 Thread MRAB
On 2017-10-20 03:32, Chris Angelico wrote: On Fri, Oct 20, 2017 at 12:18 PM, Steve D'Aprano wrote: On Fri, 20 Oct 2017 05:28 am, Israel Brewster wrote: So if the date of the first record was today, t1 was on-time, and t2 was 5 minutes late, then I would need to increment ALL of the following (

Re: Efficient counting of results

2017-10-19 Thread Chris Angelico
On Fri, Oct 20, 2017 at 12:18 PM, Steve D'Aprano wrote: > On Fri, 20 Oct 2017 05:28 am, Israel Brewster wrote: >> So if the date of >> the first record was today, t1 was on-time, and t2 was 5 minutes late, then >> I would need to increment ALL of the following (using your data structure >> from ab

Re: Efficient counting of results

2017-10-19 Thread Steve D'Aprano
On Fri, 20 Oct 2017 05:28 am, Israel Brewster wrote: > If it helps, my data would look something like this: > > [ (date, key, t1, t2), > (date, key, t1, t2) > . > . > ] > > Where the date and the key are what is used to determine what "on-time" is > for the record, and thus which "late" bin to

Re: Efficient counting of results

2017-10-19 Thread Thomas Jollans
On 19/10/17 20:04, Israel Brewster wrote: >> then loop through the records, find the schedule for that record (if any, if >> not move on as mentioned earlier), compare t1 and t2 against the schedule, >> and increment the appropriate bin counts using a bunch of if statements. >> Functional, if ug

Re: Efficient counting of results

2017-10-19 Thread Peter Otten
Israel Brewster wrote: > >> On Oct 19, 2017, at 10:02 AM, Stefan Ram wrote: >> >> Israel Brewster writes: >>> t10 = {'daily': 0, 'WTD': 0, 'MTD': 0, 'YTD': 0,} >>> increment the appropriate bin counts using a bunch of if statements. >> >> I can't really completely comprehend your requirement

Re: Efficient counting of results

2017-10-19 Thread Israel Brewster
> On Oct 19, 2017, at 10:02 AM, Stefan Ram wrote: > > Israel Brewster writes: >> t10 = {'daily': 0, 'WTD': 0, 'MTD': 0, 'YTD': 0,} >> increment the appropriate bin counts using a bunch of if statements. > > I can't really completely comprehend your requirements > specification, you might hav

Re: Efficient counting of results

2017-10-19 Thread Israel Brewster
> On Oct 19, 2017, at 9:40 AM, Israel Brewster wrote: > > I am working on developing a report that groups data into a two-dimensional > array based on date and time. More specifically, date is grouped into > categories: > > day, week-to-date, month-to-date, and year-to-date > > Then, for eac

Efficient counting of results

2017-10-19 Thread Israel Brewster
I am working on developing a report that groups data into a two-dimensional array based on date and time. More specifically, date is grouped into categories: day, week-to-date, month-to-date, and year-to-date Then, for each of those categories, I need to get a count of records that fall into t

Re: Counting words in a string??

2016-09-30 Thread breamoreboy
l home work assignment, even though stop asking for programs and > > start asking how to make the same. > > > > anyway if you ever try to write code for this you have to split you > > sentence and use a dict for counting > > > > Python has Counter from coll

Re: Counting words in a string??

2016-09-30 Thread mm0fmf
split you sentence and use a dict for counting Python has Counter from collections but it is a little bit slower when compared to defaultdict for this kind of purpose. Regards Srinivas Devaki Senior (final yr) student at Indian Institute of Technology (ISM), Dhanbad Computer Science and Engineering Dep

Re: Counting words in a string??

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 5:12 AM, Jake wrote: > Could you make the program for me or provide an outline? No. In case you didn't read any of the other responses, this community is not a plagiarism source. If you want to learn to be a programmer, you're going to have to learn some key skills, one of

Re: Counting words in a string??

2016-09-30 Thread Peter Pearson
On Fri, 30 Sep 2016 11:37:19 -0700 (PDT), Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they c

Re: Counting words in a string??

2016-09-30 Thread Jake
f you ever try to write code for this you have to split you > sentence and use a dict for counting > > Python has Counter from collections but it is a little bit slower when > compared to defaultdict for this kind of purpose. > > Regards > Srinivas Devaki > Senior (final y

Re: Counting words in a string??

2016-09-30 Thread Rob Gaddi
Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose > from their sentence. > > It would

Re: Counting words in a string??

2016-09-30 Thread srinivas devaki
up which they chose from their sentence. > typical home work assignment, even though stop asking for programs and start asking how to make the same. anyway if you ever try to write code for this you have to split you sentence and use a dict for counting Python has Counter from collections but it

Counting words in a string??

2016-09-30 Thread Jake
Hi, I need a program which: 1) Asks the user for a sentence of their choice (not including punctuation) 2) Ask the user which word they would like to know is repeated 3) Print out to the user how many times the word came up which they chose from their sentence. It would help if you could comment

Re: counting unique numpy subarrays

2015-12-04 Thread duncan smith
On 04/12/15 23:06, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I'm trying to find a computationally efficient way of identifying >> unique subarrays, counting them and returning an array containing only >> the unique subarrays and a co

Re: counting unique numpy subarrays

2015-12-04 Thread duncan smith
On 04/12/15 22:36, Albert-Jan Roskam wrote: > Hi > > (Sorry for topposting) > > numpy.ravel is faster than numpy.flatten (no copy) > numpy.empty is faster than numpy.zeros > numpy.fromiter might be useful to avoid the loop (just a hunch) > > Albert-Jan > Thanks, I'd forgotten the difference be

Re: counting unique numpy subarrays

2015-12-04 Thread Peter Otten
duncan smith wrote: > Hello, > I'm trying to find a computationally efficient way of identifying > unique subarrays, counting them and returning an array containing only > the unique subarrays and a corresponding 1D array of counts. The > following code work

RE: counting unique numpy subarrays

2015-12-04 Thread Albert-Jan Roskam
Hi (Sorry for topposting) numpy.ravel is faster than numpy.flatten (no copy) numpy.empty is faster than numpy.zeros numpy.fromiter might be useful to avoid the loop (just a hunch) Albert-Jan > From: duncan@invalid.invalid > Subject: counting unique numpy subarrays > Date: Fri, 4 Dec 2

counting unique numpy subarrays

2015-12-04 Thread duncan smith
Hello, I'm trying to find a computationally efficient way of identifying unique subarrays, counting them and returning an array containing only the unique subarrays and a corresponding 1D array of counts. The following code works, but is a bit slow. ### from collections i

Re: Reference Counting Irregularity

2015-06-25 Thread Ian Kelly
On Thu, Jun 25, 2015 at 12:49 PM, Eric Edmond wrote: > Hi, > > I have been writing a C++ extension for Python recently, and am currently > fixing the reference counting throughout the extension. As I am very new to > this topic, my question may have a simple answer, but I was unabl

Reference Counting Irregularity

2015-06-25 Thread Eric Edmond
Hi, I have been writing a C++ extension for Python recently, and am currently fixing the reference counting throughout the extension. As I am very new to this topic, my question may have a simple answer, but I was unable to find any mention of the behavior online. When using the

Reference counting and the use of PYTHONDUMPREFS

2014-01-18 Thread Anders Wegge Keller
During the final test of a bit of embedded python, I wanted to see if I had any hanging references. To my suprise, I ended up with a rather large amount, after running combinerefs.py. And even with the simplest[1] possible use of embedding, I end up with 13475 still-living references. If this i

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Thursday, December 20, 2012 12:21:57 AM UTC+13, Thomas Bach wrote: > Hi, > > > > just as a side-note > > > > On Wed, Dec 19, 2012 at 02:45:13AM -0800, : > > > for word in list: > > > if word in dict: > > > count = dict[word] > > >

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Thursday, December 20, 2012 12:03:21 AM UTC+13, Steven D'Aprano wrote: > On Wed, 19 Dec 2012 02:45:13 -0800, dgcosgrave wrote: > > > > > Hi Iam just starting out with python...My code below changes the txt > > > file into a list and add them to an empty dictionary and print how often > > >

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Wednesday, December 19, 2012 11:55:28 PM UTC+13, Jussi Piitulainen wrote: > > > > > > Hi Iam just starting out with python...My code below changes the txt > > > file into a list and add them to an empty dictionary and print how > > > often the word occurs, but it only seems to recognise an

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Thomas Bach
Hi, just as a side-note On Wed, Dec 19, 2012 at 02:45:13AM -0800, dgcosgr...@gmail.com wrote: > for word in list: > if word in dict: > count = dict[word] > count += 1 > dict[word] = count > else: > dict[wor

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 02:45:13 -0800, dgcosgrave wrote: > Hi Iam just starting out with python...My code below changes the txt > file into a list and add them to an empty dictionary and print how often > the word occurs, but it only seems to recognise and print the last entry > of the txt file. Any

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Jussi Piitulainen
dgcosgr...@gmail.com writes: > Hi Iam just starting out with python...My code below changes the txt > file into a list and add them to an empty dictionary and print how > often the word occurs, but it only seems to recognise and print the > last entry of the txt file. Any help would be great. > >

counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
Hi Iam just starting out with python...My code below changes the txt file into a list and add them to an empty dictionary and print how often the word occurs, but it only seems to recognise and print the last entry of the txt file. Any help would be great. tm =open('ask.txt', 'r') dict = {} for

counting source lines (was: Is Python a commercial proposition ?)

2012-07-29 Thread Stefan Behnel
lipska the kat, 29.07.2012 18:01: > My most recent experience is with Java. The last project I was involved > with included 6775 java source files containing 1,145,785 lines of code. > How do I know this? because I managed to cobble together a python script > that walks the source tree and counts t

Re: Counting the number of call of a function

2011-09-30 Thread Laurent Claessens
The keys of globals() are the _names_. You're giving it the function itself. Ow, ok. I didn't caught it. I understand now. > A decorator would be better. Yes. I keep the solution with foo=Wraper(foo) Thanks a lot all ! Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Counting the number of call of a function

2011-09-29 Thread Chris Rebert
On Thu, Sep 29, 2011 at 10:08 AM, Laurent Claessens wrote: >   Hello > > >   Is it possible to count the number of time a function is called ? > Of course, if I've access to the source code, it's easy. > > I tried the following : > > def foo(): >    print "foo !" > > > class wraper(object): >    d

Re: Counting the number of call of a function

2011-09-29 Thread MRAB
On 29/09/2011 18:08, Laurent Claessens wrote: Hello Is it possible to count the number of time a function is called ? Of course, if I've access to the source code, it's easy. I tried the following : def foo(): print "foo !" class wraper(object): def __init__(self,fun): globals()[fun]=self.r

Re: Counting the number of call of a function

2011-09-29 Thread Chris Angelico
On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens wrote: > class wraper(object): >    def __init__(self,fun): >        globals()[fun]=self.replacement >    def replacement(*args): >        print "I'm replaced" > > foo() > X=wraper(foo) > foo() > > I was hoping that globals()[foo] would be replace

Re: Counting the number of call of a function

2011-09-29 Thread Chris Angelico
On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens wrote: > def foo(): >    print "foo !" > > > class wraper(object): >    def __init__(self,fun): >        globals()[fun]=self.replacement >    def replacement(*args): >        print "I'm replaced" > > foo() > X=wraper(foo) > foo() Are you able to

Counting the number of call of a function

2011-09-29 Thread Laurent Claessens
Hello Is it possible to count the number of time a function is called ? Of course, if I've access to the source code, it's easy. I tried the following : def foo(): print "foo !" class wraper(object): def __init__(self,fun): globals()[fun]=self.replacement def replac

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 bit

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 simil

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 wel

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) =

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.pytho

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

Re: Reference counting problems?

2010-12-09 Thread MRAB
, so both of their refcounts will have been incremented to 2. You will need to DECREF the objects at python__x and python__y before the C variables python__x and python__y go out of scope. But for single returns I do something like this I realize that the 2 lines below are pointless,

Reference counting problems?

2010-12-09 Thread Eric Frederich
O", python__x, python__y); But for single returns I do something like this I realize that the 2 lines below are pointless, but are they causing a memory leak or problems with reference counting? python__x = Py_BuildValue("s", x) python__return_val = Py_BuildValue("

counting character occurrences

2010-01-23 Thread Wilbert Berendsen
Op vrijdag 22 januari 2010 schreef Arnaud: > Why not just start with (untested): > > import codecs > from collections import defaultdict > > tcounters = defaultdict(int) > f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") > > for c in f.read(): > tcounters[c] += 1 > > f

Re: counting lines of code

2010-01-23 Thread Michele Simionato
On Jan 22, 10:30 pm, Steve Holden wrote: > >> Oh, sorry, did I have the wrong opinion? > > > You had a condescending attitude. > > Towards someone who is fairly obviously not a Python neophyte. > > Please don't think we are telling you you can't have any opinion you > like. Just don't expect to ge

Re: counting lines of code

2010-01-23 Thread Michele Simionato
On Jan 22, 7:51 pm, Phlip wrote: > On Jan 21, 9:00 pm, Michele Simionato > wrote: > > > Just for fun I have run cloc on our trunk: > > > SUM:                8743    272238    215871   1470139 x   1.84 = > > 2708354.95 > > Nice! > > My favorite version of a cloc system can distinguish test from >

Re: counting lines of code

2010-01-22 Thread Wilbert Berendsen
Op donderdag 21 januari 2010 schreef Michele: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. sloccount can do this. http://www.dwheeler.com/sloccount/ Met vriendelijke groet, Wilbert Berendsen -- h

Re: counting lines of code

2010-01-22 Thread Steve Holden
Robert Kern wrote: > On 2010-01-21 15:31 , Phlip wrote: >> Aahz wrote: >>> In article >>> <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, >>> Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: > pylint does too many things, I want something fast that ju

Re: counting lines of code

2010-01-22 Thread Phlip
On Jan 21, 9:00 pm, Michele Simionato wrote: > Just for fun I have run cloc on our trunk: > > SUM:                8743    272238    215871   1470139 x   1.84 = > 2708354.95 Nice! My favorite version of a cloc system can distinguish test from production code. That's why I always use executable c

Re: counting lines of code

2010-01-21 Thread Michele Simionato
On Jan 21, 9:24 pm, Phlip wrote: > On Jan 20, 11:20 pm, Michele Simionato > wrote: > > > pylint does too many things, I want something fast that just counts > > the lines and can be run on thousands of files at once. > > cloc seems fine, I have just tried on 2,000 files and it gives me a > > repo

Re: counting lines of code

2010-01-21 Thread Robert Kern
On 2010-01-21 15:31 , Phlip wrote: Aahz wrote: In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: pylint does too many things, I want something fast that just counts the lines and can be run on thousands

Re: counting lines of code

2010-01-21 Thread Phlip
Aahz wrote: In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: pylint does too many things, I want something fast that just counts the lines and can be run on thousands of files at once. cloc seems fine,

Re: counting lines of code

2010-01-21 Thread Aahz
In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: >On Jan 20, 11:20=A0pm, Michele Simionato >wrote: >> >> pylint does too many things, I want something fast that just counts >> the lines and can be run on thousands of files at once. >> cloc seems fine, I

Re: counting lines of code

2010-01-21 Thread Phlip
On Jan 20, 11:20 pm, Michele Simionato wrote: > pylint does too many things, I want something fast that just counts > the lines and can be run on thousands of files at once. > cloc seems fine, I have just tried on 2,000 files and it gives me a > report in just a few seconds. In my experience wit

Re: counting lines of code

2010-01-20 Thread Michele Simionato
On Jan 21, 8:12 am, Ben Finney wrote: > Michele Simionato writes: > > I need a small utility to count the lines of Python code in a > > directory, traversing subdirectories and ignoring comments and > > docstrings. I am sure there is already something doing that, what do > > you suggest? > > Any

Re: counting lines of code

2010-01-20 Thread Michele Simionato
I did not known about cloc, it does more that I need, but it looks cool (it is perl and not Python, by who cares? ;) Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list

Re: counting lines of code

2010-01-20 Thread Ben Finney
Michele Simionato writes: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. I am sure there is already something doing that, what do > you suggest? Any of the static code checkers (‘pylint’, ‘pyflakes’,

Re: counting lines of code

2010-01-20 Thread Mark Hammond
On 21/01/2010 5:51 PM, Michele Simionato wrote: I need a small utility to count the lines of Python code in a directory, traversing subdirectories and ignoring comments and docstrings. I am sure there is already something doing that, what do you suggest? I suggest typing your subject line into

counting lines of code

2010-01-20 Thread Michele Simionato
I need a small utility to count the lines of Python code in a directory, traversing subdirectories and ignoring comments and docstrings. I am sure there is already something doing that, what do you suggest? TIA, Michele Simionato -- http://mail.python.org/mailman/listinfo

Re: Counting number of objects

2009-01-27 Thread Scott David Daniels
Kottiyath wrote: So, in a higher level class, have a weakref list which contains a reference to each person. Total count will be len(list) at any time. Now, I couldnt find a weakref list - so I am using WeakKeyDictionary with the value as None - since len(dict) also should give me the data I ty

Re: Counting number of objects

2009-01-27 Thread Kottiyath
Thank you everyone for your very helpful comments and suggestions. I have interacted in other newsgroups, but this is the most helpful of them all. As per the comments, I have now decided to go with the weakref mechanism - as per Andreas suggestion, functionally it looks correct that the person sh

Re: Counting number of objects

2009-01-26 Thread Steve Holden
Mark Wooding wrote: > Andreas Waldenburger writes: > >> On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath >> wrote: >> >>> class a(object): >>> counter = 0 >>> def __new__(cls, *args, **kwargs): >>> a.counter += 1 >>> return object.__new__(cls, *args, **kwargs) > > Hmm.

Re: Counting number of objects

2009-01-26 Thread Andreas Waldenburger
On Mon, 26 Jan 2009 02:37:37 + Mark Wooding wrote: > > This looks OK, although I'd suggest using "cls.counter += 1" instead > > of "a.counter += 1" in the __new__() method. Just seems clearer to > > me, esp. when you think about subclassing. > > I'm not sure about clarity, but that would be

Re: Counting number of objects

2009-01-25 Thread Mark Wooding
Andreas Waldenburger writes: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) Hmm. Exceptions raised during object cr

Re: Counting number of objects

2009-01-25 Thread Gabriel Genellina
En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribió: On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following:

Re: Counting number of objects

2009-01-25 Thread Gabriel Genellina
En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribió: On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following:

Re: Counting number of objects

2009-01-25 Thread Andreas Waldenburger
er way to go would be to use the weakref module and create a weakref-set (or list) as the counter. That way you would only need to add the objects in the __new__() method and not worry about removing them. I will admit that this is overengineering the problem a bit, but might be a good exercise. A

Re: Counting number of objects

2009-01-25 Thread Steve Holden
done Ok? > Yes. Just be aware that if instances become involved in cyclic data structures (or in implementations other than CPython, where reference counting isn't used) __del__ might not be called until garbage collection kicks in, so you may want a more explicit way to stop an instance

Counting number of objects

2009-01-25 Thread Kottiyath
Hi, I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following: class a(object): counter = 0 def __new__(cls, *args, **kwargs): a.counter += 1 return object.__new__(cls,

Re: gmpy and counting None

2008-10-14 Thread Robert Kern
Mensanator wrote: On Oct 14, 12:14 pm, Robert Kern <[EMAIL PROTECTED]> wrote: Mensanator wrote: On Oct 13, 5:16 pm, Robert Kern <[EMAIL PROTECTED]> wrote: Mensanator wrote: On Oct 13, 2:43 pm, <[EMAIL PROTECTED]> wrote: Hi, I just stumbled upon the following issue (I am running Debian): $ py

Re: gmpy and counting None

2008-10-14 Thread Mensanator
On Oct 14, 12:14 pm, Robert Kern <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > On Oct 13, 5:16 pm, Robert Kern <[EMAIL PROTECTED]> wrote: > >> Mensanator wrote: > >>> On Oct 13, 2:43 pm, <[EMAIL PROTECTED]> wrote: > Hi, > I just stumbled upon the following issue (I am running Debian)

Re: gmpy and counting None

2008-10-14 Thread Robert Kern
Mensanator wrote: On Oct 13, 5:16 pm, Robert Kern <[EMAIL PROTECTED]> wrote: Mensanator wrote: On Oct 13, 2:43 pm, <[EMAIL PROTECTED]> wrote: Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) [GCC 4.3.2] on linux2 Type

Re: gmpy and counting None

2008-10-14 Thread Mensanator
On Oct 13, 5:16 pm, Robert Kern <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > On Oct 13, 2:43 pm, <[EMAIL PROTECTED]> wrote: > >> Hi, > > >> I just stumbled upon the following issue (I am running Debian): > > >> $ python > >> Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) > >> [GCC 4.3.2] on

Re: gmpy and counting None

2008-10-13 Thread casevh
On Oct 13, 12:43 pm, <[EMAIL PROTECTED]> wrote: > Hi, > > I just stumbled upon the following issue (I am running Debian): > > $ python > Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> [2, > None].

Re: gmpy and counting None

2008-10-13 Thread Robert Kern
Mensanator wrote: On Oct 13, 2:43 pm, <[EMAIL PROTECTED]> wrote: Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.>>> [2, No

Re: gmpy and counting None

2008-10-13 Thread Mensanator
On Oct 13, 2:43 pm, <[EMAIL PROTECTED]> wrote: > Hi, > > I just stumbled upon the following issue (I am running Debian): > > $ python > Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> [2, > None].c

gmpy and counting None

2008-10-13 Thread mmanns
Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [2, None].count(None) 1 >>> from gmpy import mpz >>> [mpz(2), None].count

Re: Counting Elements in an xml file

2008-08-31 Thread Gerard flanagan
Ouray Viney wrote: Hi All: I am looking at writing a python script that will let me parse a TestSuite xml file that contains n number of TestCases. My goal is to be able to count the elements base on a key value pair in the xml node. Example I would like to be able to count the number of T

Re: Counting Elements in an xml file

2008-08-30 Thread Ouray Viney
On Aug 30, 2:17 pm, Paul Boddie <[EMAIL PROTECTED]> wrote: > On 30 Aug, 19:37, Ouray Viney <[EMAIL PROTECTED]> wrote: > > > > > > > > I would like to be able to count the number of TestCases that contain > > the "execute=true" but not the ones that contain "execute=false". > > With XPath-capable l

Re: Counting Elements in an xml file

2008-08-30 Thread Paul Boddie
On 30 Aug, 19:37, Ouray Viney <[EMAIL PROTECTED]> wrote: > > > > I would like to be able to count the number of TestCases that contain > the "execute=true" but not the ones that contain "execute=false". With XPath-capable libraries, it should be enough to execute an XPath query on the document. F

Re: Counting Elements in an xml file

2008-08-30 Thread Fredrik Lundh
Ouray Viney wrote: I am looking at writing a python script that will let me parse a TestSuite xml file that contains n number of TestCases. My goal is to be able to count the elements base on a key value pair in the xml node. Example I would like to be able to count the number of TestCases

Re: Counting Elements in an xml file

2008-08-30 Thread Marco Bizzarri
On Sat, Aug 30, 2008 at 7:37 PM, Ouray Viney <[EMAIL PROTECTED]> wrote: > Hi All: > > I am looking at writing a python script that will let me parse a > TestSuite xml file that contains n number of TestCases. > > My goal is to be able to count the elements base on a key > value pair in the xml nod

Counting Elements in an xml file

2008-08-30 Thread Ouray Viney
Hi All: I am looking at writing a python script that will let me parse a TestSuite xml file that contains n number of TestCases. My goal is to be able to count the elements base on a key value pair in the xml node. Example I would like to be able to count the number of TestCases that contain

Re: Multipart - Counting the amount of Values for One key

2008-08-29 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <[EMAIL PROTECTED]> >escribi�: > >> I am trying to find the amount of values there are pertaining to one key. >> >> For example: >> >> - To find the average of the value

Re: Multipart - Counting the amount of Values for One key

2008-08-29 Thread Gabriel Genellina
En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <[EMAIL PROTECTED]> escribi�: I am trying to find the amount of values there are pertaining to one key. For example: - To find the average of the values pertaining to the key. - Use the amount of values to calculate a histogram What is a "mul

Multipart - Counting the amount of Values for One key

2008-08-29 Thread Ron Brennan
hello, I am trying to find the amount of values there are pertaining to one key. For example: - To find the average of the values pertaining to the key. - Use the amount of values to calculate a histogram Also, how do reference a specific value for a key in a multipart? Thanks, Ron -- FYI,

Re: Help counting the total number of dictionaries inside a list that contain a specified key value

2008-08-12 Thread Peter Otten
Jon Bowlas wrote: > Hrmm, any ideas why I'd be getting 'SyntaxError: invalid syntax' for > both of these? > >> sum(u'Level 2 Courses' in dct for dct in yourlist) >> q = set(['1']); print q, sum(d.get('level') in q for d in thelist) > > The error occurs at the 'for' > I'm afraid I can't use Pete

Re: Help counting the total number of dictionaries inside a list that contain a specified key value

2008-08-12 Thread Christian Heimes
Jon Bowlas wrote: I'm afraid I can't use Peters suggestion as I'm using python 2.3 and it doesn't have the collection module. Thanks anyway. Python 2.3 is the reason. It doesn't support the generator expression syntax. Try sum([u'Level 2 Courses' in dct for dct in yourlist]) or len([1 for dct

  1   2   3   4   >