Re: Practice question

2014-10-09 Thread alister
On Mon, 06 Oct 2014 22:06:09 -0400, Seymore4Head wrote:

 On Tue, 7 Oct 2014 01:46:37 + (UTC), Denis McMahon
 denismfmcma...@gmail.com wrote:
 
On Sun, 05 Oct 2014 19:02:31 -0400, Seymore4Head wrote:

 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.

I think part of the problem here is that you don't understand the
expression.

The expression:

15 = x  30

contains two conditions:

15 = x

x  30

For the whole expression to be true, both conditions must be true, hence
the equivalence is:

(15 = x) and (x  30)

to test this in python command line, see if the two different
expressions give the same result for a suitable range of values of x:

for x in range(50):
if not (15 = x  30) == ((15 = x) and (x  30)):
print discrepancy

or

for x in range(50):
if (15 = x  30) == ((15 = x) and (x  30)):
print ok
 
 All of the practice questions up to this question had 4 answers.  With
 each question you could verify the correct answers by just copy and
 pasting each choice into Python.
 
 So when the instructions said I could verify this with Python I assumed
 there might be some way to test if the question was == to each answer.

no 
you need to type in each snippet of code  see if they give the same 
result when run.




-- 
In every non-trivial program there is at least one bug.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-08 Thread Rustom Mody
On Tuesday, October 7, 2014 2:19:39 AM UTC+5:30, Steven D'Aprano wrote:

 I have fewer issues with your conclusion and analogy than I do with the 
 basic premise that there is a connection between Seymore's problem here 
 and the use, or non-use, of print in the interactive interpreter. I don't 
 see how replacing interactive use and/or the use of print with functions 
 containing return statements would help Seymore.

The issue is not only that print is bad but that the interpreter is
good for learning and trying out.

Are these two really unconnected. Lets see... One can

- use print without the interpreter
- use the interpreter without print
- use both

But can one use neither? [Assuming telepathy/ESP etc is disallowed]

So pushing beginners away from print can push them up the learning 
curve more quickly
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-08 Thread Chris Angelico
On Thu, Oct 9, 2014 at 3:14 AM, Rustom Mody rustompm...@gmail.com wrote:
 The issue is not only that print is bad but that the interpreter is
 good for learning and trying out.

 Are these two really unconnected. Lets see... One can

 - use print without the interpreter
 - use the interpreter without print
 - use both

 But can one use neither? [Assuming telepathy/ESP etc is disallowed]

 So pushing beginners away from print can push them up the learning
 curve more quickly

(Please be more clear with your terminology; running Python scripts is
still using the interpreter, it's just not using *interactive* Python.
What you're saying above is all about Python's interactive mode.)

Your conclusion doesn't obviously follow from your preceding
statements. How does pushing people away from print push them up?
Which way is up? Is it up to move from interactive Python to
scripts run from the command line? Or is that down? How does the
avoidance of print push anyone anywhere, anyway?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-08 Thread Skip Montanaro
On Wed, Oct 8, 2014 at 11:14 AM, Rustom Mody rustompm...@gmail.com wrote:
 So pushing beginners away from print can push them up the learning
 curve more quickly

Or more quickly discourage them. I still use print for all sorts of
things. In my opinion, there is often no need for fancy loggers,
str.format, or the write method of file-like objects. Print will often
get you a good enough result faster than the other means.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-08 Thread Rustom Mody
On Wednesday, October 8, 2014 9:58:11 PM UTC+5:30, Skip Montanaro wrote:
 On Wed, Oct 8, 2014 at 11:14 AM, Rustom Mody  wrote:
  So pushing beginners away from print can push them up the learning
  curve more quickly

 Or more quickly discourage them. I still use print for all sorts of
 things. In my opinion, there is often no need for fancy loggers,
 str.format, or the write method of file-like objects. Print will often
 get you a good enough result faster than the other means.

Well I'm not talking of people like you!!
Nor of more sophisticated tools than print.

I am talking of the fact that an absolute basic sine qua non for
beginners is to be able to structure programs:

- breaking up a complex expression into sub-expressions
- abstracting out a sub-expression into a function with an appropriate
  parameterization
- inverses of the above when the current cut is sub-optimal

etc etc... what is nowadays fashionably called 'refactoring'

And for that the noob needs to learn to write return-ing function
where he currently writes a print-ing function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-07 Thread Steven D'Aprano
On Sun, 05 Oct 2014 20:07:50 -0400, Seymore4Head wrote:

 Here is the exact question, I was trying to post something similar.  I
 failed.
 
 http://i.imgur.com/iUGh4xf.jpg

Please don't post screen shots if you can avoid it. You almost certainly 
can copy and paste the text from the web page. And if you can't, you can 
usually re-type the question. It's good practice to strength your typing 
skills.

