Re: [Tutor] Long post: Request comments on starting code and test code on chess rating project.

2017-08-16 Thread Alan Gauld via Tutor
On 16/08/17 04:06, boB Stepp wrote:

>> I agree with Neil, this is exactly what SQL is good for and
>> would make this part of the project much easier and would have
>> the added benefit of introducing you to one of the trickiest,
>> but most common, bits of OOP - object persistence...
> 
> Would you expand on this in SQLite terms?

I'm not sure which bit you want expanded so I'll do both :-)

The reporting side is easily within SQLite's capabilities
once you have the table structures defined. And SQLite's
big benefit for this kind of project is that there is
no server involved just a single data file, so easy
to maintain. You can even use the in-memory mode if you
just want the SQL aspects and are happy to persist
your objects in text files(JSON maybe?) Simply load
the JSON data into SQLite in-memory tables to perform
the queries.

The persistence issue really has nothing to do with
SQLite per se. To persist (ie store) your objects
between program runs requires that you save them
to disk somehow. Simple classes can be saved in
simple text files. but as classes contain other
classes/objects that gets complex. The next step
is a formatted storage mechanism like XML or JSON
which can handle nested objects. The other issue
in persistence is when to save the objects? Do
you just load everything into memory at startup and
then write it all back at shutdown? Or do you
incrementally save all changes as they happen?
In a dynamic, garbage collecting language like
Python incremental saves are safer in case an
object gets deleted accidentally, before it is saved.

But sooner or later you will need to move to a database
and that brings the issues of translating a class
into tables - especially if inheritance is involved.
Do you have a table per class with superclass links?
Or do you duplicate the  superclass attributes in
each child table? There are no right answers and
figuring out the most effective mapping is one of
the big challenges in real world OOP projects.

Another option is to adopt an Object Relational
Mapper (ORM) which will create and manage the SQL
aspects for you - but in the process make reporting
more difficult.

And lastly you could use a NoSQL database like Mongo
which can more easily persist complex objects and has
a reasonable reporting language (especially if you
use Mongoose). But this is likely a much bigger learning
curve, especially if its the first time you've used
it.

For your project I suspect a JSON solution would
be fine for persistence but no help for reporting.
SQLite, especially if you don't have lots of
complex classes, gives both for low cost (both
resources and learning) assuming you know basic
SQL to start with.

-- 
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] "Path tree"

2017-08-16 Thread Alan Gauld via Tutor
On 16/08/17 02:02, Cameron Simpson wrote:

> Ok. So you have a graph like this:

>   1 -- 2 -- 3 -- 4
>|
>   7 -- 5 -- 6 -- 8
> 
>   graph = {
> 1: [2],
> 2: [1, 3],

  2: [1, 3, 5],

> 3: [2, 4],
> 4: [3],
> 5: [7, 6],

  5: [2, 6, 7],

> 6: [5, 8],
> 7: [5],
> 8: [6]
>   }

The missing link is pretty critical in this case :-)

-- 
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] pygame not working

2017-08-16 Thread Quantz Jeremy
I’m not sure if I should be asking here about this, but on my Mac computer, 
Pygame keeps crashing on me. I have Python 2.7.13 (I can’t use Python 3 because 
I’m learning from and online course and he’s using Python 2.7.13. Unless you 
can give me a list or something for all the differences, I am completely new to 
Python, and a beginner programer.) Mac OS X 32-bit i386/PPC installer. I got my 
version of Pygame from Pygame.org , I downloaded the 
pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg 
.
 It’s working until I actually try to draw anything on my screen. For example, 
I can run the following code and it works just fine.

import pygame

pygame.init()
screen = pygame.display.set_mode((900,700))

finished = False

while finished == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
finished = True

But when I run the following code, the Pygame window opens for a split second, 
then closes and I get a message from my Mac saying Python (My pygame window, 
not Python IDLE) quit unexpectedly. I’ve looked to see where it crashes and 
it’s when it reaches where it’s suppose to draw the rectangle. I can’t even see 
the rectangle for the split second while it’s open. (which if it crashes at 
that part, it makes sense.) 

import pygame

pygame.init()
screen = pygame.display.set_mode((900,700))

finished = False

while finished == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
finished = True

rectOne = pygame.Rect(0,0,800,450)

color = (0,0,255) #R,G,B
pygame.draw.rect(screen,color,rectOne)
pygame.display.flip()

I’ll try and give you as much info about my Mac as I can, as I think it’s the 
computer itself that’s the problem. But if you can’t help me, I do have a 
windows 10 laptop that I’ve tried putting Pygame on that we could see if you 
could help me put Pygame on that. I can’t seem to get the right one. I’d rather 
it on the Mac. I have tried many tutorials as well and nothing is working. I 
have a 2010 iMac (Old I know) with a 3.06 GHz Intel Core i3 Processor. Graphics 
are ATI Radeon HD 4670 256 MB. My OS Is X El Capitan Version 10.11.6. I don’t 
know what of that info you need, or if you need more, but that’s about it. If 
you could please help me with my problem, it would be much appreciated. I 
already tried stack overflow, and that didn’t work. I also think it is the 
computer because someone on there ran my code and it worked just fine. Thanks.
~Ethan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pygame not working

2017-08-16 Thread Alan Gauld via Tutor
On 16/08/17 17:33, Quantz Jeremy wrote:
> I’m not sure if I should be asking here about this,

Strictly speaking no, this list is for questions about
Python and its standard library. So PyGame issues should
really go to the PyGame support fora, and that's still
the best place for detailed support. Here's the top
level link:

http://www.pygame.org/wiki/info?parent=

The getting started page is worth reading too if you
haven't already.

But...

>  ...I have Python 2.7.13 ...Mac OS X 32-bit i386/PPC installer. 

Because you've given us so much detail there's a fair
chance somebody here will try and help.

You shouldn't need to go to Windows, the Mac version should
be fine. OTOH the windows version of pyGame should be
fine too!

-- 
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] pygame not working

2017-08-16 Thread boB Stepp
On Wed, Aug 16, 2017 at 11:33 AM, Quantz Jeremy  wrote:
> I’m not sure if I should be asking here about this, but on my Mac computer, 
> Pygame keeps crashing on me. I have Python 2.7.13 (I can’t use Python 3 
> because I’m learning from and online course and he’s using Python 2.7.13. 
> Unless you can give me a list or something for all the differences, I am 
> completely new to Python, and a beginner programer.) Mac OS X 32-bit i386/PPC 
> installer. I got my version of Pygame from Pygame.org , I 
> downloaded the pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg 
> .
>  It’s working until I actually try to draw anything on my screen. For 
> example, I can run the following code and it works just fine.

[snip]

> But when I run the following code, the Pygame window opens for a split 
> second, then closes and I get a message from my Mac saying Python (My pygame 
> window, not Python IDLE) quit unexpectedly. I’ve looked to see where it 
> crashes and it’s when it reaches where it’s suppose to draw the rectangle. I 
> can’t even see the rectangle for the split second while it’s open. (which if 
> it crashes at that part, it makes sense.)
>

[snip]

> I’ll try and give you as much info about my Mac as I can, as I think it’s the 
> computer itself that’s the problem. But if you can’t help me, I do have a 
> windows 10 laptop that I’ve tried putting Pygame on that we could see if you 
> could help me put Pygame on that. I can’t seem to get the right one. I’d 
> rather it on the Mac. I have tried many tutorials as well and nothing is 
> working. I have a 2010 iMac (Old I know) with a 3.06 GHz Intel Core i3 
> Processor. Graphics are ATI Radeon HD 4670 256 MB. My OS Is X El Capitan 
> Version 10.11.6. I don’t know what of that info you need, or if you need 
> more, but that’s about it. If you could please help me with my problem, it 
> would be much appreciated. I already tried stack overflow, and that didn’t 
> work. I also think it is the computer because someone on there ran my code 
> and it worked just fine. Thanks.

I did a quick search and a couple of things came up that *might* be
related to your issue (I am *not* an expert in programming!).  One
thing that came up is that if you are running IDLE, which relies on
Tkinter, and pygame at the same time, they both try to run their own
event loops and this can cause conflicts.  Are you starting your
pygame program from within IDLE?  If yes, you may want to instead
start your program from within the terminal window.  The other is are
you sure that your program is running with the version of Python you
think it is?  If you installed a later version of Python 2 yourself
you may in fact be running an older version of Python 2 with your
program, the one supplied originally with your Mac which is the system
default.  But I am just guessing here!


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


Re: [Tutor] "Path tree"

2017-08-16 Thread Cameron Simpson

On 16Aug2017 10:22, Alan Gauld  wrote:

On 16/08/17 02:02, Cameron Simpson wrote:

Ok. So you have a graph like this:



  1 -- 2 -- 3 -- 4
   |
  7 -- 5 -- 6 -- 8

  graph = {
1: [2],
2: [1, 3],


 2: [1, 3, 5],


3: [2, 4],
4: [3],
5: [7, 6],


 5: [2, 6, 7],


6: [5, 8],
7: [5],
8: [6]
  }


The missing link is pretty critical in this case :-)


Hmm, yes. Thanks!

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pygame not working

2017-08-16 Thread Steven D'Aprano
Hi Quantz Jeremy, or Ethan, which do you prefer?

On Wed, Aug 16, 2017 at 10:33:05AM -0600, Quantz Jeremy wrote:

> I already tried stack overflow, and that didn’t work.

What did you ask, and what answers did they give that didn't work? Or is 
it a secret? :-)



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


[Tutor] (no subject)

2017-08-16 Thread Howard Lawrence
class Address:
def _init_(self,Hs,St,Town,Zip):
  self.HsNunber=Hs
  self.Street=St
  self.Town=Town
  self.Zip=Zip
Addr=Address (7, ' high st', 'anytown', ' 123 456')


Traceback (most recent call last):
File "", line 1, in< module>
Addr = Address (7, 'High St', 'anytown', '123 456')
TypeError: object () takes no parameters

 how to fix this and where I went wrong

 This happened to me in other coding
But I skipped it,but it keeps returning!
This is from a tutorial
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Object takes no parameters

2017-08-16 Thread Howard Lawrence
class Human:
 def _init_(self, n, o)
  self.name = n
  self.occupation = o

 def do_work(self):
 if self.occupation== 'tennis player':
print(self.name, 'plays tennis')

 elif self.occupation == 'actor':
print(self.name, 'shoots film')

 def speaks(self):
 print(self.name, 'how are you')

tom = Human('tom cruise', 'actor')
tom.do_work()
tom.speak()

Traceback most recent call last
File "c:\users\shaun\python\python35\human_class.py"line 16 in module
tom =Human('tom cruise', 'actor')
TypeError: object() takes no parameters

how to fix this?why it happens?
this happens whenever i try to do
class,this is from a tutorial
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2017-08-16 Thread Zachary Ware
Hi Howard,

On Wed, Aug 16, 2017 at 5:36 PM, Howard Lawrence <1019sh...@gmail.com> wrote:
> class Address:
> def _init_(self,Hs,St,Town,Zip):

Your issue is in this line, it should be `__init__` rather than
`_init_` (that is, two underscores before and after "init").

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


Re: [Tutor] Object takes no parameters

2017-08-16 Thread Alan Gauld via Tutor
On 17/08/17 01:08, Howard Lawrence wrote:
> class Human:
>  def _init_(self, n, o)
>   self.name = n
>   self.occupation = o
> 

> 
> tom = Human('tom cruise', 'actor')
> 
> Traceback most recent call last
> File "c:\users\shaun\python\python35\human_class.py"line 16 in module
> tom =Human('tom cruise', 'actor')
> TypeError: object() takes no parameters
> 
> how to fix this?why it happens?

If you look closely at your tutorial you will find that init()
has two underscores before and after the name:

def __init__()

rather than

def _init_()

The reason for your error is that all classes inherit from object.
So when you call Human() the interpreter looks for an __init__()
method and, not finding one(because yours only has one undercore),
it looks at the one defined in object. But the object init()
takes no parameters and so there is a mismatch between your
call to Human() and the object.__init__() definition.
Hence the error message.

To fix it use two underscores.

All of the "magic" methods used by Python have these double
underscores and  hence are often referred to as "dunder" methods.
You should avoid defining any new methods (ie new names) with
double underscores yourself, in case Python introduces  a
similar method in a future version.

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] (no subject)

2017-08-16 Thread Alan Gauld via Tutor
On 16/08/17 23:36, Howard Lawrence wrote:
> class Address:
> def _init_(self,Hs,St,Town,Zip):
>   self.HsNunber=Hs
>   self.Street=St
>   self.Town=Town
>   self.Zip=Zip
> Addr=Address (7, ' high st', 'anytown', ' 123 456')

That looks suspiciously like my tutorial ;-)

The answer is to use two underscores around init():

def __init__(...)

not

def _init_(...)

This is explained in more detail in a box at the end
of the data topic:

http://www.alan-g.me.uk/l2p/tutdata.htm

-- 
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