[pygtk] ANNOUNCE: PyGObject 2.14.2
I am pleased to announce version 2.14.2 of the Python bindings for GObject. The new release is available from ftp.gnome.org as and its mirrors as soon as its synced correctly: http://download.gnome.org/sources/pygobject/2.14/ What's new since PyGObject 2.14.1: - Allow gobject.property work with subclasses. (#523352, Tomeu Vizoso) - Unbreak Source.prepare (#523075, Bryan Silverthorn) - Never override customly set 'tp_new' and 'tp_alloc' (Paul Pogonyshev) - Don't link against libffi if we cannot find libffi on the system. (#496006, Ed Catmur) - Dist .m4 files. (#496011, Ed Catmur) - Don't return NULL after warning of enum comparsion (#519631, Paul Pogonyshev) Blurb: GObject is a object system library used by GTK+ and GStreamer. PyGObject provides a convenient wrapper for the GObject+ library for use in Python programs, and takes care of many of the boring details such as managing memory and type casting. When combined with PyGTK, PyORBit and gnome-python, it can be used to write full featured Gnome applications. Like the GObject library itself PyGObject is licensed under the GNU LGPL, so is suitable for use in both free software and proprietary applications. It is already in use in many applications ranging from small single purpose scripts up to large full featured applications. PyGObject requires GObject = 2.8.0 and Python = 2.3.5 to build. -- Johan Dahlin [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
True random number generator
truerandom.py is a Python module that generates true random numbers obtained from www.random.org. Use with the form: mylist=truerandom.getnum(min,max,amount) mylist will be a list containing the true random numbers. If for some reason the numbers cannot be generated, the list will contain -1. You can download it here: http://code.google.com/p/truerandom/ -- http://mail.python.org/mailman/listinfo/python-list
which datastructure for fast sorted insert?
im writing a webcrawler. after visiting a new site i want to store it in alphabetical order. so obv i want fast insert. i want to delete duplicates too. which datastructure is best for this? -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
use a set to store them: s=set() s.add('a') s.add('b') s set(['a', 'b']) s.add('a') s set(['a', 'b']) s.add('c') s set(['a', 'c', 'b']) it does remove duplicates, but is it not ordered. to order it you can use: l=list(s) l.sort() l ['a', 'b', 'c'] hth, Rares -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
On 25 Maj, 08:56, Rares Vernica [EMAIL PROTECTED] wrote: use a set to store them: s=set() s.add('a') s.add('b') s set(['a', 'b']) s.add('a') s set(['a', 'b']) s.add('c') s set(['a', 'c', 'b']) it does remove duplicates, but is it not ordered. to order it you can use: l=list(s) l.sort() l ['a', 'b', 'c'] hth, Rares sets dont seem to be so good because there is no way to iterate them. s.pop() remove and return an arbitrary element from s; raises KeyError if empty i dont want to remove i just want to get the string that is stored there. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding icons for Apps
On Sat, 24 May 2008 21:42:57 -0700, Sanoski wrote: This might be a dumb question. I don't know. I'm new to all this. How do you find icons for your programs? All GUI applications have cool icons that represent various things. For instance, to save is often represented as a disk, etc. You know, the small little picture references that give meaning to the phrase 'Graphical User Interface'. But I'm not a graphics artist! Drawing is simply one talent that skipped me completely. Where can I find icons to use with my programs? Many GUI toolkit ( like wx and gtk ) have a standard stock of icons for common tasks ( load, save, ok, cancel, ...). Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
recursion with or without return?
when using recursion should one use a return statement or not? there is a difference obv since with a return statement it will ultimately return a value if not recursing forever. but is there a guideline for this or it just taste or is it considering good style or pythonic to always have a returnvalue? -- http://mail.python.org/mailman/listinfo/python-list
Re: module import problem
Reinstall the package python-gnupginterface with sudo aptitude reinstall Your advice helped! Upgrade is running now. Thanks! -- Milos Prudek -- http://mail.python.org/mailman/listinfo/python-list
Re: recursion with or without return?
On Sun, 25 May 2008 00:00:14 -0700, notnorwegian wrote: when using recursion should one use a return statement or not? This decision has nothing to do with recursion. It's the same as in non recursive functions. If the function calculates something that you want to return to the caller you have to use ``return``. If the function just has side effects, e.g. printing a tree structure recursively, you don't have to ``return`` something. but is there a guideline for this or it just taste or is it considering good style or pythonic to always have a returnvalue? Well, you always have a return value anyway because there's an implicit ``return None`` at the end of every function. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
On Sun, 25 May 2008 00:10:45 -0700, notnorwegian wrote: sets dont seem to be so good because there is no way to iterate them. Err: In [82]: for x in set(['a', 'b', 'c']): : print x : a c b Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: webspider getting stuck
[EMAIL PROTECTED] wrote: i am writing a simple webspider . how do i avoid getting stuck at something like this: Enter username for W3CACL at www.w3.org: ? It's a silly feature of urllib. See http://docs.python.org/lib/module-urllib.html where it says: Note: When performing basic authentication, a FancyURLopener instance calls its prompt_user_passwd() method. The default implementation asks the users for the required information on the controlling terminal. A subclass may override this method to support more appropriate behavior if needed. Yes, the default behavior when faced with a site that wants authentication is to to ask for a user name and password on standard input. This is seldom what you want. So subclass and overrride. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: need some help in serving static files inside a wsgi apps
I guess, Apache does some kind of memory caching for files, which are often requested and small enough to fit into the system memory. Are you sure about this? I could not find anything in the documentation (other than mod_cache and friends, which is an unrelated functionality). Also, I don't see the need for Apache to cache frequently requested files itself. Instead, the operating system will cache frequently requested directories and files in memory, and it will do the same for a Python web server. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
Fuzzyman [EMAIL PROTECTED] writes: Perhaps a lint-like validation tool would be optimal for this problem... So we can refuse to execute their code if they use private APIs? No, but it could complain and point out the exact offending lines, pointing their development effort to right direction. Proxying so that we can really hide our internal APIs is a better solution. How about pyprotocols and other interface packages? Proxying is pretty workable too, and it easily makes sense that the official API objects should be different from the logic executing objects. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question: How to use a .pth file on a Macintosh
you put your pth file in (same configuration: /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site- packages/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Code correctness, and testing strategies
Michael L Torrie [EMAIL PROTECTED] wrote: Watch your programmers then. They do have to write and debug the code. And they will spend at least as much or more time debugging as writing the code. It's a fact. I have several programmers working for me on several projects. What you have been told is fact. This isn't the case for everyone. In my workplace the time we spend debugging is small compared to the time writing the code in the first place. I wonder what the difference is? We do use unit-testing quite widely, but by no means everywhere. The code which doesn't have unit tests doesn't tend to be any buggier than the code which does. Where testsuites really help is when you have to upgrade some library or service that your programs are depending on, and you get to find out about subtle backwards-incompatibilities. -M- -- http://mail.python.org/mailman/listinfo/python-list
Re: Showing the method's class in expection's traceback
Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 22 May 2008 07:55:44 -0300, Duncan Booth [EMAIL PROTECTED] escribió: Bruno Desthuilliers [EMAIL PROTECTED] wrote: Not to say that your concerns are pointless, and that things cannot be improved somehow, but this is not that trivial, and there may be ambuiguities in some not so rare cases. It might be worth considering an alternative approach here: a formatted exception includes the relevant source lines (where possible). Just to note that the standard cgitb module already does that, among other things. Anywhere Python prints a traceback already does that. The 'alternative approach' I was suggesting was the part you snipped, i.e. extracting the enclosing class name from the source. -- http://mail.python.org/mailman/listinfo/python-list
Re: need some help in serving static files inside a wsgi apps
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 [ Martin v. Löwis [EMAIL PROTECTED] ] I guess, Apache does some kind of memory caching for files, which are often requested and small enough to fit into the system memory. Are you sure about this? No, I'm not. That's why I said I guess ;) Also, I don't see the need for Apache to cache frequently requested files itself. Instead, the operating system will cache frequently requested directories and files in memory, and it will do the same for a Python web server. Of course, a modern OS kernel will perform caching anyway, but this is most likely slower than in-process caching, since it will still require context switches from userspace into kernel space. Considering this, it seems reasonable to me, that apache does memory caching, but I'm by far not sure, I wouldn't put a bet on this ;) - -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkg5K7kACgkQn3IEGILecb48VwCeJYqoyi7IJKwASza9/u381dmg PqMAn1M/JBe8xEsOAPNosNWA9WoKCvNh =K3tE -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
[EMAIL PROTECTED] wrote: Ben Finney: In Python, the philosophy we're all consenting adults here applies. Michael Foord: They will use whatever they find, whether it is the best way to achieve a goal or not. Once they start using it they will expect us to maintain it - and us telling them it wasn't intended to be used by them in the first place won't cut it. So they will use the methods with one or two underscores too. And imply that you want to document them too. They don't seem adult enough, then ;-) Internal API hiding seems quite less useful if you don't need to let customers manage your code. Or if you code in C++ and they *really* need to get at something you made private they will still get at it. I've been there and done that: 'private' in languages which have it is rarely an advantage and frequently a pain. Also note that private in C++ while it does make it harder to access (though not preventing it altogether) doesn't do any data hiding, so if you are subclassing a vendor-provided function you still have to take note of the private attributes to avoid naming collisions. At least Python's convention which hides the implementation without making it hard to access has some benefits. -- http://mail.python.org/mailman/listinfo/python-list
access interactive namespace from module (shared namespace?)
I've got a probably embarrassing trivial problem with namespaces, but couldn't solve it myself nor find an answer in the net. Hopefully one of you guys can help me. What I want to do: Use the interactive shell and e.g define the variable a there. Then load a module and access a from within. e.g file utest.py def doit(): print 2*a in the shell: import utest a=3 utest.doit() - I want this to print 2*a, but of course obtain: type exceptions.NameError': global name 'a' is not defined Any change I do to a in the shell should be seen from the doit() function, any variable assignment I do in the doit() function should be seen in the shell. I guess it's somehow a namespace sharing. Actually the function doit() will contain an eval() function that should evaluate a (via a gui) dynamically inserted expression. Any one got a clue? (a clue what I try to say and how to help?!) Thanks a lot in advance!! Ulrich -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
On May 25, 2:28 am, Terry Reedy [EMAIL PROTECTED] wrote: Benjamin Kaplan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | On Sat, May 24, 2008 at 10:14 AM, Fuzzyman [EMAIL PROTECTED] wrote: || For example, at Resolver Systems we expose the spreadsheet object | model to our users. It hasa public, documented, API - plus a host of | undocumented internally used methods. | | We would really *much* rather hide these, because anything our | customers start using (whether documented or not) we will probably | have to continue supporting and maintaining. | | The 'we told you not to use that' approach, when applied to paying | customers doesn't really work... all they see is that you broke their | spreadsheet code by changing your API. Python was not really written with 'difficult' customers in mind ;-) True. It's extremely suited to what we do though.Minor difficulties like this are vastly outweighed by advantages. The difficulties are real though. One could largely hide private vars with a program that substituted random names for single _ names, and removed the doc strings for functions, classes, and methods with such names. We need to *use* those names to display the spreadsheet once the calculation has finished (and their code has run). Such a program could even put such names in a separate module imported as '_private_do_not_use_'. Splitting more of the functionality out is probably part of the best solution. Michael Foord http://www.ironpythoninaction.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: access interactive namespace from module (shared namespace?)
Ulrich Dorda wrote: I've got a probably embarrassing trivial problem with namespaces, but couldn't solve it myself nor find an answer in the net. Hopefully one of you guys can help me. What I want to do: Use the interactive shell and e.g define the variable a there. Then load a module and access a from within. e.g file utest.py def doit(): print 2*a in the shell: import utest a=3 utest.doit() - I want this to print 2*a, but of course obtain: type exceptions.NameError': global name 'a' is not defined Any change I do to a in the shell should be seen from the doit() function, any variable assignment I do in the doit() function should be seen in the shell. I guess it's somehow a namespace sharing. Actually the function doit() will contain an eval() function that should evaluate a (via a gui) dynamically inserted expression. Any one got a clue? (a clue what I try to say and how to help?!) Thanks a lot in advance!! Ulrich Here is one way #utest.py: def doit(valuemap): print 2*valuemap['a'] Python 2.5.1 (r251:54863, Mar 7 2008, 04:10:12) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type help, copyright, credits or license for more information. a = 4 import utest utest.doit(locals()) 8 -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question: How to use a .pth file on a Macintosh
Robbie wrote: I can't seem to figure out where to put this file so that Python will recognize it when I start it up. You need to put this file in your site-packages directory. To get the location of your site-packages directory, type in Python interactive shell: from distutils.sysconfig import get_python_lib print get_python_lib() -- Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: access interactive namespace from module (shared namespace?)
Thanks for the reply, Of course the suggested solution is working and good, but a bit complicated. The module/function where i need to access the variable value from the interactive shell is burried quite deep and I would nedd to hand the locals() quite often from one module to another. Furthermore it makes the call function slightly more complicated, as the locals()-argunment has to be given every time. I was hoping for something a bit different: If I wanted to access a value b from another module utest2.py, I would simply need to type in utest.py: import utest2; print 2*utest2.b Isn't there a name for the interactive namespace (like here the utest2), which I can use to access the variable without handing the whole dictionary? Cheers, Ulrich -- http://mail.python.org/mailman/listinfo/python-list
Re: access interactive namespace from module (shared namespace?)
Ulrich Dorda wrote: I've got a probably embarrassing trivial problem with namespaces, but couldn't solve it myself nor find an answer in the net. Hopefully one of you guys can help me. What I want to do: Use the interactive shell and e.g define the variable a there. Then load a module and access a from within. e.g file utest.py def doit(): print 2*a in the shell: import utest a=3 utest.doit() - I want this to print 2*a, but of course obtain: type exceptions.NameError': global name 'a' is not defined Any change I do to a in the shell should be seen from the doit() function, any variable assignment I do in the doit() function should be seen in the shell. I guess it's somehow a namespace sharing. Actually the function doit() will contain an eval() function that should evaluate a (via a gui) dynamically inserted expression. Any one got a clue? (a clue what I try to say and how to help?!) Thanks a lot in advance!! While the sane approach to this is def doit(a): print 2 * a here is an insane one: import sys def f(): pass function = type(f) def snatch_globals(f): def g(*args, **kw): return function(f.func_code, sys._getframe(1).f_globals)(*args, **kw) return g @snatch_globals def doit(): print 2 * a Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
Duncan Booth [EMAIL PROTECTED] writes: Or if you code in C++ and they *really* need to get at something you made private they will still get at it. I've been there and done that: 'private' in languages which have it is rarely an advantage and frequently a pain. Indeed. In C++, they recommend the pimpl idiom (private implementation), which actually has real advantages ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python, Daemons and D-Bus
PurpleServerMonkey schrieb: On May 25, 5:46 am, Sebastian 'lunar' Wiesner [EMAIL PROTECTED] wrote: [ PurpleServerMonkey [EMAIL PROTECTED] ] Would you use D-Bus or a more traditional IPC method such as sockets? Although D-Bus is relatively new it looks interesting, just not sure it would work well in this kind of project. DBus is not really intended for private communication between processes of the same application, but more for intercommunication between different applications. If the IPC interface of your backend daemons is intended to be used by other applications, DBus is the right choice, otherwise I would choose something different. The reason is, that DBus doesn't know about applications. It exposes all objects registered on the bus to every DBus client on the system and so makes you application-private API available to the public (and spams the bus with lots of generally useless objects ;) ). In case your IPC interface is application private, a custom IPC protocol (probably using XML RPC over unix sockets) is better suited. Moreover you should make your choice dependent on the type of data you transmit. Both DBus and XML-RPC wrap calls into XML messages, which is terribly inefficient for large binary data. -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) Thanks Sebastian, Your comments make a lot of sense. I was thinking of creating a custom session channel and using that for my purposes but as you mentioned it's not very secure and I do want to keep the server to daemon traffic private, the server has an XML-RPC interface with a public API. Will definitely look at using a different IPC mechanism for this part of the project. If you can - use Pyro. It is easy, fast and can be made secure using SSL AFAIK. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
Roy Smith schrieb: In article [EMAIL PROTECTED], Fuzzyman [EMAIL PROTECTED] wrote: Also, like others, I have had wonderful experiences of trying to track down test failures that depend on the order that tests run in. Having interdependencies between tests is a recipe for madness... I agree that tests should not depend on each other, but sometimes it's still useful to have the tests run in a certain order for reporting purposes. Then sort your report. Seriously. A test-outpt shoud be in a way that delimits individual testresults in a way that makes them easily extractable. Then if you want them to be ordered for e.g. diff'ing - sort them. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: need some help in serving static files inside a wsgi apps
Sebastian 'lunar' Wiesner schrieb: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 [ Diez B. Roggisch [EMAIL PROTECTED] ] I finally managed to work with static files with a little hack, but it's ugly because I'm reading each static file per request. How else should that work? Apache does that the same way. I guess, Apache does some kind of memory caching for files, which are often requested and small enough to fit into the system memory. May be, that's what the OP is referring to ... I'm not aware of that, and I even more seriously doubt it. Because caching is a complicated, domain-dependend subject that would *immediately* cry for configuration - e.g. caching strategies and such. And a common idiom for apache caching is to use Squid as reverse proxy. Which wouldn't be the case would apache cache by itself. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: access interactive namespace from module (shared namespace?)
On Sun, 25 May 2008 03:32:30 -0700 (PDT), [EMAIL PROTECTED] wrote: Thanks for the reply, Of course the suggested solution is working and good, but a bit complicated. The module/function where i need to access the variable value from the interactive shell is burried quite deep and I would nedd to hand the locals() quite often from one module to another. Furthermore it makes the call function slightly more complicated, as the locals()-argunment has to be given every time. I was hoping for something a bit different: If I wanted to access a value b from another module utest2.py, I would simply need to type in utest.py: import utest2; print 2*utest2.b Isn't there a name for the interactive namespace (like here the utest2), which I can use to access the variable without handing the whole dictionary? utest.py import __main__ def doit(): print 2*__main__.a Cheers, Ulrich David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list
Getting a set of lambda functions
Hi, I try to get a set of lambda functions that allows me executing each function code exactly once. Therefore, I would like to modify the set function to compare the func_code properties (or the lambda functions to use this property for comparison). (The reason is that the real function list is quite large ( 1E5), there are only few functions with non-equal code and the order of execution is not important.) How can I achieve this? func_strings=['x', 'x+1', 'x+2', 'x'] funclist = [eval('lambda x:' + func) for func in func_strings] len(funclist) 4 len(set(funclist)) 4 funclist[0].func_code == funclist[3].func_code True funclist[0] == funclist[3] False Thanks in advance Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a set of lambda functions
On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: Hi, I try to get a set of lambda functions that allows me executing each function code exactly once. Therefore, I would like to modify the set function to compare the func_code properties (or the lambda functions to use this property for comparison). (The reason is that the real function list is quite large ( 1E5), there are only few functions with non-equal code and the order of execution is not important.) How can I achieve this? func_strings=['x', 'x+1', 'x+2', 'x'] funclist = [eval('lambda x:' + func) for func in func_strings] len(funclist) 4 len(set(funclist)) 4 funclist[0].func_code == funclist[3].func_code True funclist[0] == funclist[3] False Thanks in advance Martin Maybe make a set of code objects? func_code_set = set([f.func_code for f in funclist]) funclist = [] for fc in func_code_set: f = lambda x: x f.func_code = fc funclist.append(f) -- Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a set of lambda functions
On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: Hi, I try to get a set of lambda functions that allows me executing each function code exactly once. Therefore, I would like to modify the set function to compare the func_code properties (or the lambda functions to use this property for comparison). (The reason is that the real function list is quite large ( 1E5), there are only few functions with non-equal code and the order of execution is not important.) How can I achieve this? func_strings=['x', 'x+1', 'x+2', 'x'] funclist = [eval('lambda x:' + func) for func in func_strings] len(funclist) 4 len(set(funclist)) 4 funclist[0].func_code == funclist[3].func_code True funclist[0] == funclist[3] False Thanks in advance Martin Maybe make a set of code objects? func_code_set = set([f.func_code for f in funclist]) funclist = [] for fc in func_code_set: f = lambda x: x f.func_code = fc funclist.append(f) -- Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
On May 25, 9:47 am, [EMAIL PROTECTED] (Ville M. Vainio) wrote: Fuzzyman [EMAIL PROTECTED] writes: Perhaps a lint-like validation tool would be optimal for this problem... So we can refuse to execute their code if they use private APIs? No, but it could complain and point out the exact offending lines, pointing their development effort to right direction. Proxying so that we can really hide our internal APIs is a better solution. How about pyprotocols and other interface packages? We're using IronPython. I haven't looked at pyprotocols but I know the Zope interface package is at least partly written in C. Our spreadsheet object model is very 'performance sensitive', so that's a consideration. We should definitely explore the prior art in this area before we implement anything ourselves. Thanks Michael Foord http://www.ironpythoninaction.com/ Proxying is pretty workable too, and it easily makes sense that the official API objects should be different from the logic executing objects. -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
On Sun, May 25, 2008 at 3:10 AM, [EMAIL PROTECTED] wrote: l=list(s) l.sort() l ['a', 'b', 'c'] hth, Rares sets dont seem to be so good because there is no way to iterate them. s.pop() remove and return an arbitrary element from s; raises KeyError if empty i dont want to remove i just want to get the string that is stored there. The only requirement for iterating through something is that it defines an __iter__ method, which set does. This means you can use iter(a_set) to get your iterator, or just use for i in a_set to iterate automatically. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a set of lambda functions
On Sun, 25 May 2008 12:14:25 + (UTC) Ivan Illarionov [EMAIL PROTECTED] wrote: On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: Maybe make a set of code objects? func_code_set = set([f.func_code for f in funclist]) funclist = [] for fc in func_code_set: f = lambda x: x f.func_code = fc funclist.append(f) Works for me. Thanks Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: access interactive namespace from module (shared namespace?)
Thanks a lot to all! Apart from obtaining the solution I was searching for, I learned a lot by studying your answers! Cheers, Ulrich -- http://mail.python.org/mailman/listinfo/python-list
Re: need some help in serving static files inside a wsgi apps
Diez B. Roggisch [EMAIL PROTECTED] wrote: Sebastian 'lunar' Wiesner schrieb: I guess, Apache does some kind of memory caching for files, which are often requested and small enough to fit into the system memory. May be, that's what the OP is referring to ... I'm not aware of that, and I even more seriously doubt it. Because caching is a complicated, domain-dependend subject that would *immediately* cry for configuration - e.g. caching strategies and such. This is available in current apache with mod_file_cache (for an explicitly configured list of files). I think the circumstances where you'd want to use it are quite rare. -M- -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
On May 24, 7:22 am, André [EMAIL PROTECTED] wrote: I can't relate to anyone that want to oppose a change that would give more freedom to a programmer. André Well, you can already do that. Or anything else you want. It's not all that difficult to change the algorithms in the unittest package _without_ patching the code. How to do it could be better documented, granted. For my major project (Python FIT) I've got my own test case extraction mechanism that doesn't depend on patching the code. It lets me use any name I want - that is, it doesn't depend on any kind of pattern match. (It also avoids looking in subclasses for tests.) I find the naming freedom to be quite useful in thinking about the test case. I really don't care what the OP does in his own projects. My objection is that, if it goes into the standard library, is that it passes a signal that it's good practice to allow dependencies between tests. It most definitely is _not_ good practice. I like the technique of looking at the line numbers to get the declaration order; it ought to be documented somewhere. The proper place for this is either a recipe ( http://aspn.activestate.com/ASPN/Cookbook/Python/ ) or a note in the documentation with a caveat that it's not good practice, but it may be useful in some circumstances. John Roth -- http://mail.python.org/mailman/listinfo/python-list
Coverage checker: Coverage.py or pycover or ?
Looking for feedback from people using a coverage checking utility. I've found two - wondering if there's any feature that would recommend one of these utilities vs. another (or argue for the use of both utilities). Coverage.py http://nedbatchelder.com/code/modules/coverage.html and Pycover http://www.geocities.com/drew_csillag/pycover.html Thanks, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: need some help in serving static files inside a wsgi apps
Matthew Woodcraft schrieb: Diez B. Roggisch [EMAIL PROTECTED] wrote: Sebastian 'lunar' Wiesner schrieb: I guess, Apache does some kind of memory caching for files, which are often requested and small enough to fit into the system memory. May be, that's what the OP is referring to ... I'm not aware of that, and I even more seriously doubt it. Because caching is a complicated, domain-dependend subject that would *immediately* cry for configuration - e.g. caching strategies and such. This is available in current apache with mod_file_cache (for an explicitly configured list of files). I think the circumstances where you'd want to use it are quite rare. As I said - explicit configuration is needed. And of course apache it's module system are flexible enough to allow caching as add-on. But Sebastian speculated about some behind the scenes automatic caching. Which apparently isn't there. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: raising an exception when multiple inheritance involves same baseThank
Thanks very much, Arnaud. That is exactly the hint I needed. Since it is not multiple inheritance per se I prohibit but only multiple inheritance involving more than one HocObject class, I replaced your len(bases) 1 test with code m = False for b in bases : if hasattr(b, '__mro__'): for bb in b.__mro__ : if bb == MetaHocObject.ho : if m == True: raise Exception(Inheritance of multiple HocObject not allowed) m = True /code to get class A(HocObject): pass class B(object): pass class C(): pass class D(C, B, HocObject): pass # ok class D(C, A, HocObject): pass # fail When I fold this idea into my code I may even try to eliminate the class factory aspect of class Foo(hclass(h.Vector)) in favor of class Foo(h.Vector) Thanks again, Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
In article [EMAIL PROTECTED], John Roth [EMAIL PROTECTED] wrote: I really don't care what the OP does in his own projects. My objection is that, if it goes into the standard library, is that it passes a signal that it's good practice to allow dependencies between tests. It most definitely is _not_ good practice. The OP stated that he wants the tests run in a given order. People are assuming that's because he has dependencies between his tests. Maybe he just wants them run in order because it's easier to understand the output in a certain order. For example, I'm currently working on some low-level data marshalling code (in another language). This is the sort of stuff which the Python struct module handles -- converting between internal form and network representation. There is a logical hierarchy of complexity. Handling characters is easier than handling ints, which is easier than floats, which is easier than doubles, and so on (arrays, sets and other composite types). If I was porting this to a new platform, I would want the unit tests to run in a logical order of simple to complex. If some assortment of tests failed, you want to start debugging the problem on the least complex data types. If the tests run in a specific order, it's easier to see where to start. It's not that any test depends on any other test to run, in the sense that there's some shared state between them. It's just that from a human factors point of view, there's a logical order to run them in. In fact, from a protocol point of view, some of the types really do depend on each other. We send counted strings, for example, so we can't send a string until we know how to send an int (for the string length). If the first test that fails is the string test, I know right off that the problem is not in how we send ints, because that test ran already and it passed. Earlier, I gave another example of wanting tests to be run in the same order as some externally controlled set of functional requirements. Again, not because the tests have inter-dependencies, but because it just makes it easier to interpret the results. Don't assume inter-test dependencies (which I agree are a Bad Thing) is the only reason you want to run tests in a specific order. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python database 'frontends', what's available?
Mike Driscoll [EMAIL PROTECTED] wrote: On May 23, 1:59 pm, [EMAIL PROTECTED] wrote: I'm desperately trying to move a Microsoft Access database application (a simple accounts system I wrote myself) to Linux. Python is one of my preferred programming laguages so I wonder if there are any good Python 'frameworks' for writing database applications, in particular I need good reporting and forms writing facilities. The basic database and logic/arithmetic seem fairly simple to me. -- Chris Green You might take a look at Dabo. It's made for databases and is pretty cool. http://dabodev.com/ Not sure what else is out there. Dabo looks very interesting, thank you! -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
Diez B. Roggisch [EMAIL PROTECTED] wrote: I agree that tests should not depend on each other, but sometimes it's still useful to have the tests run in a certain order for reporting purposes. Then sort your report. Seriously. A test-outpt shoud be in a way that delimits individual testresults in a way that makes them easily extractable. Then if you want them to be ordered for e.g. diff'ing - sort them. Diez Here's an example of why *running* tests in order can make sense. You could have a bunch of tests of increasing complexity. The first bunch of tests all run in a few seconds and test some basic functionality. From experience, you also know that these are the tests that are most likely to fail as you port to a new environment. There's also some tests which take a long time to run. If the basic stuff that's being tested by the earlier tests doesn't work, there's no way these tests could pass, but they still take a long time to fail. It's really handy to have the simple tests RUN first. If you see they fail, you can cancel the rest of the test run and get on with fixing your code faster. It's a good thing to make it easy to do things the right way, and difficult to do things the wrong way. The danger is when you let your pre-conceived notions of right and wrong trick you into making it difficult to do things any way but YOUR way. So far, the strongest argument I've seen against the OP's idea is that it's not portable to Iron Python. That's a legitimate argument. All the rest of the You're not supposed to do it that way arguments are just religion. -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
On May 25, 3:13 pm, Roy Smith [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], John Roth [EMAIL PROTECTED] wrote: I really don't care what the OP does in his own projects. My objection is that, if it goes into the standard library, is that it passes a signal that it's good practice to allow dependencies between tests. It most definitely is _not_ good practice. The OP stated that he wants the tests run in a given order. People are assuming that's because he has dependencies between his tests. Maybe he just wants them run in order because it's easier to understand the output in a certain order. No, we're pointing out that running tests in a specific order can introduce hidden dependencies without you being aware of it. Whilst this is already the case with unittest, further enshrining it in the standard library is a bad idea. As mentioned elsewhere, providing a better reporting mechanism is probably the way to get better understandable output. Micahel Foord http://www.ironpythoninaction.com/ For example, I'm currently working on some low-level data marshalling code (in another language). This is the sort of stuff which the Python struct module handles -- converting between internal form and network representation. There is a logical hierarchy of complexity. Handling characters is easier than handling ints, which is easier than floats, which is easier than doubles, and so on (arrays, sets and other composite types). If I was porting this to a new platform, I would want the unit tests to run in a logical order of simple to complex. If some assortment of tests failed, you want to start debugging the problem on the least complex data types. If the tests run in a specific order, it's easier to see where to start. It's not that any test depends on any other test to run, in the sense that there's some shared state between them. It's just that from a human factors point of view, there's a logical order to run them in. In fact, from a protocol point of view, some of the types really do depend on each other. We send counted strings, for example, so we can't send a string until we know how to send an int (for the string length). If the first test that fails is the string test, I know right off that the problem is not in how we send ints, because that test ran already and it passed. Earlier, I gave another example of wanting tests to be run in the same order as some externally controlled set of functional requirements. Again, not because the tests have inter-dependencies, but because it just makes it easier to interpret the results. Don't assume inter-test dependencies (which I agree are a Bad Thing) is the only reason you want to run tests in a specific order. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding icons for Apps
Sanoski wrote: This might be a dumb question. I don't know. I'm new to all this. How do you find icons for your programs? All GUI applications have cool icons that represent various things. For instance, to save is often represented as a disk, etc. You know, the small little picture references that give meaning to the phrase 'Graphical User Interface'. But I'm not a graphics artist! Drawing is simply one talent that skipped me completely. Where can I find icons to use with my programs? I don't even know how to search for them, because I'm not sure how to word it. I tried Googling various things: icons, software graphics, application icons, custom graphics, etc, etc. But I'm not getting much luck here you guys. Also, besides just finding a collection of various pre-made icons, who would I talk to to make me some original custom made icons? I'll look for hours and find one or two places, but they never respond to my messages, so I figure they must not do that kind of art work. I'm looking for both: a collection of graphics and some place (or someone) that can make custom original graphics. The latter is just for future reference. The more important one is the former, because I can't even afford to pay for originals right now. But maybe I will soon, so it would be nice to have a resource. Thanks in advance, Joshua http://tango.freedesktop.org/Tango_Desktop_Project http://www.oxygen-icons.org/ http://everaldo.com/crystal/ -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
Here's an example of why *running* tests in order can make sense. You could have a bunch of tests of increasing complexity. The first bunch of tests all run in a few seconds and test some basic functionality. From experience, you also know that these are the tests that are most likely to fail as you port to a new environment. There's also some tests which take a long time to run. If the basic stuff that's being tested by the earlier tests doesn't work, there's no way these tests could pass, but they still take a long time to fail. It's really handy to have the simple tests RUN first. If you see they fail, you can cancel the rest of the test run and get on with fixing your code faster. I don't see this as something that can be solved by ordering tests - *especially* not on a per-method-level as the OP suggested, because I tend to have test suites that span several files. Instead when I've been in the situation that you describe before, I resorted to an approach where I annotated tests as long or short-running (or any other criteria), and then ran the tests that were appropriate. For example, post-commit-tests needed to be short, as otherwise the feedback came to slow. Annotation could be done explicit, or implicit by grouping tests together that had the desired property. However, as I prefer tests that share e.g. the same module to test the same functionality, I rather have an annotation mechanism. So *if* anything should be changed IMHO it would be the introduction of a tagging system or something equivalent, together with a selection mechanism based on that. It's a good thing to make it easy to do things the right way, and difficult to do things the wrong way. The danger is when you let your pre-conceived notions of right and wrong trick you into making it difficult to do things any way but YOUR way. So far, the strongest argument I've seen against the OP's idea is that it's not portable to Iron Python. That's a legitimate argument. All the rest of the You're not supposed to do it that way arguments are just religion. So far the reasons for introducing them haven't been compelling either. Neither does it work over several testsuites, nor is it the only thing that can order *results*, which you (rightly so) claimed as being useful. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
In fact, from a protocol point of view, some of the types really do depend on each other. We send counted strings, for example, so we can't send a string until we know how to send an int (for the string length). If the first test that fails is the string test, I know right off that the problem is not in how we send ints, because that test ran already and it passed. Earlier, I gave another example of wanting tests to be run in the same order as some externally controlled set of functional requirements. Again, not because the tests have inter-dependencies, but because it just makes it easier to interpret the results. Don't assume inter-test dependencies (which I agree are a Bad Thing) is the only reason you want to run tests in a specific order. Both these points can be solved by application of output ordering or even better using groups of tests inside individual modules that test e.g. basic functionality. Selecting these to run first before trying to run more complicated tests is much more senseful than just letting a single test run in a determined order. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: need some help in serving static files inside a wsgi apps
I guess, Apache does some kind of memory caching for files, which are often requested and small enough to fit into the system memory. May be, that's what the OP is referring to ... I'm not aware of that, and I even more seriously doubt it. Because caching is a complicated, domain-dependend subject that would *immediately* cry for configuration - e.g. caching strategies and such. This is available in current apache with mod_file_cache (for an explicitly configured list of files). I think the circumstances where you'd want to use it are quite rare. Interestingly enough, this *doesn't* do memory caching for files. Instead, it either keeps the file handle open, so you can seek to the beginning of the file on the next request (avoiding the directory lookup), or you can mmap the file. However, even if you mmap the file, it is still the operating system's choice whether or not to cache the file contents in memory. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
RE: unittest: Calling tests in liner number order
On Behalf Of Roy Smith You could have a bunch of tests of increasing complexity. The first bunch of tests all run in a few seconds and test some basic functionality. From experience, you also know that these are the tests that are most likely to fail as you port to a new environment. There's also some tests which take a long time to run. If the basic stuff that's being tested by the earlier tests doesn't work, there's no way these tests could pass, but they still take a long time to fail. How about something like this: def run_quickies(): # run the quick, i.e. actual unit tests # located in folder ./unit_tests/ def run_long_ones(): # Run function tests, integration tests, what have you # located in folder ./integration_tests/ def whole_shebang(): run_quickies() run_long_ones() Now you do something like run the unit tests every time a file is saved, and run the whole shebang nightly and every time a build is performed. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list
SocketServer, its offspring, and threads
Hello, I have a small wxPython application. Today I was trying to add some RPC capability to it, so I implemented an instance of SimpleXMLRPCServer that runs in a separate thread when invoked and answers requests. All went fine until I realized that I have to sometimes stop the server - which is where I ran into a problem. Python threads can not be killed after they've been started. They can be kindly requested to end, but it's up to the thread itself to decide when it wants to finish. At least this is my understanding. It probably makes sense, because threads can hold resources which can't just be dropped suddenly, and have to be cleaned in a proper manner. (Does this sound like the truth ?) Anyway, this creates a problem because SimpleXMLRPCServer likes to block and never return. I dug deeper and found out that all offspring of SocketServer can only handle requests in a blocking manner. Even if you call handle_request( ) and not serve_forever(), it will block until a request is received and handled. This means that a SocketServer object running in a thread blocks the thread, and this thread can not be stopped. Is there any graceful solution to this problem ? I suppose I can use sockets in non-blocking mode, or use select(), but this will mean I will have to implement my server with raw sockets and not a handy helper like SocketServer. For the XML-RPC server I want this is a headache, as I will probably have to implement my own XML- RPC server based on raw non-blocking sockets. Thanks in advance for any ideas and suggestions Eli -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: Calling tests in liner number order
Diez B. Roggisch [EMAIL PROTECTED] wrote: I don't see this as something that can be solved by ordering tests - *especially* not on a per-method-level as the OP suggested, because I tend to have test suites that span several files. unittest already runs multiple test suites in the order you specify (which is another clue that running tests in order is not evil). I suspect unittest's choice of alphabetical order for the tests within a suite is more an artefact of its original Java implementation than anything else. -M- -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
En Sun, 25 May 2008 03:37:00 -0300, [EMAIL PROTECTED] escribió: im writing a webcrawler. after visiting a new site i want to store it in alphabetical order. so obv i want fast insert. i want to delete duplicates too. which datastructure is best for this? Use a list, and the bisect module to keep it sorted: py import bisect py def insert_nodupes(slist, item): ... i = bisect.bisect_left(slist, item) ... if i=len(slist) or slist[i] != item: ... slist.insert(i, item) ... py items = [] py insert_nodupes(items, 'link to some site') py insert_nodupes(items, 'another link') py insert_nodupes(items, 'third site') py insert_nodupes(items, 'another link') py items ['another link', 'link to some site', 'third site'] -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Pinging a machine from python
I tried pinging a machine from python using socket programming but could not do it. Is there any module which we can use to ping the machine like net::ping in perl or can you give me simple program. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding icons for Apps
Learn how to use Gimp, Make your own icons, of and from anything. You can use screen shots and picks from anywhere. Import your own photos and modify any pic however you want. Check them out, free download, tutorial. http://www.gimp.org jim-on-linux http://www.inqvista.com Sanoski wrote: This might be a dumb question. I don't know. I'm new to all this. How do you find icons for your programs? All GUI applications have cool icons that represent various things. For instance, to save is often represented as a disk, etc. You know, the small little picture references that give meaning to the phrase 'Graphical User Interface'. But I'm not a graphics artist! Drawing is simply one talent that skipped me completely. Where can I find icons to use with my programs? I don't even know how to search for them, because I'm not sure how to word it. I tried Googling various things: icons, software graphics, application icons, custom graphics, etc, etc. But I'm not getting much luck here you guys. Also, besides just finding a collection of various pre-made icons, who would I talk to to make me some original custom made icons? I'll look for hours and find one or two places, but they never respond to my messages, so I figure they must not do that kind of art work. I'm looking for both: a collection of graphics and some place (or someone) that can make custom original graphics. The latter is just for future reference. The more important one is the former, because I can't even afford to pay for originals right now. But maybe I will soon, so it would be nice to have a resource. Thanks in advance, Joshua http://tango.freedesktop.org/Tango_Desktop _Project http://www.oxygen-icons.org/ http://everaldo.com/crystal/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Assignment and comparison in one statement
On 19:14, sabato 24 maggio 2008 Johannes Bauer wrote: Well, I do not really see your point You wrote C statements and I felt that you were trying to apply to python interpreter. I think that a minimun of knoweledge on python grammar it's the base for doing some programming. If your examples were there only to explain your meaning, then I'm wrong here. -- http://mail.python.org/mailman/listinfo/python-list
Re: raising an exception when multiple inheritance involves same baseThank
On May 25, 8:37 am, Michael Hines [EMAIL PROTECTED] wrote: Thanks very much, Arnaud. That is exactly the hint I needed. Since it is not multiple inheritance per se I prohibit but only multiple inheritance involving more than one HocObject class, I replaced your len(bases) 1 test with code m = False for b in bases : if hasattr(b, '__mro__'): for bb in b.__mro__ : if bb == MetaHocObject.ho : if m == True: raise Exception(Inheritance of multiple HocObject not allowed) m = True /code to get class A(HocObject): pass class B(object): pass class C(): pass class D(C, B, HocObject): pass # ok class D(C, A, HocObject): pass # fail When I fold this idea into my code I may even try to eliminate the class factory aspect of class Foo(hclass(h.Vector)) in favor of class Foo(h.Vector) Thanks again, Michael Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). -- Paul for cls in (A,B,C,D): seen = set() try: bases = cls.__bases__ for b in bases: if hasattr(b,__mro__): for m in b.__mro__: if m in seen: raise Exception(diamond multiple inheritance) seen.add(m) except Exception, e: print cls,has diamond MI else: print cls,is ok -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
Rares Vernica [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | l=list(s) | l.sort() This can be condensed to l = sorted(s) | l | ['a', 'b', 'c'] -- http://mail.python.org/mailman/listinfo/python-list
Python web development that resembles PHP or classic ASP
Hi All, I have been developing websites in classic asp using VB script for a long while now. Due to the fact that I also took a detour to developing ColdFusion, and the fact the companies I work(ed) for never had time or money for courses, I am now in the awkward position that I am -still- developing classic ASP. In it, I have become quite resourceful, I wrote a framework using WSC (windows scripting components) to separate logic from presentation, and my display pages use almost no logic, except for the loops and variables I need to build my pages. I have a three-tier setup and all business logic is in separate WSC files. The framework even uses an ORM for access to the tables of my database. This works like a charm. It makes classic ASP code maintainable, it makes working in classic ASP very pleasant actually and it makes our customers very happy. The problem is that classic asp is now a dead language, I need to modernize and fast! Although the arguments some people make against it are not valid for me (spaghetti code, unmaintainable, slow), I still see that there is little to no support for it anymore. The most logical way to update my knowledge to something more modern, would be to dive into ASP.NET. I considered that for a long time, but there are some problems with this: 1. I love the control I have over my html using inline, template-based vbscript. ASP.NET's web forms really sound like a very bad idea, also the approach Microsoft takes in trying to make a stateless web-app seem like a statefull application is IMHO a burden. I think webapps are inherently different than desktop apps, and should be programmed as such. 2. Who says Microsoft isn't going to pull the plug on VB.NET in a while or make a drastic change like they did from asp to asp.net again, some time in the future? 3. I like the rapid development I can do in a dynamic, loosely typed language like vbscript. The performance-bottleneck of a site is mostly in the database-access and the http-calls and I think writing all of the declarations and types for a strong-typed language is overkill for a webapp. So that's when I started looking at other dynamic languages for webdevelopment. I looked at Ruby on Rails and at the different web- frameworks that are available for Python. The biggest problem there for me is that the MVC type frameworks that are currently very popular are also not what I'm looking for. I like having my directory tree conform to the structure of my website, so the Controller part of the MVC style of development is something I wouldn't want. What I -would- like is a separation of code and display logic (so being able to include libraries in a page) and being able to intermix code directly into the HTML. As Python would be the language I prefer over Ruby, I thought I'd ask here to see if anyone in the Python community knows if such a development-framework exists in Python. For example, does IronPython also use the same web forms approach as asp.net using VB? The frameworks I looked at (Django, Pylons) seem to be able to use different templating engines, does that mean it's just a question of finding the right one? Also, for Python there is also the problem of meaningful indentation. I'm not even sure if it's possible to use Python directly inside HTML, because indentation would be at the very least tricky to maintain. I'm kind of hoping here that there are some solutions to these problems available in Python. Any help would be greatly appreciated. Kind regards, Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python web development that resembles PHP or classic ASP
Hi Erik, As far as I know the only full web framework that works with a primarily inline style is spyce, which is not currently under active development. I used it for a while and it was the first python framework I used. I think it's pretty good, if a little bit of an underdog. That said, using a controller based framework it would be pretty easy to emulate what you are wanting. Find a templating language that fits what you want, build the controller to map to the directories, and pass into templates all the objects that are needed to interact (response/request objects etc) and you're set. -- http://mail.python.org/mailman/listinfo/python-list
UTF problem?
I am trying to set up Linux printing via Windows XP and using this HOWTO: http://justin.yackoski.name/winp/ I have one problem. When I send a file via CUPS to the windows spool directory dirwatch.py (http://justin.yackoski.name/winp/dirwatch.txt) dies and gives: UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 77: ordinal not in range (128) I think that this has something to do with UTF-8 what I do not know is how to get over it? So could someone please help me to get dirwatch.py script to understand my filenames (which, btw, do not have any non-ascii symbols, and will work if I manually copy-rename them). Thanks in advance! Vesa-Matti -- Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * * mailto:[EMAIL PROTECTED] * Music seems to help the pain * Lecturer, mathematics education * R.I.P. Syd, my hero * University of Oulu, Finland * * * * * * * * * * * * * * * * * -- http://mail.python.org/mailman/listinfo/python-list
Re: raising an exception when multiple inheritance involves same baseThank
Sorry I lost the original post. Paul McGuire [EMAIL PROTECTED] writes: On May 25, 8:37 am, Michael Hines [EMAIL PROTECTED] wrote: Thanks very much, Arnaud. That is exactly the hint I needed. Since it is not multiple inheritance per se I prohibit but only multiple inheritance involving more than one HocObject class, I replaced your len(bases) 1 test with code m = False for b in bases : if hasattr(b, '__mro__'): for bb in b.__mro__ : if bb == MetaHocObject.ho : if m == True: raise Exception(Inheritance of multiple HocObject not allowed) m = True /code I think you don't need to look at the bases' mros, just use issubclass(), e.g. (untested): if sum(1 for b in bases if issubclass(b, HocObject)) 1: raise Exception(Multiple inheritance from HocObject) to get class A(HocObject): pass class B(object): pass class C(): pass class D(C, B, HocObject): pass # ok class D(C, A, HocObject): pass # fail When I fold this idea into my code I may even try to eliminate the class factory aspect of class Foo(hclass(h.Vector)) in favor of class Foo(h.Vector) Thanks again, Michael Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). -- Paul for cls in (A,B,C,D): seen = set() try: bases = cls.__bases__ for b in bases: if hasattr(b,__mro__): for m in b.__mro__: if m in seen: raise Exception(diamond multiple inheritance) seen.add(m) except Exception, e: print cls,has diamond MI else: print cls,is ok All new-style classes descend from object, so any new-style class with at least two bases makes a diamond! For example the first version of class D above inherits twice from object, so it will be caught. OTOH, old-style classes don't have an __mro__, so this will not catch diamond inheritance of old-style classes. E.g class A: pass class B(A): pass class C(A): pass class D(B, C): pass -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On May 23, 2:50 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Brad a écrit : cm_gui wrote: Python is slow. It ain't C++, but it ain't a punch card either... somewhere in between. I find it suitable for lots of stuff. I use C++ when performance really matters tho... right tool for the job. Learn a good interpreted language (Pyhton) and a good compiled language (C or C++) LordHaveMercy(tm). Could you guys please learn what you're talking about? 1/ being interpreted or compiled (for whatever definition of these terms) is not a property of a language, but a property of an implementation of a language. 2/ actually, all known Python implementations compile to byte-code. flamingmode useofbrain=alotforaflame LordHaveMercy(violatingsomeonesTM). Couldn't you understand that a CPU INTERPRET bytes of instruction, and that means ALL languages is interpreted in one stages or another, some languages' (implementation) is translated/compiled into an intermediate language/bytecode like most Python or C/C++ or Java implementations, some language implementation interprets the language directly (like Javascript). The difference between C and Python (in their regular implementation) is WHO interprets it, most C/C++'s implementation is interpreted directly by the CPU, all Python's implementation is interpreted by a VM. Saying a language implementation is interpreted is nonsense as all languages implementation is interpreted either by a VM or by CPU or an interpretator, but we do have a semantic agreement that calling a language interpreted means it is NOT interpreted by the CPU directly, some minority have their own agreement that a language (implementation) is interpreted when it is never translated into an intermediate language/bytecode, you fall into this second group, which actually uses the wrong terminology but do have some followers. Don't forget that language is all about what the _consensus_ says, not what the dictionary says. Brad doesn't use any terms incorrectly, he stated that Python is interpreted, which is true, since in all python implementation, Python's bytecode is interpreted by a VM. He also states that C/C++ is compiled which is also true as most if not all C++ implementation have a stage where it is translated into an intermediate language/bytecode. /flamingmode -- http://mail.python.org/mailman/listinfo/python-list
Re: Code correctness, and testing strategies
Hi again. Taking the advice of numerous posters, I've been studying BDD further. I spent a while looking for a Python library which implemented BDD in Python similar to jbehave, as described by Dan North on this page: http://dannorth.net/introducing-bdd. I did find a few, but they either had awful-looking syntax, or they were overly-complicated. So I decided that using regular unit tests (via nosetest) was good enough, even if it doesn't have support for stories, scenarios, givens, etc, and it uses words with Test in it instead of Behavior. One thing I just tried was to put together a basic stack class following BDD, with nosetest. I got the idea from this page: http://www.ibm.com/developerworks/web/library/j-cq09187/index.html It was an interesting exercise, and I'm encouraged to try it further. I ended up with these 2 modules: ==test_stack.py from nose.tools import raises import stack class TestStackBehaviour: def setup(self): self.stack = stack.Stack() @raises(stack.Empty) def test_should_throw_exception_upon_pop_without_push(self): self.stack.pop() def test_should_pop_pushed_value(self): self.stack.push(12345) assert self.stack.pop() == 12345 def test_should_pop_second_pushed_value_first(self): self.stack.push(1) self.stack.push(2) assert self.stack.pop() == 2 def test_should_leave_value_on_stack_after_peep(self): self.stack.push(999) assert self.stack.peep() == 999 assert self.stack.pop() == 999 def test_should_pop_values_in_reverse_order_of_push(self): self.stack.push(1) self.stack.push(2) self.stack.push(3) assert self.stack.pop() == 3 assert self.stack.pop() == 2 assert self.stack.pop() == 1 @raises(stack.Empty) def test_peep_should_fail_when_stack_is_empty(self): self.stack.peep() def test_should_be_empty_when_new(self): assert len(self.stack) == 0 ==stack.py class Empty(Exception): Thrown when a stack operation is impossible because it is empty pass class Stack: Basic implementation of a stack def __init__(self): self._data = [] def push(self, value): Push an element onto a stack self._data.append(value) def pop(self): Pop an element off a stack try: return self._data.pop() except IndexError: raise Empty def peep(self): Return the top-most element of the stack try: return self._data[-1] except IndexError: raise Empty def __len__(self): Return the number of elements in the stack return len(self._data) === Does the above look like a decent BDD-developed class? Is it ok that there are no 'scenarios', 'stories', 'having', 'given', etc references? Some pages suggest that you should use so-called contexts (EmptyStackContext, StackWithOneElementContext, FullStackContext, AlmostFullStackContext, etc). Would you normally start with a basic TestStackBehavoiur class, and when Stack becomes more complicated, split the tests up into TestEmptyStackContext, TestStackWithOneElementContext, etc? Another thing I noticed is that some of my test cases were redundant. Would you normally leave in the redundant tests, or remove the ones which are included in the more general test? Also, I have another question. How do you unit test event loops? eg: Your app is a (very basic) service, and you want to add some functionality (following BDD principles) Here's an example unit test: class TestServiceBehavior: def setup(self): ... def test_handles_event_xyz(self): ... If your service is normally single-threaded, would your unit test need to start the service in a separate thread to test it? Another method would be to update the event loop to enable unit testing. eg only iterate once if a 'being_tested' variable is set somewhere. None of the above are ideal. What is a good way to unit test event loops? David. -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
On May 22, 12:28 pm, NC [EMAIL PROTECTED] wrote: On May 21, 1:10 pm, notbob [EMAIL PROTECTED] wrote: So, here's my delimna: I want to start a blog. Yeah, who doesn't. Yet, I want learn the guts of it instead of just booting up some wordwank or whatever. Here's a simple computation to consider... WordPress' codebase is approximately a megabyte of PHP code and megabyte of JavaScript code. Assuming that the average line of that code is 50 characters long, you are looking at 20,000 lines of code in PHP and as many in JavaScript. Based on the notion that the average developer out there writes 100 lines a day, either you're in for a two-year project or your product is going to have seriously reduced functionality compared to something that's been freely available for years. What's your choice? Nope, the core functionality of a blogging software could be replicated in just a few lines of PHP codes, in the range of tens to hundreds of lines. If you're creating your own blogging software, you wouldn't seriously think you'd recreate all those things such as pingbacks, commenting system, etc, etc, etc. No, you'd start with some basic core functionalities: a few simple server side includes only. -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
[EMAIL PROTECTED] wrote: im writing a webcrawler. after visiting a new site i want to store it in alphabetical order. so obv i want fast insert. i want to delete duplicates too. which datastructure is best for this? Keep the data redundantly in two data structures. Use collections.deque() to append and remove as in a queue, and set() to find duplicates. Again, no ordering, but very fast insert/delete/dup-check. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Pinging a machine from python
[ Prasanth [EMAIL PROTECTED] ] I tried pinging a machine from python using socket programming but could not do it. Is there any module which we can use to ping the machine like net::ping in perl or can you give me simple program. At least on linux pinging requires raw sockets since there is no syscall for sending ICMP packages. Raw sockets in turn require special privileges. Therefore its best to use the os command _ping_, this limits the use of priviledges to the required part and you don't have to deal with priviledges (ping has suid bit set). net::ping will most likely do the same. -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
On May 23, 5:14 am, inhahe [EMAIL PROTECTED] wrote: I don't like php. I tried it once and I had it sort a list, but the list was apparently too long for its sorting function because it just sorted the first so-many elements of it and left the rest in order, and didn't generate any error. I like a language that's actually determined by what you tell it to do. I hear it has a lot of security issues too. I'm not sure that php *runs* faster than python, having seen benchmarks, but it certainly loads faster. Maybe not so much of a difference once python25.dll is already in the cache though (speaking from a windows perspective). because when i load a program it can take a while but it's pretty quick if i'd just loaded one recently. but you don't necessarily have to load python for each page rendering anyway. I like the Python language a lot better than php. but I just really like Python. php mixes html and code out-of-the-box (sort of.. i guess it's more like a reversal of which one is explicit)... if you use Python you should look into a 'templating engine' like mako. i use cheetah, but mako is supposed to be better. i think Python is the easiest language to learn, with the possible exception of qbasic (just because making multidimensional arrays in python isnt that obvious, although maybe it is using numpy, i've never tried it). Python isn't as easy as basic if you use/have to read the more advanced features, but those aren't even available in basic. so I find it a comfortable learning curve. You should see Basic's file operation syntax, ugly and hackish. All those #1, #2, etc is ugly and unintuitive. That's why I've always avoided anything related to file in Basic (no hard feelings to Basic programmers, my first language is Basic and I'm pretty good at it except for anything related with files). In python, file read is as simple as open('path', 'mode'), and the for-loop can easily loop the file object. -- http://mail.python.org/mailman/listinfo/python-list
Re: raising an exception when multiple inheritance involves same baseThank
En Sun, 25 May 2008 13:32:39 -0300, Paul McGuire [EMAIL PROTECTED] escribió: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). for cls in (A,B,C,D): seen = set() try: bases = cls.__bases__ for b in bases: if hasattr(b,__mro__): for m in b.__mro__: if m in seen: raise Exception(diamond multiple inheritance) seen.add(m) except Exception, e: print cls,has diamond MI else: print cls,is ok I think you should exclude the `object` class from the test, because all new-style classes inherit from it and *every* case of multiple inheritance forms a diamond. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
On May 22, 3:10 am, notbob [EMAIL PROTECTED] wrote: I'm not posting this just to initiate some religious flame war, though it's the perfect subject to do so. No, I actaully want some serious advice about these two languages and since I think usenet is the best arena to find it, here ya' go. So, here's my delimna: I want to start a blog. Yeah, who doesn't. Yet, I want learn the guts of it instead of just booting up some wordwank or whatever. I started to learn python, but heard php was easier or faster or more like shell scripting or... fill in the blank. Anyway, so I change over to learning php. Then I run across that blog, Coding Horror, and start reading articles like this: http://www.codinghorror.com/blog/archives/001119.html Now what? Go back to python. Soldier on with php? What do I know? Not much. I can setup mysql and apache,, but don't know how to use 'em, really. I use emacs and run slackware and can fumble my way through bash scripts, but I can't really write them or do lisp. I've taken basic basic and basic C, but am barely literate in html. Sometimes it seems overwhelming, but I persevere because it's more fun/challenging than video games, which bore me to tears. Well, that's my actual question, then. Is php really so bad I'm just wasting my time? Or is it really the quickest way to blog functionality? Would I be better served in the long run learning python, which claims to be easy as pie to learn/program (still looks hard to me). I admit I'm no code geek. But, I'm not completely brain dead, either, and I need something to keep my geezer brain sparking. What say ye? nb My advice? Mix a bit of both. PHP's pros is it's tight integration with HTML, it's really easy to slip small, short PHP snippets here and there. Server side includes for example, is a short one-liner, in python it would involve reading the original file, finding where and what to slip, then reading the include file then concatenates the files then send it to the requester, or you could setup an engine for you which might take some time and patience. On the other hand, python is a general-purpose language, and is a better designed language. Writing the blog back-end in Python is probably easier than in PHP while writing the interface-related codes is probably easier in PHP. You might also consider calling python code from the PHP. -- http://mail.python.org/mailman/listinfo/python-list
Beginner question
Hi, Just want to try mod_python but it is more complicated then I expected... I just followed the tutorial on: http://www.modpython.org/live/mod_python-2.7.8/doc-html/inst-testing.html E.g. URL = http://www.example.com/mptest.py It return ImportError: No module named mptest 1. If I removed addHandler mod_python .py and PythonHandler mptest, I can see the SOURCE CODE 2. The PythonHandler mod_python.testhandler seems return correct result, showing I am using python 2.4.3 any idea? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
Lie wrote: On May 22, 12:28 pm, NC [EMAIL PROTECTED] wrote: On May 21, 1:10 pm, notbob [EMAIL PROTECTED] wrote: So, here's my delimna: I want to start a blog. Yeah, who doesn't. Yet, I want learn the guts of it instead of just booting up some wordwank or whatever. Here's a simple computation to consider... WordPress' codebase is approximately a megabyte of PHP code and megabyte of JavaScript code. Assuming that the average line of that code is 50 characters long, you are looking at 20,000 lines of code in PHP and as many in JavaScript. Based on the notion that the average developer out there writes 100 lines a day, either you're in for a two-year project or your product is going to have seriously reduced functionality compared to something that's been freely available for years. What's your choice? Nope, the core functionality of a blogging software could be replicated in just a few lines of PHP codes, in the range of tens to hundreds of lines. If you're creating your own blogging software, you wouldn't seriously think you'd recreate all those things such as pingbacks, commenting system, etc, etc, etc. No, you'd start with some basic core functionalities: a few simple server side includes only. As he said - it's either a two man-year project or your product is going to have seriously reduced functionality. It looks like you are opting for the latter. Also, you still need to write the server-side includes. But they won't do nearly enough for everything WordPress does. -- == Remove the x from my email address Jerry Stuckle JDS Computer Training Corp. [EMAIL PROTECTED] == -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a set of lambda functions
On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote: I try to get a set of lambda functions that allows me executing each function code exactly once. Therefore, I would like to modify the set function to compare the func_code properties (or the lambda functions to use this property for comparison). With Ivan's approach, you lose access to the actual lambdas, so you need to create a new function and then modify its code object to actually call the code; this seems a little clunky to me. You might instead want to wrap the lambdas in an object that will do the comparison you want: class Code(object): def __init__(self, func): self._func = func def __cmp__(self, other): return cmp(self._func.func_code, other._func.func_code) def __call__(self, *args, **kwargs): return self._func(*args, **kwargs) func_set = set(Code(f) for f in funclist) -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF problem?
Vesa-Matti Sarenius wrote: I am trying to set up Linux printing via Windows XP and using this HOWTO: http://justin.yackoski.name/winp/ I have one problem. When I send a file via CUPS to the windows spool directory dirwatch.py (http://justin.yackoski.name/winp/dirwatch.txt) dies and gives: UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 77: ordinal not in range (128) I think that this has something to do with UTF-8 what I do not know is how to get over it? So could someone please help me to get dirwatch.py script to understand my filenames (which, btw, do not have any non-ascii symbols, and will work if I manually copy-rename them). Well you don't say what line it's dying on, but I would guess it's the line which says print full_filename (altho' it could be when it prints the output from gsprint.exe). In any case, \xa0 is a non-breaking space: code import unicodedata print unicodedata.name (u\xa0) /code so it's just possible that one of your filenames has a non-ascii char in it without your noticing? (Altho' I'd find that an odd character to include in a filename). ReadDirectoryChangesW is the Unicode version of the ReadDirectoryChanges API, so always returns Unicode objects even if there are no non-ascii chars in the filenames. To get round the problem in the immediate term, change both print lines to something like: print repr (full_filename) This will show exactly what's in the filename. To do the thing properly, you'll want to encode the filename to something standard, eg, sys.stdout.encoding or just utf8: print full_filename.encode (utf8) but since these are just info outputs I imagine you're not too bothered how they look. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
Stefan Behnel [EMAIL PROTECTED] writes: [EMAIL PROTECTED] wrote: im writing a webcrawler. after visiting a new site i want to store it in alphabetical order. so obv i want fast insert. i want to delete duplicates too. which datastructure is best for this? Keep the data redundantly in two data structures. Use collections.deque() to append and remove as in a queue, and set() to find duplicates. what about heapq for sorting? -- Rodrigo Lazo (rlazo) -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
Jerry Stuckle wrote: Lie wrote: On May 22, 12:28 pm, NC [EMAIL PROTECTED] wrote: On May 21, 1:10 pm, notbob [EMAIL PROTECTED] wrote: So, here's my delimna: I want to start a blog. Yeah, who doesn't. Yet, I want learn the guts of it instead of just booting up some wordwank or whatever. Here's a simple computation to consider... WordPress' codebase is approximately a megabyte of PHP code and megabyte of JavaScript code. Assuming that the average line of that code is 50 characters long, you are looking at 20,000 lines of code in PHP and as many in JavaScript. Based on the notion that the average developer out there writes 100 lines a day, either you're in for a two-year project or your product is going to have seriously reduced functionality compared to something that's been freely available for years. What's your choice? Nope, the core functionality of a blogging software could be replicated in just a few lines of PHP codes, in the range of tens to hundreds of lines. If you're creating your own blogging software, you wouldn't seriously think you'd recreate all those things such as pingbacks, commenting system, etc, etc, etc. No, you'd start with some basic core functionalities: a few simple server side includes only. As he said - it's either a two man-year project or your product is going to have seriously reduced functionality. It looks like you are opting for the latter. Also, you still need to write the server-side includes. But they won't do nearly enough for everything WordPress does. If the OP wants to learn the guts of the blog or to implement the blog from scratch, Python/Django would be a better choice than PHP. The reason is that he can reuse and customize existing high quality components for all these auth/auth, admin, comments, etc, etc, etc. Another reason is that Python and Django encourage very clean design while PHP is too often ends up in spaghetti SQL wrapped in spaghetti PHP wrapped in spaghetti HTML. 2 man/year in PHP == 2 man/week in Python/Django. And there are Python/Django blog applications that already do almost everything (and maybe more) that WordPress does. http://byteflow.su/ is one of them (IMHO the most promising). Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: Showing the method's class in expection's traceback
En Sun, 25 May 2008 06:15:45 -0300, Duncan Booth [EMAIL PROTECTED] escribió: Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 22 May 2008 07:55:44 -0300, Duncan Booth [EMAIL PROTECTED] escribió: It might be worth considering an alternative approach here: a formatted exception includes the relevant source lines (where possible). Just to note that the standard cgitb module already does that, among other things. Anywhere Python prints a traceback already does that. The 'alternative approach' I was suggesting was the part you snipped, i.e. extracting the enclosing class name from the source. Ah, sorry for the misunderstanding! -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
Ivan Illarionov wrote: Jerry Stuckle wrote: Lie wrote: On May 22, 12:28 pm, NC [EMAIL PROTECTED] wrote: On May 21, 1:10 pm, notbob [EMAIL PROTECTED] wrote: So, here's my delimna: I want to start a blog. Yeah, who doesn't. Yet, I want learn the guts of it instead of just booting up some wordwank or whatever. Here's a simple computation to consider... WordPress' codebase is approximately a megabyte of PHP code and megabyte of JavaScript code. Assuming that the average line of that code is 50 characters long, you are looking at 20,000 lines of code in PHP and as many in JavaScript. Based on the notion that the average developer out there writes 100 lines a day, either you're in for a two-year project or your product is going to have seriously reduced functionality compared to something that's been freely available for years. What's your choice? Nope, the core functionality of a blogging software could be replicated in just a few lines of PHP codes, in the range of tens to hundreds of lines. If you're creating your own blogging software, you wouldn't seriously think you'd recreate all those things such as pingbacks, commenting system, etc, etc, etc. No, you'd start with some basic core functionalities: a few simple server side includes only. As he said - it's either a two man-year project or your product is going to have seriously reduced functionality. It looks like you are opting for the latter. Also, you still need to write the server-side includes. But they won't do nearly enough for everything WordPress does. If the OP wants to learn the guts of the blog or to implement the blog from scratch, Python/Django would be a better choice than PHP. The reason is that he can reuse and customize existing high quality components for all these auth/auth, admin, comments, etc, etc, etc. Another reason is that Python and Django encourage very clean design while PHP is too often ends up in spaghetti SQL wrapped in spaghetti PHP wrapped in spaghetti HTML. 2 man/year in PHP == 2 man/week in Python/Django. You can do the same in PHP. And PHP doesn't create spaghetti code - programmers do. Good programmers write good code in any language. Poor programmers write lousy code - in any language. And I'd love to see you write WordPress in 2 weeks in Python. That's about 2K LOC. Can't be done with the same functionality - unless you have some 50K lines. It's going to be very close to the same 2 man years that PHP takes. And there are Python/Django blog applications that already do almost everything (and maybe more) that WordPress does. http://byteflow.su/ is one of them (IMHO the most promising). Ivan And there are many CMS's written in PHP which do much more than WordPress does. Drupal, Joomla and Mambo come to mind. -- == Remove the x from my email address Jerry Stuckle JDS Computer Training Corp. [EMAIL PROTECTED] == -- http://mail.python.org/mailman/listinfo/python-list
QOTW
D'Arcy J.M. Cain wrote: Yes! One of the biggest advantages to unit testing is that you never ever deliver the same bug to the client twice. Delivering software with a bug is bad but delivering it with the same bug after it was reported and fixed is calamitous. QOTW for sure. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF problem?
In article [EMAIL PROTECTED], Tim Golden wrote: so it's just possible that one of your filenames has a non-ascii char in it without your noticing? (Altho' I'd find that an odd character to include in a filename). There is somewhere since printing worked when I changed the filename completely. To get round the problem in the immediate term, change both print lines to something like: print repr (full_filename) This did not work. Neither did commenting all print lines. The problem is somewhere else. Strange... The bash script that copies-renames the file for dirwatch.py is here: http://justin.yackoski.name/winp/winp I cannot see where they put a non ascii character there. Can you? -- Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * * mailto:[EMAIL PROTECTED] * Music seems to help the pain * Lecturer, mathematics education * R.I.P. Syd, my hero * University of Oulu, Finland * * * * * * * * * * * * * * * * * -- http://mail.python.org/mailman/listinfo/python-list
Re: Code correctness, and testing strategies
Ben Finney wrote: David [EMAIL PROTECTED] writes: You need to justify the extra time spent on writing test code. From the perspective of someone who once thought this way, and then dug in and did Behaviour Driven Development, I can tell you the time is entirely justified: by better design, more maintainable code, higher confidence when speaking to customers, high visibility of progress toward completion, freedom to refactor code when it needs it, and many other benefits. David, here's another way to convince yourself you have the time: For the next week, count how many times you repeat the same hand-test of some code on a subsequent version. Think of how much time that can add up to if you no longer do that; you had-tesing time is subtracting from the time you have to do unit tests. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF problem?
Vesa-Matti Sarenius wrote: This did not work. Neither did commenting all print lines. The problem is somewhere else. As Tim said, the line number that the exception prints would help here. Stefan -- http://mail.python.org/mailman/listinfo/python-list
RE: where do I begin with web programming in python?
This doesn't really answer your question, but you might want to consider Google App Engine. http://code.google.com/appengine/ Sam Dutton SAM DUTTON SENIOR SITE DEVELOPER 200 GRAY'S INN ROAD LONDON WC1X 8XZ UNITED KINGDOM T +44 (0)20 7430 4496 F E [EMAIL PROTECTED] WWW.ITN.CO.UK P Please consider the environment. Do you really need to print this email? Please Note: Any views or opinions are solely those of the author and do not necessarily represent those of Independent Television News Limited unless specifically stated. This email and any files attached are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error, please notify [EMAIL PROTECTED] Please note that to ensure regulatory compliance and for the protection of our clients and business, we may monitor and read messages sent to and from our systems. Thank You. -- http://mail.python.org/mailman/listinfo/python-list
Unicode lists and join (python 2.2.3)
Hello, I have a list of strings, some of the strings might be unicode. I am trying to a .join operation on the list and the .join raises a unicode exception. I am looking for ways to get around this. I would like to get a unicode string out of the list with all string elements seperated by '\n' #!/usr/bin/env python import sys import string try: x = [u\xeeabc2:xyz, uabc3:123] u = \xe7abc x.append(%s:%s % (xfasfs, u)) x.append(uHello:afddfdsfa) y = u'\n'.join(x) print(Unicode Call worked!) except Exception, err: print(Exception raised %s % err) on a related note Why does this work with no exceptions x=[] u = \xe7abc x.append(%s:%s % (xfasfs, u)) and this doesnt x=[] u = \xe7abc x.append(%s:%s % (uxfasfs, u)) Thanks, Nitin. -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF problem?
In article [EMAIL PROTECTED], Stefan Behnel wrote: Vesa-Matti Sarenius wrote: This did not work. Neither did commenting all print lines. The problem is somewhere else. As Tim said, the line number that the exception prints would help here. See my followup... -- Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * * mailto:[EMAIL PROTECTED] * Music seems to help the pain * Lecturer, mathematics education * R.I.P. Syd, my hero * University of Oulu, Finland * * * * * * * * * * * * * * * * * -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF problem?
In article [EMAIL PROTECTED], Vesa-Matti Sarenius wrote: In article [EMAIL PROTECTED], Tim Golden wrote: so it's just possible that one of your filenames has a non-ascii char in it without your noticing? (Altho' I'd find that an odd character to include in a filename). There is somewhere since printing worked when I changed the filename completely. I found the problem place, it is: cmd = '''C:\\Program Files\\Ghostgum\\gsview\\gsprint.exe -color ''' + full_filename and with that the full_filename has something utf. I tried repr or .encode (utf8) there but got file not found althougt the script itself worked. -- Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * * mailto:[EMAIL PROTECTED] * Music seems to help the pain * Lecturer, mathematics education * R.I.P. Syd, my hero * University of Oulu, Finland * * * * * * * * * * * * * * * * * -- http://mail.python.org/mailman/listinfo/python-list
set partition question
dear pythonistas, So imagine that we have a set of sets S. If we pick arbitrarily one set, s0, what are all the combinations of other sets in S which when combined by set operations result in s0? s0 = set([1]) s1 = set([1,2]) s2 = set([2]) S = set([s0,s1,s2]) one answer we're searching for is s0 = s1 - s2 There may be arbitrarily many set elements (denoted by integers 1,2,3,...) and arbitrarily many combinations of the elements composing the sets s_i (s0, s1, ...). We can use any operation or function which takes and returns sets. I think this problem is related to integer partitioning, but it's not quite the same. The range of answers has a little combinatorial explosion problem as S gains new members. In my problem, len(S) is usually on the order of 1M, and in the worst case, 10M, and there are on the order of 10k elements. My attempts to come up with an algorithm have not succeeded. Any ideas occur to you folks? -- PB. -- Patrick Ball, Ph.D. Chief Scientist Director, Human Rights Program http://www.benetech.org http://www.hrdag.org http://www.martus.org -- http://mail.python.org/mailman/listinfo/python-list
22.800000 and a 1 on the end!!??
x = 5 x /= 2 x 2 x *=11.4 x 22.801 ok where does the 1 in the come from? -- http://mail.python.org/mailman/listinfo/python-list
Re: 22.800000 and a 1 on the end!!??
On May 25, 8:58 pm, [EMAIL PROTECTED] wrote: x = 5 x /= 2 x 2 x *=11.4 x 22.801 ok where does the 1 in the come from? Floating point arithmetic. Michael Foord http://www.ironpythoninaction.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: 22.800000 and a 1 on the end!!??
[EMAIL PROTECTED] schrieb: ok where does the 1 in the come from? Conversion to floating point values, which have no precise representation for all numbers that have such in the decimal system. Read more on http://en.wikipedia.org/wiki/IEEE_754-1985 Regards, Johannes -- Wer etwas kritisiert muss es noch lange nicht selber besser können. Es reicht zu wissen, daß andere es besser können und andere es auch besser machen um einen Vergleich zu bringen. - Wolfgang Gerber in de.sci.electronics [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode lists and join (python 2.2.3)
x = [u\xeeabc2:xyz, uabc3:123] u = \xe7abc u is not a Unicode string. x.append(%s:%s % (xfasfs, u)) so what you append is not a Unicode string, either. x.append(uHello:afddfdsfa) y = u'\n'.join(x) As a consequence, .join tries to convert the byte string to a Unicode string, and fails, because it contains non-ASCII bytes. Why does this work with no exceptions x=[] u = \xe7abc x.append(%s:%s % (xfasfs, u)) % here is applied to a byte string, with all arguments also byte strings. The result is a byte string. and this doesnt x=[] u = \xe7abc x.append(%s:%s % (uxfasfs, u)) % is applied to a byte string, with one argument being a Unicode string. The result is a Unicode string, where all byte strings get converted to Unicode. Converting u fails, as it has non-ASCII bytes in it. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: which datastructure for fast sorted insert?
On Sun, 25 May 2008 13:05:31 -0300, Gabriel Genellina wrote: Use a list, and the bisect module to keep it sorted: That's worth doing if you need the data to be sorted after each insert. If the OP just needs the data to be sorted at the end, using a data structure with fast inserts (like a set) and then sorting at the end will likely be faster. -- http://mail.python.org/mailman/listinfo/python-list
Re: set partition question
s0 = set([1]) s1 = set([1,2]) s2 = set([2]) S = set([s0,s1,s2]) one answer we're searching for is s0 = s1 - s2 There may be arbitrarily many set elements (denoted by integers 1,2,3,...) and arbitrarily many combinations of the elements composing the sets s_i (s0, s1, ...). We can use any operation or function which takes and returns sets. In that case, there is always a trivial answer. As I can use any function which takes and returns sets, and as I shall come up with a function that returns s0, I just use the following function def f(s): return s0 To compute s0, just invoke f with any other of the sets, and you will - get s0. I think this problem is related to integer partitioning, but it's not quite the same. I think the problem is significantly underspecified. It would be a more interesting problem if there was a restriction to a few selected set operations, e.g. union, intersection, difference, and combinations thereof. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: 22.800000 and a 1 on the end!!??
ok where does the 1 in the come from? http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: set partition question
On May 25, 1:13 pm, Martin v. Löwis [EMAIL PROTECTED] wrote: We can use any operation or function which takes and returns sets. I think the problem is significantly underspecified. It would be a more interesting problem if there was a restriction to a few selected set operations, e.g. union, intersection, difference, and combinations thereof. Ok, that's quite right -- when I just tried to define any function, I found that all the solutions I came up with were combinations of the set operations defined for immutable sets. Let me improve the spec as the following: There may be arbitrarily many set elements (denoted by integers 1,2,3,...), arbitrarily many combinations of the elements composing the sets s_i (s0, s1, ...). We can use any of python's set operations or combination of those operations. Thanks for the clarification -- PB. -- http://mail.python.org/mailman/listinfo/python-list
Re: 22.800000 and a 1 on the end!!??
Like what others said, use the Decimal class to avoid this. from decimal import Decimal x=Decimal(5) x/=2 x*=Decimal(11.4) print x # 28.50 On Mon, May 26, 2008 at 1:28 AM, [EMAIL PROTECTED] wrote: x = 5 x /= 2 x 2 x *=11.4 x 22.801 ok where does the 1 in the come from? -- http://mail.python.org/mailman/listinfo/python-list -- Harsh J www.harshj.com -- http://mail.python.org/mailman/listinfo/python-list
Re: php vs python
On May 25, 11:46 am, Ivan Illarionov [EMAIL PROTECTED] wrote: If the OP wants to learn the guts of the blog or to implement the blog from scratch, Python/Django would be a better choice than PHP. The reason is that he can reuse and customize existing high quality components for all these auth/auth, admin, comments, etc, etc, etc. You are comparing apples to oranges... There are application frameworks for PHP as well (CakePHP and Symfony come to mind). CakePHP, if memory serves, actually has a development of a blog described in its tutorial... Another reason is that Python and Django encourage very clean design while PHP is too often ends up in spaghetti SQL wrapped in spaghetti PHP wrapped in spaghetti HTML. It's absolutely the same thing with PHP frameworks... 2 man/year in PHP == 2 man/week in Python/Django. This, I daresay, is an exaggeration... Let's take your own example: And there are Python/Django blog applications that already do almost everything (and maybe more) that WordPress does.http://byteflow.su/ is one of them (IMHO the most promising). A quick look at the revision log: http://byteflow.su/log/ reveals that the initial commit of 60 or so files has been done on 08/14/07 (10 months ago), a second developer came on board 12/01/07 (seven+ months ago), a third one, on 01/04/08 (six+ months ago), a fourth one, on 01/16/08 (also six+ months ago). There are at least nine discernible contributors overall. Say what you will, but it still looks an awful lot like like two man- years, Django or no Django... Cheers, NC -- http://mail.python.org/mailman/listinfo/python-list
Re: set partition question
[EMAIL PROTECTED] writes: dear pythonistas, So imagine that we have a set of sets S. If we pick arbitrarily one set, s0, what are all the combinations of other sets in S which when combined by set operations result in s0? s0 = set([1]) s1 = set([1,2]) s2 = set([2]) S = set([s0,s1,s2]) one answer we're searching for is s0 = s1 - s2 There may be arbitrarily many set elements (denoted by integers 1,2,3,...) and arbitrarily many combinations of the elements composing the sets s_i (s0, s1, ...). We can use any operation or function which takes and returns sets. I think this problem is related to integer partitioning, but it's not quite the same. The range of answers has a little combinatorial explosion problem as S gains new members. In my problem, len(S) is usually on the order of 1M, and in the worst case, 10M, and there are on the order of 10k elements. My attempts to come up with an algorithm have not succeeded. Any ideas occur to you folks? -- PB. Unless your sets have some sort of pattern, it sounds to me like this problem is at least exponential... Good luck! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Code correctness, and testing strategies
In article [EMAIL PROTECTED], David [EMAIL PROTECTED] wrote: Seriously, 10 hours of testing for code developed in 10 hours? What kind of environment do you write code for? This may be practical for large companies with hordes of full-time testing QA staff, but not for small companies with just a handful of developers (and where you need to borrow somone from their regular job to do non-developer testing). In a small company, programmers do the lions share of testing. For programmers to spend 2 weeks on a project, and then another 2 weeks testing it is not very practical when they have more than one project. You must have poor project management/tracking. You WILL pay the cost of testing, the only question is when. The when does have an impact on other aspects of the development process. Speaking as someone who started in my current job four years ago as the third developer in a five-person company, I believe that your claim about the differences between small companies and large companies is specious. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ Need a book? Use your library! -- http://mail.python.org/mailman/listinfo/python-list
Discount, EDhardy, 10Deep, Bape, COOGI, GGG, Rich Yung, Designers Hoodies, etc
Brand Jacket : Dsquared Jacket, Prada Jacket, Armani Jacket, Ralph Lauren Jacket, China supply Discount Coat : Burberry Coat, Helen Coat, AF Coat, Designer Hoodies : LRG hoody, Stussy Hoody, COOGI hoody, Chanel Hoody, GGG hoody, Bape hoody, 10Deep hoodies, Rich Yung Hoodies, Brand Belt China Sale : Discount Lacoste Belt, LV Belts, ( G U C C I ) Belts, Chanel belt, Bape belts, Juicy belts, EDhardy belts for low price. Brand Cap, Hat: Supply EDhardy Cap, New Era Cap, Phat Farm Hat, Red Monkey Cap, Lacoste Cap, etc ( www.c heapforwholesale.com ) -- http://mail.python.org/mailman/listinfo/python-list