Screen shots cannot be read by people using a screen reader, or who don't 
have access to the web (but are reading their mail), or if the host site 
(in this case, imgur) is down or blocked.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-07 Thread Steven D'Aprano
On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote:

 I think I get it now.  You are using a sample of answers.  So you could
 actually just run through them all.  (I haven't tried this yet)
 
 for x in range(lo,hi)
  print((15 = x  30) == (15= x and x 30))

Yes, except using print is probably not the best idea, since you might 
have dozens of True True True True ... printed, one per line, and if you 
blink the odd False might have scrolled off screen before you notice.

With two numbers, 15 and 30, all you really need is five test cases:

- a number lower than the smaller of the two numbers (say, 7);
- a number equal to the smaller of the two numbers (that is, 15);
- a number between the two numbers (say, 21);
- a number equal to the larger of the two numbers (that is, 30);
- a number higher than the larger of the two numbers (say, 999);


The exact numbers don't matter, so long as you test all five cases. And 
rather than printing True True True... let's use assert instead:


for x in (7, 15, 21, 30, 999):
assert (15 = x  30) == (15= x and x 30)


If the two cases are equal, assert will do nothing. But if they are 
unequal, assert will raise an exception and stop, and you know that the 
two cases are not equivalent and can go on to the next possibility.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-07 Thread C Smith
Steven D'Aprano wrote:
With two numbers, 15 and 30, all you really need is five test cases:

My solution assumed integers also, but after I posted it, I thought:
What about floating points?

On Tue, Oct 7, 2014 at 1:48 AM, Steven D'Aprano st...@pearwood.info wrote:
 On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote:

 I think I get it now.  You are using a sample of answers.  So you could
 actually just run through them all.  (I haven't tried this yet)

 for x in range(lo,hi)
  print((15 = x  30) == (15= x and x 30))

 Yes, except using print is probably not the best idea, since you might
 have dozens of True True True True ... printed, one per line, and if you
 blink the odd False might have scrolled off screen before you notice.

 With two numbers, 15 and 30, all you really need is five test cases:

 - a number lower than the smaller of the two numbers (say, 7);
 - a number equal to the smaller of the two numbers (that is, 15);
 - a number between the two numbers (say, 21);
 - a number equal to the larger of the two numbers (that is, 30);
 - a number higher than the larger of the two numbers (say, 999);


 The exact numbers don't matter, so long as you test all five cases. And
 rather than printing True True True... let's use assert instead:


 for x in (7, 15, 21, 30, 999):
 assert (15 = x  30) == (15= x and x 30)


 If the two cases are equal, assert will do nothing. But if they are
 unequal, assert will raise an exception and stop, and you know that the
 two cases are not equivalent and can go on to the next possibility.


 --
 Steven
 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread C Smith
14x=29

On Sun, Oct 5, 2014 at 4:14 PM, Ned Batchelder n...@nedbatchelder.com wrote:
 On 10/5/14 7:02 PM, Seymore4Head wrote:

 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.
 So the right answer is 15= x or x 30


 No, 15 = x  30 is equivalent to 15 = x and x  30.

 but one of the other answers is
 not (15= x and x 30)


 You are speaking ambiguously.  Which did you mean:
 a) one of the other answers isn't 15 = x and x  30, or:
 b) one of the other answers is not (15 = x and x  30) ?

 --
 Ned Batchelder, http://nedbatchelder.com

 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Skip Montanaro
On Sun, Oct 5, 2014 at 9:47 PM, Rustom Mody rustompm...@gmail.com wrote:
 Sorry Seymore if this sounds condescending -- its not a complaint
 against you but against those who treat the print statement/expression as
 kosher for newbies.

So if you're not griping about Seymore's original post, are you
griping about my response? It was the one you quoted. And what's with
the comparison between use of the print statement and driving on the
wrong side of the road?

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Rustom Mody
On Monday, October 6, 2014 6:34:27 PM UTC+5:30, Skip Montanaro wrote:
 On Sun, Oct 5, 2014 at 9:47 PM, Rustom Mody  wrote:
  Sorry Seymore if this sounds condescending -- its not a complaint
  against you but against those who treat the print statement/expression as
  kosher for newbies.

 So if you're not griping about Seymore's original post, are you
 griping about my response? It was the one you quoted.

It so happened you were the person to note that here was a question(er)
needing instruction about using the interpreter. Nothing wrong with the 
answer (or the question). Something wrong with the point at which it emerges.

 And what's with the comparison between use of the print statement
 and driving on the wrong side of the road?

Consider the sequence:

1. Drives on the wrong side of the road
2. Has no clue that there's such a concept as 'wrong side of road'
3. Teaches people to drive without conveying anything about 'wrong side of road'

Hopefully you will agree that 1  2  3??

My gripe is with 3
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Chris Angelico
On Tue, Oct 7, 2014 at 3:23 AM, Rustom Mody rustompm...@gmail.com wrote:
 Consider the sequence:

 1. Drives on the wrong side of the road
 2. Has no clue that there's such a concept as 'wrong side of road'
 3. Teaches people to drive without conveying anything about 'wrong side of 
 road'

 Hopefully you will agree that 1  2  3??

 My gripe is with 3

No, I don't agree. Teaching people to drive is separate from teaching
road rules, which vary by legislature. I can draw the exact same
analogy:

1. Fails to follow proper protocol at a hook turn intersection
2. Has no clue that there's such a concept as a hook turn
3. Teaches people to drive without conveying anything about hook turns.

Most of you are probably in state 2, and your instructors were
probably in state 3. Neither's a problem, because hook turns don't
matter until you come to an intersection where they're used. (And even
then, there's often signage.)

The complaints you're making are about something that does not matter.
There are multiple usage patterns for Python; one is to eschew the
interactive interpreter and run everything from scripts. That's fine,
there's nothing wrong with it. And then, the nuances of interactive
Python are completely insignificant.

I don't see that your complaints about print and interactive mode have
anything at all to do with this thread.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Rustom Mody
On Monday, October 6, 2014 10:22:27 PM UTC+5:30, Chris Angelico wrote:
 On Tue, Oct 7, 2014 at 3:23 AM, Rustom Mody wrote:
  Consider the sequence:
  1. Drives on the wrong side of the road
  2. Has no clue that there's such a concept as 'wrong side of road'
  3. Teaches people to drive without conveying anything about 'wrong side of 
  road'
  Hopefully you will agree that 1  2  3??
  My gripe is with 3

 No, I don't agree.

Interesting

So you dont agree with: 123 ?

Or with My gripe is 3  ?

The second would be quite bizarre:

I have a headache...

Sorry. But I dont agree with that
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Chris Angelico
On Tue, Oct 7, 2014 at 4:05 AM, Rustom Mody rustompm...@gmail.com wrote:
 On Monday, October 6, 2014 10:22:27 PM UTC+5:30, Chris Angelico wrote:
 On Tue, Oct 7, 2014 at 3:23 AM, Rustom Mody wrote:
  Consider the sequence:
  1. Drives on the wrong side of the road
  2. Has no clue that there's such a concept as 'wrong side of road'
  3. Teaches people to drive without conveying anything about 'wrong side of 
  road'
  Hopefully you will agree that 1  2  3??
  My gripe is with 3

 No, I don't agree.

 Interesting

 So you dont agree with: 123 ?

 Or with My gripe is 3  ?

 The second would be quite bizarre:

 I have a headache...

 Sorry. But I dont agree with that

Well, hey, I've eaten things that disagreed with me. You'd think that
would be purely factual. I ate you! I disagree!.

But no, it was the 1  2  3 part that I disagreed with... as I'm
sure you were aware. Never let the obvious truth of something get in
the way of a good joke :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Steven D'Aprano
On Mon, 06 Oct 2014 10:05:40 -0700, Rustom Mody wrote:

 On Monday, October 6, 2014 10:22:27 PM UTC+5:30, Chris Angelico wrote:
 On Tue, Oct 7, 2014 at 3:23 AM, Rustom Mody wrote:
  Consider the sequence:
  1. Drives on the wrong side of the road 2. Has no clue that there's
  such a concept as 'wrong side of road' 3. Teaches people to drive
  without conveying anything about 'wrong side of road' Hopefully you
  will agree that 1  2  3?? My gripe is with 3
 
 No, I don't agree.
 
 Interesting
 
 So you dont agree with: 123 ?

I can't speak for Chris, by my answer is neither Yes nor No, but Mu.

http://en.wikipedia.org/wiki/Mu_%28negative%29#In_popular_culture


I don't understand what semantics you are giving the  symbol. It's not 
less than, since statements 1, 2 and 3 above don't have a total order 
or even a partial order. What does it mean to say that Drives on the 
wrong side of the road is less than Teaches people to drive without 
conveying anything about 'wrong side of road'? Less than in what sense? 
Alphabetical order? Less dangerous? Less competent? Less annoying? Less 
expensive?

So, no, I don't agree. Nor do I disagree.

I have fewer issues with your conclusion and analogy than I do with the 
basic premise that there is a connection between Seymore's problem here 
and the use, or non-use, of print in the interactive interpreter. I don't 
see how replacing interactive use and/or the use of print with functions 
containing return statements would help Seymore.



 Or with My gripe is 3  ?
 
 The second would be quite bizarre:

If it's bizarre, why do you consider that Chris may mean that? The 
reasonable thing would be to reject it from contention.


 I have a headache...
 
 Sorry. But I dont agree with that


I don't agree that you have a headache. You're obviously lying, acting, 
delusional, an insentient robot programmed to repeat the words 'I have a 
headache', a zombie (not the brain eating kind, the philosophical kind), 
a sophisticated bot (but not sophisticated enough to pass the Turing 
test), or otherwise faking it.

I'm just sayin'...



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Redge @ Versalytics.com

 On Oct 6, 2014, at 4:49 PM, Steven D'Aprano st...@pearwood.info wrote:
 
 On Mon, 06 Oct 2014 10:05:40 -0700, Rustom Mody wrote:
 
 On Monday, October 6, 2014 10:22:27 PM UTC+5:30, Chris Angelico wrote:
 On Tue, Oct 7, 2014 at 3:23 AM, Rustom Mody wrote:
 Consider the sequence:
 1. Drives on the wrong side of the road 2. Has no clue that there's
 such a concept as 'wrong side of road' 3. Teaches people to drive
 without conveying anything about 'wrong side of road' Hopefully you
 will agree that 1  2  3?? My gripe is with 3
 
 No, I don't agree.
 
 Interesting
 
 So you dont agree with: 123 ?
 
 I can't speak for Chris, by my answer is neither Yes nor No, but Mu.
 
 http://en.wikipedia.org/wiki/Mu_%28negative%29#In_popular_culture
 
 
 I don't understand what semantics you are giving the  symbol. It's not 
 less than, since statements 1, 2 and 3 above don't have a total order 
 or even a partial order. What does it mean to say that Drives on the 
 wrong side of the road is less than Teaches people to drive without 
 conveying anything about 'wrong side of road'? Less than in what sense? 
 Alphabetical order? Less dangerous? Less competent? Less annoying? Less 
 expensive?
 
 So, no, I don't agree. Nor do I disagree.
 
 I have fewer issues with your conclusion and analogy than I do with the 
 basic premise that there is a connection between Seymore's problem here 
 and the use, or non-use, of print in the interactive interpreter. I don't 
 see how replacing interactive use and/or the use of print with functions 
 containing return statements would help Seymore.
 
 
 
 Or with My gripe is 3  ?
 
 The second would be quite bizarre:
 
 If it's bizarre, why do you consider that Chris may mean that? The 
 reasonable thing would be to reject it from contention.
 
 
 I have a headache...
 
 Sorry. But I dont agree with that
 
 
 I don't agree that you have a headache. You're obviously lying, acting, 
 delusional, an insentient robot programmed to repeat the words 'I have a 
 headache', a zombie (not the brain eating kind, the philosophical kind), 
 a sophisticated bot (but not sophisticated enough to pass the Turing 
 test), or otherwise faking it.
 
 I'm just sayin'...
 
 
 
 -- 
 Steven
 -- 
 I agree that 123.  From a numerical point of view this is correct.  The 
 distraction here is the inference that the numbers somehow relate to the 
 statements preceding this conclusion.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Denis McMahon
On Sun, 05 Oct 2014 19:02:31 -0400, Seymore4Head wrote:

 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.

I think part of the problem here is that you don't understand the 
expression.

The expression:

15 = x  30

contains two conditions:

15 = x

x  30

For the whole expression to be true, both conditions must be true, hence 
the equivalence is:

(15 = x) and (x  30)

to test this in python command line, see if the two different expressions 
give the same result for a suitable range of values of x:

for x in range(50):
if not (15 = x  30) == ((15 = x) and (x  30)):
print discrepancy

or

for x in range(50):
if (15 = x  30) == ((15 = x) and (x  30)):
print ok

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-06 Thread Seymore4Head
On Tue, 7 Oct 2014 01:46:37 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Sun, 05 Oct 2014 19:02:31 -0400, Seymore4Head wrote:

 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.

I think part of the problem here is that you don't understand the 
expression.

The expression:

15 = x  30

contains two conditions:

15 = x

x  30

For the whole expression to be true, both conditions must be true, hence 
the equivalence is:

(15 = x) and (x  30)

to test this in python command line, see if the two different expressions 
give the same result for a suitable range of values of x:

for x in range(50):
if not (15 = x  30) == ((15 = x) and (x  30)):
print discrepancy

or

for x in range(50):
if (15 = x  30) == ((15 = x) and (x  30)):
print ok

All of the practice questions up to this question had 4 answers.  With
each question you could verify the correct answers by just copy and
pasting each choice into Python.

So when the instructions said I could verify this with Python I
assumed there might be some way to test if the question was == to each
answer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Practice question

2014-10-05 Thread Seymore4Head
For the record, I don't want a hint.  I want the answer.
I see a practice question is similar to this.
15 = x  30  And it wants a similar expression that is equivalent.
So the right answer is 15= x or x 30
but one of the other answers is 
not (15= x and x 30)

But it says.remember you can try this out in the Python shell.
How?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Roy Smith
In article h2j33adothf9uctcdp5psqk2cclr019...@4ax.com,
 Seymore4Head Seymore4Head@Hotmail.invalid wrote:

 For the record, I don't want a hint.  I want the answer.

42.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Ned Batchelder

On 10/5/14 7:02 PM, Seymore4Head wrote:

For the record, I don't want a hint.  I want the answer.
I see a practice question is similar to this.
15 = x  30  And it wants a similar expression that is equivalent.
So the right answer is 15= x or x 30


No, 15 = x  30 is equivalent to 15 = x and x  30.


but one of the other answers is
not (15= x and x 30)


You are speaking ambiguously.  Which did you mean:
a) one of the other answers isn't 15 = x and x  30, or:
b) one of the other answers is not (15 = x and x  30) ?

--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Skip Montanaro
On Oct 5, 2014 6:07 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote:

 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.

Maybe

30  x = 15

? Seems more similar to the original expression than the other
possibilities.

As to how to try it out, bring up the Python prompt, assign various values
to x, and keep evaluating the possibilities. To simplify evaluation off a
bunch of alternatives, consider defining a function which takes x add a
parameter and print out the various expression values. I'd give a concrete
example, but don't has a prompt available on my phone...

Just my 2¢...

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Terry Reedy

On 10/5/2014 7:02 PM, Seymore4Head wrote:

For the record, I don't want a hint.  I want the answer.
I see a practice question is similar to this.
15 = x  30  And it wants a similar expression that is equivalent.
So the right answer is 15= x or x 30
but one of the other answers is
not (15= x and x 30)

But it says.remember you can try this out in the Python shell.
How?


For instance,
for x in (10, 20, 30, 40):
print((15 = x  30) == (15= x and x 30))



--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Seymore4Head
On Sun, 05 Oct 2014 19:14:27 -0400, Ned Batchelder
n...@nedbatchelder.com wrote:

On 10/5/14 7:02 PM, Seymore4Head wrote:
 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.
 So the right answer is 15= x or x 30

No, 15 = x  30 is equivalent to 15 = x and x  30.

 but one of the other answers is
 not (15= x and x 30)

You are speaking ambiguously.  Which did you mean:
a) one of the other answers isn't 15 = x and x  30, or:
b) one of the other answers is not (15 = x and x  30) ?

Here is the exact question, I was trying to post something similar.  I
failed.

http://i.imgur.com/iUGh4xf.jpg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Seymore4Head
On Sun, 05 Oct 2014 19:47:40 -0400, Terry Reedy tjre...@udel.edu
wrote:

On 10/5/2014 7:02 PM, Seymore4Head wrote:
 For the record, I don't want a hint.  I want the answer.
 I see a practice question is similar to this.
 15 = x  30  And it wants a similar expression that is equivalent.
 So the right answer is 15= x or x 30
 but one of the other answers is
 not (15= x and x 30)

 But it says.remember you can try this out in the Python shell.
 How?

For instance,
for x in (10, 20, 30, 40):
 print((15 = x  30) == (15= x and x 30))

I think I get it now.  You are using a sample of answers.  So you
could actually just run through them all.  (I haven't tried this yet)

for x in range(lo,hi)
 print((15 = x  30) == (15= x and x 30))

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Ned Batchelder

On 10/5/14 8:07 PM, Seymore4Head wrote:

On Sun, 05 Oct 2014 19:14:27 -0400, Ned Batchelder
n...@nedbatchelder.com wrote:


On 10/5/14 7:02 PM, Seymore4Head wrote:

For the record, I don't want a hint.  I want the answer.
I see a practice question is similar to this.
15 = x  30  And it wants a similar expression that is equivalent.
So the right answer is 15= x or x 30


No, 15 = x  30 is equivalent to 15 = x and x  30.


but one of the other answers is
not (15= x and x 30)


You are speaking ambiguously.  Which did you mean:
a) one of the other answers isn't 15 = x and x  30, or:
b) one of the other answers is not (15 = x and x  30) ?


Here is the exact question, I was trying to post something similar.  I
failed.

http://i.imgur.com/iUGh4xf.jpg



Why isn't the fourth one correct?

--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-05 Thread Rustom Mody
On Monday, October 6, 2014 5:04:11 AM UTC+5:30, Skip Montanaro wrote:
 On Oct 5, 2014 6:07 PM, Seymore4Head wrote:
  For the record, I don't want a hint.  I want the answer.
  I see a practice question is similar to this.
  15 = x  30  And it wants a similar expression that is equivalent.
 Maybe
     30  x = 15
 ? Seems more similar to the original expression than the other 
 possibilities.

 As to how to try it out, bring up the Python prompt, assign various
 values to x, and keep evaluating the possibilities. To simplify
 evaluation off a bunch of alternatives, consider defining a function
 which takes x add a parameter and print out the various expression
 values. I'd give a concrete example, but don't has a prompt
 available on my phone...


An interesting data-point.
We have a here a poster who's asked some 20 or so python questions
and still seems not to know how to use the interpreter interactively.

Sorry Seymore if this sounds condescending -- its not a complaint
against you but against those who treat the print statement/expression as
kosher for newbies. Imagine someone who has driven a car for a month but has
no clue about the basic rule of keep-left (or right).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-06 Thread Jean-Michel Pichavant
- Original Message -
 
 [...]
  By the way, did someone ever notice that r'\' fails ? I'm sure
  there's a
  reason for that... (python 2.5) Anyone knows ?
  
  r'\'
  SyntaxError: EOL while scanning single-quoted string
  
 
 Even in a raw string, string quotes can be escaped with a backslash,
 but the backslash remains in the string; for example, r\ is a
 valid
 string literal consisting of two characters: a backslash and a double
 quote; r\ is not a valid string literal (even a raw string cannot
 end
 in an odd number of backslashes). Specifically, a raw string cannot
 end
 in a single backslash (since the backslash would escape the following
 quote character).  -- python docs
 --
 http://mail.python.org/mailman/listinfo/python-list
 

Thanks for the pointer.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-05 Thread Dave Angel

On 02/04/2013 11:23 PM, Anthony Correia wrote:

Just started learning Python.  I just wrote a simple copy files script. I use 
Powershell now as my main scripting language but I wanted to extend into the 
linux platform as well.  Is this the best way to do it?

import os

 objdir = (C:\\temp2)
 colDir = os.listdir(objdir)
 for f in colDir:
 activefile = os.path.join(objdir + \\ + f)
 print (Removing  + activefile +  from  + objdir)
 os.remove(activefile)

In Powershell I would do this:

$colDir = gci -path c:\temp2
$objDir = C:\temp3
ForEach($file in $colDir){
 #.Fullname lists the directory and filename together.  No need to do a join
 #beforehand.
 Copy-item $file.fullname -destination $objDir
}



You started two nearly-identical threads, with nearly the same content. 
 I won't repeat the comments already posted in the other thread, but 
notice that your powershell script copies the file, while your Python 
translation deletes the file.  Big difference.


Next, you should use raw strings, or at least use the forward slash, 
rather than double backslashes in file path literals.




--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-05 Thread Jean-Michel Pichavant


- Original Message -
 On 02/04/2013 11:23 PM, Anthony Correia wrote:
  Just started learning Python.  I just wrote a simple copy files
  script. I use Powershell now as my main scripting language but I
  wanted to extend into the linux platform as well.  Is this the
  best way to do it?
 
  import os
 
   objdir = (C:\\temp2)
   colDir = os.listdir(objdir)
   for f in colDir:
   activefile = os.path.join(objdir + \\ + f)
   print (Removing  + activefile +  from  + objdir)
   os.remove(activefile)
 
  In Powershell I would do this:
 
  $colDir = gci -path c:\temp2
  $objDir = C:\temp3
  ForEach($file in $colDir){
   #.Fullname lists the directory and filename together.  No need
   to do a join
   #beforehand.
   Copy-item $file.fullname -destination $objDir
  }
 
 
 You started two nearly-identical threads, with nearly the same
 content.
   I won't repeat the comments already posted in the other thread, but
 notice that your powershell script copies the file, while your Python
 translation deletes the file.  Big difference.
 
 Next, you should use raw strings, or at least use the forward slash,
 rather than double backslashes in file path literals.
 
 
 
 --
 DaveA

He must have hit the send button too early by mistake.
By the way, did someone ever notice that r'\' fails ? I'm sure there's a reason 
for that... (python 2.5) Anyone knows ?

r'\'
SyntaxError: EOL while scanning single-quoted string

r'\b'
'\\b'


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-05 Thread Albert Hopkins

[...]
 By the way, did someone ever notice that r'\' fails ? I'm sure there's a
 reason for that... (python 2.5) Anyone knows ?
 
 r'\'
 SyntaxError: EOL while scanning single-quoted string
 

Even in a raw string, string quotes can be escaped with a backslash,
but the backslash remains in the string; for example, r\ is a valid
string literal consisting of two characters: a backslash and a double
quote; r\ is not a valid string literal (even a raw string cannot end
in an odd number of backslashes). Specifically, a raw string cannot end
in a single backslash (since the backslash would escape the following
quote character).  -- python docs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-05 Thread python . list
On Tue, 5 Feb 2013 15:32:32 +0100 (CET), Jean-Michel Pichavant wrote:
 By the way, did someone ever notice that r'\' fails ? I'm sure
 there's a reason for that... (python 2.5) Anyone knows ?
 
 r'\'
 SyntaxError: EOL while scanning single-quoted string

I hit this all the time with Vim's path-completion (:help
i_CTRL-X_CTRL-F) on Win32 which puts a trailing \ on
directory-names.  I just need to remember to remove it, a task made
easier because the syntax highlighting correctly shows how Python
interprets it (i.e., the string is still continued).

-tkc


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


Re: Best Practice Question

2013-02-05 Thread Anthony Correia
On Tuesday, February 5, 2013 10:17:54 AM UTC-5, pytho...@tim.thechases.com 
wrote:
 On Tue, 5 Feb 2013 15:32:32 +0100 (CET), Jean-Michel Pichavant wrote:
 
  By the way, did someone ever notice that r'\' fails ? I'm sure
 
  there's a reason for that... (python 2.5) Anyone knows ?
 
  
 
  r'\'
 
  SyntaxError: EOL while scanning single-quoted string
 
 
 
 I hit this all the time with Vim's path-completion (:help
 
 i_CTRL-X_CTRL-F) on Win32 which puts a trailing \ on
 
 directory-names.  I just need to remember to remove it, a task made
 
 easier because the syntax highlighting correctly shows how Python
 
 interprets it (i.e., the string is still continued).
 
 
 
 -tkc

Sorry about that I hit the touchpad on my laptop by mistake.  Beside the using  
single '\' vs a double '\\' does that look ok?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-05 Thread Joel Goldstick
On Tue, Feb 5, 2013 at 11:40 AM, Anthony Correia akcorr...@gmail.comwrote:

 On Tuesday, February 5, 2013 10:17:54 AM UTC-5, 
 pytho...@tim.thechases.comwrote:
  On Tue, 5 Feb 2013 15:32:32 +0100 (CET), Jean-Michel Pichavant wrote:
 
   By the way, did someone ever notice that r'\' fails ? I'm sure
 
   there's a reason for that... (python 2.5) Anyone knows ?
 
  
 
   r'\'
 
   SyntaxError: EOL while scanning single-quoted string
 
 
 
  I hit this all the time with Vim's path-completion (:help
 
  i_CTRL-X_CTRL-F) on Win32 which puts a trailing \ on
 
  directory-names.  I just need to remember to remove it, a task made
 
  easier because the syntax highlighting correctly shows how Python
 
  interprets it (i.e., the string is still continued).
 
 
 
  -tkc

 Sorry about that I hit the touchpad on my laptop by mistake.  Beside the
 using  single '\' vs a double '\\' does that look ok?
 --
 http://mail.python.org/mailman/listinfo/python-list


according to the docs for os.path.join, you don't need the backslash stuff
at all.  Python knows the correct separator for your os and inserts it
accordingling:
I'm on linux:

 import os
 p = os.path.join('bob', 'bill')
 p
'bob/bill'



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Practice Question

2013-02-05 Thread Dave Angel

On 02/05/2013 11:53 AM, Joel Goldstick wrote:

On Tue, Feb 5, 2013 at 11:40 AM, Anthony Correia akcorr...@gmail.comwrote:


On Tuesday, February 5, 2013 10:17:54 AM UTC-5, pytho...@tim.thechases.comwrote:

On Tue, 5 Feb 2013 15:32:32 +0100 (CET), Jean-Michel Pichavant wrote:


By the way, did someone ever notice that r'\' fails ? I'm sure



there's a reason for that... (python 2.5) Anyone knows ?







r'\'



SyntaxError: EOL while scanning single-quoted string




I hit this all the time with Vim's path-completion (:help

i_CTRL-X_CTRL-F) on Win32 which puts a trailing \ on

directory-names.  I just need to remember to remove it, a task made

easier because the syntax highlighting correctly shows how Python

interprets it (i.e., the string is still continued).



-tkc


Sorry about that I hit the touchpad on my laptop by mistake.  Beside the
using  single '\' vs a double '\\' does that look ok?
--
http://mail.python.org/mailman/listinfo/python-list



according to the docs for os.path.join, you don't need the backslash stuff
at all.  Python knows the correct separator for your os and inserts it
accordingling:
I'm on linux:


import os
p = os.path.join('bob', 'bill')
p

'bob/bill'






Worse than that, the code as posted by the OP used string concatenation 
before calling  os.path.join(), and the latter method does nothing at 
all, when presented with a single string.




--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Best Practice Question

2013-02-04 Thread Anthony Correia
Just started learning Python.  I just wrote a simple copy files script. I use 
Powershell now as my main scripting language but I wanted to extend into the 
linux platform as well.  Is this the best way to do it?

import os 

objdir = (C:\\temp2) 
colDir = os.listdir(objdir) 
for f in colDir: 
activefile = os.path.join(objdir + \\ + f) 
print (Removing  + activefile +  from  + objdir) 
os.remove(activefile) 

In Powershell I would do this: 

$colDir = gci -path c:\temp2
$objDir = C:\temp3
ForEach($file in $colDir){
#.Fullname lists the directory and filename together.  No need to do a join
#beforehand.
Copy-item $file.fullname -destination $objDir
}
-- 
http://mail.python.org/mailman/listinfo/python-list


distutils + mercurial good practice question

