load_module for loading packages
Hi, If I use load_module for loading module, I can instantiate classes, defined in that module. Is it possible to do the same, if load not a module, but package? Python documentation for load_module contains description, that load_module can load a package. But I can not find examples, how to work with result of load_module, used for loading a package. Regards, Sergey -- https://mail.python.org/mailman/listinfo/python-list
Using Python inside Programming Without Coding Technology (PWCT) environment.
Hello Article : Using Python inside Programming Without Coding Technology (PWCT) environment. http://www.codeproject.com/Articles/693408/Using-Python-inside-Programming-Without-Coding-Tec In this article you will find information about using Python in the PWCT Visual Programming Environment Programming Without Coding Technology is a free open source general purpose visual programming system. Inside PWCT we can create programs using visual programming without typing text based source code. This seems to be an attractive feature for novice programmers, but PWCT is designed to take in mind some of the expert programmer needs (Productivity and Customization). When we create applications using PWCT we can see/edit the generated source code (optional). PWCT system contains more than one visual programming language (HarbourPWCT, PythonPWCT, C#PWCT, SupernovaPWCT CPWCT). from the name of the visual language we can guess the text based language that are used in the code generation process. PythonPWCT is a visual programming language that generate the source code in the Python programming language. As any programming tool you need to try PWCT then decide for yourself if it is useful or not. I hope that some Python programmers will find that PythonPWCT is useful for them and they will like this article as an introduction to PythonPWCT. Any suggestions/Ideas are welcome Greetings, Mahmoud -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman et...@stoneleaf.us wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS. One of the (many) nice things about Python is one doesn't need to know that stuff to Get Things Done. You don't need to know how to use the brakes to drive to Wal-Mart, either. Get Things Done is not the one and only goal. It ignores productivity, correctness, ethics... It isn't a bad thing to learn things that are unnecessary to get the bare minimum accomplished. -- Devin -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman et...@stoneleaf.us wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS. One of the (many) nice things about Python is one doesn't need to know that stuff to Get Things Done. You don't need to know how to use the brakes to drive to Wal-Mart, either. Get Things Done is not the one and only goal. It ignores productivity, correctness, ethics... It isn't a bad thing to learn things that are unnecessary to get the bare minimum accomplished. When you tell a story, it's important to engage the reader from the start. Sometimes that means starting the story in the middle of the action, and filling in the important-but-less-exciting details later, when they mean something. [1] Teaching a skill often hits the same sorts of issues. Rather than explain This is how to manipulate registers in a CPU, explain This is how to print Hello World to the console and worry about what exactly the console is (and how redirection affects it) later. My tutorial on assembly language programming did the same, though it used a one-character-output operation so it printed a single asterisk to standard out. (Manually setting CPU register AX to 0200 and DX to 002A, placing an INT 21 command in memory, and single-stepping it.) Learning how all that functions - or even what the INT opcode means - came later. Start with something visible and engaging. After that, learn/teach as much background as is of interest, and improve skills. But start with something that gets something done. [1] http://tvtropes.org/pmwiki/pmwiki.php/Main/InMediasRes ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Differences between obj.attribute and getattr(obj, attribute)
Hi list, can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: Differences between obj.attribute and getattr(obj, attribute)
Hi. On 11.12.2013. 9:23, Johannes Schneider wrote: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? You can not use obj.attribute if you have the word 'attribute' as a string, e.g. if you read it from a configuration file. Also, you can not test whether an object has an attribute when using the object.attribute access method without raising/catching an exception and then it can be hard to make sure no other code caused the exception. But I suppose in most real-life cases both of the suggested access methods are equivalent, since most of the time you really do not have names of your attributes as strings and are free to simply assume the attribute exists. One example problem I had recently where I think you have to use getattr(): list the names of all global references in the __builtins__ module and, a the type of object each of those references points to. [Ran into this one by accident as a part of demonstrating to a new Python student what names Python recognizes in some module, and what names require additional imports.] Hope this helps. Best regards, Jurko Gospodnetić -- https://mail.python.org/mailman/listinfo/python-list
Re: Differences between obj.attribute and getattr(obj, attribute)
2013/12/11 Johannes Schneider johannes.schnei...@galileo-press.de: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? You use getattr when the attribute name comes from a string, rather than a literal. There's no advantage to it when you know ahead of time what attribute you're looking for. It's useful when you iterate over dir(), for instance: print(You can call...) n=0 for attr in dir(x): if callable(getattr(x,attr)): print(x.%s()%attr) n+=1 print(...,n, options.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Differences between obj.attribute and getattr(obj, attribute)
On Wed, Dec 11, 2013 at 8:30 PM, Jurko Gospodnetić jurko.gospodne...@pke.hr wrote: Also, you can not test whether an object has an attribute when using the object.attribute access method without raising/catching an exception and then it can be hard to make sure no other code caused the exception. It's pretty easy to make sure no other code caused the exception - just have no other code inside the try block. x.foo(input().split( )[4]) # Might throw from any point in the expression try: func = x.foo except AttributeError: deal_with_error func(..) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
A few practical considerations, far away from theoretical aspects. Mainly for non ascii, understand non native English speakers. Python is an ascii oriented product. Platform. On Windows, the solely version which works harmoniously with the system is Py 2.7 in a byte string mode (ie non unicode). Unicode. Sorry, but Python just becomes a no-go. The great strength is(are) the Python interactive interpreter(s). It makes learning this language a game. jmf (Not teaching computer stuff, but regulary confrontated with students and/or potential users). -- https://mail.python.org/mailman/listinfo/python-list
Re: python import error
On 11/12/2013 05:45, smilesonisa...@gmail.com wrote: On Wednesday, December 11, 2013 10:23:34 AM UTC+5:30, John Gordon wrote: In 93405ea9-6faf-4a09-9fd9-ed264e313...@googlegroups.com smilesonisa...@gmail.com writes: File aaa.py, line 5, in module from ccc.ddd import sss ImportError: No module named ccc.ddd directory structure as follows: ccc | ddd | aaa.py sss.py A python file isn't importable unless the directory also contains a file named __init__.py . Try making __init__.py files in the ccc and ddd directories. If you don't know what to put in them, just leave them blank. It is having __init__.py as blank in ccc and ddd directories. But it still doesnot work. -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. Have you actually written anything above? You also appear to be suffering from the highly contagious double spaced google disease. So would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Is there any advantage to using a main() in python scripts?
Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below) #!/usr/bin/python import sys def main(): # print command line arguments for arg in sys.argv[1:]: print arg if __name__ == __main__: main() -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 09:39, wxjmfa...@gmail.com wrote: A few practical considerations, far away from theoretical aspects. Mainly for non ascii, understand non native English speakers. Python is an ascii oriented product. Sheer unadulterated rubbish. Platform. On Windows, the solely version which works harmoniously with the system is Py 2.7 in a byte string mode (ie non unicode). Fixed in Python 3, especially with the superb work done on PEP 393 and the FSR. Unicode. Sorry, but Python just becomes a no-go. Yawn. The great strength is(are) the Python interactive interpreter(s). It makes learning this language a game. Blimey, got something correct, miracles do happen. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Differences between obj.attribute and getattr(obj, attribute)
thank you guys. On 11.12.2013 10:36, Chris Angelico wrote: 2013/12/11 Johannes Schneider johannes.schnei...@galileo-press.de: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? You use getattr when the attribute name comes from a string, rather than a literal. There's no advantage to it when you know ahead of time what attribute you're looking for. It's useful when you iterate over dir(), for instance: print(You can call...) n=0 for attr in dir(x): if callable(getattr(x,attr)): print(x.%s()%attr) n+=1 print(...,n, options.) ChrisA -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
JL lightai...@gmail.com writes: Python scripts can run without a main(). What is the advantage to using a main()? Modular code – that is, implementing the program functionality in small, well-defined units with narrow, strictly-defined interfaces – is good design. Practical benefits include being able to easily use the code as part of a larger program, and being able to easily unit-test all the program's code. Is it necessary to use a main() when the script uses command line arguments? (See script below) #!/usr/bin/python import sys def main(): # print command line arguments for arg in sys.argv[1:]: print arg if __name__ == __main__: main() Better design is to make the argument list a parameter to the ‘main’ function; this allows constructing an argument list specially for calling that function, without ‘main’ needing to know the difference. You'll also want to catch SystemExit and return that as the ‘main’ function's return value, to make it easier to use as a function when that's needed. def main(argv=None): if argv is None: argv = sys.argv exit_code = 0 try: command_name = argv[0] config = parse_command_args(argv[1:]) do_whatever_this_program_does(config) except SystemExit, exc: exit_code = exc.code return exit_code if __name__ == __main__: import sys exit_code = main(sys.argv) sys.exit(exit_code) That way, the normal behaviour is to use the ‘sys.argv’ list and to raise SystemExit (via ‘sys.exit’) to exit the program. But ‘main’ itself can, without any further changes, be called as a function that receives the command line as a parameter, and returns the exit code. -- \ “Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.” —Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble with Multi-threading
On Tue, 10 Dec 2013 17:57:50 +, Walter Hurry wrote: On Tue, 10 Dec 2013 11:21:32 -0500, dan.rose wrote: PLEASE NOTE: The preceding information may be confidential or privileged. It only should be used or disseminated for the purpose of conducting business with Parker. If you are not an intended recipient, please notify the sender by replying to this message and then delete the information from your system. Thank you for your cooperation. Regretfully I am unable to delete the message from my Usenet provider's servers. However, in accordance with your request I have expunged the body of your request so as to avoid disseminating it. When did this forum become so intolerant of even the tiniest, most minor breaches of old-school tech etiquette? Have we really got nothing better to do than to go on the war path over such trivial issues? Out of five responses to the Original Poster's email, there was *one* helpful reply, followed by no fewer than four people playing Stacks on the n00b making the same comment about being unable to delete the message. I'm sure all four of you think you are ever such wits, but you're only half right. Walter, you and I both know that such legal disclaimers are pointless and unenforceable. But you are guilty of misrepresenting what it says, and hence make yourself out to be a Grade A Dick. The disclaimer does not say Everybody who receives this message must delete it from servers they don't control. That truly would display galactic-level stupidity. But it doesn't say that. As a subscriber to the mailing list and/or newsgroup which Dan's message was sent to, you *are* an intended recipient. The disclaimer says that those who are *not* intended recipients should delete it from THEIR systems, not that those who *are* intended recipients should delete it from systems belonging to OTHERS. Duh. As programmers, we should be able to correctly interpret the boolean logic in the disclaimer. Surely you know how to read, and interpret, a set of plain English functional requirements? - It doesn't say that the message is confidential, it says it *may* be, which is a correct statement regardless of the actual confidentially of the message. - It doesn't demand that the message must be used only for certain purposes, but only that it *should* be so used -- again, a statement of intention which is correct. - Lastly, it doesn't pretend to be able to compel the recipient into any particular action, but merely *requests* that they not be a dick about confidential or privileged emails which they receive by mistake. And even thanks them in advance for their (presumed) cooperation. We shouldn't be giving a newcomer to this group a hard time over something which (1) he has little control over, (2) which isn't actually factually incorrect in any way, and (3) in the grand scheme of things isn't that bad a breach of etiquette. I'm really getting cheesed off at the intolerance and nastiness being displayed on this list. I'm not aiming this specifically at you, Walter, you're not even close to one of the worst culprits. This isn't comp.lang.c, if you want a forum for arrogant elitists who look for any petty excuse to bash newcomers, take it elsewhere. I've been a regular here for over seven years, possibly longer, and the level of unpleasantness is at an all-time high, and the level of usefulness is lower than I've ever seen it before. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
On Wed, Dec 11, 2013 at 9:26 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: except SystemExit, exc: For new code, you'd of course want to write that as: except SystemExit as exc: which is compatible with Python 2.6, 2.7, and 3.x, while the other syntax is 2.x only. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wed, Dec 11, 2013 at 7:43 PM, Chris Angelico ros...@gmail.com wrote: When you tell a story, it's important to engage the reader from the start. On Wed, Dec 11, 2013 at 8:39 PM, wxjmfa...@gmail.com wrote: A few practical considerations, far away from theoretical aspects. Mainly for non ascii, understand non native English speakers. And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble with Multi-threading
On Tue, 10 Dec 2013 11:21:32 -0500, dan.rose wrote: I am running PYTHON 2.7.3 and executing a PYTHON program that uses multi-threading. I am running this on a 64-bit Windows 2008 R2 server (Service Pack 1). Hi Dan, and despite the emails from a few others, welcome. My further comments below, interleaved with your questions. Three months ago, I was able to execute this program just fine. I ran the program and opened Task Manager and verified that the program successfully obtained all of the multiple threads it requested. Sounds great, but unfortunately you don't actually show us the program, so there's very little we can say about it. If possible, please show us the actual program. If not, please try to show us a simplified version which still displays the fault. If you can't do that, at least tell us what result you expect, and what result you actually get. Are you sure you're talking about multi-threading? Do you perhaps mean multi-processing? I'm not a Windows user, but I would expect that only independent processes show up in Task Manager, not threads within a single process. Now, when I go to run this same program (no changes to the program), I am getting this message: If nothing has changed with the program, it's unlikely that the behaviour will have changed. Since the behaviour has changed, something must be different. If not in the program itself, perhaps something in it's environment. Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 Type copyright, credits or license() for more information. RESTART multiprocessing.queues.Queue object at 0x042309E8 How are you running the program? If you are using IDLE, the first step when you run into problems is to *not* use IDLE. Instead of running the program through the interactive IDLE environment, I recommend you try running it directly in Python via the command line and see if the error persists. Do you know how to do this or do you need help? Lastly, Dan, if you don't mind I'd like to make a couple of requests. This forum is both an email mailing list and a text-only Usenet news group, were so-called Rich Text (actually HTML) emails are frowned upon. If you don't mind, please disable Rich Text when sending messages to this group, as many people get annoyed having to deal with posts like yours that include content like: brfont size=2 face=sans-serif Also, if there's any way to drop the legal disclaimer when sending here, that too would be appreciated. Thanks for your cooperation, and feel free to ask any further questions, hopefully you'll get a few more useful responses next time. Regards, -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wed, 11 Dec 2013 19:43:52 +1100, Chris Angelico wrote: [1] http://tvtropes.org/pmwiki/pmwiki.php/Main/InMediasRes TV Tropes? You utter, utter bastard. Must... resist... call... of... TV Tropes... -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 11:45, Chris Angelico wrote: And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! ChrisA Oi! You!! I'll have you know I'm a bona fide Knight of the Temple and we're not (all) villains! If I catch you calling us villains again, I'll slide up behind you in the mud and dig you with my ceremonial sword! ;-) SteveS -- https://mail.python.org/mailman/listinfo/python-list
mush 1.2 released! - Type-based dependency injection for scripts
Hi All, I'm very happy to announce the a new release of Mush, a light weight dependency injection framework aimed at enabling the easy testing and re-use of chunks of code that make up scripts. This release rounds out a some more rough edges after even more real world use: - The 'nothing' singleton is now used instead of None for marking return types, fixing a bug that occurred when a callable tried to type-map a result that was None. - Add an after() type wrapper for callables that need to wait until after a resource is used but that can't accept that resource as a parameter. For a worked example of how to use Mush to reduce the copy'n'paste in your scripts, please see here: http://pythonhosted.org/mush/examples.html Full docs are here: http://pythonhosted.org/mush/ Downloads are here: https://pypi.python.org/pypi/mush Compatible with Python 2.6, 2.7, 3.2 and 3.3 on Linux, Mac OS X and Windows: http://jenkins.simplistix.co.uk/view/mush/ Any problems, please give me a shout on the simplis...@googlegroups.com list! cheers, Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble with Multi-threading
On 11/12/2013 11:37, Steven D'Aprano wrote: When did this forum become so intolerant of even the tiniest, most minor breaches of old-school tech etiquette? [... Giant Snip...] Well said Steven. I've only been member of this list for (maybe) a year, mainly lurking to learn about Python and I also feel that the balance between quality answers and sniping/arguing has definitely tilted in the wrong direction. I'd very much like to see the original mood restored. SteveS -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would take a lot of time. In which way would you prefer to store the data, and which functions or methods would you use effectively to accomplish this task ? I deeply apologize of not defining the question more defined. English is not my mother tongue. I'll do my best next time. Thanks Tamer On 11.12.2013 06:47, Dave Angel wrote: On Wed, 11 Dec 2013 02:02:20 +0200, Tamer Higazi tamerito...@arcor.de wrote: Is there a way to get dict by search terms without iterating the entire dictionary ?! I want to grab the dict's key and values started with 'Ar'... Your wording is so ambiguous that each respondent has guessed differently. I'm guessing that you want all key/value pairs for which the key begins with the two letters 'Ar' I'm guessing further that your objection to iterating the entire dictionary is not code size but performance. If both assumptions are valid then I'll point out that a dict has no ordering to it. If you want an approach that doesn't iterate over the entire structure you'll need to store the data differently. For example if you stored all the keys in a sorted list you could use bisect. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11 December 2013 08:43, Chris Angelico ros...@gmail.com wrote: On Wed, Dec 11, 2013 at 7:34 PM, Devin Jeanpierre jeanpierr...@gmail.com wrote: When you tell a story, it's important to engage the reader from the start. Sometimes that means starting the story in the middle of the action, and filling in the important-but-less-exciting details later, when they mean something. [1] Teaching a skill often hits the same sorts of issues. Rather than explain This is how to manipulate registers in a CPU, explain This is how to print Hello World to the console and worry about what exactly the console is (and how redirection affects it) later. My tutorial on assembly language programming did the same, though it used a one-character-output operation so it printed a single asterisk to standard out. (Manually setting CPU register AX to 0200 and DX to 002A, placing an INT 21 command in memory, and single-stepping it.) Learning how all that functions - or even what the INT opcode means - came later. Start with something visible and engaging. After that, learn/teach as much background as is of interest, and improve skills. But start with something that gets something done. I certainly agree with this for our students. Explicit computing courses make up about 30 credits (~16%) of the whole degree program for the Engineering Mathematics students (if they don't take additional optional units). They are however many units that implicitly require computing skills, so we really need them to be able to be productive quickly. Some of them will focus on programming and get really good at it. Some do go on to become programmers but most do not. The Electrical Engineering students will subsequently do low-level programming with registers etc. but at the earliest stage we just want them to think about how algorithms and programs work before going into all the hardware specific details. While reading around this subject I found this interesting (although verbose) speech from Dijkstra advocating the opposite point of view: http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html This definitely wouldn't work for my students but a friend of mine studied CS (at Warwick?) and his course worked as Dijkstra describes. In the first year they don't touch a real programming language or write any actual programs. They take exams in pseudocode and formal proofs of correctness. Then after a year of studying algorithms, linguistics, semantics, proof, mathematics and so on they write their first hello world program in a real programming language. I don't really know whether he's any good at programming but he's certainly a good mathematician. Oscar -- https://mail.python.org/mailman/listinfo/python-list
Script Request
Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Thank You -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wed, Dec 11, 2013 at 10:33 PM, Steve Simmons square.st...@gmail.com wrote: On 11/12/2013 11:45, Chris Angelico wrote: And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! ChrisA Oi! You!! I'll have you know I'm a bona fide Knight of the Temple and we're not (all) villains! If I catch you calling us villains again, I'll slide up behind you in the mud and dig you with my ceremonial sword! ;-) Mister Simmons, Mister Simmons! We are not for one moment doubting your sincerity. It's just your intelligence that's in question. [1] [1] http://www.thegoonshow.net/scripts_show.asp?title=s06e19_the_jet_propelled_guided_naafi ChrisA Attempting to atone for pointing people to TVTropes... or maybe to be hung for a sheep rather than a lamb -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Tue, Dec 10, 2013 at 9:16 PM, Denis McMahon denismfmcma...@gmail.com wrote: On Tue, 10 Dec 2013 20:35:47 -0500, Dennis Lee Bieber wrote: On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing greg.ew...@canterbury.ac.nz declaimed the following: That's like saying that when teaching woodwork we shouldn't let people use hammers, we should make them use rocks to bang nails in, because it will make them better carpenters in the long run. NAILS Nails were verboten in my high school wood working class... We used dowels and glue; chisels to carve dove-tails; etc. We were allowed to use screws, but they had to be brass, not steel, we had to drill appropriate clearance and pilot holes, and countersink where appropriate. O we used to DREAM of using screws! We were given steel shafts and had to tap the threads into them with our teeth. -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
Tamer Higazi wrote: Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would take a lot of time. In which way would you prefer to store the data, and which functions or methods would you use effectively to accomplish this task ? Well, Dave already gave one approach: [Dave Angel] For example if you stored all the keys in a sorted list you could use bisect. See also http://docs.python.org/dev/library/bisect.html Another option would be to use a database. Assuming the table 'lookup' has two columns 'key' and 'value' you'd get the matching rows with select key, value from lookup where key like 'Aa%'; A lightweight database that comes with Python is sqlite: http://docs.python.org/dev/library/sqlite3.html http://www.sqlite.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Script Request
On Wed, Dec 11, 2013 at 6:53 AM, Jeff James j...@jeffljames.com wrote: Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Thank You import urllib sites = [http://www.amazon.com/;, http://nowhere.com;] for site in sites: try: urllib.urlopen(site) print site + is up except Exception, e: print site + is down -- https://mail.python.org/mailman/listinfo/python-list
please guide to make proxy type function in python
please guide to make proxy type function in python -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 13:02, Chris Angelico wrote: On Wed, Dec 11, 2013 at 10:33 PM, Steve Simmons square.st...@gmail.com wrote: On 11/12/2013 11:45, Chris Angelico wrote: And then, shortly after the beginning of the story, you need to introduce the villain. Thanks, jmf, for taking that position in our role-play storytelling scenario! A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! ChrisA Oi! You!! I'll have you know I'm a bona fide Knight of the Temple and we're not (all) villains! If I catch you calling us villains again, I'll slide up behind you in the mud and dig you with my ceremonial sword! ;-) Mister Simmons, Mister Simmons! We are not for one moment doubting your sincerity. It's just your intelligence that's in question. [1] [1] http://www.thegoonshow.net/scripts_show.asp?title=s06e19_the_jet_propelled_guided_naafi ChrisA Attempting to atone for pointing people to TVTropes... or maybe to be hung for a sheep rather than a lamb OK, We'll call it a draw. [2 - or is that 1?] SteveS [2 - or is that 3? Three shall be the number...] http://montypython.50webs.com/scripts/Holy_Grail/Scene4.htm -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wed, Dec 11, 2013 at 10:46 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: This definitely wouldn't work for my students but a friend of mine studied CS (at Warwick?) and his course worked as Dijkstra describes. In the first year they don't touch a real programming language or write any actual programs. They take exams in pseudocode and formal proofs of correctness. Then after a year of studying algorithms, linguistics, semantics, proof, mathematics and so on they write their first hello world program in a real programming language. I don't really know whether he's any good at programming but he's certainly a good mathematician. Yeah, that's how that sounds. If programming is, to your students, a tool for mathematical analysis (if code is a kind of super-algebra), then it's right to take eams in pseudocode and study algorithms before writing hello world. But if programming is a means of gaining command of a computer, it's far better to see some results of that. Some people like the idea of creating games (usually because they've played so many), so there are courses around that take you from knowing nothing about code to creating your first game (often in one of those systems that lets you build an application without writing code, though, in which case it's not really teaching programming at all). Personally, I'd rather focus on something that's universal[1] (the console and Hello, world!), but I do see the appeal of And by the end of the course, you'll have created a playable game!. Early in my computing days, I met REXX, and a program called REXXTry. It provided a basic Read/Eval/Print loop, though the Print part wasn't very sophisticated (though since REXX didn't have much in the way of complex types, all that meant was that the display of long strings was a bit ugly). I ended up creating an Extended REXXTry, partly by adding a sophisticated input routine courtesy of REXXTT, and then by adding a pile of custom functions - with the goal of making it the ultimate in algebraic handlers. It was, in fact, quite a reasonable tool for playing around with maths; I could sketch a geometric problem on paper, figure out what I knew and what I needed to know, key stuff into EREXXTry, and get a result back. Python could do exactly the same, only way way better (already has support for fractions and complex numbers, which REXX doesn't), and that would make a fine introduction to programming... for someone with a background in algebra. Different styles for different origins. ChrisA [1] Or nearly so. Ironically, many of the systems that don't have a console available are called consoles. voice imitate=Jubal EarlyDoes that seem right to you?/voice -- https://mail.python.org/mailman/listinfo/python-list
Figuring out what dependencies are needed
I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X. Now I'd like to use the backtesting package from zipline (zipline.io), but while running the test script in iPython, I receive the following error: AssertionErrorTraceback (most recent call last) ipython-input-6-f921351f78e2 in module() 1 data = load_from_yahoo() 2 dma = DualMovingAverage() 3 results = dma.run(data) 1) I assume that I'm missing some packages that aren't included in Anaconda, but how do I know which ones to upload? 2) Often I'll just unzip a library file and put the main folder in the iPython folder, but I notice there's usually a setup.py file in the main library folder. I've been ignoring this. Should I be using it? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
I would agree with the previous post but also add that I've stopped calling the main function main() and usually give it a more descriptive name, such as bake_cookies() or whatever. I think that that makes it clearer what it's doing when used as a library and the 'if __name__ == '__main__' already implies that it is the main script function. -- https://mail.python.org/mailman/listinfo/python-list
Re: Script Request
On Wed, 11 Dec 2013 04:53:41 -0700, Jeff James wrote: Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Don't reinvent the wheel, use a tool already designed for this task, such as Nagios. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
Hi Peter! I got the message I know that I could have used a database. I am using for a good reason the ZODB Database. I am making things in the ZODB Database persistent, I don't like to distribute among machines. Making use of sqlite, won't give me the possibility to scale as the amount of data and requests are high. I am thinking of scalability. Of course I could use the MongoDB as well. But this is from my side for THESE KIND of things not desired. I am thinking of making Files through objects in the ZODB Database persistent, and relational databases on long time make me sick I will workout a bselect sollution for my problem! Thanks for your support. Tamer On 11.12.2013 14:10, Peter Otten wrote: Tamer Higazi wrote: Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would take a lot of time. In which way would you prefer to store the data, and which functions or methods would you use effectively to accomplish this task ? Well, Dave already gave one approach: [Dave Angel] For example if you stored all the keys in a sorted list you could use bisect. See also http://docs.python.org/dev/library/bisect.html Another option would be to use a database. Assuming the table 'lookup' has two columns 'key' and 'value' you'd get the matching rows with select key, value from lookup where key like 'Aa%'; A lightweight database that comes with Python is sqlite: http://docs.python.org/dev/library/sqlite3.html http://www.sqlite.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: please guide to make proxy type function in python
On 11/12/2013 12:28, Jai wrote: please guide to make proxy type function in python Write some code after looking at the documentation http://docs.python.org/3/. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Figuring out what dependencies are needed
On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: Now I'd like to use the backtesting package from zipline (zipline.io), .io is not normally a file extension for Python files. Are you sure that's Python code? but while running the test script in iPython, I receive the following error: AssertionErrorTraceback (most recent call last) ipython-input-6-f921351f78e2 in module() 1 data = load_from_yahoo() 2 dma = DualMovingAverage() 3 results = dma.run(data) I think you may be missing one or more lines? Perhaps something like AssertionError: blah blah blah appearing after that? For those unfamiliar with iPython, rather than a standard Traceback, that appears to suggest that dma.run(data) is raising AssertionError, but we can't see what (if any) error message is given by that assert, or how it fails. Can you explain what precise command you are running? Please copy and paste the exact command line you used that gives that error. Also, whenever you get unexpected errors while running from an IDE or non- standard environment like IDLE or iPython, your first step should be to run the same script from the command line using the vanilla Python interpreter and see if the error goes away. Do you need assistance with doing that? Feel free to ask for additional instructions. 1) I assume that I'm missing some packages that aren't included in Anaconda, but how do I know which ones to upload? Why do you make that assumption? I would expect missing packages to give an ImportError, not an AssertionError. 2) Often I'll just unzip a library file and put the main folder in the iPython folder, but I notice there's usually a setup.py file in the main library folder. I've been ignoring this. Should I be using it? Absolutely! You'll probably see a READ ME file in the unzipped folder, you should read that for instructions. It may be that sometimes the setup.py file will do nothing more than copy the main folder into your site-packages folder, but it may do a lot more. Also, if you just dump random packages into iPython's private library area, you may even break iPython. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Figuring out what dependencies are needed
On 11/12/2013 12:44, s...@nearlocal.com wrote: I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X. Now I'd like to use the backtesting package from zipline (zipline.io), but while running the test script in iPython, I receive the following error: AssertionErrorTraceback (most recent call last) ipython-input-6-f921351f78e2 in module() 1 data = load_from_yahoo() 2 dma = DualMovingAverage() 3 results = dma.run(data) 1) I assume that I'm missing some packages that aren't included in Anaconda, but how do I know which ones to upload? 2) Often I'll just unzip a library file and put the main folder in the iPython folder, but I notice there's usually a setup.py file in the main library folder. I've been ignoring this. Should I be using it? Thanks https://pypi.python.org/pypi/z3c.dependencychecker and probably others. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
Reordering to un-top-post. On 11.12.2013 06:47, Dave Angel wrote: On Wed, 11 Dec 2013 02:02:20 +0200, Tamer Higazi wrote: Is there a way to get dict by search terms without iterating the entire dictionary ?! I want to grab the dict's key and values started with 'Ar'... Your wording is so ambiguous that each respondent has guessed differently. I'm guessing that you want all key/value pairs for which the key begins with the two letters 'Ar' I'm guessing further that your objection to iterating the entire dictionary is not code size but performance. If both assumptions are valid then I'll point out that a dict has no ordering to it. If you want an approach that doesn't iterate over the entire structure you'll need to store the data differently. For example if you stored all the keys in a sorted list you could use bisect. On Wednesday, December 11, 2013 3:37:08 PM UTC+5:30, Tamer Higazi wrote: Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would take a lot of time. In which way would you prefer to store the data, and which functions or methods would you use effectively to accomplish this task ? The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I deeply apologize of not defining the question more defined. English is not my mother tongue. I'll do my best next time. English no issue. But better not to top-post http://en.wikipedia.org/wiki/Posting_style#Top-posting -- https://mail.python.org/mailman/listinfo/python-list
Re: Figuring out what dependencies are needed
On 2013-12-11 13:27, Steven D'Aprano wrote: On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: Now I'd like to use the backtesting package from zipline (zipline.io), .io is not normally a file extension for Python files. Are you sure that's Python code? That's a package name, not a filename. but while running the test script in iPython, I receive the following error: AssertionErrorTraceback (most recent call last) ipython-input-6-f921351f78e2 in module() 1 data = load_from_yahoo() 2 dma = DualMovingAverage() 3 results = dma.run(data) I think you may be missing one or more lines? Perhaps something like AssertionError: blah blah blah appearing after that? For those unfamiliar with iPython, rather than a standard Traceback, that appears to suggest that dma.run(data) is raising AssertionError, but we can't see what (if any) error message is given by that assert, or how it fails. No, the arrow points to the active line in that frame of the traceback. Unfortunately, the OP cut off the remaining frames under `load_from_yahoo()` actually has the assert that is failing. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On Wed, 11 Dec 2013 12:07:08 +0200, Tamer Higazi wrote: Hi Dave! You were absolutely right. I don't want to iterate the entire dict to get me the key/values Let us say this dict would have 20.000 entries, but I want only those with Aa to be grabed. Those starting with these 2 letters would be only 5 or 6 then it would take a lot of time. What do you mean by a lot of time? Here is a small test. I set up a dict with 456976 keys, and then iterate over them in just over a quarter of a second on my (old, slow) computer. Here is the code I use: data = {} letters = abcdefghijklmnopqrstuvwxyz for a in letters.upper(): for b in letters: for c in letters: for d in letters: key = a + b + c + d data[key] = None print(len(data)) count = 0 with Timer(): for key in data: if key.startswith(Aa): count += 1 print(Found %d keys starting with 'Aa') The Timer() function is not standard to Python, but you can find it here: http://code.activestate.com/recipes/577896 Are you sure that just using a normal dict will be too slow? In which way would you prefer to store the data, and which functions or methods would you use effectively to accomplish this task ? I would use a dict, and iterate over the keys, until such time that I new that iterating was the bottle-neck causing my code to be too slow. Until I knew that absolutely for sure, I would not optimize. If necessary, I would consider having 26 dicts, one for each initial letter: data = {} for c in ABCDEFGHIJKLMNOPQRSTUVWXYZ: data[c] = {} then store keys in the particular dict. That way, if I wanted keys starting with Aa, I would only search the A dict, not the B dict, C dict, etc. key = Aardvark data[key[0]][key] = some value -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Programming puzzle with boolean circuits
On 09.12.2013 14:25, Chris Angelico wrote: I found this puzzle again and was thinking about: How would I code a brute-force approach to this problem in Python? Ooooh interesting! Ha, I thought so too :-) Well, here's a start: There's no value in combining the same value in an AND or an OR, ergo every gate you add must bring together two different values. To start with, you have three values (the three inputs). Every time you combine two of them, with either type of gate, you create a new value. You can also combine a single value with a NOT to create its inverse, but only if you have done so no more than once. The goal is to produce something which is provably the opposite of each of the three inputs. I'm not sure if this helps or not, but one thing I learned from geometry is that setting down everything you know and need to know is a good basis for the search! Absolutely. The hardest part, so far, is proving a result. The algorithm that's coming to mind is this: def find_solution(inputs, not_count): # TODO: First, see if inputs contains three values that are the inverses of # the three values i1,i2,i3. If they are, throw something, that's probably # the easiest way to unwind the stack. if not_count 2: for val in inputs: find_solution(inputs + [not val], not_count + 1) for val1 in inputs: for val2 in inputs: if val1 is not val2: find_solution(inputs + [val1 and val2], not_count) find_solution(inputs + [val1 or val2], not_count) find_solution([i1, i2, i3], 0) I understand your approach, it has given me some ideas too. Thanks for this! So, here's a crazy idea: Make i1, i2, i3 into objects of a type with an __eq__ that actually does the verification. Schrodinger's Objects: they might be True, might be False, and until you call __eq__, they're in both states. This probably isn't the best way, but I think it's the most fun! Haha, it surely is a very cool idea! Thanks for the ideas and your very cool approach. I'll try to tackle it myself (I think I have a good point to start) and will post the code once I'm finished. Best regards, Joe -- Wo hattest Du das Beben nochmal GENAU vorhergesagt? Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa hidbv3$om2$1...@speranza.aioe.org -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
In article 32615c9a-b983-4399-bb55-6df6c230f...@googlegroups.com, JL lightai...@gmail.com wrote: Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below) #!/usr/bin/python import sys def main(): # print command line arguments for arg in sys.argv[1:]: print arg if __name__ == __main__: main() No, it's not necessary, but it's a good idea. For one thing, it lets you import your script without actually running it. We recently tracked down a long-standing bug where some maintenance script we had started out with: import os os.environ['DJANGO_SETTINGS_MODULE'] = 'whatever' somebody imported that script in another part of the system because there was some convenient definition that he wanted to reuse. Unfortunately, the act of importing the script changed the environment! The fix was to move the setting of the environment variable to inside the main() routine. If you always follow the rule that you always put all your executable code inside main(), you'll never run into problems like that. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
In article mailman.3895.1386766655.18130.python-l...@python.org, mar...@letterboxes.org wrote: I would agree with the previous post but also add that I've stopped calling the main function main() and usually give it a more descriptive name, such as bake_cookies() or whatever. I think that that makes it clearer what it's doing when used as a library and the 'if __name__ == '__main__' already implies that it is the main script function. If you're writing a library that's meant to be imported by other scripts, then that makes sense. I tend to use main() for things that are done when your script is run as a stand-alone program. That usually involves things like parsing command-line arguments, and configuring logging, neither of which you'd want to do in an importable library. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
On Wednesday, December 11, 2013 7:47:34 PM UTC+5:30, Roy Smith wrote: JL wrote: Python scripts can run without a main(). What is the advantage to using a main()? Is it necessary to use a main() when the script uses command line arguments? (See script below) #!/usr/bin/python import sys def main(): # print command line arguments for arg in sys.argv[1:]: print arg if __name__ == __main__: main() No, it's not necessary, but it's a good idea. For one thing, it lets you import your script without actually running it. We recently tracked down a long-standing bug where some maintenance script we had started out with: import os os.environ['DJANGO_SETTINGS_MODULE'] = 'whatever' somebody imported that script in another part of the system because there was some convenient definition that he wanted to reuse. Unfortunately, the act of importing the script changed the environment! The fix was to move the setting of the environment variable to inside the main() routine. If you always follow the rule that you always put all your executable code inside main(), you'll never run into problems like that. I guess these are important but somewhat advanced considerations. For a beginner, its important to get that there is a bit of a pun here: The function habitually called 'main' may be called that or anything else It can have or not have an argument as Ben pointed out -- maybe more than one also. The module name __main__ is however sacrosanct and hardwired into python. The habit of connecting the one with the other is partly conventional and partly unavoidable -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On 2013-12-11 13:44, Steven D'Aprano wrote: If necessary, I would consider having 26 dicts, one for each initial letter: data = {} for c in ABCDEFGHIJKLMNOPQRSTUVWXYZ: data[c] = {} then store keys in the particular dict. That way, if I wanted keys starting with Aa, I would only search the A dict, not the B dict, C dict, etc. That's what the convoluted code does that I put at the end of my previous post in this thread, only to the Nth degree (the outermost dict has the first letter which links to a dictionary of the 2nd level/letter, to the 3rd level/letter, etc). -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wednesday, December 11, 2013 5:16:50 PM UTC+5:30, Oscar Benjamin wrote: The Electrical Engineering students will subsequently do low-level programming with registers etc. but at the earliest stage we just want them to think about how algorithms and programs work before going into all the hardware specific details. While reading around this subject I found this interesting (although verbose) speech from Dijkstra advocating the opposite point of view: http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html This definitely wouldn't work for my students but a friend of mine studied CS (at Warwick?) and his course worked as Dijkstra describes. In the first year they don't touch a real programming language or write any actual programs. They take exams in pseudocode and formal proofs of correctness. Then after a year of studying algorithms, linguistics, semantics, proof, mathematics and so on they write their first hello world program in a real programming language. I don't really know whether he's any good at programming but he's certainly a good mathematician. A government form -- say for filing income tax -- and poetry may both be in English but one doesn't read them with the same attitude! Dijkstra talks in so much hyperbole that one does not take him literally. In particular if you want to take him seriously, you must not take him literally. [I remember reading somewhere that in CS arrogance is measured in nano-dijkstras] I believe there is a truth in the line that Chris and Gene take of getting students' hands dirty early. Equally there is truth in Dijkstra's line that students need the habit of thinking and reflecting before diving in. Now if you believe that one is clearly more important than the other, your way is clear. However what if you want to balance both? Its a challenge... It is this need to balance that makes functional programming attractive: - implemented like any other programming language - but also mathematically rigorous No python is not strictly a functional language but it can be bent to seem that way more than C/C++/Java/what-have-you -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
In article 3efc283f-419d-41b6-ad20-c2901c3b9...@googlegroups.com, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree that a trie fits the problem description well. If I were coding this up in C or C++, that's probably the data structure I'd use, with each node containing an array of pointers to nodes, and the array indexed by the ascii value of the next character (this doesn't translate well to unicode). Lookup speed would be awesomely fast. The problem is, that doesn't make a whole lot of sense in Python. The cited implementation uses dicts at each level. By the time you've done that, you might as well just throw all the data into one big dict and use the full search string as the key. It would be a lot less code, and probably run faster. Still, as an exercise in learning about a useful (and under-appreciated) data structure, implementing this as a trie sounds like a wonderful idea. -- https://mail.python.org/mailman/listinfo/python-list
Re: load_module for import entire package
On Tue, 10 Dec 2013 23:28:31 -0800 (PST), Sergey sh0...@gmail.com wrote: def get_obj(): pkg = load_package_strict(tmp, basedir) from tmp import main return main.TTT() It is working, but if package code changes on disc at runtime and I call get_obj again, it returns instance of class, loaded for the first time previously. That's how import works. Once something has been imported, the module information is cached. There are three ways to defeat that, but they're all risky. How to replace line from tmp import main by getting properties of pkg? No clue what you mean by that. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 2013-12-11, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: That's like saying that when teaching woodwork we shouldn't let people use hammers, we should make them use rocks to bang nails in, because it will make them better carpenters in the long run. NAILS Nails were verboten in my high school wood working class... We used dowels and glue; chisels to carve dove-tails; etc. GLUE??? -- Grant Edwards grant.b.edwardsYow! When this load is at DONE I think I'll wash it gmail.comAGAIN ... -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On Wednesday, December 11, 2013 8:16:12 PM UTC+5:30, Roy Smith wrote: rusi wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree that a trie fits the problem description well. If I were coding this up in C or C++, that's probably the data structure I'd use, with each node containing an array of pointers to nodes, and the array indexed by the ascii value of the next character (this doesn't translate well to unicode). Lookup speed would be awesomely fast. The problem is, that doesn't make a whole lot of sense in Python. The cited implementation uses dicts at each level. By the time you've done that, you might as well just throw all the data into one big dict and use the full search string as the key. It would be a lot less code, and probably run faster. Still, as an exercise in learning about a useful (and under-appreciated) data structure, implementing this as a trie sounds like a wonderful idea. I was going to say that Steven's data = {} for c in ABCDEFGHIJKLMNOPQRSTUVWXYZ: data[c] = {} is really the first step of the trie approach except that instead of key = Aardvark data[key[0]][key] = some value he would need data[key[0]][key[1:] = some value The catch is keys of length 1 eg A Which makes the fully general (recursively unfolded) version easier to write, though with all those zillions of dicts probably not very efficient. Finitizing the trie into fixed small prefixes with leaves containing standard dicts looks sensible (to me without and testing of either efficiency or readability!) The short prefix problem however remains Of course there are other tricks possible: If we know that the data is case-insensitive alphabetic ASCII* we can just normalize the data with def norm(s): return [ord(c.upper()) -ord('A') for c in s] then norm(aBcD) [0, 1, 2, 3] and instead of dicts we can use 26-length lists * O me O my! Ive used the terrible A-word! Now RUN before the trolls get us! -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Thu, Dec 12, 2013 at 1:44 AM, rusi rustompm...@gmail.com wrote: It is this need to balance that makes functional programming attractive: - implemented like any other programming language - but also mathematically rigorous Attractive *to the mathematician*. A more imperative style makes sense to someone who's grown up with... well, parents... clean_room() eat_dinner() One won't start till the other finishes. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On 2013-12-11 09:46, Roy Smith wrote: The problem is, that doesn't make a whole lot of sense in Python. The cited implementation uses dicts at each level. By the time you've done that, you might as well just throw all the data into one big dict and use the full search string as the key. It would be a lot less code, and probably run faster. You're right if the search term is a whole word, a single dict-to-result works ideally. However, the OP asked about prefixes, so the Python implementation I provided uses a dict-of-nested-dicts which allows any arbitrary prefix, and then iterates over only the subset of those that match. If you need O(length-of-prefix) iteration of all results, I believe that's the best way algorithm to use (implementation details could differ for a more space-efficient structure perhaps; normalization might help reduce dict-entries). It's a specialized use-case, and doesn't have the O(1) lookup for exact-matches (that's just a special case of prefix=word with no sub-iteration, so would be O(length-of-search-word)). -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
On 12/11/2013 4:55 AM, JL wrote: What is the advantage to using a main()? In addition to what's been said I add: It separates all the global activities: defining of functions and classes, importing modules, etc. from the doing the actual task of the program. It also ensures that the defining all the classes and functions happens before referencing them (less bookkeeping for me). These two allow me to write the main program first, and follow it with all the global stuff. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wednesday, December 11, 2013 8:54:30 PM UTC+5:30, Chris Angelico wrote: On Thu, Dec 12, 2013 at 1:44 AM, rusi wrote: It is this need to balance that makes functional programming attractive: - implemented like any other programming language - but also mathematically rigorous Attractive *to the mathematician*. A more imperative style makes sense to someone who's grown up with... well, parents... clean_room() eat_dinner() One won't start till the other finishes. Yes its always like that: When you have to figure 2 (or 10) line programs its a no-brainer that the imperative style just works. When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is dependent on weird dependencies and combinatorial paths through the code you start wishing that - your only dependencies were data dependencies - Explicit is better than implicit dinned into the nut's head which BTW are the basic tenets of FP. We have functions in C, in Scheme and in Haskell. The difference is that - in C its impractical and unrealistic to have all functions as (mathematical) functions of the arguments - in Scheme its natural but not enforced - in Haskell its enforced The nice thing about python is that one can (kindof) teach it in the Scheme-like way before showing the C-like side. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 2013-12-11, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 10 Dec 2013 18:25:48 +1300, Gregory Ewing greg.ew...@canterbury.ac.nz declaimed the following: On Monday, December 9, 2013 5:53:41 PM UTC+5:30, Oscar Benjamin wrote: 5) Learning to program should be painful and we should expect the students to complain about it (someone actually said that!) but the pain makes them better programmers in the end. That's like saying that when teaching woodwork we shouldn't let people use hammers, we should make them use rocks to bang nails in, because it will make them better carpenters in the long run. NAILS Nails were verboten in my high school wood working class... We used dowels and glue; chisels to carve dove-tails; etc. ... You lucky BASTARD! We had to build bookcases out of banana leaves held together with our own spittle. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
On Thu, Dec 12, 2013 at 2:42 AM, bob gailer bgai...@gmail.com wrote: It also ensures that the defining all the classes and functions happens before referencing them (less bookkeeping for me). These two allow me to write the main program first, and follow it with all the global stuff. I prefer define-before-use for readability, even if it doesn't matter to the language. It means that locating the source of something can be found by going upward (or starting at the top and going down - first hit should be the definition), and helps keep things organized. Obviously it's not always possible (mutual recursion, for instance), but it's a general rule of thumb that I like to maintain. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 15:41, rusi wrote: When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is dependent on weird dependencies and combinatorial paths through the code you start wishing that ... he'd not been a Led Zeppelin fan, whereby every variable/module/function name was based on a song title/album name/lyric. Thankfully not on my project, it was a mate's. Code ended up in small, round filing cabinet. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 12/11/2013 3:43 AM, Chris Angelico wrote: When you tell a story, it's important to engage the reader from the start...explain This is how to print Hello World to the console and worry about what exactly the console is (and how redirection affects it) Highly agree. I was once given FORTRAN course materials and an assignment to teach this course. The first morning was spent on how to construct expressions! No context as to what a program was or what it might do or how to run it. As soon as that class was over I rewrote the materials so the first morning was how to write and run(batch job submission) a program that read a record, did a simple calculation and wrote the results. I certainly felt better about teaching this way. Asides: One student (PhD in Physics) looked at X = X + 1 and said no it doesn't. Another wrote his first program. I took one look at it and saw the mistakes. I explained how to walk thru the program step by step. He exclaimed In that much detail?. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Thu, Dec 12, 2013 at 2:41 AM, rusi rustompm...@gmail.com wrote: Yes its always like that: When you have to figure 2 (or 10) line programs its a no-brainer that the imperative style just works. When the ten becomes ten-thousand, written by a nut who's left you with code whose semantics is dependent on weird dependencies and combinatorial paths through the code you start wishing that - your only dependencies were data dependencies - Explicit is better than implicit dinned into the nut's head which BTW are the basic tenets of FP. And since teaching is seldom done with 10KLOC codebases, functional style can be left till later. I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. Start with something easy, then pick up something harder later. ESR in How to become a hacker [1] suggests learning Python, C/C++, Java, Perl, and LISP [2], and do take note of his reasons _why_. I'm not sure that Perl is so important any more (though a Unix sysadmin should probably have at least a working knowledge of it, given the likelihood of tripping over it at some point), and for LISP you might substitute some other functional language, but broadly, those five recommendations haven't changed in years and years. Knowing multiple styles lets you learn from all of them. Pure functional programming means the result of any function can be determined entirely from its arguments; that doesn't fit into everything, but it sure does make your code easier to understand when you (mostly) stick to it. (For instance, the current logging level might change whether a particular line does something or does nothing, but it still fundamentally has the same meaning, and it won't change state magically anywhere else.) And there's a lot of similarity of thinking between a well-written program in one style and a well-written program in another style, regardless of which two styles they are. ChrisA [1] http://www.catb.org/esr/faqs/hacker-howto.html [2] http://www.catb.org/esr/faqs/hacker-howto.html#skills1 -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On 11/12/2013 00:02, Tamer Higazi wrote: Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'} I want to grab the dict's key and values started with 'Ar'... I could make an iterator and look if it's inside. I wasn't able to find it, but I am asking myself if dict has a builtin method to get me these key/values on the fly. Why do I ask you?! I am working with the ZODB Database, where I make use of a PersistentDict and PersistentList, and I want I would thank you for a short reply. Tamer Plenty of answers already but this may be of interest http://stackoverflow.com/questions/2288901/best-data-structure-for-crossword-puzzle-search?lq=1 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 16:01, bob gailer wrote: One student (PhD in Physics) looked at X = X + 1 and said no it doesn't. Someone I worked with used x := x - x - x to invert a number. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Thu, Dec 12, 2013 at 3:01 AM, bob gailer bgai...@gmail.com wrote: One student (PhD in Physics) looked at X = X + 1 and said no it doesn't. Yeah, which is why some languages (I first met it with Pascal) spell that as X *becomes* X + 1... but regardless of what you call it, there's a fundamental difference between algebra (where every line is a statement of truth) and imperative programming (which may change state as time progresses). What's called a variable in programming really can vary; in maths, it's really just an unknown. This is a difference that, one way or another, just has to be taught. Another wrote his first program. I took one look at it and saw the mistakes. I explained how to walk thru the program step by step. He exclaimed In that much detail?. You mean a dry run [1]? Yes, can be tedious. Can also be very VERY valuable, especially if done verbally to another programmer, as a means of spotting differences between what the programmer thinks something does and what the language thinks it does. x = a * b + c Set x to a times the sum of b and c. ChrisA [1] http://foldoc.org/dry+run -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. I chuckle every time I read this one. Five years per language, ten languages, that's 50 years I think. Or do I rewrite my diary for next week, so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia Tuesday morning ... -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: python import error
In 58f7bd2a-ef82-4782-b4fb-db824f9c8...@googlegroups.com smilesonisa...@gmail.com writes: File aaa.py, line 5, in module from ccc.ddd import sss ImportError: No module named ccc.ddd directory structure as follows: ccc | ddd | aaa.py sss.py It is having __init__.py as blank in ccc and ddd directories. But it still doesnot work. What directory are you in when you run your python command? As written, your import will only work if you're in the parent directory of ccc (or that directory is in your PYTHONPATH.) -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. I chuckle every time I read this one. Five years per language, ten languages, that's 50 years I think. Or do I rewrite my diary for next week, so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia Tuesday morning ... Well, I went exploring the Wikipedia list of languages [1] one day, and found I had at least broad familiarity with about one in five. I'd like to get that up to one in four, if only because four's a power of two. More seriously: Once you've learned five of very different styles, it won't take you five years to learn a sixth language. I picked up Pike in about a weekend by realizing that it was Python semantics meets C syntax, and then went on to spend the next few years getting to know its own idioms. I'd say anyone who knows a dozen languages should be able to pick up any non-esoteric language in a weekend, at least to a level of broad familiarity of being able to read and comprehend code and make moderate changes to it. [1] https://en.wikipedia.org/wiki/List_of_programming_languages ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wednesday, December 11, 2013 9:31:42 PM UTC+5:30, bob gailer wrote: On 12/11/2013 3:43 AM, Chris Angelico wrote: When you tell a story, it's important to engage the reader from the start...explain This is how to print Hello World to the console and worry about what exactly the console is (and how redirection affects it) Highly agree. I was once given FORTRAN course materials and an assignment to teach this course. The first morning was spent on how to construct expressions! No context as to what a program was or what it might do or how to run it. As soon as that class was over I rewrote the materials so the first morning was how to write and run(batch job submission) a program that read a record, did a simple calculation and wrote the results. Kernighan and Ritchie set an important first in our field by making Hello World their first program. People tend to under-estimate the importance of this: Many assumptions need to be verified/truthified/dovetailed starting from switching on the machine onwards for this to work. And its quite a pleasurable sense of achievement when it finally holds together -- something which is sorely missing in the Dijkstra approach. However when we have an REPL language like python, one has the choice of teaching the hello-world program as: print (Hello World) or just Hello World The second needs one more assumption than the first, viz that we are in the REPL, however on the whole it creates better habits in the kids. [BTW: From the theoretical POV, imperative programming is 'unclean' because of assignment statements. From the practical POV of a teacher, the imperativeness of print is a bigger nuisance in students' thinking patterns ] I certainly felt better about teaching this way. Asides: One student (PhD in Physics) looked at X = X + 1 and said no it doesn't. Yes thats one issue in most modern imperative languages that the older generation (Pascal-family) did not have, viz that assignment looks like equality. Another wrote his first program. I took one look at it and saw the mistakes. I explained how to walk thru the program step by step. He exclaimed In that much detail?. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Wed, 11 Dec 2013 08:27:23 -0800, rusi wrote: [BTW: From the theoretical POV, imperative programming is 'unclean' because of assignment statements. From the practical POV of a teacher, the imperativeness of print is a bigger nuisance in students' thinking patterns ] +1 on this Trying to teach newbies to use return rather than print in their functions is one of the more difficult parts of teaching beginners. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Thu, Dec 12, 2013 at 3:27 AM, rusi rustompm...@gmail.com wrote: However when we have an REPL language like python, one has the choice of teaching the hello-world program as: print (Hello World) or just Hello World The second needs one more assumption than the first, viz that we are in the REPL, however on the whole it creates better habits in the kids. How is the bare string creating better habits? The only time I've ever been happy with bare strings having functionality[1] is in shell-like languages (including REXX; the one time I built a REXX system in which bare strings weren't executed as commands was a MUD, where command handlers could use bare strings to send lines of text to the client, and I wasn't happy with that - an explicit function would have been better). I'd much rather teach a function that produces clean output than depend on the REPL for Hello World. Now, depending on the REPL for *expressions* is quite another thing. 1+2 3 That makes perfect sense! But it's using Python as a calculator, not as a programming language. Python blurs the line a bit, but for teaching programming, I'd use programming style even at the REPL: print(Hello, world!) Hello, world! ChrisA [1] I don't have anything to footnote here, I just felt like having one. -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ My thoughts exactly! If you wade through the comments there, someone has done a more-than-naive implementation here: https://github.com/kmike/marisa-trie The write up makes it look pretty favorable as well for performance (scroll 2/3s down to the Benchmarks section). -- https://mail.python.org/mailman/listinfo/python-list
Re: grab dict keys/values without iterating ?!
On 11/12/2013 17:19, Travis Griggs wrote: On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ My thoughts exactly! If you wade through the comments there, someone has done a more-than-naive implementation here: https://github.com/kmike/marisa-trie The write up makes it look pretty favorable as well for performance (scroll 2/3s down to the Benchmarks section). http://kmike.ru/python-data-structures/ from the author of the above is well worth a read. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Movie (MPAA) ratings and Python?
On Dec 11, 2013, at 12:50 AM, Dan Stromberg drsali...@gmail.com wrote: Now the question becomes: Why did chardet tell me it was windows-1255? :) As it says on the tin: chardet guesses the encoding of text files. The operative word is ‘guesses’. -- https://mail.python.org/mailman/listinfo/python-list
Re: Script Request
Hi, On Wed, 11 Dec 2013 04:53:41 -0700 Jeff James wrote: Looking for a script which will check connectivity of any or all of our company URL's first thing in the morning to make sure none or our sites are down. Any suggestions ? Thank You This really is not a suggestion because the software is not usable for production use - there are missing too many features. But I am currently developing a Nagios style monitoring solution using Python. The software is called Linspector and it has an own homepage: http://linspector.org Linspector currrently only supports some TCP port probes and checking for a string in some content fetched via HTTP. We are not developing more servicve checks at the moment because we at first want to build the core of the application to make sure we don't have to refactor to much code all the time. In the future Linspector will be a complete monitoring solution supporting many protocols like SNMP, devices like sensors etc. Linspector differs to all other monitoring solutions that it only does monitoring, alerting and the storage of results in a database like MongoDB. It really does not build graphs, statistics, SLA reports etc. because we think this is not the job of a monitoring software which you really should rely on and which not should waste CPU time for such stuff. All data could be accessed from web applications, desktop applications etc. for later usage. Another big difference is, that we do not provide a graphical interface in Linspector. Linspector provides a Shell style interface for managing an instance. In this Shell, called Lish, you will be able to enable/disable jobs, get job lists, get a jobs state etc. Another interface to Linspector is a JSON-RPC interface so you can easy write your own management software for Linspector. Be sure, Linspector is in a very early state of development but development is going on every day and it is my main project... I love it so i will not stop developing it. We are planning to finish the core features until January/February 2014 and will then start building a lot of service checks for all the everyday monitoring tasks. Even the Shell interface is only partly usable at the moment so this will also be done until early 2014. If you have any questions about this software feel free to conatct me directly via mail. Regards, Johannes -- https://mail.python.org/mailman/listinfo/python-list
Re: Movie (MPAA) ratings and Python?
On 12/10/13 6:50 PM, Dan Stromberg wrote: On Tue, Dec 10, 2013 at 1:07 PM, Petite Abeille petite.abei...@gmail.com mailto:petite.abei...@gmail.com wrote: On Dec 10, 2013, at 6:25 AM, Dan Stromberg drsali...@gmail.com mailto:drsali...@gmail.com wrote: The IMDB flat text file probably came the closest, but it appears to have encoding issues; it's apparently nearly windows-1255, but not quite. It's ISO-8859-1. Thanks - that reads well from CPython 3.3. Now the question becomes: Why did chardet tell me it was windows-1255? :) It probably told you it was Windows-1252 (I'm assuming the last 5 is a typo). Windows-1252 is a super-set of ISO-8859-1, so any text that is correct ISO-8859-1 is also correct Windows-1252. In addition, it's not uncommon to find text marked as ISO-8859-1 that in fact has characters that make it Windows-1252. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
adding values from a csv column and getting the mean. beginner help
I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv import sys if len(sys.argv) 3: print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0])) sys.exit(1) filename = sys.argv[1] column = int(sys.argv[2]) for line in filename() , column (): elements = line.strip().split(',') values.append(int(elements[col])) csum = sum(values) cavg = sum(values)/len(values) print(Sum of column %d: %f % (col, csum)) print(Avg of column %d: %f % (col, cavg)) -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 2013-12-11 11:10, brian cleere wrote: filename = sys.argv[1] column = int(sys.argv[2]) for line in filename() , column (): elements = line.strip().split(',') values.append(int(elements[col])) 1) you need to open the file 2) you need to make use of the csv module on that file 3) you need to extract the column Thus it would looks something like column = int(sys.argv[2]) f = open(sys.argv[1], rb) r = csv.reader(f) try: for row in r: values.append(int(row[column])) finally: f.close() which can be obtusely written as values = [int(row[column]) for row in csv.reader(open(sys.argv[1], rb))] though the more expanded version allows you to do better error handling (rows with insufficient columns, non-numeric/non-integer values in the specified column, etc). -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On Thu, Dec 12, 2013 at 6:10 AM, brian cleere briancle...@gmail.com wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. Your problem is akin to debugging an empty file :) It's not so much a matter of fixing what's not working as of starting at the very beginning: How do you iterate over the content of a CSV file? Now, you're almost there... partly. You have the split() call, which will split on the comma, so if you go that route, all you need to do is open the file, using the aptly-named builtin function open. You'll find docs on that if you do a quick search. But you're actually part-way to the better solution. You're importing the 'csv' module, which is exactly what you need here. All you need is to read up on its docs: http://docs.python.org/3/library/csv.html I'm sure you can figure out the rest of your homework from there! Now, with that out of the way, I'd like to just mention a couple of other things. print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0])) Square brackets in a usage description often mean optional. You may want to be careful of that. There's no really good solution though. csum = sum(values) cavg = sum(values)/len(values) Once you've calculated the sum once, you can reuse that to calculate the average. Can you see how? :) And finally: You're using Google Groups to post, which means your paragraphs are unwrapped, and - unless you fight very hard against a stupidly buggy piece of software - your replies will be malformed and ugly. Don't make yourself look bad; switch to a better newsreader, or to the mailing list: https://mail.python.org/mailman/listinfo/python-list The content is the same, you just subscribe to the list and read and write as email. Thanks! And welcome to the group. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Tracking the status of python script execution
Hello All, I am looking for a library that can help me trace the status of a live python script execution. i.e if I have a python script `x.py` with 200 lines, when I execute the script with `python x.py`, is there a way to trace the status of this execution in terms of number of lines executed so far? Background: We have a Web page with Run button that executes the program `x.py` when a user clicks it. We were looking of a way to keep the user informed about the status of run by using: (no. of lines executed/total lines) *100. Since the script `x.py` is running multiple sql queries, it usually won't be the case that the script would complete within few seconds of its execution. Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 11/12/2013 19:10, brian cleere wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. #!/bin/env python import csv You never use the csv module. import sys if len(sys.argv) 3: print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0])) sys.exit(1) filename = sys.argv[1] column = int(sys.argv[2]) for line in filename() , column (): You're trying to loop around the filename and the column, you need to open the file and loop around that. elements = line.strip().split(',') Please don't do this when you've got the csv module to do things for you. values.append(int(elements[col])) Where did values come from? Is it col or column, please make your mind up? So let's stick things together. Something like. values = [] with open(filename) as csvfile: valuereader = csv.reader(csvfile) for row in valuereader: values.append(int(row[column])) csum = sum(values) cavg = sum(values)/len(values) print(Sum of column %d: %f % (col, csum)) print(Avg of column %d: %f % (col, cavg)) I like consistency, new style formatting here, old style above, still if it works for you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Tracking the status of python script execution
On Thu, Dec 12, 2013 at 6:26 AM, Shyam Parimal Katti spk...@nyu.edu wrote: I am looking for a library that can help me trace the status of a live python script execution. i.e if I have a python script `x.py` with 200 lines, when I execute the script with `python x.py`, is there a way to trace the status of this execution in terms of number of lines executed so far? Background: We have a Web page with Run button that executes the program `x.py` when a user clicks it. We were looking of a way to keep the user informed about the status of run by using: (no. of lines executed/total lines) *100. Since the script `x.py` is running multiple sql queries, it usually won't be the case that the script would complete within few seconds of its execution. That's a bit tricky. More useful would probably be to explicitly pepper your code with calls to some still active function, but it's going to be nearly impossible to get any sort of viable percent-done based on lines of code. There might be one primary loop that takes 80% of the execution time or more. You mention SQL queries. Can you wrap up the query handler in something that effectively treats _those_ as your fundamental divisions of job-done-ness? I'm not sure how (in either case, actually) you'd automatically figure out how many there are to do (either lines or queries), so you may still have to have something externally count them up - which would still not work if there's a loop, though with queries it's less sane to have a loop executing them than lines of code. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 11/12/2013 19:22, Chris Angelico wrote: On Thu, Dec 12, 2013 at 6:10 AM, brian cleere briancle...@gmail.com wrote: I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated. Your problem is akin to debugging an empty file :) It's not so much a matter of fixing what's not working as of starting at the very beginning: How do you iterate over the content of a CSV file? Now, you're almost there... partly. You have the split() call, which will split on the comma, so if you go that route, all you need to do is open the file, using the aptly-named builtin function open. You'll find docs on that if you do a quick search. But you're actually part-way to the better solution. You're importing the 'csv' module, which is exactly what you need here. All you need is to read up on its docs: http://docs.python.org/3/library/csv.html I'm sure you can figure out the rest of your homework from there! Now, with that out of the way, I'd like to just mention a couple of other things. print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0])) Square brackets in a usage description often mean optional. You may want to be careful of that. There's no really good solution though. There is, https://pypi.python.org/pypi/docopt/0.6.1 :) csum = sum(values) cavg = sum(values)/len(values) Once you've calculated the sum once, you can reuse that to calculate the average. Can you see how? :) And finally: You're using Google Groups to post, which means your paragraphs are unwrapped, and - unless you fight very hard against a stupidly buggy piece of software - your replies will be malformed and ugly. Don't make yourself look bad; switch to a better newsreader, or to the mailing list: https://mail.python.org/mailman/listinfo/python-list The content is the same, you just subscribe to the list and read and write as email. Ooh 'eck, we'll have the Popular Front for the Liberation of Google Groups squad out in force again, vainly trying to defend the bug ridden crap that they insist on using, and which I obviously won't mention. Whoops!!! Oh Lord, won't you buy me Mozilla Thunderbird ? My friends all use GG, I think that's absurd. Worked hard all my lifetime, no help from the nerds, So Lord, won't you buy me Mozilla Thunderbird ? With apologies to the late, great Janis Joplin. Thanks! And welcome to the group. ChrisA -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On Thu, Dec 12, 2013 at 6:41 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Square brackets in a usage description often mean optional. You may want to be careful of that. There's no really good solution though. There is, https://pypi.python.org/pypi/docopt/0.6.1 :) That appears to use x for a mandatory argument x, which is then slightly ambiguous with shell redirection. But that's the best notation I've ever seen for distinguishing mandatory args from fixed keywords. CrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 11/12/2013 19:46, Chris Angelico wrote: On Thu, Dec 12, 2013 at 6:41 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Square brackets in a usage description often mean optional. You may want to be careful of that. There's no really good solution though. There is, https://pypi.python.org/pypi/docopt/0.6.1 :) That appears to use x for a mandatory argument x, which is then slightly ambiguous with shell redirection. But that's the best notation I've ever seen for distinguishing mandatory args from fixed keywords. CrisA I use the alternative X for a mandatory argument X. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On Thu, Dec 12, 2013 at 7:00 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: I use the alternative X for a mandatory argument X. Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go to bar X, order a Y, and Z it [eg 'compress', 'gzip', 'drink'] How do you show that x/y/z are mandatory args, but foo/bar are keywords to be typed exactly? In some formats italicized text can make that distinction, but not in pure text. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 12 December 2013 03:25, Chris Angelico ros...@gmail.com wrote: On Thu, Dec 12, 2013 at 3:18 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 11/12/2013 16:04, Chris Angelico wrote: I strongly believe that a career programmer should learn as many languages and styles as possible, but most of them can wait. I chuckle every time I read this one. Five years per language, ten languages, that's 50 years I think. Or do I rewrite my diary for next week, so I learn Smalltalk Monday morning, Ruby Monday afternoon, Julia Tuesday morning ... Well, I went exploring the Wikipedia list of languages [1] one day, and found I had at least broad familiarity with about one in five. I'd like to get that up to one in four, if only because four's a power of two. More seriously: Once you've learned five of very different styles, it won't take you five years to learn a sixth language. I picked up Pike in about a weekend by realizing that it was Python semantics meets C syntax, and then went on to spend the next few years getting to know its own idioms. I'd say anyone who knows a dozen languages should be able to pick up any non-esoteric language in a weekend, at least to a level of broad familiarity of being able to read and comprehend code and make moderate changes to it. Absolutely. 10 years ago I was saying I'd forgotten at least 20 languages, and there have been many more since. Once you know enough programming languages you (and by you I mean me) get to the point where if you don't know a specific language you can pick up enough to be useful in a day or two, reasonably proficient in a week, and have a fairly high level of mastery by the time you've finished whatever project you picked it up for. And then you don't use it for a while, forget it to make room for something else, and pick it up again when you need it (much faster this time). Except Prolog. Never could get my head around it - I should go back and have another try one of these days. Some languages stick with you (e.g. Python) and I don't tend to learn languages that are too similar to what I already know unless it's for a specific project. So I've never learned Ruby ... but I have had to modify a few Ruby scripts along the way, and been able to achieve what I wanted the same day. TimD elaney -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 2013-12-12 07:03, Chris Angelico wrote: Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go to bar X, order a Y, and Z it [eg 'compress', 'gzip', 'drink'] How do you show that x/y/z are mandatory args, but foo/bar are keywords to be typed exactly? In some formats italicized text can make that distinction, but not in pure text. I prefer {} notation: $0 mv [--optional] {x} {y} $0 bar [--mutually|--exclusive] {x} {y} {z} -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 11/12/2013 20:03, Chris Angelico wrote: On Thu, Dec 12, 2013 at 7:00 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: I use the alternative X for a mandatory argument X. Also common, but how do you specify a keyword, then? Say you have a command with subcommands: $0 foo x y Move the foo to (x,y) $0 bar x y z Go to bar X, order a Y, and Z it [eg 'compress', 'gzip', 'drink'] How do you show that x/y/z are mandatory args, but foo/bar are keywords to be typed exactly? In some formats italicized text can make that distinction, but not in pure text. ChrisA Haven't a clue off the top of my head so read all about it here https://github.com/docopt/docopt -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Figuring out what dependencies are needed
On Wed, Dec 11, 2013 at 6:38 AM, Robert Kern robert.k...@gmail.com wrote: On 2013-12-11 13:27, Steven D'Aprano wrote: On Wed, 11 Dec 2013 04:44:53 -0800, sal wrote: Now I'd like to use the backtesting package from zipline (zipline.io), .io is not normally a file extension for Python files. Are you sure that's Python code? That's a package name, not a filename. Actually, the .io there appears to be a TLD. At least, zipline.io is the address for the website of a zipline Python package. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there any advantage to using a main() in python scripts?
On 12/11/2013 5:26 AM, Ben Finney wrote: Better design is to make the argument list a parameter to the ‘main’ function; this allows constructing an argument list specially for calling that function, without ‘main’ needing to know the difference. You'll also want to catch SystemExit and return that as the ‘main’ function's return value, to make it easier to use as a function when that's needed. def main(argv=None): if argv is None: argv = sys.argv exit_code = 0 try: command_name = argv[0] config = parse_command_args(argv[1:]) do_whatever_this_program_does(config) except SystemExit, exc: exit_code = exc.code return exit_code if __name__ == __main__: import sys exit_code = main(sys.argv) sys.exit(exit_code) That way, the normal behaviour is to use the ‘sys.argv’ list and to raise SystemExit (via ‘sys.exit’) to exit the program. But ‘main’ itself can, without any further changes, be called as a function that receives the command line as a parameter, and returns the exit code. In particular, it is easier to write tests when argv is a parameter. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 12/11/2013 12:34 AM, Devin Jeanpierre wrote: On Tue, Dec 10, 2013 at 2:02 PM, Ethan Furman et...@stoneleaf.us wrote: Doesn't sound like they do, as that's causing plenty of problems. In today's world that level of knowledge isn't always necessary, especially if your degree is not in CS. One of the (many) nice things about Python is one doesn't need to know that stuff to Get Things Done. You don't need to know how to use the brakes to drive to Wal-Mart, either. In my world, Getting Things Done includes not crashing at my destination. ;) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: Movie (MPAA) ratings and Python?
On Wed, Dec 11, 2013 at 10:35 AM, Ned Batchelder n...@nedbatchelder.comwrote: On 12/10/13 6:50 PM, Dan Stromberg wrote: Now the question becomes: Why did chardet tell me it was windows-1255? :) It probably told you it was Windows-1252 (I'm assuming the last 5 is a typo). Windows-1252 is a super-set of ISO-8859-1, so any text that is correct ISO-8859-1 is also correct Windows-1252. In addition, it's not uncommon to find text marked as ISO-8859-1 that in fact has characters that make it Windows-1252. $ chardet mpaa-ratings-reasons.list mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) I'm aware that chardet is playing guessing games, though one would hope it would guess well most of the time, and give a reasonable confidence rating. -- https://mail.python.org/mailman/listinfo/python-list
[newbie] trying socket as a replacement for nc
I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the measurement instrument back. I thought I could accomplish the same using the python module socket and tried out the sample program below which doesn't work however: #!/usr/bin/env python A simple echo client import socket host = '10.128.59.63' port = 7000 size = 10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host,port)) s.send('*IDN?') data = s.recv(size) s.close() print 'Received:', data Can anyone here tell me how to do it properly? thanks in advance jean -- https://mail.python.org/mailman/listinfo/python-list
Re: Tracking the status of python script execution
Long ago, I saw a C program that took another C program as input. It would output a copy of the original C program, interspersed with fprintf's that would display the text of the line current being executed. You might write something similar for Python, perhaps outputting the line being executed and/or the line number. You could have it open a file in /tmp or something. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
On Wed, Dec 11, 2013 at 3:08 PM, Jean Dubois jeandubois...@gmail.comwrote: I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the measurement instrument back. I thought I could accomplish the same using the python module socket and tried out the sample program below which doesn't work however: Sockets reserve the right to split one socket.send() into multiple socket.recv()'s on the other end of the communication, or to aggregate multiple socket.send()'s into a single socket.recv() - pretty much any way the relevant IP stacks and communications equipment feel like for the sake of performance or reliability. The confusing thing about this is, it won't be done on every transmission - in fact, it'll probably happen rather seldom unless you're on a heavy loaded network or have some MTU issues (see Path MTU Discovery, and bear in mind that paths can change during a TCP session). But writing your code assuming it will never happen is a bad idea. For this reason, I wrote http://stromberg.dnsalias.org/~strombrg/bufsock.html , which abstracts away these complications, and actually makes things pretty simple. There are examples on the web page. HTH -- https://mail.python.org/mailman/listinfo/python-list
Re: Movie (MPAA) ratings and Python?
On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: $ chardet mpaa-ratings-reasons.list mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) I'm aware that chardet is playing guessing games, though one would hope it would guess well most of the time, and give a reasonable confidence rating. What reason do you have for thinking that Windows-1255 isn't a reasonable guess? If the bulk of the text is Latin-1 except perhaps for one or two Hebrew characters (or what chardet thinks are Hebrew characters), it may actually be a reasonable guess. If it is a poor guess, perhaps you ought to report it to the chardet maintainers as a good example of a poor guess. By the way, this forum is a text-only newsgroup and so-called Rich Text (actually HTML) posts are frowned upon because most people don't appreciate having to read gunk like this: div dir=ltrbrdiv class=gmail_extradiv class=gmail_quote ... br blockquote class=gmail_quote style=margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1exdiv class=im ... br/div/div/div/div If you can, would you please turn off rich text posting when you post here please? Thank you. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Movie (MPAA) ratings and Python?
On Wed, Dec 11, 2013 at 3:24 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 11 Dec 2013 15:07:35 -0800, Dan Stromberg wrote: $ chardet mpaa-ratings-reasons.list mpaa-ratings-reasons.list: windows-1255 (confidence: 0.97) I'm aware that chardet is playing guessing games, though one would hope it would guess well most of the time, and give a reasonable confidence rating. What reason do you have for thinking that Windows-1255 isn't a reasonable guess? If the bulk of the text is Latin-1 except perhaps for one or two Hebrew characters (or what chardet thinks are Hebrew characters), it may actually be a reasonable guess. I get a traceback if I try to read the file as Windows-1255. I don't get a traceback if I read it as ISO-8859-1. If it is a poor guess, perhaps you ought to report it to the chardet maintainers as a good example of a poor guess. I was considering that, and may do so. I've also been wondering if ISO-8859-1 is just an octet-oriented codec, so it'll read about anything. There are clearly non-7-bit-ASCII characters in the file that look like line noise in an mrxvt. By the way, this forum is a text-only newsgroup and so-called Rich Text (actually HTML) posts are frowned upon because most people don't appreciate having to read gunk like this: div dir=ltrbrdiv class=gmail_extradiv class=gmail_quote ... br blockquote class=gmail_quote style=margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1exdiv class=im ... br/div/div/div/div If you can, would you please turn off rich text posting when you post here please? Thank you. Apologies. I didn't realize gmail was doing this. I had thought it would only do so if I used the formatting options in the composer, but perhaps it does so even when just typing text. I formerly used MH; are you using MH? There isn't a lot of e-mail programs that don't do HTML anymore. Even mutt can do HTML with very slight configuration; it's actually quite powerful and ISTR it can do MH folders. I found a remove formatting button in gmail's composer, and used it on this message. Does this message look like plain text? I'm not really prepared to give up gmail's quick searching; I used to index my e-mails using pyindex and dovecot, but happily I don't need to anymore. -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] trying socket as a replacement for nc
Jean Dubois jeandubois...@gmail.com writes: I have an ethernet-rs232 adapter which allows me to connect to a measurement instrument by means of netcat on a linux system. e.g. entering nc 10.128.59.63 7000 allows me to enter e.g. *IDN? after which I get an identification string of the measurement instrument back. I thought I could accomplish the same using the python module socket and tried out the sample program below which doesn't work however: In what way does it not work? Do you not get any data? Do you get the wrong data? Does your program block at a point which you do not understand? Probably more to the point, are you sure you are sending exactly the same data as you did with netcat? netcat running with stdin a terminal sends data line-by-line, and includes the newline in the data that it sends. You didn't send a newline in your example. -- https://mail.python.org/mailman/listinfo/python-list
Optimizing list processing
I have some code which produces a list from an iterable using at least one temporary list, using a Decorate-Sort-Undecorate idiom. The algorithm looks something like this (simplified): table = sorted([(x, i) for i,x in enumerate(iterable)]) table = [i for x,i in table] The problem here is that for large iterables, say 10 million items or so, this is *painfully* slow, as my system has to page memory like mad to fit two large lists into memory at once. So I came up with an in-place version that saves (approximately) two-thirds of the memory needed. table = [(x, i) for i,x in enumerate(iterable)] table.sort() for x, i in table: table[i] = x For giant iterables (ten million items), this version is a big improvement, about three times faster than the list comp version. Since we're talking about the difference between 4 seconds and 12 seconds (plus an additional 40-80 seconds of general slow-down as the computer pages memory into and out of virtual memory), this is a good, solid optimization. Except that for more reasonably sized iterables, it's a pessimization. With one million items, the ratio is the other way around: the list comp version is 2-3 times faster than the in-place version. For smaller lists, the ratio varies, but the list comp version is typically around twice as fast. A good example of trading memory for time. So, ideally I'd like to write my code like this: table = [(x, i) for i,x in enumerate(iterable)] table.sort() if len(table) ?: table = [i for x,i in table] else: for x, i in table: table[i] = x where ? no doubt will depend on how much memory is available in one contiguous chunk. Is there any way to determine which branch I should run, apart from hard- coding some arbitrary and constant cut-off value? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: adding values from a csv column and getting the mean. beginner help
On 12/11/2013 01:41 PM, Mark Lawrence wrote: On 11/12/2013 19:22, Chris Angelico wrote: There is, https://pypi.python.org/pypi/docopt/0.6.1 :) +1 for docopt. It makes everything very clear. Just type out your usage string, and then run docopt(usage_str) on it to get a dict of your args. When I saw the video at http://docopt.org my jaw dropped. I couldn't believe all of the arg parsing junk I had been writing for even the smallest scripts. The other arg parsing libs make it easier than manually doing it, but docopt is magic. -- - Christopher Welborn cjwelb...@live.com http://welbornprod.com -- https://mail.python.org/mailman/listinfo/python-list