Re: [Tutor] saving output data in a file
spir wrote: snip class Out(file): def __init__(self, filename, toconsole=True, numberlines=True): file.__init__(self, filename, 'r') print self # debug output to console self.toconsole = toconsole # line numbering self.numberlines = numberlines if self.numberlines: self.linenumber = 0 # save default stdout self.console = sys.stdout def write(self, msg): if self.numberlines: self.linenumber += 1 linenumber = %3d % self.linenumber else: linenumber = text = %s%s\n %(linenumber, msg) self.write(text) if self.toconsole: self.console.write(text) def close(self): # restore default stdout sys.stdout = self.console # close file self.close() In your call to __init__(), shouldn't the file mode have been w not r ? Aren't those write() and close() methods infinitely recursive? I suspect you meant something like: file.write(self, text) and file.close(self) Also, I'm not really sure what you're doing with self.console versus sys.stdout. Since you restore it in close(), I'm assuming you meant to change it at some point in your code. And if you are going to change it, you should flush it first. If you hadn't had the restore code, I'd have guessed instead that you were trying to force all the output to go to the original stdout, even if the caller has reassigned it in the meantime. I didn't actually try your class, but these are problems that jumped out at me. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I plot a horizontal line and a vertical line in python
On Fri, Dec 4, 2009 at 6:17 AM, Mkhanyisi Madlavana mmadlav...@gmail.comwrote: How can I do this using matplotlib? The snippet of my code looks like: snip Am I doing this all the wrong way? This way is easier: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axhline http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axvline HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python at my work
On Fri, Dec 4, 2009 at 9:22 AM, skrab...@comcast.net wrote: Is Python easier to learn that Perl? When we get new developers into our group, the new developer will need to get up to speed on the tools in our arsenal. I haven't had any experience with teaching myself Perl, but I would say yes based on what I do know. One of Perl's philosophies is that there are more than one way to do one thing. Python's philosophy is that there really should be one obvious way of doing something. And from my minimal experience with reading Perl code (and a few modifications) and decent experience reading (and modifying) other's Python code, Python is tremendously easier - especially on those new to the language. Here's an interesting source: http://wiki.python.org/moin/PerlPhrasebook HTH, Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn’t. - Primo Levi ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python at my work
Wayne Werner waynejwer...@gmail.com wrote One of Perl's philosophies is that there are more than one way to do one thing. Python's philosophy is that there really should be one obvious way of doing something. And from my minimal experience with reading Perl code (and a few modifications) and decent experience reading (and modifying) other's Python code, Python is tremendously easier - especially on those new to the language. Whiler I would agree Perl fans wouldn't. Remember Perl's Larry Wall does not coming from a computing background (as does Guido) but from a Nartural Language backgropund. Thus he designed Perl to have the natural expressibeness of English including multiple idioms for saying the same thing. Thus to Perl fans more than one way is the right way! Programming language choice is a hugely subjective topic. -- Alan Gauld 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] mod_python authentication
how to check whether a user is authenticated with mod_python ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dictionary Comprehensions
Khalid Al-Ghamdi wrote: Hi everyone! I'm using python 3.1 and I want to to know why is it when I enter the following in a dictionary comprehension: dc={y:x for y in list(khalid) for x in range(6)} I get the following: {'a': 5, 'd': 5, 'i': 5, 'h': 5, 'k': 5, 'l': 5} instead of the expected: {'a': 0, 'd': 1, 'i': 2, 'h': 3, 'k': 4, 'l': 5} and is there a way to get the target (expected) dictionary using a dictionary comprehension. note that I tried sorted(range(6)) also but to no avail. thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Are you maybe looking for `dc = {y:x for y,x in zip('khalid', range(6))}` ? -- Kind Regards, Christian Witts ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor