[Tutor] Programming for Everybody (Python) - Oct 6, University of Michigan
Here is another Python course that starts October 6 2014: https://www.coursera.org/course/pythonlearn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Instead of *.TXT I would like to use *.CSV exported from Excel
On 7/4/2014 1:21 AM, Peter Otten wrote: data = list(data) shuffle(data) Peter, Mitesh and Alan, Thank you for your help! And thank you for explaining details. Now I understand why it worked in my previous (*.TXT) version since it was already as list. Thanks again, program works great now! Mario ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Instead of *.TXT I would like to use *.CSV exported from Excel
OK, I'm finally getting closer. Code bellow (looks like) works if I comment out shuffle part But I need it to shuffle so I get random picked words. How do I get shuffle part to work? from random import shuffle import csv print('Write translation of Slovene word ') print() out=open('c:\\prevedi.csv', 'r', newline='', encoding='utf8') data=csv.reader(out) # shuffle(data) for line in data: question, rightAnswer = line answer = input(question + ' ') if answer.lower() != rightAnswer: print('Correct is: %s.' % rightAnswer,) print() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Instead of *.TXT I would like to use *.CSV exported from Excel
Windows 7, Python 3.4.0 I have a simple translation refresher program that works. For input I'm using TXT file, (prevedi.txt) words in it are separated by coma that I'm editing, adding manually. (adding new 'refresher' words as needed) And program works: from random import shuffle print('Write translation of Slovene word ') print() with open('c:\\prevedi.txt', 'r', encoding='utf8') as f: lines = f.readlines() shuffle(lines) for line in lines: question, rightAnswer = line.strip().split(',') answer = input(question + ' ') if answer.lower() != rightAnswer: print('Correct is: %s.' % rightAnswer,) print() I would like to be able to add more 'refresher' words in Excel instead of TXT fine and then export it to CSV file from Excel. I don't know how to adjust the code for this. From my tries you can see, I don't have a clue about programing. I'm searching the internet and inserting pieces of code I found with the hope that program would work. Whatever I do, I get different error trace backs, too many to post here. I know is it simple, trivial task but I'm just not up to it. Can anyone help me please? This is what I'm trying: from random import shuffle import csv print('Write translation of Slovene word ') print() with open('c:\\prevedi.csv', 'r', newline='', encoding='utf8') as f: # with open('c:\\prevedi.csv', 'r', newline='', encoding='utf8') as csv: tried this one, didn't work lines = f.readlines() # lines = csv.readlines(f) - this one doesn't work as well # lines = cvs.readlines() - neither this one... shuffle(lines) for line in lines: question, rightAnswer = line.strip().split(',') answer = input(question + ' ') if answer.lower() != rightAnswer: print('Correct is: %s.' % rightAnswer,) print() I have a feeling, there is a problem with that 'as f:' part Also, I probably don't need that strip part, csv import probably deals with it, but I don't know how much or which part to delete out... Any time I try to change something, new trace error appears... I'm out of ideas and tries... Who said even blind squirrel... ? Thank you for helping me out, Mario ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] MIT - Free Python course started today
Sort of off topic, (don't kill me) but then again very useful for beginners! MIT started free Python course today: https://www.edx.org/course/mitx/mitx-6-00-1x-introduction-computer-1841 Unfortunately they are using Python 2.7 :-( You can even get a certificate if you finish with high enough score (will cost you something for certificate) Anyway, even if partially off topic I think it may be beneficiary for some beginners here. I'm already going through the lessons :-) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Coma separated instead TAB separated
Steven, How about , for comma? LOL! I didn't know, now I know :-) Thank you also for all additional info. I printed it out! Here is a list of the escape sequences allowed: \a BEL (bell) \b BS (backspace) \f FF (formfeed) \n LF (linefeed or newline) \r CR (carriage return) \t HT (horizontal tab) \v VT (vertical tab) \0 NUL (that's a zero, not the letter Oh) \\ Backslash \' Single quote \ Double quote Of these, the most common one by far is \n. There are also escape sequences for arbitrary characters: \0ddCharacter dd (one or two digits) in octal (base eight) \xddCharacter dd (two digits) in hexadecimal (base sixteen) In both the \0dd and \xdd cases, the value is limited to the range 0 through 255. In octal, that's 0 through 377, or in hex it is 0 to FF. A backslash followed by a newline (end of line) is a line continuation, that is, the newline is ignored: s = this is a really, really, really \ long string. In Unicode strings, you can also use: \u Unicode code point U+ (four digits) in hexadecimal \Uddd Same, but eight digits \N{name}Unicode character called name (They must be exactly 4 digits or 8 digits, nothing in between). Last but not least, any other backslash escape \c gets left alone. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Coma separated instead TAB separated
Thank you Alan, so simple solution! Just show how little I know! You should probably use the csv module instead For now split should be OK, in the future I will try to learn CVS module. OK I understand, new subject, new post, thanks again Mario On 6/8/2014 5:33 PM, Alan Gauld wrote: On 08/06/14 19:56, Mario Py wrote: Hi everyone, this is very basic/beginner question. Hi, Please don;t reply to an existing message to start a new discussion. It messes up the threading and makes it harder for people searching the archives in the future. I'm reading TXT file, two words per line that are separated by TAB: question, rightAnswer = line.strip().split('\t') I would like to use TXT file that it would be separated by coma. How do I change that line of code? You should probably use the csv module instead, it is designed for reading comma separated files (or tab or any other character). But if you really do only have two fields and you know they won't have commas within them then you can do it with split()... I tried these two versions but it is not working: question, rightAnswer = line.strip().split('\c')# c for coma? question, rightAnswer = line.strip().split('\,')# , for coma? Since comma is not a special character you don't need the escape(\) character. So your line should just be: question, rightAnswer = line.strip().split(',') HTH ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Coma separated instead TAB separated
Hi everyone, this is very basic/beginner question. I'm reading TXT file, two words per line that are separated by TAB: question, rightAnswer = line.strip().split('\t') I would like to use TXT file that it would be separated by coma. How do I change that line of code? I tried these two versions but it is not working: question, rightAnswer = line.strip().split('\c')# c for coma? question, rightAnswer = line.strip().split('\,')# , for coma? I have latest Python version. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Android
I'm writing one small simple program that will use Tkinter. Once finished, will I be able to run it on android tablet? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Android
Allan, Hans and Stefan, Thank you for your replies. I will check out Kivy and Google API, thanks a lot for suggestions On 6/4/2014 6:38 AM, Stefan Behnel wrote: Mario Py, 04.06.2014 07:47: I'm writing one small simple program that will use Tkinter. Once finished, will I be able to run it on android tablet? Have a look at kivy, it supports different systems, including various mobile devices. http://kivy.org/ Stefan ___ 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
Re: [Tutor] Translator - multiple choice answer
Danny and C Smith, Thank you very much for your answers. And sorry for late reply I was away. I will start including encoding=utf8 right away. Printing them with numbers is also great idea and decent compromise, thanks The print function puts a newline at the end. You can change this default behavior by providing an end keyword to it. I'm familiar with end from examples from the internet, but I was not successful with how to implement it into my example... Or something else get merged or I get an error... I will keep try and if I don't succeed I will come back here :-) Thanks for all your help! = This might be useful for reading values from a text value into a dictionary: https://stackoverflow.com/questions/17775273/how-to-read-and-store-values-from-a-text-file-into-a-dictionary-python On Wed, May 14, 2014 at 7:00 PM, Danny Yoo d...@hashcollision.org wrote: Program read TXT file (c:\\slo3.txt) In this file there are two words per line separated by tab. First word is foreign language and second word is proper translation, like this: pivobeer kruhbread rdeca red krompir potatoe hisahouse cesta road autocar (not even trying to mess with special characters for now, lol) Do look at: http://www.joelonsoftware.com/articles/Unicode.html because the fact that you're dealing with foreign language means you want to get it right. If it were me, I'd just say that the input is UTF-8 encoded text, and always open up the file in utf-8 mode. myfile = open(slo3.txt, r, encoding=utf8) and just know that we're working with Unicode from that point forward. I was going to read content into dictionary, each pair as tuple but I gave up, couldn't figure it out. Looks like it is working with the list so no problem. Question 1: would be better to use dictionary, than list? It depends. If you're picking out a random entry, then having a dictionary in hand is not going to need the key lookup support that dictionaries give you. For the application you're describing right now, it doesn't sound like you need this yet. Question 2: slo3.txt is just small sample for now and before I type in all words, I would like to know is it better to use some other separator such as coma or empty space instead of TAB? I found on the internet example for TAB only, so this is what I'm using for now. TAB is a reasonable separator. You might also consider comma, as in Comma-Separated Values (CSV). If your data starts having more structure, then check back with folks on the tutor mailing list. There are richer formats you can use, but your program's description suggests that you probably don't need the complexity yet. I need help with two things. First one is simple, basic, but I couldn't figure it out. If I want to print out 'Wrong' part in the same line next to wrong answer, how do I do it? The print function puts a newline at the end. You can change this default behavior by providing an end keyword to it. The documentation mentions it here: https://docs.python.org/3/library/functions.html#print Small test program to demonstrate: print(Hello , end=) print(world ) Now, big, huge help request. I would like to make it easy on my wife instead of her needing to type in answer I would like that she could choose (click on) multiple choice. Say she get 4 or 5 possible answers and one of them is correct. Then she need to click on correct answer... What do I need to do? I understand there will be some graphic/windows things involved. I don't have any additional packages or libraries installed, nor do I know what/how do do it. Complete noob How about printing them with numbers, so that entry is just a number rather than the typed word? You can put a graphical user interface on the program, though it does take a bit more effort to get it to work. Look into Tkinter, which is a library for producing graphical user interfaces: https://wiki.python.org/moin/TkInter Another option might be to turn your program into a web site, so that the interface is the web browser, which everyone is getting used to these days. But this, too, is also... involved. :P ___ 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] Translator - multiple choice answer
Hi all, my first post here and my first ever programing project! (actually stealing code from all over the internet for now) So please be easy on me hints probably will not work with me, I'm complete beginner... I'm trying to create something useful, small program which will help my wife to refresh her foreign knowledge of once already memorized words. Program works. But I would like to expand it a little bit. Program read TXT file (c:\\slo3.txt) In this file there are two words per line separated by tab. First word is foreign language and second word is proper translation, like this: pivobeer kruhbread rdeca red krompir potatoe hisahouse cesta road autocar (not even trying to mess with special characters for now, lol) I was going to read content into dictionary, each pair as tuple but I gave up, couldn't figure it out. Looks like it is working with the list so no problem. Question 1: would be better to use dictionary, than list? Question 2: slo3.txt is just small sample for now and before I type in all words, I would like to know is it better to use some other separator such as coma or empty space instead of TAB? I found on the internet example for TAB only, so this is what I'm using for now. OK here is working code: from random import shuffle print('Write translation of Slovene word ') print() with open('c:\\slo3.txt') as f: lines = f.readlines() shuffle(lines) for line in lines: question, rightAnswer = line.strip().split('\t') # words are two per line separated by TAB. answer = input(question + ' ') if answer.lower() == rightAnswer: a = 0# please ingore this for now, IF wants something here and I don't want to print extra line, output looks OK for now... # print() else: print('Wrong, correct is: %s.' % rightAnswer,) print() I need help with two things. First one is simple, basic, but I couldn't figure it out. If I want to print out 'Wrong' part in the same line next to wrong answer, how do I do it? Now, big, huge help request. I would like to make it easy on my wife :-) instead of her needing to type in answer I would like that she could choose (click on) multiple choice. Say she get 4 or 5 possible answers and one of them is correct. Then she need to click on correct answer... What do I need to do? I understand there will be some graphic/windows things involved. I don't have any additional packages or libraries installed, nor do I know what/how do do it. Complete noob I'm using Python 3.4 and Windows 7. Mario P.s. I'm not even sure if this will show up on Tutor's forum... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor