Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Charles Hixson

On 01/20/2014 08:14 PM, Dan Stromberg wrote:

On Mon, Jan 20, 2014 at 12:09 PM, Charles Hixson
 wrote:


class RODict:
 #Instance Variable Doc
 ##@var_ddict
 #This variable holds the reference to the dict.

 ##Class initializer.
 #@paramddictThe data dictionary to which this is a read only
 #access.
 #@throwsTypeError if ddict is not a dict.
 def __init__ (self, ddict = {}):
 if not isinstance(ddict, dict):
 raiseTypeError("ddict must be a dict.  It is " +
repr(ddict))
 self._ddict=ddict

When I see this isinstance, I think "Gee, that means none of the
dict-like-objects I recently compared would work with this class."

The comparison is at the URL below; all the things compared are trees
that provide a dictionary-like interface, but also find_min, find_max
and can iterate in key order.  I don't think any of them inherit from
dict, but they are all dict-like in a duck-typed sense:

http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/

HTH

Well, it would mean you couldn't create instances of this class from 
them.  I haven't yet specified the eq and ne methods, but they'd 
probably be something like:

def ne(self, key):
return self._ddict.ne(key)
(I'd need to look up the precise names of the comparison routines. 
Perhaps it would be "__ne__" rather than "ne".)
So if they'd work with a normal dict, they should work with this, for 
comparison.


Note that this is a dict-alike, and therefore not in a predictable 
order.  If the items were to be ordered, however, they would be in order 
by the value rather than by the key, as my use-case is most likely to 
want to access the items with the highest value most often.   I may even 
decide to use a list of lists, but a dict yields simpler code, even if I 
suspect that lists might be more efficient. But the choice of list would 
mean I could use a tuple, which because it is standard would also tend 
to make things simpler.  (It wouldn't, however, allow background 
updating, as dictviews do, and also RODict does, so I'd need to find 
some way to manage that...probably meaning that I'd need to regenerate 
them more often.)


-- Charles Hixson
--
https://mail.python.org/mailman/listinfo/python-list


Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Dan Stromberg
On Mon, Jan 20, 2014 at 12:09 PM, Charles Hixson
 wrote:

> class RODict:
> #Instance Variable Doc
> ##@var_ddict
> #This variable holds the reference to the dict.
>
> ##Class initializer.
> #@paramddictThe data dictionary to which this is a read only
> #access.
> #@throwsTypeError if ddict is not a dict.
> def __init__ (self, ddict = {}):
> if not isinstance(ddict, dict):
> raiseTypeError("ddict must be a dict.  It is " +
> repr(ddict))
> self._ddict=ddict

When I see this isinstance, I think "Gee, that means none of the
dict-like-objects I recently compared would work with this class."

The comparison is at the URL below; all the things compared are trees
that provide a dictionary-like interface, but also find_min, find_max
and can iterate in key order.  I don't think any of them inherit from
dict, but they are all dict-like in a duck-typed sense:

http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Charles Hixson

On 01/20/2014 04:08 PM, Chris Angelico wrote:

On Tue, Jan 21, 2014 at 7:09 AM, Charles Hixson
 wrote:

#@note Instances can be created only from existing dicts.

 ##Class initializer.
 #@paramddictThe data dictionary to which this is a read only
 #access.
 #@throwsTypeError if ddict is not a dict.
 def __init__ (self, ddict = {}):
 if not isinstance(ddict, dict):
 raiseTypeError("ddict must be a dict.  It is " +
repr(ddict))
 self._ddict=ddict

Instead of demanding that a dict (or dict subclass) be passed, why not
simply pass all args on to dict() itself? Is there a reason this won't
work?

def __init__(self, *args, **kwargs):
 self._ddict = dict(*args, **kwargs)

ChrisA
It would work, as long as it would work for dict(), but I have been 
expecting to use it in situations where it would be useful to have a 
different access to the dict that would be writeable.  So I didn't 
bother.  (Well, and took steps to ensure that it was being used in the 
manner that I expected.  So I'd know to change it if it were 
appropriate.)  It *would* make it more difficult for the class to test 
it's creation arguments for sanity, though.  (One could argue that 
allowing read only access to an empty dict is violating sanity, but I 
don't think in any dangerous way.)  I do sometimes worry that using 
isinstance excessively is overly expensive.  Perhaps I should wrap them 
with a test for debug mode.



--
Charles Hixson

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


Re: Implementing append within a descriptor

2014-01-20 Thread Chris Angelico
On Tue, Jan 21, 2014 at 12:07 PM, Joseph L. Casale
 wrote:
> foo = MyClass()
> # This calls __set__
> foo.some_property = [x for x in range(5)]
> # This bypasses __set__ obviously.
> foo.some_property.append(5)
>
> So re-implementing my own list class has the draw back for the user that he 
> must create the
> data type is assigning directly. I want to avoid this. What workaround can I 
> leverage to catch
> the append event so I can avoid the new data type?

You're going to have to subclass list if you want to intercept its
methods. As I see it, there are two ways you could do that: when it's
set, or when it's retrieved. I'd be inclined to do it in __set__, but
either could work. In theory, you could make it practically invisible
- just check to see if you're trying to __set__ a list, and if you
are, set a magical list instead.

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


Implementing append within a descriptor

2014-01-20 Thread Joseph L. Casale
I have a caching non data descriptor that stores values in the implementing 
class
instances __dict__.

Something like:

class Descriptor:
def __init__(self, func, name=None, doc=None):
self.__name__ = name or func.__name__
self.__module__ = func.__module__
self.__doc__ = doc or func.__doc__
self.func = func

def __get__(self, obj, _=None):
if obj is None:
return self
value = obj.__dict__.get(self.__name__, None)
if value is None:
value = self.func(obj)
obj.__dict__[self.__name__] = value
return value

def __set__(self, obj, value):
obj.__dict__[self.__name__] = value

def __delete__(self, obj):
if self.__name__ in obj.__dict__:
del obj.__dict__[self.__name__]

For the classes that decorate a method with this and accept list type data, I 
need to catch the
following scenario (__set__ is reimplemented for the specific property by 
subclassing Descriptor):

foo = MyClass()
# This calls __set__
foo.some_property = [x for x in range(5)]
# This bypasses __set__ obviously.
foo.some_property.append(5)

So re-implementing my own list class has the draw back for the user that he 
must create the
data type is assigning directly. I want to avoid this. What workaround can I 
leverage to catch
the append event so I can avoid the new data type?

Thanks,
jlc




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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Steven D'Aprano
On Mon, 20 Jan 2014 09:08:28 -0500, Roy Smith wrote:

> In article ,
>  Chris Angelico  wrote:
> 
>> On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg 
>> wrote:
>> > I did a short time of teaching while I was in school.  If three
>> > students all turned in the same assignment, they all got docked
>> > significantly.  There was no "who copied off of whom?", it was
>> > "someone shared when they shouldn't have."
>> 
>> What a wonderful way to promote an attitude of "my code is MY CODE and
>> should never leave my sight". What a delightful way of thinking to
>> unleash on the world.
> 
> That's a little harsh.  Working in groups, and sharing code, are
> important parts of how software gets developed today.  Those
> collaborative work habits should indeed be taught.  But, school is also
> about evaluation of progress.  At the end of the class, the teacher
> needs some objective way to figure out how much each student has learned
> and assign a grade.  It's hard to do that if people aren't handing in
> assignments done individually.

An objective way to figure out individual progress is easy. It's called 
an "exam" or "test". Admittedly, it's normally only practical for 
examinations to last no more than a day for senior students, and an hour 
or maximum two hours for junior students, and some subjects are more 
easily tested this way than others. But you can still examine a lot in a 
couple of hours. If you're interested in accurately measuring the 
learning of individual students, there is at least one pretty damning 
problem with assignments: just because student X puts his name on the 
paper doesn't mean student X wrote the paper. Assignments are effectively 
based on the honour system, and we know how well that works. For those 
with the money to spend, you need not do a lick of work to get an A.

Perhaps that's why Harvard has just given up even trying to distinguish 
the students who learn things from those who don't? Forget George Bush's 
"Gentleman's C", Harvard now practically gives A's away to anyone who 
shows up (and pays the fees).

http://qz.com/153694/the-most-commonly-awarded-grade-at-harvard-is-an-a/

Presumably they're protecting their business model. Students are 
customers, and if your customers are paying a small fortune to attend, 
they need to get something in return. Knowledge is good, but you can't 
put knowledge on a CV or frame it and put it on a wall.

It would be interesting to think about the incentives which have lead to 
an over-reliance on take-home assignments rather than exams, as well as 
the pros and cons of one versus the other. Don't get me wrong, there are 
advantages to assignments as well, but I think that the total prohibition 
on collaboration is misguided. The question in my mind is how to 
encourage students to learn from each other rather than to merely 
mechanically copy from each other?

Relevant:

http://qz.com/157579/confession-of-an-ivy-league-teaching-assistant-heres-why-i-inflated-grades/


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


Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Chris Angelico
On Tue, Jan 21, 2014 at 7:09 AM, Charles Hixson
 wrote:
> #@note Instances can be created only from existing dicts.
>
> ##Class initializer.
> #@paramddictThe data dictionary to which this is a read only
> #access.
> #@throwsTypeError if ddict is not a dict.
> def __init__ (self, ddict = {}):
> if not isinstance(ddict, dict):
> raiseTypeError("ddict must be a dict.  It is " +
> repr(ddict))
> self._ddict=ddict

Instead of demanding that a dict (or dict subclass) be passed, why not
simply pass all args on to dict() itself? Is there a reason this won't
work?

def __init__(self, *args, **kwargs):
self._ddict = dict(*args, **kwargs)

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


Re: Diving in to Python - Best resources?

2014-01-20 Thread Chris Angelico
On Tue, Jan 21, 2014 at 6:50 AM, Emile van Sebille  wrote:
> On 1/20/2014 11:34 AM, Matt Watson wrote:
>
>> My question to you guys is... for someone like me, what route would you
>> take to learning Python?
>
>
> I'd work my way through the tutorial [1] then pick a work based project and
> start right in.  Ask questions along the way.
>
> [1] http://docs.python.org/2/tutorial/

I'd agree, except that I'd use this link [2] instead, and a Python 3.x
interpreter. Unless you have a good reason for writing Python 2 code
and learning Python 2, skip it and go straight to Py3.

ChrisA

[2] http://docs.python.org/3/tutorial/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Charles Hixson

On 01/20/2014 12:52 PM, Peter Otten wrote:

Charles Hixson wrote:


This is just a first sketch, and I haven't yet attempted to test it, so
what I'm hoping for is criticisms on the general approach.

class RODict:
  def __init__ (self, ddict = {}):

Default values are evaluted just once when the method is created. Mutable
default values mean trouble:


class D:

... def __init__(self, dict={}):
... self.dict = dict
... def __setitem__(self, key, value):
... self.dict[key] = value
... def __repr__(self): return repr(self.dict)
...

d1 = D()
d2 = D()
d1[1] = 42
d2[2] = 42
d1

{1: 42, 2: 42}

d2

{1: 42, 2: 42}


  if not isinstance(ddict, dict):
  raiseTypeError("ddict must be a dict.  It is " +
repr(ddict))
  self._ddict=ddict

I think instead of the type check I would build a new dict from the
argument. The usual initializers

dict({1:2, 3:4})
dict([(1,2), (3,4)])
dict(a=1, b=2)

should work with your read-only dict.


  ##Test for containment.
  #@paramkeyThe item to be found.
  #@returnTrueIf key is in the instance, otherwise False.

Docstrings are usually prefered over comments like the above.


  def __contains__(self, key):
  returnkey in self._ddict

Did you know

http://docs.python.org/dev/library/collections.abc.html#collections.abc.Mapping

Subclass from it to ensure that all the usuall methods are defined.

That link, 
http://docs.python.org/dev/library/collections.abc.html#collections.abc.Mapping 
, is a very good one.  I hadn't realized that it separated Mapping from 
MutableMapping.
It would be nice if there were some examples of it's usage around, 
though.  I can't really tell how to use it.  (E.g., it mixes in 
__contains__, but it doesn't show how to specify what you are testing 
for cotainment in.  So it looks as if I need to specify everything 
anyway because I can't tell what might be implemented in some 
inappropriate way.)  OTOH, it's a good list of what needs to be 
implemented.  (I see that I left out implementation of eq and ne, which 
is pretty straightfoward, but apparently needed (unless it's 
automatically being handled by the mixin...which I can't tell).


--
Charles Hixson

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


Re: matlabFunction Equivalent?

2014-01-20 Thread Mark Lawrence

On 20/01/2014 22:09, rpi.bal...@gmail.com wrote:

Hey all,

I'm new at Python, so if you see any mistakes feel free to let me know.

I'm trying to take a symbolic expression and turn it into a variable equation 
or function. I think that just an expression of variables would be preferable.

I have a range equation which I form using symbols and then take various 
derivatives of it. I then want to have these derivatives on hand to use for 
various functions, but short of using sub every time or just copy pasting from 
the console output (I don't want to do that), I can't find an efficient way to 
do this. Matlab had matlabFunction which was really handy, but I don't think 
Python has an equivalent.


import numpy as np
import scipy as sp
import sympy as sy
import math as ma

x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y 
z x_s y_s z_s theta theta_dot x_dot y_dot z_dot')

rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + 
y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5)

rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) 
+ theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - 
y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - 
z_dot*z_s)/rho

drho_dx = sy.diff(rho, x)

drho_dy = sy.diff(rho, y)

drho_dz = sy.diff(rho, z)

#I then want drho_dx, etc to be variable expressions with x, y, z, etc as 
variables instead of symbols or numbers. I could do:

x, y, z = 1200, 1300, 1400 #m

drho_dx = subs([x, x], [y, y], [z, z])

#but this seems inefficient to do multiple times. Thoughts?



There are references to MatlabFunction in code here 
https://github.com/scipy/scipy/tree/master/scipy/io/matlab but I haven't 
the faintest idea as to whether or not it does what you want, sorry :(


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


[ANN] pypiserver 1.1.5 - minimal private pypi server

2014-01-20 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.1.5 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

https://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

I didn't announce the previous version, so here's the changelog for the
last two versions:

1.1.5 (2014-01-20)
--
- only list devpi-server and proxypypi as alternatives
- fix wheel file handling for certain wheels
- serve wheel files as application/octet-stream
- make pypiserver executable from wheel file
- build universal wheel
- remove scripts subdirectory
- add --index-url cli parameter

1.1.4 (2014-01-03)
--
- make pypiserver compatible with pip 1.5
  (https://github.com/schmir/pypiserver/pull/42)


-- 
Cheers
Ralf
-- 
https://mail.python.org/mailman/listinfo/python-list


matlabFunction Equivalent?

2014-01-20 Thread rpi . baldum
Hey all,

I'm new at Python, so if you see any mistakes feel free to let me know.

I'm trying to take a symbolic expression and turn it into a variable equation 
or function. I think that just an expression of variables would be preferable. 

I have a range equation which I form using symbols and then take various 
derivatives of it. I then want to have these derivatives on hand to use for 
various functions, but short of using sub every time or just copy pasting from 
the console output (I don't want to do that), I can't find an efficient way to 
do this. Matlab had matlabFunction which was really handy, but I don't think 
Python has an equivalent. 


import numpy as np
import scipy as sp
import sympy as sy
import math as ma

x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y 
z x_s y_s z_s theta theta_dot x_dot y_dot z_dot')

rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + 
y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5)

rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) 
+ theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - 
y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - 
z_dot*z_s)/rho

drho_dx = sy.diff(rho, x)

drho_dy = sy.diff(rho, y)

drho_dz = sy.diff(rho, z)

#I then want drho_dx, etc to be variable expressions with x, y, z, etc as 
variables instead of symbols or numbers. I could do:

x, y, z = 1200, 1300, 1400 #m

drho_dx = subs([x, x], [y, y], [z, z])

#but this seems inefficient to do multiple times. Thoughts?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Terry Reedy

On 1/20/2014 9:08 AM, Roy Smith wrote:


That's a little harsh.  Working in groups, and sharing code, are
important parts of how software gets developed today.  Those
collaborative work habits should indeed be taught.


Until recently, teaching collaboration through group projects has had 
the problem of leeching. Asking group members to grade each other's 
participation and contributions does not work too well. My daughter ran 
into this problem in her first programming class where 
private-until-done 'group' work was too much her work. In her second 
class, there was discussion of each other's coding problems *in the 
class*, in front of the teacher, and she enjoyed that much more.


It is now possible to run collaboration through software that records 
interaction. My daughter took a composition class where discussion and 
review of each other's work was recorded and contributed to each 
person's grade. But this was not collaborative writing, which would be 
another level of interaction, and one which is common beyond college 
classes.


A programming class (probably best after the first) could use a real 
(meaning, used outside of classes) repository and tracker. *That* would 
better prepare people for later work, whether on a job or as an 
open-source volunteer.


--
Terry Jan Reedy

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


Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Peter Otten
Peter Otten wrote:

> Charles Hixson wrote:
> 
>> This is just a first sketch, and I haven't yet attempted to test it, so
>> what I'm hoping for is criticisms on the general approach.
>> 
>> class RODict:
> 
>>  def __init__ (self, ddict = {}):
> 
> Default values are evaluted just once when the method is created. Mutable
> default values mean trouble:
> 
 class D:
> ... def __init__(self, dict={}):
> ... self.dict = dict
> ... def __setitem__(self, key, value):
> ... self.dict[key] = value
> ... def __repr__(self): return repr(self.dict)
> ...
 d1 = D()
 d2 = D()
 d1[1] = 42
 d2[2] = 42
 d1
> {1: 42, 2: 42}
 d2
> {1: 42, 2: 42}

D'oh, that was just and instintive reaction.

You may already know that... Of course it doesn't matter as long as no 
attempt is made to mutate the mutable value.

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


Re: 1st Sketch at at ReadOnly dict

2014-01-20 Thread Peter Otten
Charles Hixson wrote:

> This is just a first sketch, and I haven't yet attempted to test it, so
> what I'm hoping for is criticisms on the general approach.
> 
> class RODict:

>  def __init__ (self, ddict = {}):

Default values are evaluted just once when the method is created. Mutable 
default values mean trouble:

>>> class D:
... def __init__(self, dict={}):
... self.dict = dict
... def __setitem__(self, key, value):
... self.dict[key] = value
... def __repr__(self): return repr(self.dict)
... 
>>> d1 = D()
>>> d2 = D()
>>> d1[1] = 42
>>> d2[2] = 42
>>> d1
{1: 42, 2: 42}
>>> d2
{1: 42, 2: 42}

>  if not isinstance(ddict, dict):
>  raiseTypeError("ddict must be a dict.  It is " +
> repr(ddict))
>  self._ddict=ddict

I think instead of the type check I would build a new dict from the 
argument. The usual initializers

dict({1:2, 3:4})
dict([(1,2), (3,4)])
dict(a=1, b=2)

should work with your read-only dict.

> 
>  ##Test for containment.
>  #@paramkeyThe item to be found.
>  #@returnTrueIf key is in the instance, otherwise False.

Docstrings are usually prefered over comments like the above.

>  def __contains__(self, key):
>  returnkey in self._ddict

Did you know

http://docs.python.org/dev/library/collections.abc.html#collections.abc.Mapping

Subclass from it to ensure that all the usuall methods are defined.

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


The Beauties of Islam

2014-01-20 Thread BV BV
The Beauties of Islam
 

At this time in Islam’s history, when the entire religion is being judged by 
the actions of a few, it is appropriate to step back from the glare of the 
media spotlight and examine the beauties that infuse the way of life known as 
Islam. There is greatness and splendour in Islam that is often overshadowed by 
actions that have no place in Islam or by people who speak about topics they 
only vaguely understand. Islam is a religion, a way of life that inspires 
Muslims to try harder, reach farther and act in a manner that is pleasing to 
those around them and most importantly pleasing to their Creator.

The beauties of Islam are those things that are part of the religion and make 
Islam stand out. Islam answers all of humankind’s eternal questions. Where did 
I come from? Why am I here? Is this really all there is? It answers these 
questions with clarity and in a beautiful way. So then, let us begin our 
journey and discover and ponder over the beauties of Islam.

1.  The answers to all your questions about life are in the Quran
The Quran is a book detailing the glory of God and the wonder of His creation; 
it is also a testament to His Mercy and Justice. It is not a history book, a 
storybook, or a scientific textbook, although it does contain all of those 
genres and more. The Quran is God’s greatest gift to humanity – it is a book 
like no other, for it contains the answers to the mysteries of life. It answers 
the questions and asks us to look beyond materialism and see that this life is 
little more than a transient stop on the way to everlasting life. Islam gives a 
clear aim and purpose to life.

“And I (God) created not the jinn and humankind, except to worship Me (Alone).” 
(Quran 51:56)

Thus it is the most important book and Muslims have no doubt that it is exactly 
the same today as it was when it was first revealed to Prophet Muhammad, may 
God praise him. When we ask those most important questions, we want to be sure 
that the answers we receive are the truth. Knowing that the answers are coming 
from a book which is the unchanged Word of God, gives comfort and solace. When 
God revealed the Quran, He promised to preserve it. The words we read today are 
the same as those memorised and written down by the companions of Prophet 
Muhammad.

“It is We Who have sent down the remembrance (i.e. the Quran) and surely, We 
will guard it from corruption.” (Quran 15:9)

2.  True Happiness can be found in Islam
Rejoice and be happy, remain positive and be at peace. [1] This is what Islam 
teaches us, for all God’s commandments aim to bring happiness to the 
individual. The key to happiness is in understanding and worshipping God. This 
worship serves as a reminder of Him and keeps us always conscious of Him and 
hence we stay away from evil, committing injustices and oppression. It elevates 
us to being righteous and of good character. By following His commands, we lead 
a life that guides us to the best in all our affairs. When we lead such a 
meaningful life, then and only then are we able to see happiness all around us, 
at any given moment and even on the darkest of times. It is even there in the 
touch of a hand, in the smell of rain or newly mown grass, it is in a warm fire 
on a cold night or a cool breeze on a hot day. Simple pleasures can make our 
hearts truly happy because they are manifestations of God’s Mercy and Love.

The nature of the human condition means that amongst great sorrow can be 
moments of joy and sometimes in moments of despair we can find an anchor in the 
things that bring us happiness. Prophet Muhammad said, “Indeed amazing are the 
affairs of a believer! They are all for his benefit. If he is granted ease then 
he is thankful, and this is good for him.  And if he is afflicted with a 
hardship, he perseveres, and this is good for him.” [2]

3.  In Islam we can easily communicate with God at any time of day or night
Every member of the human race is born innately knowing that God is One. 
However those who do not know how to communicate with God or establish a 
relationship with Him tend to find their existence puzzling and sometimes even 
distressing. Learning to communicate with God and worshiping Him gives life a 
whole new meaning.

According to Islam, God is accessible at any time and in any place. We need 
only call on Him and He will answer the call. Prophet Muhammad advised us to 
call on God often. He told us that God said,

“I am just as My slave thinks I am, (i.e. I am able to do for him what he 
thinks I can do for him) and I am with him if He remembers Me. If he remembers 
Me in himself, I too, remember him in Myself; and if he remembers Me in a group 
of people, I remember him in a group that is better than they; and if he comes 
one span nearer to Me, I go one cubit nearer to him; and if he comes one cubit 
nearer to Me, I go a distance of two outstretched arms nearer to him; and if he 
comes to me walking, I go to him running.” [3]

1st Sketch at at ReadOnly dict

2014-01-20 Thread Charles Hixson
This is just a first sketch, and I haven't yet attempted to test it, so 
what I'm hoping for is criticisms on the general approach.


##Read Only dict class.
#@note Instances can be created only from existing dicts.
#@warningvalues within the RODict can be accessed, so if they hold
#references to other items, they can be altered.
class RODict:
#Instance Variable Doc
##@var_ddict
#This variable holds the reference to the dict.

##Class initializer.
#@paramddictThe data dictionary to which this is a read 
only

#access.
#@throwsTypeError if ddict is not a dict.
def __init__ (self, ddict = {}):
if not isinstance(ddict, dict):
raiseTypeError("ddict must be a dict.  It is " + 
repr(ddict))

self._ddict=ddict

##Test for containment.
#@paramkeyThe item to be found.
#@returnTrueIf key is in the instance, otherwise False.
def __contains__(self, key):
returnkey in self._ddict

##Pass along the __getitem call.
def __getitem__(self, key):
returnself._ddict.__getitem__(key)

##Pass along the get call.
def get (self, key, default = None):
returnself._ddict.get(key, default)

##Return a DictView of the items of the instance.
def items(self):
returnself._ddict.items()

##Return a DictView of the keys of the instance.
def keys(self):
returnself._ddict.keys()

##Return a DictView of the values of the instance.
def values(self):
returnself._ddict.values()


##Return the length of the dict.
def __len__(self):
returnlen(self._ddict)

--
Charles Hixson

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


Re: Diving in to Python - Best resources?

2014-01-20 Thread Emile van Sebille

On 1/20/2014 11:34 AM, Matt Watson wrote:


My question to you guys is... for someone like me, what route would you take to 
learning Python?


I'd work my way through the tutorial [1] then pick a work based project 
and start right in.  Ask questions along the way.


Emile


[1] http://docs.python.org/2/tutorial/

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


Diving in to Python - Best resources?

2014-01-20 Thread Matt Watson
Getting in the habit of dropping in a google group for any new project - 
everyone tends to be so helpful.

I work in the automotive sales industry(management) and find myself doing so 
many day to day tasks that could easily be automated. I'm a very tech saavy 
person, but after running in fear from a Javascript class in undergrad 8 years 
ago I haven't ever looked back. I simply had no interest because I saw no 
applications. 

Now that I have a solid career I see SO many applications for programming in my 
industry alone. Automating data movement/calculations from websites, 
spreadsheets, pricing, etc will be my primary use. I'm OK saying I didn't 
retain 1% of what I learned in the Javascript class, I've dabbled in HTML, I've 
tweaked code in Excel macros or AutoIt scripts, but I'd classify myself as a 
complete beginner in programming. 

Like a kid, I learn by tearing things apart and watching them tick. I have 
started the Code Academy on Python, but I'm not sure a constant IV dosage of 
adderall could keep my attention. I also run into exercises that absolutely 
lose me and I have to spend 30 minutes googling a solution because the lesson 
and hints are useless. 

My question to you guys is... for someone like me, what route would you take to 
learning Python? "Learn Python the Hard Way" sounds like a good route, but I 
prefer some testimony before I make a purchase. Again, I understand the details 
are the building blocks of programming, but I don't think I can handle writing 
10 lines of true/false (boolean right?) calculations on Code Academy only for 
the next course to speak a foreign language to me. Any other methods you would 
suggest? I've even considered auditing a college class if I can find one for 
Python.

Thanks in advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex multiple patterns in order

2014-01-20 Thread Mark Lawrence

On 20/01/2014 17:09, Neil Cerutti wrote:

On 2014-01-20, Devin Jeanpierre  wrote:

On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence
 wrote:

On 20/01/2014 16:04, Neil Cerutti wrote:

I use regular expressions regularly, for example, when
editing text with gvim. But when I want to use them in Python
I have to contend with the re module. I've never become
comfortable with it.


You don't have to, there's always the "new" regex module
that's been on pypi for years.  Or are you saying that you'd
like to use regex but other influences that are outside of
your sphere of control prevent you from doing so?


I don't see any way in which someone uncomfortable with the re
module would magically find themselves perfectly at home with
the regex module. The regex module is the re module with some
extra features (and complexity), is it not?


It's a negative feedback loop. I'd have to use it more often than
I do to get comfortable. There's no way a library, even a really
good one, can compete with built-in syntax support. The BDFL must
have wanted it to be this way.



Regex was originally scheduled to go into 3.3 and then 3.4 but not made 
it.  I assume that it will again be targeted in the 3.5 release 
schedule. Three strikes and you're out is a BDFL plan?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: regex multiple patterns in order

2014-01-20 Thread Mark Lawrence

On 20/01/2014 17:06, Rustom Mody wrote:

On Monday, January 20, 2014 10:10:32 PM UTC+5:30, Devin Jeanpierre wrote:

On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote:

On 20/01/2014 16:04, Neil Cerutti wrote:

I use regular expressions regularly, for example, when editing
text with gvim. But when I want to use them in Python I have to
contend with the re module. I've never become comfortable with
it.

You don't have to, there's always the "new" regex module that's been on pypi
for years.  Or are you saying that you'd like to use regex but other
influences that are outside of your sphere of control prevent you from doing
so?



I don't see any way in which someone uncomfortable with the re module
would magically find themselves perfectly at home with the regex
module. The regex module is the re module with some extra features
(and complexity), is it not?


I wonder whether the re/regex modules are at fault?
Or is it that in a manual whose readability is otherwise exemplary the re pages
are a bit painful

eg reading http://docs.python.org/2/library/re.html#module-contents
the first thing one reads is compile



http://docs.python.org/3/library/re.html gives "re — Regular expression 
operations" and 
http://docs.python.org/3/library/re.html#regular-expression-syntax gives 
"Regular Expression Syntax".  Are you saying that the module contents 
should come before both of these?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: regex multiple patterns in order

2014-01-20 Thread Rustom Mody
On Monday, January 20, 2014 10:10:32 PM UTC+5:30, Devin Jeanpierre wrote:
> On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote:
> > On 20/01/2014 16:04, Neil Cerutti wrote:
> >> I use regular expressions regularly, for example, when editing
> >> text with gvim. But when I want to use them in Python I have to
> >> contend with the re module. I've never become comfortable with
> >> it.
> > You don't have to, there's always the "new" regex module that's been on pypi
> > for years.  Or are you saying that you'd like to use regex but other
> > influences that are outside of your sphere of control prevent you from doing
> > so?

> I don't see any way in which someone uncomfortable with the re module
> would magically find themselves perfectly at home with the regex
> module. The regex module is the re module with some extra features
> (and complexity), is it not?

I wonder whether the re/regex modules are at fault?
Or is it that in a manual whose readability is otherwise exemplary the re pages
are a bit painful

eg reading http://docs.python.org/2/library/re.html#module-contents
the first thing one reads is compile
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex multiple patterns in order

2014-01-20 Thread Neil Cerutti
On 2014-01-20, Devin Jeanpierre  wrote:
> On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence
>  wrote:
>> On 20/01/2014 16:04, Neil Cerutti wrote:
>>> I use regular expressions regularly, for example, when
>>> editing text with gvim. But when I want to use them in Python
>>> I have to contend with the re module. I've never become
>>> comfortable with it.
>>
>> You don't have to, there's always the "new" regex module
>> that's been on pypi for years.  Or are you saying that you'd
>> like to use regex but other influences that are outside of
>> your sphere of control prevent you from doing so?
>
> I don't see any way in which someone uncomfortable with the re
> module would magically find themselves perfectly at home with
> the regex module. The regex module is the re module with some
> extra features (and complexity), is it not?

It's a negative feedback loop. I'd have to use it more often than
I do to get comfortable. There's no way a library, even a really
good one, can compete with built-in syntax support. The BDFL must
have wanted it to be this way.

-- 
Neil Cerutti

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


Re: regex multiple patterns in order

2014-01-20 Thread Devin Jeanpierre
On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence  wrote:
> On 20/01/2014 16:04, Neil Cerutti wrote:
>> I use regular expressions regularly, for example, when editing
>> text with gvim. But when I want to use them in Python I have to
>> contend with the re module. I've never become comfortable with
>> it.
>>
>
> You don't have to, there's always the "new" regex module that's been on pypi
> for years.  Or are you saying that you'd like to use regex but other
> influences that are outside of your sphere of control prevent you from doing
> so?

I don't see any way in which someone uncomfortable with the re module
would magically find themselves perfectly at home with the regex
module. The regex module is the re module with some extra features
(and complexity), is it not?

-- Devin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex multiple patterns in order

2014-01-20 Thread Mark Lawrence

On 20/01/2014 16:04, Neil Cerutti wrote:

On 2014-01-20, Roy Smith  wrote:

In article
, Ben
Finney  wrote:

Be aware that regex is not the solution to all parsing
problems; for many parsing problems it is an attractive but
inappropriate tool. You may need to construct a more specific
parser for your needs. Even if it's possible with regex, the
resulting pattern may be so complex that it's better to write
it out more explicitly.


Oh, posh.

You are correct; regex is not the solution to all parsing
problems, but it is a powerful tool which people should be
encouraged to learn.  For some problems, it is indeed the
correct tool, and this seems like one of them.  Discouraging
people from learning about regexes is an educational
anti-pattern which I see distressingly often on this newsgroup.


I use regular expressions regularly, for example, when editing
text with gvim. But when I want to use them in Python I have to
contend with the re module. I've never become comfortable with
it.



You don't have to, there's always the "new" regex module that's been on 
pypi for years.  Or are you saying that you'd like to use regex but 
other influences that are outside of your sphere of control prevent you 
from doing so?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Rustom Mody
On Monday, January 20, 2014 7:38:28 PM UTC+5:30, Roy Smith wrote:
>  Chris Angelico wrote:

> > On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg wrote:
> > > I did a short time of teaching while I was in school.  If three
> > > students all turned in the same assignment, they all got docked
> > > significantly.  There was no "who copied off of whom?", it was
> > > "someone shared when they shouldn't have."
> > What a wonderful way to promote an attitude of "my code is MY CODE and
> > should never leave my sight". What a delightful way of thinking to
> > unleash on the world.

> That's a little harsh.  Working in groups, and sharing code, are 
> important parts of how software gets developed today.  Those 
> collaborative work habits should indeed be taught.  But, school is also 
> about evaluation of progress.  At the end of the class, the teacher 
> needs some objective way to figure out how much each student has learned 
> and assign a grade.  It's hard to do that if people aren't handing in 
> assignments done individually.

This position is a repeat of the position on whether print is a good
function for students to use: wearing teacher hat and professional
programmer hat give very different desiderata.

As an example of the need for multiple hats consider this scenario:

You are interviewing a programmer for a java job.  You ask the
candidate to explain quicksort.  Quick is the answer: java.util.lang.sort
[Im using java as example because the sort in python is not so
explicitly a quicksort]

You would find this answer unacceptable (hopefully)

On the other hand when that same programmer were on job, if instead
of using java.util.lang.sort he spent his time implementing one, you
would be equally peeved (hopefully!)

Most people dont get that education is like a game: Some games --
meccano, lego -- can be explicitly educative but any game can be put
to educational purpose.  Now you can stymie the purpose by saying: "I
find these rules arbitrary -- I refuse to play!" but that only
obstructs the process until some other rules/games are created.  And
will be seen to be fruitless once you get that all education is more
or less about bigger and smaller toys, ie unreality.

"Dont copy" is standard rule in edu-institutes. It should be
understood to be arbitrary and not some fundamental moral law, just as
"Dont hand-touch the ball" is a rule in football but not basketball.

Some people actually have fun making up new games -- a hybrid of
football and basketball?  More often people find it reasonable and fun 
to stay within the parameters of pre-existing rules.

As for Dan's "Punish the whole coterie rather than only the copycats"
rule: as a teacher I can say that fancy rules that are non-computable
are worse than useless.  So if this is more effective than the usual
"punish the copier" rule -- all power to you.  The only thing I would
add is this: Please close the feedback loop; ie check whether the
rules are serving their intended purpose.  Typically one finds that
beyond a point harsh rules are counterproductive. Probably related to
the fact that if your driving cycle is entirely carrot-n-stick, the
driven will become indistinguishable from mammals and repiles

At the other end of the spectrum is the interesting anecdote in "Zen
and the art of motorcycle maintenance." The author is teaching some
course and decides to abolish exams. The students who most strongly
revolt are bottom of the class -- ie those most likely to fail!!

Some more on my blog
http://blog.languager.org/2010/05/declaration-imperation-and-language.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex multiple patterns in order

2014-01-20 Thread Neil Cerutti
On 2014-01-20, Roy Smith  wrote:
> In article
> , Ben
> Finney  wrote:
>> Be aware that regex is not the solution to all parsing
>> problems; for many parsing problems it is an attractive but
>> inappropriate tool. You may need to construct a more specific
>> parser for your needs. Even if it's possible with regex, the
>> resulting pattern may be so complex that it's better to write
>> it out more explicitly.
>
> Oh, posh.
>
> You are correct; regex is not the solution to all parsing
> problems, but it is a powerful tool which people should be
> encouraged to learn.  For some problems, it is indeed the
> correct tool, and this seems like one of them.  Discouraging
> people from learning about regexes is an educational
> anti-pattern which I see distressingly often on this newsgroup.

I use regular expressions regularly, for example, when editing
text with gvim. But when I want to use them in Python I have to
contend with the re module. I've never become comfortable with
it.

-- 
Neil Cerutti

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


Re: regex multiple patterns in order

2014-01-20 Thread Roy Smith
In article ,
 Ben Finney  wrote:

> With a little experimenting I get:
> 
> >>> p = re.compile('((?:CAA)+)?((?:TCT)+)?((?:TA)+)?')
> >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
> [('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA'), ('', '', '')]

Perhaps a matter of style, but I would have left off the ?: markers and 
done this:

p = re.compile('((CAA)+)((TCT)+)((TA)+)')
m = p.match('CAACAACAATCTTCTTCTTCTTATATA')
print m.groups()

$ python r.py
('CAACAACAA', 'CAA', 'TCTTCTTCTTCT', 'TCT', 'TATATA', 'TA')

The ?: says, "match this group, but don't save it".  The advantage of 
that is you don't get unwanted groups in your match object.  The 
disadvantage is they make the pattern more difficult to read.  My 
personal opinion is I'd rather make the pattern easier to read and just 
ignore the extra matches in the output (in this case, I want groups 0, 
2, and 4).

I also left off the outer ?s, because I think this better represents the 
intent.  The pattern '((CAA)+)?((TCT)+)?((TA)+)?' matches, for example, 
an empty string; I suspect that's not what was intended.

> Be aware that regex is not the solution to all parsing problems; for
> many parsing problems it is an attractive but inappropriate tool. You
> may need to construct a more specific parser for your needs. Even if
> it's possible with regex, the resulting pattern may be so complex that
> it's better to write it out more explicitly.

Oh, posh.

You are correct; regex is not the solution to all parsing problems, but 
it is a powerful tool which people should be encouraged to learn.  For 
some problems, it is indeed the correct tool, and this seems like one of 
them.  Discouraging people from learning about regexes is an educational 
anti-pattern which I see distressingly often on this newsgroup.

Several lives ago, I worked in a molecular biology lab writing programs 
to analyze DNA sequences.  Here's a common problem: "Find all the places 
where GACGTC or TTCGAA (or any of a similar set of 100 or so short 
patterns appear".  I can't think of an easier way to represent that in 
code than a regex.

Sure, it'll be a huge regex, which may take a long time to compile, but 
one of the nice things about these sorts of problems) is that the 
patterns you are looking for tend not to change very often.  For 
example, the problem I mention in the preceding paragraph is finding 
restriction sites, i.e. the locations where restriction enzymes will cut 
a strand of DNA.  There's a finite set of commercially available 
restriction enzymes, and that list doesn't change from month to month 
(at this point, maybe even from year to year).

For more details, see 
http://bioinformatics.oxfordjournals.org/content/4/4/459.abstract

Executive summary: I wrote my own regex compiler which was optimized for 
the types of patterns this problem required.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg  wrote:
> > I did a short time of teaching while I was in school.  If three
> > students all turned in the same assignment, they all got docked
> > significantly.  There was no "who copied off of whom?", it was
> > "someone shared when they shouldn't have."
> 
> What a wonderful way to promote an attitude of "my code is MY CODE and
> should never leave my sight". What a delightful way of thinking to
> unleash on the world.

That's a little harsh.  Working in groups, and sharing code, are 
important parts of how software gets developed today.  Those 
collaborative work habits should indeed be taught.  But, school is also 
about evaluation of progress.  At the end of the class, the teacher 
needs some objective way to figure out how much each student has learned 
and assign a grade.  It's hard to do that if people aren't handing in 
assignments done individually.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write this as a list comprehension?

2014-01-20 Thread Rustom Mody
On Monday, January 20, 2014 4:32:40 PM UTC+5:30, Piet van Oostrum wrote:
> "Rhodri James" writes:

> > On Sat, 18 Jan 2014 16:00:45 -, Jussi Piitulainen wrote:

> [...]

> >> I would write that on three lines anyway, properly indented:
> >>   [ somefunc(mn,day,wd,name)
> >> for (then, name) in mylist
> >> let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ]
> >> It could be made to use existing keywords:
> >>   [ somefunc(mn,day,wd,name)
> >> for (then, name) in mylist
> >> with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ]
> > Better, in that it's readable.  It's still storing up trouble, though.
> > Seriously, what's inelegant about this?
> > def meaningful_name(then, name):
> > _,mn,dy,_,_,_,wd,_,_ = localtime(then)
> > return somefunc(mn, dy, wd, name)
> > ...
> > [meaningful_name(then, name) for (then, name) in mylist]
> > I assume there's some good reason you didn't want somefunc() to do the
> > localtime() itself?

> Actually in my use case somefunc(mn,day,wd,name) was an expression, not
> really a function call. I just presented it like that to make it a more
> generalised abstract case. So in my case that would introduce an
> additional function outside of the comprehension.

Nice! Thanks

One of things that people who decry comprehensions (and in general
hi-level constructs) dont understand is this:

One fundamental characteristic of increasing hi-level-ness of a programming
language is increased *freedom-in-naming* structures.

The 'structures' could be expressions, statements, or whatever is
the thing of the programming language.

A couple of examples will illustrate:

1. In most (imperative) programming languages when a computation is described
as a function it must willy-nilly be named. In lambda-calculus thats an option.

2. In any hi-level programming language, if we have an expression like
sqrt(b*b - 4*a*c)

we can choose to 'chunk it out' in a variety of ways:
1.
t = b*b - 4*a*c
sqrt(t)

2.
t1 = b*b
t2 = 4*a*c
t3 = t1 -t2
sqrt(t3)

Or the original: sqrt(b*b - 4*a*c)

The assembly language programmer has no such choice. He has to write
(the equivalent of)
t1 = b*b
t2 = 4*a
t3 = t2*c
t4 = t1 - t3
sqrt(t4)

Compared to a comprehension, a loop is in assembly-language category
since the list being 'comprehended' is compelled to be named.

And BTW thanks for the singleton list trick:
Sure 'v=e' is way neater than 'for v in [e]' but the for is better than nothing
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex multiple patterns in order

2014-01-20 Thread km
Aah! I understand now.
Thank you

Regards,
Krishna Mohan



On Mon, Jan 20, 2014 at 4:48 PM, Ben Finney wrote:

> km  writes:
>
> > I am trying to find sub sequence patterns but constrained by the order
> > in which they occur
>
> There are also specific resources for understanding and testing regex
> patterns, such as http://www.pythonregex.com/>.
>
> > For example
> >
> > >>> p = re.compile('(CAA)+?(TCT)+?(TA)+?')
> > >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
> > [('CAA', 'TCT', 'TA')]
> >
> > But I instead find only one instance of the CAA/TCT/TA in that order.
>
> Yes, because the grouping operator (the parens ‘()’) in each case
> contains exactly “CAA”, “TCT”, “TA”. If you want the repetitions to be
> part of the group, you need the repetition operator (in your case, ‘+’)
> to be part of the group.
>
> > How can I get 3 matches of CAA, followed by  four matches of TCT followed
> > by 2 matches of TA ?
>
> With a little experimenting I get:
>
> >>> p = re.compile('((?:CAA)+)?((?:TCT)+)?((?:TA)+)?')
> >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
> [('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA'), ('', '', '')]
>
> Remember that you'll get no more than one group returned for each group
> you specify in the pattern.
>
> > Well these patterns (CAA/TCT/TA) can occur any number of times and
> > atleast once so I have to use + in the regex.
>
> Be aware that regex is not the solution to all parsing problems; for
> many parsing problems it is an attractive but inappropriate tool. You
> may need to construct a more specific parser for your needs. Even if
> it's possible with regex, the resulting pattern may be so complex that
> it's better to write it out more explicitly.
>
> --
>  \ “To punish me for my contempt of authority, Fate has made me an |
>   `\   authority myself.” —Albert Einstein, 1930-09-18 |
> _o__)  |
> Ben Finney
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: regex multiple patterns in order

2014-01-20 Thread Ben Finney
km  writes:

> I am trying to find sub sequence patterns but constrained by the order
> in which they occur

There are also specific resources for understanding and testing regex
patterns, such as http://www.pythonregex.com/>.

> For example
>
> >>> p = re.compile('(CAA)+?(TCT)+?(TA)+?')
> >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
> [('CAA', 'TCT', 'TA')]
>
> But I instead find only one instance of the CAA/TCT/TA in that order.

Yes, because the grouping operator (the parens ‘()’) in each case
contains exactly “CAA”, “TCT”, “TA”. If you want the repetitions to be
part of the group, you need the repetition operator (in your case, ‘+’)
to be part of the group.

> How can I get 3 matches of CAA, followed by  four matches of TCT followed
> by 2 matches of TA ?

With a little experimenting I get:

>>> p = re.compile('((?:CAA)+)?((?:TCT)+)?((?:TA)+)?')
>>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
[('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA'), ('', '', '')]

Remember that you'll get no more than one group returned for each group
you specify in the pattern.

> Well these patterns (CAA/TCT/TA) can occur any number of times and
> atleast once so I have to use + in the regex.

Be aware that regex is not the solution to all parsing problems; for
many parsing problems it is an attractive but inappropriate tool. You
may need to construct a more specific parser for your needs. Even if
it's possible with regex, the resulting pattern may be so complex that
it's better to write it out more explicitly.

-- 
 \ “To punish me for my contempt of authority, Fate has made me an |
  `\   authority myself.” —Albert Einstein, 1930-09-18 |
_o__)  |
Ben Finney

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


Re: regex multiple patterns in order

2014-01-20 Thread Chris Angelico
On Mon, Jan 20, 2014 at 9:44 PM, km  wrote:
 p = re.compile('(CAA)+?(TCT)+?(TA)+?')
 p.findall('CAACAACAATCTTCTTCTTCTTATATA')
> [('CAA', 'TCT', 'TA')]
>
> But I instead find only one instance of the CAA/TCT/TA in that order.
> How can I get 3 matches of CAA, followed by  four matches of TCT followed by
> 2 matches of TA ?
> Well these patterns (CAA/TCT/TA) can occur any number of  times and atleast
> once so I have to use + in the regex.

You're capturing the single instance, not the repeated one. It is
matching against all three CAA units, but capturing just the first.
Try this:

>>> p = re.compile('((?:CAA)+)((?:TCT)+)((?:TA)+)')
>>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
[('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA')]

This groups "CAA" with non-capturing parentheses (?:regex) and then
captures that with the + around it.

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


Re: regex multiple patterns in order

2014-01-20 Thread Devin Jeanpierre
On Mon, Jan 20, 2014 at 2:44 AM, km  wrote:
> I am trying to find sub sequence patterns but constrained by the order in
> which they occur
> For example
>
 p = re.compile('(CAA)+?(TCT)+?(TA)+?')
 p.findall('CAACAACAATCTTCTTCTTCTTATATA')
> [('CAA', 'TCT', 'TA')]
>
> But I instead find only one instance of the CAA/TCT/TA in that order.
> How can I get 3 matches of CAA, followed by  four matches of TCT followed by
> 2 matches of TA ?
> Well these patterns (CAA/TCT/TA) can occur any number of  times and atleast
> once so I have to use + in the regex.

You want to include the '+' in the parens so that repetitions are
included in the match, but you still want to group CAA etc. together;
for that, you can use non-capturing groups.

I don't see how TA could ever match two, though. It'd match once
as-is, or thrice if you make the repetition greedy (get rid of the
?s).

>>> p = re.compile('((?:CAA)+?)((?:TCT)+?)((?:TA)+?)')
>>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
[('CAACAACAA', 'TCTTCTTCTTCT', 'TA')]

-- Devin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write this as a list comprehension?

2014-01-20 Thread Piet van Oostrum
"Rhodri James"  writes:

> On Sat, 18 Jan 2014 16:00:45 -, Jussi Piitulainen
>  wrote:

[...]

>> I would write that on three lines anyway, properly indented:
>>
>>   [ somefunc(mn,day,wd,name)
>> for (then, name) in mylist
>> let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ]
>>
>> It could be made to use existing keywords:
>>
>>   [ somefunc(mn,day,wd,name)
>> for (then, name) in mylist
>> with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ]
>
> Better, in that it's readable.  It's still storing up trouble, though.
>
> Seriously, what's inelegant about this?
>
> def meaningful_name(then, name):
> _,mn,dy,_,_,_,wd,_,_ = localtime(then)
> return somefunc(mn, dy, wd, name)
>
> ...
>
> [meaningful_name(then, name) for (then, name) in mylist]
>
> I assume there's some good reason you didn't want somefunc() to do the
> localtime() itself?

Actually in my use case somefunc(mn,day,wd,name) was an expression, not
really a function call. I just presented it like that to make it a more
generalised abstract case. So in my case that would introduce an
additional function outside of the comprehension.

Let me summarize what my problem really was: In a comprehension you
generally need local name(s), which can only be introduced with the
'for' construction. But then the name(s) must be bound to an element of
a sequence/iterator. There is no way to bind the name(s) to a single
object other than putting that object in a one element sequence. I was
just looking for a way to avoid that. Functional programming languages
have a way to do this with the 'let' or 'where' construction which is
missing in Python.

Thanks everybody for your thoughts on this.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


regex multiple patterns in order

2014-01-20 Thread km
I am trying to find sub sequence patterns but constrained by the order in
which they occur
For example

>>> p = re.compile('(CAA)+?(TCT)+?(TA)+?')
>>> p.findall('CAACAACAATCTTCTTCTTCTTATATA')
[('CAA', 'TCT', 'TA')]

But I instead find only one instance of the CAA/TCT/TA in that order.
How can I get 3 matches of CAA, followed by  four matches of TCT followed
by 2 matches of TA ?
Well these patterns (CAA/TCT/TA) can occur any number of  times and atleast
once so I have to use + in the regex.

Please let me know.
Thanks!

Regards,
Krishna mohan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: doctests compatibility for python 2 & python 3

2014-01-20 Thread Robin Becker

On 17/01/2014 21:10, Terry Reedy wrote:

On 1/17/2014 7:14 AM, Robin Becker wrote:


..

I never got how you are using doctests. There were certainly not meant for
heavy-duty unit testing, but for testing combined with explanation. Section
26.2.3.7. (in 3.3) Warnings warns that they are fragile to even single char
changes and suggests == as a workaround, as 'True' and 'False' will not change.
So I would not reject that option.

I have used some 'robust' True/False equality tests and also tests which return 
None or a string indicating the expected and observed outcomes eg




def equalStrings(a,b,enc='utf8'):
return a==b if type(a)==type(b) else asUnicode(a,enc)==asUnicode(b,enc)

def eqCheck(r,x):
if r!=x:
print('Strings unequal\nexp: %s\ngot: %s' % (ascii(x),ascii(r)))


of course I needed to import ascii from the future and the asUnicode function 
has to be different for python 3 and 2.


Some of our code used doctests which are discovered by a file search.
--
Robin Becker

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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Alister
On Sun, 19 Jan 2014 23:55:59 -0800, indar kumar wrote:

> Thanks all for help and positive comments. Actually, I tried to ask some
> questions but I was discouraged to do so saying that I was working on a
> project or some assignment. Truth be told I am stuck at one point and
> since I don't have experience with programming language, I have been
> working for it for two days but couldn't come up with some idea so
> posted some questions of the same format just to know whether there is
> particular method etc to do so. Hint would have been enough but I was
> strictly discouraged. You know the pain of working on assignment related
> to areas like socket programming and you even don't know how to use
> dictionaries and you are given only a week. Atleast I am trying to
> learn. The things that I am asking here are just basics on which my
> whole code would be building upon. But, as I said time is very less and
> have other courses also so wanted to know just the manipulation of
> dictionaries.
> 
> If you allow me I can post a small part of that assignment, it just
> requires the manipulation with dictionary which I am not getting. I am
> not asking to write a code for me. But a small hint would get me out of
> trouble.

General advise is post the smallest section of code that demonstrates 
your problem (It does not even have to be you actual code if it 
demonstrates the same issue).

It is also important to post the full trace back of any errors.
you should also try to understand these trace backs yourself they will 
become easier as you progress with the language
 



-- 
Your business will assume vast proportions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-20 Thread Alister
On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote:

> Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin:
>> On 18 January 2014 14:52, Jean Dupont  wrote:
>> >
>> > Thanks Peter and Terry Jan for the useful suggestions. One thing
>> > which I
>> >find a bit weird: when asking for Python-help concerning raspberry pi
>> >code
>> > or problems, a lot of people don't seem to be interested in helping
>> > out,
>> > that's of course their choice, but maybe they don't seem to be aware
>> > the raspberry pi is often the motivation for starting to learn to
>> > program in
>> >Python. And as such such a reaction is a bit disappointing.
>> Hi Jean,
>> What makes you say that? Did you previously ask questions about
>> Rasberry Pi code on this list?
> It was not about code but about python-coding in IDLE (that's the
> default on raspbian):
> I started a thread "[newbie] starting geany from within idle does not
> work" both here and in the raspberry pi forum. I just wondered why I
> never got an answer concerning that topic.
> 
>> If you did I wouldn't have answered those questions because I've never
>> used a Raspberry Pi and know nothing about them (except that they
>> encourage using Python somehow). I think that there's actually a list
>> that is specifically for Raspberry Pi Python questions that might be
>> more helpful although I don't know what it is...
> Here is the url to that forum
> 
> http://www.raspberrypi.org/forum/
> 
> kind regards,
> jean

Personally  use Geany  stand alone and not under idle, pressing F5 should 
save & run the code you are currently editing. Would running under idle 
give any other benefits? 



-- 
Cheese -- milk's leap toward immortality.
-- Clifton Fadiman, "Any Number Can Play"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread bryan rasmussen
>When you take a course, you should be learning, not just passing. That
>means that getting someone else to do your work for you is completely
>wrong, so I won't help you.

I have decided to become an MBA.



On Mon, Jan 20, 2014 at 9:48 AM, Chris Angelico  wrote:

> On Mon, Jan 20, 2014 at 6:55 PM, indar kumar 
> wrote:
> > Actually, I tried to ask some questions but I was discouraged to do so
> saying that I was working on a project or some assignment. Truth be told I
> am stuck at one point and since I don't have experience with programming
> language, I have been working for it for two days but couldn't come up with
> some idea so posted some questions of the same format just to know whether
> there is particular method etc to do so. Hint would have been enough but I
> was strictly discouraged.
> >
>
> Here's my policy on homework. Others may vary, but you'll find a lot
> will be broadly similar.
>
> When you take a course, you should be learning, not just passing. That
> means that getting someone else to do your work for you is completely
> wrong, so I won't help you. But if you've put down some code and it's
> not working, then by all means, ask for help with the details; it's
> easy if you have an error message you don't understand (you might be
> able to get that by Googling it), but a lot harder if you're getting
> output you don't understand, and then it can help a LOT to have an
> expert look at your code. You would need to post your code and exactly
> what you're seeing as wrong (exception traceback, or "expected this
> output, got this instead"); and if you make it clear up-front that
> it's homework and you're looking for hints rather than an
> answer-on-a-plate, I'm happy to help.
>
> What you will find, though, is that most requests are more of the
> nature of "please do my homework for me", so people are more likely to
> be annoyed than helpful when they see what's obviously homework. So
> you have a bit of an uphill battle just to get heard. But if you can
> show that you're here to learn - and showing that you've already
> written most of the code is a good way to do that - you can get help,
> and often a lot of it.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Chris Angelico
On Mon, Jan 20, 2014 at 6:55 PM, indar kumar  wrote:
> Actually, I tried to ask some questions but I was discouraged to do so saying 
> that I was working on a project or some assignment. Truth be told I am stuck 
> at one point and since I don't have experience with programming language, I 
> have been working for it for two days but couldn't come up with some idea so 
> posted some questions of the same format just to know whether there is 
> particular method etc to do so. Hint would have been enough but I was 
> strictly discouraged.
>

Here's my policy on homework. Others may vary, but you'll find a lot
will be broadly similar.

When you take a course, you should be learning, not just passing. That
means that getting someone else to do your work for you is completely
wrong, so I won't help you. But if you've put down some code and it's
not working, then by all means, ask for help with the details; it's
easy if you have an error message you don't understand (you might be
able to get that by Googling it), but a lot harder if you're getting
output you don't understand, and then it can help a LOT to have an
expert look at your code. You would need to post your code and exactly
what you're seeing as wrong (exception traceback, or "expected this
output, got this instead"); and if you make it clear up-front that
it's homework and you're looking for hints rather than an
answer-on-a-plate, I'm happy to help.

What you will find, though, is that most requests are more of the
nature of "please do my homework for me", so people are more likely to
be annoyed than helpful when they see what's obviously homework. So
you have a bit of an uphill battle just to get heard. But if you can
show that you're here to learn - and showing that you've already
written most of the code is a good way to do that - you can get help,
and often a lot of it.

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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Ben Finney
indar kumar  writes:

> Hint would have been enough but I was strictly discouraged.

You asked for private help, specifically to subvert the rules against
plagiarism you're subject to.

So no, I don't believe this modification of your request to be sincere.
You asked for help cheating, and you were refused. Please take a hint,
and do your assignment under the terms your teacher has set.

-- 
 \ “Holy tintinnabulation, Batman!” —Robin |
  `\   |
_o__)  |
Ben Finney

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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Ben Finney
Chris Angelico  writes:

> If Fred writes something and Bill copies it without acknowledging
> Fred's work, then Bill should be penalized. That much is clear.

The situation is where a student is being examined for skills where it's
appropriate to test the student's own skill with a reasonable level of
isolation from the relevant work of others.

So questions of plagiarism aren't relevant to that aspect.

> But why should Fred be punished? What has he done wrong?

Fred has, in your example, ignored the requirements to keep his own work
on the assignment isolated from Bill.

This is harmful to the assessment of both Bill and Fred, since the
teacher has a severely lessened ability to determine both Bill's and
Fred's individual competence levels at the skill being examined.

So, to encourage both Bill and Fred to keep their work isolated and
allow their levels of competence to be assessed with confidence, they
both need to have disincentive to both copy work and allow their work to
be copied.

> When it's less clear who copied from whom, I can understand issuing
> across-the-board penalties in the interests of fairness (and because
> the effort of figuring out who wrote what isn't worth it), but I'd say
> it's a compromise for simplicity rather than justifiable punishment on
> someone who published code.

Sure. Penalising both students – or, more precisely, advertising such
penalties from the start – seems like a much more fair and effective
measure than relying on the teacher to both detect the machinations of
ingenious students and to determine who copied from whom.

-- 
 \“Read not to contradict and confute, nor to believe and take |
  `\  for granted … but to weigh and consider.” —Francis Bacon |
_o__)  |
Ben Finney

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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread indar kumar
Thanks all for help and positive comments. Actually, I tried to ask some 
questions but I was discouraged to do so saying that I was working on a project 
or some assignment. Truth be told I am stuck at one point and since I don't 
have experience with programming language, I have been working for it for two 
days but couldn't come up with some idea so posted some questions of the same 
format just to know whether there is particular method etc to do so. Hint would 
have been enough but I was strictly discouraged. You know the pain of working 
on assignment related to areas like socket programming and you even don't know 
how to use dictionaries and you are given only a week. Atleast I am trying to 
learn. The things that I am asking here are just basics on which my whole code 
would be building upon. But, as I said time is very less and have other courses 
also so wanted to know just the manipulation of dictionaries. 

If you allow me I can post a small part of that assignment, it just requires 
the manipulation with dictionary which I am not getting. I am not asking to 
write a code for me. But a small hint would get me out of trouble. 

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


Re: Can post a code but afraid of plagiarism

2014-01-20 Thread Chris Angelico
On Mon, Jan 20, 2014 at 6:39 PM, Ben Finney  wrote:
> But sometimes different skills are being examined, and the student
> should be exercising skills on their own without basing it directly on
> the work of others. In these cases, penalties for plagiarism are
> appropriate, would you agree?

If Fred writes something and Bill copies it without acknowledging
Fred's work, then Bill should be penalized. That much is clear. That
aligns well with the requirement to see what each student can
accomplish, and with standard copyright law (including open source,
where requirement-to-acknowledge is a common part of both licensing
and courtesy). But why should Fred be punished? What has he done
wrong? If it can be proven that Fred wrote the code (granted, that's
hard to prove, but providing each student with a git/hg repo to push
code to every day would make it easier), he should be graded on that
code and not on the fact that someone else ripped it off.

When it's less clear who copied from whom, I can understand issuing
across-the-board penalties in the interests of fairness (and because
the effort of figuring out who wrote what isn't worth it), but I'd say
it's a compromise for simplicity rather than justifiable punishment on
someone who published code.

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