Re: GUI (tkinter) popularity and job prospects for

2020-10-23 Thread John Pote



On 23/10/2020 05:47, Grant Edwards wrote:



I think that commercial desktop applications with a python
compatible GUI would likely use QT or a Python binding thereof.

Agreed. If you want to improve you "hirability" for GUI application
development, I would probably put Qt first.  Then gobject or
wx. Tkinter would probably be last.


I've used tkinter and wxPython occasionally in the past for 1 off test 
tasks (and interest). What's the advantage of Qt?


John

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


Re: Multiple comparisons in a single statement

2020-03-12 Thread John Pote


On 12/03/2020 18:08, Chris Angelico wrote:

On Fri, Mar 13, 2020 at 4:55 AM Stephen Tucker  wrote:

A quickie (I hope!).

I am running Python 2.7.10 (and, yes, I know, support for it has been
withdrawn.)

This is the same in Python 3.


I have three tuples that have been generated separately and I want to check
that they are identical. all I want to do is to terminate the program and
report an error if all three are not identical.

My initial attempt to do this is to use logic of the form

if not (mytup1 == mytup2 == mytup3):
raise Exception ("Tuples are not identical")

I have tried this logic form in IDLE, and it seems to do what I want.

Is this a reasonable way to do this, or is there a better way?


Yes absolutely! (Although, as a minor quibble, I would say "equal"
rather than "identical" here - when you talk about identity, you're
usually using the 'is' operator.) The meaning of chained comparisons
is broadly equivalent to comparing the middle one against the others
("a==b==c" is "a==b and b==c"), which does the right thing here.

It's slightly unusual to negate a query rather than using "!=", but it
makes good sense here.


In case anyone thinks the original expr
 not (mytup1 == mytup2 == mytup3)
could be changed to
 (mytup1 != mytup2!= mytup3)
remember that applying De Morgan's theorem to the original expression 
would require the 'and' operation used in chained comparisons to change 
to an 'or' operation (Python always does the 'and' operation in chained 
comparisions). EG for simple integers instead of tuples,


>>> not (1==1==1)
False
>>> not (2==1==1)
True
>>> (1!=1!=1)
False  correct as before
>>> (2!=1!=1)
False  oops!

John



ChrisA

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


Re: Odd truth result with in and ==

2018-11-23 Thread John Pote

On 21/11/2018 19:18, Python wrote:

$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

1 in [1,2,3] == True

False

1 in ([1,2,3] == True)

Traceback (most recent call last):
   File "", line 1, in 
TypeError: argument of type 'bool' is not iterable

(1 in [1,2,3]) == True

True

How is the first not equivalent to either one of the second or third?
My expectation is it should produce the same result as the second.  It
*seems* like Python is ignoring the '1 in' part and just giving the
result for '[1,2,3] == True'...  Is this just a bug?

I've followed this thread with interest, as I do with threads like this, 
and learnt a useful detail about Python.


But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box)

>>> if []: print("Truthy")
...
>>> if [1,2,3]: print("Truthy")
...
Truthy
>>>

from which I concluded [] is Falsey and [1,2,3] is Truthy and the above 
if statements work as expected.


but,

>>> [1,2,3] == True
False
>>>

is unexpected as to my mind as [1,2,3] is 'Truthy' and True has ultimate 
'Truthiness'.


Any ideas? Is there an implicit 'casting' taking place and if so is this 
documented somewhere?


I interpret the above comparison as

>>> bool([1,2,3]) == bool(True)
True
>>>

Thanks everyone.



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


Re: regex pattern to extract repeating groups

2018-08-27 Thread John Pote

On 26/08/2018 00:55, Malcolm wrote:
I am trying to understand why regex is not extracting all of the 
characters between two delimiters.


The complete string is the xmp IFD data extracted from a .CR2 image file.

I do have a work around, but it's messy and possibly not future proof.
Do you mean future proof your workaround or Cannon's .CR2 raw image 
files might change? I guess .CR2's won't change but Cannon have brought 
out the new .CR3 raw image file for which I needed to upgrade my photo 
editing suit (at least I didn't but used their tool to convert .CR3s 
from the camera to the digital negative format which many photo editors 
can handle.) Can send you sample .CR3 if you want to compare.


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


Re: curses, ncurses or something else

2018-07-25 Thread John Pote

On 24/07/2018 16:13, Peter Pearson wrote:

On Mon, 23 Jul 2018 23:24:18 +0100, John Pote wrote:

I recently wrote a command line app to take a stream of numbers, do some
signal processing on them and display the results on the console. There
may be several output columns of data so a title line is printed first.
But the stream of numbers may be several hundred long and the title line
disappears of the top on the console.

So I thought it might be quick and easy to do something with curses to
keep the title line visable while the numbers roll up the screen. But
alas I'm a Windows user and the 'curses' module is not in the Windows
standard library for Python.

It occured to me that I could create a simple tkinter class but I
haven't tinkered for some time and would have to refresh my knowledge of
the API. Just wondered if there was any other simple way I could keep
the title line on the console, preferably without having to install
another library.

Browsergui is designed to simplify GUI-building by mooching off your web
browser.  I like it.

sudo pip3 install browsergui
python3 -m browsergui.examples

Enjoy!

Thanks everyone for the helpful replies. All were good ideas and I'll 
follow up on them as personal time permits. Work is a pain at the moment 
AND without any Pythoning.


Best wishes to all.
--
https://mail.python.org/mailman/listinfo/python-list


curses, ncurses or something else

2018-07-23 Thread John Pote
I recently wrote a command line app to take a stream of numbers, do some 
signal processing on them and display the results on the console. There 
may be several output columns of data so a title line is printed first. 
But the stream of numbers may be several hundred long and the title line 
disappears of the top on the console.


So I thought it might be quick and easy to do something with curses to 
keep the title line visable while the numbers roll up the screen. But 
alas I'm a Windows user and the 'curses' module is not in the Windows 
standard library for Python.


It occured to me that I could create a simple tkinter class but I 
haven't tinkered for some time and would have to refresh my knowledge of 
the API. Just wondered if there was any other simple way I could keep 
the title line on the console, preferably without having to install 
another library.


Ideas invited.


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


Re: csv module and NULL data byte

2018-03-07 Thread John Pote

On 07/03/2018 07:59, Andrew McNamara wrote:

Last time I read the documentation, it was recommended that
the file be opened in BINARY mode ("rb").

It recommends binary mode, but seems to largely work fine with
text/ascii mode or even arbitrary iterables.  I've not seen the
rationale behind the binary recommendation, but in 10+ years of using
the csv module, I've not found any issues in using text/ascii mode
that were solved by switching to using binary mode.

The CSV module was originally written by Dave Cole. I subsequently
made changes necessary to get it included a standard part of Python.
I also implemented the "dialect" logic, and I put a lot of time into
making the parser and generator produce the same results as Excel.

That particular recommendation is necessary because Excel has some
particular behaviours around CR and LF and quoting. For the parser to
produce the same result as Excel, it must see the raw bytes with no
re-ordering or suppression of CRs.

Unfortunately, I haven't had time to be involved in the module for a few
years. I wasn't involved with the Unicode changes necessary in Python 3,
and I have not verified that it is still compatible with recent versions
of Excel.
Any idea why it might throw an exception on encountering a NULL in the 
input stream? It accepts all other 255 byte values. Was this behaviour 
intended? Perhaps a comment should be added to the docs.

Thanks for your work on the module anyway.

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


Re: csv module and NULL data byte

2018-03-01 Thread John Pote

On 01/03/2018 01:35, Tim Chase wrote:

While inelegant, I've "solved" this with a wrapper/generator

   f = file(fname, …)
   g = (line.replace('\0', '') for line in f)
I wondered about something like this but thought if there's a way of 
avoiding the extra step it would keep the execution speed up.
My next thought was to pass a custom encoder to the open() that 
translates NULLs to, say, 0x01. It won't make any difference to change 
one corrupt value to a different corrupt value.

   reader = csv.reader(g, …)
   for row in reader:
 process(row)


Regards,
John

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


Re: csv module and NULL data byte

2018-03-01 Thread John Pote

On 01/03/2018 02:38, Dennis Lee Bieber wrote:

On Wed, 28 Feb 2018 23:40:41 +, John Pote 
declaimed the following:



     with open( fname, 'rt', encoding='iso-8859-1' ) as csvfile:

Pardon? Has the CSV module changed in the last year or so?
Python 3.6 docs say csv reader has to be given an iterator that supplies 
strings. That requires the file to be opened 'rt' mode as 'rb' returns 
bytes objects and the csv reader throws an exception. I did a test to 
check and with the encoding='iso-8859-1' the file obj does pass through 
all 256 possible byte values without exception.
Interesting point - how are the 'bytes' from the file translated to 
Python's unicode strings.

Only doing this for 3.6 so have not checked 2.7 docs.


Last time I read the documentation, it was recommended that the file be
opened in BINARY mode ("rb").

Using the 'rb' mode results in the helpful exception,
    >>python36 csvTest.py
    Traceback (most recent call last):
      File "csvTest.py", line 25, in 
        data = list( csvreader )
    _csv.Error: iterator should return strings, not bytes (did you open 
the file in text mode?)


Good point so thanks anyway,
John
--
https://mail.python.org/mailman/listinfo/python-list


csv module and NULL data byte

2018-02-28 Thread John Pote
I have a csv data file that may become corrupted (already happened) 
resulting in a NULL byte appearing in the file. The NULL byte causes an 
_csv.Error exception.


I'd rather like the csv reader to return csv lines as best it can and 
subsequent processing of each comma separated field deal with illegal 
bytes. That way as many lines from the file may be processed and the 
corrupted ones simply dumped.


Is there a way of getting the csv reader to accept all 256 possible 
bytes. (with \r,\n and ',' bytes delimiting lines and fields).


My test code is,

    with open( fname, 'rt', encoding='iso-8859-1' ) as csvfile:
        csvreader = csv.reader(csvfile, delimiter=',', 
quoting=csv.QUOTE_NONE, strict=False )

            data = list( csvreader )
            for ln in data:
                print( ln )

Result

>>python36 csvTest.py
Traceback (most recent call last):
  File "csvTest.py", line 22, in 
    data = list( csvreader )
_csv.Error: line contains NULL byte

strict=False or True makes no difference.

Help appreciated,

John

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


Re: async serial port in Python.

2017-12-18 Thread John Pote



On 18/12/2017 23:20, Les Cargill wrote:


What I'd like to do is set up *some* sort of method in Python to
asynchronously use callbacks to receive characters from a serial port
or 20 serial ports.

If I have to hook an event loop or even spawn a thread - fine! but it
needs to allow for making things event-driven. For lack of a better
term, I'd like this to at least have "select()/epoll() semantics".

And then I'd like to extend that to TCP and UDP ports.

Is this even possible? I keep running into "not done yet"
stuff on this front, but I'm not very up on Python. It may
be ... what's the term ... ? ... un-Pythonic, and I would accept
that as an explanation.


And no, I do not have a pet distro or version of Python. Any is fine
with me.
I've use Chris Liechti's pySerial very successfully several times on 
Python 2.7 and earlier and just a test with 3.6. Easy enough to access 
it from Python threads. I'm stuck with Windoze so have used COMx: port 
access to both PC native serial port (I have old kit) and USB virtual 
serial ports. No idea about xNix.




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


Re: f-string

2017-12-08 Thread John Pote

On 06/12/2017 00:16, Steve D'Aprano wrote:
> Anyone got a handy copy of Python 3.6 available to test something for me?
>
> What does compile('f"{spam} {eggs}"', '', 'single') return?
>
> What does eval()'ing the above compiled object do? If necessary, you may have
> to define spam and eggs first.
>
>
> Thanks in advance.
>
>
rslt = compile('f"{spam} {eggs}"', '', 'single')

print( rslt )
print( "\n" )

spam = "SPAM"
eggs = "scrambled"
eRslt = eval( 'f"{spam} {eggs}"' )
print( eRslt )

Ran above test file and got,
 >>python36 compiletest.py
 at 0x02120E40, file "", line 1>


SPAM scrambled
 >>

Py version on Win 7 box
Python 3.6.3 (v3.6.3:2c5fed8, Octâ  3 2017, 18:11:49) [MSC v.1900 64 bit
(AMD64)] on win32

Any help?
John

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


Re: f-string

2017-12-05 Thread John Pote


On 06/12/2017 00:16, Steve D'Aprano wrote:

Anyone got a handy copy of Python 3.6 available to test something for me?

What does compile('f"{spam} {eggs}"', '', 'single') return?

What does eval()'ing the above compiled object do? If necessary, you may have
to define spam and eggs first.


Thanks in advance.



rslt = compile('f"{spam} {eggs}"', '', 'single')

print( rslt )
print( "\n" )

spam = "SPAM"
eggs = "scrambled"
eRslt = eval( 'f"{spam} {eggs}"' )
print( eRslt )

Ran above test file and got,
>>python36 compiletest.py
 at 0x02120E40, file "", line 1>


SPAM scrambled
>>

Py version on Win 7 box
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit 
(AMD64)] on win32


Any help?
John
--
https://mail.python.org/mailman/listinfo/python-list


How to shut down a TCPServer serve_forever() loop?

2017-11-25 Thread John Pote

Hi all,

My problem in summary is that my use of the shutdown() method only shuts 
down a server after the next TCP request is received.


I have a TCP server created in the run() method of a thread.

    class TCPlistener( Thread ):
        def run( self ):
       with socketserver.TCPServer(  ("localhost", ), 
ConnHandler ) as server:

                self.server = server
                print( "TCP listener on: %s:%d" % ( self.host, 
self.port ) )

                self.server.serve_forever()

                print( "TCPlistener:run() ending" )

ConnHandler is a simple echo class with only a handle() method

The main bit of the program is

    if __name__ == "__main__":
        serverThrd = TCPlistener()
        serverThrd.start()            #start TCP IP server listening
        print("server started")

        ch = getche()                    #wait for key press
        print()
        serverThrd.server.shutdown()

        print( "main ending" )

Everying works as expected, numerous connections can be made and the 
received text is echoed back.


The issue is that if I press a key on the keyboard the key is 
immediately shown on the screen but then the shutdown() call blocks 
until another TCP connection is made, text is echoed back and only then 
does serve_forever()return followed by shutdown()returning as can be 
seen from the console session,


>>python36 TCPIPserver.py
server started
TCP listener on: localhost:
q #pressed 'q' key
127.0.0.1 wrote: #Sent some text from PuTTY
b'SOME TEXT'
TCPlistener:run() ending
main ending

How can I get shutdown()to shut down the server immediately without 
waiting for the next TCP connection?


Regards,

JOhn

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


Easiest way to access C module in Python

2017-11-06 Thread John Pote

Hi all,
I have successfully used Python to perform unit and integration tests in 
the past and I'd like to do the same for some C modules I'm working with 
at work. There seem to be a number of ways of doing this but being busy 
at work and home I looking for the approach with the least learning curve.


I don't want to add the C modules into the CPython build itself as I've 
never done this and at work it's a real pain getting admin rights to do 
this, and when you do it lasts just 24 hours. The C modules are likely 
to change frequently as bugs are found and features added.


The other option I'm considering is to use sockets and write a C wrapper 
round the C modules I want to test. This has the advantage for me that I 
know about sockets from Python & C points of view and I get complete 
control of the C compile process. This may be important as the C modules 
come from an embedded project and I don't want to change them in any way.


Are there any other approachs to this problem?
I'll be using Python 3.5 (work) and 3.6 (home).
Feedback appriciated.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Old Man Yells At Cloud

2017-09-16 Thread John Pote



On 16/09/2017 19:00, Stefan Ram wrote:

Steve D'Aprano  writes:

"Hi, I've been programming in Python for what seems like days now, and here's
all the things that you guys are doing wrong.

   I never ever have written a line of Python 2. I started with
   Python 3.6.0. Yet a very frequent mistake of mine is the
   imission of parentheses after »print«.

   WRT my other common errors, It thought of writing
   a program that autocorrects my source code as follows:

   Whenever the next line is indented more, add a colon:

abd def ghi
 jkl mno pqr
I've used Komodo in the past and that editor works other way round, type 
a ':' at the end of a line and the next line is indented. I would 
presume other language aware editors take the same approach.

print """
Your idea would require considerable inteligence in the editor,
1. Otherwise the previous line would print with a ':'
2. That would frustrate me.
"""


->

abd def ghi:
 jkl mno pqr

   Whenever the next line is indented more, add "def" to
   what looks like a call (and does not start with »class«
   or »def«;

f( x ):
 return x * x

->

def f( x ):
 return x * x

   Whenever a line starts with "print" and no parentheses
   are following, add them:

print x, 2
Strangely I find it irksome to have to write print as a function call in 
Python 3. Must reflect those long ago days when I started to program 
(oops, I mean code - programming came later). Come to think of it 
there's something irksome about every language I've ever used. Python 
probably the least.


->
  
print( x, 2 )


   Implementing algorithms from "The Art of Computer
   Programming" might sometimes be difficult in Python, since
   those algorithms IIRC often use »goto«.
Good point. I also have a copy of that work of art (and the fascicles - 
I must get out more). Sadly little work these days requires diving into 
them. In fairness to Knuth his pseudo code is a high level assembler 
fully described in Vol:1 and done as such so folk from any high level 
language background could follow the algorithms. Back then many like 
myself, or indeed most coders, had a hardware background and well used 
to assembler. The nearest thing most silicon has to structured 
programming is call and return, gotos are everywhere.
I always think one of the reasons Basic became so popular was its /goto 
/statement. The other was the run command, no need to compile.
See /http://entrian.com/goto// for a Python implementation from many 
years ago. No idea if it still works. To be honist never needed it - 
Python has exceptions.
Also there was a interesting thread '/"Goto" statement in Python/' in 
April this year (not the 1st).  Although mainly interesting for its 
references to gotos in 'C' which I use daily now. err 'C' that is. . . . 
. .
Used to wind up colleagues by saying loudly "Great, I can use a /*goto 
*/here.". This attracted considerable verbal abuse from purists in 
earshot and instruction from the boss NOT TO which I pretended to 
ignore. After all Python programming is supposed to be fun!






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


Re: Mapping with continguous ranges of keys

2016-12-16 Thread John Pote


On 16/12/2016 14:27, Steve D'Aprano wrote:

(2) The clever solution: use a pair of lists, one holding the starting value
of each group of keys, and the other holding the common values. This saves
a lot of memory, but is slower.

A concrete example might help. Suppose I have 15 keys in five groups:

D = {0: 10,
  1: 20, 2: 20,
  3: 30, 4: 30, 5: 30,
  6: 40, 7: 40, 8: 40, 9: 40,
  10: 50, 11: 50, 12: 50, 13: 50, 14: 50}

(Remember, in reality I could have as many as a million or two keys. This is
just a simple toy example.)

Instead of using a dict, I also set up a pair of lists:

L = [0, 1, 3, 6, 10, 15]  # starting value of each group
V = [10, 20, 30, 40, 50]  # value associated with each group
I misread the problem (skipped the comment about keys 4 - 99) and 
assumed there might be gaps between the contiguous blocks so thought of 
the list structure

[  ( (firstKeyN, lastKeyN), "value" ),
...
]
At the cost of more memory keeping first and last keys numbers in tuples 
in the L list would mean there is only one L lookup at the expence of 
two additional tuple lookups. Are small tuple lookups quicker than 1 
large list lookup? If not stick with the simple L and V you show above.


I've never used any form of tree structure, perhaps someone else could 
comment of the performance of balanced trees as compared to simple 
lists. Would the insertion cost be too high in keeping the tree balanced?


As to speeding up access with only L and V lists the binary search must 
be optimal unless specialised knowledge about the distribution of the 
size of the contiguous groups is made use of. But you say there is no 
pattern to the group sizes.


Other thought is to have a smaller pre-index list, search this to find 
the range of L indexes the key is in. If the pre-index list had a 1000 
entries then each entry would cover 1/1000 of the L list which narrows 
the binary search space in L considerably. The cost of something like 
this is keeping the pre-index list up to date when new keys are added 
and extra time to code and test it.

preList struct [ (firstKeyN, lastKeyN), (firstLindex, lastLindex),
...
  ]

Reminds me of Jackson's first two rules on optimisation, 1 - don't do 
it, 2 - don't do it yet

Thanks for an interesting problem.

Note that the first list has one extra item, namely the number one past the
final group.

I can do a key look-up using either of these:

 D[key]

 V[bisect.bisect_right(L, i) - 1]


I tested the memory consumption and speed of these two solutions with
(approximately) one million keys. I found:

- the dict solution uses a lot more memory, about 24 bytes per key, compared
to the pair of lists solution, which is about 0.3 bytes per key;

- but on my computer, dict lookups are about 3-4 times faster.


Any suggestions for improving the speed of the binary search version, or the
memory consumption of the dict?

By the way: the particular pattern of groups in the sample code (groups of
size 1, 2, 3, ... up to 50, then repeating from 1, 2, 3, ... again) is just
demo. In my real data, the sizes of the groups are all over the place, in
an unpredictable pattern.



Thanks in advance.




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


Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-25 Thread John Pote
If you are on a windows platform you could use kbhit() from the msvcrt 
module as Steven D does in his solution on the activestate site which 
also works for xNIX. Worth a look at his code to see how these sort of 
things are done on xNIX.


Alternatively you could use a couple of threads. One for your worker 
code and one for the keyboard entry code. Use a message queue to pass 
received lines from the keyboard thread to the worker thread. OK you 
still have to press Enter but you don't need the windows msvcrt library 
or xNIX termios modules.


Regards

John


On 25/10/2016 07:39, Steven D'Aprano wrote:

On Tuesday 25 October 2016 05:14, jlada...@itu.edu wrote:


After reading this rather vague thread...

https://groups.google.com/forum/#!topic/comp.lang.python/FVnTe2i0UTY

... I find myself asking why Python doesn't include a standard, non-blocking
keyboard input function.  I have often wanted one myself.  The only way that
I've ever achieved this behavior is:

1) by restricting the user to pressing Ctrl-C while the program is running,
and catching a KeyboardInterrupt; or

2) loading a heavyweight GUI like wxPython or PyQt, and using its event loop
to intercept keyboard events.

I gather that non-blocking keyboard input functions aren't the easiest thing
to implement.  They seem to depend on the operating system.  Still, ease of
use is a primary goal of Python, and the need for this feature must be
common.


Not really. I think that lots of people think they need it, but once they write
a little utility, they often realise that it's not that useful. That's just my
opinion, and I'm one of those guys who wrote one:

http://code.activestate.com/recipes/577977-get-single-keypress/?in=user-4172944

Me and ten thousand others.

If you (generic you, not you specifically) are telling the user "press any key
to continue", then you probably shouldn't. *Any* key may not do anything. E.g.
if the user hits the Shift key. A much better interface is to specify a
specific key, and ignore anything else... in which case, why not specify the
Enter key?

raw_input('Press the Enter key to continue... ')


If you are doing something more complex, waiting on different keys to do
different things, then you probably should use an existing text UI like Curses,
or a GUI like wxPython etc, rather than trying to reinvent the wheel badly.





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


Re: get the sum of differences between integers in a list

2016-09-20 Thread John Pote

On 20/09/2016 12:52, Daiyue Weng wrote:


Hi, I have a list numbers say,

[1,2,3,4,6,8,9,10,11]

First, I want to calculate the sum of the differences between the numbers
in the list.
At least for this first part a little pencil, paper and algebra yields a 
simple formula of constant and minimal calculation time. I had an 
intuitive guess and wrote down the sum of differences for a couple of 
examples,

[1, 2, 5]   => 4
[9, 11, 17, 19] => 10
It works for negative differences as well,
[1, 2, 5, 1]=> 0
The trick is to spot the relation between the sum of differences and the 
numbers in the list. A few lines of algebra then gave a very simple formula.


As for the rest it's down to code as others have hinted at.

Second, if a sequence of numbers having a difference of 1, put them in a
list, i.e. there are two such lists,

[1,2,3]

[8,9,10,11]

and also put the rest numbers in another list, i.e. there is only one such
list in the example,

[6].

Third, get the lists with the max/min sizes from above, i.e. in this
example, the max list is,

[8,9,10,11]

min list is

[1,2,3].

What's the best way to implement this?

cheers


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


Re: Sharing package data across files

2016-06-28 Thread John Pote



On 28/06/2016 20:55, zackba...@gmail.com wrote:

On Tuesday, June 28, 2016 at 1:17:23 PM UTC-6, scott...@gmail.com wrote:

I'm trying to create a package in which the constituent files share some state. 
 Apparently, I don't understand scopes, namespaces, and package semantics as 
well as I thought I did.  Here's the directory structure for a simplified 
example:

example/
  __init__.py
  vars.py
  funcs.py

vars.py defines a single variable:

 foo = 123

funcs.py defines a function that reads and writes that variable:

 def bar():
 global foo
 foo += 1
 return foo

__init__.py exposes both of those to the caller:

 from vars import foo
 from funcs import bar

Alas, it seems the bar function does not reside in the same global scope as the 
foo variable:

 >>> from example import foo, bar
 >>> foo
 123
 >>> bar()
 Traceback (most recent call last):
   File "", line 1, in 
   File "example/funcs.py", line 3, in bar
 foo += 1
 NameError: global name 'foo' is not defined

How can I make the example package work like one integrated module even though 
in reality it's split across multiple files?

Thanks,
-- Scott

This problem of references is addressed in:
http://stackoverflow.com/questions/710551/import-module-or-from-module-import

>From Michael Ray Lovett:
For example, if I do this in module a:

from foo import bar
bar = "oranges"

No code outside of a will see bar as "oranges" because my setting of bar merely affected the name 
"bar" inside module a, it did not "reach into" the foo module object and update its "bar".
Correct me if I'm wrong but is not the above only true if bar has been 
assigned to and thus references an imutable object? In your example the 
string "oranges".
If bar has been assigned to a mutable object in module foo then every 
module importing via "from foo import bar" will all import the name bar 
pointing to the same mutable object. If this mutable obj is changed via 
bar in one module then every other module importing bar will also see 
the change.

eg
In module foo:
bar = ["apples","bananas","grapes"]

In module bar1
from foo import bar
bar[0] = "oranges"

In module barx at some later time
from foo import bar
...
print bar#prints ["oranges","bananas","grapes"]

If my understanding here is correct then this would be a good case for 
never directly writing to a globle. Use getter()s and setter()s to make 
it obvious that any use of the setter() will be seen by all future calls 
to the getter().


Regards all,
John


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


Re: Recommendation for GUI lib?

2016-06-04 Thread John Pote

On 02/06/2016 22:57, Dietmar Schwertberger wrote:


On 02.06.2016 12:35, John Pote wrote:
I've used wxPython (www.wxpython.org) for a few GUI projects and 
found it ok. It's a wrapper for the wxWidgets C++ library. There's 
even a reasonable free GUI builder, wxGlade, which I use as I prefer 
constructing GUI's that way rather than writing raw wxPython code. 
Never tried any of the paid for GUI builders.
Disadvantage is the download page only provides builds for Python 2.6 
or 2.7.


Does anyone know how Project Phoenix is coming on? 
http://wxpython.org/Phoenix/ItsAlive/ shows wxPython working with 
Python 3.2.

Comments on how stable it is and how easy to install would be helpful.
I have been using Phoenix now for half a year and are very happy with 
it. A release is on its way. For most platforms there are snapshot 
builds which are easy to install.


See e.g. 
https://groups.google.com/d/msg/wxpython-users/soHFLOrerVs/MSijBTQ6KAAJ



The snapshot installation does not include the demo and the .chm help 
file (yet?). These and the book I found to be the most helpful 
resources (much more usable than online reference documentation as 
e.g. with Qt).



I think that wxGlade is the most promising Python GUI builder and I'm 
confident that it will see improvements to increase usability. I have 
tried some others from time to time, including also QtCreator, but 
none was really convincing.


Regards,

Dietmar

Qt and Qt Creator often come up in searches for Python GUI libraries. I 
need to decide weather to upgrade to wxPython.Phoenix and Python 3.5 (as 
soon as I upgrade to win 7!) or switch to Qt which I don't know at all. 
It would be interesting to hear your experiences of trying Qt and why 
you've stuck with wxPython in the end.


Thanks,
John

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


Re: Recommendation for GUI lib?

2016-06-02 Thread John Pote

On 01/06/2016 18:13, Jan Erik Moström wrote:

I want to write a few programs with a GUI but I don't want to use Tk. 
Instead I'm looking for some other library, I've tried to look around 
and also asked a few but I don't really know what to use.
I've used wxPython (www.wxpython.org) for a few GUI projects and found 
it ok. It's a wrapper for the wxWidgets C++ library. There's even a 
reasonable free GUI builder, wxGlade, which I use as I prefer 
constructing GUI's that way rather than writing raw wxPython code. Never 
tried any of the paid for GUI builders.
Disadvantage is the download page only provides builds for Python 2.6 or 
2.7.


Does anyone know how Project Phoenix is coming on? 
http://wxpython.org/Phoenix/ItsAlive/ shows wxPython working with Python 
3.2.

Comments on how stable it is and how easy to install would be helpful.
John


Do you have any recommendations? Primary platforms are OS X and Linux.

I, of course, want to have "standard" widgets but a "calendar 
view"/"date picker" is a plus.


= jem


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


Re: Serious error in int() function?

2016-04-15 Thread John Pote



On 15/04/2016 03:38, Christian Gollwitzer wrote:

Am 15.04.16 um 02:36 schrieb Dennis Lee Bieber:

I should also have said that the square root of integer squares with
between 15 and 30 decimal digits will only be correct if the square
numbers themselves are exactly representable in 53 bits.  So we can
expect failures for squares with 16 or more digits.


However, if a number with 31 or less digits is known to be the 
square of

an integer, the IEEE754 sqrt function will (I believe) give the correct
result.


How could it EXCEPT by having ~15 significant digits and an 
exponent --
since that is all the data that is provided by a double precision 
floating

point. That is, for example,


1000.0 * 1000.0

1e+30

import math
math.sqrt(1e30)

1000.0




only has ONE significant digit -- even though it has thirty 0s before 
the

decimal point.


As I was taught in school and university the number of significant 
digits are the number of digits written after the point, be that 
decinal, binary or any other base. But away from the world of 
mathematics and strict engineering we often refer to the number of 
significant digits as the number of digits that have significance in the 
value of the quantity being represented. eg a temperature or voltage.
For example we might say that a 10 bit analogue to digital converter 
has, in binary, 10 significant digits and in decimal approximately 3. 
What can be confusing here is that if readings from such a converter are 
writen down as whole numbers with a decimal point

1.0, 2.0 . 1023.0
then the readings are /shown /with 1 significant digit.
We could equally write them
1.00, 2.00 . 1023.00
and they are now shown to 2 significant digits. Of course these trailing 
0s are of no practical 'significance' as the ADC cannot affect them. 
Indeed it would not even output them.
So context is everything. Care needs to be taken in understanding the 
use of this term by writers and readers that the context is clear, are 
binary or decimal digits being refered to, are we using 'significant' 
digits in the strict mathematical/engineering sense or a more colloquial 
sense.

Then again we might write 1023.0 in an exponent form
0·1023.10^4( 0 point 1023 times 10 to the power 4)
in which case we would say the reading is shown to 4 significant digits

No, you need to count the significant digits in binary. 1e30 is not an 
even number in binary floating point.
How so? Whether or not an integer is odd or even has nothing to do with 
its representation in binary of decimal, floating point or integer. If 
you mean the mantissa is odd that may well be true. But the exponent may 
also shift the mantissa left by on1 place or more. In which case the 
value the floating point number is holding must be even. (it is 
multiplied by 2^n where n >= 1)

My Python 2.7.9 does this
>>> "%50.10f"%1e30
'119884624838656.00'
>>>
This indicates that 1e30 is not representable in Python's floating point 
representation.


John

Apfelkiste:AsynCA chris$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=2
10^30
11001001001011001001110011010100011001110100111011001010\
0100
sqrt(10^30)
1110001101011010100100110001101000

Still, the floating point arithmetic should round to the correct 
answer if both are converted to decimal.


Christian




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


Re: REMOVE ME

2016-04-11 Thread John Pote

On 10/04/2016 04:52, Chris Angelico wrote:

On Sun, Apr 10, 2016 at 1:46 PM, fan nie  wrote:

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

Sure. I presume you mean something like this:

class Thing:
 things = []
 def __init__(self):
 self.things.append(self)
 def __del__(self):
 # Remove me when I'm dead
 self.things.remove(self)

This ingenious technique guarantees that you never have dead objects
in your list, by having each object remove itself when it dies.

ChrisA
I'm not quite sure how tongue in cheek ChrisA's reply and the Thing 
class was but it did make me think and wonder if my understanding of 
Python lore was quite right. To my mind it looks like a Zombie or even 
Revenant class.


If all external references to an instance of Thing are deleted there is 
still the reference from the class list 'things []'. In which case will 
not this prevent the instance from being garbage collected and __del__() 
never called on the dead instance and its memory never released. But a 
memory dump could reveal the ghost of the instance. On the other hand a 
code wizard with the right lore could resurect the instance by getting 
the reference to it and bring it back to life -

revenant = Thing.things[x]

But then I notice 'things' is used as an instance attribute rather than 
a class attribute. All seems to be shrouded in a web of mystery


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


Evaluating error strings for 'unittest' assert methods.

2016-04-06 Thread John Pote
I have been writing a very useful test script using the standard Python 
'unittest' module. This works fine and has been a huge help in keeping 
the system I've been writing fully working even when I make changes that 
could break many features of the system. eg major rewrite of the 
interrupt routines. The target system in question is written in 'C' and 
runs on a 50p microcontroller at the end of a serial line.


I like each assert...() to output helpful information when things go 
wrong. So I have put in quite complicated code to generate the error 
string the assert() method uses only when things go wrong. The normal 
case, when everything is working, means that all these error strings are 
constructed only to be discarded immediately when the assert() detects 
the test result is correct and no exception is throw.


To my mind this seems a waste and adding unnecessary delays in the 
running of the whole test script.


So I was wondering if there was some convienient, Python, way of calling 
an assert() method so the error string is only evaluated/constructed if 
the assert() fails and throws an exception. For example,


self.assertEqual( (nBytes,expectedValues), (nBytesRd,valuesRead),
"""Unexpected reg value.
Expected values nBytes:%02x (%s)
"""%(nBytes,' '.join( [ "%04x"%v for v in expectedValues] )) +
"Read values nBytes:%02x (%s)"%(nBytesRd,' '.join( [ "%04x"%v for v 
in valuesRead] ))

)

Ideas invited, thanks everyone,
John
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to make Python interpreter a little more strict?

2016-03-26 Thread John Pote



On 26/03/2016 12:05, Chris Angelico wrote:

On Fri, Mar 25, 2016 at 11:06 PM, Aleksander Alekseev  wrote:

Recently I spend half an hour looking for a bug in code like this:

eax@fujitsu:~/temp$ cat ./t.py
#!/usr/bin/env python3

for x in range(0,5):
 if x % 2 == 0:
 next
 print(str(x))

eax@fujitsu:~/temp$ ./t.py
0
1
2
3
4

Is it possible to make python complain in this case? Or maybe solve
such an issue somehow else?

I think what you're looking for here is an acknowledgement that
evaluating the name "next" accomplishes nothing. That's not really
something the Python interpreter should be looking at (hey, you might
have good reason for doing that), but there are linters that can
detect this kind of dead code. Some of them tie into programmer's
editors, so you could get a nice little warning message right in the
window where you're typing your code. Look into some of the top-end
editors (free or commercial) and see what you think of them - they can
save you no end of time.

ChrisA

So intrigued by this question I tried the following
def fnc( n ):
print "fnc called with parameter '%d'" % n
return n

for i in range(0,5):
if i%2 == 0:
fnc
next
print i

and got the same result as the OP

D:\projects\python
>>python next.py
0
1
2
3
4
D:\projects\python
>>

A couple of tests showed that the only important thing about the name in 
the if clause is that it is known at runtime and then it is silently 
ignored.
However, if the name is not known/accessible at run time a 'NameError' 
is raised,

NameError: name 'mynewfn123' is not defined

On the other hand the following if clause
if i%2 == 0:
fncnext

results in a compiler error,
D:\projects\python
>>python next.py
  File "next.py", line 9
fnc next
   ^
SyntaxError: invalid syntax

This is all for Python 2.7.9. (Don't know about Python 3).

So I have sympathy with the OP, I would expect the compiler to pick this 
up - indeed it does so for two (or more ?) unused names on a single 
line. That is unless someone can give a useful use of this behaviour or 
is there something going on under the Python hood I'm not aware of?


It would be all to easy to write a series of lines just calling 
functions and forget the () on one of them. Not fun programming.
It's also a good reminder that the meaning of a keyword in language A is 
not necessarily the same in language B (ie 'next', Python)
So on this last point is this behaviour of Python defined somewhere in 
the docs?


Regards all,
John

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


Re: How to do integers to binary lists and back

2015-05-29 Thread John Pote



On 21/05/2015 23:31, MRAB wrote:

On 2015-05-21 23:20, John Pote wrote:

Hi everyone.
I recently had the problem of converting from an integer to its
representation as a list of binary bits, each bit being an integer 1 or
0, and vice versa. E.G.
0x53
becomes
[ 0, 1, 0, 1, 0, 0, 1, 1 ]

This I wanted to do for integers of many tens, if not hundreds, of bits.
Python very nicely expands integers to any size required, great feature.

Just wondered if there was a neat way of doing this without resorting to
a bit bashing loop.

Looking forward to some interesting answers,
John



I don't know how efficient you want it to be, but:

>>> number = 0x53
>>> bin(number)
'0b1010011'
>>> bin(number)[2 : ]
'1010011'
>>> list(map(int, bin(number)[2 : ]))
[1, 0, 1, 0, 0, 1, 1]

Thanks for the replies. Interesting that the offered solutions involve 
converting to a binary text string and then the individual chars back to 
ints. I had thought this would be a route to solve this problem but it 
seemed a bit 'heavy' hence I thought it worthwhile asking the question.


My solution to converting a list of 1s and 0s back to an int is
listLen = len( binList )
n = sum( [ binList[i]*( 2**(listLen-1 - i) ) for i in 
range(listLen)] )


In response to Ben Finney's question, I haven't done homework for 40 
years! Genuine problem, I had decided that the clearest way to write the 
algorithm I was working on was to use lists of 1s and 0s rather than 
normal ints.


Thanks for the help,
John
--
https://mail.python.org/mailman/listinfo/python-list


How to do integers to binary lists and back

2015-05-21 Thread John Pote

Hi everyone.
I recently had the problem of converting from an integer to its 
representation as a list of binary bits, each bit being an integer 1 or 
0, and vice versa. E.G.

0x53
becomes
[ 0, 1, 0, 1, 0, 0, 1, 1 ]

This I wanted to do for integers of many tens, if not hundreds, of bits. 
Python very nicely expands integers to any size required, great feature.


Just wondered if there was a neat way of doing this without resorting to 
a bit bashing loop.


Looking forward to some interesting answers,
John


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


Re: Enumerating loggers iin logging module

2015-01-03 Thread John Pote
Thanks for the replies, thought there'd be a simple answer. Much 
appreciated.

John

On 30/12/2014 22:40, Chris Angelico wrote:

On Wed, Dec 31, 2014 at 8:24 AM, Tim Chase
 wrote:

While it may involve reaching into the objects may or may not be
blessed, the following seems to work for me in Py2.7:

   >>> import logging
   >>> # add a bunch of loggers and sub-loggers
   >>> print logging.Logger.manager.loggerDict.keys()

Works in 3.5, too, aside from trivialities:

$ python3
Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

import logging
logging.getLogger("Name")



logging.getLogger("name.sublogger")



logging.Logger.manager.loggerDict

{'name.sublogger': , 'Name':
, 'name':
}

I'd say this is fine for debugging with.

ChrisA


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


Re: Talking to a 'C' program

2013-11-08 Thread John Pote
Thanks everyone for the advice, some good ideas to keep me busy. Will try and 
look at over weekend/next week as tied up the rest of today.

I've used pyserial several times  - many thanks to Chris Liechti for that module

Hm must be loosing it, forgot about stdin/out!

I've also used CUnit before and it's nice an easy and small. Problem is I've 
only 500 bytes code space left on the micro-controller so by the time CUnit 
gone in with the various tests I'm gonna run of room. I have to keep the RS232 
driver in as well as it's the only way to talk to the controller.

Python + pyserial enables me to run the tests with the C compiled and run on 
the PC as well as compiled to run on the micro-controller. Python is a great 
environment for doing this sort of thing and, as has been mentioned, a GUI can 
be added easily (time permitting).

Thanks again all,
John
 
On 8 Nov 2013, at 15:00, Grant Edwards  wrote:

> On 2013-11-08, John Pote  wrote:
>> Hi all,
>> 
>> I have the task of testing some embedded 'C' code for a small
>> micro-controller. Thought it would be a good idea to test it on the
>> PC first to make sure the algorithm is correct then perhaps test it
>> on the controller via RS232 and an appropriate wrapper round the 'C'
>> functions.
>> 
>> On the PC I can use Python's unit test library module and logging to
>> create a nice and easy to use environment (I like Python). So my
>> question is how to communicate from Python to the C module on the PC.
>> What I'd like is simplicity and ease of setting up. All I can think
>> of myself is to use sockets.
> 
> Sockets are nice and simple.  Depending on what you're doing,
> stdin/stdout may be even simpler.
> 
> For the RS232 part of the problem, don't forget about pyserial:
> 
>  http://pyserial.sourceforge.net/pyserial.html
> 
>> Any ideas on how to do this would be gratefully appreciated.
>> 
>> Also as I don't have any microsoft offerings of a C compiler any
>> suggestions as to a suitable C compiler for a PC appreciated as well.
>> llvm? mingw? gcc?
> 
> I've occasionaly used mingw (which _is_ gcc), and it worked well.
> Cygwin (also gcc) works well, but it's a bit more involved.
> 
> I do all my embedded development on a Linux host.  I find Linux to be
> far more suitable for the task -- the entire Unix system basically
> evolved as a software development platform.  I've yet to figure out
> what MS-Windows is suited for other than lining Bill Gates' pockets.
> 
> Before Linux, I used Solaris/SunOS, and before that I used Unix V7.
> Everytime I've been involved in a Microsoft-hosted embedded
> development project, I just end up walking a way afterwards shaking my
> head in puzzlement.
> 
> -- 
> Grant Edwards   grant.b.edwardsYow! I'm having a
>  at   tax-deductible experience!
>  gmail.comI need an energy crunch!!
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Talking to a 'C' program

2013-11-08 Thread John Pote
Hi all,

I have the task of testing some embedded 'C' code for a small micro-controller. 
Thought it would be a good idea to test it on the PC first to make sure the 
algorithm is correct then perhaps test it on the controller via RS232 and an 
appropriate wrapper round the 'C' functions.

On the PC I can use Python's unit test library module and logging to create a 
nice and easy to use environment (I like Python). So my question is how to 
communicate from Python to the C module on the PC. What I'd like is simplicity 
and ease of setting up. All I can think of myself is to use sockets.

Any ideas on how to do this would be gratefully appreciated.

Also as I don't have any microsoft offerings of a C compiler any suggestions as 
to a suitable C compiler for a PC appreciated as well. llvm? mingw? gcc?

Thanks a lot everyone,
John
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: global variable across modules

2013-09-11 Thread John Pote
Sorry about the html - did not realise. Thanks for your comments.
John

On 11 Sep 2013, at 22:49, John Pote  wrote:

> Chris,
> Interesting. 
>> 
>> # Test1.py
>> Debug_Value = " "
>> 
>> # Test2.py
>> from Test1 import *
>> # is exactly equivalent to
>> Debug_Value = " "
>> 
> I take it then that assigning to Debug_Value in Test2.py will not change the 
> value of Debug_Value in Test1.py.
> 
> That being the case it would be wrong to assume that the following are 
> identical
> 
> import sys
> 
> and
> 
> from sys import *
> 
> (the latter being a convenience  to avoid having to write sys. before every 
> variable).
> 
> Thus assigning to sys.stdout would change the standard out destination in 
> every module importing sys whereas
> 
> from sys import *
> stdout = foo.dst
> 
> would only change stdout in the current module and sys.stdout would remain 
> unchanged.
> 
> Is my understanding here correct?
> 
> As to global usage I do find it useful to have a file called something like 
> 'preferences.py' and put in there constants to be used throughout the 
> application. But I use these strictly read only. It is good in that system 
> wide constants are defined in one place only. Also if the constants are put 
> inside a class, possibly with getter methods, instantiated as a singleton 
> then initially the values can be typed directly into the preferences file. 
> Later the constructor could be changed to read the constants from an 
> initialisation file of your own format (e.g. .ini or JSON). Thus users 
> without python experience might find it easier to change them without having 
> to look at any python code. On the other hand I appreciate simple constant 
> assignments should be easy enough to change without needing to know any 
> Python.
> 
> Also remember that accessing any form of global that is shared between 
> multiple threads is a recipe for disaster unless appropriate locks are used. 
> A significant advantage of not using globals (except for system wide 
> constants) is that is makes testing of individual modules easier. The less 
> coupling there is between modules the easier it is to understand and test.
> 
> Regards all,
> John
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: global variable across modules

2013-09-11 Thread John Pote
Chris,
Interesting. 
> 
> # Test1.py
> Debug_Value = " "
> 
> # Test2.py
> from Test1 import *
> # is exactly equivalent to
> Debug_Value = " "
> 
I take it then that assigning to Debug_Value in Test2.py will not change the 
value of Debug_Value in Test1.py.

That being the case it would be wrong to assume that the following are identical

import sys

and

from sys import *

(the latter being a convenience  to avoid having to write sys. before every 
variable).

Thus assigning to sys.stdout would change the standard out destination in every 
module importing sys whereas

from sys import *
stdout = foo.dst

would only change stdout in the current module and sys.stdout would remain 
unchanged.

Is my understanding here correct?

As to global usage I do find it useful to have a file called something like 
'preferences.py' and put in there constants to be used throughout the 
application. But I use these strictly read only. It is good in that system wide 
constants are defined in one place only. Also if the constants are put inside a 
class, possibly with getter methods, instantiated as a singleton then initially 
the values can be typed directly into the preferences file. Later the 
constructor could be changed to read the constants from an initialisation file 
of your own format (e.g. .ini or JSON). Thus users without python experience 
might find it easier to change them without having to look at any python code. 
On the other hand I appreciate simple constant assignments should be easy 
enough to change without needing to know any Python.

Also remember that accessing any form of global that is shared between multiple 
threads is a recipe for disaster unless appropriate locks are used. A 
significant advantage of not using globals (except for system wide constants) 
is that is makes testing of individual modules easier. The less coupling there 
is between modules the easier it is to understand and test.

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


Re: help needed with subprocess, pipes and parameters

2012-07-17 Thread John Pote

nuffi,

Have you tried running your piped commands

c:\Programs\bob\bob.exe -x -y "C:\text\path\to some\file.txt" | 
c:\Programs\kate\kate.exe -A 2 --dc "Print Media Is Dead" --da "Author" 
--dt "Title" --hf "Times" --bb "14" --aa "" --font "Ariel" - 
"C:\rtf\path\to some\file.rtf"


in a single instance of subprocess? Start it up and use the poll method 
to wait until the subprocess has terminated. Then open the output file 
to get the results.


My recent (and single, hence limited, experience) of using subprocess 
indicated that the spawned process may take a little time to start up. Try


bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = 
subprocess.PIPE,)

time.sleep( 0.5 ) #experiment with the delay
kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], 
stdin = bob.stdout, stdout = subprocess.PIPE,)


Never looked under the subprocess hood but maybe there's a race 
condition with the kate subprocess starting before the bob subprocess 
has set up its stdout. It's unlikely but so easy to check with a sleep 
between the subprocesses it has to be worth a go.


John


On 13/07/2012 08:34, nuffi wrote:


If I copy and paste the following command into a command window,   it does what 
I need.

c:\Programs\bob\bob.exe -x -y "C:\text\path\to some\file.txt" | c:\Programs\kate\kate.exe -A 2 --dc "Print Media Is Dead" --da "Author" 
--dt "Title" --hf "Times" --bb "14" --aa "" --font "Ariel" - "C:\rtf\path\to some\file.rtf"

My mission is to recreate this command within a python script,  so that I can 
pass a bunch of different parameters into it,  and use it as a batch over a 
bunch of different papers.

http://docs.python.org/library/subprocess.html seems to be the thing to use in 
python 2.7.3.  I also checked out 
http://www.doughellmann.com/PyMOTW/subprocess/.

My attempts run fine,  create destination folders ok and prints done but don't 
actually seem to process the file.  Is there some way to get subprocess to 
output the command it's generating so I can see what I'm doing wrong,  rather 
than just the output of the command?

How can I chekc that kate's opening the pipe left from bob?Bob may take 
some time to execute,  will that matter?


The code I came up with looks like this:

import os, glob, subprocess

sourceDir = "c:\\text\\"
destDir = "c:\\rtf\\"
bobPath = "C:\\Programs\\bob\\bob.exe"
katePath = "C:\\Programs\\kate\\kate.exe"

def get_new_path(doc):
 blah = doc.replace(sourceDir, destDir)
 if not os.path.isdir(blah):
 os.makedirs(blah)
 rtf = blah.replace('.txt', '.rtf')
 pathString = '- "' + (os.path.join(rtf)) + '"'
 return(pathString)


def convert_doc(doc):
 dc = '--dc "Print Media Is Dead"'
 da = '--da "Author"'
 dt = '--dt "Title"'
 hf = '--hf "Times"'
 fn = '--font "Ariel"'
 bb = '--bb "14"'
 docpath = '"' + (os.path.join(doc)) + '"'
 path = get_new_path(doc)
 A = '-A 2'
 bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = 
subprocess.PIPE,)
 kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], stdin 
= bob.stdout, stdout = subprocess.PIPE,)
 end_of_pipe = kate.stdout
 #print kate
 #subprocess.call(['echo', "Test peice of text", '>', 'D:\\output.txt'])
 for line in end_of_pipe:
 print '\t', blah.strip()
 #raw_input()
 return('done')


test = convert_doc("c:\\text\\path to\\some\\specific text file.txt")
print(blah)


==

Thanks for looking  :-)





--- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net 
---
--
http://mail.python.org/mailman/listinfo/python-list


New Python build regr test___all__ fails at 'ctypes.macholib.dyld'

2012-07-13 Thread John Pote

Hi,

I have built Python 2.7.3 from source and although the interpreter 
starts up and runs scripts (so far OK) the 'test___all__' regression 
test fails.


The machine I'm building on is a virtual server running a version of Red 
Hat Linux


Build commands:
./configure --prefix /usr
make

At the end of the make the following note is shown

	Python build finished, but the necessary bits to build these 	modules 
were not found:

_bsddb _sqlite3   bsddb185
sunaudiodev



Test command
./python Lib/test/regrtest.py -v test___all__
produces the following:-

== CPython 2.7.3 (default, Jul 13 2012, 10:26:48) [GCC 3.2.2 20030217 
(Red Hat Linux 8.0 3.2.2-2)]

==   Linux-2.4.29-hs-17-i686-with-glibc2.2 little-endian
== 
/usr/local/home/aquamaster3/Python-2.7.3/Python-2.7.3/build/test_python_4517
Testing with flags: sys.flags(debug=0, py3k_warning=0, 
division_warning=0, division_new=0, inspect=0, interactive=0, 
optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, 
ignore_environment=0, tabcheck=0, verbose=0, unicode=0, bytes_warning=0, 
hash_randomization=0)

test___all__
test_all (test.test___all__.AllTest) ... BaseHTTPServer
Bastion
CGIHTTPServer
ConfigParser
Cookie
DocXMLRPCServer
HTMLParser
MimeWriter
Queue
SimpleHTTPServer
SimpleXMLRPCServer
SocketServer
StringIO
UserDict
UserList
UserString
_LWPCookieJar
_MozillaCookieJar
__phello__.foo
_abcoll
_pyio
_strptime
_threading_local
_weakrefset
abc
aifc
antigravity
anydbm
argparse
ast
asynchat
asyncore
atexit
audiodev
base64
bdb
binhex
bisect
bsddb
bsddb.db
bsddb.dbobj
bsddb.dbrecio
bsddb.dbshelve
bsddb.dbtables
bsddb.dbutils
bsddb.test
bsddb.test.test_all
bsddb.test.test_associate
bsddb.test.test_basics
bsddb.test.test_compare
bsddb.test.test_compat
bsddb.test.test_cursor_pget_bug
bsddb.test.test_db
bsddb.test.test_dbenv
bsddb.test.test_dbobj
bsddb.test.test_dbshelve
bsddb.test.test_dbtables
bsddb.test.test_distributed_transactions
bsddb.test.test_early_close
bsddb.test.test_fileid
bsddb.test.test_get_none
bsddb.test.test_join
bsddb.test.test_lock
bsddb.test.test_misc
bsddb.test.test_pickle
bsddb.test.test_queue
bsddb.test.test_recno
bsddb.test.test_replication
bsddb.test.test_sequence
bsddb.test.test_thread
cProfile
calendar
cgi
cgitb
chunk
cmd
code
codecs
codeop
collections
colorsys
commands
compileall
compiler
compiler.ast
compiler.consts
compiler.future
compiler.misc
compiler.pyassem
compiler.pycodegen
compiler.symbols
compiler.syntax
compiler.transformer
compiler.visitor
contextlib
cookielib
copy
copy_reg
csv
ctypes
ctypes._endian
ctypes.macholib
ctypes.macholib.dyld
Aborted


Any help in resolving this problem would be appreciated

Regards,

John

--- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net 
---
--
http://mail.python.org/mailman/listinfo/python-list


select module missing/corrupt

2012-07-07 Thread John Pote
We are using a virtual web server running some version of Unix. It has 
Python versions 2.4,2.6 and 3.1 pre-installed.


(BTW the intention is to use Python for a CGI script.)

When my script imports subprocess I get the traceback
  File "/usr/lib/python2.6/subprocess.py", line 427, in 
import select
ImportError: No module named select

On searching the Python installation I found what I presume is the 
select module library file


/usr/lib/python2.6/lib-dynload/select_failed.so

whereas in the 2.4 installation the file is
/usr/lib/python2.4/lib-dynload/select.so
and subprocess imports OK.

Anyone know why the version 2.6 select .so file should be renamed 
select_failed.so and so not able to be imported?


Of interest the 3.1 installation also has the select module file 
re-named select_failed.so.


Any help appreciated,

Regards,
John Pote


--- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net 
---
--
http://mail.python.org/mailman/listinfo/python-list


select.poll and winXP

2007-03-20 Thread John Pote
Hi all,

I have the standard Python 2.4.4 windows download installed on my win XP 
box. But the poll class in module select is not available. The docs indicate 
that it can work with windows as long as only sockets are used which is fine 
for me.

Is there a reason it's not in the standard build, can I use it if I re 
compile the 'select' module from the source?

Thanks for any help anyone can give

John 


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


where has Stani's Py Editor gone?

2007-01-31 Thread John Pote
Hi everyone,

Been trying to get the latest version of Stani's Python Editor the last few 
days. But I cannot get any response out of 'pythonide.stani.be'. Anyone know 
what's happened?

Ta much,

John Pote 


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


Re: knowing when file is flushed to disk

2006-08-10 Thread John Pote
Thanks for the replies. I guessed the situation would be flush() and trust. 
The probability of a crash between flush() returning and data actually 
written resulting in a trashed disk must be very small. But if you can be 
certain without too much effort it's got to be a good idea, so I thought I'd 
ask anyway.

How does the banking industry handle this sort of thing? Could be big bucks 
if something goes wrong for them!

Thanks again,

John 


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


knowing when file is flushed to disk

2006-08-09 Thread John Pote
Hello,

I'm using a Python CGI script on a web server to log data from a remote site 
every few minutes. I do not want to lose any data for whatever rare reason - 
power outage/os crash just at the wrong moment etc. So I would like to know 
when the data is actually written to disk and the file closed. At that point 
I can signal deleting of the data at the remote site which has very limited 
storage.

Is there some way from my Python script to know when the data is actually on 
the disk. BTW server OS is Linux. Presumably calling flush() and close() on 
the output file will initiate the disk write, but do they wait for the 
actual disk write or immediately return leaving the OS to do the write when 
it sees fit?

Any thoughts appreciated,

John 


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


Re: Python Evangelism

2006-03-17 Thread John Pote
If I get time I'll expand my thoughts and experiences but for now,
Don't know what Ruby on Rails is but it's catchy and current high volume of 
interest makes me think - I should look into it. Django, skip reading this 
thread before and I had not even picked up it was a Python product (still 
don't know what it is too little time to look!)

Python seems to concentrate on language development rather than environment 
development. Programmer productivity depends much more on the associated 
environment - docs, code editor, libraries, wysiwyg GUI designer -  than the 
language. So far my experience is that the further away from the core 
language the worst things get. My principle moan about the standard library 
is lack of formal stating of ALL exceptions that can be thrown by a module. 
Sometimes the detail is burried in the general text about the module which 
makes it difficult to eye ball quickly. httplib does not mention any of the 
socket module exceptions that can be thrown. This makes it difficult to 
write stable bullet proof code.

Finding myself slowed down too much by hand coding tkinter (and modifying it 
weeks later) I've switched to wxPython and Glade. Certainly better but 
wxPython docs are not ideal. (only reason for switching is lack of wysiwyg 
GUI designer for it)

I get a myApp.pyw working on one machine. Copy to another and maybe forget 
something (usually updating my own python library so a header import fails) 
and what happens? nothing if tkinter has not yet fired up the gui. and even 
if it has and there's an uncaught exception the app just closes. Any error 
message and traceback are dumped because there's no dos box.

On the positive side Twisted (I have the docs and book) looks exactly what I 
need in all respects.

I think the language has already made Python, the rest is down to its 
'environment'.

Best wishes to everyone,

John Pote




"Douglas Alan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Andrew Gwozdziewycz <[EMAIL PROTECTED]> writes:
>
>> Douglas Alan wrote:
>
>>> Ruby didn't start catching on until Ruby on Rails came out.  If
>>> Python has a naming problem, it's with the name of Django, rather
>>> than Python.  Firstly, Django doesn't have "Python" in the name, so
>>> it doesn't popularize the language behind it, even should Django
>>> become very popular.  Secondly, Django just doesn't have the ring
>>> of "Ruby on Rails".
>
>> I'll admit "Ruby on Rails" is a clever name. The fact that you
>> mention it "didn't catch on" is only partially true.
>
> I'm sorry if I wasn't clear.  By "didn't catch on", I only meant that
> it had little mainstream success.  At least in the US.  I'm certainly
> aware that it has had a significant community of devotees for some
> time now.
>
>> Rails did however jump start it's new career as the definitive
>> web2.0 language, but who cares? Not me!
>
> Well, I'm not sure that the threat to Python is being fully
> appreciated here.  I have friends who are fully convinced that Python
> is doomed because Ruby has all the buzz now.  I think that their
> predictions of doom and gloom for Python are overstated.  For one
> thing, I point out to them that Rails is what really has all the buzz,
> not Ruby per se.  But such subtle distinctions seem to often get lost
> in the type of buzz that causes technologies to succeed or fail.  This
> is an example of how names are indeed very important.
>
> There *is* a serious worry here.  For instance, look how PHP
> completely decimated Perl in its biggest market niche at the time (CGI
> programming) in just a couple of years.  PHP couldn't use that
> advantage to threaten the more general scripting niches, but unlike
> PHP, Ruby might certainly be able to leverage that advantage, as it is
> also a perfectly good general-purpose programming language.  Ruby's
> domain is not limited to just server-side web scripting.
>
> For those who don't believe that Ruby on Rails does have an incredible
> amount of buzz going for it right now, I do have a number of personal
> data points that seem to indicate that it is indeed undergoing
> exponential growth at the moment: (1) I'm sitting in on a class at MIT
> on developing web applications.  For their projects and assignments,
> the students are allowed to chose whatever programming languages,
> databases (as long as they are ACID-compliant), and development
> environments that they prefer.  From what I can tell, more than half
> of the class is using Ruby on Rails.  One group is using C# and .NET.
> Another is using JSP.  No one is using PHP.  

Re: python2.4.2 + win95, import socket dll error

2006-03-16 Thread John Pote
Dennis,
Thanks for the info. Found winsock2.0 on the MS knowledge base site. 
Downloaded, installed (with the y2k upgrade as recommended) and, amazingly, 
all is working. My simple socket server works no problem as does a test http 
client sending data to my web site. This latter program seems a little 
grainy on updating the wxPython GUI compared to my modern XP box and 
slightly older W2K laptop. But its working!

You might like to know:
I tried searching for winsock 2.2,
on MSK base no hits
on google search many hits but the ones I could make out all refered to 
winsock2.2.exe as a variant of the spybot worm.

Thanks for helping solve the problem,

All the best

John Pote


"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Thu, 16 Mar 2006 01:09:24 GMT, "John Pote"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>> Hi all,
>> Can someone throw some light on this problem? (is trying to run Python 
>> 2.4.2
>> on an old win95 box a reasonable thing to do?)
>>
> Wasn't Winsock updated between W95 and W98?
>
> You may have the older winsock 1.1, and all the newer stuff is built
> against (and trying to load) winsock 2.2
> -- 
> > == <
> >   [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG <
> >  [EMAIL PROTECTED] |   Bestiaria Support Staff   <
> > == <
> >   Home Page: <http://www.dm.net/~wulfraed/><
> >Overflow Page: <http://wlfraed.home.netcom.com/>< 


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


python2.4.2 + win95, import socket dll error

2006-03-15 Thread John Pote
Hi all,
Can someone throw some light on this problem? (is trying to run Python 2.4.2 
on an old win95 box a reasonable thing to do?)

I keep my old win95 box for an old eprom programmer that won't plug into a 
new box (needs an ISA socket!). Also use it for network testing. No problem 
with Py 2.3 but wanting to use the latest Twisted I upgraded to 2.4.2.

Installing Mark Hammond's pywin32-207.win32-py2.4.exe (or prev version -205) 
I get the following error message during the post install script bit of the 
installation:-

Traceback (most recent call last):
  File "", line 365, in ?
  File "", line 155, in install
  File "", line 94, in LoadSystemModule
ImportError: DLL load failed: A device attached to the system is not 
functioning.
*** run_installscript: internal error 0x ***

When I try to run a script using the socket library (also trying to start 
Stani's Python Editor) I get the following message:-

  File "C:\APPS\PYTHON\242\lib\SocketServer.py", line 132, in ?
import socket
  File "C:\APPS\PYTHON\242\lib\socket.py", line 45, in ?
import _socket
ImportError: DLL load failed: One of the library files needed to run this 
applic
ation cannot be found.

Is it the same dll in both cases, any idea what it might be and where could 
I find a copy?

Many thanks,

John Pote 


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


Re: Python Evangelism

2006-03-09 Thread John Pote

"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

This thread was great entertainment at the end of today reading down the 
screen with a beer going down on the side. Here's my penny's worth:

Over this side of the pond the good old British Post Office changed its name 
to 'Consignia' in 2001. After a year and a bit they chucked the fancy new 
name for the old one - 'Post Office'.  Although I scan the trade rags I 
missed the editorial announcing hp re-branding some of its products (test 
and measurement) Agilent and it confused me for some time as I saw Agilent 
products advertised that looked just like hp ones. (And I still think of my 
"Agilent" oscilloscope as an 'hp', this probably reflects my middle years!)

As no one in this thread has said why Python is so good here's my reasons.

The text
print "hello world"
stuck in a file and executed actually works and does exactly what it says on 
the tin - great for knocking up simple procedural scripts. On the other hand 
there's lots of freely available modules in the standard lib and 'out there' 
for doing full blown OO programming for complex multi-threaded apps. (I'm 
currently looking at Twisted for a distributed internet app - looks good so 
far)

wxPython + Glade I'm finding is a good combination for putting together 
Python + GUI apps.

No compile then link (while I go and make a coffee, stare out the window . . 
. ) stage, write once run anywhere.

what's in a name? fortran, algol, rexx, hope, haskell, pascal, modula, 
eiffel, B, C, J, tcl, pearl, ruby, rebol, cobol, basic, vb, .net, assembler, 
forth, snobol, ada, prolog, simula, smalltalk, oberon, dylan, bob, ML et al 
ad nauseum.
 - is Python any less meaningful? Anyway I LIKE the chesse shop sketch!

active news group that's always been helpful

One language does full blown apps and simple desktop scripts.

It's more readable than other languages I've looked at.

>
> Any suggestions for improvement?
>

Well yes,
mainly documentation - especially exceptions. The principle of exceptions is 
described well in the reference manual and standard books. What I mean is 
the ref manual often buries exception details in the text description and 
gives only outline detail of the exception's cause(s) and details of the 
exception object. Some lib modules do state that other exceptions may be 
thrown but unless they are listed how can robust programmes be written? The 
httplib does list the HTTPException based exceptions but there is no mention 
of the 'socket' exceptions that can be thrown. This leaves the programmer 
with using a catch all (frowned upon) or scanning through hundreds/thousands 
of lines of code in possibly deeply nested modules.

The beer's run out so I'll stop here.

keep at it everyone, best regards,

John Pote




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


wanted: ftp server class

2006-03-06 Thread John Pote
Hi everyone,

I have a 'client' with a built in ftp client that I wish to use to access a 
server via the internet. But I do not want to use a standard disk accessing 
ftp server as I need to do my own processing between the filesystem and the 
ftp TCP/IP port.

Can someone suggest the source of a Python ftp server class (ftplib only has 
a client class) out there. (These days I try to keep all my programming to 
Python!).

I seem to remember reading Twisted has some ftp server facilities. Does it? 
Any comments on it - easy to use, steep learning curve?

Any help appreciated,

John Pote



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


Re: sockets, where can I find documentation?

2006-03-03 Thread John Pote
Thanks everyone for such a quick response.
Brilliant!

John Pote

"John Pote" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi all,
>
> I want to use python on a server to access incoming TCP port accesses. So 
> I need to use the socket interface which is new to me. To quote the Py 
> Library Reference "7.2 socket -- Low-level networking interface":-
>
> For an introduction to socket programming (in C), see the following 
> papers: An Introductory 4.3BSD Interprocess Communication Tutorial, by 
> Stuart Sechrest and An Advanced 4.3BSD Interprocess Communication 
> Tutorial, by Samuel J. Leffler et al, both in the Unix Programmer's 
> Manual, Supplementary Documents 1 (sections PS1:7 and PS1:8). The 
> platform-specific reference material for the various socket-related system 
> calls are also a valuable source of information on the details of socket 
> semantics. For Unix, refer to the manual pages; for Windows, see the 
> WinSock (or Winsock 2) specification. For IPv6-ready APIs, readers may 
> want to refer to RFC 2553 titled Basic Socket Interface Extensions for 
> IPv6.
>
> Where can I get the various papers mentioned in the manual? And as I like 
> books sitting on the shelf can someone recommend a book on sockets.
>
> many thanks,
>
> John Pote
> 


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


sockets, where can I find documentation?

2006-03-03 Thread John Pote
Hi all,

I want to use python on a server to access incoming TCP port accesses. So I 
need to use the socket interface which is new to me. To quote the Py Library 
Reference "7.2 socket -- Low-level networking interface":-

For an introduction to socket programming (in C), see the following papers: 
An Introductory 4.3BSD Interprocess Communication Tutorial, by Stuart 
Sechrest and An Advanced 4.3BSD Interprocess Communication Tutorial, by 
Samuel J. Leffler et al, both in the Unix Programmer's Manual, Supplementary 
Documents 1 (sections PS1:7 and PS1:8). The platform-specific reference 
material for the various socket-related system calls are also a valuable 
source of information on the details of socket semantics. For Unix, refer to 
the manual pages; for Windows, see the WinSock (or Winsock 2) specification. 
For IPv6-ready APIs, readers may want to refer to RFC 2553 titled Basic 
Socket Interface Extensions for IPv6.

Where can I get the various papers mentioned in the manual? And as I like 
books sitting on the shelf can someone recommend a book on sockets.

many thanks,

John Pote 


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


Re: Hi reliability files, writing,reading,maintaining

2006-02-09 Thread John Pote
Thanks for all the replies,

> 
> Also, the whole idea of basing reliability on HTTP uploads of 50 bytes
> at a time sounds to me a bit ... strained.  There *must* be simpler
> ways--and simpler goes a long way in the direction of trustworthy.
>

The motivation to look at http: is the widespread avaiability of internet 
connections and standard servers able to run CGI scripts. In particular the 
availability of low cost GPRS modems (solar panel and/or wind gen) is very 
attractive for remote locations where there is  no power, telephone line or 
cable company.

However, I take your point about HTTP uploads of 50 or so bytes is a little 
overhead heavy. Recently I've come to know of reasonably priced fully 
managed dedicated servers in secure buildings. So I am now thinking of a 
direct TCP/IP port connection. I know Python can do this as I found the 
appropriate standard modules and set up a simple proving system on my 
private network (one port listener, one sender - no problem!). Are there 
security issues in this approach?

I realise http: reliability is not a great as it might be but we have a 
reasonable amount of time for re-tries (an hour or two) if some packets get 
lost. My recent experience of telneting to our server in London (I'm in the 
midlands) is quite revealing. Round trip time is generally sub .5 sec. Makes 
me think all that waiting for web pages is the server rather than the 
internet itself.

Any thoughts on *simpler* ways to achieve my goal of remote data to web 
servers greatly appriciated.

It would still be useful to have anyones thoughts on securely writing the 
data to disk files. The off the shelf "military" approach suggested by 
Martin Hellwig is outside our budget.

Thanks again.

John

"Cameron Laird" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> In article <[EMAIL PROTECTED]>,
> Martin P. Hellwig <[EMAIL PROTECTED]> wrote:
>>John Pote wrote:
>>
>>> So my request:
>>> 1. Are there any python modules 'out there' that might help in securely
>>> writing such files.
>>> 2. Can anyone suggest a book or two on this kind of file management. 
>>> (These
>>> kind of problems must have been solved in the financial world many 
>>> times).
>>>
>>
>>I can't answer your specific questions but I got the feeling that you're
>>  barking at the wrong tree ;-)
>>
>>You don't want to solve this in you application, file management is what
>>the OS and hardware is about. "Military" grade solutions are often
>>(depending on their criticalness) double or triple hot spares in the
>>same room which can be seen as a "unit" and these units are duplicated
>>on remote locations (at least 25km of each other) syncing their data
>>with standard tools like rsync.
>>
>>If you don't have military budget, I would suggest to do it a little
>>less expensive, like having a couple of Solaris machines (three or four
>>will do it) in the same room, using a part of their diskspace for ZFS.
>>
>>Then let your application write your data to that ZFS partition and if
>>you are particular paranoid you can build in a checksum that can be
>>calculated by other machines without the need for the original received
>>data (ZFS has a built-in mechanism for that so you might just want to
>>call that).
>>
>>There is nothing wrong for assuming a certain level of hardware, well at
>>least not if its very clearly communicated to all parties.
>>ZFS is open source (by SUN) but currently only implemented in Solaris,
>>which you also can (commercially) use without charge.
>>
>>Now you only got to figure out how to implement a heartbeat mechanism
>>between you fail-over applications :-)
> .
> .
> .
> Also, the whole idea of basing reliability on HTTP uploads of 50 bytes
> at a time sounds to me a bit ... strained.  There *must* be simpler
> ways--and simpler goes a long way in the direction of trustworthy. 


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


Hi reliability files, writing,reading,maintaining

2006-02-09 Thread John Pote
Hello, help/advice appreciated.

Background:
I am writing some web scripts in python to receive small amounts of data
from remote sensors and store the data in a file. 50 to 100 bytes every 5 or
10 minutes. A new file for each day is anticipated.  Of considerable
importance is the long term availability of this data and it's gathering and
storage without gaps.

As the remote sensors have little on board storage it is important that a
web server is available to receive the data. To that end two separately
located servers will be running at all times and updating each other as new
data arrives.

I also assume each server will maintain two copies of the current data file,
only one of which would be open at any one time, and some means of
indicating if a file write has failed and which file contains valid data.
The latter is not so important as the data itself will indicate both its
completeness (missing samples) and its newness because of a time stamp with
each sample.
I would wish to secure this data gathering against crashes of the OS,
hardware failures and power outages.

So my request:
1. Are there any python modules 'out there' that might help in securely
writing such files.
2. Can anyone suggest a book or two on this kind of file management. (These
kind of problems must have been solved in the financial world many times).

Many thanks,

John Pote






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


Hi reliability files, writing,reading and maintaining

2006-02-07 Thread John Pote
Hello, help/advice appreciated.

Background:
I am writing some web scripts in python to receive small amounts of data 
from remote sensors and store the data in a file. 50 to 100 bytes every 5 or 
10 minutes. A new file for each day is anticipated.  Of considerable 
importance is the long term availability of this data and it's gathering and 
storage without gaps.

As the remote sensors have little on board storage it is important that a 
web server is available to receive the data. To that end two separately 
located servers will be running at all times and updating each other as new 
data arrives.

I also assume each server will maintain two copies of the current data file, 
only one of which would be open at any one time, and some means of 
indicating if a file write has failed and which file contains valid data. 
The latter is not so important as the data itself will indicate both its 
completeness (missing samples) and its newness because of a time stamp with 
each sample.
I would wish to secure this data gathering against crashes of the OS, 
hardware failures and power outages.

So my request:
1. Are there any python modules 'out there' that might help in securely 
writing such files.
2. Can anyone suggest a book or two on this kind of file management. (These 
kind of problems must have been solved in the financial world many times).

Many thanks,

John Pote





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


Re: tkinter menu bar problem

2005-02-10 Thread John Pote
Thanks for the reply. I now have radio buttons (with a nice tick!) on my 
menu that can be greyed out when disabled. I can also change the background 
colour of the individual buttons as you suggest.

What I cannot do is change the background colour of the menu bar itself. The 
following code is accepted but the menu bar background stays resolutely 
light grey rather than light blue.

 rootWin = Tk()
 menuBar = MenuBar(rootWin, background='light blue')
 menuBar.insert_cascade(MenuBar.CONFIG, label='Config', menu=configMenu, 
background='light blue')

The background options are being ignored and the window retains its standard 
windows colour scheme which I assume is overriding the background colour 
option. I guess my normal windows colour scheme (classic windows!) is not so 
bad and life is too short to tinker with this any more.

Thanks again
John Pote



"Eric Brunel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <[EMAIL PROTECTED]> 
> wrote:
>
>> I have a menu bar in a top level window as follows
> [snip code]
>>
>> Q1 Cannot find a way of changing the menu bars background colour. When
>> colour options are accepted they seem to be ignored. Is this a native 
>> look
>> and feel characteristic of write once run anywhere, not yet implemented 
>> or
>> possibly a bug.
>
> Even if the tk man pages [1] don't mention it, it would not be surprising 
> if the background option for menu items did not work on Windows, since 
> many things seem to be "hardcoded" on this platform. I tested the 
> following code on Linux; it works without problem and has the expected 
> behaviour:
>
>>>> from Tkinter import *
>>>> root = Tk()
>>>> mb = Menu(root)
>>>> root.configure(menu=mb)
>>>> m = Menu(mb)
>>>> mb.add_cascade(label='Menu', menu=m)
>>>> m.add_command(label='Quit', command=root.quit, background='red')
>
> If it is what you did and if it doesn't work on Windows, it is likely that 
> the background option for menu items is not supported for this platform...
>
>> Q2 Some of the menu options in the config menu will not always be 
>> available
>> depending on program state. How can individual items in such a menu be
>> turned to faint gey to indicate their unavailability. Also a tick mark
>> against an item would be useful to show the currently selected option. Is
>> this possible?
>
> To "grey out" a menu item:
>
> parentMenu.entryconfigure(itemIndex, state=DISABLED)
>
> To have menu items with a check-mark, use the add_checkbutton or 
> add_radiobutton methods on the parent menu. Their use is similar to the 
> Checkbutton and Radiobutton classes. See [1] for all available options.
>
> [1] http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm
>  - Eric Brunel - 


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


tkinter menu bar problem

2005-02-09 Thread John Pote
I have a menu bar in a top level window as follows

 menuBar = Menu(rootWin)
 menuBar.add_command( label='Quit', command=rootWin.quit)

 configMenu = Menu(menuBar, tearoff=0)
 configMenu.add_command(label='Left Device Raw', command=setLeftRaw)
 configMenu.add_command(label='Right Device Raw', command=setRightRaw)
 etc

menuBar.add_cascade(label='Config', menu=configMenu)

 rootWin.config(menu=menuBar)

Q1 Cannot find a way of changing the menu bars background colour. When 
colour options are accepted they seem to be ignored. Is this a native look 
and feel characteristic of write once run anywhere, not yet implemented or 
possibly a bug.

Q2 Some of the menu options in the config menu will not always be available 
depending on program state. How can individual items in such a menu be 
turned to faint gey to indicate their unavailability. Also a tick mark 
against an item would be useful to show the currently selected option. Is 
this possible?

Regards,
John Pote

System: Win XP, Python 2.3.4



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


Python application extending, plugins

2005-01-07 Thread John Pote
Hi,

Has anyone any thoughts on structuring a program so that it can be extended 
simply and elegantly by a user who only has a compiled (.pyc) version of the 
application?

I wish to write an application, myApp, that provides a GUI to, amongst other 
things, a simulator implimented as a class. myApp's simulator may then be 
extended by more python code to produce what is effectively 'myApp2'. The 
simulator might then be further extended from myApp2 to myApp3 in a similar 
manor. Don't think there would be much call, if at all, to go beyond myApp3 
level. But who knows!

Any thoughts would be appreciated.

John Pote 


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


Re: Multithreading tkinter question

2004-12-16 Thread John Pote

"Mark English" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Is there a safe way to run tkinter in a multithreaded app where the
mainloop runs in a background thread ?


Mark,

I tried your code snippet with Python 2.3.4. Worked fine. Only problem was 
that the program fell off the end and terminated before the second thread 
could open the Tkinter window. So I added these lines at the end to make the 
main thread wait:-

from msvcrt import kbhit, getch
print "\n\nPress key to end"
while not kbhit(): pass
getch()

Both your Hello and Quit buttons worked.

However, I have found that tkinter crashes if any components, labels text 
box etc, are accessed directly from another thread. Below is a posting I did 
some time ago. My solution to the problem. I'm still interested to know if 
this is a good/best way to solve this problem.

It is not optimal in that 'otherThread' runs continuously even when the 
label is not being updated. What a waste of cpu cycles! This shows up in 
that other windows apps slow right down. What is needed is a comms method 
between threads that causes a thread to block while it's waiting for data 
rather than my continuous polling approach. Would a Queue help here?

John Pote

"Martin Franklin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Tue, 09 Nov 2004 17:41:56 GMT, John Pote <[EMAIL PROTECTED]>
> wrote:
>
>> Running my programme in Python 2.3.4 I received the following msg in the
>> consol :-
>> (Pent III running W2K prof)
>>
>> """
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>>   File "c:\apps\python\234\lib\lib-tk\Tkinter.py", line 1345, in __call__
>> return self.func(*args)
>>   File "c:\apps\python\234\lib\lib-tk\Tkinter.py", line 459, in callit
>> self.deletecommand(tmp[0])
>> AttributeError: 'str' object has no attribute 'deletecommand'
>> UpdateStringProc should not be invoked for type option
>>
>> abnormal program termination
>> """
>> There was no other traceback information.
>>
>> Could this be related to lines of the ilk:-
>>   self.infoSpd.config(text="%d.%01d"%spd)
>> where infoSpd is a Tkinter Label object placed using the grid manager.
>>
>> Thousands of these updates were performed so the labels displayed
>> progress
>> through a memory dump of a system accessed through a serial port.
>>
>> I had trouble before with Python versions 2.2.1 and 2.2.3 where
>> commenting
>> out these Label updates stopped the system crashing and it was happy to
>> run
>> for hours performing tests on the external hardware. (an embedded data
>> logger I'm developing)
>>
>> Anyone any thoughts?
>>
>> John
>
>
> Only one (thought that is)  Are you updating thses Label widgets from
> other
> threads? and could you possibly post an example?
>
> Martin


A  --  Experience had already taught me that lesson about tkinter. On
checking my code guess what I found I'd done - called the widget.config
method from the other thread. So I put in a list to queue the label updates
from the other thread to the tkinter thread and it's now been running for
several hours without problem.

Thanks for the reminder.

BTW the program structure I've been using is:-

def otherThread():
while TRUE:
if updatelabel:
labelQ = "new label text"

def guiLoop():
if labelQ:
myLabel.config(text=labelQ)
labelQ = None
 #re-register this fn to run again
 rootWin.after(10, guiLoop) #strangely .after_idle(guiLoop) is slower!
.
.
rootWin = Tk(className=" tester")

#rest of GUI set up. then:-

 thread.start_new( otherThread, () )
 rootWin.after(50, guiLoop)
 rootWin.mainloop()

It works but is it the best way to do this sort of thing? The point is that
I need moderately fast serial comms, which I do in 'otherThread' and found
the 'after' and 'after_idle' call backs were too slow. The timing I did on
py2.2.1 indicated that 'after_idle' could not do better than ~70ms and
'after(10, )' was faster, 30-40 ms, but still too slow for my app.

Any more thoughts appreciated.

John



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