Re: newbie question

2013-06-25 Thread Tim Rowe
On 23 June 2013 03:49, Gene Heskett  wrote:

> On Saturday 22 June 2013 22:46:51 [email protected] did opine:
>
> > Writing simple program asking a question with the answer being
> > "yes"...how do I allow the correct answer if user types Yes, yes, or
> > YES?
> >
> > Thanks
>
> AND each character coming in from the keyboard with $DF before adding it to
> the comparison buffer.  Makes it all uppercase.  Then compare it to the
> uppercase YES.
>
> Cheers, Gene
>

Hello, the 1970s called and want their hairstyles back! That is *terrible*
practice in a modern high-level language. Use the library functions. They
will take proper account of the character set being used (which you
shouldn't even have to know for a task like this, let alone make unsafe
assumptions about).

-- 
Tim Rowe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-03-31 Thread Tim Rowe
On 22 March 2012 19:14, Chris Angelico  wrote:

> In any case, though, I agree that there's a lot of people
> professionally writing code who would know about the 3-4 that you say.
> I'm just not sure that they're any good at coding, even in those few
> languages. All the best people I've ever known have had experience
> with quite a lot of languages.

I know 10 languages. But I'm not telling you what base that number is :)

-- 
Tim Rowe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what happens inside?

2011-06-22 Thread Tim Rowe
On 22 June 2011 16:53, Andrew Berg  wrote:
> On 2011.06.22 10:45 AM, Chetan Harjani wrote:
>> why tuples are immutable whereas list are mutable?
> Tuples are more efficient and more appropriate for a list of items that
> doesn't need to change.

And also it sometimes useful to be sure that something can't change.
In particular, efficient dictionary implementations need the keys to
be immutable, because it you change a key it /really/ fouls up the
look-up.

-- 
Tim Rowe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Noob question: Is all this typecasting normal?

2009-01-17 Thread Tim Rowe
2009/1/3 Russ P. :

> So unless you think the standard library will someday include code for
> air traffic management, I'll stick with camelCase, and I'll thank you
> for not making an issue of it.

Another late comment, sorry, but as an air traffic management safety
consultant, I'm quite interested about where in ATM you plan to use
Python code, and how you will be meeting the applicable safety
standards in the relevant administration.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-17 Thread Tim Rowe
2009/1/16 has :

> http://www.alice.org/

Ooh, "JavaLikeSyntax.py" indeed! Why not "PythonLikeSyntax", since
that's apparently what they used!

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-18 Thread Tim Rowe
2009/1/18 Paul Rubin <"http://phr.cx"@nospam.invalid>:

> I.e. the cast was wrong because of the failure of an unstated
> assumption that a certain sensor reading was in a certain range.
> Spark may still have allowed the cast only if the assumption was
> stated explicitly in the specification.

Unless it's changed since I used it, technically, SPADE doesn't allow
or disallow anything. It produces a predicate (a proof obligation)
that you have to prove is always true (or is it always false? It's
been 18 years since I worked on that stuff, and SPADE and MALPAS
produced their proof obligations with opposite values). So it's still
up to you to show that it won't overflow, it just gives you the
predicate calculus expression that you need to do that.

Since the value appears to come from a sensor, the only way one could
prove that there would be no overflow would be to state it as a part
of the specification of what is read in. If that specification doesn't
match the specification of the actual sensor, that's nothing to do
with the programming language or, for that matter, the program itself.
It's a specification mismatch.

I was actually at the European Space Agency's Toulouse site the week
after the Ariane 5 incident. I've been at jollier funerals. I can't
help thinking that thinking that the team would have benefited from
reading David Parnas's work on the specification of the A-7E avionics.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-21 Thread Tim Rowe
2009/1/21 Paul Rubin <"http://phr.cx"@nospam.invalid>:

> I have no direct experience with it but have read a little about it.
> It looks to be a fairly vanilla block structured imperative language
> like Pascal with some concurrency stuff added.  The sense I have is
> that it's not especially harder to program in than C or C++, but the
> programs come out much more reliable.

It is rather more than that, in that it's particularly strict (and it
has a particularly powerful arithmetic model), but its roots are
certainly there. At a conference on the safe subset, SPARK Ada, one of
the SPARK developers pointed out that the SPARK Ada subset was
effectively Modula2.

Programs done in Ada are, by objective measures, more reliable than
those done in C and C++ (the very best released C++ programs are about
as good as the worst released Ada programs), although I've always
wondered how much of that is because of language differences and how
much is because Ada tends to be used on critical projects that also
tend to get a lot more attention to development standards.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-22 Thread Tim Rowe
> Btw, the correctness of a program (on a turing-complete language) cannot be
> statically proven. Ask Turing about it.

For the most safety critical of programmes, for which static proof is
required, restrictions are placed on the use of the language that
effectively mean that it is not Turing-complete. Specifically, all
loops that are required to terminate require a loop variant to be
defined. Typically the loop variant is a finite non-negative integer
that provably decreases on every pass of the loop, which makes halting
decidable.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-23 Thread Tim Rowe
2009/1/22 Scott David Daniels :

> Having once been a more type-A, I labored for a couple of years trying
> to build a restricted language that provably terminated for work on an
> object-oriented database research.

I was careful to say that it was the /use/ of the language that is
restricted; it's still possible to write undecidable programs, there's
just an obligation on you to show that you haven't.

> I finally gave it up as a bad idea,
> because, in practice, we don't care if a loop will terminate or not in
> database work; a transaction that takes a year to commit is equivalent
> to an infinite loop for all applications that I have interacted with
> (and yes, I have worked allowing four day transactions to commit).

True -- the really serious safety critical stuff is usually real time,
and part of the proof obligations is to show that the maximum response
time is tolerable. The loop variant can help with that, too.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: The First Law Of comp.lang.python Dynamics

2009-01-23 Thread Tim Rowe
2009/1/23 Kay Schluehr :
> Whatever sufficiently sophisticated topic was the initially discussed
> it ends all up in a request for removing reference counting and the
> GIL.

Well, maybe, but it seems to me that the real issue here is that we
need to remove reference counting and the GIL.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: The First Law Of comp.lang.python Dynamics

2009-01-23 Thread Tim Rowe
2009/1/23 Benjamin Kaplan :

> BTW, he said sufficiently sophisticated topic. Since there hasn't been an
> extremely long post here yet, I don't know if this counts.

Had I waited until the thread became long enough, somebody else would
have already raised the issue -- you must surely know about Schluehr's
Law? ;-)


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: The First Law Of comp.lang.python Dynamics

2009-01-23 Thread Tim Rowe
2009/1/23 Martin P. Hellwig :

> Or you can argue that even when an argument is repeated indefinitely it
> doesn't make it suddenly right.

No, but it makes for a confirmation of Schluehr's law :-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-24 Thread Tim Rowe
2009/1/24 Rhodri James :


> My experience with medium-sized organisations (50-100 people) is that
> either you talk to Fred directly, or it doesn't happen.  In particular
> the more people (especially PHBs) that get involved, the slower the
> change will come and the less like your original requirement it will
> look.  Each person, no matter how technically adept, has a significant
> chance of misunderstanding what it is you need and/or expressing it
> poorly to the next person in line.

So you talk to Fred, and he changes the "pong" library function to go
"ping", as you wish. Unfortulately, neither of you know that Alice is
depending on Fred's "pong" library function to go "pong" as specified,
and is totally stuffed when he delivers it and it goes "ping". That's
why changes to specifications need to go through a proper
specification change procedure if the team (not the organisation) is
more than a few people.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newby: how to transform text into lines of text

2009-01-26 Thread Tim Rowe
2009/1/25 Tim Chase :

> (again, a malformed text-file with no terminal '\n' may cause it
> to be absent from the last line)

Ahem. That may be "malformed" for some specific file specification,
but it is only "malformed" in general if you are using an operating
system that treats '\n' as a terminator (eg, Linux) rather than as a
separator (eg, MS DOS/Windows).

Perhaps what you don't /really/ want to be reminded of is the
existence of operating systems other than your preffered one?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: A java hobbyist programmer learning python

2009-01-26 Thread Tim Rowe
> I like the latter two styles, particularly the last one. That way you
> can see at a glance that those member variables are defined in the
> super class.

I like the second style because it makes it leaves the 2-d
implementation hidden, which is the whole point of encapsulation.

> But then I am a fan of Hungarian notation, which many
> programmers can't stand.

Is it that programmers can't stand it, or is it that they can't stand
it when it's imposed when not needed? As a pseudo type system for
languages with no typing it's pretty useful. To the extent that a
language provides typing it's useless verging on dangerous because it
can get out of synch with the actual type. I believe that any case of
Hungarian notation being useful is evidence of a flaw in the language
being used -- but arguably all languages are flawed in some way or
other, so Hungarian /can/ be useful. At this level I don't recognise a
difference between System and Applications Hungarian, by the way --
the difference is eliminated if you declare types corresponding to the
"meanings", which is commonplace in, for example, Ada.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-26 Thread Tim Rowe
2009/1/26 Paul Rubin <"http://phr.cx"@nospam.invalid>:
> Steve Holden  writes:
>> Quite. Python is a language "for consenting adults".
>
> Shouldn't such a language allow consenting adults to enter a BDSM
> scene without being moralized at, if that's what they want to do? ;-)

The language doesn't stop you. You can shift all of your code over to
Ada if you want to, and although /some/ Pythonistas might shake their
heads in bewilderment, I don't think there would be any moralising.
The question is whether Python has to /provide/ the BDSM scene for
you. I don't think it's realistic for a language to provide every
possible degree of BDSM from BCPL to Ada, Eiffel and beyond. A
language has to be positioned somewhere on the scale, and deciding
whether that's the right point on the scale for you and your project
is part of what being a grown-up programmer is about. One size does
not fit all, one language is not ideal for all applications.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-30 Thread Tim Rowe
2009/1/30 Hung Vo :

> I want to justify the above question (is Python Object-Oriented?).
> Does Python follow the concepts/practices of Encapsulation,
> Polymorphism and Interface, which are quite familiar to Java
> programmers?

It's not the role of the language to follow those concepts, it's the
role of the programmer to follow those concepts if the programmer
believes OO to be an appropriate paradigm for the task in hand.  If
the programmer decides that following those concepts is appropriate,
Python will offer more than enough support. If the programmer decides
that OO is not an appropriate paradigm but wants to follow procedural
or functional concepts instead, Python will support that, too.

Object orientation is not really a language property at all; it's a
design approach. I've written object oriented programs in C,
hand-coding the despatch tables, before anybody gave the name "object
oriented" to that approach. When people talk about an object oriented
language they either mean a language that allows a close mapping
between an object oriented design and the actual code (Python does),
or they mean a language that *requires* the code to conform to an
object oriented design (Python doesn't). So the answer to "Is Python
Object-Oriented" is either "yes" or "no", depending on what you're
/really/ asking.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: search speed

2009-01-30 Thread Tim Rowe
2009/1/30 Diez B. Roggisch :

> No. Because nobody can automagically infer whatever structure your files
> have.

Just so. But even without going to a full database solution it might
be possible to make use of the flat file structure. For example, does
the "LF01" have to appear at a specific position in the input line? If
so, there's no need to search for it in the complete line. *If* there
is any such structure then a compiled regexp search is likely to be
faster than just 'if "LF01" in line', and (provided it's properly
designed) provides a bit of extra insurance against false positives.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: search speed

2009-01-31 Thread Tim Rowe
2009/1/30 Scott David Daniels :

> Be careful with your assertion that a regex is faster, it is certainly
> not always true.

I was careful *not* to assert that a regex would be faster, merely
that it was *likely* to be in this case.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-02-02 Thread Tim Rowe
2009/2/2 Russ P. :

> Are we supposed
> to believe that the designers of C++, Java, Ada, and Scala are all
> idiots?

No, we're supposed to believe that the designers of C++, Java, Ada,
and Scala are all designers of languages that are not Python. If all
languages had the same philosophy what would be the point of different
languages? Is it worth mentioning (again) that Python is not Java?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: what IDE is the best to write python?

2009-02-02 Thread Tim Rowe
2009/2/1 MattBD :

> Really it depends what you are doing. Some languages are very tightly
> integrated with an IDE, such as MS Visual C#, and as far as I can see
> it would be extremely difficult, if not impossible to use a text
> editor with that language.

Why so? I don't see how it would be any different to any other
language. Admittedly I use the IDE because I like IDE's, but I don't
see why it wouldn't work with a text editor and make -- the command
line compiler is there.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-02-02 Thread Tim Rowe
2009/2/2 Russ P. :
> On Feb 2, 2:46 pm, Tim Rowe  wrote:

>> No, we're supposed to believe that the designers of C++, Java, Ada,
>> and Scala are all designers of languages that are not Python. If all
>> languages had the same philosophy what would be the point of different
>> languages? Is it worth mentioning (again) that Python is not Java?
>>
>> --
>> Tim Rowe
>
> I am not sure why people keep "mentioning" that "Python is not Java."

Because Java is the language that folks most offen insist Python become like.

> As a slogan, it is rather misleading. Python is not C++, Ada, or Scala
> either. All of those languages have enforced access restriction. Why
> only mention Java?

You might notice that I also mentioned C++, Ada and Scala.

> their wishes. If that's the case, you have my sympathies, but let's
> not pretend that Java is the only popular OO language with enforced
> access restrictions.

You might notice (again) that I also mentioned C++, Ada and Scala.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: what IDE is the best to write python?

2009-02-03 Thread Tim Rowe
2009/2/3 Jervis Whitley :

> real programmers use ed.

Ed? Eee, tha' were lucky. We had to make holes in Hollerith cards wi'
our bare teeth...

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


sys.float_info.epsilon

2009-02-04 Thread Tim Rowe
I'm reading Mark Summerfield's "Programming Python 3.0" at the moment,
and I'm puzzled by some of his uses of sys.float_info.epsilon. I
appreciate the issues of comparing floating point numbers, but I'm
puzzled by code like:
...
x = float(input(msg))
if abs(x) < sys.float_info.epsilon:
...

What could the float() conversion return that would give different results for:
if abs(x) < sys.float_info.epsilon
and (to my mind, more obvious):
if abs(x) == 0.0

I didn't realise that float() could return anything with an absolute
value less than sys.float_value.epsilon other than 0.0 (which I think
all representations can represent exactly).  What am I missing here?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.float_info.epsilon

2009-02-04 Thread Tim Rowe
2009/2/4 Mark Dickinson :

> There are many positive floating-point values smaller than
> sys.float_info.epsilon.
>
> sys.float_info.epsilon is defined as the difference between 1.0 and
> the next largest representable floating-point number.  On your system,
> the next largest float is almost certainly 1 + 2**-52, so
> sys.float_info.epsilon will be exactly 2**-52, which is around
> 2.2e-16.  This number is a good guide to the relative error
> from rounding that you can expect from a basic floating-point
> operation.
>
> The smallest positive floating-point number is *much* smaller:
> again, unless you have a very unusual platform, it's going to
> be 2**-1074, or around 4.9e-324.  In between 2**-1074 and
> 2**-52 there are approximately 4.4 million million million
> different floating-point numbers.  Take your pick!

Ok, that makes a lot of sense, thanks. I was thinking in terms of
Ada's floating point delta (rather than epsilon), which as I remember
it, if specified, applies uniformly across the whole floating point
range, not just to a particular point on the scale.

That just leaves me puzzled as to why Mark Summerfield used it instead
of a check against zero on user input. There's a later division by
2*x, so small values of x matter; there's no protection against
overflow (the numerator could perfectly well be somewhere up near
sys.float_info.max; a quick check in the shell tells me that Python3
will happily do sys.float_info.max/(2*sys.float_info.epsilon) and will
give me the answer "inf") so presumably he's trying to protect against
divide by zero. So my next question is whether there is any x that can
be returned by float() such that x != 0 but some_number / (2 * x)
raises a ZeroDivisionError?


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.float_info.epsilon

2009-02-04 Thread Tim Rowe
2009/2/4 Scott David Daniels :

Thanks for that. It makes me feel guilty to point out that:

> addition is not associative in real numbers

should presumably be "addition is not associative in floating point numbers".

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Couple of noobish question

2009-02-04 Thread Tim Rowe
2009/2/4 Bruno Desthuilliers :

> # somemodule.py
>
> import os
>
> if os.uname()[0] == "Linux":

On an MS Windows system, os.uname()[0] raises an AttributeError -- sys
doesn't seem to contain uname. Is that a Linux thing? Would os.name
work on Linux? Or would one have to use exception handling and catch
the Windows case?

That's the trouble with using anything in os, of course -- it's os
dependent, which is why it's there! :-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade 2.6 to 3.0

2009-02-04 Thread Tim Rowe
2009/2/4 Scott David Daniels :
> joviyach wrote:
>>
>> I am fairly new to Python, the first version I loaded was 2.6. I have
>> since downloaded 3.0 and I was wondering what the best practice for
>> upgrading is? I am using Windows XP Pro for my OS.
>
> On Windows, X.Y.* all go in one directory (over-riding each other)
> So the whole 2.6.* family should work just fine alongside the 3.0.*

Just don't try to have a 2.6 version of Idle and a 3.0 version of Idle
running at the same time! 2.6 WinPy and 3.0 Idle seem to coexist ok,
which is handy when I'm trying to get to grips with the differences
between versions..

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: sys.float_info.epsilon

2009-02-04 Thread Tim Rowe
2009/2/5 Scott David Daniels :

> And, of course he is right (and didn't even whomp on my typo of "makes"
> as "mes in the first line quoted above).

A typo for "makes" didn't bother me. Non-associativity of the real
numbers under addition risked making my whole world fall apart :-)


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Couple of noobish question

2009-02-04 Thread Tim Rowe
2009/2/5  :
> On Feb 5, 11:14 am, Tim Rowe  wrote:
>
> ...
>
>> On an MS Windows system, os.uname()[0] raises an AttributeError -- sys
>> doesn't seem to contain uname. Is that a Linux thing? Would os.name
>> work on Linux? Or would one have to use exception handling and catch
>> the Windows case?
>
> It seems to be a Windows thing.  My Linux box gives me 'Linux' the
> server gives me 'SunOS' and a Mac tells me 'Darwin'.  I'm still
> running Python2.4 on the Windows box.  At least in that version on the
> OS,  the 'os' module has no attribute 'uname',  On both Linux and
> SunOS, os.name returns 'posix'.

Python in a Nutshell states that os.uname "exists only on certain
platforms", and in the code sample wraps it in a try statement. That
seems to be the safe way to go -- except (and I don't know much about
this) wouldn't code have to be digging into some pretty obscure
corners to find a difference between different posix implementations?


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-04 Thread Tim Rowe
2009/2/5 [email protected] :
> Using while loop and if statement, I'm trying to get Python to tell me
> whether there are even or odd number of 1's in a binary representation.
> For example, if I give Python a 0111, then I want it to say that the
> binary representation given has an odd number of 1's.
> If I give it 00010111, then it will tell me that there is an even number of
> 1's.
> I'd appreciate any suggestion.
> Thanks!

Looks like homework to me, so I'll just give a couple of suggestions.

If you're going to prompt the user for the number, you'll get a string
back, and that might be easier to work with than a number. So you need
to set a boolean value for the result, something like:
   even = True
(because so far you've seen zero 1's, and zero is even).

Then you need to loop over each character in the string -- there's
your loop -- and if (there's your if) it's a "1" change the truth
value of even:
even = !even.

If it is a number rather than a string, you want to do much the same
thing but you'll need the >> and & operators.

Chris has already shown you how this would actually be done in Python,
but that doesn't match your assignment description.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade 2.6 to 3.0

2009-02-04 Thread Tim Rowe
2009/2/5 Giampaolo Rodola' :

> Just out of curiosity, am I the only one who think that switching to
> 3.x right now is not a good idea?

I'm looking at making the switch, but I'm put off by the lack of 3rd
party stuff such as PyWin (and I can't see a NumPy build for Python
2.6 yet, never mind 3.0). Unless all you want is in the standard
library, I think it's worth the general user holding back for a while
whilst the tool providers catch up.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Feet and inches

2009-02-04 Thread Tim Rowe
2009/2/5 [email protected] :
> I'm trying to get Python to say:
>
> Enter the height (in metres):
>
> and convert whatever value to feet and inches.

This looks like another homework assignment. You'll probably get more
help (on *any* language forum) if you admit that up front. However, at
least this time you've shown us that you've made a good first attempt,
so here are a few hints.

> I've done this part as you
> can see below, but how can I terminate the program when user inputs a height
> less than 1/2 inch?

The program already terminates when the user inputs any height. If you
want it to *keep* asking you need to wrap it in some sort of loop.
Look up "while" and "break".

> How can I also take into account all the cases that need an exception?

I think your code already takes into account all the cases that need
an exception -- you just need to handle the exceptions. Try entering
some silly values for the height (try something like "one point three"
for example) and look at the exception you get. Then look up "try" and
"catch" to see what you might do about it. You might like to think
about what should happen if a user enters a negative value, but the
present behaviour -- when fixed -- may be what you need.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Tim Rowe
2009/2/5 Duncan Booth :
> Mark Dickinson  wrote:
>
>> def count_set_bits(n):
>> # make sure we include an if, to
>> # satisfy OP's requirements:
>> if n < 0:
>> raise ValueError
>> count = 0
>> while n:
>> count += 1
>> n &= n-1
>> return count
>>
>> is_even = count_set_bits(the_int) % 2 == 0
>>
>> ...but anyone submitting this as a homework
>> solution had better be prepared to explain why
>> it works.
>>
>
> I remember a programming exercise when I was an undergraduate and anyone
> who *didn't* use that trick got marked down for writing inefficient code.

Is adding and a modulus *really^ more efficient than flipping a bool
as I suggested? I think I'd want to see measurements!


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-05 Thread Tim Rowe
2009/2/5 Duncan Booth :

>>> I remember a programming exercise when I was an undergraduate and
>>> anyone who *didn't* use that trick got marked down for writing
>>> inefficient code.
>>
>> Is adding and a modulus *really^ more efficient than flipping a bool
>> as I suggested? I think I'd want to see measurements!
>>
>>
> I meant the bitwise twiddling, but actually I misread it. I thought Mark
> was using the n&~n+1 trick to pull out bits from least significant upwards
> when of course he's just clearing the low bit not extracting it.

Ah, ok. Yes, that's faster than my bit shifting. A million bytes with
your method on my computer with your bit-twiddling takes 1.047
seconds, with my bit-shifting it takes 1.578. On the other hand,
unless that was demonstrated to be a bottleneck I'd still go for the
bit shifting because I think it's clearer. And I'd want a word with a
tutor who insisted on premature optimisation ("The root of all evil",
according to C A R Hoare), especially in a scripting language!

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Tim Rowe
2009/2/5 mk :
>
> (duck)
>
> 542 comp.lang.python rtfm
>
> 467 comp.lang.python shut+up
>
> 263 comp.lang.perl rtfm
>
> 45 comp.lang.perl shut+up

Yes, but is there any real traffic on comp.lang.perl nowadays?

Sorry, cheap shot ;-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is c.l.py becoming less friendly?

2009-02-05 Thread Tim Rowe
2009/2/5 Tim Chase :

> Is this where we tell you to shut up?  ;-)

[snip]

> It would also be interesting to see how many of those posts are concentrated
> in certain threads

And, as you have clearly demonstrated, how many of those posts also
contain a smiley or some other form of hedging in a position that
could modify the "unfriendly" text?


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Couple of noobish question

2009-02-05 Thread Tim Rowe
2009/2/5 Bruno Desthuilliers :

> Thanks for the correction - as you may have guessed, I have not used windows
> for years !-)

And I can't get Linux running (more precisely, I can't /keep/
X-Windows running). Isn't it a good job that Python is cross-platform
-- as long as we stay clear of the os module :-)


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Weird" Indentation? (Or: is there a for...else construct?)

2009-02-08 Thread Tim Rowe
2009/2/7 andrew cooke :
>
> there's a justification for this awful mess here -
> http://mail.python.org/pipermail/python-3000/2006-March/000104.html
>
> i didn't know about this, and even after reading steven's broken (i
> assume) example, managed to get it backwards.

What's awful about it? Except in the sense of inspiring awe, of
course. No, Steven's example isn't broken, it works as the epydoc
authors intended.

> (it's still in 3).

Good.

--
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Putting asterisks around text

2009-02-09 Thread Tim Rowe
2009/2/9 [email protected] :

> I'm not necessarily asking for an answer. A hint would be grateful as well.

Great. Well, first you need to read:
http://www.catb.org/~esr/faqs/smart-questions.html

Especially the section on "Before you ask".

Then you should be able to give us a question that shows that you've
tried and aren't just wanting us to do your work for you, and that
gives us a clear idea of where your sticking point is so we can
address the sticking point instead of the whole assignment.

Like: How fo you do it without using a while loop? (Yes, *I* know how
to do it without using a while loop, but to help you we need to know
what *you* know). Like: do you understand what a while loop does? And
so on.

We're a pretty friendly bunch in here, but most of us believe in
"tough love" (http://en.wikipedia.org/wiki/Tough_love).

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embarrasing questio

2009-02-12 Thread Tim Rowe
2009/2/12 km :
> Hi,
>
> you could do it this way also :
>
> if i in [3,5]:
> do something...

True, you could do it, but it would be wrong. The original is true for
i = 6, 9, 10, 12 and so on, but yours doesn't seem to be...

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread Tim Rowe
2009/2/16  :
> Hi everybody,
> I am an engineer. I am trying to improve my software development
> abilities. I have started programming with ruby. I like it very much
> but i want to add something more. According to my previous research i
> have designed a learning path for myself. It's like something below.
>  1. Ruby (Mastering as much as possible)
>  2. Python (Mastering as much as possible)
>  3. Basic C++ or Basic Java
> And the story begins here. As i search on the net,  I have found that
> because of the natural characteristics of python such as GIL, we are
> not able to write multi threaded programs. Oooops, in a kind of time
> with lots of cpu cores and we are not able to write multi threaded
> programs. That is out of fashion. How a such powerful language doesn't
> support multi threading. That is a big minus for python.

In a way, you've answered your own question. Why are you learning
three languages? Perhaps you've already realised that being
Turing-complete isn't the last word in language choice; that different
languages make different compromises, so the best language for one
task may not be the best language for a different task. Ok, Python
doesn't cope well with threading. It doesn't cope well with hard
real-time, either. So what? A deep saucepan isn't much use for making
an omlette (it can be done, but it's inefficient), but it's ideal for
making soup. Just because multiple cores are available doesn't mean
they will help your program significantly. Most real-world programs
work just fine in a single core, and it usually just isn't worth all
of the extra design effort, coding effort and debugging effort of
threading to cut the user response time down from a tenth of a second
to a twentieth. For *most* applications the single-thread Python
programmer will have something written, shipped and doing the job
whilst the multi-thread programmer is still trying to debug an
intermittent livelock that goes away whenever instrumentation is
added.  For those few cases where threading is a genuine advantage,
Python is not ideal. But in the real world I doubt they're enough to
make a significant dent in Python's popularity.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-16 Thread Tim Rowe
2009/2/16  :

> I want to learn python + c++ or java because of the desire of having
> python's felxibility and easiness and c++ or java's stability and
> speed and power together.

Yes, that's what I mean by different tradeoffs. Python is much easier
to program in than C++ or Java (in my experience, at least), but C++
and Java scale better and at least have the potential to be faster.
I'm not convinced that library support is significantly better for C++
or Java -- Python's libraries seem pretty rich to me. And that extra
speed might not be needed as often as you think. My postgrad
dissertation involved heavy number-crunching on large data sets, and
in my proposal I said I'd switch from Python to C++ when Python got
too slow. In fact, Python never did get too slow (I didn't even have
to switch to numpy), and plugging together ad-hoc modules, defined in
an XML script, was a dream in Python when I'd probably still be coding
it today in C++. Horses for courses. It's almost always wrong to say
that language A is better than language B; the most you can say is
that language A is better than language B for some specific task.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-19 Thread Tim Rowe
2009/2/19  :
> Thank you Steve,
>
> I really wanted to learn python, but as i said i don't want to make a
> dead investment. I hope someone can fix these design errors and maybe
> can write an interpreter in python :)

Good luck with Java, and with your search for a perfect language. I
think it will be a long search.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-19 Thread Tim Rowe
2009/2/19  :
> Thank you Tim...
>
> It is not a search for perfect language. It is a search for a capable
> language to modern worlds' needs.

That would be just about any of the ones you mentioned, then. Unless
you mean the needs of a specific project, in which case the
suitability will depend on the project.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-19 Thread Tim Rowe
2009/2/19 Paul Rubin :

> That Python is so much slower than C is yet another area where Python
> can use improvement.

No, because we don't use Python where C would be more appropriate.
Sure nobody would complain if Python were faster, but it's not for
speed that we choose Python. Not speed of /execution/ that is.
Different languages have different trade-offs. Python's trade-offs
suit us. If they don't suit you, use a language with trade-offs that
do.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-19 Thread Tim Rowe
2009/2/19  :
> Hi again
>
> I really want to imply that i am not in search of a perfect language.
> Python for programming productivity is a great language but there are
> some real world facts. Some people want a language that provides great
> flexibility. A language can provide threads and processes and
> programmer choose the way. I really believe that GIL is a design
> error.

It's only an error if it gets in the way. It's the experience of a lot
of programmers that it doesn't, so it's not an error.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: get most common number in a list with tolerance

2009-02-20 Thread Tim Rowe
2009/2/20 Astan Chee :
> Hi,
> I have a list that has a bunch of numbers in it and I want to get the most
> common number that appears in the list. This is trivial because i can do a
> max on each unique number. What I want to do is to have a tolerance to say
> that each number is not quite unique and if the difference from other
> numbers is small, than it can be counted together. This is what I have to
> get the common number (taken from the internet somewhere):
>
> l = [10,30,20,20,11,12]
> d = {}
> tolerance = 5
> for elm in l:
>   d[elm] = d.get(elm, 0) + 1
> counts = [(j,i) for i,j in d.items()]
>
>
>
> This of course returns a list where each of them is unique
>
> [(1, 12), (1, 10), (1, 11), (2, 20), (1, 30)]
>
> but I am expecting a list that looks like this:
>
> [(3, 10), (2, 20), (1, 30)]

Why only the points 10, 20 and 30? what has happened to (3,11), for
example? (10, 11 and 12 are all within 11+/-5)

It seems you are trying to do one of two things. Either you are trying
to form a histogram with data bands +/-tolerance, or you are trying to
do something like kernel smoothing with a rectangular kernel.

What would you expect the output to be if the data set were
[10,30,20,20,11,12,13] and the tolerance were 2?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: datetime.time and midnight

2009-02-22 Thread Tim Rowe
2009/2/22 Mark Dickinson :
> On Feb 21, 10:44 pm, Ethan Furman  wrote:
>
>> --> midnight = datetime.time(0,0,0)
>> --> bool(midnight)
>> False
>
> I'd call this a bug.

No more so than zero being false. Zero exists too (check my bank
balance). Once you've accepted non-Boolean types having Boolean
values, the logic of what value they have is always going to be a bit
hairy. If you're unsure of the logic, just test against a value or a
range. After all, what value do you *expect* a time of day to have
when interpreted as a Boolean? If you don't have an expectation, why
are you interpreting it as a Boolean?


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 - is this true?

2008-11-24 Thread Tim Rowe
2008/11/24 Aahz <[EMAIL PROTECTED]>:

> (I'll agree that from some perspectives the new behavior of None is a
> wart but I think that in the end I agree with people who say that
> preventing None from being sorted except intentionally will trap more
> bugs earlier.)

So will Python be introducing strong type checking and early binding,
so we can catch more bius earlier (compile rather than run time?) ;-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: hello from colombia

2008-11-26 Thread Tim Rowe
2008/11/26 fel <[EMAIL PROTECTED]>:
> how can I convince them that Python is better

You can't, because it isn't.

I'd better explain that, before I'm lynched. The thing is, no language
is better than another language. A language is better than another
language *for a particular purpose*. SPARK Ada is better than Python
for safety-critical software (if only because it's easier to get
regulatory approval). INTERCAL is better than Python for
obfustication. Before you try to convert them to Python, you need to
find out all the reasons for the existing language choice and work out
whether Python actually /would/ be better. If you can do that, in the
process you will have gathered the evidence you need. If you can't do
that, why are you assuming that Python will be better?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: hello from colombia

2008-11-30 Thread Tim Rowe
2008/11/27 fel <[EMAIL PROTECTED]>:

> that's a lot of bytes for "do your own homework"
> but thanks, I'll do it.

It also included "You haven't defined the issue precisely enough" :-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python advocacy ... HELP!

2008-12-04 Thread Tim Rowe
2008/12/4 Michael_D_G <[EMAIL PROTECTED]>:
>
> I am a faculty member of a cs department. We currently teach C++ in
> our intro to programming course. I am teaching this class and it seems
> to me that we would be much better served teaching python in the intro
> course, C++ for Data structures, as we do now, and Java in object
> oriented programming, as we do now.
> Some of my colleagues agree with me but some still see python as a
> niche language and don't understand
> how we could teach anything beyond C, C++ or Java.

Try asking "Are we teaching computer science, so that the students
will be able to cope with whatever they meet once they graduate, or
are we teaching computer programming, in a couple of specific
languages, so that the students will be completely unprepared if they
meet anything else?"

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is 3.0 worth breaking backward compatibility?

2008-12-07 Thread Tim Rowe
2008/12/7 walterbyrd <[EMAIL PROTECTED]>:
> IMO: breaking backward compatibility is a big deal, and should only be
> done when it is seriously needed.
>
> Also, IMO, most of, if not all, of the changes being made in 3.0 are
> debatable, at best. I can not think of anything that is being changed
> that was really a "show stopper" anyway.


But that's what a major release number does for you. Modula2 was quite
a break from Modula. Think of Python3.0 it as a new language, if you
like, that's inspired by Python2. You can stay with Python2 or you can
adopt the new language. That way you won't have to think of it in
terms of breaking any sort of backwards compatibility because there is
no backwards ;-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Don't you just love writing this sort of thing :)

2008-12-10 Thread Tim Rowe
2008/12/9 Ethan Furman <[EMAIL PROTECTED]>:

> Not all code has to be written for everyone.  Not all code will be read by
> the masses.  Some code you write for yourself... an expression of who you
> are, how you think...
>
> While my own quirks are not as visually entertaining, I think it's another
> mark in Python's favor that such self-expression is possible, and
> functional.
>
> Yes, Lawrence, I do love writing fun code.

I did once get into a rivalry with a Perl programmer over
obfusticating a coding exercise. I knew from the start that I had no
chance, but I was impressed with how close-run I could make it with
Python. Fun, yes, but no way anything I would consider for code that
is actually going to be /used/ in any way whatsoever!


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing None objects from a sequence

2008-12-12 Thread Tim Rowe
2008/12/12 Filip Gruszczyński :
> I don't mean memory, but space in code ;-)

Trying to save printer paper for your listings, then?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: (Very Newbie) Problems defining a variable

2008-12-12 Thread Tim Rowe
Since we all seem to be having a go, here's my take. By pulling the
rates and thresholds into a dictionary I feel I'm getting a step
closer to the real world, where these would presumably be pulled in
from a database and the number of interest bands might vary. But is
there a tidier way to get 'thresholds'? I was a bit surprised that
rates.keys() didn't give me a list directly, so although the 3.0
tutorial says "The keys() method of a dictionary object returns a list
of all the keys used in the dictionary, in arbitrary order (if you
want it sorted, just apply the sort() method to )" that's not /quite/
such a given, because "the list of keys" doesn't seem to be there for
the sorting any more.

Is there a tidy way of making rates and thresholds local to get_rate,
without recalculating each time? I suppose going object oriented is
the proper way.

#Py3k,UTF-8

rates = {0: 0.006, 1: 0.0085, 25000: 0.0124, 5: 0.0149, 10: 0.0173}
thresholds = list(rates.keys())
thresholds.sort()
thresholds.reverse()

def get_rate(balance):
for threshold in thresholds:
if balance >= threshold:
return rates[threshold]
else:
return 0.0

balance = int(input("How much money is in your account?\n>>"))
target = int(input("How much money would you like to earn each year?\n>>"))

if balance <= 0:
print("You'll never make your fortune that way!\n")
else:
interest = 0
year = 0
while interest < target:
rate = get_rate(balance)
interest = balance * rate
balance += interest
    year += 1
print("Year %s, at %s rate: %s paid, %s in bank." % (year,
rate, interest, balance))


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: (Very Newbie) Problems defining a variable

2008-12-12 Thread Tim Rowe
2008/12/12 Kirk Strauser :

> def get_rate(balance):
>for threshold, rate in ((10, .0173),
>(5, .0149),
>(25000, .0124),
>(1, .0085),
>(0, .006)):
>if balance > threshold:
>return rate
>return .0

Yes, once it's changed from a dictionary to tuples it becomes easier,
doesn't it? D'oh!

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: (Very Newbie) Problems defining a variable

2008-12-12 Thread Tim Rowe
2008/12/12 John Machin :

> (2) sequential search can be very fast if the sequence is in
> descending order of probability of occurence ... you might like to
> consider reversing the order

I find it hard to imagine a bank with so many interest rate thresholds
that the search of the table is likely to be a significant
contribution to the run time!

> (3) for a much longer table, binary search using a function from the
> bisect module could be considered
> (4) in practice, the "default" action would not be "return 0.0";
> perhaps something along these lines:
>
> if balance < -overdraft_limit:
>   raise Exception(...)

That's more likely to be in the withdrawal routine (and is probably
best not handled as an exception, because it's pretty much normal
flow). If a bank provided a service such as the one implemented by
this program, there'd be no need for it to know about overdraft limits
because it's not making actual transactions. Why would they increase
coupling unneccesarily?

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question...

2008-12-12 Thread Tim Rowe
2008/12/12  :

> ah, ok.  now what if I want the variable to be an integer that I
> send?  for instance if I send 99 to the program, it is picking it up
> as a string instead of an integer value.  How do I handle this with
> python??

As 'r' has said, you can cast it to integer. In the real world you'd
want to handle the case where the user passes in something that isn't
an integer, or passes in nothing at all -- it's generally a good idea
to check anything the user enters for validity. It's possibly too
early for you to try to code it, but it's never too early to start
thinking about what you would /want/ it to do. What do you think it
will do for invalid or no command line arguments at the moment? Try
it!

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: 1 or 1/0 doesn't raise an exception

2008-12-15 Thread Tim Rowe
Unfortunately,

>>>> bool('Ruby totally pwn3s Python!')
> True

Using Python is not total protection against buggy programs ;-)


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Factoring Polynomials

