ANN: stats0.1.1a calculator statistics for Python
I am pleased to announce the second public release of stats for Python, and the first targeted at Python 3.x. http://pypi.python.org/pypi/stats stats is a pure-Python module providing basic statistics functions similar to those found on scientific calculators. It has over 40 statistics functions, including: Univariate statistics: * arithmetic, harmonic, geometric and quadratic means * median, mode, midrange, trimean * mean of angular quantities * running and weighted averages * quartiles, hinges and quantiles * variance and standard deviation (sample and population) * average deviation and median average deviation (MAD) * skew and kurtosis * standard error of the mean Multivariate statistics: * Pearson's correlation coefficient * Q-correlation coefficient * covariance (sample and population) * linear regression * sums Sxx, Syy and Sxy and others. This is an unstable alpha release of the software. Feedback and contributions are welcome. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list
hi
http://infohivaids.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Looking For Tutorial Comparison Of sh - perl - python
I am putting together a comparison & intro to each of sh, perl, python with a view towards addressing: - What is each language naturally good for - What are their respective strengths and weaknesses - How do they differ paradigmatically Audience is non-programming sysadmins, many of whom are trying to improve their scripting skills. I have written extensive sh and python, considerably less perl. Before I attack this myself, has anyone done something along these lines I could piggyback upon? TIA, -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Steven D'Aprano wrote: > Right website, wrong page :) > > http://effbot.org/zone/call-by-object.htm D'oh. Thanks for the catch :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Some Machine Learning related questions
On Nov 13, 7:39 pm, joy99 wrote: > Dear Group, > > Hope every one is fine. > > I am trying to put some questions. > > I am developing some tool boxes for support vector machine (SVM) and > hidden markov model (HMM). > For HMM I was following the tutorial by Leeds University Computer > Science Department, available online in HTML format, and for SVM I was > following a book on Neural Networks by Simon Haykin. > > After comprehending them, I thought to cross check my knowledge with > the original works. I referred to 1989 Rabiner paper for HMM and SVM > society's tutorial for SVM. > > Here, I am getting some confusions. > > I am looking for a forum, especially an active forum, like this one (I > searched for few in Google, but all seem to be very lazy), where I can > post these questions. > > I felt this room consists of very expert people and I visit it often > moreover it is very active -everytime I posed some question people > solved it very nicely. > > If any one can suggest a solution to my queries taking his/her > valuable time, I would be grateful enough. > > Thanks in advance. > > Apology if it is an unrelated question of the forum. > > Wishing you all a happy winter. > > Best Regards, > Subhabrata. Thanx Robert, It seems a good site. Wishing You A Happy Day Ahead, Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, 13 Nov 2010 22:22:00 +, Mark Wooding wrote: > Challenge: explain the following code using only those concepts. ("those concepts" being name and value/object) > def foo(): > l = [] > for i in xrange(10): > (lambda j: l.append((lambda: i, lambda: j)))(i) > print [(f(), g()) for f, g in l] >>> foo() [(9, 0), (9, 1), (9, 2), (9, 3), (9, 4), (9, 5), (9, 6), (9, 7), (9, 8), (9, 9)] Here's a slightly less condensed version that demonstrates the same behaviour, but may be slightly easier to understand: def spam(): a = [] b = [] for i in xrange(5): a.append(lambda: i) b.append(lambda i=i: i) print [f() for f in a] print [f() for f in b] Anyway, here goes... In your function foo, the name "i" is bound to the objects 0, 1, 2, ... 9 sequentially, each time around the for-loop. Inside the loop, a function object is created and then called: (lambda j: l.append((lambda: i, lambda: j)))(i) (Aside: this depends on scoping rules that were introduced quite late in Python's history -- prior to version 2.2, this wouldn't work at all.) The "outer" lambda: lambda j: l.append(...) has a name in the function namespace (a "local variable") called "j". On entry to this function, this j is bound to the same object which is bound to i *at the time that the function is called*. That is, each of the sequence of "outer" lambdas get a distinct j = 0, 1, 2, ... What does these outer lambdas do? They create two more function objects, which I will label "A" and "B": A:: lambda: i B:: lambda: j and places those function objects in a tuple and appends the tuple to the list. What do these "inner" functions do? They have no local variable of their own -- they refer only the i and j of their enclosing scope, namely the "outer" lambda that created them. Note that there isn't actually a single A and a single B, there is a whole series of them... we might label them A0, A1, A2, ... etc. None of the function A0, A1, A2, ... have any local variable i. When you call them, Python looks in the enclosing scopes for a variable i. It doesn't find one in the "outer" lambda, so it next searches the namespace of foo, where it finds the name i bound to the object 9. Hence the inner lambdas Ai always return 9, since 9 is the value of i when the function is called. Functions B0, B1, B2, ... similarly have no local variable j. When you call any of the Bs, Python looks in the enclosing scopes for a variable j. However, in this case it *does* find one, in the "outer" lambda, where the name j has been bound to some object which was determined at the time "outer" was called, namely the value of i *at the time*, and hence 0, 1, 2, ... depending on which specific function you're looking at. Hence the inner lambda Bi returns the value of i *at the time it was defined*. > I explain this as follows. > > * Python's `for' loop works by assignment. The name `i' remains bound > to the same storage location throughout; This is not necessarily true. It's true for CPython, where function locals are implemented as fixed slots in the function object; since the slot doesn't move relative to the function, and the function doesn't move relative to the heap, the name i is in a fixed storage location for the life of foo. But that's not necessarily the case for all implementations -- locals could be stored in a data structure that moves data around (say, a red-black tree), or objects could be free to move in the heap, or both. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Some Machine Learning related questions
On 2010-11-13 08:39 , joy99 wrote: I am looking for a forum, especially an active forum, like this one (I searched for few in Google, but all seem to be very lazy), where I can post these questions. http://stats.stackexchange.com/ -- 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: regenerating unicodedata for py2.7 using py3 makeunicodedata.py?
2010/11/13 Martin v. Loewis : >> Is this intended or even guaranteed for these generated files to be >> compatible across py2.7 and py3, or am I going to be bitten by some >> less obvious issues later? > > It works because the generated files are just arrays of structures, > and these structures are the same in 2.7 and 3.2. However, there is > no guarantee about this property: you will need to check for changes > to unicodedata.c to see whether they may affect compatibility. > > Regards, > Martin > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the confirmation Martin! Do you think, it the mentioned omission of the character names of some CJK ranges in unicodedata intended, or should it be reported to the tracker? Regards, Vlastimil Brom -- http://mail.python.org/mailman/listinfo/python-list
I am away
I will be out of the office starting 12/11/2010 and will not return until 16/11/2010. contact Narinder Kumar 0208 738 8871 (narinder.ku...@ba.com) Ian Sherrington (88149) matthew page 0208 738 3519 (matthew.p...@ba.com) Greg Lakin 0208 738 3469 (greg.t.la...@ba.com) Christopher Bristow 208 738 6933 (chris.bris...@ba.com) -- This message is private and confidential and may also be legally privileged. If you have received this message in error, please email it back to the sender and immediately permanently delete it from your computer system. Please do not read, print, re-transmit, store or act in reliance on it or any attachments. British Airways may monitor email traffic data and also the content of emails, where permitted by law, for the purposes of security and staff training and in order to prevent or detect unauthorised use of the British Airways email system. Virus checking of emails (including attachments) is the responsibility of the recipient. British Airways Plc is a public limited company registered in England and Wales. Registered number: 177. Registered office: Waterside, PO Box 365, Harmondsworth, West Drayton, Middlesex, England, UB7 0GB. Additional terms and conditions are available on our website: www.ba.com -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Steven D'Aprano writes: > On Sat, 13 Nov 2010 21:42:03 +, Mark Wooding wrote: > > > Dave Angel writes: > > > >> No, an (=) assignment is always an assignment. > > > > No. In `foo[0] = bar' it's a method call in disguise. > > How does that imply that can't also be an assignment? Is `splat(34)' an assignment? If so, I think the term's meaning is grievously diluted. I'd rather say that `splat(34)' might mutate a value, or have side effects, and reserve the term `assignment' for the job of explaining how variables work. That seems pretty tricky, because we're arguing about it a lot, so I think we need sharply defined concepts so that we don't get more confused than we have to be. > Of course, you're correct that it's not *necessarily* an assignment, [...] > I don't think it helps to overload newbies struggling with the basics > with such pathological cases though. I think that we're better off giving `newbies' a conceptual framework which is robust, so that they can understand pathological situations when they occur. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Dennis Lee Bieber writes: > def swapFunc(a, b): > return b, a That's not what a `swap' function should do. > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > "=" means just one thing, a rebinding of some identifier to a > different object. Names aren't bound to objects. See elsewhere. > Or, in more general, "=" rebinds the fully qualified name to a > different object, which has the result of mutating a partially qualified > name (a name whose suffix has be removed). Names aren't mutated at all. Values (or, synonymously, objects) are mutated. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Steven D'Aprano writes: > On Sat, 13 Nov 2010 20:01:42 +, Mark Wooding wrote: > > Some object types are primitive, provided by the runtime system; > > there are no `internal' variables to be assigned in these cases. > > You seem to be making up your own terminology here, or at least using > terminology that isn't normally used in the languages I'm used to. I was attempting to define possibly unfamiliar terms as I went along. Did you not notice? > If you mean "primitive" in the sense of "built-in", your conclusion is > wrong. Such "primitive" types include dicts and lists, Yes, those are precisely the ones I was thinking of. > which are sophisticated container objects with internal "variables" to > be assigned to: They have internal state. I don't think that internal state consists of (Python) variables, though. This is why I brought up the possibility of a pure Python implementation, maintaining its state by assigning to variables captured using closures. > > There's a qualitative difference here: simple assignment has semantics > > defined by the language and provided by the implementation, and can > > therefore be understood in isolation, using only lexically apparent > > information; whereas the complex assignments are implemented by invoking > > methods on the objects mentioned on the left hand side. > > Again, you're using unfamiliar terminology. I'm sorry. I thought I defined those terms recently. (It appears not. Sorry.) I meant to refer to assignments in which the target is an identifier (to use the actual terminology from the manual). > "Simple" and "complex" assignment -- I can guess you mean "name > binding" = simple and "any other reference binding" = complex in > Python terminology: Again: assignment is not binding. See the explanation below. > The thing is, the semantics of assigning to built-in components are > equally defined by the language as the semantics of name binding. Did you read what I said? > You are right to point out that for arbitrary types: > > x[2] = 5 > > need not be an assignment, Good. This was /precisely/ what I was pointing out: determining /whether/ the value named by an identifier inhabits one of the built-in types is, in general, hard. > The distinction between the two count as an important proviso to the > discussion: x[2] = 5 is only an assignment if the type of x is > non-pathological and not broken. The latter is not an assignment: it's a disguised method call. > But putting aside such pathological cases, I don't think you can justify > distinguishing between "simple" and "complex" assignment. To conflate them is to confuse two different levels of meaning. Simple assignments occur because the language is hard-wired that way; complex assignments are disguised method calls which often mutate values. > Names are only one type of reference in Python, not the only one, and > assignments other than name-binding can be fully understood from the > language semantics *provided you know the type is a built-in*. > >> Assignment *always* binds an object to a target. > > > > No! Assignment /never/ binds. > > A shocking claim that requires more explanation. If it doesn't bind, > what does it do? Duh! It assigns. You're not usually this slow. Fortunately I explain below. > > There is syntactic confusion here too, since Python interprets a > > simple assignment in a function body -- in the absence of a > > declaration such as `global' to the contrary -- as indicating that > > the variable in question should be bound to a fresh variable on > > entry to the function. > > Well, there seems to be some confusion here, but I don't think it's > ours... local variables in functions aren't bound on *entry* to the > function. How could they be? They are bound *when the assignment is > executed*, which may be never -- hence it is possible to get an > UnboundLocalError exception, if you try to retrieve the value of a local > which hasn't yet had a value bound to it. The exception name perpetuates the misunderstanding, alas; but it's traditional, from Lisp, to say that a variable is `unbound' if it contains no value. > > But assignment itself doesn't perform binding. (This is a > > persistent error in the Python community; or, less charitably, the > > Python community gratuitously uses the word in a different sense > > from the wider programming-language-theory community. See Lisp > > literature passim, for example.) > > *Less* charitably? I'm sorry, you think that being *wrong* is better > than being *different*? That's not a moral judgment I can agree with. Being wrong is perhaps justifiable, and is rectifiable by learning. Being gratuitously different in such a case is to intentionally do a disservice to those coming from or going to other communities where they encounter more conventional uses for the terms in question. > > There's a two step mapping: names -> storage locations -> values. > > Binding affects the left hand part of the
Re: strange behavor....
m...@distorted.org.uk (Mark Wooding) writes: > Arnaud Delobelle writes: >> I think I understand Python programs correctly using only the notions >> of "name" and "value" (or object). > > Challenge: explain the following code using only those concepts. > > def foo(): > l = [] > for i in xrange(10): > (lambda j: l.append((lambda: i, lambda: j)))(i) > print [(f(), g()) for f, g in l] > > I explain this as follows. > > * Python's `for' loop works by assignment. The name `i' remains bound > to the same storage location throughout; this binding is established > on entry to the function. Since `i' is not rebound in any function > lexically enclosed in `foo', every occurrence of `lambda: i' refers > to this same storage location. At the end of the loop, this storage > location contains the value 9. I don't need "storage locations". All occurences of the name "i" in the code above belong the the namespace local to the function "foo". > * The name `j' is rebound repeatedly: in each iteration of the `for' > loop, the function `lambda j: ...' is invoked, binding `j' to a > fresh storage location into which the value of `i' at the time is > stored. Since the function `lambda: j' is lexically enclosed within > this function, the name `j' refers to a different storage location > in each of these functions, these storage locations are initialized > with distinct values 0 up to 9, and they are never changed. I don't need "storage locations" to explain this. At each iteration a new lambda function (with a new local namespace) is created and the name "j" belongs to the namespace which is local to the lambda being created. Upon call of the lambda, "j" is bound to the current value of "i". So at each iteration, assignment to "j" is performed in a different namespace. You can argue that I use the notion of "namespace" to explain what you do with "storage locations". However, even with the notion of storage location, you *still* need the notion of namespace to understand Python (see the "lexically enclosed within this function" above). So I still maintain that "storage location" is a superfluous notion in Python. To put it another way, when you say: Two occurences of the name "a" are bound to the same storage location I say: Two occurences of the name "a" belong to the same namespace These are equivalent models (in the sense that they will interpret Python code in the same way), but in order to find out whether two occurences of a name are bound to the same storage location, you need to check whether the names belong to the same namespace! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 2.7.1 release candidate 1
On behalf of the Python development team, I'm chuffed to announce the a release candidate of Python 2.7.1. Please test the release candidate with your packages and report any bugs you find. 2.7.1 final is scheduled in two weeks. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, auto-numbering of fields in the str/unicode format method, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7.1 visit: http://www.python.org/download/releases/2.7.1/ The 2.7.1 changelog is at: http://svn.python.org/projects/python/tags/r271rc1/Misc/NEWS 2.7 documentation can be found at: http://docs.python.org/2.7/ This is a testing release, so we encourage developers to test it with their applications and libraries. Please report any bugs you find, so they can be fixed in the final release. The bug tracker is at: http://bugs.python.org/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7.1's contributors) -- http://mail.python.org/mailman/listinfo/python-list
Re: drawing with the mouse with turtle...solved?
On Sat, 13 Nov 2010 09:10:41 -0500, Brian Blais wrote: > Here is code that "works", with at least one small oddity: > > import turtle > > def gothere(event): > turtle.penup() > turtle.goto(event.x-360,340-event.y) > turtle.pendown() > > def movearound(event): > turtle.goto(event.x-360,340-event.y) [...] > the oddity is that the coordinate transformations, x-360 and 340-y, are > done by eye and do not seem to be related to any of the coordinate > values I could find. my screen size is 300x400, the x and y canvas > scales are 1 and 1, but if I try to transform with those numbers the > mouse is clearly off. Have you set the coordinates of the screen? screen.setworldcoordinates What do turtle.window_height() and turtle.window_width() return? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 3.1.3 release candidate 1
On behalf of the Python development team, I'm gladsome to announce a release candidate of the third bugfix release for the Python 3.1 series, Python 3.1.3. This bug fix release fixes numerous issues found in 3.1.2. Please try it with your packages and report any bugs you find. The final of 3.1.3 is scheduled to be released in two weeks. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.3 visit: http://www.python.org/download/releases/3.1.3/ A list of changes in 3.1.3 can be found here: http://svn.python.org/projects/python/tags/r313rc1/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.3's contributors) -- http://mail.python.org/mailman/listinfo/python-list
Re: drawing with the mouse with turtle
On Sat, 13 Nov 2010 06:22:59 -0500, Brian Blais wrote: > there is no change by changing the order, but I didn't expect one. > since ondrag is binding a callback, which is only called when the event > happens, I figure that the pen has to be down when the callback happens, > not when the binding occurs. since the pen is down (and never lifted), > when I start dragging the mouse around after that it should work...but > doesn't seem to. Can you tell if your callback is being called at all? In other words, can you distinguish between these? * the callback isn't being called; * the callback is being called, but nothing is being drawn. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, 13 Nov 2010 14:37:44 -0800, Dennis Lee Bieber wrote: > On Sat, 13 Nov 2010 16:29:19 +, m...@distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > >> to a function argument /never/ affects the caller in Python. It's >> simply not possible to write a `swap' function in Python. The latter >> means that a value itself changes but the relevant variables continue >> to store the same values. >> > I disagree (borrowing FORTRAN and Ada terms)... > > You can not write a "swap" PROCEDURE in Python... PROCEDUREs do not > return values except via side-effects on the arguments. FUNCTIONs > however, do return values as the function result... Ha, excellent point! But in fairness, in context he was talking about a function that operates purely by side-effects -- what Pascal, Fortran or Ada would call a procedure. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, 13 Nov 2010 21:42:03 +, Mark Wooding wrote: > Dave Angel writes: > >> No, an (=) assignment is always an assignment. > > No. In `foo[0] = bar' it's a method call in disguise. How does that imply that can't also be an assignment? Of course, you're correct that it's not *necessarily* an assignment, if the type of foo is a pathological or broken class that does weird things on __setitem__. We tend to gloss over that in discussions, in the same way that we gloss over the fact that: len([1,2,3]) does not necessarily return 3, but could in fact do *anything*, depending on whether or not len is still the built-in function or not. I don't think it helps to overload newbies struggling with the basics with such pathological cases though. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: regenerating unicodedata for py2.7 using py3 makeunicodedata.py?
> Is this intended or even guaranteed for these generated files to be > compatible across py2.7 and py3, or am I going to be bitten by some > less obvious issues later? It works because the generated files are just arrays of structures, and these structures are the same in 2.7 and 3.2. However, there is no guarantee about this property: you will need to check for changes to unicodedata.c to see whether they may affect compatibility. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace issue, Python vs numpy min/max problem
On Sat, 13 Nov 2010 11:41:09 -0800, dmitrey wrote: > hi all, > I have the following problem: > I have overloaded "max" function in my module (FuncDesigner); it works > like following: > if some data in arguments is of type "oofun" then my function works, > elseware numpy.max() is used. > > Now the problem: > suppose someone writes > from FuncDesigner import * > ... > a = max(0,1) > > so it calls FuncDesigner, it calls numpy.max and result is 0 (because in > numpy it means "max of array with single element 0 along 1st axis"). > But if user has not imported numpy then he expected calling ordinary > Python max and thus result to be "1". That's not your problem, that's the caller's problem. He shouldn't be calling import * unless he wants to import everything in your module directly into his namespace. If the caller said to you: "After executing len = x, I can't access the built-in len function any more, can you change x so that it magically tells when I want the built- in behaviour and does that?" you'd probably tell him to get lost. Doing import * is no different. It only becomes your problem if you have advised people that the right way to use your module is with import *. > Is there any way to get rid of the problem (somehow automatically > determine which func should be used - numpy or Python max)? The same > issue with "min", but they are equivalent, of course. Automatically? No. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, 13 Nov 2010 20:01:42 +, Mark Wooding wrote: > Terry Reedy writes: > >> On 11/13/2010 11:29 AM, Mark Wooding wrote: >> >> > Alas, Python is actually slightly confusing here, since the same >> > notation `=' sometimes means assignment and sometimes means mutation. >> >> I disagree somewhat. An object is mutated by an internal assignment. > > Some object types are primitive, provided by the runtime system; there > are no `internal' variables to be assigned in these cases. You seem to be making up your own terminology here, or at least using terminology that isn't normally used in the languages I'm used to. In OO languages such as Python, Java, and (I believe) Ruby, it is conventional to distinguish between objects and "primitives". Primitives are implemented as low-level C-like variables. In that sense, Python has no primitives. Ints, floats, etc. (which are primitives in Java) are full-blown objects in Python. If you mean "primitive" in the sense of "built-in", your conclusion is wrong. Such "primitive" types include dicts and lists, which are sophisticated container objects with internal "variables" to be assigned to: alist[0] = None assigns the value None to the first position in the list. Just because these "variables" aren't *named* variables doesn't mean they don't vary, or that they can't be assigned to. If you mean "primitive" in some other sense, I'm afraid I can't guess what you mean. >> "ll[0] = 1" assigns 1 to the 0 slot of ll. "o.a = 1" assigns 1 to the >> 'a' attribute of o. This which might be implemented by assigning 1 to >> the 'a' slot of o.__dict__, just as "a=1" might be implemented by >> assigning 1 to the 'a' slot of a namespace dict. > > There's a qualitative difference here: simple assignment has semantics > defined by the language and provided by the implementation, and can > therefore be understood in isolation, using only lexically apparent > information; whereas the complex assignments are implemented by invoking > methods on the objects mentioned on the left hand side. Again, you're using unfamiliar terminology. "Simple" and "complex" assignment -- I can guess you mean "name binding" = simple and "any other reference binding" = complex in Python terminology: name = value # simple assignment dict[key] = value # complex assignment obj.attr = value # complex The thing is, the semantics of assigning to built-in components are equally defined by the language as the semantics of name binding. If x is a built-in list or dict, the semantics of: x[something] = value is written in stone and part of the language semantics. Whether that is implemented by a method or not is an irrelevant implementation detail, but for what little it's worth, I believe the CPython implementation is written in a fully procedural fashion, with no methods in sight. One can write: [0, 1, 2, 3, 4][2] = 5 and the language semantics tell you *exactly* what will happen: the value of the list in position 2 will be unbound and the object 5 will be bound in its place. Who cares whether the *implementation* happens to be written as a C function or a Java method, or something else? You are right to point out that for arbitrary types: x[2] = 5 need not be an assignment, since if x is not a built-in x.__setitem__ will be called, and it may do anything it likes. By contrast, name binding: x = 5 *never* calls a method on any object, and therefore is fully defined by the language semantics. The distinction between the two count as an important proviso to the discussion: x[2] = 5 is only an assignment if the type of x is non-pathological and not broken. But putting aside such pathological cases, I don't think you can justify distinguishing between "simple" and "complex" assignment. Names are only one type of reference in Python, not the only one, and assignments other than name-binding can be fully understood from the language semantics *provided you know the type is a built-in*. >> Assignment *always* binds an object to a target. > > No! Assignment /never/ binds. A shocking claim that requires more explanation. If it doesn't bind, what does it do? > There is syntactic confusion here too, > since Python interprets a simple assignment in a function body -- in the > absence of a declaration such as `global' to the contrary -- as > indicating that the variable in question should be bound to a fresh > variable on entry to the function. Well, there seems to be some confusion here, but I don't think it's ours... local variables in functions aren't bound on *entry* to the function. How could they be? They are bound *when the assignment is executed*, which may be never -- hence it is possible to get an UnboundLocalError exception, if you try to retrieve the value of a local which hasn't yet had a value bound to it. > But assignment itself doesn't > perform binding. (This is a persistent error in the Python community; > or, less charitably, the Python c
Re: strange behavor....
Arnaud Delobelle writes: > m...@distorted.org.uk (Mark Wooding) writes: > > > Assignment /never/ binds. There is syntactic confusion here too, > > since Python interprets a simple assignment in a function body -- in > > the absence of a declaration such as `global' to the contrary -- as > > indicating that the variable in question should be bound to a fresh > > variable on entry to the function. But assignment itself doesn't > > perform binding. (This is a persistent error in the Python community; > > or, less charitably, the Python community gratuitously uses the word > > in a different sense from the wider programming-language-theory > > community. See Lisp literature passim, for example.) > > > > There's a two step mapping: names -> storage locations -> values. > > Binding affects the left hand part of the mapping; assignment affects > > the right hand part. > > I'm not sure the notion of "storage location" is useful in Python. We'll see. > I think I understand Python programs correctly using only the notions > of "name" and "value" (or object). Challenge: explain the following code using only those concepts. def foo(): l = [] for i in xrange(10): (lambda j: l.append((lambda: i, lambda: j)))(i) print [(f(), g()) for f, g in l] I explain this as follows. * Python's `for' loop works by assignment. The name `i' remains bound to the same storage location throughout; this binding is established on entry to the function. Since `i' is not rebound in any function lexically enclosed in `foo', every occurrence of `lambda: i' refers to this same storage location. At the end of the loop, this storage location contains the value 9. * The name `j' is rebound repeatedly: in each iteration of the `for' loop, the function `lambda j: ...' is invoked, binding `j' to a fresh storage location into which the value of `i' at the time is stored. Since the function `lambda: j' is lexically enclosed within this function, the name `j' refers to a different storage location in each of these functions, these storage locations are initialized with distinct values 0 up to 9, and they are never changed. * Therefore each `lambda: i' function, when called after the loop, outputs the same value 9; and each `lambda: j' function, when called after the loop, outputs a distinct value. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
want to start your own revenue generation site?
If you are willing to convert your groups into websites and want to earn huge revenue through your group network- do contact us- we have great service for group owners who has high number of members and messages. Start your own sms, joke, stories, news, jobs website and earn huge from your group user base and articles. We are dedicated php, ajax and open source programmers working in delhi, India. Looking for projects all over the world we can work on any projects in any regional language. We are looking for projects to work upon. If your company, hospital, school, college, non-profits need good interactive website and stores do contact us for services. We have special reduced prices for all non-profits. with warm regards ni...@nitinnaresh.com +91-8800302311 -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Dave Angel writes: > No, an (=) assignment is always an assignment. No. In `foo[0] = bar' it's a method call in disguise. > It changes the item on the left hand side to refer to a new object. Not necessarily. It could do anything at all depending on the type of the recipient object. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, 13 Nov 2010 05:50:40 -0800, alex23 wrote: > Tracubik wrote: >> why the integer value doesn't change while the list value do? > > http://effbot.org/pyfaq/why-are-default-values-shared-between- objects.htm Right website, wrong page :) http://effbot.org/zone/call-by-object.htm See also Wikipedia's page on parameter passing conventions: http://en.wikipedia.org/wiki/Evaluation_strategy -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
m...@distorted.org.uk (Mark Wooding) writes: > Assignment /never/ binds. There is syntactic confusion here too, > since Python interprets a simple assignment in a function body -- in > the absence of a declaration such as `global' to the contrary -- as > indicating that the variable in question should be bound to a fresh > variable on entry to the function. But assignment itself doesn't > perform binding. (This is a persistent error in the Python community; > or, less charitably, the Python community gratuitously uses the word > in a different sense from the wider programming-language-theory > community. See Lisp literature passim, for example.) > > There's a two step mapping: names -> storage locations -> values. > Binding affects the left hand part of the mapping; assignment affects > the right hand part. I'm not sure the notion of "storage location" is useful in Python. I think I understand Python programs correctly using only the notions of "name" and "value" (or object). After execution of the statement: a = 1 The name "a" is bound to the object 1, which means that from then on "a" evaluates to 1. There is no need to know more. As you point out, statements like: a[3] = 1 a.b = 1 are different because they are really function calls, i.e. a.__setitem__(3, 1) a.__setattr__("b", 1) so there is not necessarily any "assigning" or "binding" involved. It is simply a widely followed convention that after the function call: a.__setitem__(3, 1) the function call: a.__getitem__(3) should return 1. Augmented assignment is a different kettle of fish altogether, and IMHO it is the one that confuses things a lot. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, Nov 13, 2010 at 5:46 AM, Tracubik wrote: > hi all, > i've this on python 2.6.6: > > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 > ... > ... a = 1 > ... l = [1,1,1] > ... > ... change_integer(a) > ... change_list(l) > ... > ... print a > ... print l > 1 > [10, 1, 1] > > why the integer value doesn't change while the list value do? > in Pascal i can choose the behavour of parametres, how this work on Python? > also a link could be appreciated > > Thanks in advance > Nico > -- > http://mail.python.org/mailman/listinfo/python-list > $ cat python-argument-passing #!/usr/bin/python def assign_int(x): print 'id(x) is %d' % id(x) x = 5 # x is now a totally different integer, which won't be reflected in # the caller, because id(x) has changed print 'id(x) is %d' % id(x) def assign_list(list_): # list_ is initially a copy of the reference to list_1 print 'id(list_) is %d' % id(list_) list_ = [ 'a', 'b', 'c' ] # list_ is no a reference to a totally different list, as indicated # by the change in id(). This too won't be reflected in the caller, # because id(list_) has changed print 'id(list_) is %d' % id(list_) def assign_list_element(list_): # list_ is initially a copy of the reference to list_2 print 'id(list_) is %d' % id(list_) list_[1] = 101 # list_ is still a copy of the reference to list_2 - we only changed # one thing in that list, not the list itself. This _will_ be reflected # in the caller, because we're still talking about the same list. print 'id(list_) is %d' % id(list_) x = 1 list_1 = [ 1, 2, 3 ] list_2 = [ 4, 5, 6 ] assign_int(x) print 'x after assign_int(x): %d' % x print assign_list(list_1) print 'list_1 after assign_list(list_1): %s' % list_1 print assign_list_element(list_2) print 'list_1 after assign_list_element(list_2): %s' % list_2 print print 'The author likes to think of all this as pass by value - but' print "when we pass a simple type like an int or float, we're passing" print "the object itself, while for collections of things we're still" print "passing the object itself, but that object _contains_ other things" print "which can easily be changed from the caller's perspective as well." benchbox-dstromberg:~/src/python-var-passing i686-pc-linux-gnu 10388 - above cmd done 2010 Sat Nov 13 01:26 PM $ ./python-argument-passing id(x) is 157519248 id(x) is 157519200 x after assign_int(x): 1 id(list_) is 3077596300 id(list_) is 3077683052 list_1 after assign_list(list_1): [1, 2, 3] id(list_) is 3077682092 id(list_) is 3077682092 list_1 after assign_list_element(list_2): [4, 101, 6] The author likes to think of all this as pass by value - but when we pass a simple type like an int or float, we're passing the object itself, while for collections of things we're still passing the object itself, but that object _contains_ other things which can easily be changed from the caller's perspective as well. benchbox-dstromberg:~/src/python-var-passing i686-pc-linux-gnu 10388 - above cmd done 2010 Sat Nov 13 01:26 PM HTH :) -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On 2:59 PM, Mark Wooding wrote: Tracubik writes: def change_integer(int_value): ... int_value = 10 ... Alas, Python is actually slightly confusing here, since the same notation `=' sometimes means assignment and sometimes means mutation. You can tell which is which by looking at the left hand side: if it's a simple variable name, the variable is assigned a new value; if it's something more complicated (e.g., indexing (`foo[0]'), or attribute selection (`foo.bar') then some mutation is (probably) going to happen: No, an (=) assignment is always an assignment. It changes the item on the left hand side to refer to a new object. But if the item on the left hand side is not a simple variable, then generally only part of its contents refers to a new object, rather than the variable itself. For example, mylist[4] = "abc" is assigning a new object to a member of the list, but does not make a new list, replacing the whole list. Your other points, such as about the augmented assignment, are quite useful, however. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace issue, Python vs numpy min/max problem
On 11/13/2010 2:41 PM, dmitrey wrote: hi all, I have the following problem: I have overloaded "max" function in my module (FuncDesigner); it works like following: if some data in arguments is of type "oofun" then my function works, elseware numpy.max() is used. Now the problem: suppose someone writes from FuncDesigner import * Noone should do that unless your module is **explicitly** designed to be *-imported and you docuement that so that they know it is OK. Now you know why * import is generally discouraged ;-). -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On Sat, Nov 13, 2010 at 5:46 AM, Tracubik wrote: > hi all, > i've this on python 2.6.6: > def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 > ... > ... a = 1 > ... l = [1,1,1] > ... > ... change_integer(a) > ... change_list(l) > ... > ... print a > ... print l > 1 > [10, 1, 1] > > why the integer value doesn't change while the list value do? > in Pascal i can choose the behavour of parametres, how this work on Python? > also a link could be appreciated http://effbot.org/zone/call-by-object.htm Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Terry Reedy writes: > On 11/13/2010 11:29 AM, Mark Wooding wrote: > > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > I disagree somewhat. An object is mutated by an internal assignment. Some object types are primitive, provided by the runtime system; there are no `internal' variables to be assigned in these cases. (It is possible in principle in Python 3 to implement all of the compound data types using only assignment and closures.) > "ll[0] = 1" assigns 1 to the 0 slot of ll. > "o.a = 1" assigns 1 to the 'a' attribute of o. > This which might be implemented by assigning 1 to the 'a' slot of o.__dict__, > just as "a=1" might be implemented by assigning 1 to the 'a' slot of a > namespace dict. There's a qualitative difference here: simple assignment has semantics defined by the language and provided by the implementation, and can therefore be understood in isolation, using only lexically apparent information; whereas the complex assignments are implemented by invoking methods on the objects mentioned on the left hand side. The objects in question may choose not to implement some other semantics, so the runtime behaviour might not be determinable even in principle without actually executing the program. (Compound assignment has the same problem writ large.) > Assignment *always* binds an object to a target. No! Assignment /never/ binds. There is syntactic confusion here too, since Python interprets a simple assignment in a function body -- in the absence of a declaration such as `global' to the contrary -- as indicating that the variable in question should be bound to a fresh variable on entry to the function. But assignment itself doesn't perform binding. (This is a persistent error in the Python community; or, less charitably, the Python community gratuitously uses the word in a different sense from the wider programming-language-theory community. See Lisp literature passim, for example.) There's a two step mapping: names -> storage locations -> values. Binding affects the left hand part of the mapping; assignment affects the right hand part. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 doesn't raise exception if database is not present/inaccessible
I understand it now. Thanks for the responses. -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace issue, Python vs numpy min/max problem
On 13/11/2010 19:55, dmitrey wrote: Well, I think I have found an appropriate solution. Regards, D. Hi Dmitrey, Would you mind briefly describing your solution? Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace issue, Python vs numpy min/max problem
Well, I think I have found an appropriate solution. Regards, D. -- http://mail.python.org/mailman/listinfo/python-list
namespace issue, Python vs numpy min/max problem
hi all, I have the following problem: I have overloaded "max" function in my module (FuncDesigner); it works like following: if some data in arguments is of type "oofun" then my function works, elseware numpy.max() is used. Now the problem: suppose someone writes from FuncDesigner import * ... a = max(0,1) so it calls FuncDesigner, it calls numpy.max and result is 0 (because in numpy it means "max of array with single element 0 along 1st axis"). But if user has not imported numpy then he expected calling ordinary Python max and thus result to be "1". Is there any way to get rid of the problem (somehow automatically determine which func should be used - numpy or Python max)? The same issue with "min", but they are equivalent, of course. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to break a string literal into multiple lines?
Tim Chase and MRAB: Thanks!! On Nov 13, 2:14 pm, Tim Chase wrote: > On 11/13/2010 12:53 PM, Zeynel wrote: > > > > > > > > > > > I have string formatting line in Google App Engine webframe webapp: > > > self.response.out.write("%s: mWEIGHT: %s > > mDATE0_integer: %s mCOUNT: %s" % (result.mUNIQUE, > > result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) > > > I would like to be able to write it as > > > self.response.out.write("%s: > > mWEIGHT: %s > > mDATE0_integer: %s > > mCOUNT: %s" > > % > > (result.mUNIQUE, > > > result.mWEIGHT, > > > mDATE0_integer, > > > result.mCOUNT,)) > > > But neither \ or enclosing the string in parens let me break the > > string literal enclosed in "" Is this possible? > > Use python's triple-quoted strings: > > self.response.out.write("""%s: > mWEIGHT: %s ... > ... """) > > Or alternatively, you can do something like > > self.response.out.write( > "%s:br />" > "mWEIGHT: %s ..." > ... > "..." > ) > > (that excludes newlines and leading whitespace in the string that > gets written, but you can modify the string contents to include > them if you need/want) > > -tkc -- http://mail.python.org/mailman/listinfo/python-list
Question on Django and Django Book
I've started working, as a tech writer, for a Spanish software configuration management company. And I'm investigating the idea of releasing a user manual in the form of a wiki that supports paragraph-by-paragraph commenting. I looked at Django Book [1][2], but it's not clear to me how much of a Django wrangler I'd need to be to create and maintain a book that works the same way. It's not even clear to me if the technology supporting Django Book is available, maintained, etc. Also, maybe there's a non-Django solution that I haven't come across in my Googling. I'd appreciate guidance in any direction! Tx, John [1] http://www.djangobook.com/about/comments/ [2] http://www.djangobook.com/en/2.0/chapter12/ -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On 11/13/2010 11:29 AM, Mark Wooding wrote: Alas, Python is actually slightly confusing here, since the same notation `=' sometimes means assignment and sometimes means mutation. I disagree somewhat. An object is mutated by an internal assignment. "ll[0] = 1" assigns 1 to the 0 slot of ll. "o.a = 1" assigns 1 to the 'a' attribute of o. This which might be implemented by assigning 1 to the 'a' slot of o.__dict__, just as "a=1" might be implemented by assigning 1 to the 'a' slot of a namespace dict. Assignment *always* binds an object to a target. Names are just one possible target. And, of course, assignment always mutates something -- a set of associations -- even if the 'something' is not a Python object itself. So '=' always means assignment/binding by mutation. The question is what gets bound to what in what set of associations. The rest of your post helps clarify that. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE debugger questions
On Oct 23, 7:29 am, Roger Davis wrote: > Are there any Python debuggers with a decent GUI out there at all that > will work on a Mac with the following features: (i) ability to pass in > a sys.srgv[] list that the program would otherwise see without the > debugger, (ii) display local variables, (iii) single-step through the > source code, and (iv) set a breakpoint? I think I can live without > anything else for the moment. > I'm very happy using the Eclipse IDE (available for Mac, PC and 'Nix) with the pydev plug-in. It's free, well supported and well behaved, and has all the debugging features you name and then some. It's also a modern code editor with code-hinting, syntax highlighting, etc. The only downside of Eclipse to me is its 'workspace' and 'project' metaphors for file organization; which take a bit of getting used to, particularly if you're used to just editing in a text editor, and then running in Idle or a command line. I still usually also have Idle open as well so I can test little code snippets quickly and easily; but mostly I work in Eclipse. Cheers - Chas -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to break a string literal into multiple lines?
On 11/13/2010 12:53 PM, Zeynel wrote: I have string formatting line in Google App Engine webframe webapp: self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) I would like to be able to write it as self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) But neither \ or enclosing the string in parens let me break the string literal enclosed in "" Is this possible? Use python's triple-quoted strings: self.response.out.write("""%s: mWEIGHT: %s ... ... """) Or alternatively, you can do something like self.response.out.write( "%s:br />" "mWEIGHT: %s ..." ... "..." ) (that excludes newlines and leading whitespace in the string that gets written, but you can modify the string contents to include them if you need/want) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to break a string literal into multiple lines?
On 13/11/2010 18:53, Zeynel wrote: I have string formatting line in Google App Engine webframe webapp: self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) I would like to be able to write it as self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s" % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) But neither \ or enclosing the string in parens let me break the string literal enclosed in "" Is this possible? Use triple-quoted strings: self.response.out.write("""%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s""" (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy code runs in empty directory, not another
On 11/13/2010 11:41 AM, Dave Angel wrote: On 2:59 PM, Beliavsky wrote: After installing numpy, scipy, and matplotlib for python 2.6 and running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 (stored as xoptimize.py) in a directory with other python codes, I got the error messages C:\python\code\mycode>python xoptimize.py Traceback (most recent call last): File "xoptimize.py", line 3, in Learn to read tracebacks. They are your debugging friend. from pylab import * xoptimize imports pylab File "c:\python26\lib\site-packages\pylab.py", line 1, in from matplotlib.pylab import * pylab imports matplotlib File "c:\python26\lib\site-packages\matplotlib\__init__.py", line 133, in import sys, os, tempfile matplotlib imports tempfile (to get a plot destination) File "c:\python26\lib\tempfile.py", line 34, in from random import Random as _Random tempfile import random (to make a 'random' tempfile name) File "C:\python\code\mycode\random.py", line 1, in Look carefully at the above line. It should have been: File "C:\python26\lib\random.py ... Ignore the remaining error cascade. When I create a new directory, copy xoptimize.py there, and run, the program works. Can someone explain why other files are "interfering" in the first case? Thanks. You have a file random.py in your code directory, which is shadowing the system random library. As you can see in the traceback. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Is it possible to break a string literal into multiple lines?
I have string formatting line in Google App Engine webframe webapp: self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s " % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) I would like to be able to write it as self.response.out.write("%s: mWEIGHT: %s mDATE0_integer: %s mCOUNT: %s " % (result.mUNIQUE, result.mWEIGHT, mDATE0_integer, result.mCOUNT,)) But neither \ or enclosing the string in parens let me break the string literal enclosed in "" Is this possible? -- http://mail.python.org/mailman/listinfo/python-list
regenerating unicodedata for py2.7 using py3 makeunicodedata.py?
Hi all, I'd like to ask about a surprising possibility I found while investigating the new unicode 6.0 standard for use in python. As python 2 series won't be updated in this regard ( http://bugs.python.org/issue10400 ), I tried my "poor man's approach" of compiling the needed pyd file with the recent unicode data (cf. the older post http://mail.python.org/pipermail/python-list/2010-March/1240002.html ) While checking the changed format, i found to my big surprise, that it is possible to generate the header files using the py3 makeunicodedata.py which has already been updated for Unicode 6.0; this is even much more comfortable than the previous versions, as the needed data are downloaded automatically. http://svn.python.org/view/python/branches/py3k/Tools/unicode/makeunicodedata.py?view=markup&pathrev=85371 It turned out, that the resulting headers are accepted by MS Visual C++ Express along with the py2.7 source files and that the generated unicodedata.pyd seems to be working work at least in the cases I tested sofar. Is this intended or even guaranteed for these generated files to be compatible across py2.7 and py3, or am I going to be bitten by some less obvious issues later? The newly added ranges and characters are available, only in the CJK Unified Ideographs Extension D the character names are not present (while categories are), but this appears to be the same in the original unicodedadata with 5.2 on CJK Unified Ideographs Extension C. >>> unicodedata.unidata_version '6.0.0' >>> unicodedata.name(u"\U0002B740") # 0x2B740-0x2B81F; CJK Unified Ideographs >>> Extension D # unicode 6.0 addition Traceback (most recent call last): File "", line 1, in ValueError: no such name >>> unicodedata.category(u"\U0002B740") 'Lo' >>> ### >>> unicodedata.unidata_version '5.2.0' >>> unicodedata.name(u"\U0002A700") # 0x2A700-0x2B73F; CJK Unified Ideographs >>> Extension C Traceback (most recent call last): File "", line 1, in ValueError: no such name >>> unicodedata.category(u"\U0002A700") 'Lo' >>> Could please anybody confirm, whether this way of updating the unicodedata for 2.7 is generaly viable or point out possible problem this may lead to? Many thanks in advance, Vlastimil Brom -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 doesn't raise exception if database is not present/inaccessible
On 2010-11-13, Ravi wrote: > import sqlite3 > con = sqlite3.connect("any string here") That is a property of the sqlite database itself. It always opens the database requested; even if it has to create a new database to do so. > and there is no error reported. You will get an error you do some If you are conserned about it, check that the database contains the schema that you were expecting before trying any other operations on it. > operations on the database which is confusing. I think sqlite3 should > change this behavior. If you believe that, you should talk to the sqlite3 people since this is a property of the database rather then a Python issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 doesn't raise exception if database is not present/inaccessible
On 13/11/2010 16:54, Ravi wrote: try this: import sqlite3 con = sqlite3.connect("any string here") and there is no error reported. You will get an error you do some operations on the database which is confusing. I think sqlite3 should change this behavior. That will open an existing database or create a new one. If it raised an exception then how would you create a new database? -- http://mail.python.org/mailman/listinfo/python-list
sqlite3 doesn't raise exception if database is not present/inaccessible
try this: import sqlite3 con = sqlite3.connect("any string here") and there is no error reported. You will get an error you do some operations on the database which is confusing. I think sqlite3 should change this behavior. -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy code runs in empty directory, not another
On 2:59 PM, Beliavsky wrote: After installing numpy, scipy, and matplotlib for python 2.6 and running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 (stored as xoptimize.py) in a directory with other python codes, I got the error messages C:\python\code\mycode>python xoptimize.py Traceback (most recent call last): File "xoptimize.py", line 3, in from pylab import * File "c:\python26\lib\site-packages\pylab.py", line 1, in from matplotlib.pylab import * File "c:\python26\lib\site-packages\matplotlib\__init__.py", line 133, in import sys, os, tempfile File "c:\python26\lib\tempfile.py", line 34, in from random import Random as _Random File "C:\python\code\mycode\random.py", line 1, in from RandomArray import standard_normal File "C:\python\code\mycode\RandomArray.py", line 1, in import ranlib ImportError: No module named ranlib When I create a new directory, copy xoptimize.py there, and run, the program works. Can someone explain why other files are "interfering" in the first case? Thanks. You have a file random.py in your code directory, which is shadowing the system random library. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Tracubik writes: > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 [...] > why the integer value doesn't change while the list value do? Because in the first case you changed a variable local to the function, and that variable was lost when the function returned; and in the second case, you modified the list value that was passed to the function. > in Pascal i can choose the behavour of parametres, how this work on > Python? You must learn to distinguish two notions to understand how this works in Python: the notions are /assigning a value to a variable/, and /mutating a value/. The former is what simple assignment `foo = ...' does: it makes the variable store a different value. Assigning a value to a function argument /never/ affects the caller in Python. It's simply not possible to write a `swap' function in Python. The latter means that a value itself changes but the relevant variables continue to store the same values. Alas, Python is actually slightly confusing here, since the same notation `=' sometimes means assignment and sometimes means mutation. You can tell which is which by looking at the left hand side: if it's a simple variable name, the variable is assigned a new value; if it's something more complicated (e.g., indexing (`foo[0]'), or attribute selection (`foo.bar') then some mutation is (probably) going to happen: these kinds of assignment are translated into method calls, so what actually happens is up to the object in question. It gets worse: compound assignment -- statements like `foo += ...' -- might either be mutation or assignment. What happens if the current value of `foo' has the an appropriate method is that the method is called, and probably mutates the value of foo; otherwise Python treats the statement as if it had been `foo = foo + (...)'. Returning, sort of, to the point: if you want to write a function which causes side-effects on its caller, then you have[1] to do it by mutating the caller's argument values. So you could write an awful `swap' function like def awful_swap(x, y): x[0], y[0] = y[0], x[0] and then you have to call it as xx = [x] yy = [y] awful_swap(xx, yy) x = xx[0] y = yy[0] but there's no good reason to actually do such a thing in Python when you can write x, y = y, x anyway. In Pascal, one tends to use `var' parameters to work around the fact that Pascal functions can only return a single value. This is true in Python too, but it isn't anywhere near as annoying because Python makes it easy (a) to combine multiple values together into a tuple (`return x, y, z') and (b) to pick tuples apart into their components again at the other end (`a, b, c = some_function()'). If you have a number of values which you find that you're combining and splitting apart repeatedly then maybe you're better off putting them together in a class with some appropriate operations. [1] In general; if the called function happens to be lexically enclosed in its caller, then it can play with its caller's variables directly -- well, in Python 3, anyway. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: drawing with the mouse with turtle...solved?
On Nov 12, 2010, at 8:48 PM, Brian Blais wrote: > > On Nov 12, 2010, at 8:05 PM, Steven D'Aprano wrote: > >> On Fri, 12 Nov 2010 19:24:50 -0500, Brian Blais wrote: >> >>> I'd like to draw on a turtle canvas, but use the mouse to direct the >>> turtle. I don't see a good way of getting the mouse coordinates and the >>> button state. >> >> I think the right way to do that is by creating an event handler to the >> turtle. These docs are for Python 2.7 turtle, but they may be applicable >> to older versions as well: >> >> http://docs.python.org/library/turtle.html#turtle.ondrag >> >> I quote: >> > turtle.ondrag(turtle.goto) >> >> Subsequently, clicking and dragging the Turtle will move it >> across the screen thereby producing handdrawings (if pen is down). >> >> >> That's probably all you need to do. > > > that's what I tried first, with no luck. I am on 2.6 on Mac OSX (Enthought > distribution). The following code: > > > import turtle > > turtle.reset() > turtle.speed(0) > turtle.ondrag(turtle.goto) > turtle.pendown() > > running it in ipython brings up a window, but clicking, dragging, or anything > like that doesn't move the turtle or draw anything. running it in just plain > python brings up the window, but it instantly closes. I added: > turtle.mainloop() > > which keeps the window open, but the clicking or dragging still doesn't move > the turtle or update the window in any way. > Here is code that "works", with at least one small oddity: import turtle def gothere(event): turtle.penup() turtle.goto(event.x-360,340-event.y) turtle.pendown() def movearound(event): turtle.goto(event.x-360,340-event.y) def release(event): turtle.penup() def reset(event): turtle.clear() turtle.reset() turtle.speed(0) c=turtle.getcanvas() c.bind("", gothere) c.bind("", movearound) c.bind("", release) c.bind("",reset) s=turtle.Screen() s.listen() the oddity is that the coordinate transformations, x-360 and 340-y, are done by eye and do not seem to be related to any of the coordinate values I could find. my screen size is 300x400, the x and y canvas scales are 1 and 1, but if I try to transform with those numbers the mouse is clearly off. any ideas? bb -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Some Machine Learning related questions
Dear Group, Hope every one is fine. I am trying to put some questions. I am developing some tool boxes for support vector machine (SVM) and hidden markov model (HMM). For HMM I was following the tutorial by Leeds University Computer Science Department, available online in HTML format, and for SVM I was following a book on Neural Networks by Simon Haykin. After comprehending them, I thought to cross check my knowledge with the original works. I referred to 1989 Rabiner paper for HMM and SVM society's tutorial for SVM. Here, I am getting some confusions. I am looking for a forum, especially an active forum, like this one (I searched for few in Google, but all seem to be very lazy), where I can post these questions. I felt this room consists of very expert people and I visit it often moreover it is very active -everytime I posed some question people solved it very nicely. If any one can suggest a solution to my queries taking his/her valuable time, I would be grateful enough. Thanks in advance. Apology if it is an unrelated question of the forum. Wishing you all a happy winter. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python] scipy code runs in empty directory, not another
On Saturday, November 13, 2010, Chris Gonnerman wrote: > On 11/13/2010 07:52 AM, Beliavsky wrote: > > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. > > You'd need to post a list of the files in the directory before we'd have any > idea why this is happening. No he doesn't. We can get that from the traceback. Bekiavsky, there's a file called random.py in your folder. Python doesn't treat the standard library fila any differently than it does your own files. It searches the path for the first file called "random" that it sees and it imports that. Since it finds your file first, that's the one it imports. The failure you're seeing is actually in your code-you're trying to import a module that shouldn't exist. In > > -- Chris. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy code runs in empty directory, not another
Beliavsky writes: > After installing numpy, scipy, and matplotlib for python 2.6 and > running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 > (stored as xoptimize.py) in a directory with other python codes, I got > the error messages > > C:\python\code\mycode>python xoptimize.py > Traceback (most recent call last): > File "xoptimize.py", line 3, in > from pylab import * > File "c:\python26\lib\site-packages\pylab.py", line 1, in > from matplotlib.pylab import * > File "c:\python26\lib\site-packages\matplotlib\__init__.py", line > 133, in > import sys, os, tempfile > File "c:\python26\lib\tempfile.py", line 34, in > from random import Random as _Random > File "C:\python\code\mycode\random.py", line 1, in > from RandomArray import standard_normal > File "C:\python\code\mycode\RandomArray.py", line 1, in > import ranlib > ImportError: No module named ranlib > > When I create a new directory, copy xoptimize.py there, and run, the > program works. Can someone explain why other files are "interfering" > in the first case? Thanks. Because you probably have a file named the same way as some pyhon or matplotlib module, and that shadows the "real" one. Try copying more and more files into your new directory to find the culprit. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
alex23 writes: > Tracubik wrote: >> why the integer value doesn't change while the list value do? > > http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm Not the issue here. The reason the OP sees a difference that there is only one way to pass parameters in python. There have been wars waged about the right name to call them. What's happening is that in the function, the parameter names are bound to the objects the caller passed in. But these names only exist in the scope of the function. So re-binding that name by doing e.g. a = 2 does not change the binding in the callers context. So because of this, no change happens in change_integer. Because there is no change to the integer itself. Actually, you can't even change an integer in pyhon. They are immutable. a = 2 a += 10 will make a point to the integer-object with the value 12. But the "old" 2 and 10 still exist. And that's where the differency in change_list is in. That gets passed a reference to a _mutable_ object, a list. And if you mutatet that list, you end up with a changed object in the callers context as well. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python] scipy code runs in empty directory, not another
On 11/13/2010 07:52 AM, Beliavsky wrote: After installing numpy, scipy, and matplotlib for python 2.6 and running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 (stored as xoptimize.py) in a directory with other python codes, I got the error messages C:\python\code\mycode>python xoptimize.py Traceback (most recent call last): File "xoptimize.py", line 3, in from pylab import * File "c:\python26\lib\site-packages\pylab.py", line 1, in from matplotlib.pylab import * File "c:\python26\lib\site-packages\matplotlib\__init__.py", line 133, in import sys, os, tempfile File "c:\python26\lib\tempfile.py", line 34, in from random import Random as _Random File "C:\python\code\mycode\random.py", line 1, in from RandomArray import standard_normal File "C:\python\code\mycode\RandomArray.py", line 1, in import ranlib ImportError: No module named ranlib When I create a new directory, copy xoptimize.py there, and run, the program works. Can someone explain why other files are "interfering" in the first case? Thanks. You'd need to post a list of the files in the directory before we'd have any idea why this is happening. -- Chris. -- http://mail.python.org/mailman/listinfo/python-list
scipy code runs in empty directory, not another
After installing numpy, scipy, and matplotlib for python 2.6 and running the code from http://www.scipy.org/Cookbook/OptimizationDemo1 (stored as xoptimize.py) in a directory with other python codes, I got the error messages C:\python\code\mycode>python xoptimize.py Traceback (most recent call last): File "xoptimize.py", line 3, in from pylab import * File "c:\python26\lib\site-packages\pylab.py", line 1, in from matplotlib.pylab import * File "c:\python26\lib\site-packages\matplotlib\__init__.py", line 133, in import sys, os, tempfile File "c:\python26\lib\tempfile.py", line 34, in from random import Random as _Random File "C:\python\code\mycode\random.py", line 1, in from RandomArray import standard_normal File "C:\python\code\mycode\RandomArray.py", line 1, in import ranlib ImportError: No module named ranlib When I create a new directory, copy xoptimize.py there, and run, the program works. Can someone explain why other files are "interfering" in the first case? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Tracubik wrote: > why the integer value doesn't change while the list value do? http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm -- http://mail.python.org/mailman/listinfo/python-list
strange behavor....
hi all, i've this on python 2.6.6: >>> def change_integer(int_value): ... int_value = 10 ... ... def change_list(list): ... list[0] = 10 ... ... a = 1 ... l = [1,1,1] ... ... change_integer(a) ... change_list(l) ... ... print a ... print l 1 [10, 1, 1] why the integer value doesn't change while the list value do? in Pascal i can choose the behavour of parametres, how this work on Python? also a link could be appreciated Thanks in advance Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Is a 32-bit build faster than a 64-bit build
On Fri, 12 Nov 2010 13:24:09 -0800 (PST) Raymond Hettinger wrote: > Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for > Django or some other webserver? > > My hypotheses is that for apps not needing the 64-bit address space, > the 32-bit version has better memory utilization and hence better > cache performance. If so, then switching python versions may enable a > single server to handle a greater traffic load. Has anyone here tried > that? On micro-benchmarks, x86-64 is always faster by about 10-30% compared to x86, simply because of the extended register set and other additional niceties. On a benchmark stressing the memory system a little more such as dcbench-py3k.py in http://bugs.python.org/issue9520, the 64-bit build is still faster until the tested data structure (a large dict) overwhelms the 2MB last-level cache in my CPU, after which the 32-bit build becomes 10% faster for the same numbers of elements: To be clear, here are the figures in 64-bit mode: 1 words (9092 keys), 2893621 inserts/s, 13426069 lookups/s, 86 bytes/key (0.8MB) 2 words ( 17699 keys), 3206654 inserts/s, 12338002 lookups/s, 44 bytes/key (0.8MB) 4 words ( 34490 keys), 2613517 inserts/s, 7643726 lookups/s, 91 bytes/key (3.0MB) 8 words ( 67148 keys), 2579562 inserts/s, 4872069 lookups/s, 46 bytes/key (3.0MB) 16 words ( 130897 keys), 2377487 inserts/s, 5765316 lookups/s, 48 bytes/key (6.0MB) 32 words ( 254233 keys), 2119978 inserts/s, 5003979 lookups/s, 49 bytes/key (12.0MB) 64 words ( 493191 keys), 1965413 inserts/s, 4640743 lookups/s, 51 bytes/key (24.0MB) 128 words ( 956820 keys), 1854546 inserts/s, 4338543 lookups/s, 52 bytes/key (48.0MB) And here are the figures in 32-bit mode: 1 words (9092 keys), 2250163 inserts/s, 9487229 lookups/s, 43 bytes/key (0.4MB) 2 words ( 17699 keys), 2543235 inserts/s, 7653839 lookups/s, 22 bytes/key (0.4MB) 4 words ( 34490 keys), 2360162 inserts/s, 8851543 lookups/s, 45 bytes/key (1.5MB) 8 words ( 67148 keys), 2415169 inserts/s, 8581037 lookups/s, 23 bytes/key (1.5MB) 16 words ( 130897 keys), 2203071 inserts/s, 6914732 lookups/s, 24 bytes/key (3.0MB) 32 words ( 254233 keys), 2005980 inserts/s, 5670133 lookups/s, 24 bytes/key (6.0MB) 64 words ( 493191 keys), 1856385 inserts/s, 4929790 lookups/s, 25 bytes/key (12.0MB) 128 words ( 956820 keys), 1746364 inserts/s, 4530747 lookups/s, 26 bytes/key (24.0MB) However, it's not obvious to me that a program like "Django or some other webserver" would have really bad cache locality. Even if the total working set is larger than the CPU cache, there can still be quite a good cache efficiency if a large fraction of CPU time is spent on small datasets. By the way, I've been experimenting with denser dicts and with linear probing (in the hope that it will improve cache efficiency and spatial locality in real applications), and there doesn't seem to be adverse consequences on micro-benchmarks. Do you think I should upload a patch? Regards Antoine. -- http://mail.python.org/mailman/listinfo/python-list
Re: drawing with the mouse with turtle
On Nov 13, 2010, at 1:31 AM, Dennis Lee Bieber wrote: > On Fri, 12 Nov 2010 20:48:34 -0500, Brian Blais > declaimed the following in gmane.comp.python.general: > >> turtle.ondrag(turtle.goto) >> turtle.pendown() >> >> > I'm not familiar with the turtle module but... would it make more > sense to drop the pen before dragging the turtle around? > > """ > Subsequently, clicking and dragging the Turtle will move it across the > screen thereby producing handdrawings (if pen is down). > """ > > "if pen is down" <=== > there is no change by changing the order, but I didn't expect one. since ondrag is binding a callback, which is only called when the event happens, I figure that the pen has to be down when the callback happens, not when the binding occurs. since the pen is down (and never lifted), when I start dragging the mouse around after that it should work...but doesn't seem to. thanks, bb -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON...
NAUGHTY GIRL, WANNA NAUGHTY WITH ME, COME ON... FREE GOLD MEMBER FOR FEMALE PROFILE http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour http://goo.gl/1bour -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE debugger questions
In article , Roger Davis wrote: > Thanks for that info, Ned, I can now get the sys.argv[] list I need, > that's a big help! However, is there any other way to set a breakpoint > in idle that will work on Mac OS X, maybe entering a manual command > somewhere with a specified line number? Inability to set a breakpoint > is an absolute showstopper for me, the code I am trying to debug loops > way too much to be manually steppable in a human time frame. Sorry about the long delay in replying. It turns out that IDLE's breakpoint facility is currently unusable on OS X when Python Tkinter is built with Aqua Tk, the default on OS X. The reason: IDLE implements the Set and Clear Breakpoints menu options through a context popup menu but the popup menus don't work with Aqua Tk. On other systems, the popup menus are bound to the Right mouse button. But on OS X, there's no guarantee that there is more than one button (the Left) and, even if there is, the button bindings are different for Aqua Tk. The net effect is that you can't make the popup menus appear with or without a three-button mouse or equivalent. As far as I can tell, this has been an issue ever since Python started using Aqua Tk on OS X instead of X11 Tk, many releases ago. I've opened an issue for the problem and supplied a patch to have IDLE use Control-Click for popups on OS X as is common in other applications. http://bugs.python.org/issue10404 Thanks for calling this problem to our attention! -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
hello
http://infoukhotels.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list