Re: [Tutor] is there an explicit eof to test in Py 3?
On 22 April 2013 02:35, Jim Mooney wrote: > I'm reading a book that suggests finding EOF when the readLine == "" > > But wouldn't that end erroneously on blank lines, that really contain > '\n', in which case more lines might follow? What 'empties' are > considered equal in Python? I'm coming from javascript which has a > cluster of rules for that. In Python the rules for this are very simple. Strings compare equal if they have exactly the same sequence of characters. Otherwise they compare unequal. > Yes, I know the easy way is a for loop, which automatically breaks on > eof, but at times I want to use a while loop and break out of it > explicitly on eof. But I can't seem to find an explicit eof marker in > python. Is there one? Why do you want to do this? The only reason I can think of is to avoif buffering. Generally, the for loop is not just easier and clearer but also more efficient (because of the buffering). It also allows you to write code that can work just as easily with anything that is iterable such as a list of strings. Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] multiple versions of python on windows?
I have no idea on Wing, but I'm using Eclipse with the PyDev plugin, and I'm able to associate projects with either Python 2.7 or 3.2 in Windows. It checks for correct grammar in each, and if I tell it to run as a Python script, it uses the correct executable. So if you're not tied to Wing, you might give Eclipse/PyDev a try. -Andy On Mon, Apr 22, 2013 at 2:42 AM, Jim Mooney wrote: > On 21 April 2013 22:47, School wrote: > > You can install multiple versions. The programs use the version they > were assigned to, so there shouldn't be any conflict. > > This brings up the question of installing multiple versions of Wing > 101 IDE. I forget the install but even if I can install in a different > directory for Py 2.7, Windows awful Registry might trip me up. I've > grown to love portables since they bypass Windows Worst Idea, but Wing > isn't one of them. > > If anyone knows, does the paid version of wing allow to switch between > multipe installs? I know, this is probably a Wing discuss question, > but I'm burned out on joining discussion groups to ask one question, > since otherwise Wing is very easy to grasp. > > -- > Jim Mooney > > Today is the day that would have been tomorrow if yesterday was today > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 3to2?
On Sun, 21 Apr 2013, Steven D'Aprano wrote: On 21/04/13 04:32, Jim Mooney wrote: I was looking at google pengine for python and it only supports 2.7. I've installed 3 and would rather not go back (I kept doing Print without the parentheses for awhile and it was really annoying ;') So the question comes up. If there is a 2to3 script, which I got working, is there a 3to2 script?. Or does that even makes sense since 3 has features 2 does not, although I read somewhere that many have been backported? from __future__ import division, print_function from future_builtins import * This is the route I recommend, and take myself. Usually I'll do: from __future__ import print_function, division, unicode_literals try: input = raw_input range = xrange except NameError: pass #using python 3 already, whee! which makes you able to write code that mostly looks to Python3. You could also look at how Django does their 2/3 support: https://www.djangoproject.com/weblog/2012/aug/19/experimental-python-3-support/ Looks like they use the `six` library: http://pythonhosted.org/six/ HTH, -W ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Why is my list index going out of range
Okay, what am I doing wrong here? I'm generating primes from a list and getting "list index out of range," but since the for loops controls the indexes I don't see how that's happening. I thought it was the list append, but I commented that out and put in a print statement, and I still got the line 5 error: primeList = [1] numList = list(range(2,101)) for e in numList: for f in primeList: if numList[e] % primeList[f] != 0: #list index out of range primeList.append(numList[e]) print(primeList) -- Jim Mooney The Real Reason Things Keep Going Wrong: At the beginning of time, God set a Magic Top Spinning... and spinning... and spinning... and spinning... and spinning... and spinning... and spinning... After a few hundred million years God got bored and gave the top a good kick; so it went rebounding away, flinging off planets and stars and dinosaurs, and later, people who wrote about dinosaurs. Then God realized that although Order and Regularity are virtuous, if you want interesting stories, now and then you have to give things a good Kick! This explains a lot. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why is my list index going out of range
On 04/22/2013 09:47 PM, Jim Mooney wrote: Okay, what am I doing wrong here? I'm generating primes from a list and getting "list index out of range," but since the for loops controls the indexes I don't see how that's happening. I thought it was the list append, but I commented that out and put in a print statement, and I still got the line 5 error: primeList = [1] numList = list(range(2,101)) for e in numList: for f in primeList: if numList[e] % primeList[f] != 0: #list index out of range primeList.append(numList[e]) print(primeList) You are doing, basically: x = [1] for f in x: x[f] x[1] is out of range, because x is length=1, and the last valid index is 0. -m -- Jim Mooney The Real Reason Things Keep Going Wrong: At the beginning of time, God set a Magic Top Spinning... and spinning... and spinning... and spinning... and spinning... and spinning... and spinning... After a few hundred million years God got bored and gave the top a good kick; so it went rebounding away, flinging off planets and stars and dinosaurs, and later, people who wrote about dinosaurs. Then God realized that although Order and Regularity are virtuous, if you want interesting stories, now and then you have to give things a good Kick! This explains a lot. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why is my list index going out of range
On 04/22/2013 09:47 PM, Jim Mooney wrote: Okay, what am I doing wrong here? I'm generating primes from a list and getting "list index out of range," but since the for loops controls the indexes I don't see how that's happening. I thought it was the list append, but I commented that out and put in a print statement, and I still got the line 5 error: primeList = [1] numList = list(range(2,101)) for e in numList: for f in primeList: e and f are now values from the lists; they are *not* indexes into the list. if numList[e] % primeList[f] != 0: #list index out of range if e % f != 0:#will get rid of the exception primeList.append(numList[e]) Unfortunately, you still have an algorithm bug. But now that you shouldn't get exceptions, I'll leave you to find the bug. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor