Re: [BangPypers] Good Python training in blr
On Tue, Jun 16, 2009 at 10:27 AM, Dhananjay Nenedhananjay.n...@gmail.com wrote: I respect your calibre in training yourself. But cannot respect every organisation has the same luxury of waiting for programmers to train themselves so that they can eventually start using python. I trained myself in C and even parts of C++. But when I attended a training programme by one of the core C++ team members, it substantially expanded my capabilities on C++. Can't see how calibre is linked to being trained .. every one of us has the potential to be trained further - low, medium or high calibre. What C++ core team member? :-/ Roshan ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] How to create Debug and Release code in Python
Vishal wrote: *Is there a way to create a conditionally compilable Python script ?* Some facility that would prevent from code getting compiled into .pycsomething like the old #ifdef #endif preprocessor directivesis there a Python preprocessory available :) I've given this more thought. In the April 2009 issue of Python Magazine is a wonderful article by Paul McGuire on writing Domain Specific Languages. It shows how to intercept the import of specific types of files to preprocess the source before compiling it into bytecode. I played with those ideas to see what could be done for your case. So say you had a module marked up with special commenting like: --- cut here --- abc.pyp def main(): print Hello #? DEBUG print There #? DEBUG2 print World --- cut here --- abc.pyp Then in your main module you could do the following: --- cut here --- demo.py import cond_importer # can put in site.py for global application import abc abc.main() --- cut here --- demo.py Now you run the program normally and get: $ python2.5 demo.py Hello There World or you can filter out lines using: $ EXCLUDES=DEBUG python2.5 demo.py There World or even: $ EXCLUDES=DEBUG:DEBUG2 python2.5 demo.py World The magic to make this happen is just: --- cut here --- cond_import.py from __future__ import with_statement # for Python 2.6 import os import imputil import re patt = re.compile(r.*#\? (?Ptag[_a-zA-Z][_a-zA-Z0-9]*)$) try: # construct a set of tags to exclude in .py source pyexcludes = frozenset(os.environ['EXCLUDES'].split(':')) except Exception: pyexcludes = frozenset() def preprocess_source(filepath, fileinfo, filename): src = [] with file(filepath, 'r') as f: for line in f: m = patt.match(line) if m is None or m.group('tag') not in pyexcludes: src.append(line) src = '\n'.join(src) codeobj = compile(src, filepath, 'exec') # create return tuple: # import flag (0=module, 1=package) # code object # dictionary of variable definitions return 0, codeobj, {} importer = imputil.ImportManager() importer.add_suffix('.pyp', preprocess_source) importer.install() --- cut here --- cond_import.py I arbitrarily chose a file extension of .pyp for files to preprocess but you could use anything. And the tags to exclude could instead be tags to include. For handling packages (dirs) instead of modules you'd have to add a test for file or directory and change the code a bit. Anyway it raises some interesting possibilities of preprocessing. Python is just so cool. -Jeff ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Good Python training in blr
Sorry folks. Some editing on what i just typed. still learning still are learning to face when encouraged to face On Tue, Jun 16, 2009 at 11:02 AM, jayasimha makineni jayasimha.makin...@gmail.com wrote: Kenneth, You have been hitting the nail on its head repeatedly. I enjoy watching (reading) that. Let us train more programmers who can truly be *programmers*. Python is perhaps the best vehicle for that journey. My understanding is that those who claim to be good programmers do not like it if they are told on their face that they still learning to be just programmers. (What is wrong with life long learning anyway ? It is never late to learn). And their managers have an even worse feeling to face facts because they have to justify their salaries and other bills too. jayasimha ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Good Python training in blr
On Tue, Jun 16, 2009 at 10:59 AM, Ramdas Sram...@developeriq.com wrote: IMHO, even an experienced hand in C/C++ or Java need not take to Python easily, because of the baggage they carry, and they expect certain things to work the way their favorite language works. This can be quite frustrating if learning Python is for a project they need to start next Monday. This is where a trainer can help, because the trainer can guide and point out potential pitfalls, and get a developer through the basics in a jiffy. This baggage is indeed an issue. Thinking in terms of a new language would require reading a lot of code written using that language, and then too, one cannot be certain. To give you my own example, I learned my Object Oriented Programming from really senior Smalltalkers, and I developed and sold components based on excellent IBM business object frameworks. After I joined Thoughtworks, I was exposed to a different world where dependency injection was proposed as an alternative to getters and setters (accessors, as some of us may call them), where the line between do the simplest thing possible and do what ever is necessary to complete just _your_ work for the day can be a fine line, and where the same Java language that I had used for six years, was now being used in a different way. I had a lot of excess luggage, some of which I still lug around with me - and all this was on the same language that I had been using. When you move to a different language, there would have to be paradigm shifts, new ways of thinking, and even pitfalls that one may not recognize to be a pitfall. In such cases, I feel that it can help if one has something like Python for Java programmers - either as a book, as a series of sample code and or web page articles, or even a training session. -- Sriram ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] How to create Debug and Release code in Python
On Tue, Jun 16, 2009 at 11:57 AM, Jeff Rushj...@taupro.com wrote: I've given this more thought. In the April 2009 issue of Python Magazine is a wonderful article by Paul McGuire on writing Domain Specific Languages. It shows how to intercept the import of specific types of files to preprocess the source before compiling it into bytecode. I played with those ideas to see what could be done for your case. This was informative. Thank you ! -- Sriram ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Good Python training in blr
On Tue, Jun 16, 2009 at 11:02 AM, jayasimha makineni jayasimha.makin...@gmail.com wrote: Kenneth, You have been hitting the nail on its head repeatedly. I enjoy watching (reading) that. Let us train more programmers who can truly be *programmers*. Python is perhaps the best vehicle for that journey. My understanding is that those who claim to be good programmers do not like it if they are told on their face that they still learning to be just programmers. (What is wrong with life long learning anyway ? It is never late to learn). And their managers have an even worse feeling to face facts because they have to justify their salaries and other bills too. jayasimha ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers You seem to be questioning the wrong problem. What you state might be entirely true but is irrelevant in this context. Any given company has a million kabillion things to do. Resources are precious, and allowing them to self-learn on company time is not exactly a wise financial decision. There is no easy way to monitor them and measure their progress if they do self-learn. A lot of people might not take to the decision seriously enough and as mentioned by other posters, might carry around serious paradigm based baggage. Several C/C++ people I've known take their time to find their footing with perl, esp with using Hash as an important data structure. While specific corporate training might not be any better at improving this than self help, a training course could be structured well enough to stress on idiomatic concepts that they might never find out by reading certain books or looking at certain sites. Also, while I do advocate self-help, I honestly believe that a sense of curiosity is than the sources you learn from. Jayanth ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Good Python training in blr
On Tue, Jun 16, 2009 at 11:02 AM, jayasimha makineni jayasimha.makin...@gmail.com wrote: Let us train more programmers who can truly be *programmers*. Python is How do you make that decision ? Is there an objective set of criterion ? perhaps the best vehicle for that journey. My understanding is that those who Advocacy isn't the subject matter, I believe ! :-) There is a best tool for every job, and very rarely, one best tool for every job !! snip And their managers have an even worse feeling to face facts because they have to justify their salaries and other bills too. First thing is for the managers to justify their own salaries. IMHO, talking of lacunae, we are riddled with a defunct hierarchy of managers who switched tracks because they could no longer keep up with the productivity and smartness of younger, smarter and more agile bunch of engineers !! of course, that is generalisation streched too far... but i doubt, too detached from reality. -- regards, Banibrata http://www.linkedin.com/in/bdutta ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] which is better solution of the question
On Tue, Jun 16, 2009 at 10:42 AM, Pradeep Gowdaprad...@btbytes.com wrote: On Tue, Jun 16, 2009 at 9:52 AM, Abhishek Tiwaritiwariabhishe...@gmail.com wrote: I would like to know which method is better and why? Better for what purpose? 1. speed of execution? 2. elegance? The list comprehension solution is slightly more approachable (many are not familiar with the zip() function. I don't use zip on the first go, if at all.) The zip solution is succinct. Also, by the virtue of being a built-in function zip() should be faster than the second approach. I wrote a script to test this hypothesis : http://dpaste.com/55994/ The zip() version is 100 times faster on average than the other solution. # avg time taken for ans1 : 0.0035585308075 # avg time taken for ans2 : 0.306885209084 (averaged over 50 runs) +PG ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] which is better solution of the question
The zip solution is succinct. Also, by the virtue of being a built-in function zip() should be faster than the second approach. Complexity of first solution is O(n) and complexity of second solution is O(n^2) because it using values.index function, which is O(n). ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] which is better solution of the question
On Tue, Jun 16, 2009 at 12:55:28PM -0400, Pradeep Gowda wrote: I wrote a script to test this hypothesis : http://dpaste.com/55994/ The zip() version is 100 times faster on average than the other solution. Pradeep: Here is a surprise: http://dpaste.com/hold/56023/ I know about the timeit module. Was too lazy to look up the docs. The surprise was in the results obtained. -- Senthil ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] How to create Debug and Release code in Python
I had come across two separate modules that did something on the same lines.one is 'pypp' and the other is 'preprocess.py' from ActiveState. in the former, if the file contains a comment '#pypp somewhere in the file...it gets preprocessedbut it only uses MakoTemplates for preprocessing..and so you need to have Mako on your machine. the later, preprocess.py is a script that looks for specific tagged comments like #ifdef, #ifndef etc and creates another file...after preprocessing. A marriage between the two seems to be this Imputil thing from Paul McGuire :)) One of the things that needs to be done...is, if a upper layer import is working like this: # topMod.py --- import something.onething as one import something.anotherthing as another And 'onething.py' and 'anotherthing.py' contain the preprocessor directives...the new file that gets made and is loadedshould now be loaded with their respective module names(i.e. 'one' and 'another'). Need to do something for this Python is certainly...cool. Enjoy, Vishal On Wed, Jun 17, 2009 at 1:29 AM, Vishal vsapr...@gmail.com wrote: CoolWhile I was using preprocessor directives in C/C++...the usual internet rant I've always heard, is preprocessor is bad, using preprocessor is bad habit.. Somehow I feel that preprocessing is not all that bad. It can and does solve important problems. May be these rants mostly referred to the 'macro' side of things... Thanks a lot Jeff, this was really informative. Vishal On Tue, Jun 16, 2009 at 11:57 AM, Jeff Rush j...@taupro.com wrote: Vishal wrote: *Is there a way to create a conditionally compilable Python script ?* Some facility that would prevent from code getting compiled into .pycsomething like the old #ifdef #endif preprocessor directivesis there a Python preprocessory available :) I've given this more thought. In the April 2009 issue of Python Magazine is a wonderful article by Paul McGuire on writing Domain Specific Languages. It shows how to intercept the import of specific types of files to preprocess the source before compiling it into bytecode. I played with those ideas to see what could be done for your case. So say you had a module marked up with special commenting like: --- cut here --- abc.pyp def main(): print Hello #? DEBUG print There #? DEBUG2 print World --- cut here --- abc.pyp Then in your main module you could do the following: --- cut here --- demo.py import cond_importer # can put in site.py for global application import abc abc.main() --- cut here --- demo.py Now you run the program normally and get: $ python2.5 demo.py Hello There World or you can filter out lines using: $ EXCLUDES=DEBUG python2.5 demo.py There World or even: $ EXCLUDES=DEBUG:DEBUG2 python2.5 demo.py World The magic to make this happen is just: --- cut here --- cond_import.py from __future__ import with_statement # for Python 2.6 import os import imputil import re patt = re.compile(r.*#\? (?Ptag[_a-zA-Z][_a-zA-Z0-9]*)$) try: # construct a set of tags to exclude in .py source pyexcludes = frozenset(os.environ['EXCLUDES'].split(':')) except Exception: pyexcludes = frozenset() def preprocess_source(filepath, fileinfo, filename): src = [] with file(filepath, 'r') as f: for line in f: m = patt.match(line) if m is None or m.group('tag') not in pyexcludes: src.append(line) src = '\n'.join(src) codeobj = compile(src, filepath, 'exec') # create return tuple: # import flag (0=module, 1=package) # code object # dictionary of variable definitions return 0, codeobj, {} importer = imputil.ImportManager() importer.add_suffix('.pyp', preprocess_source) importer.install() --- cut here --- cond_import.py I arbitrarily chose a file extension of .pyp for files to preprocess but you could use anything. And the tags to exclude could instead be tags to include. For handling packages (dirs) instead of modules you'd have to add a test for file or directory and change the code a bit. Anyway it raises some interesting possibilities of preprocessing. Python is just so cool. -Jeff ___ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers -- Thanks and best regards, Vishal Sapre --- So say...Day by day, in every way, I am getting better, better and better !!! A Strong and Positive attitude creates more miracles than anything else. Because...Life is 10% how you make it, and 90% how you take it Diamond is another piece of coal that did well under pressure” Happiness keeps u Sweet, Trials keep u Strong, Sorrow keeps u Human, Failure Keeps u Humble, Success keeps u Glowing, But only God Keeps u Going.Keep Going. -- Thanks and best regards, Vishal Sapre --- So say...Day by day, in every way, I