Re: More urllib timeout issues.
Facundo Batista wrote: Steve Holden wrote: 1) There is work afoot to build timeout arguments into network libraries for 2.6, and I know Facundo Batista has been involved, you might want to Google or email Facundo about that. Right now (in svn trunk) httplib, ftplib, telnetlib, etc, has a timeout argument. If you use it, the socket timeout will be set (through s.settimeout()). What behaviour has the socket after setting it the timeout, is beyond of these changes, though. BTW, I still need to make the final step here, that is adding a timeout argument to urllib2.urlopen(). Regards, urllib, robotparser, and M2Crypto also need to be updated to match. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check if a string is empty in python?
On Wed, 02 May 2007 21:59:56 -0700, Alex Martelli wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 02 May 2007 21:19:54 -0400, Roy Smith wrote: for c in s: raise it's not empty String exceptions are depreciated and shouldn't be used. http://docs.python.org/api/node16.html They're actually deprecated, not depreciated. Er, um... oh yeah... I knew that... I mean... yes, that was deliberate, to see who was paying attention. Well done Alex! -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list
Re: FInd files with .so extension
On Wed, 02 May 2007 21:58:41 -0700, pradeep nair wrote: HI, How do i find files with .so extension using python . import os help(os.listdir) help(os.walk) help(os.path.splitext) That should give you all the tools you need. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
Fuzzyman wrote: On May 2, 8:20 pm, Pascal Costanza [EMAIL PROTECTED] wrote: sturlamolden wrote: On Monday Microsoft announced a new runtime for dynamic languages, which they call DLR. It sits on top of the conventional .NET runtime (CLR) and provides services for dynamically typed languages like Python or Lisp (thus the cross-posting). Apparently is is distributed under a BSD-like open-source license. I am curious to know how it performs in comparison to CPython and an efficient compiled Lisp like CMUCL. Speed is a major problem with CPython but not with .NET or CMUCL, so it will be interesting to see how the DLR performs in comparison. It would be great to finally see a Python that runs on steroids, but knowing M$ bloatware my expectations are not too high. Has anyone looked at the DLR yet? What are your impression? So far, there is not a lot of information available. The only statement about the technology I have read so far is that the DLR is a thin layer on top of the CLR. This doesn't say a lot. So it's hard to tell whether this is a (good) marketing stunt or whether there are actual substantial improvement to the infrastructure. Well, they're now implementing four dynamic languages on top of the DLR - not just IronPython. * IronPython * IronRuby * Java Script * VBx (a dynamic version of VB) The DLR provides a dynamic type system and hosting environment for dynamic languages. The nice part is that the DLR runs on top of the 'Core CLR' which ships with Silverlight. This means that apps. that run in Silverlight are secure - so you can run an IronPython console in the browser... That still doesn't explain what DLR actually does. You can implement these languages on top of the JVM as well. You could implement them on any Turing-complete language, for that matter. The interesting question how well integrated such an implementation is. However, Jim Hugunin seems to be willing to give more details on his blog - the recent entry gives hints that there is indeed something interesting going on. I'm still waiting for the meat, though... Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP ContextL: http://common-lisp.net/project/closer/ -- http://mail.python.org/mailman/listinfo/python-list
Re: FInd files with .so extension
May be this would work import os grep=so dir=. lst = os.listdir(dir) filelst=[] for i in lst: if i.split(.)[len(i.split(.))-1] == grep: lst.append(i) print lst On 2 May 2007 21:58:41 -0700, pradeep nair [EMAIL PROTECTED] wrote: HI, How do i find files with .so extension using python . -- http://mail.python.org/mailman/listinfo/python-list -- Regards-- Rishi Pathak National PARAM Supercomputing Facility Center for Development of Advanced Computing(C-DAC) Pune University Campus,Ganesh Khind Road Pune-Maharastra -- http://mail.python.org/mailman/listinfo/python-list
Re: Firefighters at the site of WTC7 Move away the building is going to blow up, get back the building is going to blow up.
On May 2, 9:46 pm, Eric Gisse [EMAIL PROTECTED] wrote: On May 2, 7:10 pm, Midex [EMAIL PROTECTED] wrote: [...] I guess the explanation that people were looking at the building and watching its' structure deform is too rational. Also, that was a Larry Silverstein impostor who said they were going to 'pull it'. And the only reason he took out huge amounts of extra insurance on the buildings two months before this happened was because of global warming, because we all know a little bit of heat will bring down steel buildings. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Firefighters at the site of WTC7 Move away the building is going to blow up, get back the building is going to blow up.
On May 2, 10:14 pm, malibu [EMAIL PROTECTED] wrote: On May 2, 9:46 pm, Eric Gisse [EMAIL PROTECTED] wrote: On May 2, 7:10 pm, Midex [EMAIL PROTECTED] wrote: [...] I guess the explanation that people were looking at the building and watching its' structure deform is too rational. Also, that was a Larry Silverstein impostor who said they were going to 'pull it'. ...maybe if you read the context, it would make a little more rational sense. Fucking nutter. And the only reason he took out huge amounts of extra insurance on the buildings two months before this happened was because of global warming, because we all know a little bit of heat will bring down steel buildings. A little heat and major structural damage. John -- http://mail.python.org/mailman/listinfo/python-list
Re: FInd files with .so extension
do YOU mean hit reply to all not reply? On 5/3/07, kaens [EMAIL PROTECTED] wrote: do you mean filelst.append(i)? On 5/3/07, rishi pathak [EMAIL PROTECTED] wrote: May be this would work import os grep=so dir=. lst = os.listdir(dir) filelst=[] for i in lst: if i.split(.)[len(i.split(.))-1] == grep: lst.append(i) print lst On 2 May 2007 21:58:41 -0700, pradeep nair [EMAIL PROTECTED] wrote: HI, How do i find files with .so extension using python . -- http://mail.python.org/mailman/listinfo/python-list -- Regards-- Rishi Pathak National PARAM Supercomputing Facility Center for Development of Advanced Computing(C-DAC) Pune University Campus,Ganesh Khind Road Pune-Maharastra -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python un-plugging the Interpreter
Jorgen Grahn [EMAIL PROTECTED] wrote: On Wed, 25 Apr 2007 08:05:01 +0200, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Jorgen Grahn [EMAIL PROTECTED] wrote: ... I doubt it. (But I admit that I am a bit negative towards thread programming in general, and I have whined about this before.) I find this last statement interesting, because it differs so much from my own attitude - getting a thread running was one of the first things I did when I started getting to grips with python. Do you mind whining some more - maybe I can learn something - threads seem to me to make a lot of things so much easier and more natural, as I see them as sequences that run at the same time, and I find this immensely useful for all sorts of things, as it enables me to think in a simple linear fashion about parts of complicated things. It's the other way around for me -- using a threaded design looks superficially more linear, but all the complexity is still there, and then some. I mean, threads are well known for causing surprising and hard-to-track-down (and hard to trigger!) bugs and performance problems. (I'm comparing with the Unix select() call, and I assume the APIs I want to use are designed to work with select(). i.e. use select()able file descriptors.) This is a valuable insight - it is to a large extent true that threading is used to front end i/o - but that is not its only use... I tend to use it to build, via Queue glue, structures that resemble systolic arrays - where each thread does a small part of a whole job. And if you add queues, you have something in your hand that you can do quite fancy stuff with in a robust, simple manner... *grin* before I discovered the queue module, I was using named pipes to communicate between threads... So you could say I am a threading freak if you want to, and I won't argue. But I would like to hear the opposite viewpoint.. Good. My viewpoint is due to my Unix background (but I'm not insinuating that all Unix users dislike threads). Eric Raymond's The Art of Unix Programming sums up the threading criticism, I think: http://catb.org/~esr/writings/taoup/html/multiprogramchapter.html /Jorgen Thanks - interesting link. This guy really is not turned on by threading... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: FInd files with .so extension
On May 3, 11:27 am, kaens [EMAIL PROTECTED] wrote: do YOU mean hit reply to all not reply? On 5/3/07, kaens [EMAIL PROTECTED] wrote: do you mean filelst.append(i)? On 5/3/07, rishi pathak [EMAIL PROTECTED] wrote: May be this would work import os grep=so dir=. lst = os.listdir(dir) filelst=[] for i in lst: if i.split(.)[len(i.split(.))-1] == grep: lst.append(i) print lst On 2 May 2007 21:58:41 -0700, pradeep nair [EMAIL PROTECTED] wrote: HI, How do i find files with .so extension using python . -- http://mail.python.org/mailman/listinfo/python-list -- Regards-- Rishi Pathak National PARAM Supercomputing Facility Center for Development of Advanced Computing(C-DAC) Pune University Campus,Ganesh Khind Road Pune-Maharastra -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
In comp.lang.lisp sturlamolden [EMAIL PROTECTED] wrote: I am curious to know how it performs in comparison to CPython and an efficient compiled Lisp like CMUCL. Speed is a major problem with You are not allowed to publish .NET benchmarks. :-) -- Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
On Thu, 3 May 2007 09:20:22 +0200, Stefan Scholl [EMAIL PROTECTED] wrote: You are not allowed to publish .NET benchmarks. :-) I'm pretty sure that only applied to their beta releases. -- Lisp is not dead, it just smells funny. Real email: (replace (subseq [EMAIL PROTECTED] 5) edi) -- http://mail.python.org/mailman/listinfo/python-list
Re: pack/unpack zero terminated string
On May 2, 11:13 pm, John Machin [EMAIL PROTECTED] wrote: On May 3, 12:01 am, Laurent Pointal [EMAIL PROTECTED] wrote: tmp123a écrit : Hello, Thanks for your time. After review the struct documentation, it seems there are no option to pack/unpack zero terminated strings. By example, if the packed data contains: byte + zero terminated string + zero terminated string + byte, it seems no possible to unpack it using struct. Please, has someone any hint or pointer to another librarian to be used? May look at xstruct too http://www.sis.nl/python/xstruct/xstruct.shtml Hi, Laurent, It's a reasonable presumption that the OP needs to unpack *variable- length* zero-terminated strings, otherwise why is he asking? This would need a new format type e.g. z. xstruct doesn't appear to offer variable-length strings, and is frozen in time (October 1999) -- inspection of the source shows that it is a copy of Python 1.5.2 structmodule.c with added stuff. The OP might like to try a bit of DIY in Python, along the following lines: C:\junktype unpackz.py def getz(strg, start=0): zpos = strg.index('\0', start) return strg[start:zpos], zpos + 1 def getB(strg, start=0): return ord(strg[start]), start + 1 def unpack_BzzB(strg): pos = 0 r0, pos = getB(strg, pos) r1, pos = getz(strg, pos) r2, pos = getz(strg, pos) r3, pos = getB(strg, pos) assert pos == len(strg) return r0, r1, r2, r3 x = chr(42) + 'foo\0' + 'mumble\0' + '\xff' print unpack_BzzB(x) print unpack_BzzB('\0' * 4) C:\junkunpackz.py (42, 'foo', 'mumble', 255) (0, '', '', 0) HTH, John Hello John, Totally true, the solution you propose is the one I'm using now. The subject was, before to start from scratch, try to reuse something existing. Another possibility was to modify the struct package with the new option, but it seems a mixed C-Python implementation, and I do not like to start having compatibility problems in the C elements. Kind regards. -- http://mail.python.org/mailman/listinfo/python-list
Re: test
On 2 Maj, 05:19, Robert Rawlins - Think Blue [EMAIL PROTECTED] wrote: [...] I like comp.lang.python - it is a friendly place. See this post on the C-list and compare: http://groups.google.se/group/comp.lang.c/browse_thread/thread/0a4e2e194a6da45b [:)]-|-- /Per -- Per Erik Strandberg .NET Architect - Optimization Tomlab Optimization Inc. http://tomopt.com/tomnet/ -- http://mail.python.org/mailman/listinfo/python-list
Re: FInd files with .so extension
On May 3, 9:58 am, pradeep nair [EMAIL PROTECTED] wrote: HI, How do i find files with .so extension using python . Hi pradeep This piece of code should help you import os,re def findfile(filepattern, base = '.'): regex = re.compile(filepattern) matches = [] for root,dirs,files in os.walk(base): for f in files: if regex.match(f): matches.append(root + '/' + f) return matches HAPPY CODING -- http://mail.python.org/mailman/listinfo/python-list
Searching for a piece of string
Hi, How can i match a part of string and branch to some part of code. Ex If there is a string like Timeout and i want to search only whether the word Time is present in it(which is valid in this case).so if i have CastinTime,still this should hold. I need to use this in a if statement and code.Can someone help me in this. Thanks . -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching for a piece of string
On May 3, 8:35 am, [EMAIL PROTECTED] wrote: Hi, How can i match a part of string and branch to some part of code. Ex If there is a string like Timeout and i want to search only whether the word Time is present in it(which is valid in this case).so if i have CastinTime,still this should hold. I need to use this in a if statement and code.Can someone help me in this. Thanks . if Time in text: # do stuff. -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching for a piece of string
s=CastinTime if s.find(Time) != -1: print found else: print not found On 3 May 2007 00:35:57 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, How can i match a part of string and branch to some part of code. Ex If there is a string like Timeout and i want to search only whether the word Time is present in it(which is valid in this case).so if i have CastinTime,still this should hold. I need to use this in a if statement and code.Can someone help me in this. Thanks . -- http://mail.python.org/mailman/listinfo/python-list -- Regards-- Rishi Pathak National PARAM Supercomputing Facility Center for Development of Advanced Computing(C-DAC) Pune University Campus,Ganesh Khind Road Pune-Maharastra -- http://mail.python.org/mailman/listinfo/python-list
passing an array of variant in vb to a python COM object = win32com bug ?
I have a python com object which contains a method to inverse an array in vb 6 the definition of the class is : class Fop: _public_methods_ = [ 'SqVal' ] def SqVal(self,*val): #vol=(val[0][0],val[0][1]) #mat1=mat((vol)) #up=linalg.inv(mat1) return str(val)#up _reg_verprogid_ = Python.Fop.3 _reg_progid_ = Python.Fop _reg_desc_ = Python Fop _reg_clsid_ = {30BD3490-2632-11cf-AD5B-524153480001} I pass to this method an array of variant which is the matrix to invert like that: vb6 code : Set obj = CreateObject(Python.Fop) Dim ty(1, 1) As Variant ty(0, 0) = 1 ty(1, 0) = 2 ty(0, 1) = 3 ty(1, 1) = 4 toto = obj.SqVal(ty) when I dispaly toto as str(val) I obtain the following tuple (((1, 3), (2, 4)),) which is not usable Do you have an idea to explain this strange behaviour ? thank you ! -- http://mail.python.org/mailman/listinfo/python-list
Re: python,win32com,scipy and vb 6 : no module named scipy
On 3 mai, 03:30, Terry Reedy [EMAIL PROTECTED] wrote: scipy is a 3rd party package which I believe you get from the same place, more or less, as numpy. the bug was between the chair and the keyboard;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Responding to Trolls [was Re: ignorance and intolerance in computing communties]
On Thu, 03 May 2007 14:54:21 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote: Subject: Responding to Trolls [was Re: ignorance and intolerance in computing communties] Nope. No way. Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}-(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^RY]*YB=' .'KYU;*EVH[.FHF2W+#\Z*5TI/ERZ`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:\r;print,redo}#JAPH, -- http://mail.python.org/mailman/listinfo/python-list
Re: Video: Professor of Physics, Phd at Cal Tech says: 911 Inside Job
On 2 May 2007 22:26:07 -0700, [EMAIL PROTECTED] Gave us: http://www.911blogger.com/node/8101 What a lard ass... no wonder the Navy got rid of him. And he isn't from cal tech, he teaches in Iowa. Also, being a physicist, does NOT make him, in any way shape or form, a structural engineer. The guy is an idiot. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use Dispatch to open an application in win32com.client
Hello Tim, Thank you for your answer. I just tried, but it didn't work. The reason seems to be that Google Earth prevents a second instance to run on the same machine. Maybe for licensing reasons (do you know whether it is legal to bypass this and how to do this?). So that is no python/COM problem. However, now I will try to run the two instances on separate machines and to synchronize them via network. Do you know how to start a second instance on a second machine over the network in python/COM (DCOM)? Is this possible directly with the win32com package in python or do I have to install an additional package? You would greatly help me with an answer, best regards, Peter. Tim Golden [EMAIL PROTECTED] wrote:Suspect you want win32com.client.DispatchEx which, among other things, starts a separate instance of the app. (Or whatever they call the things in COMspeak). GE_n = win32com.client.DispatchEx (GoogleEarth.ApplicationGE) TJG -- http://mail.python.org/mailman/listinfo/python-list - Ahhh...imagining that irresistible new car smell? Check outnew cars at Yahoo! Autos.-- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
Pascal Costanza [EMAIL PROTECTED] wrote: That still doesn't explain what DLR actually does. You can implement these languages on top of the JVM as well. You could implement them on any Turing-complete language, for that matter. The interesting question how well integrated such an implementation is. However, Jim Hugunin seems to be willing to give more details on his blog - the recent entry gives hints that there is indeed something interesting going on. I'm still waiting for the meat, though... Watch the video he linked from his blog. In short, the implementation looks really well integrated. They start with an example (in Ruby) which creates a C# control and handles the event it generates to call some VB which retrieves a list of strings from the server and then passes it to a 3d animation written in JScript. All seamless, and all running in the local browser (which in the demo is Safari). The significant part of the DLR is (I think) that you can have a single object e.g. a string, but the methods available on that object vary according to the source file from which you are accessing the object. That means in pure Python code the string has python methods, but in Python using the CLR it gains the CLR methods. Presumably in Ruby code it looks like a Ruby string and so on, but (and this is what's new) it is the same object, not a bunch of language specific wrappers around the string type. -- http://mail.python.org/mailman/listinfo/python-list
Re: Slicing Arrays in this way
John Machin wrote: On May 3, 10:21 am, Michael Hoffman [EMAIL PROTECTED] wrote: Tobiah wrote: elegant_solution([1,2,3,4,5,6,7,8,9,10]) [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] That's not an array, it's a list. See the array module for arrays (fixed-length, unlike variable-length lists). You must have your very own definitions of fixed-length and unlike. Sorry, too much time spent with numarray arrays which are documented to have immutable size. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Lazy evaluation: overloading the assignment operator?
On 2007-05-03, Terry Reedy [EMAIL PROTECTED] wrote: sturlamolden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | | Python allows the binding behaviour to be defined for descriptors, | using the __set__ and __get__ methods. I think it would be a major | advantage if this could be generalized to any object, by allowing the | assignment operator (=) to be overloaded. Conceptually, assignment is *not* an operator. Binary operators take two values (of the same type) and produce a third (usually of either the input type or a boolean) that usually depends on both inputs. Assignment does nothing of the sort. In Python, the equal sign is *not* an operator: it is a grammatical symbol. One use of the operator fiction in C is to enable simple chained assignment: a=b=2. Python does this directly without the fiction. C's store-and-test usage can be implemented in Python with a 'purse' class. | One particular use for this would be to implement lazy evaluation. Since (in Python, at least) operands are evaluated *before* the operator/function is called, I do not see how. But they could evaluate to an expression tree instead of the actual result. This tree could then be evaluate at the moment of assignment. This is an idea I have been playing with myself in an other context. You have a class of symbolic names. e.g. First, Last ... You can use the normal operators to these names, the result will be an expression tree. So Last - 2 will evaluate to something like sub / \ Last2 I want to use this in the context of a table (a list like structure but with arbitrary start index, which can be negative, so tab[-1] can't refer to the last element). So I can use this as follows: el = tab[Last - 2] to access the element two places before the last, because the evaluation of the tree happens in the __getitem__ method. I could even write something like: el = tab[(First + Last) / 2] To get at the midle element. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Refreshing imported modules
On May 2, 7:24 pm, [EMAIL PROTECTED] wrote: I have the python interperter opened while editing a module. The problem is that when I make changes, the module is not refreshed whenever I import it again. I have to re-launch the interpreter, is there a way to shortcut this? I believe you can use the 'reload' command. ie First import your module : import module_name If you want to refresh the module after having changed it, module_name = reload(module_name) That should work. However, any variables you have declared which arise from classes within your module must be redeclared. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use Dispatch to open an application in win32com.client
Peter Fischer wrote: Thank you for your answer. I just tried, but it didn't work. The reason seems to be that Google Earth prevents a second instance to run on the same machine. Maybe for licensing reasons (do you know whether it is legal to bypass this and how to do this?). Don't know, but common sense tells me it's not a good idea! However, now I will try to run the two instances on separate machines and to synchronize them via network. Do you know how to start a second instance on a second machine over the network in python/COM (DCOM)? Is this possible directly with the win32com package in python or do I have to install an additional package? Well, funnily enough, you use exactly the same call, but with a machine name on the end: code import win32com.client xl = win32com.client.DispatchEx ( Excel.Application, other_machine ) /code The trouble now is that, to use COM/DCOM effectively, you really need to know what to do, not just be a dabbler like me. On a recent thread, Alex Martelli recommended Don Box's Essential COM which I've noted down but haven't read: http://groups.google.com/group/comp.lang.python/msg/f95a2d51b6e84091?hl=en; That said, this is Python so even without using DCOM directly, you have a whole slew of across-the-network possibilities for interacting between apps on two machines. Just ask this list and sit back and wait for the variety of replies! TJG -- http://mail.python.org/mailman/listinfo/python-list
problem with meteo datas
Messaggio originale Da: [EMAIL PROTECTED] Data: 3-mag-2007 10.02 A: python-list@python.org Ogg: problem with meteo datas Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-Est : 44.50/ 2.50 MODELE PA PARAMETRE P NIVEAU MER 0 ECHEANCE 0.0 DATE 2002030400 NB_POINTS 25 1020.911020.871020.911021.05 1021.13 1020.071020.271020.491020.91 1021.15 1019.37 1019.651019.791020.53 1020.77 1018.731018.89 1019.191019.83 1020.81 1018.051018.191018.75 1019.55 1020.27 NIVEAU MER 0 ECHEANCE 3.0 DATE 2002030400 NB_POINTS 25 1019.801019.781019.921020.18 1020.34 1018.941019.241019.541020.08 1020.32 1018.24 1018.641018.941019.84 1019.98 1017.481017.88 1018.281018.98 1019.98 1016.621017.081017.66 1018.26 1018.34 NIVEAU MER 0 ECHEANCE 6.0 DATE 2002030400 NB_POINTS 25 1019.371019.391019.57 ... . ... ... ... ... . NIVEAU MER 0 ECHEANCE 48.0 DATE 2002030400 NB_POINTS 25 1017.841017.461017.14 1016.86 1016.58 1017.281016.901016.461016.48 1016.34 1016.501016.061015.621015.90 1015.72 1015.941015.301014.781014.68 1014.86 1015.86 1015.101014.361014.00 1013.90 . MODELE PA PARAMETRE T NIVEAU HAUTEUR 2 ECHEANCE 0.0 DATE 2002030400 NB_POINTS 25 1.34 1.51 1.40 0.56 -0.36 1.73 1.43 0.89 -0.16 -0.99 2.06 1.39 1.14 -0.53 -0.99 2.12 2.22 2.15 0.76 -1.16 1.67 1.45 1.40 1.260.28 NIVEAU HAUTEUR 2 ECHEANCE 3.0 DATE 2002030400 NB_POINTS 25 0.94 1.16 1.03 0.44 -0.41 0.95 0.61 0.22 . I'am at the begginning of computation and for the moment I write this code to extract only number data in form of a string: from pyparsing import * dec = Combine (Optional( - ) + delimitedList( Word( nums ), ., combine=True )) datas = ZeroOrMore( dec ) f=file(arqal-Arpege.00, r) g=file(out3, w) for line in f: try: result = datas. parseString (line) add = result add1 = ;.join (add) print g,(,add1,) except ParseException, pe: print pe This is the output result in file g=file(out3, w) ( ) ( ) ( ) ( 1020.91;1020.87;1020.91;1021.05;1021.13 ) ( 1020.07;1020.27; 1020.49;1020.91;1021.15 ) ( 1019.37;1019.65;1019.79; 1020.53;1020.77 ) ( 1018.73;1018.89;1019.19;1019.83;1020.81 ) ( 1018.05;1018.19;1018.75; 1019.55;1020.27 ) ( ) ( 1019.80;1019.78; 1019.92;1020.18;1020.34 ) ( 1018.94;1019.24;1019.54;1020.08;1020.32 ) ( 1018.24;1018.64;1018.94; 1019.84;1019.98 ) ( 1017.48;1017.88;1018.28; 1018.98;1019.98 ) ( 1016.62; 1017.08;1017.66;1018.26;1018.34 ) ( ) ( 1019.37;1019.39;1019.57; 1019.9;..; .; 1016.87) ( ) ( 1017.84; 1017.46;1017.14;1016.86;1016.58 ) ( 1017.28; 1016.90;1016.46;1016.48; 1016.34 ) ( 1016.50;1016.06;1015.62;1015.90; 1015.72 ) ( 1015.94;1015.30; 1014.78;1014.68;1014.86 ) ( 1015.86; 1015.10;1014.36;1014.00;1013.90 ) So I don't have any word but the problem is that Now I have to put in order this numerical datas in a type of NESTED matrix emulated by python like a nested dictionary : { 'P ' : { MER 0 : [ (1020.91; 1020.87;;1020.27 ) ; (.) ; ( 1019.80;1019.78;; 1018.26;1018.34 ) ]; ..; SOL 0 : [ ( ...);.;( ) ] } ; 'T' : { SOL 0 : [(.;..) ; (ECHEANCE 3.0) ; (ECHEANCE 6.0) ; (...;) ]; HAUTEUR 2 : [(...;..;..) ] } } == { 'Parameter X' : { Level X : [ (predict step 3 hours from +0 to +48 hours ) ;]} } the bigger shell is fixed by Dictionary PARAMETER in the example is P= 'Pressure' but thre are many of this Temperature = T , Wind = U and V ecc... the second nested shell is setted by another Dictionary NIVEAU MER 0 in the example is MER 0 = sea level or SOL 0, but can be HAUTER 2,10 (HEIGHT 2,10 METERS) ecc. (soil level , 1;0 meter from soil) ecc (from French language) and after every Level is associated with a LIST OF TUPLE: [(); ();()] to rappresented every step hours of prediction or expiration hours in French language: ECHEANCE XX.X = predicted hour +3. 0 +6.0 until 48H is setted of a list of tuple [(ECHEANCE 3.0); (ECHEANCE 6.0);
assigning to __class__ for an extension type: Is it still possible?
Hello, We are currently writing python bindings to an existing C++ library, and we encountered a problem that some of you may have solved (or that has found unsolvable :( ): A C++ class (let's call it CClass) is binded using classical Python extension API to _PClass, which is accesible through python without any problem. The problem is that I want this class to be extended/ extensible in python, and expose the python-extended version (PClass) to library users (_PClass should never be used directly nor be retruned by any function). The aim is to leave only performance critical methods in C++ so that the binding work is minimal, and develop the other methods in python so that they are easier to maintain/extend. We thus have something like this class PClass(_PClass): def overide_method(self,...): ... def new_method(self,...): ... and I can define a=PClass() and use my new or overiden method a.overide_method() a.new_method() as intended... So far, so good, trouble begin when I have a method from another class PClass2 derived from _PClass2 which bind the C++ class CClass2, that should return objects of type PClass: Let call this method troublesome_method: b=_PClass2() c=b.troublesome_method() type(c) gives _PClass. Now I want to define a python class PClass2 for extending methods of _PClass2 like I have done for _PClass, in particular I want that PClass2 troublesome_method return objects of type PClass instead of _PClass... To this end I try something like this class PClass2(_PClass2): ... def troubelsome_method(self): base=_PClass2.troublesome_method(self) base.__class__=PClass and I have python complaining about TypeError: __class__ assignment: only for heap types... We have then added the Py_TPFLAGS_HEAPTYPE tp_flag, which turn _PClass into a heap class and should make this class assignment possible...or so I though: When the _PClass is turned into a heaptype, assignent to __class__trigger a test in python's typeobject.c on tp_dealloc/tp_free witch raise an exception TypeError: __class__ assignment: '_PClass' deallocator differs from 'PClass' I have commented out this test, just to check what happen, and just got an error later on TypeError: __class__ assignment: '_PClass' object layout differs from 'PClass' It seems thus that this approach is not possible, but problem is that delegation ( embedding a _PClass instance in PClass (lets say as _base attribute) and automatically forwarding all methods calls/setattr/getattr to ._base) is far from ideal... Indeed, we would have to change all other methods that accepted _PClass, to give them PClass._base, this means wrapping a large number of methods (from our c++ bindings) for argument-processing... This is particularly frustrating cause I also have the impression that want we want to do was at one time possible in python, let say in 2002-2003, when __class__ was already assignable but before various safety checks were implemented (assignmenent only for heaptypes, check on tp_free/tp_dealloc, layout check,...) Any hint on this problem? In particular, a list of condition type A and B have to fullfull so that a=A(); a.__class__=B is possible would be very nice, especially when A is an extension type (I think the correct term is static type) while B is defined by a class statement (dynamic type)...This is something that is not easy to find in the docs, and seems to have changed quite a lot between revisions 2.2/2.3/2.4/2.5... Thanks, Greg. -- http://mail.python.org/mailman/listinfo/python-list
32 OS on 64-bit machine
If anyone has a x86_64 machine and is running a 32bit OS on top of that could you tell me what output would you get for the following program #== import platform print platform.processor() print platform.architecture() #== Thanks in advance : )~ -- http://mail.python.org/mailman/listinfo/python-list
Using Bessel Functions
Hi, I want to use Bessel functions in Python. I found on internet that package Scipy has a function jn(x), but I'm not able to use it. I am importing scipy and numpy for using it. But i'm getting an error NameError: name 'j1' is not defined. Can anyone tell me what is the exact syntax for to use it. Thank you, Amit -- http://mail.python.org/mailman/listinfo/python-list
Re: Lazy evaluation: overloading the assignment operator?
On May 3, 6:22 am, Charles Sanders [EMAIL PROTECTED] wrote: y = a*b+c*d # Returns a proxy object x = y[4] # Computes x = a[4]*b[4] + c[4]*d[4] v = y.eval() # Evaluates all elements, returning Xarray z = ((a+b)*(c+d)).eval() # Also evaluates all elements When I suggested this on the NumPy mailing list, I too suggested using the indexing operator to trigger the computations. But I am worried that if an expression like y = a*b+c*d returns a proxy, it is somehow possible to mess things up by creating cyclically dependent proxies. I may be wrong about this, in which case __getitem__ et al. will do the job. Whether it would be any faster is doubtful, but it would eliminate the temporaries. The Numexpr compiler in SciPy suggests that it can. It parses an expression like 'y = a*b+c*d' and evaluates it. Numexpr is only a slow prototype written in pure Python, but still it can sometimes give dramatical speed-ups. Here we do not even need all the machinery of Numexpr, as Python creates the parse tree on the fly. Inefficiency of binary operators that return temporary arrays is mainly an issue when the arrays in the expression is too large to fit in cache. RAM access can be very expensive, but cache access is usually quite cheap. One also avoids unnecessary allocation and deallocation of buffers to hold temporary arrays. Again, it is mainly an issue when arrays are large, as malloc and free can be rather efficient for small objects. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are functions atomic?
[EMAIL PROTECTED] (Alex Martelli) wrote: Is there a reason for using the closure here? Using function defaults seems to give better performance: What measurements show you that...? ... brain:~ alex$ python -mtimeit -s'import powi; p=powi.powerfactory1(3)' 'p(27)' 100 loops, best of 3: 0.485 usec per loop brain:~ alex$ python -mtimeit -s'import powi; p=powi.powerfactory2(3)' 'p(27)' 100 loops, best of 3: 0.482 usec per loop Your own benchmark seems to support Michael's assertion although the difference in performance is so slight that it is unlikely ever to outweigh the loss in readability. Modifying powi.py to reduce the weight of the function call overhead and the exponent operation indicates that using default arguments is faster, but you have to push it to quite an extreme case before it becomes significant: def powerfactory1(exponent, plus): def inner(x): for i in range(1000): res = x+exponent+plus return res return inner def powerfactory2(exponent, plus): def inner(x, exponent=exponent, plus=plus): for i in range(1000): res = x+exponent+plus return res return inner C:\Temp\python25\python -mtimeit -s import powi; p=powi.powerfactory1 (3,999) p(27) 1 loops, best of 3: 159 usec per loop C:\Temp\python25\python -mtimeit -s import powi; p=powi.powerfactory2 (3,999) p(27) 1 loops, best of 3: 129 usec per loop -- http://mail.python.org/mailman/listinfo/python-list
Re: 32 OS on 64-bit machine
SamG wrote: If anyone has a x86_64 machine and is running a 32bit OS on top of that could you tell me what output would you get for the following program #== import platform print platform.processor() print platform.architecture() #== Thanks in advance : )~ Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import platform print platform.processor () print platform.architecture () ('32bit', 'WindowsPE') -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Bessel Functions
amit soni amitsoni.605 at gmail.com writes: Can anyone tell me what is the exact syntax for to use it. Thank you,Amit For example evaluating j1 @ 0 from scipy import special print special.j1(0) HTH, Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: 32 OS on 64-bit machine
On May 3, 2:58 pm, Harald Karner [EMAIL PROTECTED] wrote: SamG wrote: If anyone has a x86_64 machine and is running a 32bit OS on top of that could you tell me what output would you get for the following program #== import platform print platform.processor() print platform.architecture() #== Thanks in advance : )~ Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import platform print platform.processor () print platform.architecture () ('32bit', 'WindowsPE') Thanks, I would be more interested in the output on Linux's or Unix Thanks again : )~ -- http://mail.python.org/mailman/listinfo/python-list
Re: 32 OS on 64-bit machine
I have at home an AMD Turion 64 and using Ubuntu. You may be interested on this, i will post here the results when i get back home! -- http://mail.python.org/mailman/listinfo/python-list
Re: ignorance and intolerance in computing communties
As i have indicated in my post, it is non-trivial to implement a function that returns the positive angle of a vector. For example, it can be done with sign checking of the coordinate components (in total 4 cases, which can be done as 2 levels of nesting if, or simply 4 if.), and or the evaluation of Min[Abs[ArcCos[x],Abs[ArcSin[x]]], or use clever ways with dot product, or ArcTan. It is not a trivial to know which algorithm is in general more efficient. (this is important, since finding the angle of a vector is a basic function, that may needs to be called millions times directly or indirectly) Further, consider the inverse trig function, it is likely 99.99% of people with a PH D in math wouldn't know how these are actually implemented. So, the question of whether calling one of the inverse trig function is more robust or efficient than another is a open question. And, besides the algorithmic level, the question also entails how the language actually implement the inverse trig functions. Besides efficiency concerns, there's also robustness concerns. For example, if the 2 vectors are {1,0} and {0,1}, a simplistic implementation will result in division by 0 or similar errors. Checking whether one of them lies on the x or y axis means more if statements, as well the non-trivial problem of determining if two numbers are equal. (e.g. is 0.01 considered equal to 0.0001 ) Xah [EMAIL PROTECTED] ∑http://xahlee.org/ Xah could you please post staff related to lisp programming like above in separate thread from your personal things like someone banning you from the IRC. thanks bobi -- http://mail.python.org/mailman/listinfo/python-list
Re: 32 OS on 64-bit machine
SamG ha scritto: If anyone has a x86_64 machine and is running a 32bit OS on top of that could you tell me what output would you get for the following program I have a Athlon64 X2 with Debian unstable i386: [EMAIL PROTECTED] pts/0 ~]$ python Python 2.4.4 (#2, Apr 26 2007, 00:02:45) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type help, copyright, credits or license for more information. import platform print platform.processor() print platform.architecture() ('32bit', '') I also have a MacBook with a Core 2 Duo and Mac OS X 10.4.9 : [EMAIL PROTECTED] ttyp4 ~/Desktop/ETICS]$ python Python 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type help, copyright, credits or license for more information. import platform print platform.processor() i386 print platform.architecture() ('32bit', '') -- Mattia Gentilini Collaborator for ETICS project - http://eu-etics.org/ INFN - CNAF - RD Division - Bologna, Italy * Using Mac OS X 10.4.9 powered by Cerebros (Core 2 Duo) * -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check if a string is empty in python?
On May 2, 5:50 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 02 May 2007 13:35:47 -0700, noagbodjivictor wrote: How to check if a string is empty in python? if(s == ) ?? In no particular order, all of these methods will work: # test s is equal to another empty string if s == : # assuming s is a string, test that it is empty if not s: # test s is a string and it is empty if isinstance(s, str) and not s: # test s has length 0 if len(s) == 0: # test the length of s evaluates as false if not len(s): # a long way to test the length of s if s.__len__() 1: # a stupid way to test s is empty if bool(s) == False: # a REALLY stupid way to test s is empty if (bool(s) == False) == True: # test that appending s to itself is itself if s+s == s: Being the slow person that I am, it really did take me this long to find a mistake. s+s != 'appending' s+s == 'concatenation' # test that s has none of any character if not filter(None, [1 + s.find(chr(n)) for n in range(256)]): That last one is really only good for wasting CPU cycles. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to unicode line endings
On 2 May, 17:29, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 2 May 2007 09:19:25 -0700, [EMAIL PROTECTED] wrote: The code: import codecs udlASCII = file(c:\\temp\\CSVDB.udl,'r') udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16) udlUNI.write(udlASCII.read()) udlUNI.close() udlASCII.close() This doesn't seem to generate the correct line endings. Instead of converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as 0x0D/ 0x0A I have tried various 2 byte unicode encoding but it doesn't seem to make a difference. I have also tried modifying the code to read and convert a line at a time, but that didn't make any difference either. I have tried to understand the unicode docs but nothing seems to indicate why an seemingly incorrect conversion is being done. Obviously I am missing something blindingly obvious here, any help much appreciated. Consider this simple example: import codecs f = codecs.open('test-newlines-file', 'w', 'utf16') f.write('\r\n') f.close() f = file('test-newlines-file') f.read() '\xff\xfe\r\x00\n\x00' And how it differs from your example. Are you sure you're examining the resulting output properly? By the way, \r\0\n\0 isn't a unicode line ending, it's just the UTF-16 encoding of \r\n. Jean-Paul I am not sure what you are driving at here, since I started with an ascii file, whereas you just write a unicode file to start with. I guess the direct question is is there a simple way to convert my ascii file to a utf16 file?. I thought either string.encode() or writing to a utf16 file would do the trick but it probably isn't that simple! I used a binary file editor I have used a great deal for all sorts of things to get the hex values. Dom -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com.client Excel Color Porblem
Thanks a lot!! ici wrote: My Excel Template :) + Rows # -*- encoding:utf-8 -*- import win32com.client try: import psyco; psyco.full() except ImportError: pass try: app = win32com.client.Dispatch(Excel.Application.11) # Excel 2003 except com_error: try: app = win32com.client.Dispatch(Excel.Application.10) # Excel XP except com_error: try: app = win32com.client.Dispatch(Excel.Application.9) # Excel 2000 except com_error: try: app = win32com.client.Dispatch(Excel.Application.8) # Excel 97 except com_error: app = win32com.client.Dispatch(Excel.Application) # Excel 5.0? # Or raise No Office ... app.Visible = True wbk = app.Workbooks.Add() app.DisplayAlerts = False while wbk.Worksheets.Count 1: wbk.Worksheets[0].Delete() wbk.Worksheets[0].Name = SHIT sht = wbk.Worksheets[0] # Containers starts with 0! sht.Name += $ # Rows rng = sht.Rows(7) rng.Interior.ColorIndex = 6 sht.Rows(8).Interior.ColorIndex = 8 # Rows End app.DisplayAlerts = True wbk.SaveAs(rc:\temp\test.xls) app.Quit() -- http://mail.python.org/mailman/listinfo/python-list
Re: assigning to __class__ for an extension type: Is it still possible?
We have then added the Py_TPFLAGS_HEAPTYPE tp_flag, which turn _PClass into a heap class and should make this class assignment possible... A precision: it seems that just addind Py_TPFLAGS_HEAPTYPE flag in the PyTypeObject tp_flags is not all you have to do to turn a static type into a heap type: indeed, when doing such in the Noddy examples, I have a segfault when just typing: n=Noddy() n there is an access to the ht_name slot that is apparently non initialized... So Maybe the core of the problem is that I do not define the heap type correctlyDo anybody have (or can tell me where to find) a small example of an extension module defining a heap class? Similar to the Noddy examples from the python doc? I did not find any concrete example of Py_TPFLAGS_HEAPTYPE in the current doc or on the net... Best regards, Greg. -- http://mail.python.org/mailman/listinfo/python-list
Re: BUSTED!!! 100% VIDEO EVIDENCE that WTC7 was controlled demolition!! NEW FOOTAGE!!! Ask yourself WHY havn't I seen this footage before?
Ask yourself WHY havn't I seen this footage before? OK, why haven't you seen this footage before? -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
On May 2, 8:22 pm, sturlamolden [EMAIL PROTECTED] wrote: On Monday Microsoft announced a new runtime for dynamic languages, which they call DLR. It sits on top of the conventional .NET runtime (CLR) and provides services for dynamically typed languages like Python or Lisp (thus the cross-posting). Apparently is is distributed under a BSD-like open-source license. I am curious to know how it performs in comparison to CPython and an efficient compiled Lisp like CMUCL. Speed is a major problem with CPython but not with .NET or CMUCL, so it will be interesting to see how the DLR performs in comparison. It would be great to finally see a Python that runs on steroids, but knowing M$ bloatware my expectations are not too high. Has anyone looked at the DLR yet? What are your impression? Jim Hugunin har written about the DLR in his blog: http://blogs.msdn.com/hugunin/ To cite one of the comments: Fuck this microsoft bollocks! You just stole the Lisp runtime ideas and fucked them up by stupid it salesman lingo. (Khrishna) Sturla Molden If I looked at every crup they promote I would be braindead by now.Just look at the DataMining articles at Microsoft research. Piece of junk IMHO. Antoan -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to unicode line endings
On 3 May 2007 04:30:37 -0700, [EMAIL PROTECTED] wrote: On 2 May, 17:29, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 2 May 2007 09:19:25 -0700, [EMAIL PROTECTED] wrote: The code: import codecs udlASCII = file(c:\\temp\\CSVDB.udl,'r') udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16) udlUNI.write(udlASCII.read()) udlUNI.close() udlASCII.close() This doesn't seem to generate the correct line endings. Instead of converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as 0x0D/ 0x0A I have tried various 2 byte unicode encoding but it doesn't seem to make a difference. I have also tried modifying the code to read and convert a line at a time, but that didn't make any difference either. I have tried to understand the unicode docs but nothing seems to indicate why an seemingly incorrect conversion is being done. Obviously I am missing something blindingly obvious here, any help much appreciated. Consider this simple example: import codecs f = codecs.open('test-newlines-file', 'w', 'utf16') f.write('\r\n') f.close() f = file('test-newlines-file') f.read() '\xff\xfe\r\x00\n\x00' And how it differs from your example. Are you sure you're examining the resulting output properly? By the way, \r\0\n\0 isn't a unicode line ending, it's just the UTF-16 encoding of \r\n. Jean-Paul I am not sure what you are driving at here, since I started with an ascii file, whereas you just write a unicode file to start with. I guess the direct question is is there a simple way to convert my ascii file to a utf16 file?. I thought either string.encode() or writing to a utf16 file would do the trick but it probably isn't that simple! There's no such thing as a unicode file. The only difference between the code you posted and the code I posted is that mine is self-contained and demonstrates that the functionality works as you expected it to work, whereas the code you posted is requires external resources which are not available to run and produces external results which are not available to be checked regarding their correctness. So what I'm driving at is that both your example and mine are doing it correctly (because they are doing the same thing), and mine demonstrates that it is correct, but we have to take your word on the fact that yours doesn't work. ;) Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
sturlamolden [EMAIL PROTECTED] wrote: I am curious to know how it performs in comparison to CPython and an efficient compiled Lisp like CMUCL. Speed is a major problem with CPython but not with .NET or CMUCL, so it will be interesting to see how the DLR performs in comparison. It would be great to finally see a Python that runs on steroids, but knowing M$ bloatware my expectations are not too high. The video of Jim Hugunin's talk from MIX has a slide showing how many Pystones you get on some different versions of Python. Of course that is just one benchmark and not terribly relevant to any real applications, but if you do get a similar speedup in real code 'Python that runs on steroids' won't be far from the truth. The claimed figures were 50,000 Pystones for CPython 2.5, and 101,000 for the latest IronPython. (He didn't mention it, but I believe Psyco will outdo both of these.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing bitmap images for differences?
On May 2, 10:36 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks for the tip for an algorithm - I can see how that could work really nicely (and it gives me some ideas for other things, too!) Thanks also for the link to the OpenCV bindings. I'll give 'em a try and see what happens. I did similar stuff for a project at Uni, but for tracking pedestrians... in (eurgh) Java. Tad boring, but might help a little bit: http://uni.johnsto.co.uk/crowd/ Unfortunately it only got tested on pre-recorded feeds, not live ones. The background removal was fun. I think I ended up getting the background by converting every 5th frame to grayscale, and calculating the median for each pixel position across the sample. A couple filters to remove tiny 1 or 2 pixel specks of noise, and then went onto blob detection for identifying people and tracking their movement across the entire video. The same filtering in numpy should be really quite fast indeed! -- http://mail.python.org/mailman/listinfo/python-list
Re: passing an array of variant in vb to a python COM object = win32com bug ?
En Thu, 03 May 2007 04:54:43 -0300, vml [EMAIL PROTECTED] escribió: I have a python com object which contains a method to inverse an array in vb 6 the definition of the class is : class Fop: _public_methods_ = [ 'SqVal' ] def SqVal(self,*val): #vol=(val[0][0],val[0][1]) #mat1=mat((vol)) #up=linalg.inv(mat1) return str(val)#up _reg_verprogid_ = Python.Fop.3 _reg_progid_ = Python.Fop _reg_desc_ = Python Fop _reg_clsid_ = {30BD3490-2632-11cf-AD5B-524153480001} I pass to this method an array of variant which is the matrix to invert like that: vb6 code : Set obj = CreateObject(Python.Fop) Dim ty(1, 1) As Variant ty(0, 0) = 1 ty(1, 0) = 2 ty(0, 1) = 3 ty(1, 1) = 4 toto = obj.SqVal(ty) when I dispaly toto as str(val) I obtain the following tuple (((1, 3), (2, 4)),) which is not usable Do you have an idea to explain this strange behaviour ? This is the expected behaviour. Writing it completely in Python: py def SqVal(*val): ... return str(val) ... py ty=((1,3),(2,4)) py SqVal(ty) '(((1, 3), (2, 4)),)' The *val parameter receives a tuple, whose elements are the positional arguments used when calling the function. As you call the function with a single argument, val receives a tuple with a single element. Perhaps you want to write it as: py def SqVal(val): ... print val[0][0] ... print val[0][1] ... print val[1][0] ... print val[1][1] ... py SqVal(ty) 1 3 2 4 (Of course, if used as a Fop method, dont forget the self parameter) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to unicode line endings
On 2 May 2007 09:19:25 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The code: import codecs udlASCII = file(c:\\temp\\CSVDB.udl,'r') udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16) udlUNI.write(udlASCII.read()) udlUNI.close() udlASCII.close() This doesn't seem to generate the correct line endings. Instead of converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as 0x0D/ 0x0A That code (using my own local files, of course) basically works for me. If I open my input file with mode 'r', as you did above, my '\r\n' pairs get transformed to '\n' when I read them in and are written to my output file as 0x00 0x0A. If I open the input file in binary mode 'rb' then my output file shows the expected sequence of 0x00 0x0D 0x00 0x0A. Perhaps there's a quirk of your version of python or your platform? I'm running Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Firefighters at the site of WTC7 Move away the building is going to blow up, get back the building is going to blow up.
On 2 May 2007 20:10:20 -0700, Midex [EMAIL PROTECTED] wrote: LIES LIES LIES LIES LIES Trying to understand the World Trade Center events is like waking up to act fifteen of a long Greek Tragedy. It needs a complex fabric of description to give a full picture. In explaining this crisis, we will be showing how the situation rests on layers of historical developments, layers of crises and solutions. shamelessly taken from: http://www.againstsleepandnightmare.com/ASAN/ASAN7/ASAN7.html The World After September 11th, 2001 The Old Mole By the time you read this, a crisis different from September 11th may well be foremost in people's minds. Read on. For us today, all the crises merge to one and we can see the form of Enron's Collapse or the Iraq War within September 11th and vice-versa. Now, beyond the death and destruction, the horror of an event like September 11th is the horror of losing control of your world. This feeling is an extension of the ordinary experience of being a resident of modern capitalist society. Here, work, commuting, shopping, and television are transmitted to you in ways that are beyond any individual or collective control. Damn good read. -- == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
file Error
Hi, I am parsing an xml file,and using raw_input command to ask the user to enter the file name.Ex Enter The ODX File Path: Suppose my code does not work properly,then in the python idle window it shows something like this: C:\Projects\ODX Import\Sample Files\MiscFiles \CIM_A3300_diag_spec_sw49.xml Traceback (most recent call last): File C:\Projects\ODX Import\code_ini\odxparse_mod_off_comm.py, line 339, in module process_variant(variant) File C:\Projects\ODX Import\code_ini\odxparse_mod_off_comm.py, line 285, in process_variant triplet = triplet + get_did_lengths(iservice,local_service_id) File C:\Projects\ODX Import\code_ini\odxparse_mod_off_comm.py, line 238, in get_did_lengths local_min = local_min + ddoref_min[ddorefstring] KeyError: '_210' This is some bug related to code ..thats ok..but when i run the program immediately again for some other input..then it does not show the prompt : Enter The ODX File Path: but instead a blinking prompt which accepts the filename something like this: C:\Projects\ODX Import\Sample Files\MiscFiles\Diagnostic CTS Global Epsilon TIM V1.4.xml I want the inputfile prompt to appear regardless of the error condition.I dont know where the problem lies.Can someone help me out. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check if a string is empty in python?
On May 3, 5:59 am, [EMAIL PROTECTED] (Alex Martelli) wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 02 May 2007 21:19:54 -0400, Roy Smith wrote: for c in s: raise it's not empty String exceptions are depreciated and shouldn't be used. http://docs.python.org/api/node16.html They're actually deprecated, not depreciated. In Steven's defence, string exceptions *are* probably worth less, as there's no longer such a demand for them. -- Ant... -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
On 3 May 2007 12:13:49 GMT, Duncan Booth [EMAIL PROTECTED] wrote: sturlamolden [EMAIL PROTECTED] wrote: I am curious to know how it performs in comparison to CPython and an efficient compiled Lisp like CMUCL. Speed is a major problem with CPython but not with .NET or CMUCL, so it will be interesting to see how the DLR performs in comparison. It would be great to finally see a Python that runs on steroids, but knowing M$ bloatware my expectations are not too high. The video of Jim Hugunin's talk from MIX has a slide showing how many Pystones you get on some different versions of Python. Of course that is just one benchmark and not terribly relevant to any real applications, but if you do get a similar speedup in real code 'Python that runs on steroids' won't be far from the truth. The claimed figures were 50,000 Pystones for CPython 2.5, and 101,000 for the latest IronPython. (He didn't mention it, but I believe Psyco will outdo both of these.) fwiw, my desktop happens to do 50,000 pystones with cpython 2.4 and 294,000 pystones with cpython 2.4 and psyco.full() Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Lazy evaluation: overloading the assignment operator?
On 2007-05-03, sturlamolden [EMAIL PROTECTED] wrote: On May 3, 6:22 am, Charles Sanders [EMAIL PROTECTED] wrote: y = a*b+c*d # Returns a proxy object x = y[4] # Computes x = a[4]*b[4] + c[4]*d[4] v = y.eval() # Evaluates all elements, returning Xarray z = ((a+b)*(c+d)).eval() # Also evaluates all elements When I suggested this on the NumPy mailing list, I too suggested using the indexing operator to trigger the computations. But I am worried that if an expression like y = a*b+c*d returns a proxy, it is somehow possible to mess things up by creating cyclically dependent proxies. I may be wrong about this, in which case __getitem__ et al. will do the job. How do you expect to handle the following kind of situation: while condition: x = y a = ... b = ... y = a * x + b -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: passing an array of variant in vb to a python COM object = win32com bug ?
On 3 mai, 14:20, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 03 May 2007 04:54:43 -0300, vml [EMAIL PROTECTED] escribió: I have a python com object which contains a method to inverse an array in vb 6 the definition of the class is : class Fop: _public_methods_ = [ 'SqVal' ] def SqVal(self,*val): #vol=(val[0][0],val[0][1]) #mat1=mat((vol)) #up=linalg.inv(mat1) return str(val)#up _reg_verprogid_ = Python.Fop.3 _reg_progid_ = Python.Fop _reg_desc_ = Python Fop _reg_clsid_ = {30BD3490-2632-11cf-AD5B-524153480001} I pass to this method an array of variant which is the matrix to invert like that: vb6 code : Set obj = CreateObject(Python.Fop) Dim ty(1, 1) As Variant ty(0, 0) = 1 ty(1, 0) = 2 ty(0, 1) = 3 ty(1, 1) = 4 toto = obj.SqVal(ty) when I dispaly toto as str(val) I obtain the following tuple (((1, 3), (2, 4)),) which is not usable Do you have an idea to explain this strange behaviour ? This is the expected behaviour. Writing it completely in Python: py def SqVal(*val): ... return str(val) ... py ty=((1,3),(2,4)) py SqVal(ty) '(((1, 3), (2, 4)),)' The *val parameter receives a tuple, whose elements are the positional arguments used when calling the function. As you call the function with a single argument, val receives a tuple with a single element. Perhaps you want to write it as: py def SqVal(val): ... print val[0][0] ... print val[0][1] ... print val[1][0] ... print val[1][1] ... py SqVal(ty) 1 3 2 4 (Of course, if used as a Fop method, dont forget the self parameter) -- Gabriel Genellina I just tried to replace the *val by SqVal(self,val) and call the method in vb but it crashes down : when refilling safe array the sequence must have the same number of dimension as the existing array my python code is now : def SqVal(self,val): ##volr=[val[0][0][i] for i in range(size(val,2))] ##voli=[val[0][1][i] for i in range(size(val,2))] ##mat1=mat(volr)+1j*mat(voli) ##up=linalg.pinv(mat1) ##out=up.real.tolist() ##out.extend(up.imag.tolist()) return val By the way Do you have any idea to debug the com server script ? ( I would like to know if a can access the value in the function while calling it from vb 6) tahnks a lot ! -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to unicode line endings
On 3 May, 13:00, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 3 May 2007 04:30:37 -0700, [EMAIL PROTECTED] wrote: On 2 May, 17:29, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 2 May 2007 09:19:25 -0700, [EMAIL PROTECTED] wrote: The code: import codecs udlASCII = file(c:\\temp\\CSVDB.udl,'r') udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16) udlUNI.write(udlASCII.read()) udlUNI.close() udlASCII.close() This doesn't seem to generate the correct line endings. Instead of converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as 0x0D/ 0x0A I have tried various 2 byte unicode encoding but it doesn't seem to make a difference. I have also tried modifying the code to read and convert a line at a time, but that didn't make any difference either. I have tried to understand the unicode docs but nothing seems to indicate why an seemingly incorrect conversion is being done. Obviously I am missing something blindingly obvious here, any help much appreciated. Consider this simple example: import codecs f = codecs.open('test-newlines-file', 'w', 'utf16') f.write('\r\n') f.close() f = file('test-newlines-file') f.read() '\xff\xfe\r\x00\n\x00' And how it differs from your example. Are you sure you're examining the resulting output properly? By the way, \r\0\n\0 isn't a unicode line ending, it's just the UTF-16 encoding of \r\n. Jean-Paul I am not sure what you are driving at here, since I started with an ascii file, whereas you just write a unicode file to start with. I guess the direct question is is there a simple way to convert my ascii file to a utf16 file?. I thought either string.encode() or writing to a utf16 file would do the trick but it probably isn't that simple! There's no such thing as a unicode file. The only difference between the code you posted and the code I posted is that mine is self-contained and demonstrates that the functionality works as you expected it to work, whereas the code you posted is requires external resources which are not available to run and produces external results which are not available to be checked regarding their correctness. So what I'm driving at is that both your example and mine are doing it correctly (because they are doing the same thing), and mine demonstrates that it is correct, but we have to take your word on the fact that yours doesn't work. ;) Jean-Paul Thanks for the advice. I cannot prove what is going on. The following code seems to work fine as far as console output goes, but the actual bit patterns of the files on disk are not what I am expecting (or expected as input by the ultimate user of the converted file). Which I can't prove of course. import codecs testASCII = file(c:\\temp\\test1.txt,'w') testASCII.write(\n) testASCII.close() testASCII = file(c:\\temp\\test1.txt,'r') testASCII.read() '\n' Bit pattern on disk : \0x0D\0x0A testASCII.seek(0) testUNI = codecs.open(c:\\temp\\test2.txt,'w','utf16') testUNI.write(testASCII.read()) testUNI.close() testUNI = file(c:\\temp\\test2.txt,'r') testUNI.read() '\xff\xfe\n\x00' Bit pattern on disk:\0xff\0xfe\0x0a\0x00 Bit pattern I was expecting:\0xff\0xfe\0x0d\0x00\0x0a\0x00 testUNI.close() Dom -- http://mail.python.org/mailman/listinfo/python-list
Re: BUSTED!!! 100% VIDEO EVIDENCE that WTC7 was controlled demolition!! NEW FOOTAGE!!! Ask yourself WHY havn't I seen this footage before?
Peter Webb wrote: Ask yourself WHY havn't I seen this footage before? OK, why haven't you seen this footage before? Nice response ! Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to unicode line endings
On 3 May, 13:39, Jerry Hill [EMAIL PROTECTED] wrote: On 2 May 2007 09:19:25 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The code: import codecs udlASCII = file(c:\\temp\\CSVDB.udl,'r') udlUNI = codecs.open(c:\\temp\\CSVDB2.udl,'w',utf_16) udlUNI.write(udlASCII.read()) udlUNI.close() udlASCII.close() This doesn't seem to generate the correct line endings. Instead of converting 0x0D/0x0A to 0x0D/0x00/0x0A/0x00, it leaves it as 0x0D/ 0x0A That code (using my own local files, of course) basically works for me. If I open my input file with mode 'r', as you did above, my '\r\n' pairs get transformed to '\n' when I read them in and are written to my output file as 0x00 0x0A. If I open the input file in binary mode 'rb' then my output file shows the expected sequence of 0x00 0x0D 0x00 0x0A. Perhaps there's a quirk of your version of python or your platform? I'm running Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 -- Jerry Thanks very much! Not sure if you intended to fix my whole problem, but changing the read mode to 'rb' has done the trick :) Dom -- http://mail.python.org/mailman/listinfo/python-list
Re: hp 11.11 64 bit python 2.5 build gets error import site failed
On May 2, 5:09 pm, Martin v. Löwis [EMAIL PROTECTED] wrote: import site failed OverflowError: signed integer is greater than the maximum. This is happening in the convertsimple() routine when it tries to return a signed int: ival = PyInt_AsLong(arg) the ival is larger than what is defined in INT_MAX. Why is this happening in a standard HP 64 bit build? Can you provide a complete gdb/dbx backtrace? Some function tries to convert a Python int into a C int, using the i conversion character. Python int uses C long for internal representation, and that particular C long happens to be larger than INT_MAX. This is quite reasonable to happen in principle, but shouldn't happen on interpreter startup. So the questions are: - what are the callers of convertsimple here? (in particular, where does the call to PyArg_ParseTuple come from?) - what is the value of ival? - where does that number come from? The first two questions are best answered with a C debugger. Depending on the answer, the third question may nor may not need an answer. Good luck, Martin P.S. If you are asking in the more abstract sense why is that happening to me?, the answer is because you are using an uncommon platform on which Python sees little or no testing. To work around, try a 32-bit build, or switch to Solaris, OS X, Debian Linux, or (heaven forbid) MS Windows :-) - what are the callers of convertsimple here? (in particular, where does the call to PyArg_ParseTuple come from?) since the debugger locks up when I run, here is a printf call stack of where things are happening: import site # precompiled from ... builtin___import__ PyArg_ParseTupleAndKeywords vgetargskeywords: positional arg: 0 convertitem vgetargskeywords: positional arg: 1 convertitem vgetargskeywords: positional arg: 2 convertitem vgetargskeywords: positional arg: 3 convertitem vgetargskeywords: positional arg: 4 convertitem - what is the value of ival? ival: 4294967295 - where does that number come from? It is coming from the call to PyInt_AsLong. In that function there is a call to: PyInt_AS_LONG((PyIntObject*)op) which returns the value of ival. I wish we could just skip this port, but it is required for our product that we have HP 64 bit. This did not happen with python 2.3.1 or 2.0. Thanks for the help. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: file Error
En Thu, 03 May 2007 09:39:37 -0300, [EMAIL PROTECTED] escribió: Hi, I am parsing an xml file,and using raw_input command to ask the user to enter the file name.Ex Enter The ODX File Path: Suppose my code does not work properly,then in the python idle window it shows something like this: [...traceback...] I want the inputfile prompt to appear regardless of the error condition.I dont know where the problem lies.Can someone help me out. - IDLE is a development environment - don't use it to actually run your program in production. - Instead of asking the user to type the file name, accept it as a parameter, that's what almost everyone else does in the world... It has many advantages: you can associate your program with the filename extension, you can use the Send to... menu, you can run it inside a batch file, you can drop a file over your program to be processed, etc. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling Infinite Loops on Server Applications
En Wed, 02 May 2007 21:38:52 -0300, Paul Kozik [EMAIL PROTECTED] escribió: I'm working with a small server program I'm writing for a small video game. The main class constructor starts a thread that handles socket connections, which itself starts new threads for each user connection. And what's the purpose of the main thread then? The actual server program itself however needs to wait in the background, but continue looping as not to close the running threads. The problem is, simply running a [while True: pass] main loop in this style eats precious CPU cycles (and for nothing). If it waits for input, such as a socket.accept() or raw_input(), this problem does not occur (obviously because it's not constantly looping). Exactly. Use the network handling thread as the main thread, by example. What would be the best way to handle this, perhaps in a fashion similar to how most server programs are handled (with arguments such as [apache start], [apache stop])? Any guides towards this type of application development? See the asyncore module, or any of the predefined servers in the Python library. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: file Error
On May 3, 6:09 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 03 May 2007 09:39:37 -0300, [EMAIL PROTECTED] escribió: Hi, I am parsing an xml file,and using raw_input command to ask the user to enter the file name.Ex Enter The ODX File Path: Suppose my code does not work properly,then in the python idle window it shows something like this: [...traceback...] I want the inputfile prompt to appear regardless of the error condition.I dont know where the problem lies.Can someone help me out. - IDLE is a development environment - don't use it to actually run your program in production. - Instead of asking the user to type the file name, accept it as a parameter, that's what almost everyone else does in the world... It has many advantages: you can associate your program with the filename extension, you can use the Send to... menu, you can run it inside a batch file, you can drop a file over your program to be processed, etc. -- Gabriel Genellina Thanks for the replyHow do i accept the filename is a parameter and avoid the error.Can you elaborate. -- http://mail.python.org/mailman/listinfo/python-list
SQLObject 0.7.6
Hello! I'm pleased to announce the 0.7.6 release of SQLObject. What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.7.6 News and changes: http://sqlobject.org/docs/News.html What's New == News since 0.7.5 Bug Fixes - * Fixed a longstanding bug with .select() ignoring 'limit' parameter. * Fixed a bug with absent comma in JOINs. * Fixed sqlbuilder - .startswith(), .endswith() and .contains() assumed their parameter must be a string; now you can pass an SQLExpression: Table.q.name.contains(func.upper('a')), for example. * Fixed a longstanding bug in sqlbuilder.Select() with groupBy being a sequence. * Fixed a bug with Aliases in JOINs. * Yet another patch to properly initialize MySQL connection encoding. * Fixed a minor comparison problem in test_decimal.py. Docs * Added documentation about 'validator' Col constructor option. * More documentation about orderBy. For a more complete list, please see the news: http://sqlobject.org/docs/News.html Oleg. -- Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: passing an array of variant in vb to a python COM object = win32com bug ?
vml wrote: On 3 mai, 14:20, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 03 May 2007 04:54:43 -0300, vml [EMAIL PROTECTED] escribió: I have a python com object which contains a method to inverse an array in vb 6 the definition of the class is : class Fop: _public_methods_ = [ 'SqVal' ] def SqVal(self,*val): #vol=(val[0][0],val[0][1]) #mat1=mat((vol)) #up=linalg.inv(mat1) return str(val)#up _reg_verprogid_ = Python.Fop.3 _reg_progid_ = Python.Fop _reg_desc_ = Python Fop _reg_clsid_ = {30BD3490-2632-11cf-AD5B-524153480001} I pass to this method an array of variant which is the matrix to invert like that: vb6 code : Set obj = CreateObject(Python.Fop) Dim ty(1, 1) As Variant ty(0, 0) = 1 ty(1, 0) = 2 ty(0, 1) = 3 ty(1, 1) = 4 toto = obj.SqVal(ty) when I dispaly toto as str(val) I obtain the following tuple (((1, 3), (2, 4)),) which is not usable Do you have an idea to explain this strange behaviour ? This is the expected behaviour. Writing it completely in Python: py def SqVal(*val): ... return str(val) ... py ty=((1,3),(2,4)) py SqVal(ty) '(((1, 3), (2, 4)),)' The *val parameter receives a tuple, whose elements are the positional arguments used when calling the function. As you call the function with a single argument, val receives a tuple with a single element. Perhaps you want to write it as: py def SqVal(val): ... print val[0][0] ... print val[0][1] ... print val[1][0] ... print val[1][1] ... py SqVal(ty) 1 3 2 4 (Of course, if used as a Fop method, dont forget the self parameter) -- Gabriel Genellina I just tried to replace the *val by SqVal(self,val) and call the method in vb but it crashes down : when refilling safe array the sequence must have the same number of dimension as the existing array my python code is now : def SqVal(self,val): ##volr=[val[0][0][i] for i in range(size(val,2))] ##voli=[val[0][1][i] for i in range(size(val,2))] ##mat1=mat(volr)+1j*mat(voli) ##up=linalg.pinv(mat1) ##out=up.real.tolist() ##out.extend(up.imag.tolist()) return val By the way Do you have any idea to debug the com server script ? ( I would like to know if a can access the value in the function while calling it from vb 6) tahnks a lot ! Debugging COM objects is best done using logging module or at least writing to a file during processing. You can review the log file to see what was going on. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check if a string is empty in python?
In article [EMAIL PROTECTED], Ant [EMAIL PROTECTED] wrote: On May 3, 5:59 am, [EMAIL PROTECTED] (Alex Martelli) wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 02 May 2007 21:19:54 -0400, Roy Smith wrote: for c in s: raise it's not empty String exceptions are depreciated and shouldn't be used. http://docs.python.org/api/node16.html They're actually deprecated, not depreciated. In Steven's defence, string exceptions *are* probably worth less, as there's no longer such a demand for them. You just wait until they start showing up on Antiques Roadshow :-) -- http://mail.python.org/mailman/listinfo/python-list
SQLObject 0.8.3
Hello! I'm pleased to announce the 0.8.3 release of SQLObject. What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.8.3 News and changes: http://sqlobject.org/News.html What's New == News since 0.8.2 Bug Fixes - * Fixed a longstanding bug with .select() ignoring 'limit' parameter. * Fixed a bug with absent comma in JOINs. * Fixed sqlbuilder - .startswith(), .endswith() and .contains() assumed their parameter must be a string; now you can pass an SQLExpression: Table.q.name.contains(func.upper('a')), for example. * Fixed a longstanding bug in sqlbuilder.Select() with groupBy being a sequence. * Fixed a bug with Aliases in JOINs. * Yet another patch to properly initialize MySQL connection encoding. * Fixed a minor comparison problem in test_decimal.py. Docs * Added documentation about 'validator' Col constructor option. * Added an answer and examples to the FAQ on how to use sqlmeta.createSQL. * More documentation about orderBy. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: BUSTED!!! 100% VIDEO EVIDENCE that WTC7 was controlled demolition!! NEW FOOTAGE!!! Ask yourself WHY havn't I seen this footage before?
On May 2, 10:24 pm, Major Quaternion Dirt Quantum [EMAIL PROTECTED] wrote: maybe, pulled is just a firefighteresque synonym for gravity doing its thing -- still not subsumed in the Standard Model of physicists, so, There. y'know, sort of like, how it is, pilots refer to going out and in, instead of up down. You can also try pull as a term for a general alarm that says get everyone out of there. It could be from pull the alarm a term for triggering an alarm manually or pull the troops out a term for getting soldiers out of a location. [.] thus: if you can't prove that all Fermat numbers are pairwise coprime, again! But but I've got a video of someone saying it. That *proves* it doesn't it. -- http://mail.python.org/mailman/listinfo/python-list
Re: My Python annoyances
I rewrote my code in Python and I found myself running into many of the same hassles that I run into with other languages: inaccurate and incomplete documentation, a maze of little platform-specific quirks to work around in the base classes, and a macho community of users. The python web site recommended Dive Into Python, so I learned by reading that. It has several examples that don't work because the Python base classes have changed behavior. I should have taken that as lesson. I tried to write portable Python code. The zlib CRC function returned different results on architectures between 32 bit and 64 bit architectures. I filed a bug report. It was closed, without a comment from the person who closed it. I get the unspoken message: bug reports are not welcome. I installed Cygwin on a Windows machine. I try to quit from an interactive Python session. It tells me that on my platform, I must press Control-Z to exit. I press Control-Z and it makes Python a background process. I tried to use the XML.minidom. The documentation here is minimal as well. So I read up on other web sites. It turns out that the interface has changed quite a bit from the documentation I found on other web sites. Where are the much loved docstrings? In 2.3 minidom, they are sparse and cryptic. Between 2.4 and 2.5, tempfile returns a different type of object. My code cannot have a single test, it has check for type(obj) == file or obj.__class__ == tempfile._TemporaryFileWrapper. I decided to make a tkinter front-end for a Python program. I decided to go with tkinter because it is included with many Python installations, so it maximizes the chance for my program to run out of the box. The tkinter documentation on the Python site mainly consists of loose notes and links to other sites. The documentation on other sites is great, if you already know how to use tkinter. I ran into bugs in TkAqua which make the grid layout unusable for me. So I will need to ask potential users to install Xcode, X11, and mac ports, if they want to run my program. In short, there is plenty of room for improvement. Admittedly these are not problems with the language definition. But I downloaded a Python distribution, and the problems are Python specific. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python user group in Portland, OR?
bradallen wrote: I would be happy to meet with you and any other Portland Python programmers to talk about ideas for organizing a user group. There is also some good discussion about it on the Python Advocacy the mailing list, because PSF has begun an effort to foster and promote user groups. I don't use Ruby, but I read the blog of a dude in Portland who went to the Ruby user group. He said that the programmers there spent as much time talking about Python and Perl as they did about Ruby, so you might be interested in that. Ben -- http://mail.python.org/mailman/listinfo/python-list
Sybase module 0.38 released
WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. The module is available here: http://downloads.sourceforge.net/python-sybase/python-sybase-0.38.tar.gz The module home page is here: http://python-sybase.sourceforge.net/ CHANGES SINCE 0.38pre2: * Corrected bug in databuf_alloc: Sybase reports the wrong maxlength for numeric type - verified with Sybase 12.5 - thanks to patch provided by Phil Porter MAJOR CHANGES SINCE 0.37: * This release works with python 2.5 * It also works with sybase 15 * It works with 64bits clients * It can be configured to return native python datetime objects * The bug This routine cannot be called because another command structure has results pending. which appears in various cases has been corrected * It includes a unitary test suite based on the dbapi2.0 compliance test suite -- http://mail.python.org/mailman/listinfo/python-list
pyscripter to slow
I have some problem with pyscripter. Sometimes when I type pyscripter get to slow (i type 10 chars and pyscripter needs 5 seconds to complete this). This happens mostly on deleting some chars. It is very frustrating. Does someone have same situation? btw My comp is amd athlon x2 4000 2mb cache sapphire am2rd580adv 3200 ati chipset 2GB corsair xm2 sapphire x1650 pro 256mb windows vista -- http://mail.python.org/mailman/listinfo/python-list
newbie: copy base class fields
Hello, Thanks for your time. The following small program gives an error: #!/usr/bin/python # class A: def __init__(self): self.v1=1 def __repr__(self): return v1=%d\n % self.v1 class B(A): def __init__(self,a): self=a self.v2=2 def __repr__(self): return A.__repr__(self) + (v2=%d\n % self.v2) x=A() print x y=B(x) print y $ ./prueba.pl v1=1 Traceback (most recent call last): File ./prueba.pl, line 23, in module print y File ./prueba.pl, line 17, in __repr__ return A.__repr__(self) + (v2=%d\n % self.v2) File ./prueba.pl, line 9, in __repr__ return v1=%d\n % self.v1 AttributeError: B instance has no attribute 'v1' It seems that the statement self=a is not the correct way to copy all the fields of the base class from the __init__ argument to the new object. Of course, it is not an option to copy one by one all the fields of class A inside the __init__ of B. Several variants of the program produces similar results. Please, could someone explain which way is the correct way? Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLObject 0.8.3
Oleg Broytmann [EMAIL PROTECTED] writes: * Fixed sqlbuilder - .startswith(), .endswith() and .contains() assumed their parameter must be a string; now you can pass an SQLExpression: Table.q.name.contains(func.upper('a')), for example. Oleg, this made me think: is it possible to call a function in a schema other than public in PostgreSQL? For example if I had myschema.myfunction and wanted to use it I can't do func.myschema.myfunction... Is there something like a dbName for func? :-) -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: My Python annoyances
On 3 Mai, 15:49, Ben Collver [EMAIL PROTECTED] wrote: I rewrote my code in Python and I found myself running into many of the same hassles that I run into with other languages: inaccurate and incomplete documentation, a maze of little platform-specific quirks to work around in the base classes, and a macho community of users. I'm sorry to hear about that. If by macho you mean people who insist that things are good enough as they are, and that newcomers should themselves adapt to whatever they may discover, instead of things being improved so that they are more intuitive and reliable for newcomers and experienced developers alike, then I'd certainly be interested in undermining that culture. The python web site recommended Dive Into Python, so I learned by reading that. It has several examples that don't work because the Python base classes have changed behavior. I should have taken that as lesson. Really Dive Into Python should be a sufficient guide, and it was perhaps the best introduction to the language when it was written. It is very unfortunate that the language has changed in a number of ways (and exhibits continued change) whilst effort into documenting what is already there remains neglected amongst the people making all the changes. I tried to write portable Python code. The zlib CRC function returned different results on architectures between 32 bit and 64 bit architectures. I filed a bug report. It was closed, without a comment from the person who closed it. I get the unspoken message: bug reports are not welcome. Can you provide the bug identifier? Bug reports are generally welcome, and despite complaints about patch reviews, I've found people reviewing things I've submitted. I installed Cygwin on a Windows machine. I try to quit from an interactive Python session. It tells me that on my platform, I must press Control-Z to exit. I press Control-Z and it makes Python a background process. Yes, Ctrl-Z exits Python in the standard Windows edition. Since Cygwin provides a POSIX-like environment, Ctrl-D should be used instead. If the documentation is wrong, a bug report or patch should be filed against the software. I tried to use the XML.minidom. The documentation here is minimal as well. So I read up on other web sites. It turns out that the interface has changed quite a bit from the documentation I found on other web sites. Where are the much loved docstrings? In 2.3 minidom, they are sparse and cryptic. I really don't know what to say about the PyXML/xmlcore situation. I don't use ElementTree and hardly use PyXML or minidom, but something really should have been done about the maintenance of the established libraries rather than declaring them as legacy items and pretending that they don't exist. Between 2.4 and 2.5, tempfile returns a different type of object. My code cannot have a single test, it has check for type(obj) == file or obj.__class__ == tempfile._TemporaryFileWrapper. Try using isinstance or relying on deeper knowledge of how the object will be used. I decided to make a tkinter front-end for a Python program. I decided to go with tkinter because it is included with many Python installations, so it maximizes the chance for my program to run out of the box. The tkinter documentation on the Python site mainly consists of loose notes and links to other sites. The documentation on other sites is great, if you already know how to use tkinter. I ran into bugs in TkAqua which make the grid layout unusable for me. So I will need to ask potential users to install Xcode, X11, and mac ports, if they want to run my program. Take a look at the python.org Wiki for links to other resources on Tkinter: http://wiki.python.org/moin/TkInter Or consider other graphical frameworks: http://wiki.python.org/moin/GuiProgramming In short, there is plenty of room for improvement. Admittedly these are not problems with the language definition. But I downloaded a Python distribution, and the problems are Python specific. My opinions, already expressed, include the observation that the core development community is more interested in extending the language than in strengthening the standard library (and its documentation). It should be noted that the proposed standard library reorganisation, which is a very conservative affair, has actually been postponed until after the release of Python 3.0a1 according to a message I read recently. And yet, if you read people's lists about what they hate about Python (amongst actual users of Python), guess which thing almost always comes up? http://www.google.com/search?q=%22things+I+hate+about+Python%22 Paul -- http://mail.python.org/mailman/listinfo/python-list
How to replace the last (and only last) character in a string?
Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s[len(s)-1],'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why? Thanks L. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: copy base class fields
In [EMAIL PROTECTED], tmp123 wrote: The following small program gives an error: #!/usr/bin/python # class A: def __init__(self): self.v1=1 def __repr__(self): return v1=%d\n % self.v1 class B(A): def __init__(self,a): self=a self.v2=2 def __repr__(self): return A.__repr__(self) + (v2=%d\n % self.v2) x=A() print x y=B(x) print y $ ./prueba.pl v1=1 Traceback (most recent call last): File ./prueba.pl, line 23, in module print y File ./prueba.pl, line 17, in __repr__ return A.__repr__(self) + (v2=%d\n % self.v2) File ./prueba.pl, line 9, in __repr__ return v1=%d\n % self.v1 AttributeError: B instance has no attribute 'v1' It seems that the statement self=a is not the correct way to copy all the fields of the base class from the __init__ argument to the new object. This binds the local name `self` to the same object that is bound to `a`. Now you have lost the reference to the instance, so the next line sets the attribute `v2` on the object passed to the constructor of the `B` object. Of course, it is not an option to copy one by one all the fields of class A inside the __init__ of B. Several variants of the program produces similar results. Please, could someone explain which way is the correct way? Call the `__init__()` of `A`: class B(A): def __init__(self, a): A.__init__(self) self.v2 = 2 Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite for mac?
Does sqlite come in a mac version? The interface (pysqlite) is part of the python 2.5 standard library but you need to install sqlite itself separately (as far as I remember) fromwww.sqlite.org http://developer.apple.com/documentation/MacOSX/Conceptual/OSX_Techno... I downloaded pysqlite, ran the setup script, and tested the installation and everything worked fine. However, if I try to import either sqlite, sqlite2, or sqlite3 into a python program, I get an error saying there's no such module. I assume that means pysqlite cannot see the installation of SQlite that came preinstalled on my mac. My python book says to download the SQlite source where automatic code generation has already been performed. I did that. Then my book says says to follow the instructions in the README file. However, the download only has two files: sqlite3.c and sqlite3.h. As a result, I don't know what to do. If all tests ran fine then pysqlite can see your sqlite installation. How are you importing sqlite? It's usually something like from pysqlite2 import dbapi2 as sqlite not simply import sqlite. If you go to the test directory where everything works you can see how those modules import it and that should definitely work for you as well. HTH, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to unicode line endings
In [EMAIL PROTECTED], fidtz wrote: import codecs testASCII = file(c:\\temp\\test1.txt,'w') testASCII.write(\n) testASCII.close() testASCII = file(c:\\temp\\test1.txt,'r') testASCII.read() '\n' Bit pattern on disk : \0x0D\0x0A testASCII.seek(0) testUNI = codecs.open(c:\\temp\\test2.txt,'w','utf16') testUNI.write(testASCII.read()) testUNI.close() testUNI = file(c:\\temp\\test2.txt,'r') testUNI.read() '\xff\xfe\n\x00' Bit pattern on disk:\0xff\0xfe\0x0a\0x00 Bit pattern I was expecting:\0xff\0xfe\0x0d\0x00\0x0a\0x00 testUNI.close() Files opened with `codecs.open()` are always opened in binary mode. So if you want '\n' to be translated into a platform specific character sequence you have to do it yourself. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: How to replace the last (and only last) character in a string?
On May 3, 9:27 am, Johny [EMAIL PROTECTED] wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s[len(s)-1],'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why? Thanks L. I think the reason it's not working is because you're doing it kind of backwards. For one thing, the string module is deprecated. I would do it like this: s = s.replace(s[len(s)-1], 'r') Although that is kind of hard to read. But it works. Mike -- http://mail.python.org/mailman/listinfo/python-list
getmtime in 2.5 reports GMT instead of local time
Hello, I have tried this only on Windows XP. in Python 2.4 os.path.getmtime() used to return an integer representing the local time. in Python 2.5 os.path.getmtime() reports a float representing the GMT of the file's modification time. Since I could not find any documentation to this behavioural change, I am asking here: was this change intentional? Is it going to stay? Windows reports the same time for the file as Python 2.4 used to. So I am tempted to call this a bug, but wanted some feedback from the developers, before filing a bug report. If you want to test this, make sure your local time differs from GMT, then do: import os, time print time.ctime(os.path.getmtime('foo.txt')) on a file foo.txt, once with Python 2.4 then with Python 2.5, and you should see what I mean. - Josef -- http://mail.python.org/mailman/listinfo/python-list
Library Naming
I'm taking a pole on how best to name programming library packages. If you have a second, please have a look. http://7ranscode.blogspot.com/2007/05/library-poll.html Thanks, T. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: copy base class fields
On May 3, 4:29 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: #!/usr/bin/python # class A: def __init__(self): self.v1=1 def __repr__(self): return v1=%d\n % self.v1 class B(A): def __init__(self,a): self=a self.v2=2 def __repr__(self): return A.__repr__(self) + (v2=%d\n % self.v2) x=A() print x y=B(x) print y $ ./prueba.pl v1=1 Traceback (most recent call last): File ./prueba.pl, line 23, in module print y File ./prueba.pl, line 17, in __repr__ return A.__repr__(self) + (v2=%d\n % self.v2) File ./prueba.pl, line 9, in __repr__ return v1=%d\n % self.v1 AttributeError: B instance has no attribute 'v1' Hello Marc, Thanks for your help. I'm sorry, I've not correctly explained the subject. It is need to init class B with the current value of the A instance, not with the initial ones. A best example is: x=A() print x x.v1=3 y=B(x) print y at the end, y.v1 must be equal to 3. Sorry again. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to replace the last (and only last) character in a string?
On May 3, 4:37 pm, [EMAIL PROTECTED] wrote: On May 3, 9:27 am, Johny [EMAIL PROTECTED] wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s[len(s)-1],'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why? Thanks L. I think the reason it's not working is because you're doing it kind of backwards. For one thing, the string module is deprecated. I would do it like this: s = s.replace(s[len(s)-1], 'r') Although that is kind of hard to read. But it works. Mike Mike it does NOT work for me. s.replace(s[len(s)-1], 'r') '123r5 r3r3 r5r' I need only the last character to be replaced -- http://mail.python.org/mailman/listinfo/python-list
Re: How to replace the last (and only last) character in a string?
In [EMAIL PROTECTED], Johny wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s[len(s)-1],'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why? Because you can't change strings. Any function or method that changes a string returns a new and modified copy. So does the `string.replace()` function. And you don't bind the result to a name, so it is lost. This is shorter than using `replace()`: In [9]: s = '12345 4343 454' In [10]: s = s[:-1] + 'r' In [11]: s Out[11]: '12345 4343 45r' BTW most things in the `string` module are deprecate because they are available as methods on string objects. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: How to replace the last (and only last) character in a string?
On May 3, 9:27 am, Johny [EMAIL PROTECTED] wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s[len(s)-1],'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why? Instead of doing it that way, you should use slicing. s='12345 4343 454' s = s[:-1] + 'r' print s 12345 4343 45r See http://docs.python.org/tut/node5.html#strings HTH. Jay Graves -- http://mail.python.org/mailman/listinfo/python-list
Re: ignorance and intolerance in computing communties
Xah Lee wrote: « ... “Ignorance And Intolerance In Online Computing Communities” http://xahlee.org/Netiquette_dir/ignorance_intolerance.html ... As i have indicated in my post, it is non-trivial to implement a function that returns the positive angle of a vector » I have now coded this. I think it is probably the most algorithmically optimal, and rather much simpler than i originally thought. Here's the Mathematica code: vectorAngle[{a1_, a2_}] := Module[{x, y}, {x, y} = {a1, a2}/Sqrt[a1^2 + a2^2] // N; If[x == 0 y == 0, fucked, If[x == 0, [EMAIL PROTECTED] === 1, π/2, -π/2], If[y == 0, [EMAIL PROTECTED] === 1, 0, π], [EMAIL PROTECTED] === 1, [EMAIL PROTECTED], 2 π - [EMAIL PROTECTED] ] ] ] ] Btw, if we can use any Mathematica's buildin function, this is actually just vectorAngle2[{a1_, a2_}] := Arg@(Complex @@ {a1, a2}) I'm still interested, if someone would show the source code, of how Perl, Python, or Lisp or Java, implement the function that finds the angle of a complex number. Originally, i was also hoping perhaps there's some math trick by dot product or combination of trig functions, that obviates the need to check which quadrant the vector is in ... Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: copy base class fields
tmp123 [EMAIL PROTECTED] wrote: ... It seems that the statement self=a is not the correct way to copy all the fields of the base class from the __init__ argument to the new object. Indeed, it isn't. Assigning to self just rebinds the name 'self' as a local variable of method B.__init__ -- really useless. Of course, it is not an option to copy one by one all the fields of class A inside the __init__ of B. Several variants of the program produces similar results. Please, could someone explain which way is the correct way? Somebody else suggested you call A.__init__ from inside B.__init__, and that is correct if what you want to do is freshly initialize the B instance as an A. However, from the fact that you pass to B.__init__ an argument 'a', it looks as if what you're trying to do is indeed copy each of a's instance variables to self (it's hard to read your mind from the code you've posted, but if I had to guess that would be by guess), where a is an instance of A that's not necessarily freshly initialized. In this case, you might for example start B.__init__ with: self.__dict__.update(a.__dict__) This is not very elegant or solid, but at least it's short and fast:-). A better way would require having _somewhere_ a list or tuple with the names of all the instance variables you know you want to copy; if that list of names was for example B._names_to_copy, for name in self._names_to_copy: value = getattr(a, name) setattr(self, name, value) IS elegant and robust. The advantages of explicitly controlling what names you're copying (rather than blindly taking whatever happens to be there) are similar to those of avoiding from wherever import *: you avoid accidental name pollution. The advantages of using getattr and setattr (rather than blindly working on the __dict__s) are those of working correctly and transparently with properties and other similar kinds of descriptors, rather than just raw instance variables. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: How to replace the last (and only last) character in a string?
On May 3, 7:44 am, Johny [EMAIL PROTECTED] wrote: On May 3, 4:37 pm, [EMAIL PROTECTED] wrote: On May 3, 9:27 am, Johny [EMAIL PROTECTED] wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? I tried string.replace(s,s[len(s)-1],'r') where 'r' should replace the last '4'. But it doesn't work. Can anyone explain why? Thanks L. I think the reason it's not working is because you're doing it kind of backwards. For one thing, the string module is deprecated. I would do it like this: s = s.replace(s[len(s)-1], 'r') Although that is kind of hard to read. But it works. Mike Mike it does NOT work for me. s.replace(s[len(s)-1], 'r') '123r5 r3r3 r5r' I need only the last character to be replaced Its not working because str.replace: [docstring] Help on method_descriptor: replace(...) S.replace (old, new[, count]) - string Return a copy of string S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced. [/docstring] Notice the all occurrences of substring part. Strings are immutable, so there isn't really any replace, either way you are going to be creating a new string. So the best way to do what (I think) you want to do is this... [code] s = '12345 4343 454' s = s[:-1]+'r' s '12345 4343 45r' [/code] -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I use Python instead of Joomla?
On May 2, 5:38 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: You're mixing apples, fishes, and cars here. Joomla is a content management system, Django a framework and Python a language. Yes, I know, but they are all ways to create a website. If I wanted a site which included galleries, forums, etc. and I didn't want to re- invent the wheel, I could: 1) Use joomla or drupal, and possible end up fighting the framework to get just what I want. 2) Cooble together a web-site with various scripts, either developed by others, or myself. I would like to work with django, and include some python stuff. But, the PHP environments seem to have a much richer assortment of pre- written scripts. If I want to include my own applications, I could develop those apps with a popular PHP MVC called CakePHP and include those into joomla or drupal. I don't know if there is anything like that with Python development. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: copy base class fields
On 3 May 2007 07:14:04 -0700, tmp123 [EMAIL PROTECTED] wrote: Of course, it is not an option to copy one by one all the fields of class A inside the __init__ of B. Is it okay to copy them all at once? Like this: class B(A): def __init__(self, a): self.__dict__.update(a.__dict__) self.v2 = 2 That will copy all of the attributes of instance a into the new instance. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: 32 OS on 64-bit machine
$ python Python 2.5c1 (r25c1:51305, Sep 12 2006, 08:39:50) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-54)] on linux2 Type help, copyright, credits or license for more information. import platform print platform.processor() x86_64 print platform.architecture() ('64bit', 'ELF') This is an Opteron box running 64-bit RedHat Enterprise Lunix release 3 update 7, not 32-bit. $ uname -a Linux localhost.localdomain 2.4.21-40.EL #1 Thu Feb 2 22:20:41 EST 2006 x86_64 x86_64 x86_64 GNU/Linux /Jean Brouwers On May 3, 2:10 am, SamG [EMAIL PROTECTED] wrote: If anyone has a x86_64 machine and is running a 32bit OS on top of that could you tell me what output would you get for the following program #== import platform print platform.processor() print platform.architecture() #== Thanks in advance : )~ -- http://mail.python.org/mailman/listinfo/python-list
Re: ignorance and intolerance in computing communties
It is not that difficult to those of us who know math. Obvious analogy to the function below exists in 'perl'. double vectorAngle( double x, double y ) { double r2 = x*x+y*y; if( r2 == 0 ) return -10; // error case int quadrant = x 0 ? (y = 0 : 0 : 3) : (y 0 ? 1 : 2); return pi/2 * quadrant + asin( abs(y)/sqrt( r2 ) ); } -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's Dynamic Languages Runtime (DLR)
Duncan Booth [EMAIL PROTECTED] wrote: means in pure Python code the string has python methods, but in Python using the CLR it gains the CLR methods. Presumably in Ruby code it looks like a Ruby string and so on, but (and this is what's new) it is the same object, not a bunch of language specific wrappers around the string type. So is it changeable (making Python code using it deeply unhappy) or unchangeable (making Ruby or Javascript code similarly unhappy)? The idea of just having one string type across languages is fascinating, but I'm not sure it can work as stated due to different semantics such as mutable vs immutable... Alex -- http://mail.python.org/mailman/listinfo/python-list
_csv.Error: string with NUL bytes
Anyone have an idea of what I might do to fix this? I have googled adn can only find some random conversations about it that doesn't make sense to me. I am basically reading in a csv file to create an xml and get this error. I don't see any empty values in any fields or anything... -- http://mail.python.org/mailman/listinfo/python-list
Re: My Python annoyances
On May 3, 9:27 am, Paul Boddie [EMAIL PROTECTED] wrote: On 3 Mai, 15:49, Ben Collver [EMAIL PROTECTED] wrote: I rewrote my code in Python and I found myself running into many of the same hassles that I run into with other languages: inaccurate and incomplete documentation, a maze of little platform-specific quirks to work around in the base classes, and a macho community of users. I'm sorry to hear about that. If by macho you mean people who insist that things are good enough as they are, and that newcomers should themselves adapt to whatever they may discover, instead of things being improved so that they are more intuitive and reliable for newcomers and experienced developers alike, then I'd certainly be interested in undermining that culture. The python web site recommended Dive Into Python, so I learned by reading that. It has several examples that don't work because the Python base classes have changed behavior. I should have taken that as lesson. Really Dive Into Python should be a sufficient guide, and it was perhaps the best introduction to the language when it was written. It is very unfortunate that the language has changed in a number of ways (and exhibits continued change) whilst effort into documenting what is already there remains neglected amongst the people making all the changes. I tried to write portable Python code. The zlib CRC function returned different results on architectures between 32 bit and 64 bit architectures. I filed a bug report. It was closed, without a comment from the person who closed it. I get the unspoken message: bug reports are not welcome. Can you provide the bug identifier? Bug reports are generally welcome, and despite complaints about patch reviews, I've found people reviewing things I've submitted. I installed Cygwin on a Windows machine. I try to quit from an interactive Python session. It tells me that on my platform, I must press Control-Z to exit. I press Control-Z and it makes Python a background process. Yes, Ctrl-Z exits Python in the standard Windows edition. Since Cygwin provides a POSIX-like environment, Ctrl-D should be used instead. If the documentation is wrong, a bug report or patch should be filed against the software. I tried to use the XML.minidom. The documentation here is minimal as well. So I read up on other web sites. It turns out that the interface has changed quite a bit from the documentation I found on other web sites. Where are the much loved docstrings? In 2.3 minidom, they are sparse and cryptic. I really don't know what to say about the PyXML/xmlcore situation. I don't use ElementTree and hardly use PyXML or minidom, but something really should have been done about the maintenance of the established libraries rather than declaring them as legacy items and pretending that they don't exist. Between 2.4 and 2.5, tempfile returns a different type of object. My code cannot have a single test, it has check for type(obj) == file or obj.__class__ == tempfile._TemporaryFileWrapper. Try using isinstance or relying on deeper knowledge of how the object will be used. I decided to make a tkinter front-end for a Python program. I decided to go with tkinter because it is included with many Python installations, so it maximizes the chance for my program to run out of the box. The tkinter documentation on the Python site mainly consists of loose notes and links to other sites. The documentation on other sites is great, if you already know how to use tkinter. I ran into bugs in TkAqua which make the grid layout unusable for me. So I will need to ask potential users to install Xcode, X11, and mac ports, if they want to run my program. Take a look at the python.org Wiki for links to other resources on Tkinter: http://wiki.python.org/moin/TkInter Or consider other graphical frameworks: http://wiki.python.org/moin/GuiProgramming In short, there is plenty of room for improvement. Admittedly these are not problems with the language definition. But I downloaded a Python distribution, and the problems are Python specific. My opinions, already expressed, include the observation that the core development community is more interested in extending the language than in strengthening the standard library (and its documentation). It should be noted that the proposed standard library reorganisation, which is a very conservative affair, has actually been postponed until after the release of Python 3.0a1 according to a message I read recently. And yet, if you read people's lists about what they hate about Python (amongst actual users of Python), guess which thing almost always comes up? http://www.google.com/search?q=%22things+I+hate+about+Python%22 Paul I agree with Paul and Ben. The Docs need some help. Some are excellent and others are hosed because of changes to the language. I started with Tkinter, but
Re: How to replace the last (and only last) character in a string?
On 2007-05-03, Johny [EMAIL PROTECTED] wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? s = '12345 4343 454' s = s[:-1] + 'X' s '12345 4343 45X' -- Grant Edwards grante Yow! Where's th' DAFFY at DUCK EXHIBIT?? visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with meteo datas
On May 3, 4:08 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Messaggio originale Da: [EMAIL PROTECTED] Data: 3-mag-2007 10.02 A: [EMAIL PROTECTED] Ogg: problem with meteo datas Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-Est : 44.50/ 2.50 MODELE PA PARAMETRE P NIVEAU MER 0 ECHEANCE 0.0 DATE 2002030400 NB_POINTS 25 1020.911020.871020.911021.05 1021.13 1020.071020.271020.491020.91 1021.15 1019.37 1019.651019.791020.53 1020.77 1018.731018.89 1019.191019.83 1020.81 1018.051018.191018.75 1019.55 1020.27 NIVEAU MER 0 ECHEANCE 3.0 DATE 2002030400 NB_POINTS 25 1019.801019.781019.921020.18 1020.34 1018.941019.241019.541020.08 1020.32 1018.24 1018.641018.941019.84 1019.98 1017.481017.88 1018.281018.98 1019.98 1016.621017.081017.66 1018.26 1018.34 NIVEAU MER 0 ECHEANCE 6.0 DATE 2002030400 NB_POINTS 25 1019.371019.391019.57 Peter - Your first attempt at pyparsing is a good step - just get something working! You've got a first pattern working that detects and extracts all decimal numbers. (I think you are the first one to model a decimal number as a delimited list of integers with . as the delimiter.) The next step is to start looking for some higher-level text groups or patterns. Your data is well structured as an n-level hierarchy, that looks to me like: - model+parameter - level - nb_points - level - nb_points - level - nb_points - model+parameter - level - nb_points - level - nb_points ... You can build your pyparsing grammar from the ground up, first to parse individual terminal expressions (such as decimal numbers which you already have), and then buld up to more and more complex structures within your data. The first thing to change about your approach is to start looking at this data as a whole, instead of line by line. Instead of extracting this first line of 5 point values: 1020.911020.871020.911021.05 1021.13 look at this as one piece of a larger structure, a data set for a given niveau: NIVEAU MER 0 ECHEANCE 0.0 DATE 2002030400 NB_POINTS 25 1020.911020.871020.911021.05 1021.13 1020.071020.271020.491020.91 1021.15 1019.371019.651019.791020.53 1020.77 1018.731018.891019.191019.83 1020.81 1018.051018.191018.751019.55 1020.27 So let's create a parser for this structure that is the next step up in the data hierarchy. NIVEAU, ECHEANCE, DATE, and NB_POINTS are helpful labels for marking the data, but not really important to return in the parsed results. So I will start by creating definitions for these labels which will parse them, but leave out (suppress) them from the returned data: NIVEAU, ECHEANCE, DATE, NB_POINTS = \ map(Suppress,NIVEAU ECHEANCE DATE NB_POINTS .split()) You stated that there are several options for what a niveau identifier can look like, so this should be its own expression: niveau_ref = Literal(MER 0) | Literal(SOL 0) | \ Combine(Literal(HAUTEUR ) + eurodec) (I defined eurodec as you defined dec, but with a comma delimiter.) I'll also define a dateString as a Word(nums) of exactly 14 digits, but you can come back to this later and refine this as you like (build in parse-time conversion for example). dateString = Word(nums,exact=14) And then you can create an expression for a full niveau's-worth of data: niveau = NIVEAU + niveau_ref + ECHEANCE + dec + DATE + dateString + NB_POINTS + countedArray(dec) Notice that we can use the pyparsing built-in countedArray to capture all of the data point values, since NB_POINTS gives the number of points to follow, and these are followed immediately by the points themselves. Pyparsing will convert all of these into a nice n-element list for us. You astutely requested that these values should be accessible like values in a dict, so we do this in pyparsing by adding results names: niveau = NIVEAU + niveau_ref.setResultsName(niveau) + \ ECHEANCE + dec.setResultsName(echeance) + \ DATE + dateString.setResultsName(date) + \ NB_POINTS + countedArray(dec).setResultsName(nb_points) Now you should be able to search through your data file, extracting all of the niveaux (?) and their related data: f=file(arqal-Arpege.00, r) fdata = f.read() # read the entire file, instead of going line-by- line for n in niveau.searchString(fdata): print n.niveau print n.dump() pointValues = map(float,n.nb_points[0])
Article on wxPython ToolKit for Mac OS X
Hi there! Just wanted to let people know in this group that I have recently (April 24th) published an introductory article on wxPython and Mac OS X. It is available here: http://www.macdevcenter.com/ Hope someone finds it useful. Regards, Jeremiah -- http://mail.python.org/mailman/listinfo/python-list