Classes

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Classes

Marc Stevens
Hallo, beste python gangers,

Ik heb het volgende probleem simplistisch weergegeven in de bijlage.Ik hoop dat het niet te basic is.Als het werkt kan ik dit bij complexere programma’s toepassen.
Om delen van programma’s laten herhalen kun je in python met classes werken en omdat je in python (dat afgeleid is van het langgeleden Basic) geen adres regels heeft ,
kun je die die met een naam aan roepen

Zou U mij kort kunnen vertellen wat ik in de bijlage verkeerd doe en hoe ik een class correct aan roep? 


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl

test.py (156 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Classes

Frank van Wijgerden

Verander "class" in "def" en zet er "()" achter, zodat eerste regel "def proefje():" wordt. Gefeliciteerd, nu werkt het als method/function. Maar het is geen class... Weet niet of Python site goede introductie heeft, maar er zijn gratis boeken te vinden, zelfs in het nederlands; bijvoorbeeld http://nl.m.wikibooks.org/wiki/Programmeren_in_Python (weet niet wat de kwaliteit is...). Succes, Frank

Op 14 okt. 2014 21:22 schreef "Marc Stevens" <[hidden email]>:
Hallo, beste python gangers,

Ik heb het volgende probleem simplistisch weergegeven in de bijlage.Ik hoop dat het niet te basic is.Als het werkt kan ik dit bij complexere programma’s toepassen.
Om delen van programma’s laten herhalen kun je in python met classes werken en omdat je in python (dat afgeleid is van het langgeleden Basic) geen adres regels heeft ,
kun je die die met een naam aan roepen

Zou U mij kort kunnen vertellen wat ik in de bijlage verkeerd doe en hoe ik een class correct aan roep? 


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes

Perica Zivkovic
In reply to this post by Marc Stevens
Hi Marc,

here is a simple description of Python class syntax and couple of examples. 


kind regards,

Perica

2014-10-14 21:03 GMT+02:00 Marc Stevens <[hidden email]>:
Hallo, beste python gangers,

Ik heb het volgende probleem simplistisch weergegeven in de bijlage.Ik hoop dat het niet te basic is.Als het werkt kan ik dit bij complexere programma’s toepassen.
Om delen van programma’s laten herhalen kun je in python met classes werken en omdat je in python (dat afgeleid is van het langgeleden Basic) geen adres regels heeft ,
kun je die die met een naam aan roepen

Zou U mij kort kunnen vertellen wat ik in de bijlage verkeerd doe en hoe ik een class correct aan roep? 


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes

Dorian Hoxha
I can't undestand over google translate very well what you problem is but:

if a="j" will always be true,


To compare if a equals 'j' you must use ==, change it to :
if a == "j"

Also, looking at documentation for raw_input: https://docs.python.org/2/library/functions.html#raw_input

Look at the example how it should be used.

And you can't use a class like that, you could a function. While you can use an __init__ method on a class to execute a function everytime you create an object on that class.

And break is not necessary in the "else" clause.

I've attached the working-changed script.

2014-10-14 21:37 GMT+02:00 Perica Zivkovic <[hidden email]>:
Hi Marc,

here is a simple description of Python class syntax and couple of examples. 


kind regards,

Perica

2014-10-14 21:03 GMT+02:00 Marc Stevens <[hidden email]>:
Hallo, beste python gangers,

Ik heb het volgende probleem simplistisch weergegeven in de bijlage.Ik hoop dat het niet te basic is.Als het werkt kan ik dit bij complexere programma’s toepassen.
Om delen van programma’s laten herhalen kun je in python met classes werken en omdat je in python (dat afgeleid is van het langgeleden Basic) geen adres regels heeft ,
kun je die die met een naam aan roepen

Zou U mij kort kunnen vertellen wat ik in de bijlage verkeerd doe en hoe ik een class correct aan roep? 


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl

test.py (242 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Classes

Ward De Ridder-2
In reply to this post by Marc Stevens
On Tue, Oct 14, 2014 at 09:03:56PM +0200, Marc Stevens wrote:
> Hallo, beste python gangers,
>
> Ik heb het volgende probleem simplistisch weergegeven in de bijlage.Ik hoop dat het niet te basic is.Als het werkt kan ik dit bij complexere programma’s toepassen.
> Om delen van programma’s laten herhalen kun je in python met classes werken en omdat je in python (dat afgeleid is van het langgeleden Basic) geen adres regels heeft ,
> kun je die die met een naam aan roepen
>
> Zou U mij kort kunnen vertellen wat ik in de bijlage verkeerd doe en hoe ik een class correct aan roep?

Beste Marc

Als ik het voorbeeld even bekijk haalt u het concept class en function door elkaar.
Wat je hierboven beschrijft (dezelfde code op meerdere plaatsen in je programma gebruiken) is een function, die wordt gedefinieerd op de volgende manier:

  def proefje():
      ...

en aangeroepen met

  proefje()

Een class is eigenlijk een verzameling van zulke functions.

Ward
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Geert Stappers
In reply to this post by Marc Stevens
On Tue, Oct 14, 2014 at 09:03:56PM +0200, Marc Stevens wrote:
> Hallo, beste python gangers,
>
> Ik heb het volgende probleem simplistisch weergegeven in de bijlage.Ik
> hoop dat het niet te basic is.Als het werkt kan ik dit bij complexere
> programma?s toepassen.

class proefje:
    x=0
    while x<5:
        print x
        x=x+1

raw_input(a)="nog eens?j/n"
if a="j":
    proefje()
else:
    break

> Om delen van programma?s laten herhalen kun je in python met classes
> werken en omdat je in python (dat afgeleid is van het langgeleden Basic)
> geen adres regels heeft ,
> kun je die die met een naam aan roepen

Waarschijnlijk bedoelje "functie", in BASIC was dat een subroutine
in Python begint een funcie definitie met 'def '


> Zou U mij kort kunnen vertellen wat ik in de bijlage verkeerd doe en
> hoe ik een class correct aan roep?


def proefje():
    x=0
    while x<5:
        print x
        x=x+1

while 1:
    a=raw_input("nog eens?j/n")
    if a=="j":
        proefje()
    else:
        break



Groeten
Geert Stappers
--
Leven en laten leven
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Winfried Tilanus
On 10/14/2014 09:42 PM, Geert Stappers wrote:

Hoi,

> def proefje():
>     x=0
>     while x<5:
>         print x
>         x=x+1
>
> while 1:
>     a=raw_input("nog eens?j/n")
>     if a=="j":
>         proefje()
>     else:
>         break

Ik vraag me wel af of we nu niet iemands huiswerk hebben zitten maken... ;-)

groet,

Winfried
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Dorian Hoxha
We probably did.

2014-10-15 10:54 GMT+02:00 Winfried Tilanus <[hidden email]>:
On 10/14/2014 09:42 PM, Geert Stappers wrote:

Hoi,

> def proefje():
>     x=0
>     while x<5:
>         print x
>         x=x+1
>
> while 1:
>     a=raw_input("nog eens?j/n")
>     if a=="j":
>         proefje()
>     else:
>         break

Ik vraag me wel af of we nu niet iemands huiswerk hebben zitten maken... ;-)

groet,

Winfried
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Guido Wesdorp-3
Actually, I assume we're dealing with someone who has surpassed the high-school age a bit  (no offence!! :) , since he thinks 'Python is like Basic, but without the line numbers' and I think the last Basic I've dealt with that had line numbers was pre-Amiga or so... :) I assume this is someone who wants to pick up Python as a hobby (or perhaps needs a couple of lines of code for some work-related project) after playing with Basic on a C-64 or ZX-something or so?

Anyway, I think it would make sense for Marc to read some entry-level docs before asking questions here, this stuff is so basic that if you don't know that, you will most probably want to read the other 101 stuff too, and asking here before reading the beginner docs is time-consuming, not only for us, but also for him... I would say, first thing to do would be to visit docs.python.org and read https://docs.python.org/2/tutorial/index.html (or replace the 2 with 3 for the latest Python version), then tinker about a bit, then if you really get stuck ask here (I assume you haven't read the docs, else you would probably have known that functions ('def') are used for 'subroutines' and 'class' is more of a container of data and functions rather than a callable block of code).

Cheers,

Guido

On Wed, Oct 15, 2014 at 11:02 AM, Dorian Hoxha <[hidden email]> wrote:
We probably did.

2014-10-15 10:54 GMT+02:00 Winfried Tilanus <[hidden email]>:
On 10/14/2014 09:42 PM, Geert Stappers wrote:

Hoi,

> def proefje():
>     x=0
>     while x<5:
>         print x
>         x=x+1
>
> while 1:
>     a=raw_input("nog eens?j/n")
>     if a=="j":
>         proefje()
>     else:
>         break

Ik vraag me wel af of we nu niet iemands huiswerk hebben zitten maken... ;-)

groet,

Winfried
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Perica Zivkovic
+1 for referring to doc's

cheers,

Perica

On Wed, Oct 15, 2014 at 11:18 AM, Guido Wesdorp <[hidden email]> wrote:
Actually, I assume we're dealing with someone who has surpassed the high-school age a bit  (no offence!! :) , since he thinks 'Python is like Basic, but without the line numbers' and I think the last Basic I've dealt with that had line numbers was pre-Amiga or so... :) I assume this is someone who wants to pick up Python as a hobby (or perhaps needs a couple of lines of code for some work-related project) after playing with Basic on a C-64 or ZX-something or so?

Anyway, I think it would make sense for Marc to read some entry-level docs before asking questions here, this stuff is so basic that if you don't know that, you will most probably want to read the other 101 stuff too, and asking here before reading the beginner docs is time-consuming, not only for us, but also for him... I would say, first thing to do would be to visit docs.python.org and read https://docs.python.org/2/tutorial/index.html (or replace the 2 with 3 for the latest Python version), then tinker about a bit, then if you really get stuck ask here (I assume you haven't read the docs, else you would probably have known that functions ('def') are used for 'subroutines' and 'class' is more of a container of data and functions rather than a callable block of code).

Cheers,

Guido

On Wed, Oct 15, 2014 at 11:02 AM, Dorian Hoxha <[hidden email]> wrote:
We probably did.

2014-10-15 10:54 GMT+02:00 Winfried Tilanus <[hidden email]>:
On 10/14/2014 09:42 PM, Geert Stappers wrote:

Hoi,

> def proefje():
>     x=0
>     while x<5:
>         print x
>         x=x+1
>
> while 1:
>     a=raw_input("nog eens?j/n")
>     if a=="j":
>         proefje()
>     else:
>         break

Ik vraag me wel af of we nu niet iemands huiswerk hebben zitten maken... ;-)

groet,

Winfried
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Dirkjan Ochtman
In reply to this post by Guido Wesdorp-3
On Wed, Oct 15, 2014 at 11:18 AM, Guido Wesdorp <[hidden email]> wrote:

> Anyway, I think it would make sense for Marc to read some entry-level docs
> before asking questions here, this stuff is so basic that if you don't know
> that, you will most probably want to read the other 101 stuff too, and
> asking here before reading the beginner docs is time-consuming, not only for
> us, but also for him... I would say, first thing to do would be to visit
> docs.python.org and read https://docs.python.org/2/tutorial/index.html (or
> replace the 2 with 3 for the latest Python version), then tinker about a
> bit, then if you really get stuck ask here (I assume you haven't read the
> docs, else you would probably have known that functions ('def') are used for
> 'subroutines' and 'class' is more of a container of data and functions
> rather than a callable block of code).

Yeah, I very much feel this isn't a great forum for this kind of
discussion (that is, very basic Python questions). Or at least, it's
very far from the type of discussion I subscribe to this list for. On
the other hand, other subscribers don't seem to mind, and if this is
the rare forum where questions can be asked in Dutch, maybe that is a
valid purpose for this list.

Cheers,

Dirkjan
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Dexter-24
In reply to this post by Perica Zivkovic
When looking for problems to solve while learning python you can try out http://www.pythonchallenge.com/


Dexter - DexterLabs.nl

On Wed, Oct 15, 2014 at 11:20 AM, Perica Zivkovic <[hidden email]> wrote:
+1 for referring to doc's

cheers,

Perica

On Wed, Oct 15, 2014 at 11:18 AM, Guido Wesdorp <[hidden email]> wrote:
Actually, I assume we're dealing with someone who has surpassed the high-school age a bit  (no offence!! :) , since he thinks 'Python is like Basic, but without the line numbers' and I think the last Basic I've dealt with that had line numbers was pre-Amiga or so... :) I assume this is someone who wants to pick up Python as a hobby (or perhaps needs a couple of lines of code for some work-related project) after playing with Basic on a C-64 or ZX-something or so?

Anyway, I think it would make sense for Marc to read some entry-level docs before asking questions here, this stuff is so basic that if you don't know that, you will most probably want to read the other 101 stuff too, and asking here before reading the beginner docs is time-consuming, not only for us, but also for him... I would say, first thing to do would be to visit docs.python.org and read https://docs.python.org/2/tutorial/index.html (or replace the 2 with 3 for the latest Python version), then tinker about a bit, then if you really get stuck ask here (I assume you haven't read the docs, else you would probably have known that functions ('def') are used for 'subroutines' and 'class' is more of a container of data and functions rather than a callable block of code).

Cheers,

Guido

On Wed, Oct 15, 2014 at 11:02 AM, Dorian Hoxha <[hidden email]> wrote:
We probably did.

2014-10-15 10:54 GMT+02:00 Winfried Tilanus <[hidden email]>:
On 10/14/2014 09:42 PM, Geert Stappers wrote:

Hoi,

> def proefje():
>     x=0
>     while x<5:
>         print x
>         x=x+1
>
> while 1:
>     a=raw_input("nog eens?j/n")
>     if a=="j":
>         proefje()
>     else:
>         break

Ik vraag me wel af of we nu niet iemands huiswerk hebben zitten maken... ;-)

groet,

Winfried
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl


_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl



_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl
Reply | Threaded
Open this post in threaded view
|

Re: Classes om delen van programma te herhalen

Jochem Oosterveen
In reply to this post by Dirkjan Ochtman
On 15 Oct 2014, at 11:25, Dirkjan Ochtman <[hidden email]> wrote:
> Yeah, I very much feel this isn't a great forum for this kind of
> discussion (that is, very basic Python questions). Or at least, it's
> very far from the type of discussion I subscribe to this list for. On
> the other hand, other subscribers don't seem to mind, and if this is
> the rare forum where questions can be asked in Dutch, maybe that is a
> valid purpose for this list.

It’s actually in the description:

"[python-nl] is the main discussion channel for PUN, the 'Python Usergroup Nederland', and for Dutch Python users in general. The channel, though used by some hard-core Python geeks - remember Python is has Dutch roots! - is open to anyone and very 'newbie-friendly’.”

However, if someone considers it as his personal helpdesk for all kinds of basic python stuff for which he apparently doesn’t want to do the effort of actually doing any research at all… In the archives I see Marc Stevens first question being asked in May and we’re currently explaining to him what a float is? There is a limit to newbie-friendlyness, I’d say.
_______________________________________________
Python-nl mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/python-nl