ZODB 3.5.1 final released
I'm pleased to announce the release of ZODB 3.5.1 final. This corresponds to the ZODB that will ship in Zope 3.1.0 final. You can download a source tarball or Windows installer from: http://zope.org/Products/ZODB3.5 Note that there are two Windows installers, for Python 2.3 (2.3.5 is recommended) and Python 2.4 (2.4.1 is recommended). ZODB 3.5.1 contains (just) a few bugfixes relative to 3.5.0, involving Zope 3's zeoctl and mkzeoinst scripts, and the ZopeUndo.Prefix class. See the NEWS file for details: http://zope.org/Products/ZODB3.5/NEWS.html The current status of all active ZODB lines can be seen here: http://www.zope.org/Wikis/ZODB/CurrentStatus -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Dynamic character substitution.
John Bausano [EMAIL PROTECTED] wrote: Hello all, I've been using Ansys which is a commercial FEA package which can be controlled through its own scripting language they call APDL. Now I'm trying to write some stand alone code in Python to supplement my current efforts. In Ansys I can do something like this. *do,n,1,3 #loop through n *dim,data%n%,1000,2 #creates variables arrays data1(1000,2), data2(1000,2).. *vread,data%n%,filename%n%#fills arrays with data from filename1,. Generally, you need to think about your problem in a slightly different way. Instead of thinking about creating variables called data1 and data2, think about creating a dictionary called data which contains three elements. For example: data = {} for n in range(3): data[n] = read_from( 'filename%d' % n ) It IS possible to create variables on the fly, but except in very special situations, it is almost never the right way to do things. -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic character substitution.
On Mon, 26 Sep 2005 21:09:51 -0400, John Bausano [EMAIL PROTECTED] wrote: Hello all, ... Funny enough, some people have wanted to substitute a more dynamic character for me on occasion g. -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Library documentation.
Do you think of pydoc? Just make comments in your code this way: def add10(x): this function adds ten to the given variable Then save this into add.py and now (in the same directory): pydoc add Voila, your documentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Library documentation.
Kenneth McDonald wrote: I have a module I'd like to document using the same style... http://docs.python.org/doc/doc.html -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: ncurses programming
thank you very much for your suggestions and links, also slang got my attention. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
On Mon, 26 Sep 2005 15:35:21 -0700, Micah Elliott [EMAIL PROTECTED] wrote: Please read/comment/vote. This circulated as a pre-PEP proposal submitted to c.l.py on August 10, but has changed quite a bit since then. I'm reposting this since it is now Open (under consideration) at http://www.python.org/peps/pep-0350.html. Thanks! Generally, I like this (I've even rambled on the subject myself before ;-) But I don't think DONE is a synonym for TBD or FIXME etc. Some quick reactions: (in case I don't get to detailed comments ;-) 1) IMO DONE (or a well-chosen alternative) should be reserved as a tag that you insert *after* a TODO-type code tag, and should NOT replace the TODO. Cleaning TODO/DONE pairs out of a source is a good job for a tool, which can be given an optional name for a project log file or DONE file etc. or take it from an environment variable or other config mechanism. This could run as a cron job, to clean and log, and notify etc. IOW, no error-prone manual DONE file stuff. 2) In general, I think it might be good to meet Paul Rubin half way re convention vs syntax, but I don't think code tagging should be part of the language syntax per se. (-*- cookies -*- really are defacto source syntax that snuck in by disguise IMO) So perhaps a python command line option could invoke an official tool, with some more options passed to it to do various checking or extracting etc. BF 3) Since a source containing code tags is usually the source for a module, a python expression with implicit scope of this module is a precise way of referring to some elements, e.g., # TODO: clean up uses of magic $MyClass.MAGIC c:magic tool can know MyClass.MAGIC is valid expr or c:$MyClass.MAGIC... ? /BF 4) Why can't a codetag be on the same line as code? What's wrong with assert something, message # ???: Really always so? Is it just to make tag lines python parser independent easily? To be purist, you still have to deal with s = # FIXME: I'm embedded in a string that needs the python parser to exclude or make conventional rule against it. 5) Sometimes time of day can be handy, so maybe 2005-09-26 12:34:56 could be recognized? 6) Maybe some way of bracketing a section of code explicitly, e.g., # FIXME: rework everything in this section sect:xxx def foo(): pass class Bar: and so forth # ...: sect:xxx 7) A way of appending an incremental progress line to an existing code tag line, e.g., # FIXME: This will take a while: rework foo and bar WHO 2005-09-25 # ...: test_foo for new foo works! WHO 2005-09-26 01:23:45-0700 # ...: vacation WHO 2005-10-01 d:2005-10-08 Later a tool can strip this out to the devlog.txt or DONE file, when the tool sees an added progress line like # ---: woohoo, completed ;-) WHO 2005-10-11 04:56:12 My preliminary .02USD for now ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Indexed variables
[EMAIL PROTECTED] wrote: Hello, being an almost complete Python AND programming neophyte I would like to ask the following - very elementary, as I might suspect - question: How do I do the following flawed things right: a1=a2=0 def f(x): if x == a1: a1 = a1 + 1 elif x == a2: a2 = a2 + 1 It seems you are a bit confused about objects and names now... See http://www.fredosaurus.com/notes-cpp/arrayptr/60song.html For a more helpful reference, see http://effbot.org/zone/python-objects.htm (You are comparing integers here, not some kind of variable names that you can see in your code.) I also suspect that you haven't quite understood how functions are intended to work. They should really know as little as possible about the code outside them. Now if I call f with f(a2) only a1, of course, is incremented because the if-clause does only check for the value of the input and the values of a1 and a2 are identical. So how do I define the function such as to discrimate wheter I call it by f(a1) or f(a2) ? Others have talked about mutable and immutable objects, and object immutability is a very good thing. If you have an immutable object a1 somewhere in your code (which has now grown to a few hundred lines) and look at something like... ... a1 = 0 f(a1) print a1 ... ...you will know for sure than the result of the last line is that 0 is printed. There is no way that the line f(a1) can change a1, however the callable object f (function or whatever) is written if this is Python. This makes it easier to write and understand Python code. Sure, f(a1) is bound to mean something important, otherwise it wouldn't be therer, but you can follow how a1 changes without looking at the definition of f right now. That might sound moderately important, but it's really a big benefit. I assume that a real f would do more than add 1, but assuming that it does the same thing with whatever value you pass in, as I suspect you intend, your best option would be to make it return the intended result, and to reassign your variable to that. I.e: ... def f(x): return x + 1 ... a1 = a2 = 0 a1 = f(a1) print a1 a2 = f(a2) ... In this case, even if the definition of f is hundreds of lines away from the other three lines of code, you will see at once that something happens with a1 between the a1 = 0 and print a1. You'll understand that you need to understand what f does to know the state of a1. Assuming that you give your functions more intelligent names than f (maybe add_one in this case) it will be clearer what happens here. Just as in mathematics, it's essential in programming to divide and conquer--to split a problem into small parts, understand and solve each individual part, and get the whole system to work even if the whole system is too complex to fully grasp at once. For that reason, it's important to make the various parts of a program as independent of each other as we can. A function will enforce some kind of contract: It will only do it's work right if it's supplied with reasonable input, but it should know as little as possible about its surroundings. Ideally it knows and assumes nothing about the code that calls it. Another aid in making code clearer is object-oriented programming. With o-o, you define new types (called classes) that capture both the data structure and the program logic that belong together. That way there will be no confusion regarding what kind of object you pass to a function. The function is part of the object itself. But that's another story... -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
[EMAIL PROTECTED] (Bengt Richter) writes: 2) In general, I think it might be good to meet Paul Rubin half way re convention vs syntax, but I don't think code tagging should be part of the language syntax per se. (-*- cookies -*- really are defacto source syntax that snuck in by disguise IMO) So perhaps a python command line option could invoke an official tool, with some more options passed to it to do various checking or extracting etc. I think there should be a single tool that knows about as many of these conventions as possible and warns about misuse, not a bunch of different tools. If there are a bunch of different tools, then knowing which tools to use is yet another convention. Conventions are un-Pythonic IMO, since one of the goals of Python is that the knowledge you need is supposed to be right there, not something you have to absorb through a lot of different lore and PEP's. Java has some of the same disease, and I dislike Javadoc for about the same reason. Maybe the checking functions don't really belong in the compiler/interpreter. PyChecker might be a good home for them, if it's made part of the distro. There could be an interpreter flag to invoke PyChecker automatically. -- http://mail.python.org/mailman/listinfo/python-list
Changing the module not taking effect in calling module
Hi, I've a module report.py having a set of funtions to open/close/write data to a log file. I invoke these functions from another module script.py. Whenever I'm changing something in report.py, I'm running the file (however, it has not effect). After that I'm running script.py again. However, the output is not taking effect. If I shut the IDLE interpreter and all the other files and then reopen again; and then run script.py, the output is taking effect. Is there any way to improve it? I'm new to Python. -Gopal. -- http://mail.python.org/mailman/listinfo/python-list
Re: Self reordering list in Python
LRU caches are nice and simple, but if you want something fancier, with support for squid-like expiry models (ie, using mtime and atime to estimate a stale time, and IMS fetches), you can have a look at my GCache; http://minkirri.apana.org.au/~abo/projects/GCache Even if you don't want something that fancy, it uses a PQueue priority queue to achieve exactly what you want. I provide a pure-python implementation using bisect, but recommend a C extension module with the same name by Andrew Snare which uses a fibonacci heap (python-pqueue is the Debian Package). Note that python 2.3 introduced a heapq module that does for queue lists what bisect does for heap lists. I am planning to modify my PQueue to use it instead of bisect. -- http://mail.python.org/mailman/listinfo/python-list
Re: Carrying variables over from function to function
Bruno Desthuilliers wrote: 2/ functional solution: --- def make_funcs(): x = 0 def _abc(): x = 1 return x + 1 def _abcd(): return x + 1 return _abc, _abcd abc, abcd = make_funcs() print abc() print abcd() The x in function _abc() is not the same as that in make_funcs() and _abcd() as you can easily verify by modifying _abc() to def _abc(): x # raises UnboundLocalError x = 1 return x + 1 Once a variable is assigned a value the compiler treats it as local to that function. Closed-over variables are therefore always read-only, much to the chagrin of Lisp-lovers. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the module not taking effect in calling module
Gopal wrote: Hi, I've a module report.py having a set of funtions to open/close/write data to a log file. I invoke these functions from another module script.py. Whenever I'm changing something in report.py, I'm running the file (however, it has not effect). After that I'm running script.py again. However, the output is not taking effect. If I shut the IDLE interpreter and all the other files and then reopen again; and then run script.py, the output is taking effect. Is there any way to improve it? I'm new to Python. -Gopal. you could try reload(module) instead of import module or running the file. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
Le 27-09-2005, Paul http nous disait: Maybe the checking functions don't really belong in the compiler/interpreter. PyChecker might be a good home for them, if it's made part of the distro. There could be an interpreter flag to invoke PyChecker automatically. Just to make a quick note that pylint [1] already has some limited support for this, though it was developed independently from this PEP. We will most probably add more complete support for codetags based on this PEP in a future release of pylint. [1] http://www.logilab.org/projects/pylint/ -- Alexandre Fayolle LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the module not taking effect in calling module
Gopal wrote: I've a module report.py having a set of funtions to open/close/write data to a log file. I invoke these functions from another module script.py. Whenever I'm changing something in report.py, I'm running the file (however, it has not effect). After that I'm running script.py again. However, the output is not taking effect. If I shut the IDLE interpreter and all the other files and then reopen again; and then run script.py, the output is taking effect. Is there any way to improve it? I'm new to Python. If I understand you correctly, you are importing your module report in script.py. If so, you need reload. When in IDLE, you have a python process running, in which you execute your program. The first time you run script.py after starting IDLE, your module report is imported from file. The next time you run script.py, there is already a module named report in memory. Then the corresponding file will not be executed again. Instead, the one in memory will be used. What I do when I am developing a module for a program is that I both import and reload the module in my main file. Once I think I am done developing, I remove the reload statement. So, in your script.py, I would write: import report reload(report) HTH /MiO -- http://mail.python.org/mailman/listinfo/python-list
Re: Parametric Polymorphism
Pierre Barbier de Reuille [EMAIL PROTECTED] wrote: Now suppose you have two classes A and B, B subclassing A. If you define : @method(A) def myfct(f): do_something_with_f Then, you want it to work with any object of type B ... but with either Guido's or this implementation, it won't ! The problem is much more complex and cannot be solved in constant (or even linear) time. What I read concerning Lisp is they use a cache to optimize method resolution. Yes, I realised that subclass/superclass relations cannot be quicly solved. I haven't looked at the Lisp implementation and can't comment on it. I suspect that using something like splay trees to re-adjust the search graph at every search would speed things up a bit. -- Catalin -- http://mail.python.org/mailman/listinfo/python-list
Re: Telephony project
CheckOn is the working name for my project. Our church community has many elderly who are at home but close to assisted living placements. Many do not have family and rely on volunteer caretakers and lunch providers for their socialization. We are trying to make phone contact with these members to check on their needs, wellbeing, and ability to take care of themselves. In sharing that information with other denominations in our city, we discovered that others were having identical issues. The numbers are larger than we anticipated. Thus the project. Thanks for your interest. -- http://mail.python.org/mailman/listinfo/python-list
@staticmethod, backward compatibility?
How can I write code to take advantage of new decorator syntax, while allowing backward compatibility? I almost want a preprocessor. #if PYTHON_VERSION = 2.4 @staticmethod ... Since python 2.4 will just choke on @staticmethod, how can I do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: @staticmethod, backward compatibility?
Neal Becker wrote: How can I write code to take advantage of new decorator syntax, while allowing backward compatibility? I almost want a preprocessor. #if PYTHON_VERSION = 2.4 @staticmethod ... Since python 2.4 will just choke on @staticmethod, how can I do this? It seems to me that no matter what you do, if it's not done with an external processing tool which requires no changes in the source code, the result will be much uglier than if you just used the pre-2.4 decorator syntax: def meth(): pass meth = staticmethod(meth) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: @staticmethod, backward compatibility?
Neal Becker wrote: How can I write code to take advantage of new decorator syntax, while allowing backward compatibility? I almost want a preprocessor. #if PYTHON_VERSION = 2.4 @staticmethod ... Since python 2.4 will just choke on @staticmethod, how can I do this? Decorators are there because class MyClass: @staticmethod def my_method(arg1, arg2, ...): whatever is nicer than class MyClass: def my_method(arg1, arg2, ...): whatever my_method = staticmethod(my_method) I'm affraid, if you need to be 2.3 compatible then you need to use the later form. Les -- http://mail.python.org/mailman/listinfo/python-list
Re: @staticmethod, backward compatibility?
Neal Becker wrote: How can I write code to take advantage of new decorator syntax, while allowing backward compatibility? I almost want a preprocessor. #if PYTHON_VERSION = 2.4 @staticmethod ... Since python 2.4 will just choke on @staticmethod, how can I do this? Here's one way to do it. The restrictions are: it only works on modules, so you can't use decorators in the main script; it only handles one decorate per function (but shouldn't be too hard to extend); decorators are assumed to only occupy a single line. Example of use: - example.py import decorate23 import test test.C().fred('it', 'works') - end example.py - test.py --- class C: @staticmethod def fred(a, b): print a, b return None @classmethod def freda(cls, a, b): print a, b return None - end test.py --- The contents of decorate23 are, of course, left as an exercise for the reader. Only kidding: - decorate23.py - # Automatically apply decorators for pre-2.4 code import sys import re if sys.version_info (2,4): from imputil import _compile, _suffix_char import imp, sys, marshal, struct, __builtin__ import imputil PATTERN = re.compile('^(?Pindent[\\s]*)@(?Pdecorator.*)\n' '(?Pbody\\1def (?Pid[a-zA-Z_0-9]+)\\(.*(?:\n\\1.*)*)', re.MULTILINE) def autodecorate(source): def replace(match): decorator = match.group('decorator') indent = match.group('indent') id = match.group('id') body = match.group('body') return %(body)s\n%(indent)s%(id)s = %(decorator)s(%(id)s)\n % locals() return PATTERN.sub(replace, source) def hook_compile(pathname, timestamp): Compile (and cache) a Python source file. The file specified by pathname is compiled to a code object and returned. Presuming the appropriate privileges exist, the bytecodes will be saved back to the filesystem for future imports. The source file's modification timestamp must be provided as a Long value. codestring = open(pathname, 'rU').read() if codestring and codestring[-1] != '\n': codestring = codestring + '\n' codestring = autodecorate(codestring) code = __builtin__.compile(codestring, pathname, 'exec') # try to cache the compiled code try: f = open(pathname + _suffix_char, 'wb') except IOError: pass else: f.write('\0\0\0\0') f.write(struct.pack('I', timestamp)) marshal.dump(code, f) f.flush() f.seek(0, 0) f.write(imp.get_magic()) f.close() return code imputil._compile = hook_compile imputil.ImportManager().install() - end decorate23.py - The overhead shouldn't be too bad as the hook will only kick in when the code needs recompiling, but the line numbers in tracebacks refer to the modified code so they'll be slightly out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Carrying variables over from function to function
Peter Otten wrote: Bruno Desthuilliers wrote: 2/ functional solution: --- def make_funcs(): x = 0 def _abc(): x = 1 return x + 1 def _abcd(): return x + 1 return _abc, _abcd abc, abcd = make_funcs() print abc() print abcd() The x in function _abc() is not the same as that in make_funcs() and _abcd() as you can easily verify by modifying _abc() to def _abc(): x # raises UnboundLocalError x = 1 return x + 1 Once a variable is assigned a value the compiler treats it as local to that function. Closed-over variables are therefore always read-only, much to the chagrin of Lisp-lovers. Doh :( I wasn't aware of this limitation (I thought I had done this before in Python and it was working, but it seems that I suffer a severe case of MemoryCorruption...). And this will also teach me to *always* test my code before posting (I usually do...). op Sorry, my bad :( /op peter Thanks for the correction /peter -- bruno desthuilliers ruby -e print '[EMAIL PROTECTED]'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@') python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Metaclasses, decorators, and synchronization
On Tuesday 27 September 2005 00:22, Michele Simionato wrote: It is not that easy, but you can leverage on my decorator module which does exactly what you want: http://www.phyast.pitt.edu/~micheles/python/decorator.zip Excellent. Thank you :-). - Michael -- http://mail.python.org/mailman/listinfo/python-list
Dr. Dobb's Python-URL! - weekly Python news and links (Sep 26)
QOTW: This is Open Source. If you want an initiative, start one. -- Rheinold Birkenfeld I've found jython incredibly helpful in learning java. -- pythonUser_07 The fourth annual Free Software and Open Source Symposium hosted by Canada's largest college includes a talk on Python Power -- Learning, Teaching and Doing with the World's Easiest Programming Language: http://cs.senecac.on.ca/soss/2005/agenda.php http://cs.senecac.on.ca/soss/2005/presentations/george.php The first PyWeek Game Programming Challenge is finished - and it seems it was a great success. See this thread for the results: http://groups.google.com/group/comp.lang.python/msg/e33c3ee2550b90d3 py2exe has been a tremendous help for lots of application developers - but its maintainer is getting tired maintaining it. Any volunteers? http://groups.google.com/group/comp.lang.python/msg/397dbc71441a8890 pythonXX.dll gets larger and larger - read on how you can reduce it in size if you absolutely must in the age of gigabyte-equipped mp3-players: http://groups.google.com/group/comp.lang.python/msg/a20f937a67047406 Laszlo Zolt Nagy learns that self-reordering lists aren't the solution for least-recently-used caches - and is given some pointers where to find implementations of these: http://groups.google.com/group/comp.lang.python/msg/5431d51de8d3c9a1 Mercurial is a Python-based distributed SCM . http://www.selenic.com/mercurial/wiki/index.cgi This is to all of the home-brewn frankenstein-style DNA-sequence manglers: use Python, but don't use immutable strings when a list is all you need to fine-tune your next creation: http://groups.google.com/group/comp.lang.python/msg/78b7f9df4f36b2db sys.argv nicely provides command-line arguments - most of the time. But when it comes to passing internationalized strings on windows, one has to use the win32-API: http://groups.google.com/group/comp.lang.python/browse_frm/thread/22bcdd80266c6b68/5ed8287c40c79e10?q=Python+argv+and+special+charactersrnum=1#5ed8287c40c79e10 Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS
Spoiler to Python Challenge (help!!!)
Damn this is annoying me. I have a webpage with a BZ2 compressed text embedded in it looking like: 'BZh91AYSYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M \x07]\xc9\x14\xe1BA\x06\xbe\x084' Now, if I simply copy and paste this into Python and decompress it - it works a treat. However, I want to read the file containing this data, extract the data and decompress it and this for some reason does not work. I am doing the following (excuse the probably very long handed way of doing it): file = urllib.urlopen(url, proxies=proxies) line = file.readlines() file.close() line = line[20:] line = line[:-1] user = line[0] password = line[1] user = user[5:] user = user[:-2] user = str(user) password = password[5:] password = password[:-2] This gives me a user string of: BZh91AYSYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M \x07]\xc9\x14\xe1BA\x06\xbe\x084 But if I put this into the decompression function, I get a error of 'IOError: invalid data stream'. I know it is the escape characters but how do I get these to be correctly converted into a string compatible with bz2.decompress()? -- http://mail.python.org/mailman/listinfo/python-list
Python batching on XP
Hi ! I want to write a program that backup some databases in the night. Pseudo like this: try: if cmd('net stop dbservice'): s=c://backup'+str(time.time())+'.zip' if cmd('zipit c:\\database '+s): if cmd('map drive backupdrive\\c$ y -user BACKUP -pwd SECRET'): if cmd('copy '+s+' y:\\'): LogSucc() finally: cmd('net start dbservice') I'm trying with os.system() commands. But that is printing the result message to the screen, not to a tuple, like commands.|getstatusoutput(). I need to store this message, because I want to log everything that this program do/print; every of the messages. So: how to I capture the screen, or how to I use |commands.|getstatusoutput() to access the Windows batch/cmd commands, and get their errors/statuses ? Please help me ! Thanks for it: dd | -- http://mail.python.org/mailman/listinfo/python-list
memoru usage of process
I need to know how much memory uses child process (after subprocess.Popen), so I want function: get_memory_usage(pid) I found two ways: - call ps and analyze its output - this is not portable (different output on Linux, Cygwin and QNX) - use resource.getrusage - but it works for self/children, not for single process with given pid Do you know any ideas how to do it in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python batching on XP
You should take a look at the subprocess module http://www.python.org/dev/doc/devel/lib/module-subprocess.html -Larry Bates [EMAIL PROTECTED] wrote: Hi ! I want to write a program that backup some databases in the night. Pseudo like this: try: if cmd('net stop dbservice'): s=c://backup'+str(time.time())+'.zip' if cmd('zipit c:\\database '+s): if cmd('map drive backupdrive\\c$ y -user BACKUP -pwd SECRET'): if cmd('copy '+s+' y:\\'): LogSucc() finally: cmd('net start dbservice') I'm trying with os.system() commands. But that is printing the result message to the screen, not to a tuple, like commands.|getstatusoutput(). I need to store this message, because I want to log everything that this program do/print; every of the messages. So: how to I capture the screen, or how to I use |commands.|getstatusoutput() to access the Windows batch/cmd commands, and get their errors/statuses ? Please help me ! Thanks for it: dd | -- http://mail.python.org/mailman/listinfo/python-list
WindowsError: stack overflow
Hi, I'm developing a program that analyzes all the webpages on my webserver. I've created one class, Filewalker(), with a function that returns the paths of all ASP pages of interest as a list, which I then turn into a tuple. I then iterate over the tuple, passing each path to my Analyzer() class, which immediately creates an instance of Webpage(), which takes the path and using urllib, downloads the source of the webpage and returns it as a string to the Analyzer() object. The Analyzer() object then examines the source, and when it comes across an error in the source, writes the error to a log file. I can get through about 1750 pages of 5000 before I get a WindowsError: stack overflow exception. Any ideas how I can keep the program chugging along? Regards, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Parametric Polymorphism
I haven't been following this whole thread, but it sounds like you want something like PJE's RuleDispatch package. There's a Developer Works article about it, put up very recently: http://www-128.ibm.com/developerworks/linux/library/l-cppeak2/?ca=dgr- lnxw02aScalingPEAK PJE (IIRC) based it off of LISP's system of multi-method dispatch. Instructions for installing can be found here: http://peak.telecommunity.com/ I've used this package quite a bit in the past, and have been very happy with it. It allows for dynamic type AND value based function dispatch. Jay P. -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory stats
linux: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222 Martin v. Löwis wrote: Tarek Ziadé wrote: I am trying to find a general memory profiler that can measure the memory usage in Python program and gather some stats about object usages, and things like that. As Diez says, use gc: gc.getobjects() gives you all container objects. If you want a list of all objects (container or not), you have to compile a debug build of Python. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory stats
Martin v. Löwis wrote: Tarek Ziadé wrote: I am trying to find a general memory profiler that can measure the memory usage in Python program and gather some stats about object usages, and things like that. As Diez says, use gc: gc.getobjects() gives you all container objects. If you want a list of all objects (container or not), you have to compile a debug build of Python. Regards, Martin Ok thanks, I am amazed not to find an existing implementation for this. Regards Tarek -- Tarek Ziadé, Nuxeo RD (Paris, France) CPS Platform : http://www.cps-project.org Zope3 / ECM : http://www.z3lab.org mail: tziade at nuxeo.com; tel: +33 (0) 6 30 37 02 63 -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory stats
gene tani wrote: linux: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222 Yes thanks I have found this one, I need to try it out, but it does not provide a way to refcount, Another solution could be to use trace maybe I am going to try things out Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: Config parser module
wow, Thanks alex, this rocks really, [ i am new to OOP style in python] I am trying to implement it on similar lines, I`ll comeback if I encounter any trouble. thanks again -Jiro Paul McGuire wrote: [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all I am a newbie and I just saw a ongoing thread on Fileprocessing which talks abt config parser. I have writen many pyhton program to parse many kind of text files by using string module and regex. But after reading that config parser thread I feel stunned. Can somebody tell me some intro info how to parse huge data (most of them are input data to application softwares like nastran, abaqus etc) Recently I saw a great work by John on Nastran file parser (i am still trying to understand the program, http://jrfonseca.dyndns.org/svn/phd/python/Data/Nastran/ An example of dat may be like this, (part of) (say point id coordinateSysNo x,y,z ...) GRID 1 12478.0 0.0 256.75 1 GRID 2 12357.25 0.0 256.75 1 GRID 3 12357.25 0.0 199.0 1 (say Elementtype id property point1 point 2 point3 point4 etc) CQUAD4 7231 2156915700570156920.0 CQUAD4 7232 2156925701570256930.0 CQUAD4 7233 2156935702570356940.0 the data file is very complex if i consider all complexities) Is is possible to use config parser module insome way for this. I also have few perl parser (for some part for some particular tasks) and now changing them to python. (I feel perl regex combination is very easy to learn and very powerfull) Any information will be appreciated. -jiro Here's some sample code that might give you some ideas. -- Paul data = \ GRID 1 12478.0 0.0 256.75 1 GRID 2 12357.25 0.0 256.75 1 GRID 3 12357.25 0.0 199.0 1 CQUAD4 7231 2156915700570156920.0 CQUAD4 7232 2156925701570256930.0 CQUAD4 7233 2156935702570356940.0 class Node(object): def __init__(self,s): self.__dict__.update( zip(self.getInitVarNames(), s.split()) ) def __str__(self): return %s %s % (self.__class__.__name__, self.__dict__) class GridNode(Node): def getInitVarNames(self): return id,x,y,z,other.split(',') class Cquad4Node(Node): def getInitVarNames(self): return id,p1,p2,p3,p4,other.split(',') # define mapping of leading keyword to class name typeNodeClassMap = { GRID : GridNode, CQUAD4 : Cquad4Node, } def makeNode(s): nodeType,nodeArgs = s.split( ,1) nodeClass = typeNodeClassMap[nodeType] return nodeClass( nodeArgs ) for line in data.split(\n): if line: n = makeNode(line) print n -- http://mail.python.org/mailman/listinfo/python-list
Re: Telephony project
I was able to do something like this in Python a while back. You'll need one of: (a) A telephone line dialer/monitor DTMF I/O board that works through the serial port, and a phone audio tap that mixes the soundcard I/O to the phone (b) A TAPI-compliant modem that does everything you need (c) A digital POTS phone that is controllable through serial, USB or your LAN, or a TAPI interface. (d) VOIP software and service than uses SIP, etc. (I found this I found this: http://softphones.globaliptel.com/(c50kru45yksjek55xr2b5g45)/_Pages/NoFrames/PageBuilder.aspx?content=4214134c0c4f416982e844bcd86b2955, but am in no way endorsing it. Also check out http://www.sipfoundry.org/) I used method (a) -- (b) tends to be a pain (as most OEM TAPI modems have some fatal flaw or three...) and (c/d) may be more possible now that before. I used voice reco on the input side rather then DTMF, but I was doing it from local phone exensions on the same loop, not for outside calls, and not for the elderly, so DTMF is probably better anyway. (If you need to know the exact hardware I used, I can find out.) The other option is to not have your own hardware at all and use a service -- there are companies provide web services that let you write/generate markup (VoiceXML or other) to make the calls, wait for DTMF or voice input, etc. (Though I had trouble Googling one at the moment - there were more a few years ago...) m Roger [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] CheckOn is the working name for my project. Our church community has many elderly who are at home but close to assisted living placements. Many do not have family and rely on volunteer caretakers and lunch providers for their socialization. We are trying to make phone contact with these members to check on their needs, wellbeing, and ability to take care of themselves. In sharing that information with other denominations in our city, we discovered that others were having identical issues. The numbers are larger than we anticipated. Thus the project. Thanks for your interest. -- http://mail.python.org/mailman/listinfo/python-list
Python 2.4 under WinXP, free VC71 toolkit and VC6 libraries
I have wrapped some inhouse libraries for Python. The development team uses VC6 and DF6.1 for development of these libraries under WinXP. I would like to wrap the libraries for Python and use the official Win Python from python.org. Now I get a segmentation fault in (access violation in NTDLL.DLL). The code used to work on Python 2.3, so I am afraid I have a plroblem in mixing the code generated by different VC versions. Is this the probable cause of my problem, or should the combination work in general (some libraries seem to work). Kind regards Berthold -- __ Address: G / \ L Germanischer Lloyd phone: +49-40-36149-7374 -++- Vorsetzen 35 P.O.Box 111606 fax : +49-40-36149-7320 \__/ D-20459 HamburgD-20416 Hamburg -- http://mail.python.org/mailman/listinfo/python-list
Re: A 'find' utility that continues through zipped directory structure?
B Mahoney wrote: Is there a Python 'find' -like utility that will continue the file search through any zippped directory structure on the find path? something like this? # File: zipfind.py import fnmatch, os, sys, zipfile program, root, name = sys.argv for dirpath, dirnames, filenames in os.walk(root): for file in fnmatch.filter(filenames, name): print os.path.join(dirpath, file) for file in fnmatch.filter(filenames, *.zip): try: zip = zipfile.ZipFile(os.path.join(dirpath, file)) except zipfile.BadZipfile: pass # cannot read this file else: for f in fnmatch.filter(zip.namelist(), name): print os.path.join(dirpath, file) + : + f $ python zipfind.py aggdraw README* aggdraw/README aggdraw/agg2/README.txt aggdraw/dist/aggdraw-1.1b3-20050925.zip:aggdraw-1.1b3-20050925/README.txt /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What is self?
Diez B. Roggisch wrote: This still seems not quite right to me... Or more likely seems to be missing something still. (But it could be this migraine I've had the last couple of days preventing me from being able to concentrate on things with more than a few levels of complexity.) Playing around with the shell a bit gives the impression that calling a method in a instance gives the following (approximate) result... try: leader.__dict__[set_name](John) except: type(leader).__dict__[set_name].__get__(leader, John) # which results in... #Person.set_name(leader, John) except: raise( AttributeError, %s object has no attribute %s \ % (leader, set_name) ) Of course this wouldn't use the object names directly... I guess I'll need to look in the C object code to see exactly how it works. But the links you gave help. I guess you mean to indent the whole part after the first except and put a try beforehand? Yes, I did. I'm not sure why I left out the try. try: leader.__dict__[set_name](John) except: try: type(leader).__dict__[set_name].__get__(leader, John) # which results in... #Person.set_name(leader, John) except: raise( AttributeError, %s object has no attribute %s \ % (leader, set_name) ) Apart from that you seem to be right - there can very well be values in the class dict that don't follow the descriptor-protocol. However my playing around with this stuff indicates that the creation of bound methods relies on the method being wrapped in a descriptor - otherwise, you get the notorious TypeError set_name() takes exactly 1 argument (0 given) as the binding doesn't occur. Regards, Diez What I've noticed is you can block the visibility of a class attribute, which include methods, by inserting an object in the instance with the same name. Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. class a(object): ... def b(self, value): ... print value ... aa = a() def foo(value): ...print %r % value ... aa.b('hello') hello aa.b = foo aa.b('hello') 'hello' del aa.b aa.b('hi there') hi there So the underlying mechanism for calling methods doesn't kick in until *after* an attempt to get an attribute of the same name in the instance. a.boo = boo def boo(self, value): ...print list(value) ... a.boo = boo aa.boo('hello') ['h', 'e', 'l', 'l', 'o'] The attribute aa.boo is not there, so call boo.__get__() in class a. Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamically adding and removing methods
Steven D'Aprano wrote: On Sun, 25 Sep 2005 14:52:56 +, Ron Adam wrote: Steven D'Aprano wrote: Or you could put the method in the class and have all instances recognise it: py C.eggs = new.instancemethod(eggs, None, C) py C().eggs(3) eggs * 3 Why not just add it to the class directly? You just have to be sure it's a class and not an instance of a class. Because I started off explicitly adding functions to instances directly, and when I discovered that didn't work properly, I never even tried adding it to the class until after I discovered that instancemethod() worked. As far as I can see, Python's treatment of functions when you dynamically add them to classes and instances is rather confused. See, for example: py class Klass: ... pass ... py def eggs(self, x): ... print eggs * %s % x ... py inst = Klass() # Create a class instance. py inst.eggs = eggs # Dynamically add a function/method. py inst.eggs(1) Traceback (most recent call last): File stdin, line 1, in ? TypeError: eggs() takes exactly 2 arguments (1 given) From this, I can conclude that when you assign the function to the instance attribute, it gets modified to take two arguments instead of one. Test it by explicitly passing an instance: py inst.eggs(inst, 1) eggs * 1 My hypothesis is confirmed. You defined it to take two arguements.. (self, x). If it's found directly in the object instead of indirectly in the objects parent objects, it calls it just as you defined it. def beacon(self, x): ...print beacon + %s % x ... Did you mean bacon? *wink* Of course... remembering arbitrary word letter sequences is probably my worst skill. ;-) That, and I think for some reason the name Francis Beacon was in my mind at the time. C.beacon = beacon dir(A) ['__doc__', '__module__', 'beacon', 'ham', 'spam'] Okay, you aren't showing all your code. What is A? 'A' is an instace of 'C' which has 'ham' and 'spam' methods in it. Define a funciton and add it directly to class 'C'. def beacon(self, x): ...print beacon + %s % x ... C.beacon = beacon Show that it shows up in instance 'A' and can be used. dir(A) ['__doc__', '__module__', 'beacon', 'ham', 'spam'] A.beacon(3) beacon + 3 Delete the function. And show it's usable as a method from instance 'A'. del beacon dir(A) ['__doc__', '__module__', 'beacon', 'ham', 'spam'] A.beacon(3) beacon + 3 Show it's still bound to class 'C' even thought the function was deleted. dir(C) ['__doc__', '__module__', 'beacon', 'ham', 'spam'] Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: number of python users
Bryan wrote: just for fun, i looked at the top linux distros at distrowatch and looked at what version of python the latest released version is shipping with out of the box: 1. ubuntu hoary - python 2.4.1 2. mandriva 2005 - python 2.4 3. suse 9.3 - python 2.4 4. fedora core 4 - python 2.4.1 5. mepis 3.3.1 - python 2.3.5 6. knoppix 4.0.2 - python 2.3.5 7. debian sarge - python 2.3.5 8. gentoo 2005.1 - python 2.3.5 9. slackware 10.2 - python 2.4.1 10.kubuntu hoary - python 2.4.1 11. freebsd 5.4 - python 2.4 12. xandros 3.0 - python 2.3.4 13. pclinuxos 0.91 - python 2.3.4 no RHEL? (are they still stuck on 2.2, btw?) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: A 'find' utility that continues through zipped directory structure?
An effbot utility? I'll try that. Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: Telephony project
It will be much easier to use asterisk, there's a win32 version aterisk available but it does not support hardware phone, voip only. A clone FXO card only cost $15 on ebay. Roger [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm new to Python and need to do a (low level, I think) telephony project ( POTS, all local calling) in WinXp. 1. Fetch phone number from my ASCII data. 2. Dial (always a local number) phone (through USRobotics 56K? ). 3. Ask @3 questions to called phone number. Y/N Y/N Y/N 4. Save answers to ASCII file. 5. Say 'Thanks', hang up. Repeat till eof() And...I've not seen any telephony books in/for Python. Any and all help, suggestions, directions, etc. would be *GREATLY* appreciated. TIA -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] PEP 350: Codetags
At 03:35 PM 9/26/2005 -0700, Micah Elliott wrote: Please read/comment/vote. This circulated as a pre-PEP proposal submitted to c.l.py on August 10, but has changed quite a bit since then. I'm reposting this since it is now Open (under consideration) at http://www.python.org/peps/pep-0350.html. This seems a little weird to me. On the one hand, seems like a cool idea if you aren't using Eclipse or another IDE that tracks this stuff, but still need some kind of tracking system. But, if that is the case, the notation seems a little bit overkill, especially with respect to tracking who's responsible - i.e., just you. If you have a team that can agree to use the tools, I suppose it might be useful, but then I wonder, why not use something like Trac? Finally, I think there should be something besides just a comment to distinguish these things; like starting with a symbol (e.g. # !FIXME), so that that documentation extraction tools can distinguish code tags from other documentation that just happens to start with a CAPITALIZED word. Overall, I'm kind of -0.5. It seems like a spec in search of an application. The Motivation is sorely lacking - it reads like, hey, it's optional and you can do stuff, where the stuff you can do is deferred to a later section, and is mostly stuff that could easily be done in other ways. For example, FIT-style acceptance test documents, or Python doctest files go a long way towards documenting stories in association with tests, and they don't require you to cram things into comments. (And because they're executable tests, they get kept up-to-date.) Tracking bugfixes with code history is handled nicely by tools like Trac. There are lots of Python documentation tools already. And so on. Really, it reads to me like you came up with the features to sell the format, instead of designing the format to implement specific features. My suggestion: implement some tools, use them for a while, and come back with more focused use cases to show why only this format can work, and why the Python core developers should therefore use it. I'm not saying that you can't have an informational PEP unless it should be used in the stdlib, mind you. Just pointing out that if you can't convince the core developers it's useful, I'm thinking you'll have a hard time convincing the community at large to actually use it. You need to actually have a better mousetrap to present before you ask people to move their cheese. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: What is self?
Ron Adam wrote: What I've noticed is you can block the visibility of a class attribute, which include methods, by inserting an object in the instance with the same name. [snip example of this behavior] Yes, that's true for non-data descriptors (see last two bullets below) Raymond Hettinger [http://users.rcn.com/python/download/Descriptor.htm] The important points to remember are: * descriptors are invoked by the __getattribute__ method * overriding __getattribute__ prevents automatic descriptor calls * __getattribute__ is only available with new style classes and objects * object.__getattribute__ and type.__getattribute__ make different calls to __get__. * data descriptors always override instance dictionaries. * non-data descriptors may be overridden by instance dictionaries. Michael -- http://mail.python.org/mailman/listinfo/python-list
installing cx_Oracle on Unix/Solaris
I'm posting this message here, so that someone googling here will be able to find it. I was having problems installing cx_Oracle on Solaris. The build would fail with a message: ld: fatal: file /apps/oracle/prod/9.2/lib/libclntsh.so: wrong ELF class: ELFCLASS64 I found the solution on Grig Gheorghiu's blog. Grig had similar problems when installing on UNIX, specifically AIX. You can find his very useful report on how he solved the problem, here: http://agiletesting.blogspot.com/2005/05/installing-and-using-cxoracle-on-unix.html and also here: http://agiletesting.blogspot.com/2005/07/installing-python-241-and-cxoracle-on.html To put matters in a nutshell, Oracle 9i installs the 64-bit libraries in $ORACLE_HOME/lib and the 32-bit libraries in $ORACLE_HOME/lib32. Since setup.py is looking by default in $ORACLE_HOME/lib, it finds the 64-bit libraries and it fails. The trick (at least for me) was to change lib to lib32 in my ORACLE_HOME environment setting, and in setup.py. MUCH thanks to Grig for his useful blog! -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory stats
In message [EMAIL PROTECTED], Tarek Ziadé [EMAIL PROTECTED] writes I am trying to find a general memory profiler that can measure the memory usage in Python program and gather some stats about object usages, and things like that. Not a Python module, but Python Memory Validator may fit the bill. No data on the website, just go straight to the beta page and select the product. Windows NT/W2K/XP/etc.. http://www.softwareverify.com http://www.softwareverify.com/beta.php?product=PMVB000 Stephen -- Stephen Kellett Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html Computer Consultancy, Software Development Windows C++, Java, Assembler, Performance Analysis, Troubleshooting -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory stats
Tarek Ziadé wrote: If you want a list of all objects (container or not), you have to compile a debug build of Python. I am amazed not to find an existing implementation for this. the debug build is an existing implementation, of course. /F -- http://mail.python.org/mailman/listinfo/python-list
Problem SQL ADO
Using Python on WinXP going against MS SQL 2000 server. Connection is fine and I have executed several queries successfully. The following SQL statement however gives me an error and I have tried it several different ways: SELECT VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY,VO_DESCRIPTION + \ FROM D014800 LEFT OUTER JOIN D014900 ON (VA_MK_NUMBER_VER = VO_MAKE_NO) AND (VA_MK_YEAR = VO_YEAR) + \ WHERE (((VA_MK_YEAR)=?) AND ((VA_MK_DESCRIP)=?) AND ((VO_MODEL)=?)) I have tried it with a INNER JOIN, JOIN, LEFT JOIN etc and get the following error each time with a syntax error just after the word INNER, JOIN, or LEFT sample message below: com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', Incorrect syntax near the keyword 'LEFT'., None, 0, -2147217900), None) OR com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', Incorrect syntax near the keyword 'INNER'., None, 0, -2147217900), None) any help appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 under WinXP, free VC71 toolkit and VC6 libraries
Le Tue, 27 Sep 2005 17:48:47 +0200, Berthold Höllmann a écrit : I have wrapped some inhouse libraries for Python. How ? Directly coding C code ? The development team uses VC6 and DF6.1 for development of these libraries under WinXP. DF6.1 is Digital FORTRAN 6.1 ? I would like to wrap the libraries for Python and use the official Win Python from python.org. Now I get a segmentation fault in (access violation in NTDLL.DLL). The code used to work on Python 2.3, so I am afraid I have a plroblem in mixing the code generated by different VC versions. Is this the probable cause of my problem, or should the combination work in general (some libraries seem to work). Kind regards Berthold A possible solution would be to write any VC6 and DF6.1 code to generate some DLLs (black boxes) and to use these DLLs from Python by using ctypes, to build your applications. All the CPU intensive code should be in DLLs and the high level stuff (GUI, presentation, application logic, ...) could be in python. (GUI with wnd or venster for example). Regards. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
On Tue, 27 Sep 2005, Bengt Richter wrote: 5) Sometimes time of day can be handy, so maybe 2005-09-26 12:34:56 could be recognized? ISO 8601 suggests writing date-and-times like 2005-09-26T12:34:56 - using a T as the separator between date and time. I don't really like the look of it, but it is a standard, so i'd suggest using it. Bear in mind that if you don't, a black-helicopter-load of blue-helmeted goons to come and apply the rubber hose argument to you. tom -- On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. -- Charles Babbage -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] PEP 350: Codetags
On 9/27/05, Phillip J. Eby [EMAIL PROTECTED] wrote: At 03:35 PM 9/26/2005 -0700, Micah Elliott wrote: Please read/comment/vote. This circulated as a pre-PEP proposal submitted to c.l.py on August 10, but has changed quite a bit since then. I'm reposting this since it is now Open (under consideration) at http://www.python.org/peps/pep-0350.html. My suggestion: implement some tools, use them for a while, and come back with more focused use cases to show why only this format can work, and why the Python core developers should therefore use it. I'm not saying that you can't have an informational PEP unless it should be used in the stdlib, mind you. Just pointing out that if you can't convince the core developers it's useful, I'm thinking you'll have a hard time convincing the community at large to actually use it. You need to actually have a better mousetrap to present before you ask people to move their cheese. :) +1 I agree with PJE almost entirely. Peace Bill Mill bill.mill at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Self reordering list in Python
Actually, after posting this I did some more work on the PQueue modules I had, implementing both bisect and heapq versions. It turns out the bisect version is heaps faster if you ever delete or re-set values in the queue. The problem is heapq is O(N) for finding a particular entry in the Queue, and any time you change or remove something from it you need to heapify it again, which is also O(N). Andew Snare has a C PQueue extension module that is heaps faster from all angles. It uses a fibonacci heap and gets O(lg N) deletes and re-sets. I think it does this by using the dict to speed finding entries it in the heap, and uses some properties of the heap to assign lower efficiently. The queue used in the lrucache will also suffer from the O(N) problem when deleting or reseting values in the cache. -- http://mail.python.org/mailman/listinfo/python-list
Re: Carrying variables over from function to function
Ivan Shevanski wrote: Thanks for your quick responce Roy, thats exactly what I needed. =) No, it isn't! ;) It might seem like a good idea right now, but it's not a good choice in the long run. It's like peeing in bed: Initially it's both a relief and you get warm and cosy, but you'll end upp with a mess that you (or someone else) will need to clean up later. Sure, it's unproblematic in this tiny example, but it's a bad habit to rely on global variables in cases that are easily solved without them. The obvious solution in your case is to just pass on the variable you need. There are several problems with globals that will become appearent as your code grows bigger, and you can't see all details in the program in the same instant. Your global namespace will get cluttered by a lot of names that are used far away in the code, the code in your functions will become difficult to understand, and it will be more difficult to see how the functions interact to each other. Your programs will also be brittle, since a change in one place is more likely to break some other code in another place in your program. Besides, if your code relies on changing global variables, your functions get very restricted: You can't have two or more sets of data being modified by these functions at the same time. It's pretty common in Python, that people use global variables for objects that are really constants (although Python won't enforce that) and it's common that these varaible names are written with CAPS. There are also cases where we want to keep some kind of module global state, and globals can be used for that, but it should be used only when needed. I just scanned through 55 000 lines of Python code in 276 files here at work, and found about a dozen occurences of the global keyword. In other words, it's very uncommon here that we use global variables that aren't just constants. The normal way to share data between functions is to pass data in as arguments, and out as return values. If you want objects to keep state between function calls without passing them around, consider using object-oriented code, but lets wait a bit with that. Anyway, here are two examples of a small program using globals or passing parameters. # Global version def getYear(): global year year = None while year is None: try: year = int(raw_input(prompt)) except ValueError: pass def calcAge(): global age age = current_year - birth_year def printAge(): print **age print You are, age, years. def main(): global prompt prompt = 'What year were you born? ' getYear() global birth_year birth_year = year prompt = 'What year is it now? ' getYear() global current_year current_year = year calcAge() printAge() main() # Parameter passing version def getYear(prompt): year = None while year is None: try: year = int(raw_input(prompt)) except ValueError: pass return year def calcAge(start, end): return end - start def printAge(age): print **age print You are, age, years. def main(): birth_year = getYear('What year were you born? ') current_year = getYear('What year is it now? ') age = calcAge(birth_year, current_year) printAge(age) main() In this case, the fact that getYear() in the global version assigns to the global year when you need to work with two different year is an inconvenience. If you imagine that you'd do something like when was X born, when was Y born, when was Z born, then Y is oldest, you'll see that it's really stupid to have your functions write to globals instead of returning values directly to the caller of the function. -- http://mail.python.org/mailman/listinfo/python-list
Documenting properties
I notice that if I use this syntax: def classname: ... ## # closes the database connection and releases the resources. def close(self): ## # Returns a list of fields fields = property() then doing: help (classname) then the text is listed for the property and the method, whereas if I do this: classname.close.__doc__ then nothing is listed, and to get that I have to use the .. syntax to document: def close(self): closes the datab... then classname.close.__doc__ shows the text. So, my question is, is there a way to get __doc__ support for properties, in effect, use the xxx syntax for documenting properties. Is the preferred way to use xxx or # to document ? Whatever is preferred, what's the upside/downsides of the two beyond what I just explained? -- Lasse Vågsæther Karlsen http://usinglvkblog.blogspot.com/ mailto:[EMAIL PROTECTED] PGP KeyID: 0x2A42A1C2 -- http://mail.python.org/mailman/listinfo/python-list
Re: number of python users
RHEL isn't really big on Distrowatch because Distrowatch is geared more towards users. RHEL 4.1 is using Python 2.3.4 now, btw. -- http://mail.python.org/mailman/listinfo/python-list
Re: Documenting properties
Lasse Vågsæther Karlsen wrote: So, my question is, is there a way to get __doc__ support for properties, in effect, use the xxx syntax for documenting properties. Yes, the property() function accepts a doc argument, as in: property(fget, fset, fdel, doc) ex: MyProp = property(_get, _set, None, This will show up in __doc__) Is the preferred way to use xxx or # to document ? # is for source code commenting (audience is the person reading your code). x is for documenting your API (audience is the person using your code). They are quite different. Whatever is preferred, what's the upside/downsides of the two beyond what I just explained? Nothing really, but something handy to keep in mind is that the string literal (x) can be used to block out huge sections of code during testing, where you'd have to put a # in front of every line otherwise. -- Paul McNett http://paulmcnett.com http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Getting a number out of a string
I'm trying to extract single digit number from a string. t[1] = '06897' I want to get the 7, 9,8 6 seperated out to use but can't find a way to split out the single characters. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Documenting properties
Paul McNett wrote: Whatever is preferred, what's the upside/downsides of the two beyond what I just explained? Nothing really, but something handy to keep in mind is that the string literal (x) can be used to block out huge sections of code during testing, where you'd have to put a # in front of every line otherwise. Except, of course, code that contains string literals with triple quotes. And with a good editor, it's not too difficult to insert a # in front of hundreds of lines (:%s/^/#/g). Gerrit. -- Temperature in Luleå, Norrbotten, Sweden: | Current temperature 05-09-27 20:19:549.8 degrees Celsius ( 49.7F) | -- Det finns inte dåligt väder, bara dåliga kläder. -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Library documentation.
Unfortunately, none of the documentation tools that use documentation strings are suitable for full, serious documentation. There are a number of reasons for this, and I'll touch on a few. The obvious one is that there is no standard format for docstrings, and this creates problems when trying to achieve a uniform look across python documentation. More seriously, there is a major problem with docstrings in that they can only document something that has a docstring; classes, functions, methods, and modules. But what if I have constants that are important? The only place to document them is in the module docstring, and everything else--examples, concepts, and so on--must be thrown in there as well. But there are no agreed on formats and processing pipelines that then allow such a large module docstring, plus other docstrings, to produce a good final document. I do tech writing for a living, so I have some idea of what I'm talking about, I think :-) It's too bad that there is no equivalent of d'oxygen for Python. That is a _nice_ program. Thanks for the advice, Ken On Sep 27, 2005, at 1:21 AM, beza1e1 wrote: Do you think of pydoc? Just make comments in your code this way: def add10(x): this function adds ten to the given variable Then save this into add.py and now (in the same directory): pydoc add Voila, your documentation. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a number out of a string
You can index into a string: s = '06897' s[2] '8' You can also turn each character into an integer, in various ways: [int(c) for c in s] [0, 6, 8, 9, 7] map(int, s) [0, 6, 8, 9, 7] Jeff pgpDMq5e3RucB.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a number out of a string
what about: lst = [digit for digit in '06897'] lst ['0', '6', '8', '9', '7'] Claudio [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] I'm trying to extract single digit number from a string. t[1] = '06897' I want to get the 7, 9,8 6 seperated out to use but can't find a way to split out the single characters. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a number out of a string
Claudio Grondi wrote: what about: lst = [digit for digit in '06897'] lst ['0', '6', '8', '9', '7'] Or.. list('06897') ['0', '6', '8', '9', '7'] Will McGugan -- http://www.willmcgugan.com .join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in jvyy*jvyyzpthtna^pbz) -- http://mail.python.org/mailman/listinfo/python-list
Re: Spoiler to Python Challenge (help!!!)
Ian Vincent [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] line = line[20:] line = line[:-1] please, line = line[20:-1], etc, is easier to read and understand ;-) tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: WindowsError: stack overflow
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I can get through about 1750 pages of 5000 before I get a WindowsError: stack overflow exception. Any ideas how I can keep the program chugging along? A typical source of stack overflow is recursion. Without seeing the code or actual stacktrace, I would guess that you are somehow using recursion instead of iteration. Or perhaps you are analyzing big, deeply nested pages. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
zlib decode fails with -5
Traceback (most recent call last): File string, line 20, in ? File c:\Python24\lib\encodings\zlib_codec.py, line 43, in zlib_decode output = zlib.decompress(input) zlib.error: Error -5 while decompressing data The -5 error appears to be a Z_BUF_ERROR from looking at the manual at http://www.zlib.net/ The original data was 50K. It compressed to 30K. When I try to decompress, this error occurs. I have done this successfully on 150K of data, so I do not know why it would be a space issue. Any ideas or suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Librarydocumentation.
Kenneth McDonald wrote: More seriously, there is a major problem with docstrings in that they can only document something that has a docstring; classes, functions, methods, and modules. But what if I have constants that are important? The only place to document them is in the module docstring, and everything else--examples, concepts, and so on--must be thrown in there as well. But there are no agreed on formats and processing pipelines that then allow such a large module docstring, plus other docstrings, to produce a good final document. fwiw, that's one of reason why I developed PythonDoc (which supports JavaDoc-style documentation for all the usual suspects, but also for con- stants, attributes, and variables) It's too bad that there is no equivalent of d'oxygen for Python. That is a _nice_ program. doesn't doxygen support Python? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a number out of a string
Thanks all! This is just what I needed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 under WinXP, free VC71 toolkit and VC6 libraries
F. Petitjean [EMAIL PROTECTED] writes: Le Tue, 27 Sep 2005 17:48:47 +0200, Berthold Höllmann a écrit : I have wrapped some inhouse libraries for Python. How ? Directly coding C code ? Depends :-) f2py, directly coding C, SWIG. The development team uses VC6 and DF6.1 for development of these libraries under WinXP. DF6.1 is Digital FORTRAN 6.1 ? Yes I would like to wrap the libraries for Python and use the official Win Python from python.org. Now I get a segmentation fault in (access violation in NTDLL.DLL). The code used to work on Python 2.3, so I am afraid I have a plroblem in mixing the code generated by different VC versions. Is this the probable cause of my problem, or should the combination work in general (some libraries seem to work). Kind regards Berthold A possible solution would be to write any VC6 and DF6.1 code to generate some DLLs (black boxes) and to use these DLLs from Python by using ctypes, to build your applications. All the CPU intensive code should be in DLLs and the high level stuff (GUI, presentation, application logic, ...) could be in python. (GUI with wnd or venster for example). As I understand it, ctypes is not really a solution. The code is about data handling and FE analysis. It has not GUI component. I'm not sure how well ctypes works with Numeric arrays, but I'm sure ctypes does not work on Linux and Solaris, but my code has to. Regards. -- Es gelten die Regeln der christlichen Seefahrt: Rot und Grün markiert das sichere Fahrwasser, Schwarz und Gelb markieren Untiefen und Wracks. Christa Sager, Bundestagsfraktionsvorsitzende Bündnis 90/Grüne -- http://mail.python.org/mailman/listinfo/python-list
How can I set the size of a window with tkinter?
Hi I create a canvas that is to big for the default window-size, so it gets cut to fit... How can I increase the window-size to make sure the canvas fits? regards tores -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem SQL ADO
SELECT VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY,VO_DESCRIPTION + \ FROM D014800 LEFT OUTER JOIN D014900 ON (VA_MK_NUMBER_VER = VO_MAKE_NO) AND (VA_MK_YEAR = VO_YEAR) + \ WHERE (((VA_MK_YEAR)=?) AND ((VA_MK_DESCRIP)=?) AND ((VO_MODEL)=?)) Doesn't look like you have a space between VO_DESCRIPTION and FROM SQL statements are a good place to use Python's triple-quote feature: sql = \ SELECT VA_MK_YEAR, VA_MK_DESCRIP, VO_VIN_NO, VO_MODEL, VO_BODY, VO_DESCRIPTION FROM D014800 LEFT OUTER JOIN D014900 ON ( VA_MK_NUMBER_VER = VO_MAKE_NO AND VA_MK_YEAR = VO_YEAR ) WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ? AND VO_MODEL = ? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I set the size of a window with tkinter?
Tor Erik Sønvisen wrote: I create a canvas that is to big for the default window-size, so it gets cut to fit... what default window size? what geometry management approach are you using? (if you're using pack or grid, your toplevel window should adapt itself to the canvas size, unless you're using an obnoxious window manager. if you do, Tkinter may not be able to do much about that...) /F -- http://mail.python.org/mailman/listinfo/python-list
sqlobject performance problems (really)
I'm writing a small project and I decided to try pysqlite. The database consists of one master table with five columns and two detail tables with one and two columns each (not counting foreign key columns). The program scans an input file and inserts data into those three tables. First I used pysqlite (ver 2). It took a few seconds to parse and populate one thousand of main record and five-six thousand detail records (including a print statement for each main record). This is acceptable. Then I decided to give a try to sqlobject (I had to revert to pysqlite 1.x). I created something like this: class T1(SQLObject): col1 = StringCol() col2 = StringCol(length=5) ... det1 = MultipleJoin('T2') det2 = MultipleJoin('T3') class T2(SQLObject): ... t1 = ForeignKey('T1') class T2(SQLObject): ... t1 = ForeignKey('T1') My main loop looks like this: for r1 in par.parse(filename): # r1 is an intermediary object because I didn't # know how to instantiate an instance without # creating a record automatically, especially # because I didn't have all mandatory values # up until the end of the parse so I had to # keep the values in paralel instead of # storing them directly to my brand new class print r t1 = T1(col1=r.col1, ...) for r2 in r1.det1: t2 = T2(..., t1=t1) for r3 in r1.det2: t2 = T3(..., t1=t1) Now this takes around half a second for ONE master record!!! When I turned on the debug mode of connection I could see a lots of *select* and *commit* statements. I tried to disable autocommit but with no success. I also tried to explicitly provide ID column (hoping to avoid select) but also with no success. autocommit off attempt: connection_string = 'sqlite:/' + db_filename +'?autoCommit=0' no select attempt: t1 = T1(id=t1id, col1=r.col1, ...) Any ideas how to make sqlobject work as fast as plain pysqlite. P.S. I used 0.6.1 version of sqlobject, but later I downloaded fresh version from SVN (upgraded pysqlite to 2.x, downloaded formencode, ez_setup, setuptools and maybe others) but it still doesn't work any better. qvx -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I set the size of a window with tkinter?
You may want to read this scrollbar page: http://effbot.org/zone/tkinter-scrollbar-patterns.htm On Tuesday 27 September 2005 12:31, Tor Erik S�nvisen wrote: Hi I create a canvas that is to big for the default window-size, so it gets cut to fit... How can I increase the window-size to make sure the canvas fits? regards tores -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 under WinXP, free VC71 toolkit and VC6 libraries
Berthold Höllmann wrote: I'm sure ctypes doesnot work on Linux and Solaris, but my code has to. I've used ctypes to great effect on Linux. -- Benji York -- http://mail.python.org/mailman/listinfo/python-list
Re: memoru usage of process
On Linux, this may work for you http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222 /Jean Brouwers Jacek Poplawski wrote: I need to know how much memory uses child process (after subprocess.Popen), so I want function: get_memory_usage(pid) I found two ways: - call ps and analyze its output - this is not portable (different output on Linux, Cygwin and QNX) - use resource.getrusage - but it works for self/children, not for single process with given pid Do you know any ideas how to do it in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Librarydocumentation.
Fredrik Lundh wrote: Kenneth McDonald wrote: More seriously, there is a major problem with docstrings in that they can only document something that has a docstring; classes, functions, methods, and modules. But what if I have constants that are important? The only place to document them is in the module docstring, and everything else--examples, concepts, and so on--must be thrown in there as well. But there are no agreed on formats and processing pipelines that then allow such a large module docstring, plus other docstrings, to produce a good final document. fwiw, that's one of reason why I developed PythonDoc (which supports JavaDoc-style documentation for all the usual suspects, but also for con- stants, attributes, and variables) The one thing I dislike about PythonDoc is that it puts everything into comments and thus docstrings are usually neglected. I spend my entire work day at an ipython shell, which makes querying docstrings very easy. In [1]: set? Type: type Base Class: type 'type' String Form:type 'set' Namespace: Python builtin Docstring: set(iterable) -- set object Build an unordered collection. It disappoints me when I have to go open the ElementTree documentation instead of querying the methods themselves. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Silly function call lookup stuff?
Dear pythonians, I've been reading/thinking about the famous function call speedup trick where you use a function in the local context to represent a remoter function to speed up the 'function lookup'. This is especially usefull in a loop where you call the function a zillion time they say. I think this is very odd behavior. Why isn't the result of the first function-lookup cached so that following function calls don't need to do the function-lookup at all? And if the context changes (an import-statement say) reset the cached 'function-lookups'. This way any function would only need to be looked up once. L. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] PEP 350: Codetags
Phillip J. Eby [EMAIL PROTECTED] wrote: At 03:35 PM 9/26/2005 -0700, Micah Elliott wrote: Please read/comment/vote. This circulated as a pre-PEP proposal submitted to c.l.py on August 10, but has changed quite a bit since then. I'm reposting this since it is now Open (under consideration) at http://www.python.org/peps/pep-0350.html. This seems a little weird to me. On the one hand, seems like a cool idea if you aren't using Eclipse or another IDE that tracks this stuff, but still need some kind of tracking system. But, if that is the case, the notation seems a little bit overkill, especially with respect to tracking who's responsible - i.e., just you. There are various Python editors which have had support for a similar style of tags for quite a while. Some allow #anything: comment, others allow # alphanumeric and spaces : comment, even others allow more or less. Some even count exclamation points as an indicator of severity. Personally, though I use tags in some of the code I write, and though the editor I use (and wrote) supports tags, I'm of the opinion that an unofficial spec is sufficient. See koders.com and search for 'fixme' to see some common variants. - Josiah -- http://mail.python.org/mailman/listinfo/python-list
Re: Silly function call lookup stuff?
Lucas Lemmens wrote: Why isn't the result of the first function-lookup cached so that following function calls don't need to do the function-lookup at all? And if the context changes (an import-statement say) reset the cached 'function-lookups'. import isn't the only way for the context to change. how many other ways can you think of ? This way any function would only need to be looked up once. you haven't really thought this over, have you? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Silly function call lookup stuff?
Lucas Lemmens wrote: Dear pythonians, I've been reading/thinking about the famous function call speedup trick where you use a function in the local context to represent a remoter function to speed up the 'function lookup'. This is especially usefull in a loop where you call the function a zillion time they say. I think this is very odd behavior. Why isn't the result of the first function-lookup cached so that following function calls don't need to do the function-lookup at all? I guess because the function name may be re-bound between loop iterations. Are there good applications of this? I don't know. And if the context changes (an import-statement say) reset the cached 'function-lookups'. In general an object doesn't know what names are bound to it and there are many ways besides an import statement of binding/re-binding, so if the context changes is easier said than done. This way any function would only need to be looked up once. L. Would you apply this optimization to all lookups in outer scopes, or just callables? Why? ;-) Michael -- http://mail.python.org/mailman/listinfo/python-list
__call__ in module?
I have a feeling that this is highly unlikely, but does anyone in here know if it's possible to directly call a module, or will I have to wrap it up in a class? i.e., import MyMod MyMod.whatever = Hi? MyMod(meow mix) Thanks in advance -Wes -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Librarydocumentation.
You get to spend all day in ipython? Can I have your job? -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Library documentation.
On Sep 27, 2005, at 12:45 PM, Kenneth McDonald wrote: It's too bad that there is no equivalent of d'oxygen for Python. That is a _nice_ program. I've been using epydoc (http://epydoc.sourceforge.net) for a while now, and it's really nice. The output is very much in the style of Javadoc. Its markup language lets you document module, class, and instance variables and constants by mentioning them in the module or class's docstring. It has its own markup languge (very JavaDoc-ish), but it also supports JavaDoc and reStructuredText syntax. - Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: __call__ in module?
ncf wrote. I have a feeling that this is highly unlikely, but does anyone in here know if it's possible to directly call a module no. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate PythonLibrarydocumentation.
Robert Kern wrote: The one thing I dislike about PythonDoc is that it puts everything into comments and thus docstrings are usually neglected. teaser: from elementtree import ElementTree help(ElementTree) Help on module ElementTree: NAME ElementTree DESCRIPTION # ElementTree # $Id: ElementTree.py 2324 2005-03-16 15:49:27Z fredrik $ # # light-weight XML support for Python 1.5.2 and later. ... CLASSES Element ElementTree QName TreeBuilder XMLParser iterparse class Element | Methods defined here: | | __delitem__(self, index) | | __delslice__(self, start, stop) | | __getitem__(self, index) | | __getslice__(self, start, stop) ... import pythondoc help(ElementTree) Help on module ElementTree: NAME ElementTree DESCRIPTION The Element type is a flexible container object, designed to store hierarchical data structures in memory. CLASSES Element ElementTree QName TreeBuilder XMLParser iterparse class Element | Element class. | | Methods defined here: | | __delitem__(self, index) | Deletes the given subelement. | | __delslice__(self, start, stop) | Deletes a number of subelements. | | __getitem__(self, index) | Returns the given subelement. | | __getslice__(self, start, stop) | Returns a list containing subelements in the given range. ... now, if I could only motivate myself to write a PEP on adding a __help__ hook to pydoc, so that the help command can be taught to do this all by itself... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Librarydocumentation.
Brett Hoerner wrote: You get to spend all day in ipython? Can I have your job? Well, I use the terms work and day rather loosely. I'm a graduate student in geophysics. Somehow it rarely happens during daylight hours and quite possibly wouldn't be called working by an outside observer. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Overhead of individual python apps
I'm setting up a system that consists of several small python applications that all communicate amongst each other on the same pc. When running in Windows, launching each application generates a process, and each of those processes ends up taking up 4MB of system memory. This memory usage is as reported by the Windows Task manager for the python.exe image name. My Question: Is there any way to reduce this per-process overhead? eg: can you set it somehow so that one python.exe instance handles multiple processes? One possibility considered is to run them as threads of a single process rather than multiple processes, but this has other drawbacks for my application and I'd rather not, Another possibility I considered is to strip out all but the most essential imports in each app, but I tested this out and it has marginal benefits. I demonstrated to myself that a simple one liner app consisting of 'x = raw_input()' still eats up 2.7MB . I also tried -O but it, not surprisingly, did nothing for the one-liner. I'm simply running the .py files and I am still on v2.3 All help appreciated! Thanks, Russ -- http://mail.python.org/mailman/listinfo/python-list
Re: Silly function call lookup stuff?
On Tue, 27 Sep 2005 22:41:22 +0200, Fredrik Lundh wrote: Lucas Lemmens wrote: Why isn't the result of the first function-lookup cached so that following function calls don't need to do the function-lookup at all? And if the context changes (an import-statement say) reset the cached 'function-lookups'. import isn't the only way for the context to change. how many other ways can you think of ? So myLocalFunc = hisRemoteFunc may break if you're not carefull you mean. If not then there's room for improvement. This way any function would only need to be looked up once. you haven't really thought this over, have you? /F You haven't really answered my questions have you? L. -- http://mail.python.org/mailman/listinfo/python-list
Re: Silly function call lookup stuff?
On Tue, 27 Sep 2005 13:56:53 -0700, Michael Spencer wrote: Lucas Lemmens wrote: Dear pythonians, I've been reading/thinking about the famous function call speedup trick where you use a function in the local context to represent a remoter function to speed up the 'function lookup'. This is especially usefull in a loop where you call the function a zillion time they say. I think this is very odd behavior. Why isn't the result of the first function-lookup cached so that following function calls don't need to do the function-lookup at all? I guess because the function name may be re-bound between loop iterations. Are there good applications of this? I don't know. Yuk I'd hate that. I think it would be extremely rare. Would the myLocalFunc = hisRemoteFunc optimization break in such a case? If not then why not auto-add a local hisRemoteFunc that points to the remote hisRemoteFunc to the local context when hisRemoteFunc is executed for the first time. And if the context changes (an import-statement say) reset the cached 'function-lookups'. In general an object doesn't know what names are bound to it and there are many ways besides an import statement of binding/re-binding, so if the context changes is easier said than done. My guess (but I'm not a python programmer) is that context changes would be the odd case. So optimizing for not having them ... This way any function would only need to be looked up once. L. Would you apply this optimization to all lookups in outer scopes, or just callables? Why? ;-) Hmmm callables have probably the highest chance of being recalled. Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] PEP 350: Codetags
At 03:35 PM 9/26/2005 -0700, Micah Elliott wrote: Please read/comment/vote. This circulated as a pre-PEP proposal submitted to c.l.py on August 10, but has changed quite a bit since then. I'm reposting this since it is now Open (under consideration) at http://www.python.org/peps/pep-0350.html. -1 Personally I do use code tags in my code, but not from this standardised set, nor would I wish to. I tend to use: TODO SMELL STINK STENCH VOMIT ... depending on context. Sometimes they might relate to third party libraries which the code is a workaround for, and hence can't really be fixed beyond the SMELL stage. STENCH and VOMIT I tend to use as my priority mechanism for TODOs. Generally only used if the code can't be fixed or deleted when the decision to tag the code as STENCH or VOMIT. The last 3 are only very, very rarely used. (I'll also only tend to tag my own code that way since they can be taken the wrong way by people :) An example of how I use SMELL (a long lived comment on the implementation that is wrong, but exists for a reason): # # SMELL : Periodically check if this is still needed or not. # # OVERLAY_FUDGE_OFFSET_FACTOR is the result of experimentally # trying to get SDL_Overlay/pygame.Overlay to work with Xorg/fbdev # based displays on linux. If the overlay is precisely the right # size and shape for the data, it can't be displayed right. # The value must be even, and preferably small. Odd values # result in the picture being sheared/slanted. # # This problem rears itself when the following version numbers are aligned: #SDL : 1.2.8 #pygame : Anything up to/including 1.7.1prerelease #xorg : 6.8.2 #Linux (for fbdev) : 2.6.11.4 It sits there as a clear warning/comment for the next developer. This kind of comment doesn't really map to the contents of the PEP in any sensible way, and yet uses the SMELL code tag as a clear warning. Having a standard set of tags /within/ a project is good. Recommending a single set across all projects seems un-enforceable, and hence loses the stated benefits of uniformity. (Kinda the python equivalent of the C-style-language flame wars of the right place to place braces { } in your code) If the intent is to have an aim for a standard set of tags within the /standard library/, that seems a more reasonable goal, but have a big set of tags is a problem there, since no one will ever really remember a big list of random tags (or is that just me?). I also think the fields idea is a big mistake. As a code standard for a *particular* project it looks fine, but not for all. Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: __call__ in module?
Nope - you can't even force it by binding a __call__ method to the module. For future reference, you can check to see what things *are* callable with the built-in function 'callable'. eg (with sys instead of MyApp): import sys callable(sys) False Also - a thing you can do to sort of do what you want (?) is wrap the code to be executed by the module in a main() function. eg: #-- Start of MyApp.py -- def main(foo): print My cat loves, foo if __name__ == __main__: import sys main( .join(sys.argv[1:])) #-- EOF -- The main function then lets you either run your module from the command line (MyApp.py Meow Mix) or have another module use it with: import MyApp MyApp.main(Meow Mix) -- http://mail.python.org/mailman/listinfo/python-list
Re: Overhead of individual python apps
Qopit [EMAIL PROTECTED] writes: When running in Windows, launching each application generates a process, and each of those processes ends up taking up 4MB of system memory. This memory usage is as reported by the Windows Task manager for the python.exe image name. The first step is to clarify what's being reported. If WTM is reporting the total memory usage for each process, then it's over estimating the total usage by a considerable amount. In particular, all the Python executable code should be shared by all the processes. Unless you load compiled extensions, anyway - those will only be shared by the ones that use them. You'll need something that will give you the stack, heap and code segment sizes separately to work out what the memory usage really is. My Question: Is there any way to reduce this per-process overhead? eg: can you set it somehow so that one python.exe instance handles multiple processes? The OS should do that for you by default. One possibility considered is to run them as threads of a single process rather than multiple processes, but this has other drawbacks for my application and I'd rather not, That shouldn't help memory usage - the data that isn't across processes would need to be thread-private in any case. The reason for the uncertainty is that I'm not positive that Windows behaves sanely in this area. It may be that Windows doesn't have shared executables. In this case, one solution is to move to a modern OS - like v6 Unix :-). mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
On Monday 26 September 2005 10:25 pm, Paul Rubin wrote: I really doubt you'll find much agreement for this (the compiler should enforce it) position. The 'fewer conventions are better' position might enjoy more support, but doesn't strike me as particularly Pythonic (e.g. compare whitespace in Python and C). It's ok if the enforcement isn't strict. In this case, of course, it wouldn't be the compiler, but rather automatic documentation tools that enforce the convention (i.e. they will choke and/or not generate correct documentation if the convention is not followed. The PEP specifically mentions a validating application (check that codetags are correct). Nevertheless, enforcement does occur. This is the same situation as with docstring conventions (fields in epydoc for example, or using restructured text). By having a PEP convention for this sort of thing, it becomes easier for such applications to be written. Doesn't that qualify as non-strict enforcement? -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What tools are used to write and generate Python Library documentation.
On Monday 26 September 2005 10:24 pm, Kenneth McDonald wrote: I have a module I'd like to document using the same style... Google for epydoc, pydoc, and happydoc. You've already received a comment about markup standards, although you will find more information at the web pages for the above tools. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
On Tuesday 27 September 2005 03:07 am, Paul Rubin wrote: [EMAIL PROTECTED] (Bengt Richter) writes: 2) In general, I think it might be good to meet Paul Rubin half way re convention vs syntax, but I don't think code tagging should be part of the language syntax per se. (-*- cookies -*- really are defacto source syntax that snuck in by disguise IMO) So perhaps a python command line option could invoke an official tool, with some more options passed to it to do various checking or extracting etc. I think there should be a single tool that knows about as many of these conventions as possible and warns about misuse, not a bunch of different tools. If there are a bunch of different tools, then knowing which tools to use is yet another convention. [...] Maybe the checking functions don't really belong in the compiler/interpreter. PyChecker might be a good home for them, if it's made part of the distro. There could be an interpreter flag to invoke PyChecker automatically. But that's precisely why it would be valuable to have a PEP -- a central catalog of such conventions makes it possible for checking software to be consistent. If PyChecker were going to check for such things, it would do so only because a standard convention had been established. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Spoiler to Python Challenge (help!!!)
On Tuesday 27 September 2005 08:32 am, Ian Vincent wrote: I have a webpage with a BZ2 compressed text embedded in it looking like: 'BZh91AYSYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M \x07]\xc9\x14\xe1BA\x06\xbe\x084' Now, if I simply copy and paste this into Python and decompress it - it works a treat. However, I want to read the file containing this data, extract the data and decompress it and this for some reason does not work. [...] This gives me a user string of: BZh91AYSYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M \x07]\xc9\x14\xe1BA\x06\xbe\x084 But if I put this into the decompression function, I get a error of 'IOError: invalid data stream'. I know it is the escape characters but how do I get these to be correctly converted into a string compatible with bz2.decompress()? Took me a long time to figure out what you meant. ;-) So the string actually contains the backslashes, not the escaped characters. This works: bz2.decompress(eval(repr(user))) 'huge' (which I take it is what your sample data encoded -- though I can't help but notice it is actually much shorter than the compressed version. ;-)). This may have some security issues, though, since it evaluates essentially any expression given for user. I'd be interested to know if someone knows a more secure way. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Human readable number formatting
When reporting file sizes to the user, it's nice to print '16.1 MB', rather than '16123270 B'. This is the behaviour the command 'df -h' implements. There's no python function that I could find to perform this formatting , so I've taken a stab at it: import math def human_readable(n, suffix='B', places=2): '''Return a human friendly approximation of n, using SI prefixes''' prefixes = ['','k','M','G','T'] base, step, limit = 10, 3, 100 if n == 0: magnitude = 0 #cannot take log(0) else: magnitude = math.log(n, base) order = int(round(magnitude)) // step return '%.1f %s%s' % (float(n)/base**(order*step), \ prefixes[order], suffix) Example usage print [human_readable(x) for x in [0, 1, 23.5, 100, 1000/3, 500, 100, 12.345e9]] ['0.0 B', '1.0 B', '23.5 B', '100.0 B', '0.3 kB', '0.5 kB', '1.0 MB', '12.3 GB'] I'd hoped to generalise this to base 2 (eg human_readable(1024, base=2) == '1 KiB' and enforcing of 3 digits at most (ie human_readable(100) == '0.1 KB' instead of '100 B). However I can't get the right results adapting the above code. Here's where I'd like to ask for your help. Am I chasing the right target, in basing my function on log()? Does this function already exist in some python module? Any hints, or would anyone care to finish it off/enhance it? With thanks Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a number out of a string
On Tue, 27 Sep 2005 20:28:53 +, Claudio Grondi wrote: what about: lst = [digit for digit in '06897'] lst ['0', '6', '8', '9', '7'] No need to use a list comprehension when this works just as well: py list('06897') ['0', '6', '8', '9', '7'] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: __call__ in module?
On Tue, 27 Sep 2005 14:19:13 -0700, ncf wrote: I have a feeling that this is highly unlikely, but does anyone in here know if it's possible to directly call a module, or will I have to wrap it up in a class? Why not try it yourself? Write a quick module like this: Call a module def __call__(): return Thank you for calling. then try to call it from an interactive session: py import caller py caller() Traceback (most recent call last): File stdin, line 1, in ? TypeError: 'module' object is not callable With things this simple, you learn more from doing than from asking. A better question is, if a module object has a __call__ method, shouldn't it *be* callable? That would let you write a script, put the normal Python idiom at the end: if __name__ == __main__: __call__(sys.argv) # instead of main() No major benefit there, we've just changed main to __call__. But then you can call the script as a stand-alone piece of code from within Python: import script result = script(my_args) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: __call__ in module?
ncf wrote: I have a feeling that this is highly unlikely, but does anyone in here know if it's possible to directly call a module, or will I have to wrap it up in a class? You could use trickery with sys.modules to automatically wrap it in a class: import sys from types import ModuleType class CallableModule(ModuleType): def __call__(self): print You called me! mod = FooModule(__name__, __doc__) mod.__dict__.update(globals()) sys.modules[__name__] = mod -- http://mail.python.org/mailman/listinfo/python-list