Re: Reinstall python 2.3 on OSX 10.3.5?

2005-02-02 Thread Robert Kern
Christian Dieterich wrote:
On Dé Céadaoin, Feabh 2, 2005, at 17:48 America/Chicago, 
[EMAIL PROTECTED] wrote:

Hi there
I started a very long and roundabout process of attempting to install
python 2.3.4 along side my apple-installed 2.3 system. To make a long
story short, I have completely confabulated my environment ( i deleted
the 2.3 binaries and so forth from the system in an attempt to start
things fresh), and now I cannot figure out how to reinstall the base
2.3 Apple python distribution.
Can somebody please point me in the right direction?

You could use
fink install python
which makes you a Python installation under /sw.
But that doesn't solve his problem, which is to restore the 
Apple-supplied Python that he deleted.

--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Awkwardness of C API for making tuples

2005-02-02 Thread Fredrik Lundh
Dave Cole wrote:

> for (i = 0; i < num_values; i++) {
> PyObject *obj;
>
> obj = PyInt_FromLong(value[i]);
> if (obj == NULL
> || PyTuple_SetItem(tuple, i, obj) != 0) {
> Py_DECREF(tuple);
> return NULL;
> }
> }

in theory, if PyInt_FromLong succeeds, and PyTuple_SetItem fails, you'll leak
an object.

 



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


RE: Crashing Python interpreter! (windows XP, python2.3.4, 2.3.5rc1, 2.4.0)

2005-02-02 Thread Leeuw van der, Tim

-Original Message-
From: [EMAIL PROTECTED] on behalf of John Machin
Sent: Thu 2/3/2005 12:03 AM
To: python-list@python.org
Subject: Re: Crashing Python interpreter! (windows XP, python2.3.4, 
2.3.5rc1,2.4.0)
 

> Leeuw van der, Tim TOP-POSTED:
> > Hi all,
> >
[...]
> >
> > Leeuw van der, Tim schrieb:
> > > I'm using the following combination of software:
> > > - Pydev Eclipse plugin (pydev 0.8.5)
> > > - eclipse 3.0.1
> > > - windows XP SP1
> > > - pygtk 2.4.1
> > > - GTK 2.6.1 (for windows32 native)
> >
> > > When trying to get a list of possible completions for the 'gtk'
> import object, the python interpreter crashes. Happens with all
> versions listed in the subject: python 2.3.4, 2.3.5rc1, 2.4.0.
> > 
> 
> Do you have a file called drwtsn32.log anywhere on your computer?

No, unfortunately I cannot find such file anywhere on my computer

What do I do to get such file? Or anything equally useful?

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


Re: Reference count question

2005-02-02 Thread Fredrik Lundh
John Machin wrote:

>> you should check the return value, though.  PyList_SetItem may (in
>> theory) fail.
>
> :-)
> Only a bot could say that. We mere mortals have been known to do things
> like (a) pass a non-list as the first argument (b) pass an out-of-range
> value for the second argument.

even for trivial code fragments like the one in the original post?

 



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


[EVALUATION] - E01: The Java Failure - May Python Helps?

2005-02-02 Thread Ilias Lazaridis
"
A cooperation between Sun Microsystems and IBM&Co. in conjunction with
liberal & high evolutive communities would result in an nearly
unbeatable programming platform.
My evaluation has shown: this is a non achievable goal, as stubborness
and egoism rules - instead of reason and cooperation.
Thus I leave all those ridiculous folks behind, which will continue to
do an excellent job in keeping the very promising JAVA platform far
below the technological level it could be
"
-
"
Of course It's a sad day.
Censorship (NetBeans, Eclipse) has forced me to move.
No platform is _really_ open, thus I cannot build on them:
http://lazaridis.com/core/project/open.html
"
-
"I'm sure there is one community out there which will realize immediatly 
the benefits of an high-evolutive system. "

-
source: [messages within thread]
[JAVA] [EVALUATION] - The Java Failure (Sorry: The Java(tm) Failure)
http://groups-beta.google.com/group/comp.lang.java.softwaretools/msg/ae6315fda51d50a1
-
-
-
During the 6 months evaluation i've extracted several constructs.
"How it should be to become high evolutive"
-
I don't know python.
Basicly I would like to do everything in C++.
But development must go quicker.
-
I've seen that Nokia has just integrated Python it in a platform.
-
Possibly it's time to structure python projects in a way similar to 
Sun's Java, NetBeans and especially IBM&Co's Eclipse (but of course more 
efficient and evolutive):

http://lazaridis.com/case/ide/project/index.html
www.osgi.org and similar standards should (whenever possible) be used.
E.g. Nokia should be intrested in an python osgi implementation.
[Note: i've not verified technical and legal applicability]
-
osgi is just a detail.
The goal would be: to make a high competitive andhigh evolutive 
programming platform / Rich Client Platform based on Python.

-
My question is essentially:
How many of those constructs are already supported by python (and the 
surrounding open-source-projects):

http://lazaridis.com/case/stack/index.html
-
I'll be possibly for some time off-line, as the evaluation has brought 
me to my financial limits, thus i'm loosing my phone-line in a few hours.

I'll try to communicate via internet-cafe, but cannot promise this.
-
Please notify the people within the relevant python communities about 
this thread.

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


Re: Redirecting stdout/err under win32 platform

2005-02-02 Thread Pierre Barbier de Reuille
David Douard a écrit :
Alan,
I did search Google for this problem (not enough, thou).
In fact, I found some kind of solution (by myself, not that much on Google),
but it is not really satisfactory.
I have used win32 pipes to do so (win32api.CreatePipe). I can redirect
stdout/stderr to it from my python code (even redirecting the stdout/stderr
from my C lib). 
But I still have a problem with this solution (well, 2):
- it is *much* more complicated than any solution available on Unix like
systems (not really a problem, but),
- it not synchronous at all. And I'd like it to be so (or almost so).

David

AFAIK, there is no working bidirectionnal pipes on Windows ! The 
functions exists in order for them to claim being POSIX, but they're not 
working properly. Under Windows environment, I suppose you have to find 
your way using their buggy pipes (and by no means their "POSIX" pipes) 
or you have to use another inter-process communication protocol (DDE, 
COM, ...).

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


Re: test_socket.py failure

2005-02-02 Thread x2164
Marc Christiansen <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Nick Coghlan <[EMAIL PROTECTED]> wrote:
> >> Hmm, when the second argument is omitted, the system call looks like:
> >> 
> >> getservbyname("daytime", NULL);
> >> 
> >> Based on "man getservbyname" on my Linux PC, that should give
> >> the behaviour we 
> >> want - any protocol will match.
> >> 
> >> However:
> >> 
> >> Linux 2.6.4-52-default (Suse 9.1)
> >> Glibc 2.3.3
> >> gcc   3.3.3
> >> 
> >> So it may be that your older platform doesn't have this
> >> behaviour - I'd be very 
> >> interested in what 'man getservbyname' has to say.
> > 
> >Just took a look at the man page for getservbyname on this
> >system and it doesn't mention passing NULL as the second
> >argument.  The pertinents: ;-)
> > 
> >Linux kernel 2.6.10
> >Glibc 2.2.5
> >gcc   2.95.3

> Just to confuse the matter more, on my system the man page mentions
> passing NULL as the second argument and it works. Alas:
> SuSE 7.3
> Kernel 2.4.29 (vanilla)
> Glibc  2.2.4 (older than yours)
> gcc2.95.3

> >I'd say your probably right about there being a difference
> >in the behaviour of getservbyname between libc 2.2.5 and 
> >and libc-2.3.3 given the differences in man pages and 
> >observed return values. I'll try and compare the libcs'
> >getservbyname codes and let you know a little later in 
> >the day.
> > 
> >I wonder if the developers wanted to tie the python source
> >code so closely to a glibc version and possibly gnu-libc
> >specific?

> Perhaps SuSE did patch the glibc...

> Saluton
>   Marc



 hey Marc


 Oh man, not another problem that's just happening to
 me, again. :-)

 We all are still talking about python 2.4 aren't we?  I'm
 really running out of options on this.

 My manual page for getservbyname is dated "22 April 1996"
 and i think that it wasn't installed by glibc-2.2.5.  The
 info page for getservbyname which was installed by 2.2.5
 doesn't mention being able to pass NULL as a 'PROTO'
 argument.

 As for my saying above that i would take a look at the
 libcs' code for getservbyname, well, let's just say
 i won't be bantering about that idea so readily anytime
 soon. :-)

 What i believe happens in glibc-2.3.3 is that getservbyname
 is generated by two files: inet/getsrvbynm.c which contains
 a number of '#define's that then '#include's the file 
 nss/getXXbyYY.c which is sort of a template function that
 the '#define's fill out.  If your use to reading it
 nss/getXXbyYY.c probably is easy reading, but, for ego's sake,
 let's just say that i'm not use to reading it.  There's
 also  getsrvbynm_r.c and getXXbyYY_r.c for the reentrant
 versions of getservbyname plus some references to nss and
 nis versions of getservbyname.  Of course its also possilble
 that where i said "What i believe happens" at the beginning
 of this paragraph could be read as "I'm confused about what
 happens" and i don't mean that as critic of glibc.

 Marc, it is possible that there was a change between 
 glibc-2.2.4 and 2.2.5 that would account for the 
 difference in behaviour.  I think i'll write a little
 test program in C to check out getservbyname's return
 values in a little more controled environment.  I'll
 post the results tomorrow.

 
 pete jordan
 x2164   mailcity com


 

-- 


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


Re: CONTEST - What is the (best) solution?

2005-02-02 Thread Miki Tebeka
Hello Lad,

> In a file there can be several dictionaries like this
> {Key11: Value11
> Key12: Value12
> Key13: Value13,
> ...
> ...
> Key1n:Value1n}
> {Key21: Value21
> Key22: Value22
> Key23: Value23,
> ...
> ...
> Key2n:Value2n}
> {Key31: Value31
> Key32: Value32
> Key33: Value33,
> ...
> ...
> Key3n:Value3n}
> 
> 
> 
> {Keyn1: Valuen1
> Keyn2: Valuen2
> Keyn3: Value3,
> ...
> ...
> Keynn:Valuenn}
> 
> Each pair in a dictionary is separated by CRLF and in each dictionary
> numbers of pairs can be different.
> I need to read only the the first and the last dictionaries.What is a
> best solution?

 d.py ---

#!/usr/bin/env python

from sys import argv

dicts = eval("[" + open(argv[1]).read().replace("}", "},") + "]")
print dicts[0], dicts[-1]

 d.py ---

HTH.
--

Miki Tebeka <[EMAIL PROTECTED]>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys

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


Re: Two classes problem

2005-02-02 Thread Steven Bethard
Gurpreet Sachdeva wrote:
The purpose is, I pass a list to a class in a module but I want to use
that list out of the scope of that class and that too not in any other
class or a function but in the main program...
The problem is that when I import that, the statements in the module
which are not in the class are executed first and then the variable
gets intiallised...
I will explain with the example...
-global test
-
-class a:
-def __init__(self,test):
-global test
-print test
-
-print 'Outside: '+test
I want to print that variable test which I am giving to the class as
an argument, in the scope of main...
I know it is not a good way of programming but my situation is like this...
But is this possible or not? If I pass test as 'Garry' can I (by any
way) print 'Outside: Garry' with that print statement... (in the main
scope)
Probably a better approach for this would be something like:
class A(object):
def __init__(self, test):
self.test = test
def printtest(self):
print 'Outside: %s' % self.test
where your code in your main module looks something like:
import amodule
a = amodule.A('Garry')
a.printtest()
The __init__ method is used for initializing *instances* of a class, so 
using the __init__ method to initialize a module-level variable doesn't 
really make much sense.  If you really want to play around with 
module-level variables, you probably want to modify them with 
module-level functions, e.g.:

test = 'default'
def a(val):
global test
test = val
def printtest():
print 'Outside: %s' % test
where your code in your main module looks something like:
import amodule
amodule.a('Garry')
amodule.printtest()
Note that I've moved all your code that would normally be executed at 
module import time into the 'printtest' function.  This way you can 
execute this code after import.

If you really need to have the code executed at the same time as the 
module is imported, another option would be to exec your code in an 
empty module instead of importing it:

py> a_module_str = """print 'Outside: %s' % test"""
py> a_module = new.module('a')
py> a_module.test = 'Garry'
py> exec a_module_str in a_module.__dict__
Outside: Garry
Here I create an empty module, set its 'test' attribute to 'Garry', and 
then execute the rest of your code (e.g. the print statement).  This is 
certainly my least favorite approach, but it seems to do the closest 
thing to what you're asking for.

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


python-2.4.msi installation issue

2005-02-02 Thread mirandacascade
O/S: Windows XP Home (with Service Pack 2)
Downloaded python-2.4.msi from python.org (10,632KB).  When I double
click on the file from Windows Explorer, the installation process
presents the window in which I am prompted to either install for all
users (the default) or install for just me.  I selected the defaulted
value.  Installation process presents a window in which the user may
select the directory for python 2.4 files.  I selected the default
value of the Python24 folder.  After clicking Next, the process
presents a window with the message, "Python 2.4 installer ended
prematurely.  Python 2.4 ended prematurely because of an error.  Your
system has not been modified.  To install this program at a later time,
please run the installation again."

My question is this: how do I determine what the error was that caused
the installation process to end prematurely?

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


Popularizing SimpleHTTPServer and CGIHTTPServer

2005-02-02 Thread Michele Simionato
Just submitted a recipe with this goal in mind:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/365606
Michele Simionato

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


Re: Computing class variable on demand?

2005-02-02 Thread Steven Bethard
fortepianissimo wrote:
We all know that using __getattr__() we can compute an instance
variable on demand, for example:
class Foo:
def __getattr__ (self, name):
if name == 'bar':
self.bar = 'apple'
return self.bar
else:
raise AttributeError()
Then we can
f = Foo()
s1 = f.bar
s2 = f.bar   # this uses the "cached" result
My question is can we do the same with class variables?
You can do this using a metaclass, e.g.:
py> class FooType(type):
... def __getattr__(self, name):
... if name == 'bar':
... self.bar = 'apple'
... return self.bar
... else:
... raise AttributeError('no attribute named %r' % name)
...
py> class Foo(object):
... __metaclass__ = FooType
...
py> Foo.bar
'apple'
However, you probably don't want to.  What's your use case?
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Logging

2005-02-02 Thread Samuel Kilchenmann
"Neil Benn" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
Neil Benn wrote:
Hello,
 I'm running a test and having issues with logging, if I call 
logging.shutdown() and then want to start the logging going again 
then I get a problem as if I call shutdown, I can't get the root 
logger again, such as :

.
Previous code missed out a line :
.>>> import logging
.>>> objTestLogger = logging.getLogger()
.>>> objTestLogger.setLevel(logging.INFO)
.>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
.>>> objTestLogger.info("THIS IS A TEST")
.>>> logging.shutdown()
.>>> objTestLogger = logging.getLogger()
.>>> objTestLogger.setLevel(logging.INFO)
.>>> objTestLogger.addHandler(logging.FileHandler('c:\\test.log'))
.>>> objTestLogger.info("THIS IS A TEST")
.Traceback (most recent call last):
. File "c:\program files\python23\lib\logging\__init__.py", line 679, 
in emit
.self.stream.write("%s\n" % msg)
.ValueError: I/O operation on closed file
.>>>

logging.shutdown() doesn't clean up the dict of handlers at the module 
level and the list of handlers maintained and at the level of the 
manager of loggers. So after calling logging.getLogger() etc. for the 
second time, you still have the closed filehandle in the list of 
loghandlers. The new FileHandler with the open filehandle is appended to 
this list of handlers. Then when you call ...info("...") this call is 
dispatched to all handlers in the handlerlist, i.e. also to the one with 
the closed filehandle.
I don't know if this has to be considered a bug in the logging module or 
if your use case is simply not covered.
If you add something like
.>>> logging._handlers.clear()
.>>> logging.root.handlers = []
.>>> for l in logging.Logger.manager.loggerDict.values():
.>>> l.handlers = []
after logging.shutdown() and before getting the new logger, your script 
will probably run without errors.

hth,
Samuel 

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


Computing class variable on demand?

2005-02-02 Thread fortepianissimo
We all know that using __getattr__() we can compute an instance
variable on demand, for example:

class Foo:
def __getattr__ (self, name):
if name == 'bar':
self.bar = 'apple'
return self.bar
else:
raise AttributeError()

Then we can

f = Foo()
s1 = f.bar
s2 = f.bar   # this uses the "cached" result

My question is can we do the same with class variables? I can't find a
class-equivalent __getattr__ for this purpose. The key is to allow the
use of the following statement

Foo.bar   # bar is a class variable of Foo computed on demand
without unnecessary fudge. Thanks.

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


Re: Two classes problem

2005-02-02 Thread Gurpreet Sachdeva
The purpose is, I pass a list to a class in a module but I want to use
that list out of the scope of that class and that too not in any other
class or a function but in the main program...
The problem is that when I import that, the statements in the module
which are not in the class are executed first and then the variable
gets intiallised...
I will explain with the example...

-global test
-
-class a:
-def __init__(self,test):
-global test
-print test
-
-print 'Outside: '+test

I want to print that variable test which I am giving to the class as
an argument, in the scope of main...
I know it is not a good way of programming but my situation is like this...
But is this possible or not? If I pass test as 'Garry' can I (by any
way) print 'Outside: Garry' with that print statement... (in the main
scope)

Thanks and Regards,
Garry
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python AST Sprint

2005-02-02 Thread Robert Brewer
Timothy Fitz wrote:
> I am interested in helping Python, however my knowledge of Abstract
> Syntax Trees is lacking. Where should I turn to educate myself? Any
> books or websites would be appreciated.

Follow the links and advice in this python-dev thread:
http://marc.free.net.ph/thread/20050104.014254.b2978a88.en.html#20050104
.014254.b2978a88

That should hold you until the sprint ;)


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reinstall python 2.3 on OSX 10.3.5?

2005-02-02 Thread moa
keerist. I suspected as much. so much for my happy Mac feeling to date.

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


Re: IDLE history, Python IDE, and Interactive Python with Vim

2005-02-02 Thread Ashot
WingIDE looks nice though, and it seems that the interactive shell is  
built in from the screenshots.  Can you run a program to a certain point  
break point and use the shell?

On Wed, 02 Feb 2005 23:40:40 -0500, Stephen Waterbury <[EMAIL PROTECTED]>  
wrote:

Daniel Bickett wrote:
This is certainly a worthy topic. There are several IDEs for Python
(one I like very much being Komodo) that have plenty of fancy
debugging features and advanced operations, however I have yet to
encounter (elsewhere) the convenience that comes with being able to
press F5 and have an interactive interpreter load my code and be ready
for testing.
*Sigh*, I too am a vi kinda guy, and I keep badgering the WingIDE
gang to give Wing a vi mode ... :)  They keep saying "it's coming",
but it's been a while ... and in fairness to them, I don't think
there is exactly a huge horde of vi barbarians at their gate!
Probably a pretty tiny horde, and not very noisy.  ;)
Steve

--
==
Ashot Petrosian
University of Texas at Austin, Computer Sciences
(views expressed are solely my own)
==
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE history, Python IDE, and Interactive Python with Vim

2005-02-02 Thread Stephen Waterbury
Daniel Bickett wrote:
This is certainly a worthy topic. There are several IDEs for Python
(one I like very much being Komodo) that have plenty of fancy
debugging features and advanced operations, however I have yet to
encounter (elsewhere) the convenience that comes with being able to
press F5 and have an interactive interpreter load my code and be ready
for testing.
*Sigh*, I too am a vi kinda guy, and I keep badgering the WingIDE
gang to give Wing a vi mode ... :)  They keep saying "it's coming",
but it's been a while ... and in fairness to them, I don't think
there is exactly a huge horde of vi barbarians at their gate!
Probably a pretty tiny horde, and not very noisy.  ;)
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Atlas and NumPy Problems

2005-02-02 Thread Robert Kern
Robert Kern wrote:
Justin Lemkul wrote:
Hello all,
I am hoping someone out there will be able to help me.  I am trying to 
install a program that utilizes NumPy.  In installing NumPy, I 
realized that I was lacking Atlas.  I ran into the following problems 
installing Atlas and NumPy, as I realized that NumPy could be 
installed using the Mac OSX veclib already built in.  If anyone has 
any ideas on how to fix either of these, I would be most grateful.

I am fairly new to Python (I've been learning it myself), so I 
apologize if these questions are a bit foolish.  I've been fighting 
these problems for days, and I'm out of ideas.

I am running OS X v10.3, gcc v3.3, Python v2.3, ScientificPython 
v2.4.3, and am attempting to install NumPy 23.7

Did you try to follow my advice from the other thread? What does your 
setup.py look like?
For the record, he did in fact follow my advice (removing the 
ATLAS-specific defaults and letting setup.py autodetect the vecLib 
framework), and it turns out my advice was incomplete.

One also needs to add
  extra_link_args=extra_link_args,
to the argument list of the Extension() call for the _dotblas module.
It worked fine on my machine because I had modified my Python config to 
use "-undefined dynamic_lookup" instead of explicit -framework arguments 
(this change is necessary for the neighborly cohabitation of different 
Python versions, I believe. See the PythonMac-SIG archives for more 
information).

--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Awkwardness of C API for making tuples

2005-02-02 Thread Dave Cole
John Machin wrote:
Dave Opstad wrote:
One of the functions in a C extension I'm writing needs to return a
tuple of integers, where the length of the tuple is only known at
runtime. I'm currently doing a loop calling PyInt_FromLong to make
the
integers,

What is the purpose of this first loop?
In what variable-length storage are you storing these (Python) integers
during this first loop? Something you created with (a) PyMem_Malloc (b)
malloc (c) alloca (d) your_own_malloc?

then PyTuple_New, and finally a loop calling PyTuple_SET_ITEM
to set the tuple's items. Whew.

Whew indeed.

Does anyone know of a simpler way? I can't use Py_BuildValue because
I
don't know at compile-time how many values there are going to be. And

there doesn't seem to be a PyTuple_FromArray() function.
If I'm overlooking something obvious, please clue me in!

1. Determine the length of the required tuple; this may need a loop,
but only to _count_ the number of C longs that you have.
2. Use PyTuple_New.
3. Loop to fill the tuple, using PyInt_FromLong and PyTuple_SetItem.
Much later, after thoroughly testing your code, gingerly change
PyTuple_SetItem to PyTuple_SET_ITEM. Benchmark the difference. Is it
anywhere near what you saved by cutting out the store_in_temp_array
thing in the first loop?
Shouldn't something like this (uncompiled) do what you want?
- Dave
PyObject *PyTuple_FromArray(int *values, int num_values)
{
PyObject *tuple;
int i;
tuple = PyTuple_New(num_values);
if (tuple == NULL)
return NULL;
for (i = 0; i < num_values; i++) {
PyObject *obj;
obj = PyInt_FromLong(value[i]);
if (obj == NULL
|| PyTuple_SetItem(tuple, i, obj) != 0) {
Py_DECREF(tuple);
return NULL;
}
}
return tuple;
}
--
http://www.object-craft.com.au
--
http://mail.python.org/mailman/listinfo/python-list


Re: streaming a file object through re.finditer

2005-02-02 Thread Steven Bethard
Erick wrote:
Hello,
I've been looking for a while for an answer, but so far I haven't been
able to turn anything up yet. Basically, what I'd like to do is to use
re.finditer to search a large file (or a file stream), but I haven't
figured out how to get finditer to work without loading the entire file
into memory, or just reading one line at a time (or more complicated
buffering).
Can you use mmap?
http://docs.python.org/lib/module-mmap.html
"You can use mmap objects in most places where strings are expected; for 
example, you can use the re module to search through a memory-mapped file."

Seems applicable, and it should keep your memory use down, but I'm not 
very experienced with it...

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


Re: Easy Q: dealing with object type

2005-02-02 Thread Steven Bethard
Erik Johnson wrote:
"Erick" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Ah, you're running into the "old-style classes vs. new style classes".
Try subclassing from "object".
For example:
class A(object):
That works! :) I guess I am fortunate to be running 2.2 - looks kinda ugly
prior to that.
It's not horrible:
py> class A:
... pass
...
py> class B:
... pass
...
py> a = A()
py> a.__class__ == A
True
py> a.__class__ == B
False
Still, if you can use new-style classes, you should.
Also, you should probably Google for "duck typing".  Generally, in 
Python it is frowned upon to check the type of an object.  There are 
times when it's necessary, but if you're just starting off, my guess is 
that you haven't discovered one of these times yet...

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


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread vincent wehren
Tim Daneliuk wrote:
Steve Holden wrote:
Roland Heiber wrote:
Tim Daneliuk wrote:
Aha!  Exactly ... and that makes perfect sense too.  D'oh!  I guess a 
better
distribution strategy would be to have the installation program generate 
the pyo
file at installation time...

Thanks -
Also, the *.py? files contain the full pathname of the *.py they have 
been compiled from. Copying them to other path locations will give you 
the wrong __file___ information in tracebacks.

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


Re: Reinstall python 2.3 on OSX 10.3.5?

2005-02-02 Thread Christian Dieterich
On Dé Céadaoin, Feabh 2, 2005, at 17:48 America/Chicago, 
[EMAIL PROTECTED] wrote:

Hi there
I started a very long and roundabout process of attempting to install
python 2.3.4 along side my apple-installed 2.3 system. To make a long
story short, I have completely confabulated my environment ( i deleted
the 2.3 binaries and so forth from the system in an attempt to start
things fresh), and now I cannot figure out how to reinstall the base
2.3 Apple python distribution.
Can somebody please point me in the right direction?
You could use
fink install python
which makes you a Python installation under /sw.
Christian
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding user's home dir

2005-02-02 Thread Christian Dieterich
On Dé Céadaoin, Feabh 2, 2005, at 13:26 America/Chicago, Nemesis wrote:
Hi all, I'm trying to write a multiplatform function that tries to
return the actual user home directory. I saw that

Please, could you test it on your systems and tell me what you got?
I'd like to know what it returns on different operating systems because
I'm developing a multiplatform software.
It works with Python 2.2 and Python 2.3 on Mac OS 10.2 and Debian Linux.
Christian
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE history, Python IDE, and Interactive Python with Vim

2005-02-02 Thread Daniel Bickett
This is certainly a worthy topic. There are several IDEs for Python
(one I like very much being Komodo) that have plenty of fancy
debugging features and advanced operations, however I have yet to
encounter (elsewhere) the convenience that comes with being able to
press F5 and have an interactive interpreter load my code and be ready
for testing.

That said, that is my only reason for my ever using IDLE. Without it I
would probably forget that IDLE exists, were it not for the obnoxious
context menu entry. ;)

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: streaming a file object through re.finditer

2005-02-02 Thread Daniel Bickett
Erick wrote:
> True, but it doesn't work with multiline regular expressions :(

If your intent is for the expression to traverse multiple lines (and
possibly match *across* multiple lines,) then, as far as I know, you
have no choice but to load the whole file into memory.

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: streaming a file object through re.finditer

2005-02-02 Thread Erik Johnson

Is it not possible to wrap your loop below within a loop doing
file.read([size]) (or readline() or readlines([size]),
reading the file a chunk at a time then running your re on a per-chunk
basis?

-ej


"Erick" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ack, typo. What I meant was this:
> cat a b c > blah
>
> >>> import re
> >>> for m in re.finditer('\w+', file('blah')):
>
> ...   print m.group()
> ...
> Traceback (most recent call last):
> File "", line 1, in ?
> TypeError: buffer object expected
>
> Of course, this works fine, but it loads the file completely into
> memory (right?):
> >>> for m in re.finditer('\w+', file('blah').read()):
> ...   print m.group()
> ...
> a
> b
> c
>


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


Delivery failed

2005-02-02 Thread Post Office
The original message was received at Thu, 3 Feb 2005 08:03:02 +0500
from [182.255.28.192]

- The following addresses had permanent fatal errors -
python-list@python.org

- Transcript of session follows -
... while talking to 72.27.31.20:
550 5.1.2 ... Host unknown (Name server: host not found)

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

Re: Easy Q: dealing with object type

2005-02-02 Thread Erik Johnson

"Erick" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ah, you're running into the "old-style classes vs. new style classes".
> Try subclassing from "object".
>
> For example:
>
> >>> class A(object):

That works! :) I guess I am fortunate to be running 2.2 - looks kinda ugly
prior to that.

> Check out the following article, it should answer your questions:
>
http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html#SECTION00031


Thank you both for your replies! :)
-ej


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


Re: Finding user's home dir

2005-02-02 Thread Kartic
Nemesis said the following on 2/2/2005 2:26 PM:
Hi all, I'm trying to write a multiplatform function that tries to
def getHomeDir():
''' Try to find user's home directory, otherwise return current 
directory.'''
Please, could you test it on your systems and tell me what you got?
I'd like to know what it returns on different operating systems because
I'm developing a multiplatform software.
Thank you all.

Neat!
Works fine on Freebsd 5.3, Python 2.4
Thanks,
-Kartic
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reinstall python 2.3 on OSX 10.3.5?

2005-02-02 Thread Robert Kern
[EMAIL PROTECTED] wrote:
Hi there
I started a very long and roundabout process of attempting to install
python 2.3.4 along side my apple-installed 2.3 system. To make a long
story short, I have completely confabulated my environment ( i deleted
the 2.3 binaries and so forth from the system in an attempt to start
things fresh), and now I cannot figure out how to reinstall the base
2.3 Apple python distribution.
Can somebody please point me in the right direction?
Borrow Guido's time machine and prevent your former self from doing 
that. OS X depends on it's python being there untouched. They also have 
compiled stuff that does not exist in the standard Python distribution.

Back up your data and reinstall the OS.
--
Robert Kern
[EMAIL PROTECTED]
"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


IDLE history, Python IDE, and Interactive Python with Vim

2005-02-02 Thread Ashot
This is sort of both Python and Vim related (which is why I've posted to  
both newsgroups).

Python related:
--
I have been frustrated for quite some time with a lack of a history  
command in IDLE (in fact with IDLE in general).  Often I'll develop new  
code at the command line, testing each line as I go.  Currently I have to  
copy and paste, removing outputs and the ">>>" at each line.
Is it perhaps possible to make some kind of hack to do this (dump a  
command history)?

Idle in general isn't that great IMO, so I was wondering also if there are  
better alternatives out there?  What do people use mostly?  I've tried  
something called pyCrust, but this too didn't have history and some other  
things I was looking for.  On a more general note, although the agility  
and simplicity of Python make programming tools like an IDE less  
necessary, it still seems that Python is lacking in this departement.  The  
PyDev plug-in for Eclipse seems like good step in this direction, although  
I haven't tried it yet.  Does anyone have any experience with this, or  
perhaps can point me to other tools.

Vim related:
--
Ideally, it would be nice to have a command mapped to a keystroke that can  
append the last executed command to a file.  Even better would be a system  
that would integrate the file editing and interactive command line tool  
more seamlessly.  Something along the lines of a debugger + file editor  
+ command line utility, where file editor = vim.  I know that vim has a  
utility for running python commands from its command prompt, but I have  
had a hard time getting this to work in windows and haven't explored it.   
Has anyone seen/tried a system along these lines, perhaps incorporating  
the python debugger (pdb)?  I can see something that will run the file you  
are editing in vim up to the cursor or a mark with a set_trace at the line  
you are editing.

Any info is appreciated, thanks.
--
Ashot Petrosian
University of Texas at Austin, Computer Sciences
--
http://mail.python.org/mailman/listinfo/python-list


Python AST Sprint

2005-02-02 Thread Timothy Fitz
I am interested in helping Python, however my knowledge of Abstract
Syntax Trees is lacking. Where should I turn to educate myself? Any
books or websites would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CONTEST - What is the (best) solution?

2005-02-02 Thread Daniel Bickett
Cappy2112 wrote:
> > dictionaries can NOT contain dictionaries.
> 
> Who told you this?
> In my python, they can.
> [snip]

You took his reply out of context. Fuzzyman asked him if *his*
dictionaries were to contain dictionaries, and the reply was no, they
will not.

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: streaming a file object through re.finditer

2005-02-02 Thread Erick
True, but it doesn't work with multiline regular expressions :(

-e

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


Re: Easy Q: dealing with object type

2005-02-02 Thread Erick
Ah, you're running into the "old-style classes vs. new style classes".
Try subclassing from "object".

For example:

>>> class A(object):
...   pass
...
>>> a=A()
>>> type(a)

>>> type(a) == A
True
>>> type(a) is A
True
>>> b=A()
>>> type(a) == type(b)
True
>>> type(a) is type(b)
True


Check out the following article, it should answer your questions:
http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html#SECTION00031
-e

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


Re: streaming a file object through re.finditer

2005-02-02 Thread Erick
Ack, typo. What I meant was this:
cat a b c > blah

>>> import re
>>> for m in re.finditer('\w+', file('blah')):

...   print m.group()
...
Traceback (most recent call last):
File "", line 1, in ?
TypeError: buffer object expected

Of course, this works fine, but it loads the file completely into
memory (right?):
>>> for m in re.finditer('\w+', file('blah').read()):
...   print m.group()
...
a
b
c

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


Re: streaming a file object through re.finditer

2005-02-02 Thread Daniel Bickett
The following example loads the file into memory only one line at a
time, so it should suit your purposes:

>>> data = file( "important.dat" , "w" )
>>> data.write("this\nis\nimportant\ndata")
>>> data.close()

now read it

>>> import re
>>> data = file( "important.dat" , "r" )
>>> line = data.readline()
>>> while line:
for x in re.finditer( "\w+" , line):
print x.group()
line = data.readline()


this
is
important
data
>>> 


-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easy Q: dealing with object type

2005-02-02 Thread Erick
Ah, you're running into the "old-style classes vs. new style classes".
Try subclassing from "object".

For example:

>>> class A(object):
...   pass
...
>>> a=A()
>>> type(a)

>>> type(a) == A
True
>>> type(a) is A
True
>>> b=A()
>>> type(a) == type(b)
True
>>> type(a) is type(b)
True


Check out the following article, it should answer your questions:
http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html#SECTION00031
-e

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


Re: how about writing some gui to a known console application

2005-02-02 Thread Grant Edwards
On 2005-02-01, alexrait1 <[EMAIL PROTECTED]> wrote:

> I tried to delete this message, but I guess it was too late... or it
> didn't work for me... sorry anyway.

No worries.  Since the article didn't have a refereces or
in-reply-to header, it showed up as the first post in it's own
thread.  I later saw the post to which you intended to reply.

-- 
Grant Edwards   grante Yow!  The entire CHINESE
  at   WOMEN'S VOLLEYBALL TEAM all
   visi.comshare ONE personality --
   and have since BIRTH!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easy Q: dealing with object type

2005-02-02 Thread Daniel Bickett
On Erik Johnson wrote:
> # The following "works", but I don't want to keep a set of instances to
> compare against
> >>> obj2 = A()
> >>> type(obj) == type(obj2)
> 1

How about:

>>> class A:
pass
>>> class B:
pass
>>> objA = A()
>>> type( objA ) == type( A() )
True

then again

>>> objB = B()
>>> type( objA ) == type( B() )
True

they're both of type 'instance'. So how about this:

>>> class A:
pass
>>> class B( object ):
pass
>>> objA = A()
>>> objB = B()
>>> type( objA )

>>> type( objB )

>>> type( objB ) == B
True

I believe that achieves what you were aiming for.

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how about writing some gui to a known console application

2005-02-02 Thread Grant Edwards
On 2005-02-01, Jeremy Bowers <[EMAIL PROTECTED]> wrote:
> On Tue, 01 Feb 2005 21:57:45 +, Grant Edwards wrote:
>
>> On 2005-02-01, alexrait1 <[EMAIL PROTECTED]> wrote:
>> 
>>> Do something useful... (at least for me) For instance I need a gtk
>>> frontend for pgp. So here you can have an opportunity to learn both
>>> pyGTK and pgp. A lot of python code... :)
>> 
>> Um, to whom are you addressing your commands?
>
> Presumably the "Suggesion[sic] for an undergrad final year project in
> Python" thread.

Ah yes. The article to which I posted a follow-up wasn't part
of a thread.  I now see there was a different thread with the
same topic.

-- 
Grant Edwards   grante Yow!  I have a very good
  at   DENTAL PLAN. Thank you.
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


streaming a file object through re.finditer

2005-02-02 Thread Erick
Hello,

I've been looking for a while for an answer, but so far I haven't been
able to turn anything up yet. Basically, what I'd like to do is to use
re.finditer to search a large file (or a file stream), but I haven't
figured out how to get finditer to work without loading the entire file
into memory, or just reading one line at a time (or more complicated
buffering).

For example, say I do this:
cat a b c > blah

Then run this python script:
>>> import re
>>> for m in re.finditer('\w+', buffer(file('blah'))):
...   print m.group()
...
Traceback (most recent call last):
File "", line 1, in ?
TypeError: buffer object expected

Of course, this works fine, but it loads the file completely into
memory (right?):
>>> for m in re.finditer('\w+', buffer(file('blah').read())):
...   print m.group()
...
a
b
c

So, is there any way to do this?

Thanks,

-e

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


Easy Q: dealing with object type

2005-02-02 Thread Erik Johnson

I quickly browsed through section 9 of the Tutorial, tried some simple
Google searches: I'm not readily seeing how to test class type.  Given some
object (might be an instance of a user-created class, might be None, might
be list, might be some other "standard" type object instance), how do you
test its type?


Python 2.2.2 (#1, Mar 17 2003, 15:17:58)
[GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
...   pass
...
>>> obj = A()
>>> obj
<__main__.A instance at 0x81778d4>

# Here, it's fairly obvious its an A-type object. A as defined in module
'__main__'.

# Some of the comparisons against "Python primitives", work as you might
expect...
>>> int

>>> type(3) == int
1
>>> ls = range(3)
>>> ls
[0, 1, 2]
>>> type(ls)

>>> type(ls) == list
1
>>> type({}) == dict
1
>>> type(3.14) == float
1


# but this doesn't seem to extend to user-defined classes.
>>> dir(obj)
['__doc__', '__module__']
>>> obj.__module__
'__main__'
>>> type(obj)

>>> type(obj) == A
0
>>> type(obj) is A
0

# The following "works", but I don't want to keep a set of instances to
compare against
>>> obj2 = A()
>>> type(obj) == type(obj2)
1



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


Re: CONTEST - What is the (best) solution?

2005-02-02 Thread Cappy2112


> dictionaries can NOT contain dictionaries.

Who told you this?
In my python, they can.

d1={1:"one"}
>>> d2={2:"two"}
>>> d1
{1: 'one'}
>>> d2
{2: 'two'}
>>> d3={3:d2}
>>> d3
{3: {2: 'two'}}

[EMAIL PROTECTED] wrote:
> Fuzzyman wrote:
> > Can your dictionaries contain dictionaries ?
> Hi Fuzzy,
> dictionaries can NOT contain dictionaries.
> I re-checked and I would need only the last dictionary.
> Any idea how I could do that?
> Thanks
> Lad.

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


Re: Suggesion for an undergrad final year project in Python

2005-02-02 Thread JanC
Kartic schreef:

> Or if you are the networking types, come up with a peer-to-peer chat 
> application with whitetboard capability, which I am sure will be fairly 
> novel.

Hm, a Python version of The Coccinella?  :-)

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and gpl

2005-02-02 Thread JanC
Paul Rubin schreef:

> My IANAL amateur reading is that the GPL does in fact apply, at least
> in the US.  Running the program is not restricted, but loading the
> program from disk to memory before you can run it counts as copying
> it, which invokes the license, Computer Associates v. Altai, 982 F.2d
> 693.  I personally believe that doctrine is insane, but that's what
> software companies pushed through the courts in order to make
> shrink-wrap EULA's enforceable.  (Otherwise they'd only be enforceable
> if you agreed to the terms before the vendor got your money).

In Belgium (and the whole EU, I think) copying a program from disk to 
memory to be able to run it is covered under "fair use" (just like copying 
digital data from an audio CD to a DAC to be able to listen to it is fair 
use), which can't be restricted by companies.

AFAIK. IANAL. Etc.  ;-)

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML with Unicode: what am I doing wrong?

2005-02-02 Thread Kevin Dangoor
In article  news.t-online.com>,
"Diez B. Roggisch"  web.de> wrote:
you confuse unicode with utf8. Expat can parse the latter - the former is
internal to python. And passing it to something that needs a string will
result in a conversion - which fails because of the ascii encoding.

Ahh... that makes sense. I kept thinking that if I'm working with 
unicode strings, I should be passing around unicode objects. What you 
say makes sense, though, that the PyExpat understands UTF-8 encoded 
strings. Working with unicode objects in Python is so transparent, it's 
easy to forget about what a C extension would likely want.

Thanks Diez and Just for the quick responses!
Kevin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie alert

2005-02-02 Thread Timo Virkkala
Valone, Toren W. wrote:
Traceback (most recent call last):
  File "C:/Python24/dialog1.py", line 29, in -toplevel-
d = MyDialog(root)
NameError: name 'MyDialog' is not defined
Suggestion: Read the place in your code where MyDialog is defined and compare it 
with where it is used. Check case. You'll find the problem :)

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


Re: global variables

2005-02-02 Thread M.E.Farmer
Ok it has been a long day,
In my reply to Steven Bethard , Steve should read Steven ;)

M.E.Farmer

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


managing multiple subprocesses

2005-02-02 Thread Marcos
Hi guys,
I realise this question has been answered in one form or another many
times before but I can't quite find the solution I need. I am trying to
run multiple subprocesses from a python script and then wait until all
subprocesses have completed before continuing. The subprocesses run on
other machines ie this is a coarse grained parallel computation task.

So the commands I am using are:
for x in range(0, limit):
os.system("xgrid  ./someprogram %d &" % x)

and then to check whether they are all finished I do a very crude:

joblist = commands.getoutput("xgrid  -job list")
while joblist != "{jobArray = (); }":
time.sleep(1)
joblist = commands.getoutput("xgrid  -job list")

Xgrid is a system for parallel computation on Mac OS X. It is quite
good, check it out at www.apple.com/acg/xgrid. But anyway the method I
am using above, while it works, it quite often hangs. I'd like to just
run all the subprocesses at once and then check within the script,
rather than an auxilliary, to see if everything has returned. The
output of the commands is not important as that gets redirected to
files outside the script. I have tried all sorts of popens / excevs /
os.systems / commands etc etc. I realise the subprocess module may have
what I need but I can't get python 2.4 on the Mac so I need a 2.3 based
solution. Any help is much appreciated. Cheers.

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


Re: global variables

2005-02-02 Thread M.E.Farmer
Steve,
Yes I agree ;) Never use builtin names.
I know better but missed it somehow.
I apologize for any confusion I may have caused.
Thank you Steve for the correction.
M.E.Farmer

Steven Bethard wrote:
> M.E.Farmer wrote:
> > alex wrote:
> >> is it possible to create 'global' variables that can be seen in
all
> >> other classes?
> >
> > What about using a class?
> >
> > Py> class globalVar:
> > ...pass
> >
> > Py> globals = globalVar()
>
> Probably naming it something other than 'globals' would be a good
idea
> -- otherwise you'll hide the builtin globals() function.
>
> But I agree that the attributes of a class instance (as you suggest)
or
> the attributes of a module (as Steve Holden suggests) is probably the
> right way to go.
> 
> Steve

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


Re: Finding user's home dir

2005-02-02 Thread Nick
Python 2.4 (#1, Jan  1 2005, 21:33:55)
[GCC 3.3.4] on linux2
Slackware 10 Current
Works! Nice.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Printing Filenames with non-Ascii-Characters

2005-02-02 Thread aurora
 > print d.encode('cp437')
So I would have to specify the encoding on every call to print? I am  
sure to
forget and I don't like the program dying, in my case garbled output  
would be
much more acceptable.
Marian I'm with you. You never known you have put enough encode in all the  
right places and there is no static type checking to help you. So that  
short answer is to set a different default in sitecustomize.py. I'm trying  
to writeup something about unicode in Python, once I understand what's  
going on inside...
--
http://mail.python.org/mailman/listinfo/python-list


Re: global variables

2005-02-02 Thread Larry Bates
One way to to this is by using keyword args:
class a:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.arg1=arg1
self.arg2=arg2
self.__dict__.update(kwargs)
return
class b:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.__dict__.update(kwargs)
self.a=a(arg1, arg2, **kwargs)
return
class c:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.__dict__.update(kwargs)
self.b=b(arg1, arg2, **kwargs)
return
globals={'global1':1, 'global2':2, 'global3':3, 'global4':4}
C=c(1, 2, **globals)
you will have global1, global2, global3, and global4 attributs
in all classes.  If you don't want the attributes, just access
to the values, delete the self.__dict__.update(kwargs) lines.
Larry Bates
alex wrote:
Hi,
is it possible to create 'global' variables that can be seen in all
other classes?
Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: global variables

2005-02-02 Thread Steven Bethard
M.E.Farmer wrote:
alex wrote:
is it possible to create 'global' variables that can be seen in all
other classes?
What about using a class?
Py> class globalVar:
...pass
Py> globals = globalVar()
Probably naming it something other than 'globals' would be a good idea 
-- otherwise you'll hide the builtin globals() function.

But I agree that the attributes of a class instance (as you suggest) or 
the attributes of a module (as Steve Holden suggests) is probably the 
right way to go.

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


managing multiple subprocesses

2005-02-02 Thread Marcos
Hi guys,
I realise this question has been answered in one form or another many
times before but I can't quite find the solution I need. I am trying to
run multiple subprocesses from a python script and then wait until all
subprocesses have completed before continuing. The subprocesses run on
other machines ie this is a coarse grained parallel computation task.

So the commands I am using are:
for x in range(0, limit):
os.system("xgrid  ./someprogram %d &" % x)

and then to check whether they are all finished I do a very crude:

joblist = commands.getoutput("xgrid  -job list")
while joblist != "{jobArray = (); }":
time.sleep(1)
joblist = commands.getoutput("xgrid  -job list")

Xgrid is a system for parallel computation on Mac OS X. It is quite
good, check it out at www.apple.com/acg/xgrid. But anyway the method I
am using above, while it works, it quite often hangs. I'd like to just
run all the subprocesses at once and then check within the script,
rather than an auxilliary, to see if everything has returned. The
output of the commands is not important as that gets redirected to
files outside the script. I have tried all sorts of popens / excevs /
os.systems / commands etc etc. I realise the subprocess module may have
what I need but I can't get python 2.4 on the Mac so I need a 2.3 based
solution. Any help is much appreciated. Cheers.

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


Re: Is this a contradiction in the docs ?

2005-02-02 Thread Terry Reedy

"Fuzzyman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Equally possible (or more likely !) is that I misunderstand it :

Or that you did not sufficiently test the indicated difference ;-)

> The docs for compile say that if you are creating a code object from a
> sequence of statements you must use the kind argument 'exec'. Eval says
> that if you are using the eval function you must use 'eval' as your
> kind argument.

And I believe that if you use the eval function as a function, rather than 
as a subroutine, the latter *is* true.

 > In practise I have found that using the eval function with code objects
> compiled with 'exec' as the kind argument works fine.

A minimal code example backing your claim would have been illuminative.
Eval'ing exec-compiled expressions does NOT work fine, as least not in 2.2, 
and, I suspect, in all other versions:

>>> def test():
...   print 'in test'
...   return 1
...
>>> coex = compile('test()', '', 'exec')
>>> coev = compile('test()', '', 'eval')
>>> print eval(coex)
in test
None# wrong due to exex-compile-eval mismatch bug
>>> print eval(coev)
in test
1

The compile flag affects the code generation, but it does not get attached 
to the resulting code object.  Eval runs the code object without knowing 
whether the correct flag was used.  Therefore, 'must use the correct flag' 
means 'must, in order to get correct functioning' (in particular, the 
return of the expression value rather than None), and not 'must, in order 
to run at all'.  A 'practise' that only tests running and ignores incorrect 
value returning is not a complete test.

Terry J. Reedy





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


Re: global variables

2005-02-02 Thread M.E.Farmer
alex wrote:
> Hi,
>
> is it possible to create 'global' variables that can be seen in all
> other classes?
>
> Alex
Hello,
What about using a class?

Py> class globalVar:
...pass

Py> globals = globalVar()

Now you can assign 'variables' to it.
And use it anywhere you need it.

Py> globals.image_height = (255,777)
Py> globals.image_mode = 'RGB'
Py> globals.image_names = ['this.jpg', that.jpg']
etc...
hth, 
M.E.Farmer

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


Reinstall python 2.3 on OSX 10.3.5?

2005-02-02 Thread moa
Hi there

I started a very long and roundabout process of attempting to install
python 2.3.4 along side my apple-installed 2.3 system. To make a long
story short, I have completely confabulated my environment ( i deleted
the 2.3 binaries and so forth from the system in an attempt to start
things fresh), and now I cannot figure out how to reinstall the base
2.3 Apple python distribution.
Can somebody please point me in the right direction?

best -Nick

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


Re: Newbie alert

2005-02-02 Thread Steve Holden
Valone, Toren W. wrote:
Ok, new to Python and Tkinter.. Following along examples in book, got to
dialog windows example coded this
# dialog1.py
from Tkinter import *
class Mydialog:


[...]
d = MyDialog(root)
  
root.wait_window(d.top)   

When I run it IDLE 

gives me this
Traceback (most recent call last):
  File "C:/Python24/dialog1.py", line 29, in -toplevel-
d = MyDialog(root)
NameError: name 'MyDialog' is not defined
I have a feeling this is something very simple, but I cannot figure it out.
Help!
Python is case-sensitive!
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread Steve Holden
Tim Daneliuk wrote:
Steve Holden wrote:
Roland Heiber wrote:
Tim Daneliuk wrote:
It does - thanks.  One more question:  Are pyc and pyo file portable
across operating systems?  I suspect not since I generated a pyo
on a FreeBSD machine that will not run on a Win32 machine.  I was
under the impression that "compiled" meant optimized byte code that
was portable across implementations, but it looks to not be the case...
Hi,
..pyc's should be, cause it's standard python-bytecode, if you use 
massive optimizations it depends not on the os but on the underlying 
cpu/architecture ...

So long, Roland

You probably tried to use a bytecode file from *one* version of Python 
with an interpreter of another version. Python actually checks the 
first four bytes of the .pyc file for a compatible "magic number" 
before accepting the file for execution.

regards
 Steve

Aha!  Exactly ... and that makes perfect sense too.  D'oh!  I guess a 
better
distribution strategy would be to have the installation program generate 
the pyo
file at installation time...

Thanks -
That's what most sensible distributions do.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread Tim Daneliuk
Steve Holden wrote:
Roland Heiber wrote:
Tim Daneliuk wrote:
It does - thanks.  One more question:  Are pyc and pyo file portable
across operating systems?  I suspect not since I generated a pyo
on a FreeBSD machine that will not run on a Win32 machine.  I was
under the impression that "compiled" meant optimized byte code that
was portable across implementations, but it looks to not be the case...
Hi,
..pyc's should be, cause it's standard python-bytecode, if you use 
massive optimizations it depends not on the os but on the underlying 
cpu/architecture ...

So long, Roland

You probably tried to use a bytecode file from *one* version of Python 
with an interpreter of another version. Python actually checks the first 
four bytes of the .pyc file for a compatible "magic number" before 
accepting the file for execution.

regards
 Steve
Aha!  Exactly ... and that makes perfect sense too.  D'oh!  I guess a better
distribution strategy would be to have the installation program generate the pyo
file at installation time...
Thanks -
--

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


Newbie alert

2005-02-02 Thread Valone, Toren W.
Ok, new to Python and Tkinter.. Following along examples in book, got to
dialog windows example coded this

# dialog1.py

from Tkinter import *

class Mydialog:

  def _int_(self,parent):

top = self.top = Toplevel(parent)

Label(top, text="Value").pack()

self.e = Entry(top)
self.e.pack(padx=5)

b = Button(top,text="OK", command=self.ok)
   
b.pack(pady=5)

  def ok(self):

print "value is", self.e.get()
self.top.destroy()

root = Tk()
Button(root, text="Hello!").pack()
root.update()

d = MyDialog(root)

root.wait_window(d.top)   

When I run it IDLE 

gives me this

Traceback (most recent call last):
  File "C:/Python24/dialog1.py", line 29, in -toplevel-
d = MyDialog(root)
NameError: name 'MyDialog' is not defined

I have a feeling this is something very simple, but I cannot figure it out.
Help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic file operation questions

2005-02-02 Thread David Douard
David Douard wrote:

> Marcel van den Dungen wrote:
> 
>> alex wrote:
>>> Hi,
>>> 
>>> I am a beginner with python and here is my first question:
>>> How can I read the contents of a file using a loop or something? I open
>>> the file with file=open(filename, 'r') and what to do then? Can I use
>>> something like
>>> 
>>> for xxx in file:
>>>
>>> 
>>> 
>>> Thanks for help
>>> Alex
>>> 
>> take a look at this:
>> http://www.devshed.com/c/a/Python/File-Management-in-Python/
>> 
>> HTH,
>> -- Marcel
> 
> Or even have a look at the excellent Gnosis book on the subject (and very
> much more further, but...):
> http://gnosis.cx/TPiP/ which is freely available in text format.
> 
> David

Just to tell (it's not clear at all in my message): the author of the book
and creator of Gnosis Software is  David Mertz, and the book is published
by Addison Wesley.
Sorry

David

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


Re: global variables

2005-02-02 Thread Steve Holden
alex wrote:
Hi,
is it possible to create 'global' variables that can be seen in all
other classes?
Alex
Not sensibly, though you can mess around with the __builtin__ namespace 
to make values accessible without qualification.

The usual solution is to maintain a config module that establishes 
default settings for configuration variables. Other modules that import 
config can access (and change) those values using

  config.name = value
and so on. Hope this help.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Basic file operation questions

2005-02-02 Thread David Douard
Marcel van den Dungen wrote:

> alex wrote:
>> Hi,
>> 
>> I am a beginner with python and here is my first question:
>> How can I read the contents of a file using a loop or something? I open
>> the file with file=open(filename, 'r') and what to do then? Can I use
>> something like
>> 
>> for xxx in file:
>>
>> 
>> 
>> Thanks for help
>> Alex
>> 
> take a look at this:
> http://www.devshed.com/c/a/Python/File-Management-in-Python/
> 
> HTH,
> -- Marcel

Or even have a look at the excellent Gnosis book on the subject (and very
much more further, but...):
http://gnosis.cx/TPiP/ which is freely available in text format.

David




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


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread Steve Holden
Roland Heiber wrote:
Tim Daneliuk wrote:
It does - thanks.  One more question:  Are pyc and pyo file portable
across operating systems?  I suspect not since I generated a pyo
on a FreeBSD machine that will not run on a Win32 machine.  I was
under the impression that "compiled" meant optimized byte code that
was portable across implementations, but it looks to not be the case...
Hi,
..pyc's should be, cause it's standard python-bytecode, if you use 
massive optimizations it depends not on the os but on the underlying 
cpu/architecture ...

So long, Roland
You probably tried to use a bytecode file from *one* version of Python 
with an interpreter of another version. Python actually checks the first 
four bytes of the .pyc file for a compatible "magic number" before 
accepting the file for execution.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.python.org/pycon/2005/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: continuous plotting with Tkinter

2005-02-02 Thread David Douard
Martin Blume wrote:

> I have a number-crunching application that spits out
> a lot of numbers. Now I'd like to pipe this into a python
> app and plot them using Tkinter, such as:
> $ number_cruncher | myplot.py
> But with Tkinter once  I call Tkinter's mainloop() I
> give up my control of the app and I can't continue to
> read in data from stdin.  Or can I? If so, how?
> 
> Regards
> Martin

Maybe the simpler is to run the Tk mainloop in a separate thread.
You may have a look a candygram which gives a very simple to use
multi-thread semantics (ala Haskell) and is simpler to use than the
threading module.


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


Re: Getting a module's byte code, how?

2005-02-02 Thread Irmen de Jong
Steve Holden wrote:
But I also want the bytecode of modules that don't have a .pyc file,
possibly because they have already been 'dynamically' loaded from
another bytecode string ;-)
Aah, right, I suspect in these cases (which *are* pretty far from the 
ordinary run of things) you'd sometimes be up the creek without a paddle.
I was afraid of that.
The whole mobile code stuff in Pyro is very powerful, for the
cases where it works and makes sense, I think.
However it is also fairly messy.
In the end perhaps it introduces more problems than it solves,
but its really nice to see it work for the simple cases :)

I want them! :-)
Well I'm afraid there's no guarantee that they haven't already been 
garbage collected, and stamping your foot isn't going to do any good :-)
Heh, that was funny :D
A pleasure. Thanks for Pyro! (and thanks for reminding me indirectly 
that I need to guard that execution of hte module's code against 
exceptions).
Pyro happily throws these exceptions in your face.
Like I said, rather messy.
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread Roland Heiber
Tim Daneliuk wrote:
It does - thanks.  One more question:  Are pyc and pyo file portable
across operating systems?  I suspect not since I generated a pyo
on a FreeBSD machine that will not run on a Win32 machine.  I was
under the impression that "compiled" meant optimized byte code that
was portable across implementations, but it looks to not be the case...
Hi,
.pyc's should be, cause it's standard python-bytecode, if you use 
massive optimizations it depends not on the os but on the underlying 
cpu/architecture ...

So long, Roland
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integrated Testing - Peppable?

2005-02-02 Thread John Roth
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Hi,
Please excuse the intrusion from an admirer, but not a user, of Python.
I've got an idea that I think could improve the language and might be
relatively simple to implement.  I've developed a prototype with a toy
language here: , with screenshot
here: 
The idea is that if the language had testing built into it, editors
could take advantage of that to highlight, not by syntax, but by
correctness (as defined by the tests).  As a side effect, coverage
coloring is also possible.
So far, I see the need for three keywords: "expect", "returns", and
"archetype".  "expect" and "returns" get used together, as an
expression of what the function should return, given certain inputs.
"archetype" would define edit-type instantiable objects that could be
used in the tests.  The biggest lack at present is support for void
functions.
So...  Should I turn this into a PEP?
I'd say no, for a couple of reasons. One is that there
are Eclipse plugins that do this for JUnit; they don't
require any changes to Java in order to function. They
just require JUnit, which is pretty ubuquitous.
Second, is that the IDEs aren't part of Python proper.
Outside of that, it's might be quite a good idea to
do something similar with unittest, doctest or py.test.
John Roth
Peace,
--Carl
--
http://mail.python.org/mailman/listinfo/python-list


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread Tim Daneliuk
Roland Heiber wrote:
Tim Daneliuk wrote:
I use a makefile to create distribution tarballs of freestanding Python
programs and their documentation.  I cannot seem to find the right
command line option to just generate a pyc/pyo file from the program
and then exit.  If I use 'python - -c"import myprog"' it creates
the pyo file, but myprog starts up and keeps running.
IOW, I need a batch method for generating compiled python.  I know it
exists, but I can't find it for some reason ...
TIA,
Hi,
take a look at http://docs.python.org/lib/module-compileall.html
HtH, Roland
It does - thanks.  One more question:  Are pyc and pyo file portable
across operating systems?  I suspect not since I generated a pyo
on a FreeBSD machine that will not run on a Win32 machine.  I was
under the impression that "compiled" meant optimized byte code that
was portable across implementations, but it looks to not be the case...
--

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


Re: Reference count question

2005-02-02 Thread John Machin

Fredrik Lundh wrote:
>
> >PyList_SetItem(List,i,Str);
>
> you should check the return value, though.  PyList_SetItem may (in
> theory) fail.
>

:-)
Only a bot could say that. We mere mortals have been known to do things
like (a) pass a non-list as the first argument (b) pass an out-of-range
value for the second argument.
(-:

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


pyFMOD problem

2005-02-02 Thread Tian
I am trying to use pyfmod in python to manipulate sound.
i have installed pyfmod, ctype, numarray (if they are necessary), i
also copied fmod.dll to python/DLLs as well as windows/system32, but
when i tried

   import pyFMOD

I got:

Traceback (most recent call last):
  File "", line 1, in -toplevel-
import pyFMOD
  File "C:\Python24\Lib\site-packages\pyFMOD.py", line 177, in
-toplevel-
_FSOUND_Sample_Load = getattr(fmod, "[EMAIL PROTECTED]")
  File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 323,
in __getattr__
func = self._StdcallFuncPtr(name, self)
AttributeError: function '[EMAIL PROTECTED]' not found
-
How can I deal with this?
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a module's byte code, how?

2005-02-02 Thread Steve Holden
Irmen de Jong wrote:
Steve Holden wrote:
Having said which, if the module was loaded from a .pyc file then the 
bytecode is available from that - take everything but the first eight 
bytes and use marshal.loads() to turn it back into a code object:

Yup. As I explained in the other message, this is basically
what I'm doing at the moment (with a few twists; it reads the .py
file if no .pyc is available).
But I also want the bytecode of modules that don't have a .pyc file,
possibly because they have already been 'dynamically' loaded from
another bytecode string ;-)
Aah, right, I suspect in these cases (which *are* pretty far from the 
ordinary run of things) you'd sometimes be up the creek without a paddle.

Now, I could ofcourse store the bytecode string that I started
with *inside* the module itself, in a special attribute or so.
This just occurred to me and I think it's a possible solution.
But the bytecodes must be stored by Python itself somewhere
already... because Python is able to execute my module... right?
Not necessarily. I've just been playing with importing modules from a 
database. Here's the relevant extract from my load_module() function:

code, package, path = row # ... from the database
code = marshal.loads(code)
module = DBmodule(modname) # subclass of moduleType
sys.modules[modname] = module
module.__name__ = modname
module.__file__ = path # "db:%s" % modname
module.__loader__ = dbimporter
if package:
module.__path__ = ["*db*"]
exec code in module.__dict__
#print modname, "loaded:", module, "pkg:", package
return module
Note well that the module is essentially imported by executing its 
bytecode in the context of the module's directory. From that point on 
the module doesn't need access to its code - all its functions and 
classes have been created, and the functions and methods reachable from 
the module's __dict__ now have appropriate snippets of the byte code as 
their own code objects.

I want them! :-)
Well I'm afraid there's no guarantee that they haven't already been 
garbage collected, and stamping your foot isn't going to do any good :-)

Note that the ugly details *might* change, and that byte codes are 
version-dependent.

I know, but this fact was not yet mentioned in the Pyro manual.
Thanks for reminding me, I'll add it.
--Irmen
A pleasure. Thanks for Pyro! (and thanks for reminding me indirectly 
that I need to guard that execution of hte module's code against 
exceptions).

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.python.org/pycon/2005/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


global variables

2005-02-02 Thread alex
Hi,

is it possible to create 'global' variables that can be seen in all
other classes?

Alex

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


Question about pyFMOD importing

2005-02-02 Thread Tian
I am trying to use pyFMOD, I have installed all other supporting
libraries (hopefully), such as ctypes, numarray, I also installed FMOD
itself and copied its DLL files to python/DLLs. When I try to import
pyFMOD in python, i got this message:

>>> import pyFMOD

Traceback (most recent call last):
  File "", line 1, in -toplevel-
import pyFMOD
  File "C:\Python24\Lib\site-packages\pyFMOD.py", line 2, in
-toplevel-
fmod = windll.fmod
  File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 346,
in __getattr__
dll = self._dlltype(name)
  File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 283,
in __init__
self._handle = _LoadLibrary(self._name)
WindowsError: [Errno 126] The specified module could not be found

Seems there are something wrong in ctype and its related DLL? How
should I install it right?

Another question, where can I find a tutorial of pyFMOD? the document
of FMOD itself is daunting and I don't know how exactly pyFMOD wraps
it.

Thanks!!

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


Re: Crashing Python interpreter! (windows XP, python2.3.4, 2.3.5rc1, 2.4.0)

2005-02-02 Thread John Machin

Leeuw van der, Tim TOP-POSTED:
> Hi all,
>
> I can use this version of gtk and PyGtk to run simple programs. There
seems to be no problem with the code-completion in PythonWin.
> I can do: dir(gtk) without problems after importing the gtk module of
PyGtk, when I use idle or console. (Python version for this test:
python2.4, python 2.3.5rc1)
>
> I already knew that I could run simple PyGtk programs with this
combination of Python, PyGtk, and Gtk. Also knew already, that the code
completion in the PythonWin IDE works.
> The crash comes when invoked from pydev under eclipse. So I can't
remove them from the equation (I mentioned the problem also on the
Pydev Sourceforge-forum, but decided to post here since it's the
interpreter crashing).
>
> It's the "send/don't send" type of error box, so I choose "don't
send" at that point since that will only send crash info to
Microsoft... no point in that! :-)
>
> It could of course be a problem in the GTK DLLs and I haven't yet had
time to test with older GTK versions. Hopefully I can try that
tomorrow.
>
> cheers,
>
> --Tim
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Behalf Of Stefan Behnel
> Sent: Wednesday, February 02, 2005 3:59 PM
> To: python-list@python.org
> Subject: Re: Crashing Python interpreter! (windows XP, python2.3.4,
2.3.5rc1, 2.4.0)
>
> Leeuw van der, Tim schrieb:
> > I'm using the following combination of software:
> > - Pydev Eclipse plugin (pydev 0.8.5)
> > - eclipse 3.0.1
> > - windows XP SP1
> > - pygtk 2.4.1
> > - GTK 2.6.1 (for windows32 native)
>
> > When trying to get a list of possible completions for the 'gtk'
import object, the python interpreter crashes. Happens with all
versions listed in the subject: python 2.3.4, 2.3.5rc1, 2.4.0.
> 

Do you have a file called drwtsn32.log anywhere on your computer?

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


Re: Generating .pyc/.pyo from a make file

2005-02-02 Thread Roland Heiber
Tim Daneliuk wrote:
I use a makefile to create distribution tarballs of freestanding Python
programs and their documentation.  I cannot seem to find the right
command line option to just generate a pyc/pyo file from the program
and then exit.  If I use 'python - -c"import myprog"' it creates
the pyo file, but myprog starts up and keeps running.
IOW, I need a batch method for generating compiled python.  I know it
exists, but I can't find it for some reason ...
TIA,
Hi,
take a look at http://docs.python.org/lib/module-compileall.html
HtH, Roland
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python's idiom for function overloads

2005-02-02 Thread Stephen Thorne
On Wed, 02 Feb 2005 14:45:35 -0800 (PST), Simo Melenius
<[EMAIL PROTECTED]> wrote:
> Philippe Fremy <[EMAIL PROTECTED]> writes:
> 
> > You can not reproduce the C++ overload idiom but you can get something
> > close with manual type testing.
> >
> >  > To in a
> >  > function do an if statement with the type() function?
> >
> > I am not aware of any other method.
> >
> > def a( arg1 ):
> >   if type(arg1) == types.IntType: return aWithInt(arg1)
> >   if type(arg1) == types.ListType: return aWithList(arg1)
> >   ...
> 
> Or:
> 
> def a_overloader (arg1):
> return my_typed_a_func_dict[type (arg1)] (arg1)
> 
> Next I'd put my hands in automating the creation of these wrappers and
> the my_typed_a_func_dict map based on my implementation written so
> far. Then I'd think of parameterizing on any arbitrary destructuring
> of arguments like def foo ((a,b), c) and also on classes to which
> instance methods are bound to. At this point, a preprocessor might be
> handy to avoid seeing all the internals after which things would
> probably start looking sick enough to either switch languages or
> thinking of the right problem first and then come up with a pythonic
> solution to _that_.

Pah.

Use a decorator. 

Code is available here:
Jack Diederich posted a good multimethod snippet here, in response to
my own clumsy effort.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/5b50153e3fb84862
http://tinyurl.com/4awat

type(arg1) == types.IntType
def multi_type(t):
  return multi(lambda x:type(x) == t)

@multi_type(types.IntType)
def foo(x):
  return someOperationOnInt(x)

@multi_type(types.FloatType)
def foo(x):
  return someOperationOnFloat(x)

Regards,
Stephen Thorne.

"Just because it is possible doesn't make a good idea *wink*", 
-Jack Diederich, Aug 2004
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a module's byte code, how?

2005-02-02 Thread Irmen de Jong
Steve Holden wrote:
I'm not sure why you think the module's code would be needed once it's 
been executed. That assigns all necessary code blocks to the functions 
defined therein, so the code, once the import has been executed, is 
garbage (from the interpreter's rather process-centric view of things).
Ah, ofcourse. Thanks for this insight.
I may have to rethink some of this...
I am presuming that this feature of Pyro won't allow a 2.3 system to 
talk to a 2.4 one, since the byte codes are incompatible.
Correct. However, when you're not using mobile code (the default),
you're fine.
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a module's byte code, how?

2005-02-02 Thread Irmen de Jong
Steve Holden wrote:
Having said which, if the module was loaded from a .pyc file then the 
bytecode is available from that - take everything but the first eight 
bytes and use marshal.loads() to turn it back into a code object:
Yup. As I explained in the other message, this is basically
what I'm doing at the moment (with a few twists; it reads the .py
file if no .pyc is available).
But I also want the bytecode of modules that don't have a .pyc file,
possibly because they have already been 'dynamically' loaded from
another bytecode string ;-)
Now, I could ofcourse store the bytecode string that I started
with *inside* the module itself, in a special attribute or so.
This just occurred to me and I think it's a possible solution.
But the bytecodes must be stored by Python itself somewhere
already... because Python is able to execute my module... right?
I want them! :-)
Note that the ugly details *might* change, and that byte codes are 
version-dependent.
I know, but this fact was not yet mentioned in the Pyro manual.
Thanks for reminding me, I'll add it.
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python's idiom for function overloads

2005-02-02 Thread Simo Melenius
Philippe Fremy <[EMAIL PROTECTED]> writes:

> You can not reproduce the C++ overload idiom but you can get something
> close with manual type testing.
> 
>  > To in a
>  > function do an if statement with the type() function?
> 
> I am not aware of any other method.
> 
> def a( arg1 ):
>   if type(arg1) == types.IntType: return aWithInt(arg1)
>   if type(arg1) == types.ListType: return aWithList(arg1)
>   ...

Or:

def a_overloader (arg1):
return my_typed_a_func_dict[type (arg1)] (arg1)

Next I'd put my hands in automating the creation of these wrappers and
the my_typed_a_func_dict map based on my implementation written so
far. Then I'd think of parameterizing on any arbitrary destructuring
of arguments like def foo ((a,b), c) and also on classes to which
instance methods are bound to. At this point, a preprocessor might be
handy to avoid seeing all the internals after which things would
probably start looking sick enough to either switch languages or
thinking of the right problem first and then come up with a pythonic
solution to _that_.


br,
S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a module's byte code, how?

2005-02-02 Thread Steve Holden
Irmen de Jong wrote:
Mark Nenadov wrote:
On Wed, 02 Feb 2005 23:03:17 +0100, Irmen de Jong wrote:

What would be the best way, if any, to obtain
the bytecode for a given loaded module?
I can get the source:
import inspect
import os
src = inspect.getsource(os)
but there is no ispect.getbytecode()  ;-)
--Irmen

The inspect API documentation says that code objects have "co_code", 
which
is a string of raw compiled bytecode.

Hope that helps!

