Elisa Media Center 0.5.22 Release
Dear Python users, The Elisa team is happy to announce the release of Elisa Media Center 0.5.22, code-named Where Is My Mind?. Elisa is a cross-platform and open-source Media Center written in Python. It uses GStreamer [1] for media playback and pigment [2] to create an appealing and intuitive user interface. The main new feature is a set of generic RSS models and a controller that allow plugin developers to very easily integrate media RSS feeds in their plugins. Expect new cool plugins that make use of this very soon! As usual, a bunch of bugs were fixed, a complete list can be found at: http://bugs.launchpad.net/elisa/+milestone/0.5.22 Installers and sources can be downloaded from http://elisa.fluendo.com/download/ Bug reports and feature requests are welcome at http://bugs.launchpad.net/elisa/+filebug Have a media-centered evening, The Elisa team [1] http://www.gstreamer.net/ [2] https://code.fluendo.com/pigment/trac Elisa 0.5.22 Where Is My Mind? This is Elisa 0.5.22, twenty-second release of the 0.5 branch. New features since 0.5.21: - Generic RSS models and controller that allow plugin developers to very easily integrate media RSS feeds in their plugins Bugs fixed since 0.5.21: - 288210: [win32] Elisa launched from the installer tries to write a log file in program files - 302349: [linux] plugins installed using plugin management feature disappear at Elisa next startup - 297612: ffwd forever - 305116: [win32] Playing any media file using Open with contextual menu throws an error message on windows XP not on Vista - 305430: Don't display media duration if it's zero Download You can find source releases of Elisa on the download page: http://elisa.fluendo.com/download Elisa Homepage More details can be found on the project's website: http://elisa.fluendo.com Support and Bugs We use Launchpad for bug reports and feature requests: https://bugs.launchpad.net/elisa/+filebug Developers All code is in a Bazaar branch and can be checked out from there. It is hosted on Launchpad: https://code.launchpad.net/elisa Contributors to this release: - Benjamin Kampmann - David McLeod - Florian Boucault - Guido Amoruso - Guillaume Emont - Jesús Corrius - Lionel Martin - Maxwell Young - Olivier Tilloy - Philippe Normand -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Sphinx 0.5.1 released
Hi all, I'm proud to announce the release of Sphinx 0.5.1, the first bugfix release in the 0.5 series. What is it? === Sphinx is a tool that makes it easy to create intelligent and beautiful documentation for Python projects (or other documents consisting of multiple reStructuredText source files). Its website is at http://sphinx.pocoo.org/. Fixes in version 0.5.1 == can be found at http://sphinx.pocoo.org/changes.html. Many thanks to all bug reporters! cheers, Georg -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Hypy 0.8.1 (first public release!)
Hypy is a fulltext search interface for Python applications. Use it to index and search your documents from Python code. Hypy is based on the estraiernative bindings by Yusuke Yoshida. * Fast, scalable * Perfect recall ratio by N-gram method * High precision by hybrid mechanism of N-gram and morphological analyzer * Phrase search, regular expressions, attribute search (including numeric and date comparisons), and similarity search * Simple and powerful API Homepage, downloads, everything, etc.: http://goonmill.org/hypy/ This is of course on pypi and can be installed with easy_install or pip. You will need Hyper Estraier installed to use it. Release Version 0.8.1 (2008.12.15) ~~~ * Initial Public Opensourcing. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Numerical optimization framework OpenOpt 0.21
Hi all, OpenOpt 0.21, free Python-written optimization framework (license: BSD) with some own solvers and connections to tens of 3rd party ones, has been released. All details here: http://openopt.blogspot.com/2008/12/openopt-release-021.html Let us also invite you into new forum about numerical optimization and related free and opensource software: http://forum.openopt.org/ Regards, OpenOpt developers. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
RE: tutorial on parser
Hi John, You may want to read http://nedbatchelder.com/text/python-parsers.html Bye, Ron. -Original Message- From: John Fabiani [mailto:jfabi...@yolo.com] Sent: Tuesday, December 16, 2008 08:47 To: python-list@python.org Subject: tutorial on parser Hi, I'm attempting to learn how to convert MsSQl Transact-SQL to postgres pgsql. So far my readings have led me to finding a parser. I'm looking for a tutorial on how to get it done. I did find a commercial product but they want over $10,000 us. This way beyond my means. Therefore, I need to get it done either myself to find a open source project. Thanks in advance. John Fabiani -- http://mail.python.org/mailman/listinfo/python-list
Re: Python music sequencer timing problems
On Mon, 15 Dec 2008, John O'Hagan wrote: On Sun, 14 Dec 2008, Bad Mutha Hubbard wrote: John O'Hagan wrote: On Wed, 10 Dec 2008, badmuthahubbard wrote: [...] from time import time, sleep start = time() for event in music: duration=len(event) #Really, the length of the event play(event) while 1: timer = time() remaining = start + duration - timer if remaining 0.001: break else: sleep(remaining / 2) stop(event) start += duration Very interesting approach, halving the remaining duration. Right now I'm not working with note-offs, Csound takes care of the duration. I just need to be able to call the notes at the right times. [...] I'm also using the above code without the stop(event) line for playing non-midi stuff (fixed-length samples for example), which from the sound of it also applies to your requirement - IOW, you _can_ use it just to start notes at the right time, because the note-playing loop sleeps till then. And as I realized after having a good sleep myself, this is only useful for timing events which occur sequentially and do not overlap, which is how my program works because it generates the events in real time, but which may be of no use in your case. But I suppose the same principle could be applied to reduce the number of calls needed in a separate timing thread. Unless of course each event contained the start-time of the next event as an attribute? John -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory leak when using a C++ module for Python
En Thu, 11 Dec 2008 15:35:58 -0200, Jaume Bonet jaume.bo...@gmail.com escribió: This is the function that is visible from python and the one that the python code calls: static PyObject * IMFind (PyObject *self, PyObject *args, PyObject *kwargs) { Your function does not call any Python function except PyArg_ParseTupleAndKeywords (which does not modify reference counts). So it's unlikely that this could cause any memory leak. I'd revise how memory is allocated and deallocated on the C++ side. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: weird dict problem, how can this even happen?
Duncan Booth wrote: It could happen quite easily if the hash value of the object has changed since it was put in the dictionary. what does the definition of your core.gui.FragmentInfo object look like? Dunno if it'll help much, but: class FragmentInfo(object): def __init__(self, renderer, render_area): self.renderer = renderer self.render_area = render_area def __hash__(self): return hash((FragmentInfo, self.renderer, self.render_area)) def __eq__(self, other): return (isinstance(other, self.__class__) and other.renderer == self.renderer and other.render_area == self.render_area) Is the hash definitely immutable? No. It's a hash of a tuple of its key attributes, themselves similar objects. The program can be thought of as a map viewer. In the gui part, image fragments are cached for speed, and fragments are only half rendered if there's a lot of complex features to draw. The pool consists of semi rendered fragments. The reason I did it this way is the cache. The cache is a dict with a use tracker so when the hash changes, the older fragments eventually drop from the cache. Hmm... I'm starting to realise now why my implementation of this isn't so hot. I'm going to hazard a guess here, and then you can correct me ok? I create a dict and populate it with a key-value pair, and then the key's hash changes. When the key is returned by k = d.keys(), then k not in d, even though k in d.keys(). Simple example: class moo(object): def __init__(self, a): self.a = a def __hash__(self): return hash(self.a) d = {moo(1): 1} k = d.keys()[0] k.a = 2 k = d.keys()[0] print k in d, k in d.keys() d.pop(k) output: False True Traceback (most recent call last): File /bioinfo/yohell/eclipse/Test/src/test.py, line 14, in module d.pop(k) KeyError: __main__.moo object at 0x7f1c64120590 I'd say that's pretty similar to what I observed. I guess the logical outcome is that the cache dict will fill up with old junk that I can't access and can't selectively flush since the hashes have changed, unless I actually somehow save copies of the keys, which can get pretty complex and probably won't do wonders for execution speed. Yeah this was probably a bad soulution. I should probably do this with lists instead because I can't really think of a way of salvaging this. Am i right? Thanks for your help! /Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
Giampaolo Rodola' a écrit : Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named use_gmt_times to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the ethical doubts I'm gonna write below. In first place I've never liked global variables too much and always preferred per-class-instance variables instead. The problem in my case is that I have to use such variable in two separated classes: FTPHandler and VirtualFileSystem. Also, I want that for no reason one class uses times in GMT and the other one local times. Looks like it's more a configuration variable than a global. IOW, it's not supposed to change during execution. Another doubt is the naming convention. PEP-8 states that global variables should use the lower_case_naming_convention but I've seen a lot of library module using the UPPER_CASE_NAMING_CONVENTION. ALL_UPPER_NAMES are pseudo-constants - IOW, they are really variables but are by convention considered as constants. HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
Steve Holden st...@holdenweb.com writes: Ben Finney wrote: James Stroud jstr...@mbi.ucla.edu writes: Ben Finney wrote: James Stroud jstr...@mbi.ucla.edu writes: Yes. I think it was the British who decided that the apostrophe rule for it would be reversed from normal usage relative to just about every other noun. It also seems an indefensible claim to say that anyone decided it would be that way, especially the British. It's our language, dammit! Ours, ours, ours! This decision was actually taken at a meeting of the Society of British pedants on November 23, 1786. This led to a schism between the British and the newly-independent Americans, who responded by taking the u out of colour, valour, and aluminium. I'd thought that the main schism was triggered by a tax on tea but it turns out that it was due to an apostrophe after t. ;-) -- Pete Forman-./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does not represent pete.for...@westerngeco.com-./\.- the opinion of Schlumberger or http://petef.22web.net -./\.- WesternGeco. -- http://mail.python.org/mailman/listinfo/python-list
Re: Structure using whitespace vs logical whitespace
En Mon, 15 Dec 2008 14:29:31 -0200, cmdrrickhun...@yaho.com conrad.am...@gmail.com escribió: PS. In my opinion the solution would be to have the option of entering a whitespace insensitive mode which uses C style {} and ;. The token to enter it could be as complicated as you want (in fact, it may make sense to make it complicated to discourage use unless it's really advantageous). I'd sugest {{ and }} or something bigger like {={ } =}. Only two problems: 1) I'm sure it would offend Guido's sense of language aesthetics 2) I'm sure the idea has been hashed over on this newsgroup to death... hence prefering a workaround instead. It's a hidden feature, already implemented. Try: from __future__ import braces -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: weird dict problem, how can this even happen?
Joel Hedlund yoh...@ifm.liu.se writes: I'm having a very hard time explaining why this snippet *sometimes* raises KeyError: snippet: print type(self.pool) for frag in self.pool.keys(): if frag is fragment_info: print the fragment_info *is* in the pool, hash(frag), hash(fragment_info), hash(frag) == hash(fragment_info), frag == fragment_info, frag in self.pool, frag in self.pool.keys() try: renderer_index = self.pool.pop(fragment_info) except KeyError: print Glorious KeyError! for frag in self.pool.keys(): if frag is fragment_info: print the fragment_info *is* in the pool, hash(frag), hash(fragment_info), hash(frag) == hash(fragment_info), frag == fragment_info, frag in self.pool, frag in self.pool.keys() raise output: type 'dict' the fragment_info *is* in the pool 987212075 987212075 True True False True Glorious KeyError! the fragment_info *is* in the pool 987212075 987212075 True True False True Traceback (most recent call last): File /home/yohell/workspace/missy/core/gui.py, line 92, in process_job renderer_index = self.pool.pop(fragment_info) KeyError: core.gui.FragmentInfo object at 0x8fc906c This snippet is part of a much larger gtk program, and the problem only from time to time, predominantly when the cpu is under heavy load and this method gets called a lot. If I didn't know better I'd say it's a bug in python's dict implementation, but I do know better, so I know it's far more likely that I've made a mistake somewhere. I'll be damned if I can figure out what and where though. I've reproduced this bug (?) with python-2.5.2 on Ubuntu 8.10 and python-2.5.1 on WinXP. I would very much like an explanation to this that does not involve threads, because I haven't made any that I'm aware of. I can't even understand how this could happen. How do I even debug this? Please help, I feel like I've taken crazy pills here! /Joel Hedlund It could happen if two object x and y are such that hash(x) != hash(y) but x == y, breaking the requirement on hash values. HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] Having Issues with CMD and the 'python' command
On Mon, Dec 15, 2008 at 9:56 AM, Benjamin Kaplan benjamin.kap...@case.eduwrote: It's not a question of sensibility. It's a question of purpose. The Zen is the philosophy of a language that tries to be easy to learn and easy to use. Python is used by programmers who want to experiment with it, but who usually know enough not to os.system(rm -r /) or anything similar. Windows, on the other hand, wants to hide everything that can potentially ruin the system as deep as possible so that many of the idiots who use that system don't do stupid things like delete the registry, wipe the environment settings, turn off the Nag Screen (UAC), and other things of that nature But if it were sensible, it would (like certain other OS's) make it more difficult to have built-in permissions that allow you to totally hose the system, i.e. it would be secure.While it may not technically be using the same comparison criteria we do, Python still gives you the proper result: In [5]: 'obfuscation' is not 'security' and 'obfuscation' != 'security' Out[5]: True I think that's an important concept for programmers to realize. Allowing people to break things if they fool around enough is not a very sensible, or secure way of running things. And if you're writing OSes, the sensible thing is to write secure code. And if you're writing programs for general consumption, it's /also/ best to write secure code. That's my 2c anyways :) -Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
On Dec 15, 11:04 am, Steve Holden st...@holdenweb.com wrote: Tim Chase wrote: Steve Holden wrote: This led to a schism between the British and the newly-independent Americans, who responded by taking the u out of colour, valour, and aluminium. Darn Americans and their alminim ;-) Next thing you know, they'll be putting an I in TEAM.[1] It's called humour. Or humor. Or incompetence ;-) There's an 'I' in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help improving number guessing game
feba a écrit : .strip() returns a copy of the string without leading and ending whitespaces (inlcuding newlines, tabs etc). Ahh. I had removed it because it didn't seem to do anything, but I've readded it. And I understand your dictionary stuff correctly now, I think, and I worked it in. Currently, I have: import random def safeint(prompt=y): while True: x = input(prompt) try: x = int(x) except ValueError: print(BAD INPUT!) else: break return x def safestr(prompt=y): while True: x = input(prompt) try: x = str(x) Doesn't input already return a string ? except ValueError: print(BAD INPUT!) else: break return x You could as well replace the 'break' statement by 'return x' - since returning will obviously break the loop Now don't you notice kind of a pattern in these two functions ? obviously, the only thing that change is the conversion/validation part. The good news is that Python functions are objects too, so you can pass them as params to another function. The generic version of your above code could be: def safeinput(prompt, convert): while True: x = input(prompt) try: x = convert(x) except ValueError, e: print(Bad input : %s % e) else: return x then you can use it for int: i = safeinput(Please enter an integer, int) or use more complex conversion/validation: def yesno(s): s = s.strip().lower() if not s in (y, n): raise ValueError(please answer with 'y' or 'n') # we return a boolean return s == 'y' answer = safeinput(really do this ?, yesno) Last point : if your conversion/validation function needs more arguments than the value to convert - ie : converting to an int and vaidating this int is in a specified range, which require mini and maxi arguments for the range - you can use partial evaluation[1]: from functools import partial def int_in_range(x, mini, maxi): x = int(x) if not mini = x = maxi: raise ValueError(%s is not in range (%s, %s) % (x, mini, maxi)) return x i = safeinput( Please enter an int between 1 and 99, partial(int_in_range, mini=1, maxi=99) ) [1] given the function f(x, y): return x + y, the partial evaluation partial(f, x=2) is a function fx(y) that when called returns the result of f(2, y). (snip) rewrite it once again using objects instead of dicts ? I'd need to find out how those work, Mostly as glorified dicts with associated functions. Your game and players dicts are obvious candidates. Whenever you see a dict with a more or less defined structure and a set of functions working on this dict, you have in fact a class waiting to be born. and I have a list of python stuff to read piling up anyway... That said, I think for something like that, something that's not a major flaw, I'd prefer to make something else, and maybe work on this again later on. There is only so much guessing numbers one person can take. Indeed. That was just a suggestion, and it would have been pretty interesting IMHO as a basis for a from QD procedural scripting to OO application programing tutorial. -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen inheriting
Hi, I have a file handle I want to inherit in a child process. I am looking at '_make_inheritable' in 'Popen', but it needs an instance, and by the time I have one, the subprocess is already running. Can't I call 'Popen._make_inheritable( None, handle )'? The method does not use 'self'. -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
En Tue, 16 Dec 2008 00:45:05 -0200, Giampaolo Rodola' gne...@gmail.com escribió: Another doubt is the naming convention. PEP-8 states that global variables should use the lower_case_naming_convention but I've seen a lot of library module using the UPPER_CASE_NAMING_CONVENTION. What am I supposed to do about it? Are you sure those UPPER_CASE names you've seen are actually variables? or constants like: CRLF = '\r\n' (ok, it's not a true constant because the language doesn't prevent you from modifying it... but the intended usage is to be a constant) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Interface Implementation
En Fri, 12 Dec 2008 19:48:09 -0200, Lie Ryan lie.1...@gmail.com escribió: but if you really want it, simple inheritance might be better anyway, though not really pythonic: class MyIfc(object): def myMeth1(self): return NotImplemented def myMeth2(self): return NotImplemented class MyClass(MyIfc): def myMeth1(self): # some implementation def myMeth2(self): # some implementation # some might notice the (ab)use of NotImplemented sentinel there I'd raise NotImplementedError instead. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
Dennis Lee Bieber w@ix.netcom.com wrote: 8- stuff blaming Davy for aluminum -- Isn't Davy a Brit? No, he was a Brit. He's dead now. His safety lamp lives on. It's a good thing its got that heat-sink sieve- it's enabled countless miners to flee when they see its change of colour. Thus it's saved the lives of a lot of canaries, and that's of ecological importance. Spot the apostrophe error, if you can. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
Federico Moreira wrote: Hi all, Im parsing a 4.1GB apache log to have stats about how many times an ip request something from the server. The first design of the algorithm was for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] if match_counter.has_key(ip): match_counter[ip] += 1 else: match_counter[ip] = 1 And it took 3min 58 seg to give me the stats Then i tried a generator solution like def generateit(): for line in fileinput.input(sys.argv[1:]): yield line.split()[0] for ip in generateit(): ...the same if sentence Instead of being faster it took 4 min 20 seg Should i leave fileinput behind? Am i using generators with the wrong aproach? Your first design is already simple to understand, so I think that using a generator isn't necessary (and probably isn't worth the cost!). You might want to try defaultdict instead of dict to see whether that would be faster: from collections import defaultdict match_counter = defaultdict(int) for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] match_counter[ip] += 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Structure using whitespace vs logical whitespace
On Mon, 15 Dec 2008 08:29:31 -0800, cmdrrickhun...@yaho.com wrote: I've been trying to search through the years of Python talk to find an answer to this, but my Googlefu is weak. In most languages, I'll do something like this xmlWriter.BeginElement(parent); xmlWriter.BeginElement(child); --xml.Writer.Characters(subtext); xmlWriter.EndElement(); xmlWriter.EndElement(); Where the dashes are indentation (since some newsgroup handlers don't do tabs well). XML writing is just an example. In general, I'm using indentation to show logical flow through code. Python's choice to give semantic meaning to whitespace prevents me from doing such things. What was once reserved for logical use is now used syntactically. In 90% of cases, its not needed, and whitespace significance seems to be pretty effective. In that last 10%, however, I've been frustrated many times. I've been using python for a few years, and gotten around this in one way or another, but now I want to get other who work with me to pick up Python. All newbies to Python have trouble with the idea of whitespace sensitivity, but how can I convince them that it just works better when I have this construct which I want to use but can't. Has anybody found a way to emulate this behavior? I've often done it by opening an expression for the whole thing, but there's a lot of tasks where a single expression just isn't sufficient (such as things with assignment). PS. In my opinion the solution would be to have the option of entering a whitespace insensitive mode which uses C style {} and ;. The token to enter it could be as complicated as you want (in fact, it may make sense to make it complicated to discourage use unless it's really advantageous). I'd sugest {{ and }} or something bigger like {={ } =}. Only two problems: 1) I'm sure it would offend Guido's sense of language aesthetics 2) I'm sure the idea has been hashed over on this newsgroup to death... hence prefering a workaround instead. It's possible (although no real python programmers would do it) to use a code preprocessor that would search for special marked sections in which spacing would be ignored and punctuations or end-of-block marker would be used to determine spacings. -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
On 2008-12-16, Hendrik van Rooyen m...@microcorp.co.za wrote: Dennis Lee Bieber w@ix.netcom.com wrote: 8- stuff blaming Davy for aluminum -- Isn't Davy a Brit? No, he was a Brit. He's dead now. His safety lamp lives on. It's a good thing its got that heat-sink sieve- should be it's got (contracted form of it has got). it's enabled countless miners to flee when they see its change of colour. Thus it's saved the lives of a lot of canaries, and that's of ecological importance. Spot the apostrophe error, if you can. -- Grant Edwards grante Yow! RHAPSODY in Glue! at visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Structure using whitespace vs logical whitespace
On Tue, 16 Dec 2008 10:00:32 +0100, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Mon, 15 Dec 2008 14:29:31 -0200, cmdrrickhun...@yaho.com conrad.am...@gmail.com escribió: PS. In my opinion the solution would be to have the option of entering a whitespace insensitive mode which uses C style {} and ;. The token to enter it could be as complicated as you want (in fact, it may make sense to make it complicated to discourage use unless it's really advantageous). I'd sugest {{ and }} or something bigger like {={ } =}. Only two problems: 1) I'm sure it would offend Guido's sense of language aesthetics 2) I'm sure the idea has been hashed over on this newsgroup to death... hence prefering a workaround instead. It's a hidden feature, already implemented. Try: from __future__ import braces I was almost shocked so I tried it. It's much clearer now... ;-) -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
[cookielib] How to add cookies myself?
Hello I'm using urllib and urlib to download data from a web server that requires cookies. The issue I'm having, is the server uses JavaScript in the response to insert new cookies and send them with the next query, so I need to manually add a couple of cookies in the CookieJar, but I don't know how to do this and Google didn't return examples: = import urllib import urllib2 import cookielib headers = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) url = http://www.acme.com/index.php; req = urllib2.Request(url, None, headers) response = urllib2.urlopen(req).read() print Fetched cookies: for index, cookie in enumerate(cj): print index, ' : ', cookie How to Add manually? crm_cookieEnabled=1 ctr=1 = Thanks for any tip. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
On Tue, 16 Dec 2008 12:07:14 -0300, Federico Moreira wrote: Hi all, Im parsing a 4.1GB apache log to have stats about how many times an ip request something from the server. The first design of the algorithm was for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] if match_counter.has_key(ip): match_counter[ip] += 1 else: match_counter[ip] = 1 And it took 3min 58 seg to give me the stats Then i tried a generator solution like def generateit(): for line in fileinput.input(sys.argv[1:]): yield line.split()[0] for ip in generateit(): ...the same if sentence Instead of being faster it took 4 min 20 seg Should i leave fileinput behind? Am i using generators with the wrong aproach? What's fileinput? A file-like object (unlikely)? Also, what's fileinput.input? I guess the reason why you don't see much difference (and is in fact slower) lies in what fileinput.input does. Generators excels in processing huge data since it doesn't have to create huge intermediate lists which eats up memory, given an infinite memory, a generator solution is almost always slower than straight up solution using lists. However in real life we don't have infinite memory, hogging our memory with the huge intermediate list would make the system start swapping, swapping is very slow and is a big hit to performance. This is the way generator could be faster than list. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
On Tue, 16 Dec 2008 12:07:14 -0300, Federico Moreira wrote: Hi all, Im parsing a 4.1GB apache log to have stats about how many times an ip request something from the server. The first design of the algorithm was for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] if match_counter.has_key(ip): match_counter[ip] += 1 else: match_counter[ip] = 1 nitpick: dict.has_key is usually replaced with if ip in match_counter: ... also, after investigating your code further, I see that you've unnecessarily used generators, the first code is simpler and you've not avoided any creation of huge intermediate list by using the generator this way. You won't get any performance improvement with this, and instead get a performance hit due to function overhead and name look up. -- http://mail.python.org/mailman/listinfo/python-list
RE: String slices work only for first string character ?
Hi Mr. Cain, Mae culpa: obviously, I erroneously understood the number after the ':' as the string length. Thanks, Ron. -Original Message- From: D'Arcy J.M. Cain [mailto:da...@druid.net] Sent: Tuesday, December 16, 2008 15:45 To: Barak, Ron Cc: python-list@python.org Subject: Re: String slices work only for first string character ? On Tue, 16 Dec 2008 13:35:27 + Barak, Ron ron.ba...@lsi.com wrote: Can any one explain why the following string slice works only for the first character, but not for any other ? I think that you need to reread the docs on slices. print |+data[0:1]+| print |+data[1:1]+| If you want the second character use data[1:2]. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bidirectional Networking
Thanks everybody and in particular Gabriel and Bryan for their contributions to this thread. Very much useful information. Manu -- http://mail.python.org/mailman/listinfo/python-list
help I'm getting delimited
Hi, I'm going nuts over the csv.reader and UnicodeReader class. Somehow I can't get this method working which is supposed to read a csv file which name is inputted but here now hardcoded. What I need for now is that the string version of the list is put out for control. Later on I will only need to read the first column (id) of the csv file to be able to fill in a session var with a list of all ids. inp = c:/temp/test.csv roles = [] try: fp = open(inp, 'rb') reader = csv.reader(fp) for r in reader: rollen.append(r) except: msg = Er is iets mis met de UnicodeReader return dict(file=in,roles=str(roles)) Any help greatly appreciated! Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
Lie Ryan wrote: On Tue, 16 Dec 2008 12:07:14 -0300, Federico Moreira wrote: Hi all, Im parsing a 4.1GB apache log to have stats about how many times an ip request something from the server. The first design of the algorithm was for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] if match_counter.has_key(ip): match_counter[ip] += 1 else: match_counter[ip] = 1 And it took 3min 58 seg to give me the stats Then i tried a generator solution like def generateit(): for line in fileinput.input(sys.argv[1:]): yield line.split()[0] for ip in generateit(): ...the same if sentence Instead of being faster it took 4 min 20 seg Should i leave fileinput behind? Am i using generators with the wrong aproach? What's fileinput? A file-like object (unlikely)? Also, what's fileinput.input? I guess the reason why you don't see much difference (and is in fact slower) lies in what fileinput.input does. Fileinput is a standard module distributed with Python: From the manual: 11.2 fileinput -- Iterate over lines from multiple input streams This module implements a helper class and functions to quickly write a loop over standard input or a list of files. The typical use is: import fileinput for line in fileinput.input(): process(line) ... Generators excels in processing huge data since it doesn't have to create huge intermediate lists which eats up memory, given an infinite memory, a generator solution is almost always slower than straight up solution using lists. However in real life we don't have infinite memory, hogging our memory with the huge intermediate list would make the system start swapping, swapping is very slow and is a big hit to performance. This is the way generator could be faster than list. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
On 16 Dic, 07:23, Michele Simionato michele.simion...@gmail.com wrote: On Dec 16, 3:45 am, Giampaolo Rodola' gne...@gmail.com wrote: Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named use_gmt_times to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the ethical doubts I'm gonna write below. Global variables have a bad reputation, but they are not so bad in Python. Notice that: 1. global variables in Python are local to the module they are defined in; 2. class names and module names are usually global variables and nobody complains about that. 3. if you use an ALL_CAPS convention it is quite quite clear that you are using a global variable. Actually the ALL_CAPS convention is for constants, but sometimes I use it for configuration variables too, if they are set at the beginning and they are never changed during the running of the program. If you have more than a single global, it makes sense to introduce a configuration object, as others have said (this is how typically work) but if you have a single parameter the confuguration object is not worth the effort, IMO. M. Simionato No, all the other configurable variables are offered as class attributes. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
feba I'm getting started in python, and it would be helpful to have a feba place to put up various code snippets I've made, so I don't have feba to send them individually to each person I want to show it to. feba I'd prefer to use something that would give me a directory for my feba use only, instead of something where you can only upload one at a feba time. I'd especially like to avoid stuff that uses CAPTCHAs feba and/or forced waiting periods. http://pastebin.com/? -- Skip Montanaro - s...@pobox.com - http://smontanaro.dyndns.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: help I'm getting delimited
On Tue, 2008-12-16 at 08:26 -0800, aka wrote: Hi, I'm going nuts over the csv.reader and UnicodeReader class. Somehow I can't get this method working which is supposed to read a csv file which name is inputted but here now hardcoded. What I need for now is that the string version of the list is put out for control. Later on I will only need to read the first column (id) of the csv file to be able to fill in a session var with a list of all ids. inp = c:/temp/test.csv roles = [] try: fp = open(inp, 'rb') reader = csv.reader(fp) for r in reader: rollen.append(r) except: msg = Er is iets mis met de UnicodeReader return dict(file=in,roles=str(roles)) Any help greatly appreciated! Cheers Did you intend inside the loop to write: roles.append(r) -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
MRAB: from collections import defaultdict match_counter = defaultdict(int) for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] match_counter[ip] += 1 This can be a little faster still: match_counter = defaultdict(int) for line in fileinput.input(sys.argv[1:]): ip = line.split(None, 1)[0] match_counter[ip] += 1 Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
The defaultdict option looks faster than the standard dict (20 secs aprox). Now i have: # import fileinput import sys from collections import defaultdict match_counter = defaultdict(int) for line in fileinput.input(sys.argv[1:]): match_counter[line.split()[0]] += 1 # About generators, now i get the idea of when use them and when not. Thanks MRAB, Lie and Gary. Now not only is faster but also cleaner and easy to understand =) -- http://mail.python.org/mailman/listinfo/python-list
Re: Copying files in directory
On Dec 15, 9:49 pm, pacsciad...@gmail.com wrote: I'm writing a project management system, and I need the ability to accept a directory name and move its contents to another directory. Can someone give me a code sample that will handle this? I can't find any copying functions in os or os.path. Regards, LeafStorm shutil's move function does what you describe -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
On Tue, 2008-12-16 at 12:27 +0200, Hendrik van Rooyen wrote: Dennis Lee Bieber w@ix.netcom.com wrote: 8- stuff blaming Davy for aluminum -- Isn't Davy a Brit? No, he was a Brit. He's dead now. His safety lamp lives on. It's a good thing its got that heat-sink sieve- it's enabled countless miners to flee when they see its change of colour. Thus it's saved the lives of a lot of canaries, and that's of ecological importance. Spot the apostrophe error, if you can. - Hendrik It's a good thing *its* got that heat-sink sieve- its - it has Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: zipfile.is_zipfile() and string buffers
En Tue, 16 Dec 2008 12:28:00 -0200, Brendan brendandetra...@yahoo.com escribió: I would like zipfile.is_zipfile(), to operate on a cStringIO.StringIO string buffer, but is seems only to accept file names as arguments. Should it not be able to handle string buffers too? A version of zipfile.is_zipfile() accepting both file names and file objects: def _check_zipfile(fp): try: if _EndRecData(fp): return True # file has correct magic number except IOError: pass return False def is_zipfile(filename): Quickly see if file is a ZIP file by checking the magic number. result = False try: if hasattr(filename, read): result = _check_zipfile(fp=filename) else: with open(filename, rb) as fp: result = _check_zipfile(fp) except IOError: pass return result -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Does Python3 offer a FrozenDict?
Hello group, is there anything like a frozen dict in Python3, so I could do a foo = { FrozenDict({a : b}): 3 } or something like that? Regards, Johannes -- Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verlästerung von Gott, Bibel und mir und bewusster Blasphemie. -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik 48d8bf1d$0$7510$54022...@news.sunrise.ch -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
For anything more complicated than a simple script, I find it easier to use some sort of config object. This could be a simple dictionnary type class, where the values can be set/retrieved by the other classes directly, or a more elaborate class including functions to set/ retrieve the variables. This way setting/retrieving can be 'smart' -- possibly looking at other variables, program states, thread count, whatever, for the requested config option. It also allows for a lot of expansion down the line if need be, rather than dealing with all sorts of global variables floating around - which gets annoying pretty quickly. On Dec 15, 9:45 pm, Giampaolo Rodola' gne...@gmail.com wrote: Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named use_gmt_times to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the ethical doubts I'm gonna write below. In first place I've never liked global variables too much and always preferred per-class-instance variables instead. The problem in my case is that I have to use such variable in two separated classes: FTPHandler and VirtualFileSystem. Also, I want that for no reason one class uses times in GMT and the other one local times. Another doubt is the naming convention. PEP-8 states that global variables should use the lower_case_naming_convention but I've seen a lot of library module using the UPPER_CASE_NAMING_CONVENTION. What am I supposed to do about it? Thanks in advance for any comment. --- Giampaolohttp://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
String slices work only for first string character ?
Hi, Can any one explain why the following string slice works only for the first character, but not for any other ? $ cat /tmp/tmp.py #!/usr/bin/env python data = 'F0023209006-0101' print data print |+data[0:1]+| print |+data[1:1]+| print |+data[2:1]+| $ python `cygpath -w /tmp/tmp.py` F0023209006-0101 |F| || || $ Thanks, Ron. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python plugin for Netbeans
On Dec 15, 3:23 pm, a a...@a.aa wrote: Netbeans added a python plugin to its plugin repository. Do you tried it? What do you think about this plugin? If you like netbeans already it's great to finally have python officially supported. I find netbeans to be easier to use than eclipse. -- http://mail.python.org/mailman/listinfo/python-list
Re: weird dict problem, how can this even happen?
Joel Hedlund joel.hedl...@gmail.com wrote: I should probably do this with lists instead because I can't really think of a way of salvaging this. Am i right? I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent values might change the hash and wrap them up: before changing the hash pop the item out of the dict, then reinsert it after the change. Alternatively give up on defining hash and __eq__ for FragmentInfo and rely on object identity instead. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: String slices work only for first string character ?
Can any one explain why the following string slice works only for the first character, but not for any other ? $ cat /tmp/tmp.py #!/usr/bin/env python data = 'F0023209006-0101' print data print |+data[0:1]+| print |+data[1:1]+| print |+data[2:1]+| $ python `cygpath -w /tmp/tmp.py` F0023209006-0101 |F| || || Slices are defined by [start_idx:end_idx] not [start_idx:length] so you want data[0:1] data[1:2] data[2:3] -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: tricky nested list unpacking problem
Chris Rebert wrote: On Mon, Dec 15, 2008 at 11:06 AM, Reckoner recko...@gmail.com wrote: Hi, I have lists of the following type: [1,2,3,[5,6]] and I want to produce the following strings from this as '0-1-2-3-5' '0-1-2-3-6' That was easy enough. The problem is that these can be nested. For example: [1,2,3,[5,6],[7,8,9]] which should produce '0-1-2-3-5-7' '0-1-2-3-5-8' '0-1-2-3-5-9' '0-1-2-3-6-7' '0-1-2-3-6-8' '0-1-2-3-6-9' also, [1,2,3,[5,6],7,[9]] should produce '0-1-2-3-5-7-9' '0-1-2-3-6-7-9' obviously, these are nested loops over the lists. The problem is that I don't know ahead of time how many lists there are or how deep they go. In other words, you could have: [1,2,3,[5,6,[10, 11]],7,[9,[1, 2, 3, 4, 5 ]]] Any help appreciated. I've really been having trouble with this. I hope that made sense. You just need a recursive list-flattening function. There are many recipes for these. Here's mine: def flatten(lst): if isinstance(lst, list): result = [] for item in lst: result += flatten(item) return result else: return [lst] flattened = flatten([1,2,3,[5,6,[10, 11]],7,[9,[1, 2, 3, 4, 5 ]]]) flattened [1, 2, 3, 5, 6, 10, 11, 7, 9, 1, 2, 3, 4, 5] '-'.join(str(num) for num in flattened) '1-2-3-5-6-10-11-7-9-1-2-3-4-5' Read the problem description again ... regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: weird dict problem, how can this even happen?
Duncan Booth wrote: I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent values might change the hash and wrap them up: before changing the hash pop the item out of the dict, then reinsert it after the change. That would probably require a lot of uncomfortable signal handling, especially for a piece of functionality I'd like to be as unobtrusive as possible in the application. Alternatively give up on defining hash and __eq__ for FragmentInfo and rely on object identity instead. Object identity wouldn't work so well for caching. Objects would always be drawn as they appeared for the first time. No updates would be shown until the objects were flushed from the cache. I've been experimenting with a list cache now and I can't say I'm noticing any change in performance for a cache of 100 items. I'm still using the hash to freeze a sort of object tag in order to detect changes, and I require both hash and object equality for cache hits, like so: def index(self, key): h = hash(key) for i, item in enumerate(self.items): if item.hash == h and item.key == key: return i raise KeyError(key) This seems to do what I want and does OK performance wise. Thanks again! /Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
Aaron Brady castiro...@gmail.com wrote: There's an 'I' in Python. No! It's supposed to be : There's a T in python. an is only used when the next word starts with a vowel, as in: It's been an hour now... All this is because English speakers are genetically incapable of moving their tongues. :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python3 offer a FrozenDict?
Johannes Bauer: is there anything like a frozen dict in Python3, so I could do a foo = { FrozenDict({a : b}): 3 } You can adapt this code to Python3 (and post a new recipe? It may be positive to create a new section of the Cookbook for Py3 only): http://code.activestate.com/recipes/414283/ Please remember that Py3 is very new, so 99% of the stuff present for Py2.x is absent. Using Py3 is your choice. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help improving number guessing game
The good news is that Python functions are objects too, so you can pass them as params to another function. duh, duh, duh, duh, duh! I knew I was missing something there. Thanks. if not mini = x = maxi: also thanks for this, I forgot about that. But I have it as if not minr guess maxr: because it's to DISALLOW the numbers to stay the same. That was just a suggestion, and it would have been pretty interesting IMHO as a basis for a from QD procedural scripting to OO application programing tutorial. Yeah, I can see that. -- http://mail.python.org/mailman/listinfo/python-list
Re: tricky nested list unpacking problem
bearophileh...@lycos.com writes: I was waiting to answer because so far I have found a bad-looking solution only. Seeing there's only your solution, I show mine too. It seems similar to your one. I think that the solution below is a bit clearer, although I think it is more resource intensive than my first one. I've switched to a generator function to make it more easily comparable. It's true that it's a problem that seems designed for Scheme! l1 = [1,2,3,[5,6]] l2 = [1,2,3,[5,6],[7,8,9]] l3 = [1,2,3,[5,6,[10, 11]],7,[9,[1, 2, 3, 4, 5 ]]] def flatten(x): if isinstance(x, list): for y in x: for z in flatten(y): yield z else: yield x def unpack(lst, acc=[]): i = len(acc) if i == len(lst): yield '-'.join(map(str, acc)) else: for x in flatten(lst[i]): for res in unpack(lst, acc + [x]): yield res -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Structure using whitespace vs logical whitespace
cmdrrickhun...@yaho.com wrote: I've been trying to search through the years of Python talk to find an answer to this, but my Googlefu is weak. In most languages, I'll do something like this xmlWriter.BeginElement(parent); xmlWriter.BeginElement(child); --xml.Writer.Characters(subtext); xmlWriter.EndElement(); xmlWriter.EndElement(); Where the dashes are indentation (since some newsgroup handlers don't do tabs well). XML writing is just an example. Yes, I hate that too. IMO Newsgroup and email clients should not remove indentation. In general, I'm using indentation to show logical flow through code. Python's choice to give semantic meaning to whitespace prevents me from doing such things. What was once reserved for logical use is now used syntactically. In 90% of cases, its not needed, and whitespace significance seems to be pretty effective. In that last 10%, however, I've been frustrated many times. When I first learned python I was occasionally bothered by this. Since then I have gotten used to it and would not have it any other way. I certainly would not consider changing the language for this. I consider the benefits of a uniform meaning of whitespace and the corresponding consistency of indentation style, as well as the lack of punctuation, to be well worth the price. Also, I have found over the years that, for reasons described below, that this price effectively drops to zero. I've been using python for a few years, and gotten around this in one way or another, but now I want to get other who work with me to pick up Python. All newbies to Python have trouble with the idea of whitespace sensitivity, but how can I convince them that it just works better when I have this construct which I want to use but can't. I disagree with the generalization that All newbies to Python have trouble with the idea I would say that perhaps most newbies that have experience with whitespace neutral languages experience some initial discomfort, which is expected for any change from what one is used to. I suspect that very few people who are new to programming dislike whitespace sensitivity. Has anybody found a way to emulate this behavior? I've often done it by opening an expression for the whole thing, but there's a lot of tasks where a single expression just isn't sufficient (such as things with assignment). This would depend on the specific case. In general, if you are writing lots of code that contains structure other than program control structure, you probably are missing an opportunity to use a data-driven approach. In other words, ideally the structure in your python code should be /only /program control structure, in which case the indentation will be exactly where you would want it to be. For that other 10%, you probably should code your content as data (either in an external file or as data literals in your code). The case in point is your example: xmlWriter.BeginElement(parent); xmlWriter.BeginElement(child); --xml.Writer.Characters(subtext); xmlWriter.EndElement(); xmlWriter.EndElement(); I would use a template system such as Genshi instead, so that kind of structure would not need to be in my python code in the first place. I know that this xmlWriter code is just an example, but I think that the principle I am describing really does apply more or less universally. If you are expressing nested structure other than program control structure, you should be expressing your structure as data. Here's another solution to your example that is more generally applicable to other situations: content = (element, parent, [ (element, child, [ (characters, subtext), ] ), ] ) do_something_with(content) (Sorry if the above indentation has been removed by evil software) In this case I have made the code data-driven, but include the data in my python code. This means you have the extra task of implementing *do_something_with()* but that is usually a trivial task, and worth the effort IMO because it makes the structure more readable and easier to modify. It also separates content from implementation, which is also a really good idea. For example, if at some point in the future I decide to use something else instead of *xmlWriter *to process the data, I can do so by changing the implementation of *do_something_with()*. PS. In my opinion the solution would be to have the option of entering a whitespace insensitive mode which uses C style {} and ;. The token to enter it could be as complicated as you want (in fact, it may make sense to make it complicated to discourage use unless it's really advantageous). I'd sugest {{ and }} or something bigger like {={ } =}. Only two problems: 1) I'm sure it would offend Guido's sense of language aesthetics 2) I'm sure the idea has been hashed over on this newsgroup to death... hence prefering a workaround instead. A definitive Yes to both 1 and 2 :-)
Re: Deepcopying slice objects
En Sun, 14 Dec 2008 15:43:01 -0200, Max Argus argus@googlemail.com escribió: I stumbled across a thread about that suggests fixing deepcopy to let it copy slice objects. ( http://mail.python.org/pipermail/python-list/2006-August/398206.html). I expected this to work and don't see any reason why it shouldn't in case there is a good reason why it dosen't work can someone please explain it. It works fine, both in 2.6 and 3.0: py from copy import copy, deepcopy py x = slice(1, 10, 2) py copy(x) slice(1, 10, 2) py deepcopy(x) slice(1, 10, 2) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
Quoth Lie Ryan lie.1...@gmail.com: On Tue, 16 Dec 2008 12:07:14 -0300, Federico Moreira wrote: Hi all, Im parsing a 4.1GB apache log to have stats about how many times an ip request something from the server. The first design of the algorithm was for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] if match_counter.has_key(ip): match_counter[ip] += 1 else: match_counter[ip] = 1 nitpick: dict.has_key is usually replaced with if ip in match_counter: ... I'd say it's just slightly more than a nitpick nowadays: since Python 3.0 does not support has_key, it's time to get used to not using it :) --RDM -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen inheriting
En Tue, 16 Dec 2008 07:29:19 -0200, Aaron Brady castiro...@gmail.com escribió: I have a file handle I want to inherit in a child process. I am looking at '_make_inheritable' in 'Popen', but it needs an instance, and by the time I have one, the subprocess is already running. Can't I call 'Popen._make_inheritable( None, handle )'? The method does not use 'self'. File handles are inherited by default, I think. What's your specific problem? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
On 16 Dic, 15:56, feba feb...@gmail.com wrote: On Dec 16, 8:29 am, s...@pobox.com wrote: feba I'm getting started in python, and it would be helpful to have a feba place to put up various code snippets I've made, so I don't have feba to send them individually to each person I want to show it to. feba I'd prefer to use something that would give me a directory for my feba use only, instead of something where you can only upload one at a feba time. I'd especially like to avoid stuff that uses CAPTCHAs feba and/or forced waiting periods. http://pastebin.com/? -- Skip Montanaro - s...@pobox.com -http://smontanaro.dyndns.org/ well, ignoring the fact that pastebin doesn't work for me for some reason, I'm talking about hosting it as a .py downloadable, not a hunk of text. code.google.com? It also has a SVN repository. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
well, ignoring the fact that pastebin doesn't work for me for some reason, I'm talking about hosting it as a .py downloadable, not a hunk of text. maybe one option is registering in some free project hosting service like code.google.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
Stuff like code.google, sf.net, are more oriented towards serious development, not just holding random apps, aren't they? Anyway, I found MediaFire, which looks like it will suffice for now. -- http://mail.python.org/mailman/listinfo/python-list
Re: help I'm getting delimited
Paul Watson wrote: On Tue, 2008-12-16 at 08:26 -0800, aka wrote: Hi, I'm going nuts over the csv.reader and UnicodeReader class. Somehow I can't get this method working which is supposed to read a csv file which name is inputted but here now hardcoded. What I need for now is that the string version of the list is put out for control. Later on I will only need to read the first column (id) of the csv file to be able to fill in a session var with a list of all ids. inp = c:/temp/test.csv roles = [] try: fp = open(inp, 'rb') reader = csv.reader(fp) for r in reader: rollen.append(r) except: msg = Er is iets mis met de UnicodeReader return dict(file=in,roles=str(roles)) Any help greatly appreciated! Cheers Did you intend inside the loop to write: roles.append(r) Also, the bare except will catch _all_ exceptions. You should catch only those you expect. In this case, it's catching your use of rollen instead of roles (probably unintentional) and then complaining about UnicodeReader, even though that's (probably, again!) not the problem. -- http://mail.python.org/mailman/listinfo/python-list
Python Dictionary Algorithm Question
Hello! I am in a beginning algorithms class this semester and I am working on a presentation. I want to discuss in some detail the algorithm python uses to determine the hash function for python dictionaries. Does anyone know what this algorithm is? Or where I can go to find information on it? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
2008/12/16 rdmur...@bitdance.com Python 3.0 does not support has_key, it's time to get used to not using it :) Good to know line.split(None, 1)[0] really speeds up the proccess Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Generator slower than iterator?
Hi all, Im parsing a 4.1GB apache log to have stats about how many times an ip request something from the server. The first design of the algorithm was for line in fileinput.input(sys.argv[1:]): ip = line.split()[0] if match_counter.has_key(ip): match_counter[ip] += 1 else: match_counter[ip] = 1 And it took 3min 58 seg to give me the stats Then i tried a generator solution like def generateit(): for line in fileinput.input(sys.argv[1:]): yield line.split()[0] for ip in generateit(): ...the same if sentence Instead of being faster it took 4 min 20 seg Should i leave fileinput behind? Am i using generators with the wrong aproach? Thanks in advance, Federico. -- http://mail.python.org/mailman/listinfo/python-list
AIM client code for Python?
I'd like to write an AIM bot in Python. I found and tried http://www.jamwt.com/Py-TOC/, but it doesn't work for me: Connecting... Traceback (most recent call last): File aimbot-1.py, line 17, in module bot.go() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 62, in go self.process_loop() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 156, in process_loop event = self.recv_event() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 230, in recv_event dtemp = self._socket.recv(buflen - len(data)) socket.error: (54, 'Connection reset by peer') I wrote to the author a week ago, but never got a reply. It could be as simple as changing the server addresses in toc.py, currently: TOC_SERV_AUTH = (login.oscar.aol.com, 2 ) TOC_SERV = ( toc.oscar.aol.com, 9898 ) ...but I don't understand AIM well enough to know the correct values (and was rather hoping that I wouldn't have to). Does anyone know how to get Py-TOC to work, or have another Python TOC implementation to suggest? Thanks, - Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python3 offer a FrozenDict?
On 16 Dec, 17:28, bearophileh...@lycos.com wrote: Johannes Bauer: is there anything like a frozen dict in Python3, so I could do a foo = { FrozenDict({a : b}): 3 } You can adapt this code to Python3 (and post a new recipe? It may be positive to create a new section of the Cookbook for Py3 only):http://code.activestate.com/recipes/414283/ There's actually only tiny changes needed (I believe) - Change exception syntax: raise AttributeError(A frozendict cannot be modified.) - (bugfix for the original version): add **kw arg to __new__ (passed to dict.__init__) Simple testing looks OK. And the resulting code is OK for both 2.x and 3.0. Moral - don't assume that all code needs to be rewritten for Python 3.0 :-) Paul. PS I imagine that 2to3 would have fixed this up fine, but it was so easy to do by hand that I didn't bother :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
On Dec 16, 8:29 am, s...@pobox.com wrote: feba I'm getting started in python, and it would be helpful to have a feba place to put up various code snippets I've made, so I don't have feba to send them individually to each person I want to show it to. feba I'd prefer to use something that would give me a directory for my feba use only, instead of something where you can only upload one at a feba time. I'd especially like to avoid stuff that uses CAPTCHAs feba and/or forced waiting periods. http://pastebin.com/? -- Skip Montanaro - s...@pobox.com -http://smontanaro.dyndns.org/ well, ignoring the fact that pastebin doesn't work for me for some reason, I'm talking about hosting it as a .py downloadable, not a hunk of text. -- http://mail.python.org/mailman/listinfo/python-list
Re: String slices work only for first string character ?
On Tue, 16 Dec 2008 13:35:27 + Barak, Ron ron.ba...@lsi.com wrote: Can any one explain why the following string slice works only for the first character, but not for any other ? I think that you need to reread the docs on slices. print |+data[0:1]+| print |+data[1:1]+| If you want the second character use data[1:2]. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Dictionary Algorithm Question
Brigette Hodson schrieb: Hello! I am in a beginning algorithms class this semester and I am working on a presentation. I want to discuss in some detail the algorithm python uses to determine the hash function for python dictionaries. Does anyone know what this algorithm is? Or where I can go to find information on it? Python's dict implementation doesn't have its own hashing algorithm. It completely relies upon the __hash__() function and the __eq__() comparison function of the objects that are used as keys. The source repository contains a document with some insights. Make your you read dictnotes.txt and the cmments in dictobject.c http://svn.python.org/view/python/branches/release25-maint/Objects/ Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: alt.possessive.its.has.no.apostrophe
Aaron Brady castiro...@gmail.com writes: On Dec 15, 11:04 am, Steve Holden st...@holdenweb.com wrote: Tim Chase wrote: Steve Holden wrote: This led to a schism between the British and the newly-independent Americans, who responded by taking the u out of colour, valour, and aluminium. Darn Americans and their alminim ;-) Next thing you know, they'll be putting an I in TEAM.[1] It's called humour. Or humor. Or incompetence ;-) There's an 'I' in Python. There's no 'F' in Python in this thread. -- Pete Forman-./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does not represent pete.for...@westerngeco.com-./\.- the opinion of Schlumberger or http://petef.22web.net -./\.- WesternGeco. -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
On Dec 16, 4:45 am, Giampaolo Rodola' gne...@gmail.com wrote: Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named use_gmt_times to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the ethical doubts I'm gonna write below. In first place I've never liked global variables too much and always preferred per-class-instance variables instead. The problem in my case is that I have to use such variable in two separated classes: FTPHandler and VirtualFileSystem. Also, I want that for no reason one class uses times in GMT and the other one local times. Another doubt is the naming convention. PEP-8 states that global variables should use the lower_case_naming_convention but I've seen a lot of library module using the UPPER_CASE_NAMING_CONVENTION. What am I supposed to do about it? Thanks in advance for any comment. --- Giampaolohttp://code.google.com/p/pyftpdlib/ Note also that PEP-8 states that _single_leading_underscore... from M import * does not import objects whose name starts with an underscore -- http://mail.python.org/mailman/listinfo/python-list
mysql hash generator in python
(sorry for my english, but i'm speak spanish) Hi list.. this is my first post... and obviously if for help.. I try to implement the password function of mysql in a python script. I read that the password function of mysql was implemented with a double sha1() I python i try this: example1: if __name__==__main__: s = hashlib.sha1() s.update('test') s2 = hashlib.sha1() s2.update(s.digest() print s2.hexdigest() This script show me the same hash that password function of mysql, but when i implement this in a class the hash is different??? why??? And if is posible??? can you show a example code of old_password function of mysql in python??? THNX -- http://mail.python.org/mailman/listinfo/python-list
Free place to host python files?
I'm getting started in python, and it would be helpful to have a place to put up various code snippets I've made, so I don't have to send them individually to each person I want to show it to. I'd prefer to use something that would give me a directory for my use only, instead of something where you can only upload one at a time. I'd especially like to avoid stuff that uses CAPTCHAs and/or forced waiting periods. I'd really rather not have to run a server off my own computer, if it can be avoided at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: AIM client code for Python?
On Tue, 16 Dec 2008 10:54:38 -0700, Joe Strout j...@strout.net wrote: I'd like to write an AIM bot in Python. I found and tried http://www.jamwt.com/Py-TOC/, but it doesn't work for me: Connecting... Traceback (most recent call last): File aimbot-1.py, line 17, in module bot.go() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 62, in go self.process_loop() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 156, in process_loop event = self.recv_event() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 230, in recv_event dtemp = self._socket.recv(buflen - len(data)) socket.error: (54, 'Connection reset by peer') I wrote to the author a week ago, but never got a reply. It could be as simple as changing the server addresses in toc.py, currently: TOC_SERV_AUTH = (login.oscar.aol.com, 2 ) TOC_SERV = ( toc.oscar.aol.com, 9898 ) ...but I don't understand AIM well enough to know the correct values (and was rather hoping that I wouldn't have to). Does anyone know how to get Py-TOC to work, or have another Python TOC implementation to suggest? You need an OSCAR-based AIM library. AOL discontinued TOC support several years ago. No TOC-based client can work on the AIM network. Twisted includes a (somewhat crufty) OSCAR implementation. There are probably also other Python OSCAR implementations. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_Oracle issues
On Dec 15, 12:59 pm, ron.re...@gmail.com ron.re...@gmail.com wrote: On Dec 15, 2:44 am, huw_at1 huwdjo...@gmail.com wrote: On Dec 11, 5:34 pm, ron.re...@gmail.com ron.re...@gmail.com wrote: On Dec 10, 9:48 am, huw_at1 huwdjo...@gmail.com wrote: Hey all. When usingcx_Oracleto run a procedure like: cursor.execute(select (obj.function(value)) from table where id=blah) I am getting the following error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 Looking at cursor.description I get: [('(obj.function(value))', type 'cx_Oracle.STRING', 4000, 4000, 0, 0, 1)] Any tips - i have never seen this error before but am guessing that the value being returned is too big for the buffer size set for the cursor. the procedure fetches data from a LOB. Any suggestions/confirmations? Many thanks This error is a problem with the PL/SQL, notcx_Oracle. You need to debug obj.function to see what kind of data is being accessed and then a data analysis of that data to understand why this error occurs. I can tell you the function is most likely expecting characters from a column that are numeric [0 .. 9] and is getting alpha characters. -- Ron Reidy Sr. Oracle DBA Hi thanks for the responses. Unfortunately the procedure in question is from a third party vendor so I can't really debug it so I'd say I was fairly stumped. Just out of interest how do you increase the output buffer size withcx_Oracle? Many thanks- Hide quoted text - - Show quoted text - Hi, Sure you can. You can see the PL/SQL source from the ditionary view ALL_SOURCE: select text from all_source where name = 'NAME_OF_FUNCTION'; From there, reverse engineeer which table(s) and column(s) are being accesses and do the data analysis. -- Ron Reidy Hi all, So I tried Rons query but unfortunately I got 0 records returned. However I can confirm that running the select query from a client does indeed generate the same error. Is there anything else I could try? Otherwise I'll just get in touch with the vendor I guess. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
bearophileh...@lycos.com writes: This can be a little faster still: match_counter = defaultdict(int) for line in fileinput.input(sys.argv[1:]): ip = line.split(None, 1)[0] match_counter[ip] += 1 Bye, bearophile Or maybe (untested): match_counter = defaultdict(int) for line in fileinput.input(sys.argv[1:]): ip = line[:line.index(' ')] match_counter[ip] += 1 Or even (untested, I've never tried this ;): from itertools import count match_counter = defaultdict(count) for line in fileinput.input(sys.argv[1:]): ip = line[:line.index(' ')] match_counter[ip].next() match_total = dict((key, val()) for key, val in match_counter.iteritems()) Obviously the variable 'ip' could be removed in all cases. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Dictionary Algorithm Question
You might be interested in the Beautiful Code book: http://oreilly.com/catalog/9780596510046/ It has a chapter on Python's dict implementation that is pretty good. On Tue, Dec 16, 2008 at 10:51 AM, Brigette Hodson brigettehod...@gmail.comwrote: Hello! I am in a beginning algorithms class this semester and I am working on a presentation. I want to discuss in some detail the algorithm python uses to determine the hash function for python dictionaries. Does anyone know what this algorithm is? Or where I can go to find information on it? Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
sorting for recursive folder rename
Hello all, I trying to recursively rename folders and files, and am looking for some ideas on the best way of doing this. The problem is that the given list of items can be in order, and one to all items may be renamed. Here is some preliminary code I have, but which does not work very well. self.toRename has the following structure : [ [original_name, new_name, os.path.isdir] .. ] # define these here for faster processing def split(item): return os.path.split(item) def addSep(path): return os.sep + path + os.sep def recursiveFolderSort(x,y): return cmp(y[0], x[0]) sortedRename = sorted(self.toRename) # make a list of all folders that will be processed foldersToAdjust = [] for item in sortedRename: if item[2] is False: oF = split(item[0])[1] # original folder name nF = split(item[1])[1] # new folder name if oF is not nF: foldersToAdjust.append((oF, nF)) # replace all occurences of folders in path for i in range(len(self.toRename)): for f in foldersToAdjust: oF = addSep(f[0]) # original folder name nF = addSep(f[1]) # new folder name self.toRename[i][0] = self.toRename[i][0].replace(oF,nF) self.toRename[i][1] = self.toRename[i][1].replace(oF,nF) if progressDialog.update(i) is False: error = 'cancelled' break # make sure renaming will be in correct order ! self.toRename.sort(recursiveFolderSort) First problem is adjusting the paths can take a very long time. Second problem is sorting is not always right and files get lost !! Any input welcome. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.environ.get('SSH_ORIGINAL_COMMAND') returns None
On Dec 15, 8:51 pm, Tzury Bar Yochay afro.syst...@gmail.com wrote: Trying to follow a technique found at bzr I did the following added to ~/.ssh/authorized_keys the command=my_parder parameter which point to a python script file named 'my_parser' and located in / usr/local/bin (file was chmoded as 777) in that script file '/usr/local/bin/my_parser' I got the following lines: #!/usr/bin/env python import os print os.environ.get('SSH_ORIGINAL_COMMAND', None) When trying to ssh e.g. 'ssh localhost' I get None on the terminal and then the connection is closed. You should define SSH_ORIGINAL_COMMAND in environment of the calling shell/application. -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_Oracle issues
On Dec 15, 12:59 pm, ron.re...@gmail.com ron.re...@gmail.com wrote: On Dec 15, 2:44 am, huw_at1 huwdjo...@gmail.com wrote: On Dec 11, 5:34 pm, ron.re...@gmail.com ron.re...@gmail.com wrote: On Dec 10, 9:48 am, huw_at1 huwdjo...@gmail.com wrote: Hey all. When usingcx_Oracleto run a procedure like: cursor.execute(select (obj.function(value)) from table where id=blah) I am getting the following error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 Looking at cursor.description I get: [('(obj.function(value))', type 'cx_Oracle.STRING', 4000, 4000, 0, 0, 1)] Any tips - i have never seen this error before but am guessing that the value being returned is too big for the buffer size set for the cursor. the procedure fetches data from a LOB. Any suggestions/confirmations? Many thanks This error is a problem with the PL/SQL, notcx_Oracle. You need to debug obj.function to see what kind of data is being accessed and then a data analysis of that data to understand why this error occurs. I can tell you the function is most likely expecting characters from a column that are numeric [0 .. 9] and is getting alpha characters. -- Ron Reidy Sr. Oracle DBA Hi thanks for the responses. Unfortunately the procedure in question is from a third party vendor so I can't really debug it so I'd say I was fairly stumped. Just out of interest how do you increase the output buffer size withcx_Oracle? Many thanks- Hide quoted text - - Show quoted text - Hi, Sure you can. You can see the PL/SQL source from the ditionary view ALL_SOURCE: select text from all_source where name = 'NAME_OF_FUNCTION'; From there, reverse engineeer which table(s) and column(s) are being accesses and do the data analysis. -- Ron Reidy Hi all, So I tried Rons query but unfortunately I got 0 records returned. However I can confirm that running the select query from a client does indeed generate the same error. Is there anything else I could try? Otherwise I'll just get in touch with the vendor I guess. -- http://mail.python.org/mailman/listinfo/python-list
subprocess returncode windows
Hello, I'm running into a strange situation with getting incorrect returncodes / exit status from python subprocess.call. I'm using a python script (runtime 2.6.1 on windows) to automate the deploy of java applications to glassfish application server. Below is an example of using a subprocess call to test the success / failure of the glassfish CLI tool asadmin Example.py: -- import sys from subprocess import * try: retcode = call(c:/glassfish/bin/asadmin.bat + list-system- properties --host mydomain --port 4848 --user admin server-01, shell=True) if retcode 0: print sys.stderr, Child was terminated by signal, -retcode else: print sys.stderr, Child returned, retcode except OSError, e: print sys.stderr, Execution failed:, e -- However, when I execute it, it gets the same returncode whether it fails or succeeds (0). - C:\python z:\bin\example.py Please enter the admin password ***Enters Good Password*** IIOP_SSL_MUTUALAUTH_PORT=33920 JMX_SYSTEM_CONNECTOR_PORT=38686 IIOP_LISTENER_PORT=33700 IIOP_SSL_LISTENER_PORT=33820 HTTP_LISTENER_PORT=38080 AJP_INSTANCE_NAME=WebReporting-01 HTTP_SSL_LISTENER_PORT=38181 JMS_PROVIDER_PORT=37676 AJP_PORT=18009 Command list-system-properties executed successfully. Child returned 0 C:\python z:\bin\example.py Please enter the admin password***Enters BAD PASSWORD*** Invalid user or password CLI137 Command list-system-properties failed. Child returned 0 C:\ When I execute this manually from the cmd.exe and I check the %errorlevel% it returns the correct levels: --- C:\c:\glassfish\bin\asadmin.bat list-system-properties --host mydomain --port 4848 --user admin server-01 Please enter the admin password***GOOD PASSWORD*** IIOP_SSL_MUTUALAUTH_PORT=33920 JMX_SYSTEM_CONNECTOR_PORT=38686 IIOP_LISTENER_PORT=33700 IIOP_SSL_LISTENER_PORT=33820 HTTP_LISTENER_PORT=38080 AJP_INSTANCE_NAME=WebReporting-01 HTTP_SSL_LISTENER_PORT=38181 JMS_PROVIDER_PORT=37676 AJP_PORT=18009 Command list-system-properties executed successfully. C:\echo %errorlevel% 0 C:\c:\glassfish\bin\asadmin.bat list-system-properties --host mydomain --port 4848 --user admin server-01 Please enter the admin password***BAD PASSWORD*** Invalid user or password CLI137 Command list-system-properties failed. C:\echo %errorlevel% 1 C:\ - I'm guessing that returncode isn't the same thing as exit status? Is there a way to get exit status using a subprocess function instead of returncode? Is this the right way to go about this? Thanks for any direction / advice you can provide. Andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
On 16 Dic, 18:01, ianaré ian...@gmail.com wrote: For anything more complicated than a simple script, I find it easier to use some sort of config object. This could be a simple dictionnary type class, where the values can be set/retrieved by the other classes directly, or a more elaborate class including functions to set/ retrieve the variables. This way setting/retrieving can be 'smart' -- possibly looking at other variables, program states, thread count, whatever, for the requested config option. It also allows for a lot of expansion down the line if need be, rather than dealing with all sorts of global variables floating around - which gets annoying pretty quickly. On Dec 15, 9:45 pm, Giampaolo Rodola' gne...@gmail.com wrote: Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named use_gmt_times to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the ethical doubts I'm gonna write below. In first place I've never liked global variables too much and always preferred per-class-instance variables instead. The problem in my case is that I have to use such variable in two separated classes: FTPHandler and VirtualFileSystem. Also, I want that for no reason one class uses times in GMT and the other one local times. Another doubt is the naming convention. PEP-8 states that global variables should use the lower_case_naming_convention but I've seen a lot of library module using the UPPER_CASE_NAMING_CONVENTION. What am I supposed to do about it? Thanks in advance for any comment. --- Giampaolohttp://code.google.com/p/pyftpdlib/- Nascondi testo citato - Mostra testo citato - All the modificable options the library has acquired so far consist of class attributes and I'm ok with that. The only option that should be global is use_gmt_times because it is supposed to be used in two classes and I want that both of them use the same parameter. Using a Config class for a single option like use_gmt_times is not worth the effort, IMO. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
sys.maxint in Python 2.6.1 (amd64) on Windows XP x64
Hi, I installed the amd64 version of Python 2.6.1 on my Windows XP x64 system. I was expecting sys.maxint to be 9223372036854775807 (or 2 ^63 -1), but instead I got 2147483647 (i.e., 2^31-1) just like what I got from a 32-bit version of Python. Is this by design or does it indicate a bug or an installation problem? Thank you very much! --lin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Dictionary Algorithm Question
Brigette Hodson wrote: Hello! I am in a beginning algorithms class this semester and I am working on a presentation. I want to discuss in some detail the algorithm python uses to determine the hash function for python dictionaries. Does anyone know what this algorithm is? Or where I can go to find information on it? Thanks. Look in http://svn.python.org/view/python/tags/r26/Objects/ for dictnotes.txt and dictobject.c. Good luck with the class! regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python3 offer a FrozenDict?
Paul Moore: Moral - don't assume that all code needs to be rewritten for Python 3.0 :-) In practice this time your moral is of little use: having a place that allows you to choose Py3 OR Py2 code is much better and tidier, helps you save time, helps you avoid wasting some time, etc. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
zipfile.is_zipfile() and string buffers
I would like zipfile.is_zipfile(), to operate on a cStringIO.StringIO string buffer, but is seems only to accept file names as arguments. Should it not be able to handle string buffers too? -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.maxint in Python 2.6.1 (amd64) on Windows XP x64
Lin schrieb: Hi, I installed the amd64 version of Python 2.6.1 on my Windows XP x64 system. I was expecting sys.maxint to be 9223372036854775807 (or 2 ^63 -1), but instead I got 2147483647 (i.e., 2^31-1) just like what I got from a 32-bit version of Python. Is this by design or does it indicate a bug or an installation problem? Thank you very much! This is by design. In their infinitive wisdom Microsoft has decided to make the 'long' C type always a 32 bit signed integer - even on 64bit systems. On most Unix systems a long is at least 32 bit but usually sizeof(ptr). Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess returncode windows
Andrew schrieb: Hello, I'm running into a strange situation with getting incorrect returncodes / exit status from python subprocess.call. I'm using a python script (runtime 2.6.1 on windows) to automate the deploy of java applications to glassfish application server. Below is an example of using a subprocess call to test the success / failure of the glassfish CLI tool asadmin Example.py: -- import sys from subprocess import * try: retcode = call(c:/glassfish/bin/asadmin.bat + list-system- properties --host mydomain --port 4848 --user admin server-01, shell=True) if retcode 0: print sys.stderr, Child was terminated by signal, -retcode else: print sys.stderr, Child returned, retcode except OSError, e: print sys.stderr, Execution failed:, e Don't use shell=True! Instead use a list of arguments without shell=True: call([c:/glassfish/bin/asadmin.bat, list-system-properties, --host mydomain, --port 4848, --user admin, server-01]) That should solve your quoting issues on Windows and fix your code. shell=True is considered evil and should be avoided whenever possible. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: sorting for recursive folder rename
ianaré wrote: Hello all, I trying to recursively rename folders and files, and am looking for some ideas on the best way of doing this. The problem is that the given list of items can be in order, and one to all items may be renamed. Here is some preliminary code I have, but which does not work very well. self.toRename has the following structure : [ [original_name, new_name, os.path.isdir] .. ] # define these here for faster processing def split(item): return os.path.split(item) def addSep(path): return os.sep + path + os.sep def recursiveFolderSort(x,y): return cmp(y[0], x[0]) sortedRename = sorted(self.toRename) # make a list of all folders that will be processed foldersToAdjust = [] for item in sortedRename: if item[2] is False: if not item[2]: oF = split(item[0])[1] # original folder name nF = split(item[1])[1] # new folder name if oF is not nF: if oF != nF: foldersToAdjust.append((oF, nF)) # replace all occurences of folders in path for i in range(len(self.toRename)): for f in foldersToAdjust: oF = addSep(f[0]) # original folder name nF = addSep(f[1]) # new folder name self.toRename[i][0] = self.toRename[i][0].replace(oF,nF) self.toRename[i][1] = self.toRename[i][1].replace(oF,nF) if progressDialog.update(i) is False: if not progressDialog.update(i): error = 'cancelled' break # make sure renaming will be in correct order ! self.toRename.sort(recursiveFolderSort) First problem is adjusting the paths can take a very long time. Second problem is sorting is not always right and files get lost !! Any input welcome. You should use is and is not _only_ when checking for _identity, ie are these 2 both references to the _same_ object. Most of the time that would be x is None or x is not None. -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory leak when using a C++ module for Python
When I tried the C++ function with a C++ main() (skipping the Python part) it didn't show any memory problem, but I'll re-check it anyway, thanks... On Dec 16, 9:16 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 11 Dec 2008 15:35:58 -0200, Jaume Bonet jaume.bo...@gmail.com escribió: This is the function that is visible from python and the one that the python code calls: static PyObject * IMFind (PyObject *self, PyObject *args, PyObject *kwargs) { Your function does not call any Python function except PyArg_ParseTupleAndKeywords (which does not modify reference counts). So it's unlikely that this could cause any memory leak. I'd revise how memory is allocated and deallocated on the C++ side. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Where is a good open source python project to be used as example?
I'm looking for a python project to use as example to learning python. The project should have these features: 1. is almost fully unit tested 2. use consistently the code convention recommended by PEP 8 3. it's elements are almost fully documented Extra point features are: 4. building, assembling, and release automation Did you know where are such projects? -- http://mail.python.org/mailman/listinfo/python-list
executables no longer executing on PC's without Python installed
Hi, I recently figured out a problem that came up with the latest versions of Python and cx_Freeze. I thought I post it here so that it might be usefull to someone. The problem was that, when I switched to Python 2.6.x and cx_Freeze-4.0.1.win32-py2.6.msi, the executables that were produced ran perfectly on my PC but not any other PC. They did not print any useful information whatsoever. Googling around, I learned that it had to do with Visual Studio being installed on my PC and not on the other PC's. The common solution that worked for other people was to put the redistributable manifest and DLL's from C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT, into the same directory as the generated EXE. This didn't work for me. With the help of Anthony Tuininga, I finally tracked it down to the DLL version. In the good ol' days, when your application was lacking the C rntime library DLL in its search path, it gave a clear warning. e.g. can not find msvcr71.dll or something like that. The only thing you needed to do was to go look for one (either on your PC or on the internet), and pluck whatever DLL with that name into the search path, typically in the same directory as your exe or windows \system32. It didn't care about different versions of DLL's. Now with the advent of at least Visual Studio 2008 (and probably 2005, but I skipped that one), Microsoft, in its infinite wisdom, decided that that method was way too easy for everyone and came up with yet another way to torment everyone that dares to develop software in anything else than Microsoft monstrosities. I am referring to these mysterious things with names like side by side installation, SxS, manifests, assemblies, ... Why does the noble community of enlightened scholars developing Python care at all ? Because Python 2.6 binaries for Windows are now compiled using Visual Studio 2008. In essence, that should not mean more than replacing your msvcr71.dll with msvcr90.dll. Unfortunately, you inherit this assemblies crap with it. The new terminology invented with this and the MSDN articles on this subject make it only more obscure and complicated than it should be. In a nutshell, DLL's now are attributed with a version number. Executables generated with VS2008 are now restricted to run only with a predefined specific version of a DLL. This allows you to run executable A with version X of a DLL and another exe with version Y of that same DLL and not be affected with obscure bugs caused by pairing the wrong version of a DLL with an exe (the infamous DLL hell). How do you pair an exe with a particular DLL version ? That is done with manifest files, basically a small XML file, listing the exact version number and some obscure hash numbers for integrity checking. I haven't figured out how to manually produce these (VS2008 does this for you) but fortunately for us, Python developers we don't need to care. We just have to use the same one the Python distribution was compiled with. How do I know which version Python is compiled with ? The easiest way is to install Python with the option install just for me. This has the result that the msvcrxx.dll used by Python is copied into the c:\pythonxx directory instead of in a common windows\system32 folder (or something like that). This was my first mistake, I used the other option install for other users. This should not be a problem. cx_Freeze is clever enough to go out and find this DLL for you. It will probably find the right one, PROVIDING you have the right version of the DLL's in your search path. Now back to Microsoft. Up until around 9/16/2008, there was only 1 version of msvcr DLL's, nl. 9.0.21022.8 and that was good, because it happens to be the same version Python was installed with. The only thing you have to do is to accompany your generated exe with a manifest with the correct hieroglyphs, copy this dll in the same directory and you were done. (you actually need 2 manifest files: one that accompanies to the exe which DLL version it needs, and another manifest file that specifies the versions of the DLL. The exe manifest can be embedded in the exe). Poor old Anthony Tuininga had to figure this out the hard way. He makes our lives a lot easier by already embedding the correct exe manifest into the executable. You can check this by opening the generated binary with a hex editor and scroll down until you see some XML. That is the manifest. That will tell you which DLL's it needs and which version (nl. 9.0.21022.8). It needs to be this version because of the version of Visual Studio 2008 used to compile Python itself. Having Visual Studio 2008 installed on your PC while freezing your Python apps should not be a problem. Even if you didn't specify install just for me, cx_Freeze will probably find msvcr90.dll somewhere. But then came Visual Studio 2008 SP1. With it came an updated msvcr90.dll with version 9.00.30729.1. That is what I had installed and things went south from
Re: subprocess returncode windows
On Dec 16, 12:50 pm, Christian Heimes li...@cheimes.de wrote: Andrew schrieb: Hello, I'm running into a strange situation with getting incorrect returncodes / exit status from python subprocess.call. I'm using a python script (runtime 2.6.1 on windows) to automate the deploy of java applications to glassfish application server. Below is an example of using a subprocess call to test the success / failure of the glassfish CLI tool asadmin Example.py: -- import sys from subprocess import * try: retcode = call(c:/glassfish/bin/asadmin.bat + list-system- properties --host mydomain --port 4848 --user admin server-01, shell=True) if retcode 0: print sys.stderr, Child was terminated by signal, -retcode else: print sys.stderr, Child returned, retcode except OSError, e: print sys.stderr, Execution failed:, e Don't use shell=True! Instead use a list of arguments without shell=True: call([c:/glassfish/bin/asadmin.bat, list-system-properties, --host mydomain, --port 4848, --user admin, server-01]) That should solve your quoting issues on Windows and fix your code. shell=True is considered evil and should be avoided whenever possible. Christian Thanks Christian, I've removed shell=True, unfortunately, if I structure the call like: call([c:/glassfish/bin/asadmin.bat, list-system-properties, -- host mydomain, --port 4848, --user admin, server-01]) It doesn't seem to recognize any arguments after list-system- properties. If I structure it like: call(c:/glassfish/bin/asadmin.bat +list-system-properties --host mydomain --port 4848 --user admin server-01) Then it executes correctly but still gives invalid returncode of 0 when it fails instead of 1. Andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.maxint in Python 2.6.1 (amd64) on Windows XP x64
I installed the amd64 version of Python 2.6.1 on my Windows XP x64 system. I was expecting sys.maxint to be 9223372036854775807 (or 2 ^63 -1), but instead I got 2147483647 (i.e., 2^31-1) just like what I got from a 32-bit version of Python. Is this by design or does it indicate a bug or an installation problem? Thank you very much! This is by design. In their infinitive wisdom Microsoft has decided to make the 'long' C type always a 32 bit signed integer - even on 64bit systems. On most Unix systems a long is at least 32 bit but usually sizeof(ptr). Ah, this makes sense. Thanks.. The main reason I'm trying 64-bit Python is that I want to write files bigger than 4GB. This should work on Windows x64, right? (i.e., are the pointers bona fide 64 bit?) -lin -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is a good open source python project to be used as example?
On Tue, 16 Dec 2008 19:13:00 GMT Andrea Francia andrea.fran...@remove-from-here.ohoihihoihoih.to-here.gmx.it wrote: I'm looking for a python project to use as example to learning python. The project should have these features: 1. is almost fully unit tested 2. use consistently the code convention recommended by PEP 8 3. it's elements are almost fully documented Extra point features are: 4. building, assembling, and release automation Did you know where are such projects? http://www.PyGreSQL.org/. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generator slower than iterator?
Arnaud Delobelle arno...@googlemail.com writes: match_total = dict((key, val()) for key, val in match_counter.iteritems()) Sorry I meant match_total = dict((key, val.next()) for key, val in match_counter.iteritems()) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
2008/12/16 feba feb...@gmail.com: Stuff like code.google, sf.net, are more oriented towards serious development, not just holding random apps, aren't they? Anyway, I found MediaFire, which looks like it will suffice for now. Take a look to Dropbox (http://www.getdropbox.com/). You can use it to directly share files with your friends or to create a public link to your files so other people can download them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is a good open source python project to be used as example?
D'Arcy J.M. Cain wrote: On Tue, 16 Dec 2008 19:13:00 GMT Andrea Francia wrote: I'm looking for a python project to use as example to learning python. The project should have these features: 1. is almost fully unit tested 2. use consistently the code convention recommended by PEP 8 3. it's elements are almost fully documented Extra point features are: 4. building, assembling, and release automation Did you know where are such projects? http://www.PyGreSQL.org/. Thanks! But I can't find any unit test in the code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is a good open source python project to be used as example?
On Tue, 16 Dec 2008 20:03:21 GMT Andrea Francia andrea.fran...@remove-from-here.ohoihihoihoih.to-here.gmx.it wrote: Did you know where are such projects? http://www.PyGreSQL.org/. Thanks! But I can't find any unit test in the code. Look again. They are in the files named TEST_PyGreSQL_classic.py and TEST_PyGreSQL_dbapi20.py. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen inheriting
On Dec 16, 4:15 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 16 Dec 2008 07:29:19 -0200, Aaron Brady castiro...@gmail.com escribió: I have a file handle I want to inherit in a child process. I am looking at '_make_inheritable' in 'Popen', but it needs an instance, and by the time I have one, the subprocess is already running. Can't I call 'Popen._make_inheritable( None, handle )'? The method does not use 'self'. File handles are inherited by default, I think. What's your specific problem? -- Gabriel Genellina I want a dual-console application for some multi-threaded output. The main process spawns a second process in a second window, and directs its readout through a pipe. That is, the second process is just a dummy, print pipe directly to console. It worked when I used the 'stdin= PIPE' keyword in Popen, but passing my own pipe handle on the command line isn't working. The keyword is a workaround. File handles are inherited by default, I think. I thought so too. The web seems to say that on Linux they are, and on Windows, you need to call DuplicateHandle for it. By the way, there are a few solutions to the inheritance problem. 1. Override __init__ and __del__ in a subclass. 2. Assign DummyClass= Popen._make_inheritable 3. Override Popen._execute_child to call _make_inheritable, then call the super method. -- http://mail.python.org/mailman/listinfo/python-list
Can anyone suggest a good HTTP/1.1 web client?
Hi all, I have to connect to a secure website every second to get the data and then post to it. I have been investigating on many web clients in python, but nothing fits the bill properly. The ones I tried implementing are: 1. httplib based - I created myself. (I cannot use urllib2 since I have to transfer files, and urllib2 doesnt have multipart content-type support) 2. Twisted web client. I also looked at mechanize etc too. The problems I face are - 1. I liked twisted a lot, but when I implemented it, I found that client support is there only for twisted.web and not twisted.web2. Since I connect to the same website every time, I would like to have persistent connections and since twisted.web is HTTP/1.0, persistent connection support is not yet there. Without persistent connections, I would have to have TCP connection handshake everytime and it is taking too much time. 2. Since I connect to the website every second, I have to have many connections running at the same time. I am worried that creating threads for each connection is going to be a big problem (esp if the server response is slow), since the processor will get swamped - especially since there are many other activities going on in the machine. 3. I would also like to pipe line the requests - esp if the response is slow. Other requirements: 1. HTTPS Support 2. Connection through proxy. Is there any good web client which I can use straight up? Or would I have to implement the whole thing myself? It looks like a big beast and I was wondering whether python provides it straight up. Regards K -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.maxint in Python 2.6.1 (amd64) on Windows XP x64
Lin schrieb: Ah, this makes sense. Thanks.. The main reason I'm trying 64-bit Python is that I want to write files bigger than 4GB. This should work on Windows x64, right? (i.e., are the pointers bona fide 64 bit?) You can create files with more than 4GB on a 32bit OS, too. It depends on the file system. It works with NTFS but I'm not sure how FAT32 deals with large files. My DVB-S receiver with USB port chokes on files with more than 2 GB. Christian -- http://mail.python.org/mailman/listinfo/python-list
mod_python resources
I'm trying again because I'm stubborn. Maybe the fourth time will be the charm... Are there any good tutorials out there for setting up Apache with mod_python? Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list