Re: manually build a unittest/doctest object.

2015-12-08 Thread Peter Otten
Vincent Davis wrote:

> If I have a string that is python code, for example
> mycode = "print('hello world')"
> myresult = "hello world"
> How can a "manually" build a unittest (doctest) and test I get myresult
> 
> I have attempted to build a doctest but that is not working.
> e = doctest.Example(source="print('hello world')/n", want="hello world\n")
> t = doctest.DocTestRunner()
> t.run(e)

There seems to be one intermediate step missing:

example --> doctest --> runner

>>> import doctest
>>> example = doctest.Example(
... "print('hello world')\n",
... want="hello world\n")
>>> test = doctest.DocTest([example], {}, None, None, None, None)
>>> runner = doctest.DocTestRunner(verbose=True)
>>> runner.run(test)
Trying:
print('hello world')
Expecting:
hello world
ok
TestResults(failed=0, attempted=1)

But why would you want to do that?

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


Re: Understanding Python from a PHP coder's perspective

2015-12-08 Thread Peter Otten
Chris Angelico wrote:

> On Tue, Dec 8, 2015 at 8:59 AM, Ian Kelly  wrote:
>> On Mon, Dec 7, 2015 at 2:40 PM, Chris Angelico  wrote:
>>> So that's a quick potted summary of why the URLs don't reflect the
>>> language used. Python is event-driven, but instead of defining events
>>> at the file level, the way PHP does, they're defined at the function
>>> level. Of course, if you *want* to put ".py" on the end of all your
>>> URLs, Python won't stop you... :)
>>
>> Or, if it's a poorly implemented site, ".rb". ;-)
> 
> Well hey. Python won't stop me from adding ".rb" to the ends of my
> URLs either...

Or ".php". Leaking the suffix is both ugly and excellent marketing -- a 
combination that is also common in the fashion industry.

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


Re: Understanding Python from a PHP coder's perspective

2015-12-08 Thread Chris Angelico
On Tue, Dec 8, 2015 at 8:24 PM, Peter Otten <[email protected]> wrote:
> Chris Angelico wrote:
>
>> On Tue, Dec 8, 2015 at 8:59 AM, Ian Kelly  wrote:
>>> On Mon, Dec 7, 2015 at 2:40 PM, Chris Angelico  wrote:
 So that's a quick potted summary of why the URLs don't reflect the
 language used. Python is event-driven, but instead of defining events
 at the file level, the way PHP does, they're defined at the function
 level. Of course, if you *want* to put ".py" on the end of all your
 URLs, Python won't stop you... :)
>>>
>>> Or, if it's a poorly implemented site, ".rb". ;-)
>>
>> Well hey. Python won't stop me from adding ".rb" to the ends of my
>> URLs either...
>
> Or ".php". Leaking the suffix is both ugly and excellent marketing -- a
> combination that is also common in the fashion industry.

Worst I've ever done there is create shim redirects. I refuse to have
my Python site advertise PHP.

https://github.com/Rosuav/Flask1/blob/master/1.py#L82

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


Re: writing an email.message.Message in UTF-8

2015-12-08 Thread Adam Funk
On 2015-12-08, dieter wrote:

> Adam Funk  writes:
>
>> I'm trying to write an instance of email.message.Message, whose body
>> contains unicode characters, to a UTF-8 file.  (Python 2.7.3 & 2.7.10
>> again.)
>>
>> reply = email.message.Message()
>> reply.set_charset('utf-8')
>> ... # set various headers
>> reply.set_payload('\n'.join(body_lines) + '\n')
>> ...
>> outfile = codecs.open(outfilename, 'w', encoding='utf-8', 
>> errors='ignore')
>> outfile.write(reply.as_string())
>> outfile.close()
>>
>> Then reply.as_string() barfs a UnicodeDecodeError.  I look in the
>> documentation, which says the generator is better.  So I replace the
>> outfile.write(...) line with the following:
>>
>> g = email.generator.Generator(outfile, mangle_from_=False)
>> g.flatten(reply)
>>
>> which still barfs a UnicodeDecodeError.  Looking closer at the first
>> error, I see that the exception was in g.flatten(...) already & thrown
>> up to reply.as_string().  How can I force the thing to do UTF-8
>> output?
>
> You could try replacing "reply.set_payload('\n'.join(body_lines) + '\n')"
> by "reply.set_payload(('\n'.join(body_lines) + '\n').encode('utf-8'))",
> i.e. you would not pass in a unicode payload but an "utf-8" encode
> "str" payload.

That didn't work (I got the same error) but switching to python 3.2
did.  Thanks, though.


-- 
A mathematical formula should never be "owned" by anybody! Mathematics
belonga to God.   --- Donald Knuth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: writing an email.message.Message in UTF-8

2015-12-08 Thread Adam Funk
On 2015-12-07, Terry Reedy wrote:

> On 12/7/2015 9:57 AM, Adam Funk wrote:
>> I'm trying to write an instance of email.message.Message, whose body
>> contains unicode characters, to a UTF-8 file.  (Python 2.7.3 & 2.7.10
>> again.)
>
> The email package was rewritten for, I believe, 3.3.  I believe it 
> should handle unicode email encoded as utf-8 more easily.

Actually it works in Python 3.2.3, & fortunately my program doesn't
depend on anything that isn't available for python 3 yet.  Thanks!


-- 
Most Americans are too civilized to hang skulls from baskets, having
been headhunters, of course, only as recently as Vietnam.
  --- Kinky Friedman
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: storing test logs under /var/log/

2015-12-08 Thread Ganesh Pal
> Finally. sys.exit accepts an integer, not a string.
>

Most of code  uses sys.exit("some error message")   ,  I did notice
that the error message is not displayed by sys .exit("some error
message") ,  do  u mean that using string is not advisable with
sys.exit ?
How to I display error messages with sys.exit then ?

PS:Thanks for all your previous comments ,  all were quite helpful .

Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: storing test logs under /var/log/

2015-12-08 Thread Peter Otten
Ganesh Pal wrote:

[Cameron Simpson:]

>> Finally. sys.exit accepts an integer, not a string.

> Most of code  uses sys.exit("some error message")   ,  I did notice
> that the error message is not displayed by sys .exit("some error
> message") ,  do  u mean that using string is not advisable with
> sys.exit ?

Cameron is wrong (he's probably coming from the C side of things). 
You can invoke sys.exit() with arbitrary objects:

"""
Help on built-in function exit in module sys:

exit(...)
exit([status])

Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is an integer, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
"""

> How to I display error messages with sys.exit then ?

Wrong question; if you want to use sys.exit() in a way similar to C display 
the error message first and invoke sys.exit() afterwards with a numerical 
argument.

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


Re: Accessing container's methods

2015-12-08 Thread Tony van der Hoff

On 07/12/15 23:47, Erik wrote:

Hi Tony,

On 07/12/15 18:10, Tony van der Hoff wrote:

A highly contrived example, where I'm setting up an outer class in a
Has-a relationship, containing a number of Actors. The inner class needs
to access a method of the outer class; here the method get_name.


Generally, an object should not need to know which container it's in
(let alone its "index" or "key" in that container). Amongst other
things, you can't put the object into multiple containers which might be
organised differently and you are asking for bugs where the container
and the object get out of sync WRT just where the object is in the
container (in your example, if you found you wanted to add a method
where the 'actors' list is modified (say, calling "self.actors.insert(3,
...)", or sorting the list) then things get nasty quickly.

However, you've said this is a highly contrived example, so I'll bear
with you and assume what you're trying to do is not quite as nasty as
the example implies ;)


Can anyone please advise me on how to achieve this magic?


As you can't sensibly put the object into more than one container at a
time anyway, then you can pass the container object to the Actor object
as its "parent". It can then call its parent object for things that the
parent will know (such as, the total number of contained objects):

class Actor:
def __init__ ( self, name, id, parent ):
  self.name = name
  self.id = id
  self.parent = parent

def get_name( self ):
  txt = "I'm Actor {} Number {} of {}".\
   format(  self.name, self.id, self.parent.count_actors() )
  return txt

Then you can add a new actor with:

   self.actors.append( Actor( n, i, self ) )


Note that you are creating circular references here, too (the container
references the Actor object and the Actor object references the
container). Just another possible issue to bear in mind ...


Also, while I'm looking at this, you have this loop and comment:

 >def __init__( self, names ):
 >  self.actors = []
 >
 >  i = 0
 >  for n in names:
 >self.actors.append( Actor( n, i ) )
 >i += 1# here is a case for python supporting post-increment!

However, if you refactor that loop to use iterators, you don't need to
manually manipulate 'i' at all (you need to import the itertools module
first, and this is the "new" version where the container is passed in as
the parent):

 def __init__( self, names ):
   self.actors = [ Actor ( n, i, self ) for n, i in
itertools.izip(names, itertools.count()) ]

Or, if you don't like list comprehensions:

 def __init__( self, names ):
   self.actors = []
   for n, i in itertools.izip(names, itertools.count()):
 self.actors.append( Actor( n, i, self ) )

(I assume you're using Python 3 because of your print statement - in
Python 3, 'itertools.izip' should just be 'zip'.)
HTH,
E.


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


ANN: eGenix pyOpenSSL Distribution 0.13.12

2015-12-08 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

   eGenix.com pyOpenSSL Distribution

Version 0.13.12

An easy-to-install and easy-to-use distribution
of the pyOpenSSL Python interface for OpenSSL -
   available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.12.html


INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

https://launchpad.net/pyopenssl/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/


NEWS

This new release of the eGenix.com pyOpenSSL Distribution includes the
following updates:

New in OpenSSL
--

 * Updated included OpenSSL libraries from OpenSSL 1.0.1p to
   1.0.1q. See https://www.openssl.org/news/secadv/20151203.txt ​for a
   complete list of changes. The following fixes are relevant for
   pyOpenSSL applications:

   - CVE-2015-3194 The signature verification routines will crash with
 a NULL pointer dereference, if presented with an ASN.1 signature
 using the RSA PSS algorithm and absent mask generation function
 parameter. This can be exploited in as DoS attack in applications
 which performs certificate verification.

   - CVE-2015-3195: When presented with a malformed X509_ATTRIBUTE
 structure OpenSSL will leak memory.

   - CVE-2015-3196: If PSK identity hints are received by a
 multi-threaded client, then the values are wrongly updated in the
 parent SSL_CTX structure. This can potentially lead to a double
 free of the identify hint data, leading to a segfault.

 * Updated the Mozilla CA root bundle to version 2015-10-27.

 * Added support to allow building wheels from source or prebuilt
   packages.

Please see the product changelog for the full set of changes.

http://www.egenix.com/products/python/pyOpenSSL/changelog.html


pyOpenSSL / OpenSSL Binaries Included
-

In addition to providing sources, we make binaries available that
include both pyOpenSSL and the necessary OpenSSL libraries for all
supported platforms: Windows, Linux, Mac OS X and FreeBSD, for x86 and
x64.

To simplify installation, we have uploaded a web installer to PyPI
which will automatically choose the right binary for your platform, so
a simple

pip install egenix-pyopenssl

will get you the package with OpenSSL libraries installed. Please see
our installation instructions for details:

http://www.egenix.com/products/python/pyOpenSSL/#Installation

We have also added .egg-file distribution versions of our eGenix.com
pyOpenSSL Distribution for Windows, Linux and Mac OS X to the
available download options. These make setups using e.g. zc.buildout
and other egg-file based installers a lot easier.


DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/pyOpenSSL/


UPGRADING

Before installing this version of pyOpenSSL, please make sure that
you uninstall any previously installed pyOpenSSL version. Otherwise,
you could end up not using the included OpenSSL libs.

___
SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.


MORE INFORMATION

For more information about the eGenix pyOpenSSL Distribution, licensing
and download instructions, please visit our web-site or write to
[email protected].

About eGenix (http://www.egenix.com/):

eGenix is a Python software project, consulting and product
company delivering expert services and professional quality
products for companies, Python users and developers. We specialize
in database driven applications, large scale software designs and
integration.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Dec 08 2015)
>>> Python Projects, Coaching and Consult

Python Script - Windows Task Scheduler - Logging

2015-12-08 Thread Raheel Rao
Hello there,I created a python script that connects to an ftp and downloads 
files to a specifed folder and logs each event in a log file. This script works 
perfectly fine as i want it to however when i put this in a task scheduler, the 
script runs and downloads the file just fine except that there is no log 
created. Any suggestions? I remember task scheduler have a bug where you have 
to put something in "start in". Have been searching froums but so far no luck. 
Thanks in advance!

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


Re[2]: Packages installing problem

2015-12-08 Thread lalith

Thank for reply..

some packages does not exist for windows.

Thanks,
Lalith.
-- Original Message --
From: "Laura Creighton" 
To: "lalith" 
Cc: [email protected]; [email protected]
Sent: 12/7/2015 9:21:19 PM
Subject: Re: Packages installing problem


In a message of Mon, 07 Dec 2015 00:32:37 +, lalith writes:

Dear sir.

I was using Python2.7 and i move to Python3.5.
I face big trouble with installing software packages, i need in my
development.

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


Do you want to install your packages system-wide?

Try py -3.5 -m install 

Do you want to install your python packages in a virtual environment?

Start reading here:
https://docs.python.org/3/library/venv.html

If you sometimes want a python 2.7 virtual env you cannot get it with
venv.  You will have to use the older virtualenv.
https://virtualenv.readthedocs.org/en/latest/

Laura


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


Re: Python Script - Windows Task Scheduler - Logging

2015-12-08 Thread Laura Creighton
In a message of Mon, 07 Dec 2015 23:53:10 +, Raheel Rao writes:
>Hello there,I created a python script that connects to an ftp and downloads 
>files to a specifed folder and logs each event in a log file. This script 
>works perfectly fine as i want it to however when i put this in a task 
>scheduler, the script runs and downloads the file just fine except that there 
>is no log created. Any suggestions? I remember task scheduler have a bug where 
>you have to put something in "start in". Have been searching froums but so far 
>no luck. Thanks in advance!
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list


Maybe related to this?
tackoverflow.com/questions/20196049/problems-running-python-script-by-windows-task-scheduler-that-does-pscp

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


Is Python a good choice for a data logger?

2015-12-08 Thread villascape
Let's say there are multiple data-loggers (PCs probably running Linux) behind 
various firewalls which communicate to other devices on their respective LAN 
via a proprietary protocol using UDP/IP to collect data.  On perhaps a sixty 
second periodic basis, the data-loggers will send the data to a server located 
outside of their firewalls (via TCP/IP and probably using HTTP).  The server 
(probably running Linux) will store the data monitored by the data-loggers.  
Web clients will then make HTTP requests to the server to retrieve the data.


Is Python a good choice for the following:

1) The data-loggers to pole data and/or receive data from the UDP devices and 
send the data to the server?

2) The daemon/application running on the server which receives the data from 
the data-loggers, and stores it in the database?


If Python is a good choice, please explain why.  Also, please provide a very 
high level strategy to implement (I am not asking for script, but just enough 
so I can initially focus on  learning those parts of Python).

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


Re: Accessing container's methods [solved]

2015-12-08 Thread Tony van der Hoff

Hum, sorry about the empty reply; just finger trouble!

Anyway I wasn't expecting such a great response; thanks to all.

On 07/12/15 23:47, Erik wrote:
[snip]


As you can't sensibly put the object into more than one container at a
time anyway, then you can pass the container object to the Actor object
as its "parent". It can then call its parent object for things that the
parent will know (such as, the total number of contained objects):

class Actor:
def __init__ ( self, name, id, parent ):
  self.name = name
  self.id = id
  self.parent = parent

def get_name( self ):
  txt = "I'm Actor {} Number {} of {}".\
   format(  self.name, self.id, self.parent.count_actors() )
  return txt

Then you can add a new actor with:

   self.actors.append( Actor( n, i, self ) )

Whilst I'm grateful for all the responses, this is the one that got me 
out of the hole I dug myself into.


In fact, this is precisely what I tried previously, and got:
TypeError: 'instancemethod' object has no attribute '__getitem__'

In my naivety, I concluded that this meant I couldn't use the 'self' 
pointer in this way. However, trying it with the Monty example, it 
worked fine, and I have now tracked down my error elsewhere.




Note that you are creating circular references here, too (the container
references the Actor object and the Actor object references the
container). Just another possible issue to bear in mind ...

Yes, I guess it's quite nasty, but, in the non-trivial case, I'm only 
calling for dynamic data from the parent, and not modifying it in any 
way, so I think I can get away with it. Otherwise, I'd have to pass a 
vast list of initialization data to the (many) children, and keep that 
up to date by passing it down the line to each one, just in case it's 
required, which would slow down things excessively. I know that if a 
design doesn't feel comfortable, then it's probably wrong, but I believe 
that in this case it's probably the best way forward.




Also, while I'm looking at this, you have this loop and comment:

 >def __init__( self, names ):
 >  self.actors = []
 >
 >  i = 0
 >  for n in names:
 >self.actors.append( Actor( n, i ) )
 >i += 1# here is a case for python supporting post-increment!

However, if you refactor that loop to use iterators, you don't need to
manually manipulate 'i' at all (you need to import the itertools module
first, and this is the "new" version where the container is passed in as
the parent):

 def __init__( self, names ):
   self.actors = [ Actor ( n, i, self ) for n, i in
itertools.izip(names, itertools.count()) ]

Or, if you don't like list comprehensions:

 def __init__( self, names ):
   self.actors = []
   for n, i in itertools.izip(names, itertools.count()):
 self.actors.append( Actor( n, i, self ) )


I rather liked Terry's suggestion of using enumerate.

The comment was tounge-in-cheek: Referring to an earlier thread, I'm yet 
to be convinced that Python is better for not having 
pre/post-increment/decrement operators. But, hey, I'm sure better minds 
than mine have addressed the subject ;)



(I assume you're using Python 3 because of your print statement - in
Python 3, 'itertools.izip' should just be 'zip'.)


No, Im actually stuck on Python 2.7. I don't see how you jumped to that 
conclusion from a simple print statement.


On 07/12/15 21:38, Terry Reedy wrote:
[snip]
> This is actually a case for using enumerate:
>for i, name in enumerate(names):
>
I've not come across this previously, but shall certainly use it in 
future. Thanks!


> return list(self.actors)  # or perhaps even faster
> return self.actors[:]

That doesn't seem to work:
<__main__.Actor instance at 0x7fc7478ba560>
<__main__.Actor instance at 0x7fc7478ba5a8>
<__main__.Actor instance at 0x7fc7478ba5f0>


Anyway, I'm no longer in a hole; thanks for all the excellent help. I'll 
certainly review the design of my current project, to see if it can be 
improved.


Cheers, Tony

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


Re: manually build a unittest/doctest object.

2015-12-08 Thread Vincent Davis
On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <[email protected]> wrote:

> But why would you want to do that?


Thanks Peter, I want to do that because I want to test jupyter notebooks.
​The notebook is in JSON and I can get the source and result out but it was
unclear to me how to stick this into a test. doctest seemed the simplest
but maybe there is a better way.

I also tried something like:
assert exec("""print('hello word')""") == 'hello word'


Vincent Davis
720-301-3003
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is Python a good choice for a data logger?

2015-12-08 Thread Chris Angelico
On Wed, Dec 9, 2015 at 12:30 AM,   wrote:
> Is Python a good choice for the following:
>
> 1) The data-loggers to pole data and/or receive data from the UDP devices and 
> send the data to the server?
>
> 2) The daemon/application running on the server which receives the data from 
> the data-loggers, and stores it in the database?
>
>
> If Python is a good choice, please explain why.
>

Yep! Both of these applications are going to spend virtually all their
time *waiting*. That means you don't have to stress about performance,
and can concentrate on writing code in the easiest and cleanest way
possible. To my mind, that says either Python or Pike; both languages
have excellent networking libraries, but in this case, Python
definitely takes the edge, because you already have broad familiarity
with it.

> Also, please provide a very high level strategy to implement (I am not asking 
> for script, but just enough so I can initially focus on  learning those parts 
> of Python).
>

Start with the socket module:

https://docs.python.org/3/library/socket.html

Get to know something of how TCP/IP works, if you don't already. Then
once you're ready to do your actual implementation, since you've
considered using HTTP, I would suggest looking into the third-party
'requests' library for the HTTP clients (you can do everything with
the standard library if you prefer, but you owe it to yourself to at
least have a quick _look_ at requests), and one of the standard web
frameworks for the server (personally, I use Flask, but any would do).
You'll probably want a database back end to store the actual content;
I strongly recommend PostgreSQL, which you can access from Python
using psycopg2. If you don't like hand-writing SQL, you could use
something like SQLAlchemy as middleware; otherwise, direct use of
psycopg2 works just fine.

Every part in this can be replaced without affecting the rest, but if
I were doing this kind of job, these would be the tools I'd first
reach for.

requests: http://requests.readthedocs.org/en/latest/
Flask: http://flask.pocoo.org/docs/
psycopg2: http://initd.org/psycopg/docs/
SQLAlchemy: http://www.sqlalchemy.org/

You asked for a "very high level" strategy. This is so high level it's
practically in LEO, but it's a start :)

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


Re: manually build a unittest/doctest object.

2015-12-08 Thread Chris Angelico
On Wed, Dec 9, 2015 at 1:04 AM, Vincent Davis  wrote:
> I also tried something like:
> assert exec("""print('hello word')""") == 'hello word'

I'm pretty sure exec() always returns None. If you want this to work,
you would need to capture sys.stdout into a string:

import io
import contextlib
output = io.StringIO()
with contextlib.redirect_stdout(output):
exec("""print("Hello, world!")""")
assert output.getvalue() == "Hello, world!\n" # don't forget the \n

You could wrap this up into a function, if you like. Then your example
would work (modulo the \n):

def capture_output(code):
"""Execute 'code' and return its stdout"""
output = io.StringIO()
with contextlib.redirect_stdout(output):
exec(code)
return output.getvalue()

assert capture_output("""print('hello word')""") == 'hello word\n'
# no error

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


Re: manually build a unittest/doctest object.

2015-12-08 Thread Laura Creighton
In a message of Tue, 08 Dec 2015 07:04:39 -0700, Vincent Davis writes:
>On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <[email protected]> wrote:
>
>> But why would you want to do that?
>
>
>Thanks Peter, I want to do that because I want to test jupyter notebooks.
>​The notebook is in JSON and I can get the source and result out but it was
>unclear to me how to stick this into a test. doctest seemed the simplest
>but maybe there is a better way.
>
>I also tried something like:
>assert exec("""print('hello word')""") == 'hello word'
>
>
>Vincent Davis
>720-301-3003
>-- 
>https://mail.python.org/mailman/listinfo/python-list

Check out this:
https://pypi.python.org/pypi/pytest-ipynb

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


Re: manually build a unittest/doctest object.

2015-12-08 Thread Vincent Davis
On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <[email protected]> wrote:

> >>> import doctest
> >>> example = doctest.Example(
> ... "print('hello world')\n",
> ... want="hello world\n")
> >>> test = doctest.DocTest([example], {}, None, None, None, None)
> >>> runner = doctest.DocTestRunner(verbose=True)
> >>> runner.run(test)
> Trying:
> print('hello world')
> Expecting:
> hello world
> ok
> TestResults(failed=0, attempted=1)
>

​and now how to do a multi line statement​.

>>> import doctest
>>> example =
doctest.Example("print('hello')\nprint('world')",want="hello\nworld")
>>> test = doctest.DocTest([example], {}, None, None, None, None)
>>> runner = doctest.DocTestRunner(verbose=True)
>>> runner.run(test)

Trying:
print('hello')
print('world')
Expecting:
hello
world
**
Line 1, in None
Failed example:
print('hello')
print('world')
Exception raised:
Traceback (most recent call last):
  File "/Users/vincentdavis/anaconda/envs/py35/lib/python3.5/doctest.py",
line 1320, in __run
compileflags, 1), test.globs)
  File "", line 1
print('hello')
 ^
SyntaxError: multiple statements found while compiling a single statement



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


Re: manually build a unittest/doctest object.

2015-12-08 Thread Vincent Davis
On Tue, Dec 8, 2015 at 7:30 AM, Laura Creighton  wrote:

> >--
> >https://mail.python.org/mailman/listinfo/python-list
>
> Check out this:
> https://pypi.python.org/pypi/pytest-ipynb
>

​Thanks Laura, I think I read the descript as saying I could run untittests
on source code from a jupyter notebook. Reading closer this seems like it
will work.
Not that I mind learning more about how doctests work ;-)


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


Re: Help on for loop understanding

2015-12-08 Thread Robert
On Monday, December 7, 2015 at 10:24:09 PM UTC-5, Chris Angelico wrote:
> On Tue, Dec 8, 2015 at 1:36 PM, Erik  wrote:
> > So, you can write your class's iterator to do anything that makes sense when
> > someone says "for i in myclassinstance:".
> >
> > If your class is a subclass of a class ("is-a") that already has a defined
> > iterator (such as a list or a dict) and the behaviour of that is correct for
> > you, then you need to do nothing (you inherit that class's __iter__()
> > method).
> >
> > If your class should iterate over an embedded object ("has-a") that already
> > has a defined iterator, then your __iter__() method can just delegate to
> > that object's iterator using something like:
> >
> > def __iter__(self):
> > return iter(self.embedded_thing)
> 
> Another great way to write an __iter__ method is as a generator.
> 
> def __iter__(self):
> yield "thing"
> yield from self.things
> yield "other thing"
> 
> Like returning an embedded object's iterator, this saves you having to
> write a __next__ method. The less work you do, the less bugs you get.
> 
> ChrisA

Thanks. One more question is here. I see the following code snippet. 
It can run as expected. That is, zeros array is iterable, but I don't see
the iterator of it. And I do see some codes using np.nditer, but the 
following without it.


seq = [ im for im in zeros((20,240,320), int)]

1. What difference for iterate with and without np.nditer?
2. How can I know one object whether it is iterable (only by testing?)

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


Problem

2015-12-08 Thread Namrah Anwar
Dear Administration,

I am Namrah Anwar writing to you from Pakistan. I downloaded Python version
3.5.1 and 2.7 and after installation at first, upon opening again it asked
for Modify, repair or uninstall options. I tried to fix it but could not.
Can you please help me out how to fix this and why it is asking every time
for same option?

Thanking you in anticipation.

-- 


*Regards,Namrah Anwar*
*PhD Student (Fellowship) - Cancer Biology - Agha Khan University-Karachi*
*Masters in Health care Biotechnology  (ASAB) NUST, Islamabad*
*Pakistan.*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2015-12-08 Thread Laura Creighton
In a message of Tue, 08 Dec 2015 20:03:27 +0500, Namrah Anwar writes:
>Dear Administration,
>
>I am Namrah Anwar writing to you from Pakistan. I downloaded Python version
>3.5.1 and 2.7 and after installation at first, upon opening again it asked
>for Modify, repair or uninstall options. I tried to fix it but could not.
>Can you please help me out how to fix this and why it is asking every time
>for same option?
>
>Thanking you in anticipation.
>
>-- 
>
>
>*Regards,Namrah Anwar*
>*PhD Student (Fellowship) - Cancer Biology - Agha Khan University-Karachi*
>*Masters in Health care Biotechnology  (ASAB) NUST, Islamabad*
>*Pakistan.*

What OS version are you running?

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


Can one use Python 3.4 lzma library to initialize file_reader for a 7z file?

2015-12-08 Thread Anmol Dalmia
Hello all.

I am trying to read lines from a compressed xml file in a 7z format contained 
archive. The native lzma library of Python 3.4 allows to do so, but I am not 
sure it does so for 7z files. I explored many threads and found very 
unsatisfactory answers such as this one.

https://groups.google.com/forum/#!search/lzma$207z/linux.debian.changes.devel/3vVvPIxnMuQ/3sPm5GEBbH4J

Can anyone please clear this out to me once? Or if it doesn't, can anyone help 
on how to do it using any python or wrapped C functions?

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


Re: Problem

2015-12-08 Thread Fabien

On 12/08/2015 04:03 PM, Namrah Anwar wrote:

Dear Administration,

I am Namrah Anwar writing to you from Pakistan. I downloaded Python version
3.5.1 and 2.7 and after installation at first, upon opening again it asked

(snip)

-- *Regards,Namrah Anwar* *PhD Student (Fellowship) - Cancer Biology -


I can see from your signature that you are going to use python for 
scientific purposes. I recommend to go directly for Anaconda:


https://www.continuum.io/downloads

Cheers,

Fabien

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


Re: Problem

2015-12-08 Thread Laura Creighton
In a message of Tue, 08 Dec 2015 16:11:53 +0100, Fabien writes:
>On 12/08/2015 04:03 PM, Namrah Anwar wrote:
>> Dear Administration,
>>
>> I am Namrah Anwar writing to you from Pakistan. I downloaded Python version
>> 3.5.1 and 2.7 and after installation at first, upon opening again it asked
>(snip)
>> -- *Regards,Namrah Anwar* *PhD Student (Fellowship) - Cancer Biology -
>
>I can see from your signature that you are going to use python for 
>scientific purposes. I recommend to go directly for Anaconda:
>
>https://www.continuum.io/downloads
>
>Cheers,
>
>Fabien

That is a very good idea.

Laura

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


Re: manually build a unittest/doctest object.

2015-12-08 Thread Peter Otten
Vincent Davis wrote:

> On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <[email protected]> wrote:
> 
>> >>> import doctest
>> >>> example = doctest.Example(
>> ... "print('hello world')\n",
>> ... want="hello world\n")
>> >>> test = doctest.DocTest([example], {}, None, None, None, None)
>> >>> runner = doctest.DocTestRunner(verbose=True)
>> >>> runner.run(test)
>> Trying:
>> print('hello world')
>> Expecting:
>> hello world
>> ok
>> TestResults(failed=0, attempted=1)
>>
> 
> ​and now how to do a multi line statement​.

doctest doesn't do tests with multiple *statements.* A docstring like

"""
>>> x = 42
>>> print(x)
42
"""

is broken into two examples:

>> import doctest
>>> p = doctest.DocTestParser()
>>> doctest.Example.__repr__ = lambda self: "Example(source={0.source!r}, 
want={0.want!r})".format(self)
>>> p.get_examples("""
... >>> x = 42
... >>> print(x)
... 42
... """)
[Example(source='x = 42\n', want=''), Example(source='print(x)\n', 
want='42\n')]


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


Getting data out of Mozilla Thunderbird with Python?

2015-12-08 Thread Anthony Papillion
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Hello Everyone,

I have a TON of email (years) stored in my Thunderbird. My backup
strategy for the last few years has been to periodically dump it all
in a tar file, encrypt that tar file, and move it up to the cloud.
That way, if my machine ever crashes, I don't lose years of email.

But I've been thinking about bringing Python into the mix to build a
bridge between Thunderbird and SQLite or MySQL (probably sqlite) where
all mail would be backed up to a database where I could run analytics
against it and search it more effectively.

I'm looking for a way to get at the mail stored in Thunderbird using
Python and, so far, I can't find anything. I did find the mozmail
package but it seems to be geared more towards testing and not really
the kind of use I need.

Can anyone suggest anything?

Many Thanks,
Anthony Papillion

- -- 
Phone:  1.845.666.1114
Skype:  cajuntechie
PGP Key:0x028ADF7453B04B15
Fingerprint:C5CE E687 DDC2 D12B 9063  56EA 028A DF74 53B0 4B15

-BEGIN PGP SIGNATURE-

iQIcBAEBCgAGBQJWZx+3AAoJEAKK33RTsEsVVa8QAKf1AmFdJsi4/b08vpkfwP3c
akGV98EuZzEva29jr8nnfXGgqw7xD/nDjMyLzuO0/q4Kn7eKpEnxkcGDLSbDgxaW
O8kD5eALHCVlUp9p/h7RMBBAyZ4mH8YC6qwvd5SWtH0TIMR7ClcWmDYwPF1Ahk7n
NAFvTsMl8PSnhcIoWHE4vebN4wHR8gZAxOLI8WVPA2BbER64EXiL00nWBav6UDN5
NUosAAVa549rrH0ibEf7Lada63DRTHCYnESxNIkAAHIO0z69WjnfZQ8gmmGFhuaW
AZzqYV5pIhdRnvrwjCQ06LtUNtz/qPqLbLSWF0hA6lwPKqzNum9EdvS4c1xjcXsU
KpOCTmJXy40x1Oi8h+yT6PGiDxt5VCHCdN8ppToI3HY5pYmoiPgWszJzrqYMz7hz
ruhNFAksKNUSI9QQupYcPw6oKQdnoGWmBH1yvGlZqeZuIxhGEv87oqRISE4NRQLe
yL4aDebwXdDgBzIZvFOFy2W4L43jdravg2/LliSC18iCUKBnIpWhazy7NZHw6h55
h3QP84DeuB/9tPLQUZF+BEJm3I+V8WfSKVVnsSbk/n/chHgYpWnu+h/wpD6lx43x
y0lPJm0ni5LeQM1bK4TsIXVEAOzl8UaOwn/VUG7P6Jnt6VEqvQutWZ0/WEeP1nIX
M7+e9hLlQWtlEbl6ud1K
=Dz7N
-END PGP SIGNATURE-

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


Re: Getting data out of Mozilla Thunderbird with Python?

2015-12-08 Thread Thomas 'PointedEars' Lahn
Anthony Papillion wrote:

> -BEGIN PGP SIGNED MESSAGE-

Please don’t do that again.

> I have a TON of email (years) stored in my Thunderbird. My backup
> strategy for the last few years has been to periodically dump it all
> in a tar file, encrypt that tar file, and move it up to the cloud.
> That way, if my machine ever crashes, I don't lose years of email.
> 
> But I've been thinking about bringing Python into the mix to build a
> bridge between Thunderbird and SQLite or MySQL (probably sqlite) where
> all mail would be backed up to a database where I could run analytics
> against it and search it more effectively.
> 
> I'm looking for a way to get at the mail stored in Thunderbird using
> Python and, so far, I can't find anything. I did find the mozmail
> package but it seems to be geared more towards testing and not really
> the kind of use I need.
> 
> Can anyone suggest anything?

Yes.

(Please never ask that question again:
)











Thunderbird uses the mbox format to store both e-mails and news messages.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing container's methods

2015-12-08 Thread Thomas 'PointedEars' Lahn
Erik wrote:

Please fix, Erik #75656.

> On 07/12/15 18:10, Tony van der Hoff wrote:
>> A highly contrived example, where I'm setting up an outer class in a
>> Has-a relationship, containing a number of Actors. The inner class needs
>> to access a method of the outer class; here the method get_name.
> 
> Generally, an object should not need to know which container it's in

NAK.  All kinds of objects already "know" which container they are in.

> (let alone its "index" or "key" in that container).

That is a different issue.

> Amongst other things, you can't put the object into multiple containers

You could if you made it a list of container references.

> which might be organised differently and you are asking for bugs where the
> container and the object get out of sync WRT just where the object is in 
> the container

It is the container’s job to make sure that this does not happen.

>> Can anyone please advise me on how to achieve this magic?
> 
> As you can't sensibly put the object into more than one container at a
> time anyway,

You can.  Quickhack:

class Child:
self._parents = []

def add_to_parent (self, parent):
self._parents.append(parent)
self._parents = list(set(self._parents))

def get_parents (self)
return self._parents

class Parent:
self._children = []

def add_child (self, child):
self._children.append(child)
child.add_to_parent(self)

| >>> p = Parent()
| >>> c = Child()
| >>> p.add_child(c)
| >>> p2 = Parent()
| >>> p2.add_child(c)
| >>> c.get_parents()
| [p, p2]

“As a child, I want to know who my parents are.”

Certainly you will not deny the validity of that user story ;-)

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing container's methods

2015-12-08 Thread Vincent Vande Vyvre

Le 08/12/2015 20:02, Thomas 'PointedEars' Lahn a écrit :

Erik wrote:

Please fix, Erik #75656.


On 07/12/15 18:10, Tony van der Hoff wrote:

A highly contrived example, where I'm setting up an outer class in a
Has-a relationship, containing a number of Actors. The inner class needs
to access a method of the outer class; here the method get_name.

Generally, an object should not need to know which container it's in

NAK.  All kinds of objects already "know" which container they are in.


(let alone its "index" or "key" in that container).

That is a different issue.


Amongst other things, you can't put the object into multiple containers

You can.  Quickhack:

class Child:
 self._parents = []

 def add_to_parent (self, parent):
 self._parents.append(parent)
 self._parents = list(set(self._parents))

 def get_parents (self)
 return self._parents

class Parent:
 self._children = []
.

I thing you should test your code before post it.

>>> class Child:
... self.parents = []
...
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in Child
NameError: name 'self' is not defined

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


Re: Accessing container's methods

2015-12-08 Thread Mark Lawrence

On 08/12/2015 19:02, Thomas 'PointedEars' Lahn wrote:

Erik wrote:

Please fix, Erik #75656.



Please fix what?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Getting data out of Mozilla Thunderbird with Python?

2015-12-08 Thread Mark Lawrence

On 08/12/2015 18:42, Thomas 'PointedEars' Lahn wrote:

Anthony Papillion wrote:


-BEGIN PGP SIGNED MESSAGE-


Please don’t do that again.



Says who?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Accessing container's methods

2015-12-08 Thread Erik
Annoyingly, there seemed to be no responses to the original question 
when I wrote that and then shortly after, I saw all the others (and we 
all pretty much said the same thing - so I'm not sure why I was singled 
out for special attention ;)).


On 08/12/15 19:02, Thomas 'PointedEars' Lahn wrote:

Erik wrote:

Please fix, Erik #75656.


Fixed(*)

Thomas 'PointerEars', you have chosen to selectively quote snippets of 
code and comments out of context, so I think it's futile to respond to 
those arguments individually. The original request (if you read it) was 
to return a string that said, essentially, "I am element 2 of 3 in my 
container".


You posted a "Quickhack" (which, to be fair, is an accurate description) 
which is incomplete, has errors and makes no sense in the context of the 
original question. We all know we can create a list in Python (of parent 
objects or whatever), but I think that if you expanded on that class a 
bit more (methods for the containers to update the contained objects on 
just what their index/key is etc) that you'll soon realise it's not a 
scalable option.


Also, WRT the original question, what is the method supposed to return 
now? "I am element 0 of 3 in container , key 'bar' of ('bar', 
'foo', 'spam') in container "? Just curious.


I'm interested in this response though:

>> Generally, an object should not need to know which container it's in
>
> NAK.  All kinds of objects already "know" which container they are in.

Please elucidate. Examples from the standard library would be interesting.

E.

(*) In the sense that it's not going to change ;)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing container's methods

2015-12-08 Thread Thomas 'PointedEars' Lahn
Vincent Vande Vyvre wrote:

> Le 08/12/2015 20:02, Thomas 'PointedEars' Lahn a écrit :
>> Erik wrote:
>>> Amongst other things, you can't put the object into multiple containers
>> You can.  Quickhack:
 ^
>> class Child:
>>  self._parents = []
>>
>>  def add_to_parent (self, parent):
>>  self._parents.append(parent)
>>  self._parents = list(set(self._parents))
>>
>>  def get_parents (self)
>>  return self._parents
>>
>> class Parent:
>>  self._children = []
>> .
> I thing you should test your code before post it.

I _think_ you should read postings more carefully before replying to them.
 
>  >>> class Child:
> ... self.parents = []
> ...
> Traceback (most recent call last):
>File "", line 1, in 
>File "", line 2, in Child
> NameError: name 'self' is not defined

Can be fixed easily by omitting “self.” there; likewise in Parent.  (In 
other programming languages I know, you need to refer to the class/instance 
explicitly to which you add attributes/properties.)

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing container's methods

2015-12-08 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote:

> On 08/12/2015 19:02, Thomas 'PointedEars' Lahn wrote:
>> Erik wrote:
>> 
>> Please fix, Erik #75656.
> 
> Please fix what?

You are not ready for the answer yet.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: filter a list of strings

2015-12-08 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote:

> On 03/12/2015 01:15, [email protected] wrote:
>> I would like to know how this could be done more elegant/pythonic.
>>
>> I have a big list (over 10.000 items) with strings (each 100 to 300
>> chars long) and want to filter them.
>>
>> list = .
>> […]
> 
> targets = ['Banana', 'Car'...]
> for item in list[:]:
>  for target in targets:
>  if target in item:
>  list.remove(item)
> 
>> btw: Is it correct to iterate over a copy (list[:]) of that string list
>> and not the original one?
> 
> Absolutely :)

However, “list” is a built-in class/constructor that would be overwritten 
this way.  One should choose another identifier than “list” for one’s 
variables.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing container's methods

2015-12-08 Thread Mark Lawrence

On 08/12/2015 22:52, Thomas 'PointedEars' Lahn wrote:

Mark Lawrence wrote:


On 08/12/2015 19:02, Thomas 'PointedEars' Lahn wrote:

Erik wrote:

Please fix, Erik #75656.


Please fix what?


You are not ready for the answer yet.



I'll be all pointed ears when you actually manage to provide an answer 
to anything here.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Accessing container's methods

2015-12-08 Thread Ian Kelly
On Tue, Dec 8, 2015 at 3:37 PM, Erik  wrote:
> On 08/12/15 19:02, Thomas 'PointedEars' Lahn wrote:
>>
>> Erik wrote:
>> 
>> Please fix, Erik #75656.
>
>
> Fixed(*)

[SNIP]

> (*) In the sense that it's not going to change ;)

Then I think you mean "Working as Intended", not "Fixed".  B-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing container's methods

2015-12-08 Thread Chris Angelico
On Wed, Dec 9, 2015 at 10:41 AM, Ian Kelly  wrote:
> On Tue, Dec 8, 2015 at 3:37 PM, Erik  wrote:
>> On 08/12/15 19:02, Thomas 'PointedEars' Lahn wrote:
>>>
>>> Erik wrote:
>>> 
>>> Please fix, Erik #75656.
>>
>>
>> Fixed(*)
>
> [SNIP]
>
>> (*) In the sense that it's not going to change ;)
>
> Then I think you mean "Working as Intended", not "Fixed".  B-)

No, he's doing a brilliant equivocation on the word 'fixed'. Once you
use superglue on something, it is fixed in place.

Win for Erik.

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


Re: storing test logs under /var/log/

2015-12-08 Thread Cameron Simpson

On 08Dec2015 13:24, Peter Otten <[email protected]> wrote:

Ganesh Pal wrote:
[Cameron Simpson:]

Finally. sys.exit accepts an integer, not a string.



Most of code  uses sys.exit("some error message")   ,  I did notice
that the error message is not displayed by sys .exit("some error
message") ,  do  u mean that using string is not advisable with
sys.exit ?


Cameron is wrong (he's probably coming from the C side of things).


Correct on both counts.


You can invoke sys.exit() with arbitrary objects:

[...]

   Exit the interpreter by raising SystemExit(status).
   If the status is omitted or None, it defaults to zero (i.e., success).
   If the status is an integer, it will be used as the system exit status.
   If it is another kind of object, it will be printed and the system
   exit status will be one (i.e., failure).


I Did Not Know That!

It says "printed". To stderr or stdout? If it isn't stderr, I think I will 
avoid this anyway.



How to I display error messages with sys.exit then ?

Wrong question; if you want to use sys.exit() in a way similar to C display
the error message first and invoke sys.exit() afterwards with a numerical
argument.


Indeed. My general habit is that fatal errors (when the code decides that they 
are fatal) print or log an error message and set a suitable failure flag. Which 
is then caught later somewhere suitable.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Getting data out of Mozilla Thunderbird with Python?

2015-12-08 Thread Cameron Simpson

On 08Dec2015 12:21, Anthony Papillion  wrote:

I have a TON of email (years) stored in my Thunderbird. [...]
I've been thinking about bringing Python into the mix to build a
bridge between Thunderbird and SQLite or MySQL (probably sqlite) where
all mail would be backed up to a database where I could run analytics
against it and search it more effectively.

I'm looking for a way to get at the mail stored in Thunderbird using
Python and, so far, I can't find anything. I did find the mozmail
package but it seems to be geared more towards testing and not really
the kind of use I need.

Can anyone suggest anything?


The local messges folders in Thunderbird are plain old mbox files IIRC. You can 
read these with the email.* modules and analyse them to your heart's content.


So I'd just write a Python program to read a single mbox file and break it into 
messages, make each one into an email Message object, and the process as you 
see fit.


Then point it at each of the TBird mbox files in turn.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: storing test logs under /var/log/

2015-12-08 Thread Ganesh Pal
> Wrong question; if you want to use sys.exit() in a way similar to C display
> the error message first and invoke sys.exit() afterwards with a numerical
> argument.
>
> --

oh ok , got it  thanks :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Shadowing built-ins [was Re: filter a list of strings]

2015-12-08 Thread Steven D'Aprano
On Wednesday 09 December 2015 09:58, Thomas 'PointedEars' Lahn wrote:

> Mark Lawrence wrote:
> 
>> On 03/12/2015 01:15, [email protected] wrote:
>>> I would like to know how this could be done more elegant/pythonic.
>>>
>>> I have a big list (over 10.000 items) with strings (each 100 to 300
>>> chars long) and want to filter them.
>>>
>>> list = .
>>> […]
[...]
> However, “list” is a built-in class/constructor that would be overwritten
> this way.  One should choose another identifier than “list” for one’s
> variables.

Correct, well mostly correct.

The original built-in list is *not* overridden, as such, but shadowed: it 
still exists, but access to it is blocked by the local variable "list". The 
list *type* still exists, only the *name* list is shadowed. So you can 
easily recover from accidentally shadowing the name by deleting the local:

del list

To beginners, accidental shadowing of built-ins is a serious source of 
confusion. But to experts, intentional shadowing can be useful.

There's nothing wrong with (say):

def sort_and_pop(list):
list.sort()
list.pop(0)

Yes, the local "list" shadows the built-in list. So what?

More usefully, one can monkey-patch a module by shadowing a built-in in that 
module:

# Python 3 only.
import builtins
def print(*args, **kwargs):
log_something()
builtins.print(*args, **kwargs)




-- 
Steve

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


META email [was Re: Getting data out of Mozilla Thunderbird with Python?]

2015-12-08 Thread Steven D'Aprano
On Wednesday 09 December 2015 05:42, Thomas 'PointedEars' Lahn wrote:

[snip]

Thomas, your sig says:

Please do not cc me. / Bitte keine Kopien per E-Mail.

but you have a Reply-To set. That implies that you want replies to be sent 
directly to you by email, not to the list or newsgroup. Is that really what 
you want? That seems incompatible with your signature. Which is correct?



-- 
Steve

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