ANN: AOPython 1.0.2
AOPython 1.0.2 has been released. AOPython is an AOP (Aspect Oriented Programming) module for Python. AOPython provides a base 'Aspect' that can 'advise' or wrap function and/or method calls. It also contains a weave function that can weave (apply advice to a subset of- or all functions and methods in) a module, class, or instance. Advice may modify or replace parameters and/or the return value of the advised function or method each time it is called. It can do many other things such as handle exceptions raised by an advised function, collect information on the method call (logging), or obtain and release resources before and after a method is invoked. Example 1: How to wrap a function from aopython import Aspect def negate(x): return -x aspect = Aspect() negate = aspect.wrap(negate) negate(2) # advised function call Example 2: How to weave a class from aopython import Aspect class MyObj(object): def double(self, x): return x * 2 def tripple(self, x): return x * 3 aspect = Aspect() aspect.weave(MyObj) myobj = MyObj() myobj.double(5) # advised method call MyObj.tripple(myobj, 5) # advised method call In this release the weave functionality has been enhanced to allow more flexible weaving of callables in modules, classes, or instances. An unweave function has been added to allow advice to be removed en-mass from an object that was previously weaved. Test coverage was also greatly improved, especially for the weave/unweave functions. See the change log for more details. Download/leave comments/ask questions http://www.openpolitics.com/pieces/archives/001710.html Comments are appreciated. pa href=http://www.openpolitics.com/pieces/archives/001710.html;AOPython 1.0.2/a - Aspect Oriented Python (16-Aug-05)/p -- ~ Daniel Miller [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Making programs work together.
On 16 Aug 2005 22:30:51 -0700, [EMAIL PROTECTED] wrote: I'm looking to make what's basically a macro for a computer game. But I want this macro to take information from the game itself, so it's not really a macro. How do I access the data from my game to use in a program? How do I access the data behind your question? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: keeping a ref to a non-member function in a class
Gregory Bond wrote: Thanks Peter, that's a big help. You're welcome. I can solve my problem now, but I'm chasing this further in the name of education, because it seems there is some deep magic happening here that I don't understand. Python resorts to deep magic only when it's inevitable, i. e. hardly ever :-) It seems that applying staticfunction() (or perhaps assigning to the class object) is treated differently if it happens in the class defininition, to when it happens at run time. (My previous attempts to get staticmember() to do the right thing were all run time like the examples below.) There is no distinction between run time and class definition time. The class body is actually a function that is called when the module is loaded. Its locals() are then used to create a type instance, i. e. the class. Say I wanted to keep the need for staticmember hidden from subclasses, and do the staticmember() conversion in the base class methods. I've tried 2 ways of doing this (no subclassing here, just to keep it simple): class B(object): fn = foo def try1(self): print B.fn is, type(B.fn) B.fn = staticmethod(B.fn) print B try1 print B.fn is now, type(B.fn) B.fn() def try2(self): fn2 = staticmethod(B.fn) print B try2 print fn2 is now, type(fn2) fn2() If I try method 1 (assigning to the class object - ignore for a moment the problem of only doing this once!) I get a set of very surprising results: B.fn is type 'instancemethod' B try1 B.fn is now type 'instancemethod' Traceback (most recent call last): File t_o1.py, line 28, in ? B().try1() File t_o1.py, line 17, in try1 B.fn() TypeError: unbound method foo() must be called with B instance as first argument (got nothing instead) note that assigning the staticmember() result to B.fn does NOT change the type of B.fn!! And foo is treated as a member function. So if I try method 2 (using staticmethod() at runtime): B try2 fn2 is now type 'staticmethod' Traceback (most recent call last): File t_o1.py, line 27, in ? B().try2() File t_o1.py, line 22, in try2 fn2() TypeError: 'staticmethod' object is not callable fn2 is a static method, as I'd expect, but it is somehow not callable? Your problems stem from the fact that attribute assignment to a class doesn't always roundtrip: A.value = 42 A.value 42 def f(): pass ... A.method = f A.method, f (unbound method A.f, function f at 0x4028eae4) If a class attribute is a descriptor i. e. it has a __get__() method (which pure python functions do) A.method is not just a dictionary lookup but a call A.__dict__[method].__get__(None, A) This is slightly simplified as it doesn't take inheritance into account. __get__() is free to apply whatever magic, but staticmethod just gives back the original function whereas a some_func.__get__(None, SomeClass) gives you an unbound method: staticmethod(f).__get__(None, A) function f at 0x4028eae4 f.__get__(None, A) unbound method A.f Is there a way to get the original function back out of the unbound method? Let's see: dir(A.method) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func', 'im_self'] im_func seems promising: A.method.im_func function f at 0x4028eae4 Can someone explain what is going on here? Pointers to language spec, code, PEPs etc gladly accepted. Greg, caught in a twisty little maze of descriptors, all different! The two relevant documents are http://users.rcn.com/python/download/Descriptor.htm http://www.python.org/2.2.1/descrintro.html Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Making programs work together.
Example: I'm driving a car in a game and I hit an oil slick so instead of me having to lift off the throttle button on the keyboard, I want to make a program to disengage the throttle as long as I'm on that oil slick. Does that clear anything up? -- http://mail.python.org/mailman/listinfo/python-list
Embedding Python in C, undefined symbol: PyExc_FloatingPointError
Hi, I've just starting out embedding Python in C and get the following error when I try and import a module that in turn imports the math module. ImportError: /usr/lib/python2.4/lib-dynload/math.so: undefined symbol: PyExc_FloatingPointError The module is as follows: # begin script.py import math def fn(i): print i is %d % i # end script.py and the C code is : // start main.c #include Python.h int main(int argc, char *argv[]) { PyObject *mymod, *fn, *strargs; Py_Initialize(); mymod = PyImport_ImportModule(script); if(mymod == NULL) { PyErr_Print(); exit(1); } fn = PyObject_GetAttrString(mymod, fn); if(fn == NULL) { PyErr_Print(); exit(1) ; } strargs = Py_BuildValue((i), 0); PyEval_CallObject(fn, strargs); Py_Finalize(); return 0; } // end main.c Testing script.py by running python and importing the module works fine. Commenting out the import math statement and import other modules (sys, string etc) work fine. The C program is being built like so: gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm /usr/lib/python2.4/config/libpython2.4.a -o main I've tried the above on two machines, one Debian stable and the other Debian testing. Same results on both. It's like I'm missing a library or something, any ideas ? Cheers, Simon Newton -- http://mail.python.org/mailman/listinfo/python-list
Re: Making programs work together.
[EMAIL PROTECTED] wrote: Example: I'm driving a car in a game and I hit an oil slick so instead of me having to lift off the throttle button on the keyboard, I want to make a program to disengage the throttle as long as I'm on that oil slick. Does that clear anything up? Yes. Here's how to do it: import random import time class Car: def throttle(self, on): if on: print full throttle else: print on that oil slick again class ThatOilSlick: def __contains__(self, item): return random.random() .7 class Game: def __init__(self): self.car = Car() self.thatOilSlick = ThatOilSlick() def play(self): while True: self.car.throttle(self.car in self.thatOilSlick) time.sleep(.2) if __name__ == __main__: Game().play() :-) Look here for further information: www.catb.org/~esr/faqs/smart-questions.html Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Read from stdouton Popen on WinXP?
The only way I know how to do this is using a pseudo terminal (pty), but I think that only works on Unix. The problem is the way stdout in C works: - If connected to a character device, it will flush after each line. - If connected to a block device it will flush only after it's buffer is full. Any kind of pipe or file is a block device. As this is how stdout works even your OS can't help, because as long as the application doesn't flush, the output doesn't even arrive at the pipe or file. If you have access to the source of the application you can force it to flush, otherwise you'll need to find out if anything similar to pty exists in Windows. I have 3 years of Windows programming experience, but I don't know of any solution. This probably also means your solution of piping the .exe will not work. Adriaan Renting. mhenry1384 [EMAIL PROTECTED] 08/16/05 11:48 PM I am trying to run a program and filter the output on Windows XP. Since I want to filter the output, I'd like to read it a line at a time and only print the lines I care about. p = subprocess.Popen([doxygen.exe, rDoxyfile.cfg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while 1: line = p.stdout.readline() if not line: break print line The problem is that readline() only returns after the whole process has completed. I have tried various permutations such as using os.read() and changing the bufsize parameter and using popen4. To no avail. Obviously, it should be possible to read stdout before the process completes, since if I leave off the stdout= parameter, the full output shows up in stdout in realtime as you'd expect. About the only thing I can come up with is to pipe the .exe to another python script which could communicate to the main script via TCP/IP, but that seems ridiculous. I searched the newsgroup and didn't see anything particularly helpful. Anyone have a non-ridiculous solution? -- http://mail.python.org/mailman/listinfo/python-list Adriaan Renting| Email: [EMAIL PROTECTED] ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands| Web: http://www.astron.nl/~renting/ -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP and XMLRPC
import SOAPpy client = SOAPpy.SOAPProxy('http://localhost:80/Webservice') server = SOAPpy.SOAPServer(('localhost', 81), ) server.registerFunction(self.somefunction, 'urn:webservice') Adriaan Renting| Email: [EMAIL PROTECTED] ASTRON | Phone: +31 521 595 217 P.O. Box 2 | GSM: +31 6 24 25 17 28 NL-7990 AA Dwingeloo | FAX: +31 521 597 332 The Netherlands| Web: http://www.astron.nl/~renting/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Library vs Framework (was Dr. Dobb's Python-URL!)
Simon Brunning wrote: On 8/15/05, Rocco Moretti [EMAIL PROTECTED] wrote: Which lead me to the question - what's the difference between a library and a framework? If you call its code, it's a library. If it calls yours, it's a framework. Pretty! I don't think it is an oversimplification. The crucial difference is that between interface and implementation. A framework forces the programmers code to conform certain interfaces and contracts. It does not restrict implementation in any way ( which might be empty ). The implementation part uses library functions that do not tell much about the implementation and nothing about interfaces. Libaries give you any freedom but sometimes ( and only sometimes ) people also like to structure their code ;) What are frameworks really good for - a very true success story. A colleague of mine used to spread all kinds of flags ( state- and property markers ) over the code that were used to glue everything together until I raised my tyranny of frameworks. It was a hard struggle for an OO warrier and took me almost a year or so to become the undebated projects architect/dictator who trashed all kind of misguided freedom ( i.e. bad code ): What the fuck is this? I worked almost a week on it! It has to be reworked. No, you don't do it! I did it. Who claims that social life is easy? What is nice about this kind of cruelness is not only my colleague became finally happy and hopefully learned at least a little bit about programming but also our customers were gratefull about stable code, thight release schedules and just-in-time requirement dispatch. Now we have some bread-and-butter maintenance contract and true freedom to experiment with other more interesting things besides this. But the struggle just starts again with the new project ;) Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)
Op 2005-08-16, Peter Hansen schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Why has one made a difference in search policy for finding a variable based on whether the variable is rebound or not in the first place. Do you really not understand the reason, or do you simply disagree with it? How can I understand something that was never explained to me. Each time I saw this coming up people answered the technical question about the difference between rebinding and accessing or modification. I haven't seen anyone answer the question asnwer at this level. It's a choice with rational thought behind it. Then please explain this rational thought instead of just asserting that it is present. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a graphical interface on top of SSH. How?
John F. wrote: I want to write a client app in Python using wxWindows that connects to my FreeBSD server via SSH (using my machine account credentials) and runs a python or shell script when requested (by clicking a button for instance). Can someone give me some advice on how to create a graphical shell per se? Well, a graphical shell is just a wxWidgets application that exposes a few widgets (buttons, list, whatever). Each widget has a event associated to it and this event can trigger whatever command, even a remote command on your FreeBSD server (via ssh). As a consequence: - create your user interface (I suggest you to use wxPython and wxGlade for this) - associate to each and every widget a event handler - make your event handlers call your scripts on your FreeBSD machine via SSH (use PySSH or Conch for this) Python has a couple of good implementation of SSH: http://pyssh.sourceforge.net/ http://twistedmatrix.com/projects/conch/ Both of them are well documented. You can find a small example here: http://www.palovick.com/code/python/python-ssh-client.php Do not use wxWidgets directly. You would have to re-create a lot of Python-wxWidgets integration that already exists. Use wxPython instead (www.wxpython.org). There is a quite good GUI builder for wxPython that is called wxGlade. It can generate XML files that are easier to maintain than C o Python code. CU --- Alessandro Bottoni -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in C, undefined symbol: PyExc_FloatingPointError
Simon Newton wrote: gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm /usr/lib/python2.4/config/libpython2.4.a -o main I've tried the above on two machines, one Debian stable and the other Debian testing. Same results on both. It's like I'm missing a library or something, any ideas ? No. You need to export the Python symbols from your executable to extension modules. IOW, you need to pass -Xlinker -export-dynamic to the gcc invocation. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] implementation of copy standard lib
On 8/16/05, Martijn Brouwer [EMAIL PROTECTED] wrote: Well, I guess making a deep copy of an object is important in many case. Just try this: A=[] B=A A.append(foo) print B Guess the output. It is: ['foo'] I remember thinking that this behavior was odd when I learned Java many years ago. (Java shares this behavior, and I learned it before Python. In fact, I think that many OO languages behave this way - JavaScript, C#, and so on.) But these days, it's 2nd nature. I also thought that it might be dangerous, but now I know that it hardly ever is. (When is it dangerous? Well, if you are trying to build an immutable class, you have to be careful not to pass out references to mutable attributes.) In many cases this is undesirable, so you need to make a deep copy using something as B=copy.deepcopy(A). This is where we differ. I know that it's *occasionally* useful to be able to copy or deep-copy an object - that's why the copy module is there. But I find that it's not many cases - it's actually rather rare. Shallow copies of dictionaries and (especially) lists are a little less rare, but you can make those without the copy module: new_list = list(old_list) # or old_list[:] new_dict = dict(old_dict) # or old_dict.copy() -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Need better way to unpack a list
Is there a better solution to following problem : I want to unpack a list into variables the list is created at runtime and I do not know how many items there will be , but I know not more than 25. The list unpacks into variables which are prev. defined as line1,line2line25 which are actually the names of lineedit fields in a Qt gui application and which need to be populated. I currently use following to achieve that : c=0 while c len(mylinelist): c = c + 1 if c==1: self.line1.setText(mylinelist[c]) if c==2 : self.line2.setText(mylinelist[c]) . . . if c==25: self.line25.setText(mylinelist[c]) I rather have someting like pseudo code follows: self.line+c+.setText(mylinelist[c]) How to do that ? Nx -- http://mail.python.org/mailman/listinfo/python-list
PyPE 2.1 run problem
Hello, I have downloaded the PyPE2.1-win-unicode.zip, after unzip it with winzip into PyPE2.1-win-unicode dierctory on window XP. I try to run pype.exe by double click on it, but nothing has happen, then when I run it with run as... using the right click button. I have the following Message in the pype.exe.log Traceback (most recent call last): File pype.py, line 30, in ? File configuration.pyc, line 129, in ? WindowsError: [Errno 267] The directory name is invalid: 'E:\\Downloads\\Python\\PyPE\\PyPE2.1-win-unicode\\library.zip/*.*' I also copy the PyPE2.1-win-unicode directory into C:\Python24\Lib\site-packages and run it, but it behaves the same !! Then I downloaded the source code and unzip it into PyPe2.1-src, and run python pype.py in a command window. The progroam detected I have an older version of wxPython 2.5.5 and askes me do I want to download the newer version 2.6.1. Which I did. After downlowd the wxPython 2.6.1 (win-unicode version). I installed it into Python 2.4.1, then re-run PyPE. i.e re-issue python pype.py in a command window. I have the following traceback Error message: [ Wed Aug 17 09:32:32 2005 ] Loading history from C:\Documents and Settings\gbr02333\.pype\history.txt Traceback (most recent call last): File pype.py, line 3926, in ? main() File pype.py, line 3916, in main filehistory.root = root = app.frame = MainWindow(None, -1, PyPE, sys.argv[1+opn:]) File pype.py, line 438, in __init__ self.loadHistory() File pype.py, line 1152, in loadHistory self.config[nam][k] = dict(v) TypeError: iteration over non-sequence I wonder does anyone using PyPE2.1 on Windown XP SP2 and have the same problem? Can any one help with the problem? Thanks in advance ! Tony Ha. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need better way to unpack a list
Nx wrote: Is there a better solution to following problem : I want to unpack a list into variables the list is created at runtime and I do not know how many items there will be , but I know not more than 25. The list unpacks into variables which are prev. defined as line1,line2line25 which are actually the names of lineedit fields in a Qt gui application and which need to be populated. I currently use following to achieve that : c=0 while c len(mylinelist): c = c + 1 if c==1: self.line1.setText(mylinelist[c]) if c==2 : self.line2.setText(mylinelist[c]) . . . if c==25: self.line25.setText(mylinelist[c]) I rather have someting like pseudo code follows: self.line+c+.setText(mylinelist[c]) How to do that ? for index, value in enumerate(mylinelist): getattr(self, line%d % (index + 1)).setText(value) A better approach would be to create a list of lineedit fields in the __init__() method instead of (or in addition to) the individual lineNNN attributes and then just write for edit, value in zip(self.lineedits, mylinelist): edit.setText(value) If you want to play it safe you might also want to clear the extra lineedits: from itertools import repeat, chain, izip for edit, value in izip(self.lineedits, chain(mylinelist, repeat())): edit.setText(value) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Need better way to unpack a list
On 8/17/05, Nx [EMAIL PROTECTED] wrote: I want to unpack a list into variables the list is created at runtime and I do not know how many items there will be , but I know not more than 25. The list unpacks into variables which are prev. defined as line1,line2line25 which are actually the names of lineedit fields in a Qt gui application and which need to be populated. I currently use following to achieve that : c=0 while c len(mylinelist): c = c + 1 if c==1: self.line1.setText(mylinelist[c]) if c==2 : self.line2.setText(mylinelist[c]) . . . if c==25: self.line25.setText(mylinelist[c]) I rather have someting like pseudo code follows: self.line+c+.setText(mylinelist[c]) How to do that ? Lift would be much easier if you held your 'linenn' lineedit fields in a list instead. Is that possible? If so, you could do something like (untested): for index, line in enumerate(mylinelist): self.lines[index].setText(line) -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Python as VBA replacement under Windows?
Hello, this is a potentially veeery dumb question, but: - If an application supports VBA as a macro language, - and if you can execute Python code from within a VBA script (how?) - and if the application exposes its VBA scripting interface through COM then it should be perfectly possible to entirely replace VBA in nearly all Windows applications with Python, right? TIA, sincerely, Wolfgang Keller -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or'module' better?)
Bengt Richter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Yes, the roster model works for me too, but I'm not sure I understand your concept of container/room ;-) I only meant that if collective objects were containers of objects like rooms are containers of people, then an object could be in only 1 collective at a time. But that is importantly not true. Therefore collectives are not containers. I once mistakenly thought of mathematical sets as being like boxes. Don't know if someone else said so or if I just thought up that error on my own. But then I realized that the box model leads to the the same counterfactual conclusion. Therefore 'box' is a bad metaphor. Sets are rosters. The very term 'member of' is a clue that I missed for years ;-) I hope to help other avoid the same mistake. The roster idea also explains how a set can be a 'member' of itself, and how a list can include itself. Weird, perhaps, but easily possible. The underlying problem is that 'contains' has two meanings: a room contains people by actual presence and hence is a container. A club roster metaphorically contains people by name (reference) as members, but not actually, and hence is not a container even though we may speak of it as 'containing'. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] implementation of copy standard lib
Simon Brunning [EMAIL PROTECTED] writes: I think that copy is very rarely used. I don't think I've ever imported it. Or is it just me? Not really. I've used it once that I can recall, to copy a kind of generic default value, something like: def value(self, v, default): if hasattr(source, v): return getattr(source, v) else: return copy.copy(default) (except not quite, there would probably be better ways to write exactly that). Cheers, mwh -- washort glyph: you're evil, too glyph washort: I try washort not the good kind of evil washort the other kind -- from Twisted.Quotes -- http://mail.python.org/mailman/listinfo/python-list
Iterparse and ElementTree confusion
Hi Im trying to parse a large(150MB) xml file in order to extract specific required records. import sys from elementtree.ElementTree import ElementTree root = ElementTree(file=big.xml') This works fine for smaller versions of the same xml file but...when i attempted the above my PC goes to lala land, theres much HDD grinding followed by windows runnign low on virtual memory popup after 10-15mins. Then just more grinding...for an hour before i gave up XML file format: root rubbish1 . . /rubbish1 . . rubbishX . . /rubbishX Products Product ID=QU17861 UserTypeID=PH_QUOTE QualifierID=Qualifier root ParentID=LIVE_AREA Name QualifierID=Qualifier root23172/Name Description QualifierID=Qualifier rootThree Spot Rail Light Brushed Chrome/Description ClassificationReference ClassificationID=[EMAIL PROTECTED] Lighting QualifierID=Qualifier root Type= / ProductReference ProductID=QU17749 QualifierID=Qualifier root Type=Accessory / Linked Product Name QualifierID=Qualifier root73520/Name . .etc /Product /Products /root Ok, i thought, surely theres a way to parse this thing in chucnks till i get to the element i require then I'll reuse the ElementTree goodness. I found Iterparse def parse_for_products(filename): for event, elem in iterparse(filename): if elem.tag == Products: root = ElementTree(elem) print_all(root) else: elem.clear() My problem is that if i pass the 'elem' found by iterparse then try to print all attributes, children and tail text i only get elem.tagelem.keys returns nothing as do all of the other previously useful elementtree methods. Am i right in thinking that you can pass an element into ElementTree? How might i manually iterate through product.../product grabbing everything? -- http://mail.python.org/mailman/listinfo/python-list
Re: Library vs Framework (was Dr. Dobb's Python-URL!)
Simon Brunning schrieb: On 8/15/05, Rocco Moretti [EMAIL PROTECTED] wrote: Which lead me to the question - what's the difference between a library and a framework? If you call its code, it's a library. If it calls yours, it's a framework. IOW Apache with modpython is a framework for web apps because it calls your Python handlers. According to Andy Smith the Apache/ modpython combo sucks because it takes away the freedom to call a HTTP library and write your own HTTP server ;) -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Re: zlib + Windows 32 service problem (ImportError)
| | C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program | Files\Common Files\GTK\2.0\bin | | Then I restarted my computer. It is still missing initzlib. :-( | Please note that I can run the same program as an application, logged in | as the same user. | | Les Changing the Windows dll search path doesn't make any difference. It is sys.path (Python's search path) that's causing you the headache. Please see the mentioned thread for proposed solutions. Great. I could make my service working with this snippet: import sys sys.path.insert(0,r'C:\Python24\DLLs') But this is very ugly. Primarily, I do not want to use absolute path names in a this program. I want to use the same code on different computers and operating systems, but this code is not portable. Secondly, I do not understand why sys.path is different when I start python interactively. I believe that sys.path should be the same when starting the program as a service. The only difference between the application and the service is that the 'main' program of the service imports some additional modules. See them below. iT:\Python\Projects\NamedConnectorpython Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import sys s1 = str(sys.path) import win32serviceutil, win32service import pywintypes, win32con, winerror from win32event import * from win32file import * from win32pipe import * from win32api import * from ntsecuritycon import * s2 = str(sys.path) print s1 == s2 True I cannot distribute my service until I make it independent of the python installation directory. Why sys.path is different when starting the code as a windows service? How can I make this code portable? By the way, you have been a great help. Thank you very much. I can now continue working. :-) Les -- http://mail.python.org/mailman/listinfo/python-list
Re: Read from stdouton Popen on WinXP?
mhenry1384 a écrit : I am trying to run a program and filter the output on Windows XP. Since I want to filter the output, I'd like to read it a line at a time and only print the lines I care about. [snip] I had the exact same problem yesterday. This is an obvious use case for the bufsize parameter to os.popen4, except that the Windows implementation doesn't accept anything but -1... The only way I can see out of this is to use win32api to launch the process through CreateProcess, then perform asynchronous I/O on its stdout using the OVERLAPPED structure in a call to ReadFile... Ugly... -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in C, undefined symbol: PyExc_FloatingPointError
On Wed, 2005-08-17 at 09:52 +0200, Martin v. Löwis wrote: Simon Newton wrote: gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm /usr/lib/python2.4/config/libpython2.4.a -o main No. You need to export the Python symbols from your executable to extension modules. IOW, you need to pass -Xlinker -export-dynamic to the gcc invocation. Thanks Martin, -export-dynamic fixed it. Simon -- http://mail.python.org/mailman/listinfo/python-list
question about threading
hi i have a program that listens socket connection and serial device. in main program i am creating a socket then calling a class to listen socket under while 1: , class soket(Thread): def __init__(self): Thread.__init__(self) self.host = '127.0.0.1' self.port = 4500 self.data = '' try: self.s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.s.bind((self.host,self.port)) self.s.listen(1) except: print 'error creating a socket !?!' def run(self): Thread.__init__(self) self.conn, self.addr = self.s.accept() self.data += self.conn.recv(1024) if not self.data: pass else: return trim(self.data) self.conn.close() in main after doing this , try: s = AboutSocket.soket() s.setDaemon(1) s.start() except: print 'Error occured while using Threaded Socket !?!' after creating a socket i put bot soket and serial listeners in same while 1: while 1: skcgelen = s.run() print '\n\nreceived data from socket : ' + skcgelen.__str__() okunan = serial_readline(ser,'[ETX]') print '\n\nreceived data : ' + okunan.__str__() # ser.write('[ACK]') # database_relation(db,okunan) this works but when i send message to serial, the program waits for socket to receive message, if i send a message to a socket it prints both socket message and serial device message, how can i work them separetly. i want to see the message from the serial if received immediately and socket if socket receives immediately. i`ll put these incoming message to the list dynamically. note: serial device listener is not threaded. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Gadfly use (Newby)
Fredrik Lundh wrote: niko [EMAIL PROTECTED] wrote: while using gadfly, got an error that i don't understand. Code is as follow : cursor = connection.cursor() cursor.execute('select id_m from mots where nom_m = %s' % nom_m) id_m = cursor.fetchall() Error message : File C:\Python24\Lib\site-packages\gadfly\kjParser.py, line 567, in getmember (Token,skip) = self.LexDict.Token(self.String, self.Position) File C:\Python24\Lib\site-packages\gadfly\kjParser.py, line 433, in Token raise LexTokenError, Lexical token not found +info gadfly.kjParser.LexTokenError: Lexical token not found near :: ' where nom_m = '*'Ancient s Pled' Stored value seems to interfere with somethong ? Am i wrong ? Did i missed something ? Thanks in advance for any help. the % operator does the substitution *before* the execute method is called. maybe you meant cursor.execute('select id_m from mots where nom_m = %s', nom_m) ? /F I suspect he actually meant cursor.execute(select id_m from mots where nom_m = '%s' % nom_m) or perhaps cursor.execute(select id_m from mots where nom_m = %s, (nom_m, )) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Making programs work together.
[EMAIL PROTECTED] wrote: I'm looking to make what's basically a macro for a computer game. But I want this macro to take information from the game itself, so it's not really a macro. That's exactly a macro as the term is used in e.g. MS Office macros written in VBA etc. Do you have access to the source code for the game? -- http://mail.python.org/mailman/listinfo/python-list
Re: Standalone applications ?
Well, I think I must answer to my own post... There is at least one reason to bother with executables. I have just read a message. Someone wanted to run a program written in Python + wxPython. But he has failed. Why? Because the version of wxPython on his system was newer and it's API was different. Of course he could install an older (the proper) version of wxPython as well... But he's not a developer. He don't know how to install Python, wxPython and so on... And he's not interested in such knowledge. So there *is* a reason for making executables. -- http://mail.python.org/mailman/listinfo/python-list
Re: List copying idiom was Re: [Python-Dev] implementation of copy standard lib
Tom Anderson wrote: On Tue, 16 Aug 2005, Ron Adam wrote: Simon Brunning wrote: On 8/14/05, Martijn Brouwer [EMAIL PROTECTED] wrote: I can imagine that *a lot* of libs/scripts use the copy library, I think that copy is very rarely used. I don't think I've ever imported it. I use copy.deepcopy() sometimes, and more often [:] with lists. Dictionary objects have a copy method. All non mutable objects are copies. When you say [:], do you mean that you copy lists like this: l = someList() m = [] m[:] = l ? That's what i've been doing. The other day, i realised that i could just do: l = someList() m = list(l) The same works for copying dicts. Whilst it's still not utterly obvious that what this is about is making a copy, it's more obvious, cleaner, shorter and probably faster than the slice assignment, which is really kludgy (almost intercalorific, in fact - or even perlish!). Not really: it used to be the preferred mechanism, but now it seems a little old-fashioned is all. I too have wondered why copy isn't a builtin, Same here. It seems like a sort of obvious thing to have, and could probably implemented much more simply and quickly in the interpreter. You'd probably want a __copy__ hook for classes which want special handling, and just do a normal deep copy for everything else. Well yes, but given that module copy now exists (and will therefore have to continue ti exist until Py3) that would introduce some redundancy. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in C, undefined symbol: PyExc_FloatingPointError
On Wed, 17 Aug 2005 14:29:43 +0800 Simon Newton wrote: The C program is being built like so: gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4 -I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm /usr/lib/python2.4/config/libpython2.4.a -o main Try to link libpython as a library (as it should be), not as an object module: gcc main.o -L/usr/lib -lpthread -ldl -lutil -lm -lpython2.4 -o main -- jk -- http://mail.python.org/mailman/listinfo/python-list
looking to GIVE my first oral favor
im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me -- http://mail.python.org/mailman/listinfo/python-list
Re: socket setdefaulttimeout
Sheila King wrote: I'm doing DNS lookups on common spam blacklists (such as SpamCop..and others) in an email filtering script. Sometimes, because the DNS server that is resolving the looksup can go down, it is important to make sure that the socket doesn't just hang there waiting for a response. After a recent system upgrade to Python 2.4.1 (from 2.2.2) I thought I could take advantage of the setdefaulttimeout in the socket module, to limit the amount of time the sockets take for a lookup. As a test, I set the default timout ridiculously low. But it doesn't seem to be having any effect. The sockets will take several seconds to make the connection and complete the lookups, even though I've set the timeout to millionths of a second, which I thought would ensure a timeout (sample script below). Am I doing something wrong? Do I misunderstand something? Is what I want to do simply not possible? Thanks for any tips. Example code follows signature... -- Sheila King http://www.thinkspot.net/sheila/ #!/usr/local/bin/python2.4 import socket import sys from time import time, asctime, localtime socket.setdefaulttimeout(.1) debugfile = socketdebug.txt def debug(data): timestamp = str(asctime(localtime(time( try: f = open(debugfile, 'a') f.write('\n*** %s ***\n' % timestamp) f.write('%s\n' % data) # 24-Dec-2003 -ctm- removed one linefeed f.close() except IOError: pass # do nothing if the file cannot be opened IPaddy = '220.108.204.114' if IPaddy: IPquads = IPaddy.split('.') IPquads.reverse() reverseIP = '.'.join(IPquads) bl_list = { 'bl.spamcop.net' : 'IP Address %s Rejected - see: http://spamcop.net/bl.shtml' % IPaddy, \ 'relays.ordb.org' : 'IP Address %s Rejected - see: http://ordb.org/' % IPaddy, \ 'list.dsbl.org' : 'IP Address %s Rejected - see: http://dsbl.org' % IPaddy} timing_done = 0 start_time = time() for host in bl_list.keys(): if host in bl_list.keys(): IPlookup = %s.%s % (reverseIP, host) try: debug( IPlookup=%s= % IPlookup) resolvesIP = socket.gethostbyname(IPlookup) debug( resolvesIP=%s= % resolvesIP) if resolvesIP.startswith('127.'): end_time = time() elapsed_time = end_time - start_time timing_done = 1 debug(Time elapsed for rDNS on bl_list: %f secs % elapsed_time) debug(exiting--SPAM! id'd by %s % host) print bl_list[host] sys.exit(0) except socket.gaierror: pass if not timing_done: end_time = time() elapsed_time = end_time - start_time debug(2nd try:Time elapsed for rDNS on bl_list: %f secs % elapsed_time) I don't believe that gethostbyname()'s use of socket technology can be expected to raise socket timeout exceptions, since in general it's a call to a library that uses standard system calls. This would at least explain the behaviour you were seeing. It might just be easier to to the DNS work yourself using the rather nifty dnspython module. This does allow you to easily implement timeouts for specific interactions. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Zope, Python 2.4 pythonScripts import problem
On Tuesday 16 August 2005 07:09 am, [EMAIL PROTECTED] wrote: I see that Python 2.4.x does not work with Zope-2-7-6 properly. When I start zope I get warning that I should recompile my pythonScripts by executing manage_addProduct/PythonScripts/recompile. I do it and get list of scripts whoose were compiled but when I repeat that action I get the same list of scripts. It doesn't compile them - when I visit script by ZMI I still get the following error message invalid syntax (Script (Python), line 1). The first script at page http://www.zope.org/Members/goppelt/2-4-3Upgrade gives no effect - outcome is invalid syntax (Script (Python), line 1) error i scripts. I'm affraid that I will have to resign with Python 2.4.x :( I read that Python 2.4 was complaisant back but I don't think that Zope-2-7-6 is??? Please read the docs that come with zope. No version of zope supports python 2.4 right now. For zope 2.7 and zope 2.8 the python version to use is python 2.3.5. Everytime a new version of python is done a lot of stuff is checked to make sure it works and minor changes are made. I know it is possible to get zope2.7 and 2.8 working fine on python 2.4 but that should only be done by zope developers and not by zope users. -- http://mail.python.org/mailman/listinfo/python-list
PyXML and xml.dom
I'm writing a Python program that does some XML parsing, though nothing heavy, and I want to avoid requiring the user to install additional libraries like PyXML. The documentation for my version of Python (2.3.5) mentions PyXML as an additional library while discussing the DOM module http://www.python.org/doc/2.3.5/lib/module-xml.dom.html. I don't seem to have PyXML installed on my system, but: import xml.dom.minidom print xml.dom.minidom.xml.__doc__ [blah, blah] The full PyXML package, available from http://pyxml.sf.net, is installed. [blah, blah] Is PyXML now part of the Python distribution, or is it still an add-on? -- In the early 1980s, teenagers began getting high from aerosols, despite clear warnings of death. Then liability lawyer Victor E. Schwartz suggested adding a (false) warning of facial disfigurement. According to Schwartz, We haven't had a liability claim since. -- http://mail.python.org/mailman/listinfo/python-list
Re: zlib + Windows 32 service problem (ImportError)
Laszlo Zsolt Nagy wrote: | | C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client;c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program | Files\Common Files\GTK\2.0\bin | | Then I restarted my computer. It is still missing initzlib. :-( | Please note that I can run the same program as an application, logged in | as the same user. | | Les Changing the Windows dll search path doesn't make any difference. It is sys.path (Python's search path) that's causing you the headache. Please see the mentioned thread for proposed solutions. Great. I could make my service working with this snippet: import sys sys.path.insert(0,r'C:\Python24\DLLs') But this is very ugly. Primarily, I do not want to use absolute path names in a this program. I want to use the same code on different computers and operating systems, but this code is not portable. Try this (or something like it): if sys.platform == win32: sys.path.insert(0, sys.exec_prefix + r'\DLLs') Secondly, I do not understand why sys.path is different when I start python interactively. I believe that sys.path should be the same when starting the program as a service. The only difference between the application and the service is that the 'main' program of the service imports some additional modules. See them below. iT:\Python\Projects\NamedConnectorpython Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import sys s1 = str(sys.path) Add this: print os.getcwd() # see below for why import win32serviceutil, win32service import pywintypes, win32con, winerror from win32event import * from win32file import * from win32pipe import * from win32api import * from ntsecuritycon import * s2 = str(sys.path) Why do you think str() is needed here? print s1 == s2 True Add in here: print sys.path print os.getcwd() # see below for why I cannot distribute my service until I make it independent of the python installation directory. Why sys.path is different when starting the code as a windows service? Possibly because sys.path can start with '' which is interpreted as the current directory. Perhaps when the code is started as a windows service [I know nothing about windows services], the current directory is set to %windir%\system32 (where lots of DLLs hang out), and if there is a zlib.dll there, it will get picked up first. Try printing the current directory (see above). Setting the PYTHONVERBOSE environment variable may assist in showing where modules are being loaded from. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Making programs work together.
[EMAIL PROTECTED] wrote: Example: I'm driving a car in a game and I hit an oil slick so instead of me having to lift off the throttle button on the keyboard, I want to make a program to disengage the throttle as long as I'm on that oil slick. Does that clear anything up? Yes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterparse and ElementTree confusion
Further to the above I pass my found element 'Product' to ElementTree's handy print all function def print_all(element): root = element #Create an iterator iter = root.getiterator() #Iterate for element in iter: #First the element tag name print Element:, element.tag #Next the attributes (available on the instance itself using #the Python dictionary protocol if element.keys(): print \tAttributes: for name, value in element.items(): print \t\tName: '%s', Value: '%s'%(name, value) #Next the child elements and text print \tChildren: #Text that precedes all child elements (may be None) if element.text: text = element.text text = len(text) 40 and text[:40] + ... or text print \t\tText:, repr(text) if element.getchildren(): #Can also use: for child in element.getchildren(): for child in element: #Child element tag name print \t\tElement, child.tag #The tail on each child element consists of the text #that comes after it in the parent element content, but #before its next sibling. if child.tail: text = child.tail text = len(text) 40 and text[:40] + ... or text print \t\tText:, repr(text) if the element i pass to the above is from root = ElementTree(file='somefile.xml') iter = root.getiterator() #Iterate for element in iter: if element.tag == 'Product': print_all(element) I print all of my required element's attributes, children, children's children, etc However if i pass the element i get from iterparse for event, elem in iterparse(filename): if elem.tag == Products: print_all(elem) else: elem.clear() i only get the attributes for product and a list of its children, no further iteration into the children and the children's children what am i missing? -- http://mail.python.org/mailman/listinfo/python-list
Lists of list
Hi All I am having problem with delete line if its belong to another one , example ['0132442\n', '13\n', '24\n'] the 2nd and 3rd are already in the first line , how can do this !!! Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterparse and ElementTree confusion
[EMAIL PROTECTED] wrote: def parse_for_products(filename): for event, elem in iterparse(filename): if elem.tag == Products: root = ElementTree(elem) print_all(root) else: elem.clear() My problem is that if i pass the 'elem' found by iterparse then try to print all attributes, children and tail text i only get elem.tagelem.keys returns nothing as do all of the other previously useful elementtree methods. Am i right in thinking that you can pass an element into ElementTree? How might i manually iterate through product.../product grabbing everything? by default, iterparse only returns end events, which means that the iterator will visit the Products children before you see the Products element itself. with the code above, this means that the children will be nuked before you get around to process the parent. depending on how much rubbish you have in the file, you can do for event, elem in iterparse(filename): if elem.tag == Products: process(elem) elem.clear() or for event, elem in iterparse(filename): if elem.tag == Products: process(elem) elem.clear() elif elem.tag in (Rubbish1, Rubbish2): elem.clear() or inside = False for event, elem in iterparse(filename, events=(start, end)): if event == start: # we've seen the start tag for this element, but not # necessarily the end tag if elem.tag == Products: inside = True else: # we've seen the end tag if elem.tag == Products: process(elem) elem.clear() inside = False elif not inside: elem.clear() for more info, see http://effbot.org/zone/element-iterparse.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Urgent: Embedding Python problems - advice sought
Does anyone have advice on other groups, sites etc that has knowledge of this subject ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: FW: List copying idiom was Re: [Python-Dev] implementation of copystandard lib
On Wed, 17 Aug 2005, Delaney, Timothy (Tim) wrote: Tom Anderson wrote: When you say [:], do you mean that you copy lists like this: l = someList() m = [] m[:] = l Forwarded to python-list, where it belongs. The idiom is actually: a = [1, 2, 3] b = a[:] Aha. I'd never thought of that. Doh. tom -- 10 PARTY : GOTO 10 -- http://mail.python.org/mailman/listinfo/python-list
Off-screen rendering in PyOpenGL?
Poking around in the PyOpenGL tarball... I can see that the wrapper for the WGL pixel format function includes flags for rendering to a bitmap and for hardware acceleration... so maybe I could get hardware-accelerated off-screen rendering under win32.. but what about linux? Matt Feinstein -- There is no virtue in believing something that can be proved to be true. -- http://mail.python.org/mailman/listinfo/python-list
Re: List copying idiom was Re: [Python-Dev] implementation of copy standard lib
On Wed, 17 Aug 2005, Steve Holden wrote: Tom Anderson wrote: On Tue, 16 Aug 2005, Ron Adam wrote: Simon Brunning wrote: On 8/14/05, Martijn Brouwer [EMAIL PROTECTED] wrote: I can imagine that *a lot* of libs/scripts use the copy library, I think that copy is very rarely used. I don't think I've ever imported it. I too have wondered why copy isn't a builtin, Same here. It seems like a sort of obvious thing to have, and could probably implemented much more simply and quickly in the interpreter. You'd probably want a __copy__ hook for classes which want special handling, and just do a normal deep copy for everything else. Well yes, but given that module copy now exists (and will therefore have to continue ti exist until Py3) that would introduce some redundancy. True. This is more of a vague Py3k wish than a serious suggestion. tom -- 10 PARTY : GOTO 10 -- http://mail.python.org/mailman/listinfo/python-list
Re: stopping a python windows service
I may have taken your code example too literally. I tried putting in the check for 'shutdownEvent.isset()' but it's failing at run time. It's looking for a global variable, I guess. Do I have to register these threads somehow in the beginning? I'm somewhat new to Python so please be patient... -- http://mail.python.org/mailman/listinfo/python-list
Re: get the return code when piping something to a python script?
Now that I know it's not possible to do what I wanted, I can work around this without a problem. I'll just scan the output of the .exe to determine whether it appears to have failed or not. Thanks to everyone for the info. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need better way to unpack a list
for index, value in enumerate(mylinelist): getattr(self, line%d % (index + 1)).setText(value) Thanks ! This was the line which did it The correct code snippet now reads : # set the lineedits of the QT gui for index,value in enumerate(self.mylinelist): getattr(self, lineEdit%d % (index + 1)).setText(self.tr(value)) Nx -- http://mail.python.org/mailman/listinfo/python-list
sys.path and win32 services (was: importerror)
Why do you think str() is needed here? Because I'm not sure if sys.path was overwritten or changed. Some bad modules could overwrite sys.path with another list. I know I'm paranoid. :-) Possibly because sys.path can start with '' which is interpreted as the current directory. Perhaps when the code is started as a windows service [I know nothing about windows services], the current directory is set to %windir%\system32 (where lots of DLLs hang out), and if there is a zlib.dll there, it will get picked up first. Try printing the current directory (see above). Okay, I did so. I wrote a service that prints out sys.path into a logfile. Here is the result: sys.path=['C:\\Python24\\lib\\site-packages\\win32', 'T:\\Python\\Lib', 'C:\\WINDOWS\\system32\\python24.zip', 'C:\\WINDOWS\\system32', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Python24\\lib\\site-packages\\win32', 'C:\\Python24', 'C:\\Python24\\lib\\site-packages', 'C:\\Python24\\lib\\site-packages\\PIL', 'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\\lib\\site-packages\\Pythonwin', 'C:\\Python24\\lib\\site-packages\\wx-2.6-msw-ansi', 'T:\\Python\\Projects\\NamedConnector'] The empty string is not on sys.path. This is very strange, because it is different when I start the python interactively. The problem was caused by C:\WINDOWS\system32, not the empty string. I'm still not sure why it is included in sys.path, and why '' is not there? I also checked the Python documentation about sys.path, and read the thread mentioned before but still sys.path is magical, and magic is not Pythonic. :-) Anyway, I think I have found the most platform independent solution. Here it is: import _socket import os import sys dyndir = os.path.split(_socket.__file__)[0] # This can be /usr/local/lib/python2.4/lib-dynload or C:\Python24\DLLs or whatever sys.path.append(dyndir) In most cases, '_socket.pyd' will be the first module that can be imported, and it will by in the dynaload directory for sure. I feel this is still unclean code. Do you think that it would be nice to add new features to the sys module? sys.dlpath - could be the path to the lib-dynload or DLLs folder sys.libpath - could be the path to the lib folder Setting the PYTHONVERBOSE environment variable may assist in showing where modules are being loaded from. This cannot be used in conjunction with a windows service, because its output cannot be seen. :-( -- http://mail.python.org/mailman/listinfo/python-list
Re: looping list problem
Fredrik Lundh wrote: Jon Bowlas wrote: (snip) But I get the following error- Line 5: Yield statements are not allowed. umm. I might be missing something, but I cannot find any trace of that error message in the Python interpreter source code. it doesn't even look like a Python traceback. did you perhaps forget to tell us that you're using some fancy web framework that uses Python in its own idiosyncratic way? Some fancy web framework named Zope, I guess... -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: get the return code when piping something to a python script?
I use the following when I have an external command to do: # def doCommand( cmd,forked=False,runFrom=None ): Do a command, and return the (stdout+stderr) and the exit status. This was written to work both on Windows and *nix, and in the limited testing to which it has been subjected, it works well. import sys; import os; exitcode = None; output = None; origin = None; if runFrom: origin = os.getcwd() try: os.chdir( runFrom ); except: pass; # forked to us means run in background and forget about it. The # method of execution is the same on both windows and unix if forked: theCommand = cmd.split()[0]; theArgs= cmd.split(); # Include the cmd itself in the v. # Guaranteed to be a list. # P_DETACH: we don't want the process to be our child, and # we don't want to know what happens to it... Some father! exitstatus = os.spawnve( os.P_DETACH,theCommand,theArgs,os.environ ); # if we're not spawning off a separate child, then we do care about # the results of the process, and execution is different between # windows and unix else: if( sys.platform == win32 ): import win32pipe; (stdin,stdout) = win32pipe.popen4( cmd,'t' ); stdin.close(); output = stdout.read(); try: exitcode = stdout.close() or 0; except IOError: exitcode = ( -1 ); else: import commands; ( exitstatus,output ) = commands.getstatusoutput(cmd) # exitstatus is a smashing of the return value and any signal # sent back from the child process... break them out. exitcode = (( exitstatus 8) 0xFF ); signal = ( exitstatus0xFF ); if runFrom: #return( 0,Returning to %s from %s %(origin,os.getcwd()) ) os.chdir( origin ); return( exitcode,output ); #--- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as VBA replacement under Windows?
Wolfgang Keller [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello, this is a potentially veeery dumb question, but: - If an application supports VBA as a macro language, - and if you can execute Python code from within a VBA script (how?) - and if the application exposes its VBA scripting interface through COM then it should be perfectly possible to entirely replace VBA in nearly all Windows applications with Python, right? TIA, sincerely, Wolfgang Keller perfectly possible? Hmmmhh! Because the MS Office suite and a few (very few!) other applications expose their object models via COM, you can manipulate these programs with Python and other languages. No applicatoin supports VBA as a macro language. Rather - VBA is bundled and integrated with MS Office in order to manipulate COM. You can use Python to do that too! However It is difficult to argue with the built in integrated editor/debugger behind Excel, Word, PowerPoint, et al with the scripts packaged seamlessly inside the application files. It's also difficult to argue with the myriad of built in VBA functions that are custom designed to ease the pain of working with Windows internals. On the other hand I can think of nothing that you can do with VBA but can not do with Python. It just takes a bit more effort and you need to know more of Windows internals in order to pull it off. perfectly possible? I'm still thinking :-) -Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: Read from stdouton Popen on WinXP?
As far as I understand it, the buffering is indeed happening in the .exe, depending on what it thinks it's stout is connected to. There's nothing the operating system, or Python can do about it, if the .exe was created using #include stdio.h. This might help: http://www.cplusplus.com/ref/cstdio/ http://htmlhelp.sunsite.dk/page.php/9/ch13s20.html http://pexpect.sourceforge.net/ Especially read the FAQ of Pexpect, it's quite clear. It took me some time to figure it out too, and I'm not realy happy about it, but I suppose that the advantage is, that it's all KR compatible in this way. I find that as long as one of the stdin/out/err are connected to a terminal, stdio will use them as character devices. This is why .exe | more works I think: more's stdout$err are a terminal, therefore it's std is a character device, and then the pipe is a character device, and then the .exe will have stdout as a character device. I do not know al the intricate details, but for me Pexpect works, and it's FAQ is quite clear, but AFAIK there are no pseudo-terminals on Windows, so you'll need to find a different trick. Adriaan. Matthew Henry [EMAIL PROTECTED] 08/17/05 3:42 pm On 8/17/05, Adriaan Renting [EMAIL PROTECTED] wrote: that only works on Unix. The problem is the way stdout in C works: - If connected to a character device, it will flush after each line. - If connected to a block device it will flush only after it's buffer is full. Any kind of pipe or file is a block device. As this is how stdout works even your OS can't help, because as long as the application doesn't flush, the output doesn't even arrive at the pipe or file. Thanks for the info. I am a longtime C++ programmer, but all GUI stuff so I'm afraid I don't really understand how the stdio stuff works. From the cmd prompt, I can pipe the output of the .exe to more and see it work in realtime. Thus I presume the buffering is happening on the Python end (or the stdio library that Python is using). Not in the .exe. So, assuming that's true, why would it help to have the created process flush its buffer? Does that put some kind of special character in the buffer that tells Python's stdio library to clear out its buffer? Or is my assumption incorrect, and the buffering is happening in the .exe and the cmd shell is working some magic to get at the output? Know of a good (online) reference that explains how stdin, stdout, stderr really works under the covers? Especially under Windows? -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
Paul Rubin http://[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Mateusz £oskot [EMAIL PROTECTED] writes: Thank you for any piece of advice in advance. Ask yourself why you want a GUI toolkit. Maybe you can write a web application instead, and use a browser as the GUI. That's a lot easier to write (just use html), and makes it trivial to run the application and the browser on separate machines. Wow Paul! I just couldn't help zeroing on that comment. a lot easier to write (just use html), I would have used adjectives like clunky and limited when talking about using an html in a browser app. Particularly if we are talking about high powered math/graphs as we often are in the science apps indicated in the original post. I would take MS Excel/VBA as the premier fat client prototyping tool/GUI toolkit for science education. How would one go about replicating any of that in an HTML/browser app? How do we get to easier to write? Ask yourself why you want a GUI toolkit. I just did. The answer is that I don't *think* you can do much of that with html. Then again - I was wrong once :-) -Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as VBA replacement under Windows?
Because the MS Office suite and a few (very few!) other applications expose their object models via COM, you can manipulate these programs with Python and other languages. No applicatoin supports VBA as a macro language. What I meant was that quite a lot of Windows applications (not only MS Office) allow to execute VBA scripts just like macros from within the application. What I want now is to write a dummy VBA script container that consists of/executes Python sourcecode by calling the Pythonwin interpreter. Rather - VBA is bundled and integrated with MS Office in order to manipulate COM. You can use Python to do that too! Yup, from outside. What I would like to do is do it from inside the application. perfectly possible? Well, at least as far as there's a COM interface and for someone who refuses to learn VB(A) but still wants to script Windows applications. Sincerely, Wolfgang Keller -- http://mail.python.org/mailman/listinfo/python-list
Re: random seed
Robert Kern wrote: random.seed(1234567890) is traditional and works just fine. Other favorites: 3141592653589793 2718281828459045 Nothing beats 42! (That was just an exclamation mark in the end, no factorial intended.) 371 is another nice number, since it's its own reverse in hex. If you liked 3141592653589793, you might also like 113355. :) -- http://mail.python.org/mailman/listinfo/python-list
Testing for presence of arguments
Hi I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
Well, I don't think you want to write everything in HTML, but you can certainly have a program in Python/perl/PHP/ASP/java that outputs your user interface in HTML on one side, and maybe talks to Matlab or Root on the otherside to do the actual science/generate the images. I wouldn't advice Excel+VBA, unless it's the only thing you have. Thomas Bartkus [EMAIL PROTECTED] 08/17/05 4:50 pm Paul Rubin http://[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Mateusz £oskot [EMAIL PROTECTED] writes: Thank you for any piece of advice in advance. Ask yourself why you want a GUI toolkit. Maybe you can write a web application instead, and use a browser as the GUI. That's a lot easier to write (just use html), and makes it trivial to run the application and the browser on separate machines. Wow Paul! I just couldn't help zeroing on that comment. a lot easier to write (just use html), I would have used adjectives like clunky and limited when talking about using an html in a browser app. Particularly if we are talking about high powered math/graphs as we often are in the science apps indicated in the original post. I would take MS Excel/VBA as the premier fat client prototyping tool/GUI toolkit for science education. How would one go about replicating any of that in an HTML/browser app? How do we get to easier to write? Ask yourself why you want a GUI toolkit. I just did. The answer is that I don't *think* you can do much of that with html. Then again - I was wrong once :-) -Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
On 8/17/05, Madhusudan Singh [EMAIL PROTECTED] wrote: I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). Could you just write the function as: myFunc(*args, **kwargs): ...and then figure out what was passed? -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterparse and ElementTree confusion
when i attempted [to load 150MB xml file] my PC goes to lala land, theres much HDD grinding followed by windows runnign low on virtual memory popup after 10-15mins. Then just more grinding...for an hour before i gave up I have had great success using SAX to parse large XML files. If you use care your memory use will peak at a low number no matter how much XML you chew through. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
On Wed, 17 Aug 2005 11:13:03 -0400, Madhusudan Singh [EMAIL PROTECTED] wrote: I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? def f(**kw): if kw.has_key('required_argument'): print require_argument was present else: print require_argument was not present My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). You can very nearly achieve this with carefully planned default arguments. Put this into a module: class _SemiPrivateClass: pass def f(required_argument=_SemiPrivateClass): if required_argument == _SemiPrivateClass: print required_argument was probably not present else: print required_argument was present It's not impossible fool f, but an external module has to try very hard to do so. (All code untested.) Regards, Dan -- Dan Sommers http://www.tombstonezero.net/dan/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Madhusudan Singh wrote: I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? People generally use a value that isn't a valid option, often None. def my_func(a, b, c=None): if c is None: do something If None is a valid value, make one that isn't: unspecified = object() def my_func(a, b, c=unspecified): if c is unspecified: do something -- Benji York -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
I don't have the details ready - but in the ASPN cookbook are recipes to e.g. figure insied a function f out how many results the caller of f expects - and act accordingly. This boils down to inspect the call-stack. So it ceratinly is possible. However, I'd say it is almost 100% a design flaw. Or can you give us a compelling reason why you need this behaviour? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: extending: new type instance
BranoZ [EMAIL PROTECTED] writes: I'm writing my own (list-like) type in C. It is implementing a Sequence Protocol. In 'sq_slice' method I would like to return a new instance of my class/type. How do I create (and initialize) an instance of a given PyTypeObject MyType ? I have tried to provide (PyObject *)MyType as 'class' argument to: PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw) It failed the PyClass_Check. I have also found a couple of PyObject_New functions which accept PyTypeObject as an argument. They look very low-level and obviously don't call __init__. Should I do it myself manualy ? PyObject_New is the usual way, although there are others -- MyType.tp_new, PyObject_Call ... Cheers, mwh -- 81. In computing, turning the obvious into the useful is a living definition of the word frustration. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as VBA replacement under Windows?
Wolfgang Keller [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Because the MS Office suite and a few (very few!) other applications expose their object models via COM, you can manipulate these programs with Python and other languages. No applicatoin supports VBA as a macro language. What I meant was that quite a lot of Windows applications (not only MS Office) allow to execute VBA scripts just like macros from within the application. What I want now is to write a dummy VBA script container that consists of/executes Python sourcecode by calling the Pythonwin interpreter. I *think* you may want to approach this from the other way around. If it were me, I would write a Python app that initates, and maintains handles to, the target Windows app. The controlling Python app could then drop from sight and respond as necessary to events occurring within the Windows app. This is the way you would do it from an external VB app. Rather - VBA is bundled and integrated with MS Office in order to manipulate COM. You can use Python to do that too! Yup, from outside. What I would like to do is do it from inside the application. I don't *think* this is possible. Nor do I think this is worth worrying about. You write VB/VBA applications to work either from the inside (in process) or the outside (out of process) with the former being somewhat more efficient. Unfortunately, this is where VBA with it's integrated editor is woven into the warp and woof of MS Office. You are stuck running out of process with Python. But again, I don't really see this as being worth worrying about. perfectly possible? Well, at least as far as there's a COM interface and for someone who refuses to learn VB(A) but still wants to script Windows applications. I have dabbled a bit using Python to control Excel. But just a bit. It's just too easy to invoke VBA behind Excel and fire away - even if the resulting code isn't nearly so elegant! Somewhere out there, is a project to integrate Python into Visual Studio. Microsoft has rewritten Visual Studio to enable the integration of 3rd party languages. That might hold some promise for you although I have not been following developments here very closely. As for me - I'm sick of the directions MS is taking. I'm looking to Gnumeric/Python as an open source replacement to Excel/VBA :-) Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Diez B. Roggisch wrote: I don't have the details ready - but in the ASPN cookbook are recipes to e.g. figure insied a function f out how many results the caller of f expects - and act accordingly. This boils down to inspect the call-stack. So it ceratinly is possible. However, I'd say it is almost 100% a design flaw. Or can you give us a compelling reason why you need this behaviour? Diez I am writing some code for a measurement application (would have used fortran 95 if a library had been available for linux-gpib, but python is a lot friendlier than C without the irritating and utterly pointless braces) where one of the input parameters for the GPIB command is optional, and depending on whether it is specified at all, an entire sequence of commands has to be sent to the GPIB bus plus some input parameters recalculated. Further, the sequence of commands depends on the range of values of the optional parameter. And some of these commands in turn have similar optional arguments. All in all, the above would have been a bunch of simple one-liners with a simple if block if python had something like the fortran 95 present() intrinsic, but I could not find it. Hence my query. Just because there is no simple and direct way of doing something in a language does not mean that the application that requires it has a design flaw. Unrelated question, how does one call a fortran 95 subroutine from python ? I need really high speed of execution for that call (needed for each measurement point, and is used to calculate some parameters for the excitation for the next measurement point) and a scripting language would not cut it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Benji York wrote: Madhusudan Singh wrote: I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? People generally use a value that isn't a valid option, often None. def my_func(a, b, c=None): if c is None: do something If None is a valid value, make one that isn't: unspecified = object() def my_func(a, b, c=unspecified): if c is unspecified: do something -- Benji York Now, that was a very good suggestion. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Dan Sommers wrote: On Wed, 17 Aug 2005 11:13:03 -0400, Madhusudan Singh [EMAIL PROTECTED] wrote: I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? def f(**kw): if kw.has_key('required_argument'): print require_argument was present else: print require_argument was not present My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). You can very nearly achieve this with carefully planned default arguments. Put this into a module: class _SemiPrivateClass: pass def f(required_argument=_SemiPrivateClass): if required_argument == _SemiPrivateClass: print required_argument was probably not present else: print required_argument was present It's not impossible fool f, but an external module has to try very hard to do so. (All code untested.) Regards, Dan Thanks for the suggestion, but seems needlessly complicated for something very simple. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Peter Decker wrote: On 8/17/05, Madhusudan Singh [EMAIL PROTECTED] wrote: I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). Could you just write the function as: myFunc(*args, **kwargs): ...and then figure out what was passed? Seems a lot simpler than the other module suggestion, but another person has posted a suggestion that is a lot more quick and elegant. Thanks anyways. I might find this useful in some as yet unknown context. -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP and XMLRPC
Daniel == dcrespo [EMAIL PROTECTED] writes: Daniel Someone knows if is there possible to have a Python SOAP Daniel or XMLRPC server that works with VB? Sure, why not? What have you tried that didn't work? Getting SOAP libraries to interoperate is often a pain but usually possible unless you want to be able to have more than one type of library for clients. Daniel My examples are: [...] Good. So you seem to have the Python side going. Are you asking in the Python group for help with VB? Or do you have a VB solution/attempt that you can't get your Python server to work with? In the former case I suggest you contact a VB group in the latter that you post infos on what you have tried already so we don't have to guess. As an additional pointer, I can tell you that I have had success with getting a PocketSOAP client to talk to a SoapPy server. You may want to give that a try. Holger -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
1. Mateusz Loskot: I would like to ask some scientists or students which GUI toolkit they would recommend to develop scientific prototypes (for education and testing some theories). My vote is for ipython + matplotlib. Very easy and very powerful. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Urgent: Embedding Python problems - advice sought
[EMAIL PROTECTED] writes: Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). What version of Python are you using? Can anyone clarify: - if Python correctly supports multiple sub-interpreters (Py_NewInterpreter) ? It's supposed to but it's not often used or tested and can get a bit flaky. - if Python correctly supports multiple thread states per sub-interpreter (PyThreadState_New) ? There are bugs in 2.3.5 and 2.4.1 in this area (they are fixed in CVS -- I hope -- and will be in 2.4.2). and the real question: - what is the rationale for choosing one of: [a] one sub-interpreter with many thread states This is the best tested and understood (it's what the core Python interpreter does, after all). [b] many sub-interpreters with one thread state each [c] many sub-interpreters with many threas states each These are probably somewhat broken in recent Python's, I'm afraid. Can you try CVS? Cheers, mwh -- ARTHUR: Yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard. -- The Hitch-Hikers Guide to the Galaxy, Episode 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Urgent: Embedding Python problems - advice sought
[EMAIL PROTECTED] writes: Does anyone have advice on other groups, sites etc that has knowledge of this subject ? I've just replied to your original post, having not seen it the first time around. Cheers, mwh -- Nafai w00t w00t w00t w00t! Nafai I don't understand all of the code, but it works! Nafai I guess I should check it in. -- from Twisted.Quotes -- http://mail.python.org/mailman/listinfo/python-list
SPE 0.7.5.b IDE: New windows installer (with working shortcuts)
Thanks to Jose Galvez, there is a now a working python installer for python2.4 SPE 0.7.5.b now features a remote, encrypted and embedded python debugger of Nir Aides. Stani Spe is a free python IDE with auto indentation completion, call tips, syntax coloring highlighting, UML diagrams, class explorer, source index, auto todo list, sticky notes, pycrust shell, file browsers, dragdrop, context help, Blender support, ... Spe ships with Python debugger (remote encrypted), wxGlade (gui designer), PyChecker (source code doctor) and Kiki (regex console). http://pythonide.stani.be http://pythonide.stani.be/screenshots Screenshot of windows shortcuts: http://pythonide.stani.be/screenshots/spe-win-start.png -- http://mail.python.org/mailman/listinfo/python-list
Obfuscator for Python Code
Is there any obfuscator out there that obfuscates the python code (byte code i guess)??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Obfuscator for Python Code
codecraig [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there any obfuscator out there that obfuscates the python code (byte code i guess)??? Hmmhh! I know lots of obfuscators for VB, C, and Java. For these languages, it seems to be one of the more popular coding specialties. Certainly, I don't see much reason why one couldn't obfuscate Python code. It's just that coders with an aptitude for obfuscation don't seem to like the Python language very much. Perhaps if the help wanted ads contained more Python posting, the obfuscators might be tempted to flock to it :-) Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
I am writing some code for a measurement application (would have used fortran 95 if a library had been available for linux-gpib, but python is a lot friendlier than C without the irritating and utterly pointless braces) where one of the input parameters for the GPIB command is optional, and depending on whether it is specified at all, an entire sequence of commands has to be sent to the GPIB bus plus some input parameters recalculated. Further, the sequence of commands depends on the range of values of the optional parameter. And some of these commands in turn have similar optional arguments. I still don't see why default arguments like None won't do the trick. If The argument _can_ be some value (let's say an int) or None, you still could go for a default value like () or any other value from a different domain. All in all, the above would have been a bunch of simple one-liners with a simple if block if python had something like the fortran 95 present() intrinsic, but I could not find it. Hence my query. Just because there is no simple and direct way of doing something in a language does not mean that the application that requires it has a design flaw. Certainly, but as certainly thinking in terms of one language while using another is prone to creating design flaws. So far you still haven't convinced me that default arguments don't work for you. To me it seems that your idiom of present() is modeld by python's if arg is None: whatever pretty mich. It might help if you show'd us what your code would like _if_ python had present() available. Then we can see what alternatives there are. Unrelated question, how does one call a fortran 95 subroutine from python ? I need really high speed of execution for that call (needed for each measurement point, and is used to calculate some parameters for the excitation for the next measurement point) and a scripting language would not cut it. Didn't ever try that, but either do it in C, or if fortran code can be exposed as C lib, use that (ctypes is your friend). I'm not aware of a fortran binding - but I never tried to find one. Basically Python can interface with everything that can behave like C - which is the least common denominator I think, so there should be some way. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
win32pipe.popen3
Follow-up on a thread from 1999 (see below) Well now it is 2005 and the operating system I'm using is Windows Server 2003, and I can still see that the same problem persists with: win32pipe.popen2() win32pipe.popen3() win32pipe.popen4() while win32pipe.popen() does almost what you want. import win32pipe win32pipe.popen('cmd') open file 'cmd', mode 'r' at 0x009DD698 r=win32pipe.popen('cmd') r.readline() 'Microsoft Windows XP [Version 5.1.2600]\n' r.readline() '(C) Copyright 1985-2001 Microsoft Corp.\n' r.readline() '\n' r.readline() 'C:\\backup\\TRPython241\\trpython' Although I think the last readline ought to return None since no carriage return has been issued yet, it is better than popen2,popen3 and popen4, which all just block the parent process. The current behaviour of win32pipe.popen2(), win32pipe.popen3() and win32pipe.popen4() would be acceptable for me if I knew a way to test if there was something ready for reading, but I can't see how to do that test, therfore I don't know when to stop reading from output :( Is there a solution for this, can I poll/test for ready-read on popen3 I/O objects. Best regards Jakob Simon-Gaarde --- From a thread in 1999 High Arpard, thanx for help but I got probs with that popen3 under Win95: 'o.readlines()' doesn't return anymore. To find out I checked it line per line: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam import win32pipe i,o,e=win32pipe.popen3('ver', 'b') o.readline() '\015\012' o.readline() 'Windows 95. [Version 4.00.]\015\012' o.readline() '\015\012' o.readline() Don't know why, but it never;-) returns. Perhaps it may be a bug in win32pipe, that it doesn't return becourse readline couldn't find CarriageReturn/EOF? I took win32pipe.popen('ver','r') for a better solution. That works fine. greetings, Holger -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Diez B. Roggisch wrote: I still don't see why default arguments like None won't do the trick. If The argument _can_ be some value (let's say an int) or None, you still could go for a default value like () or any other value from a different domain. None works perfectly. Someone else on the thread suggested it. I did not know about the special intrinsic. Unrelated question, how does one call a fortran 95 subroutine from python ? I need really high speed of execution for that call (needed for each measurement point, and is used to calculate some parameters for the excitation for the next measurement point) and a scripting language would not cut it. Didn't ever try that, but either do it in C, or if fortran code can be exposed as C lib, use that (ctypes is your friend). I'm not aware of a fortran binding - but I never tried to find one. Basically Python can interface with everything that can behave like C - which is the least common denominator I think, so there should be some way. Hmm. Thanks for the pointers here. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] implementation of copy standard lib
Michael Hudson wrote: Simon Brunning [EMAIL PROTECTED] writes: I think that copy is very rarely used. I don't think I've ever imported it. Or is it just me? Not really. I've used it once that I can recall, to copy a kind of generic default value, something like: def value(self, v, default): if hasattr(source, v): return getattr(source, v) else: return copy.copy(default) (except not quite, there would probably be better ways to write exactly that). Cheers, mwh My most recent use of copy.deepcopy() was to save the state of a recusivly built object so that it could be restored before returning a result that involved making nested changes (with multiple methods) to the ojbects subparts as part of the result calculation. The alternative would be to use a flag and shallow copies in all the methods that altered the object. copy.deepcopy() was a lot easier as it's only needed in the method that initiates the result calculation. Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Madhusudan Singh wrote: Unrelated question, how does one call a fortran 95 subroutine from python ? I need really high speed of execution for that call (needed for each measurement point, and is used to calculate some parameters for the excitation for the next measurement point) and a scripting language would not cut it. http://cens.ioc.ee/projects/f2py2e/ -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Obfuscator for Python Code
codecraig schrieb: Is there any obfuscator out there that obfuscates the python code (byte code i guess)??? http://www.lysator.liu.se/~ast rand/projects/pyobfuscate/ -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Obfuscator for Python Code
Peter Maas schrieb: codecraig schrieb: Is there any obfuscator out there that obfuscates the python code (byte code i guess)??? http://www.lysator.liu.se/~ast rand/projects/pyobfuscate/ Delete space: http://www.lysator.liu.se/~astrand/projects/pyobfuscate/ -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Re: String functions deprication
Dan wrote: http://www.python.org/doc/2.4.1/lib/node110.html These methods are being deprecated. What are they being replaced with? They're being made methods of the string class itself. For example: s = 'any old string' string.split(s, ' ') # Old way ['any', 'old', 'string'] s.split()# New way s.split(' '), if we want to be equivalent. ['any', 'old', 'string'] Reinhold -- http://mail.python.org/mailman/listinfo/python-list
looking to GIVE my first oral favor
im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me -- http://mail.python.org/mailman/listinfo/python-list
Tix cannot open /usr/share/libtix
Hi, I have a problem getting Tix to run: Python 2.4.1 (#2, Aug 17 2005, 10:19:59) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type help, copyright, credits or license for more information. import Tix t = Tix.Tk() Traceback (most recent call last): File stdin, line 1, in ? File /usr/projects/EES_dev/haroldf/lib/python2.4/lib-tk/Tix.py, line 210, in __init__ self.tk.eval('package require Tix') _tkinter.TclError: couldn't load file /usr/share/libtix8.1.8.3.so: /usr/share/libtix8.1.8.3.so: cannot open shared object file: No such file or directory libtix is not in /usr/share/ but I located it in /usr/lib/ [EMAIL PROTECTED] dpd]$ locate libtix8.1.8.3.so warning: locate: warning: database /var/lib/slocate/slocate.db' is more than 8 days old /usr/lib/libtix8.1.8.3.so [EMAIL PROTECTED] dpd]$ is there any way to tell python/tkinter/tix where to look for the library? thanks, - harold - -- http://mail.python.org/mailman/listinfo/python-list
Re: creating/modifying sparse files on linux
[EMAIL PROTECTED] wrote] Hi, Is there any special support for sparse file handling in python? My initial search didn't bring up much (not a thorough search). I wrote the following pice of code: options.size = 6442450944 options.ranges = [4096,1024,3,314572800] fd = open(testfile, w) fd.seek(options.size-1) fd.write(a) for drange in options.ranges: off = int(drange.split(,)[0]) len = int(drange.split(,)[1]) print off =, off, len =, len fd.seek(off) for x in range(len): fd.write(a) fd.close() This piece of code takes very long time and in fact I had to kill it as the linux system started doing lot of swapping. Am I doing something wrong here? Is there a better way to create/modify sparse files? test_largefile.py in the Python test suite does this kind of thing and doesn't take very long for me to run on Linux (SuSE 9.0 box). Trent -- Trent Mick [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: creating/modifying sparse files on linux
In [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: options.size = 6442450944 options.ranges = [4096,1024,3,314572800] fd = open(testfile, w) fd.seek(options.size-1) fd.write(a) for drange in options.ranges: off = int(drange.split(,)[0]) len = int(drange.split(,)[1]) print off =, off, len =, len fd.seek(off) for x in range(len): fd.write(a) fd.close() This piece of code takes very long time and in fact I had to kill it as the linux system started doing lot of swapping. Am I doing something wrong here? Is there a better way to create/modify sparse files? `range(len)` creates a list of size `len` *in memory* so you are trying to build a list with 314,572,800 numbers. That seems to eat up all your RAM and causes the swapping. You can use `xrange(len)` instead which uses a constant amount of memory. But be prepared to wait some time because now you are writing 314,572,800 characters *one by one* into the file. It would be faster to write larger strings in each step. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
looking to GIVE my first oral favor
im new to this, i guess you can say im still curious about having extra marital lovers. i've only had 1 encounter with a married man and I loved it so much. its such a strong burning desire now. when I look at men, i'm always wondering how they look nude, or their cock size. basically, i want to find a man to have his way with me and really show me the ropes of being a lover to another man on the side. exchange face and cock pics with me here under luvnlady3050 http://www.no-strings-fun.net/kallegirl26 kisses, me -- http://mail.python.org/mailman/listinfo/python-list
Moinmoin config
Hi, I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, all screen elements are lined up on the left hand side. How can I get it displayed like the wiki at: http://moinmoin.wikiwikiweb.de/HelpOnConfiguration instead of this ? - LANShieldOS Release Notes Search: * MarkRuedy * UserPreferences * HelpOnEditing * HelpContents * HelpForBeginners * UserPreferences * FrontPage * RecentChanges * FindPage * HelpContents * Edit * Show Changes * Get Info * Subscribe * FrontPage -- http://mail.python.org/mailman/listinfo/python-list
Re: Tix cannot open /usr/share/libtix
[EMAIL PROTECTED] wrote: is there any way to tell python/tkinter/tix where to look for the library? Try (un)setting TIX_LIBRARY. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: creating/modifying sparse files on linux
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there any special support for sparse file handling in python? Since I have not heard of such in several years, I suspect not. CPython, normally compiled, uses the standard C stdio lib. If your system+C has a sparseIO lib, you would probably have to compile specially to use it. options.size = 6442450944 options.ranges = [4096,1024,3,314572800] options.ranges = [(4096,1024),(3,314572800)] # makes below nicer fd = open(testfile, w) fd.seek(options.size-1) fd.write(a) for drange in options.ranges: off = int(drange.split(,)[0]) len = int(drange.split(,)[1]) off,len = map(int, drange.split(,)) # or off,len = [int(s) for s in drange.split(,)] # or for tuples as suggested above off,len = drange print off =, off, len =, len fd.seek(off) for x in range(len): If I read the above right, the 2nd len is 300,000,000+ making the space needed for the range list a few gigabytes. I suspect this is where you started thrashing ;-). Instead: for x in xrange(len): # this is what xrange is for ;-) fd.write(a) Without indent, this is syntax error, so if your code ran at all, this cannot be an exact copy. Even with xrange fix, 300,000,000 writes will be slow. I would expect that an real application should create or accumulate chunks larger than single chars. fd.close() This piece of code takes very long time and in fact I had to kill it as the linux system started doing lot of swapping. Am I doing something wrong here? See above Is there a better way to create/modify sparse files? Unless you can access builting facilities, create your own mapping index. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists of list
Mohammed Altaj [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I am having problem with delete line if its belong to another one , example ['0132442\n', '13\n', '24\n'] the 2nd and 3rd are already in the first line , how can do this !!! You have a list of strings, not a list of lists. Anyway, I can't understand your question. You will probably have to give more information. tjtr -- http://mail.python.org/mailman/listinfo/python-list
Re: creating/modifying sparse files on linux
Thanks for the info on xrange. Writing single char is just to get going quickly. I knew that I would have to improve on that. I would like to write chunks of 1MB which would require that I have 1MB string to write. Is there any simple way of generating this 1MB string (other than keep appending to a string until it reaches 1MB len)? I don't care about the actual value of the string itself. Thanks, Raghu. -- http://mail.python.org/mailman/listinfo/python-list
Re: creating/modifying sparse files on linux
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Thanks for the info on xrange. Writing single char is just to get going quickly. I knew that I would have to improve on that. I would like to write chunks of 1MB which would require that I have 1MB string to write. Is there any simple way of generating this 1MB string megastring = 100*'a' # t 1 sec on my machine (other than keep appending to a string until it reaches 1MB len)? You mean like (unexecuted) s = '' for i in xrange(100): s += 'a' #? This will allocate, copy, and deallocate 100 successively longer temporary strings and is a noticeable O(n**2) operation. Since strings are immutable, you cannot 'append' to them the way you can to lists. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
Thomas Bartkus napisał(a): Paul Rubin http://[EMAIL PROTECTED] wrote in message I would take MS Excel/VBA as the premier fat client prototyping tool/GUI toolkit for science education. How would one go about replicating any of that in an HTML/browser app? How do we get to easier to write? As I said, I'm looking for multiplatform solution. So, I will go with Python, Tk and C++ (for algorithm and critical parts of applications). Tk is simple, very simple, Python I like, C++ I love, as I'm professional C++ programmer. Students and profs will use Python with Tk mainly. I will convert some of libraries with algorithms they will prototype in python (and exsiting in Pascal) to C/C++ and bind them with Python. There is also C++/Tk by Maciej Sobczak, great tool. Cheers -- Mateusz Łoskot, mateusz (at) loskot (dot) net Registered Linux User #220771 -- http://mail.python.org/mailman/listinfo/python-list
Re: Moinmoin config
Mark wrote: Hi, I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, all screen elements are lined up on the left hand side. How can I get it displayed like the wiki at: Well, this is probably a better question for the moin lists but I have seen this behavior before. I would check the data_underlay_dir = './underlay/' line in your wikiconfig.py file. If it's not getting the right templates it won't format the page right. This is the only advice I can give. Beyond this I don't know what else you can try. http://moinmoin.wikiwikiweb.de/HelpOnConfiguration instead of this ? - LANShieldOS Release Notes Search: * MarkRuedy * UserPreferences * HelpOnEditing * HelpContents * HelpForBeginners * UserPreferences * FrontPage * RecentChanges * FindPage * HelpContents * Edit * Show Changes * Get Info * Subscribe * FrontPage -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tookit for science and education
As I said, I'm looking for multiplatform solution. So, I will go with Python, Tk and C++ (for algorithm and critical parts of applications). Tk is simple, very simple, Python I like, C++ I love, as I'm professional C++ programmer. Good choice! -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists of list
Mohammed Altaj wrote: Hi All I am having problem with delete line if its belong to another one , example I think, you mean to remove all lines that are substrings of another line. l = ['0132442\n', '13\n', '24\n'] l = [e.strip() for e in l] i = 0 while True: try: for j in range(len(l)): if i == j: continue if l[j].find(l[i]) = 0: # line 'j' is superstring of line 'i' del l[i] break else: # doesn't have superstring i += 1 except IndexError: break Basically, I try all n*n combinations, and remove substring lines in-place. BranoZ -- http://mail.python.org/mailman/listinfo/python-list
List of strings
Hi All Thanks for your reply , what i am doing is , i am reading from file , using readlines() , I would like to check in these lines , if there is line belong to another one or not , if it is , then i would like to delete it ['0132442\n', '13\n', '24\n'] '13' is already in '0132442' '24' is already in '0132442' Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Moinmoin config
Hi Patrick, Sorry about the cross post, but I could not find a moin list. Do you have a sub folder or a better name? I searched for moin and for wiki but only found some actual wikis and some groups with only a few members. Anyway, I checked my data_underlay_dir and it is valid and contains one subdir, called pages, which has a huge set of subdirs. Do you know where else I can turn? Thanks Mark -- http://mail.python.org/mailman/listinfo/python-list