Re: Fast text display?
On Thu, 09 Jun 2005 02:22:08 +0200, Riccardo Galli <[EMAIL PROTECTED]> wrote: > Using tkinter doesn't need downloading and installing only in Windows. > In *nix is not so common to have tcl/tk installed (and probably in Mac too) > > GUI cross platform need external support, in a OS or in another. Even if tcl/tk is not installed by default on your system, doing it is usually not a pain, since the guys making it insist on keeping its required dependencies minimal: IIRC, to install tcl/tk on any Unix, you just need to have X and a C compiler. This may be a slight advantage over most other toolkits, that usually require other libraries that you may not have installed on your system, or installed at the wrong version. I was sometimes caught in such a dependency hell when trying to install a toolkit that I eventually gave up... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Make Tkinter child window active
It's working, thank you very much :) -- http://mail.python.org/mailman/listinfo/python-list
RE: identifying 64-bit Windows from 2.3.5?
From: Steven Knight <[EMAIL PROTECTED]> To: python-list@python.org Subject: identifying 64-bit Windows from 2.3.5? Date: Wed, 8 Jun 2005 23:51:15 -0400 (EDT) If I have installed 2.3.5 from the python.org Windows installer, can any one point me to a run-time way to identify whether I'm running on a 32-bit vs. 64-bit version of Windows XP, given that Python itself was built on/for a 32-bit system? I hoped sys.getwindowsversion() was the answer, but it returns the same platform value (2) on both 32-bit and 64-bit systems. sys.platform ("win32") and sys.maxint are both set at compile time. Things like os.uname() aren't on Windows. Can some Windows-savvy Pythonista point me to some way to distinguish between these two? Thanks, --SK -- http://mail.python.org/mailman/listinfo/python-list I really don't think it matters too much which one you have, I have 64 bit and it works fine. -Ivan _ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Saving/retrieving user preferences
(my last post seemed to not get out, sorry if you see it twice) This may be a FAQ,but I cannot find it. I want to save user preferences, window sizes, recently opened file names, etc for a python application and I am looking for a package that does this in a way that is portable across unix/linux and windows (and mac would be nice as well). Is there a 'standard' package for doing this in python? thanks, -- brian... -- http://mail.python.org/mailman/listinfo/python-list
my golf game needs gui
hi i've been writing a golf game in text only. this was to work out some of details. it's great but making a golf course with ---'s and |||'s is kinda silly looking. (at least to some..) now i'm ready to begin shopping for a gui widget to work with python so my players can have some kind of pictures and possibly some motion. i won't be creating figures swinging the golf clubs but would like to show their golf ball flying thru the air and land on the green for one example. will pyQT work for me? any suggestions on which way I should go next? i would like my game to work on linux and possibly windows as well, unless developing for windows means i will have to write it all over again.. let me know what your reactions are. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Abstract and concrete syntax
"Greg Ewing" wrote: > > More generally, I think there is no abstract distinction between > > statements and expressions. Everything is an expression, can be evaluated > > to a value. > > That's true in a functional language, but Python is not a > functional language. In imperative programming, often you just > do something for its side effect, and there's no obvious value > to return. Forcing everything to return a value just for the > sake of conceptual purity is an artificiality, in my view. Well, I guess what makes an artificiality is subjective then, because IMO the distinction between expressions and statements is a bigger artificiality. Python already uses a default value (None) to return from a callable, so what makes statements special ? Certainly not the side effects, as the two equivalent ways to set an attribute show: a.x = val# statement setattr(a,'x',val) # expression George -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing func_closure?
Greg Ewing wrote: > As far as I know, there is currently no supported way > of directly creating or modifying cell objects from Python; > it can only be done by some obscure trickery. So the docs > are telling the truth here, in a way. :-) In a twisted, convoluted way :) But thanks for the clarification (which IMHO belongs in the docs). Oh well, it was a dirty hack anyways, so it's probably best not done. Cheers, f -- http://mail.python.org/mailman/listinfo/python-list
Re: Incorrect number of arguments
Steven D'Aprano wrote: > I worked around this problem by predicting what error message to expect > given N expected arguments and M supplied arguments. Yuck: this is a > messy, inelegant, ugly hack :-( Thank goodness that functions are first > class objects that support introspection :-) *eureka moment* I can use introspection on the function directly to see how many arguments it accepts, instead of actually calling the function and trapping the exception. > So, I'm wondering if there is a good reason why TypeError is generated > instead of (say) ArgumentError, or if it is just a wart of the language > for historical reasons? Still a good question though. Why is it TypeError? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
appending an array to a list in BOOST / Python
i have an array in C++ (array[100]) and i want to append that to the list can i just say list1.append(array) without actually traversing through the entire array and appending... how can i do this in BOOST Python please help -- http://mail.python.org/mailman/listinfo/python-list
Incorrect number of arguments
I'm trying to keep an open mind, but I am perplexed about something in Python that strikes me as a poor design. py> def func(a,b): py> print a,b py> func(1) Traceback (most recent call last): File "", line 1, in ? TypeError: func() takes exactly 2 arguments (1 given) Why is the exception raised by passing the wrong number of arguments a TypeError instead of a more specific exception? I'm asking because of a practical problem I had. I have written some test suites for a module, and wanted a test to ensure that the functions were accepting the correct number of arguments, eg if the specs say they take three arguments, that they actually do fail as advertised if you pass the wrong number of arguments. That should be simple stuff to do. Except that I have to distinguish between TypeErrors raised because of wrong argument counts, and TypeErrors raised inside the function. To add an extra layer of complication, the error string from the TypeError differs according to how many parameters were expected and how many were supplied, eg: func() takes exactly 2 arguments (1 given) func() takes at least 2 arguments (1 given) func() takes at most 1 argument (2 given) etc. I worked around this problem by predicting what error message to expect given N expected arguments and M supplied arguments. Yuck: this is a messy, inelegant, ugly hack :-( Thank goodness that functions are first class objects that support introspection :-) So, I'm wondering if there is a good reason why TypeError is generated instead of (say) ArgumentError, or if it is just a wart of the language for historical reasons? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: anygui,anydb, any opinions?
Tim Roberts ha scritto: > Renato Ramonda <[EMAIL PROTECTED]> wrote: > >>wxWidgets apps look ALMOST native on windows (combobox and similar >>widgets are emulated, and look really bad), > > > That just isn't true. They use the standard combo box. Then it has changed recently. Mind that most stable apps still use wx2.4 > wx uses "sizers" to do the same thing. Same purpose, different philosophy. > I find sizers more natural, but people should certainly stick to whatever > makes them comfortable. I like sizers too, but in my experience wx apps do not use them. Are they by chance something that came with the 2.5/2.6 development cycle? That version is still pretty rare in real world applications. >>And that's not even starting to consider the version mess: try to >>install xCHM, Boa Constructor, aMule, VLC and some other app together... >>instant madness. > > > They why would you do it? gvim and wxPython do the job for me. No mess. Because i USE a chm reader. And I USE aMule, and I USE a multimedia player. I'm not talking about developing (don't get confused by my mention of Boa), I'm talking about using. Only very recently wx introduced a mechanism to keep different versions in parallel. -- Renato Usi Fedora? Fai un salto da noi: http://www.fedoraitalia.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Make Tkinter child window active
Try: > > Label(c, text="Child window").grid() c.focus_set() > root = Tk() "Svennglenn" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > How do i make a child window "active" like the root window? > > from Tkinter import * > > def open_child(): > c = Toplevel(root) > c.title("Child window") > c.geometry('200x160+230+130') > > Label(c, text="Child window").grid() > > root = Tk() > root.title("root window") > > Button(root, text="Open child window", command=open_child).grid() > > root.mainloop() > > > When the child windows opens i would like it to be active like the > root window, how can i easily do that? > -- http://mail.python.org/mailman/listinfo/python-list
Re: poker card game revisited (code included)
John Hazen wrote: > Interesting. I've been thinking about playing with this stuff too, but > hadn't considered masks. So each card has a representation: > > n bits for rank, then m bits for suit. > > 10 0001 = 2 clubs > 01 1000 = K spades > ... You can also deal with them as a mask of card indexes. So the deuce of clubs is bit 0, the three of clubs is bit 1, all the way up to the ace of spades, which is bit 51. (That obviously won't fit in an int; you'll need a long.) -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis You are the lovers rock / The rock that I cling to -- Sade -- http://mail.python.org/mailman/listinfo/python-list
Re: help with sending mail in Program
Kent Johnson <[EMAIL PROTECTED]> wrote: >Ivan Shevanski wrote: >> Could someone send me a good tutorial for sending mail then? The one I >> found is not what I'm looking for. Also please dont send me the stmp >> definition cause i've looked at that enough. > >Here is a module I use to send mail to myself using smtplib: Not exactly like this, you didn't. The list of destination addresses in SMTP.sendmail must be a sequence, not a string: >#!/usr/local/bin/python > >''' Send mail to me ''' > >from smtplib import SMTP > >def sendToMe(subject, body): >me = '"Kent Johnson" <[EMAIL PROTECTED]>' >send(me, me, subject, body) > > >def send(frm, to, subject, body): >s = SMTP() >#s.set_debuglevel(1) >s.connect('mail.mycompany.com') >s.ehlo('10.0.3.160') # IP address of my computer, I don't remember why I > needed this > >msg = '''From: %s >Subject: %s >To: %s > >%s >''' % (frm, subject, to, body) > >s.sendmail(frm, to, msg) s.sendmail(frm, [to], msg) >s.quit() > > >if __name__ == '__main__': >sendToMe('Testing', 'This is a test') -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Destructive Windows Script
Magnus Lycka <[EMAIL PROTECTED]> wrote: >rbt wrote: >> data = ['0', 'a', '1', 'b', '2', 'c',\ >> '3', 'd', '4', 'e', '5', 'f',\ >> '6', 'g', '7', 'h', '8', 'i',\ >> '9', 'j', '~', '!', '@', '#',\ >> '$', '%', '^', '&', '*', ';'] >> > >Note that the backslashes are redundant between pairs >of [ ], ( ) or { }. Just write: > > data = ['0', 'a', '1', 'b', '2', 'c', > '3', 'd', '4', 'e', '5', 'f', > '6', 'g', '7', 'h', '8', 'i', > '9', 'j', '~', '!', '@', '#', > '$', '%', '^', '&', '*', ';'] > > >(Not that it solves your disk wiping issue.) This is a lot easier to type: data = list("[EMAIL PROTECTED]&*;") -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: need some cgi help please
i fixed it. the program was going nuts because there were spaces in the name of the file. go figgure. anyway, i changed the way i format the timestamp that becomes the file name and removed the spaces. working all better now. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Abstract and concrete syntax
David Baelde wrote: > Statements are not expressions. > > I feel there are some real problems here. But I can't find anything > absolutely unsolvable. There's no doubt that these problems could be solved in a technical sense, but the real issue is whether the resulting code would be *readable*. One of Python's major strengths is that its code is usually very easy to read, even if it means being a bit more verbose at times than strictly necessary. All the proposals I've seen for statements-in-expressions in Python (and there have been quite a few) have been a disaster in the readability department > PEP #308 was about having a ternary (?:) > operator for expression level conditional, pythonists rejected it. Actually, it was really Guido who rejected it, because Pythonistas failed to reach a consensus on syntax, and he wasn't really hot on the idea in the first place. If he had really wanted it, he would have just picked a syntax himself. > More generally, I think there is no abstract distinction between > statements and expressions. Everything is an expression, can be evaluated > to a value. That's true in a functional language, but Python is not a functional language. In imperative programming, often you just do something for its side effect, and there's no obvious value to return. Forcing everything to return a value just for the sake of conceptual purity is an artificiality, in my view. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: OO re-factoring (was Pythonese/Efficiency/Generalese critique [on Tutor])
Thanks for the comment Dan,Yes, that much I'm aware of. I just thought I'd refactor my little utility in an OO approach as an exercise. What I've learned so far is that my non-OO approach is in this situation very efficient, succinct and non-duplicative. Except for avoiding multiple argument passing (globals not even considered ;') there seems little to be gained. Even so, one learns best by doing and I'm gaining a better understanding of OOP (and where to apply such). The oak trees are hard on this old head though :~)Thanks again,Lee COn Jun 8, 2005, at 11:40 PM, [EMAIL PROTECTED] wrote:Subject: Re: OO re-factoring (was Pythonese/Efficiency/Generalese critique [on Tutor]) Dan Sommers wrote: I don't remember the original post, but methods and recursion are *not* mutually exclusive (e.g., an Integer class with a factorial method, or a binary tree class whose nodes are also binary trees). Also, don't think that you have to make everything OO. OO isn't necessarily better than non-OO. It's a means to an end, not an end in itself. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
RE: help
-Ivan >From: [EMAIL PROTECTED] >To: python-list@python.org >Subject: help >Date: Thu, 2 Jun 2005 11:11:41 EDT > >When i try to open IDLE(python GUI) it says that i have a socket error: >conection refused what do i do to fix this >-- Reinstall my friend. . .Reinstalling is the cure for everything. . . -Ivan _ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Rocco Moretti wrote: > The main problem is that Python is trying to stick at least three > different concepts onto the same set of operators: equivalence (are > these two objects the same?), ordering (in a sorted list, which comes > first?), and mathematical "size". A possible compromise would be to add a new special method, such as __equal__, for use by == and != when there is no __eq__ or __ne__. Then there would be three clearly separated levels of comparison: (1) __cmp__ for ordering, (2) __equal__ for equivalence, (3) __eq__ etc. for unrestricted semantics. > This gives the wacky world where > "[(1,2), (3,4)].sort()" works, whereas "[1+2j, 3+4j].sort()" doesn't. To solve that, I would suggest a fourth category of "arbitrary ordering", but that's probably Py3k material. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
identifying 64-bit Windows from 2.3.5?
If I have installed 2.3.5 from the python.org Windows installer, can any one point me to a run-time way to identify whether I'm running on a 32-bit vs. 64-bit version of Windows XP, given that Python itself was built on/for a 32-bit system? I hoped sys.getwindowsversion() was the answer, but it returns the same platform value (2) on both 32-bit and 64-bit systems. sys.platform ("win32") and sys.maxint are both set at compile time. Things like os.uname() aren't on Windows. Can some Windows-savvy Pythonista point me to some way to distinguish between these two? Thanks, --SK -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Jordan Rastrick wrote: > Where are the 'number of situations' where __ne__ cannot be derived > from __eq__? Is it just the floating point one? I must admit, I've > missed any others. The floating point one is just an example, it's not meant to be the entire justification. Some others: * Numeric arrays, where comparisons return an array of booleans resulting from applying the comparison to each element. * Computer algebra systems and such like, which return a parse tree as a result of evaluating an expression. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Jordan Rastrick wrote: > But I explicitly provided a method to test equality. Actually, no, you didn't. You provided a method to define the meaning of the operator spelled '==' when applied to your object. That's the level of abstraction at which Python's __xxx__ methods work. They don't make any semantic assumptions. It's arguable that there should perhaps be some default assumptions made, but the Python developers seem to have done the Simplest Thing That Could Possibly Work, which isn't entirely unreasonable. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: __init__.py in packages
Gary Wilson Jr wrote: I would really like to see an example or situation that makes good use of the __init__.py file. I've attached a non-trivial example, from my PyGUI package. It uses some trickery to switch in one of a number of subdirectories of platform specific code, and then imports a bunch of names from submodules into the top-level package, so the user can pretend he's just using a single top-level module, e.g. from GUI import Window even though Window is actually defined in some submodule. This is a rather extreme example, though -- most __init__.py files are much simpler! -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg _versions = [ ("Carbon", "Mac"), ("gtk", "Gtk"), ] from os import environ as _env _platdir = _env.get("PYGUI_IMPLEMENTATION") if not _platdir: for _testmod, _platdir in _versions: try: __import__(_testmod) break except ImportError: continue else: raise ImportError("Unable to find an implementation of PyGUI for this installation") print "PyGUI: Using implementation:", _platdir from os.path import join as _join _here = __path__[0] __path__.append(_join(_here, _platdir)) __path__.append(_join(_here, "Generic")) from Version import version from Actions import Action from AlertFunctions import alert, alert2, alert3, \ stop_alert, note_alert, confirm, ask, confirm_or_cancel, ask_or_cancel from Applications import Application, application from Buttons import Button from CheckBoxes import CheckBox from Colors import Color, rgb from Components import Component from Dialogs import Dialog from Documents import Document from Events import Event from Exceptions import Cancel from FileDialogs import request_old_file, request_new_file from Files import FileRef, DirRef from Fonts import Font from Containers import Frame from Images import Image from Labels import Label from Menus import Menu from MessageHandlers import MessageHandler from ModalDialogs import ModalDialog from Models import Model from Pixmaps import Pixmap from Properties import Properties, overridable_property from RadioButtons import RadioButton from RadioGroups import RadioGroup from ScrollBars import ScrollBar from ScrollFrames import ScrollFrame import StdColors import StdFonts from Tasks import Task from TextFields import TextField ##from TextModels import TextModel ##from TextViews import TextView from Views import View from Windows import Window -- http://mail.python.org/mailman/listinfo/python-list
Python Challenge web site
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit http://www.pythonchallenge.com/ anybody get to the level 30? :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: anygui,anydb, any opinions?
Renato Ramonda <[EMAIL PROTECTED]> wrote: > >wxWidgets apps look ALMOST native on windows (combobox and similar >widgets are emulated, and look really bad), That just isn't true. They use the standard combo box. >Last time I looked wx did not have spacers (vbox, hbox and the like)... >this leads to ugly non resizable vb-style guis, in my experience wx uses "sizers" to do the same thing. Same purpose, different philosophy. I find sizers more natural, but people should certainly stick to whatever makes them comfortable. >And that's not even starting to consider the version mess: try to >install xCHM, Boa Constructor, aMule, VLC and some other app together... >instant madness. They why would you do it? gvim and wxPython do the job for me. No mess. -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: file permissions on windows XP (home)
Hi All-- [EMAIL PROTECTED] wrote: > > I have noticed a bug that if I have a folder open for viewing in > Windows Explorer with Thumbnail view enabled that I often run into > inexplicable problems with modify permissions, say when I want to > rename or delete an item. Changing the view to Detailed or rebooting > seems to make the issue go away. > Makes sense. With the thumbnail view enabled, Windows has to monitor every file in the directory for changes, and update the thumbs all the time. With other types it watches for changes, but it doesn't have to be so obsessive about it. Now that I think about it, the times that I've had permission trouble it's always been with thumbs. Not definitive, but worth looking out for. Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding: many interpreters OR one interpreter with many thread states ?
[EMAIL PROTECTED] wrote: > - creating many sub-interpreters (Py_NewInterpreter) with a thread > state each > > Or > > - creating one interpreter with many thread states (PyThreadState_New) My understanding is that using multiple interpeters isn't really supported properly, despite there being apparent support in the API. So I suggest using a single interpeter with multiple threads. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: \r\n or \n notepad editor end line ???
Peter Hansen wrote: > (I don't believe there's a "wU" and conceptually it's sort > of meaningless anyway, If we ever get quantum computers, presumably "wU" will write the newlines in all possible formats simultaneously... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: circular import Module
Thomas Guettler wrote: > file1.py: > import file2 > > > file2.py: > # import file1 # Does not work! Actually, that *will* work as long as you don't try to use anything from file1 until it has finished being loaded. What won't work is file2.py: from file1 import somename because somename won't yet have been defined in file1 at the time file2 is imported. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing func_closure?
Fernando Perez wrote: > I can reuse the closure from a different > function, but the docs don't say how to make a valid closure tuple. This is > the typical problem of the stdlib docs, which under-specify what is supposed > to > go into a call and don't give at least a specific example. As far as I know, there is currently no supported way of directly creating or modifying cell objects from Python; it can only be done by some obscure trickery. So the docs are telling the truth here, in a way. :-) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Walking through a mysql db
On Jun 4, 2005, at 9:24 AM, Jeff Elkins wrote: > I'm writing a small wxpython app to display and update a dataset. Have you looked at Dabo (URL is in my sig)? You can create an app to select, edit and update a MySQL database in about 30 seconds. It also wraps wxPython to make creating custom apps a whole lot easier than if you were to use wxPython by itself. ___/ / __/ / / Ed Leafe http://leafe.com/ http://dabodev.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: OO re-factoring (was Pythonese/Efficiency/Generalese critique [on Tutor])
Dan Sommers wrote: > I don't remember the original post, but methods and recursion are *not* > mutually exclusive (e.g., an Integer class with a factorial method, or a > binary tree class whose nodes are also binary trees). Also, don't think that you have to make everything OO. OO isn't necessarily better than non-OO. It's a means to an end, not an end in itself. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Abstract and concrete syntax
"David Baelde" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Hi, > > I tried python, and do like it. Easy to learn and read (at least for the > commonly used part), has a very large community so great doc and > contributions, and... the design is clean. I come from functional > programming languages, and I do like the proper static binding, the first > class functions. That's what interests me in Python. It's the most modern > of those addictive scripting languages. > > But, there is something I can't believe. Statements are not expressions. I > tried to find some doc about that on the web. I'm not satisfied, and I'd > like to learn more and discuss here. > > First, there are some trolls about Python Zen forbidding statements to be > expressions. But I think the Zen is often contradictory. I don't like > trolls, want something serious. > > Basically, I found one good point against statements-as-expressions: it > cannot fit the indentation sensitive syntax. > > --- > http://mail.python.org/pipermail/python-list/2005-January/260566.html > Python allows statements inside suites and suites inside compound > statements. It also allows expressions inside statements and expressions > inside expressions. The one thing it never ever does is allow a suite or a > statement inside an expression, because doing so would utterly destroy the > handling of significant white space. > --- > > I feel there are some real problems here. But I can't find anything > absolutely unsolvable. I played a few examples, can't get anything > ambiguous. Maybe the nesting analyzer > (http://python.org/doc/2.4.1/ref/indentation.html) needs to take into > account parenthesis-like delimiters together with indentation, but that > doesn't look impossible (although I suspect it's harder than I can > imagine). > The parenthesis trick could avoid over-deep indentation. > > set_callback(obj, > lambda x: (if a: > 2 > else: > 3) > > Well, I suspect there are some moral issues, and maybe pythonists don't > want statements in expressions. There are a number of ways of doing it; I suspect that the BDFL simply doesn't want it. > PEP #308 was about having a ternary (?:) > operator for expression level conditional, pythonists rejected it. I'd > like to read more about the motivations of the vote. Well, Guido has been against it from the start. He finally decided to put it up to the community to vote on the appropriate syntax. As you can imagine, there were a huge (well, a couple of dozen) different syntax suggestions, so it was effectively impossible to get a majority vote. Result: proposal killed permanently with a sham showing of giving the community a say in it. Unfortunately, I found out about Condorcet voting too late; by that time the original tallies no longer existed so they could not be reanalyzed. > But I guess you'll have more to say on that subject... > __ > David > -- http://mail.python.org/mailman/listinfo/python-list
Re: need some cgi help please
[EMAIL PROTECTED] wrote: > IOError: [Errno 2] No such file or directory: > '/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun 7 20:13:35 > 2005.txt' > args = (2, 'No such file or directory') The web server isn't running in a chrooted environment or anything, is it? Are there any other files that it *can* open? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Abstract and concrete syntax
Hi, I tried python, and do like it. Easy to learn and read (at least for the commonly used part), has a very large community so great doc and contributions, and... the design is clean. I come from functional programming languages, and I do like the proper static binding, the first class functions. That's what interests me in Python. It's the most modern of those addictive scripting languages. But, there is something I can't believe. Statements are not expressions. I tried to find some doc about that on the web. I'm not satisfied, and I'd like to learn more and discuss here. First, there are some trolls about Python Zen forbidding statements to be expressions. But I think the Zen is often contradictory. I don't like trolls, want something serious. Basically, I found one good point against statements-as-expressions: it cannot fit the indentation sensitive syntax. --- http://mail.python.org/pipermail/python-list/2005-January/260566.html Python allows statements inside suites and suites inside compound statements. It also allows expressions inside statements and expressions inside expressions. The one thing it never ever does is allow a suite or a statement inside an expression, because doing so would utterly destroy the handling of significant white space. --- I feel there are some real problems here. But I can't find anything absolutely unsolvable. I played a few examples, can't get anything ambiguous. Maybe the nesting analyzer (http://python.org/doc/2.4.1/ref/indentation.html) needs to take into account parenthesis-like delimiters together with indentation, but that doesn't look impossible (although I suspect it's harder than I can imagine). The parenthesis trick could avoid over-deep indentation. set_callback(obj, lambda x: (if a: 2 else: 3) Well, I suspect there are some moral issues, and maybe pythonists don't want statements in expressions. PEP #308 was about having a ternary (?:) operator for expression level conditional, pythonists rejected it. I'd like to read more about the motivations of the vote. Many people will tell me that my tiny example can be written with the if-else outside the assignation. I claim it's better to be able to express it the way you mean it. That's why lambda is here for, too. More generally, I think there is no abstract distinction between statements and expressions. Everything is an expression, can be evaluated to a value. Making function first class objects was the same kind of good and beautiful idea. So if there is no abstract distinction, why should there be a concrete one? If it's just a technical issue, let's work on it. But I guess you'll have more to say on that subject... __ David -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal Places Incorrect
Tom Haddon wrote: > Hi Folks, > > When I run: > > print "%0.2f" % ((16160698368/1024/1024/1024),) > > I get 15.00 > > I should be getting 15.05. Can anyone tell me why I'm not? Because you forgot to use "from __future__ import division". -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Paul Rubin wrote: > We're just talking about a scrolling text window that has to run at > human reading and typing speeds, right? It shouldn't be a problem. > I've used the text widget and found it to be fast enough for what I > was doing, though I didn't exactly stress it. It should have burst speeds of 2-10x reading speed; given the stop-and-start nature of most muds, the data comes in bursts that the player processes and reacts to before the next burst. It's good to know that my concerns seem mostly unfounded. When I get to a reasonable state of implementation, I'll post here if I've made any unexpected discoveries. -- PS: Really sorry to everyone about all the e-mails I've generated. I'm not quite used to Thunderbird, and it puts "reply to sender only" where I'd expect "reply to newsgroup" to be. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal Places Incorrect
Tom Haddon wrote: > Hi Folks, > > When I run: > > print "%0.2f" % ((16160698368/1024/1024/1024),) > > I get 15.00 > > I should be getting 15.05. Can anyone tell me why I'm not? Short answer: Integer division. Long answer: Integer division. 16160698368/1024 = 15781932L 15781932L/1024 = 15412 15412/1024 = 15 Fix: >>> print "%.02f" % (float(16160698368)/1024/1024/1024,) 15.05 -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Jp Calderone <[EMAIL PROTECTED]> writes: > What does "included with Python" mean anyway? Different packagers > make different decisions. I mean included with the source distro from python.org. > This applies to other libraries as well, of course. Installing > wxPython on Debian is a 5 second ordeal. I don't believe that, unless you're installing a binary. I only want to install from source. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabnanny?
"Anna M." <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thank you so much > and so it goes . . . > > from random import randint > > def idxLargest(list, n): >idxMx = 0 > >for i in range(1, n, 1): > >if list[i] > list[idxMx]: >idxMx = i > >return idxMx > > > def radixSort(data): >sorting = [data] >tmp = [] > >for i in range(10): >tmp.append([]) > >idx = idxLargest(data, len(data) <<<= needs end parenthesis = missing ) x >max = data[idx] >passes = len(max) + 1 > >for i in range(1, passes + 1, 1): >sorter = tmp > >for bucket in sorting: > >for next in bucket: >nr = next%(10**i) >radix = (nr/10**(i-1)) >sorter[radix].append(next) > >sorting = sorter >return sorting > > n = 10 > a = 0 > b = 200 > test = [] > for i in range(n): >test.append(randint(a,b)) > > print test > test = radixsort(test) > print test > > > >>Hi Anna ! >> >>Please post your code, so we can take a look to see what is happening. >> >>See ya ! >> >>Em Quarta 08 Junho 2005 23:36, Anna M. escreveu: >>> Hello, i am very new to this. Only heard of python a week ago and have >>> never posted before anywhere. But I am trying to rewrite a program that >>I >>> made in C++ in Python, a radixSort I did as a school project. I get a >>> Tabnanny Tokenizing Error that says Token Error: EOF in multi-line >>> statement. I gather from the internet that it means I have a tab-error. >>I >>> just can't seem to find it. Is this something you can help me with? >>Could >>> I post my code here and you could look at it or is that a bit to much ;) >>> >>> Many thanks, >>> >>> Anna > > -- > Douglas Soares de Andrade > http://douglasandrade.cjb.net - dsa at unilestemg.br > UnilesteMG - www.unilestemg.br > ICQ, MSN = 76277921, douglas at tuxfamily.org > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: refactoring, unit testing, ant, etc.
"Dave Rose" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello all > I've been learning Python for the past few months, reading tutorials and > postings here. I've bought the personal Komodo then downloaded Eclipse > with > Pydev. IDLE also is a staple of everyday use. > > ~10 years ago, I had CS as a minor in college. I learned some C and > modula-2 > to name the relevent languages. Back then I was compiling on a VAX. Much > different than today. > > I was hoping someone could guide me a bit with current-day practices. > I've > been pythoning along, but I hear about things I don't know about > (re-factoring, > unit-testing, debugging, ant build tools) and I don't know how they're > applicable to make my life easier. Tutorials didn't shed too much > light -- > they make it seem to be more work than I need now. > > To be clear, I've used debuggers in the past, but it seems when I set > break- > points, the Eclipse just skips merrily past them, or steps at every line, > and > for wxPython, that's annoying given all the support libraries. I also use > wxPython and wxGlade, so those seem to ignore debug mode completely for > some > reason. > > Can someone please shed some light onto how I should really use my IDE to > make my life more enjoyable? I feel I just don't know how to use the > tools > that are available, and that's frustrating. It's actually not an IDE issue (well, not much of one). I never use the debugger. The next thing to learn is probably Test Driven Development. Kent Beck's book (Test Driven Development by Example) has an extended example in Python as the second section. TDD is simply the practice of writing a test, then writing the code to make it pass, then writing another test and so forth. As long as you make sure all the tests keep passing, whenever one of them breaks it's probably the last edit you made, which makes it real easy to figure out what the problem is and fix it. The easiest way to ease into refactoring is to ruthlessly eliminate duplication in your programs. One of the really interesting things about this is that you can frequently see the right abstractions and design patterns just emerge without having to design them up front. Doesn't always happen, but it does often enough to be really gratifying. The Python library contains a module named unittest which is the Python equivalent of JUnit etc. I normally run my test suite out of a command line that I keep open while I'm working. I think PyDev in Eclipse has support for it, but since I don't use that I'm not at all sure. John Roth > > Thanks so much! > Dave > -- http://mail.python.org/mailman/listinfo/python-list
Re: file permissions on windows XP (home)
I have noticed a bug that if I have a folder open for viewing in Windows Explorer with Thumbnail view enabled that I often run into inexplicable problems with modify permissions, say when I want to rename or delete an item. Changing the view to Detailed or rebooting seems to make the issue go away. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal Places Incorrect
Tom Haddon wrote: > Hi Folks, > > When I run: > > print "%0.2f" % ((16160698368/1024/1024/1024),) > > I get 15.00 > > I should be getting 15.05. Can anyone tell me why I'm not? Integer division does not yield floats. http://docs.python.org/lib/typesnumeric.html -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Decimal Places Incorrect
Hi Folks, When I run: print "%0.2f" % ((16160698368/1024/1024/1024),) I get 15.00 I should be getting 15.05. Can anyone tell me why I'm not? Thanks, Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
On 08 Jun 2005 17:26:30 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: >Riccardo Galli <[EMAIL PROTECTED]> writes: >> Using tkinter doesn't need downloading and installing only in Windows. >> In *nix is not so common to have tcl/tk installed (and probably in Mac too) > >Hmm, in the Linux distros that I'm used to, tcl/tk is preinstalled. I >had the impression that it was included with Python but obviously I >haven't looked that closely. What does "included with Python" mean anyway? Different packagers make different decisions. Some may include Tcl/Tk, others may exclude it. Some may provide a separate but trivially-installable package for it. On systems with reasonable package managers, it barely makes a difference, as any packaged software is at most one or two simple commands away. This applies to other libraries as well, of course. Installing wxPython on Debian is a 5 second ordeal. This is not to say debian is awesome and you should go install it right now or *else*, just to say that the installation of a single piece of software can vary greatly in difficulty between different platforms. Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Riccardo Galli <[EMAIL PROTECTED]> writes: > Using tkinter doesn't need downloading and installing only in Windows. > In *nix is not so common to have tcl/tk installed (and probably in Mac too) Hmm, in the Linux distros that I'm used to, tcl/tk is preinstalled. I had the impression that it was included with Python but obviously I haven't looked that closely. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
On Wed, 08 Jun 2005 13:58:00 -0700, Paul Rubin wrote: > Christopher Subich <[EMAIL PROTECTED]> writes: >> > Use tkinter if you care about cross-platform operation. Everything >> > else requires downloading and installing separate toolkits. >> >> Oh, the downloading and installing isn't a big deal. If in the >> far-flung future anyone else uses this program, they'll be big boys who >> can install things themselves. :) > > No, it's a big pain. I'm a big boy and gave up on trying to install > wxpython for bittorrent on FC3 (the problem was with wxwidgets needing an > obsolete version of gtk, not with wxpython itself). There's just no > compelling reason to want to deal with this stuff. Tkinter has its warts > but it allows making functional gui's without all that much fuss. Using tkinter doesn't need downloading and installing only in Windows. In *nix is not so common to have tcl/tk installed (and probably in Mac too) GUI cross platform need external support, in a OS or in another. Bye, Riccardo -- Riccardo Galli Sideralis Programs http://www.sideralis.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabnanny?
Hi Anna ! > idx = idxLargest(data, len(data) In this line we have a missing ")", for me, this was the problem. Anyway, Check this line too: passes = len(max) + 1 It is giving me an error. See ya ! -- Douglas Soares de Andrade http://douglasandrade.cjb.net - dsa at unilestemg.br UnilesteMG - www.unilestemg.br ICQ, MSN = 76277921, douglas at tuxfamily.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
> > That looks quite good, except that Trolltech doesn't yet have a GPL-qt > for Win32. I might take another look at it whenever qt4 comes out, but > in the meantime (since I'm unfortunately developing on a win2k system) > it's not useful. Look at qt feee win edition, available here: http://pythonqt.vanrietpaap.nl/ Diez -- http://mail.python.org/mailman/listinfo/python-list
Software for System Builders, Resellers, and Hardware Purchasers Only.
GET latest softwares, 99% savings. http://djjnjs.b0fqeab48lt0qub.risalafe.com There is a fullness of all things, even of sleep and love. Be not ashamed of mistakes and thus make them crimes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a DOM element's children by type (STUPID)
Tom Anderson wrote: > This strikes me as a rather common thing to want to do, but i can't see > a method for it; it seems i have to go through elem.childNodes myself, > fishing out the ones i want. Or rather, to write exactly the same > three-line helper function that millions of other people must have > written to do this. Am i missing something blindingly obvious? I'm happy > to RTFM here, but would appreciate a pointer to the appropriate such > manual, since the docs i have to hand are somewhat unenlightening. No RTFM here - it's just that (stupid..) way. Go read up RTFMs on elementtree or XPath though - they'll do what you want. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: MoinMoin WikiName and python regexes
Ara.T.Howard wrote: > i know nada about python so please forgive me if this is way off base. i'm > trying to fix a bug in MoinMoin whereby > > WordsWithTwoCapsInARowLike I don't think there is such a thing as the perfect "hyperlink vs just-text" convention. In MoinMoin, you can force a custom link using e.g.: [wiki:WebsiteSecurity this is the link text to WebsiteSecurity so call it whatever you want such as WebsiteSecurities] This custom linking, whilst obviously not ideal, solves the problems mentioned at http://www.c2.com/cgi/wiki?WikiName This seems better than producing endless confusing variations on the "standard" (be it formal, actual, or simply obviously desired). I'm not convinced of the usefulness of MoinMoin's "subpages" idea, while we're on the (related) subject - they seem to create more problems than they solve: http://moinmoin.wikiwikiweb.de/HelpOnEditing/SubPages -- http://mail.python.org/mailman/listinfo/python-list
RE: Tabnanny?
Thank you so much and so it goes . . . from random import randint def idxLargest(list, n): idxMx = 0 for i in range(1, n, 1): if list[i] > list[idxMx]: idxMx = i return idxMx def radixSort(data): sorting = [data] tmp = [] for i in range(10): tmp.append([]) idx = idxLargest(data, len(data) max = data[idx] passes = len(max) + 1 for i in range(1, passes + 1, 1): sorter = tmp for bucket in sorting: for next in bucket: nr = next%(10**i) radix = (nr/10**(i-1)) sorter[radix].append(next) sorting = sorter return sorting n = 10 a = 0 b = 200 test = [] for i in range(n): test.append(randint(a,b)) print test test = radixsort(test) print test >Hi Anna ! > >Please post your code, so we can take a look to see what is happening. > >See ya ! > >Em Quarta 08 Junho 2005 23:36, Anna M. escreveu: >> Hello, i am very new to this. Only heard of python a week ago and have >> never posted before anywhere. But I am trying to rewrite a program that >I >> made in C++ in Python, a radixSort I did as a school project. I get a >> Tabnanny Tokenizing Error that says Token Error: EOF in multi-line >> statement. I gather from the internet that it means I have a tab-error. >I >> just can't seem to find it. Is this something you can help me with? >Could >> I post my code here and you could look at it or is that a bit to much ;) >> >> Many thanks, >> >> Anna -- Douglas Soares de Andrade http://douglasandrade.cjb.net - dsa at unilestemg.br UnilesteMG - www.unilestemg.br ICQ, MSN = 76277921, douglas at tuxfamily.org -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabnanny?
Hi Anna ! Please post your code, so we can take a look to see what is happening. See ya ! Em Quarta 08 Junho 2005 23:36, Anna M. escreveu: > Hello, i am very new to this. Only heard of python a week ago and have > never posted before anywhere. But I am trying to rewrite a program that I > made in C++ in Python, a radixSort I did as a school project. I get a > Tabnanny Tokenizing Error that says Token Error: EOF in multi-line > statement. I gather from the internet that it means I have a tab-error. I > just can't seem to find it. Is this something you can help me with? Could > I post my code here and you could look at it or is that a bit to much ;) > > Many thanks, > > Anna -- Douglas Soares de Andrade http://douglasandrade.cjb.net - dsa at unilestemg.br UnilesteMG - www.unilestemg.br ICQ, MSN = 76277921, douglas at tuxfamily.org -- http://mail.python.org/mailman/listinfo/python-list
Tabnanny?
Hello, i am very new to this. Only heard of python a week ago and have never posted before anywhere. But I am trying to rewrite a program that I made in C++ in Python, a radixSort I did as a school project. I get a Tabnanny Tokenizing Error that says Token Error: EOF in multi-line statement. I gather from the internet that it means I have a tab-error. I just can’t seem to find it. Is this something you can help me with? Could I post my code here and you could look at it or is that a bit to much ;) Many thanks, Anna -- http://mail.python.org/mailman/listinfo/python-list
Saving/retrieving user preferences
This may be a FAQ,but I cannot find it. I want to save user preferences, window sizes, recently opened file names, etc for a python application and I am looking for a package that does this in a way that is portable across unix/linux and windows (and mac would be nice as well). Is there a 'standard' package for doing this in python? thanks, -- http://mail.python.org/mailman/listinfo/python-list
refactoring, unit testing, ant, etc.
Hello all I've been learning Python for the past few months, reading tutorials and postings here. I've bought the personal Komodo then downloaded Eclipse with Pydev. IDLE also is a staple of everyday use. ~10 years ago, I had CS as a minor in college. I learned some C and modula-2 to name the relevent languages. Back then I was compiling on a VAX. Much different than today. I was hoping someone could guide me a bit with current-day practices. I've been pythoning along, but I hear about things I don't know about (re-factoring, unit-testing, debugging, ant build tools) and I don't know how they're applicable to make my life easier. Tutorials didn't shed too much light -- they make it seem to be more work than I need now. To be clear, I've used debuggers in the past, but it seems when I set break- points, the Eclipse just skips merrily past them, or steps at every line, and for wxPython, that's annoying given all the support libraries. I also use wxPython and wxGlade, so those seem to ignore debug mode completely for some reason. Can someone please shed some light onto how I should really use my IDE to make my life more enjoyable? I feel I just don't know how to use the tools that are available, and that's frustrating. Thanks so much! Dave -- http://mail.python.org/mailman/listinfo/python-list
Getting a DOM element's children by type (STUPID)
Hi, If i get myself a DOM tree using xml.dom.minidom (or full-fat xml.dom, i don't mind), is there an easy way to ask a element for its child elements of a particular type? By 'type' i mean 'having a certain tag'. This strikes me as a rather common thing to want to do, but i can't see a method for it; it seems i have to go through elem.childNodes myself, fishing out the ones i want. Or rather, to write exactly the same three-line helper function that millions of other people must have written to do this. Am i missing something blindingly obvious? I'm happy to RTFM here, but would appreciate a pointer to the appropriate such manual, since the docs i have to hand are somewhat unenlightening. Thanks, tom -- Just because Congresspeople do it, doesn't mean it's right. -- Ian York -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
On Wed, 08 Jun 2005 11:01:27 -0700, Mahesh wrote: > No, why should Python assume that if you use != without supplying a > __ne__ that this is what you want? Without direction it will compare > the two objects which is the default behavior. Why should Python assume that != means "not is" instead of "not equal"? That seems like an especially perverse choice given that the operator is actually called "not equal". > So, s != t is True because the ids of the two objects are different. > The same applies to, for example s > t and s < t. Do you want Python to > be smart and deduce that you want to compare one variable within the > object if you don't create __gt__ and __lt__? I do not want Python to > do that. That is an incorrect analogy. The original poster doesn't want Python to guess which attribute to do comparisons by. He wants "!=" to be defined as "not equal" if not explicitly overridden with a __ne__ method. If there are no comparison methods defined, then and only then does it make sense for == and != to implicitly test object identity. I'm all for the ability to override the default behaviour. But surely sensible and intuitive defaults are important? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: poker card game revisited (code included)
[Erik Max Francis] > > > Searching for straights and flushes is much better done by masks. Interesting. I've been thinking about playing with this stuff too, but hadn't considered masks. So each card has a representation: n bits for rank, then m bits for suit. 10 0001 = 2 clubs 01 1000 = K spades ... [flupke] > > As for straights, if i understand correctly, you make all possible > > straights of the cards in the hand and then see if one matches? Yeah, I originally thought that's what you meant, too. But if you take the scheme above, and sort the cards before you merge them into the hand-bits aggregate, then you can just have *one* mask for straights, and shift it down by a bit each time you check. So the best straight mask (A high) would be (ignoring suit bits): 10 01 001000 000100 10 Then this could be shifted right for a K-high straight: 01 001000 000100 10 01 I guess that means that an Ace has to have the following representation, since it can be both at the high and low end of a straight: 11 0100 = A hearts But this may mess with bit-counting shortcuts for other calculations... This is interesting to think about. Thanks for the pointer. I'm also going to look at pokersource, though I may put that off until I at least partially re-invent the wheel for learning purposes. -John -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with SMTP
"Ivan Shevanski" <[EMAIL PROTECTED]> writes: > Ok, all my problems are solved except for one. . .If I want my program > to send a message back to me do I need the from adress? Because I > don't specifically know it for the person using the program. Any help > is appreciated =D You need a from address for the SMTP transaction. You really should have a From: field in the message headers as well, but the message may work without that. In one sense, the message is "from" you, as it's being sent by your script. I'd be tempted to cons up a maildrop for the script, alias it to point at your mailbox, and then use that as the "From" address for the mail you're sending. You could ask the user to input an email address and use that as the >From address. Unless you plan on getting back to them via email, I wouldn't bother. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Robert Kern wrote: > The problem arises that, in the presence of rich comparisons, (a == b) > is not always a boolean value, while (a is b) is always a boolean value. But that still doesn't mean that in a case where a == b (via __eq__) returns a non-boolean, __ne__ would not be defined as well. In other words, there's _nothing_ preventing this "fix" from being made to provide saner behaviour in the most common case (which happens to pose the greatest risk of inadvertent mistakes for those who aren't aware of the requirement to define both) while still allowing the cases that need unusual behaviour to get it by (as they already surely do!) defining both __ne__ and __eq__. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Jp Calderone wrote: > If you like, you can check out the code: > > http://sourceforge.net/projects/originalgamer > > As MUD clients go, it's pretty weak, but it solves the text display > problem pretty decently. Oooh! Code! Thanks! After taking an extremely quick look, I think I might be kicking myself soon for not knowing about Twister and writing socket code thus far instead. Interesting to see how someone else solves a the same problem. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Christopher Subich wrote: > Perhaps the language should offer > the sensible default of (!=) == (not ==) if one of them but not the > other is overriden, but still allow overriding of both. I believe that's exactly what Jordan is promoting and, having been bitten in exactly the same way I would support the idea. On the other hand, I was bitten only _once_ and I suspect Jordan will never be bitten by it again either. It's pretty hard to forget this wart once you discover it, but I think the real reason to want to have it excised is that a large number of people will have to learn this the hard way, documentation (thankfully) not being shoved down one's throat as one starts intrepidly down the road of overriding __eq__ for the first time. > This would technically break backwards compatibilty, because it changes > default behavior, but I can't think of any good reason (from a python > newbie perspective) for the current counterintuitive behavior to be the > default. Possibly punt this to Python 3.0? I'd support an effort to fix it in 2.5 actually. I suspect nobody will pipe up with code that would actually be broken by it, though some code (as John Roth points out) doesn't *need* to have the automatic __ne__ even if it wouldn't break because of it. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Mahesh wrote: > I understand that what makes perfect sense to me might not make perfect > sense to you but it seems a sane default. When you compare two objects, > what is that comparision based on? In the explicit is better than > implicit world, Python can only assume that you *really* do want to > compare objects unless you tell it otherwise. The only way it knows how > to compare two objects is to compare object identities. This isn't the issue here. I agree that object identity comparison is a good default equality test. The issue is whether this default should be thought of as # your approach (and the current implementation) def __eq__(self, other): return self is other def __ne__(self, other): return self is not other or # my approach def __eq__(self, other): return self is other def __ne__(self, other): return not (self == other) My approach simplifies the implementation (i.e., requires one fewer method to be overridden) of classes for which (x != y) == not (x == y). This is a very common case. Your approach simplifies the implementation of classes for which equality tests are based on data but inequality tests are based on identity (or vice-versa). I can't think of a single situation in which this is useful. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Christopher Subich <[EMAIL PROTECTED]> writes: > Fair enough. At the moment, the expected user base for the program is > exactly one, but making it easy has its advantages. Since you've > obviously used it yourself, if I end up going with tkinter, are there > any performance gotchas on text rendering that I should be aware of? We're just talking about a scrolling text window that has to run at human reading and typing speeds, right? It shouldn't be a problem. I've used the text widget and found it to be fast enough for what I was doing, though I didn't exactly stress it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Well, I'll admit I haven't ever used the Numeric module, but since > PEP207 was submitted and accepted, with Numeric as apparently one of > its main motivations, I'm going to assume that the pros and cons for > having == and ilk return things other than True or False have already > been discussed at length and that argument settled. (I suppose theres a > reason why Numeric arrays weren't just given the same behaviour as > builtin lists, and then simple non-special named methods to do the > 'rich' comparisons.) They were - read the PEP again. That's the behavior they wanted to get away from. > But again, it seems like a pretty rare and marginal use case, compared > to simply wanting to see if some object a is equal to (in a non object > identity sense) object b. > > The current situation seems to be essentially use __cmp__ for normal > cases, and use the rich operations, __eq__, __gt__, __ne__, and rest, > only in the rare cases. Also, if you define one of them, make sure you > define all of them. > > Theres no room for the case of objects where the == and != operators > should return a simple True or False, and are always each others > complement, but <, >= and the rest give an error. I haven't written > enough Python to know for sure, but based on my experience in other > languages I'd guess this case is vastly more common than all others put > together. > > I'd be prepared to bet that anyone defining just __eq__ on a class, but > none of __cmp__, __ne__, __gt__ etc, wants a != b to return the > negation of a.__eq__(b). It can't be any worse than the current case of > having == work as the method __eq__ method describes but != work by > object identity. To quote Calvin Coolege: You lose. The primary open source package I work on, PyFit, always wants to do an equal comparison, and never needs to do a not equal. It also has no use for ordering comparisons. I do not equals as a matter of symmetry in case someone else wants them, but I usually have no need of them. Strict XP says I shouldn't do them without a customer request. > So far, I stand by my suggested change. I think most of your justification is simple chicken squaking, but write the PEP anyway. I'd suggest tightening it to say that if __eq__ is defined, and if neither __ne__ nor __cmp__ is defined, then use __eq__ and return the negation if and only if the result of __eq__ is a boolean. Otherwise raise the current exception. I wouldn't suggest the reverse, though. Defining __ne__ and not defining __eq__ is simply perverse. John Roth > -- http://mail.python.org/mailman/listinfo/python-list
Re: pack heterogeneous data types
On 8 Jun 2005 14:49:00 -0700, [EMAIL PROTECTED] wrote: >Hello, > >How do i pack different data types into a struct or an array. Examples >would be helpful. > >Say i need to pack an unsigned char( 0xFF) and an long( 0x) >into a single array? The reason i need to do this is send a packet over >a network. >>> import struct >>> struct.pack('!BL', 0xff, 0x) '\xff\xaa\xaa\xaa\xaa' >>> Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: pack heterogeneous data types
[EMAIL PROTECTED] wrote: > Hello, > > How do i pack different data types into a struct or an array. Examples > would be helpful. > > Say i need to pack an unsigned char( 0xFF) and an long( 0x) > into a single array? The reason i need to do this is send a packet over > a network. Look at the struct module, struct.pack sounds like what you need. -- http://mail.python.org/mailman/listinfo/python-list
Re: Controlling source IP address within urllib2
John, Thanks again for your help! I think that the do_open function in AbstractHTTPHandler does not return the correct object type as required by the opener. When I include the code you recommended, the implementation comes back with the message, "urlopen error unknown url type: http". Strange, because I would think that overriding the "http_open" function in the handler would have signaled that this function is capable of handling http. If I call the HTTPHandler base class "http_open" function from within the derived class, all works okay, but of course, I don't get to use the source IP address I wanted to use. I'll keep trying and let you know what I find. -Dan -- http://mail.python.org/mailman/listinfo/python-list
windows processes
I am using Trent's process.py but I have a problem with killing the processes in windows. For example : import process,time p=process.ProcessOpen('C:\Program Files\Windows Media Player\wmplayer')time.sleep(3)p.kill() will start Media Player without terminating it. Any suggestions? Thanks in advance. Veronica Discover Yahoo! Find restaurants, movies, travel & more fun for the weekend. Check it out!-- http://mail.python.org/mailman/listinfo/python-list
killing process in windows
Hi, I am using Trent's process.py but I have a problem with killing the processes in windows. For example : import process,time p=process.ProcessOpen('C:\Program Files\Windows Media Player\wmplayer')time.sleep(3)p.kill() will start Media Player without terminating it. Any suggestions? Thanks in advance. Veronica Discover Yahoo! Get on-the-go sports scores, stock quotes, news & more. Check it out!-- http://mail.python.org/mailman/listinfo/python-list
help
When i try to open IDLE(python GUI) it says that i have a socket error: conection refused what do i do to fix this -- http://mail.python.org/mailman/listinfo/python-list
pack heterogeneous data types
Hello, How do i pack different data types into a struct or an array. Examples would be helpful. Say i need to pack an unsigned char( 0xFF) and an long( 0x) into a single array? The reason i need to do this is send a packet over a network. Thanks, -AB -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
On Wed, 08 Jun 2005 14:15:35 -0400, Christopher Subich <[EMAIL PROTECTED]> wrote: >As a hobby project, I'm writing a MUD client -- this scratches an itch, >and is also a good excuse to become familiar with the Python language. >I have a conceptual handle on most of the implementation, but the >biggest unknown for me is the seemingly trivial matter of text display. > >My first requirement is raw speed; none of what I'm doing is >processing-intensive, so Python itself shouldn't be a problem here. But >still, it's highly desirable to have very fast text updates (text >inserted only at the end)-- any slower than 20ms/line stretches >usability for fast-scrolling. EVERY other action on the text display, >though, like scrolling backwards or text selection, can be orders of >magnitude slower. > >The second requirement is that it support text coloration. The exact >markup method isn't important, just so long as individual characters can >be independently colored. > >The third requirement is cross-platform-osity; if you won't hold it >against me I'll tell you that I'm developing under Cygwin in Win2k, but >I'd really like it if the app could run under 'nix and mac-osx also. I've done this with Tkinter before. At the time, I surveyed the various toolkits for the quality of their text widgets, and of Tkinter, PyGTK, PyQT, and wxPython, only Tkinter could satisfy the performance requirements. This was about three years ago, so the field may have changed. If you like, you can check out the code: http://sourceforge.net/projects/originalgamer As MUD clients go, it's pretty weak, but it solves the text display problem pretty decently. Hope this helps, Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: file permissions on windows XP (home)
Thanks, I will go the win32security.SetFileSecurity route. It seems a pity that I can't use platform independant code to sort this out but I guess you're saying that I've managed to get my files into a non standard state that needs non standard code to sort it out. I wonder how winamp/itunes manage to bypass it. Barney -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
I understand that what makes perfect sense to me might not make perfect sense to you but it seems a sane default. When you compare two objects, what is that comparision based on? In the explicit is better than implicit world, Python can only assume that you *really* do want to compare objects unless you tell it otherwise. The only way it knows how to compare two objects is to compare object identities. I am against making exceptions for corner cases and I do think making __ne__ implicitly assume not __eq__ is a corner case. Maybe you think that it takes this explicit is better than implicit philosophy too far and acts dumb but I think it is acting consistently. Cheers, Mahesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Christopher Subich wrote: > You're off by a decimal, though, an 80-column line > at 20ms is 4kbytes/sec. D'oh! Yeah, I did hundredths of a second instead of thousands. > My guess is that any faster throughput than > 10kbytes/sec is getting amusing for a mud, which in theory intends for > most of this text to be read anyway. Which is why I don't think you'll have a problem with any of the standard GUI libraries. > That looks quite good, except that Trolltech doesn't yet have a GPL-qt > for Win32. Cost and license weren't listed as requirements. :) You *did* say "hobby" though in post-hoc justification, I've known people with some pretty expensive hobbies. > See the scrolling problem in the original post, as to why I can't use it > as a temporary user interface. :) Indeed, but MUDs 15 years ago could run in a terminal and display colored text via ANSI terminal controls, letting the terminal itself manage history and scrolling. I had some sort of TSR for the latter, under DOS. Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Jordan Rastrick wrote: > Mahesh raised the argument some posts back that Python should not 'just > guess' what you want. But the problem is, it *already does* - it > guesses you want object identity comparison if you haven't written > __ne__. But if __ne__ is not provided, than the negation of > > a==b > > is *surely* a better guess for a != b than the negation of > > a is b The problem arises that, in the presence of rich comparisons, (a == b) is not always a boolean value, while (a is b) is always a boolean value. I *would* prefer that (a != b) raise an error when __ne__ isn't provided, but such is life until 3.0. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: anygui,anydb, any opinions?
Thomas Bartkus ha scritto: > The attractiveness of wxPython here is that it extends the platform > neutrality of Python to GUI interfaces. On a Windows platform, the work > looks like any other Windows program. On Gnome/Linux, the identical code > fits right into the Gnome desktop scheme. *Big* plus. Maybe I'm just nitpicking, but please! wxWidgets apps look ALMOST native on windows (combobox and similar widgets are emulated, and look really bad), and they sure _don't_ look like gnome apps on linux (gtk maybe, except for those custom widgets, but surely not gnome). Besides, wx generally catches the look, but almost never the 'feel'. wx is what you use if you really have no other choice, from my point of view... I'd honestly prefer to code a _good_ gui with gtk+glade and then bundle all the package together with py2exe and InnoSetup on windows. It will not look _native_, but it will look _GOOD_. Last time I looked wx did not have spacers (vbox, hbox and the like)... this leads to ugly non resizable vb-style guis, in my experience (just look at aMule... plain ugly). And that's not even starting to consider the version mess: try to install xCHM, Boa Constructor, aMule, VLC and some other app together... instant madness. > Yes. And I'm sorry to sound like I was complaining (but I was :-) > I'm here because MS is well along it's declining years and I've jumped off > the .NET bandwagon. New/wonderful things are no longer forthcoming from Then download gtk2.6 and glade for windows and then install pygtk and code away to your satisfaction! :-D -- Renato Usi Fedora? Fai un salto da noi: http://www.fedoraitalia.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Paul Rubin wrote: > No, it's a big pain. I'm a big boy and gave up on trying to install > wxpython for bittorrent on FC3 (the problem was with wxwidgets needing > an obsolete version of gtk, not with wxpython itself). There's just > no compelling reason to want to deal with this stuff. Tkinter has its > warts but it allows making functional gui's without all that much > fuss. If it were replaced in the default distro then I'd say use > whatever the new default is, but as it is, it's best to not impose > unnecessary extra headache on users. Fair enough. At the moment, the expected user base for the program is exactly one, but making it easy has its advantages. Since you've obviously used it yourself, if I end up going with tkinter, are there any performance gotchas on text rendering that I should be aware of? -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
I'm a Maths and Philosophy undergraduate first and foremost, with Computer Science as a tacked on third; I've studied a fair bit of logic both informally and formally, and am familiar with things such as the non-nessecity of the law of the excluded middle in an arbitrary propositional calculus farmework. I can now also see the usefulness of overriding != and == to do things other than simple equality comparison. Kay Schueler's Expr class seems like a particularily elegant and beautful example! (and seems to me a much better justification for rich comparisons than the rather mundane typying-reduction case of Numeric arrays) So I'm not arguing Python should demand != and not(a == b) return the same thing all the time (although I did question this in my original post). My argument is simply one of pragmatism - cases where this is not the case are the highly unusual ones, and so they should be the ones forced to write seperate __eq__ and __ne__ methods, In *every* example that's been rased so far - Floats, Numeric.array, Expr, (hypothetically) some unusual Symbolic Logic program without the law of excluded middle - these methods are both by nessecity independently defined, and my suggestion would not change the status quo at all. Mahesh raised the argument some posts back that Python should not 'just guess' what you want. But the problem is, it *already does* - it guesses you want object identity comparison if you haven't written __ne__. But if __ne__ is not provided, than the negation of a==b is *surely* a better guess for a != b than the negation of a is b As always, explicit is better than implicit. But if we're going to be implicit, lets be implicit in the way that makes the most sense. I can't stand Perl's autoconversion from strings to integers. But how much worse would it be if strings were auto-converted to, for example, the sum of the ordinal value of their ascii characters? OK, thats about as compelling as I can make the argument. If Perl bashing won't sway Python fans over, I don't know what will :) P.S. Excuse the excessive presence typos throughout all my posts, its been a long night. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Christopher Subich <[EMAIL PROTECTED]> writes: > > Use tkinter if you care about cross-platform operation. Everything > > else requires downloading and installing separate toolkits. > > Oh, the downloading and installing isn't a big deal. If in the > far-flung future anyone else uses this program, they'll be big boys > who can install things themselves. :) No, it's a big pain. I'm a big boy and gave up on trying to install wxpython for bittorrent on FC3 (the problem was with wxwidgets needing an obsolete version of gtk, not with wxpython itself). There's just no compelling reason to want to deal with this stuff. Tkinter has its warts but it allows making functional gui's without all that much fuss. If it were replaced in the default distro then I'd say use whatever the new default is, but as it is, it's best to not impose unnecessary extra headache on users. -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Peter Hansen wrote: > I can see only one comment that seems to describe that situation, where it refers to "IEEE 754 floating point numbers do not satisfy [== being the complement of !=]". > > (Though that may be justification enough for the feature...) To my naive eye, that possibility seems like justification for the language to not -enforce- that (not (a == b)) == (a != b), but for the vast majority of cases this is true. Perhaps the language should offer the sensible default of (!=) == (not ==) if one of them but not the other is overriden, but still allow overriding of both. This would technically break backwards compatibilty, because it changes default behavior, but I can't think of any good reason (from a python newbie perspective) for the current counterintuitive behavior to be the default. Possibly punt this to Python 3.0? -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Paul Rubin wrote: > Use tkinter if you care about cross-platform operation. Everything > else requires downloading and installing separate toolkits. Oh, the downloading and installing isn't a big deal. If in the far-flung future anyone else uses this program, they'll be big boys who can install things themselves. :) I'm just concerned about availability; the cross-platform operation for me would exclude things like direct Win32API calls, or direct linux-terminal calls (which apparently mcl uses to great effect). -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Andrew Dalke wrote: > Christopher Subich wrote: > >> My first requirement is raw speed; none of what I'm doing is processing-intensive, so Python itself shouldn't be a problem here. > > > > There's raw speed and then there's raw speed. Do you want to > display, say, a megacharacter/second? [snip] > Ahh, that's 400 bytes per second. That's pretty slow. Scrolling the text at any faster than a blur is counterproductive for the user, after all. You're off by a decimal, though, an 80-column line at 20ms is 4kbytes/sec. My guess is that any faster throughput than 10kbytes/sec is getting amusing for a mud, which in theory intends for most of this text to be read anyway. > > qtextedit has all of those. See > http://doc.trolltech.com/3.3/qtextedit.html That looks quite good, except that Trolltech doesn't yet have a GPL-qt for Win32. I might take another look at it whenever qt4 comes out, but in the meantime (since I'm unfortunately developing on a win2k system) it's not useful. > Depending on what you want, curses talking to a terminal might be > a great fit. That's how we did MUDs back in the old days. :) See the scrolling problem in the original post, as to why I can't use it as a temporary user interface. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: running distutils installer without admin on windows
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > I didn't build the installer, someone else did. I did get the source > and installed cygwin to see if I could recreate it; at least build the > library, but when I tried to do a build_ext I got a message saying I > needed to have the .NET SDK installed. You could at least open the installer exe in winzip or a similar tool, and unpack it manually to the site-packages directory. Thomas PS: I *think* that the distutils from newer Python versions (2.4.1 and 2.3.5) create installers that can also run without admin rights. -- http://mail.python.org/mailman/listinfo/python-list
Re: separate IE instances?
Here is quick and dirty example of what jc talked about. import win32api from win32com.client import Dispatch a = win32api.ShellExecute(0,None,"iexplore.exe",None,None,1) internetExplorerClassIdentity='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}' hwnds = Dispatch(internetExplorerClassIdentity) ieObj = hwnds[1] ieObj.Navigate("http://www.google.com/search?hl=en&lr=&q=python";) -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Matt Warden wrote: > Jordan, > > On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick > <[EMAIL PROTECTED]> wrote: > >>But I explicitly provided a method to test equality. And look at the >>plain english meaning of the term "Not equals" I think its pretty >>reasonable > > > Indeed. Furthermore, it seems quite silly that these would be different: > > a != b > not (a == b) It's only "silly" if one sticks to strict Boolean semantics or implicitly assumes the law of the excluded middle (http://en.wikipedia.org/wiki/Excluded_middle), the principle of bivalence (http://en.wikipedia.org/wiki/Principle_of_bivalence), or the law of noncontradiction (http://en.wikipedia.org/wiki/Law_of_non-contradiction). Despite "law" status, it is possible (and useful) to imagine situations where they don't hold. (A'la non-euclidlean geometry). The main problem is that Python is trying to stick at least three different concepts onto the same set of operators: equivalence (are these two objects the same?), ordering (in a sorted list, which comes first?), and mathematical "size". This gives the wacky world where "[(1,2), (3,4)].sort()" works, whereas "[1+2j, 3+4j].sort()" doesn't. Luckily another related concept, identity, has already been separated out (the 'is' operator). It would be nice (but I'm not hoding my breath) if the complete issue gets resolved with Python 3000. -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Jordan Rastrick wrote: > Just because a behaviour is documented, doesn't mean its not counter > intutitive, potentially confusing, and unnessecary. > > I have spent a fair amount of time reading the Python docs. I have not > yet memorised them. I may have read this particular section of the > reference manual, or I may have not, I can't remember. This is the > first time I've had cause to override the __eq__ operator, and so the > first time I've encountered the behaviour in a concrete setting, which > I feel is a far more effective way to learn than to read all the > documentation cover to cover. > > Where are the 'number of situations' where __ne__ cannot be derived > from __eq__? Is it just the floating point one? I must admit, I've > missed any others. For certain classes you can define behaviour like this: >>> x = Expr() >>> let(x+2 == 0) x+2==0 >>> solve(let(x+2==0)) x==-2 >>> x.val -2 My Expr class implements __eq__ and __ne__ in the following way: def __eq__(self,other): self._wrapPredicate("==",other) return self._iseq(other) def __ne__(self,other): self._wrapPredicate("!=",other) return not self._iseq(other) It would be hard to use operator overloading to create expressions if there are a lot of implicite assumptions. On the other hand I agree with you about the default behaviour of __ne__ and that it should be related locally to the class that overloads __eq__ and not to some global interpreter defined behaviour. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: __init__.py in packages
Gary Wilson Jr napisał(a): > What is intended use for __init__.py files? > Well, I found this: http://www.python.org/doc/essays/packages.html >>From what I can gather it is for initialization of the package when doing an > import, but I would really like to see an example or situation that makes good > use of the __init__.py file. > > Looking at the distutils __init__.py file, it only defines things like > __version__. However, looking at the logging __init__.py file, it is a > 1196-line monster with functions and classes defined throughout. > > What is the RightThing? I don't know The Right Thing, I just use __init__.py as namespace shortcut -- everything you define there (functions, classes, names), will be available at module level, not deeper. > Should I only define things in __init__.py that need to be defined when > importing a subpackage and/or module of package foo? > > Is it ok for me to define classes in foo/__init__.py? > Whereby I could do something like: > > from foo import MyClass > > Or is is better if I were to put these classes and/or functions in > foo/core.py? > Whereby I would do something like: > > from foo.core import MyClass It's mostly a matter of taste. And logic. -- Jarek Zgoda http://jpa.berlios.de/ | http://www.zgodowie.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: MoinMoin WikiName and python regexes
On Wed, 8 Jun 2005, Terry Reedy wrote: > > "Ara.T.Howard" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> i'm trying to fix a bug in MoinMoin whereby > > A 'bug' is a discrepancy between promise (specification) and perfomance > (implementation). Have you really found such -- does MoinMoin not follow > the Wiki standard -- or are you just trying to customize MoinMoin to your > different specification. well, according to the specification at http://moinmoin.wikiwikiweb.de/WikiName?highlight=%28wikiname%29 ThisIsAWikiName there seems to be general agreement here http://wikka.jsnx.com/WikiName http://twiki.org/cgi-bin/view/TWiki/WikiWord though not a wikis agree. in moinmoin others have noted the inconsistency and filed a bug as noted in http://moinmoin.wikiwikiweb.de/MoinMoinBugs/AllCapsInWikiName?highlight=%28wikiname%29 the problem being that the specification is simply vague here and does not specifically prohibit AWikiName. > >> WordsWithTwoCapsInARowLike >> ^^ >> do not become WikiNames. > > Would your proposed change to make the above into an Wiki name also make > all-cap sequences like NATO, FTP, and API into WikiNames it wouldn't since NATO !~ /^([A-Z]+[a-z]+){2,}$/ FTP !~ /^([A-Z]+[a-z]+){2,}$/ API !~ /^([A-Z]+[a-z]+){2,}$/ the pattern is word = one, or more, upper case letters followed by one, or more, lower case letters wikiword = at least two words together so FOobar is not a link but AFooBar is > If WikiNum, appearing one place, were also mistyped as WikeNUm (from holding > down the shift key too long, which I do occasionally), should the latter > become a separate WikiName? I can certainly understand why the Wike > designers might have answered both questions 'No." perhaps - it's just inconsistent the way it is now. cheers. -a -- === | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso === -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Well, I'll admit I haven't ever used the Numeric module, but since PEP207 was submitted and accepted, with Numeric as apparently one of its main motivations, I'm going to assume that the pros and cons for having == and ilk return things other than True or False have already been discussed at length and that argument settled. (I suppose theres a reason why Numeric arrays weren't just given the same behaviour as builtin lists, and then simple non-special named methods to do the 'rich' comparisons.) But again, it seems like a pretty rare and marginal use case, compared to simply wanting to see if some object a is equal to (in a non object identity sense) object b. The current situation seems to be essentially use __cmp__ for normal cases, and use the rich operations, __eq__, __gt__, __ne__, and rest, only in the rare cases. Also, if you define one of them, make sure you define all of them. Theres no room for the case of objects where the == and != operators should return a simple True or False, and are always each others complement, but <, >= and the rest give an error. I haven't written enough Python to know for sure, but based on my experience in other languages I'd guess this case is vastly more common than all others put together. I'd be prepared to bet that anyone defining just __eq__ on a class, but none of __cmp__, __ne__, __gt__ etc, wants a != b to return the negation of a.__eq__(b). It can't be any worse than the current case of having == work as the method __eq__ method describes but != work by object identity. So far, I stand by my suggested change. -- http://mail.python.org/mailman/listinfo/python-list
Re: different time tuple format
It is probably the best to calculate back to UTC. Assume "2005-06-07 15:07:12" the local time, then convert it as follows to UTC. Use the UTC time to store/manipulate/whatever you want to do. import time t = time.mktime(time.strptime("2005-06-07 15:07:12", "%Y-%m-%d %H:%M:%S")) print time.ctime(t) offset = time.timezone if time.daylight: offset = time.altzone t += offset print time.ctime(t) -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
"Jordan Rastrick" wrote: > I'd suggest the only nessecary change is, if objects a,b both define > __eq__ and not __ne__, then a != b should return not (a == b) > > If a class defines __ne__ but not __eq__, well that seems pretty > perverse to me. I don't especially care one way or another how thats > resolved to be honest. > > The ordering comparisons (__lt__, __ge__ etc) are fine as they are I'd > say, since they only come up in the rare cases where __cmp__ isn't > sufficient. > > I'll wait for a bit more discussion on here before starting a PEP - as > I've said I'm only a beginner, and a more experience Pyonista may yet > give a perfectly good argument in favour of the current behaviour. > I've been bitten by this particular wart more than once, so I wrote a metaclass for automating the addition of the missing rich comparisons with the expected semantics: == and != are complementary, and given either of them and one of <, >, <=, >=, the other three are defined. You can check it out at http://rafb.net/paste/results/ymLfVo81.html. Corrections and comments are welcome. Regards, George -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Christopher Subich <[EMAIL PROTECTED]> writes: > The third requirement is cross-platform-osity; if you won't hold it > against me I'll tell you that I'm developing under Cygwin in Win2k, > but I'd really like it if the app could run under 'nix and mac-osx > also. > > I'm pretty open to any graphical toolkit -- I have experience with > none of them, so I have little in the way of prejudice. Use tkinter if you care about cross-platform operation. Everything else requires downloading and installing separate toolkits. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast text display?
Christopher Subich wrote: > My first requirement is raw speed; none of what I'm doing is > processing-intensive, so Python itself shouldn't be a problem here. There's raw speed and then there's raw speed. Do you want to display, say, a megacharacter/second? > it's highly desirable to have very fast text updates (text > inserted only at the end)-- any slower than 20ms/line stretches > usability for fast-scrolling. Ahh, that's 400 bytes per second. That's pretty slow. > The second requirement is that it support text coloration. > The third requirement is cross-platform-osity qtextedit has all of those. See http://doc.trolltech.com/3.3/qtextedit.html Looks like LogText mode is exactly what you want http://doc.trolltech.com/3.3/qtextedit.html#logtextmode ] Setting the text format to LogText puts the widget in a special mode ] which is optimized for very large texts. Editing, word wrap, and rich ] text support are disabled in this mode (the widget is explicitly made ] read-only). This allows the text to be stored in a different, more ] memory efficient manner. and ] By using tags it is possible to change the color, bold, italic and ] underline settings for a piece of text. Depending on what you want, curses talking to a terminal might be a great fit. That's how we did MUDs back in the old days. :) Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Jordan Rastrick wrote: > Are there any other reasonable examples people can give where it makes > sense for != and == not to be each other's complement? __eq__ and __ne__ implement *rich* comparisons. They don't have to return only True or False. In [1]:import Numeric In [2]:a = Numeric.array([1, 2, 3, 4, 5]) In [3]:b = Numeric.array([1, 0, 4, 0, 5]) In [4]:a == b Out[4]:array([1, 0, 0, 0, 1],'b') In [5]:a != b Out[5]:array([0, 1, 1, 1, 0],'b') In [6]:(a != b) == (not (a == b)) Out[6]:array([1, 0, 0, 0, 1],'b') In [7]:not (a == b) Out[7]:False In [8]:not (a != b) Out[8]:False -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying behaviour of the != operator
Jordan, On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick <[EMAIL PROTECTED]> wrote: > But I explicitly provided a method to test equality. And look at the > plain english meaning of the term "Not equals" I think its pretty > reasonable Indeed. Furthermore, it seems quite silly that these would be different: a != b not (a == b) To be fair, though, other languages have peculiarities with equation. Consider this Java code: String s1 = "a"; String s2 = "a"; String s3 = new String("a"); String s4 = new String("a"); s1 == s2; // true s1.equals(s2); // true s1 == s3; // false s1.equals(s3); // true s3 == s4; // false s3.equals(s4); // true Doesn't make it any less silly, though. -- Matt Warden Miami University Oxford, OH, USA http://mattwarden.com This email proudly and graciously contributes to entropy. -- http://mail.python.org/mailman/listinfo/python-list