ANN: Leo 4.4.6 beta 1 released
Leo 4.4.6 beta 1 is available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 Leo 4.4.6 fixes several recently reported bugs, all minor. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.4.6: - Fixes all known bugs. - Added @auto importers for javascript and xml files. - Added find-next-clone and toggle-sparse-move commands. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[CfP] Workshop on Self-sustaining Systems (S3) 2008
*** Workshop on Self-sustaining Systems (S3) 2008 *** May 15-16, 2008 Potsdam, Germany http://www.swa.hpi.uni-potsdam.de/s3/ -- Call for papers: The Workshop on Self-sustaining Systems (S3) is a forum for discussion of topics relating to computer systems and languages that are able to bootstrap, implement, modify, and maintain themselves. One property of these systems is that their implementation is based on small but powerful abstractions; examples include (amongst others) Squeak/Smalltalk, COLA, Klein/Self, PyPy/Python, Rubinius/Ruby, and Lisp. Such systems are the engines of their own replacement, giving researchers and developers great power to experiment with, and explore future directions from within, their own small language kernels. S3 will be take place May 15-16, 2008 at the Hasso-Plattner-Institute in Potsdam, Germany. It is an exciting opportunity for researchers and practitioners interested in self-sustaining systems to meet and share their knowledge, experience, and ideas for future research and development. -- Invited talk: Ian Piumarta: Late-bound Object Lambda Architectures (Viewpoints Research Institute, USA) -- Submissions and proceedings: S3 invites submissions of high-quality papers reporting original research, or describing innovative contributions to, or experience with, self-sustaining systems, their implementation, and their application. Papers that depart significantly from established ideas and practices are particularly welcome. Submissions must not have been published previously and must not be under review for any another refereed event or publication. The program committee will evaluate each contributed paper based on its relevance, significance, clarity, and originality. Revised papers will be published as post-proceedings in the Springer LNCS series. Papers should be submitted electronically via EasyChair at http://www.easychair.org/conferences/?conf=s3 in PDF format. Submissions must be written in English (the official language of the workshop) and must not exceed 20 pages. They should use the LNCS format, templates for which are available at http://www.springer.de/comp/lncs/authors.html. -- Venue: Hasso-Plattner-Institut (Potsdam, Germany) -- Important dates: Submission of papers: February 15, 2008 Author notification: April 11, 2008 Revised papers due: April 25, 2008 S3 workshop: May 15-16, 2008 Final papers for LNCS post-proceedings due: June 6, 2008 -- Chairs: * Robert Hirschfeld (Hasso-Plattner-Institut Potsdam, Germany) * Kim Rose (Viewpoints Research Institute, USA) -- Program committee: * Johan Brichau, Universite Catholique de Louvain, Belgium * Pascal Costanza, Vrije Universiteit Brussel, Belgium * Wolfgang De Meuter, Vrije Universiteit Brussel, Belgium * Stephane Ducasse, INRIA Lille, France * Michael Haupt, Hasso-Plattner-Institut, Germany * Robert Hirschfeld, Hasso-Plattner-Institut, Germany * Dan Ingalls, Sun Microsystems Laboratories, USA * Martin von Lšwis, Hasso-Plattner-Institut, Germany * Hidehiko Masuhara, University of Tokyo, Japan * Ian Piumarta, Viewpoints Research Institute, USA * David Ungar, IBM, USA -- Registration fees: Early (until April 18, 2008) * Regular participants: EUR 160 * Students: EUR 80 Late (after April 18, 2008) * Regular participants: EUR 170 * Students: EUR 90 -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Cookie expiration time
Hi All ! I'm using httplib2 library in my python script for interactions with remote web-server. Remote server responses me cookies with the set expiration time. I'd like to extend this time. Does anybody know how can I do it using this library ? -- http://mail.python.org/mailman/listinfo/python-list
Re: looping list?
En Thu, 13 Dec 2007 06:07:46 -0300, datulaida ali [EMAIL PROTECTED] escribi�: i'm trying to insert value into list according to the key (ASCII) that i generate.. example : win = 95, so must insert into list[95] and = 70, so must insert into list[70] this is my coding.. The indentation is lost so I can't see exactly what you are doing. But looks like you got a list too long (twice the size). Instead of a list, why don't use a dictionary? list = [] Using list as a name is not a good idea, hides the builtin list type. I'll use data instead: data = {} for i in range (100): if i == key : list.append([i,word]) else : list.append([0]) data[key] = word print list for key,word in sorted(data.items()): print key,word (All remaining slots are 0; you may build a true list from that) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: programming container object
On Dec 17, 1:18 am, bambam [EMAIL PROTECTED] wrote: I wish to create a generic container object, devlist, such that devlist.method(arguments) runs as for each dev in devlist.pool: dev.method(arguments) and s = devlist.method(arguments) runs as for each dev in devlist.pool: s.append(dev.method(arguments)) ...but it is outside my ability to do so. Can anyone provide an example of how to do that? Thanks, Steve Ok, I'll take a stab at it. -- Paul class DevList(object): def __init__(self, objs): self.devpool = objs def __getattribute__(self,attrname): if attrname == devpool: return object.__getattribute__(self,attrname) def ret(*args): return [ getattr(p,attrname)(*args) for p in self.devpool ] return ret dl = DevList([1,2,3]) print dl.__str__() prints: ['1', '2', '3'] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate pdf file from an html page??
On Dec 16, 10:21 pm, Zentrader [EMAIL PROTECTED] wrote: I'm sure it can be done but there is no reason to reinvent the wheel unless it's for a programming exercise. You can use pdftohtml and run it from a Python program if you want.http://pdftohtml.sourceforge.net/ Hi Zentrader, thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
free video lessons on 12 computer Science Courses
Hi Guys, Good news is that as many as 12 courses from top universities are providing free video lessons http://freevideolectures.com/ComputerScience/ on all the basic courses. All you need to have is Real Player installed on your PC. I think it is useful to you -- http://mail.python.org/mailman/listinfo/python-list
Re: programming container object
On Mon, 17 Dec 2007 18:18:11 +1100, bambam wrote: I wish to create a generic container object, devlist, such that devlist.method(arguments) runs as for each dev in devlist.pool: dev.method(arguments) and s = devlist.method(arguments) runs as for each dev in devlist.pool: s.append(dev.method(arguments)) ...but it is outside my ability to do so. Can anyone provide an example of how to do that? If I've understood you correctly, I don't think it can be done. It looks to me that you want: s = instance.method() and instance.method() to do completely different things. This is a bad idea and a recipe for confusion. In any case, it is not possible, because the instance method cannot know whether its result is being assigned to a name or just thrown away. I may have misunderstood what you are trying to do. Please feel free to explain in more detail, perhaps with an example. By the way, the correct way to get the result you want is to have devlist.method() work as in your first example, and then do this: s.extend(devlist.method()) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Announcement: pacparser - a c library to parse proxy auto-config (pac) files
Hi Folks, I am very pleased to announce the release of pacparser - a C library to parse proxy auto-config (PAC) scripts. Needless to say, PAC files are now a widely accepted method for proxy configuration management and almost all popular browsers support them. The idea behind pacparser is to make it easy to add this PAC file parsing capability to other programs. It comes as a shared C library with a clear API. You can use it to make any C or python (using ctypes) program PAC scripts intelligent. For documentation and available packages, please visit project home page at: http://code.google.com/p/pacparser For the ones who like to start with source code, here is the link to direct download for source code: http://pacparser.googlecode.com/files/pacparser-1.0.0.tar.gz. Cheers :-), Manu -- Manu Garg http://www.manugarg.com Journey is the destination of the life. -- http://mail.python.org/mailman/listinfo/python-list
Re: Finite State Machine GUI editor in python?
Hendrik van Rooyen [EMAIL PROTECTED] writes: I am looking for a similar front end, going from pretty pictures of state diagrams to some sort of state machine descriptor language or specification file, and I am not very fussy about the format of the output at this stage. In case nothing better comes up and you want to code it yourself: Our Hidden Markov Model library GHMM (http://ghmm.org) has a graphical editor with XML output. Maybe http://networkx.lanl.gov/ or other general Python graph packages have what you want. Also check out http://www.graphviz.org/ Best, Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: programming container object
Steven D'Aprano wrote: On Mon, 17 Dec 2007 18:18:11 +1100, bambam wrote: I wish to create a generic container object, devlist, such that devlist.method(arguments) runs as for each dev in devlist.pool: dev.method(arguments) and s = devlist.method(arguments) runs as for each dev in devlist.pool: s.append(dev.method(arguments)) ...but it is outside my ability to do so. Can anyone provide an example of how to do that? If I've understood you correctly, I don't think it can be done. It looks to me that you want: s = instance.method() and instance.method() to do completely different things. This is a bad idea and a recipe for confusion. In any case, it is not possible, because the instance method cannot know whether its result is being assigned to a name or just thrown away. This isn't entirely correct - there _are_ ways to know. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/284742 Now if it is _desirable_ to use this as clever optimization scheme is a subject worth discussing - I certainly wouldn't do it... Diez -- http://mail.python.org/mailman/listinfo/python-list
Imports in Packages
While working within a package...what is the 'best practice' way to do your imports. a/__init__.py a/one.py a/two.py a/b/__init__.py a/b/cat.py a/b/dog.py a/c/cow.py Suppose I am working in a/c/cow.py and I need something from a/b/ dog.py. If a/b/__init__.py contains what I need from dog.py, should I do: from a.b import desiredfunction or from a.b.dog import desiredfunction What are your reasons for preferring one over the other (performance, readability, portability)? Also, the same can be said of functions from other packages... I know that from math import cos x = cos(3) is preferred for performance reasons over import math x = math.cos(3) because of the required lookup. Does this mean that that I should import as far down as possible as well? For example, from a.b.c.mod import func versus from a import fun. -- http://mail.python.org/mailman/listinfo/python-list
Re: programming container object
Diez B. Roggisch [EMAIL PROTECTED] writes: In any case, it is not possible, because the instance method cannot know whether its result is being assigned to a name or just thrown away. This isn't entirely correct - there _are_ ways to know. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/284742 Not by using the public API, though. The above recipe relies on a number of CPython's implementation details, and will stop working if any of this changes. (I'm sure you're aware of that, but it might not be obvious to some readers.) It also doesn't work when the function is called from C code, or when the unpacking is done in a separate step. -- http://mail.python.org/mailman/listinfo/python-list
Re: OpenOpt install
Use python setup.py install Regards, D On Dec 16, 2:27 pm, Neal Becker [EMAIL PROTECTED] wrote: What do I need to do? I have numpy, scipy (Fedora F8) cdopenopt/ [EMAIL PROTECTED] python setup.py build running build running config_cc unifing config_cc, config, build_clib, build_ext, build commands --compiler options running config_fc unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options running build_py creating build creating build/lib creating build/lib/scikits copying scikits/__init__.py - build/lib/scikits creating build/lib/scikits/openopt copying scikits/openopt/__init__.py - build/lib/scikits/openopt copying scikits/openopt/info.py - build/lib/scikits/openopt copying scikits/openopt/oo.py - build/lib/scikits/openopt Traceback (most recent call last): File setup.py, line 101, in module import scikits ImportError: No module named scikits -- http://mail.python.org/mailman/listinfo/python-list
Re: why this error?
En Mon, 17 Dec 2007 02:45:34 -0300, python.jiang [EMAIL PROTECTED] escribi�: thanks all first. but i had one class bellow to get object info what user had inputed when run application. because the problem that i had showed yestoday, i must write the code so hard to understand. can any friend tell me one way to solve this problem? thanks!! You can import a module using __import__, and from the returned module object obtain all the info you want using getattr. Don't use eval - write your code as if such function didn't exist. And don't use global variables either - you have defined a class, use its attributes and methods! -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: in-client web server
I've done something reasonably similar using CherryPy as the webserver. The main application I wrote stored data in a sqlite3 database. A separate thread then ran the CherryPy server process. Each web browser call is mapped (by CherryPy) to a class method which dealt with connecting to the sqlite3 database, collecting the appropriate data and then generating the page. You can have much tighter integration between the webserver and the application if required. I found cherrytemplate to be a usable and lightweight HTML page templating system that was appropriate for what I wanted but there are lots of others. I haven't gone down the full AJAX/DHTML line with CherryPy but from what I've seen of it, it seems quite capable of delivering. Neither have I come across any issues with firewalls or proxy configurations - I just set CherryPy to bind to 127.0.0.1 at a suitably high port number and it's always worked so far. Matthew. -- http://mail.python.org/mailman/listinfo/python-list
Re: free video lessons on 12 computer Science Courses
On Dec 17, 3:13 am, AK444 [EMAIL PROTECTED] wrote: Hi Guys, Good news is that as many as 12 courses from top universities are providing free video lessons http://freevideolectures.com/ComputerScience/ on all the basic courses. All you need to have is Real Player installed on your PC. I think it is useful to you Lots of fun A/V at the Berkeley webcast page also: http://webcast.berkeley.edu/courses.php?semesterid=21 Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Deleting lines from a file
Hi, I need to write a program which reads an external text file. Each time it reads, then it needs to delete some lines, for instance from second line to 55th line. The file is really big, so what do you think is the fastest method to delete specific lines in a text file ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
Horacius ReX wrote: Hi, I need to write a program which reads an external text file. Each time it reads, then it needs to delete some lines, for instance from second line to 55th line. The file is really big, so what do you think is the fastest method to delete specific lines in a text file ? Not using a file but a database instead. If that's not possible, you can't do anything but open/read/filter/write - filesystems (at least not the known ones) don't support random deletion. Diez -- http://mail.python.org/mailman/listinfo/python-list
arrays in lists
Hi! I have a list of arrays and want to find an array with list.index(x). Is that possible. I get an ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() For example: from numpy import array a = array([1]) b = array([2]) c = [a,b] d = c.index(a) Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
Horacius ReX wrote: Hi, I need to write a program which reads an external text file. Each time it reads, then it needs to delete some lines, for instance from second line to 55th line. The file is really big, so what do you think is the fastest method to delete specific lines in a text file ? Thanks One way would be to mark the lines as being deleted by either: 1) replacing them with some known character sequence that you treat as deleted. This assumes that the lines are long enough. or 2) by keeping a separate dictionary that holds line numbers and deleteflag. Pickle and dump this dictionary before program execution ends. Load it at program execution beginning. deletedFlags={1:False, 2: True, ...} def load(): pFiles=deletedLines.toc fp=open(pFiles, 'wb') deletedFlags=pickle.dump(fp) fp.close() def dump(deletedFlags): pFiles=deletedLines.toc fp=open(pFiles, 'rb') pickle.dump(deletedFlags, fp) fp.close() Caveats: 1) you must write EXACTLY the same number of bytes (padded with spaces, etc.) on top of deleted lines. This method doesn't work if any of the lines are so short they don't support your DELETED flag string. 2) You must be very careful to maintain consistency of the deletedFlags dictionary and the data file (by using try/except/finally around your entire process). Personally I would employ method #2 and periodically pack the file with a separate process. That could run unattended (e.g. at night). Or, if I did this a lot, I would use a database instead. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
On Dec 17, 2007, at 5:34 AM, Horacius ReX wrote: I need to write a program which reads an external text file. Each time it reads, then it needs to delete some lines, for instance from second line to 55th line. The file is really big, so what do you think is the fastest method to delete specific lines in a text file ? AFAIK, there really isn't much you can do to *speed* the reading and writing of the large text file. But maybe you can avoid doing it too much. If you must make many changes it might help to just keep a list of lines to consider deleted -- and write the modified file out later. hth, Michael --- I use tuples simply because of their mellifluous appellation. --Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
and regardless of the speed, what do you think would be the best method to do this ? Michael Bentley wrote: On Dec 17, 2007, at 5:34 AM, Horacius ReX wrote: I need to write a program which reads an external text file. Each time it reads, then it needs to delete some lines, for instance from second line to 55th line. The file is really big, so what do you think is the fastest method to delete specific lines in a text file ? AFAIK, there really isn't much you can do to *speed* the reading and writing of the large text file. But maybe you can avoid doing it too much. If you must make many changes it might help to just keep a list of lines to consider deleted -- and write the modified file out later. hth, Michael --- I use tuples simply because of their mellifluous appellation. --Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in lists
On 17 déc, 14:05, Peter Stahlir [EMAIL PROTECTED] wrote: For example: from numpy import array a = array([1]) b = array([2]) c = [a,b] d = c.index(a) No problem here, Python 2.4.4 -- http://mail.python.org/mailman/listinfo/python-list
Re: int vs long
Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 16 Dec 2007 20:28:02 -0300, Troels Thomsen nej tak...@bag.python.org escribi?: The readFile function from the win32 package aparently really expect an integer : def inWaiting(self): Returns the number of bytes waiting to be read flags, comstat = ClearCommError(self.__handle) return comstat.cbInQue ReadFile(h, s.inWaiting()) My code crashes because inWaiting returns a long, not an int That's very strange. The cbInQue field is a DWORD in C, seen as an int in Python. How do you know it returns a long? Why is that different on my machine and my collegues ? Have I or he installed a wrong version of a package? CPython 2.5. And pywin32 build 210, I presume. Was not expecting int-long type problems in excactly python language. Is that because we are navigating so close to the win32 api that the types are more strictly enforced ? Somewhat. At the API level, function arguments have to be converted to native C types, like ReadFile expecting a DWORD. Any number greater than 2**32 won't fit, but I can't think how such thing could happen looking at those few posted code lines. Actually any number = 2**31 won't fit in a python int. 2**31 2147483648L According to my headers DWORD is defined like this typedef unsigned long DWORD; So you might see longs returned when you expected ints if the result was = 0x800. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
I need to write a program which reads an external text file. Each time it reads, then it needs to delete some lines, for instance from second line to 55th line. The file is really big, so what do you think is the fastest method to delete specific lines in a text file ? Generally, with files that are really big, you either want to edit them in place (which takes a database-type structure), or you need to stream through the file a line/window at a time, dumping the output to a temporary output file. The *nix tool for this job is sed: sed '2,55d' infile.txt outfile.txt (it doesn't get much more consise than this). That's about the same as the following in Python out = file('outfile.txt', 'w') for i, line in enumerate(file('infile.txt')): if 1 i 54: continue out.write(line) out.close() If you want it in place, sed will do the output file and renaming for you with sed -i '2,55d' file.txt whereas in the Python variant, you'd have to then use the os.rename call to move outfile.txt to infile.txt The Python version is a bit more flexible, as you can add other logic to change your bounds. Not that sed isn't flexible, but it starts getting unreadible very quickly as logic grows. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Fractions on musical notation
On 2007-12-17, Gabriel Genellina [EMAIL PROTECTED] wrote: On 16 dic, 06:40, Lie [EMAIL PROTECTED] wrote: [btw, off topic, in music, isn't 1/4 and 2/8 different? I'm not very keen of music though, so correct me if I'm wrong.] As a time signature 1/4 has no sense, but 3/4 and 6/8 are different things. In the standard musical notation both numbers are written one above the other, and no division line is used. Note that they just *look* like a fraction when written in text form, like here, because it's not easy to write one above the other. 3/4 is read as three by four, not three quarters -at least in my country- so there is even less confussion. Time signatures are crap. They should have switched to a number over a note value a long time ago; we could have easily avoided abominable travesties like the time signature on the 2nd movement of Beethoven's 9th (B needed four over dotted quarter). If music notation had been invented by a computer scientist we wouldn't be stuck in the current mess in which 6/8 means two completely different meters (3 over quarter, or 2 over dotted quarter). And... er... Python doesn't need a time signature data type. But rationals would be quite nifty. ;-) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
Horacius ReX wrote: and regardless of the speed, what do you think would be the best method to do this ? Without more information about the contents of the file and who's reading them, we can't say more. if the reader is not under your control doesn't deal with deletion-marks or anything such in the file, you can't do anything but really delete the lines. If you can control it, it depends on how you process the file - has it fixed line length, or not, and so forth. Because you need to use seek to position the file-pointer to the proper location in the file to write a deletion mark, but to do so you of course need to determine it first - and that will need to be done in a two-pass apporach most probably. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Finite State Machine GUI editor in python?
On Dec 16, 1:55 am, Hendrik van Rooyen [EMAIL PROTECTED] wrote: I have spent some time googling and on wiki and came up with pyFSA in python. It may end up being useful, but it is not directly what I am looking for, as there is no GUI that I can see. I know about SMC, but it is not Python, and I can't find the gui. This looks good, but it seems to be in a Latin based language and I am linguistically challenged: http://www.ucse.edu.ar/fma/sepa/edt.htm I am looking for a similar front end, going from pretty pictures of state diagrams to some sort of state machine descriptor language or specification file, and I am not very fussy about the format of the output at this stage. Does anyone know of such an animal that is FOSS? - if written in Python it will be a bonus! It will also help if its in a language I can understand. : - ( - Hendrik This looks interesting (and GPL'd :) http://www46.homepage.villanova.edu/timothy.m.white/ [java] Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
On 12/17/07, Horacius ReX [EMAIL PROTECTED] wrote: and regardless of the speed, what do you think would be the best method to do this ? use sqlite -- Vladimir Rusinov GreenMice Solutions: IT-решения на базе Linux http://greenmice.info/ -- http://mail.python.org/mailman/listinfo/python-list
Static linking of python and pyqt
Hello, I'm trying to link python statically with qt and pyqt. I've tried this in several ways but never succeeded. At the moment the final make runs without errors but I get import errors when accessing pyqt. How can I solve this problem? Markus # installing zipimport hook import zipimport # builtin # installed zipimport hook # /opt/python-2.4.4/lib/python2.4/site.pyc matches /opt/python-2.4.4/lib/python2.4/site.py import site # precompiled from /opt/python-2.4.4/lib/python2.4/site.pyc # /opt/python-2.4.4/lib/python2.4/os.pyc matches /opt/python-2.4.4/lib/python2.4/os.py import os # precompiled from /opt/python-2.4.4/lib/python2.4/os.pyc import posix # builtin # /opt/python-2.4.4/lib/python2.4/posixpath.pyc matches /opt/python-2.4.4/lib/python2.4/posixpath.py import posixpath # precompiled from /opt/python-2.4.4/lib/python2.4/posixpath.pyc # /opt/python-2.4.4/lib/python2.4/stat.pyc matches /opt/python-2.4.4/lib/python2.4/stat.py import stat # precompiled from /opt/python-2.4.4/lib/python2.4/stat.pyc # /opt/python-2.4.4/lib/python2.4/UserDict.pyc matches /opt/python-2.4.4/lib/python2.4/UserDict.py import UserDict # precompiled from /opt/python-2.4.4/lib/python2.4/UserDict.pyc # /opt/python-2.4.4/lib/python2.4/copy_reg.pyc matches /opt/python-2.4.4/lib/python2.4/copy_reg.py import copy_reg # precompiled from /opt/python-2.4.4/lib/python2.4/copy_reg.pyc # /opt/python-2.4.4/lib/python2.4/types.pyc matches /opt/python-2.4.4/lib/python2.4/types.py import types # precompiled from /opt/python-2.4.4/lib/python2.4/types.pyc # /opt/python-2.4.4/lib/python2.4/warnings.pyc matches /opt/python-2.4.4/lib/python2.4/warnings.py import warnings # precompiled from /opt/python-2.4.4/lib/python2.4/warnings.pyc # /opt/python-2.4.4/lib/python2.4/linecache.pyc matches /opt/python-2.4.4/lib/python2.4/linecache.py import linecache # precompiled from /opt/python-2.4.4/lib/python2.4/linecache.pyc import encodings # directory /opt/python-2.4.4/lib/python2.4/encodings # /opt/python-2.4.4/lib/python2.4/encodings/__init__.pyc matches /opt/python-2.4.4/lib/python2.4/encodings/__init__.py import encodings # precompiled from /opt/python-2.4.4/lib/python2.4/encodings/__init__.pyc # /opt/python-2.4.4/lib/python2.4/codecs.pyc matches /opt/python-2.4.4/lib/python2.4/codecs.py import codecs # precompiled from /opt/python-2.4.4/lib/python2.4/codecs.pyc import _codecs # builtin # /opt/python-2.4.4/lib/python2.4/encodings/aliases.pyc matches /opt/python-2.4.4/lib/python2.4/encodings/aliases.py import encodings.aliases # precompiled from /opt/python-2.4.4/lib/python2.4/encodings/aliases.pyc # /opt/python-2.4.4/lib/python2.4/encodings/utf_8.pyc matches /opt/python-2.4.4/lib/python2.4/encodings/utf_8.py import encodings.utf_8 # precompiled from /opt/python-2.4.4/lib/python2.4/encodings/utf_8.pyc Python 2.4.4 (#1, Dec 7 2007, 11:16:51) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type help, copyright, credits or license for more information. import QtCore import QtCore # builtin import sip # builtin Traceback (most recent call last): File stdin, line 1, in ? SystemError: _PyImport_FixupExtension: module QtCore not loaded import sys print sys.builtin_module_names ('QtCore', 'QtGui', '__builtin__', '__main__', '_codecs', '_sre', '_symtable', 'errno', 'exceptions', 'gc', 'imp', 'marshal', 'posix', 'pwd', 'signal', 'sip', 'sys', 'thread', 'time', 'xxsubtype', 'zipimport') # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value # clear sys.exc_traceback # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup __main__ # cleanup[1] site # cleanup[1] encodings # cleanup[1] _codecs # cleanup[1] zipimport # cleanup[1] PyQt4.QtCore # cleanup[1] warnings # cleanup[1] encodings.utf_8 # cleanup[1] codecs # cleanup[1] types # cleanup[1] signal # cleanup[1] linecache # cleanup[1] posix # cleanup[1] encodings.aliases # cleanup[1] exceptions # cleanup[2] copy_reg # cleanup[2] sip # cleanup[2] posixpath # cleanup[2] os.path # cleanup[2] stat # cleanup[2] UserDict # cleanup[2] os # cleanup sys # cleanup __builtin__ # cleanup ints: 7 unfreed ints in 1 out of 3 blocks # cleanup floats -- http://mail.python.org/mailman/listinfo/python-list
checking for negative values in a list
hi all, -- http://mail.python.org/mailman/listinfo/python-list
checking for negative values in a list
hi all, i am new to python guys. hope u will help me with this i have a list of numbers say a = [1,-1,3,-2,4,-6] how should i check for negative values in the list -- http://mail.python.org/mailman/listinfo/python-list
Re: programming container object
On Dec 17, 2:31 am, Paul McGuire [EMAIL PROTECTED] wrote: On Dec 17, 1:18 am, bambam [EMAIL PROTECTED] wrote: I wish to create a generic container object, devlist, such that devlist.method(arguments) runs as for each dev in devlist.pool: dev.method(arguments) and s = devlist.method(arguments) runs as for each dev in devlist.pool: s.append(dev.method(arguments)) ...but it is outside my ability to do so. Can anyone provide an example of how to do that? Thanks, Steve Ok, I'll take a stab at it. -- Paul class DevList(object): def __init__(self, objs): self.devpool = objs def __getattribute__(self,attrname): if attrname == devpool: return object.__getattribute__(self,attrname) def ret(*args): return [ getattr(p,attrname)(*args) for p in self.devpool ] return ret dl = DevList([1,2,3]) print dl.__str__() prints: ['1', '2', '3']- Hide quoted text - - Show quoted text - Here's some expanded demo code for the previously-posted DevList class: from math import sqrt class NumberWrapper(object): def __init__(self,value=0): self.value = value def inverse(self): if self.value != 0: return 1.0/self.value else: return None def sqrt(self): return sqrt(self.value) def incrBy(self,offset): self.value += offset return self.value dl = DevList([NumberWrapper(i) for i in range(5)]) print dl.sqrt() print dl.inverse() print dl.incrBy(10) print dl.sqrt() print dl.inverse() prints: [0.0, 1.0, 1.4142135623730951, 1.7320508075688772, 2.0] [None, 1.0, 0.5, 0.1, 0.25] [10, 11, 12, 13, 14] [3.1622776601683795, 3.3166247903553998, 3.4641016151377544, 3.6055512754639891, 3.7416573867739413] [0.10001, 0.090909090909090912, 0.083329, 0.076923076923076927, 0.071428571428571425] -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: checking for negative values in a list
On Mon, 17 Dec 2007 06:20:23 -0800, vimal wrote: i have a list of numbers say a = [1,-1,3,-2,4,-6] how should i check for negative values in the list In [6]: a = [1, -1, 3, -2, 4, -6] In [7]: any(n 0 for n in a) Out[7]: True Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: checking for negative values in a list
i am new to python guys. i have a list of numbers say a = [1,-1,3,-2,4,-6] how should i check for negative values in the list I'm not sure if this is a homework problem, as it seems to be a fairly simple programming problem whether you know Python or not. If you're using 2.5 or more recent, you should be able to do something like if any(x 0 for x in a): yep() else: nope() If a is small, you could do if [x for x in a if x 0]: yep() else: nope() Or you could write your own function: def has_negatives(iterable): for x in iterable: if x 0: return True return False if has_negatives(a): yep() else: nope() -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: checking for negative values in a list
thanks for your help Tim and Marc. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: free video lessons on 12 computer Science Courses
On Dec 17, 6:12 am, MonkeeSage [EMAIL PROTECTED] wrote: On Dec 17, 3:13 am, AK444 [EMAIL PROTECTED] wrote: Hi Guys, Good news is that as many as 12 courses from top universities are providing free video lessons http://freevideolectures.com/ComputerScience/ on all the basic courses. All you need to have is Real Player installed on your PC. I think it is useful to you Lots of fun A/V at the Berkeley webcast page also: http://webcast.berkeley.edu/courses.php?semesterid=21 Regards, Jordan And not forgetting Sussman-Abelson lectures... http://www.archive.org/details/mit_ocw_sicp Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Deleting lines from a file
On Dec 17, 2007, at 6:25 AM, Horacius ReX wrote: and regardless of the speed, what do you think would be the best method to do this ? The first thing I'd look into is reading the whole file into memory, making all the deletions, and finally writing it out. But you said the file is big, so here's a quick stab at it (with multiple read passes and a single write): import string rm = [] #first pass through file -- mark some lines for deletion for line, text in enumerate(file('words')): if text[0] in string.uppercase: rm.append(line) #second pass -- mark lines with 'e' for deletion for line, text in enumerate(file('words')): if line in rm: print 'skipping %s' % line continue if 'e' in text: rm.append(line) # now write the modified file print 'Writing %d of %d lines' % (len(rm), line) outFile = file('newWords', 'w') for line, text in enumerate(file('words')): if line not in rm: outFile.write(text) hth, Michael --- Simplicity is the ultimate sophistication. -Leonardo da Vinci -- http://mail.python.org/mailman/listinfo/python-list
Debugging pipe IPC
I have the mother (of all) application(s, written in C++) that occasionally outsources certain tasks to a child Python script. The mother fork/execs (or equivalent) the child and then begins serving the child's requests. The child/client sends requests on its stdout and receives responses on stdin. The interaction is facilitated by a Pyrex extension which handles the lower-level aspects of the conversation and exposes a few functions and classes to the script. This part works peachy keen, but debugging has so far been via printstderr-and-scratch-head. On a contemplative bike ride one day, I imagined how neat it would be to run interactively. On returning, I began to experiment with rebinding sys.stdin and sys.stdout to /dev/tty, using the -i command-line switch, etc. to see if I could devise a child that prompted me with and allowed me to compose/test small snippets on the terminal. So far, no joy. Is this possible? If so, can someone nudge me toward a solution or better yet a recipe? Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
Free LINUX Tips and Triks - Building Interactive Movie With Ming
Free LINUX Tips and Triks - Building Interactive Movie With Ming 001. Linux What are the benefits of Linux 002. Which Linux distribution should I use 003. Linux redhat network programming 004. LINUX Using Open Source APIs to Save Time 005. LINUX TIPS - Uploading a File with a Simple Program Using libcurl 006. LINUX TIPS - Using the libcurl Library C Programming 007. LINUX TIPS - Building a Simple Flash Movie with Ming 008. LINUX TIPS - Building Interactive Movies with Ming 009. Configuring Linux as a Firewall and many more articles. You can read and download at http://www.network.79br.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate pdf file from an html page??
On 2007-12-16, abhishek [EMAIL PROTECTED] wrote: Hi everyone, I am trying to generate a PDF printable format file from an html page. Is there a way to do this using python. If yes then which library and functions are required and if no then reasons why it cant be done. Here's one way: --html2pdf.py #!/usr/bin/python import os,sys inputFilename,outputFilename = sys.argv[1:3] os.system(w3m -dump %s | a2ps -B --borders=no | ps2pdf - %s % (inputFilename,outputFilename)) - -- Grant Edwards grante Yow! Someone in DAYTON, at Ohio is selling USED visi.comCARPETS to a SERBO-CROATIAN -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Fractions on musical notation
As a time signature 1/4 has no sense, You've never played and Grainger, have you? :-) --greg -- http://mail.python.org/mailman/listinfo/python-list
is it possible to install 2 Python versions on windows XP ?
hello, I'm currently using Python 2.4, and I don't dare to switch to 2.5, because I depend heavily on Scipy, which is based on 2.4 To test some other Python programs I need Python version 2.5. I've tried to install 2.5 in the past, but got a lot of trouble trying to uninstall it to go back to 2.4. Is there a safe way to install Python 2.5, without affecting the Python 2.4 version and the windows registry, on windows XP ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: is it possible to install 2 Python versions on windows XP ?
On Dec 17, 11:07 am, Stef Mientki [EMAIL PROTECTED] wrote: hello, I'm currently using Python 2.4, and I don't dare to switch to 2.5, because I depend heavily on Scipy, which is based on 2.4 To test some other Python programs I need Python version 2.5. I've tried to install 2.5 in the past, but got a lot of trouble trying to uninstall it to go back to 2.4. Is there a safe way to install Python 2.5, without affecting the Python 2.4 version and the windows registry, on windows XP ? thanks, Stef Mientki I'm currently running 2.3 and 2.5 on the same XP system with no problems. As I remember the installs didn't effect each other at all. -Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
[EMAIL PROTECTED] wrote: Given a bunch of arrays, if I want to create tuples, there is zip(arrays). What if I want to do the opposite: break a tuple up and append the values to given arrays: map(append, arrays, tupl) except there is no unbound append() (List.append() does not exist, right?). list.append does exist (try the lower-case flavor). Without append(), I am forced to write a (slow) explicit loop: for (a, v) in zip(arrays, tupl): a.append(v) Except that isn't technically the opposite of zip. The opposite would be a tuple of single-dimensional tuples: def unzip(zipped): Given a sequence of size-sized sequences, produce a tuple of tuples that represent each index within the zipped object. Example: zipped = zip((1, 2, 3), (4, 5, 6)) zipped [(1, 4), (2, 5), (3, 6)] unzip(zipped) ((1, 2, 3), (4, 5, 6)) if len(zipped) 1: raise ValueError, 'At least one item is required for unzip.' indices = range(len(zipped[0])) return tuple(tuple(pair[index] for pair in zipped) for index in indices) This is probably not the most efficient hunk of code for this but this would seem to be the correct behavior for the opposite of zip and it should scale well. Modifying the above with list.extend would produce a variant closer to what I think you're asking for: def unzip_extend(dests, zipped): Appends the unzip versions of zipped into dests. This avoids an unnecessary allocation. Example: zipped = zip((1, 2, 3), (4, 5, 6)) zipped [(1, 4), (2, 5), (3, 6)] dests = [[], []] unzip_extend(dests, zipped) dests [[1, 2, 3], [4, 5, 6]] if len(zipped) 1: raise ValueError, 'At least one item is required for unzip.' for index in range(len(zipped[0])): dests[index].extend(pair[index] for pair in zipped) This should perform pretty well, as extend with a comprehension is pretty fast. Not that it's truly meaningful, here's timeit on my 2GHz laptop: bash-3.1$ python -m timeit -s 'import unzip; zipped=zip(range(1024), range(1024))' 'unzip.unzip_extend([[], []], zipped)' 1000 loops, best of 3: 510 usec per loop By comparison, here's the unzip() version above: bash-3.1$ python -m timeit -s 'import unzip; zipped=zip(range(1024), range(1024))' 'unzip.unzip(zipped)' 1000 loops, best of 3: 504 usec per loop Rich -- http://mail.python.org/mailman/listinfo/python-list
Re: is it possible to install 2 Python versions on windows XP ?
Dan wrote: On Dec 17, 11:07 am, Stef Mientki [EMAIL PROTECTED] wrote: hello, I'm currently using Python 2.4, and I don't dare to switch to 2.5, because I depend heavily on Scipy, which is based on 2.4 To test some other Python programs I need Python version 2.5. I've tried to install 2.5 in the past, but got a lot of trouble trying to uninstall it to go back to 2.4. Is there a safe way to install Python 2.5, without affecting the Python 2.4 version and the windows registry, on windows XP ? thanks, Stef Mientki I'm currently running 2.3 and 2.5 on the same XP system with no problems. As I remember the installs didn't effect each other at all. Generally, subsequent installs will offer the possibility of associating themselves with the .py extension. I just deselect this on the .msi options screen -- or go back in and reset the association later if I need to -- and I have run about 5 different versions for compatibility testing without any problems. I'm currently running 2.2, 2.4, 2.5 and the svn head. 2.5 is the default (ie associated with .py files and with its scripts folder on the system PATH). TJG -- http://mail.python.org/mailman/listinfo/python-list
Suite of the imaginary beings now complete for free download!
You can dowload the complete Suite from Ubú's new blog: http://ubumusic.blogspot.com/ Thanks, greetings -- http://mail.python.org/mailman/listinfo/python-list
ANN: Leo 4.4.6 beta 1 released
Leo 4.4.6 beta 1 is available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 Leo 4.4.6 fixes several recently reported bugs, all minor. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.4.6: - Fixes all known bugs. - Added @auto importers for javascript and xml files. - Added find-next-clone and toggle-sparse-move commands. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
Rich Harkins wrote: [EMAIL PROTECTED] wrote: Given a bunch of arrays, if I want to create tuples, there is zip(arrays). What if I want to do the opposite: break a tuple up and append the values to given arrays: map(append, arrays, tupl) except there is no unbound append() (List.append() does not exist, right?). list.append does exist (try the lower-case flavor). Without append(), I am forced to write a (slow) explicit loop: for (a, v) in zip(arrays, tupl): a.append(v) Except that isn't technically the opposite of zip. The opposite would be a tuple of single-dimensional tuples: def unzip(zipped): Given a sequence of size-sized sequences, produce a tuple of tuples that represent each index within the zipped object. Example: zipped = zip((1, 2, 3), (4, 5, 6)) zipped [(1, 4), (2, 5), (3, 6)] unzip(zipped) ((1, 2, 3), (4, 5, 6)) if len(zipped) 1: raise ValueError, 'At least one item is required for unzip.' indices = range(len(zipped[0])) return tuple(tuple(pair[index] for pair in zipped) for index in indices) This is probably not the most efficient hunk of code for this but this would seem to be the correct behavior for the opposite of zip and it should scale well. Modifying the above with list.extend would produce a variant closer to what I think you're asking for: def unzip_extend(dests, zipped): Appends the unzip versions of zipped into dests. This avoids an unnecessary allocation. Example: zipped = zip((1, 2, 3), (4, 5, 6)) zipped [(1, 4), (2, 5), (3, 6)] dests = [[], []] unzip_extend(dests, zipped) dests [[1, 2, 3], [4, 5, 6]] if len(zipped) 1: raise ValueError, 'At least one item is required for unzip.' for index in range(len(zipped[0])): dests[index].extend(pair[index] for pair in zipped) This should perform pretty well, as extend with a comprehension is pretty fast. Not that it's truly meaningful, here's timeit on my 2GHz laptop: bash-3.1$ python -m timeit -s 'import unzip; zipped=zip(range(1024), range(1024))' 'unzip.unzip_extend([[], []], zipped)' 1000 loops, best of 3: 510 usec per loop By comparison, here's the unzip() version above: bash-3.1$ python -m timeit -s 'import unzip; zipped=zip(range(1024), range(1024))' 'unzip.unzip(zipped)' 1000 loops, best of 3: 504 usec per loop Rich As Paddy wrote, zip is its own unzip: zipped = zip((1, 2, 3), (4, 5, 6)) zipped [(1, 4), (2, 5), (3, 6)] unzipped = zip(*zipped) unzipped [(1, 2, 3), (4, 5, 6)] Neat and completely confusing, huh? :-) http://paddy3118.blogspot.com/2007/02/unzip-un-needed-in-python.html -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Debugging pipe IPC
Jim B. Wilson wrote: I have the mother (of all) application(s, written in C++) that occasionally outsources certain tasks to a child Python script. The mother fork/execs (or equivalent) the child and then begins serving the child's requests. The child/client sends requests on its stdout and receives responses on stdin. The interaction is facilitated by a Pyrex extension which handles the lower-level aspects of the conversation and exposes a few functions and classes to the script. This part works peachy keen, but debugging has so far been via printstderr-and-scratch-head. On a contemplative bike ride one day, I imagined how neat it would be to run interactively. On returning, I began to experiment with rebinding sys.stdin and sys.stdout to /dev/tty, using the -i command-line switch, etc. to see if I could devise a child that prompted me with and allowed me to compose/test small snippets on the terminal. So far, no joy. Is this possible? If so, can someone nudge me toward a solution or better yet a recipe? Jim Wilson Gainesville, FL You're looking for the cmd module. http://docs.python.org/lib/module-cmd.html Ian Clark -- http://mail.python.org/mailman/listinfo/python-list
Getting al classes inside a package
How can I get all the clasess inside a package (including it subpackages) ? for example, I have a package with classes A and B and with a subpackage wichs has class C. How can I get a list (and a path) of the classes that exists under the root package ? Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
Using 'property' in evolving code
Hi all- I was reading http://dirtsimple.org/2004/12/python-is-not-java.html, in particular the part about getters and setters are evil: In Java, you have to use getters and setters because using public fields gives you no opportunity to go back and change your mind later to using getters and setters. So in Java, you might as well get the chore out of the way up front. In Python, this is silly, because you can start with a normal attribute and change your mind at any time, without affecting any clients of the class. So, don't write getters and setters. I understand the idea behind this, but how does this transition work in actuality? Lets say I define class Foo initially as... class Foo(object): def __init__(self, x): self.x = x def get_sqrt(self): return sqrt(self.x) Fine. I can read from x, and write to x: def test(): f = Foo(9) print 'sqrt of', f.x, 'is', f.get_sqrt() f.x = 16 print 'sqrt of', f.x, 'is', f.get_sqrt() Let's say later on I decide that f.get_sqrt will be called far more often than f.x is changed, and that it therefore makes sense to store the actual sqrt in the class, rather than calling math.sqrt each time f.get_sqrt is called. So I rewrite Foo: class Foo(object): def __init__(self, x): self._x = x self._my_root = sqrt(x) def _set_x(self, x): self._x = x self._my_root = sqrt(x) def get_sqrt(self): return self._my_root x = property(lambda self: self._x, _set_x) External to the class, everything behaves as before, except with the benefit of not having to wait for slow sqrt each time. self.x is now a property rather than an attribute. Internal to the class, I have to search replace all old occurences of self.x with self._x? Otherwise there is a collision between f.x the attribute and f.x the property? Am I understanding this correctly? Thanks! -Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Using 'property' in evolving code
On Dec 17, 2007 11:48 AM, Steven Clark [EMAIL PROTECTED] wrote: Hi all- I was reading http://dirtsimple.org/2004/12/python-is-not-java.html, in particular the part about getters and setters are evil: In Java, you have to use getters and setters because using public fields gives you no opportunity to go back and change your mind later to using getters and setters. So in Java, you might as well get the chore out of the way up front. In Python, this is silly, because you can start with a normal attribute and change your mind at any time, without affecting any clients of the class. So, don't write getters and setters. I understand the idea behind this, but how does this transition work in actuality? Lets say I define class Foo initially as... class Foo(object): def __init__(self, x): self.x = x def get_sqrt(self): return sqrt(self.x) Fine. I can read from x, and write to x: def test(): f = Foo(9) print 'sqrt of', f.x, 'is', f.get_sqrt() f.x = 16 print 'sqrt of', f.x, 'is', f.get_sqrt() Let's say later on I decide that f.get_sqrt will be called far more often than f.x is changed, and that it therefore makes sense to store the actual sqrt in the class, rather than calling math.sqrt each time f.get_sqrt is called. So I rewrite Foo: class Foo(object): def __init__(self, x): self._x = x self._my_root = sqrt(x) def _set_x(self, x): self._x = x self._my_root = sqrt(x) def get_sqrt(self): return self._my_root x = property(lambda self: self._x, _set_x) External to the class, everything behaves as before, except with the benefit of not having to wait for slow sqrt each time. self.x is now a property rather than an attribute. Internal to the class, I have to search replace all old occurences of self.x with self._x? Otherwise there is a collision between f.x the attribute and f.x the property? You only need to update uses of the attribute that *need* the raw attribute, and not the property. Quite often these are just your (new) getters and setters, as you see. There is no collision - properties and (raw) attributes are accessed the same way. Any use of f.x will go through the property. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Exponent Question
In article [EMAIL PROTECTED], databyss [EMAIL PROTECTED] wrote: I have a simple program and the output isn't what I expect. Could somebody please explain why? Here's the code: #simple program print v = 2 v = 2 print v**v = 2**2 =, v**v print v**v**v = 2**2**2 =, v**v**v print v**v**v**v = 2**2**2**2 =, v**v**v**v #end program Here's the output: v = 2 v**v = 2**2 = 4 v**v**v = 2**2**2 = 16 v**v**v**v = 2**2**2**2 = 65536 I would expect 2**2**2**2 to be 256 Python's ** operator associates to the right, not to the left; thus, 2 ** 2 ** 2 ** 2 ... really means 2 ** (2 ** (2 ** 2)) ... and not ((2 ** 2) ** 2) ** 2 ... as you seem to expect. As usual, you can enforce different associations by explicitly including the parentheses. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie design problem
On Dec 14, 8:02 am, [EMAIL PROTECTED] wrote: Lex is very crude. I've found that it takes about half a day to organize your token definitions and another half day to write a tokenizer by hand. What's the point of the second half-day's work? As someone who has earned a BS in Physics, I have learned one powerful truth: No matter how smart you are, you are not as smart as everyone else. See, the scientific arena of Physics has gotten to the point where it is because people carefully built on each other's work. They spend a great deal of time trying to understand what everyone else is doing and why they do it that way and not another way, and very little time trying to outsmart each other. The brightest bulbs in the physics community don't think they are the brightest bulbs. They are just really good at understanding everyone else and putting it all together. This is summed up in Isaac Newton's statement about seeing farther because he has stood on the shoulders of giants. The same applies to computer science. Either you can take a few days and study about how parsers and lexers really work and why you need them to make your life easier and which implementations are worthwhile, or you can go off and do things on your own and learn the hard way that everyone that went before you was really smarter than you think you are. Five months later, maybe you will have made up the time you would have wasted by reading a good booking on formal languages, lexers, and parsers. At that point, you will opt to use one of the existing libraries, perhaps even Bison and Flex. It's your time that is at stake, man. Don't waste it trying to reinvent the wheel, even if you think you need an upside-down one. -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb syntax issues - HELP
Luke wrote: Bruno Desthuilliers wrote: Luke a écrit : (snip) cursor.execute( CREATE TABLE %s ( name CHAR(40), gender CHAR(40), job CHAR(40), levelTEXT, str TEXT, dex TEXT, intelTEXT, cha TEXT, luc TEXT ) % CharAccount) Err... Are you sure you want a new table here ? (snip) yes, thats the easier way i can think of for now since i am so new to SQL, eventually im sure i will put all the characters into one larger table though... but for now i just dont feal like figuring out how to scan the table for the records i need based on name of character... ill save that for later. (unless there is a very easy way to do it that doesnt require re) That's the whole point of SQL. You write a SELECT statement to extract the records you want. A SELECT statement can select on multiple conditions in one statement, and this is done very efficiently. Just add a characcount field to your record, use one database, and use select statements like cursor.execute(SELECT name, job FROM gamecharacters WHERE characcout=%, (charAccount,)) and MySQL will do the rest. Your database searches will go much faster if you add some indexes. Like INDEX characcount, INDEX name And if you use add UNIQUE INDEX name no two characters can have the same name, even if they're from different accounts. If you wanted to allow duplicate names from the same account, you could write UNIQUE INDEX (name,characcount) which requires that the combo of name and characcount be unique. With that rule in the database, an INSERT that tries to insert a duplicate name will raise an exception. You're on the right track; you just need to understand more of what MySQL can do for you. Which is quite a lot. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
SWIG C Extensions, win32 MinGW: undefined reference
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined reference compiler errors: ..\build\temp.win32-2.5\Release\example_wrap.o:example_wrap.c:(.text+0x670f): undefined reference to `_imp__PyExc_MemoryError' there are many other similar errors all prefaced with _imp__Py, so I am assuming there is a linker error with the python libraries. I have adjusted my PATH variable to include all the python directories (libs/dlls), so I am unclear what else I can try. Any suggestions? FILES FROM TUTORIAL: //example.c #include time.h double My_variable = 3.0; int fact(int n) { if (n = 1) return 1; else return n*fact(n-1); } int my_mod(int x, int y) { return (x%y); } char *get_time() { time_t ltime; time(ltime); return ctime(ltime); } //*** //example.i %module example %{ /* Put header files here or function declarations like below */ extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); %} extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); //*** //setup.py from distutils.core import setup, Extension setup(name='example', version = '1.0', ext_modules=[ Extension('example', ['example.c', 'example.i']) ]) //*** -- View this message in context: http://www.nabble.com/SWIG---C-Extensions%2C-win32---MinGW%3A-undefined-reference-tp14373972p14373972.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: urlparse.urlparse bug - FIX/IN TRACKER
John Nagle wrote: Here's a hostile URL that urlparse.urlparse seems to have mis-parsed. Added to tracker, with proposed fix: http://bugs.python.org/issue1637 John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Fractions on musical notation
Dan Upton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Since the US, at least, uses whole/half/quarter/eighth/sixteenth... | notes, three-quarter and six-eight time falls out... | | I don't think this is technically true, but I've never been able to | tell the difference. I learned three-four, four-four, six-eight, etc. as time sigs. Not a fraction. -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Fractions on musical notation
On Dec 16, 2007 10:32 PM, Terry Reedy [EMAIL PROTECTED] wrote: Dan Upton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Since the US, at least, uses whole/half/quarter/eighth/sixteenth... | notes, three-quarter and six-eight time falls out... | | I don't think this is technically true, but I've never been able to | tell the difference. I learned three-four, four-four, six-eight, etc. as time sigs. Not a fraction. I can't tell whether you're agreeing with me or not... At any rate though, if time signatures really fell out as reducible fractions, then why don't we just reduce 4/4 to 1 and call the whole thing off? ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Fractions on musical notation
Dan Upton [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | | notes, three-quarter and six-eight time falls out... | | | | I don't think this is technically true, but I've never been able to | | tell the difference. | | I learned three-four, four-four, six-eight, etc. as time sigs. Not a | fraction. | | | I can't tell whether you're agreeing with me or not... I disagreed with three-quarter rather than three-four and agreed with six-eight. -- http://mail.python.org/mailman/listinfo/python-list
Re: Debugging pipe IPC
Ian Clark pointed me to: ... the cmd module. http://docs.python.org/lib/module-cmd.html Yes, I found that, but I could only get it to print a nice interactive prompt, (Cmd), read a line of input and discard it. Apparently, I'm too stupid to figure out how to hook it into python. Jim -- http://mail.python.org/mailman/listinfo/python-list
New to Python Would like debug advice
Yep, I'm new to the language, it's been a couple of months. I opted for gvim and console window for developing on a Windows XP box. I'm not a huge fan of IDEs except for when I need some debugging. I've done my googling and see a bunch of options out there for a debugging solution for Python on Windows. I've used Eclipse for a few years for Java development and I understand there is a Python module for it that might make sense. What I'm looking for is advice on what to use to debug general Python programs at the source level, some will be graphical. If the eclipse route is the way to go, that's fine, but I'm wondering what other options people have good luck with. Keep in mind I will probably continue to use Vi/Emacs and a console window for my main development. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: opposite of zip()?
Matt Nordhoff wrote: [snip] As Paddy wrote, zip is its own unzip: zipped = zip((1, 2, 3), (4, 5, 6)) zipped [(1, 4), (2, 5), (3, 6)] unzipped = zip(*zipped) unzipped [(1, 2, 3), (4, 5, 6)] Neat and completely confusing, huh? :-) http://paddy3118.blogspot.com/2007/02/unzip-un-needed-in-python.html I hadn't thought about zip() being symmetrical like that. Very cool... Rich -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb syntax issues - HELP
Luke a écrit : Bruno Desthuilliers wrote: Luke a écrit : (snip) cursor.execute( CREATE TABLE %s ( name CHAR(40), gender CHAR(40), job CHAR(40), levelTEXT, str TEXT, dex TEXT, intelTEXT, cha TEXT, luc TEXT ) % CharAccount) Err... Are you sure you want a new table here ? (snip) yes, thats the easier way i can think of for now since i am so new to SQL, Then keep away from Python long enough to learn the most basic features of SQL. eventually im sure i will put all the characters into one larger table though... but for now i just dont feal like figuring out how to scan the table for the records i need based on name of character... What you think SQL is for ? Selecting a given record (or a given set of record) is actually the most basic SQL operation. ill save that for later. You should not. (unless there is a very easy way to do it that doesnt require re) WTF would you want to use regexps here ??? (snip) What you want here is: sql = INSERT INTO %s (name, gender, job, level, str, dex, intel, cha, luc) VALUES (%%s, %%s, %%s, %%s, %%s, %%s, %%s, %%s, %%s) % CharAccount cursor.execute(sql, (CharName, CharGender, CharJob, CharLevel, Strength, Dexterity, Inteligence, Charm, Luck)) wow, i was so focused on learning the MySQLdb module i have been overlooking simply escaping my % signs the whole time... nice catch, thanks alot. it works like a charm now. Not as far as I'm concerned !-) PROBLEM SOLVED, BUT IF YOU WANT TO ADD ANYTHING, FEEL FREE... Yes : do what everyone here already told you : learn SQL !-) -- http://mail.python.org/mailman/listinfo/python-list
Another newbie design question
I've designed a language, Decaf, for beginners. I've got block comments but not multi-line strings. If you can only have one or the other, which is more helpful? Should I have both? (Make a strong argument here: my design principal is, Designed by a backpacker: when in doubt, leave it out.) -- http://mail.python.org/mailman/listinfo/python-list
python webserver question
I am working on a task to display a wireless network nodes using Google Earth (GE) with KML network links. I am using a simple python webserver (see code below) to serve up the python scripts as KML output to GE for this. import BaseHTTPServer import CGIHTTPServer class Handler(CGIHTTPServer.CGIHTTPRequestHandler): cgi_directories = ['/cgi-bin'] httpd = BaseHTTPServer.HTTPServer(('',8000), Handler) httpd.serve_forever() This works fine for my initial scripts, but now I thinking of combining the python scripts into the server program and making things more efficient. The script file currently reads sensor data from different I/O ports (GPS -serial, network data - ethernet). I am new to python, and was wondering if there might be a better way to run the server side process than how I am doing it now: 1. GE client requests data through KML network link on a periodic update interval 2. python webserver handles request and executes python script in cgi-bin directory 3. python script reads sensor input from serial and ethernet ports and writes data as KML output to GE client 4. repeat process at update interval I am thinking if it would be better to make the process server-side focussed as opposed to client side. Have the server only update sensor data to the client when there has been a change in sensor data, and only send the data that has changed. Has anyone had experience in doing this with python that could point me in the right direction? thx Dale-- http://mail.python.org/mailman/listinfo/python-list
Re: Another newbie design question
[EMAIL PROTECTED] wrote: If you can only [block comments] or [multi-line strings] the other, which is more helpful? I'm afraid no one would use a language that didn't feature block comments. However, inspection of a vast corpus of code might lead one to believe that any commenting capability was completely unnecessary. Should I have both? (Make a strong argument here: my design principal is, Designed by a backpacker: when in doubt, leave it out.) After my brief experience with Python, I don't think I'd advocate the removal of 'd strings. They come in quite handy in a lot of practical cases. And remember: If you need it and you don't have it, you don't need it. (at least in backpacking :) Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
Re: Debugging pipe IPC
Jim B. Wilson wrote: ... The child/client sends requests on its stdout and receives responses on stdin. So, why can't you just run this client on the command line and let the shell handle stdin/stdout for you? Ian Clark -- http://mail.python.org/mailman/listinfo/python-list
Re: Debugging pipe IPC
Ian Clark wrote: Jim B. Wilson wrote: ... The child/client sends requests on its stdout and receives responses on stdin. So, why can't you just run this client on the command line and let the shell handle stdin/stdout for you? I'm not sure I understand the topology of your proposal? And, it's certainly possible the shell has mystical powers of which I am unaware. Are you suggesting a run client that spews the mother's messages to the terminal, and I somehow cut/paste them into the client, running with stdin/stdout unconnected to anything but me? Or is there some combination of tee, etal., I can lash together so that my commands (to the client) don't get mixed up with mother's messages? Some such arrangement would surely help. I often forget the stderr, on my scratch-head debugging prints, and mother gets quite upset when the incoming message doesn't fit the mold :) Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: Gnu/Linux dialogue boxes in python
On 2 Des, 07:02, Donn Ingle [EMAIL PROTECTED] wrote: Paul Boddie wrote: but I'll either upload a new release, or I'll make the code available separately. Thanks, give me a shout when you do -- if you remember! I've now uploaded a new release of the desktop module which is now, in fact, a package: http://www.python.org/pypi/desktop From release 0.3 onwards, the intention is that the desktop.dialog module (spelled in the American way to show the connection with the classic dialog command) will support dialogue boxes for many desktop environments, although only X11 environments are supported so far. There's also a desktop.windows module (no relation to the operating system with the dubious trademark) which currently only supports window introspection in X11 environments, but I imagine that supporting win32 wouldn't be too difficult for those motivated enough to look into it. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: OpenOpt install
dmitrey wrote: Use python setup.py install People should be able to run the distutils commands independently. What are you trying to achieve with this block of code that follows the setup() call? new_name = 'tmp55' os.rename('scikits', new_name) newPath = [] for directory in sys.path: if not 'scikits' in directory: newPath.append(directory)# something wrong with list.remove() sys.path = newPath import scikits reload(scikits) Path = scikits.__path__[0] NewPath = os.path.join(Path, 'openopt') rmtree(NewPath, True) # True means ignore errors copytree(os.path.join(os.path.curdir, new_name, 'openopt'), NewPath) NewPath = Path compileall.compile_dir(NewPath) os.rename(new_name, 'scikits') This just looks like a really bad idea. -- 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in lists
Peter Stahlir wrote: Hi! I have a list of arrays and want to find an array with list.index(x). Is that possible. I get an ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() For example: from numpy import array a = array([1]) b = array([2]) c = [a,b] d = c.index(a) You can't use .index() to do this. numpy arrays use rich comparisons such that (a == b) returns another array, not a boolean. -- 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Another newbie design question
Jim B. Wilson a écrit : [EMAIL PROTECTED] wrote: If you can only [block comments] or [multi-line strings] the other, which is more helpful? I'm afraid no one would use a language that didn't feature block comments. Hem... May I remind you that Python doesn't have block comments ?-) However, inspection of a vast corpus of code might lead one to believe that any commenting capability was completely unnecessary. +1 QOTW !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python Would like debug advice
PatrickMinnesota a écrit : Yep, I'm new to the language, it's been a couple of months. I opted for gvim and console window for developing on a Windows XP box. I'm not a huge fan of IDEs except for when I need some debugging. I've done my googling and see a bunch of options out there for a debugging solution for Python on Windows. I've used Eclipse for a few years for Java development and I understand there is a Python module for it that might make sense. What I'm looking for is advice on what to use to debug general Python programs at the source level, some will be graphical. If the eclipse route is the way to go, that's fine, but I'm wondering what other options people have good luck with. Keep in mind I will probably continue to use Vi/Emacs and a console window for my main development. If you're ok with a command line interface, Python already provide one: http://docs.python.org/lib/module-pdb.html Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports in Packages
[EMAIL PROTECTED] a écrit : While working within a package...what is the 'best practice' way to do your imports. a/__init__.py a/one.py a/two.py a/b/__init__.py a/b/cat.py a/b/dog.py a/c/cow.py Suppose I am working in a/c/cow.py and I need something from a/b/ dog.py. If a/b/__init__.py contains what I need from dog.py, should I do: from a.b import desiredfunction or from a.b.dog import desiredfunction What would be the point of exposing desiredfunction in a/b/__init__ if you still import it from a/b/dog ?-) What are your reasons for preferring one over the other (performance, readability, portability)? What about encapsulation of the package's internal organisation ? (snip) I know that from math import cos x = cos(3) is preferred for performance reasons over import math x = math.cos(3) because of the required lookup. If you only use it once, it won't make such a difference wrt/ lookup time. The make names local trick is mostly useful for tight loops in functions. Else, better to go for readability and favor the first form IMHO - at least you don't wonder where this 'cos' stuff come from !-) Does this mean that that I should import as far down as possible as well? For example, from a.b.c.mod import func versus from a import fun. This won't save anything wrt/ lookup. And I stronly suggest that you read more about namespaces and lookup rules in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie edit/compile/run cycle question
Op Mon, 10 Dec 2007 16:00:04 -0800, schreef Matimus: better written: python -mpy_compile FILENAME The -m option doesn't work in all versions of cpython (I think since v2.4, or maybe 2.3?). -- JanC -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQL_python install failed on Ubuntu 7.1
Bruza a écrit : I installed MySQL 5.0.45 on Ubuntu 7.1 and download MySQL_python from Sourceforge (http://sourceforge.net/project/showfiles.php? group_id=22307). Then I untar the package and executed python setup.py install. But I got compilation errors (see part of the failed messages below). Looks like the installation tried to compile the _mysql extension and failed. Anybody knows a solution to this problem? (snip) In file included from _mysql.c:29: pymemcompat.h:10:20: error: Python.h: No such file or directory Looks like gcc doesn't find the Python's headers. You probably need to install the python-dev (or whatever it's named on Ubuntu) package, that is the one with the required stuff to compile and link C libs relying on CPython implementation. -- http://mail.python.org/mailman/listinfo/python-list
python web server questions
I am working on a task to display a wireless network nodes using Google Earth (GE) with KML network links. I am using a simple python webserver (see code below) to serve up the python scripts as KML output to GE for this. import BaseHTTPServer import CGIHTTPServer class Handler(CGIHTTPServer.CGIHTTPRequestHandler): cgi_directories = ['/cgi-bin'] httpd = BaseHTTPServer.HTTPServer(('',8000), Handler) httpd.serve_forever() This works fine for my initial scripts, but now I thinking of combining the python scripts into the server program and making things more efficient. The script file currently reads sensor data from different I/O ports (GPS -serial, network data - ethernet). I am new to python, and was wondering if there might be a better way to run the server side process than how I am doing it now: 1. GE client requests data through KML network link on a periodic update interval 2. python webserver handles request and executes python script in cgi- bin directory 3. python script reads sensor input from serial and ethernet ports and writes data as KML output to GE client 4. repeat process at update interval I am thinking if it would be better to make the process server-side focussed as opposed to client side. Have the server only update sensor data to the client when there has been a change in sensor data, and only send the data that has changed. Has anyone had experience in doing this with python that could point me in the right direction? thx Dale -- http://mail.python.org/mailman/listinfo/python-list
Re: Another newbie design question
On Dec 17, 2007 1:10 PM, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Hem... May I remind you that Python doesn't have block comments ?-) I suppose we could argue semantics, since strings are actually processed, but they are basically block comments. So, there we are, multiline strings AND block comments! However, inspection of a vast corpus of code might lead one to believe that any commenting capability was completely unnecessary. Lol! Who uses them dern comments anyway? -- http://mail.python.org/mailman/listinfo/python-list
Re: Another newbie design question
Patrick Mullen a écrit : On Dec 17, 2007 1:10 PM, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Hem... May I remind you that Python doesn't have block comments ?-) I suppose we could argue semantics, since strings are actually processed, You guessed !-) but they are basically block comments. Nope, they are basically multiline strings. Their (not that wide AFAICT) use as block comments comes from both the docstrings stuff and the lack of block comments in Python. (snip) However, inspection of a vast corpus of code might lead one to believe that any commenting capability was completely unnecessary. Lol! Who uses them dern comments anyway? Really, I wonder... -- http://mail.python.org/mailman/listinfo/python-list
Re: DNS servers in Python - which ones are a good base for work?
Op Tue, 11 Dec 2007 11:10:52 -0800, schreef John Nagle: I need to do a non-standard DNS server in Python. This is for a spam blacklist type DNS server, not for IP lookup. dnspython seems to be client side only. Oak DNS is deprecated. Suggestions? $ wajig search python-twisted-names python-twisted-names - A DNS protocol implementation with client and server (There might be other solutions too, and I have no experience using it.) -- JanC -- http://mail.python.org/mailman/listinfo/python-list
error during call to cPickle
hello, when pickling a very large object (~200 MB) in python 2.4.4 with cPickle to a file, I get the following errors: python(14896) malloc: *** vm_allocate(size=8421376) failed (error code=3) python(14896) malloc: *** error: can't allocate region python(14896) malloc: *** set a breakpoint in szone_error to debug reducing the size to about half that, everything works fine. is there a limit I should be aware of? I'm running python 2.4.4 under OS X 10.4.11. any thoughts on what might be going on would be most appreciated! cheers, Chris Diehl -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in lists
No problem here too. Using python 2.5 on Ubuntu Gutsy and the newest NumPy 2007/12/17, Robert Kern [EMAIL PROTECTED]: Peter Stahlir wrote: Hi! I have a list of arrays and want to find an array with list.index(x). Is that possible. I get an ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() For example: from numpy import array a = array([1]) b = array([2]) c = [a,b] d = c.index(a) You can't use .index() to do this. numpy arrays use rich comparisons such that (a == b) returns another array, not a boolean. -- 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 -- http://mail.python.org/mailman/listinfo/python-list -- Rafael Sachetto Oliveira Sir - Simple Image Resizer http://rsachetto.googlepages.com -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in lists
Rafael Sachetto wrote: No problem here too. Using python 2.5 on Ubuntu Gutsy and the newest NumPy That's a bug, then. It should fail. It looks like we're not raising the exception when there is only one element. -- 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in lists
Rafael Sachetto wrote: No problem here too. Using python 2.5 on Ubuntu Gutsy and the newest NumPy Okay, I just checked with Travis and we do allow 1-element arrays to have a truth value because it is unambiguous whereas n-element arrays are ambiguous. Regardless, *in general* one cannot use list.index() to find an array. -- 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 -- http://mail.python.org/mailman/listinfo/python-list
Deploying embedded Python
Hi - I'm currently looking into a few deployment issues with our embedded Python interpreter and I'm looking for any information about deploying embedded Python that people may have. Specifically, I'm looking for the following information: 1) How to define a useful subset of the stdlib that can serve as an initial basis for the installation but later allows upgrade to the full library if desirable. In other words, I'd like to deploy a small subset of the stdlib to begin with (simply because of size constraints) which may later be extended to a full stdlib if this is desirable. Has someone done this before? I'd love to have a small Python.zip cross-platform stdlib surrogate that just gets shipped with the product. If not, what is the right starting point for analyzing the dependencies inside the stdlib? 2) How to isolate the embedded interpreter from environmental effects. I have found that on occasion, the interpreter would pick up stray installations which can cause weird problems. Which environmental settings affect the startup of an embedded Python interpreter? How does one work around/remove those dependencies? Is there any information available about how exactly the startup works? What is being read/loaded in which order etc? 3) General advice about deploying embedded Python. Pointers to web sites, general experience (good or bad) etc. are all very welcome. Thanks, - Andreas -- http://mail.python.org/mailman/listinfo/python-list
Keyword args to SimpleXMLRPCServer
Why is the following not working? Is there any way to get keyword arguments working with exposed XMLRPC functions? server.py import SocketServer from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandler # Threaded mix-in class AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer): pass class XMLFunctions(object): def returnArgs(*args, **kwargs): return kwargs.items() # Instantiate and bind to localhost:1234 server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler) # Register example object instance server.register_instance(XMLFunctions()) # run! server.serve_forever() client.py from xmlrpclib import ServerProxy, Error server = ServerProxy(http://localhost:8080;, allow_none=1) # local server try: print server.returnArgs(foo, bar=bar, baz=baz) except Error, v: print ERROR, v [seans-imac:~/Desktop/] halfitalian% ./client.py Traceback (most recent call last): File ./XMLRPC_client.py, line 9, in module print server.returnArgs(foo, bar=bar, baz=baz) TypeError: __call__() got an unexpected keyword argument 'bar' ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling cookies without urllib2 and cookielib
Gabriel Genellina wrote: On 14 dic, 23:44, Joshua Kugler [EMAIL PROTECTED] wrote: I'm using HTTPlib to construct some functional tests for a web app we're writing. We're not using urllib2 because we need support for PUT and DELETE methods, which urllib2 does not do. We also need client-side cookie handling. So, I start reading about cookielib and run across a problem. It's cookie handling is tied quite tightly to urllib2's request object. httplib has somewhat different semantics in its request object. So, you can use cookielib with httplib. And cookie lib has no simple function (that I could find) for passing in a set-cookie header and getting back a CookieJar object (or even a list of Cookie objects). What about correcting the first thing, making urllib2 support HEAD/PUT/ DELETE? SNIP We may have to do that, and then hack on the Redirect handler too so it will properly keep the request method. But that's not our preference, for obvious reasons. :) I just find it hard to believe that no one has ever needed to do cookie handling in a generic way (i.e. input: set-cookie header, output: cookie objects) before. May have to write my own. Or sublcass/extend cookielib. j -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyword args to SimpleXMLRPCServer
On Dec 17, 4:13 pm, Sean DiZazzo [EMAIL PROTECTED] wrote: Why is the following not working? Is there any way to get keyword arguments working with exposed XMLRPC functions? server.py import SocketServer from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandler # Threaded mix-in class AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer): pass class XMLFunctions(object): def returnArgs(*args, **kwargs): return kwargs.items() # Instantiate and bind to localhost:1234 server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler) # Register example object instance server.register_instance(XMLFunctions()) # run! server.serve_forever() client.py from xmlrpclib import ServerProxy, Error server = ServerProxy(http://localhost:8080;, allow_none=1) # local server try: print server.returnArgs(foo, bar=bar, baz=baz) except Error, v: print ERROR, v [seans-imac:~/Desktop/] halfitalian% ./client.py Traceback (most recent call last): File ./XMLRPC_client.py, line 9, in module print server.returnArgs(foo, bar=bar, baz=baz) TypeError: __call__() got an unexpected keyword argument 'bar' ~Sean PS. The same thing happens if you don't use **kwargs... ... class XMLFunctions(object): def returnArgs(foo, bar=None, baz=None): return foo, bar, baz ... -- http://mail.python.org/mailman/listinfo/python-list
very puzzling doctest behaviour
Hi everyone, I've run into a very puzzling doctest behaviour - I'm trying to narrow down the case of it but I'm dealing with multiple files being imported for one of the case and I have not, so far, created a simple example. However, just in case someone had run into something similar, I thought I would ask. I am using the doctest.testfile() interface to load up tests that resides in a text file. Here's a description of the puzzling feature. file 1: all tests pass title print import module_a print So far, nothing surprising... file 2: we have a failure title print import module_a print + 400 lines of text and further tests The second expected fails; instead, we get lt; file 3: all tests pass title print import module_a print lt; + 400 lines of text and further tests Upon further inspection, I find in module_a that, if I comment out a line like import module_b then, tests in file 2 pass again. So, I figure the problem is in module_b. I then did file 4: one failure title print import module_b print + 400 lines of text and further tests Again, this can be fixed by changing the expected output of the second test file 5: no failure title print import module_b print lt; + 400 lines of text and further tests As mentioned, I have not succeeded in narrowing it down further. However, has anyone observed such a behaviour of doctests before? André -- http://mail.python.org/mailman/listinfo/python-list
Re: very puzzling doctest behaviour
Oops, sorry, I made an error in the original description of the problem (test 4 5 below) On Dec 17, 8:25 pm, André [EMAIL PROTECTED] wrote: Hi everyone, I've run into a very puzzling doctest behaviour - I'm trying to narrow down the case of it but I'm dealing with multiple files being imported for one of the case and I have not, so far, created a simple example. However, just in case someone had run into something similar, I thought I would ask. I am using the doctest.testfile() interface to load up tests that resides in a text file. Here's a description of the puzzling feature. file 1: all tests pass title print import module_a print So far, nothing surprising... file 2: we have a failure title print import module_a print + 400 lines of text and further tests The second expected fails; instead, we get lt; file 3: all tests pass title print import module_a print lt; + 400 lines of text and further tests Upon further inspection, I find in module_a that, if I comment out a line like import module_b then, tests in file 2 pass again. So, I figure the problem is in module_b. I then did Sorry, file 4 had NO failure ... so it looked like the problem was NOT in module_b; and yet, when I commented its import in module_a, the problem went away. file 4: one failure title print import module_b print + 400 lines of text and further tests As mentioned, I have not succeeded in narrowing it down further. However, has anyone observed such a behaviour of doctests before? André -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyword args to SimpleXMLRPCServer
Sean DiZazzo [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Why is the following not working? Is there any way to get keyword | arguments working with exposed XMLRPC functions? | | server.py | import SocketServer | from SimpleXMLRPCServer import | SimpleXMLRPCServer,SimpleXMLRPCRequestHandler | | # Threaded mix-in | class | AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer): | pass | | class XMLFunctions(object): |def returnArgs(*args, **kwargs): |return kwargs.items() | | # Instantiate and bind to localhost:1234 | server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler) | | # Register example object instance | server.register_instance(XMLFunctions()) | | # run! | server.serve_forever() | | client.py | from xmlrpclib import ServerProxy, Error | | server = ServerProxy(http://localhost:8080;, allow_none=1) # local | server | | try: |print server.returnArgs(foo, bar=bar, baz=baz) | except Error, v: |print ERROR, v | | | [seans-imac:~/Desktop/] halfitalian% ./client.py | Traceback (most recent call last): | File ./XMLRPC_client.py, line 9, in module |print server.returnArgs(foo, bar=bar, baz=baz) | TypeError: __call__() got an unexpected keyword argument 'bar' In general, C function do not recognize keyword arguments. But the error message above can be reproduced in pure Python. def f(): pass f(bar='baz') Traceback (most recent call last): File pyshell#2, line 1, in -toplevel- f(bar='baz') TypeError: f() takes no arguments (1 given) def f(x): pass f(bar='baz') Traceback (most recent call last): File pyshell#5, line 1, in -toplevel- f(bar='baz') TypeError: f() got an unexpected keyword argument 'bar' Whereas calling a C function typically gives ''.join(bar='baz') Traceback (most recent call last): File pyshell#6, line 1, in -toplevel- ''.join(bar='baz') TypeError: join() takes no keyword arguments But I don't know *whose* .__call__ method got called, so I can't say much more. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: int vs long
En Mon, 17 Dec 2007 10:30:05 -0300, Nick Craig-Wood [EMAIL PROTECTED] escribió: Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 16 Dec 2007 20:28:02 -0300, Troels Thomsen nej tak...@bag.python.org escribi?: The readFile function from the win32 package aparently really expect an integer : def inWaiting(self): Returns the number of bytes waiting to be read flags, comstat = ClearCommError(self.__handle) return comstat.cbInQue ReadFile(h, s.inWaiting()) My code crashes because inWaiting returns a long, not an int That's very strange. The cbInQue field is a DWORD in C, seen as an int in Python. How do you know it returns a long? Why is that different on my machine and my collegues ? Have I or he installed a wrong version of a package? CPython 2.5. And pywin32 build 210, I presume. Was not expecting int-long type problems in excactly python language. Is that because we are navigating so close to the win32 api that the types are more strictly enforced ? Somewhat. At the API level, function arguments have to be converted to native C types, like ReadFile expecting a DWORD. Any number greater than 2**32 won't fit, but I can't think how such thing could happen looking at those few posted code lines. Actually any number = 2**31 won't fit in a python int. 2**31 2147483648L According to my headers DWORD is defined like this typedef unsigned long DWORD; So you might see longs returned when you expected ints if the result was = 0x800. More than 2GB waiting to be read from a serial port? If that were the case the OP has a very big throughput problem rather than an API mismatch :) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
[TRAC] WikiInclude on 0.11 - Noah Kantrowitz blocks bug-fix
Essence: * Deletion of valid defect reports on trac community resources The WikiInclude plugin is not recognised on trac 0.11, thus I took a look an made a small addition to the setup.py (the entry_point). Other users have the same problem, thus I filed a ticket in the trac- hacks community resource. Mr. Noah Kantrowitz closed the ticket as invalid. My comments within this ticket are deleted, directly in the database, which is the same as censorship. I've copied the email-notification from my comment below. [1] Please realize: * this is a real-live defect, which remains unprocessed, thus more users run into this trouble. * My attemps to inform users in the user-threads do not show up in all threads (moderation on trac-users!!!) * The IncludeMacro is not compatible to the WikiInclude macro * My comments were deleted in a non-trackable way * Users of the WikiInclude plugin are not informed in any way You are may wondering why the trac project fails to produce a stable 1.0 version since years. The answer is here: http://case.lazaridis.com/wiki/TracAudit - [1] #2294: Plugin is not detectd on trac 0.11 (even the 0.11 specific one) +--- Reporter: [EMAIL PROTECTED] |Owner: yu-ji Type: defect | Status: reopened Priority: normal |Component: WikiIncludePlugin Severity: critical | Resolution: Keywords: | Release: 0.11 +--- Changes (by [EMAIL PROTECTED]): * status: closed = reopened * resolution: invalid = * summary: Missing entry_point within setup.py = Plugin is not detectd on trac 0.11 (even the 0.11 specific one) Comment: (Mr. Kantrowitz. This is defenitely a defect, which occoured for several users. The provided information helps any user which hits on this ticket via a search. I ask you once more to stop with the deletions on this '''community''' resource). The resolution invalid is incorrect. The problem exists for me '''and other''' users, see e.g.: * [http://groups.google.com/group/trac-users/browse_frm/thread/ de454e7dcf9f0438/d9806ad4a31a14a7 thread 1] * [http://groups.google.com/group/trac-users/browse_frm/thread/ 2ccf4b2855a6f242?q=WikiInclude thread 2] I've solved it whilst simply adding the entry point to the setup.py. It is ok to point to the more flexible and maintained IncludeMacro, but other people possibly just want to continue to use the simpler WikiInclude one. I suggest the maintainer of WikiInclude (or another developer) corrects the setup.py in the repo, and additionally one should place a note in the WikiInclude documentation, that there's a more flexible IncludeMacro available. -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Fractions on musical notation
En Mon, 17 Dec 2007 10:35:39 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: On 2007-12-17, Gabriel Genellina [EMAIL PROTECTED] wrote: On 16 dic, 06:40, Lie [EMAIL PROTECTED] wrote: [btw, off topic, in music, isn't 1/4 and 2/8 different? I'm not very keen of music though, so correct me if I'm wrong.] As a time signature 1/4 has no sense, but 3/4 and 6/8 are different things. In the standard musical notation both numbers are written one above the other, and no division line is used. Note that they just *look* like a fraction when written in text form, like here, because it's not easy to write one above the other. 3/4 is read as three by four, not three quarters -at least in my country- so there is even less confussion. Time signatures are crap. They should have switched to a number over a note value a long time ago; we could have easily avoided abominable travesties like the time signature on the 2nd movement of Beethoven's 9th (B needed four over dotted quarter). If music notation had been invented by a computer scientist we wouldn't be stuck in the current mess in which 6/8 means two completely different meters (3 over quarter, or 2 over dotted quarter). That was proposed by (some great musician from XIX century that I can't remember) but it's hard to change habits. The idea was to use: above, number of beats, and below, the note lasting one beat, *always*. So conventional 6/8 would be 2/dotted quarter with a dotted quarted drawn as itself, not implied by a number. This allows for more meaningful signatures, like 3+3+2/eight note for some Piazzolla tangos that are now written as 4/4 (but don't have the stress pattern for 4/4 at all). And... er... Python doesn't need a time signature data type. But rationals would be quite nifty. ;-) I'm happy enough with rationals as 3rd party library (like gmpy) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting al classes inside a package
En Mon, 17 Dec 2007 14:20:38 -0300, Matias Surdi [EMAIL PROTECTED] escribió: How can I get all the clasess inside a package (including it subpackages) ? for example, I have a package with classes A and B and with a subpackage wichs has class C. How can I get a list (and a path) of the classes that exists under the root package ? If the package does not import its modules or subpackages in __init__.py, you'll have to inspect the __path__ attribute and enumerate .py files. Then, try to load them and find all classes. Warning: There is no way to tell if a certain module is intended to be imported at all or not (might be a test module, an unimplemented feature, a leftover from previous versions, a script intended to be run from the command line...) You can use the inspect standard module (mainly getmembers() and isclass()) to find all classes; remember to filter by the class __module__ attribute (else you'll get imported classes too). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Deploying embedded Python
On Dec 18, 11:07 am, Andreas Raab [EMAIL PROTECTED] wrote: Hi - I'm currently looking into a few deployment issues with our embedded Python interpreter and I'm looking for any information about deploying embedded Python that people may have. Specifically, I'm looking for the following information: 1) How to define a useful subset of the stdlib that can serve as an initial basis for the installation but later allows upgrade to the full library if desirable. In other words, I'd like to deploy a small subset of the stdlib to begin with (simply because of size constraints) which may later be extended to a full stdlib if this is desirable. Has someone done this before? I'd love to have a small Python.zip cross-platform stdlib surrogate that just gets shipped with the product. If not, what is the right starting point for analyzing the dependencies inside the stdlib? 2) How to isolate the embedded interpreter from environmental effects. I have found that on occasion, the interpreter would pick up stray installations which can cause weird problems. Which environmental settings affect the startup of an embedded Python interpreter? PYTHONHOME environment variable, or if embedded in C application use Py_SetPythonHome() before calling Py_Intialize(). This can be used to ensure that specific Python installation is used as source of configuration and modules. How does one work around/remove those dependencies? Is there any information available about how exactly the startup works? Yes, the source code. :-) What is being read/loaded in which order etc? Set PYTHONVERBOSE environment variable to have Python output a lot of information about what it is doing at startup. Graham 3) General advice about deploying embedded Python. Pointers to web sites, general experience (good or bad) etc. are all very welcome. Thanks, - Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: Deploying embedded Python
Graham Dumpleton wrote: 2) How to isolate the embedded interpreter from environmental effects. I have found that on occasion, the interpreter would pick up stray installations which can cause weird problems. Which environmental settings affect the startup of an embedded Python interpreter? PYTHONHOME environment variable, or if embedded in C application use Py_SetPythonHome() before calling Py_Intialize(). This can be used to ensure that specific Python installation is used as source of configuration and modules. Aha! I have never seen this call mentioned in any of the embedding docs. How does one work around/remove those dependencies? Is there any information available about how exactly the startup works? Yes, the source code. :-) Heh, heh. What is being read/loaded in which order etc? Set PYTHONVERBOSE environment variable to have Python output a lot of information about what it is doing at startup. Thanks I'll do that. Cheers, - Andreas -- http://mail.python.org/mailman/listinfo/python-list