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

2012-05-09 Thread J. Mwebaze
I have a  bunch of objects of the same type. Each object has a version
attribute and this refers to source code that was used to make the object.
SouceCode is maintained in separate files. eg.
myclass_01.py, myclass_02.py, myclass_03.py, myclass_04.py ..

During object instantiaton, i would like to use  the specific class, that
corresponds to the version of the class that was used to create the object.
However i cant know the specific "myclass_??.py" before i read the version
attribute of the object.

Seems like a situation where i have to partially instantiate the object to
read the version attribute, and after that continue with instantiaton with
the specific version of the version..

Is this doeable?
-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting 1172026 entries

2012-05-06 Thread J. Mwebaze
I noticed the error in code please ignore this post..

On Sun, May 6, 2012 at 6:29 PM, J. Mwebaze  wrote:

> sorry see, corrected code
>
>
> for filename in txtfiles:
>temp=[]
>f=open(filename)
>for line in f.readlines():
>  line = line.strip()
>  line=line.split()
>  temp.append((parser.parse(line[0]), float(line[1])))
>temp=sorted(temp)
>with open(filename.strip('.txt')+ '.sorted', 'wb') as p:
> for i, j in temp:
>    p.write('%s %s\n' %(str(i),j))
>
>
> On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze  wrote:
>
>> I have attached one of the files, try to sort and let me know the
>> results.  Kindly sort by date. ooops - am told the file exceed 25M.
>>
>> below is the code
>>
>> import glob
>> txtfiles =glob.glob('*.txt')
>> import dateutil.parser as parser
>>
>>
>> for filename in txtfiles:
>>temp=[]
>>f=open(filename)
>>for line in f.readlines():
>>  line = line.strip()
>>  line=line.split()
>>  temp.append((parser.parse(line[0]), float(line[1])))
>>temp=sorted(temp)
>>with open(filename.strip('.txt')+ '.sorted', 'wb') as p:
>> for i, j in temp:
>>p.write('%s %s\n' %(str(i),j))
>>
>>
>> On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre 
>> wrote:
>>
>>> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze  wrote:
>>> > [ (datatime, int) ] * 1172026
>>>
>>> I can't duplicate slowness. It finishes fairly quickly here. Maybe you
>>> could try posting specific code? It might be something else that is
>>> making your program take forever.
>>>
>>> >>> x = [(datetime.datetime.now() +
>>> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _
>>> in xrange(1172026)]
>>> >>> random.shuffle(x)
>>> >>> x.sort()
>>> >>>
>>>
>>> -- Devin
>>>
>>
>>
>>
>> --
>> *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze
>> |  skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze
>>
>> /* Life runs on code */*
>>
>>
>
>
> --
> *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze
> |  skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze
>
> /* Life runs on code */*
>
>


-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting 1172026 entries

2012-05-06 Thread J. Mwebaze
sorry see, corrected code


for filename in txtfiles:
   temp=[]
   f=open(filename)
   for line in f.readlines():
 line = line.strip()
 line=line.split()
 temp.append((parser.parse(line[0]), float(line[1])))
   temp=sorted(temp)
   with open(filename.strip('.txt')+ '.sorted', 'wb') as p:
for i, j in temp:
   p.write('%s %s\n' %(str(i),j))


On Sun, May 6, 2012 at 6:26 PM, J. Mwebaze  wrote:

> I have attached one of the files, try to sort and let me know the results.
>  Kindly sort by date. ooops - am told the file exceed 25M.
>
> below is the code
>
> import glob
> txtfiles =glob.glob('*.txt')
> import dateutil.parser as parser
>
>
> for filename in txtfiles:
>temp=[]
>f=open(filename)
>for line in f.readlines():
>  line = line.strip()
>  line=line.split()
>  temp.append((parser.parse(line[0]), float(line[1])))
>temp=sorted(temp)
>with open(filename.strip('.txt')+ '.sorted', 'wb') as p:
> for i, j in temp:
>        p.write('%s %s\n' %(str(i),j))
>
>
> On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre 
> wrote:
>
>> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze  wrote:
>> > [ (datatime, int) ] * 1172026
>>
>> I can't duplicate slowness. It finishes fairly quickly here. Maybe you
>> could try posting specific code? It might be something else that is
>> making your program take forever.
>>
>> >>> x = [(datetime.datetime.now() +
>> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _
>> in xrange(1172026)]
>> >>> random.shuffle(x)
>> >>> x.sort()
>> >>>
>>
>> -- Devin
>>
>
>
>
> --
> *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze
> |  skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze
>
> /* Life runs on code */*
>
>


-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting 1172026 entries

2012-05-06 Thread J. Mwebaze
I have attached one of the files, try to sort and let me know the results.
 Kindly sort by date. ooops - am told the file exceed 25M.

below is the code

import glob
txtfiles =glob.glob('*.txt')
import dateutil.parser as parser


for filename in txtfiles:
   temp=[]
   f=open(filename)
   for line in f.readlines():
 line = line.strip()
 line=line.split()
 temp.append((parser.parse(line[0]), float(line[1])))
 temp=sorted(temp)
 with open(filename.strip('.txt')+ '.sorted', 'wb') as p:
for i, j in temp:
   p.write('%s %s\n' %(str(i),j))


On Sun, May 6, 2012 at 6:21 PM, Devin Jeanpierre wrote:

> On Sun, May 6, 2012 at 12:11 PM, J. Mwebaze  wrote:
> > [ (datatime, int) ] * 1172026
>
> I can't duplicate slowness. It finishes fairly quickly here. Maybe you
> could try posting specific code? It might be something else that is
> making your program take forever.
>
> >>> x = [(datetime.datetime.now() +
> datetime.timedelta(random.getrandbits(10)), random.getrandbits(32)) for _
> in xrange(1172026)]
> >>> random.shuffle(x)
> >>> x.sort()
> >>>
>
> -- Devin
>



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting 1172026 entries

2012-05-06 Thread J. Mwebaze
On Sun, May 6, 2012 at 6:09 PM, Devin Jeanpierre wrote:

> On Sun, May 6, 2012 at 11:57 AM, J. Mwebaze  wrote:
> > I have several lists with approx 1172026 entries. I have been trying to
> sort
> > the records, but have failed.. I tried lists.sort() i also trired sorted
> > python's inbuilt method. This has been running for weeks.
>
> Sorting 1172026 random floats takes about 1.5 seconds to do on my
> machine. More complicated objects take more time, but usually not that
> much more time. What exactly are you sorting?
>
> -- Devin
>

[ (datatime, int) ] * 1172026
-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorting 1172026 entries

2012-05-06 Thread J. Mwebaze
On Sun, May 6, 2012 at 6:07 PM, Benjamin Schollnick  wrote:

>
> On May 6, 2012, at 11:57 AM, J. Mwebaze wrote:
>
> I have several lists with approx 1172026 entries. I have been trying to
> sort the records, but have failed.. I tried lists.sort() i also trired
> sorted python's inbuilt method. This has been running for weeks.
>
> Any one knows of method that can handle such lists.
>
>
> The issue there is the sheer size of the list.  I can't think of an
> algorithium that wouldn't have a problem with a list of that size.
>
> Two suggestions
>
> 1) Is there no other way to organize this data, other than having it in a
> single list?  You can't organize it by, for example, zip code, area code,
> year, or something, and make multiple lists?  Reducing the size would speed
> the sort up.
>
> 2) Maybe consider a different storage method, for example, adding the data
> into a database?  And then connecting to the database via python?
>
> - Benjamin
>
>
I could try the database option..



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


sorting 1172026 entries

2012-05-06 Thread J. Mwebaze
I have several lists with approx 1172026 entries. I have been trying to
sort the records, but have failed.. I tried lists.sort() i also trired
sorted python's inbuilt method. This has been running for weeks.

Any one knows of method that can handle such lists.

cheers



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compute a delta: the difference between lists of strings

2012-05-05 Thread J. Mwebaze
thank Chris..

On Sat, May 5, 2012 at 2:39 PM, Chris Angelico  wrote:k

> On Sat, May 5, 2012 at 10:12 PM, J. Mwebaze  wrote:
> > This is out of curiosity, i know this can be done with python diffllib
> > module, but been figuring out how to compute the delta, Consider two
> lists
> > below.
> >
> > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C']
> > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z']
> >
> > This is the result should be
> >
> > ['  e', '+ A', '+ B', '  f', '  g', '- A', '- B', '  C', '  D', '- C', '+
> > z']
> >
> > ideas on how to approach this.. ?
>
> Here's a simple algorithm that produces sorta-mostly-reasonable
> results most of the time:
>
> Set your current-position-index to the beginning of each lists. (Call
> them 'pos1' and 'pos2'.)
> If s1[pos1] and s2[pos2] are identical, match - increment and iterate.
> Otherwise, increment pos2 until either it matches pos1 or you reach
> the end of s2.
> If you find a match, report the insertion into s2, increment both
> pointers past the match, and carry on.
> If you hit the end of s2, increment pos1 once and report an insertion
> into s1, then go back to looking for a match.
>
> It helps to append a sentinel to each list; that way, you don't need
> to separately check for additional content at the end of either list
> (as the sentinel won't match any of the strings).
>
> This is the algorithm I used for writing a simple file diff tool ages
> ago. It's not as good as diff(1), but it was fun to do the exercise.
> It's quite inefficient at handling large insertions into s1, and needs
> to be modified for most file handling (for instance, requiring a
> 2-line or 3-line rematch after a difference, to avoid matching on
> blank lines), but it's a basis.
>
> Producing beautiful or minimal diffs is a more complex task. :)
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


try/except in a loop

2012-05-02 Thread J. Mwebaze
I have multiple objects, where any of them can serve my purpose.. However
some objects might not have some dependencies. I can not tell before hand
if the all the dependencies exsit. What i want to is begin processing from
the 1st object, if no exception is raised, i am done.. if an exception is
raised, the next object is tried, etc  Something like

objs = [... ]
try:
  obj = objs[0]
  obj.make()
except Exception, e:
  try:
  obj = objs[1]
  obj.make()
  except Exception, e:
 try:
obj = objs[2]
obj.make()
 except Exception, e:
   continue

The problem is the length of the list of objs is variable... How can i do
this?



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code help for understand

2012-05-02 Thread J. Mwebaze
if you are referring to the line
*
*
*if __name__ == '__main__':*
*
*
Find a good explanation here
*
*
http://stackoverflow.com/questions/419163/what-does-if-name-main-do



On Wed, May 2, 2012 at 2:30 PM, viral shah  wrote:

> Hi
>
> in every .py file I found this same code line on the below side
>
> *def main():
> application = webapp.WSGIApplication([('/', MainHandler)],
>  debug=True)
> run_wsgi_app(application)
>
>
> if __name__ == '__main__':
> main()
> *
> can anyone explain me what's the all this thing suggest?
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


algorithm does python use to compare two strings

2012-04-29 Thread J. Mwebaze
I am just wondering which specific algorithm does python use to compare two
strings.  Could it be the  Longest common subsequence is the most u

Regards

-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


class versions and object deserialization

2012-04-24 Thread J. Mwebaze
We have classes of this form classA version1, classA version2, classA
version3 .. etc. This is same class that has been modified. Each
"modification" creates a new version of a class. Each object has a version
attribute which refers to the version of the class from which it was
derived. egObjectA.version =1 # means it was derived from ClassA version1

Here is my problem. During object de-serializing, i would like to use the
specific version of the class that was used to used to make the object. For
example, if i am de-serializing object ObjectA withversion=3 then ClassA
version 3 should be used. Source code for all the different variations of
the classes is stored.

This looks getting the object first the get the class. Any idea on how to
approach this?

-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


CFG for python

2012-03-28 Thread J. Mwebaze
Anyone knows how to create control-flow-graph for python.. After searching
around, i found  this article,
http://www.python.org/dev/peps/pep-0339/#ast-to-cfg-to-bytecode  and also a
reference to http://doc.pypy.org/en/latest/objspace.html#the-flow-model

However, i stil cant figure out what how to create the CFG from the
two references.
Regards
-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Message passing between python objects

2012-03-19 Thread J. Mwebaze
I am trying to learn about the interaction between python objects. One
thing i have often read is that objects interact by sending messages to
other objects to invoke corresponding methods. I am specifically interested
in tracing these messages and also probably log the messages for further
scrutiny. I would like to build a provenance kind of system.


Regards
-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list