2008-12-19 Thread Tim Rowe
2008/12/18 Scott David Daniels :

> def quadsolve(a, b, c):
>try:
>discriminant = sqrt(b**2 - 4 * a * c)

The discriminant of a quadratic is more usually just the b**2 - 4 * a
* c part, not the square root of it. Testing that for negative, zero
or positive avoids the need to use an exception for a normal case.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2009-01-05 Thread Tim Rowe
2009/1/1 r :
> I am beginning to think
> the perfect high level language would take the best for Ruby and
> Python. The ultimate language with speed in mind, pythons clear
> syntax, but with shortcuts for gurus.

I spent quite a few evenings looking at Ruby, and didn't find a single
thing I liked (and I certainly didn't find it "elegant", as the
original poster described it). What do you see in it that you think
would be good in Python? Remember, put in too many shortcuts and
you'll end up with code that's as unmaintainable as Perl!

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: When Python should not be used?

2008-10-06 Thread Tim Rowe
2008/10/6 Andrea Francia
<[EMAIL PROTECTED]>:
> The right tool depends on the current problem.
>
> While some python users prefer to talk about when Python is the right tool I
> think that it is more instructive to know when it is not.
>
> Please, could you let me know what do you think about that?

I don't think it would be the best tool for mission critical / safety
of life applications, or for hard real-time embedded systems.  There
are also areas where domain-specific languages have advantages over
general purpose languages (although the domain-specific language can
be wrapped in a Python library, of course, as is the case with regexp
support). Logic languages still seem to have the edge over imperative
in some AI and theorem proving applications (although I suppose one
/could/ implement Prolog in Python, if Prolog is what you need it's
probably best to go straight there).

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: automatically insert text in ms-word properties

2008-10-07 Thread Tim Rowe
2008/10/7 Peter Wang <[EMAIL PROTECTED]>:
> "gita ziabari" <[EMAIL PROTECTED]> writes:
>
>> All,
>>
>> I wanna use python to automatically insert text in ms-word properties.
>> Anyone could help me?
> Why not use VBA for that work?

Why use VBA?

It's actually not a straight choice. VBA is pretty much all that's
available if you're doing it from *inside* Word, it's not available if
you're doing it from *outside* Word. VB is available from outside
Word, but I for one would much sooner use Python in that case.

The difficulty isn't with the language, it's with lack of
documentation on Office Automation access to document properties. If
Gita can find that, Python should be at least as good for the job as
VB (and I think I'm being unduly kind to VB in putting it like that!)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: indentation

2008-10-21 Thread Tim Rowe
2008/10/21 Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>:

> Ever noticed that computer freaks often start counting at 0?  ;-)

We grow to be like our pets

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Linq to Python

2008-10-27 Thread Tim Rowe
2008/9/24 Duncan Booth <[EMAIL PROTECTED]>:


> Python still wins hands down on this example both in verbosity and
> readability:

But AFAICS, the Python version you give creates a temporary. One of
the advantages cited for LINQs functional programming paradigm is that
it specifies what is wanted at a higher level, so the compiler can
decide whether to create temporaries, and can also decide whether to
farm the thing off to multiple processors -- harder if you've
specified in detail /how/ to do the job. Not an issue for little jobs,
but certainly an issue for, for example, a friend who had a daily
database job to do that took over 24 hours to run.

> I haven't yet had occasion to use LINQ in anger yet, so I have no idea
> whether its an idea to love or to hate. I do think it is good that C# has
> effectively sprouted list comprehensions (not to mention anonymous types
> and type inferencing) and I expect there may be some aspects worth looking
> at for Python but I think they are more likely to lead to itertools
> functions than extensions to syntax.

Yes, looking at what LINQ adds to C# (according to
http://msdn.microsoft.com/en-gb/library/bb397909.aspx):
- Implicitly typed variables: Python already has.
- Object and collection initialisers: Not sure whether Python can do
this directly, but it can certainly emulate it with a dictionary.
- Anonymous types: Not sure whether Python can do this directly, but
it can certainly emulate it with a dictionary.
- Extension methods: Python already has.
- Lambda expressions: Python already has.
- Auto-Implemented properties: No, but that's just syntactic sugar to
make declarations more compact.

So all of the language elements that are needed for LINQ are already
in Python; a library should do the trick.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering python sets

2008-11-01 Thread Tim Rowe
2008/10/27  <[EMAIL PROTECTED]>:
> Lie Ryan:
>
>>Oh no, the two dict implementation would work _exactly_ the same from the 
>>outside, they are transparently interchangeable. Only the performance 
>>characteristic differs because of the different implementation.<
>
> I don't agree with the general idea. If the operations done by your
> data structure have different computational complexity, then they are
> fit for different usages. When you program you must know what
> computational complexity has each of the operations of your data
> structyre, otherwise there's no way to know the complexity of your
> whole program, so instead of programming you are just become a mage
> that tries magical spells and hopes for the better.

No, when you program you know how you will be using the data
structure, so you can choose the implementation that's right for the
application. That's what the container libraries for other languages
do. At the moment, you just have one implementation, and have to hope
it's right for the job. Adding an *optional* parameter that says, in
effect, "I want this list optimised for writes and reads at both ends"
or "I want this list optimised for fully random reads but writes only
at the end" doesn't *lose* you any information about what you're
programming with. Of course it's essential that the data structure has
identican /functional/ behaviour whatever optimisation you use. Other
languages can enforce that, but Python programmers are used to taking
care of that side of things for themselves.

> So I don't accept
> so much different data structures to have the same name. That's why
> I'll never appreciate the Python list type to be named list instead of
> array, despite it supports more or less all the functions you expect
> from an abstract list type.

They're not different data structures from the client point of view.
"More or less" all the functions wouldn't be enough.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rewriting a bash script in python

2008-11-05 Thread Tim Rowe
2008/11/6 Chris Jones <[EMAIL PROTECTED]>:

> Begs the question .. how do I tell what is an object-oriented vs. a
> procedural problem?

Practice, largely, so you're doing the right thing (provided you don't
trust your /real/ backup data to a tutorial program). If you find that
the program is at its neatest when it's just a couple of methods in
one class, it was a procedural problem.

Actually, from your description of the problem -- that the interest is
in all the "what if" cases -- suggests that it's a specification
problem rather than a design or implementation problem, so rather than
recoding it it might be worth looking at various approaches to
requirements capture and specification.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: locating the chorus in a MIDI song?

2008-11-05 Thread Tim Rowe
2008/11/4 Banibrata Dutta <[EMAIL PROTECTED]>:
> Without pretending to be an expert on the subject of music-theory or
> audio-processing, my n00b'ish doubt is -- MIDI, unlike MP3 would be devoid
> of voice... and in my overtly simplistic thinking --  presence / absence of
> which (i.e. voice) could be a "brute-force" way of detecting refrain/chorus

I think you're right. After all, The melody of the verse repeats
between verses, so without the words repetition is no longer a good
indicator of the chorus, and a shift in style is as likely (maybe more
likely) to find the bridge than find a chorus.. By the way, some of
the papers referenced seem confused between refrains (which form part
of the verses) and choruses (which are separate musical units).

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rewriting a bash script in python

2008-11-06 Thread Tim Rowe
2008/11/6 Lawrence D'Oliveiro <[EMAIL PROTECTED]>:

> Nothing wrong with rapid prototyping. :)

That's one requirements capture methodology, certainly. Actually,
there's quite a lot wrong with rapid prototyping, but there's quite a
lot wrong with all other requirements capture methodologies too, so
rapid prototyping is up there with the rest of them.


-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: duck-type-checking?

2008-11-12 Thread Tim Rowe
2008/11/12 Joe Strout <[EMAIL PROTECTED]>:
> Let me preface this by saying that I think I "get" the concept of
> duck-typing.
>
> However, I still want to sprinkle my code with assertions that, for example,
> my parameters are what they're supposed to be -- too often I mistakenly pass
> in something I didn't intend, and when that happens, I want the code to fail
> as early as possible, so I have the shortest possible path to track down the
> real bug.  Also, a sufficiently clever IDE could use my assertions to know
> the type of my identifiers, and so support me better with autocompletion and
> method tips.
>
> So I need functions to assert that a given identifier quacks like a string,
> or a number, or a sequence, or a mutable sequence, or a certain class, or so
> on.  (On the class check: I know about isinstance, but that's contrary to
> duck-typing -- what I would want that check to do instead is verify that
> whatever object I have, it has the same public (non-underscore) methods as
> the class I'm claiming.)
>
> Are there any standard methods or idioms for doing that?

What do you actually mean by "Quacks like a string"? Supports the
'count()' method? Then you find out if it doesn't when you try to
apply the 'count()' method. Supports some method that you don't
actually use? Then why do you care?

The point about duck typing is that something might quack like a duck
but not walk like a duck -- one of those duck calls that hunters use,
for instance. Quacking like a duck doesn't actually mean it /is/ a
duck, it means that it will do instead of a duck if the quack is all
you want.

If all you care about is that 'foo' quacks like a duck then all you
need to know is that
   hasattr(foo, "quack")
and (if so)
   callable(foo.quack)
If you need to know that it walks like a duck, mates like a duck and
tastes like a duck when roasted, you probably want it to really /be/ a
duck and should go back to inheritance.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: duck-type-checking?

2008-11-12 Thread Tim Rowe
2008/11/12 Joe Strout <[EMAIL PROTECTED]>:

>> If you need to know that it walks like a duck, mates like a duck and
>> tastes like a duck when roasted, you probably want it to really /be/ a
>> duck and should go back to inheritance.
>
> I can't agree; there are times when inheritance just won't do, for example
> when you don't have control over the object creation, because they come from
> some factory method you can't change.  In that case you may need to make a
> wrapper instead of a subclass, but if you've faithfully implemented the
> interface of the original class, you should be able to use it wherever the
> original class could be used (within reason).

And then the original class definition changes -- new members added --
but the ones from the factory class don't change, and so are no longer
compliant with the the factory class (which doesn't support the new
"form_pun_relating_to_avoiding_a_high_hazard()" method) . Fine. If you
checked for all the members of the class that your code uses, it makes
no difference. ABCs give you a way of doing this, but in their absence
it's a long list of checks. If you /can/ use inheritance then it saves
having to do those checks.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: duck-type-checking?

2008-11-13 Thread Tim Rowe
2008/11/13 Ben Finney <[EMAIL PROTECTED]>:

> That is not duck typing.

Oh, I'm pretty sure it is. It just isn't /using/ the duck typing in
the way you'd like.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reference or Value?

2009-02-24 Thread Tim Rowe
2009/2/24 Steven D'Aprano :

> If you look at this Wikipedia page:
>
> http://en.wikipedia.org/wiki/Evaluation_strategy
>
> you should be able to count no fewer than thirteen different terms for
> different evaluation strategies, and "call-by-value" itself is described as
> a family of strategies.

And that call by sharing is a member of that family even though the
behaviour is (as I understand it) exactly what you would get if you
pass an object by ^reference^ in C++. Wikipedia can be a double-edged
sword ;-).

I think the problem is that "Call by value" and "Call by reference"
are terms that pre-date object orientation, and don't cope well with
obect-oriented languages in general, not just with Python. That Java
programmers get by thinking the mechanism is called "call by value",
C++ programmers get by thinking the same mechanism is called "call by
reference" and Python programmers get by thinking the same mechanism
is called "call by sharing" suggests that the terms are no longer
helpful. Programmers in one language simply can't know what the
terminology means when applied to another language without learning
the behaviour in that other language before learning the terminology.

That means that Torsten's original question probably wasn't the one he
wanted to ask, and wasn't a useful one. The useful question is "what
is Python's parameter passing *behaviour^",
with a possible supplementary "what do they call that behaviour *in
the Python community*", recognising that if they asked "what is Java's
parameter passing *behaviour^",
with the supplementary "what do they call that behaviour *in the Java
community*" they would get much the same answer for the first question
(immutability is handled differently, I think, but it's there) but a
totally different answer to the second.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newby - is this what they are looking for ?? and is their a better a way

2009-02-24 Thread Tim Rowe
You're doing well so far. As Chris has said, you need to read the
later part of the question more carefully. A couple of other things:

1. 'input' might not be the best way to get the phrase, because the
user will have to put the phrase in quotes or the program will
(probably) crash. Have a look at raw_input.

2. A cosmetic thing. Your users will be happier if you put a space
after 'enter a phrase'

3. A "better way" might not be a better way for you. There's a very
Pythonic way of doing this using something called list comprehensions,
but they're almost certainly not what your tutor wants because they're
rather more advanced than the level you're working at. If it wasn't
for the requirement to put the acronym into the variable "letters",
the whole task could be done in one Python statement. Don't try that.
Keep it simple, the way you have been so far.

4. If you want to be a wise guy, ask your tutor why he/she got you to
convert the whole phrase to upper case, wasting a whole pile of
character conversion operations under the hood, because it's only the
acronym that needs to be converted :-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: try except question - serious foo bar question, and pulling my hair out :-)

2009-02-24 Thread Tim Rowe
2009/2/24 Grant Edwards :

> It works with a person as well as stuffed toys -- but trying to
> order a person on the internet gets you in a lot more trouble.
> It's also a little more embarassing when you realize your
> mistake in front of a person.  OTOH, sometimes a person will
> ask an enlightening question; but, sometimes they just make
> unhelpfull wisecracks.  It's a tough choice.

I used to use a baby, which avoids the embarrassment but can be just
as problematic to order on the internet.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient searching through objects

2009-02-26 Thread Tim Rowe
2009/2/26 sert :
> [email protected] wrote in
> news:[email protected]
> ups.com:
>
>> Try using a dict instead, where keys are the names and
>> objects the values (it turns a linear search in a quick
>> hash look up). . Then tell us the performance changes.
>>
>
> It halved the overall execution time. Thanks.

Good to see that you've already got an improvement. For what it's
worth, this seems to be classic relational database stuff, and a
relational database will be optimised to do these operations and so is
likely to be faster still. I think there are a couple that Python
works well with, but I've never looked into that -- others will no
doubt be along with recommendations now I've raised the subject.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: removing duplication from a huge list.

2009-02-27 Thread Tim Rowe
2009/2/27 odeits :

> How big of a list are we talking about? If the list is so big that the
> entire list cannot fit in memory at the same time this approach wont
> work e.g. removing duplicate lines from a very large file.

We were told in the original question: more than 15 million records,
and it won't all fit into memory. So your observation is pertinent.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: removing duplication from a huge list.

2009-02-27 Thread Tim Rowe
2009/2/27 Steve Holden :

> Assuming no duplicates, how does this help? You still have to verify
> collisions.
>
>> Pretty brutish and slow, but it's the first algorithm which comes to
>> mind. Of course, I'm assuming that the list items are long enough to
>> warrant using a hash and not the values themselves.
>>
> The problem is you can't guarantee any hash value will be unique, so
> ultimately you have to check whether list entries hashing to the same
> value are or are not equal. Which would mean either having the whole
> list in memory or having access to it via some other random access method.

You don't need random access to the whole list, just to the records
that collide on a hash. although you do end up using the external
storage as random access, which can be very slow, you've possibly
drastically reduced the number of such random accesses, which should
be a big saving. The best case is if the number of collisions is low
enough for the random access to be dealt with in buffering, avoiding
wasteful seeks of the external storage, in which case it's a complete
win. Remember that if the identical hashes are not collisions but
genuine duplicates you can throw them away as soon as they're checked,
so with some clever buffering you can stop them from clogging up the
buffer. The worst case is if there are a lot of genuine collisions, in
which case it's probably not a very good hash.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-02 Thread Tim Rowe
2009/3/1 Paul Rubin :
> Steve Holden  writes:
>> I'm not sure what you think the speed of Ruby has to do with Python.
>
> In the real world, people care about the relative speed of programs.

Yes, and they care about the cost of programs, and about the
functionality of programs. If I wanted fast code I wouldn't use Python
*or* Ruby (I'd probably use FORTH; C would be a more mainstream
choice) -- but don't expect the program soon. Even where speed does
matter, plain Python against plain Ruby isn't a meaningful comparison,
because a common style in Python (and probably in Ruby too) is to get
the code working, then if there are any *measured* bottlenecks to
optimise them in C++.  That means that in practice there won't be a
perceptible speed difference for the user.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Indentations and future evolution of languages

2009-03-06 Thread Tim Rowe
2009/3/6  :
> This is an interesting post, it shows me that fitness plateau where
> design of Python syntax lives is really small, you can't design
> something just similar:
>
> http://unlimitednovelty.com/2009/03/indentation-sensitivity-post-mortem.html

I don't think the article is right that "it's silly to have some
expression/statement groupings indentation based and some grouped by
enclosing tokens" -- provided it's done right. The OCAML-based
language F# accepts OCAML enclosing tokens, but if you mark the groups
with indentation they're not necessary (but still legal). That seems
to me to work pretty cleanly.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is python worth learning as a second language?

2009-03-09 Thread Tim Rowe
2009/3/9 ZikO :

> Do you think python would be good complementary language for C++? Do you
> think it's worth learning it or let's say try Java? and how difficult it
> would be for me if I know C++ pretty well I would say?

We're not exactly impartial advisors in here ;-)

I reckon Python and C++ make a good pairing, because:

- Python is far enough from C++ for each language to give you things
that the other doesn't (as opposed to Java; if I were still a C++
programmer I would only be interested in Java as a replacement for
C++, not to use alongside it);

- Python is far enough from C++ for you not to get confused over the
syntax; when I was learning Java I kept forgetting it wasn't C++ and
throwing in bits of C++ code! That never happened with Python

- Python integrates well with C++, at least for single-thread systems.

Python has a fairly shallow learning curve -- a reasonable programmer
can become productive in Python very quickly. For one programmer's
experience of learning Python have a look at
http://www.python.org/about/success/esr/ (although I grant that Eric
Raymond might count slightly higher than just a /reasonable/
programmer!)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6.1 - simple division

2009-03-09 Thread Tim Rowe
2009/3/8  :
>>>> 4 / 5.0
> 0.84
>>>> 0.8 * 5
> 4.0
>
> python 2.6.1 on mac. What the hell is going on here?

I know this has already been answered in detail, but one thing that
it's easy for those new to floating point issues to miss is that
fractions that can be expressed exactly in decimal can end up as
recurring decimals in binary. 0.8 looks nice and tidy, but in binary
(if I get this right) it's 0.1100110011001100..., recurring ad
infinitum. The computer has to truncate it somewhere.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Indentations and future evolution of languages

2009-03-10 Thread Tim Rowe
2009/3/8 Tim Roberts :
> Tim Rowe  wrote:
>>
>>I don't think the article is right that "it's silly to have some
>>expression/statement groupings indentation based and some grouped by
>>enclosing tokens" -- provided it's done right. The OCAML-based
>>language F# accepts OCAML enclosing tokens, but if you mark the groups
>>with indentation they're not necessary (but still legal). That seems
>>to me to work pretty cleanly.
>
> Boy, I really want to like F# -- a lot of smart people have worked on it --
> but every program I write is completely incomprehensible to me a week
> later.
>
> The more I look around, the more I like Python.

Indentation works just fine in Python, too, just in case anybody
hadn't noticed ;-)

My point was that Python isn't alone on that whitespace-significant
plateau. F# is up here too. And so is FORTRAN, of course. We try to
ignore FORTRAN, but the distance we are able to edge away from it goes
to show how big the plateau is.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-13 Thread Tim Rowe
2009/3/12 Raymond Hettinger :
> If anyone here is interested, here is a proposal I posted on the
> python-ideas list.
>
> The idea is to make numbering formatting a little easier with the new
> format() builtin
> in Py2.6 and Py3.0:  http://docs.python.org/library/string.html#formatspec

As far as I can see you're proposing an amendment to *encourage*
writing code that is not locale aware, with the amendment itself being
locale specific, which surely has to be a regressive move in the 21st
century. Frankly, I'd sooner see it made /harder/ to write code that
is not locale aware (warnings, like FxCop gives on .net code?) tnan
/easier/. Perhaps that's because I'm British, not American and I'm
sick of having date fields get the date wrong because the programmer
thinks the USA is the world. It makes me sympathetic to the problems
caused to others by programmers who think the English-speaking world
is the world.

By the way, to others who think that 123,456.7 and 123.456,7 are the
only conventions in common use in the West, no they're not. 123 456.7
is in common use in engineering, at least in Europe, precisely to
reduce (though not eliminate) problems caused by dot and comma
confusion..

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-13 Thread Tim Rowe
2009/3/13  :
> I think this proposal is more for debugging big numbers and meant mostly
> for programmers' eyes. We are already using the dot instead of comma
> decimal separator in our programming languages that one more
> Americanism won't kill us.

If it were for the programmers' eyes then it would be in the code, not
in the formatted output. Debugging of big numbers can be done by
checking within code, so there's no need to let this escape to the
output.

And if it's for programmers' eyes then the statement "The COMMA is
used when a PERIOD is the decimal separator" is wrong, at least if it
means that the COMMA is the /only/ separator used when a PERIOD is the
decimal separator. Ada uses UNDERSCOREs, which can be placed almost
anywhere in a numeric literal and are ignored.

And if it's mostly for programmers' eyes, why does the motivation
state that "Adding thousands separators is one of the simplest ways to
improve the professional appearance and readability of output exposed
to end users"? The proposal is clearly for the presentation of numbers
to end users, and quite simply is an encouragement to sloppiness in
presenting those numbers. If "Finance users and non-professional
programmers find the locale approach to be frustrating, arcane and
non-obvious" then by all means propose a way of making it simpler and
clearer, but not a bodge that will increase the amount of bad software
in the world.

-1 for all of the proposals.
-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-15 Thread Tim Rowe
2009/3/14 Hendrik van Rooyen :

> No account seems to be taken of the fact that the locale approach
> is a global one that forces uniformity on everything done on a PC
> or by a user.

Not so. Under .NET, for instance, the global settings will give you a
default CultureInfo class, but you can create your own CultureInfo
classes for other cultures in your program and use them in place of
the default.

> So when you want to make a report in a format that would suit
> what your foreign visitors are used to, do you have to change
> your server's locale, and change it back again afterwards, or what ?

No, you create a local locale and use that.

There are essentially three possible levels I can see for this:

- programs that will only ever be used in one locale, known in
advance. They can have the locale hard-wired into the program. No
special support is needed for this. It's pretty easy to write a
function to format a number to a hard-wired locale. I've done it in
Pascal and FORTH and it was easy-peasy, so I can't imagine it's going
to be a big deal in Python. If it's such a big deal for accountants to
write this code, if they ask in this forum how to do it somebody will
almost certainly supply a function that takes a float and returns a
formatted string within a few minutes. It might even be you or me.

- Programs that may be used in any unchanging locale. The existing
locale support is built for this case.

- Programs that nead to operate across locales. This can either be
managed by switching global locales (which you rightly deprecate) or
by managing alternate locales within the program.

> The locale approach has all the disadvantages of global variables.

No, it has all the advantages of global constants used as overridable
defaults for local variables.

> To make software usable by, or expandable to, different languages
> and cultures is a tricky design problem - you have to, at the
> minimum, do things like storing all your text, both for prompts and
> errors, in some kind of database and refer to it by its key, everywhere.
> You cannot simply assume, that because a number represents
> a monetary value, that it is Yen, or Australian Dollar, or whatever -
> you may have to convert it first, from its currency, to the currency
> that you want to display it as, and only then can you worry about
> the format that you want to display it in.

Nothing in the proposal being considered addresses any of that.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threads not Improving Performance in Program

2009-03-19 Thread Tim Rowe
> Thank you for your response. I did not realize that. That seems like a
> huge limitation for such a great language.
> I will look into forking off processes instead of using threads.

If that's what you need to do, yes it is. If it isn't, no it's not. No
language is optimum for all possible applications, each one has
different compromises. You've just discovered one of Python's.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-20 Thread Tim Rowe
2009/3/20 Hendrik van Rooyen :

> A joke based on the Monty Python series is BY DEFINITION not stupid!

But may get /too/ silly.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-01 Thread Tim Rowe
2009/4/1 Carl Banks :

> I am also an engineer, and I can tell your idea of intuitive is not
> universal, even among engineers.  I certainly do not lean toward one-
> based indexing.

Another engineer here who finds 0-based indexing more intuitive than
1-based indexing.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-02 Thread Tim Rowe
2009/4/1 一首诗 :
> Hi all,
>
> I am a programmer who works with some different kinds of programming
> languages, like python, C++(in COM), action script, C#, etc.
>
> Today, I realized that, what ever language I use, I always meet a same
> problem and I think I never solve it very well.
>
> The problem is : how to break my app into functional pieces?

One approach is to go through the specification of the program,
underline all of the significant nouns and try to implement each of
the nouns as a class. That won't take you all the way to a good design
-- some of the resulting classes will be too trivial, and it won't
give you the derived classes you need, but it's a good first step to
breaking a problem down, and might help break your one big class
habit.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does Python show the whole array?

2009-04-09 Thread Tim Rowe
2009/4/9 Miles :

> Clearly, any comparison with a boolean literal should be illegal.  ;)

Hey, we could have strict type checking at compile time of /all/
operations, couldn't we? Anybody care to join me over at the Ada list?
;-)

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-15 Thread Tim Rowe
2009/4/15 Deep_Feelings :
> I want to start programming a new program (electronic health care
> center) in python and before start learning python i wanna make sure
> that python does have all the features i need to accomplish this
> project so i wanna ask you does python able to support these
> features :
>
> 1- cross platform (windows + linux)
> 2- mysql database access
> 3- 2D graphs (curves)
> 4- support of international languages
> 5- can access a scanner and input pictures from it.
>
> and possibly be able to import data from labratory machines (such as
> CBC machines) to automatically register patient investigations result
> into the system (not mandatory)

What are the safety and security requirements? If you're handling
patient investigation results then there are certainly security issues
because of patient confidentiality, and there may be safety issues
(could a software fault contribute to a patient receiving incorrect
treatment, or failing to receive necessary treatment?)

You almost certainly need to contact the appropriate regulatory
authority to check whether they have any requirements for languages in
such applications (and for specific development processes), or you
could find yourself either with an application you can't use or a very
big lawsuit and possibly jail if it goes wrong.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-16 Thread Tim Rowe
2009/4/15 Rhodri James :

> That's not sufficient.  It isn't enough that your program works, it also
> has to satisfy the regulatory authorities otherwise (depending on what
> country you're in) you could end up on the wrong end of some very
> expensive law-suits without actually having done anything wrong.  Check
> first.

Quite -- but I'd add that if you haven't identified the safety
significance of the software, or haven't kept an audit trail to show
that you have applied techniques appropriate to the safety
significance, then you /have/ done something wrong.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-17 Thread Tim Rowe
2009/4/17 Michael Torrie :

> Spaghetti code can be written in *any* language.

I challenge you to write spahgetti code in SPARK!

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-18 Thread Tim Rowe
2009/4/17 Hyuga :

> I'm not too assured... What are the actual requirements for this
> software?  Is this intended for real world use in health care?  I'm
> not too comfortable with a single individual with apparently limited
> experience in Python developing something like that.

And limited experience in safety-related systems, if he thinks safety
can be tested in, after the event.

But of course it might be that the proposed system has gone through a
proper safety analysis, and it /might/ have been determined that there
are no safety or security risks with it, in which case there would be
no reason for him not to cut his Python teeth (fangs?) on it.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-18 Thread Tim Rowe
2009/4/18 norseman :

> "...only within the current procedure."   That was one of the "why Pascal
> didn't hang on" as long as it might have.

Really? I thought it was because of the lack of support for packaging,
which was solved in different ways by Object Pascal/Delphi and by
Modula 2, the latter of which in turn became Ada, which is still doing
pretty well in mission-critical contexts.

>  Another was it's COBAL structure
> in defining things. Just like today - the more typing the more errors, the
> longer to 'in service'.

Got any evidence for that? There's a lot of typing in Ada (it shows
its Pascal roots) but in all the studies I've seen Ada production code
has consistently shown fewer errors than the more concise C/C++ family
of languages.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-18 Thread Tim Rowe
2009/4/18 Aahz :

>   I had never previously heard that Modula-2 significantly
> influenced Ada, and the Wikipedia entry says nothing about it.  Do you
> have a cite?

Not in writing. I got it from a SPARK user group meeting many years
ago. SPARK is, of course a subset of Ada with some mandatory
structured comments, and is a successor to SPADE which was much the
same thing for Pascal. When somebody asked one of the SPARK team -- I
think it was Denton Clutterbuck -- why they'd gone from Pascal to Ada
rather than Modula2, he observed "If you look at the SPARK subset
you'll see that it pretty much *is* Modula2". So whether Modula2 was a
direct influence or not, it seems to have found its way in.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a programming language that is combination of Python and Basic?

2009-04-19 Thread Tim Rowe
2009/4/19 Steven D'Aprano :

> "GOTO, after all, is just a jump, and we use jumps in Python all the time:
>
> raise Exception
> break
> continue
> if... elif... else...
> for... else...
> etc."

So as a syllogism:
P1: GOTO is a jump;
P2: GOTO is bad.
C: Jumps are  bad.

And then by showing the conclusion is false, you believe you have
shown a contradiction? Try looking up "Affirming the consequent"!

GOTO is an /unstructured/ jump. Raise, break, continue, if, for and so
an are all /structured/ jumps.

-- 
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >