Re: building an index for large text files for fast access

2006-07-24 Thread Erik Max Francis
alex23 wrote:

> The standard library module 'libcache' does exactly what you're
> considering implementing.

I believe the module you're referring to is `linecache`.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   It is from numberless diverse acts of courage and belief that human
history is shaped. -- John F. Kennedy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: building an index for large text files for fast access

2006-07-24 Thread Neil Hodgson
Yi Xing:

> Since different lines have different size, I 
> cannot use seek(). So I am thinking of building an index for the file 
> for fast access. Can anybody give me some tips on how to do this in 
> Python?

It depends on the size of the files and the amount of memory and 
disk you may use. First suggestion would be an in-memory array.array of 
64 bit integers made from 2 'I' entries with each 64 bit integer 
pointing to the start of a set of n lines. Then to find a particular 
line number p you seek to a[p/n] and then read over p%n lines. The 
factor 'n' is adjusted to fit your data into memory. If this uses too 
much memory or scanning the file to build the index each time uses too 
much time then you can use an index file with the same layout instead.

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


Re: building an index for large text files for fast access

2006-07-24 Thread alex23
Yi Xing wrote:
> I need to read specific lines of huge text files. Each time, I know
> exactly which line(s) I want to read. readlines() or readline() in a
> loop is just too slow. Since different lines have different size, I
> cannot use seek(). So I am thinking of building an index for the file
> for fast access. Can anybody give me some tips on how to do this in
> Python? Thanks.

Hey Yi,

The standard library module 'libcache' does exactly what you're
considering implementing.

-alex23

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


Re: regular expression - matches

2006-07-24 Thread John Machin
On 22/07/2006 2:18 AM, Simon Forman wrote:
> John Salerno wrote:
>> Simon Forman wrote:
>>
>>> Python's re.match() matches from the start of the string,  so if you

(1) Every regex library's match() starts matching from the beginning of 
the string (unless of course there's an arg for an explicit starting 
position) -- where else would it start?

(2) This has absolutely zero relevance to the "match whole string or 
not" question.

>>> want to ensure that the whole string matches completely you'll probably
>>> want to end your re pattern with the "$" character (depending on what
>>> the rest of your pattern matches.)

*NO* ... if you want to ensure that the whole string matches completely, 
you need to end your pattern with "\Z", *not* "$".

Perusal of the manual would seem to be indicated :-)

>> Is that necessary? I was thinking that match() was used to match the
>> full RE and string, and if they weren't the same, they wouldn't match
>> (meaning a begin/end of string character wasn't necessary). That's wrong?

Yes. If the default were to match the whole string, then a metacharacter 
would be required to signal "*don't* match the whole string" ... 
functionality which is quite useful.

> 
> My understanding, from the docs and from dim memories of using
> re.match() long ago, is that it will match on less than the full input
> string if the re pattern allows it (for instance, if the pattern
> *doesn't* end in '.*' or something similar.)

Ending a pattern with '.*' or something similar is typically a mistake 
and does nothing but waste CPU cycles:

C:\junk>python -mtimeit -s"import 
re;s='a'+80*'z';m=re.compile('a').match" "m(s)"
100 loops, best of 3: 1.12 usec per loop

C:\junk>python -mtimeit -s"import 
re;s='a'+8000*'z';m=re.compile('a').match" "m(s)"
10 loops, best of 3: 1.15 usec per loop

C:\junk>python -mtimeit -s"import 
re;s='a'+80*'z';m=re.compile('a.*').match" "m(s)"
10 loops, best of 3: 1.39 usec per loop

C:\junk>python -mtimeit -s"import 
re;s='a'+8000*'z';m=re.compile('a.*').match" "m(s)"
1 loops, best of 3: 24.2 usec per loop

The regex engine can't optimise it away because '.' means by default 
"any character except a newline" , so it has to trundle all the way to 
the end just in case there's a newline lurking somewhere.

Oh and just in case you were wondering:

C:\junk>python -mtimeit -s"import 
re;s='a'+8000*'z';m=re.compile('a.*',re.DOTALL).match" "m(s)"
100 loops, best of 3: 1.18 usec per loop

In this case, logic says the '.*' will match anything, so it can stop 
immediately.

> 
> I'd test this, though, before trusting it.
> 
> What the heck, I'll do that now:
> 
 import re
 re.match('ab', 'abcde')
> <_sre.SRE_Match object at 0xb6ff8790>
 m = _

??? What's wrong with _.group() ???

 m.group()
> 'ab'
 print re.match('ab$', 'abcde')
> None
> 

HTH,
John

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


building an index for large text files for fast access

2006-07-24 Thread Yi Xing
Hi,

I need to read specific lines of huge text files. Each time, I know 
exactly which line(s) I want to read. readlines() or readline() in a 
loop is just too slow. Since different lines have different size, I 
cannot use seek(). So I am thinking of building an index for the file 
for fast access. Can anybody give me some tips on how to do this in 
Python? Thanks.

Yi 

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


Re: Help in string.digits functions

2006-07-24 Thread John Machin

Anoop wrote:
> Hi All
>
> I am getting two different outputs when i do an operation using
> string.digits and test.isdigit(). Is there any difference between the
> two.

Your first sentence appears to answer that ..but yes, there's quite a
difference. Have you read the manual?

> I have given the sample program and the output
>

There is a much better way to try out very small snippets of code than
putting them in a script: use the Python interactive prompt.

>>> import string
>>> string.digits
'0123456789'
>>> '0' in string.digits
True
>>> '9' in string.digits
True
>>> '90' in string.digits
False
>>> '90' in string.digits
False
>>> '123' in string.digits
True
>>> 'oo' in 'Anoop'
True
>>> '' in 'Anoop'
True
>>>

Manual:
"""
For the Unicode and string types, x in y is true if and only if x is a
substring of y. An equivalent test is y.find(x) != -1. Note, x and y
need not be the same type; consequently, u'ab' in 'abc' will return
True. Empty strings are always considered to be a substring of any
other string, so "" in "abc" will return True. Changed in version 2.3:
Previously, x was required to be a string of length 1.
"""

>>> '12345'.isdigit()
True
>>> ''.isdigit()
False
>>> 'xyz'.isdigit()
False
>>> '123xyz'.isdigit()
False
>>> '123 '.isdigit()
False
>>> ' 123'.isdigit()
False

Manual:
"""
isdigit( )
Return true if all characters in the string are digits and there is at
least one character, false otherwise. 
"""

HTH,
John

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


Re: Help in string.digits functions

2006-07-24 Thread John McMonagle
On Mon, 2006-07-24 at 22:19 -0700, Anoop wrote:
> Hi All
> 
> I am getting two different outputs when i do an operation using
> string.digits and test.isdigit(). Is there any difference between the
> two. I have given the sample program and the output
> 
> Thanks for ur inputs
> 
> Anoop
> 
> #1:
> ~~
> import string
> 
> test='121206'
> 
> if test not in string.digits:
> print "I am Not Digit"
> else:
> print "I am Digit"
> 
> #2:
> ~~
> import string
> 
> test='121206'
> 
> if not test.isdigit():
> print "I am Not Digit"
> else:
> print "I am Digit"
> 
> Output
> ~
> #1:I am Not Digit
> #2:I am Digit
> 
> Thnks and Rgds 
> 
> Anoop
> 


string.digits is the string constant '0123456789'

So your test, "if test not in string.digits:" will evaluate True because
'121206' is not in '0123456789'.

Whereas test.isdigit() returns true if all the characters in test are
digits.

So yes, there is a big difference between the two.

Regards,

John



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: prob with struct and byte order

2006-07-24 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, nephish wrote:

> tohex gave me
> '53 54 58
  
   S  T  X

> 00 00 00 34

Length!?  Decimal 57.

> 00 00 00 c8

Type!?  Decimal 200.

> 70 69 76 6f 74 72 61 63 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> 74 72 61 63 31 70 69 76 6f 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Payload!?

> 45 4e 58'

  E  N  X

> this is the login message (message type 200)

import struct

data = ('STX'
'\x00\x00\x004'
'\x00\x00\x00\xc8'
'stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x00\x00\x00state1man\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x00\x00\x00\x00ENX')

def split_message(message):
if not (message.startswith('STX') or message.endswith('ENX')):
raise ValueError('missing start or end sequence')
length, message_type = struct.unpack('>II', message[3:11])
return length, message_type, message[11:-3]

print 'length: %d\ntype: %d\n%r' % split_message(data)

The problem I see is the length.  The payload without STX, ENX and the two
numbers in front is 47 bytes so there's a 5 byte difference.  You have to
look at some more messages to get an idea how the length corresponds to
the actual payloads length.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


stuff 2

2006-07-24 Thread Andrew Coffman
http://www.ferg.org/papers/debugging_in_python.html
python and vmware (interface)

using super():
super(class, instance).method()

class MyConfig(ConfigParser, object):
 def add_section(self, section)
  super(MyConfig, self).add_section(section)

effing the ineffable:
http://maverickphilosopher.powerblogs.com/posts/1124325868.shtml

Visual Exploration of Complex Networks
Visualizing large state spaces

evolving print masks
environments
crossover operators
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Stripped CSS Background Image Calls

2006-07-24 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, JenAsh wrote:

> In my python file I have several css calls--they all works except for
> the background image CSS call.
> 
> .mystyle { background-image:
> url(http://www.mysite.com/images/background.gif); }
> 
> When I try to view it in the browser the code is somehow stripped. I
> only get the following:
> 
> .mystyle { }
> 
> How can I get Python to ignore the codes? Sort of like cdata in XML.
> Sorry I am very unfamilar with Python.
> 
> Can anyone explain?

Can you explain in a little more detail what you are doing?  Python
doesn't know about CSS  and it's illegal syntax to just write CSS into
Python programs.  I guess there's a web framework involved?  Or CGI?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: print function question

2006-07-24 Thread Bertrand-Xavier M.
On Tuesday 25 July 2006 05:52, Eric Bishop wrote:
> Why does this work:
>
> # start
> a = 5
>
> print a, 'is the number'
>
> #end, prints out "5 is the number"
>
> But not this:
>
> # start
>
> a = 5
>
> print a 'is the number'
>
> #end, errors out
>
> The difference here is the comma seperating the variable and the string
> literal. Is the comma some sort of concatenation operator or is the comma
> necessary in some form of a requirement in the print function, i.e is the
> variable a an argument to print as well as 'is th number' another argument
> to print?

Yes.
It allows to concat several variables, and also adds a space.
These do work as well:

a = 5
print "value is", a
print "value %s" %(a)
print "value is", a, '...'

Regards,
Rob
-- 
http://mail.python.org/mailman/listinfo/python-list


Help in string.digits functions

2006-07-24 Thread Anoop
Hi All

I am getting two different outputs when i do an operation using
string.digits and test.isdigit(). Is there any difference between the
two. I have given the sample program and the output

Thanks for ur inputs

Anoop

#1:
~~
import string

test='121206'

if test not in string.digits:
print "I am Not Digit"
else:
print "I am Digit"

#2:
~~
import string

test='121206'

if not test.isdigit():
print "I am Not Digit"
else:
print "I am Digit"

Output
~
#1:I am Not Digit
#2:I am Digit

Thnks and Rgds 

Anoop

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


Re: HELP!!! How do I send an ACK packet in UDP?????

2006-07-24 Thread Joe Knapka
[EMAIL PROTECTED] wrote:

> I need my udp server to send an ACK back to the client when it
> successfully receives data from the client to let it know not to retry
> the send (yes, I do know this is how TCP works but must be in UDP)
> I am using this example code I found on the net for the server, I need
> to figure out how to get the ip and port that the client transmitted
> from and return an ack response. Any help would be greatly
> appreciated..
> 
> from socket import *
> 
> # Set the socket parameters
> host = "localhost"
> port = 21567
> buf = 1024
> addr = (host,port)
> 
> # Create socket and bind to address
> UDPSock = socket(AF_INET,SOCK_DGRAM)
> UDPSock.bind(addr)
> 
> # Receive messages
> while 1:
>   data,addr = UDPSock.recvfrom(buf)

Um... There's the sender's address, right there,
per the documentation for recvfrom(), which you
seem to have read, since you know recvfrom()
returns a 2-item sequence.

No doubt you realized that seconds after hitting
"send".

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


Re: HELP!!! How do I send an ACK packet in UDP?????

2006-07-24 Thread Joe Knapka
[EMAIL PROTECTED] wrote:

> I need my udp server to send an ACK back to the client when it
> successfully receives data from the client to let it know not to retry
> the send (yes, I do know this is how TCP works but must be in UDP)
> I am using this example code I found on the net for the server, I need
> to figure out how to get the ip and port that the client transmitted
> from and return an ack response. Any help would be greatly
> appreciated..
> 
> from socket import *
> 
> # Set the socket parameters
> host = "localhost"
> port = 21567
> buf = 1024
> addr = (host,port)
> 
> # Create socket and bind to address
> UDPSock = socket(AF_INET,SOCK_DGRAM)
> UDPSock.bind(addr)
> 
> # Receive messages
> while 1:
>   data,addr = UDPSock.recvfrom(buf)

Um... There's the sender's address, right there,
per the documentation for recvfrom(), which you
seem to have read, since you know recvfrom()
returns a 2-item sequence.

No doubt you realized that seconds after hitting
"send".

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


Python Stripped CSS Background Image Calls

2006-07-24 Thread JenAsh
In my python file I have several css calls--they all works except for
the background image CSS call.

.mystyle { background-image:
url(http://www.mysite.com/images/background.gif); }

When I try to view it in the browser the code is somehow stripped. I
only get the following:

.mystyle { }

How can I get Python to ignore the codes? Sort of like cdata in XML.
Sorry I am very unfamilar with Python.

Can anyone explain?

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


Re: Help beautify ugly heuristic code

2006-07-24 Thread Stuart D. Gathman
On Thu, 09 Dec 2004 00:01:36 -0800, Lonnie Princehouse wrote:
 
> I believe you can still do this with only compiling a regex once and
> then performing a few substitutions on the hostname.

That is a interesting idea.  Convert ip matches to fixed patterns, and
*then* match the regex.  I think I would convert hex matches to the same
pattern as decimal (and roman numeral).  How would you handle zero fill?

1.2.3.4 001002003004foo.isp.com

An idea I had last night is to precompile 254 regexes - one for each of
the possible last ip bytes.  However, your idea is cleaner - except, how
would it handle ip bytes that are the same: 1.2.2.2

Mitja has proposed a scoring system reminiscent of SpamAssassin.

This gives me a few things to try.

-- 
  Stuart D. Gathman <[EMAIL PROTECTED]>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

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


print function question

2006-07-24 Thread Eric Bishop
Why does this work:
 
# start 
a = 5
 
print a, 'is the number'
#end, prints out "5 is the number"
 
But not this:
 
# start
 
a = 5
 
print a 'is the number'
 
#end, errors out
 
The difference here is the comma seperating the variable and the string literal. Is the comma some sort of concatenation operator or is the comma necessary in some form of a requirement in the print function, i.e is the variable a an argument to print as well as 'is th number' another argument to print?

-- Thanks,Eric 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread John Machin
Steve Jobless wrote:
> Hi,
>
> I just started learning Python. I went through most of the tutorial at
> python.org. But I noticed something weird. I'm not talking about the
> __private hack.
>
> Let's say the class is defined as:
>
>   class MyClass:
> def __init__(self):
>   pass
> def func(self):
>   return 123
>
> But from the outside of the class my interpreter let me do:
>
>   x = MyClass()
>   x.instance_var_not_defined_in_the_class = 456

Uh-huh. Could result from a typo. Found in testing. pychecker and/or
pylint may help here. Use __slots__ if this bothers you.

>
> or even:
>
>   x.func = 789
>
> After "x.func = 789", the function is totally shot.

So is the developer :-)

>
> Are these bugs or features? If they are features, don't they create
> problems as the project gets larger?
>

Features. They don't *create* problems by themselves. If a project
already has  problems (like they hire idiots, and don't have
appropriate review and testing), then yeah things can blow up because
of some language features being mis-used -- this applies to any
language. Further, there are lots more reasons why projects blow up,
few of them related to a couple of features of the development
language.

Another way of looking at it: languages can't tell who's using them. If
they constrain idiots, they also constrain non-idiots.

Cheers,
John

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread Kevin Watters
See:

http://redhanded.hobix.com/inspect/monkeypytching.html

Shouldn't be done unless you have a really cool reason for doing so.

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


Re: Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread Jean-Paul Calderone
On Tue, 25 Jul 2006 02:49:06 GMT, Steve Jobless <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I just started learning Python. I went through most of the tutorial at
>python.org. But I noticed something weird. I'm not talking about the
>__private hack.
>
>Let's say the class is defined as:
>
>  class MyClass:
>def __init__(self):
>  pass
>def func(self):
>  return 123
>
>But from the outside of the class my interpreter let me do:
>
>  x = MyClass()
>  x.instance_var_not_defined_in_the_class = 456
>
>or even:
>
>  x.func = 789
>
>After "x.func = 789", the function is totally shot.
>
>Are these bugs or features? If they are features, don't they create
>problems as the project gets larger?

If you do things like this, you will probably encounter problems, yes.

Fortunately the solution is simple: don't do things like this ;)

It is allowed at all because, to the runtime, "x.someattr = someval" is
no different from "self.someattr = someval".  The fact that a different
name is bound to a particular object doesn't matter.

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


Newbie Q: Class Privacy (or lack of)

2006-07-24 Thread Steve Jobless
Hi,

I just started learning Python. I went through most of the tutorial at
python.org. But I noticed something weird. I'm not talking about the
__private hack.

Let's say the class is defined as:

  class MyClass:
def __init__(self):
  pass
def func(self):
  return 123

But from the outside of the class my interpreter let me do:

  x = MyClass()
  x.instance_var_not_defined_in_the_class = 456

or even:

  x.func = 789

After "x.func = 789", the function is totally shot.

Are these bugs or features? If they are features, don't they create
problems as the project gets larger?

TIA,

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


Re: Which Pyton Book For Newbies?

2006-07-24 Thread hanumizzle

Bob Sinclar wrote:
> Web programming is all about stdin & stdout. Recommanded practice
> before going further.

It's actually a little more (at least as far as CGI is concerned)...it
bears some level of abstraction, namely, a decent CGI lib.

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


Re: Search within running python scripts

2006-07-24 Thread Simon Forman
Cameron Laird wrote:
...
> Particularly when I hear "os-independent", I think first of
> binding to a socket.  While http://wiki.tcl.tk/1558 >
> is written for a Tcl-based crowd, the commentary there ap-
> plies quite well to Python.

I was going to suggest something like this, as I have noticed that IDLE
seems to do exactly this, and on windows and linux, but I was afraid to
look the fool if it was indeed foolish. (and also, I didn't know
details of it.)

Thanks Cameron.

Peace,
~Simon

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


HELP!!! How do I send an ACK packet in UDP?????

2006-07-24 Thread myersoft
I need my udp server to send an ACK back to the client when it
successfully receives data from the client to let it know not to retry
the send (yes, I do know this is how TCP works but must be in UDP)
I am using this example code I found on the net for the server, I need
to figure out how to get the ip and port that the client transmitted
from and return an ack response. Any help would be greatly
appreciated..

from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
if not data:
print "Client has exited!"
break
else:
print "\nReceived message '", data,"'"

# Close socket
UDPSock.close()

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


Re: How to force a thread to stop

2006-07-24 Thread Paul Rubin
"Carl J. Van Arsdall" <[EMAIL PROTECTED]> writes:
> > Communications through Queue.Queue objects can help. But if you
> > research the history of this design decision in the language you
> > should discover there are fairly sound rasons for not allowing
> > arbitrary "threadicide".
> >
> Right, I'm wondering if there was a way to make an interrupt driven
> communication mechanism for threads?  Example: thread receives a
> message, stops everything, and processes the message. --

There is in fact some under-the-covers mechanism in CPython (i.e.
one you can call from C extensions but not from Python code) to
raise exceptions in other threads.  I've forgotten the details.
There has been discussion at various times about how to expose
something like that to Python code, but it's been inconclusive.  E.g.:

http://sf.net/tracker/?func=detail&atid=105470&aid=502236&group_id=5470 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Search within running python scripts

2006-07-24 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Simon Forman <[EMAIL PROTECTED]> wrote:
>gmax2006 wrote:
.
.
.
>> > Yes, there are several ways.  What OS are you using?
>> >
>> > ~Simon
>>
>> I have to use an os-independent approach.
>>
>> At this point I use a file as running-flag. It doesn't work so good.
>> Because if the python application breaks or get terminated, it won't
>> run again unless somebody deletes the flag file.
>>
>> Alan
>
>Hmm,  I'm very far from being an expert on this, so hopefully someone
>who knows better will reply.
>You might have to check the OS your script is running on and do, say,
>what faulkner proposed for linux (and Mac?), and something like
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474070 for
>windows.
.
.
.
Particularly when I hear "os-independent", I think first of
binding to a socket.  While http://wiki.tcl.tk/1558 >
is written for a Tcl-based crowd, the commentary there ap-
plies quite well to Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


About Embedding PyWin or wxPython

2006-07-24 Thread Mr. Roboto

Folks:  I want to embark on a project to add Python (actually, wxPython
or PythonWin) to a new Windows app I want to start writing soon.
Essentially, I want to take VB6 (or pos Delphi) and construct the app
framework/core functionality using one of those languages, then extend
the app w/ Python, the same way one can extend the MS Office apps
using VBA.  The core Python docs provide the fundamental info one
needs to get started.  But, I've been looking for some pointers to
articles/web pages that will bootstrap the effort, so I won't have to
completely reinvent the wheel.  So far, the c.l.p ngroup traffic (and
the web in general) that speaks to this subject is apparently pretty
sparse.  Since I'm a one-man show, it would be helpful if anyone could
offer pointers to sites/pages/books that address some of these issues:

1)  To COM or not ?  From an implementation standpoint, it seems
worthwhile to build the host app as a series of COM objects, which
could then be ref'd/manipulated via external Python code.  Not sure if
this makes sense from a performance-perspective, but I doubt the apps
I'm thinking about (mostly desk accessory utils kinda, sorta) are
going to be compute-intensive at all.

2)  SWIG or not ?  Have never used it, but know that SWIG has been
ref'd many times in the ngroup as an tool for facilitating the use of
Python as an embedded language.  Is SWIG worth the effort for a
relatively small (<10 KLOC) app ?

3)  Handling exceptions.  I want to start from Day One with a sensible
approach to debugging and testing both host objects and external
scripts.

4)  Deployment.  Size (30 - 50MB for wxPython or PyWin alone) and a
silent install of either pkg prior to installing the host app.

Regardless of the conversation in this group, I plan to get started in
the next few days.  This is how I'm currently looking at the above
issues:

1)  COM:  Yes, since COM seems like an easy fit w/o writing lotsa
glue code because of built-in support via PyWin

2)  SWIG:  Not for a 1st cut, at least not to get one's feet wet, so
to speak

3)  Exceptions:  No clue.  Need to closely read Extending/Embedding
Python for more guidance

4) Deployment: Bite the disk space bullet and use PyWin or wxPython as
is

Anyway, that's the beginning of the conversation.  If you have any
observations or suggestions, please feel free.  Later...MR

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


Re: prob with struct and byte order

2006-07-24 Thread John Machin
[EMAIL PROTECTED] wrote:
> ok. indeed i did do '' instead of ' '.
> here is an example of a message
> 'STX\x00\x00\x004\x00\x00\x00\xc8stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00state1man\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ENX'
>
> tohex gave me '53 54 58 00 00 00 34 00 00 00 c8 70 69 76 6f 74 72 61 63
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 74 72 61 63 31 70 69 76
> 6f 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 4e 58'

It may well have given you that, but *NOT* from the 'STXetcetc' string
you quote above.

>
> this is the login message (message type 200)

Perhaps you might consider giving examples of some other message
type(s) e.g. ones that have more data and less possibly sensitive info
than what are presumably usernames and passwords.

>
> i will try out your code sample when i get to work in the morning.

Do you actually have documentation of the individual fields in each
message type (like what is the maximum length of each of those
NUL-padded text fields in the login message")?
How many different message types are there?
Note that given a reasonably well laid out soft copy of the docs for
each message type, it would be quite within reason to write a fairly
short script to *generate* correct legible runnable Python code ...
it's scarcely a novel concept.

Cheers,
John

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


Re: Converting a web to pdf or ..‍

2006-07-24 Thread Colin J. Williams
Bayazee wrote:
> Hi ,
> I have a web site and i want to write a perogram with python that my
> users can convert custom web page of site to pdf (or other type :jpeg,
> doc,odt,or...) and download it . i dont want only convert text . it is
> be very good to i can don it for both text and images ... similar to
> web page ... can i do it with  ReportLab ??
> 
> ---
> Iranian Python Community --> www.python.ir
> 
You might consider using OpenOffice and talking to it through PyUno.

Colin W.

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


Re: find_longest_match in SequenceMatcher

2006-07-24 Thread John Machin

John Machin wrote:
> koara wrote:
> > John Machin wrote:
> There is a bug.
> I'll report it.

Reported.
http://sourceforge.net/tracker/index.php?func=detail&aid=1528074&group_id=5470&atid=105470

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


Re: prob with struct and byte order

2006-07-24 Thread nephish
ok. indeed i did do '' instead of ' '.
here is an example of a message
'STX\x00\x00\x004\x00\x00\x00\xc8stateman\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00state1man\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ENX'

tohex gave me '53 54 58 00 00 00 34 00 00 00 c8 70 69 76 6f 74 72 61 63
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 74 72 61 63 31 70 69 76
6f 74 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 4e 58'

this is the login message (message type 200)

i will try out your code sample when i get to work in the morning.

thanks, gents, for your time and attention on this

sk

John Machin wrote:
> Grant Edwards wrote:
> > On 2006-07-24, Steve Holden <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > >
> > >> now the 17758 is significant because it is the actual unit number of
> > >> the machine we want to monitor. I just dont know how to extract the
> > >> real values out of this message.
> >
> > What is meant by "real values"?
> >
>
> :-)
> I guess he means "real" as opposed to unreal/surreal/virtual/imagined,
> not as in the FORTRAN programmer's credo:
> """
> GOD is REAL
> JESUS is INTEGER
> """
> (-:

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


Re: micro authoritative dns server

2006-07-24 Thread Edmond Dantes
Jean-Paul Calderone wrote:

...
> Twisted includes a DNS server which is trivially configurable to perform
> this task.  Take a look.
> 
>   http://twistedmatrix.com/
>   http://twistedmatrix.com/projects/names/documentation/howto/names.html
> 
> Jean-Paul

On a tangential note:

If you want a DNS server to be updatable in real time from a database, then
you want PowerDNS:

http://www.powerdns.com/

I've been using this for quite some time now and it's great to be able to
add zones, etc. just by a new entry or two in the MySQL database.

It can interface to other databases as well. 

-- 
-- Edmond Dantes, CMC
And Now for something Completely Different:
  http://beadwork.SelfMadeDream.com
  http://dealership.anyhottips.com
  http://beanie.hugmykids.com
  http://jockey.AreYouTaken.com
  http://headset.GadgetRUs.com
  http://lighting.desktopgod.com
  http://portfolio.desktopgod.com


 Posted Via Usenet.com Premium Usenet Newsgroup Services
--
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
--
http://www.usenet.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: find_longest_match in SequenceMatcher

2006-07-24 Thread John Machin
koara wrote:
> John Machin wrote:
> > --test results snip---
> > Looks to me like the problem has nothing at all to do with the length
> > of the searched strings, but a bug appeared in 2.3.  What version(s)
> > were you using? Can you reproduce your results (500 & 499 giving
> > different answers) with the same version?
>
> Hello John, thank you for investigating and responding!
>
> Yes, I can reproduce the behaviour with different results within the
> same version -- which is 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310
> 32 bit (Intel)]
>
> The catch is to remove the last character, as i described in my
> original post, as opposed to passing reduced length parameters to
> find_longest_match, which is what you did.
>
> It is morning now, but i still fail to see the mistake i am making --
> if it is indeed a bug, where do i report it?
>

Further sniffing shows that we were both partially right/wrong:
There is a bug.
It is length-dependant.
It was introduced in Python 2.3.

If you want to, you can hack your copy of
/Lib/difflib.py
so that line 316 reads:
if 0:
instead of:
if n >= 200 and len(indices) * 100 > n:

I'll report it.

Cheers,
John

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


Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread Joe Knapka
Grant Edwards wrote:

> On 2006-07-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
> 
>>>Logs of the serial traffic would be helpful.
>>
>>Here they are. First a log of the traffic generated by the
>>T-logger GUI program, abtained with Portmon.
> 
> 
> I try to avoid Windows as much as humanly possible, but one
> thing that appears to be different is that Tlogger clears RTS
> and your program sets it.  Try clearing RTS in your program
> when you set up the serial port.
> 
> If clearing RTS doesn't help, I guess I'd try different flow
> control settings (try enabling and disabling RTS/CTS flow
> control).
> 
> Since you're dealing with binary data, make sure that Xon/Xoff
> flow control is disabled.

It could also be a timing issue or handshaking problem.
Having to write to the chip "a byte at a time" implies
that it could take it a little while to digest each byte;
longer than the natural character time for the baud rate,
that is. I'm not sure if I'm reading the portmon output
correctly, but it looks like the "T-logger" program
is waiting for CTS (or possibly some other condition)
before sending each byte. The Python program does not
appear to be doing so, it's just sending the three bytes,
bang bang bang.

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


Re: Search within running python scripts

2006-07-24 Thread Simon Forman
gmax2006 wrote:
> Simon Forman wrote:
> > gmax2006 wrote:
> > > Hi,
> > >
> > > Is it possible that a python script finds out whether another instance
> > > of it is currently running or not?
> > >
> > > Thank you,
> > > Max
> >
> > Yes, there are several ways.  What OS are you using?
> >
> > ~Simon
>
> I have to use an os-independent approach.
>
> At this point I use a file as running-flag. It doesn't work so good.
> Because if the python application breaks or get terminated, it won't
> run again unless somebody deletes the flag file.
>
> Alan

Hmm,  I'm very far from being an expert on this, so hopefully someone
who knows better will reply.
You might have to check the OS your script is running on and do, say,
what faulkner proposed for linux (and Mac?), and something like
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474070 for
windows.

HTH,
~Simon

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


Re: micro authoritative dns server

2006-07-24 Thread Jean-Paul Calderone
On 24 Jul 2006 14:45:25 -0700, [EMAIL PROTECTED] wrote:
>Hi,
>
>I'm new in python. I know that there are several classes for writing
>dns servers, but I don't understand it
>
>I just want to know if anyone could help me in writing a code for
>minimal authoritative dns server. I would like that anyone show me the
>code, minimal, for learn how expand it.
>
>The code I desireed should do the following:
>
>1) It has an hash:
>hosts = { "myhost"   => 84.34.56.67
>"localhost" => 127.0.0.1,
>"blue"  => fe80::20f:b0ff:fef2:f106
> }
>2) If any application asks if know any hosts, say nothing if this host
>is not in the hash (hosts). If this host is in the hash, return the ip
>3) And not do anything more
>
>So if we put this server in /etc/resolv.conf then the browsers only
>recognize the hosts we want

Twisted includes a DNS server which is trivially configurable to perform
this task.  Take a look.

  http://twistedmatrix.com/
  http://twistedmatrix.com/projects/names/documentation/howto/names.html

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


micro authoritative dns server

2006-07-24 Thread xan2
Hi,

I'm new in python. I know that there are several classes for writing
dns servers, but I don't understand it

I just want to know if anyone could help me in writing a code for
minimal authoritative dns server. I would like that anyone show me the
code, minimal, for learn how expand it.

The code I desireed should do the following:

1) It has an hash:
hosts = { "myhost"   => 84.34.56.67
"localhost" => 127.0.0.1,
"blue"  => fe80::20f:b0ff:fef2:f106
 }
2) If any application asks if know any hosts, say nothing if this host
is not in the hash (hosts). If this host is in the hash, return the ip
3) And not do anything more

So if we put this server in /etc/resolv.conf then the browsers only
recognize the hosts we want

Thanks in advance,
Xan.

PS: For personal communication, DXpublica @ telefonica.net

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


Re: How to force a thread to stop

2006-07-24 Thread Jean-Paul Calderone
On Mon, 24 Jul 2006 13:51:07 -0700, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> 
wrote:
>Jean-Paul Calderone wrote:
>> On Mon, 24 Jul 2006 11:22:49 -0700, "Carl J. Van Arsdall" <[EMAIL 
>> PROTECTED]> wrote:
>>
>>> Steve Holden wrote:
>>>
 Carl J. Van Arsdall wrote:
 [... rant ...]


> So with this whole "hey mr. nice thread, please die for me" concept gets
> ugly quickly in complex situations and doesn't scale well at all.
> Furthermore, say you have a complex systems where users can write
> pluggable modules.  IF a module gets stuck inside of some screwed up
> loop and is unable to poll for messages there's no way to kill the
> module without killing the whole system.  Any of you guys thought of a
> way around this scenario?
>
>
>
>
 Communications through Queue.Queue objects can help. But if you research
 the history of this design decision in the language you should discover
 there are fairly sound rasons for not allowing arbitrary "threadicide".




>>> Right, I'm wondering if there was a way to make an interrupt driven
>>> communication mechanism for threads?  Example: thread receives a
>>> message, stops everything, and processes the message.
>>>
>>>
>>
>> And what happens if the thread was halfway through a malloc call and
>> the data structures used to manage the state of the heap are in an
>> inconsistent state when the interrupt occurs?
>>
>> This has been discussed many many times in the context of many many
>> languages and threading libraries.  If you're really interested, do
>> the investigation Steve suggested.  You'll find plenty of material.
>>
>
>I've been digging around with Queue.Queue and have yet to come across
>any solution to this problem.

Right.  Queue.Queue doesn't even try to solve this problem.

>Queue.Queue just offers a pretty package 
>for passing around data, it doesn't solve the "polling" problem.

Exactly correct.

>I 
>wonder why malloc()'s can't be done in an atomic state (along with other
>operations that should be atomic, maybe that's a question for OS guys, I
>dunno).

(Note that malloc() is just a nice example - afaik it is threadsafe on
all systems which support threading at all)

Because it turns out that doing things atomically is difficult :)

It's not even always obvious what "atomic" means.  But it's not impossible
to do everything atomically (at least not provably ;), and in fact many
people try, most commonly by using mutexes and such.

However, unless one is extremely disciplined, critical sections generally
get overlooked.  It's often very difficult to find and fix these, and in
fact much of the time no one even notices they're broken until long after
they have been written, since many bugs in this area only surface under
particular conditions (ie, particular environments or on particular
hardware or under heavy load).

>Using Queue.Queue still puts me in a horribly inflexible
>"polling" scenario.  Yea, I understand many of the reasons why we don't
>have "threadicide", and why it was even removed from java.  What I don't
>understand is why we can't come up with something a bit better.  Why
>couldn't a thread relinquish control when its safe to do so?  

Of course, if you think about it, CPython does exactly this already.  The
GIL ensures that, at least on the level of the interpreter itself, no
thread switching can occur while data structures are in an inconsistent
state.  This works pretty well, since it means that almost anything you do
at the application level in a multithreaded application won't cause random
memory corruption or other fatal errors.

So why can't you use this to implement killable threads in CPython?  As it
turns out, you can ;)  Recent versions of CPython include the function
PyThreadState_SetAsyncExc.  This function sets an exception in another
thread, which can be used as a primitive for killing other threads.

Why does everyone say killing threads is impossible, then?  Well, for one
thing, the CPython developers don't trust you to use SetAsyncExc correctly,
so it's not exposed to Python programs :)  You have to wrap it yourself
if you want to call it.  For another thing, the granularity of exceptions
being raised is somewhat sketchy: an exception will not be raised while
a single bytecode operation is being executed.  Exceptions set with this
function will only be raised /between/ the execution of two bytecode
operations.

But this is just what you described above.  The thread is checking for
messages at certain intervals but only while all of its internal state
is consistent.  The problem here is that the granularity of a bytecode
being executed is pretty variable.  Some operations might take only a
microsecond.  Other operations might take a week.  This might be useful
in some specific contexts, but it's definitely not a general solution.


>While the
>interpreter is busy doing malloc()s a thread receives a control message,
>the thread waits unt

Re: How to force a thread to stop

2006-07-24 Thread Carl J. Van Arsdall
Steve Holden wrote:
> Carl J. Van Arsdall wrote:
>   
>
>>
>> 
> I take this to mean you don't want to do the necessary research? ;-)
>   
Well, i've been looking at this on and off for quite some time now, I 
almost feel like I've seen it all in regards to the "thread killer" 
scenario.  It could be that i'm not finding or understanding the answers 
I'm getting from google.  But after the last email I sat here with my 
python book, the python cook book, the python module reference, and 
google for a few minutes before responding.  I swear... i'm not THAT 
lazy.  Just curious and uninformed!  Questions of event driven python 
generally lead me to twisted.  I will admit that I haven't read much 
about that yet.

>> There is no system that is completely interruptible, there will always 
>> be a state in which it is not safe to interrupt, but many systems work 
>> around this just fine with cautious programming.  Has anyone considered 
>> an event driven approach to sending control messages to threads?
>>
>> 
> The big problem (as you'll see when you ...) is providing facilities 
> that are platform-independent.
>
>   
Ah, I could see that.  I think before I can make any suggestions on this 
front I need to start reading python source code.

Gracias,

Carl




-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: installing numpy: problems with lapack, blas etc

2006-07-24 Thread Robert Kern
Ken Dere wrote:
> I am trying to install numpy-0.9.8 prior to installing scipy (0.4.9) on a
> machine running Suse 10.0 with Python 2.4

Please join us on the numpy mailing list.

   http://www.scipy.org/Mailing_Lists

However, you should know now that Suse ships an incomplete ATLAS-optimized 
LAPACK library, and you will have to do some extra steps to get one that works. 
See this thread:

   http://projects.scipy.org/pipermail/scipy-user/2006-July/008681.html

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: prob with struct and byte order

2006-07-24 Thread John Machin

Grant Edwards wrote:
> On 2006-07-24, Steve Holden <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >
> >> now the 17758 is significant because it is the actual unit number of
> >> the machine we want to monitor. I just dont know how to extract the
> >> real values out of this message.
>
> What is meant by "real values"?
>

:-)
I guess he means "real" as opposed to unreal/surreal/virtual/imagined,
not as in the FORTRAN programmer's credo:
"""
GOD is REAL
JESUS is INTEGER
"""
(-:

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


Re: prob with struct and byte order

2006-07-24 Thread John Machin

[EMAIL PROTECTED] wrote:

> the starting and ending deliminators are ASCII 'STX' and 'ENX'. i
> wondered why they did it like that also. But they did.
>
> the message length is a 4 byte integer indicating how long the message
> body is.
> the message type is also 4 bytes. There is a table in the docs that
> describe what each message type is. for example 200 = login,
> etc...etc...
>
> the big deal in the docs goes on about how the clients need the byte
> order to match that of the arch that the server runs on 'Sun
> UltraSPARC' , i think they run Solaris.
>
> if i sound like i do not know what i am talking about... there is a
> reason...  i am very new to this type of communication with the server.
> I have about 6 months with python ( my first language ).
>

Perhaps if you could post
(a) the *FULL* docs for one record type -- it's not apparent whether
you have these or not; Grant is trying to show you how to do elementary
data detective work ...
(b) the Python repr() of an example or two of that record type
(c) what you expect (or are told) that example data means,
we could post back some sample complete code with a bit of explanation

Cheers,
John

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


Re: Search within running python scripts

2006-07-24 Thread gmax2006

Simon Forman wrote:
> gmax2006 wrote:
> > Hi,
> >
> > Is it possible that a python script finds out whether another instance
> > of it is currently running or not?
> >
> > Thank you,
> > Max
>
> Yes, there are several ways.  What OS are you using?
>
> ~Simon

I have to use an os-independent approach.

At this point I use a file as running-flag. It doesn't work so good.
Because if the python application breaks or get terminated, it won't
run again unless somebody deletes the flag file.

Alan

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


Re: How to force a thread to stop

2006-07-24 Thread Steve Holden
Carl J. Van Arsdall wrote:
> Jean-Paul Calderone wrote:
[...]
>>This has been discussed many many times in the context of many many
>>languages and threading libraries.  If you're really interested, do
>>the investigation Steve suggested.  You'll find plenty of material.
>>  
> 
> 
> I've been digging around with Queue.Queue and have yet to come across 
> any solution to this problem.  Queue.Queue just offers a pretty package 
> for passing around data, it doesn't solve the "polling" problem.  I 
> wonder why malloc()'s can't be done in an atomic state (along with other 
> operations that should be atomic, maybe that's a question for OS guys, I 
> dunno).  Using Queue.Queue still puts me in a horribly inflexible 
> "polling" scenario.  Yea, I understand many of the reasons why we don't 
> have "threadicide", and why it was even removed from java.  What I don't 
> understand is why we can't come up with something a bit better.  Why 
> couldn't a thread relinquish control when its safe to do so?  While the 
> interpreter is busy doing malloc()s a thread receives a control message, 
> the thread waits until it knows its no longer in an atomic state and 
> gives control to the message handler when it can.  Its about setting up 
> a large system that is controllable without the painstaking process of 
> putting message polling loops all over the place.  Main threads in a 
> python program can setup a signal handler, accept signals, and that 
> signal can happily go ahead and kill a python interpreter.  Why can't 
> this concept be taken farther and introduced into threading? 
> 
I take this to mean you don't want to do the necessary research? ;-)

> There is no system that is completely interruptible, there will always 
> be a state in which it is not safe to interrupt, but many systems work 
> around this just fine with cautious programming.  Has anyone considered 
> an event driven approach to sending control messages to threads?
> 
The big problem (as you'll see when you ...) is providing facilities 
that are platform-independent.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


installing numpy: problems with lapack, blas etc

2006-07-24 Thread Ken Dere
I am trying to install numpy-0.9.8 prior to installing scipy (0.4.9) on a
machine running Suse 10.0 with Python 2.4

I am able to get numpy installed to the point when I import it I can do the
following:


numpy.show_config()
atlas_threads_info:
  NOT AVAILABLE

blas_opt_info:
libraries = ['f77blas', 'cblas', 'atlas']
library_dirs = ['/usr/lib/atlas']
define_macros = [('ATLAS_INFO', '"\\"3.6.0\\""')]
language = c

atlas_blas_threads_info:
  NOT AVAILABLE

lapack_opt_info:
libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
library_dirs = ['/usr/lib/atlas']
define_macros = [('ATLAS_INFO', '"\\"3.6.0\\""')]
language = c

atlas_info:
libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
library_dirs = ['/usr/lib/atlas']
language = c

lapack_mkl_info:
  NOT AVAILABLE

blas_mkl_info:
  NOT AVAILABLE

atlas_blas_info:
libraries = ['f77blas', 'cblas', 'atlas']
library_dirs = ['/usr/lib/atlas']
language = c

mkl_info:
  NOT AVAILABLE

It is clear that I have much but not all that is needed.  I have already
downloaded lapack and compiled the blas and lapack libraries and put them
in /usr/lib/atlas and defined BLAS and LAPACK so I am not sure what I have
missed.

Thanks

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


using Jython in Websphere 6.0

2006-07-24 Thread alfa1234
Used the following command to extract correct commandLine arguments to
Automate deployment:

AdminApp.installInteractive('z:/Builds_test/sgs/sgs-procDist.ear')

Got the following Args to use for deployment..

install 'z:/Builds_test/sgs/sgs-procDist.ear'  '[  -preCompileJSPs
-installed.ear.destination
d:/WebSphere/AppServer/profiles/profileStandAlone/installedApps/TESTND1Network
-distributeApp -nouseMetaDataFromBinary -nodeployejb -appname
SGSProcedure -createMBeansForResources -noreloadEnabled -nodeployws
-validateinstall warn -noprocessEmbeddedConfig -MapModulesToServers
[["SGS Wizard" sgs-procDist.war,WEB-INF/web.xml
WebSphere:cell=TESTND1Network,node=IIS,server=webserver+WebSphere:cell=TESTND1Network,cluster=SGSProcedure]]
-MapWebModToVH [["SGS Wizard" sgs-procDist.war,WEB-INF/web.xml
default_host]]]'


When trying to execute command below via "wsadmin -lang jython"
commanfpromt I got the error below..??? Can anyone HELP ??

Traceback (innermost last):
  (no code object) at line 0
  File "", line 1
AdminApp.install 'z:/Builds_test/sgs/sgs-procDist.ear' '[
-preCompileJS
Ps -installed.ear.destination
d:/WebSphere/AppServer/profiles/profileStandAlone/
installedApps/TESTND1Network -distributeApp -nouseMetaDataFromBinary
-nodeployej
b -appname SGSProcedure -createMBeansForResources -noreloadEnabled
-nodeployws -
validateinstall warn -noprocessEmbeddedConfig -MapModulesToServers
[["SGS Wizard
" sgs-procDist.war,WEB-INF/web.xml
WebSphere:cell=TESTND1Network,node=IIS,server
=webserver+WebSphere:cell=TESTND1Network,cluster=SGSProcedure]]]'
 ^
SyntaxError: invalid syntax
wsadmin>

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


Re: Type signature

2006-07-24 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, paul kölle
wrote:

> Marc 'BlackJack' Rintsch wrote:
>> In <[EMAIL PROTECTED]>, Yacao Wang
>> wrote:
>> 
>>> However, type signatures are not only a kind of information provided for
>>> the compiler, but also for the programmer, or more important, for the
>>> programmer. Without it, we have to "infer" the return type or required
>>> agument types of a function, and this can't be done without seeing the
>>> implementation of it,
>> 
>> That's what documentation is meant for.  If you are forced to look at the
>> implementation, the documentation is bad.
> I think the OP refers to reading the *code*, the documentation might not
> exist (yet).

It should be right there under the `def` as docstring.

> Sometimes I feel python is easier to write than to read and
>  missing argument type declarations (just for documentation purposes)
> are  IMHO one reason. Another are missing (optional) argument type
> checks at runtime. Something like WrongArgumentType exceptions instead
> of rather unspecific AttributeError from deep inside the code would be
> very convenient.

The you start getting `WrongArgumentType` exceptions sooner or later for
arguments that have all the necessary attributes in place but are of the
wrong "type".  Very inconvenient.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread Grant Edwards
On 2006-07-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>> Logs of the serial traffic would be helpful.
>
> Here they are. First a log of the traffic generated by the
> T-logger GUI program, abtained with Portmon.

I try to avoid Windows as much as humanly possible, but one
thing that appears to be different is that Tlogger clears RTS
and your program sets it.  Try clearing RTS in your program
when you set up the serial port.

If clearing RTS doesn't help, I guess I'd try different flow
control settings (try enabling and disabling RTS/CTS flow
control).

Since you're dealing with binary data, make sure that Xon/Xoff
flow control is disabled.

-- 
Grant Edwards   grante Yow!  What's the MATTER
  at   Sid?... Is your BEVERAGE
   visi.comunsatisfactory?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using names before they're defined

2006-07-24 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
>>>First case is a little shorter but then you have to use a parser for it
>>
>>There's one builtin.
> 
> 
> do you mean 'configparser'? 

Yes.

> I'm just trying to figure out how this
> works. 

One nice thing with Python is the interactive python shell. It makes 
exploring a package a breeze.

> Does it generate objects from the config file automatically?

It generates a representation of the config file as a Python object 
composed of sections and options. The documentation should get you started.

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


Re: How to force a thread to stop

2006-07-24 Thread Carl J. Van Arsdall
Jean-Paul Calderone wrote:
> On Mon, 24 Jul 2006 11:22:49 -0700, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> 
> wrote:
>   
>> Steve Holden wrote:
>> 
>>> Carl J. Van Arsdall wrote:
>>> [... rant ...]
>>>
>>>   
 So with this whole "hey mr. nice thread, please die for me" concept gets
 ugly quickly in complex situations and doesn't scale well at all.
 Furthermore, say you have a complex systems where users can write
 pluggable modules.  IF a module gets stuck inside of some screwed up
 loop and is unable to poll for messages there's no way to kill the
 module without killing the whole system.  Any of you guys thought of a
 way around this scenario?



 
>>> Communications through Queue.Queue objects can help. But if you research
>>> the history of this design decision in the language you should discover
>>> there are fairly sound rasons for not allowing arbitrary "threadicide".
>>>
>>>
>>>
>>>   
>> Right, I'm wondering if there was a way to make an interrupt driven
>> communication mechanism for threads?  Example: thread receives a
>> message, stops everything, and processes the message.
>>
>> 
>
> And what happens if the thread was halfway through a malloc call and
> the data structures used to manage the state of the heap are in an
> inconsistent state when the interrupt occurs?
>
> This has been discussed many many times in the context of many many
> languages and threading libraries.  If you're really interested, do
> the investigation Steve suggested.  You'll find plenty of material.
>   

I've been digging around with Queue.Queue and have yet to come across 
any solution to this problem.  Queue.Queue just offers a pretty package 
for passing around data, it doesn't solve the "polling" problem.  I 
wonder why malloc()'s can't be done in an atomic state (along with other 
operations that should be atomic, maybe that's a question for OS guys, I 
dunno).  Using Queue.Queue still puts me in a horribly inflexible 
"polling" scenario.  Yea, I understand many of the reasons why we don't 
have "threadicide", and why it was even removed from java.  What I don't 
understand is why we can't come up with something a bit better.  Why 
couldn't a thread relinquish control when its safe to do so?  While the 
interpreter is busy doing malloc()s a thread receives a control message, 
the thread waits until it knows its no longer in an atomic state and 
gives control to the message handler when it can.  Its about setting up 
a large system that is controllable without the painstaking process of 
putting message polling loops all over the place.  Main threads in a 
python program can setup a signal handler, accept signals, and that 
signal can happily go ahead and kill a python interpreter.  Why can't 
this concept be taken farther and introduced into threading? 

There is no system that is completely interruptible, there will always 
be a state in which it is not safe to interrupt, but many systems work 
around this just fine with cautious programming.  Has anyone considered 
an event driven approach to sending control messages to threads?

-c

 





-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: When writing text. . .

2006-07-24 Thread Ivan Shevanski
On 7/14/06, Gerhard Fiedler <[EMAIL PROTECTED]> wrote:
On 2006-07-14 18:05:56, Ivan Shevanski wrote:> Hey I'm pretty new to python and I have a question.  I'm trying to write:> "[BOOT]> run=C:\windows\aawin.bat">> in my win.ini
> So I went about it like this:>> win = open('C:\windows\win.ini', 'a')> win.write('[BOOT]')> win.write('\n')> win.write('run=C:\windows\aawin.bat')Maybe write a '\n' before the [BOOT] -- unless you can guarantee that the
previous line ends with a CRLF.BTW, it's probably a good thing to always escape the backslash (that is,use '\\') when you want a backslash, not only for the '\\a' case. Or ofcourse use a raw string.
Gerhard--http://mail.python.org/mailman/listinfo/python-listSorry about the late response, I was away.  Thanks for all the help =D
-- -Ivan
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Nested function scope problem

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 17:09:24, Steve Holden wrote:

> Would I do? 

It seems so :)

> If there's a binding to a name *anywhere* in the function's body then
> that name is treated as local to the function. 
> 
> This is a matter of static analysis, and is irrespective of where in the
> body the assignment is found. 

One difficulty I'm having is knowing the proper terminology when looking
for an effect like this. Just someone rephrasing the question using the
proper terms already helps a lot. "Binding" seems to be the keyword here.

It is surprising in the sense that binding seems not to be necessary for
read access. 


Going back to the original question... What would be the most common/useful
way to access variables from the outer function for writing from within the
inner function?

Thanks,
Gerhard

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


Re: Functions, Operators, and Overloading?

2006-07-24 Thread Bruno Desthuilliers
Michael Yanowitz a écrit :
> Hello:
> 
>Maybe I am missing something, but from what I've seen,
> it is not possible to overload functions in Python. That
> is I can't have a
>   def func1 (int1, string1):
>and a 
>   def func1 (int1, int3, string1, string2):
> without the second func1 overwriting the first.

You may want to have a look at Philip Eby's dispatch package. Here's an 
introduction:
http://peak.telecommunity.com/DevCenter/VisitorRevisited

>However, operators can be overloaded.
>So can I define a new operator? 

No.

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


Re: unittest ValueError

2006-07-24 Thread Steve Holden
Chris Fonnesbeck wrote:
> I have built the following unit test, observing the examples laid out
> in the python docs:
> 
> class testMCMC(unittest.TestCase):
> 
> def setUp(self):
> 
> # Create an instance of the sampler
> self.sampler = DisasterSampler()
> 
> def testCoalMiningDisasters(self):
> """Run coal mining disasters example sampler"""
> 
> print 'Running coal mining disasters test case ...'
> 
> # Specify the nimber of iterations to execute
> iterations = 1
> thin = 2
> burn = 5000
> chains = 2
> 
> # Run MCMC simulation
> for i in range(chains):
> 
> self.failUnless(self.sampler.sample(iterations, burn=burn,
> thin=thin, plot=True))
> 
> # Run convergence diagnostics
> self.sampler.convergence()
> 
> # Plot autocorrelation
> self.sampler.autocorrelation()
> 
> # Goodness of fit
> self.failIf(self.sampler.goodness(iterations/10)['overall'] < 0.05)
> 
> 
> def test():
> # Run unit tests
> unittest.main()
> 
> However, when I run test() from the python shell, it dies:
> 
> In [2]: test()
> 
> --
> Ran 0 tests in 0.000s
> 
> OK
> ---
> exceptions.SystemExitTraceback (most
> recent call last)
> 
> /Users/chris/
> 
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/PyMC/MCMC.py
> in test()
>2986
>2987 def test():
>2988 # Run unit tests
> -> 2989 unittest.main()
> global unittest.main = 
>2990
> 
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
> in __init__(self=,
> module='__main__', defaultTest=None, argv=['/usr/local/bin/ipython'],
> testRunner=None, testLoader=)
> 757 self.progName = os.path.basename(argv[0])
> 758 self.parseArgs(argv)
> --> 759 self.runTests()
> self.runTests =  >
> 760
> 761 def usageExit(self, msg=None):
> 
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
> in runTests(self=)
> 795 self.testRunner = TextTestRunner(verbosity=self.verbosity)
> 796 result = self.testRunner.run(self.test)
> --> 797 sys.exit(not result.wasSuccessful())
> global sys.exit = 
> result.wasSuccessful =  _TextTestResult.wasSuccessful of  errors=0 failures=0>>
> 798
> 799 main = TestProgram
> 
> SystemExit: False
> Type exit or quit to exit IPython (%Exit or %Quit do so unconditionally).
> 
> In [3]: from PyMC import testMCMC
> 
> In [4]: foo = testMCMC()
> ---
> exceptions.ValueErrorTraceback (most
> recent call last)
> 
> /Users/chris/
> 
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
> in __init__(self=,
> methodName='runTest')
> 206 self.__testMethodDoc = testMethod.__doc__
> 207 except AttributeError:
> --> 208 raise ValueError, "no such test method in %s: %s" % \
> global ValueError = undefined
> self.__class__ = 
> methodName = 'runTest'
> 209   (self.__class__, methodName)
> 210
> 
> ValueError: no such test method in : runTest
> 
> 
> I have no idea why this is happening. My TestCase class begins with
> "test", the method begins with "test", yet no tests are seen. Also, I
> do not get the runTest ValueError. I assumed that you get this method
> for free win TestCase. The examples certainly do not have this method,
> so I am not sure what the problem is.
> 
> Thanks for any help,

Well, it would make a lot more sense to set the test up to be run as a 
main program with

if __name__ == "__main__":
 test()

at the end, then run it. When I did so with your code (after adding an 
import of the unittest module) I got

C:\Steve\Projects\Python>test47.py
E
==
ERROR: Run coal mining disasters example sampler
--
Traceback (most recent call last):
   File "C:\Steve\Projects\Python\test47.py", line 9, in setUp
 self.sampler = DisasterSampler()
NameError: global name 'DisasterSampler' is not defined

--
Ran 1 test in 0.000s

FAILED (errors=1)

This just shows me that more code is missing. Hope this helps.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Nested function scope problem

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 16:51:56, danielx wrote:

> Gerhard's reply sounded not so confident. 

Yes, it is not. It's just the conclusion I drew from my experiments. (I'm
still all wet behind the ears WRT Python...)

As long as there was no write access to the variable, the inner function
could read the value just fine. When there was a write access, the first
read (if it was before the write access) bombed with that error message
that there was a read without a previous write. (Actually, it wasn't a
simple read, it was that "len(var)" access. I'm not sure a normal read
would bomb the same way. But the error message was that it was a read
access without a previous write.)

So that was just my conclusion. It is also consistent with the observation
that variables seem to be known in their scope, even before the location of
their first appearance. 

> Can we have someone who "really" knows weigh in on this? 

That would be nice :)

Gerhard

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


Re: Nested function scope problem

2006-07-24 Thread Steve Holden
danielx wrote:
> Gerhard Fiedler wrote:
[...]
>>Yes, but it is the line "tok = ''" that seems to cause tok to be now a
>>variable of the inner function's scope (rather than the variable tok of
>>breakLine).
> 
> 
> OHH! Yes, that sounds like it could be it. Wow, to me, that behavior is
> eXtremely unexpected (there's lisp popping up its ugly head again :P).
> So you're saying that because an assignment to tok appears later within
> the def for addTok, that the line if len(tok) won't try to look in
> enclosing local scopes? (If such things even exist...)
> 
> Gerhard's reply sounded not so confident. Can we have someone who
> "really" knows weigh in on this? Thanks!
> 
Would I do? If there's a binding to a name *anywhere* in the function's 
body then that name is treated as local to the function. This is a 
matter of static analysis, and is irrespective of where in the body the 
assignment is found.

Of course, you could always test this yourself in interactive mode ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Search within running python scripts

2006-07-24 Thread faulkner
IPC via files, sockets, and shared memory are all readily available in
python.
the simplest way is to have the script write its pid to a certain file.

pidfn = '/tmp/hellowerld_ipc_pid'
if os.path.isfile(pidfn):
f = file(pidfn)
pid = f.read()
f.close()
if pid in os.popen('ps -A -o pid').read():
print "another instance of me is running!"
else:
f = file(pidfn, 'w')
f.write(str(os.getpid()))
f.close()


gmax2006 wrote:
> Hi,
>
> Is it possible that a python script finds out whether another instance
> of it is currently running or not?
> 
> Thank you,
> Max

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


Re: Search within running python scripts

2006-07-24 Thread Simon Forman
gmax2006 wrote:
> Hi,
>
> Is it possible that a python script finds out whether another instance
> of it is currently running or not?
>
> Thank you,
> Max

Yes, there are several ways.  What OS are you using?

~Simon

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


Re: Nested function scope problem

2006-07-24 Thread danielx
Gerhard Fiedler wrote:
> On 2006-07-23 14:53:33, danielx wrote:
>
> > I can't figure out why Josiah's breakLine function won't work either. I
> > know Josiah has had his problem resolved, but I'd still like to know
> > why his func won't work. I'd like to redirect this discussion in that
> > direction, if I may.
>
> I think what happens is this (and this may not be expressed in the proper
> terms for Python): It is possible to read variables from the outer function
> in the inner function. But when trying to write to them, this causes that
> same name to be re-defined in the inner function's scope, making it a
> different variable. Now, in the OP's code, that caused that new variable
> (with scope of the inner function) to be accessed before anything was
> assigned to it.
>
> One obvious way is to not write to the variables from the outer scope, but
> rather return a value from the inner function and assign it in the outer
> function. But it seems there should be a way to be able to write in the
> inner function to variables that are defined in the outer function.
>
>
> >> First point: the nested function only have access to names that exists
> >> in the enclosing namespace at the time it's defined.
> >
> > Coming from lisp, that doesn't make very much sense, and I'm not sure
> > that's true. If you move the def for addTok bellow the lines that
> > initialize the locals of breakLines, you still get the same problem.
>
> The problem there is only secondarily a scope problem. At first it is
> reading a variable (the inner function scope variable tok) before anything
> has been assigned to it. Of course, the real problem is the secondary one:
> that this variable tok is a variable of scope addTok and not of scope
> breakLine.
>
> >> Second point: a nested function cannot rebind names from the enclosing
> >> namespace. Note that in Python, rebinding a name and modifying the
> >> object bound to a name are very distinct operations.
> >
> > I'm not sure that's the problem, because when I ran the debugger, the
> > problem is with the line that says if len(tok), not the one bellow it
> > which says tok = "". Regardless, my above issue seems to be overriding
> > this one.
>
> Yes, but it is the line "tok = ''" that seems to cause tok to be now a
> variable of the inner function's scope (rather than the variable tok of
> breakLine).

OHH! Yes, that sounds like it could be it. Wow, to me, that behavior is
eXtremely unexpected (there's lisp popping up its ugly head again :P).
So you're saying that because an assignment to tok appears later within
the def for addTok, that the line if len(tok) won't try to look in
enclosing local scopes? (If such things even exist...)

Gerhard's reply sounded not so confident. Can we have someone who
"really" knows weigh in on this? Thanks!

>
>
> > After some experimentation, I am completely baffeled as to why
> > breakLine won't work. Here is an example of one of the things I did,
> > which I believe exactly mimics what breakLine does:
> >
>  def outer():
> > ... def inner():
> > ... if outerLocal:
> > ... return "I hear you, 'hello world'."
> > ... else:
> > ... return "Come again?"
> > ... outerLocal = "hello world"
> > ... return inner()
> > ...
>  outer()
> > "I hear you, 'hello world'."
> >
> > As I said, I believe the line which sets tok should break (quietly),
> > but not the line which tests tok. My experiment seems to confirm
> > this...
>
> The line that sets tok causes tok to be a different tok from the outer tok
> -- in the whole scope of the assignment.
> 
> Gerhard

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


Re: random shuffles

2006-07-24 Thread Boris Borcic
Paul Rubin wrote:
> Boris Borcic <[EMAIL PROTECTED]> writes:
>> To be more convincing... assume the algorithm is optimal and calls
> 
> That assumption is not even slightly realistic.  Real-world sorting
> algorithms almost never do a precisely minimal amount of comparison.

'optimal' or 'minimal amount of comparisons' does not mean here to make just 
the 
right n-1 comparisons between successive items to verify the order of n items, 
but rather that no strict subset of the comparisons made to sort some data is 
sufficient to sort that data.

IOW "minimal" in "minimal amount of comparisons" refers not to the total 
ordering by size of the sets of comparisons made, but to the partial ordering 
by 
set inclusion of these sets.

And in this sense, it is clear that quicksort for instance is optimal*

It is easy to see, when you detail this algorithm, that never during its run is 
the result of a comparison it makes, preordained by comparisons already made; 
iow : it doesn't make superfluous or redundant comparisons.

Do you mean quicksort-like algorithms aren't real-world ?

Best, BB
--

*assuming a variant, like the following for illustration, that doesn't waste 
info on equal items.

def qsort(items,cmp) :
 if len(items)<2 : return items
 pivot = items[0]
 divide = [[pivot],[],[]]
 for item in items[1:] :
 divide[cmp(item,pivot)].append(item)
 return qsort(divide[-1],cmp)+divide[0]+qsort(divide[1],cmp)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comment on this script. Possible error in communication with list arg between functions

2006-07-24 Thread Phoe6
Juho Schultz wrote:
> I think return values should be used for communication between
> functions. Maybe something like this could work for you (not tested).
>
> def checkForRpm(rpmname):
> # 
> # Strings with 0 lenght are False
> if output:
> print output
> else:
> print rpmname + ' is not installed'
> return output
>
> def checkPreReqs():
> missingRpms = []
> for requiredRpm in listOfRpms:
> if not checkForRpm(requiredRpm):
> missingRpms.append(requiredRpm)
> # you could also do this by a list comprehension
> missingRpms = [reqRpm for reqRpm in listOfRpms if not
> checkForRpm(reqRpm)]
> # or you could use the builtin function filter() - see
> filter.__doc__ for that

Thanks Juho. I got the logic to workout the problem and I was able to
solve it. There was bit alteration of my code was required. Its working
now. Thanks.
---
def checkForRpm(rpmname):
''' Check for the presence of the RPM. '''
cin,cout,cerr = os.popen3('rpm -q ' + rpmname)
rpmStatus = cout.read()
print rpmStatus,
return rpmStatus



def preReqCheckRpms():
''' Check for the required RPMS '''
listOfRpms =
['firefox','senthil','binutils','gcc','cpp','glibc-devel','glibc-headers','glibc-kernheaders','compat-db','compat-gcc','compat-gcc-c++','compat-libstdc++','compat-libstdc++-devel','gnome-libs','openmotif21','setarch']
missingRpms = []
for requiredRpm in listOfRpms:
if checkForRpm(requiredRpm).find('is not installed') >
0:
missingRpms.append(requiredRpm)
if missingRpms:
print 'The following RPMS are not installed:'
for eachMissingRpm in missingRpms:
print eachMissingRpm
print 'Please install them for the installation to
continue.'
sys.exit(-1)


 
---

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


Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread alexandre_irrthum
Thanks Grant,

> Can you verify that the device is actually responding by
> watching the data line with an oscilloscope?

I don't have an oscilloscope but the device does respond (LED blinks)
when I send it a test command (44H).

> I take it that means that other programs are able to read from
> the device?

Yes, the device comes with a little GUI program to read the logged
temperatures, calibrate, etc... Works fine, but I would like to read
distributed loggers over the network with python and sockets.

> Logs of the serial traffic would be helpful.

Here they are. First a log of the traffic generated by the T-logger GUI
program, abtained with Portmon.

### TRAFFIC WHEN THE PROGRAM IS LAUNCHED:

0  0.  TLogger.exe  IRP_MJ_CREATE  Serial0  Options: Open
0  0.6174  SUCCESS
1  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
1  0.0726  SUCCESS
2  0.  TLogger.exe  IOCTL_SERIAL_PURGE  Serial0  Purge: TXABORT
RXABORT TXCLEAR RXCLEAR
2  0.0698  SUCCESS
3  0.  TLogger.exe  IOCTL_SERIAL_SET_TIMEOUTS  Serial0  RI:-1
RM:0 RC:0 WM:0 WC:5000
3  0.0168  SUCCESS
4  0.  TLogger.exe  IOCTL_SERIAL_GET_BAUD_RATE  Serial0
4  0.0279  SUCCESS
5  0.  TLogger.exe  IOCTL_SERIAL_GET_LINE_CONTROL  Serial0
5  0.0196  SUCCESS
6  0.  TLogger.exe  IOCTL_SERIAL_GET_CHARS  Serial0
6  0.0223  SUCCESS
7  0.  TLogger.exe  IOCTL_SERIAL_GET_HANDFLOW  Serial0
7  0.0196  SUCCESS
8  0.  TLogger.exe  IOCTL_SERIAL_GET_BAUD_RATE  Serial0
8  0.0196  SUCCESS
9  0.  TLogger.exe  IOCTL_SERIAL_GET_LINE_CONTROL  Serial0
9  0.0168  SUCCESS
10  0.  TLogger.exe  IOCTL_SERIAL_GET_CHARS  Serial0
10  0.0168  SUCCESS
11  0.  TLogger.exe  IOCTL_SERIAL_GET_HANDFLOW  Serial0
11  0.0168  SUCCESS
12  0.  TLogger.exe  IOCTL_SERIAL_SET_BAUD_RATE  Serial0  Rate:
9600
12  0.1285  SUCCESS
13  0.  TLogger.exe  IOCTL_SERIAL_CLR_RTS  Serial0
13  0.0782  SUCCESS
14  0.  TLogger.exe  IOCTL_SERIAL_SET_DTR  Serial0
14  0.0810  SUCCESS
15  0.  TLogger.exe  IOCTL_SERIAL_SET_LINE_CONTROL  Serial0
StopBits: ERROR Parity: NONE WordLength: 8
15  0.0698  SUCCESS
16  0.  TLogger.exe  IOCTL_SERIAL_SET_CHAR  Serial0  EOF:1a
ERR:0 BRK:0 EVT:0 XON:11 XOFF:13
16  0.0531  SUCCESS
17  0.  TLogger.exe  IOCTL_SERIAL_SET_HANDFLOW  Serial0
Shake:1 Replace:0 XonLimit:8 XoffLimit:8
17  0.0754  SUCCESS
18  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
18  0.1145  SUCCESS
19  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
19  0.0531  SUCCESS
20  0.  TLogger.exe  IOCTL_SERIAL_WAIT_ON_MASK  Serial0

### TRAFFIC WHEN THE PROGRAM READS CURRENT TEMP FROM DEVICE:

21  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
21  0.1034  SUCCESS
22  0.  TLogger.exe  IRP_MJ_WRITE  Serial0  Length 1: 33
22  0.3269  SUCCESS
20  9.28649032  SUCCESS
23  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
23  0.0587  SUCCESS
24  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
24  0.0559  SUCCESS
25  0.  TLogger.exe  IOCTL_SERIAL_GET_PROPERTIES  Serial0
25  0.0168  SUCCESS
26  0.  TLogger.exe  IRP_MJ_WRITE  Serial0  Length 1: 00
27  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
27  0.0726  SUCCESS
28  0.  TLogger.exe  IOCTL_SERIAL_WAIT_ON_MASK  Serial0
26  0.00107611  SUCCESS
28  0.00097666  SUCCESS
29  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
29  0.0587  SUCCESS
30  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
30  0.0503  SUCCESS
31  0.  TLogger.exe  IOCTL_SERIAL_GET_PROPERTIES  Serial0
31  0.0196  SUCCESS
32  0.  TLogger.exe  IRP_MJ_WRITE  Serial0  Length 1: 00
33  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
33  0.0531  SUCCESS
34  0.  TLogger.exe  IOCTL_SERIAL_WAIT_ON_MASK  Serial0
32  0.00102583  SUCCESS
34  0.00098811  SUCCESS
35  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
35  0.0559  SUCCESS
36  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
36  0.0726  SUCCESS
37  0.  TLogger.exe  IOCTL_SERIAL_GET_COMMSTATUS  Serial0
37  0.0559  SUCCESS
38  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
38  0.1173  SUCCESS
39  0.  TLogger.exe  IOCTL_SERIAL_WAIT_ON_MASK  Serial0
39  0.00934281  SUCCESS
40  0.  TLogger.exe  IOCTL_SERIAL_SET_WAIT_MASK  Serial0  Mask:
RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
40  0.0922  SUCCESS
41  0.  TLogger.exe  IOCTL_SERIAL_WAIT_ON_MASK  Serial0
41  0.1034 

ldexpf undefined in Python 2.4.3 build on SCO OSR 5.0.5

2006-07-24 Thread edcdave
My (gcc 2.95.2) build of Python 2.4.3 is failing with:

 gcc  -Wl,-Bexport -o python \
Modules/ccpython.o \
libpython2.4.a -lnsl -ldl-lm
Undefined   first referenced
 symbol in file
ldexpf  /usr/ccs/lib/libm.so
python: fatal error: Symbol referencing errors. No output written to
python
collect2: ld returned 1 exit status
*** Error code 1 (bu21)
UX:make: ERROR: fatal error.

This is hardly surprising since config.log contained:

configure:18218: checking for hypot
configure:18269: gcc -o conftest -g -O2   conftest.c -lnsl -ldl  -lm
>&5
Undefined   first referenced
 symbol in file
ldexpf  /usr/ccs/lib/libm.so
conftest: fatal error: Symbol referencing errors. No output written to
conftest
collect2: ld returned 1 exit status
configure:18275: $? = 1

Which led to pyconfig.h containing:

/* Define to 1 if you have the `hypot' function. */
/* #undef HAVE_HYPOT */

So, even without HAVE_HYPOT, ldexpf is still referenced somehow.

Any suggestions? Should I step back to Python 2.3 source? Thanks,
Dave Harris

BTW, I'm the guy trying to get MoinMoin running on SCO OpemServer 5.0.5
(http://groups.google.com/group/comp.lang.python/browse_thread/thread/9321890929d5431d/fcc5a79144c195df?lnk=gst&q=getaddrinfo&rnum=2#fcc5a79144c195df).
The configure script correctly identifies getaddrinfo() as absent.

/* Define if you have the getaddrinfo function. */
/* #undef HAVE_GETADDRINFO */

Thanks for the suggestion to check it, Martin. There's still room for
some confusion since I'm trying to build Python 2.4.3 now and my
original binary was Python 2.3.4. But I'm satisfied that the Python
script is correct.

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


Re: prob with struct and byte order

2006-07-24 Thread Grant Edwards
On 2006-07-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> ok, i did this print ' '.join(["%02.2x" % ord(b) for b in message])
> and i got this in the text file

> 535458002c00ea31373538343636383535d6090d54454e58

No, I don't think so. If you did what you said you did, you
would have gotten something with spaces in it:

>>> ' '.join(["%02.2x" % ord(b) for b in "hi there, how are you"])
'68 69 20 74 68 65 72 65 2c 20 68 6f 77 20 61 72 65 20 79 6f 75'

It's very important that you cut-paste things into postings
exactly as they appear in your program and output.  We can
sometimes guess what you did, but not always.  In this case,
I'm guessing you did ''.join rather than ' '.join.

> so, yes, more of the info seems discernable now.
>
> according to their docs, all of their variables are sent as 32bit long
> int (prefferably unsigned long int).

Then you can use the struct module to pull those values out of
the message:

  def tohex(bytes):
return ' '.join(['%02.2x' % ord(b) for b in bytes])

  startDelimiter,msglen = struct.unpack('>3sI', message[:7])
  endDelimiter = struc.unpack('>3s',message[-3:])
  assert startDelimiter == 'STX'
  assert endDelimiter == 'ENX'
  payload = message[7:-3]  
  assert msglen == len(payload)

  while len(payload) >= 4:
print struct.unpack('>I',payload[:4])
payload = payload[4:]

  if payload:
print "extra bytes", tohex(payload)  
  
... or whatever.  You'll probably want to pull the message type
out first, and then look up a format string using the message
type as the key.

NB:  The above code is off-the-cuff and untested.  It almost
certainly contains typos and maybe even a thinko.

> the big deal in the docs goes on about how the clients need the byte
> order to match

That's what the '>' at the beginning of the struct format
string does.  Your message appears to be big-endian, so you use
the '>' specifier to tell the struct module to interprent the
data as big-endian.

> that of the arch that the server runs on 'Sun UltraSPARC'

Which is indeed big-endian.

> i think they run Solaris.

Which doesn't actually matter -- you'd see the same thing if
they were running Linux, BSD, or some other OS.

-- 
Grant Edwards   grante Yow!  Are we live or
  at   on tape?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and real-time OS timing/task communication?

2006-07-24 Thread Ray Schumacher
Has anyone used Python and a hard real-time OS/patch to schedule timed events?
We have started in on Debian and RTAI, and may be using LXRT.
(I've been reading 
http://people.mech.kuleuven.be/~psoetens/lxrt/portingtolxrt.html)
I was envisioning that we really only need a separate RT-process in C using 
RDTSC or ACPI clocking that can get its control messages from non-RT Python 
every 50ms or so, to toggle pins on parport0.
Any pointers, examples, etc for communicating from Python to an RT task?

Thanks,
Ray

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


Re: _mssql on Python 2.5 Beta 2

2006-07-24 Thread Andrew MacIntyre
[EMAIL PROTECTED] wrote:
> I'm trying to use the _mssql module from
> http://pymssql.sourceforge.net/.  It works fine on Python 2.4.  I've
> just installed Python 2.5 Beta 2 on my Linux box and, whenever I try
> and run the mssql.close() function, or close the program, I get the
> following message:
> 
> *** glibc detected *** python2.5: free(): invalid pointer: 0xb7f08320

I'm assuming that you recompiled the extension, rather than installed
a binary built with a Python 2.4 installation.

Python 2.5 tightens the requirements that memory allocated via one
memory management API family must be released via calls through the
same API family - eg malloc() -> free(); PyMem_Malloc() -> PyMem_Free();
PyObject_Malloc() -> PyObject_Free().  I think I recall something about
this in one of the "whats new" type docs.

A fair bit of code erroneously assumes that free() can be used to
release any block of memory, regardless of which API family was used to
allocate the memory.  This code needs to be fixed.

-- 
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating all possible combination of elements in a list

2006-07-24 Thread [EMAIL PROTECTED]

Mir Nazim wrote:
> Paul Rubin wrote:
> > > 1060! / (1060 - 96)!
> >
>
> > More than you want to think about:
> >
> > import math
> >
> > def logf(n):
> > """return base-10 logarithm of (n factorial)"""
> > f = 0.0
> > for x in xrange(1,n+1):
> > f += math.log(x, 10)
> > return f
> >
> > print logf(1060) - logf(1060 - 96)
> >
> > Of course there are other ways you can calculate it, e.g.
>
> My problem is not to calculate this number, but generate this much
> number of permutations in a  fastest possible ways.
>
> by the way,  logf(1060) - logf(1060 - 96) = 288.502297251. Do you mean
> there are only 289 possible permutation if 1060 elements taken 96 at a
> time. Wow it is cool.
>
> Please correct me if I got something wrong

Not 289, but 10**288.502297251.

That would make generating them all slightly intractable.

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


Re: Functions, Operators, and Overloading?

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 15:05:53, Stefan Behnel wrote:

Maybe I am missing something, but from what I've seen,
 it is not possible to overload functions in Python. That
 is I can't have a
   def func1 (int1, string1):
and a
   def func1 (int1, int3, string1, string2):
 without the second func1 overwriting the first.
>>> Correct.
>> 
>> Can you write a function that accepts any number of arguments? And then
>> branch based on the number of arguments supplied?
>> 
>> I guess you can do that with a list as only argument. But can that be done
>> using the "normal" function argument notation?
> 
> I guess you mean something like
> 
>func1(int1, arg2, *args):
>if len(args) == 2:
>   ...
>elif not args:
>   ...
>else:
>   raise ...

Exactly. So in a way, the OP's question whether such an overload is
possible has two answers: a formal overload (two separate function
definitions) is not possible, but a functional overload (two definitions
for the different parameter numbers inside one function) is possible.

Thanks,
Gerhard

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


Re: prob with struct and byte order

2006-07-24 Thread nephish
ok, i did this print ' '.join(["%02.2x" % ord(b) for b in message])
and i got this in the text file
535458002c00ea31373538343636383535d6090d54454e58
so, yes, more of the info seems discernable now.

according to their docs, all of their variables are sent as 32bit long
int (prefferably unsigned long int).

the developers at the server we are trying to talk to have released an
api for C (maybe C++) that comes in an osx module that one is supposed
to import into visual basic. I am not developing in visual basic, or
windows or C or C++. So my challenge is to get some of the same
functionality  out of python on debian linux.

the osx module is what they give out to developers who have apps that
need to talk with this server.

the starting and ending deliminators are ASCII 'STX' and 'ENX'. i
wondered why they did it like that also. But they did.

the message length is a 4 byte integer indicating how long the message
body is.
the message type is also 4 bytes. There is a table in the docs that
describe what each message type is. for example 200 = login,
etc...etc...

the big deal in the docs goes on about how the clients need the byte
order to match that of the arch that the server runs on 'Sun
UltraSPARC' , i think they run Solaris.

if i sound like i do not know what i am talking about... there is a
reason...  i am very new to this type of communication with the server.
I have about 6 months with python ( my first language ).

thanks for your help, gents .

-sk
Grant Edwards wrote:
> On 2006-07-24, Steve Holden <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >> hello there, all.
> >>
> >> i have a difficult app that connects to a server to get information for
> >> our database here.
> >> this server is our access point to some equipment in the field that we
> >> monitor.
> >>
> >> the messages come in over a socket connection. And according to their
> >> (very limited) documentation, are set up in a particular order. like
> >> this
> >>
> >> STX [length indicator] [message type] [message body] ENX
> >>
> >> length indicator = length of the message body in 4 bytes
> >> message type = the code for what type of message is being sent
> >>for example 200 = login
> >> message body = the actual command to send to the server
> >>
> >> STX and ENX are the values assigned to start and stop a message.
> >> they are literally 'STX' and 'ENX'
>
> > I believe you, but this is clearly a perversion of the
> > single-character "start of transmission" and "end of
> > transmission" that are part of the ASCII alphabet. So the
> > protocol designer may have been inexperienced, and the
> > documentation may be confused ...
>
> I had the same reaction: surely he means the frame is delmited
> at the beginning by the ASCII STX character (0x02) and the end
> by the ETX character (0x03).
>
> If somebody is indeed sending the three character string "STX"
> to mark the beginning of a frame and "ENX" to mark the end,
> then they're seriously confused (and can't spell).
>
> >> when i capture a message i can print it to the screen and the 'STX' at
> >> the beginning and the 'ENX' at the end are discernable, but the rest of
> >> the message looks like this..
> >>
> >> \x00\x00\x00,\x00\x00\x00\e17758\x00\x00   and so on and so forth...
> >> with some commas and other symbols in there. (the e before the 17758
> >> has a little hat on it)
>
> So the unit number is an ASCII string.  Firstly, I'd recommend
> printing the message in hex:
>
> print ' '.join(["%02.2x" % ord(b) for b in message])
>
> That should make it easier to figure how which byte indexes
> contain the info you're looking for.
>
> >> If i print it out to a text file, i get this...
> >> STXNULNULNULea17758NULLNULL etc..
>
> I'm a but baffled how the string shown above would get printed
> like that.
>
> > The "\x00" is the Python repr() of a single-byte string containing a
> > null byte (i.e. a byte whose decimal value is zero).
> >
> >> now the 17758 is significant because it is the actual unit number of
> >> the machine we want to monitor. I just dont know how to extract the
> >> real values out of this message.
>
> What is meant by "real values"?
>
> >> anyone have an idea where to start? i have experimented with
> >> struct, but do not know enough about it. Does anyone know a
> >> good tutorial about learning byte codes and such.
>
> What are "byte codes"?
>
> >> The docs on pythons website explain the module well, but i
> >> still do not know what to do with it.
>
> You've got to figure out the format and location within the
> message of the objects you care about.  Once you know that, you
> use struct to pull out the appropriate bytes and convert them
> into Python objects.
>
> If you know (or suspect) there are IEEE 754 32-bit floating
> point values in the message, then start converting all of the
> possible 4-byte chunks into Python floats (using both endian
> conventions) until you see numbers you re

Re: Comment on this script. Possible error in communication with list arg between functions

2006-07-24 Thread Juho Schultz
Phoe6 wrote:
> Hi all,
>  Part of my script is to check for pre-requisite rpms to be
> installed.
> If its installed, I just display the rpm version as in rpm database,
> otherwise I output a message saying:
> ' rpm is not installed' and collect the rpm name in a list
> (notInstalled).
> At the end if the len(notInstalled) is greater than 0 then I display
> them all asking it to be installed and exit the program.
> My Script is below:
> ---
> def checkForRpm(rpmname):
> ''' Check for the presence of the RPM. '''
> cin,cout,cerr = os.popen3('rpm -q ' + rpmname)
> output = cout.read()
> global notInstalled
> if len(output) <= 0:
> print rpmname + ' not installed.'
> notInstalled.append(rpmname)
> else:
> print output
>
>
>
> def preReqCheckRpms():
> ''' Check for the required RPMS '''
> listOfRpms = ['firefox','senthil',]
>
>
> for eachRpm in listOfRpms:
> checkForRpm(eachRpm)
> global notInstalled
> if len(notInstalled) > 0:
> print 'The following RPMS are not installed:'
> for eachRpm in notInstalled:
> print eachRpm
> print 'Please install them for the installation to
> continue.'
> sys.exit(-1)
>

> * This is NOT Working.
> * notInstalled.append(rpmname) is not taking effect in
> checkForRpm(rpmname)
> * I dont know how to communicate the notInstalled list to
> preReqCheckRpms.
>
> --
> Senthil

I think return values should be used for communication between
functions. Maybe something like this could work for you (not tested).

def checkForRpm(rpmname):
# 
# Strings with 0 lenght are False
if output:
print output
else:
print rpmname + ' is not installed'
return output

def checkPreReqs():
missingRpms = []
for requiredRpm in listOfRpms:
if not checkForRpm(requiredRpm):
missingRpms.append(requiredRpm)
# you could also do this by a list comprehension
missingRpms = [reqRpm for reqRpm in listOfRpms if not
checkForRpm(reqRpm)]
# or you could use the builtin function filter() - see
filter.__doc__ for that

# now, list of lenght 0 is False.
if missingRpms:
# print error messages, exit.

--
Juho Schultz

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


Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread alexandre_irrthum
Gerhard Fiedler wrote:
> On 2006-07-24 14:03:30, [EMAIL PROTECTED] wrote:
>
> > To read from the chip, one must issue the "read page" command (33h),
> > followed by the two-byte address of the requested page (pages are 32
> > bytes long). After receiving this, the DS1615 will send the data in a
> > burst of (up to) 32 bytes.
>
> I'm not sure what you mean when you say it will send "up to" 32 bytes. If
> you mean that it sends bytes until all existing values have been sent --
> did you make sure you have any values in the buffer?
>
> (Just asking the obvious... :)
>
> Gerhard

Thanks Gerhard,

Up to 32 bytes means that the chip sends the bytes from the address you
give up to the end of the memory page that contains this address. Thus
if you give the address of the beginning of a memory page (e.g. like
here H for the beginning of the first page, which contains control
registers and the current temperature register), you get 32 bytes.

alex

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


Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread Grant Edwards
On 2006-07-24, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>>> import serial
>>> s = serial.Serial(0, baudrate=9600, bytesize=8, parity='N', stopbits=1, 
>>> timeout=None)
>>> s.write("\x33")
>>> s.write("\x00")
>>> s.write("\x00")
>>> s.read()   # "\x00" is returned here. This byte was already in the receive 
>>> buffer before issueing the write commands.
>>> s.read()   # The interpreter is blocked here as there is nothing to read 
>>> from the serial port.

Can you verify that the device is actually responding by
watching the data line with an oscilloscope?

> I'm completely clueless and would really appreciate your
> comments. If it helps, I can post a log from a serial port
> monitor captured when the provided T-logger program pulls data
> from the device,

I take it that means that other programs are able to read from
the device?

> as well as a log when pyserial is used.

Logs of the serial traffic would be helpful.

-- 
Grant Edwards   grante Yow!  It's the land of
  at   DONNY AND MARIE as promised
   visi.comin TV GUIDE!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread Grant Edwards
On 2006-07-24, Gerhard Fiedler <[EMAIL PROTECTED]> wrote:
> On 2006-07-24 14:03:30, [EMAIL PROTECTED] wrote:
>
>> To read from the chip, one must issue the "read page" command (33h),
>> followed by the two-byte address of the requested page (pages are 32
>> bytes long). After receiving this, the DS1615 will send the data in a
>> burst of (up to) 32 bytes. 
>
> I'm not sure what you mean when you say it will send "up to" 32 bytes.

Registers are in 32-byte pages.  If you request register N, the
device sends register N followed by the remainder of the
32-byte page that contains address N.  If you request the first
register on a page, you'll get 32 bytes back.  If you request
the last register on a page, you'll get one 1 back.

-- 
Grant Edwards   grante Yow!  If I pull this SWITCH
  at   I'll be RITA HAYWORTH!! Or
   visi.coma SCIENTOLOGIST!
-- 
http://mail.python.org/mailman/listinfo/python-list


Search within running python scripts

2006-07-24 Thread gmax2006
Hi,

Is it possible that a python script finds out whether another instance
of it is currently running or not?

Thank you,
Max

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


Re: easy questions from python newbie

2006-07-24 Thread Tim
James Stroud wrote:
> John Machin wrote:
> > James Stroud wrote:
> >
> >>walterbyrd wrote:
> >>
> >>>This is the first real python program I have ever worked on. What I
> >>>want to do is:
> >>>1) count identical records in a cvs file
> >>>2) create a new file with quantities instead duplicate records
> >>>3) open the new file in ms-excel
> >>>
> >>>For example, I will start with a file like:
> >>>
> >>>1001
> >>>1012
> >>>1008
> >>>1012
> >>>1001
> >>>1001
> >>>
> >>>and finish with a file like:
> >>>
> >>>1001,3
> >>>1008,1
> >>>1012,2
> >>>
> >>>What I need to know:
> >>>1) is there a function in python that will sort a file into another
> >>>file. Something like:
> >>>sort file1.txt > file2.txt from the DOS command line. I know there is
> >>>also a similar "sort" funtion in Unix.
> >>

snip...

> >>>3) I will probably be working with 50 items, or less, would it be best
> >>>for me to do this with a
> >>>multi-diminsional array? For example: sort the file, read a rec into
> >>>the array, if the next rec is the same then incr the count, otherwise
> >>>add a new rec with a count of 1. Then write the array to a file?
> >>>
> >>
> >>Ah, a real question. Use a dict:
> >>
> >>if adict.has_key(some_key):
> >
> >
> > Hey, d00d, ask the department sysadmin to update your Python for you,
> > then you'll be able to use this:
> >
> > if some_key in adict:
> >
> >
> >>   adict[some_key] += 1
> >>else:
> >>   adict[some_key] = 1
> >>
>
> Last I checked, both worked.
>
> James
>

Alternatively, the whole if can be replaced with:-

adict[some_key] = adict.get(some_key, 0) + 1

Tim

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


Re: How to force a thread to stop

2006-07-24 Thread Jean-Paul Calderone
On Mon, 24 Jul 2006 11:22:49 -0700, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> 
wrote:
>Steve Holden wrote:
>> Carl J. Van Arsdall wrote:
>> [... rant ...]
>>
>>> So with this whole "hey mr. nice thread, please die for me" concept gets
>>> ugly quickly in complex situations and doesn't scale well at all.
>>> Furthermore, say you have a complex systems where users can write
>>> pluggable modules.  IF a module gets stuck inside of some screwed up
>>> loop and is unable to poll for messages there's no way to kill the
>>> module without killing the whole system.  Any of you guys thought of a
>>> way around this scenario?
>>>
>>>
>>>
>>
>> Communications through Queue.Queue objects can help. But if you research
>> the history of this design decision in the language you should discover
>> there are fairly sound rasons for not allowing arbitrary "threadicide".
>>
>>
>>
>Right, I'm wondering if there was a way to make an interrupt driven
>communication mechanism for threads?  Example: thread receives a
>message, stops everything, and processes the message.
>

And what happens if the thread was halfway through a malloc call and
the data structures used to manage the state of the heap are in an
inconsistent state when the interrupt occurs?

This has been discussed many many times in the context of many many
languages and threading libraries.  If you're really interested, do
the investigation Steve suggested.  You'll find plenty of material.

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


Re: Which Pyton Book For Newbies?

2006-07-24 Thread Bob Sinclar
Web programming is all about stdin & stdout. Recommanded practice
before going further.

On Monday 24 July 2006 20:08, John Salerno wrote:
> Gerhard Fiedler wrote:
> > While I don't doubt that there are many applications that are well-suited
> > for web apps and that there are a number of good reasons for making some
> > apps web-based, why do you think web programming is /not/ GUI
> > programming?
>
> Personally I enjoy GUI programming, so I'm not really one of the people
> that recommend a web app instead. I was just throwing that out there as
> a possibility. After all, it does seem easier to use a few HTML buttons
> and textboxes in a table than to have to learn even the basics of
> something like wxPython or Tkinter. But wxPython is fun anyway, so I
> recommend it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Comment on this script. Possible error in communication with list arg between functions

2006-07-24 Thread Phoe6
Hi all,
 Part of my script is to check for pre-requisite rpms to be
installed.
If its installed, I just display the rpm version as in rpm database,
otherwise I output a message saying:
' rpm is not installed' and collect the rpm name in a list
(notInstalled).
At the end if the len(notInstalled) is greater than 0 then I display
them all asking it to be installed and exit the program.
My Script is below:
---
#!/usr/bin/env python
import os
import sys



notInstalled = []



def checkForRpm(rpmname):
''' Check for the presence of the RPM. '''
cin,cout,cerr = os.popen3('rpm -q ' + rpmname)
output = cout.read()
global notInstalled
if len(output) <= 0:
print rpmname + ' not installed.'
notInstalled.append(rpmname)
else:
print output



def preReqCheckRpms():
''' Check for the required RPMS '''
listOfRpms =
['firefox','senthil','binutils','gcc','cpp','glibc-devel','glibc-headers','glibc-kernheaders','compat-db','compat-gcc','compat-gcc-c++','compat-libstdc++','compat-libstdc++-devel','gnome-libs','openmotif21','setarch']



for eachRpm in listOfRpms:
checkForRpm(eachRpm)
global notInstalled
if len(notInstalled) > 0:
print 'The following RPMS are not installed:'
for eachRpm in notInstalled:
print eachRpm
print 'Please install them for the installation to
continue.'
sys.exit(-1)






def main():
preReqCheckRpms()



if __name__ == '__main__':
main()


* This is NOT Working.
* notInstalled.append(rpmname) is not taking effect in
checkForRpm(rpmname)
* I dont know how to communicate the notInstalled list to
preReqCheckRpms.

-- 
Senthil

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


Re: Exercises for dive into python

2006-07-24 Thread Gerard Flanagan

Ben Edwards (lists) wrote:
> On Mon, 2006-07-24 at 16:39 +, Tal Einat wrote:
> > Ben Edwards (lists  videonetwork.org> writes:
> >
> > >
> > > Have been working through Dive Into Python which is excellent.  My only
> > > problem is that there are not exercises.  I find exercises are a great
> > > way of helping stuff sink in and verifying my learning.  Has anyone done
> > > such a thing?
> > >
> > > Ben
> > >
> >
> >
> > I recently gave a Python crash-course in my company, and ran into the same
> > problem. There are many good Python tutorials, manuals, references etc., 
> > most
> > are accompannied by various code examples, but there are very few 
> > exercises. I
> > had a hard time collecting and inventing a few good exercises, about 12 in 
> > all.
> >
> > There are probably some good exercises out there, but they seem to be 
> > relatviely
> > hard to find. Maybe they should be collected and organized at Python.org?
>
> That sounds like an exelent idea.  Maybe the way to structure it is by
> book/chapter.
>
> >
> > I think building a large collection of good Python exercises could help both
> > those teaching Python and those learning it. Also, gathering a set of Python
> > exercises for those learning general programming concepts (variables, 
> > functions,
> > object-oriented, etc.) could help spread the use of Python for teaching
> > programming.
>
> I think there is little doubt about this.  The reason I liked the
> 'Thinking in Java' book was it had 10 exercises at the end of each
> chapter.  I would not more onto a chapter until I had completed them
> all.
>

This is something I had planned for the suggested tutorial restructure
at the 'pytut' wiki here:

http://pytut.infogami.com/gerard_refactor

I had hoped (and hope!) to add exercises at the end of each chapter.
It's a wiki of course so if you've any ideas, feel free...

That said, I don't know how visible this sight is among the community -
it's been quiet for a few months - or if it's even on the radar of the
'Powers That Be', whoever (or whatever ;^) ) they are...

But it's there anyway.  The main pages are (obviously):

http://pytut.infogami.com

Gerard

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


Re: Functions, Operators, and Overloading?

2006-07-24 Thread bearophileHUGS
Michael Yanowitz:

> Maybe I am missing something, but from what I've seen,
> it is not possible to overload functions in Python.

Maybe here you can find some ideas:
http://www.artima.com/forums/flat.jsp?forum=106&thread=101605
http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/
http://blog.ianbicking.org/more-on-multimethods.html


> (on the side, I have always wanted to define the
> ++ operator as +=1. Is that possible?)

That's not possible. Maybe you can create an inc() function, similar to
the Pascal one, that with a bit of stack-based magic may increment the
value its called on, but I think this is a bad idea. Leading/trailing
++/-- are quite bad for a language that tries to be clear and to avoid
programmer errors.

Bye,
bearophile

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


Re: How to force a thread to stop

2006-07-24 Thread Carl J. Van Arsdall
Steve Holden wrote:
> Carl J. Van Arsdall wrote:
> [... rant ...]
>   
>> So with this whole "hey mr. nice thread, please die for me" concept gets 
>> ugly quickly in complex situations and doesn't scale well at all.  
>> Furthermore, say you have a complex systems where users can write 
>> pluggable modules.  IF a module gets stuck inside of some screwed up 
>> loop and is unable to poll for messages there's no way to kill the 
>> module without killing the whole system.  Any of you guys thought of a 
>> way around this scenario?
>>
>>
>> 
>
> Communications through Queue.Queue objects can help. But if you research 
> the history of this design decision in the language you should discover 
> there are fairly sound rasons for not allowing arbitrary "threadicide".
>
>
>   
Right, I'm wondering if there was a way to make an interrupt driven 
communication mechanism for threads?  Example: thread receives a 
message, stops everything, and processes the message. 


-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: How to force a thread to stop

2006-07-24 Thread Steve Holden
Carl J. Van Arsdall wrote:
[... rant ...]
> So with this whole "hey mr. nice thread, please die for me" concept gets 
> ugly quickly in complex situations and doesn't scale well at all.  
> Furthermore, say you have a complex systems where users can write 
> pluggable modules.  IF a module gets stuck inside of some screwed up 
> loop and is unable to poll for messages there's no way to kill the 
> module without killing the whole system.  Any of you guys thought of a 
> way around this scenario?
> 
> 

Communications through Queue.Queue objects can help. But if you research 
the history of this design decision in the language you should discover 
there are fairly sound rasons for not allowing arbitrary "threadicide".

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Which Pyton Book For Newbies?

2006-07-24 Thread John Salerno
Gerhard Fiedler wrote:

> While I don't doubt that there are many applications that are well-suited
> for web apps and that there are a number of good reasons for making some
> apps web-based, why do you think web programming is /not/ GUI programming? 

Personally I enjoy GUI programming, so I'm not really one of the people 
that recommend a web app instead. I was just throwing that out there as 
a possibility. After all, it does seem easier to use a few HTML buttons 
and textboxes in a table than to have to learn even the basics of 
something like wxPython or Tkinter. But wxPython is fun anyway, so I 
recommend it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functions, Operators, and Overloading?

2006-07-24 Thread Stefan Behnel
Gerhard Fiedler schrieb:
> On 2006-07-24 14:30:31, Brian Beck wrote:
> 
>> Michael Yanowitz wrote:
>>>Maybe I am missing something, but from what I've seen,
>>> it is not possible to overload functions in Python. That
>>> is I can't have a
>>>   def func1 (int1, string1):
>>>and a
>>>   def func1 (int1, int3, string1, string2):
>>> without the second func1 overwriting the first.
>> Correct.
> 
> Can you write a function that accepts any number of arguments? And then
> branch based on the number of arguments supplied?
> 
> I guess you can do that with a list as only argument. But can that be done
> using the "normal" function argument notation?

I guess you mean something like

   func1(int1, arg2, *args):
   if len(args) == 2:
  ...
   elif not args:
  ...
   else:
  raise ...


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


unittest ValueError

2006-07-24 Thread Chris Fonnesbeck
I have built the following unit test, observing the examples laid out
in the python docs:

class testMCMC(unittest.TestCase):

def setUp(self):

# Create an instance of the sampler
self.sampler = DisasterSampler()

def testCoalMiningDisasters(self):
"""Run coal mining disasters example sampler"""

print 'Running coal mining disasters test case ...'

# Specify the nimber of iterations to execute
iterations = 1
thin = 2
burn = 5000
chains = 2

# Run MCMC simulation
for i in range(chains):

self.failUnless(self.sampler.sample(iterations, burn=burn,
thin=thin, plot=True))

# Run convergence diagnostics
self.sampler.convergence()

# Plot autocorrelation
self.sampler.autocorrelation()

# Goodness of fit
self.failIf(self.sampler.goodness(iterations/10)['overall'] < 0.05)


def test():
# Run unit tests
unittest.main()

However, when I run test() from the python shell, it dies:

In [2]: test()

--
Ran 0 tests in 0.000s

OK
---
exceptions.SystemExitTraceback (most
recent call last)

/Users/chris/

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/PyMC/MCMC.py
in test()
   2986
   2987 def test():
   2988 # Run unit tests
-> 2989 unittest.main()
global unittest.main = 
   2990

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in __init__(self=,
module='__main__', defaultTest=None, argv=['/usr/local/bin/ipython'],
testRunner=None, testLoader=)
757 self.progName = os.path.basename(argv[0])
758 self.parseArgs(argv)
--> 759 self.runTests()
self.runTests = >
760
761 def usageExit(self, msg=None):

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in runTests(self=)
795 self.testRunner = TextTestRunner(verbosity=self.verbosity)
796 result = self.testRunner.run(self.test)
--> 797 sys.exit(not result.wasSuccessful())
global sys.exit = 
result.wasSuccessful = >
798
799 main = TestProgram

SystemExit: False
Type exit or quit to exit IPython (%Exit or %Quit do so unconditionally).

In [3]: from PyMC import testMCMC

In [4]: foo = testMCMC()
---
exceptions.ValueErrorTraceback (most
recent call last)

/Users/chris/

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in __init__(self=,
methodName='runTest')
206 self.__testMethodDoc = testMethod.__doc__
207 except AttributeError:
--> 208 raise ValueError, "no such test method in %s: %s" % \
global ValueError = undefined
self.__class__ = 
methodName = 'runTest'
209   (self.__class__, methodName)
210

ValueError: no such test method in : runTest


I have no idea why this is happening. My TestCase class begins with
"test", the method begins with "test", yet no tests are seen. Also, I
do not get the runTest ValueError. I assumed that you get this method
for free win TestCase. The examples certainly do not have this method,
so I am not sure what the problem is.

Thanks for any help,
-- 
Chris Fonnesbeck + Atlanta, GA + http://trichech.us
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial to read from DS1615 temperature recorder chip

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 14:03:30, [EMAIL PROTECTED] wrote:

> To read from the chip, one must issue the "read page" command (33h),
> followed by the two-byte address of the requested page (pages are 32
> bytes long). After receiving this, the DS1615 will send the data in a
> burst of (up to) 32 bytes. 

I'm not sure what you mean when you say it will send "up to" 32 bytes. If
you mean that it sends bytes until all existing values have been sent --
did you make sure you have any values in the buffer?

(Just asking the obvious... :)

Gerhard

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


Re: Functions, Operators, and Overloading?

2006-07-24 Thread Terry Reedy

"Michael Yanowitz" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hello:
>
>   Maybe I am missing something, but from what I've seen,
> it is not possible to overload functions in Python. That
> is I can't have a
>  def func1 (int1, string1):
>   and a
>  def func1 (int1, int3, string1, string2):
>without the second func1 overwriting the first.

I am hard put to think of why you would want to do something like that in 
real code.  The 2nd-parameter type mismatch will make using code harder to 
write and read without bugs.  Why not just give the two 
different-but-related functions two different-but-related, names?  But if 
you insist ..., here is the Python way...

def func1(int1, int3, string1=None, string2=None):
  "doc short calling sequence"
  if string1==None:
string1 = int3; del int3, string2

  else:


or
def func1(int1, *args):
  if len(args ==1):
string1 = args[0]; del args

  elif len(args ==3):
int3,string1,string2 = args; del args

  else: 

>   However, operators can be overloaded.

In the sense that you can define classes with appropriate special methods. 
You can also give two different classes methods named 'func1'.

>   So can I define a new operator?

No.

Terry Jan Reedy



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


Re: Functions, Operators, and Overloading?

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 14:30:31, Brian Beck wrote:

> Michael Yanowitz wrote:
>>Maybe I am missing something, but from what I've seen,
>> it is not possible to overload functions in Python. That
>> is I can't have a
>>   def func1 (int1, string1):
>>and a
>>   def func1 (int1, int3, string1, string2):
>> without the second func1 overwriting the first.
> 
> Correct.

Can you write a function that accepts any number of arguments? And then
branch based on the number of arguments supplied?

I guess you can do that with a list as only argument. But can that be done
using the "normal" function argument notation?

Gerhard

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


Re: Generating all possible combination of elements in a list

2006-07-24 Thread Mir Nazim

Paul Rubin wrote:
> > 1060! / (1060 - 96)!
>

> More than you want to think about:
>
> import math
>
> def logf(n):
> """return base-10 logarithm of (n factorial)"""
> f = 0.0
> for x in xrange(1,n+1):
> f += math.log(x, 10)
> return f
>
> print logf(1060) - logf(1060 - 96)
>
> Of course there are other ways you can calculate it, e.g.

My problem is not to calculate this number, but generate this much
number of permutations in a  fastest possible ways.

by the way,  logf(1060) - logf(1060 - 96) = 288.502297251. Do you mean
there are only 289 possible permutation if 1060 elements taken 96 at a
time. Wow it is cool.

Please correct me if I got something wrong

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


Re: function v. method

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 14:41:02, Gerhard Fiedler wrote:

> (I actually think that possibly the current way of embedding javadoc-like
> documentation into sources is only a stepping stone into the direction
> generally pointed to by what Wirth called "literate programming". 

That was Knuth, not Wirth. But this is not really that relevant.

Gerhard

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


Re: function v. method

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 13:25:14, fuzzylollipop wrote:

>> So... the final authority /is/ the code. I don't see an alternative. For
>> me, good abstraction doesn't mean I don't have to read the sources; good
>> abstraction means (among other things) that I can read the sources easily.

> having auto generated docs, which means the documentatin is in the code
> as doc strings, javadoc, reflex, or whatever format is the BEST way of
> doing API documentation, period.

It may be the best way, no contest to that. But it still is not the code.
(I actually think that possibly the current way of embedding javadoc-like
documentation into sources is only a stepping stone into the direction
generally pointed to by what Wirth called "literate programming". In any
case, I'd rather not call it the "best way, period"; calling it the "best
currently widely supported way" seems more appropriate to me.)

Even doc strings tend to get out of sync with the code. And even doc
strings document (at best) what the code should do, not what it actually
does. And even doc strings are not always complete in describing the
functionality.

So auto generated docs are also incomplete and out of sync with the code,
sometimes more, sometimes less, sometimes so little that it is not
relevant. But you can't know how much out of sync they are from reading the
docs alone. So when push comes to shove (or so the saying goes? :), the
code is the authority. Even with auto generated docs. Period... ?!? 

Gerhard

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


Re: prob with struct and byte order

2006-07-24 Thread Grant Edwards
On 2006-07-24, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>> hello there, all.
>> 
>> i have a difficult app that connects to a server to get information for
>> our database here.
>> this server is our access point to some equipment in the field that we
>> monitor.
>> 
>> the messages come in over a socket connection. And according to their
>> (very limited) documentation, are set up in a particular order. like
>> this
>> 
>> STX [length indicator] [message type] [message body] ENX
>> 
>> length indicator = length of the message body in 4 bytes
>> message type = the code for what type of message is being sent
>>for example 200 = login
>> message body = the actual command to send to the server
>> 
>> STX and ENX are the values assigned to start and stop a message.
>> they are literally 'STX' and 'ENX'

> I believe you, but this is clearly a perversion of the
> single-character "start of transmission" and "end of
> transmission" that are part of the ASCII alphabet. So the
> protocol designer may have been inexperienced, and the
> documentation may be confused ...

I had the same reaction: surely he means the frame is delmited
at the beginning by the ASCII STX character (0x02) and the end
by the ETX character (0x03).  

If somebody is indeed sending the three character string "STX"
to mark the beginning of a frame and "ENX" to mark the end,
then they're seriously confused (and can't spell).

>> when i capture a message i can print it to the screen and the 'STX' at
>> the beginning and the 'ENX' at the end are discernable, but the rest of
>> the message looks like this..
>> 
>> \x00\x00\x00,\x00\x00\x00\e17758\x00\x00   and so on and so forth...
>> with some commas and other symbols in there. (the e before the 17758
>> has a little hat on it)

So the unit number is an ASCII string.  Firstly, I'd recommend
printing the message in hex:

print ' '.join(["%02.2x" % ord(b) for b in message])

That should make it easier to figure how which byte indexes
contain the info you're looking for.

>> If i print it out to a text file, i get this...
>> STXNULNULNULea17758NULLNULL etc..

I'm a but baffled how the string shown above would get printed
like that.

> The "\x00" is the Python repr() of a single-byte string containing a 
> null byte (i.e. a byte whose decimal value is zero).
>
>> now the 17758 is significant because it is the actual unit number of
>> the machine we want to monitor. I just dont know how to extract the
>> real values out of this message.

What is meant by "real values"?

>> anyone have an idea where to start? i have experimented with
>> struct, but do not know enough about it. Does anyone know a
>> good tutorial about learning byte codes and such.

What are "byte codes"?

>> The docs on pythons website explain the module well, but i
>> still do not know what to do with it.

You've got to figure out the format and location within the
message of the objects you care about.  Once you know that, you
use struct to pull out the appropriate bytes and convert them
into Python objects.

If you know (or suspect) there are IEEE 754 32-bit floating
point values in the message, then start converting all of the
possible 4-byte chunks into Python floats (using both endian
conventions) until you see numbers you recognize.

Same for 64-bit floats and interger values of various sizes.

-- 
Grant Edwards   grante Yow!  HUMAN REPLICAS are
  at   inserted into VATS of
   visi.comNUTRITIONAL YEAST...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exercises for dive into python

2006-07-24 Thread Ben Edwards (lists)
On Mon, 2006-07-24 at 16:39 +, Tal Einat wrote:
> Ben Edwards (lists  videonetwork.org> writes:
> 
> > 
> > Have been working through Dive Into Python which is excellent.  My only
> > problem is that there are not exercises.  I find exercises are a great
> > way of helping stuff sink in and verifying my learning.  Has anyone done
> > such a thing?
> > 
> > Ben
> > 
> 
> 
> I recently gave a Python crash-course in my company, and ran into the same
> problem. There are many good Python tutorials, manuals, references etc., most
> are accompannied by various code examples, but there are very few exercises. I
> had a hard time collecting and inventing a few good exercises, about 12 in 
> all.
> 
> There are probably some good exercises out there, but they seem to be 
> relatviely
> hard to find. Maybe they should be collected and organized at Python.org?

That sounds like an exelent idea.  Maybe the way to structure it is my
book/chapter. 

> 
> I think building a large collection of good Python exercises could help both
> those teaching Python and those learning it. Also, gathering a set of Python
> exercises for those learning general programming concepts (variables, 
> functions,
> object-oriented, etc.) could help spread the use of Python for teaching
> programming.

I think there is little doubt about this.  The reason I liked the
'Thinking in Java' book was it had 10 exercises at the end of each
chapter.  I would not more onto a chapter until I had completed them
all.

Ben

> 
> - Tal
> 


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


Re: Functions, Operators, and Overloading?

2006-07-24 Thread Brian Beck
Michael Yanowitz wrote:
>Maybe I am missing something, but from what I've seen,
> it is not possible to overload functions in Python. That
> is I can't have a
>   def func1 (int1, string1):
>and a
>   def func1 (int1, int3, string1, string2):
> without the second func1 overwriting the first.

Correct.

>However, operators can be overloaded.
>So can I define a new operator?  If so, can I
> define func1 as an operator?

No. Operators in Python are merely syntax for "magic methods" on the
corresponding type. For instance, x + y would call x.__add__(y). In this
sense you are not really "overloading" the operator, you are simply
defining or overwriting its behavior (just like above, where the second
func1 overwrites the previous).

> (on the side, I have always wanted to define the
> ++ operator as +=1. Is that possible?)

No, for the reason above -- there is no magic method associated with ++,
which isn't a real Python operator.

--
Brian Beck
Adventurer of the First Order
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a compelling argument to use Django instead of Rails

2006-07-24 Thread aaronwmail-usenet
Steve Holden wrote:
...
> I wouldn't waste your time. "A man convinced against his will is of the
> same opinion still", and they already know they aren't interested in
> Python. There are probably many other matters about which they are
> uninformed and equally determined

This is too true.  Fortunately progress proceeds
slowly nonetheless.  For example C++ is much
less used these days where it is totally and
catastrophically inappropriate than in years past
-- maybe because the true C++ boneheads have
been promoted or are retiring...  Nevertheless I was
recently told by a new grad that I should translate
one of my (working, no problems) python apps to
C++ because C++ is "a higher level language."
But I'm sure he'll fall in line with the next stream
of lemmings rather than sink into the tarpit with the
dinosaurs.

   -- Aaron Watters

===
Paradigms shift when the old guys retire.  -- Kuhn (?)

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


Re: How to force a thread to stop

2006-07-24 Thread Carl J. Van Arsdall
Dennis Lee Bieber wrote:
> On Sat, 22 Jul 2006 14:47:30 +0200, "Hans" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>
>   
>> Hi all,
>>
>> Is there a way that the program that created and started a thread also stops 
>> it.
>> (My usage is a time-out).
>>
>> 
>   Hasn't this subject become a FAQ entry yet? 
>
>   The only reliable way of stopping a thread is from inside the thread
> itself. That is, the thread must, at some point, examine some flag
> variable which, when set, says "stop"
>
> Without using actual code:
>
> class StoppableThread(...):
>   def __init__(self, ...):
>   #whatever is needed to initialize as a thread
>   self.Stop = False
>
>   def run(self, ...):
>   while not self.Stop:
>   #do one cycle of the computation
>
>
>   

My problem with the fact that python doesn't have some type of "thread 
killer" is that again, the only solution involves some type of polling 
loop.  I.e. "if your thread of execution can be written so that it 
periodically checks for a kill condition".  This really sucks, not just 
because polling is a ridiculous practice, but it forces programmers in 
many situations to go through a lengthy process of organizing operations 
into a list.  For, say I have threads that share a bunch of common 
memory (yea, i'm saying this exclusively to get the procses users off my 
back) that executes a series of commands on remote nodes using rsh or 
something.  So if i've constructed my system using threads I need to 
neatly go and dump all operations into some sort of list so that I can 
implement a polling mechanism, i.e.

opList = [op1, op2, op3, op4]
for op in opList:
  checkMessageQueue()
  op()

That works if you can easily create an opList.  If you want good 
response time this can become quite ugly, especially if you have a lot 
going on.  Say I have a function I want to run in a thread:

#Just pretend for the sake of arguement that 'op' actually means 
something and is a lengthy operation
def func_to_thread():
  os.system('op 1')
  os.system('op 2')
  os.system('op 3')


#In order to make this killable with reasonable response time we have to 
organize each of our ops into a function or something equally annoying

op_1():
  os.system('op 1')

op_2():
  os.system('op 2')

op_3():
  os.system('op 3')

opList(op_1, op_2, op_3)
def to_thread():
  for op in opList:
checkMessageQueue()
op()


So with this whole "hey mr. nice thread, please die for me" concept gets 
ugly quickly in complex situations and doesn't scale well at all.  
Furthermore, say you have a complex systems where users can write 
pluggable modules.  IF a module gets stuck inside of some screwed up 
loop and is unable to poll for messages there's no way to kill the 
module without killing the whole system.  Any of you guys thought of a 
way around this scenario?


-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: Type signature

2006-07-24 Thread Hugo Ferreira
Which is expecially true when using IDEs with auto-completion.Using
VisualStudio/MonoDevelop and C# I rarely need to look at the
documentation because I can quickly see what a method accept and
returns. And when I need to pass flags or options, enums are much more
neat and encapsulated.
With Python I'm constantly looking at the documentation when
surfing a library. I personally like the terse code and abstraction
features of Python which is making me slowly writing more and more
tools in it. Still, I have to agree that there are edges (like these)
that must be sharpened out...On 7/24/06, paul kölle <[EMAIL PROTECTED]> wrote:
Marc 'BlackJack' Rintsch wrote:> In <[EMAIL PROTECTED]>, Yacao Wang> wrote:>>> However, type signatures are not only a kind of information provided for
>> the compiler, but also for the programmer, or more important, for the>> programmer. Without it, we have to "infer" the return type or required>> agument types of a function, and this can't be done without seeing the
>> implementation of it,>> That's what documentation is meant for.  If you are forced to look at the> implementation, the documentation is bad.I think the OP refers to reading the *code*, the documentation might not
exist (yet). Sometimes I feel python is easier to write than to read and missing argument type declarations (just for documentation purposes)are  IMHO one reason. Another are missing (optional) argument type
checks at runtime. Something like WrongArgumentType exceptions insteadof rather unspecific AttributeError from deep inside the code would bevery convenient.Yes docstrings are nice but sometimes a simple:
foo(int:param1, string:param2) is way better than:foo(param1, param2):  """  @type param1: integer  @type parame2: string  """cheers Paul--
http://mail.python.org/mailman/listinfo/python-list-- GPG Fingerprint: B0D7 1249 447D F5BB 22C5  5B9B 078C 2615 504B 7B85
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Detecting socket connection failure

2006-07-24 Thread Dieter Maurer
[EMAIL PROTECTED] writes on 19 Jul 2006 08:34:00 -0700:
> ...
> Were you also using mac osx?

No, I have observed the problem under Linux.


> Dieter Maurer wrote:
> 
> > I have seen something similar recently:
> >
> >   I can write ("send" to be precise) to a socket closed by
> >   the foreign partner without error
> >   (but of course, the written data does not arrive at the remote side).
> >   Only the second "send" raises an exception.
> > 
> >   I expect this is a TCP bug.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Pyton Book For Newbies?

2006-07-24 Thread Gerhard Fiedler
On 2006-07-24 13:39:20, John Salerno wrote:

> But I think the usual caveat for GUI programming is, is it necessary?
> Would it work just as well to make a website interface to do your work,
> rather than spend the time learning a GUI toolkit and creating a GUI
> app?

While I don't doubt that there are many applications that are well-suited
for web apps and that there are a number of good reasons for making some
apps web-based, why do you think web programming is /not/ GUI programming? 

If you just need a few text boxes and buttons in a table-like layout, both
are easy. If you need fancier functionality, both get a bit more
complicated. There isn't much of a difference in terms of designing the
GUI, IMO. 

(Actually, complex GUI functionality is probably easier to design to run
well in a local application. You don't have to split up the GUI
functionality between server-side and client-side and you don't have to
deal with the subtle but sometimes significant differences between
browsers.)

Gerhard

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


Re: prob with struct and byte order

2006-07-24 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> hello there, all.
> 
> i have a difficult app that connects to a server to get information for
> our database here.
> this server is our access point to some equipment in the field that we
> monitor.
> 
> the messages come in over a socket connection. And according to their
> (very limited) documentation, are set up in a particular order. like
> this
> 
> STX [length indicator] [message type] [message body] ENX
> 
> length indicator = length of the message body in 4 bytes
> message type = the code for what type of message is being sent
>for example 200 = login
> message body = the actual command to send to the server
> 
> STX and ENX are the values assigned to start and stop a message.
> they are literally 'STX' and 'ENX'
> 
I believe you, but this is clearly a perversion of the single-character 
"start of transmission" and "end of transmission" that are part of the 
ASCII alphabet. So the protocol designer may have been inexperienced, 
and the documentation may be confused ...
> 
> when i capture a message i can print it to the screen and the 'STX' at
> the beginning and the 'ENX' at the end are discernable, but the rest of
> the message looks like this..
> 
> \x00\x00\x00,\x00\x00\x00\e17758\x00\x00   and so on and so forth...
> with some commas and other symbols in there. (the e before the 17758
> has a little hat on it)
>  If i print it out to a text file, i get this...
> STXNULNULNULea17758NULLNULL etc..
> 
The "\x00" is the Python repr() of a single-byte string containing a 
null byte (i.e. a byte whose decimal value is zero).

> now the 17758 is significant because it is the actual unit number of
> the machine we want to monitor. I just dont know how to extract the
> real values out of this message.
> 
> anyone have an idea where to start? i have experimented with struct,
> but do not know enough about it. Does anyone know a good tutorial about
> learning byte codes and such. The docs on pythons website explain the
> module well, but i still do not know what to do with it. Or how to
> generate a message or pull apart these values to get a message out of
> what the server sends us. 
> 
Well if the string you are seeing (when you print it from Python) looks like

"STX\x00\x00\x00,\x00\x00\x00\e17758\x00\x00 ... ETX"

then it looks like the bytes you want can be obtained, supposing the 
string is stored in variable s, as s[12:17].

  >>> s = "STX\x00\x00\x00,\x00\x00\x00\e17758\x00\x00 ... ETX"
  >>> s[12:17]
'17758'
  >>>

You may need to juggle about with the indexes a little, but one of the 
joys of Python is that the interactive interpreter is so cooperative!

Good luck.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


  1   2   >