Re: Computer Language Shootout
Hi bearophileH, Thank you for the code example. Could you post some more information about ShedSkink? malv -- http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
[EMAIL PROTECTED] wrote: > Bengt Richter wrote: > > On 29 Nov 2005 14:08:12 -0800, [EMAIL PROTECTED] wrote: > > > > >We don't scrape programs from news-groups, if you'd like the program to > > >be shown on the shootout then please attach the source code to a > > >tracker item. > > You asked for something, got a response, and then you haughtily[1] declare > > that it's not being served on a special platter from your cupboard, > > and you won't deign to "scrape" the serving onto your own platter. > > Pfui. Your apparent[1] attitude turns me off, not to mention your > > top-posting. > > > I don't see it as an attitude issue but wording. It is blunt but I can > see his point. He was asking people if it is possible to > submit(contribute) some code to the test. And based on what I saw on > his site, it is inappropriate for him to just take code from ML/usenet > as all codes there need proper author(beyond courtesy, there may be > copyright issue). That is my reading anyway. That is correct, we publish an author's work under Revised BSD - we can't just take a program from a newsgroup. > > If it was nicely explained why it needs to be done this way upfront(or > in the response), I believe you may not feel it this way. > > Interestingly, I find this response quite compatible with the > personality of this group. -- http://mail.python.org/mailman/listinfo/python-list
[Announce] boost.date_time library Python bindings
Hi. I am pleased to announce a new Python package - date_time. date_time package is a Python bindings for the boost.date_time C++ library. boost.date_time is a cross-platform and open source C++ library which is designed to provide a basis for performing efficient time calculations. The boost.date_time library has been created by Jeff Garland. boost.date_time library has: * good documentation * well defined interfaces * clear concepts * comprehensive unit tests The boost.date_time library home page: http://boost.org/doc/html/date_time.html. The date_time package also has comprehensive unit tests. Documentation of boost.date_time library can be re-used for the Python package. date_time package available for Linux(Python 2.3) and Windows(Python 2.4). Download: http://tinyurl.com/cp3lo http://sourceforge.net/project/showfiles.php?group_id=118209&package_id=167694&release_id=374482 The date_time package was created using boost.python library and new code generator - pyplusplus. The boost.python library home page: http://www.boost.org/libs/python/doc/index.html The pyplusplus package home page: http://www.language-binding.net/ Enjoy. Roman Yakovenko -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
viewcharts wrote:
> I am reading two text files comparing the values in one to the other,
> this requires two loops. The problem is that when the inner loop is
> finished, it never goes back into the loop. Any suggestions?
>
>
> for refSymbol in symbols.readlines():
> for lookupSymbol in myfile.readlines():
> showme = lookupSymbol.split('\t')
> if showme[3] == refSymbol.strip():
> priceNew.write(refSymbol.strip()+" "+showme[10])
>
>
>
When the inner loop is finished for the 1st time,
myfile has been read. So next time you start to the
loop, myfile.readlines() returns an empty list.
Something like this should be better:
lookupSymList = myfile.readlines()
for refSymbol in symbols.readlines():
for lookupSymbol in lookupSymList:
showme = lookupSymbol.split('\t')
if showme[3] == refSymbol.strip():
priceNew.write(refSymbol.strip()+" "+showme[10])
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
viewcharts wrote:
> I am reading two text files comparing the values in one to the other,
> this requires two loops. The problem is that when the inner loop is
> finished, it never goes back into the loop. Any suggestions?
>
>
> for refSymbol in symbols.readlines():
> for lookupSymbol in myfile.readlines():
> showme = lookupSymbol.split('\t')
> if showme[3] == refSymbol.strip():
> priceNew.write(refSymbol.strip()+" "+showme[10])
As another poster said, you have "used up" the inner iterable in the
first round, it is an iterable, just not like a list where you can use
multiple times.
Either turn it into a list(so you can reuse it) or better yet, turn it
into a dict which would speed up the matching process. Either way, it
better be done outside of the outer loop.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Death to tuples!
Mike Meyer wrote:
>>> An object is compatible with an exception if it is either the object
>>> that identifies the exception, or (for exceptions that are classes)
>>> it is a base class of the exception, or it is a tuple containing an
>>> item that is compatible with the exception.
>>
>> Requiring a tuple here means that the code doesn't have to worry
>> about a possible recursive data structure.
>
> How so?
>
> except ExceptType1, (ExceptType2, ExceptType3, (ExceptType4,
> ExceptType5):
>
> I suspect this won't work, but meets the description.
>
> Lists could be used here with the same restrictions as tuples.
I think you meant:
except (ExceptType1, (ExceptType2, ExceptType3, (ExceptType4,
ExceptType5))):
otherwise the first comma separates the exception specification from the
target and you get a syntax error even before the syntax error you might
expect from the unmatched parentheses. And yes, that works fine.
e.g. You can do this:
>>> ExcGroup1 = ReferenceError, RuntimeError
>>> ExcGroup2 = MemoryError, SyntaxError, ExcGroup1
>>> ExcGroup3 = TypeError, ExcGroup2
>>> try:
raise ReferenceError("Hello")
except ExcGroup3, e:
print "Caught",e
Caught Hello
>>> ExcGroup3
(, (, , (, )))
>>>
The exception tuple has the same sort of nesting as your example, and no
matter how deeply nested the system will find the relevant exception.
Now consider what happens if you used a list here:
>>> ExcGroup1 = [ReferenceError, RuntimeError]
>>> ExcGroup2 = MemoryError, SyntaxError, ExcGroup1
>>> ExcGroup3 = TypeError, ExcGroup2
>>> ExcGroup1.append(ExcGroup3)
>>> ExcGroup3
(, (, , [, , (, (, , [...]))]))
>>> try:
raise ReferenceError("Hello")
except ExcGroup3, e:
print "Caught",e
Traceback (most recent call last):
File "", line 2, in -toplevel-
raise ReferenceError("Hello")
ReferenceError: Hello
>>>
As it currently stands, the exception is not caught because anything in the
exception specification which is not a tuple is considered to be a
(potential) exception.
With lists is suddenly becomes possible to have a recursive data structure.
repr goes to a lot of effort to ensure that it can detect the recursion and
replace that particular part of the output with ellipses. The exception
handling code would have to do something similar if it accepted lists and
that would slow down all exception processing. By only traversing inside
tuples we can be sure that, even if the data structure as a whole is
recursive, the part which is traversed is not.
(Note that the repr code also fails to detect the recursive tuple, it isn't
until it hits the list a second time that it spots the recursion.)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
I think I understand my problem, but first the sample code extracted to my project. Rq : it's an automatic run of unitary test, the names of unitary test are parameter of main program "imported" file via the "execfile" function (an usage of "import" instead may be a solution) : file run.py : def run_ut( test ) : # to have the problem the execfile MUST be in a function execfile( test ) run_ut( "ut_00.py" ) file ut_00.py : import math def f() : ## global math # <-- just decomment this line to avoid error print "Second access :" print "\t",math.pi # ERROR print "First access :" print "\t",math.pi # OK f() -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question concerning formatted output
Hi all, thanks for all your answers. Is see that there are - as ususal - several ways to accomplish this. I decided to go for the way Frederik suggested, because it looked as the most straight forward method for that kind of data. Thanks again, ./Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
lot's of solutions proposed in the discussion works fine : file run.py : def run_ut( test ) : # to have the problem the execfile MUST be in a function # execfile( test ) # ERROR execfile( test, globals() ) # OK exec "import ut_00" # OK exec file(test).read() # OK run_ut( "ut_00.py" ) Thanks a lor -- http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
yes I have imported math in the file I want to use it. But the imported module "math" is not visible in function without a global instruction. But the solutions already proposed seems to work file for my sample program. I will try on my project soon :) -- http://mail.python.org/mailman/listinfo/python-list
Re: an intriguing wifi http server mystery...please help
Paul McNett wrote: >[EMAIL PROTECTED] wrote: > > >>1) >>Laptop wired, client >>Desktop wired, server >>GREAT! >>webpage served in 2 seconds >> >>2) >>Laptop wired, server >>Deskop wired, client >>GREAT! >>webpage served in 2 seconds >> >>3) >>Laptop wireless, client >>Desktop wireless, server >>GREAT! >>webpage served in 2 seconds >> >>4) >>Laptop wireless, server >>Desktop wireless, client >>CRAP! >>webpage served in 90 seconds >> >> >>What the heck is happening? >> >> > >Please post your routing tables and, if you are referencing your server >machine >by name, your name server addresses (/etc/resolv.conf on Linux). > > > > i'm inclined to agree, your client and server might be taking totally different routes to get to each other and hence the 90ms -- http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
sample and solution posted in another branch of this thread -- http://mail.python.org/mailman/listinfo/python-list
Debugging functionality for embedded Python
Hi, i have embedded the Python 2.3 engine into a C++ framework. Now i want to add to the basic editing features that are provided by this C++ framework also some debug functionality. Until now i did not find any documentation on how to do this. The Python C/API manual does not say much about it. Does anyone know any literature/references regarding this topic? What i would need would be tracebacks of errors with info on line numbers, files and so on. Greets, Thomas Korimort. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode speed
V Tue, 29 Nov 2005 10:14:26 +, Neil Hodgson napsal(a):
> David Siroky:
>
>> output = ''
>
> I suspect you really want "output = u''" here.
>
>> for c in line:
>> if not unicodedata.combining(c):
>> output += c
>
> This is creating as many as 5 new string objects of increasing
> size. To build large strings, some common faster techniques are to
> either create a list of characters and then use join on the list or use
> a cStringIO to accumulate the characters.
That is the answer I wanted, now I'm finally enlightened! :-)
>
> This is about 10 times faster for me:
>
> def no_diacritics(line):
> if type(line) != unicode:
> line = unicode(line, 'utf-8')
>
> line = unicodedata.normalize('NFKD', line)
>
> output = []
> for c in line:
> if not unicodedata.combining(c):
> output.append(c)
> return u''.join(output)
>
> Neil
Thanx!
David
--
http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
[EMAIL PROTECTED] wrote: > I think I understand my problem, but first the sample code extracted to > my project. > > Rq : it's an automatic run of unitary test, the names of unitary test > are parameter of main program "imported" file via the "execfile" > function (an usage of "import" instead may be a solution) : > > file run.py : > > > def run_ut( test ) : > # to have the problem the execfile MUST be in a function > execfile( test ) > run_ut( "ut_00.py" ) > > > file ut_00.py : > > import math > > def f() : > ## global math # <-- just decomment this line to avoid error > print "Second access :" > print "\t",math.pi # ERROR > > print "First access :" > print "\t",math.pi # OK > f() > How interesting. Can anyone actually explain the behaviour here? Without the global statement everything works as I expect: the 'import math' is executed in the local scope of run_ut, so the function f() doesn't find it either in its local scope nor in global scope. Inserting 'global math' at the outer level in ut_00.py (e.g. before the 'import math') also works as I expect: math now becomes a global variable and is visible to f(). What I really don't understand is why the global statement *inside* f affects the scope of math outside f. If we had nested functions then a global variable in an inner function doesn't affect scope in outer functions. I realise that f() here isn't a nested function, but even so it looks to me like a bug unless I'm missing something. (Technically the program is invoking undefined behaviour as the language reference says that names listed in a global statement must not be defined in an import statement, but that isn't really relevant since you can replace the import with an assignment statement and get the same weird behaviour.) -- http://mail.python.org/mailman/listinfo/python-list
sha1,256,512 on files
Hi ! I have a problem in Windows. I need to get the filelist in HDD-s, with sha-N value for every file (to see what changed in the past). 1. I see that Python supports the sha-1. But I need to make sha value in big files to (swap file, iso-s, etc.). Possible that file size more than 2 GB, so I cannot read as string... How to get the sha value of a file ? If python not supports that, please give me a link with freeware command line utility that can do it,and can pass to python. 2. How to generate sha-256, or sha-512 values ? Thanx for every help: dd -- http://mail.python.org/mailman/listinfo/python-list
Debugging of Python code in embedded interpreter
Hi! I have embedded a Python interpreter into a C++ framework. When running some Python code in the interpreter, how can i get a traceback with line number file..., when an exception occurs? Greetings, Thomas Korimort. -- http://mail.python.org/mailman/listinfo/python-list
Re: Death to tuples!
On 2005-11-29, Duncan Booth <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: > >> The question is, should we consider this a problem. Personnaly, I >> see this as not very different from functions with a list as a default >> argument. In that case we often have a list used as a constant too. >> >> Yet python doesn't has a problem with mutating this list so that on >> the next call a 'different' list is the default. So if mutating >> a list used as a constant is not a problem there, why should it >> be a problem in your example? >> > Are you serious about that? I'm at least that serious that I do consider the two cases somewhat equivallent. > The semantics of default arguments are quite clearly defined (although > suprising to some people): the default argument is evaluated once when the > function is defined and the same value is then reused on each call. > > The semantics of list constants are also clearly defined: a new list is > created each time the statement is executed. Consider: > > res = [] > for i in range(10): > res.append(i*i) > > If the same list was reused each time this code was executed the list would > get very long. Pre-evaluating a constant list and creating a copy each time > wouldn't break the semantics, but simply reusing it would be disastrous. This is not about how things are defined, but about should we consider it a problem if it were defined differently. And no I am not arguing python should change this. It would break too much code and would make python all the more surprising. But lets just consider. Your above code could simply be rewritten as follows. res = list() for i in range(10): res.append(i*i) Personnaly I think that the two following pieces of code should give the same result. def Foo(l=[]):def Foo(l): ... ... Foo() Foo([]) Foo() Foo([]) Just as I think, you want your piece of code to give the same result as how I rewrote it. I have a problem understanding people who find the below don't have to be equivallent and the upper must. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: sha1,256,512 on files
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > I see that Python supports the sha-1. But I need to make sha value in > big files to (swap file, iso-s, etc.). Possible that file size more > than 2 GB, so I cannot read as string... > How to get the sha value of a file ? Use the sha.update method. Something like: ctx = sha.new() while True: x = f.read(16384) if not x: break ctx.update(x) hash = ctx.digest() > How to generate sha-256, or sha-512 values ? There are some modules around for this. Unless you're trying to interoperate with something that needs them, or have some other reason to want them, I wouldn't bother. -- http://mail.python.org/mailman/listinfo/python-list
Re: General question about Python design goals
On 2005-11-29, Bengt Richter <[EMAIL PROTECTED]> wrote:
> On 29 Nov 2005 08:27:43 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:
>
>>On 2005-11-28, Duncan Booth <[EMAIL PROTECTED]> wrote:
>>> Antoon Pardon wrote:
>>>
No I gave an example, you would implement differently. But even
if you think my example is bad, that would make it a bad argument
for tuples having list methods. That is not the same as being
a good argument against tuples having list methods.
>>>
>>> Tuples don't have list methods, therefore any code which seems to require a
>>> tuple with list methods should make you stop and consider whether your
>>> design is wrong.
>>
>>IMO that is a non-sequitur, because that makes what is good or bad
>>design dependand on the language used.
>>
>>If I have a design that seems to require tuples with a count method,
>>then wether that is a good or bad design doesn't depend on
>>whether or not python allows that or not.
>>
> No, but if your requirement is to count __eq__ - matching items in a
> tuple, maybe your sense of orthogonality ought to abstract out the
> sequence aspect in some other way than seeing it as a seeming method
> requirement for tuple. A tuple.count method has implications about
> attribute access to a special object, tuple, which then you have
> to deal with for every new object you introduce, unless you want to
> inherit it from object, but that means object becomes a
> mega swiss army knife in short order.
I'm open too other possibilties, and I'm interrested in your iterator
methods. It is just that on the one hand people talk about the
advantages of tuples as keys, (no need to copy the keys, since
they are immutable) while on the other hand when tuples lack
some functionality tell me to cast them as lists, completely
eliminating the adavantage tuples have.
> So IMO the thing is not to ask for a specific solution like "why
> not a count method for tuples?" You'll just get answers to that literal
> question, with some elaborations. Instead, if you put it in the form
> of what your general requirement really is (I'm guessing ;-) which I
> assume is to be able to apply list count method _functionality_ to
> anything which quacks like a list, including tuples etc. In short,
> anything iterable.
Sure, A base sequence type, from which tuples and lists would inherit
that would provide for this functionality would be good too. Of
course it isn't that difficult to write a general function that works
on any iterable either.
> Now the problem is to bring program and data together with some
> spelling in python. data.method() is certainly one spelling, but
> so is method(data). You gain something either way. The first allows
> you to associate the method and data without executing the method, i.e.,
> data.method is a bound method object that has the data-method association
> built in, and it can be passed around.
There are other ways to get a bound method like object, so I don't
consider that a big advantage.
> method(data) does the call right
> away and uses a diferent name space search path to find method, and is
> not necessarily associated with type(data). To ask for common methods
> for all objects that exhibit some similar aspect is to entangle their
> types in some way or to duplicate stuff. Sometimes it's fine to
> derive from a common base etc., but
>
> why not a built-in count function that does something like (untested)
>
> def count(obj, match_item, eq=operator.eq):
> return sum(1 for item in iter(obj) if eq(item, match_item))
Sure. The problem here is a bit about python only providing a partial
solution. If python didn't provide any count methods I think nobody
would have complained. If you needed this, you could easily provide
it your self.
But now python does provide it, but not for all classes it seems
applyable to, so people question why.
> which would give a little flexibility about eq comparison as well as
> wide applicability to any sequence? index too (untested)
>
> def index(obj, match_item, eq=operator.eq):
> try: return (i for i, item in enumerate(obj) if eq(item,
> match_item)).next()
> except StopIteration: raise ValueError('index(seq, item): item not in
> seq')
>
> why doesn't list have a find like str? ;-)
>
> def find(obj, match_item, eq=operator.eq):
> try: return (i for i, item in enumerate(obj) if eq(item,
> match_item)).next()
> except StopIteration: return -1
>
> One could create an alternate spelling for obj.count(thing) using the count
> function above.
> You can spell it now as
>
> count.__get__(obj, type(obj))(thing)
>
> if you want to duplicate the effect of having the count function retrieved
> from type(obj)
> as if it were a method defined there. Or you can spell it
>
> count(obj)
>
> which doesn't seem too bad ;-)
> But now the problem is cluttering the __builtins__ space. So maybe it would be
> better to write
> from sequence_goodies import count
>
Newbie question: Getting "unstaisfied" error while installing scipy
Hello! I'm trying to install scipy_core_0.6.1-1.i586 on my Mandrake Linux (via RPM) 10.2 machine. I double click on the rpm icon but it gives the following error... scipy_core_0.6.1-1.i586 failed due to unstaisfied libg2c.so.0 What do i do?? I know this query is not directly related to Python.. but i'd appreciate your inputs Thanks in advance, Have a great day -- http://mail.python.org/mailman/listinfo/python-list
Winsound doesn't play whole sound?
Hello,
I'm having a problem with playing WAV files using Winsound.
If I use winsound to play a certain WAV files only the first few seconds
of the file get played. I think this comes because these files contain
some parts of silence. There winsound seems the stop playing the files
(windows media player plays the sounds correctly).
Does anybody have an idea about how I could fix this problem? I have
considered installing extra modules like PyMedia. But this would limit
the portability of my script (I would have to install PyMedia on all the
Pc's I want to use my script on).
Many Thanks,
Dieter
Just as a reference, the code I use:
winsound.PlaySound("My_wav.wav", winsound.SND_FILENAME)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Death to tuples!
Antoon Pardon wrote: > But lets just consider. Your above code could simply be rewritten > as follows. > > res = list() > for i in range(10): > res.append(i*i) > I don't understand your point here? You want list() to create a new list and [] to return the same (initially empty) list throughout the run of the program? > Personnaly I think that the two following pieces of code should > give the same result. > > def Foo(l=[]):def Foo(l): > ... ... > > Foo() Foo([]) > Foo() Foo([]) > > Just as I think, you want your piece of code to give the same > result as how I rewrote it. > > I have a problem understanding people who find the below don't > have to be equivallent and the upper must. The left one is equivalent to: __anon = [] def Foo(l): ... Foo(__anon) Foo(__anon) The left has one list created outside the body of the function, the right one has two lists created outside the body of the function. Why on earth should these be the same? Or to put it even more simply, it seems that you are suggesting: __tmp = [] x = __tmp y = __tmp should do the same as: x = [] y = [] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python as Guido Intended
On 2005-11-29, Mike Meyer <[EMAIL PROTECTED]> wrote: > Antoon Pardon <[EMAIL PROTECTED]> writes: >>> You see, you can make languages more powerful by *removing* things >>> from it. >> You cast this in way to general terms. The logic conclusion >> from this statements is that the most powerfull language >> is the empty language. > > The only way you reach that conclusion is if you read the statement as > saying that removing things *always* makes a langauge more > powerful. That's not what I said, I would say it is the common interpretation for such a sentence. > and that's as false as the belief > that adding things always makes a language more powerful. > >>> Wrong. There are some thing which there should *not* be a way to do. >>> For instance, there should not be a way to produce a segmentation >>> fault - which means certain features common to other languages will >>> never be added. >> Then C-extentions shouldn't be allowed. > > C-extensions aren't part of Python. As far as I understand, if you implement a class with a C-extension, then that class is understood to be part of Python. So if you think there should be no way to produce a segmentation fault in python you shouldn't allow such classes. >>> We don't talk much about how you produce buffer >>> overfows in Python, but people have asked for that as well. Adding >>> ways to write hard-to-read code is frowned upon. And so on. >> Do you mean people have asked for the possibility that a buffer >> overflow would overwrite other variables? > > Buffer overflows don't have to overwrite variables. They just asked > how you create buffer overflows in Python. I do wonder what they mean with a buffer overflow. Would the following classify: buf = range(10) buf[10] = 10 >>> I won't speak for others, but I wouldn't reject it out of hand. You >>> haven't provided enough information. Accepting it just because it adds >>> a way to do something is wrong. First, you have to ask whether or not >>> that something is something we want in Python at all. Then you >>> consider whether how the way proposed fits with the language: is it >>> ugly? >> That is a highly subjective question, answering it says more about >> the person then about the proposal. > > True. But whether or not a language is good is a highly subjective > question. Since the goal - keeping python good to the people who > already consider it good - is subjective, it's only natural that part > of the evaluation process be sujectie. > >>> Is it prone to abuse? >> I don't see why this is always brought up, given the number of >> features that can be abused in python. > > Just because Python isn't perfect is no reason to make it worse. Why is it worse. You seem to think that if one has a toolbox, which lacks a hammer, that the fact that the hammer can be abused makes your toolbox less usefull if you add a hammer to it. We have a toolbox, full of equipment that can be abused, yet that something else can be abused too, seems to be a mayor stumbling block for adding it. >>> In summary, the design philosophy is that it's better to do without >>> some facility than to add it in a way that doesn't fit with the >>> language, and the process reflects that. >> I don't mind that a proposal is worked on and that counter-proposals >> can be made. But some people just seem to counter any new proposal, >> while other are more interrested in searching for ways to make >> the new proposal fit the language. Now sometimes a proposal can't >> be fitted and gets rejected, so be it. But maybe more could be >> fitted in the langauge if more people were willing to look for >> ways to fit something, instead of rejecting it simply because >> the current proposal doesn't fit properly yet. > > The only way this would be good is if "more features" were inherently > better. That's simply not true. So the change in behavior you're > looking for isn't clearly good. No, this is good while there are still possible features that could make python a better language -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
How could I ask Thread B to call B().Method() from inside Thread A's run?
I have 2 thead instances, A and B, In A's run method, if I call B.Method(), it will be executed in thead A, but I want B.Method() to be executed in B's thread. That's to say, I want to tell Thead B to do B's stuff in B's thread, kinda like PostMessage in win32. Can I do it in python? How? Thank you in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
"Krystian" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi > are there any future perspectives for Python to be as fast as java? Sure, if/when Python becomes as water-logged with obtruse OO-layers as Java is now. Python is faster than Java. Because Python per design generally is a thin layer of glue poured over binary C modules, it does not take very many instructions before one hits the fastest speed that the platform can go at. I would test it, then worry about it. > i would like to use Python as a language for writing games. >From the speed requirement: Is that correspondance chess by any chance?? -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Oracle 9i client for Linux
> It is version 10, would it be compatible with 9i servers? Yes. > Indeed I use cx_oracle but on M$ yet. Want to move to Linux. If you need to compile yourself, the instant client headers don't live where a full-blown Oracle install would put them and you may need to slightly alter setup.py. cx_oracle has a support list, see http://sourceforge.net/projects/cx-oracle/ Cheers, Bernard. -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Frithiof Andreas Jensen wrote: > > From the speed requirement: Is that correspondance chess by any chance?? > Regular chess at tournament time controls requires speed too. Any pure Python chess program would lose badly to the best C/C++ programs out there now. I would also like to see Half Life 2 in pure Python. /David -- http://mail.python.org/mailman/listinfo/python-list
Re: After migrating from debian to ubuntu, tkinter "hello world" doesn't work
Mandus ha escrito: > works just fine on my ubunty 5.10. Make sure you have the python2.4-tk > package installed (sudo apt-get install python2.4-tk). > yes, i got it. It's a fresh instalation from a cd in a brand new laptop. I tried to reinstall python2.4-tk and many other packeges :-( There are two errors _tkinter.TclError: this isn't a Tk application invalid color name "#efebe7 " It is a tk problem. amsn (also based on tk) displays the same error. Somebody in a post said that aptitude install xrgb solved it, but it didn't work for me. It seems to be a problem of X window. In a debian box, it works fine. But if I export the display to the ubuntu one, get same error. (Other apps export fine) And even running it in the debian box, with a vnc display in the ubuntu, same error! :-(( > > -- > Mandus - the only mandus around. -- http://mail.python.org/mailman/listinfo/python-list
Re: After migrating from debian to ubuntu, tkinter "hello world" doesn't work
[EMAIL PROTECTED] wrote: > Hi > > My tkinter apps worked fine in debian linux (woody and sarge) > I moved to ubuntu 5.10 > > I follow the 'hello world' test as seen in > http://wiki.python.org/moin/TkInter > Ubuntu uses X.org. Did your Debian distro use xfree86? -- http://mail.python.org/mailman/listinfo/python-list
Re: How could I ask Thread B to call B().Method() from inside Thread A's run?
could ildg wrote:
> I have 2 thead instances,
> A and B,
> In A's run method, if I call B.Method(), it will be executed in thead A,
> but I want B.Method() to be executed in B's thread.
> That's to say, I want to tell Thead B to do B's stuff in B's thread,
> kinda like PostMessage in win32.
> Can I do it in python?
> How?
> Thank you in advance.
Here is a really simple, stupid example of what I think you're trying to
do. You probably want to use a Queue between your threads.
##
#!/usr/bin/python
import threading
import Queue
class A(threading.Thread):
def __init__(self, q):
self.q = q
threading.Thread.__init__(self)
def run(self):
for i in range(10):
print "Thread A putting \"something\" onto the queue"
self.q.put("something")
self.q.put("stop")
class B(threading.Thread):
def __init__(self, q):
self.q = q
self.proceed = True
threading.Thread.__init__(self)
def do_something(self):
print "Thread B doing something"
def do_stop(self):
print "Thread B should stop soon"
self.proceed = False
def run(self):
while self.proceed:
print "Thread B pulling sommething off of the queue"
item = q.get()
print "Thread B got %s" % item
getattr(self, "do_" + str(item))()
if __name__ == "__main__":
q = Queue.Queue()
a = A(q)
a.start()
b = B(q)
b.start()
a.join()
b.join()
##
HTH,
- jmj
--
http://mail.python.org/mailman/listinfo/python-list
Re: python speed
>I would also like to see Half Life 2 in pure Python. or even quake1, do you think it could have any chances to run smoothly? or maybe demoscene productions... -- http://mail.python.org/mailman/listinfo/python-list
XML processing
Hi! I need to do some XML programming, and I have installed the PyXML package. However I read some stuff on the web that using the modules in PyXML is slow and not elegant and it uses up lots of memory, and I don't know what else. Is the current implementation of PyXML legging behind in comparison to similar tools in available for other languages? Thanks, Catalin -- == << We are what we repeatedly do. >> << Excellence, therefore, is not an act >> << but a habit. >> == -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Dr. Armin Rigo has some mathematical proof, that High Level Languages like esp. Python are able to be faster than low level code like Fortran, C or assembly. I am not wise enough to understand that proof. Maybe I understood those papers totally wrong and he was saying something totally different. But whatever, the pypy-team is formed out of some more people of his calibre and founded by the European Union to provide "butter by the fish", say, to produce real code that may deliver that promise. And I could see real development just from watching the BDFL: 3 years ago PyPy was 2000times slower then CPython, and Guido was joking "and that number is growing", this year there were not officially negated romours that sometime maybe PyPy could be the reference implementation of Python; and also reports that PyPy is only 18 times slower then CPython. For the time being, my Python programs just sit and wait for database, network, user input or the acting of COM-Applications like Excel or Winword. Sometimes I even have 3 threads, one to wait for user, one for database and one to wait for Excel - boy, I wait fast! But on the other hand, I do no real world applications like triple mersenne first person shooters, only business software like the one which in earlier time was written in COBOL or carved into cave walls. Less challenge, higher reward. Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: Help!!! On Tkinter Menu problem!!!
Xuening wrote: > I have a problem about menu by using Tkinter. I want to make a dynamic > menu. That is when I create a new view/window, one menuitem will be > added to the menu. and when I kill a window, the correponding menuitem > will be deleted. I write a simple code and I can add menuitem now. But > I don't know how to remove the item when I close the window. > [code snipped] > > > Maybe I should bind something to event. Everytime I close the > window, the name of the window should be removed from the windowList > and refresh the all the menuitems again. But I don't know how and > where to add the "destroy" event. Can anyone give me a hand > > Thanks a lot!! > Well first of all I presume you understand that menus have a delete method, so you can remove items. If not, see "delete()" in http://effbot.org/tkinterbook/menu.htm Are these top-level windows you are deleting? If so, look under "Protocol" in http://effbot.org/zone/tkinter-events-and-bindings.htm for details of how to handle WM_DELETE_WINDOW. The handler for each window can delete the appropriate menu item. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Harald Armin Massa wrote: > Dr. Armin Rigo has some mathematical proof, that High Level Languages > like esp. Python are able to be faster than low level code like > Fortran, C or assembly. > Faster than assembly? LOL... :) /David -- http://mail.python.org/mailman/listinfo/python-list
ANN: DecInt 0.3 - Arithmetic for very large decimal integers
DecInt is a class that support arithmetic on very large decimal integers. For example, it can calculate the decimal form of the 42nd Mersenne prime, all 7,816,230 digits, in less than 21 seconds. And less than 6 seconds if gmpy 1.01 is available. This version is significantly faster than the prior version. Multiplication used a combination of 4-way Toom-Cook and Nussbaumer convolution. Pure Python multiplication is less than 10x slower than GMP's hand optimised assembler code! Division uses a new algorithm based on David M. Smith's division algorithm. Pure Python division is 16x slower than GMP but can actually be faster in some instances; for example, dividing a 2,000,000 digit number by an 800,000 digit number. DecInt can be found at http://home.comcast.net/~casevh/ (DecInt used to be called BigDecimal; I renamed it to avoid confusion with the "decimal" class include with Python.) Enjoy, casevh -- http://mail.python.org/mailman/listinfo/python-list
Re: python number handling - tiny encryption algorithm
Hi! Kinsley Turner wrote: [snip] > > def teaDecipher(input,key): > y = input[0] > z = input[1] > n = 32 > sum = 0xC6EF3720 > delta=0x9E3779B9 > > while (n > 0): > n -= 1 > z -= (y << 4 ^ y >> 5) + y ^ sum + key[sum>>11 & 3]; > sum -= delta; > y -= (z << 4 ^ z >> 5) + z ^ sum + key[sum&3]; > return y,z > That seems to return hugely-long integers (around 30? digits), whereas I'd > expect > them to max-out at 2^32. Yes, python integers overflow to longs, which is a good thing for your use-case, since python's int type corresponds to a signed long on C level. To make the code do the right thing you have to keep integers in the range 0, 2^32 by hand by inserting something like x = x % 2 ** 32 y = y % 2 ** 32 into the while loop. Cheers, Carl Friedrich -- http://mail.python.org/mailman/listinfo/python-list
Re: Winsound doesn't play whole sound?
Dieter Vanderelst wrote:
> Hello,
>
> I'm having a problem with playing WAV files using Winsound.
>
> If I use winsound to play a certain WAV files only the first few seconds
> of the file get played. I think this comes because these files contain
> some parts of silence. There winsound seems the stop playing the files
> (windows media player plays the sounds correctly).
[snip]
> Just as a reference, the code I use:
> winsound.PlaySound("My_wav.wav", winsound.SND_FILENAME)
This is totally a guess, but add the following to the end of your test
script:
import time
time.sleep(10)
Did the file play for ten seconds longer? I don't know anything about
winsound, but I'm guessing that the PlaySound call is non-blocking, and
your playback stops because your process is quitting before the sound
has played.
Graham
--
http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
"malv" wrote: > Could you post some more information about ShedSkink? http://sourceforge.net/projects/shedskin/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Death to tuples!
On 2005-11-30, Duncan Booth <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: >> But lets just consider. Your above code could simply be rewritten >> as follows. >> >> res = list() >> for i in range(10): >> res.append(i*i) >> > I don't understand your point here? You want list() to create a new list > and [] to return the same (initially empty) list throughout the run of the > program? No, but I think that each occurence returning the same (initially empty) list throughout the run of the program would be consistent with how default arguments are treated. > >> Personnaly I think that the two following pieces of code should >> give the same result. >> >> def Foo(l=[]):def Foo(l): >> ... ... >> >> Foo() Foo([]) >> Foo() Foo([]) >> >> Just as I think, you want your piece of code to give the same >> result as how I rewrote it. >> >> I have a problem understanding people who find the below don't >> have to be equivallent and the upper must. > > The left one is equivalent to: > > __anon = [] > def Foo(l): >... > > Foo(__anon) > Foo(__anon) So, why shouldn't: res = [] for i in range(10): res.append(i*i) be equivallent to: __anon = list() ... res = __anon for i in range(10): res.append(i*i) > The left has one list created outside the body of the function, the right > one has two lists created outside the body of the function. Why on earth > should these be the same? Why on earth should it be the same list, when a function is called and is provided with a list as a default argument? I see no reason why your and my question should be answered differently. > Or to put it even more simply, it seems that you are suggesting: > > __tmp = [] > x = __tmp > y = __tmp > > should do the same as: > > x = [] > y = [] No, I'm not suggesting it should, I just don't see why it should be considered a problem if it would do the same, provided this is the kind of behaviour we already have with list as default arguments. Why is it a problem when a constant list is mutated in an expression, but isn't it a problem when a constant list is mutated as a default argument? -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get started in GUI Programming?
[EMAIL PROTECTED] wrote: > Can anyone offer any suggestions as to the least painful way forwards? I learnt more in half-an-hour with these lectures than days reading the book and I've been writing programs of all sorts for more than 25 years. http://wiki.python.org/moin/Intro_to_programming_with_Python_and_Tkinter Rod (slightly late answer... sorry) -- http://mail.python.org/mailman/listinfo/python-list
Cropping sound files
Hello,
My previous problem with Winsound has boiled down to a new problem.
I have some soundfiles (wav) of which I only need the n first seconds.
So, I thought I could crop them using
the standard wave-module:
This is some of my code:
#I open the wav file and I read the first n frames
f_org = wave.open(file_name, 'r')
frames = f_org.readframes(f_org.getframerate( )*sec)
#these frames I write to a new file
#the parameters for the new file are the same as for the original
file,
#only the number of frames is different
f_new.setparams(pra)
f_new.writeframesraw(frames).
This works fine for short files (up to 20 sec). But if I try this with
larger files, an later play the new cropped files with windsound,
winsound doesn't play the whole
new file (although windows media player does so).
Does anybody has a piece of code that I can use to crop my files?
Because I must be doing something wrong.
Thanks,
Dieter
Graham Fawcett wrote:
Dieter Vanderelst wrote:
Hello,
I'm having a problem with playing WAV files using Winsound.
If I use winsound to play a certain WAV files only the first few seconds
of the file get played. I think this comes because these files contain
some parts of silence. There winsound seems the stop playing the files
(windows media player plays the sounds correctly).
[snip]
Just as a reference, the code I use:
winsound.PlaySound("My_wav.wav", winsound.SND_FILENAME)
This is totally a guess, but add the following to the end of your test
script:
import time
time.sleep(10)
Did the file play for ten seconds longer? I don't know anything about
winsound, but I'm guessing that the PlaySound call is non-blocking, and
your playback stops because your process is quitting before the sound
has played.
Graham
--
http://mail.python.org/mailman/listinfo/python-list
Re: Multiple versions
This will work fine for me Tim, thank you for your time! "Tim Golden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] (Just to keep things readable, I've reordered the posts top-to-bottom chronologically. And "Me" is the cognomen of the original poster, not simply a redundant personal pronoun!) [Me] > I need to install both 2.3 and 2.4 on my Win2000 system. > Can someone please > give me a pointer as to how to do this? Thanks! [Tim Golden] > ... The simple answer is: just install > them (in different directories, eg c:\python23, > c:\python24), installing last the one which > you want your .py/.pyw files to be associated with. [Me] > Thank you for your reply! Is there a simple way to > change the .py/.pyw associations? Like a registry > setting I can "toggle"? Or are there lots of other > things involved, system directory libraries etcetera? Assuming that you're not doing anything fancy with system or Python paths -- and I guess from the tenor of your questions that you're not -- then it's just the same as changing any other file association on Windows. There was a thread on this subject fairly recently, but in essence you can either use the File Associations tab on Explorer (on XP it's under Tools > Folder Options > File Types) or you can use the command line equivalent: FTYPE Python.File="C:\Python24\python.exe" "%1" %* replacing c:\python24 by whatever is appropriate. If you really wanted to do things which involved testing your programs against different versions of Python, which I imagine might be your aim, then you probably want either to write some sort of batch file wrapper (search c.l.py for some examples of this in the past) or to use a MoveablePython installation: http://www.voidspace.org.uk/python/movpy/ which is designed for this kind of things (according to their introduction). TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Death to tuples!
Antoon Pardon wrote: >> The left one is equivalent to: >> >> __anon = [] >> def Foo(l): >>... >> >> Foo(__anon) >> Foo(__anon) > > So, why shouldn't: > >res = [] >for i in range(10): > res.append(i*i) > > be equivallent to: > > __anon = list() > ... > >res = __anon >for i in range(10): > res.append(i*i) Because the empty list expression '[]' is evaluated when the expression containing it is executed. > >> The left has one list created outside the body of the function, the >> right one has two lists created outside the body of the function. Why >> on earth should these be the same? > > Why on earth should it be the same list, when a function is called > and is provided with a list as a default argument? Because the empty list expression '[]' is evaluated when the expression containing it is executed. > > I see no reason why your and my question should be answered > differently. We are agreed on that, the answers should be the same, and indeed they are. In each case the list is created when the expression (an assigment or a function definition) is executed. The behaviour, as it currently is, is entirely self-consistent. I think perhaps you are confusing the execution of the function body with the execution of the function definition. They are quite distinct: the function definition evaluates any default arguments and creates a new function object binding the code with the default arguments and any scoped variables the function may have. If the system tried to delay the evaluation until the function was called you would get surprising results as variables referenced in the default argument expressions could have changed their values. -- http://mail.python.org/mailman/listinfo/python-list
Re: Death to tuples!
Antoon Pardon a écrit : > On 2005-11-30, Duncan Booth <[EMAIL PROTECTED]> wrote: > >>Antoon Pardon wrote: >> >>>But lets just consider. Your above code could simply be rewritten >>>as follows. >>> >>> res = list() >>> for i in range(10): >>> res.append(i*i) >>> >> >>I don't understand your point here? You want list() to create a new list >>and [] to return the same (initially empty) list throughout the run of the >>program? > > > No, but I think that each occurence returning the same (initially empty) > list throughout the run of the program would be consistent with how > default arguments are treated. What about that : def f(a): res = [a] return res How can you return the same list that way ? Do you propose to make such construct illegal ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
[EMAIL PROTECTED] wrote:
> viewcharts wrote:
>
>>I am reading two text files comparing the values in one to the other,
>>this requires two loops. The problem is that when the inner loop is
>>finished, it never goes back into the loop. Any suggestions?
>>
>>
>>for refSymbol in symbols.readlines():
>>for lookupSymbol in myfile.readlines():
>>showme = lookupSymbol.split('\t')
>>if showme[3] == refSymbol.strip():
>>priceNew.write(refSymbol.strip()+" "+showme[10])
>
> As another poster said, you have "used up" the inner iterable in the
> first round, it is an iterable, just not like a list where you can use
> multiple times.
>
The result of the readlines() function *is* a list, which is precisely
why it's been used up:
>>> f = file("mail.py")
>>> type(f.readlines())
>>>
A second call to readlines just gets an empty list, since there are no
more lines left to be read.
> Either turn it into a list(so you can reuse it) or better yet, turn it
> into a dict which would speed up the matching process. Either way, it
> better be done outside of the outer loop.
>
The solution, as already proposed, is to bind the list of lines to a
nanme so it can be reused.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: improving pypi / setuptools
Alia Khouri wrote: > What ideas do people out there have for making the installation of > python module more reliable? judging from the support load it's causing me these days, setuptools is a piece of utter crap. if you want to make things reliable, don't use it. (if the various "rails" cloners want people to use their stuff, it would be a lot better is they shipped complete and well-tested source code kits, and left the packaging to the huge crowd of nice, friendly, and competent downstream packagers that exist for all major platforms these days. the downstream folks know what they're doing, and the tools they're using happens to work. both for the maintainers and for the users.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 14, Issue 147
On Wed, 10 Nov 2004 19:55:54 +0100 (CET) [EMAIL PROTECTED] wrote: > Send Python-list mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > [EMAIL PROTECTED] > > You can reach the person managing the list at > [EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
David Rasmussen wrote: > Harald Armin Massa wrote: > >> Dr. Armin Rigo has some mathematical proof, that High Level Languages >> like esp. Python are able to be faster than low level code like >> Fortran, C or assembly. > > Faster than assembly? LOL... :) I think the claim goes something along the lines of "assembly is so hard to get right that if you can automatically generate it from a HLL, not only will it be more likely to be correct, it will be more likely to be fast because the code generator can provide the appropriate optimizations". OTOH, you can almost certainly take automatically generated assembly code and make optimizations the code generator wasn't able to, thanks to knowing more about the real semantics of the program. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Help!!! On Tkinter Menu problem!!!
Xuening wrote:
> I have a problem about menu by using Tkinter. I want to make a dynamic
> menu. That is when I create a new view/window, one menuitem will be
> added to the menu. and when I kill a window, the correponding menuitem
> will be deleted. I write a simple code and I can add menuitem now. But
> I don't know how to remove the item when I close the window.
>
> The following is my code:
>
>
> ==
> from Tkinter import*
>
> class App:
> def __init__(self):
> root=Tk()
> self.root=root
> self.doMenus()
> root.config(menu=self.mBar)
> delete=deletewindow()
> self.root.mainloop()
>
> def doMenus(self):
> mBar=Menu(self.root)
> self.mBar=mBar
> self.doFileMenu()
> self.doWindowMenu()
>
> def doFileMenu(self):
> filemenu = Menu(self.mBar,tearoff=0,background='yellow')
> filemenu.add_command(label='New
> window',underline=0,command=self.newWindow)
> filemenu.add('separator')
>
> filemenu.add_command(label='Quit',underline=0,command=self.root.destroy)
> self.filemenu=filemenu
> self.mBar.add_cascade(label="File", menu=self.filemenu)
>
> def doWindowMenu(self):
> WinName = Menu(self.mBar,
> tearoff=0,postcommand=self.windowListUpdate)
> self.windowMenu=WinName
> self.mBar.add_cascade(label="Window", menu=self.windowMenu)
> self.windowList=[]
> self.nWindows=0
>
> def windowListUpdate(self):
> self.windowMenu.delete(0, END)
> for window in self.windowList:
> self.windowMenu.add_command(label=window)
>
>
> def newWindow(self):
> self.nWindows+=1
> windowName = "Window %d"% self.nWindows
> self.windowList.append(windowName)
> self.windowListUpdate()
>
> root2=Tk()
> self.root2=root2
> self.root2.title(windowName)
> canvas=Canvas(self.root2, width=450,height=300,bg='green')
> canvas.pack()
> self.canvas=canvas
>
> if __name__ == '__main__':
> test=App()
>
>
> Maybe I should bind something to event. Everytime I close the
> window, the name of the window should be removed from the windowList
> and refresh the all the menuitems again. But I don't know how and
> where to add the "destroy" event. Can anyone give me a hand
>
> Thanks a lot!!
>
The Menu Tk Widget has a delete or deletecommand method(s) the first
accepts an index the second a Menu label, both will remove the menu entry
for more on this...
http://effbot.org/tkinterbook/menu.htm
Regards
Martin
--
http://mail.python.org/mailman/listinfo/python-list
Re: XML and namespaces
Wilfredo Sánchez Vega:
"""
I'm having some issues around namespace handling with XML:
>>> document = xml.dom.minidom.Document()
>>> element = document.createElementNS("DAV:", "href")
>>> document.appendChild(element)
>>> document.toxml()
'\n'
"""
I haven't worked with minidom in just about forever, but from what I
can tell this is a serious bug (or at least an appalling mising
feature). I can't find anything in the Element,writexml() method that
deals with namespaces. But I'm just baffled. Is there really any way
such a bug could have gone so long unnoticed in Python and PyXML? I
searched both trackers, and the closest thing I could find was this
from 2002:
http://sourceforge.net/tracker/index.php?func=detail&aid=637355&group_id=6473&atid=106473
Different symptom, but also looks like a case of namespace ignorant
code.
Can anyone who's worked on minidom more recently let me know if I'm
just blind to something?
--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
malv: >Hi bearophileH, bearophile is enough :-) >Could you post some more information about ShedSkink? ShedSkin (SS) is a Python -> C++ compiler (or translator) written in Python, created by Mark Dufour. Its development was initially "financed" by the summer of code by Google. It contains some smart algorithms that allow it to infer the type of most variables, and to compile everything statically (but with a garbage collector). This produces a very fast executable, usually like a C++ one. SS has some limits, some of them are temporary, and some of them are here to stay (it cannot be used on really dynamic stuff). It's not intended to compile every Python program, but mostly for "algorithmic" code that has to go fast, often the same code Psyco is used for. It can be seen as complementary to Psyco, and not really like something to substitute it, Psyco is a very good software. I am helping Mark as I can, in different ways, because I think SS is a very interesting software. At the moment SS is in the Alpha stage still, this means: - It has a lot of bugs still, but Mark fixes some of them almost every week. That problem in that fannkuch code is relative to the version 0.0.5, a successive version may compile it correctly. - Some common things aren't possible yet, like inheritance, but Mark is probably going to implement this in the following days. - The code produced is C++, and it calls functions of the SS library. CPython source code contains some very fast routines (by Raymond Hettinger and other people), so sometimes CPython is faster (example: sometimes Python dicts are faster). This is mostly a "tuning/implementation" problem, it's not a limit of SS or the C++ and its compiler. It's a matter of knowing lot of complex C++ "tricks" and implementing/copying faster routines. Another developer can probably help Mark improve most of those algorithms (I think that sometimes the CPython source code itself may be adapted and used). - If another developer helps Mark, a future version of SS can probably be used to automatically produce compiled modules that can be imported into normal Python programs (it may call something like SIP/SWIG by itself), a very simple single-click command can be used (on Windows in a contex menu). The info about the input types of the functions/methods may be expressed with some very simple syntax inside the module docstring, or simply it may be contained in the part of the module that isn't executed when then module is called. - There are lot of ways to improve SS still, some people in the Blender group have already shown interest in SS, but it contains too much bugs still to be used in serious projects. Helping hands can speed up its development a lot. The project on Sourceforge, it contains more information and documentation: http://sourceforge.net/projects/shedskin/ SS blog: http://shed-skin.blogspot.com/ The last version is 0.0.5.1, it contains an important memory bugfix and other minor bugfixings. Some timings for version 0.0.5: http://sourceforge.net/mailarchive/forum.php?thread_id=9040577&forum_id=46397 (small_dict_fp test is probably faster in version 0.0.5.1). Bear hugs, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI question
Dan Stromberg wrote:
> >> What's the best way of converting this:
> >>
> >> 'hide\\?http://www.dedasys.com/articles/programming_language_economics.html\x012005-07-20
> >> 14:48'
> >>
> >> ...to something easily usable in a python CGI script?
> >
> > easily usable for what purpose?
> >
> > if you want to extract the URL that seems to be hidden in that string,
> > something like:
> >
> > url, junk = text.split("\x01", 1)
> > junk, url = url.split("\\?", 1)
> >
> > should work.
> >
> >
>
> This is great, but is there no standard python module for taking
> apart command line arguments to a CGI script? I'm not eager to reinvent
> the wheel, at least not on this project :)
command-line arguments to CGI scripts?
I'm probably dense, but doesn't CGI scripts usually get their arguments via
environment variables and stdin ? and chr(1) and "hide\?" sure don't look
like standard URL separators to me...
if you want standard CGI argument handling, the "cgi" module contains all
the tools you need.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which License Should I Use?
Paul Rubin wrote: > That is the guy who claims it is impossible to release anything into > the public domain, other than by dying and then waiting 70 years. Is that an indirect reference to the following article? http://www.linuxjournal.com/article/6225 Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: python number handling - tiny encryption algorithm
Kinsley Turner wrote: > I'm getting a bit out of my depth porting the 'tiny encryption algorithm' > from C to python > In my version, I end up with hugely long integers, which have obviously > not be constrained into the 4-byte unsigned longs that TEA is expecting. > ... > def teaDecipher(input,key): > y = input[0] > z = input[1] > n = 32 > sum = 0xC6EF3720 > delta=0x9E3779B9 > while (n > 0): > n -= 1 > z -= (y << 4 ^ y >> 5) + y ^ sum + key[sum>>11 & 3]; > sum -= delta; > y -= (z << 4 ^ z >> 5) + z ^ sum + key[sum&3]; > return y,z > > That seems to return hugely-long integers (around 30? digits), whereas > I'd expect them to max-out at 2^32. If you really want 32-bit arithmetic, you need to specify it. Do you have to rewrite the C for 64-bit machines? For example: MASK = (1 << 32) - 1 def teaDecipher(input, key): y = input[0] z = input[1] sum = 0xC6EF3720 delta = 0x9E3779B9 for n in range(32): z = MASK & (z - (y << 4 ^ y >> 5) - y ^ sum - key[sum>>11 & 3]) sum = MASK & (sum - delta) y = MASK & (y - (z << 4 ^ z >> 5) - z ^ sum - key[sum&3]) return y, z --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Distutils postinstall script: useless?
Hi, the bdist_wininst command of distutils allows me to specify a script to be executed at the end of the installation. That's great, but how can I know the installation path from inside the script? I've already tried os.getcwd(), but it just return the directory where the setup was started. -- Saluti, Mardy http://interlingua.altervista.org -- http://mail.python.org/mailman/listinfo/python-list
Re: XML and namespaces
I've found the same bug. This is what I've been doing:
from xml.dom.minidom import Document
try:
from xml.dom.ext import PrettyPrint
except ImportError:
PrettyPrint = None
doc = Document()
...
if PrettyPrint is not None:
PrettyPrint(doc, stream=output, indent='')
else:
top_parent.setAttribute("xmlns", xmlns)
output.write(doc.toprettyxml(indent=''))
--
http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
[EMAIL PROTECTED] wrote: > This is a direct translation of the D code, maybe it's not the faster > Python implementation, and surely it's not the shorter one. But Psyco > makes it much faster (Psyco likes "low level" style code). And if you contributed the program like this http://shootout.alioth.debian.org/gp4/faq.php#contribute we could run the program with Psyco http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=psyco&lang2=python best wishes, Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
Bengt Richter wrote: > That's not just blunt and concise, it looks like the modus operandi > of a typical volunteer/employee-exploiter (or perhaps spoiled brat, > the typical precursor to the former). careful. his faq requires you to "be nice". -- http://mail.python.org/mailman/listinfo/python-list
Re: python number handling - tiny encryption algorithm
One systematic, if maybe clumsy way, is to mimic the C arithmetic
operations more closely in Python. If you do, for example, a left shift
in C, the result is always returned in a certain precision, 64 bits in
the example below. In python, no bits are lost, so you have to force the
result into the 64 bits back to obtain the same result.
Instead of (y << 4) you can write something like (untested!) (y << 4) &
0xFF...FF.
Once you understand what the algorithm is doing, you may want to go back
and express the algorithm in a more pythonic way (not by programming C
in Python).
Kinsley Turner wrote:
>
> Hey-ho,
>
> I'm getting a bit out of my depth porting the 'tiny encryption algorithm'
> from C to python.
>
> Ref:
> http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm
> http://www.simonshepherd.supanet.com/source.htm#new_ansi
>
> Specifically I don;t know how to handle a C-long block and perform the
> mathmatical manipulations in python syntax. I played with pack and unpack
> (from struct module) but that didn't seem to buy me anything.
>
> In my version, I end up with hugely long integers, which have obviously
> not be constrained into the 4-byte unsigned longs that TEA is expecting.
>
> This is the C function:
>
> /* v is 64-bits input, w is 64-bits output, k is the 128-bit key */
> void decipher(const unsigned long *const v,unsigned long *const w, const
> unsigned long * const k)
> {
>register unsigned long
> y=v[0],z=v[1],sum=0xC6EF3720,delta=0x9E3779B9,n=32;
>
>while(n-->0)
> {
> z -= (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
> sum -= delta;
> y -= (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
> }
>w[0]=y; w[1]=z;
> }
>
>
> Which gives me a (broken) python version:
>
> def teaDecipher(input,key):
> y = input[0]
> z = input[1]
> n = 32
> sum = 0xC6EF3720
> delta=0x9E3779B9
>
> while (n > 0):
> n -= 1
> z -= (y << 4 ^ y >> 5) + y ^ sum + key[sum>>11 & 3];
> sum -= delta;
> y -= (z << 4 ^ z >> 5) + z ^ sum + key[sum&3];
> return y,z
>
> That seems to return hugely-long integers (around 30? digits), whereas I'd
> expect
> them to max-out at 2^32.
>
> Perhaps I'm not packing the input or the key properly. My inputs are
> just strings which I put into an integer with the ordinal value of each
> character
> shifted into the correct position to make the C-long.
>
> Something like:
> input[0] = ord(encrypted[i])<<24 + ord(encrypted[i+1])<<16 +
> ord(encrypted[i+2])<<8 + ord(encrypted[i+3])
> input[1] = ord(encrypted[i+4])<<24 + ord(encrypted[i+5])<<16 +
> ord(encrypted[i+6])<<8 + ord(encrypted[i+7])
>
> The key is created as an array of numbers, each the ord() of the key
> character...
>
>
> Anyway, that's about it.
> Any help much appreciated.
>
>
> thanks,
> -kt
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> (non-removable disclaimer below... *sigh*)
> --
>
> Please consider our environment before printing this email.
>
> WARNING - This email and any attachments may be confidential. If received in
> error, please delete and inform us by return email. Because emails and
> attachments may be interfered with, may contain computer viruses or other
> defects and may not be successfully replicated on other systems, you must be
> cautious. Westpac cannot guarantee that what you receive is what we sent. If
> you have any doubts about the authenticity of an email by Westpac, please
> contact us immediately.
>
> It is also important to check for viruses and defects before opening or using
> attachments. Westpac's liability is limited to resupplying any affected
> attachments.
>
>
> This email and its attachments are not intended to constitute any form of
> financial advice or recommendation of, or an offer to buy or offer to sell,
> any security or other financial product. We recommend that you seek your own
> independent legal or financial advice before proceeding with any investment
> decision.
>
> Westpac Institutional Bank is a division of Westpac Banking Corporation, a
> company registered in New South Wales in Australia under the Corporations Act
> 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the
> Financial Services Authority and is registered at Cardiff in the United
> Kingdom as Branch No. BR 106. Westpac operates in the United States of
> America as a federally chartered branch, regulated by the Office of the
> Comptroller of the Currency.
>
> Westpac Banking Corporation ABN 33 007 457 141.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python as Guido Intended
On 30 Nov 2005 10:57:04 GMT in comp.lang.python, Antoon Pardon <[EMAIL PROTECTED]> wrote: >On 2005-11-29, Mike Meyer <[EMAIL PROTECTED]> wrote: >> Antoon Pardon <[EMAIL PROTECTED]> writes: You see, you can make languages more powerful by *removing* things from it. >>> You cast this in way to general terms. The logic conclusion >>> from this statements is that the most powerfull language >>> is the empty language. >> >> The only way you reach that conclusion is if you read the statement as >> saying that removing things *always* makes a langauge more >> powerful. That's not what I said, > >I would say it is the common interpretation for such a sentence. I hope no one ever tells you that you'd be healthier if you ate less and exercised more. (Perhaps it's not true in your case, but it certainly is in mine.) Regards, -=Dave -- Change is inevitable, progress is not. -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
>> viewcharts wrote:
>>
>>> I am reading two text files comparing the values in one to the other,
>>> this requires two loops. The problem is that when the inner loop is
>>> finished, it never goes back into the loop. Any suggestions?
>>>
>>> for refSymbol in symbols.readlines():
>>>for lookupSymbol in myfile.readlines():
>>>showme = lookupSymbol.split('\t')
>>>if showme[3] == refSymbol.strip():
>>>priceNew.write(refSymbol.strip()+" "+showme[10])
>>
>> As another poster said, you have "used up" the inner iterable in the
>> first round, it is an iterable, just not like a list where you can use
>> multiple times.
...
> The solution, as already proposed, is to bind the list of lines to a
> nanme so it can be reused.
>
> regards
> Steve
Or you could read each on the fly, and rewind the inner:
for refSymbol in symbols:
for lookupSymbol in myfile:
showme = lookupSymbol.split('\t')
if showme[3] == refSymbol.strip():
priceNew.write(refSymbol.strip() + " " + showme[10])
myfile.seek(0)
This is probably more what you wanted, but Steve's suggestion will run
much faster.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
pyparsing and LaTeX?
Anyone parsing simple LaTeX constructs with pyparsing? I'm playing around with it (and looking at John Hunter's matplotlib stuff), but I thought I'd ask here if anyone had other TeX/LaTeX examples. thanks, --Tim Arnold -- http://mail.python.org/mailman/listinfo/python-list
Re: Debugging of Python code in embedded interpreter
Thomas Korimort wrote: > Hi! > > I have embedded a Python interpreter into a C++ framework. When running > some Python code in the interpreter, how can i get a traceback with line > number file..., when an exception occurs? > > Greetings, Thomas Korimort. Google for "python traceback", there seems to be interesting output. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Steven Bethard wrote: > David Rasmussen wrote: > > Faster than assembly? LOL... :) Faster than physics? ;-) > I think the claim goes something along the lines of "assembly is so hard > to get right that if you can automatically generate it from a HLL, not > only will it be more likely to be correct, it will be more likely to be > fast because the code generator can provide the appropriate optimizations". I think this is just a restatement of existing motivations for using high-level languages and compilers. My impression is that PyPy takes inspiration from work which showed that run-time knowledge can sometimes produce code that is better optimised than that produced by a compiler. That said, when everyone starts showing off their favourite benchmarks, it might be more interesting not to parade some festival of arithmetic yet again. Where more recent versions of the Java virtual machines have improved is in their handling of object memory allocation, amongst other things, and merely scoffing that Java is slow (by pulling specific/specialised extension packages out of the hat) fails to acknowledge the potential for similar improvements (and others) in Python, especially where programs involving plain objects - as opposed to numbers, and where no conveniently available and wrapped C/C++ package exists for the task - are concerned. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Harald Armin Massa wrote: > Dr. Armin Rigo has some mathematical proof, that High Level Languages > like esp. Python are able to be faster than low level code like > Fortran, C or assembly. > > I am not wise enough to understand that proof. > > Maybe I understood those papers totally wrong and he was saying > something totally different. Here is a paper of Armin explaining his psycology: http://psyco.sourceforge.net/theory_psyco.pdf Heck, Python has at least one programmer who is computer scientist and knows how to draw commutative diagrams :) -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Steven Bethard wrote: > David Rasmussen wrote: > >>Harald Armin Massa wrote: >> >> >>>Dr. Armin Rigo has some mathematical proof, that High Level Languages >>>like esp. Python are able to be faster than low level code like >>>Fortran, C or assembly. >> >>Faster than assembly? LOL... :) > > > I think the claim goes something along the lines of "assembly is so hard > to get right that if you can automatically generate it from a HLL, not > only will it be more likely to be correct, it will be more likely to be > fast because the code generator can provide the appropriate optimizations". > > OTOH, you can almost certainly take automatically generated assembly > code and make optimizations the code generator wasn't able to, thanks to > knowing more about the real semantics of the program. Yeah, but the other important part of the claim has to do with just that: the real [runtime] semantics of the program. Hand optimization happens before runtime, obviously, whereas the HLL->assembly conversion can happen once the program is running and more info is known about the actual sets of data being operated on, the frequence of function calls, i.e. where the need for optimization actually exists. The optimization could even happen multiple times to adapt over time, or to allow multiple optimizations for different classes of data so that the code that actually executes is highly specialized. So, yeah, knowledge of the runtime behavior can allow a hand-optimized version to run faster than a static, automatically-generated version, but knowledge of the runtime behavior could also allow a dynamic code generator to even beat the hand-optimized version. -Dave -- http://mail.python.org/mailman/listinfo/python-list
UnicodeDecodeError
hi, one of the modules in my programs stopped wroking after i upgraded from python 2.3 to 2.4. I also changed my wxPython to unicode supported one during the process. what the module essentially does is search for a stirng pattern form a list of strings. this is the function: def srchqu(self): for i in range(1,len(qu)):#qu is the list of strings if qu[i][0].lower().find(self.query)==-1: pass else: #do some stuff here I get this error message on calling the function: Traceback (most recent call last): File "E:\mdi\search.py", line 86, in OnSrchButton self.srchqu() File "E:\mdi\search.py", line 97, in srchqu if qu[i][0].lower().find(self.query)==-1: UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 66: ordinal not in range(128) what is the problem and the solution? thanks in advance for any help. Ashoka -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
On Nov 29, viewcharts wrote: > I am reading two text files comparing the values in one to the other, > this requires two loops. Or you could have a look at difflib. http://docs.python.org/lib/differ-examples.html -- _ _ ___ |V|icah |- lliott <>< [EMAIL PROTECTED] " " """ -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
>Faster than assembly? LOL... :) why not? Of course, a simple script like "copy 200 bytes from left to right" can be handoptimized in assembler and run at optimum speed. Maybe there is even a special processor command to do that. I learned that there was one generation of CPUs which had effectively a command to copy X bytes from left to right; but a specific version of that CPU did this command slower then a loop in certain situations. Some newer generations of that CPU and even some competitors CPU had that command implented correctly, and it was indeed faster than the loop. Now: is it rather likely that for a single programm a programmer is able to get it right for all CPUs? It even gets more complicated. The human mind is able to consider a certain amount of things at once, sth. like on-chip-cache or short-term-memory. Now with an ever growing complexity of processors, with cache lines, partyparallelexecution, branchprediction, out of order execution, multilevelcaching, hypermetathreading ... it may be that the usual availaible human brain is no longer capable of really knowing what happens. My guess is that the average code speed of a Rigopy could indeed be higher than the average code speed of the average assembler programmer. Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: import Excel csv - files
On Nov 30, Jürgen Kemeter wrote: >My actual Problem: >The Excel workbook contains several spreadsheets. These are >linked through Hyperlinks, and contain several cell comments. How >can I export these comments and Hyperlinks using Python? Are you just wanting read a .xls file with Python? pyExcelerator http://sourceforge.net/projects/pyexcelerator> can do that job. Documentation is non-existent AFAICT, but the tools directory has good examples. I don't know how comments/hyperlinks are treated but you can try and find out. -- _ _ ___ |V|icah |- lliott <>< [EMAIL PROTECTED] " " """ -- http://mail.python.org/mailman/listinfo/python-list
Re: import Excel csv - files
You should actually explain what you mean by "export". Excel has a Save As HTML that would save everything out to HTML or you can do Save As .CSV. Hard to tell what you want. I suspect that to get to the cell comments you will need to go through COM interface to Excel. -Larry Bates Micah Elliott wrote: > On Nov 30, Jürgen Kemeter wrote: > >> My actual Problem: >> The Excel workbook contains several spreadsheets. These are >> linked through Hyperlinks, and contain several cell comments. How >> can I export these comments and Hyperlinks using Python? > > > Are you just wanting read a .xls file with Python? pyExcelerator > http://sourceforge.net/projects/pyexcelerator> can > do that job. Documentation is non-existent AFAICT, but the tools > directory has good examples. > > I don't know how comments/hyperlinks are treated but you can try and > find out. > -- http://mail.python.org/mailman/listinfo/python-list
Automate decryption using GnuPGInterface
Hi,
Does anyone have any experience with GnuPGInterface? I'm having a
problem with decrypting files through a cron job. The below job works
great when I run it manually from the command line, but it blows up
whenever I try to run it through cron, and I can't really figure out
why. I've been trying to learn python, and I'm at the point where I can
get things working in small scripts (you know, just enough to be
dangerous). If anybody could shed some light as to what I might be
doing wrong, I would really appreciate it. TIA...
#!/usr/local/bin/python
import os, glob, time, GnuPGInterface
gnupg = GnuPGInterface.GnuPG()
gnupg.options.extra_args.append('--no-secmem-warning')
gnupg.passphrase = ##
# get list of files in /home/ns1
# that match regex pattern
for pgpname in glob.glob("/home/ns1/[ABDP]*.pgp"):
txtname = pgpname.replace('.pgp','.txt')
inputfile = file(pgpname,'r')
outputfile = file(txtname,'w')
process = gnupg.run(['--decrypt'],
attach_fhs={'stdin':inputfile,'stdout':outputfile})
process.wait() # cleanup
inputfile.close()
outputfile.close()
os.remove(pgpname)
--
http://mail.python.org/mailman/listinfo/python-list
Re: XML processing
I haven't used PyXML extensively, but I have used parts of the Amara XML Toolkit (http://uche.ogbuji.net/uche.ogbuji.net/tech/4suite/amara/) and recommend it for elegance. I can't say, however, which tool is faster. There are many other XML modules that people have written for Python. Do your research and pick the best one for you. On a side note, XML has historically been a poor solution for most of the cases I've seen it used. You should seriously rethink whether you "need to do some XML programming" and consider simpler options. In most simple cases, a primitive text parser with a delimited format is your best bet. You would know best, but this is my 2 cents. -- http://mail.python.org/mailman/listinfo/python-list
Re: Automate decryption using GnuPGInterface
Are you able to run a dummy Python script using crontabs? For troubleshooting purposes, I would verify this before trying to debug my code. Check your permissions, paths, etc. Can you post your entry into cron? What exactly happens when it "blows up"? -- http://mail.python.org/mailman/listinfo/python-list
min pathon code
Hi! All I would like to call some python module or function from C code. Except installing whole python23 window version, what is the min module I need to keep or install. Is there any tool that I can use to strip extral modules that are not necessary in my program.? Anyone kenw? Thanks Yong Yahoo! Personals Single? There's someone we'd like you to meet. Lots of someones, actually. Try Yahoo! Personals-- http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
Fredrik Lundh wrote: > Bengt Richter wrote: > > > That's not just blunt and concise, it looks like the modus operandi > > of a typical volunteer/employee-exploiter (or perhaps spoiled brat, > > the typical precursor to the former). > > careful. his faq requires you to "be nice". > > "Be Nice!" *is* one of paragraph headings in the FAQ section "How can I help?" imo Saying that the FAQ "requires you to "be nice" is a misrepresentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: How could I ask Thread B to call B().Method() from inside Thread A's run?
I agree with jmj's solution, you would want to send a signal of some sort to Thread B from A when some event occurs in A. A queue is one way to do it, but keep in mind that there are numerous ways to communicate between threads/processes (queue, pipe, exit status, TCP/UDP message, etc.). I believe one of the first couple chapters in O'Reilly's "Programming Python" book discusses most of these methods. Choose the simplest one that meets your needs. -- http://mail.python.org/mailman/listinfo/python-list
Re: import Excel csv - files
Hi, Larry Bates <[EMAIL PROTECTED]> wrote: > You should actually explain what you mean by "export". > Excel has a Save As HTML that would save everything out to HTML > or you can do Save As .CSV. Hard to tell what you want. > I suspect that to get to the cell comments you will need to > go through COM interface to Excel. You can also script OpenOffice from python to suck in an excel file and spit out a CSV or HTML or whatever else you want. After that you can parse the resulting files. Ognen -- http://mail.python.org/mailman/listinfo/python-list
Re: an intriguing wifi http server mystery...please help
Hi again, Please excuse any ignorance here. I would love to show you what you are asking for, but I am not sure what you are asking for (newbie here). All these connections (i.e. client-server connections) are within my local area network. I have a simple linksys 802.11b router. My server is set to say, "192.168.1.100", port , and my client is set to say, "192.168.1.101" I load up the server, then go to the client computer webbrowser and enter "http://192.168.1.100:"; You guys probably already know this, so let me know if i need to be more specific. Thanks again for the rapid response! jojoba -- http://mail.python.org/mailman/listinfo/python-list
Quene
I am trying to write a function that holds a variable-length quene. The quene has 2 bits of information. At some point, I would like to remove bits of this quene, when they are completed. Is there a way to do this with something as follows? quene=[] quene.append((4,2)) quene.append((3,6)) if(4 in quene):#Shows false, what's the correct syntax to show true? remove 4 from quene #(Not python code, not sure how to do this...) So, how can I make this work? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
mmm-mode, python-mode and doctest-mode?
Is it possible to get doctest-mode to work with mmm-mode and python-mode nicely so that docstrings containing doctests are editable in doctest-mode? In my utter e-lisp ignorance, I tried this: (require 'mmm-auto) (setq mmm-global-mode 'maybe) (mmm-add-classes '( (doctest :submode doctest-mode :front "\"\"\"" :back "\"\"\""))) (mmm-add-mode-ext-class nil "\\.py$" 'doctest) That has the following problems: - Fails to set the background colour of the doctest-mode regions to the default mmm-mode gray (as documented by mmm-mode - and observed for another mmm class I have). Maybe an interaction with python-mode? - Confuses python-mode: the face of docstrings sometimes fluctuates from second to second between the string face and the face of ordinary text (I assume the former face is python-mode's string face and the latter face is the doctest-mode English-text face)! Any tips appreciated! John -- http://mail.python.org/mailman/listinfo/python-list
Re: an intriguing wifi http server mystery...please help
[EMAIL PROTECTED] wrote: > Please excuse any ignorance here. > I would love to show you what you are asking for, but I am not sure > what you are asking for (newbie here). > > All these connections (i.e. client-server connections) are within my > local area network. > > I have a simple linksys 802.11b router. > My server is set to say, "192.168.1.100", port , > and my client is set to say, "192.168.1.101" > > I load up the server, then go to the client computer webbrowser and > enter "http://192.168.1.100:"; If you are on Windows, please open a command window (Start|Run and then type 'cmd') and type: route print On Linux or Mac, the command would simply be: route Do this on both computers, and post the output here. If you are using ip addresses only in your URL's the problem isn't with DNS or name lookup so let's eliminate a routing problem next. -- Paul McNett http://paulmcnett.com http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython installation issues on Debian
Hi Robert, Thanks for the suggestion, but an apt-cache search python2.4-wxgtk2.4 returns no results for a package with that name. Aaron -- http://mail.python.org/mailman/listinfo/python-list
Re: Quene
On 30 Nov 2005 09:38:44 -0800 in comp.lang.python, "Tuvas" <[EMAIL PROTECTED]> wrote: >I am trying to write a function that holds a variable-length quene. The >quene has 2 bits of information. At some point, I would like to remove >bits of this quene, when they are completed. Is there a way to do this >with something as follows? > the following might work... >quene=[] >quene.append((4,2)) >quene.append((3,6)) >if(4 in quene):#Shows false, what's the correct syntax to >show true? found = [t for t in queue if t[0] == 4] if found: >remove 4 from quene #(Not python code, not sure how to do this...) queue.remove(found[0]) HTH, -=Dave -- Change is inevitable, progress is not. -- http://mail.python.org/mailman/listinfo/python-list
Re: improving pypi / setuptools
On Wed, Nov 30, 2005 at 11:49:14AM +0100, Fredrik Lundh wrote: > Alia Khouri wrote: > > > What ideas do people out there have for making the installation of > > python module more reliable? > > judging from the support load it's causing me these days, setuptools is a > piece of utter crap. if you want to make things reliable, don't use it. setuptools is still alpha. Give it another 6months to a year and you will wonder how we ever got along without it. > > (if the various "rails" cloners want people to use their stuff, it would be a > lot better is they shipped complete and well-tested source code kits, and > left the packaging to the huge crowd of nice, friendly, and competent > downstream packagers that exist for all major platforms these days. the Which downstream packager exists for Windows, or is Windows not a major platform anymore? Besides many useful modules are not important enough to be picked up by packagers for some distributions. For instance, Gentoo does not have RuleDispatch. > downstream folks know what they're doing, and the tools they're using > happens to work. both for the maintainers and for the users.) > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: an intriguing wifi http server mystery...please help
Hello again! Heres the CLIENT info you requested: === Interface List 0x1 ... MS TCP Loopback interface 0x20002 ...00 09 5b 41 0c b7 .. NETGEAR MA311 PCI Adapter - Packet Scheduler Miniport === === Active Routes: Network DestinationNetmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.107 30 127.0.0.0255.0.0.0127.0.0.1 127.0.0.1 1 192.168.0.0255.255.255.0192.168.0.107 192.168.0.107 30 192.168.0.107 255.255.255.255127.0.0.1 127.0.0.1 30 192.168.0.255 255.255.255.255192.168.0.107 192.168.0.107 30 224.0.0.0240.0.0.0192.168.0.107 192.168.0.107 30 255.255.255.255 255.255.255.255192.168.0.107 192.168.0.107 1 Default Gateway: 192.168.0.1 === Persistent Routes: None Here's the SERVER info you requested: === Interface List 0x1 ... MS TCP Loopback interface 0x40003 ...00 d0 59 49 2e 2c .. LAN-Express IEEE 802.11 PCI Adapter === === Active Routes: Network DestinationNetmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.105 30 127.0.0.0255.0.0.0127.0.0.1 127.0.0.1 1 192.168.0.0255.255.255.0192.168.0.105 192.168.0.105 30 192.168.0.105 255.255.255.255127.0.0.1 127.0.0.1 30 192.168.0.255 255.255.255.255192.168.0.105 192.168.0.105 30 224.0.0.0240.0.0.0192.168.0.105 192.168.0.105 30 255.255.255.255 255.255.255.255192.168.0.105 192.168.0.105 1 Default Gateway: 192.168.0.1 === Persistent Routes: None (hope the text-formatting doesn't make it too unreadable!) Note: this is for the condition that is SLOW. Hope this helps Thanks again, jojoba -- http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> On 30 Nov 2005 00:58:45 -0800, [EMAIL PROTECTED]
> declaimed the following in comp.lang.python:
>
>> yes I have imported math in the file I want to use it. But the
>> imported module "math" is not visible in function without a
>> global instruction.
>>
> The code you just posted shows it, yes... My reading of an
> earlier
> message seemed to imply you had a nested import chain with the
> "import math" at the wrong level... Something like:
>
> #file 1
> execfile("file 2")
>
> #file 2
> import math
> import file_3
>
> #file_3
> print math.pi
>
>> But the solutions already proposed seems to work file for my
>> sample program. I will try on my project soon :)
>
> Looking at the documentation for "execfile", I can see
> /how/ the
> problem occurs -- but can't determine if this can be considered
> "expected".
>
> -=-=-=-=-=-=-
> execfile( filename[, globals[, locals]])
>
> This function is similar to the exec statement, but parses a
> file instead of a string. It is different from the import
> statement in that it does not use the module administration --
> it reads the file unconditionally and does not create a new
> module.2.2 -=-=-=-=-=-=-
>
> I'm guessing that the intent was only that "file 1" not
> become an
> entry on the module list, but it seems to be applying "...not
> create a new module" recursively to the imported "math"... Maybe
> an expert with the Python byte-code can verify. My hypothesis is
> something on the order of:
> Outer (file level) references to math (math.pi) are being
> handled
> during the byte-code compilation phase of execfile, so even if
> "math" isn't in the module list, it is still in local scope for
> the outer math.pi...
>
> Inner (function) references to math become dynamic look-ups
> evaluated at function execution; at that point math is not in
> scope and is not in the module list.
>
> Interestingly, I note that is the file calling execfile has
> imported
> math (so math is in the module list), the called file works...
>
> #no import in run
> E:\UserData\Dennis Lee Bieber\My Documents\Python Progs>python
> run.py in module:
> Traceback (most recent call last):
> File "run.py", line 5, in ?
> run_ut("ut_00.py")
> File "run.py", line 3, in run_ut
> execfile(test)
> File "ut_00.py", line 8, in ?
> f()
> File "ut_00.py", line 5, in f
> print "in function: \t %s" % math
> NameError: global name 'math' is not defined
>
> #import is in run
> E:\UserData\Dennis Lee Bieber\My Documents\Python Progs>python
> run.py
>
> in module:
> in function:
>
This may be saying what you said, but it seems to depend on where
the import occurs:
# File: runt2.py
def Bobo():
import math
execfile( "ut_00.py" )
b = Bobo()
>runt2
First access :
3.14159265359
Second access :
Traceback (most recent call last):
File "D:\pyWork\test\runt2.py", line 5, in ?
b = Bobo()
File "D:\pyWork\test\runt2.py", line 3, in Bobo
execfile( "ut_00.py" )
File "ut_00.py", line 10, in ?
f()
File "ut_00.py", line 6, in f
print "\t",math.pi # ERROR
NameError: global name 'math' is not defined
# File: runt.py
import math
def Bobo():
execfile( "ut_00.py" )
b = Bobo()
>runt
First access :
3.14159265359
Second access :
3.14159265359
So the import at the module level of the caller works, but an
import at the function level of the caller doesn't. I don't see why
the namespace would be significantly different by the time execfile
is executed, though it apparently is.
--
rzed
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
Micah Elliott wrote: > On Nov 29, viewcharts wrote: > >>I am reading two text files comparing the values in one to the other, >>this requires two loops. > > > Or you could have a look at difflib. > > http://docs.python.org/lib/differ-examples.html > Indeed, but I personally don't see a way to persuade difflib to compare the lines of one file with the fourth field of lines in another. Do you know something I don't? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
David Rasmussen wrote: > Harald Armin Massa wrote: > >>Dr. Armin Rigo has some mathematical proof, that High Level Languages >>like esp. Python are able to be faster than low level code like >>Fortran, C or assembly. >> > > > Faster than assembly? LOL... :) > I don't see why this is so funny. A good C compiler with optimization typically produces better code than an equivalent assembly language program. As compilation techniques improve this gap is likely to widen. There's less and less reason to use assembler language with each passing year. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Automate decryption using GnuPGInterface
I have 5 python scripts I've added to cron over the past year that run
correctly all the time. I double-checked the permissions and paths and
everything looks good there. Here's the cron entry that I just tested
with:
23 12 * * * /usr/local/bin/decrypt_test.py >
/usr/local/bin/decrypt.log 2>&1
As for "blowing up", I get the typical stack trace, but I'm not
python-savvy enough to quite figure it out:
Traceback (most recent call last):
File "/SHCD/scripts/decrypt_certegy.py", line 18, in ?
attach_fhs={'stdin':inputfile,'stdout':outputfile})
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
357, in run
create_fhs, attach_fhs)
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
401, in _attach_fork_exec
if process.pid == 0: self._as_child(process, gnupg_commands, args)
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
442, in _as_child
os.execvp( command[0], command )
File "/usr/local/lib/python2.2/os.py", line 298, in execvp
_execvpe(file, args)
File "/usr/local/lib/python2.2/os.py", line 352, in _execvpe
raise exc, arg
OSError: [Errno 2] No such file or directory
/home/ns1/PTAccountTransfer.051130022347.pgp
Traceback (most recent call last):
File "/SHCD/scripts/decrypt_certegy.py", line 20, in ?
process.wait() # cleanup
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
639, in wait
raise IOError, "GnuPG exited non-zero, with code %d" % (e << 8)
IOError: GnuPG exited non-zero, with code 65536
I'm guessing it has something to do with stdin, stdout, and cron, but I
can't figure out any more than that, or how I would go about changing
it.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Nested loop
> Micah Elliott wrote: > > On Nov 29, viewcharts wrote: > >>I am reading two text files comparing the values in one to the other, > >>this requires two loops. > > > > Or you could have a look at difflib. > > http://docs.python.org/lib/differ-examples.html On Nov 30, Steve Holden wrote: > Indeed, but I personally don't see a way to persuade difflib to > compare the lines of one file with the fourth field of lines in > another. Right. I was just pointing out the possibility (I don't know the OP's data format) since no one had mentioned it yet. If there are multiple "fields" per line, then pre-massaging into one field per line might be a reasonable approach. But then you might end up doing more work than the nested loop idea. -- _ _ ___ |V|icah |- lliott <>< [EMAIL PROTECTED] " " """ -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Hi! Harald Armin Massa wrote: > And I could see real development just from watching the BDFL: 3 years > ago PyPy was 2000times slower then CPython, and Guido was joking "and > that number is growing", this year there were not officially negated > romours that sometime maybe PyPy could be the reference implementation > of Python; and also reports that PyPy is only 18 times slower then > CPython. well, currently PyPy is around 9-11 times slower than CPython. Since a few weeks ago we are now able to switch stacklessness on and off at compile time to be able to have an interpreter that supports very deeply recursive algorithms, if that is needed. Cheers, Carl Friedrich Bolz -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
David Rasmussen wrote: > Frithiof Andreas Jensen wrote: >>From the speed requirement: Is that correspondance chess by any chance?? > > Regular chess at tournament time controls requires speed too. Any pure > Python chess program would lose badly to the best C/C++ programs out > there now. > > I would also like to see Half Life 2 in pure Python. True, but so what? Why did you suddenly change the discussion to require "pure" Python? And please define "pure" Python, given that the interpreter and many builtins, not to mention many widely used extension modules, are coded in C? And are you not allowed to use any of the performance-boosting techniques available for Python, like Pyrex or Psyco? Why such restrictions, when these are things Python programs use on a daily basis: these are *part* of Python, as much as the -O switch on the compiler is part of C/C++. Okay, let's compare a "pure" Python program (if you can define it in any meaningful, practical way) with a "pure" Java program, running on a non-JIT interpreter and with optimizations turned off (because, of course, those optimizations are umm... somehow.. not "pure"...?). Judging by the other posts in this thread, the gauntlet is down: Python is faster than Java. Let those who believe otherwise prove their point with facts, and without artificially handcuffing their opponents with non-real-world "purity" requirements. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Why I need to declare import as global in function
Dennis Lee Bieber wrote: > > But the solutions already proposed seems to work file for my sample > > program. I will try on my project soon :) > > Looking at the documentation for "execfile", I can see /how/ the > problem occurs -- but can't determine if this can be considered > "expected". > > -=-=-=-=-=-=- > execfile( filename[, globals[, locals]]) > > This function is similar to the exec statement, but parses a file > instead of a string. It is different from the import statement in that > it does not use the module administration -- it reads the file > unconditionally and does not create a new module.2.2 > -=-=-=-=-=-=- > > I'm guessing that the intent was only that "file 1" not become an > entry on the module list, but it seems to be applying "...not create a > new module" recursively to the imported "math"... Maybe an expert with > the Python byte-code can verify. My hypothesis is something on the order > of: > Outer (file level) references to math (math.pi) are being handled > during the byte-code compilation phase of execfile, so even if "math" > isn't in the module list, it is still in local scope for the outer > math.pi... the byte code is identical for both cases; the only difference I can see is that when when you compile a function that contains a global statement, the corresponding name is added to the globals for the function that does the compilation (run_ut in this case). if you don't use globals, or if the "global" name doesn't exist in the module namespace, this doesn't happen. hmm. puzzling. -- http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Shootout
[EMAIL PROTECTED] wrote: > "Be Nice!" *is* one of paragraph headings in the FAQ section "How can I > help?" yeah, we've noticed that it's not one of the headings in the FAQ section "How can we encourage you to contribute". -- http://mail.python.org/mailman/listinfo/python-list
Re: Quene
Tuvas wrote: > I am trying to write a function that holds a variable-length quene. The > quene has 2 bits of information. At some point, I would like to remove > bits of this quene, when they are completed. Is there a way to do this > with something as follows? > > quene=[] > quene.append((4,2)) Here you are not adding two items (a 4 and a 2) but only a single item (a tuple, containing within it a 4 and a 2). What did you really want to do? > quene.append((3,6)) > if(4 in quene):#Shows false, what's the correct syntax to > show true? Since you don't have a 4 in your list, there is no correct syntax. If you did have a 4, that would be the correct syntax, or you could use queue.index(4) instead if you cared *where* it was in the list. > remove 4 from quene #(Not python code, not sure how to do this...) queue.pop(0) will pop an item off the front of the list, which is the end opposite where .append() puts them. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: python speed
Harald Armin Massa wrote: > >Faster than assembly? LOL... :) > > why not? Of course, a simple script like "copy 200 bytes from left to > right" can be handoptimized in assembler and run at optimum speed. > Maybe there is even a special processor command to do that. > > I learned that there was one generation of CPUs which had effectively a > command to copy X bytes from left to right; but a specific version of > that CPU did this command slower then a loop in certain situations. > Some newer generations of that CPU and even some competitors CPU had > that command implented correctly, and it was indeed faster than the > loop. > > Now: is it rather likely that for a single programm a programmer is > able to get it right for all CPUs? > > It even gets more complicated. The human mind is able to consider a > certain amount of things at once, sth. like on-chip-cache or > short-term-memory. > > Now with an ever growing complexity of processors, with cache lines, > partyparallelexecution, branchprediction, out of order execution, > multilevelcaching, hypermetathreading ... it may be that the usual > availaible human brain is no longer capable of really knowing what > happens. global optimizers for non-C languages can sometimes produce faster code than human C coders, also when those optimizers use C as an intermediate language... -- http://mail.python.org/mailman/listinfo/python-list
wxPython - processes
In wxPython, I want to be able to start downloading a file and have the window doing such remain interactive, so that the user can cancel downloading the next file. Also, if there is a way to cancel a downloading process, what is it? I am using urllib.urlretrieve. Thanks for any help, in advance. -- http://mail.python.org/mailman/listinfo/python-list
