Re: [Tutor] building table from textfile

2013-11-27 Thread Alan Gauld
On 27/11/13 18:22, Ruben Guerrero wrote: Dear tutor. I am trying to build the matrix and get some other information from the following text files: file1: -O- 1 2 3 4 5 6 1 C6.617775 -0.405794 0.371689 -0.212231 0.06440

Re: [Tutor] pygame error

2013-11-27 Thread Alan Gauld
On 27/11/13 19:13, Vipul Sharma wrote: Hello ! I am a beginner in pygame, i was just trying a simple pygame program where I wanted to load an image (.png) from the same directory where my actual source code was. I wrote this line in my source code to load the image : Img = pygame.image.load('cat

Re: [Tutor] string codes

2013-11-27 Thread Alan Gauld
On 27/11/13 21:20, spir wrote: py> s.startswith("bcd", 1, -1) and s.endswith("bcd", 1, -1) True Hum, I don't understand the reasoning, here. * First, why use the end-index param? (Here in this case, or in any other)? It contradicts the idea of starting with in my view, but also is useless for

Re: [Tutor] string codes

2013-11-27 Thread Walter Prins
Hi, On 27 November 2013 21:20, spir wrote: > All in all, startswith plus start-index only seems to work fine, I guess. > What is wrong? string.find also works (someone suggested it on the > python-ideas mailing list) but requires both start- and end- indexes. Also, > startswith returns true/fal

[Tutor] pygame error

2013-11-27 Thread Vipul Sharma
Hello ! I am a beginner in pygame, i was just trying a simple pygame program where I wanted to load an image (.png) from the same directory where my actual source code was. I wrote this line in my source code to load the image : Img = pygame.image.load('cat.png') But I got a traceback : pygame.e

Re: [Tutor] string codes

2013-11-27 Thread spir
On 11/26/2013 12:59 PM, Steven D'Aprano wrote: On Tue, Nov 26, 2013 at 10:01:14AM +, Alan Gauld wrote: Is there a method to compare a substring, without building a substring >from the big one? Like startswith or endswith, but anywhere inside the string? test = s[1, -1] == "bcd"#

[Tutor] building table from textfile

2013-11-27 Thread Ruben Guerrero
Dear tutor. I am trying to build the matrix and get some other information from the following text files: file1: -O- 1 2 3 4 5 6 1 C6.617775 -0.405794 0.371689 -0.212231 0.064402 0.064402 2 C -0.405794 6.617775

[Tutor] Python scope and variable binding

2013-11-27 Thread Arnaud Legout
Hi, I have some experience on Python programming, but I have hard time to understand to full variable and attribute lookup in Python in corner cases. This mail will be a bit long with many examples, but I hope it will help me and others to better grasp the full story of variables and attribute lo

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, Nov 27, 2013 at 09:45:20AM +0100, Peter Otten wrote: > >> I took the freedom to report it myself: >> >> http://bugs.python.org/issue19808 > > Thanks for reporting the issue! > > > [off-topic] > > You might like to know that the standard English idiom is "I to

Re: [Tutor] Nested for loops

2013-11-27 Thread Dave Angel
On Wed, 27 Nov 2013 17:08:11 +0100, Rafael Knuth wrote: for x in range(2, n): if n % x == 0: print(n, 'equals', x, '*', n//x) #3 Round: n = 4 x = 3 When n is 4, the inner loop will test 2, then 3. But since n% x is zero for values 4 and 2, it will print, then b

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread Mark Lawrence
On 27/11/2013 01:18, Dominik George wrote: for x in xrange(len(animal)): if animal[x].isdigit(): animal[x] = int(animal[x]) Before posting anything else would you please do a tutorial yourself. The above for loop is appalling newbie code, I'll leave you to post the Pyth

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread Dominik George
Mark Lawrence schrieb: >Dominik, > >I'm very sorry about the above, I really should know better than to >post >at stupid o'clock in the morning when I'm already exhausted. Thanks, Mark :)! -nik ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] Nested for loops

2013-11-27 Thread Andreas Perstinger
Rafael Knuth wrote: >I am trying to figure out how exactly variables in nested loops are >generated, and don't get it 100% right yet. Here's my code: Maybe it's easier if you look at a simpler example like: for i in range(4): for j in range(4): print("i: {}, j: {}".format(i, j)) Do

Re: [Tutor] Nested for loops

2013-11-27 Thread Joel Goldstick
On Wed, Nov 27, 2013 at 11:08 AM, Rafael Knuth wrote: > Hej there, > > I am trying to figure out how exactly variables in nested loops are > generated, and don't get it 100% right yet. Here's my code: > > for n in range(2, 10): > for x in range(2, n): > if n % x == 0: > pri

[Tutor] Nested for loops

2013-11-27 Thread Rafael Knuth
Hej there, I am trying to figure out how exactly variables in nested loops are generated, and don't get it 100% right yet. Here's my code: for n in range(2, 10): for x in range(2, n): if n % x == 0: print(n, 'equals', x, '*', n//x) break else: print

Re: [Tutor] Returns an iterator of tuples

2013-11-27 Thread Steven D'Aprano
On Wed, Nov 27, 2013 at 02:15:22AM -0800, Mike Sila wrote: > I know what return, iteration and tuples are.  Can anyone please tell > me what an iterator of tuples is? An iterator is a thing which returns objects one at a time instead of all at once. The easiest way to get one is to pass a seque

[Tutor] Returns an iterator of tuples

2013-11-27 Thread Mike Sila
I know what return, iteration and tuples are.  Can anyone please tell me what an iterator of tuples is? Thanks On Wednesday, November 27, 2013 11:00 AM, "tutor-requ...@python.org" wrote: Welcome to the Tutor@python.org mailing list! This list is for folks who want to ask (and/or answer) qu

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread spir
On 11/27/2013 02:18 AM, Dominik George wrote: >Before posting anything else would you please do a tutorial >yourself. The above for loop is appalling newbie code, I'll leave >you to post the Pythonic format. Can I trust my ears? Did you just make a move to expell me from posting newbie-readable

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread spir
On 11/26/2013 08:00 PM, Sam Lalonde wrote: Hi, I am very new to python. I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] There is a little interpretation error

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Rafael Knuth
> Does German have anything similar? (I presume you are German.) Ich nehme mir die Freiheit. (present) Ich habe mir die Freiheit genommen. (past) And in Polish: Pozwalam sobie. (present) Pozwoliłem sobie. (past) ;-) Cheers, Raf ___ Tutor maillist

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Steven D'Aprano
On Wed, Nov 27, 2013 at 09:45:20AM +0100, Peter Otten wrote: > I took the freedom to report it myself: > > http://bugs.python.org/issue19808 Thanks for reporting the issue! [off-topic] You might like to know that the standard English idiom is "I took the liberty" rather than "freedom". In g

Re: [Tutor] string replacement in Python 2 and 3

2013-11-27 Thread Albert-Jan Roskam
On Wed, 11/27/13, Steven D'Aprano wrote: Subject: Re: [Tutor] string replacement in Python 2 and 3 To: tutor@python.org Date: Wednesday, November 27, 2013, 12:36 AM On Tue, Nov 26, 2013 at 11:42:29AM -0800, Albert-Jan Roskam wrote: > Hi, > >

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Mark Lawrence
On 27/11/2013 08:45, Peter Otten wrote: Rafael Knuth wrote: simple issue I couldn't find a solution for: YourName = input(str("What is your name?")) print("Hello", YourName) When executing the program, in case the user input is "for", "not", "True", "while" Python interprets that as a command

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Rafael Knuth
Thank you, Peter! On Wed, Nov 27, 2013 at 9:45 AM, Peter Otten <__pete...@web.de> wrote: > Rafael Knuth wrote: > >> simple issue I couldn't find a solution for: >> >> YourName = input(str("What is your name?")) >> print("Hello", YourName) >> >> When executing the program, in case the user input is

Re: [Tutor] Issue w/ string input "for", "not", "while", "else" etc.

2013-11-27 Thread Peter Otten
Rafael Knuth wrote: > simple issue I couldn't find a solution for: > > YourName = input(str("What is your name?")) > print("Hello", YourName) > > When executing the program, in case the user input is "for", "not", > "True", "while" Python interprets that as a command and changes the > input's co