Re: [Tutor] CRC calculation with python

2007-02-06 Thread Johan Geldenhuys
Thanks for all the replies, I got this code from a protocol spec that I must use for communications to a RS232 interface and this the way they calculate the CRC for the data in the packet. I have never done any C programming and thought that somebody in this list may be able to assist. The idea

Re: [Tutor] get cpu time used by a python script

2007-02-06 Thread Kim Branson
Hi Chris, that seems to be exactly what i need. Cheers Kim >>> import resource >>> def cpu_time(): ... return resource.getrusage(resource.RUSAGE_SELF)[0] ... Now try this out >>> def f(): ... for i in xrange(10): ... pass ... >>> start = cpu_time(); f(); dt = cpu_time() - start; pri

Re: [Tutor] get cpu time used by a python script

2007-02-06 Thread Christopher Lucas
This link may be of use to you. http://www.gossamer-threads.com/lists/ python/python/545797?page=last -Chris On Feb 6, 2007, at 9:37 PM, Kim Branson wrote: > > The time in used by the cpu for the execution of the script, rather > than the wall clock time. > > CPU execution time for program =

Re: [Tutor] get cpu time used by a python script

2007-02-06 Thread Christopher Lucas
On Feb 6, 2007, at 9:37 PM, Kim Branson wrote: > > On Feb 6, 2007, at 8:20 PM, Christopher Lucas wrote: > >> >> On Feb 6, 2007, at 9:14 PM, Kim Branson wrote: >> >>> Hi >>> >>> whats the simplest cross platform way of getting the cpu time >>> used by >>> a python script? >>> >>> Kim >> >> What

Re: [Tutor] get cpu time used by a python script

2007-02-06 Thread Kim Branson
The time in used by the cpu for the execution of the script, rather than the wall clock time. CPU execution time for program = Clock Cycles for program x Clock Cycle Time But i'm interested in the cpu cycles used purely for the python app, regardless of what other processes may be running.

Re: [Tutor] get cpu time used by a python script

2007-02-06 Thread Christopher Lucas
On Feb 6, 2007, at 9:14 PM, Kim Branson wrote: > Hi > > whats the simplest cross platform way of getting the cpu time used by > a python script? > > Kim What do you mean by cpu time, Kim? -Chris ___ Tutor maillist - Tutor@python.org http://mail.pyth

[Tutor] get cpu time used by a python script

2007-02-06 Thread Kim Branson
Hi whats the simplest cross platform way of getting the cpu time used by a python script? Kim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How does this work?

2007-02-06 Thread Tony Cappellini
Hi Danny, > > > Hi Tony, > > Ack! > > This is not safe. I would strongly recommend not to do this. There is a > much simpler way for the caller to be written: What is not safe about doing it this way ? > > import tester > tester.main([], "argument") > #

Re: [Tutor] How does this work?

2007-02-06 Thread Daniel Yoo
On Tue, 6 Feb 2007, Daniel Yoo wrote: >> this is the callee which is saved in tester.py >> ## >> import sys >> >> def main(arg): >> if arg != []: >> print"\nArgument is %s" % arg >> >> if __name__ == "__main__"": >> main(sys.argv) >> #

Re: [Tutor] How does this work?

2007-02-06 Thread Daniel Yoo
On Tue, 6 Feb 2007, Tony Cappellini wrote: > this is the caller > ## > callee=open("tester.py").read() > exec(callee) > eval("main(['', 'argument'])") > > ## > this is the callee which is saved in tester.py > ##

[Tutor] How does this work?

2007-02-06 Thread Tony Cappellini
I saw a snippet of python which is used to execute another python script, and I'm trying to understand the mechanism. Simple as it is, I don't understand how it works :-) this is the caller ## callee=open("tester.py").read() exec(callee) eval("main(['', 'argument'])")

Re: [Tutor] How to make ftplib show progress while uploading a large file

2007-02-06 Thread Terry Carroll
On Tue, 6 Feb 2007, Kent Johnson wrote: > Well, the options seem to be > - take Martin L. Lowis up on his review 5 / get 1 reviewed offer > - beg on python-dev > - beg privately to a committer of your choice > - become a committer and fix it yourself ;-) Well, I don't have the development skills

Re: [Tutor] How to make ftplib show progress while uploading a large file

2007-02-06 Thread Terry Carroll
On Mon, 5 Feb 2007, Terry Carroll wrote: > On Sun, 4 Feb 2007, [ISO-8859-1] Magnus Wirstr?m wrote: > > > I'm workinga on a program that will upload a large file to a server > > using ftp. I'm using ftplib to do this. I'm using a gui with wxpython > > and i would like to have a progressbar showi

Re: [Tutor] How to make ftplib show progress while uploading a large file

2007-02-06 Thread Kent Johnson
Terry Carroll wrote: > On Tue, 6 Feb 2007, Kent Johnson wrote: > >> Bottom line: the committers are volunteers and they work on what they >> want to. Often they prefer writing code to reviewing and applying patches. > > I wonder if there's any way to wave this one under their nose. If for no >

Re: [Tutor] Multi-line code that uses \ in doctest

2007-02-06 Thread Kent Johnson
Terry Carroll wrote: > On Tue, 6 Feb 2007, Kent Johnson wrote: > >> Kent Johnson wrote: >>> This page has more details: >>> file:///C:/Python25/Doc/lib/doctest-finding-examples.html >> Oops. The on-line version of that is here: >> file:///C:/Python25/Doc/lib/doctest-finding-examples.html > > http

Re: [Tutor] Multi-line code that uses \ in doctest

2007-02-06 Thread Terry Carroll
On Tue, 6 Feb 2007, Kent Johnson wrote: > Kent Johnson wrote: > > This page has more details: > > file:///C:/Python25/Doc/lib/doctest-finding-examples.html > > Oops. The on-line version of that is here: > file:///C:/Python25/Doc/lib/doctest-finding-examples.html http://www.python.org/doc/lib/doc

Re: [Tutor] How to make ftplib show progress while uploading a large file

2007-02-06 Thread Terry Carroll
On Tue, 6 Feb 2007, Kent Johnson wrote: > Bottom line: the committers are volunteers and they work on what they > want to. Often they prefer writing code to reviewing and applying patches. I wonder if there's any way to wave this one under their nose. If for no reason other than to stem potent

Re: [Tutor] Multi-line code that uses \ in doctest

2007-02-06 Thread Kent Johnson
Kent Johnson wrote: > This page has more details: > file:///C:/Python25/Doc/lib/doctest-finding-examples.html Oops. The on-line version of that is here: file:///C:/Python25/Doc/lib/doctest-finding-examples.html Kent ___ Tutor maillist - Tutor@python.

Re: [Tutor] sefl modifing script

2007-02-06 Thread Vladimir Strycek
on for a solution. > > Chris > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > __ NOD32 2040 (20070206) Information __ >

Re: [Tutor] sefl modifing script

2007-02-06 Thread Christopher Arndt
Vladimir Strycek schrieb: > Hi all, > > Is it possible to do self modifing script ? I think like variables which > are defined in the beginning of script could be modified by it self on > the run... like saving setting but not to external file but directly to > it self... While what you propos

Re: [Tutor] Multi-line code that uses \ in doctest

2007-02-06 Thread Kent Johnson
Don Taylor wrote: > When I try to use something like: > > >>> hexStringNums = ('1', '2', '3', '4', '5', '6',\ > ... '7', '8', '9','0') > > or: > > >>> for hexString in hexStrings: > ... for x in hexString: > ... if ((not x in hexStringChars) and > ... (

[Tutor] sefl modifing script

2007-02-06 Thread Vladimir Strycek
Hi all, Is it possible to do self modifing script ? I think like variables which are defined in the beginning of script could be modified by it self on the run... like saving setting but not to external file but directly to it self... Thanks and best regards Vladimir _

Re: [Tutor] CRC calculation with python

2007-02-06 Thread Dave Kuhlman
On Tue, Feb 06, 2007 at 12:10:36PM -0500, Chris Calloway wrote: > First, you need to find the preprocessor define for CCITT_POLY. The code > is incomplete without it. > > Second, where did this code come from? It defines an unused local named > cval, which will usually cause at least a compilati

[Tutor] Multi-line code that uses \ in doctest

2007-02-06 Thread Don Taylor
When I try to use something like: >>> hexStringNums = ('1', '2', '3', '4', '5', '6',\ ... '7', '8', '9','0') or: >>> for hexString in hexStrings: ... for x in hexString: ... if ((not x in hexStringChars) and ... (not x in hexStringNums)): ...

Re: [Tutor] CRC calculation with python

2007-02-06 Thread Chris Calloway
First, you need to find the preprocessor define for CCITT_POLY. The code is incomplete without it. Second, where did this code come from? It defines an unused local named cval, which will usually cause at least a compilation warning. This looks like a snippet, not a complete CCITT CRC calculati

Re: [Tutor] CRC calculation with python

2007-02-06 Thread Daniel Yoo
On Tue, 6 Feb 2007, Johan Geldenhuys wrote: > I'm not a C++ expert at all and I would like to find out if somebody can > explain to me how the statement below can be done in Python? > > """ > _uint16 ComCRC16(_uint8 val, _uint16 crc) > { >_uint8 i; >_uint16 cval; > >for (i=0

Re: [Tutor] CRC calculation with python

2007-02-06 Thread Kent Johnson
Johan Geldenhuys wrote: > Hi all, > > I'm not a C++ expert at all and I would like to find out if somebody can > explain to me how the statement below can be done in Python? I suggest you Google "Python CRC" and find out how others have done this, rather than trying to translate the code direc

[Tutor] CRC calculation with python

2007-02-06 Thread Johan Geldenhuys
Hi all, I'm not a C++ expert at all and I would like to find out if somebody can explain to me how the statement below can be done in Python? """ _uint16 ComCRC16(_uint8 val, _uint16 crc) { _uint8 i; _uint16 cval; for (i=0;i<8;i++) { if (((crc & 0x0001)^(val &

Re: [Tutor] MapReduce

2007-02-06 Thread Kent Johnson
Steve Nelson wrote: > On 2/5/07, Kent Johnson <[EMAIL PROTECTED]> wrote: >> You can also do this operation easily with dicts (not tested!): > > Thank you - code now complete and tests passing. Would appreciate > comments / criticisms. I did wonder if I should create a UrlAnalyser > Class rather

Re: [Tutor] timedelta doesnt do month

2007-02-06 Thread Kent Johnson
Alan Gauld wrote: > "Kent Johnson" <[EMAIL PROTECTED]> wrote > >> Because of the ambiguities of month arithmetic (what is 2005-1-31 >> plus >> one month?) datetime refuses to guess and does not support this. > >> The third-party dateutil module is not as circumspect: >> >> In [1]: import datetim

Re: [Tutor] How to make ftplib show progress while uploading a large file

2007-02-06 Thread Kent Johnson
Terry Carroll wrote: > The hard part is going to get ftplib to talk to your dialog. You're > uploading. ftplib's download methods (retrbinary and retrlines) include a > callback option, which would let you update the progress as you went, but > the upload methods (storbinary and storlines) doe

Re: [Tutor] timedelta doesnt do month

2007-02-06 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote > Because of the ambiguities of month arithmetic (what is 2005-1-31 > plus > one month?) datetime refuses to guess and does not support this. > The third-party dateutil module is not as circumspect: > > In [1]: import datetime > > In [2]: startdate = date

Re: [Tutor] best book?

2007-02-06 Thread Alan Gauld
"Andrew Purdea" <[EMAIL PROTECTED]> wrote > Hi! what do you guys think that would be the best free book, or > tutorial or > something to start learning python? The best free book for an experienced programmer is the standard tutorial that comes with Python. > Something that can also focus on i

Re: [Tutor] MapReduce

2007-02-06 Thread Steve Nelson
On 2/5/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > You can also do this operation easily with dicts (not tested!): Thank you - code now complete and tests passing. Would appreciate comments / criticisms. I did wonder if I should create a UrlAnalyser Class rather than have hanging methods: #!/