[Tutor] Object references and garbage collection confusion

2015-05-05 Thread Brandon D
Hello tutors,

I'm having trouble understanding, as well as visualizing, how object
references work in the following situation.  For demonstration purposes I
will keep it at the most rudimentary level:

x = 10

x = x ** x

If my knowledge serves me correctly, Python destroys the value once
reassigned.  So, how does x = x +  1 work if it's destroyed before it can
be referenced?  The only solution I came up with is that the two operands
are evaluated before storing it in the variable, consequently replacing the
original value of 0.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 135, Issue 12

2015-05-05 Thread Siya 360
Hi,

Twice i unsubscribed to this mailing list, and i still continue to get them, 
why?

Please remove with immediate effect as this course has not served me well too 
many of my enquires went unanswered so i see no use for it, just flooding my 
mailbox

Kind Regards,
Siya

 
> On 05 May 2015, at 1:26 AM, tutor-requ...@python.org wrote:
> 
> Send Tutor mailing list submissions to
>   tutor@python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>   https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
> 
> You can reach the person managing the list at
>   tutor-ow...@python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: Sieve of Erastthotenes without sofisticated tools (Dave Angel)
>   2. Re: trouble with stringio function in python 3.2 (eryksun)
>   3. Jacob Kaplan-Moss's keynote at PyCon 2015 (Danny Yoo)
>   4. Integrating TDD into my current project work-flows (WolfRage)
>   5. Re: Integrating TDD into my current project work-flows
>  (Martin A. Brown)
>   6. Re: Python program malfunction (Jag Sherrington)
> 
> 
> --
> 
> Message: 1
> Date: Mon, 04 May 2015 06:00:24 -0400
> From: Dave Angel 
> To: tutor@python.org
> Subject: Re: [Tutor] Sieve of Erastthotenes without sofisticated tools
> Message-ID: <55474338.6050...@davea.name>
> Content-Type: text/plain; charset=windows-1252; format=flowed
> 
> On 05/04/2015 03:19 AM, yvan moses Levy wrote:
>> My code is wrong!
> 
> You'd find it a lot easier to get responses if you'd say in what way the 
> code is wrong.  If you get an exception, show the full traceback.  If 
> you get printed results, show what you expected, and what you got 
> instead.  If it hung, or crashed the OS, or ran out of memory, say so.
> 
>> I tried and tried
>> But I'm very isolated and It's hard without consultation with a tutor
>> from math import sqrt
>> def holeofStrainer():
>>   bigList = [False, False] + [True]*100
>>   print("line 4 - bigList : ", bigList)
>>   for num in range(2, 101):
>> print("line 6 - num : ", num)
>> for x in range(bigList[2], bigList[int(sqrt(num)) + 1]):
> 
> What did you expect this to do?  What is bigList[2] ?  What is 
> bigList[int(sqrt(num)) + 1] ?  Are these reasonable values to put into a 
> range() function?
> 
> 
> 
>>   print("line 8 x : %d"%x)
>>   if num % x == 0:
>> print("line 10 {0} divise par {1} = {2} ".format(num, x, num/x))
>> bigList[num] == False
>> print "bigList[{0} == {1}]".format(num, bigList[num])
>>   bigList[num] == True
>> 
>> for multiple in range (2, int(101/num) + 1):
>>   bigList[multiple] = False
>>   return(bigList)
>> print("the last result of bigList {} ".format(holeofStrainer()))
>> I WANT TO KNOW WHILE THE EXECUTION DO NOT GOING DOWNWARD
>> 
>> --
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>> 
>> 
> 
> 
> -- 
> DaveA
> 
> 
> --
> 
> Message: 2
> Date: Mon, 4 May 2015 09:58:05 -0500
> From: eryksun 
> To: Chris Warrick 
> Cc: tutor@python.org
> Subject: Re: [Tutor] trouble with stringio function in python 3.2
> Message-ID:
>   
> Content-Type: text/plain; charset=UTF-8
> 
> On Mon, May 4, 2015 at 2:46 AM, Chris Warrick  wrote:
>> Python 3.0?3.2 do not support the u'' notation for Unicode strings, it
>> was restored in Python 3.3 to make it easier to write code compatible
>> with 2.x and 3.x
> 
> Whoever restored this forgot about raw literals:
> 
 ur'abc'
>  File "", line 1
>ur'abc'
>  ^
>SyntaxError: invalid syntax
> 
> 
> --
> 
> Message: 3
> Date: Mon, 4 May 2015 10:03:31 -0700
> From: Danny Yoo 
> To: Python Tutor Mailing List 
> Subject: [Tutor] Jacob Kaplan-Moss's keynote at PyCon 2015
> Message-ID:
>   
> Content-Type: text/plain; charset=UTF-8
> 
> Apologies: this is somewhat off-topic, but I thought it might resonate
> with the audience here:
> 
>https://www.youtube.com/watch?v=hIJdFxYlEKE
> 
> It reminds me of Camille Fournier's talk back in 2014 at BangBangCon:
> 
>https://www.youtube.com/watch?v=sc8sc-ELMhA
> 
> Both express the experience of being a programmer, on the dangers of
> thinking of programming skill as some kind of bi-modal thing.  A key
> point in both their talks, I think, is that almost all of us aren't
> born natural programmers.  It's a skill.  We stumble, we learn, and we
> can get better at it.
> 
> 
> I hope that's an encouraging thought.
> 
> 
> --
> 
> Message: 4
> Date: Mon, 04 May 2015 15:04:31 -0400
> From: WolfRage 
> To: Python Tutor Mailing List 
> Subject: [T

Re: [Tutor] Object references and garbage collection confusion

2015-05-05 Thread Alan Gauld

On 05/05/15 05:29, Brandon D wrote:

Hello tutors,

I'm having trouble understanding, as well as visualizing, how object
references work in the following situation.  For demonstration purposes I
will keep it at the most rudimentary level:

x = 10
x = x ** x


Its good to use a simple example but in this case your
example bears no relation to your comments below!



If my knowledge serves me correctly, Python destroys the value once
reassigned.


Eventually.
Or more accurately Python marks the object for deletion
once all references to the object have been lost. Remember
variables in Python are not storage locations, they are
names attached to objects. When there are no more names
attached to an object it can be deleted. But that does
not necessarily happen immediately, Python gets around
to it when it has the time.


So, how does x = x +  1 work if it's destroyed before it can
be referenced?


Its not. This says assign x to the object on the right.
So it has to work out what "the object on the right" is
before it can stick the label x onto the result.


The only solution I came up with is that the two operands
are evaluated before storing it in the variable, consequently

> replacing the original value of 0.

Remember, its the name that moves, not the objects. Python
doesn't store the objects in the variables, it assigns
the variable names to the objects. There is a big difference.

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


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


Re: [Tutor] Tutor Digest, Vol 135, Issue 12

2015-05-05 Thread Alan Gauld

On 05/05/15 08:17, Siya 360 wrote:


Twice i unsubscribed to this mailing list, and i still continue to get them, 
why?


I don't know. Are you doing it via the web page?


Please remove with immediate effect


The web page is the only way to unsubscribe. Nobody else
on the list can unsubscribe you.


 as this course has not served me well too many of my enquires went unanswered


I only see 3 questions posted since the start of 2015, all were answered.

Although 2 of them appear to be Django specific and you were
advised to ask on the Django forum. This list is for questions
about the Python language.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Open a Url in new tab and tab switching in IE using python and selenium

2015-05-05 Thread shweta kaushik
Hi All,

I am trying to open a new tab in IE10 and selenium 2.45. It is able to open
a new tab using pyrobot. But when i am trying to open url in new tab, it is
getting opened in first tab. Focus is not set to second tab and hence it is
not working and also switching of tab is not working. please provide
solution. I have provided my code below:
Code:

# Open first tab
IEDriverPath = "/../../../../../../../IEDriverServer.exe"
driver = webdriver.Ie(IEDriverPath, port=)
pyseldriver.get("https://www.google.com/";)
time.sleep(5)
tab1 = pyseldriver.current_window_handle

#open another tab
obja = pyrobot.Robot()
obja.key_press(pyrobot.Keys.ctrl)
obja.key_press(pyrobot.Keys.t)
obja.key_release(pyrobot.Keys.ctrl)
obja.key_release(pyrobot.Keys.t)
time.sleep(FrameworkConstants.Time02)

pyseldriver.switch_to_window(pyseldriver.window_handles[-1])
tab2 = pyseldriver.current_window_handle
pyseldriver.get("https://www.python.org/";)
time.sleep(5)

#Switching to first tab and opening new url
pyseldriver.switch_to_window(tab1)
pyseldriver.get("https://www.yahoo.com/";)
time.sleep(10)

#switching to second tab and opening new url
pyseldriver.switch_to_window(tab2)
pyseldriver.get("https://www.gmail.com/";)
time.sleep(10)

But links are not opening in new tab and switching is also not happening.
All links are getting opened in first tab itself.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open a Url in new tab and tab switching in IE using python and selenium

2015-05-05 Thread Steven D'Aprano
On Tue, May 05, 2015 at 01:38:59PM +0530, shweta kaushik wrote:
> Hi All,
> 
> I am trying to open a new tab in IE10 and selenium 2.45.

This list is for beginners learning the Python language, and 
unfortunately selenium is a little too advanced for most of the people 
here. I myself have never used it.

You might be lucky, and someone has used it, but you will probably have 
more success on the main python list, python-l...@python.org, also 
available on Usenet as comp.lang.python and gmane.comp.python.general.

Your best chances of success are to find a dedicated selenium mailing 
list or forum, and ask there.

Good luck!


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


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread Oscar Benjamin
On 4 May 2015 at 20:04, WolfRage  wrote:
> I would like some help integrating TDD into my current projects.
> My chosen TDD framework is unittest from the standard library.
> My system details are: Linux Mint 17.1 64-bit, Python 3.4, bzr(for version
> control).
>
> My projects are structured like:
> Project > develop > Project > Project > __main__.py
>   tests   > __main__.py
> I want to be able to execute my Project from a cwd of:
> Project/develop/Project
> as: Python3 -m Project
> That currently works.

That will only work if there is also a file __init__.py under the
Project/develop/Project/Project directory (alongside the __main__.py
file). Adding a __main__.py file allows the directory to be treated as
a Python script e.g.:

$ python3 Project/develop/Project/Project
$ python3 Project  # Assuming cwd is Project/develop/Project

The -m switch searches for a script as if it were a module using the
module search path. In this case the directory containing the package
Project must be on sys.path and one way to achieve this is to change
directory to the Project/develop/Project directory. Then the Project
folder in this directory is on sys.path.

However a directory is not considered a package unless it contains a
file __init__.py. So if the directory is on sys.path (e.g. in the cwd)
AND their is an __init__.py file then you can do

$ python3 -m Project

and the code in __main__.py will run.

Assuming you have the same setup in the
Project/develop/Project/Project/tests directory (both __init__.py and
__main__.py and Project is on sys.path) then you can run
tests/__main__.py using the module search path as

$ python3 -m Project.tests

Note that this is the same name that you would use to import from the
tests package in interpreter e.g.

>>> from Project.tests import test_stuff

imports from the __init__.py in the tests folder.

> But executing my tests as: Python3 -m tests
> requires that test_Project.py has this hack to import the Project module:
> sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
> do you consider that OK? Is there a better way?
> I call it a hack because every testcase file will have to have this line
> added to it in order to work.

I'm not 100% sure I understand what you're doing but hopefully what
I've written above leads to a better solution.

> I am also using coverage.py and it is good but seems to be testing the
> coverage of my tests, which is not desired, how can I stop this behaviour.
> Or is it really OK.

I don't see any problem with it since it shows how many of your tests
are being run. If you're not running all of your tests then that's a
problem. I don't know how involved your projects are but often large
projects will have tests that run conditionally for example they
only/don't run on certain platforms. In that case it could be useful
each time you run your tests to get a loose idea of how many tests are
being skipped.

Of course it may just be a distraction from the main goal which is
ensuring good coverage of the exported code. You can control which
files coverage tracks and reports the coverage of. I don't know how to
do it the way that you're running coverage (from within Python code).
I've always run coverage from the command line interface using a
configuration file. See here for more on that:

http://nedbatchelder.com/code/coverage/cmd.html#cmd
http://nedbatchelder.com/code/coverage/config.html#config
http://nedbatchelder.com/code/coverage/source.html#source


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


Re: [Tutor] Object references and garbage collection confusion

2015-05-05 Thread Steven D'Aprano
On Tue, May 05, 2015 at 12:29:59AM -0400, Brandon D wrote:
> Hello tutors,
> 
> I'm having trouble understanding, as well as visualizing, how object
> references work in the following situation.  For demonstration purposes I
> will keep it at the most rudimentary level:
> 
> x = 10
> 
> x = x ** x


In the first case statement, Python creates the integer object 10, and 
binds it to the name 'x'. From this instant onwards, x will resolve as 
the int 10.

When the second line executes, Python first evaluates the right hand 
side 'x ** x'. To do this, it looks up the name 'x', which resolves to 
10. It then evaluates 10**10, which creates the int 100, and 
binds that to the name 'x'. From this instant, x now resolves as the new 
value 100.

Immediately afterwards, Python sees that the int 10 is no longer in use. 
(Well, in principle -- in practice, things are more complicated.) Since 
it is no longer in use, the garbage collector deletes the object, and 
reclaims the memory.

That, at least, is how it works in principle. In practice, Python may 
keep a cache of small integers, so that they never get deleted. That 
makes things a bit faster, at the cost of a tiny amount of extra memory. 
But this will depend on the version and implementation of Python. For 
example, some versions of Python cached integers 0 to 100, others -1 to 
255, very old versions might not cache any at all. As a Python 
programmer, you shouldn't care about this, it is purely an optimization 
to speed up the language.


> If my knowledge serves me correctly, Python destroys the value once
> reassigned.  So, how does x = x +  1 work if it's destroyed before it can
> be referenced?  The only solution I came up with is that the two operands
> are evaluated before storing it in the variable,

Correct. Let's say x = 10 again, just for simplicity.

Python first evaluates the right hand side: it looks up 'x', which 
resolves to 10. Then it generates the int 1, and adds them together, 
giving 11. Then it binds 11 to the name 'x', which frees up the 
reference to 10, and (in principle) 10 will be deleted.

The right hand side of the equals sign is always fully evaluated before 
any assignments are done. This is why we can swap two variables like 
this:

a = 1
b = 2
a, b = b, a

The third line evaluates b (giving 2) and a (giving 1), and Python then 
does the assignment:

a, b = 2, 1

which is equivalent to a=2, b=1, thus swapping the values.


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


Re: [Tutor] Object references and garbage collection confusion

2015-05-05 Thread Albert-Jan Roskam via Tutor

-
On Tue, May 5, 2015 8:00 PM CEST Steven D'Aprano wrote:

>On Tue, May 05, 2015 at 12:29:59AM -0400, Brandon D wrote:
>> Hello tutors,
>> 
>> I'm having trouble understanding, as well as visualizing, how object
>> references work in the following situation.  For demonstration purposes I
>> will keep it at the most rudimentary level:
>> 
>> x = 10
>> 
>> x = x ** x
>
>
>In the first case statement, Python creates the integer object 10, and 
>binds it to the name 'x'. From this instant onwards, x will resolve as 
>the int 10.
>
>When the second line executes, Python first evaluates the right hand 
>side 'x ** x'. To do this, it looks up the name 'x', which resolves to 
>10. It then evaluates 10**10, which creates the int 100, and 
>binds that to the name 'x'. From this instant, x now resolves as the new 
>value 100.
>
>Immediately afterwards, Python sees that the int 10 is no longer in use. 
>(Well, in principle -- in practice, things are more complicated.) Since 
>it is no longer in use, the garbage collector deletes the object, and 
>reclaims the memory.
>
>That, at least, is how it works in principle. In practice, Python may 
>keep a cache of small integers, so that they never get deleted. That 
>makes things a bit faster, at the cost of a tiny amount of extra memory. 
>But this will depend on the version and implementation of Python. For 
>example, some versions of Python cached integers 0 to 100, others -1 to 
>255, very old versions might not cache any at all. As a Python 
>programmer, you shouldn't care about this, it is purely an optimization 
>to speed up the language.
>
>
>> If my knowledge serves me correctly, Python destroys the value once
>> reassigned.  So, how does x = x +  1 work if it's destroyed before it can
>> be referenced?  The only solution I came up with is that the two operands
>> are evaluated before storing it in the variable,
>
>Correct. Let's say x = 10 again, just for simplicity.
>
>Python first evaluates the right hand side: it looks up 'x', which 
>resolves to 10. Then it generates the int 1, and adds them together, 
>giving 11. Then it binds 11 to the name 'x', which frees up the 
>reference to 10, and (in principle) 10 will be deleted.
>
>The right hand side of the equals sign is always fully evaluated before 
>any assignments are done. This is why we can swap two variables like 
>this:
>
>a = 1
>b = 2
>a, b = b, a
>
>The third line evaluates b (giving 2) and a (giving 1), and Python then 
>does the assignment:
>
>a, b = 2, 1
>
>which is equivalent to a=2, b=1, thus swapping the values.


It will probably only add confusion, but I thought it'd be nice to mention the 
weakref module: http://pymotw.com/2/weakref/ (the only thing I *might* ever use 
is WeakValueDictionary or WeakKeyDictionary)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Object references and garbage collection confusion

2015-05-05 Thread Dave Angel

On 05/05/2015 12:29 AM, Brandon D wrote:

Hello tutors,

I'm having trouble understanding, as well as visualizing, how object
references work in the following situation.  For demonstration purposes I
will keep it at the most rudimentary level:

x = 10

x = x ** x

If my knowledge serves me correctly, Python destroys the value once
reassigned.  So, how does x = x +  1 work if it's destroyed before it can
be referenced?  The only solution I came up with is that the two operands
are evaluated before storing it in the variable, consequently replacing the
original value of 0.


It's not destroyed before it's referenced.  The ten-object is destroyed 
(or may be, depending on optimizations and such) when nothing is bound 
to it.  That happens just after the new object is bound to x.


it may be interesting to put some simple statements into a function, and 
use dis.dis on that function.


import dis
def myfunc():
x = 10
x = x ** x

dis.dis(myfunc)



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


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread WolfRage

On 05/05/2015 10:59 AM, Oscar Benjamin wrote:


My projects are structured like:
Project > develop > Project > Project > __main__.py
   tests   > __main__.py
I want to be able to execute my Project from a cwd of:
Project/develop/Project
as: Python3 -m Project
That currently works.


That will only work if there is also a file __init__.py under the
Project/develop/Project/Project directory (alongside the __main__.py
file). Adding a __main__.py file allows the directory to be treated as
a Python script e.g.:

But actually there is no __init__.py in Project/develop/Project/Project/
There is only __main__.py and Project.py files. The __main__.py file 
imports Project.py.

$ python3 Project/develop/Project/Project
$ python3 Project  # Assuming cwd is Project/develop/Project

I tested the above on the terminal and it does not work. I get:
wolfrage@wolfrage-Lemur-UltraThin 
~/HomePlusWolfrage/Projects/Project/develop/Project $ python3 Project

Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
  File "Project/__main__.py", line 4, in 
from . import Project
SystemError: Parent module '' not loaded, cannot perform relative import


The -m switch searches for a script as if it were a module using the
module search path. In this case the directory containing the package
Project must be on sys.path and one way to achieve this is to change
directory to the Project/develop/Project directory. Then the Project
folder in this directory is on sys.path.

Did you perhaps mean the Project/develop/Project/Project/ directory?


However a directory is not considered a package unless it contains a
file __init__.py. So if the directory is on sys.path (e.g. in the cwd)
AND their is an __init__.py file then you can do

$ python3 -m Project

and the code in __main__.py will run.

Assuming you have the same setup in the
Project/develop/Project/Project/tests directory (both __init__.py and
__main__.py and Project is on sys.path) then you can run
tests/__main__.py using the module search path as

I think I may have confused you. The layout is like this:
Project/develop/Project/Project
Project/develop/Project/tests
Thus tests is not contained in module's directory.
My reasoning for this is that the tests would be shipped with my 
production code. I am currently undecided as to whether this is a good 
or bad thing. But the more that I read about testing the more it seems 
to be a good thing. So perhaps the best solution is to move the tests 
into the module's directory. Then the below information would probably work.


