Re: Is there any way to use the logging module adding nothing to a message

2016-06-04 Thread cl
Ben Finney  wrote:
> c...@isbd.net writes:
> 
> > If I do:-
> >
> > f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 
> > 'a', 100, 4)
> > f.setLevel(logging.DEBUG)
> > formatter = logging.Formatter('%(message)s')
> > f.setFormatter(formatter)
> > log.addHandler(f)
> >
> > Will I get just the message with no extras added by the logging module?
> 
> Yuo have the code, and presumably the system on which to test it. What's
> the answer?
> 
Very true, I thought the code was going to be much longer than that.
:-)

... and the answer is, yes, with the above I just get the message text
which is what I want.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Is there any way to use the logging module adding nothing to a message

2016-06-04 Thread cl
I want to use Python to handle the stdout logging that comes from
syncthing.

When you run syncthing it logs to stdout in a fairly standard format
with date, time, ERROR/WARNING/INFO etc. so I don't want to add these.
I just want to be able to write the log to a file with appropriate
rotation etc.

If I do:-

f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 
100, 4)
f.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(message)s')
f.setFormatter(formatter)
log.addHandler(f)

Will I get just the message with no extras added by the logging module?


-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get a directory list sorted by date?

2016-05-15 Thread cl
Tim Chase  wrote:
> On 2016-05-15 14:36, Grant Edwards wrote:
> > On 2016-05-15, Tim Chase  wrote:
> > > unless sorted() returns a lazy sorter,
> > 
> > What's a lazy sorter?
> 
> A hypothetical algorithm that can spool out a sorted sequence without
> holding the entire sequence in memory at the same time. 
> 
> Though I typed that initial reply a little quickly, as I hadn't known
> at the time that scandir()'s results also provide stat() results with
> reduced overhead (whereas listdir() just returns the filenames, so
> you have to stat() each one).  Thanks, Peter, for highlighting this
> feature.
> 
> So in light of my newfound knowledge, I humbly retract my snark and
> agree that it's better to exploit scandir()'s inclusion of stat()
> details without additional calls.
> 
Thanks everyone for the ideas etc.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How to get a directory list sorted by date?

2016-05-15 Thread cl
I have a little Python program I wrote myself which copies images from
a camera (well, any mounted directory) to my picture archive.  The
picture archive is simply a directory hierarchy of dates with years at
the top, then months, then days.

My Python program simply extracts the date from the image (put there
by the camera) and copies the image to the appropriate place in the
picture archive.

There is one small bit of speeding up done by my program, it checks if
the file is already in the archive and doesn't copy if it's already
there.  I don't generally clear pictures off the camera memory cards
so it's often the case that most of the pcitures are already in the
archive and all I actually want to do is copy the last couple of weeks
of new pictures.

As camera memory card sizes get bigger (and images get more detailed)
this is beginning to take rather a long time.

So, to the question, how can I get a list of the files on the memory
card (i.e. files in a directory) in date/time order, latest first.  I
can then copy them until the first one I find which is already in the
archive.  The file date may not *exactly* match the date/time in the
image file but it will produce the right order which is what I need.

What I want is a list in the order produced by:-
ls --sort=time

I suppose I could use a system call but that seems a little inelegant.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: No SQLite newsgroup, so I'll ask here about SQLite, python and MS Access

2016-05-05 Thread cl
There's a gmane 'newsgroup from a mailing list' for sqlite:-

gmane.comp.db.sqlite.general

It's quite active and helpful too.   (Also 'announce' and others)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread cl
Thomas 'PointedEars' Lahn  wrote:
> c...@isbd.net wrote:
> 
> > Occasionally I have to make forays into Javascript, can anyone
> > recommend a place similar to this list where Javascript questions can
> > be asked?  The trouble is that there are very many usenet Javascript
> > lists and it's difficult to guess which one[es] might be good.
> 
> There is no Javascript. 
> 
> There are no Usenet lists.
> 
> This is not only a Python *mailing* list, it is also mirrored as an 
> international Usenet _newsgroup_,  (which I am 
> reading).
> 
Which is what (OP) do too.  Life's too short to go into detail about
how one is accessing a group/list in the context of a question like my
original question.

It's quite fun following all the resulting flak though!  :-)

> If you can accept all of that, then the international Usenet _newsgroup_ 
>  (where I am posting primarily) is for you.
> So are other national/language-specific newsgroups on the JavaScripts and 
> other ECMAScript implementations.  In your newsreader, search for newsgroups 
> whose name contains “javascript”.
> 
> Next time, read  and STFW first, and get a real name.
> 
Ay?  

Thanks anyway, comp.lang.javascript it is, or I'll try it anyway.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread cl
Ned Batchelder  wrote:
> On Friday, March 25, 2016 at 5:17:21 PM UTC-4, Thomas 'PointedEars' Lahn 
> wrote:
> > c...@isbd.net wrote:
> > 
> > > Occasionally I have to make forays into Javascript, can anyone
> > > recommend a place similar to this list where Javascript questions can
> > > be asked?  The trouble is that there are very many usenet Javascript
> > > lists and it's difficult to guess which one[es] might be good.
> > 
> > There is no Javascript. 
> > 
> > There are no Usenet lists.
> > 
> > This is not only a Python *mailing* list, it is also mirrored as an 
> > international Usenet _newsgroup_,  (which I am 
> > reading).
> > 
> > If you can accept all of that, then the international Usenet _newsgroup_ 
> >  (where I am posting primarily) is for you.
> > So are other national/language-specific newsgroups on the JavaScripts and 
> > other ECMAScript implementations.  In your newsreader, search for 
> > newsgroups 
> > whose name contains "javascript".
> > 
> > Next time, read  and STFW first, and get a real name.
> 
> Chris, I apologize for Thomas.  His main goal on this list seems to be
> pointing out when people are wrong, over the smallest details.  His
> secondary goal is enforcing some imaginary rule about real names, though
> he couldn't be bothered to read your post thoroughly enough to discover yours.
> 
> Thomas is not typical of the Python community. We are mostly nice people. :)
> 
Yes, I know, this is one of my favourite groups/lists.  Just about
every question I have ever asked here has received really helpful
replies.  Even this one has, though it does seem to have stirred a bit
of a hornet's nest at the same time.  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-25 Thread cl
Larry Martell  wrote:
> On Thu, Mar 24, 2016 at 4:53 PM,   wrote:
> > I use Python wherever I can and find this list (as a usenet group via
> > gmane) an invaluable help at times.
> >
> > Occasionally I have to make forays into Javascript, can anyone
> > recommend a place similar to this list where Javascript questions can
> > be asked?  The trouble is that there are very many usenet Javascript
> > lists and it's difficult to guess which one[es] might be good.
> 
> I don't know of any JS specific mailing lists. When I have a JS
> question I usually use stackoverflow. But there is also the web design
> mailing list, which will accept JS questions. See
> http://www.webdesign-l.com/
> 
OK, thanks, I do know about both of those though I hadn't realised
there was a mailing list at Web Design.


> For jQuery questions I use the jquery forum - http://forum.jquery.com/

I find forums very difficult to use in general for a number of reasons:-

I have to visit them individually, it's not practical for the
number of subjects I'm interested in. I belong to 77 lists just
now, a similar number of forums would be totally unmanageable.

I can't use a decent editor (or my choice) to write and reply to
messages.

The threading is often rather poor (though some are better than
others).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-24 Thread cl
Mark Lawrence  wrote:
> On 24/03/2016 22:08, c...@isbd.net wrote:
> >
> >> If you do find anything like c.l.p for Javascript, let us know...
> >>
> > OK!  :-)
> >
> 
> I'd try c.l.bartc as he is the world's leading expert on everything that 
> you need to know about any language, whereby the only thing to know is 
> how fast is it.  It's just fantastic, you don't have to bother about the 
> source code that you write, all you have to bother about is the 
> underlying byte code.
> 
Many a true word.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-24 Thread cl
Grant Edwards  wrote:
> On 2016-03-24, c...@isbd.net  wrote:
> 
> > I use Python wherever I can and find this list (as a usenet group
> > via gmane) an invaluable help at times.
> >
> > Occasionally I have to make forays into Javascript, can anyone
> > recommend a place similar to this list where Javascript questions
> > can be asked?
> 
> Are you asking about
> 
>  1) Javascript itself (the language)?
> 
Probably mostly this.

>  2) jQuery or some other client-side framework?
> 
A little of this, but not much.


>  3) The DOM model and API provided by various web browsers?
> 
Not this.


> In most forums 99% of the threads are about 2 and 3.
> 
> > The trouble is that there are very many usenet Javascript lists and
> > it's difficult to guess which one[es] might be good.
> 
> That's a tough one.  I dabble in Javascript in order to support the
> Web UI's on some of the embedded products I work on, and I've yet to
> find a high quality forum for Javascript questions.  Javascript
> programing seems to be dominated by cargo-cult programmers with little
> understanding of the language.  They just sort of cut-n-paste code
> snippets they find online and then hope.  It's not quite as bad as PHP
> in that regard, but that's not saying mutch.  [IMO, the design of the
> Javascript language itself is _far_ better than the "design" of the
> PHP language, and that the results of cargo-cult programming in
> Javascript usually turn out better than they do in PHP.]
> 
Yes, it seems that the 'right way' in Javascript is often almost the
opposite of the 'right way' in other langueages.  Optimise at the
expense of readability seems to be the main aim.


> If you do find anything like c.l.p for Javascript, let us know...
> 
OK!  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


[OT'ish] Is there a list as good as this for Javascript

2016-03-24 Thread cl
I use Python wherever I can and find this list (as a usenet group via
gmane) an invaluable help at times.

Occasionally I have to make forays into Javascript, can anyone
recommend a place similar to this list where Javascript questions can
be asked?  The trouble is that there are very many usenet Javascript
lists and it's difficult to guess which one[es] might be good.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is this an error in python-babel or am I missing something?

2016-03-20 Thread cl
c...@isbd.net wrote:
> I am getting the following error when running some code that uses
> python-sqlkit.  This uses python-babel to handle dates for different
> locales.
> 
> Traceback (most recent call last):
> File 
> "/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/widgets/table/columns.py",
>  
> 
 
> line 169, in cell_data_func_cb formatted_value = 
> self.field.format_value(value) 
> 
> File 
> "/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/fields.py",
>  
> line 1114, in format_value return dates.format_date(value, format=format 
> or self.format, locale=self.locale) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 569, in 
> format_date 
> return pattern.apply(date, locale) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 892, in apply 
> return self % DateTimeFormat(datetime, locale) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 889, in __mod__ 
> return self.format % other 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 948, in 
> __getitem__ 
> return self.format_milliseconds_in_day(num) 
> File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 1029, in 
> format_milliseconds_in_day 
> self.value.minute * 6 + self.value.hour * 360 
> AttributeError: 'datetime.date' object has no attribute 'microsecond'
> 
> I'm handling a date in my sqlite database, *not* a datetime.  The
> sqlkit code seems to be calling the correct method - format_date() -
> in the python-babel dates.py file.
> 
> However it seems that python-babel ends up trying to hand the date
> down to a method that's expecting a datetime.
> 
> I've tried searching for reports of this error but I can't see any
> which makes me wonder if it's not a bug in python-babel, however if
> it's not a bug then I'm confused about what has gone wrong.
> 
> Is it a bug or is sqlkit doing something wrong?
> 
Well, it's a sort of bug.  I had made the sqlkit code set the 'format'
field to something that it shouldn't be.  It should be "full", "long",
"medium", or "short".  Due to my misunderstanding I had set it to a
completely wrong value.  This makes python-babel fall over as above.

So, my mistake, but python-babel should have caught it.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Any sqledit/sqlkit users here?

2016-03-19 Thread cl
Does anyone here use sqledit/sqlkit?  It's a sqlite database
browser/editor which does most of its work by introspection (at least
I think that's the right name for it).

Thus it's trivially simple to write a gui program to edit data in a
database:-

#!/usr/bin/python

from sqlkit.widgets import SqlTable
from sqlkit.db import proxy

import gtk

db = proxy.DbProxy(bind="sqlite:home/chris/tmp/odinlog.db")

t = SqlTable('tripLog',dbproxy=db, order_by='Date' )
t.reload()

gtk.main()


(Yes, I know exit/close is missing)

Just run the above (against an existing database) and you get a very
neat looking, editable, grid view.

I was wondering if there are any active users with whom I could share
ideas, the mailing list is quite quiet though there is activity to
move the code to bitbucket and allow more contributions.

I'm just a bit overwhelmed by it at the moment and need some feedback.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Is this an error in python-babel or am I missing something?

2016-03-19 Thread cl
I am getting the following error when running some code that uses
python-sqlkit.  This uses python-babel to handle dates for different
locales.

Traceback (most recent call last):
  File 
"/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/widgets/table/columns.py",
 line 169, in cell_data_func_cb formatted_value = self.field.format_value(value)
  File 
"/usr/local/lib/python2.7/dist-packages/sqlkit-0.9.6.1-py2.7.egg/sqlkit/fields.py",
 line 1114, in format_value return dates.format_date(value, format=format or 
self.format, locale=self.locale)
  File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 569, in 
format_date return pattern.apply(date, locale)
  File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 892, in 
apply return self % DateTimeFormat(datetime, locale)
  File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 889, in 
__mod__ return self.format % other
  File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 948, in 
__getitem__ return self.format_milliseconds_in_day(num)
  File "/usr/lib/python2.7/dist-packages/babel/dates.py", line 1029, in 
format_milliseconds_in_day self.value.minute * 6 + self.value.hour * 360
AttributeError: 'datetime.date' object has no attribute 'microsecond'

I'm handling a date in my sqlite database, *not* a datetime.  The
sqlkit code seems to be calling the correct method - format_date() -
in the python-babel dates.py file.

However it seems that python-babel ends up trying to hand the date
down to a method that's expecting a datetime.

I've tried searching for reports of this error but I can't see any
which makes me wonder if it's not a bug in python-babel, however if
it's not a bug then I'm confused about what has gone wrong.

Is it a bug or is sqlkit doing something wrong?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to waste computer memory?

2016-03-19 Thread cl
Gene Heskett  wrote:
> On Thursday 17 March 2016 17:37:02 alister wrote:
> 
> > On Fri, 18 Mar 2016 07:42:30 +1100, Chris Angelico wrote:
> > > On Fri, Mar 18, 2016 at 7:31 AM,   wrote:
> > >> Rick Johnson  wrote:
> > >>> In the event that i change my mind about Unicode, and/or for the
> > >>> sake of others, who may want to know, please provide a list of
> > >>> languages that *YOU* think handle Unicode better than Python,
> > >>> starting with the best first. Thanks.
> > >>
> > >> How about a list of languages that Unicode handles better than
> > >> ASCII? Like almost every language *except* English.
> > >
> > > Like every language *including* English. You can pretend that ASCII
> > > is enough, but you do lose some information.
> > >
> > > ChrisA
> >
> > as we all seam to have bitten the troll's thread
> > "how to waste computer memory"
> > give it to an delusion-ed incompetent to play with
> >
> > it is now 2016 not 1978, Memory is cheap. plentifully and fast there
> > is more than enough to go arround
> >
> While you all are trying to play can you top this, I just have to comment 
> that in 1978 I paid $400 for a kit to put 4k of static ram in a Cosmac 
> Super Elf.  And the code I wrote for it, looking up in the RCA 
> programmers manual to get the hex value I then entered via the onboard 
> monitor facility with its 6 digit led display, was still running in 1995 
> at that tv station.
> 
> So the obvious question then is, will any of your python code still be 
> running and doing its labor saving and dead on the video frame timing 
> job several times daily, 17 years hence?
> 
I wrote a Cosmac assembler for the Cosmac.  :-)

However I doubt it's still being used, a year or two after I wrote it
we migrated to a Tektronix development system that ran Unix (wow!).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to waste computer memory?

2016-03-19 Thread cl
Grant Edwards  wrote:
> On 2016-03-17, Chris Angelico  wrote:
> > On Fri, Mar 18, 2016 at 7:31 AM,   wrote:
> >> Rick Johnson  wrote:
> >>>
> >>> In the event that i change my mind about Unicode, and/or for
> >>> the sake of others, who may want to know, please provide a
> >>> list of languages that *YOU* think handle Unicode better than
> >>> Python, starting with the best first. Thanks.
> >>>
> >> How about a list of languages that Unicode handles better than ASCII?
> >> Like almost every language *except* English.
> >
> > Like every language *including* English. You can pretend that ASCII is
> > enough, but you do lose some information.
> 
> And I suppose you youngsters really think you need both upper and
> lower case and all those fancy curly braces, pipes, backslashes
> asterisks, and semi-colons and whatnot.  [Yes, I've written software
> that had to deal with baudot because that's all the paper tape reader
> could handle.]
> 
I'm hardly a youngster, I'm nearly 70 and started programming in the
early 1970s.  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is this an error in python-babel or am I missing something?

2016-03-19 Thread cl
Rick Johnson  wrote:
> On Thursday, March 17, 2016 at 5:48:12 PM UTC-5, c...@isbd.net wrote:
> > So, my mistake, but python-babel should have caught it.
> 
> Yeah, errors like that are a real pisser, and the further away from the 
> source that they break, the more headache they become to resolve. They 
> send you on a wild goose chase, and then after you've smacked your head 
> against the desk for 10 mins, you find out it was something stupid that 
> type checking could have easily prevented! If you find that this happens 
> frequently, you may want to consider creating a wrapper to validate the 
> inputs first, before sending them in -- there is no shame in doing this. 
> 
In this case I'm running around like a headless chicken in sqlkit
anyway so I'm very *likely* to make the sort of mistake I made. :-)

However I'm getting on reasonably well with sqlkit, it's very clever
indeed with the instrospection it does so that a very few lines of
(my) code can produce a useful, working application.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to waste computer memory?

2016-03-19 Thread cl
Rick Johnson  wrote:
> 
> In the event that i change my mind about Unicode, and/or for
> the sake of others, who may want to know, please provide a
> list of languages that *YOU* think handle Unicode better than
> Python, starting with the best first. Thanks.
> 
How about a list of languages that Unicode handles better than ASCII?
Like almost every language *except* English.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to program round this poplib error?

2016-03-10 Thread cl
Jon Ribbens  wrote:
> On 2016-03-10, c...@isbd.net  wrote:
> > # Read each message into a string and then parse with the email 
> > module, if 
> > # there's an error retrieving the message then just throw it away 
> > # 
> > try:
> > popmsg = pop3.retr(i+1)
> > except:
> > pop3.dele(i+1)
> > continue
> >
> > The trouble is that the error is (presumably) some sort of buffer size
> > limitation in pop3.dele().  If I trap the error then I still can't get
> > rid of the rogue E-Mail and, more to the point, I can't even identify
> > it so that the trap could report the error and tell me which message
> > was causing it.
> 
> You really, really should not be using bare "except:".
> Always specify which exceptions you are trying to catch.
> 
Yes, I know, but it doesn't really relate to the problem does it.


> In this case, I think there are two problems. Firstly, I think
> whoever implemented poplib mis-read the POP3 specification, as
> they are applying the line-length limit to not just the POP3
> commands and responses, but the email contents too.
> 
> Secondly, you are just trying to carry on with the POP3 connection
> after it has thrown an exception. You can't do that, because you
> don't know what the problem was. My guess would be that what you
> are mostly seeing is a line in the email content that is over 2kB,
> which causes 'retr' to throw a "line too long" exception.
> 
> You then blindly throw a "DELE" at the server, and when you try to
> read the response to that command it throws another "line too long"
> exception because (a) the server's actually still in the middle of
> sending the email contents and (b) there's a bug in the SSL poplib
> which means once it's thrown "line too long" it will keep doing so
> repeatedly.
> 
> So what I think you need to do is:
> 
>   (a) after your "import poplib" add "poplib._MAXLINE = 10*1024*1024"
>   or somesuch (i.e. increase it a lot),
> 
Ah, that's a much better way of doing it than actually changing the
code, thank you.


>   (b) get rid of your "except:" and work out what you really meant,
>   checking what the error returned was before blindly throwing
>   commands at a POP3 server in an unknown state. You may well
>   need to disconnect and reconnect before continuing - or indeed
>   you may well not need to catch any exception at all at this
>   point after doing (a).

Yes, hopefully the exception will go away.

Thank you again.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to program round this poplib error?

2016-03-10 Thread cl
Mark Lawrence  wrote:
> On 10/03/2016 12:04, c...@isbd.net wrote:
> > I have a (fairly simple) Python program that scans through a
> > 'catchall' E-Mail address for things that *might* be for me.  It sends
> > anything that could be for me to my main E-Mail and discards the rest.
> >
> > However I *occasionally* get an error from it as follows:-
> >
> >  Traceback (most recent call last):
> >File "/home/chris/.mutt/bin/getCatchall.py", line 65, in 
> >  pop3.dele(i+1)
> >File "/usr/lib/python2.7/poplib.py", line 240, in dele
> >  return self._shortcmd('DELE %s' % which)
> >File "/usr/lib/python2.7/poplib.py", line 160, in _shortcmd
> >  return self._getresp()
> >File "/usr/lib/python2.7/poplib.py", line 132, in _getresp
> >  resp, o = self._getline()
> >File "/usr/lib/python2.7/poplib.py", line 377, in _getline
> >  raise error_proto('line too long')
> >  poplib.error_proto: line too long
> >
> >
> > Does anyone have any idea how I can program around this somehow?  As
> > it is at the moment I have to go to the webmail system at my ISP and
> > manually delete the message which is a bit of a nuisance.
> >
> 
> How about a try/except in your code that catches poplib.error_proto?
> 
... and?  I'm still stuck because I can't identify the E-Mail in any
way to enable me to go and find it and delete it.  So the program
keeps trapping on the same E-Mail and never gets to process anything
after that.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How to program round this poplib error?

2016-03-10 Thread cl
I have a (fairly simple) Python program that scans through a
'catchall' E-Mail address for things that *might* be for me.  It sends
anything that could be for me to my main E-Mail and discards the rest.

However I *occasionally* get an error from it as follows:-

Traceback (most recent call last):
  File "/home/chris/.mutt/bin/getCatchall.py", line 65, in 
pop3.dele(i+1)
  File "/usr/lib/python2.7/poplib.py", line 240, in dele
return self._shortcmd('DELE %s' % which)
  File "/usr/lib/python2.7/poplib.py", line 160, in _shortcmd
return self._getresp()
  File "/usr/lib/python2.7/poplib.py", line 132, in _getresp
resp, o = self._getline()
  File "/usr/lib/python2.7/poplib.py", line 377, in _getline
raise error_proto('line too long')
poplib.error_proto: line too long


Does anyone have any idea how I can program around this somehow?  As
it is at the moment I have to go to the webmail system at my ISP and
manually delete the message which is a bit of a nuisance.

The piece of code that produces the error is as follows:-

# 
# 
# Read each message into a string and then parse with the email module, 
if 
# there's an error retrieving the message then just throw it away 
# 
try:
popmsg = pop3.retr(i+1)
except:
pop3.dele(i+1)
continue

The trouble is that the error is (presumably) some sort of buffer size
limitation in pop3.dele().  If I trap the error then I still can't get
rid of the rogue E-Mail and, more to the point, I can't even identify
it so that the trap could report the error and tell me which message
was causing it.

I guess one way to get around the problem would be to increase
_MAXLINE in /usr/lib/python2.7/poplib.py, it's on my own system so I
could do this.  Can anyone think of a better approach?



-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Continuing indentation

2016-03-04 Thread cl
Steven D'Aprano  wrote:
> On Fri, 4 Mar 2016 12:23 pm, INADA Naoki wrote:
> 
> >>
> >>
> >> Indeed. I don't understand why, when splitting a condition such as this,
> >> people tend to put the operator at the end of each line.
> >>
> >>
> > Because PEP8 says:
> > 
> >> The preferred place to break around a binary operator is after the
> > operator, not before it.
> > http://pep8.org/#maximum-line-length
> 
> PEP 8 is wrong :-)
> 
Yes, I agree.  In my mind the logic is:-

IF xxx
AND yyy
AND zzz
OR aaa
THEN do something

The PEP8 correct(er):-

IF xxx AND
 yyy AND
 zzz OR
 aaa
THEN do something

... just seems all wrong and difficult to understand.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Continuing indentation

2016-03-03 Thread cl
codewiz...@gmail.com wrote:
> On Wednesday, March 2, 2016 at 3:44:07 PM UTC-5, Skip Montanaro wrote:
> > 
> > if (some_condition and
> > some_other_condition and
> > some_final_condition):
> > play_bingo()
> 
> How about:
> 
>   continue_playing = (
>   some_condition and
>   some_other_condition and
>   some_final_condition
>   )
> 
>   if continue_playing:
>   play_bingo()
> 
> or:
> 
>   play_conditions = [
>   some_condition,
>   some_other_condition,
>   some_final_condition,
>   ]
> 
>   if all(play_conditions):
>   play_bingo()
> 
I'd much prefer the [] and () to be aligned so I can check that
beginnings have ends.  Similarly in C I prefer:-

if ( x == y )
{
z = 99;
}

rather than:-

if ( x == y ) {
z = 99;
}

Apparently the second is/was only popular because it uses fewer lines
and thus more code would appear on a single screen.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Everything good about Python except GUI IDE?

2016-02-28 Thread cl
Dietmar Schwertberger  wrote:
> On 28.02.2016 13:23, Sven R. Kunze wrote:
> > I recently introduced LaTeX to my girlfriend. LaTeX is quite ugly and 
> > it has this "distinct compile/execute step", so initially I hesitated 
> > to show it to her. But her MS Word experience got worse and worse the 
> > more complex (and especially larger) her workload became. Word became 
> > less responsive and results became even less reproducible (footnote 
> > numbering, styling, literature, etc.).
> Well, MS Word is a bad example, as it's lacking even some very basic 
> features like a good user interface for styles. (This is the reason why 
> most people are using Word just like a typwriter instead of creating 
> structured documents.)
> There were and probably still are better word processors, especially for 
> scientific use.
> 
E.g. Latex or reStructuredText, not GUI.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Does anyone here use wxGlade on Linux?

2016-02-11 Thread cl
I am trying out wxGlade on Linux, version 0.7.1 of wxGlade on xubuntu
15.10.

I have already written something using wxPython directly so I have the
basics (of my Python skills and the environment) OK I think.

I am having a lot of trouble getting beyond the first hurdle of
creating a trivial Python GUI with wxGlade.  Some of the problem is no
doubt that I'm unfamiliar with the interface but I seem to repeatedly
get to a situation where the interface won't respond to mouse clicks
(though the main menu items still work, I can Exit OK for instance).

Is wxPython still buggy or is it really just down to my lack of
familiarity with it?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does anyone here use wxGlade on Linux?

2016-02-11 Thread cl
Frank Miles <f...@u.washington.edu> wrote:
> On Thu, 11 Feb 2016 14:29:04 +, cl wrote:
> 
> > I am trying out wxGlade on Linux, version 0.7.1 of wxGlade on xubuntu
> > 15.10.
> > 
> > I have already written something using wxPython directly so I have the
> > basics (of my Python skills and the environment) OK I think.
> > 
> > I am having a lot of trouble getting beyond the first hurdle of
> > creating a trivial Python GUI with wxGlade.  Some of the problem is no
> > doubt that I'm unfamiliar with the interface but I seem to repeatedly
> > get to a situation where the interface won't respond to mouse clicks
> > (though the main menu items still work, I can Exit OK for instance).
> > 
> > Is wxPython still buggy or is it really just down to my lack of
> > familiarity with it?
> 
> Sure, there are bugs in wxPython, but they are "minor".  I haven't tried
> using wxGlade, but if it's anything like the glade I tried using long ago
> there are issues in getting the two working together.
> 
Oops, I meant to say "Is wxGlade still buggy".

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to trap this error (comes from sqlite3)

2016-02-09 Thread cl
Peter Otten <__pete...@web.de> wrote:
> c...@isbd.net wrote:
> 
> > It's absolutely right, there is a non-UTF character in the column.
> > However I don't want to have to clean up the data, it would take
> > rather a long time.  How can I trap the error and just put a Null or
> > zero in the datagrid?
> > 
> > Where do I put the try:/except: ?
> 
> Handle the problem earlier on by setting a text_factory that ignores or 
> replaces the offending bytes:
> 
> db = sqlite3.connect(...)
> db.text_factory = lambda b: b.decode("utf-8", "replace")
> 
> https://docs.python.org/2.7/library/sqlite3.html#sqlite3.Connection.text_factory
> https://docs.python.org/2/howto/unicode.html
> 
Brilliant, thank you, works perfectly and (IMHO) is about the neatest
possible solution.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How to trap this error (comes from sqlite3)

2016-02-09 Thread cl
I have the following code snippet populating a wxPython grid with data
from a database. :-

#
#
# populate grid with data 
#
all = self.cur.execute("SELECT * from " + table + " ORDER by id ")
for row in all:
row_num = row[0]
cells = row[1:]
for col in range(len(cells)):
if cells[col] != None and cells[col] != "null":
xx = cells[col]
if not isinstance(xx, basestring):
xx = str(xx)
print("row: ",row_num, "col: ", col, "value: ", xx)

self.SetCellValue(row_num, col, xx)


It works fine until it hits an invalid character in one of the
columns.  The print is just a temporary diagnostic.

The output I get, when it hits an invalid character is:-

('row: ', 5814, 'col: ', 9, 'value: ', u'')
('row: ', 5814, 'col: ', 10, 'value: ', '10.5')
('row: ', 5814, 'col: ', 11, 'value: ', u'')
('row: ', 5814, 'col: ', 12, 'value: ', u' Fuel (with inter-tank tap open) 
is at about 10.5 - 11cm in the sight glass before setting out.')
('row: ', 6186, 'col: ', 0, 'value: ', '0')
Traceback (most recent call last):
  File "/home/chris/bin/pg.py", line 100, in 
grid = Grid(frame, dbCon, table)
  File "/home/chris/bin/pg.py", line 52, in __init__
self.SetCellValue(row_num, col, xx)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/grid.py", line 
2016, in SetCellValue
return _grid.Grid_SetCellValue(*args, **kwargs)
sqlite3.OperationalError: Could not decode to UTF-8 column 'dayno' with 
text '�'


It's absolutely right, there is a non-UTF character in the column.
However I don't want to have to clean up the data, it would take
rather a long time.  How can I trap the error and just put a Null or
zero in the datagrid?

Where do I put the try:/except: ?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


A question about imports in wxpython

2016-02-08 Thread cl
I'm playing with some code that uses the wxpython grid.  *Every*
example I have seen starts with the imports:-

import wx
import wx.grid as Gridlib

As Gridlib is exactly the same number of characters as wx.grid I
really don't see the point.  Am I missing something?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Confused by wxpython documentation

2016-02-08 Thread cl
I'm playing around with some existing code that uses wxpython.  I've
been trying to understand a basic bit about the import statement and
so went to the beginning of the wxPython on line documents.

Going from the top to the "Hello World Example" (can't give URL as the
URL is the same for all the docs, http://www.wxpython.org/onlinedocs.php)
the first thing I see is some C/C++ code.  What's this about? How have
I got to the underlying C/C++ implementation rather than the Python
documentation?

I realise the Python usage follows the underlying C/C++ very closely
but seeing the C/C++ doesn't really help me write my Python too much.

Looking more closely what I've actually been taken to is the wxWidgets
documentation which, not unreasonably, is in C/C++.

... but where do I find the Python documentation for this?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's the best/neatest way to get Unicode data from a database into a grid cell?

2016-02-08 Thread cl
Dietmar Schwertberger  wrote:
> On 07.02.2016 12:19, c...@isbd.net wrote:
> > However my database has quite a lot of Unicode data as there are
> > French (and other) names with accents etc.  What's the right way to
> > handle this reasonably neatly?  At the moment it traps an error at
> > line 37:-
> >  self.SetCellValue(row_num, i, str(cells[i]))
> The unicode versions of wxPython should have no problems with handling 
> unicode strings.
> The problem that you see here is that str(...) tries to convert your 
> unicode data into a non-unicode string, which of course fails.
> Do something like:
> 
> value = cells[i]
> if not isinstance(value, basestring):
> value = str(value)
> self.SetCellValue(row_num, i, value)
> 
Thanks, worked perfectly!  I had been trying to produce something
similar in tkinter but grids are a bit clumsy in tkinter.  This wx
implementation will do me nicely.


> Once you switch to Python 3 and Phoenix you have to modify this 
> slightly, e.g. by adding this to the top of your code:
> 
> try:
> basestring
> except:
> basestring = (bytes,str)
> 
Everything else is 3 compatible so moving should be fairly painless
if/when phoenix becomes available.


-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's the best/neatest way to get Unicode data from a database into a grid cell?

2016-02-08 Thread cl
Vlastimil Brom  wrote:
> 
> Hi,
> your code in
> http://www.salstat.com/news/linking-wxgrid-to-sqlite-database-in-python-an-example
> 
> seems to work for me after small changes with both python 2.7 and 3.4
> (using wx Phoenix)

Where are you getting phoenix from?  It's not in the Ubuntu
repositories and when I search on Google I seem to go in ever
decreasing circles and always end up finding wxPython for 2.7.

Did you build it from source yourself (I can do that but only if it's
necessary).


> the changes I made are:
> - encoding declaration at the beginning of the file (mainly for py 2,
> if utf-8 is used):
> 
> #! Python
> # -*- coding: utf-8 -*-
> 
> - removing the str(...) call in the offending line you mentioned:
>  self.SetCellValue(row_num, i, cells[i])
> (what was the intent of the conversion to str?)
> 
I've no idea what the intent is/was, I just copied the code as I found
it.  I guess the cell value could be numeric.


> - corrected event name (insted of EVT_GRID_CELL_CHANGE)
> self.Bind(gridlib.EVT_GRID_CELL_CHANGED, self.CellContentsChanged)
> 
> - normal App() call (instead of the PySimpleApp)
> 
> app = wx.App()
> 
> I randomly tried some characters using Latin, Greek etc. characters
> (within BMP) as well as Gothic - beyond the  range - the cell
> content seems to be saved and and newly loaded from the sqlite db on
> subsequent calls of the app.
> 
Thanks for your help, very useful.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Confused by wxpython documentation

2016-02-08 Thread cl
Ian Kelly  wrote:
> On Mon, Feb 8, 2016 at 8:36 AM,   wrote:
> > I'm playing around with some existing code that uses wxpython.  I've
> > been trying to understand a basic bit about the import statement and
> > so went to the beginning of the wxPython on line documents.
> >
> > Going from the top to the "Hello World Example" (can't give URL as the
> > URL is the same for all the docs, http://www.wxpython.org/onlinedocs.php)
> > the first thing I see is some C/C++ code.  What's this about? How have
> > I got to the underlying C/C++ implementation rather than the Python
> > documentation?
> >
> > I realise the Python usage follows the underlying C/C++ very closely
> > but seeing the C/C++ doesn't really help me write my Python too much.
> >
> > Looking more closely what I've actually been taken to is the wxWidgets
> > documentation which, not unreasonably, is in C/C++.
> >
> > ... but where do I find the Python documentation for this?
> 
> wiki.wxpython.org was the site I used when I was developing wxPython.

Thanks, a good place to start, and it tells me why I get to the C/C++
docs for wxWidgets.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


What's the best/neatest way to get Unicode data from a database into a grid cell?

2016-02-07 Thread cl
I'm using this as a starting point for creating a grid to view and
edit some sqlite data:-

http://www.salstat.com/news/linking-wxgrid-to-sqlite-database-in-python-an-example

I can actually understand most of it which is a good start.  

However my database has quite a lot of Unicode data as there are
French (and other) names with accents etc.  What's the right way to
handle this reasonably neatly?  At the moment it traps an error at
line 37:-
self.SetCellValue(row_num, i, str(cells[i]))

I realise why this fails (I think) but how should one program this so
that:-
1 - the accented characters are displayed correctly in the grid cell
2 - One can edit the cell with accented characters

(I'll get round how to get the accented characters back to the
database later!)

My system (xubuntu 15.10) is all UTF8 so accented characters are
handled by the display, in terminals, etc. correctly.  I'm currently
using python 2.7 for this but would be quite happy to move to 3.4 if
this handles UTF8 better (I seem to remember it does maybe).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's the best/neatest way to get Unicode data from a database into a grid cell?

2016-02-07 Thread cl
Chris Angelico  wrote:
> 
> So the question then becomes: Under Python 3, can you use regular
> string objects for both the things you're working with? I can confirm
> that the inbuilt sqlite3 module works just fine with Unicode text; so
> all you need to do is try out your GUI code under Python 3. I've no
> idea how good wx support in Py3 is, so you might find you need to
> switch GUI toolkits to get everything working; but whether it's with
> wxWidgets, GTK, QT, or some other library, you should be able to put
> something together under Python 3 that "just works" as regards
> Unicode. Caveat: I haven't done any serious GUI programming using
> Python.
> 
Sadly wxpython doesn't work at all in Python 3.  There's a project
called Phoenix to move it across to Python 3 but it's nowhere near
stable yet, which is rather a pity.

So the question is do I stay with 2.7 and live with the Unicode
difficulties or do I try and move to another GUI that does work with
Python 3.  

Are there any Python 3 GUIs that would be reasonably easy to move to?
E.g. ones which have a grid object and which work in the same sort of
way as wxpython in general?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's the best/neatest way to get Unicode data from a database into a grid cell?

2016-02-07 Thread cl
Chris Angelico  wrote:
> On Sun, Feb 7, 2016 at 11:42 PM,   wrote:
> >
> > Are there any Python 3 GUIs that would be reasonably easy to move to?
> > E.g. ones which have a grid object and which work in the same sort of
> > way as wxpython in general?
> 
> Grid object? I'm not sure. But all of my GUI work of late has been
> with GTK, and I'm pretty happy with it. (Granted, that's with Pike,
> not Python, so the exact API is slightly different; but I know there
> is good support for Python 3.) You may also want to look into Tk /
> tkinter, although its Unicode support is (or was, last I heard)
> limited to the Basic Multilingual Plane - the 64K most commonly used
> characters.
> 
Tkinter is certainly a possibility.  Basic Unicode support will be
fine, I'm only interested in handling European accented characters.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hiding code from intruders, a different slant on an old question

2015-10-08 Thread cl
Dennis Lee Bieber  wrote:
> On Wed, 7 Oct 2015 13:05:07 + (UTC), alister
>  declaimed the following:
> 
> 
> >With a simple Cesar the method is "shift the alphabet by 'X' characters 
> >and X is the key
> >
> >if the key is unknown then the attacker still has to brute force the 
> >method (admittedly with only 25 options this is not difficult)
> 
> But who'd consider that with just one-case and alphabet only...
> 
> At the least include upper, lower, numbers, and basic punctuation --
> that will add a few more cycles of computation time to break 
> 
> 
> But the other point, yes... The most used encryption systems have
> publicly known/reviewed algorithms and rely on the secrecy of the key(s).

Which makes a nonsense of using a super-secure algorithm in many cases.

If you are doing in-place symmetric file encryption then it's the
security of the key hashing algorithm that matters much more than the
actual encryption used on the file.

Using ccrypt, enc, etc. for file encryption means the password that
encodes the encryption key is saved with the file so brute-force
attacks to get the key are quite straightforward.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Hiding code from intruders, a different slant on an old question

2015-10-07 Thread cl
I know questions similar to this are often asked but my reasons for
wanting to do this (and thus ways it can be done) are slightly different.

I have a number of little utility scripts (python and others) which I
use to automate the process of decrypting and displaying things like
files containing passwords.  

The encryption I use is reasonably secure anyway but I'd like to hide
the programs/methods I use so that:-

1 - The encrypted files are not identifiable as encrypted data (the file
command just returns 'data' so they can't be identified by that).  If
there's a script in my ~/bin directory that relates directly to the
files it's obvious they're encrypted.

2 - The method used for encryption isn't obvious, again an obvious
script will show the program I have used.


I *could* write a C program which just exec()'s the required programs,
if they're done separately this would be fairly well hidden but I was
wondering if there's anything more obvious I can do that enables me to
do things easily in Python.


This is for protecting against any possible intruder who has gained
access to my system by breaking an ssh password or stealing my laptop
for example.  It's *not* for hiding code that I'm giving to others,
I'd be quite happy to give the code in question to people who might
want to use it.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem with handling errors in POP3 message retrieval/deletion

2015-09-11 Thread cl
I have a (fairly) simple script that does 'catchall' processing on my
POP3 mailbox.  It looks for messages To: strings that *might* be for
me and then throws everything else away.

I was getting the occasional error as follows:-

Traceback (most recent call last):
  File "/home/chris/.mutt/bin/getCatchall.py", line 59, in 
popmsg = pop3.retr(i+1)
  File "/usr/lib/python2.7/poplib.py", line 232, in retr
return self._longcmd('RETR %s' % which)
  File "/usr/lib/python2.7/poplib.py", line 167, in _longcmd
return self._getlongresp()
  File "/usr/lib/python2.7/poplib.py", line 152, in _getlongresp
line, o = self._getline()
  File "/usr/lib/python2.7/poplib.py", line 377, in _getline
raise error_proto('line too long')
poplib.error_proto: line too long


So I added a try/except round the pop3.retr() and now I get this error:-

Traceback (most recent call last):
  File "/home/chris/.mutt/bin/getCatchall.py", line 63, in 
x = pop3.dele(i+1)
  File "/usr/lib/python2.7/poplib.py", line 240, in dele
return self._shortcmd('DELE %s' % which)
  File "/usr/lib/python2.7/poplib.py", line 160, in _shortcmd
return self._getresp()
  File "/usr/lib/python2.7/poplib.py", line 136, in _getresp
raise error_proto(resp)
poplib.error_proto: Data Base /Diamond /Arm /Freeway /Pocket /Barbecue
/Bathroom /Eyes /Train /Hat /Planet /Web /Girl /Surveyor /Rocket
/Slave /Software /Vampire /Vacuum /Sun /Egg /Leg /Ice /Guitar
/Post-office /Pepper /Hat /Eartupletters:10,50:
AAMGQLMUHSMCCVXEOPQRDWUSFEJFSHPEAQWHh /Spiral /Garden /Tennis racquet
/Banana /Spectrum /Bed /Fruit /Earth /Wheelchair /Spoon /Bee /Highway
/God /Guitar /Sandpaper /Typewriter /Finger /Feather /Salt
/Electricity /Pants /Sphere /Table /Comet / /Bee /Button /Map /Data
Base /Hieroglyph /Carpet /Hose /Bank /Fire /Solid /Staircase /Eyes
/Rope /School /Onion /Barbecue /Gemstone /Ice-cream /Nail /Alphabet
/Feather /Compass /Bottle /Shop /Fruit /Map /Sphere /Coffee /Radar
/Tongue /Tapestry /Radar /Sandwich /Circus /Spectrum /Aeroplane /Clock
/Room /Stomach /Snail / Satellite /Worm /Money  /Bed /Pyramid /Boy
/Pepper /Fruit /Junk /Bank /Bird /Pebble /Chair /Microscope /Satellite
/Woman /Kaleidoscope /Perfume /Triangle /Sunglasses /Needle
/Thermometer /Freeway /Man /Mist upletters:10,50:
TQDPDUGSMYEPJGBPYCTEIKMNFXKCSNDY/Vulture /Thermometer /Treadmill
/Pillow /Hose /Necklace /Coffee-shop /Space Shuttle /Pyramid /Rope
/Surveyor /Spot Light /Nail /Bed /Mist /Sandwich /Family /Salt /Fan
/Air /Maze /Mouth /Vacuum /Tongue /Bible /Gate /Wheelchair /Jet
fighter /Bible /Tunnel /Navy /Festival /Shop /Tapestry /Shower
/Cappuccino /Sandpaper /PaintBrush /Prison /Sex /Church /Man /Meat
/Ring /Snail /Floodlight /Toilet /Shower /Computer /Tiger /Diamond
/Bathroom /Boss /Leather jacket /Dress /Ship /Finger /Torpedo /Car
/Compass /Water /Mist /Butterfly /Staircase /Child /Backpack /Umbrella
/Tiger /School /Explosive /Restaurant /Bird /Cycle /Television
/Cappuccino /Bible /Kaleidoscope /Drill /Church /Television
/Hieroglyph /Game /Fungus /Sword /Gloves /Highway /Box functon /2022
/browser /cowritten /livinglogic /ione /800 /susceptibles /psz


Can anyone make any suggestions as to how to overcome this issue, all
I want to do is throw away the offending message.


The code for the whole thing is as follows:-

#!/usr/bin/python
#
#
# Collect E-Mail from my catchall POP3 mailbox on tsohost, deliver anything 
# that looks remotely useful and bin the rest
# 
#
import getpass, poplib
import email
import mailbox
import string
import smtplib
import time
import mailLib

home = "/home/chris"

log = mailLib.initLog("getCatchall")
#
#
# Read the filter file
#
fltr = {}
f = open(home + "/.mutt/getCatchall.filter", 'r')
for ln in f:# for each line in filter
if ln[0] == '#':# ignore comments
continue
#
#
# split the line into fields and store in a dictionary
#
fld = ln.split()
fltr[fld[0]] = fld[1]
#
#
# Process the messages, do a maximum of 100 at a time
#
while (1):
#
#
# Connect to the POP3 server, get message count, exit if no messages
#
pop3 = poplib.POP3_SSL('pop.isbd.net')
pop3.user('catch...@isbd.net')
pop3.pass_('')
numMessages = len(pop3.list()[1])
if (numMessages == 0):
break
#
#
# Process a maximum of 100 messages
#
log.info(str(numMessages) + " messages")
for i in range(min(numMessages, 100)):
#
#
# Read each message into a string and then parse with the email 
module, if
# 

Re: Problem with handling errors in POP3 message retrieval/deletion

2015-09-11 Thread cl
c...@isbd.net wrote:
> I have a (fairly) simple script that does 'catchall' processing on my
> POP3 mailbox.  It looks for messages To: strings that *might* be for
> me and then throws everything else away.
> 
[snip]

Sorry folks, I found the problem, it's a known 'bug' due to someone
trying to protect poplib from excessively long lines.  See:-

https://bugs.python.org/issue16041

It's easy to work around by something like:-

import poplib
poplib._MAXLINE=20480


-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Setting PYTHONPATH does not allow importing module

2015-03-04 Thread cl
fa...@vt.edu wrote:
 I have the following directory /home/me/projects/modulename.
 
 I update PYTHONPATH using the following command:
 export PYTHONPATH=$PYTHONPATH:/home/me/projects/modulename
 
 It seems to have been added:
 [me@machine ~]$ python -c import sys; print(sys.path)
 ['',... '/home/me', '/home/me/projects/modulename', ...]
 
 But import modulename does not work:
 [me@machine ~]$ python -c import modulename
 Traceback (most recent call last):
   File string, line 1, in module
 ImportError: No module named modulename
 
Don't you have that one level wrong, to import modulename you need
the directory where the name modulename is to be on PYTHONPATH.

I.e. you should have:-
export PYTHONPATH=$PYTHONPATH:/home/me/projects/

If you think about it this makes sense!

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-02-26 Thread cl
Ben Finney ben+pyt...@benfinney.id.au wrote:
 Chris Angelico ros...@gmail.com writes:
 
  I'd really like to see a lot more presentations done in pure text.
 
 Maybe so. My request at the moment, though, is not for people to change
 what's on their slides; rather, if they want people to retrieve them,
 the slides should be downloadable easily (i.e. without a web app,
 without a registration to some specific site).
 
... and having downloaded them what do you view them with if they're
not plain text?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-02-26 Thread cl
Ian Kelly ian.g.ke...@gmail.com wrote:
 On Wed, Feb 25, 2015 at 1:45 PM, Mark Lawrence breamore...@yahoo.co.uk 
 wrote:
  http://www.slideshare.net/pydanny/python-worst-practices
 
  Any that should be added to this list?  Any that be removed as not that bad?
 
 Using XML for configuration is a good example of a worst practice, but
 using Python instead isn't best practice. There are good arguments
 that a configuration language shouldn't be Turing-complete. See for
 instance this blog post: http://taint.org/2011/02/18/001527a.html
 
I agree wholeheartedly about XML, it's just not designed for what half
the world seems to be using it for.  Rather like HTML in a way, that
should have been a proper mark-up language.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-17 Thread cl
Chris Angelico ros...@gmail.com wrote:
 On Sun, Jan 18, 2015 at 1:51 AM, Albert van der Horst
 alb...@spenarnc.xs4all.nl wrote:
  In article mailman.17471.1420721626.18130.python-l...@python.org,
  Chris Angelico  ros...@gmail.com wrote:
  SNIP
 
 But sure. If you want to cut out complication, dispense with user
 accounts altogether and run everything as root. That's WAY simpler!
 
  I didn't except this strawman argument from you.
  Of course you need a distinction between doing system things as
  root, and working as a normal user. You just don't need sudo.
 
 So you have to have a password on the root account. My systems are
 more secure, as they do not have a password that someone could learn.
 
Yes, they do (if you use sudo) it's *your* password and IMHO it's less
secure as you only need to know one password to get root access.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hello World

2015-01-17 Thread cl
Michael Torrie torr...@gmail.com wrote:
 On 01/17/2015 07:51 AM, Albert van der Horst wrote:
  In article mailman.17471.1420721626.18130.python-l...@python.org,
  Chris Angelico  ros...@gmail.com wrote:
  SNIP
 
  But sure. If you want to cut out complication, dispense with user
  accounts altogether and run everything as root. That's WAY simpler!
  
  I didn't except this strawman argument from you.
  Of course you need a distinction between doing system things as
  root, and working as a normal user. You just don't need sudo.
 
 I just don't see the distinction.  What's the difference between having
 to type in a root password and having to type in your own administrative
 user password?  Guess we're all just struggling to understand your logic
 here.
 
One big distinction is that you need to know two passwords to get root
access if there's a real root account as opposed to using sudo.  This
only applies of course if direct root login isn't allowed (via ssh or
whatever).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extension of while syntax

2014-12-12 Thread cl
Marko Rauhamaa ma...@pacujo.net wrote:
 Chris Angelico ros...@gmail.com:
 
  You could deduplicate it by shifting the condition:
 
  while True:
  value = get_some_value()
  if value not in undesired_values: break
 
  But I'm not sure how common this idiom actually is.
 
 Extremely common, and not only in Python.
 
It's the classic C 'for' loop.

'for' in C is essentially a while with an initialiser for the loop
variable.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Most gratuitous comments

2014-11-20 Thread cl
sohcahto...@gmail.com wrote:
 
 # increment x
 x += 1

But it shouldn't say 'increment x', it should say 'add one to the line
count' or some such.  Although changing the variable name to
'lineCount' would do almost as well.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding help command description syntax - explanation needed

2014-11-07 Thread cl
Darren Chen ccylily1...@gmail.com wrote:
 在 2014年11月5日星期三UTC+8下午8时17分11秒,larry@gmail.com写道:
  On Wed, Nov 5, 2014 at 7:13 AM, Ivan Evstegneev webmailgro...@gmail.com 
  wrote:
   Firtst of all thanks for reply.
  
  brackets [] means that the argument is optional.
  
   That's what I'm talking about (asking actually), where do you know it 
   from?
  
  I know it because I've been a programmer for 39 years.
 
 that's awesome!!

Well I started in 1971 or thereabouts.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Egg help wanted

2014-10-03 Thread cl
I have installed (using easy_install) a little utility, it seems to
have installed just the top-level python script in /usr/local/bin
which in turn uses load_entry_point() to run the actual code.

As far as I can see the code and support files remain in the .egg file
in /usr/local/lib/python2.7/dist-packages, is this right?  I.e. is the
egg file unzipped 'on the fly' when the program is called?

Reading the documentation for pkg_resources it sounds like it will
also work if I unpack the .egg file into a directory of the same name
also put in /usr/local/lib/python2.7/dist-packages.  Have I understood
this correctly?  I want to do this to make it easy to do trivial edits
to the program rather than having to move it all back into a proper
development environment.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function passed as an argument returns none

2014-10-02 Thread cl
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 between printing output to the screen and returning values from a function,
 and under what circumstances Python will automatically print said returned
 values as a convenience. Conflating the two as 2 kinds of return is an

To me automically printing something is a mis-feature!

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread cl
Travis Griggs travisgri...@gmail.com wrote:
 
 
 Sent from my iPhone
 
  On Oct 1, 2014, at 04:12, Peter Otten __pete...@web.de wrote:
  
  `lambda` is just a fancy way to define a function inline
 
 Not sure fancy is the correct adjective; more like syntactic tartness 
 (a less sweet version of syntactic sugar). 
 
It throws me because 'lambda' simply has no meaning whatsoever for me,
i.e. it's just a greek letter.

So from my point of view it's like seeing 'epsilon' stuck in the
middle of some code. 

It's not as if I'm new to programming either, I've been writing
software professionally since the early 1970s, now retired.  I have no
formal computer training, there wasn't much in the way of university
courses on computing in the 1960s, I have a degree in Electrical
Engineering.  Maybe that's why 'lambda' means nothing to me!  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-02 Thread cl
Grant Edwards invalid@invalid.invalid wrote:
 On 2014-10-02, c...@isbd.net c...@isbd.net wrote:
  Travis Griggs travisgri...@gmail.com wrote:
  
  
  Sent from my iPhone
  
   On Oct 1, 2014, at 04:12, Peter Otten __pete...@web.de wrote:
   
   `lambda` is just a fancy way to define a function inline
  
  Not sure fancy is the correct adjective; more like syntactic tartness 
  (a less sweet version of syntactic sugar). 
  
  It throws me because 'lambda' simply has no meaning whatsoever for me,
  i.e. it's just a greek letter.
 
  So from my point of view it's like seeing 'epsilon' stuck in the
  middle of some code. 
 
  It's not as if I'm new to programming either, I've been writing
  software professionally since the early 1970s, now retired.
 
 The use of lamba as a keyword to define an anonymous function is
 borrowed from Lisp which got it from Lambda calculus.
 
 http://en.wikipedia.org/wiki/Lambda_calculus
 
Ah, so at least there is a reason for it, I'm far from being a
mathematician though so it's not particularly obvious (for me anyway).

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
I have a dictionary as follows:-

{
u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', 
conv=6834.374834509803, Description=u'Starter Amps'), 
u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', 
conv=29.01374215995874, Description=u'Leisure Volts'),
u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, 
Description=u'Rudder Position'),
u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', 
conv=32.727273081945, Description=u'Leisure Amps'),
u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', 
conv=28.94469628911757, Description=u'Starter Volts')
}

