Re: [Tutor] Elementtree and pretty printing in Python 2.7

2010-08-22 Thread Stefan Behnel
Jerry Hill, 22.08.2010 16:51: Neither, as far as I know. The XML you get is perfectly valid XML. It's clearly well-formed, but I can't see it being valid without some kind of schema to validate it against. Note that the OP has already written a follow-up but forgot to reply to the origin

Re: [Tutor] continuous running of a method

2010-08-22 Thread Greg Bair
On 08/23/2010 01:10 AM, James Mills wrote: On Mon, Aug 23, 2010 at 3:00 PM, Greg Bair wrote: I have a method (I'll call it foo) that will either return None or an object depending on a random value generated. What I want to happen is that if I call foo(), i.e, f = foo() and it returns None

Re: [Tutor] continuous running of a method

2010-08-22 Thread James Mills
On Mon, Aug 23, 2010 at 3:00 PM, Greg Bair wrote: > I have a method (I'll call it foo) that will either return None or an object > depending on a random value generated.  What I want to happen is that if I > call foo(), i.e, f = foo() and it returns None, to re-call it until it > returns something

[Tutor] continuous running of a method

2010-08-22 Thread Greg Bair
I have a method (I'll call it foo) that will either return None or an object depending on a random value generated. What I want to happen is that if I call foo(), i.e, f = foo() and it returns None, to re-call it until it returns something else. I would think this would be done with a while l

Re: [Tutor] Writing a prime number program using upper bound of square root of n

2010-08-22 Thread Steven D'Aprano
On Mon, 23 Aug 2010 07:48:03 am Denis Gomes wrote: > Nick, > >If you are using python 2.X, xrange(2,n) is just like range(2,n), > the xrange function is faster. In python 3.X, they got rid of the > slower range function and renamed xrange to range. A slight over-simplification, but broadly co

Re: [Tutor] Writing a prime number program using upper bound of square root of n

2010-08-22 Thread Steven D'Aprano
On Mon, 23 Aug 2010 04:55:15 am Nick wrote: > Is there a way I can set my email program to insert the ">" symbol to > mark what I'm replying to without manually doing it? Depends on your mail client. What are you using? Outlook? > I get the picture now, that was a great example. I wrote some

Re: [Tutor] Writing a prime number program using upper bound of square root of n

2010-08-22 Thread Denis Gomes
Nick, If you are using python 2.X, xrange(2,n) is just like range(2,n), the xrange function is faster. In python 3.X, they got rid of the slower range function and renamed xrange to range. The x in [x for x in xrange...] will just go from 2 to the number n, but not including n. This brings u

Re: [Tutor] Writing a prime number program using upper bound of square root of n

2010-08-22 Thread Alan Gauld
"Nick" wrote Is there a way I can set my email program to insert the ">" symbol to mark what I'm replying to without manually doing it? Give us a clue. What is your email program? You can do it in most programs but the method will be different in each! HTH, -- Alan Gauld Author of the

Re: [Tutor] input problem

2010-08-22 Thread Nick Raptis
Please try and reply to the list instead of just me. raw_input did not the trick. fruit.count is the next exercise. Oke, I deleted the initialazion and change teller into letter. Roelof Should be alright now.. Hmmm Can you paste your exact code AND the error you're getting? As I understand

Re: [Tutor] input problem

2010-08-22 Thread Nick Raptis
On 08/22/2010 09:35 PM, Roelof Wobben wrote: Hello, I made this programm : def count_letters(n,a): count = 0 for char in n: if char == a: count += 1 return count fruit="" letter="" fruit= input("Enter a sort of fruit: ") teller = input("Enter the character which

Re: [Tutor] input problem

2010-08-22 Thread Alex Hall
On 8/22/10, Roelof Wobben wrote: > > Hello, > > > > I made this programm : > > > > def count_letters(n,a): > count = 0 > for char in n: > if char == a: > count += 1 > return count > > fruit="" > letter="" > fruit= input("Enter a sort of fruit: ") > teller = input("E

Re: [Tutor] Writing a prime number program using upper bound of square root of n

2010-08-22 Thread Nick
"1 * 120 = 120 2 * 60 = 120 3 * 40 = 120 4 * 30 = 120 5 * 24 = 120 6 * 20 = 120 8 * 15 = 120 10 * 12 = 120 10.9545 * 10.9545 = 120 12 * 10 = 120 <=== already seen this one! > Also I can write a program that > tests whether the number is a factor of 2, 3, 5, 7, but I think > you're trying to poin

Re: [Tutor] input problem

2010-08-22 Thread Nick Raptis
On 08/22/2010 09:35 PM, Roelof Wobben wrote: Hello, I made this programm : def count_letters(n,a): count = 0 for char in n: if char == a: count += 1 return count fruit="" letter="" fruit= input("Enter a sort of fruit: ") teller = input("Enter the character which

[Tutor] input problem

2010-08-22 Thread Roelof Wobben
Hello, I made this programm : def count_letters(n,a): count = 0 for char in n: if char == a: count += 1 return count fruit="" letter="" fruit= input("Enter a sort of fruit: ") teller = input("Enter the character which must be counted: ") x=count_letters (f

Re: [Tutor] type() problem

2010-08-22 Thread Roelof Wobben
Hello, Very wierd. >From a python shell it works. If a type it as module in SPE , it doesn't work. Roelof > Date: Sun, 22 Aug 2010 19:47:09 +0200 > From: knack...@googlemail.com > To: tutor@python.org > Subject: Re: [Tutor] type() problem > > > > fruit="ramadana" > > print "fruit

Re: [Tutor] type() problem

2010-08-22 Thread Knacktus
fruit="ramadana" print "fruit heeft als type", type(fruit) y=len(fruit) print y z=fruit[:3] print z These lines put in a module and executed print (using Python 2.7): fruit heeft als type 8 ram Strange that it doesn't work for you. I can only advice you to check the file again or run the

Re: [Tutor] Elementtree and pretty printing in Python 2.7

2010-08-22 Thread Karim
Sorry wrong import! from xml.minidom import parseString from xml.etree import ElementTree Karim On 08/22/2010 05:24 PM, Karim wrote: Hello Jerry, Tricky solution using minidom (standard) Not tested: import ElementTree import minidom def prettyPrint(element): txt = ElementTree.tostring(

Re: [Tutor] Elementtree and pretty printing in Python 2.7

2010-08-22 Thread Jerry Hill
On Fri, Aug 20, 2010 at 3:49 AM, Knacktus wrote: > Hi guys, > > I'm using Python 2.7 and the ElementTree standard-lib to write some xml. > > My output xml has no line breaks! So, it looks like that: > > > > instead of something like this: > > >     > > > I'm aware of lxml which seems to have a

[Tutor] type() problem

2010-08-22 Thread Roelof Wobben
Hello, This is my exercise: Write Python code to make each of the following doctests pass: """ >>> type(fruit) >>> len(fruit) 8 >>> fruit[:3] 'ram' """ I have made this : >>> type(fruit) >>> len(fruit) 8 >>> fruit[:3] 'ram' """ fruit="ramadana" print "fruit

Re: [Tutor] Tutor Digest, Vol 78, Issue 99 -- Prime numbers

2010-08-22 Thread Alan Gauld
"Nick" wrote I think I'm doing everything correctly now, but please tell me what I'm not-- if such is the case. One last thing - change the subject line to reflect the actual subject. Alan G. ___ Tutor maillist - Tutor@python.org To unsub