[Tutor] Affect of doc strings on performance
Hi,I wanted to know if we give large doc strings in the python scripts, does it slow down the script execution?Should we always keep those doc strings to minimum if we want fast script execution?ThanksAkanksha __Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Affect of doc strings on performance
i don't think it makes any difference. I suppose it will slow down the parsing of the file by a tiny amount, and increase memory usage by the size of the strings, but I don't think it will change execution time. The Python standard library has lots of doc strings. Type help(dict) at the interpreter prompt for an example. The dict class is highly optimized so if doc strings affected speed that would be a problem. If you have a time critical function, you could always time it with and without doc strings to be sure! In Python it's always best to answer "which is faster" questions with real data. Kent Akanksha Govil wrote: > Hi, > > I wanted to know if we give large doc strings in the python scripts, > does it slow down the script execution? > > Should we always keep those doc strings to minimum if we want fast > script execution? > > Thanks > Akanksha > > __ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] dictionary
[EMAIL PROTECTED] wrote: > how can i print a dictionary, sorted by the values? A dictionary itself is an unordered collection and can't be sorted. But you can sort and print the list of key, value pairs returned by dict.items(). For example: In [3]: from operator import itemgetter In [4]: d = { 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four' } In [5]: for k, v in sorted(d.items(), key=itemgetter(1)): ...: print k, '=', v ...: ...: 4 = four 1 = one 3 = three 2 = two d.items() returns a list of (key, value) pairs: In [6]: d.items() Out[6]: [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')] itemgetter(1) actually returns a function which, when called with an argument x, returns x[1]: In [7]: get1 = itemgetter(1) In [8]: get1(d.items()) Out[8]: (2, 'two') In [9]: get1('abc') Out[9]: 'b' Using itemgetter(1) as the key argument to sorted() makes the sort happen on the second item of each pair, the value. (This example requires Python 2.4; Python 2.3 has no sorted() function, you have to do the sort in a separate step using list.sort(). In earlier Python you have to use a different trick called DSU to sort by key.) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] (OT) Monitorising WEB POSTs
I am building a python application to automate information capture from a web site. I want to use a python application to request and process the information instead of using the site's WEB page. However I am having problems finding out exactly what data the server expects. I have a firefox add-in called Web Developer that gives me good information about the form (fields names etc..) But what I want to do is find out exactly what POST data my browser is sending. I am aware of two ways of doing this. a) A sniffer to read the udp packet sent from my computer b) Send the page to my own WEB server Is there a program or add in that will give me this information without resorting to the solutions above. Peter Jessop ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python application on a web page
Tkinter is a multiplatform toolkit for producing programs with graphical interface. But multiplatform refers to BSD, Linux, Mackintosh, Windows etc. If you want to produce the output on the WEB you need to produce the output in HTML or in some way that most users can see it in their Browsers. (Java Script, Flash, etc...) This forum caters well for beginners (and more advanced) and the quality and helpfulness are very high. Here are a some links that may be useful. http://wiki.python.org/moin/BeginnersGuide/NonProgrammers http://www.python.org/doc/Intros.html http://diveintopython.org/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Truly generic database API
It depends on your system constraints. If you are only developing on Windows then you can use ODBC. ODBC supports writing to text files. It is an old fashioned technology and is not very fast. However it is well supported and mature. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (OT) Monitorising WEB POSTs
Install the Firefox extension called "Live HTTP headers", and look at the "Generator" tab. This appears to be what you want. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Jessop Sent: 07 June 2006 11:00 To: tutor@python.org Subject: [Tutor] (OT) Monitorising WEB POSTs I am building a python application to automate information capture from a web site. I want to use a python application to request and process the information instead of using the site's WEB page. However I am having problems finding out exactly what data the server expects. I have a firefox add-in called Web Developer that gives me good information about the form (fields names etc..) But what I want to do is find out exactly what POST data my browser is sending. I am aware of two ways of doing this. a) A sniffer to read the udp packet sent from my computer b) Send the page to my own WEB server Is there a program or add in that will give me this information without resorting to the solutions above. Peter Jessop ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (OT) Monitorising WEB POSTs
Matthew Fantastic! Exactly what I needed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] default module
Message: 3 Date: Tue, 06 Jun 2006 20:59:11 -0400 From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] How do I get Dos to recognize python command? To: Python Tutor > > Besides, I already have one default module saved, and it would seem > complicated to have more than one. I don't know what you mean by this, what is a default module? Kent ** Hello Kent. A while back in time, I wanted to make a library of subroutines. Someone showed me how to tell python to declare the file a module. I don't remember how I did it. Now whenever I want to make the library available, in idle, I type import factor30 from factor30 import factor00, gcd, ksqrt #what ever subroutines I wish to have local I assumed that I could have only one library. That why I called it the default module. Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] default module
Kermit Rose wrote: > From: Kent Johnson <[EMAIL PROTECTED]> >> Besides, I already have one default module saved, and it would seem >> complicated to have more than one. > > I don't know what you mean by this, what is a default module? > > A while back in time, I wanted to make a library of subroutines. > > Someone showed me how to tell python to declare the file a module. > > I don't remember how I did it. > > Now whenever I want to make the library available, > > in idle, > > I type > > import factor30 > from factor30 import factor00, gcd, ksqrt #what ever subroutines I > wish to have local > > I assumed that I could have only one library. > > That why I called it the default module. Hi Kermit, To make a module available for import, you just have to save it somewhere on your Python path. There are several ways to do this, but if you want to make another importable module just save it in the same location as factor30.py. There is no practical limit on how many modules you can have - just RAM and disk space limits, AFAIK. You already have many modules installed as part of the standard library and any third-party add-ons you have installed. If you are working with a module from the interpreter and you make changes to the module, you have to reload it with the command >>> reload(factor30) This won't work for local names (from factor30 import xx)! Just use the full name to access any elements of factor30, e.g. factor30.gcd. Read more here: http://www.python.org/doc/faq/programming/#when-i-edit-an-imported-module-and-reimport-it-the-changes-don-t-show-up-why-does-this-happen Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Offtopic observation
This marks the third time this week I have been typing in a question for the group, and have made the answer apparent just by trying to explain my question clearly. This suggests that either I think better in text, or Proust was onto something ... but then again, I majored in english. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Offtopic observation
On Wed, 7 Jun 2006, doug shawhan wrote: > This marks the third time this week I have been typing in a question for > the group, and have made the answer apparent just by trying to explain > my question clearly. Yes. *grin* It's a very powerful technique. Writing does this for me as well. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Offtopic observation
On Wednesday 07 June 2006 17:55, doug shawhan wrote: > This marks the third time this week I have been typing in a question for > the group, and have made the answer apparent just by trying to explain my > question clearly. > > This suggests that either I think better in text, or Proust was onto > something ... but then again, I majored in english. It's also called confessional debugging :-) It's also something that actually tends to apply outside programming as well. The act of understanding the problem often leads to a solution :-) Michael. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Offtopic observation
> From: Danny Yoo <[EMAIL PROTECTED]> > On Wed, 7 Jun 2006, doug shawhan wrote: > > > This marks the third time this week I have been typing in a question for > > the group, and have made the answer apparent just by trying to explain > > my question clearly. > > Yes. *grin* It's a very powerful technique. Writing does this for me as > well. For me it's often talking. I have a friend in the office I go to when I am stuck on something. He's a very powerful listener - often by the time I am done describing the problem and the available options I have settled on an answer. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] combo box
On Tue, 06 Jun 2006 13:39:21 +0700 kakada <[EMAIL PROTECTED]> wrote: > Dear Friends, > > I am now working on GUI python (Tkinter). > I want to use combobox as my widget, but I cannot find it in any document. > > Does anybody have experience with that? > There is no ComboBox widget in plain Tkinter. Probably the easiest way to get one is to use Tix which is included in the windows python distribution and should be available in any recent linux distro. If you want to use Tix simply replace the import line from Tkinter import * with from Tix import * You then can use your Tknter widgets as usual, plus a nice set of extra widgets (ComboBox, NoteBook, DirTree etc.) . I hope this helps Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] module versus file
Message: 7 Date: Wed, 07 Jun 2006 08:12:59 -0400 From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] default module >> Hi Kermit, To make a module available for import, you just have to save it somewhere on your Python path. There are several ways to do this, *** Yes. By some means that I don't remember I declared the file factor30.py in directory math\factoring to be a module. but if you want to make another importable module just save it in the same location as factor30.py. *** Are you saying that any .py file that I save in math\factoring can be imported? There is no practical limit on how many modules you can have - just RAM and disk space limits, AFAIK. ** Had to look up the acronyn. What is AFAIK? It's an acronym for As Far As I Know. >> You already have many modules installed as part of the standard library and any third-party add-ons you have installed. ** Yes. I'm impressed with the listing in built_in. I assumed system modules were handled in a different way than user modules. * If you are working with a module from the interpreter and you make changes to the module, you have to reload it with the command >>> reload(factor30) * I will try the reload command next time I work with factor30. >> This won't work for local names (from factor30 import xx)! Just use the full name to access any elements of factor30, e.G. factor30.gcd. Read ** In order to have the shorter name, gcd instead of factor30.gcd, I prepare by typing from factor30 import gcd Once someone said that modules and files are not the same thing. This statement left me puzzled. Why not? Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Offtopic observation
On 08/06/06, doug shawhan <[EMAIL PROTECTED]> wrote: > This marks the third time this week I have been typing in a question for the > group, and have made the answer apparent just by trying to explain my > question clearly. I'm usually a step back from that --- the answer becomes apparent approximately five seconds _after_ I send off my question.. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Offtopic observation
Kent Johnson wrote: >> From: Danny Yoo <[EMAIL PROTECTED]> >> On Wed, 7 Jun 2006, doug shawhan wrote: >> >>> This marks the third time this week I have been typing in a question for >>> the group, and have made the answer apparent just by trying to explain >>> my question clearly. >> Yes. *grin* It's a very powerful technique. Writing does this for me as >> well. > > For me it's often talking. I have a friend in the office I go to when I am > stuck on something. He's a very powerful listener - often by the time I am > done describing the problem and the available options I have settled on an > answer. > > Kent > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > I want one of those...hahaha...someone who would listen long enough for me to settle on an answer on my own? God, you're a lucky person. If I so much as shape my mouth like the word "computer" is going to come out, my wife runs for cover...my friends do their best, but most of them aren't great listeners so we end up getting off topic and never do find a solution. My daughter listens, but I have to wait for her to start pre-school for hope of any real response. Consider yourself quite lucky, Kent. Jon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] module versus file
On Wed, Jun 07, 2006 at 06:44:08PM -0400, Kermit Rose wrote: [snip] > > > Yes. By some means that I don't remember I declared the file factor30.py > in directory > math\factoring > > to be a module. > If you are importing a module from a directory other than your current directory, then the directory is effectively a package. In order to make a directory into a package, the directory must contain a file named __init__.py. The file __init__.py can be empty or can contain code. It will be evaluated the first time (and only the first time) an application imports the package or something in it. Dave [snip] -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Offtopic observation
On Thu, Jun 08, 2006 at 10:45:41AM +1200, John Fouhy wrote: > On 08/06/06, doug shawhan <[EMAIL PROTECTED]> wrote: > > This marks the third time this week I have been typing in a question for the > > group, and have made the answer apparent just by trying to explain my > > question clearly. 1. That's why we write and ask questions: to make things clear to ourselves. 2. And the reason we teach (Python etc) is so that students ask us questions and we are forced to explain ourselves, which enables us to understand what we are talking about. Dave > > I'm usually a step back from that --- the answer becomes apparent > approximately five seconds _after_ I send off my question.. > You are one of the quick ones. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor