Default method arguments

2005-11-15 Thread gregory . petrosyan
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ) print x All I want is to make self.data the default argument for self.f(). (I want to use 'A' class as following : myA = A(5) myA.f() and get printed '5' as a resu

Re: Default method arguments

2005-11-15 Thread Gregory Petrosyan
I want to find REALLY NICE AND PYTHONIC solution (if any) -- http://mail.python.org/mailman/listinfo/python-list

Re: Default method arguments

2005-11-15 Thread Gregory Petrosyan
Thanks a lot, but that's not what I do really want. 1) f() may have many arguments, not one 2) I don't whant only to _print_ x. I want to do many work with it, so if I could simply write def f(self, x = self.data) (*) it would be much better. By the way, using class A(

Re: Default method arguments

2005-11-15 Thread Gregory Petrosyan
Great thanks, Alex! -- http://mail.python.org/mailman/listinfo/python-list

Re: Default method arguments

2005-11-15 Thread Gregory Petrosyan
I'm not very familiar with Python, so please explain me why should containers be used? For example in one of Paul Graham's essays there's an example of 'generator of accumulators' in Python: def foo(n): s = [n] def bar(i): s[0] += i return s[0] return bar 1) So, why

Re: Default method arguments

2005-11-15 Thread Gregory Petrosyan
Thanks a lot, I understood the rule. Let's don't discuss this (containers etc.) anymore, or it'll be offtopic. -- http://mail.python.org/mailman/listinfo/python-list

Re: Default method arguments

2005-11-18 Thread Gregory Petrosyan
Thanks Martin, you are right. -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree - Why not part of the core?

2005-12-14 Thread Gregory Petrosyan
[EMAIL PROTECTED]:~$ python Python 2.5a0 (#1, Dec 14 2005, 14:11:55) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xml.etree.ElementTree as ET Traceback (most recent call last): File "", line 1, in File "/usr/l

Re: ElementTree - Why not part of the core?

2005-12-14 Thread Gregory Petrosyan
This I've got after make install and [EMAIL PROTECTED]:~$ python When launching ./python from ./trunk, everything is OK. Is it a problem with me or with installation? -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree - Why not part of the core?

2005-12-14 Thread Gregory Petrosyan
[EMAIL PROTECTED]:~$ python Python 2.5a0 (#4, Dec 14 2005, 22:08:59) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from xml.etree import ElementTree as ET >>> ET >>> Thanks for fix. -- http://mail.python.org/mailman/l

Re: Merging Subway and TurboGears

2005-12-22 Thread Gregory Petrosyan
+1 for Kid -- it's more pythonic IMHO. -- http://mail.python.org/mailman/listinfo/python-list

Optional typecheck

2006-01-07 Thread Gregory Petrosyan
Hello all! Please enlighten me about optional typecheck: 1) Will it be available in Python 2.5? 2) Will it support things like def f(a: int | float) 3) Will it support interface checking like def g(a: BookInterface) or even mix like def k(a: file | BookInterface) 4) Will it support things li

Re: Optional typecheck

2006-01-09 Thread Gregory Petrosyan
Btw, why not in 2.x? Thanks for link, nice module. But I prefer built-in solution, that I can use in any piece of python code. So, I'll wait for version of Python that supports it. -- http://mail.python.org/mailman/listinfo/python-list

Arithmetic sequences in Python

2006-01-16 Thread Gregory Petrosyan
Please visit http://www.python.org/peps/pep-0204.html first. As you can see, PEP 204 was rejected, mostly because of not-so-obvious syntax. But IMO the idea behind this pep is very nice. So, maybe there's a reason to adopt slightly modified Haskell's syntax? Something like [1,3..10] --> [1,3,5,

Re: Arithmetic sequences in Python

2006-01-16 Thread Gregory Petrosyan
_Consistentsy_ is what BDFL rejects, if I understand pep right. As for me, it's not too god to have similar syntax for really different tasks. And [1:10] is really not obvious, while [1..10] is. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-16 Thread Gregory Petrosyan
Thanks for your replies. So, some problems and possible solutions: 1) [f(n), f(n)-1 .. 0] can be easily catched by interpreter, and f(n) can be evaluated only once. 2) if you need right border excluded, I think [0 .. n) is very clear (and consistent with mathematics). And about brakets highlighti

Re: Arithmetic sequences in Python

2006-01-16 Thread Gregory Petrosyan
Steven D'Aprano wrote: > Python indexing deliberately goes to one-past-the-end counting for a > reason: it helps prevent off-by-one signpost errors. This syntax goes > against that decision, and adds one more thing to memorise about Python: > the end index is not included in the list, except for ar

Re: Arithmetic sequences in Python

2006-01-17 Thread Gregory Petrosyan
Some ideas: 1) Let [a,b .. c] be *ordinary list* ! Just like [1,2,3]. Are there any questions why 3 is included in [1,2,3]? IMO it's more correct to think about [first, next .. last] as about syntax for list creation, but not as about "syntax-to-replace-range-function". (And, because it's an ordi

Re: Arithmetic sequences in Python

2006-01-17 Thread Gregory Petrosyan
Hmm, and why not? Or you realy hate such behaviour? Note, everything I post here is just some ideas I want to discuss, and to make these ideas better after discussion. And this particular idea needs to be discussed, too. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-17 Thread Gregory Petrosyan
Hey guys, this proposal has already been rejected (it is the PEP 204). -- http://mail.python.org/mailman/listinfo/python-list

nested functions

2006-06-14 Thread Gregory Petrosyan
I often make helper functions nested, like this: def f(): def helper(): ... ... is it a good practice or not? What about performance of such constructs? -- Regards, Gregory. -- http://mail.python.org/mailman/listinfo/python-list

Re: nested functions

2006-06-15 Thread Gregory Petrosyan
Thanks everybody for your help! -- http://mail.python.org/mailman/listinfo/python-list

"pre-"*10 + "PEP": extension to the list comprehensions & genexps syntax

2006-01-25 Thread Gregory Petrosyan
This is revised version of "Arithmetic sequences in Python" proposal. I don't want this topic to become as bloated with offtopic as "ASiP". Please post here corresponding info only. Your (revised) comments (possibly already posted to "ASiP") are welcome. The first thing I want to mention is that,

Re: Automatic Logging

2006-01-27 Thread Gregory Petrosyan
My decorator bike: import logging import traceback logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s:\n%(message)s\n", filename="/tmp/py.log", filemode='w') def log(f): def new_f(*args, **kwds): try

Re: Automatic Logging

2006-01-27 Thread Gregory Petrosyan
Sorry for broken indentation. -- http://mail.python.org/mailman/listinfo/python-list

Pythonic gui format?

2006-02-13 Thread Gregory Petrosyan
Buenos dias, amigos! I have to write _simple_ gui library, for embedding into game. My first attempt was to use XML: isn't it cute to describe ui in such a way: Hello World! (some text here) first element second one... (or something si

Re: Pythonic gui format?

2006-02-13 Thread Gregory Petrosyan
Thanks for your reply. But isn't python code more flexible than XML? I think it's not harder to edit py file than xml file. Also python can give me more speed than xml, and possibly python code can be integrated better with rest of app (because of absence of extra layer called "XML"). Has anybody h

Re: Pythonic gui format?

2006-02-13 Thread Gregory Petrosyan
Nice, thanks! BTW, maybe decorators could do good job here (something like @expose in TG?) -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic gui format?

2006-02-13 Thread Gregory Petrosyan
I need format, specialised for manual editing. (And in this case a) I don't want/need to develop/find GUI forms editors etc; b) maybe python is better for manual work? XML is pretty nice for machines, but what about human mind: what is closer to it?) Anyway, thanks for your help & attention. --

Re: Pythonic gui format?

2006-02-14 Thread Gregory Petrosyan
> > Isn't it ugly a bit? >I'd even say 'ugly 16-bits' !-) You are right of course. Those "examples" are really bad, and, most of all, really un-pythonic. Thanks for JSON. It's more clean&simple than XML, but my main idea is to remove any extra layer between Python and GUI. I want all GUI elemen

Re: Pythonic gui format?

2006-02-15 Thread Gregory Petrosyan
Bruno: in your original example, how can it be specified that image should be placed before text? Of course, it *can* be done with one extra level of wrapping of gui elements in list... did you mean that? Patrik: thanks a lot! Stan (the way it represents XML) is almost what I am looking for. --

how to break a for loop?

2006-02-20 Thread Gregory Petrosyan
Hello! It's 1:56 o'clock in St.-Petersburg now, and I am still coding... maybe that's why I encountered stupid problem: I need to remove zeros from the begining of list, but I can't :-(. I use for i,coef in enumerate(coefs): if coef == 0: del coefs[i]

Re: how to break a for loop?

2006-02-21 Thread Gregory Petrosyan
Thanks to everybody for help. Python community is very friendly and helpfull indeed! -- http://mail.python.org/mailman/listinfo/python-list

What's up with this code?

2006-02-22 Thread Gregory Petrosyan
Hello, it's me again. I am trying to optimise small module for working with polynomials, and I have encountered problem: new, optimised, code, doesn't work in some specific case. Here's the old version of the code: (3x^2 + 2x + 1 <=> poly([3, 2, 1]), btw) def __add__(self, other): "

Re: What's up with this code?

2006-02-23 Thread Gregory Petrosyan
That's it! Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list

Re: What's up with this code?

2006-02-23 Thread Gregory Petrosyan
Oh, by the way, is there any documentation about time of execution of standart functions (is len(list) O(1) or O(n), etc) and is there any C version of decimal? -- http://mail.python.org/mailman/listinfo/python-list

Re: What's up with this code?

2006-02-23 Thread Gregory Petrosyan
Again, thanks a lot! I'm optimising my polynomial module as hard as possible, because when it used native floats/integers it was very fast, but in some specific cases -- too inaccurate. So, I migrated to decimals, and module began to be very slow. Current success is nearly 4x speedup, and now it se

Re: python-list/python-dev quoting style

2006-02-26 Thread Gregory Petrosyan
"me" wrote: > I see. > -- > me Wonderfull. -- http://mail.python.org/mailman/listinfo/python-list

enumerate() question

2006-05-22 Thread Gregory Petrosyan
Hello! I have a question for the developer[s] of enumerate(). Consider the following code: for x,y in coords(dots): print x, y When I want to iterate over enumerated sequence I expect this to work: for i,x,y in enumerate(coords(dots)): print i, x, y Unfortunately, it doesn't =( and I

Re: enumerate() question

2006-05-22 Thread Gregory Petrosyan
Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list

Re: Speed up this code?

2006-05-26 Thread Gregory Petrosyan
# Paul Rubin's version [EMAIL PROTECTED]:~$ python -mtimeit "import test2" "test2.primes(1000)" 100 loops, best of 3: 14.3 msec per loop # version from the Cookbook [EMAIL PROTECTED]:~$ python -mtimeit "import test1" "test1.primes(1000)" 1000 loops, best of 3: 528 usec per loop -- http://mail.py

write() vs. writelines()

2006-05-26 Thread Gregory Petrosyan
My question is: why write(''.join(...)) works slowly than writelines(...)? Here's the code: import sys import random #try: #import psyco #psyco.full() #except ImportError: #pass def encrypt(key, infile, outfile, bufsize=65536): random.seed(key) in_buf = infile.read(bufsize)

Re: write() vs. writelines()

2006-05-26 Thread Gregory Petrosyan
Thanks for your reply. I understand this fact, but I wonder why writelines() works slowly -- I think C code can be optimised to work faster than Python one. Is it correct that writelines(...) is just a shorthand for for ch in ...: file.write(ch) ? -- http://mail.python.org/mailman/listinfo/

Re: Python 2.5 Schedule

2006-03-19 Thread Gregory Petrosyan
Yes, it's very annoying to see VC8 warnings on perfectly legal C constructs (AFAIK even sprinf is now considered "unsafe", MS wants everybody to use sprintf_s). But the optimisation capacities of VC8 are really great. Maybe someone can measure the speedup? P.S. there's an "_CRT_SECURE_NO_DEPRECATE

Re: python library for web discussions

2006-03-19 Thread Gregory Petrosyan
reddit is written with webpy (webpy.org), maybe you should give it a try? -- http://mail.python.org/mailman/listinfo/python-list

Why "class exceptions" are not deprecated?

2006-03-21 Thread Gregory Petrosyan
1) From 2.4.2 documentation: There are two new valid (semantic) forms for the raise statement: raise Class, instance raise instance 2) In python: >>> raise NameError Traceback (most recent call last): File "", line 1, in ? NameError >>> help(NameError) Help on class NameError in module exception

Re: Why "class exceptions" are not deprecated?

2006-03-21 Thread Gregory Petrosyan
Thanks for answer. But what about "Explicit is better than implicit"? -- http://mail.python.org/mailman/listinfo/python-list

Re: Why "class exceptions" are not deprecated?

2006-03-21 Thread Gregory Petrosyan
"The first argument to raise names the exception to be raised. The optional second argument specifies the exception's argument. Alternatively, the above could be written as raise NameError('HiThere'). Either form works fine, but there seems to be a growing stylistic preference for the latter." Are

Why "class exceptions" are not deprecated?

2006-03-21 Thread Gregory Petrosyan
1) From 2.4.2 documentation: There are two new valid (semantic) forms for the raise statement: raise Class, instance raise instance 2) In python: >>> raise NameError Traceback (most recent call last): File "", line 1, in ? NameError >>> help(NameError) Help on class NameError in module exception