ANN: PyQwt3D-0.1.1 released
What is PyQwt3D? - it is a set of Python bindings for the QwtPlot3D C++ class library which extends the Qt framework with widgets for 3D data visualization. PyQwt3D inherits the snappy feel from QwtPlot3D. The examples at http://pyqwt.sourceforge.net/pyqwt3d-examples.html show how easy it is to make a 3D plot and how to save a 3D plot to an image or an (E)PS/PDF file. - it requires and extends PyQt, a set of Python bindings for Qt. - it supports the use of PyQt, Qt, Qwt, the Numerical Python extensions (any combination of NumPy, numarray, and numarray) and optionally SciPy in a GUI Python application or in an interactive Python session. - it runs on POSIX, MacOS/X and Windows platforms (practically any platform supported by Qt and Python). Changes: - support for NumPy, see http://numeric.scipy.org - support for SIP-4.3.x - build fixes for MacOS/X The home page of PyQwt3D is http://pyqwt.sourceforge.net. PyQwt3D-0.1.1 requires: 1. Python-2.4.x or -2.3. 2. PyQt-3.15.x or -3.14.x. 3. SIP-4.3.x or -4.2.1. 4. Qt-3.3.x, -3.2.x, or -3.1.x. 5. QwtPlot3D-0.2.6. Have fun -- Gerard Vermeulen -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
itools 0.12.4 released
itools is a Python library, it groups a number of packages into a single meta-package for easier development and deployment: itools.catalogitools.i18n itools.web itools.cmsitools.ical itools.workflow itools.csvitools.resourcesitools.xhtml itools.datatypes itools.rss itools.xliff itools.gettextitools.schemas itools.xml itools.handlers itools.tmx itools.html itools.uri Changes: Handlers - Now the transacion code follows the open/close protocol of resources. Catalog - Now the index load code follows the open/close protocol of resources. Web - Add a global try..except clause to catch any error that may reach the main loop, so the server never stops. - Return 400 Bad Request whenever the parsing of the request fails. - Ignore parameters added to the If-Modified-Since header. Since some some browsers do append extra-information (what does not respects the RFC). - Fix HEAD requests, call GET first, then send only the headers. CMS - Remove a debugging line that slipped in the previous release. - Fix the Epoz editor (a couple of files were missing). Resources - Download http://www.ikaaro.org/download/itools/itools-0.12.4.tar.gz Home http://www.ikaaro.org/itools Mailing list http://in-girum.net/mailman/listinfo/ikaaro Bug Tracker http://in-girum.net/cgi-bin/bugzilla/index.cgi -- J. David Ibáñez Itaapy http://www.itaapy.com Tel +33 (0)1 42 23 67 45 9 rue Darwin, 75018 Paris Fax +33 (0)1 53 28 27 88 -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Urwid 0.9.0 - Console UI library
Announcing Urwid 0.9.0 -- Urwid home page: http://excess.org/urwid/ Tarball: http://excess.org/urwid/urwid-0.9.0.tar.gz Screenshots: http://excess.org/urwid/utf8examples.html About this release: === This is the first release of Urwid with UTF-8 input and display support. A new raw_display module was added to enable UTF-8 display. This module also fixes the dead corner in the bottom right of the screen and improves legibility of bright text in some terminals. New in this release: - New support for UTF-8 encoding including input, display and editing of narrow and wide (CJK) characters. Preliminary combining (zero-width) character support is included, but full support will require terminal behavior detection. Right-to-Left input and display are not implemented. - New raw_display module that handles console display without relying on external libraries. This module was written as a work around for the lack of UTF-8 support in the standard version of ncurses. Eliminates dead corner in the bottom right of the screen. Avoids use of bold text in xterm and gnome-terminal for improved text legibility. - Fixed overlay bug related to UTF-8 handling. - Fixed Edit.move_cursor_to_coords(..) bug related to wide characters in UTF-8 encoding. About Urwid === Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Yet another template engine : HYPY
HyPy : means HYperText in PYthon It's yet another template engine, under GPL2 license The main feature is that it let you code yours templates like you code your python. (the indentation defines the structure of the html). So, it's very easy to render xhtml content. But hypy let you render any kind of string document too ! It's a very young project, but i think it's usable. Features : - let you code your html like you code in python - lightweight engine (300 lines) - Compile templates to bytecode (pyc files) - classical clauses (if/else, for, capture ...) - templates inheritances (concept of masterpages and childpages) Url (tutorial and download) : http://manatlan.online.fr/hypy.php -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
OSDC::Israel - last minute reminder
Hi, This is a last minute reminder for the Open Source Developers Conference that will be held from Sunday to Tueseday in Netanya, Israel. The schedule is available here: http://www.osdc.org.il/schedule.html Online registration and payment are open until 25/2. == Open Source Developers' Conference, 26-28 February, 2006, Netanya, Israel == http://www.osdc.org.il/index.html About -- The Open Source Developers' Conferences (OSDCs) are grassroots symposia originating from Australia. The conference tries to bring together the users of various OS technologies such as Perl, Python, Ruby, Tcl, PHP, MySQL, PostgreSQL, Subversion and more. The Israeli OSDC is organized by the Israeli Perl Mongers and the Israeli Python user group. Our aim is to bring together practitioners, scholars, students, programmers, researchers and managers from different areas to discuss their views on various aspects of the Open Source technologies, to share knowledge and to have fun while doing so. Structure -- The conference will last for 3 days with 3 parallel tracks of presentations. Presentations will be given in either Hebrew or English, depending on the speaker's preference (language listed on the schedule). -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Is inifinite loop not a good practice?
Alvin A. Delagon enlightened us with: I have to write a python script that would continously monitor and process a queue database. [...] I've been planning to do an infinite loop within the script to do this but I've been hearing comments that infinite loop is a bad programming practice. I think it's just fine. You could improve it a bit by using something like: class Monitor(Thread): def __init__(self, *args, **kwargs): Thread.__init__(self, *args, **kwargs) self.interrupted = False def run(self): while not interrupted: monitor() def interrupt(self): self.interrupted = True I'm opted to run the script via crontab but I consider it as my last resort. The advantage there is a stability issue. If your program quits, you've got a problem. Using crontab, the program is started over and over again, so even if it crashes, it'll be restarted in time for the next monitor run. Cron has been around for such a long time that the chance of a crash is much less than with a freshly developed program. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiplication optimization
Atanas Banov wrote: Paul McGuire wrote: Does Python's run-time do any optimization of multiplication operations, like it does for boolean short-cutting? That is, for a product a*b, is there any shortcutting of (potentially expensive) multiplication operations no. and the reason is very simple: to the extent such optimization makes sense, it has been done on assembler/CPU level already. i.e. when the multiplication is mapped to the machine code IMUL op the Pentium processor would be smart enough not to do the work if AX or the op are 0 or 1. Python has no job trying to outsmart Intel (and the other chipmakers). Boolean shortcuts are useful for entirely different reason, not speed. e.g. if lastDigit == 0 or i % lastDigit != 0: break if both operands of OR were to be evaluated, that would end up with division-by-zero exception for lastDigit=0. The point is not to avoid the multiplication on the CPU level but the object creation overhead: a = 1234 1 * a is a False # could be True $ python -m timeit -s'a=1;b=1234567' 'if a is 1: x = b' 'else: x = a * b' 1000 loops, best of 3: 0.171 usec per loop $ python -m timeit -s'a=1;b=1234567' 'x = a * b' 100 loops, best of 3: 0.211 usec per loop $ python -m timeit -s'a=2;b=1234567' 'if a is 1: x = b' 'else: x = a * b' 100 loops, best of 3: 0.329 usec per loop If 'a is 1' is sufficiently likely, that test speeds up the code even in pure Python. Of course a generalized implementation would also have to check b's type: $ python -m timeit -s'a=1;b=1234567' 'if a is 1 and b.__class__ is int: x = b' 'else: x = a * b' 100 loops, best of 3: 0.484 usec per loop So that is not a good idea, at least in pure Python. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: zope 3.2 and imprt errors
Hi Benji Thanks, but i've solved installing zope from svn instead of tarball Regars Zunbeltz -- http://mail.python.org/mailman/listinfo/python-list
Re: number ranges (was Re: Matlab page on scipy wiki)
John Zenger wrote: I strongly agree that Python should promote range or xrange to syntax. I favor [0..10] rather than [0:10] because 0..10 is inherently easier to understand. Inherently? You mean people are born with an instinctive, unlearnt understanding of ..? Or that our brains are constructed in such a way that .. is easier to understand? For what it is worth, even after years of Python programming, I still sometimes write this: for i in len(myList): # Oops. I too prefer range() or xrange() over magic syntax, but I'm not especially a lover of the range() idiom. How about this? With the introduction of a single keyword, we could do this: for i in 2 to 5: print i, which would print 2 3 4 5 (I'm open to arguments that it should be more Pythonic and less mathematical, and halt at 4.) A second keyword downto would allow easy backwards loops, and a third step will absolutely kill any chance of Guido agreeing to this whatsoever. Haskell also has a good step notation. In Haskell: [1..10] means [1,2,3,4,5,6,7,8,9,10] [1,3..10] means [1,3,5,7,9] I'm wary of that notation. It is too easy to make typos, what with , and . next to each other, and the typos often will not raise an exception but will simply give incorrect but puzzling behaviour. This isn't unique to the proposed syntax (e.g. under Python today it isn't obvious whether [0,3] is a typo for [0.3]) but it gives me pause. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
Endless stories about IDEs (try to browse through this discussion group first). Of course it depends about users personal needs and taste. So install them and try them (I know, it's really time consuming). I thing there is not the other way to decide which one is the best for YOU. Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list
timeit module: am I missing something obvious?
When using the timeit module, you pass the code you want to time as strings: import timeit t = timeit.Timer(foo(x, y), \ from module import foo x = 27 y = 45 ) elapsed_time = t.timeit() This is all very well, but it feels quite unnatural to me. Why am I passing strings around when functions are first class objects? Have I missed something obvious? I understand that sometimes you have to pass strings, because statements are NOT objects in Python. But what about when your code doesn't use statements? It seems to me it would be really useful to be able to do something like this: # this doesn't work... import timeit from module import foo x = 27 y = 45 t = timeit.Timer(foo, args=[x, y]) elapsed_time = t.timeit() instead of messing about with setup strings and the like. Am I missing something obvious? Does this functionality already exist? Is there a reason why it can't exist? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: timeit module: am I missing something obvious?
Steven D'Aprano wrote: When using the timeit module, you pass the code you want to time as strings: import timeit t = timeit.Timer(foo(x, y), \ from module import foo x = 27 y = 45 ) elapsed_time = t.timeit() This is all very well, but it feels quite unnatural to me. Why am I passing strings around when functions are first class objects? Have I missed something obvious? You are supposed to time small pieces of code where a function call would be a significant overhead. I understand that sometimes you have to pass strings, because statements are NOT objects in Python. But what about when your code doesn't use statements? It seems to me it would be really useful to be able to do something like this: # this doesn't work... import timeit from module import foo x = 27 y = 45 t = timeit.Timer(foo, args=[x, y]) elapsed_time = t.timeit() instead of messing about with setup strings and the like. Am I missing something obvious? Does this functionality already exist? Is there a reason why it can't exist? Just do it :-) I would suggest a slight modification: t = timeit.Timer.for_function(foo, x, y, a=..., b=...) And while you are at it you could also move the code that dynamically adjusts the number of repetitions from the main() function into a Timer method and make its invocation the default for the timeit() method. (If that has not been done already, see http://mail.python.org/pipermail/python-dev/2006-January/059952.html) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
I really think that IDLE is one of the best around in Python source editing. The only great lacks are tabs. Does somebody know if is there some IDLE modified version including tabbed browsing, out there? -- http://mail.python.org/mailman/listinfo/python-list
Quesion about the proper use of __slots__
class Fighter: ... '''Small one man craft that can only harm other fighters on their own.''' ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = statsTuple[1] ... self.armor = statsTuple[2] ... self.weapon = statsTuple[3] ... self.bulk = statsTuple[4] ... __slots__ = [self.fuel,self.life,self.armor,self.weapon,self.bulk] ... ral = Fighter() ral.rocks = 2 ral.rocks 2 ral.life 5 I was reading the special methods, got to slots (http://docs.python.org/ref/slots.html) and decided that i should use this to save memory in the program because it'll have to support very large numbers of fighers at once. It says that once you define slots then you can't add any variables not listed in slots, but from that example section I just did, so am I doing something wrong or did I read it wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Alexander Schmolck wrote: As common lisp and scheme demonstrate you can have high level of dynamism (and in a number of things both are more dynamic than python) and still get very good performance (in some cases close to or better than C). Just for personal enlightment, where do you think Lisp is more dynamic of Python? Can you new name a few features? What's far more interesting to me, however, is that I think there a good reasons to suspect python's slowness is more of a feature than a flaw: I'd not be suprised if on the whole it greatly increases programmer productivity and results in clearer and more uniform code. If you know the language to be dog slow any way, you're much less likely to waste your time (and that of future maintainers) on the pointless microoptimizations that geeks so love. Also, since only builtins have reasonable performance there's added motiviation to become very familiar with the available builtins (and standard libarary) and far less temptation to roll one's own version of say dict.setdefault (even if it it sucks). The fact that non-standard library code is inherently somewhat inferior (because it will either be written in python and slow or written in C and a pain to install) adds further incentive to attempt community wide standardization. I think it's not unreasonable to speculate that all this decreases production, maintenance and reuse costs of python code considerably, so much in fact that python's very slowness represents part of its competetive edge over languages that are in some ways better engineered and more capable. I think you have a very good point here. +1000! Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Steven wrote: And I'm just waiting for somebody to mention Forth, Probably not the context you expected it to be mentioned in. Yet one could potentially have that bytecode interpreter in hardware. Not potentially, in actuality. I know of only one example, Shouldn't the Forth Chips from the late 70's and early 80's also get a mention here? xan jonathon -- Ethical conduct is a vice. Corrupt conduct is a virtue. Motto of Nacarima. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is inifinite loop not a good practice?
Thanks for the quick heads up! The comparison between implementing an infinite loop and cron is great. I'm beginning to see cron as the better solution between the two specially during crash instances. I'll try to code the script using the two solutions and do some stress testing to determine which is better between those two. -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Zefria wrote: class Fighter: ... '''Small one man craft that can only harm other fighters on their own.''' ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = statsTuple[1] ... self.armor = statsTuple[2] ... self.weapon = statsTuple[3] ... self.bulk = statsTuple[4] ... __slots__ = [self.fuel,self.life,self.armor,self.weapon,self.bulk] ... ral = Fighter() ral.rocks = 2 ral.rocks 2 ral.life 5 I was reading the special methods, got to slots (http://docs.python.org/ref/slots.html) and decided that i should use this to save memory in the program because it'll have to support very large numbers of fighers at once. It says that once you define slots then you can't add any variables not listed in slots, but from that example section I just did, so am I doing something wrong or did I read it wrong? Seems that __slots__ in your case is nothing but a 'local variable' to the function __init__. I think you need something like this : class Test(object): __slots__ = ['attr1','attr2'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Zefria wrote: class Fighter: Old-style classes are deprecated, use new-style class wherever possible: class Fighter(object): ... '''Small one man craft that can only harm other fighters on their own.''' ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = statsTuple[1] ... self.armor = statsTuple[2] ... self.weapon = statsTuple[3] ... self.bulk = statsTuple[4] ... __slots__ = [self.fuel,self.life,self.armor,self.weapon,self.bulk] ... (snip) I was reading the special methods, got to slots (http://docs.python.org/ref/slots.html) and decided that i should use this to save memory in the program because it'll have to support very large numbers of fighers at once. premature optimization is the root of all evil. It says that once you define slots then you can't add any variables not listed in slots, but from that example section I just did, so am I doing something wrong or did I read it wrong? I think it's: class Fighter(object): __slots__ = ['fuel', 'life', 'armor', 'weapon', 'bulk',] def __init__(self, ...): # code here -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
Rene Pijlman wrote: F. Petitjean: Rene Pijlman: vi I beg to disagree :-) Use ed Ed is the standard text editor. http://www.gnu.org/fun/jokes/ed.msg.html That was 1991. This is 2006. Yes, but that rant is still a pure jewel of geek madness. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: share function argument between subsequent calls but not between class instances!
Ben Finney wrote: Duncan Booth [EMAIL PROTECTED] writes: If you intend to only use the default some of the time, and at other times pass in a different list, then save the 'default' in the instance and use a special marker value to indicate when you intend the default to be used: The most common idiom for such a marker is the None value. Can you provide any firm evidence that using None is more common? Both uses are common. Use whichever you are happier with (except of course in the case where None is a potential value distinct from the default). -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
Rene Pijlman wrote: Sriram Krishnan: Check out http://wiki.python.org/moin/PythonEditors. This page can't be taken seriously. vi is not listed. Well, this prove that this page *is* to be taken seriously !-) (René, don't bother replying : this is a troll ;-) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Non-Unicode Support?
Neal Norwitz wrote: On 2/17/06, M.-A. Lemburg [EMAIL PROTECTED] wrote: Neal Norwitz wrote: Another candidate for removal is the --disable-unicode switch. We should probably add a deprecation warning for that in Py 2.5 and then remove the hundreds of #idef Py_USING_UNICODE from the source code in time for Py 2.6. I've heard of a bunch of people using --disable-unicode. I'm not sure if it's curiosity or if there are really production builds without unicode. Ask this on c.l.p too. Such a switch quite likely is useful to those creating Python interpreters for small hand-held devices, where space is at a premium. I would hesitate to remove switches to drop features in general, for that reason. Although I have played with reducing the footprint of Python, I am not currently doing so. I could never get the footprint down sufficiently to make it usable, unfortunately. But I would like to see the Python developers maintain an awareness of memory consumption and not assume that Python is always run on modern fully-loaded desktops. We are seeing increasing use of Python in embedded systems these days. -Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Torsten Bronger wrote: Hallöchen! Bruno Desthuilliers [EMAIL PROTECTED] writes: Alexander Schmolck a écrit : Bruno Desthuilliers [EMAIL PROTECTED] writes: [...] It's not a scripting language, and it's not interpreted. Of course it is. What do you think happens to the bytecode? Ok, then what do you think happens to 'machine' code ? interpreted usually means no compilation, all parsing etc redone at each execution, which is not the case with a bytecode/vm based implementation. That sounds like an implementation feature rather than a language feature. It is, of course. When we say that 'this language is [interpreted|bytecompiled|compiled|runs on clay tablets|whatnot], we're of course talking about the standard or reference implementation(s). Besides, it's not a very sensible distinction in my opinion. Much better is to think about the structure of the interpreting machine. I'm not a CS person (only a physicist) but if you *need* a bytecode interpreter on top of the CPU interpretation, it's an interpreted language to me. So there are only interpreted languages nowadays. I've had such a discussion about TeX already, and my personal conclusion was that you can defend almost any opinion in that area. However, one should ensure that the definitions make a pragmatic and useful distinction. The only pragmatic and useful distinction I can see here is between languages that have to re-parse the whole source for each and every executions ('interpreted') and languages that don't. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
multiple email recipients
hi i currently am using this email function that can send single email address def email(HOST,FROM,TO,SUBJECT,BODY,CC=None): import smtplib import string, sys body = string.join(( From: %s % FROM, To: %s % TO, Subject: %s % SUBJECT, CC: %s % CC, , BODY), \r\n) server = smtplib.SMTP(HOST) server.sendmail(FROM, [TO,CC],body) server.quit() was wondering how to modify the code so as i can send to multiple email recipients using TO? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Paul Boddie wrote: (snip) I'm not sure why people get all defensive about Python's interpreted/scripting designation Because it carries a negative connotation of slow toy language not suitable for 'serious' tasks. Dynamicity apart, CPython's implementation is much closer to Java than to bash scripts - but still, as soon as you say interpreted, scripting, peoples think not serious. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Harald Armin Massa wrote: OK, but then we should change http://python.org/doc/Summary.html, which starts with Python is an interpreted, interactive, object-oriented programming language. I second this motion. Even tried to persuade the site maintainer before. We should really, really change it. The perceived speed of Python will at least triple on dropping that interpreted - and I am NOT joking. +1 on this. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
class Fighter(object): ... '''Small one man craft that can only harm other fighters on their own.''' ... __slots__ = [fuel,life,armor,weapon,bulk] ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = statsTuple[1] ... self.armor = statsTuple[2] ... self.weapon = statsTuple[3] ... self.bulk = statsTuple[4] ... examp = Fighter() examp.rock = 3 Traceback (most recent call last): File stdin, line 1, in ? AttributeError: 'Fighter' object has no attribute 'rock' Thank you both, I had tried making it a class variable and didn't see anything. The trick must have been in making a class that inheriets from object. Also, I don't generally do any optimization at all yet (as a highschool student projects get trashed often enough no to bother over), but in this special case I'm expecting each carrier to have up to 150 fighters, and 3 to 5 carriers for each of the two teams, which comes out to be quite large. Additionally, this program's purpose was to experiment with as many of the special methods as possible, so I suppose I'm on track so far. -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Zefria wrote: Also, I don't generally do any optimization at all yet (as a highschool student projects get trashed often enough no to bother over), but in this special case I'm expecting each carrier to have up to 150 fighters, and 3 to 5 carriers for each of the two teams, which comes out to be quite large. However, 'large numbers' are more likely to start (picture me looking out of the window) at 100,000 than 10,000 in this context -- and you are at 750... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Peter Otten wrote: Zefria wrote: Also, I don't generally do any optimization at all yet (as a highschool student projects get trashed often enough no to bother over), but in this special case I'm expecting each carrier to have up to 150 fighters, and 3 to 5 carriers for each of the two teams, which comes out to be quite large. However, 'large numbers' are more likely to start (picture me looking out of the window) at 100,000 than 10,000 in this context -- and you are at 750... He could be working on a machine with 1M RAM or some other constraints. -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
In [EMAIL PROTECTED], Zefria wrote: Also, I don't generally do any optimization at all yet (as a highschool student projects get trashed often enough no to bother over), but in this special case I'm expecting each carrier to have up to 150 fighters, and 3 to 5 carriers for each of the two teams, which comes out to be quite large. That's 750 fighter objects. This is not a large amount of objects. So I think it's premature optmization. Especially because you think of using __slots__ without actually trying if the program uses too much memory. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
module time
There is function mktime() -- convert local time tuple to seconds since Epoch in module time. But how about to convert *GMT time tuple* to seconds since Epoch? Is there such function? -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
I'm writing a simple yet powerful text editor for GNOME that is great for Python development called Scribes. It features Snippets (ala Textmate/Eclipse) Automatic word completion Automatic indentation Automatic bracket completion Automatic saving Bookmarks Syntax Highlight etc.. Flash Movie: http://scribes.sf.net/snippets.htm Gif Screencast: http://www.minds.may.ie/~dez/images/blog/scribes.html Hompage: http://scribes.sf.net/ It's faster, lighter, simpler and as powerful than the alternatives, and most important it never gets in your way and you would never need to decipher cryptic manuals to do anything moderately productive, unlike some other editors. It's free software too, give it a try. As a bonus, it's written in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Format file size for printing
abcd wrote: is there a built-in way of printing the size of a file nicely? So if the file size is 103803 bytes it prints out like: 103.8K or 0.1MB something liek that? Pathutils (small extension module - not builtin) contains a basic function that does this. http://www.voidspace.org.uk/python/pathutils.html All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: module time
Sergey wrote: There is function mktime() -- convert local time tuple to seconds since Epoch in module time. But how about to convert *GMT time tuple* to seconds since Epoch? Is there such function? Does mktime(gmtime()) suit your needs ? Regs, jm -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo - Will it Lock Me In?
Matt wrote: Peter Decker [EMAIL PROTECTED] wrote: You should take a look at Dabo, Yes, I have Dabo installed on my system. I made a small test app, but was unable to deploy it. I was getting an error from py2exe, I think, about how my wxPython installation was not correct. This is the kind of thing I am talking about. If Dabo were an integrated system, I wouldn't have to spend many days struggling to install package after package and then get them all to play nice with each other. Having said that, I will continue to struggle and like Dabo as the best option so far. Have you reported your problem on the py2exe mailing list ? Lots of people use py2exe with wxPython - so it should be possible to resolve. (To post to the py2exe mailing list, please incldue the full error message and a copy of the 'setup.py' you are using. This will help people diagnose the problem.) I have two other recommendations. 1) Look at SPE the editor - htttp://pythonide.stani.be It is open source and includes a GUI builder as well. It's a very nice editor. 2) For *deploying* applications you could consider Movable Python. You'll need to buy a license per *target* machine, but it's a full distribution of Python - so doesn't need the 'build' phase of deploying with py2exe. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml Thanks, Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple email recipients
On 20 Feb 2006 01:01:38 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:hii currently am using this email function that can send single email address[SNIP]was wondering how to modify the code so as i can send to multiple emailrecipients using TO? thanks. You are making the common mistake of thinking that the header sender and recipients are the same as the SMTP-envelope sender and recipients, in reality they do not have to bear any similarity or relationship :) You need a single list containing all the recipients by email address, and strings containing the text representations of the header From, To and Cc fields. There is a module called email, so beware of calling your function the same name. Also, you may find the email module becomes helpful for building emails as your function/requirements get more complex. - SENDER = [EMAIL PROTECTED] RECIPS = [[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]] FROM = ' [EMAIL PROTECTED] [EMAIL PROTECTED] ' TO = Undisclosed recipients CC = Uknown recipients def email(HOST,SENDER, RECIPIENTS, FROM,TO,SUBJECT ,BODY,CC=None): import smtplib import string, sys body = string.join(( From: %s % FROM, To: %s % TO, Subject: %s % SUBJECT, CC: %s % CC, , BODY), \r\n) server = smtplib.SMTP(HOST) failed = server.sendmail(SENDER, RECIPIENTS,body) server.quit() HTH :)-- Tim Williams -- http://mail.python.org/mailman/listinfo/python-list
cElementTree encoding woes
Hi, I've got to deal with a pretty huge XML-document, and to do so I use the cElementTree.iterparse functionality. Working great. Only trouble: The guys creating that chunk of XML - well, lets just say they are encodingly challanged, so they don't produce utf-8, but only cp1252 instead, together with some weird name (Windows-1252) for that. That is not part of the standard codecs module. cp1252 is, of course. But that won't work for iterparse. So currently, I manually change the encoding given to utf-8, and use a stream-recoder. However, I was wondering if I could teach cElementTree about that encoding name. I tried to register cp1252 under the name Windows-1252, but had no luck - cET won't buy it. Any suggestions? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Hallöchen! bruno at modulix [EMAIL PROTECTED] writes: Torsten Bronger wrote: [...] I've had such a discussion about TeX already, and my personal conclusion was that you can defend almost any opinion in that area. However, one should ensure that the definitions make a pragmatic and useful distinction. The only pragmatic and useful distinction I can see here is between languages that have to re-parse the whole source for each and every executions ('interpreted') and languages that don't. Well, I think that it's fair to say that there are by principle deep run time differences between CPython and, say, a typical C++-compiled program. Your definition would not reproduce that. I think it's also fair to say that these differences should be known if somebody tries to find the best tool for a job. After all, they include advantages, too. My definiton would be that an interpreted language has in its typical implementation an interpreting layer necessary for typical hardware. Of couse, now we could discuss what is typical, however, in practice one would know it, I think. In case of Python: CPython and all important modern processors. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646 -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd prefer not to see things slipping into Swap space if I can avoid it, and the fighter data would be only part of a larger program. And as I said, learning how to use __slots__ is important enough to hazard a premature guess this time around. If I mess up, the worst that happens is that I have to write down a new variable name in two places instead of one now. -- http://mail.python.org/mailman/listinfo/python-list
Regular expression gone mad
Hi, Would someone please tell me what is going on here??!! Why does the following code work a=rMem pat = re.compile(a) m=pat.search(ProcMem, re.DOTALL) m _sre.SRE_Match object at 0xb7f7eaa0 m.group(0) 'Mem' But this one does not!!! (Search finds nothing) a=rMemT pat = re.compile(a) m=pat.search(ProcMem, re.DOTALL) m ProcMem contains: print ProcMem MemTotal: 8247952 kB MemFree: 5980920 kB Buffers:417044 kB Cached: 703036 kB SwapCached: 0 kB Active:1440136 kB Inactive: 370668 kB HighTotal: 7405512 kB HighFree: 5977600 kB LowTotal: 842440 kB LowFree: 3320 kB SwapTotal: 8339440 kB SwapFree: 8339296 kB Dirty: 96 kB Writeback: 0 kB Mapped: 786672 kB Slab: 359208 kB Committed_AS: 2453912 kB PageTables: 24696 kB VmallocTotal: 106488 kB VmallocUsed: 8700 kB VmallocChunk:96708 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 2048 kB -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple email recipients
[EMAIL PROTECTED]: was wondering how to modify the code so as i can send to multiple email recipients using TO? thanks. You add RFC 2822 headers. http://www.ietf.org/rfc/rfc2822.txt (3.6.3. Destination address fields) -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list
Re: why does close() fail miserably on popen with exit code -1 ?!
Atanas Banov: i ran onto this weirdness today: seems like close() on popen-ed (pseudo)file fails miserably with exception instead of returning exit code, when said exit code is -1. Not here. Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] Type help, copyright, credits or license for more information. import os print os.popen('exit 1').close() 1 -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
bruno at modulix wrote: Paul Boddie wrote: (snip) I'm not sure why people get all defensive about Python's interpreted/scripting designation Because it carries a negative connotation of slow toy language not suitable for 'serious' tasks. Dynamicity apart, CPython's implementation is much closer to Java than to bash scripts - but still, as soon as you say interpreted, scripting, peoples think not serious. Perhaps we should blame the main man for this confusing label, then [1]: From one perspective you can say Python is a very high-level scripting language. Interestingly, with regard to my remark about various criteria being more appropriate when distinguishing between interactive and non-interactive languages, we also learn the following: From another perspective you can say it's a high-level programming language that happens to be implemented in a way that emphasizes interactivity. Python shares some characteristics with scripting languages, but also shares some characteristics with more traditional programming languages. Of course, we've all had this debate before, or rather everyone else has had this debate before and I've mostly ignored whether people call Python a scripting language, an interactive language, an agile language, a dynamic language, an applications programming language, or whatever. Personally, I rather think that whichever labels one chooses to attach to a language or platform generally come about from the success stories one can show people in relation to that language or platform. But there are always going to be people who contrast something like CPython's runtime with the Java virtual machine and ask whether CPython has, for example as one distinguishing factor, just-in-time compilation as a generally supported feature, and such people will be genuinely interested in why such things typically lie outside the principal runtime development process. People like to find distinctions between things - sometimes arbitrary ones - and make classifications that allow them to arrange such things conveniently in their mind. What I find quite worrying is that while in previous years people have responded to such discussions with a critical analysis of where Python (or rather CPython) can be improved, it's now the fashion to just trot out some response or other which excuses rather than explains the way things are. Paul [1] http://www.artima.com/intv/python.html -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple email recipients
On 20/02/06, Rene Pijlman [EMAIL PROTECTED] wrote: [EMAIL PROTECTED]:was wondering how to modify the code so as i can send to multiple email recipients using TO? thanks.You add RFC 2822 headers.http://www.ietf.org/rfc/rfc2822.txt(3.6.3. Destination address fields) RFC 2822 relates to the format of the message, not the sending of it. Adding headers such as Destination address fields will not affect nor necessarilly be related in any way to the actual recipients of the message The correct RFC might be RFC 2821 , Simple Mail Transfer Protocol. But the OP doesn't need RFC help, just help with the smtplib module itself. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Zefria wrote: Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd prefer not to see things slipping into Swap space if I can avoid it, and the fighter data would be only part of a larger program. And as I said, learning how to use __slots__ is important enough to hazard a premature guess this time around. If I mess up, the worst that happens is that I have to write down a new variable name in two places instead of one now. For this particular setup, I don't think it would be a concern given your mentioned size as you are very unlikely to be actively using all the apps at the same time and linux is quite efficient in handling it. However, I don't think attempting to use __slots__ in this case is bad either. Afterall, one of the strength of python is allowing you to quickly test out different approachs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular expression gone mad
fileexit: (Search finds nothing) a=rMemT pat = re.compile(a) m=pat.search(ProcMem, re.DOTALL) m From the docs: Compiled regular expression objects support the following methods and attributes: match( string[, pos[, endpos]]) Your re.DOTALL is seen as start position. That's why it's probably matching 'MemFree' instead of 'MemTotal'. -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list
Re: os.mkdir simple help
I'm new to python too, but I've read that sys.stdin.readline() is preferred. Is that right? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Fredrik Lundh wrote: Alexander Schmolck wrote: My point was that Guido probably (and fortunately!) was unaware of the extent to which you can have both dynamism and speed any my point was that chosing to ignore something doesn't mean that you're ignorant. I think it's more charitable (or rather, it possibly expresses the intent behind the quoted text more accurately or objectively) to rephrase ignorance on Guido's part and Guido... was unaware of with Guido's deliberate design decisions upon considering previous work on dynamic language runtime implementation and Guido chose to disregard strategies illustrating respectively. Not that I actually profess to know what Guido's knowledge of the field was in the late 1980s or what he actually knows right now beyond what he has said in various articles and interviews. (but since you keep repeating this nonsense, it's clear that you're pretty ignorant wrt. software design. too much CS exposure?). Unfortunate choices of words notwithstanding, I think the contributor in question raises interesting issues at a level way above this kind of response. Not that I actually profess to know what his level of CS exposure is beyond a brief perusal of his Google Groups profile, but I don't see how that really comes into play here, apart from as a convenient put-down label. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: cElementTree encoding woes
Diez B. Roggisch wrote: I've got to deal with a pretty huge XML-document, and to do so I use the cElementTree.iterparse functionality. Working great. Only trouble: The guys creating that chunk of XML - well, lets just say they are encodingly challanged, so they don't produce utf-8, but only cp1252 instead, together with some weird name (Windows-1252) for that. That is not part of the standard codecs module. cp1252 is, of course. But that won't work for iterparse. So currently, I manually change the encoding given to utf-8, and use a stream-recoder. However, I was wondering if I could teach cElementTree about that encoding name. I tried to register cp1252 under the name Windows-1252, but had no luck - cET won't buy it. Any suggestions? Both my python2.3 and python2.4 interpreters seem to know Windows-1252: import codecs codecs.open(windows.xml, encoding=windows-1252) open file 'windows.xml', mode 'rb' at 0x403737e0 Maybe the problem lies in the python installation rather than cElementTree? Just guessing, though. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
[EMAIL PROTECTED] wrote: Zefria wrote: Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd prefer not to see things slipping into Swap space if I can avoid it, and the fighter data would be only part of a larger program. And as I said, learning how to use __slots__ is important enough to hazard a premature guess this time around. If I mess up, the worst that happens is that I have to write down a new variable name in two places instead of one now. For this particular setup, I don't think it would be a concern given your mentioned size as you are very unlikely to be actively using all the apps at the same time and linux is quite efficient in handling it. However, I don't think attempting to use __slots__ in this case is bad either. Afterall, one of the strength of python is allowing you to quickly test out different approachs. Yes, something like import sys class Fighter(object): if --use-slots in sys.argv: __slots__ = [...] and then comparing $ python fighters.py with $ python fighters.py --use-slots might be instructive. I don't think the OP will perceive a difference. He could be working on a machine with 1M RAM or some other constraints. I have 256K, by the way. Peter -- http://mail.python.org/mailman/listinfo/python-list
Pythonpath and gnome panel
My pygtk gui can not be started from a gnome panel, because, apparently, the panel doesn't know about my modified PYTHONPATH. So how can I instruct the panel ? -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 -- http://mail.python.org/mailman/listinfo/python-list
Re: cElementTree encoding woes
Diez B. Roggisch wrote: I've got to deal with a pretty huge XML-document, and to do so I use the cElementTree.iterparse functionality. Working great. Only trouble: The guys creating that chunk of XML - well, lets just say they are encodingly challanged, so they don't produce utf-8, but only cp1252 instead, together with some weird name (Windows-1252) for that. That is not part of the standard codecs module. cp1252 is, of course. But that won't work for iterparse. So currently, I manually change the encoding given to utf-8, and use a stream-recoder. However, I was wondering if I could teach cElementTree about that encoding name. I tried to register cp1252 under the name Windows-1252, but had no luck - cET won't buy it. you need cET 1.0.5 or later for this to work. for earlier versions, you have to use stream recoding: http://effbot.org/zone/celementtree-encoding.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: cElementTree encoding woes
Both my python2.3 and python2.4 interpreters seem to know Windows-1252: import codecs codecs.open(windows.xml, encoding=windows-1252) open file 'windows.xml', mode 'rb' at 0x403737e0 Maybe the problem lies in the python installation rather than cElementTree? Just guessing, though. Hm. No idea why I was under the impression they weren't there - but still, it doesn't work: I get inf = file(sys.argv[1]) #inf = codecs.StreamRecoder(inf,encoder, decoder, reader, writer) for event, elem in cElementTree.iterparse(inf): pass pukes on me with Traceback (most recent call last): File ./splitter.py, line 31, in ? for event, elem in cElementTree.iterparse(inf): File string, line 61, in __iter__ SyntaxError: not well-formed (invalid token): line 35, column 34 That is the first french character encountered. titleIntroduction aux Probabilités/title So - then the problem is not the codec being ignored, but it simply is not working. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: module time
Sergey wrote: There is function mktime() -- convert local time tuple to seconds since Epoch in module time. But how about to convert *GMT time tuple* to seconds since Epoch? Is there such function? import calendar help(calendar.timegm) Help on function timegm in module calendar: timegm(tuple) Unrelated but handy function to calculate Unix timestamp from GMT. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
On Mon, 20 Feb 2006 01:14:20 -0800, Zefria wrote: class Fighter(object): ... '''Small one man craft that can only harm other fighters on their own.''' ... __slots__ = [fuel,life,armor,weapon,bulk] ... def __init__(self,statsTuple=(50,5,0,(2,4),1)): ... self.fuel = statsTuple[0] ... self.life = statsTuple[1] ... self.armor = statsTuple[2] ... self.weapon = statsTuple[3] ... self.bulk = statsTuple[4] ... examp = Fighter() examp.rock = 3 Traceback (most recent call last): File stdin, line 1, in ? AttributeError: 'Fighter' object has no attribute 'rock' Thank you both, I had tried making it a class variable and didn't see anything. The trick must have been in making a class that inheriets from object. For technical reasons, __slots__ don't work as expected for old-style classes, and never will. You have to inherit from object to make them work correctly. Also, I don't generally do any optimization at all yet (as a highschool student projects get trashed often enough no to bother over), but in this special case I'm expecting each carrier to have up to 150 fighters, and 3 to 5 carriers for each of the two teams, which comes out to be quite large. 750 objects is not very many, not unless they are carrying around large chunks of data. And even then, using __slots__ saves only a small amount of memory per object. Write your code the slot-less way, see how it performs, and if it is slow, change your class definition. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
Mladen Adamovic wrote: Hi! I wonder which editor or IDE you can recommend me for writing Python programs. I tried with jEdit but it isn't perfect. I've been using wing for quite some time and it's an excellent dedicated editor for python. If you want flexible debugging in a gui environment it's hard to beat. Tim Parkin -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
I did a review of Python IDE's at my blog. If you're interested you can take a look:http://www.straw-dogs.co.uk/blog/python-ide-reviewI have a couple of links to other reviews on there too. Worth a look if you're trying to find a good IDE. On 2/20/06, Tim Parkin [EMAIL PROTECTED] wrote: Mladen Adamovic wrote:Hi!I wonder which editor or IDE you can recommend me for writing Pythonprograms. I tried with jEdit but it isn't perfect.I've been using wing for quite some time and it's an excellent dedicated editor for python. If you want flexible debugging in a gui environmentit's hard to beat.Tim Parkin--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Peter Otten wrote: He could be working on a machine with 1M RAM or some other constraints. I have 256K, by the way. Impressive, curious to know what kind of environment it is as it has been a long time I have seen such limited spec. My first x86(IBM PC) had more than that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
[EMAIL PROTECTED] wrote: Peter Otten wrote: He could be working on a machine with 1M RAM or some other constraints. I have 256K, by the way. Impressive, curious to know what kind of environment it is as it has been a long time I have seen such limited spec. My first x86(IBM PC) had more than that. Touché -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Oracle Interace on Solaris
Kenny wrote: Thanks... Im not sure if you would know how to solve this one, but when I ran my setup python scripts I got the error: library -lclntsh not found. In the instantclient folder the library exists... is this a matter of just copying the libraries to a different spot or just setting up the correct environment variables? Not sure on Solaris... You might try exporting an LD_LIBRARY_PATH, or editing /etc/ld.so.conf and running ldconfig, if Solaris has such a thing. I would caution against moving the library, it's probably already where it's expected to be. You have ORACLE_HOME set? -- http://mail.python.org/mailman/listinfo/python-list
Scientific Survey: Working Conditions in Open Source Projects
We like to invite you to a survey about the working conditions in Free/Open-Source Software development. This survey is conducted by the Open-Source Research Group of the University of Würzburg (Germany). We will compare work design in open source and proprietary software development. Our findings should be used to adjust the working conditions of software development to the needs of the developers. The results will be published under the Creative Commons License. To start the survey, please click on the following link: http://www.unipark.de/uc/open-source-task/ If you have any questions don't hesitate to contact us! Dirk Jendroska http://wy2x05.psychologie.uni-wuerzburg.de/ao/staff/jendroska.php?lang=en -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
On Sun, 19 Feb 2006 20:52:54 +0100, Mladen Adamovic wrote: Hi! I wonder which editor or IDE you can recommend me for writing Python programs. I tried with jEdit but it isn't perfect. eclipse+pydev ? I've never tried it though -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Torsten Bronger wrote: Well, I think that it's fair to say that there are by principle deep run time differences between CPython and, say, a typical C++-compiled program. Your definition would not reproduce that. I think it's also fair to say that these differences should be known if somebody tries to find the best tool for a job. After all, they include advantages, too. My definiton would be that an interpreted language has in its typical implementation an interpreting layer necessary for typical hardware. Of couse, now we could discuss what is typical, however, in practice one would know it, I think. In case of Python: CPython and all important modern processors. Well, if we take any modern Intel/AMD chip (which could be described as typical), a C++ program would fit the interpreted definition, since the processor does not execute the machine code directly but rather breaks it down into smaller microcode instruction -- a process that could be described as intepretation. Another problem with the definition: what would you call a C++ program that is running on top of an emulator? Does a language become interpreted just by running the program on top of an emulator? Why is the python interpreter different from an emulator in this respect? I think that the disctinction between interpreted and compiled (whatever both means) is really just not sensible at all. Cheers, Carl Friedrich -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
What's far more interesting to me, however, is that I think there a good reasons to suspect python's slowness is more of a feature than a flaw: I'd not be suprised if on the whole it greatly increases programmer productivity and results in clearer and more uniform code. Yes, it's Guidos master-plan to lock programmers into a slow language in order to dominate them for decades. Do you also believe that Al Quaida is a phantom organization of the CIA founded by neocons in the early '90s who planned to invade Iraq? Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: any ftpd written in python?
[EMAIL PROTECTED] wrote: Kenneth Xie [EMAIL PROTECTED] wrote: I need a simple ftpd example in pure python. Is there already such a ftpd available? Thank you very much in advance. self-advertising: http://melkor.dnp.fmph.uniba.sk/~garabik/pyftpd.html it is a bit dated and I do not develop it anymore, but as a base of your own server software it can be quite good. Exactly what I need now, thank you very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion about the proper use of __slots__
Zefria wrote: Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd prefer not to see things slipping into Swap space if I can avoid it, and the fighter data would be only part of a larger program. And as I said, learning how to use __slots__ is important enough to hazard a premature guess this time around. If I mess up, the worst that happens is that I have to write down a new variable name in two places instead of one now. Ok, but don't forget that using slots prevents you from attaching new attributes on the fly on a given instance - which can be quite handy for some use cases. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Hallöchen! Carl Friedrich Bolz [EMAIL PROTECTED] writes: Torsten Bronger wrote: [...] My definiton would be that an interpreted language has in its typical implementation an interpreting layer necessary for typical hardware. Of couse, now we could discuss what is typical, however, in practice one would know it, I think. In case of Python: CPython and all important modern processors. Well, if we take any modern Intel/AMD chip (which could be described as typical), a C++ program would fit the interpreted definition, since the processor does not execute the machine code directly but rather breaks it down into smaller microcode instruction -- a process that could be described as intepretation. This is an interpreting layer within the hardware, not necessary for it. Another problem with the definition: what would you call a C++ program that is running on top of an emulator? Compiled. I said necessary for typical hardware. [...] I think that the disctinction between interpreted and compiled (whatever both means) is really just not sensible at all. The question is whether such features have to be considered when choosing the right tool for a task. I think, yes. Whereas C is very close to the fastest code you can get because it works very closely to how the machine itself works, Python can well be one or one and a half orders of magnitude farther away. No problem since you can get the best of both worlds but: You must be aware of it. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646 -- http://mail.python.org/mailman/listinfo/python-list
Re: How many web framework for python ?
Alex Martelli wrote: Bruno Desthuilliers [EMAIL PROTECTED] wrote: ... There are very good web framework for java and ruby , Is there one for python ? In fact, there are actually too much *good* python web frameworks. Dear Mr. BDFL, there are too many good web frameworks nowadays. Please eliminate three. Seems like I should have added a smiley somewhere... -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Print a PDF transparently
Have you seen this? http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html In particular, the section on using win32print directly. Yes, I have. The problems is that an external program is launched for handling the file and print it. In the case of PDF, acrobat is launched. In the case of PS, Ghostview is launched. When printing a PDF, acrobat keeps alive, so the user has to close it manually. On the other hand, Ghostview is opened, prints the file and closes automatically. The last one is which I find the best for me, until now, (because the Ghostview closes automatically). If I decide to go this way, my problem then is to transform a pdf to ps, or generate a ps directly. For further information on what I want, please, refer to my first two posts in this topic. Any other help? Thank you very much -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
It was said that Boa is good, but I prefer SPE. WingIDE is good but commercial, I tried it but didn't buy. -- http://mail.python.org/mailman/listinfo/python-list
Re: general coding issues - coding style...
On 2006-02-19, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Bonjour, 1/ learn OO and get rid of globals. Well I created two classes now. I put some things global (your point 6). e.g. if it's on Windows or not, and other things. 2/ use dict or list based dispatch instead of long if/elif/elif... clauses when I find out what you mean, I will. Probably something lika a 'case' thing? #python meant a list containing functions or so. So that the values represent the functions to call, isn 'it? 3/ stdout is meant for *normal* program outputs. Errors and verbosity go to stderr yeah, changed (somebit) 4/ triple quoted strings are fine for multiline text yeah. I have lot of triple prints... 5/ os.path is fine for portable filepath operations I don't really understant what you mean here, sorry 6/ things that dont change during program execution (ie : constants) should not be defined inside a function As I mentioned above, these I placed globally: main gtkwindows, smwin or not, pyexe or not, preferred encoging according to your statement? Anyway, since I did lot of changes, I'm myself confused actually. http://calmar.ws/tmp/cal.html Will try to cleanup and implement even further all good advices from all in some days. Thanks a lot!! calmar -- calmar (o_ It rocks: LINUX + Command-Line-Interface //\ V_/_ http://www.calmar.ws -- http://mail.python.org/mailman/listinfo/python-list
Re: Print a PDF transparently
Have you seen this? http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html In particular, the section on using win32print directly. Yes, I have. The problems is that an external program is launched for handling the file and print it. In the case of PDF, acrobat is launched. In the case of PS, Ghostview is launched. When printing a PDF, acrobat keeps alive, so the user has to close it manually. On the other hand, Ghostview is opened, prints the file and closes automatically. The last one is which I find the best for me, until now, (because the Ghostview closes automatically). If I decide to go this way, my problem then is to transform a pdf to ps, or generate a ps directly. For further information on what I want, please, refer to my first two posts in this topic. Any other help? Thank you very much -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
On Sun, 19 Feb 2006 20:52:54 +0100, Mladen Adamovic [EMAIL PROTECTED] wrote: Hi! I wonder which editor or IDE you can recommend me for writing Python programs. I tried with jEdit but it isn't perfect. Maybe you try out DrPython. (Written in Python and wxPython, Autocompletion, Calltips, easily extensible with plugins and scripts, source browser, ...) -- Franz Steinhaeusler -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo - Will it Lock Me In?
On 2/19/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Yes, I have Dabo installed on my system. I made a small test app, but was unable to deploy it. I was getting an error from py2exe, I think, about how my wxPython installation was not correct. This is the kind of thing I am talking about. If Dabo were an integrated system, I wouldn't have to spend many days struggling to install package after package and then get them all to play nice with each other. Dabo is an open source package written by two guys in their spare time. I'm not surprised that there might still be some loose ends, especially with integrating with external packages. Did you post a message to their list explaining the problem? Just last week someone found a problem building with py2exe, and Paul, one of the authors, identified the problem (py2exe wasn't 'finding' a library that it should have), and had a fix posted within a couple of hours. Having said that, I will continue to struggle and like Dabo as the best option so far. Good to hear! And don't struggle too much without posting a message about your problem on the Dabo lists, or on their issue tracker (http://dabodev.com/tracker). I've never worked with a more helpful team than with the Dabo folks. -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Komodo - Will it Lock Me In?
matt Any other thoughts on Komodo? If you code in any other languages (Perl, Ruby) or need to edit xml, html, php etc, Komodo will handle all of these for you with appropriate color coding, nested loops etc. rd www.dooling.com Matt wrote: Hi Everybody, If I were to use Komodo to write in Python, would it add a lot of goo to my code such that I would not be able to switch to another IDE without having to claw my way out of a tarpit first? Any other thoughts on Komodo? I am considering it because I am hoping to find a solution to the install-packages-until-you-go-blind aspect of Python. Setting up a serious, cross-platform, gui development environment is quite a struggle for a newbie. Thanks, Matt -- http://mail.python.org/mailman/listinfo/python-list
Python for PHP Programmers
Hi AllPlease be gentle but I'm primarily a PHP coder after a few years of academic experience in Java I've lost my object orientated programming style and have become a procedural PHP coder. I started using Python almost 12mths ago now but I'm still very much working in a PHP style. Obviously I need to learn the Python way and I have been doing a piece at a time, however, I was wondering if you had any specific advice for PHP - Python programmers? Any habits I need to pickup/drop? Thanks for any input and thanks for your patience.Doug -- http://mail.python.org/mailman/listinfo/python-list
Re: number ranges (was Re: Matlab page on scipy wiki)
Steven D'Aprano wrote: John Zenger wrote: I strongly agree that Python should promote range or xrange to syntax. I favor [0..10] rather than [0:10] because 0..10 is inherently easier to understand. Inherently? You mean people are born with an instinctive, unlearnt understanding of ..? I mean that most people will have seen that notation somewhere else in their pre-Python lives, so it won't take much effort for them to remember what it is, at least more so than 0:10. With the introduction of a single keyword, we could do this: for i in 2 to 5: print i, which would print 2 3 4 5 This proposed syntax is also easy to understand, maybe more than .., because it uses natural language. The only criticism is that it creates a list without using [] notation. How about [2 to 5]? (I'm open to arguments that it should be more Pythonic and less mathematical, and halt at 4.) I am also open to such arguments but it will be tough to convince me that x to y should mean something different from what it means in Pascal, BASIC, and English. A second keyword downto would allow easy backwards loops, Downto would only be necessary if we wanted [10 to 1] to equal []. and a third step will absolutely kill any chance of Guido agreeing to this whatsoever. What about [1 to 3 to 10]? (Or [1 to 10:2]?) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs. Lisp -- please explain
Fredrik Lundh [EMAIL PROTECTED] writes: Alexander Schmolck wrote: My point was that Guido probably (and fortunately!) was unaware of the extent to which you can have both dynamism and speed For the convenience of other readers, allow me to restore the snipped second half of that sentence: ... and the extent to which very dynamic languages are suitable for writing robust software. any my point was that chosing to ignore something doesn't mean that you're ignorant. Interviewer: You said originally you thought 500 lines would be a big Python program. Guido van Rossum: That was just my lack of imagination. http://www.artima.com/intv/pyscale3.html Guido van Rossum: Another thing, much farther in the future, is compilation to C or machine code. I used to think that this was impossible and (perhaps because of that) uninteresting, but recent experiments (like Armin Rigo's Psyco and Greg Ewing's Pyrex) suggest that this will eventually be possible. It should provide Python with an incredible performance boost and remove many of the reasons why many people are still reluctant to switch to Python. http://www.onlamp.com/pub/a/python/2002/06/04/guido.html?page=1 (but since you keep repeating this nonsense, it's clear that you're pretty ignorant wrt. software design. too much CS exposure?). Indeed. Your amazing reading comprehesion and lucid argumentation would obviously be lost on my posts. 'as -- http://mail.python.org/mailman/listinfo/python-list
Re: Tab Character?
[EMAIL PROTECTED] wrote: How do I make a tab character in code to split a line read with tabs in it? Thanks. Tom You should also take a look at csv module. If you are reading lines that contain tab delimeted data the csv module can make splitting very easy. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
On 2006-02-19, Rene Pijlman [EMAIL PROTECTED] wrote: I beg to disagree :-) Use ed Ed is the standard text editor. http://www.gnu.org/fun/jokes/ed.msg.html That was 1991. This is 2006. That's a joke, son. A flag waver. You're built too low. The fast ones go over your head. Ya got a hole in your glove. I keep pitchin' 'em and you keep missin' 'em. Ya gotta keep your eye on the ball. Eye. Ball. I almost had a gag, son. Joke, that is. -- Grant Edwards grante Yow! Wait... is this a FUN at THING or the END of LIFE in visi.comPetticoat Junction?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Forth for real?
Cameron Laird wrote: In article [EMAIL PROTECTED], Steven D'Aprano [EMAIL PROTECTED] wrote: . . . on the web for each language. By comparison, even Forth gives 13 million plus hits, and who uses Forth? . . . The programmers of, among other things, the FedEx bar-code reader, the Sun boot loader, and parts of the Space Shuttle. The original post seems to be missing, but my answer to the title question is, No, Forth is not real. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] (-1)**(1/2)==1?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello! it's Ok. Python gets from 1/2 0 as 0 is the integer part of that division. So, Python is interpreting -1**0 so you get 1 as answer. you should try this (-1)**(1.0/2.0) so 1.0/2.0 is an operation returning 0.5 completely. and you'll get: (-1)**(1.0/2.0) Traceback (most recent call last): File stdin, line 1, in ? ValueError: negative number cannot be raised to a fractional power Regards, Jesús (Neurogeek) Jonathan Barbero wrote: Hello! My name is Jonathan, i´m new with Python. I try this in the command line: (-1)**(1/2) 1 This is wrong, i think it must throw an exception. What do you think? Bye. Jonathan. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/jrivero%40python.org.ve -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD+eA4dIssYB9vBoMRAuZXAJ4/hc6FrApyDxFScsv8w1kjc+Yi8QCfWzdb Izl2OQUE3iPVeqBnvjErrHA= =y5uC -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular expression gone mad
fileexit [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, Would someone please tell me what is going on here??!! Why does the following code work a=rMem pat = re.compile(a) m=pat.search(ProcMem, re.DOTALL) m _sre.SRE_Match object at 0xb7f7eaa0 m.group(0) 'Mem' ProcMem contains: print ProcMem MemTotal: 8247952 kB MemFree: 5980920 kB Buffers:417044 kB Cached: 703036 kB SwapCached: 0 kB Active:1440136 kB Inactive: 370668 kB HighTotal: 7405512 kB HighFree: 5977600 kB LowTotal: 842440 kB LowFree: 3320 kB SwapTotal: 8339440 kB SwapFree: 8339296 kB Dirty: 96 kB Writeback: 0 kB Mapped: 786672 kB Slab: 359208 kB Committed_AS: 2453912 kB PageTables: 24696 kB VmallocTotal: 106488 kB VmallocUsed: 8700 kB VmallocChunk:96708 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 2048 kB Are you going to create re's for every line of that data? Here's a pyparsing version that generates the grammar for you (or you can modify this example to generate re's if you prefer). This is an unusual form for pyparsing. Typically, people construct an And in their grammar by connecting expressions together with '+' operators (as in the procMemEntry method of the example). But here, we are generating the list of entries, and then directly creating the And with the resulting list of expressions. Download pyparsing at http://pyparsing.sourceforge.net. -- Paul procMemData = MemTotal: 8247952 kB MemFree: 5980920 kB Buffers:417044 kB Cached: 703036 kB SwapCached: 0 kB Active:1440136 kB Inactive: 370668 kB HighTotal: 7405512 kB HighFree: 5977600 kB LowTotal: 842440 kB LowFree: 3320 kB SwapTotal: 8339440 kB SwapFree: 8339296 kB Dirty: 96 kB Writeback: 0 kB Mapped: 786672 kB Slab: 359208 kB Committed_AS: 2453912 kB PageTables: 24696 kB VmallocTotal: 106488 kB VmallocUsed: 8700 kB VmallocChunk:96708 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 2048 kB from pyparsing import Word,nums,Literal,Suppress,Group,And,Dict # define an integer, and an integer kB value integer = Word(nums).setParseAction(lambda s,l,t:int(t[0])) numKb = integer + Suppress(kB) # convenience method for extracting procMem entries def procMemEntry(name, valExpr): return Group(Literal(name) + Suppress(:) + valExpr).setName(name) # extract names from sample procMem data, and create list of matching value expressions names = [l.split(':')[0] for l in procMemData.split('\n') if l] exprs = [n.startswith(HugePages_) and integer or numKb for n in names] # generate grammar using names and exprs lists procMemGrammar = Dict(And([ procMemEntry(nam,expr) for nam,expr in zip(names,exprs) ])) # check grammar by parsing input string pmData = procMemGrammar.parseString(procMemData) # access pmData as a dict for k in pmData.keys(): print k,pmData[k] # or create a standard Python dict from pmData print dict(pmData) -- http://mail.python.org/mailman/listinfo/python-list
Modifying an instances dict to change attribute lookup
Hmm, I know this is something fundamental about how Python implements predicate dispatch, but for some reason I believed that this would work: class delegate_dict(dict): def __init__(self, orig, deleg): dict.__init__(self, orig) self.deleg = deleg def __getitem__(self, name): print 'here:', name try: v = dict.__getitem__(self, name) except KeyError: return self.deleg.__getitem__(name) return v def delegate(target, source): target.__dict__ = delegate_dict(target.__dict__, source.__dict__) As a simple usage, give: class A(object): pass class B(object): def __init__(self, o): delegate(self, o) a = A() a.test = 1 b = B(a) print b.__dict__.__getitem__('test') # This goes down in flames print b.test And then a dumb example showing the concept I assumed was a given: class C(object): pass c = C() c.x = 1 assert c.__dict__.__getitem__('x') == c.x Could someone please tell me why the first example using a customized dict does not perform as advertised? -- http://mail.python.org/mailman/listinfo/python-list
Processing text using python
Hey everyone! I'm hoping someone will be able to help me, cause I haven't had success searching on the web so far... I have large chunks of text ( all in a long string) that are currently all in separate notebook files. I want to use python to read these strings of text, THREE CHARACTERS AT A TIME. (I'm studying the genetic code you see, so I need to read and analyse each sequence one codon at a time effectively.) Does anyone have any idea of how to do this using python? I'm going to be optimistic and thank you for your help in advance! Samantha. -- http://mail.python.org/mailman/listinfo/python-list
Re: number ranges (was Re: Matlab page on scipy wiki)
[EMAIL PROTECTED] wrote: Tim Hochberg wrote: Colin J. Williams wrote: It would be good if the range and slice could be merged in some way, although the extended slice is rather complicated - I don't understand it. The semantics for an extended slicing are as follows. The primary must evaluate to a mapping object, and it is indexed with a key that is constructed from the slice list, as follows. If the slice list contains at least one comma, the key is a tuple containing the conversion of the slice items; otherwise, the conversion of the lone slice item is the key. The conversion of a slice item that is an expression is that expression. The conversion of an ellipsis slice item is the built-in |Ellipsis| object. The conversion of a proper slice is a slice object (see section section 4.2 The standard type hierarchy http://www.network-theory.co.uk/docs/pylang/ref_30.html) whose |start|, |stop| and |step| attributes are the values of the expressions given as lower bound, upper bound and stride, respectively, substituting |None| for missing expressions. [source: http://www.network-theory.co.uk/docs/pylang/ref_60.html] The seems to be a bit of a problem with slicing that needs sorting out. The syntax for a slice list appears to allow multiple slices in a list: extended_slicing ::= primary primaries.html#tok-primary [ slice_list slicings.html#tok-slice_list ] slice_list ::= slice_item slicings.html#tok-slice_item (, slice_item slicings.html#tok-slice_item)* [,] but the current interpreter reports an error: a= range(20) a[slice(3, 9, 2)] [3, 5, 7] a[slice(3, 9, 2), slice(5, 10)] Traceback (most recent call last): File interactive input, line 1, in ? TypeError: list indices must be integers Extended slicing has nothing to do with lists. All that gobbeldy gook is trying to tell you is what the interpreter does with O[1:2:3, 4:5:6] where O is some arbitrary object. What it does is: O[1:2:3, 4:5:6] == O[slice(1,2,3), slice(4,5,6)] == O.__getitem__((slice(1,2,3), slice(4,5,6))) In the case of python lists, __getitem__ doesn't support multiple slice arguments. However, you are free to define your own types which do support multiple slices. That explains it but the current documentation in the reference manual doesn't(I also tried what Colin did when reading that part). And as I mentioned in another post, the current documentation suggests that extended slicing is not supported for sequence type. As it said the primary must be evaluated to mapping object for extended slicing. Though it seems it doesn't matter as all python does now is turn [start:stop:stride] into slice object and pass that to __getitem__, no matter what object it is. I try not to read the reference manual, since it just makes my eyes glaze over, but I believe that the distinction between sequences and mappings referred to only exists for objects defined at the C level. Objects can define getitem two different ways: using sq_item/sq_slice or using mp_subscript. The former functions take integers, the latter takes general PyObjects. So, only the mapping version (mp_*) supports extended slicing. Python class objects always have the mp_subscript defined and it dispatches things to __getitem__. In the past, lists only supported start and stop arguments to slices, so they could get by with using the sq_ functions. Now that they support step arguments as well, it seems that they must define the mapping methods as well, although I admit I haven't checked. You can get an idea of what sq_slice does by looking at the following chunk of code: class ExtendedSlicingDemo(object): def __getitem__(self, key): return key def __getslice__(self, start, stop): return start, stop esd = ExtendedSlicingDemo() print esd[1:2] print esd[1:2:3] print esd[1:2:3, 3:4:5] print esd[1:2:3, ..., 3:4:5] # Note that __getslice__ is deprecated. I think sq_item/sq_slice is still around for efficiency reasons for sequences that don't support extended slicing as well as backwards compatibility / historical reasons. -tim -- http://mail.python.org/mailman/listinfo/python-list
Re: How many web framework for python ?
bruno at modulix [EMAIL PROTECTED] wrote: Alex Martelli wrote: Bruno Desthuilliers [EMAIL PROTECTED] wrote: ... There are very good web framework for java and ruby , Is there one for python ? In fact, there are actually too much *good* python web frameworks. Dear Mr. BDFL, there are too many good web frameworks nowadays. Please eliminate three. Seems like I should have added a smiley somewhere... Naah, smileys unneeded -- you'll notice that my I am not a crackpot comment was unsmilied either (and nobody nominated it for QOTW, darn!). Having just coincidentally finished wrapping up the 2nd edition's Nutshell first draft of the chapter on serverside web programming, after a long time researching all the alternatives I've given up on even MENTIONING all of the frameworks available, much less providing any in-depth coverage, so I'm quite sensitized to the situation!-) Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: timeit module: am I missing something obvious?
Peter Otten [EMAIL PROTECTED] writes: Steven D'Aprano wrote: When using the timeit module, you pass the code you want to time as strings: ... This is all very well, but it feels quite unnatural to me. Why am I passing strings around when functions are first class objects? Have I missed something obvious? You are supposed to time small pieces of code where a function call would be a significant overhead. I think it can be useful to time longer code as well. Moreover, when you pass in strings, you have to ensure that the namespace is set-up correctly, which can be awkward at times. If you could pass in a function, this would often be much easier. Just do it :-) Yes, please do! I would suggest a slight modification: t = timeit.Timer.for_function(foo, x, y, a=..., b=...) And while you are at it you could also move the code that dynamically adjusts the number of repetitions from the main() function into a Timer method and make its invocation the default for the timeit() method. I agree. Moreover, I think the calibration could be improved a lot. What I use is below. It would be great if something like this could be merged into timeit.py... Notice how quickly it locks onto an appropriate number of iterations. (Only 3% of the time is spent on calibration.) import timer timer.timing(3*2/6, goal=0.5, repeat=3, verbose=True) 1 loops - 1e-05 secs 49933 loops - 0.0396 secs 630325 loops - 0.499 secs 630325 loops - 0.499 secs 0.5 secs 0.501 secs 630325 loops, best of 3 trials: 0.792 usec per loop Dan Uses timeit to benchmark code, quickly choosing number of iterations. Differences: - This can be used interactively from python, not just from the command line. - Doesn't use separate creation and timing steps. - The algorithm for choosing the number of iterations is faster and more accurate. It also allows for just 1 iteration. - The result from the final pass through the convergence loop is used as one of the samples, which saves time (especially if repeat=1). Sample usage: import timer timer.timing(sin(10),setup=from math import sin,repeat=3) import time timer.timing(3*2/6,repeat=3,goal=0.5,timer=time.time) To do: - add support for passing in a function instead of a string. import timeit import time def timing(stmt=pass, setup=pass, repeat=1, goal=None, number=None, timer=timeit.default_timer, verbose=False, precision=3): '''Eval setup, and then time stmt. goal is desired time in seconds, a float. number is desired number of iterations. At most one of goal and number can be specified. If neither is specified, default to a goal of 1 second. When number is not specified, it is determined in an efficient way. repeat is the total number of times to run the test. timer is the timer to use. if verbose, show information about calibration. precision is the number of significant digits to display. ''' t = timeit.Timer(stmt,setup,timer=timer) r = [] if number != None and goal != None: raise ValueError,'Only one of number and goal may be specified.' if number == None: if goal == None: goal = 1.0 # determine number so that total time = 90% of goal. number = 1 x = 0.0 while x 0.9*goal: x = t.timeit(number) if verbose: print %9d loops - %.*g secs % (number, precision, x) if x == 0: # 1e2 is chosen because this is a common resolution # for time.clock. Make sure that number gets increased # by at least one, to avoid an infinite loop. number = max(number+1,int(number*1e2*goal)) elif x 0.9*goal: # If x is very small, goal/x is large (possibly inf); # to be cautious we limit the ratio to 1e6. # The +1 is to ensure that number increases by at least 1, # since goal/x 1. number = int(number*min(1e6,goal/x)+1) r=[x] repeat -= 1 r.extend(t.repeat(repeat, number)) best = min(r) if verbose: print %9d loops - % number, print .join([%.*g secs % (precision, x) for x in r]) print %9d loops, best of %d trials: % (number, len(r)), usec = best * 1e6 / number if usec 1000: print %.*g usec per loop % (precision, usec) elif usec 1e6: print %.*g milliseconds per loop % (precision, usec/1000) else: print %.*g seconds per loop % (precision, usec/1e6) -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing text using python
nuttydevil [EMAIL PROTECTED] wrote: Hey everyone! I'm hoping someone will be able to help me, cause I haven't had success searching on the web so far... I have large chunks of text ( all in a long string) that are currently all in separate notebook files. I want to use python to read these strings of text, THREE CHARACTERS AT A TIME. (I'm studying the genetic code you see, so I need to read and analyse each sequence one codon at a time effectively.) Does anyone have any idea of how to do this using python? Open each file and call thefile.read(3) in a loop, move to the next file when the current one is exhausted. What part of this is giving you problems? Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing text using python
nuttydevil wrote: Hey everyone! I'm hoping someone will be able to help me, cause I haven't had success searching on the web so far... I have large chunks of text ( all in a long string) that are currently all in separate notebook files. I want to use python to read these strings of text, THREE CHARACTERS AT A TIME. (I'm studying the genetic code you see, so I need to read and analyse each sequence one codon at a time effectively.) Does anyone have any idea of how to do this using python? I'm going to be optimistic and thank you for your help in advance! Samantha. Since you're reading from files, the read operation of file-like objects takes an argument specifying the number of characters to read from the stream e.g. f = file(stuff.txt) f.read(3) 'car' f.read(3) 'act' f.read() 'erization' Would that be enough for what you need? -- http://mail.python.org/mailman/listinfo/python-list
Re: Open Relay Test
On Friday 17 February 2006 05:31, D wrote: Hi all .. how could one test to see if an open relay exists on a specific email server? My simple favorite... run: telnet relay-test.mail-abuse.org from the mail server in question (and be patient). Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying an instances dict to change attribute lookup
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... c = C() c.x = 1 assert c.__dict__.__getitem__('x') == c.x Could someone please tell me why the first example using a customized dict does not perform as advertised? Because Python's __getattribute__ is currently not EXACTLY as you imagine it to be, but slightly different, say something like: dict.__getitem__(c, 'x') at the crucial step rather than c.__getitem__. More generally, when (on any type or newstyle class -- oldstyle legacy classes are different) a special method gets implicitly invoked, it's invoked on the type, not on the instance (no per-instance overriding in this case); and, for speed, many internal dict lookups do dict.__getitem__(obj,name) rather than type(obj).__getitem__(obj, name). The documented way to do what you want in Python is by overriding __getattr__ (which gets called when other normal lookup procedures fail and would, absent __getattr__, raise AttributeError), not by trying to install as the __dict__ something whose type isn't exactly __dict__. Other approaches may work, but they depend on implementation accidents which are liable to change with every passing breeze. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing text using python
In article [EMAIL PROTECTED], nuttydevil [EMAIL PROTECTED] wrote: Hey everyone! I'm hoping someone will be able to help me, cause I haven't had success searching on the web so far... I have large chunks of text ( all in a long string) that are currently all in separate notebook files. I want to use python to read these strings of text, THREE CHARACTERS AT A TIME. (I'm studying the genetic code you see, so I need to read and analyse each sequence one codon at a time effectively.) Does anyone have any idea of how to do this using python? Don't reinvent the wheel. Take a look at http://www.biopython.org/. -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing text using python
I think this is what you want: file = open(r'c:/test.txt','r') c = file.read(3) while c: print c c = file.read(3) file.close(); -- http://mail.python.org/mailman/listinfo/python-list
changing value of 'self' when subclassing int
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but changing 'self' obviously just alters the value of that local variable. Is there some way for me to change the value of the BitSequence object itself? I've also tried wrapping and delegating using __getattr__, but I couldn't figure out how to handle in-place methods. Thanks for your help, David Coffin class BitSequence(int): An integer emulating a sequence of bits, subclassing int. def __new__(cls, value, length=32): inst = super(BitSequence,cls).__new__(cls, value) inst.length = length return inst def __setitem__(self, index, bit): mask = 1 self.length - index - 1 if bit == 1: # XXX only changing local 'self' self |= mask elif bit == 0: self = ~mask def __getitem__(self, i): return (self (self.length - i -1)) 1 def __repr__(self): s = '' for i in xrange(self.length): s = str(self i 1) + s return s + : + str(self) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter / Aqua (OS X) question (canvas borders)
In article [EMAIL PROTECTED], [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: There appears to be an asymmetric border around the inside of the canvas. There was a thread on this last May (you can search for the thread titled Unusable outer edge of Tkinter canvases?) Fredrik Lundh suggested resetting the coordinate system via: w.xview_moveto(0) w.yview_moveto(0) This seemed to help, but in the end it still seems that there's a narrow border inside the edges of a Canvas which can't be drawn to. And it seems to be different for OS X and Windows. In the end I just made sure everything I draw is no closer than 5 pixels from the edge of the Canvas, and that seems to work on all the platforms I'm deploying on. Dave Opstad -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing text using python
[EMAIL PROTECTED] wrote: I think this is what you want: file = open(r'c:/test.txt','r') c = file.read(3) while c: print c c = file.read(3) file.close(); Or: def read3(): return file.read(3) for chars in iter(read3, ''): ... do something with chars ... STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing text using python
nuttydevil [EMAIL PROTECTED] wrote: Hey everyone! I'm hoping someone will be able to help me, cause I haven't had success searching on the web so far... I have large chunks of text ( all in a long string) that are currently all in separate notebook files. I want to use python to read these strings of text, THREE CHARACTERS AT A TIME. (I'm studying the genetic code you see, so I need to read and analyse each sequence one codon at a time effectively.) Does anyone have any idea of how to do this using python? did you read the string chapter in the tutorial ? http://docs.python.org/tut/node5.html#SECTION00512 around the middle of that chapter, there's a section on slicing: substrings can be specified with the slice notation: two indices separated by a colon /F -- http://mail.python.org/mailman/listinfo/python-list
Re: preserving POST data
On Thursday 16 February 2006 22:35, Steve Young wrote: Lets say that I'm filling out a form and the information gets sent to another server first for some processing(before the one that it should go to). But from there, I want that intermediate server to be able to preserve this POST data using python so it can still retrieve the page that was originally requested (with some modifications from the intermediate server). Is there a way to do this with python? That's less a python-specific question. The general solution is to store the information on your server and remember who the user was. Many web programmers use a cookie based authentication/identification with a database backend. Which means: - User comes to your website - You send the user a cookie - You create an entry in your database with that cookie - User enters data - You add the data to the database (referring to the cookie) - User comes back later - You can look up the data in your database according to the user's cookie I use that scheme in a more complex way for cookie based authentication (http://workaround.org/pysessions). Kindly Christoph -- ~ ~ .signature [Modified] 1 line --100%--1,48 All -- http://mail.python.org/mailman/listinfo/python-list