Re: [Tutor] text file help

2015-02-18 Thread Alan Gauld

On 18/02/15 07:50, Tihomir Zjajic wrote:

How  can I get this ; kl_number = 1202, kl_number = 1403, kl_number = 1802, 
kl_number = 2801, kl_number = 2502, kl_number = 2303, kl_number = 2254, 
kl_number = 1682, kl_number = 1403
kl_number = 1304, from text file(formular doznake) . I got this on this way ;


Your mail seems to assume that we will know what you are talking about.

I have no idea what doznake is. I don;t recognize your data sample.


def vrs_drv():
 vrs_drv = raw_input("Enter a vrs_drv:")


Its a really bad idea to name a variable the
same as the name of the function.


 if vrs_drv == "21":
 return("1")
 if vrs_drv == "22":
 return("2")
 if vrs_drv == "41":
 return("4")


I have no idea what these numbers are supposed to signify,
they appear to be quite arbitrary and bear no relation
to the numbers in your data above... Also what do you do
if the user enters a different number from 21,31,41?


number1 = vrs_drv()
print("kl_number1:",number1)


You show us your code. What does the output look like?


def prs_prec():
 prs_prec = raw_input("Enter a prs_prec:")


Again, don't use the same name as the function.


 if prs_prec == "20":
 return("20")
 if prs_prec == "40":
 return("40")
 if prs_prec == "80":
 return("80")


Since you just return the same string as the input
you could have saved a lot of coding.
What you expect to happen if the user enters
something other than 20,40 or 80?


number2 = prs_prec()
print("kl_number2:",number2)


Again, can we see the output?


def teh_kl():
 teh_kl = raw_input("Enter a teh_kl:")
 if teh_kl == "1":
 return("1")
 if teh_kl == "2":
 return("2")
 if teh_kl == ("3"):
 return("3")
 if teh_kl == ("4"):
 return("4")


Exactly the same comments as above.


number3 = teh_kl()
print("kl_number3:",number3)
print(number1+number2+number3)
print("\n\nPress the enter key to exit.")


OK, Now I see the relationship with the data sample.


formular doznake.txt

red_broj = 1
vrs_drv = 21
prs_prec = 20
teh_kl = 2
red_broj = 2
vrs_drv = 21
prs_prec = 40
teh_kl = 3


I assume red_broj indicates the start of a new record?
So you can read three lines from the file after you
find a red_broj entry?

Something like this? (untested)

kl_numbers = []
with open('doznake.txt') as doznake
for line in doznake:
   if line.startswith('red_broj')
  num = makeNumber(next(doznake),next(doznake),next(doznake))
  kl_numbers.append(num)

def makeNumber(l1,l2,l3):
nums = []
for line in (s1,s2,s3):
nums.append(line.rstrip().split()[-1])
return ''.join(nums)

That should result in you having a list of the kl_numbers
you asked for in your data sample. If I understood
your question properly.

--
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] monkey patching question

2015-02-18 Thread Albert-Jan Roskam


- Original Message -

> From: Dave Angel 
> To: tutor@python.org
> Cc: 
> Sent: Tuesday, February 17, 2015 11:50 PM
> Subject: Re: [Tutor] monkey patching question
> 
> On 02/17/2015 04:53 PM, Albert-Jan Roskam wrote:
>>  Hi,
>> 
>>  I would like to monkey patch a function 'decode' that is defined 
> inside a class. It is defined there because it is a logical place, next to 
> its 
> counterpart *method* 'encode'. I can successfully monkey patch meth1, 
> but when I call meth2, it does not use the patched decorator. How can this be 
> done? In this example, I would like to effectively "turn off" @decode. 
> I am hoping for a solution that works on Python 2.7 and 3.3+.
>> 
>> 
>>  import inspect, functools
>>  class Foo(object):
>> 
>>   def decode(func):
>>   @functools.wraps(func)
>>   def wrapped(*args, **kwargs):
>>   print "original decorator was called"
>>   return func(*args, **kwargs).decode("utf-8")
>>   return wrapped
>> 
>>   def encode(self):
>>   """this is just here to show why decode() is 
> defined
>>   within Foo"""
>>   pass
>> 
>>   def meth1(self):
>>   return "original method was called"
>> 
>>   @decode
>>   def meth2(self):
>>   return b"python rocks"
>> 
> 
> I assume the monkey patching happens in some other file which will 
> import this one.
> 
> So by the time the import is finished, the meth2() method has already 
> been decorated by the decode function.
> 
> 





Hi Dave, Danny, 


aha, now I see why it does not work. The code is patched, but it's too little, 
too late. 


>> 
>>  original decorator was called
>>  u'python rocks' 
> 
> 
> I think you're going to have to patch meth2().  Patching decode won't 
> help, since it's already done its work.


But in reality there is meth2 through methn, where n is at least a dozen. I 
considered monkey patching because it seemed easy to experiment with and the 
use case for which this would be needed was not very common. And it's fun to 
experiment with it of course. But I will have to refactor my decode decorator. 
Thanks!!

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


Re: [Tutor] OT: Preferred email client for sending plain text programming code snippets

2015-02-18 Thread Sydney Shall

On 18/02/2015 03:48, Mark Lawrence wrote:

On 17/02/2015 23:23, boB Stepp wrote:

Hopefully this is not a touchy subject like Emacs vs. Vim. ~(:>))

My home PC uses Win7-64bit. I currently use Chrome, Gmail and have a
Nexus 5 phone. The nice thing about all of this is that all of my
information usually seamlessly syncs. That is nice! But I am getting
increasingly frustrated with Gmail in terms of communicating with this
group (and sometimes others). It seems that if I am not constantly
attentive, my settings change from plain text to html, or, now, my New
Courier fixed-width font vanishes from the Gmail ecosystem and cannot
be found. I actually have come to prefer plain text communication as I
only rarely need html formatting. And I rarely care to see most of the
crap people send me that require html!

So are there any recommendations from this group that would make
things easy, would still be able to receive/send from my Gmail
account, etc.?



Thunderbird.  Access to 300+ Python mailing lists, blogs and the rest
all in one place via gmane.  Personally I've never had a single problem
with it.


Mark,
Could you give  us or point us towards some simple instructions as how 
one uses gmane.comp.python.tutor with Thunderbird. I had a go and I have 
found it daunting.

Thanks

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


Re: [Tutor] OT: Preferred email client for sending plain text programming code snippets

2015-02-18 Thread Alan Gauld

On 18/02/15 12:09, Sydney Shall wrote:


Could you give  us or point us towards some simple instructions as how
one uses gmane.comp.python.tutor with Thunderbird. I had a go and I have
found it daunting.


Create a new news account (File-New-OtherAccount)
Enter your details, click next
Enter the gmane news server address: news.gmane.org
Give it a friendly name
Finish

Thats it.

Now on that account page

Manage newsgroup subscriptions(wait for it to populate)
Use the show items box to filter - eg type comp.python
Select the ones you want.
Click subscribe

Done

Now on each newsgroup you can click on it and it will
download the latest messages(might take a while first
time round. You might want to limit the number to
say 50-100)



--
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] mySQL and Python

2015-02-18 Thread James Chapman
One of my pet hates about this list... "This is a tutor list, your question
is out of scope". Sure there might be better places to seek answers, and
sure maybe the first responder doesn't know the answer, but that's not a
reason to respond with that phrase. This list is a called python tutor, not
python beginner, even if the large majority of the questions are beginner
questions. The fact that people can ask any python related question is one
of the things I like about it and wish that other languages had similar
lists.

Back to answer the original question...

I recommend using the official MySQL connector because it's supported by
MySQL and it's continuously developed, which means it won't stop working
when you change Python versions, or MySQL versions, and it's documented.
I've tried some other MySQL libs in the past that worked OK but were a
nightmare when it came to supporting them due to changes in the environment.

Download the connector from
https://dev.mysql.com/downloads/connector/python/

The latest version should work just fine on Python 3.4

Documentation on how to use it is also available on the MySQL website:
https://dev.mysql.com/doc/connector-python/en/connector-python-examples.html

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


[Tutor] Python 3 simple socket issue

2015-02-18 Thread Juan C.
Code:

