subpackage import problem

2005-08-21 Thread Eric Huss
I'm having a problem with packages within packages.  Here's an example:

foo/
foo/__init__.py: empty file
foo/sub/__init__.py:
from foo.sub.B import B
foo/sub/A.py:
class A:
pass
foo/sub/B.py
import foo.sub.A
class B(foo.sub.A):
pass

Trying to "import foo.sub" will result in this error:

>>> import foo.sub
Traceback (most recent call last):
  File "", line 1, in ?
  File "foo/sub/__init__.py", line 1, in ?
from foo.sub.B import B
  File "foo/sub/B.py", line 3, in ?
class B(foo.sub.A):
AttributeError: 'module' object has no attribute 'sub'

This can be fixed using a relative import in B.py, but I don't feel
comfortable with relative package imports (unintentional shadowing of
modules you want to use in the future, and the symantics might change in
the future due to PEP 328).

Does anyone have any suggestions?

The situation this comes up is:
- Have package foo with module bar.
- Module bar has a large number of classes.
- I want to break bar up into multiple files because it is getting too
large.
- In order to keep these classes together, I create a subpackage with a
separate file for each class.
- I import these files in the subpackage __init__.py so I don't have to
change any other code and so I don't have
foo.bar.flashlight.flashlight() lines where the word
"flashlight" is repeated.

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


passing arguments from scale widget to function

2005-08-21 Thread m7b52000
Some time ago I wrote a little program in Tcl/Tk that took the values 
from 3 sliders and performed a calculation using these values. The 
calculation was of course automatically repeated each time a slider was 
moved.

It is proving most difficult in Python. How do I pass the .get() values 
to my calculating function? Do I use the command option for each 
slider? e.g command = Calc(a.get()). Obviously not cos it doesn't work.

I am not a real programmer and do not wish to get involved in classes 
and objects
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Martin v. Löwis
Giovanni Bajo wrote:
> I don't think I fully understand the reason why additional .pyd modules were
> built into the .dll. OTOH, this does not help anyone, since:

The reason is simple: a single DLL is easier to maintain. You only need
to add the new files to the VC project, edit config.c, and be done. No
new project to create for N different configurations, no messing with
the MSI builder.

In addition, having everything in a single DLL speeds up Python startup
a little, since less file searching is necessary.

> Can we at least undo this unfortunate move in time for 2.5? I would be 
> grateful
> if *at least* the CJK codecs (which are like 1Mb big) are splitted out of
> python25.dll. IMHO, I would prefer having *more* granularity, rather than
> *less*.

If somebody would formulate a policy (i.e. conditions under which
modules go into python2x.dll, vs. going into separate files), I'm
willing to implement it. This policy should best be formulated in
a PEP.

The policy should be flexible wrt. to future changes. I.e. it should
*not* say "do everything as in Python 2.3", because this means I
would have to rip off the modules added after 2.3 entirely (i.e.
not ship them at all). Instead, the policy should give clear guidance
even for modules that are not yet developed.

It should be a PEP, so that people can comment. For example,
I think I would be -1 on a policy "make python2x.dll as minimal
as possible, containing only modules that are absolutely
needed for startup".

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


Re: subpackage import problem

2005-08-21 Thread Robert Kern
Eric Huss wrote:
> I'm having a problem with packages within packages.  Here's an example:
> 
> foo/
> foo/__init__.py: empty file
> foo/sub/__init__.py:
>   from foo.sub.B import B
> foo/sub/A.py:
>   class A:
>   pass
> foo/sub/B.py
>   import foo.sub.A
>   class B(foo.sub.A):
>   pass
> 
> Trying to "import foo.sub" will result in this error:
> 
import foo.sub
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "foo/sub/__init__.py", line 1, in ?
> from foo.sub.B import B
>   File "foo/sub/B.py", line 3, in ?
> class B(foo.sub.A):
> AttributeError: 'module' object has no attribute 'sub'

I imagine it has something to do with the timing of imports. Python is
executing the contents of foo/sub/B.py while it's trying to create the
module object foo.sub. You can get around it, though.

Try this in foo/sub/B.py :

  from foo.sub.A import A
  class B(A):
  pass

That works for me (Python 2.4.1, OS X).

-- 
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: >time.strftime %T missing in 2.3

2005-08-21 Thread Jorgen Grahn
On Fri, 05 Aug 2005 01:02:48 -0500, Andy Leszczynski 
 wrote:
> Robert Kern wrote:
>> Andy Leszczynski wrote:
>> 
>>> Python 2.2/Unix
>>>
>>>  >>time.strftime("%T")
>>> '22:12:15'
>>>  >>time.strftime("%X")
>>> '22:12:17'
>>>
>>> Python 2.3/Windows
>>>
>>>  >>time.strftime("%X")
>>> '22:12:47'
>>>  >> time.strftime("%T")
>>> ''
>> 
>> 
>>  From http://docs.python.org/lib/node252.html
>> 
>> """The full set of format codes supported varies across platforms, 
>> because Python calls the platform C library's strftime() function, and 
>> platform variations are common."""
>> 
>> So I suggest that it's a platform issue, not a Python version issue. FWIW:
>> 
>> Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
>> [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> import time
>>  >>> time.strftime("%T")
>> '22:50:49'
>>  >>> time.strftime("%X")
>> '22:50:59'
>> 
>
> I accept that, but still pain. Took me a while to filter out the problem 
> in the code running on the Unix and not on M$.

I can imagine ...

By the way, you should probably /not/ change %T to %X.

%T (standardized in the Singe Unix Specification) is the same thing as ANSI
C %H:%M:%S which should be usable everywhere. %X on the other hand is "The
preferred time representation for the current locale without the date".
Not the same thing at all, for some users.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Giovanni Bajo
Martin v. Löwis wrote:

>> I don't think I fully understand the reason why additional .pyd
>> modules were built into the .dll. OTOH, this does not help anyone,
>> since:
>
> The reason is simple: a single DLL is easier to maintain. You only
> need
> to add the new files to the VC project, edit config.c, and be done. No
> new project to create for N different configurations, no messing with
> the MSI builder.

FWIW, this just highlights how ineffecient your build system is. Everything you
currently do by hand could be automated, including MSI generation. Also, you
describe the Windows procedure, which I suppose it does not take into account
what needs to be done for other OS. But I'm sure that revamping the Python
building system is not a piece of cake.

I'll take the point though: it's easier to maintain for developers, and most
Python users don't care.

> In addition, having everything in a single DLL speeds up Python
> startup a little, since less file searching is necessary.

I highly doubt this can be noticed in an actual benchmark, but I could be
wrong. I can produce numbers though, if this can help people decide.

>> Can we at least undo this unfortunate move in time for 2.5? I would
>> be grateful if *at least* the CJK codecs (which are like 1Mb big)
>> are splitted out of python25.dll. IMHO, I would prefer having *more*
>> granularity, rather than *less*.
>
> If somebody would formulate a policy (i.e. conditions under which
> modules go into python2x.dll, vs. going into separate files), I'm
> willing to implement it. This policy should best be formulated in
> a PEP.
>
> The policy should be flexible wrt. to future changes. I.e. it should
> *not* say "do everything as in Python 2.3", because this means I
> would have to rip off the modules added after 2.3 entirely (i.e.
> not ship them at all). Instead, the policy should give clear guidance
> even for modules that are not yet developed.
>
> It should be a PEP, so that people can comment. For example,
> I think I would be -1 on a policy "make python2x.dll as minimal
> as possible, containing only modules that are absolutely
> needed for startup".

I'm willing to write up such a PEP, but it's hard to devise an universal
policy. Basically, the only element we can play with is the size of the
resulting binary for the module. Would you like a policy like "split out every
module whose binary on Windows is > X kbytes?".

My personal preference would go to something "make python2x.dll include only
the modules which are really core, like sys and os". This would also provide
guidance to future modules, as they would simply go in external modules (I
don't think really core stuff is being added right now).

At this point, my main goal is getting CJK out of the DLL, so everything that
lets me achieve this goal is good for me.

Thanks,
-- 
Giovanni Bajo


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

Re: Bug in slice type

2005-08-21 Thread Kay Schluehr
Steven Bethard wrote:

> "The slice of s from i to j with step k is defined as the sequence of
> items with index x = i + n*k such that 0 <= n < (j-i)/k."
>
> This seems to contradict list behavior though.
>  range(10)[9:-1:-2] == []

No, both is correct. But we don't have to interpret the second slice
argument m as the limit j of the above definition. For positive values
of m the identity
m==j holds. For negative values of m we have j = max(0,i+m). This is
consistent with the convenient negative indexing:

>>> range(9)[-1] == range(9)[8]

If we remember how -1 is interpreted as an index not as some limit the
behaviour makes perfect sense.

Kay

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


Re: __del__ pattern?

2005-08-21 Thread Jorgen Grahn
On Tue, 16 Aug 2005 08:03:58 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
> Tom Anderson wrote:
>> On Mon, 15 Aug 2005, Peter Hansen wrote:
>>> Using '' instead of 'localhost' means bind to *all* interfaces, not 
>>> just the loopback one.
>> 
>> Doesn't '' mean 'bind to the *default* interface'?
>
> What does "default" mean, and is that definition in conflict with what I 
> said?
>
> The docs say it means INADDR_ANY.  They don't say what that means, so 
> you'd have to read up on the C socket calls to learn more.
>
> Or some helpful soul will clarify for the class... :-)

INADDR_ANY means "every network interface you can find". This includes the
local loopback and all physical and logical network interfaces.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposed PEP: New style indexing, was Re: Bug in slice type

2005-08-21 Thread Kay Schluehr
Bryan Olson wrote:
> Steven Bethard wrote:
>  > Well, I couldn't find where the general semantics of a negative stride
>  > index are defined, but for sequences at least[1]:
>  >
>  > "The slice of s from i to j with step k is defined as the sequence of
>  > items with index x = i + n*k such that 0 <= n < (j-i)/k."
>  >
>  > This seems to contradict list behavior though. [...]
>
> The conclusion is inescapable: Python's handling of negative
> subscripts is a wart. Indexing from the high end is too useful
> to give up, but it should be specified by the slicing/indexing
> operation, not by the value of the index expression.

It is a Python gotcha, but the identity X[-1] == X[len(X)-1] holds and
is very usefull IMO. If you want to slice to the bottom, take 0 as
bottom value. The docs have to be extended in this respect.

Kay

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


Re: Binary Trees in Python

2005-08-21 Thread Jorgen Grahn
On Sat, 20 Aug 2005 15:19:55 -0400, Roy Smith <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
>  [diegueus9] Diego Andrés Sanabria <[EMAIL PROTECTED]> wrote:
>
>> Hello!!!
>> 
>> I want know if python have binary trees and more?
>
> Python does not come with a tree data structure.  The basic data structures 
> in Python are lists, tuples, and dicts (hash tables).
>
> People who are used to C++'s STL often feel short-changed because there's 
> not 47 other flavors of container, but it turns out that the three Python 
> gives you are pretty useful.  Many people never find a need to look beyond 
> them.

Uh, the STL has seven flavors:
- vector
- deque
- list
- set
- map
- multimap
- multiset
so that's not too bad for a static language. Each of them
is vital for some purpose, but vector and map are by far the
most commonly used.

Neither C++ nor Python has tree structures in their standard libraries. I
assume that's because there is no single interface that is proven to suit
everybody's needs.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback Questions

2005-08-21 Thread ncf
Thanks man, I'll definately take a look into this and hopefully port it
over and publish it.

Have a GREAT day

-Wes

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


Re: Module Name Conflicts

2005-08-21 Thread ncf
Heh, so long as it works. Sorry for the delay, I've been away for a bit
;P Hope it's all owrking out
-Wes

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


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Michael Hoffman
Giovanni Bajo wrote:
> 
> FWIW, this just highlights how ineffecient your build system is. Everything 
> you
> currently do by hand could be automated, including MSI generation.

I'm sure Martin would be happy to consider a patch to make the build 
system more efficient. :)

> I'm willing to write up such a PEP, but it's hard to devise an universal
> policy.

This is the reason that a PEP is needed before there are changes.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


RE vs. SRE

2005-08-21 Thread Yoav
What is the difference between the two? Which on is better to use and why?

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


Re: RE vs. SRE

2005-08-21 Thread Michael Hoffman
Yoav wrote:
> What is the difference between the two? Which on is better to use and why?

In Python 2.4, this is what's in re.py:

'''
"""Minimal "re" compatibility wrapper.  See "sre" for documentation."""

engine = "sre" # Some apps might use this undocumented variable

from sre import *
from sre import __all__
'''

If you're using CPython, they're the same thing now. Use re, because sre 
is really an undocumented implementation detail of re.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposed PEP: New style indexing, was Re: Bug in slice type

2005-08-21 Thread Paul Rubin
Bryan Olson <[EMAIL PROTECTED]> writes:
>  seq[3 : -4]
> 
> we write:
> 
>  seq[3 ; $ - 4]

+1

> When square-brackets appear within other square-brackets, the
> inner-most bracket-pair determines which sequence '$' describes.
> (Perhaps '$$' should be the length of the next containing
> bracket pair, and '$$$' the next-out and...?)

Not sure.  $1, $2, etc. might be better, or $ like in regexps, etc.

> So really seq[-2] should be out-of-bounds. Alas, that would
> break way too much code. For now, simple indexing with a
> negative subscript (and no '$') should continue to index from
> the high end, as a deprecated feature. The presence of '$'
> always indicates new-style slicing, so a programmer who needs a
> negative index to trigger a range error can write:
> 
>  seq[($ - $) + index]

+1

> Commas are already in use to form tuples, and we let them do
> just that. A slice is a subscript that is a tuple (or perhaps we
> should allow any sequence). We could just as well write:
> 
>  index_tuple = (start, stop, step)
>  sequence[index_tuple]

Hmm, tuples are hashable and are already valid indices to mapping
objects like dictionaries.  Having slices means an object can
implement both the mapping and sequence interfaces.  Whether that's
worth caring about, I don't know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: while c = f.read(1)

2005-08-21 Thread Reinhold Birkenfeld
John Machin wrote:

> ... AND it's about time that list is updated to include False explicitly 
>   -- save nitpicking arguments about whether False is covered by 
> "numeric zero of all types" :-)

Done.

>> If I try:
>> 
>>   f = open("blah.txt", "r")
>>   while (c = f.read(1)) != '':
>>   # ... work on c
>> 
>> I get a syntax error also. :(
>> 
>> Is this related to Python's expression vs. statement syntactic
>> separation? How can I be write this code more nicely?
>> 
>> Thanks
>> 
> 
> How about
> for c in f.read():
> ?
> Note that this reads the whole file into memory (changing \r\n to \n on 
> Windows) ... performance-wise for large files you've spent some memory 
> but clawed back the rather large CPU time spent doing f.read(1) once per 
> character. The "more nicely" factor improves outasight, IMHO.
> 
> Mild curiosity: what are you doing processing one character at a time 
> that can't be done with a built-in function, a standard module, or a 
> 3rd-party module?

Don't forget

for line in f:
for c in line:
# do stuff

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


Re: while c = f.read(1)

2005-08-21 Thread Paul Rubin
Reinhold Birkenfeld <[EMAIL PROTECTED]> writes:
> Don't forget
> 
> for line in f:
> for c in line:
> # do stuff

As mentioned before, that's careless programming, since it can read
the whole file into memory if the file contains no newlines.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Light Revisted?

2005-08-21 Thread Max
Steve M wrote:
> I agree with you in part and disagree in part.
> 
> I don't see the point to making the distribution any smaller. 10MB for
> the installer from python.org, 16MB for ActiveState .exe installer. How
> is 5MB "lightweight" while 10MB isn't? The Windows XP version of Java
> at java.com is 16+ MB, and the .NET framework is, well, I don't know
> how big, but I doubt it's much less than 10MB.
> 

AFAIR, it's closer to 50MB.

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


Embedding threaded Python in C

2005-08-21 Thread Richard
I've tried embedding Python in a C app so that Threading is done in the
Python side.

In the simple example below, unless I uncomment the ALLOW_THREADS macros,
the Python thread does nothing until the C for-loop finishes. 

My real-world example is a large C/Motif application - apart from scattering
the ALLOW_THREADS macros everywhere (and what do you do while the Motif
event loop is idling?), is there a better way to get the Python threads to
run?

I'm using Python-2.4 on Linux.

--
/* app.c */

#include 
#include 

void run_worker(void)
{
  PyObject *pmod;
  PyObject *pfunc;
  PyObject *pargs;
  PyObject *pres;

  pmod = PyImport_ImportModule("Manager");
  pfunc = PyObject_GetAttrString(pmod, "run");
  pargs = Py_BuildValue("()");
  pres = PyEval_CallObject(pfunc, pargs);
  Py_DECREF(pres);
  Py_DECREF(pfunc);
  Py_DECREF(pargs);
  Py_DECREF(pmod);
} 


int main(int argc, char **argv) 
{
  int  i;

  Py_Initialize();
  PyEval_InitThreads(); 
  PySys_SetArgv(argc, argv);

  run_worker();
  
  for (i=0; i<8; i++)
  {
printf("%d main()\n", i); 

/*Py_BEGIN_ALLOW_THREADS*/
sleep(1);
/*Py_END_ALLOW_THREADS*/
  }
  
  Py_Finalize();
}

--
# Manager.py
import time
from threading import Thread, currentThread

class Worker(Thread):

def run(self):
for i in range(5):
print "Worker.run() %d [%s]" % (i, currentThread().getName())
time.sleep(1)

def run():
w = Worker()
w.start()

--


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


Re: [newbie]search string in tuples

2005-08-21 Thread Viper Jack
Thanks to all for the help.

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


Re: while c = f.read(1)

2005-08-21 Thread John Machin
Reinhold Birkenfeld wrote:
> John Machin wrote:
> 
> 
>>... AND it's about time that list is updated to include False explicitly 
>>  -- save nitpicking arguments about whether False is covered by 
>>"numeric zero of all types" :-)
> 
> 
> Done.

Thanks -- those of us who actually read manuals salute you.

> 
>w about
>>for c in f.read():
> [snip]

> Don't forget
> 
> for line in f:
> for c in line:
> # do stuff
> 

OK. I'll pay that one.


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


Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out)

2005-08-21 Thread Giovanni Bajo
Michael Hoffman wrote:

>> FWIW, this just highlights how ineffecient your build system is.
>> Everything you currently do by hand could be automated, including
>> MSI generation.
>
> I'm sure Martin would be happy to consider a patch to make the build
> system more efficient. :)


Out of curiosity, was this ever discussed among Python developers? Would
something like scons qualify for this? OTOH, scons opens nasty
self-bootstrapping issues (being written itself in Python).

Before considering a patch (or even a PEP) for this, the basic requirements
should be made clear. I know portability among several UNIX flavours is one,
for instance. What are the others?
-- 
Giovanni Bajo


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


Automatic documentation options

2005-08-21 Thread Terry Hancock
I've been trying to use "happydoc" to document a source
tree that I'm working on.  It does pretty much what I want,
except:

Version 2.1:
Creates a weird directory structure for the HTML pages
it generates -- they embed the full path to the working
copy of the sources, which, beyond just being ugly,
would be pretty annoying for  a collaborative project
(each collaborator's copy would produce documentation
in separate directories, probably resulting in duplication).

Version 3-alpha:
Solves that problem, but very incomplete compared to
2.1, and apparently abandoned in 2003 (maybe because
of pydoc?).  Various options aren't available, and, for
example it forces me to use "README.txt" instead of
just "README" if I want it to collect that information.

Neither version documents class attributes, which is somewhat
annoying, because they are part of my interface. But I can fix
this with the docstrings, of course.

Now I've considered using pydoc, but it seems to be very weak
in this kind of application (generating a tree of static HTML pages
to provide library documentation). On the plus side, I find its
overall layout prettier, and it does include attributes.

But it also includes a lot of garbage (such as symbols loaded 
by "from pygame.locals import *"), doesn't apparently understand
the structured text docstrings, and finally, it chokes on some
modules because it can't find all of their imports (because I'm
trying to run it from the documentation directory).  I don't
think happydoc has this problem, because it doesn't 
attempt to import the module in order to generate documentation,
so it only documents what is actually defined in that module. It
also reads comment lines, which can be a plus.

Unlike happydoc, pydoc doesn't seem to have many command
line options for changing any of this behavior, so if you don't like
it, you seem to be stuck.

So while I use pydoc quite a lot for on-the-fly documentation,
I'm not so happy with it as a docset generator (or maybe I just
don't know how to get it to do what I want?).

What I really want to do is to have a set of (static) HTML documentation
pages that I write, that are deep-linked into an automatically
generated set of library documentation.

Any suggestions on getting pydoc, happydoc, or yet another
documentation generator to do this, would be greatly appreciated.

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Reading my own stdout

2005-08-21 Thread Miki Tebeka
Hello All,

I have a windows app (wxPython) that uses a C DLL (via SWIG).
The C DLL emits a lot of information using "printf" and I'd like to catch
this output and show it in the GUI.

How can I do this? (OS is winXP).