$ python3 -m Project.tests

Note that this is the same name that you would use to import from the
tests package in interpreter e.g.


from Project.tests import test_stuff


imports from the __init__.py in the tests folder.




Oscar



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


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread WolfRage

On 05/04/2015 04:49 PM, Martin A. Brown wrote:


Hi there,

Yes, a bit ugly.  Have you tried using nose?  I have used a similar
project development tree and use nose to run the tests.
I had thought about it, but decided not too, since it was not part of 
the standard library. But then again, it is not like I don't know how to 
install additional dependencies for my projects.

Here are a few sample command-lines (I'm on an opensuse-13.2 system with
Python 3.4 and nose for Python-3.4, which is called 'nosetests-3.4'):

   nosetests-3.4 -- ./tests/
   nosetests-3.4 --with-coverage -- ./tests/
   nosetests-3.4 --with-coverage --cover-package=Project -- ./tests/

I like nose because it will discover any unittest and doctest testing
code under the specified files/directories.
It looks pretty easy to use, does it have an API like coverage and 
unittest so that I can write my test scripts and simply execute them 
rather than running commands from the terminal? I find that scripts 
prevent errors as compared to typing commands on the terminal.





-Martin



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


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread WolfRage

Update: My previous hack, has been changed. I now put:

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

in the __main__.py file located under the tests/ directory and it is 
only needed the one time in that one file. Not sure why I was thinking I 
would need to do that for every test. But that now makes the tests 
standalone.


Also I understand the benefit of coverage showing the coverage for test 
files too, so this is not a problem.


As I am reading about TDD and unittests and the likes. I am thinking 
that testing from a "higher" level is better as compared to the "unit" 
level testing.
It seems to me that in order to get the benefits of testing I need to 
have less test code that will actually test more of my real code. I am 
seeing many potential names for this concept (Blackbox Automated 
Testing; System Level Test; API Level Tests) and would like your inputs 
on it.

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


[Tutor] key detection

2015-05-05 Thread Jim Mooney Py3.4.3winXP
Can python detect a keypress? I've looked all over and can't find it. I
don't mean input('blah') and have to press Enter - just detect it directly
like Javascript does. All I find are references using msvcrt, which is
Msoft specific, or using tkinter - but I don't want a whacking big GUI,
just keypress detection. Can I make a simple keyboard event loop without
tkinter?

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


Re: [Tutor] key detection

2015-05-05 Thread Alan Gauld

On 05/05/15 22:30, Jim Mooney Py3.4.3winXP wrote:

Can python detect a keypress?


That sounds simple but is actually quite tricky
since it's terminal dependent.


like Javascript does. All I find are references using msvcrt, which is
Msoft specific, or using tkinter - but I don't want a whacking big GUI,


You can also use curses on Unix like systems
which is CLI based. But it acts a bit like a GUI, you do need to 
initialize the framework ec.


It's described in the Event Driven Programming topic of my tutorial.

There are other  ways like using the low level C functions directly from 
the C libraries using ctypes, but that brings its own difficulties in 
converting Python data into C compatible types etc.


curses is the preferred option on Unix like systems.

There are some third party modules that try to address this in
a system independent manner, they can be found on PyPI but
I can't recommend any of them as I've not used them. I think
Fred Lundh created one such called, maybe, terminal?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread Alan Gauld

On 05/05/15 22:24, WolfRage wrote:


As I am reading about TDD and unittests and the likes. I am thinking
that testing from a "higher" level is better as compared to the "unit"
level testing.


Not better, just necessary. The two concepts are complementary.
You need both. The developer primarily needs unit testing, the 
integrator*(who may of course be the developer in a different

role) needs integration testing and the client/project manager
needs system testing and acceptance testing. They are all part
of a project (especially big/commercial projects)


It seems to me that in order to get the benefits of testing I need to
have less test code that will actually test more of my real code. I am
seeing many potential names for this concept (Blackbox Automated
Testing; System Level Test; API Level Tests) and would like your inputs
on it.


Don't underestimate the scale of testing. It is not unusual to
have more test code than functional code! (although it is still
the exception!) In real-world commercial projects testing (and
the associated debugging) typically consumes about 25-40% of
the total project budget. Baseline coding by contrast is only
about 10-25%, sometimes much less.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Open a Url in new tab and tab switching in IE using python and selenium

2015-05-05 Thread shweta kaushik
Thanks Steve for the information.
I searched but was not able to find suitable forum to shoot this question.
So posted here if anyone can help out.

Regards,
Shweta
On May 5, 2015 6:21 PM, "Steven D'Aprano"  wrote:

> On Tue, May 05, 2015 at 01:38:59PM +0530, shweta kaushik wrote:
> > Hi All,
> >
> > I am trying to open a new tab in IE10 and selenium 2.45.
>
> This list is for beginners learning the Python language, and
> unfortunately selenium is a little too advanced for most of the people
> here. I myself have never used it.
>
> You might be lucky, and someone has used it, but you will probably have
> more success on the main python list, python-l...@python.org, also
> available on Usenet as comp.lang.python and gmane.comp.python.general.
>
> Your best chances of success are to find a dedicated selenium mailing
> list or forum, and ask there.
>
> Good luck!
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open a Url in new tab and tab switching in IE using python and selenium

2015-05-05 Thread Alan Gauld

On 05/05/15 19:22, shweta kaushik wrote:

Thanks Steve for the information.
I searched but was not able to find suitable forum to shoot this question.
So posted here if anyone can help out.



As Steve suggested the main python list is probably your best bet.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread WolfRage

On 05/05/2015 06:49 PM, Alan Gauld wrote:


Not better, just necessary. The two concepts are complementary.
You need both. The developer primarily needs unit testing, the
integrator*(who may of course be the developer in a different
role) needs integration testing and the client/project manager
needs system testing and acceptance testing. They are all part
of a project (especially big/commercial projects)
So how low level of unit testing is acceptable. My use case is the sole 
programmer on a team project. Their is potential for another programmer 
to join the ranks but that has not happened yet. Additionally the 
project is well under way. But Feature additions have slowed so I want 
to make the code less buggy, and so I am hoping to re-factor my code 
now. I think some unit tests could improve the end result of my 
re-factoring, but where to start is the toughest problem for me to 
solve. Especially given the time trade off that is at least initially 
required for unit tests.




Don't underestimate the scale of testing. It is not unusual to
have more test code than functional code! (although it is still
the exception!) In real-world commercial projects testing (and
the associated debugging) typically consumes about 25-40% of
the total project budget. Baseline coding by contrast is only
about 10-25%, sometimes much less.
I agree I have seen this sort of budget numbers in the government 
project that I have been involved in. Especially once the project hits a 
more general life cycle/maintenance mode.


So how can I make unit testing apply to my project without starting from 
scratch? And how low should I test(ie. every function; every class; 
every interface; system level)?

Thank you for any insight and all of your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread WolfRage
I find myself in the same mind set as this individual: 
http://stackoverflow.com/a/64453/4285911
It is hard to write a proper test with out me initially outlining where 
I am going. Perhaps I need to better understand planning and drafting a 
programming project before I can hope to emulate TDD.


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


Re: [Tutor] key detection

2015-05-05 Thread Jim Mooney Py3.4.3winXP
On 5 May 2015 at 15:36, Alan Gauld  wrote:

> Can python detect a keypress?
>>
>
> That sounds simple but is actually quite tricky
> since it's terminal dependent.


An ancillary question. I found a readchar that purports to install in py2
and 3 but fails in 3. The errors (something from the encodings module)
won't copy from the console, so I thought I could redirect them like so:

python3 setup.py > errors.txt

But that didn't work. How can I get a printout of setup errors so I can
post them? That's something of general use aside from the keyboard loop.
Otherwise, I decided to just use msvcrt for now, which is quite simple, and
put in a try block for win or linux, when I dual boot linux, which I'm
working on. (solving the usual driver problems for a toshiba laptop)


-- 
Jim

"What a rotten, failed experiment. I'll start over. Maybe dogs instead of
monkeys this time." --God
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Integrating TDD into my current project work-flows

2015-05-05 Thread Mark Lawrence

On 06/05/2015 00:16, WolfRage wrote:

On 05/05/2015 06:49 PM, Alan Gauld wrote:


Not better, just necessary. The two concepts are complementary.
You need both. The developer primarily needs unit testing, the
integrator*(who may of course be the developer in a different
role) needs integration testing and the client/project manager
needs system testing and acceptance testing. They are all part
of a project (especially big/commercial projects)

So how low level of unit testing is acceptable. My use case is the sole
programmer on a team project. Their is potential for another programmer
to join the ranks but that has not happened yet. Additionally the
project is well under way. But Feature additions have slowed so I want
to make the code less buggy, and so I am hoping to re-factor my code
now. I think some unit tests could improve the end result of my
re-factoring, but where to start is the toughest problem for me to
solve. Especially given the time trade off that is at least initially
required for unit tests.



Don't underestimate the scale of testing. It is not unusual to
have more test code than functional code! (although it is still
the exception!) In real-world commercial projects testing (and
the associated debugging) typically consumes about 25-40% of
the total project budget. Baseline coding by contrast is only
about 10-25%, sometimes much less.

I agree I have seen this sort of budget numbers in the government
project that I have been involved in. Especially once the project hits a
more general life cycle/maintenance mode.


If and only if the project ever gets this far.  One third of major 
projects fail to deliver anything.  Part of the reason for that is 
growing bug lists owing to limited or even no (controlled) testing.




So how can I make unit testing apply to my project without starting from
scratch? And how low should I test(ie. every function; every class;
every interface; system level)?
Thank you for any insight and all of your help.



Ensure that every publicly available part of your code is tested.  Don't 
bother with internal helper functions or similar.  Remember that the 
toughest parts to test are often the error handling capabilities and the 
rarely occurring edge cases, so up front thought can save a huge amount 
of time, money and effort later on.


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


Re: [Tutor] key detection

2015-05-05 Thread Jim Mooney Py3.4.3winXP
On 5 May 2015 at 16:47, Jim Mooney Py3.4.3winXP 
wrote:

> But that didn't work. How can I get a printout of setup errors so I can
> post them?


I remembered how to copy the DOS console. Here is the error. Error wasn't
in setup.py so that wouldn't have worked anyway.

C:\Python34\Lib\site-packages\readchar-1.1.0>python3 setup.py
Traceback (most recent call last):
  File "setup.py", line 39, in 
long_description=read_description(),
  File "setup.py", line 11, in read_description
return fd.read()
  File "c:\python34\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position
2468: cha
racter maps to 


-- 
Jim

"What a rotten, failed experiment. I'll start over. Maybe dogs instead of
monkeys this time." --God
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] key detection

2015-05-05 Thread Steven D'Aprano
On Tue, May 05, 2015 at 02:30:41PM -0700, Jim Mooney Py3.4.3winXP wrote:
> Can python detect a keypress? I've looked all over and can't find it. I
> don't mean input('blah') and have to press Enter - just detect it directly
> like Javascript does. All I find are references using msvcrt, which is
> Msoft specific, or using tkinter - but I don't want a whacking big GUI,
> just keypress detection. Can I make a simple keyboard event loop without
> tkinter?

https://code.activestate.com/recipes/577977-get-single-keypress/


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


Re: [Tutor] key detection

2015-05-05 Thread Steven D'Aprano
On Tue, May 05, 2015 at 04:47:24PM -0700, Jim Mooney Py3.4.3winXP wrote:

> An ancillary question. I found a readchar that purports to install in py2
> and 3 but fails in 3. The errors (something from the encodings module)
> won't copy from the console, so I thought I could redirect them like so:
> 
> python3 setup.py > errors.txt

Is this under Linux or another Unix? If so, > only redirects stdout, not 
stderr, so you need:

python3 setup.py 2> errors.txt

to capture the errors.

I have no idea if Windows works the same way.



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


Re: [Tutor] Integrating TDD into my current project work-flows :p:

2015-05-05 Thread Thomas C. Hicks

On 05/06/2015 07:18 AM, WolfRage wrote:
I find myself in the same mind set as this individual: 
http://stackoverflow.com/a/64453/4285911
It is hard to write a proper test with out me initially outlining 
where I am going. Perhaps I need to better understand planning and 
drafting a programming project before I can hope to emulate TDD.


For what it is worth the idea of user stories really helped me develop 
an approach to testing (or should I say, start an approach to testing).  
The tutorial (here 
) 
covering Django development really drove that idea and its 
implementation home for me.  I believe the user story idea first shows 
up in chapter 2 of the book.


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


Re: [Tutor] key detection

2015-05-05 Thread Jim Mooney Py3.4.3winXP
On 5 May 2015 at 18:35, Steven D'Aprano  wrote:

> Is this under Linux or another Unix? If so, > only redirects stdout, not
> stderr, so you need:
>
> python3 setup.py 2> errors.txt
>
> to capture the errors.
>
> I have no idea if Windows works the same way.
>

Damn, that actually worked in windows instead of using their awful screen
copy. What a surprise:

errors.txt

Traceback (most recent call last):
  File "setup.py", line 39, in 
long_description=read_description(),
  File "setup.py", line 11, in read_description
return fd.read()
  File "c:\python34\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position
2468: character maps to 


-- 
Jim

"What a rotten, failed experiment. I'll start over. Maybe dogs instead of
monkeys this time." --God
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] key detection

2015-05-05 Thread Jim Mooney Py3.4.3winXP
On 5 May 2015 at 18:32, Steven D'Aprano  wrote:

> https://code.activestate.com/recipes/577977-get-single-keypress/


That only has a stub for Linux,  but I found one that does both. Although,
alas, no IOS version:

http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/

Anyway, I set up msvcrt for now until I install linux - I'm not interested
in the program I mentioned, per se, just the error message - mainly to
know, generally, what sort of thing it's choking on. Errors are useful to
know.

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


Re: [Tutor] key detection

2015-05-05 Thread Mark Lawrence

On 06/05/2015 05:30, Jim Mooney Py3.4.3winXP wrote:

On 5 May 2015 at 18:32, Steven D'Aprano  wrote:


https://code.activestate.com/recipes/577977-get-single-keypress/



That only has a stub for Linux,  but I found one that does both. Although,
alas, no IOS version:

http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/

Anyway, I set up msvcrt for now until I install linux - I'm not interested
in the program I mentioned, per se, just the error message - mainly to
know, generally, what sort of thing it's choking on. Errors are useful to
know.



I went a further step from the recipes linked to above and got here 
https://pypi.python.org/pypi/readchar


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


Re: [Tutor] key detection

2015-05-05 Thread Mark Lawrence

On 06/05/2015 00:47, Jim Mooney Py3.4.3winXP wrote:

On 5 May 2015 at 15:36, Alan Gauld  wrote:


Can python detect a keypress?




That sounds simple but is actually quite tricky
since it's terminal dependent.



An ancillary question. I found a readchar that purports to install in py2
and 3 but fails in 3. The errors (something from the encodings module)
won't copy from the console, so I thought I could redirect them like so:

python3 setup.py > errors.txt

But that didn't work. How can I get a printout of setup errors so I can
post them? That's something of general use aside from the keyboard loop.
Otherwise, I decided to just use msvcrt for now, which is quite simple, and
put in a try block for win or linux, when I dual boot linux, which I'm
working on. (solving the usual driver problems for a toshiba laptop)




You may find life far easier on Windows with http://conemu.github.io/

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


Re: [Tutor] key detection

2015-05-05 Thread Alex Kleider

On 2015-05-05 15:36, Alan Gauld wrote:

On 05/05/15 22:30, Jim Mooney Py3.4.3winXP wrote:

Can python detect a keypress?


The following works for my (on my Ubuntu platform) system
although probably won't be of much use on a Redmond OS.

#!/usr/bin/env python3
# file: 'readchar.py'
"""
Provides readchar()
Implementation of a way to get a single character of input
without waiting for the user to hit .
(OS is Linux, Ubuntu 14.04)
"""

import tty, sys, termios

class ReadChar():
def __enter__(self):
self.fd = sys.stdin.fileno()
self.old_settings = termios.tcgetattr(self.fd)
tty.setraw(sys.stdin.fileno())
return sys.stdin.read(1)
def __exit__(self, type, value, traceback):
termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)

def readchar():
with ReadChar() as rc:
return rc

def testrc():
print\
("Testing ReadChar: enter a character and we'll report what it is.")
while True:
char = readchar()
if ord(char) <= 32:
print("You entered character with ordinal {}, aka {}."
.format(ord(char), repr(char)))
else:
print("You entered character '{}'."
.format(char))
if char in "^C^D":
break

if __name__ == "__main__":
testrc()

To give credit where credit is due: I seem to remember cobbling this 
together
based on something that was discussed on this mailing list quite some 
time ago.

i.e. it's not original work:-)


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