# !/usr/bin/env python3
# -*- coding: utf-8 -*-

import socket

def main():
target_host = 'www.google.com'
target_port = 80

client = socket.socket()
client.connect((target_host, target_port))
client.send(b"GET HTTP/1.1\r\nHost:google.com\r\n\r\n")

response = client.recv(4096)
print(response)


Output:

C:\Python34\python.exe D:/Documents/PyCharm/Test/__main__.py
b'HTTP/1.0 403 Forbidden\r\nContent-Length: 1180\r\nContent-Type:
text/html; charset=UTF-8\r\nDate: Wed, 18 Feb 2015 15:43:16 GMT\r\nServer:
GFE/2.0\r\nAlternate-Protocol: 80:quic,p=0.08\r\n\r\nSorry... body { font-family: verdana,
arial, sans-serif; background-color: #fff; color: #000;
}GoogleSorry...We\'re sorry.. but your computer or network may be
sending automated queries. To protect our users, we can\'t process your
request right now.See https://support.google.com/websearch/answer/86640";>Google Help for more
information.https://www.google.com";>Google
Home'

Process finished with exit code 0

Why a I getting 403? The code seems fine.

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


Re: [Tutor] mySQL and Python

2015-02-18 Thread boB Stepp
On Wed, Feb 18, 2015 at 9:24 AM, James Chapman  wrote:
> One of my pet hates about this list... "This is a tutor list, your question
> is out of scope". Sure there might be better places to seek answers, and
> sure maybe the first responder doesn't know the answer, but that's not a
> reason to respond with that phrase. This list is a called python tutor, not
> python beginner, even if the large majority of the questions are beginner
> questions. The fact that people can ask any python related question is one
> of the things I like about it and wish that other languages had similar
> lists.

I understand the need to warn a questioner that this list *might* not
be the best forum for their question; however, I fully enjoy these
types of posts as often even if I don't fully understand what is being
discussed, I still can cull valuable information. Also, sometimes
something *clicks* and I am able to solve an issue that has been
baffling me for a while. Plus it gives me thought to what to study in
the future...


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


Re: [Tutor] Python 3 simple socket issue

2015-02-18 Thread Zachary Ware
On Wed, Feb 18, 2015 at 9:48 AM, Juan C.  wrote:
> We\'re sorry.. but your computer or network may be
> sending automated queries. To protect our users, we can\'t process your
> request right now.See https://support.google.com/websearch/answer/86640";>Google Help for more
> information.https://www.google.com";>Google
> Home'
>
> Process finished with exit code 0
>
> Why a I getting 403? The code seems fine.

Read the response you got back, particularly the link they sent you:
https://support.google.com/websearch/answer/86640

The code is fine, the action is not in line with what Google will
allow you to do.

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


Re: [Tutor] Python 3 simple socket issue

2015-02-18 Thread Dave Angel

On 02/18/2015 10:48 AM, Juan C. wrote:

Code:

# !/usr/bin/env python3
# -*- coding: utf-8 -*-

import socket

def main():
target_host = 'www.google.com'
target_port = 80

client = socket.socket()
client.connect((target_host, target_port))
client.send(b"GET HTTP/1.1\r\nHost:google.com\r\n\r\n")

response = client.recv(4096)
print(response)



When I run that, I get:

davea@think2b:~/zzztemp$ python juan.py
  File "juan.py", line 8
target_host = 'www.google.com'
  ^
IndentationError: expected an indented block
davea@think2b:~/zzztemp$


So you might want to fix the indentation.  And add a call to main() at 
top level.


Once I do that, I get approximately the same thing you post below.



Output:

C:\Python34\python.exe D:/Documents/PyCharm/Test/__main__.py
b'HTTP/1.0 403 Forbidden\r\nContent-Length: 1180\r\nContent-Type:
text/html; charset=UTF-8\r\nDate: Wed, 18 Feb 2015 15:43:16 GMT\r\nServer:
GFE/2.0\r\nAlternate-Protocol: 80:quic,p=0.08\r\n\r\nSorry... body { font-family: verdana,
arial, sans-serif; background-color: #fff; color: #000;
}GoogleSorry...We\'re sorry.. but your computer or network may be
sending automated queries. To protect our users, we can\'t process your
request right now.See https://support.google.com/websearch/answer/86640";>Google Help for more
information.https://www.google.com";>Google
Home'

Process finished with exit code 0

Why a I getting 403? The code seems fine.



Could it be because google.com doesn't want automated queries?  That's 
what they say in the text there.


See:
   http://www.google.com/intl/en/policies/terms/




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


Re: [Tutor] Python 3 simple socket issue

2015-02-18 Thread Juan C.
The code is fine, the email should have ruined the indentation. Anyway,
indeed, I only saw the 403 error and didn't even read the rest as I thought
it was only HTML/CSS code, my bad.

Tried with other pages and everything is working, thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] unittest for: Raises an exception

2015-02-18 Thread Sydney Shall

I use a MAC OSX 10.9.5
Enthought Canopy Python 2.7.6

I am a learner.

I am now trying to learn unittests as is often emphasised on this list.
I think that I have understood the simple unit tests such as Equal, 
Greater etc.

But I am struggling with the syntax of a test for Raises an exception.

The function that I am tring to test is:
For some reason my indentation has not been correctly copied.
I am sure that it is correct becuase I have chacked it as well as the 
program. Also the 20 tests that are OK refer to all the other functions 
in the program.


def getSurplusLabourTime(self, ww, uvc):
self.ww = ww
 self.uvc = uvc
 try:
self.surplus_labour_time = self.ww - self.uvc
return self.surplus_labour_time
 except:
if self.surplus_labour_time <= 0.0:
raise ValueError("Surplus labour time cannot be" + \
" equal to or shorter than zero!")

My test code is the following:

def test_func_getSurplusLabourTime_Exc(self):

self.assertRaises(ValueError,self.cwp.getSurplusLabourTime(self.cwp.ww,self.cwp.uvc)) 


[This last line should indented, but it refuses to do so!]

The traceback is as follows:

==
ERROR: test_func_getSurplusLabourTime_Exc (__main__.Testcwp)
--
Traceback (most recent call last):
  File 
"/Users/sydney/My_Documents/Political_Economy/Capital_Simulation/Capital/Current 
version/TestCWP_WorkDuration.py", line 88, in 
test_func_getSurplusLabourTime_Exc
self.assertRaises(ValueError, 
self.cwp.getSurplusLabourTime(self.cwp.ww, self.cwp.uvc))
  File 
"/Applications/Canopy.app/appdata/canopy-1.5.1.2730.macosx-x86_64/Canopy.app/Contents/lib/python2.7/unittest/case.py", 
line 475, in assertRaises

callableObj(*args, **kwargs)
TypeError: 'float' object is not callable

--
Ran 21 tests in 0.005s

FAILED (errors=1)


I do know that I have not added the arguments that would sause an 
exception to be raised. But I have tried several forms and none have 
worked. I get the same traceback as above.



Any guidance would be appreciated.



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


Re: [Tutor] unittest for: Raises an exception

2015-02-18 Thread Raúl Cumplido
Hi,

When using self.assertRaises like this you should pass a callable (the
function you are going to call), but not call the function on the test. The
problem is when the function takes arguments. At this point you need to
create a callable with the two arguments. That can be done with functools
but it's not easy to follow (If you want me to explain more on this path I
can happily do it). For me the nicest syntax to test raising exceptions is
to use a context manager. As the following:

with self.assertRaises(ValueError):
self.cwp.getSurplusLabourTime(self.cwp.ww,self.cwp.uvc)

Kind Regards,
Raul

On Wed, Feb 18, 2015 at 6:15 PM, Sydney Shall 
wrote:

> I use a MAC OSX 10.9.5
> Enthought Canopy Python 2.7.6
>
> I am a learner.
>
> I am now trying to learn unittests as is often emphasised on this list.
> I think that I have understood the simple unit tests such as Equal,
> Greater etc.
> But I am struggling with the syntax of a test for Raises an exception.
>
> The function that I am tring to test is:
> For some reason my indentation has not been correctly copied.
> I am sure that it is correct becuase I have chacked it as well as the
> program. Also the 20 tests that are OK refer to all the other functions in
> the program.
>
> def getSurplusLabourTime(self, ww, uvc):
> self.ww = ww
>  self.uvc = uvc
>  try:
> self.surplus_labour_time = self.ww - self.uvc
> return self.surplus_labour_time
>  except:
> if self.surplus_labour_time <= 0.0:
> raise ValueError("Surplus labour time cannot be" + \
> " equal to or shorter than zero!")
>
> My test code is the following:
>
> def test_func_getSurplusLabourTime_Exc(self):
>
> self.assertRaises(ValueError,self.cwp.getSurplusLabourTime(self.cwp.ww,self.cwp.uvc))
>
> [This last line should indented, but it refuses to do so!]
>
> The traceback is as follows:
>
> ==
> ERROR: test_func_getSurplusLabourTime_Exc (__main__.Testcwp)
> --
> Traceback (most recent call last):
>   File 
> "/Users/sydney/My_Documents/Political_Economy/Capital_Simulation/Capital/Current
> version/TestCWP_WorkDuration.py", line 88, in test_func_
> getSurplusLabourTime_Exc
> self.assertRaises(ValueError, self.cwp.getSurplusLabourTime(self.cwp.ww,
> self.cwp.uvc))
>   File "/Applications/Canopy.app/appdata/canopy-1.5.1.2730.
> macosx-x86_64/Canopy.app/Contents/lib/python2.7/unittest/case.py", line
> 475, in assertRaises
> callableObj(*args, **kwargs)
> TypeError: 'float' object is not callable
>
> --
> Ran 21 tests in 0.005s
>
> FAILED (errors=1)
>
>
> I do know that I have not added the arguments that would sause an
> exception to be raised. But I have tried several forms and none have
> worked. I get the same traceback as above.
>
>
> Any guidance would be appreciated.
>
>
>
> --
> Sydney
> ___
> 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] mySQL and Python

2015-02-18 Thread Danny Yoo
On Wed, Feb 18, 2015 at 7:24 AM, James Chapman  wrote:
> One of my pet hates about this list... "This is a tutor list, your question
> is out of scope". Sure there might be better places to seek answers, and
> sure maybe the first responder doesn't know the answer, but that's not a
> reason to respond with that phrase. This list is a called python tutor, not
> python beginner, even if the large majority of the questions are beginner
> questions. The fact that people can ask any python related question is one
> of the things I like about it and wish that other languages had similar
> lists.


I'd like to apologize for the brusqueness in my last reply.  In no way
did I intend to be unfriendly.

I do want to make sure that we stay on mailing list topic.  Sometimes
I get zealous about this, but that's because if the traffic on the
list starts becoming very advanced, it can scare away the very folks
we're trying to help.  That's something that tends to happen when
experts talk to each other.


> I recommend using the official MySQL connector because it's supported by
> MySQL and it's continuously developed, which means it won't stop working
> when you change Python versions, or MySQL versions, and it's documented.
> I've tried some other MySQL libs in the past that worked OK but were a
> nightmare when it came to supporting them due to changes in the environment.

Ah, I missed this one.  Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Topic focus of ‘python-tutor’ (was: mySQL and Python)

2015-02-18 Thread Ben Finney
James Chapman  writes:

> One of my pet hates about this list... "This is a tutor list, your
> question is out of scope". Sure there might be better places to seek
> answers, and sure maybe the first responder doesn't know the answer,
> but that's not a reason to respond with that phrase.

You're right to address problematic tone, such as brusqueness. The
poster has apologised, so that's acknowledged.

That said, the point made is valid: This is not a general-purpose Python
discussion forum, so there are many potential threads that are off-topic
and should happen elsewhere.

> This list is a called python tutor, not python beginner, even if the
> large majority of the questions are beginner questions.

The focus of this forum *is* tutoring beginners. The name can't be the
sole guide to what's on or off topic, so please don't argue as though it
is. 

> The fact that people can ask any python related question is one of the
> things I like about it and wish that other languages had similar
> lists.

Then you have the wrong forum in mind. While we're not going to boot
people out merely for asking “any Python related question”, there are
many Python-related topics that are better not discussed here and it's
important that we regulars point that out.

If you want a more general Python discussion forum, we have one of those
too: it's called ‘python-list’, also available via Usenet at
‘comp.lang.python’. So it is evident that your needs are already met :-)

-- 
 \“[R]ightful liberty is unobstructed action, according to our |
  `\will, within limits drawn around us by the equal rights of |
_o__) others.” —Thomas Jefferson, 1819 |
Ben Finney

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


Re: [Tutor] unittest for: Raises an exception

2015-02-18 Thread Ben Finney
Sydney Shall  writes:

> My test code is the following:
>
> def test_func_getSurplusLabourTime_Exc(self):
>
> self.assertRaises(ValueError,self.cwp.getSurplusLabourTime(self.cwp.ww,self.cwp.uvc))
>  
>
> [This last line should indented, but it refuses to do so!]

What is “it” which refuses to indent your text? You might need to use a
better message composition tool.

If you're typing into a Web application, please see the discussion
happening in this forum about appropriate email clients for posting
program code.

So I'll reformat that code for readability::

def test_func_getSurplusLabourTime_Exc(self):
self.assertRaises(
ValueError,
self.cwp.getSurplusLabourTime(self.cwp.ww, self.cwp.uvc))

> The traceback is as follows:
>
> ==
> ERROR: test_func_getSurplusLabourTime_Exc (__main__.Testcwp)
> --
> Traceback (most recent call last):
[…]
> "/Applications/Canopy.app/appdata/canopy-1.5.1.2730.macosx-x86_64/Canopy.app/Contents/lib/python2.7/unittest/case.py",
>  line 475, in assertRaises
> callableObj(*args, **kwargs)
> TypeError: 'float' object is not callable

The error message is correct: the ‘assertRaises’ method expects a
callable object in the second parameter, but you've supplied an object
which is not callable (a float).

Have a closer look at the documentation for ‘TestCase.assertRaises’::

assertRaises(exception, callable, *args, **kwds)

Test that an exception is raised when callable is called with any
positional or keyword arguments that are also passed to assertRaises().


https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaises>

It's unfortunate the documentation doesn't give an example. But note
that clause “when `callable` is called with any […] arguments that *are
also passed to assertRaises*”.

So you don't call the function yourself; if you do, you get back its
return value (in your case, a float object) and *that's* your argument
to ‘assertRaises’ — not the function you're trying to test!

Instead of calling the function and getting its return value, you pass
*the function itself* to ‘assertRaises’, along with any arguments you
want *the test method* to call it with.

This indirection is a little confusing, and again I'm unhappy the
documentation doesn't show an example. Here's one::

def test_func_getSurplusLabourTime_Exc(self):
self.assertRaises(
ValueError,
self.cwp.getSurplusLabourTime,
self.cwp.ww, self.cwp.uvc)

What the documentation does show as an example, though, is a new-ish
feature that might suit you better.

You can now make your test code more comprehensible by instead using the
‘assertRaises’ method as a context manager, and then you just call your
function normally. Like this::

def test_func_getSurplusLabourTime_Exc(self):
with self.assertRaises(ValueError):
self.cwp.getSurplusLabourTime(self.cwp.ww, self.cwp.uvc)

Context managers are a very helpful feature that can make code more
elegant and readable. They might seem a little magic for now if you
haven't learned about them yet, but this is a good demonstration of
the improvement they can make.

-- 
 \   “… one of the main causes of the fall of the Roman Empire was |
  `\that, lacking zero, they had no way to indicate successful |
_o__)  termination of their C programs.” —Robert Firth |
Ben Finney

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


Re: [Tutor] mySQL and Python

2015-02-18 Thread Danny Yoo
>> I recommend using the official MySQL connector because it's supported by
>> MySQL and it's continuously developed, which means it won't stop working
>> when you change Python versions, or MySQL versions, and it's documented.
>> I've tried some other MySQL libs in the past that worked OK but were a
>> nightmare when it came to supporting them due to changes in the environment.
>
> Ah, I missed this one.  Thanks.


Hi Beatrice,

Following up on James's recommendation, it does look like MySQL
Connector should support the latest versions of Python, according to:

http://dev.mysql.com/doc/connector-python/en/connector-python-versions.html

where it says "Python 3.3 and later" are supported.  So try using the
2.0 version of the Connector.


Also, there appears to be a forum specific to MySQL Connector
questions hosted by the MySQL folks at:

http://forums.mysql.com/list.php?50

and they should be able to give specific help on that software too.


That being said, you're welcome to ask questions here!

My apologies again for sounding exclusive in my last email.  I was
trying to express the idea that Tutor might not be the best place to
ask MySQL driver installation questions.  I was trying to direct you
to folks that should be better equipped to answer your questions based
on their direct experience.  But thankfully, it does sound like we do
have a few MySQL-familiar folks on the list after all, so my concerns
aren't as valid as I had thought.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Suggestions on pyserial for RS232 com monitor?

2015-02-18 Thread dw
Hi Python Gang.
I have a project where I'm sending serial data to a Ten-Tec RX320 radio
receiver.
I'm using COM2 @1200 baud(standard N,8,1 parameters).
I have a need to verify the data that I'm sending to the device.
It occurred to me that python installed on a laptop might be a great
idea.
I can send the commands to the laptop instead of the radio and monitor
the commands.
Does anyone have any suggestions on a python script that would wait for
incoming data on a select com and display the data once sent?
I would probably install python 2.7 in the laptop for this project,
since the laptop has Ubuntu 12.04 OS.
Any suggestions, script, or point me in a direction would be greatly
appreciated.

Sincere thanks!
dw :-]
-- 
 bw...@fastmail.net

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


Re: [Tutor] Suggestions on pyserial for RS232 com monitor?

2015-02-18 Thread Raúl
I have never worked with serial ports on python, but have you taken a look on 
http://pyserial.sourceforge.net

Regards,
Raúl

> On 18 Feb 2015, at 16:18, dw  wrote:
> 
> Hi Python Gang.
> I have a project where I'm sending serial data to a Ten-Tec RX320 radio
> receiver.
> I'm using COM2 @1200 baud(standard N,8,1 parameters).
> I have a need to verify the data that I'm sending to the device.
> It occurred to me that python installed on a laptop might be a great
> idea.
> I can send the commands to the laptop instead of the radio and monitor
> the commands.
> Does anyone have any suggestions on a python script that would wait for
> incoming data on a select com and display the data once sent?
> I would probably install python 2.7 in the laptop for this project,
> since the laptop has Ubuntu 12.04 OS.
> Any suggestions, script, or point me in a direction would be greatly
> appreciated.
> 
> Sincere thanks!
> dw :-]
> -- 
> bw...@fastmail.net
> 
> ___
> 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] mySQL and Python

2015-02-18 Thread Alan Gauld

On 18/02/15 15:24, James Chapman wrote:

One of my pet hates about this list... "This is a tutor list, your question
is out of scope". Sure there might be better places to seek answers, and
sure maybe the first responder doesn't know the answer, but that's not a
reason to respond with that phrase.


The point of these responses is two fold:
1) It guides the poster to a more appropriate place to get the answers 
they need. This list is populated by a large number of beginners who 
probably can't answer specialised topics and a smaller number of more 
expert volunteers who are here to answer beginner type questions. It is 
pot luck whether within that community there exists anyone with the 
specialised skills needed for any given question. So asking on a 
specialised forum (or a general forum with more experts) makes sense.


2) Asking too many specialised or deeply technical questions scares
off the beginners and newbies that this list is designed to cater for.
If they can't understand the content of much of the mails then they 
assume they must be too stupid to participate or learn. We don't want 
that to happen.


After all the official description of the group says in the very
first line:

" This list is for folks who want to ask questions regarding how to 
learn computer programming with the Python language and its standard 
library."


It goes on:

" Folks interested in learning about programming with Python are 
encouraged to join, as are folks interested in helping others learn. 
While the list is called tutor, anyone, whether novice or expert, can 
answer questions."


We already have a general interest Python list, the reason for spinning 
off a separate tutor list some 18(?) years ago was specifically to 
remove some of the techno-fear that the main list generated for beginners.


But we very rarely flat out refuse to answer, we usually just say you'll 
likely get a better response elsewhere. Which is a simple

statement of the facts.

--
Alan G
List moderator

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


Re: [Tutor] Suggestions on pyserial for RS232 com monitor?

2015-02-18 Thread Ben Finney
dw  writes:

> I have a project where I'm sending serial data to a Ten-Tec RX320 radio
> receiver.

You will likely get a better response on our general Python discussion
forum https://www.python.org/community/lists/#comp-lang-python>.

This forum is focussed on tutoring newcomers in programming Python.

-- 
 \   “For fast acting relief, try slowing down.” —Jane Wagner, via |
  `\   Lily Tomlin |
_o__)  |
Ben Finney

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


Re: [Tutor] mySQL and Python

2015-02-18 Thread Beatrice Perez
Don't worry, thanks everyone for the reply. I realize that the question was
very general but I was looking for pointers which is exactly what you guys
have given me. Now I know what to read, where to start.

--Beatrice

On Wed, Feb 18, 2015 at 9:14 PM, Danny Yoo  wrote:

> >> I recommend using the official MySQL connector because it's supported by
> >> MySQL and it's continuously developed, which means it won't stop working
> >> when you change Python versions, or MySQL versions, and it's documented.
> >> I've tried some other MySQL libs in the past that worked OK but were a
> >> nightmare when it came to supporting them due to changes in the
> environment.
> >
> > Ah, I missed this one.  Thanks.
>
>
> Hi Beatrice,
>
> Following up on James's recommendation, it does look like MySQL
> Connector should support the latest versions of Python, according to:
>
>
> http://dev.mysql.com/doc/connector-python/en/connector-python-versions.html
>
> where it says "Python 3.3 and later" are supported.  So try using the
> 2.0 version of the Connector.
>
>
> Also, there appears to be a forum specific to MySQL Connector
> questions hosted by the MySQL folks at:
>
> http://forums.mysql.com/list.php?50
>
> and they should be able to give specific help on that software too.
>
>
> That being said, you're welcome to ask questions here!
>
> My apologies again for sounding exclusive in my last email.  I was
> trying to express the idea that Tutor might not be the best place to
> ask MySQL driver installation questions.  I was trying to direct you
> to folks that should be better equipped to answer your questions based
> on their direct experience.  But thankfully, it does sound like we do
> have a few MySQL-familiar folks on the list after all, so my concerns
> aren't as valid as I had thought.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mySQL and Python

2015-02-18 Thread Mark Lawrence

On 18/02/2015 23:43, Beatrice Perez wrote:

Don't worry, thanks everyone for the reply. I realize that the question was
very general but I was looking for pointers which is exactly what you guys
have given me. Now I know what to read, where to start.

--Beatrice

On Wed, Feb 18, 2015 at 9:14 PM, Danny Yoo  wrote:


I recommend using the official MySQL connector because it's supported by
MySQL and it's continuously developed, which means it won't stop working
when you change Python versions, or MySQL versions, and it's documented.
I've tried some other MySQL libs in the past that worked OK but were a
nightmare when it came to supporting them due to changes in the

environment.


Ah, I missed this one.  Thanks.



Hi Beatrice,

Following up on James's recommendation, it does look like MySQL
Connector should support the latest versions of Python, according to:


http://dev.mysql.com/doc/connector-python/en/connector-python-versions.html

where it says "Python 3.3 and later" are supported.  So try using the
2.0 version of the Connector.


Also, there appears to be a forum specific to MySQL Connector
questions hosted by the MySQL folks at:

 http://forums.mysql.com/list.php?50

and they should be able to give specific help on that software too.


That being said, you're welcome to ask questions here!

My apologies again for sounding exclusive in my last email.  I was
trying to express the idea that Tutor might not be the best place to
ask MySQL driver installation questions.  I was trying to direct you
to folks that should be better equipped to answer your questions based
on their direct experience.  But thankfully, it does sound like we do
have a few MySQL-familiar folks on the list after all, so my concerns
aren't as valid as I had thought.



My pet hate on this list is top posting as it makes following a thread 
so difficult.


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