Re: [Tutor] Why difference between printing string typing its object reference at the prompt?
On Mon, Oct 8, 2012 at 10:35 PM, boB Stepp robertvst...@gmail.com wrote: I am not up (yet) on the details of Unicode that Python 3 defaults to for strings, but I believe I comprehend the general concept. Looking at the string escape table of chapter 2 it appears that Unicode characters can be either 16-bit or 32-bit. That must be a lot of potential characters! There are 1114112 possible codes (65536 codes/plane * 17 planes), but some are reserved, and only about 10% are assigned. Here's a list by category: http://www.fileformat.info/info/unicode/category/index.htm Python 3 lets you use any Unicode letter as an identifier, including letter modifiers (Lm) and number letters (Nl). For example: aꘌꘌb = True aꘌꘌb True Ⅰ, Ⅱ, Ⅲ, Ⅳ, Ⅴ = range(1, 6) Ⅰ, Ⅱ, Ⅲ, Ⅳ, Ⅴ (1, 2, 3, 4, 5) A potential gotcha in Unicode is the design choice to have both [C]omposed and [D]ecomposed forms of characters. For example: from unicodedata import name, normalize s1 = ü name(s1) 'LATIN SMALL LETTER U WITH DIAERESIS' s2 = normalize(NFD, s1) list(map(name, s2)) ['LATIN SMALL LETTER U', 'COMBINING DIAERESIS'] These combine as one glyph when printed: print(s2) ü Different forms of the 'same' character won't compare as equal unless you first normalize them to the same form: s1 == s2 False normalize(NFC, s1) == normalize(NFC, s2) True I don't see a mention of byte strings mentioned in the index of my text. Are these just the ASCII character set? A bytes object (and its mutable cousin bytearray) is a sequence of numbers, each in the range of a byte (0-255). bytes literals start with b, such as b'spam' and can only use ASCII characters, as does the repr of bytes. Slicing returns a new bytes object, but an index or iteration returns integer values: b'spam'[:3] b'spa' b'spam'[0] 115 list(b'spam') [115, 112, 97, 109] bytes have string methods as a convenience, such as find, split, and partition. They also have the method decode(), which uses a specified encoding such as utf-8 to create a string from an encoded bytes sequence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Saving GUIs
Hi, I have started creating GUIs. But my current challenge now is saving the GUIs created. I have observed that whenever I close the console, the GUIs also get closed. So, please what do I need to do to save the GUIs, or call them back when next needed, if they don't actually get extinguished when the console is closed? I use Python 3.2 on windows 7. Regards. Tayo.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Saving GUIs
On 10/09/2012 12:27 PM, tayo rotimi wrote: Hi, I have started creating GUIs. But my current challenge now is saving the GUIs created. I have observed that whenever I close the console, the GUIs also get closed. So, please what do I need to do to save the GUIs, or call them back when next needed, if they don't actually get extinguished when the console is closed? I use Python 3.2 on windows 7. Regards. Tayo. First question is whether that console is desired in the first place. It may depend on which GUI library you're using (wx, tkinterf, ...) but Windows has a habit of requiring a console to be sitting around for each application, just in case it decides to display something on it. The usual workaround is to run PythonW.exe instead of Python.exe. One way to cause this is to rename the main script to have an extension of .pyw instead of .py , assuming the appropriate file associations exist. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Saving GUIs
On 09/10/12 17:27, tayo rotimi wrote: Please do not reply to an existing thread to create a new topic. Send a fresh email to tutor@python.org. Using an existing one means your messages get inserted amongst messages for the original thread making them hard to find and follow the thread. I have started creating GUIs. What are you using to create the GUIs? Which GUI library? Is it Tkinter, wxPython or something else? But my current challenge now is saving the GUIs created. What do you mean by saving the GUI? The GUI should normally be created in a Python program file (aka a script) which you run from the console (or in Windows by clicking on it in Windows explorer). To save the program just save the file. Are you using a development tool such as IDLE or pythonwin to create the .py program file? If so which one? I have observed that whenever I close the console, the GUIs also get closed. Which console are you talking about? The one where you started the program? The one where you created the program? or the one that sometimes starts when you start the GUI? So, please what do I need to do to save the GUIs, or call them back when next needed, if they don't actually get extinguished when the console is closed? You need to rerun the program file, assuming you are creating one and not just typing the commands into the prompt. If you are just typing them at the prompt then you need to type them into a file instead. Send a reply answering the questions above and we will be in a better position to help you. -- 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
[Tutor] I am learning python3 and would like some more python3 modules/programs on my...
version python3.2 linux I am learning python3 and would like some more python3 modules/programs on my computer to look at and work with to learn more about python3. I have read the tutorial and some of the complete language reference. I can't tell from the package index whats a python3 module/program and whats for 2.X. I seems from the voting guide that their are not many python3 programs; did I learn python at the wrong time? If possible I would like to get involved with a python3 program despite the fact I would not be at first a good programmer (It may help you to know that python3 is my first language though I did try to learn ruby but I did not like the language much [I like python though]) unfortunately their does not seem to be much choice of what to or not to help program. On my OS their are only a few bindings to libraries the standard python installation and the python3-tools package which contains some turtle programs and examples of programming in python. To give you an idea of what I should li ke to work in I eventually want to create with python something like a voice recognition program though not to recognize voice but rather music. Though I intend to create more then the afore mentioned program so any branch of application programming would do, I intend to create it first. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] using the loop function while another
Ok, here is my problem. If a person has two different people to order books for, then when using the loop option, How do you add the two seperate choices together for a final total of books cost? another='y' while another=='y' or another=='Y': choice() another=input('Do you have another book to order for this student? '+\ 'Enter y for yes: ') def choice(): book=int(input('Enter the book chioce you want: ' +\ 'For Hardback Enter the number 1: ' +\ 'Paperback Enter the number 2: ' +\ 'Electronic Enter the number 3: ')) num=int(input('Enter how many you need: ')) cost=0 if book==1: cost=79 elif book==2: cost=49 elif book==3: cost=19 b_total=float(cost*num) print('Your book cost is $ ',format(b_total,'.2f')) -- Amanda Colley ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] using the loop function while another
On 09/10/2012 20:47, Amanda Colley wrote: Ok, here is my problem. If a person has two different people to order books for, then when using the loop option, How do you add the two seperate choices together for a final total of books cost? another='y' while another=='y' or another=='Y': choice() another=input('Do you have another book to order for this student? '+\ 'Enter y for yes: ') def choice(): book=int(input('Enter the book chioce you want: ' +\ 'For Hardback Enter the number 1: ' +\ 'Paperback Enter the number 2: ' +\ 'Electronic Enter the number 3: ')) num=int(input('Enter how many you need: ')) cost=0 if book==1: cost=79 elif book==2: cost=49 elif book==3: cost=19 b_total=float(cost*num) print('Your book cost is $ ',format(b_total,'.2f')) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Create an empty list at the top of your loop. Store your b_total in the list inside the loop with the append method. When the loop finishes use the built-in sum function to get the final total. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] I am learning python3 and would like some more python3 modules/programs on my...
frank ernest wrote: version python3.2 linux I am learning python3 and would like some more python3 modules/programs on my computer to look at and work with to learn more about python3. I have read the tutorial and some of the complete language reference. I can't tell from the package index whats a python3 module/program and whats for 2.X. I seems from the voting guide that their are not many python3 programs; did I learn python at the wrong time? If possible I would like to get involved with a python3 program despite the fact I would not be at first a good programmer (It may help you to know that python3 is my first language though I did try to learn ruby but I did not like the language much [I like python though]) unfortunately their does not seem to be much choice of what to or not to help program. On my OS their are only a few bindings to libraries the standard python installation and the python3-tools package which contains some turtle programs and examples of programming in python. To give you an idea of what I should like to work in I eventually want to create with python something like a voice recognition program though not to recognize voice but rather music. Though I intend to create more then the afore mentioned program so any branch of application programming would do, I intend to create it first. Python 2 and Python 3 are pretty similar syntactically, but it can be a bit challenging for a beginner. This might help tell you how to map from 2 to 3 or vice-versa. http://docs.python.org/py3k/whatsnew/3.0.html As for choosing between Python 2 and 3, it really depends on what you want to do and if the libraries are available for Python 3 or not. For example, PIL is a popular Python image manipulation library and I believe is only Python 2 officially. Of course, if you do not need PIL then it does not matter which you pick. Given no definite goal or task to create, I would suggest learning Python 3 as I think Python 2 will only get security fixes. I have no knowledge of music/voice analysis modules but maybe this will give you a start. http://wiki.python.org/moin/PythonInMusic http://stackoverflow.com/questions/6356749/music-analysis-and-visualization You can even think about switching later if necessary. Although, it is probably easier to go from 2 to 3 due to the existence of automated conversion tools. I would imagine that even if your OS only includes a few bindings, it is probably not a big deal to compile / install your own python packages (including library bindings). IT is possible that your package manager might not name all python bindings as python-*; sometimes they are named program-python. Nobody is a good programmer at first, it takes practice and experience. Good luck and feel free to ask more questions when you run into a problem. This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] using the loop function while another
Mark Lawrence wrote: On 09/10/2012 20:47, Amanda Colley wrote: Ok, here is my problem. If a person has two different people to order books for, then when using the loop option, How do you add the two seperate choices together for a final total of books cost? another='y' while another=='y' or another=='Y': choice() another=input('Do you have another book to order for this student? '+\ 'Enter y for yes: ') def choice(): book=int(input('Enter the book chioce you want: ' +\ 'For Hardback Enter the number 1: ' +\ 'Paperback Enter the number 2: ' +\ 'Electronic Enter the number 3: ')) num=int(input('Enter how many you need: ')) cost=0 if book==1: cost=79 elif book==2: cost=49 elif book==3: cost=19 b_total=float(cost*num) print('Your book cost is $ ',format(b_total,'.2f')) Create an empty list at the top of your loop. Store your b_total in the list inside the loop with the append method. When the loop finishes use the built-in sum function to get the final total. -- Cheers. Mark Lawrence. I would also have choice() return the choice and num and then let the function calling it assign the book price. another='y' while another=='y' or another=='Y': book_format = choice() # rename to be more descriptive e.g. get_book_format() price = price_by_format(book_format) subtotal.append(price) another=input('Do you have another book to order for this student? '+\ 'Enter y for yes: ') The backslash near the + is also unnecessary and I consider it a sign of a possible bad habit/practice. You can usually wrap your multi-line expressions with a parenthesis. input(' blah ' + 'blah2') OR x = (something * something_else + some_fucntion_call() + last_thing_here) OR if blah and ( blah != shoo and shoo != 1 and shoo 5 and blah is not None ): print('true') This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] using the loop function while another
On 09/10/12 20:47, Amanda Colley wrote: Ok, here is my problem. If a person has two different people to order books for, then when using the loop option, How do you add the two seperate choices together for a final total of books cost? This looks a bit like it might be homework so I won't answer directly but will give some general comments that might help... another='y' while another=='y' or another=='Y': This line should not be indented. It's usually easier to convert the string being tested to a known case. Either while another.lower() == 'y': or while another.upper() == 'Y': choice() choice does not return any values so you cannot access the data inside. You want to get back the cost (and maybe the book too!) another=input('Do you have another book to order for this student? '+\ 'Enter y for yes: ') Using a line continuation character is not needed here. Using string addition is usually the wrong approach in Python. In this case you could use string literal concatenation: another=input('Do you have another book to order for this student?', 'Enter y for yes: ') or just a single long line. In case you think this will put it on two lines you are wrong, it will need an exp[licit newline character ('\n') to do that: another=input('Do you have another book to order for this student?', '\nEnter y for yes: ') or you could use triple quotes: another=input(''' Do you have another book to order for this student? Enter y for yes: ''') Lots of choices... def choice(): book=int(input('Enter the book chioce you want: ' +\ 'For Hardback Enter the number 1: ' +\ 'Paperback Enter the number 2: ' +\ 'Electronic Enter the number 3: ')) num=int(input('Enter how many you need: ')) cost=0 if book==1: cost=79 elif book==2: cost=49 elif book==3: cost=19 while this would work I'd prefer to use an else clause to catch unexpected values explicitly rather than rely on the initialisation: cost=0 # this becomes redundant if book==1: cost=79 elif book==2: cost=49 elif book==3: cost=19 else: cost = 0 b_total=float(cost*num) print('Your book cost is $ ',format(b_total,'.2f')) As a general rule its better to keep presentation and logic separate so rather than printing the result inside the function return the value and the calling code can then print it out. Or store it for further processing(hint!) def choice(): # ... as above except the end: ... b_total=float(cost*num) return b_total And where you call it print('Your book cost is $ ',format(choice(),'.2f')) To do more than one book you need your loop to collect the values rather than print them (or add them as you go) then when done sum() the values and print the result. HTH -- 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] using the loop function while another
On Tue, Oct 9, 2012 at 7:39 PM, Alan Gauld alan.ga...@btinternet.com wrote: another=input('Do you have another book to order for this student?', '\nEnter y for yes: ') Remove the comma, and this will parse correctly. A comma in a function call is used to separate arguments. On its own a comma creates a tuple -- outside of a list or dict and assuming parentheses for precedence where necessary. or you could use triple quotes: another=input(''' Do you have another book to order for this student? Enter y for yes: ''') This retains the leading spaces. You can use textwrap.dedent() to remove them: print(textwrap.dedent( ... Do you have another book to order for this student? ... Enter y for yes: )) Do you have another book to order for this student? Enter y for yes: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor