[Tutor] Printing with no newline :(
I am learning Python 3 and programming and am very new so please bear with me… I am writing a program to pull out specific characters in a sequence and then print then out. So far so good however when the characters are printed out they pint on separate lines as opposed to what I want, all on the same line. I have tried \n and just , in the pint statement i.e. print(letterGroup[4],) and print(letterGroup[4]\n) and even print(letterGroup[4],/n)…….. Can anyone help and explain please….Thank you for line in file:m = re.search(regexp, line)if m: letterGroup=m.group(0)print(letterGroup[4]) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 6 November 2011 13:11, Peter Otten __pete...@web.de wrote: Joe Batt wrote: I am learning Python 3 and programming and am very new so please bear with me… I am writing a program to pull out specific characters in a sequence and then print then out. So far so good however when the characters are printed out they pint on separate lines as opposed to what I want, all on the same line. I have tried \n and just , in the pint statement i.e. print(letterGroup[4],) and print(letterGroup[4]\n) and even print(letterGroup[4],/n)…….. Can anyone help and explain please….Thank you The following arrived in a totally messed up formatting: for line in file: m = re.search(regexp, line) if m: letterGroup = m.group(0) print(letterGroup[4]) You can specify what to print after the argument(s) with the end keyword parameter: items = 1, 2, 3 for item in items: ... print(item, end= ) ... 1 2 3 for item in items: ... print(item, end=) ... 123 for item in items: ... print(item, end=WHATEVER) Another way of writing the above. for i in items: print item[i], whatever, \n ... 1WHATEVER2WHATEVER3WHATEVER The default for end is of course newline, spelt \n in a Python string literal. Use help(print) in the interactive interpreter to learn more about the print() function. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 11/06/2011 04:45 AM, Sarma Tangirala wrote: On 6 November 2011 13:11, Peter Otten__pete...@web.de wrote: Joe Batt wrote: I am learning Python 3 and programming and am very new so please bear SNIP for item in items: ... print(item, end=WHATEVER) Another way of writing the above. for i in items: print item[i], whatever, \n Nope. That would put a newline between each iteration, which is explicitly what the OP did not want. More importantly, it'd give a syntax error in Python 3, which the OP carefully specified. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 6 November 2011 15:47, Dave Angel d...@davea.name wrote: On 11/06/2011 04:45 AM, Sarma Tangirala wrote: On 6 November 2011 13:11, Peter Otten__pete...@web.de wrote: Joe Batt wrote: I am learning Python 3 and programming and am very new so please bear SNIP for item in items: ... print(item, end=WHATEVER) Another way of writing the above. for i in items: print item[i], whatever, \n Nope. That would put a newline between each iteration, which is explicitly what the OP did not want. More importantly, it'd give a syntax error in Python 3, which the OP carefully specified. -- DaveA I'm sorry. Didn't notice the python 3 part, I just joined the list and did not look at the OPs post. Sorry about that. Please bear with me on this, but does the following not print end for every iteration of items? for item in items: print(item, end=) -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
I am so very sorry for the noise. I was careless in reading the OPs post. On 6 November 2011 15:53, Sarma Tangirala tvssarma.ome...@gmail.com wrote: On 6 November 2011 15:47, Dave Angel d...@davea.name wrote: On 11/06/2011 04:45 AM, Sarma Tangirala wrote: On 6 November 2011 13:11, Peter Otten__pete...@web.de wrote: Joe Batt wrote: I am learning Python 3 and programming and am very new so please bear SNIP for item in items: ... print(item, end=WHATEVER) Another way of writing the above. for i in items: print item[i], whatever, \n Nope. That would put a newline between each iteration, which is explicitly what the OP did not want. More importantly, it'd give a syntax error in Python 3, which the OP carefully specified. -- DaveA I'm sorry. Didn't notice the python 3 part, I just joined the list and did not look at the OPs post. Sorry about that. Please bear with me on this, but does the following not print end for every iteration of items? for item in items: print(item, end=) -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 11/06/2011 05:23 AM, Sarma Tangirala wrote: SNIP python 3 SNIP. Please bear with me on this, but does the following not print end for every iteration of items? for item in items: print(item, end=) Sure it does. And the value of end is the empty string. So it prints nothing but the item itself. If you don't supply an argument for 'end', it also prints end, but the default value, which is documented as a newline. So it prints the item followed by a newline. In other words, it prints each item on a separate line. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 11/06/2011 05:23 AM, Sarma Tangirala wrote: SNIP I just joined the list and did WELCOME to the list. I should have said that first. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 6 November 2011 16:57, Dave Angel d...@davea.name wrote: On 11/06/2011 05:23 AM, Sarma Tangirala wrote: SNIP I just joined the list and did WELCOME to the list. I should have said that first. -- DaveA Ha! Sorry for the noise again! -- Sarma Tangirala, Class of 2012, Department of Information Science and Technology, College of Engineering Guindy - Anna University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Printing with no newline :(
On 06/11/11 10:23, Sarma Tangirala wrote: I'm sorry. Didn't notice the python 3 part, I just joined the list and did not look at the OPs post. Sorry about that. welcome to the list :-) Please bear with me on this, but does the following not print end for every iteration of items? for item in items: print(item, end=) No, end is a new optional parameter for the print function in Python 3. Recall that in Python2 print was a command whereas in Python 3 it is a function which has a couple of new options: --- Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regexp
On Sat, 5 Nov 2011, Dinara Vakhitova wrote: I need to find the words in a corpus, which letters are in the alphabetical order (almost, my etc.) I started with matching two consecutive letters in a word, which are in the alphabetical order, and tried to use this expression: ([a-z])[\1-z], but it won't work, it's matching any sequence of two letters. I can't figure out why... Evidently I can't refer to a group like this, can I? But how in this case can I achieve what I need? First, I agree with the others that this is a lousy task for regular expressions. It's not the tool I would use. But, I do think it's doable, provided the requirement is not to check with a single regular expression. For simplicity's sake, I'll construe the problem as determining whether a given string consists entirely of lower-case alphabetic characters, arranged in alphabetical order. What I would do is set a variable to the lowest permissible character, i.e., a, and another to the highest permissible character, i.e., z (actually, you could just use a constant, for the highest, but I like the symmetry. Then construct a regex to see if a character is within the lowest-permissible to highest-permissible range. Now, iterate through the string, processing one character at a time. On each iteration: - test if your character meets the regexp; if not, your answer is false; on pass one, this means it's not lower-case alphabetic; on subsequent passes, it means either that, or that it's not in sorted order. - If it passes, update your lowest permissible character with the character you just processed. - regenerate your regexp using the updated lowest permissible character. - iterate. I assumed lower case alphabetic for simplicity, but you could modify this basic approach with mixed case (e.g., first transforming to all-lower-case copy) or other complications. I don't think there's a problem with asking for help with homework on this list; but you should identify it as homework, so the responders know not to just give you a solution to your homework, but instead provide you with hints to help you solve it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] regexp
Dear Terry, Thank you for your advise, I'll try to implement it. D. 2011/11/6 Terry Carroll carr...@tjc.com On Sat, 5 Nov 2011, Dinara Vakhitova wrote: I need to find the words in a corpus, which letters are in the alphabetical order (almost, my etc.) I started with matching two consecutive letters in a word, which are in the alphabetical order, and tried to use this expression: ([a-z])[\1-z], but it won't work, it's matching any sequence of two letters. I can't figure out why... Evidently I can't refer to a group like this, can I? But how in this case can I achieve what I need? First, I agree with the others that this is a lousy task for regular expressions. It's not the tool I would use. But, I do think it's doable, provided the requirement is not to check with a single regular expression. For simplicity's sake, I'll construe the problem as determining whether a given string consists entirely of lower-case alphabetic characters, arranged in alphabetical order. What I would do is set a variable to the lowest permissible character, i.e., a, and another to the highest permissible character, i.e., z (actually, you could just use a constant, for the highest, but I like the symmetry. Then construct a regex to see if a character is within the lowest-permissible to highest-permissible range. Now, iterate through the string, processing one character at a time. On each iteration: - test if your character meets the regexp; if not, your answer is false; on pass one, this means it's not lower-case alphabetic; on subsequent passes, it means either that, or that it's not in sorted order. - If it passes, update your lowest permissible character with the character you just processed. - regenerate your regexp using the updated lowest permissible character. - iterate. I assumed lower case alphabetic for simplicity, but you could modify this basic approach with mixed case (e.g., first transforming to all-lower-case copy) or other complications. I don't think there's a problem with asking for help with homework on this list; but you should identify it as homework, so the responders know not to just give you a solution to your homework, but instead provide you with hints to help you solve it. __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor -- *Yours faithfully, Dinara Vakhitova* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Accessing methods in same class
Hi. I'm working on a project for my friend, but I'm running into errors. No matter what I do, I can't seem to get one method to execute another method in the same class. Is there a way that I can do this? Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing methods in same class
On Sun, Nov 6, 2011 at 9:59 PM, Max S. maxskywalk...@gmail.com wrote: Hi. I'm working on a project for my friend, but I'm running into errors. No matter what I do, I can't seem to get one method to execute another method in the same class. Is there a way that I can do this? Thanks. Yes, you can do this, and it's very straightforward. However, we cannot help you unless you give us three things: A) The code you're running B) what you expect to happen C) what happened instead A minimal example is best, as I would prefer not to dig through 300 lines of code on my own time. Illustrutate our problem for us. Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing methods in same class
Hi, Could you post a copy of the code you are working on, so we can help you better with this? Usually, when calling a method in the same class you use the syntax: self.method_name() 'self' refers to an attribute or method within the same class. Sorry, if this does not help you. Regards Peter Lavelle ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing methods in same class
Oh. Sorry. It's 500 lines, so I'll just post an example. Windows Vista and Python 3, just because I forgot. class K: def __init__(self): doThis() def doThis(self): print(Hi.) k = K() From what I understand by your help, the code class K: def __init__(self): self.doThis() def doThis(self): print(Hi.) k = K() should work. Thank you for coping with my lack of code to work with. On Sun, Nov 6, 2011 at 4:23 PM, Peter Lavelle li...@solderintheveins.co.ukwrote: Hi, Could you post a copy of the code you are working on, so we can help you better with this? Usually, when calling a method in the same class you use the syntax: self.method_name() 'self' refers to an attribute or method within the same class. Sorry, if this does not help you. Regards Peter Lavelle __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://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] regexp
IMO the regex is not too bad; I will not use it for this job -- typing a 50+ character string is more painful (and more error prone) than writing 5--10 lines of code. That said, if it made you look at regexes deeply and beyond the simple explanation of what each character (*, ., +) does I think the teacher ended up making you learn something. FInally, the simplest NON-REGEX method is probably isAlphaOrder(s): return sorted(s) == list(s) It is useful learning to add default parameters to this to improve the functionality to case-dependent or case independent modes. Happy learning Asokan Pichai ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor