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
I want to find REALLY NICE AND PYTHONIC solution (if any)
--
http://mail.python.org/mailman/listinfo/python-list
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(
Great thanks, Alex!
--
http://mail.python.org/mailman/listinfo/python-list
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
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
Thanks Martin, you are right.
--
http://mail.python.org/mailman/listinfo/python-list
[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
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
[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
+1 for Kid -- it's more pythonic IMHO.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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,
_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
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
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
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
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
Hey guys, this proposal has already been rejected (it is the PEP 204).
--
http://mail.python.org/mailman/listinfo/python-list
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
Thanks everybody for your help!
--
http://mail.python.org/mailman/listinfo/python-list
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,
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
Sorry for broken indentation.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
Nice, thanks!
BTW, maybe decorators could do good job here (something like @expose in
TG?)
--
http://mail.python.org/mailman/listinfo/python-list
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.
--
> > 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
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.
--
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]
Thanks to everybody for help. Python community is very friendly and
helpfull indeed!
--
http://mail.python.org/mailman/listinfo/python-list
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):
"
That's it! Thanks a lot!
--
http://mail.python.org/mailman/listinfo/python-list
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
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
"me" wrote:
> I see.
> --
> me
Wonderfull.
--
http://mail.python.org/mailman/listinfo/python-list
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
Thanks a lot.
--
http://mail.python.org/mailman/listinfo/python-list
# 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
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)
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/
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
reddit is written with webpy (webpy.org), maybe you should give it a
try?
--
http://mail.python.org/mailman/listinfo/python-list
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
Thanks for answer. But what about "Explicit is better than implicit"?
--
http://mail.python.org/mailman/listinfo/python-list
"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
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
49 matches
Mail list logo