Not very much, sorry. Because we now changed the problem into:
"how to obtain the code object from a module".
Perhaps a bit of background is in order.
For Pyro, I'm sending module byte codes across the
wire if the other side needs it (the mobile code feature).
However, this only works for modules that can be loaded
from a file on disk (because I'm now reading the .pyc file
that belongs to the module). When the receiving end in turn
calls another Pyro object, it may have to send the module's
bytecode again-- but that is no longer possible because the
module has no associated file anymore! (It is considered to
be a builtin module)
But because it is *loaded*, there must be some way to get
to the bytecodes, right?
I'm not sure why you think the module's code would be needed once it's 
been executed. That assigns all necessary code blocks to the functions 
defined therein, so the code, once the import has been executed, is 
garbage (from the interpreter's rather process-centric view of things).

The module will, however, have a __file__ attribute, which should allow 
you to retrieve the code as mentioned in my previous post - a .pyc file, 
it appears, is just a four-byte magic number, a four-byte timestamp and 
a marshalled code object.

Of course there's no guarantee that the module has been loaded from a 
compiled file. In that case your only option is to read in the source 
and compile it.

I am presuming that this feature of Pyro won't allow a 2.3 system to 
talk to a 2.4 one, since the byte codes are incompatible.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.python.org/pycon/2005/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a module's byte code, how?

2005-02-02 Thread Steve Holden
Mark Nenadov wrote:
On Wed, 02 Feb 2005 23:03:17 +0100, Irmen de Jong wrote:

What would be the best way, if any, to obtain
the bytecode for a given loaded module?
I can get the source:
import inspect
import os
src = inspect.getsource(os)
but there is no ispect.getbytecode()  ;-)
--Irmen

The inspect API documentation says that code objects have "co_code", which
is a string of raw compiled bytecode.
Hope that helps!
Unfortunately co_code is an attribute of code objects, and a module 
doesn't *have* a code object, as far as I know - when it's imported its 
bytecode is executed in the scope of the module directory, but no 
attempt is made to keep the code around thereafter: what would be the point?

Having said which, if the module was loaded from a .pyc file then the 
bytecode is available from that - take everything but the first eight 
bytes and use marshal.loads() to turn it back into a code object:

 >>> mbc = file("/lib/python2.4/re.pyc", "rb").read()[8:]
 >>> import marshal
 >>> code = marshal.loads(mbc)
 >>> code

 >>>

Note that the ugly details *might* change, and that byte codes are 
version-dependent.

tadaaa-ly y'rs  - steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.python.org/pycon/2005/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a module's byte code, how?

2005-02-02 Thread Irmen de Jong
Mark Nenadov wrote:
On Wed, 02 Feb 2005 23:03:17 +0100, Irmen de Jong wrote:

What would be the best way, if any, to obtain
the bytecode for a given loaded module?
I can get the source:
import inspect
import os
src = inspect.getsource(os)
but there is no ispect.getbytecode()  ;-)
--Irmen

The inspect API documentation says that code objects have "co_code", which
is a string of raw compiled bytecode.
Hope that helps!
Not very much, sorry. Because we now changed the problem into:
"how to obtain the code object from a module".
Perhaps a bit of background is in order.
For Pyro, I'm sending module byte codes across the
wire if the other side needs it (the mobile code feature).
However, this only works for modules that can be loaded
from a file on disk (because I'm now reading the .pyc file
that belongs to the module). When the receiving end in turn
calls another Pyro object, it may have to send the module's
bytecode again-- but that is no longer possible because the
module has no associated file anymore! (It is considered to
be a builtin module)
But because it is *loaded*, there must be some way to get
to the bytecodes, right?
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: set, dict and other structures

2005-02-02 Thread Simo Melenius
"Giovanni Bajo" <[EMAIL PROTECTED]> writes:

> Just today I was writing some code where I wanted to use sets for
> the abstraction (intersection, etc.), but also carry some values
> with them to process. So, yes, I believe that having set-like
> abstraction for dictionaries would be great. In fact, for a moment I
> wondered if dict.keys() was already of type set in 2.4, because it
> could have made sense.

Which sets you need depends on each case, so a generic set-ified
extension would be both limited and potentially confusing. For
example, a set of (key,value) tuples is the simplest and unambiguous.
On the other hand, if the values differ you really just need a set of
keys and then you can do the value lookup and collision handling
yourself using the result set as keys to both of your dictionaries.
You could subclass dict to provide aliases such as:

dict.itemset ()
dict.keyset ()
dict.valueset ()

for the following if these look overly bloated to you:

set (dict.iteritems ())
set (dict.iterkeys ())
set (dict.itervalues ())

For example:

py> for k,v in set (d1.iteritems ()) - set (d2.iteritems ()):
py>   print k, v

looks quite concise and self-explanatory to me already. A _notable_
performance gain would probably justify native set-ifying getters,
especially if there indeed were implementation-level data structures
to share.


br,
S
-- 
http://mail.python.org/mailman/listinfo/python-list


Generating .pyc/.pyo from a make file

2005-02-02 Thread Tim Daneliuk
I use a makefile to create distribution tarballs of freestanding Python
programs and their documentation.  I cannot seem to find the right
command line option to just generate a pyc/pyo file from the program
and then exit.  If I use 'python - -c"import myprog"' it creates
the pyo file, but myprog starts up and keeps running.
IOW, I need a batch method for generating compiled python.  I know it
exists, but I can't find it for some reason ...
TIA,
--

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


Re: Getting a module's byte code, how?

2005-02-02 Thread Mark Nenadov
On Wed, 02 Feb 2005 23:03:17 +0100, Irmen de Jong wrote:

> What would be the best way, if any, to obtain
> the bytecode for a given loaded module?
> 
> I can get the source:
> import inspect
> import os
> src = inspect.getsource(os)
> 
> but there is no ispect.getbytecode()  ;-)
> 
> --Irmen

The inspect API documentation says that code objects have "co_code", which
is a string of raw compiled bytecode.

Hope that helps!

- -
Mark Nenadov
Python Byte Solutions
http://www.pythonbyte.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic file operation questions

2005-02-02 Thread Steve Holden
alex wrote:
Hi,
I am a beginner with python and here is my first question:
How can I read the contents of a file using a loop or something? I open
the file with file=open(filename, 'r') and what to do then? Can I use
something like
for xxx in file:
   
Yes, indeed you can. That's by no means *all* you can do, but to iterate 
over the lines of the file that will wrok exactly. Note that the lines 
will still have their terminating "\n" on the end, which is why the 
print statement inthe following example ends in a comma (this stops 
print from putting out its own newline).

 >>> f = file("test92.py", 'r')
 >>> for l in f:
 ...   print l,
 ...
import os.path
def getHomeDir():
''' Try to find user's home directory, otherwise return current 
directory.''
'
try:
path1=os.path.expanduser("~")
except:
path1=""
try:
path2=os.environ["HOME"]
except:
path2=""
try:
path3=os.environ["USERPROFILE"]
except:
path3=""

if not os.path.exists(path1):
if not os.path.exists(path2):
if not os.path.exists(path3):
return os.getcwd()
else: return path3
else: return path2
else: return path1
print getHomeDir()
 >>>
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.python.org/pycon/2005/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Getting a module's byte code, how?

2005-02-02 Thread Irmen de Jong
What would be the best way, if any, to obtain
the bytecode for a given loaded module?
I can get the source:
import inspect
import os
src = inspect.getsource(os)
but there is no ispect.getbytecode()  ;-)
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: pythonic equivalent of Mathematica's FixedPoint function

2005-02-02 Thread Terry Reedy

"jelle" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> >You could probably write your own FixedPoint function without too much
>>difficulty, with the only tricky part being for it to know when to
> stop!
>
> It would be quite interesting to have this kind of function. But
> likely its far from trivial.

Fixed point iteration is a standard technique in numerical analysis --  
floating point calculations as approximation of real-number functions.  The 
first problem is getting an equation form that will converge  -- which has 
a stable, preferably unique fixed point.  The second is how to start --  
getting a first approximation that leads to convergence.  For stopping, one 
must choose between relative and absolute changes in the variable or 
expression (in x or y) or some combiniation thereof.

> FixedPoint seems to be one of the core functions in Mathematica, where
> many other functions are based on. Some additions such as FixedPoint
> would make functional programming in Python [easier].

It belongs in a module of floating-point equation solvers.  Perhaps one is 
already in scipy.

Terry J. Reedy



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


Re: Basic file operation questions

2005-02-02 Thread Marcel van den Dungen
alex wrote:
Hi,
I am a beginner with python and here is my first question:
How can I read the contents of a file using a loop or something? I open
the file with file=open(filename, 'r') and what to do then? Can I use
something like
for xxx in file:
   
Thanks for help
Alex
take a look at this:
http://www.devshed.com/c/a/Python/File-Management-in-Python/
HTH,
-- Marcel
--
http://mail.python.org/mailman/listinfo/python-list


errors

2005-02-02 Thread Joel Eusebio

Can someone help me on this, I don' know where the "testmptest" came from
but the mptest.py is at the /usr/local/apache2/htdocs/test directory and
this error came from apache's error_log

PythonHandler mod_python.publisher: ImportError: No module named testmptest

Thanks,

Joel

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


Re: Basic file operation questions

2005-02-02 Thread Caleb Hattingh
Hi Alex
Assuming you have a file called "data.txt":
***
f = open('data.txt','r')
lines = f.readlines()
f.close()
for line in lines:
print line
***
Will print each line of the file.
You can make a huge investment by setting 2 or 3 hours aside to go through  
the Python tutorial, which gets installed as part of the documentation.   
That tutorial can get you much of the knowledge you will ever need with  
Python.

thx
Caleb
On 2 Feb 2005 13:27:49 -0800, alex <[EMAIL PROTECTED]> wrote:
Hi,
I am a beginner with python and here is my first question:
How can I read the contents of a file using a loop or something? I open
the file with file=open(filename, 'r') and what to do then? Can I use
something like
for xxx in file:
   
Thanks for help
Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: Two classes problem

2005-02-02 Thread Caleb Hattingh
Steven, thanks for your help once again :)
so you could write the code like:
test = 'first'
class aclass:
 def __init__(self, value):
 mod = __import__(__name__)
 mod.test = value
This is sweet.  I really like this technique for manipulating module-scope  
identifiers (from within a class or function).

To the OP:
In general, this seems like a bad organization strategy for your code.  
What is your actual use case?
Agreed.  It is an interesting intellectual exercise, but there is surely a  
better way of controlling access to 'test' in the OP's post.

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


Re: Generating modul classes with eval

2005-02-02 Thread Jeremy Bowers
On Wed, 02 Feb 2005 16:20:41 -0500, Jeremy Bowers wrote:
> That said, "__main__" indicates you ran it in the interactive shell.

Or ran it directly on the command line. Duh. I thought that clause really
loudly, but I guess I never actually typed it.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >