From alan.gauld at yahoo.co.uk  Thu Feb  1 05:14:34 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 1 Feb 2018 10:14:34 +0000
Subject: [Tutor] unable to locate python on mac
In-Reply-To: <20180201021529.GK26553@ando.pearwood.info>
References: <9FDB173A-AACF-47D2-B0D4-1267F9990940@gmail.com>
 <p4t667$l8g$1@blaine.gmane.org> <20180201021529.GK26553@ando.pearwood.info>
Message-ID: <p4up6a$4qh$1@blaine.gmane.org>

On 01/02/18 02:15, Steven D'Aprano wrote:

> You can also run:
> 
> sys.executable

I'd forgotten that one...

> 
> from Python itself. For example, on my system:
> 
> py> sys.executable
> '/usr/local/bin/python3.5'

For the benefit of the OP, you need to import sys first
so it looks like:

>>> import sys
>>> sys.executable


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



From wwhhss at lzu.edu.cn  Thu Feb  1 05:43:11 2018
From: wwhhss at lzu.edu.cn (House WANG)
Date: Thu, 1 Feb 2018 18:43:11 +0800
Subject: [Tutor] Python36.dll
Message-ID: <1B744EF1-80F5-46C5-9046-424E3D7EBFD8@lzu.edu.cn>

> Dear python manager:
> I can use python3.6.4,I can use 3.6.4 zip, but I cannt use python 3.6.4exe version, when installed 3.6.4exe, open cmd python, pop python36.dll missing. I copy 3.6.4zip(unzip) python36.dll into system32 and systemWow64 both, it cannt solve the bug?
> ?use win10 64
> Hope your answer!

> ???
> ????????
> ?????????????222#
> ???Zip code??730000
> ???Tel??13659318365
> House WANG
> School of Management, Lanzhou University
> Add: 222# Tianshui Road, Lanzhou, Gansu, P. R. China
> 
> Best regards!

From laprea21 at ensworth.com  Thu Feb  1 21:44:06 2018
From: laprea21 at ensworth.com (Anna Lapre)
Date: Thu, 1 Feb 2018 20:44:06 -0600
Subject: [Tutor] New Line Problem
Message-ID: <CALntM2d89S9We7=ir8KOU8ALSn5VN+H-qjGMdxmhLcD6OHsXNg@mail.gmail.com>

I am having a problem with creating a new line in a return statement for a
function. It has a mix of a bunch of strings and variables. Everything that
I want included will print, except for the new lines. I have tried "\n" but
with no luck. Do you have any recommendations? Thanks.

http://py3.codeskulptor.org/#user301_SIdBE94Q8yi3qtM.py
(it's the second function)

From __peter__ at web.de  Fri Feb  2 04:17:51 2018
From: __peter__ at web.de (Peter Otten)
Date: Fri, 02 Feb 2018 10:17:51 +0100
Subject: [Tutor] New Line Problem
References: <CALntM2d89S9We7=ir8KOU8ALSn5VN+H-qjGMdxmhLcD6OHsXNg@mail.gmail.com>
Message-ID: <p51a82$q8l$1@blaine.gmane.org>

Anna Lapre wrote:

> I am having a problem with creating a new line in a return statement for a
> function. It has a mix of a bunch of strings and variables. Everything
> that I want included will print, except for the new lines. I have tried
> "\n" but with no luck. Do you have any recommendations? Thanks.
> 
> http://py3.codeskulptor.org/#user301_SIdBE94Q8yi3qtM.py
> (it's the second function)

"\n" is indeed what you need:

>>> equal = "================"
>>> index = 2
>>> line1 = "helllo"
>>> line2 = "heillo"
>>> print(line1 + "\n" + equal[:index] + "^\n" + line2)
helllo
==^
heillo

Note that you can repeat a string with

>>> "=" * 3
'==='
>>> "ab" * 2
'abab'

which combined with str.format allows the following alternative solutions:

>>> print("{}\n{}^\n{}".format(line1, "=" * index, line2))
helllo
==^
heillo

# requires Python 3.6
>>> print(f"{line1}\n{'='*index}^\n{line2}")
helllo
==^
heillo



From alan.gauld at yahoo.co.uk  Fri Feb  2 04:26:59 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Fri, 2 Feb 2018 09:26:59 +0000
Subject: [Tutor] New Line Problem
In-Reply-To: <CALntM2d89S9We7=ir8KOU8ALSn5VN+H-qjGMdxmhLcD6OHsXNg@mail.gmail.com>
References: <CALntM2d89S9We7=ir8KOU8ALSn5VN+H-qjGMdxmhLcD6OHsXNg@mail.gmail.com>
Message-ID: <p51ap3$i76$1@blaine.gmane.org>

On 02/02/18 02:44, Anna Lapre wrote:
> I am having a problem with creating a new line in a return statement for a
> function. It has a mix of a bunch of strings and variables. Everything that
> I want included will print, except for the new lines. I have tried "\n" but
> with no luck. Do you have any recommendations? Thanks.
> 
> http://py3.codeskulptor.org/#user301_SIdBE94Q8yi3qtM.py
> (it's the second function)

For a short function like this just post the code in the message, its
much easier to work with.

def singleline_diff_format(line1, line2, idx):
    length_line1 = len(line1)
    length_line2 = len(line2)
    if (idx + 1) <= length_line1 and (idx + 1) <= length_line2:
        equal = "===================================================="
        code = (line1 +
                equal[0:idx] + "^" +
                line2)
        return code
    else:
        return ""

You just need to add newline characters around the equal line.

        code = (line1 +
                '\n'+ equal[0:idx] + "^" + '\n' +
                line2)

Or using a format string:

code = "%s\n%s\n%s" % (line1,equal[:idx]+'^',line2)

You also are not implementing the part of your specification
that says return an empty string if either input contains a
newline. testing the lengths does not work:

>>> s = "fred\njones"
>>> len(s)
10

You need to test whether '\n' is in the string.

By the way, your first function is much more complicated
than it needs to be, it is very inefficient and I'm pretty
sure its wrong too. Try:

singleline_diff("part trap", "part part")

And see if you get the right answer.

But you can make it a whole lot simpler if you just
compare the characters one by one and stop messing
around with indexes.

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



From alan.gauld at yahoo.co.uk  Fri Feb  2 13:01:02 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Fri, 2 Feb 2018 18:01:02 +0000
Subject: [Tutor] Updates to web tutor
In-Reply-To: <cfed362f-03d8-4402-958a-e271a2f4960f@yahoo.co.uk>
References: <cfed362f-03d8-4402-958a-e271a2f4960f@yahoo.co.uk>
Message-ID: <p528su$j60$1@blaine.gmane.org>

On 15/11/17 17:41, Alan Gauld via Tutor wrote:

Hopefully my last on this topic.

I've just uploaded the new landing page for my web site.
Aside from being more mobile friendly it also has a wider
remit than before, being a gateway to more than just my
programming tutorial.

As ever feedback is appreciated (link is in the .sig).

-- 
Alan G
http://www.alan-g.me.uk/



From steve at pearwood.info  Fri Feb  2 18:06:49 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 3 Feb 2018 10:06:49 +1100
Subject: [Tutor] Python36.dll
In-Reply-To: <1B744EF1-80F5-46C5-9046-424E3D7EBFD8@lzu.edu.cn>
References: <1B744EF1-80F5-46C5-9046-424E3D7EBFD8@lzu.edu.cn>
Message-ID: <20180202230648.GP26553@ando.pearwood.info>

You should not be trying to copy Python.exe by hand, you should use the 
installer:

https://www.python.org/downloads/release/python-364/

Use the installer and let it install Python to where it needs to go. If 
you still have problems, you will have to tell us how you are trying to 
start Python and the EXACT error message you get.


On Thu, Feb 01, 2018 at 06:43:11PM +0800, House WANG wrote:
> > Dear python manager:
> > I can use python3.6.4,I can use 3.6.4 zip, but I cannt use python 3.6.4exe version, when installed 3.6.4exe, open cmd python, pop python36.dll missing. I copy 3.6.4zip(unzip) python36.dll into system32 and systemWow64 both, it cannt solve the bug?
> > ?use win10 64
> > Hope your answer!


-- 
Steve

From jselby68 at gmail.com  Fri Feb  2 21:12:46 2018
From: jselby68 at gmail.com (JSelby)
Date: Fri, 2 Feb 2018 18:12:46 -0800
Subject: [Tutor] help with some code for my 8 year old! Thank you.
Message-ID: <5A4789F7-69F5-428E-8496-C98D65E2FDC1@gmail.com>

   My 8 year old is reading  Python for kids and is trying a few programs
   from the book We are working on a Mac  OS X ELCapitain.  We are looking at
   WHACK THE BOUNCING BALL.
   He has copied the code  below and we get the red error message below. We
   followed the code exactly so are not sure what is wrong. Please can you
   help.
   Object: [1]application/x-apple-msg-attachment
   Object: [2]application/x-apple-msg-attachment
   Julie Selby
   [3]julie at beaglestrategy.com
   Tel: 604 762 1968
   [4]http://ca.linkedin.com/in/julieselby/
   [5]www.beaglestrategy.com

References

   Visible links
   1. file:///tmp/cid:BC5630A8-FD4A-488B-9979-8A8936D74EC7 at hitronhub.home
   2. file:///tmp/cid:80B89FF3-BA17-444D-8E95-8C63CCF4851F at hitronhub.home
   3. mailto:julie at beaglestrategy.com
   4. http://ca.linkedin.com/in/julieselby/
   5. http://www.beaglestrategy.com/

From wombingsac at gmail.com  Sat Feb  3 04:34:24 2018
From: wombingsac at gmail.com (Whom Isac)
Date: Sat, 03 Feb 2018 19:34:24 +1000
Subject: [Tutor] help with some code for my 8 year old! Thank you.
In-Reply-To: <5A4789F7-69F5-428E-8496-C98D65E2FDC1@gmail.com>
References: <5A4789F7-69F5-428E-8496-C98D65E2FDC1@gmail.com>
Message-ID: <dc7bb05d-b2aa-4ff1-8c0e-2f128d199c42@gmail.com>

Sorry can't see any error messages through the visible links.

On 3 Feb. 2018, 7:08 pm, at 7:08 pm, JSelby <jselby68 at gmail.com> wrote:
> My 8 year old is reading  Python for kids and is trying a few programs
>from the book We are working on a Mac  OS X ELCapitain.  We are looking
>at
>   WHACK THE BOUNCING BALL.
>He has copied the code  below and we get the red error message below.
>We
>followed the code exactly so are not sure what is wrong. Please can you
>   help.
>   Object: [1]application/x-apple-msg-attachment
>   Object: [2]application/x-apple-msg-attachment
>   Julie Selby
>   [3]julie at beaglestrategy.com
>   Tel: 604 762 1968
>   [4]http://ca.linkedin.com/in/julieselby/
>   [5]www.beaglestrategy.com
>
>References
>
>   Visible links
> 1. file:///tmp/cid:BC5630A8-FD4A-488B-9979-8A8936D74EC7 at hitronhub.home
> 2. file:///tmp/cid:80B89FF3-BA17-444D-8E95-8C63CCF4851F at hitronhub.home
>   3. mailto:julie at beaglestrategy.com
>   4. http://ca.linkedin.com/in/julieselby/
>   5. http://www.beaglestrategy.com/
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

From alan.gauld at yahoo.co.uk  Sat Feb  3 07:34:16 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 3 Feb 2018 12:34:16 +0000
Subject: [Tutor] help with some code for my 8 year old! Thank you.
In-Reply-To: <5A4789F7-69F5-428E-8496-C98D65E2FDC1@gmail.com>
References: <5A4789F7-69F5-428E-8496-C98D65E2FDC1@gmail.com>
Message-ID: <p54a47$fbh$1@blaine.gmane.org>

On 03/02/18 02:12, JSelby wrote:
>    My 8 year old is reading  Python for kids and is trying a few programs
>    from the book We are working on a Mac  OS X ELCapitain.  We are looking at
>    WHACK THE BOUNCING BALL.
>    He has copied the code  below and we get the red error message below. 

This is a text only mailing list so attachments get stripped
by the server. Please resend but cut 'n paste the actual text
into the mail message, don't use an attachment.

If that doesn't work you could post the attachments on a
web server and send a link that we can view.

For the error messages be sure to send the entire message
not just a few lines or summary.

>    Object: [1]application/x-apple-msg-attachment
>    Object: [2]application/x-apple-msg-attachment

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



From dbosah at buffalo.edu  Sat Feb  3 14:07:32 2018
From: dbosah at buffalo.edu (Daniel Bosah)
Date: Sat, 3 Feb 2018 14:07:32 -0500
Subject: [Tutor] Data Structures printing and Python Package creation
Message-ID: <CAFSTFyWPFb2uJ_JaMCQr=H8LYfyf4wwtVCH2PJN=PNiPJFnr1Q@mail.gmail.com>

I'm in a research group for school, and my first task is to learn how to
make a Python package and to learn how to print out all types of data
structures. Are there resources I can be pointed to to help me out.

Thanks

From bgailer at gmail.com  Sat Feb  3 14:20:47 2018
From: bgailer at gmail.com (Bob Gailer)
Date: Sat, 3 Feb 2018 14:20:47 -0500
Subject: [Tutor] Data Structures printing and Python Package creation
In-Reply-To: <CAP1rxO642dW-tBWnVncvTCa_9EPnK36EwBZyRB9udzi9xoQCfQ@mail.gmail.com>
References: <CAFSTFyWPFb2uJ_JaMCQr=H8LYfyf4wwtVCH2PJN=PNiPJFnr1Q@mail.gmail.com>
 <CAP1rxO642dW-tBWnVncvTCa_9EPnK36EwBZyRB9udzi9xoQCfQ@mail.gmail.com>
Message-ID: <CAP1rxO6xQWZPKmVG4P58ccpQRT4AhBDLYgM6HjEkjYb5ZmDtXg@mail.gmail.com>

On Feb 3, 2018 2:09 PM, "Daniel Bosah" <dbosah at buffalo.edu> wrote:
>
> I'm in a research group for school, and my first task is to learn how to
> make a Python package and to learn how to print out all types of data
> structures. Are there resources I can be pointed to to help me out.

https://python-packaging.readthedocs.io/en/latest/

I got that using Google search. Hint hint?

All types is a bit vague. I suggest you take one type at a time.

Very often it is sufficient to print the object using, as you might guess,
the print function.

Also Google python prettyprint and python formatting.

Let us know how it goes and please ask more questions.
_______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From akleider at sonic.net  Sat Feb  3 14:39:11 2018
From: akleider at sonic.net (Alex Kleider)
Date: Sat, 03 Feb 2018 11:39:11 -0800
Subject: [Tutor] Data Structures printing and Python Package creation
In-Reply-To: <CAP1rxO6xQWZPKmVG4P58ccpQRT4AhBDLYgM6HjEkjYb5ZmDtXg@mail.gmail.com>
References: <CAFSTFyWPFb2uJ_JaMCQr=H8LYfyf4wwtVCH2PJN=PNiPJFnr1Q@mail.gmail.com>
 <CAP1rxO642dW-tBWnVncvTCa_9EPnK36EwBZyRB9udzi9xoQCfQ@mail.gmail.com>
 <CAP1rxO6xQWZPKmVG4P58ccpQRT4AhBDLYgM6HjEkjYb5ZmDtXg@mail.gmail.com>
Message-ID: <b752a27ce1ae05eac1379d96d37d612e@sonic.net>

On 2018-02-03 11:20, Bob Gailer wrote:
> On Feb 3, 2018 2:09 PM, "Daniel Bosah" <dbosah at buffalo.edu> wrote:
>> 
>> I'm in a research group for school, and my first task is to learn how 
>> to
>> make a Python package and to learn how to print out all types of data
>> structures. Are there resources I can be pointed to to help me out.
> 
> https://python-packaging.readthedocs.io/en/latest/
> 
> I got that using Google search. Hint hint?
> 
> All types is a bit vague. I suggest you take one type at a time.
> 
> Very often it is sufficient to print the object using, as you might 
> guess,
> the print function.
> 
> Also Google python prettyprint and python formatting.
> 
> Let us know how it goes and please ask more questions.

Here's another to consider: 
https://packaging.python.org/tutorials/distributing-packages/

As for printing out data structures: I assume you mean to present a 
textual representation of specific instances. If the instances are of 
built in types, simply print:
>>> print(myvar)     # as suggested by Bob above
If it is an instance of a class you've created yourself, then to get 
anything useful you'll have had to declare a __str__ method within that 
class. The method should return (as a string) what you want print to 
show.

...at least that's my understanding.


From sunnlotus at aol.com  Sun Feb  4 23:11:23 2018
From: sunnlotus at aol.com (Rex Florian)
Date: Sun, 4 Feb 2018 23:11:23 -0500
Subject: [Tutor] fractions from Fractions
Message-ID: <16164294cc5-1721-4938@webjas-vae223.srv.aolmail.net>

I have written a program to generate the array that describes the finite simple continued fraction from any fractional input.  The input is any fraction, num/den, and the output is the array.  The program works and I am happy with the work.

The problem is one of the PyCharm problems and when I use the check feature it tells me my answer is incorrect.  I think I know the source of the trouble.  The problem asks that my input format be "A single line with an fraction in the numerator/denominator format.

My input is obtained as seen in the code.  I have googled fractions in Python.  I have tried importing fractions from Fraction but seem to be in over my head.  What am I missing?



fraction = input()
# define list for holding coefficients
coef = []

# find the index where the / is
slash = fraction.find('/')
# extract the string num and den and convert them to integers
num = int(fraction[0:slash])
den = int(fraction[slash + 1:])

while num > den and den != 0:
    mod = num % den
    a = num // den
    coef.append(a)
    num = den
    den = mod
for i in coef:
    print(i, end=' ')



From alan.gauld at yahoo.co.uk  Mon Feb  5 04:47:20 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 5 Feb 2018 09:47:20 +0000
Subject: [Tutor] fractions from Fractions
In-Reply-To: <16164294cc5-1721-4938@webjas-vae223.srv.aolmail.net>
References: <16164294cc5-1721-4938@webjas-vae223.srv.aolmail.net>
Message-ID: <p59937$gf1$1@blaine.gmane.org>

On 05/02/18 04:11, Rex Florian via Tutor wrote:

> The problem is one of the PyCharm problems and when I 
> use the check feature it tells me my answer is incorrect.  

What input did you use and what output did you get?

So far as I can tell your algorithm is correct, although
I'm not sure why you limit it to values greater than 1?

But is it perhaps the format of the output that Pycharm
objects to?

> I think I know the source of the trouble.  

Would you like to tell us?

> I have tried importing fractions from Fraction 

And what happened?
(I assume you mean you tried importing Fraction from fractions)
Although you don't really need it for this problem.

> fraction = input()
> # define list for holding coefficients
> coef = []
> 
> # find the index where the / is
> slash = fraction.find('/')
> # extract the string num and den and convert them to integers
> num = int(fraction[0:slash])
> den = int(fraction[slash + 1:])
> 
> while num > den and den != 0:
>     mod = num % den
>     a = num // den
>     coef.append(a)
>     num = den
>     den = mod
> for i in coef:
>     print(i, end=' ')


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



From steve at pearwood.info  Mon Feb  5 04:57:10 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Mon, 5 Feb 2018 20:57:10 +1100
Subject: [Tutor] fractions from Fractions
In-Reply-To: <16164294cc5-1721-4938@webjas-vae223.srv.aolmail.net>
References: <16164294cc5-1721-4938@webjas-vae223.srv.aolmail.net>
Message-ID: <20180205095709.GV26553@ando.pearwood.info>

Hi Rex,

My comments below.


On Sun, Feb 04, 2018 at 11:11:23PM -0500, Rex Florian via Tutor wrote:

> I have written a program to generate the array that describes the 
> finite simple continued fraction from any fractional input.  The input 
> is any fraction, num/den, and the output is the array.  The program 
> works and I am happy with the work.

Have you tried it with a proper fraction, like 1/2 or 4/11? As continued 
fractions, they ought to print out:

0 2        # 1/2 = 0 + 1/2
0 2 1 3    # 4/11 = 0 + 1/(2 + 1/(1 + 1/3))

but it doesn't.

 
> The problem is one of the PyCharm problems and when I use the check 
> feature it tells me my answer is incorrect.

I'm afraid I have no idea what you are talking about. What are the 
PyCharm problems, and what's "check feature"?


> I think I know the source 
> of the trouble.  The problem asks that my input format be "A single 
> line with an fraction in the numerator/denominator format.

Is it possible that you are supposed to write a function?

def contfract(fraction):
    # code as before


And then call it like this?


frac = input("Enter a fraction like num/den ")
contfract(frac)




-- 
Steve

From alan.gauld at yahoo.co.uk  Tue Feb  6 04:26:55 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 6 Feb 2018 09:26:55 +0000
Subject: [Tutor] Fwd: Re:  fractions from Fractions
In-Reply-To: <16168ce7283-1721-e0298@webjas-vaa131.srv.aolmail.net>
References: <16168ce7283-1721-e0298@webjas-vaa131.srv.aolmail.net>
Message-ID: <efbdecb5-ec86-6cdf-d38c-17f3e6049802@yahoo.co.uk>

Forwarding to list, please always use Reply ALL or Reply LIst to send
mail to the list.



-----Original Message-----
From: Alan Gauld via Tutor <tutor at python.org>
To: tutor <tutor at python.org>
Sent: Mon, Feb 5, 2018 4:50 am
Subject: Re: [Tutor] fractions from Fractions

On 05/02/18 04:11, Rex Florian via Tutor wrote:

> The problem is one of the PyCharm problems and when I
> use the check feature it tells me my answer is incorrect.

What input did you use and what output did you get?

Input 239/30? --->? 7 1 29
Input 415/93? --->? 4 2 6 7

So far as I can tell your algorithm is correct, although
I'm not sure why you limit it to values greater than 1?

The problem suggests to do so and the wiki on Finite simple continued
fractions showed examples also greater than one.? Upon consideration, i
suppose that being greater than one is not a requirement but really is
not of consequence to the insight I am seeking.

But is it perhaps the format of the output that Pycharm
objects to?

No, the format required is for the elements of the list to appear on one
line separated by a space.

> I think I know the source of the trouble.

Would you like to tell us?

My input is a string which I convert to num and den.? The problem ask
specifically that the input format be "A line with an fraction in the
"numerator/denominator" format and I am interpreting this to mean some
kind of application of the Fraction module.? But that is just a wild
guess and is what I was hoping I could get some insight on.

So, is there away with using the Fraction module to input a fraction
without having to go through the int conversions that my code employees?

> I have tried importing fractions from Fraction

And what happened?

Not much.? I just bungled something:
fraction = input(Fraction(numerator, denominator)
Please don't scold me.? It was late and I was fighting the flu and? ....
and ...

(I assume you mean you tried importing Fraction from fractions)
Although you don't really need it for this problem.

I agree I do not really need to for this problem but am just trying to
see if I could input a fraction that would not need to be processed like
my program does.

> fraction = input()
> # define list for holding coefficients
> coef = []
>
> # find the index where the / is
> slash = fraction.find('/')
> # extract the string num and den and convert them to integers
> num = int(fraction[0:slash])
> den = int(fraction[slash + 1:])
>
> while num > den and den != 0:
> mod = num % den
> a = num // den
> coef.append(a)
> num = den
> den = mod
> for i in coef:
> print(i, end=' ')


-- 
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 at python.org <mailto:Tutor at python.org>
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

From alan.gauld at yahoo.co.uk  Tue Feb  6 04:53:14 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 6 Feb 2018 09:53:14 +0000
Subject: [Tutor] Fwd: Re: fractions from Fractions
In-Reply-To: <efbdecb5-ec86-6cdf-d38c-17f3e6049802@yahoo.co.uk>
References: <16168ce7283-1721-e0298@webjas-vaa131.srv.aolmail.net>
 <efbdecb5-ec86-6cdf-d38c-17f3e6049802@yahoo.co.uk>
Message-ID: <p5btqa$780$1@blaine.gmane.org>

On 06/02/18 09:26, Alan Gauld via Tutor wrote:
> Forwarding to list, please always use Reply ALL or Reply LIst to send
> mail to the list.
> 

> What input did you use and what output did you get?
> 
> Input 239/30? --->? 7 1 29
> Input 415/93? --->? 4 2 6 7
> 
> So far as I can tell your algorithm is correct, although
> I'm not sure why you limit it to values greater than 1?
> 
> The problem suggests to do so and the wiki on Finite simple continued
> fractions showed examples also greater than one.? Upon consideration, i
> suppose that being greater than one is not a requirement but really is
> not of consequence to the insight I am seeking.

It depends on how the PyCharm "checker" works.
If it uses a test value less than 1 it will fail the test.

> But is it perhaps the format of the output that Pycharm
> objects to?
> 
> No, the format required is for the elements of the list to appear on one
> line separated by a space.

Do you have the exact wording of the requirements?
Or even a url to the PyCharm site for this specific problem?

>> I think I know the source of the trouble.
> Would you like to tell us?
> 
> My input is a string which I convert to num and den.? The problem ask
> specifically that the input format be "A line with an fraction in the
> "numerator/denominator" format and I am interpreting this to mean some
> kind of application of the Fraction module.? But that is just a wild
> guess and is what I was hoping I could get some insight on.

I don't think so, your conversion is doing the same job.

Personally I'd have used split() rather than finding
the index and slicing

num,den = [int(n) for n in fraction.split('/')]

But under the covers its doing much the same as your code.

>> I have tried importing fractions from Fraction
> 
> And what happened?
> 
> Not much.? I just bungled something:
> fraction = input(Fraction(numerator, denominator)

You would have needed something like

fraction = Fraction(input('>'))

Assuming Fraction has a string based constructor which
I don't think it does. I really don't think Fraction
helps you here.

>> while num > den and den != 0:

I'd let it handle numbers less than 1 by converting
the while loop:

while den > 0


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



From renukeshnk15 at gmail.com  Tue Feb  6 05:34:51 2018
From: renukeshnk15 at gmail.com (renukesh nk)
Date: Tue, 6 Feb 2018 16:04:51 +0530
Subject: [Tutor] fix overwriting issue
Message-ID: <CAO2EJjhmWkTyhAjzSD_okKNNdmEigQAntoBR5C-ytC+18-Z2cw@mail.gmail.com>

Hi,

i am facing issue while writing files to a folder, where the files get
overwrite if they have same file names , so any help me to  fix

thanks

From alan.gauld at yahoo.co.uk  Tue Feb  6 08:31:38 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 6 Feb 2018 13:31:38 +0000
Subject: [Tutor] fix overwriting issue
In-Reply-To: <CAO2EJjhmWkTyhAjzSD_okKNNdmEigQAntoBR5C-ytC+18-Z2cw@mail.gmail.com>
References: <CAO2EJjhmWkTyhAjzSD_okKNNdmEigQAntoBR5C-ytC+18-Z2cw@mail.gmail.com>
Message-ID: <p5cajq$khc$1@blaine.gmane.org>

On 06/02/18 10:34, renukesh nk wrote:
> i am facing issue while writing files to a folder, where the files get
> overwrite if they have same file names , so any help me to  fix

That's just what happens, what did you expect to happen?
The same would be true id you saved a file from notepad,
if you used an existing name notepad would overwrite the
old file (albeit with a warning).

Are you trying to add extra information to the end of an
existing file? If so use the "a" mode when opening the
file instead of "w".

If the problem is accidentally typing inan existing name
then you can use the os module to test whether the file
exists before opening it and giving a warning if it does.

But until we know more about what you are trying to do
we can't really offer much more help. Also it helps if
you show us the code - at lest the bit that opens the
file.

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



From wolfgang.maier at biologie.uni-freiburg.de  Tue Feb  6 10:00:38 2018
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Tue, 6 Feb 2018 16:00:38 +0100
Subject: [Tutor] Fwd: Re: fractions from Fractions
In-Reply-To: <p5btqa$780$1@blaine.gmane.org>
References: <16168ce7283-1721-e0298@webjas-vaa131.srv.aolmail.net>
 <efbdecb5-ec86-6cdf-d38c-17f3e6049802@yahoo.co.uk>
 <p5btqa$780$1@blaine.gmane.org>
Message-ID: <02c35e82-9962-8d4e-967c-bb76b7180bcd@biologie.uni-freiburg.de>

On 06.02.2018 10:53, Alan Gauld via Tutor wrote:
> 
> You would have needed something like
> 
> fraction = Fraction(input('>'))
> 
> Assuming Fraction has a string based constructor which
> I don't think it does. I really don't think Fraction
> helps you here.

Oh, most certainly it has - though it may accept more forms of input 
than the OP needs/wants:

 >>> from fractions import Fraction
 >>> Fraction('2/3')
Fraction(2, 3)
 >>> Fraction('2.3')
Fraction(23, 10)
 >>> Fraction('2e-3')
Fraction(1, 500)
 >>>

Since fractions is pure Python it may also be instructive to study its 
source:
https://github.com/python/cpython/blob/master/Lib/fractions.py


From joaquin.henriquez at countercept.com  Tue Feb  6 08:23:10 2018
From: joaquin.henriquez at countercept.com (Joaquin Henriquez)
Date: Tue, 6 Feb 2018 13:23:10 +0000
Subject: [Tutor] EXTERNAL:  fix overwriting issue
In-Reply-To: <CAO2EJjhmWkTyhAjzSD_okKNNdmEigQAntoBR5C-ytC+18-Z2cw@mail.gmail.com>
References: <CAO2EJjhmWkTyhAjzSD_okKNNdmEigQAntoBR5C-ytC+18-Z2cw@mail.gmail.com>
Message-ID: <fe51c70be3274cbab705b99be18caf9c@BSKEXCH2013HYPV.mwrinfosecurity.com>

Hi 

This is a python forum and we try to help as much as possible.

It wpuld be usefull from your side to put the python code you are trying to run an explain whats is wrong and what you are trying to do.

BR



-----Original Message-----
From: Tutor [mailto:tutor-bounces+joaquin.henriquez=countercept.com at python.org] On Behalf Of renukesh nk
Sent: 06 February 2018 10:35
To: tutor at python.org
Subject: EXTERNAL: [Tutor] fix overwriting issue

Hi,

i am facing issue while writing files to a folder, where the files get
overwrite if they have same file names , so any help me to  fix

thanks
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


From beachkidken at gmail.com  Tue Feb  6 14:45:49 2018
From: beachkidken at gmail.com (Ken Green)
Date: Tue, 6 Feb 2018 14:45:49 -0500
Subject: [Tutor] What is day of week from either 20180211 or 02112018
Message-ID: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>

Greeting: I have been trying to determine the day of
the week when inputting year + month + date. I have
not yet been able to determine what is really needed
for datetime and later on the date in the program below.
Running Python 2.7 on Ubuntu 16.04. Thanks.
===========================================
# A_Weekday.py
from datetime import date
year = "2018"
monthdate = raw_input ("Enter the month and date (MDD or MMDD): ")
print
if (len(monthdate)) == 3:
 ??? month = monthdate[0:1]
 ??? month = "0" + month
 ??? day? = monthdate[1:3]
else:
 ??? month = monthdate[0:2]
 ??? day? = monthdate[2:4]
print month, day, year; print
print year, month, day; print
datecode = year + month + day
print datecode
print
answer = datetime.date(year, month, day).weekday()
print answer
==================================================
Error message below:
Enter the month and date (MDD or MMDD): 211
02 11 2018
2018 02 11
20180211
Traceback (most recent call last):
 ? File "A_Weekday.py", line 20, in <module>
 ??? answer = datetime.date(year, month, day).weekday()
NameError: name 'datetime' is not defined


From david at graniteweb.com  Tue Feb  6 15:20:12 2018
From: david at graniteweb.com (David Rock)
Date: Tue, 6 Feb 2018 14:20:12 -0600
Subject: [Tutor] What is day of week from either 20180211 or 02112018
In-Reply-To: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>
References: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>
Message-ID: <71193BC5-5B71-4654-B25B-8D7DF6618BE5@graniteweb.com>


> On Feb 6, 2018, at 13:45, Ken Green <beachkidken at gmail.com> wrote:
> Traceback (most recent call last):
>   File "A_Weekday.py", line 20, in <module>
>     answer = datetime.date(year, month, day).weekday()
> NameError: name 'datetime' is not defined

Your error message tells you the problem.  You are importing date _from_ datetime, but then try to call datetime.date

> from datetime import date

You have _not_ imported date time, so the program doesn?t know what you mean when you say

answer = datetime.date(year, month, day).weekday()

Try just doing 

import datetime 

instead.


? 
David Rock
david at graniteweb.com





From breamoreboy at gmail.com  Tue Feb  6 15:36:48 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Tue, 6 Feb 2018 20:36:48 +0000
Subject: [Tutor] What is day of week from either 20180211 or 02112018
In-Reply-To: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>
References: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>
Message-ID: <p5d3h2$e3r$1@blaine.gmane.org>

On 06/02/18 19:45, Ken Green wrote:
> Greeting: I have been trying to determine the day of
> the week when inputting year + month + date. I have
> not yet been able to determine what is really needed
> for datetime and later on the date in the program below.
> Running Python 2.7 on Ubuntu 16.04. Thanks.
> ===========================================
> # A_Weekday.py
> from datetime import date
> year = "2018"
> monthdate = raw_input ("Enter the month and date (MDD or MMDD): ")
> print
> if (len(monthdate)) == 3:
>  ??? month = monthdate[0:1]
>  ??? month = "0" + month
>  ??? day? = monthdate[1:3]
> else:
>  ??? month = monthdate[0:2]
>  ??? day? = monthdate[2:4]
> print month, day, year; print
> print year, month, day; print
> datecode = year + month + day
> print datecode
> print
> answer = datetime.date(year, month, day).weekday()
> print answer
> ==================================================
> Error message below:
> Enter the month and date (MDD or MMDD): 211
> 02 11 2018
> 2018 02 11
> 20180211
> Traceback (most recent call last):
>  ? File "A_Weekday.py", line 20, in <module>
>  ??? answer = datetime.date(year, month, day).weekday()
> NameError: name 'datetime' is not defined
> 

There's no need for the `datetime` as you've imported `date` directly 
into the namespace.  Correct that problem and you'll still fail as 
you're passing strings instead of integers.  I'd just force your 
`monthdate` to be MMDD and pass that into `strptime` with `year`.

 >>> year = '2018'
 >>> monthdate = '0211' # skipping the input code.
 >>> from datetime import datetime
 >>> datetime.strptime(year + monthdate, '%Y%m%d')
datetime.datetime(2018, 2, 11, 0, 0)
 >>> datetime.strptime(year + monthdate, '%Y%m%d').weekday()
6


-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From beachkidken at gmail.com  Tue Feb  6 15:59:15 2018
From: beachkidken at gmail.com (Ken Green)
Date: Tue, 6 Feb 2018 15:59:15 -0500
Subject: [Tutor] What is day of week from either 20180211 or 02112018
 (SOLVED)
In-Reply-To: <71193BC5-5B71-4654-B25B-8D7DF6618BE5@graniteweb.com>
References: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>
 <71193BC5-5B71-4654-B25B-8D7DF6618BE5@graniteweb.com>
Message-ID: <1413cc37-711e-6c54-767d-2e9b478b8f27@gmail.com>



On 02/06/2018 03:20 PM, David Rock wrote:
>> On Feb 6, 2018, at 13:45, Ken Green <beachkidken at gmail.com> wrote:
>> Traceback (most recent call last):
>>    File "A_Weekday.py", line 20, in <module>
>>      answer = datetime.date(year, month, day).weekday()
>> NameError: name 'datetime' is not defined
> Your error message tells you the problem.  You are importing date _from_ datetime, but then try to call datetime.date
>
>> from datetime import date
> You have _not_ imported date time, so the program doesn?t know what you mean when you say
>
> answer = datetime.date(year, month, day).weekday()
>
> Try just doing
>
> import datetime
>
> instead.
>
>
> ?
> David Rock
> david at graniteweb.com
>
>
Thank you, sir. You put me on the right path. Much appreciated.

From beachkidken at gmail.com  Tue Feb  6 16:07:17 2018
From: beachkidken at gmail.com (Ken Green)
Date: Tue, 6 Feb 2018 16:07:17 -0500
Subject: [Tutor] What is day of week from either 20180211 or 02112018
 (SOLVED)
In-Reply-To: <p5d3h2$e3r$1@blaine.gmane.org>
References: <69d54261-8481-b1c5-79f7-d7ca5aeb3d44@gmail.com>
 <p5d3h2$e3r$1@blaine.gmane.org>
Message-ID: <cf9334fc-a69b-56a2-3896-59beb05b5bf1@gmail.com>



On 02/06/2018 03:36 PM, Mark Lawrence wrote:
> On 06/02/18 19:45, Ken Green wrote:
>> Greeting: I have been trying to determine the day of
>> the week when inputting year + month + date. I have
>> not yet been able to determine what is really needed
>> for datetime and later on the date in the program below.
>> Running Python 2.7 on Ubuntu 16.04. Thanks.
>> ===========================================
>> # A_Weekday.py
>> from datetime import date
>> year = "2018"
>> monthdate = raw_input ("Enter the month and date (MDD or MMDD): ")
>> print
>> if (len(monthdate)) == 3:
>> ???? month = monthdate[0:1]
>> ???? month = "0" + month
>> ???? day? = monthdate[1:3]
>> else:
>> ???? month = monthdate[0:2]
>> ???? day? = monthdate[2:4]
>> print month, day, year; print
>> print year, month, day; print
>> datecode = year + month + day
>> print datecode
>> print
>> answer = datetime.date(year, month, day).weekday()
>> print answer
>> ==================================================
>> Error message below:
>> Enter the month and date (MDD or MMDD): 211
>> 02 11 2018
>> 2018 02 11
>> 20180211
>> Traceback (most recent call last):
>> ?? File "A_Weekday.py", line 20, in <module>
>> ???? answer = datetime.date(year, month, day).weekday()
>> NameError: name 'datetime' is not defined
>>
>
> There's no need for the `datetime` as you've imported `date` directly 
> into the namespace.? Correct that problem and you'll still fail as 
> you're passing strings instead of integers.? I'd just force your 
> `monthdate` to be MMDD and pass that into `strptime` with `year`.
>
> >>> year = '2018'
> >>> monthdate = '0211' # skipping the input code.
> >>> from datetime import datetime
> >>> datetime.strptime(year + monthdate, '%Y%m%d')
> datetime.datetime(2018, 2, 11, 0, 0)
> >>> datetime.strptime(year + monthdate, '%Y%m%d').weekday()
> 6
>
Thanks. I already got it up and running. Much appreciated.


From huseyin at piramit.com.tr  Tue Feb  6 16:07:24 2018
From: huseyin at piramit.com.tr (=?iso-8859-9?Q?H=FCseyin_Ertu=F0rul?=)
Date: Tue, 6 Feb 2018 21:07:24 +0000
Subject: [Tutor] Formatting text file with python
Message-ID: <AM4PR0601MB211590C5A593E9C5DD5DFDF292FD0@AM4PR0601MB2115.eurprd06.prod.outlook.com>

Hello friends,
I want to format the log (text) file my email's server.
The text file (named s1.txt) contains the following information, text file has about 3000 lines.

"hMailServer SpamProtection rejected RCPT (Sender: Valeria0021 at mikelsonconstruction.com, IP:187.62.63.218, Reason: Rejected by Spamhaus.)"
"hMailServer SpamProtection rejected RCPT (Sender: Veronika07372 at etb.net.co, IP:190.25.189.74, Reason: Rejected by SpamCop.)"
"hMailServer SpamProtection rejected RCPT (Sender: Sofia610 at pembroketownhouse.ie, IP:103.247.48.95, Reason: Rejected by Spamhaus.)"

I want to select ip addresses in text file and I want to delete duplicated records. Finally I want to write this data into a new file. What do you suggest me?

That codes returned me about 500 records and gives error ;

Traceback (most recent call last):
  File "C:/Depo/Python/prj1/analiz.py", line 17, in <module>
    prnt(deger)
  File "C:/Depo/Python/prj1/analiz.py", line 7, in prnt
    iplist = list_line[1]
IndexError: list index out of range)
-------------------------------------------------------------------------------
My code is below;
def prnt(L1):

    L1 = L1[:-1]

    list_line = L1.split(",")
    list0 = list_line[0]
    iplist = list_line[1]
    list2 = list_line[2]
    print(iplist)


with open("s1.txt","r",) as file:

    for deger in file:
        prnt(deger)

#with open("iplistesi.txt","w") as file2:
#    file2.write(i)


Best Regards.

Huseyin


From sa.testinggeek at gmail.com  Tue Feb  6 22:22:40 2018
From: sa.testinggeek at gmail.com (Dragan Mestrovik)
Date: Wed, 7 Feb 2018 08:52:40 +0530
Subject: [Tutor] Suggest some Android app
Message-ID: <CAKtn2oNZabp+200hvgoPmrYTTRvYcHhYpBP-_gSg2haCBz4jDQ@mail.gmail.com>

Hi,

please suggest me some good android apps through which i can execute my
python scripts and practice python. I want to download videos using
youtube-dl python script and want to save them to external drive like otg
pendrive. I tried termux, which is not able to  store the files in external
storage. I want to directly download videos to external otg pendrive.

From alan.gauld at yahoo.co.uk  Wed Feb  7 03:55:38 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 7 Feb 2018 08:55:38 +0000
Subject: [Tutor] Formatting text file with python
In-Reply-To: <AM4PR0601MB211590C5A593E9C5DD5DFDF292FD0@AM4PR0601MB2115.eurprd06.prod.outlook.com>
References: <AM4PR0601MB211590C5A593E9C5DD5DFDF292FD0@AM4PR0601MB2115.eurprd06.prod.outlook.com>
Message-ID: <p5eeq9$umv$1@blaine.gmane.org>

On 06/02/18 21:07, H?seyin Ertu?rul wrote:

> "hMailServer SpamProtection rejected RCPT (Sender: Valeria0021 at mikelsonconstruction.com, IP:187.62.63.218, Reason: Rejected by Spamhaus.)"
> "hMailServer SpamProtection rejected RCPT (Sender: Veronika07372 at etb.net.co, IP:190.25.189.74, Reason: Rejected by SpamCop.)"
> "hMailServer SpamProtection rejected RCPT (Sender: Sofia610 at pembroketownhouse.ie, IP:103.247.48.95, Reason: Rejected by Spamhaus.)"
> 
> Traceback (most recent call last):
>   File "C:/Depo/Python/prj1/analiz.py", line 17, in <module>
>     prnt(deger)
>   File "C:/Depo/Python/prj1/analiz.py", line 7, in prnt
>     iplist = list_line[1]
> IndexError: list index out of range)

So you have a line with no commas in it. Have you checked
the line that causes the error - presumably right after
the last one that printed correctly.

> -------------------------------------------------------------------------------
> My code is below;
> def prnt(L1):
> 
>     L1 = L1[:-1]
> 
>     list_line = L1.split(",")

You are splitting by comma but I notice the IP addresses
all start with IP: so it might be easier/more reliable
to split by 'IP:' in case there are other messages with
commas but no IP addresses in them?

But even so you still need to either check the result
length or use a try/except IndexError to deal with malformed
lines.

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



From bhaskaran.vinod at gmail.com  Wed Feb  7 06:58:20 2018
From: bhaskaran.vinod at gmail.com (vinod bhaskaran)
Date: Wed, 7 Feb 2018 17:28:20 +0530
Subject: [Tutor] can someone explain the reason for error
Message-ID: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>

Hi, I am a beginner level programmer and in one assignment the question
given is:to remove ',' from a list after getting a comma separated input
from console.

I gave the below (most print statements are for reference except the last
print statement). but i get the attached error. can someone explain why
this error nd how to rectify?

inputdata = input ('Enter comma separated data \n')
type(inputdata)
inputlist = list(inputdata)
print(inputlist)
a = len(inputdata)
print(a)
print ('xxxxxxxxxxxxxxxx')
for b in range(0,a):
    print(a)
    a = a - 1
    print(inputlist)
    inputlist.remove(',')
print(inputlist)




Thanks,
Vinod

From alan.gauld at yahoo.co.uk  Wed Feb  7 12:56:24 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 7 Feb 2018 17:56:24 +0000
Subject: [Tutor] can someone explain the reason for error
In-Reply-To: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>
References: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>
Message-ID: <p5feg8$dqb$1@blaine.gmane.org>

On 07/02/18 11:58, vinod bhaskaran wrote:
> Hi, I am a beginner level programmer and in one assignment the question
> given is:to remove ',' from a list after getting a comma separated input
> from console.

First up I'll say you are doing an awful lot of work
that's not needed. As a result your solution is much
more complex than is necessary.

Remember that a string is just like a list of letters
so you don't need to convert it to a list. Just use
it as is. Also strings have lots of useful methods
that you can use - hint: try reading about them in
the Python documentation, you might find easier ways
to do things.

> I gave the below (most print statements are for reference except the last
> print statement). but i get the attached error. can someone explain why
> this error nd how to rectify?
> 
> inputdata = input ('Enter comma separated data \n')
> type(inputdata)

This line does nothing useful.

> inputlist = list(inputdata)
> print(inputlist)
> a = len(inputdata)
> print(a)

Note that you converted to a list but you are
taking the length of the original string.

> print ('xxxxxxxxxxxxxxxx')
> for b in range(0,a):
>     print(a)
>     a = a - 1

This is a terrible idea. Don't mess with the values
to give to range in a loop. Bad things are likely
to happen.

Also note that Pythons for loops give you each item
in the data, you don;t need to mess about with indexes.
And if you do need indexes enumerate() is usually a
better solution than using range. (range is great
if you just want a list of numbers but its usually
the wrong way to process a collection of any kind)

However in this case you are not using a or b,
just reducing the size of a in each iteration,
while increasing the size of b such that they
will meet in the middle. I'm pretty sure that's
not what you want?

>     print(inputlist)
>     inputlist.remove(',')

This removes the commas starting at the front
of the list. So you remove 1 comma each time
round the loop. But you go round the loop half
as many times as there are characters in the
string. What happens if there are less commas
than that?

You don't show us the error, (if you used an
attachment it will have been stripped by the
server). But if it was a ValueError then I
suspect you hit the above scenario.

> print(inputlist)

Let me suggest a simpler algorithm in pseudo code.
(WE don;t do your homework for you so you will need
to translate the pseudocode into real Python yourself)

inputstr = input()
for char in inputstr:
   if char not a comma
      print char

There is an even shorter way if you use the built
in string methods.

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



From breamoreboy at gmail.com  Wed Feb  7 13:03:32 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Wed, 7 Feb 2018 18:03:32 +0000
Subject: [Tutor] can someone explain the reason for error
In-Reply-To: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>
References: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>
Message-ID: <p5fetm$b67$1@blaine.gmane.org>

On 07/02/18 11:58, vinod bhaskaran wrote:
> Hi, I am a beginner level programmer and in one assignment the question
> given is:to remove ',' from a list after getting a comma separated input
> from console.
> 
> I gave the below (most print statements are for reference except the last
> print statement). but i get the attached error. can someone explain why
> this error nd how to rectify?
> 
> inputdata = input ('Enter comma separated data \n')
> type(inputdata)
> inputlist = list(inputdata)
> print(inputlist)
> a = len(inputdata)
> print(a)
> print ('xxxxxxxxxxxxxxxx')
> for b in range(0,a):
>      print(a)
>      a = a - 1
>      print(inputlist)
>      inputlist.remove(',')
> print(inputlist)
> 
> Thanks,
> Vinod

The attachment doesn't get through to this text only list so please cut 
and paste the entire traceback into a reply, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From akleider at sonic.net  Wed Feb  7 12:56:46 2018
From: akleider at sonic.net (Alex Kleider)
Date: Wed, 07 Feb 2018 09:56:46 -0800
Subject: [Tutor] can someone explain the reason for error
In-Reply-To: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>
References: <CAKS=jrDSZT48X3V39M7L0HVbNNFvRbiNe0BARYOddyyQOwoZtQ@mail.gmail.com>
Message-ID: <57bd2625acab0c946b13dbb80261e5bd@sonic.net>

On 2018-02-07 03:58, vinod bhaskaran wrote:
> Hi, I am a beginner level programmer and in one assignment the question
> given is:to remove ',' from a list after getting a comma separated 
> input
> from console.
> 
> I gave the below (most print statements are for reference except the 
> last
> print statement). but i get the attached error. can someone explain why
> this error nd how to rectify?
> 
> inputdata = input ('Enter comma separated data \n')
> type(inputdata)
> inputlist = list(inputdata)
> print(inputlist)
> a = len(inputdata)
> print(a)
> print ('xxxxxxxxxxxxxxxx')
> for b in range(0,a):
>     print(a)
>     a = a - 1
>     print(inputlist)
>     inputlist.remove(',')
> print(inputlist)


The following might help you on your way:
Python 3.6.3 (default, Oct  6 2017, 08:44:35)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "a,b,c,d"
>>> l = list(s)
>>> l
['a', ',', 'b', ',', 'c', ',', 'd']
>>> l2 = s.split()
>>> l2
['a,b,c,d']
>>> l3 = s.split(',')
>>> l3
['a', 'b', 'c', 'd']


When 'list()' is handed a string, it returns a list of all characters in 
the string; in your case many of them are commas.
The str method 'split' takes a string and  splits it into an array: by 
default it uses white space as the delimiter (your string has no white 
space so it is returned as the only member of the list) but this (the 
delimiter) can be set to what you want. In your case you want to split 
on the comma character.
For "extra bonus points" you might want to look at the csv (comma 
separated values) module- it might be helpful depending on your use 
case.

From carroll at tjc.com  Wed Feb  7 15:06:00 2018
From: carroll at tjc.com (Terry Carroll)
Date: Wed, 7 Feb 2018 15:06:00 -0500 (EST)
Subject: [Tutor] Java equivalent of Python-Tutor?
Message-ID: <alpine.NEB.2.21.1802071459120.6189@panix2.panix.com>

In my early days of using Python I benefited greatly from this Tutor list, 
thanks to both Alan and Steven as well as as many contributors. I still 
check in now and then and try to chime in to help now that I have a bit 
more experience under my belt.

I'm doing a few projects in Java now and would love to find a similar 
resource that covers that language, and the Eclipse IDE. Some of my 
questions are too newbie for a forum like stackoverflow (and most of the 
responses there assume a non-newbie level of knowledge).

Any suggestions? (I acknowledge that this is a bit off-topic, but I hope 
the blatantly obsequious sucking up at the beginning of my note makes up 
for it.)

-- 
Terry Carroll
carroll at tjc.com

From dominguezfrank2 at gmail.com  Wed Feb  7 16:34:29 2018
From: dominguezfrank2 at gmail.com (Frank Dominguez)
Date: Wed, 7 Feb 2018 16:34:29 -0500
Subject: [Tutor] help
Message-ID: <CAGJZN=tf1fkEd2rpd2tS8rjufVDbSQv0AQUCMk_zuuNE3hB=5A@mail.gmail.com>

greetings,
this is my first time using python and i just cannot figure out what I am
doing wrong im sure the answer is very simple but sadly i do not know what
it is
thanks for the help!
-------------- next part --------------
'''
Author:  Frank Dominguez
CS 140: February 5, 2018
Python Lab 1

Determine the cost of landscaping a backyard

'''
length = eval(input("Enter the length of the yard")
width = eval(input("Enter the width of the yard")
sod = eval(input("Enter the cost of sod"
fence = eval(input("What is the cost of the fence")
area = length*width
perimeter = length*2+width*2
total_sod = area*sod
total_fence = fence*perimeter
landscaping = total_sod+total_fence
print ("the total cost of landscaping is",landscaping)

From alan.gauld at yahoo.co.uk  Wed Feb  7 18:29:27 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 7 Feb 2018 23:29:27 +0000
Subject: [Tutor] Suggest some Android app
In-Reply-To: <CAKtn2oNZabp+200hvgoPmrYTTRvYcHhYpBP-_gSg2haCBz4jDQ@mail.gmail.com>
References: <CAKtn2oNZabp+200hvgoPmrYTTRvYcHhYpBP-_gSg2haCBz4jDQ@mail.gmail.com>
Message-ID: <p5g20m$qie$1@blaine.gmane.org>

On 07/02/18 03:22, Dragan Mestrovik wrote:

> please suggest me some good android apps through which i can execute my
> python scripts and practice python. 

I don't know if its the best but the one I use is QPython3.

Its free and includes an interactive interpreter.


> I want to download videos using
> youtube-dl python script and want to save them to external drive like otg

I have no idea if it will help with that...

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



From alan.gauld at yahoo.co.uk  Wed Feb  7 18:46:00 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 7 Feb 2018 23:46:00 +0000
Subject: [Tutor] Java equivalent of Python-Tutor?
In-Reply-To: <alpine.NEB.2.21.1802071459120.6189@panix2.panix.com>
References: <alpine.NEB.2.21.1802071459120.6189@panix2.panix.com>
Message-ID: <p5g2vn$lsr$1@blaine.gmane.org>

On 07/02/18 20:06, Terry Carroll wrote:

> I'm doing a few projects in Java now and would love to find a similar 
> resource that covers that language, 

I did a deep dive into Java for a new job a couple of years ago
and found the official Oracle tutorials very good combined with
YouTube videos for a quick overview.

If you have a reasonable Python background you should be able
to follow it easily enough. The biggest challenges are the
static typing (which soon becomes frustratingly annoying
after Python! - that's where the IDE pays dividends)

> and the Eclipse IDE. 

I used Netbeans as it is the official Java IDE so I can't
help with Java on Eclipse, although I do know a lot of it
depends on which plugins you install (I used it for
UML designs in a previous life!).

> Any suggestions? 

I also used two books (Actually I read about 5 but
these were the most useful):

- Learning Java - O'Reilly
and
- Java A Beginners Guide

Both are good but, if forced to choose just one, I'd
now opt for the more advanced version of the latter:
"Java The Complete Reference" by the same author,
Herbert Schildt. There is a new 10th edition out which
means the previous one is available at much cheaper
prices...

FWIW Java 8 is now a half decent language, something
I'd never have said about Java up to v5 (which was
the last time I looked at it).

Finally, If you need to use the Enterprise extensions
(JEE) you can use the online tutorials but I definitely
recommend pre-viewing YouTube vids for that.
They really help with the concepts.

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



From alan.gauld at yahoo.co.uk  Wed Feb  7 18:55:35 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 7 Feb 2018 23:55:35 +0000
Subject: [Tutor] help
In-Reply-To: <CAGJZN=tf1fkEd2rpd2tS8rjufVDbSQv0AQUCMk_zuuNE3hB=5A@mail.gmail.com>
References: <CAGJZN=tf1fkEd2rpd2tS8rjufVDbSQv0AQUCMk_zuuNE3hB=5A@mail.gmail.com>
Message-ID: <p5g3hm$j8h$1@blaine.gmane.org>

On 07/02/18 21:34, Frank Dominguez wrote:

> this is my first time using python and i just cannot figure out what I am
> doing wrong im sure the answer is very simple but sadly i do not know what

Please always include full error messages in your mail
 - don't assume we will willingly run buggy code!

Also post the code in the email, using plain text rather
than attaching it. It makes replies easier and ensures
it doesn't get lost in the archives.

Here is yours with my comments:

> length = eval(input("Enter the length of the yard")
> width = eval(input("Enter the width of the yard")
> sod = eval(input("Enter the cost of sod"

You are missing a closing paren there.
But you are also missing a closing paren on all
the other lines. You close the input() but not
the eval()

> fence = eval(input("What is the cost of the fence")

Never, ever, combine eval() with input() it is a
recipe for disaster since a malicious user (or
a mis-typing one) can wreak havoc by typing in
malicious code that could, potentially trash
your computer. It's a very bad habit, avoid at
all costs.

Read the input and convert it explicitly using
int() or float() or whatever. Like so:

fence = float(input("What is the cost of the fence"))

It's much safer (and not much extra typing).

> area = length*width
> perimeter = length*2+width*2
> total_sod = area*sod
> total_fence = fence*perimeter
> landscaping = total_sod+total_fence
> print ("the total cost of landscaping is",landscaping)

This bit seems fine.

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



From Sunnlotus at aol.com  Wed Feb  7 18:49:51 2018
From: Sunnlotus at aol.com (Rex)
Date: Wed, 7 Feb 2018 18:49:51 -0500
Subject: [Tutor] help
In-Reply-To: <CAGJZN=tf1fkEd2rpd2tS8rjufVDbSQv0AQUCMk_zuuNE3hB=5A@mail.gmail.com>
References: <CAGJZN=tf1fkEd2rpd2tS8rjufVDbSQv0AQUCMk_zuuNE3hB=5A@mail.gmail.com>
Message-ID: <C4FC2503-2BFD-41EA-A496-C57BE24A252E@aol.com>

I think you need to convert the input value to an integer with int(variable_name)



Sent from my iPhone

> On Feb 7, 2018, at 4:34 PM, Frank Dominguez <dominguezfrank2 at gmail.com> wrote:
> 
> greetings,
> this is my first time using python and i just cannot figure out what I am
> doing wrong im sure the answer is very simple but sadly i do not know what
> it is
> thanks for the help!
> <backyard.py>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


From robertvstepp at gmail.com  Wed Feb  7 20:01:52 2018
From: robertvstepp at gmail.com (boB Stepp)
Date: Wed, 7 Feb 2018 19:01:52 -0600
Subject: [Tutor] Java equivalent of Python-Tutor?
In-Reply-To: <alpine.NEB.2.21.1802071459120.6189@panix2.panix.com>
References: <alpine.NEB.2.21.1802071459120.6189@panix2.panix.com>
Message-ID: <CANDiX9LP-rnq8UADRCQUzAyC1v2zvASFEHe1Bmpw-34BkdfPwg@mail.gmail.com>

On Wed, Feb 7, 2018 at 2:06 PM, Terry Carroll <carroll at tjc.com> wrote:
>
> In my early days of using Python I benefited greatly from this Tutor list, thanks to both Alan and Steven as well as as many contributors. I still check in now and then and try to chime in to help now that I have a bit more experience under my belt.
>
> I'm doing a few projects in Java now and would love to find a similar resource that covers that language, and the Eclipse IDE. Some of my questions are too newbie for a forum like stackoverflow (and most of the responses there assume a non-newbie level of knowledge).
>
> Any suggestions?

When I was dabbling with Java a few years ago, I found the Beginning
Java Forum at JavaRanch helpful.  It can be found at:

https://coderanch.com/f/33/java

-- 
boB

From dominguezfrank2 at gmail.com  Wed Feb  7 19:59:31 2018
From: dominguezfrank2 at gmail.com (Frank Dominguez)
Date: Wed, 7 Feb 2018 19:59:31 -0500
Subject: [Tutor] help
In-Reply-To: <C4FC2503-2BFD-41EA-A496-C57BE24A252E@aol.com>
References: <CAGJZN=tf1fkEd2rpd2tS8rjufVDbSQv0AQUCMk_zuuNE3hB=5A@mail.gmail.com>
 <C4FC2503-2BFD-41EA-A496-C57BE24A252E@aol.com>
Message-ID: <CAGJZN=uM3xYrWS=Tw74j=EYLM9D0okxYegLo2w2aAogzWUy90Q@mail.gmail.com>

Thanks for the tip!

On Feb 7, 2018 18:49, "Rex" <Sunnlotus at aol.com> wrote:

> I think you need to convert the input value to an integer with
> int(variable_name)
>
>
>
> Sent from my iPhone
>
> > On Feb 7, 2018, at 4:34 PM, Frank Dominguez <dominguezfrank2 at gmail.com>
> wrote:
> >
> > greetings,
> > this is my first time using python and i just cannot figure out what I am
> > doing wrong im sure the answer is very simple but sadly i do not know
> what
> > it is
> > thanks for the help!
> > <backyard.py>
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
>

From charlotte.sonne at hotmail.com  Thu Feb  8 16:23:09 2018
From: charlotte.sonne at hotmail.com (Charlotte Hoff Sonne)
Date: Thu, 8 Feb 2018 21:23:09 +0000
Subject: [Tutor] Creating a DataFrame from excel file
Message-ID: <HE1PR05MB1452F664E2D2BD1E371D6163E6F30@HE1PR05MB1452.eurprd05.prod.outlook.com>

I wish to create a very large data frame with pandas. So far, I have learned how to create data frames by manually entering the values I want in my data frame. However, now I have a large dataset from excel that I want to get imported as a data frame in jupyter notebook. Initially i wrote the following code:

pd.read_excel(???)

But this is not a data frame, is it? Can I convert my excel file to a data frame?

From breamoreboy at gmail.com  Fri Feb  9 11:35:15 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Fri, 9 Feb 2018 16:35:15 +0000
Subject: [Tutor] Creating a DataFrame from excel file
In-Reply-To: <HE1PR05MB1452F664E2D2BD1E371D6163E6F30@HE1PR05MB1452.eurprd05.prod.outlook.com>
References: <HE1PR05MB1452F664E2D2BD1E371D6163E6F30@HE1PR05MB1452.eurprd05.prod.outlook.com>
Message-ID: <p5kig5$uvj$1@blaine.gmane.org>

On 08/02/18 21:23, Charlotte Hoff Sonne wrote:
> I wish to create a very large data frame with pandas. So far, I have learned how to create data frames by manually entering the values I want in my data frame. However, now I have a large dataset from excel that I want to get imported as a data frame in jupyter notebook. Initially i wrote the following code:
> 
> pd.read_excel(???)
> 
> But this is not a data frame, is it? Can I convert my excel file to a data frame?

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html 
states quite clearly "Read an Excel table into a pandas DataFrame" so 
you just have to assign the return value from the call to a variable.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From naren_sap at yahoo.com  Fri Feb  9 12:22:55 2018
From: naren_sap at yahoo.com (Naren)
Date: Fri, 9 Feb 2018 09:22:55 -0800
Subject: [Tutor] Creating a DataFrame from excel file
In-Reply-To: <mailman.8.1518195601.19012.tutor@python.org>
References: <mailman.8.1518195601.19012.tutor@python.org>
Message-ID: <D6EFBE0C-681D-42D5-8A9D-C24DECEE9B9F@yahoo.com>


Creating a data frame from excel. 

pd.read_csv(path, index_col=0,parse_dates=True).

example:

df = pd.read_csv('small_data/fha_by_tract.csv', names=names)
df.head()

Best Regards - Naren


> On Feb 9, 2018, at 9:00 AM, tutor-request at python.org wrote:
> 
> Send Tutor mailing list submissions to
> 	tutor at 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-request at python.org
> 
> You can reach the person managing the list at
> 	tutor-owner at python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
> 
>   1. Creating a DataFrame from excel file (Charlotte Hoff Sonne)
>   2. Re: Creating a DataFrame from excel file (Mark Lawrence)
> 
> From: Charlotte Hoff Sonne <charlotte.sonne at hotmail.com>
> Subject: [Tutor] Creating a DataFrame from excel file
> Date: February 8, 2018 at 1:23:09 PM PST
> To: "tutor at python.org" <tutor at python.org>
> 
> 
> I wish to create a very large data frame with pandas. So far, I have learned how to create data frames by manually entering the values I want in my data frame. However, now I have a large dataset from excel that I want to get imported as a data frame in jupyter notebook. Initially i wrote the following code:
> 
> pd.read_excel(???)
> 
> But this is not a data frame, is it? Can I convert my excel file to a data frame?
> 
> 
> From: Mark Lawrence <breamoreboy at gmail.com>
> Subject: Re: [Tutor] Creating a DataFrame from excel file
> Date: February 9, 2018 at 8:35:15 AM PST
> To: tutor at python.org
> 
> 
> On 08/02/18 21:23, Charlotte Hoff Sonne wrote:
>> I wish to create a very large data frame with pandas. So far, I have learned how to create data frames by manually entering the values I want in my data frame. However, now I have a large dataset from excel that I want to get imported as a data frame in jupyter notebook. Initially i wrote the following code:
>> pd.read_excel(???)
>> But this is not a data frame, is it? Can I convert my excel file to a data frame?
> 
> https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html states quite clearly "Read an Excel table into a pandas DataFrame" so you just have to assign the return value from the call to a variable.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor


From robertvstepp at gmail.com  Sat Feb 10 00:44:11 2018
From: robertvstepp at gmail.com (boB Stepp)
Date: Fri, 9 Feb 2018 23:44:11 -0600
Subject: [Tutor] Does Python and its standard libraries use semantic
 versioning?
Message-ID: <CANDiX9K0zZ+v3V3kkYTux951Mf2XCqHe2mhHMXhG6GfcVxgK=g@mail.gmail.com>

I have been reading the interesting web page "Semantic Versioning
2.0.0" at https://semver.org/  I like how its use can supposedly make
"dependency hell" a thing of the past.  So I am wondering if Python
and its standard libraries make use of semantic versioning as
described in this article?  But I suppose that for third party
libraries anything goes?

TIA!

-- 
boB

From alan.gauld at yahoo.co.uk  Sat Feb 10 04:07:21 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 10 Feb 2018 09:07:21 +0000
Subject: [Tutor] Does Python and its standard libraries use semantic
 versioning?
In-Reply-To: <CANDiX9K0zZ+v3V3kkYTux951Mf2XCqHe2mhHMXhG6GfcVxgK=g@mail.gmail.com>
References: <CANDiX9K0zZ+v3V3kkYTux951Mf2XCqHe2mhHMXhG6GfcVxgK=g@mail.gmail.com>
Message-ID: <p5mck8$q4c$1@blaine.gmane.org>

On 10/02/18 05:44, boB Stepp wrote:
> I have been reading the interesting web page "Semantic Versioning

Interesting read, it's the first time I've come across the term.
The practice is of course fairly standard and certainly every
major project I've ever worked on has done it but.... they
were all compiled code and the x.y.z versioning only applied to
the final-build binaries (which is what was released).

Source files are usually maintained via the version control's
numbering system and that does not respect the semantics of
releases. So I'm not sure how you would control semantic
versioning for a project that releases the source files
(ie like Python projects do). One option would be to us
a dual version control setup with one for file management
and one for releases (I've seen that done before) but the
potential for a file to bypass the release system is high.

I'll be interested to see how others respond in general.
And also for the specifics of how the Python project handles
it.


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



From akleider at sonic.net  Sat Feb 10 18:34:53 2018
From: akleider at sonic.net (Alex Kleider)
Date: Sat, 10 Feb 2018 15:34:53 -0800
Subject: [Tutor] Does Python and its standard libraries use semantic
 versioning?
In-Reply-To: <p5mck8$q4c$1@blaine.gmane.org>
References: <CANDiX9K0zZ+v3V3kkYTux951Mf2XCqHe2mhHMXhG6GfcVxgK=g@mail.gmail.com>
 <p5mck8$q4c$1@blaine.gmane.org>
Message-ID: <9aeee6ae2d1f6b0130345fad33351cb5@sonic.net>

On 2018-02-10 01:07, Alan Gauld via Tutor wrote:
> On 10/02/18 05:44, boB Stepp wrote:
>> I have been reading the interesting web page "Semantic Versioning

This link may be of interest to those following this thread:
http://nvie.com/posts/a-successful-git-branching-model/

From robertvstepp at gmail.com  Sat Feb 10 19:33:20 2018
From: robertvstepp at gmail.com (boB Stepp)
Date: Sat, 10 Feb 2018 18:33:20 -0600
Subject: [Tutor] Does Python and its standard libraries use semantic
 versioning?
In-Reply-To: <9aeee6ae2d1f6b0130345fad33351cb5@sonic.net>
References: <CANDiX9K0zZ+v3V3kkYTux951Mf2XCqHe2mhHMXhG6GfcVxgK=g@mail.gmail.com>
 <p5mck8$q4c$1@blaine.gmane.org> <9aeee6ae2d1f6b0130345fad33351cb5@sonic.net>
Message-ID: <CANDiX9LpMOVqOxcaNkftvVdh-mEjMQqZuUKqbP7pxX1NXvFCvw@mail.gmail.com>

On Sat, Feb 10, 2018 at 5:34 PM, Alex Kleider <akleider at sonic.net> wrote:
> On 2018-02-10 01:07, Alan Gauld via Tutor wrote:
>>
>> On 10/02/18 05:44, boB Stepp wrote:
>>>
>>> I have been reading the interesting web page "Semantic Versioning
>
>
> This link may be of interest to those following this thread:
> http://nvie.com/posts/a-successful-git-branching-model/

Alex, I actually had just finished reading the page at your link,
before I read the other on Semantic Versioning.  For those interested,
there is git-flow (At https://github.com/nvie/gitflow) to aid in the
implementing of this type of release workflow.

-- 
boB

From charlotte.sonne at hotmail.com  Mon Feb 12 10:47:13 2018
From: charlotte.sonne at hotmail.com (Charlotte Hoff Sonne)
Date: Mon, 12 Feb 2018 15:47:13 +0000
Subject: [Tutor] Barplot order-arrangement
Message-ID: <HE1PR05MB14521F817B7B82C32B00EC2CE6F70@HE1PR05MB1452.eurprd05.prod.outlook.com>

Hi,

I have created a barplot in Python. Now I want to arrange the order of the bars differently. I want them to be ordered from highest to lowest - how do I do that? Furthermore, I would like the names of the bars to be vertical - how do I do that?

This is the code I have written:
sns.barplot(x='word',y='andelelite',data=plotpanda)

I have also attached a picture of the plot I have created.
[cid:5226C847-252D-4E1A-9657-D4512B5085B9 at emea.devoteam.com]

From alan.gauld at yahoo.co.uk  Mon Feb 12 13:49:09 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 12 Feb 2018 18:49:09 +0000
Subject: [Tutor] Barplot order-arrangement
In-Reply-To: <HE1PR05MB14521F817B7B82C32B00EC2CE6F70@HE1PR05MB1452.eurprd05.prod.outlook.com>
References: <HE1PR05MB14521F817B7B82C32B00EC2CE6F70@HE1PR05MB1452.eurprd05.prod.outlook.com>
Message-ID: <p5snf3$nvn$1@blaine.gmane.org>

On 12/02/18 15:47, Charlotte Hoff Sonne wrote:
> Hi,
> 
> I have created a barplot in Python. 

It will help f you tell us which version of Python and which OS.

> This is the code I have written:
> sns.barplot(x='word',y='andelelite',data=plotpanda)

What is sns? It's not part of the standard library so presumably
it's a library you downloaded? Or maybe part of something like
numpy or SciPy?

> I have also attached a picture of the plot I have created.

Binary attachments get stripped by the mail server. It will be
better if you can put the picture on a web server somewhere
and provide a link.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/




From nelsonjonkane6 at live.com  Mon Feb 12 13:59:20 2018
From: nelsonjonkane6 at live.com (nelson jon kane)
Date: Mon, 12 Feb 2018 18:59:20 +0000
Subject: [Tutor] Barplot order-arrangement
In-Reply-To: <HE1PR05MB14521F817B7B82C32B00EC2CE6F70@HE1PR05MB1452.eurprd05.prod.outlook.com>
References: <HE1PR05MB14521F817B7B82C32B00EC2CE6F70@HE1PR05MB1452.eurprd05.prod.outlook.com>
Message-ID: <DM5PR20MB1306BCE6BEAE549BD88A4E7CEAF70@DM5PR20MB1306.namprd20.prod.outlook.com>

If I try to teach myself Python through YouTube videos, why would anyone hire me over someone who has a 2-year Computer Science degree? And why would anyone hire someone who has a 2-year Computer Science degree over someone who has a 4-year Computer Science degree?


Would I be hired if I showed the employer a project I did in Python that was more impressive than projects done by the 2-year and 4-year degree people?


If so, then hypothetically, what type of project would that be?


Thanks,

Nelson Kane

________________________________
From: Tutor <tutor-bounces+nelsonjonkane6=live.com at python.org> on behalf of Charlotte Hoff Sonne <charlotte.sonne at hotmail.com>
Sent: Monday, February 12, 2018 10:47:13 AM
To: tutor at python.org
Subject: [Tutor] Barplot order-arrangement

Hi,

I have created a barplot in Python. Now I want to arrange the order of the bars differently. I want them to be ordered from highest to lowest - how do I do that? Furthermore, I would like the names of the bars to be vertical - how do I do that?

This is the code I have written:
sns.barplot(x='word',y='andelelite',data=plotpanda)

I have also attached a picture of the plot I have created.
[cid:5226C847-252D-4E1A-9657-D4512B5085B9 at emea.devoteam.com]
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

From charlotte.sonne at hotmail.com  Mon Feb 12 14:10:20 2018
From: charlotte.sonne at hotmail.com (Charlotte Hoff Sonne)
Date: Mon, 12 Feb 2018 19:10:20 +0000
Subject: [Tutor] Barplot order-arrangement
Message-ID: <HE1PR05MB1452C2A53146122097B2E47EE6F70@HE1PR05MB1452.eurprd05.prod.outlook.com>

Hi,

I have created a barplot in Python 3.6.3 on my Mac OS. Now I want to arrange the order of the bars differently. I want them to be ordered from highest to lowest - how do I do that? Furthermore, I would like the names of the bars to be vertical - how do I do that?

This is the code I have written (sns stands for seaborn):
sns.barplot(x='word',y='andelelite',data=plotpanda)

You can see a picture of my bar chart through this link: https://ibb.co/mUKVfn

From cm12789 at gmail.com  Tue Feb 13 07:16:22 2018
From: cm12789 at gmail.com (cm)
Date: Tue, 13 Feb 2018 12:16:22 +0000
Subject: [Tutor] [Help] urllib.error.HTTPError: HTTP Error 400: Bad Request
Message-ID: <CAMk8b23kr1C49io3LrfOYP9cYZHNyCUEivUnXCP++RgFYrpOmQ@mail.gmail.com>

Dear tutors,

I have written below function to open the profanity check url and then
to check for profanity in some text. When I go to the url
http://www.wdylike.appspot.com/?q= and type in the same text, it works
fine.

I am using Microsoft OS X and Python 3.5.2 Interpreter with Pycharm
Community Edition.

---
import urllib.request

def check_profanity(some_text):
    # check text for a curse word
    connection =
urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
    output = connection.read()
    print(output)
    connection.close()

check_profanity(some_text="I gave it a good shot")
---

Error message:
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
line 29, in <module>
    check_profanity(some_text="I gave it a good shot")
  File "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
line 15, in check_profanity
    connection =
urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 472, in open
    response = meth(req, response)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 582,
in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 510, in error
    return self._call_chain(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 444,
in _call_chain
    result = func(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 590,
in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

Process finished with exit code 1

---
However when I run the code it just says Bad Request. I tried to read
into the traceback message but it refers not only to my file but the
urllib function itself too and I can't understand.

Please kindly help me guide to debug the code.

Thank you,
Amy L

From __peter__ at web.de  Tue Feb 13 08:47:56 2018
From: __peter__ at web.de (Peter Otten)
Date: Tue, 13 Feb 2018 14:47:56 +0100
Subject: [Tutor] [Help] urllib.error.HTTPError: HTTP Error 400: Bad
 Request
References: <CAMk8b23kr1C49io3LrfOYP9cYZHNyCUEivUnXCP++RgFYrpOmQ@mail.gmail.com>
Message-ID: <p5uq6e$uvh$1@blaine.gmane.org>

cm wrote:

> Dear tutors,
> 
> I have written below function to open the profanity check url and then
> to check for profanity in some text. When I go to the url
> http://www.wdylike.appspot.com/?q= and type in the same text, it works
> fine.
> 
> I am using Microsoft OS X and Python 3.5.2 Interpreter with Pycharm
> Community Edition.
> 
> ---
> import urllib.request
> 
> def check_profanity(some_text):
>     # check text for a curse word
>     connection =
> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
>     output = connection.read()
>     print(output)
>     connection.close()
> 
> check_profanity(some_text="I gave it a good shot")
> ---
> 
> Error message:
> Traceback (most recent call last):
>   File
>   "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
> line 29, in <module>
>     check_profanity(some_text="I gave it a good shot")
>   File
>   "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
> line 15, in check_profanity
>     connection =
> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 163, in
>   urlopen
>     return opener.open(url, data, timeout)
>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 472, in
>   open
>     response = meth(req, response)
>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 582,
> in http_response
>     'http', request, response, code, msg, hdrs)
>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 510, in
>   error
>     return self._call_chain(*args)
>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 444,
> in _call_chain
>     result = func(*args)
>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 590,
> in http_error_default
>     raise HTTPError(req.full_url, code, msg, hdrs, fp)
> urllib.error.HTTPError: HTTP Error 400: Bad Request
> 
> Process finished with exit code 1
> 
> ---
> However when I run the code it just says Bad Request. I tried to read
> into the traceback message but it refers not only to my file but the
> urllib function itself too and I can't understand.

Spaces aren't allowed in the url:

>>> c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice try")
[...]
urllib.error.HTTPError: HTTP Error 400: Bad Request

Once you escape the ' ':

>>> c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice+try")
>>> c.read()
b'false'

Have a look at the first example at

https://docs.python.org/dev/library/urllib.request.html#urllib-examples

for a more general solution.


From terrapin-turtle at lycos.com  Mon Feb 12 21:49:04 2018
From: terrapin-turtle at lycos.com (terrapin-turtle at lycos.com)
Date: Tue, 13 Feb 2018 02:49:04 +0000
Subject: [Tutor] Pong using python
Message-ID: <aa4a7859e01e962f151f0e773917b15f@lycos.com>

Tutor, 

Are you aware/familiar with DeVry University using python to educate
students using a PONG game? 

Thank you, 

Lost in python using pong

From robertvstepp at gmail.com  Tue Feb 13 22:17:33 2018
From: robertvstepp at gmail.com (boB Stepp)
Date: Tue, 13 Feb 2018 21:17:33 -0600
Subject: [Tutor] Pong using python
In-Reply-To: <aa4a7859e01e962f151f0e773917b15f@lycos.com>
References: <aa4a7859e01e962f151f0e773917b15f@lycos.com>
Message-ID: <CANDiX9KgU6q33vRzP6LUV3p0fudWgmnfPrauc8qbz=_sY0fY+A@mail.gmail.com>

Greetings!

On Mon, Feb 12, 2018 at 8:49 PM,  <terrapin-turtle at lycos.com> wrote:
> Tutor,
>
> Are you aware/familiar with DeVry University using python to educate
> students using a PONG game?

You should assume that we do not.  But we probably can help you if you
provide a specific, targeted question.  Copy and paste a
self-contained code example that demonstrates the problems you are
having in a plain text email.  Copy and paste any error tracebacks you
received (in their entirety).  Let us know which Python version you
are using and your operating system type/version as well.  Ask good
questions and we will do our best to help (But we won't do your
homework for you!).  But if you instead ask vague questions you are
unlikely to get a helpful response.



Good luck and better thinking!
-- 
boB

From cm12789 at gmail.com  Tue Feb 13 19:31:04 2018
From: cm12789 at gmail.com (cm)
Date: Wed, 14 Feb 2018 00:31:04 +0000
Subject: [Tutor] Thanks for the advise to tutor! HTTP Error 400 resolved
Message-ID: <CAMk8b21WsXEQ0B7e=4Uyqk_bp2exEOqA8gv_as_P2DbeOvh1gA@mail.gmail.com>

I have added below to the first line of the function and managed to
ignore the space and solve it. Thank you for the hint!

some_text=urllib.parse.quote_plus(some_text)


On Tue, Feb 13, 2018 at 5:00 PM,  <tutor-request at python.org> wrote:
> Send Tutor mailing list submissions to
>         tutor at 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-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at 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: [Help] urllib.error.HTTPError: HTTP Error 400: Bad
>       Request (Peter Otten)
>
>
> ---------- Forwarded message ----------
> From: Peter Otten <__peter__ at web.de>
> To: tutor at python.org
> Cc:
> Bcc:
> Date: Tue, 13 Feb 2018 14:47:56 +0100
> Subject: Re: [Tutor] [Help] urllib.error.HTTPError: HTTP Error 400: Bad Request
> cm wrote:
>
>> Dear tutors,
>>
>> I have written below function to open the profanity check url and then
>> to check for profanity in some text. When I go to the url
>> http://www.wdylike.appspot.com/?q= and type in the same text, it works
>> fine.
>>
>> I am using Microsoft OS X and Python 3.5.2 Interpreter with Pycharm
>> Community Edition.
>>
>> ---
>> import urllib.request
>>
>> def check_profanity(some_text):
>>     # check text for a curse word
>>     connection =
>> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
>>     output = connection.read()
>>     print(output)
>>     connection.close()
>>
>> check_profanity(some_text="I gave it a good shot")
>> ---
>>
>> Error message:
>> Traceback (most recent call last):
>>   File
>>   "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
>> line 29, in <module>
>>     check_profanity(some_text="I gave it a good shot")
>>   File
>>   "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
>> line 15, in check_profanity
>>     connection =
>> urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
>>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 163, in
>>   urlopen
>>     return opener.open(url, data, timeout)
>>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 472, in
>>   open
>>     response = meth(req, response)
>>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 582,
>> in http_response
>>     'http', request, response, code, msg, hdrs)
>>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 510, in
>>   error
>>     return self._call_chain(*args)
>>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 444,
>> in _call_chain
>>     result = func(*args)
>>   File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 590,
>> in http_error_default
>>     raise HTTPError(req.full_url, code, msg, hdrs, fp)
>> urllib.error.HTTPError: HTTP Error 400: Bad Request
>>
>> Process finished with exit code 1
>>
>> ---
>> However when I run the code it just says Bad Request. I tried to read
>> into the traceback message but it refers not only to my file but the
>> urllib function itself too and I can't understand.
>
> Spaces aren't allowed in the url:
>
>>>> c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice try")
> [...]
> urllib.error.HTTPError: HTTP Error 400: Bad Request
>
> Once you escape the ' ':
>
>>>> c = rq.urlopen("http://www.wdylike.appspot.com/?q=nice+try")
>>>> c.read()
> b'false'
>
> Have a look at the first example at
>
> https://docs.python.org/dev/library/urllib.request.html#urllib-examples
>
> for a more general solution.
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>

From terrapin-turtle at lycos.com  Tue Feb 13 08:41:57 2018
From: terrapin-turtle at lycos.com (terrapin-turtle at lycos.com)
Date: Tue, 13 Feb 2018 13:41:57 +0000
Subject: [Tutor] Pong code
Message-ID: <04c606e591aafb665a7a2f5691bd67b2@lycos.com>

Anyone know the pygame pong code and want to assist in a student learn
where the mistakes in the code reside? 

Yes, reply to this mail.

From alan.gauld at yahoo.co.uk  Wed Feb 14 03:48:28 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 14 Feb 2018 08:48:28 +0000
Subject: [Tutor] Pong code
In-Reply-To: <04c606e591aafb665a7a2f5691bd67b2@lycos.com>
References: <04c606e591aafb665a7a2f5691bd67b2@lycos.com>
Message-ID: <p60t0r$mdj$1@blaine.gmane.org>

On 13/02/18 13:41, terrapin-turtle at lycos.com wrote:
> Anyone know the pygame pong code and want to assist in a student learn
> where the mistakes in the code reside? 
> 
> Yes, reply to this mail.

That's not how it works.

You post a question and the code and any error messages
and we (collectively) try to help you.

It is a community tutor not one to one.

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



From nathantheweird1 at gmail.com  Wed Feb 14 14:18:57 2018
From: nathantheweird1 at gmail.com (Nathantheweird1)
Date: Wed, 14 Feb 2018 13:18:57 -0600
Subject: [Tutor] (no subject)
In-Reply-To: <CAPGRju7xizN6FghuLGt0Lgbssmh59xq86kMBz51bq3EnSYKmqQ@mail.gmail.com>
References: <CAPGRju68obAmnTWaWyS0FrXneS93fXhJgg+z-7vMzzYjjpCjug@mail.gmail.com>
 <CAPGRju5ooCwyVmsW1QCKZOT6Nw8xafxvVmtEgsOSRTLOzQqvew@mail.gmail.com>
 <CAPGRju7xizN6FghuLGt0Lgbssmh59xq86kMBz51bq3EnSYKmqQ@mail.gmail.com>
Message-ID: <CAPGRju5WW5VQrUhynZ5y=OfCwUCjwdXs_x9jPu_3zveJxaZ1uw@mail.gmail.com>

I'm having a problem with my code on an interactive story. All the choices
work until the end. When the code reaches the end, it will print different
functions that aren't even set to be called in the code. I'm not sure what
I've done wrong and can't ask anyone for help because they're learning the
same rate as I am in my computer science class. If you would like, I can
send you a link to my code on pythonroom.com.

From alan.gauld at yahoo.co.uk  Wed Feb 14 19:42:42 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 15 Feb 2018 00:42:42 +0000
Subject: [Tutor] (no subject)
In-Reply-To: <CAPGRju5WW5VQrUhynZ5y=OfCwUCjwdXs_x9jPu_3zveJxaZ1uw@mail.gmail.com>
References: <CAPGRju68obAmnTWaWyS0FrXneS93fXhJgg+z-7vMzzYjjpCjug@mail.gmail.com>
 <CAPGRju5ooCwyVmsW1QCKZOT6Nw8xafxvVmtEgsOSRTLOzQqvew@mail.gmail.com>
 <CAPGRju7xizN6FghuLGt0Lgbssmh59xq86kMBz51bq3EnSYKmqQ@mail.gmail.com>
 <CAPGRju5WW5VQrUhynZ5y=OfCwUCjwdXs_x9jPu_3zveJxaZ1uw@mail.gmail.com>
Message-ID: <p62ku0$5p6$1@blaine.gmane.org>

On 14/02/18 19:18, Nathantheweird1 wrote:
> I'm having a problem with my code on an interactive story. All the choices
> work until the end. When the code reaches the end, it will print different
> functions that aren't even set to be called in the code. I'm not sure what
> I've done wrong and can't ask anyone for help because they're learning the
> same rate as I am in my computer science class.

That shouldn't stop you.
Everyone picks up different things, there's a pretty good chance
that collectively you can solve the problem.

>  If you would like, I can
> send you a link to my code on pythonroom.com.

Well yes. We aren't psychic so, without seeing the code, we haven't
a hope of guessing what you have done.

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



From alan.gauld at yahoo.co.uk  Wed Feb 14 19:59:20 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 15 Feb 2018 00:59:20 +0000
Subject: [Tutor] Pong code
In-Reply-To: <48b472fd729a6502d139048e6156c3b1@lycos.com>
References: <04c606e591aafb665a7a2f5691bd67b2@lycos.com>
 <p60t0r$mdj$1@blaine.gmane.org> <48b472fd729a6502d139048e6156c3b1@lycos.com>
Message-ID: <1a881762-7c50-668a-c689-a81c8afa219d@yahoo.co.uk>

On 14/02/18 23:22, terrapin-turtle at lycos.com wrote:
>
> Alan,
>
> I know NOTHING of this program.
>

So how did you find it?
What do you hope to do with it?

BTW You sent this to me only,. you need to use Reply-All
or Reply-List to include the tutor list. I've CCd the list in this response.

> Here is what I have:
>
> import pygame
> import sys
> import random
> pygame.init()
> gameSurface=pygame.display.set_mode((450,450))
> pygame.display.set_caption("Pong Player")
> pygame.mouse.set_visible(0)
>
> GREEN=(0,200,0)
> BLUE=(0,0,128)
> PURPLE=(102,0,102)
> WHITE=(255,255,255)
>
> rect1x=20
> rect1y=100
> rect2x=400
> rect2y=100
> gameSurface.fill(WHITE)
> pygame.draw.rect(gameSurface, GREEN,(rect1x, rect1y,30,150))
> pygame.draw.rect(gameSurface, GREEN,(rect2x, rect2y,30,150))
> ballx=random.randint(200,300)
> bally=random.randint(100,150)
> pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
> pygame.display.update()
>

So this apparently draws two green rectangles and a ball at
a random location.

> FPS=20
> fpsClock=pygame.time.Clock()
>

This sets the frames per second timer to 20fps.
>
> pygame.key.set_repeat(1,1)
> if event.type==KEYDOWN:
> pygame.quit()
> sys.exit()
>

The previous two lines should be indented.
Indentation is critical in Python so you need to post
in plain text not HTML or RTF. Without the indentation
it gets difficult to tell what is going on.

But in this case it basically exits the program when
the KEYDOWN event is received. (Whatever KEYDOWN and
event mean? in this context - I don't see them defined
anywhere.)

> if event.key==K_q:
> ballx=ballx+1
> pygame.draw.circle(gameSurface, WHITE,(ballx, bally),20)
> pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
>

If q is pressed it draws another 2 balls. I have no idea why,
I never played pong...
>
> if event.key==K_LEFT:
> ballx=ballx-1
> pygame.draw.circle(gameSurface, WHITE,(oldballx, bally),20)
> pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
> if ballx==70:
> pygame.draw.rect(gameSurface, PURPLE,(rect1x, rect1y,30,150))
> if ballx==380:
> pygame.draw.rect(gameSurface,PURPLE,(rect2x, rect2y,30,150))
>
More of the same kind of thing.

> pygame.display.update()
fpsClock.tic(FPS)
>
> pygame.display.update()
>

> What it means????
>

Its a game using PyGame.
Have you read the PyGame tutorial?
If not I suggest you start there and then try asking questions
on the pyGame forum, because almost all the code is PyGame
specific rather than generic Python.

> Does this makes any sense to anyone? 

Sure, I'm sure a PyGame user would find it very straightforward.
You probably just need to do some research/reading.

But the big questions are:
- what is it supposed to do?
- What does it actually do?
- do you get any error messages? If so what?

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


From mats at wichmann.us  Wed Feb 14 21:10:16 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Wed, 14 Feb 2018 19:10:16 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <p62ku0$5p6$1@blaine.gmane.org>
References: <CAPGRju68obAmnTWaWyS0FrXneS93fXhJgg+z-7vMzzYjjpCjug@mail.gmail.com>
 <CAPGRju5ooCwyVmsW1QCKZOT6Nw8xafxvVmtEgsOSRTLOzQqvew@mail.gmail.com>
 <CAPGRju7xizN6FghuLGt0Lgbssmh59xq86kMBz51bq3EnSYKmqQ@mail.gmail.com>
 <CAPGRju5WW5VQrUhynZ5y=OfCwUCjwdXs_x9jPu_3zveJxaZ1uw@mail.gmail.com>
 <p62ku0$5p6$1@blaine.gmane.org>
Message-ID: <857bf26d-7af8-ef99-2c05-0f3fcc94dca9@wichmann.us>

On 02/14/2018 05:42 PM, Alan Gauld via Tutor wrote:
> On 14/02/18 19:18, Nathantheweird1 wrote:
>> I'm having a problem with my code on an interactive story. All the choices
>> work until the end. When the code reaches the end, it will print different
>> functions that aren't even set to be called in the code. I'm not sure what
>> I've done wrong and can't ask anyone for help because they're learning the
>> same rate as I am in my computer science class.
> 
> That shouldn't stop you.
> Everyone picks up different things, there's a pretty good chance
> that collectively you can solve the problem.

second that viewpoint...  I know the classroom environment is different,
but in most professional programming environments you will be working
collaboratively with a team and unless you've been told not to do so in
class, if it's not an exam, working with peers is a great way to learn
skills you will use forever. In the Open Source Software world there's a
famous quote "many eyeballs make all bugs shallow" (Eric Raymond, "The
Cathedral and the Bazaar", a free essay that will be worth a read
someday. It's often referred to as Linus' Law).

From leo.silver at soholinux.com.au  Wed Feb 14 20:27:16 2018
From: leo.silver at soholinux.com.au (Leo Silver)
Date: Thu, 15 Feb 2018 12:27:16 +1100
Subject: [Tutor] Error in class definition of __init__
Message-ID: <CAMvRPDdXuL8u9vm-wa4tK-d4wKfMDO4KKvmGxu9QXUqAT6rO8g@mail.gmail.com>

Hello.

I'm trying to create a class to represent products which includes a list of
volume based pricing and sets the first of these as the unit price:

    def __init__(self, RatePlanID):
        self.id = RatePlanID
        self.name = RatePlans.toggleids[self.id]
        self.pricing = RatePlans.pricebreaks[self.name]
        self.unitprice = RatePlans.pricebreaks[self.name][0]

This code gives an IndexError:
...
    self.unitprice = RatePlans.pricebreaks[self.name][0]
IndexError: list index out of range

However, the same code with the last line changed to:
        self.unitprice = RatePlans.pricebreaks[self.name][:1]

seems to work OK, although, I can't process it further and extract the
second element of the pair.

The list I'm trying to process is:
[(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500,
14.7), (10000, 13.7)]

and a cut and paste into the IDLE GUI let's me process it exactly as I
expect (including picking the second element of the tuple, the price rather
than the volume level):
>>> [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500,
14.7), (10000, 13.7)][0][1]
21.0

What am I missing about the class definition that won't let me put this
class in the init call?

Thanks, Leo.

From __peter__ at web.de  Thu Feb 15 04:12:53 2018
From: __peter__ at web.de (Peter Otten)
Date: Thu, 15 Feb 2018 10:12:53 +0100
Subject: [Tutor] Error in class definition of __init__
References: <CAMvRPDdXuL8u9vm-wa4tK-d4wKfMDO4KKvmGxu9QXUqAT6rO8g@mail.gmail.com>
Message-ID: <p63iqp$m22$1@blaine.gmane.org>

Leo Silver wrote:

> Hello.
> 
> I'm trying to create a class to represent products which includes a list
> of volume based pricing and sets the first of these as the unit price:
> 
>     def __init__(self, RatePlanID):
>         self.id = RatePlanID
>         self.name = RatePlans.toggleids[self.id]
>         self.pricing = RatePlans.pricebreaks[self.name]

To debug your code print out the list and a few other things here with:

          print("name:", self.name)
          print("price breaks:", RatePlans.pricebreaks)
          print("pricebreaks[name]:", RatePlans.pricebreaks[self.name])

>         self.unitprice = RatePlans.pricebreaks[self.name][0]
> 
> This code gives an IndexError:
> ...
>     self.unitprice = RatePlans.pricebreaks[self.name][0]
> IndexError: list index out of range
> 
> However, the same code with the last line changed to:
>         self.unitprice = RatePlans.pricebreaks[self.name][:1]

Slicing allows for the list to be shorter than specified:

>>> items = [1, 2, 3]
>>> items[:1]
[1]
>>> items[:100]
[1, 2, 3]

In your case it's an empty list:

>>> items = []
>>> items[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> items[:1]
[]

> 
> seems to work OK, although, I can't process it further and extract the
> second element of the pair.
> 
> The list I'm trying to process is:
> [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500,
> 14.7), (10000, 13.7)]

I'm pretty sure that's not what you'll see printed if you follow my advice 
and add those print() calls above.

> and a cut and paste into the IDLE GUI let's me process it exactly as I
> expect (including picking the second element of the tuple, the price
> rather than the volume level):
>>>> [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500,
> 14.7), (10000, 13.7)][0][1]
> 21.0
> 
> What am I missing about the class definition that won't let me put this
> class in the init call?

This has nothing to do with __init__() specifically.



From alan.gauld at yahoo.co.uk  Thu Feb 15 04:13:51 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 15 Feb 2018 09:13:51 +0000
Subject: [Tutor] Error in class definition of __init__
In-Reply-To: <CAMvRPDdXuL8u9vm-wa4tK-d4wKfMDO4KKvmGxu9QXUqAT6rO8g@mail.gmail.com>
References: <CAMvRPDdXuL8u9vm-wa4tK-d4wKfMDO4KKvmGxu9QXUqAT6rO8g@mail.gmail.com>
Message-ID: <p63ise$2k9$1@blaine.gmane.org>

On 15/02/18 01:27, Leo Silver wrote:
> Hello.
> 
> I'm trying to create a class to represent products which includes a list of
> volume based pricing and sets the first of these as the unit price:
> 
>     def __init__(self, RatePlanID):
>         self.id = RatePlanID
>         self.name = RatePlans.toggleids[self.id]
>         self.pricing = RatePlans.pricebreaks[self.name]
>         self.unitprice = RatePlans.pricebreaks[self.name][0]
> 

You could simolify the last line to:

         self.unitprice = self.pricing[0]

BTW This process is poor practice since you are effectively
reading the data from a global object (whose definition you don't
share) It would be better to pass the RatePlans into the
init() ass a parameter. Also its bad OO practice to extract
lots of data out of another object to store in your own.
It suggests that either you should be storing a reference to the
object(self.ratePlan, say) or that your RatePlans collection
should be storing some other kind of object which can
be extracted by init (a PriceBreak maybe):

self.foo = RatePlans.getObject(RatePlanID)

Anyway, design issues aside...

> This code gives an IndexError:
> ...
>     self.unitprice = RatePlans.pricebreaks[self.name][0]
> IndexError: list index out of range
> 
> However, the same code with the last line changed to:
>         self.unitprice = RatePlans.pricebreaks[self.name][:1]

These do very different things.
The first uses indexing to extract a single item out of a collection.
The second creates a new collection based on an existing one, but it
does not require the slice values to exist, it will use defaults
if they don't.

> seems to work OK, 

When you say "work" I assume you mean you don;t get an error,
rather than that you have tested it and the unitprice
contains the correct data?

> The list I'm trying to process is:
> [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500,
> 14.7), (10000, 13.7)]

Which list is this in your code?
Is it RatePlans or is it RatePlans.pricebreaks?
Or is it the list returned by RatePlans.pricebreaks[self.name]?
You need to be more specific. I'll assume the last one...

> and a cut and paste into the IDLE GUI let's me process it exactly as I
> expect (including picking the second element of the tuple, the price rather
> than the volume level):
>>>> [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500,
> 14.7), (10000, 13.7)][0][1]

But that's not what you are doing in your code.
You are using variables populated from another object (RatePlans).
Unless you have printed out the values in self.name etc to confirm
they are a valid list. The error message suggests you are retrieving
an empty list. Have you checked?

> What am I missing about the class definition that won't let me put this
> class in the init call?

Nothing, I think the problem is in your RatePlans data.
Coupled to the fact that you are trying to use some very
dodgy OO design.

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



From noreply at resources.webcompliancepanel.com  Fri Feb 16 08:49:42 2018
From: noreply at resources.webcompliancepanel.com (Webcompliancepanel)
Date: Fri, 16 Feb 2018 13:49:42 -0000
Subject: [Tutor] 510k Submission for Device and Software Changes New Guidance
Message-ID: <b2rpwxybf9x318audcyf2by82ar2gd.17407847.3557@mta864.resources.webcompliancepanel.com>

   [1]A Regulatory Perspective: FDA's                            [2]OCP_Logo
   New Guidance's Deciding When to      Call 510-857-5896
   Submit a 510(k) for Device &         38780 Tyson Lane Suite 210 Fremont,
   Software Changes                     CA-94536
   LIVE WEBINAR
   Date: Monday, 12 March 2018
   Time: 10:00 AM PDT | 01:00 PM EDT
      Early Bird Offer! Use Promo Code RECD10 to Get 10% off on Recorded
                            Session/CD/Flash Drive/
   Corporate Live Session/Super Combos of this webinar. Offer valid till Feb
                   18, 2018 midnight. Call us to know more.
   [3][IMG]        [4][IMG] [5][IMG] [10]instructor Carolyn Troiano
   The U.S. FDA has published two                   Carolyn Troiano has
   New Guidance Documents in October                more than 35 years of
   2017, "Deciding When to Submit a                 experience in the
   510(k) for a Change to an                        pharmaceutical, medical
   Existing Device", 1) on the                      device, tobacco and
   device itself, and 2) on device                  other FDA-regulated
   software. These documents attempt                industries. She has
   to provide companies tools to                    worked directly, or on
   perform meaningful, results                      a consulting basis, for
   driven 510(k) / change analysis                  many of the larger
   activities. This is part of a                    pharmaceutical and
   growing push by the Agency to                    tobacco companies in
   strengthen the 510(k) process.                   the US and Europe,
   The addition of simple tools will                developing and
   assist companies in implementing                 executing compliance
   formal, documented, repeatable                   strategies and
   methods with defensible rationale                programs.
   for their decisions on when one                            [11]View More
   or several changes may require a  Similar On-Demand Webinar
   new 510(k) submission. This       [12]FDA Regulation and Legislation
   webinar will provide valuable     of Cosmetics
   assistance to all regulated       [13]View More
   companies performing and
   documenting meaningful, results            [14]NEW! SOP Library
   driven 510(k) / change analysis
   activities, based on the FDA's
   two new Guidance documents on
   510(k) Device and Software
   changes. The new guidance will
   provide manufacturers with a
   greater understanding of the
   FDA's expectations in the current
   regulatory environment.

   Key Learning Objectives

     * Background on 510(k) device
       modifications
     * Important changes in device
       and software modification
       guidances
     * Common software changes that
       might require a 510(k) filing
     * General guidance highlights
     * Software guidance highlights
     * Case study analysis on
       instances requiring/not
       requiring a new 510(k)
   [6]View More
   [7][IMG]
   [8]YES I am Attending
   [9]NO I Want a Different Course
   [15][IMG] [16]Host This Webinar At Your Organization [17][IMG][18]Become a
   Speaker
     [19]WOULD YOU LIKE TO RESERVE YOUR SPOT TODAY AND PAY US LATER? Click
                                     here.
    [20]Please feel free to forward this email to your friends or colleagues

   This message was sent to [21]tutor at python.org by
   Event Marketing Team OnlineCompliancePanel
   [22]www.onlinecompliancepanel.com
   38780 Tyson Lane Suite 210 Fremont, CA - 94536
   Call: +1-510-857-5896 / Fax: +1-510-509-9659
   [23]customersupport at onlinecompliancepanel.com.

   If you do not wish to receive emails from OnlineCompliancePanel Please
   [24]Unsubscribe
   or reply to this email with "Unsubscribe Me" as subject line.

   (c) 2018 OnlineCompliancePanel.com

References

   Visible links
   1. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB
   2. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB
   3. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB
   4. https://www.onlinecompliancepanel.com/ocpFiles/add-calendar/2017/CAROLYN-TROIANO-MAR12.ics
   5. mailto:customersupport at onlinecompliancepanel.com
   6. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB
   7. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB/SHARE
   8. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB
   9. https://www.onlinecompliancepanel.com/webinar
  10. https://www.onlinecompliancepanel.com/expert/Carolyn-Troiano-22466/CHE-CAROLYN-TROIANO-MAR12-EB
  11. https://www.onlinecompliancepanel.com/expert/Carolyn-Troiano-22466/CHE-CAROLYN-TROIANO-MAR12-EB
  12. https://www.onlinecompliancepanel.com/webinar/FDA-Regulation-and-Legislation-of-Cosmetics-504344/CHE-CAROLYN-TROIANO-MAR12-EB
  13. https://www.onlinecompliancepanel.com/campaignSimilarWebinar/508234/CHE-CAROLYN-TROIANO-MAR12-EB/508234-CAROLYN
  14. https://www.onlinecompliancepanel.com/resources-sops/CHE-CAROLYN-TROIANO-MAR12-EB
  15. https://www.onlinecompliancepanel.com/host-webinar/CHE-CAROLYN-TROIANO-MAR12-EB
  16. https://www.onlinecompliancepanel.com/host-webinar/CHE-CAROLYN-TROIANO-MAR12-EB
  17. https://www.onlinecompliancepanel.com/become-speaker/CHE-CAROLYN-TROIANO-MAR12-EB
  18. https://www.onlinecompliancepanel.com/become-speaker/CHE-CAROLYN-TROIANO-MAR12-EB
  19. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB
  20. https://www.onlinecompliancepanel.com/webinar/A-Regulatory-Perspective-FDA-s-New-Guidance-s-Deciding-When-to-Submit-a-510-k-for-Device-Software-Changes-508234/CHE-CAROLYN-TROIANO-MAR12-EB/SHARE
  21. file:///tmp/tmp_OIuYN.html#
  22. http://www.onlinecompliancepanel.com/
  23. mailto:customersupport at onlinecompliancepanel.com
  24. http://ebm.cheetahmail.com/r/webunsub?t=BahtzgB9ZUn-B9k$daABCZ9nkZ&email=tutor at python.org&n=1

From alan.gauld at yahoo.co.uk  Fri Feb 16 14:01:35 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Fri, 16 Feb 2018 19:01:35 +0000
Subject: [Tutor] 510k Submission for Device and Software Changes New
 Guidance
In-Reply-To: <b2rpwxybf9x318audcyf2by82ar2gd.17407847.3557@mta864.resources.webcompliancepanel.com>
References: <b2rpwxybf9x318audcyf2by82ar2gd.17407847.3557@mta864.resources.webcompliancepanel.com>
Message-ID: <p679md$hhv$1@blaine.gmane.org>

Apologies for the spam, I hit the wrong button on the moderation pane.

Alan G.

On 16/02/18 13:49, Webcompliancepanel wrote:
>    [1]A Regulatory Perspective: FDA's                            [2]OCP_Logo
>    New Guidance's Deciding When to      Call 510-857-5896
>    Submit a 510(k) for Device &         38780 Tyson Lane Suite 210 Fremont,
>    Software Changes                     CA-94536
>    LIVE WEBINAR
>    Date: Monday, 12 March 2018
>    Time: 10:00 AM PDT | 01:00 PM EDT


From dbosah at buffalo.edu  Fri Feb 16 17:50:24 2018
From: dbosah at buffalo.edu (Daniel Bosah)
Date: Fri, 16 Feb 2018 17:50:24 -0500
Subject: [Tutor] How to get all previous revision entries of a wikipedia
 page?
Message-ID: <CAFSTFyXLMexgu0WEUJ-U0tcqE+HF5v4K1+VB-Tx3GWCw=OZJXQ@mail.gmail.com>

Hello,

I'm doing research for a compsci group. I'm new at Python, and my task is
the use the Wikipedia API to get all the previous revision entries of a
Wikipedia page and collect them in one list.

Now, I'm totally lost on how to do this. I have never used a API before,
and I'm not sure how to use the Wikipedia API. Is there any resource anyone
can point me to to help me do this? To not only use the API but to also
parse through all the previous edits?

Thanks

From alan.gauld at yahoo.co.uk  Fri Feb 16 18:17:43 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Fri, 16 Feb 2018 23:17:43 +0000
Subject: [Tutor] How to get all previous revision entries of a wikipedia
 page?
In-Reply-To: <CAFSTFyXLMexgu0WEUJ-U0tcqE+HF5v4K1+VB-Tx3GWCw=OZJXQ@mail.gmail.com>
References: <CAFSTFyXLMexgu0WEUJ-U0tcqE+HF5v4K1+VB-Tx3GWCw=OZJXQ@mail.gmail.com>
Message-ID: <p67oml$cjr$1@blaine.gmane.org>

On 16/02/18 22:50, Daniel Bosah wrote:
> Now, I'm totally lost on how to do this. I have never used a API before,
> and I'm not sure how to use the Wikipedia API. Is there any resource anyone
> can point me to to help me do this? To not only use the API but to also
> parse through all the previous edits?

A Google search for Wikipedia API Python led me to this article:

http://2015.compjour.org/tutorials/exploring-wikipedia-api-via-python/

It covers basic use of the API to retrieve data and the lxzml
parser to extract fields from the returned XML

It should get you started.

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



From dbosah at buffalo.edu  Mon Feb 19 15:50:31 2018
From: dbosah at buffalo.edu (Daniel Bosah)
Date: Mon, 19 Feb 2018 15:50:31 -0500
Subject: [Tutor] How to Load Every Revised Wikipedia Page Revision
Message-ID: <CAFSTFyUfBgXZY25nouCiS8h_7fwbwOXuMnvLisvUigA8B_EVbw@mail.gmail.com>

Good day,

I'm doing research for a compsci group. I have a script that is supposed to
load every revised page of a wikipedia article on FDR.

This script is supposed to, in while loop
 access the wikipedia api and using the request library,
access the api
if the continue is in the requests
update the query dict with continue
keep updating until there are no more 'continue' ( or until the API load
limit is reached )
else
break

Here is the code:



def GetRevisions():
    url = "https://en.wikipedia.org/w/api.php" #gets the api and sets it to
a variable
    query = {
    "format": "json",
    "action": "query",
    "titles": "Franklin D. Roosevelt",
    "prop": "revisions",
    "rvlimit": 500,
    }# sets up a dictionary of the arguments of the query

    while True: # in  a while loop
        r = requests.get(url, params = query).json() # does a request call
for the url in the parameters of the query
        print repr(r) #repr gets the "offical" string output of a object
        if 'continue' in r: ## while in the loop, if the keyword is in "r"
            query.update(r['continue']) # updates the dictionary to include
continue in it, and keeps on printing out all instances of 'continue"
        else: # else
           break # quit loop



I want to load every page version with the revisions of the wikipedia page,
not just the info about the page revision. How can I go about that?

Thanks

From bandagunda at hotmail.com  Tue Feb 20 10:18:30 2018
From: bandagunda at hotmail.com (banda gunda)
Date: Tue, 20 Feb 2018 15:18:30 +0000
Subject: [Tutor] pandas
Message-ID: <HE1PR0602MB325734AE13D2F753BA8DE1EBDECF0@HE1PR0602MB3257.eurprd06.prod.outlook.com>

Dear tutor,


python3

pandas


The function below returns the maximum cost row of the df.


def maximum():
    return [df.loc[df['cost'].idxmax()]]

 maximum()


But I am only interested in specific column of the df.

How could I extract from the returned row of the df?


Thanks in advance.

Best.

banda


From dbosah at buffalo.edu  Wed Feb 21 03:36:36 2018
From: dbosah at buffalo.edu (dbosah)
Date: Wed, 21 Feb 2018 03:36:36 -0500
Subject: [Tutor] Fwd: How to Load Every Revised Wikipedia Page Revision
In-Reply-To: <CAFSTFyUfBgXZY25nouCiS8h_7fwbwOXuMnvLisvUigA8B_EVbw@mail.gmail.com>
Message-ID: <20180221083639.B181A317468E@smtp.buffalo.edu>





Sent from my T-Mobile 4G LTE Device
-------- Original message --------From: Daniel Bosah <dbosah at buffalo.edu> Date: 2/19/18  3:50 PM  (GMT-05:00) To: tutor at python.org Subject: How to Load Every Revised Wikipedia Page Revision 
Good day,
I'm doing research for a compsci group. I have a script that is supposed to load every revised page of a wikipedia article on FDR.
This script is supposed to, in while loop?access the wikipedia api and using the request library,?access the apiif the continue is in the requestsupdate the query dict with continuekeep updating until there are no more 'continue' ( or until the API load limit is reached )elsebreak
Here is the code:


def GetRevisions():? ? url = "https://en.wikipedia.org/w/api.php" #gets the api and sets it to a variable? ? query = {? ? "format": "json",? ? "action": "query",? ? "titles": "Franklin D. Roosevelt",? ? "prop": "revisions",? ? "rvlimit": 500,? ? }# sets up a dictionary of the arguments of the query?
? ? while True: # in? a while loop? ? ? ? r = requests.get(url, params = query).json() # does a request call for the url in the parameters of the query? ? ? ? print repr(r) #repr gets the "offical" string output of a object? ? ? ? if 'continue' in r: ## while in the loop, if the keyword is in "r"? ? ? ? ? ? query.update(r['continue']) # updates the dictionary to include continue in it, and keeps on printing out all instances of 'continue"? ? ? ? else: # else? ? ? ? ? ?break # quit loop


I want to load every page version with the revisions of the wikipedia page, not just the info about the page revision. How can I go about that?

Thanks


From jbernts at broadpark.no  Thu Feb 22 06:12:50 2018
From: jbernts at broadpark.no (Jostein Berntsen)
Date: Thu, 22 Feb 2018 12:12:50 +0100
Subject: [Tutor] How to Load Every Revised Wikipedia Page Revision
In-Reply-To: <CAFSTFyUfBgXZY25nouCiS8h_7fwbwOXuMnvLisvUigA8B_EVbw@mail.gmail.com>
References: <CAFSTFyUfBgXZY25nouCiS8h_7fwbwOXuMnvLisvUigA8B_EVbw@mail.gmail.com>
Message-ID: <20180222111250.GI2361@jbsupah>

On 19.02.18,15:50, Daniel Bosah wrote:
> Good day,
> 
> I'm doing research for a compsci group. I have a script that is supposed to
> load every revised page of a wikipedia article on FDR.
> 
> This script is supposed to, in while loop
>  access the wikipedia api and using the request library,
> access the api
> if the continue is in the requests
> update the query dict with continue
> keep updating until there are no more 'continue' ( or until the API load
> limit is reached )
> else
> break
> 
> Here is the code:
> 
> 
> 
> def GetRevisions():
>     url = "https://en.wikipedia.org/w/api.php" #gets the api and sets it to
> a variable
>     query = {
>     "format": "json",
>     "action": "query",
>     "titles": "Franklin D. Roosevelt",
>     "prop": "revisions",
>     "rvlimit": 500,
>     }# sets up a dictionary of the arguments of the query
> 
>     while True: # in  a while loop
>         r = requests.get(url, params = query).json() # does a request call
> for the url in the parameters of the query
>         print repr(r) #repr gets the "offical" string output of a object
>         if 'continue' in r: ## while in the loop, if the keyword is in "r"
>             query.update(r['continue']) # updates the dictionary to include
> continue in it, and keeps on printing out all instances of 'continue"
>         else: # else
>            break # quit loop
> 
> 
> 
> I want to load every page version with the revisions of the wikipedia page,
> not just the info about the page revision. How can I go about that?
> 

There are different kinds of Python Wikipedia APIs available. Do you try 
any of these? 

https://pypi.python.org/pypi/wikipedia

http://wikipedia.readthedocs.io/en/latest/code.html#api

https://pypi.python.org/pypi/Wikipedia-API

https://github.com/richardasaurus/wiki-api


Jostein



From davidallenbauer at gmail.com  Thu Feb 22 17:16:40 2018
From: davidallenbauer at gmail.com (David Bauer)
Date: Thu, 22 Feb 2018 14:16:40 -0800
Subject: [Tutor] I have a problem with def
Message-ID: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>

it doesn't work, you are suppsed to declare a function as def func() and it
comes back as:

File "<stdin>", line 1
    def func()
             ^
SyntaxError: invalid syntax

that is not expected I would also expect def to turn red because it is a
keyword in Python, but that doesn't happen, anyone else having this
problem???? Anyone know what I should do or look for????

From gonzaleshuerta24 at gmail.com  Thu Feb 22 22:34:53 2018
From: gonzaleshuerta24 at gmail.com (gonzales huerta)
Date: Thu, 22 Feb 2018 22:34:53 -0500
Subject: [Tutor] startin python
Message-ID: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>

SIRS
I am an absolute  beginner in PYTHON  so I would like to ask your
advice regarding the appropriate  compilers.
What would be the best compiler for a beginner?
What would be the best compiler for writing a combined code PYTHON and C?
3)I need PYTHON  for the following purposes:
A)EMBEDDED SYSTEM PROGRAMMING
B)SCIENTIFIC PROGRAMMING
C)IMAGE AND VIDEO PROCESSING
D)DATA VISUALIZATION
E)REAL TIME GUI
F)DESIGNING PC BASED MEASURING SYSTEMS (like  pc dso,logic analyzer,ect)
Please let me know what kind of PYTHON libraries would    the most
adequate for these tasks and where it would be possible to download
them and if possibe direct me to the corresponding PYTHON  literature
Thank you for your collaboration
  JEOVANNY VITERI

From breamoreboy at gmail.com  Fri Feb 23 04:03:18 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Fri, 23 Feb 2018 09:03:18 +0000
Subject: [Tutor] I have a problem with def
In-Reply-To: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>
References: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>
Message-ID: <p6ol8n$hlt$1@blaine.gmane.org>

On 22/02/18 22:16, David Bauer wrote:
> it doesn't work, you are suppsed to declare a function as def func() and it
> comes back as:
> 
> File "<stdin>", line 1
>      def func()
>               ^
> SyntaxError: invalid syntax
> 
> that is not expected I would also expect def to turn red because it is a
> keyword in Python, but that doesn't happen, anyone else having this
> problem???? Anyone know what I should do or look for????

The colon is missing.

def func():
     ...
-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From steve at pearwood.info  Fri Feb 23 05:48:08 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 23 Feb 2018 21:48:08 +1100
Subject: [Tutor] startin python
In-Reply-To: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>
References: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>
Message-ID: <20180223104807.GI10142@ando.pearwood.info>

Hello, and see my comments below.

On Thu, Feb 22, 2018 at 10:34:53PM -0500, gonzales huerta wrote:
> SIRS
> I am an absolute  beginner in PYTHON  so I would like to ask your
> advice regarding the appropriate  compilers.
> What would be the best compiler for a beginner?

Python is normally described as using an interpreter.

(Technically it has a compiler, but it is a byte-code compiler, it 
doesn't generate machine code.)

Stick to the standard Python 3 interpreter unless you need to run Java 
libraries or run under .Net,


> What would be the best compiler for writing a combined code PYTHON and C?

There's no such thing as a combined Python and C compiler, although 
Cython comes close. But I would say Cython is probably not for 
beginners, if you don't know Python, you'll struggle with Cython.


> 3)I need PYTHON  for the following purposes:
> A)EMBEDDED SYSTEM PROGRAMMING
> B)SCIENTIFIC PROGRAMMING
> C)IMAGE AND VIDEO PROCESSING
> D)DATA VISUALIZATION
> E)REAL TIME GUI
> F)DESIGNING PC BASED MEASURING SYSTEMS (like  pc dso,logic analyzer,ect)
> Please let me know what kind of PYTHON libraries would    the most
> adequate for these tasks and where it would be possible to download
> them and if possibe direct me to the corresponding PYTHON  literature

Do you know how to use a search engine?

https://duckduckgo.com/html/?q=scientific%20python%20ide

For embedded programming, you will probably want to use MicroPython 
instead of the regular Python interpreter.

You could try a commercial IDE like Enthought Canopy, PyCharm, 
ActiveState's Python (I think this one is called Anaconda?), or the Wing 
Python IDE.

https://wingware.com/

A free alternative is Spyder, although this is the only one I've 
actually used and I found it to be unusably slow on my computer.

Another alternative is iPython, which lets you write notebooks rather 
like Mathematica.

It is not helpful to ask what libraries you should use when we don't 
know what you will be doing, but in general, the most common third-party 
libraries for scientific programming include:

numpy
scipy
pandas
matplotlib


and probably a thousand others.



-- 
Steve

From bhaskaran.vinod at gmail.com  Fri Feb 23 06:26:03 2018
From: bhaskaran.vinod at gmail.com (vinod bhaskaran)
Date: Fri, 23 Feb 2018 16:56:03 +0530
Subject: [Tutor] Doubt in list comprehension
Message-ID: <CAKS=jrDg6cp_xbwoDT66YYaN7rHgfZMfw2kuXrnwBpZiVH7VBg@mail.gmail.com>

Hi All,

I am a beginner programmer and i wrote a small program (as per a assignment
i saw) as below:

newlist = []
for a in range(2,5):
  for b in range (0,3):
    newlist.append([a])
    a = a + 1
print(newlist)

it gives the expected output as below:
[[2], [3], [4], [3], [4], [5], [4], [5], [6]]

but when i try list comprehension i am not able to get it correct....can
someone please suggest where the (a=a+1) should be placed in a list
comprehension

Thanks,
Vinod Bhaskaran

From __peter__ at web.de  Fri Feb 23 08:40:48 2018
From: __peter__ at web.de (Peter Otten)
Date: Fri, 23 Feb 2018 14:40:48 +0100
Subject: [Tutor] Doubt in list comprehension
References: <CAKS=jrDg6cp_xbwoDT66YYaN7rHgfZMfw2kuXrnwBpZiVH7VBg@mail.gmail.com>
Message-ID: <p6p5h2$hhr$1@blaine.gmane.org>

vinod bhaskaran wrote:

> Hi All,
> 
> I am a beginner programmer and i wrote a small program (as per a
> assignment i saw) as below:
> 
> newlist = []
> for a in range(2,5):
>   for b in range (0,3):
>     newlist.append([a])
>     a = a + 1
> print(newlist)
> 
> it gives the expected output as below:
> [[2], [3], [4], [3], [4], [5], [4], [5], [6]]
> 
> but when i try list comprehension i am not able to get it correct....can
> someone please suggest where the (a=a+1) should be placed in a list
> comprehension

You canot sneak a statement like

>     a = a + 1

into a list comprehension, you have to modify the expressions. Given

[[...] for a in range(2, 5) for b in range(3)]

what expression replacing the ... would give the expected result? 

Hint: it depends on both a and b.

Once you have figured it out you can try and reshuffle it a bit into

[[b] for a in range(2, 5) for b in range(...)]


From bgailer at gmail.com  Fri Feb 23 08:49:57 2018
From: bgailer at gmail.com (Bob Gailer)
Date: Fri, 23 Feb 2018 08:49:57 -0500
Subject: [Tutor] I have a problem with def
In-Reply-To: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>
References: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>
Message-ID: <CAP1rxO5w4UeZkHOkzzfVdEVAK220NuDKaXs6tbf+16bXfbxP+g@mail.gmail.com>

On Feb 23, 2018 3:58 AM, "David Bauer" <davidallenbauer at gmail.com> wrote:
>
> it doesn't work, you are suppsed to declare a function as def func() and
it
> comes back as:
>
> File "<stdin>", line 1
>     def func()
>              ^
> SyntaxError: invalid syntax
>
> that is not expected I would also expect def to turn red because it is a
> keyword in Python, but that doesn't happen

That is an effect of syntax coloring. That in turn depends on what you're
using to enter your program. Please tell us what you are using to enter
your program and we can help with that.

anyone else having this
> problem???? Anyone know what I should do or look for????
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From mats at wichmann.us  Fri Feb 23 09:29:20 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Fri, 23 Feb 2018 07:29:20 -0700
Subject: [Tutor] Doubt in list comprehension
In-Reply-To: <p6p5h2$hhr$1@blaine.gmane.org>
References: <CAKS=jrDg6cp_xbwoDT66YYaN7rHgfZMfw2kuXrnwBpZiVH7VBg@mail.gmail.com>
 <p6p5h2$hhr$1@blaine.gmane.org>
Message-ID: <cf86ede0-736c-d7d8-2dec-69fe80818cc1@wichmann.us>

On 02/23/2018 06:40 AM, Peter Otten wrote:
> vinod bhaskaran wrote:
> 
>> Hi All,
>>
>> I am a beginner programmer and i wrote a small program (as per a
>> assignment i saw) as below:
>>
>> newlist = []
>> for a in range(2,5):
>>   for b in range (0,3):
>>     newlist.append([a])
>>     a = a + 1
>> print(newlist)
>>
>> it gives the expected output as below:
>> [[2], [3], [4], [3], [4], [5], [4], [5], [6]]
>>
>> but when i try list comprehension i am not able to get it correct....can
>> someone please suggest where the (a=a+1) should be placed in a list
>> comprehension
> 
> You canot sneak a statement like
> 
>>     a = a + 1

I would go further: you should not be sneaking it into your original
code either - it's not a great idea to modify the iteration variable
while inside the loop. It works this time because you're iterating over
a list that has been made for you by range:

>>> print(range(2,5))
[2, 3, 4]

so second time through 'a' gets the second value in the list and it
doesn't break things that you changed 'a' while it was in use, but it's
a bad habit to get into - if you use the same concept in a while loop,
say, you will get unpleasant surprises.

So to further Peter's suggestion - try to figure out how to stop doing
that in your inner loop, and it will be much more clear what to do in
the comprehension form.





From mats at wichmann.us  Fri Feb 23 09:45:52 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Fri, 23 Feb 2018 07:45:52 -0700
Subject: [Tutor] startin python
In-Reply-To: <20180223104807.GI10142@ando.pearwood.info>
References: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>
 <20180223104807.GI10142@ando.pearwood.info>
Message-ID: <d07b89fa-6871-edeb-2bc8-82333086fee0@wichmann.us>

Just a quick clarification:

> You could try a commercial IDE like Enthought Canopy, PyCharm, 
> ActiveState's Python (I think this one is called Anaconda?), or the Wing 
> Python IDE.

ActiveState's Python is ActivePython while Anaconda is a separate
distribution, also very useful. Both orient themselves now as being a
"Data Science Platform" - more familiar with Anaconda, it's nice because
it gives you lots of the scientific, etc. stuff installed without
problems, and the installer makes adding more fairly easy. I believe
ActivePython now is similar.

From johnf at jfcomputer.com  Fri Feb 23 10:48:15 2018
From: johnf at jfcomputer.com (john fabiani)
Date: Fri, 23 Feb 2018 07:48:15 -0800
Subject: [Tutor] I have a problem with def
In-Reply-To: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>
References: <CAJ=pNhFO=5okJD4TqNsCv+UNCqBytnLnAP53pExboBktvGQ-fw@mail.gmail.com>
Message-ID: <3d2d6564-91c5-edb6-96f1-3edb5230089b@jfcomputer.com>

I don't what you are doing but

it should be at least

def func():

notice the colon at the end.

Johnf


On 02/22/2018 02:16 PM, David Bauer wrote:
> it doesn't work, you are suppsed to declare a function as def func() and it
> comes back as:
>
> File "<stdin>", line 1
>      def func()
>               ^
> SyntaxError: invalid syntax
>
> that is not expected I would also expect def to turn red because it is a
> keyword in Python, but that doesn't happen, anyone else having this
> problem???? Anyone know what I should do or look for????
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


From bhaskaran.vinod at gmail.com  Fri Feb 23 08:56:15 2018
From: bhaskaran.vinod at gmail.com (vinod bhaskaran)
Date: Fri, 23 Feb 2018 13:56:15 +0000
Subject: [Tutor] Doubt in list comprehension
In-Reply-To: <p6p5h2$hhr$1@blaine.gmane.org>
References: <CAKS=jrDg6cp_xbwoDT66YYaN7rHgfZMfw2kuXrnwBpZiVH7VBg@mail.gmail.com>
 <p6p5h2$hhr$1@blaine.gmane.org>
Message-ID: <CAKS=jrC_D2M5QxtGNRFFWAtLtXUzQxYOLat9xFvLBnjfLgwJ=Q@mail.gmail.com>

Thanks Peter.

Shall figure it out with the below hint. I had a hunch am wrong but was not
sure where to put in .

Thanks,
Vinod Bhaskaran

On Fri, Feb 23, 2018, 7:11 PM Peter Otten <__peter__ at web.de> wrote:

> vinod bhaskaran wrote:
>
> > Hi All,
> >
> > I am a beginner programmer and i wrote a small program (as per a
> > assignment i saw) as below:
> >
> > newlist = []
> > for a in range(2,5):
> >   for b in range (0,3):
> >     newlist.append([a])
> >     a = a + 1
> > print(newlist)
> >
> > it gives the expected output as below:
> > [[2], [3], [4], [3], [4], [5], [4], [5], [6]]
> >
> > but when i try list comprehension i am not able to get it correct....can
> > someone please suggest where the (a=a+1) should be placed in a list
> > comprehension
>
> You canot sneak a statement like
>
> >     a = a + 1
>
> into a list comprehension, you have to modify the expressions. Given
>
> [[...] for a in range(2, 5) for b in range(3)]
>
> what expression replacing the ... would give the expected result?
>
> Hint: it depends on both a and b.
>
> Once you have figured it out you can try and reshuffle it a bit into
>
> [[b] for a in range(2, 5) for b in range(...)]
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From gonzaleshuerta24 at gmail.com  Fri Feb 23 10:08:28 2018
From: gonzaleshuerta24 at gmail.com (gonzales huerta)
Date: Fri, 23 Feb 2018 10:08:28 -0500
Subject: [Tutor] startin python
In-Reply-To: <20180223104807.GI10142@ando.pearwood.info>
References: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>
 <20180223104807.GI10142@ando.pearwood.info>
Message-ID: <CAN6dJE7tydti6gf3fahtGYEOz=QpCijGW-y5Q4CwzF69QO=2sg@mail.gmail.com>

Thank you very much for the tips
I hope we will be in touch in the futire
  jeovanny

2018-02-23 5:48 GMT-05:00, Steven D'Aprano <steve at pearwood.info>:
> Hello, and see my comments below.
>
> On Thu, Feb 22, 2018 at 10:34:53PM -0500, gonzales huerta wrote:
>> SIRS
>> I am an absolute  beginner in PYTHON  so I would like to ask your
>> advice regarding the appropriate  compilers.
>> What would be the best compiler for a beginner?
>
> Python is normally described as using an interpreter.
>
> (Technically it has a compiler, but it is a byte-code compiler, it
> doesn't generate machine code.)
>
> Stick to the standard Python 3 interpreter unless you need to run Java
> libraries or run under .Net,
>
>
>> What would be the best compiler for writing a combined code PYTHON and C?
>
> There's no such thing as a combined Python and C compiler, although
> Cython comes close. But I would say Cython is probably not for
> beginners, if you don't know Python, you'll struggle with Cython.
>
>
>> 3)I need PYTHON  for the following purposes:
>> A)EMBEDDED SYSTEM PROGRAMMING
>> B)SCIENTIFIC PROGRAMMING
>> C)IMAGE AND VIDEO PROCESSING
>> D)DATA VISUALIZATION
>> E)REAL TIME GUI
>> F)DESIGNING PC BASED MEASURING SYSTEMS (like  pc dso,logic analyzer,ect)
>> Please let me know what kind of PYTHON libraries would    the most
>> adequate for these tasks and where it would be possible to download
>> them and if possibe direct me to the corresponding PYTHON  literature
>
> Do you know how to use a search engine?
>
> https://duckduckgo.com/html/?q=scientific%20python%20ide
>
> For embedded programming, you will probably want to use MicroPython
> instead of the regular Python interpreter.
>
> You could try a commercial IDE like Enthought Canopy, PyCharm,
> ActiveState's Python (I think this one is called Anaconda?), or the Wing
> Python IDE.
>
> https://wingware.com/
>
> A free alternative is Spyder, although this is the only one I've
> actually used and I found it to be unusably slow on my computer.
>
> Another alternative is iPython, which lets you write notebooks rather
> like Mathematica.
>
> It is not helpful to ask what libraries you should use when we don't
> know what you will be doing, but in general, the most common third-party
> libraries for scientific programming include:
>
> numpy
> scipy
> pandas
> matplotlib
>
>
> and probably a thousand others.
>
>
>
> --
> Steve
>

From alan.gauld at btinternet.com  Fri Feb 23 13:09:33 2018
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 23 Feb 2018 18:09:33 +0000
Subject: [Tutor] startin python
In-Reply-To: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>
References: <CAN6dJE4PwfZ87C+zTvjYcdGszVGQvphe715TmPDpn=6WCmkdew@mail.gmail.com>
Message-ID: <ec333146-7b92-041e-b2d9-8305a9839709@btinternet.com>

On 23/02/18 03:34, gonzales huerta wrote:
> What would be the best compiler for writing a combined code PYTHON and C?

There are several ways to do this and it depends on your application
which is
most practical. If w assume yyou want to access the C code from Python then:

1) Write a Python module in C and then import it into Python

2) Write a C library and call it from Python (using the ctypes
Python module for example)

3) Write a C program and then call it from Python using the
subprocess library.

These are in reverse order of difficulty (ie 3 is easiest).
1 is best if you need to access the C code from several Pyhon programs.
2 is best if you need to access the C code from both Python and C
3 is best if you only have a few high-level tasks to perform in C, and
want the simplest integration.

If you want to access Pyhon code from C then you need

1) Embed the Python intetrpreter in your C code ande call it
using the Python API.

2) Write a Python service framework that can be called from C using
fork/system or whatever

3) Create a Python http server that you can call from
C (or any other language) using AJAX

1) Most difficult but best performance and loweset resource usage,
2) Relatively easy but resource heavy
3) Easiest if you know web technology and best if you might need
several programs to access it, but probably slowest too.

There are other options too (Steve mentioned Cython and there
are tools like Boost too)

> 3)I need PYTHON  for the following purposes:
> A)EMBEDDED SYSTEM PROGRAMMING
See the comments above re integrating C and Python.
> B)SCIENTIFIC PROGRAMMING
> C)IMAGE AND VIDEO PROCESSING
> D)DATA VISUALIZATION
Down to here suggests you get a distribution with all the SciPy
stuff included such as Anaconda or Entropy. Anaconda seems
to be the most popular so probably has best support network.
> E)REAL TIME GUI

That's pretty much a contradiction in terms, GUIs are hardly
ever truly real-time. However Python can create GUIs that talk
to real-time back end processes or threads.

> F)DESIGNING PC BASED MEASURING SYSTEMS (like  pc dso,logic analyzer,ect)

I'm not familiar with these so can't comment

> Please let me know what kind of PYTHON libraries 

If you get Anaconda etc then most libraries you need will be included.
That then leaves application specific libraries that you would
need to describe your needs in more detail for anyone to give
recommendations.


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


From jamesalundy at hotmail.com  Sat Feb 24 15:00:58 2018
From: jamesalundy at hotmail.com (James Lundy)
Date: Sat, 24 Feb 2018 20:00:58 +0000
Subject: [Tutor] List vs. Set:
Message-ID: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>

To whom it may concern. This code is from Dr. John Keyser.


gooddata = []

for singleday in datalist:
    if (singleday[0] == day) and (singleday[1] == month):
        gooddata.append({singleday[2], singleday[3], singleday[4], singleday[5]})

# Perform analysis
minsofar = 120
maxsofar = -100
numgooddates = 1
sumofmin = 0
sumofmax = 0

# so singleday in datalist is a list while singleday in gooddata is a set?????????

for singleday in gooddata:

    sumofmin += singleday[1]
    sumofmax += singleday[2]
    if singleday[1] < minsofar:
        minsofar = singleday[1]
    if singleday[2] > maxsofar:
        maxsofar = singleday[2]

Could this be a bug in my Pycharm 3 compiler I have had mixed experiences running the code.

An insertion of a space after for singleday in gooddata: line 54 caused the program to run as desired, once, since other runs cause the error


Traceback (most recent call last):

  File "C:/Users/Dad/PycharmProjects/TopDownDesign/WeatherDataSpecialDay.py", line 56, in <module>

    sumofmin += singleday[1]

TypeError: 'set' object does not support indexing

persist.

I will attach the code and test file. Please allow me to thank you in advance for answering this query. I am new with Python and would appreciate any advice.

God Bless:

James Lundy
jalundy at computer.org<mailto:jalundy at computer.org>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: WeatherDataSpecialDay.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20180224/cb1c4533/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: WeatherData.txt
URL: <http://mail.python.org/pipermail/tutor/attachments/20180224/cb1c4533/attachment.txt>

From alan.gauld at yahoo.co.uk  Sun Feb 25 04:26:27 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sun, 25 Feb 2018 09:26:27 +0000
Subject: [Tutor] List vs. Set:
In-Reply-To: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>
References: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>
Message-ID: <p6tvc1$6hh$1@blaine.gmane.org>

On 24/02/18 20:00, James Lundy wrote:
> To whom it may concern. This code is from Dr. John Keyser.

Since you don;t show us the complete program I will have
to make some assumptions...

> gooddata = []

This is degioned as a list by virtue of the []

> for singleday in datalist:
>     if (singleday[0] == day) and (singleday[1] == month):
>         gooddata.append({singleday[2], singleday[3], singleday[4], singleday[5]})

This appends a set by virtue of the {}

The bracket type is what defines the data type.

> # Perform analysis
> minsofar = 120
> maxsofar = -100
> numgooddates = 1
> sumofmin = 0
> sumofmax = 0
> 
> # so singleday in datalist is a list while singleday in gooddata is a set?????????

I don't know what singleday is since you don't show it's creation.
But singleday does not exist in gooddata. Instead you have created
a set that contains some elements from singleday. But those values
are copies that bear no relation to the original singleday elements.

> for singleday in gooddata:

This creates a new singleday object that is not related to the
original singleday. This one will be an instance of whatever
is in gooddata. In this case we know these are sets.

>     sumofmin += singleday[1]

And you can't index a set. So you get an error.
If you want singleday to be a list you either need to insert
a list in the first loop or explicitly convert the set to
a list. But bear in mind that sets have no defined order
so you may not get the values out in the order you put
them in. And sets don;t allow duplicates so if two of
your original singleday values were identical one would
be thrown away.

I suspect you really wanted to use a list in the top
for loop:

    if (singleday[0] == day) and (singleday[1] == month):
        gooddata.append( [ singleday[2], singleday[3],
                           singleday[4], singleday[5] ]
                       )

Note however that the indexes will not be carried over, so in your
second loop singleday[1] refers to the old singleday[3].

If you want to retain the original indexes (and all the elements)
then just append singleday itself:

    if (singleday[0] == day) and (singleday[1] == month):
        gooddata.append( singleday )

> Could this be a bug in my Pycharm 3 compiler 

Nope, it is extremely unlikely that you will find a bug
in any compiler or interpreter(*). You should always assume
that the fault is in your code first and only consider
the compiler when all else has been eliminated.

(*)In 40 years of programming I've only once found
such a bug and it only manifested itself with a very
arcane - and slightly suspect - piece of code. Compilers
and interpreters tend to be very rigorously tested;
because they can be -  they have a very clearly defined
function.

> TypeError: 'set' object does not support indexing
> 
> persist.

Because you are creating a list of sets.
Change the set to a list and the problem will go away.

> I will attach the code and test file. 

The list server doesn't like attachments (although
text is usually OK) its better to paste things into
the message or provide a link to a web site)

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



From breamoreboy at gmail.com  Sun Feb 25 04:47:43 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Sun, 25 Feb 2018 09:47:43 +0000
Subject: [Tutor] List vs. Set:
In-Reply-To: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>
References: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>
Message-ID: <p6u0k0$40u$1@blaine.gmane.org>

On 24/02/18 20:00, James Lundy wrote:
> To whom it may concern. This code is from Dr. John Keyser.

Please arrange for him to go on a programming course :-)

> 
> 
> gooddata = []
> 
> for singleday in datalist:
>      if (singleday[0] == day) and (singleday[1] == month):

Yuck, unneeded brackets disease.

>          gooddata.append({singleday[2], singleday[3], singleday[4], singleday[5]})

That looks like a set to me.

> 
> # Perform analysis
> minsofar = 120
> maxsofar = -100
> numgooddates = 1
> sumofmin = 0
> sumofmax = 0
> 
> # so singleday in datalist is a list while singleday in gooddata is a set?????????

Seems like it.

> 
> for singleday in gooddata:
> 
>      sumofmin += singleday[1]
>      sumofmax += singleday[2]
>      if singleday[1] < minsofar:
>          minsofar = singleday[1]
>      if singleday[2] > maxsofar:
>          maxsofar = singleday[2]
> 
> Could this be a bug in my Pycharm 3 compiler I have had mixed experiences running the code.

I very much doubt that.

> 
> An insertion of a space after for singleday in gooddata: line 54 caused the program to run as desired, once, since other runs cause the error

Really, I don't see how?

> 
> 
> Traceback (most recent call last):
> 
>    File "C:/Users/Dad/PycharmProjects/TopDownDesign/WeatherDataSpecialDay.py", line 56, in <module>
> 
>      sumofmin += singleday[1]
> 
> TypeError: 'set' object does not support indexing
> 
> persist.
> 
> I will attach the code and test file. Please allow me to thank you in advance for answering this query. I am new with Python and would appreciate any advice.

Put print calls into the code that you don't show above.  This should 
show what gets written to the datalist and it's type, ditto for the 
gooddata list.  I think you'll find that the code "works" when an 
invalid day and month gets input, yet produces the traceback when a 
valid day and month is input.

> 
> God Bless:
> 
> James Lundy
> jalundy at computer.org<mailto:jalundy at computer.org>
> 

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From steve at pearwood.info  Sun Feb 25 04:44:16 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 25 Feb 2018 20:44:16 +1100
Subject: [Tutor] List vs. Set:
In-Reply-To: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>
References: <CY4PR10MB1445F23BC32F7E5E2872AD69B4C30@CY4PR10MB1445.namprd10.prod.outlook.com>
Message-ID: <20180225094416.GN10142@ando.pearwood.info>

On Sat, Feb 24, 2018 at 08:00:58PM +0000, James Lundy wrote:

> Could this be a bug in my Pycharm 3 compiler I have had mixed 
> experiences running the code.

As a general rule, any time you get an unexpected error and think "Could 
this be a bug in the compiler?", the chances are almost always "No".

Which is more likely?

- tens or hundreds of thousands of people have used this compiler, and 
never noticed this bug? or

- the bug is in my code?

Even for experts, the chances are that the bug is in their code. The 
difference between the expert and the beginner is that the expert has a 
good shot at recognising that one-in-a-million time that it actually is 
an undiscovered bug in the compiler.

In the case of your code, I think the problem is this line:

>         gooddata.append({singleday[2], singleday[3], singleday[4], singleday[5]})

In particular, the part between the curly brackets (braces):

    # curly brackets make a set
    { singleday[2], ... }

makes a set. My guess is that you were intending a list:

    # square brackets make a list
    [ singleday[2], ... ]

But there's a better way to fix this. You are grabbing four items out of 
a list, in order. Python has a short-cut for doing that:

    # the long way
    [singleday[2], singleday[3], singleday[4], singleday[5]]

    # the short (and faster!) way
    singleday[2:6]

Notice that the first index (2) is included, but the second index (6) is 
excluded. While it might seem confusing at first, this actually helps 
prevent "off by one" errors.

So the troublesome line becomes:

    gooddata.append(singleday[2:6])

and, I believe, that ought to fix the bug. Possibly, or possibly not, 
to reveal any more bugs... *smiles*


Regards,


-- 
Steve

From rls4jc at gmail.com  Mon Feb 26 14:01:49 2018
From: rls4jc at gmail.com (Roger Lea Scherer)
Date: Mon, 26 Feb 2018 11:01:49 -0800
Subject: [Tutor] Regex not working as desired
Message-ID: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>

  The first step is to input data and then I want to check to make sure
there are only digits and no other type of characters. I thought regex
would be great for this. The program works great, but no matter what I
enter, the regex part does the same thing. By same thing I mean this:

======== RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py
========
Please enter an integer less than 10,000 greater than 0:  4jkk33
No match
>>>
======== RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py
========
Please enter an integer less than 10,000 greater than 0:  4k33
No match
>>>
======== RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py
========
Please enter an integer less than 10,000 greater than 0:  4jjk4
No match
>>>
======== RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py
========
Please enter an integer less than 10,000 greater than 0:  4334
No match

So I don't know what I'm doing wrong. The cipher will still draw, but I
want to return an "error message" in this case print("No match"), but it
does it every time, even when there are only digits; that's not what I
want. Please help. Below is my code:

from turtle import *
import re

# use turtle to draw ciphers of the Cistercian monks

digits = input("Please enter an integer less than 10,000 greater than 0:  ")

""" ensure input is no other characters than digits
sudocode: if the input has anything other than digits
 return digits  """

#def digit_check(digits):
# I thought making it a function might h
p = re.compile(r'[^\D]')
m = p.match(digits)
if m:
    print("No match")
else:
    print(digits)
    digits = m

#digit_check(digits)

mode("logo")   # resets turtle heading to north
speed(0)
ht()
fd(100)

# if statements for the ones position
if digits[-1] == "1":
    pu()
    goto(0, 100)
    seth(90)
    pd()
    fd(35)

if digits[-1] == "2":
    pu()
    goto(0, 65)
    seth(90)
    pd()
    fd(35)

if digits[-1] == "3":
    pu()
    goto(0, 100)
    seth(135)
    pd()
    fd(50)

if digits[-1] == "4":
    pu()
    goto(0, 65)
    seth(45)
    pd()
    fd(50)

if digits[-1] == "5":
    pu()
    goto(0, 100)
    seth(90)
    pd()
    fd(35)
    rt(135)
    fd(50)

if digits[-1] == "6":
    pu()
    goto(30, 100)
    seth(180)
    pd()
    fd(35)

if digits[-1] == "7":
    pu()
    goto(0, 100)
    seth(90)
    pd()
    fd(35)
    rt(90)
    fd(35)

if digits[-1] == "8":
    pu()
    goto(0, 65)
    seth(90)
    pd()
    fd(35)
    lt(90)
    fd(35)

if digits[-1] == "9":
    pu()
    goto(0, 100)
    seth(90)
    pd()
    fd(35)
    rt(90)
    fd(35)
    rt(90)
    fd(35)

# if statements for the tens position
if digits[-2:-1] == "1":
    pu()
    goto(0, 100)
    seth(-90)
    pd()
    fd(35)

if digits[-2:-1] == "2":
    pu()
    goto(0, 65)
    seth(-90)
    pd()
    fd(35)

if digits[-2:-1] == "3":
    pu()
    goto(0, 100)
    seth(-135)
    pd()
    fd(50)

if digits[-2:-1] == "4":
    pu()
    goto(0, 65)
    seth(-45)
    pd()
    fd(50)

if digits[-2:-1] == "5":
    pu()
    goto(0, 100)
    seth(-90)
    pd()
    fd(35)
    lt(135)
    fd(50)

if digits[-2:-1] == "6":
    pu()
    goto(-30, 100)
    seth(180)
    pd()
    fd(35)

if digits[-2:-1] == "7":
    pu()
    goto(0, 100)
    seth(-90)
    pd()
    fd(35)
    lt(90)
    fd(35)

if digits[-2:-1] == "8":
    pu()
    goto(0, 65)
    seth(-90)
    pd()
    fd(35)
    rt(90)
    fd(35)

if digits[-2:-1] == "9":
    pu()
    goto(0, 100)
    seth(-90)
    pd()
    fd(35)
    lt(90)
    fd(35)
    lt(90)
    fd(35)

# if statments for the hundreds position
if digits[-3:-2] == "1":
    pu()
    goto(0, 0)
    seth(90)
    pd()
    fd(35)

if digits[-3:-2] == "2":
    pu()
    goto(0, 35)
    seth(90)
    pd()
    fd(35)

if digits[-3:-2] == "3":
    pu()
    goto(0, 0)
    seth(45)
    pd()
    fd(50)

if digits[-3:-2] == "4":
    pu()
    goto(0, 35)
    seth(135)
    pd()
    fd(50)

if digits[-3:-2] == "5":
    pu()
    goto(0, 0)
    seth(90)
    pd()
    fd(35)
    lt(135)
    fd(50)

if digits[-3:-2] == "6":
    pu()
    goto(30, 0)
    seth(0)
    pd()
    fd(35)

if digits[-3:-2] == "7":
    pu()
    goto(0, 0)
    seth(90)
    pd()
    fd(35)
    lt(90)
    fd(35)

if digits[-3:-2] == "8":
    pu()
    goto(0, 35)
    seth(90)
    pd()
    fd(35)
    rt(90)
    fd(35)

if digits[-3:-2] == "9":
    pu()
    goto(0, 0)
    seth(90)
    pd()
    fd(35)
    lt(90)
    fd(35)
    lt(90)
    fd(35)

# if statments for the thousands position
if digits[-4:-3] == "1":
    pu()
    goto(0, 0)
    seth(-90)
    pd()
    fd(35)

if digits[-4:-3] == "2":
    pu()
    goto(0, 35)
    seth(-90)
    pd()
    fd(35)

if digits[-4:-3] == "3":
    pu()
    goto(0, 0)
    seth(-35)
    pd()
    fd(50)

if digits[-4:-3] == "4":
    pu()
    goto(0, 35)
    seth(-135)
    pd()
    fd(50)

if digits[-4:-3] == "5":
    pu()
    goto(0, 0)
    seth(-90)
    pd()
    fd(35)
    rt(135)
    fd(50)

if digits[-4:-3] == "6":
    pu()
    goto(-30, 0)
    seth(0)
    pd()
    fd(35)

if digits[-4:-3] == "7":
    pu()
    goto(0, 0)
    seth(-90)
    pd()
    fd(35)
    rt(90)
    fd(35)

if digits[-4:-3] == "8":
    pu()
    goto(0, 35)
    seth(-90)
    pd()
    fd(35)
    lt(90)
    fd(35)

if digits[-4:-3] == "9":
    pu()
    goto(0, 0)
    seth(-90)
    pd()
    fd(35)
    rt(90)
    fd(35)
    rt(90)
    fd(35)



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

From cs at cskk.id.au  Tue Feb 27 00:13:00 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Tue, 27 Feb 2018 16:13:00 +1100
Subject: [Tutor] Regex not working as desired
In-Reply-To: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
Message-ID: <20180227051300.GA2357@cskk.homeip.net>

On 26Feb2018 11:01, Roger Lea Scherer <rls4jc at gmail.com> wrote:
>  The first step is to input data and then I want to check to make sure
>there are only digits and no other type of characters. I thought regex
>would be great for this.

Many people do :-) They are a reasonable tool for an assortment of text 
matching tasks, but as you're discovering they can be easy to get wrong and 
hard to debug when you do. That's not to say you shouldn't use them, but many 
people use them for far too much.

>The program works great, but no matter what I
>enter, the regex part does the same thing. By same thing I mean this:
[...]
>Please enter an integer less than 10,000 greater than 0:  4jkk33
>No match
>Please enter an integer less than 10,000 greater than 0:  4k33
>No match
>Please enter an integer less than 10,000 greater than 0:  4jjk4
>No match
>Please enter an integer less than 10,000 greater than 0:  4334
>No match

So, "no match regardless of the input".

>So I don't know what I'm doing wrong. The cipher will still draw, but I
>want to return an "error message" in this case print("No match"), but it
>does it every time, even when there are only digits; that's not what I
>want. Please help. Below is my code:

Thank you for the code! Many people forget to include it. I'm going to trim for 
readability...

[...]
>digits = input("Please enter an integer less than 10,000 greater than 0:  ")
>
>""" ensure input is no other characters than digits
>sudocode: if the input has anything other than digits
> return digits  """
>
>#def digit_check(digits):
># I thought making it a function might h
>p = re.compile(r'[^\D]')

This seems a slightly obtuse way to match a digit. You're matching "not a 
nondigit". You could just use \d to match a digit, which is more readable.

This regular expression also matches a _single_ digit.

>m = p.match(digits)

Note that match() matches at the beginning of the string.

I notice that all your test strings start with a digit. That is why the regular 
expression always matches.

>if m:
>    print("No match")

This seems upside down, since your expression matches a digit.

Ah, I see what you've done.

The "^" marker has 2 purposes in regular expressions. At the start of a regular 
expression it requires the expression to match at the start of the string. At 
the start of a character range inside [] it means to invert the range. So:

  \d    A digit.
  \D    A nondigit.
  ^\D   A nondigit at the start of the string
  [^\D] "not a nondigit" ==> a digit

The other thing that you may have missed is that the \d, \D etc shortcuts for 
various common characters do not need to be inside [] markers.

So I suspect you wanted to at least start with "a nondigit at the start of the 
string". That would be:

  ^\D

with no [] characters.

Now your wider problem seems to be to make sure your string consists entirely 
of digits. Since your logic looks like a match for invalid input, your regexp 
might look like this:

  \D

and you could use .search instead of .match to find the nondigit anywhere in 
the string instead of just at the start.

Usually, however, it is better to write validation code which matches exactly 
what you actually want instead of trying to think of all the things that might 
be invalid. You want an "all digits" string, so you might write this:

  ^\d*$

which matches a string containing only digits from the beginning to the end.  
That's:

  ^     start of string
  \d    a digit
  *     zero or more of the digit
  $     end of string

Of course you really want at least one or more, so you would use "+" instead of 
"*".

So you code might look like:

  valid_regexp = re.compile(r'^\d+$')
  m = valid_regexp.match(digits)
  if m:
    # input is valid
  else:
    # input is invalid

Finally, you could also consider not using a regexp for this particular task.  
Python's "int" class can be called with a string, and will raise an exception 
if that string is not a valid integer. This also has the advantage that you get 
an int back, which is easy to test for your other constraints (less than 10000, 
greater than 0). Now, because int(0 raises an exception for bad input you need 
to phrase the test differently:

  try:
    value = int(digits)
  except ValueError:
    # invalid input, do something here
  else:
    if value >= 10000 or value <= 0:
      # value out of range, do something here
    else:
      # valid input, use it

Cheers,
Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)

From carroll at tjc.com  Mon Feb 26 20:16:59 2018
From: carroll at tjc.com (Terry Carroll)
Date: Mon, 26 Feb 2018 20:16:59 -0500 (EST)
Subject: [Tutor] Regex not working as desired
In-Reply-To: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
Message-ID: <alpine.NEB.2.21.1802262006350.18156@panix3.panix.com>

On Mon, 26 Feb 2018, Roger Lea Scherer wrote:

> """ ensure input is no other characters than digits
> sudocode: if the input has anything other than digits
> return digits  """
  ....
> p = re.compile(r'[^\D]')

I'm not so great at regular expressions, but this regex appears to be 
searching for a string that matches anything in the class start-of-string 
of non-digit.

  "[...]" says, look for anything in this set of characters; and you have 
two things:
  ^ : start-of-string
  \D : any non-digit

Instead of looking fo re xcaprions, I would look for what you *do* want. 
this regex should do it for you:

   r'^\d+$'

This is looking for a start-of-string ("^"); then a digit ("\d") that 
occurs at least once (the "+" qualifier); then an end-of string ("$").

In other words, one or more digits, with nothing else before or after.

Here's a simple looping test to get you started (ignore the "from 
__future__" line; I'm running Python 2):

from __future__ import print_function
import re
p = re.compile(r'^\d+$')
test_data = ["4jkk33", "4k33", "4jjk4", "4334", "4","44", "444", ""]
for thing in test_data:
     m = p.match(thing)
     if m is None:
         print("not all digits:", thing)
     else:
         print("all digits:", thing)


-- 
Terry Carroll
carroll at tjc.com


From carroll at tjc.com  Mon Feb 26 20:18:51 2018
From: carroll at tjc.com (Terry Carroll)
Date: Mon, 26 Feb 2018 20:18:51 -0500 (EST)
Subject: [Tutor] Regex not working as desired
In-Reply-To: <alpine.NEB.2.21.1802262006350.18156@panix3.panix.com>
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
 <alpine.NEB.2.21.1802262006350.18156@panix3.panix.com>
Message-ID: <alpine.NEB.2.21.1802262017470.18156@panix3.panix.com>

On Mon, 26 Feb 2018, Terry Carroll wrote:

> Instead of looking fo re xcaprions..

Wow. That should read "Instead of looking for exceptions..." Something 
really got away from me there.

-- 
Terry Carroll
carroll at tjc.com

From steve at pearwood.info  Tue Feb 27 03:44:41 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Tue, 27 Feb 2018 19:44:41 +1100
Subject: [Tutor] Regex not working as desired
In-Reply-To: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
Message-ID: <20180227084441.GP10142@ando.pearwood.info>

On Mon, Feb 26, 2018 at 11:01:49AM -0800, Roger Lea Scherer wrote:
>   The first step is to input data and then I want to check to make sure
> there are only digits and no other type of characters. I thought regex
> would be great for this.

I'm going to quote Jamie Zawinski:

    Some people, when confronted with a problem, think "I know, 
    I'll use regular expressions." Now they have two problems.


Welcome to the club of people who discovered that regexes are just as 
likely to make things worse as better :-(

Here's another, simpler way to check for all digits:

value = '12345'  # for example
value.isdigit()

The isdigit() method will return True if value contains nothing but 
digits (or the empty string), and False otherwise.


Sounds like just what you want, right? Nope. It *seems* good right up to 
the moment you enter a negative number:

py> '-123'.isdigit()
False

Or you want a number including a decimal point. Floating point numbers 
are *especially* tricky to test for, as you have to include:

# mantissa
optional + or - sign
zero or more digits
optional decimal point (but no more than one!)
zero or more digits
but at least one digit either before or after the decimal point;
# optional exponent
E or e
optional + or - sign
one or more digits


It is hard to write a regex to match floats.

Which brings us to a better tactic for ensuring that values are a valid 
int or float: try it and see!

Instead of using the Look Before You Leap tactic:

if string looks like an int:
    number = int(string)  # hope this works, if not, we're in trouble!
else:
    handle the invalid input


we can use the "Easier To Ask For Forgiveness Than Permission" tactic, 
and just *try* converting it, and deal with it if it fails:

try:
    number = int(string)
except ValueError:
    handle the invalid input

The same applies for floats, of course.

Now, one great benefit of this is that the interpreter already knows 
what makes a proper int (or float), and *you don't have to care*. Let 
the interpreter deal with it, and only if it fails do you have to deal 
with the invalid string.




By the way: absolute *none* of the turtle graphics code is the least bit 
relevant to your question, and we don't need to see it all. That's a bit 
like going to the supermarket to return a can of beans that you bought 
because they had gone off:

"Hi, I bought this can of beans yesterday, but when I got it home and 
opened it, they were all mouldy and green inside. Here's my receipt, 
and the can, and here's the can opener I used to open them, and the bowl 
I was going to put the beans into, and the microwave oven I would have 
used to heat them up, and the spoon for stirring them, and the toast I had 
made to put the beans on, and the salt and pepper shakers I use."

:-)



-- 
Steve

From alan.gauld at yahoo.co.uk  Tue Feb 27 03:45:05 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 27 Feb 2018 08:45:05 +0000
Subject: [Tutor] Regex not working as desired
In-Reply-To: <20180227051300.GA2357@cskk.homeip.net>
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
 <20180227051300.GA2357@cskk.homeip.net>
Message-ID: <p735me$ko4$1@blaine.gmane.org>

On 27/02/18 05:13, Cameron Simpson wrote:

> hard to debug when you do. That's not to say you shouldn't use them, but many 
> people use them for far too much.


> Finally, you could also consider not using a regexp for this particular task.  
> Python's "int" class can be called with a string, and will raise an exception 

And, as another alternative, you can use all() with a
generator expression:

>>> all(c.isdigit() for c in '1234')
True
>>> all(c.isdigit() for c in '12c4')
False
>>>

Or generally:

def all_digits(s):
    return all(c.isdigit() for c in s)

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



From __peter__ at web.de  Tue Feb 27 04:50:18 2018
From: __peter__ at web.de (Peter Otten)
Date: Tue, 27 Feb 2018 10:50:18 +0100
Subject: [Tutor] Regex not working as desired
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
 <20180227051300.GA2357@cskk.homeip.net> <p735me$ko4$1@blaine.gmane.org>
Message-ID: <p739gs$8n1$1@blaine.gmane.org>

Alan Gauld via Tutor wrote:

> On 27/02/18 05:13, Cameron Simpson wrote:
> 
>> hard to debug when you do. That's not to say you shouldn't use them, but
>> many people use them for far too much.
> 
> 
>> Finally, you could also consider not using a regexp for this particular
>> task. Python's "int" class can be called with a string, and will raise an
>> exception
> 
> And, as another alternative, you can use all() with a
> generator expression:
> 
>>>> all(c.isdigit() for c in '1234')
> True
>>>> all(c.isdigit() for c in '12c4')
> False
>>>>
> 
> Or generally:
> 
> def all_digits(s):
>     return all(c.isdigit() for c in s)
 
Note that isdigit() already checks all characters in the string:

>>> "123".isdigit()
True
>>> "1a1".isdigit()
False

The only difference to your suggestion is how it handles the empty string:

>>> def all_digits(s):
...     return all(c.isdigit() for c in s)
... 
>>> all_digits("")
True
>>> "".isdigit()
False

A potential problem of str.isdigit() -- and int() -- may be its unicode 
awareness:

>>> s = "\N{CHAM DIGIT ONE}\N{CHAM DIGIT TWO}\N{CHAM DIGIT THREE}"
>>> s
'???'
>>> s.isdigit()
True
>>> int(s)
123



From alan.gauld at yahoo.co.uk  Tue Feb 27 06:59:50 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 27 Feb 2018 11:59:50 +0000
Subject: [Tutor] Regex not working as desired
In-Reply-To: <p739gs$8n1$1@blaine.gmane.org>
References: <CAPvEsMw2dnr+cwpMRWuUgZxtLafyA=g0hVZu7Xw2N0rdn+syKA@mail.gmail.com>
 <20180227051300.GA2357@cskk.homeip.net> <p735me$ko4$1@blaine.gmane.org>
 <p739gs$8n1$1@blaine.gmane.org>
Message-ID: <p73h3j$svq$1@blaine.gmane.org>

On 27/02/18 09:50, Peter Otten wrote:
>> def all_digits(s):
>>     return all(c.isdigit() for c in s)
>  
> Note that isdigit() already checks all characters in the string:

Ah! I should have known that but forgot.
I think the singular name confused me.

> The only difference to your suggestion is how it handles the empty string:
> 
>>>> def all_digits(s):
> ...     return all(c.isdigit() for c in s)
> ... 
>>>> all_digits("")
> True
>>>> "".isdigit()
> False

Interesting, I'd have expected all() to return
False for an empty sequence... But looking at help(all)
it clearly states that it returns True. RTFM! :-(

However, in practice, and for this specific case, the
try/except route is probably best, I just wanted to
point out that there were other (concise) ways to
avoid a regex.


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