Re: [Python-ideas] allow line break at operators
Yingjie Lan writes: > Have you considered line continuation by indentation? It seems to > meet the design principle. I think it is the most natural way to > allow free line breaking in Python. Briefly, yes, and I think it would need a lot of tuning and probably complex rules. Unlike statements, where everybody (except the judges of the Obfuscated C Contest) agrees on a simple rule: "In a control structure, the controlled suite should be uniformly indented one level", line breaking and indentation of long expressions is an art, and people have different opinions on "readability" and "beauty." Achieving a compromise that is workable even for a few major styles is likely to be annoying and bug-prone. Pretty much every program I write seems to have a continued list of data or a multi-line dictionary display as data. It's not unusual for me to comment the formal arguments in a function definition, or the parent classes of a class definition. The exception for parenthesized objects is something I depend on for what I consider good style. Of course I could use explicit continuation, but in a long table that's ugly and error-prone. Long expressions that need to be broken across lines, on the other hand, often indication that I haven't thought carefully enough about that component of the program, and an extra pair of parentheses or a terminal backslash just isn't that "heavy" or ugly in the context of such long expressions. For me, they're also pretty rare; many programs I write have no explicit continuations in them at all. YMMV, of course, but I find the compromise that Python arrived at to be very useful, and I must suppose that it was substantially easier to implement than "fully free" line breaking (whatever that means to you). -- http://mail.python.org/mailman/listinfo/python-list
Re: json in python 2.5
On Fri, Sep 2, 2011 at 10:36 PM, Vineet Deodhar wrote: >> e.g., I have this list: >> L = ['spam', 'ham', 'eggs', 12, (13.63)] >> What is the correct way to convert L to javascript array format? > Python likewise has a JSON module in the std lib: > http://docs.python.org/library/json.html > > I tried with json in std lib. > But it is included in python 2.6 onwards. > For my current proj, I need to use python 2.5. > Hence can't use json from the std lib. > Any idea on converting list to json in python 2.5? http://pypi.python.org/pypi/simplejson/ Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
json in python 2.5
> e.g., I have this list: > L = ['spam', 'ham', 'eggs', 12, (13.63)] > What is the correct way to convert L to javascript array format? > 1) jsonify the list and pass it to javascript > (whether json format & javascript array are similar?) JSON is in fact a subset of JavaScript, and modern browsers now include a specific API for parsing and generating it (https://developer.mozilla.org/En/Using_native_JSON ). = @Chris, thanks for the pointer on parsing json. = Python likewise has a JSON module in the std lib: http://docs.python.org/library/json.html I tried with json in std lib. But it is included in python 2.6 onwards. For my current proj, I need to use python 2.5. Hence can't use json from the std lib. Any idea on converting list to json in python 2.5? = Thanks, Vineet -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms Library - Asking for Pointers
In article <18fe4afd-569b-4580-a629-50f6c7482...@c29g2000yqd.googlegroups.com> Travis Parks wrote: >[Someone] commented that the itertools algorithms will perform >faster than the hand-written ones. Are these algorithms optimized >internally? They are written in C, so avoid a lot of CPython interpreter overhead. Mileage in Jython, etc., may vary... -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 with context manager
On Fri, Sep 2, 2011 at 12:43 PM, Tim Arnold wrote: > Hi, > I'm using the 'with' context manager for a sqlite3 connection: > > with sqlite3.connect(my.database,timeout=10) as conn: > conn.execute('update config_build set datetime=?,result=? > where id=?', > (datetime.datetime.now(), success, > self.b['id'])) > > my question is what happens if the update fails? Shouldn't it throw an > exception? That depends on why it fails. If you pass in an id that doesn't exist in the database, it "successfully" updates 0 rows. I would guess that's what happened here. You should check cursor.rowcount after running the update query to make sure it actually did something. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] allow line break at operators
Guido van Rossum writes: > On Fri, Sep 2, 2011 at 12:28 AM, Stephen J. Turnbull > wrote: > > Sure, but IIRC one design principle of Python is that the keyword that > > denotes the syntax should be the first thing on the line, [...] > That's true for *statements* (except assignments and calls). > > > Analogously, if operators are going to denote continuation, they > > should come first on the line. > That doesn't follow. Agreed, it's not a logical implication. The analogy is only an analogy, but my eyes do work that way. My conclusion is that we shouldn't try to encourage either style, because people "see" continuation differently. Legislating a style isn't going to change that, I think. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] allow line break at operators
Have you considered line continuation by indentation? It seems to meet the design principle. I think it is the most natural way to allow free line breaking in Python. (Sorry, the yahoo web email interface is so weird that I don't know how to format comments between the quoted message below.) > >From: Stephen J. Turnbull >To: Gabriel AHTUNE >Cc: Matt Joiner ; "python-list@python.org" >; python-ideas ; Yingjie Lan > >Sent: Friday, September 2, 2011 3:28 PM >Subject: Re: [Python-ideas] allow line break at operators > >Gabriel AHTUNE writes: >> So can be done with this syntax: >> >> > x = firstpart * secondpart + #line breaks here >> > anotherpart + #continue >> > stillanother #continue on. >> >> after a "+" operator the line is clearly not finished yet. > >Sure, but IIRC one design principle of Python is that the keyword that >denotes the syntax should be the first thing on the line, making it >easy to scan down the left side of the code to see the syntactic >structure. The required indentation of the controlled suite also >helps emphasize that keyword. > >Analogously, if operators are going to denote continuation, they >should come first on the line. > > > >I just don't think this idea is going anywhere. Explicit continuation >with backslash or implicit continuation of parenthesized expressions >is just not that heavy a price to pay. Perhaps historically some of >these ideas could have been implemented, but now they're just going to >confuse a host of editors and code analysis tools. > >-- http://mail.python.org/mailman/listinfo/python-list
sqlite3 with context manager
Hi, I'm using the 'with' context manager for a sqlite3 connection: with sqlite3.connect(my.database,timeout=10) as conn: conn.execute('update config_build set datetime=?,result=? where id=?', (datetime.datetime.now(), success, self.b['id'])) my question is what happens if the update fails? Shouldn't it throw an exception? I ask because apparently something went wrong yesterday and the code never updated but I never got any warning. I rebooted the machine and everything is okay now, but I'd like to understand what happened. thanks, --Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms Library - Asking for Pointers
On Fri, Sep 2, 2011 at 6:39 PM, Travis Parks wrote: > You commented that the itertools algorithms will perform faster than > the hand-written ones. Are these algorithms optimized internally? For one thing, they are written in C. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension timing difference.
t...@thsu.org writes: > On Sep 2, 9:54 am, Bart Kastermans wrote: >> if d(a,b) == 1 and a < b: > > It will probably be faster if you reverse the evaluation order of that > expression. > > if a > That way the d() function is called less than half the time. Of course > this assumes that a that's true for your example. > -- > // T.Hsu Indeed makes quite a difference, goes from 275 seconds down to 153 seconds. -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms Library - Asking for Pointers
On Sep 2, 6:49 pm, Travis Parks wrote: > On Sep 2, 4:09 pm, Ian Kelly wrote: > > > > > > > On Fri, Sep 2, 2011 at 10:59 AM, Travis Parks > > wrote: > > > Hello: > > > > I am working on an algorithms library. It provides LINQ like > > > functionality to Python iterators. Eventually, I plan on having > > > feaures that work against sequences and mappings. > > > > I have the code up athttp://code.google.com/p/py-compass. > > > > This is my first project in Python, so I'd like some feedback. I want > > > to know if I am following conventions (overall style and quality of > > > code). > > > Sure, here are my comments. > > > In the "forever" and "__forever" functions, your use of the term > > "generator" is confusing. "__forever" is a generator function, > > because it has a yield statement. Its argument, called "generator", > > appears to be a callable, not a generator or even necessarily a > > generator function. Also, note that __forever(lambda: value) is > > functionally equivalent to the more efficient itertools.repeat(value). > > > The staticmethod __next(iterator) accesses the class it is defined in, > > which suggests that it might be better written as a classmethod > > __next(cls, iterator). > > > Each of the LINQ-style methods is divided into two parts: the public > > method that contains the docstring and some argument checks, and a > > private staticmethod that contains the implementation. I'm not > > certain what the purpose of that is. If it's to facilitate overriding > > the implementation in subclasses, then you need to change the names of > > the private methods to start with only one _ character so that they > > won't be mangled by the compiler. > > > The comments before each method that only contain the name of the > > immediately following method are redundant. > > > aggregate: the default aggregator is unintuitive to me. I would make > > it a required field and add a separate method called sum that calls > > aggregate with the operator.add aggregator. > > Also, the implementation doesn't look correct. Instead of passing in > > each item to the aggregator, you're passing in the number of items > > seen so far? The LINQ Aggregate method is basically reduce, so rather > > than reinvent the wheel I would suggest this: > > > # MISSING is a unique object solely defined to represent missing arguments. > > # Unlike None we can safely assume it will never be passed as actual data. > > MISSING = object() > > > def aggregate(self, aggregator, seed=MISSING): > > if seed is self.MISSING: > > return reduce(aggregator, self._iterable) > > else: > > return reduce(aggregator, self._iterable, seed) > > > Note for compatibility that in Python 3 the reduce function has been > > demoted from a builtin to a member of the functools module. > > > any: the name of this method could cause some confusion with the "any" > > builtin that does something a bit different. > > > compare: the loop would more DRY as a for loop: > > > def __compare(first, second, comparison): > > for firstval, secondval in itertools.izip_longest(first, second, > > fillvalue=self.MISSING): > > if firstval is self.MISSING: > > return -1 > > elif secondval is self.MISSING: > > return 1 > > else: > > result = comparison(firstval, secondval) > > if result != 0: > > return result > > return 0 > > > concatenate: again, no need to reinvent the wheel. This should be > > more efficient: > > > def concatenate(self, other): > > return extend(itertools.chain(self.__iterable, other)) > > > equals: could be just "return self.compare(other, comparison) == 0" > > > __last: the loop could be a for loop: > > > # assume we're looking at the last item and try moving to the next > > item = result.Value > > for item in iterator: pass > > return item > > > lastOrDefault: there's a lot of repeated logic here. This could just be: > > > def lastOrDefault(self, default=None): > > try: > > return self.last() > > except ValueError: > > return default > > > map / forEach: .NET has to separate these into separate methods due to > > static typing. It seems a bit silly to have both of them in Python. > > Also, map would be more efficient as "return itertools.imap(mapper, > > self.__iterable)" > > > max / min: it would be more efficient to use the builtin: > > def max(self, key): > > return max(self.__iterable, key=key) > > If somebody really needs to pass a comparison function instead of a > > key function, they can use functools.cmp_to_key. > > > randomSamples: a more canonical way to pass the RNG would be to pass > > an instance of random.Random rather than an arbitrary function. Then > > to get a random integer you can just call generator.randrange(total). > > Note that for the default you can just use the random module itself, > > which provides default implementations of all t
Re: Why doesn't threading.join() return a value?
In article Roy Smith wrote: >Thread.join() currently returns None, so there's >no chance for [return value] confusion. Well, still some actually. If you use my example code (posted elsethread), you need to know: - that there was a target function (my default return value if there is none is None); and - that the joined thread really did finish (if you pass a timeout value, rather than None, and the join times out, the return value is again None). Of course, if your target function always exists and never returns None, *then* there's no chance for confusion. :-) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
Chris Angelico wrote: Although I heard somewhere that that's more gimmick than guarantee, and that it IS possible for an app to hook CAD - just that it's a lot harder than building a simple window that looks like the login... And of course it's possible that someone has snuck in during the night and installed Linux on the machine, with a program that fakes a Windows login screen, with Ctrl-Alt-Delete and everything... -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
In article <5da6bf87-9412-46c4-ad32-f8337d56b...@o15g2000vbe.googlegroups.com>, Adam Skutt wrote: > On Sep 2, 10:53 am, Roy Smith wrote: > > I have a function I want to run in a thread and return a value. It > > seems like the most obvious way to do this is to have my target > > function return the value, the Thread object stash that someplace, and > > return it as the return value for join(). > > > Yes, I know there's other ways for a thread to return values (pass the > > target a queue, for example), but making the return value of the > > target function available would have been the most convenient. I'm > > curious why threading wasn't implemented this way. > > I assume it is because the underlying operating system APIs do not > support it. Windows and POSIX threads only support returning an > integer when a thread exits, similar to the exit code of a process. But the whole point of higher level languages is to hide the warts of the lower-level APIs they are built on top of. Just because a POSIX thread can only return an int (actually, a void *) doesn't mean that level of detail needed to be exposed at the Python threading library level. > More importantly, there's no way to tell whether the exit code of a > thread was set by user code or by the system. Even worse, some of > those integer values are reserved by some operating systems. If your > thread died via an exception, it still has an error code set by the > operating system. How would you going to distinguish those codes from > your own? I think you're talking about processes, not threads, but in any case, it's a non-sequitur. Thread.join() currently returns None, so there's no chance for confusion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`?
On Aug 30, 9:53 am, Michel Albert wrote: > Unfortunately this setup makes `logging.basicConfig` pretty useless. > However, I believe that this is something that more people could > benefit from. I also believe, that it just "makes sense" to send > warnings (and above) to `stderr`, the rest to `stdout`. > > So I was thinking: "Why does `logging.basicConfig` not behave that > way". Because what seems entirely natural and obvious to you might not seem so for someone else. The API in the stdlib tries to provide baseline functionality which others can build on. For example, if you always have a particular pattern which you use, you can always write a utility function to set things up exactly how you like, and others who want to set things up differently (for whatever reason) can do the same thing, without having to come into conflict (if that's not too strong a word) with views different from their own. > Naturally, I was thinking of writing a patch against the python > codebase and submit it as a suggestion. But before doing so, I would > like to hear your thoughts on this. Does it make sense to you too or > am I on the wrong track? Are there any downsides I am missing? Python 2.x is closed to feature changes, and Python 2.7 and Python 3.2 already support flexible configuration using dictConfig() - see http://docs.python.org/library/logging.config.html#logging.config.dictConfig Also, Python 3.3 will support passing a list of handlers to basicConfig(): see http://plumberjack.blogspot.com/2011/04/added-functionality-for-basicconfig-in.html which will allow you to do what you want quite easily. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms Library - Asking for Pointers
On Sep 2, 4:09 pm, Ian Kelly wrote: > On Fri, Sep 2, 2011 at 10:59 AM, Travis Parks wrote: > > Hello: > > > I am working on an algorithms library. It provides LINQ like > > functionality to Python iterators. Eventually, I plan on having > > feaures that work against sequences and mappings. > > > I have the code up athttp://code.google.com/p/py-compass. > > > This is my first project in Python, so I'd like some feedback. I want > > to know if I am following conventions (overall style and quality of > > code). > > Sure, here are my comments. > > In the "forever" and "__forever" functions, your use of the term > "generator" is confusing. "__forever" is a generator function, > because it has a yield statement. Its argument, called "generator", > appears to be a callable, not a generator or even necessarily a > generator function. Also, note that __forever(lambda: value) is > functionally equivalent to the more efficient itertools.repeat(value). > > The staticmethod __next(iterator) accesses the class it is defined in, > which suggests that it might be better written as a classmethod > __next(cls, iterator). > > Each of the LINQ-style methods is divided into two parts: the public > method that contains the docstring and some argument checks, and a > private staticmethod that contains the implementation. I'm not > certain what the purpose of that is. If it's to facilitate overriding > the implementation in subclasses, then you need to change the names of > the private methods to start with only one _ character so that they > won't be mangled by the compiler. > > The comments before each method that only contain the name of the > immediately following method are redundant. > > aggregate: the default aggregator is unintuitive to me. I would make > it a required field and add a separate method called sum that calls > aggregate with the operator.add aggregator. > Also, the implementation doesn't look correct. Instead of passing in > each item to the aggregator, you're passing in the number of items > seen so far? The LINQ Aggregate method is basically reduce, so rather > than reinvent the wheel I would suggest this: > > # MISSING is a unique object solely defined to represent missing arguments. > # Unlike None we can safely assume it will never be passed as actual data. > MISSING = object() > > def aggregate(self, aggregator, seed=MISSING): > if seed is self.MISSING: > return reduce(aggregator, self._iterable) > else: > return reduce(aggregator, self._iterable, seed) > > Note for compatibility that in Python 3 the reduce function has been > demoted from a builtin to a member of the functools module. > > any: the name of this method could cause some confusion with the "any" > builtin that does something a bit different. > > compare: the loop would more DRY as a for loop: > > def __compare(first, second, comparison): > for firstval, secondval in itertools.izip_longest(first, second, > fillvalue=self.MISSING): > if firstval is self.MISSING: > return -1 > elif secondval is self.MISSING: > return 1 > else: > result = comparison(firstval, secondval) > if result != 0: > return result > return 0 > > concatenate: again, no need to reinvent the wheel. This should be > more efficient: > > def concatenate(self, other): > return extend(itertools.chain(self.__iterable, other)) > > equals: could be just "return self.compare(other, comparison) == 0" > > __last: the loop could be a for loop: > > # assume we're looking at the last item and try moving to the next > item = result.Value > for item in iterator: pass > return item > > lastOrDefault: there's a lot of repeated logic here. This could just be: > > def lastOrDefault(self, default=None): > try: > return self.last() > except ValueError: > return default > > map / forEach: .NET has to separate these into separate methods due to > static typing. It seems a bit silly to have both of them in Python. > Also, map would be more efficient as "return itertools.imap(mapper, > self.__iterable)" > > max / min: it would be more efficient to use the builtin: > def max(self, key): > return max(self.__iterable, key=key) > If somebody really needs to pass a comparison function instead of a > key function, they can use functools.cmp_to_key. > > randomSamples: a more canonical way to pass the RNG would be to pass > an instance of random.Random rather than an arbitrary function. Then > to get a random integer you can just call generator.randrange(total). > Note that for the default you can just use the random module itself, > which provides default implementations of all the Random methods. > Also, for loops: > > def __randomSamples(iterable, sampleCount, generator): > samples = [] > iterator = iter(iterable) > # fill up the samples with the items from the beginning of the > i
Re: Why do class methods always need 'self' as the first parameter?
On Sep 2, 2:30 pm, Ian Kelly wrote: > On Fri, Sep 2, 2011 at 11:51 AM, John Roth wrote: > >> I don't see how you could get rid of the wrappers. Methods would > >> still need to be bound, somehow, so that code like this will work: > > >> methods = {} > >> for obj in objs: > >> if obj.is_flagged: > >> methods[obj.user_id] = obj.do_work > >> else: > >> methods[obj.user_id] = obj.do_other_work > >> # ... > >> methods[some_user_id]() > > >> Without method wrappers, how does the interpreter figure out which > >> instance is bound to the method being called? > > >> Cheers, > >> Ian > > > Good question. > > > Currently the instance wrapper is created during method instantiation, > > so the instance is obviously available at that point. There are two > > rather obvious ways of remembering it. One is to use the invocation > > stack, which has the instance. Another would be for the compiler to > > create a local variable for the instance and possibly the class and > > fill them in at instantiation time. Both of these require fixing the > > names "self" and "cls" so the compiler knows what to do with them. The > > first would require giving these two names their own bytecodes, the > > second makes them simple local variables the same as the ones in the > > method headers. The latter also allows them to be changed by the > > method, which is probably not the world's best programming practice > > although it's possible now. > > That's not what I asked. Both of those options are storing the > instance within a stack frame, once it's been called. I'm asking how > you would remember the instance during the interval from the time when > the method > is accessed until when it has been called. > > In the code above, the method is accessed just before it is stored in > the dictionary. That is when the method wrapper is currently created, > and the instance is available. It is not called until much later, > possibly not even within the same function. How would you remember > the instance over that period without wrapping the function? > > Cheers, > Ian I see what you're saying now - I didn't get your example the first time. So the optimization of eliminating the instance wrapper is only possible if it's retrieved via the instance and then called immediately. That would seem to be a useful optimization if it was possible - I wonder if PyPy is doing it since they've got that fancy JIT, and it would seem that an immediate call after retrieving the method is overwhelmingly more frequent than saving it for later. I think it's still true that calling the underlying function object through the instance wrapper requires remaking the parameter list, which seems to be another piece of unnecessary overhead, unless there's a fast path through the call machinery that treats the instance specially. It does, however, decouple the two issues so I can't claim the optimization as a benefit. Drat. John Roth -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
On Sep 2, 4:14 pm, Chris Torek wrote: > In article > Adam Skutt wrote: > > >No, it can only pass a void*, which isn't much better than passing an > >int. > > It is far better than passing an int, although it leaves you with > an annoying storage-management issue, and sidesteps any reasonable > attempts at type-checking (both of which are of course "par for > the course" in C). And when written out, makes it sound distinctly worse than passing an int :p. And let's not kid ourselves, unless you're a C programmer, it is distinctly worse than passing an int. Heck, your example (snipped) goes out of your way to unnecessarily leverage the functionality provided by pthreads. > Some manual pages are clearer about this than others. Here is one > that I think is not bad: > > The symbolic constant PTHREAD_CANCELED expands to a constant > expression of type (void *), whose value matches no pointer to > an object in memory nor the value NULL. > > So, provided you use pthread_exit() "correctly" (always pass either > NULL or the address of some actual object in memory), the special > reserved value is different from all of "your" values. Unfortunately, I'm not sure all implementations behave that way. Not that cancellation is really worth bothering with anyway, but it's a pretty nasty corner case. Adam -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On Sat, Sep 3, 2011 at 2:26 AM, Den wrote: > I've been doing some more thinking on what I want. This may be a > better explanation. Is there a way of detecting if my program has > lost "focus" (I'm not sure the correct term)? For example, if someone > is typing in my program, but some other program takes control (or CAD > has been pressed) I would like simply to log that. I have no interest > in trying to hijack or interfere with anything, simply log it. Ah, then yes most definitely! If you're writing a GUI program, a LostFocus event is a normal thing to be able to catch. Now, if you're writing a console program, that mightn't be so easy. But certainly you can detect loss of focus to any window that you control. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
Seebs wrote: > On 2011-09-02, Steven D'Aprano > wrote: [...] >> Because then the code launching the thread would have to block, waiting >> until the thread is completed, so it will have a result to return. > > Isn't "waiting until the thread is completed" sort of the point of join()? Doh! I mean, well done, you have passed my little test! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do class methods always need 'self' as the first parameter?
On Fri, Sep 2, 2011 at 11:51 AM, John Roth wrote: >> I don't see how you could get rid of the wrappers. Methods would >> still need to be bound, somehow, so that code like this will work: >> >> methods = {} >> for obj in objs: >> if obj.is_flagged: >> methods[obj.user_id] = obj.do_work >> else: >> methods[obj.user_id] = obj.do_other_work >> # ... >> methods[some_user_id]() >> >> Without method wrappers, how does the interpreter figure out which >> instance is bound to the method being called? >> >> Cheers, >> Ian > > Good question. > > Currently the instance wrapper is created during method instantiation, > so the instance is obviously available at that point. There are two > rather obvious ways of remembering it. One is to use the invocation > stack, which has the instance. Another would be for the compiler to > create a local variable for the instance and possibly the class and > fill them in at instantiation time. Both of these require fixing the > names "self" and "cls" so the compiler knows what to do with them. The > first would require giving these two names their own bytecodes, the > second makes them simple local variables the same as the ones in the > method headers. The latter also allows them to be changed by the > method, which is probably not the world's best programming practice > although it's possible now. That's not what I asked. Both of those options are storing the instance within a stack frame, once it's been called. I'm asking how you would remember the instance during the interval from the time when the method is accessed until when it has been called. In the code above, the method is accessed just before it is stored in the dictionary. That is when the method wrapper is currently created, and the instance is available. It is not called until much later, possibly not even within the same function. How would you remember the instance over that period without wrapping the function? Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling 2.7 and 3.0 Versions of Dict
En Fri, 02 Sep 2011 13:53:37 -0300, Travis Parks escribió: On Sep 2, 12:36 pm, "Gabriel Genellina" wrote: En Wed, 31 Aug 2011 22:28:09 -0300, Travis Parks escribi : > On Aug 31, 7:37 pm, Gregory Ewing wrote: >> Ian Kelly wrote: >> > if sys.version_info < (3,): >> > getDictValues = dict.itervalues >> > else: >> > getDictValues = dict.values >> > (which is basically what the OP was doing in the first place). > My problem was that I didn't understand the scoping rules. It is still > strange to me that the getValues variable is still in scope outside > the if/else branches. Those if/else are at global scope. An 'if' statement does not introduce a new scope; so getDictValues, despite being "indented", is defined at global scope, and may be used anywhere in the module. Does that mean the rules would be different inside a function? Yes: a function body *does* create a new scope, as well as the class statement. See http://docs.python.org/reference/executionmodel.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling 2.7 and 3.0 Versions of Dict
On 9/2/2011 12:53 PM, Travis Parks wrote: On Sep 2, 12:36 pm, "Gabriel Genellina" Those if/else are at global scope. An 'if' statement does not introduce a new scope; so getDictValues, despite being "indented", is defined at global scope, and may be used anywhere in the module. Does that mean the rules would be different inside a function? Yes. Inside a function, you would have to add global getDictValues before the if statement in order for the assignments to have global effect. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
>On Sep 2, 2:23 pm, Alain Ketterlin >wrote: >> Sorry, you're wrong, at least for POSIX threads: >> >> void pthread_exit(void *value_ptr); >> int pthread_join(pthread_t thread, void **value_ptr); >> >> pthread_exit can pass anything, and that value will be retrieved with >> pthread_join. In article Adam Skutt wrote: >No, it can only pass a void*, which isn't much better than passing an >int. It is far better than passing an int, although it leaves you with an annoying storage-management issue, and sidesteps any reasonable attempts at type-checking (both of which are of course "par for the course" in C). For instance: struct some_big_value { ... lots of stuff ... }; struct some_big_value storage_management_problem[SIZE]; ... void *func(void *initial_args) { ... #ifdef ONE_WAY_TO_DO_IT pthread_exit(&storage_management_problem[index]); /* NOTREACHED */ #else /* the other way */ return &storage_management_problem[index]; #endif } ... int error; pthread_t threadinfo; pthread_attr_t attr; ... pthread_attr_init(&attr); /* set attributes if desired */ error = pthread_create(&threadinfo, &attr, func, &args_to_func); if (error) { ... handle error ... } else { ... void *rv; result = pthread_join(&threadinfo, &rv); if (rv == PTHREAD_CANCELED) { ... the thread was canceled ... } else { struct some_big_value *ret = rv; ... work with ret->field ... } } (Or, do dynamic allocation, and have a struct with a distinguishing ID followed by a union of multiple possible values, or a flexible array member, or whatever. This means you can pass any arbitrary data structure back, provided you can manage the storage somehow.) >Passing a void* is not equivalent to passing anything, not even >in C. Moreover, specific values are still reserved, like >PTHREAD_CANCELLED. Some manual pages are clearer about this than others. Here is one that I think is not bad: The symbolic constant PTHREAD_CANCELED expands to a constant expression of type (void *), whose value matches no pointer to an object in memory nor the value NULL. So, provided you use pthread_exit() "correctly" (always pass either NULL or the address of some actual object in memory), the special reserved value is different from all of "your" values. (POSIX threads are certainly klunky, but not all *that* badly designed given the constraints.) >>Re. the original question: since you can define your own Thread >>subclass, with wathever attribute you want, I guess there was no need to >>use join() to communicate the result. The Thread's run() can store its >>result in an attribute, and the "client" can get it from the same >>attribute after a successful call to join(). For that matter, you can use the following to get what the OP asked for. (Change all the instance variables to __-prefixed versions if you want them to be Mostly Private.) import threading class ValThread(threading.Thread): "like threading.Thread, but the target function's return val is captured" def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None): super(ValThread, self).__init__(group, None, name, None, None, verbose) self.value = None self.target = target self.args = args self.kwargs = {} if kwargs is None else kwargs def run(self): "run the thread" if self.target: self.value = self.target(*self.args, **self.kwargs) def join(self, timeout = None): "join, then return value set by target function" super(ValThread, self).join(timeout) return self.value -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms Library - Asking for Pointers
On Fri, Sep 2, 2011 at 10:59 AM, Travis Parks wrote: > Hello: > > I am working on an algorithms library. It provides LINQ like > functionality to Python iterators. Eventually, I plan on having > feaures that work against sequences and mappings. > > I have the code up at http://code.google.com/p/py-compass. > > This is my first project in Python, so I'd like some feedback. I want > to know if I am following conventions (overall style and quality of > code). Sure, here are my comments. In the "forever" and "__forever" functions, your use of the term "generator" is confusing. "__forever" is a generator function, because it has a yield statement. Its argument, called "generator", appears to be a callable, not a generator or even necessarily a generator function. Also, note that __forever(lambda: value) is functionally equivalent to the more efficient itertools.repeat(value). The staticmethod __next(iterator) accesses the class it is defined in, which suggests that it might be better written as a classmethod __next(cls, iterator). Each of the LINQ-style methods is divided into two parts: the public method that contains the docstring and some argument checks, and a private staticmethod that contains the implementation. I'm not certain what the purpose of that is. If it's to facilitate overriding the implementation in subclasses, then you need to change the names of the private methods to start with only one _ character so that they won't be mangled by the compiler. The comments before each method that only contain the name of the immediately following method are redundant. aggregate: the default aggregator is unintuitive to me. I would make it a required field and add a separate method called sum that calls aggregate with the operator.add aggregator. Also, the implementation doesn't look correct. Instead of passing in each item to the aggregator, you're passing in the number of items seen so far? The LINQ Aggregate method is basically reduce, so rather than reinvent the wheel I would suggest this: # MISSING is a unique object solely defined to represent missing arguments. # Unlike None we can safely assume it will never be passed as actual data. MISSING = object() def aggregate(self, aggregator, seed=MISSING): if seed is self.MISSING: return reduce(aggregator, self._iterable) else: return reduce(aggregator, self._iterable, seed) Note for compatibility that in Python 3 the reduce function has been demoted from a builtin to a member of the functools module. any: the name of this method could cause some confusion with the "any" builtin that does something a bit different. compare: the loop would more DRY as a for loop: def __compare(first, second, comparison): for firstval, secondval in itertools.izip_longest(first, second, fillvalue=self.MISSING): if firstval is self.MISSING: return -1 elif secondval is self.MISSING: return 1 else: result = comparison(firstval, secondval) if result != 0: return result return 0 concatenate: again, no need to reinvent the wheel. This should be more efficient: def concatenate(self, other): return extend(itertools.chain(self.__iterable, other)) equals: could be just "return self.compare(other, comparison) == 0" __last: the loop could be a for loop: # assume we're looking at the last item and try moving to the next item = result.Value for item in iterator: pass return item lastOrDefault: there's a lot of repeated logic here. This could just be: def lastOrDefault(self, default=None): try: return self.last() except ValueError: return default map / forEach: .NET has to separate these into separate methods due to static typing. It seems a bit silly to have both of them in Python. Also, map would be more efficient as "return itertools.imap(mapper, self.__iterable)" max / min: it would be more efficient to use the builtin: def max(self, key): return max(self.__iterable, key=key) If somebody really needs to pass a comparison function instead of a key function, they can use functools.cmp_to_key. randomSamples: a more canonical way to pass the RNG would be to pass an instance of random.Random rather than an arbitrary function. Then to get a random integer you can just call generator.randrange(total). Note that for the default you can just use the random module itself, which provides default implementations of all the Random methods. Also, for loops: def __randomSamples(iterable, sampleCount, generator): samples = [] iterator = iter(iterable) # fill up the samples with the items from the beginning of the iterable for i, value in zip(xrange(sampleCount), iterator): samples.append(value) # replace items if the generated number is less than the total total = len(samples) for value in iterator: total +
Re: Invoking profile from command line prevent my sys.path modification
En Thu, 01 Sep 2011 07:51:43 -0300, Yaşar Arabacı escribió: I am new to profile module, so I am sorry if this is an absolute beginner question. In order to my code to run, I need to add a directory to sys.path. When I invole python -m profile myfile.py, my code won't work, saying that the thing that is supposed to be in path, isn't. Code works fine without profiling. Profiling works if I write it into the file, but I don't prefer doing that, if that is possible. You may set the PYTHONPATH environment variable, just for the profiling session. http://docs.python.org/install/index.html#modifying-python-s-search-path -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: idiomatic analogue of Perl's: while (<>) { ... }
Dennis Lee Bieber wrote: On Thu, 1 Sep 2011 00:56:50 -0400, Sahil Tandon # process input, line-by-line, and print responses after parsing input while 1: rval = parse(raw_input()) if rval == None: There is only ONE "None" object so the preferred method is if rval is None: Understood; thanks for that enlightenment. Note: I don't see any exit handler/condition... Indeed. I excluded such things in the interest of brevity, to focus the discussion on my question. :) -- Sahil Tandon -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] allow line break at operators
On Fri, Sep 2, 2011 at 12:28 AM, Stephen J. Turnbull wrote: > Gabriel AHTUNE writes: > > So can be done with this syntax: > > > > > x = firstpart * secondpart + #line breaks here > > > anotherpart + #continue > > > stillanother #continue on. > > > > after a "+" operator the line is clearly not finished yet. > > Sure, but IIRC one design principle of Python is that the keyword that > denotes the syntax should be the first thing on the line, making it > easy to scan down the left side of the code to see the syntactic > structure. The required indentation of the controlled suite also > helps emphasize that keyword. That's true for *statements* (except assignments and calls). > Analogously, if operators are going to denote continuation, they > should come first on the line. That doesn't follow. My preferred style is actually to put the binary operator at the end of the line. This also matches the prevailing style for breaking lines after commas (a comma can be seen as a kind of binary operator). > I just don't think this idea is going anywhere. Explicit continuation > with backslash or implicit continuation of parenthesized expressions > is just not that heavy a price to pay. Perhaps historically some of > these ideas could have been implemented, but now they're just going to > confuse a host of editors and code analysis tools. Totally agreed that this isn't going to happen. -- --Guido van Rossum (python.org/~guido) -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
wrote in message news:mailman.703.1314969082.27778.python-l...@python.org... > Hi Fokke, > > Disclaimer: I have no experience with the Python WebDAV package you're > using. > > But a thought: > >> In the config file it says: >> "# main directory >> directory = \Webdav" > > Perhaps you should qualify your directory path with a drive letter? > > I would try this 2 ways: > > directory = E:\Webdav > > And if that doesn't work: > > directory = E:/Webdav > > My thinking about the 2nd example is that perhaps the \W is getting > interpreted as a control character vs. "backslash" "W". > I tried: directory=D:\Webdav directory=D:/Webdav To no avail. It didn't make any difference. I surely believe my WebDAV installation is at fault. And D: is the same partition as where Python is, D:\Python27 Fokke -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
"becky_lewis" wrote in message news:86b084e0-09a8-4997-9e0c-4526d7851...@s2g2000vby.googlegroups.com... On Sep 2, 1:19 pm, "Fokke Nauta" wrote: > "Dennis Lee Bieber" wrote in > messagenews:mailman.687.1314941410.27778.python-l...@python.org... > > > On Thu, 1 Sep 2011 12:30:43 +0200, "Fokke Nauta" > > declaimed the following in > > gmane.comp.python.general: > > >> "Dennis Lee Bieber" wrote in message > >>news:mailman.643.1314851358.27778.python-l...@python.org... > > >> > Next, if you'd read further and didn't take the comment as the > >> > instruction. set > >> > firstrun=1 > > >> I did > > >> > to tell the server this is the first time it is being run - IT WILL > >> > create the database table (after the first start, reset the flag to 0 > >> > to > >> > speed up later runs). > > >> It didn't create the table. The database kept empty. > > > Odd -- but then, I'm not running it myself, and wasn't up to reading > > all the code to see what path it takes. > > It's only for experimenting with calendar software, so authorization is > not > a point. > So I forget about MySQL. > >> > Later in the config file set > >> > mysql_auth=1 > >> > to enable the use of MySQL, and set the admin user/password to what > >> > you > >> > plan to have it use. > > >> I did > > >> > You probably want to set > >> > daemonize=1 > >> > (maybe after first run) > > >> I left this to 0. > > >> > Oh, and don't forget to set the main data directory and any > >> > port/host changes. > > >> I left host and port as they were. The main directory is e:\wwwroot > > >> > Start the server - it should connect to MySQL, create the table, and > >> > add the admin user to the table. > > >> I started the server with server.py (in > >> D:\Python27\WebDAV\PyWebDAV\DAVServer) -D e:/wwwroot -m -c config.ini > > > If the main directory is already in the config file, you probably > > don't need to specify it on the command line... > > OK > > > And... could there be > > something in the code where overriding the directory by command line > > changes where it looks for the config file? (Just guessing at this > > point). > > Possibly. > I tried this: > server.py -n -c config.ini > Once again, the server is up and running and when I am logging in with my > browser (10.0.0.140:8081) I can see information showing up at the command > prompt, showing somebody is logging is, but the same error: > "fshandler:get_data: \Webdav not found". During starting up the server > mentioned: "pywebdav:Serving data from \Webdav". > > In the config file it says: > "# main directory > directory = \Webdav" > > Perhaps my Python configuration is at fault. > > Fokke Is the path supposed to be absolute? In which case you'd need to have: directory=C:\path\to\Webdav instead of just directory=\Webdav I tried: directory=D:\Webdav directory=D:/Webdav To no avail. It didn.t make any difference. I surely believe my WebDAV installation is at fault. Fokke -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
"Dennis Lee Bieber" wrote in message news:mailman.711.1314983727.27778.python-l...@python.org... > On Fri, 2 Sep 2011 14:19:32 +0200, "Fokke Nauta" > declaimed the following in > gmane.comp.python.general: > > >> >> In the config file it says: >> "# main directory >> directory = \Webdav" >> > I think that's the line that should have your e:/wwwroot > specification > -- Sorry! It used to have. But as it did not work, with the same error message, it could not find E:\wwwroot, I changed it into \Webdav. Ofcourse, in the command line as well. Later on I left the D specification out in the command line. Perhaps another drive letter might cause the problem, so in this case I kept it on the same partition. But I still got the same error. Fokke -- http://mail.python.org/mailman/listinfo/python-list
Re: Help required accessing dictionary
En Wed, 31 Aug 2011 22:46:54 -0300, escribió: I need to access the dictionary of the script that I am running through my vc++ application by embedding python. I am linking to python dynamically. I want to obtain the dictionary of the script and access the variables declared in the script. However, with the PyObject * that I get from the dictionary, I am not able to find the type of the object. The reason being that GetProcAddress to PyInt_Check returns a NULL. The same thing with PyFloat_Check and so on. I think this is because they are macros and not exported functions. What can be done to be able to perform these checks without statically linking to the pyhon lib ? Just include python.h PyInt_Check is completely implemented as a macro, it doesn't call any function. /* from intobject.h */ #define PyInt_Check(op) \ PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS) /* from object.h */ #define PyType_FastSubclass(t,f) PyType_HasFeature(t,f) #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
On Sep 2, 2:23 pm, Alain Ketterlin wrote: > Sorry, you're wrong, at least for POSIX threads: > > void pthread_exit(void *value_ptr); > int pthread_join(pthread_t thread, void **value_ptr); > > pthread_exit can pass anything, and that value will be retrieved with > pthread_join. No, it can only pass a void*, which isn't much better than passing an int. Passing a void* is not equivalent to passing anything, not even in C. Moreover, specific values are still reserved, like PTHREAD_CANCELLED. Yes, it was strictly inappropriate for me to say both return solely integers, but my error doesn't meaningful alter my description of the situation. The interface provided by the underlying APIs is not especially usable for arbitrary data transfer. Doubly so when we're discussing something like Python's threading module. > I'm not sure what you are talking about here. Maybe you confuse threads > with processes? Windows threads have exit codes, just like processes. At least one code is reserved and cannot be used by the programmer. Adam -- http://mail.python.org/mailman/listinfo/python-list
ANN: A new version (0.2.8) of the Python module which wraps GnuPG has been released.
A new version of the Python module which wraps GnuPG has been released. What Changed? = This is a minor enhancement and bug-fix release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. Summary: Better support for status messages from GnuPG. The fixing of some Unicode encoding problems. Quoted some command-line arguments to gpg for increased safety. The current version passes all tests on Windows (CPython 2.4, 2.5, 2.6, 3.1, 2.7 and Jython 2.5.1) and Ubuntu (CPython 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2). On Windows, GnuPG 1.4.11 has been used for the tests. What Does It Do? The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-BEGIN PGP MESSAGE-\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf ... -END PGP MESSAGE-\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' For more information, visit http://code.google.com/p/python-gnupg/ - as always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
Adam Skutt writes: > On Sep 2, 10:53 am, Roy Smith wrote: >> I have a function I want to run in a thread and return a value. It >> seems like the most obvious way to do this is to have my target >> function return the value, the Thread object stash that someplace, and >> return it as the return value for join(). >> > Yes, I know there's other ways for a thread to return values (pass the >> target a queue, for example), but making the return value of the >> target function available would have been the most convenient. I'm >> curious why threading wasn't implemented this way. > > I assume it is because the underlying operating system APIs do not > support it. Windows and POSIX threads only support returning an > integer when a thread exits, similar to the exit code of a process. Sorry, you're wrong, at least for POSIX threads: void pthread_exit(void *value_ptr); int pthread_join(pthread_t thread, void **value_ptr); pthread_exit can pass anything, and that value will be retrieved with pthread_join. Threads of a process share their address space, there is no reason to restrict their return value to an int. > More importantly, there's no way to tell whether the exit code of a > thread was set by user code or by the system. Even worse, some of > those integer values are reserved by some operating systems. I'm not sure what you are talking about here. Maybe you confuse threads with processes? Re. the original question: since you can define your own Thread subclass, with wathever attribute you want, I guess there was no need to use join() to communicate the result. The Thread's run() can store its result in an attribute, and the "client" can get it from the same attribute after a successful call to join(). -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do class methods always need 'self' as the first parameter?
On Sep 1, 8:26 am, Ian Kelly wrote: > On Thu, Sep 1, 2011 at 6:45 AM, John Roth wrote: > > I personally consider this to be a wart. Some time ago I did an > > implementation analysis. The gist is that, if self and cls were made > > special variables that returned the current instance and class > > respectively, then the compiler could determine whether a function was > > an instance or class method. If it then marked the code object > > appropriately you could get rid of all of the wrappers and the > > attendant run-time overhead. > > I don't see how you could get rid of the wrappers. Methods would > still need to be bound, somehow, so that code like this will work: > > methods = {} > for obj in objs: > if obj.is_flagged: > methods[obj.user_id] = obj.do_work > else: > methods[obj.user_id] = obj.do_other_work > # ... > methods[some_user_id]() > > Without method wrappers, how does the interpreter figure out which > instance is bound to the method being called? > > Cheers, > Ian Good question. Currently the instance wrapper is created during method instantiation, so the instance is obviously available at that point. There are two rather obvious ways of remembering it. One is to use the invocation stack, which has the instance. Another would be for the compiler to create a local variable for the instance and possibly the class and fill them in at instantiation time. Both of these require fixing the names "self" and "cls" so the compiler knows what to do with them. The first would require giving these two names their own bytecodes, the second makes them simple local variables the same as the ones in the method headers. The latter also allows them to be changed by the method, which is probably not the world's best programming practice although it's possible now. John Roth -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling 2.7 and 3.0 Versions of Dict
On Sep 2, 12:36 pm, "Gabriel Genellina" wrote: > En Wed, 31 Aug 2011 22:28:09 -0300, Travis Parks > escribi : > > > On Aug 31, 7:37 pm, Gregory Ewing wrote: > >> Ian Kelly wrote: > >> > if sys.version_info < (3,): > >> > getDictValues = dict.itervalues > >> > else: > >> > getDictValues = dict.values > > >> > (which is basically what the OP was doing in the first place). > > > My problem was that I didn't understand the scoping rules. It is still > > strange to me that the getValues variable is still in scope outside > > the if/else branches. > > Those if/else are at global scope. An 'if' statement does not introduce a > new scope; so getDictValues, despite being "indented", is defined at > global scope, and may be used anywhere in the module. > > -- > Gabriel Genellina > > Does that mean the rules would be different inside a function? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
On Sep 2, 10:53 am, Roy Smith wrote: > I have a function I want to run in a thread and return a value. It > seems like the most obvious way to do this is to have my target > function return the value, the Thread object stash that someplace, and > return it as the return value for join(). > > Yes, I know there's other ways for a thread to return values (pass the > target a queue, for example), but making the return value of the > target function available would have been the most convenient. I'm > curious why threading wasn't implemented this way. I assume it is because the underlying operating system APIs do not support it. Windows and POSIX threads only support returning an integer when a thread exits, similar to the exit code of a process. More importantly, there's no way to tell whether the exit code of a thread was set by user code or by the system. Even worse, some of those integer values are reserved by some operating systems. If your thread died via an exception, it still has an error code set by the operating system. How would you going to distinguish those codes from your own? Adam -- http://mail.python.org/mailman/listinfo/python-list
Tenjin and External CSS
I'm new at Python, Cherrypy and Tenjin and I can't get tenjin to recognize external css file. Does anyone have an example showing how it's done? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: convert python List to javascript array
On Fri, Sep 2, 2011 at 8:34 AM, Vineet Deodhar wrote: > Hi ! > Within a web framework, I want want to pass a python sequence (list or > tuple) to client-side javascript function as an array (javascript > compatible) > e.g., I have this list: > L = ['spam', 'ham', 'eggs', 12, (13.63)] > What is the correct way to convert L to javascript array format? > 1) jsonify the list and pass it to javascript > (whether json format & javascript array are similar?) JSON is in fact a subset of JavaScript, and modern browsers now include a specific API for parsing and generating it (https://developer.mozilla.org/En/Using_native_JSON ). Python likewise has a JSON module in the std lib: http://docs.python.org/library/json.html > OR > 2) >>> import array >>> y = array.array(i, L) > then return y to javascript function > But the problem with this method is, it will give an array of basic values > only. The word "array" gets tossed around a lot by programmers. The `array` module is not at all what you want in this case. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Algorithms Library - Asking for Pointers
Hello: I am working on an algorithms library. It provides LINQ like functionality to Python iterators. Eventually, I plan on having feaures that work against sequences and mappings. I have the code up at http://code.google.com/p/py-compass. This is my first project in Python, so I'd like some feedback. I want to know if I am following conventions (overall style and quality of code). Thanks, Travis Parks -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
On 2011-09-02, Steven D'Aprano wrote: > Roy Smith wrote: >> I have a function I want to run in a thread and return a value. It >> seems like the most obvious way to do this is to have my target >> function return the value, the Thread object stash that someplace, and >> return it as the return value for join(). >> Yes, I know there's other ways for a thread to return values (pass the >> target a queue, for example), but making the return value of the >> target function available would have been the most convenient. I'm >> curious why threading wasn't implemented this way. > Because then the code launching the thread would have to block, waiting > until the thread is completed, so it will have a result to return. Isn't "waiting until the thread is completed" sort of the point of join()? -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling 2.7 and 3.0 Versions of Dict
En Wed, 31 Aug 2011 22:28:09 -0300, Travis Parks escribió: On Aug 31, 7:37 pm, Gregory Ewing wrote: Ian Kelly wrote: > if sys.version_info < (3,): > getDictValues = dict.itervalues > else: > getDictValues = dict.values > (which is basically what the OP was doing in the first place). My problem was that I didn't understand the scoping rules. It is still strange to me that the getValues variable is still in scope outside the if/else branches. Those if/else are at global scope. An 'if' statement does not introduce a new scope; so getDictValues, despite being "indented", is defined at global scope, and may be used anywhere in the module. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On Sep 1, 8:52 am, Den wrote: > Obviously, this is a windows-based question. I know that Ctrl-Alt-Del > is handled deep inside the OS, and I'm not trying to interrupt that. > But is there some way to detect that a C-A-D has been pressed? > > Also, is there a corresponding key-sequence in Mac and Linux? And how > might one detect those too? > > Den I've been doing some more thinking on what I want. This may be a better explanation. Is there a way of detecting if my program has lost "focus" (I'm not sure the correct term)? For example, if someone is typing in my program, but some other program takes control (or CAD has been pressed) I would like simply to log that. I have no interest in trying to hijack or interfere with anything, simply log it. Den -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On Sep 2, 5:27 am, sjm wrote: > On Sep 1, 12:52 pm, Den wrote: > > > Obviously, this is a windows-based question. I know that Ctrl-Alt-Del > > is handled deep inside the OS, and I'm not trying to interrupt that. > > But is there some way to detect that a C-A-D has been pressed? > > If you manage to write a program that can detect CTRL-ALT-DEL, please > report it as a bug in Windows! CTRL-ALT-DEL is Windows' "secure > attention sequence" which must only be handled by the OS. > > -- Steve I'm not trying to hook it or stop it, just detect it. Den -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On Sep 2, 5:27 am, sjm wrote: > On Sep 1, 12:52 pm, Den wrote: > > > Obviously, this is a windows-based question. I know that Ctrl-Alt-Del > > is handled deep inside the OS, and I'm not trying to interrupt that. > > But is there some way to detect that a C-A-D has been pressed? > > If you manage to write a program that can detect CTRL-ALT-DEL, please > report it as a bug in Windows! CTRL-ALT-DEL is Windows' "secure > attention sequence" which must only be handled by the OS. > > -- Steve I have already done that, in AutoHotKey ... or at least it used to work. AHK can detect when a window opened. And when CAD was pressed the ... well, I've forgotten what it was called ... but a window opened asking if you wanted to open the task manager, or quit or log off or what. Then you would know that CAD was pressed. There was nothing you could do to stop it, but you could at least detect that it had been pressed. That's why I was wondering if there was a similar technique which could be used in Python. Den -- http://mail.python.org/mailman/listinfo/python-list
Re: convert python List to javascript array
On Fri, Sep 2, 2011 at 11:34 AM, Vineet Deodhar wrote: > Hi ! > Within a web framework, I want want to pass a python sequence (list or > tuple) to client-side javascript function as an array (javascript > compatible) > e.g., I have this list: > L = ['spam', 'ham', 'eggs', 12, (13.63)] > What is the correct way to convert L to javascript array format? > 1) jsonify the list and pass it to javascript > (whether json format & javascript array are similar?) > > OR > 2) >>> import array >>> y = array.array(i, L) > then return y to javascript function > But the problem with this method is, it will give an array of basic values > only. > > OR > 3) Any other alternative? > > Thanks, > Vineet > -- The JavaScript Object Notation (JSON) is meant exactly for this purpose. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't threading.join() return a value?
Roy Smith wrote: > I have a function I want to run in a thread and return a value. It > seems like the most obvious way to do this is to have my target > function return the value, the Thread object stash that someplace, and > return it as the return value for join(). > > Yes, I know there's other ways for a thread to return values (pass the > target a queue, for example), but making the return value of the > target function available would have been the most convenient. I'm > curious why threading wasn't implemented this way. Because then the code launching the thread would have to block, waiting until the thread is completed, so it will have a result to return. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
convert python List to javascript array
Hi ! Within a web framework, I want want to pass a python sequence (list or tuple) to client-side javascript function as an array (javascript compatible) e.g., I have this list: L = ['spam', 'ham', 'eggs', 12, (13.63)] What is the correct way to convert L to javascript array format? 1) jsonify the list and pass it to javascript (whether json format & javascript array are similar?) OR 2) >> import array >> y = array.array(i, L) then return y to javascript function But the problem with this method is, it will give an array of basic values only. OR 3) Any other alternative? Thanks, Vineet-- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension timing difference.
On Sep 2, 9:54 am, Bart Kastermans wrote: > if d(a,b) == 1 and a < b: It will probably be faster if you reverse the evaluation order of that expression. if ahttp://mail.python.org/mailman/listinfo/python-list
Why doesn't threading.join() return a value?
I have a function I want to run in a thread and return a value. It seems like the most obvious way to do this is to have my target function return the value, the Thread object stash that someplace, and return it as the return value for join(). Yes, I know there's other ways for a thread to return values (pass the target a queue, for example), but making the return value of the target function available would have been the most convenient. I'm curious why threading wasn't implemented this way. -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension timing difference.
MRAB writes: > On 02/09/2011 01:35, Bart Kastermans wrote: >> graph = [[a,b] for a in data for b in data if d(a,b) ==1 and a< b] >> graph2 = [] >> for i in range (0, len(data)): >> for j in range(0,len(data)): >> if d(data[i],data[j]) == 1 and i< j: >> graph2.append ([i,j]) > > Are they actually equivalent? Does graph == graph2? > > The first version (list comprehension) creates a list of pairs of > values: > > [a, b] > > whereas the second version (for loops) creates a list of pairs of > indexes: > > [i, j] > > The second version has subscripting ("data[i]" and "data[j]"), which > will slow it down. You are absolutely right. I had changed the code from the equivalent: graph2 = [] for i in range (0, len(data)): for j in range(0,len(data)): if d(data[i],data[j]) == 1 and i < j: graph2.append ([data[i],data[j]]) But then also tried the equivalent for a in data: for b in data: if d(a,b) == 1 and a < b: graph2.append([a,b]) Which does away with the indexing, and is just about exactly as fast as the list comprehension. That'll teach me; I almost didn't ask the question thinking it might be silly. And it was, but I thought it for the wrong reason. I tell my students there are no stupid questions, I should listen to myself more when I do. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: slightly OT -- LaTeX
Hi Alan, Thanks for sharing that link - very interesting! http://www.pytex.org/ Malcolm (former LaTeX/TeX user from early 90's) -- http://mail.python.org/mailman/listinfo/python-list
Re: OSX application built with py2app can't see bundled PySide module?
On 9/1/11 3:54 PM, Aaron Scott wrote: I'm trying to deploy a Python app on OSX that was built with PySide. py2app packages it without issue, copying and linking a lot of PySide and Qt files in the process. But then, when I try to run the built app, I get this error: Traceback (most recent call last): File "/Users/sequence/Desktop/code/dailies/dist/dailies_v02.app/Contents/Resources/__boot__.py", line 31, in _run('dailies_v02.py') File "/Users/sequence/Desktop/code/dailies/dist/dailies_v02.app/Contents/Resources/__boot__.py", line 28, in _run execfile(path, globals(), globals()) File "/Users/sequence/Desktop/code/dailies/dist/dailies_v02.app/Contents/Resources/dailies_v02.py", line 9, in from PySide.QtCore import * File "PySide/__init__.pyc", line 2, in File "PySide/private.pyc", line 2, in File "PySide/QtCore.pyc", line 18, in File "PySide/QtCore.pyc", line 15, in __load ImportError: '/usr/lib/python2.6/lib-dynload/PySide/QtCore.so' not found The weird thing is, QtCore.so IS included in the application bundle: py2app copied it to the build under Contents/Resources/lib/python2.6/lib-dynload/PySide/. Is there a reason the application isn't seeing this? You might want to post this question to the MacPython list--that's where the py2app experts are found. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: slightly OT -- LaTeX
http://www.pytex.org/ hth, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
Hi Fokke, Disclaimer: I have no experience with the Python WebDAV package you're using. But a thought: > In the config file it says: > "# main directory > directory = \Webdav" Perhaps you should qualify your directory path with a drive letter? I would try this 2 ways: directory = E:\Webdav And if that doesn't work: directory = E:/Webdav My thinking about the 2nd example is that perhaps the \W is getting interpreted as a control character vs. "backslash" "W". Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
On Sep 2, 1:19 pm, "Fokke Nauta" wrote: > "Dennis Lee Bieber" wrote in > messagenews:mailman.687.1314941410.27778.python-l...@python.org... > > > > > > > > > > > On Thu, 1 Sep 2011 12:30:43 +0200, "Fokke Nauta" > > declaimed the following in > > gmane.comp.python.general: > > >> "Dennis Lee Bieber" wrote in message > >>news:mailman.643.1314851358.27778.python-l...@python.org... > > >> > Next, if you'd read further and didn't take the comment as the > >> > instruction. set > >> > firstrun=1 > > >> I did > > >> > to tell the server this is the first time it is being run - IT WILL > >> > create the database table (after the first start, reset the flag to 0 > >> > to > >> > speed up later runs). > > >> It didn't create the table. The database kept empty. > > > Odd -- but then, I'm not running it myself, and wasn't up to reading > > all the code to see what path it takes. > > It's only for experimenting with calendar software, so authorization is not > a point. > So I forget about MySQL. > > > > > > > > > > > > >> > Later in the config file set > >> > mysql_auth=1 > >> > to enable the use of MySQL, and set the admin user/password to what you > >> > plan to have it use. > > >> I did > > >> > You probably want to set > >> > daemonize=1 > >> > (maybe after first run) > > >> I left this to 0. > > >> > Oh, and don't forget to set the main data directory and any > >> > port/host changes. > > >> I left host and port as they were. The main directory is e:\wwwroot > > >> > Start the server - it should connect to MySQL, create the table, and > >> > add the admin user to the table. > > >> I started the server with server.py (in > >> D:\Python27\WebDAV\PyWebDAV\DAVServer) -D e:/wwwroot -m -c config.ini > > > If the main directory is already in the config file, you probably > > don't need to specify it on the command line... > > OK > > > And... could there be > > something in the code where overriding the directory by command line > > changes where it looks for the config file? (Just guessing at this > > point). > > Possibly. > I tried this: > server.py -n -c config.ini > Once again, the server is up and running and when I am logging in with my > browser (10.0.0.140:8081) I can see information showing up at the command > prompt, showing somebody is logging is, but the same error: > "fshandler:get_data: \Webdav not found". During starting up the server > mentioned: "pywebdav:Serving data from \Webdav". > > In the config file it says: > "# main directory > directory = \Webdav" > > Perhaps my Python configuration is at fault. > > Fokke Is the path supposed to be absolute? In which case you'd need to have: directory=C:\path\to\Webdav instead of just directory=\Webdav Becky Lewis -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
Obviously, this is a windows-based question. I know that Ctrl-Alt-Del is handled deep inside the OS, and I'm not trying to interrupt that. But is there some way to detect that a C-A-D has been pressed? Others have pointed out that this shouldn't really be possible for reasons of security. (And I agree). However, if what you're really after is to detect a session switch or a logon then this might be of some use: http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 96, Issue 4
Two underscores??!!! OH!!! I thank thee! -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On Sep 1, 12:52 pm, Den wrote: > Obviously, this is a windows-based question. I know that Ctrl-Alt-Del > is handled deep inside the OS, and I'm not trying to interrupt that. > But is there some way to detect that a C-A-D has been pressed? If you manage to write a program that can detect CTRL-ALT-DEL, please report it as a bug in Windows! CTRL-ALT-DEL is Windows' "secure attention sequence" which must only be handled by the OS. -- Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 96, Issue 4
Thank you very much And no, no, I have not been reading a book with bad font =D haha!! The problem was that I did not inherit from Object... Since I am from a JAVA background, I assumed that Python would inherit implicitly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
"Dennis Lee Bieber" wrote in message news:mailman.687.1314941410.27778.python-l...@python.org... > On Thu, 1 Sep 2011 12:30:43 +0200, "Fokke Nauta" > declaimed the following in > gmane.comp.python.general: > >> "Dennis Lee Bieber" wrote in message >> news:mailman.643.1314851358.27778.python-l...@python.org... > >> > Next, if you'd read further and didn't take the comment as the >> > instruction. set >> > firstrun=1 >> >> I did >> >> > to tell the server this is the first time it is being run - IT WILL >> > create the database table (after the first start, reset the flag to 0 >> > to >> > speed up later runs). >> >> It didn't create the table. The database kept empty. > > Odd -- but then, I'm not running it myself, and wasn't up to reading > all the code to see what path it takes. It's only for experimenting with calendar software, so authorization is not a point. So I forget about MySQL. >> >> > Later in the config file set >> > mysql_auth=1 >> > to enable the use of MySQL, and set the admin user/password to what you >> > plan to have it use. >> >> I did >> >> > You probably want to set >> > daemonize=1 >> > (maybe after first run) >> >> I left this to 0. >> >> > Oh, and don't forget to set the main data directory and any >> > port/host changes. >> >> I left host and port as they were. The main directory is e:\wwwroot >> >> > Start the server - it should connect to MySQL, create the table, and >> > add the admin user to the table. >> >> I started the server with server.py (in >> D:\Python27\WebDAV\PyWebDAV\DAVServer) -D e:/wwwroot -m -c config.ini >> > If the main directory is already in the config file, you probably > don't need to specify it on the command line... OK > And... could there be > something in the code where overriding the directory by command line > changes where it looks for the config file? (Just guessing at this > point). > Possibly. I tried this: server.py -n -c config.ini Once again, the server is up and running and when I am logging in with my browser (10.0.0.140:8081) I can see information showing up at the command prompt, showing somebody is logging is, but the same error: "fshandler:get_data: \Webdav not found". During starting up the server mentioned: "pywebdav:Serving data from \Webdav". In the config file it says: "# main directory directory = \Webdav" Perhaps my Python configuration is at fault. Fokke -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing WebDAV server
"Dennis Lee Bieber" wrote in message news:mailman.622.1314812583.27778.python-l...@python.org... > On Wed, 31 Aug 2011 11:27:36 +0200, "Fokke Nauta" > declaimed the following in > gmane.comp.python.general: > >> >> Ofcourse I realized it was Unix/Linux. I already could tell that as the >> packages I downloaded were tar.gz files. >> So I unpacked them and expected to run a Python installer script from the >> Python command line. >> Hence my question "How do I do that", but perhaps I did not make myself >> clear enough. >> > NO Python package installer runs "from the Python command line" (ie; > from a Python interactive session prompt). > > Typically you run them from the OS command interpreter. If the > installer is a .py file and the associations are correct, the Python > interpreter will be started to process the installer script. If the > associations aren't set, you may have to enter > > python installer.py > > at the system prompt instead of > > installer.py > >> Tried to run the Python installer script from the DOS command line but >> that >> resulted in an error. >> > Okay -- so what was the error? > -- Sorry - I didn't come back on your question. In the mean time I forgot what the error message was. But I installed it the way Paul Kölle mentioned: "You dont install from "Python GUI", use normal cmd, navigate to the folder you downloaded PyXML and PyWebDAV and run "python setup.py install" (python.exe has to be in your PATH)." Fokke -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me understand this logging config
On Aug 30, 1:39 pm, Roy Smith wrote: > Oh, my, it turns out that django includes: > > # This is a copy of the Pythonlogging.config.dictconfig module, > # reproduced with permission. It is provided here for backwards > # compatibility for Python versions prior to 2.7. > > Comparing the django copy to lib/logging/config.py from Python 2.7.2, > they're not identical. It's likely they grabbed something earlier in > the 2.7 series. I'll check 2.7.0 and 2.7.1 to see. They're not identical, but should be functionally equivalent. I'm not able to reproduce your results: I copied the "loggers" part of your config into a Django 1.3 project, and from a manage.py shell session: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> import logging >>> logger = logging.getLogger('djfront.auth.facebook') >>> logger.debug('Debug') >>> logger.info('Info') 2011-09-02 10:51:13,445 INFO djfront.auth.facebook Info >>> ... as expected. Since it's Python 2.6, it should be using the dictconfig which ships with Django 1.3. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On 01/09/11 17:52, Den wrote: > Obviously, this is a windows-based question. I know that Ctrl-Alt-Del > is handled deep inside the OS, and I'm not trying to interrupt that. > But is there some way to detect that a C-A-D has been pressed? > > Also, is there a corresponding key-sequence in Mac and Linux? And how > might one detect those too? On Linux Ctrl+Alt+Delete is typically configured to reboot the machine when in console mode. In X11 (graphical), as far as I know, it's no different than other keys. To catch it globally, you'd probably have to go through the individual window manager. As m'colleague Nobody mentions, there's also the SysRq feature, but that always goes straight to the kernel and is, like Ctrl+Alt+Delete on Windows, impossible to handle in userspace code. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me understand this logging config
On Aug 30, 1:39 pm, Roy Smith wrote: > Oh, my, it turns out that django includes: > > # This is a copy of the Pythonlogging.config.dictconfig module, > # reproduced with permission. It is provided here for backwards > # compatibility for Python versions prior to 2.7. > > Comparing the django copy to lib/logging/config.py from Python 2.7.2, > they're not identical. It's likely they grabbed something earlier in > the 2.7 series. I'll check 2.7.0 and 2.7.1 to see. They're not identical, but should be functionally equivalent. I'm not able to reproduce your results: I copied the "loggers" part of your config into a Django 1.3 project, and from a manage.py shell session: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> import logging >>> logger = logging.getLogger('djfront.auth.facebook') >>> logger.debug('Debug') >>> logger.info('Info') 2011-09-02 10:51:13,445 INFO djfront.auth.facebook Info >>> ... as expected. Since it's Python 2.6, it should be using the dictconfig which ships with Django 1.3. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me understand this logging config
On Aug 30, 1:39 pm, Roy Smith wrote: > Oh, my, it turns out that django includes: > > # This is a copy of the Pythonlogging.config.dictconfig module, > # reproduced with permission. It is provided here for backwards > # compatibility for Python versions prior to 2.7. > > Comparing the django copy to lib/logging/config.py from Python 2.7.2, > they're not identical. It's likely they grabbed something earlier in > the 2.7 series. I'll check 2.7.0 and 2.7.1 to see. They're not identical, but should be functionally equivalent. I'm not able to reproduce your results: I copied the "loggers" part of your config into a Django 1.3 project, and from a manage.py shell session: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> import logging >>> logger = logging.getLogger('djfront.auth.facebook') >>> logger.debug('Debug') >>> logger.info('Info') 2011-09-02 10:51:13,445 INFO djfront.auth.facebook Info >>> ... as expected. Since it's Python 2.6, it should be using the dictconfig which ships with Django 1.3. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On Fri, Sep 2, 2011 at 5:06 PM, Stephen Hansen wrote: > That's why you have to hit CAD to get to the login form in some versions > of Windows. The whole point of that secure sequence is that the OS and > only the OS responds. > Although I heard somewhere that that's more gimmick than guarantee, and that it IS possible for an app to hook CAD - just that it's a lot harder than building a simple window that looks like the login... but it's pretty easy to fool a lot of people. Just look at the emails in your spam box one day, find the ones spoofing a bank, and see what a poor job they do. And yet they work. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] allow line break at operators
Gabriel AHTUNE writes: > So can be done with this syntax: > > > x = firstpart * secondpart + #line breaks here > > anotherpart + #continue > > stillanother #continue on. > > after a "+" operator the line is clearly not finished yet. Sure, but IIRC one design principle of Python is that the keyword that denotes the syntax should be the first thing on the line, making it easy to scan down the left side of the code to see the syntactic structure. The required indentation of the controlled suite also helps emphasize that keyword. Analogously, if operators are going to denote continuation, they should come first on the line. I just don't think this idea is going anywhere. Explicit continuation with backslash or implicit continuation of parenthesized expressions is just not that heavy a price to pay. Perhaps historically some of these ideas could have been implemented, but now they're just going to confuse a host of editors and code analysis tools. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to daemonize a HTTPServer
On Sep 1, 6:32 am, "Martin P. Hellwig" wrote: > On 01/09/2011 04:16, babbu Pehlwan wrote: > > > I have written a http server using BaseHTTPServer module. Now I want > > to instantiate it through another python script. The issue here is > > after instantiate the control doesn't come back till the server is > > running. Please suggest. > > Sounds like something you could use the multiprocessing module for, but > then again my crystal ball is a bit fuzzy today. > > -- > mph Thanks dear, the issue get solved now. You are absolutely right, actually I was daemonising the same thread. Now I have created a seperate thread for the server. -- http://mail.python.org/mailman/listinfo/python-list
CompIMAGE 2012: Call for Thematic Sessions and Papers
Dear Colleague, We would like to call your attention to the International Symposium CompIMAGE 2012 – Computational Modeling of Objects Presented in Images: Fundamentals, Methods and Applications (www.dis.uniroma1.it/ compimage2012), that will be held in Rome, Italy, in September 5-7, 2012. MAIN TOPICS - image processing and analysis - image segmentation - 2D and 3D reconstruction - data interpolation - registration and acquisition - objects tracking - scientific data visualization - satellite data - shape modeling - simulation - biometric person identification - medical imaging - motion and deformation analysis - material science - large set data visualization - vision in robotics and automation INVITED LECTURERS - Lorenzo Bruzzone, University of Trento, Italy - Jorge Marques, Instituto Superior Técnico, Lisboa, Portugal - Fiorella Sgallari, University of Bologna, Italy - Bertrand Thirion, INRIA, France - Luminita Vese, UCLA, USA THEMATIC SESSIONS Proposals to organize Thematic Session within CompIMAGE2012 are welcome and should be submitted by email to: compimage2...@dis.uniroma1.it. PUBLICATIONS - The proceedings book will be published by Taylor & Francis Group and indexed by Thomson Reuters Conference Proceedings Citation Index, IET Inspect and Elsevier Scopus. - A book with 20 invited works from the best ones presented in CompIMAGE 2012 (extended versions) will be published by Springer. - The organizers will encourage the submission of extended versions of the accepted papers to related International Journals; in particular, for special issues dedicated to CompIMAGE 2012. IMPORTANT DATES - Deadline for Thematic Sessions proposals: November 1, 2011 - Deadline for Full Paper Submission: December 31, 2011 - Authors Notification: March 16, 2012 - Final camera-ready papers: April 20, 2012 - Early Symposium registration (mandatory for Authors): April 20, 2012 - Symposium dates: September 5-7, 2012 AWARDS "Best paper award" and "Best student paper award" are going to be given to the author(s) of two papers presented at CompIMAGE 2012, selected by the Organizing Committee based on the best combined marks from the Scientific Committee and Session Chairs. Kind regards, Paolo Di Giamberardino Daniela Iacoviello Renato M. Natal Jorge João Manuel R. S. Tavares PS. For further details, please, visit CompIMAGE 2012 website at: www.dis.uniroma1.it/compimage2012. -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting Ctrl-Alt-Del in Windows
On 9/1/11 8:52 AM, Den wrote: > Obviously, this is a windows-based question. I know that Ctrl-Alt-Del > is handled deep inside the OS, and I'm not trying to interrupt that. > But is there some way to detect that a C-A-D has been pressed? IIUC, by definition, Ctrl-Alt-Delete can't be responded to in any way. Its the entire point of the sequence: when you type it you can be entirely, totally, 100% certain that what happens next is the true OS and not any app faking things. That's why you have to hit CAD to get to the login form in some versions of Windows. The whole point of that secure sequence is that the OS and only the OS responds. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list