Re: errorhandler 2.0.0 Released!

2016-06-06 Thread Pavel S
Hi,
can you explain, why is the attribute 'fired' class-level and not 
instance-level? There must be good reason for modifying class attribute from 
instance.


Dne pondělí 6. června 2016 15:26:08 UTC+2 Chris Withers napsal(a):
> Hi All,
> 
> errorhandler is a tiny but useful logging handler for the python logging 
> framework. It lets you tell when logging above a certain level has 
> occurred, even if it's not in code you can control.
> 
> I'm pleased to announce the release of errorhandler 2.0.0 featuring the 
> following:
> 
> - Support for Python 3
> 
> - Documentation on Read The Docs
> 
> - Continuous testing using Travis CI
> 
> - Code coverage reporting through Coveralls
> 
> The package is on PyPI and a full list of all the links to docs, issue 
> trackers and the like can be found here:
> 
> https://github.com/Simplistix/errorhandler
> 
> Any questions, please do ask on the Testing in Python list or on the 
> Simplistix open source mailing list...
> 
> cheers,
> 
> Chris
> 
> -- 
> Simplistix - Content Management, Batch Processing & Python Consulting
>  - http://www.simplistix.co.uk

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mod_python compilation error in VS 2008 for py2.7.1

2016-06-14 Thread Pavel S
Have you considered to use rather WSGI-based solution? (for Apache Httpd is 
mod_wsgi). Mod_python is totally obsolete.
-- 
https://mail.python.org/mailman/listinfo/python-list


__all__ attribute: bug and proposal

2016-06-27 Thread Pavel S
Hi,
I today uncovered subtle bug and would like to share it with you.

By a mistake, I forgot to put comma into '__all__' tuple of some module. Notice 
missing comma after 'B'.

# module foo.py
__all__ = (
'A',
'B'
'C',
)

class A: pass
class B: pass
class C: pass

If you try to import * from the module, it will raise an error, because 'B' and 
'C' will be concatenated into 'BC'.

>>> from foo import *
AttributeError: 'module' object has no attribute 'BC'

The bug won't be found until someone imports *.
In order to identify problems as soon as possible, here's the proposal.

Porposal: allow putting objects into __all__ directly, so possible problems 
will be found earlier:

# module foo.py
class A: pass
class B: pass
class C: pass

__all__ = (A, B, C)

Note: this currently don't work.

>>> from foo import *
TypeError: attribute name must be string, not 'type'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __all__ attribute: bug and proposal

2016-06-27 Thread Pavel S
> but what about integers or strings?

Can you provide example?

---
No matter if __all__ uses names or objects, I think it should be validated not 
only when importing '*', but always.

Frankly, do you always unit-test if __all__ works?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: C Python extension to export an Function

2016-09-01 Thread Pavel S
If you're familiar with C++, I recommend to have a look at Boost::Python. 

Sample program:

#include 

#include 

void world()
{
std::cout << "hello world" << std::endl;
}


BOOST_PYTHON_MODULE( hello )
{
using namespace ::boost::python;

def( "world", &world );
}

Usage:

python -c "import hello; hello.world()"

-- 
https://mail.python.org/mailman/listinfo/python-list


GOTCHA with list comprehension

2015-08-04 Thread Pavel S
Hi,

I recently found interesting GOTCHA while doing list comprehension in python 
2.6:

>>> values = ( True, False, 1, 2, 3, None )
>>> [ value for value in values if value if not None ]
[True, 1, 2, 3]

I was wondering why this list comprehension returns incorrect results and 
finally found a typo in the condition. The typo wasn't visible at the first 
look.

My intention was: if value is not None
But I wrote: if value if not None

Is that a language feature of list comprehension that it accepts conditions 
like: if A if B if C if D ...?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
It seems this is allowed by the grammar:

list_display::=  "[" [expression_list | list_comprehension] "]"
list_comprehension  ::=  expression list_for
list_for::=  "for" target_list "in" old_expression_list [list_iter]
old_expression_list ::=  old_expression [("," old_expression)+ [","]]
old_expression  ::=  or_test | old_lambda_expr
list_iter   ::=  list_for | list_if
list_if ::=  "if" old_expression [list_iter]

So chaining multiple ifs is fine:

[ i for i in range(10) if True if True if True if True ]

Dne středa 5. srpna 2015 8:49:20 UTC+2 Pavel S napsal(a):
> Hi,
> 
> I recently found interesting GOTCHA while doing list comprehension in python 
> 2.6:
> 
> >>> values = ( True, False, 1, 2, 3, None )
> >>> [ value for value in values if value if not None ]
> [True, 1, 2, 3]
> 
> I was wondering why this list comprehension returns incorrect results and 
> finally found a typo in the condition. The typo wasn't visible at the first 
> look.
> 
> My intention was: if value is not None
> But I wrote: if value if not None
> 
> Is that a language feature of list comprehension that it accepts conditions 
> like: if A if B if C if D ...?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.5 (Santiago)
$ python --version
Python 2.6.6

> Incidentally, why Python 2.6?
> 
> ChrisA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
Hi Chris, yeah, I have to stick on the software which my employer provides to 
me (we're enterprise company). I'm not root on that system. I'm happy with 2.6 
now, two years ago we were on older RHEL with python 2.4 and it was a real pain 
:)

> > $ cat /etc/redhat-release
> > Red Hat Enterprise Linux Server release 6.5 (Santiago)
> > $ python --version
> > Python 2.6.6
> >
> >> Incidentally, why Python 2.6?
> >>
> 
> I guess that would be why :)
> 
> That's probably actually a patched 2.6.6 - from what I understand of
> how Red Hat works, the version number is the number of the *oldest*
> part of the code, so that quite possibly has a lot of backported
> fixes. When I said 2.6 was out of support, I meant from python.org;
> Red Hat supports stuff for a lot longer.
> 
> So, yeah, perfectly good reason for sticking with 2.6. For now. :)
> 
> ChrisA

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Successfully send sms with python

2015-09-22 Thread Pavel S
On Tuesday, September 22, 2015 at 1:20:07 PM UTC+2, Timon Rhynix wrote:
> Hello, I have used pyserial, sms0.4 and other libraries to send sms via 
> huawei E1750 modem.
> The code runs well and no error is thrown but the text message is not 
> sent/delivered to the number.
> One of my code is as follows:
> 
> import serial
> import time
> 
> class TextMessage:
> def __init__(self, recipient="0123456789", message="TextMessage.content 
> not set."):
> self.recipient = recipient
> self.content = message
> 
> def setRecipient(self, number):
> self.recipient = number
> 
> def setContent(self, message):
> self.content = message
> 
> def connectPhone(self):
> conn = 'COM13'
> self.ser = serial.Serial(conn, 460800, timeout=5)
> time.sleep(1)
> 
> def sendMessage(self):
> self.ser.write('ATZ\r')
> time.sleep(1)
> self.ser.write('AT+CMGF=1\r')
> time.sleep(1)
> self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
> time.sleep(1)
> self.ser.write(self.content + "\r")
> time.sleep(1)
> self.ser.write(chr(26))
> time.sleep(1)
> print "message sent!"
> 
> def disconnectPhone(self):
> self.ser.close()
> 
> When run it, the "message sent!" is printed but no message is sent/delivered.
> Please assist on what I am missing. Thank you

Hi,

why don't you use http://wammu.eu/python-gammu/
?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Successfully send sms with python

2015-09-23 Thread Pavel S
I don't understand why all of you are telling him about '\r\n\, write(),..' 
instead of recommending to use take library which already has all problems 
resolved (python-gammu / wammu).

When one will write custom templating stuff, you would also recommend him to 
take jinja.
-- 
https://mail.python.org/mailman/listinfo/python-list