2012-02-22 Thread Steven D'Aprano
distutils generates a number of files automatically in my projects, 
including MANIFEST, build/* and dist/* 

Is there any reason why I would want or need to track them in mercurial?

I currently have this .hgignore file:

syntax: glob
*.pyc
*~
exclude/*
build/*
dist/*
MANIFEST


Good practice or bad practice?


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-schema 'best practice' question

2008-09-20 Thread Frank Millman
On Sep 18, 8:28 am, Frank Millman [EMAIL PROTECTED] wrote:
 Hi all

 This is not strictly a Python question, but as I am writing in Python,
 and as I know there are some XML gurus on this list, I hope it is
 appropriate here.

 XML-schemas are used to define the structure of an xml document, and
 to validate that a particular document conforms to the schema. They
 can also be used to transform the document, by filling in missing
 attributes with default values.

[..]

 Or maybe the best practice is to *always* validate a document before
 processing it.


I have realised that my question was irrelevant.

xml's raison d'etre is to facilitate the exchange of information
between separate entities. If I want to use xml as a method of
serialisation within my own system, I can do what I like, but there
can be no question of 'best practice' in this situation.

When xml is used as intended, and you want to process a document
received from a third party, there is no doubt that you should always
validate it first before processing it. Thank you, Lorenzo, for
pointing out the obvious. It may take me a while to catch up, but at
least I can see things a little more clearly now.

As to why I am using xml at all, I know that there is a serious side
to Skip's light-hearted comment, so I will try to explain.

I want to introduce an element of workflow management (aka Business
Process Management) into the business/accounting system I am
developing. I used google to try to find out what the current state of
the art is. After several months of very confusing research, this is
the present situation, as best as I can figure it out.

There is an OMG spec called BPMN, for Business Process Modeling
Notation. It provides a graphical notation, intended to be readily
understandable by all business users, from business analysts, to
technical developers, to those responsible for actually managing and
monitoring the processes. Powerful though it is, it does not provide a
standard method of serialsing the diagram, so there is no standard way
of exchanging a diagram between different vendors, or of using it as
input to a workflow engine.

There is an OASIS spec called WS-BPEL, for Web Services Business
Process Execution Language. It defines a language for specifying
business process behavior based on Web Services. This does have a
formal xml-based specification. However, it only covers processes
invoked via web services - it does not cover workflow-type processes
within an organisation. To try to fill this gap, a few vendors got
together and submitted a draft specification called BPEL4People. This
proposes a series of extensions to the WS-BPEL spec. It is still at
the evaluation stage.

The BPMN spec includes a section which attempts to provide a mapping
between BPMN and BPEL, but the authors state that there are areas of
incompatibility, so it is not a perfect mapping.

Eventually I would like to make sense of all this, but for now I want
to focus on BPMN, and ignore BPEL. I can use wxPython to design a BPMN
diagram, but I have to invent my own method of serialising it so that
I can use it to drive the business process. For good or ill, I decided
to use xml, as it seems to offer the best chance of keeping up with
the various specifications as they evolve.

I don't know if this is of any interest to anyone, but it was
therapeutic for me to try to organise my thoughts and get them down on
paper. I am not expecting any comments, but if anyone has any thoughts
to toss in, I will read them with interest.

Thanks

Frank
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML-schema 'best practice' question

2008-09-20 Thread Lorenzo Gatti
On 20 Set, 07:59, Frank Millman [EMAIL PROTECTED] wrote:

 I want to introduce an element of workflow management (aka Business
 Process Management) into the business/accounting system I am
 developing. I used google to try to find out what the current state of
 the art is. After several months of very confusing research, this is
 the present situation, as best as I can figure it out.

What is the state of the art of existing, working software? Can you
leverage it instead of starting from scratch? For example, the
existing functionality of your accounting software can be reorganized
as a suite of components, web services etc. that can be embedded in
workflow definitions, and/or executing a workflow engine can become a
command in your application.

 There is an OMG spec called BPMN, for Business Process Modeling
 Notation. It provides a graphical notation
[snip]
 there is no standard way
 of exchanging a diagram between different vendors, or of using it as
 input to a workflow engine.

So BPMN is mere theory. This spec might be a reference for
evaluating actual systems, but not a standard itself.

 There is an OASIS spec called WS-BPEL, for Web Services Business
 Process Execution Language. It defines a language for specifying
 business process behavior based on Web Services. This does have a
 formal xml-based specification. However, it only covers processes
 invoked via web services - it does not cover workflow-type processes
 within an organisation. To try to fill this gap, a few vendors got
 together and submitted a draft specification called BPEL4People. This
 proposes a series of extensions to the WS-BPEL spec. It is still at
 the evaluation stage.

Some customers pay good money for buzzword compliance, but are you
sure you want to be so bleeding edge that you care not only for WS-
something specifications, but for evaluation stage ones?

There is no need to wait for BPEL4People before designing workflow
systems with human editing, approval, etc.
Try looking into case studies of how BPEL is actually used in
practice.

 The BPMN spec includes a section which attempts to provide a mapping
 between BPMN and BPEL, but the authors state that there are areas of
 incompatibility, so it is not a perfect mapping.

Don't worry, BPMN does not exist: there is no incompatibility.
On the other hand, comparing and understanding BPMN and BPEL might
reveal different purposes and weaknesses between the two systems and
help you distinguish what you need, what would be cool and what is
only a bad idea or a speculation.

 Eventually I would like to make sense of all this, but for now I want
 to focus on BPMN, and ignore BPEL. I can use wxPython to design a BPMN
 diagram, but I have to invent my own method of serialising it so that
 I can use it to drive the business process. For good or ill, I decided
 to use xml, as it seems to offer the best chance of keeping up with
 the various specifications as they evolve.

If you mean to use workflow architectures to add value to your
business and accounting software, your priority should be executing
workflows, not editing workflow diagrams (which are a useful but
unnecessary user interface layer over the actual workflow engine);
making your diagrams and definitions compliant with volatile and
unproven specifications should come a distant last.

 I don't know if this is of any interest to anyone, but it was
 therapeutic for me to try to organise my thoughts and get them down on
 paper. I am not expecting any comments, but if anyone has any thoughts
 to toss in, I will read them with interest.


1) There are a number of open-source or affordable workflow engines,
mostly BPEL-compliant and written in Java; they should be more useful
than reinventing the wheel.

2) With a good XML editor you can produce the workflow definitions,
BPEL or otherwise, that your workflow engine needs, and leave the
interactive diagram editor for a phase 2 that might not necessarily
come; text editing might be convenient enough for your users, and for
graphical output something simpler than an editor (e.g a Graphviz
exporter) might be enough.

3) Maybe workflow processing can grow inside your existing accounting
application without the sort of big bang redesign you seem to be
planning; chances are that the needed objects are already in place and
you only need to make workflow more explicit and add appropriate new
features.

Regards,
Lorenzo Gatti
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML-schema 'best practice' question

2008-09-20 Thread Lorenzo Gatti
Sorry for pressing the send button too fast.

On 20 Set, 07:59, Frank Millman [EMAIL PROTECTED] wrote:

 I want to introduce an element of workflow management (aka Business
 Process Management) into the business/accounting system I am
 developing. I used google to try to find out what the current state of
 the art is. After several months of very confusing research, this is
 the present situation, as best as I can figure it out.

What is the state of the art of existing, working software? Can you
leverage it instead of starting from scratch? For example, the
existing functionality of your accounting software can be reorganized
as a suite of components, web services etc. that can be embedded in
workflow definitions, and/or executing a workflow engine can become a
command in your application.

 There is an OMG spec called BPMN, for Business Process Modeling
 Notation. It provides a graphical notation
[snip]
 there is no standard way
 of exchanging a diagram between different vendors, or of using it as
 input to a workflow engine.

So BPMN is mere theory. This spec might be a reference for
evaluating actual systems, but not a standard itself.

 There is an OASIS spec called WS-BPEL, for Web Services Business
 Process Execution Language. It defines a language for specifying
 business process behavior based on Web Services. This does have a
 formal xml-based specification. However, it only covers processes
 invoked via web services - it does not cover workflow-type processes
 within an organisation. To try to fill this gap, a few vendors got
 together and submitted a draft specification called BPEL4People. This
 proposes a series of extensions to the WS-BPEL spec. It is still at
 the evaluation stage.

Some customers pay good money for buzzword compliance, but are you
sure you want to be so bleeding edge that you care not only for WS-
something specifications, but for evaluation stage ones?

There is no need to wait for BPEL4People before designing workflow
systems with human editing, approval, etc.
Try looking into case studies of how BPEL is actually used in
practice.

 The BPMN spec includes a section which attempts to provide a mapping
 between BPMN and BPEL, but the authors state that there are areas of
 incompatibility, so it is not a perfect mapping.

Don't worry, BPMN does not exist: there is no incompatibility.
On the other hand, comparing and understanding BPMN and BPEL might
reveal different purposes and weaknesses between the two systems and
help you distinguish what you need, what would be cool and what is
only a bad idea or a speculation.

 Eventually I would like to make sense of all this, but for now I want
 to focus on BPMN, and ignore BPEL. I can use wxPython to design a BPMN
 diagram, but I have to invent my own method of serialising it so that
 I can use it to drive the business process. For good or ill, I decided
 to use xml, as it seems to offer the best chance of keeping up with
 the various specifications as they evolve.

If you mean to use workflow architectures to add value to your
business and accounting software, your priority should be executing
workflows, not editing workflow diagrams (which are a useful but
unnecessary user interface layer over the actual workflow engine);
making your diagrams and definitions compliant with volatile and
unproven specifications should come a distant last.

 I don't know if this is of any interest to anyone, but it was
 therapeutic for me to try to organise my thoughts and get them down on
 paper. I am not expecting any comments, but if anyone has any thoughts
 to toss in, I will read them with interest.


1) There are a number of open-source or affordable workflow engines,
mostly BPEL-compliant and written in Java; they should be more useful
than reinventing the wheel.

2) With a good XML editor you can produce the workflow definitions,
BPEL or otherwise, that your workflow engine needs, and leave the
interactive diagram editor for a phase 2 that might not necessarily
come; text editing might be convenient enough for your users, and for
graphical output something simpler than an editor (e.g a Graphviz
exporter) might be enough.

3) Maybe workflow processing can grow inside your existing accounting
application without the sort of big bang redesign you seem to be
planning; chances are that the needed objects are already in place and
you only need to make workflow more explicit and add appropriate new
features.

Regards,
Lorenzo Gatti
--
http://mail.python.org/mailman/listinfo/python-list


XML-schema 'best practice' question

2008-09-18 Thread Frank Millman
Hi all

This is not strictly a Python question, but as I am writing in Python,
and as I know there are some XML gurus on this list, I hope it is
appropriate here.

XML-schemas are used to define the structure of an xml document, and
to validate that a particular document conforms to the schema. They
can also be used to transform the document, by filling in missing
attributes with default values.

In my situation, both the creation and the processing of the xml
document are under my control. I know that this begs the question 'why
use xml in the first place', but let's not go there for the moment.

Using minixsv, validating a document with a schema works, but is quite
slow. I appreciate that lxml may be quicker, but I think that my
question is still applicable.

I am thinking of adding a check to see if a document has changed since
it was last validated, and if not, skip the validation step. However,
I then do not get the default values filled in.

I can think of two possible solutions. I just wondered if this is a
common design issue when it comes to xml and schemas, and if there is
a 'best practice' to handle it.

1. Don't use default values - create the document with all values
filled in.

2. Use python to check for missing values and fill in the defaults
when processing the document.

Or maybe the best practice is to *always* validate a document before
processing it.

How do experienced practitioners handle this situation?

Thanks for any hints.

Frank Millman
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML-schema 'best practice' question

2008-09-18 Thread Lorenzo Gatti
On 18 Set, 08:28, Frank Millman [EMAIL PROTECTED] wrote:

 I am thinking of adding a check to see if a document has changed since
 it was last validated, and if not, skip the validation step. However,
 I then do not get the default values filled in.

 I can think of two possible solutions. I just wondered if this is a
 common design issue when it comes to xml and schemas, and if there is
 a 'best practice' to handle it.

 1. Don't use default values - create the document with all values
 filled in.

 2. Use python to check for missing values and fill in the defaults
 when processing the document.

 Or maybe the best practice is to *always* validate a document before
 processing it.

The stated problem rings a lot of premature optimization bells;
performing the validation and default-filling step every time,
unconditionally, is certainly the least crooked approach.

In case you really want to avoid unnecessary schema processing, if you
are willing to use persistent data to check for changes (for example,
by comparing a hash or the full text of the current document with the
one from the last time you performed validation) you can also store
the filled-in document that you computed, either as XML or as
serialized Python data structures.

Regards,
Lorenzo Gatti
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML-schema 'best practice' question

2008-09-18 Thread skip
Frank 1. Don't use default values - create the document with all values
Frank filled in.

Frank 2. Use python to check for missing values and fill in the defaults
Frank when processing the document.

Frank Or maybe the best practice is to *always* validate a document
Frank before processing it.

Frank How do experienced practitioners handle this situation?

3. Don't use XML.

(sorry, couldn't resist)

Skip
--
http://mail.python.org/mailman/listinfo/python-list