[Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Hello tutors I've constructed an example which shows a problem I'm having testing a real world program and would like to run it past you. tutor_question.py -- # -*- coding: utf-8 -*- import sys import threading import time class Time_Printer(threading.Thread)

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread spir
On 01/31/2014 12:31 PM, James Chapman wrote: try: while self.attribute: time.sleep(1) except KeyboardInterrupt: Maybe I'm missing apoint or reasoning wrongly, but I'd rather do: while self.attribute: try: time.sleep(1) except KeyboardInterrupt: ... or something lik

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 01:10:03PM +0100, spir wrote: > I don't know whether one can interrupt while sleeping py> from time import sleep py> sleep(60*60*24*365) # 1 year Traceback (most recent call last): File "", line 1, in KeyboardInterrupt Yes you can. -- Steven ___

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread eryksun
On Fri, Jan 31, 2014 at 6:31 AM, James Chapman wrote: > try: > while self.attribute: > time.sleep(1) > except KeyboardInterrupt: > ... > > My unit test could then set the attribute. However I'd still have the > problem of how I get from the unit test line that fires up the method t

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Hmm... Here is an example of how I'm currently trying to test it: test_tutor_question.py - # -*- coding: utf-8 -*- import unittest import mock from tutor_question import Infinite_Loop_Tutor_Question class Test_Infinite_Loop_Tutor_Question(unittest.TestCase): def

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 11:31:49AM +, James Chapman wrote: > Hello tutors > > I've constructed an example which shows a problem I'm having testing a real > world program and would like to run it past you. [...] > class Infinite_Loop_Tutor_Question(object): > def run_forever(self): >

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Thanks Steven! You've raised a few valid points, mostly that the run_forever method should be broken up. I like the principle of a method doing just one thing and for whatever reason I didn't apply that thinking to this method as it's the master loop (even though it does nothing). So for starters

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 02:03:13PM +, James Chapman wrote: > On the note of what doesn't need a test... > The question of coverage always comes up when unit testing is > mentioned and I read an interesting blog article once about it. It > basically said: Assume you have 85% coverage on a progr

[Tutor] run a python script from access form

2014-01-31 Thread Ahmed, Shakir
Hi, I am trying to run a python script from Microsoft Access form. Your help is highly appreciated. Thanks S We value your opinion. Please take a few minutes to share your comments on the service you received from the District by clicking on this link

Re: [Tutor] run a python script from access form

2014-01-31 Thread Joel Goldstick
Look up shell function On Jan 31, 2014 11:37 AM, "Ahmed, Shakir" wrote: > Hi, > > > > I am trying to run a python script from Microsoft Access form. Your help > is highly appreciated. > > > > Thanks > > S > > > We value your opinion. Please take a few minutes to share your comments on > the ser

Re: [Tutor] run a python script from access form

2014-01-31 Thread emile
On 01/31/2014 08:20 AM, Ahmed, Shakir wrote: Hi, I am trying to run a python script from Microsoft Access form. Your help is highly appreciated. I've not done this with Access, but I have created com servers in python that were used from Excel. I'd start with ActiveState's python distribu

[Tutor] interactive script

2014-01-31 Thread Gabriele Brambilla
Hi, I'm very new to Python (just 5 days!) is there a possibility to write an interactive script? in the sense that: - you run your script and it do some things that you don't want to type everytime you run the program - but at a certain step I want that it ask me question like "which column of thi

Re: [Tutor] interactive script

2014-01-31 Thread Gabriele Brambilla
to simplify the question: does a command like cin in C++ or scanf in C exist?? thanks Gabriele 2014-01-31 Gabriele Brambilla : > Hi, > I'm very new to Python (just 5 days!) > is there a possibility to write an interactive script? > in the sense that: > > - you run your script and it do some th

[Tutor] is an alias a variable

2014-01-31 Thread Ian D
Hi is import longModuleName as lmn or lmn = longModuleName creating an alias or assigning to a variable. or both? Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscripti

[Tutor] creating Turtle() object using 2 different ways

2014-01-31 Thread Ian D
Hi Another quickie. I can create turtle objects (if that's the correct terminology) using 2 different ways, both work. t1 = turtle.Turtle() or t2 = turtle But which is the best practice... and why? import turtle t1 = turtle.Turtle() t2 = turtle t1.fd(100) t2.goto(-100,100)

Re: [Tutor] interactive script

2014-01-31 Thread Mark Lawrence
On 31/01/2014 15:38, Gabriele Brambilla wrote: Please don't top post on this mailing list. to simplify the question: does a command like cin in C++ or scanf in C exist?? thanks Gabriele 2014-01-31 Gabriele Brambilla mailto:gb.gabrielebrambi...@gmail.com>>: Hi, I'm very new to Pytho

Re: [Tutor] interactive script

2014-01-31 Thread Alan Gauld
On 31/01/14 15:08, Gabriele Brambilla wrote: Hi, I'm very new to Python (just 5 days!) is there a possibility to write an interactive script? Yes, If using Python v3 use input() If using Python v2 use raw_input() (and definitely not input() ) You'll get a string back so may need to convert it

[Tutor] auto completion before initially running program

2014-01-31 Thread Ian D
I notice that until a program has been run once, and I presume loaded its imports, I cannot use auto completion. I don't suppose there is a way to have it load modules in a way that would give me access to the module functions straight away other than running the program I presume there is no

Re: [Tutor] auto completion before initially running program

2014-01-31 Thread emile
On 01/31/2014 01:13 AM, Ian D wrote: I notice that until a program has been run once, and I presume loaded its imports, I cannot use auto completion. I don't suppose there is a way to have it load modules in a way that would give me access to the module functions straight away other than runni

Re: [Tutor] run a python script from access form

2014-01-31 Thread Alan Gauld
On 31/01/14 16:20, Ahmed, Shakir wrote: Hi, I am trying to run a python script from Microsoft Access form. Your help is highly appreciated. If its just a command line tool then do it the same way you'd run a .bat file or another exe. If you want to interact with the script as it runs then yo

Re: [Tutor] is an alias a variable

2014-01-31 Thread emile
On 01/31/2014 01:57 AM, Ian D wrote: Hi is import longModuleName as lmn or lmn = longModuleName creating an alias or assigning to a variable. or both? Yes (I'm not goint to get into the symantic issues of what's an alias or variable) Python 2.7.3 (default, Nov 2 2012, 09:35:42) [GC

Re: [Tutor] is an alias a variable

2014-01-31 Thread Alan Gauld
On 31/01/14 09:57, Ian D wrote: import longModuleName as lmn or lmn = longModuleName creating an alias or assigning to a variable. or both? variables in Python are just names. There is no concept of an alias as such, its just another name referring to the same object. -- Alan G Author

Re: [Tutor] creating Turtle() object using 2 different ways

2014-01-31 Thread Alan Gauld
On 31/01/14 10:09, Ian D wrote: Hi Another quickie. I can create turtle objects (if that's the correct terminology) using 2 different ways, both work. t1 = turtle.Turtle() or t2 = turtle But which is the best practice... and why? import turtle t1 = turtle.Turtle() This creates an ins

Re: [Tutor] Code runs in interpreter but won't output to stdout

2014-01-31 Thread bob gailer
On 1/29/2014 8:59 PM, scurvy scott wrote: Please always reply to the tutor list so we can all play with your question. On 1/28/2014 9:12 PM, scurvy scott wrote: Hi guys, I'm trying to figure out why my code won't output to terminal, but will run just fine in interpreter. I'm using

Re: [Tutor] is an alias a variable

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 09:36:13PM +, Alan Gauld wrote: > On 31/01/14 09:57, Ian D wrote: > > >import longModuleName as lmn > > > >or > > > >lmn = longModuleName > > > >creating an alias or assigning to a variable. or both? > > variables in Python are just names. > There is no concept of