Update: [ANN] 1 year pyCologne and next meeting, Wed Nov 14, 2007, 6:30 pm
As some of you have noticed, I got the date wrong again in the announcement below. I really shouldn't write these announcements in the pub between my second and third beer ;-) So here's the right data for this week's meeting of pyCologne: Date: Wednesday Nov 14, 2007 Time: 6:30 Uhr pm c.t. Venue: Pool 0.14, Benutzerrechenzentrum (RRZK-B) der Universität Köln, Berrenrather Str. 136, 50937 Köln, Germany Thanks and hoping to see you, Chris Christopher Arndt schrieb: Dear Pythonistas, with great pleasure and some pride I'd like to announce that pyCologne, the Python User Group Köln, will meet for the 13th time this week and we are therefore celebrating our 1st anniversary. The next meeting takes place here: Date: Wednesday Nov 11, 2007 Time: 6:30 Uhr pm c.t. Venue: Pool 0.14, Benutzerrechenzentrum (RRZK-B) der Universität Köln, Berrenrather Str. 136, 50937 Köln Agenda: * From the series My favourite editor: Emacs (Rebecca Breu) * Discussion: The first year pyCologne * Topics for a Python beginner's course (Rebecca Breu) * pyCologne logo decision Around 9 pm we will head to a nearby establishment and have some drinks, food and a friendly chat. Further information about pyCologne, including directions, photographs and minutes of past meetings etc., can be found on our web site on the German Python wiki: http://www.pycologne.de/ CU, Christopher Arndt -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] Release of the first PyTables video
= Release of the first PyTables video = `Carabos http://www.carabos.com/`_ is very proud to announce the first of a series of videos dedicated to introducing the main features of PyTables to the public in a visual and easy to grasp manner. http://www.carabos.com/videos/pytables-1-intro `PyTables http://www.pytables.org/`_ is a Free/Open Source package designed to handle massive amounts of data in a simple, but highly efficient way, using the HDF5 file format and NumPy data containers. This first video is an introductory overview of PyTables, covering the following topics: * HDF5 file creation * the object tree * homogeneous array storage * natural naming * working with attributes With a running length of little more than 10 minutes, you may sit back and watch it during any short break. More videos about PyTables will be published in the near future. Stay tuned on www.pytables.org for the announcement of the new videos. We would like to hear your opinion on the video so we can do it better the next time. We are also open to suggestions for the topics of future videos. Best regards, :: Ivan Vilata i Balaguer qo http://www.carabos.com/ Cárabos Coop. V. V V Enjoy Data signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: function call problem in class?
En Wed, 14 Nov 2007 04:51:57 -0300, Davy [EMAIL PROTECTED] escribió: I have write a simple class, I want the function two() to call private function __one(), but there is an error : NameError: global name '_simple__one' is not defined, how to work around it class simple: def __one(self): print Hello def two(self): __one() print world if __name__ == '__main__': s = simple() s.two() Note that your problem is not related to mangled names: replacing __one by one raises a similar exception. Remember that self is not implicit: you must use self.__one() private methods (and atributes in general) use a single underscore: _one. Double underscores __one are reserved for the (rare) cases when you want to ensure unique names (or name clashes are expected). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: function call problem in class?
On Nov 14, 4:10 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Nov 2007 04:51:57 -0300, Davy [EMAIL PROTECTED] escribió: I have write a simple class, I want the function two() to call private function __one(), but there is an error : NameError: global name '_simple__one' is not defined, how to work around it class simple: def __one(self): print Hello def two(self): __one() print world if __name__ == '__main__': s = simple() s.two() Note that your problem is not related to mangled names: replacing __one by one raises a similar exception. Remember that self is not implicit: you must use self.__one() Hi Gabriel, Thank you. now my code work well ) Davy private methods (and atributes in general) use a single underscore: _one. Double underscores __one are reserved for the (rare) cases when you want to ensure unique names (or name clashes are expected). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: cross-platform c questions
When writing a python c extension for needs to be compiled for Windows, Linux, and the Mac, what cross-platform differences need to be accounted for?# From a Python point of view, it's primarily the difference in the size of types. For example, long may vary across platforms, and so changes the result value range for PyInt_AsLong. Another issue is the mechanism to export things from a shared library; on Windows, you have to use __declspec(export). Yet another issue the question what basic functions are available in the system (e.g. whether strdup is available) Are there functions in the python api to deal with the differences? For example, byte ordering, how is that controlled? Not functions, no, but macros and typedefs. For example, there is now a typedef Py_ssize_t that you should use if you measure the number of bytes (or, more generally, things in a collection). For the __declspec(export) thing, there are the PyAPI_FUNC and PyMODINIT_FUNC macros. For detecting platform-specific details, autoconf is used, which defines things like HAVE_STRDUP. autoconf also defines WORDS_BIGENDIAN if the system uses the bigendian byte order. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
re: mpmath puzzle
Dick Moores wrote: For 1234 ** 10.9, why the wrong result from mpmath.power()? #!/usr/bin/env python #coding=utf-8 from mpmath import * mpf.dps = 32 x = mpf(1234) y = mpf(10.9) print power(x,y) print 4.9583278648155041477415234438717e+33 # from Windows calculator output: 4.9583278648155166864966558721921e+33 4.9583278648155041477415234438717e+33 (Code is also at http://python.pastebin.com/m72a277b8) Thanks, Dick Moores Hi, When you create y, you first create an inexact Python float whose value is actually 10.900355... and then pass it to mpf, which just copies that value along with the error. To create an accurate representation of a fractional number (integers are safe), pass a string instead: from mpmath import * mpf.dps = 32 x = mpf(1234) y = mpf('10.9') print power(x,y) 4.9583278648155041477415234438719e+33 The last printed digit is wrong, which is to be expected in binary arithmetic since 10.9 still cannot be represented exactly (with mpf.dps = 32, the error is about 5e-033); computing a power amplifies that error. You can temporarily increase the precision by a couple of digits during calculations and then reduce it before printing the final value if you want all digits to be right. I should update the mpmath documentation to be much clearer about all this. Fredrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Arrays
On Nov 14, 3:51 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Modules contain objects. When you want to import a specific set of objects contained in a module into the local namespace, you use: from module import names to import For example: from math import sqrt from math import sin, cos If you want to import everything from a module, use: from module import * For example: from math import * If you want to import a module as an entity itself, use: import module For example: import math #Use, for example, math.sqrt to call the sqrt function You can also use import ... as ... to rename an imported object: import math as m #Now use m.sqrt instead of math.sqrt from math import sqrt as square_root #sqrt is now bound to square_root in the local module In the array module, there is an object named array. You could access using: import array array.array or from array import array array or from array import array as foobar foobar or ... The way you choose to actually do this is up to you. Most people just decide what they like/makes the most sense. In the math module, there is no object called math. That is why we do not use from math import math Traceback (most recent call last): File stdin, line 1, in module ImportError: cannot import name math --Nathan Davis On Nov 13, 7:25 pm, Gordon C [EMAIL PROTECTED] wrote: OK Steve, But why do we say from array import array and NOT from math import math? Why the difference in syntax? Gord Steven D'Aprano [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Tue, 13 Nov 2007 11:26:28 -0500, Gordon C wrote: OK, thanks to all. The key statement is from array import array which is not exactly intuitive! The only intuitive interface is the nipple. After that, it's all learned. -- Bruce Ediger on user interfaces. Once you've been using Python for a while, using import becomes as intuitive as a spoon. The only tricky part is knowing *which* module to import. But, honestly, are you surprised to learn that the array type is held in in the array module? -- Steven. Let me just say, that is a perfect reply! -- http://mail.python.org/mailman/listinfo/python-list
How to use the evaluate the code object returned by PyParser_Simp leParseString function?
Hi, Can someone please help me in the following question? On the web page http://olympus.het.brown.edu/cgi-bin/info2www?(python2.3-api)Very+High+Level+Layer, I got the following information: `struct _node* PyParser_SimpleParseString(char *str, int start)' Parse Python source code from STR using the start token START. The result can be used to create a code object which can be evaluated efficiently. This is useful if a code fragment must be evaluated many times. I have exactly same requirement. I have dynamic expressions loaded from database at startup in my C++ application. I want to parse these expressions at startup keep the parsed (compiled) code in memory of this application. Then at runtime, I want to evaluate all this parsed code. This has to be very efficient. So, which function should be used for evaluating the parsed code generated by PyParser_SimpleParseString? Do I need to use the struct _node* returned by PyParser_SimpleParseString? Any example of this use would be more helpful? Thanks in advance for guidance help. Warm Regards, Ganesh == Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html == -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
[EMAIL PROTECTED] wrote: Hello, I'm a teen trying to do my part in improving the world, and me and my pal came up with some concepts to improve the transportation system. I have googled up and down for examples of using python to create a city street but I can not find any. my objective is to replicate a section of los angeles using python, and program the street lights and cars and whatnot. Should I be looking towards 3D to do this? so here is MY question: how would you replicate a street intersection in python? and furthermore, how would you do you have the cars move up and down those streets. my question to YOU is: can you point me in the right direction? I will search on my own, but I would greatly appreciate any help :) and if anyone is interested in learning more about this project (we've got some nifty things planned), or if you wanna help, give a shout ;] It's hard to tell you what to do with so sparse information about what you try to accomplish in the end. Of course if you want to have more or less realistic imaging for whatever purpose, 3D is the way to go. If you are after traffic-simulations, it's unneeded complexity. Regarding the moving cars: you can also go from simply defining paths cars can take and parametrize these to full-blown physics - depending on what you want. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Equivalent of TCL's subst ?
gamename a écrit : Hi, In TCL, you can do things like: set foobar HI! set x foo set y bar subst $$x$y HI! Is there a way to do this type of evaluation in python? TIA, -T you can also try using eval: foobar = HI! x = 'foo' y = 'bar' print eval(x+y) HI! Loic -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
On Nov 14, 4:09 am, [EMAIL PROTECTED] wrote: my question to YOU is: can you point me in the right direction? I will search on my own, but I would greatly appreciate any help :) have a look at http://simpy.sourceforge.net/ for the simulation part -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
On Wed, 14 Nov 2007 11:01:40 +0100, Diez B. Roggisch wrote: [EMAIL PROTECTED] wrote: Hello, I'm a teen trying to do my part in improving the world, and me and my pal came up with some concepts to improve the transportation system. […] Of course if you want to have more or less realistic imaging for whatever purpose, 3D is the way to go. If you are after traffic-simulations, it's unneeded complexity. Not if their solution includes flying buses and taxis. Or this pneumatic delivery system for people from `Futurama`. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Populating a dictionary, fast [SOLVED]
A Tuesday 13 November 2007, Steven D'Aprano escrigué: On Tue, 13 Nov 2007 17:27:11 +0100, Francesc Altet wrote: I don't know exactly why do you need a dictionary for keeping the data, but in case you want ultra-fast access to values, there is no replacement for keeping a sorted list of keys and a list with the original indices to values, and the proper list of values. Then, to access a value, you only have to do a binary search on the sorted list, another lookup in the original indices list and then go straight to the value in the value list. This should be the faster approach I can think of. Maybe on Bizarro World, but not on Planet Earth. Searching a dict takes on average a constant amount of time, regardless of the key and the size of the dict. Because dicts are the basis of Python's namespaces, it is optimized up the wazoo, and being implemented in C it is extremely fast. Using your suggestion, to get a value: you have to do a binary search which is O(log N) instead of O(1), then ANOTHER lookup into a list of indices, and finally a THIRD lookup to actually retrieve the value -- all implemented in relatively slow Python instead of fast C. Well, the bisect module in Python is implemented in fast C. Apart from that, you are basically right, see below. And let's not even discuss the overhead of keeping these three lists synchronized. But don't take my word for it: measure for yourself. I'm not even going to attempt to code your suggestion, but here's how you measure the time it takes for dictionary lookup. # Create a dataset to search on. D = {} chars = abcdefghijklmnopqrstuvwxyz triplets = (a+b+c for a in chars for b in chars for c in chars) for i, s in enumerate(triplets): D[s] = i # D is of the form {'abc': 12345} # Now time a successful search for an arbitrary triplet. import timeit min(timeit.Timer(D['foo'], from __main__ import D).repeat(6)) On my PC, it takes about 0.2 seconds per million searches. Oh yes. All of you are right, guys. I've implemented code (attached) for measuring the lookup times using a a dictionary and using a binary search approach (using numpy, mostly for space efficiency) and here are my results: $ python2.5 gq-dict.py Creating the dictionary... Time for dict creation: 89.115 Items in dict: 8191180 Timing queries... Time for querying: 39.44 $ python2.5 gq-binary-search.py Creating the lists... Time for lists creation: 4.245 Sorting... Time for sorting: 6.195 Timing queries... Time for querying: 108.1 i.e. a dict approach proves to be almost 3x faster than a regular binary search (5 us/lookup vs 13 us/lookup). I think I've got messed on some benchmarks that I've done on that subject some time ago, but either my memory is bad or I've made some mistake on those experiments. My apologies. Cheers, -- 0,0 Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data - gq-binary-search.py Description: application/python gq-dict.py Description: application/python -- http://mail.python.org/mailman/listinfo/python-list
Re: Populating a dictionary, fast [SOLVED]
A Wednesday 14 November 2007, Istvan Albert escrigué: On Nov 13, 11:27 am, Francesc Altet [EMAIL PROTECTED] wrote: Another possibility is using an indexed column in a table in a DB. Lookups there should be much faster than using a dictionary as well. I would agree with others who state that for a simple key based lookup nothing beats a dictionary. But knowing that you are one of the authors of the excellent pytables module I think you are approaching this problem from the perspective of reading in a large number of values on each access. In those cases specialized libraries (like the hdf) can directly load into memory huge amounts of continuous data at speeds that substantially outperform all other approaches. Yes, could be. However, I was well aware that the problem was looking up one single value, so, mea culpa :(. Sorry for introducing noise. -- 0,0 Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data - -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert some Python code to C++
[EMAIL PROTECTED] a écrit : For those that understand algorithms and can talk Python, I want to convert the Python code in the section Reading out all LCSs into C++ code but I don't understand some of the syntax. Can anyone give me a hand? def backTrackAll(C, X, Y, i, j): if i == 0 or j == 0: return set([]) elif X[i-1] == Y[j-1]: return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1, j-1)]) else: R = set() if C[i][j-1] = C[i-1][j]: R.update(backTrackAll(C, X, Y, i, j-1)) if C[i-1][j] = C[i][j-1]: R.update(backTrackAll(C, X, Y, i-1, j)) return R Thanks! just have a look at this tutorial: and look for Lists and Sets http://docs.python.org/tut/tut.html and look in the reference index for set() and list() in http://docs.python.org/lib/genindex.html or just pick the algo in another language in the url you give or tell us precisely what part of the python algo you do not understant! -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes pointers
Giorgos Giagas wrote: Hi all, I have started using ctypes and I am having some questions I can't seem to find the answers to. There is a structure referenced by a pointer in an other structure and I want to see if it is one of the structures I have pointers to. So what I think I need is a way to compare 2 pointer's memory location. I can't find a way to do this. Pointer comparisons don't work. Is there something else I should do? Use addressof on the contents of your pointers. The other thing is more of a curiosity... The documentation says that I need to keep references to structures so they don't get freed is this also true for structures returned as pointers? What about structures that I cast to something else? I guess the largest of the two casts gets freed like it should... can someone confirm this? The one has nothing to do with the other. If you create a struct and pass e.g. a pointer to it into a DLL, you need to keep a reference, otherwise the struct will be deallocated and the pointer is dangling. If you have a pointer and cast it to some structure, you get a structure object (in python) that points to a certain memory portion. But GCing that object doesn't do anything to the memory location. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Arrays
On Tue, 13 Nov 2007 20:25:07 -0500, Gordon C wrote: OK Steve, But why do we say from array import array and NOT from math import math? Why the difference in syntax? It isn't different syntax. The difference is that there is a function array (technically, a type rather than a function) in the module array, but there is no function math in the array math. There is however a function sin, so you can do this: from math import sin Precisely the same syntax: from module-name import object-name. Only the names are different. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
ctypes pointers
Hi all, I have started using ctypes and I am having some questions I can't seem to find the answers to. There is a structure referenced by a pointer in an other structure and I want to see if it is one of the structures I have pointers to. So what I think I need is a way to compare 2 pointer's memory location. I can't find a way to do this. Pointer comparisons don't work. Is there something else I should do? The other thing is more of a curiosity... The documentation says that I need to keep references to structures so they don't get freed is this also true for structures returned as pointers? What about structures that I cast to something else? I guess the largest of the two casts gets freed like it should... can someone confirm this? -- http://mail.python.org/mailman/listinfo/python-list
Google's tolerance of spam
On 13 Nov, 23:03, Ben Finney [EMAIL PROTECTED] wrote: Their messages are an abuse of Google Groups's terms of service, and Google will likely act on complaints that include a *full* copy of the offending message. Unless things have changed recently, I doubt that Google can be bothered to do anything about such spam, even stuff apparently originating from GMail. I used to flag a lot of messages as spam, and on the occasions when the spam report form actually worked, it didn't seem to have much of a subsequent effect on the ability of the spammers to send the same tired nonsense to the group over and over again. (Either newsgroups and Google groups are just write-only channels for these idiots, or they take the classic Usenet approach of playing in non-political/off-topic groups, knowing that their low- end debate wouldn't stand five seconds of scrutiny in an appropriate forum with people actually interested to read and respond to such nonsense.) Anyway, for Google it's a problem that's probably less serious than having people gaming Adwords (or whatever Google's advertising system is called): unless there's a financial impact on Google, they're inclined to look the other way even if other people are clearly getting a bad deal (from what I've read of various advertising scams, at least). Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
On Nov 14, 3:09 am, [EMAIL PROTECTED] wrote: ... so here is MY question: how would you replicate a street intersection in python? and furthermore, how would you do you have the cars move up and down those streets. I've never used it, but I'd have thought that pygame would satisfy the graphical side of things. -- Ant -- http://mail.python.org/mailman/listinfo/python-list
Re: Arrays
On Tue, 13 Nov 2007 22:31:57 -0200, Jorge Godoy wrote: Steven D'Aprano wrote: The only intuitive interface is the nipple. After that, it's all learned. -- Bruce Ediger on user interfaces. And after we learn its other uses, not even the nipple is so easy... Who haven't heard (or said, if you're a woman) Don't bite it like that, it hurts!? :-) Or even Please Sir, bite it like that! Thank you Sir! *ducks and hides* -- Steven -- http://mail.python.org/mailman/listinfo/python-list
pygobject replacement?
Hi, I have a python library which is written years ago and heavily using pygobject in binding signal/events (No GUI stuffs involve). Now I have to use it in a totally different environment which doesnot allow to install glib, gtk and gobject. Surely I don't want to change the whole structure of handling signals/events. Is there any pure python pygobject replacement that I can switch to, and change only functions like emit? Any suggestion is appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: pygobject replacement?
Linan napisał(a): I have a python library which is written years ago and heavily using pygobject in binding signal/events (No GUI stuffs involve). Now I have to use it in a totally different environment which doesnot allow to install glib, gtk and gobject. Surely I don't want to change the whole structure of handling signals/events. Is there any pure python pygobject replacement that I can switch to, and change only functions like emit? I used to use Louie (http://pylouie.org/) and PyDispatcher. They are both synchronous, though, so to have real signal behaviour you have to use eg. threads. -- Jarek Zgoda Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101 We read Knuth so you don't have to. (Tim Peters) -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_Oracle: Non-ASCII characters handling with different versions
Benjamin Hell wrote: On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g) I can get query results consisting of strings including non-ASCII characters, e.g. the code example below outputs é 0xe9 (which is the correct ISO-8859-1 hex code for é). On a newer installation with cx_Oracle 4.3.3 (Python 2.5.1, connecting to the same Oracle 10g server) these characters are interpreted as ASCII (output e 0x65). It's solved: Because of a local full Oracle DB installation the working box had the registry key HKEY_LOCAL_SYSTEM\SOFTWARE\ORACLE\KEY_OraBD10g_home1\NLS_LANG set to AMERICAN_AMERICA.WE8MSWIN1252. A similar key was missing on the other box. I added HKEY_LOCAL_SYSTEM\SOFTWARE\ORACLE\NLS_LANG with the same value and now it works. -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes pointers
On Nov 14, 2:00 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Giorgos Giagas wrote: Hi all, I have started using ctypes and I am having some questions I can't seem to find the answers to. There is a structure referenced by a pointer in an other structure and I want to see if it is one of the structures I have pointers to. So what I think I need is a way to compare 2 pointer's memory location. I can't find a way to do this. Pointer comparisons don't work. Is there something else I should do? Use addressof on the contents of your pointers. Thank you. I was looking for a pointer or structure property and missed that. The other thing is more of a curiosity... The documentation says that I need to keep references to structures so they don't get freed is this also true for structures returned as pointers? What about structures that I cast to something else? I guess the largest of the two casts gets freed like it should... can someone confirm this? The one has nothing to do with the other. If you create a struct and pass e.g. a pointer to it into a DLL, you need to keep a reference, otherwise the struct will be deallocated and the pointer is dangling. If you have a pointer and cast it to some structure, you get a structure object (in python) that points to a certain memory portion. But GCing that object doesn't do anything to the memory location. That makes sence. I was confused about this thing... Thanks a lot for the quick reply, Giorgos -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
[EMAIL PROTECTED] wrote: Hello, I'm a teen trying to do my part in improving the world, and me and my pal came up with some concepts to improve the transportation system. I have googled up and down for examples of using python to create a city street but I can not find any. http://www.gis.usu.edu/~sanduku/public_html/dissertation/outline/node23.html Automobile traffic has a very extensive body of literature involving simulation. Most people in the industrialized world deal with automobile traffic on a daily basis, and many studies are funded annually to alleviate existing or potential traffic problems. Several academic journals are dedicated exclusively to automobile traffic dynamics, new textbooks on the subject are published regularly, and the number of articles published each year dealing with automobile traffic number in the hundreds. while they may not be in Python, I'm sure you can find modeling systems to do a you want to do for far less effort than it would take to re-create them from scratch. -- Speech-recognition in use. It makes mistakes, I correct some. -- http://mail.python.org/mailman/listinfo/python-list
RE: Using Python To Change The World :)
It sounds as if this project is a major task based on your current level of experience. That being said, all we pythonistas encourage and support anyone who is trying to learn/apply python. Break the problem into 2 parts: --simulation math of what you're trying to do --cool visual display (2D is sufficient) to make it interesting and so others can grasp what you did Then the math drives the display, but you can build and test the math using text output. pygame and pysim are good candidates. There is also www.vpython.org. Make sure you find some tutorial on object oriented programming OOP because that's the way to build this critter. I'm assuming you have a fairly powerful PC, if so you need a decent development environment. google for python IDE or check at python.org. I use Eclipse + PyDev (both free) although there is a wide difference of opinion on IDE's. Remember to eat the elephant one byte at a time. i.e. small steps. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Ant Sent: Wednesday, November 14, 2007 6:48 AM To: python-list@python.org Subject: Re: Using Python To Change The World :) On Nov 14, 3:09 am, [EMAIL PROTECTED] wrote: ... so here is MY question: how would you replicate a street intersection in python? and furthermore, how would you do you have the cars move up and down those streets. I've never used it, but I'd have thought that pygame would satisfy the graphical side of things. -- Ant -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
[EMAIL PROTECTED] wrote: my objective is to replicate a section of los angeles using python, and program the street lights and cars and whatnot. Should I be looking towards 3D to do this? so here is MY question: how would you replicate a street intersection in python? and furthermore, how would you do you have the cars move up and down those streets. my question to YOU is: can you point me in the right direction? I will search on my own, but I would greatly appreciate any help :) If you do want to do this in 3-D, try out VPython. More than any other 3-D system I've seen, it allows you to concentrate more on your problem, and let it handle most of the 3-D rendering calculations as you are learning how to use it. -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a good Python environment
[EMAIL PROTECTED] wrote: Hey, I'm looking for a good Python environment. That is, at least an editor and a debugger, and it should run on Windows. Does anyone have any idea? I've been looking for the equivalent although I want the IDE to run on Windows and to be able to edit/debug/bzr files on a remote system (linux in VM or remote physical hardware). Solutions that I've explored are: Network filesystems (Samba, NFS) Emacs plus tramp eclipse plus remote file access remote system IDE, local display with X11 local editor plus unison Here's how they failed: Network filesystems always fail because they get ownership and permissions wrong. No matter what you set the mapping to, it's almost always wrong for some part of the system. It's made worse because setup .py does not make it easy to force permissions and ownership to what you want them to be (afaik). this forces the use of an ad hoc script to enforce permissions and ownership after running setup.py. using this configuration, it is possible to hibernate your Windows machine but only if you manually restart your remote filesystem connections before trying to do anything with your IDE. Emacs plus tramp is the best solution so far albeit somewhat fragile. It's moderately difficult to jump into the right point in the filesystem although this may be an artifact of trying to use speech recognition for this task. another annoying problem is forcing Emacs to use UNIX format text files. I know I just need to RTF but I haven't gotten around to it yet. Emacs plus tramp is also the easiest to hibernate as it does not use persistent connections to remote machine but if the remote host isn't available when you try to access a file via recentf, you lose the reference to the file and need to type/speak the path in again. Eclipse has been an unmitigated disaster for me. It's fat, it's heavy, it pushes all of my other applications out of virtual memory and then I need to wait 10s of seconds when I switch. I can't figure out which components of the bag of parts I need and easy eclipse is too old to use the remote file system access extension. blech. Using X11 for local display is great if the remote machine is local and you're not paging out to virtual memory. most common problem is that the local X11 display loses track of local Windows and you end up with this graphic ink blot on the screen that never quite goes away until you restart X11 and all the other applications through it. with the X11 solution, you cannot hibernate your host machine because the persistent connections break and cannot be restarted. local editor plus unison sort of, kind of works. Yes, you can edit all your files and replicate them on the target machine. Ownership and permissions are broken. There is a problem with UNIX versus DOS file format but once you force the editor to do the right thing, the format is right on the remote side. It's clumsy but it does have the advantage that if you make changes on the remote system when debugging, those changes are replicated back on your editing house. As for debugging, personally, I just use winpdb everywhere and just suffer with bad X11 connections. One additional factor raised by split machine operations is how do you organize your files? Do you have different repositories on different machines or do you have a single repository on your editing host and look to some form of replication for updates across one or more machines? it's an interesting set of problems. Today, I just muddle along as I don't really see a good solution. I'm hoping I'll be proven wrong and find a solution that will make my life easier someday. -- Speech-recognition in use. It makes mistakes, I correct some. -- http://mail.python.org/mailman/listinfo/python-list
Re: A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.
On 11/14/07 3:30 AM, in article [EMAIL PROTECTED], ChairmanOfTheBored [EMAIL PROTECTED] wrote: On Tue, 13 Nov 2007 20:32:10 -0800, Don Bowey [EMAIL PROTECTED] wrote: Notice that I... acted like a total retard... again. Good job, retard boy. No problem. I'm glad I could help, paleo-boy. -- http://mail.python.org/mailman/listinfo/python-list
[SOLVED] Re: os walk() and threads problems (os.walk are thread safe?)
Ok. I found the problem. That's because in for i test if EXIT and break loop if it's true. In main part i'm wait Queue to be empty and set EXIT after that, with this subdirectories in for loop does not process and program exit. Because that output are not same. Removing if EXIT all works fine again. Thanks all Regards Marcus Alves Grando wrote: I make one new version more equally to original version: --code-- #!/usr/bin/python import os, sys, time import glob, random, Queue import threading EXIT = False BRANDS = {} LOCK=threading.Lock() EV=threading.Event() POOL=Queue.Queue(0) NRO_THREADS=20 def walkerr(err): print err class Worker(threading.Thread): def run(self): EV.wait() while True: try: mydir=POOL.get(timeout=1) if mydir == None: continue for root, dirs, files in os.walk(mydir, onerror=walkerr): if EXIT: break terra_user = 'test' terra_brand = 'test' user_du = '0 a' user_total_files = 0 LOCK.acquire() if not BRANDS.has_key(terra_brand): BRANDS[terra_brand] = {} BRANDS[terra_brand]['COUNT'] = 1 BRANDS[terra_brand]['SIZE'] = int(user_du.split()[0]) BRANDS[terra_brand]['FILES'] = user_total_files else: BRANDS[terra_brand]['COUNT'] = BRANDS[terra_brand]['COUNT'] + 1 BRANDS[terra_brand]['SIZE'] = BRANDS[terra_brand]['SIZE'] + int(user_du.split()[0]) BRANDS[terra_brand]['FILES'] = BRANDS[terra_brand]['FILES'] + user_total_files LOCK.release() except Queue.Empty: if EXIT: break else: continue except KeyboardInterrupt: break except Exception: print mydir raise if len(sys.argv) 2: print 'Usage: %s dir...' % sys.argv[0] sys.exit(1) glob_dirs = [] for i in sys.argv[1:]: glob_dirs = glob_dirs + glob.glob(i+'/[a-z_]*') random.shuffle(glob_dirs) for x in xrange(NRO_THREADS): Worker().start() try: for i in glob_dirs: POOL.put(i) EV.set() while not POOL.empty(): time.sleep(1) EXIT = True while (threading.activeCount() 1): time.sleep(1) except KeyboardInterrupt: EXIT=True for b in BRANDS: print '%s:%i:%i:%i' % (b, BRANDS[b]['SIZE'], BRANDS[b]['COUNT'], BRANDS[b]['FILES']) --code-- And run in make servers: # uname -r 2.6.18-8.1.15.el5 # python test.py /usr test:0:2267:0 # python test.py /usr test:0:2224:0 # python test.py /usr test:0:2380:0 # python -V Python 2.4.3 # uname -r 7.0-BETA2 # python test.py /usr test:0:1706:0 # python test.py /usr test:0:1492:0 # python test.py /usr test:0:1524:0 # python -V Python 2.5.1 # uname -r 2.6.9-42.0.8.ELsmp # python test.py /usr test:0:1311:0 # python test.py /usr test:0:1486:0 # python test.py /usr test:0:1520:0 # python -V Python 2.3.4 I really don't know what's happen. Another ideia? Regards Chris Mellon wrote: On Nov 13, 2007 1:06 PM, Marcus Alves Grando [EMAIL PROTECTED] wrote: Diez B. Roggisch wrote: Marcus Alves Grando wrote: Diez B. Roggisch wrote: Marcus Alves Grando wrote: Hello list, I have a strange problem with os.walk and threads in python script. I have one script that create some threads and consume Queue. For every value in Queue this script run os.walk() and printing root dir. But if i increase number of threads the result are inconsistent compared with one thread. For example, run this code plus sort with one thread and after run again with ten threads and see diff(1). I don't see any difference. I ran it with 1 and 10 workers + sorted the output. No diff whatsoever. Do you test in one dir with many subdirs? like /usr or /usr/ports (in freebsd) for example? Yes, over 1000 subdirs/files. Strange, because to me accurs every time. And I don't know what you mean by diff(1) - was that
Creating Installer or Executable in Python
I have a small project which has around 10 .py files and I run this project using command line arguments. I have to distribute this project to somebody. I was wondering how can I make an executable or some kind of installer, so that end user doesn't need to compile and worry if he/ she has Python installed or not ? Every help is greatly appreciated. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
A few candidate solutions: http://nsis.sourceforge.net/Main_Page http://www.jrsoftware.org/isinfo.php DanielJohnson wrote: I have a small project which has around 10 .py files and I run this project using command line arguments. I have to distribute this project to somebody. I was wondering how can I make an executable or some kind of installer, so that end user doesn't need to compile and worry if he/ she has Python installed or not ? Every help is greatly appreciated. Thanks, -- Shane Geiger IT Director National Council on Economic Education [EMAIL PROTECTED] | 402-438-8958 | http://www.ncee.net Leading the Campaign for Economic and Financial Literacy begin:vcard fn:Shane Geiger n:Geiger;Shane org:National Council on Economic Education (NCEE) adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States email;internet:[EMAIL PROTECTED] title:IT Director tel;work:402-438-8958 url:http://www.ncee.net version:2.1 end:vcard -- http://mail.python.org/mailman/listinfo/python-list
Re: Populating a dictionary, fast [SOLVED SOLVED]
On Nov 12, 12:46 pm, Michael Bacarella [EMAIL PROTECTED] wrote: It takes about 20 seconds for me. It's possible it's related to int/long unification - try using Python 2.5. If you can't switch to 2.5, try using string keys instead of longs. Yes, this was it. It ran *very* fast on Python v2.5. Um. Is this the take away from this thread? Longs as dictionary keys are bad? Only for older versions of Python? This could be a problem for people like me who build lots of structures using seek values, which are longs, as done in http://nucular.sourceforge.net and http://bplusdotnet.sourceforge.net and elsewhere. Someone please summarize. -- Aaron Watters === http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=white%20trash -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
DanielJohnson wrote: I have a small project which has around 10 .py files and I run this project using command line arguments. I have to distribute this project to somebody. I was wondering how can I make an executable or some kind of installer, so that end user doesn't need to compile and worry if he/ she has Python installed or not ? http://www.fuckinggoogleit.com/?q=py2exe Under UNIX systems of course, your user should install using the given system's package manager... -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
On Wed, Nov 14, 2007 at 03:34:14PM +0100, Laszlo Nagy wrote regarding Re: Creating Installer or Executable in Python: DanielJohnson wrote: I have a small project which has around 10 .py files and I run this project using command line arguments. I have to distribute this project to somebody. I was wondering how can I make an executable or some kind of installer, so that end user doesn't need to compile and worry if he/ she has Python installed or not ? http://www.fuckinggoogleit.com/?q=py2exe While I agree with the sentiment, I'm left wondering how you think he would have known to google for py2exe. Maybe you meant: http://www.fuckinggoogleit.com/?q=python+executable (Which also yields py2exe as the first result.) Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
On Nov 14, 8:34 am, Laszlo Nagy [EMAIL PROTECTED] wrote: DanielJohnson wrote: I have a small project which has around 10 .py files and I run this project using command line arguments. I have to distribute this project to somebody. I was wondering how can I make an executable or some kind of installer, so that end user doesn't need to compile and worry if he/ she has Python installed or not ? http://www.fuckinggoogleit.com/?q=py2exe Under UNIX systems of course, your user should install using the given system's package manager... If everyone knew about Google then user groups would be obsolete. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
Thanks for telling about py2exe. Is there any utility that will help to make it as a .deb or .rpm file (for Linux)? -- http://mail.python.org/mailman/listinfo/python-list
Re: why there is no pythonscript insine web browsers?
[EMAIL PROTECTED] (k) wrote: k On Nov 12, 12:07 pm, Timuçin K z lay [EMAIL PROTECTED] wrote: I'm an old programmer coming from a cobol background and started to learn python. I'm using javasript for web based applications but after I started to learn python, the javascript language started to seem ugly to me. Now I'm wondering why there is java support on web browsers but no python support? there is even a vbscript support inside MS-IE but there is no python support. it would be really nice and easy for me to use python instead of javascript to write those ajax scripts. Please tell me, is there a python substitude for JRE ? k You can also use Python's cgi module. It's pretty cool, from what I've k read: CGI is server-side. The OP was asking for client-side embedding of Python. -- Piet van Oostrum [EMAIL PROTECTED] URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem using os.environ.get
[EMAIL PROTECTED] wrote: # echo $HOSTTYPE x86_64 # python import os print os.environ.get('HOSTTYPE') None If I do the same thing with a different variable (XILINX, in this case), it works fine. bash documentation indicates that HOSTTYPE (and a few others: OSTYPE, MACHTYPE, etc.) are variables set by the shell - not quite part of the environment, as such, and they're don't seem to be available to any subprocess: if you launch ksh from bash and check the variable, you'll get none too (on netbsd at least). So, that's a bash problem - not that it helps I guess :-) but bash docs may have some more info about this issue. j. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem using os.environ.get
[EMAIL PROTECTED] wrote: Hello, I am trying to retrieve a linux environment variable using os.environ.get, however it does not appear to be working properly. It returns none for a variable that does, in fact exist. # echo $HOSTTYPE x86_64 # python import os print os.environ.get('HOSTTYPE') None If I do the same thing with a different variable (XILINX, in this case), it works fine. # echo $XILINX /Xilinx # python import os print os.environ.get('XILINX') /Xilinx Any thoughts on why it is behaving this way? is HOSTTYPE exported? If not, it will not be included in subprocess-environments by the shell. Diez -- http://mail.python.org/mailman/listinfo/python-list
Problem using os.environ.get
Hello, I am trying to retrieve a linux environment variable using os.environ.get, however it does not appear to be working properly. It returns none for a variable that does, in fact exist. # echo $HOSTTYPE x86_64 # python import os print os.environ.get('HOSTTYPE') None If I do the same thing with a different variable (XILINX, in this case), it works fine. # echo $XILINX /Xilinx # python import os print os.environ.get('XILINX') /Xilinx Any thoughts on why it is behaving this way? Thanks, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
On 14 Nov, 16:17, DanielJohnson [EMAIL PROTECTED] wrote: Thanks for telling about py2exe. Also note that you should build an MSI installer e.g. using InnoSetup after applying py2exe. You could skip the py2exe part and only use InnoSetup to create an MSI. Most likely your client will not care if the executable file is called .py/.pyw/.pyc or .exe. Windows users are generally ignorant to the contents of the Program Files folder. They will not understand what is there and certainly not care what is there. Therefore, the only thing that really matters is to make it easy to install and run the program. That is: 1. Create an MSI that makes it easy to install the software (including runtime and dependencies). 2. Use autorun if you ship a DVD or CD-ROM. The installer should start automatically when the disc is placed in the player. 3. Make sure an icon on the Start Menu launches the program. If you have done that, 99.9% of all clients will be happy. The latter 0.01% is stupid enough to think it matters if the suffix of the executable is called .exe or not. Never mind these morons, just ship an .exe that does nothing except to spawn your Python program and exit. Is there any utility that will help to make it as a .deb or .rpm file (for Linux)? There is a tool called cx_Freeze which is similar to py2exe, except that it works on several platforms, including Linux. You will have to build the .deb or .rpm using other tools afterwards. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python as primary language
On 13 Nov, 22:39, [EMAIL PROTECTED] wrote: The wxPython user's group mentions charting quite a bit. I think they use matplotlib among others. You might contact them for suggestions as well. Indeed, use NumPy/SciPy and matplotlib if you are using Python for numerical computing and data visualization. Matplotlib has capabilites similar to the 2D plotting/charting of Matlab, and gives you beautiful antialiased graphs. Matplotlib works nicely with wxPython, PyGTK and tkinter. NumPy and matplotlib is not in the Python standard library, but I hope that will change one day. -- http://mail.python.org/mailman/listinfo/python-list
RE: Creating Installer or Executable in Python
I'd second InnoSetup for Windows installers, it's easy and powerful (and free). However, I don't think it can create actual .MSI files, only .EXE installers. I wish it would create .MSIs, since those are easier to automatically deploy for large user groups. I'm not aware of any free tools for building MSIs, but I'd love to find one. - Adam -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of sturlamolden Sent: Wednesday, November 14, 2007 9:54 AM To: python-list@python.org Subject: Re: Creating Installer or Executable in Python On 14 Nov, 16:17, DanielJohnson [EMAIL PROTECTED] wrote: Thanks for telling about py2exe. Also note that you should build an MSI installer e.g. using InnoSetup after applying py2exe. You could skip the py2exe part and only use InnoSetup to create an MSI. Most likely your client will not care if the executable file is called .py/.pyw/.pyc or .exe. Windows users are generally ignorant to the contents of the Program Files folder. They will not understand what is there and certainly not care what is there. Therefore, the only thing that really matters is to make it easy to install and run the program. That is: 1. Create an MSI that makes it easy to install the software (including runtime and dependencies). 2. Use autorun if you ship a DVD or CD-ROM. The installer should start automatically when the disc is placed in the player. 3. Make sure an icon on the Start Menu launches the program. If you have done that, 99.9% of all clients will be happy. The latter 0.01% is stupid enough to think it matters if the suffix of the executable is called .exe or not. Never mind these morons, just ship an .exe that does nothing except to spawn your Python program and exit. Is there any utility that will help to make it as a .deb or .rpm file (for Linux)? There is a tool called cx_Freeze which is similar to py2exe, except that it works on several platforms, including Linux. You will have to build the .deb or .rpm using other tools afterwards. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Global variables within classes.
Donn Ingle a écrit : (snip) I have been hearing about new classes for a while but there's no clarity in the Python docs (that I can find). Then you perhaps should have a closer look at the entries in the 'documentation' sub-menu of python.org !-) Anyway, here's a direct link: http://python.org/doc/newstyle/ Have you any references for me? I thought they were the standard by now anyway. Would break compatibility with older code. -- http://mail.python.org/mailman/listinfo/python-list
Re: pygobject replacement?
Thanks. It's very helpful. On Nov 14, 12:50 pm, Jarek Zgoda [EMAIL PROTECTED] wrote: Linan napisa³(a): I have a python library which is written years ago and heavily using pygobject in binding signal/events (No GUI stuffs involve). Now I have to use it in a totally different environment which doesnot allow to install glib, gtk and gobject. Surely I don't want to change the whole structure of handling signals/events. Is there any pure python pygobject replacement that I can switch to, and change only functions like emit? I used to use Louie (http://pylouie.org/) and PyDispatcher. They are both synchronous, though, so to have real signal behaviour you have to use eg. threads. -- Jarek Zgoda Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101 We read Knuth so you don't have to. (Tim Peters) -- http://mail.python.org/mailman/listinfo/python-list
Ultimate Guitars!!!!!
See all about it... http://guitarspirit.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
Adam Pletcher wrote: I'd second InnoSetup for Windows installers, it's easy and powerful (and free). However, I don't think it can create actual .MSI files, only .EXE installers. I wish it would create .MSIs, since those are easier to automatically deploy for large user groups. I'm not aware of any free tools for building MSIs, but I'd love to find one. I just learned about this one within the last week, wix http://wix.sourceforge.net/ PHP.net uses it for their Windows installers. -Shawn - Adam -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of sturlamolden Sent: Wednesday, November 14, 2007 9:54 AM To: python-list@python.org Subject: Re: Creating Installer or Executable in Python On 14 Nov, 16:17, DanielJohnson [EMAIL PROTECTED] wrote: Thanks for telling about py2exe. Also note that you should build an MSI installer e.g. using InnoSetup after applying py2exe. You could skip the py2exe part and only use InnoSetup to create an MSI. Most likely your client will not care if the executable file is called .py/.pyw/.pyc or .exe. Windows users are generally ignorant to the contents of the Program Files folder. They will not understand what is there and certainly not care what is there. Therefore, the only thing that really matters is to make it easy to install and run the program. That is: 1. Create an MSI that makes it easy to install the software (including runtime and dependencies). 2. Use autorun if you ship a DVD or CD-ROM. The installer should start automatically when the disc is placed in the player. 3. Make sure an icon on the Start Menu launches the program. If you have done that, 99.9% of all clients will be happy. The latter 0.01% is stupid enough to think it matters if the suffix of the executable is called .exe or not. Never mind these morons, just ship an .exe that does nothing except to spawn your Python program and exit. Is there any utility that will help to make it as a .deb or .rpm file (for Linux)? There is a tool called cx_Freeze which is similar to py2exe, except that it works on several platforms, including Linux. You will have to build the .deb or .rpm using other tools afterwards. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python as primary language
On 14 Nov, 01:07, Diez B. Roggisch [EMAIL PROTECTED] wrote: I'm not sure if you mean both above compared to Java - but I won't call Swing/AWT good - eclipse doesn't come with SWT for nothing. Swing vs. SWT is a matter of taste and religion. The main complaint against Swing was how it looked. That has changed. Also, Swing was sluggish ong Windows and SWT was sluggish on X11. And I simply don't understand the networking that works with GUI toolkits. I'm aware of some eventloop-unifications twisted does, but I never really understood the need for that - multi-threading is a problem for GUIs, not for networking. And queues are your friend. Indeed. I think the need for these eventloop unifications stems from Visual Basic. VB programmers never learned to use more than one thread, and they are still struggling to unlearn the bad habits they aquired. -- http://mail.python.org/mailman/listinfo/python-list
Re: Populating a dictionary, fast [SOLVED SOLVED]
Aaron Watters [EMAIL PROTECTED] writes: On Nov 12, 12:46 pm, Michael Bacarella [EMAIL PROTECTED] wrote: It takes about 20 seconds for me. It's possible it's related to int/long unification - try using Python 2.5. If you can't switch to 2.5, try using string keys instead of longs. Yes, this was it. It ran *very* fast on Python v2.5. Um. Is this the take away from this thread? Longs as dictionary keys are bad? Only for older versions of Python? It sounds like Python 2.4 (and previous versions) had a bug when populating large dicts on 64-bit architectures. Someone please summarize. Yes, that would be good. -- http://mail.python.org/mailman/listinfo/python-list
RE: current script path via execfile?
That works well, thank you! - Adam -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabriel Genellina Sent: Wednesday, November 14, 2007 12:34 AM To: python-list@python.org Subject: Re: current script path via execfile? En Tue, 13 Nov 2007 13:42:04 -0300, Adam Pletcher [EMAIL PROTECTED] inc.com escribió: I have an app with an embedded Python interpreter. In that interpreter, I want to use execfile (or something similar) to execute a script from disk. The script needs to somehow acquire the full path to itself, but I can't work out how to do this. Since it's run with execfile in the embedded interpreter, there's no sys.argv to look at. Is there another way to get the current script's full pathname? Set a __file__ variable in the globals that you pass to execfile: fullpath = os.path.abspath(your script file) g = globals().copy() g['__file__'] = fullpath execfile(fullpath, g) From inside the executed script, just inspect __file__ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python as primary language
On 8 Nov, 08:52, Michel Albert [EMAIL PROTECTED] wrote: In our company we are looking for one language to be used as default language. So far Python looks like a good choice (slacking behind Java). A few requirements that the language should be able cope with are: * Database access to Sybase. This seems to be available for python, but the windows-binaries for the library are not available. Self-Compiling them proved to be non-trivial (As always on windows). * Easy GUI creation. Solved using PyQt. * Cross Platform (Linux + Windows). Again, PyQt, solves this * Easy deployment. Solved using py2exe + innosetup * Charting (Histograms, Line charts, bar charts, pie charts, ...) I am currently looking into PyQwt, which looks promising. * Report generation with GUI support reportlab + rml? These are all library issues, and has nothing to do with the language! Besides that, if Visual Studio and .NET is what you want, you can always use IronPython. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Installer or Executable in Python
On Nov 14, 9:17 am, DanielJohnson [EMAIL PROTECTED] wrote: Thanks for telling about py2exe. Is there any utility that will help to make it as a .deb or .rpm file (for Linux)? You'll probably want to take a look at PyInstaller. It can be found here: http://pyinstaller.python-hosting.com/ Mike -- http://mail.python.org/mailman/listinfo/python-list
making a typing speed tester
Referred here from the tutor list. I'm trying to write a program to test someones typing speed and show them their mistakes. However I'm getting weird results when looking for the differences in longer (than 100 chars) strings: import difflib # a tape measure string (just makes it easier to locate a given index) a = '1-3-5-7-9-12-15-18-21-24-27-30-33-36-39-42-45-48-51-54-57-60-63-66-69 -72-75-78-81-84-87-90-93-96-99-103-107-111-115-119-123-127-131-135-139 -143-147-151-155-159-163-167-171-175-179-183-187-191-195--200' # now with a few mistakes b = '1-3-5-7- l-12-15-18-21-24-27-30-33-36-39o42-45-48-51-54-57-60-63-66-69-72-75-78 -81-84-8k-90-93-96-9l-103-107-111-115-119-12b-1v7-131-135-139-143-147- 151-m55-159-163-167-a71-175j179-183-187-191-195--200' s = difflib.SequenceMatcher(None, a ,b) ms = s.get_matching_blocks() print ms [(0, 0, 8), (200, 200, 0)] Have I made a mistake or is this function designed to give up when the input strings get too long? If so what could I use instead to compute the mistakes in a typed text? -- Forwarded message -- From: Evert Rol Hi Tom, Ok, I wasn't on the list last year, but I was a few days ago, so persistence pays off; partly, as I don't have a full answer. I got curious and looked at the source of difflib. There's a method __chain_b() which sets up the b2j variable, which contains the occurrences of characters in string b. So cutting b to 199 characters, it looks like this: b2j= 19 {'a': [168], 'b': [122], 'm': [152], 'k': [86], 'v': [125], '-': [1, 3, 5, 7, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171, 179, 183, 187, 191, 195, 196], 'l': [8, 98], 'o': [39], 'j': [175], '1': [0, 10, 13, 16, 20, 50, 80, 100, 104, 108, 109, 110, 112, 113, 116, 117, 120, 124, 128, 130, 132, 136, 140, 144, 148, 150, 156, 160, 164, 170, 172, 176, 180, 184, 188, 190, 192], '0': [29, 59, 89, 101, 105, 198], '3': [2, 28, 31, 32, 34, 37, 62, 92, 102, 129, 133, 137, 142, 162, 182], '2': [11, 19, 22, 25, 41, 71, 121, 197], '5': [4, 14, 44, 49, 52, 55, 74, 114, 134, 149, 153, 154, 157, 174, 194], '4': [23, 40, 43, 46, 53, 83, 141, 145], '7': [6, 26, 56, 70, 73, 76, 106, 126, 146, 166, 169, 173, 177, 186], '6': [35, 58, 61, 64, 65, 67, 95, 161, 165], '9': [38, 68, 88, 91, 94, 97, 118, 138, 158, 178, 189, 193], '8': [17, 47, 77, 79, 82, 85, 181, 185]} This little detour is because of how b2j is built. Here's a part from the comments of __chain_b(): # Before the tricks described here, __chain_b was by far the most # time-consuming routine in the whole module! If anyone sees # Jim Roskind, thank him again for profile.py -- I never would # have guessed that. And the part of the actual code reads: b = self.b n = len(b) self.b2j = b2j = {} populardict = {} for i, elt in enumerate(b): if elt in b2j: indices = b2j[elt] if n = 200 and len(indices) * 100 n: # --- !! populardict[elt] = 1 del indices[:] else: indices.append(i) else: b2j[elt] = [i] So you're right: it has a stop at the (somewhat arbitrarily) limit of 200 characters. How that exactly works, I don't know (needs more delving into the code), though it looks like there also need to be a lot of indices (len(indices*100n); I guess that's caused in your strings by the dashes, '1's and '0's (that's why I printed the b2j string). If you feel safe enough and on a fast platform, you can probably up that limit (or even put it somewhere as an optional variable in the code, which I would think is generally better). Not sure who the author of the module is (doesn't list in the file itself), but perhaps you can find out and email him/her, to see what can be altered. Hope that helps. Evert -- http://mail.python.org/mailman/listinfo/python-list
Building python packages for the correct architecture on OSX 10.5
Hi fellow python enthusiasts. Having recently acquired a MacBook Pro (Intel Core 2 Duo) which comes with python2.5, I have been installing some modules that I need (PIL, psycopg2, PyXML ...). The problem is that [$python setup.py build] compiles all the binaries to universal files for i386 and ppc32, but not x86_64 or ppc64. It does not appear to be a problem when running scripts from the shell (as python seems to run as a 32 bits problems), but it is a problem from apache2/mod_python as the included apache2 runs as 64 bits processes. This means the modules need to be compiles for at least both i386 and x86_64 in my case. I have been looking at the setup.py files of various modules but I cannot see a suitable way to indicate what architectures I want them compiled for. So far, I have managed by adding the following lines in setup.py just after the Extension class is imported: OrigExtension = Extension def Extension(*args, **kwargs): extra_args = ['-arch', 'ppc', '-arch', 'ppc64', '-arch', 'i386', '-arch', 'x86_64 '] kwargs['extra_compile_args'] = extra_args + kwargs.get('extra_compile_args', []) kwargs['extra_link_args'] = extra_args + kwargs.get('extra_link_args', []) return OrigExtension(*args, **kwargs) Obviously this is a dirty hack, and I would like to know how to do this the right way. How can this be done better? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack
On Nov 14, 12:57 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 13 Nov 2007 19:59:56 -0300, [EMAIL PROTECTED] escribió: working on a smaller example. i could not get pyNode_root invoked yet and PyRun_String(import node\nprint node.root()\n, Py_file_input, exec, g_maindict); The globals argument should contain (at least) a key __builtins__ pointing to the __builtin__ module; else, no builtin functions (like __import__) will be found. PyEval_Globals (you used it somewhere) returns a suitable globals argument. thank you. result is the same however: pyt: main.cpp:17: PyObject* pyNode_root(PyObject*, PyObject*): Assertion `co' failed. Program received signal SIGABRT, Aborted. [Switching to Thread -1218617216 (LWP 4807)] 0x00a54eff in raise () from /lib/tls/libc.so.6 with testimp.py: import node print import test worked def runtest(): print runtest()!!! res = node.root() and the code #undef _POSIX_C_SOURCE #include Python.h #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ #define PyMODINIT_FUNC void #endif PyObject *g_mainmod; PyObject *g_maindict; bool worked = false; static PyObject * pyNode_root(PyObject *self, PyObject *args) { PyObject *dict = PyEval_GetGlobals(); PyObject *co = PyDict_GetItemString(dict, interp); assert(co); assert(PyCObject_Check(co)); void *interp = PyCObject_AsVoidPtr(co); assert(interp); // ... printf(root() worked\n); worked=true; return 0; } static PyMethodDef module_methods[] = { /* no need to create pyNode from python programs {new, pyNode_new, METH_VARARGS, PyDoc_STR(new() - new Node object)}, */ {root,pyNode_root,METH_VARARGS, PyDoc_STR(root('dm') - wrapper for the rootnode)}, {NULL} /* Sentinel */ }; int main() { Py_Initialize(); PyRun_SimpleString(import sys\n sys.path.append('.')\n print ': ',sys.path\n ); g_mainmod = PyImport_AddModule(__main__); assert(g_mainmod); g_maindict = PyModule_GetDict(g_mainmod); assert(g_maindict); Py_INCREF(g_maindict); // it was a borrowed reference PyObject* m = Py_InitModule(node, module_methods); if (m == NULL) return 1; PyObject *eglobal = PyDict_New(); void *handle = (void*)0xdeadc0ed; PyObject *ih = PyCObject_FromVoidPtr(handle, NULL); int st= PyDict_SetItemString(eglobal, interp, ih); assert(!st); PyObject *builtins = PyEval_GetBuiltins(); st= PyDict_SetItemString(eglobal, __builtins__, builtins); assert(!st); PyObject *import = PyImport_ImportModule(testimp); if(!import) { PyErr_Print(); return 3; } Py_INCREF(import); PyModule_AddObject(g_mainmod, testimp, import); PyObject *mScriptHandle= Py_CompileString(testimp.runtest(), comp, Py_eval_input); if(!mScriptHandle) { if (PyErr_Occurred()) { PyErr_Print(); } return 2; } PyObject *res = PyEval_EvalCode((PyCodeObject*)mScriptHandle, eglobal, g_maindict); if (PyErr_Occurred()) { PyErr_Print(); } Py_DECREF(res); assert(worked); } -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop three lists at the same time?
In article [EMAIL PROTECTED], Davy [EMAIL PROTECTED] wrote: Hi all, I have three lists with the same length. Is there any method to loop the three lists without a loop counter? Best regards, Davy Davy, Look at the zip function, http://docs.python.org/lib/built-in-funcs.html Look near the bottom of the page. Example: zip([1,2,3], [4,5,6], [7,8,9]) == [(1, 4, 7), (2, 5, 8), (3, 6, 9)] Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA -- http://mail.python.org/mailman/listinfo/python-list
Re: python - an eggs...
bruce a écrit : hey dietz... (snip) but yeah, you are a jerk (snip) you ignorant slut I don't think that insulting a more than helpful poster is the best way to get some help here in a near future. -- http://mail.python.org/mailman/listinfo/python-list
Re: mpmath puzzle
On Nov 13, 11:55 pm, Dick Moores [EMAIL PROTECTED] wrote: For 1234 ** 10.9, why the wrong result from mpmath.power()? #!/usr/bin/env python #coding=utf-8 from mpmath import * mpf.dps = 32 x = mpf(1234) y = mpf(10.9) print power(x,y) print 4.9583278648155041477415234438717e+33 # from Windows calculator output: 4.9583278648155166864966558721921e+33 4.9583278648155041477415234438717e+33 (Code is also at http://python.pastebin.com/m72a277b8) Thanks, Dick Moores Check this out, better than Windows or mpmath: import gmpy a = 1234 b = gmpy.f2q(10.9) print b 109/10 c = a**b.numer() d = gmpy.root(c,b.denom()) d (mpz(4958327864815504147741523443871702L), 0) -- http://mail.python.org/mailman/listinfo/python-list
Trouble building pywin32 with Visual Studio 2005
Hi everybody... I'm hoping one of you reading this can help me out here. I'm having trouble getting pywin32 to build with Visual Studio 2005. But first, some background. I'm embedding Python in an MFC application. I've manually built Python .lib and .dll files using Visual Studio 2005 from the solution/ project files in the PCBuild8 folder. I've got a totally happy, working Python interpreter in my MFC application. When I use pre-built pywin32 packages, some strange crashes occur. Specifically, if I import win32com.server.register and call the RegisterClasses function, I get a complaint regarding an attempt to free unallocated memory. Now, my theory on this issue is that DLLs like win32api.pyd, which I acquired pre-built, were built with Visual Studio 2003, and they depend on msvcr71.dll. My Python/MFC application, on the other hand, was built with Visual Studio 2005, and is linking with msvcr80.dll. If memory gets allocated through one DLL, and an attempt is made at freeing it in the other DLL, bad things can happen, since the freeing DLL doesn't have any header information on the allocated memory. In order to test this theory (and potentially fix it), I want to re- build the pywin32 stuff using Visual Studio 2005. Now I've never built pywin32, so please excuse any noobness from here on out. I downloaded the pywin32-210.zip source from sourceforge. I tried running setup.py build per the Readme, and I received the following message. Warning - can't find an installed platform SDK error: Python was built with Visual Studio 2003; extensions must be built with a compiler that can generate compatible binaries. Visual Studio 2003 was not found on this system. if you have Cygwin installed, you can try compiling with MingW32, by passing -c mingw32 to setup.py. (Note that I don't have the Platform SDK - This is a Vista machine, so I've got what they now are calling the Windows SDK. If it ends up being a problem, I'll tackle it when it shows up) The logical conclusion to jump to from this error message is that pywin32 is trying to build with VS2005, but it thinks that Python was built with VS2003. Well, in a manner of speaking, that is true. I did have a regular Python installation in C:\Python25, straight from one of the MSI installers. That regular Python installation was undoubtedly compiled with VS2003. I guess what I need to do is find a way to replace the default installation, or certain files within it, with stuff I compiled myself using VS2005. I tried replacing all of the python25[_d].dll and python[w][_d].exe files with those that I built, and that isn't helping. I considered creating a Python installer with the msi.py that is included in the Python Source, but that requires pywin32 (according to the README), and that's what I'm trying to build. I tried going through the setup.py code to find out where it is acquiring this Python was built with Visual Studio 2003 information, but I keep getting lost in the code, so I can't figure out which, if any, file(s) to change/replace. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble building pywin32 with Visual Studio 2005
On Nov 14, 12:41 pm, [EMAIL PROTECTED] wrote: Hi everybody... I'm hoping one of you reading this can help me out here. I'm having trouble getting pywin32 to build with Visual Studio 2005. But first, some background. I'm embedding Python in an MFC application. I've manually built Python .lib and .dll files using Visual Studio 2005 from the solution/ project files in the PCBuild8 folder. I've got a totally happy, working Python interpreter in my MFC application. When I use pre-built pywin32 packages, some strange crashes occur. Specifically, if I import win32com.server.register and call the RegisterClasses function, I get a complaint regarding an attempt to free unallocated memory. Now, my theory on this issue is that DLLs like win32api.pyd, which I acquired pre-built, were built with Visual Studio 2003, and they depend on msvcr71.dll. My Python/MFC application, on the other hand, was built with Visual Studio 2005, and is linking with msvcr80.dll. If memory gets allocated through one DLL, and an attempt is made at freeing it in the other DLL, bad things can happen, since the freeing DLL doesn't have any header information on the allocated memory. In order to test this theory (and potentially fix it), I want to re- build the pywin32 stuff using Visual Studio 2005. Now I've never built pywin32, so please excuse any noobness from here on out. I downloaded the pywin32-210.zip source from sourceforge. I tried running setup.py build per the Readme, and I received the following message. Warning - can't find an installed platform SDK error: Python was built with Visual Studio 2003; extensions must be built with a compiler that can generate compatible binaries. Visual Studio 2003 was not found on this system. if you have Cygwin installed, you can try compiling with MingW32, by passing -c mingw32 to setup.py. (Note that I don't have the Platform SDK - This is a Vista machine, so I've got what they now are calling the Windows SDK. If it ends up being a problem, I'll tackle it when it shows up) The logical conclusion to jump to from this error message is that pywin32 is trying to build with VS2005, but it thinks that Python was built with VS2003. Well, in a manner of speaking, that is true. I did have a regular Python installation in C:\Python25, straight from one of the MSI installers. That regular Python installation was undoubtedly compiled with VS2003. I guess what I need to do is find a way to replace the default installation, or certain files within it, with stuff I compiled myself using VS2005. I tried replacing all of the python25[_d].dll and python[w][_d].exe files with those that I built, and that isn't helping. I considered creating a Python installer with the msi.py that is included in the Python Source, but that requires pywin32 (according to the README), and that's what I'm trying to build. I tried going through the setup.py code to find out where it is acquiring this Python was built with Visual Studio 2003 information, but I keep getting lost in the code, so I can't figure out which, if any, file(s) to change/replace. Probably the easiest way to fix this is to use MinGW or VS2003 or recompile your MFC using MingW against what amounts to VS2003. I've heard from multiple sources that trying to compile impure Python extensions against anything other than the original compiler can (and does) lead to screwy issues. Of course, there is the theory that you could compile your own Python using VS2005 and then it should just work...but from what I've heard, even the Python developers are skipping VS2005 and heading straight to VS2008. Not very helpful, I know. You may get better help from the people on the PyWin32 user's group. See http://mail.python.org/mailman/listinfo/python-win32 Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: webbrowser.open still gives problem with file://
Gabriel Genellina [EMAIL PROTECTED] writes: En Mon, 12 Nov 2007 16:18:06 -0300, krishnakant Mane [EMAIL PROTECTED] escribió: some days bac I posted a problem about webbrowser.open() not opening the file on the local machine. I get a few responses and I tryed working it out. I also refered to the cookbook example posted on that thread. I still can't figure out why webbrowser.open(file:///home/krishna/documents/tut.html) does not open the file. as I mentioned earlier the url in the addressbar of mozilla firefox 3 alpha is file:///home/krishna//home/krishna/documents/tut.html which is indeed wrong. I can think of two alternatives: 1) omit the file: protocol, and just use the absolute file path, like webbrowser.open(/home/krishna/documents/tut.html) 2) use this recipe http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347810 which lets you display content inside a browser window without requiring a temporary file. -- Gabriel Genellina You didn't say which platform you're on. I found that on older Mac OS X systems that one needs to give file://localhost/path instead of file:///path but the localhost version didn't always work on other platforms. The other thing you need to do is to use Python 2.5's version of webbrowser.py instead of the earlier ones. It's easy to backport and works *much* better. Greg Couch UCSF Computer Graphics Lab -- http://mail.python.org/mailman/listinfo/python-list
Feeding data into MySQLdb LOAD DATA from Python
Is it possible to feed data into a LOAD DATA command in MySQL without writing out the data to a file? It's possible to do this using the MySQL command line and a UNIX FIFO, but that's kind of clunky. I have to load a few gigabytes of data, and using INSERT takes a whole day for each update. And can this be done portably across UNIX and Windows? Thanks. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a good Python environment
Well, I am recent Windows escapee, and was dismayed by lack of Pyscripter for Linux. Hold on... there is hope! Pyscripter works great using WINE. search http://groups.google.com/group/PyScripter?hl=en for Linux Enjoy! Paul Rudin wrote: jwelby [EMAIL PROTECTED] writes: This is a fair question. I didn't phrase my post too well. I find PyScripter does pretty much everything I need in terms of doing actual development for Python. My use of 'lightweight' is by no means a criticism of PyScripter - it's more of a compliment, as it refers to the relatively modest demands that it makes on my system compared with Eclipse, which can be hog. The main reason I have used Eclipse for larger, team based, projects is for the source control plug-ins. Eclipse has plug-in support for cvs and svn. PyScripter may have this too - perhaps I've missed it. (I'm away from my Windows box at the moment, otherwise I would check). Of course, there are other ways to implement source control without it needing to be integrated in the IDE, so even this need not put off anyone who wants to use PyScripter with source control. Summary - unless you need the added flexibility offered by Eclipse plug-ins, PyScripter is a great tool for developing with Python on Windows. I'm not sure if you count emacs as lightweight but it's certainly less resource hungry than eclipse/pydev, and does have integrated cvs/svn functionality. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble building pywin32 with Visual Studio 2005
Now, my theory on this issue is that DLLs like win32api.pyd, which I acquired pre-built, were built with Visual Studio 2003, and they depend on msvcr71.dll. My Python/MFC application, on the other hand, was built with Visual Studio 2005, and is linking with msvcr80.dll. If memory gets allocated through one DLL, and an attempt is made at freeing it in the other DLL, bad things can happen, since the freeing DLL doesn't have any header information on the allocated memory. That is the likely cause, yes. In order to test this theory (and potentially fix it), I want to re- build the pywin32 stuff using Visual Studio 2005. That might not be sufficient. You have to rebuild Python itself as well. The logical conclusion to jump to from this error message is that pywin32 is trying to build with VS2005, but it thinks that Python was built with VS2003. Well, in a manner of speaking, that is true. I did have a regular Python installation in C:\Python25, straight from one of the MSI installers. That regular Python installation was undoubtedly compiled with VS2003. I guess what I need to do is find a way to replace the default installation, or certain files within it, with stuff I compiled myself using VS2005. I tried replacing all of the python25[_d].dll and python[w][_d].exe files with those that I built, and that isn't helping. That is likely to happen. distutils doesn't actually *check* what CRT or VC version Python was built with, instead, it *knows*, hardcoded. I tried going through the setup.py code to find out where it is acquiring this Python was built with Visual Studio 2003 information, but I keep getting lost in the code, so I can't figure out which, if any, file(s) to change/replace. If you know what you are doing, you can override the logic of distutils. Set up an SDK environment (with LIBRARY, INCLUDE and everything), then also set the MSSdk environment variable (which should get set if you use the standard environment batch file from the SDK), and then also set DISTUTILS_USE_SDK. Then distutils will trust that the environment you set up works correctly, and will use it without further questioning. HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list
Fender Guitars
Best off http://fender-guitars-review.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
SPAM
-- http://mail.python.org/mailman/listinfo/python-list
Re: making a typing speed tester
On Nov 14, 11:56 am, [EMAIL PROTECTED] wrote: Referred here from the tutor list. I'm trying to write a program to test someones typing speed and show them their mistakes. However I'm getting weird results when looking for the differences in longer (than 100 chars) strings: import difflib # a tape measure string (just makes it easier to locate a given index) a = '1-3-5-7-9-12-15-18-21-24-27-30-33-36-39-42-45-48-51-54-57-60-63-66-69 -72-75-78-81-84-87-90-93-96-99-103-107-111-115-119-123-127-131-135-139 -143-147-151-155-159-163-167-171-175-179-183-187-191-195--200' # now with a few mistakes b = '1-3-5-7- l-12-15-18-21-24-27-30-33-36-39o42-45-48-51-54-57-60-63-66-69-72-75-78 -81-84-8k-90-93-96-9l-103-107-111-115-119-12b-1v7-131-135-139-143-147- 151-m55-159-163-167-a71-175j179-183-187-191-195--200' s = difflib.SequenceMatcher(None, a ,b) ms = s.get_matching_blocks() print ms [(0, 0, 8), (200, 200, 0)] Have I made a mistake or is this function designed to give up when the input strings get too long? If so what could I use instead to compute the mistakes in a typed text? -- Forwarded message -- From: Evert Rol Hi Tom, Ok, I wasn't on the list last year, but I was a few days ago, so persistence pays off; partly, as I don't have a full answer. I got curious and looked at the source of difflib. There's a method __chain_b() which sets up the b2j variable, which contains the occurrences of characters in string b. So cutting b to 199 characters, it looks like this: b2j= 19 {'a': [168], 'b': [122], 'm': [152], 'k': [86], 'v': [125], '-': [1, 3, 5, 7, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171, 179, 183, 187, 191, 195, 196], 'l': [8, 98], 'o': [39], 'j': [175], '1': [0, 10, 13, 16, 20, 50, 80, 100, 104, 108, 109, 110, 112, 113, 116, 117, 120, 124, 128, 130, 132, 136, 140, 144, 148, 150, 156, 160, 164, 170, 172, 176, 180, 184, 188, 190, 192], '0': [29, 59, 89, 101, 105, 198], '3': [2, 28, 31, 32, 34, 37, 62, 92, 102, 129, 133, 137, 142, 162, 182], '2': [11, 19, 22, 25, 41, 71, 121, 197], '5': [4, 14, 44, 49, 52, 55, 74, 114, 134, 149, 153, 154, 157, 174, 194], '4': [23, 40, 43, 46, 53, 83, 141, 145], '7': [6, 26, 56, 70, 73, 76, 106, 126, 146, 166, 169, 173, 177, 186], '6': [35, 58, 61, 64, 65, 67, 95, 161, 165], '9': [38, 68, 88, 91, 94, 97, 118, 138, 158, 178, 189, 193], '8': [17, 47, 77, 79, 82, 85, 181, 185]} This little detour is because of how b2j is built. Here's a part from the comments of __chain_b(): # Before the tricks described here, __chain_b was by far the most # time-consuming routine in the whole module! If anyone sees # Jim Roskind, thank him again for profile.py -- I never would # have guessed that. And the part of the actual code reads: b = self.b n = len(b) self.b2j = b2j = {} populardict = {} for i, elt in enumerate(b): if elt in b2j: indices = b2j[elt] if n = 200 and len(indices) * 100 n: # --- !! populardict[elt] = 1 del indices[:] else: indices.append(i) else: b2j[elt] = [i] So you're right: it has a stop at the (somewhat arbitrarily) limit of 200 characters. How that exactly works, I don't know (needs more delving into the code), though it looks like there also need to be a lot of indices (len(indices*100n); I guess that's caused in your strings by the dashes, '1's and '0's (that's why I printed the b2j string). If you feel safe enough and on a fast platform, you can probably up that limit (or even put it somewhere as an optional variable in the code, which I would think is generally better). Not sure who the author of the module is (doesn't list in the file itself), but perhaps you can find out and email him/her, to see what can be altered. Hope that helps. Evert I would use the time module to time the user. Then you should be able to compare the original string with the user inputted string using cmp. code # untested start = time.time() print 'some complicated long string' # you should use a GUI toolkit's textbox rather than # using a variable user_string = raw_input('Please type the string above as quickly and accurately as you can:\n\n') end = time.time() print 'amount of time to complete: %s seconds' % (end-start) # do the comparison here # which I am not sure how to do right now /code See the following for ideas on comparing similar strings/iterables: http://www.velocityreviews.com/forums/t345107-comparing-2-similar-strings.html Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Building python packages for the correct architecture on OSX 10.5
Arnaud Delobelle wrote: Hi fellow python enthusiasts. Having recently acquired a MacBook Pro (Intel Core 2 Duo) which comes with python2.5, I have been installing some modules that I need (PIL, psycopg2, PyXML ...). The problem is that [$python setup.py build] compiles all the binaries to universal files for i386 and ppc32, but not x86_64 or ppc64. It does not appear to be a problem when running scripts from the shell (as python seems to run as a 32 bits problems), but it is a problem from apache2/mod_python as the included apache2 runs as 64 bits processes. This means the modules need to be compiles for at least both i386 and x86_64 in my case. I have been looking at the setup.py files of various modules but I cannot see a suitable way to indicate what architectures I want them compiled for. So far, I have managed by adding the following lines in setup.py just after the Extension class is imported: OrigExtension = Extension def Extension(*args, **kwargs): extra_args = ['-arch', 'ppc', '-arch', 'ppc64', '-arch', 'i386', '-arch', 'x86_64 '] kwargs['extra_compile_args'] = extra_args + kwargs.get('extra_compile_args', []) kwargs['extra_link_args'] = extra_args + kwargs.get('extra_link_args', []) return OrigExtension(*args, **kwargs) Obviously this is a dirty hack, and I would like to know how to do this the right way. How can this be done better? -- Arnaud You may want to post this on the MacPython list--there are plenty of experts there on building Python mudles for OS X. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: mpmath puzzle
On Nov 14, 3:20 am, Fredrik Johansson [EMAIL PROTECTED] wrote: Dick Moores wrote: For 1234 ** 10.9, why the wrong result from mpmath.power()? #!/usr/bin/env python #coding=utf-8 from mpmath import * mpf.dps = 32 x = mpf(1234) y = mpf(10.9) print power(x,y) print 4.9583278648155041477415234438717e+33 # from Windows calculator output: 4.9583278648155166864966558721921e+33 4.9583278648155041477415234438717e+33 (Code is also at http://python.pastebin.com/m72a277b8) Thanks, Dick Moores Hi, When you create y, you first create an inexact Python float whose value is actually 10.900355... and then pass it to mpf, which just copies that value along with the error. To create an accurate representation of a fractional number (integers are safe), pass a string instead: from mpmath import * mpf.dps = 32 x = mpf(1234) y = mpf('10.9') print power(x,y) 4.9583278648155041477415234438719e+33 The last printed digit is wrong, which is to be expected in binary arithmetic since 10.9 still cannot be represented exactly (with mpf.dps = 32, the error is about 5e-033); computing a power amplifies that error. You can temporarily increase the precision by a couple of digits during calculations and then reduce it before printing the final value if you want all digits to be right. I should update the mpmath documentation to be much clearer about all this. Fredrik You could also use the Decimal module to keep things accurate. Some people like numpy or scipy for the more complex math problems they do. Mike -- http://mail.python.org/mailman/listinfo/python-list
daemon under windows
I wrote a simple UNIX daemon (using 2 forks) which does a simple job: it executes a function, waits for some time, and then executes it again. Now I'd like to port that to Windows. How do I create daemon on Windows (since I can't use fork)? -- Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
John Bean [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Wed, 14 Nov 2007 11:04:35 -0800, just bob [EMAIL PROTECTED] wrote: Your SPAM appears to be non-existent. Vapourware. Not real. Shame, I fancied a Spam fritter. The guy gets Google dollars when people view the site or click on links, me thinks. It's spam. -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
On Wed, 14 Nov 2007 11:04:35 -0800, just bob [EMAIL PROTECTED] wrote: Your SPAM appears to be non-existent. Vapourware. Not real. Shame, I fancied a Spam fritter. -- John Bean -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
On Nov 14, 7:42 am, Scott David Daniels [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: my objective is to replicate a section of los angeles using python, and program the street lights and cars and whatnot. Should I be looking towards 3D to do this? so here is MY question: how would you replicate a street intersection in python? and furthermore, how would you do you have the cars move up and down those streets. my question to YOU is: can you point me in the right direction? I will search on my own, but I would greatly appreciate any help :) If you do want to do this in 3-D, try out VPython. More than any other 3-D system I've seen, it allows you to concentrate more on your problem, and let it handle most of the 3-D rendering calculations as you are learning how to use it. -Scott David Daniels [EMAIL PROTECTED] Although, i am quite the python noob, pygame would be the way to go -- http://mail.python.org/mailman/listinfo/python-list
Re: Building python packages for the correct architecture on OSX 10.5
On Nov 14, 7:40 pm, Martin v. Löwis [EMAIL PROTECTED] wrote: This means the modules need to be compiles for at least both i386 and x86_64 in my case. Building Python in 64-bit mode as a universal (fat) binary is not supported in Python 2.5, period. So any solution you come necessarily has to be a work-around. The only solution I can see is to make a plain, non-fat installation of Python in 64-bit mode, and then use that installation to build 64-bit extension modules. def Extension(*args, **kwargs): extra_args = ['-arch', 'ppc', '-arch', 'ppc64', '-arch', 'i386', '-arch', 'x86_64 '] This cannot really work, for two reasons: a) even if your extension module becomes x86_64 with that mechanism, the Python interpreter itself (i.e. the Python framework) will be purely 32-bit code. So it should not link correctly. My machine disagrees: marigold:~ arno$ file /System/Library/Frameworks/Python.framework/ Python /System/Library/Frameworks/Python.framework/Python: Mach-O universal binary with 4 architectures /System/Library/Frameworks/Python.framework/Python (for architecture ppc7400): Mach-O dynamically linked shared library ppc /System/Library/Frameworks/Python.framework/Python (for architecture ppc64): Mach-O 64-bit dynamically linked shared library ppc64 /System/Library/Frameworks/Python.framework/Python (for architecture i386): Mach-O dynamically linked shared library i386 /System/Library/Frameworks/Python.framework/Python (for architecture x86_64):Mach-O 64-bit dynamically linked shared library x86_64 b) During configure, Python generates a pyconfig.h which has the computed sizes of data types (such as int, long, size_t). It only has a single such file, and the file is generated only during configure. Therefore, the data in it cannot work both for 32-bit and 64-bit architectures. When you compile for a 64-bit target using the 32-bit pyconfig.h, the code may work incorrectly (provided it makes use of the computed values somewhere) (*) (*) It is surprising that pyconfig.h actually works for both big-endian (ppc) and little-endian (i386) systems, even though it computes the endianness during configure only once. This is due to an OSX-specific hack in pyconfig.h, which hides the definition of the computed endianness value, and uses the value that the compiler provides as a macro instead. Thanks for the details. I have had no problems with the modules I have compiled so far, they have been working in 32 and 64 bits. Maybe I was just lucky? I'll have to look into this more, then. Python on OSX 10.5 has been a challenge so far :( Regards, Martin Thanks -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Building python packages for the correct architecture on OSX 10.5
This means the modules need to be compiles for at least both i386 and x86_64 in my case. Building Python in 64-bit mode as a universal (fat) binary is not supported in Python 2.5, period. So any solution you come necessarily has to be a work-around. The only solution I can see is to make a plain, non-fat installation of Python in 64-bit mode, and then use that installation to build 64-bit extension modules. def Extension(*args, **kwargs): extra_args = ['-arch', 'ppc', '-arch', 'ppc64', '-arch', 'i386', '-arch', 'x86_64 '] This cannot really work, for two reasons: a) even if your extension module becomes x86_64 with that mechanism, the Python interpreter itself (i.e. the Python framework) will be purely 32-bit code. So it should not link correctly. b) During configure, Python generates a pyconfig.h which has the computed sizes of data types (such as int, long, size_t). It only has a single such file, and the file is generated only during configure. Therefore, the data in it cannot work both for 32-bit and 64-bit architectures. When you compile for a 64-bit target using the 32-bit pyconfig.h, the code may work incorrectly (provided it makes use of the computed values somewhere) (*) (*) It is surprising that pyconfig.h actually works for both big-endian (ppc) and little-endian (i386) systems, even though it computes the endianness during configure only once. This is due to an OSX-specific hack in pyconfig.h, which hides the definition of the computed endianness value, and uses the value that the compiler provides as a macro instead. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: general information
yyyyyyyyyyGyUykypy{yyyy¢y ¥yµyºy½yÂyÔyäyçyêyêyzzz)z,zz»z¾zÃzÆz{ {||g|l|l|l|l|l|r|·|·|Â|Ø| Û|}ë '· ¢¨ÊÏÔU,,, ,¡,¤ ,½,À,Å,Ë, F³¶¶¶ÏÏÔõùü$,,',,l,,g...k...n... ... ...£...3CFILUc||'·ÓÓ X [^dggjmru°½!Ñû ®®ääíôô÷ DGGTW_ill ¢§§³¶è i am trying with notepad but there ara similar this -- http://mail.python.org/mailman/listinfo/python-list
Re: mpmath puzzle
On Nov 14, 2007 8:21 PM, [EMAIL PROTECTED] wrote: You could also use the Decimal module to keep things accurate. Some people like numpy or scipy for the more complex math problems they do. Unlike mpmath, the decimal module doesn't support non-integer powers (except for square roots), and nor does gmpy (though you can do them indirectly as mensanator showed earlier in the thread). And numpy / scipy don't support arbitrary-precision floats. Now, if you really want exact arithmetic, SymPy is the winner: from sympy import * x = 1234 ** Rational('10.9') x 8187505353567209228244052427776*1234**(9/10) x / 1234**10 1234**(9/10) x.evalf() 4.958327864815504147741523444E+33 Fredrik -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
just bob wrote: John Bean [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Wed, 14 Nov 2007 11:04:35 -0800, just bob [EMAIL PROTECTED] wrote: Your SPAM appears to be non-existent. Vapourware. Not real. Shame, I fancied a Spam fritter. The guy gets Google dollars when people view the site or click on links, me thinks. It's spam. Yes, but it's not SPAM. SPAM is a registered trademark of Hormel Foods Corporation for a canned pork product. Spam is unwanted messages or email. -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Re: daemon under windows
I wrote a simple UNIX daemon (using 2 forks) which does a simple job: it executes a function, waits for some time, and then executes it again. Now I'd like to port that to Windows. How do I create daemon on Windows (since I can't use fork)? On Windows, you develop services. They are under the control of the service control manager, and can be managed through the services control panel application, and the net start/stop command line utility. In that architecture, you don't need fork to start a background process, but instead, you register your service with the system, and it will get started automatically (if you wish so) or manually (through the management interface). You can use the Win32 extensions to create services, with the win32serviceutil module. HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble building pywin32 with Visual Studio 2005
In order to test this theory (and potentially fix it), I want to re- build the pywin32 stuff using Visual Studio 2005. That might not be sufficient. You have to rebuild Python itself as well. Either I misunderstand, or you do. If it wasn't clear, I have already rebuilt Python using Visual Studio 2005. The logical conclusion to jump to from this error message is that pywin32 is trying to build with VS2005, but it thinks that Python was built with VS2003. Well, in a manner of speaking, that is true. I did have a regular Python installation in C:\Python25, straight from one of the MSI installers. That regular Python installation was undoubtedly compiled with VS2003. I guess what I need to do is find a way to replace the default installation, or certain files within it, with stuff I compiled myself using VS2005. I tried replacing all of the python25[_d].dll and python[w][_d].exe files with those that I built, and that isn't helping. That is likely to happen. distutils doesn't actually *check* what CRT or VC version Python was built with, instead, it *knows*, hardcoded. Oof. Fair enough. If you know what you are doing, you can override the logic of distutils. Set up an SDK environment (with LIBRARY, INCLUDE and everything), then also set the MSSdk environment variable (which should get set if you use the standard environment batch file from the SDK), and then also set DISTUTILS_USE_SDK. Then distutils will trust that the environment you set up works correctly, and will use it without further questioning. I'll see if I can get that working. During my internet searches, I came across a mail/post/blog or two indicating DISTUTILS_USE_SDK does not work in Visual Studio 2005. I'll see what I can do. -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
You can do a little spamming of your own here... http://help.blogger.com/?page=troubleshooter.csproblem=ItemType=spamcontact_type=SpamSubmit=Continue Just enter the offending blogspot URL and hopefully they'll sort this guy out. Steve just bob [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: cmp and sorting non-symmetric types
On Nov 13, 1:18 pm, Carl Banks [EMAIL PROTECTED] wrote: The right solution is to use comparison operators only for ordered comparisons, not for subset and superset testing. The whole point of the rich comparisons PEP was to be able to override the operators for other purposes. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: cmp and sorting non-symmetric types
On Nov 13, 2:54 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: Carl Banks [EMAIL PROTECTED] resurrecting the __cmp__ operator. I didnd't realize __cmp__ was going. Are we really supposed to implement all the rich comparison methods to code an ordered class? Or is there some kind of library superclass we can inherit from that implements something like __cmp__? What about making __key__ ? IIRC, you need only define __le__ and __eq__ and the rest get defined using a mixin class. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Building python packages for the correct architecture on OSX 10.5
a) even if your extension module becomes x86_64 with that mechanism, the Python interpreter itself (i.e. the Python framework) will be purely 32-bit code. So it should not link correctly. My machine disagrees: I see. I guess Apple has implemented that somehow; the official Python release does not support such an operation. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
SoCal Youth Python User Group
best name I could come up with, but I'm open to suggestions :) current site: http://sypug.blogspot.com/ irc: irc://irc.p2p-network.net/sypug I could only find one other SoCal python user group, and the members seemed more adult, job oriented (one of the guys had worked at Disney already..). Don't get me wrong -- power to the guys making moves in the python world! -- but I don't think I'd fit in. I've been playing with Python for a couple months now, and have a few programs written. The latest is PyGq. I know a bit, but I definitely wouldn't be able to keep up with those other guys. So, this is a user group for us young Pythonistas :). If anyone is interested in joining this group, please let me know via a comment, this group, or show up in the IRC channel (listed below). We can set up a website (I can host it), and a mailing list :). -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble building pywin32 with Visual Studio 2005
Either I misunderstand, or you do. If it wasn't clear, I have already rebuilt Python using Visual Studio 2005. I see. I must have misunderstood then - if you already rebuilt Python itself, all is fine. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
ANN: Chandler 0.7.2
The Chandler Project is pleased to announce the 0.7.2 release of Chandler Desktop! Download links, information on mailing lists, and how to get the sources are available from the homepage[1]. The 0.7.2 release is the second in a series of quick, time-based releases since Chandler Preview 0.7.0.1 intended to respond to the feedback we received from 0.7.0.1 and continue to receive from these quick releases. 0.7.2 fixes over 80 bugs and includes some major improvements: * Dashboard: Following up on users logged bugs and remarks, we improved the Dashboard display of the Who column and made it work more in sync with the other columns. We also changed how the triage status cycles. * Support for Ubuntu Gutsy Gibbon: We’re now using wxPython 2.8.6.0 which fixes crashes reported by several users of Ubuntu Gutsy Gibbon. This fixes Bug #10906. * New version of PyLucene: Chandler’s PyLucene is not using gcj anymore, but rather our own home brew jcc. This fixes Bug #10803 among others. * Auto fill for common email providers: Account settings now fill automatically for the most common email providers. Just type your email address and if the provider is recognized, most of the settings will be filled out automatically. * Chandler-on-a-stick, a.k.a. “Portable Chandler”: Though not built automatically and available for download, it is now possible to build a relocatable distribution of Chandler that can be stored on, and run from a removable device such as a USB memory stick or an iPod. * Getting ready for l10n (localization): Chandler Desktop 0.7.2 is not completely ready for localizers yet (still a handful of bugs to fix; this will happen in 0.7.3) but we solved a significant set of issues that will make the localization process much easier. For a more complete list of bug fixes and known issues, please visit our Release Notes[2]. Thanks for your interest in Chandler Desktop! [1] http://chandlerproject.org/ [2] http://chandlerproject.org/Projects/ReleaseNotes -- http://mail.python.org/mailman/listinfo/python-list
Re: mpmath puzzle
On Nov 14, 2:45 pm, Fredrik Johansson [EMAIL PROTECTED] wrote: Unlike mpmath, the decimal module doesn't support non-integer powers (except for square roots), and nor does gmpy (though you can do them indirectly as mensanator showed earlier in the thread). And numpy / scipy don't support arbitrary-precision floats. But in Python 2.6 (and in the current trunk), it will: Python 2.6a0 (trunk:58930, Nov 10 2007, 20:54:42) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type help, copyright, credits or license for more information. from decimal import Decimal, getcontext getcontext().prec = 32 1234**Decimal(10.9) Decimal(4.9583278648155041477415234438717E+33) Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python To Change The World :)
On Nov 14, 5:38 am, Sells, Fred [EMAIL PROTECTED] wrote: It sounds as if this project is a major task based on your current level of experience. That being said, all we pythonistas encourage and support anyone who is trying to learn/apply python. Break the problem into 2 parts: --simulation math of what you're trying to do --cool visual display (2D is sufficient) to make it interesting and so others can grasp what you did Then the math drives the display, but you can build and test the math using text output. pygame and pysim are good candidates. There is alsowww.vpython.org. Make sure you find some tutorial on object oriented programming OOP because that's the way to build this critter. I'm assuming you have a fairly powerful PC, if so you need a decent development environment. google for python IDE or check at python.org. I use Eclipse + PyDev (both free) although there is a wide difference of opinion on IDE's. Remember to eat the elephant one byte at a time. i.e. small steps. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Ant Sent: Wednesday, November 14, 2007 6:48 AM To: [EMAIL PROTECTED] Subject: Re: Using Python To Change The World :) On Nov 14, 3:09 am, [EMAIL PROTECTED] wrote: ... so here is MY question: how would you replicate a street intersection in python? and furthermore, how would you do you have the cars move up and down those streets. I've never used it, but I'd have thought that pygame would satisfy the graphical side of things. -- Ant -- http://mail.python.org/mailman/listinfo/python-list ah, great advice. thanks very much. thank you to everyone for helping :) -- http://mail.python.org/mailman/listinfo/python-list
Re: private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack
En Wed, 14 Nov 2007 15:08:42 -0300, [EMAIL PROTECTED] escribió: thank you. result is the same however: pyt: main.cpp:17: PyObject* pyNode_root(PyObject*, PyObject*): Assertion `co' failed. Well, is the same in the sense that the code still doesn't do what you want... But the previous error is gone. (Now I regret having said the reason it didn't work before: you took my words too literally). I suggest you first try to write the program in pure Python, even with a dummy Node. From what I can understand of what you are doing, it appears you don't fully understand how import works, how modules work, and namespaces in Python. The C API exposes the same concepts so it's easier when one knows how to do things in pure Python first. Right now you have two problems: what to do, and how to write that using the API. First try to solve the what, in Python, and only later move to the second stage. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
dependency algorithm
Hi, Consider tuples of the above numbers in the form: (a,b) Suppose this relation means: a depends on b Given a list of tuples, I would like an algorithm to return the proper ordering of the elements...and if the ordering has a loop (which in this case, prevents a proper ordering), then it should return None. For example, [(1,2),(2,3),(3,4)] should give: [4,3,2,1] [(3,2),(1,3),(2,4)] should give: [4,2,3,1] [(1,4),(4,3),(2,3)] should give: [3,2,4,1] or [3,4,2,1] (which one doesn't matter) [(1,2), (2,3), (3,2)] should give None, since it cannot be resolved I'm sure this is a standard problem (mro, resolving inheritance?), but this is a simplified case since each element can directly depend on only one other element (thus, multiple inheritance is not allowed)...but many elements can depend on the same element (no limit on the number of classes which subclass another class). A quick hack is simple enough to code, but I am wondering if there are 'standard' ways of performing this task in this limited scope. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
Marc Espie schrieb: Apart from the fact that Knuth wrote a book series that is still THE definitive series on computer algorithms I don't wish to diminish Knuth's work, but it's definitely not timeless. For an alternative, see Sedgewick's Algorithms in C/Pascal/whatever. Not as rigorous about proving the properties of algorithms, but the selection of algorithms is more modern, and the presentation is palatable (instead of the assembly/flowchart mix that Knuth is so fond of). There are other algorithm collections. The largest one is the Internet itself. A search engine or Wikipedia would be my first stop when looking for an algorithm. (Agreeing with the rest.) Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
Re: cross-platform c questions
En Wed, 14 Nov 2007 05:36:04 -0300, Martin v. Löwis [EMAIL PROTECTED] escribió: When writing a python c extension for needs to be compiled for Windows, Linux, and the Mac, what cross-platform differences need to be accounted for?# Not functions, no, but macros and typedefs. For example, there is now a typedef Py_ssize_t that you should use if you measure the number of bytes (or, more generally, things in a collection). Is there any rules/criteria to decide when to use Py_ssize_t, int, or long? I've seen them somewhat mixed and don't know when exactly to use Py_ssize_t. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedded Python - Blocking Python Function
En Wed, 14 Nov 2007 20:02:42 -0300, [EMAIL PROTECTED] escribió: The problem is that the function Main in the Python script can take up to 60 seconds to execute. How can I terminate this thread (and therefore the Main function in python) cleanly from the primary thread of my application? Not forcibly - you need some cooperation from the Main function. Maybe setting a global variable that Main checks periodically. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: dependency algorithm
Tom Jones wrote: Hi, Consider tuples of the above numbers in the form: (a,b) Suppose this relation means: a depends on b Given a list of tuples, I would like an algorithm to return the proper ordering of the elements...and if the ordering has a loop (which in this case, prevents a proper ordering), then it should return None. You want what's called a topological sort, see: http://blog.vrplumber.com/scripts/toposort.py for a pair of old algorithms from Tim Peters and I. I believe we raise errors on loops, but that's pretty trivial to change. Have fun, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Custom Tkinter scrollbar
I want to create a custom scrollbar using particular images, which will then be placed on a canvas to control another window on the canvas. Right now I am inheriting from scrollbar, but I do the movement with custom functions. When I create it and put in into the canvas with canvas.create_window a standard scrollbar shows in the correct spot and my custom one is outside of the canvas. All I have right now is something that moves like a scrollbar but has no effect on other objects. Can anyone give me some advice or point me to a guide for this? Is it even possible? Can I create a widget that mimics a scrollbar, or would that be more difficult? I have been unable to find anything online and would appreciate any help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Populating a dictionary, fast [SOLVED SOLVED]
On Wed, 14 Nov 2007 18:16:25 +0100, Hrvoje Niksic wrote: Aaron Watters [EMAIL PROTECTED] writes: On Nov 12, 12:46 pm, Michael Bacarella [EMAIL PROTECTED] wrote: It takes about 20 seconds for me. It's possible it's related to int/long unification - try using Python 2.5. If you can't switch to 2.5, try using string keys instead of longs. Yes, this was it. It ran *very* fast on Python v2.5. Um. Is this the take away from this thread? Longs as dictionary keys are bad? Only for older versions of Python? It sounds like Python 2.4 (and previous versions) had a bug when populating large dicts on 64-bit architectures. No, I found very similar behaviour with Python 2.5. Someone please summarize. Yes, that would be good. On systems with multiple CPUs or 64-bit systems, or both, creating and/or deleting a multi-megabyte dictionary in recent versions of Python (2.3, 2.4, 2.5 at least) takes a LONG time, of the order of 30+ minutes, compared to seconds if the system only has a single CPU. Turning garbage collection off doesn't help. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Feeding data into MySQLdb LOAD DATA from Python
John Nagle wrote: Is it possible to feed data into a LOAD DATA command in MySQL without writing out the data to a file? It's possible to do this using the MySQL command line and a UNIX FIFO, but that's kind of clunky. I have to load a few gigabytes of data, and using INSERT takes a whole day for each update. And can this be done portably across UNIX and Windows? Thanks. John Nagle Where is the data coming from? Two suggestions: 1) There is a MySQL option to not commit every insert, sorry I can't remember what it is, but it REALLY speeds things up (especially if you have lots of keys). Or drop all the keys load, the data, and recreate the keys. Sounds odd, but it is a recommended method. 2) If data is coming from a file now, use LOAD DATA directly, don't go through Python. You may even find writing to file and then loading it is very fast. I recommend tab delimited as that seems to work well. -Larry -- http://mail.python.org/mailman/listinfo/python-list