[Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread anupama srinivas murthy
Hello,

My python code needs to run on versions 2.7 to 3.4. To use stringio
function as appropriate, the code i use is;

if sys.version < '3':
dictionary = io.StringIO(u"""\n""".join(english_words))
else:
dictionary = io.StringIO("""\n""".join(english_words))

The code runs fine on all versions mentioned above except for 3.2 where i
get the error:
dictionary = io.StringIO(u"""\n""".join(english_words))
^
SyntaxError: invalid syntax

How can I solve the issue?

Thank you
Anupama
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python program malfunction

2015-05-04 Thread Jag Sherrington
Hi,
There appears to be a problem with this program.
It is taken from the "Starting out with Python" book third edition.

The problem is when the "validate the wholesale cost" is introduced.
Without the validator the code works fine, but with it the code won't let you 
enter a positive wholesale cost unless you do a negative cost first. 
Even after you have entered a negative cost and got the results of your 
positive cost it asks wether you want to do another item if you type "y" you 
still can't enter a positive amount.

HERE IS THE CODE AS COPIED FROM THE BOOK:

#This program calculates retail prices.

mark_up = 2.5  # The mark up percentage.
another = 'y'   # Variable to control the loop.

# Process one or more items.
while another == 'y' or another == 'y':
#Get the item 's wholesale cost'
wholesale = float(input("Enter the item's wholesale cost: "))

# Validate the wholesale cost.
while wholesale < 0:
print('ERROR: the cost cannot be negative.')
wholesale = float(input('Enter the correct wholesale cost: '))

#Calculate the retail price.
retail = wholesale * mark_up

#Display the retail price.
print('Retail price: $', format(retail, ',.2f'), sep='')

#Do this again.
another = input('Do you have another item? ' + \
'(Enter y for yes): ')

HERE ARE THE RESULTS:

Enter the item's wholesale cost: 0.50
Enter the item's wholesale cost:(THIS SEEMS TO BE A PROBLEM)
>>>  RESTART 
>>> 
Enter the item's wholesale cost: -0.50  (YOU HAVE TO ENTER A NEGATIVE FIRST 
???)  
ERROR: the cost cannot be negative.
Enter the correct wholesale cost: 0.50  
Retail price: $1.25
Do you have another item? (Enter y for yes): y
Enter the item's wholesale cost: 0.50
Enter the item's wholesale cost: 

 
THANK YOU FOR YOUR HELP.

Regards, Jag
BraveArt Multimedia 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2015-05-04 Thread Grace Anne St Clair-Bates
I am trying to write a program that uses while and if loops, but my print
statements are not going through and showing up when I run the module. I
have tried numerous things and changed in the code and cannot for the life
of me figure out why it won't print. If someone could help that would be
amazing. Thank you
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread Alan Gauld

On 04/05/15 06:03, anupama srinivas murthy wrote:

Hello,

My python code needs to run on versions 2.7 to 3.4. To use stringio
function as appropriate, the code i use is;

if sys.version < '3':
 dictionary = io.StringIO(u"""\n""".join(english_words))
 else:
 dictionary = io.StringIO("""\n""".join(english_words))


Are you sure you are cutting and pasting the exact code
and error messages?
If so are you using plain text?

Because the indentation of the code above is wrong and should
give an error message every time.


The code runs fine on all versions mentioned above except for 3.2 where i
get the error:
dictionary = io.StringIO(u"""\n""".join(english_words))
 ^
SyntaxError: invalid syntax


The code you have shown us doesn't run on any version.
We will need to see the exact code and full error message.

Also, have you looked at the string returned by sys.version?
Comparing it to '3' like that is not a reliable way to test
version. You would be better off using sys.version_info.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program malfunction

2015-05-04 Thread Alan Gauld

On 04/05/15 05:26, Jag Sherrington wrote:

Hi,
There appears to be a problem with this program.
It is taken from the "Starting out with Python" book third edition.

The problem is when the "validate the wholesale cost" is introduced.
Without the validator the code works fine, but with it the code won't let you 
enter a positive wholesale cost unless you do a negative cost first.
Even after you have entered a negative cost and got the results of your positive cost it 
asks wether you want to do another item if you type "y" you still can't enter a 
positive amount.

HERE IS THE CODE AS COPIED FROM THE BOOK:

#This program calculates retail prices.

mark_up = 2.5  # The mark up percentage.
another = 'y'   # Variable to control the loop.

# Process one or more items.
while another == 'y' or another == 'y':


That's the same test twice. Is that what you meant?


 #Get the item 's wholesale cost'
 wholesale = float(input("Enter the item's wholesale cost: "))

 # Validate the wholesale cost.
 while wholesale < 0:
 print('ERROR: the cost cannot be negative.')
 wholesale = float(input('Enter the correct wholesale cost: '))

 #Calculate the retail price.
 retail = wholesale * mark_up

 #Display the retail price.
 print('Retail price: $', format(retail, ',.2f'), sep='')

 #Do this again.
 another = input('Do you have another item? ' + \
 '(Enter y for yes): ')

HERE ARE THE RESULTS:

Enter the item's wholesale cost: 0.50
Enter the item's wholesale cost:(THIS SEEMS TO BE A PROBLEM)


No problem, its exactly what your program tells it to do.
If the cost is >0 there is nothing else to do so it goes
round the loop a second time.

What did you expect it to do?


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program malfunction

2015-05-04 Thread Peter Otten
Jag Sherrington wrote:

> Hi,
> There appears to be a problem with this program.
> It is taken from the "Starting out with Python" book third edition.
> 
> The problem is when the "validate the wholesale cost" is introduced.
> Without the validator the code works fine, but with it the code won't let
> you enter a positive wholesale cost unless you do a negative cost first.
> Even after you have entered a negative cost and got the results of your
> positive cost it asks wether you want to do another item if you type "y"
> you still can't enter a positive amount.
> 
> HERE IS THE CODE AS COPIED FROM THE BOOK:
> 
> #This program calculates retail prices.
> 
> mark_up = 2.5  # The mark up percentage.
> another = 'y'   # Variable to control the loop.
> 
> # Process one or more items.
> while another == 'y' or another == 'y':
> #Get the item 's wholesale cost'
> wholesale = float(input("Enter the item's wholesale cost: "))
> 
> # Validate the wholesale cost.
> while wholesale < 0:
> print('ERROR: the cost cannot be negative.')
> wholesale = float(input('Enter the correct wholesale cost: '))

Look at the indentation of the rest of your code. To which while loop do you 
want it to belong and in which while loop is it actually executed?
 
> #Calculate the retail price.
> retail = wholesale * mark_up
> 
> #Display the retail price.
> print('Retail price: $', format(retail, ',.2f'), sep='')
> 
> #Do this again.
> another = input('Do you have another item? ' + \
> '(Enter y for yes): ')
> 
> HERE ARE THE RESULTS:
> 
> Enter the item's wholesale cost: 0.50
> Enter the item's wholesale cost:(THIS SEEMS TO BE A PROBLEM)
  RESTART
 
 
> Enter the item's wholesale cost: -0.50  (YOU HAVE TO ENTER A NEGATIVE
> FIRST ???) ERROR: the cost cannot be negative.
> Enter the correct wholesale cost: 0.50
> Retail price: $1.25
> Do you have another item? (Enter y for yes): y
> Enter the item's wholesale cost: 0.50
> Enter the item's wholesale cost:
> 
>  
> THANK YOU FOR YOUR HELP.
> 
> Regards, Jag


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2015-05-04 Thread Peter Otten
Grace Anne St Clair-Bates wrote:

> I am trying to write a program that uses while and if loops, but my print
> statements are not going through and showing up when I run the module. I
> have tried numerous things and changed in the code and cannot for the life
> of me figure out why it won't print. If someone could help that would be
> amazing. Thank you

Write a small example script that shows the problem. Post it here so that we 
have something to start the discussion.

Do not attach the script to your mail, put it into the body as plain text. 
Only then everyone can see your code.

Thank you.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2015-05-04 Thread Alan Gauld

On 04/05/15 06:00, Grace Anne St Clair-Bates wrote:

I am trying to write a program that uses while and if loops, but my print
statements are not going through and showing up when I run the module. I
have tried numerous things and changed in the code and cannot for the life
of me figure out why it won't print. If someone could help that would be
amazing. Thank you


To help you would need to show us the code.
We are not mind readers.

Also post any error messages you get, they
are full of useful information once you
learn how to read them.

Finally, please tell us which Python version you are using,
which OS and which tutorial or book you are using.

With that information available we can try to help.

But note: if *statements* are not *loops*.
*loops* are bits of code that repeat zero or more times.
*if statements* are bits of code that may or may not
execute depending on some test result.

In programming it is very important to be precise
in your language. Otherwise we all get very confused
about what you mean.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread Chris Warrick
On Mon, May 4, 2015 at 7:03 AM, anupama srinivas murthy
 wrote:
> Hello,
>
> My python code needs to run on versions 2.7 to 3.4. To use stringio
> function as appropriate, the code i use is;
>
> if sys.version < '3':

A better comparison to use would be

if sys.version_info[0] == 2:

It’s the standard idiom, which compares 2 == 2 instead of '2.7.9 (more
garbage here)' < '3'.

> dictionary = io.StringIO(u"""\n""".join(english_words))
> else:
> dictionary = io.StringIO("""\n""".join(english_words))
>
> The code runs fine on all versions mentioned above except for 3.2 where i
> get the error:
> dictionary = io.StringIO(u"""\n""".join(english_words))
> ^
> SyntaxError: invalid syntax
>
> How can I solve the issue?

The best solution is not supporting Python 3.2, especially considering
that Python 3.3.0 was released in September 2012 (and the latest
version is 3.4.3).

Python 3.0–3.2 do not support the u'' notation for Unicode strings, it
was restored in Python 3.3 to make it easier to write code compatible
with 2.x and 3.x (just like you are trying to do here!)  Python has to
read in and parse all the code, and it encounters a strange u'' thing
it does not recognize.  Thus, it fails with a SyntaxError.

Many Python projects out there don’t support 3.2, and this was one of
the reasons.

If you REALLY have to support it (why?), there are two solutions.  The
first one is to use '\n'.decode('utf-8') instead of u'\n' for Python
2.7, which will not trigger a compile error (it does not matter that
there is no str.decode in Python 3, the syntax makes sense even if it
cannot be executed).  The second one is to use (at the top of your
file)

from __future__ import unicode_literals

This will make Python 2.7 think '\n' is a Unicode string, and Python
3.x will ignore this line — in that case, you can even drop the
if/else and just use the same dictionary assignment for both Pythons.
Just be warned that it applies to the entire file and can lead to
problems.

PS. There is no reason to use """multi-line strings""" in this case,
regular "strings" will do it equally well and are more readable.

-- 
Chris Warrick 
PGP: 5EAAEA16
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread Peter Otten
anupama srinivas murthy wrote:

> Hello,
> 
> My python code needs to run on versions 2.7 to 3.4. To use stringio
> function as appropriate, the code i use is;
> 
> if sys.version < '3':
> dictionary = io.StringIO(u"""\n""".join(english_words))
> else:
> dictionary = io.StringIO("""\n""".join(english_words))
> 
> The code runs fine on all versions mentioned above except for 3.2 where i
> get the error:
> dictionary = io.StringIO(u"""\n""".join(english_words))
> ^
> SyntaxError: invalid syntax
> 
> How can I solve the issue?

Unfortunately Python 3.2 doesn't understand the u-prefixed syntax for 
unicode strings. Are the strings in english_words all unicode? Then

dictionary = io.StringIO("\n".join(english_words))

should work. In Python 3 "\n" is unicode anyway, and Python 2 implicitly 
converts "\n" to unicode:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "\n".join([u"foo", u"bar"])
u'foo\nbar'


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread Peter Otten
Peter Otten wrote:

> anupama srinivas murthy wrote:
> 
>> Hello,
>> 
>> My python code needs to run on versions 2.7 to 3.4. To use stringio
>> function as appropriate, the code i use is;
>> 
>> if sys.version < '3':
>> dictionary = io.StringIO(u"""\n""".join(english_words))
>> else:
>> dictionary = io.StringIO("""\n""".join(english_words))
>> 
>> The code runs fine on all versions mentioned above except for 3.2 where i
>> get the error:
>> dictionary = io.StringIO(u"""\n""".join(english_words))
>> ^
>> SyntaxError: invalid syntax
>> 
>> How can I solve the issue?
> 
> Unfortunately Python 3.2 doesn't understand the u-prefixed syntax for
> unicode strings. Are the strings in english_words all unicode? Then
> 
> dictionary = io.StringIO("\n".join(english_words))
> 
> should work. In Python 3 "\n" is unicode anyway, and Python 2 implicitly
> converts "\n" to unicode:
> 
> $ python
> Python 2.7.6 (default, Mar 22 2014, 22:59:56)
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 "\n".join([u"foo", u"bar"])
> u'foo\nbar'

There is also the

from __future__ import unicode_literals

directive in Python 2.7. With that

"..." will be unicode, and bytestrings must be marked b"...".
The latter is understood by both 2.7 and 3.x

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread anupama srinivas murthy
> On May 4, 2015 2:17 AM, "anupama srinivas murthy" <
> anupama.2312.bm...@gmail.com> wrote:
>
>> Hello,
>>
>> My python code needs to run on versions 2.7 to 3.4. To use stringio
>> function as appropriate, the code i use is;
>>
>> if sys.version < '3':
>> dictionary = io.StringIO(u"""\n""".join(english_words))
>> else:
>> dictionary = io.StringIO("""\n""".join(english_words))
>>
>> The code runs fine on all versions mentioned above except for 3.2 where i
>> get the error:
>> dictionary = io.StringIO(u"""\n""".join(english_words))
>> ^
>> SyntaxError: invalid syntax
>>
>> How can I solve the issue?
>>
>> Thank you
>> Anupama
>>
>>
>


On 4 May 2015 at 12:48, Reuben  wrote:

Did you import correct library?


Thank you for asking

Yes. I made a new modification and the code now runs fine on python 3.2 as
well. I replaced;

dictionary = io.StringIO(u"""\n""".join(english_words))

with

dictionary = io.StringIO(unicode('\n').join(english_words))

However, i do not understand why it works fine now
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Sieve of Erastthotenes without sofisticated tools

2015-05-04 Thread yvan moses Levy
My code is wrong!
I tried and tried
But I'm very isolated and It's hard without consultation with a tutor
from math import sqrt
def holeofStrainer():
  bigList = [False, False] + [True]*100
  print("line 4 - bigList : ", bigList)
  for num in range(2, 101):
print("line 6 - num : ", num)
for x in range(bigList[2], bigList[int(sqrt(num)) + 1]):
  print("line 8 x : %d"%x)
  if num % x == 0:
print("line 10 {0} divise par {1} = {2} ".format(num, x, num/x))
bigList[num] == False
print "bigList[{0} == {1}]".format(num, bigList[num])
  bigList[num] == True

for multiple in range (2, int(101/num) + 1):
  bigList[multiple] = False
  return(bigList)
print("the last result of bigList {} ".format(holeofStrainer()))
I WANT TO KNOW WHILE THE EXECUTION DO NOT GOING DOWNWARD

--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sieve of Erastthotenes without sofisticated tools

2015-05-04 Thread Dave Angel

On 05/04/2015 03:19 AM, yvan moses Levy wrote:

My code is wrong!


You'd find it a lot easier to get responses if you'd say in what way the 
code is wrong.  If you get an exception, show the full traceback.  If 
you get printed results, show what you expected, and what you got 
instead.  If it hung, or crashed the OS, or ran out of memory, say so.



I tried and tried
But I'm very isolated and It's hard without consultation with a tutor
from math import sqrt
def holeofStrainer():
   bigList = [False, False] + [True]*100
   print("line 4 - bigList : ", bigList)
   for num in range(2, 101):
 print("line 6 - num : ", num)
 for x in range(bigList[2], bigList[int(sqrt(num)) + 1]):


What did you expect this to do?  What is bigList[2] ?  What is 
bigList[int(sqrt(num)) + 1] ?  Are these reasonable values to put into a 
range() function?





   print("line 8 x : %d"%x)
   if num % x == 0:
 print("line 10 {0} divise par {1} = {2} ".format(num, x, num/x))
 bigList[num] == False
 print "bigList[{0} == {1}]".format(num, bigList[num])
   bigList[num] == True

 for multiple in range (2, int(101/num) + 1):
   bigList[multiple] = False
   return(bigList)
print("the last result of bigList {} ".format(holeofStrainer()))
I WANT TO KNOW WHILE THE EXECUTION DO NOT GOING DOWNWARD

--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor





--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with stringio function in python 3.2

2015-05-04 Thread eryksun
On Mon, May 4, 2015 at 2:46 AM, Chris Warrick  wrote:
> Python 3.0–3.2 do not support the u'' notation for Unicode strings, it
> was restored in Python 3.3 to make it easier to write code compatible
> with 2.x and 3.x

Whoever restored this forgot about raw literals:

>>> ur'abc'
  File "", line 1
ur'abc'
  ^
SyntaxError: invalid syntax
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Jacob Kaplan-Moss's keynote at PyCon 2015

2015-05-04 Thread Danny Yoo
Apologies: this is somewhat off-topic, but I thought it might resonate
with the audience here:

https://www.youtube.com/watch?v=hIJdFxYlEKE

It reminds me of Camille Fournier's talk back in 2014 at BangBangCon:

https://www.youtube.com/watch?v=sc8sc-ELMhA

Both express the experience of being a programmer, on the dangers of
thinking of programming skill as some kind of bi-modal thing.  A key
point in both their talks, I think, is that almost all of us aren't
born natural programmers.  It's a skill.  We stumble, we learn, and we
can get better at it.


I hope that's an encouraging thought.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Integrating TDD into my current project work-flows

2015-05-04 Thread WolfRage

I would like some help integrating TDD into my current projects.
My chosen TDD framework is unittest from the standard library.
My system details are: Linux Mint 17.1 64-bit, Python 3.4, bzr(for 
version control).


My projects are structured like:
Project > develop > Project > Project > __main__.py
  tests   > __main__.py
I want to be able to execute my Project from a cwd of:
Project/develop/Project
as: Python3 -m Project
That currently works.
But executing my tests as: Python3 -m tests
requires that test_Project.py has this hack to import the Project module:
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
do you consider that OK? Is there a better way?
I call it a hack because every testcase file will have to have this line 
added to it in order to work.


I am also using coverage.py and it is good but seems to be testing the 
coverage of my tests, which is not desired, how can I stop this 
behaviour. Or is it really OK.


Output of running the tests:
python3 -m tests
Ran Main.
.
--
Ran 1 test in 0.001s

OK
Name Stmts   Miss  Cover   Missing
--
Project/Project  3  0   100%
tests/test_Project   8  0   100%
--
TOTAL   11  0   100%


The test files:
{FileName = __main__.py}
# -*- coding: utf-8 -*-
if __name__ == '__main__':
import coverage
import unittest
cov = coverage.coverage()
cov.start()
# .. call your code ..
from .test_Project import ProjectTestCase  # lint:ok
unittest.main(exit=False)
cov.stop()
cov.save()
import sys
cov.report(file=sys.stdout)


{FileName = test_Project.py}
# -*- coding: utf-8 -*-
import os
import sys
import unittest
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from Project import Project


class ProjectTestCase(unittest.TestCase):

def test_example(self):
self.assertTrue(Project.main())


The Project Files:
{FileName = __main__.py}
# -*- coding: utf-8 -*-

if __name__ == '__main__':
from . import Project
Project.main()

{FileName = Project.py}
# -*- coding: utf-8 -*-


def main():
return True
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-04 Thread Martin A. Brown


Hi there,

I would like some help integrating TDD into my current projects. 
My chosen TDD framework is unittest from the standard library. My 
system details are: Linux Mint 17.1 64-bit, Python 3.4, bzr(for 
version control).


My projects are structured like:
Project > develop > Project > Project > __main__.py
 tests   > __main__.py
I want to be able to execute my Project from a cwd of:
Project/develop/Project
as: Python3 -m Project
That currently works.
But executing my tests as: Python3 -m tests
requires that test_Project.py has this hack to import the Project module:
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))


Yes, a bit ugly.  Have you tried using nose?  I have used a 
similar project development tree and use nose to run the tests.


Here are a few sample command-lines (I'm on an opensuse-13.2 system 
with Python 3.4 and nose for Python-3.4, which is called 
'nosetests-3.4'):


  nosetests-3.4 -- ./tests/
  nosetests-3.4 --with-coverage -- ./tests/
  nosetests-3.4 --with-coverage --cover-package=Project -- ./tests/

I like nose because it will discover any unittest and doctest 
testing code under the specified files/directories.



do you consider that OK? Is there a better way?


I call it a hack because every testcase file will have to have 
this line added to it in order to work.


Agreed, is a hack.

I am also using coverage.py and it is good but seems to be testing 
the coverage of my tests, which is not desired, how can I stop 
this behaviour. Or is it really OK.


That's precisely what coverage is supposed to do--that is it should 
report on how much of the 'code under test' has been exercised by 
the testing code.  So, in fact, it's better than OK--it's the 
primary point!


There are two good things about using coverage.

  #1: You see how much more effort you should invest to get
  substantial testing coverage of the code under test.
  [Though, some code is easy to test and others very difficult.]

  #2: You get a report of the lines in the code under test which are
  NOT yet tested; handy!

Good luck,

-Martin

--
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program malfunction

2015-05-04 Thread Jag Sherrington
Hi, Alan> Enter the item's wholesale cost: 0.50 (AFTER THIS LINE PRINTS I HIT 
ENTER AND WOULD EXPECT THE NEXT LINE TO GIVE ME THE RESULT> Enter the item's 
wholesale cost:    "Retail price: $1.25"  INSTEAD WHEN I HIT ENTER I GET "Enter 
the item's wholesale cost: " AGAIN AND AGAIN
Regards, Jag
BraveArt Multimedia

 


 On Monday, 4 May 2015, 17:35, Alan Gauld  wrote:
   

 On 04/05/15 05:26, Jag Sherrington wrote:
> Hi,
> There appears to be a problem with this program.
> It is taken from the "Starting out with Python" book third edition.
>
> The problem is when the "validate the wholesale cost" is introduced.
> Without the validator the code works fine, but with it the code won't let you 
> enter a positive wholesale cost unless you do a negative cost first.
> Even after you have entered a negative cost and got the results of your 
> positive cost it asks wether you want to do another item if you type "y" you 
> still can't enter a positive amount.
>
> HERE IS THE CODE AS COPIED FROM THE BOOK:
>
> #This program calculates retail prices.
>
> mark_up = 2.5  # The mark up percentage.
> another = 'y'  # Variable to control the loop.
>
> # Process one or more items.
> while another == 'y' or another == 'y':

That's the same test twice. Is that what you meant?

>      #Get the item 's wholesale cost'
>      wholesale = float(input("Enter the item's wholesale cost: "))
>
>      # Validate the wholesale cost.
>      while wholesale < 0:
>          print('ERROR: the cost cannot be negative.')
>          wholesale = float(input('Enter the correct wholesale cost: '))
>
>          #Calculate the retail price.
>          retail = wholesale * mark_up
>
>          #Display the retail price.
>          print('Retail price: $', format(retail, ',.2f'), sep='')
>
>          #Do this again.
>          another = input('Do you have another item? ' + \
>                          '(Enter y for yes): ')
>
> HERE ARE THE RESULTS:
>
> Enter the item's wholesale cost: 0.50
> Enter the item's wholesale cost:    (THIS SEEMS TO BE A PROBLEM)

No problem, its exactly what your program tells it to do.
If the cost is >0 there is nothing else to do so it goes
round the loop a second time.

What did you expect it to do?


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program malfunction

2015-05-04 Thread Alan Gauld

On 05/05/15 00:08, Jag Sherrington wrote:

Hi, Alan
> Enter the item's wholesale cost: 0.50
(AFTER THIS LINE PRINTS I HIT ENTER AND WOULD
EXPECT THE NEXT LINE TO GIVE ME THE RESULT


But why would it? Your print code is all inside a loop that
only runs if the price is negative. If you enter a positive
price that code will not execute.

Look at your code. Follow it through line by line.


> while another == 'y' or another == 'y':
>  wholesale = float(input("Enter the item's wholesale cost: "))
>  while wholesale < 0:
>  print('ERROR: the cost cannot be negative.')
>  wholesale = float(input('Enter the correct wholesale cost: '))
>
>  #Calculate the retail price.
>  retail = wholesale * mark_up
>
>  #Display the retail price.
>  print('Retail price: $', format(retail, ',.2f'), sep='')
>
>  #Do this again.
>  another = input('Do you have another item? ' + \
>  '(Enter y for yes): ')


I suspect that if you look at your books code the lines starting
#Calculate the retail price.
are all aligned under the first while not the second?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program malfunction

2015-05-04 Thread Dave Angel

On 05/04/2015 07:08 PM, Jag Sherrington wrote:

Hi, Alan>




Please don't top-post.  Enter your new message *after* whatever portion 
of the previous message you're quoting.  I'm rearranging the portion of 
your message to conform to that standard.





  On Monday, 4 May 2015, 17:35, Alan Gauld  
wrote:



# Process one or more items.
while another == 'y' or another == 'y':


That's the same test twice. Is that what you meant?


   #Get the item 's wholesale cost'
   wholesale = float(input("Enter the item's wholesale cost: "))

   # Validate the wholesale cost.
   while wholesale < 0:
   print('ERROR: the cost cannot be negative.')
   wholesale = float(input('Enter the correct wholesale cost: '))


BUG on following line:

   #Calculate the retail price.
   retail = wholesale * mark_up

   #Display the retail price.
   print('Retail price: $', format(retail, ',.2f'), sep='')

   #Do this again.
   another = input('Do you have another item? ' + \
   '(Enter y for yes): ')

HERE ARE THE RESULTS:

Enter the item's wholesale cost: 0.50
Enter the item's wholesale cost:(THIS SEEMS TO BE A PROBLEM)


No problem, its exactly what your program tells it to do.
If the cost is >0 there is nothing else to do so it goes
round the loop a second time.

What did you expect it to do?


> Enter the item's wholesale cost: 0.50 (AFTER THIS LINE PRINTS I HIT
> ENTER AND WOULD EXPECT THE NEXT LINE TO GIVE ME THE RESULT>
> Enter the item's wholesale cost:"Retail price: $1.25"
> INSTEAD WHEN I HIT ENTER I GET "Enter the item's
>  wholesale cost: " AGAIN AND AGAIN

(See Peter's comment as well as Alan's second one.)

All the rest of your logic is inside the while loop that's only run when 
the wholesale < 0 branch is taken.  So you don't see any output from it, 
as it never runs unless you enter a negative value followed by a 
positive one.


You have to fix the indentation of the lines starting "#Calculate the 
retail price"




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sieve of Erastthotenes without sofisticated tools

2015-05-04 Thread Dave Angel
You accidentally sent your response to me instead of the list.  The 
proper thing to do for nearly all messages is to respond to the list. 
The main exception for that is if you just want to leave a simple 
thank-you for a person, and nothing of interest to anyone else.


From your email program, use Reply-List.  If it doesn't support that, 
use Reply-All, and then delete me, so it goes just to the list.


Another problem with your message is messed-up formatting, apparently 
caused by the fact that you're sending html-encoded email to a text-only 
mailing list.  Please tell your mailer to use text.


On 05/04/2015 10:07 PM, yvan moses levy wrote:> Le 04/05/15 13:00, Dave 
Angel a écrit :

>> On 05/04/2015 03:19 AM, yvan moses Levy wrote:
>>> My code is wrong!
>>
>> You'd find it a lot easier to get responses if you'd say in what way 
the code

>> is wrong.  If you get an exception, show the full traceback.  If you get
>> printed results, show what you expected, and what you got instead. 
If it

>> hung, or crashed the OS, or ran out of memory, say so.
>>
>>> I tried and tried
>>> But I'm very isolated and It's hard without consultation with a tutor
>>> from math import sqrt
>>> def holeofStrainer():
>>>bigList = [False, False] + [True]*100
>>>print("line 4 - bigList : ", bigList)
>>>for num in range(2, 101):
>>>  print("line 6 - num : ", num)
>>>  for x in range(bigList[2], bigList[int(sqrt(num)) + 1]):
>>
>> What did you expect this to do?  What is bigList[2] ?  What is
>> bigList[int(sqrt(num)) + 1] ?  Are these reasonable values to put into a
>> range() function?
>>

You didn't answer any of these questions.  Why not?

>>
>>
>>>print("line 8 x : %d"%x)
>>>if num % x == 0:
>>>  print("line 10 {0} divise par {1} = {2} ".format(num, x, 
num/x))

>>>  bigList[num] == False
>>>  print "bigList[{0} == {1}]".format(num, bigList[num])
>>>bigList[num] == True
>>>
>>>  for multiple in range (2, int(101/num) + 1):
>>>bigList[multiple] = False
>>>return(bigList)
>>> print("the last result of bigList {} ".format(holeofStrainer()))
>>> I WANT TO KNOW WHILE THE EXECUTION DO NOT GOING DOWNWARD
>>>
>>>
>> OK I'll trying
> code:
> from math import sqrt
> def holeofStrainer():
> """The purpose is to build a sieve of Erasthotenes.
> We beginn with a sieve without holes, called biglist.
> The indexes of the list have a double function:
> First, The natural list indexation. II-st, there are
> as keys of the corresponding list items(the boolean
>   values of the prime being question about each number).
> We have for each index a"""
> bigList = [False, False] + [True]*100
> print("line 11 - bigList : ", bigList)
> for num in range(3, 101):
>   print("line 13 - num : ", num)
>   # I f we don't find divisors of nume littler that sqrt(num)
>   # it is guaranted that num is prime.
>   # 'int(sqrt(num)) + 1' is the first integer greater than sqrt(num)
>   for x in range(bigList[2], bigList[int(sqrt(num)) + 1]):

I repeat, what did you expect this line to do? Examine this line 
carefully.  Print out the two expressions you're passing to range().


This currently loops from True to True, or from False to False, so it 
skips the whole predicate. Think about what you really want the loop to do.



> print("line 18 x  is equal to %d"%x)
> if num % x == 0:
>   print("line 20 {0} divided by {1} = {2} ".format(num, x, 
num/x))

>   bigList[num] == False
>   print ("bigList index {0} == {1}".format(num, bigList[num]))
> bigList[num] == True
>
>   for multiple in range (2, int(101/num) + 1):
> bigList[multiple] = False
> return(bigList) #We expect a 'sieve with many holes'
> print("the last result of bigList {} ".format(holeofStrainer()))*
>
> *
>
> ***Hi Dave.*

What's the reason you're quad-spacing the expected output?  I'm fixing 
it, but it's a pain to do.


>
> **
> > *I expected to obtain an output as:*
>
> *line 13 num 3*
> *line 18 x :2*
> *line 20: 3 divided by 2 is equal to 1.5*
> *biglist index 3 == True*
> *line 13 num 4*
> *line 18 x:2*
> *line 20 4 divided by 2 is equal to 2*
> *biglist index 4 == False*

So that's what you expected.  What did you get instead?  If you notice 
that line 18 never printed, shouldn't you guess that something's wrong 
with the loop in line 17?




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor