Re: I'm missing something here with range vs. xrange

2007-12-07 Thread Carl Banks
ate ten million integer objects dwarfs the time required to allocate a single list with ten million entries, and this cost occurs with both range and xrange, unless you break early. > Given the amount of performance difference, I don't see why > xrange even > exists. To keep memor

Re: Best way to protect my new commercial software.

2007-12-10 Thread Carl Banks
e OP was asked by a misguided management to make sure it was "reverse-engineer-proof". So any attempt to convince the OP may be aimed at the wrong person. Misguided as they are, sometimes you have to placate these people. So, are there any ways to make it "harder" to reverse engineer a

Re: Floating point subtraction rounding error (NOT display error)

2007-12-14 Thread Carl Banks
. If it's for school you're probably covered, but in real world, it would be better to: 1. Rewrite calculation to avoid arccos and arcsin (using trigonometric or geometric identities) 2. Clamp it to range [-1.0:1.0]. You can do this in numpy with numpy.clip(). Carl Banks -- http://m

Re: state machine and a global variable

2007-12-14 Thread Carl Banks
def set_state(): return my_machine.get_state() Some users won't want the simplified interface. Really. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: container.___le___ can use only <=?

2007-12-15 Thread Carl Banks
en both be > supplied by the contained objects. And yet, by the same reasoning, using > and <= for list and tuple is also a "bad idea". > If a LarchTree user stores objects that don't support __gt__, > will he have a legitimate complaint when using LarchTree.__le__

Re: Pythonic way to add method alias in subclass

2007-12-15 Thread Carl Banks
tly more self-documenting. And if you had been using super(), you could have avoided repeating the symbol Foo. But 2 is more efficient and less typing than 3. Option 4 is abhorrent. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: container.___le___ can use only <=?

2007-12-15 Thread Carl Banks
On Dec 15, 9:05 am, [EMAIL PROTECTED] wrote: > On Dec 15, 8:33 am, Carl Banks <[EMAIL PROTECTED]> wrote: > > > > > On Dec 14, 4:15 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > > When implementing the rich comparison operators for some sort of >

Re: New+old-style multiple inheritance

2007-12-18 Thread Carl Banks
plication to depend on their library? Sometimes you have to work with code that's not up to your standards, but come on. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: New+old-style multiple inheritance

2007-12-18 Thread Carl Banks
ng old and new style > classes. > > Monkey patching is definitely unpythonic. You must be a Ruby guy. Why > don't you try doing something else to get the behavior you want, > something more explicit? Time and place. A well-considered, timely monkey-patch can sometimes save all kinds of workarounds and other headaches. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: It's ok to __slots__ for what they were intended (was: Don't use __slots__ (was Re: Why custom objects take so much memory?))

2007-12-18 Thread Carl Banks
p anyone. The OP wanted to minimize memory usage, exactly the intended usage of slots. Without knowing more about the OP's situation, I don't think your or I or Chris Mellon can be sure it's not right for the OP's situation. You're obviously smart and highly expert i

Re: New+old-style multiple inheritance

2007-12-19 Thread Carl Banks
On Dec 19, 10:55 am, George Sakkis <[EMAIL PROTECTED]> wrote: > On Dec 18, 3:16 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > > > On Dec 18, 10:08 am, "[EMAIL PROTECTED]" > > > <[EMAIL PROTECTED]> wrote: > > > We are trying to monkey-patc

Re: In an inherited class, "embedded" classes is referenced?

2007-12-19 Thread Carl Banks
dict): for key,value in clsdict.iteritems(): if isinstance(value,type): clsdict[key] = type(value.__name__,(value,),{}) type.__new__(cls,name,bases,clsdict) class A(object): __metaclasS__ = AutoSubclassMetaclass class C(object): foobar = 40 class B(A): pass Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 359: The "make" Statement

2006-04-17 Thread Carl Banks
h to justify a new statement. Metaclasses aren't too common, and are generally used by experts who don't need the straightforwardness the make statement would provide. But, properties, dicts, and other things could benefit from some of the semantics the class statement, and with the make statem

Re: PEP 359: The "make" Statement

2006-04-17 Thread Carl Banks
Tim Hochberg wrote: > Carl Banks wrote: > > Mike Orr wrote: > > > >>>I think this PEP is going off the rails. It's primary virtue was that it > >> > >>was a simpler, clearer way to write: > >> > >> class Foo(args): > &g

Re: Method Call in Exception

2006-04-19 Thread Carl Banks
same exception; might have to disambiguate them somehow in the except block. Language-wise, I doubt there are any serious gotchas whem running regular (as opposed to error handling) code in an except block. So go right ahead; no need to feel guilty about it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Missing interfaces in Python...

2006-04-19 Thread Carl Banks
es be mature enough that writing interface definitions would be useful and not a burden. (And let's face it: there aren't many projects that get that far. :) Adaptation I have no comment about, not having needed it (yet). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Carl Banks
e not - or hardly - existed in programming > before python? Nesting by indentation Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: what has python added to programming languages? (lets be esoteric, shall we ; )

2006-04-21 Thread Carl Banks
Cameron Laird wrote: > In article <[EMAIL PROTECTED]>, > Carl Banks <[EMAIL PROTECTED]> wrote: > >Wildemar Wildenburger wrote: > >> Are there any concepts that python has not borrowed, concepts that were > >> not even inspired by other languages? I'

Re: OOP / language design question

2006-04-25 Thread Carl Banks
[EMAIL PROTECTED] wrote: > Heiko Wundram wrote: > > Because sometimes you don't want to call the base classes constructors? > Sounds strange to me at the moment, but I'll try to adjust to this > thought. In Java and C++, classes have private members that can only be accessed by the class itself (a

Re: OOP / language design question

2006-04-25 Thread Carl Banks
that I'd say that Python __init__ is analogous to Java and C++ constructors, but is not a constructor because C++ and Java constructors are not constructors. :) And Java has pointers, not references. :) A-rose-by-any-other-name-ly yr's, Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: OOP / language design question

2006-04-25 Thread Carl Banks
Duncan Booth wrote: > In other words, the object is constructed in Python before any __init__ is > called, but in C++ it isn't constructed until after all the base class > constructors have returned. That's true. Good point. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: OOP / language design question

2006-04-26 Thread Carl Banks
t yet been > set up. In Python, if you try to use an uninitialized member you get an AttributeError; I really don't see too much inherent danger here. If you make a mistake, the language tells you and you fix it. C++ and Java are worse since accessing uninitialized variables is a silen

Re: A defense for bracket-less code

2006-04-26 Thread Carl Banks
ine if can't be > followed by an else. Thus proving the original claim about it being confusing. :) I think he intended it to parse this way: if ($x) { $y++ if $z; } else { $z--; } Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: OOP / language design question

2006-04-27 Thread Carl Banks
Lawrence D'Oliveiro wrote: > In article <[EMAIL PROTECTED]>, > "Carl Banks" <[EMAIL PROTECTED]> wrote: > > >bruno at modulix wrote: > >> [EMAIL PROTECTED] wrote: > >> > I was wondering, why you always have to remember to call bas

Re: unable to resize mmap object

2006-05-02 Thread Carl Banks
It would accept a filename rather than a file descriptor, anonymous blocks would be handled OS-independently, rather than mapping /dev/zero, and so on.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuple assignment and generators?

2006-05-04 Thread Carl Banks
q = 0 >>> r = 0 >>> s = 0 >>> id(q) 134536636 >>> id(r) 134536636 >>> id(s) 134536636 [snip] > My rule, don't do it unless you know exactly why you > want to do it. It will trip you up at some point and > be VERY hard to find. It's ok to do it with constant objects, really. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuple assignment and generators?

2006-05-05 Thread Carl Banks
e? If yes, then use ==. 0 == 0 should be true even if the two zeros are different objects. Corrollary: You should test for singleton objects with is. None, NotImplemented, and Ellipsis are singleton objects; this is part of the language and not an implementation detail. You can rely on

Re: Multi-line lambda proposal.

2006-05-09 Thread Carl Banks
ultiple times in the same statement. Try showing what they look like nested. The "readable" example would turn into ASCII vomit. Probably the day it makes it into Python is the day Python jumps the shark. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Can Python installation be as clean as PHP?

2006-05-09 Thread Carl Banks
gle-file executables. PyInstaller works on Unix too, IIRC. If you're good at tweaking stuff and have some knowledge of Python internals; it's possible to make a minimal distro just by copying files out of a regular installation by hand (and maybe zipping some them up). This can be a

Re: Can Python installation be as clean as PHP?

2006-05-09 Thread Carl Banks
G. Monzón wrote: > Please don't compare PHP with Python... They are very different worlds. I'm not. I was simply agreeing that the single executable way the OP claimed PHP does it can *sometimes* be preferrable in Python, and giving him recommendations thereto. Carl Ba

Re: New tail recursion decorator

2006-05-10 Thread Carl Banks
n func(*args,**kwd) > return iterfunc CONTINUE could be put inside tail_recursive, couldn't it? And to squeeze a little more speed out of it, var could be a list (saves a hash lookup). Cool decorator. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Time to bundle PythonWin

2006-05-11 Thread Carl Banks
ction for SGI IRIX modules, and IRIX support is scheduled to be dropped in Python 3000. There might be a good reason why win32 isn't in Python base distro, but that it's Windows-only isn't it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: distributing a app frozen by cx_freeze

2006-05-12 Thread Carl Banks
shared library (if the license allows it, of course), or rebuild the qt.so with the static QT libraries. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: distributing a app frozen by cx_freeze

2006-05-13 Thread Carl Banks
u're doing this on Linux, it's not all that unreasonable to require QT to be installed on the target system. Any reasonable distribution has it nicely packaged. But, if you must, "ldd qt.so" will list library dependencies of qt.so. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Script to make Windows XP-readable ZIP file

2006-05-18 Thread Carl Banks
gt; Position the CWD in the desired base directory of > the archive, > add the files to the archive using their relative pathnames, and put > the CWD back > where it was when you started: This may be the best way anyways, unless you have some reason to not change the current directory. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3102 for review and comment

2006-05-20 Thread Carl Banks
modifier (like Ada's "in and out") instead? Problem with that is then positional arguments line up wrong. Ick. def func(a : int = 1): pass def func(a : kwonly int = 1): pass Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Exception style (was: calling python functions using variables)

2006-05-20 Thread Carl Banks
alling it and catch CallableError (or whatever it is). Of course, that error can be raised inside the function; and in this case, there's no way to isolate only the part you you're checking for an exception. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Exception style (was: calling python functions using variables)

2006-05-20 Thread Carl Banks
hecking is appropriate to it -- and if needed, raise > some custom "command failure" exception after handling the real failure > internally. That probably doesn't help when the exception is due to a bug and not bad input. If you have an AttributeError due to a bug, it w

Re: noob import question

2006-05-20 Thread Carl Banks
. So queuing instead of Queue. Unfortunately, the Python library isn't setting a good example here. Too much glob.glob, time.time, socket.socket, and Queue.Queue. I hope all these go away in Python 3000. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Carl Banks
tianly negative) pronouncement, so we have it on the record. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread Carl Banks
in y: if x is not None: _.append(x) In other words, each for and if in a listcomp is equivalent to a nested block in a regular statement. There's a regular way to nest, and listcomp way, and they're separate. This PEP suggests we should mix them up--now *that'

Re: list in a tuple

2007-12-27 Thread Carl Banks
nnoys quite a few people. When you reply to a message, please move your cursor to below the quoted message before you begin typing. Thank you Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Cheat sheet

2007-12-27 Thread Carl Banks
ne or two about the set objects. (It's probably at least better than listing internal objects.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: os.system question

2007-12-28 Thread Carl Banks
which seems to be what you need. In IDLE, you'll have to capture the output of the programs and print it yourself, since you can't (AFAIK) run a DOS shell in an IDLE window. Untested: import subprocess output = subprocess.Popen('MD "' + new_folder + '"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0] print output Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Carl Banks
: for i in xrange(len(x)-1): j = random.randrange(i+1,len(x)) tmp = x[j] if test_property_func(tmp): return tmp x[j] = x[i] x[i] = tmp return None Then, for example, use it like this: def odd(i): return i&1 e = random_element_with_proper

Re: list property fires get on append

2008-01-06 Thread Carl Banks
hildren to be an instance attribute rather than a class attribute, so I redid it that way, but .) P.S. Is calling a method called "firing" in C#? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: python interfaces

2008-01-06 Thread Carl Banks
en than a benefit, especially in code that is young and still subject to lots of redesign and refactoring. And ehen interfaces do make sense, such as in a plugin system or a complex framework, the user should be free to ignore the interface at his own risk. Carl Banks -- http://mail.python.or

Re: Python's great, in a word

2008-01-07 Thread Carl Banks
7;ve done enough to choose. "it doesn't suck". (Really. All programming languages have good, useful features. Even Perl. Python is unique in having no very bad ones.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's great, in a word

2008-01-08 Thread Carl Banks
quot;its pythonicity". Mixing Greek and Latin suffixes usually works better than mixing Greek and Germanic, doesn't it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: for loop without variable

2008-01-09 Thread Carl Banks
intrc file (location may vary on Windows) and there was a declaration in the file that listed symbols to ignore. Last time I bothered running it, I added "id" to that list, since I use it often (bad habit) and almost never use the builtin id, but still wanted shadowing warnings for othe

Re: Pygame w/ GUI

2008-01-09 Thread Carl Banks
the event loop, same as most GUIs do. Plus it's not straightforward to integrate the SDL window into the widget systems. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: for loop without variable

2008-01-10 Thread Carl Banks
repeat" as the keyword.) 1. Looping a fixed number of times is quite uncommon. 2. A syntax for it buys you almost nothing. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Magic function

2008-01-11 Thread Carl Banks
Obj(*args) self.tracked_objs.add(obj) return obj def run(self): for obj in self.tracked_objs: # do something with obj bigobj = Bigobj() obj1 = bigobj.create_object(params1) obj2 = bigobj.create_object(params2) # maybe do something with obj1 and obj2 here bigobj.run() Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: where do my python files go in linux?

2008-01-12 Thread Carl Banks
I recommend putting *.py files there as well, so users can refer to it if there are any problems, but you don't have to. The Python module compileall is your friend here. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: where do my python files go in linux?

2008-01-12 Thread Carl Banks
hatever to their path path and use it that way. I realize it's a fine line and a judgment call in some cases, but site- packages is really for libraries; applications should use their own directories. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Carl Banks
ighted that str.rstrip() > removed the trailing-padding-for-nicer-layout no-break spaces that the > users had copy/pasted from some clown's website :-) > > What was the *real* cause of your irritation? If you want to use str.split() to split words, you will foil the user who wants to not break at a certain point. Your use of rstrip() is a lot more specialized, if you ask me. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: SyntaxError: 'import *' not allowed with 'from .'

2008-01-14 Thread Carl Banks
recursion. Or, perhaps something more subtle than infinite recursion, such as hard-to-comprehend rules about what modules and subpackages would be imported. So they just decided to disallow it. Just a guess. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: module naming conventions

2008-01-14 Thread Carl Banks
? Is there a best practices guide for module > naming? Not really. Try to pick a unique name for your project. <:\ Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: TopSort in Python?

2008-01-18 Thread Carl Banks
dia article, which led me to the topsort algorithm. I did a dance of joy. Ten minutes later I saw it mentioned it on comp.lang.python. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Using "pickle" for interprocess communication - some notes and things that ought to be documented.

2008-01-18 Thread Carl Banks
ng "univeral newlines" in a non-text format seems like it's not a good idea. For text-format pickles it'd be the right thing, of course. > Incidentally, in the subprocess, it's useful to do > > sys.stdout = sys.stderr > > after setting up the Pick

Re: I don't understand what is happening in this threading code

2008-01-18 Thread Carl Banks
quot; > % id(w.should_keep_running)) > > if __name__ == "__main__": > main() It looks like your program's hanging while the waiter is waits to acquire another plate of hot food. Quick and dirty solution is to have waiter timeout at intervals while waiting for the chef and check the clock to see if his shift has ended. Better solution is to rewrite the logic, which you did. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Module/package hierarchy and its separation from file structure

2008-01-24 Thread Carl Banks
f itself). You can reassign the class's module: from org.lib.animal.monkey import Monkey Monkey.__module__ = 'org.lib.animal' (Which, I must admit, is not a bad idea in some cases.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: translating Python to Assembler

2008-01-24 Thread Carl Banks
On Jan 24, 10:14 am, Bjoern Schliessmann wrote: > Tim Roberts wrote: > > Grant is quite correct; Python scripts (in the canonical CPython) > > are NOT compiled into assembly language. Scripts are compiled to > > an intermediate language. Processors execute Python scripts when > > the interpreter

Re: Module/package hierarchy and its separation from file structure

2008-01-25 Thread Carl Banks
t least for classes, without softening the one-to-one module-to-file relationship, or using "hacks". In fact, I'd say this is good practice. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Generational Interfaces

2008-01-25 Thread Carl Banks
s when it's not there. Make sense? Details can vary, but that's the basic idea. In this way, you can combine some of the openness that helps in early development, but also have some of the benefits of stricter typing when things mature and turn out to be pretty strictly useful, withou

Re: Generational Interfaces

2008-01-25 Thread Carl Banks
On Jan 26, 12:32 am, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > Carl Banks <[EMAIL PROTECTED]> writes: > > AirplaneInterface = InterfaceTracker("Airplane") > > ... > > set_up_initial_state() > > ... > > Airplane

Re: Generational Interfaces

2008-01-26 Thread Carl Banks
appropriate for that particular use. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Module/package hierarchy and its separation from file structure

2008-01-29 Thread Carl Banks
ISTM you came here looking for a particular means and not a particular end. Python already has the power to meet your stated needs, but you won't use that solution because it's "hacky". Apparently all you really wanted was the loosened file structure in the first place. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Module/package hierarchy and its separation from file structure

2008-01-30 Thread Carl Banks
quot;unintended consequences", by a very large margin. Python has always been one-to-one module-to-file (excepting modules built into the interpretter), and many codes and tools have come to depend on it. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Naive idiom questions

2008-01-31 Thread Carl Banks
effect other than by writing separate, independent > manpages? Not a big expert on docstrings (they seem so superfluous...) but perhaps there are third-party packages that let you specify meta- documentation with function decorators. For example: @overview("Blah blah blah") @authors("So and so") def some_function(): pass Try looking on PyPI (cheeseshop.python.org). Python's in-code documentation is pretty basic; I think Python is happy to outsource more elaborate schemes to third party packages. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: very simple Genetic Algorithm completed

2008-02-01 Thread Carl Banks
on, to get a random index in a range. Perhaps even better still, use random.choice. It gets a random element in a sequence. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Linux Journal Survey

2008-02-02 Thread Carl Banks
-readable form. It is appropriate to call > such a program a script. If the first two characters is "#!" > and the execution bit is set, it is a script in the linux sense. > > So as far as I can tell it boils down to a clear technical > distinction, and I'm sure they didn't mean offence. Java doesn't compile to ELF binaries, last time I checked. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected timing results with file I/O

2008-02-04 Thread Carl Banks
xplain why the code which does more work > > takes less time? > > > -- > > Steven > > The code that does more work takes more time. The second one does > quite a bit less work. Think of it like this: > > You have 500,000 people to fit through a door. He

Re: Why does list have no 'get' method?

2008-02-07 Thread Carl Banks
ly the true/false test only works for certain set of expected values that I have in my mind. When the acceptable values are generalized, when you want to expand this function's role, does the true/false test still work? I find it rarely does. The Python treatment of booleans is, by far, my biggest gripe with Python. (Which, you know, is a pretty good thing to have as a biggest gripe.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does list have no 'get' method?

2008-02-08 Thread Carl Banks
tainly it wouldn't be possible if Python treated bools according to my preference. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: sort functions in python

2008-02-08 Thread Carl Banks
od choice. But if you're at that stage you probably were doing something wrong in the first place. For a list of any decent size a few insertions using a bisection algorithm will take fewer comparisons than a single bubblesort pass. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: sort functions in python

2008-02-09 Thread Carl Banks
On Feb 9, 4:37 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > On Feb 8, 10:09 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > >> If you expect your data to be pretty nearly sorted > >> already, but you just want to make sure (e.g. because a

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Carl Banks
with divide by zero? I understand your pain, but Python, like any good general-purpose language, is a compromise. For the vast majority of programming, division by zero is a mistake and not merely a degenerate case, so Python decided to treat it like one. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Turn off ZeroDivisionError?

2008-02-10 Thread Carl Banks
broken in the special > case of division by zero. Do you recall what the very next Zen after "Special cases aren't special enough to break the rules" is? that's-why-they-call-it-Zen-ly yr's, Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Better way to do this?

2008-02-11 Thread Carl Banks
%s not found" % value) As an added bonus, you get a more useful error message if it's not there (I know what you said, but bugs happen). If it's too bulky for you, put it into its own function and call it. > Can't You first convert the tuple of tuples in a dict, and the

Re: Encrypting a short string?

2008-02-11 Thread Carl Banks
om a particular user? > > > Regards, > > Marek > > In essence what I'm doing is trying to manage tickets for a helpdesk. > I want the ticket identifier to be short enough to fit in the subject > line along with the normal subject chosen by the user. So > cryptograp

Re: mmap and shared memory

2008-02-11 Thread Carl Banks
p the OS could still write that memory to swap space, which, if your swap space is fixed and limited, might negatively affect performance for the rest of the system. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: dream hardware

2008-02-12 Thread Carl Banks
On Feb 12, 1:05 pm, [EMAIL PROTECTED] wrote: > What is dream hardware for the Python interpreter? A 10 GHz single core. (Dual core if doing lots of I/O.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: InstanceType tests in Python-3.0

2008-02-14 Thread Carl Banks
lass(cls): try: modname = cls.__module__ except AttributeError: return False try: mod = sys.modules[modname] except KeyError: return False try: filename = mod.__file__ except AttributeError: return False return filename.endswith('.pyc') Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: RELEASED Python 2.5.2, release candidate 1

2008-02-14 Thread Carl Banks
t I did - I made the release > candidate available to the public. > > So is the subject incorrect as well? If so, what should it say? I think it's fine as it is. You can "release" a release candidate. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Turn off ZeroDivisionError?

2008-02-15 Thread Carl Banks
eed to do some preliminary calculations in Python (where there's no edit/compile/run cycle but there is slicing and array ops), but want the same floating point behavior. IEEE conformance is not an unreasonable thing to ask for, and "you should be using something else" isn't a good answer to "why not?". Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: QOTW: Re: dream hardware

2008-02-16 Thread Carl Banks
garlic, that suddenly turns into > >>>>> Sylvester Stallone in a tutu just before my program returns its result. > >>>> IHNTA, IJWTSA > >>> IJWTW? Anyone set up to profile CPython?... or step through? > >> I give up. Is there a

Re: How about adding rational fraction to Python?

2008-02-16 Thread Carl Banks
occasional special purpose uses, but for most cases they're at best marginally better then floats and more often incomparably worse. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-16 Thread Carl Banks
On Feb 16, 5:51 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > On Feb 16, 3:03 pm, Lie <[EMAIL PROTECTED]> wrote: > >> Although rationals have its limitations too, it is a much > >> better choice compared to floats/Decimals for most case

Re: How about adding rational fraction to Python?

2008-02-16 Thread Carl Banks
On Feb 16, 5:51 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > On Feb 16, 3:03 pm, Lie <[EMAIL PROTECTED]> wrote: > >> Although rationals have its limitations too, it is a much > >> better choice compared to floats/Decimals for most case

Re: How about adding rational fraction to Python?

2008-02-16 Thread Carl Banks
On Feb 16, 7:54 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > On Feb 16, 5:51 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > >> Carl Banks wrote: > >>> On Feb 16, 3:03 pm, Lie <[EMAIL PROTECTED]> wrote: > >>>

Re: How about adding rational fraction to Python?

2008-02-17 Thread Carl Banks
nd subtraction would only grow the denominator up to > a certain limit I said repeated additions and divisions. Anyways, addition and subtraction can increase the denominator a lot if for some reason you are inputing numbers with many different denominators. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Article of interest: Python pros/cons for the enterprise

2008-02-20 Thread Carl Banks
type-checked language, which means it is totally safer for newbies than Python. Yep, your big company is totally safe with newbie C++ programmers. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: is this data structure build-in or I'll have to write my own class?

2008-02-20 Thread Carl Banks
in __dict__, is this the only > way of doing it? OrderedDict is usually the term used here for this (not to be confused with SortedDict, which is a mapping type with identically sorted keys). It's asked for pretty often but no one's stepped up to implement one for the standard library. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Article of interest: Python pros/cons for the enterprise

2008-02-21 Thread Carl Banks
a downside: it's at least a wash. In C++ you manage memory and the language manages resources. In Python you manage resources and the language manages memory. RAII is merely one way of minimizing complexity. Garbage collection is another way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Article of interest: Python pros/cons for the enterprise

2008-02-21 Thread Carl Banks
On Feb 21, 7:17 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > On Feb 21, 1:22 pm, Nicola Musatti <[EMAIL PROTECTED]> wrote: > >> There are other downsides to garbage collection, as the fact that it > >> makes it harder t

Re: Article of interest: Python pros/cons for the enterprise

2008-02-21 Thread Carl Banks
all I was really saying is that there are far more more important things when it comes to "safety" than dynamic typing. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Article of interest: Python pros/cons for the enterprise

2008-02-21 Thread Carl Banks
On Feb 22, 12:23 am, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > On Feb 21, 7:17 pm, Jeff Schwab <[EMAIL PROTECTED]> wrote: > >> Carl Banks wrote: > >>> On Feb 21, 1:22 pm, Nicola Musatti <[EMAIL PROTECTED]> wrote: > >>&

Re: Return value of an assignment statement?

2008-02-22 Thread Carl Banks
if m where m = re.match(r"name=(.*)",line): name = m.group(1).strip() elif m where m = re.match(r"id=(.*)",line): id = m.group(1).strip() elif m where m = re.match(r"phone=(.*)",line): phone = m.group(1).strip() This won't happen because the set-a

Re: Return value of an assignment statement?

2008-02-22 Thread Carl Banks
e(m): phone = m.group(1).strip() This decorator might be more to the point: def call_if_match(regexp): m = re.match(regexp) if m: return lambda func: func(m) return lambda func: None These have the drawback of being a little dense, and the functions can't rebind v

<    1   2   3   4   5   6   7   8   9   10   >