Python 2.4c1 vs. 2.4

2004-11-30 Thread Russ
My sysadmin recently installed 2.4c1 on our network. Should we now install 2.4, or is it the same as 2.4c1? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

parameter files

2006-09-13 Thread Russ
I have a python module (file) that has a set of parameters associated with it. Let's say the module is called "code.py." I would like to keep the parameter assignments in a separate file so that I can save a copy for each "run" without having to save the entire code.py file. Let's say the parameter

Re: parameter files

2006-09-13 Thread Russ
> I would try a configuration file, instead of a python module. > See ConfigParser: > . > You can save values for each "run" in a separate [section]. > Execfile is a pretty big hammer for this. Hey, that looks interesting, but those docs don't

Re: parameter files

2006-09-14 Thread Russ
parameters were used to get particular results. I don't need a section for each run. I only need one set of parameters. I suppose I could use the sections for different modules or classes, each of which needs its own parameters. Gabriel Genellina wrote: > At Thursday 14/9/2006 01:10, Russ

Why not just show the out-of-range index?

2006-12-03 Thread Russ
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the offending index are. Why does it force you to determine that information for yourself when it could save you a

Re: Why not just show the out-of-range index?

2006-12-03 Thread Russ
> Rather, they (like I) will encourage to OP to submit a patch that fixes the > problem. Now, that would be rather silly. I would have to familiarize myself with the code for the Python interpreter, then send a patch to the maintainers (and hope they notice it in their inboxes), while the mainta

Re: Why not just show the out-of-range index?

2006-12-03 Thread Russ
Jean-Paul Calderone wrote: > And I have some laundry that I would like you to do for me. Let me know > when a convenient time for you to pick it up would be. What that has to do with this thread escapes me, but since you apparently have nothing better to do than track down information that shoul

Re: Why not just show the out-of-range index?

2006-12-03 Thread Russ
John Machin wrote: > Perhaps a better analogy is that the OP has observed (correctly IMHO) > that the robes of *all* Pythonistas, including those not yet born and > those not yet converted from heathen languages, could be whiter than > what they are. There are others whose capability to implement

Re: Why not just show the out-of-range index?

2006-12-03 Thread Russ
Dennis Lee Bieber wrote: > OTOH: IndexError is something I seldom see -- most Python statements > are intelligent enough to not need ad hoc indexing. About the only type > that I've seen is just an, almost obvious, off-by-one problem... > > for i in xrange(len(a)): > a[i

Re: Why not just show the out-of-range index?

2006-12-03 Thread Russ
Fredrik Lundh wrote: > Russ wrote: > > > Holy cow! I can't believe that many changes would be necessary unless > > the IndexError exception is scattered all over the place. I would hope > > that one well-placed change could fix the bulk of cases. > > when you w

Re: Why not just show the out-of-range index?

2006-12-03 Thread Russ
Robert Kern wrote: > No one is castigating the OP for bringing up the issue. His suggestion that > his > time is worth more than that of anyone else, though, is drawing some ire. I'm afraid that any such "suggestion" is purely in your own imagination. My time? Do you think I am the only one who

Re: Why not just show the out-of-range index?

2006-12-04 Thread Russ
Fredrik Lundh wrote: > Russ wrote: > > >> No one is castigating the OP for bringing up the issue. His suggestion > >> that his > >> time is worth more than that of anyone else, though, is drawing some ire. > > > > I'm afraid that any such

Re: Why not just show the out-of-range index?

2006-12-04 Thread Russ
Robert Kern wrote: > Nothing is going to happen until you do one of these two things. Being more > rude > (and yes, you are being incredibly rude and insulting) won't move things > along. I re-read the thread, and I don't see anywhere where I was rude except in reply to rudeness by others. Sorr

Re: Why not just show the out-of-range index?

2006-12-04 Thread Russ
Carsten Haese wrote: > You may not have meant this to be rude, but it does come off as rude and > arrogant, and I'll explain to you why: In your first post you stated > that the feature seems like a no-brainer to you. That implies to the > reader that you might have the necessary skill to impleme

Re: Why not just show the out-of-range index?

2006-12-04 Thread Russ
Fredrik Lundh wrote: > > Sorry I haven't thought this through 100% > > obviously not. And you didn't like the "tone" of some of my earlier posts? -- http://mail.python.org/mailman/listinfo/python-list

Re: Why not just show the out-of-range index?

2006-12-04 Thread Russ
Fredrik Lundh wrote: > you're forgetting that you're dealing with "squeaky wheel contributors" > here, not the kind of nice and helpful persons that actually make open > source work. Please refrain from dishing out gratutious insults until you have a clue what you are talking about. It just so ha

Re: Why not just show the out-of-range index?

2006-12-04 Thread Russ
Folks, I'm truly sorry that so many feathers got ruffled in this thread. Let's see if I can put this thing to rest gracefully. Russ wrote: > My suggestion is trivial to implement and would benefit every Python > programmer (even if only slightly), so I don't think it is

Re: Why not just show the out-of-range index?

2006-12-05 Thread Russ
stdazi wrote: > Usually, when I make some coding mistake (index out of range - in this > case) I just care to fix the mistake and I usually don't mind to > inspect by how much the index was overflowed. It really seems like a > feature that should be embedded in some Python debugger than a feature >

Re: Why not just show the out-of-range index?

2006-12-07 Thread Russ
> - because error messages are not debugging tools (better use unit Then what are they? Machine-generated poetry? -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic debugging of copy by reference errors?

2006-12-11 Thread Russ
greg wrote: > You need to stop using the term "copy by reference", > because it's meaningless. Just remember that assignment I agree that "copy by reference" is a bad choice of words. I meant pass by reference and assign by reference. But the effect is to make a virtual copy, so although the phr

representing physical units

2006-02-09 Thread Russ
I know that python packages are available for representing physical units, but I am getting frustrated trying to find them and determine which is the best. Rather than just using conventional dimensionless numbers with implicit units, I would like to have a way to explicitly represent the units. I

aborting without killing the python interpreter

2006-02-18 Thread Russ
I wrote a simple little function for exiting with an error message: def error ( message ): print_stack(); exit ("\nERROR: " + message + "\n") It works fine for executing as a script, but when I run it interactively in the python interpreter it kills the interpreter. That's not what I want. Is the

deriving from float or int

2006-02-20 Thread Russ
Does it ever make sense to derive a class from a basic type such as float or int? Suppose, for example, that I want to create a class for physical scalars with units. I thought about deriving from float, then adding the units. I played around with it a bit, but it doesn't seem to work very well. Am

Re: deriving from float or int

2006-02-21 Thread Russ
The problem is that when I derive a new class from float, the darn thing won't let me create a constructor that accepts more than one argument. I need two arguments: one for the numerical value and one for the units. But when I try to give the constructor two arguments, I get this when I call the c

"configuring" a class

2006-02-22 Thread Russ
I would like to let the user of one of my classes "configure" it by activating or de-activating a particular behavior (for all instances of the class). One way to do this, I figured, is to have a static class variable, along with a method to set the variable. However, I am stumped as to how to do

compiling python and calling it from C/C++

2007-06-07 Thread Russ
Is it possible to compile python code into a library (on unix), then link to it and call it from C/C++? If so, where can I learn how. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: compiling python and calling it from C/C++

2007-06-08 Thread Russ
Diez B. Roggisch wrote: > Russ schrieb: > > Is it possible to compile python code into a library (on unix), then > > link to it and call it from C/C++? If so, where can I learn how. > > You can't compile python, but what you can do is create a > library-wrapping aro

type conversions for comparison operators

2007-07-18 Thread Russ
I recently discovered a bug in one of my programs that surprised me because I thought Python's dynamic type checking would have caught it. Suppose I have a function that returns an integer, such as def numItems: return len(self.items) Now I want to do a test like this: if object.numItems() > 2:

automatic type conversion for comparison operators

2007-07-26 Thread Russ
I posted a message on this several days ago, but it apparently got lost in googlespace, so I'll try it again. I recently discovered a bug in my code that apparently resulted from the automatic conversion of a function pointer to an integer. Say you have a class member function called getCount(),

Re: automatic type conversion for comparison operators

2007-07-26 Thread Russ
Dan Bishop wrote: > BTW, are you a former Pascal programmer? No. Why do you ask? [The code snippet I wrote was made up to get a point across. I did not actually use that function name in my code.] > > But Python > > somehow compares the function pointer with an integer without > > complaining.

status of Programming by Contract (PEP 316)?

2007-08-28 Thread Russ
I just stumbled onto PEP 316: Programming by Contract for Python (http://www.python.org/dev/peps/pep-0316/). This would be a great addition to Python, but I see that it was submitted way back in 2003, and its status is "deferred." I did a quick search on comp.lang.python, but I don't seem to see mu

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Russ
On Aug 28, 9:35 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: > Russ wrote: > > I just stumbled onto PEP 316: Programming by Contract for Python > > (http://www.python.org/dev/peps/pep-0316/). This would be a great > > addition to Python, but I see that it was submitte

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Russ
On Aug 28, 10:58 pm, Michele Simionato <[EMAIL PROTECTED]> wrote: > Why do you think that would ad a strong positive capability? > To me at least it seems a big fat lot of over-engineering, not > needed in 99% of programs. In the remaining 1%, it would still not > be needed since Python provides o

Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Russ
> But it's always a good idea to make your software "correct and as > reliable as possible", isn't it? The problem is the external constraints > on the project. As the old saying goes: "Cheap, fast, reliable: choose > any two". If you are suggesting that "programming by contract" is not appropria

Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Russ
> I disagree. IMO automatic testing is thousands of times better than > design by contract and Python has already all the support you need > (unittest, doctest, py.test, nose, ...) In theory, anything you can verify with "design by contract" you can also verify with unittest and the rest. However

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> PEP 316 introduces new syntax for a limited use feature. That's pretty > much a no-starter, in my opinion, and past experience tends to bear > that out. Furthermore, it predates decorators and context managers, > which give all the syntax support you need and let you move the actual > DBC featu

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> Things get vetted *before* they get added to the core, not after. I realize that. I meant that it would get vetted in the process of putting it into the core. That would provide more confidence that it was done the best possible way -- or close to it. -- http://mail.python.org/mailman/listinf

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
Bruno Desthuilliers wrote: > Russ a écrit : > (snip) > > > I don't see how you can avoid adding some new syntax, given that > > Python does not > > currently have syntax for specifying invariants and pre- and post- > > conditions. > > class Parrot(objec

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
Bruno Desthuilliers wrote: > Russ a écrit : > > On Aug 28, 10:58 pm, Michele Simionato <[EMAIL PROTECTED]> > > wrote: > > > > > >>Why do you think that would ad a strong positive capability? > >>To me at least it seems a big fat lot of over-eng

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> > That looks like new syntax to me. > > It's the syntax for decorator functions, and it's not that new - it > cames with Python 2.4, released November 30, 2004. After looking more carefully at your example, I don't think it is as clean and logical as the PEP 316 syntax. At first I thought that

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
Ryan Ginstrom wrote: > I tried using DBC for a time in C++ (using a library with a clever > assembly-language hack). I personally found it neater having such code in > unit tests, but obviously, it's a matter of preference. I agree that it ultimately boils down to preference, but as I tried to e

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> Pre and post conditions applying to the class ? Now that's an > interesting concept. IIRC, Eiffels pre and post conditions only apply to > methods, and I fail to see how they could apply to a class. But since > you're an expert on the subject, I don't doubt you'll enlighten us ? I made a simple

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> FWIW, the "Eiffel and SPARK Ada folks" also "brilliantly explained" why > one can not hope to "write reliable programs" without strict static > declarative type-checking. And they are probably right. I don't think you understand what they mean by "reliable programs." Any idea how much Python i

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
Paul Rubin wrote: > Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > > FWIW, the "Eiffel and SPARK Ada folks" also "brilliantly explained" > > why one can not hope to "write reliable programs" without strict > > static declarative type-checking. > > I don't know about Eiffel but at least an impor

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> I've always wondered... Are the compilers (or interpreters), which take > these programs to machine code, also formally proven correct? No, they are not formally proven correct (too complicated for that), but I believe they are certified to a higher level than your "typical" compiler. I think t

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> I guess one difference from unit test philosophy is > that at least > sometime, you'd run the entire application with all > the dbc checks > enabled, and just live with the slowdown. Yes, that's right. You don't expect to run efficiently with the self- test checks activated, but you can test yo

Re: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Russ
> Python really isn't suitable for in-flight controls > for various > reasons, and mission critical concerns is a minor one (systems with Do you know anything about the FAA certification process for flight- critical systems? I am not an expert on it, but I know it is very expensive. If I am not m

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
On Aug 30, 7:20 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Russ <[EMAIL PROTECTED]> wrote: > >... > > > programs." Any idea how much Python is used for flight control systems > > in commercial > > transport aircraft or jet fighters? Hi Alex.

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
Michele Simionato wrote: > I am curious. Why do you think I attacked you? The conversion went as > follows: I don't think you attacked me. I was referring to another person, who apparently came to your defense and *did* attack me. For the record, I apologize for saying that you don't seem to kn

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
Steve Holden wrote: > Frankly I am getting a little tired of they way you are unable to even > recognize that your readers may well have a sensible appreciation of the > difficulties about which you write. As has been pointed out already, > many readers here are extremely experienced programmers.

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
Alex Martelli wrote: > Russ specifically mentioned *mission-critical applications* as being > outside of Python's possibilities; yet search IS mission critical to > Google. Yes, reliability is obtained via a "systems approach", Alex, I think you are missing the point

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
Neil Cerutti wrote: > Who watches the watchmen? The contracts are composed by the > programmers writing the code. Is it likely that the same person > who wrote a buggy function will know the right contract? The idea here is that errors in the self-testing code are unlikely to be correlated with

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
Steve Holden wrote: > Well that's a healthy attitude, but I am concerned that the Python > community should be as welcoming as possible, so I don't like the fact > that you feel you are being treated differently from anyone else. I certainly appreciate that. And I will try my best to refrain fro

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
Ricardo Aráoz wrote: > Actually my point was that if a program is to be trusted in a critical > situation (critical as in catastrophe if it goes wrong) then the OS, the > compiler/interpreter etc should abide by the same rules. That is > obviously not possible, so there's not much case in making

Re: status of Programming by Contract (PEP 316)?

2007-08-31 Thread Russ
On Aug 31, 6:45 pm, Steve Holden > We probably need to distinguish between "mission-critical", where a > program has to work reliably for an organization to meet its goals, and > "safety-critical" where people die or get hurt if the program misbehaves. The term "mission critical" itself can have

Re: status of Programming by Contract (PEP 316)?

2007-09-01 Thread Russ
On Sep 1, 4:25 am, Bryan Olson > Design-by-contract (or programming-by-contract) shines in large > and complex projects, though it is not a radical new idea in > software engineering. We pretty much generally agree that we want > strong interfaces to encapsulate implementation complexity. > That's

Re: status of Programming by Contract (PEP 316)?

2007-09-01 Thread Russ
On Sep 1, 6:51 pm, [EMAIL PROTECTED] (Alex Martelli) > try: > blah blah with as many return statements as you want > finally: > something that gets executed unconditionally at the end Thanks. I didn't think of that. So design by contract *is* relatively easy to use in Python already. The mai

Re: status of Programming by Contract (PEP 316)?

2007-09-01 Thread Russ
On Sep 1, 10:44 pm, Russ <[EMAIL PROTECTED]> wrote: > On, one more thing. I see that the line wrapping on Google Groups is > finally working for me after many months. Fantastic! I can't help but > wonder if my mentioning it to you a few days ago had anything to do > with

Re: status of Programming by Contract (PEP 316)?

2007-09-02 Thread Russ
On Sep 1, 10:05 pm, Russ <[EMAIL PROTECTED]> wrote: > changing the language itself. Someone please correct me if I am wrong, > but I think PEP adds only to the libraries. I meant to write PEP 316, of course. -- http://mail.python.org/mailman/listinfo/python-list

Re: status of Programming by Contract (PEP 316)?

2007-09-02 Thread Russ
On Sep 1, 11:04 pm, Paul Rubin wrote: > I still don't understand why you don't like the decorator approach, > which can easily implement the above. Well, maybe decorators are the answer. If a function needs only one decorator for all the conditions and invariants (pre and post- conditions), and i

programming by contract using "decorators"

2007-09-03 Thread Russ
In the thread I started a few days ago, I was told that "programming by contract," could be done with "decorators." I was skeptical that this was a good approach, but as an exercise, I tried to code it up in a reasonably elegant form. I'd like to think I succeeded -- and I must admit that those who

generating stats from stdout on a regular interval

2007-03-20 Thread russ
a regular interval, i.e. every 10 min. Probably push the stats out to a CSV file. The popen2 module can read the stdout just like a file, and the csv module can handle the reading / writing. How do I go about 'processing' the stdout every 10 min? Thanks, Russ -- http://mail.python.

Re: how can I clear a dictionary in python

2007-03-29 Thread Russ
This little squabble got me thinking. I normally just use the myDict={} method of "clearing" a dictionary when I know there are no other references to it. However, I wonder how the efficiency of relying on the garbage collector to clear a dictionary compares with using the "clear" method. Does anyo

Re: Units of measurement

2007-01-17 Thread Russ
Robert Kern wrote: > Paul Rubin wrote: > > I'm sure this has been done before, but it just struck my fancy, an > > example of Python's "emulating numeric types", inspired by the old > > Unix "units" utility, and the Frink language. > > Oh yeah, it's been done before. Several times over, in fact.

Re: Is any python like linux shell?

2007-01-21 Thread Russ
Frank Potter wrote: > I learned some python in windows. > And now I've turned to linux. > I read a book and it teaches how to write shell script with bash, > but I don't feel like the grammar of bash. > Since I know about python, > I want to get a linux shell which use python grammar. > I searched

Re: Overloading assignment operator

2007-01-23 Thread Russ
Achim Domma wrote: > Hi, > > I want to use Python to script some formulas in my application. The user > should be able to write something like > > A = B * C > > where A,B,C are instances of some wrapper classes. Overloading * is no > problem but I cannot overload the assignment of A. I understand t

generating Java bytecode

2007-02-18 Thread Russ
I would like to generate Java bytecode from Python source. I know this is possible using Jython, but I am having problems getting my code to run on Jython. Is there another way to get Java bytecode? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

setup.py installation and module search path

2007-02-20 Thread Russ
When I run setup.py to install a pure python package, is it supposed to automatically set my search path to find the installed modules? Or am I supposed to set my PYTHONPATH variable myself in my .bashrc file? And what if I don't have root priviledge? Then what is supposed to happen? Can anyone gi

Re: setup.py installation and module search path

2007-02-20 Thread Russ
Larry Bates wrote: > I'm no expert, but I think what normally happens is the module gets > installed into ../pythonxx/lib/site-packages/ and if it > installs __init__.py file there they get automatically searched. > At least that the way things work for me. But if I don't have root priviledge, t

jython import search path

2007-02-21 Thread Russ
I have a Python program that I want to run in Jython so I can get Java bytecode output. The program runs fine in Python, but when I change the first line of the main program to make it run in Jython, it fails to find some of the imported modules. These are just plain Python imports of code I wrote

Re: jython import search path

2007-02-21 Thread Russ
On Feb 21, 4:15 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > Russ wrote: > > I have a Python program that I want to run in Jython so I can get Java > > bytecode output. The program runs fine in Python, but when I change > > the first line of the main program to make

Re: jython import search path

2007-02-22 Thread Russ
Diez B. Roggisch wrote: > >> Maybe Jython expert has the perfect answer but til then. > >> > >> Did you try: > >> > >> sys.path.append('path to search') > >> > >> Usually this works if nothing else does. > >> > >> -Larry > > > > Thanks. That's a good workaround, but I would like to know the > > "

Re: Google App Engine Code Challenge - write a tetris playing algorithm

2008-12-01 Thread russ
that's the first feature i'll add.. once the popularity gets over zero! :) On Tue, Dec 2, 2008 at 2:19 PM, Casey McGinty <[EMAIL PROTECTED]>wrote: > On Sun, Nov 30, 2008 at 2:41 PM, russ.au <[EMAIL PROTECTED]> wrote: > >> I've got more features to add, depending on how >> popular it is..

Re: Google App Engine Code Challenge - write a tetris playing algorithm

2008-12-01 Thread russ
> > what if you wanted to move a piece to the left or right after its past some > vertical obstruction? > Not _presently_ supporting moving the piece left or right. I've thought about it, and would make things a bit more complicated - just wanted to get something simple "out there", and see how m

implementation of "complex" type

2006-03-09 Thread Russ
I tried the following: >>> x = complex(4) >>> y = x >>> y *= 2 >>> print x, y (4+0j) (8+0j) But when I tried the same thing with my own class in place of "complex" above, I found that both x and y were doubled. I'd like to make my class behave like the "complex" class. Can someone tell me the tri

Re: implementation of "complex" type

2006-03-09 Thread Russ
"Why don't you show us your complex class?" Because I don't have a complex class. I merely used the complex class as an example to test the referencing behavior. Please read more carefully next time. -- http://mail.python.org/mailman/listinfo/python-list

Re: implementation of "complex" type

2006-03-09 Thread Russ
"When you are the one seeking help, you may find it helpful to be polite I have found that comp.lang.python has some of the most friendly and helpful people around. They will undoubtably help you (as they helped me many times), if you provide answers to the questions they ask in trying to hel

Re: implementation of "complex" type

2006-03-09 Thread Russ
"Better still, let's not bother ... I'm sorry you don't like the support around here, I guess you get what you ask for. " Boy, some people are very sensitive around here. And some of them also have a bad habit of misrepresenting my views. For the record, I am very happy with the support here. In

Re: implementation of "complex" type

2006-03-09 Thread Russ
Thanks for the links, especially for the pure Python implementation. That provides a good model for similar classes. I am just wondering why your implementation of complex numbers does not have "assignment operators" such as "__iadd", etc. By the way, I suppose my original post (where I wrote, "

output formatting for classes

2006-03-09 Thread Russ
I'd like to get output formatting for my own classes that mimics the built-in output formatting. For example, >>> x = 4.54 >>> print "%4.2f" % x 4.54 In other words, if I substitute a class instance for "x" above, I'd like to make the format string apply to an element or elements of the instance.

"pow" (power) function

2006-03-15 Thread Russ
other (perhaps less efficient) algorithm based on logarithms? Thanks, Russ -- http://mail.python.org/mailman/listinfo/python-list

Re: "pow" (power) function

2006-03-15 Thread Russ
Ben Cartwright wrote: > Russ wrote: > > Does "pow(x,2)" simply square x, or does it first compute logarithms > > (as would be necessary if the exponent were not an integer)? > > > The former, using binary exponentiation (quite fast), assuming x is an > int

output formatting for user-defined types

2006-04-05 Thread Russ
I'd like to get output formatting for my own classes that mimics the built-in output formatting. For example, >>> x = 4.54 >>> print "%4.2f" % x 4.54 In other words, if I substitute a class instance for "x" above, I'd like to make the format string apply to an element or elements of the instance

Re: output formatting for user-defined types

2006-04-05 Thread Russ
Thanks, but that is not acceptable for my application. Any other ideas? I thought I might be able to overload __rmod__, but apparently python applies the % operator before __rmod__ is even invoked if the left-hand argument is a string. -- http://mail.python.org/mailman/listinfo/python-list

Re: output formatting for user-defined types

2006-04-06 Thread Russ
>Yeah, how about we read your mind or make wild guesses about why it's >not acceptable, and about what your requirements really are. >Really, your response seems a little bizarre to me, given that __float__ >is the defined way in which float() gets a value from an instance, and >float() is what th

Re: output formatting for user-defined types

2006-04-06 Thread Russ
>I'm sorry, your system of units doesn't allow trig functions to operate on >degrees? I presume you don't allow grads either. What about steradians or >other arbitrary measures of angle or solid angle? I should have stated that more clearly. You can enter the value in degrees, but it will automati

Re: output formatting for user-defined types

2006-04-07 Thread Russ
> dist = 4 * ft > print >> out, dist/ft >> 4 >> Note, however, that this requires the user to explicity ask for the >> conversion. >How is this any more explicit and any less safe than: >dist = 4 * ft >print float(dist) Because the former specifies the actual units and the latter does n

Re: output formatting for user-defined types

2006-04-07 Thread Russ
Let me just revise earlier my reply slightly. >But in any case, I suspect you do automatically convert units. What do you >do in this case: Yes, I do automatically convert units, but I only do correct conversions. Conversion from any unit other than radian to a dimensionless float is incorrect, s

Re: output formatting for user-defined types

2006-04-08 Thread Russ
>So what you are saying is, if I enter a unit in feet, you automatically >change that unit to some base unit (say, metres if you use SI) behind my >back. So, assuming SI units as the base, if I say: >print 2*ft + 1*ft >you're going to give me an answer of 0.9144 metres, instead of the >expected 3

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Russ P.
On Tuesday, June 4, 2013 8:44:11 AM UTC-7, Rick Johnson wrote: > Yes, but the problem is not "my approach", rather the lack > > of proper language design (my apologizes to the "anointed > > one". ;-) If you don't like implicit conversion to Boolean, then maybe you should be using another langu

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Russ P.
On Wednesday, June 5, 2013 12:15:57 AM UTC-7, Chris Angelico wrote: > On Wed, Jun 5, 2013 at 4:11 PM, Russ P. wrote: > > > On Tuesday, June 4, 2013 8:44:11 AM UTC-7, Rick Johnson wrote: > > > > > >> Yes, but the problem is not "my approach", rather

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Russ P.
On Wednesday, June 5, 2013 1:59:01 AM UTC-7, Mark Lawrence wrote: > On 05/06/2013 07:11, Russ P. wrote: > > > > > But then, what would you expect of a language that allows you to write > > > > > > x = 1 > > > x = "Hello" > &

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Russ P.
On Wednesday, June 5, 2013 9:59:07 AM UTC-7, Chris Angelico wrote: > On Thu, Jun 6, 2013 at 2:15 AM, Russ P. wrote: > > > On Wednesday, June 5, 2013 1:59:01 AM UTC-7, Mark Lawrence wrote: > > >> I want to launch this rocket with an expensive satellite on top. I know >

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Russ P.
On Wednesday, June 5, 2013 4:18:13 PM UTC-7, Michael Torrie wrote: > On 06/05/2013 12:11 AM, Russ P. wrote: > > > But then, what would you expect of a language that allows you to > > > write > > > > > > x = 1 > > > x = "Hello" >

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-05 Thread Russ P.
On Wednesday, June 5, 2013 7:29:44 PM UTC-7, Chris Angelico wrote: > On Thu, Jun 6, 2013 at 11:56 AM, Steven D'Aprano > > wrote: > > > On Wed, 05 Jun 2013 14:59:31 -0700, Russ P. wrote: > > >> As for Python, my experience with it is that, as > > >

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-06 Thread Russ P.
On Thursday, June 6, 2013 2:29:02 AM UTC-7, Steven D'Aprano wrote: > On Thu, 06 Jun 2013 12:29:44 +1000, Chris Angelico wrote: > > > > > On Thu, Jun 6, 2013 at 11:56 AM, Steven D'Aprano > > > wrote: > > >> On Wed, 05 Jun 2013 14:59:31

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread russ . pobox
for key, value in sorted(months.items(), key=lambda x:x[1]): print("""'\t%s'\n""" % (value, key)) Explanation: - - - - - - dict.items is a method associated with dicts just like dict.keys or dict.values, and returns a list of (key, value) pairs. sorted and some other builtin functions have

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-11 Thread russ . pobox
Just try this in the interpreter and see. for key, value in sorted(months.items(), key=lambda x:x[1]): print "%s %s" % (value, key) -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple program question.

2013-06-11 Thread russ . pobox
input() is a function which returns a string. You can assign this return value to a variable. That's what variables are for. option = input() Now you can use the variable named option in place of all those calls to input(). i.e: ...instead of.. if input() == 'parry': # etc ...do this...

Re: My son wants me to teach him Python

2013-06-13 Thread russ . pobox
I couldn't read every post here so don't know if this has been suggested, or if there is perhaps a better suggestion which I haven't read in this thread, but in as far as I've read I feel the need to recommend: learnpythonthehardway.org Knowing a little JavaScript and even allot of HTML doesn't

  1   2   3   4   >