(The only option I see now is to do a "-Dprintf=my_log_function"
which I don't like.)

Thanks.
--

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


pgptbvCZxGky9.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

import __main__ where can i find a module called "__main__.py"?

2005-08-21 Thread wen
and, in which case, the following case will happen:
if __name__!='__main__':
do_sth()

any help would be appreciated.


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


Re: Binary Trees in Python

2005-08-21 Thread François Pinard
[Jorgen Grahn]

> Neither C++ nor Python has tree structures in their standard
> libraries.  I assume that's because there is no single interface that
> is proven to suit everybody's needs.

It is already easy writing "tree constants" using recursive tuples or
lists.  To process simple trees in Python, I usually subclass some
Node type from list, and write the traversal methods that suit the
application.  The sub-classing already allow for indexing sub-nodes by
"self[index]", and iterating over all by "for subnode in self:", etc.
In my experience, it all goes pretty easily, while staying simple.

However, things related to balancing, finding paths between nodes, or
searching for patterns, etc. may require more work.  There are surely
a flurry of tree algorithms out there.  What are the actual needs you
have, and would want to see covered by a library?

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


Re: Reading my own stdout

2005-08-21 Thread Robert Kern
Miki Tebeka wrote:
> Hello All,
> 
> I have a windows app (wxPython) that uses a C DLL (via SWIG).
> The C DLL emits a lot of information using "printf" and I'd like to catch
> this output and show it in the GUI.
> 
> How can I do this? (OS is winXP).
> 
> (The only option I see now is to do a "-Dprintf=my_log_function"
> which I don't like.)

Look at the py.io module.

http://codespeak.net/py/current/doc/home.html
http://codespeak.net/svn/py/dist/

-- 
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: last line chopped from input file

2005-08-21 Thread phil hunt
On 20 Aug 2005 22:53:42 -0700, Eric Lavigne <[EMAIL PROTECTED]> wrote:
>Here is a shell command (MS-DOS):
>  debug\curve-fit output.txt
>
>And here is a Python script that *should* do the same thing (and almost
>does):
>
>  import os
>
>  inputfilename = 'input.txt'
>  outputfilename = 'output.txt'
>
>  inputfile = open(inputfilename,'r')
>  outputfile = open(outputfilename,'w')
>  inputstream,outputstream = os.popen2("debug\\curve-fit")
>  inputstream.write(inputfile.read())
>  inputfile.close()
>  inputstream.close()
>  outputfile.write(outputstream.read())
>  outputstream.close()
>  outputfile.close()
>
>On a side note, I am very new to Python so I would appreciate any
>comments on style, or suggestions for simpler ways to write something
>like this (seems overkill for matching one line of shell), or more
>portable ways to write it (requires '\\' on windows but '/' on linux).

A shorter python program would be:

   os.command("debug\\curve-fit output.txt")

If you don't like the doubled \\, you could write:

   os.command(r"debug\curve-fit output.txt")

For portability regarding \\ versus /, look at the os.path module.

-- 
Email: zen19725 at zen dot co dot uk


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


Re: import __main__ where can i find a module called "__main__.py"?

2005-08-21 Thread gene tani
http://www.python.org/doc/faq/programming.html#how-do-i-find-the-current-module-name

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


Re: import __main__ where can i find a module called "__main__.py"?

2005-08-21 Thread John Machin
wen wrote:
> and, in which case, the following case will happen:
> if __name__!='__main__':
> do_sth()
> 
> any help would be appreciated.
> 
> 
Sorry, but your question is rather difficult to interpret.

For a start, you don't need/want to import __main__.

On import, __name__ is set to the name of the module. When a source file 
is run as a script, there is no module, so  __name__ is set to the dummy 
value "__main__". The module __main__ doesn't exist, and its source file 
__main__.py doesn't exist either (this side of the looking-glass).

Below is a minimal example of the behaviour of __name__.

C:\junk>type wenmain.py
print "__name__:", __name__

C:\junk>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import wenmain
__name__: wenmain
 >>> ^Z

C:\junk>python wenmain.py
__name__: __main__

Hope this helps,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Martin v. Löwis
Giovanni Bajo wrote:
> FWIW, this just highlights how ineffecient your build system is. Everything 
> you
> currently do by hand could be automated, including MSI generation. Also, you
> describe the Windows procedure, which I suppose it does not take into account
> what needs to be done for other OS. But I'm sure that revamping the Python
> building system is not a piece of cake.

You are wrong. It is not true that everything I do by hand could be
automated. Atleast after automation, I still would have to do things
by hand, namely invoke the automation.

You probably haven't looked at the MSI generation at all: it *is*
automatic. However, everytime something changes in the structure,
the code generating the MSI must be adjusted to the new structure.

> I'll take the point though: it's easier to maintain for developers, and most
> Python users don't care.

See, this I find surprising. If there really is such a big need for
python24.dll being split in many more modules - why doesn't anybody
just do this, and offers it as a separate installation for use
with py2exe?

The fact that this hasn't happened indicates that users don't need
it badly enough. I personally rarely need to create a standalone
Python application, but when I did, I just used freeze, and static
linking. That way, I got a single binary, with no magic packaging,
and a minimal one, too.

>>In addition, having everything in a single DLL speeds up Python
>>startup a little, since less file searching is necessary.
> 
> I highly doubt this can be noticed in an actual benchmark, but I could be
> wrong. I can produce numbers though, if this can help people decide.

No, this is a minor issue. If you do write a PEP, and you find it
relatively easy to compare the maximum modularization to the minimal
one, it would be useful to underline your point, of course.

> I'm willing to write up such a PEP, but it's hard to devise an universal
> policy. 

Indeed. For Python 2.4, I made up a policy for myself: everything that
does not depend on a separate (non-system) library goes into
pythonxy.dll. That way, everybody will be able to compile Python
from sources without downloading anything else, yet it causes minimum
maintenance overhead. That's how the current python24.dll came about.

> Basically, the only element we can play with is the size of the
> resulting binary for the module. Would you like a policy like "split out every
> module whose binary on Windows is > X kbytes?".

It's less important what I like - I think I would ask for a poll on
the proposed PEP, and I would be -1 on anything that means more work
for contributors. But that would be only one voice, and, if a majority
of the Windows Python users preferred your policy, it would be
implemented (of course, somebody contributing the resulting project
files or some automation for them would also help).

> My personal preference would go to something "make python2x.dll include only
> the modules which are really core, like sys and os". This would also provide
> guidance to future modules, as they would simply go in external modules (I
> don't think really core stuff is being added right now).

Ok, then write that into the PEP. You would have to provide a definition
for "core", e.g. "everything that is needed for startup".

As a guideline, the Unix build process currently includes only the
following modules by default:

- marshal, imp, __main__, __builtin__, sys, exceptions: Modules
  living in Python/*.c
- gc, signal: invoked directly from the interpreter
- thread: not sure
- posix, errno, _sre, _codecs, so that setup.py can run
- zipimport, to avoid bootstrapping problems for importing python24.zip
- _symtable, because setup.py cannot get the dependencies right
- xxsubtype, for an undocumented reason I forgot

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


Re: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out)

2005-08-21 Thread Martin v. Löwis
Giovanni Bajo wrote:
>>I'm sure Martin would be happy to consider a patch to make the build
>>system more efficient. :)
> 
> Out of curiosity, was this ever discussed among Python developers? Would
> something like scons qualify for this? OTOH, scons opens nasty
> self-bootstrapping issues (being written itself in Python).

No. The Windows build system must be integrated with Visual Studio.
(Perhaps this is rather, "dunno: is it integrated with VS.NET 2003?")

When developing on Windows, you really want all the support you can
get from VS, e.g. when debugging, performing name completion, etc.
To me, this makes it likely that only VS project files will work.

> Before considering a patch (or even a PEP) for this, the basic requirements
> should be made clear. I know portability among several UNIX flavours is one,
> for instance. What are the others?

Clearly, the starting requirement would be that you look at the build
process *at all*. The Windows build process and the Unix build process
are completely different. Portability is desirable only for the Unix
build process; however, you might find that it already meets your needs
quite well.

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


Re: Automatic documentation options

2005-08-21 Thread Terry Hancock
On Sunday 21 August 2005 07:37 am, Terry Hancock wrote:
> I've been trying to use "happydoc" to document a source
> tree that I'm working on. 
> [...]
> Any suggestions on getting pydoc, happydoc, or yet another
> documentation generator to do this, would be greatly appreciated.

Ah, well, it looks like epydoc will do what I need
http://epydoc.sourceforge.net

The module import error I mentioned was actually a real bug
in my sources, when fixed, pydoc (and epydoc) don't seem to
have a problem with them. Doesn't address the general issue,
but it works fine for this project.

The only remaining problem is that epydoc doesn't seem to 
understand Structured Text, despite having an option for
it ('--docformat="restructuredtext"').  Good enough though.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out)

2005-08-21 Thread Giovanni Bajo
Martin v. Löwis wrote:

>> Out of curiosity, was this ever discussed among Python developers?
>> Would something like scons qualify for this? OTOH, scons opens nasty
>> self-bootstrapping issues (being written itself in Python).
>
> No. The Windows build system must be integrated with Visual Studio.
> (Perhaps this is rather, "dunno: is it integrated with VS.NET 2003?")
> When developing on Windows, you really want all the support you can
> get from VS, e.g. when debugging, performing name completion, etc.
> To me, this makes it likely that only VS project files will work.

You seem to ignore the fact that scons can easily generate VS.NET projects. And
it does that by parsing the same file it could use to build the project
directly (by invoking your Visual Studio); and that very same file would be the
same under both Windows and UNIX.

And even if we disabled this feature and build the project directly from
command line, you could still edit your files with the Visual Studio
environment and debug them in there (since you are still compiling them with
Visual C, it's just scons invoking the compiler). You could even setup the
environment so that when you press CTRL+SHIFT+B (or F7, if you have the old
keybinding), it invokes scons and builds the project.

So, if the requirement is "integration with Visual Studio", that is not an
issue to switching to a different build process.

>> Before considering a patch (or even a PEP) for this, the basic
>> requirements should be made clear. I know portability among several
>> UNIX flavours is one, for instance. What are the others?
>
> Clearly, the starting requirement would be that you look at the build
> process *at all*.

I compiled Python several times under Windows (both 2.2.x and 2.3.x) using
Visual Studio 6, and one time under Linux. But I never investigated into it in
detail.

> The Windows build process and the Unix build process
> are completely different.

But there is no technical reason why it has to be so. I work on several
portable projects, and they use the same build process under both Windows and
Unix, while retaining full Visual Studio integration (I myself am a Visual
Studio user).

> Portability is desirable only for the Unix
> build process; however, you might find that it already meets your
> needs quite well.

Well, you came up with a maintenance problem: you told me that building more
external modules needs more effort. In a well-configured and fully-automated
build system, when you add a file you have to write its name only one time in a
project description file; if you want to build a dynamic library, you have to
add a single line. This would take care of both Windows and UNIX, both
compilation, packaging and installation.
-- 
Giovanni Bajo


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

network programming

2005-08-21 Thread John Walton
Hello, everyone.  I just began school, and they
already assigned us science fair.  Since I'm in 8th
grade, I get to do demonstrations for our projects. 
I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger
program.  I only have a few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

  So if any of you know of a good Python Networking
Tutorial or a website with lots of information on
networks and networking, please reply.  Thanks!

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?)

2005-08-21 Thread [EMAIL PROTECTED]
Python lets me access module level variables from *anywhere*.  All I
have
to do is add module name in front.

e.g.

mymodule.myvariable

Is this considered a 'global'?  Or, does a 'global variable' have to be
accessible anywhere *without* a namespace in front?

(I'm not sure what proper academic definition of 'global variable' is.)

Thanks!

Chris

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


Best way to 'touch' a file?

2005-08-21 Thread Kenneth McDonald
I could've sworn python had such a command, but now I can't find it...

I'm looking for an easy way to perform a UNIX-style "touch", to  
update the modification time of a file without actually modifying it.  
I could do something (I imagine) like opening the file for appending  
and then immediately closing it, but that doesn't seem like a good  
idea--what if the file is already open for reading or writing? Anyone  
know of a nice, elegant solution?

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


Re: Best way to 'touch' a file?

2005-08-21 Thread jepler
On Unix, 'touch' is basically a wrapper around utime(2), available in python as
os.utime.

Jeff


pgpZb4MBupMDt.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: last line chopped from input file

2005-08-21 Thread Eric Lavigne
>A shorter python program would be:
>
>   os.command("debug\\curve-fit output.txt")

I tried this program:
  import os
  os.command("debug\\curve-fit output.txt")

My error message is:
  AttributeError: 'module' object has no attribute 'command'

I also could not find os.command in the help files. My Python version
is 2.4 (latest is 2.4.1, just a bug-fix release).

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


X-Platform method of remote execution of Windows programs

2005-08-21 Thread utabintarbo
How can I execute a program in windows on a remote pc, from both linux
and windows, using python (more-or-less) alone?

Any help would be GREATLY appreciated!

Bob

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


Re: last line chopped from input file

2005-08-21 Thread Alan Kemp
On Sun, 21 Aug 2005 13:41:14 -0400, Eric Lavigne <[EMAIL PROTECTED]>  
wrote:

>> A shorter python program would be:
>>
>>   os.command("debug\\curve-fit output.txt")
>
> I tried this program:
>   import os
>   os.command("debug\\curve-fit output.txt")
>
> My error message is:
>   AttributeError: 'module' object has no attribute 'command'
>
> I also could not find os.command in the help files. My Python version
> is 2.4 (latest is 2.4.1, just a bug-fix release).
>

I imagine thats was a typo for:

>>> os.system("debug\\curve-fit output.txt")

Alan


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


Re: tkinter text widget question

2005-08-21 Thread William Gill


rafi wrote:
> William Gill wrote:
> 
>> The tkinter text widget uses indexes to identify row:column offsets 
>> within the text, but it seems counter intuitive to have to convert row 
>> and column integers to a string like "0.1'.  It's great that index can 
>> take a string, but what about looping through rows and columns?  Am I 
>> missing a way to use integers directly, or should I create a class 
>> that takes the two integers and returns them formatted as the proper 
>> string?
> 
> 
> tkinter relies on tk that is for tcl at first, and in tcl every thing is 
> a string (more or less).
> 
> "%s.%s" % (row, column)

Simple enough.  (sometimes I can't see the simplest things, without 
complicating them)

Thanks,

Bill
> 
> should answer your problem easily
> 
> my 2 cents
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Ron Adam
Martin v. Löwis wrote:

>>Can we at least undo this unfortunate move in time for 2.5? I would be 
>>grateful
>>if *at least* the CJK codecs (which are like 1Mb big) are splitted out of
>>python25.dll. IMHO, I would prefer having *more* granularity, rather than
>>*less*.
> 
> If somebody would formulate a policy (i.e. conditions under which
> modules go into python2x.dll, vs. going into separate files), I'm
> willing to implement it. This policy should best be formulated in
> a PEP.

+1  Yes, I think this needs to be addressed.

> The policy should be flexible wrt. to future changes. I.e. it should
> *not* say "do everything as in Python 2.3", because this means I
> would have to rip off the modules added after 2.3 entirely (i.e.
> not ship them at all). Instead, the policy should give clear guidance
> even for modules that are not yet developed.

Agree.

> It should be a PEP, so that people can comment. For example,
> I think I would be -1 on a policy "make python2x.dll as minimal
> as possible, containing only modules that are absolutely
> needed for startup".

Also agree,  Both the minimal and maximal dll size possible are ideals 
that are not the most optimal choices.

I would put the starting minimum boundary as:

1. "The minimum required to start the python interpreter with no 
additional required files."

Currently python 2.4 (on windows) does not yet meet that guideline, so 
it seems some modules still need to be added while other modules, (I 
haven't checked which), are probably not needed to meet that guideline.

This could be extended to:

2. "The minimum required to run an agreed upon set of simple Python 
programs."

I expect there may be a lot of differing opinions on just what those 
minimum Python programs should be.  But that is where the PEP process 
comes in.


Regards,
Ron


> Regards,
> Martin

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


tkinter text widget question

2005-08-21 Thread William Gill
The tkinter text widget uses indexes to identify row:column offsets 
within the text, but it seems counter intuitive to have to convert row 
and column integers to a string like "0.1'.  It's great that index can 
take a string, but what about looping through rows and columns?  Am I 
missing a way to use integers directly, or should I create a class that 
takes the two integers and returns them formatted as the proper string?

Thanks

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


Re: last line chopped from input file

2005-08-21 Thread Eric Lavigne

> >   import os
> >   os.command("debug\\curve-fit output.txt")
> >
>
> I imagine thats was a typo for:
>
> >>> os.system("debug\\curve-fit output.txt")
> 
> Alan

That fixes it. Thanks.

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


Re: TKinter

2005-08-21 Thread [EMAIL PROTECTED]

It's pretty hard to know what the problem is with the vague description
you've provided.  Why not post your problem code or, if there's a lot
of it, create a small sample that has the problematic behaviour.
Better yet, post your message to [EMAIL PROTECTED]

cheers
S

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


Re: last line chopped from input file

2005-08-21 Thread gene tani
or: (for long-running Win32 processes)

os.startfile(r'/relative/path/to/app')

http://docs.python.org/lib/os-process.html

under linux/BSD/solaris, i've run into situations where PATH and other
environmental var s aren't what you expect (they're from the
/etc/profile system defaults, not from your .bashrc).  I can't remember
if anything like that happens in windows.

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


Re: network programming

2005-08-21 Thread gene tani
If i had started in 8th grade, I'd be Guido MartelliPeters by now!
Anyway, these people claim to have 125 tutorials, it'll take at least a
couple hours to work thru

http://www.awaretek.com/tutorials.html

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


Gimp-Python

2005-08-21 Thread danilo

Salve,

qualcuno sa se è ancora in fase di sviluppo e qual'è il sito di  
riferimento?

Grazie
Danilo
-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: tkinter text widget question

2005-08-21 Thread rafi
William Gill wrote:
> The tkinter text widget uses indexes to identify row:column offsets 
> within the text, but it seems counter intuitive to have to convert row 
> and column integers to a string like "0.1'.  It's great that index can 
> take a string, but what about looping through rows and columns?  Am I 
> missing a way to use integers directly, or should I create a class that 
> takes the two integers and returns them formatted as the proper string?

tkinter relies on tk that is for tcl at first, and in tcl every thing is 
a string (more or less).

"%s.%s" % (row, column)

should answer your problem easily

my 2 cents

-- 
rafi

"Imagination is more important than knowledge."
(Albert Einstein)
-- 
http://mail.python.org/mailman/listinfo/python-list


Further questions on dictionaries, namespaces, etc.

2005-08-21 Thread Talin
Thanks to everyone for pointing out my bone-headed errors :) I don't 
*usually* make that sort of mistake...

What I'm attempting to do is create an implentation of the unification 
algorithm. Now, its fairly straightforward to do unification on my own 
custom types, all I have to do is define a unify() method for each class:

def unify( self, other, bindings ):
   ...

However, this doesn't work so well when the objects being unified are 
built-in python types (tuples, integers, etc.) This requires the 
"un-pythonic" testing of each individual type and then calling the 
appropriate unification function for the given type.

Another thing that is important is that this particular unifier supports 
commutative functions (which accept their arguments in any order), which 
is what the permutation stuff is for. (I haven't done associativity yet, 
still working on it.) The unifier is structured as a stack of 
generators, each returning all possible matches. This allows the higher 
levels of the unifier to backtrack by processing alternatives produced 
by the lower-level generators.

So here's my list of further questions:

1) Is there are better way to do "functional overloading" on built-in 
types than using a whole series of "if type( x ) is y".

2) Is there an easy way to determine if a given object has a callable 
method named "unify"? I know how to determine if there's an attribute 
with a name, but not how to determine whether or not that attribute is 
callable.

3) The "bindings" object is a dictionary that is constructed as the 
unification proceeds. (So for example, if I attempt to unify "x + 1" 
with "2 + 1" it will have the binding "x : 2" in the dictionary.

I want this bindings object to behave like a function call scope - in 
that you can "see" the variables in the enclosing scope. In fact, I'd 
like to be able to use a regular python namespace (such as a module) as 
the enclosing scope, so that the unification algorithm has access to all 
of the variable definitions within that module. (Again, this is part of 
the notion that I want to be able to do unification operations on normal 
python data structures, rather than specially "wrapped" types.)

In fact, I had thought about the idea of the bindings being an actual 
Python "module" object, however that doesn't appear to be possible (or 
what I want for that matter.) Similarly, being able to take the local 
function scope and capture it in a closure and export that to the 
outside world was also something I briefly pondered.

Because of the backtracking nature of the matcher, I need to be able to 
"undefine" bindings that have been previously defined. The way I am 
currently doing this is to create a new "scope" each time I add a new 
binding, where the new scope's "parent" is the previous scope. (So in 
fact my dictionary has only one entry in it.) Something like this:

for new_bindings in generate_matches( a, b, old_bindings ):
   ...

If none of the alternatives pan out, it simply discards "new_bindings" 
and reverts back to the old_bindings.

So my question here is: Do I want to continue using a subclass of dict 
for this, or something more exotic?

4) I've seen a couple of code examples on the net where people use the 
idiom "lambda x: (for x in [])" to represent a "null" iterator, i.e. one 
that immediately terminates. How is this any different from simply 
returning "()"? (Or range( n, n ) for that matter.) Which one is the 
most efficient? And if they are different, how about adding a null 
iterator to itertools :)

-- Talin

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


Re: last line chopped from input file

2005-08-21 Thread Jeff Schwab
Eric Lavigne wrote:
> Here is a shell command (MS-DOS):
>   debug\curve-fit output.txt
> 
> And here is a Python script that *should* do the same thing (and almost
> does):

Python equivalent is roughly:

import os
import subprocess

subprocess.Popen([os.path.join("debug", "curve-fit")],
stdin=file("input.txt"), stdout=file("output.txt", 'w')).wait()


>   import os
> 
>   inputfilename = 'input.txt'
>   outputfilename = 'output.txt'
> 
>   inputfile = open(inputfilename,'r')
>   outputfile = open(outputfilename,'w')
>   inputstream,outputstream = os.popen2("debug\\curve-fit")
>   inputstream.write(inputfile.read())
>   inputfile.close()
>   inputstream.close()
>   outputfile.write(outputstream.read())
>   outputstream.close()
>   outputfile.close()
> 
> In the shell command, my curve-fit program processes the entire input
> file. In the Python script, my curve-fit program processes all except
> for the last line. Adding an extra newline to the end of my input file
> fixes this problem. What did I do wrong that led to this small
> difference?

No idea.  Your version works fine for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gimp-Python

2005-08-21 Thread Jeff Schwab
danilo wrote:
> 
> Salve,
> 
> qualcuno sa se è ancora in fase di sviluppo e qual'è il sito di  
> riferimento?
> 
> Grazie
> Danilo

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

Re: Binary Trees in Python

2005-08-21 Thread Jeff Schwab
Jorgen Grahn wrote:
> On Sat, 20 Aug 2005 15:19:55 -0400, Roy Smith <[EMAIL PROTECTED]> wrote:
> 
>>In article <[EMAIL PROTECTED]>,
>> [diegueus9] Diego Andrés Sanabria <[EMAIL PROTECTED]> wrote:
>>
>>
>>>Hello!!!
>>>
>>>I want know if python have binary trees and more?
>>
>>Python does not come with a tree data structure.  The basic data structures 
>>in Python are lists, tuples, and dicts (hash tables).
>>
>>People who are used to C++'s STL often feel short-changed because there's 
>>not 47 other flavors of container, but it turns out that the three Python 
>>gives you are pretty useful.  Many people never find a need to look beyond 
>>them.
> 
> 
> Uh, the STL has seven flavors:
> - vector
> - deque
> - list
> - set
> - map
> - multimap
> - multiset

There are others, e.g. std::valarray.  There are also adapters that use 
the above templates to implement other structures, adding or limiting 
functionality as appropriate; e.g., std::heap and std::stack.

> so that's not too bad for a static language. Each of them
> is vital for some purpose, but vector and map are by far the
> most commonly used.
> 
> Neither C++ nor Python has tree structures in their standard libraries. I
> assume that's because there is no single interface that is proven to suit
> everybody's needs.

Hmmm...  I guess I never noticed the lack.  C++ has structures or 
language features that represent most of the common things trees are 
typically used to implement.  Of course, a "tree" can be represented in 
so many ways, it's more of a design pattern than a data structure. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Revamping Python build system (Was: pythonXX.dll size: please split CJK codecs out)

2005-08-21 Thread Martin v. Löwis
Giovanni Bajo wrote:
> You seem to ignore the fact that scons can easily generate VS.NET projects.

I'm not ignoring it - I'm not aware of it. And also, I don't quite
believe it until I see it.

> But there is no technical reason why it has to be so. I work on several
> portable projects, and they use the same build process under both Windows and
> Unix, while retaining full Visual Studio integration (I myself am a Visual
> Studio user).

Well, as long "F6" works...

> Well, you came up with a maintenance problem: you told me that building more
> external modules needs more effort. In a well-configured and fully-automated
> build system, when you add a file you have to write its name only one time in 
> a
> project description file; if you want to build a dynamic library, you have to
> add a single line. This would take care of both Windows and UNIX, both
> compilation, packaging and installation.

I very much doubt this is possible. For some modules, you also need to
create autoconf fragments on Unix, for example, and you need might need
to specify different libraries on different systems.

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


Re: Please Criticize My Code

2005-08-21 Thread Christoph Rackwitz
Why not? Because the regex isn't compiled?
Don't tell me not to do something, tell me why i should'nt do it.

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


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Martin v. Löwis
Ron Adam wrote:
> I would put the starting minimum boundary as:
> 
>1. "The minimum required to start the python interpreter with no
> additional required files."
> 
> Currently python 2.4 (on windows) does not yet meet that guideline, so
> it seems some modules still need to be added while other modules, (I
> haven't checked which), are probably not needed to meet that guideline.

I'm not sure, either, but I *think* python24 won't load any .pyd file
on interactive startup.

> This could be extended to:
> 
>2. "The minimum required to run an agreed upon set of simple Python
> programs."
> 
> I expect there may be a lot of differing opinions on just what those
> minimum Python programs should be.  But that is where the PEP process
> comes in.

As I mentioned earlier, there also should be a negative list: modules
that depend on external libraries should not be incorporated into
python24.dll. Most notably, this rules out zlib.pyd, _bsddb.pyd,
and _ssl.pyd, all of which people may consider to be useful into these
simple programs.

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


Problem with wxPython 2.6.1

2005-08-21 Thread Mario Lacunza
Hello!

Im newbie in Linux, I have instaled Ubuntu 5.04, but I couldt install
the wxPython 2.6.1, anybody help me??

For this reason I dont do my Job , because I use SpeIde and Boa
Constructor, and both dont run with the old v wxPython 2.5.3

Thanks in advance!!

-- 
Saludos / Best regards

Mario Lacunza
Desarrollador de Sistemas - Webmaster
Email: [EMAIL PROTECTED]
Email: [EMAIL PROTECTED]
Messenger MSN: [EMAIL PROTECTED]
Website: http://www.lacunza.tk
Lima - Peru
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?)

2005-08-21 Thread Michael Ekstrand
On 21 Aug 2005 09:45:26 -0700
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Python lets me access module level variables from *anywhere*.  All I
> have
> to do is add module name in front.
> 
> e.g.
> 
> mymodule.myvariable
> 
> Is this considered a 'global'?  Or, does a 'global variable' have to
> be accessible anywhere *without* a namespace in front?

Whether or not it is a true academic global, such a variable is what
Python calls a global. There is no way to make a variable universally
accessible without a namespace.

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


Re: question about binary and serial info

2005-08-21 Thread nephish
Sorry i am late getting back on this.
ord() is finally what is giving me what i wanted.
the vendor told me that what was comming in was an ascii string
representing hex characters. So i expected when i used the serial
module
that what i would be getting was something along the lines of 4A, 3D,
etc..
but i got weird characters. So then (with the help of this very thread)
discovered that i am reading raw bytes. i am supposed to validate the
bytes as they come in because the message comes in four at a time. and
i validate each byte
like this
var = (validation number)
a = ser.read(1)
x = ord(a)
then to validate : x = (x & var)

I am really sorry about the confusion. i am really new at this.
but i am getting what i am supposed to now.

i dont have the details on the script, because it is at work.
but i will post it monday.
thanks for everything.
i would still be banging my head if not for this thread

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


Re: Further questions on dictionaries, namespaces, etc.

2005-08-21 Thread Bruno Desthuilliers
Talin a écrit :
(snip)
> 2) Is there an easy way to determine if a given object has a callable 
> method named "unify"? 

if callable(getattr(obj, 'unify', None)):
# obj.unify exists and is callable

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


Re: Python Light Revisted?

2005-08-21 Thread Steve Holden
Steve M wrote:
> I agree with you in part and disagree in part.
> 
> I don't see the point to making the distribution any smaller. 10MB for
> the installer from python.org, 16MB for ActiveState .exe installer. How
> is 5MB "lightweight" while 10MB isn't? The Windows XP version of Java
> at java.com is 16+ MB, and the .NET framework is, well, I don't know
> how big, but I doubt it's much less than 10MB.
> 
I really don't think that it's worth trying to compress the standard 
distribution any further, given that it isn't really bloatware. I can 
see the point for embedded systems and the like, but for generic PC use 
there isn't really a problem.

> Also I think it's a terrible idea to distribute without pieces of the
> standard library if the distribution is meant to be developed against
> for arbitrary applications. (If you just want a slimmed down Python for
> one specific application, use py2exe - I think it only includes
> whatever gets imported for your program to run.) And excluding zip
> while including Twisted? I don't get it. Besides, how do you know
> Twisted doesn't import XML-RPC? I could see an enlarged Python that
> includes Twisted along with the standard library, and in fact
> ActiveState's includes win32 stuff. There's another such
> mega-distribution around, the name of which escapes me at the moment.
> But removing zip from the standard library so you can save 20kb seems
> foolish. (Again, unless it is for one specific application, in which
> case py2exe should do the trick, although I could be wrong about that
> since I've never used it.)
> 
> Now, what I do agree with is a Python that can be run from a folder
> without having to be installed on the system. That could have lots of
> benefits, if the details with pythonpath and whatever could be sorted
> out. For example I haven't upgraded to 2.4 yet because I have 20
> different packages (e.g. SOAPpy, ZODB, whatever)  installed on WinXP,
> many of which required me selecting my 2.3 installation when I
> installed them. I have no idea what will happen to all those if I run
> the ActiveState installer for 2.4. I seem even to remember reading that
> I have to un-install 2.3 before installing 2.4. I don't want to
> re-install those 20 packages. Anyway I haven't had time to research it
> and it isn't pressing, even though I'd like to start trying decorators
> and generator expressions.
> 
Someone recently produced a distribution capable of running from a CD 
and designed to make it easy to use Python on machines where it wasn't 
actually installed. That might be a useful starting point too, but I 
can't find the right incantation to get Google to bring it up.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: while c = f.read(1)

2005-08-21 Thread Steve Holden
Paul Rubin wrote:
> Reinhold Birkenfeld <[EMAIL PROTECTED]> writes:
> 
>>Don't forget
>>
>>for line in f:
>>for c in line:
>># do stuff
> 
> 
> As mentioned before, that's careless programming, since it can read
> the whole file into memory if the file contains no newlines.

I agree that there may be circumstances where this naiive approach is 
sub-optimal. However, calling this careless programming is a bit over 
the top. Reading files into memory is often the preferred approach 
nowadays, and on a modern laptop (say) files several megabytes in size 
will be processed perfectly happily.

Efficiency is good, but remember Kernighan and Plauger (elements of 
Programming Style): First, make it work. Then (if it doesn't work fast 
enough) make it work faster.

Most times the simple solution works for the problem under 
consideration, and useless optimization work is avoided.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: Related To Threads

2005-08-21 Thread Steve Holden
Sidd wrote:
> Hello,
>   I want to write a thread in python which can be invoked for say 5
> sec, within that the threads function would be to take input,is it
> possible because i tried it and found that raw_input() is blocking
> threads.
> 
There isn't really a convenient solution to this problem, since a thread 
can't easily be stopped "from the outside".

Various solutions you might dream up using signals are likely to be 
either unreliable or non-portable or possibly both.

You m ay have to poll the keyboard directly to gather input and time out 
if it doesn't arrive.

http://www.python.org/doc/faq/windows.html#how-do-i-check-for-a-keypress-without-blocking

will be some help in the windows environment, select() is your friend 
under *nix.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: Moinmoin config

2005-08-21 Thread skip

Mark> I have another question, and as of yet, have not found another
Mark> discussion group for moinmoin, so sorry, but here goes:

Have you tried the mailing list [EMAIL PROTECTED]  If you
are determined to read it via Usenet, try gmane:

http://dir.gmane.org/search.php?match=moin

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


Re: urllib leaves sockets open?

2005-08-21 Thread Chris Tavares
"Paul Rubin"  wrote in message
news:[EMAIL PROTECTED]
> "Chris Tavares" <[EMAIL PROTECTED]> writes:
> > Is this normal behavior for urllib? Is there a way to force that initial
> > socket closed earlier? Is there something else I need to do?
>
> I'd say open a sourceforge bug.  There may be a way around it with the
> fancy opener methods of urllib2, but it's a bug if regular urllib
> opens a second socket without closing the first one.  For http 1.1
> it should be able to use just one socket anyway.

Thanks, I'll do some poking around in urllib first and see if I can narrow
it down.

Is there a way to do HTTP 1.1 with urllib? The docs say 0.9 and 1.0 only.

Thanks,

-Chris


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


Re: urllib leaves sockets open?

2005-08-21 Thread Paul Rubin
"Chris Tavares" <[EMAIL PROTECTED]> writes:
> Is there a way to do HTTP 1.1 with urllib? The docs say 0.9 and 1.0 only.

I'm not sure.  Try urllib2, but I'm still not sure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: network programming

2005-08-21 Thread Steve Holden
John Walton wrote:
> Hello, everyone.  I just began school, and they
> already assigned us science fair.  Since I'm in 8th
> grade, I get to do demonstrations for our projects. 
> I'm probably going to demonstrate Python's networking
> capabilities by writing a simple instant messenger
> program.  I only have a few problems:
> 
> 1. I know squat about Python network Programming
> 
> 2. I know nothing about networks
> 
>   So if any of you know of a good Python Networking
> Tutorial or a website with lots of information on
> networks and networking, please reply.  Thanks!
> 
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

You might want to take a look at the materials from a Network 
Programming tutorial I wrote for LinuxWorld a couple of years ago.

http://www.holdenweb.com/linuxworld/NetProg.pdf (student notes)
http://www.holdenweb.com/linuxworld/NetProg.ppt (slides)
http://www.holdenweb.com/linuxworld/ex.tar (code samples)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Ron Adam
Martin v. Löwis wrote:
> Ron Adam wrote:
> 
>>I would put the starting minimum boundary as:
>>
>>   1. "The minimum required to start the python interpreter with no
>>additional required files."
>>
>>Currently python 2.4 (on windows) does not yet meet that guideline, so
>>it seems some modules still need to be added while other modules, (I
>>haven't checked which), are probably not needed to meet that guideline.
> 
> 
> I'm not sure, either, but I *think* python24 won't load any .pyd file
> on interactive startup.
> 
> 
>>This could be extended to:
>>
>>   2. "The minimum required to run an agreed upon set of simple Python
>>programs."
>>
>>I expect there may be a lot of differing opinions on just what those
>>minimum Python programs should be.  But that is where the PEP process
>>comes in.
> 
> 
> As I mentioned earlier, there also should be a negative list: modules
> that depend on external libraries should not be incorporated into
> python24.dll. 

This fits under the above, rule #1, of not needing additional files.


Most notably, this rules out zlib.pyd, _bsddb.pyd,
> and _ssl.pyd, all of which people may consider to be useful into these
> simple programs.

I would not consider those as being part of "simple" programs.  But 
that's only an opinion and we need something more objective than opinion.

Now that I think of it.. Rule 2 above should be...

 2. "The minimum (modules) required to run an agreed upon set of 
"common simple" programs.

Frequency of use is also an important consideration.

Maybe there's a way to classify a programs complexity based on a set of 
attributes.

So...  program simplicity could consider:

 1.  Complete program is a single .py file.
 2.  Not larger than 'n' lines.  (some reasonable limit)
 3.  Limited number of import statements.
 (less than 'n' modules imported)
 4.  Uses only stdio and/or basic file operations for input
 and output. (runs in interactive console or command line.)

Then ranking the frequency of imported modules from this set of programs 
could give a good hint as to what might be included and those less 
frequently used that may be excluded.

Setting a pythonxx.dll minimum file size goal could further help.  For 
example if excluding modules result is less than the minimum goal, then 
a few extra more frequently used modules could be included as a bonus.

This is obviously a "practical beats purity" exercise. ;-)

Cheers,
Ron




> Regards,
> Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Light Revisted?

2005-08-21 Thread skip

Ramza> The goal, build python(mainly for win32) so that the ENTIRE
Ramza> install is maybe less than 5MBs and includes possibly a GUI
Ramza> library, possibly TwistedMatrix, possibly install from just
Ramza> unzipping an archive like applications such as Eclipse.

...

Ramza> Why?  For example, I don't need an XML-RPC library, or zip
Ramza> library, or the other libraries.

Let's suppose I decided to take your bait and build a python-lite
distribution (fyi, I'm not biting).  How would I know what to remove and
what to retain?  Some choices would be simple.  If I was targeting Win32 I
could clearly leave out Mac- or Unix-Specific stuff.  I could probably
dispense with the docs on the premise that you could read them online.  How
would I decide whether to keep or toss xmlrpclib or zipfile?  If I keep
xmlrpclib should I also keep SimpleXMLRPCServer?  What about unicodedata
(it's a biggie)?

What about compatibility?  If someone installs the python-lite distro then
downloads, let's say, Tailor, a version control converter.  What are the
chances that it will croak with an ImportError?  Put another way, are you
really willing to trade off a few megs of disk space against almost certain
breakage at some point in the near future?

I can understand that distributions for some platforms (PalmOS, OS/2, Amiga,
Jython) might contain fewer modules simply because not everything has been
ported to them, but given the cost of disk space today I don't understand
why a distribution for a mainstream platform should be hobbled.

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


Re: question about binary and serial info

2005-08-21 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Sorry i am late getting back on this.
> ord() is finally what is giving me what i wanted.
> the vendor told me that what was comming in was an ascii string
> representing hex characters. So i expected when i used the serial
> module
> that what i would be getting was something along the lines of 4A, 3D,
> etc..
> but i got weird characters. So then (with the help of this very thread)
> discovered that i am reading raw bytes. i am supposed to validate the
> bytes as they come in because the message comes in four at a time. and
> i validate each byte
> like this
> var = (validation number)
> a = ser.read(1)
> x = ord(a)
> then to validate : x = (x & var)
> 
> I am really sorry about the confusion. i am really new at this.
> but i am getting what i am supposed to now.
> 
> i dont have the details on the script, because it is at work.
> but i will post it monday.
> thanks for everything.
> i would still be banging my head if not for this thread
> 
Nice of you to provide some feedback, and great that your program in 
understanding the data.

You'll find c.l.py can save you large amounts of time, and before you 
know it you'll be answering other people's questions.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Python dutch

2005-08-21 Thread Dragonfly
hi,
Do you have a python lesson book in dutch version on your site?

greetz erik =)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: network programming

2005-08-21 Thread Lucas Raab
John Walton wrote:
> Hello, everyone.  I just began school, and they
> already assigned us science fair.  Since I'm in 8th
> grade, I get to do demonstrations for our projects. 
> I'm probably going to demonstrate Python's networking
> capabilities by writing a simple instant messenger
> program.  I only have a few problems:
> 
> 1. I know squat about Python network Programming
> 
> 2. I know nothing about networks
> 
>   So if any of you know of a good Python Networking
> Tutorial or a website with lots of information on
> networks and networking, please reply.  Thanks!
> 

I believe the Twisted Matrix library has an IM module written for it and 
a tutorial on programming with the library. www.twistedmatrix.com


-- 
--
Lucas Raab
lvraab"@"earthlink.net
dotpyFE"@"gmail.com
AIM:Phoenix11890
MSN:dotpyfe "@" gmail.com
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sandboxes

2005-08-21 Thread Peter Hansen
42 wrote:
> Thoughts? Still gaping holes?

Certainly.  And rather than rehash them all here, I'm going to suggest 
you check the comp.lang.python archives for any of the many past 
discussions about this before you spend too much time thinking 
(repeatedly) that you've nailed that one last hole only to have somebody 
point out yet another way around it.

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


Decorator and Metaclasses Documentation

2005-08-21 Thread sysfault
Does anyone know of any good documentation on these topics, doesn't look
like the official python tutorial covers them. Thanks in advance.
-- 
A wise man knows he knows nothing.

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


Re: Best way to 'touch' a file?

2005-08-21 Thread Peter Hansen
Kenneth McDonald wrote:
> I could've sworn python had such a command, but now I can't find it...
> 
> I'm looking for an easy way to perform a UNIX-style "touch", to  update 
> the modification time of a file without actually modifying it.  I could 
> do something (I imagine) like opening the file for appending  and then 
> immediately closing it, but that doesn't seem like a good  idea--what if 
> the file is already open for reading or writing? Anyone  know of a nice, 
> elegant solution?

from path import path
path('myfile').touch()

(That relies on Jason Orendorff's path.py module, which does this and 
much more very elegantly, not to mention practically.)

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


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Jeffrey E. Forcier
Amusingly, I was just perusing these links earlier today. Go go Firefox
history search!

http://www.python.org/2.2/descrintro.html
http://users.rcn.com/python/download/Descriptor.htm

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


Re: Gimp-Python

2005-08-21 Thread David Trudgett
danilo <[EMAIL PROTECTED]> writes:

> Salve,
>
> qualcuno sa se è ancora in fase di sviluppo e qual'è il sito di
> riferimento?

Beh, tutto e' sempre in fase di sviluppo, non e' vero?

An Internet search turns up: 

  http://www.jamesh.id.au/software/pygimp

but the site was not responding when I tried it.

According to the gimp website (http://www.gimp.org/) the Python
bindings have undergone some recent improvements (up to June this
year). So, it would appear that these bindings are receiving continued
attention.

Perhaps you could try a mailing list to find out more?

  http://www.gimp.org/mail_lists.html



Saluti,

David


-- 

David Trudgett
http://www.zeta.org.au/~wpower/

Così uno, il quale fin dalla nascita avesse avuto le gambe legate e
pure avesse trovato modo di camminare alla men peggio, potrebbe
attribuire la sua facoltà di muoversi precisamente a quei legami, che
invece non fanno che diminuire e paralizzare l'energia muscolare delle
sue gambe.

[...]

Figuratevi che all'uomo dalle gambe legate, che abbiamo supposto, il
medico esponesse tutta una teoria e mille esempi abilmente inventati
per persuaderlo che colle gambe sciolte egli non potrebbe né
camminare, ne vivere; quell'uomo difenderebbe rabbiosamente i suoi
legami e considererebbe nemico chi volesse spezzarglieli.

-- Errico Malatesta, "Anarchia"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python dutch

2005-08-21 Thread Terry Reedy

"Dragonfly" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> hi,
> Do you have a python lesson book in dutch version on your site?

Did you try to look?  Either by using the search bar at the top of each 
page or going to the documentation page http://www.python.org/doc/ where 
there is a link to Non-English Documents?

Terry J. Reedy



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


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread sysfault
On Sun, 21 Aug 2005 17:01:13 -0700, Jeffrey E. Forcier wrote:

> Amusingly, I was just perusing these links earlier today. Go go Firefox
> history search!
> 
> http://www.python.org/2.2/descrintro.html
> http://users.rcn.com/python/download/Descriptor.htm


Are descriptors the same thing as decorators?
-- 
A wise man knows he knows nothing.

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


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Mike C. Fletcher
sysfault wrote:

>Does anyone know of any good documentation on these topics, doesn't look
>like the official python tutorial covers them. Thanks in advance.
>  
>
PyCon 2005, PyCon 2004 and PyGTA November 2004 presentations here are 
all on these topics:
http://www.vrplumber.com/programming/

Though the don't go into extreme detail on decorators (they are 
basically syntactic sugar for a particular type of descriptor).

HTH,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Steve Holden
sysfault wrote:
> On Sun, 21 Aug 2005 17:01:13 -0700, Jeffrey E. Forcier wrote:
> 
> 
>>Amusingly, I was just perusing these links earlier today. Go go Firefox
>>history search!
>>
>>http://www.python.org/2.2/descrintro.html
>>http://users.rcn.com/python/download/Descriptor.htm
> 
> 
> 
> Are descriptors the same thing as decorators?

No. In brief:

Decorators are a mechanism whereby a function or method can be 
transparently wrapped by another function.

Descriptors are used to hook programmed functionality into the basic 
access mechanisms of object attributes.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

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


Re: Please Criticize My Code

2005-08-21 Thread Ray
Christoph Rackwitz wrote:
> Why not? Because the regex isn't compiled?
> Don't tell me not to do something, tell me why i should'nt do it.

No it's not the regex, it's because you just spoiled the challenge for
everybody who hasn't solved level 10 yet...

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


Re: Problem with wxPython 2.6.1

2005-08-21 Thread Trian Diarsa
can you explain about your problem ?
 
 
> --- Mario Lacunza <[EMAIL PROTECTED]> menulis:
> 
> > Hello!
> > 
> > Im newbie in Linux, I have instaled Ubuntu 5.04,
> but
> > I couldt install
> > the wxPython 2.6.1, anybody help me??
> > 
> > For this reason I dont do my Job , because I use
> > SpeIde and Boa
> > Constructor, and both dont run with the old v
> > wxPython 2.5.3
> > 
> > Thanks in advance!!
> > 
> > -- 
> > Saludos / Best regards
> > 
> > Mario Lacunza
> > Desarrollador de Sistemas - Webmaster
> > Email: [EMAIL PROTECTED]
> > Email: [EMAIL PROTECTED]
> > Messenger MSN: [EMAIL PROTECTED]
> > Website: http://www.lacunza.tk
> > Lima - Peru
> > -- 
> >
> http://mail.python.org/mailman/listinfo/python-list
> > 
> 
> 
> 
>   
> 
>   
>   
>

> 
> Apakah Anda Yahoo!?
> Sekarang dengan penyimpanan 1GB
> http://id.mail.yahoo.com/
> 







 
Apakah Anda Yahoo!?
Sekarang dengan penyimpanan 1GB
http://id.mail.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SOAP and XMLRPC

2005-08-21 Thread Sybren Stuvel
phil hunt enlightened us with:
> I thought it was the whole point of XMLRPC that the server can be
> written in one language and the client in another. Am I wrong?

It is, but not all SOAP libs really support the standard.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python dutch

2005-08-21 Thread Sybren Stuvel
Dragonfly enlightened us with:
> Do you have a python lesson book in dutch version on your site?

I'd suggest learning English. The programming language is based on
English anyway. Besides, everybody in The Netherlands learns English
at school.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Jeffrey E. Forcier
Sorry about that, I misread the original question. However, the
python.org link is still valid as it concerns metaclasses as well as a
handful of other topics.

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


Re: global interpreter lock

2005-08-21 Thread [EMAIL PROTECTED]
km wrote:
>
> is true parallelism possible in python ? or atleast in the coming versions ?
> is global interpreter lock a bane in this context ?

I've had absolutely zero problems implementing truly parallel programs
in python.  All of my parallel programs have been multiprocess
architectures, though--the GIL doesn't affect multiprocess
architectures.

Good support for multiple process architectures was one of the things
that initially lead me to pick Python over Java in the first place
(Java was woefully lacking in support facilities for this kind of
architecture at that time; it's improved somewhat since then but still
requires some custom C coding).  I don't have much desire to throw out
decades of work by OS implementors on protected memory without a pretty
darn good reason.

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


Re: As Simple As Possible?

2005-08-21 Thread [EMAIL PROTECTED]
Jorgen Grahn wrote:
> More importantly, I think: it's not polite for a programming language to
> make it hard to communicate with the rest of your environment.
>
> Java pissed me off when I looked at it back in the 1990s, because I was on
> Unix, and the language would barely give me access to the command line
> options, had no getopt-style parser, etc. "No, you're supposed to write the
> kinds of programs that /we/ want you to write!"
>
> Python, in contrast, happily provides all that (and enough, it seems, to
> make Windows and web server people reasonably happy too). The ideological
> stuff ends at the source code level.


I always phrased it as "Java is platform independent; Python is
platform agnostic".  The failure of Java to provide access to even such
simple niceties as select() (which is available on all major platforms
in some form) because it doesn't fit the Java Way (TM) was pretty
frustrating (they've fixed that example since, but analagous facilities
are still lacking).

Despite reject TMTOOTDI, Python doesn't have any interest in mandating
a Pure Python solution done using one true philosophy of software
design.

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


Network Programming Information

2005-08-21 Thread John Walton
Hello. It's me again.  Thanks for all the help with
the Python Networking Resources, but does anyone know
what I'll need to know to write a paper on Network
Programming and Python.  Like terminology and all
that.  Maybe I'll have a section on socketets, TCP,
Clients (half of the stuff I don't even know what it
means).  So, does anyone know any good websites with
Network Programming information.  Thanks!

John

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sandboxes

2005-08-21 Thread 42
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] 
says...
> 42 wrote:
> > Thoughts? Still gaping holes?
> 
> Certainly.  And rather than rehash them all here, I'm going to suggest 
> you check the comp.lang.python archives for any of the many past 
> discussions about this before you spend too much time thinking 
> (repeatedly) that you've nailed that one last hole only to have somebody 
> point out yet another way around it.
> 
> -Peter
> 

Fair enough. I'm more or less ready to 'give up' on this fantasy of 
python in a sandbox. I'll either use something else, or just accept the 
risk. :)

But for what its worth, I *am* curious what sorts of holes persist. I 
did try googling the archives, but with no idea what I'm looking for -- 
python security brings up a mess of unrelated issues... Python in 
Apache, rexec/bastion stuff, xss, issues with infinite loops and many 
other 'security' issues that might be relevant to someone running python 
on a web server where you have to be concerned about DOS but not of any 
concern to me... and so on and so forth.

Can you, or someone, at least give me a few keywords I should be looking 
for that will bring matches for the sorts of attachs you've hinted at? 

Mostly just to satisfy my curiousity.

-regards,
Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


win32 - associate .pyw with a file extension...

2005-08-21 Thread knutsample
Hello!

I'm trying to associate a file extension to my wxPython script so that
all I have to do is double click on the file and my python script will
load up with the path of that file.

For instance, I've associated all .py files to be opened up with
emacs.exe.  If I double click on a .py file, emacs.exe would open up
with that file in its buffer.

Is there a way to do this with a non-exe (wxPython script)?  Everytime
I try to associate a certain file extension (right clicking file->Open
with->Choose program) with my python script (.pyw) windows states that
I do not have a valid win32 program.  Is there a way to do this with a
python script?  Thank you for your time.

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


Uploading images to imageshack.us with Python

2005-08-21 Thread Ricardo Sanchez
Hello,

I'm trying to upload images to http://imageshac.us via a Python script.


I have looked at the POST request with HTTPLiveHeaders Firefox
extension when I upload an image, but I can't figure what's wrong. (if
I disable the cookies in the browser, it still works, so it's not
that).

When I try to upload images with the script below, the server replies
with the following error:


Warning:  Division by zero in /home/image/www/index.php
on line 270

followed with the regular imageshack.us index.

Currently my code is the following one (I got it from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306):

# --
import urllib, httplib, mimetypes

def post_multipart(host, port, selector, fields, files):
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form
fields.
files is a sequence of (name, filename, value) elements for data to
be uploaded as files
Return the server's response page.
"""
content_type, body = encode_multipart_formdata(fields, files)

h = httplib.HTTP(host, port)

h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()

def encode_multipart_formdata(fields, files):
"""
fields is a sequence of (name, value) elements for regular form
fields.
files is a sequence of (name, filename, value) elements for data to
be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
BOUNDARY = '---13049614110900'

CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s";
filename="%s"' % (key, filename))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body

def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or
'application/octet-stream'

params = [('MAX_FILE_SIZE', '3145728'), ('refer',
'http://reg.imageshack.us/v_images.php')]
files = [('fileupload', 'b.jpg', open('b.jpg').read())]

print open('a.jpg').read()

print post_multipart('proxy-a.mains.nitech.ac.jp', 8080,
'http://imageshack.us/index.php', params, files)
# --


Here is the HTTPLiveHeaders POST request:
# --
http://imageshack.us/index.php

POST http://imageshack.us/index.php HTTP/1.1
Host: imageshack.us
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10)
Gecko/20050716 Firefox/1.0.6
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Referer: http://imageshack.us/
Cookie: imgshck=4d590dbf69a8461ddff60153181b6c61;
img_gallery=e04663a565bc72348bfb2bdeec6d50a0%3Dp10100397vj.jpg%3Dimg185;
PHPSESSID=1bd06f468149071bd87f7f8e90142cff
Content-Type: multipart/form-data;
boundary=---114782935826962
Content-Length: 90772
-114782935826962
Content-Disposition: form-data; name="MAX_FILE_SIZE"

3145728
-114782935826962
Content-Disposition: form-data; name="refer"


-114782935826962
Content-Disposition: form-data; name="fileupload"; filename="a.jpg"
Content-Type: image/jpeg

ÿØÿà
HTTP/1.x 200 OK
Date: Mon, 22 Aug 2005 05:14:16 GMT
Server: Apache/2.0.54 (Unix)
X-Powered-By: PHP/4.4.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
pre-check=0
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=ISO-8859-1
# --


Any help would be appreciated.

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


Re: Uploading images to imageshack.us with Python

2005-08-21 Thread Ricardo Sanchez
I forgot to add that I'm behind a proxy, but I think that is
irrelevant.

If you are not behind a proxy replace this line:

print post_multipart('proxy-a.mains.nitech.ac.jp', 8080,
'http://imageshack.us/index.php', params, files)

with

print post_multipart('imageshack.us', 80, '/index.php', params, files)

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


Re: Sandboxes

2005-08-21 Thread Steve Jorgensen
Clearly, Pyton does not directly offer any kind of useful security sandbox
capability, but since Java does, I suppose JPython is an option.  I know there
are a lot of downsides to JPython, but it should be a genuine solution to the
sandbox problem.

On Sat, 20 Aug 2005 10:21:06 GMT, 42 <[EMAIL PROTECTED]> wrote:

>Hi,
>
>I'm extremely new to python, and am looking at using it as an embedded 
>script engine in a dotnet project I'm working on. I'm currently playing 
>with the "Python for Net" (http://www.zope.org/Members/Brian/PythonNet) 
>stuff, and it seems to work well.
>
>Googling for information on securing Python in a "sandbox" seems 
>indicate that there are some built in features, but they aren't really 
>trustworthy. Is that correct?
>
>For my purposes, I really just want to let users run in a sandbox, with 
>access to only the language, manipuate a few published objects in the 
>application (and perhaps give them some string and math libraries if 
>applicable).
>
>I was wondering if it would be effective to pre-parse incoming scripts 
>and reject those containing "import"? I'd also have the application 
>inject the (short) list of trusted imports to the script before passing 
>it to the interpreter.
>
>In theory I'm hoping this would mean script writers would have access to 
>the stuff they need and no way to add in anything else.
>
>Would this sufficient? Are there any drawbacks or giant gaping holes? 
>I'm anticipating that I'd also need to block 'exec' and 'eval' to 
>prevent an import from being obfuscated past the pre-parse.
>
>Or is this a hopeless cause? 
>
>Finally, either way, would anyone recommend a different script engine 
>that might be more suitable for what I'm trying to accomplish that I 
>might not have looked at. I don't need much; it needs to work with C#, 
>and be able to easily interact with 'published' interface. I'd also like 
>to leverage a "popular" language instead of something obscure.
>
>I also looked at Javascript, but couldn't find a way to embed an 
>interpreter into a C# app. There's some CodeDom stuff with JScript, but 
>that seemed backwards...overkill; I don't really want to compile 
>temporary assemblies for hundreds of 2 and 3 line scripts... and the VSA 
>stuff has been marked deprecated with no apparent successor... seems 
>like I jumped into this at precisely the wrong time. :)
>
>Any thoughts, insights, or comments welcome. Forgive my lack of Python 
>savvy... I've only been playing with it for a few hours now; after 
>bumping into the "python for net" link.
>
>-regards,
>Dave

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


Re: pythonXX.dll size: please split CJK codecs out

2005-08-21 Thread Thomas Heller
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:

> Ron Adam wrote:
>> I would put the starting minimum boundary as:
>> 
>>1. "The minimum required to start the python interpreter with no
>> additional required files."
>> 
>> Currently python 2.4 (on windows) does not yet meet that guideline, so
>> it seems some modules still need to be added while other modules, (I
>> haven't checked which), are probably not needed to meet that guideline.
>
> I'm not sure, either, but I *think* python24 won't load any .pyd file
> on interactive startup.

That seems to be true.  But it will need zlib.pyd as soon if you try to
import from compressed zips.  So, zlib can be thought as part of the
modules required for bootstrap.

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


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Michele Simionato
There are also my lectures at Oxford:

http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip

   Michele Simionato

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