Re: complex numbers

2005-01-13 Thread Antoon Pardon
Op 2005-01-12, It's me schreef <[EMAIL PROTECTED]>:
> Precisely.   One have to convert complex number into vectors, and vector of
> complex numbers into vector of vectors, list of complex numbers into list of
> vectors, , you get the idea.

Wrong. My vector example was an illustration that you can build a user
class that behaves as you want. Python doesn't has a vecor class build
in. Yet I could write a vector class that behaved as you wished with
regard to your twice function.

What can be done for a vector class can be done again for a complex
class, no need to use the vector class for complex numbers.

> And my code no longer look like the equation I have on paper...
>
> Like I said, I've travelled down that path before with C++ and Modelica.
> It gets ugly.

Ugly, where? In the implementation of the class? That is possible.
In the use of the class, as you suggest by writing that
your code no longer looks like the equation you have on paper.

In that case I suggest the class was poorly done.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-13 Thread Tim Roberts
Stephen Thorne <[EMAIL PROTECTED]> wrote:

>On 12 Jan 2005 16:21:29 -0800, PJDM <[EMAIL PROTECTED]> wrote:
>> Maybe P3K will have an integer literal like "n_b" for "the integer n in
>> base b".
>
>I would actually like to see pychecker pick up conceptual errors like this:
>
>import datetime
>datetime.datetime(2005, 04,04)

Why is that a conceptual error?  Syntactically, this could be a valid call
to a function.  Even if you have parsed and executed datetime, so that you
know datetime.datetime is a class, it's quite possible that the creation
and destruction of an object might have useful side effects.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-13 Thread Antoon Pardon
Op 2005-01-12, Steve Holden schreef <[EMAIL PROTECTED]>:
>
> Given that Guido is on record as saying that expressions aren't 
> statements because he wants those things to be separate, I don't really 
> see why there's this consistent pressure to reverse that decision.

Well, it seems that Guido is wrong then. The documentation clearly
states that an expression is a statement.

More specifically, everywhere you can use a statement, you can
simply use an expression according to the python syntax.

That makes the set of expressions a subset of the set of
statements and thus makes an expression a statement.

> Which would be a worthier goal than trying to graft macros on to Python. 
> You responded that macros would be difficult to implement in m4 because 
> (in essence) of the indented structure of Python. I'm not convinced 
> they'd be any easier in Python, and I'm *certainly* not convinced that 
> their addition would improve Python's readability.
>
> At best it would offer new paradigms for existing constructs (violating 
> the "there should be one obvious way to do it" zen); at worst it would 
> obfuscate the whole language.

That zen is already broken. Look at the number of answers one gets
if a newbee askes for a ternary operator. I think that a simple
ternary operator or macro's with an official supported macro that
implemented the ternary operator would have been far closer to
the spirit of only having one obvious way than what we have now.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 16:51:46 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote:

>On 12 Jan 2005 22:36:54 -0800, yaipa <[EMAIL PROTECTED]> wrote:
>> What would be the common sense way of finding a binary pattern in a
>> .bin file, say some 200 bytes, and replacing it with an updated pattern
>> of the same length at the same offset?
>> 
>> Also, the pattern can occur on any byte boundary in the file, so
>> chunking through the code at 16 bytes a frame maybe a problem.  The
>> file itself isn't so large, maybe 32 kbytes is all and the need for
>> speed is not so great, but the need for accuracy in the
>> search/replacement is very important.
>
>Okay, given the requirements.
>
>f = file('mybinfile')
>contents = f.read().replace(oldbinstring, newbinstring)
>f.close()
>f = file('mybinfile','w')
>f.write(contents)
>f.close()
>
>Will do it, and do it accurately. But it will also read the entire
>file into memory.
>
You must be on linux or such, otherwise you would have shown opening the
_binary_ files (I assume that's what a .bin file is) with 'rb' and 'wb', IWT.

Not sure what system the OP was/is on.

BTW, I'm sure you could write a generator that would take a file name
and oldbinstring and newbinstring as arguments, and read and yield nice
os-file-system-friendly disk-sector-multiple chunks, so you could write

fout = open('mynewbinfile', 'wb')
for buf in updated_file_stream('myoldbinfile','rb', oldbinstring, 
newbinstring):
fout.write(buf)
fout.close()

(left as an exercise ;-)
(modifying a file "in place" is another exercise)
(doing the latter with defined maximum memory buffer usage
 even when mods increase the length of the file is another ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Why would I get a TypeEror?

2005-01-13 Thread Harper, Gina
Because you can't take the len() of an integer.  Try casting a as a str:
b=(1,len(str(a)))[isinstance(a,(list,tuple,dict))]

-Original Message-
From: It's me [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 12, 2005 12:35 PM
To: python-list@python.org
Subject: Why would I get a TypeEror?


For this code snip:

a=3

b=(1,len(a))[isinstance(a,(list,tuple,dict))]

Why would I get a TypeError from the len function?

Thanks,



--
http://mail.python.org/mailman/listinfo/python-list


Re: java 5 could like python?

2005-01-13 Thread Olaf Delgado-Friedrichs
Roman Suzi wrote:
-Realying on ides is imposible due to python dinamic nature,very litle(next
to nothing) assistance can be espected from them.

Class browsing and auto-completion are probably the only features
I sometime miss. But otherwise what IDEs are for?
Refactoring? You got to admit, Bicycle Repair Man is not much of a 
superhero.

Eclipse's refactoring capabilies and the standard library was what drove 
me from Python to Java, although I still like Python much better as a 
language.

Cheers, O.
--
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-13 Thread Tim Roberts
Simon Wittber <[EMAIL PROTECTED]> wrote:

>I've noticed that a few ASPN cookbook recipes, which are recent
>additions, use classic classes.
>
>I've also noticed classic classes are used in many places in the
>standard library.
>
>I've been using new-style classes since Python 2.2, and am suprised
>people are still using the classic classes.
>
>Is there a legitimate use for classic classes that I am not aware of?
>Is there a project to specifically migrate standard library classes to
>new-style classes?

Probably because there is still no compelling reason to break the old
habits and type those 6 extra characters.

Once a person has a case where the new classes make a difference, I suspect
they catch the new habit and never look back.  I haven't crossed that
threshhold yet.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Nick Craig-Wood
Stephen Thorne <[EMAIL PROTECTED]> wrote:
>  Why not use a regexp based approach.

Good idea...  You could also use sre.Scanner which is supposed to be
fast like this...

import re, sre

scanner = sre.Scanner([
(r"\.php$", "application/x-php"),
(r"\.(cc|cpp)$", "text/x-c++-src"),
(r"\.xsl$", "xsl"),
(r"Makefile", "text/x-makefile"),
(r".", None),
])

def detectMimeType( filename ):
t = scanner.scan(filename)[0]
if len(t) < 1:
return None
# raise NoMimeError
return t[0]


for f in ("index.php", "index.php3", "prog.cc", "prog.cpp", "flodge.xsl", 
"Makefile", "myMakefile", "potato.123"):
print f, detectMimeType(f)

...

prints

index.php application/x-php
index.php3 None
prog.cc text/x-c++-src
prog.cpp text/x-c++-src
flodge.xsl xsl
Makefile text/x-makefile
myMakefile text/x-makefile
potato.123 None

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: property () for Java Programmers ?

2005-01-13 Thread michael . bierenfeld
> Note that I used 'c = C()' instead of 'c = C' as in your code.
Hello,

thanks that was the problem. *hmpf* :-)

Michael

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie q

2005-01-13 Thread Stephen Thorne
On Thu, 13 Jan 2005 17:05:39 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote:
> 
> "Stephen Thorne" <[EMAIL PROTECTED]> ÑÐÐÐÑÐÐ/ÑÐÐÐÑÐÐÐ Ð 
> 
> ÑÐÐÐÑÑÑÐÐ: news:[EMAIL PROTECTED]
> On Thu, 13 Jan 2005 15:55:10 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote:
> > how to get rid of 'for' operator in the code?
> >
> > import os, os.path
> >
> > def _test():
> > src = 'C:\\Documents and Settings\\ÐÐÐÑ\\My Documents\\My Music\\'
> >
> > for i in [x for x in os.listdir(src) if
> > os.path.isfile(os.path.join(src,
> > x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u']:
> > os.remove(os.path.join(src, i))
> >
> > if __name__ == '__main__':
> > _test()
> 
> import glob
> for x in glob.glob("*.m3u"):
> os.remove(x)
> 
> i want to wipe out 'for x in []: f(x)' using map, lambda, reduce, filter and
> List
> Comprehensions [x for x in []]
> just don't get how to add string to all elements of list

Here's a few ways,

map(os.remove, glob.glob("*.m3u"))
[os.remove(x) for x in glob.glob("*.m3u")]

[os.remove(x) for x in os.listdir(src) if
 os.path.isfile(os.path.join(src, x)) 
 and len(x.split('.')) > 1 
 and x.split('.')[-1].lower() == 'm3u']

def myfilter(x):
  return os.path.isfile(os.path.join(src, x))  and len(x.split('.')) >
1  and x.split('.')[-1].lower() == 'm3u'
map(os.remove, filter(myfilter, os.listdir(src)))

Regards,
Stephen Thorne.
--
http://mail.python.org/mailman/listinfo/python-list


Re: else condition in list comprehension

2005-01-13 Thread Andrey Tatarinov
Steve Holden wrote:
Nick Coghlan wrote:
Luis M. Gonzalez wrote:
Hi there,
I'd like to know if there is a way to add and else condition into a
list comprehension. I'm sure that I read somewhere an easy way to do
it, but I forgot it and now I can't find it...
for example:
z=[i+2 for i in range(10) if i%2==0]
what if I want i to be "i-2" if i%2 is not equal to 0?
Hmm:
z = [newval(i) for i in range(10)] using:
def newval(x):
if x % 2:
return x - 2
else:
return x + 2
Just some more mental twiddling relating to the thread on statement 
local namespaces.

I presume the point of this is to avoid polluting the local namespace 
with "newval". I further presume you also have plans to do something 
about "i"? ;-)
no, the point is in grouping definition of newval() with place where it 
is used.
--
http://mail.python.org/mailman/listinfo/python-list


site.here on python 2.4

2005-01-13 Thread ariza

greetings. it seems that the attribute site.here, of the site module,
has vanished in python 2.4. up until python 2.3, site.here seemed (to
me at least) a convenient way to get the complete path to the python
library on any platform:

>>> import site
>>> site.here
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'

i do not see any information about this change save that in the new
documentation it says:

"""
This module is automatically imported during initialization. The
automatic import can be suppressed using the interpreter's -S option.

Importing this module will append site-specific paths to the module
search path.
"""

can anyone propose a similarly effective and cross-platform solution
for easily discovering the the library path on any python installation?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reference or pointer to some object?

2005-01-13 Thread Antoon Pardon
Op 2005-01-12, Jeff Shannon schreef <[EMAIL PROTECTED]>:
> Torsten Mohr wrote:
>
>> I still wonder why a concept like "references" was not
>> implemented in Python.  I think it is (even if small)
>> an overhead to wrap an object in a list or a dictionary.
>
> Because Python uses a fundamentally different concept for variable 
> names than C/C++/Java (and most other static languages).  In those 
> languages, variables can be passed by value or by reference; neither 
> term really applies in Python.  (Or, if you prefer, Python always 
> passes by value, but those values *are* references.)

I would think the reference was the id. As such python always
passes by reference, as the id of the parameter is the id
of the argument.

> Python doesn't 
> have lvalues that contain rvalues; Python has names that are bound to 
> objects.  Passing a parameter just binds a new name (in the called 
> function's namespace) to the same object.
>
> It's also rather less necessary to use references in Python than it is 
> in C et. al.

You use nothing but references in Python, that is the reason why
if you assign a mutable to a new name and modify the object through
either name, you see the change through both names.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: site.here on python 2.4

2005-01-13 Thread Fredrik Lundh
"ariza" <[EMAIL PROTECTED]> wrote:


> greetings. it seems that the attribute site.here, of the site module,
> has vanished in python 2.4. up until python 2.3, site.here seemed (to
> me at least) a convenient way to get the complete path to the python
> library on any platform.

"here" was a temporary variable used to get the exact location of
the LICENSE file.  in Python 2.4, that code has been moved into
a function, in which "here" is still a temporary variable.

was it documented somewhere else?

> can anyone propose a similarly effective and cross-platform solution
> for easily discovering the the library path on any python installation?

the library path is defined by the sys.path variable, which contains a list
of library directories.

sys.prefix gives you the installation root, sys.executable tells you where
the interpreter is.

if you need the exact behaviour of "site.here", you can do

import os
here = os.path.dirname(os.__file__)

but I don't really see why your program should have to care about
anything but the path...

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils linux script installation broken?

2005-01-13 Thread Cory Davis
Thanks for the help Chris. I tried the -E option, and also installing as 
root with no change - the scripts in the bin directory still end up with 
#!None on the first line.  Next step is to reinstall Python 2.4, and if 
that doesn't work I'll just stick with 2.3.4.

Cheers,
Cory.
Christopher De Vries wrote:
I've got python 2.3.3, 2.4, and 1.5.2 (which came preinstalled) on my
linux box. It's redhat 7.2 (I know... I would upgrade, but it would
void my service contract, so I just install things in /usr/local). You
can check if PYTHONHOME or PYTHONPATH are set, which may somehow be
interfering. I don't have those variables set. If they are set, you
could try running:
python -E setup.py install
The -E option should make python ignore those environment variables.
Good luck, I hope this helps.
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-13 Thread Fredrik Lundh
Antoon Pardon wrote:

> Well, it seems that Guido is wrong then. The documentation clearly
> states that an expression is a statement.

no, it says that an expression statement is a statement.  if you don't
understand the difference, please *plonk* yourself.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


from __future__ import decorators

2005-01-13 Thread Jacek Generowicz
I have some code, which makes copious use of the @decorator syntax
which was introduced in Python2.4. Now I find myself in a situation
where I have to run the code under Python 2.3. However, I would like
to keep developing the code with the new syntax.

How could I best automate the process of making the syntax digestible
by Python2.3 ?

-- 
http://mail.python.org/mailman/listinfo/python-list


[perl-python] 20050112 while statement

2005-01-13 Thread Xah Lee
# here's a while statement in python.

a,b = 0,1
while b < 20:
print b
a,b = b,a+b

---
# here's the same code in perl

($a,$b)=(0,1);
while ($b<20) {
print $b, "\n";
($a,$b)= ($b, $a+$b);
}


 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from __future__ import decorators

2005-01-13 Thread Thomas Heller
Jacek Generowicz <[EMAIL PROTECTED]> writes:

> I have some code, which makes copious use of the @decorator syntax
> which was introduced in Python2.4. Now I find myself in a situation
> where I have to run the code under Python 2.3. However, I would like
> to keep developing the code with the new syntax.
>
> How could I best automate the process of making the syntax digestible
> by Python2.3 ?

The only way that I know of is this, although you have to rewrite your
code somewhat:

http://dirtsimple.org/2004/11/using-24-decorators-with-22-and-23.html

Thomas

-- 
http://mail.python.org/mailman/listinfo/python-list


lambda

2005-01-13 Thread Egor Bolonev
why functions created with lambda forms cannot contain statements?
how to get unnamed function with statements?
--
http://mail.python.org/mailman/listinfo/python-list


Re: site.here on python 2.4

2005-01-13 Thread ariza

i am not sure where i found site.here documented as used prior to 2.4.

the issue is that i do not need sys.path, as in the list of all paths
that python searches. sys.prefix is close to what i need:

>>> sys.prefix
'/System/Library/Frameworks/Python.framework/Versions/2.3'

but the old site.here gave sys.prefix, plus the additional directories
to get into the actual python library:

>>> site.here
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'

can we assume that, on all platforms, the old site.here is the same as:

>>> os.path.join(sys.prefix, 'lib', 'python%s' % sys.version[:3])
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'

or is it better to use, as you suggest,

>>> import os
>>> os.path.dirname(os.__file__)
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'

this is useful for a few reasons. the first was i needed a cross
platform way to find the complete path to the idle directory; the
second was the complete path to the 'site-packages' directory.

thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


wxPython and CheckListBox

2005-01-13 Thread ncookson
I am trying to add a caption or title to the box drawn around a
checklistbox and having no luck. Is there a way to do this?
I am using python 2.3.4 and wxPython 2.5 on a windows platform.

Noel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-13 Thread Antoon Pardon
Op 2005-01-13, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Well, it seems that Guido is wrong then. The documentation clearly
>> states that an expression is a statement.
>
> no, it says that an expression statement is a statement.  if you don't
> understand the difference, please *plonk* yourself.

And what else is an expression statement but an expression (list) used
as a statement.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050112 while statement

2005-01-13 Thread Michael Hoffman
Xah Lee wrote:
# here's a while statement in python.
> [...]
>
# here's the same code in perl
[...]
So?
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: java 5 could like python?

2005-01-13 Thread Arthur
On Wed, 12 Jan 2005 11:18:17 -0500, Istvan Albert
<[EMAIL PROTECTED]> wrote:

>vegetax wrote:
>
>> previus two python proyects where relatively big,and python didnt feel 
>> well suited for the task.
>
>One typical problem that others might talk about in more detail
>is that you might be writing java code in python. That means
>using Java style class hierarchies, methods and overall
>organization. That does not work well in python.

On the other hand in could be argued that the language seems to be
evolving in a direction in which this is too possible - the
distinctive "voice" of Python being muffled in static and class
methods, type declarations and the like.

Perhaps Python is forced in this direction as an appropriate admission
of the advantages of the architecture encouraged by the Java/C# class
of langauge. And is being courageous in these admission.

Or perhpas it is an unfortunate result of trying to find acceptance
and establish some compatibility in an atmosphere in which these
language approaches dominate the current mainstream. And trying too
hard to avoid a LISPish fate.

Or else everything is just as it should be.

I honestly don't pretend to know.

But am a little confused about the lack of the discussion here about
the developments in this direction.

Art 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-13 Thread Tim Leslie
Because if it takes more than a single line it deserves a name. Also,
if you have more than one line in this function, how do you plan to
reference it if not by name?

Tim


On Thu, 13 Jan 2005 20:53:09 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote:
> why functions created with lambda forms cannot contain statements?
> 
> how to get unnamed function with statements?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Free python server.

2005-01-13 Thread rootshell
Hello.

I need an account no free python server.
Would somebody help me?
I tried to find one no www.python.org [there are few addresses of 
free hosts] but unfortunately can't manage with the registration.

Best Regards
Rootshell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-13 Thread Daniel Dittmar
Egor Bolonev wrote:
why functions created with lambda forms cannot contain statements?
syntax/technical answer: because lambda is an expression and it is not 
obvious how the syntax for 'statement inside expression' should be

'Python is perfect' answer: if a function contains more than an 
expression, then it's complex enough to require a name

how to get unnamed function with statements?
You can't. See various threads about Smalltalk/Ruby-like blocks and the 
recent one about the 'where' keyword for proposals to change this

Daniel
--
http://mail.python.org/mailman/listinfo/python-list


Unclear On Class Variables

2005-01-13 Thread Tim Daneliuk
I am a bit confused.  I was under the impression that:
class foo(object):
x = 0
y = 1
means that x and y are variables shared by all instances of a class.
But when I run this against two instances of foo, and set the values
of x and y, they are indeed unique to the *instance* rather than the
class.
It is late and I am probably missing the obvious.  Enlightenment appreciated ...
--

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/
--
http://mail.python.org/mailman/listinfo/python-list


Pickling a class instead of an instance

2005-01-13 Thread Sebastien Boisgerault
Hi,

It seems to me that it's not possible with the pickle module 
to serialize a class rather than an instance, as in

>> from pickle import *
>>
>> class C(object):
>> "... doc ..."
>> a = 1
>>
>> pickstr = dumps(C)

I mean, it does *something*, there is no error indeed, but 
from the string pickstr, I am unable to rebuild the class 
C in a brand new context (got a "you're really stupid, all 
you deserve is an AttributeError because you know there is
no attribute 'C' in the 'module' object" error).

Am I wrong ? Why would the "(new-style) classes are regular 
objects too" mantra not apply in this case ? Could we imagine
a patch to the pickle module to handle this kind of situation ?

SB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free python server.

2005-01-13 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
Hi !

Server, web ?
Files server ?
Web-services server ?
XML-RPC server ?
Mail-server ?
Newsgroups server ?
SGBD server ?
Object server ?
Persistance server ?
Restaurant server ?


or ALL ?


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Simon Brunning
On 13 Jan 2005 07:18:26 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote:
> I am a bit confused.  I was under the impression that:
> 
> class foo(object):
> x = 0
> y = 1
> 
> means that x and y are variables shared by all instances of a class.
> But when I run this against two instances of foo, and set the values
> of x and y, they are indeed unique to the *instance* rather than the
> class.

I can see why you might think that:

>>> class Spam(object):
... eggs = 4
... 
>>> spam = Spam()
>>> spam2 = Spam()
>>> spam.eggs
4
>>> spam2.eggs
4
>>> spam.eggs = 2
>>> spam.eggs
2
>>> spam2.eggs
4

But you are being mislead by the fact that integers are immutable.
'spam.eggs = 2' is *creating* an instance member - there wasn't one
before. Have a look at what happens with a mutable object:

>>> class Spam(object):
... eggs = [3]
... 
>>> spam = Spam()
>>> spam2 = Spam()
>>> spam.eggs
[3]
>>> spam2.eggs
[3]
>>> spam.eggs.append(5)
>>> spam.eggs
[3, 5]
>>> spam2.eggs
[3, 5]

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread harold fellermann
Hi Tim,
If you have
class Foo(object) :
x = 0
y = 1
foo = Foo()
foo.x # reads either instance or class attribute (class in this case)
foo.x = val # sets an instance attribute (because foo is instance not  
class)

Foo.x = val   # sets a class attribute
foo.__class.__x = val # does the same
this might be sometimes confusing. IMHO, the following is especially  
nasty:

>>> foo = Foo()
>>> foo.x += 1
>>>
>>> print foo.x
1
>>> print Foo.x
0
although the += operator looks like an inplace add it isn't.
it is just syntactic sugar for foo.x = foo.x + 1.
- harold -
On 13.01.2005, at 07:18, Tim Daneliuk wrote:
I am a bit confused.  I was under the impression that:
class foo(object):
x = 0
y = 1
means that x and y are variables shared by all instances of a class.
But when I run this against two instances of foo, and set the values
of x and y, they are indeed unique to the *instance* rather than the
class.
It is late and I am probably missing the obvious.  Enlightenment  
appreciated ...
--  
--- 
-
Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/
--
http://mail.python.org/mailman/listinfo/python-list


--
Everyone is a genius.
It's just that some people are too stupid to realize it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial and com port interrupts

2005-01-13 Thread Neil Benn
engsol wrote:
Has anyone done a script that will rspond to the serial com port(s)
receive buffer interrupt, as opposed to polling and timeouts? 
Win2000 is the main interest right now.
Thanks
Norm B
 

Hello,
 I came across this problem as when I first used PySerial, I 
came from a java background which has the ability to register listeners 
to a serial comm instance and receive interrupts (although some 
implementations use polling behind the scenes anyway).  I don't think 
that pyserial has this kind of thing so I used the following :

   def __checkSerial(self):
  
   self.__objLock.acquire()
   try:
   try:
   intNoChars = self.__objSerialPort.inWaiting()
   if (intNoChars > 0):
   strReceivedString = 
self.__objSerialPort.read(intNoChars)
   #or you could fire an event
   self.newMessage(strReceivedString)
  except:
  #put any clean up code in here.
  raise   
finally:
self.__objLock.release()

   You can then wrap this in a thread which runs the method every x 
milliseconds (the code to ensure that I have all the information is 
elsewhere in a superclass which deals with this use case across 
communication implementations).  However you will have to be aware that 
you will need to lock around groups of calls to ensure you are receiving 
the correct information (as above). 
   Therefore, although threading in Python is 'easy' you would still 
have to think about this issue, it is unavoidable in communications I'm 
afraid.  Even if you could receive interrupts then you will likely be 
receiving the interrupt on a different thread of execution than the main 
anyways so you'll still have threading problems and need to lock around 
calls.  This is the problem which I usually express as '/RS232C is not 
really a standard, more of a rumour/'.

   Interestingly, if we take the 'python in threading is easy' 
discussion (partially due to the GIL), then for this use case we could 
also say that threading in VB6 is even easier than python - I'll leave 
you to guess why!!!

Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : [EMAIL PROTECTED]
Cenix Website : http://www.cenix-bioscience.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating text on images

2005-01-13 Thread Roland Heiber
morphex wrote:
Hi all,
I'm trying to create a script that will superimpose text on an image.
I didn't find any great examples out there on how this can be done (I
presume using PIL is necessary), do you know of any examples?
Thanks,
Morten
Hi,
something like this?
###
from PIL import Image, ImageFont, ImageDraw
import sys
im = Image.open(YOUR_IMAGE_HERE)
idraw = ImageDraw.Draw(im)
idraw.text((1,1),"Hello", fill=128)
im.save(YOUR_NEW_IMAGE_HERE, IMAGE_TYPE)
###
HtH, Roland
--
http://mail.python.org/mailman/listinfo/python-list


how to stop google from messing Python code

2005-01-13 Thread Xah Lee
i'm using groups-beta.google.com to post python code.

Is there a way to stop google from messing with my format? it seems to
have eaten the spaces in my python code.
thanks.

 Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling a class instead of an instance

2005-01-13 Thread harold fellermann
have a look at the thread "copying classes?" some days ago.
what goes for copying goes for pickling also, because the
modules use the same interface.
- harold -
On 13.01.2005, at 13:32, Sebastien Boisgerault wrote:
Hi,
It seems to me that it's not possible with the pickle module
to serialize a class rather than an instance, as in
from pickle import *
class C(object):
"... doc ..."
a = 1
pickstr = dumps(C)
I mean, it does *something*, there is no error indeed, but
from the string pickstr, I am unable to rebuild the class
C in a brand new context (got a "you're really stupid, all
you deserve is an AttributeError because you know there is
no attribute 'C' in the 'module' object" error).
Am I wrong ? Why would the "(new-style) classes are regular
objects too" mantra not apply in this case ? Could we imagine
a patch to the pickle module to handle this kind of situation ?
SB
--
http://mail.python.org/mailman/listinfo/python-list

--
If you make people think they're thinking, they'll love you;
but if you really make them think they'll hate you.
--
http://mail.python.org/mailman/listinfo/python-list


Debian says "Warning! you are running an untested version of Python." on 2.3

2005-01-13 Thread Alex Stapleton
Whenever I run python I get

"Warning! you are running an untested version of Python."

prepended to the start of any output on stdout.

This is with Debian and python 2.3 (running the debian 2.1 and 2.2 binaries
doesn't have this effect)

Does anyone have any idea how to stop this or have even seen it before?
Google says Your search - "you are running an untested version" - did not
match any documents
:(

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to stop google from messing Python code

2005-01-13 Thread Just
In article <[EMAIL PROTECTED]>,
 "Xah Lee" <[EMAIL PROTECTED]> wrote:

> i'm using groups-beta.google.com to post python code.
> 
> Is there a way to stop google from messing with my format? it seems to
> have eaten the spaces in my python code.

It does that when you cross-post.

Just
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie q

2005-01-13 Thread Will Stuyvesant
I understand you want to do it in an applicative programming style?
Not recommended in general.  But here goes:

.# c.l.p. question:
.# "using map, lambda, reduce, filter and List Comprehensions [x for
.# x in []] just don't get how to add string to all elements of list"
.
.##
.# A function that returns a function, taking a function as argument.
.def allapply(fn):
.def f(seq): return map(fn, seq)
.return f
.
.def add_string_to_element(stringval):
.def f(x): return x + stringval
.return f
.
.add_string_to_all = allapply(add_string_to_element('mystring'))
.
.print add_string_to_all(['d:', 'c:\windows\\','something/'])

this outputs:
['d:mystring', 'c:\\windows\\mystring', 'something/mystring']
-- 
look Ma, no for and no lambda!
-- Will Stuyvesant

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free python server.

2005-01-13 Thread rootshell
Hi there.
What I need is web sever, where I could put just one python script.
Greetings.
Rootshell.
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython and CheckListBox

2005-01-13 Thread Ed Leafe
On Jan 13, 2005, at 5:54 AM, [EMAIL PROTECTED] wrote:
I am trying to add a caption or title to the box drawn around a
checklistbox and having no luck. Is there a way to do this?
I am using python 2.3.4 and wxPython 2.5 on a windows platform.
	I don't think you can do it directly. What you might want to try is to 
create a StaticBoxSizer with the label you want, and add the checkbox 
to that sizer. Then add the StaticBoxSizer to the panel's layout 
instead of the checkbox.

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050112 while statement

2005-01-13 Thread brianr
"Xah Lee" <[EMAIL PROTECTED]> writes:

> # here's a while statement in python.
>
> a,b = 0,1
> while b < 20:
> print b
> a,b = b,a+b
>
> ---
> # here's the same code in perl
>
> ($a,$b)=(0,1);
> while ($b<20) {
> print $b, "\n";
> ($a,$b)= ($b, $a+$b);
> }

That python code produces a syntax error:

  File "w.py", line 3
print b
^
IndentationError: expected an indented block

So, not the same then!

(As a matter of interest, is this sequence of posts intended to
demonstrate ignorance of both languages, or just one?)

-- 
Brian Raven
If you write something wrong enough, I'll be glad to make up a new
witticism just for you.
 -- Larry Wall in <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


pyPgSQL giving error!

2005-01-13 Thread Gurpreet Sachdeva
I am using Redhat 9.0/python2.3. I installed pyPgSQL-2.4.tar.gz and it
was successfull. Now when I am trying to import that module, I got:

Python 2.3.3 (#1, Jan 11 2005, 15:24:09)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyPgSQL import PgSQL
Traceback (most recent call last):
  File "", line 1, in ?
  File "pyPgSQL/PgSQL.py", line 391, in ?
from libpq import *
  File "pyPgSQL/libpq/__init__.py", line 23, in ?
from libpq import *
ImportError: No module named libpq

I tried googling also but couldn't get the answere.
Please help...

~Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from __future__ import decorators

2005-01-13 Thread Jacek Generowicz
Thomas Heller <[EMAIL PROTECTED]> writes:

> Jacek Generowicz <[EMAIL PROTECTED]> writes:
> 
> > I have some code, which makes copious use of the @decorator syntax
> > which was introduced in Python2.4. Now I find myself in a situation
> > where I have to run the code under Python 2.3. However, I would like
> > to keep developing the code with the new syntax.
> >
> > How could I best automate the process of making the syntax digestible
> > by Python2.3 ?
> 
> The only way that I know of is this, although you have to rewrite your
> code somewhat:

The whole point would be to keep on developing perfectly normal
Python2.4 code, but have some means of getting it to run on 2.3,
without modification.

> http://dirtsimple.org/2004/11/using-24-decorators-with-22-and-23.html

Certainly an interesting approach. Perhaps this can be combined with a
simple textual transformation of the source code which simply replaces
@decorator with add_assignment_advisor(decorator) ... or something
along those lines.

Still, I'd prefer to find a solution on the AST level, but I guess
that's not possible without re-writing the praser.

Crazy idea ... would it be possible to shadow 2.3's parser with one
stolen from 2.4 ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python.org, Website of Satan

2005-01-13 Thread Lucas Raab
Jane wrote:
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
python.org = 194.109.137.226
194 + 109 + 137 + 226 = 666
What is this website with such a demonic name and IP address?  What
evils are the programmers who use this language up to?
Some people have too much time on their hands...
Jane

Better get some ointment for that burn!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration over two sequences

2005-01-13 Thread Diez B. Roggisch
My example is somewhat flawed because it assigns a and b the values of the
iteration - so in the end, b is 'c', and only setting a to [1,2] will show
your results.

Use c and d for the variables in the for-statments, and things work as
expected.
-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-13 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
In Mythical Future Python I would like to be able to use any base in
integer literals, which would be better. Example random syntax:
flags= 2x00011010101001
umask= 8x664
answer= 10x42
addr= 16x0E84  # 16x == 0x
gunk= 36x8H6Z9A0X
I think I kinda like this idea.  Allowing arbitrary values,
however, would probably be pointless, as there are very
few bases in common enough use that a language should make
it easy to write literals in any of them.  So I think "36x"
is silly, and would suggest limiting this to 2, 8, 10, and
16.  At the very least, a range of 2-16 should be used.
(It would be cute but pointless to allow 1x0. :-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial and com port interrupts

2005-01-13 Thread Neil Benn
Neil Benn wrote:
engsol wrote:
Has anyone done a script that will rspond to the serial com port(s)
receive buffer interrupt, as opposed to polling and timeouts? Win2000 
is the main interest right now.
Thanks
Norm B
 

Hello,
 I came across this problem as when I first used PySerial, I 
came from a java background which has the ability to register 
listeners to a serial comm instance and receive interrupts (although 
some implementations use polling behind the scenes anyway).  I don't 
think that pyserial has this kind of thing so I used the following :

Tabs got screwed up here is teh code again :
   def __checkSerial(self):
  
   self.__objLock.acquire()
   try:
   try:
   intNoChars = self.__objSerialPort.inWaiting()
   if (intNoChars > 0):
   strReceivedString = 
self.__objSerialPort.read(intNoChars)
   self.newMessage(strReceivedString)
   except:
   raise   
   finally:
   self.__objLock.release()  

Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : [EMAIL PROTECTED]
Cenix Website : http://www.cenix-bioscience.com
--
http://mail.python.org/mailman/listinfo/python-list


module on files & directories

2005-01-13 Thread Sara Fwd
Hi all

Can anybody help me find a module or a function that
looks in a directory and defines whether the objects
in there are files or directories? 

Thanks,
Sara



__ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debian says "Warning! you are running an untested version of Python." on 2.3

2005-01-13 Thread Gerhard Haering
On Thu, Jan 13, 2005 at 12:56:38PM -, Alex Stapleton wrote:
> Whenever I run python I get
> 
> "Warning! you are running an untested version of Python."
> 
> prepended to the start of any output on stdout. [...]

ROFL. Are you using testing, sid or experimental?  I expect overzealous
patching from Debian developers, but this is the worst I've heard of.

To look what's going on and how to fix it, you could try to download the
sources with "apt-get source ...", which will give you the standard
Python tarball + the Debian patches. Then you can look into the Debian
patches wtf they're doing there.

-- Gerhard


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Unclear On Class Variables

2005-01-13 Thread Antoon Pardon
Op 2005-01-13, Simon Brunning schreef <[EMAIL PROTECTED]>:
> On 13 Jan 2005 07:18:26 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote:
>> I am a bit confused.  I was under the impression that:
>> 
>> class foo(object):
>> x = 0
>> y = 1
>> 
>> means that x and y are variables shared by all instances of a class.
>> But when I run this against two instances of foo, and set the values
>> of x and y, they are indeed unique to the *instance* rather than the
>> class.
>
> I can see why you might think that:
>
 class Spam(object):
> ...   eggs = 4
> ... 
 spam = Spam()
 spam2 = Spam()
 spam.eggs
> 4
 spam2.eggs
> 4
 spam.eggs = 2
 spam.eggs
> 2
 spam2.eggs
> 4
>
> But you are being mislead by the fact that integers are immutable.
> 'spam.eggs = 2' is *creating* an instance member - there wasn't one
> before. Have a look at what happens with a mutable object:
>
 class Spam(object):
> ...   eggs = [3]
> ... 
 spam = Spam()
 spam2 = Spam()
 spam.eggs
> [3]
 spam2.eggs
> [3]
 spam.eggs.append(5)
 spam.eggs
> [3, 5]
 spam2.eggs
> [3, 5]
>

Well I find this a confusing behaviour on python's part. The fact
that instance.field can mean something different, depending on
where in a statement you find it, makes the behaviour inconsistent.

I know people in general here are against declarations, but declarations
could IMO provide more consistency here and thus more obvious behaviour.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe Excludes

2005-01-13 Thread Ed Leafe
On Jan 13, 2005, at 12:04 AM, vincent wehren wrote:
Just a guess: What happens if you remove everything that's in the 
"build" directory before running setup.py? There may still be files 
around from an earlier build that *did* include the Dabo modules.
	Ah, that was it! I didn't realize that it would still pull those 
things in there. I wiped out the build directory and re-ran setup, and 
it's now what I expected. Thanks!

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: module on files & directories

2005-01-13 Thread Simon Brunning
On Thu, 13 Jan 2005 04:51:22 -0800 (PST), Sara Fwd <[EMAIL PROTECTED]> wrote:
> Hi all
> 
> Can anybody help me find a module or a function that
> looks in a directory and defines whether the objects
> in there are files or directories?

See os.path.isfile() and os.path.isdir() -
.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyserial and com port interrupts

2005-01-13 Thread Peter Hansen
engsol wrote:
I'm working on a s/w test program using python
code. Com1 and com2 play a part. The problem is that the python code
has a lot of work to do...and the results from the hardware under test can
come from either com1 or com2...at any time. It may be a few milliseconds, 
or several seconds, sometimes minutes, before a response is expected. 
I'm not sure what timeout value I'd use. Using threads, and re-loading the
timeout values on the fly may be a solution, but I'm not experienced with
threadsand was hoping to avoid them.
I'm with Grant on this: threads in Python are really easy.  If
you can describe a little more about what you need/would like
to do with the serial data when it *does* arrive, and how that
relates to the "lot of work" that the rest of the code is doing,
I'm sure there are a number of helpful replies just waiting to
be written to convince you how easy it really is.
For example, if you need to retrieve the data from the serial
ports right away, so the sending device doesn't block or lose
data, but can afford to just store it for later processing
when the main thread has time, that's only a few lines of
code.
If you actually want to reply immediately, then the only
real question is how you come up with the reply.  If it needs
data from the main thread, we can show you several easy and
appropriate ways to do that with no thread safety issues.
If you're not experienced with threads, there's almost no place
better to start learning than with Python and c.l.p. :-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Diez B. Roggisch
Tim Daneliuk wrote:

> I am a bit confused.  I was under the impression that:
> 
> class foo(object):
> x = 0
> y = 1
> 
> means that x and y are variables shared by all instances of a class.
> But when I run this against two instances of foo, and set the values
> of x and y, they are indeed unique to the *instance* rather than the
> class.
> 
> It is late and I am probably missing the obvious.  Enlightenment
> appreciated ...

Without actual code how you set the vars, no one can answer that question.

-- 
Regards,

Diez B. Roggisch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why not datetime.strptime() ?

2005-01-13 Thread Skip Montanaro

Josh> The datetime is full of these calls. Would it make sense to make
Josh> this a separate patch? (Or maybe the PyImport_ImportModule could
Josh> implement such a cache :) ?)

Hmmm...  I wonder why that wasn't done before.  Perhaps it just doesn't
matter performance-wise.  I just checked in your changes.  Thanks for the
effort.

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-13 Thread Antoon Pardon
Op 2005-01-13, Tim Leslie schreef <[EMAIL PROTECTED]>:
> Because if it takes more than a single line it deserves a name.

So if I have a call with an expression that takes more than
one line, I should assign the expression to a variable and
use the variable in the call?

But wait if I do that, people will tell me how bad that it
is, because it will keep a reference to the value which
will prevent the garbage collector from harvesting this
memory.

Besides python allows more than one statement on the same line.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Antoon Pardon
Op 2005-01-13, harold fellermann schreef <[EMAIL PROTECTED]>:
> Hi Tim,
>
> If you have
>
> class Foo(object) :
>   x = 0
>   y = 1
>
> foo = Foo()
>
> foo.x # reads either instance or class attribute (class in this case)
>
> foo.x = val # sets an instance attribute (because foo is instance not  
> class)
>
> Foo.x = val   # sets a class attribute
> foo.__class.__x = val # does the same
>
> this might be sometimes confusing. IMHO, the following is especially  
> nasty:
>
> >>> foo = Foo()
> >>> foo.x += 1
> >>>
> >>> print foo.x
> 1
> >>> print Foo.x
> 0
>
> although the += operator looks like an inplace add it isn't.
> it is just syntactic sugar for foo.x = foo.x + 1.

Except is x belongs to a mutable class that implements the
+= operator as an inplace add.

Try the same but with x = [2]
and foo.x += [3]

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from __future__ import decorators

2005-01-13 Thread Jacek Generowicz
Peter Otten <[EMAIL PROTECTED]> writes:

> Have a look at Bill Mill's redecorate utility:
> 
> http://llimllib.f2o.org/files/redecorate.py

Heh, this is exactly the sort of thing I wanted do avoid writing, as
it would be difficult to get right. Looks like it's author has similar
feelings. However, it could well be the most pragmatic solution in my
case.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-13 Thread Peter Hansen
Paul Rubin wrote:
Simon Wittber <[EMAIL PROTECTED]> writes:
Is there a reason NOT to use them?  If a classic class works fine, what
incentive is there to switch to new style classes?  
Perhaps classic classes will eventually disappear?
It just means that the formerly "classic" syntax will define a
new-style class.  Try to write code that works either way.
Unfortunately, if we should follow the recent advice about
always using "super()" in the __init__ method, it's hard
to do what you suggest (though it sounds like good advice)
without resorting to extreme ugliness:
>>> class Classic:
...   def __init__(self):
... super(Classic, self).__init__()
...
>>> c = Classic()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in __init__
TypeError: super() argument 1 must be type, not classobj
Could classic classes ever be removed without us having manually
to fix all __init__ calls to the superclass?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-13 Thread phil_nospam_schmidt
Peter Hansen wrote:
> [EMAIL PROTECTED] wrote:
> > In Mythical Future Python I would like to be able to use any base
in
> > integer literals, which would be better. Example random syntax:
> >
> > flags= 2x00011010101001
> > umask= 8x664
> > answer= 10x42
> > addr= 16x0E84  # 16x == 0x
> > gunk= 36x8H6Z9A0X
>
> I think I kinda like this idea.  Allowing arbitrary values,
> however, would probably be pointless, as there are very
> few bases in common enough use that a language should make
> it easy to write literals in any of them.  So I think "36x"
> is silly, and would suggest limiting this to 2, 8, 10, and
> 16.  At the very least, a range of 2-16 should be used.
> (It would be cute but pointless to allow 1x0. :-)
>
> -Peter
>
>
>
How about base 24 and 60, for hours and minutes/seconds?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-13 Thread Aahz
In article <[EMAIL PROTECTED]>,
Peter Hansen  <[EMAIL PROTECTED]> wrote:
>
>Unfortunately, if we should follow the recent advice about always using
>"super()" in the __init__ method, it's hard to do what you suggest
>(though it sounds like good advice) without resorting to extreme
>ugliness:
>
> >>> class Classic:
>...   def __init__(self):
>... super(Classic, self).__init__()
>...
> >>> c = Classic()
>Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 3, in __init__
>TypeError: super() argument 1 must be type, not classobj
>
>Could classic classes ever be removed without us having manually
>to fix all __init__ calls to the superclass?

Maybe.  If you follow the python-dev thread about "super() considered
harmful", you'll learn that Guido believes super() should only be used
with class hierarchies explicitly designed for the purpose.  Given that,
you'd have to do a lot of other changes to support super() and it's less
outrageous.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-13 Thread Simon Wittber
> Unfortunately, if we should follow the recent advice about
> always using "super()" in the __init__ method, it's hard
> to do what you suggest (though it sounds like good advice)
> without resorting to extreme ugliness:

'import this' also provides some good advice:

"There should be one-- and preferably only one --obvious way to do it."

It seems to me that python is not as simple/clean as it once was. It
has grown warts, for the sake of backwards compatibility. :(

Sw.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Peter Hansen
Simon Brunning wrote:
On 13 Jan 2005 07:18:26 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote:
But you are being mislead by the fact that integers are immutable.
'spam.eggs = 2' is *creating* an instance member - there wasn't one
before. Have a look at what happens with a mutable object:
Simon, it's really not about mutability at all.  You've changed
the example, which was binding a name (specifically setting an
attribute), to one in which you are simply calling a method on
the object.  If you change your example to bind the name the
same way, even with a mutable, it will work the same way as Tim's
original did with integers:
class Spam(object):
... eggs = [3]
...
spam = Spam()
spam2 = Spam()
spam.eggs = [7]
>>> spam2.eggs
[3]
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


seperating GUI from other code + reports

2005-01-13 Thread flupke
Hi,
i need to develop an app here which will be used to produce stats.
I'm going to go with twisted pb for the client server communication.
And wxPython for the GUI.
Now i would want to split the GUI code from the pb code to make 
debugging easier amongst other things but i'm not sure how i would best 
implement the communication of between the GUI and the client.
Do i also use pb for it? But then i would end up with the problems that 
some users have reported here that wxPython and pb have.
This would look like this, where GUI and CLIENT are off course on the
same machine.

GUI pb  CLIENT pb   SERVER
   <--->  <--->
1) Any thoughts about this or other methods of doing this or reason why 
i should not bother with this setup?

2) I will display the results of the query in a list of grid on the 
client. But then the users are going to want to print the results.
Are there any tools that provide a way of printing queries or that 
provide a mechanism to build reports based on tables?
The easiest way i can do it now is to make a html of the results and
then opening a browser with that html page using popen.
Any other ideas?

Thanks,
Benedict
--
http://mail.python.org/mailman/listinfo/python-list


How to install pyparallel

2005-01-13 Thread Michel LE VAN KIEM
Hi everybody !
I'm trying to install the pyparallel module for my Python 2.3.4 (runs on 
a FC3) but I do have some troubles.

When I import the parallel module, python shows the following message :
>>> import parallel
/usr/lib/python2.3/site-packages/parallel/parallelppdev.py:32: 
FutureWarning: x<
...

>>> p=parallel.Parallel()
ppdev0: failed to register device !
...
IOError: [No such device or address]
Some help would be appreciated.
Michel
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Simon Brunning
On Thu, 13 Jan 2005 08:56:10 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
> Simon, it's really not about mutability at all.  You've changed
> the example, 

Err, there *wasn't* an example, not really. The OP just mentioned
'setting the values' of instance members. That *can* mean name
binding, but (to my mind at least) it can also mean calling mutating
methods. I just wanted to show both.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Steve Holden
Tim Daneliuk wrote:
I am a bit confused.  I was under the impression that:
class foo(object):
x = 0
y = 1
means that x and y are variables shared by all instances of a class.
What it actually does is define names with the given values *in the 
class namespace*.

But when I run this against two instances of foo, and set the values
of x and y, they are indeed unique to the *instance* rather than the
class.
I imagine here you are setting instance variables, which then *mask* the 
presence of class variables with the same name, because "self-relative" 
name resolution looks in the instance namespace before it looks in the 
class namespace.

It is late and I am probably missing the obvious.  Enlightenment 
appreciated ...
You can refer to class variables using the class name explicitly, both 
within methods and externally:

 >>> class X:
 ...   count = 0
 ...   def getCt(self):
 ... return self.count
 ...   def inc(self):
 ... self.count += 1
 ...
 >>> x1 = X()
 >>> x2 = X()
 >>> id(x1.count)
168378284
 >>> x1.inc()
 >>> id(x1.count)
168378272
 >>> id(x2.count)
168378284
 >>> id(X.count)
168378284
 >>> x1.getCt()
1
 >>> x2.getCt()
0
 >>>
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-13 Thread Steve Holden
[EMAIL PROTECTED] wrote:
John Machin wrote:

I regard continued usage of octal as a pox and a pestilence.

Quite agree. I was disappointed that it ever made it into Python.
Octal's only use is:
a) umasks
b) confusing the hell out of normal non-programmers for whom a
leading zero is in no way magic
(a) does not outweigh (b).
In Mythical Future Python I would like to be able to use any base in
integer literals, which would be better. Example random syntax:
flags= 2x00011010101001
umask= 8x664
answer= 10x42
addr= 16x0E84  # 16x == 0x
gunk= 36x8H6Z9A0X
But either way, I want rid of 0->octal.

Is it not regretted?

Maybe the problem just doesn't occur to people who have used C too
long.
:-)
OT: Also, if Google doesn't stop lstrip()ing my posts I may have to get
a proper news feed. What use is that on a Python newsgroup? Grr.
I remember using a langauge (Icon?) in which arbitrary bases up to 36 
could be used with numeric literals. IIRC, the literals had to begin 
with the base in decimnal, folowed by a "b" followed by the digits of 
the value using a through z for digits from ten to thirty-five. So

gunk = 36b8H6Z9A0X
would have been valid.
nothing-new-under-the-sun-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Fredrik Lundh
Tim Daneliuk wrote:

>I am a bit confused.  I was under the impression that:
>
> class foo(object):
> x = 0
> y = 1
>
> means that x and y are variables shared by all instances of a class.
> But when I run this against two instances of foo, and set the values
> of x and y, they are indeed unique to the *instance* rather than the
> class.

"set" as in:

obj = foo()
obj.x = 10 # set x

?

if so, the "obj.x=" line is *adding* an instance variable to the "x" object, 
which will
then hide the "x" at the class level.

>>> class foo(object):
... x = 0
... y = 1
...
>>> obj = foo()
>>> obj.__dict__
{}
>>> obj.x
0
>>> obj.y
1
>>> foo.x
0
>>> obj.x = 10
>>> obj.__dict__
{'x': 10}
>>> obj.x
10
>>> foo.x
0

if you want to assign to the class variable, assign to the class variable:

>>> obj = foo()
>>> obj.x
0
>>> foo.x = 20
>>> obj.__dict__
{}
>>> obj.x
20
>>> foo().x
20

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-13 Thread Steve Holden
Fredrik Lundh wrote:
Antoon Pardon wrote:

Well, it seems that Guido is wrong then. The documentation clearly
states that an expression is a statement.

no, it says that an expression statement is a statement.  if you don't
understand the difference, please *plonk* yourself.
OK then, "The documentation clearly states that not all statements can 
be expressions". Specifically Guido has justified the fact that an 
assignment does not return any value, and therefore cannot be used as a 
component of an expression.

Mea culpa, but I'm not going to *plonk* myself - then *nobody* would be 
listening to me :-)

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050112 while statement

2005-01-13 Thread Peter Maas
[EMAIL PROTECTED] schrieb:
"Xah Lee" <[EMAIL PROTECTED]> writes:
[...]
(As a matter of interest, is this sequence of posts intended to
demonstrate ignorance of both languages, or just one?)
:)
This sequence of posts is intended to stir up a debate just for
the sake of a debate. It's a time sink. It's up to you wether you
want to post to this thread or do something useful. :)
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie q

2005-01-13 Thread Steve Holden
Egor Bolonev wrote:
"Stephen Thorne" <[EMAIL PROTECTED]> ÑÐÐÐÑÐÐ/ÑÐÐÐÑÐÐÐ Ð 
ÑÐÐÐÑÑÑÐÐ: news:[EMAIL PROTECTED]
On Thu, 13 Jan 2005 15:55:10 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote:
how to get rid of 'for' operator in the code?
import os, os.path
def _test():
src = 'C:\\Documents and Settings\\ÐÐÐÑ\\My Documents\\My Music\\'
for i in [x for x in os.listdir(src) if
os.path.isfile(os.path.join(src,
x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u']:
os.remove(os.path.join(src, i))
if __name__ == '__main__':
_test()

import glob
for x in glob.glob("*.m3u"):
   os.remove(x)
i want to wipe out 'for x in []: f(x)' using map, lambda, reduce, filter 
and List
Comprehensions [x for x in []]
just don't get how to add string to all elements of list

Any statement of the form
for i in [x for x in something]:
can be rewritten as
for i in something:
Note that this doesn't mean you never want to iterate over a list 
comprehension. It's the easiest way, for example, to iterate over the 
first item of each list in a list of lists:

for i in [x[0] for x in something]:
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: why not datetime.strptime() ?

2005-01-13 Thread Skip Montanaro

Skip> I just checked in your changes.  Thanks for the effort.

Jeez Skip...  That reads poorly.  How about "Thanks for your contribution"?
In any case, thanks.

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.3.4 for windows: float("NaN") throws exception

2005-01-13 Thread asmirnov1234567890
Hi

my python 2.3.4 for windows refuse to execute line float("NaN"). It
says:

>>> float("NaN")
Traceback (most recent call last):
File "", line 1, in ?
ValueError: invalid literal for float(): NaN

The same line works as expected on Linux and Solaris with python 2.3.4.
Could anybody explain what is possibly wrong here? is it bug or
feature?

Andrei

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.3.4 for windows: float("NaN") throws exception

2005-01-13 Thread Tim Peters
[EMAIL PROTECTED]
> my python 2.3.4 for windows refuse to execute line float("NaN"). It
> says:
>
> >>> float("NaN")
> Traceback (most recent call last):
> File "", line 1, in ?
> ValueError: invalid literal for float(): NaN
> 
> The same line works as expected on Linux and Solaris with python 2.3.4.
> Could anybody explain what is possibly wrong here? is it bug or
> feature?

Neither -- all Python behavior in the presence of float NaNs,
infinities, or signed zeroes is a platform-dependent accident.  In
this specific case, the accident is that the platform C runtime
string->double functions on your Linux and Solaris boxes recognize
"NaN", but Microsoft's string->double functions do not.  Microsoft's
libraries can't even read back the strings they *produce* for
NaNs.(usually "-1.#IND").
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.3.4 for windows: float("NaN") throws exception

2005-01-13 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> my python 2.3.4 for windows refuse to execute line float("NaN"). It
> says:
>
 float("NaN")
> Traceback (most recent call last):
> File "", line 1, in ?
> ValueError: invalid literal for float(): NaN
>
> The same line works as expected on Linux and Solaris with python 2.3.4.
> Could anybody explain what is possibly wrong here? is it bug or
> feature?

feature, sort of.  see http://www.python.org/peps/pep-0754.html :

"Currently, the handling of IEEE 754 special values in Python
depends on the underlying C library. Unfortunately, there is little
consistency between C libraries in how or whether these values
are handled. For instance, on some systems "float('Inf')" will
properly return the IEEE 754 constant for positive infinity. On
many systems, however, this expression will instead generate
an error message."

the PEP includes a pointer to a module that lets you replace that "float"
with the fully portable:

import fpconst

def myfloat(x):
if x == "NaN":
return fpconst.NaN
return float(x)

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unclear On Class Variables

2005-01-13 Thread Antoon Pardon
>
> Well I find this a confusing behaviour on python's part. The fact
> that instance.field can mean something different, depending on
> where in a statement you find it, makes the behaviour inconsistent.
>
> I know people in general here are against declarations, but declarations
> could IMO provide more consistency here and thus more obvious behaviour.

Well just to show how confusing python can be, the following piece of
code.

| class Spam:
|   eggs = [2, 3]
| 
| 
| sp1 = Spam()
| sp2 = Spam()
| 
| print sp1.eggs, id(sp1.eggs)
| print sp2.eggs, id(sp2.eggs)
| print ''
| 
| sp1.eggs += [4,]
|
| print sp1.eggs, id(sp1.eggs)
| print sp2.eggs, id(sp2.eggs)
| print ''
|
| Spam.eggs = [3,5]
|
| print sp1.eggs, id(sp1.eggs)
| print sp2.eggs, id(sp2.eggs)
| print ''

Which produces:

[2, 3] 1075958860
[2, 3] 1075958860

[2, 3, 4] 1075958860
[2, 3, 4] 1075958860

[2, 3, 4] 1075958860
[3, 5] 1075959084


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to install pyparallel

2005-01-13 Thread Peter Hansen
Michel LE VAN KIEM wrote:
I'm trying to install the pyparallel module for my Python 2.3.4 (runs on 
a FC3) but I do have some troubles.

 >>> p=parallel.Parallel()
ppdev0: failed to register device !
...
IOError: [No such device or address]
Some help would be appreciated.
Did you read the notes in the parallelppydev.py file's
Parallel class?  I suspect they may be of some help...
(I don't see any other significant documentation of
pyParallel, so I'm not sure where else one would look
for assistance.)
Also, perhaps one of these threads would be of help:
http://groups.google.ca/groups?q=parallel+ppdev0+failed+to+register+device
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.3.4 for windows: float("NaN") throws exception

2005-01-13 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
my python 2.3.4 for windows refuse to execute line float("NaN"). It
says:
float("NaN")
Traceback (most recent call last):
File "", line 1, in ?
ValueError: invalid literal for float(): NaN
The same line works as expected on Linux and Solaris with python 2.3.4.
Could anybody explain what is possibly wrong here? is it bug or
feature?
Differences in the underlying platform/C library.  No difference
here with similar platforms.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python.org, Website of Satan

2005-01-13 Thread Jane

"Lucas Raab" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jane wrote:
> > <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> >>python.org = 194.109.137.226
> >>
> >>194 + 109 + 137 + 226 = 666
> >>
> >>What is this website with such a demonic name and IP address?  What
> >>evils are the programmers who use this language up to?
> >>
> >
> > Some people have too much time on their hands...
> >
> > Jane
> >
> >
>
> Better get some ointment for that burn!!

Huh???

Jane


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-13 Thread Nick Coghlan
Nick Coghlan wrote:
Semantics
-
The code::
 with:
   
translates to::
def unique_name():


unique_name()
I've come to the conclusion that these semantics aren't what I would expect from 
the construct. Exactly what I would expect can't really be expressed in current 
Python due to the way local name bindings work. The main thing to consider is 
what one would expect the following to print:

def f():
a = 1
b = 2
print 1, locals()
print 3, locals() using:
a = 2
c = 3
print 2, locals()
print 4, locals()
I think the least suprising result would be:
1 {'a': 1, 'b': 2} # Outer scope
2 {'a': 2, 'c': 3} # Inner scope
3 {'a': 2, 'b': 2, 'c': 3} # Bridging scope
4 {'a': 1, 'b': 2} # Outer scope
In that arrangement, the statement with a using clause is executed normally in 
the outer scope, but with the ability to see additional names in its local 
namespace. If this can be arranged, then name binding in the statement with the 
using clause will work as we want it to.

Anyway, I think further investigation of the idea is dependent on a closer look 
at the feasibility of actually implementing it. Given that it isn't as 
compatible with the existing nested scope structure as I first thought, I 
suspect it will be both tricky to implement, and hard to sell to the BDFL 
afterwards :(

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Free python server.

2005-01-13 Thread Kartic
You can try for a free shell access at www.arbornet.org.

telnet (or better SSH) to m-net.arbornet.org and at the login prompt,
type newuser, press enter and follow the on-screen instructions to
register.

Once you register, you get a shell account with email and web space.
Since it is a free service, space is very limited but should more than
serve your needs now.

--Kartic

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
>Before you get too carried away, how often do you want to do this and
>how grunty is the box you will be running on?

Oops, I should have specified this. The script will only need to be run
once every three or four months, when the sequences are updated. I'll
be running it on boxes that are 3GHz/100GB Ram, but others may not be
so fortunate, and so I'd like to keep that in mind.

>BTW, you need to clarify "don't have access to an RDBMS" ... surely
>this can only be due to someone stopping them from installing good
>free software freely available on the Internet.

I understand your and others' sentiment on this. I agree, the
open-source database systems are wonderful. However, keeping it
Python-only saves me hassle by only having to assist in instances where
others need help downloading and installing Python. I suppose if I keep
it in Python, I can even use Py2exe to generate an executable that
wouldn't even require them to install Python. A solution using
interaction with a database is much sexier, but, for the purposes of
the script, seems unnecesary. However, I certainly appreciate the
suggestions.

>My guess is that you don't need anything much fancier than the
>effbot's index method -- which by now you have probably found works
>straight out of the box and is more than fast enough for your needs.

I think Mr. Lundh's code will work very well for these purposes. Thanks
very much to him for posting it. Many thanks for posting that! You'll
have full credit for that part of the code. Thanks very much to all who
replied!

Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
Thanks for your reply, Larry. I thought about this, but I'm worried the
dictionary will consume a lot of resources. I think my 3GHz/1GB RAM box
could handle the load fine, but I'm not sure about others' systems.
Chris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free python server.

2005-01-13 Thread Kartic
And yes, they have python installed...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: else condition in list comprehension

2005-01-13 Thread Nick Coghlan
Andrey Tatarinov wrote:
I presume the point of this is to avoid polluting the local namespace 
with "newval". I further presume you also have plans to do something 
about "i"? ;-)
no, the point is in grouping definition of newval() with place where it 
is used.
I'd have said the point was both :)
But yeah, unfortunately the 'leaking list comp' problem won't be fixed in the 
2.x series due to the compatibility problem. Fortunately, generator expressions 
didn't inherit the issue.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


dynamically inserting function into an object

2005-01-13 Thread michael
Hi,

below is a snipplet that could be seen as a part of a spreadsheet with
getter and setter properties and a way how to dynamically insert
function to be used when setting the value of a "cell" instance


import new
import inspect

class Cell (object):

def __init__ (self, initialvalue = 0):
self._func = None
self.__value = initialvalue

def setvalue (self, newvalue):
if self._func:
self.__value = self._recalculate (newvalue)
else:
self.__value = newvalue

def getvalue (self):
return self.__value

def _recalculate (self, value):

ret_value = self._func (value)

return ret_value

def delvalue (self):
del self.__value


value = property(getvalue, setvalue, delvalue, "I'm the 'value'
property.")

def curry(self, func, *args):
self._func =  new.function(func.func_code, func.func_globals,
argdefs=args)

func = property(curry, "I'm the 'func' property.")

def func (value, firstcell, secondcell):
return value + firstcell.value + secondcell.value

cell0 = Cell (10)
cell1 = Cell (20)

curriedcell = Cell (100)

print "uncurried initial %d " % (curriedcell.value)

curriedcell.value = 60

print "uncurried set %d " % (curriedcell.value)

curriedcell.curry (func, cell0, cell1)
curriedcell.value = 62

print "curried set %d " % (curriedcell.value)



Is there a better way to do this or am I totally on the wrong way ?

Regards

Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from __future__ import decorators

2005-01-13 Thread Skip Montanaro

Jacek> Crazy idea ... would it be possible to shadow 2.3's parser with
Jacek> one stolen from 2.4 ?

If you're willing to go to that much trouble, why not just upgrade to 2.4?

Skip

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from __future__ import decorators

2005-01-13 Thread Peter Otten
Jacek Generowicz wrote:

> I have some code, which makes copious use of the @decorator syntax
> which was introduced in Python2.4. Now I find myself in a situation
> where I have to run the code under Python 2.3. However, I would like
> to keep developing the code with the new syntax.
> 
> How could I best automate the process of making the syntax digestible
> by Python2.3 ?

Have a look at Bill Mill's redecorate utility:

http://llimllib.f2o.org/files/redecorate.py

Peter


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-13 Thread Aahz
In article <[EMAIL PROTECTED]>,
Simon Wittber  <[EMAIL PROTECTED]> wrote:
>
>'import this' also provides some good advice:
>
>"There should be one-- and preferably only one --obvious way to do it."
>
>It seems to me that python is not as simple/clean as it once was. It
>has grown warts, for the sake of backwards compatibility. :(

That's progress.  One of the primary goals for Python 3.0 is to make a
fresh start by removing a lot of the backwards compatibility.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-13 Thread Chris Lasher
>Others have probably solved your basic problem, or pointed
>the way. I'm just curious.

>Given that the information content is 2 bits per character
>that is taking up 8 bits of storage, there must be a good reason
>for storing and/or transmitting them this way? I.e., it it easy
>to think up a count-prefixed compressed format packing 4:1 in
>subsequent data bytes (except for the last byte which have
>less than 4 2-bit codes).

My guess for the inefficiency in storage size is because it is
human-readable, and because most in-silico molecular biology is just a
bunch of fancy string algorithms. This is my limited view of these
things at least.

>I'm wondering how the data is actually used once records are
>retrieved.

This one I can answer. For my purposes, I'm just organizing the
sequences at hand, but there are all sorts of things one could actually
do with sequences: alignments, BLAST searches, gene annotations, etc.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Tix and Tkinter

2005-01-13 Thread harold fellermann
On 31.12.2004, at 16:50, Harlin Seritt wrote:
import Tix
from Tkconstants import *
from Tkinter import *
root = Tix.Tk()
Label(root, text="Hello!").pack()
Tix.tixControl().pack()
root.mainloop()

When I run this, I get the following error:
Traceback (most recent call last):
  File "TixTest.py", line 8, in ?
Tix.tixControl().pack()
AttributeError: 'module' object has no attribute 'tixControl'
in the Tix module this widget is called Control. writing
Tix.Control().pack()
should work.
- harold -
--
Man will occasionally stumble over the truth,
but most of the time he will pick himself up and continue on.
-- Winston Churchill
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-13 Thread hanz

Antoon Pardon wrote:
> So if I have a call with an expression that takes more than
> one line, I should assign the expression to a variable and
> use the variable in the call?

Yes, that's sometimes a good practice and can clarify
the call.

> But wait if I do that, people will tell me how bad that it
> is, because it will keep a reference to the value which
> will prevent the garbage collector from harvesting this
> memory.

Nobody will tell you that it's bad. Python was never
about super performance, but about readability.
Besides, using such temporaries won't consume much
memory (relatively).

> Besides python allows more than one statement on the same line.
But it's discouraged in general.

-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode conversion in 'print'

2005-01-13 Thread Ricardo Bugalho
Hello,
 I'm using Python 2.3.4 and I noticed that, when stdout is a terminal, the
'print' statement converts Unicode strings into the encoding defined by
the locales instead of the one returned by sys.getdefaultencoding().
However, I can't find any references to it. Anyone knows where it's
descrbed?

Example:

!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, locale

print 'Python encoding:', sys.getdefaultencoding()
print 'System encoding:', locale.getpreferredencoding()
print 'Test string: ', u'Olà mundo'


If stdout is a terminal, works fine
$ python x.py
Python encoding: ascii
System encoding: UTF-8
Test string:  Olà mundo

If I redirect the output to a file, raises an UnicodeEncodeError exception
$ python x.py > x.txt
Traceback (most recent call last):
  File "x.py", line 8, in ?
print 'Test string: ', u'Olà mundo'
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 2: 
ordinal not in range(128)


-- 
Ricardo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread François Pinard
[Stephen Thorne]

> On 12 Jan 2005 22:36:54 -0800, yaipa <[EMAIL PROTECTED]> wrote:
>
> > What would be the common sense way of finding a binary pattern in
> > a .bin file, say some 200 bytes, and replacing it with an updated
> > pattern of the same length at the same offset?  The file itself
> > isn't so large, maybe 32 kbytes is all and the need for speed is not
> > so great, but the need for accuracy in the search/replacement is
> > very important.

> Okay, given the requirements.

> f = file('mybinfile')
> contents = f.read().replace(oldbinstring, newbinstring)
> f.close()
> f = file('mybinfile','w')
> f.write(contents)
> f.close()

> Will do it, and do it accurately. But it will also read the entire
> file into memory.

32Kb is a small file indeed, reading it in memory is not a problem!

People sometimes like writing long Python programs.  Here is about the
same, a bit shorter: :-)

buffer = file('mybinfile', 'rb').read().replace(oldbinstring, newbinstring)
file('mybinfile', 'wb').write(buffer)

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamically inserting function into an object

2005-01-13 Thread John Roth
If what you want is to insert a method into an
instance, look at new.instancemethod.
John Roth
"michael" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Hi,
below is a snipplet that could be seen as a part of a spreadsheet with
getter and setter properties and a way how to dynamically insert
function to be used when setting the value of a "cell" instance
import new
import inspect
class Cell (object):
   def __init__ (self, initialvalue = 0):
   self._func = None
   self.__value = initialvalue
   def setvalue (self, newvalue):
   if self._func:
   self.__value = self._recalculate (newvalue)
   else:
   self.__value = newvalue
   def getvalue (self):
   return self.__value
   def _recalculate (self, value):
   ret_value = self._func (value)
   return ret_value
   def delvalue (self):
   del self.__value
   value = property(getvalue, setvalue, delvalue, "I'm the 'value'
property.")
   def curry(self, func, *args):
   self._func =  new.function(func.func_code, func.func_globals,
argdefs=args)
   func = property(curry, "I'm the 'func' property.")
def func (value, firstcell, secondcell):
   return value + firstcell.value + secondcell.value
cell0 = Cell (10)
cell1 = Cell (20)
curriedcell = Cell (100)
print "uncurried initial %d " % (curriedcell.value)
curriedcell.value = 60
print "uncurried set %d " % (curriedcell.value)
curriedcell.curry (func, cell0, cell1)
curriedcell.value = 62
print "curried set %d " % (curriedcell.value)

Is there a better way to do this or am I totally on the wrong way ?
Regards
Michael 
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-13 Thread Paul Rubin
"hanz" <[EMAIL PROTECTED]> writes:
> > But wait if I do that, people will tell me how bad that it is,
> > because it will keep a reference to the value which will prevent
> > the garbage collector from harvesting this memory.
> 
> Nobody will tell you that it's bad. Python was never about super
> performance, but about readability.  Besides, using such temporaries
> won't consume much memory (relatively).

That completely depends on the objects in question.  Compare

   temp = all_posters[:]
   temp.sort()
   top_five_posters = temp[-5:]

to:

   top_five_posters = all_posters.sorted()[-5:]

which became possible only when .sorted() was added to Python 2.4.

This is another reason it would be nice to be able to create very
temporary scopes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debian says "Warning! you are running an untested version of Python." on 2.3

2005-01-13 Thread Nick Craig-Wood
Alex Stapleton <[EMAIL PROTECTED]> wrote:
>  Whenever I run python I get
> 
>  "Warning! you are running an untested version of Python."
> 
>  prepended to the start of any output on stdout.
> 
>  This is with Debian and python 2.3 (running the debian 2.1 and 2.2 binaries
>  doesn't have this effect)

What version of a) Debian and b) python are you running?

I don't have that problem here (I'm running testing/sarge)

  $ python2.4 -c 'pass'
  $ python2.3 -c 'pass'
  $ python2.2 -c 'pass'
  $ python2.1 -c 'pass'
  $ 

  $ dpkg -l python2.1  python2.2  python2.3  python2.4
  ||/ Name   VersionDescription
  +++-==-==-
  ii  python2.1  2.1.3-25   An interactive high-level object-oriented la
  ii  python2.2  2.2.3-10   An interactive high-level object-oriented la
  ii  python2.3  2.3.4-18   An interactive high-level object-oriented la
  ii  python2.4  2.4-2  An interactive high-level object-oriented la

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >