Re: [Tutor] Baccarat code check.

2011-12-17 Thread Dave Angel

On 12/16/2011 03:29 AM, col speed wrote:

If anyone has the time, please have a look at the attached text file
and let me know any comments on how to improve it.
Thanks a lot
Col

I don't see any response for 24 hours, so I'd say that nobody has the 
time.  However, you could have improved the odds substantially by giving 
us a clue what you were looking for.


Is this a program that runs properly, correctly and quickly enough, and 
you just want advice on making the code cleaner and clearer?


Or does the program run apparently normally, but gets the wrong results, 
and you need help fixing that?  If so, tell us specifically what seems 
to be wrong:   what happens when you run it, and what did you expect 
different?


Or does the program die with some exception?  in that case, tell us how 
to reproduce the symptom, and show us the full traceback when it dies.


Or something else?


I can only guess the first case is your supposed situation.  So I'll 
look it over.  I'm not running it, so all i can comment on is obvious 
bugs and stylistic errors.  I also have to assume you're running it on a 
Linux type machine, with Python 2.7.


I don't know baccarat, so I make mistakes on that account.

First obvious problem is that each player has its own kitty.  I don't 
know of any card game where that is done.  But maybe in baccarat the 
word means something totally different.


Naming difficulty, getPlayers() cannot reasonably be called more than 
once, so it's better named something like init_players().


In class Card, your final else clause looks like a good place for 
assert().  It'll never happen in production, but only till the program 
has passed its test suite.


In placeBets(), there doesn't seem to be any indication of which person 
(name) is betting each time.  That should probably be part of the prompt 
to raw_input.


In   (), the raw_input() that's assigned to standordraw, it doesn't 
include the player name in the prompt. This is even more important than 
the last, since only a few of the players will get prompted like this 
each round.


hope that helps some.



--

DaveA

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


Re: [Tutor] Baccarat code check.

2011-12-17 Thread Peter Otten
col speed wrote:

> If anyone has the time, please have a look at the attached text file
> and let me know any comments on how to improve it.

At first glance the code looks good. I think you can move to the next level 
now ;)

Are you using a version control system? If not, have a look at mercurial. 
Here's an introduction: http://hginit.com/

Once you've checked in the code you can start writing tests that verify the 
correctness of parts of it, see http://docs.python.org/library/unittest.html
Don't be afraid to change your code to make it easier to test. That's called 
"refactoring" and usually improves the code quality. If something goes wrong 
you always have the previous version in the version control.

How do you know you're done writing tests? There's a great tool that helps 
you measure what portion of your code is exercised by your tests:

http://pypi.python.org/pypi/coverage

Do you know the style guide for Python code 
(http://www.python.org/dev/peps/pep-0008/)? You should at least consider to 
follow it.

Now to your actual code: I don't know Baccarat and haven't looked closely at 
your script. I think you should base your Card class on data rather than 
calculations. That will simplify it significantly:

_cards = [
("1", 1),
("2", 2),
("3", 3),
("4", 4),
("5", 5),
("6", 6),
("7", 7),
("8", 8),
("9", 9),
("10", 0),
("J", 0),
("Q", 0),
("K", 0),
("A", 1),
]

class Card(object):
def __init__(self, name, value):
self.name = name
self.value = value

cards = [Card(n, v) for n, v in _cards]

class Shoe(list):
"""A collection of 8 decks of cards"""
def __init__(self):
self[:] = cards*(4*8)
random.shuffle(self)
#...

Once you have unittests in place you can try and replace your Card 
implementation with mine and see if your script continues to work correctly.

Last and least: 

- I ran your script and got an UnboundLocalError (I'm sorry I didn't keep 
the traceback); there must be a code path in main() where last_card is 
undefined. Try to separate the program logic from the user interface. This 
makes it easier to identify and reproduce problems in the program logic and 
to write tests to prevent them in the future.

- random.choice() takes a list argument


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


Re: [Tutor] Baccarat code check.

2011-12-17 Thread col speed
On 17 December 2011 16:40, Dave Angel  wrote:
> On 12/16/2011 03:29 AM, col speed wrote:
>>
>> If anyone has the time, please have a look at the attached text file
>> and let me know any comments on how to improve it.
>> Thanks a lot
>> Col
>>
> I don't see any response for 24 hours, so I'd say that nobody has the time.
>  However, you could have improved the odds substantially by giving us a clue
> what you were looking for.
>
> Is this a program that runs properly, correctly and quickly enough, and you
> just want advice on making the code cleaner and clearer?
>
> Or does the program run apparently normally, but gets the wrong results, and
> you need help fixing that?  If so, tell us specifically what seems to be
> wrong:   what happens when you run it, and what did you expect different?
>
> Or does the program die with some exception?  in that case, tell us how to
> reproduce the symptom, and show us the full traceback when it dies.
>
> Or something else?
>
> 
> I can only guess the first case is your supposed situation.  So I'll look it
> over.  I'm not running it, so all i can comment on is obvious bugs and
> stylistic errors.  I also have to assume you're running it on a Linux type
> machine, with Python 2.7.
>
> I don't know baccarat, so I make mistakes on that account.
>
> First obvious problem is that each player has its own kitty.  I don't know
> of any card game where that is done.  But maybe in baccarat the word means
> something totally different.
>
> Naming difficulty, getPlayers() cannot reasonably be called more than once,
> so it's better named something like init_players().
>
> In class Card, your final else clause looks like a good place for assert().
>  It'll never happen in production, but only till the program has passed its
> test suite.
>
> In placeBets(), there doesn't seem to be any indication of which person
> (name) is betting each time.  That should probably be part of the prompt to
> raw_input.
>
> In   (), the raw_input() that's assigned to standordraw, it doesn't include
> the player name in the prompt. This is even more important than the last,
> since only a few of the players will get prompted like this each round.
>
> hope that helps some.
>
>
>
> --
>
> DaveA
>
Thanks for your reply.
Yes, you supposed correctly, I just wanted some advice to make it
clearer and cleaner. Thanks for your help, I know people here don't
have a lot of time and I appreciate that. That's all I wanted, really.
I'll try & make myself clearer next time.
Thanks again
Col
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Baccarat code check.

2011-12-17 Thread col speed
On 17 December 2011 16:49, Peter Otten <__pete...@web.de> wrote:
> col speed wrote:
>
>> If anyone has the time, please have a look at the attached text file
>> and let me know any comments on how to improve it.
>
> At first glance the code looks good. I think you can move to the next level
> now ;)
>
> Are you using a version control system? If not, have a look at mercurial.
> Here's an introduction: http://hginit.com/
>
> Once you've checked in the code you can start writing tests that verify the
> correctness of parts of it, see http://docs.python.org/library/unittest.html
> Don't be afraid to change your code to make it easier to test. That's called
> "refactoring" and usually improves the code quality. If something goes wrong
> you always have the previous version in the version control.
>
> How do you know you're done writing tests? There's a great tool that helps
> you measure what portion of your code is exercised by your tests:
>
> http://pypi.python.org/pypi/coverage
>
> Do you know the style guide for Python code
> (http://www.python.org/dev/peps/pep-0008/)? You should at least consider to
> follow it.
>
> Now to your actual code: I don't know Baccarat and haven't looked closely at
> your script. I think you should base your Card class on data rather than
> calculations. That will simplify it significantly:
>
> _cards = [
> ("1", 1),
> ("2", 2),
> ("3", 3),
> ("4", 4),
> ("5", 5),
> ("6", 6),
> ("7", 7),
> ("8", 8),
> ("9", 9),
> ("10", 0),
> ("J", 0),
> ("Q", 0),
> ("K", 0),
> ("A", 1),
> ]
>
> class Card(object):
>    def __init__(self, name, value):
>        self.name = name
>        self.value = value
>
> cards = [Card(n, v) for n, v in _cards]
>
> class Shoe(list):
>    """A collection of 8 decks of cards"""
>    def __init__(self):
>        self[:] = cards*(4*8)
>        random.shuffle(self)
>    #...
>
> Once you have unittests in place you can try and replace your Card
> implementation with mine and see if your script continues to work correctly.
>
> Last and least:
>
> - I ran your script and got an UnboundLocalError (I'm sorry I didn't keep
> the traceback); there must be a code path in main() where last_card is
> undefined. Try to separate the program logic from the user interface. This
> makes it easier to identify and reproduce problems in the program logic and
> to write tests to prevent them in the future.
>
> - random.choice() takes a list argument
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Fantastic! I will check all those out.
Thanks again
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Weird Error

2011-12-17 Thread Ken G.
I have use 'sleep.time(5)' in most of my program but the following error 
is throwing me for a loss.


import time
Traceback (most recent call last):
  File "/home/ken/Python2/Blood Glucose/BloodGlucose04ReadingTimed.py", 
line 63, in 

time.sleep(2)
AttributeError: 'str' object has no attribute 'sleep'

Using the following is okay:

import time
print "Now"
time.sleep(2)
print "Later"


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


Re: [Tutor] Weird Error

2011-12-17 Thread Peter Otten
Ken G. wrote:

> I have use 'sleep.time(5)' in most of my program but the following error
> is throwing me for a loss.
> 
> import time
> Traceback (most recent call last):
>File "/home/ken/Python2/Blood Glucose/BloodGlucose04ReadingTimed.py",
> line 63, in 
>  time.sleep(2)
> AttributeError: 'str' object has no attribute 'sleep'
> 
> Using the following is okay:
> 
> import time
> print "Now"
> time.sleep(2)
> print "Later"

Look for an assignment like

time = "whatever"

in module BloodGlucose04ReadingTimed.py.

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


Re: [Tutor] Weird Error

2011-12-17 Thread Shrivats
Hello, 
On Sat, Dec 17, 2011 at 10:19:37AM -0500, Ken G. wrote:
> I have use 'sleep.time(5)' in most of my program but the following error 
> is throwing me for a loss.
> 
> import time
> Traceback (most recent call last):
>   File "/home/ken/Python2/Blood Glucose/BloodGlucose04ReadingTimed.py", 
> line 63, in 
> time.sleep(2)
> AttributeError: 'str' object has no attribute 'sleep'
Here's your clue: Do you have another string variable that apparently goes by
the name 'time' ? I have added another line to your snippet below. Running that
will throw the same error you see above. 
> 
> Using the following is okay:
> 
> import time
> print "Now"
time="hello"
> time.sleep(2)
> print "Later"
> 

HTH,

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


Re: [Tutor] Weird Error

2011-12-17 Thread Ken G.



On 12/17/2011 10:40 AM, Peter Otten wrote:

Ken G. wrote:


I have use 'sleep.time(5)' in most of my program but the following error
is throwing me for a loss.

import time
Traceback (most recent call last):
File "/home/ken/Python2/Blood Glucose/BloodGlucose04ReadingTimed.py",
line 63, in
  time.sleep(2)
AttributeError: 'str' object has no attribute 'sleep'

Using the following is okay:

import time
print "Now"
time.sleep(2)
print "Later"

Look for an assignment like

time = "whatever"

in module BloodGlucose04ReadingTimed.py.

Whew!  I search for "time" in the program and yes, I did have time as an
assignment in several places in the program prior to using time.sleep.

Changed the assigned time to timing.

Thanks guys.

Ken


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


[Tutor] Github Pygame Example Repository

2011-12-17 Thread ANKUR AGGARWAL
I have created an pygame example repo on github to promote the
learning of this API. check this out
https://github.com/ankur0890/Pygame-Examples-For-Learning . I created
an blog post of the same on my linux blog :
http:.//flossstuff.wordpress.com/2011/12/17/github-repository-for-pygame-examples/
. Suggestions and feedback would be great. Looking for contribution
too :)

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


[Tutor] unsupported operand

2011-12-17 Thread stm atoc
Hi there,

I would like to define concentration array based on time and then plot it.
Here is the profile:

from pylab import *
import numpy
import array
import math
tmax=1*3600
t  = 1.
outfile=open('ourtest_out.list','w')
N = 100
Conc1 = arange([0, tmax])
outfile.close()

lw = 2.0 #linewidth
dpi = 96
figure(figsize=(12,6),dpi=dpi)
pyplot.plot(Conc1, t,'r-',label='Conc' )
savefig('Conc.png')
show()

and this is the error that I got:

TypeError: unsupported operand type(s) for -: 'list' and 'int'

What would you suggest?
Thank you,
Sue
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsupported operand

2011-12-17 Thread bodsda
I would suggest a few things, like variable naming style consistency or the 
unused file that you open and close. You also have an unused lw variable, and 
does dpi really need to be a variable? Its only used once, why not hard code it.

But the main thing I suggest, is posting the 'complete' traceback, so we can 
see what caused the error. I'm gonna take a wild guess at it being the 
pyplot.plot call though, due to the data types that its moaning about.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: stm atoc 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sat, 17 Dec 2011 21:30:17 
To: tutor
Subject: [Tutor] unsupported operand

Hi there,

I would like to define concentration array based on time and then plot it.
Here is the profile:

from pylab import *
import numpy
import array
import math
tmax=1*3600
t  = 1.
outfile=open('ourtest_out.list','w')
N = 100
Conc1 = arange([0, tmax])
outfile.close()

lw = 2.0 #linewidth
dpi = 96
figure(figsize=(12,6),dpi=dpi)
pyplot.plot(Conc1, t,'r-',label='Conc' )
savefig('Conc.png')
show()

and this is the error that I got:

TypeError: unsupported operand type(s) for -: 'list' and 'int'

What would you suggest?
Thank you,
Sue
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Github Pygame Example Repository

2011-12-17 Thread Ken G.

The second link should be read as follow:

http://flossstuff.wordpress.com/2011/12/17/github-repository-for-pygame-examples/

You had an extra period after http:

Ken

On 12/17/2011 01:00 PM, ANKUR AGGARWAL wrote:

I have created an pygame example repo on github to promote the
learning of this API. check this out
https://github.com/ankur0890/Pygame-Examples-For-Learning . I created
an blog post of the same on my linux blog :
http:.//flossstuff.wordpress.com/2011/12/17/github-repository-for-pygame-examples/
. Suggestions and feedback would be great. Looking for contribution
too :)

Regards
Ankur Aggarwal


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


Re: [Tutor] unsupported operand

2011-12-17 Thread Steven D'Aprano

stm atoc wrote:


and this is the error that I got:


Would you like us to guess which line causes the error?

Please show the ENTIRE traceback. Do not retype it from memory, paraphrase or 
simplify it, or otherwise change it in any way. Copy and paste it.



TypeError: unsupported operand type(s) for -: 'list' and 'int'

What would you suggest?


The code sample you showed did not include any subtractions. This hints that 
perhaps you are not showing us all of the code you are actually running. The 
full traceback will answer that one way or the other.


Otherwise, I suggest you look at the line which the traceback prints. It 
probably has something like "result = a - b" (or some other subtraction). Look 
for the two variables: one of them is set to a list.



--
Steven

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


[Tutor] where does the ViewerFrameWorkGUI come from

2011-12-17 Thread lina
Hi,

I met below issue:

File "/usr/lib/python2.7/dist-packages/ViewerFramework/VF.py", line
369, in __init__
self.GUI = ViewerFrameworkGUI(self, title=title,
NameError: global name 'ViewerFrameworkGUI' is not defined


can someone tell me how to examine,

I mean, how to examine, what would you do when you face the problem?

Thanks with best regards,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor