[Tutor] Hey guys!
So I'm kind of stuck trying to program a function that returns a list of tuples. The function takes 2 lists containing circles of which it should compare list1[0] to list2[0] to see if they intersect. If they intersect or touch then I should return them on a list of tuples(in the tuple would be both intersecting circles). I can't get circles_only to work the way I see it I'm comparing h to x only if they're both in the same place on the list (hence my "h==x") I know it doesn't work because the test returns None so I would really appreciate an alternative method if you guys see one. Here are my functions: def circles_overlap(c1, c2): x=(c2.center.y-c1.center.y)**2 y=(c2.center.x-c1.center.x)**2 distancemid=math.sqrt(x+y) distancerad=(c1.radius+c2.radius) if distancemid > distancerad: return 1 elif distancemid < distancerad: return -1 elif distancemid == distancerad: return 0 def circles_only(lst1, lst2): newlst=[] for h in lst1: for x in lst2: if h==x: if circles_overlap(lst1[h],lst2[x])== -1: newlst.append(lst1[h],lst2[x]) elif circles_overlap(lst1[h],lst2[x])== 0: newlst.append(lst1[h],lst2[x]) print newlst TEST CASE: def test_circles_olap1(self): list1=[data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(2,3), 2), data_2.Circle(data_2.Point(2,3), 2) ] list2=[data_2.Circle(data_2.Point(6,3), 2),data_2.Circle(data_2.Point(10,3), 2), data_2.Circle(data_2.Point(5,3), 2) ] testor=functions_2.circles_only(list1,list2) newlist=[(data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(6,3), 2)),(data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(10,3), 2))] self.assertEqual(testor, newlist) Thanks in advance! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hey guys!
On 17/02/15 04:22, Levi Adissi wrote: Hello. Thanks for your post. However could you please use a subject that rflects the content. Otherwise we wind up with an archive full of "Hey Guys", "Hello chaps", "Gday mate", Bonjour" etc Not very useful for searching. So I'm kind of stuck trying to program a function that returns a list of tuples. Note that your function prints the list it does not return the list. The two are very different. The function takes 2 lists containing circles of which it should compare list1[0] to list2[0] to see if they intersect. If they intersect or touch then I should return them on a list of tuples(in the tuple would be both intersecting circles). I can't get circles_only to work the way I see it I'm comparing h to x only if they're both in the same place on the list (hence my "h==x") I know it doesn't work because the test returns None so I would really appreciate an alternative method if you guys see one. Here are my functions: def circles_overlap(c1, c2): x=(c2.center.y-c1.center.y)**2 y=(c2.center.x-c1.center.x)**2 distancemid=math.sqrt(x+y) distancerad=(c1.radius+c2.radius) if distancemid > distancerad: return 1 elif distancemid < distancerad: return -1 elif distancemid == distancerad: return 0 Since this is a test you should probably just return True or False. Either they overlap or they don't. If you want to use touching as a third result you can still give a boolean for the general case: return 1 for overlap -1 for touching 0 for not touching 1 and -1 both evaluate to True in a boolean sense 0 evaluates to False This makes the test code in your second function look like: if circles_overlap(c1,c2): newlst.append((c1,c2)) and you don't need the else clause def circles_only(lst1, lst2): newlst=[] for h in lst1: for x in lst2: if h==x: Why do you have this test? You only check if they overlap when they are equal? That seems odd to me. Also h and x seem an odd choice of name for two circles. Why not for c1 in lst1: for c2 in lst2: if circles_overlap(lst1[h],lst2[x])== -1: newlst.append(lst1[h],lst2[x]) Now you are trying to use indexing to extract the circles but you are (quite rightly) iterating over the lists directly not using indexes. So h and x are circles, you don't need to get them out of the lists. Also you are trying to store two items in your newlist rather than a tuple. (See my suggested test above.) HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hey guys!
On 02/16/2015 11:22 PM, Levi Adissi wrote: Thank you for using text email, rather than the html mail that so many newcomers use. So I'm kind of stuck trying to program a function that returns a list of tuples. The function takes 2 lists containing circles of which it should compare list1[0] to list2[0] to see if they intersect. If they intersect or touch then I should return them on a list of tuples(in the tuple would be both intersecting circles). I can't get circles_only to work the way I see it I'm comparing h to x only if they're both in the same place on the list (hence my "h==x") I know it doesn't work because the test returns None so I would really appreciate an alternative method if you guys see one. Here are my functions: def circles_overlap(c1, c2): x=(c2.center.y-c1.center.y)**2 y=(c2.center.x-c1.center.x)**2 distancemid=math.sqrt(x+y) distancerad=(c1.radius+c2.radius) if distancemid > distancerad: return 1 elif distancemid < distancerad: return -1 elif distancemid == distancerad: return 0 def circles_only(lst1, lst2): newlst=[] for h in lst1: for x in lst2: if h==x: That's silly. You don't want to compare the two circles to see if they're equal. Remove this line. if circles_overlap(lst1[h],lst2[x])== -1: Why don't you tell us the exception this line causes? lst1 is subscripted by integers, not by circle objects. What you really want in this line is something like: if circles_overlap(h, x) ! = 1: newlst.append(h, x) newlst.append(lst1[h],lst2[x]) elif circles_overlap(lst1[h],lst2[x])== 0: newlst.append(lst1[h],lst2[x]) print newlst Don't print it, return it. Otherwise, you're returning None. TEST CASE: def test_circles_olap1(self): list1=[data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(2,3), 2), data_2.Circle(data_2.Point(2,3), 2) ] list2=[data_2.Circle(data_2.Point(6,3), 2),data_2.Circle(data_2.Point(10,3), 2), data_2.Circle(data_2.Point(5,3), 2) ] testor=functions_2.circles_only(list1,list2) newlist=[(data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(6,3), 2)),(data_2.Circle(data_2.Point(2,3), 2),data_2.Circle(data_2.Point(10,3), 2))] self.assertEqual(testor, newlist) The test code makes no sense to me at all. it's a method of some unspecified class, and it uses some namespaces called data_2 and functions_2 for an unknown purpose. -- -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What are *appropriate* uses for exec() and eval() ?
On Mon, Feb 16, 2015 at 07:10:21PM -0800, Devin Jeanpierre wrote: > On Mon, Feb 16, 2015 at 6:15 PM, Steven D'Aprano wrote: > > Here is a fork of that recipe. It uses an inner class for the new > > namedtuple class. The only thing which needs exec is the __new__ method. > > > > http://code.activestate.com/recipes/578918-yet-another-namedtuple/ > > > > This demonstrates a powerful truth about Python: *most of the time* you > > don't need to use exec or eval because the standard language features > > are powerful enough to solve the problem for you. Using a dynamically > > created inner class is *almost* enough to solve this problem, only the > > __new__ method defeats it. If our requirements where just a little less > > demanding, we could avoid exec completely. > > No, exec is not necessary at all. I'm not sure that I said that exec was "necessary" anywhere, but since you mention it, how about the two earlier examples I gave, timeit and doctest? Especially doctest. How would you implement doctests without exec? Of course you could write your own Python parser, and build your own Python interpreter. But that's just re-inventing exec. And it would be horribly slow. Back in the very early days of PyPy, they wrote a Python interpreter using nothing but pure Python. It was about 100 times slower than the regular Python interpreter. Another reasonable use for exec is to develop your own language or mini-language. You generate Python code, compile it, then execute it. Template engines like Mako, Jinja2 and Genshi work like this, or so I am lead to believe. > If they had to the author could have > reimplemented the argument assignment logic by hand. They chose not to > because it is "too hard". (And it is.) Fortunately, they don't have > to go that far: > > signature = inspect.Signature([ > inspect.Parameter(field_name, inspect.Parameter.POSITIONAL_OR_KEYWORD) > for field_name in field_names]) Hmmm. Well, namedtuple was added to Python in version 2.6. [steve@ando ~]$ python2.6 Python 2.6.7 (r267:88850, Mar 10 2012, 12:32:58) [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2 Type "help", "copyright", "credits" or "license" for more information. py> from inspect import Signature Traceback (most recent call last): File "", line 1, in ImportError: cannot import name Signature So much for that idea. Of course you are right that using exec is rarely the *only possible* way to solve a problem. But it's a tool like any other tool, we shouldn't be afraid to use it when it is the best tool for the job. The problem comes from people using it when it is the *wrong* tool for the job, or using it carelessly. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
I know that there have been multiple posts in the past about Michael Dawson's book, "Python Programming for the Absolute Beginner, 3rd ed.". Because of this I thought I might mention something my son encountered this morning. I have finally gotten my son to start working in this book. He came to me with a problem this morning, which he could not figure out when trying to replicate the author's (Michael Dawson) Game Over 2.0 program in chapter two on page 17. The object of this program is to do ASCII-style art to generate a large rendition of "Game Over" using the following characters: "_" , "\" , "|" , and "/" . When my son tried to do his version, the "Over" portion did not print correctly. The top half of "Over" printed first followed by the second half of the word next to it. I don't want to say too much for those working through this book, but the essence of the issue is illustrated by the following: Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> print( """ boB Stepp """ ) boB Stepp >>> print( """ boB\ Stepp """ ) boBStepp This led to a discussion with my son about the invisible characters that terminate lines in Window and *nix, escape sequences, etc. Hopefully this might prove helpful to those starting this book without just giving the answer if this problem comes up in their efforts. -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] mySQL and Python
Hi, I am looking for tools to use mySQL and python. I saw in a question posted in Stack Overflow ( http://stackoverflow.com/questions/23376103/python-3-4-0-with-mysql-database) that mySQLdb is not compatible with python 3 but the post was 9 months ago. I haven't been able to find updated information (maybe because I'm not sure how to look...) I found the mySQL/Python connector but in the python versions supported, the last one listed is 3.3. I have 3.4 does this mean that it won't work? I have only ever used php with mySQL so I need some help. What would be the best library/extension to get? If I use mySQLdb or PyMySQL would I need the connector as well? thanks for your help, --Beatrice ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mySQL and Python
On Tue, Feb 17, 2015 at 5:49 AM, Beatrice Perez wrote: > I have only ever used php with mySQL so I need some help. What would be the > best library/extension to get? If I use mySQLdb or PyMySQL would I need the > connector as well? Unfortunately, I don't know. Since this is the Tutor mailing list, we help with general learning questions: database module installation questions are a little out of scope. You might get better MySQL and Python-specific help on the general mailing list: https://mail.python.org/mailman/listinfo/python-list I'd recommend checking with the. Let's see... From looking at the wiki: https://wiki.python.org/moin/MySQL I see that there's a "PyMySQL" library that is labeled as supporting Python 3, but I have no personal experience with it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
On Tue, Feb 17, 2015 at 12:43 PM, Danny Yoo wrote: [...] > Ah ha. Escape characters. I see what you mean. :P > > > Just to add: there is a "raw" string literal syntax that will turn off > escape sequence handling. Using a raw string literal may make it > easier to type the value in question. > > We can use raw literal strings by prepending a 'r' in the front of the > string literal. e.g.: > > ## x = r''' > ... this\ > ... is\ > ... a/ > ... test\ > ... ''' x > '\nthis\\\nis\\\na/\ntest\\\n' print x > > this\ > is\ > a/ > test\ > ## Actually, that is the solution I recommended to my son to use. > It might be that the question is trying to motivate the use of raw > string literals, or teaching about escape sequences. I don't have the > book, so I can't say for sure. At this point in the text he is not talking about raw literal strings. I examined the author's source and he has obviously inserted at least one space between each use of a backslash at the end of a line and the EOL terminating characters. He did not do this with the "Game" portion of the code, which did not make any use of "\" . When the file is run everything behaves as desired. But if, as my son did, you leave no spaces between the last backslash and the EOL termination characters, then the problem behavior occurs. Actually, I realize I have a question: If I do the following in the Win7 command line Python interpreter: Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print(""" ... boB\ ... Stepp ... """ ... ) boB\ Stepp Here I placed exactly one space between "\" and where I pressed "Enter". This would be the Game Over 2.0 desired behavior. However, if I bring up the IDLE Python interpreter and do the exact same thing: Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> print(""" boB\ Stepp """ ) boBStepp it gives the undesired behavior. I typed exactly the same character sequences, though IDLE displayed things slightly differently, e.g., the command line interpreter put in "..." in several places, where the IDLE interpreter did not. I am currently scratching my head on these differences, and am currently guessing that IDLE implements the Python interpreter somewhat differently than the implementation that occurs in the Windows command line. Do you have an explanation for these differences? -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
On 02/17/2015 02:12 PM, boB Stepp wrote: See https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals At this point in the text he is not talking about raw literal strings. I examined the author's source and he has obviously inserted at least one space between each use of a backslash at the end of a line and the EOL terminating characters. Then he's teaching you wrong. Backslash followed by space is not a valid escape sequence, and to do it at the end of line is particularly odious. I wouldn't even suggest it in real code, never mind in something that's published on paper. The docs admit that the invalid escape sequences behave differently than C, in that the backslash is retained. I think it should be a syntax error to have an invalid sequence. If the backslash immediately precedes the newline, then the two characters both get eaten, and the two lines are combined into one. That can be useful if you want to define a string that's too long to fit in your source file. I would never intentionally make any trailing whitespace in source code be significant. And years ago I used an editor that routinely deleted any such invisible characters. From the rest of your message, it looks like IDLE may have that behavior. He did not do this with the "Game" portion of the code, which did not make any use of "\" . When the file is run everything behaves as desired. But if, as my son did, you leave no spaces between the last backslash and the EOL termination characters, then the problem behavior occurs. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
> Dawson) Game Over 2.0 program in chapter two on page 17. The object of > this program is to do ASCII-style art to generate a large rendition of > "Game Over" using the following characters: "_" , "\" , "|" , and "/" > . When my son tried to do his version, the "Over" portion did not > print correctly. Hi boB, Ah ha. Escape characters. I see what you mean. :P Just to add: there is a "raw" string literal syntax that will turn off escape sequence handling. Using a raw string literal may make it easier to type the value in question. We can use raw literal strings by prepending a 'r' in the front of the string literal. e.g.: ## >>> x = r''' ... this\ ... is\ ... a/ ... test\ ... ''' >>> x '\nthis\\\nis\\\na/\ntest\\\n' >>> print x this\ is\ a/ test\ ## It might be that the question is trying to motivate the use of raw string literals, or teaching about escape sequences. I don't have the book, so I can't say for sure. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Need help with find error
This was mailed just to me by accident. Forwarding to tutor. Apologies for not forwarding this ten days ago: I missed it. -- Forwarded message -- From: Андрей Пугачев Date: Sat, Feb 7, 2015 at 12:27 AM Subject: Re: [Tutor] Need help with find error To: Danny Yoo Sorry for my absense, but you want to say, that loop in code isn't working? (in main()-function) When category is empty code must print 2 last rows, but I have error I learn python book M. Dawson and this exercise from his book. I add original working files, where points count as score +=1 and all works. But if I add some points to each question code don't work. I can't understand it/ 2015-02-04 20:24 GMT+02:00 Danny Yoo : > > As a revision of my initial question, when we look at next_block(), > it's documented as follows: > > > def next_block(the_file): > """Return the next block of data from the trivia file.""" > > > > What if there are no more blocks in the file? What should happen then? > > Let's say that we do a test, where we pass in the empty file to next_block(). > > ## > from io import StringIO > x = next_block(StringIO('')) > ## > > What do you want to happen in this situation? > > --- > > As a side note: if you have control over the data format, you might > want to consider using JSON rather than a line-based format. If you > use JSON, this takes care of a few issues that you are working around > now. > > For example, you can reuse the newline escapes rather than define your > own convention. Also, rather than read a stream of records, where you > have to deal with the end of the file, you might just read one JSON > object that represents your whole trivia file, which will simplify > your program's logic. > > See: https://docs.python.org/2/library/json.html and use your favorite > web search engine for 'json python tutorial', and you should be able > to find some useful information. If you have questions, please feel > free to ask. An Episode You Can't Refuse On the Run With a Mammal Let's say you turn state's evidence and need to "get on the lamb." If you wait /too long, what will happen? You'll end up on the sheep You'll end up on the cow You'll end up on the goat You'll end up on the emu 1 A lamb is just a young sheep. The Godfather Will Get Down With You Now Let's say you have an audience with the Godfather of Soul. How would it be /smart to address him? Mr. Richard Mr. Domino Mr. Brown Mr. Checker 3 James Brown is the Godfather of Soul. That's Gonna Cost Ya If you paid the Mob protection money in rupees, what business would you most /likely be insuring? Your tulip farm in Holland Your curry powder factory in India Your vodka distillery in Russian Your army knife warehouse in Switzerland 2 The Rupee is the standard monetary unit of India. Keeping It the Family If your mother's father's sister's son was in "The Family," how are you /related to the mob? By your first cousin once removed By your first cousin twice removed By your second cousin once removed By your second cousin twice removed 1 Your mother's father's sister is her aunt -- and her son is your /mother's first cousin. Since you and your mother are exactly one generation /apart, her first cousin is your first cousin once removed. A Maid Man If you were to literally launder your money, but didn't want the green in your /bills to run, what temperature should you use? Hot Warm Tepid Cold 4 According to my detergent bottle, cold is best for colors that might run.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
On Tue, Feb 17, 2015 at 1:47 PM, Dave Angel wrote: > On 02/17/2015 02:12 PM, boB Stepp wrote: > > See > https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals >> >> >> At this point in the text he is not talking about raw literal strings. >> I examined the author's source and he has obviously inserted at least >> one space between each use of a backslash at the end of a line and the >> EOL terminating characters. > > > Then he's teaching you wrong. Backslash followed by space is not a valid > escape sequence, and to do it at the end of line is particularly odious. I > wouldn't even suggest it in real code, never mind in something that's > published on paper. I guess I am inclined to cut the author some slack here. The point of his example was NOT to teach escape sequences, but instead show how using keyboard characters you could create a text picture, in this instance of a large "Game Over". He at this point was talking about the print function used with quotes and triple quotes. A little bit later in this same chapter he talks about escape sequences. The point of my original post was to point out that because the author is using a backslash as part of his ASCII art, that unintended consequences might result. I will admit that I was surprised that the author did not think of this potential issue and warn the reader of possible problems, especially as the book is aimed at total beginners. But I suppose it is difficult to anticipate all possible problems. But sure enough, my son stumbled into this one! [...] > I would never intentionally make any trailing whitespace in source code be > significant. And years ago I used an editor that routinely deleted any such > invisible characters. From the rest of your message, it looks like IDLE may > have that behavior. This seems to be the case. On a related note, I wanted to copy and paste the author's source code, showing how he generated the large, "Game Over", but my Gmail keeps collapsing the white space, making the result look like gibberish. So far I cannot find a setting to eliminate this undesired behavior. Argh! -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
On Tue, Feb 17, 2015 at 3:05 PM, boB Stepp wrote: > This seems to be the case. On a related note, I wanted to copy and > paste the author's source code, showing how he generated the large, > "Game Over", but my Gmail keeps collapsing the white space, making the > result look like gibberish. So far I cannot find a setting to > eliminate this undesired behavior. Argh! I have found the problem. During some previous update or other Google-induced behavior, all of the work I did to have a specific fixed-width font with an extension has apparently been undone. Anyway, here is the snippet of the author's source code that I had intended to send earlier: print( """ _ ___ ___ ___ _ / ___| / | / |/ | | ___| | |/ /| |/ /| /| | | |__ | | _/ ___ | / / |__/ | | | __| | |_| | / / | | / / | | | |___ \_/ /_/ |_| /_/|_| |_| _ _ _ _ _ / _ \ | | / / | ___| | _ \ | | | | | | / / | |__ | |_| | | | | | | | / / | __| | _ / | |_| | | |/ /| |___ | | \ \ \_/ |___/ |_| |_| \_\ """ ) -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Need help with find error
Forwarding to tutor. Again, apologies that I didn't respond earlier. Overloaded. -- Forwarded message -- From: Андрей Пугачев Date: Tue, Feb 17, 2015 at 11:58 AM Subject: Re: [Tutor] Need help with find error To: Danny Yoo Anybody can help with this? 2015-02-07 10:27 GMT+02:00 Андрей Пугачев : > > Sorry for my absense, but you want to say, that loop in code isn't working? > (in main()-function) > When category is empty code must print 2 last rows, but I have error > > I learn python book M. Dawson and this exercise from his book. > I add original working files, where points count as score +=1 and all works. > But if I add some points to each question code don't work. > I can't understand it/ > > > > 2015-02-04 20:24 GMT+02:00 Danny Yoo : >> >> As a revision of my initial question, when we look at next_block(), >> it's documented as follows: >> >> >> def next_block(the_file): >> """Return the next block of data from the trivia file.""" >> >> >> >> What if there are no more blocks in the file? What should happen then? >> >> Let's say that we do a test, where we pass in the empty file to next_block(). >> >> ## >> from io import StringIO >> x = next_block(StringIO('')) >> ## >> >> What do you want to happen in this situation? >> >> --- >> >> As a side note: if you have control over the data format, you might >> want to consider using JSON rather than a line-based format. If you >> use JSON, this takes care of a few issues that you are working around >> now. >> >> For example, you can reuse the newline escapes rather than define your >> own convention. Also, rather than read a stream of records, where you >> have to deal with the end of the file, you might just read one JSON >> object that represents your whole trivia file, which will simplify >> your program's logic. >> >> See: https://docs.python.org/2/library/json.html and use your favorite >> web search engine for 'json python tutorial', and you should be able >> to find some useful information. If you have questions, please feel >> free to ask. > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
On Tue, Feb 17, 2015 at 4:05 PM, boB Stepp wrote: > On Tue, Feb 17, 2015 at 1:47 PM, Dave Angel wrote: >> On 02/17/2015 02:12 PM, boB Stepp wrote: >> >> See >> https://docs.python.org/3.4/reference/lexical_analysis.html#string-and-bytes-literals >>> >>> >>> At this point in the text he is not talking about raw literal strings. >>> I examined the author's source and he has obviously inserted at least >>> one space between each use of a backslash at the end of a line and the >>> EOL terminating characters. >> >> >> Then he's teaching you wrong. Backslash followed by space is not a valid >> escape sequence, and to do it at the end of line is particularly odious. I >> wouldn't even suggest it in real code, never mind in something that's >> published on paper. > > I guess I am inclined to cut the author some slack here. The point of > his example was NOT to teach escape sequences, but instead show how > using keyboard characters you could create a text picture, in this > instance of a large "Game Over". He at this point was talking about > the print function used with quotes and triple quotes. A little bit > later in this same chapter he talks about escape sequences. The point > of my original post was to point out that because the author is using > a backslash as part of his ASCII art, that unintended consequences > might result. I will admit that I was surprised that the author did > not think of this potential issue and warn the reader of possible > problems, especially as the book is aimed at total beginners. But I > suppose it is difficult to anticipate all possible problems. But sure > enough, my son stumbled into this one! > > [...] > >> I would never intentionally make any trailing whitespace in source code be >> significant. And years ago I used an editor that routinely deleted any such >> invisible characters. From the rest of your message, it looks like IDLE may >> have that behavior. > > This seems to be the case. On a related note, I wanted to copy and > paste the author's source code, showing how he generated the large, > "Game Over", but my Gmail keeps collapsing the white space, making the > result look like gibberish. So far I cannot find a setting to > eliminate this undesired behavior. Argh! Do you have gmail set to plain text mode? > -- > boB > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor -- Joel Goldstick http://joelgoldstick.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Potential problem with Game Over 2.0 problem in "Python Programming for the Absolute Beginner, 3rd Ed."
On Tue, Feb 17, 2015 at 3:34 PM, Joel Goldstick wrote: > On Tue, Feb 17, 2015 at 4:05 PM, boB Stepp wrote: >> On Tue, Feb 17, 2015 at 1:47 PM, Dave Angel wrote: >>> On 02/17/2015 02:12 PM, boB Stepp wrote: >> This seems to be the case. On a related note, I wanted to copy and >> paste the author's source code, showing how he generated the large, >> "Game Over", but my Gmail keeps collapsing the white space, making the >> result look like gibberish. So far I cannot find a setting to >> eliminate this undesired behavior. Argh! > > Do you have gmail set to plain text mode? What I just sent out, that showed what I wanted to show, was not plain text, but Google's fixed-width font. Of course, turning that on took away plain text mode. I had a couple of years ago or so (Whenever it was that I started working with Python and interacting with the Tutor list.) installed the Stylish extension to Gmail and set up a plain text, fixed width font. Somehow that font has been removed from my Gmail settings with no known action on my part. I did not notice it until today when I tried to reproduce the ASCII art under discussion in this thread and found that I could not. So apparently I can do plain text, but not fixed width, or I can do fixed width, but not plain text! At least until I come up with a solution. Heavy sighs! -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] monkey patching question
Hi, I would like to monkey patch a function 'decode' that is defined inside a class. It is defined there because it is a logical place, next to its counterpart *method* 'encode'. I can successfully monkey patch meth1, but when I call meth2, it does not use the patched decorator. How can this be done? In this example, I would like to effectively "turn off" @decode. I am hoping for a solution that works on Python 2.7 and 3.3+. import inspect, functools class Foo(object): def decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "original decorator was called" return func(*args, **kwargs).decode("utf-8") return wrapped def encode(self): """this is just here to show why decode() is defined within Foo""" pass def meth1(self): return "original method was called" @decode def meth2(self): return b"python rocks" # works - f = Foo() print f.meth1() Foo.meth1 = lambda self: "new method was called" print f.meth1() print "---" # does not work - def patched_decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "patched decorator was called" return func(*args, **kwargs) return wrapped f = Foo() print 'ORIGINAL' print inspect.getsource(Foo.decode) # shows source code of regular decode (as expected) result = f.meth2() print repr(result), type(result) #setattr(Foo, "decode", patched_decode) Foo.decode = patched_decode print 'PATCHED' print inspect.getsource(f.decode) # shows source code of patched_decode (as expected) result = f.meth2() print repr(result), type(result) # not patched at all! it's still unicode! # output: In [1]: %run monkey_patch.py original method was called new method was called --- ORIGINAL def decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "original decorator was called" return func(*args, **kwargs).decode("utf-8") return wrapped original decorator was called u'python rocks' PATCHED def patched_decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "patched decorator was called" return func(*args, **kwargs) return wrapped original decorator was called u'python rocks' Regards, Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] monkey patching question
On 02/17/2015 04:53 PM, Albert-Jan Roskam wrote: Hi, I would like to monkey patch a function 'decode' that is defined inside a class. It is defined there because it is a logical place, next to its counterpart *method* 'encode'. I can successfully monkey patch meth1, but when I call meth2, it does not use the patched decorator. How can this be done? In this example, I would like to effectively "turn off" @decode. I am hoping for a solution that works on Python 2.7 and 3.3+. import inspect, functools class Foo(object): def decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "original decorator was called" return func(*args, **kwargs).decode("utf-8") return wrapped def encode(self): """this is just here to show why decode() is defined within Foo""" pass def meth1(self): return "original method was called" @decode def meth2(self): return b"python rocks" I assume the monkey patching happens in some other file which will import this one. So by the time the import is finished, the meth2() method has already been decorated by the decode function. # works - f = Foo() print f.meth1() Foo.meth1 = lambda self: "new method was called" print f.meth1() print "---" # does not work - def patched_decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "patched decorator was called" return func(*args, **kwargs) return wrapped f = Foo() print 'ORIGINAL' print inspect.getsource(Foo.decode) # shows source code of regular decode (as expected) result = f.meth2() print repr(result), type(result) #setattr(Foo, "decode", patched_decode) Foo.decode = patched_decode print 'PATCHED' print inspect.getsource(f.decode) # shows source code of patched_decode (as expected) result = f.meth2() print repr(result), type(result) # not patched at all! it's still unicode! # output: In [1]: %run monkey_patch.py original method was called new method was called --- ORIGINAL def decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "original decorator was called" return func(*args, **kwargs).decode("utf-8") return wrapped original decorator was called u'python rocks' PATCHED def patched_decode(func): @functools.wraps(func) def wrapped(*args, **kwargs): print "patched decorator was called" return func(*args, **kwargs) return wrapped original decorator was called u'python rocks' I think you're going to have to patch meth2(). Patching decode won't help, since it's already done its work. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] monkey patching question
Apologies, but the answer might be unsatisfactory. The syntactic use of decorators is confusing the situation. Let's simplify. Your question is equivalent to the following scenario: def logged(g): def wrapped(x): print "call" return g(x) return wrapped square = logged(lambda x: x * x) # where we can only interact with the resulting environment afterwards. The function that you want to mock out has *already* been called by the time you have control. Monkey patching as a technique works only under late binding, when there's a name that you can use to swap out an original binding with a new one. But in the situation above, that's not applicable at all. The function value is not being referred to by some name that's externally accessible, so there's no handle to monkey-patch. Can you do something else instead besides trying to monkey-patch? Even if it were possible to do, if you can correct the original code, that might be preferable and use less magic. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] OT: Preferred email client for sending plain text programming code snippets
Hopefully this is not a touchy subject like Emacs vs. Vim. ~(:>)) My home PC uses Win7-64bit. I currently use Chrome, Gmail and have a Nexus 5 phone. The nice thing about all of this is that all of my information usually seamlessly syncs. That is nice! But I am getting increasingly frustrated with Gmail in terms of communicating with this group (and sometimes others). It seems that if I am not constantly attentive, my settings change from plain text to html, or, now, my New Courier fixed-width font vanishes from the Gmail ecosystem and cannot be found. I actually have come to prefer plain text communication as I only rarely need html formatting. And I rarely care to see most of the crap people send me that require html! So are there any recommendations from this group that would make things easy, would still be able to receive/send from my Gmail account, etc.? -- boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT: Preferred email client for sending plain text programming code snippets
On 17/02/15 23:23, boB Stepp wrote: So are there any recommendations from this group that would make things easy, would still be able to receive/send from my Gmail account, etc.? Thunderbird seems to work for me. I use it for 4 different email accounts (including both yahoo and gmail) as well as over a dozen newsgroups, mostly from gmane (including c.l.p, tutor and tkinter). It can also handle RSS feeds apparently but I don't use that. Some of the accounts I set up to use rich text, others I use plain text. Each account has its own settings. And it works on both my Linux and Windows. By using IMAP I can open any account on any box and see the same mail setup. And in most cases using my Android phone does the same too... The downsides? Occasionally, while editing/composing it blanks out a line of text so it becomes invisible and I have to select the line to get it back. Hopefully a patch will fix that soon. I don't particularly like the split UI where the message action buttons are on a toolbar in the middle of the window (at the top of the message preview). I also don't like when it tries to be too clever. Sometimes it detects list email addresses and replaces the Reply-All button with Reply-List. This is very bad, especially with another list I help moderate. When I'm discussing an iffy mail with my fellow moderators it tries to send it to the list because it detects the list address in the body of the mail - NOT what I want! I've had some embarrassing moments because of that! But overall it does what I want, most of the time. hth -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Question: Excluding certain keywords.
Dear Python Tutor. First of all, thank you for your kindness in advance. I am learning python by myself and having some difficulties in a problem that I encounter. Here I attach my python file. What I am trying to do is: 1) get the data by opening the data source, which is ‘apple.son' 2) obtain only the text part of JSON. 3) exclude the certain string which includes certain keywords. Up to part 2), I think it works. However, part 3) it does not return any value. Do you know why? I really appreciate your help and I am looking forward your response. Thank you again. Best, Arnold DongWoo Chung Master’s Degree Student, Stan Richards School of Advertising and Public Relations Moody College of Communication The University of Texas at Austin 512.466.6435 | adw...@utexas.edu ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Question: Excluding certain keywords.
On 02/17/2015 03:30 PM, Arnold Chung wrote: Dear Python Tutor. Welcome to the tutor list. As far as I can tell, this is your first post. And thank you for using text mail, rather than html. First of all, thank you for your kindness in advance. I am learning python by myself and having some difficulties in a problem that I encounter. Here I attach my python file. This mailing list doesn't support attachments. What that means is that even if some subscribers might see the attachment you presumably did, others will not. I do not. Please paste the relevant code into the message. If it's too large for that, then strip it down to a simpler case that is reasonable. You probably will also need to tell us your Python version. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Old popen turned in subprocess...[SOLVED]
I wish to thanks Danny Yoo and Alan Gauld for providing information on using the new subprocess in printing on paper, replacing my old popen which was deprecated since Python 2.6. After some trial and errors, I got my desired output printed. Not looking forward to updating my old programs. Thanks, guys. Ken ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Question: Excluding certain keywords.
Hi Arnold, and welcome. On Tue, Feb 17, 2015 at 02:30:34PM -0600, Arnold Chung wrote: > Dear Python Tutor. > > First of all, thank you for your kindness in advance. I am learning > python by myself and having some difficulties in a problem that I > encounter. > > Here I attach my python file. [...] Unfortunately you forgot to attach your Python code. If your code is short, say less than 100 lines, please just copy and paste it into the body of your email. If it is more than 100 lines but less than, say, 300, attach it as a .py file. If it is bigger than that, please don't send it to the mailing list without asking first. We are volunteers, and it is very unlikely that anyone is going to spend hours working through a ten thousand line file trying to debug it on your behalf. Thank you, -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Old popen turned in subprocess...[SOLVED]
On 18/02/15 00:23, Ken G. wrote: I wish to thanks Danny Yoo and Alan Gauld for providing information on using the new subprocess in printing on paper, Glad to help. I got my desired output printed. Not looking forward to updating my old programs. If it's a common function in your code why not create a module with a function. Then you can simply import it and call the function. import lprinter lprinter_init() ... lprint('some text here') or similar? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT: Preferred email client for sending plain text programming code snippets
On 17/02/2015 23:23, boB Stepp wrote: Hopefully this is not a touchy subject like Emacs vs. Vim. ~(:>)) My home PC uses Win7-64bit. I currently use Chrome, Gmail and have a Nexus 5 phone. The nice thing about all of this is that all of my information usually seamlessly syncs. That is nice! But I am getting increasingly frustrated with Gmail in terms of communicating with this group (and sometimes others). It seems that if I am not constantly attentive, my settings change from plain text to html, or, now, my New Courier fixed-width font vanishes from the Gmail ecosystem and cannot be found. I actually have come to prefer plain text communication as I only rarely need html formatting. And I rarely care to see most of the crap people send me that require html! So are there any recommendations from this group that would make things easy, would still be able to receive/send from my Gmail account, etc.? Thunderbird. Access to 300+ Python mailing lists, blogs and the rest all in one place via gmane. Personally I've never had a single problem with it. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT: Preferred email client for sending plain text programming code snippets
boB Stepp writes: > Hopefully this is not a touchy subject like Emacs vs. Vim. ~(:>)) Heh. If anyone tries to start a Vim-versus-Emacs fight, feel free to cite me as someone well experienced with both who sees no need to be tribal about either of them. > My home PC uses Win7-64bit. My condolences, I hope you soon find a better environment in which to program. > I currently use Chrome, Gmail and have a Nexus 5 phone. One strong piece of advice: Please don't be tempted to compose email messages on a handheld device. The resulting messages are usually significantly worse, in terms of etiquette. Instead, wait until you're at a proper keyboard where you can compose a message that is considerate of readers. > I actually have come to prefer plain text communication as I only > rarely need html formatting. And I rarely care to see most of the crap > people send me that require html! Congratulations! That is a commendable position, I hope you can persuade others within your influence to make the same decision. > So are there any recommendations from this group that would make > things easy, would still be able to receive/send from my Gmail > account, etc.? There are many good email clients. I would recommend you select one which uses standard protocols (nearly all of them do), and which is licensed as free software and works on all major platforms. Google Mail still (I believe) allows you to communicate as the same identity by sending mail using SMTP and accessing your mailboxes via IMAP. You need to learn their specific servers and ports to configure your mail client. On the Android operating system, the leader seems to be K-9 Mail https://f-droid.org/repository/browse/?fdid=com.fsck.k9>; though, again, I'll caution you against composing messages unless you have a real keyboard plugged in and can edit the text easily. On a desktop operating system, I would recommend one of: * Mozilla Thunderbird https://www.mozilla.org/thunderbird/>, very comprehensive and mature. * Claws Mail http://www.claws-mail.org/>, lighter but still with many features, and a good plug-in ecosystem. * Sylpheed Mail http://sylpheed.sraoss.jp/en/>, quite lightweight and focussed. All three are licensed as free software (copyleft, GPL). All three work on the major desktop operating systems. All three have alrge active development and support communities. Interestingly, all three are also “newsreaders”, clients to Usenet's NNTP protocol. This allows even better aggregation of discussion forums, such as those available at GMane. Good hunting! -- \ “Contentment is a pearl of great price, and whosoever procures | `\it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.” —J. Balguy | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What are *appropriate* uses for exec() and eval() ?
On Tue, Feb 17, 2015 at 7:31 AM, Steven D'Aprano wrote: > On Mon, Feb 16, 2015 at 07:10:21PM -0800, Devin Jeanpierre wrote: >> On Mon, Feb 16, 2015 at 6:15 PM, Steven D'Aprano wrote: >> > Here is a fork of that recipe. It uses an inner class for the new >> > namedtuple class. The only thing which needs exec is the __new__ method. >> > >> > http://code.activestate.com/recipes/578918-yet-another-namedtuple/ >> > >> > This demonstrates a powerful truth about Python: *most of the time* you >> > don't need to use exec or eval because the standard language features >> > are powerful enough to solve the problem for you. Using a dynamically >> > created inner class is *almost* enough to solve this problem, only the >> > __new__ method defeats it. If our requirements where just a little less >> > demanding, we could avoid exec completely. >> >> No, exec is not necessary at all. > > I'm not sure that I said that exec was "necessary" anywhere, You said that most of the time you don't "need" to use it. You then explained how you narrowly had to use exec in this case, and could have avoided it if the restrictions were relaxed. That sure sounds like you were saying it was necessary. Maybe you meant to say something else? > but since > you mention it, how about the two earlier examples I gave, timeit and > doctest? Especially doctest. How would you implement doctests without > exec? I already covered this in my response to Cameron: I only meant that in this particular case exec is not needed. >> If they had to the author could have >> reimplemented the argument assignment logic by hand. They chose not to >> because it is "too hard". (And it is.) Fortunately, they don't have >> to go that far: >> >> signature = inspect.Signature([ >> inspect.Parameter(field_name, inspect.Parameter.POSITIONAL_OR_KEYWORD) >> for field_name in field_names]) > > Hmmm. Well, namedtuple was added to Python in version 2.6. [snip] > So much for that idea. What? Why should what was impossible in the past stop you from doing what is possible now? -- Devin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Re: Fwd: Need help with find error
I do not have time to help you right now. Please continue correspondence with the main tutor mailing list. -- Forwarded message -- From: "Андрей Пугачев" Date: Feb 17, 2015 9:20 PM Subject: Re: [Tutor] Fwd: Need help with find error To: "Danny Yoo" Cc: Hi, in this folder https://drive.google.com/folderview?id=0B5_iElL_NLhAfllsSDRlV20wR3JKd0ltdUt0UFNscklLWTAwS1k5b3pjbW9LNG1qNEhsZkE&usp=sharing you get 2 original files and folder "my" where is changed code. thanks for help 2015-02-17 22:29 GMT+02:00 Danny Yoo : > Forwarding to tutor. Again, apologies that I didn't respond earlier. > Overloaded. > > > -- Forwarded message -- > From: Андрей Пугачев > Date: Tue, Feb 17, 2015 at 11:58 AM > Subject: Re: [Tutor] Need help with find error > To: Danny Yoo > > > Anybody can help with this? > > 2015-02-07 10:27 GMT+02:00 Андрей Пугачев : > > > > Sorry for my absense, but you want to say, that loop in code isn't > working? (in main()-function) > > When category is empty code must print 2 last rows, but I have error > > > > I learn python book M. Dawson and this exercise from his book. > > I add original working files, where points count as score +=1 and all > works. > > But if I add some points to each question code don't work. > > I can't understand it/ > > > > > > > > 2015-02-04 20:24 GMT+02:00 Danny Yoo : > >> > >> As a revision of my initial question, when we look at next_block(), > >> it's documented as follows: > >> > >> > >> def next_block(the_file): > >> """Return the next block of data from the trivia file.""" > >> > >> > >> > >> What if there are no more blocks in the file? What should happen then? > >> > >> Let's say that we do a test, where we pass in the empty file to > next_block(). > >> > >> ## > >> from io import StringIO > >> x = next_block(StringIO('')) > >> ## > >> > >> What do you want to happen in this situation? > >> > >> --- > >> > >> As a side note: if you have control over the data format, you might > >> want to consider using JSON rather than a line-based format. If you > >> use JSON, this takes care of a few issues that you are working around > >> now. > >> > >> For example, you can reuse the newline escapes rather than define your > >> own convention. Also, rather than read a stream of records, where you > >> have to deal with the end of the file, you might just read one JSON > >> object that represents your whole trivia file, which will simplify > >> your program's logic. > >> > >> See: https://docs.python.org/2/library/json.html and use your favorite > >> web search engine for 'json python tutorial', and you should be able > >> to find some useful information. If you have questions, please feel > >> free to ask. > > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] text file help
How can I get this ; kl_number = 1202, kl_number = 1403, kl_number = 1802, kl_number = 2801, kl_number = 2502, kl_number = 2303, kl_number = 2254, kl_number = 1682, kl_number = 1403 kl_number = 1304, from text file(formular doznake) . I got this on this way ; def vrs_drv(): vrs_drv = raw_input("Enter a vrs_drv:") if vrs_drv == "21": return("1") if vrs_drv == "22": return("2") if vrs_drv == "41": return("4") number1 = vrs_drv() print("kl_number1:",number1) def prs_prec(): prs_prec = raw_input("Enter a prs_prec:") if prs_prec == "20": return("20") if prs_prec == "40": return("40") if prs_prec == "80": return("80") number2 = prs_prec() print("kl_number2:",number2) def teh_kl(): teh_kl = raw_input("Enter a teh_kl:") if teh_kl == "1": return("1") if teh_kl == "2": return("2") if teh_kl == ("3"): return("3") if teh_kl == ("4"): return("4") number3 = teh_kl() print("kl_number3:",number3) print(number1+number2+number3) print("\n\nPress the enter key to exit.") formular doznake.txt red_broj = 1 vrs_drv = 21 prs_prec = 20 teh_kl = 2 red_broj = 2 vrs_drv = 21 prs_prec = 40 teh_kl = 3 red_broj = 3 vrs_drv = 21 prs_prec = 80 teh_kl = 2 red_broj = 4 vrs_drv = 22 prs_prec = 80 teh_kl = 1 red_broj = 5 vrs_drv = 22 prs_prec = 50 teh_kl = 2 red_broj = 6 vrs_drv = 22 prs_prec = 30 teh_kl = 3 red_broj = 7 vrs_drv = 22 prs_prec = 25 teh_kl = 4 red_broj = 8 vrs_drv = 41 prs_prec = 68 teh_kl = 2 red_broj = 9 vrs_drv = 41 prs_prec = 40 teh_kl = 3 red_broj = 10 vrs_drv = 41 prs_prec = 30 teh_kl = 4 but , I want get this automatically without raw_input ,from text file. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor