Roundup Issue Tracker release 1.1.0
I'm proud to release this, the 1.1.0 release of Roundup. Feature: - trackers may configure custom stop-words for the full-text indexer - login may now be for a single session (and this is the default) - trackers may hide exceptions from web users (they will be mailed to the tracker admin) (hiding is the default) - include clear this message link in the ok message bar Fixed: - fixes in scripts/import_sf.py - fix some unicode bugs in roundup-admin import - Xapian indexer wasn't actually being used and its reindexing of existing data was busted to boot - roundup-admin import wasn't indexing message content - allow dispname to be passed to renderWith (sf bug 1424587) - rename dispname to @dispname to avoid name clashes in the future - fixed schema migration problem when Class keys were removed If you're upgrading from an older version of Roundup you *must* follow the Software Upgrade guidelines given in the maintenance documentation. Roundup requires python 2.3 or later for correct operation. To give Roundup a try, just download (see below), unpack and run:: python demo.py Release info and download page: http://cheeseshop.python.org/pypi/roundup Source and documentation is available at the website: http://roundup.sourceforge.net/ Mailing lists - the place to ask questions: http://sourceforge.net/mail/?group_id=31577 About Roundup = Roundup is a simple-to-use and -install issue-tracking system with command-line, web and e-mail interfaces. It is based on the winning design from Ka-Ping Yee in the Software Carpentry Track design competition. Note: Ping is not responsible for this project. The contact for this project is [EMAIL PROTECTED] Roundup manages a number of issues (with flexible properties such as description, priority, and so on) and provides the ability to: (a) submit new issues, (b) find and edit existing issues, and (c) discuss issues with other participants. The system will facilitate communication among the participants by managing discussions and notifying interested parties when issues are edited. One of the major design goals for Roundup that it be simple to get going. Roundup is therefore usable out of the box with any python 2.3+ installation. It doesn't even need to be installed to be operational, though a disutils-based install script is provided. It comes with two issue tracker templates (a classic bug/feature tracker and a minimal skeleton) and five database back-ends (anydbm, sqlite, metakit, mysql and postgresql). -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
pypy pycon 2006 sprint
Post-PyCon PyPy Sprint: February 27th - March 2nd 2006 The next PyPy sprint is scheduled to take place right after PyCon 2006 in Dallas, Texas, USA. We hope to see lots of newcomers at this sprint, so we'll give friendly introductions. Note that during the Pycon conference we are giving PyPy talks which serve well as preparation. Goals and topics of the sprint -- While attendees of the sprint are of course welcome to work on what they wish, we offer these ideas: - Work on an 'rctypes' module aiming at letting us use a ctypes implementation of an extension module from the compiled pypy-c. - Writing ctypes implementations of modules to be used by the above tool. - Experimenting with different garbage collection strategies. - Implementing Python 2.5 features in PyPy - Implementation of constraints solvers and integration of dataflow variables to PyPy. - Implement new features and improve the 'py' lib and py.test which are heavily used by PyPy (doctests/test selection/...). - Generally experiment with PyPy -- for example, play with transparent distribution of objects or coroutines and stackless features at application level. - Have fun! Location The sprint will be held wherever the PyCon sprints end up being held, which is to say somewhere within the Dallas/Addison Marriott Quorum hotel. For more information see the PyCon 06 sprint pages: - http://us.pycon.org/TX2006/Sprinting - http://wiki.python.org/moin/PyCon2006/Sprints Exact times --- The PyPy sprint will from from Monday February 27th until Thursday March 2nd 2006. Hours will be from 10:00 until people have had enough. Registration, etc. -- If you know before the conference that you definitely want to attend our sprint, please subscribe to the `PyPy sprint mailing list`_, introduce yourself and post a note that you want to come. Feel free to ask any questions or make suggestions there! There is a separate `PyCon 06 people`_ page tracking who is already planning to come. If you have commit rights on codespeak then you can modify yourself a checkout of http://codespeak.net/svn/pypy/extradoc/sprintinfo/pycon06/people.txt .. _`PyPy sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint .. _`PyCon 06 people`: http://codespeak.net/pypy/extradoc/sprintinfo/pycon06/people.txt -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: read-only attributes
limodou wrote: On 2/10/06, john peter [EMAIL PROTECTED] wrote: (snip) what do i have to do if i want my application code to have read-only attributes? I think you may consider property() built-in function: property( [fget[, fset[, fdel[, doc) Return a property attribute for new-style classes (classes that derive from object). fget is a function s/function/callable/ for getting an attribute value, likewise fset is a function for setting, and fdel a function for del'ing, an attribute. Typical use is to define a managed attribute x: class C(object): def __init__(self): self.__x = None def getx(self): return self.__x def setx(self, value): self.__x = value def delx(self): del self.__x x = property(getx, setx, delx, I'm the 'x' property.) Note that you don't need to define all three accessors. For a 'read-only' attribute, just define the getter: class ReadOnly(object): def __init__(self, x): self._x = x x = property(fget=lambda self: self._x) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: breaking from loop
Ritesh Raj Sarraf enlightened us with: bFound = True break return bFound I see two weird things. First of all, the retun statement won't be reached due to the break before it. Let's assume the break isn't needed, and you want just the return. Why set the variable if you're going to return anyway? I'd change those three lines to return True. But since test directory is under temp, work_tree_copy makes two calls of the same function _but_ break only is able to get out from the inner call. Raise an exception and catch it at the outer level. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove BR using replace function?
Sion Arrowsmith wrote: Duncan Booth [EMAIL PROTECTED] wrote: Although I generally advise against overuse of regular expressions, this is one situation where regular expressions might be useful: [ ... ] nobr = re.compile('\W*br.*?\W*', re.I) Agreed (on both counts), but r'\s*br.*?\s*' might be better (consider what happens with an unfortunate... br in the middle if you use \W rather than \s). Yes, I don't really know why I wrote \W when I obviously meant \s. Thanks for correcting that. Even better might be r'(\s*br.*?)+\s*' to get multiple runs of br tags. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using bytecode, not code objects
On Sun, 29 Jan 2006 14:51:18 -0800, rumours say that Michael Spencer [EMAIL PROTECTED] might have written: http://www.effbot.org/librarybook/marshal.htm There's a typo in the text accompanying that example: img.get_magic() should be imp.get_magic(). The error is easy to explain: he's on PIL(s) for years. -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: breaking from loop
Ritesh Raj Sarraf wrote: Following is the code: def walk_tree_copy(sRepository, sFile, sSourceDir, bFound = None): try: if sRepository is not None: for name in os.listdir(sRepository): path = os.path.join(sRepository, name) if os.path.isdir(path): walk_tree_copy(path, sFile, sSourceDir, bFound) elif name.endswith('.foo') or name.endswith('.bar'): if name == sFile: Pick /one/ the conditions - file name must be ... - file must end with ... or ... try: shutil.copy(path, sSourceDir) except IOError, (errno, errstring): errfunc(errno, errstring) except shutil.Error: print name + is available in + sSourceDir + Skipping Copy! bFound = True break return bFound except OSError, (errno, strerror): print errno, strerror This function allows me to walk into a directory based tree and search for files ending with .foo and .bar. My requirement is to copy .foo/.bar. Say in directory temp=test=test.bar is found. So shutil.copy will copy it. I want that once the copy is done, it should make bFound = True and get out. But since test directory is under temp, work_tree_copy makes two calls of the same function _but_ break only is able to get out from the inner call. Where am I wrong in this code ? Is there a better way to implement it ? An implementation on top of os.walk() can simplify things a bit: import os import shutil def files(root): for path, folders, files in os.walk(root): for file in files: yield path, file def copy_first_match(repository, filename, dest_dir): # aka walk_tree_copy() for path, file in files(repository): if file == filename: shutil.copy(os.path.join(path, file), dest_dir) return True return False files() and os.walk() take care of the recursion, and you can just break or return from the loop in copy_first_match(). Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Raymond Hettinger wrote: [Alex] So what is the rationale for having list SO much harder to use in such a way, than either set or collections.deque? Sounds like a loaded question ;-) If you're asking why list's don't have a clear() method, the answer is that they already had two ways to do it (slice assignment and slice deletion) and Guido must have valued API compactness over collection polymorphism. The latter is also evidenced by set.add() vs list.append() and by the two pop() methods having a different signatures. Sounds to me that it is a preference(style, whatever), rather than some other posts of this thread argued that del L[:] is better. If you're asking why your specific case looked so painful, I suspect that it only looked hard because the adaptation was force-fit into a lambda (the del-statement or slice assignment won't work as an expression). You would have had similar difficulties embedding try/except logic or a print-statement. Guido, would of course recommend using a plain def-statement: L = list() def L_clearer(L=L): del L[:] for listbunch in buncher(src, '', L, L.append, L_clearer): print listbunch Is that really clearer ? While it is still very localized(just read a few lines up for the definition), buncher(src, '', L.append, L.clear) seems to be clearer to me, especially there are two similar construct on set/dict above, even the Alex's lambda form conveys more info, IMO. Usng the new partial function, may be it can be written as : buncher(src.'', L, L.append, partial(L.__delslice__, 0, sys.maxint)) #assuming list can have at at most maxint items. -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting filename-encoding (on WinXP)?
On 2 Feb 2006 08:03:14 -0800, rumours say that Tim N. van der Leeuw [EMAIL PROTECTED] might have written: So now what I need to know is, how do I find out in what encoding a particular filename is? Is there a portable way for doing this? You said the filename comes as data, and not as contents of os.listdir(), right? You can only know (for almost certain) what encoding is *not* the filename (by looping over encodings and marking those where .decode fails). If it was textual data, you could be more successful in guessing (btw, it's been a long time since I requested example texts from various encodings for my encoding-guessing app, but I was sent only one) by testing characters in pairs and their frequencies. -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: breaking from loop
Ritesh Raj Sarraf wrote: Hi, Following is the code: def walk_tree_copy(sRepository, sFile, sSourceDir, bFound = None): try: if sRepository is not None: You're being overly defensive here. Passing None as first arg is clearly a programming error, so the sooner you detect it the better. Hence, just don't test, and let exceptions propagate. for name in os.listdir(sRepository): path = os.path.join(sRepository, name) if os.path.isdir(path): walk_tree_copy(path, sFile, sSourceDir, bFound) elif name.endswith('.foo') or name.endswith('.bar'): if name == sFile: Why do you *first* test on the extension, and *then* on the whole name ? The boolean expression: (name.endswith('.foo') or name.endswith('.bar')) and name == sFile logically implies that : sFile.endswith('.foo') or sFile.endswith('.bar') So the first test is pretty useless... Also, why hardcode such tests ? Python makes it easy to write generic (hence reusable) code. try: shutil.copy(path, sSourceDir) except IOError, (errno, errstring): errfunc(errno, errstring) ??? What is this function doing ? except shutil.Error: print name + is available in + sSourceDir + Skipping Copy! Don't assume the cause of the exception. FWIW, try the following snippet: f = open('test.txt', 'w') f.write('coucou') f.close() for i in range(10): ... shutil.copy('test.txt', 'testcopy.txt') ... Also, stdout is meant to be used for normal program outputs. Other messages should go to stderr. bFound = True break return bFound Err... this last statement won't be executed. except OSError, (errno, strerror): print errno, strerror This function allows me to walk into a directory based tree and search for files ending with .foo and .bar. My requirement is to copy .foo/.bar. Say in directory temp=test=test.bar is found. So shutil.copy will copy it. I want that once the copy is done, it should make bFound = True and get out. What's the use of setting bFound to True ? If you want to get out returning a value, just return that value : # dummy exemple def test(seq, target): for item in seq: if item == target: return True return False But since test directory is under temp, work_tree_copy makes two calls of the same function _but_ break only is able to get out from the inner call. You should first focus on making it work without worrying about error handling. Ensure that all return path are covered (in your actual implementation, your function always return None). Use a callback function for testing if a file should be copied, so your code has a chance of being reusable when specs evolve. And two hints: * exceptions are not only for error handling, they are also useful to control flow of execution... * generators and iterators are great AFAICT, what you're trying to do here is mainly to 1/ recursively search files matching a given condition in a directory tree 2/ do something with these files. A solution could be to split your code accordingly: def find_in_tree(tree_path, match): join = os.path.join isdir = os.path.isdir isfile = os.path.isfile for name in os.listdir(tree_path): fpath = join(tree_path, name) if isdir(fpath): for foundpath in find_in_tree(fpath, match) yield foundpath elif isfile(fpath) and match(fpath): yield fpath raise StopIteration def find_and_copy_to(tree_path, dest_path, match, stop_on_first_match=False): done = [] for fpath in find_in_tree(tree_path, match): if fpath not in done: shutil.copy(fpath, dest_path) done.append(fpath) if stop_on_first_match: break return done match_foo_bar = lambda fpath: \ fpath.endswith('.foo') or fpath.endswith('.bar') done = find_and_copy_to(sRepository, sSourceDir, match_foo_bar, stop_on_first_match=True) NB1 : not tested NB2: I'm not sure I clearly undestand your specs (you're mixing functional specs and implementation details in your description of you're trying to do), so this may not be exactly what you want... Also some stylistic advices: 1/ hungarian notation is *evil* - and even worse in a dynamically typed language. Better use explicit names. What's important is not the type of a variable, but it's role. 2/ string formating is fine print sys.stderr, \ %s is available in %s - skipping copy % (filename, source_dir) Is there a better way to implement it ? Probably. Anyway, the better implementation is usually no implementation. What about: find $Repository -name *.bar -exec cp {}
Re: Hi reliability files, writing,reading and maintaining
On Wed, 08 Feb 2006 00:29:16 +0100, rumours say that Xavier Morel [EMAIL PROTECTED] might have written: You can also nest Raid arrays, the most common nesting are Raid 01 (creating Raid1 arrays of Raid0 arrays), Raid 10 (creating Raid0 arrays of Raid1 arrays), Raid 50 (Raid0 array of Raid5 arrays), and the Raids for Paranoids, Raid 15 and Raid 51 arrays (creatung a Raid5 array of Raid1 arrays, or a Raid1 array of Raid5 arrays, both basically means that you're wasting most of your storage space for redundancy informations, but that the probability of losing any data is extremely low). Nah, too much talk. Better provide images: http://www.epidauros.be/raid.jpg -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: random playing soundfiles according to rating.
On 8 Feb 2006 19:49:09 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I am a little bit stuck I want to play a bunch of soundfiles randomly, but i want to give each soundfile a rating (say 0-100) and have the likelihood that the file be chosen be tied to its rating so that the higher the rating the more likely a file is to be chosen. Then i need some additional flags for repetition, and some other business. I am guessing a dictionary would be a great way to do this, with the key being the soundfile name and the values being my ratings and other flags associated data. It depends how accurate you want the likelihood to be and how important performance is. I was thinking about this in respect of queueing mp3s from my collection (10,000+) to be played based on a 1-5 star rating (five stars is five times more likely to be played than 1 star). If speed is no issue (for example you can queue an mp3 while the current one is playing), then Ben's solution is the classic one. Store the total of all your scores (or calculate it on the fly if you don't have too many files), pick a random number up to that total, and then iterate through all your scores, subtracting each score from the total, until the total reaches zero, and then play that file. However that approach gets slower and slower the more files you have (slower to calculate the total and slower to iterate through the files). If speed is more of an issue, you could give up on trying to use a perfect probability, and just pick 10 (or 50, or 100) files at random, and then play one of those based on the above approach. Ed -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Bryan Olson wrote: Magnus Lycka wrote: Do you really have a usecase for this? It seems to me that your argument is pretty hollow. Sure: if item_triggering_end in collection: handle_end(whatever) collection.clear() Or maybe moving everything from several collections into a single union: big_union = set() for collection in some_iter: big_union.update(t) collection.clear() I don't understand the second one. Where did 't' come from? Anyway, tiny code snippets are hardly usecases. Are these from real code? If they are, why aren't there support for emptying lists? Have you patched your Python? Didn't you actually need to support lists? I still don't see any convincing usecase for the kind of ducktyping you imply. There are certainly situations where people have used lists or dicts before there were sets in Python, and want to support both variants for a while at least, but since their APIs are so differnt for these types, .clear() seems like a non-issue. If this was a problem in the real world, I bet we'd see a lot of code with functions similar to this: def clear(container): try: del container[:] except TypeError: container.clear() If you *do* have this problem, this is a very simple workaround. As far as I understand, the only operation which is currently used by all three collections is .pop, but that takes a different number or parameters, since these collections are conceptually different! The all support len, iteration, and membership test. Ok. Forgot that. id(), str() and repr() as well. Still, after almost 10 years of Python programming I can't remember that I ever ran into a situation where I ever needed one single piece of code to empty an arbitrary container. It's trivial to solve, so I wouldn't have stopped to think about it for even a minute if it happened, but I still don't think it happened.This was never a problem for me, and I don't think I saw anyone else complain about it either, and I've seen plenty of complaints! ;) I can understand the argument about making it easy to remember how to perform an action. I think the current situation is correct. To introduce redunancy in this case (del x[:] == x.clear()) would not be an improvement of Python. In the long run, such a strategy of synonyms would make Python much more like Perl, and we don't want that. So I can understand that the question pops up though (but not why it gets such proportions). I don't buy this duck-typing argument though. Considering how little it would change in unifying these divergent APIs, it still sounds as hollow to me. Many algorithms make sense for either sets or lists. Even if they cannot work on every type of collection, that's no reason not to help them be as general as logic allows. class BryansList(list): ... add=list.append ... def clear(self): ... del self[:] ... b = BryansList([1,2,3,4,5]) b [1, 2, 3, 4, 5] b.add(6) b.clear() b [] Happy now? You can keep it, I don't need it. :) Most of us consider minimal interfaces a virtue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Magnus Lycka wrote: class BryansList(list): ... add=list.append ... def clear(self): ... del self[:] ... b = BryansList([1,2,3,4,5]) b [1, 2, 3, 4, 5] b.add(6) b.clear() b [] Happy now? You can keep it, I don't need it. :) Most of us consider minimal interfaces a virtue. What kind of performance penalty are we talking about here ? list being such a fundamental thing, no one would like to use a slower version just for the clear/add method. And if it is a use when you really need to, it would make the code harder to understand as it would be sometimes it is BryansList, sometimes it is builtin list. That said, I don't find clear() to be useful as unless one needs to pass around a single copy of list object around and saved them for future use(which can be a source of subtle bug), just lst=[] is usually good enough for localized usage. -- http://mail.python.org/mailman/listinfo/python-list
Re: random playing soundfiles according to rating.
On Fri, 10 Feb 2006 09:59:43 +, rumours say that Ed Singleton [EMAIL PROTECTED] might have written: If speed is no issue (for example you can queue an mp3 while the current one is playing), then Ben's solution is the classic one. Store the total of all your scores (or calculate it on the fly if you don't have too many files), pick a random number up to that total, and then iterate through all your scores, subtracting each score from the total, until the total reaches zero, and then play that file. However that approach gets slower and slower the more files you have (slower to calculate the total and slower to iterate through the files). Hm... just playing: import random, itertools scored=[('bad',1), ('not that bad',2),('ok',3),('better',4),('best',5)] def player(lst): def forever(lst): while 1: for item in lst: yield item total_score= sum(x[1] for x in lst) scanner= forever(lst) while 1: next_score= random.randrange(total_score) for item in scanner: if next_score = item[1]: yield item[0] next_score+= random.randrange(total_score) else: next_score-= item[1] print list(itertools.islice(player(scored), 0, 20)) ['better', 'ok', 'best', 'not that bad', 'best', 'best', 'best', 'not that bad', 'ok', 'best', 'best', 'bad', 'better', 'better', 'better', 'ok', 'ok', 'not that bad', 'best', 'best'] -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Magnus Lycka wrote: Bryan Olson wrote: Magnus Lycka wrote: Do you really have a usecase for this? It seems to me that your argument is pretty hollow. Sure: if item_triggering_end in collection: handle_end(whatever) collection.clear() Or maybe moving everything from several collections into a single union: big_union = set() for collection in some_iter: big_union.update(t) collection.clear() I don't understand the second one. Where did 't' come from? Cut-and-past carelessness. Meant to update with 'collection'. Anyway, tiny code snippets are hardly usecases. The task is the usecase. [...] I still don't see any convincing usecase for the kind of ducktyping you imply. I didn't say I could convince you. I said that when different types can support the same operation, they should also support the same interface. That's what enables polymorphism. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing XML scheme (xsd) to python objects
Yes, documents should also be validated against the schema. I finally managed to compile my schema with generateDS.py but I haven't tested the result because of my poor knowledge of Python. So I have to wait until the group does which wanted to use my schema. Thanks for your answer! Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
If you're asking why list's don't have a clear() method, the answer is that they already had two ways to do it (slice assignment and slice deletion) and Guido must have valued API compactness over collection polymorphism. The latter is also evidenced by set.add() vs list.append() and by the two pop() methods having a different signatures. [bonono] Sounds to me that it is a preference(style, whatever), rather than some other posts of this thread argued that del L[:] is better. It was simply design decision reflecting Guido's values on language economics. If you're asking why your specific case looked so painful, I suspect that it only looked hard because the adaptation was force-fit into a lambda (the del-statement or slice assignment won't work as an expression). You would have had similar difficulties embedding try/except logic or a print-statement. Guido, would of course recommend using a plain def-statement: L = list() def L_clearer(L=L): del L[:] for listbunch in buncher(src, '', L, L.append, L_clearer): print listbunch Is that really clearer ? While it is still very localized(just read a few lines up for the definition), buncher(src, '', L.append, L.clear) seems to be clearer to me, especially there are two similar construct on set/dict above, Hmm, my post was so long that the main points were lost: * the example was tricky only because of the unnecessary in-place update requirement * eliminating that requirement solves the adaptation problem and simplifies the client code * the constructor API is polymorphic, use it * adding clear() doesn't help with the other API variations between set, list, dict, etc. * Guido's decision for distinct APIs is intentional (i.e. set.add vs list.append) * Alex's adapter PEP is likely a better solution for forcing polymorphism on unlike APIs * When a lambda becomes awkward, Guido recommends a separate def * Guido has no sympathy for atrocities resulting from squeezing everything into one line * Alex's example can be simplified considerably: def buncher(sourceit, sentinel, constructor): for k, g in groupby(sourceit, lambda x: x != sentinel): if k: yield constructor(g) for setbunch in buncher(src, '', set): print setbunch * The improved version has no need for list.clear(). End of story. Raymond -- http://mail.python.org/mailman/listinfo/python-list
a second TKinter
I found if I opened a second TKinter, Python will go out of work. But I need two graph outputs at the same time. What to do? Linda. -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining an operating system's default browser
John McMonagle wrote: Is there a python module which can determine an operating system's default web browser application. I would like to use it in the following context: I have a GUI application where all the documentation is written as html pages. I wish to have these html help pages open in the default browser when selected from the application's Help menu If python can determine the path to the default browser, I can then just spawn it. Regards, John McMonagle I think the htmlview command is used for this purpose (displaying html documentation of applications) on many Linuxes. So you could try os.system('htmlview'). Given the variety of Unixes (and even Linuxes) out there this is not a general solution. So I would try htmlview first. If it does not work, the program could ask the user for his favourite browser the 1st time he looks at docs, and save this to a configuration file. -- http://mail.python.org/mailman/listinfo/python-list
AdaptionFailure: How to use Interfaces with PyProtocols ?
Hi, I tried to understand the docs of Peak's PyProtocols, and failed. I use PyProtocols v0.93 final. I fetched the ...tar.gz file for Linux and installed it using the setup.py. Here's my Hello-World-like example, that defines a Duck, which implements the given Interface: from protocols import Interface,adapt,advise class Quackable(Interface): def quack(loudness): print how loud to quack class Duck: advise(instancesProvide=[Quackable,]) def quack(self, loudness): print quack! %s loud%(loudness) if __name__ == __main__: d = adapt(Duck, Quackable) # this line raises the failure d.quack(3) But it does not work that way. It get this AdaptionFailure : File ...interfaces.py, line 14, in ? d = adapt(Duck, Quackable) File C:\cygwin\home\pje\PyProtocols\src/protocols/_speedups.pyx, line 199, in _speedups.adapt File C:\cygwin\home\pje\PyProtocols\src/protocols/_speedups.pyx, line 188, in _speedups._adapt protocols.adapters.AdaptationFailure: (Can't adapt, class __main__.Duck at 0xb7bcc47c, class '__main__.Quackable') *** Or is my Duck code wrong ? Anybody knowing how to use an Interface ? Thank you very much- Nebur Remark:There seems to be some windows stuff in PyProtocols (C:\...) - a bug ? (I re-installed PyProtocols with option --without-speedups but nothing changed.) -- http://mail.python.org/mailman/listinfo/python-list
Re: a second TKinter
On 2/10/06, Michael Foord [EMAIL PROTECTED] wrote: On 10/02/06, linda.s [EMAIL PROTECTED] wrote: I found if I opened a second TKinter, Python will go out of work. But I need two graph outputs at the same time. What to do? Linda. Hello linda (?), How are you opening a 'second Tkinter' ? There is no problem with having two top level windows at the same time, you can't hjave two 'mainloops' though. :-) All the best, Fuzzyman What does having two top level windows mean? Can you give an example? For opening a second tkinter, i mean that I run python using PythonWin: if I run the code again when the first Tk is still open, then the program will crash. -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonic exec* spawn*
os.fork() does that (on Mac and Unix). Okay, but how? Sorry, fork() is implemented strictly on a 'need to know' basis :-) It seems to me that if the process which issued os.fork() ends, then the forked process also ends. No, no, they're not a quantum mechanic photon pair. Every process decides for itself if and when to end. As long as it's not signalled/killed, that is. But the execute of longer( data ) should keep going even though the original program ended. I'm pretty sure it's something basic and probably I'm not aware of the right concepts and that's why I can't find the right place to look in the docs. You can search for daemonize. Here's a recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 The concept is best explained in this book: http://www.kohala.com/start/apue.html Okay, thanks a lot, I'll look into that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Raymond Hettinger wrote: [...] If you're asking why list's don't have a clear() method, the answer is that they already had two ways to do it (slice assignment and slice deletion) and Guido must have valued API compactness over collection polymorphism. That's a decision from long ago. Now that we have sets and the iterable protocol, the case is quite different. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: module with __call__ defined is not callable?
On Wed, 08 Feb 2006 07:14:04 -0500, Steve Holden wrote: Someone had to code Python so that it raised an error when you try to call a module object. Is there a reason why module() should not execute module.__call__()? I would have thought that by the duck typing principle, it shouldn't matter whether the object was a class, a module or an int, if it has a __call__ method it should be callable. It would nice if you could make modules callable. Right. While we're at it, why don't we make strings callable. I don't believe strings have a __call__ method, nor do I see any compelling case for giving one to them. But one could sub-class strings so they had a __call__ method, in which case they should be callable. Just like objects with a __len__ method work with len(), and objects with a __getitem__ method are indexable. Calling a string could call the function whose name (in some namespace or other) was in the string. Or it could do whatever the __call__ method says it should do. And we can make integers callable too - that could just assume that the integer was the address of a function to be called. No, that wouldn't work, because Python doesn't have pointers. You can't just jump to an address in memory and execute it. That would be Bad. In case you think I'm joking, I am. I'm not. Why should a module be callable? What's the advantage? Modules could behave not only as collections of functions, methods, classes etc., but as single entry-point functions themselves. Or, to put it another way, modules are not just collections of code which gets called by other code, but could also be tools in the Unix sense. Here is a (trivial) hypothetical example: py import sillycase py sillycase(hello world) hElLO wOrLd py sillycase.start_with_lowercase # can still see the internals True A side-effect of this is you wouldn't need so many calls like glob.glob, dis.dis or bisect.bisect. If Python were smart enough to automatically execute the __call__ method of a module (if it has one) when the module is given as a command line argument, we could get rid of this boiler-plate code found in oh-so-many scripts: if __name__ == '__main__': main() # __call__() would be better Should we be able to add two modules together, yielding a module that contains all the code of both modules? If modules had a __add__ method, then moduleA + moduleB should do whatever the __add__ method says. Just as when you add a module to a class instance, it will do whatever the class __add__ method says. Frankly I can't think of anything useful adding two modules would do, but maybe that's my failure of imagination. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Dump of a python process
Thank you for your info. Now I have read that a simple call os.getpid() returned the linux identifier of the thread in latest python versions, but I'm using Python 2.3 and 2.4 and this call returns always the same id I only want to take the pid of the thread but isn't as easier as it seems. -- View this message in context: http://www.nabble.com/Thread-Dump-of-a-python-process-t1089322.html#a2868401 Sent from the Python - python-list forum at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining an operating system's default browser
John McMonagle wrote: Is there a python module which can determine an operating system's default web browser application. I would like to use it in the following context: I have a GUI application where all the documentation is written as html pages. I wish to have these html help pages open in the default browser when selected from the application's Help menu If python can determine the path to the default browser, I can then just spawn it. The module webrowser module does this - and I use it for exactly this purpose. :-) Fuzzyman http://www.voidspace.org.uk/python/index.shtml Regards, John McMonagle -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining an operating system's default browser
John McMonagle wrote: On Thu, 2006-02-09 at 17:53 -0600, Larry Bates wrote: You don't have to determine it. Just os.startfile('page1.html') and let the OS figure it out. Works great for Windows - not available on Unix though. Take a look at the desktop module for similar functionality for KDE, GNOME and the Mac OS X desktop environment (as well as Windows, of course): http://www.python.org/pypi/desktop Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Scientific Computing with NumPy
where to download numpy for Python 2.3 in Mac? Thanks! Linda -- http://mail.python.org/mailman/listinfo/python-list
help regarding installing python documentation
Hi I have installed the python 2.4 version and downloaded the HTML documentation also. But when I give the command help( ) in the IDLE command prompt and ' while ' ,it says Sorry, topic and keyword documentation is not available because the PythonHTML documentation files could not be found. If you have installed them,please set the environment variable PYTHONDOCS to indicate their location. I don't know how to set the variable PYTHONDOCS .kindly help . Sharmishta -- http://mail.python.org/mailman/listinfo/python-list
Re: a second TKinter
linda.s wrote: On 2/10/06, Michael Foord [EMAIL PROTECTED] wrote: On 10/02/06, linda.s [EMAIL PROTECTED] wrote: I found if I opened a second TKinter, Python will go out of work. But I need two graph outputs at the same time. What to do? Linda. Hello linda (?), How are you opening a 'second Tkinter' ? There is no problem with having two top level windows at the same time, you can't hjave two 'mainloops' though. :-) All the best, Fuzzyman What does having two top level windows mean? Can you give an example? For opening a second tkinter, i mean that I run python using PythonWin: if I run the code again when the first Tk is still open, then the program will crash. You are actually doing well to run even *one* Tkinter-based application under PythonWin, since PythonWin is an MFC-based Windows application. There may well be conflict between the multiple windowing modules in use. Not a good idea to run GUI-based applications under an IDE that isn't designed to handle them. Sorry. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: a second TKinter
On 2/10/06, Steve Holden [EMAIL PROTECTED] wrote: linda.s wrote: On 2/10/06, Michael Foord [EMAIL PROTECTED] wrote: On 10/02/06, linda.s [EMAIL PROTECTED] wrote: I found if I opened a second TKinter, Python will go out of work. But I need two graph outputs at the same time. What to do? Linda. Hello linda (?), How are you opening a 'second Tkinter' ? There is no problem with having two top level windows at the same time, you can't hjave two 'mainloops' though. :-) All the best, Fuzzyman What does having two top level windows mean? Can you give an example? For opening a second tkinter, i mean that I run python using PythonWin: if I run the code again when the first Tk is still open, then the program will crash. You are actually doing well to run even *one* Tkinter-based application under PythonWin, since PythonWin is an MFC-based Windows application. There may well be conflict between the multiple windowing modules in use. Not a good idea to run GUI-based applications under an IDE that isn't designed to handle them. Sorry. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ so run from the terminal? -- http://mail.python.org/mailman/listinfo/python-list
Re: a second TKinter
linda.s wrote: On 2/10/06, Steve Holden [EMAIL PROTECTED] wrote: linda.s wrote: On 2/10/06, Michael Foord [EMAIL PROTECTED] wrote: On 10/02/06, linda.s [EMAIL PROTECTED] wrote: I found if I opened a second TKinter, Python will go out of work. But I need two graph outputs at the same time. What to do? Linda. [...] so run from the terminal? Yes, but wouldn't just trying that have been easier than asking me? ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Pulling all n-sized combinations from a list
[EMAIL PROTECTED] wrote: But using the free SDK compiler from MS? That seems elusive. Have you seen this? http://www.vrplumber.com/programming/mstoolkit/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
slogging_away wrote: Adding it back in cause it to not run - no error message - just a return to the in the IDLE console window much as if I had executed the 'Check Module' command. What happens if you run it from the command line instead of IDLE? After all, it might be some problem in IDLE involved here. Even if it doesn't work correctly outside IDLE, I was thinking that IDLE might swallow some kind of error message. -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining an operating system's default browser
John McMonagle [EMAIL PROTECTED] wrote: Is there a python module which can determine an operating system's default web browser application. http://docs.python.org/lib/module-webbrowser.html -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: AdaptionFailure: How to use Interfaces with PyProtocols ?
On Feb 10, 2006, at 4:21 AM, Nebur wrote: Hi, I tried to understand the docs of Peak's PyProtocols, and failed. I use PyProtocols v0.93 final. I fetched the ...tar.gz file for Linux and installed it using the setup.py. Here's my Hello-World-like example, that defines a Duck, which implements the given Interface: from protocols import Interface,adapt,advise class Quackable(Interface): def quack(loudness): print how loud to quack class Duck: advise(instancesProvide=[Quackable,]) def quack(self, loudness): print quack! %s loud%(loudness) if __name__ == __main__: d = adapt(Duck, Quackable) # this line raises the failure d.quack(3) You've *almost* got it. The adaption adapts *instances* of a class. Your setup is correct, but change your __main__ to: if __name__ == __main__: d = Duck() adapted_d = adapt(d, Quackable) adapted_d.quack(3) or more concisely: if __name__ == __main__: d = adapt(Duck(), Quackable) d.quack(3) Of course, it's kind of a pointless example, because you're adapting something that declares to be Quackable to a Quackable object, but I'm sure you know that :) Most of my own work with PyProtocols would not involve objects that just had 'instancesProvide', but would also have 'asAdapterFor' (at least, I think it's 'asAdapterFor', it's been a few months since I've touched my PyProtocols related code) Jay P. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python good for web crawlers?
Paul Rubin wrote: Xavier Morel [EMAIL PROTECTED] writes: BeautifulSoup... The API of the package is extremely simple, straightforward and... obvious. I did not find that. I spent a few minutes looking at the documentation and it wasn't obvious at all how to use it. Maybe I 1. read about Soup and mechanize http://sig.levillage.org/?p=599 2. flip thru oreilly spidering hacks book (put on YAPH t-shirt) 3. go at your task 4. write Spidering Hacks in Python, 1st edition. Cite me as inspiration. -- http://mail.python.org/mailman/listinfo/python-list
RE: Python-list Digest, Vol 29, Issue 147
nope, we where one short plus mark just pulled out so now we're two short. if you can get ANYONE that would be great? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: 10 February 2006 02:21 To: python-list@python.org Subject: Python-list Digest, Vol 29, Issue 147 Send Python-list mailing list submissions to python-list@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Python-list digest... IMPORTANT NOTICE: If you are not the intended recipient of this email (or such person's authorised representative), then : (a) please notify the sender of this email immediately by return email, facsimile or telephone and delete this message from your system; (b) you may not print, store, forward or copy this message or any part thereof or disclose or cause information in this message to be disclosed to any other person. The information in or attached to this email message is confidential and may be subject to legal privilege and client confidentiality. In addition this message is subject to important restrictions, qualifications and disclaimers (the disclaimer) that must be accessed and read by copying the following address into your Internet browser's address bar : http://www.investec.com/emaildisclaimer/ The disclaimer also provides our corporate information and names of our directors as required by law. The disclaimer is deemed to form part of this message in terms of Section 11 of the Electronic Communications and Transactions Act 25 of 2002. If you cannot access the disclaimer, please obtain a copy thereof from us by sending an email to : [EMAIL PROTECTED] Certain entities within the Investec group of companies are registered as authorised financial services providers. The details of these entities are available on our website : http://www.investec.com/southafrica -- http://mail.python.org/mailman/listinfo/python-list
Re: anybody help me
On Fri, 10 Feb 2006 02:44:41 -0800, Rahul wrote: Hi Everybody I have some problem in my script. please help me. I'll do better: I'll help you help yourself. First step: what is the problem? Saying I have a problem and expecting us to guess what it is will not give good results. Second step: what is the ENTIRE traceback you get when you run the script? Do not write it out by memory -- copy and paste it exactly as Python prints it. Third step: do you understand what the traceback is telling you? Hint: Python almost always knows what you've done wrong. You just have to pay attention. Fourth step: if you still can't determine the error, don't expect others to debug a 1000+ line script. Spend some time cutting the script back to the smallest possible version that still gives you the same error. This may even help you understand what the error is. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: apostrophe or double quote?
On 09 Feb 2006 12:54:04 + (GMT) Sion Arrowsmith [EMAIL PROTECTED] wrote: Terry Hancock [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Just to present a complete picture, not mentioned in this thread are triple-quoted strings: [ ... ] Also in the mode of beating a dead horse ... ;-) Some people prefer to use single quotes for 'labels' (i.e. a name which is meaningful to the program, but not to the user), and reserve either double-quotes or triple-double-quotes for text to be shown to the user. [ ... ] Hmm, I made both these points a couple of posts upthread, but it didn't appear to get through the news-mail gateway. Ah well, it all came up on the list about a month or two ago anyway (I guess. I don't know, maybe it was a year ago), so I'm just repeating it. -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Dump of a python process
Shanon wrote: Thank you for your info. Now I have read that a simple call os.getpid() returned the linux identifier of the thread in latest python versions, but I'm using Python 2.3 and 2.4 and this call returns always the same id I only want to take the pid of the thread but isn't as easier as it seems. I believe the underlying call to thread.start_new_thread() already returns the thread identifier that you want, but I haven't tried it recently and don't recall for sure. To use this, however, you'd have to patch the source or subclass, as I mentioned. I did this once and stored the result in the Thread as an attribute called .threadId and don't recall any problem using that. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread Dump of a python process
Shanon wrote: Thank you for your info. Now I have read that a simple call os.getpid() returned the linux identifier of the thread in latest python versions, but I'm using Python 2.3 and 2.4 and this call returns always the same id I only want to take the pid of the thread but isn't as easier as it seems. Oops, please ignore my other reply to this post. I didn't grab the start_new_thread() result, but instead grabbed the result of thread.get_ident() and stored that. The docs claim this is not a value that necessarily relates to anything in the outside world (Return the `thread identifier' of the current thread. This is a nonzero integer. Its value has no direct meaning; it is intended as a magic cookie ...) so if it happens to match the thread id from the OS's point of view, it's an implementation detail you couldn't rely on. So the general idea I gave might be useful, but I don't know precisely how to do exactly what you are asking. Sorry. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
slogging_away wrote: It appears it may not be a 'if' statment limitation at all. This is because I added another 800 element array Looks like a memory problem then... in which to store the various error messages generated when a configuration file error is deteceted based on their severity level. Why storing error messages ? Why don't you just write'em out (be it to stdout or to a file) ? (snip) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: help regarding installing python documentation
N Sharmishta-in1769c wrote: Hi I have installed the python 2.4 version and downloaded the HTML documentation also. But when I give the command help( ) in the IDLE command prompt and ' while ' ,it says */Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found. If you have installed them, please set the environment variable PYTHONDOCS to indicate their location./* *//* I don't know how to set the variable PYTHONDOCS .kindly help . Environment variables are handled by the operating system, so until we know what operating system you are on, we can't provide a complete answer... -- http://mail.python.org/mailman/listinfo/python-list
Create dict from two lists
I have two lists which I want to use to create a dictionary. List x would be the keys, and list y is the values. x = [1,2,3,4,5] y = ['a','b','c','d','e'] Any suggestions? looking for an efficent simple way to do this...maybe i am just having a brain fart...i feel like this is quit simple. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
py wrote: I have two lists which I want to use to create a dictionary. List x would be the keys, and list y is the values. x = [1,2,3,4,5] y = ['a','b','c','d','e'] Any suggestions? looking for an efficent simple way to do this...maybe i am just having a brain fart...i feel like this is quit simple. dict(zip(x,y)) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
On Fri, 2006-02-10 at 08:51, py wrote: I have two lists which I want to use to create a dictionary. List x would be the keys, and list y is the values. x = [1,2,3,4,5] y = ['a','b','c','d','e'] Any suggestions? looking for an efficent simple way to do this...maybe i am just having a brain fart...i feel like this is quit simple. d = dict(zip(x,y)) -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Post-PyCon PyPy Sprint: February 27th - March 2nd 2006
The next PyPy sprint is scheduled to take place right after PyCon 2006 in Dallas, Texas, USA. We hope to see lots of newcomers at this sprint, so we'll give friendly introductions. Note that during the Pycon conference we are giving PyPy talks which serve well as preparation. Goals and topics of the sprint -- While attendees of the sprint are of course welcome to work on what they wish, we offer these ideas: - Work on an 'rctypes' module aiming at letting us use a ctypes implementation of an extension module from the compiled pypy-c. - Writing ctypes implementations of modules to be used by the above tool. - Experimenting with different garbage collection strategies. - Implementing Python 2.5 features in PyPy - Implementation of constraints solvers and integration of dataflow variables to PyPy. - Implement new features and improve the 'py' lib and py.test which are heavily used by PyPy (doctests/test selection/...). - Generally experiment with PyPy -- for example, play with transparent distribution of objects or coroutines and stackless features at application level. - Have fun! Location The sprint will be held wherever the PyCon sprints end up being held, which is to say somewhere within the Dallas/Addison Marriott Quorum hotel. For more information see the PyCon 06 sprint pages: - http://us.pycon.org/TX2006/Sprinting - http://wiki.python.org/moin/PyCon2006/Sprints Exact times --- The PyPy sprint will from from Monday February 27th until Thursday March 2nd 2006. Hours will be from 10:00 until people have had enough. Registration, etc. -- If you know before the conference that you definitely want to attend our sprint, please subscribe to the `PyPy sprint mailing list`_, introduce yourself and post a note that you want to come. Feel free to ask any questions or make suggestions there! There is a separate `PyCon 06 people`_ page tracking who is already planning to come. If you have commit rights on codespeak then you can modify yourself a checkout of http://codespeak.net/svn/pypy/extradoc/sprintinfo/pycon06/people.txt .. _`PyPy sprint mailing list`: http://codespeak.net/mailman/listinfo/pypy-sprint .. _`PyCon 06 people`: http://codespeak.net/pypy/extradoc/sprintinfo/pycon06/people.txt -- M-x psych[TAB][RETURN] -- try it -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
py [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have two lists which I want to use to create a dictionary. List x would be the keys, and list y is the values. x = [1,2,3,4,5] y = ['a','b','c','d','e'] Any suggestions? looking for an efficent simple way to do this...maybe i am just having a brain fart...i feel like this is quit simple. thanks. x = [1,2,3,4,5] y = ['a','b','c','d','e'] dict(zip(x,y)) {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'} -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: breaking from loop
Thanks to everyone. It is really the best place and the best people to learn from. Here's what I followed from the discussion: def files(root): for path, folders, files in os.walk(root): for file in files: yield path, file def copy_first_match(repository, filename, dest_dir): # aka walk_tree_copy() for path, file in files(repository): if file == filename: try: shutil.copy(os.path.join(path, file), dest_dir) sys.stdout.write(%s copied from local cache %s. % (file, repository)) except shutil.Error: sys.stdout.write(%s is available in %s. Skipping Copy! % (file, dest_dir)) return True return False All I've added is the exception check because in case file is available in dest_dir, I want to display a message. Since I'm still new and learning will be great if you let me know if this is the proper way or not. Thanks to everyone once again. It's been a very good experience understanding everyone's comments. Regards, rrs -- http://mail.python.org/mailman/listinfo/python-list
How to invoke a tkinter menu *itself*
Hi, I've spent a pleasant hour or so trying to bring up a top-level Tk menu at the same spot as it would appear if I had actually clicked the menu. That is, I want to bring up a menu from the keyboard. The problem is computing the x and y args to menu.post. menu.winfo_x and menu.winfo_rootx are always 0, presumably be cause the menu isn't packed. And I haven't been able to use menu.invoke(??) to invoke the menu *itself*. One would think this would be a basic Tk functionality. Any ideas? Thanks. Edward P.S. Here is my best so far. (It must be run from Leo for the Leo magic to work.) import tkFont name = 'File' # The menu to be invoked. # A list of all of Leo's menus. menus = ('File','Edit','Outline','Plugins','Cmds','Window','Help') # Compute the *approximate* x offsets of each menu. offsets = {} ; n = 0 for z in menus: menu = c.frame.menu.getMenu(z) fontName = menu.cget('font') font = tkFont.Font(font=fontName) offsets[z] = n # A total hack: sorta works on windows. n += font.measure(z+' '*4)+1 top = c.frame.top # Leo magic. topx,topy = top.winfo_rootx(),top.winfo_rooty() menu = c.frame.menu.getMenu(name) # Leo magic. menu.post(topx+offsets.get(name,0),topy) EKR Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
Diez B. Roggisch wrote: py wrote: I have two lists which I want to use to create a dictionary. List x would be the keys, and list y is the values. x = [1,2,3,4,5] y = ['a','b','c','d','e'] Any suggestions? looking for an efficent simple way to do this...maybe i am just having a brain fart...i feel like this is quit simple. dict(zip(x,y)) Diez I'd even suggest using izip (from itertools), it's often much faster than zip (end result is the same). Demo: from itertools import izip l1 = range(5000) l2 = range(5000, 1) from timeit import Timer t1 = Timer(dict(zip(l1, l2)), from __main__ import l1, l2) t2 = Timer(dict(izip(l1, l2)), from __main__ import l1, l2, izip) min(t1.repeat(5, 1)) 17.989041903370406 min(t2.repeat(5, 1)) 10.381146486494799 42% speed gain from using izip instead of zip (memory was not an issue during the test, machine had 1.3Gb of available ram) -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
Thanks, itertools.izip and just zip work great. However, I should have mentioned this, is that I need to keep the new dictionary sorted. d = {1:'first', -5 : 'negative 5', 6:'six', 99:'ninety-nine', 3:'three'} keys = d.keys() keys.sort() vals = map(d.get, keys) At this point keys is sorted [-5, 1, 3, 6, 99] and vals is sorted ['negative 5', 'first', 'three', 'six', 'ninety-nine'] Using zip does not create the dictionary sorted in this order. new_d = dict(zip(keys, vals)) How can I use the two lists, keys and vals to create a dictionary such that the items keep their order? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mental Abuse
[EMAIL PROTECTED] wrote: || My abuser has been using the medical device to harass me the || last 4-5 years. I have no idea what type of a device is being || used on me. I believe the device is only available to || licensed pharmacist(s). I am not very familiar with the || intend usage of the device. As I understand, the device can || be used as a stimulator; 24 hours therapeutic session; ease || off a lot of emotion--anger, sadness, fear...ect.; enhance || recovery of mental illnesses. If abuse is the intention, it || can be used to sense what the other person's thinking or as a || form of communication through inner voices. In my case, the || abuser has been using it to insult me in every way he could || possible think of. As I know, a single device is only || effective if you are in the same city. Mulitple devices can || reach billion of people world wide. Fear of being evaluate || as mental ill due to lack of physical evidence. I am hoping || to find out more about the device, before reporting to the || police. If anyone know what type of a device has been using || on me. Who manufacture such a device. What can I do to stop || the abuser from such criminal act? Please email me at || [EMAIL PROTECTED], I would greatly appreciated. I am not sure of the device being used but try this http://zapatopi.net/afdb/ -- The power of artificial intelligence is nothing compared to the power of human stupidity. -- http://mail.python.org/mailman/listinfo/python-list
Re: What editor shall I use?
On 8 Feb 2006 06:48:30 -0800, Lad wrote: What editor shall I use if my Python script must contain utf-8 characters? I use XP The best (and free) are: Eclipse http://www.eclipse.org/ with pydev http://pydev.sourceforge.net/ SPE http://pythonide.stani.be/ Eric3 http://www.die-offenbachs.de/detlev/eric3.html win32 binary: http://www.quadgames.com/download/pythonqt/ All of them contain cool debugger and a lot of usefull options. If you want only plain text editor, you can use SciTe, vim, Notepad++ or whatever. -- Jarosław Zabiełło http://blog.zabiello.com -- http://mail.python.org/mailman/listinfo/python-list
To paletted image
Hello, this time I have a question about PIL usage, maybe if Lundh has some time he can answer me. I am experimenting different color quantization algorithms, so having computed the palette with a clustering function, I use the code below to quantize the original image to produce an image without dithering (so I can see better the quantization results). I have seen that the *standard* distance function I use isn't standard enough, because given the fixed palette computed by me, most graphics programs give me a different (better) quantized image. I don't know what's wrong/different in this quantize function, maybe you can tell me. I'd also like to know if there is a simpler code for PIL to do the same thing (given my palette and a truecolor image), but this is less important. I know the dither=Image.NONE for the im.convert() method, but I don't know a good way to use it in this problem. (Note that the quantize function below uses a perceptual-based color distance, but to do the quantization with PIL I can settle with its standard color distance function.) Thank you, bearophile # Input: # im = input truecolor image # palette = a palette computed by me, of about 32 colors # im_out = output image with no dithering def quantize(data, palette_short): out_data = [] for rgb in data: dist_min = 1e100 closest_col = None for col_pos, pal_col in enumerate(palette_short): # Standard distance #dr = rgb[0] - pal_col[0] #dg = rgb[1] - pal_col[1] #db = rgb[2] - pal_col[2] #d = dr*dr + dg*dg + db*db d = perceptualColorDistance(rgb, pal_col) if d dist_min: dist_min = d closest_col = col_pos out_data.append(closest_col) return out_data #.. import psyco; psyco.bind(quantize) # Copy of palette, to speed up quantization palette_short = list(palette) # Add duplicated colors (the last one) to produce a palette of 256 colors palette.extend( palette[-1] for i in xrange(256 - len(palette)) ) # Create empty paletted output image im_out = Image.new(P, im.size, 0) # Flatten the list of colors, for PIL #flattened_palette = flatten(palette) flattened_palette = [component for color in palette for component in color] # Put the computed palette in the output image im_out.putpalette(flattened_palette) # quantize the input image with the computed palette out_data = quantize(data, palette_short) # Put the computed data inside the output image im_out.putdata(out_data) # Save computed output image im_out.save(out_filename) -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
bruno at modulix wrote: Looks like a memory problem then... The system I am using has 2GB of memory, (unless you are syaing the memory is faulty). Why storing error messages ? Why don't you just write'em out (be it to stdout or to a file) ? I guess I could do that, (write them to a file as they are discovered). Right now the error messages are stored in the array and then the the array is scanned via, a for loop and the error messages are written to several files in different formats based on the severity of the errors, (on a per device basis, a per severity basis, etc.). This keeps the write statements to a minimum and in a central location of the script instead of having several statements for each individual error message spread throughout the script, (three write statements per error message at over 500 error messages would be a significant change). Not to complain but if I can't use arrays then thats a pretty significant limitation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
py wrote: Thanks, itertools.izip and just zip work great. However, I should have mentioned this, is that I need to keep the new dictionary sorted. Dictionaries aren't sorted. Period. /MiO -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
py: Thanks, itertools.izip and just zip work great. However, I should have mentioned this, is that I need to keep the new dictionary sorted. A Python dictionary is an unsorted data structure, so you cannot have it sorted as you please. (I have seen that lot of people ask for a sorted dictionary and for permutation/combination functions, maybe they are batteries to be included too in the standard library.) If you need an ordered dict you can manage it yourself, keeping the lists of keys, etc, or you can use an ordered dict implementation: http://www.voidspace.org.uk/python/odict.html http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823 Etc. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: What editor shall I use?
Peter Maas wrote: Lad schrieb: What editor shall I use if my Python script must contain utf-8 characters? I use XP An extremely capable, easy to use and small editor is Neil Hodgson's SciTE. It's my favorite editor on Windows and Linux. There is a Windows installer at http://users.hfx.eastlink.ca/~gisdev/scite-1.67-setup-3.exe Peter Maas, Aachen Yes, Scite is an excellent editor for Windows or Linux, but PyScripter [http://mmm-experts.com/Products.aspx?ProductID=4] offers more, including call completion and call tips. It's true that call completion is advertised with SciTE but I have not been able to use it with Windows. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
slogging_away wrote: bruno at modulix wrote: Why storing error messages ? Why don't you just write'em out (be it to stdout or to a file) ? I guess I could do that, (write them to a file as they are discovered). Right now the error messages are stored in the array and then the the array is scanned via, a for loop and the error messages are written to several files in different formats based on the severity of the errors, (on a per device basis, a per severity basis, etc.). This keeps the write statements to a minimum and in a central location of the script instead of having several statements for each individual error message spread throughout the script, (three write statements per error message at over 500 error messages would be a significant change). Sounds like you might like the logging module. A single log entry can be written to multiple destinations based on level or source of the entry. The distribution of log entries is controlled by the logging configuration which can be stored in a text file if you like. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
Magnus Lycka wrote: What happens if you run it from the command line instead of IDLE? After all, it might be some problem in IDLE involved here. Even if it doesn't work correctly outside IDLE, I was thinking that IDLE might swallow some kind of error message. Excellent suggestion, (behold the power of the command line!). I ran two saved versions of the script that had produced the symptom originally described. The fist seemed to be caused by too many 'if' statements, the second by adding another array, but both came up with the same system error at the command prompt level shown here: SystemError: com_backpatch: offset too large This error is not produced with the IDLE console but is seen only when executing from the command line. I'll search around and see if I can determine what this means and a possible fix. Thanks for the suggestion! -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
py wrote: Thanks, itertools.izip and just zip work great. However, I should have mentioned this, is that I need to keep the new dictionary sorted. d = {1:'first', -5 : 'negative 5', 6:'six', 99:'ninety-nine', 3:'three'} keys = d.keys() keys.sort() vals = map(d.get, keys) At this point keys is sorted [-5, 1, 3, 6, 99] and vals is sorted ['negative 5', 'first', 'three', 'six', 'ninety-nine'] Using zip does not create the dictionary sorted in this order. new_d = dict(zip(keys, vals)) How can I use the two lists, keys and vals to create a dictionary such that the items keep their order? Thanks. Short answer - you can't. Dictionaries aren't sequential structures, so they have no sorted form. You can iterate through it in a sorted manner however, as long as you keep your list of keys: keys.sort() for k in keys: print d[k] Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: Create dict from two lists
Iain King wrote: Short answer - you can't. Dictionaries aren't sequential structures, so they have no sorted form. You can iterate through it in a sorted manner however, as long as you keep your list of keys: keys.sort() for k in keys: print d[k] Iain duh!thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Rethinking the Python tutorial
On 09/02/06, Magnus Lycka [EMAIL PROTECTED] wrote: While the official Python Tutorial has served its purpose well, keeping it up to date is hardly anyones top priority, and there are others who passionately create really good Python tutorials on the web. I think 'A Byte of Python' by Swaroop C H is a good beginners tutorial, and 'Dive Into Python' by Mark Pilgrim is a good tutorial for more experienced programmers. My radical idea is that we mirror these at diveinto.python.org and byteof.python.org, and simply remove the old tutorial from the Python 2.5 (or 2.6?) docs. Give these two good texts an official status as the Python tutorials. Just as we want to adopt best of breed packages for the standard library, I think we should use best of breed documentation, and I think there are less backward compatibility issues with tutorials than with libraries. :) I think this change would give us better docs as well as a smaller maintenance burden. If a day comes when Mark Pilgrim or Swaroop C H don't want to maintain these texts, I strongly suspect that there are other tutorials we can replace them with if noone else steps in to keep them up to date. How about putting the current tutorial into the wiki and seeing if people start updating it? I'm not saying it would work, but it might have interesting effects... Ed -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
On Fri, 10 Feb 2006 06:50:25 -0800, slogging_away wrote: Excellent suggestion, (behold the power of the command line!). I ran two saved versions of the script that had produced the symptom originally described. The fist seemed to be caused by too many 'if' statements, the second by adding another array, but both came up with the same system error at the command prompt level shown here: SystemError: com_backpatch: offset too large Is this a Python error or a shell error? If it is a Python error, perhaps you would like to post the entire traceback? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too Many if Statements?
Steven D'Aprano wrote: On Fri, 10 Feb 2006 06:50:25 -0800, slogging_away wrote: Excellent suggestion, (behold the power of the command line!). I ran two saved versions of the script that had produced the symptom originally described. The fist seemed to be caused by too many 'if' statements, the second by adding another array, but both came up with the same system error at the command prompt level shown here: SystemError: com_backpatch: offset too large Is this a Python error or a shell error? If it is a Python error, perhaps you would like to post the entire traceback? I would believe CamelCaseErrorMessages are produced by Python. The message is exactly the same I reported with the 2500 elifs. I fooled around a bit with this, and it seems that also for/while blocks containing more than ~4860 lines give this error. slogging_away claims his script is about 4900 lines, most of that in a for loop, so my bet is he has trouble with the same bug. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about idioms for clearing a list
Bryan Olson wrote: Magnus Lycka wrote: Bryan Olson wrote: big_union = set() for collection in some_iter: big_union.update(t) collection.clear() I don't understand the second one. Where did 't' come from? Cut-and-past carelessness. Meant to update with 'collection'. If some_iter gives you dicts, the code above will throw away your values, and put the set of keys in big_union. Is that what you meant to do? I suspect most people would find this somewhat surprising. For sets and BryanLists it will put a set of all the contents of those collections in big_union. I think this just verifies my previous arguments. It's rarely meaningful to write functions that are meaingful for all builtin collections. -- http://mail.python.org/mailman/listinfo/python-list
html entity to unicode
Hi, I'm parsing html. I have a page with a lot of html enitties for hebrew characters. When i print what i get are blanks, dots and commas. How can i decode this entities to unicode charachters? TIA Zunbeltz -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Tkinter app works in Linux, not in Windows
There is a difference between the above code and your prior code, namely in that you have explicitly instantiated Tk and put your canvas into the root toplevel. Try this in idle where it was failing: snip Problem solved...I tried James' suggestion (explicitly instantiating the root Tk window, and then running the mainloop() as suggested), but it produced the same result i.e. no photo. Ugg... I then looked REALLY closely at my code and noticed that my __init__ function was actually ___init___ (3 underscores instead of 2). Thus, a Frame object was being built, but the __init__ function wasn't getting run. So no image was ever getting added. Silly underscores...or, silly Python newbie :-) It now works under both Linux and Windoze just fine. I would have thought that having no __init__ function would flag an error, but I guess this isn't necessary. I thought about grabbing PDB to debug, and I bet this would have shown the error immediately (i.e., it would never have called the function). Being a newbie is such a joy... Thanks for the help, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Rethinking the Python tutorial
There are now more than 300 tutorials listed at www.awaretek.com/tutorials.html so one could even imagine a mega-tutorial using the best-of-breed tutorial for each sub-section, a la Turbogears ;-))) Of course it might bear an unholy resemblance to a FrankenTutorial ;-))) Ron Stephens -- http://mail.python.org/mailman/listinfo/python-list
ordered sets operations on lists..
Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5]) thanks in advance, amit. -- Amit Khemka -- onyomo.com Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Legality of using Fonts
I have a question for all you Pythoneers out there. I'm making a game with Python, and have a need for fonts. I am currently using a free TrueType font, but am considering switching to a bitmap font instead. Let's say I own a font, and use it in a paint program to 'draw some text' on a picture that I slap up on the Internet. Everything's probably fine, right? But what if I draw some text on a bitmap on the hard drive, add drop shadows and decorations, and use it to 'blit' text in a game? The answer is less obvious to me then. Any advice you could offer would be greatly appreciated! --Kamilche -- http://mail.python.org/mailman/listinfo/python-list
[ANN] functional 0.5 released
Hello all, I have released version 0.5 of my functional module, a collection of higher-order and functional programming tools for Python. Currently offered are tools for function composition, partial function application, plus flip, foldl, foldr, scanl and scanr functions. Two version of the release are available: one is written in pure Python and aims for maximum readability and portability. The other is coded as a C extension module and is focused on raw performance. Where to get it: # functional is available at http://oakwinter.com/code/functional/ and from the Python Package Index at http://cheeseshop.python.org/pypi/functional. Both source tarballs and Python Eggs are available for both the pure Python and C releases. I'm open to user-contributed RPM, Deb or other packagings. Release Notes The biggest news in this release is the addition of the C implementation. Also, a number of functions were removed, as I had unknowingly duplicated a lot of functionality from the itertools module. As always, feedback welcome! Collin Winter -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting filename-encoding (on WinXP)?
Actually, the directory-name comes in as a URL and as such I had no problems yet just creating a unicode-string from it which I can pass to os.walk(), and get proper unicode-filenames back from it. Then I can encode them into utf-8 and pass them to the database-layer and it all works. cheers, --Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: ordered sets operations on lists..
Amit Khemka wrote: Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5]) what do you mean by direct way ? ugly(some said) one liner ? filter(set(l1).intersection(set(l2)).__contains__, l1) filter(set(l1).intersection(set(l2)).__contains__, l2) -- http://mail.python.org/mailman/listinfo/python-list
Re: AdaptionFailure: How to use Interfaces with PyProtocols ?
Yes, I adapted the instance, and it's working.That's it. Thank you ! Nebur -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter, X-windows and ebay
Paul Rubin http://[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Bob Greschke [EMAIL PROTECTED] writes: What I came up with was the user can just create a text file (a kind of a transaction log of what things were done to the copy of the database on his machine), then cut and paste that text into a window created on their machine by the main database program (using X-windows, ssh, etc.), then the main program can read the contents of that text field and update the main copy of the database. It should work. :) Yuck! Why not use an http interface instead of the remote tkinter interface? Then the user would interact with your app through a web browser, giving a familiar UI as well as giving that upload button (which tells the browser to upload the file). Mainly because the user may be in the middle of the Himalayas trying to create paperwork for equipment being shipped to Japan and Chile. The Internet is not always an option in our line of work. We need to have standalone everythings. We don't live in your real world. :) The two databases (the one on the user's laptop, and the one back at the office) don't need to be reconciled until the user gets back. We just need to (eventually) know which pieces of equipment were sent to Japan, and which went to Chile. Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Jython inherit from Java class
Alan, Kent, many thanks this really helped! But there is still a problem I guess with inheritance. I use the java testsuit supplied with the original to test the server. If I use the Java FitServer the testsuite can be completed. I commented everything out from my class and it does not work?? Thats the trace when I run the JUnit testsuit: java.io.IOException: CreateProcess: jython D:\AUT_TEST\workspace\JyFIT\fit\JyFitServer.py -Dpython.path='D:\AUT_TEST\workspace\JyFIT' D:\AUT_TEST\fitnesse\fitnesse.jar localhost 1234 23 error=2 at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.init(Unknown Source) at java.lang.ProcessImpl.start(Unknown Source) at java.lang.ProcessBuilder.start(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at FitServerTest.FitServerTest.prepareSessionProcess(FitServerTest.java:163) at FitServerTest.FitServerTest.testSimpleStartUp(FitServerTest.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Unfortunately I do not get much information at the prompt because both Java FitServer and JyFitServer behave the same there. D:\AUT_TESTjython D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py -Dpython.path='D:\\AUT_TEST\\workspace\\JyFIT' D:\\AUT_TEST\\fitnesse\\fitnesse.jar localhost 1234 23 Traceback (innermost last): File D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py, line 42, in ? java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:507) at java.net.Socket.connect(Socket.java:457) at java.net.Socket.init(Socket.java:365) at java.net.Socket.init(Socket.java:178) at fit.FitServer.establishConnection(Unknown Source) at fit.FitServer.establishConnection(Unknown Source) at fit.FitServer.run(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java) at org.python.core.PyMethod.__call__(PyMethod.java) at org.python.core.PyObject.__call__(PyObject.java) at org.python.core.PyInstance.invoke(PyInstance.java) at org.python.pycode._pyx0.f$0(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py:42) at org.python.pycode._pyx0.call_function(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py) at org.python.core.PyTableCode.call(PyTableCode.java) at org.python.core.PyCode.call(PyCode.java) at org.python.core.Py.runCode(Py.java) at org.python.core.__builtin__.execfile_flags(__builtin__.java) at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java) at org.python.util.jython.main(jython.java) java.net.ConnectException: java.net.ConnectException: Connection refused: connect ## And the Java FitServer: D:\AUT_TESTjava -cp D:\\AUT_TEST\\fitnesse\\fitnesse.jar fit.FitServer localhost 1234 23 Exception in thread main java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at
is there a better way?
Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using something like this: _ while list[0] != O: storage.append(list[0]) list.pop(0) if len(list) == 0: break _ But this seems ugly to me, and using while give me the heebies. Is there a better approach? hope this is clear. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
[EMAIL PROTECTED] wrote: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. What not for x in list: if x == O: break storage.append(x) ?? -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Q: dynamically assigning object attribute
Ben Wilson [EMAIL PROTECTED] wrote: I would like to dynamically assign object attributes: dict = { a : 1, b : 2, } for key,val in dict : obj.key = val I've googled to no effect, or maybe I'm needing to be hit with the appropriately sized clue-by-four. The conventional clue-by-four applied to this question is Don't do that: just put the dictionary (or a copy of it) in the object with obj.d = d (and don't shadow the built-in dict while you're at it). Having spent significant portions of the last two days coping with the mess of adding functionality to a class written by someone who thought doing what you want to do was a Good Idea, I can only concur with that conventional wisdom. Really. Don't do it. (Unless you have a damn good reason. In which case, you've already been pointed at setattr().) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Are there memory limits for external C modules?
[EMAIL PROTECTED] wrote: I was able to modify my C code so that instead of being a Python module, it runs as a standalone binary, and it works as it should. Calling it with os.spawn* works. The two versions are essentially the same, the primary differences being the necessary difference in how arguments and return values are handled. This will work if necessary, but I would think having it as a Python module would be slightly more elegant and efficient since we avoid the overhead of setting up new processes. I was able to resolve this issue. I was missing a call into Ethereal that allocated necessary memory. Now the Python module version works, and some various GLib assert warnings I was getting have gone away as well. Some testing has shown that the Python module version is quicker; I'm assuming that the overhead involved in setting up a separate process was slowing things down. There was a noticeable difference. - David -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
[EMAIL PROTECTED] wrote: Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using something like this: _ while list[0] != O: storage.append(list[0]) list.pop(0) if len(list) == 0: break _ But this seems ugly to me, and using while give me the heebies. Is there a better approach? hope this is clear. thanks There's a few ways to do this, really depends on : mylist = [1,2,3,4,5,6,0,0,0] list comprehension (will get ALL non zeros, and strip out all zeros, but is different from your function): [x for x in mylist if x != 0] list slice(same as your function): mylist[:mylist.index(0)] Depends what you want to happen if your list is something like: [1,2,3,0,4,5,6,0,0] [0,1,2,3,4,5,6] [0,1,2,3,4,5,6,0] [1,2,3,4,5,6] -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using something like this: _ while list[0] != O: storage.append(list[0]) list.pop(0) if len(list) == 0: break _ While it doesn't modify your list, you can try something like storage = [q for q in myList if q != O] If you've already got stuff in storage that you want to keep, you can use storage.extend([q for q in myList if q != O]) I suppose, if you wanted to remove all the O's, you could then just do myList = [q for q in myList if q == O] (trickiness using Oh's vs. using zeros...) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using something like this: _ while list[0] != O: storage.append(list[0]) list.pop(0) if len(list) == 0: break _ But this seems ugly to me, and using while give me the heebies. Is there a better approach? hope this is clear. thanks Use itertools. import itertools lst = X,X,X,O,O,O,O,O,X,X,X,X,O,X.split(,) [z for z in itertools.takewhile(lambda x:x==X,lst)] ['X', 'X', 'X'] -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
Paul McGuire [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using something like this: _ while list[0] != O: storage.append(list[0]) list.pop(0) if len(list) == 0: break _ But this seems ugly to me, and using while give me the heebies. Is there a better approach? hope this is clear. thanks Use itertools. import itertools lst = X,X,X,O,O,O,O,O,X,X,X,X,O,X.split(,) [z for z in itertools.takewhile(lambda x:x==X,lst)] ['X', 'X', 'X'] -- Paul duh, last line should be: list(itertools.takewhile(lambda x:x==X,lst)) ['X', 'X', 'X'] (Also, don't name variables list) -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: get output of cmd-line command under MS windows
On 2006-02-08, Bernard Lebel [EMAIL PROTECTED] wrote: Hi Bernhard and all, oPipe = os.popen( run C:/program files/my app/executable.exe ) while 1: sLine = oPipe.read() print sLine if sLine == '': print 'No more line from pipe, exit.' break I see. I saw also os.popen().read() or so. Anyway, not sure if that would also catch stderr? But doesn't matter. It seems, imagemagick (binaries) won't provide proper error-codes, but at least when it prints something, something was not ok probably. I will check the resulting file, to see if everything went ok, and try to catch the output like you mentioned. thanks a lot marco -- calmar (o_ It rocks: LINUX + Command-Line-Interface //\ V_/_ http://www.calmar.ws -- http://mail.python.org/mailman/listinfo/python-list
Re: random playing soundfiles according to rating.
kpp9c wrote: I've been looking at some of the suggested approaches and looked a little at Michael's bit which works well bisect is a module i always struggle with (hee hee) I am intrigued by Ben's solution and Ben's distilled my problem quite nicely Thanks!-) Actually, you should use Michael's solution, not mine. It uses the same concept, but it finds the correct subinterval in O(log n) steps (by using bisect on a cached list of cumulative sums). My code takes O(n) steps -- this is a big difference when you're dealing with thousands of items. but, welli don't understand what point is doing with wieght for key, weight for zlist This line: point = random.uniform(0, sum(weight for key, weight in zlist)) Is shorthand for: total = 0 for key, weight in zlist: total += weight point = random.uniform(0, total) furthermore, it barfs in my interpreter... (Python 2.3) Oops, that's because it uses generator expressions (http://www.python.org/peps/pep-0289.html), a 2.4 feature. Try rewriting it longhand (see above). The second line of the test code will have to be changed too, i.e.: counts = dict([(key, 0) for key, weight in data]) --Ben -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python interface to Microsoft Outlook Web Access
Hi all, Because I telecommute, I'm limited to using my company's webmail interface, Microsoft Outlook Web Access, rather than having direct POP or IMAP access to e-mail. This isn't ideal, for several reasons: * Outlook Web Access has a horrendous user interface in any browser other than Internet Explorer. (And I'm on Linux, so I can't use Internet Explorer.) It's hard to search, the icons are unintuitive, it encourages top-posting and doesn't have the basic benefits of a desktop e-mail app, such as spell-checking and address auto-completion. * Using webmail forces me to keep a browser window/tab open to check messages. And Outlook Web Access doesn't auto-refresh, so I have to remember to click Inbox every so often to get the latest messages. This is a huge disruption. * It's just simpler and more efficient to have all my e-mail in one place. So I figured I'd do a bit of programming to make my life easier. The result: weboutlook, a Python library that screen-scrapes Outlook Web Access. It can: * Log into a Microsoft Outlook Web Access account on a given server with a given username and password. * Retrieve all e-mail IDs from the first page of your Inbox. * Retrieve all e-mail IDs from the first page of any folder in your webmail (such as Sent Items). * Retrieve the full, raw source of the e-mail with a given ID. * Delete an e-mail with a given ID (technically, move it to the Deleted Items folder). Also, I've included a Python implementation of a POP server that provides a POP interface to the scraper. This means I can point my desktop e-mail client at the script, my e-mail client will think it's a normal POP server, and my e-mails will download nicely into my desktop app, with the screen-scraper running silently behind the scenes. I put this together in my free time, and it's been working nicely for a week, so I'm open-sourcing it for other poor souls who've been sentenced to use Outlook Web Access. I presented this at yesterday's Chicago Python Users Group meeting and was surprised to see that, even in a group of only 30 people, 5 or 6 people used Outlook Web Access through their company. I hope somebody finds this useful. http://www.holovaty.com/code/weboutlook/ Please send comments and improvements to [EMAIL PROTECTED] Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org -- http://mail.python.org/mailman/listinfo/python-list
Martin Franklin's Tkinter/Tile wrapper--where'd it go?
I believe Martin Franklin wrote a Tile.py wrapper for the Tk/Tile extension, which adds theming to the core Tk widget set. It used to reside here: http://mfranklin.is-a-geek.org/docs/Tile/index.html That server seems to be down. Anyone know if the wrapper is available elsewhere? Or if someone else has written a Tile wrapper? -- Kevin Walzer iReveal: File Search Tool http://www.wordtech-software.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter, X-windows and ebay
In article [EMAIL PROTECTED], Bob Greschke [EMAIL PROTECTED] wrote: Paul Rubin http://[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Bob Greschke [EMAIL PROTECTED] writes: What I came up with was the user can just create a text file (a kind of a transaction log of what things were done to the copy of the database on his machine), then cut and paste that text into a window created on their machine by the main database program (using X-windows, ssh, etc.), then the main program can read the contents of that text field and update the main copy of the database. It should work. :) Yuck! Why not use an http interface instead of the remote tkinter interface? Then the user would interact with your app through a web browser, giving a familiar UI as well as giving that upload button (which tells the browser to upload the file). Mainly because the user may be in the middle of the Himalayas trying to create paperwork for equipment being shipped to Japan and Chile. The Internet is not always an option in our line of work. We need to have standalone everythings. We don't live in your real world. :) The two databases (the one on the user's laptop, and the one back at the office) don't need to be reconciled until the user gets back. We just need to (eventually) know which pieces of equipment were sent to Japan, and which went to Chile. . . . Certainly. And, if you're content with what you have, that's great; *I* certainly do enough funny things with Tkinter and X. But what you *can* do is deploy the end-user desktop with a browser pointed to a local Web page, presumably one with enough client-side processing to prepare a form. Then, when he's within range of an IP address, he selects an upload link, and you get all the HTTP-related advantages Paul and others have mentioned. -- http://mail.python.org/mailman/listinfo/python-list
Re: by reference
Thanks but I am a bit unsure as to what error I have made by posting this question. I am not trying to be funny but can you give me a pointer to the issue. Many thanks David -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Q: dynamically assigning object attribute
Well, my Perl way of doing it would be to have all attributes in a dict (hash), then create the accessor vi a dynamic function. I knew Python would have a right way to do it for Python, but when I went looking I neglected to look at the core of the language. I suppose I'm just too accustomed to the TIMTOWTDY approach to expect the one-ring-to-bind-them-all solution. :-) It's a mental shift on my part, to be certain. What I was actually doing was reading a user configuration file and setting an object's variables--the example I got was a fairly close approximation of how I was trying to approach it before setattr(). Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: ordered sets operations on lists..
Amit Khemka wrote: Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? Nope For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) returns [3, 5]) However: intersection = set(list1) set(list2) [element for element in list1 if element in intersection] or [element for element in list2 if element in intersection] Give you the result you'd like. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Legality of using Fonts
Kamilche wrote: I have a question for all you Pythoneers out there. I'm making a game with Python, and have a need for fonts. I am currently using a free TrueType font, but am considering switching to a bitmap font instead. Let's say I own a font, and use it in a paint program to Typically you don't own a font, but you have a license to use it. You need to read the license to figure out what you are allowed to do with it. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
[EMAIL PROTECTED] wrote: Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X. There are never O's between X's. I have been using something like this: while list[0] != O: storage.append(list[0]) list.pop(0) if len(list) == 0: break But this seems ugly to me, and using while give me the heebies. Is there a better approach? Your names could be better as someone mentioned. ex, oh = 7, 13 # for example data = [ex, ex, ex, oh, oh, oh, oh] If you need a list distinct from the original: try: result = data[: data.index(oh)] except ValueError: result = list(data) Or you could simply: try: data = data[: data.index(oh)] except ValueError: pass and data will be either the sublist you want or the original list. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: ordered sets operations on lists..
[Amit Khemka] Hello, Is there a *direct* way of doing set operations on lists which preserve the order of the input lists ? For Ex. l1 = [1, 5, 3, 2, 4, 7] l2 = [3, 5, 10] and (l1 intersect l2) returns [5, 3] (and (l2 intersect l1) [bonono] what do you mean by direct way ? ugly(some said) one liner ? filter(set(l1).intersection(set(l2)).__contains__, l1) filter(set(l1).intersection(set(l2)).__contains__, l2) The intersection step is unnecessary, so the answer can be simplified a bit: filter(set(l2).__contains__, l1) [5, 3] filter(set(l1).__contains__, l2) [3, 5] -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a better way?
[...] What not for x in list: if x == O: break storage.append(x) i think this may take too long better aproach would be to test for zero from the end Regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list