Re: [Tutor] exercise with classes
On Feb 2, 2012, at 12:36, Tonu Mikk tm...@umn.edu wrote: snip I feel stumped and don't know how to go about creating this game with two classes. So far I have searched for info on how to pass variables from one class to another and have been able to create a small two class program (attached). snip Thank you, Tonu classes_test.py __ Hi Tonu. I'm fairly certain that your second class is missing the most important function of a class, the __init__ function! It's necessary to initialize the object. Add it to your second class and see how it changes things. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Zip, tar, and file handling
On Jan 6, 2012, at 22:57, daedae11 daeda...@126.com wrote: I was asked to write a program to move files between ZIP(.zip) and TAR/GZIP(.tgz/.tar.gz) or TAR/BZIP2(.tbz/.tar.bz2) archive. my code is: import zipfile; import tarfile; import os; from os import path ; def showAllFiles(fileObj): if fileObj.filename.endswith(zip): if isinstance(fileObj, zipfile.ZipFile): print j*20; for name in fileObj.namelist(): print name; else: for name in fileObj.getnames(): print name; def moveFile(srcObj, dstObj): fileName = raw_input(input the name of the file to move: ); srcObj.extract(fileName); if isinstance(dstObj, zipfile.ZipFile): dstObj.write(fileName); else: dstObj.addfile(tarfile.TarInfo(fileName)); os.remove(fileName); def main(): intro = enter a choice (M)ove file from source file to destinatiom file (S)how all the files in source file (Q)uit your choice is: srcFile = raw_input(input the source file name: ); dstFile = raw_input(input the destination file name: ); while True: with ( zipfile.ZipFile(srcFile, r) if srcFile.endswith(zip) else tarfile.open(srcFile, r+:+path.splitext(srcFile)[1][1:]) ) as srcObj, \ ( zipfile.ZipFile(dstFile, r) if dstFile.endswith(zip) else tarfile.open(dstFile, w+:+path.splitext(dstFile)[1][1:]) ) as dstObj: choice = raw_input(intro)[0].lower(); if choice == s: showAllFiles(srcObj); elif choice == m: moveFile(srcObj, dstObj); elif choice == q: break; else: print invalid command! if __name__ == '__main__': main(); But there are some problems. 1. It could extract file successfully, but can't add files to .tar.gz file. 2. I think it's a little tedious, but I don't know how to improve it. Please give me some help , thank you! daedae11 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi there. I would start by handling file extensions other than ZIP in your first two functions. Why not handle if the file is a tgz or tbz within the functions. Also I don't see the purpose of the first function, showallfiles it prints out twenty js? Looking forward to your response. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list mail formatting
On Dec 22, 2011, at 4:10, Alan Gauld alan.ga...@btinternet.com wrote: On 22/12/11 03:34, Alexander wrote: We request, and advise where possible, on setting up email in plain text, but we do not insist It's a frustration to most folks who were brought up on plain-text email. I'm glad I came across this thread. I've been following a few posts here and there, and now that Alan has posted I feel comfortable exchanging emails for this mailing list from here on in rich formatting. Notice I didn't say we encourage it. If you can send mails in plain tesxt you will avoid many problems, particularly in code formatting issues. You will also avoid frustrating those who might help you. But, if you can't figure out how to send in plain text we would rather you posted RTF than not post at all! But if you ever want to grow as a programmer and use any of the more advanced technical mailing lists you will find them less accomodating. So avoiding plain text may work here but will ultimately be limiting to your learning. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ __ Ah I know of what you mentioned. On an GNU Emacs mailing list I was advised to avoid anything but plaintext. It just seems so archaic. But I'm a novice and will learn why eventually. Alexander. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Blacklist?
I'm top posting because the link below is spam. Does the email address who sent the message get blacklisted or punished? Alexander On Nov 27, 2011, at 4:45, Mario Cavett ma_developm...@hotmail.com wrote: Hola. finally my aunt gave me a push in the right direction this turned my luck around now im making my way to the top I promise youll love it http://gabfair.com/profile/29DavidScott/ see you later ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Blacklist?
On Nov 27, 2011, at 17:55, Steven D'Aprano st...@pearwood.info wrote: Alexander Etter wrote: I'm top posting because the link below is spam. Why on earth do you think that it is acceptable to repeat spam on the list just because you top post? If you have to reply to spam, does your backspace key not work? ESPECIALLY the spammer's URL. -- Steven Sorry Steven! I've learned my lesson. Alexander. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Shorten Code.
On Nov 18, 2011, at 13:15, ALAN GAULD alan.ga...@btinternet.com wrote: for var in [value,value_1]: var = green Um, that won't work. You typed that example too quickly. Oops! Yes. You'd need to enumerate and access the variables via an index. yuk. Don't do it folks! :-) Excuse: It was early morning and I hadn't had any coffee... Alan G. In your defense Alan, after you typed that code in your response you mentioned the necessity of defining the variables: But you need to have already created the variables somewhere and unless there is a big list its not usually worth while. Alexander Etter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Suggest Book
On Nov 11, 2011, at 9:29, Pankaj Jakhar pankajjakh...@gmail.com wrote: Hello Please suggest me the best book for Python from which I can learn basics to advanced Python. Thank you. PankaJ Jakhar I'm sure Alan or one of our veteran list members will have something to say, but at my school for a class called intro to problem solving or something like that CS1114, the book used is by T. Gaddis, Introduction to Python. I think. I may be incorrect. I'll check it out on amazon. Alexander ___ Tutor - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Find all strings that....
Hi. My friend gave me a good wake up exercise which I do not want you to solve for me: find all strings which can be converted to alpha with at most two operations, where alpha is some string constant, and a substring of at least length three of alpha must be in the answers. So, my question is: is there a library or .txt dictionary ( not the data type, rather the merriam webster kind ) I can use to test my script on? I'd imagine this library/dictionary to contain thousands of words. Not random words. Thanks for reading, Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Find all strings that....
On Nov 10, 2011, at 13:52, Francesco Loffredo f...@libero.it wrote: Alexander Etter wrote: Hi. My friend gave me a good wake up exercise which I do not want you to solve for me: find all strings which can be converted to alpha with at most two operations, where alpha is some string constant, and a substring of at least length three of alpha must be in the answers. I'd like to try this exercise too; would you mind defining operations more specifically, please? Given a sufficiently broad meaning of operations (e.g. operation = any function call) then any word can be converted into any given word with at most ONE operation. Consider an operation not as a function. A function could easily contain more than two operations. An operation would remove two letters. An operation would add one letter. Etc. Alexander So, my question is: is there a library or .txt dictionary ( not the data type, rather the merriam webster kind ) I can use to test my script on? I'd imagine this library/dictionary to contain thousands of words. Not random words. http://www.cs.nmsu.edu/~hfugal/cs167/labs/words.txt Thanks for reading, Alexander More thanks for writing! Francesco - Nessun virus nel messaggio. Controllato da AVG - www.avg.com Versione: 2012.0.1869 / Database dei virus: 2092/4606 - Data di rilascio: 09/11/2011 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GNU Emacs and Python
On Oct 31, 2011, at 15:31, Tim Johnson t...@akwebsoft.com wrote: * Rinu Boney rinu.mat...@gmail.com [111031 07:03]: I Use Windows.I Already Know C/C++ which makes python syntax seem very easy. Maybe Setting Up Emacs With Python Will Make Me Productive. I Have Eclipse With PyDev. Why Is There Not A Pythonic Emacs? Rinu, by this time I believe that Alan has addressed your question above. He has also (wisely) provided caveats regarding the difficulty of learning emacs itself. I'll take a reverse of Alan's comments, not to contradict him, but to give a possible different perspective: If you learn to use emacs with python, you will essentially be learning *two* programming languages: Python _and_ elisp, which is the internal programming language of emacs. Emacs is essentially an elisp interpreter. There may be advantages to learning two languages simultaneously. This will take time. A lot of time. Do you have the time? Will you be compensated for the time? :) having two additional programming languages under your belt may be considered compensation. In case you do not know this: Emacs has the ability to run the python or language-your-choice interpreter asynchronous within the editor, in it's own window. There could be great advantages to this. I have in the past, written elisp code that allows me two write code in one window and have it evaluated in the 'python window' or 'language-of-your-choice window'. I'll reiterate what I said earlier, I no longer use emacs, but have great respect for it. I use vim linked against the python binary so that I can use python code to enhance my (hand-rolled) IDE. grin I much prefer python code to elisp code. I hope my comments are of some help. I'm sure that you have been well informed as to what you would be getting youself into. :) regards -- Tim Rinu, I use emacs. I use Python and C++. I'm also a university student. Last semester I learned python 2.7 using IDLE, and continued with IDLE while I searched for alternatives over the summer. I didn't find what I was looking for. Say, just a few weeks ago I started my C++ course and switched to emacs since the professor was using it. I tried it, read the easy to understand documentation, and I am so productive, jubilant, and satisfied with GNU Emacs. It's extensible beyond immediate comprehension; like a sunflower it starts as a seed, sprouts leaves, etc; I'm elaborating the infinite usability of emacs. There is a learning curve. One may find a learning curve with everything in existence, whereas I repudiate one discouraging another for the aforementioned. Those who desire the power of emacs seek it. Tim, do you use GNU Emacs? From what literature I've encountered including a wikipedia page I believe there is a satiric starwars-like cold-war feud between users of vi and emacs. I'm neutral and won't judge an entity or patronize one for their use of free will. I'm happy. Forgive me if I appear too anything. Good Day. Alexander Etter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On Nov 1, 2011, at 12:47, Chris Hare ch...@labr.net wrote: I am working on a python Tk program which involves a login window and I am looking for some advice. Currently the code I have creates a window (Toplevel) where the login controls are and I am running that using a main loop for the window. The root window is hidden. The objective is that when the user ha successfully authenticated, the login window is closed or the main loop os exited and then the root window is shown and the main loop started for the actual application. Questions: 1. Is this the best way of doing this or is there a better way? 2. How do I exit the main loop when the user has authenticated? Thanks Chris Hare ch...@labr.net Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Hi, hopefully a more experience hacker can provide clarity, but how secure does this login need to be? I dont much about python in DRAM but your login sounds like it could be easily hacked. Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GNU Emacs and Python
On Nov 1, 2011, at 16:06, Wayne Werner waynejwer...@gmail.com wrote: On Tue, Nov 1, 2011 at 6:31 AM, Alexander Etter rhettna...@gmail.com wrote: There is a learning curve. Yes, and for a graphical comparison of learning curves: http://jeetworks.org/files/images/emacs_learning_curves.png ;) One may find a learning curve with everything in existence, whereas I repudiate one discouraging another for the aforementioned. Those who desire the power of emacs seek it. Tim, do you use GNU Emacs? From what literature I've encountered including a wikipedia page I believe there is a satiric starwars-like cold-war feud between users of vi and emacs. I'm neutral and won't judge an entity or patronize one for their use of free will. I think these days a lot more people have become more pragmatic (or maybe I just hang around more levelheaded people now ;) but there are few better ways to start a flame war on IRC or USENET than ask the question which is better - vi or emacs. I grew up using vim, and I personally prefer modal editing - something about my brain prefers the clear distinction between writing my code and editing my code. For a while I tried emacs (mainly because I started learning Lisp, and I was working at a .NET shop and they had some horribly basic emacs shortcuts), and got lots of wrist cramps using chords for everything, even after I changed the caps key to control like it should be. My only recommendation is that you should learn emacs, vim, (or both, if you're crazy like I was ;) because you will be a *much* more productive programmer, simply because you can do things with both emacs and vim that you cannot do in more basic editors. Anyhow, just my two-bits. -Wayne I like than .png image! It does appear vi biased though! Alexander___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to replace the '\'s in a path with '/'s?
On Jul 31, 2011, at 1:28, Richard D. Moores rdmoo...@gmail.com wrote: 64-bit Vista Python 3.2.1 I would like to write a function that would take a path such as 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' and return 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf' . I've tried this: def test(path): return path.replace('\', '/') print(test('C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf')) gets me File c:\P32Working\untitled-5.py, line 2 return path.replace('\', '/') ^ SyntaxError: EOL while scanning string literal Process terminated with an exit code of 1 Thanks, Dick Hi Dick. EOL means End-of-line. Try using double slashes when specifying a path. The back slash \ by itself may be interpreted as an escape character or keyword. For example: print(test('C:\\Users\\Dick\\Desktop\\Documents\\Notes\\CollegeNotes.rtf')) Hope that helps, Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mailing list documentation
Hello everyone, is there a page that contains documentation for this mailing list? I've seen a few users top post and others advise against it; if there isn't a page listing conventions let's create it and if there is what is it's URL and how do you suggest users read it? Alexander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor