Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread Larry Hudson via Python-list
On 05/18/2016 06:50 PM, Jake Kobs wrote: MRAB, I am not quite sure how to return the print statements so I thought that returning the displayInfo def would help.. Im so lost. Why do you think you want to _return_ a print statement? The print statement _DOES_ the printing, there is nothing th

Re: Extract the middle N chars of a string

2016-05-18 Thread Wildman via Python-list
On Thu, 19 May 2016 01:47:33 +1000, Steven D'Aprano wrote: > Is this the simplest way to get the middle N characters? This will return a sub-string of any length starting at any point. This is the way the old VB mid$ function worked. def mid(string, start, length): # start begins at 0 i

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Rustom Mody
On Thursday, May 19, 2016 at 9:26:39 AM UTC+5:30, Steven D'Aprano wrote: > On Thursday 19 May 2016 13:31, Rustom Mody wrote: > > > On Thursday, May 19, 2016 at 6:26:26 AM UTC+5:30, Ben Finney wrote: > > >> Code Like A Pythonista was written in the Python 2 era > >>

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Steven D'Aprano
On Thursday 19 May 2016 13:31, Rustom Mody wrote: > On Thursday, May 19, 2016 at 6:26:26 AM UTC+5:30, Ben Finney wrote: >> Code Like A Pythonista was written in the Python 2 era >> >> but is still excellent advice today. > >

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Chris Angelico
On Thu, May 19, 2016 at 1:31 PM, Rustom Mody wrote: > On Thursday, May 19, 2016 at 6:26:26 AM UTC+5:30, Ben Finney wrote: >> Code Like A Pythonista was written in the Python 2 era >> >> but is still excellent advice today. > >

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Rustom Mody
On Thursday, May 19, 2016 at 6:26:26 AM UTC+5:30, Ben Finney wrote: > Jacob Scott writes: > > > Today, I'm happily writing primarily Python (unfortunately, 2.7 -- but I'm > > not sure it makes that much of a difference) > > Python 2.7 is still viable, but is certainly a dead end. The difference

Re: setrecursionlimit

2016-05-18 Thread Rustom Mody
On Thursday, May 19, 2016 at 3:13:44 AM UTC+5:30, bream wrote: > On Wednesday, May 18, 2016 at 6:47:42 PM UTC+1, Chris Kaynor wrote: > > On Wed, May 18, 2016 at 10:15 AM, Steven D'Aprano wrote: > > > > > I don't really understand why the system can't track the current top of > > > the > > > stack

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Chris Angelico
On Thu, May 19, 2016 at 11:15 AM, Jacob Scott wrote: > I think I would be (perhaps pleasantly) surprised if there was a wide gulf > between Python 2.7 and Python 3 *in terms of advice/resources applicable to > my original question*. Based on my (admittedly shallow) understanding of > overall Pytho

Re: Summing/combining tuples

2016-05-18 Thread Larry Hudson via Python-list
On 05/18/2016 05:59 PM, DFS wrote: Have aList = [ ('x','Name1', 1, 85), ('x','Name2', 3, 219), ('x','Name2', 1, 21), ('x','Name3', 6, 169) ] want aList = [ ('Name1', 1, 85), ('Name2', 4, 240), ('Name3', 6, 169) ] This drops the first element in each tuple: alist = [(b,c,d) for a,b,c,d in ali

Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread MRAB
On 2016-05-19 02:50, Jake Kobs wrote: MRAB, I am not quite sure how to return the print statements so I thought that returning the displayInfo def would help.. Im so lost. "return the print statements"? The print statements ... print! Have a search for Python tutorials online and pick one t

Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 11:50 am, Jake Kobs wrote: > MRAB, > > I am not quite sure how to return the print statements so I thought that > returning the displayInfo def would help.. Im so lost. There's no need to return the text that you printed. You printed it, the job is done. Here is some genera

Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread Jake Kobs
MRAB, I am not quite sure how to return the print statements so I thought that returning the displayInfo def would help.. Im so lost. -- https://mail.python.org/mailman/listinfo/python-list

Re: Extract the middle N chars of a string

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 02:54 am, Peter Otten wrote: > Peter Otten wrote: > > def mid(s, n): >> ... shave = len(s) - n >> ... if shave > 0: > shave += len(s) % 2 >> ... shave //= 2 >> ... s = s[shave:shave+n] >> ... return s > >> Not exactly the same res

Re: Extract the middle N chars of a string

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 03:00 am, MRAB wrote: > I think your results are inconsistent. > > For an odd number of characters you have "abc" + "de" + "fg", i.e. more > on the left, but for an even number of characters you have "a" + "bcd" + > "ef", i.e. more on the right. Correct. That's intentional.

Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread MRAB
On 2016-05-19 02:04, Jake Kobs wrote: Here is the code: #Lab 9-4 Blood Drive #the main function def main(): endProgram = 'no' while endProgram == 'no': print # declare variables pints = [0] * 7 totalPints = 0 averagePints = 0 highPints = 0 lowPints = 0

Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread John Gordon
In <1cc14787-7061-45c9-a70e-1b16e3f5e...@googlegroups.com> Jake Kobs writes: > Here is the code: > def getHigh(pints, highPints): > highPints = pints[0] > counter = 1 > while counter < 7: > if (pints[counter] > highPints): > highPints = pints[counter] >

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Jacob Scott
Ah, what I should have done is note that I am writing Python 2.7 (and this is at work, with all that entails...), but am happy to take advice that applies only to Python 3 (even 3.5 or 3.6.0a1!) and work backwards to apply it to Python 2.7. I think I would be (perhaps pleasantly) surprised if ther

Re: Extract the middle N chars of a string

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 07:28 am, Random832 wrote: > My take: > > def mid(string, n): > if n > len(string): n = len(string) > if n <= 0: n = 0 > offset = int(len(string)/2+n/2) > return string[offset:offset+n] > > It doesn't get the same result as yours when the length is odd and N i

Program prints questions for user input, but won't show the answer output

2016-05-18 Thread Jake Kobs
Here is the code: #Lab 9-4 Blood Drive #the main function def main(): endProgram = 'no' while endProgram == 'no': print # declare variables pints = [0] * 7 totalPints = 0 averagePints = 0 highPints = 0 lowPints = 0

Re: Quote of the day

2016-05-18 Thread Ethan Furman
On 05/18/2016 05:43 PM, Steven D'Aprano wrote: On Thu, 19 May 2016 09:30 am, Ethan Furman wrote: On 05/18/2016 03:52 PM, Gregory Ewing wrote: Ned Batchelder wrote: I'm not sure how the test runner could determine that it was empty. I guess it could introspect the test function to see if it

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Ben Finney
Jacob Scott writes: > Today, I'm happily writing primarily Python (unfortunately, 2.7 -- but I'm > not sure it makes that much of a difference) Python 2.7 is still viable, but is certainly a dead end. The difference increases month by month, and the advantage is only going to increase to Python

Re: Extract the middle N chars of a string

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 07:35 am, Grant Edwards wrote: > On 2016-05-18, Steven D'Aprano wrote: > >> Getting the middle N seems like it ought to be easy: > > I'm still trying to figure out when one would want to do that... I wanted to centre some text and truncate it to a fixed width. So I needed t

Re: Quote of the day

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 09:30 am, Ethan Furman wrote: > On 05/18/2016 03:52 PM, Gregory Ewing wrote: >> Ned Batchelder wrote: > >>> I'm not sure how >>> the test runner could determine that it was empty. I guess it could >>> introspect the test function to see if it had any real code in it, >> >> Th

Re: Basic Concepts

2016-05-18 Thread marcusjmurphy
On Wednesday, April 27, 2016 at 2:29:25 AM UTC-7, Smith wrote: > Fill in the blanks to declare a variable, add 5 to it and print its value: > > >>> x = 4 > >>> x_ = 5 > >>> print_ > > > Any suggestion ? > > Thanks >>> x = 4 >>> x += 5 >>> print(x) 9 -- https://mail.python.org/mailman/listi

Re: Quote of the day

2016-05-18 Thread Ethan Furman
On 05/18/2016 03:52 PM, Gregory Ewing wrote: Ned Batchelder wrote: I'm not sure how the test runner could determine that it was empty. I guess it could introspect the test function to see if it had any real code in it, Then people would just get clever at putting dummy code in the test that

Re: OT: limit number of connections from browser to my server?

2016-05-18 Thread Gregory Ewing
Grant Edwards wrote: Product spec explicitly states HTTPS only. I'm told that is not open for discussion. The customer is a large, somewhat bureaucratic German corporation, and they generally mean it when they say something is non-negotiable. They're probably being sensible. The way the Inter

Re: Quote of the day

2016-05-18 Thread Gregory Ewing
Ned Batchelder wrote: I'm not sure how the test runner could determine that it was empty. I guess it could introspect the test function to see if it had any real code in it, Then people would just get clever at putting dummy code in the test that fools the test runner but doesn't really test a

Re: Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Andrew Farrell
Hi Jacob, You are probably looking for the book Test-Driven Development with Python . You'll also want to look at py.test Cheers! Andrew Farrell On Wed, May 18, 2016 at 5:01 PM, Jacob Scott wrote: > Man

Re: Extract the middle N chars of a string

2016-05-18 Thread Grant Edwards
On 2016-05-18, Steven D'Aprano wrote: > Getting the middle N seems like it ought to be easy: I'm still trying to figure out when one would want to do that... -- Grant Edwards grant.b.edwardsYow! My CODE of ETHICS at is vacat

Re: Extract the middle N chars of a string

2016-05-18 Thread Random832
On Wed, May 18, 2016, at 11:47, Steven D'Aprano wrote: > So after spending a ridiculous amount of time on what seemed like it > ought > to be a trivial function, and an embarrassingly large number of > off-by-one > and off-by-I-don't-even errors, I eventually came up with this: > > def mid(string,

Resources/pointers for writing maintable, testable Python

2016-05-18 Thread Jacob Scott
Many years ago, when I was primarily writing Java, I found Misko Hevery's Guide: Writing Testable Code to be incredibly helpful in guiding the design and structure of my codebase, and as reference for checking if my code was

Re: OT: limit number of connections from browser to my server?

2016-05-18 Thread Grant Edwards
On 2016-05-16, Grant Edwards wrote: > Is there any way to limit the number of connections a browser uses to > download a web page? [Long-winded tail of woe...] > So now I'm going to set up a simple Python HTTP server to try some > other approaches: > > 1) Only allow the listening socket to ac

Re: setrecursionlimit

2016-05-18 Thread Christian Gollwitzer
Am 18.05.16 um 19:15 schrieb Steven D'Aprano: Not being a C programmer, I don't really understand this. The idea I have in mind is a model of program memory I learned[1] way back in the 80s. I don't know if it's still valid. Your application has a bunch of memory available, which broadly speakin

Re: setrecursionlimit

2016-05-18 Thread Chris Kaynor
On Wed, May 18, 2016 at 10:15 AM, Steven D'Aprano wrote: > I don't really understand why the system can't track the current top of the > stack and bottom of the heap, and if they're going to collide, halt the > process. That would still be kinda awful, in a sudden "your application > just died" k

Re: setrecursionlimit

2016-05-18 Thread Ian Kelly
On Wed, May 18, 2016 at 11:15 AM, Steven D'Aprano wrote: > I don't really understand why the system can't track the current top of the > stack and bottom of the heap, and if they're going to collide, halt the > process. That would still be kinda awful, in a sudden "your application > just died" ki

Re: setrecursionlimit

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 02:29 am, Rob Gaddi wrote: > Ned Batchelder wrote: >> Is there a way to know how large the C stack can grow, and how much it >> will grow for each Python function call? That sounds complicated to get >> right. >> >> --Ned. > > It's probably trivial to look at a number and say

Re: Extract the middle N chars of a string

2016-05-18 Thread MRAB
On 2016-05-18 16:47, Steven D'Aprano wrote: Extracting the first N or last N characters of a string is easy with slicing: s[:N] # first N s[-N:] # last N Getting the middle N seems like it ought to be easy: s[N//2:-N//2] but that is wrong. It's not even the right length! py> s = 'aardvark'

Re: setrecursionlimit

2016-05-18 Thread Chris Kaynor
On Wed, May 18, 2016 at 9:19 AM, Ned Batchelder wrote: > I believe the issue here is that Python recursion results in the C stack > growing. Each Python function call creates a number of C function calls, > which grows the C stack. The crash you see is the C stack overflowing. > > Is there a wa

Re: Extract the middle N chars of a string

2016-05-18 Thread Peter Otten
Peter Otten wrote: def mid(s, n): > ... shave = len(s) - n > ... if shave > 0: shave += len(s) % 2 > ... shave //= 2 > ... s = s[shave:shave+n] > ... return s > Not exactly the same results as your implementation though. The extra line should fix th

Re: Quote of the day

2016-05-18 Thread Steven D'Aprano
On Thu, 19 May 2016 02:05 am, Ethan Furman wrote: > On 05/18/2016 08:35 AM, Thomas Mlynarczyk wrote: >> On 18/05/16 17:21, Ned Batchelder wrote: > >>> Ideally, an empty test wouldn't be a success, but I'm not sure how >>> the test runner could determine that it was empty. I guess it could >>> in

Re: Extract the middle N chars of a string

2016-05-18 Thread Peter Otten
Steven D'Aprano wrote: > Extracting the first N or last N characters of a string is easy with > slicing: > > s[:N] # first N > s[-N:] # last N > > Getting the middle N seems like it ought to be easy: > > s[N//2:-N//2] > > but that is wrong. It's not even the right length! > > py> s = 'aardv

Re: Extract the middle N chars of a string

2016-05-18 Thread Ian Kelly
On Wed, May 18, 2016 at 9:47 AM, Steven D'Aprano wrote: > Extracting the first N or last N characters of a string is easy with > slicing: > > s[:N] # first N > s[-N:] # last N > > Getting the middle N seems like it ought to be easy: > > s[N//2:-N//2] > > but that is wrong. It's not even the righ

Re: setrecursionlimit

2016-05-18 Thread Rob Gaddi
Ned Batchelder wrote: > On Wednesday, May 18, 2016 at 12:11:25 PM UTC-4, Steven D'Aprano wrote: >> The documentation for setrecursion limit warns against setting the limit too >> high: >> >> [quote] >> The highest possible limit is platform-dependent. A user may need to >> set the lim

Re: setrecursionlimit

2016-05-18 Thread Ned Batchelder
On Wednesday, May 18, 2016 at 12:11:25 PM UTC-4, Steven D'Aprano wrote: > The documentation for setrecursion limit warns against setting the limit too > high: > > [quote] > The highest possible limit is platform-dependent. A user may need to > set the limit higher when they have a prog

setrecursionlimit

2016-05-18 Thread Steven D'Aprano
The documentation for setrecursion limit warns against setting the limit too high: [quote] The highest possible limit is platform-dependent. A user may need to set the limit higher when they have a program that requires deep recursion and a platform that supports a higher limit. Th

Re: Quote of the day

2016-05-18 Thread Ethan Furman
On 05/18/2016 08:35 AM, Thomas Mlynarczyk wrote: On 18/05/16 17:21, Ned Batchelder wrote: Ideally, an empty test wouldn't be a success, but I'm not sure how the test runner could determine that it was empty. I guess it could introspect the test function to see if it had any real code in it, b

Re: Quote of the day

2016-05-18 Thread Ned Batchelder
On Wednesday, May 18, 2016 at 11:36:03 AM UTC-4, Thomas Mlynarczyk wrote: > On 18/05/16 17:21, Ned Batchelder wrote: > > Ideally, an empty test wouldn't be a success, but I'm not sure how > > the test runner could determine that it was empty. I guess it could > > introspect the test function to se

Extract the middle N chars of a string

2016-05-18 Thread Steven D'Aprano
Extracting the first N or last N characters of a string is easy with slicing: s[:N] # first N s[-N:] # last N Getting the middle N seems like it ought to be easy: s[N//2:-N//2] but that is wrong. It's not even the right length! py> s = 'aardvark' py> s[5//2:-5//2] 'rdv' So after spending a

Re: Quote of the day

2016-05-18 Thread Thomas Mlynarczyk
On 18/05/16 17:21, Ned Batchelder wrote: > Ideally, an empty test wouldn't be a success, but I'm not sure how > the test runner could determine that it was empty. I guess it could > introspect the test function to see if it had any real code in it, > but I don't know of a test runner that does tha

Re: Quote of the day

2016-05-18 Thread Ned Batchelder
On Wednesday, May 18, 2016 at 8:06:11 AM UTC-4, Thomas Mlynarczyk wrote: > On 17/05/16 12:39, Cem Karan wrote: > > Just downloaded and used a library that came with unit tests, which all > > passed. > > [...] > > I discovered they had commented out the bodies of some of the unit > tests... > > Sh

Re: OT: limit number of connections from browser to my server?

2016-05-18 Thread Grant Edwards
On 2016-05-17, Dennis Lee Bieber wrote: > On Tue, 17 May 2016 18:42:12 + (UTC), Grant Edwards > declaimed the following: > > >>40MHz with multiple MB of RAM is pretty high-end in my book. I've > > How about a 68040 running at 30MHz (when not running in a dual system > with a 20MHz board

Re: Quote of the day

2016-05-18 Thread Chris Angelico
On Wed, May 18, 2016 at 10:05 PM, Thomas Mlynarczyk wrote: > On 17/05/16 12:39, Cem Karan wrote: >> Just downloaded and used a library that came with unit tests, which all >> passed. >> [...] >> I discovered they had commented out the bodies of some of the unit > tests... > > Shouldn't the unit t

Re: OrderedDict

2016-05-18 Thread Peter Otten
Chris Angelico wrote: > On Wed, May 18, 2016 at 7:28 PM, Peter Otten <__pete...@web.de> wrote: >> I don't see an official way to pass a custom dict type to the library, >> but if you are not afraid to change its source code the following patch >> will allow you to access the value of dictionaries

Re: Quote of the day

2016-05-18 Thread Thomas Mlynarczyk
On 17/05/16 12:39, Cem Karan wrote: > Just downloaded and used a library that came with unit tests, which all > passed. > [...] > I discovered they had commented out the bodies of some of the unit tests... Shouldn't the unit test framework have those "empty" tests reported as "todo"/"incomplete"

Re: OrderedDict

2016-05-18 Thread Chris Angelico
On Wed, May 18, 2016 at 7:28 PM, Peter Otten <__pete...@web.de> wrote: > I don't see an official way to pass a custom dict type to the library, > but if you are not afraid to change its source code the following patch > will allow you to access the value of dictionaries with a single entry as > d[

Re: OrderedDict

2016-05-18 Thread Peter Otten
silver0...@gmail.com wrote: > Hi all, > > I have a understanding problem with return values from xmltodict. > > I have a xml file. Content: > > > > > > > > > > With code > > __f_name = '' > with open(__f_name) as __fd: > __doc = xmltodict.parse(__fd.read()) > > __doc > >

Re: OrderedDict

2016-05-18 Thread Chris Angelico
On Wed, May 18, 2016 at 6:32 PM, wrote: > Hi all, > > I have a understanding problem with return values from xmltodict. > > I have a xml file. Content: > > > > > > > > > > > > > > > > > No prints __doc['profiles']['profile']['package'][0]['@package-id']: > > u'0964-gpg4

OrderedDict

2016-05-18 Thread silver0346
Hi all, I have a understanding problem with return values from xmltodict. I have a xml file. Content: With code __f_name = '' with open(__f_name) as __fd: __doc = xmltodict.parse(__fd.read()) __doc I get OrderedDict([(u'profiles', OrderedDict([(u'profile', OrderedDict([(