[ANN] PyTables 2.0b2 released
=== Announcing PyTables 2.0b2 === PyTables is a library for managing hierarchical datasets and designed to efficiently cope with extremely large amounts of data with support for full 64-bit file addressing. PyTables runs on top of the HDF5 library and NumPy package for achieving maximum throughput and convenient use. The PyTables development team is happy to announce the public availability of the second *beta* version of PyTables 2.0. This will hopefully be the last beta version of 2.0 series, so we need your feedback if you want your issues to be solved before 2.0 final would be out. You can download a source package of the version 2.0b2 with generated PDF and HTML docs and binaries for Windows from http://www.pytables.org/download/preliminary/ For an on-line version of the manual, visit: http://www.pytables.org/docs/manual-2.0b2 Please have in mind that some sections in the manual can be obsolete (specially the Optimization tips chapter). Other chapters should be fairly up-to-date though (although still a bit in state of flux). In case you want to know more in detail what has changed in this version, have a look at ``RELEASE_NOTES.txt``. Find the HTML version for this document at: http://www.pytables.org/moin/ReleaseNotes/Release_2.0b2 If you are a user of PyTables 1.x, probably it is worth for you to look at ``MIGRATING_TO_2.x.txt`` file where you will find directions on how to migrate your existing PyTables 1.x apps to the 2.0 version. You can find an HTML version of this document at http://www.pytables.org/moin/ReleaseNotes/Migrating_To_2.x Keep reading for an overview of the most prominent improvements in PyTables 2.0 series. New features of PyTables 2.0 - NumPy is finally at the core! That means that PyTables no longer needs numarray in order to operate, although it continues to be supported (as well as Numeric). This also means that you should be able to run PyTables in scenarios combining Python 2.5 and 64-bit platforms (these are a source of problems with numarray/Numeric because they don't support this combination as of this writing). - Most of the operations in PyTables have experimented noticeable speed-ups (sometimes up to 2x, like in regular Python table selections). This is a consequence of both using NumPy internally and a considerable effort in terms of refactorization and optimization of the new code. - Combined conditions are finally supported for in-kernel selections. So, now it is possible to perform complex selections like:: result = [ row['var3'] for row in table.where('(var2 20) | (var1 == sas)') ] or:: complex_cond = '((%s = col5) (col2 = %s)) ' \ '| (sqrt(col1 + 3.1*col2 + col3*col4) 3)' result = [ row['var3'] for row in table.where(complex_cond % (inf, sup)) ] and run them at full C-speed (or perhaps more, due to the cache-tuned computing kernel of Numexpr, which has been integrated into PyTables). - Now, it is possible to get fields of the ``Row`` iterator by specifying their position, or even ranges of positions (extended slicing is supported). For example, you can do:: result = [ row[4] for row in table# fetch field #4 if row[1] 20 ] result = [ row[:] for row in table# fetch all fields if row['var2'] 20 ] result = [ row[1::2] for row in # fetch odd fields table.iterrows(2, 3000, 3) ] in addition to the classical:: result = [row['var3'] for row in table.where('var2 20')] - ``Row`` has received a new method called ``fetch_all_fields()`` in order to easily retrieve all the fields of a row in situations like:: [row.fetch_all_fields() for row in table.where('column1 0.3')] The difference between ``row[:]`` and ``row.fetch_all_fields()`` is that the former will return all the fields as a tuple, while the latter will return the fields in a NumPy void type and should be faster. Choose whatever fits better to your needs. - Now, all data that is read from disk is converted, if necessary, to the native byteorder of the hosting machine (before, this only happened with ``Table`` objects). This should help to accelerate applications that have to do computations with data generated in platforms with a byteorder different than the user machine. - The modification of values in ``*Array`` objects (through __setitem__) now doesn't make a copy of the value in the case that the shape of the value passed is the same as the slice to be overwritten. This results in considerable memory savings when you are modifying disk objects with big array values. - All the leaf constructors (except Array) have received a new ``chunkshape`` argument that lets the user to explicitly select the chunksizes for the underlying HDF5 datasets (only for advanced users). -
Re: Prevent Modification of Script?
Just throw out the .py files and let it run on the .pyc's alone. ~Sean On Apr 4, 8:03 pm, James Stroud [EMAIL PROTECTED] wrote: ts-dev wrote: The root of my question is verifying the integrity of the application and the scripts being run. Google md5sum. Then google birthday attack. James -- http://mail.python.org/mailman/listinfo/python-list
Python and Java
Hi I am new to python .I need your help in solving my problem. Is there any way to call python files in a java file .How is it possible? Thanks Sreelatha -- http://mail.python.org/mailman/listinfo/python-list
ok
hi looking for someone to bult my web site for me -- http://mail.python.org/mailman/listinfo/python-list
Re: ok
How much does it pay? [EMAIL PROTECTED] wrote: hi looking for someone to bult my web site for me -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question about sequence multiplication
Scott wrote: sentence = raw_input('Sentence: ') screen_width = 80 text_width = len(sentence) box_width = text_width + 6 left_margin = (screen_width - box_width) // 2 print print ' ' * left_margin + '+' + '-' * (box_width-2) + '+' print ' ' * left_margin + '| ' + ' ' * text_width + ' |' print ' ' * left_margin + '| ' + ' ' sentence + ' |' print ' ' * left_margin + '| ' + ' ' * text_width + ' |' print ' ' * left_margin + '+' + '-' * (box_width-2) + ' |' print Now that, even though copied straight from Beginning Python: From Novice to Professional, returns : There's an error in your program: invalid syntax The source code available at http://hetland.org/writing/beginning-python/ does work. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open a txt file from the same folder as my module (w/out changing the working dir)
Larry, Gabriel Thanks for the replies. Both ways work great. Sergio On 4/4/07, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 04 Apr 2007 20:14:37 -0300, Larry Bates [EMAIL PROTECTED] escribió: Sergio Correia wrote: I have a program in 'C:\Python25\Lib\site-packages\spam\spam.py' Importing and everything works fine: from spam import spam But the program calls a file located on the same folder (that is: C:\Python25\Lib\site-packages\spam\). How do i do that? The problem is that C:\Python25\Lib\site-packages\spam is not the current working directory when you run the program. If it were, and if configuration.txt is in that directory it WILL find it. If you are running this from a shortcut make the working directory C:\Python25\Lib\site-packages\spam If changing the working directory is not possible/convenient, use the module __file__ attribute (spam.__file__) to obtain the directory where spam.py resides. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Why does my callback funtion collapse?
Hi,all I try to callback from a thread in C. But it collapsed. I can't figure it out. My test files attached. Thanks. #include windows.h #include Python.h #include stdio.h static PyObject *my_callback = NULL; DWORD threadId; HANDLE thread; static PyObject * callback_set_callback(PyObject *dummy, PyObject *args) { PyObject *result = NULL; PyObject *temp; if (PyArg_ParseTuple(args, O:set_callback, temp)) { if (!PyCallable_Check(temp)) { PyErr_SetString(PyExc_TypeError, Must be callable); return NULL; } my_callback = temp; Py_XINCREF(temp); Py_XDECREF(my_callback); Py_INCREF(Py_None); result = Py_None; } return result; } PyObject* Test() { PyObject *result; PyObject *arglist; int i = 0; for (; i10; ++i) { printf(Callback from Test()\n); arglist = Py_BuildValue((i), i*i); result = PyEval_CallObject(my_callback, arglist); Py_DECREF(arglist); } return result; } static PyObject * callback_test(PyObject *dummy, PyObject *args) { thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Test, NULL, 0, threadId); //FIXME //WaitForMultipleObjects(1, thread, TRUE, INFINITE); // return Py_BuildValue(b, TRUE); } static PyMethodDef CameraModuleMethods[] = { {Test, callback_test, METH_NOARGS, Test}, {SetCallback, callback_set_callback, METH_VARARGS, Set callback func}, {NULL, NULL, 0, NULL} }; void initCallbackTest(void) { Py_InitModule(CallbackTest, CameraModuleMethods); }; # # usage: python setup.py install # from distutils.core import setup, Extension my_module = Extension(CallbackTest, sources=['callback.c']) setup(name=CallbackTest, version=1.0, ext_modules=[my_module]) import CallbackTest as cb import time def print_msg(long_number): print * 3, long_number return True cb.SetCallback(print_msg) cb.Test() time.sleep(1) -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve error
[EMAIL PROTECTED] wrote: On Apr 5, 12:14 pm, 7stud [EMAIL PROTECTED] wrote: test1.py: import shelve s = shelve.open(/Users/me/2testing/dir1/aaa.txt) s['x'] = red s.close() output:-- $ python test1.py Traceback (most recent call last): File test1.py, line 3, in ? s = shelve.open(/Users/me/2testing/dir1/aaa.txt) File /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/shelve.py, line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/shelve.py, line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/anydbm.py, line 80, in open raise error, db type could not be determined anydbm.error: db type could not be determined Exception exceptions.AttributeError: DbfilenameShelf instance has no attribute 'writeback' in ignored - What should I do to correct that error? how did you generate aaa.txt? In a text editor, which I then saved to that directory. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with my urllib.urlopen() function
En Thu, 05 Apr 2007 02:40:38 -0300, Xell Zhang [EMAIL PROTECTED] escribió: hello all, I am a newbie in Python. In my module, if I call urllib.urlopen() function like: url = http://www.google.com/; source = urllib.urlopen(url) Then in the output there will be an exception: Exception exceptions.AttributeError: 'NoneType' object has no attribute 'print_exc' in bound method FancyURLopener.__del__ of urllib.FancyURLopener instance at 0x00D59AA8 ignored I do not know why, if I did something wrong? It works OK for me (I don't get any exception). Such messages happen when any __del__ method raises any exception; it can't be handled normally so Python just logs the error on the console. Can you provide a complete and small example showing the problem? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve error
On Apr 4, 10:22 pm, [EMAIL PROTECTED] wrote: how did you generate aaa.txt? Ok, I got it to work by supplying a filename that didn't previously exist. Neither the book I am reading, Beginning Python: From Novice to Professional nor the book I am using as a reference, Python in Nutshell, happens to mention that important fact. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does my callback funtion collapse?
En Thu, 05 Apr 2007 03:35:34 -0300, lialie [EMAIL PROTECTED] escribió: I try to callback from a thread in C. But it collapsed. I can't figure it out. - If you are using threads, you must handle the Global Interpreter Lock (GIL), see http://docs.python.org/api/threads.html - You don't handle refcounts well: my_callback = temp; Py_XINCREF(temp); Py_XDECREF(my_callback); The code above does nothing. You must decrement my_callback *before* the assignment (because you are about to lose a reference to the previous value) and increment it after (because you keep a reference to the new value). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
On Apr 3, 3:53 pm, bahoo [EMAIL PROTECTED] wrote: My first submission handles duplicates, but not triplicates and more. Here is one that seems a bit more bulletproof: duplist = [1, 2, 3, 4, 'haha', 1, 2, 3, 4, 5, 1,2,3,4,6,7,7,7,7,7] copylist = duplist[:] fullset = set(duplist) for x in duplist: del(copylist[copylist.index(x)]) if x in copylist: if x in fullset: fullset.remove(x) print list(fullset) when it is run, I get: IDLE 1.1.3 No Subprocess [5, 6, 'haha'] Now how would one do it and preserve the original order? This apparently simple problem is surprisingly FOS... But list comprehension to the rescue : [x for x in duplist if duplist.count(x) == 1] ['haha', 5, 6] *shakes head* duh... why does it take so long? : - ( - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Dennis Lee Bieber wrote: On 4 Apr 2007 14:23:19 -0700, Chris Lasher [EMAIL PROTECTED] declaimed the following in comp.lang.python: A friend of mine with a programming background in Java and Perl places each class in its own separate file in . I informed him that keeping all related classes together in a single file is more in the Python idiom than one file per class. He asked why, and frankly, his valid question has me flummoxed. As I recall, Java essentially doesn't offer a CHOICE... So I'd consider any argument that one per file is best to be flawed if based upon Java practice. After all, if one can not even experiment with other ways, how can one really evaluate the options? {and I consign Perl to realms described by Dante} On class per file was easier to do when Java was developed (remember it was develop to control vending machines; scary. Reminds me of the movie 'Tron'). The desktop computer for Sun was an IPC workstation. Nice but no balls and no good editors that could have 24+ tabs open or a way to 'close' sections of coherent text (which are common in my preferred editor, Komodo). So your friend is arguing the past. Ask him if he's a Republican too or needs a serious reboot. I have a good pair of boot to give him a kick in the ass (Democrats would need a kick in the head to reset; we all know what organ Republican think with). sph -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Terry Reedy [EMAIL PROTECTED] wrote: Ask him why he does not wear a straightjacket all the time. It is great for one's posture ;-) No it isn't - those funny arms give you round shoulders.. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Resume of Steve Snow : Database SQL Applications Programmer
stevesnow a écrit : -- Please forward this work experience skills summary to your Database software development, MIS/IT/Software Department for review. -- Here is my full resume in Microsoft Word format. -0 Years experience in usenet posting -- http://mail.python.org/mailman/listinfo/python-list
Re: Requirements For A Visualization Software System For 2010
You could look at sage.its all python! http://sage.scipy.org/sage/ I wish Xah Lee would stop trolling.oh well Cheers Nathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Sherm Pendley a écrit : Bruno Desthuilliers [EMAIL PROTECTED] writes: Chris Lasher a écrit : so I thought I'd ask here to see why the Python idiom is the way it is: why should we NOT be placing classes in their own separate files? Because it just sucks. ... Just ask him why Java insists on 'one-(public)-class-per-file', and why it's considered good form in C++. I mean, the real *technical* reasons... Yeah, as if because it just sucks is a technical reason. :-) It doesn't pretend to be one !-) It's a stylistic thing, nothing more. A bit more than just 'stylistic' IMHO. It's a matter of convenience. Having to manage hundreds of files each with a dozen lines of code is a PITA. Having to retype the same import statements in hundreds of files is a PITA - and a good way to waste time and forget something when one has to fix these import statements (yes, even with the appropriate tediting tools). I wouldn't call such considerations nothing more than stylistic. There's no technical basis for it, No, but there's no technical reason for putting each class in a separate file. just personal preference. True, I prefer to avoid boilerplate proliferation, switching-file-dance, and maintenance nightmares. -- http://mail.python.org/mailman/listinfo/python-list
Can we make a local variable in a function as global variable???
I have some local variables defined in one method and Can I make those variables as global variables? If so , can any one explain me how can I do that Thanks, Sairam -- http://mail.python.org/mailman/listinfo/python-list
Welch essential for learning Tkinter well?
In a couple of places recently I've seen Brent Welch's _Practical Programming in Tcl Tk_ (http://tinyurl.com/ynlk8b) recommended for learning Tkinter well. So a couple of questions: 1) Is it really good for learning Tkinter, even though it doesn't mention Tkinter at all (in the 4th edition at least)? 2) If it is good for learning Tkinter, can I get by with a cheaper, used copy of the 3rd edition? Thanks, Dick Moores -- http://mail.python.org/mailman/listinfo/python-list
Re: way to extract only the message from pop3
On 3 Apr 2007 12:36:10 -0700, flit [EMAIL PROTECTED] wrote: Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? for i in range( M.stat()[0] ): # M.stat returns msg-count and mbox size msg = '\r\n'.join( M.retr(i+1)[1] )# retrieve the email into string hdrs,body = msg.split('\r\n\r\n',1)# split it into hdrs body HTH :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Steven Howe [EMAIL PROTECTED] writes: On class per file was easier to do when Java was developed (remember it was develop to control vending machines Not quite. Java grew out of a set-top box at Sun, code-named Oak. ; scary. Reminds me of the movie 'Tron' Vending machines in Tron were pussycats compared to the one in Maximum Overdrive. :-) sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we make a local variable in a function as global variable???
On Apr 5, 3:19 am, sairam [EMAIL PROTECTED] wrote: I have some local variables defined in one method and Can I make those variables as global variables? If so , can any one explain me how can I do that Thanks, Sairam --- num = None def f1(): global num num = 30 def f2(): print num f1() f2() --- You can read from a global variable, but to assign to one, you have to declare its name in a global statement on the first line of the function. A better way: def f1(): num = 30 return num def f2(x): print x result = f1() f2(result) --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Chris Lasher a écrit : A friend of mine with a programming background in Java and Perl places each class in its own separate file in . I informed him that keeping all related classes together in a single file is more in the Python idiom than one file per class. He asked why, and frankly, his valid question has me flummoxed. In Java, you HAVE to place a class in it's own file. That's how the language works. But in Java, you do not have to place each class in it's own module/package, in fact, it would be bad. It's the same in Python: you do not want to have one class per module/package. Unfortunately, in Python, a module/package is a file, and in Java, it's a directory. Also, Python doesn't really have the notion of a root package/module. Translation: import foo; foo.foo() sucks so avoid having only one class per module :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Christophe wrote: Chris Lasher a écrit : A friend of mine with a programming background in Java and Perl places each class in its own separate file in . I informed him that keeping all related classes together in a single file is more in the Python idiom than one file per class. He asked why, and frankly, his valid question has me flummoxed. In Java, you HAVE to place a class in it's own file. That's how the language works. But in Java, you do not have to place each class in it's own module/package, in fact, it would be bad. It's the same in Python: you do not want to have one class per module/package. Unfortunately, in Python, a module/package is a file, and in Java, it's a directory. Also, Python doesn't really have the notion of a root package/module. Translation: import foo; foo.foo() sucks so avoid having only one class per module :) One further thought: http://www.artima.com/weblogs/viewpost.jsp?thread=42242 regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Java
Sreelatha G wrote: Hi I am new to python .I need your help in solving my problem. Is there any way to call python files in a java file .How is it possible? Jython is an implementation of Python that compiles to Java bytecode, but at the moment there's some version lag so it won't handle the mos recent language enhancements. Probably worth a look, though. http://www.jython.org/ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve error
7stud wrote: On Apr 4, 10:22 pm, [EMAIL PROTECTED] wrote: how did you generate aaa.txt? Ok, I got it to work by supplying a filename that didn't previously exist. Neither the book I am reading, Beginning Python: From Novice to Professional nor the book I am using as a reference, Python in Nutshell, happens to mention that important fact. It seems to make sense that you have to open a file as writable in order to be able to change its contents, though, doesn't it? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: low level networking in python
I wish to do some low level network stuff using python. I've googled somewhat and came up with pylibpcap[1], trouble is I can't compile it on my Ubuntu 6.10 workstation. I would suggest pcapy: http://oss.coresecurity.com/projects/pcapy.html Higher level, easier Object-Oriented API and support for multi- threading. Here's an example showing a simple sniffer app: http://oss.coresecurity.com/impacket/sniff.py Anyway, what kind of 'low-level network stuff' we're talking about? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Bruno Desthuilliers [EMAIL PROTECTED] writes: Sherm Pendley a écrit : It's a stylistic thing, nothing more. A bit more than just 'stylistic' IMHO. It's a matter of convenience. Having to manage hundreds of files each with a dozen lines of code is a PITA. Yes, but the pain in that case comes from having hundreds of trivial classes, not from the way in which the source for them is organized. Having to retype the same import statements in hundreds of files is a PITA - and a good way to waste time and forget something when one has to fix these import statements (yes, even with the appropriate tediting tools). I wouldn't call such considerations nothing more than stylistic. Neither would I. But then, I would describe the existence of all those files as just the symptom - the real problem being the design that needs all of those hundreds of trivial classes in the first place. Granted, I know very little of Python. It may be the case that Python encourages the use of hundreds of little classes - and if that is the case, then I agree, storing each one in its own file would be rather absurd. I'm more accustomed to writing classes that tend to be larger - hundreds if not thousands of lines each, or more - and in that case, storing them one per file is a reasonable way to organize one's sources. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: String manipulation
On 4 Apr, 21:47, Alexander Schmolck [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] writes: Thank you very much, your code works perfectly! One thing I forgot: you might want to make the whitespace handling a bit more robust/general e.g. by using something along the lines of set_phrase.replace(' ', r'\w+') 'as Hi! Thanks again... But where must I insert this instruction? -- Marco Minerva, [EMAIL PROTECTED] http://blogs.ugidotnet.org/marcom -- http://mail.python.org/mailman/listinfo/python-list
Re: String manipulation
[EMAIL PROTECTED] writes: On 4 Apr, 21:47, Alexander Schmolck [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] writes: Thank you very much, your code works perfectly! One thing I forgot: you might want to make the whitespace handling a bit more robust/general e.g. by using something along the lines of set_phrase.replace(' ', r'\w+') Oops, sorry I meant r'\s+'. 'as Hi! Thanks again... But where must I insert this instruction? If you're sure the code already does what you want you can forget about my remark; I was thinking of transforming individual patterns like so: 'kindest regard' - r'kindest\w+regard', but it really depends on the details of your spec, which I'm not familiar with. For example you clearly want to do some amount of whitespace normalization (because you use ``.strip()``), but how much? The most extreme you could go is input = .join(file.read().split()) # all newlines, tabs, multiple spaces - In which case you don't need to worry about modifying the patterns to take care of possible whitespace variations. Another possibility is that you specify the patterns you want to replace as regexps in the file e.g. \bkind(?:est)?\b\s+regard(?:s)?\b \byours,\b ... In any case I'd suggest the following: think about what possible edge cases your input can contain and how you'd like to handle then; then write them up as unittests (use doctest or unittest and StringIO) and finally modify your code until it passes all the tests. Here are some examples of possible test patterns: - kindest regard, - kindest regard - kindest\tregard - kind regards - mankind regards other species as inferior - ... and please send your wife my kindest regards, Finally, if you're looking for a programming excercise you could try the following: rather than working on strings and using regexps, work on a stream of words (i.e. [kindest, regards, ...]) and write your own code to match sequences of words. 'as p.s. BTW, I overlooked the ``.readlines()`` before, but you don't need it -- files are iterable and you also want to hang on to the openend file object so that you can close it when you're done. -- http://mail.python.org/mailman/listinfo/python-list
Equivalent of PyEval_ThreadsInitialized for 2.3?
I ran into a problem with PyGILState_Release under Python 2.4.2, that forced me to call PyEval_InitThreads() in my extension module. 2.4.2 had a fix for that problem :It is now safe to call PyGILState_Release() before PyEval_InitThreads() (from the NEWS file). I can live with this call, but I was wondering if there isn't a better way. As PyEval_ThreadsInitialized is not available either, it seems there is no way to know if threads have been initialized. Thanks! -- Thomas -- http://mail.python.org/mailman/listinfo/python-list
Make a FREE Call Any Where Any Time
Make a FREE Call Any Where Any Time No Download, No Registration, Just Enter Mobile No. and Talk Click Below Link http://surl.in/PCOISCR283817GCJWJUK -- http://mail.python.org/mailman/listinfo/python-list
Storing of folder structure in SQL DB
Hi All! Can you please help me with the following problem: I need to store a copy of local folders structure in MySQL database. I have chosen the following table structure for that: | id | id_uplink | folder_name | id - unique property of each folder. id_uplink - id of upper level folder is stored here (for example: if id of c:\test is 1, than id_uplink of c:\test\python equals 1). folder_name - name of folder. You see, i dont want to store the path list, but the structure. The question is how to implement that in Python. I easily made it in C+ + using recursion. But, unfortunately, I can't figure it out how to make it in python using os.walk function (or can you recommend smth. else???). :( Though it looks quite simple, but anyway. Best Regards, Segei -- http://mail.python.org/mailman/listinfo/python-list
Re: Prevent Modification of Script?
ts-dev [EMAIL PROTECTED] wrote: Please correct any wrong assumptions that I might be making.. In a compiled application its not impossible to by pass the code.. but its not so easy. The huge amount of existing viruses targeting binaries seems to indicate that binary-only distribution does not deter attackers very well. Your assumption that the availability of source code makes your program a more vulnerable is likely wrong. The script could easily be modified to by-pass authentication and encryption could be disabled. Relying on authentication done at the client end is doomed to fail. Doing so is similar to asking people to put the lock in the door before opening it. It doesn't matter how good a lock is or how obscure the inside of the lock is if the lock isn't an integral part of the door; a burglar will simply bring his own lock, to which he of course has the key, and use that. Perhaps this is just a side-effect of being a scripted language - not a flaw, just me trying to use it for something its not well suited for. No. To be blunt, it is an effect of you not knowing enough about security. (Don't feel too bad about it. I have made similar mistakes myself, but after many years working with computer security I have managed to learn not to do *that* particular error again; I hope...) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden Life IS pain, highness. Anyone who tells ! bellman @ lysator.liu.se differently is selling something. ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list
Re: Welch essential for learning Tkinter well?
Dick Moores wrote: In a couple of places recently I've seen Brent Welch's _Practical Programming in Tcl Tk_ (http://tinyurl.com/ynlk8b) recommended for learning Tkinter well. So a couple of questions: 1) Is it really good for learning Tkinter, even though it doesn't mention Tkinter at all (in the 4th edition at least)? 2) If it is good for learning Tkinter, can I get by with a cheaper, used copy of the 3rd edition? Thanks, Dick Moores Probably better is to get Grayson (google Grayson Tkinter). It covers Tkinter -- Tcl/Tk mapping to sufficient extent for Tkinter proficiency. I have found the online Tcl/Tk documentation to fill in the gaps. Tkinter seems to me to have been created largely automatically and so has much of the documentation that maps it to Tcl/Tk. This begs the question, is anyone truly an expert in Tkinter? James -- http://mail.python.org/mailman/listinfo/python-list
Re: Storing of folder structure in SQL DB
On 5 Apr 2007 04:58:22 -0700, Sergei Minayev [EMAIL PROTECTED] wrote: Hi All! Can you please help me with the following problem: I need to store a copy of local folders structure in MySQL database. I have chosen the following table structure for that: | id | id_uplink | folder_name | id - unique property of each folder. id_uplink - id of upper level folder is stored here (for example: if id of c:\test is 1, than id_uplink of c:\test\python equals 1). folder_name - name of folder. You see, i dont want to store the path list, but the structure. The question is how to implement that in Python. I easily made it in C+ + using recursion. But, unfortunately, I can't figure it out how to make it in python using os.walk function (or can you recommend smth. else???). :( Though it looks quite simple, but anyway. Best Regards, os.walk should be more than sufficient in your case. You can navigate the directory structure and at each 'new' directory find its parents id and assign a new-id to this 'new' directory. An Example: import os root='/my/root/directory' id =0 tree={root:(-1, id)} id+=1 for path, dirs, files in os.walk(root): for dir in dirs: if not tree.has_key(path+'/'+dir): tree[path+'/'+dir]=(tree[path][1], id) id+=1 It stores ids as a tuple (parent_id, id) in a dictionary(tree). Should be straight forward to modify to your requirements. Also you can make the following code more efficient by saving/caching some lookups ! Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Not understanding absolute_import
I've been trying to use from absolute_import and it's giving me a hell of a headache. I can't figure out what it's *supposed* to do, or maybe rather, it doesn't seem to be doing what I *think* it's supposed to be doing. For example (actual example from my code, assume all files have from __future__ import absolute_import): /project /common guid.py (has class Guid) __init__.py (has from .guid import Guid) /relate relatable.py (has from .common import Guid and class Relatable(Guid)) __init__.py (has from .relatable import Relatable) Now, this all compiles ok and if I change the imports, it does not. So obviously this is working. However, I can't figure out *why* it works. In relatable.py, shouldn't that need to be from ..common import Guid? from . should import stuff from the current directory, from .foo should import stuff from module foo in the current directory. to go up a directory, you should need to use .. but if I do that, python complains that I've gone up too many levels. So, I don't understand... if the way I have above is correct, what happens if I put a common.py in the relate directory? How would you differentiate between that and the common package? I don't understand why .common works from relatable. According to the docs and according to what seems to be common sense, it really seems like it should be ..common. -Nate -- http://mail.python.org/mailman/listinfo/python-list
Re: Storing of folder structure in SQL DB
On 4/5/07, Amit Khemka [EMAIL PROTECTED] wrote: On 5 Apr 2007 04:58:22 -0700, Sergei Minayev [EMAIL PROTECTED] wrote: snip An Example: import os root='/my/root/directory' id =0 tree={root:(-1, id)} id+=1 for path, dirs, files in os.walk(root): for dir in dirs: if not tree.has_key(path+'/'+dir): tree[path+'/'+dir]=(tree[path][1], id) id+=1 It stores ids as a tuple (parent_id, id) in a dictionary(tree). Should be straight forward to modify to your requirements. Also you can make the following code more efficient by saving/caching some lookups ! use os.sep instead of '/' ! Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
So, here's a view from a guy who's not a python nut and has a long history of professional programming in other languages (C++, C, C#, Java) I think you're all going about this the wrong way. There's no reason to *always* have one class per file. However, there's also no reason to have 1600 lines of code and 50 classes in one file either. You talk about the changing file dance, but what about the scroll for 30 seconds dance? What about the six different conflicts in source control because everything's in one file dance? I think it doesn't matter how many classes and/or functions you have in one file as long as you keep files to a reasonable size. If you've ever worked on a medium to large-scale project using multiple developers and tens or hundreds of thousands of lines of code, then you know that keeping code separate in source control is highly important. If I'm working on extending one class and someone else is working on another class... it's much less of a headache if they're in separate files in source control. Then you don't have to worry about conflicts and merging. I think that's the number one benefit for short files (not necessarily just one class per file). My cutoff is around 500 lines per file. If a file goes much over that, it's really time to start looking for a way to break it up. Sure, if all your classes are 4 lines long, then by all means, stick them all in one file. But I don't think that's really any kind of valid stance to argue from. Sure, if you don't need organization, it doesn't matter what organization technique you use. But if you do need organization, it does matter. And I think one class per file is an acceptable way to go about it, especially when your classes tend to be over a couple hundred lines long. -Nate -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Fortran from Python
On Apr 4, 10:10 pm, Lenard Lindstrom [EMAIL PROTECTED] wrote: Mangabasi wrote: On Apr 4, 5:48 pm, Robert Kern [EMAIL PROTECTED] wrote: Mangabasi wrote: Would Python 2.5 work with Visual Studio 6.6? No. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco I will try the GCC then. It is a shame that I could not get calldll to work. It was very simple to use. I think I am making a mistake with the argument types but not sure. Thanks for your help, it is greatly appreciated. Did you try ctypes? from ctypes import * sample=cdll.sample.sample_ sample.restype=None sample.argtypes=[POINTER(c_int), POINTER(c_int), POINTER(c_double), POINTER(c_double)] e1 = c_int(0) e2 = c_int(0) ain = (c_double*3)(2.0, 3.0, 4.0) aout = (c_double*4)() sample(e1, e2, ain, aout) aout[:] [6.0, 9.0, 8.0, 12.0] e1.value 0 e2.value 0 I compile the SAMPLE example with mingw g77 3.4.5: g77 -shared -o sample.dll sample.for I had to take out the INTENT(OUT)s because g77 didn't like them. And SAMPLE became sample_ in the dll. Also note that argument passing to Fortran subroutines is strictly pass-by-reference. Thus the ain pointer. Lenard Lindstrom- Hide quoted text - - Show quoted text - Lenard, Now I tried it as you suggested. I did not install G77 yet. I tried it with the dll I already had. Something interesting happened: from ctypes import * sample=cdll.sample_dll.SAMPLE sample.restype=None sample.argtypes=[POINTER(c_int), POINTER(c_int), POINTER(c_double), POINTER(c_double)] sample.argtypes=[POINTER(c_int), POINTER(c_int), POINTER(c_double), POINTER(c_double)] e1 = c_int(-10) e2 = c_int(-10) ain = (c_double*3)(2.0, 3.0, 4.0) ain = (c_double*3)(2.0, 3.0, 4.0) aout = (c_double*4)() aout = (c_double*4)() sample(e1, e2, ain, aout) Traceback (most recent call last): File interactive input, line 1, in ? ValueError: Procedure called with not enough arguments (16 bytes missing) or wrong calling convention aout[:] [6.0, 9.0, 8.0, 12.0] I got an error message and the expected answer! Any guesses? -- http://mail.python.org/mailman/listinfo/python-list
Re: operator overloading
[EMAIL PROTECTED] wrote: On Apr 4, 4:55 pm, Terry Reedy [EMAIL PROTECTED] wrote: Ziga Seilnacht [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | This looks like a bug in Python. It works for all the other | operators: [SNIP] | i ** 3 | 74088 | | You should submit a bug report to the bug tracker: | |http://sourceforge.net/bugs/?group_id=5470 Nice test. I thought maybe __pow__ might be different in not having a reverse form, but indeed, int has an __rpow__ method. Before submitting, make sure that this does not work in 2.5, and then say so in the bug report. In fact, copy the version/system info that the interactive interpreter puts up when it starts. FWIW: Python 2.5 (r25:51908, Jan 21 2007, 03:10:25) [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on HOSTNAME_REDACTED Type help, copyright, credits or license for more information. class MyInt(int): ... __pow__ = int.__add__ ... i=MyInt(42) i**3 74088 Interestingly, Jython doesn't suffer from this drawback, which I suspect is due to special-casing of the __pow__ operator that was discussed quite recently on python-dev without anybody noticing this aspect of things. C:\jython2.2b1jython [...] class S(int): ... pass ... S.__pow__ = S.__add__ s = S(12) s ** 2 14 Note that it still doesn't work to override the *instance's* method. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
Steven Bethard typed: Or, just: In [1]: l = [0024,haha,0024] In [2]: filter(lambda x: x != 0024, l) Out[2]: ['haha'] Only if you want to make your code harder to read and slower:: Slower, I can see. But harder to read? There really isn't much use for filter() anymore. Even in the one place I would have expected it to be faster, it's slower:: $ python -m timeit -s L = ['', 'a', '', 'b'] filter(None, L) 100 loops, best of 3: 0.789 usec per loop $ python -m timeit -s L = ['', 'a', '', 'b'] [i for i in L if i] 100 loops, best of 3: 0.739 usec per loop I am getting varying results on my system on repeated runs. What about itertools.ifilter()? $ python -m timeit -s L = ['0024', 'haha', '0024']; import itertools itertools.ifilter(lambda i: i != '1024', L) 10 loops, best of 3: 5.37 usec per loop $ python -m timeit -s L = ['0024', 'haha', '0024'] [i for i in L if i != '0024'] 10 loops, best of 3: 5.41 usec per loop $ python -m timeit -s L = ['0024', 'haha', '0024'] [i for i in L if i] 10 loops, best of 3: 6.71 usec per loop $ python -m timeit -s L = ['0024', 'haha', '0024']; import itertools itertools.ifilter(None, L) 10 loops, best of 3: 4.12 usec per loop -- Ayaz Ahmed Khan Do what comes naturally now. Seethe and fume and throw a tantrum. -- http://mail.python.org/mailman/listinfo/python-list
Newbie - Boa Constructor, wxPython problem running Boa
Hi all I am a Newbie to the world of Python, wxPython and Boa. Please forgive me if there is a really obvious answer to this one. I am trying to get Python, wxPython and Boa all to install on my Windows XP machine. I have both Python and wxPython running. However, when I launch Boa I get an error message; An 'Error On Startup' dialog/message box is displayed that says; 'module' object has no attribute 'NotebookSizer' (Output on the console window is at the end of this message incase that helps.) I click OK and everything closes. I have the following setup; Python2.5 --- installed using python-2.5.msi from http://www.python.org/download/releases/2.5/ wxPython for Python2.5 installed using http://prdownloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.3.0-py25.exe Boa Constructor installed using boa-constructor-0.4.4.win32.exe Does anyone have any ideas, thoughts as to what the problem might be ? The only thing I'm wondering is that instead of installing on my c: drive in installed on my d: drive Thanks in advance Anbeyon BELOW IS THE OUTPUT IN THE CONSOLE WINDOW WHEN I LAUNCH BOA Starting Boa Constructor v0.4.4 importing wxPython reading user preferences running main... importing Models.Controllers importing Models.EditorModels importing Views importing Views.SourceViews D:\Python25\Lib\site-packages\boa-constructor\Views\STCStyleEditor.py: 59: Deprec ationWarning: The wxPython compatibility package is no longer automatically gene rated or actively maintained. Please switch to the wx package as soon as possib le. import wxPython.stc # needed names from 2.4 for config files importing Explorers.ExplorerNodes importing Companions importing PropertyEditors importing Companions.FrameCompanions importing Companions.WizardCompanions importing Companions.ContainerCompanions importing Companions.SizerCompanions -- http://mail.python.org/mailman/listinfo/python-list
Re: Storing of folder structure in SQL DB
In [EMAIL PROTECTED], Amit Khemka wrote: On 4/5/07, Amit Khemka [EMAIL PROTECTED] wrote: On 5 Apr 2007 04:58:22 -0700, Sergei Minayev [EMAIL PROTECTED] wrote: snip An Example: import os root='/my/root/directory' id =0 tree={root:(-1, id)} id+=1 for path, dirs, files in os.walk(root): for dir in dirs: if not tree.has_key(path+'/'+dir): tree[path+'/'+dir]=(tree[path][1], id) id+=1 […] use os.sep instead of '/' ! Or even better `os.path.join()` instead of building the strings with ``+``. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie - Boa Constructor, wxPython problem running Boa
On Apr 5, 8:32 am, Anbeyon [EMAIL PROTECTED] wrote: Hi all I am a Newbie to the world of Python, wxPython and Boa. Please forgive me if there is a really obvious answer to this one. I am trying to get Python, wxPython and Boa all to install on my Windows XP machine. I have both Python and wxPython running. However, when I launch Boa I get an error message; An 'Error On Startup' dialog/message box is displayed that says; 'module' object has no attribute 'NotebookSizer' (Output on the console window is at the end of this message incase that helps.) I click OK and everything closes. I have the following setup; Python2.5 --- installed using python-2.5.msi fromhttp://www.python.org/download/releases/2.5/ wxPython for Python2.5 installed usinghttp://prdownloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode... Boa Constructor installed using boa-constructor-0.4.4.win32.exe Does anyone have any ideas, thoughts as to what the problem might be ? The only thing I'm wondering is that instead of installing on my c: drive in installed on my d: drive Thanks in advance Anbeyon BELOW IS THE OUTPUT IN THE CONSOLE WINDOW WHEN I LAUNCH BOA Starting Boa Constructor v0.4.4 importing wxPython reading user preferences running main... importing Models.Controllers importing Models.EditorModels importing Views importing Views.SourceViews D:\Python25\Lib\site-packages\boa-constructor\Views\STCStyleEditor.py: 59: Deprec ationWarning: The wxPython compatibility package is no longer automatically gene rated or actively maintained. Please switch to the wx package as soon as possib le. import wxPython.stc # needed names from 2.4 for config files importing Explorers.ExplorerNodes importing Companions importing PropertyEditors importing Companions.FrameCompanions importing Companions.WizardCompanions importing Companions.ContainerCompanions importing Companions.SizerCompanions I haven't had much luck with Boa Constructor either. Here's a forum post on the same issue that might help you though: http://www.nabble.com/HOW-TO-START-BOAConstructor--t2545395.html You may want to try wxGlade, VisualWx, PythonCard, Dabo or Stani's Python Editor (SPE). Stani's, wxGlade, PythonCard and Dabo are mentioned often on the wxPython user's group. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Requirements For A Visualization Software System For 2010
Xah Lee wrote: In this essay, i give a list of requirements that i think is necessary for a software system for creating scientific visualization for the next decade (2007-2017). You may be interested in the F# programming language from Microsoft Research. This is a high-performance functional programming language with integrated Visual Studio support and an interactive mode (like a Mathematica notebook). The F# language is not distributed with any graphical tools except a couple of example programs. However, you can write a purely functional scene graph library and compiler in only 200 lines of code and then generate 2D and 3D graphics (spawned as separate visualizations from an interactive sessions) with the brevity of Mathematica and the robustness of ML. I have detailed exactly this functionality in the visualization chapter of my forthcoming book F# for Scientists: http://www.ffconsultancy.com/products/fsharp_for_scientists/ and I am so happy with the results that we are going to write another book specifically on the use of graphics from the F# language. Also, as .NET programs, F# programs can be executed on non-Windows platforms using tools like Mono. In the case of a DirectX-based visualization, you would probably need to write another back-end targetting OpenGL. -- Dr Jon D Harrop, Flying Frog Consultancy OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Fortran from Python
On Apr 4, 10:10 pm, Lenard Lindstrom [EMAIL PROTECTED] wrote: Mangabasi wrote: On Apr 4, 5:48 pm, Robert Kern [EMAIL PROTECTED] wrote: Mangabasi wrote: Would Python 2.5 work with Visual Studio 6.6? No. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco I will try the GCC then. It is a shame that I could not get calldll to work. It was very simple to use. I think I am making a mistake with the argument types but not sure. Thanks for your help, it is greatly appreciated. Did you try ctypes? from ctypes import * sample=cdll.sample.sample_ sample.restype=None sample.argtypes=[POINTER(c_int), POINTER(c_int), POINTER(c_double), POINTER(c_double)] e1 = c_int(0) e2 = c_int(0) ain = (c_double*3)(2.0, 3.0, 4.0) aout = (c_double*4)() sample(e1, e2, ain, aout) aout[:] [6.0, 9.0, 8.0, 12.0] e1.value 0 e2.value 0 I compile the SAMPLE example with mingw g77 3.4.5: g77 -shared -o sample.dll sample.for I had to take out the INTENT(OUT)s because g77 didn't like them. And SAMPLE became sample_ in the dll. Also note that argument passing to Fortran subroutines is strictly pass-by-reference. Thus the ain pointer. Lenard Lindstrom- Hide quoted text - - Show quoted text - A little bit of googling solved the problem. instead of sample = cdll.sample_dll.SAMPLE I used sample = windll.sample_dll.SAMPLE and now it seems to be working without error messages. Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: AW: Write to a binary file
On 2007-04-05, Thomi Aurel RUAG A [EMAIL PROTECTED] wrote: A simplified test programm to compare the function for opening a file i used (file()) and your suggested os.open() showed different behaviour. My simple testprogramm: --- START --- import os msg = chr(0x02) + chr(0x36) + chr(0x00) + chr(0x01) + chr(0x0a) + chr(0xb0) + chr(0x77) f = os.open('/dev/pytest', os.O_RDWR) os.write(f,msg) os.close(f) f = file('/dev/pytest', 'wb') f.write(msg) f.close() --- END --- The pytest device is a very simple device-driver which prints out (using printk()) the buffer delivered to the write function in a hexadecimal format (Pytest write [buffer in hex format]). The output was: --- Start --- Pytest write 02 36 00 01 0a b0 77 Pytest write 02 36 00 01 0a Pytest write b0 77 --- END --- I'm surprised that the normal file object's write method does that -- especially for a binary file. IMO, it's a bug when a binary file object treats 0x0a differently than other byte values. But, using the file object to read/write a device is probably not a good idea because of undefined behavior like that. File objects also do their own buffering, which I suspect isn't what you want. Using os.open will work for me, i wasn't aware of the existence of several file interaces. The os.file/open ones are just very thin wrappers around the corresponding libc routines. The file object contains it's own buffering and other features that will just get in the way of what you probably want to do. -- Grant Edwards grante Yow! .. here I am in 53 at B.C. and all I want is a visi.comdill pickle!! -- http://mail.python.org/mailman/listinfo/python-list
snippet manager idea
Hi. I am writing a opensource code snippet manager in python (pyqt4). The idea is that users can upload their snippets to remote subversion server, (if they choose) and add comments to existing snippets, vote for snippet deletion, add flags to snippets: (tested, working, not working... etc) The snippets are stored locally in a sqlite3 database. So far i have a working application that use a small Soap client/ server to upload snippets to a remote server. The client sends a dict to the server, the server writes the dict as a text file and adds it to the svn server. On the client a local svn repo is downloaded and parsed into the database. The client Ui has syntaxhighlighting(only cplusplus and python at the moment), an add snippet form, treewidget for snippet listing. My personal conserns are: individual snippet licensing I was wondering if anyone could comment on this idea. And perhaps come with some ideas. -- http://mail.python.org/mailman/listinfo/python-list
snippet manager idea
Hi. I am writing a opensource code snippet manager in python (pyqt4). The idea is that users can upload their snippets to remote subversion server, (if they choose) and add comments to existing snippets, vote for snippet deletion, add flags to snippets: (tested, working, not working... etc) The snippets are stored locally in a sqlite3 database. So far i have a working application that use a small Soap client/ server to upload snippets to a remote server. The client sends a dict to the server, the server writes the dict as a text file and adds it to the svn server. On the client a local svn repo is downloaded and parsed into the database. The client Ui has syntaxhighlighting(only cplusplus and python at the moment), an add snippet form, treewidget for snippet listing. My personal conserns are: individual snippet licensing I was wondering if anyone could comment on this idea. And perhaps come with some ideas. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Nate Finch a écrit : So, here's a view from a guy who's not a python nut and has a long history of professional programming in other languages (C++, C, C#, Java) I think you're all going about this the wrong way. There's no reason to *always* have one class per file. However, there's also no reason to have 1600 lines of code and 50 classes in one file either. Nope. What matters is to have - logical grouping of code units (high cohesion) - manageable files (not too much files, not too large files - of course the balance depends on the project as well). There are quite a few professional programmers here with experience on medium to large to huge projects with different languages, you know. -- http://mail.python.org/mailman/listinfo/python-list
Re: AW: Write to a binary file
Grant Edwards wrote: On 2007-04-05, Thomi Aurel RUAG A [EMAIL PROTECTED] wrote: A simplified test programm to compare the function for opening a file i used (file()) and your suggested os.open() showed different behaviour. My simple testprogramm: --- START --- import os msg = chr(0x02) + chr(0x36) + chr(0x00) + chr(0x01) + chr(0x0a) + chr(0xb0) + chr(0x77) f = os.open('/dev/pytest', os.O_RDWR) os.write(f,msg) os.close(f) f = file('/dev/pytest', 'wb') f.write(msg) f.close() --- END --- The pytest device is a very simple device-driver which prints out (using printk()) the buffer delivered to the write function in a hexadecimal format (Pytest write [buffer in hex format]). The output was: --- Start --- Pytest write 02 36 00 01 0a b0 77 Pytest write 02 36 00 01 0a Pytest write b0 77 --- END --- I'm surprised that the normal file object's write method does that -- especially for a binary file. IMO, it's a bug when a binary file object treats 0x0a differently than other byte values. But, using the file object to read/write a device is probably not a good idea because of undefined behavior like that. File objects also do their own buffering, which I suspect isn't what you want. Why not try to create a file object with bufsize = 0 ? for ex: - fo = file('/dev/pytest', 'wb', 0) fo.write() fo.close() -- Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED] http://heaven.branda.to/~thinker/GinGin_CGI.py -- http://mail.python.org/mailman/listinfo/python-list
Plugin architecture - how to do?
I'm making a program that consists of a main engine + plugins. Both are in Python. My question is, how do I go about importing arbitrary code and have it be able to use the engine's functions, classes, etc? First, here's how it's laid out on the filesystem: -mainstarterscript.py -engine -__init__.py -[whole bunch of files] -plugin -__init__.py -main.py -[whole bunch of files] So you'd execute the whole thing with ./mainstarterscript.py, which imports engine. Engine initializes, then executes plugin somehow. Plugin needs to be able to call functions in engine, and vice versa. Although various IPC methods would probably work, I think there's gotta be an easier and more straightforward way to do it. I use execfile to execute the plugin's __init__.py script. I insert some globals from engine into it so that __init__ can use them. __init__.py also imports plugin/main.py, which uses functions the engine functions, and so must import __init__.py. The problem is, when main imports __init__, the inserted globals aren't there, so it dies. So I've tried to make some globals in __init__ that simply map them to the engine's globals. Here's roughly how: #plugin/__init__.py engine_globals = {} if __name__ == '__builtin__': #run via execfile global engine_globals engine_globals = globals() #I don't really want all the globals, but in my real code I go through them one by one else: #imported from one of the other scripts in plugin dir. pass import main #among other things # end __init__.py # plugins/main.py import __init__ __init__.engine_globals.['some_function'](args) #do other stuff #end main.py #engine/__init__.py def some_function(args): pass sys.argv.append('plugins') execfile('plugins/__init__.py') When main.py imports plungin/__init__, it reinitializes engine_globals to {}, of course. But I can't think of a way not to initialize it to something, thus overwriting the original, because it needs to be in the namespace.. Essentially, I want a global to not reset itself if it's already set. So how do I go about doing this? Am I on the right track? Should I be __import__'ing plugins instead of execfile'ing them? Thanks, Nick -- http://mail.python.org/mailman/listinfo/python-list
[dateutil] bug(s) in dateutil.parser /dateutil.tz
Hi all, I'm having some problems with python-datetutil (which is a very, very nice tool, btw). Anybody knows where to adress these other than here? I tried reaching the author but don't seem to get through. Anyhow: 1. There's a bug in dateutil.parser you run into when you try to use a custom parserinfo. This patch fixes it: *** /data/pydev/DOWNLOADS/python-dateutil-1.1/dateutil/parser.py.ORIG Mon Nov 6 15:39:26 2006 --- /data/pydev/DOWNLOADS/python-dateutil-1.1/dateutil/parser.pyMon Nov 6 15:39:46 2006 *** *** 285,291 def __init__(self, info=parserinfo): if issubclass(info, parserinfo): ! self.info = parserinfo() elif isinstance(info, parserinfo): self.info = info else: --- 285,291 def __init__(self, info=parserinfo): if issubclass(info, parserinfo): ! self.info = info() elif isinstance(info, parserinfo): self.info = info else: 2. There is another bug in dateutil.tz in the tzfile class. This is a section of the Solaris MET zoninfo file $ zdump -v MET|grep 1982 MET Sun Mar 28 00:59:59 1982 UTC = Sun Mar 28 01:59:59 1982 MET isdst=0 MET Sun Mar 28 01:00:00 1982 UTC = Sun Mar 28 03:00:00 1982 MEST isdst=1 MET Sun Sep 26 00:59:59 1982 UTC = Sun Sep 26 02:59:59 1982 MEST isdst=1 MET Sun Sep 26 01:00:00 1982 UTC = Sun Sep 26 02:00:00 1982 MET isdst=0 Using this with tz.tzfile: from dateutil import tz import datetime tz.TZPATHS.insert(0, /usr/share/lib/zoneinfo) datetime.datetime(1982, 9, 25, 22, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) datetime.datetime(1982, 9, 26, 0, 59, tzinfo=tzfile('/usr/share/lib/zoneinfo/MET')) print datetime.datetime(1982, 9, 25, 22, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) 1982-09-26 00:59:00+02:00 datetime.datetime(1982, 9, 25, 23, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) datetime.datetime(1982, 9, 26, 2, 59, tzinfo=tzfile('/usr/share/lib/zoneinfo/MET')) print datetime.datetime(1982, 9, 25, 22, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) 1982-09-26 00:59:00+02:00 print datetime.datetime(1982, 9, 25, 23, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) 1982-09-26 02:59:00+01:00 datetime.datetime(1982, 9, 26, 0, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) datetime.datetime(1982, 9, 26, 3, 59, tzinfo=tzfile('/usr/share/lib/zoneinfo/MET')) print datetime.datetime(1982, 9, 26, 0, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) 1982-09-26 03:59:00+01:00 datetime.datetime(1982, 9, 26, 1, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) datetime.datetime(1982, 9, 26, 4, 59, tzinfo=tzfile('/usr/share/lib/zoneinfo/MET')) print datetime.datetime(1982, 9, 26, 1, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) 1982-09-26 04:59:00+01:00 datetime.datetime(1982, 9, 26, 2, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) datetime.datetime(1982, 9, 26, 3, 59, tzinfo=tzfile('/usr/share/lib/zoneinfo/MET')) print datetime.datetime(1982, 9, 26, 2, 59, 0, tzinfo=tz.tzutc()).astimezone(tz.gettz()) 1982-09-26 03:59:00+01:00 Note how the MET local time is wrong at 23:59UTC, 0:59UTC and 01:59UTC. I've looked at the code but currently don't really understand how the default tzfinfo.fromutc implementation, as quoted in the python datetime documentation, is supposed to work in the first place. Any ideas? Cheers, Holger -- Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Java
On Apr 5, 7:18 am, Steve Holden [EMAIL PROTECTED] wrote: Sreelatha G wrote: Hi I am new to python .I need your help in solving my problem. Is there any way to call python files in a java file .How is it possible? Your other option is to utilize a system exec call, and try and trap the results. -- http://mail.python.org/mailman/listinfo/python-list
AttributeError: 'tuple' object has no attribute 'encode'
Hi, I'm trying to build a SQL string sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid, ag, self.data[parent][child]['results']['test']) It raises this error: AttributeError: 'tuple' object has no attribute 'encode' Some of the variables are unicode (test and ag) - is that what is causing this error? What do I need to do to make it work? Thanks! Erik -- http://mail.python.org/mailman/listinfo/python-list
Review/commit patch?
How long does it take for a patch at the Python SF tracker to be reviewed and/or committed? I am unfamiliar with how the process works. (I originally submitted a bug report, then figured out how to patch the item in question, and subsequently submitted a patch.) -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we make a local variable in a function as global variable???
sairam wrote: I have some local variables defined in one method and Can I make those variables as global variables? If so , can any one explain me how can I do that Thanks, Sairam See: http://www.faqs.org/docs/diveintopython/dialect_locals.html When a line of code asks for the value of a variable x, Python will search for that variable in all the available namespaces, in order: 1. local namespace - specific to the current function or class method. If the function defines a local variable x, or has an argument x, Python will use this and stop searching. 2. global namespace - specific to the current module. If the module has defined a variable, function, or class called x, Python will use that and stop searching. 3. built-in namespace - global to all modules. As a last resort, Python will assume that x is the name of built-in function or variable. -- http://mail.python.org/mailman/listinfo/python-list
Re: Welch essential for learning Tkinter well?
James Stroud wrote: This begs the question, is anyone truly an expert in Tkinter? Frederick Lundh is, if anyone is. http://www.pythonware.com/library/tkinter/introduction/index.htm (outdated) http://effbot.org/tkinterbook/ (new but incomplete) Coming to Python from a Tcl/Tk background, I find Tkinter to be pretty compatible with what I know about Tk: usually it's just a matter of figuring out how to translate the code. Having a Tk background from Tcl is also helpful in using some of the more advanced Tcl/Tk stuff that has been wrapped in Python, but isn't much documented or widely used, such as BWidgets. From that standpoint, the Welch book is a useful resource, though probably not essential. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Review/commit patch?
[Kevin Walzer] How long does it take for a patch at the Python SF tracker to be reviewed and/or committed? I am unfamiliar with how the process works. (I originally submitted a bug report, then figured out how to patch the item in question, and subsequently submitted a patch.) Which bug report and patch is yours? Raymond -- http://mail.python.org/mailman/listinfo/python-list
embedded python project
selamlar; Türkiyeden selamlar. Grubunuza yeni katıldım. Pythonu çok merak ediyorum.Yüksek lisans projemi python ile yapmak istiyorum. Gömülü sistemler üzerine bir konu tasarlamayı düşünüyorum. Basit olursa sevinirim. Önerilerinizi bekliyorum. Şimdiden teşekkürler. Hi from Turkey. I am new in your grub. I wonder The Python. I want to do master project with python.I am thinking about to design an embedded system. ii will be happy if it be a simple. I wait your recommends. thanks for now. Mehmet S. YILDIRIM Bucak/Burdur Teacher of Computer || Bilgisayar Öğretmeni Isparta Süleyman Demirel University || Süleyman Demirel Üniversitesi Institute of Sciences || Fen Bilimleri Enstitüsü Departman of Electronic and Computer || Elektronik ve Bilgisayar Bölümü Master Student || Yüksek Lisans Öğrencisi Türkiye -- http://mail.python.org/mailman/listinfo/python-list
embedded python project
selamlar; Türkiyeden selamlar. Grubunuza yeni katıldım. Pythonu çok merak ediyorum.Yüksek lisans projemi python ile yapmak istiyorum. Gömülü sistemler üzerine bir konu tasarlamayı düşünüyorum. Basit olursa sevinirim. Önerilerinizi bekliyorum. Şimdiden teşekkürler. Hi from Turkey. I am new in your grub. I wonder The Python. I want to do master project with python.I am thinking about to design an embedded system. ii will be happy if it be a simple. I wait your recommends. thanks for now. Mehmet S. YILDIRIM Bucak/Burdur Teacher of Computer || Bilgisayar Öğretmeni Isparta Süleyman Demirel University || Süleyman Demirel Üniversitesi Institute of Sciences || Fen Bilimleri Enstitüsü Departman of Electronic and Computer || Elektronik ve Bilgisayar Bölümü Master Student || Yüksek Lisans Öğrencisi Türkiye -- http://mail.python.org/mailman/listinfo/python-list
Re: Review/commit patch?
Raymond Hettinger wrote: [Kevin Walzer] How long does it take for a patch at the Python SF tracker to be reviewed and/or committed? I am unfamiliar with how the process works. (I originally submitted a bug report, then figured out how to patch the item in question, and subsequently submitted a patch.) Which bug report and patch is yours? Raymond bug: https://sourceforge.net/tracker/?func=detailatid=105470aid=1691411group_id=5470 patch: https://sourceforge.net/tracker/?func=detailatid=305470aid=1693258group_id=5470 -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: snippet manager idea
On Apr 5, 9:41 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi. I am writing a opensource code snippet manager in python (pyqt4). The idea is that users can upload their snippets to remote subversion server, (if they choose) and add comments to existing snippets, vote for snippet deletion, add flags to snippets: (tested, working, not working... etc) The snippets are stored locally in a sqlite3 database. So far i have a working application that use a small Soap client/ server to upload snippets to a remote server. The client sends a dict to the server, the server writes the dict as a text file and adds it to the svn server. On the client a local svn repo is downloaded and parsed into the database. The client Ui has syntaxhighlighting(only cplusplus and python at the moment), an add snippet form, treewidget for snippet listing. My personal conserns are: individual snippet licensing I was wondering if anyone could comment on this idea. And perhaps come with some ideas. You could have some kind of legalese for them to read and accept (i.e. electronically sign), preferably something that is an open source license agreement like Python's or BSD or maybe that new Creative Commons thing. Regardless, you need to let the coders know what their rights are one way or the other. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: way to extract only the message from pop3
flit wrote: Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? As mentioned before, you should use module email: #!/usr/bin/env python import poplib import email import os import sys import string PROVIDER = pop.YourMailProvider.de USER = YourUserName PASSWORD = YourPassword try: client = poplib.POP3(PROVIDER) except: print Error: Provider not found. sys.exit(1) client.user(USER) client.pass_(PASSWORD) nrof_mails = len(client.list()[1]) for i in range(nrof_mails): lines = client.retr(i + 1)[1] mailstring = string.join(lines, \n) blockit = 0 msg = email.message_from_string(mailstring) for part in msg.walk(): if part.get_content_maintype() == text and blockit == 0: blockit = 1 mycontent = part.get_payload() mycontent = mycontent.decode(quopri_codec) print mycontent print client.quit() See You H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service and pyc files
Have you tried the subprocess module for this rather than os.system? You might be able to pipe errors to a file with it. You might be able to use the traceback module for more verbose error catching too. Okay, I'm tried this instead of os.system: def dumpexc(e): import sys,traceback,StringIO f = StringIO.StringIO('') ei = sys.exc_info() traceback.print_exception(ei[0],ei[1],ei[2],file=f) return f.getvalue() def spawn(): # ... setup mydir here os.chdir(mydir) prog = os.path.join(mydir,Application.py) params = [sys.executable,prog] logger.info(Spawing %s,str(params)) fout = file(os.path.join(mydir,'errorlog.txt'),'wb+') try: p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), stderr=fout.fileno()) except Exception, e: logger.error(dumpexc(e)) return -1 retcode = p.wait() logger.info(Subprocess exited, return code: %d,retcode) fout.close() return retcode When I call spawn() from a service, this is written into the logfile: 2007-04-05 17:52:53,828 INFO .Spawner Spawing ['C:\\Python25\\lib\\site-packages\\win32\\PythonService.exe', 'T:\\Python\\Projects\\Test\\Application.py'] 2007-04-05 17:52:53,828 ERROR .Spawner Traceback (most recent call last): File T:\Python\Projects\Test\Processor.py, line 40, in spawn_downloader p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), stderr=fout.fileno()) File C:\Python25\lib\subprocess.py, line 586, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) File C:\Python25\lib\subprocess.py, line 681, in _get_handles p2cread = self._make_inheritable(p2cread) File C:\Python25\lib\subprocess.py, line 722, in _make_inheritable DUPLICATE_SAME_ACCESS) TypeError: an integer is required errorlog.txt is - of course - becomes an empty file. When I call spawn() from an application, it works just fine. Any ideas? Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'tuple' object has no attribute 'encode'
On Apr 5, 11:41 am, [EMAIL PROTECTED] wrote: On Apr 5, 10:31 am, erikcw [EMAIL PROTECTED] wrote: Hi, I'm trying to build a SQL string sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid, ag, self.data[parent][child]['results']['test']) It raises this error: AttributeError: 'tuple' object has no attribute 'encode' Some of the variables are unicode (test and ag) - is that what is causing this error? What do I need to do to make it work? Thanks! Erik It sounds like you're not calling the encode method correctly. But it's hard to say when you didn't include that bit of code. You may need to check your database's docs to make sure it accepts unicode strings and if so, what types (utf-8, 16, 32). See this post for a similar problem: http://lists.modevia.com/archives/py-transports/2005-December/001719 and this link details tuple usage:http://www.faqs.org/docs/diveintopython/odbchelper_tuple.html Mike I tried adding .encode(utf-8) onto each of the variables in the tuple, but that didn't seem to help. The error just changes slightly to AttributeError: 'long' object has no attribute 'encode' I'm using Mysql. -- http://mail.python.org/mailman/listinfo/python-list
Re: Prevent Modification of Script?
[EMAIL PROTECTED] wrote: Just throw out the .py files and let it run on the .pyc's alone. Which are very easily decompilable. :-) -- Lawrence, oluyede.org - neropercaso.it It is difficult to get a man to understand something when his salary depends on not understanding it - Upton Sinclair -- http://mail.python.org/mailman/listinfo/python-list
Project organization and import redux
I apologize for bringing up something that's a month dead. But, I've been reading through the recent archives and came across this discussion, and want to make sure I understand a particular about the interactive prompt. Martin Unsal martinunsal at gmail.com wrote: I'm perfectly well aware that I'm not going to be able to reload a widget in the middle of a running GUI app, for example. I'm not looking for gotcha free, I'll settle for minimally useful. Here's an analogy. In C, you can do an incremental build and run your modified application without having to first reboot your computer. In Python, where reload() is essentially the incremental build process, and the interpreter is essentially a virtual machine, you guys are saying that my best option is to just reboot the virtual machine to make sure I have a clean slate. It may be the path of least resistance, but to say that it is necessary or inevitable is 1960s mainframe thinking. Yes, the interpreter is a virtual machine. But the interactive prompt is not a command line in that virtual machine. Instead, it is the statement that is about to be executed by a program running in that virtual machine. When you type a statement and press enter, that statement is executed as the next line of the program. It's analogous to using a debugger to step through a C program line by line, except you're providing those lines immediately rather than having to write and compile them in advance. Restarting the interactive prompt isn't like rebooting the computer; it's just restarting a program that is running on the computer. At worst, the interpreter is a computer that automatically shuts down when the program running on it ends. Is this a valid understanding of the workings of the interactive prompt, or am I way off base? --- -Bill Hamilton [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Support SSL for Solaris 10
Hi all, Last time I installed Python 2.5 by default, it didn't support SSL. When I tried to use HTTPS, the following error occured: AttributeError: 'module' object has no attribute 'ssl' In README file: -- (a) the band-aid fix is to link the _socket module statically rather than dynamically (which is the default). To do this, run ./configure --with-threads=no including any other options you need (--prefix, etc.). Then in Modules/Setup uncomment the lines: #SSL=/usr/local/ssl #_socket socketmodule.c \ # -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ # -L$(SSL)/lib -lssl -lcrypto and remove local/ from the SSL variable. Finally, just run make! -- I followed these steps. However I am puzzled with: remove local/ from the SSL variable I tried several cases such as /usr/ssl, ~/local/ssl, /usr/local/ ssl All failed in building ssl module. How to solve it? Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Review/commit patch?
[Kevin Walzer] How long does it take for a patch at the Python SF tracker to be reviewed and/or committed? I am unfamiliar with how the process works. (I originally submitted a bug report, then figured out how to patch the item in question, and subsequently submitted a patch.) Which bug report and patch is yours? bug:https://sourceforge.net/tracker/?func=detailatid=105470aid=1691411;... patch:https://sourceforge.net/tracker/?func=detailatid=305470aid=1693258;... I've assigned these to Ronald Oussoren who is maintaining the MacOS support for IDLE. The timing of the response pretty much depends on his availability and interest. If we get close to the Py2.5.2 release (the 2.5.1 branch is already frozen) and there has been no action, then re-assign to me and bump-up the priority. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'tuple' object has no attribute 'encode'
erikcw wrote: I'm trying to build a SQL string sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid, ag, self.data[parent][child]['results']['test']) This makes a tuple, though: the first element is the SQL string; the second element contains a tuple of parameters. It raises this error: AttributeError: 'tuple' object has no attribute 'encode' What does? I imagine that this error comes from a call to a cursor object's execute method. In other words, I imagine that you may be doing something like this: cursor.execute(*sql) Not that there would be anything obviously wrong with that: you are keeping the string and its parameters separate, after all. However, you'd have to show us the full error (a traceback including lines of code from the database library) for us to really see what's going on. Some of the variables are unicode (test and ag) - is that what is causing this error? What do I need to do to make it work? Show us more of the error! ;-) Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service and pyc files
When I call spawn() from a service, this is written into the logfile: 2007-04-05 17:52:53,828 INFO .Spawner Spawing ['C:\\Python25\\lib\\site-packages\\win32\\PythonService.exe', 'T:\\Python\\Projects\\Test\\Application.py'] 2007-04-05 17:52:53,828 ERROR .Spawner Traceback (most recent call last): File T:\Python\Projects\Test\Processor.py, line 40, in spawn_downloader p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), stderr=fout.fileno()) File C:\Python25\lib\subprocess.py, line 586, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) File C:\Python25\lib\subprocess.py, line 681, in _get_handles p2cread = self._make_inheritable(p2cread) File C:\Python25\lib\subprocess.py, line 722, in _make_inheritable DUPLICATE_SAME_ACCESS) TypeError: an integer is required Okay, here is what I learnt: 1. subprocess.Popen cannot redirect stderr and stdout when called from a win32 service. This is not documented, and makes debugging almost impossible. 2. sys.executable becomes pythonservice.exe inside a win32 service. If I specify rC:\Python25\python.exe instead of sys.executable, and if I do not specify stdout and stderr parameters for subprocess.Popen, then my program starts to work. Here arises the question: how can I find rC:\Python25\python.exe from inside a win32 service? Can I use this: interpreter = os.path.join( os.path.split(sys.executable),[0], os.sep,os.sep,os.sep,'Python.exe' ) Is it safe? Please advise. Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Why NOT only one class per file?
Nate Finch wrote: I think you're all going about this the wrong way. There's no reason to *always* have one class per file. However, there's also no reason to have 1600 lines of code and 50 classes in one file either. It's really an operating system thing. We think of programs as living in text files, manipulated by programs which are basically text editors. Python has that implicit assumption. There have been systems that didn't work that way, in which the program source was manipulated within the language environment, in a more structured fashion. Smalltalk, LISP, and (wierdly) Forth environments have been built that way. But it never really caught on. The assumption that programs are text files is deeply embedded in programming culture, so deeply that it's seldom questioned. Programs are the last refuge of non-rich media. You can't even embed an image in your program; it has to be in some completely separate file. Interestingly, PHP breaks this model; PHP programs are web pages. They may be on to something. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service and pyc files
En Thu, 05 Apr 2007 13:00:52 -0300, Laszlo Nagy [EMAIL PROTECTED] escribió: p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), stderr=fout.fileno()) When I call spawn() from a service, this is written into the logfile: 2007-04-05 17:52:53,828 INFO .Spawner Spawing ['C:\\Python25\\lib\\site-packages\\win32\\PythonService.exe', 'T:\\Python\\Projects\\Test\\Application.py'] 2007-04-05 17:52:53,828 ERROR .Spawner Traceback (most recent call last): File T:\Python\Projects\Test\Processor.py, line 40, in spawn_downloader p = subprocess.Popen(params, bufsize=1, stdout=fout.fileno(), stderr=fout.fileno()) File C:\Python25\lib\subprocess.py, line 586, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) File C:\Python25\lib\subprocess.py, line 681, in _get_handles p2cread = self._make_inheritable(p2cread) File C:\Python25\lib\subprocess.py, line 722, in _make_inheritable DUPLICATE_SAME_ACCESS) TypeError: an integer is required With a bit of guessing, I think I've found what's happening. Since you don't provide a value for stdin, None is used. Inside subprocess.py, method _get_handles, line 670, GetStdHandle *may* return None; in that case _make_inheritable fails. If you print the value of p2cread in line 670 I bet you'll get None. The fix is to test for None in _make_inheritable (line 720): if handle is not None: return DuplicateHandle(...) (else return None, implicit) When I call spawn() from an application, it works just fine. Any ideas? According to http://msdn2.microsoft.com/en-us/library/ms683231.aspx GetStdHandle may return NULL (translated to None in Python) when invoked from a service with no redirected standard handles. From an application, there is no problem. Please try the simple fix above to comfirm it works; I'll submit a patch if that's the case. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve error
On Apr 5, 5:20 am, Steve Holden [EMAIL PROTECTED] wrote: 7stud wrote: On Apr 4, 10:22 pm, [EMAIL PROTECTED] wrote: how did you generate aaa.txt? Ok, I got it to work by supplying a filename that didn't previously exist. Neither the book I am reading, Beginning Python: From Novice to Professional nor the book I am using as a reference, Python in Nutshell, happens to mention that important fact. It seems to make sense that you have to open a file as writable in order to be able to change its contents, though, doesn't it? My text file was writable. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service and pyc files
En Thu, 05 Apr 2007 13:50:16 -0300, Laszlo Nagy [EMAIL PROTECTED] escribió: 1. subprocess.Popen cannot redirect stderr and stdout when called from a win32 service. This is not documented, and makes debugging almost impossible. Without the patch menctioned in my previous message, you must redirect all stdin, stdout AND stderr (because the child cannot inherit the handles from the parent service, as a service has no standard handles assigned usually) or none of them. 2. sys.executable becomes pythonservice.exe inside a win32 service. If I specify rC:\Python25\python.exe instead of sys.executable, and if I do not specify stdout and stderr parameters for subprocess.Popen, then my program starts to work. Here arises the question: how can I find rC:\Python25\python.exe from inside a win32 service? Can I use this: interpreter = os.path.join( os.path.split(sys.executable),[0], os.sep,os.sep,os.sep,'Python.exe' ) I think you meant to write: os.path.join(os.path.split(sys.executable)[0], os.pardir, os.pardir, os.pardir, 'python.exe') pythonservice.exe is so Windows-specific that using os.pardir only makes the code harder to read. Anyway I'd use os.path.join(sys.prefix, 'python.exe') (sys.prefix would be C:\Python25 in your case) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'tuple' object has no attribute 'encode'
On Apr 5, 12:37 pm, Paul Boddie [EMAIL PROTECTED] wrote: erikcw wrote: I'm trying to build a SQL string sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid, ag, self.data[parent][child]['results']['test']) This makes a tuple, though: the first element is the SQL string; the second element contains a tuple of parameters. It raises this error: AttributeError: 'tuple' object has no attribute 'encode' What does? I imagine that this error comes from a call to a cursor object's execute method. In other words, I imagine that you may be doing something like this: cursor.execute(*sql) Not that there would be anything obviously wrong with that: you are keeping the string and its parameters separate, after all. However, you'd have to show us the full error (a traceback including lines of code from the database library) for us to really see what's going on. Some of the variables are unicode (test and ag) - is that what is causing this error? What do I need to do to make it work? Show us more of the error! ;-) Paul Here is the full error: (sorry) Traceback (most recent call last): File /home/erik/Desktop/wa.py, line 178, in ? curHandler.walkData() File /home/erik/Desktop/wa.py, line 91, in walkData sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid.encode(utf-8), ag, self.data[parent][child]['results']['test']) AttributeError: 'long' object has no attribute 'encode' sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid.encode(utf-8), ag, self.data[parent][child]['results']['test']) self.cursor.execute(sql) Now, I changed all ofth e %i/%d to %s, and changed self.cursor.execute(sql) to self.cursor.execute(*sql) and it seems to be working now! -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Fortran from Python
Mangabasi wrote: A little bit of googling solved the problem. instead of sample = cdll.sample_dll.SAMPLE I used sample = windll.sample_dll.SAMPLE and now it seems to be working without error messages. Thanks a lot. I remember someone on the ctypes mailing list mentioning that g77 uses the C calling convention for exported functions. Other compilers might default to standard calls. At least with ctypes one can tinker with calling convention and function arguments to make a call work. Lenard -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'tuple' object has no attribute 'encode'
erikcw wrote: Hi, I'm trying to build a SQL string sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid, ag, self.data[parent][child]['results']['test']) I am guessing you want the string formatting operator here: sql = ... % (cid, ...) The comma creates a tuple. -- http://mail.python.org/mailman/listinfo/python-list
Objects, lists and assigning values
Hello, while trying to learn how to program using objects in python (up to now simple scripts were sufficient for my needs) I stumbled over the a problem while assigning values to an object. The following piece of code shows what I intend to do: ---snip--- class new_class(object): def __init__( self, internal_list=[]): self.internal_list= internal_list external_list=[[b*a for b in xrange(1,5)] for a in xrange(1,5)] print external_list first_collection=[new_class() for i in xrange(4)] temporary_list=[[] for i in xrange(4)] for i in xrange(4): for j in xrange(4): temporary_list[i].append(external_list[i][j]) first_collection[i].internal_list=temporary_list[i] #Now everything is as I want it to be: for i in xrange(4): print first_collection[i].internal_list #Now I tried to get the same result without the temporary #variable: second_collection=[new_class() for i in xrange(4)] for i in xrange(4): for j in xrange(4): second_collection[i].internal_list.append(external_list[i][j]) #Which obviously leads to a very different result: for i in xrange(4): print second_collection[i].internal_list ---snip--- Can someone explain to me, what's happening here and why the two approaches do not lead to the same results? Thanks in Advance. Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 -- http://mail.python.org/mailman/listinfo/python-list
Antigen Notification: Antigen found a message matching a filter
Microsoft Antigen for Exchange found a message matching a filter. The message is currently Purged. Message: Python_list Digest_ Vol 43_ Issue 83 Filter name: KEYWORD= spam: Timing Sent from: [EMAIL PROTECTED] Folder: SMTP Messages\Inbound And Outbound Location: ITURAN/First Administrative Group/VITORIA -- http://mail.python.org/mailman/listinfo/python-list
Python Instructor Needed
We have an immediate need for a four- or five-day Intro to Python course in the Midwest United States for late May/early June 2007. We are looking for a Python instructor with outstanding credentials and a proven track record. You would be teaching this course as a third- party contractor. If you are interested, please contact Abbey immediately at 978 823 0130. We will also need the following information: 1. Your daily rate (US$). 2. Your availability. 3. Please indicate which materials you would use for the course and the price of the materials. -- http://mail.python.org/mailman/listinfo/python-list
Re: AW: Write to a binary file
En Thu, 05 Apr 2007 11:38:06 -0300, Grant Edwards [EMAIL PROTECTED] escribió: On 2007-04-05, Thomi Aurel RUAG A [EMAIL PROTECTED] wrote: The output was: --- Start --- Pytest write 02 36 00 01 0a b0 77 Pytest write 02 36 00 01 0a Pytest write b0 77 --- END --- I'm surprised that the normal file object's write method does that -- especially for a binary file. IMO, it's a bug when a binary file object treats 0x0a differently than other byte values. A write() call on a Python file object gets directly translated into a fwrite() C runtime library call. Any special handling is made inside that library. But, using the file object to read/write a device is probably not a good idea because of undefined behavior like that. File objects also do their own buffering, which I suspect isn't what you want. I agree - using os.open, os.write etc. appears to be the right thing here. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
tkinter canvas
I have made drawing area and few butons. How can I make when i click my fill button that later when i click on oval oval gets filled with chousen color? -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service and pyc files
1. subprocess.Popen cannot redirect stderr and stdout when called from a win32 service. This is not documented, and makes debugging almost impossible. Without the patch menctioned in my previous message, you must redirect all stdin, stdout AND stderr (because the child cannot inherit the handles from the parent service, as a service has no standard handles assigned usually) or none of them. The truth is that subprocess.Popen raises an exception when I try to redirect stdin,stdout or stderr. If I do not redirect any of them, then everything works fine for me. (Well, of course standard output is lost.) interpreter = os.path.join( os.path.split(sys.executable),[0], os.sep,os.sep,os.sep,'Python.exe' ) I think you meant to write: os.path.join(os.path.split(sys.executable)[0], os.pardir, os.pardir, os.pardir, 'python.exe') Yes, sorry. pythonservice.exe is so Windows-specific that using os.pardir only makes the code harder to read. Anyway I'd use os.path.join(sys.prefix, 'python.exe') (sys.prefix would be C:\Python25 in your case) Oh, I did not know about that variable. Thanks! :-) Best, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: AW: Write to a binary file
On 2007-04-05, Thinker [EMAIL PROTECTED] wrote: --- START --- import os msg = chr(0x02) + chr(0x36) + chr(0x00) + chr(0x01) + chr(0x0a) + chr(0xb0) + chr(0x77) f = os.open('/dev/pytest', os.O_RDWR) os.write(f,msg) os.close(f) f = file('/dev/pytest', 'wb') f.write(msg) f.close() --- END --- I just ran that on my system (2.4.3), and both versions do a signle write. The pytest device is a very simple device-driver which prints out (using printk()) the buffer delivered to the write function in a hexadecimal format (Pytest write [buffer in hex format]). The output was: --- Start --- Pytest write 02 36 00 01 0a b0 77 Pytest write 02 36 00 01 0a Pytest write b0 77 --- END --- I'm surprised that the normal file object's write method does that -- especially for a binary file. IMO, it's a bug when a binary file object treats 0x0a differently than other byte values. But, using the file object to read/write a device is probably not a good idea because of undefined behavior like that. File objects also do their own buffering, which I suspect isn't what you want. Why not try to create a file object with bufsize = 0 ? for ex: - fo = file('/dev/pytest', 'wb', 0) fo.write() fo.close() That's worth a try, but I can't get the normal method to fail... -- Grant Edwards grante Yow! I selected E5... but at I didn't hear Sam the Sham visi.comand the Pharoahs! -- http://mail.python.org/mailman/listinfo/python-list
Re: Objects, lists and assigning values
En Thu, 05 Apr 2007 14:13:43 -0300, Manuel Graune [EMAIL PROTECTED] escribió: class new_class(object): def __init__( self, internal_list=[]): self.internal_list= internal_list All your instances share the *same* internal list, because default arguments are evaluated only once (when the function is defined) The usual way is to write: class new_class(object): def __init__(self, internal_list=None): if internal_list is None: internal_list = [] self.internal_list= internal_list See http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows service and pyc files
With a bit of guessing, I think I've found what's happening. Since you don't provide a value for stdin, None is used. Inside subprocess.py, method _get_handles, line 670, GetStdHandle *may* return None; in that case _make_inheritable fails. If you print the value of p2cread in line 670 I bet you'll get None. The fix is to test for None in _make_inheritable (line 720): if handle is not None: return DuplicateHandle(...) (else return None, implicit) When I call spawn() from an application, it works just fine. Any ideas? According to http://msdn2.microsoft.com/en-us/library/ms683231.aspx GetStdHandle may return NULL (translated to None in Python) when invoked from a service with no redirected standard handles. From an application, there is no problem. Please try the simple fix above to comfirm it works; I'll submit a patch if that's the case. Yes, it fixed the problem. Please submit the patch. Thank you! Laszlo -- http://mail.python.org/mailman/listinfo/python-list
PyDispatcher question
Hi all, Hopefully someone can help me. I am fairly new to Python, and I am looking into PyDispatcher. I am familiar with the C++ sigslot variant, and I wonder how similar PyDispatches is. I run in to the following 'problem' (pseudo code, untested here) import pydispatch.dispatcher class A: def __init__(self): dispatcher.connect(self.someSignal, signal = 1) def someSignal(self): print 'Hello world' obj = A() # send a trial signal dispatcher.send(signal = 1) Hello world # now for the catch, how to clean up? # if I do: obj = None # clean up dispatcher.send(signal = 1) Hello world The object still extists... Which is logical, the method is still bound to the signal, and the object itself is not yet deleted. Is there an elegant way to delete the object and let the signal unbind itself? Or do I need to do this in the destructor of the object? AFAIK there is no real destructor in Python? Do I need to do it differently? Or is there a better signal mechanism to use? Any help is appreciated! - Jorgen -- http://mail.python.org/mailman/listinfo/python-list
Re: Prevent Modification of Script?
If you are *really* worried about the database being attacked and edited, encrypt it by private key: require that the user set a password and use that password every time that s/he accesses the database. I am afraid that you cannot really prevent the database from being deleted completely, but you can stop it from being edited such that it actually contains readable information. I am repeating what someone else has already said, but how likely is it that someone will attack your program specifically with malware? The very worst that can happen is that someone replaces your application completely, and there is no way to prevent this. There are probably much better things to replace than your program (such as OS files that are run during startup). Perhaps now would be a good time for me to begin my rant about how security has all been gone about the wrong way within computers (network security is just fine, with the exception of WEP). Part I: the problem Firstly, it is possible to bypass all security in Windows (I only talk about windows because I have not used any other OS enough to know the security flaws, not because they are any better). This is because Windows runs on top of the bios, which runs on top of the hardware. Making calls to the bios or the hardware directly therefore bypasses Windows, and allows you to do anything that Windows might prevent you from doing (this is all theoretical, by the way). I have actually managed to log into other users of whom I do not know the password in Windows 98. It is quite simple, in fact I discovered it by accident. If that user was logged in last, and shut down the computer, you (1) start up the computer, (2) type in a few bogus passwords in the login screen and try to login with them, and (3) clear the password field, and press login. You will login as that previous user. Part II: what is wrong with this The OS should not be inhibiting users or programs from doing things. These things can be done anyway by bypassing it. This is a security flaw that can be fixed (and will be in a computer that I am in the process of designing: don't expect it to be on the market any time soon). Current security is like security written in javascript (client side). The browser checks a form against source code which is available to the user to see if the password is correct, and then goes to a page, the URL of which is also available to the user in the source code. My planned security is more like security written in php (server side). The browser submits the form, and the server checks it against a database, choosing the location which the browser goes to based on that. The location to which the browser is sent was not previously available to the user in the source code. It was safely hidden away in a remote database for which the user had no access. Part III: the solution Since I will be including the solution in my design for a computer, I can only vaguely explain it. When programs run, they will be given a password. When the program tries to connect to a piece of hardware, they must securely pass the password to that hardware. The hardware then decides what rights the program has to it based on the location of the password in a database. The OS will inhibit nothing. The hardware will inhibit everything. Not even the OS nor the hardware has access to the contents of the database: They can only compare passwords against it, just like anything else. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
On Apr 4, 7:43 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: (snipped) A we-don't-need-no-stinkin'-one-liners more relaxed approach: import collections d = collections.defaultdict(int) for x in myList: d[x] += 1 list(x for x in myList if d[x]==1) yields O(N) performance (give that dict-indexing is about O(1)...). Collapsing this kind of approach back into a one-liner while keeping the O(N) performance is not easy -- whether this is a fortunate or unfortunate ocurrence is of course debatable. If we had a turn sequence into bag function somewhere (and it might be worth having it for other reasons): def bagit(seq): import collections d = collections.defaultdict(int) for x in seq: d[x] += 1 return d then one-linerness might be achieved in the gimme nonduplicated items task via a dirty, rotten trick...: list(x for bag in [bagit(myList)] for x in myList if bag[x] == 1) ...which I would of course never mention in polite company... Alex With a context managed set one could have, as a one-liner: with cset() as s: retval = [ (x, s.add(x))[0] for x in myList if x not in s ] I've not looked at the underlying implementation of set(), but I presume that checking set membership is also about O(1). -- Cheers, Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'tuple' object has no attribute 'encode'
Lenard Lindstrom wrote: I'm trying to build a SQL string sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid, ag, self.data[parent][child]['results']['test']) I am guessing you want the string formatting operator here: sql = ... % (cid, ...) That's a superficial solution which encourages a bad practice: if any of that data can be subverted to modify the query, as opposed to merely providing a simple value, then you have a vulnerability in your code. Perhaps the %i and %d substitutions may prevent such things, but the %s substitution won't. Paul -- http://mail.python.org/mailman/listinfo/python-list
Looping issues
What I am trying to do is compare two files to each other. If the 2nd file contains the same line the first file contains, I want to print it. I wrote up the following code: correct_settings = open(C:\Python25\Scripts\Output \correct_settings.txt,r) current_settings = open(C:\Python25\Scripts\Output\output.txt,r) for line in correct_settings: for val in current_settings: if val == line: print line + found. correct_settings.close() current_settings.close() For some reason this only looks at the first line of the correct_settings.txt file. Any ideas as to how i can loop through each line of the correct_settings file instead of just looking at the first? -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: 'tuple' object has no attribute 'encode'
erikcw wrote: Here is the full error: (sorry) No problem! It's easier to comment with these details... Traceback (most recent call last): File /home/erik/Desktop/wa.py, line 178, in ? curHandler.walkData() File /home/erik/Desktop/wa.py, line 91, in walkData sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid.encode(utf-8), ag, self.data[parent][child]['results']['test']) AttributeError: 'long' object has no attribute 'encode' If cid is a long, it won't have an encode method, but this is a diversion from the real problem. sql = INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d), (cid.encode(utf-8), ag, self.data[parent][child]['results']['test']) self.cursor.execute(sql) This won't work because the first parameter of the execute method must be a string (or Unicode object, I guess), but you've provided a tuple. Now, I changed all ofth e %i/%d to %s, and changed self.cursor.execute(sql) to self.cursor.execute(*sql) and it seems to be working now! The first modification may not have been necessary, but you should check the database module documentation to make sure what kinds of parameter markers are permitted. The second modification should, as I suspected, solve your problem. As you may be aware, adding the * unpacks the contents of sql into the parameters for the execute method. Thus, the first element in the tuple gets presented as the first parameter (the SQL statement), and the second element gets presented as the second parameter (a sequence of values which are to be used with the SQL statement). Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: PyDispatcher question
Jorgen Bodde wrote: Hi all, Hopefully someone can help me. I am fairly new to Python, and I am looking into PyDispatcher. I am familiar with the C++ sigslot variant, and I wonder how similar PyDispatches is. I run in to the following 'problem' (pseudo code, untested here) Here's some real code... from pydispatch import dispatcher import gc class X(object): def __init__( self ): dispatcher.connect( self.someSignal, signal=1 ) def someSignal( self ): print 'hello world' obj = X() dispatcher.send( signal= 1 ) del obj #gc.collect() dispatcher.send( signal= 1 ) This will print out only one hello world on my Python 2.5 Gentoo machine (it should work the same on any recent Python). Basically your python shell will tend to keep around an extra copy of the X instance until you get rid of it explicitly, and that's what keeps the object live and receiving signals if you try the code in the shell. PyDispatcher is designed so that, by default, when the object goes away the registration is removed. It uses the weakref module to do this, rather than __del__ methods, to avoid garbage cycles, btw. HTH, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Re: way to extract only the message from pop3
so get two strings: only headers, and the whole message. find the length of the headers, and chop that off the beginning of the whole message: message=whole_message[len(headers):None] You can omit the word None: it is just there for clarity purposes. On 3 Apr 2007 12:36:10 -0700, flit [EMAIL PROTECTED] wrote: Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? like remove the fields below: Return-Path: X-Original-To: Received: from [ by (Postfix) with ESMTP id B32382613C for Tue, 3 Apr 2007 09:54:28 -0300 (BRT) Date: Tue, 03 Apr 2007 09:52:15 -0300 From: @ To: Subject: test Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver. 2.24.02 [en] X-UIDL: !Dn!!HKT!!/k Status: RO and only get this: this is a text message.. .. Thanks -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: SNMP agent
In article [EMAIL PROTECTED], alain [EMAIL PROTECTED] wrote: On Apr 4, 1:30 pm, alf [EMAIL PROTECTED] wrote: twistedmatrix.org? I already took a look at it but the agent functionality is somewhat primitive. I need something production-ready. Alain 'Doesn't exist. I understand the sentiment; in principle, it shouldn't be hard to write a library which supports construction of SNMP agents in Python. I'm aware of no one who has done so publicly, though. Myself, I like using the Tcl-based Scotty. For severely-constrained performance, though, you'll likely have to go to C, in some form. -- http://mail.python.org/mailman/listinfo/python-list
SUMMON - Rapid prototyping of 2D visualizations
I have been using python for the last two years to create various visualizations for my research in computational biology. Over the years, I found that I often needed the same kinds of features for many of my visualizations (OpenGL graphics with basic scrolling and zooming). I have implemented these features in an extension module for python called SUMMON which I have made freely available on my website for anyone who is interested http://people.csail.mit.edu/ rasmus/summon/index.shtml. Although, there are many visualization frameworks, I believe SUMMON provides a fairly unique combination. - First, SUMMON is designed to be fast and able to visualize extremely large datasets. In the examples included, there is a visualization of a binary tree with roughly 40,000 leaves (a hierarchical clustering of all protein sequences from the human and dog genomes). Specifying how to draw the tree is done once in using python functions provided by SUMMON (relatively slowly in about 10secs), however once constructed, it uses natively compiled C++ to handle interaction. Callbacks such as mouse movements, clicks, and key strokes can all be bound to python functions to customize interaction. - SUMMON is designed for prototyping visualizations. Often times in science, one wants to visualize something in order to understand whether it has any interesting patterns. If the answer is no, you have to be able to throw away the visualization and move on to another approach. However, if there is a large amount of overhead in creating a visualization (designing dialog boxes, toolbars, laying out check boxes), it can become difficult to give up a visualization with that much investment so easily. The philosophy with SUMMON is to rely on the python shell for handling basic interaction (reading in data, specifying options, interacting with visualization) in order to avoid GUI design. Once, you realize a visualization is worth while for your research, you can then reimplement it in your favorite full featured GUI-toolkit. - It provides basic scrolling and zooming for an arbitrarily large coordinate space. As a user you simply draw out your visualization with lines, polygons, and text in the coordinate system you wish, completely ignoring how many pixels anything may take. SUMMON will handle the display, including smart display of text (automatic clipping, sizing, and justification of text). - Its cross-platform: It only relies on python2.4, OpenGL, GLUT, and SDL. So if this sounds like something you may need for your work, please check it out and let me know what you think. Matt -- http://mail.python.org/mailman/listinfo/python-list