Re: [Tutor] TDD in Python

2016-09-26 Thread Steven D'Aprano
Hi Angela, and welcome! My comments below, interleaved with yours. On Mon, Sep 26, 2016 at 09:54:18PM +0100, angela ebirim wrote: [...] > I'm keen to learn about testing my Python code and hoping someone could > help me with this query... > > #test.py > > class Test: >def __init__(self, m

Re: [Tutor] Unicode to Ascii

2016-09-26 Thread Steven D'Aprano
On Tue, Sep 27, 2016 at 03:46:25AM +0530, srinivas devaki wrote: > How can I convert Unicode to Ascii by stripping of any non ascii characters. > > one way is to filter on s like > > ascii = ''.join(filter(lambda x: 0 <= ord(x) < 256, unicode_string)) > > but are there any other simple ways ? S

Re: [Tutor] unicode decode/encode issue

2016-09-26 Thread Steven D'Aprano
I'm sorry, I have misinterpreted your question. On Mon, Sep 26, 2016 at 12:59:04PM -0400, bruce wrote: > I've got a page from a web fetch. I'm simply trying to go from utf-8 to > ascii. Why would you do that? It's 2016, not 1953, and ASCII is well and truly obsolete. (ASCII was even obsolete i

Re: [Tutor] event loop vs threads

2016-09-26 Thread Steven D'Aprano
Hi Srinivas, On Sat, Sep 24, 2016 at 01:09:46PM +0530, srinivas devaki wrote: > how does Python switch execution and maintain context i.e function stack > etc,.. for co-routines and why is it less costly than switching threads > which almost do the same, and both are handled by Python Interpreter

[Tutor] Unicode to Ascii

2016-09-26 Thread srinivas devaki
How can I convert Unicode to Ascii by stripping of any non ascii characters. one way is to filter on s like ascii = ''.join(filter(lambda x: 0 <= ord(x) < 256, unicode_string)) but are there any other simple ways ? Regards Srinivas Devaki Senior (final yr) student at Indian Institute of Technol

[Tutor] TDD in Python

2016-09-26 Thread angela ebirim
Hello everyone, I'm a new member on this maling list and am in the process of learning python. I'm keen to learn about testing my Python code and hoping someone could help me with this query... #test.py class Test: def __init__(self, members): self.members = members def printMe

Re: [Tutor] unicode decode/encode issue

2016-09-26 Thread bruce
Hey folks. (peter!) Thanks for the reply. I wound up doing: #s=s.replace('\u2013', '-') #s=s.replace(u'\u2013', '-') #s=s.replace(u"\u2013", "-") #s=re.sub(u"\u2013", "-", s) s=s.encode("ascii", "ignore") s=s.replace(u"\u2013", "-") s=s.replace("–", "-") ##<<< this was actually in

Re: [Tutor] python coding problem

2016-09-26 Thread Ben Finney
Alex Hall writes: > On Mon, Sep 26, 2016 at 11:35 AM, Richard Koeman > wrote: > > > def maximum(n1, n2): > > print "the first number is" ,n1 > > print "the second number is", n2 > > if n1 > n2: > > return > > Using the 'return' keyword will return whatever follows it (nothing, in > thi

Re: [Tutor] python coding problem

2016-09-26 Thread Ramanathan Muthaiah
> > This is my first time using this so I hope it works. > I am trying to find out why this code doesnt work. > Its simple. I want to find out which number is bigger. > Welcome! > > I hope you can help and that I am using this python feature properly. > Thanks. > The function prints the first t

Re: [Tutor] python coding problem

2016-09-26 Thread Alex Hall
On Mon, Sep 26, 2016 at 11:35 AM, Richard Koeman wrote: > This is my first time using this so I hope it works. > I am trying to find out why this code doesnt work. > Its simple. I want to find out which number is bigger. > > I hope you can help and that I am using this python feature properly. >

Re: [Tutor] CSR generation script

2016-09-26 Thread Alan Gauld via Tutor
On 23/09/16 23:12, Srinivas Naga Kotaru (skotaru) wrote: > I am using pyOpenSSL module to automate CSR generation. Don't assume we know what that means. I know what pyOpenSSL is, but have no idea what CSR means to you. (To me it means Customer Service Representative!) > Not much self-explanatory

Re: [Tutor] python coding problem

2016-09-26 Thread Alan Gauld via Tutor
On 26/09/16 16:35, Richard Koeman wrote: > The function prints the first two print statements then nothing else > happens. > > def maximum(n1, n2): > print "the first number is" ,n1 > print "the second number is", n2 We know this works so far, so that's fine. > if n1 > n2: > return B

Re: [Tutor] unicode decode/encode issue

2016-09-26 Thread Peter Otten
bruce wrote: > Hi. > > Ive got a "basic" situation that should be simpl. So it must be a user > (me) issue! > > > I've got a page from a web fetch. I'm simply trying to go from utf-8 to > ascii. I'm not worried about any cruft that might get stripped out as the > data is generated from a us sit

Re: [Tutor] python coding problem

2016-09-26 Thread Danny Yoo
Hi Richard, The "return" statement does an early escape out of the currently running function. You have a "return" statement in your program that looks unintentional. In an ideal world, the Python compiler would give a warning about this because it's a common mistake. Unfortunately it looks lik

[Tutor] python coding problem

2016-09-26 Thread Richard Koeman
This is my first time using this so I hope it works. I am trying to find out why this code doesnt work. Its simple. I want to find out which number is bigger. I hope you can help and that I am using this python feature properly. Thanks. The function prints the first two print statements then noth

Re: [Tutor] unicode decode/encode issue

2016-09-26 Thread Steven D'Aprano
On Mon, Sep 26, 2016 at 12:59:04PM -0400, bruce wrote: > When I look at the input content, I have : > > u'English 120 Course Syllabus \u2013 Fall \u2013 2006' > > So, any pointers on replacing the \u2013 with a simple '-' (dash) (or I > could even handle just a ' ' (space) You misinterpret wha

[Tutor] unicode decode/encode issue

2016-09-26 Thread bruce
Hi. Ive got a "basic" situation that should be simpl. So it must be a user (me) issue! I've got a page from a web fetch. I'm simply trying to go from utf-8 to ascii. I'm not worried about any cruft that might get stripped out as the data is generated from a us site. (It's a college/class dataset