ANN: PiCloud cloud library 1.8 release
PiCloud, a cloud-computing platform for the Python Programming Language, has released version 1.8 of its client library, cloud. PiCloud enables Python users to leverage the power of an on-demand, high performance, and auto scaling compute cluster with as few as three lines of code! No server management necessary. You can find out more here: http://www.picloud.com What's New: * The client library is now open source with an LGPL license. * Users can choose to run their code across 2.5ghz nodes or 1ghz nodes with a simple kwarg. * Users can now select to run their code in real-time, guaranteeing that their processes start in under a second. * Drop-in replacement for multiprocessing. * Improved cluster workload distribution performance by 20%. * Improved efficiency of Python interpreter state extraction by the client library. * Optimized for all Python packages in the Enthought Python Distribution. * Bug fixes. * And much more! Full service description: PiCloud is a cloud-computing platform that integrates into the Python Programming Language. It enables you to leverage the compute power of Amazon Web Services without having to manage, maintain, or configure virtual servers. PiCloud integrates seamlessly into your existing code base through a custom Python library, cloud. To offload the execution of a function to the cloud, all you must do is pass your desired function into the cloud library. PiCloud will then run the function on its high-performance and automatically-scaling cluster. We quickly scale our server capacity to meet your computational needs, and only charge you for the resources you actually consume. Getting on the cloud has never been this easy! PiCloud improves the full cycle of software development and deployment. Functions that are run on PiCloud have their resource usage monitored, performance analyzed, and errors traced; we further aggregate all your functions to give you a bird's eye view of your service. Through these introspective capabilities, PiCloud enables you to develop faster, easier, and smarter. Common use cases for our platform: * Crawling the web * Manipulating images and videos * Generating charts and graphs * Statistical analysis of data sets * Real-time data processing Cheers, Ken Elkabany PiCloud, Inc. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Few questions on SOAP
On Feb 19, 8:49 am, Steve Holden st...@holdenweb.com wrote: Brendon Wickham wrote: On 19 February 2010 08:07, Mark Lawrence breamore...@yahoo.co.uk wrote: Muhammad Alkarouri wrote: Your question is borderline if not out of topic in this group. I will make a few comments though. This might be a Python group, but threads often drift way off topic, which added to the language itself make this a great group to read. If you don't like the way a thread goes, you can always skip it. Perhaps...but he answered the question very well and with great, IMO, patience. +1 -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ Dear Group, Thank you for taking your time to discuss the issue, esp. to Mohammad for his great patience and solving each aspect in a great way. That's I frequent this group and I just learn lot. If it is bit diverted topic,sorry. Wishing you Happy Day Ahead, Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
Ben Finney ben+pyt...@benfinney.id.au writes: Arnaud Delobelle arno...@googlemail.com writes: What about foo = iter('') That doesn't return a generator. foo = iter('') foo listiterator object at 0xf7cd3ed0 Whether the OP needs to create a generator, or just any iterable type, isn't clear. If it walks and quacks like a duck... Anyway it's not just an iterable object, it's an iterator. I can't really imagine that there would be some code which would be happy with generators but not with iterators (as long as you can't send anything to them, which is always the case with an empty generator). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Submit HTTP GET data from XP PC to PHP on web server.
Hello everyone I haeve tried to understand the capabilities of python in web development. Have gone throuhg forums and online tutorials. Nevertheless I am not able to find any topic which can give me some insite along with basic examples of how to send http get data from an xp mashine using python code to php on web server. I have some parameters to collect from windows mashine via http get and collect them on web server using php. Any hint how to begin would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
Arnaud Delobelle arno...@googlemail.com writes: Ben Finney ben+pyt...@benfinney.id.au writes: Whether the OP needs to create a generator, or just any iterable type, isn't clear. If it walks and quacks like a duck... Anyway it's not just an iterable object, it's an iterator. I can't really imagine that there would be some code which would be happy with generators but not with iterators (as long as you can't send anything to them, which is always the case with an empty generator). I can't imagine that someone would want to create a generator that's always empty, but has some side-effect that is the *real* purpose for using the generator. Clearly, none of us should let our limited imaginations be the guide to what people actually want to do. -- \ “Generally speaking, the errors in religion are dangerous; | `\those in philosophy only ridiculous.” —David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this doesn't work?
mk a écrit : (snip) Sorry, no time to get into details now - but I can at least provide a couple hints. The first point is that, to override a method on an _instance_, you have to provide a method object, not a plain function - remember that the descriptor protocol is only invoked on _class_ attributes, not on instance attributes. class Foo(object): def bar(self): print the original bar def mybar(self): print mybar f = Foo() f.bar = mybar f.bar() Traceback (most recent call last): File stdin, line 1, in module File /tmp/python-1287O_i.py, line 32, in module f.bar() TypeError: mybar() takes exactly 1 argument (0 given) type(f.bar) type 'function' f.bar is mybar True f.bar(f) mybar As you see, bar is here resolved as an ordinary instance attribute - so here it evals to the mybar function object. If you want it to be a method object, you do have to invoke the descriptor protocol manually: f.bar = mybar.__get__(f, type(f)) f.bar bound method Foo.mybar of __main__.Foo object at 0xb7e16b0c f.bar() mybar Or alternatively, you can use the types module: import types f.bar = types.MethodType(mybar, f, type(f)) f.bar bound method Foo.mybar of __main__.Foo object at 0xb7e16b0c f.bar() mybar Second point is that the descriptor protocol is invoked on each and every lookup. So when it comes to function class attributes, you get a new method object each time: f = Foo() m1 = f.bar m1 bound method Foo.bar of __main__.Foo object at 0xb7cb522c m2 = f.bar m2 bound method Foo.bar of __main__.Foo object at 0xb7cb522c id(m1) 3084861188L id(m2) 3083656564L m1 is m2 False I think this should help you understand why your code doesn't work as you assumed it would !-) PS : as a side note, a common optimization trick is to short-circuit the whole lookup / descriptor mechanism when you have to call the same method of the same object in a loop: l = [] append = l.append for i in xrange(100): append(i) print l HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated?
wow, for some strange reason I did not find this with my first search yesterday: http://pypi.python.org/pypi/python-amazon-product-api/0.2.2 I will try this. sometime I wish all the old stuff would disappear from the internet. if somebody is looking for a cool startup idea: what about some website overlay that says hey, dude, this stuff is old, go here, here is the new and improved thing! :) thanks for your attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
On Feb 19, 1:44 pm, Steve Howell showel...@yahoo.com wrote: def coroutine(co): def _inner(*args, **kwargs): gen = co(*args, **kwargs) gen.next() return gen return _inner def squares_and_cubes(lst, target): for n in lst: target.send((n * n, n * n * n)) @coroutine def reject_bad_values(target): while True: square, cube = (yield) if not (square == 25 or cube == 64): target.send((square, cube)) @coroutine def cubes_only(target): while True: square, cube = (yield) target.send(cube) @coroutine def print_results(): while True: print (yield) squares_and_cubes(range(10), reject_bad_values( cubes_only( print_results() ) ) ) Wow! It took me a while to get my head around it, but that's pretty cool. This pipeline idea has actually been implemented further, see http:// blog.onideas.ws/stream.py. from stream import map, filter, cut range(10) map(lambda x: [x**2, x**3]) filter(lambda t: t[0]! =25 and t[1]!=64) cut[1] list [0, 1, 8, 27, 216, 343, 512, 729] -- aht -- http://mail.python.org/mailman/listinfo/python-list
Re: Constraints on __sub__, __eq__, etc.
On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov anfedo...@gmail.comwrote: It seems intuitive to me that the magic methods for overriding the +, -, , ==, , etc. operators should have no sideffects on their operands. Also, that == should be commutative and transitive, that and should be transitive, and anti-commutative. Is this intuition written up in a PEP, or assumed to follow from the mathematical meanings? It may be intuitive to you, but its not true, written down anywhere, nor assumed by the language, and the mathematical meaning of the operators doesn't matter to Python. Python purposefully does not enforce anything for these methods. Still, it's clear that (for example) '==' is not just a normal function call. Look at this example (in ipython): False == False == False True True == False == False False (True == False) == False True Anybody knows how why this is so? -- http://mail.python.org/mailman/listinfo/python-list
Re: Constraints on __sub__, __eq__, etc.
On Fri, Feb 19, 2010 at 2:30 AM, Roald de Vries r...@roalddevries.nl wrote: On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov anfedo...@gmail.comwrote: It seems intuitive to me that the magic methods for overriding the +, -, , ==, , etc. operators should have no sideffects on their operands. Also, that == should be commutative and transitive, that and should be transitive, and anti-commutative. Is this intuition written up in a PEP, or assumed to follow from the mathematical meanings? It may be intuitive to you, but its not true, written down anywhere, nor assumed by the language, and the mathematical meaning of the operators doesn't matter to Python. Python purposefully does not enforce anything for these methods. Still, it's clear that (for example) '==' is not just a normal function call. Look at this example (in ipython): False == False == False True True == False == False False (True == False) == False True Anybody knows how why this is so? Python is smart enough to recognize chained comparisons and do The Right Thing (tm). `X == Y == Z` is equivalent to `X == Y and Y == Z`. Same goes for the other comparison operators besides == and also possibly for longer chains. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
The Disappearing Program?
I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? -- http://mail.python.org/mailman/listinfo/python-list
Re: Constraints on __sub__, __eq__, etc.
Roald de Vries wrote: On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov anfedo...@gmail.comwrote: It seems intuitive to me that the magic methods for overriding the +, -, , ==, , etc. operators should have no sideffects on their operands. Also, that == should be commutative and transitive, that and should be transitive, and anti-commutative. Is this intuition written up in a PEP, or assumed to follow from the mathematical meanings? It may be intuitive to you, but its not true, written down anywhere, nor assumed by the language, and the mathematical meaning of the operators doesn't matter to Python. Python purposefully does not enforce anything for these methods. Still, it's clear that (for example) '==' is not just a normal function call. Look at this example (in ipython): False == False == False True True == False == False False (True == False) == False True Anybody knows how why this is so? As Chris said expr1 op1 expr2 op2 expr3 op3 ... is resolved as (expr1 op1 expr2) and (expr2 op2 expr3) and (expr3 op3 ... where each exprN is evaluated just once. For this to become the obvious way you have to look at interval checks like a b c Peter -- http://mail.python.org/mailman/listinfo/python-list
how to do filetransfer using usrp.
how to do filetransfer using usrp. can i make lan interface between two computers connected to usrp each and then transfer files (images/video) between them? how to transfer files? is there any example of such kind in gnuradio? sarosh -- View this message in context: http://old.nabble.com/how-to-do-filetransfer-using-usrp.-tp27652452p27652452.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: with statement and standard library
nobrowser nobrow...@gmail.com wrote: Yet there are many, many classes in the library whose use would be more elegant and readable if the with statement could be employed. Start with the connection objects in httplib and you can probably come up with 10 others easily. Maybe it is the case that some of these classes have with statement support already but I don't know it? If so, how can I know (without asking here each time, LOL)? If not, is there work being done on that? If an object has __enter__ and __exit__ methods, it should work as a context manager. If you do find any such classes, submitting doc bugs or patches would be really handy. However, I'm not sure if there was any attempt to retrofit the stdlib with context manager supports, so if you do come up with more elegant approaches, please contribute them, we'll all thank you :) -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wolftra...@invalid.com wrote: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? No idea whether it has to do with your problem, but if it's executable in Windows, its name is snowball.exe, not snowball. -- André Engels, andreeng...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
Andre Engels wrote: On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wolftra...@invalid.com wrote: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? No idea whether it has to do with your problem, but if it's executable in Windows, its name is snowball.exe, not snowball. Not necessarily, it's perfectly possible to setup a Python script to run on Windows using file associations in the same way that you can run a command (.bat) file. If the OP types the command ASSOC .py without the quotes at the command prompt, the response .py=Python.File tells you that this association has been setup. HTH. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wolftra...@invalid.com wrote: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? No idea whether it has to do with your problem, but if it's executable in Windows, its name is snowball.exe, not snowball. Not necessarily, it's perfectly possible to setup a Python script to run on Windows using file associations in the same way that you can run a command (.bat) file. If the OP types the command ASSOC .py without the quotes at the command prompt, the response .py=Python.File tells you that this association has been setup. And how does that invalidate what I wrote? One cannot associate the empty extension, so if snowball runs a program, that's the program in the file snowball.exe not the program in the file snowball that has its extension associated to something - it has no extension, so its extension cannot be associated. -- André Engels, andreeng...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this doesn't work?
Steven D'Aprano wrote: On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: nostat.__orig_get__ = nostat.__get__ I should point out that leading-and-trailing-double-underscore names are reserved for use by the language. Right... I completely missed that. I will try to change the habit. I am under impression that a function with no underscore in name is meant to be called publicly on instance, like Foo().nostat, a function with one underscore (and no trailing underscores) is meant to be like it's mostly intended for internal use, but you can still call it, somewhat like protected in C++, and a function with two leading underscores (and no trailing underscores) is meant as completely internal to the class, not meant to be called by outsiders, somewhat like private in C++ (I abstract from obvious point in C++ that semantics of those keywords is enforced by a compiler in C++). Is that correct? Regards, mk -- http://mail.python.org/mailman/listinfo/python-list
Re: Submit HTTP GET data from XP PC to PHP on web server.
On Fri, Feb 19, 2010 at 3:54 AM, Schedule ssched...@gmail.com wrote: Hello everyone I haeve tried to understand the capabilities of python in web development. Have gone throuhg forums and online tutorials. Nevertheless I am not able to find any topic which can give me some insite along with basic examples of how to send http get data from an xp mashine using python code to php on web server. Have a look at urllib2 (urllib2.Request) and maybe mechanize (http://wwwsearch.sourceforge.net/mechanize/). -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this doesn't work?
John Posner wrote: a False I expected to see 'nostatget' output: nostat.__get__ = nostatget obviously failed to replace this function's __get__ method. I don't quite understand the above sentence, so I'm assuming that you wanted the final is test to be True instead of False. No. I should have described my goal in plain English in first place. I wanted to replace nostat function's __get__ descriptor with a function that would allow me to peek inside it (i.e. into __get__ descriptor arguments) and that would then call original nostat.__get__. So no, I expected it to be false, that is, I expected to replace original descriptor with a custom descriptor. I just wondered why this custom nostatget descriptor didn't get called even though the new nostat.__get__ didn't seem to be its old self (so quite likely it was the new, nostatget, descriptor). But Bruno pointed out that I need instancemethod for that, not plain function. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list
Re: how to do filetransfer using usrp.
On Feb 19, 7:38 pm, sarosh sarosh.n...@hotmail.com wrote: how to do filetransfer using usrp. can i make lan interface between two computers connected to usrp each and then transfer files (images/video) between them? how to transfer files? is there any example of such kind in gnuradio? sarosh am not sure what USRP is but a quick google found http://packages.debian.org/sid/python-usrp -- http://mail.python.org/mailman/listinfo/python-list
What happened to pyjamas?
It appears that, in trying to cut down spm, somone chahnged a DNS entry and screwed it up : it shouldbe back before long. John -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this doesn't work?
mk a écrit : Steven D'Aprano wrote: On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: nostat.__orig_get__ = nostat.__get__ I should point out that leading-and-trailing-double-underscore names are reserved for use by the language. Right... I completely missed that. I will try to change the habit. I am under impression that a function with no underscore in name is meant to be called publicly on instance, like Foo().nostat, a function with one underscore (and no trailing underscores) is meant to be like it's mostly intended for internal use, but you can still call it, somewhat like protected in C++, and a function with two leading underscores (and no trailing underscores) is meant as completely internal to the class, not meant to be called by outsiders, somewhat like private in C++ (I abstract from obvious point in C++ that semantics of those keywords is enforced by a compiler in C++). Is that correct? Mostly, yes. - s/function/whatever/ : these rules apply to all names - the single leading underscore denote implementation, IOW : you should not use it, unless you have a pretty good reason to do so AND you take full responsability for what may happens - the double leading underscore is in fact mostly to protect your attribute from accidental overloading. It triggers a (simple) name-mangling operation that turns __yourname into _Yourclassname__yourname. FWIW, this is something I must have a use for at most once a year, and even then most of the times because I'm a bit of a control freak sometimes. -- http://mail.python.org/mailman/listinfo/python-list
Attributes in privates methods
Hi all. I have a class with the attribute 'log_file', opened out of the class: class ProteinCluster: def __init__(self,cluster_name,log_file): ... self.log_file = log_file ... Then i have a private method which write in the log_file: def _read_structure(self, pdb_code): ... ... self.log_file.write('blablabla') ... ... When i run the script, it raises the error: AttributeError: ProteinCluster instance has no attribute 'log_file' My question is, the class attributes are valids in private methods, like in publics methods? Thanks -- Yasser Almeida Hernández, BSc Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 214-3178 alme...@cim.sld.cu Correo FENHI -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
Andre Engels wrote: On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wolftra...@invalid.com wrote: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? No idea whether it has to do with your problem, but if it's executable in Windows, its name is snowball.exe, not snowball. Not necessarily, it's perfectly possible to setup a Python script to run on Windows using file associations in the same way that you can run a command (.bat) file. If the OP types the command ASSOC .py without the quotes at the command prompt, the response .py=Python.File tells you that this association has been setup. And how does that invalidate what I wrote? One cannot associate the empty extension, so if snowball runs a program, that's the program in the file snowball.exe not the program in the file snowball that has its extension associated to something - it has no extension, so its extension cannot be associated. Darn, only half the story, sorry. When the OP types snowball something executes. The command SET PATHEXT will show what file extensions are set to run files. On my system the response is :- c:\Users\Mark\Java2Pythonset pathext PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY So snowball with any one of the 12 extensions listed above would run on my system without actually typing the extension. I'm just guessing but has an executable been created but in another directory, so snowball.py is running? Perhaps the best bet is simply to search appropriate directories, or even the whole hard drive, for snowball.*. Then the OP would know exactly what he has or hasn't got. HTH. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Why this doesn't work?
mk a écrit : John Posner wrote: a False I expected to see 'nostatget' output: nostat.__get__ = nostatget obviously failed to replace this function's __get__ method. I don't quite understand the above sentence, so I'm assuming that you wanted the final is test to be True instead of False. No. I should have described my goal in plain English in first place. I wanted to replace nostat function's __get__ descriptor A descriptor (shortcut for object implementing the descriptor protocol) is an object that have a __get__ method - not the __get__ method itself. A function is a descriptor. The __get__ method of the function type is a method, and methods are not descriptors. with a function that would allow me to peek inside it (i.e. into __get__ descriptor arguments) = __get__(self, instance, cls=None) When called as a result of a look up on an instance f of class Foo, nostat.__get__ will get (nostat, f, Foo) as args. So no, I expected it to be false, that is, I expected to replace original descriptor with a custom descriptor. s/descriptor/__get__/ Anyway: these types (function, method etc) are implemented in (higly optimized) C, and with a lot of restriction for both performance and sanity reasons. It's a case of practicality beats purity. Another - perhaps more rewarding - exercise might be to implement a custom callable type that implements the descriptor protocol the same way the function do. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attributes in privates methods
Am 19.02.10 16:08, schrieb Yasser Almeida Hernández: Hi all. I have a class with the attribute 'log_file', opened out of the class: class ProteinCluster: def __init__(self,cluster_name,log_file): ... self.log_file = log_file ... Then i have a private method which write in the log_file: def _read_structure(self, pdb_code): ... ... self.log_file.write('blablabla') ... ... When i run the script, it raises the error: AttributeError: ProteinCluster instance has no attribute 'log_file' My question is, the class attributes are valids in private methods, like in publics methods? There is no semantical difference there, you must have some other error. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
This pipeline idea has actually been implemented further, see http:// blog.onideas.ws/stream.py. from stream import map, filter, cut range(10) map(lambda x: [x**2, x**3]) filter(lambda t: t[0]! =25 and t[1]!=64) cut[1] list [0, 1, 8, 27, 216, 343, 512, 729] Wow, cool! Just to show that you can easily add the iterator.map(f).blabla-syntax to Python: from __future__ import print_function class rubified(list): map= lambda self, f: rubified(map(f, self)) filter = lambda self, f: rubified(filter(f, self)) reject = lambda self, f: rubified(filter(lambda x: not f(x), self)) # each = lambda self, f: rubified(reduce(lambda x, y: print(y), self, None)) def each(self, f): for x in self: f(x) def __new__(cls, value): return list.__new__(cls, value) def print_numbers(): rubified([1, 2, 3, 4, 5, 6]).map(lambda n: [n * n, n * n * n]).reject(lambda (square, cube): square == 25 or cube == 64).map(lambda (square, cube): cube).each(lambda n: print(n)) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
On 2010-02-19 00:21 AM, Steven D'Aprano wrote: On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: What's the point of the wheel spinning? Did I miss something? I wonder whether it's for some kind of framework with a main loop like for it in list_of_iterables: for x in it: do_this_or_that (x) where, every once in a while one wants to throw some arbitrary code into the process, in the form of an empty iterable with side effects. Yes. That is exactly what the OP said in his original post: I have some generators that do stuff, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really generators because I want to call them /as/ a generator as part of a generalized system. But he doesn't say anything about side-effects. I have some generators *that do stuff*, then start yielding results. [emphasis mine]. Then he gives an example of a generator that does side-effect stuff and returning before yielding anything. -- 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
Executing Python code on another computer
Hello community, I googled for an answer of the following problem, but I couldn't find anything. I've got a netbook and my fast workstation compter, which I usually use for developing. But I'd also like to take my netbook around the house and to develop Python programms on it. The problem is that naturally a netbook is not the fastest computer you could find. So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
On 2010-02-19 01:01 AM, Ben Finney wrote: Robert Kernrobert.k...@gmail.com writes: On 2010-02-18 18:33 PM, Ben Finney wrote: Robert Kernrobert.k...@gmail.com writes: He doesn't want *any* empty generator. He wants an iterator that executes some given side-effect-producing code then immediately raises the StopIteration. Ah, hm. That's a rather perverse use case, but I'm sure the OP has their reasons. Which he explained fairly clearly, I thought, in his original post. (The original post isn't available to me; the reference in your reply isn't accessible AFAICT.) You responded to my post which quoted his in full. In the part of the original that you quoted, he speaks only of empty generators (easy and clean), not generators that exist only for the purpose of side-effects without yielding any items. I have some generators *that do stuff*, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really generators because I want to call them /as/ a generator as part of a generalized system. ... def gen(): # *do my one-time processing here* return yield [emphasis mine] Seriously, it's all there. I'm rather appalled at the lack of reading comprehension demonstrated in this thread. It's that latter that I describe as perverse, and I would think it worth some effort to determine if that can be avoided by a different approach. By rearchitecting the system to accept things that aren't iterators, yes. But he may not be in control of that system. And it may not make things cleaner to do so if he wants to use itertools to compose the iterables, whether they are for side effects or not, in various ways. -- 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: with statement and standard library
On 2010-02-19 01:18 AM, nobrowser wrote: Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many classes in the library whose use would be more elegant and readable if the with statement could be employed. Start with the connection objects in httplib and you can probably come up with 10 others easily. Yup. I believe that the devs wanted to adopt the new feature carefully and deliberately, though. They introduced it for file objects and locks first because those were the use cases that had been thoroughly explored in the development of the PEP. They held back from making every reasonable object a context manager in order to see how the new feature worked in the real world with those two use cases first. Now is probably a good time to start adding more sensible context managers to objects. I don't think there is any particular organized effort to do so, though. -- 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: Executing Python code on another computer
On Fri, 19 Feb 2010 07:52:59 -0800 (PST) SiWi wimmersi...@googlemail.com wrote: So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? Yes but it isn't really a Python question. I suggest Google but you haven't given us enough information, particularly what OSs you are running. If it was me I would simply use the netbook as a thin client for programs that I am writing and running on the main server. In my case a simple xterm would do the job since vi is my IDE and bash is my runtime environment. If you are using a GUI IDE you may be able to run the GUI app on the server with the display on the netbook. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Question about getmtime
Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? Thank you, Brandon -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
On Fri, Feb 19, 2010 at 4:52 PM, SiWi wimmersi...@googlemail.com wrote: Hello community, I googled for an answer of the following problem, but I couldn't find anything. I've got a netbook and my fast workstation compter, which I usually use for developing. But I'd also like to take my netbook around the house and to develop Python programms on it. The problem is that naturally a netbook is not the fastest computer you could find. So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? -- http://mail.python.org/mailman/listinfo/python-list I recommend setting up a SSH server on your stationary and run something like emacs. It's how I'm doing it anyway. -- http://mail.python.org/mailman/listinfo/python-list
A tool for find dependencies relationships behind Python projects
Hi, I just wrote a tool for drawing dependencies relationships diagram of Python project on Pypi. Here is the home page of the tool: http://code.google.com/p/python-gluttony/ Some examples: Sprox: http://static.ez2learn.com/gluttony/sprox_dot.png TurboGears2: http://static.ez2learn.com/gluttony/tg2_dot.png Hope this could be helpful :P Regards. Victor Lin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about getmtime
On Fri, Feb 19, 2010 at 5:05 PM, Brandon btaylordes...@gmail.com wrote: Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? Thank you, Brandon Wouldn't it be easier to make a script and see for yourself then to write a mail about it? -- http://mail.python.org/mailman/listinfo/python-list
a question on building MySQL-python
During installation of MySQL-python-1.2.3c1 I encountered the following error: $ python2.6 setup.py build running build running build_py copying MySQLdb/release.py - build/lib.linux-x86_64-2.6/MySQLdb running build_ext building '_mysql' extension creating build/temp.linux-x86_64-2.6 gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/include/mysql -I/usr/local/Python-2.6.3/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -L. -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so /usr/bin/ld: cannot find -lpython2.6 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 Linker could not find libpython2.6.so. Note that the compiler *did* find Python include file: -I/usr/local/Python-2.6.3/include/python2.6. I am running CentOS5.3. Python 2.6 was configured as follows: $ TARGET=/usr/local/Python-2.6.3 $ export LDFLAGS=-Wl,-rpath,$TARGET/lib $ ./configure --prefix=$TARGET \ --with-cxx=g++ --with-threads --enable-shared to avoid messing with LD_LIBRARY_PATH. I managed to complete the installation by pasting the above link command and adding proper -L option, but I would like to know what would be the proper fix. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Attributes in privates methods
Yasser Almeida Hernández a écrit : Hi all. I have a class with the attribute 'log_file', opened out of the class: class ProteinCluster: def __init__(self,cluster_name,log_file): ... self.log_file = log_file ... Then i have a private method which write in the log_file: def _read_structure(self, pdb_code): ... ... self.log_file.write('blablabla') ... ... When i run the script, it raises the error: AttributeError: ProteinCluster instance has no attribute 'log_file' My question is, the class attributes are valids in private methods, like in publics methods? Diez already answered - the above code seems correct, so the source of your problem is elsewhere. For the record, in your code, log_file is an instance attribute - a 'class attribute' is an attribute that is defined on the class object itself, and is shared by all instances of the class. Also, Python has no notion of public or private - at least at the language level. The '_name' convention is just, well, a naming convention. This wont solve your problem - sorry, not much we can do here - but at least it will help wrt/ mutual understanding !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
On 19 Feb, 15:52, SiWi wimmersi...@googlemail.com wrote: Hello community, I googled for an answer of the following problem, but I couldn't find anything. I've got a netbook and my fast workstation compter, which I usually use for developing. But I'd also like to take my netbook around the house and to develop Python programms on it. The problem is that naturally a netbook is not the fastest computer you could find. So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? There are plenty of ways to do this - but they are not really related to Python. What is most convenient for you will probably depend on the tools that you are used to using, your operating system and your level of expertise with configuring network services. On mac and linux it is very easy to set up an ssh server on your workstation. You can then edit your files remotely - the method might be different depending on your operating system, unless you use something like Emacs - and also execute them remotely. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
On 19 Feb, 15:52, SiWi wimmersi...@googlemail.com wrote: Hello community, I googled for an answer of the following problem, but I couldn't find anything. I've got a netbook and my fast workstation compter, which I usually use for developing. But I'd also like to take my netbook around the house and to develop Python programms on it. The problem is that naturally a netbook is not the fastest computer you could find. So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? Yes. Assuming you can cope with the relatively small netbook screen here are some options: 1. Telnet (ok within a home and where no graphics needed) 2. Ssh (ok where no graphics needed) 3. An X-Windows server on your netbook (ok under Linux but good Windows X Servers may be limited or nonexistent) 4. VNC (e.g. RealVnc) to get a remote view of the workstation's screen. I use telnet and RealVnc for purposes similar to those you describe. James -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about getmtime
On Feb 19, 10:26 am, Krister Svanlund krister.svanl...@gmail.com wrote: On Fri, Feb 19, 2010 at 5:05 PM, Brandon btaylordes...@gmail.com wrote: Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? Thank you, Brandon Wouldn't it be easier to make a script and see for yourself then to write a mail about it? Gee, thanks for the help. I guess. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
On Feb 19, 5:10 pm, D'Arcy J.M. Cain da...@druid.net wrote: On Fri, 19 Feb 2010 07:52:59 -0800 (PST) SiWi wimmersi...@googlemail.com wrote: So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? Yes but it isn't really a Python question. I suggest Google but you haven't given us enough information, particularly what OSs you are running. If it was me I would simply use the netbook as a thin client for programs that I am writing and running on the main server. In my case a simple xterm would do the job since vi is my IDE and bash is my runtime environment. If you are using a GUI IDE you may be able to run the GUI app on the server with the display on the netbook. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. I'm normally using IDLE and sometimes PyScripter on Windows Vista. The netbook is Windows XP. Should I switch to Vim or Emacs? -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
On Feb 19, 7:50 am, Roald de Vries r...@roalddevries.nl wrote: This pipeline idea has actually been implemented further, see http:// blog.onideas.ws/stream.py. from stream import map, filter, cut range(10) map(lambda x: [x**2, x**3]) filter(lambda t: t[0]! =25 and t[1]!=64) cut[1] list [0, 1, 8, 27, 216, 343, 512, 729] Wow, cool! Just to show that you can easily add the iterator.map(f).blabla-syntax to Python: from __future__ import print_function class rubified(list): map = lambda self, f: rubified(map(f, self)) filter = lambda self, f: rubified(filter(f, self)) reject = lambda self, f: rubified(filter(lambda x: not f(x), self)) # each = lambda self, f: rubified(reduce(lambda x, y: print(y), self, None)) def each(self, f): for x in self: f(x) def __new__(cls, value): return list.__new__(cls, value) def print_numbers(): rubified([1, 2, 3, 4, 5, 6]).map(lambda n: [n * n, n * n * n]).reject(lambda (square, cube): square == 25 or cube == 64).map(lambda (square, cube): cube).each(lambda n: print(n)) Sure, that definitely achieves the overall sequential structure of operations that I like in Ruby. A couple other example have been posted as well now, which also mimic something akin to a Unix pipeline. A lot of Ruby that I see gets spelled like this: list.select { |arg1, arg2| expr }.reject { |arg| expr }.collect { |arg} expr } With your class you can translate into Python as follows: list.select(lambda arg1, arg2: expr ).reject(lambda arg: expr ).collect(lambda arg: expr ) So for chaining transformations based on filters, the difference really just comes down to syntax (and how much sugar is built into the core library). The extra expressiveness of Ruby comes from the fact that you can add statements within the block, which I find useful sometimes just for debugging purposes: debug = true data = strange_dataset_from_third_party_code() data.each { |arg| if debug and arg 1 puts arg end # square the values arg * arg } -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
On Fri, 19 Feb 2010 08:32:48 -0800 (PST) SiWi wimmersi...@googlemail.com wrote: I'm normally using IDLE and sometimes PyScripter on Windows Vista. The netbook is Windows XP. Should I switch to Vim or Emacs? Umm... Yes? It's still not a Python question and is in fact a religious one. Other people have different religions. You should probably ask this question on a list dedicated to using Windows. What you want to know is how to run programs remotely. The fact that it is a Python program is irrelevant. I'm not trying to brush you off. I'm just trying to point you somewhere that can answer your question better. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: On 2010-02-19 00:21 AM, Steven D'Aprano wrote: On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: What's the point of the wheel spinning? Did I miss something? I wonder whether it's for some kind of framework with a main loop like for it in list_of_iterables: for x in it: do_this_or_that (x) where, every once in a while one wants to throw some arbitrary code into the process, in the form of an empty iterable with side effects. Yes. That is exactly what the OP said in his original post: I have some generators that do stuff, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really generators because I want to call them /as/ a generator as part of a generalized system. But he doesn't say anything about side-effects. I have some generators *that do stuff*, then start yielding results. [emphasis mine]. What does do stuff have to do with side-effects? Here's a generator that does stuff, and it has no side-effects. def generator_that_does_stuff(x): y = 3*x**2 - 5*x + 1 yield y Do stuff is ambiguous -- it could mean stuff with side-effects, or stuff without. The first is potentially harmful, the second is pointless. Then he gives an example of a generator that does side-effect stuff and returning before yielding anything. Unfortunately the OP's original post isn't visible to me, so I can only respond to your post, which may or may not quote the entire original post. The only example I have seen was an empty generator with a comment saying do my one-time processing here, with *no* indication of what that one- time processing is supposed to be, why it is necessary, and whether it has side-effects or not. Since the OP (apparently) hasn't seen fit to comment, we're still all guessing what he means. It's certainly possible, likely even, that he's using generators that operate by side-effect: that explanation is consistent with his request. Personally, I can't imagine that would be good coding practice, but I could be wrong. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
On 2/19/2010 7:16 AM, Mark Lawrence wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wolftra...@invalid.com ... tories, or even the whole hard drive, for snowball.*. Then the OP would know exactly what he has or hasn't got. HTH. Mark Lawrence Here's the answer. Consider this folder. Afolder abc.py hello.py I now apply py2exe steps to produce an executable for abc. The folder now changes to Afolder build dist abc.py hello.py build are two new folders. dist contains abc.exe. Somehow when I type abc at the command prompt, this follows a path to dist, and finds abc.exe, where it executes properly. Cute, eh? I have no explanation for it. I have no idea what build is for, but dist contains a bunch of other files that possible apply to doing this with other files in the Afolder. hello.py maybe. The details seem to be shrouded. Possible a Google might provide a full explanation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
On Fri, 19 Feb 2010 08:32:53 -0800, Steve Howell wrote: The extra expressiveness of Ruby comes from the fact that you can add statements within the block, which I find useful sometimes just for debugging purposes: debug = true data = strange_dataset_from_third_party_code() data.each { |arg| if debug and arg 1 puts arg end # square the values arg * arg } How is that different from this? debug = true data = strange_dataset_from_third_party_code() for i, arg in enumerate(data): if debug and arg 1 print arg # square the values data[i] = arg * arg I don't see the extra expressiveness. What I see is that the Ruby snippet takes more lines (even excluding the final brace), and makes things implicit which in my opinion should be explicit. But since I'm no Ruby expert, perhaps I'm misreading it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: with statement and standard library
On 2/19/2010 2:18 AM, nobrowser wrote: Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many classes in the library whose use would be more elegant and readable if the with statement could be employed. Start with the connection objects in httplib and you can probably come up with 10 others easily. Maybe it is the case that some of these classes have with statement support already but I don't know it? If so, how can I know (without asking here each time, LOL)? If not, is there work being done on that? I am interested in this question mostly in the context of Python 2.6. 2.6 is in maintenance mode only; no new features. 2.7 will be so when released in June and effectively so in a month when the first beta is released. 3.2 is a reasonable target. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
On Fri, Feb 19, 2010 at 9:21 AM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: But he doesn't say anything about side-effects. I have some generators *that do stuff*, then start yielding results. [emphasis mine]. What does do stuff have to do with side-effects? Here's a generator that does stuff, and it has no side-effects. def generator_that_does_stuff(x): y = 3*x**2 - 5*x + 1 yield y Do stuff is ambiguous -- it could mean stuff with side-effects, or stuff without. The first is potentially harmful, the second is pointless. What does it matter what *do stuff* means? My point is, there's *stuff* I need to do there, and what that stuff is really has absolutely nothing to do with the issue at hand. Its certainly a side-effect, at least in terms of the generator, otherwise there would be no point really in having the generator there at all. I have a system that consumes generators which, almost always, yield over objects to be handled. One in ten-- nay, one in 20, if not worse-- cases has me wanting to inject into this system some arbitrary code that gets run. Some bit of processing I need to get done in the context of that cycle. There's nothing harmful about it. These aren't generic generators that are going to be passed around and consumed by random things or anything else. They exist solely to be consumed by the core system. They're never composed or loaded by anything else, its just the API of how the system works. It loads bunches of modules dynamically, each module has a generator for yielding objects to be consumed. That generator is the one and only line of connection between the core system and the modules. Then he gives an example of a generator that does side-effect stuff and returning before yielding anything. Unfortunately the OP's original post isn't visible to me, so I can only respond to your post, which may or may not quote the entire original post. The only example I have seen was an empty generator with a comment saying do my one-time processing here, with *no* indication of what that one- time processing is supposed to be, why it is necessary, and whether it has side-effects or not. It doesn't matter what the one-time processing is supposed to be. I could say, This particular module doesn't yield objects like all the rest, but instead just needs to override a certain utility function the system uses, to change how name equality is handled so that tests compare on normalized forms. The API for integrating into the the core system -- to be loaded as a module and integrated into the system -- is to have a generator of a certain name, which yields N objects. In this case, N = 0.. Now, having said that, why in the world does that matter at all to my question? :) It changes no part of anyone's possible solution, be it Robert's once-wrapped-to-decorator, to Holden's just-comment-the-oddity, to your empty-for-loop-yield, to any others. It doesn't *matter* what the processing has to be. And if it has side-effects or not is only relevant to the question of the perversity of my use-case, a discussion I just don't really even have any interest in =) Thanks, all, though, for your responses and solutions. Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here return [] A generator is just a callable that returns an iterator, after all. If I don't want to yield anything, returning an empty iterable accomplishes the same goal to get the code loaded and run by the host-cycle while contributing nothing at all to the object pool. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to create a dict from string
Tim Arnold wrote: Hi, I've got some text to parse that looks like this text = ''' blah blah blah \Template[Name=RAD,LMRB=False,LMRG=True]{tables} ho dee ho ''' If you're going to include backslashes in the string literal then use a raw string for safety. I want to extract the bit between the brackets and create a dictionary. Here's what I'm doing now: def options(text): d = dict() options = text[text.find('[')+1:text.find(']')] for k,v in [val.split('=') for val in options.split(',')]: d[k] = v return d 1. I'd check whether there's actually a template. 2. 'dict' will accept a list of key/value pairs. def options(text): start = text.find('[') end = text.find(']', start) if start == -1 or end == -1: return {} options = text[start + 1 : end] return dict(val.split('=') for val in options.split(',')) if __name__ == '__main__': for line in text.split('\n'): if line.startswith('\\Template'): print options(line) is that the best way or maybe there's something simpler? The options will always be key=value format, comma separated. thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
On Feb 19, 9:30 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Fri, 19 Feb 2010 08:32:53 -0800, Steve Howell wrote: The extra expressiveness of Ruby comes from the fact that you can add statements within the block, which I find useful sometimes just for debugging purposes: debug = true data = strange_dataset_from_third_party_code() data.each { |arg| if debug and arg 1 puts arg end # square the values arg * arg } How is that different from this? debug = true data = strange_dataset_from_third_party_code() for i, arg in enumerate(data): if debug and arg 1 print arg # square the values data[i] = arg * arg I don't see the extra expressiveness. What I see is that the Ruby snippet takes more lines (even excluding the final brace), and makes things implicit which in my opinion should be explicit. But since I'm no Ruby expert, perhaps I'm misreading it. You are reading the example out of context. Can you re-read the part you snipped? The small piece of code can obviously be written imperatively, but the point of the example was not to print a bunch of squares. -- http://mail.python.org/mailman/listinfo/python-list
speed question, reading csv using takewhile() and dropwhile()
I have some some (~50) text files that have about 250,000 rows each. I am reading them in using the following which gets me what I want. But it is not fast. Is there something I am missing that should help. This is mostly an question to help me learn more about python. It takes about 4 min right now. def read_data_file(filename): reader = csv.reader(open(filename, U),delimiter='\t') read = list(reader) data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in read]) data = [x for x in data_rows][1:] mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) mask = [row for row in mask_rows if row][3:] outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) outlier = [row for row in outlier_rows if row][3:] *Vincent Davis 720-301-3003 * vinc...@vincentdavis.net my blog http://vincentdavis.net | LinkedInhttp://www.linkedin.com/in/vincentdavis -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to pyjamas?
On 18 Feb, 19:58, sstein...@gmail.com sstein...@gmail.com wrote: Down from here (NH, US). S On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: Unreacheable from Italy as well... -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to pyjamas?
On Feb 18, 5:21 pm, Daniele Gondoni daniele.gond...@gmail.com wrote: On 18 Feb, 19:58, sstein...@gmail.com sstein...@gmail.com wrote: Down from here (NH, US). S On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: Unreacheable from Italy as well... Same here (Buenos Aires, Argentina). -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing a routine that sends mail
commander_coder a écrit : Hello, I have a routine that sends an email (this is how a Django view notifies me that an event has happened). I want to unit test that routine. http://docs.djangoproject.com/en/dev/topics/email/#e-mail-backends Or if you're stuck with 1.x 1.2a, you could just mock the send_mail function to test that your app does send the appropriate mail - which is what you really want to know. My 2 cents... -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for e.message() in python 2.6
On Feb 17, 4:58 am, Nandakumar Chandrasekhar navanitach...@gmail.com wrote: Dear Folks, In previous versions of Python I used to use e.message() to print out the error message of an exception like so: try: result = x / y except ZeroDivisionError, e: print e.message() Unfortunately in Python 2.6 the message method is deprecated. Is there any replacement for the message method in Python 2.6 or is there any best practice that should be used in Python from now on? Thank you. Yours sincerely, Nanda try: result = x / y except ZeroDivisionError as e: print e Note different syntax using except ... as ... e.message is deprecated here, but e.args[0] contains the same thing. see http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110 and http://www.python.org/dev/peps/pep-3110/ chris -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to pyjamas?
On Feb 18, 9:53 pm, Irmen de Jong ir...@-nospam-xs4all.nl wrote: On 2/18/10 9:45 PM, Luis M. González wrote: On Feb 18, 5:21 pm, Daniele Gondonidaniele.gond...@gmail.com wrote: On 18 Feb, 19:58, sstein...@gmail.comsstein...@gmail.com wrote: Down from here (NH, US). S On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: Unreacheable from Italy as well... Same here (Buenos Aires, Argentina). It ain't down till Netcraft confirms it! http://uptime.netcraft.com/up/graph?site=www.pyjs.org Oh wait... -irmen my goodness! it seems only the domain has expired the site's still there, just add 216.34.181.97 pyjs.org to your hosts file and BANG -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to pyjamas?
On 2/18/10 9:45 PM, Luis M. González wrote: On Feb 18, 5:21 pm, Daniele Gondonidaniele.gond...@gmail.com wrote: On 18 Feb, 19:58, sstein...@gmail.comsstein...@gmail.com wrote: Down from here (NH, US). S On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: Unreacheable from Italy as well... Same here (Buenos Aires, Argentina). It ain't down till Netcraft confirms it! http://uptime.netcraft.com/up/graph?site=www.pyjs.org Oh wait... -irmen -- http://mail.python.org/mailman/listinfo/python-list
Trouble running pywin32-214.win-amd64-py3.1 on 64-bit Windows 7
Hello, I downloaded pywin32-214.win-amd64-py3.1, and it installs just fine (except that it prints a traceback when it tells me the postinstall script completed), but then when I try to execute Pythonwin.exe, I get the following error popup: The application can not locate win32ui.pyd (or Python) (126) The specified module could not be found However, the file win32ui.pyd is right there in the same directory from which I am executing Pythonwin.exe. Can anyone help me figure out what I am doing wrong here? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
SiWi wrote: On Feb 19, 5:10 pm, D'Arcy J.M. Cain da...@druid.net wrote: On Fri, 19 Feb 2010 07:52:59 -0800 (PST) SiWi wimmersi...@googlemail.com wrote: So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? Yes but it isn't really a Python question. I suggest Google but you haven't given us enough information, particularly what OSs you are running. If it was me I would simply use the netbook as a thin client for programs that I am writing and running on the main server. In my case a simple xterm would do the job since vi is my IDE and bash is my runtime environment. If you are using a GUI IDE you may be able to run the GUI app on the server with the display on the netbook. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. I'm normally using IDLE and sometimes PyScripter on Windows Vista. The netbook is Windows XP. Should I switch to Vim or Emacs? Vista supports rdesktop , you could use it. I don't know if XP is shipped with a rdesktop client though (goggle for remote desktop). JM -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
On Feb 19, 12:21 pm, W. eWatson wolftra...@invalid.com wrote: On 2/19/2010 7:16 AM, Mark Lawrence wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wolftra...@invalid.com ... tories, or even the whole hard drive, for snowball.*. Then the OP would know exactly what he has or hasn't got. HTH. Mark Lawrence Here's the answer. Consider this folder. Afolder abc.py hello.py I now apply py2exe steps to produce an executable for abc. The folder now changes to Afolder build dist abc.py hello.py build are two new folders. dist contains abc.exe. Somehow when I type abc at the command prompt, this follows a path to dist, and finds abc.exe, where it executes properly. Cute, eh? I have no explanation for it. Are you sure it's executing abc.exe? If you are at a Python command prompt within the DOS shell and you just type just abc, I think what is happening is you are running abc.py, NOT abc.exe. py2exe creates a dist folder (short for distributables) by default and puts your .exe into it along with whatever other files are needed to run your application. Depending on how you set the bundling options, this may be a lot of things or just 1-2 other things. Che -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about getmtime
Brandon wrote: On Feb 19, 10:26 am, Krister Svanlund krister.svanl...@gmail.com wrote: On Fri, Feb 19, 2010 at 5:05 PM, Brandon btaylordes...@gmail.com wrote: Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? Thank you, Brandon Wouldn't it be easier to make a script and see for yourself then to write a mail about it? Gee, thanks for the help. I guess. Well, copying the file won't affect the getmtime, since it's still there, and unmodified. Moving it will cause the getmtime to to get an os.error, because the file no longer exists. Probably you mean you're adjusting the path variable to point to the new location for the file. But the answer is still it depends. How about if you get more specific? If you write a copy utility using two opens, a read() and a write(), then the new file will certainly get a new timestamp unless you do something to prevent it. If you copy the file from a DOS box in Windows XP, using the COPY command, then the getmtime on the new file will be identical to the one on the old. If you do it on an Amiga using pip, I have no idea. Perhaps you're writing a copy/move utility of your own, and you want to know how to cause a new file to have the same attributes as the original. If so, be more specific. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing Python code on another computer
SiWi wrote: On Feb 19, 5:10 pm, D'Arcy J.M. Cain da...@druid.net wrote: On Fri, 19 Feb 2010 07:52:59 -0800 (PST) SiWi wimmersi...@googlemail.com wrote: So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? Yes but it isn't really a Python question. I suggest Google but you haven't given us enough information, particularly what OSs you are running. If it was me I would simply use the netbook as a thin client for programs that I am writing and running on the main server. In my case a simple xterm would do the job since vi is my IDE and bash is my runtime environment. If you are using a GUI IDE you may be able to run the GUI app on the server with the display on the netbook. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. I'm normally using IDLE and sometimes PyScripter on Windows Vista. The netbook is Windows XP. Should I switch to Vim or Emacs? In that case, consider using RemoveDesktop, which is built into both Xp and Vista. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Upgrading Py2exe App
On Feb 18, 7:19 pm, Ryan Kelly r...@rfk.id.au wrote: On Thu, 2010-02-18 at 07:46 -0800, T wrote: I have a Python app which I converted to an EXE (all files separate; single EXE didn't work properly) via py2exe - I plan on distributing this and would like the ability to remotely upgrade the program (for example, via HTTP/HTTPS). Looks like it's not just the EXE that I will need need to replace (DLLs, the library.zip, etc.). What would be the best way to go about doing this? I've been working on an auto-update framework for my own frozen apps, you might find it useful: http://pypi.python.org/pypi/esky Docs are a little scarce at the moment, the next release will hopefully come with a short tutorial (as well as support for cx_freeze and maybe py2app, depending on how adventurous I'm feeling). Cheers, Ryan -- Ryan Kellyhttp://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au | http://www.rfk.id.au/ramblings/gpg/for details signature.asc 1KViewDownload Thanks Ryan..this looks like it could be what I'm looking for, but I'm still a bit unsure of how exactly how it works. Do you happen to have an idea approx when the next release w/ tutorial will be out? -- http://mail.python.org/mailman/listinfo/python-list
Chaining 501 generators breaks everything?
I implemented a Sieve of Eratostheneshttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenesprimes algorithm using generators: http://gist.github.com/309109 This code which chains together 500 generators works fine (~1/20th of a second) on my laptop. The code which chaines 501 generators (s/498/499/ on line 23) doesn't seem to finish. Does anyone know the reason for this, or can anyone point me where to look for a good explanation? Cheers, Andrey -- http://mail.python.org/mailman/listinfo/python-list
Re: Chaining 501 generators breaks everything?
Ack, just ran it from shell, realized my editor was just choking on a maximum recursion depth exceeded RuntimeError. Didn't realize generators used the call stack... - Andrey On Fri, Feb 19, 2010 at 2:47 PM, Andrey Fedorov anfedo...@gmail.com wrote: I implemented a Sieve of Eratostheneshttp://en.wikipedia.org/wiki/Sieve_of_Eratosthenesprimes algorithm using generators: http://gist.github.com/309109 This code which chains together 500 generators works fine (~1/20th of a second) on my laptop. The code which chaines 501 generators (s/498/499/ on line 23) doesn't seem to finish. Does anyone know the reason for this, or can anyone point me where to look for a good explanation? Cheers, Andrey -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make an empty generator?
On 2/19/2010 2:25 PM, Terry Reedy wrote: On 2/19/2010 12:44 PM, Stephen Hansen wrote: Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here return [] A generator is just a callable that returns an iterator, after all. Confusing generators and generator functions is, well, confusing. For future reference, and clarity of communication in Pythonland, generator function: function that produces a generator when called; if python coded, its body contains 'yield'. generator: iterator produced by a generator function; I suggest: iterator produced by a generator function or a generator expression; has .__next__ and self-returning .__init__, like all other iterators. generator expression: an expression that evaluates to a generator; the expression is used to create a temporary anonymous generator function that is called to produce the generator and is then discarded. Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms to Terry's definitions above in most places. But the Glossary says: generator A function which returns an iterator. ... more ... generator expression An expression that returns a generator. ... more ... The additional verbiage in these definitions mitigates the damage, but I think the first entry should be headlined *generator function* instead of *generator*. And the Glossary should include Terry's additional entry [ as amended by me :-) ]: generator An iterator produced by a generator function or a generator expression. -John -- http://mail.python.org/mailman/listinfo/python-list
Re: speed question, reading csv using takewhile() and dropwhile()
On 2/19/2010 3:02 PM, MRAB wrote: Is this any better? def read_data_file(filename): reader = csv.reader(open(filename, U),delimiter='\t') data = [] for row in reader: if '[MASKS]' in row: break data.append(row) As noted in another thread recently, you can save time by *not* looking up the append method of the list object each time through the FOR loop: data = [] app_method = data.append for row in reader: if '[MASKS]' in row: break app_method(row) Similarly in the rest of the code. This technique improved performance about 31% in this test: # import timeit tt = timeit.repeat(for i in xrange(100): mylist.append(i), mylist=[], number=25) print look up append() method each time:, min(tt) tt = timeit.repeat(for i in xrange(100): app(i), mylist=[]; app = mylist.append, number=25) print look up append() method just once:, min(tt) # output: look up append() method each time: 8.45481741783 look up append() method just once: 5.84429637887 -John -- http://mail.python.org/mailman/listinfo/python-list
Re: speed question, reading csv using takewhile() and dropwhile()
On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis vinc...@vincentdavis.netwrote: I have some some (~50) text files that have about 250,000 rows each. I am reading them in using the following which gets me what I want. But it is not fast. Is there something I am missing that should help. This is mostly an question to help me learn more about python. It takes about 4 min right now. def read_data_file(filename): reader = csv.reader(open(filename, U),delimiter='\t') read = list(reader) You're slurping the entire file here when it's not necessary. data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in read]) [x for x in read] is basically a copy of the entire list. This isn't necessary. data = [x for x in data_rows][1:] Again, copying here is unnecessary. [x for x in y] isn't a paradigm in Python. If you really need a copy of an array, x = y[:] is the paradigm. mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) mask = [row for row in mask_rows if row][3:] Here's another unnecessary array copy. outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) outlier = [row for row in outlier_rows if row][3:] And another. Just because you're using Python doesn't mean you get to be silly in how you move data around. Avoid copies as much as possible, and try to avoid slurping in large files all at once. Line-by-line processing is best. I think you should invert this operation into a for loop. Most people tend to think of things better that way than chained iterators. It also helps you to not duplicate data when it's unnecessary. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Upgrading Py2exe App
On Thu, 2010-02-18 at 20:32 -0800, CM wrote: On Feb 18, 7:19 pm, Ryan Kelly r...@rfk.id.au wrote: On Thu, 2010-02-18 at 07:46 -0800, T wrote: I have a Python app which I converted to an EXE (all files separate; single EXE didn't work properly) via py2exe - I plan on distributing this and would like the ability to remotely upgrade the program (for example, via HTTP/HTTPS). Looks like it's not just the EXE that I will need need to replace (DLLs, the library.zip, etc.). What would be the best way to go about doing this? I've been working on an auto-update framework for my own frozen apps, you might find it useful: http://pypi.python.org/pypi/esky This looks pretty interesting and useful. Thanks :-) Just to help me understand it a bit more: what is it that users will download from some web page in order to initially get the py2exe'd app on their system? Is it really an esky, with the app's .exe file inside it (but the esky is named the same as the app)? Currently, it's just a zip file with the frozen app in it, which the user unzips to wherever they want the app. When unzipped it looks like this: myapp.exe -- actually the esky bootstrap exe myapp-X.Y.Z.win32/ myapp.exe -- the actual frozen app as produced by py2exe python26.dll ...etc... This could easily be wrapped in an installer - the important thing is just that the files end up on the user's machine in the expected directory structure. And then when they want to update, the app's code calls the esky class to do the work of swapping out the appropriate .exe file? Something like this? Yes. The idea of having a bootstrapping exe is that actual application code can be swapped out without having to overwrite the executable file. As long as you don't change python versions, this allows updates to be safe against system crashes, even on platforms without atomic file replacement. So the frozen app does this in a background thread: Esky(sys.executable,http://my.updates.com;).auto_update() And it hits the given url, grabs the latest zipfile, downloads and unpacks and atomically places it into the application directory. Et viola, your app is at the latest version. From the packager's point of view, you run the bdist_esky distutils command to generate the zipfile containing your latest version, then simply upload it to your server. Would this also work if one used InnoSetup to install the exe on the user's system? Yes, absolutely - in fact I plan to do this myself at some stage. All that's required is that the files end up in the expected directory structure. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: Upgrading Py2exe App
On Fri, 2010-02-19 at 11:08 -0800, T wrote: On Feb 18, 7:19 pm, Ryan Kelly r...@rfk.id.au wrote: On Thu, 2010-02-18 at 07:46 -0800, T wrote: I have a Python app which I converted to an EXE (all files separate; single EXE didn't work properly) via py2exe - I plan on distributing this and would like the ability to remotely upgrade the program (for example, via HTTP/HTTPS). Looks like it's not just the EXE that I will need need to replace (DLLs, the library.zip, etc.). What would be the best way to go about doing this? I've been working on an auto-update framework for my own frozen apps, you might find it useful: http://pypi.python.org/pypi/esky Docs are a little scarce at the moment, the next release will hopefully come with a short tutorial (as well as support for cx_freeze and maybe py2app, depending on how adventurous I'm feeling). Thanks Ryan..this looks like it could be what I'm looking for, but I'm still a bit unsure of how exactly how it works. Do you happen to have an idea approx when the next release w/ tutorial will be out? If I punt on the py2app support, I should be able to get it done in the next 3-4 days. I'll send a quick email to python-list when it's ready. Here's a rough roadmap of where the project is heading: v0.4.0: cx_freeze support and a tutorial [the next 3-4 days] v0.4.1: py2app support [the next 2-3 weeks] v0.5.0: differential updates using bsdiff [next few months] Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
On 2/19/2010 10:56 AM, CM wrote: On Feb 19, 12:21 pm, W. eWatsonwolftra...@invalid.com wrote: On 2/19/2010 7:16 AM, Mark Lawrence wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: Andre Engels wrote: On Fri, Feb 19, 2010 at 12:20 PM, W. eWatsonwolftra...@invalid.com ... tories, or even the whole hard drive, for snowball.*. Then the OP would know exactly what he has or hasn't got. HTH. Mark Lawrence Here's the answer. Consider this folder. Afolder abc.py hello.py I now apply py2exe steps to produce an executable for abc. The folder now changes to Afolder build dist abc.py hello.py build are two new folders. dist contains abc.exe. Somehow when I type abc at the command prompt, this follows a path to dist, and finds abc.exe, where it executes properly. Cute, eh? I have no explanation for it. Are you sure it's executing abc.exe? If you are at a Python command prompt within the DOS shell and you just type just abc, I think what is happening is you are running abc.py, NOT abc.exe. py2exe creates a dist folder (short for distributables) by default and puts your .exe into it along with whatever other files are needed to run your application. Depending on how you set the bundling options, this may be a lot of things or just 1-2 other things. Che Well, you are right. What proof do I have? In fact, I just tried to run a program that was not converted, and left off py. It worked. So maybe the only way to execute the compiled code is to to to dist? -- http://mail.python.org/mailman/listinfo/python-list
Re: Chaining 501 generators breaks everything?
On Fri, Feb 19, 2010 at 11:47 AM, Andrey Fedorov anfedo...@gmail.com wrote: I implemented a Sieve of Eratosthenes primes algorithm using generators: http://gist.github.com/309109 This code which chains together 500 generators works fine (~1/20th of a second) on my laptop. You may want a more traditional approach. Until Python gets tail recursion (doubtful), this won't work very well on any platform. #!/usr/bin/env python from itertools import islice, count from time import time def primes(): seen = [] for i in count(2): for s in seen: if i%s == 0: break else: # Run if the for loop doesn't break seen.append(i) yield i start = time() for i in islice(primes(), 0, 1): print i print time() - start -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list
Can't Access ANY url from python (errno 61)
Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. The strangest thing about this is that firefox still works flawlessly on any site. However, at my friend's place, I was able to open url's from HIS computer, no problem. Can anyone think of anything I can do to solve this problem? Why would firefox be working fine but not Python? Any suggestions would be greatly appreciated. Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: The Disappearing Program?
On Fri, Feb 19, 2010 at 1:42 PM, W. eWatson wolftra...@invalid.com wrote: Well, you are right. What proof do I have? In fact, I just tried to run a program that was not converted, and left off py. It worked. So maybe the only way to execute the compiled code is to to to dist? Yes. You're meant to move everything in dist to where you want to run it, that's the point of the dist folder-- its what you distribute. THe .exe and the other stuff next to it the .exe needs to run. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: speed question, reading csv using takewhile() and dropwhile()
In reference to the several comments about [x for x in read] is basically a copy of the entire list. This isn't necessary. or list(read). I had thought I had a problem with having iterators in the takewhile() statement. I thought I testes and it didn't work. It seems I was wrong. It clearly works. I'll make this change and see if it is any better. I actually don't plan to read them all in at once, only as needed, but I do need the whole file in an array to perform some mathematics on them and compare different files. So my interest was in making it faster to open them as needed. I guess part of it is that they are about 5mb so I guess it might be disk speed in part. Thanks *Vincent Davis 720-301-3003 * vinc...@vincentdavis.net my blog http://vincentdavis.net | LinkedInhttp://www.linkedin.com/in/vincentdavis On Fri, Feb 19, 2010 at 2:13 PM, Jonathan Gardner jgard...@jonathangardner.net wrote: On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis vinc...@vincentdavis.netwrote: I have some some (~50) text files that have about 250,000 rows each. I am reading them in using the following which gets me what I want. But it is not fast. Is there something I am missing that should help. This is mostly an question to help me learn more about python. It takes about 4 min right now. def read_data_file(filename): reader = csv.reader(open(filename, U),delimiter='\t') read = list(reader) You're slurping the entire file here when it's not necessary. data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in read]) [x for x in read] is basically a copy of the entire list. This isn't necessary. data = [x for x in data_rows][1:] Again, copying here is unnecessary. [x for x in y] isn't a paradigm in Python. If you really need a copy of an array, x = y[:] is the paradigm. mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) mask = [row for row in mask_rows if row][3:] Here's another unnecessary array copy. outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) outlier = [row for row in outlier_rows if row][3:] And another. Just because you're using Python doesn't mean you get to be silly in how you move data around. Avoid copies as much as possible, and try to avoid slurping in large files all at once. Line-by-line processing is best. I think you should invert this operation into a for loop. Most people tend to think of things better that way than chained iterators. It also helps you to not duplicate data when it's unnecessary. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On Fri, Feb 19, 2010 at 1:48 PM, MattB mattbar...@gmail.com wrote: I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. The strangest thing about this is that firefox still works flawlessly on any site. However, at my friend's place, I was able to open url's from HIS computer, no problem. Can anyone think of anything I can do to solve this problem? Why would firefox be working fine but not Python? Any suggestions would be greatly appreciated. Are you running behind a firewall? See if Firefox is configured with a proxy. You'll have to use that to talk to any website. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
On 02/19/10 14:57, Steve Howell wrote: In a more real world example, the intermediate results would be something like this: departments departments_in_new_york departments_in_new_york_not_on_bonus_cycle employees_in_departments_in_new_york_not_on_bonus_cycle names_of_employee_in_departments_in_new_york_not_on_bonus_cycle I fare better, in less than ten-seconds thinking: departments eligible_departments eligible_departments eligible_employees eligible_employee_names as a bonus, they would be much more resilient when there are change of eligibility requirements. Names doesn't have to exactly describe what's in it; in fact, if your names is way too descriptive, it may take significantly more brain-cycle to parse. A good name abstracts the objects contained in it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On Fri, Feb 19, 2010 at 1:48 PM, MattB mattbar...@gmail.com wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. The strangest thing about this is that firefox still works flawlessly on any site. snip Can anyone think of anything I can do to solve this problem? Why would firefox be working fine but not Python? Any suggestions would be greatly appreciated. Based on what you've said, it's possible the school may have blocked mechanize's User-Agent somehow. Try spoofing mechanize as Firefox by setting the string for the User-Agent header to that of Firefox. See the section Changing the automatically-added headers (User-Agent) on http://wwwsearch.sourceforge.net/mechanize/doc.html for how to do that. To see what Firefox's User-Agent is, use http://whatsmyuseragent.com/ Cheers, Chris -- Disclaimer: This is not meant to in any way endorse violating AUPs. http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about getmtime
On Feb 19, 10:06 am, MRAB pyt...@mrabarnett.plus.com wrote: Brandon wrote: Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? The modification time of a copied file should be the same as the original. The creation time of a copied file will be the time at which it was copied, so that can result in the paradoxical state of a file having been modified _before_ it was created! :-) ctime does not stand for creation time. I went through this a couple of months ago. It's updated whenever the inode is updated, so changing permissions, among other things will update it. It blew me away when I finally found this out. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
ActiveState/O'Reilly Launch New and Improved Code Share Site (Python)
ActiveState launched today the new code.activestate.com with code recipes for dynamic languages such as Python, Perl and Tcl and web development. This site is great recipe sharing site for all Python, Perl and Tcl developers. O'Reilly will be use recipes from the site for its next Python cook book. Bit.ly link to the blog announcement: http://bit.ly/b1Wkdm -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On 02/19/10 21:48, MattB wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. The strangest thing about this is that firefox still works flawlessly on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). Any suggestions would be greatly appreciated. Matt Google a bit around how you can figure out (from inside your script) whether your used platform has a proxy configured and how to use it with your application. Good luck! -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about getmtime
Sean DiZazzo wrote: On Feb 19, 10:06 am, MRAB pyt...@mrabarnett.plus.com wrote: Brandon wrote: Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? The modification time of a copied file should be the same as the original. The creation time of a copied file will be the time at which it was copied, so that can result in the paradoxical state of a file having been modified _before_ it was created! :-) ctime does not stand for creation time. I went through this a couple of months ago. It's updated whenever the inode is updated, so changing permissions, among other things will update it. It blew me away when I finally found this out. On Windows ctime doesn't change when the file permissions are changed. -- http://mail.python.org/mailman/listinfo/python-list
Re: speed question, reading csv using takewhile() and dropwhile()
On Fri, Feb 19, 2010 at 1:58 PM, Vincent Davis vinc...@vincentdavis.netwrote: In reference to the several comments about [x for x in read] is basically a copy of the entire list. This isn't necessary. or list(read). I had thought I had a problem with having iterators in the takewhile() statement. I thought I testes and it didn't work. It seems I was wrong. It clearly works. I'll make this change and see if it is any better. I actually don't plan to read them all in at once, only as needed, but I do need the whole file in an array to perform some mathematics on them and compare different files. So my interest was in making it faster to open them as needed. I guess part of it is that they are about 5mb so I guess it might be disk speed in part.nks Record your numbers in an array and then work your magic on them later. Don't store the entire file in memory, though. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use python to register a service (an existing .exe file)
In article 4b79e28c$0$4610$426a7...@news.free.fr, News123 news...@free.fr wrote: Is there a python way to register new windows services. I am aware of the instsrv.exe program, which can be used to install services. I could use subprocess.Popen to call instsrv.exe service_name program.exe but wondered, whether there's already an existing function. Use the win32 package. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On Feb 19, 6:02 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: On 02/19/10 21:48, MattB wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. The strangest thing about this is that firefox still works flawlessly on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). Any suggestions would be greatly appreciated. Matt Google a bit around how you can figure out (from inside your script) whether your used platform has a proxy configured and how to use it with your application. Good luck! -- mph Hey all, I've used httpfox to identify the precise headers being sent by firefox, and then added them to my program using br.addheaders(), as per the proper mechanize syntax. No dice. (In fact, these headers were in the program when I ran it successfully from my friend's computer at his apartment). So I'm pretty sure it's not a header issue. I'll check and see whether firefox and my system are using a proxy. Also, based on Martin's comment, I just wanted to make you all aware that I intend no misuse, but rather am just trying to learn, as I'm a programming noob. I am not doing anything that I can't do myself from firefox (ie, I have an account at the school, and am allowed to sign on with my name and password and look up information in the student directory). If I do it for more than one student, it just becomes repetitive, so I thought this was a first modest goal in learning to do some programming.) That said, I'm happy to discontinue the attempts, but I'd like to know how it is that my computer (unless using firefox) is completely blocked from opening urls from within python. (And how to fix it). Thanks for the continued help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On Feb 19, 7:20 pm, MattB mattbar...@gmail.com wrote: On Feb 19, 6:02 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: On 02/19/10 21:48, MattB wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. The strangest thing about this is that firefox still works flawlessly on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). Any suggestions would be greatly appreciated. Matt Google a bit around how you can figure out (from inside your script) whether your used platform has a proxy configured and how to use it with your application. Good luck! -- mph Hey all, I've used httpfox to identify the precise headers being sent by firefox, and then added them to my program using br.addheaders(), as per the proper mechanize syntax. No dice. (In fact, these headers were in the program when I ran it successfully from my friend's computer at his apartment). So I'm pretty sure it's not a header issue. I'll check and see whether firefox and my system are using a proxy. Also, based on Martin's comment, I just wanted to make you all aware that I intend no misuse, but rather am just trying to learn, as I'm a programming noob. I am not doing anything that I can't do myself from firefox (ie, I have an account at the school, and am allowed to sign on with my name and password and look up information in the student directory). If I do it for more than one student, it just becomes repetitive, so I thought this was a first modest goal in learning to do some programming.) That said, I'm happy to discontinue the attempts, but I'd like to know how it is that my computer (unless using firefox) is completely blocked from opening urls from within python. (And how to fix it). Thanks for the continued help. Breakthrough: I tried switching from a wireless connection to my router, and instead used an ethernet connection -- and now everything works. Why would this make a difference? MAC address? Is it possible for an external server to see my MAC address and block it? Clearly wasn't an IP address issue! -- http://mail.python.org/mailman/listinfo/python-list
Looking for crossfold validation code
Hello, I am doing research as part of a Uni research Scholarship into using data compression for classification. What I am looking for is python code to handle the crossfold validation side of things for me - that will take my testing / training corpus and create the testing / training files after asking me for number of folds and number of times (or maybe allow me to enter a random seed or offset instead of times.) I could then either hook my classifier into the program or use it in a separate step. Probably not very hard to write, but why reinvent the wheel ;-) Thanks in advance, MarkL -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On Fri, Feb 19, 2010 at 5:06 PM, MattB mattbar...@gmail.com wrote: On Feb 19, 7:20 pm, MattB mattbar...@gmail.com wrote: On Feb 19, 6:02 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: On 02/19/10 21:48, MattB wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. The strangest thing about this is that firefox still works flawlessly on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). Any suggestions would be greatly appreciated. snip Breakthrough: I tried switching from a wireless connection to my router, and instead used an ethernet connection -- and now everything works. Why would this make a difference? MAC address? Is it possible for an external server to see my MAC address and block it? Clearly wasn't an IP address issue! If you're using the campus network and depending on the exact network details, yes, they very likely can know your MAC address and thus block it. Since your Wi-Fi card and Ethernet card have different hardware MAC addresses, yes, switching would change your visible MAC address, thus circumventing any blocks based on it. Cheers, Chris -- Hi ACMS! http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
the mystery of dirname()
In the following code sample : def dirname(p): Returns the directory component of a pathname i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == __main__: p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of if head and head != '/'*len(head): and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? Regards, ~l0nwlf -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
On Feb 19, 8:28 pm, Chris Rebert c...@rebertia.com wrote: On Fri, Feb 19, 2010 at 5:06 PM, MattB mattbar...@gmail.com wrote: On Feb 19, 7:20 pm, MattB mattbar...@gmail.com wrote: On Feb 19, 6:02 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: On 02/19/10 21:48, MattB wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. The strangest thing about this is that firefox still works flawlessly on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). Any suggestions would be greatly appreciated. snip Breakthrough: I tried switching from a wireless connection to my router, and instead used an ethernet connection -- and now everything works. Why would this make a difference? MAC address? Is it possible for an external server to see my MAC address and block it? Clearly wasn't an IP address issue! If you're using the campus network and depending on the exact network details, yes, they very likely can know your MAC address and thus block it. Since your Wi-Fi card and Ethernet card have different hardware MAC addresses, yes, switching would change your visible MAC address, thus circumventing any blocks based on it. Cheers, Chris -- Hi ACMS!http://blog.rebertia.com Chris, I'm using the network in my own apartment. Not the campus's. Moreover, my mac's MAC address is different from the MAC address shown by my router, but as I said I'm also blocked when using my friend's wireless router at his apartment. So it must be my mac's MAC, and not the router's MAC, that's being blocked, right? But ALSO -- is it my ISP that's blocking the mac's MAC (and not the school), since I can't raise ANY url's from python when I'm on wireless? -- http://mail.python.org/mailman/listinfo/python-list
Capturing errors raised by other scripts ?
I'm using the subroutine module to run run python script A.py from B.py (this is on windows fwiw). A.py is not my script and it may raise arbitary errors before exiting. How can I determine what's happened before A.py exited ? To simulate this I've got this script (which is meant to simulate A.py): class customError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) try: raise customError(2*2) except customError as e: print 'Custom exception occurred, value:', e.value I then run my A.py like this : fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') try: ... pathtojob=python.exe A.py ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) ... except: ... print bad stuff happened ... When I do this I the exception handler is not fired and the text Custom exception occurred, value: 4 ends up in the stdout file. I'd really like it to end up in stderr because then I could say anything in stderr ? then ignore the output and flag an error. I don't want to have to parse the stdout for error like messages and I can't make changes to A.py. I'm sure there's a better way to do this - can anyone offer some advice ? thanks Richard. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't Access ANY url from python (errno 61)
try this : url = 'http://www.google.com' proxy = {'http': 'http://username:passw...@proxy:port'} content = urllib.urlopen(url, proxies = proxy).read() Hopefully it should run without error. Second approach can be to check whether your environment variables are setup. $set will show you. If not the case set up your environment variable. HTH, ~l0nwlf On Sat, Feb 20, 2010 at 8:02 AM, MattB mattbar...@gmail.com wrote: On Feb 19, 8:28 pm, Chris Rebert c...@rebertia.com wrote: On Fri, Feb 19, 2010 at 5:06 PM, MattB mattbar...@gmail.com wrote: On Feb 19, 7:20 pm, MattB mattbar...@gmail.com wrote: On Feb 19, 6:02 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: On 02/19/10 21:48, MattB wrote: Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. The strangest thing about this is that firefox still works flawlessly on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). Any suggestions would be greatly appreciated. snip Breakthrough: I tried switching from a wireless connection to my router, and instead used an ethernet connection -- and now everything works. Why would this make a difference? MAC address? Is it possible for an external server to see my MAC address and block it? Clearly wasn't an IP address issue! If you're using the campus network and depending on the exact network details, yes, they very likely can know your MAC address and thus block it. Since your Wi-Fi card and Ethernet card have different hardware MAC addresses, yes, switching would change your visible MAC address, thus circumventing any blocks based on it. Cheers, Chris -- Hi ACMS!http://blog.rebertia.com Chris, I'm using the network in my own apartment. Not the campus's. Moreover, my mac's MAC address is different from the MAC address shown by my router, but as I said I'm also blocked when using my friend's wireless router at his apartment. So it must be my mac's MAC, and not the router's MAC, that's being blocked, right? But ALSO -- is it my ISP that's blocking the mac's MAC (and not the school), since I can't raise ANY url's from python when I'm on wireless? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: the mystery of dirname()
Shashwat Anand wrote: In the following code sample : def dirname(p): Returns the directory component of a pathname i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == __main__: p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of if head and head != '/'*len(head): and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? What if the path is '//x'? The current dirname would return '//', whereas dirname1 would return ''. -- http://mail.python.org/mailman/listinfo/python-list
Re: the mystery of dirname()
But this is posixpath, right ? So '//x' like path will not occur as far as I guess ? On Sat, Feb 20, 2010 at 8:35 AM, MRAB pyt...@mrabarnett.plus.com wrote: Shashwat Anand wrote: In the following code sample : def dirname(p): Returns the directory component of a pathname i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == __main__: p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of if head and head != '/'*len(head): and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? What if the path is '//x'? The current dirname would return '//', whereas dirname1 would return ''. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Capturing errors raised by other scripts ?
northof40 wrote: I'm using the subroutine module to run run python script A.py from B.py (this is on windows fwiw). A.py is not my script and it may raise arbitary errors before exiting. How can I determine what's happened before A.py exited ? To simulate this I've got this script (which is meant to simulate A.py): class customError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) try: raise customError(2*2) except customError as e: print 'Custom exception occurred, value:', e.value I then run my A.py like this : fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') try: ... pathtojob=python.exe A.py ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) ... except: ... print bad stuff happened ... When I do this I the exception handler is not fired and the text Custom exception occurred, value: 4 ends up in the stdout file. I'd really like it to end up in stderr because then I could say anything in stderr ? then ignore the output and flag an error. I don't want to have to parse the stdout for error like messages and I can't make changes to A.py. I'm sure there's a better way to do this - can anyone offer some advice ? thanks A.py is printing the error message. The 'print' statement prints to stdout unless you direct it elsewhere with '', for example: print my_file, 'message' If you don't want error messages to go to stdout, then don't print them to stdout, it's as simple as that! -- http://mail.python.org/mailman/listinfo/python-list
Re: the mystery of dirname()
Shashwat Anand wrote: But this is posixpath, right ? So '//x' like path will not occur as far as I guess ? Can you guarantee that? It's safer to just leave it as it is, just in case! :-) On Sat, Feb 20, 2010 at 8:35 AM, MRAB pyt...@mrabarnett.plus.com mailto:pyt...@mrabarnett.plus.com wrote: Shashwat Anand wrote: In the following code sample : def dirname(p): Returns the directory component of a pathname i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == __main__: p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of if head and head != '/'*len(head): and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? What if the path is '//x'? The current dirname would return '//', whereas dirname1 would return ''. -- http://mail.python.org/mailman/listinfo/python-list
Re: the mystery of dirname()
basically I infer that : dirname = path - basename, like for path = '//x', basename = x, hence dirname = '//' On Sat, Feb 20, 2010 at 8:47 AM, MRAB pyt...@mrabarnett.plus.com wrote: Shashwat Anand wrote: But this is posixpath, right ? So '//x' like path will not occur as far as I guess ? Can you guarantee that? It's safer to just leave it as it is, just in case! :-) On Sat, Feb 20, 2010 at 8:35 AM, MRAB pyt...@mrabarnett.plus.commailto: pyt...@mrabarnett.plus.com wrote: Shashwat Anand wrote: In the following code sample : def dirname(p): Returns the directory component of a pathname i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == __main__: p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of if head and head != '/'*len(head): and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? What if the path is '//x'? The current dirname would return '//', whereas dirname1 would return ''. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Avoid converting functions to methods in a class
I have a convention when writing unit tests to put the target of the test into a class attribute, as follows: class MyTest(unittest.TestCase): target = mymodule.someclass def test_spam(self): Test that someclass has a spam attribute. self.failUnless(hasattr(self.target, 'spam')) It works well until I write a test for stand-alone functions: class AnotherTest(unittest.TestCase): target = mymodule.function def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') The problem is that target is turned into a method of my test class, not a standalone function, and I get errors like: TypeError: function() takes exactly 2 arguments (3 given) The solution I currently use is to drop the target attribute in this class, and just refer to mymodule.function in each individual test. I don't like this solution because it violates Once And Only Once: if the function changes name, I have to make many edits to the test suite rather than just one. Are there any better solutions? -- Steven -- http://mail.python.org/mailman/listinfo/python-list