Re: [Tutor] Tutor Digest, Vol 146, Issue 9

2016-04-09 Thread khalil zakaria Zemmoura
Hi,
there is one place i think you have to have a look at it and it's the
python official site.

One thing i love about python is the so well written documentation, i
remember when i was learning ruby and had to go to the official doc! it was
hard to understand for the beginner how i was. so, here is the link
https://docs.python.org/3/tutorial/index.html

Good luck

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


Re: [Tutor] Tutor Digest, Vol 146, Issue 9

2016-04-08 Thread Alan Gauld
On 08/04/16 17:44, Jason Willis wrote:

> there are hard-coded content dependant entries. I solved this by changing
> all instances of the word "elite" and changing them to "standard" and the
> program works! 

Glad you got it working.

> I agree with you that taking a few hours to learn python
> would go a long way. I believe by doing things like this that this is
> exactly what I am doing. 

I don't know that you are. You are reading and playing with other
people's code. But you don't know if what you are reading is good
or bad code. For example the code you just posted is not that
great it (unnecessarily) mixes two different techniques for
processing the text and has several awkward stylistic things
going on. Also do you know what classes are for and when/how they should
be used? In the code example you sent there are two
classes and two functions, but why? And is that a good idea?

Just because something gives you the answer you expect today does
not mean it will tomorrow if it is not properly designed.
How do you know when the code you modify is well designed
unless you know what it all does? How will you fix it
if/when it breaks?

> I don't know if it's the materials I'm using or
> what but learning from a book is not helping me much. 

There are many online tutorials (see below for mine) but there
are also videos galore on Youtube/Vimeo etc.

I personally like the ShowMeDo series:

http://showmedo.com/videos/python

And there are interactive code schools online too that many
find more inspiring than reading books.

Here's one you might try:

http://www.learnpython.org/

But there are several others.

Don't get me wrong, reading and playing code is an important part of
learning to code. But even more important is creating your own code from
scratch. Only then are you forced to confront what each and every line
does and thus be sure you understand it.

And the great thing about Python is you can get up to a useful
standard with literally a few (<10?) hours of reading/practising.

-- 
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] Tutor Digest, Vol 146, Issue 9

2016-04-08 Thread Jason Willis
My apologies for the word wrap. It seemed to look ok in my web client
(gmail). Thank you for the pointer to other instances in the program where
there are hard-coded content dependant entries. I solved this by changing
all instances of the word "elite" and changing them to "standard" and the
program works! I agree with you that taking a few hours to learn python
would go a long way. I believe by doing things like this that this is
exactly what I am doing. I don't know if it's the materials I'm using or
what but learning from a book is not helping me much. Maybe you all have
better ideas about sources that would be helpful in moving me along into
learning python.

Thanks again!

On Fri, Apr 8, 2016 at 12:00 PM,  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. Re: Declaring variables (Mark Lawrence)
>2. Re: customizing dark_harvest problems (Alan Gauld)
>3. Re: customizing dark_harvest problems (Ben Finney)
>
>
> --
>
> Message: 1
> Date: Thu, 7 Apr 2016 22:51:05 +0100
> From: Mark Lawrence 
> To: tutor@python.org
> Subject: Re: [Tutor] Declaring variables
> Message-ID: 
> Content-Type: text/plain; charset=windows-1252; format=flowed
>
> On 07/04/2016 18:49, Dimitar Ivanov wrote:
> > Hello everyone,
> >
> > I have a (hopefully) quick and easy to explain question. I'm currently
> > using MySQLdb module to retrieve some information from a database. In my
> > case, the result that's being yield back is a single line.
> >
> > As far as my understanding goes, MySQLdb function called 'fetchone()'
> > returns the result as a tuple. Problem is, the tuple has some unnecessary
> > characters, such as an additional comma being returned. In my case:
> >
>    idquery = 'select id from table;'
>    cur = mysql.cursor()
>    cur.execute(idquery)
>    id = cur.fetchone()
>
> Note that using 'id' is frowned upon as you're overriding the builtin of
> the same name.  I'll use id_ below.
>
>    print id
> > ('idinhere',)
>
> No, it isn't an additional comma, it's a tuple that only has one field.
>
> >
> > I stumbled across an example given like this:
> >
>    (id,) = cur.fetchone()
> >
> > So I decided to give it a try and the result is exactly what I need:
> >
>    (id,) = cur.fetchone()
>    print id
> > idinhere
> >
> > My question is - can I reliably use this method? Is it always going to
> > return the string between the brackets as long as I define the variable
> > with '(,)'? I'm planning to use another query that will be using the
> result
> > from this one and then update another database with this result but I
> must
> > be sure that the variable will always be the string in and between the
> > brackets otherwise I'm risking to mess up a lot of things big time.
>
> I'd write it as:-
>
> id_ = cur.fetchone()[0]
>
> >
> > A backup plan I had was to use the following:
> >
>    id = cur.fetchone()
>    for x in id:
>  id = x
>
> Yuck :)
>
> >
> > But if the method above is certain to always return only the value I
> need,
> > I find it to be a far more elegant solution.
> >
> > Also, just to clarify things for myself - what does this method of
> > declaring variables do exactly? I'm sorry if this isn't the right place
> the
> > ask and if this has been documented clearly already, I'm not sure what to
> > use as a search term in order to find an answer.
>
> In Python nothing is declared as in C or Java. A name is bound to an
> object.  So from the above the name 'id_' is bound to the string object
> that happens to be 'idinhere'.  Once this has been done there is nothing
> to stop you from writing:-
>
> id_ = 1
> id_ = 1.0
> id_ = Point(1, 2)
> id_ = Complicated(lots, of, parameters, here)
>
> >
> > Thanks a lot in advance! I hope I posted all the details needed and my
> > question is easy to comprehend.
>
> The only things that are sometimes needed are your OS and Python
> version.  The latter can be deduced from your 'print id' rather than
> 'print(id)', indicating that it is 2.x, not 3.y.
>
> >
> > Regards,
> > Dimitar
> >
>
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
>
>
> --
>
> Message: 2
> Date: Fri, 8 Apr 2016 02:10:55 +0100
> From: Alan Gauld 
> To: tutor@python.org
> Subject: Re: [Tutor] customizing