[ANNOUNCE] PyGObject 2.27.0 – unstable release
I am pleased to announce version 2.27.0 of the Python bindings for GObject. A lot of fixes went in under the hood include fixes to the Windows build environment. On the Introspection side we are getting closer to parity with PyGtk interfaces with notes from people who have successfully ported their plugins and apps.I would like to thank the numerous bug and patch filers including the GEdit team for letting us know what they need for us to support them. Keep those bugs coming and hop on irc to pester us until we fix your issue. Some higlights include: * better handling of virtual methods * fixed gobject inheritance model * you can now call dir on dynamic modules to see what member exist * the Tree* API is much nicer, exporting a lot of the convenience APIs that exist in PyGtk * cairo_rectangle_int_t is supported as a foreign type if pycairo exports it (patch at https://bugs.freedesktop.org/show_bug.cgi?id=3) * some Python 3 fixes so we can compile under Python 3.2 The new release is available from ftp.gnome.org as and its mirrors: http://download.gnome.org/sources/pygobject/2.27/ What’s new since PyGObject 2.26.0? * Implement richcompare for GIBaseInfo (Jonathan Matthew) * [gi] add the rectangle_int_t forign cairo type (John (J5) Palmieri) * add a foreign type for cairo_rectangle_int_t and allow it to be caller-allocated (John (J5) Palmieri) * [gi] add overrides to Gtk.Editable (John (J5) Palmieri) * [gi] handle virtual invokers (John (J5) Palmieri) * add overrides for the insert* apis of list_store and tree_store (John (J5) Palmieri) * fix dialogs overrides which were relying on broken inheritance behavior (John (J5) Palmieri) * Add a overrides registry so we can refrence overrides inside the module (John (J5) Palmieri) * setup.py: ease maintenance burden for tests installation (Dieter Verfaillie) * fix inheritence issues in overrides (John (J5) Palmieri) * tests: add runtests-windows.py script (Dieter Verfaillie) * pygobject_postinstall.py: remove pygobject-2.0.pc treatment from postinstall as pkg-config on windows figures out the correct prefix at runtime (Dieter Verfaillie) * pygobject_postinstall.py: remove shortcut creation (Dieter Verfaillie) * setup.py: formatting cleanup, makes things readable (Dieter Verfaillie) * setup.py: build and install tests (Dieter Verfaillie) * setup.py: install documentation when available on build system (Dieter Verfaillie) * setup.py: install pygobject-codegen script (Dieter Verfaillie) * setup.py: install fixxref.py script (Dieter Verfaillie) * setup.py: rearrange constants (Dieter Verfaillie) * setup.py: check python version and pkgconig availability before anything else (Dieter Verfaillie) * setup.py: simplify sys.platform != 'win32' detection and error reporting (Dieter Verfaillie) * setup.py: rearrange imports (Dieter Verfaillie) * README.win32: update build instructions (Dieter Verfaillie) * dsextras.py: formatting cleanup, makes things readable (Dieter Verfaillie) * dsextras.py: add ggc4 to MSVC compatible struct packing comment (Dieter Verfaillie) * dsextras.py: use the pkgc_ functions instead of repeating pgk-config incantations all over the place (Dieter Verfaillie) * dsextras.py: add pkgc_get_version and pkgc_get_defs_dir functions (Dieter Verfaillie) * dsextras.py: PEP8: Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. (Dieter Verfaillie) * dsextras.py: use True/False instead of 1/0 (Dieter Verfaillie) * dsextras.py: rearrange imports (Dieter Verfaillie) * Add distutils generated build/dist directories and eclipse configuration files to .gitignore (Dieter Verfaillie) * [gi] add tests for calling dir on a dynamic module (John (J5) Palmieri) * [gi] dir() now works for modules (Deepankar Sharma) * Don't check the inner type when comparing gpointers (Simón Pena) * Release GIL when calling into C functions (John (J5) Palmieri) * _gi.Repository : Implement missing info bindings. (José Aliste) * include Python.h so that PY_VERSION_HEX gets defined (John (J5) Palmieri) * [gi] make overrides work for python 3.x protocols and alias for python 2.x (John (J5) Palmieri) * Override Gtk.Widget.translate_coordinates to not return success value (Sebastian Pölsterl) * Override Gtk.TreeViewColumn.cell_get_position to not return success value (Sebastian Pölsterl) * Override get_path_at_pos and get_dest_row_at_pos of Gtk.TreeView to not return success value (Sebastian Pölsterl) * Override Gtk.TreeSortable.get_sort_column_id to not return success value (Sebastian Pölsterl) * Override forward_search and backward_search of Gtk.TextIter to not return success value (Sebastian Pölsterl) * Override Gtk.TextBuffer.get_selection_bounds to not return success value (Sebastian
Re: Class extension confusion :(
r0g wrote: On 10/11/10 09:52, Peter Otten wrote: r0g wrote: I have a subclass of BaseHHTPRequestHandler which uses a dictonary paths and a function api_call which are defined in the main namespace of the module. I'd rather I was able to pass these object to the constructor and store them as data attributes self.paths and self.api_call but I'm not sure how to do that properly. My understanding is that one may extend a constructor by defining it's __init__ method, calling the parents constructor and then adding ones own attributes to taste. What I don't understand is where or how I am supposed to get these extra constructor arguments into the class given that I don't instantiate it myself, it is seemingly instantiated by HTTPServer class that I pass it to e.g. httpd = HTTPServer(server_address, PlainAJAXRequestHandler) I wondered if I ought to instantiate an instance of PlainAJAXRequestHandler, set the attributes (either manually or by extending it's constructor) and pass that to HTTPServer but I figured it expects a class not an instance as it probably wants to spawn one instance for each request so that would be a non starter. Might I need to subclass HTTPServer, find the bit that instantiates the request handler and override that so it passes it's constructor more parameters? Right now I'm pretty confused, can somebody please tell me how I might accomplish this, what I'm failing to grasp or point me to the docs that explain it - I've spent the last hour or two plowing through docs to no avail, I guess it's a case of keyword ignorance on my part! Code follows... Try passing a factory function instead of a class. Untested: from functools import partial class PlainAJAXRequestHandler(BaseHTTPRequestHandler): def __init__(self, api_call, paths, *args, **kw): BaseHTTPRequestHandler.__init__(self, *args, **kw) self.api_call = api_call self.paths = paths paths = ... api_call = ... httpd = HTTPServer( server_address, partial(PlainAJAXRequestHandler, paths, api_call)) Great, that looks ideal Peter, thanks very much :) One more question quick question if you have time... I actually subclass the class in question later on to provide an SSL secured connection, is it possible (or even advisable) to do the following to spare me having to modify the derived classes init (and any subsequent classes' inits) too?... PlainAJAXRequestHandler = partial(PlainAJAXRequestHandler, paths, api_call)) ^??? Remap name to new extended class class SecureAJAXRequestHandler(PlainAJAXRequestHandler): That's not possible; you are trying to subclass a function. What you can do (again untested): def make_handler_class(paths, api_call): class MyHandler(BaseHTTPRequestHandler): paths = paths api_call = staticmethod(api_call) return MyHandler PlainAJAXRequestHandler = make_handler_class(paths, api_call) class SecureAJAXRequestHandler(PlainAJAXRequestHandler): ... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Eval *always* Evil?
On 11/10/2010 6:39 PM, Robert Kern wrote: On 2010-11-10 17:14 , Christian Heimes wrote: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. If you have to use eval, use the 2 or 3 argument form with a globals and locals dictionary. This lists the variables and functions that eval can see and touch. The Python documentation for this is not very good: If the globals dictionary is present and lacks ‘__builtins__’, the current globals are copied into globals before expression is parsed. This means that expression normally has full access to the standard __builtin__ module and restricted environments are propagated. What this means is that you have to put in __builtins__ to PREVENT all built-ins from being imported. See http://lybniz2.sourceforge.net/safeeval.html for something readable on how to use eval safely. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Eval *always* Evil?
Robert Kern robert.k...@gmail.com writes: On 2010-11-10 17:14 , Christian Heimes wrote: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. Still - it is used in the standard library... -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions: While And List Comprehension
James Mills wrote: On Thu, Nov 11, 2010 at 11:01 AM, alex23 wuwe...@gmail.com wrote: +1 on this approach. Clear and obvious and not reliant on any library modules other than sys. itertools, what WAS I thinking? :) maybe: import sys from itertools import islice print [v for v in islice((line for line in sys.stdin), 0, 5)] (line for line in sys.stdin) and sys.stdin are equivalent as are [v for v in items] and list(items) So print list(islice(sys.stdin, 5)) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: How convert list to nested dictionary?
Hello, On Thu, Nov 04, 2010 at 02:10:12PM -0700, macm wrote: How convert list to nested dictionary? l ['k1', 'k2', 'k3', 'k4', 'k5'] result {'k1': {'k2': {'k3': {'k4': {'k5': {}} http://www.amk.ca/python/writing/functional so, why didn't you try python's reduce? IMO this is trivial: l ['k1', 'k2', 'k3', 'k4', 'k5'] reduce(lambda x,y: {y:x}, l.__reversed__()) {'k1': {'k2': {'k3': {'k4': 'k5' reduce(lambda x,y: {y:x}, l.__reversed__(), dict()) {'k1': {'k2': {'k3': {'k4': {'k5': {}} second reduce uses empty dict for seed. -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
Re: Class extension confusion :(
On 10/11/10 09:52, Peter Otten wrote: class PlainAJAXRequestHandler(BaseHTTPRequestHandler): def __init__(self, api_call, paths, *args, **kw): BaseHTTPRequestHandler.__init__(self, *args, **kw) self.api_call = api_call self.paths = paths Hmm, the plot thickens! I always thought you had to call the parent constructor first (as above) when extending a constructor (not that I've had occasion to do that in a long time), but it turns out when I do this the lines below it never get executed and when I move them above that line they seem to work fine so it appears I was wrong about that. I've tried typing many variants of python class extend constructor into google over the last few days but I'm damned if I can find the docs explaining this. I'm sure I found them several years back when I first too up python, maybe by google-fu is on the wane! Anyway, that's not my main question, this is... The extra names that I pass to functools.partial seem to be bound permanently into the namespace of my class now i.e. I can reference them as 'api_call' and 'paths' anywhere in the classes' methods as opposed to having to assign them in the constructor and reference them as 'self.api_call' and 'self.paths'. I'm not 100% how that's working but in practical terms it suggests to two lines assigning those names to data attributes are redundant as I can access them anywhere anyway. Indeed, I've commented them out and my app still seems to work fine so... Question A) Are there any good reasons why I shouldn't just do that? (other than B!) Question B) The only reason I can think of so far is that I don't have a clear picture of how those names came to end up in that scope, it seems very convenient but I'm worried it's black magic of some sort! Could anyone explain or point me to the right docs please? Please shout if you would like to see the source. Thanks muchly :) Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Eval *always* Evil?
On 11 November 2010 09:07, John Nagle na...@animats.com wrote: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. If you have to use eval, use the 2 or 3 argument form with a globals and locals dictionary. This lists the variables and functions that eval can see and touch. The Python documentation for this is not very good: If the globals dictionary is present and lacks ‘__builtins__’, the current globals are copied into globals before expression is parsed. This means that expression normally has full access to the standard __builtin__ module and restricted environments are propagated. What this means is that you have to put in __builtins__ to PREVENT all built-ins from being imported. Aren't I already doing this? result = eval(xpath_command, {__builtins__:[]},{x: x}) SM -- http://mail.python.org/mailman/listinfo/python-list
Re: Class extension confusion :(
r0g wrote: On 10/11/10 09:52, Peter Otten wrote: class PlainAJAXRequestHandler(BaseHTTPRequestHandler): def __init__(self, api_call, paths, *args, **kw): BaseHTTPRequestHandler.__init__(self, *args, **kw) self.api_call = api_call self.paths = paths Hmm, the plot thickens! I always thought you had to call the parent constructor first (as above) when extending a constructor (not that I've had occasion to do that in a long time), but it turns out when I do this the lines below it never get executed and when I move them above that line they seem to work fine so it appears I was wrong about that. I've I didn't believe you until I had a look into the source. The meat is in SocketServer.py: class BaseRequestHandler: [snip] def __init__(self, request, client_address, server): self.request = request self.client_address = client_address self.server = server try: self.setup() self.handle() self.finish() finally: sys.exc_traceback = None# Help garbage collection def setup(self): pass def handle(self): pass def finish(self): pass As you can see this doesn't use __init__() just to set up the instance, it makes it the only method that is called by client code. That's an unusual design decision, to say the least. tried typing many variants of python class extend constructor into google over the last few days but I'm damned if I can find the docs explaining this. I'm sure I found them several years back when I first too up python, maybe by google-fu is on the wane! Anyway, that's not my main question, this is... The extra names that I pass to functools.partial seem to be bound permanently into the namespace of my class now i.e. I can reference them as 'api_call' and 'paths' anywhere in the classes' methods as opposed to having to assign them in the constructor and reference them as 'self.api_call' and 'self.paths'. I'm not 100% how that's working but in practical terms it suggests to two lines assigning those names to data attributes are redundant as I can access them anywhere anyway. Indeed, I've commented them out and my app still seems to work fine so... Question A) Are there any good reasons why I shouldn't just do that? (other than B!) No. Use either class B(A): path = ... or class B(A): def __init__(self, path, *args, **kw): self.path = path A.__init__(self, *args, **kw) not both. Question B) The only reason I can think of so far is that I don't have a clear picture of how those names came to end up in that scope, it seems very convenient but I'm worried it's black magic of some sort! Could anyone explain or point me to the right docs please? Python looks for attributes in the instance first, and then in the class as a fallback. You only need to put them in the instance if you expect that you want a different value for every instance. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions: While And List Comprehension
On Thu, Nov 11, 2010 at 6:10 AM, Peter Otten __pete...@web.de wrote: James Mills wrote: On Thu, Nov 11, 2010 at 11:01 AM, alex23 wuwe...@gmail.com wrote: +1 on this approach. Clear and obvious and not reliant on any library modules other than sys. itertools, what WAS I thinking? :) maybe: import sys from itertools import islice print [v for v in islice((line for line in sys.stdin), 0, 5)] (line for line in sys.stdin) and sys.stdin are equivalent as are [v for v in items] and list(items) So print list(islice(sys.stdin, 5)) Peter -- http://mail.python.org/mailman/listinfo/python-list Hello Folks, You are great! Thanks for the suggestions! With the values between # #, I meant I would like to limit the values sys.stdin.readlines() read (but I think there is no way to do it); instead of reading the entire input, limit it to read only 5 entries. I knew about readline(), but when checking it with cProfile each readline() needs a function call and with readlines() it is only one. I think that depending on input, readline() calls may have a higher cost. Check below: My test file: TestFile.txt = 1 2 3 4 5 6 7 8 9 10 = My test code: simpleReadLines.py = import sys import cProfile def simpleTestLimitRLS(tLimit): sysStdinReadLines = sys.stdin.readlines allValues = [ int(v) for v in sysStdinReadLines() ] print allValues[:tLimit] def simpleTestLimitRL(tLimit): sysStdinReadLine = sys.stdin.readline print [ sysStdinReadLine() for x in xrange(0,5) ] if __name__ == '__main__': cProfile.run(simpleTestLimitRL(5)) cProfile.run(simpleTestLimitRLS(5)) = Test result: = type TestFile.txt | python simpleReadLines.py ['1\n', '2\n', '3\n', '4\n', '5\n'] 8 function calls in 0.004 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 10.0000.0000.0040.004 string:1(module) 10.0040.0040.0040.004 simpleReadLines.py:13(simpleTestLimitRL) 10.0000.0000.0000.000 {method 'disable' of '_lsprof.Profiler' objects} 50.0000.0000.0000.000 {method 'readline' of 'file' objects} [6, 7, 8, 9, 10] 4 function calls in 0.003 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 10.0000.0000.0030.003 string:1(module) 10.0030.0030.0030.003 simpleReadLines.py:8(simpleTestLimitRLS) 10.0000.0000.0000.000 {method 'disable' of '_lsprof.Profiler' objects} 10.0000.0000.0000.000 {method 'readlines' of 'file' objects} = If I change the execution order to: 1. simpleTestLimitRLS(5) 2. simpleTestLimitRL(5) Of course, python returns an error because all the input has been consumed by readlines(). Again, thanks for your attention and suggestions. Regards, Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions: While And List Comprehension
On Thu, Nov 11, 2010 at 6:10 PM, Peter Otten __pete...@web.de wrote: (line for line in sys.stdin) and sys.stdin are equivalent as are [v for v in items] and list(items) So print list(islice(sys.stdin, 5)) I was being a little verbose ... But I like your simplification :) cheers James -- -- James Mills -- -- Problems are solved by method -- http://mail.python.org/mailman/listinfo/python-list
Re: Enumeration of strings and export of the constants
On 11/11/2010 01:30 AM, Ian wrote: On Nov 10, 6:12 am, lnenovlne...@mm-sol.com wrote: Is there a better and more common way to do this? from itertools import count, izip class APINamespace(object): def __init__(self): self._named_values = [] def enumerate(self, names, start=0, step=1): self._named_values.extend(izip(names, count(start, step))) def import_to(self, destination): for name, number in self._named_values: setattr(destination, name, number) Note the step parameter of itertools.count requires Python 2.7 or 3.1. And can line 6 be replaced by something less evil. Yes, by putting the names to be imported into their own container as I've done above, instead of polluting the class dictionary with them. Thanks a lot. It was my initial idea to pull something like that but for some mysterious reason i failed miserably. Thanks again. ~Lyudmil Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Enumeration of strings and export of the constants
On 11/10/2010 11:19 PM, Emile van Sebille wrote: On 11/10/2010 5:12 AM lnenov said... Hi, I need to enumerate a couple hundred strings to constants and export them to another module(s) globals. Do they really need to be globals? Why not a constants in an object/container that would neither pollute the global namespace nor risk being shadowed by subsequent inadvertent name conflict? It is ment for testing purposes and would be used mainly in interactive mode. This would save some typing : ) ~Lyudmil -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast!
Hello, On Tue, Nov 09, 2010 at 09:32:17AM -0800, macm wrote: dict1 = {'ab':[[1,2,3,'d3','d4',5],12],'ac':[[1,3,'78a','79b'], 54],'ad': [[56,57,58,59],34], 'ax': [[56,57,58,59],34]} dict2 = {'ab':[[22,2,'a0','42s','c4','d3'],12],'ab':[[2,4,50,42,'c4'], 12],'ac':[[1,3,'79b',45,65,'er4'],54],'ae': [[56,57,58,59],34],'ax': [[9],34]} You have a problem here: key 'ab' is listed twice in dict2 and only its second value is then visible: [[2,4,50,42,'c4'], 12], so that I couldn't get the desired {'ac':[1,3,'79b'], 'ab':[2,'d3']} intersection. So, after I've found the problem, the desired functional-style code emerges: dict(filter(lambda t: t[1], ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])), ...filter(dict2.has_key, dict1.iterkeys())) ...) ... ) {'ac': [1, 3, '79b'], 'ab': [2, 'd3']} -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast!
On Thu, Nov 11, 2010 at 11:51:33AM +0200, Alexander Gattin wrote: functional-style code emerges: dict(filter(lambda t: t[1], ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], dict1[k][0])), ...filter(dict2.has_key, dict1.iterkeys())) ...) ... ) Sorry, the indentation for the above code is plain wrong. I'm not accustomed to lisp-indenting, and only have managed to produce the next version below: dict(filter(lambda t: t[1], ... map(lambda k: (k, filter(lambda v: v in dict2[k][0], ... dict1[k][0] ... ) ... ), ... filter(dict2.has_key, dict1.iterkeys()) ...) ...) ... ) {'ac': [1, 3, '79b'], 'ab': [2, 'd3']} -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple discontinued ranges
On Nov 10, 10:02 am, Mel mwil...@the-wire.com wrote: xoff wrote: I was wondering what the best method was in Python programming for 2 discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. Am I obliged to use 2 for loops defining the 2 ranges like this: for i in range (3,7): do bla for i in range (7,17): do bla or is there a more clever way to do this? One horribly clever way is to concoct a 9-th order polynomial to return 3,4,5,6,17,18,19,20,21,22 for input values 0,1,2,3,4,5,6,7,8,9. And one would want one with integer coefficients... truly horribly clever! A good example of complex is better than complicated... The reasonable way is to use two loops as you've done. If the pattern of discontinuous ranges is really important in your application, you'd perhaps want to package it up (not tested): def important_range (): for x in xrange (3, 7): yield x for x in xrange (17,23): yield x Reasonable; but DRY: don't repeat yourself. IMNSHO, better would be: ... def important_range (): ... for x in [xrange (3, 7), xrange (17,23)]: ... for y in x: ... yield y because face it, you're probably going to add to that list of ranges anyway, so you should anticipate it (and there's no cost if you don't end up adding to it). To extend that notion, I would imagine that itertools.chain is already basically defined as: ... def chain(*args): ... for x in args: ... for y in x: ... yield y so important_range() can then be simply defined as: ... def important_range: ... return chain(xrange (3, 7), xrange (17,23)) Cheers - Chas to be used elsewhere as for v in important_range(): # use v ... Mel. -- http://mail.python.org/mailman/listinfo/python-list
Open Multiples Files at same time with multiprocessing - How declare dynamically the var?
Hi Folks My approach to open multiples files at same time is: def openFiles(self,file,q): fp = open(file, 'rb') fp.seek(0) fcontent = fp.read() fp.close() q.put(fcontent) return def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) q = Queue() m = Process(target=self.openFiles, args=(x,q,)) m.start() d1.append(q.get()) # = This get is locking ? It is mean: wait m.start(), like m.join()?? print list(d1) return Is the best way? Is q.get() locking the loop? I feel that q.get() is locking so I would like to declare dynamically the var q{z} in python? is it possible? How? def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) q{z} = Queue() m{z} = Process(target=self.openFiles, args=(x,q{z},)) m{z}.start() for x in L: z=L.index(x) d1.append(q{z}.get()) # = So now I am sure that q{z}.get() isn't lock print list(d1) return I tried use list but didn't work look below one shot. Best Regards macm I tried : def testOpen(self): L = ['file1.txt','file2.txt', 'file3.txt','file4.txt', 'file5.txt'] d1 = [] q = [] m = [] for x in L: z=L.index(x) q.insert(z, Queue()) m.insert(z,Process(target=self.openFiles, args=(x,q[z]))) m[z].start() # Now I am sure. Isnt lock for x in L: z=L.index(x) d1.append(q[z].get()) print list(d1) return -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
r0g aioe@technicalbloke.com writes: Really? I get a metric butt-ton of spam every day to this address. I'm sure I get sent a lot of spam (though I don't know for sure -- see below). But I don't think much of it comes from Usenet harvesters any more. Right now it simply filtered by address straight into my recycle bin, I suppose if it ever becomes burdensome or starts to choke my bandwidth I'll tell my mailserver to bounce it :) Don't do that. Get your mailserver to /reject/ spam during SMTP with a 5xx code. Bouncing spam is really bad because it implicitly assumes that the envelope sender address is good. Spam rarely has a valid envelope sender. If you're lucky, the envelope sender is simply invalid, and you'll end up with a double-bounce when your mailserver finds out. If you're unlucky, the envelope sender is a /valid/ address from the spammer's list and some innocent victim will end up receiving your bounce (this is called `backscatter'). -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
strange problem with multiprocessing
Any idea what this could be about? Traceback (most recent call last): File run-tests-1004.py, line 48, in module results = pool.map (run_test, cases) File /usr/lib64/python2.7/multiprocessing/pool.py, line 199, in map return self.map_async(func, iterable, chunksize).get() File /usr/lib64/python2.7/multiprocessing/pool.py, line 491, in get raise self._value ValueError: cannot convert float NaN to integer -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial or Famous Applicattions.?
On Wed, 10 Nov 2010 16:58:06 -0800, alex23 wrote: Martin Gregorie mar...@address-in-sig.invalid wrote: Now, if ESR had fixed fetchmail [...] Did you try submitting patches? Nope. I'd already seen comments that bug reports etc. are ignored and tried getmail. Since that does the needful, why should I bother? -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
Re: strange problem with multiprocessing
Neal Becker ndbeck...@gmail.com wrote: Any idea what this could be about? Traceback (most recent call last): File run-tests-1004.py, line 48, in module results = pool.map (run_test, cases) File /usr/lib64/python2.7/multiprocessing/pool.py, line 199, in map return self.map_async(func, iterable, chunksize).get() File /usr/lib64/python2.7/multiprocessing/pool.py, line 491, in get raise self._value ValueError: cannot convert float NaN to integer The ValueError comes from run_test. It contains an int(x), where x == float('nan'). Does cases maybe contain a NaN? Ciao Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: A matter of queues, tasks and multiprocessing
On Nov 10, 9:19 pm, danmcle...@yahoo.com danmcle...@yahoo.com wrote: If you are using Python 2.6 or greater, look into the multiprocessing module. It may contain 90% of what you need. Thank you Dan, indeed the multi-processing module has been my first port of call and indeed it has all the basic ingredients. What I'm looking for is an higher-level architecture built on the multi- processing and the multi-threading modules. Thanks again! Manu -- http://mail.python.org/mailman/listinfo/python-list
Re: A matter of queues, tasks and multiprocessing
On 11/11/2010 14:04, Emanuele D'Arrigo wrote: On Nov 10, 9:19 pm, danmcle...@yahoo.comdanmcle...@yahoo.com wrote: If you are using Python 2.6 or greater, look into the multiprocessing module. It may contain 90% of what you need. Thank you Dan, indeed the multi-processing module has been my first port of call and indeed it has all the basic ingredients. What I'm looking for is an higher-level architecture built on the multi- processing and the multi-threading modules. Try Celery http://ask.github.com/celery/getting-started/introduction.html TJG -- http://mail.python.org/mailman/listinfo/python-list
is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
How do I skip over multiple words in a file?
Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words the, and, or, and but. What would be the general strategy for attacking a problem like this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Ways of accessing this mailing list?
On Nov 3, 9:27 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Grant Edwards inva...@invalid.invalid writes: On 2010-11-02, John Bond li...@asd-group.com wrote: My normal inbox is getting unmanageable, and I think I need to find a new way of following this and other lists. Point an NNTP client at new.gmane.org. Ditto, but the correct hostname is ‘news.gmane.org’. Hey. I'm was trying this, and got stuck for a while. I have found 'gmane.comp.python.devel', which looks great for lurking, along with many other entries under gmane.comp.python.*. But I couldn't find *this* list (comp.lang.python) for ages, despite scrutinising possible aliases. For anyone else in the same boat, you are looking for gmane.comp.python.general. Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I skip over multiple words in a file?
On 11/11/10 09:07, chad wrote: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words the, and, or, and but. What would be the general strategy for attacking a problem like this? I'd keep a file of stop words, read them into a set (normalizing case in the process). Then, as I skim over each word in my target file, check if the case-normalized version of the word is in your stop-words and skipping if it is. It might look something like this: def normalize_word(s): return s.strip().upper() stop_words = set( normalize_word(word) for word in file('stop_words.txt') ) for line in file('data.txt'): for word in line.split(): if normalize_word(word) in stop_words: continue process(word) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: udp sockets with python
On Nov 10, 9:23 pm, Tim Roberts t...@probo.com wrote: Mag Gam magaw...@gmail.com wrote: I am measuring the round trip time using tcpdump. The C version is giving me around 80 microseconds (average) and the python is giving me close to 300 microseconds (average). If you need the performance of a compiled language, then it's probably not appropriate to use an interpreter. Ridiculous. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looping through files in a directory
On Nov 10, 4:14 pm, James Mills prolo...@shortcircuit.net.au wrote: On Thu, Nov 11, 2010 at 8:46 AM, Matty Sarro msa...@gmail.com wrote: Short story - I have a few thousand files in a directory I need to parse through. Is there a simple way to loop through files? I'd like to avoid writing a python script that can parse 1 file, and have to call it a few thousand times from a bash script. Any input or pointers to functions that'd help would be very much appreciated. Thanks! os.walk or os.listdir cheers James -- -- James Mills -- -- Problems are solved by method I was able to do something similar like this... rootPath = 'T:/' pattern = '*.xml' for root, dirs, files in os.walk(rootPath): for filename in fnmatch.filter(files, pattern): full_path = (os.path.join(root, filename)) print(full_path) -- http://mail.python.org/mailman/listinfo/python-list
Re: Open Multiples Files at same time with multiprocessing - How declare dynamically the var?
On 11/11/2010 4:28 AM, macm wrote: def openFiles(self,file,q): fp = open(file, 'rb') fp.seek(0) The seek is unnecessary; the file will already be at position 0 after it is opened. def testOpen(self): L = ['file1.txt','file2.txt','file3.txt','file4.txt','file5.txt'] d1 = [] for x in L: z=L.index(x) for z, x in enumerate(L): q = Queue() m = Process(target=self.openFiles, args=(x,q,)) m.start() d1.append(q.get()) #= This get is locking ? It is mean: wait m.start(), like m.join()?? It can't get an item from the queue until an item has been put in the queue to get, so it waits for the process m to put something there. It does not do an implicit m.join() however. I tried use list but didn't work look below one shot. It didn't work is not very useful for helping you debug. Be specific. What were you expecting, and what did you get instead? If there was a traceback, copy and paste it. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Question on using urllib
Hello all, Sorry if this question is not 100% python related, it is also related to http or html ... Everything takes place in this page: http://www.infometeo.be/klanten/KYC/campage2mega.php With the following program, I can download the 2 small meteo images, without any problem: import urllib urllib.urlretrieve(http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN;, meteo1.jpg) urllib.urlretrieve(http://www.meteokust.be/metstatgr.php?s=zb;, meteo2.jpg) But I would like to download the main background picture. By looking inside the html page, it seems it's url is: http://www.infometeo.be/img.php?iid=1057 ... table bgcolor=#6699FF tr td table width=1280 height=960 background=http://www.infometeo.be/img.php?iid=1057; tr td align=right valign=bottom ... Warning, the iid may vary depending time ... I try to download it with python: urllib.urlretrieve(http://www.infometeo.be/img.php?iid=1057;, picture.jpg) But then I receive only 2 bytes: CR LF I think. If I use this url with my browser (firefox), I also get nothing (a blank page). If I go back to the main page with the firebug plugin activated, I can change the iid directly inside the html code with firebug, and then, even previous pictures can be displayed ... So I am a bit lost ... Any help would be very appreciate !! Thanks, Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyGUI 2.3
The problem is that some part of the application gets installed to /home/fetchinson/.local/lib/python2.6/site-packages/GUI and some other parts get installed to /home/fetchinson/.local/lib/python/site-packages/GUI Which parts get installed in which places, exactly? This gets installed to /home/fetchinson/.local/lib/python/GUI : Generic Gtk __init__.py __init__.pyc Version.py Version.pyc _where.py _where.pyc And this gets installed to /home/fetchinson/.local/lib/python2.6/site-packages/GUI : Resources I'm puzzled, because I can't see anything in the setup.py that could result in things getting split up like this. I'm wondering whether there is some breakage in distutils. I honestly have no idea :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on using urllib
Olivier Scalbert wrote: Sorry if this question is not 100% python related, it is also related to http or html ... Everything takes place in this page: http://www.infometeo.be/klanten/KYC/campage2mega.php With the following program, I can download the 2 small meteo images, without any problem: import urllib urllib.urlretrieve(http://www.infometeo.be/wwweather/currentimage.php?icao=EBFN;, meteo1.jpg) urllib.urlretrieve(http://www.meteokust.be/metstatgr.php?s=zb;, meteo2.jpg) But I would like to download the main background picture. By looking inside the html page, it seems it's url is: http://www.infometeo.be/img.php?iid=1057 I try to download it with python: urllib.urlretrieve(http://www.infometeo.be/img.php?iid=1057;, picture.jpg) The problem is indeed not Python-related. The provider of the images doesn't like what you're trying to do and verifies the referer, i. e. that the page you claim to be coming from is acceptable. Here's one way to satisfy that check: from urllib2 import Request, urlopen r = Request(http://www.infometeo.be/img.php?iid=1057;, headers=dict(Referer=http://www.infometeo.be/img.php?iid=1057;)) img = urlopen(r).read() with open(tmp.jpg, w) as f: f.write(img) ... Now if you are using that workaround a lot he may come up with more sophisticated techniques. So dont ;) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I The Only One Who Keeps Reading “Numpy” as “Numpty”?
On Nov 10, 5:35 pm, Arnaud Delobelle arno...@gmail.com wrote: So pypy is pie-pee, not pie-pie or pee-pee. With that edifying thought, I'm off to bed. :) Good catch! Actually i've always thought of pypi as pie-pie and Scipy as cy-pie. Num-pie does not work for me. Maybe some linguist could chime in and explain these odd tendencies...? -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 11-11-2010 19:01, Steve Holden wrote: On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. Steve I agree with you, but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) cheers, Stef regards Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on using urllib
On 11/11/2010 06:37 PM, Peter Otten wrote: The problem is indeed not Python-related. The provider of the images doesn't like what you're trying to do and verifies the referer, i. e. that the page you claim to be coming from is acceptable. Here's one way to satisfy that check: from urllib2 import Request, urlopen r = Request(http://www.infometeo.be/img.php?iid=1057;, headers=dict(Referer=http://www.infometeo.be/img.php?iid=1057;)) img = urlopen(r).read() with open(tmp.jpg, w) as f: f.write(img) ... Now if you are using that workaround a lot he may come up with more sophisticated techniques. So dont ;) Peter Thanks Peter, it works perfectly ! At 60 fps I can even make a video ... ;-) Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: Silly newbie question - Caret character (^)
(Note followups, this has stopped being very Pythony.) On 2010-11-11, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: Another function that should be deprecated is strncat???I myself was caught out misunderstanding it recently. What purpose does it serve? I'm wondering if you're thinking of strncpy(), which is the famously bogus one. strncat() just has a fencepost error -- given a limit N, it will write at most N+1 characters. strncpy(), however, pads with null bytes if the source string isn't long enough, and does not null terminate if there isn't room to. This behavior is nearly always undesireable. However, if you were building a filesystem in which file path names were given exactly sixteen bytes of space in the directory entry, and you didn't want to truncate them to 15 bytes, you might write precisely this behavior. So that's what we got. I don't know whether anyone's gotten buy-in from the standards people for strlcpy()/strlcat(), but I really hope so. Me, I just use snprintf with a %s format instead of str*cpy(). -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
os.tmpfile() vs. tempfile.TemporaryFile()
Is there any reason to prefer tempfile.TemporaryFile() over os.tmpfile()? Both create a nameless temporary file that will be deleted on close. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: os.tmpfile() vs. tempfile.TemporaryFile()
On Nov 11, 11:32 am, John Nagle na...@animats.com wrote: Is there any reason to prefer tempfile.TemporaryFile() over os.tmpfile()? Both create a nameless temporary file that will be deleted on close. John Nagle tempfile.TemporaryFile has more options, e.g. file prefix, suffix, dir location, mode, and buf size. if you don't care about any of that, then it probably makes no difference. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
From: Stef Mientki stef.mien...@gmail.com To: python-list@python.org Sent: Thu, November 11, 2010 10:20:03 AM Subject: Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? On 11-11-2010 19:01, Steve Holden wrote: On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. - Steve I agree with you, - but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) So, assuming you want the 'straight ahead' (i.e. no framework, like Django) your looking at vanilla CGI programming. form = cgi.FieldStorage() # parse query string, handles decoding and GET and POST print pname:, form[name].value http://docs.python.org/library/cgi.html Enjoy! :) David-- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 11-11-2010 19:36, david wright wrote: *From:* Stef Mientki stef.mien...@gmail.com *To:* python-list@python.org *Sent:* Thu, November 11, 2010 10:20:03 AM *Subject:* Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ? On 11-11-2010 19:01, Steve Holden wrote: On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. - Steve I agree with you, - but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) So, assuming you want the 'straight ahead' (i.e. no framework, like Django) your looking at vanilla CGI programming. form = cgi.FieldStorage() # parse query string, handles decoding and GET and POST print pname:, form[name].value http://docs.python.org/library/cgi.html thanks David, looks that was what I was looking for, I'll investigate all the properties of Fieldstorage. thanks, Stef Enjoy! :) David -- http://mail.python.org/mailman/listinfo/python-list
ANNOUNCE: NHI1-0.9, PLMK-1.7 und libmsgque-4.7
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dear User, ANNOUNCE:Major Feature Release libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, TCL, PERL, PHP, PYTHON, RUBY, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 LINKS = ChangeLog: http://nhi1.berlios.de/theLink/changelog.htm libmsgque including PHP documentation: http://nhi1.berlios.de/theLink/index.htm NHI1: http://nhi1.berlios.de/ DOWNLOAD: http://developer.berlios.de/projects/nhi1/ PHP man pages: reference: msgqueforphpref.n tutorial: msgqueforphptut.n SUMMARY === This version adds the ability to: * PHP language support. * a new interface of the ProcessEvent function and the startAs configuration option. * terminate an application from a callback with the ErrorSetEXIT function. The PHP language is characterized by an extensive but undocumented C API. The number of features combined with a growing and moving language made the extension programming difficult and lengthy. The successful PHP extension shows the flexibility and adaptability of NHI1. mfg Andreas Otto (aotto1968) -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJM3Ds6AAoJEGTcPijNG3/ATywH/iguN1+96sp2RGzIz6N3I8mx tw4YO6ac8NPT+Ztm+IXYbGlkyb2Z/3UwES7aZunYy7DK/kJBh7VBbZNGGWZlRTvm w02uMa4dTCBye8tNkQ8dRAxjshe9taM1+54Z4k1EsFmIXOMi8bbdDuAPk2i8xGRu vJIFC6ubIx93Sjgodcr/AIGRskjutpF29+uoaSMz+8UrTxnSoJxq8VvgWR/+MXfZ UOb8GutVV6bGI/ylE/NgLpxvE1LUMNgMS0QzHgQHSu4E/8tW3Oyzt6FU68k51n8+ OTJaFYC7o1W9VwSoc/HNHPhVmECYONW40pRrf2P0llqiKElBAd23g1/h83iblqo= =5U+w -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Class extension confusion :(
On 11/11/10 09:34, Peter Otten wrote: r0g wrote: Question B) The only reason I can think of so far is that I don't have a clear picture of how those names came to end up in that scope, it seems very convenient but I'm worried it's black magic of some sort! Could anyone explain or point me to the right docs please? Python looks for attributes in the instance first, and then in the class as a fallback. You only need to put them in the instance if you expect that you want a different value for every instance. Peter Thanks Peter, I think I understand now, I'll quickly explain my picture of things though so you or some other denizens of the mighty comp.lang.python can correct me if I'm wrong!... I can access the parameters I pass to __init__ within the classes' methods without using self. as these methods are run within the constructor itself and are therefore within it's local scope. That also explains why I had to call the constructor _after_ creating the new data attributes to have them be included. My initial belief that one has to call the parent constructor as the first action in the extended constructor is not technically valid, in most cases it can be called at any point but in situations like the above it can mess things up so I ought to put it at the end of my constructors for it to always work. Are there any drawbacks to calling it last or is that how it is supposed to work? The BaseHTTPRequestHandler seemed curiously constructed to me at first too but I think I can see why now... as it's a handler it's only ever meant to be a transient thing and it requires no external parameters (unless you're me!) as it's always called by HTTPServer which has all the info necessary so there's be no sense requiring users to create an instance then call a method to get the servers response, you may as well just bundle it all into one. Also as it might be called hundreds or thousands of times in quick succession it would be important to have it finish and get garbage collected. I also see that I ought to at least assign these extended params to data attributes and access them via self. like I would normally do as I can't guarantee that implementation of BaseHTTPREquestHandler will remain constant over time. If I understand correctly it may also be possible (and more efficient) to use setattr() to inject the parameters I want into the class as class attributes before use, rather than assigning them to data attributes every time I instantiate an new instance. Actually looking at the code from BaseRequestHandler it seems I may have overlooked the proper way of associating a callback function anyway. It looks like I should just define self.handle() in my subclass so that's one less parameter to worry about, although I think I may still need to use the factory function method you showed me to get the paths dictionary in there. Thanks so much for all your help, I really appreciate it and, assuming I'm not totally wrong about all of the above, I find it reassuring that I'm not going mad! Cheers, Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/10 11:28, Mark Wooding wrote: r0gaioe@technicalbloke.com writes: Really? I get a metric butt-ton of spam every day to this address. I'm sure I get sent a lot of spam (though I don't know for sure -- see below). But I don't think much of it comes from Usenet harvesters any more. Right now it simply filtered by address straight into my recycle bin, I suppose if it ever becomes burdensome or starts to choke my bandwidth I'll tell my mailserver to bounce it :) Don't do that. Get your mailserver to /reject/ spam during SMTP with a 5xx code. Bouncing spam is really bad because it implicitly assumes that the envelope sender address is good. Spam rarely has a valid envelope sender. If you're lucky, the envelope sender is simply invalid, and you'll end up with a double-bounce when your mailserver finds out. If you're unlucky, the envelope sender is a /valid/ address from the spammer's list and some innocent victim will end up receiving your bounce (this is called `backscatter'). -- [mdw] Whoops, I forgot 'bounce' has a clear meaning in the world email, I meant reject. Having suffered plenty of backscatter back in the day I wouldn't want to wish that on anyone. Thankfully I haven't had any of that in a few years now. I guess a lot more people are using Domainkeys and SPF these days. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
In message mailman.853.1289449099.2218.python-l...@python.org, Jon Dufresne wrote: On Wed, Nov 10, 2010 at 1:50 AM, Lawrence D'Oliveiro wrote: In message mailman.780.1289326087.2218.python-l...@python.org, Jon Dufresne wrote: On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judgement, for which I expect an apology. Otherwise, it becomes grounds for an abuse complaint to your ISP. Is this for real? I did a replay all to respond to your post. What are you suggesting? I don't see anything that looks like an obfuscated email. Tell me what you see here, for example http://mail.python.org/pipermail/python-list/2010-November/1260153.html. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 11/11/10 14:22, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki PHP only tends to be run one way, the mod_php Apache module. There's several ways run python in conjunction with a webserver like apache: mod_wsgi, mod_python, CGI and FastCGI. I've never really looked into this way of doing things but I guess the details are going to vary depending on which one you use. It's also not uncommon for python to actually BE the webserver too, there's lots of webserver modules for python, cherrypy is fairly simple and well regarded. Often you can proxy these through Apache to get the benefits of both although again, that's not an approach I've used so I can't really advise you further. Roger. -- http://mail.python.org/mailman/listinfo/python-list
please subscribe me to the list
Thanks! Ryszard -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I skip over multiple words in a file?
On 11/11/10 15:07, chad wrote: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words the, and, or, and but. What would be the general strategy for attacking a problem like this? If your files are not too big I'd simply read them into a string and do a string replace for each word you want to skip. If you want case insensitivity use re.replace() instead of the default string.replace() method. Neither are elegant or all that efficient but both are very easy. If your use case requires something high performance then best keep looking :) Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: udp sockets with python
On 11/11/10 16:03, Jean-Paul Calderone wrote: On Nov 10, 9:23 pm, Tim Robertst...@probo.com wrote: Mag Gammagaw...@gmail.com wrote: I am measuring the round trip time using tcpdump. The C version is giving me around 80 microseconds (average) and the python is giving me close to 300 microseconds (average). If you need the performance of a compiled language, then it's probably not appropriate to use an interpreter. Ridiculous. Terse! -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 2010-11-11 11:20, Stef Mientki wrote: On 11-11-2010 19:01, Steve Holden wrote: On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. Steve I agree with you, but replacing a number of 3 to 10 lines of code scripts won't create a mess ;-) cheers, Stef regards Steve If there is no automated process to do the translation, then it should be avoided. It is an opportunity for chaos to ensue. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 11/11/10 18:01, Steve Holden wrote: On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. regards Steve Come on Steve, I thought your role is to encourage / cheerlead here ;D While you're absolutely right when it comes to complex apps and sites I get the impression he's only talking about your common or garden short admin scripts. I might be wrong though. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: please subscribe me to the list
On 11/11/2010 20:08, Ryszard Czermiński wrote: Thanks! Ryszard What don't you do it yourself? Go to: http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Copy Protected PDFs and PIL
I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? Brett Bowman Bioinformatics Associate Cibus LLC -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
In message mailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I skip over multiple words in a file?
On 2010-11-11 08:07, chad wrote: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words the, and, or, and but. What would be the general strategy for attacking a problem like this? I realize that you may need or want to do this in Python. This would be trivial in an awk script. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/10 13:49, Lawrence D'Oliveiro wrote: Is this for real? I did a replay all to respond to your post. What are you suggesting? I don't see anything that looks like an obfuscated email. Tell me what you see here, for example http://mail.python.org/pipermail/python-list/2010-November/1260153.html. How about we look at an excerpt of the message you just sent: === From: Lawrence D'Oliveiro l...@geek-central.gen.nz Newsgroups: gmane.comp.python.general Subject: Re: How to test if a module exists? Date: Fri, 12 Nov 2010 08:49:18 +1300 [snip] On Mon, Nov 8, 2010 at 11:35 PM, Lawrence D'Oliveiro ... I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judgement, for which I expect anapology. Otherwise, it becomes grounds for an abuse complaint to your ISP. Gee...your unobfuscated email addresses FROM YOU. How about you apologize for blaming your own sins on others and then demanding THEIR apologies? When your own incompetence is at fault, demanding an apology just makes you look like an even bigger fool. And using a pre-authored email just amplifies your numskullery. And besides, your addle-pated folly has now exposed your email address to the big bad intarwebs. Once exposed, it doesn't really matter if anybody else exposes it because you yourself are to blame for letting the horse out of the barn. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
On 11/11/2010 3:23 PM, r0g wrote: On 11/11/10 18:01, Steve Holden wrote: On 11/11/2010 9:22 AM, Stef Mientki wrote: hello, finally got Python running at my server. Now I would like to replace the PHP server scripts with Python ( for easier maintenance). But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? Google finds lots of links, but I can't find the answer. thanks, Stef Mientki Stef: Moving from one language to anther is not just a matter of transliterating the code. Of you try that you will end up with a messy code base that looks like PHP written in Python. regards Steve Come on Steve, I thought your role is to encourage / cheerlead here ;D While you're absolutely right when it comes to complex apps and sites I get the impression he's only talking about your common or garden short admin scripts. I might be wrong though. Roger I'm quite happy to encourage, but I do find it necessary to interject a warning from time to time. I was pretty sure someone with PHP knowledge would come to the rescue. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I skip over multiple words in a file?
chad cdal...@gmail.com writes: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words the, and, or, and but. What would be the general strategy for attacking a problem like this? Something like (untested): stopwords = set (('and', 'or', 'but')) def goodwords(): for line in file: for w in line.split(): if w.lower() not in stopwords: yield w Removing punctuation is left as an exercise. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy Protected PDFs and PIL
On Nov 11, 2010, at 3:28 PM, Brett Bowman wrote: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? What operating system? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
Lawrence D'Oliveiro wrote: In message mailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? I'm using Thunderbird, and the headers, which I see very plainly while reading postings, says : Lawrence D'Oliveiro l...@geek-central.gen.nz. That's what I see. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/2010 3:26 PM, Lawrence D'Oliveiro wrote: In message mailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? I still await some insight (which, of course, you are under no obligation to provide) about just why you perceive these innocent mistakes to be great wrongs that need righting. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy Protected PDFs and PIL
On 11/11/2010 20:28, Brett Bowman wrote: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? You could try it in a worker thread; it might kill only the worker. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy Protected PDFs and PIL
On 11/11/2010 3:28 PM, Brett Bowman wrote: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? Well, you might consider letting us know whether the program gives a traceback or whether it's a PIL crash, for a start. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/10 20:26, Lawrence D'Oliveiro wrote: In messagemailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? Lawrence, this is getting old fast, just suck it up and move along. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On Nov 11, 1:26 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message mailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? Soifyou claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? I also see the unobfuscated email address when reading your messages from python-list. The only place I see the obfuscated .new_zealand email address is when I click View profile in Google Groups -- but in that case the address is already truncated, so it hardly matters. -- http://mail.python.org/mailman/listinfo/python-list
returning results from function
Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the returned loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the return command to just return the values to me in the main script so I can work with them! Any help is appreciated. Thanks in advance, Neil _ Mac OS X 10.6.4 Python 2.6 _ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc local = pytz.timezone(US/Pacific) utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ #print utc_dt.strftime(fmt), = , loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
I'm using thunderbird via gmane and see the sender shown as l...@geek-central.gen.nz -- so, no lies -- you've been self-outed. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Class extension confusion :(
On 11/11/10 19:34, r0g wrote: On 11/11/10 09:34, Peter Otten wrote: r0g wrote: If I understand correctly it may also be possible (and more efficient) to use setattr() to inject the parameters I want into the class as class attributes before use, rather than assigning them to data attributes every time I instantiate an new instance. Ah, it's even simpler than that, turns out I've been significantly overcomplicating things, I can just set the class attributes by calling classname.attributename = whatever once at the start of my script. The one thing I might need to change as the server runs is the paths dictionary but dicts are mutable so that's no problem and I don't need to inject any data into the instances at all. I'm guessing I can subclass that easily now too - happy days! Well, far from wasted time it's been a very educational diversion, cheers :) Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/2010 20:26, Lawrence D'Oliveiro wrote: In messagemailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? Lawrence, I receive posts from this list via email and I can tell you that the post referred to above arrived in my inbox with an unobfuscated email address, so what both you and I see in that webpage is not necessarily the same as what arrives by email. Looking back I can tell you that your post (give or take an hour for DST) at 3 Nov 2010 07:52 Re: functions, list, default parameters was the last to arrive with an obfuscated address; the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy Protected PDFs and PIL
On 11/11/2010 12:28 PM Brett Bowman said... I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? try / except around the relevant code? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy Protected PDFs and PIL
Windows currently, though I also have a Linux box running Ubuntu if need be. On Thu, Nov 11, 2010 at 12:28 PM, Brett Bowman bnbow...@gmail.com wrote: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? Brett Bowman Bioinformatics Associate Cibus LLC -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I skip over multiple words in a file?
Am 11.11.2010 21:33, schrieb Paul Watson: On 2010-11-11 08:07, chad wrote: Let's say that I have an article. What I want to do is read in this file and have the program skip over ever instance of the words the, and, or, and but. What would be the general strategy for attacking a problem like this? I realize that you may need or want to do this in Python. This would be trivial in an awk script. There are several ways to do this. skip = ('and','or','but') all=[] [[all.append(w) for w in l.split() if w not in skip] for l in open('some.txt').readlines()] print all If some.txt contains your original question, it returns this: [Let's, 'say', 'that', 'I', 'have', 'an', 'article.', 'What', 'I', 'want', 'to ', 'do', 'is', 'read', 'in', 'this', 'file', 'have', 'the', 'program', 'skip', ' over', 'ever', 'instance', 'of', 'the', 'words', 'the,', 'and,', 'or,', ' but.', 'What', 'would', 'be', 'the', 'general', 'strategy', 'for', 'attacking', 'a', 'problem', 'like', 'this?'] But this _one_ way to get there. Faster solutions could be based on a regex: import re skip = ('and','or','but') all = re.compile('(\w+)') print [w for w in all.findall(open('some.txt').read()) if w not in skip] this gives this result (you loose some punctuation etc): ['Let', 's', 'say', 'that', 'I', 'have', 'an', 'article', 'What', 'I', 'want', ' to', 'do', 'is', 'read', 'in', 'this', 'file', 'have', 'the', 'program', 'skip', 'over', 'ever', 'instance', 'of', 'the', 'words', 'the', 'What', 'would', 'be', 'the', 'general', 'strategy', 'for', 'attacking', 'a', 'problem', 'like', 'this '] But there are some many ways to do it ... attachment: stefan_sonnenberg.vcf-- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
Lawrence D'Oliveiro l...@geek-central.gen.nz wrote: In message mailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? No, I would not -- it is not what I use, and it is not what I see. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
In message mailman.894.1289510633.2218.python-l...@python.org, MRAB wrote: ... the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. You mean from this one on http://mail.python.org/pipermail/python-list/2010-November/1259515.html? -- http://mail.python.org/mailman/listinfo/python-list
Re: returning results from function
On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg nb...@atmos.ucla.edu wrote: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the returned loc_y/m/d/h values, but no output is visibly seen when I run the main script. Does the main script print() the returned values? Python doesn't output stuff unless you explicitly ask it to (except when you're using the REPL). Show us your main script, or at least the part of it where utc_to_local() is called. I want the return command to just return the values to me in the main script so I can work with them! It already does that. The problem must lie with the caller (i.e. the main script). Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 2:59 PM, Lawrence D'Oliveiro wrote: In messagemailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? On the link you specify, your email address has the word 'at' in it. I subscribe to this list by email, in digest form. And your email address here has a real @ in it. Don't be so free to call people liars when they're reporting what they actually see. If you get this message directly, you can look at the TO: list. I just did a reply-all without editing anything. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: returning results from function
Am 11.11.2010 22:16, schrieb Neil Berg: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the returned loc_y/m/d/h values, but no output is visibly seen when I run the main script. I want the return command to just return the values to me in the main script so I can work with them! Any help is appreciated. Thanks in advance, Neil _ Mac OS X 10.6.4 Python 2.6 _ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc local = pytz.timezone(US/Pacific) utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(local) # local date YY-MM-DD HR TZ #print utc_dt.strftime(fmt), = , loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h Could you please be so nice and share the relevant parts of your main script with us ? attachment: stefan_sonnenberg.vcf-- http://mail.python.org/mailman/listinfo/python-list
Torrent VFS for Midnight Commander
Torrent Virtual FileSystem for Midnight Commander WHAT IS IT View files, directories and meta information from a torrent metafile in Midnight Commander. WHAT'S NEW in version 1.0.0 (2010-11-11) Initial release. WHERE TO GET Master site: http://phd.pp.ru/Software/mc/ Mirrors: http://phd.by.ru/Software/mc/ http://phd.webhost.ru/Software/mc/ AUTHOR Oleg Broytman p...@phd.pp.ru COPYRIGHT Copyright (C) 2010 PhiloSoft Design LICENSE GPL Oleg. -- Oleg Broytmanhttp://phd.pp.ru/p...@phd.pp.ru Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I The Only One Who Keeps Reading “Numpy” as “Numpty”?
On 10/11/2010 06:53, Lawrence D'Oliveiro wrote: Sorry... I read it as numpty all the time! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
Dave Angel wrote: On 2:59 PM, Lawrence D'Oliveiro wrote: In messagemailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? On the link you specify, your email address has the word 'at' in it. I subscribe to this list by email, in digest form. And your email address here has a real @ in it. Don't be so free to call people liars when they're reporting what they actually see. If you get this message directly, you can look at the TO: list. I just did a reply-all without editing anything. DaveA Interesting -- Lawrence's email address is showing the .new_zealand in your To headers, and that's what came up just now when I replied to all; but when I reply to something directly from Lawrence, it has the .nz instead. ~Ethan~ -- For those interested, I'm using Thunderbird on Windows boxen. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/2010 21:53, Lawrence D'Oliveiro wrote: In messagemailman.894.1289510633.2218.python-l...@python.org, MRAB wrote: ... the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. You mean from this one on http://mail.python.org/pipermail/python-list/2010-November/1259515.html? Yes. -- http://mail.python.org/mailman/listinfo/python-list
Re: returning results from function
My main script reads in monthly netCDF files that record variables each hour for that month. The length of all time variables is equal to the number of hours per month. Using January 1995, for example, time_y is a 1d array of the integer 1995 repeated 744 times, time_m is a 1d array of the integer 1 repeated 744 times, time_d is a 1d array that ranges from 1 to 31, and time_h is a 1d array that cycles from 0 23. The part that calls upon utc_to_local() is: time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] time_d = ncfile.variables['time_d'][:] # (time,int) [days] time_h = ncfile.variables['time_h'][:]# (time,float) [hrs] ntim =len(time_h) for tim_idx in range(0,ntim): local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) ***Here is where I'd like to see the returned values so I can create new arrays that store them * Hope this makes sense. Thanks, Neil On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg nb...@atmos.ucla.edu wrote: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the returned loc_y/m/d/h values, but no output is visibly seen when I run the main script. Does the main script print() the returned values? Python doesn't output stuff unless you explicitly ask it to (except when you're using the REPL). Show us your main script, or at least the part of it where utc_to_local() is called. I want the return command to just return the values to me in the main script so I can work with them! It already does that. The problem must lie with the caller (i.e. the main script). Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/2010 2:01 PM Dave Angel said... I subscribe to this list by email, in digest form. And your email address here has a real @ in it. Don't be so free to call people liars when they're reporting what they actually see. If you get this message directly, you can look at the TO: list. I just did a reply-all without editing anything. Which I see on my end now as copying to: l...@geek-central.gen.new_zealand so it didn't go directly as it happens... Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/2010 1:53 PM, Lawrence D'Oliveiro wrote: In message mailman.894.1289510633.2218.python-l...@python.org, MRAB wrote: ... the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. You mean from this one on http://mail.python.org/pipermail/python-list/2010-November/1259515.html? Here's a screen capture from Thunderbird. Anything else you need? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ attachment: doliviero.png-- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes: In message mailman.894.1289510633.2218.python-l...@python.org, MRAB wrote: ... the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. You mean from this one on http://mail.python.org/pipermail/python-list/2010-November/1259515.html? No. More like http://article.gmane.org/gmane.comp.python.general/677953 We'll accept your apologies now. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: returning results from function
On Nov 11, 2010, at 1:54 PM, Chris Rebert wrote: On Thu, Nov 11, 2010 at 1:16 PM, Neil Berg nb...@atmos.ucla.edu wrote: Hi Python community, In a main script, I pass the year (yr), month (mo), day (dy) and hour(hr) into the utc_to_local function (pasted below) which converts that date and time into local standard time. I am passing several dates and times into this function and would like to work with the returned loc_y/m/d/h values, but no output is visibly seen when I run the main script. Does the main script print() the returned values? Python doesn't output stuff unless you explicitly ask it to (except when you're using the REPL). Show us your main script, or at least the part of it where utc_to_local() is called. I want the return command to just return the values to me in the main script so I can work with them! It already does that. The problem must lie with the caller (i.e. the main script). On Thu, Nov 11, 2010 at 2:57 PM, Neil Berg nb...@atmos.ucla.edu wrote: My main script reads in monthly netCDF files that record variables each hour for that month. The length of all time variables is equal to the number of hours per month. Using January 1995, for example, time_y is a 1d array of the integer 1995 repeated 744 times, time_m is a 1d array of the integer 1 repeated 744 times, time_d is a 1d array that ranges from 1 to 31, and time_h is a 1d array that cycles from 0 23. The part that calls upon utc_to_local() is: time_y = ncfile.variables['time_y'][:] # (time,int) [yrs] time_m = ncfile.variables['time_m'][:] # (time,int) [mnths] time_d = ncfile.variables['time_d'][:] # (time,int) [days] time_h = ncfile.variables['time_h'][:] # (time,float) [hrs] ntim =len(time_h) for tim_idx in range(0,ntim): local_date = utc_to_local(time_y[tim_idx],time_m[tim_idx],time_d[tim_idx],int(time_h[tim_idx])) ***Here is where I'd like to see the returned values so I can create new arrays that store them * Add: print(local_date) Or if you want to be fancy: print(%.4d-%.2d-%.2d %.2d % local_date) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 2010-11-11 14:26 , Lawrence D'Oliveiro wrote: In messagemailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? You would agree that it shows my e- mail address as obfuscated, would you not? So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? This is what I see, reading from GMane using Thunderbird: http://imgur.com/Dg1Xr Face it: your post gets passed through a variety of systems outside of your control or the other readers here. Somewhere along the line, your email address is getting unobfuscated. The people replying are simply replying with what their email/NNTP clients show them. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy Protected PDFs and PIL
On 2010-11-11 14:28 , Brett Bowman wrote: I'm trying to parse some basic details and a thumbnail from ~12,000 PDFs for my company, but a few hundred of them are copy protected. To make matters worse, I can't seem to trap the error it causes: whenever it happens PIL throws a FATAL PDF disallows copying message and dies. An automated way to snap a picture of the PDFs would be ideal, but I'd settle for a way to skip over them without crashing my program. Any tips? I don't think PIL reads PDF files at all. Are you sure that the error comes from PIL and not some other piece of software? I would be very surprised if PIL simply crashed with such an error message. That is not a situation where a well-behaved Python library like PIL would abort without a catchable traceback. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 2010-11-11, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message mailman.843.1289438674.2218.python-l...@python.org, Tim Chase wrote: Amusingly, as others have noted, you replied with an unobfuscated email address. This http://mail.python.org/pipermail/python-list/2010-November/1260153.html would seem to be an independent, true record of what members of python-list would see of my posting, would it not? It might or might not be. Not all of us are members of python-list. I'm reading this on Usenet. (Where the only distinction I see is that the country name is spelled out.) You would agree that it shows my e- mail address as obfuscated, would you not? I don't know whether that counts as obfuscated. So if you claim to be seeing an unobfuscated e-mail address for my posting on python-list, you would be lying, would you not? I have found that, in general, the chances that someone is lying are very low. The chances are much higher that they are mistaken, or that I have misunderstood their claim. Or for that matter, that there's Something Strange Going On. Say, someone's got a Usenet provider that Helpfully Fixes things, or someone set up an aliasing thing in a Very Clever newsreader some time back so they could reply to your posts and didn't notice it was then performing the same aliasing when displaying the group, or... Usually, with people who aren't obvious frothing kooks, I tend to view lying as being an extremely unusual explanation. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 2010-11-11, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message mailman.894.1289510633.2218.python-l...@python.org, MRAB wrote: ... the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. You mean from this one on http://mail.python.org/pipermail/python-list/2010-November/1259515.html? Just as a data point: I'm using comp.lang.python via NNTP from Megabitz, reader is SLRN, and I still see .gen.new_zealand. Sounds to me like some source may be helpfully fixing the address as it forwards things. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 2010-11-11, Tim Chase python.l...@tim.thechases.com wrote: === From: Lawrence D'Oliveiro unobfuscated Newsgroups: gmane.comp.python.general Oh, interesting. Gee...your unobfuscated email addresses FROM YOU. No, from gmane. Out here in comp.lang.python (no gmane), it's obfuscated. So it sounds like there is an entity other than Lawrence deobfuscating the addresses, but it's not a specific poster here. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/10 21:53, Lawrence D'Oliveiro wrote: In messagemailman.894.1289510633.2218.python-l...@python.org, MRAB wrote: ... the next one at 3 Nov 2010 22:40 Re: Allowing comments after the line continuation backslash and _all_ the subsequent ones arrived with an _unobfuscated_ email address. You mean from this one on http://mail.python.org/pipermail/python-list/2010-November/1259515.html? Lawrence if you keep this up it won't be long til somebody writes a script to spam your precious bloody email address across every damn message board on the internet. All you are doing now is drawing further attention to it and causing it to be reposted over and over again, it's not a secret, you're being obnoxious and you deserve every shred of spam you get as a result. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: parse date/time from a log entry with only strftime (and no regexen)
This was a long time ago But just in case anyone googling ever has the same question, this is what I did (last year). The user just needs to supply a strftime formatted string, such as %A, %e %b %h:%M and this Class figures out the regex to use on the log entries... class RegexBuilder(object): This class is used to create the regex from the strftime string. So, we pass it a strftime string and it returns a regex with capture groups. lookup_table = { '%a' : r(\w{3}),# locale's abbrev day name '%A' : r(\w{6,8}), # locale's full day name '%b' : r(\w{3}),# abbrev month name '%B' : r(\w{4,9}), # full month name '%d' : r(3[0-1]|[1-2]\d|0[1-9]|[1-9]|[1-9]), # day of month '%e' : r([1-9]|[1-3][0-9]), # day of month, no leader '%H' : r(2[0-3]|[0-1]\d|\d), # Hour (24h clock) '%I' : r(1[0-2]|0[1-9]|[1-9]), # Hour (12h clock) '%j' : r(36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]\ |[1-9]\d|0[1-9]|[1-9]), # Day of year '%m' : r(1[0-2]|0[1-9]|[1-9]), # Month as decimal '%M' : r([0-5]\d|\d), # Minute '%S' : r(6[0-1]|[0-5]\d|\d), # Second '%U' : r(5[0-3]|[0-4]\d|\d), # Week of year (Sun = 0) '%w' : r([0-6]), # Weekday (Sun = 0) '%W' : r(5[0-3]|[0-5]\d|\d), # Week of year (Mon = 0) '%y' : r(\d{2}), # Year (no century) '%Y' : r(\d{4}), # Year with 4 digits '%p' : r(AM|PM), '%P' : r(am|pm), '%f' : r(\d+), # TODO: microseconds. Only in Py 2.6+ } # Format of the keys in the table above strftime_re = r'%\w' def __init__(self, date_format): r = re.compile(RegexBuilder.strftime_re) self.created_re = r.sub(self._lookup, date_format) def _lookup(self, match): Regex lookup... return RegexBuilder.lookup_table[match.group()] 2009/2/3 andrew cooke and...@acooke.org ValueError: unconverted data remains: this is the remainder of the log line that I do not care about you could catch the ValueError and split at the ':' in the .args attribute to find the extra data. you could then find the extra data in the original string, use the index to remove it, and re-parse the time. ugly, but should work. andrew -- http://mail.python.org/mailman/listinfo/python-list -- Simon Mullis _ si...@mullis.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
I have just received an admission from Barry Warsaw that a hack was done on python-list specifically to deal with bounces caused by a list member trying to reply to my obfuscated e-mail address. I have asked him to undo that hack. If he likes, he can filter out that (obfuscated) address of mine completely, I don’t mind, since I can always read replies to my postings here on USENET. The important point, as far as I’m concerned, is that I do NOT want to see my unobfuscated address appear on USENET. As for those who persisted in posting my address after being warned of this, I’m still deciding what to do. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
Lawrence D'Oliveiro wrote: The important point, as far as I’m concerned, is that I do NOT want to see my unobfuscated address appear on USENET. You sure did a lousy job of obfuscating for someone so concerned about it. As for those who persisted in posting my address after being warned of this, I’m still deciding what to do. You can be such an ass sometimes. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 2010-11-12, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: As for those who persisted in posting my address after being warned of this, I'm still deciding what to do. Plonk. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a module exists?
On 11/11/2010 4:55 PM, Grant Edwards wrote: On 2010-11-12, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: As for those who persisted in posting my address after being warned of this, I'm still deciding what to do. Plonk. Don't you mean On 2010-11-12, Lawrence D'Oliveiro l...@geek-central.gen.nz wrote: ? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
neglecting daylight savings
Hi Python community, I am trying to convert UTC to PST and want to neglect daylight savings even for the days that are in PDT, not PST. I simply want every UTC date to be pushed back by 8 hours and not worry about the days when the difference is really -7 due to daylight savings. I have written a function called utc_to_local (pasted below) that reads in the UTC year, month, day, and hour from a main code and returns that value in local standard time. The problem is that I can't figure out how to turn off the automatic daylight savings switch that appears be built in to somewhere. Here is some sample output showing the daylight savings switch on April 2, 1995 at 2am local time, which I would like to override. 1995-04-02 08 UTC = 1995-04-02 00 PST 1995-04-02 09 UTC = 1995-04-02 01 PST 1995-04-02 10 UTC = 1995-04-02 03 PDT 1995-04-02 11 UTC = 1995-04-02 04 PDT I want the third line of the output to read 1995-04-02 02 PST, the fourth to read 1995-04-02 03, etc. ___ from datetime import datetime from pytz import timezone import pytz def utc_to_local(yr,mo,dy,hr): fmt = '%Y-%m-%d %H %Z' utc = pytz.utc pacific = pytz.timezone(America/Los_Angeles) utc_dt = datetime(yr,mo,dy,hr, tzinfo=utc) loc_dt = utc_dt.astimezone(pacific) # local date YY-MM-DD HR TZ print utc_dt.strftime(fmt), =, loc_dt.strftime(fmt) loc_y = loc_dt.year # local year loc_m = loc_dt.month # local month loc_d = loc_dt.day # local day loc_h = loc_dt.hour # local hour return loc_y, loc_m, loc_d, loc_h _ Python 2.6 Mac OS X 10.6.4 _ Any help is much appreciated. Thank you in advance, Neil Berg -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an Python equivalent for the PHP super globals like $_POST, $_COOKIE ?
In article ibhi4h$ev...@speranza.aioe.org, r0g aioe@technicalbloke.com wrote: On 11/11/10 14:22, Stef Mientki wrote: I can't find how th get to PHP's equivalent of $_Post and $_Cookie ? PHP is mostly a one-trick pony. It's meant to be run as a web scripting language with Apache (or, I suppose, something else) on the front end. As a result, a lot of web-specific things like $_Post and $_Cookie are built into the language. Python is intended to be more general purpose, so things which are built in to other languages usually can be found in library modules. In this case, you probably want to look at the SimpleHTTPServer module. You may also want to look at any of several web application frameworks such as Django, Pylons, etc. I'm guessing these are overkill for the sorts of things you want to do, but they're worth at least browsing to get some idea of what's out there. For what it's worth, I've pretty much avoided PHP for all these years. My latest gig, however, has had me doing PHP for the past 3 months or so. The more I learn about PHP, the more I want to go running in the other direction. -- http://mail.python.org/mailman/listinfo/python-list