Re: Threading: Method trigger after thred finished
On Oct 20, 5:55 am, Steven D'Aprano wrote: > On Wed, 19 Oct 2011 13:14:21 -0700, markus.mj wrote: > > Hi, > > > I am looking for help with following problem. I scripted threaded > > database query, with session open per thread, and queries delivered > > through queue. Every open DB session must be closed with "abort" or > > "commit", however on which event should I trigger the DB disconnect? > > Ideally it would close the DB as the thread class gets deconstructed, > > but "__del__" does never fire. > > The __del__ destructor method is not guaranteed to be called in a timely > fashion, if at all. My *guess* is that the main Python environment is > shutting down when the daemon threads get killed, and the __del__ method > never gets a chance to run. > > To be honest, I'm not sure why you are using daemon threads. It seems to > me that blocking until the queue is empty makes the use of daemon threads > pointless, but I'm not experienced enough with threads to be sure. > > The usual advice is to explicitly call destructors rather than rely on > automatic __del__ methods. Given that, this works for me: > > import threading > import Queue > import time > > # Fill the queue. > queue = Queue.Queue() > queries = ["query"+str(i) for i in range(10)] > for query in queries: > queue.put(query) > > # Make consumer threads. > class ThreadSql(threading.Thread): > def __init__(self, queue): > threading.Thread.__init__(self) > self.queue = queue > # Open database connection instance > self.session = "+++connection+++" # DbConnect() > self._open = True > > def run(self): > while self._open: > # Grab a query from queue. > query = self.queue.get() > # And process it. > print self, query > time.sleep(1) > # Mark the queue job as done. > self.queue.task_done() > > def close(self): > print "Closing", self > # self.session.Disconnect() > self._open = False > > threads = [ThreadSql(queue) for _ in range(4)] > for t in threads: > t.setDaemon(True) > t.start() > > # Wait until the queue is empty, then close the threads. > queue.join() > for t in threads: > t.close() > > -- > Steven Hi Steven, great point with the explicit call of destructor. I did a quick test and it is behaving exactly like I need. Thank you very much! Markus -- http://mail.python.org/mailman/listinfo/python-list
Are range iterators thread safe?
Using Python 3, are range_iterator objects thread-safe? I have tried this, and it seems to be safe: >>> from threading import Thread >>> x = iter(range(4)) >>> def doit(x): ... print("result =", next(x)) ... >>> threads = [Thread(target=doit, args=(x,)) for i in range(4)] >>> for t in threads: ... t.start() ... result = 0 result = 1 result = 2 result = 3 >>> -- Steven -- http://mail.python.org/mailman/listinfo/python-list
COM / .NET
Is python able to access COM libraries or .NET assemblies? If both, which is the easist or most popular? -- http://mail.python.org/mailman/listinfo/python-list
Re: COM / .NET
On 20/10/2011 09:06, Uffe Kousgaard wrote: Is python able to access COM libraries or .NET assemblies? If both, which is the easist or most popular? You have a few choices in this regard: * CPython can access COM objects either via the pywin32 extensions[1] or via comtypes[2]. The former is maintained and is quite mature and stable (and has recently had a small fix made to allow more flexibility when dealing with COM VARIANTS). comtypes, I think, unmaintained, although perfectly usable and somewhat more flexible than pywin32 in certain respects. * Python.NET [3] is a project which was dormant for a while but which is now maintained once more. This is a sort of bridge between CPython and the .NET assemblies. * IronPython [4] is a project, originally run inside Microsoft, now spun off as an Open Source project, which re-implements Python as a 1st-class .NET language running on the DLR. From that you have full access to the .NET Framework and its facilities. [1] http://sourceforge.net/projects/pywin32/ [2] http://pypi.python.org/pypi/comtypes [3] http://pythonnet.sourceforge.net/ (not sure if that's the canonical URL for that project or not) [4] http://ironpython.net/ TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Python based silent installer, how to?
On 20/10/2011 01:35 ص, Alec Taylor wrote: Just download the msi (script is available to regenerate yourself) and run it with the silent swtich, something like: msiexec /x nameofmsi.msi Sorry I didn't explain what I'm looking for exactly. I've packages built by bdist_wininst, Is there any way for install them silently? Or is there any way for convert them to another format (ex. msi) in that way I can install them silently. -- Best Regards Muhammad Bashir Al-Noimi My Blog: http://mbnoimi.net <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Python based silent installer, how to?
On 20/10/2011 12:00 ص, Steven D'Aprano wrote: Please don't send raw HTML (so-called "rich text") to mailing lists. It makes it very difficult for some people to read. If you must use HTML, please ensure your email client or news reader also sends a plain text version of the message as well. Sorry I forgot to configure my Thunderbird. That will depend on what your installer is, and whether it has an option for silent installation. Your question is unclear. What is the connection between Python and the installer? "I am installing Python on Windows." "Python is already installed, and I'm installing extra Python packages, using many different installers." "I'm installing applications using an installer written in Python." "I'm writing my own installer, using Python." or something else? If you want a better answer, you will need to explain what you are doing in more detail. I've packages built by bdist_wininst, Is there any way for install them silently? Or is there any way for convert them to another format (ex. msi) in that way I can install them silently. PS I tried to unzip that packages (I thought I may re-package un-zipped packages by NSIS or something else) and I discovered that the structure of directories of bdist_wininst packages so different! for example: ---xlwt-0.7.2.win32.exe--- PURELIB | |-- xlwt-0.7.2-py2.5.egg-info |-+ xlwt |-+ doc |-+ examples |-- __init__.py |-- antlr.py . . ---bzr-2.3.4-1.win32-py2.6.exe--- DATA |-- Doc PLATLIB | |-- bzr-2.3.4-py2.6.egg-info |-+ bzrlib |-+ bundle |-+ doc |-- __init__.py |-- _annotator_py.py . . SCRIPTS | |-- bzr |-- bzr-win32-bdist-postinstall.py -- Best Regards Muhammad Bashir Al-Noimi My Blog: http://mbnoimi.net <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Python based silent installer, how to?
On 20/10/2011 09:45, Muhammad Bashir Al-Noimi wrote: On 20/10/2011 01:35 ص, Alec Taylor wrote: Just download the msi (script is available to regenerate yourself) and run it with the silent swtich, something like: msiexec /x nameofmsi.msi Sorry I didn't explain what I'm looking for exactly. I've packages built by bdist_wininst, Is there any way for install them silently? Or is there any way for convert them to another format (ex. msi) in that way I can install them silently. If you can get the source (specifically including the setup.py which I don't think is included in the wininst .zip) then you can use that to build an msi: python setup.py bdist_msi which you can then manage via the usual msiexec switches. It's often available from the same source as the wininst .exe and/or from the project's code repository. If not, you're down to reverse-engineering a suitable setup.py. For many projects this is pretty simple. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: COM / .NET
"Tim Golden" wrote in message news:mailman.2075.1319100141.27778.python-l...@python.org... > > You have a few choices in this regard: Thanks for a detailed reply. We'll start looking at [1] and [3]. -- http://mail.python.org/mailman/listinfo/python-list
Re: Are range iterators thread safe?
Steven D'Aprano, 20.10.2011 10:04: Using Python 3, are range_iterator objects thread-safe? I have tried this, and it seems to be safe: >>> from threading import Thread >>> x = iter(range(4)) >>> def doit(x): ... print("result =", next(x)) ... >>> threads = [Thread(target=doit, args=(x,)) for i in range(4)] >>> for t in threads: ... t.start() ... result = 0 result = 1 result = 2 result = 3 The GIL ensures it's thread safe. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python based silent installer, how to?
On 20/10/2011 12:12 م, Tim Golden wrote: If you can get the source (specifically including the setup.py which I don't think is included in the wininst .zip) then you can use that to build an msi: python setup.py bdist_msi which you can then manage via the usual msiexec switches. It's often available from the same source as the wininst .exe and/or from the project's code repository. In case I got .egg file (ex. http://pypi.python.org/pypi/setuptools/0.6c11) from some website, can I use it as alternative to bdist_wininst package? In case 'yes' where I've to put .egg file? -- Best Regards Muhammad Bashir Al-Noimi My Blog: http://mbnoimi.net <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Are range iterators thread safe?
Stefan Behnel writes: > Steven D'Aprano, 20.10.2011 10:04: > > Using Python 3, are range_iterator objects thread-safe? > The GIL ensures it's thread safe. The GIL applies only to CPython. What is the answer for other Python implementations which don't have a GIL? -- \ Eccles: “I just saw the Earth through the clouds!” Lew: “Did | `\ it look round?” Eccles: “Yes, but I don't think it saw me.” | _o__)—The Goon Show, _Wings Over Dagenham_ | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading: Method trigger after thred finished
Am 20.10.2011 05:55, schrieb Steven D'Aprano: > # Make consumer threads. > class ThreadSql(threading.Thread): > def __init__(self, queue): > threading.Thread.__init__(self) > self.queue = queue > # Open database connection instance > self.session = "+++connection+++" # DbConnect() > self._open = True > > def run(self): > while self._open: > # Grab a query from queue. > query = self.queue.get() > # And process it. > print self, query > time.sleep(1) > # Mark the queue job as done. > self.queue.task_done() > > def close(self): > print "Closing", self > # self.session.Disconnect() > self._open = False The code may contain a subtle and nasty bug but this really depends on your database connection. Most db connections are neither thread safe nor reentrant and must not be shared between threads. However this code shares the connection across two threads. The __init__() method is run inside the thread that *creates* the new thread, not the new thread. Just the run() is executed in the new thread. I suggest that you acquire and close the connection inside the run() method protected by an try/finally or with block. Christian -- http://mail.python.org/mailman/listinfo/python-list
Insert Data with pymongo
Hi guys, i want to insert a JSON formated String into a mongoDB. But get some problem with the insert to the database. Traceback (most recent call last): File "obp_import_pb.py", line 102, in do_import() File "obp_import_pb.py", line 97, in do_import collection = db.pb_mp.insert(obp_transaction_json) File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 274, in insert docs = [self.__database._fix_incoming(doc, self) for doc in docs] File "/usr/lib64/python2.7/site-packages/pymongo/database.py", line 249, in _fix_incoming son = manipulator.transform_incoming(son, collection) File "/usr/lib64/python2.7/site-packages/pymongo/son_manipulator.py", line 73, in transform_incoming son["_id"] = ObjectId() TypeError: 'str' object does not support item assignment I'm using json.dumps to format a json string obp_transaction_json = json.dumps(..) I took a look about the pymongo Doc, which didn't help me a bit. I using Python 2.7, on a Gentoo(Linux-3.0.5) AMD64 Greeting's from Germany, Akendo -- http://mail.python.org/mailman/listinfo/python-list
Re: Are range iterators thread safe?
Ben Finney, 20.10.2011 13:23: Stefan Behnel writes: Steven D'Aprano, 20.10.2011 10:04: Using Python 3, are range_iterator objects thread-safe? The GIL ensures it's thread safe. The GIL applies only to CPython. and PyPy. What is the answer for other Python implementations which don't have a GIL? That would basically be Jython and IronPython. Note that none of the three alternative implementations currently supports Python language version 3. So, the current answer for all existing Python 3 implementations is: the GIL ensures that it's thread safe. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Insert Data with pymongo
In article , 4k3nd0 <4k3...@googlemail.com> wrote: > Hi guys, > > i want to insert a JSON formated String into a mongoDB. But get some > problem with the insert to the database. > > Traceback (most recent call last): > File "obp_import_pb.py", line 102, in > do_import() > File "obp_import_pb.py", line 97, in do_import > collection = db.pb_mp.insert(obp_transaction_json) > File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line > 274, in insert > docs = [self.__database._fix_incoming(doc, self) for doc in docs] > File "/usr/lib64/python2.7/site-packages/pymongo/database.py", line > 249, in _fix_incoming > son = manipulator.transform_incoming(son, collection) > File "/usr/lib64/python2.7/site-packages/pymongo/son_manipulator.py", > line 73, in transform_incoming > son["_id"] = ObjectId() > TypeError: 'str' object does not support item assignment > > > I'm using json.dumps to format a json string > > obp_transaction_json = json.dumps(..) > > I took a look about the pymongo Doc, which didn't help me a bit. > I using Python 2.7, on a Gentoo(Linux-3.0.5) AMD64 You haven't given enough information to even guess at the problem. Does the exception get thrown as part of the assignment, or evaluating the "." you pass to json.dumps()? I would start by breaking things down into smaller pieces and seeing which piece raises the exception. Also, post more of your code so we can see what's going on. -- http://mail.python.org/mailman/listinfo/python-list
revive a generator
Hi, it seems a generator expression can be used only once: >>> g = (x*x for x in range(3)) >>> for x in g: print x 0 1 4 >>> for x in g: print x #nothing printed >>> Is there any way to revive g here? Yingjie -- http://mail.python.org/mailman/listinfo/python-list
compare range objects
Hi, Is it possible to test if two range objects contain the same sequence of integers by the following algorithm in Python 3.2? 1. standardize the ending bound by letting it be the first excluded integer for the given step size. 2. compare the standardized starting bound, ending bound and step size: two ranges equal if and only if this triplet is the same. If that's correct, it would be good to have equality comparison on two ranges. Further, it might also be good to have sub-sequence test on ranges without enumerating it. Cheers, Yingjie -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
On Fri, Oct 21, 2011 at 12:23 AM, Yingjie Lan wrote: > Hi, > > it seems a generator expression can be used only once: > g = (x*x for x in range(3)) for x in g: print x > 0 > 1 > 4 for x in g: print x #nothing printed > > Is there any way to revive g here? If you're not generating very much, just use a list comprehension instead; you can iterate over the list as many times as you like: >>> g = [x*x for x in range(3)] >>> for x in g: print(x) 0 1 4 >>> for x in g: print(x) 0 1 4 Of course, since this is Python 3, you need the parens on print, but I assume you had something else you were doing with x. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
Yingjie Lan writes: > Hi, > > it seems a generator expression can be used only once: > g = (x*x for x in range(3)) for x in g: print x > 0 > 1 > 4 for x in g: print x #nothing printed > > Is there any way to revive g here? > Generators are like that - you consume them until they run out of values. You could have done [x*x for x in range(3)] and then iterated over that list as many times as you wanted. A generator doesn't have to remember all the values it generates so it can be more memory efficient that a list. Also it can, for example, generate an infinite sequence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Are range iterators thread safe?
On Thu, Oct 20, 2011 at 3:22 AM, Stefan Behnel wrote: > Steven D'Aprano, 20.10.2011 10:04: >> >> Using Python 3, are range_iterator objects thread-safe? >> >> I have tried this, and it seems to be safe: >> >> >>> from threading import Thread >> >>> x = iter(range(4)) >> >>> def doit(x): >> ... print("result =", next(x)) >> ... >> >>> threads = [Thread(target=doit, args=(x,)) for i in range(4)] >> >>> for t in threads: >> ... t.start() >> ... >> result = 0 >> result = 1 >> result = 2 >> result = 3 > > The GIL ensures it's thread safe. Because range_iterator objects are implemented in C and so calling the __next__ method is only a single bytecode instruction, correct? If they were implemented in Python the GIL would make no such assurance. -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
On Thu, Oct 20, 2011 at 06:19:40AM -0700, Yingjie Lan wrote: > Hi, > > Is it possible to test if two range objects contain the same sequence of > integers by the following algorithm in Python 3.2? > > 1. standardize the ending bound by letting it be the first excluded integer > for the given step size. > 2. compare the standardized starting bound, ending bound and step size: two > ranges equal if and only if this triplet is the same. > > If that's correct, it would be good to have equality comparison on two > ranges. > > Further, it might also be good to have sub-sequence test on ranges without > enumerating it. > There's already a discussion about this on python-ideas. But somebody please tell me, why would you ever need to compare ranges? -- http://mail.python.org/mailman/listinfo/python-list
Py3K: file inheritance
In the Python 2.x was simple to create own file object: class MyFile(file): pass for example to reimplement write() or something else. How to do it in Python 3.x? -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K: file inheritance
On Thu, Oct 20, 2011 at 11:28 AM, Yosifov Pavel wrote: > In the Python 2.x was simple to create own file object: > > class MyFile(file): > pass > > for example to reimplement write() or something else. How to do it in > Python 3.x? See the docs for the io module. Depending on what you want to do, you probably need to subclass either io.FileIO or io.TextIOWrapper. -- http://mail.python.org/mailman/listinfo/python-list
Benefits of xml.dom.minidom?
I recently inherited some code that uses xml.dom.minidom to build a large XML document, and I noticed that it is quite slow and uses a ton of memory. I converted the same code to use lxml.etree and it is much faster and uses not nearly so much memory. Why is minidom so hungry for resources? What is it doing with all that memory and CPU? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
On 20/10/11 18:22:04, Westley Martínez wrote: On Thu, Oct 20, 2011 at 06:19:40AM -0700, Yingjie Lan wrote: Hi, Is it possible to test if two range objects contain the same sequence of integers by the following algorithm in Python 3.2? 1. standardize the ending bound by letting it be the first excluded integer for the given step size. 2. compare the standardized starting bound, ending bound and step size: two ranges equal if and only if this triplet is the same. If that's correct, it would be good to have equality comparison on two ranges. Further, it might also be good to have sub-sequence test on ranges without enumerating it. There's already a discussion about this on python-ideas. But somebody please tell me, why would you ever need to compare ranges? It could be useful if you're unit-testing a function that returns a range. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
On Thu, Oct 20, 2011 at 12:00 PM, Hans Mulder wrote: >> There's already a discussion about this on python-ideas. But somebody >> please tell me, why would you ever need to compare ranges? > > It could be useful if you're unit-testing a function that returns a range. Easy: list(range1) == list(range2) -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
Ian Kelly wrote: On Thu, Oct 20, 2011 at 12:00 PM, Hans Mulder wrote: There's already a discussion about this on python-ideas. But somebody please tell me, why would you ever need to compare ranges? It could be useful if you're unit-testing a function that returns a range. Easy: list(range1) == list(range2) The biggest reason in my mind for implementing range equality is that currently two ranges compare equal iff they are the same range. In other words: --> range(10) == range(10) False ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
google maps api help
I have an excel sheet with a bunch of info regarding the stops a delivery truck makes throughout the day. I can successfully extract the information I need with xlrd. This is the code I am using: book = xlrd.open_workbook(r'c:\xytest.xls') sheet= book.sheet_by_index(0) odList = [] for i in range(1,6125): cID = sheet.row(i)[0].value #Company ID tID = sheet.row(i)[1].value #Truck ID xyCoord = sheet.row_values(i,start_colx = 8,end_colx = 10 ) #long and lat xyCoord.reverse() #reversed, so that lat,long is in correct format odList.append([cID,tID,xyCoord]) Printing odList give me this output where fields are [CompanyID,TruckID, Lat,Long] : [[520.0, 1.0, [35.77, -78.115784]], [520.0, 1.0, [36.075812, -78.256766]], [520.0, 1.0, [35.77, -78.115784]], [520.0, 2.0, [35.79528, -78.137549]], [520.0, 3.0, [35.79528, -78.137549]] I used list indices to grab the coordinates and query gmaps with: result = gmaps.directions(odList[0][2],odList[1][2]) time = result['Directions']['Duration']['seconds'] dist = result['Directions']['Distance']['meters'] Unfortunately, gmaps does not understand [35.77, -78.115784], [36.075812, -78.256766], gmaps does understand (35.77, -78.115784), (36.075812, -78.256766). Any ideas on how to get the query to send () instead of [] ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefits of xml.dom.minidom?
I use minidom all the time and i don' t have that problem could you describe more of the process ? El oct 20, 2011 5:53 p.m., "John Gordon" escribió: > > I recently inherited some code that uses xml.dom.minidom to build a large > XML document, and I noticed that it is quite slow and uses a ton of memory. > > I converted the same code to use lxml.etree and it is much faster and > uses not nearly so much memory. > > Why is minidom so hungry for resources? What is it doing with all that > memory and CPU? > > -- > John Gordon A is for Amy, who fell down the stairs > gor...@panix.com B is for Basil, assaulted by bears >-- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefits of xml.dom.minidom?
John Gordon, 20.10.2011 19:46: I recently inherited some code that uses xml.dom.minidom to build a large XML document, and I noticed that it is quite slow and uses a ton of memory. I converted the same code to use lxml.etree and it is much faster and uses not nearly so much memory. Why is minidom so hungry for resources? What is it doing with all that memory and CPU? Not much. It's memory hungry because it builds a tree from rather heavy XML objects and is neither optimised for speed nor for a low memory footprint. Its main purpose is to be (mostly) W3C DOM compatible. It's also been in the standard library for quite a bit longer than ElementTree, and predates lxml by years. That's the most likely reason why your original script was written using minidom. In a way, it's unfair to compare minidom with lxml.etree (or cElementTree, for that purpose), as the latter two were specifically designed for high performance and a much simpler API. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: google maps api help
On 20/10/2011 19:39, Christopher Saunders wrote: I have an excel sheet with a bunch of info regarding the stops a delivery truck makes throughout the day. I can successfully extract the information I need with xlrd. This is the code I am using: book = xlrd.open_workbook(r'c:\xytest.xls') sheet= book.sheet_by_index(0) odList = [] for i in range(1,6125): cID = sheet.row(i)[0].value #Company ID tID = sheet.row(i)[1].value #Truck ID xyCoord = sheet.row_values(i,start_colx = 8,end_colx = 10 ) #long and lat xyCoord.reverse() #reversed, so that lat,long is in correct format odList.append([cID,tID,xyCoord]) Printing odList give me this output where fields are [CompanyID,TruckID, Lat,Long] : [[520.0, 1.0, [35.77, -78.115784]], [520.0, 1.0, [36.075812, -78.256766]], [520.0, 1.0, [35.77, -78.115784]], [520.0, 2.0, [35.79528, -78.137549]], [520.0, 3.0, [35.79528, -78.137549]] I used list indices to grab the coordinates and query gmaps with: result = gmaps.directions(odList[0][2],odList[1][2]) time = result['Directions']['Duration']['seconds'] dist = result['Directions']['Distance']['meters'] Unfortunately, gmaps does not understand [35.77, -78.115784], [36.075812, -78.256766], gmaps does understand (35.77, -78.115784), (36.075812, -78.256766). Any ideas on how to get the query to send () instead of [] ? Try turning the lists into tuples: result = gmaps.directions(tuple(odList[0][2]), tuple(odList[1][2])) -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
The range() in python is an iterable generator that returns an object ref/id. The xrange() is different. -- http://mail.python.org/mailman/listinfo/python-list
sysconfig on OS X 10.7 (Lion) and XCode 4.2
Hello all, I've struggled mightily to get Numpy and pyopencl installed on my brand-new Lion machine running XCode 4.2 (not recommended, I know, but I'm a sucker for punishment). I did finally succeed, anyway. I found that the greatest problem I had (after installing gfortran from a precompiled package) was getting setup.py and subsidiaries to use the right GCC. The python.org official builds of Python (I'm specifically using 3.2.2, though I'm sure this applies to 2.7 as well) have some trouble with building extensions because CC is specified as "gcc-4.2", which no longer exists in XCode 4.2 (one could chalk that up to being Apple's problem, but hey). The root of this problem is in the sysconfig module, which I assume has hardcoded names for the compiler, etc. Most insidious was fixing LDSHARED, which was gcc-4.2 with a bunch of flags appended to it including the system framework (for 10.6, I should point out, which is also what sysconfig returned for sysconfig.platform()). Is there any way to permanently override these values in sysconfig short of building my own Python and installing it? I'm having to override the environment variables whenever I build a C/C++ module, and it's getting to be a pain. For anyone looking for the answer to a similar problem (usually gcc-4.2 not being found when running setup.py), export the following environment variables to build things under XCode 4.2: CC=gcc CXX=g++ LDSHARED="gcc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -isysroot /Developer/SDKs/MacOSX10.7.sdk -g" (obviously, replace 10.7 with 10.6 if you're building under 10.6) For example: sudo CC=gcc CXX=g++ LDSHARED="gcc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -isysroot /Developer/SDKs/MacOSX10.7.sdk -g" pip install pyopencl This will override the default values taken from the sysconfig module. - Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: google maps api help
On Oct 20, 1:02 pm, MRAB wrote: > On 20/10/2011 19:39, Christopher Saunders wrote: > > > > > > > > > > > I have an excel sheet with a bunch of info regarding the stops a > > delivery truck makes throughout the day. I can successfully extract > > the information I need with xlrd. This is the code I am using: > > > book = xlrd.open_workbook(r'c:\xytest.xls') > > sheet= book.sheet_by_index(0) > > odList = [] > > > for i in range(1,6125): > > cID = sheet.row(i)[0].value #Company ID > > tID = sheet.row(i)[1].value #Truck ID > > xyCoord = sheet.row_values(i,start_colx = 8,end_colx = 10 ) #long > > and lat > > xyCoord.reverse() #reversed, so that lat,long is in correct format > > odList.append([cID,tID,xyCoord]) > > > Printing odList give me this output where fields are > > [CompanyID,TruckID, Lat,Long] : [[520.0, 1.0, [35.77, > > -78.115784]], [520.0, 1.0, [36.075812, -78.256766]], [520.0, > > 1.0, [35.77, -78.115784]], [520.0, 2.0, [35.79528, > > -78.137549]], [520.0, 3.0, [35.79528, -78.137549]] > > > I used list indices to grab the coordinates and query gmaps with: > > > result = gmaps.directions(odList[0][2],odList[1][2]) > > time = result['Directions']['Duration']['seconds'] > > dist = result['Directions']['Distance']['meters'] > > > Unfortunately, gmaps does not understand [35.77, -78.115784], > > [36.075812, -78.256766], gmaps does understand (35.77, -78.115784), > > (36.075812, -78.256766). Any ideas on how to get the query to send () > > instead of [] ? > > Try turning the lists into tuples: > > result = gmaps.directions(tuple(odList[0][2]), tuple(odList[1][2])) Awesome, that worked! -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
On 10/20/2011 9:23 AM, Yingjie Lan wrote: it seems a generator expression can be used only once: Generators are iterators. Once iterators raise StopIteration, they are supposed to continue doing so. A generator expression defines a temporary anonymous generator function that is called once to produce a generator and then deleted. It, like all comprehensions, is purely a convenient abbreviation. g = (x*x for x in range(3)) for x in g: print x 0 1 4 for x in g: print x #nothing printed Define a named generator function (and add a parameter to make it more flexible and useful and reuse it. def g(n): for i in range(n): yield i*i Then, "for x in g(3)", "for x in g(8)", "for x in g(y*x)", etc, as many times as you want. You might call it 'square' or even 'r_square' instead of 'g'. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: sysconfig on OS X 10.7 (Lion) and XCode 4.2
In article <5ed3f418-a03d-4be6-91a5-51c0df899...@mantaro.com>, David Riley wrote: > I've struggled mightily to get Numpy and pyopencl installed on my brand-new > Lion machine running XCode 4.2 (not recommended, I know, but I'm a sucker for > punishment). I did finally succeed, anyway. > > I found that the greatest problem I had (after installing gfortran from a > precompiled package) was getting setup.py and subsidiaries to use the right > GCC. The python.org official builds of Python (I'm specifically using 3.2.2, > though I'm sure this applies to 2.7 as well) have some trouble with building > extensions because CC is specified as "gcc-4.2", which no longer exists in > XCode 4.2 (one could chalk that up to being Apple's problem, but hey). > > The root of this problem is in the sysconfig module, which I assume has > hardcoded names for the compiler, etc. Most insidious was fixing LDSHARED, > which was gcc-4.2 with a bunch of flags appended to it including the system > framework (for 10.6, I should point out, which is also what sysconfig > returned for sysconfig.platform()). > > Is there any way to permanently override these values in sysconfig short of > building my own Python and installing it? I'm having to override the > environment variables whenever I build a C/C++ module, and it's getting to be > a pain. > > > > For anyone looking for the answer to a similar problem (usually gcc-4.2 not > being found when running setup.py), export the following environment > variables to build things under XCode 4.2: > > CC=gcc > CXX=g++ > LDSHARED="gcc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 > -isysroot /Developer/SDKs/MacOSX10.7.sdk -isysroot > /Developer/SDKs/MacOSX10.7.sdk -g" > > (obviously, replace 10.7 with 10.6 if you're building under 10.6) > > For example: > > sudo CC=gcc CXX=g++ LDSHARED="gcc -bundle -undefined dynamic_lookup -arch > i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -isysroot > /Developer/SDKs/MacOSX10.7.sdk -g" pip install pyopencl > > > This will override the default values taken from the sysconfig module. On OS X, Python's Distutils goes to some trouble to ensure that C extension modules are built with the same compiler and compatible settings as the Python interpreter itself was built. The current python.org 64-bit/32-bit installers (which I assume you are using) for 3.2.x and 2.7.x were built on 10.6 using the gcc-4.2 available in Xcode 3. Now that Xcode 4.2 has been released and has deleted gcc-4.2, that's a problem. A thorough building and testing cycle using the various compiler options (llvm-gcc and clang) is needed for Lion; there have been problems already reported and corrected for clang with Xcode 4.1. I'm starting to do that. It would be helpful if you could open an issue on the Python bug tracker (http://bugs.python.org) and summarize what you've found there. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: COM / .NET
Tim Golden wrote: You have a few choices in this regard: Also it's reportedly possible to register a .NET assembly as a COM library and use it that way. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
RE: Problem with a wx notebook
-Original Message- From: python-list-bounces+ramit.prasad=jpmorgan@python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of faucheuse Sent: Monday, October 17, 2011 5:33 AM To: python-list@python.org Subject: Problem with a wx notebook Hi there, I've created a wx NoteBook in wich I set multiples panels in wich I set one or more sizers. But nothing displays in the notebook, everything is outside. I've been searching an answer for 2 days ><. Can you help me plz ? Here is my code(with only one panel, to sum up the code) : class StreamingActivationDialog(wx.Dialog): def __init__(self, *args, **kwds): # begin wxGlade: StreamingActivationDialog.__init__ kwds["style"] = wx.DEFAULT_DIALOG_STYLE wx.Dialog.__init__(self, *args, **kwds) self.bitmap_1_copy = wx.StaticBitmap(self, -1, wx.Bitmap("img\ \logo.png", wx.BITMAP_TYPE_ANY)) self.labelDnD = wx.StaticText(self, -1, "Si vous avez déjà un fichier d'activation, faite le glisser dans cette fenetre") self.keyBitmap = wx.StaticBitmap(self, -1, wx.Bitmap("img\ \key.bmp", wx.BITMAP_TYPE_ANY)) self.conclude = wx.StaticText(self, -1, _("test"), style=wx.ALIGN_CENTRE) ### Panel ### self.intro3_label = wx.StaticText(self, -1, "Envoyez un mail à \nactivat...@monmail.com\ncontenant le code :",style=wx.ALIGN_CENTRE) self.activationCode_label= wx.StaticText(self, -1, "123456789", style=wx.TE_READONLY) self.copy2_Button = wx.Button(self, -1, "Copier dans le presse- papier") self.copy2_Button.Bind(wx.EVT_BUTTON, PanelMail.onCopy) ## self.note = wx.Notebook(self, wx.ID_ANY, style=wx.BK_LEFT, size=wx.Size(100, 341)) self.page3 = wx.Panel(self.note) imagelist = wx.ImageList(94, 94) bitmap1 = wx.Bitmap("img\\a.bmp", wx.BITMAP_TYPE_BMP ) imagelist.Add(bitmap1) self.note.AssignImageList(imagelist) self.__set_properties() self.__do_layout() # end wxGlade def __set_properties(self): # begin wxGlade: StreamingActivationDialog.__set_properties self.SetTitle(_("Activation de FlashProcess")) self.SetBackgroundColour(wx.Colour(255, 255, 255)) #self.linkProblem.SetForegroundColour(wx.Colour(0, 0, 0)) # end wxGlade def __do_layout(self): # begin wxGlade: StreamingActivationDialog.__do_layout self.grid_sizer_1 = wx.FlexGridSizer(6, 1, 0, 0) self.grid_sizer_2 = wx.FlexGridSizer(1, 2, 0, 30) self.grid_sizer_1.Add(self.bitmap_1_copy, 0, wx.TOP|wx.BOTTOM| wx.EXPAND, 10) ### Page 3 ### sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.intro3_label, 0, wx.BOTTOM|wx.ALIGN_CENTER, 5) sizer.Add(self.activationCode_label, 0, wx.BOTTOM| wx.ALIGN_CENTER, 20) sizer.Add(self.copy2_Button, 0, wx.ALIGN_CENTER, 20) self.page3.SetSizer(sizer) sizer.Fit(self.page3) ## self.note.AddPage(self.page3, "", False, 0) self.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGED, self.OnPageChanged) self.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGING, self.OnPageChanging) self.grid_sizer_1.Add(self.note, 0, wx.EXPAND, 20) self.grid_sizer_1.Add(self.labelDnD, 0, wx.TOP| wx.ALIGN_CENTER_HORIZONTAL, 20) self.grid_sizer_2.Add(self.keyBitmap, 0, wx.LEFT, 10) self.grid_sizer_2.Add(self.labelDnD, 0, wx.LEFT, 20) self.grid_sizer_1.Add(self.grid_sizer_2, 0, wx.EXPAND, 20) self.grid_sizer_1.Add(self.conclude, 0, wx.TOP| wx.ALIGN_CENTER_HORIZONTAL, 20) self.SetSizer(self.grid_sizer_1) self.grid_sizer_1.Fit(self) self.Layout() # end wxGlade def OnPageChanged(self, event): event.Skip() def OnPageChanging(self, event): event.Skip() = Is this still a problem? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Problem with a wx notebook
Prasad, Ramit wrote: > I've created a wx NoteBook in wich I set multiples panels in wich I > set one or more sizers. But nothing displays in the notebook, > everything is outside. I've been searching an answer for 2 days ><. > Can you help me plz ? Here is my code(with only one panel, to sum up > the code) : > > class StreamingActivationDialog(wx.Dialog): > def __init__(self, *args, **kwds): > # begin wxGlade: StreamingActivationDialog.__init__ > kwds["style"] = wx.DEFAULT_DIALOG_STYLE > wx.Dialog.__init__(self, *args, **kwds) > self.bitmap_1_copy = wx.StaticBitmap(self, -1, wx.Bitmap("img\ > \logo.png", wx.BITMAP_TYPE_ANY)) > self.labelDnD = wx.StaticText(self, -1, "Si vous avez déjà un > fichier d'activation, faite le glisser dans cette fenetre") > self.keyBitmap = wx.StaticBitmap(self, -1, wx.Bitmap("img\ > \key.bmp", wx.BITMAP_TYPE_ANY)) > self.conclude = wx.StaticText(self, -1, _("test"), > style=wx.ALIGN_CENTRE) > > ### Panel ### > self.intro3_label = wx.StaticText(self, -1, "Envoyez un mail à > \nactivat...@monmail.com\ncontenant le code :",style=wx.ALIGN_CENTRE) > self.activationCode_label= wx.StaticText(self, -1, > "123456789", style=wx.TE_READONLY) > self.copy2_Button = wx.Button(self, -1, "Copier dans le presse- > papier") > self.copy2_Button.Bind(wx.EVT_BUTTON, PanelMail.onCopy) > ## > > self.note = wx.Notebook(self, wx.ID_ANY, style=wx.BK_LEFT, > size=wx.Size(100, 341)) > self.page3 = wx.Panel(self.note) > > imagelist = wx.ImageList(94, 94) > bitmap1 = wx.Bitmap("img\\a.bmp", wx.BITMAP_TYPE_BMP ) > imagelist.Add(bitmap1) > self.note.AssignImageList(imagelist) > > self.__set_properties() > self.__do_layout() > # end wxGlade > > def __set_properties(self): > # begin wxGlade: StreamingActivationDialog.__set_properties > self.SetTitle(_("Activation de FlashProcess")) > self.SetBackgroundColour(wx.Colour(255, 255, 255)) > #self.linkProblem.SetForegroundColour(wx.Colour(0, 0, 0)) > # end wxGlade > > def __do_layout(self): > # begin wxGlade: StreamingActivationDialog.__do_layout > self.grid_sizer_1 = wx.FlexGridSizer(6, 1, 0, 0) > self.grid_sizer_2 = wx.FlexGridSizer(1, 2, 0, 30) > self.grid_sizer_1.Add(self.bitmap_1_copy, 0, wx.TOP|wx.BOTTOM| > wx.EXPAND, 10) > > > ### Page 3 ### > sizer = wx.BoxSizer(wx.VERTICAL) > sizer.Add(self.intro3_label, 0, wx.BOTTOM|wx.ALIGN_CENTER, 5) > sizer.Add(self.activationCode_label, 0, wx.BOTTOM| > wx.ALIGN_CENTER, 20) > sizer.Add(self.copy2_Button, 0, wx.ALIGN_CENTER, 20) > > self.page3.SetSizer(sizer) > sizer.Fit(self.page3) > ## > > self.note.AddPage(self.page3, "", False, 0) [ ... ] It looks a though all the controls that are meant for page3 have been created with the top-level dialog as their parent. AFAIK this cannot be. self.page3 is (correctly) a child window of self.note, but the controls to be shown inside have to be children of self.page3 . Putting things into the sizers is not enough. In my own code, I usually define a separate class descended from wx.Panel to create a page3 instance with its own sizers, then create one of those with a a wx.Notebook instance as a parent, and add it to the notebook: def _new_capture_page (self): new_trace = TraceWindow (self.tracebook) self.tracebook.AddPage (new_trace, 'Capture %d' % (self.capture_serial,), select=True) return new_trace Hope this helps, Mel. -- http://mail.python.org/mailman/listinfo/python-list
RE: [OT] Re: Benefit and belief
>I think you need to speak German fluently to be a good programmer. Why? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Re: Benefit and belief
On Wed, 19 Oct 2011 14:49:26 -0700, Westley Martínez wrote: >> I am a poly-illiterate. I can't read or write hundreds of languages. > > I think you need to speak German fluently to be a good programmer. No, just Dutch :) -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Re: Benefit and belief
On Thu, Oct 20, 2011 at 06:05:00PM -0400, Prasad, Ramit wrote: > >I think you need to speak German fluently to be a good programmer. > Why? > I won't reveal my secrets to JP Morgan Chase! I am loyal to the mighty Bank of America. -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Re: Benefit and belief
On Fri, Oct 21, 2011 at 9:14 AM, Redcat wrote: > On Wed, 19 Oct 2011 14:49:26 -0700, Westley Martínez wrote: >> >> I think you need to speak German fluently to be a good programmer. > > No, just Dutch :) Whatever language it be, you do need to be competent in a human language to be a good programmer. I speak only English of all human languages (can comprehend a smattering of phrases in a few other languages, but no fluency), and there are plenty of programmers who speak only X for some other X, but you do need the skill of coalescing thoughts into words. If nothing else, it makes everyone's lives easier when you ask for help :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: how to change the order of a button, static text or other components
On Thu, Oct 20, 2011 at 6:08 PM, install...@189.cn wrote: > what i want to do is,when i press a button, i change the order of > selected components,how to do this? Which GUI toolkit are you using? Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
- Original Message - > From: Paul Rudin > To: python-list@python.org > Cc: > Sent: Thursday, October 20, 2011 10:28 PM > Subject: Re: revive a generator > > Yingjie Lan writes: > >> Hi, >> >> it seems a generator expression can be used only once: >> > g = (x*x for x in range(3)) > for x in g: print x >> 0 >> 1 >> 4 > for x in g: print x #nothing printed > >> >> Is there any way to revive g here? >> > > Generators are like that - you consume them until they run out of > values. You could have done [x*x for x in range(3)] and then iterated > over that list as many times as you wanted. > > A generator doesn't have to remember all the values it generates so it > can be more memory efficient that a list. Also it can, for example, > generate an infinite sequence. > > Thanks a lot to all who answered my question. I am still not sure why should we enforce that a generator can not be reused after an explicit request to revive it? -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
On Fri, Oct 21, 2011 at 12:46 PM, Yingjie Lan wrote: > > Thanks a lot to all who answered my question. > I am still not sure why should we enforce that > a generator can not be reused after an explicit > request to revive it? Here's an example of an explicit request to revive the generator: >>> g = (x*x for x in range(3)) >>> for x in g: print x 0 1 4 >>> g = (x*x for x in range(3)) # revive the generator >>> for x in g: print x #now this will work 0 1 4 ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
- Original Message - > From: Westley Martínez > To: python-list@python.org > Cc: > Sent: Friday, October 21, 2011 12:22 AM > Subject: Re: compare range objects > > There's already a discussion about this on python-ideas. But somebody > please tell me, why would you ever need to compare ranges? In simulation, one can use range objects to denote a discrete domain, and domain comparison could be very useful. Not just equality, but also things like if one domain is contained in another. -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
On Fri, Oct 21, 2011 at 12:55 PM, Yingjie Lan wrote: > In simulation, one can use range objects to denote a discrete domain, > and domain comparison could be very useful. Not just equality, but also > things like if one domain is contained in another. > Hmm. I wonder would slice objects be appropriate? They're comparable: >>> a=slice(1,10) >>> b=slice(1,10) >>> a==b True They're not iterable though - not directly (but you could slice range(maxint) down to size). You could possibly use itertools.islice objects for a similar job, but they're not comparable. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Oct 21, 5:31 am, Chris Angelico wrote: > On Fri, Oct 21, 2011 at 9:14 AM, Redcat wrote: > > On Wed, 19 Oct 2011 14:49:26 -0700, Westley Martínez wrote: > > >> I think you need to speak German fluently to be a good programmer. > > > No, just Dutch :) > > Whatever language it be, you do need to be competent in a human > language to be a good programmer. I speak only English of all human > languages (can comprehend a smattering of phrases in a few other > languages, but no fluency), and there are plenty of programmers who > speak only X for some other X, but you do need the skill of coalescing > thoughts into words. If nothing else, it makes everyone's lives easier > when you ask for help :) > > ChrisA The American programmer would profit more from learning Latin than from learning yet another programming language. Edsger Dijkstra in "On the fact that the Atlantic Ocean has two sides" http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD611.html -- http://mail.python.org/mailman/listinfo/python-list
Re: how to change the order of a button, static text or other components
On 10月21日, 上午9时26分, Chris Rebert wrote: > On Thu, Oct 20, 2011 at 6:08 PM, install...@189.cn wrote: > > what i want to do is,when i press a button, i change the order of > > selected components,how to do this? > > Which GUI toolkit are you using? > > Cheers, > Chris wxpython. thx so much. -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
On Oct 21, 12:16 pm, Chris Angelico wrote: > Hmm. I wonder would slice objects be appropriate? > They're not iterable though They're not hashable either, which kind of surprised me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K: file inheritance
On 21 окт, 00:42, Ian Kelly wrote: > On Thu, Oct 20, 2011 at 11:28 AM, Yosifov Pavel wrote: > > In the Python 2.x was simple to create own file object: > > > class MyFile(file): > > špass > > > for example to reimplement write() or something else. How to do it in > > Python 3.x? > > See the docs for the io module. Depending on what you want to do, you > probably need to subclass either io.FileIO or io.TextIOWrapper. Little silly example: class MyFile(file): def __init__(self, *a, **ka): super(MyFile, self).__init__(*a, **ka) self.commented = 0 def write(self, s): if s.startswith("#"): self.commented += 1 super(MyFile, self).write(s) When I tried in Python 3.x to inherit FileIO or TextIOWrapper and then to use MyFile (ex., open(name, mode, encoding), write(s)...) I get errors like 'unsupported write' or AttributeError 'readable'... Can you show me similar simple example like above but in Python 3.x? -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Fri, Oct 21, 2011 at 1:34 PM, rusi wrote: > The American programmer would profit more from learning Latin than > from learning yet another programming language. > > Edsger Dijkstra in "On the fact that the Atlantic Ocean has two > sides" > Expanding that quote: --- A thorough study of one or more foreign languages makes one much more conscious about one's own; because an excellent mastery of his native tongue is one of the computing scientist's most vital assets, I often feel that the American programmer would profit more from learning, say, Latin than from learning yet another programming language. --- The reason he recommends learning Latin is because it helps you master English. One of the benefits (if you like, a blessing in a REALLY good disguise) of being Australian is that we're forced to work internationally in a way that Americans aren't. You can write a program, even sell it and make your living off it, that never goes outside the boundaries of the US of A. Here in Australia, that's not really a viable option, which means our minds have to be able to 'skip to Honolulu and back in two seconds' as a regular thing. Yes, we can still restrict ourselves to English-speaking countries quite easily, but there's the encouragement to support Europe, and extending from there to the whole world. Of course, not everyone takes advantage of the opportunity thus afforded. There are still plenty of people who are ignorant of the difference between a character and a byte, who assume or mandate one date format, or who parse mailing addresses too strictly. But at least we have a bit of impetus. Which means it's more of a crime for an Aussie (or a European, for that matter) to muck up like that than it is for an American. Blessing or curse? Now I'm not even sure myself. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
rusi writes: > The American programmer would profit more from learning Latin than > from learning yet another programming language. > > Edsger Dijkstra in "On the fact that the Atlantic Ocean has two > sides" > > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD611.html It's ambiguous whether Dijkstra is saying anything positive about Latin there. He could be saying “learning Latin would be a useful thing for average US programmers”. Or he could be saying “learning any second natural human language – even one as useless as Latin – will benefit the average US programmer more than learning another programming language”. I prefer to think someone as wise as Dijkstra would not be deluded as to the value of Latin, and lean more toward the latter meaning. -- \ “Everyone is entitled to their own opinions, but they are not | `\entitled to their own facts.” —US Senator Pat Moynihan | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Py3K: file inheritance
On Thu, Oct 20, 2011 at 10:17 PM, Yosifov Pavel wrote: > Little silly example: > > class MyFile(file): > def __init__(self, *a, **ka): > super(MyFile, self).__init__(*a, **ka) > self.commented = 0 > def write(self, s): > if s.startswith("#"): > self.commented += 1 > super(MyFile, self).write(s) > > When I tried in Python 3.x to inherit FileIO or TextIOWrapper and then > to use MyFile (ex., open(name, mode, encoding), write(s)...) I get > errors like 'unsupported write' or AttributeError 'readable'... Can > you show me similar simple example like above but in Python 3.x? class MyTextIO(io.TextIOWrapper): def __init__(self, *args, **kw): super().__init__(*args, **kw) self.commented = 0 def write(self, s): if s.startswith('#'): self.commented += 1 super().write(s) buffered = open(name, 'wb') textio = MyTextIO(buffered, encoding='utf-8') textio.write('line 1') textio.write('# line 2') textio.close() print(textio.commented) HTH, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: compare range objects
On Thu, Oct 20, 2011 at 8:16 PM, Chris Angelico wrote: > Hmm. I wonder would slice objects be appropriate? They're comparable: > a=slice(1,10) b=slice(1,10) a==b > True > > They're not iterable though - not directly (but you could slice > range(maxint) down to size). You could possibly use itertools.islice > objects for a similar job, but they're not comparable. They have completely different semantics for negative numbers. range(-7, 10) and range(maxint)[slice(-7, 10)] are two completely different things. Still, though, if slice objects are directly comparable, I can't see any reason why range objects shouldn't be. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list