I want to output a menu to a user comprising some parts of the
dictionary (ain and Description) sorted by ain.

Is there some incantation of sorted() that will do what I want?  I
can't quite fathom out the 'key=' parameter needed to sort it by the
tuple item.  Maybe I need a cmp= ?

E.g. I want to do something like:-

for meas in sorted(adc.cfg, key=???):
print(adc.cfg[meas].ain, adc.cfg[meas].Description)

What's needed in the ???

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Peter Otten __pete...@web.de wrote:
 c...@isbd.net wrote:
 
  I have a dictionary as follows:-
  
  {
  u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
  conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
  Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
  Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
  name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'), u'xx':
  Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
  u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1',
  conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts':
  Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757,
  Description=u'Starter Volts') }
  
  I want to output a menu to a user comprising some parts of the
  dictionary (ain and Description) sorted by ain.
  
  Is there some incantation of sorted() that will do what I want?  I
  can't quite fathom out the 'key=' parameter needed to sort it by the
  tuple item.  Maybe I need a cmp= ?
  
  E.g. I want to do something like:-
  
  for meas in sorted(adc.cfg, key=???):
  print(adc.cfg[meas].ain, adc.cfg[meas].Description)
  
  What's needed in the ???
 
 for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
 print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
Brilliant, worked perfectly, thank you.  The bit I didn't understamd was
that 'lambda' bit, but I just looked it up and I'm a bit clearer now.

 or simpler
 
 for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
 print(row.ain, row.Description)
 
I tried this, I got:-

Traceback (most recent call last):
  File /home/chris/bin/calibrate.py, line 24, in module
  for meas in sorted(adc.cfg.values,
  key=operator.attrgetter(ain)):
  NameError: name 'operator' is not defined
I must admit that it's the bits like 'operator' in the parameters that
I can't really understand where they come from.


 or even
 
 for row in sorted(
 map(operator.attrgetter(ain, Description), adc.cfg.values())):
 print(*row)
 

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Joel Goldstick joel.goldst...@gmail.com wrote:
 On Wed, Oct 1, 2014 at 6:45 AM,  c...@isbd.net wrote:
  Peter Otten __pete...@web.de wrote:
  c...@isbd.net wrote:
 
   I have a dictionary as follows:-
  
   {
   u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1',
   conv=6834.374834509803, Description=u'Starter Amps'), u'LeisureVolts':
   Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874,
   Description=u'Leisure Volts'), u'RudderPos': Row(id=6, ain=u'AIN5',
   name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'), u'xx':
   Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
   u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1',
   conv=32.727273081945, Description=u'Leisure Amps'), u'StarterVolts':
   Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757,
   Description=u'Starter Volts') }
  
   I want to output a menu to a user comprising some parts of the
   dictionary (ain and Description) sorted by ain.
  
   Is there some incantation of sorted() that will do what I want?  I
   can't quite fathom out the 'key=' parameter needed to sort it by the
   tuple item.  Maybe I need a cmp= ?
  
   E.g. I want to do something like:-
  
   for meas in sorted(adc.cfg, key=???):
   print(adc.cfg[meas].ain, adc.cfg[meas].Description)
  
   What's needed in the ???
 
  for meas in sorted(adc.cfg, key=lambda key: adc.cfg[key].ain):
  print(adc.cfg[meas].ain, adc.cfg[meas].Description)
 
  Brilliant, worked perfectly, thank you.  The bit I didn't understamd was
  that 'lambda' bit, but I just looked it up and I'm a bit clearer now.
 
  or simpler
 
  for row in sorted(adc.cfg.values(), key=operator.attrgetter(ain))
  print(row.ain, row.Description)
 
  I tried this, I got:-
 
  Traceback (most recent call last):
File /home/chris/bin/calibrate.py, line 24, in module
for meas in sorted(adc.cfg.values,
key=operator.attrgetter(ain)):
NameError: name 'operator' is not defined
  I must admit that it's the bits like 'operator' in the parameters that
  I can't really understand where they come from.
 
 
 operator is a module. See
 https://docs.python.org/2/library/operator.html#module-operator

Ah, OK, as it sort of might be a keyword I hadn't thought of that. :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread cl
Joel Goldstick joel.goldst...@gmail.com wrote:
 On Wed, Oct 1, 2014 at 5:58 AM,  c...@isbd.net wrote:
  I have a dictionary as follows:-
 
  {
  u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', 
  conv=6834.374834509803, 
 Description=u'Starter Amps'), 
  u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', 
  conv=29.01374215995874, 
 Description=u'Leisure Volts'), 
  u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, 
 Description=u'Rudder Position'), 
  u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
  u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', 
  conv=32.727273081945, 
 Description=u'Leisure Amps'), 
  u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', 
  conv=28.94469628911757, 
 Description=u'Starter Volts') 
  }
 
 Is Row a function?  Or do you have a key with a tuple as the value?

Row is a namedtuple, the dictionary is extracted from a database with
a row factory so the namedtuple names are the column names.  It means
that if I change a column name then most things continue to work
without any code changes, and also I can refer to items in the tuple
by name of course.

I have the answer to my question in other responses.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-09-30 Thread cl
I am developing some code which runs on a (remote from me most of the
time) Beaglebone Black single board computer.  It reads various items
of data (voltages, currents, temperatures, etc.) using both a 1-wire
bus system and the Beaglebone's ADC inputs.  The values are stored
at hourly intervals into a database which is regularly rsync'ed
across to my home system where I use the values for monitoring etc.

Associated with each value are various parameters, i.e. for each ADC
input of the Beaglebone there is the ADC input number, a short name
for the value, a conversion factor and a description.  Similarly for
the 1-wire inputs there is the 1-wire filesystem filename, a short
name for the data and a longer description.

I am puzzling where and how to keep these configuration values. My
current design has them in dedicated tables in the database but this
is rather clumsy in many ways as there's an overhead reading them
every time the program needs them and changing them isn't particularly
convenient at the Beaglebone doesn't have a GUI so it has to be done
using SQL from the command line.

Does it make sense to add them to the modules which handle the reading
of the inputs?  I already have modules defining classes called Adc and
OneWire, is it a reasonable approach to add the configuration to these
as, probably, dictionaries?  Modifying it would be pretty simple -
just edit the python source (one of the easiest things for me to do on
the Beaglebone as my sole access is via ssh/command line).

Thus I'd have something like (apologies for any syntax errors):-

cfg = { LeisureVolts: [AIN0, 0.061256, Leisure Battery Voltage],
StarterVolts: [AIN1, 0.060943, Starter Battery Voltage],
LeisureAmps1: [AIN2, 0.423122, Leisure Battery Current}

(It might be better to makes those lists dictionaries, but it shows
the idea)

Are there any better ways of doing this?  E.g. some sort of standard
configuration file format that Python knows about?  I would actually
quite like to keep the configuration data separate from the code as it
would simplify using the data at the 'home' end of things as I'd just
need to copy the configuration file across.  This was why the database
approach appealed at first as all I need to do is copy the database
and everything is in there.

I'm not really expecting quick/glib answers, just some ideas and
comments on the various ways of doing this and their advantages and
disadvantages.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re:Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-09-30 Thread cl
Dave Angel da...@davea.name wrote:
 c...@isbd.net Wrote in message:
  I am puzzling where and how to keep these configuration values. My
  current design has them in dedicated tables in the database but this
  is rather clumsy in many ways as there's an overhead reading them
  every time the program needs them and changing them isn't particularly
  convenient at the Beaglebone doesn't have a GUI so it has to be done
  using SQL from the command line.
 
 It is very useful for the database to be self contained and self
  describing.  Among other things it means that you can easily take
  a snapshot at any time,  and that snapshot is not tied to any
  specific version of the code. As for changing with sql, you can
  always add a configuration utility when using sql becomes a
  nuisance,  or introduces errors. 
 
I guess I can write a script to do the change but it's more code to
write and maintain as opposed to simply editing a configuration file
with tools I know well.


 The key thing is to manage change.  You need to decide which
  things are conceivably going to change and how you'll manage both
  the change itself and the inevitable split between prechange data
  and post. One kind of change might be fixing the spelling of
  battery.  No biggie,  just let new accesses get the new one. 
  Another kind might be the addition of a new instance of an adc
  converter.  Not a problem,  as long as you don't reuse an old
  name. And presumably you never remove an old name from the
  config.
 
The only things really likely to change (and may change regularly) are
the conversion factors, drifting voltage references etc. will
inevitably require these to be recalibrated every so often.  Other
than that it's just typos or me deciding to change the name of
something.


 More troublesome is adding a new kind of data. You have to decide
  whether it's worth generalizing the code to anticipate the
  change,  or just admit that the code will grow at that point and
  that old code won't deal with the new data. 
 
There's a separate module for each input type (just ADC and 1-wire at
the moment), I don't anticipate any more though I suppose there might
be digital inputs one day.  So a configuration [file] for each type
seems to make sense, generalising it would be more trouble than it's
worth I think.


  
  Does it make sense to add them to the modules which handle the reading
  of the inputs?  I already have modules defining classes called Adc and
  OneWire, is it a reasonable approach to add the configuration to these
  as, probably, dictionaries?  Modifying it would be pretty simple -
  just edit the python source (one of the easiest things for me to do on
  the Beaglebone as my sole access is via ssh/command line).
  
 
 Nope, read it from the db. You still might be loading it to a cfg
  variable, however. 
 
  Thus I'd have something like (apologies for any syntax errors):-
  
  cfg = { LeisureVolts: [AIN0, 0.061256, Leisure Battery Voltage],
  StarterVolts: [AIN1, 0.060943, Starter Battery Voltage],
  LeisureAmps1: [AIN2, 0.423122, Leisure Battery Current}
  
  (It might be better to makes those lists dictionaries, but it shows
  the idea)
 
 Actually it's probably better to use named tuples. All those lists
  are apparently of identical length with identical meaning of a
  given element offset.  But if named tuple isn't flexible,enough, 
  you probably need a new class.
 
  
  Are there any better ways of doing this?  E.g. some sort of standard
  configuration file format that Python knows about?  I would actually
  quite like to keep the configuration data separate from the code as it
  would simplify using the data at the 'home' end of things as I'd just
  need to copy the configuration file across.  This was why the database
  approach appealed at first as all I need to do is copy the database
  and everything is in there.
  
  I'm not really expecting quick/glib answers, just some ideas and
  comments on the various ways of doing this and their advantages and
  disadvantages.
 
 Main next question is whether you can restart each system when you
  add to the configuration.  
 
Yes, restarting isn't a problem, the Beaglebone is dedicated to this
task and doesn't control anything so restarts are not an issue.  

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-09-30 Thread cl
Rustom Mody rustompm...@gmail.com wrote:
 On Tuesday, September 30, 2014 5:18:31 PM UTC+5:30, Chris wrote:
 
  I would actually
  quite like to keep the configuration data separate from the code as it
  would simplify using the data at the 'home' end of things as I'd just
  need to copy the configuration file across.  This was why the database
  approach appealed at first as all I need to do is copy the database
  and everything is in there.
 
 Of course
 
  Are there any better ways of doing this?  E.g. some sort of standard
  configuration file format that Python knows about? 
 
 Umm this is getting to be a FAQ...
 Maybe it should go up somewhere?
 
 Yes there are dozens:
 - ini
 - csv
 - json
 - yml
 - xml
 - pickle
 - And any DBMS of your choice
 
 I guess Ive forgotten as many as Ive listed!!

Yes, I know, I've found most of those.  I'm really asking for help in
choosing which to use.  I think I can reject some quite quickly:-

ini - doesn't work so well with lists/dictionaries (though possible)
csv - rather difficult to edit
json - one of the most likely possibilities, but prefer yml
yml - front runner if I go for configuration files
xml - horrible, nasty to edit, etc. I don't like XML! :-)
pickle - not user editable as I understand it
dbms - current solution in sqlite3 as described

What I'm really asking for is how to choose between:-

DBMS - present solution, keeps config with data easily but more
code and less easy to change
yml - easy to edit config, keeps data separate from code but needs
YAML installed and separate files to manage
python - just keep config in the modules/classes, not easy to use
at 'both ends' (home and remote), otherwise quite simple

My requirements are:-
Easy to change, i.e.human readable format which can be edited
simply as I have to do this via a terminal/ssh.
Easy to use at local end as well as remote end, the remote end is
where it lives and is the 'driver' as it were but I need to know
the configuration at the local end as well.
-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-09-30 Thread cl
Rustom Mody rustompm...@gmail.com wrote:
 
  # docs for first option
  # more docs
  # examples
  # etcetera
  first_option =123
 
  # docs for second option
  second_option = 234
 
  Is that Python code, or is it a sectionless INI file, or what?
 
 Yeah I was going to say that this is possible
 
  There's  no difference.
 
 But there is! Its code that looks like data.
 
The main trouble with this approach is that I need some way to have
the python/config file available at the 'home' end of this as well as
at the 'remote' end.  I guess I could write a copy of the file into
the database but then I have the editing issue again, changing it
becomes messy.  If it's not in the database then how do I 'tie' it to
the data?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Keepin constants, configuration values, etc. in Python - dedicated module or what?

2014-09-30 Thread cl
Neil D. Cerutti ne...@norwich.edu wrote:
 On 9/30/2014 7:35 AM, c...@isbd.net wrote:
  Thus I'd have something like (apologies for any syntax errors):-
 
  cfg = { LeisureVolts: [AIN0, 0.061256, Leisure Battery Voltage],
   StarterVolts: [AIN1, 0.060943, Starter Battery Voltage],
   LeisureAmps1: [AIN2, 0.423122, Leisure Battery Current}
 
  (It might be better to makes those lists dictionaries, but it shows
  the idea)
 
 Using configparser.ConfigParser to read an ini-format seems like a good 
 idea. I use it for my own numerous fixed format data file definitions, 
 and it's been convenient and even extensible.
 
 [LeisureVolts]
 Description=Leisure Battery Voltage
 Code=AIN0
 Value=0.061256
 
 [StarterVolts]
 Description=Starter Battery Voltage
 Code=AIN1
 Value=0.060943
 
 [LeisureAmps1]
 Description=Leisure Battery Current
 Code=AIN2
 Value=0.423122
 
That's OK except that it doesn't associate the different sections in
any way, I need another level which includes these to indicate that
these are values read from the ADC.  There's another collection of
config data for values read from the 1-wire bus.

I guess I could have two config files, one for ADC and one for 1-wire.

In fact I think that's the best approach so far.  Ini format files are
human readable (and more to the point editable), I can store them in
the same directory as the database so they will get carried around
with the data and the configparser module is built-in.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Using namedtuple with sqlite, surely it can do better than the example

2014-09-30 Thread cl
In the namedtuple documentation there's an example:-

EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, 
department, paygrade')

import sqlite3
conn = sqlite3.connect('/companydata')
cursor = conn.cursor()
cursor.execute('SELECT name, age, title, department, paygrade FROM 
employees')
for emp in map(EmployeeRecord._make, cursor.fetchall()):
print emp.name, emp.title

(I've deleted the csv bit)

Surely having to match up the name, age, title, department,
paygrade between the tuple and the database can be automated, the
example is rather pointless otherwise.  At the very least one should
use the same variable instance for both, but it should be possible to
get the tuple names from the database.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to turn a string into a list of integers?

2014-09-05 Thread cl
Joshua Landau jos...@landau.ws wrote:
 On 3 September 2014 15:48,  c...@isbd.net wrote:
  Peter Otten __pete...@web.de wrote:
   [ord(c) for c in This is a string]
  [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103]
 
  There are other ways, but you have to describe the use case and your Python
  version for us to recommend the most appropriate.
 
  That looks OK to me.  It's just for outputting a string to the block
  write command in python-smbus which expects an integer array.
 
 Just be careful about Unicode characters.

I have to avoid them completely because I'm sending the string to a
character LCD with a limited 8-bit only character set.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How to turn a string into a list of integers?

2014-09-03 Thread cl
I know I can get a list of the characters in a string by simply doing:-

listOfCharacters = list(This is a string)

... but how do I get a list of integers?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to turn a string into a list of integers?

2014-09-03 Thread cl
Peter Otten __pete...@web.de wrote:
 c...@isbd.net wrote:
 
  I know I can get a list of the characters in a string by simply doing:-
  
  listOfCharacters = list(This is a string)
  
  ... but how do I get a list of integers?
  
 
  [ord(c) for c in This is a string]
 [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103]
 
 There are other ways, but you have to describe the use case and your Python 
 version for us to recommend the most appropriate.
 
That looks OK to me.  It's just for outputting a string to the block
write command in python-smbus which expects an integer array.

Thanks.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: usenet reader software

2014-07-24 Thread cl
Sturla Molden sturla.mol...@gmail.com wrote:
 Monte Milanuk memila...@gmail.com wrote:
  Aaaannnd here we have a good example of why it would be really nice to
  be able to filter/score based on the message *body*, not just the
  headers. 8(
 
 Actually, here we have the reason why Usenet died.
 
... and the alternatives have the ability to filter/score based on
the message body do they?  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: usenet reader software

2014-07-19 Thread cl
memilanuk memila...@gmail.com wrote:
 
 Guess where I'm going with this is... is there anything out there worth 
 trying - on Linux - that I'm missing?
 
If slrn was a maybe then there's also tin for text mode news readers,
it's what I have always used.  I don't know what it does with HTML as
none of the groups I frequent ever have any HTML in them.

It does add one 'GUIness' to its text mode, it's mouse aware so you
can click on messages in a list to open them.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: usenet reader software

2014-07-19 Thread cl
Sturla Molden sturla.mol...@gmail.com wrote:
  Guess where I'm going with this is... is there anything out there worth 
  trying - on Linux - that I'm missing?
 
 leafnode
 
That doesn't address the problem at all! :-)  You still need a news
reader.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python obfuscate

2014-04-11 Thread cl
Chris Angelico ros...@gmail.com wrote:
 On Fri, Apr 11, 2014 at 7:17 PM, Sturla Molden sturla.mol...@gmail.com 
 wrote:
  The only way to protect your code is never to ship anything.
 
 It's worth noting, as an aside, that this does NOT mean you don't
 produce or sell anything. You can keep your code secure by running it
 on a server and permitting users to access it; that's perfectly safe.
 
Perfectly?  :-)

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


How do I encode and decode this data to write to a file?

2013-04-29 Thread cl
I am debugging some code that creates a static HTML gallery from a
directory hierarchy full of images. It's this package:-
https://pypi.python.org/pypi/Gallery2.py/2.0


It's basically working and does pretty much what I want so I'm happy to
put some effort into it and fix things.

The problem I'm currently chasing is that it can't cope with directory
names that have accented characters in them, it fails when it tries to
write the HTML that creates the page with the thumbnails on.

The code that's failing is:-

raw = os.path.join(directory, self.getNameNoExtension()) + .html
file = open(raw, w)
file.write(.join(html).encode('utf-8'))
file.close()

The variable html is a list containing the lines of HTML to write to the
file.  It fails when it contains accented characters (an é in this
case).  Here's the traceback:-

Traceback (most recent call last):
  File /usr/local/lib/python2.7/dist-packages/gallery/galleries.py, line 41, 
in run self._recurse()
  File /usr/local/lib/python2.7/dist-packages/gallery/galleries.py, line 272, 
in _recurse os.path.walk(self.props[sourcedir], self.processDir, None)
  File /usr/lib/python2.7/posixpath.py, line 246, in walk walk(name, func, 
arg) File /usr/lib/python2.7/posixpath.py, line 246, in walk walk(name, func, 
arg)
  File /usr/lib/python2.7/posixpath.py, line 246, in walk walk(name, func, 
arg) File /usr/lib/python2.7/posixpath.py, line 238, in walk func(arg, top, 
names)
  File /usr/local/lib/python2.7/dist-packages/gallery/galleries.py, line 263, 
in processDir self.createGallery()
  File /usr/local/lib/python2.7/dist-packages/gallery/galleries.py, line 215, 
in createGallery self.picturemanager.createPictureHTMLs(self.footer)
  File /usr/local/lib/python2.7/dist-packages/gallery/picturemanager.py, line 
84, in createPictureHTMLs curPic.createPictureHTML(self.galleryDirectory, 
self.getStylesheet(), self.fullsize, footer)
  File /usr/local/lib/python2.7/dist-packages/gallery/picture.py, line 361, 
in createPictureHTML file.write(.join(html).encode('utf-8')) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 783: 
ordinal not in range(128)



If I understand correctly the encode() is saying that it can't
understand the data in the html because there's a character 0xc3 in it.
I *think* this means that the é is encoded in UTF-8 already in the
incoming data stream (should be as my system is wholly UTF-8 as far as I
know and I created the directory name).

So how do I change the code so I don't get the error?  Do I just
decode() the data first and then encode() it?

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I encode and decode this data to write to a file?

2013-04-29 Thread cl
Andrew Berg bahamutzero8...@gmail.com wrote:
 On 2013.04.29 04:47, c...@isbd.net wrote:
  If I understand correctly the encode() is saying that it can't
  understand the data in the html because there's a character 0xc3 in it.
  I *think* this means that the é is encoded in UTF-8 already in the
  incoming data stream (should be as my system is wholly UTF-8 as far as I
  know and I created the directory name).
 You can verify that your filesystem is set to use UTF-8 with 
 sys.getfilesystemencoding(). 
 If it returns 'ascii', then your locale settings 
 are incorrect.
 

chris$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 import sys
 sys.getfilesystemencoding()
'UTF-8'
 

So I am set up right for UTF-8.

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I encode and decode this data to write to a file?

2013-04-29 Thread cl
Dave Angel da...@davea.name wrote:
 On 04/29/2013 05:47 AM, c...@isbd.net wrote:
 
 A couple of generic comments:  your email program made a mess of the 
 traceback by appending each source line to the location information.
 
What's me email program got to do with it?  :-)   I'm using a dedicated
newsreader (tin) as I posted via the gmane/usenet interface.  The posting
looks perfectly OK to me when I read it back from usenet.


 Please mention your Python version  OS.  Apparently you're running 2.7 
 on Linux or similar.
 
Sorry, yes you're spot on.


  I am debugging some code that creates a static HTML gallery from a
  directory hierarchy full of images. It's this package:-
   https://pypi.python.org/pypi/Gallery2.py/2.0
 
 
  It's basically working and does pretty much what I want so I'm happy to
  put some effort into it and fix things.
 
  The problem I'm currently chasing is that it can't cope with directory
  names that have accented characters in them, it fails when it tries to
  write the HTML that creates the page with the thumbnails on.
 
  The code that's failing is:-
 
   raw = os.path.join(directory, self.getNameNoExtension()) + .html
   file = open(raw, w)
   file.write(.join(html).encode('utf-8'))
 
 You can't encode byte data, it's already encoded. So you're forcing the 
 Python system to implicitly decode it (using ASCII codec) before letting 
 you encode it to utf-8.  If you think it's already in utf-8, then omit 
 the encode() call there.
 
It's the way the code was as I installed it from pypi.  What you say
makes a lot of sense though, I'll remove the encode().


 Additionally, you can debug things with some simple print statements, at 
 least if you decompose your 3-function line so you can get at the 
 intermediate data.  Split the line into three parts;
  temp1 = .join(html) #temp1 is byte data
  temp2 = temp1.decode()#temp2 is unicode data
  temp3 = temp2.encode(utf-8)  #temp3 is byte data again
  file.write(temp3)
 
OK, thanks for this and all the other advice on this thread.

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I encode and decode this data to write to a file?

2013-04-29 Thread cl
Robert Kern robert.k...@gmail.com wrote:
 On 2013-04-29 13:59, c...@isbd.net wrote:
  Dave Angel da...@davea.name wrote:
  On 04/29/2013 05:47 AM, c...@isbd.net wrote:
 
  A couple of generic comments:  your email program made a mess of the
  traceback by appending each source line to the location information.
 
  What's me email program got to do with it?  :-)   I'm using a dedicated
  newsreader (tin) as I posted via the gmane/usenet interface.  The posting
  looks perfectly OK to me when I read it back from usenet.
 
 FWIW, I see the same problem Dave sees. I'm using gmane via Thunderbird.
 
How strange.  I think it must be something to do with the gmane
interface between news and mail then.

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it me or is the python-vobject documentation rather lacking?

2013-03-26 Thread cl
I'm trying to use the python vobject package instead of what I use at
the moment (the icalendar package) because it's more widely supported
and available from my Linux repository.

However I'm having a really hard time actually working out how to use
it. The 'Usage examples' at http://vobject.skyhouseconsulting.com/usage.html
have very little about parsing existing .ics files and say More
examples can be found in source code doctests.  I can't find those
examples at all.  The only test code I can see comprises direct data
entry using the python interpreter directly and is just a mess.

I can open a .ics file and vobject parses it:-

 f = open(orage.ics)
 p = vobject.readOne(f)
 p.vevent.dtstart.value
datetime.date(2012, 3, 16)

... but then I need to know how to iterate through the .ics file and how
to get all the other fields out of an event entry.

Can anyone point me at some examples that do something rather more
extensive than the above example?

Alternatively where do I find how to extract other fields from a vevent
as values like vevent.dtstart.value?  These don't seem to be documented
anywhere obvious in http://vobject.skyhouseconsulting.com/epydoc/.


-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


I need a neat way to print nothing or a number

2013-03-26 Thread cl
What's a neat way to print columns of numbers with blanks where a number
is zero or None?

E.g. I want to output something like:-

Credit  Debit   Description
100.00  Initial balance
123.45  Payment for cabbages
202.00  Telephone bill


For each line I have either the credit or the debit amount and the other
is 0 or None.  However you can't get number formatting (old or new) to
output a blank for 0 and it barfs on None.

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tyrton ERP 1.0 released

2008-11-20 Thread CL (Ciu Loeng) Lam
HiCould the trython use the Oracle instead of the default postgresql ?

2008/11/19 erp software [EMAIL PROTECTED]

 On Nov 18, 3:26 pm, Hartmut Goebel [EMAIL PROTECTED] wrote:
  On behalf of the Tryton team I'm proud to announce Tryton 1.0,
  an Open Source application platform and ERP. It provides modularity,
  scalability and security.
 
  This is the first release of Tryton, a fork of OpenERP (formally known
  as TinyERP). This release is the result of 8 months of intensive work
  which consist of the rewrite of all modules (including contact, sale,
  purchase, invoice, analytic and general account and inventory
  management) and some parts of the core features. It is available in four
  languages (English, French, German and Spanish).
 
  :Homepage:http://www.tryton.org/
  :Downloads:  http://www.tryton.org/downloads.html
  :Screenshots:http://www.tryton.org/screenshots.html
 
  Tryton is aspire to be a strong community-driven project. We are looking
  for contributors for translations, documentations and testings as long
  as business expertise and user feedbacks.
 
  What is Tryton?
  
  Tryton is a three-tiers high-level general purpose application platform
  under the license GPL-3 written in Python and use Postgresql as database
  engine. It is the core base of an Open Source ERP. It provides
  modularity, scalability and security.
 
  The target audience is the small and medium enterprises who are
  looking for a highly customizable and easy to use application platform
  and ERP. Tryton provides the ability to organizations to let their
  solution grow with their needs.
 
  Tryton Core
  --
  The core of Tryton (also called Tryton kernel) provide all the necessary
  functionalities for a complete application framework: data persistence
  (i.e an ORM with extensive modularity), users management
  (authentication, fine grained control for data access, handling of
  concurrent access of resources), workflow and report engines, web
  services and internationalization. Thus constituting a complete
  application platform which can be used for any relevant purpose.
 
  Base Modules
  -
  Currently, the main modules available for Tryton cover the following
  fields of activity:
 
   * Accounting
   * Invoicing
   * Sale Management
   * Purchase Management
   * Analytic Accounting
   * Inventory Management
 
  They establish a sane base and an easy to use abstraction of some of the
  key concepts for every business customization.

 Good! inform the same information to http://www.open-source-erp-site.com,
 so that more people will get to know about it.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Problem on getting date column in SQLObject

2008-09-11 Thread CL (Ciu Loeng) Lam
Hi,all:I make the SQLObject as the ORM in turbogears ,now I meet a problems
on selecting records for a given date . Here is the define for my class:
class updateHistory(SQLObject):
actionTime =  DateTimeCol(default=datetime.now)
actionContent = UnicodeCol(length=500,default=)

Then how can I  get the records during a special time ,for example , from
2008-05-10 to 2008-09-01,
It will be very thankful if someone could paste some snippets for this
problems.
Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list

Turbogear installing error.

2008-07-14 Thread CL (Ciu Loeng) Lam
HI,there:
I get the errors below when installing the Turebogear,could anyone help me ?
Thanks in advance.

error: Not a recognized archive type: c:\docume~1\admini~1\locals~1\
temp\easy_in
stall-y2znne\PasteScript-1.6.3.tar.gz
--
http://mail.python.org/mailman/listinfo/python-list