Avaliable free modules
Hi group, Is there any site like cpan.org for python? Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
modpython, apache and windows
Hi All, I am interested in learning python since I am hearing more and more about python for use in web development I am starting out on python, with knowledge of PHP some perl my current hurdle is setting up either apache 1 or 2 with python 2.3.3 I have installed modpython fine which informed me that I need to make some configuration changes to httpd.conf I have not had it working yet, searches on the web give conflicting suggestions and so far has confused me some forums mention spyce and serving .spy files so far I one explanation worked in that a .py file was parsed but I had to set the name of the actual file within apache.conf this seems strange thanks in advance >> SS -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: 30/12/2004 -- http://mail.python.org/mailman/listinfo/python-list
Powerful CGI libraries for Python?
Hi, I m looking for a CGI libraries just like perl's CGI.pm for Python. From google, I found quite a few of CGI libraries already written for python. But I haven't had experience to try any of them in Python. Can anyone share your Python CGI experience with me? Which library is better in terms of functionality and stability? Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
Excel module for Python
Hi group, I m wondering which Excel module is good to be used by Python? Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: Excel module for Python
Simon Brunning wrote: On Wed, 12 Jan 2005 15:18:09 +0800, sam <[EMAIL PROTECTED]> wrote: I m wondering which Excel module is good to be used by Python? If you are on Windows, and you have Excel, then the Python for Windows extensions[1] are all you need to drive Excel via COM. O'Reilly's "Python Programming on Win32" covers COM scripting extensively - and by good fortune, driving Excel is the example they use, and the COM scripting chapter is on-line[2]. You'll also need to know the objects and methods that Excel exposes. These are documented on Microsoft's web site[3], or in the Excel VBA help, which is an optional part of they Office installation. No, I don't use MS windows. I need to generate Excel file by printing data to it, just like Perl module Spreadsheet::WriteExcel. thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
compile python to binary
Hi, I have seen some software written in python and delivered as binary form. How does these binary code get generated by python compiler? Thanks Sam. -- http://mail.python.org/mailman/listinfo/python-list
Re: compile python to binary
Fredrik Lundh wrote: Daniel Bickett wrote: I believe Sam was talking about "frozen" python scripts using tools such as py2exe: oh, you mean that "python compiler" didn't mean "the python compiler". here are links to some more tools, btw: http://effbot.org/zone/python-compile.htm Thanks for the link. It is what I exactly looking for. Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: compile python to binary
Peter Hansen wrote: Daniel Bickett wrote: Fredrik Lundh wrote: oh, you mean that "python compiler" didn't mean "the python compiler". [snip] I simply inferred that he was using the wrong terminology, being that he said "binary" twice ;-) While I suspect you've guessed correctly at what the OP meant, one should also consider that the word "binary" can be quite ambiguous in the hands of a newbie. After all, source code is stored in binary too... Sorry for the vagues terms. I meant compile a python script into a binary program. Thanks Sam -Peter -- http://mail.python.org/mailman/listinfo/python-list
python module in webmin
Hi, Had anyone written any python module for webmin? Since webmin is written in perl, but I want to write a python app/module used by webmin. If you know the detail of writing a python module for use in perl webmin, please drop me some guideline. Perhaps It is better off to find/write a python version of webmin first. Thanks Sam. -- http://mail.python.org/mailman/listinfo/python-list
create/access dynamic growth list
Hi, I have a configuration file need to be processed (read/write) by python. Currently I the following method can only read and store data that python read a line from a configuraiton file: def _parse (self): # parse message m = self.FWShow_Command.match (conf_data) if (m == None): raise FW_Command.Error ("corrupt macro definition") # store generic data macro = {} macro["key"] = m.group (1) macro["value"] = m.group (2) return (conf_data, macro) Since there are unknown number of lines in a configuration file, I want to store the array of "macro" in a list. How can I do that in Python? Thanks Sam. -- http://mail.python.org/mailman/listinfo/python-list
syntax incorrect with regex
Hi, What is the correct syntax of declaring a regex syntax in Python 2.3? I got the following error: # python2.3 test.py File "test.py", line 10 macros_parser = re.compile (r""" (\s+)=\"(\s+)\"$ """,re.VERBOS) ^ SyntaxError: invalid syntax Thanks sam -- http://mail.python.org/mailman/listinfo/python-list
Re: create/access dynamic growth list
Larry Bates wrote: sam wrote: Hi, I have a configuration file need to be processed (read/write) by python. Currently I the following method can only read and store data that python read a line from a configuraiton file: def _parse (self): # parse message m = self.FWShow_Command.match (conf_data) if (m == None): raise FW_Command.Error ("corrupt macro definition") # store generic data macro = {} macro["key"] = m.group (1) macro["value"] = m.group (2) return (conf_data, macro) Since there are unknown number of lines in a configuration file, I want to store the array of "macro" in a list. How can I do that in Python? Thanks Sam. Pretty sketchy description, but I'll take a shot. fp=open(conf_data, 'r') macro_lines=fp.readlines() fp.close() After this macro_lines will be a list with one line per element such that macro_list[0] is the first line, macro_list[1] the second, etc. Thanks for the suggestion. Since each line of the configuration file need to be parsed into "key" and "value" pairs, these pair of tokens need to be stored in another list. Can I use the following operation to store these pair of tokens? eg. Assumed macro_hash["key"]="some key" macro_hash["value"]="some value" then build a list that contains a list of macro_hash: macro_list.append(macro) when treverse the macro_list, it would be similar to perl: foreach macro (in macro_list) key = macro["key"] value = macro["value"] Sam. Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
inline comparison
Hi, I got the the following syntax error in comparison: File "/usr/local/work/myparser.py", line 85 if ( (m=self.macro_parser.match (d)) != None ): ^ SyntaxError: invalid syntax How can I get around wtih this? I don't want to break down this comparison in two steps. Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
what is \s+ and \S+ means in re.compile?
Hi, I was confused by \s+ and \S+ in python. The second one (\S+) is stand for matching all alphabets except for digit and space? How about the first one? Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: inline comparison
Tim Roberts wrote: sam <[EMAIL PROTECTED]> wrote: Hi, I got the the following syntax error in comparison: File "/usr/local/work/myparser.py", line 85 if ( (m=self.macro_parser.match (d)) != None ): ^ SyntaxError: invalid syntax How can I get around wtih this? I don't want to break down this comparison in two steps. Sorry, you have to. Assignment statements are not expressions in Python. m = self.macro_parser.match(d) if m: xxx This is very bad to me, I will need to write some cumbersome syntax as follow: for d in self.data: m = self.macro_parser.match (d)) != None ): if (m == None): m_nat = self.a_parser.match (d) if (m_a == None): m_rdr = self.b_parser.match (d) if (m_b == None): m_c = self.c_parser.match (d) if (m_c == None): m_d = self.d_parser.match (d) if (m_d == None): m_e = self.e_parser.match (d) if (m_e == None): . You know the outer parentheses are not necessary, right? -- http://mail.python.org/mailman/listinfo/python-list
Re: inline comparison
Diez B. Roggisch wrote: If you really need that sort of dependent matching, there are better ways to accomplish that in python: for m, name in [self.macro_parser, self.a_parser, self.b_parser, ...]: mo = m.match(data) if mo: break Hi, this method looks more elegant. However I got the following error: for m, name in [self.macro_parser] ^ SyntaxError: invalid syntax What is the valid syntax with this usage? Thanks Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: [Info] PEP 308 accepted - new conditional expressions
Leif K-Brooks writes: Sam wrote: And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators. What _isn't_ Perl-ish? BASIC? pgp7WNg5zZz7a.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Setting optimum gtkhtml2 widget size.
I'm putting gtkhtml2.View() inside a gtk.ScrolledWindow, which goes into a gtk.Dialog.vbox. How do I obtain gtkhtml2.View's preferred height, and set the dialog's height accordingly, given a specific width? I can do a gtk.Dialog.set_default_size() up front, specifying the width and height large enough for everything, then create all the widgets, and realize them. But then, even after I realize everything I can't get any useful metrics from gtkhtml2.View(). None of the usual suspects -- get_size_request, get_allocation -- give anything useful. I also tried not using a ScrolledWindow, but adding gtkhtml2 as gtk.Dialog.vbox's child. pgp8liVmGWclS.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Python eats gator.
http://www.wnbc.com/family/5060215/detail.html I know there's an on-topic joke in here somewhere, but I'm having some problem finding it, at the moment. You may take a crack at it, if you'd like… pgpWkRit76A0o.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: C/API Clarification
Jeremy Moles writes: in the world I got the idea from! According to the docs, METH_VARARGS is (PyObject*, PyObject*)? Right. My prototype shouldn't even compile... but it Why wouldn't it compile? 2. No where in the docs does it show how to "correctly" create an instance of your custom PyTypeObject in C (rather than in the interpreter). I'm using: That's what tp_alloc is for. Then you call tp_init to initialize it. But, your tp_new handler should already invoke tp_alloc, so it's cleaner to call tp_new, followed by tp_init. 3. I'm not able to return the "self" argument (useful, for instance, when you want to chain a group of method calls) without screwing things up really, really bad. For example: PyObject* somefunc(cstruct* self, PyObject* args, PyObject* kargs) { self->pointerToData->doSomeStuff(); return (PyObject*)(self); } ...returns "something"; it has the methods you would expect, but trying to use the object when it gets back to the interpreter is pretty much undefined behavior. :) It's seen as a "" instance in the interpreter, even though a dir() shows it still has the methods you would expect. You need to increment the reference count of the object, in this case. pgpU4yWTepvmr.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Daisy Daisy, give me your answer do
Xah Lee writes: Dear Michael Goettsche, why don't you lead the pack to be on-topic for a change, huh? Why don't you: 1. Learn how to properly format messages for posting to Usenet, so that your scribblings don't read like stream-of-consciousness babbling (see http://en.wikipedia.org/wiki/Top-posting). 2. Explain why such an important and famous ubergeek like yourself (judging by your web site) has to beg others to write code for him. 3. Make sure the door handle doesn't hit your ass on the way out. pgpPbnLZqTCxN.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Wanted: Python module allowing direct access to raw sectors ofharddrives (MFT, boot sector, etc.) in MS Windows
The following site contains my routines to access information from the Microsoft SCSIPASSTHROUGH layer under windows. These routines allow you to access the storage devices mounted under windows using SCSI commands. The dll that I provide will work with Python 2.3 http://starship.python.net/crew/samschul/ Sam Schulenburg Claudio Grondi wrote: > Thank you Jeff very much for your quick reply. > It saved me really much time of digging in the wrong direction. > > <[EMAIL PROTECTED]> wrote in > news:<[EMAIL PROTECTED]>... > >> I took the advice from this web page: > >> http://support.microsoft.com/kb/q100027/ > Ok, I had found this page myself during Googling, but I have missed just > to try to use the described way of addressing physical devices with file > opening in Python. > It works as expected with harddrives so you are right that you are getting > the MBR with the proposed code. > > After some not always happy end adventures with Python > scripting I am impressed by the power of the concept behind > the language once again. > > Claudio > > >>(I don't know how this extends to floppies, and the 9x family of OSes > isn't > >>listed in "applies to", so this may not help your case) > >>Here, I open "physical drive 0" and see that the magic number indicates a > valid > >>boot record. I believe it is the MBR. > >>>>> f = open('.\\PhysicalDrive0', 'rb') > >>>>> f.read(512)[-2:] > >>'U\xaa' # that is, hex 55 AA > >>I don't know much about low-level filesystem or partition details--I got > the > >>tidbit about the 55 AA magic number from > >>http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/sles9/adminguide-sles9/ch08.ht > ml > >>Jeff > >><[EMAIL PROTECTED]> schrieb im Newsbeitrag > news:[EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Wanted: Python module allowing direct access to raw sectors ofharddrives (MFT, boot sector, etc.) in MS Windows
The main use of my SCSI routines,is that by using the SCSIPASSTHROUGH layer under Windows gives the user absolute control of the storage device. For example copying data from and IDE drive to a SCSI drive becomes transparent using SCSI commands. I.e Logical block 0 remains consistant. I had an PHD clam that using fopen(),and fread(),along with fwrite() with an offset of 0 would always get you sector zero,head zero on a drive. I was able to prove that this was not the case. When using the SCSIPASSTHROUGH layer LBA 0 will always return the first user accessable sector. Using Python open() behaves the same as the C functions,thus you would have the same problem. -- http://mail.python.org/mailman/listinfo/python-list
Re: access to preallocated block of memory?
I had a simular situation when I was writing Python routines to access the the storage (SCSIPASSTHROUGH) layer provided by Windows XP. My solution was to develope an extention in C that allocated all storage buffers within the extension. Then I added access extensions to controll reading and writing to and from these buffers. I would guess that you can write a vxworks extension that provides this linkage. Bengt Richter wrote: > On 14 Dec 2005 14:30:34 -0800, "Greg Copeland" <[EMAIL PROTECTED]> wrote: > > >I am running python on VxWorks. In the course of operation, a vxworks > >tasks writes to a reserved area of memory. I need access to this chunk > >of memory from within python. Initially I thought I could simply > >access it as a string but a string would reallocate and copy this chunk > >of memory; which is not something I can have as it would waste a huge > >amount of memory. We're talking about something like 40MB on a device > >with limited RAM. I have been looking at array. It looks promising. > >What's the best route to go here? Ideally, I would like to simply pass > >in the address of the reserved block and a length, and have the memory > >accessible. > > > >Is there some existing python object/facility I can use or will I need > >to create a custom module? Any tips, hints, or pointers would > >certainly be appreciated! > > What have you gathered from people who have gone before? googling python > vxworks > gives about 50k hits ;-) > > Your post does not have enough info about your environment, but for > the sake of eliciting same, suppose you had a custom extension module > written in C that would give you the access to the "reserved area of memory" > that you want. So e.g. from the point of view of your python program, it looks > like a module you can import, e.g., > > import vxreservedmem > > Ok, how does the module know where the "reserved area" is? Would you link > the C to some vx library interface to establish location and size? Or? > Is there already a python interface to provide some access? > Can there be more than one instance, so the module should be able to > give you multiple objects that you can use to access different areas? > > Once you have an access-providing object, what kind of access do you require? > What is represented within the "memory area" besides an array of bytes? Do the > bytes represent C structs and primitive types? Are there access locks that > determine when it's safe to touch the bytes? A single lock for the whole area, > or individual locks for structs/subregions within the whole? Do you just need > read access or do you want to store info? How would you like to select > chunks of info? Just slices of byte arrays, or are there meaningful arrays > of numbers -- integer, floats, etc. or bit fields etc? > > You could define a pure python vxresrvedmem module that just simulates the > real > thing, to test ideas -- and to communicate more clearly to us what the > problem is. > > What modules/libraries do you have to give you access now from python to the > vxworks > environment? A file system? /dev/magic_stuff? or /proc/magic_stuff or ? > > > Regards, > Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
UpDate For SCSIPython Storage device test library
I have updated my page at http://starship.python.net/crew/samschul/ These tools allow for the user to issue low level SCSI commands via the windows SCSIPASSTHROUGH interface layer. These routines will work from IDLE, Pythonwin,and Python.exe. The changes include the following: 1) Deleted documentation references to ASPY interface as it is not used very much anymore. 2) Compiled SCSIPy.dll for Python 2.3 and Python 2.4 see SCSITOOLS23USBUpdate.zip,and SCSITOOLS24USBUpdate.zip 4) Made many changes to documentation -- http://mail.python.org/mailman/listinfo/python-list
Re: UpDate For SCSIPython Storage device test library
Just a added note,that these routines will access any storage drive that is mounted under Windows. The Scsi Pass Through layer maps all Pcmcia,IDE,andSCSI drives to use SCSI commands. This allows a user to access all these interfaces with a common command set. Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: UpDate For SCSIPython Storage device test library
I found a bug in the GetLastError() call I was making after all calls to DeviceIOControl() when accessing the devices mounted by Windows. This has been corrected and posted to http://starship.python.net/crew/samschul/ These changes have been made to SCSITOOLS23USBVer1.4.zip, and SCSITOOLS24USBV1.4.zip Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft IronPython?
After downloading and trying out Ironpython, I have the following comments: 1) I like the idea of Python under .net 2) I like the support for both Microsoft math lib,and Python's math lib Will Microsoft maintain the compatability between standard python with the addition of their libs? -- http://mail.python.org/mailman/listinfo/python-list
Building Pywin32 source code?
Has anyone been able to access the source code for Pywin32 at sourceforge? I have been able to use TortouseCVS to access other CVS projects,but with the Pywin32 cvs site, I can not log in. Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: Building Pywin32 source code?
Trent: Thanks for the reply. I tried again today and everthing worked. I did find a type in my CVSROOT string,and corrected it. Thanks for the examples posted in the included link. Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyserial never read
luca72 wrote: > Thanks to all for the help, > > here you find the code, pls note if i use handshaking = 1 the > application don't start. > in the delphi configuratio of com port if i use or not handshaking the > application work. > Best Regards at all > > Luca > > import serial > import win32file > port = 2 Is port = 2 correct? I thought that com ports under windows are designated as a string "com1","com2",..etc. > baudrate = 38400 > bytesize =serial.EIGHTBITS > parity =serial.PARITY_ODD > stopbits =serial.STOPBITS_TWO > timeout = 1 > ser = serial.Serial(2, baudrate=38400, bytesize=8, > parity=serial.PARITY_ODD, stopbits=2, timeout=3) > ct = '' > ch = '' > a = self.textCtrl1.GetValue() > ind = 0 > ind1 = 2 > lunghezza = len(a) > while ind < lunghezza : > b = a[ind:ind1] > b = int(b,16) > b = ~b > c = ''.join([str((b >> Digit) & 1) for Digit in range(7, > -1, -1)]) > c1 = c[0:4] > c2 = c[4:] > c1 = c1[3:] + c1[2:3] + c1[1:2] + c1[0:1] > c2 = c2[3:] + c2[2:3] + c2[1:2] + c2[0:1] > c1 = hex(int(c1,2)) > c2 = hex(int(c2,2)) > c1 = c1[2:] > c2 = c2[2:] > c = c2+c1 > ct = ct + c > ind = ind + 2 > ind1 = ind1 + 2 > c = int(c,16) > c = chr(c) > ch = ch + c > > > ser.write(ch) > > elf.textCtrl2.SetValue(ct) > ser.readline() You might want to try using ser.read() instead of ser.readline() as you may not be getting linefeed carrage return characters . I usually setup a buffer to scan for the characters I expect. > > > > Pls.Note i hove also try with read(number of byte ) with inWaiting(), > flush etc > > > But no result. > > Thanks Luca Hope this helps Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyserial never read
Thanks for the info Grant. It'll teach me not to read the documentation :>) Sam -- http://mail.python.org/mailman/listinfo/python-list
Threading, real or simulated?
I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading approach from pygtk's FAQ 20.6 - invoking "gtk.gdk.threads_init()", and wrapping all gtk/gdk function calls with gtk.threads_enter()/gtk.threads_leave() I start a thread, via thread.Threading.start(). The thread then calls a particularly time consuming C function, from an extension module. I find that when the thread is running the C code, the GUI hangs even though I'm not inside the threads_enter/threads_leave territory. It looks like thread.Threading() only simulates threading, by having the python interpreter multiplex between running threads. Is real threading possible, so that I do something time-consuming in the thread, without hanging the GUI? pgp2z4y14Omjn.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading, real or simulated?
Jp Calderone writes: On Wed, 21 Sep 2005 18:23:33 -0500, Sam <[EMAIL PROTECTED]> wrote: I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading approach from pygtk's FAQ 20.6 - invoking "gtk.gdk.threads_init()", and wrapping all gtk/gdk function calls with gtk.threads_enter()/gtk.threads_leave() I start a thread, via thread.Threading.start(). The thread then calls a particularly time consuming C function, from an extension module. I find that when the thread is running the C code, the GUI hangs even though I'm not inside the threads_enter/threads_leave territory. Does the extension module release the GIL? It sounds like it does not. Of course, there are a dozen other mistakes that could be made which would have roughly this symptom. It's difficult to say which is the problem without actually seeing any code. What's the GIL?. The extension module is invoked outside of threads_enter/threads_leave(). It looks like thread.Threading() only simulates threading, by having the python interpreter multiplex between running threads. Is real threading possible, so that I do something time-consuming in the thread, without hanging the GUI? Assuming you mean threading.Thread, this is a native thread. It is not a simulation. Something else is going wrong. Then I must have something locked. Here's what I do: gtk.gdk.threads_init() mainwindow=MainWindow() gtk.threads_enter() gtk.main() gtk.threads_leave() The code in MainWindow.__init__() does this: self.__window=gtk.Window(gtk.WINDOW_TOPLEVEL) self.__window.set_default_size(600, 600) [ some more initialization ] self.__window.show_all() self.__window.connect("delete-event", self.delete_event) self.__window.connect("destroy", self.destroy) t=self.initializationThread() t.packageLayout=packageLayout t.start() Here's the definition of my initializationThread class: class initializationThread(threading.Thread): def run(self): gtk.threads_enter() busy_cursor=gtk.gdk.Cursor(gtk.gdk.WATCH) self.packageLayout.window.set_cursor(busy_cursor) gtk.threads_leave() I do get a busy cursor at this point, so I know that this thread is running. initializationThread.run() continues, as follows: try: sysrep=lpm.getSystemRepository() pkgs=sysrep.getPackages() pkgs.sort() for i in pkgs: icon=sysrep.getManifest(i).header("Icon") gtk.threads_enter() try: if self.packageLayout.window == None: break # Someone was impatient self.packageLayout.addPackage(i, icon) finally: gtk.threads_leave() lpm.getSystemRepository() instantiates an object of an extension-defined type. It's getPackages() method returns a list of objects that are also of an extension-defined type, which I then iterate over. Each iteration invokes the getManifest() method of an extension-defined type. All the stuff between gtk.threads_enter() and gtk.threads_leave() runs pure python code, and should be nearly instantaneous. Furthermore, gtk functions that end up being invoked in the addPackage() method, provide some GUI feedback. Each addPackage() iteration adds a new widget in the main window. Occasionally, there's a noticeable delay, before a new widget appears, because there's a lot on getManifest()'s plate. I get no response from any GUI activity, during the delay. getManifest() gets invoked outside the threads_enter/threads_leave lock, but the GUI is still hanging when that happens. pgp1CNTdr48aH.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading, real or simulated?
Antoon Pardon writes: Assuming you mean threading.Thread, this is a native thread. It is not a simulation. Something else is going wrong. Then I must have something locked. Here's what I do: Yes you have locked the GIL. Take a look at the following URL: http://docs.python.org/api/threads.html, hope it helps. Yes, thank you. That was it. Since I was creating threads, and messing with them, in pure Python with threading.Thread, I never had an opportunity to read this part of the API spec. pgphmv1znQGt9.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: [Info] PEP 308 accepted - new conditional expressions
Reinhold Birkenfeld writes: Hi, after Guido's pronouncement yesterday, in one of the next versions of Python there will be a conditional expression with the following syntax: X if C else Y which is the same as today's (Y, X)[bool(C)] What's wrong with "C ? X:Y"? Aside from ":" being overloaded? pgpZksJ3aZt0b.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: [Info] PEP 308 accepted - new conditional expressions
Jaime Wyant writes: On 9/30/05, Sam <[EMAIL PROTECTED]> wrote: Reinhold Birkenfeld writes: > Hi, > > after Guido's pronouncement yesterday, in one of the next versions of Python > there will be a conditional expression with the following syntax: > > X if C else Y > > which is the same as today's > > (Y, X)[bool(C)] What's wrong with "C ? X:Y"? Aside from ":" being overloaded? First thing that comes to my mind is that it is more C-ish (read cryptic) than pythonic (read elegant and understandable). And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators. pgp2YIfNenxUE.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
The use of PyW32_BEGIN_ALLOW_THREADS and PyW32_END_ALLOW_THREADS
The foowing code lifted from Mark Hammond Pywin32 code shows and example of calling the Windows Kernel32 GetTickCount(),using PyW32_BEGIN_ALLOW_THREADS and PYW32_END_ALLOW_THREADS. My Code does not use this,but uses SetThreadAffinityMask(GetCurrentThread(),1). My questions are: 1) What is the difference? 2) What happens after I leave my function, to the previous threads that I may have had running? 3) Should I be using the BEGIN/END ALLOW_THREADS? / @pymethod string|win32api|GetTickCount|Returns the number of milliseconds since windows started. static PyObject * PyGetTickCount(PyObject * self, PyObject * args) { if (!PyArg_ParseTuple (args, ":PyGetTickCount")) return NULL; PyW32_BEGIN_ALLOW_THREADS DWORD count = GetTickCount(); PyW32_END_ALLOW_THREADS return Py_BuildValue("l",(long)count); } Now my code uses the Microsoft "SetThreadAffinityMask(GetCurrentThread(),1)" // // PROGRAMMER: Samuel W. Schulenburg // DATE:May 18,2006 // // FUNCTION:double dMyClock() // // DESCRIPTION: This function will return the seconds since the system was started // as a double. If a call to QueryPerformanceFrequency() returns a true // then QueryPerformanceCounter() will be used else the standard 'C' // dMyClock() function will be used. // // PARAMETERS: None // // RETURN: double The seconds passed sense the system was started // double dMyClock() { double dLow; double dHigh; if(iPerformanceClocks == 1) // if the hardware supports the high performance clock { SetThreadAffinityMask(GetCurrentThread(),1); QueryPerformanceCounter(&liPerformanceCount); dLow = (double)liPerformanceCount.LowPart; dHigh = (double)(liPerformanceCount.HighPart)*(4294967296.0); return((dLow+dHigh)/dTicksPerSecond); } else // use the standard C clock function return((double) (clock()/dTicksPerSecond)); } -- http://mail.python.org/mailman/listinfo/python-list
Re: IronPython 1.0 Beta 7 Released
vbgunz: When you download IronPython,the tutorial directory has some examples of interfacing With the .NET environment i.e.: 1: IronPython -> C# 2: C# -> IronPython 3: IronPython -> VB 4: VB -> IronPython Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you practice Python?
Years ago I developed a Hard Disk Drive diagnostic program "SCSIPython" while working for a disk drive company. When I left that company,and realized that these routines would never be used by the company, I released it as Open Source. Since then I have maintained this code, and enhanced it with the various versions of Python that have been released after V1.5. I find that with each update my code becomes more robust,with added features. Also As I moved from company to company I made certain that they knew that this code was Open Source,and only proprietary methods will be excluded, when I signed the standard intellectual property forms. Sam Schulenburg Jarek Zgoda wrote: > [EMAIL PROTECTED] napisa³(a): > > >>In our field, we don't always get to program in the language we'd like > >>to program. So... how do you practice Python in this case? > > > > Write code. Lots of it. Work on a project at home, contribute to > > something open source, use it to write support scripts at work, > > whatever. Figure out a way to write code. > > I second that. I moved from Python to J2EE in my job, but I didn't stop > writing Python code for my spare-time projects. Now, when tight schedule > made my project's manager to shift paradigm from buzz to productivity, I > am happy I can write programs in Python again. On AS/400, but still > better than Java... :D > > -- > Jarek Zgoda > http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Seg fault in python extension module
I recommend that you also replace the NULL after the METH_VARARGS with a valid documentations string such as: static PyMethodDef modglMethods[] = { { (char *)"glVertex4f", _wrap_glVertex4f, METH_VARARGS, "My Doc String"}, { NULL, NULL, 0, NULL } }; Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: Seg fault in python extension module
Sorry, From MethodObject.h the 4th parameter is usually documented as having a NULL, but is intended to be used for a documentation string that will be available to the user under the various GUI IDE's such as IDLE or PyWin32. I just wanted to point that out.. struct PyMethodDef { const char *ml_name; /* The name of the built-in function/method */ PyCFunction ml_meth; /* The C function that implements it */ int ml_flags; /* Combination of METH_xxx flags, which mostly describe the args expected by the C func */ const char *ml_doc;/* The __doc__ attribute, or NULL */ }; Sam Schulenburg John Machin wrote: > On 3/06/2006 1:38 PM, sam wrote: > > I recommend that you also replace the NULL after the METH_VARARGS with > > a valid documentations string such as: > > > > static PyMethodDef modglMethods[] = > >{ > > { (char *)"glVertex4f", _wrap_glVertex4f, METH_VARARGS, "My > > Doc String"}, > > { NULL, NULL, 0, NULL } > > > > }; > > > > Lack of one is unlikely to have anything to do with the OP's segfault. > > |>>> repr(modgl.glVertex4f.__doc__) > 'None' > |>>> > > As to style, etiquette, and good citizenship in module extension > writing, it might be better to give him some references, rather than > mention just one point. > > Cheers, > John -- http://mail.python.org/mailman/listinfo/python-list
Re: carshing the interpreter in two lines
tomer: It is my opinion that you would loose performance if the Python interpreter had the additional task of verifying byte code. It might be more appropriate to have a preprocessor that did the verifying as it compiled the byte code. Sam Schulenburg gangesmaster wrote: > the following (random) code crashes my interpreter > (python 2.4.3/winxp): > > from types import CodeType as code > exec code(0, 5, 8, 0, "hello moshe", (), (), (), "", "", 0, "") > > i would expect the interpreter to do some verifying, at least for > sanity (valid opcodes, correct stack size, etc.) before executing > artbitrary code... after all, it was the BDFL who said """I'm not > saying it's uncrashable. I'm saying that if you crash it, it's a > bug unless proven harebrained.""" > > > -tomer -- http://mail.python.org/mailman/listinfo/python-list
Re: carshing the interpreter in two lines
Mel: Wow that book brings back memories. I scanned my copy to review the subject covered, and came to the conclusion that mind reading algorithms are the answer. Sam Schulenburg Mel Wilson wrote: > sam wrote: > > tomer: > > > > It is my opinion that you would loose performance if the Python > > interpreter had the additional task of verifying byte code. It might be > > more appropriate to have a preprocessor that did the verifying as it > > compiled the byte code. > > Possibly. A good book on the topic is Douglas Hofstadter's > _Goedel, Escher, Bach: an Eternal Golden Braid_. > > Particularly starting from the chapter "Contracrostipunctus". > > Cheers,Mel. > > > > > Sam Schulenburg > > > > gangesmaster wrote: > >> the following (random) code crashes my interpreter > >> (python 2.4.3/winxp): > >> > >> from types import CodeType as code > >> exec code(0, 5, 8, 0, "hello moshe", (), (), (), "", "", 0, "") > >> > >> i would expect the interpreter to do some verifying, at least for > >> sanity (valid opcodes, correct stack size, etc.) before executing > >> artbitrary code... after all, it was the BDFL who said """I'm not > >> saying it's uncrashable. I'm saying that if you crash it, it's a > >> bug unless proven harebrained.""" > >> > >> > >> -tomer > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Very nice python IDE (windows only)
Very interesting, I have downloaded it,and I like what I see. ago wrote: > I have just discovered Python Scripter by Kiriakos Vlahos and it was a > pleasant surprise. I thought that it deserved to be signalled. It is > slim and fairly fast, with embedded graphical debugger, class browser, > file browser... If you are into graphical IDEs you are probably going > to enjoy it. Windows only unfortunately. > > http://mmm-experts.com/Products.aspx?ProductId=4 -- http://mail.python.org/mailman/listinfo/python-list
The old round off problem?
Hello all, I am taking a class in scientific programming at the local college. My problem is that the following difference produces round off errors as the value of x increases. For x >= 19 the diference goes to zero.I understand the problem, but am curious as to whether their exists a solution. I have tried various graphing programs,and they all exihibit this problem. thanks in advance Sam Schulenburg f(x) = cosh^2(x) - sinh^2(x) = 1 >>> from math import * >>> for x in range(20): print "x= %2d Sinh^2(x) = %20.3f f(x) = %2.10f "%(x,pow(cosh(x),2),pow(cosh(x),2)- pow(sinh(x),2)) x= 0 Sinh^2(x) =1.000 f(x) = 1.00 x= 1 Sinh^2(x) =2.381 f(x) = 1.00 x= 2 Sinh^2(x) = 14.154 f(x) = 1.00 x= 3 Sinh^2(x) = 101.358 f(x) = 1.00 x= 4 Sinh^2(x) = 745.740 f(x) = 1.00 x= 5 Sinh^2(x) = 5507.116 f(x) = 1.00 x= 6 Sinh^2(x) =40689.198 f(x) = 1.00 x= 7 Sinh^2(x) = 300651.571 f(x) = 0.99 x= 8 Sinh^2(x) = 2221528.130 f(x) = 1.00 x= 9 Sinh^2(x) = 16414992.784 f(x) = 1.37 x= 10 Sinh^2(x) =121291299.352 f(x) = 1.000298 x= 11 Sinh^2(x) =896228212.033 f(x) = 0.998808 x= 12 Sinh^2(x) = 6622280532.961 f(x) = 1.019073 x= 13 Sinh^2(x) = 48932402357.710 f(x) = 0.923706 x= 14 Sinh^2(x) = 361564266073.369 f(x) = 0.389648 x= 15 Sinh^2(x) =2671618645381.616 f(x) = 1.00 x= 16 Sinh^2(x) = 19740740045670.668 f(x) = 0.9921875000 x= 17 Sinh^2(x) = 145865435631864.219 f(x) = 1.00 x= 18 Sinh^2(x) = 1077807886778799.250 f(x) = 1.00 x= 19 Sinh^2(x) = 7963982939278438.000 f(x) = 0.00 >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: The old round off problem?
David I beg I beg Can you answer the question? Also thanks for the information on using the Taylor series. Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
Re: The old round off problem?
David Treadwell wrote: > exp(x) is implemented by: > > 1. reducing x into the range |r| <= 0.5 * ln(2), such that x = k * > ln(2) + r > 2. approximating exp(r) with a fifth-order polynomial, > 3. re-scaling by multiplying by 2^k: exp(x) = 2^k * exp(r) > > sinh(x) is mathematically ( exp(x) - exp(-x) )/2 but it's not > calculated directly that way. > > My brain hurts at this point; it's late. I'll have another go at > hunting down the errors tomorrow. In the interim, does anybody out > there already know the answer? > > :--David I tried the exp(x) equivalent of sinh(x) and cosh(x) with the same results. I think I will write my own or steal the Taylor(f(x),x,n) function in both C++, and python. -- http://mail.python.org/mailman/listinfo/python-list
Re: "pow" (power) function
I not shure which algorithm,but I am assumeing that all Python does,is to call the underlying C pow() function. Sam -- http://mail.python.org/mailman/listinfo/python-list
ANN: SCSIPYTHON on Sourceforge
I have updated and moved my SCSI diagnostic tools from starship to sourceforge. I will be still maintaining these files at both locations as long as starship exists. These tools allow low level tests to be conducted on storage devices under the Windows operating system. These routines access all storage devices through the Windows SCSIPASSTHROUGH layer, which maps all storage devices (SCSI,IDE/ATA,USB,PCMCIA,DVD,CD) to look like a SCSI device that is accessed using SCSI command descripter blocks. The move to Sourceforge also places the sourcecode,and files under CVS control. Starship link: http://starship.python.net/crew/samschul Sourceforge link: https://sourceforge.net/projects/scsipython Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
returning None instead of value: how to fix?
i am starting to experiment with recursion, and decided to write a fairly trivial little program which took a float as input, then called a function to halve it recursively until it was less than 1: import recursive_halve_module raw_value = raw_input('please enter the number you would like to halve: ') value = float(raw_value) final_value = recursive_halve_module.recursive_halve(value) print final_value raw_input('hit enter to close: ') _ def recursive_halve(value): if value < 1: print value return value else: value = value/2 print value if value < 1: return value else: recursive_halve(value) __ it works fine apart from printing 'None' instead of 'final_value' at the end. however, if you enter a value that is already less than 1, it prints 'final_value' (i.e. that very same number) just fine. now, it looks to me like only 'value' can be returned: either right at the beginning (for values less than 1) or when you eventually get down to below 1 after x function calls. but clearly that's not the case. i understand that 'None' is returned by default by functions in Python. my question is: how am i slipping into that default despite seemingly (to me at least) avoiding it through explicitly returning something else? thanks in advance, sam -- http://mail.python.org/mailman/listinfo/python-list
Re: returning None instead of value: how to fix?
> Missing a return on the last line is likely your immediate problem. thanks to everyone for pointing this out. obviously, i had not understood what was actually involved in a recursive call. i have corrected it as suggested and it works fine now. > You have more subtle problems, though. First, you have needlessly > reduplicated value<1 test--the first thing recursive_halve does is to > check whether value<1, so there's no need to check whether value<1 > before calling it. yes, i could see this was nasty. i figured i'd go back and try and streamline it afterwards. i wrote an insertion sort yesterday and i had to cheat by putting two items into a new list to begin with, and only then enter the nested loops to do the rest of it. i seem to be fighting my way into a process to get a foothold, and only then trying to finish it smoothly/elegantly. hopefully this will ease up with time and practice. > Second, you have redundant branching logic. Look at your first else > statement. It does nothing; the else doesn't affect whether the stuff > inside it gets executed or not; it's redundant. It's better style to > not to have such redundancy (either by omitting the else, or having a > single return point). if i understand this correctly, you mean that the function will terminate if it returns 'value' at the beginning, so the else: is implicit in the fact that the interpreter has even got that far. i take your point about trying to abbreviate what is, in effect, verbiage. thanks again for all the answers. it boggles the mind that one can have access to this almost immediate help at no charge. sam -- http://mail.python.org/mailman/listinfo/python-list
python interpreter on solaris 10
dear all, having spent the last couple of weeks getting to grips with python on windows, i am in the position of trying to make the transition to my newly arrived ultra 20. however, although there are plenty of files with idle somewhere in the title, idle.py (which i assume is the interpreter) will not open, as there is 'no installed viewer.' surely sun have not installed python only for it to unusable? i may well be completely off base here, as using unix is still very much a mystery to me. i have tried /usr/sfw/lib/python at the command prompt. it worked yesterday, but having now moved and restored the python2.3 file to its original position, i find the same command prompt failing to work. have i messed it up by moving it around? my workstation remains a shiny box which does naught but hum malevolently. is there hope? thank you, sam -- http://mail.python.org/mailman/listinfo/python-list
Re: python interpreter on solaris 10
to update: i think i've tracked down the equivalent files on my pc. one opens the interpreter in a white-backed text editor, the other at the black-backed command prompt. i have equivalent files of the same size on the workstation, which must be the same. does anyone know why i'm getting 'there is no installed viewer capable of displaying the document'? i have no idea what i need, or where i can get it. any ideas? sam -- http://mail.python.org/mailman/listinfo/python-list
Re: python interpreter on solaris 10
[EMAIL PROTECTED] wrote: > > i think i've tracked down the equivalent files on my pc. one opens the > > interpreter in a white-backed text editor, the other at the > > black-backed command prompt. i have equivalent files of the same size > > on the workstation, which must be the same. does anyone know why i'm > > getting 'there is no installed viewer capable of displaying the > > document'? > > What, exactly, are you doing to create this error? > searching on the java desktop for all files with 'idle' in them. clicking on idle.py which is the same size as the equivalent file on my pc (from which idle does open). 'could not open document "idle.py"' message comes up. > What happens when you enter the line below at a command prompt? > > /usr/bin/python not found /usr/lib/python2.4/idlelib/idle.py /usr/sfw/python2.3/idlelib/idle.py gives 'there is no action associated with "idle.py"' configure gnome to associate application? click yes: edit file type window pops up. program to run menu is empty. browse is available. any ideas on what i need to choose? -- http://mail.python.org/mailman/listinfo/python-list
Re: python interpreter on solaris 10
> I would try to use the python executable located in /usr/bin if it is > exists, otherwise use the python executable in /usr/sfw/bin. > > casevh lordy lord, is that where it was. i just found it now. i had been thinking that idle was the name of the python interpreter, not just the IDE, hence my emphasis on it. python itself is indeed just in /usr/sfw/bin, as you said. a thousand thanks. i've got it on command line now. -- http://mail.python.org/mailman/listinfo/python-list
how to reuse class deinitions?
hello all, pretty straightforward question here, i think. i'm experimenting with classes and have written a File class that looks like it's worth keeping for future use. however, i cannot work out where to put it for this purpose or how to get it in. i figured i'd try a bit of (un)inspired guesswork by putting it in my module folder, appending sys.path to tell the interpreter where this was, and importing it like a module. probably don't need to tell you that that didn't work, but i'm drawing a blank in the tutorial and not getting any luck in the archives here. maybe i'm just not searching with the right words. it's late here and my brain's switching off... cutting and pasting it into the interpreter is a bit of a bore. any help? much appreciated in advance, sam PS i've just reached first base with classes, and i think i'm starting to see what the big deal is about OOP. it's like someone's turned a light on. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to reuse class deinitions?
should read 'definitions', of course. i hate stupid typos. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to reuse class deinitions?
> What I do: > > For each new major version of python, in .../site-packages I make a > directory "sdd" (my initials). In it I put an empty file named > "__init__.py". When I have things I want to reuse, I put them in > files named things like ".../site-packages/sdd/goodidea.py", and > I get use of them in python programs like: > > from sdd.goodidea import File > ... > > ... > > or (actually my current style): > from sdd import goodidea > ... > > ... > this is basically what i was trying to do. i just tried it again, with a class_defs.py file in a folder i appended to the system path, itself containing the class definition for File. then: from class_defs import File works fine. nice to know i was on the right lines. thanks for the pointer! -- http://mail.python.org/mailman/listinfo/python-list
error handling in user input: is this natural or just laborious
hi all, i'm starting to put together a program to simulate the performance of an investment portfolio in a monte carlo manner doing x thousand iterations and extracting data from the results. i'm still in the early stages, and am trying to code something simple and interactive to get the percentages of the portfolio in the five different investment categories. i thought i'd get in with the error handling early so if someone types in something wrong (like a word), or the numbers don't add up to 100%, the error would be caught immediately and the user sent back to the start of the loop. granting that there may be better ways of doing this, if i decide that i do want to do it like this (i.e. a single error requires all data to be re-entered, not unreasonable for only five items), is this a good way of doing it or a confusing way of doing it from the perspective of readability and maintenance: while True: cash, bond, blue, tech, dev = 0,0,0,0,0 check=False try: cash=input('Please enter a cash percentage for the portfolio: ') except NameError: print 'That is not a number. Please start again and remember to enter integers.' else: try: bond=input('Please enter a bond portfolio for the portfolio: ') except NameError: print 'That is not a number. Please start again and remember to enter integers.' else: try: blue=input('Please enter a blue-chip percentage for the portfolio: ') except NameError: print 'That is not a number. Please start again and remember to enter integers.' else: try: tech=input('Please enter a tech stocks percentage for the portfolio: ') except NameError: print 'That is not a number. Please start again and remember to enter integers.' else: try: dev=input('Please enter a developing countries index for the portfolio: ') check=True except NameError: print 'That is not a number. Please start again and remember to enter integers.' if cash+bond+blue+tech+dev==100: break if cash+bond+blue+tech+dev!=100 and check!= False: print 'Those numbers do not sum to 100. Please start again.' i know it's a bit verbose, but it was the nested try clauses i was really wondering about. is the code immediate legible to experienced python users? or does it look like gibberish at first? just hoped for some fresh eyes on it. thanks, sam PS making check=True just saves the code from printing 'those numbers don't sum to 100' if they haven't all been entered, which looks kind of silly. -- http://mail.python.org/mailman/listinfo/python-list
Re: error handling in user input: is this natural or just laborious
you're right, of course. it occurred to me that, even if it were manageable for a few items, it would quickly become absurd as the number of items grew. this: def get_pct(): while True: pct_list=[['cash', 0], ['bond', 0], ['blue', 0], ['tech', 0], ['dev', 0]] total=0 for i in range(len(pct_list)): pct_list[i][1]=input('Please enter the percentage value for %s: ' %pct_list[i][0]) total+=pct_list[i][1] if total == 100: return pct_list break else: print "You've messed up, do it again..." is much better, and easily maintainable by adding to the assignment for pct_list. still leaves me with checking for strings though, in case someone types 'donut' at the prompt... -- http://mail.python.org/mailman/listinfo/python-list
Re: error handling in user input: is this natural or just laborious
this does what i want, though i don't like the inner while loop having to be there def get_pct(): while True: pct_list=[['cash', 0], ['bond', 0], ['blue', 0], ['tech', 0], ['dev', 0]] total=0 for i in range(len(pct_list)): while True: pct_list[i][1]=raw_input('Please enter the percentage value for %s: ' %pct_list[i][0]) if pct_list[i][1].isdigit() == False: print "You've messed up, do it again..." else: total+=int(pct_list[i][1]) break if total == 100: return pct_list break else: print "You've messed up, do it again..." gosh, a lot of work to get some input. i must be missing something, though this is a lot better than what i had before... -- http://mail.python.org/mailman/listinfo/python-list
Re: error handling in user input: is this natural or just laborious
a huge amount to think about there. special thanks to james for taking the time to make such detailed responses. the problem is that even though nested loops and the like place a heavy analytical burden on the programmer (i.e. me) as he tries to remember what does what, conceptualizing a program as a collection of classes and functions tied together with a minimal amount of code brings to bear what is, at the moment, an even greater burden. my gut feeling is that, over time (as james said was true in his own case), and with practice, the relative weights of these two burdens change so that the procedural approach becomes easier to adopt, and its benefits of readability and maintainability easier to enjoy. fingers crossed... i will continue coding the monte carlo machine until it does what i want in more or less clumsy fashion, and might put it up here if it feels like it would be of interest. thanks again, sam -- http://mail.python.org/mailman/listinfo/python-list
print time comparison: IDLE versus terminal on ultra 20
hi all, i continue to footle around on my spanking new ultra 20 (1.8GHz / Opteron Model 144), gradually trying to get to grips with python and unix both. the slow print time in IDLE had already struck me as rather odd. running programs with heavy print requirements from the terminal was a major discovery though, printing being so fast as to make everything appear at once except in the case of literally thousands of items to be printed. test case: import time time1 = time.time() for i in range(100): print 'go get \'em, son!' time2 = time.time() print time2-time1 in IDLE: 4.433 seconds in terminal: 0.001 seconds a difference of between 3 and 4 orders of magnitude is rather striking. anyone know what's going on here? is it a python, a unix thing, or something else? sam -- http://mail.python.org/mailman/listinfo/python-list
Re: print time comparison: IDLE versus terminal on ultra 20
i was actually experimenting on windows on my own pc before the workstation arrived, and IDLE printed a lot faster on windows than in solaris for me too. i would indeed complain to sun if i had ever got the impression that anyone over there ever knew what was going on... : ) > but on the other hand, IDLE runs your sample script in less than 0.5 > seconds on my cheap Windows box. complain to Sun ;-) > > -- http://mail.python.org/mailman/listinfo/python-list
Re: print time comparison: IDLE versus terminal on ultra 20
i forgot to mention that i'm running a version of python 2.3 (think it's 2.3.5), as that's what was installed and i'm not hooked up to the internet with the ultra 20 yet. that may account for some of the difference. sam -- http://mail.python.org/mailman/listinfo/python-list
program written to model population evolving over time
dear all, i've just finished a program which sets up an initial population consisting of four different phenotypes, allows them to evolve over time and graphs the output at the end, displaying what is in effect the evolutionary steady state for the system. i'm no authority on evolutionary game theory (to put it mildly), but there is a certain amount of interesting emergent behaviour if you put the initial parameters in in a certain manner. excuse my ignorance, but is there a site where people post this kind of stuff? i figured someone might be interested in playing with it, tweaking it a bit, changing the parameters. i've only been programming a couple of months, so i'm sure more experienced programmers could whack into shape if they were interested. or not... it's about 500 lines, including white space and comments, probably about 400 lines of pretty unconcise code in all. thought i'd try and contribute something for once instead of just asking questions. sam PS it does actually work, in case you're wondering. :-) -- http://mail.python.org/mailman/listinfo/python-list
accessing fortran modules from python
hello all, i am currently in the process of planning a piece of software to model polymerisation kinetics, and intend to use python for all the high-level stuff. the number-crunching is something i would prefer to do in fortran (which i have never used, but will learn), but i have no experience of accessing non-python code from python. i am also fairly new to programming period, and am therefore tackling a fairly serious issue reletive to my experience. how easy is it to get fortran modules running from python? if c is easier to use in this respect, i could go in that direction instead. i realize there is a lot of material on this subject already available, but i am finding it difficult to make sense of, it's like trying to take a drink from a fire hose. any advice would be gratefully received. i will almost certainly be coding this on windows, for what it's worth. thank you, sam PS if numpy is adequate for this, i would be quite happy to use it. i got the impression it was more for matrix algebra. i will be programming a monte carlo simulation, which will need to perform a lot (a lot!) of simple operations over and over... -- http://mail.python.org/mailman/listinfo/python-list
Re: accessing fortran modules from python
thanks guys, i'll follow this up more in a couple of weeks when i know what i need to do better. sam -- http://mail.python.org/mailman/listinfo/python-list
Re: About the 79 character line recommendation
Steve Bergman wrote: > As I study Python, I am trying to develop good, Pythonic, habits. For > one thing, I am trying to keep Guido's the style guide in mind. > > And I know that it starts out saying that it should not be applied in > an absolute fashion. > > However, I am finding that the 79 character line prescription is not > optimal for readability. > > Certainly, cutting back from the length of lines that I used to use has > *helped* readability. But if I triy very hard to apply 79, I think > readability suffers. If this were just something that was an issue > occasionally, I would just put it off to "know when to break the > rules". However, find myself going to 90 to 100 characters very > frequently. Now, if it were just me, I'd shoot for < 100. However, > the Python philosophy includes making code easier for others to read, > as well. > > So, I was wondering what more accomplished Python programmers thought > about this. > > While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? > > Thanks, > Steve Bergman I prefer to use 132 char per line, and like you I line up the = sign for readability. The reason for this convention arises from the fact that I am Dyslexic, and this convention helps me double check my typing. Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
problems caused by very large for-loop
hi all, i am writing some software to model polymerisation kinetics and have created a way of doing so which involves taking ever smaller slices of time to model until some sort of convergence was observed in the results. so far so good, but i was using 'for i in the range(iterations):' a for loop over each slice of time, where the number of iterations was getting into the tens of millions. up until about 125,000,000 it worked, then i got a MemoryError. now i wasn't surprised to get a memory error eventually because what i was doing was some serous number-crunching. but it didn't occur to me where it was at first. i had to keep some results in memory to calculate something at the end, but that was about a million integers, not that hard with 512 Mb of RAM. then i thought it might be something structural in the way python works, but i couldn't guess at what it might be. thinking about it a bit more, i remembered having read that the for-loop declaration i used actually created a list of integers, which would be eating up over half of my memory before i'd even started doing anything. the program was creating a directory as instructed, then doing nothing, just churning, which made it clear that the problem was encountered right at the start of the program. that helped clear it up, but i was surprised that something as innocuous as the for-loop was creating such a problem. i changed it to a while-loop and it worked fine. has anyone else bumped up against this problem before? i suppose for-loops with 250 million iterations are seldom used in most applications. it was just the first time i'd ever solved a problem by actually having some insight into how python works at a slightly lower level. anyway, sorry to be so long-winded. i'm just glad the damn thing's working again... :) sam -- http://mail.python.org/mailman/listinfo/python-list
Re: problems caused by very large for-loop
thanks, i'll remember that. it makes sense that there should be a way of doing it... sam -- http://mail.python.org/mailman/listinfo/python-list
matplotlib, wxPanel inside a wxPanel
Hello, I'm currently creating a GUI, which consists of a main frame that contains a menu bar,a toolbar and an empty panel, let's call it main_panel. Ideally, I'd like the following functionality: upon choosing an item from the menu bar, a particular graph will be displayed inside main_panel. Now I've taken a look at the 'embedding_in_wx' example files that come with matplotlib. Using this example, I can place a graph in a panel (let's call it graph_panel), and display this in a frame. I can also get NavigationToolbar2 to work completely. On the other hand, when i create graph_panel and put this inside of main_panel, NavigationToolbar2 does not work. The graph and toolbar are both displayed, but none of the buttons on the toolbar do anything. I'm beginning to think that what i'm trying to do isn't actually possible, and that i'll need to put it in a frame instead, which is a pity. Can anyone please advise if what i'm trying to do is possible and if so, provide a small example? I'm running windows XP, python 2.4, wxpython 2.6. -- http://mail.python.org/mailman/listinfo/python-list
Re: matplotlib, wxPanel inside a wxPanel
Hi Daniel, Thanks very much for your quick response! You're right, it was a case of the cut-and-paste blues, and me not really knowing what each part of the code in the examples was actually doing. A couple of things caught me out: first of all, i wasn't calling SetSizer and Fit on the right panels... Secondly, I stuffed up when trying to give graph_panel a parent of main_panel. It turns out I was actually never doing this, so the toolbar would appear, but none of the buttons would work. Thanks again for your comments, they were very helpful, Cheers Sam -- http://mail.python.org/mailman/listinfo/python-list
"wxmsw26uh_vc.dll not found" when using wxAgg backend
Hello, I've installed matplotlib recently because I want to add graphing functionality to a GUI that i'm making. I decided to try using the wxAgg backend instead of plain old wx because: a) I hear it's quicker, and b) when i use the wx backend, the axis labels don't seem to work properly - i can't change their font, and the axis label always overwrites my tickbox labels. So i'm not too concerned about these wx problems anymore because i'm changing to wxAgg. Here's the problem i'd like help with. - i import the wxAgg backends, Figurecanvas, etc. - i run the file - the following error box pops up: "This application has failed to start because wxmsw26uh_vc.dll was not found. Reinstalling the application may fix this problem." This problem occurs even when I run the matplotlib example files that you can download from the matplotlib homepage. I have tried reinstalling, and that has not rectified the problem. I googled for wxmsw26uh_vc.dll and found a small number of posts. The following post: https://svn.enthought.com/enthought/ticket/774 suggests that it will be "fixed in 1.0.0.rc1" which was supposedly released a few weeks ago. I didn't really follow the discussion of why this error is occurring, i just want to find out how to fix it! I'm running a windows XP machine with: python 2.4, matplotlib 87.4 and wxPython ansi-2.6.3.3 Any help would be much appreciated Cheers Samantha -- http://mail.python.org/mailman/listinfo/python-list
"list index out of range" error
hey everybody, this is my first time posting here. i'm pretty new to python and programming in general (as you'll soon work out for yourselves...) i'm trying to code a version of a selection sort and the heart of the code is as follows (no_lines is simply the number of items to be sorted, read out of an input file): for j in range(0, no_lines): k = 0 while k < no_lines: sorted_check = 0 if list_initial[k] < list_initial[k+1]: temp_str = list_initial[k] elif list_initial[k] == list_initial[k+1]: temp_str = list_initial[k] elif list_initial[k] > list_initial[k+1]: temp_str = list_initial[k+1] sorted_check = 1 k += 1 list_initial.remove(temp_str) list_final.append(temp_str) no_lines -= 1 if sorted_check == 0: break problem is, i keep getting a "list index out of range" error. i've had this problem before in different contexts with lists in loops. i thought i had it cracked when it occurred to me that i needed to decrement no_lines to take into account that list_initial was shrinking as i deleted sorted items, but i still got the same error. it's probably something trivial, but i can't seem to get round it by using while loops, and i had the same problem with cmp(), hence the explicit comparison above, which still doesn't work. can anyone help a beginner out with this? many thanks in advance, sam lynas -- http://mail.python.org/mailman/listinfo/python-list
Re: "list index out of range" error
actually, that little bit of code i wrote is obscenely wrong anyway, so please don't bother analyzing the flow. any insight into the "list index out of range" error would still be welcome, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: "list index out of range" error
yes, yes, of course, thank you. not sure what i thought i was doing there. i'll see if i can get it running now... -- http://mail.python.org/mailman/listinfo/python-list
Re: "list index out of range" error
for what it's worth. and it is approx. five times quicker than the bubblesort i wrote to begin with on a 286-word highly unordered list, so i wasn't wasting my time after all... __ import time file_input = open('wordlist.txt', 'r') list_initial = [] no_lines = 0 for line in file_input: list_initial.append(line) no_lines += 1 no_lines_2 = no_lines print list_initial file_input.close() raw_input('press enter to sort: ') list_final = [] temp_str = "" time1 = time.clock() for j in range(no_lines_2): temp_str = 'zz' for k in range(no_lines): if temp_str > list_initial[k]: temp_str = list_initial[k] list_initial.remove(temp_str) list_final.append(temp_str) no_lines -= 1 time2 = time.clock() final_time = time2 - time1 print list_final print print 'number of seconds for sort list: ', final_time print print 'number of words in list: ', no_lines_2 ___ thanks again for your help. that sorted out something that had really been bugging me. -- http://mail.python.org/mailman/listinfo/python-list
Re: "list index out of range" error
gabriel, > Now that your main problem is gone, just a few comments: > - python lists know their length, so you don't need explicit no_lines > and no_lines_2 > - list_initial.remove(temp_str) is fairly slow - it has to *scan* the > list to locate temp_str. Just keep its index instead, and use del > list_initial[index] i will try rewriting it in that manner and comparing the times. i have no feel so far for the relative speeds of different ways of doing things, but i can see the importance of it. > - as a general sorting routine, that 'zzz' does not look very > good, try to avoid it. yes, it's hideous even to a novice. however, i need to go to bed now, and if i hadn't got this to work before bed, i'd never get to sleep! i'll have to mull it over and come up with something more elegant. ben, i used to work for a company where we exchanged a lot of e-mails, and the titles were always 're: your e-mail', or 'project stuff', or 'file for client' or suchlike. made it kind of difficult to find anything. figured a similar principle might apply here... ; ) thanks again all, sam -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing class variables in staticmethods.
On 21 Jan 2007 12:49:17 -0800, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > class Base: > staticvar = 'Base' > > @staticmethod > def printname(): > # this doesn't work > # print staticvar > # this does work but derived classes wouldn't behave as I want > print Base.staticvar > > class Derived(Base): > staticvar = 'Derived' > > Base.printname() # should print 'Base' > Derived.printname() # should print 'Derived' > > Any idea on how to go about this? Also from a staticmethod how can I > find out other attributes of the class (not objects)? Do static methods > get some classinfo via some implicit argument(s)? No, staticmethods get told nothing about the class they're being defined in. What you want is a classmethod, which gets passed the class to work with. Using classmethods, your code becomes: #untested, bear in mind class Base: staticvar = 'Base' @classmethod def printname(cls): print cls.staticvar class Derived(Base): staticvar = 'Derived' Base.printname() #prints 'Base' Derived.printname() #prints 'Derived' Incidentally, you can also use cls.__name__ for this purpose, but I guess that your actual motivation for this is more complicated than class names. -- http://mail.python.org/mailman/listinfo/python-list
Re: Socket and array
On 07/02/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > How to send an array via socket to the other end?Thanks. What you want is a serialisation solution - turning objects into a string format, and vice versa. Python provides a system for this in its standard library, in the pickle module. Some pseudocode might look like: #sender import pickle socket_send(pickle.dumps(my_list)) #receiver import pickle my_list = pickle.loads(read_all_socket_data()) However, this should only be used if you trust where the data is coming from; with untrusted data, a more restrictive format (such as JSON, perhaps, or a similar lightweight notation system if you are only sending lists) would be a good idea. --Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: c++ for python programmers
On 13 Feb 2007 17:51:00 GMT, Jorgen Grahn <[EMAIL PROTECTED]> wrote: > Well, C++ is a better language than C in many ways. So, if he needs to learn > one of them, why does it have to be C? > > Another reason some people choose C++ over Python for some tasks is that > they feel that larger programs benefit from strong, static type checking. > I like both ways, but depending on the task, one or the other is better. C++ is -not- strongly typed. You can cast anything to void *, and manipulate it in ways unimaginable. Plus there's the whole mess that is pointer arithmetic and a weak typesystem... Disclaimer: I am unashamedly in the "C++ Is Evil" camp, and wholly believe that if you want proper strong, static type checking, use Haskell, or if you want proper, complete object-orientation (C++'s primitive types compromise its object system's integrity, and I believe I've already discussed casting and pointers), use Python, and if you want under-the-hood pointer-fu, use C. --Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: Pep 3105: the end of print?
On 16 Feb 2007 13:48:29 -0800, Klaas <[EMAIL PROTECTED]> wrote: > 3. in your code: > try: > from compat26 import print2 > except (ImportError, SyntaxError): > # python 3.0 > print2 = print Python 2.5c1 (r25c1:51305, Aug 17 2006, 10:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> try: from compat26 import print2 except (ImportError, SyntaxError): # python 3.0 print2 = print SyntaxError: invalid syntax >>> try: pass except (ImportError, SyntaxError): # python 3.0 print2 = print SyntaxError: invalid syntax Any and all aliasing must happen in compat26.py. My suggested solution is this: #_compat30.py print2 = print #compat.py try: from _compat30 import print2 except SyntaxErorr, ImportError): def print2(): --Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: Most elegant way to generate 3-char sequence
I have found that the more elegant the code is, the harder it is for me to understand what it is trying to accomplish. It is my opinion that "Keep It Simple" wins over elegance. When I have had the urge to get elegant, I make sure I comment the elegance so my less elegant co-workers can figure out what I was trying to accomplish. Sam Schulenburg James Stroud wrote: > Fredrik Lundh wrote: > > James Stroud wrote: > > > >> See the actual question: > >> > >> >How would you construct a generator to acheive this? > > > > > > if you don't think the context provided by the subject line and the > > sentence before the question is important, how come you're so sure what > > "this" refers to ? > > > > > > > > I'm getting the feeling that "correct" answers have nothing to do with > correctness (i.e. working code) but on some vague notion of "elegance". > Please point me to the page where code elegance is precisely defined so > that I may construct my answers appropriately. And yes, I am too lazy to > google "code elegance". > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
I have been using the latest VC.net to compile my SCSIPython extension dll for Python 2.3, 2.4, and 2.5 without any problems. I just have to make shure that I link with the correct Python.lib Sam Schulenburg -- http://mail.python.org/mailman/listinfo/python-list
I can do it in sed...
I have spent so much time using sed and awk that I think that way. Now, when I have to do some Python things, I am having to break out of my sed-ness and awk-ness, and it is causing me problems. I'm trying. Honest! Here are the two things that I'm trying to do: In sed, I can print every line between ^start to ^end by using /^start/,/^end/p. It's quick, easy, and doesn't take much time. Is there a way to do this easily in Python? Also, I frequently use something like s/^[A-Z]/~&/ to pre-pend a tilde or some other string to the beginning of the matched string. I know how to find the matched string, but I don't know how to change the beginning of it while still keeping the matched part. If I were able to stay in the *nix environment for all my work, I could do it with these tools and the beloved pipe(|), but that isn't my lot in life. I would do it in Perl, but, frankly, it gives me headaches even looking at it. Any ideas? Thanks, Lance -- http://mail.python.org/mailman/listinfo/python-list
Re: I can do it in sed...
Thanks to everyone who answered my two questions. I have only submitted questions twice, and on both occasions the solutions were excellent, and, I'm emarrassed to say, much simpler than I thought they would be. My next goal is to be able to help someone they way y'all have helped me. Thanks again, Lance Kent Johnson wrote: Kotlin Sam wrote: Also, I frequently use something like s/^[A-Z]/~&/ to pre-pend a tilde or some other string to the beginning of the matched string. I know how to find the matched string, but I don't know how to change the beginning of it while still keeping the matched part. Something like re.sub(r'^([A-Z])', r'~\1', target) should do it. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Do You Want To Know For Sure That You Are Going To Heaven? The reason some people don't know for sure if they are going to Heaven when they die is because they just don't know. The good news is that you can know for sure that you are going to Heaven wh
The only people who "know" they are going to heaven, clearly aren't <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > The reason some people don't know for sure > if they are going to Heaven when they die > is because they just don't know. > > The good news is that you can know for > sure that you are going to Heaven which is > described in the Holy Bible as a beautiful > place with no death, sorrow, sickness or > pain. > > God tells us in the Holy Bible how simple > it is to be saved so that we can live > forever with Him in Heaven. > > "For if you confess with your mouth Jesus > is Lord and believe in your heart that God > raised Him from the dead, you > WILL BE SAVED." (Romans 10:9) > > Over 2000 years ago God came from Heaven > to earth in the person of Jesus Christ to > shed His blood and die on a cross to pay > our sin debt in full. > > Jesus Christ was born in Israel > supernaturally to a virgin Jewish woman > named Mary and lived a sinless life for > thirty-three years. > > At the age of thirty-three Jesus was > scourged and had a crown of thorns pressed > onto His head then Jesus was crucified. > > Three days after Jesus died on a cross and > was placed in a grave Jesus rose from the > dead as Jesus said would happen before > Jesus died. > > If someone tells you that they are going > to die and in three days come back to life > again and it happens then this person must > be the real deal. > > Jesus Christ is the only person that ever > lived a perfect sinless life. > > This is why Jesus is able to cover our > sins(misdeeds) with His own blood because > Jesus is sinless. > > The Holy Bible says, "In Him(Jesus) we > have redemption through His blood, the > forgiveness of sins..." (Ephesians 1:7) > > If you would like God to forgive you of > your past, present and future sins just > ask Jesus Christ to be your Lord and > Saviour. > > It doesn't matter how old you are or how > many bad things that you have done in > your life including lying and stealing > all the way up to murder. > > Just pray the prayer below with your > mouth and mean it from your heart and > God will hear you and save you. > > Dear Jesus Christ, I want to be saved so > that I can have a home in Heaven with You > when I die. I agree with You that I am a > sinner. I believe that You love me and want > to save me. I believe that You bled and > died on the cross to pay the penalty for my > sins and that You rose from the dead. > Please forgive my sins and come into my > heart and be my Lord and Saviour. Thanks > Lord Jesus Christ for forgiving me and > saving me through Your merciful grace. > Amen. > > Welcome to the family of God if you just > allowed God to save you. Now you are a real > Christian and you can know for sure that > you will live in Heaven forever when this > life comes to an end. > > As a child of God we are to avoid > sin(wrongdoing), but if you do sin the > Holy Bible says, "My dear children, I > write this to you so that you will not sin. > But if anybody does sin, we have one who > speaks to the Father in our defense Jesus > Christ, the Righteous One." > > Those of you that have not yet decided to > place your trust in the Lord Jesus Christ > may never get another chance to do so > because you do not know when you will die. > > Jesus said "I am the way, the truth and > the life: no one can come to the > Father(God)(in Heaven), but by me." > (John 14:6) > > This means that if you die without > trusting in Jesus Christ as your Lord and > Saviour you will be forever separated from > the love of God in a place called Hell. > > The Holy Bible descibes Hell as a place of > eternal torment, suffering, pain and agony > for all those who have rejected Jesus Christ. > > The good news is that you can avoid Hell by > allowing Jesus Christ to save you today. > Only then will you have true peace in your > life knowing that no matter what happens you > are on your way to Heaven. > > > Praise the Lord! > Servant of the Lord Jesus Christ > Ronald L. Grossi > > *Show this to your family and friends so > they can know that they have a choice > where they will spend eternity. Thanks! > > > > > > Got Questions? > http://www.gotquestions.org/archive.html > > Other Languages > http://www.godssimpleplan.org/gsps.html > > Free Movie: To Hell and Back > http://www.tbn.org/index.php/8/1.html > > Animation > http://www.browser.to/jesus-animation > > The Passion Of The Christ > http://www.thepassionofthechrist.com > > Beware Of Cults > http://www.carm.org/cults/cultlist.htm > > About Hell > http://www.equip.org/free/DH198.htm > > Is Jesus God? > http://www.powertochange.com/questions/qna2.html > > Free Online Bible > http://www.biblegateway.com > > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: forum
[EMAIL PROTECTED] wrote at 2-10-2005 19:00:23: >Forum commuication is easier, and I've just started a new forum and >would like to invite all of you to sign up and post there. I don't agree with you, I like news-commuication. It's more free than forum use. -- with kind regards / met vriendelijke groeten Sam Francke -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce wxpython
I'd always assumed it was doubleyew-ecks python, but it could be wicks python, or similar. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
What about not storing args at all? Something like this: def cache_function(func, args_list): cache = {} def cached_result(*args, **kwargs): kwargs.update(dict(zip(args_list, args))) if kwargs in cache: return cache[kwargs] result = func(**kwargs) cache[kwargs] = result return result return cached_result args_list is a list of all the argument names, so that they can be converted into keyword arguments. -- http://mail.python.org/mailman/listinfo/python-list
Re: Works only in interactive mode
That looks like a different module named pcop getting in the way. If there's another pcop.py in the directory where you're running it as a script, then that gets priority and you'll end up with an error like the one you got. However, if you run it interactively, then that directory is not checked, or is (normally) checked lower-down than, say, Python's standard library. Try checking if help(pcop) and dir(pcop) are what you expect in the script, and looking at where sys.path is looking for scripts. -- http://mail.python.org/mailman/listinfo/python-list
Re: wierd threading behavior
thread is a low-level threading module, and start_new is deprecated. Aside from that, thread.start_new(test.()) is syntaxically wrong (a pair of brackets can't follow a dot). However, your example does work for me once I fix the syntax, and it prints hello but then hangs. I can't explain the other results, though - possibly undefined behaviour or more likely me not having much experience with the low-level thread interface. Use threading instead, like so: import threading def test(): print 'Test successful!' def main(): thread = threading.Thread(target = test) thread.start() main() -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling an exe from Python?
from subprocess import Popen proc = Popen('my_programme.exe') Use proc.communicate(input) to send input to stdin, and get a tuple of (stdout, stderr) back. If you need the returncode, use proc.poll() or proc.wait(), depending on if you want it to block or not. -- http://mail.python.org/mailman/listinfo/python-list
Re: High Order Messages in Python
This can be suitably applied to Python with the use of Higher Order Functions, though. It's not quite the Ruby version because Python allows you to use functions as first-class objects, complicating the All-You-Can-Do-Is-Pass-A-Message philosophy. This is my 5-minute implementation: class HigherOrderList(list): def do(self, func): return HigherOrderList(each(self, func)) def where(self, pred): return HigherOrderList(mass_test(self, pred)) def mass_test(iterable, pred): for item in iterable: if pred(item): yield item def each(iterable, method): for item in iterable: yield method(item) -- http://mail.python.org/mailman/listinfo/python-list
Re: index and find
>>> s = 'foobar' >>> s.find('z') -1 >>> s.index('z') Traceback (most recent call last): File "", line 1, in -toplevel- s.index('z') ValueError: substring not found Pretty self explanatory. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I sort these?
> unzip doesn't seem to work for me... It's not a part of the standard Python distribution, but this is a naive implementation (it doesn't react well to the list's contents having different lengths). def unzip(seq): result = [[] for i in range(len(seq[0]))] for item in seq: for index in range(len(item)): result[index].append(item[index]) return result >>> unzip(zip(range(5), 'abcde')) [[0, 1, 2, 3, 4], ['a', 'b', 'c', 'd', 'e']] -- http://mail.python.org/mailman/listinfo/python-list
Re: SNMP
py wrote: > >From what I have seen Python does not come with an snmp module built > in, can anyone suggest some other SNMP module (preferably one you have > used/experienced)..I have googled and seen yapsnmp and pysnmp (which > seem to be the two most active SNMP modules). > > Thanks I've used pysnmp on Windows to successfully monitor and set parameters in half a dozen different 802.11a/b/g access points from different vendors, so I guess, it gets my nod. The documentation is adequate but no spoon-feeding here! You'll have to try and see if it serves your needs. -A -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickling and unpickling inherited attributes
The reason the state of obj.A and obj.B aren't preserved is because your __getstate__ and __setstate__ don't preserve them - they only save obj.C, and you don't make a call to the parent class's respective methods. Here's what I mean: >>> import pickle >>> class Child(Parent): __slots__=['C',] def __init__(self, c): self.C=c def __getstate__(self): return Parent.__getstate__(self) + (self.C) def __setstate__(self, tup): self.C = tup.pop() Parent.__setstate__(self, tup) >>> obj = Child('foo') >>> obj.A = 'bar' >>> obj.B = 'baz' >>> objct = pickle.loads(pickle.dumps(obj)) >>> objct.A 'bar' >>> objct.B 'baz' >>> objct.C 'foo' -- http://mail.python.org/mailman/listinfo/python-list