Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-09 Thread Danny Yoo
By the way, there's a nice book by Kent Beck called "Test Driven Development by Example" that might be helpful to look at: http://en.wikipedia.org/wiki/Test-Driven_Development_by_Example ___ Tutor maillist - Tutor@python.org To unsubscribe or chang

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-09 Thread Amit Saha
On Sun, Dec 8, 2013 at 8:22 PM, Rafael Knuth wrote: > Hey there, > > I struggle to understand what unit testing specifically means in > practice and how to actually write unit tests for my code (my gut is > telling me that it's a fairly important concept to understand). > > Over the last few days

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 09:27 PM, Alan Gauld wrote: On 09/12/13 17:57, Roel Schroeven wrote: You are right in a sense, but this is what int() does, isn't it? No. int() can be done in several ways... spir should have said "..., but this is what str() does, ..." I think. Doh! Yes, that makes sense I

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Alan Gauld
On 09/12/13 23:46, Steven D'Aprano wrote: Python has two different quote characters ' and " so you can use one for delimiters and the other inside the string: And if you need both you can also use triple quotes. If you need both, you can escape the one that matches the delimiter: s = 'this

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Steven D'Aprano
On Mon, Dec 09, 2013 at 11:14:38PM +, J Sutar wrote: > Steven, I updated the very last line of code as below, as I need to get the > word wrapped around quotes. Is that a good way of achieving that? [...] > writer.writerow([str(n) + " " + chr(34) + s + chr(34) for n, s in >

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Danny Yoo
> > I'm trying to write to csv a string which contains double quotation >> marks and a comma however I'm finding that the write reads the comma as a >> delimiter. If try wrap the string around double quotes it clashes with the >> raw quotes originally within the string text (which I'd like to/must

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread J Sutar
Thanks all. Yes csv module make it whole lot easier. I did try using it before posting to list but couldn't get it working for some reason. Steven, I updated the very last line of code as below, as I need to get the word wrapped around quotes. Is that a good way of achieving that? import csv word

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Steven D'Aprano
On Mon, Dec 09, 2013 at 09:52:34PM +, J Sutar wrote: > I'm trying to write to csv a string which contains double quotation marks > and a comma however I'm finding that the write reads the comma as a > delimiter. If try wrap the string around double quotes it clashes with the > raw quotes origi

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Alan Gauld
On 09/12/13 22:28, Dave Angel wrote: On Mon, 09 Dec 2013 20:27:38 +, Alan Gauld wrote: Incidentally, I just remembered another completely different way to do it, although I can't recall how it works! Unfortunately it doesn't work for 10, 20, ... Ah, I knew it must be too good to be tru

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Dave Angel
On Tue, 10 Dec 2013 09:28:32 +1100, Steven D'Aprano wrote: Joel, You don't appear to have actually written anything in your response. Every line in your post starts with a ">" quoting J Sutar's original post, with nothing new added apart from your signature at the end. I cannot read eithe

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Joel Goldstick
On Mon, Dec 9, 2013 at 5:28 PM, Steven D'Aprano wrote: > Joel, > > You don't appear to have actually written anything in your response. > Every line in your post starts with a ">" quoting J Sutar's original > post, with nothing new added apart from your signature at the end. > > > More 'google (g

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Steven D'Aprano
Joel, You don't appear to have actually written anything in your response. Every line in your post starts with a ">" quoting J Sutar's original post, with nothing new added apart from your signature at the end. On Mon, Dec 09, 2013 at 04:57:50PM -0500, Joel Goldstick wrote: > On Mon, Dec 9,

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Dave Angel
On Mon, 09 Dec 2013 20:27:38 +, Alan Gauld wrote: Incidentally, I just remembered another completely different way to do it, although I can't recall how it works! Maybe one of the math gurus can explain it, and how to extend it. This version only works for 2 digit numbers... and has a huge g

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread Joel Goldstick
On Mon, Dec 9, 2013 at 4:52 PM, J Sutar wrote: > # Re-sending from registered email address #. > > Hi, > > Posting for first time so hope I get the forum etiquette and rules right, > please let me know otherwise. > > I'm trying to write to csv a string which contains double quotation marks > and

[Tutor] Writing to CSV string containing quote and comma

2013-12-09 Thread J Sutar
# Re-sending from registered email address #. Hi, Posting for first time so hope I get the forum etiquette and rules right, please let me know otherwise. I'm trying to write to csv a string which contains double quotation marks and a comma however I'm finding that the write reads the comma as a

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Alan Gauld
On 09/12/13 17:57, Roel Schroeven wrote: You are right in a sense, but this is what int() does, isn't it? No. int() can be done in several ways... spir should have said "..., but this is what str() does, ..." I think. Doh! Yes, that makes sense I should have realized. All in all I think

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Roel Schroeven
Alan Gauld schreef: On 09/12/13 13:48, spir wrote: On 12/09/2013 02:29 PM, Wolfgang Maier wrote: spir gmail.com> writes: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. ... also the pure numbers approach pointed out by me and Alan. You are right in

Re: [Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread Marc Tompkins
On Sun, Dec 8, 2013 at 8:46 PM, Varuna Seneviratna < varunasenevira...@gmail.com> wrote: > But what is meant by "A *namespace* is a mapping from names to objects" > Steven touched on this, but I'd like to emphasize: in Python, EVERYTHING is an object - variables, functions, integers, strings, you

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Dave Angel
On Mon, 09 Dec 2013 17:00:49 +0100, spir wrote: On 12/09/2013 03:49 PM, Alan Gauld wrote: > On 09/12/13 13:48, spir wrote: >> On 12/09/2013 02:29 PM, Wolfgang Maier wrote: >> You are right in a sense, but this is what int() does, isn't it? > No. int() can be done in several ways but usually it

Re: [Tutor] No module named '_tkinter' ***solved***

2013-12-09 Thread pierre dagenais
On 13-12-09 03:14 AM, eryksun wrote: > On Sun, Dec 8, 2013 at 2:36 PM, pierre dagenais wrote: >> I'm running Ubuntu 10.04 and I've installed python 3.3.3 from the >> tarball at http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz >> >> Here is the error I get when trying to run tkinter. >> >>

Re: [Tutor] No module named '_tkinter'

2013-12-09 Thread pierre dagenais
On 13-12-08 10:57 PM, Reuben wrote: > Can you try importing the module '_tkinter' > On 09-Dec-2013 6:43 AM, "pierre dagenais" wrote: > >> Hi, >> I'm running Ubuntu 10.04 and I've installed python 3.3.3 from the >> tarball at http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz >> >> Here is t

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 03:49 PM, Alan Gauld wrote: On 09/12/13 13:48, spir wrote: On 12/09/2013 02:29 PM, Wolfgang Maier wrote: spir gmail.com> writes: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. ... also the pure numbers approach pointed out by me and A

Re: [Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread Alan Gauld
On 09/12/13 04:46, Varuna Seneviratna wrote: do not understand what is meant by "A /namespace/ is a mapping from names to objects". How I understand to be a namespace is a particular space within which a particular name is unique. That's correct. But a name on its own can refer to anything. Bu

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Alan Gauld
On 09/12/13 13:48, spir wrote: On 12/09/2013 02:29 PM, Wolfgang Maier wrote: spir gmail.com> writes: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. ... also the pure numbers approach pointed out by me and Alan. You are right in a sense, but this i

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Wolfgang Maier
spir gmail.com> writes: > > On 12/09/2013 02:29 PM, Wolfgang Maier wrote: > > spir gmail.com> writes: > > > >> > >> Tu sum it up (aha!): you algorithm is the right and only one > > > > No, it's not the only one. It's certainly the most obvious one, but there is > > also the pure numbers approac

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 02:29 PM, Wolfgang Maier wrote: spir gmail.com> writes: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. It's certainly the most obvious one, but there is also the pure numbers approach pointed out by me and Alan. You are right in a sen

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 02:42 PM, Rafael Knuth wrote: Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. It's certainly the most obvious one, but there is also the pure numbers approach pointed out by me and Alan. So far I received 7 different alternative suggestion

Re: [Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread spir
On 12/09/2013 05:46 AM, Varuna Seneviratna wrote: Let’s begin with some definitions. A *namespace* is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that’s normally not noticeable in any way (except for performance), and it may change in t

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Rafael Knuth
>> Tu sum it up (aha!): you algorithm is the right and only one > > No, it's not the only one. It's certainly the most obvious one, but there is > also the pure numbers approach pointed out by me and Alan. So far I received 7 different alternative suggestions, both pure numbers & mixed int/str app

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Wolfgang Maier
spir gmail.com> writes: > > Tu sum it up (aha!): you algorithm is the right and only one No, it's not the only one. It's certainly the most obvious one, but there is also the pure numbers approach pointed out by me and Alan. ___ Tutor maillist -

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread spir
On 12/09/2013 09:08 AM, Rafael Knuth wrote: Hej there, I wrote a program that converts an integer into a digit sum: def DigitSum(YourNumber): DigitList = [] YourNumber = str(YourNumber) for i in YourNumber: DigitList.append(int(i)) print(sum(DigitList)) DigitSum(55

Re: [Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread Steven D'Aprano
On Mon, Dec 09, 2013 at 10:16:30AM +0530, Varuna Seneviratna wrote: > I do not understand what is meant by "A *namespace* is a mapping from names > to objects". How I understand to be a namespace is a particular space > within which a particular name is unique.For a example within the space set >

Re: [Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread Amit Saha
On Mon, Dec 9, 2013 at 2:46 PM, Varuna Seneviratna wrote: >> Let’s begin with some definitions. >> >> A namespace is a mapping from names to objects. Most namespaces are >> currently implemented as Python dictionaries, but that’s normally not >> noticeable in any way (except for performance), and

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Alan Gauld
On 09/12/13 08:08, Rafael Knuth wrote: def DigitSum(YourNumber): DigitList = [] YourNumber = str(YourNumber) for i in YourNumber: DigitList.append(int(i)) print(sum(DigitList)) DigitSum(55) 10 It actually works but I was wondering if that's the only way to solve th

[Tutor] What is a namespace? What is meant by "A namespace is a mapping from names to objects"

2013-12-09 Thread Varuna Seneviratna
> > Let’s begin with some definitions. > > A *namespace* is a mapping from names to objects. Most namespaces are > currently implemented as Python dictionaries, but that’s normally not > noticeable in any way (except for performance), and it may change in the > future. Examples of namespaces are: t

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Oscar Benjamin
On 9 December 2013 08:08, Rafael Knuth wrote: > Hej there, > > I wrote a program that converts an integer into a digit sum: > > def DigitSum(YourNumber): > DigitList = [] > YourNumber = str(YourNumber) > for i in YourNumber: > DigitList.append(int(i)) > print(sum(DigitList)

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Wolfgang Maier
Rafael Knuth gmail.com> writes: > > Hej there, > > I wrote a program that converts an integer into a digit sum: > > def DigitSum(YourNumber): > DigitList = [] > YourNumber = str(YourNumber) > for i in YourNumber: > DigitList.append(int(i)) > print(sum(DigitList)) > > D

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Rafael Knuth
Thanks, guys - got it! I was suspecting that my solution is too complex and that there must be a simpler way to convert integers into a digit sum. Have a great morning/day/evening, Raf On Mon, Dec 9, 2013 at 9:23 AM, Amit Saha wrote: > On Mon, Dec 9, 2013 at 6:08 PM, Rafael Knuth wrote: >> Hej t

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Asokan Pichai
On Mon, Dec 9, 2013 at 1:38 PM, Rafael Knuth wrote: > Hej there, > > I wrote a program that converts an integer into a digit sum: > > def DigitSum(YourNumber): > DigitList = [] > YourNumber = str(YourNumber) > for i in YourNumber: > DigitList.append(int(i)) > print(sum(Dig

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Amit Saha
On Mon, Dec 9, 2013 at 6:08 PM, Rafael Knuth wrote: > Hej there, > > I wrote a program that converts an integer into a digit sum: > > def DigitSum(YourNumber): > DigitList = [] > YourNumber = str(YourNumber) > for i in YourNumber: > DigitList.append(int(i)) > print(sum(Digi

Re: [Tutor] No module named '_tkinter'

2013-12-09 Thread eryksun
On Sun, Dec 8, 2013 at 2:36 PM, pierre dagenais wrote: > I'm running Ubuntu 10.04 and I've installed python 3.3.3 from the > tarball at http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz > > Here is the error I get when trying to run tkinter. > > ImportError: No module named '_tkinter' > > I'v

[Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-09 Thread Rafael Knuth
Hej there, I wrote a program that converts an integer into a digit sum: def DigitSum(YourNumber): DigitList = [] YourNumber = str(YourNumber) for i in YourNumber: DigitList.append(int(i)) print(sum(DigitList)) DigitSum(55) >>> 10 It actually works but I was wondering if