Re: What's so funny? WAS Re: rotor replacement

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

> The likely-best-known Python application in the world (probably more
> people have heard of it than have heard of Python) originally had
> crypto

and what Python application is that?  I can think of quite a few applications
written in Python that are widely known, but none of these are distributed as
Python code to end users.

> I do know that its author wanted an AES module in the core
> to use for that application, in order to not have to distribute a C
> extension

 



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


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Michael Spencer
Francis Girard wrote:
The following implementation is even more speaking as it makes self-evident 
and almost mechanical how to translate algorithms that run after their tail 
from recursion to "tee" usage :

Thanks, Francis and Jeff for raising a fascinating topic.  I've enjoyed trying 
to get my head around both the algorithm and your non-recursive implementation.

Here's a version of your implementation that uses a helper class to make the 
algorithm itself prettier.

from itertools import tee, imap
def hamming():
def _hamming():
yield 1
for n in imerge(2 * hamming, imerge(3 * hamming, 5 * hamming)):
yield n
hamming = Tee(_hamming())
return iter(hamming)
class Tee(object):
"""Provides an indepent iterator (using tee) on every iteration request
Also implements lazy iterator arithmetic"""
def __init__(self, iterator):
self.iter = tee(iterator,1)[0]
def __iter__(self):
return self.iter.__copy__()
def __mul__(self, number):
return imap(lambda x: x * number,self.__iter__())
def imerge(xs, ys):
  x = xs.next()
  y = ys.next()
  while True:
if x == y:
  yield x
  x = xs.next()
  y = ys.next()
elif x < y:
  yield x
  x = xs.next()
else: # if y < x:
  yield y
  y = ys.next()
>>> hg = hamming()
>>> for i in range(1):
... n = hg.next()
... if i % 1000 == 0: print i, n
...
0 1
1000 5184
2000 81
3000 27993600
4000 4707158941350
5000 5096079360
6000 4096000
7000 2638827906662400
8000 143327232
9000 680244480
Regards
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: error

2005-01-25 Thread Fredrik Lundh
"me" <[EMAIL PROTECTED]> wrote:

> whenever i try and run my Python GUI, my computer thinks for a sec, then
> drops the process, without ever displaying the window. the command prompt
> window seems to work fine, but the IDLE GUI won't start.
>
> i'm running Windows 2K professional and python 2.4, so any advice help would
> be appreciated. i've already tried reinstalling and use a thread response,
> as the e-mail on this account is bogus.

have you tried tweaking your firewall settings?  idle uses socket communication
between its processes, and some firewalls may interfere with this.  see:

http://www.python.org/2.4/bugs.html

as a last resort, there's also a way to run idle in "single process" mode:

http://article.gmane.org/gmane.comp.python.general/383376

 



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


Re: Help on project, anyone?

2005-01-25 Thread Fuzzyman

Miki Tebeka wrote:
> Hello Fuzzyman,
>
> > 3) Simple Version Control program for single programmer. A very
simple
> > way of doing version control/releases for small projects with only
a
> > single programmer. [3]
> Subversion (and CVS) are dead simple to install and use.

I've heard *lots* of people say exactly the opposite.

> IMO in the long run you'll find yourself implementing most of their
> features anyway.
>
> > [3] I think lots of people would find this useful. A version
control
> > system for projects where CVS/Subversion is overkill. This would be
> > based on DirWatcher/FSDM (
> > http://www.voidspace.org.uk/python/programs.shtml#dirwatcher ) -
All
> > the code for finding which files have changed is already there, and
> > there is an existing Tkinter GUI for Dirwatcher.
> Adding changes to version control should be done as an explicit
action by
> the developer. Anything else is on the road to disaster, you'll find
> yourself spending too much time backing out of changes you didn't
want in.

Yeah, my idea is pretty flexible. You could snapshot a 'release state',
and roll back changes on individual files in between releases. You
basically maintain it on your file system in the normal way and keep an
archive of releases/changes.

I think this probably works well with the may most small projects are
actually managed.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

>
> Bye.
> --
>

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

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


Re: is there better 32 clock() timing?

2005-01-25 Thread Tim Roberts
Ray Schumacher <[EMAIL PROTECTED]> wrote:
>
>I have a need for a time.clock() with >0.16 second (16us) accuracy.
>The sleep() (on Python 2.3, Win32, at least) has a .001s limit.
>
>Are they lower/better on other's platforms? 

You need to be careful about describing what you're seeing here.  It is not
that time.clock() is inaccurate.  The problem is that the "time.clock()"
statement takes several hundred microseconds to execute.

>I had also considered forking a thread that would spin a loop checking
>time.clock() and firing the TTL pulse after the appropriate interval,
>but the real, ultimate resolution of time.clock() appears to be 
>~.00035s. If I increase process priority to real-time, it is ~.00028s
>The alternative appears to be more C code...

Are you seriously considering writing a real-time application in Python on
Windows?  The ONLY way to get small-integer microsecond responses in
Windows is to write a kernel driver, and even then there are no guarantees.
Windows is NOT a real-time system.  If you have an environment where an
unexpected delay of a millisecond or more is going to cause damage, then
you need to redesign your application.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Retrieving modification time of file class was declared in

2005-01-25 Thread Bengt Richter
On 24 Jan 2005 20:39:11 -0800, [EMAIL PROTECTED] wrote:

>Assume I am using a class Foo. I want to find out the modification time
>of the file that that class was defined in. How would I go about this?
>
>If I could find out the name of the file that Foo was defined in then
>it is easy, I could use os.path.getmtime(), but I can't even figure
>that out.
>
>I realize that this wouldn't be a completely accurate way to tell the
>last time this class was modified because it could inherit info from
>other classes, or use functions from other modules that have been
>modified, etc.
>
>Nathan Bullock
>

try this for about any object you can pass to finfo:

< finfo.py >
import sys, os
def finfo(obj):
if not hasattr(obj, '__name__'):
obj = type(obj)
name = '<%s instance>'%obj.__name__
else:
name = obj.__name__
if type(obj) == type(sys):  # module type
modname = name
else:  # not module type, but be class now
modname = obj.__module__
mod = sys.modules[modname]
if modname == '__builtin__' or repr(mod) == ""%modname:
path = sys.executable
else:
path = vars(sys.modules[modname]).get('__file__','??')
if path != '??': tmod = os.path.getmtime(path)
else: tmod = '???'
return name, modname, path, tmod


Not very tested, but seems to retrieve info. The file in question for builtins 
is
the interpreter executable, I supposed.

Ignore the "ut." here, that's just my utilities grabbag

 [ 0:25] C:\pywk\sovm>py24
 Python 2.4b1 (#56, Nov  3 2004, 01:47:27)
 [GCC 3.2.3 (mingw special 20030504-1)] on win32
 Type "help", "copyright", "credits" or "license" for more information.
 >>> from ut.finfo import finfo
 >>> finfo(finfo)
 ('finfo', 'ut.finfo', 'c:\\pywk\\ut\\finfo.pyc', 1106641080)
 >>> import time
 >>> time.ctime(finfo(finfo)[-1])
 'Tue Jan 25 00:18:00 2005'

HIH

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


Re: Why can't use cursor.nextset() in adodbapi package?

2005-01-25 Thread Tim Roberts
nightmarch <[EMAIL PROTECTED]> wrote:

>Thank you Dennis!
>
>You mean I should execute many select statement like this " rec =
>crsr.fetchall() " ?

No, you misunderstand.  nextset() is used when you issue several SELECT
statements in a single request.  The first fetchall() gets the results of
the first SELECT statement.  To get the next one, you use nextset().

Your example only had one SELECT:

>> > >>> sql = "select * from wjtmp"
>> > >>> crsr.execute(sql)
>> > >>> rec = crsr.fetchone()
>> > >>> crsr.nextset()

If you are only issuing one SELECT, like most applications, then nextset()
serves no purpose.  If you did something like this:

  sql = "select * from wjtmp; select count(*) from wjtmp;"

That's when you need nextset().  Personally, I've never used it.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Folder in Desktop

2005-01-25 Thread Dennis Benzinger
Kamilche wrote:
> Is there a command you can execute in Python that will open a window on
> the desktop, such as 'My Documents'? Kind of like 'system', but for
> folder names, not just programs. I'm running on Windows 2000.
> 

Here are some commands you can use (tested on WinXP, so YMMV):


1. The os.system function

import os
os.system('explorer "c:\program files"')

This has the disadvantage that a cmd.exe windows is also opened,
because os.system executes the command in a subshell.

But using this approach the explorer starts in front of all other windows.


2. The os.startfile function

import os
os.startfile("C:\program files")

Using startfile doesn't open a cmd.exe window, but the folder window
is not started in front of the other windows


3. The subprocess.Popen function

import subprocess
subprocess.Popen('explorer "C:\program files"')

With subprocess.Popen no cmd.exe window is opened and the explorer
starts in front of the other windows.
But the subprocess module is new in Python 2.4.



Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Folder in Desktop

2005-01-25 Thread Ulf Göransson
Kamilche wrote:
Is there a command you can execute in Python that will open a window on
the desktop, such as 'My Documents'? Kind of like 'system', but for
folder names, not just programs. I'm running on Windows 2000.
Maybe this is good enough?
os.system("explorer " + folder_path)
/ug
--
http://mail.python.org/mailman/listinfo/python-list


RE: Open Folder in Desktop

2005-01-25 Thread Jimmy Retzlaff
Kamilche wrote:
> Is there a command you can execute in Python that will open a window
on
> the desktop, such as 'My Documents'? Kind of like 'system', but for
> folder names, not just programs. I'm running on Windows 2000.

There are two issues here. The first is how to open a folder and the
second is how to resolve "special" folders. Folders are "documents"
typically associated with the explorer.exe application. To open a
document with its default app (e.g., a folder), use os.startfile which
is included in Python. For example:

import os
os.startfile(r'c:\windows')

Folders like My Documents, My Pictures, etc. are special and you need to
determine their actual path before you can open them. The pywin32
extensions
(https://sourceforge.net/project/showfiles.php?group_id=78018) include a
way to get at this:

from win32com.shell import shellcon, shell
path = shell.SHGetFolderPath(0, shellcon.CSIDL_MYPICTURES, 0, 0)
os.startfile(path)

Google for CSIDL to find the constants to use for other special folders.

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


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Nick Craig-Wood
Francis Girard <[EMAIL PROTECTED]> wrote:
>  def hamming():
>def _hamming():
>  yield 1
>  hamming2 = hammingGenerators[0]
>  hamming3 = hammingGenerators[1]
>  hamming5 = hammingGenerators[2]
>  for n in imerge(imap(lambda h: 2*h, iter(hamming2)),
>  imerge(imap(lambda h: 3*h, iter(hamming3)),
> imap(lambda h: 5*h, iter(hamming5:
>yield n
>hammingGenerators = tee(_hamming(), 4)
>return hammingGenerators[3]

If you are after readability, you might prefer this...

def hamming():
  def _hamming():
yield 1
for n in imerge(imap(lambda h: 2*h, iter(hamming2)),
imerge(imap(lambda h: 3*h, iter(hamming3)),
   imap(lambda h: 5*h, iter(hamming5:
  yield n
  hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
  return result

PS interesting thread - never heard of Hamming sequences before!
-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to call python code from C#

2005-01-25 Thread just starting
Thanks for all your kind information. I haven't used COM objects so
far.I think now I have to learn it.Anyway thanks a lot again.
paritosh.


On Mon, 24 Jan 2005 12:43:50 -0700, Dave Brueck
<[EMAIL PROTECTED]> wrote:
> Peter Hansen wrote:
> > paritosh mahana wrote:
> >
> >> How can I call python code from my C#  code.
> [snip]
> > You could use ctypes or the pywin32 package to provide your
> > Python code with an ActiveX interface.  Then you could just
> > use it via COM, like any other COM object.  Lots of references
> > available via Google if you want to learn more about this
> > approach...
> 
> Lemme add my two cents and say that this approach works well.
> 
> We have a component that uses ctypes and runs as a COM local server (its own
> .exe) and we currently use it both from Internet Explorer and from a C#
> application. COM can be hairy initially, but if you have any experience with 
> COM
> then this approach is pretty straightforward.
> 
> -Dave
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Ola Natvig
Roy Smith wrote:
In article <[EMAIL PROTECTED]>,
 Quest Master <[EMAIL PROTECTED]> wrote:

I am interested in developing an application where the user has an
ample amount of power to customize the application to their needs, and
I feel this would best be accomplished if a scripting language was
available. However, I want to code this application in Python, and I
have not yet heard of an implementation of another scripting language
into Python.
An example of what I mean is this (an implementation of Lua into Ruby
-- which I'd prefer not to use): http://ruby-lua.unolotiene.com/
I know C/C++ might be better suited for a task of this kind, but most
of the modules in my application which need speed have already been
coded in C++. I want to use Python as the "glue" for this project;
writing an entire application with a pretty GUI is not fun, as most of
you may know from previous experience.
So, my question is simply this: is there an implementation of another
scripting language into Python?

Python *is* a scripting language.  Why not just let your users write 
Python modules which you them import and execute via some defined API?
There are examples of XML used for application configuration and in 
template systems, I don't know how much power you intend to give your 
users, but if it boils down to simple display logic and some small 
'macro' calls to a predefined API, you could make some kind of tagged 
language for that implementing basic flowcontroll functionality, 
allowing function calling and definition.

You could look at wxWidgets/wxPython's XRC format, which are a XML 
tagged  format that are used to customize layout of wx forms.

But I don't think there are a implemented any fully usable scripting 
languages like that in Python. But it should not be to much work if you 
don't need many functions.

--
--
 Ola Natvig <[EMAIL PROTECTED]>
 infoSense AS / development
--
http://mail.python.org/mailman/listinfo/python-list


ANN: LJ pyGTK clien Zapys-0.3 released

2005-01-25 Thread Timothy Babytch
Usable simple app for posting messages to LiveJournal.
Easy extandable.
Main feature: character substitution. I mean (tm) to â, (c) to Â, quote 
to matching pairs and so on. The list can be easily extended with your 
own regexps.

submit on Ctrl+Enter.
Edit/delete last entry.
screenshot: http://img.lj.com.ua/ilishin/zapys-3.png
download: http://firefox.org.ua/misc/zapys-0.3.tar.bz2
--
http://mail.python.org/mailman/listinfo/python-list


RE: how to ncurses on win32 platform

2005-01-25 Thread Tim Golden
[Jorgen Grahn]
| [Alan Gauld ]
| > You can use ncurses via cygwin.
| > There are DOS ports too but I couldn't get any of them to 
| > work on my XP box, YMMV...
| 
| Or, as Alex Martelli wrote in "Python in a nutshell":
| 
|"The curses package works only on Unix-like platforms 
| (there are persis-
|tent rumors of Windows ports of it, but I've never found a 
| working one)."

This is the only one I've seen which claims 
(at least partial) compatibility. I've looked
it over, but never had a chance to try it out:

http://flangy.com/dev/python/curses/

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Fuzzyman
An implementation of the core language semantics - without any modules
or file operations would be dead useful.

It could replace some of the function of the long dead rexec modules as
well as support projects like this.
Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: how to call python code from C#

2005-01-25 Thread Ryan Paul
On Tue, 25 Jan 2005 00:35:04 +0530, paritosh mahana wrote:

> Hi all,
> How can I call python code from my C#  code. One thing is to make an
> .exe file of the python program and then try to call it from my C#
> code. But I don't like that idea. Is there any other way to do this.
> Like making a .dll file from the python code and somehow call it from
> C# program.But I couldn't find anything on this topic on the net.
> Actually my GUI is in C#  and rest part is in python, and i need to
> call python from my C# program. Please correct me if I am wrong
> anywhere.
> thanks
> paritosh.

This may not be relevant, but if what you are looking for is a way to
write a program for .NET with a language that doesnt suck, you might want
to look at Boo (http://boo.codehaus.org/). I'm not sure if it can directly
use winforms, but you can probably make native .net libraries with it that
you can utilize from C#. Boo looks and feels almost exactly like
Python, so the learning curve is minimal, and using it is very pleasant.

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


Re: specifying constants for a function (WAS: generator expressions: performance anomaly?)

2005-01-25 Thread Bengt Richter
On Mon, 24 Jan 2005 20:35:09 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:

>On Mon, 24 Jan 2005 00:31:17 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>
>>Bengt Richter wrote:
>>> So, e.g., for
>>> 
>>>  >>> presets = dict(a=1, b=2, deftime=__import__('time').ctime())
>>> 
>>> in the decorator args, the next version will act as if the decorated
>>> function had the source code
>>> 
>>>  >>> print '%s = __frompresets__' % ', '.join(sorted(presets))
>>>  a, b, deftime = __frompresets__
>>> 
>>> for the current version, except that it will be hidden.
>>
>>Cool!  Keep us posted.  I assume you'll put this into the Cookbook?
>>
>Not ready for prime time, I guess, but I made a module that does presets
>and also adjusts parameters and count to do currying without nested function
>calling in the curried function.
>
> >>> from presets import presets, curry
> >>> @presets(verbose=True, a=1, b=2, deftime=__import__('time').ctime())
> ... def foo():
> ...print (a, b)
> ...print deftime
> ...
>
> presets: -- "name(?)" means name may be unused
>a = 1
>b = 2
>  deftime = 'Mon Jan 24 12:16:07 2005'
>
> >>> foo()
> (1, 2)
> Mon Jan 24 12:16:07 2005
> >>> @curry(verbose=True, y=444)
> ... def bar(x=3, y=4):
> ... return x*y
> ...
>
> presets: -- "name(?)" means name may be unused
>y = 444
>
> >>> bar(2)
> 888
> >>> bar(2, 3)
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: bar() takes at most 1 argument (2 given)
> >>> bar()
> 1332

Not much reaction, so I guess I won't see it if any, since I am going off line 
for a while.
BTW, this exercise makes me realize that you could do some other interesting 
things too,
if you put your mind to it. E.g., it might be interesting to inject properties 
into
the local namespace of a function, so that e.g., x=1 would would trigger an 
effect
like someobj.x = 1, where type(someobj).x was a property. It wouldn't be
too hard to make

@addprop(verbose=True, x=property(getx, setx, delx))
def foo():
x = 123
return x

etc. Maybe could be used to monitor access to specific locals for debug,
or other uses. Haven't even begun to think about that. 

Another thing is to turn selected local defs into constants, since executing
the aggregation-of-parts code that accomplished the def may well be unchanging.
This would reduce the execution cost of nested functions. I guess that is
a specific case of a more general sticky-evaluate-rhs-once kind of directive
for locals that are only assigned in one place. special sentinels could
be used in the decorator keyword values to indicate this treatment of the
associated name, e.g.
from presets import presets
@presets(x=presets.STICKY, y=123)
def foo(y):
x = initx() # done once on the first call, making x references constant 
after that
return x*y

Another thing that could be done is to inject pre and post things like atexit 
stuff.
Also maybe some adaptation things that is just a buzzword so far that I haven't 
explored.

BTW, is there another op that needs relocation besides JUMP_ABSOLUTE? 

I was wondering about doing code mods by messing with an ast, but a decorator 
would
have to chase down the source and reparse I guess, in order to do that. It 
would be
interesting to be able to hook into ast stuff with some kind of metacompile 
hook (hand waving ;-)

Bye for a while.

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-25 Thread Robert Kern
Fredrik Lundh wrote:
<[EMAIL PROTECTED]> wrote:

The likely-best-known Python application in the world (probably more
people have heard of it than have heard of Python) originally had
crypto

and what Python application is that?  I can think of quite a few applications
written in Python that are widely known, but none of these are distributed as
Python code to end users.
BitTorrent, probably.
I believe that a very high percentage of users get the BitTorrent apps 
as standalone executables, not as a Python package where one has to go 
download Python first. The ones that do get it as Python source probably 
get it from their Linux/FreeBSD/other distribution where such 
dependencies are also taken care of for them.

--
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: how to ncurses on win32 platform

2005-01-25 Thread Fuzzyman

Tim Golden wrote:
> [Jorgen Grahn]
> | [Alan Gauld ]
> | > You can use ncurses via cygwin.
> | > There are DOS ports too but I couldn't get any of them to
> | > work on my XP box, YMMV...
> |
> | Or, as Alex Martelli wrote in "Python in a nutshell":
> |
> |"The curses package works only on Unix-like platforms
> | (there are persis-
> |tent rumors of Windows ports of it, but I've never found a
> | working one)."
>
> This is the only one I've seen which claims
> (at least partial) compatibility. I've looked
> it over, but never had a chance to try it out:
>
> http://flangy.com/dev/python/curses/
>
> TJG

It's a shame there isn't (as far as I can see) a source distribution,
or a 2.4 binary.

It works very well for the parts implemented.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
>
>

> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a
proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
>


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


Re: Help with Threading

2005-01-25 Thread Philip Smith

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I use threading.Thread as outlined in this recipe:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65448
>Thanks 


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


Re: is there better 32 clock() timing?

2005-01-25 Thread Bengt Richter
On Tue, 25 Jan 2005 00:18:44 -0800, Tim Roberts <[EMAIL PROTECTED]> wrote:

>Ray Schumacher <[EMAIL PROTECTED]> wrote:
>>
>>I have a need for a time.clock() with >0.16 second (16us) accuracy.
>>The sleep() (on Python 2.3, Win32, at least) has a .001s limit.
>>
>>Are they lower/better on other's platforms? 
>
>You need to be careful about describing what you're seeing here.  It is not
>that time.clock() is inaccurate.  The problem is that the "time.clock()"
>statement takes several hundred microseconds to execute.
What system are you on?
This is 300 mhz P2 and py2.4b1 gcc/mingw generated:

 >>> from time import clock
 >>> min(abs(clock()-clock()) for i in xrange(10**5))
 5.857725137128e-006
 >>> min(abs(clock()-clock()) for i in xrange(10**5))
 5.85771847579e-006
 >>> min(abs(clock()-clock()) for i in xrange(10**5))
 5.857700712221e-006
 >>> import time
 >>> min(abs(time.clock()-time.clock()) for i in xrange(10**5))
 7.5428559824786134e-006
 >>> min(abs(time.clock()-time.clock()) for i in xrange(10**5))
 7.5428559824786134e-006
 >>> min(abs(time.clock()-time.clock()) for i in xrange(10**5))
 7.5428559824786134e-006

Even with the attribute lookup overhead, it's not several hundred microseconds
as a *minimum*. But on e.g. win32 you can get preempted for a number of 
milliseconds.
E.g., turn that to a max instead of a min:

I see a couple 20-30 ms ones ;-/

 >>> max(abs(time.clock()-time.clock()) for i in xrange(10**5))
 0.0085142082264155761
 >>> max(abs(time.clock()-time.clock()) for i in xrange(10**5))
 0.0088125700856949152
 >>> max(abs(time.clock()-time.clock()) for i in xrange(10**5))
 0.0022125710913769581
 >>> max(abs(clock()-clock()) for i in xrange(10**5))
 0.023374472628631793
 >>> max(abs(clock()-clock()) for i in xrange(10**5))
 0.030183995400534513
 >>> max(abs(clock()-clock()) for i in xrange(10**5))
 0.0017130664056139722
 >>> max(abs(clock()-clock()) for i in xrange(10**5))
 0.0070844179680875641

>
>>I had also considered forking a thread that would spin a loop checking
>>time.clock() and firing the TTL pulse after the appropriate interval,
>>but the real, ultimate resolution of time.clock() appears to be 
>>~.00035s. If I increase process priority to real-time, it is ~.00028s
>>The alternative appears to be more C code...
>
>Are you seriously considering writing a real-time application in Python on
>Windows?  The ONLY way to get small-integer microsecond responses in
>Windows is to write a kernel driver, and even then there are no guarantees.
>Windows is NOT a real-time system.  If you have an environment where an
>unexpected delay of a millisecond or more is going to cause damage, then
>you need to redesign your application.
For sure. The big requirements picture is missing (not uncommon ;-)

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


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Bengt Richter
On 25 Jan 2005 08:30:03 GMT, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:

>Francis Girard <[EMAIL PROTECTED]> wrote:
>>  def hamming():
>>def _hamming():
>>  yield 1
>>  hamming2 = hammingGenerators[0]
>>  hamming3 = hammingGenerators[1]
>>  hamming5 = hammingGenerators[2]
>>  for n in imerge(imap(lambda h: 2*h, iter(hamming2)),
>>  imerge(imap(lambda h: 3*h, iter(hamming3)),
>> imap(lambda h: 5*h, iter(hamming5:
>>yield n
>>hammingGenerators = tee(_hamming(), 4)
>>return hammingGenerators[3]
>
>If you are after readability, you might prefer this...
>
>def hamming():
>  def _hamming():
>yield 1
>for n in imerge(imap(lambda h: 2*h, iter(hamming2)),
>imerge(imap(lambda h: 3*h, iter(hamming3)),
>   imap(lambda h: 5*h, iter(hamming5:
>  yield n
>  hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
>  return result
>
>PS interesting thread - never heard of Hamming sequences before!

Are the long words really that helpful?

def hamming():
  def _hamming():
yield 1
for n in imerge(imap(lambda h: 2*h, iter(hg2)),
imerge(imap(lambda h: 3*h, iter(hg3)),
   imap(lambda h: 5*h, iter(hg5:
  yield n
  hg2, hg3, hg5, result = tee(_hamming(), 4) # four hamming generators
  return result

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


Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-25 Thread Richie Hindle

[Tim]
> there's no 100% guarantee that a __del__ method will ever get called

Can anyone point me to any definitive documentation on why this is the
case?  I was under the impression that __del__ would always be called:

 1. for objects not in cycles and with no references

 2. for objects whose only references are from cycles which themselves
have no external references and no __del__methods, assuming that
garbage collection runs.

> __del__ methods (weakref callbacks too, for that matter) triggered
> while Python is tearing itself down at exit may suffer bizarre
> exceptions (due to trying to use facilities in partially-torn down
> modules, including the module the __del__ method appears in).

Good point.

> In general, __del__ is a user-visible method like any other, and user
> code may call it explicitly.  For that reason, it's safest to write
> __del__ methods in library objects such that they can be invoked
> multiple times gracefully.

Another good point - thanks.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Simon Brunning
On Mon, 24 Jan 2005 12:17:13 -0600, Philippe C. Martin
<[EMAIL PROTECTED]> wrote:
> 
> I use "__"for private variables because I must have read on net it was
> the way to do so - yet this seems to have changed - thanks:
> 
> http://www.network-theory.co.uk/docs/pytut/tut_77.html

Nope, that's still the right way to make a member 'really' private.
Stephen was pointing out a very common Python idiom - "private by
convention", and suggesting that using it would be more appropriate.

A member with a single preceding underscore is private by convention.
That is to say, there is no mechanism in place to prevent clients of
the class accessing these members, but they should consider themselves
to have been warned that they do so at their own risk.

If you take the back off the radio, the warranty is void. ;-)

I (and by inference Stephen) feel that this is a more "Pythonic"
approach. Give the programmer the information that they need, but
don't try to stop them from doing what they need to do.

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


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread michele . simionato
>Name mangling is there to keep you from accidentally hiding such an
>attribute in a subclass, but how often is this really a danger? Can
>someone give me an example of where __-mangling really solved a
problem
>for them, where a simple leading underscore wouldn't have solved the
>same problem?

Look at the "autosuper" implementation on Guido's descrintro paper;
there the
fact that you user __super instead of _super is essential.

However I have written tens of thousands of lines of Python code and
never
needed __protected variables except in a few experimental scripts for
learning purpose. So I agree that the need does not occur often, but it
is still an useful thing to have.
Michele Simionato

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


Re: is there better 32 clock() timing?

2005-01-25 Thread Stephen Kellett
that time.clock() is inaccurate.  The problem is that the "time.clock()"
statement takes several hundred microseconds to execute.
The statement is incorrect. clock() itself isn't slow, but it is 
accessing a resource, the accuracy of which is no better than 1ms.

There are various timers available, documented and undocumented, all of 
which end up at 1ms or 1.1ms, give or take. For anything shorter you 
need QueryPerformanceCounter() (but that *is* a slow call), or use the 
RDTSC instruction which is fast but gives a count of instruction cycles 
executed and is thus not totally accurate (multiple execution pipelines, 
plus multithreading considerations).

You have to choose the system that works best for you. In many cases 
RDTSC works OK.

Stephen
--
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk
RSI Information:http://www.objmedia.demon.co.uk/rsi.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Right place for third party modules (here: fixedpoint)

2005-01-25 Thread Sibylle Koczian
Fredrik Lundh schrieb:
ah, forget what I said.  you need to put the fixedpoint.py *file* under 
site-packages,
not the entire directory.  as that "python -v -v" would have told you:
Thank you (and Steve Holden), that did it.

more out
...
# trying C:\python24\lib\site-packages\fixedpoint.pyd
# trying C:\python24\lib\site-packages\fixedpoint.dll
# trying C:\python24\lib\site-packages\fixedpoint.py
# trying C:\python24\lib\site-packages\fixedpoint.pyw
# trying C:\python24\lib\site-packages\fixedpoint.pyc
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named fixedpoint
...
 

Very helpful, not only directories, but full module names. I hope I'll 
remember (or find) "python -v -v" next time around.

Python is nice, but Python + c.l.p. is a Really Good Thing.
Koczian
--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: What YAML engine do you use?

2005-01-25 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>Sion Arrowsmith wrote:
>> I'm probably not thinking deviously enough here, but how are you
>> going to exploit an eval() which has very tightly controlled
>> globals and locals (eg. eval(x, {"__builtins__": None}, {}) ?
>try this:
>
>eval("'*'*100*2*2*2*2*2*2*2*2*2")

No thanks.

I guess my problem is a tendency view security issues from the
point of view of access to data rather than access to processing.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Nick Craig-Wood
Francis Girard <[EMAIL PROTECTED]> wrote:
>  The following implementation is even more speaking as it makes self-evident 
>  and almost mechanical how to translate algorithms that run after their tail 
>  from recursion to "tee" usage :
> 
>  *** BEGIN SNAP
>  from itertools import tee, imap
>  import sys
> 
>  def imerge(xs, ys):
>x = xs.next()
>y = ys.next()
>while True:
>  if x == y:
>yield x
>x = xs.next()
>y = ys.next()
>  elif x < y:
>yield x
>x = xs.next()
>  else:
>yield y
>y = ys.next()

Thinking about this some more leads me to believe a general purpose
imerge taking any number of arguments will look neater, eg

def imerge(*generators):
values = [ g.next() for g in generators ]
while True:
x = min(values)
yield x
for i in range(len(values)):
if values[i] == x:
values[i] = generators[i].next()

>  def hamming():
>def _hamming():
>  yield 1
>  hamming2 = hammingGenerators[0]
>  hamming3 = hammingGenerators[1]
>  hamming5 = hammingGenerators[2]
>  for n in imerge(imap(lambda h: 2*h, iter(hamming2)),
>  imerge(imap(lambda h: 3*h, iter(hamming3)),
> imap(lambda h: 5*h, iter(hamming5:
>yield n
>hammingGenerators = tee(_hamming(), 4)
>return hammingGenerators[3]

This means that this can be further simplified thus,

def hamming():
def _hamming():
yield 1
for n in imerge( imap(lambda h: 2*h, hamming2),
 imap(lambda h: 3*h, hamming3),
 imap(lambda h: 5*h, hamming5) ):
yield n
hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
return result

(Note the iter(...) seemed not to be doing anything useful so I
removed them)

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


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Richie Hindle

[Steven]
> Can someone give me an example of where __-mangling really solved a problem 
> for them, where a simple leading underscore wouldn't have solved the 
> same problem?

http://cvs.sourceforge.net/viewcvs.py/spambayes/spambayes/spambayes/Dibbler.py?r1=1.13&r2=1.13.4.1

That's a bugfix to SpamBayes, where I'd inadvertently named an instance
variable '_map' without realising that the base class
(asynchat.async_chat) also had an instance variable of that name.  Using
double underscores fixed it, and had I used them from the beginning the
bug would never have cropped up (even if asynchat.async_chat had an
instance variable named '__map', which is the whole point (which you know,
Steven, but others might not)).

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: is there better 32 clock() timing?

2005-01-25 Thread Bengt Richter
On Tue, 25 Jan 2005 11:42:35 +, Stephen Kellett <[EMAIL PROTECTED]> wrote:

>>>that time.clock() is inaccurate.  The problem is that the "time.clock()"
>>>statement takes several hundred microseconds to execute.
>
>The statement is incorrect. clock() itself isn't slow, but it is 
>accessing a resource, the accuracy of which is no better than 1ms.
I believe that is quite wrong as a general statement. It may be right
on some benighted system, but not on win32/NT python 2.4.
How do you account for getting deltas of 6-7 microseconds
in abs(clock()-clock()) ? If the "resource" only had ~1ms granularity,
the minimum would be zero, as it is if you call time.time() in a tight loop,
since it doesn't tick over often enough. time.clock does tick over fast
enough that you can't snag the same reading on two successive clock() calls
on a 300mhz P2.

>
>There are various timers available, documented and undocumented, all of 
>which end up at 1ms or 1.1ms, give or take. For anything shorter you 
>need QueryPerformanceCounter() (but that *is* a slow call), or use the 
Have you timed it, to make that claim? What do you mean by "slow"?

>RDTSC instruction which is fast but gives a count of instruction cycles 
>executed and is thus not totally accurate (multiple execution pipelines, 
>plus multithreading considerations).
Accurate for what. A single clock AFAIK drives RDTSC
>
>You have to choose the system that works best for you. In many cases 
>RDTSC works OK.
I wrote an extension to access it directly, and was agble to get down
to 23 cycles IIRC for a C call pair like above on a 300 mhz P2. 23/300 us I 
guess,
less than 100 ns between the clock reads of two calls.

The main problem with a CPU clock based reading is that it's very stable unless
there's variable clock rate due to power management.

Why am I doing this? ;-)

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Arthur
On Mon, 24 Jan 2005 19:40:31 -0500, Roy Smith <[EMAIL PROTECTED]> wrote:

>In article <[EMAIL PROTECTED]>,
> Quest Master <[EMAIL PROTECTED]> wrote:
>
>
>Python *is* a scripting language.  Why not just let your users write 
>Python modules which you them import and execute via some defined API?

This is the tact I take with PyGeo.

The burden is on myself, as the API designer and documenter to make it
as accessible as I might want it to be.  And I think I can accomplish
that without building in crippling limitations as to  what depth a
"scripter" might want to explore - even to the extent of extending the
API itself.

I guess its a matter of the audience one hopes to reach.  There are a
number of other dynamic geometry applications out there.  Despite my
own interest in the subject, it was precisely the limitations their
API, whether GUI based or otherwise, that led me to the explorations
that is becoming PyGeo.  It was the limitaions in exploring *geometry*
to which I refer. Having no per se interest in programming, I would
not impose the assumption of such an interest on my users.

I guess I hope to reach others like myself.  With no particular
interest in programming, per se. Just with what you can get do with
it.

Art


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


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Toby Dickenson
On Tuesday 25 January 2005 12:40, Richie Hindle wrote:
> 
> [Steven]
> > Can someone give me an example of where __-mangling really solved a 
problem 
> > for them, where a simple leading underscore wouldn't have solved the 
> > same problem?
> 
> 
http://cvs.sourceforge.net/viewcvs.py/spambayes/spambayes/spambayes/Dibbler.py?r1=1.13&r2=1.13.4.1
> 
> That's a bugfix to SpamBayes, where I'd inadvertently named an instance
> variable '_map' without realising that the base class
> (asynchat.async_chat) also had an instance variable of that name.  Using
> double underscores fixed it, and had I used them from the beginning the
> bug would never have cropped up (even if asynchat.async_chat had an
> instance variable named '__map', which is the whole point (which you know,
> Steven, but others might not)).

I have a counterexample. Consider refactoring a class from

class B(A):
etc

into

class C(A):
etc
class B(C):
etc

Usage of some double-undescore attributes moved from B to the new intermediate 
base class C. Unit tests on B still passed, so that change is safe. right?

The problem occured because the double-underscore mangling uses the class 
name, but ignores module names. A related project already had a class named C 
derived from B  (same name - different module). My refactoring caused 
aliasing of some originally distinct double-underscore attributes.

-- 
Toby Dickenson



Important Notice:

This email and any attachments are confidential and may contain trade secrets 
or be legally privileged. If you have received this email in error you must not 
use, rely upon, disclose, copy or distribute the contents. Please reply to the 
sender so that proper delivery can be arranged and delete the email from your 
computer.
Gemini Data Loggers monitor incoming and outgoing email to ensure satisfactory 
customer service, maintain company security and prevent abuse of their email 
system. However, any views expressed in this email are not necessarily those of 
Gemini and Gemini cannot be held responsible for the content.
Gemini makes best efforts to ensure emails are virus free; however you are 
advised to carry out your own checks. Gemini does not accept responsibility for 
any damage resulting from email viruses.


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


snakespell and myspell

2005-01-25 Thread Fuzzyman
I'm looking to implement a plugin spell checker.

I'm probably going to go with PyEnchant, as it looks to be the most
promising currently maintained spell checker.

I just wondered if anyone knew what happened to snakespell and myspell.
Both seem to have dissapeared from the net. People have reported good
results from both - and it seems a shame to lose them.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


threading.py Condition wait overflow error

2005-01-25 Thread Mark English
Every once in a while since I moved to Python 2.4 I've been seeing the
following exception in threading.py Condition:

  File "mctest3.py", line 1598, in WaitForMessages
self.condResponses.wait(1.0)
  File "C:\Program Files\Python24\lib\threading.py", line 221, in wait
delay = min(delay * 2, remaining, .05)
OverflowError: long int too large to convert to int

Is there something I'm doing wrong here ? I've looked at my code, and
glanced at threading.py, and I can't see any obvious errors (multiplying
a float by 2, using the result of the time.time() call none of which use
longs as far as I know).

I added some print statements to threading.py and the exception is
thrown on the first iteration when delay is 0.0005 and remaining is 1.0
However the code does keep running...
---
Delay: 0.0005 Remaining: 1.0
Traceback (most recent call last):
  File "", line 1, in ?
  File "mctest3.py", line 2665, in getLogonResponse
respLogon.WaitForMessages()
  File "mctest3.py", line 1598, in WaitForMessages
self.condResponses.wait(1.0)
  File "C:\Program Files\Python24\lib\threading.py", line 222, in wait
delay = min(delay * 2, remaining, .05)
OverflowError: long int too large to convert to int
Delay: 0.016 Remaining: 8.0789619
Delay: 0.032 Remaining: 8.0163242
Delay: 0.05 Remaining: 7.9539619
Done
Message response handler got message 
---

Is this something to do with min ? Converting 1.0 ?

Thanks for any help.

Mark


---
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary 
companies.
---

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Roy Smith
"Carl Banks" <[EMAIL PROTECTED]> wrote:

> > Imbed
> EMBED.

My apologies for being sloppy.  And with an initial capital, so it just 
jumps off the page at you :-)
 
> > Python, or Perl, or TCL, or Ruby, or PHP,
> 
> Not PHP.  PHP is one of the better (meaning less terrible) examples of
> what happens when you do this sort of thing, which is not saying a lot.

But, that's exactly my point.  To be honest, I've never used PHP.  But 
however bad it may be, at least it's got a few years of people fixing 
bugs, writing books, writing add-on tools, etc, behind it.  Better to 
use somebody else's well-known and well-supported mess of a scripting 
language than to invest several person-years inventing your own mess 
that's no better.

There are a lot of existing scripting languages to pick from.  It's nice 
to pick the best one, but even if you pick the worst, that's probably 
better than you can do on your own.
 
> TCL isn't that great in this regard, either, as it makes a lot of
> common operations that ought to be very simple terribly unweildy.

In my last job, I did a lot of TCL.  I've posted on this before (when I 
was at a previous employer), so I'll just provide a pointer 
(http://tinyurl.com/44w6n).  That article says most of what that needs 
saying, *AND* proves that I really do know how to spell embed :-)

It might be worth adding, however, that the TCL implementation discussed 
above was a 3rd generation for that product.  Generation #1 was a bunch 
of shell scripts.  Generation #2 was a home-grown scripting language.  
Fortunately, they learned their lesson soon enough to rescue the project 
with a conversion to TCL.  I'm not sure how many person-years were 
wasted both in the initial implementation and in the conversion effort, 
but I imagine it was a $500,000 mistake.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter socket client ?

2005-01-25 Thread Tonino
Hi,

thanks for this info - I had to abandon the createfilehandler() method
as it is not supported in windows and the GUI "might" be used there at
some time ...

So - I went the threading route - works well - for now - so I will
stick to it ...

BUT - the next question:
In the Text() widget - why - when the text scrolls off the screen -
does the window not follow it ?

I have added a scrollbar to it :

self.center_frame = Frame(self.top_frame, background="tan",
relief=RIDGE)

self.text=Text(self.center_frame,background='white')
scroll=Scrollbar(self.center_frame)
self.text.configure(yscrollcommand=scroll.set)

self.text.pack(side=LEFT, fill=BOTH, expand=YES)
scroll.pack(side=RIGHT,fill=Y)
self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)


but the window does not scroll to follow the text ?
Any ideas ?

Thanks
Tonino

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


Re: RE:"private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Sion Arrowsmith
Jeremy Bowers  <[EMAIL PROTECTED]> wrote:
> [ ... ] the Python community, and in general the dynamic language
>community, has become increasingly confident that private variables don't
>solve *real* problems.

Years of writing and maintaining others' C++ and Java code (plus
one year of maintaining Python code and rather more writing) has
led me to believe that there is no justification for truly private
variables. "protected" yes, I can see the argument for, but
denying derived classes full access to your inner workings just
leads to clumsier (less readable and more bug-prone) implementations
derivations. (The same applies to Java's "final".) And it's based on
the hubris that you are a better programmer than anyone who might
want to extend your class and can forsee all circumstances in which
it might be subclassed.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter socket client ?

2005-01-25 Thread Martin Franklin
Tonino wrote:
Hi,
thanks for this info - I had to abandon the createfilehandler() method
as it is not supported in windows and the GUI "might" be used there at
some time ...
So - I went the threading route - works well - for now - so I will
stick to it ...
BUT - the next question:
In the Text() widget - why - when the text scrolls off the screen -
does the window not follow it ?
I have added a scrollbar to it :
self.center_frame = Frame(self.top_frame, background="tan",
relief=RIDGE)
self.text=Text(self.center_frame,background='white')
scroll=Scrollbar(self.center_frame)
self.text.configure(yscrollcommand=scroll.set)
self.text.pack(side=LEFT, fill=BOTH, expand=YES)
scroll.pack(side=RIGHT,fill=Y)
self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
but the window does not scroll to follow the text ?
Any ideas ?
This is the default behavior of the Text widget.  You have two options 
(as I see it) one, put the new text at the top of the Text widget 
textwidget.insert(0, "your new text") or two, use the yview_pickplace 
method to move the view down every time you insert text 
textwidget.yview_pickplace('end')

I wrote a sub-class of the ScrolledText widget to do just this
I gave it a write method - so I could re-direct stdout to it - and also 
called yview_pickplace in that method.

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


Re: DevX: "Processing EDI Documents into XML with Python"

2005-01-25 Thread Satchidanand Haridas
There has already been some work in this area - although for X12 
transactions for the healthcare industry. Its on sourceforge already and 
best of all the development language is Python:

http://sourceforge.net/projects/pyx12/
thanks,
Satchit

Satchidanand Haridas (sharidas at zeomega dot com)
ZeOmega (www.zeomega.com)
Open  Minds' Open Solutions
#20,Rajalakshmi Plaza,
South End Road,
Basavanagudi,
Bangalore-560 004, India

Jeremy Jones wrote:
Claudio Grondi wrote:
"You don't have to rely on expensive and proprietary EDI conversion 
software
to parse, validate, and translate EDI X12 data to and from XML; you can
build your own translator with any modern programming language, such as
Python."

 by Jeremy Jones
 http://www.devx.com/enterprise/Article/26854
 Excerpt:
 "Python is an object-oriented, byte-compiled language with a clean
syntax, clear and consistent philosophy, and a strong user community. 
These
attributes (both of the language and the community) make it possible to
quickly write working, maintainable code, which in turn makes Python an
excellent choice for nearly any programming task. Processing any 
"flavor" of
EDI is no exception."

Hi,
just wanted to share with you, that the last issue
of the DevX newsletter comes with a Python related
article as first item in the list of subjects.
Claudio
 

Anyone interested in processing EDI with Python will probably be 
interested in giving it a read.  Please feel free to scrutinize the 
code mercilessly.  I plan on creating a project on Sourceforge with 
the code that is attached to that article (and hopefully with 
modifications coming from user input in the ensuing months).  Comments 
are greatly appreciated.

Thanks for posting this, Claudio.
Jeremy Jones
--
http://mail.python.org/mailman/listinfo/python-list


Re: delay and force in Python

2005-01-25 Thread Nick Coghlan
Peter Otten wrote:
Nick Coghlan wrote:

Py> print islice((x for x in xrange(1, 996) if x % 2 == 0), 1, 2).next()
4
Wouldn't it be nice if this could be spelt:
print (x for x in xrange(1, 996) if x % 2 == 0)[2]
Well, I just put a patch on SF to enable exactly that:
http://www.python.org/sf/1108272
 
I like it. Of course you always have to bear in mind that one giant leap for
a list could be _many_ small steps for an iterator.
Indeed. The main cases I am thinking of involve picking off the first few items 
of an iterator (either to use them, or to throw them away before using the rest).

And if an app actually *needs* random access, there's a reason lists still 
exist ;)
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Instances of class object not modifiable?

2005-01-25 Thread Nick Coghlan
Steven Bethard wrote:
Open Issues
===
What should the type be named?  Some suggestions include 'Bunch',
'Record' and 'Struct'.
Add 'namespace' to the list of name suggestions :)
Cheers,
Nick.
The name came up in some thread a few weeks back. . .
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's so funny? WAS Re: rotor replacement

2005-01-25 Thread Fuzzyman
I've already downloaded p3 - thanks :-)

I wonder how long it took (in reality) an average hacker to break the
algorithm used by rotor ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Browsing text ; Python the right tool?

2005-01-25 Thread Paul Kooistra
I need a tool to browse text files with a size of 10-20 Mb. These
files have a fixed record length of 800 bytes (CR/LF), and containt
records used to create printed pages by an external company.

Each line (record) contains an 2-character identifier, like 'A0' or
'C1'. The identifier identifies the record format for the line,
thereby allowing different record formats to be used in a textfile.
For example:

An A0 record may consist of:
recordnumber [1:4]
name [5:25]
filler   [26:800]

while a C1 record consists of:
recordnumber [1:4]
phonenumber  [5:15]
zipcode  [16:20]
filler   [21:800]

As you see, all records have a fixed column format. I would like to
build a utility which allows me (in a windows environment) to open a
textfile and browse through the records (ideally with a search
option), where each recordtype is displayed according to its
recordformat ('Attributename: Value' format). This would mean that
browsing from a A0 to C1 record results in a different list of
attributes + values on the screen, allowing me to analyze the data
generated a lot easier then I do now, browsing in a text editor with a
stack of printed record formats at hand.

This is of course quite a common way of encoding data in textfiles.
I've tried to find a generic text-based browser which allows me to do
just this, but cannot find anything. Enter Python; I know the language
by name, I know it handles text just fine, but I am not really
interested in learning Python just now, I just need a tool to do what
I want.

What I would REALLY like is way to define standard record formats in a
separate definition, like:
- defining a common record length; 
- defining the different record formats (attributes, position of the
line);
- and defining when a specific record format is to be used, dependent
on 1 or more identifiers in the record.

I CAN probably build something from scratch, but if I can (re)use
something that already exists it would be so much better and faster...
And a utility to do what I just described would be REALLY usefull in
LOTS of environments.

This means I have the following questions:

1. Does anybody now of a generic tool (not necessarily Python based)
that does the job I've outlined?
2. If not, is there some framework or widget in Python I can adapt to
do what I want?
3. If not, should I consider building all this just from scratch in
Python - which would probably mean not only learning Python, but some
other GUI related modules?
4. Or should I forget about Python and build someting in another
environment?

Any help would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple slices

2005-01-25 Thread Nick Coghlan
George Sakkis wrote:
You're probably right about the allocation time, but my main concern is the 
memory required for each
slice, which can be O(n) wrt the length of the whole tuple. I would like this 
to be constant (at
least if there was a way around to the problem of deleting the underlying 
sequence).
If you really want a view into a tuple (or any sequence for that matter):
  from itertools import islice
  islice(iter(seq), start, end, step)
Then use the various functions in itertools to work with the resulting iterator 
(since the syntactic support for working with iterators is currently quite 
limited - slicing, concatenation and repetition are spelt with 
itertools.islice(), itertools.chain() and itertools.repeat(), rather than with 
their standard syntactic equivalents "[x:y:z]", "+" and "*").

The above approach does suffer from the problem of holding a reference to the 
original sequence, though.

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Nick Coghlan
Fuzzyman wrote:
An implementation of the core language semantics - without any modules
or file operations would be dead useful.
It could replace some of the function of the long dead rexec modules as
well as support projects like this.
Securing a custom build of the CPython interpreter would probably be 
significantly easier than designing a 'secure mode' that ran on top of the 
standard version. The former might even be a stepping stone towards the latter.

Still not easy though (the main task would be to prevent Python code from 
accessing the OS, while still allowing module imports to work).

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


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Philippe C. Martin
Well I _was_ a bit slow on that one !

So I will happily stick to the double underscore.

Regards,

Philippe



Le mardi 25 janvier 2005 Ã 10:28 +, Simon Brunning a Ãcrit :
> On Mon, 24 Jan 2005 12:17:13 -0600, Philippe C. Martin
> <[EMAIL PROTECTED]> wrote:
> > 
> > I use "__"for private variables because I must have read on net it was
> > the way to do so - yet this seems to have changed - thanks:
> > 
> > http://www.network-theory.co.uk/docs/pytut/tut_77.html
> 
> Nope, that's still the right way to make a member 'really' private.
> Stephen was pointing out a very common Python idiom - "private by
> convention", and suggesting that using it would be more appropriate.
> 
> A member with a single preceding underscore is private by convention.
> That is to say, there is no mechanism in place to prevent clients of
> the class accessing these members, but they should consider themselves
> to have been warned that they do so at their own risk.
> 
> If you take the back off the radio, the warranty is void. ;-)
> 
> I (and by inference Stephen) feel that this is a more "Pythonic"
> approach. Give the programmer the information that they need, but
> don't try to stop them from doing what they need to do.
> 
-- 
***
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***

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


Re: Memory Usage

2005-01-25 Thread Nick Coghlan
Stuart McGarrity wrote:
Do you have a page file?
The Mem column should be RAM usage and not total working set. Some of it 
could be swapped to the page file. A free tool like process explorer can 
give you better informaton than the task manager.
As Tim pointed out, "View->Select Columns" and activating "VM Size" is enough to 
find out how much memory that program actually has *mapped* (rather than 
currently loaded into RAM).

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


Re: Installer made with bdist_wininst segfaulting...

2005-01-25 Thread Thomas Heller
Fernando Perez <[EMAIL PROTECTED]> writes:

> Hi all,
>
> I am seeking advice/help from those with more win32 experience than myself.  I
> am trying to build a proper win32 installer for IPython, after a user did most
> of the hard work.  For the most part, it's working very well, but I am running
> into a nasty problem, which took me a few hours to finally understand.  This
> smells to me like a python  bug, but I could be wrong.  Much googling didn't
> turn up anything relevant.
>
> Here is a brief summary: if the installer file is run from a windows drive 
> which
> is different from the one where python resides (and hence where ipython will
> end up), the installer segfaults.  No traceback, nothing, just a segfault
> (well, one of those Windows dialogs asking me to send a binary traceback to
> Redmond, but not a proper Python traceback).

There are a couple of known bugs in bdist_wininst, and you just reported
another one.  All these bugs are related to using the
post_install_script, and show up when either (thats what I currently
remember):

- the installer is run from a readonly location,
- the installer is run from a different drive (as you reported)
- the installer installs for Python 2.4

I will fix these issues in Python 2.3.5, which will probably be out as a
release candidate this week, and in Python 2.4.1.

I urge everyone to install this release candidate, rebuild the
installer with it, and test them thoroughly.

Thanks,

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


*IMPORTANT* Message for Google Group users!

2005-01-25 Thread google_groups_001
Good News!

Do you know how simple it is to go to Heaven after this life has ended?

Some people believe that belonging to a local church, temple, mosque or
synagogue will get them to Heaven.

Others believe that water baptism, obeying the ten commandments or just
being a good person will get them to Heaven.

There are many other beliefs as well, but the good news about God's way
to Heaven is found in the Holy Bible.

The good news is that God came from Heaven to earth in the person of
Jesus Christ over 2000 years ago and died for our sins(misdeeds). He
was born in the land of Israel supernaturally to a virgin Jewish woman
named Mary. He lived a sinless life for thirty-three years and then
sacrificed His sinless blood and died on a cross to pay the death
penalty for our sins. After Jesus was placed in a tomb He rose from the
dead three days later as He said He would. The Holy Bible also tells us
that Jesus Christ ascended into Heaven and that all who accept Him as
their Lord and Saviour will live forever with Him in Heaven where there
is no more death, sorrow, sickness and pain.

The Bible says, "For the wages of sin is death, but the gift of God is
eternal life through Christ Jesus our Lord." (Romans 6:23)

This verse in the Bible says, "For ALL HAVE SINNED, and come short of
the glory of God." (Romans 3:23)

This verse says, "But God demonstrates his own love for us in this:
While we were still sinners, Christ died for us." (Romans 5:8)

In this passage the Bible clearly explains how simple it is to be saved
and on your way to Heaven, "For if you confess with your mouth, "Jesus
is Lord," and believe in your heart that God raised him from the dead,
you WILL BE SAVED." (Romans 10:9)

You can be saved right now and on your way to Heaven if you will open
your heart to Jesus and pray the following prayer out loud: Dear Jesus
Christ, I want to be saved so that I can have a home in Heaven when
this life is over. I agree with You that I am a sinner. I believe You
love me and want to save me. I believe that You bled and died on the
cross to pay the penalty for my sins. I believe that You rose from the
dead. Please forgive my sins and come into my heart and be my Lord and
Saviour. Thank You Lord Jesus Christ for forgiving me and saving me
through Your merciful grace. Amen.

You are now a Christian if you said the prayer and allowed God to save
you. Welcome to the family of God.

Salvation is not a reward but a gift. The Bible says it this way, "For
it is by GRACE you have been SAVED, through FAITH and this not from
yourselves, it is the GIFT of God." (Ephesians 2:8)

Nothing in the world is more important than your eternal destiny.

The Bible says, "In Him(Jesus) we have redemption through His blood,
the forgiveness of sins..."  (Ephesians 1:7)

If you have not yet made a decision to be saved, please do so now
before it is too late. The reason why it is so important to be saved
now is because you do not know exactly when you will die. You may die
prematurely in a traffic accident, terrorist attack or some other way
before you get another chance to be saved.

The Bible tells us that we will spend eternity in Heaven or a place of
eternal torment called Hell. It would be terrible to die and go to Hell
when all you have to do is accept Jesus Christ as your personal Lord
and Saviour.

Some people that have already made Jesus Christ their Lord and Saviour
worry about losing their salvation. The Bible teaches Christians that
we can never lose our salvation no matter what happens.

The Bible says it this way, "My dear children, I write this to you so
that you will not sin. But if anybody does sin, we have one who speaks
to the Father in our defense Jesus Christ, the Righteous One."

Yes my friend, Jesus Christ is able to save you and keep you saved.

Please tell your family and friends, thanks!


Have a great day!
Internet Evangelist R.L. Grossi



1. http://www.biblegateway.com << Free Online Bible

2. http://www.free-hoster.com/goodnews << Passion of the Christ

3. http://www.carm.org/cults/cultlist.htm << Beware Of Cults

4. http://www.equip.org/free/DH198.htm << About Hell
5. http://www.powertochange.com/questions/qna2.html << Is Jesus God?

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


Re: Help on project, anyone?

2005-01-25 Thread Captain Dondo
On Sun, 23 Jan 2005 21:11:32 +0100, Georg Brandl wrote:

> Hello,
> 
> to train my Python skills I am looking for some project I can contribute
> to. I learned Python about one year ago, and had already some
> programming background behind (I contributed to SharpDevelop for
> instance), so I'm not the complete newbie.
> 
> About myself: I'm a 20 year old German with strong interests in
> programming and, of course, especially in Python (I love it...).
> 
> Does anyone run, or participate in, a project looking for fellow
> programmers? I don't have a special area of interest, well, perhaps web
> programming...
> 
> Thanks,
> Georg

Well, if you want to help, I've got a project that has been a python
learning experience for me, and it has *lots* of potential ( read: very
poor code and implementation ;-) ).

Basically, it has to do with managing and playing movies on a computer,
automatically moving them from recent arrivals to archives, keeping track
of how many times each has been played, etc.  I'd like to implement a
simple text-based record for each movie to set up the brightness, volume,
etc.

I also need to write a back end that will generate web pages for the web
interface; something along the lines of album
 but the author is taking album in
a direction that won't work for me anymore.

Email me if interested.

Remvoe the obvious from my email, and include this
kpwq1jkcsEzdx39gnkVvgycd15ayqq anywhere in your email to get through my
spam filters.

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


Re: Tuple slices

2005-01-25 Thread gsakkis

Terry Reedy wrote:
> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Actually my initial motivation was not a huge tuple I had to slice
many
> > times. It was something much
> > less extraordinarily unlikely, a recursive function with a sequence

> > parameter:
> >
> > def foo(sequence):
> ># base_case
> ># do_stuff()
> >combine(foo(sequence[:n]),
> >  foo(sequence[n:]))
> >
> > Having each slice be a view of the original sequence instead of a
fresh
> > copy would be a Good Thing
>
> Why?  To save time? memory?  Either would require more that a few
bytes per
> slice.   If they are, you can probably use virtual slices as follows.
>
> def foo(sequence):
>   def _foo(seq, start, stop)
>  # base_case
>  # do_stuff()
>  combine(_foo(seq, start, n), _foo(seq, n, stop))
>   _foo(sequence, 0, len(sequence)
>
> In other words, if you don't really want slices copied out of the
sequence,
> then don't slice!  Just use 2 ints to indicate the working region or
view.
> Both this and using a nested function with additional params are
standard
> techniques.  This also works when the seq is mutable and you want
changes
> to the 'slice' to change the original, as in quicksort.
>
> Terry J. Reedy


I would say these are standard *C/C++* techniques; slicing simplifies
things and thus seems more 'pythonic' to me.

George

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


Re:Crypto in Python: (Was: What's so funny? WAS Re: rotor replacement)

2005-01-25 Thread Philippe C. Martin
>Now what if acipher and this class could be made from part of the core
>distro? Any application could have the option of encryption with only a
>few lines of code:



Just a bit of info on the subject (which you might already have)


I do not know in which country the python.msi is compiled (Deuchland ?),
but most likely, the county has rules like most other as far as crypto
code in binary format export (especially if distributed as part of a
commercial package): for instance, if you want to export a .exe in
France, you usually have to go through the DCSSI, in the USA, the
BIS . It is a _long_ and tedious process.

Like you I would love to see crypto support built into python but it
_might_ have an impact on its distribution.


Regards,

Philippe



-- 
***
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***

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


Re: is there better 32 clock() timing?

2005-01-25 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, Bengt Richter 
<[EMAIL PROTECTED]> writes
I believe that is quite wrong as a general statement.
Actually my initial statement should have been written
"accessing a resource, the accuracy of which is no better than 10ms.". I 
was thinking of the 1ms multimedia timer but wrote about clock() 
instead.

10ms, coincidentally is the approx minimum scheduling granularity for 
threads unless you are in a multimedia thread (or real time thread - not 
sure about real time threads in NT).

If the "resource" only had ~1ms granularity,
the minimum would be zero, as it is if you call time.time() in a tight loop,
Correct. Write your app in C and call clock(). Thats what you get. You 
can call clock 2 times and still get a delta of zero. The next delta 
(on my system) is 10ms at about 22000 calls.

There are various timers available, documented and undocumented, all of
which end up at 1ms or 1.1ms, give or take. For anything shorter you
Whoops here we go, same typo - should have been 10ms or 11ms. There is a 
1ms timer in the multimedia timing group.

need QueryPerformanceCounter() (but that *is* a slow call), or use the
Have you timed it, to make that claim?
Yes.
What do you mean by "slow"?
Slower than any other Win32, CRT or Undocumented NT function you can use 
to get timer information. Yes, I have timed them all, a few years ago.

QueryPerformanceCounter is 47 times slower to call than clock() on my 
1Ghz Athlon.

QueryPerformanceCounter may have finer granularity, but called in a 
tight loop it'll crush your program.

RDTSC instruction which is fast but gives a count of instruction cycles
executed and is thus not totally accurate (multiple execution pipelines,
plus multithreading considerations).
Accurate for what.
See below - you haven't taken things into account, despite my comment in 
brackets above which gives a big hint.

A single clock AFAIK drives RDTSC
Correct.
The main problem with a CPU clock based reading is that it's very stable unless
there's variable clock rate due to power management.
Try running multiple apps at the same time you are doing your 
measurement, each of which has a variable loading. Each of these apps is 
contributing to the count returned by RDTSC. That is what I was 
referring to.

Stephen
--
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk
RSI Information:http://www.objmedia.demon.co.uk/rsi.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Fuzzyman

Nick Coghlan wrote:
> Fuzzyman wrote:
> > An implementation of the core language semantics - without any
modules
> > or file operations would be dead useful.
> >
> > It could replace some of the function of the long dead rexec
modules as
> > well as support projects like this.
>
> Securing a custom build of the CPython interpreter would probably be
> significantly easier than designing a 'secure mode' that ran on top
of the
> standard version. The former might even be a stepping stone towards
the latter.
>
> Still not easy though (the main task would be to prevent Python code
from
> accessing the OS, while still allowing module imports to work).

Pure python imports only... no C extensions.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
> ---
>  http://boredomandlaziness.skystorm.net

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Orlando Vazquez  <[EMAIL PROTECTED]> wrote:
>Jeff Shannon wrote:
>
>snip
>
>> Because you cannot make Python secure against a malicious (or ignorant) 
>> user -- there's too much flexibility to be able to guard against every 
>> possible way in which user-code could harm the system. Parsing your own 
>> (limited) scripting language allows much better control over what 
>> user-code is capable of doing, and therefore allows (at least some 
>> measure of) security against malicious code.
>
>I don't see how that would equate to something that the original 
>programmer should be concerned about. You could include a bit in your 
>licensing scheme that voids all support on code that has been modified 
>in any way. You shouldn't be obligated and no one expects you to support 
>something the end-user has mucked with.
>
>You could trivially enforce this by keeping checksums of all the system 
>files.
>
>In any case, there's nothing you can really do to "secure" your code. 
>This is true of any language, C, C++, and especially scripting languages 
>like Python. Anyone who has the determination get at and modify the code 
>probably will.
>
>The only time where I can see someone using another language in place of 
>Python for a scripting language is just domain-specific factors, e.g. if 
>you need the extension language to be easily used non-programmers.
.
.
.
I think there's a bit of "talking past" each other.
There's a serious issue here that I suspect Mr. 
Vazquez misunderstood.  I'll try to illustrate:

The original poster wants to work in Python.  That's
fine.  Several of us have suggested he further
expose Python itself to his end-users as an extension
language.  That certainly is feasible.  He needn't
explain all of Python to those end-users--probably 
only a bit about "assignments", control structures,
and maybe lists.  

That approach creates a sort of fragility, though.
Python includes, along with much else, os.unlink().
Suppose our original poster doesn't want end-users
to be able to delete files (or directories ...).
That particular design decision is NOT particularly
apt for a licensing specification, much as I generally
favor trust in the latter; don't-delete-filesystem-
entries is simply too low-level to admit good 
expression in legal language.  More broadly, the 
model of "end-users mucking around" captures the
range of concerns only poorly.

This is a serious issue.

It's also one that brings Tcl, mentioned several
times in this thread, back into focus.  Tcl presents
the notion of "safe interpreter", that is, a sub-
ordinate virtual machine which can interpret only
specific commands.  It's a thrillingly powerful and
correct solution to the main problem Jeff and others
have described.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple slices

2005-01-25 Thread George Sakkis
An iterator is perfectly ok if all you want is to iterate over the
elements of a view, but as you noted, iterators are less flexible than
the underlying sequence. The view should be (or at least appear)
identical in functionality (i.e. public methods) with its underlying
sequence.

George

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


Re: pylibpcap and multiple threads

2005-01-25 Thread Örjan Gustavsson
Hi Carlos,
I looked in the source code for pylibpcap, and it does not release the 
GIL, hence my problem.

I found a solution though, the pcap object has a fileno member so I 
could use select to wait for a packet, then call loop without blocking. 
Problem solved! :)

And since it is only a thin wrapper over the pcap library it (seems to 
be) ok to open multiple instances of pcap, at least so long the 
different istances does select a separate interface. At least it works 
for me now!

And thank you for the link to http://libdnet.sourceforge.net it solved 
my next problem to send raw packets from python.

/Örjan Gustavsson
Carlos Ribeiro wrote:
On Mon, 24 Jan 2005 15:18:39 +0100, Örjan Gustavsson
<[EMAIL PROTECTED]> wrote:
Hi All!
Sorry if this is not the correct forum for this kind of question (I did
not find any pylibpcap related lists).
I am trying to use pylibpcap to capture network traffic from several
ethernet devices at the same time, each nic having a separate thread
assigned to it.
My problem is that when one thread is blocking inside pcap.loop() for
instance, it seems to have acquired the GIL, so that no other threads
can run.
Does anyone know a way to do this with threads, or is the only way to
have separate processes for each NIC?

From the top of my head, and without any test. I did use libpcap for
some stuff recently. loop() is the primitive that keeps reading and
calls the callback, right? I believe that it should release the GIL in
the C wrapper code, right before calling the libpcap loop
implementation, and re-acquire it before calling the callback. There
is a standard way to do it, that is used before blocking calls are
issued (file writing, for example). If it fails to release the GIL it
will block.
I'm also not sure if the libpcap itself is supposed to be used this
way - with multiple instances - but I assume that it should work (I
never tried to open several instances of tcpdump at the same time).
Also, check these links also, as they may be helpful to you:
http://libdnet.sourceforge.net/
http://oss.coresecurity.com/projects/pcapy.html
--
http://mail.python.org/mailman/listinfo/python-list


[perl-python] 20050125 standard modules

2005-01-25 Thread Xah Lee
# -*- coding: utf-8 -*-
# Python

# some venture into standard modules

import os

# print all names exported by the module
print dir(os)

# print the module's online manual
print help(os)
# the above is also available in
# interactive mode in Python terminal

# example of using a function
print 'current dir is:', os.getcwd()

# this prints a list of existing modules
print help('modules')

# referecnce
# http://python.org/doc/2.3.4/tut/node12.html

# in Python terminal, type help() then
# modules
# to get a list
# then a module name to see its doc.

# take a gander of its richness and
# suitability

--
in perl, i don't think there is one way to
list available modules.

one can write a program to find out. Start by
use Data::Dumper; print Dumper [EMAIL PROTECTED];
to see where is the standard modules located,
then search for *.pm files to get an idea.

-
Note: this post is from the Perl-Python a-day mailing list at
http://groups.yahoo.com/group/perl-python/
to subscribe, send an email to perl-python-subscribe @ yahoogroups.com
if you are reading it on a web page, program examples may not run
because html conversion often breaks the code.
Xah
 [EMAIL PROTECTED]
 http://xahlee.org/PageTwo_dir/more.html

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


Skype and Python

2005-01-25 Thread python
Does anyone played with Skype
(http://www.skype.com/ free Internet telephony  )
by using Python?

Lad.

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Roy Smith
Cameron Laird <[EMAIL PROTECTED]> wrote:
>It's also one that brings Tcl, mentioned several
>times in this thread, back into focus.  Tcl presents
>the notion of "safe interpreter", that is, a sub-
>ordinate virtual machine which can interpret only
>specific commands.  It's a thrillingly powerful and
>correct solution to the main problem Jeff and others
>have described.

Yup, we used that feature.  I don't remember the details, but I do
remember that you couldn't open files, and the source command only
allowed access to files in a specific directory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Steven Bethard
Nick Craig-Wood wrote:
Thinking about this some more leads me to believe a general purpose
imerge taking any number of arguments will look neater, eg
def imerge(*generators):
values = [ g.next() for g in generators ]
while True:
x = min(values)
yield x
for i in range(len(values)):
if values[i] == x:
values[i] = generators[i].next()
This kinda looks like it dies after the first generator is exhausted, 
but I'm not certain.  An alternate version that doesn't search for 'i':

py> def imerge(*iterables):
... iters = [iter(i) for i in iterables]
... values = [i.next() for i in iters]
... while iters:
... x, i = min((val, i) for i, val in enumerate(values))
... yield x
... try:
... values[i] = iters[i].next()
... except StopIteration:
... del iters[i]
... del values[i]
... 
py> list(imerge([1, 4, 7], [2, 5, 8], [3, 6, 9]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
py> list(imerge([3, 6, 9], [1, 4, 7], [2, 5, 8]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
py> list(imerge([1, 4, 7], [3, 6, 9], [2, 5, 8]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
This means that this can be further simplified thus,
def hamming():
def _hamming():
yield 1
for n in imerge( imap(lambda h: 2*h, hamming2),
 imap(lambda h: 3*h, hamming3),
 imap(lambda h: 5*h, hamming5) ):
yield n
hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
return result
Nice.
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Carl Banks <[EMAIL PROTECTED]> wrote:
.
.
.
>> Python, or Perl, or TCL, or Ruby, or PHP,
>
>Not PHP.  PHP is one of the better (meaning less terrible) examples of
>what happens when you do this sort of thing, which is not saying a lot.
>PHP was originally not much more than a template engine with some
>crude operations and decision-making ability.  Only its restricted
>problem domain has saved it from the junkheap where it belongs.
>
>TCL isn't that great in this regard, either, as it makes a lot of
>common operations that ought to be very simple terribly unweildy.
.
.
.
I've lost track of the antecedent by the time of our arrival at
"this regard".  I want to make it clear that, while Tcl certainly
is different from C and its imitators, and, in particular, insists
that arithmetic be expressed more verbosely than in most languages,
the cause is quite distinct from the imperfections perceived in 
PHP.  PHP is certainly an instance of "scope creep" in its semantics.
Tcl was designed from the beginning, though, and has budged little in
over a decade in its fundamentals; Tcl simply doesn't bother to "make
a lot of common operations ..." concise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Richie Hindle

[Toby]
> The problem occured because the double-underscore mangling uses the class 
> name, but ignores module names. A related project already had a class named C 
> derived from B  (same name - different module).

Yikes!  A pretty bizarre case, but nasty when it hits.  I guess the
double-underscore system can give you a false sense of security.

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Re: [perl-python] 20050125 standard modules

2005-01-25 Thread Dan Perl
I sent the following feedback message to Yahoo! Groups about this abusive 
use of their service.

Feel free to also report this as an abuse of the Yahoo! Groups service until 
the problem is resolved.

Dan

---
As the owner of the perl-python group, p0lyglut (aka Xah Lee), has added two 
newsgroups to the mailing list of the group: comp.lang.perl.misc and 
comp.lang.python.

First of all, I don't think anyone could have given Xah Lee an authorization 
on behalf of the newsgroups.  I am not sure, but that is probably a 
violation of the Terms of Service in itself.  I will leave this matter up to 
you to investigate.

The daily messages of the perl-python group are unwanted by the two 
newsgroups.  Just take a look at the follow-ups in the newsgroups that the 
perl-python postings have generated.

I hope that not only the newsgroups will be removed from the perl-python 
group but that such an abuse will also be prevented in the future.

Thanks,

Dan Perl 


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


Re: smtplib bug with Windows XP

2005-01-25 Thread [EMAIL PROTECTED]
thank Peter, elbert, for the suggestions.  I hadn't thought of using
telnet to try to connect to the SMTP server.  and when I do try, telnet
can't connect either, at least on port 25.  On port 110, it has no
problem.  So, perhaps the IT people have made some configuration
changes; I'll have a chat with them.  I'm relieved that it's not a
Python problem, though.

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Fuzzyman

Cameron Laird wrote:
[snip..]
> This is a serious issue.
>
> It's also one that brings Tcl, mentioned several
> times in this thread, back into focus.  Tcl presents
> the notion of "safe interpreter", that is, a sub-
> ordinate virtual machine which can interpret only
> specific commands.  It's a thrillingly powerful and
> correct solution to the main problem Jeff and others
> have described.

A better (and of course *vastly* more powerful but unfortunately only a
dream ;-) is a similarly limited python virutal machine.

It could make embedding python a lot simpler for lots of applications
and even 'embedded python' a lot simpler. (Not to mention 'restricted
execution' - e.g. for applets in web pages)

*Perhaps* the pypy core will be a bit like this - but it's design goals
are very different of course.

Anyway, little point in wishing on a dream - I'm certainly not up to
the job :-)
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Installer made with bdist_wininst segfaulting...

2005-01-25 Thread Fernando Perez
Hi Thomas,

Thomas Heller wrote:

> Fernando Perez <[EMAIL PROTECTED]> writes:

>> Here is a brief summary: if the installer file is run from a windows drive
>> which is different from the one where python resides (and hence where
>> ipython will
>> end up), the installer segfaults.  No traceback, nothing, just a segfault
>> (well, one of those Windows dialogs asking me to send a binary traceback to
>> Redmond, but not a proper Python traceback).
> 
> There are a couple of known bugs in bdist_wininst, and you just reported
> another one.  All these bugs are related to using the
> post_install_script, and show up when either (thats what I currently
> remember):

[...]

many thanks for following up on this.  In my case, I realized I could avoid the
chdir() call and things were then OK.  But it's good to see the bug fixed.

Best regards,

f

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Carl Banks

Roy Smith wrote:
> "Carl Banks" <[EMAIL PROTECTED]> wrote:
>
> > > Imbed
> > EMBED.
>
> My apologies for being sloppy.  And with an initial capital, so it
just
> jumps off the page at you :-)

Ok.  Prescriptive language isn't normally my cup of tea, but there's
always something.  And usually it's very silly.

> > > Python, or Perl, or TCL, or Ruby, or PHP,
> >
> > Not PHP.  PHP is one of the better (meaning less terrible) examples
of
> > what happens when you do this sort of thing, which is not saying a
lot.
>
> But, that's exactly my point.  To be honest, I've never used PHP.
But
> however bad it may be, at least it's got a few years of people fixing

> bugs, writing books, writing add-on tools, etc, behind it.  Better to

> use somebody else's well-known and well-supported mess of a scripting

> language than to invest several person-years inventing your own mess
> that's no better.

Well, if you look at it that way, I guess so.

My mindset was closer to "hacked-up quasi-languages are evil" than
"hacked-up quasi-languages are not worth the time to implement when
there are plenty of hacked-up quasi-languages already out there, not to
mention some real languages."


-- 
CARL BANKS

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


ANN: matplotlib-0.71

2005-01-25 Thread John Hunter

matplotlib is a 2D graphics package that produces plots from python
scripts, the python shell, or embeds them in your favorite python GUI
-- wx, gtk, tk, fltk currently supported with qt in the works. Unlike
many python plotting alternatives is written in python, so it is
easy to extend. matplotlib is used in the finance industry, web
application servers, and many scientific and enginneering disciplines.
With a large community of users and developers, matplotlib is
approaching the goal of having a full featured, high quality, 2D
plotting library for python.

  http://matplotlib.sourceforge.net

What's new in matplotlib 0.71

numerix refactor

  The organization of the numerix module was refactored to be mindful
  of namespaces. See http://matplotlib.sf.net/API_CHANGES. pylab no
  longer overrides the built-ins min, max, and sum, and provides amin,
  amax and asum as the numerix/mlab versions of these.  pylab defines
  __all__ to prevent surprises when doing from pylab import *.  To see
  the complete list of symbols provided

>>> import matplotlib.pylab
>>> matplotlib.pylab.__all__

contour zigzag bug fixed

  Thanks Nadia for the blood, sweat and tears, and Dominique for the
  report.

contour colormaps

  Contour now uses the current colormap if colors is not provided, and
  works with colorbars.  See examples/contour_demo2.py

colorbar enhancements

  Horizontal colorbars supported with keyword arg
  orientation='horizontal' and colorbars can be placed in an arbitrary
  axes with keyword arg cax.

accents in mathtext

  Added accents to mathtext: \hat, reve, \grave, ar, cute, ilde, ec,
  \dot, \ddot. All of them have the same syntax, eg to make an overbar
  you do ar{o} or to make an o umlaut you do \ddot{o}. The shortcuts
  are also provided, eg: "o 'e \`e \~n \.x \^y . See
  examples/accent_demo.py

fixed super/subscript parsing in mathtext

  Widowed superscripts now work, eg r'$^12 m{CO}$'

little bugs and enhancements

  Plugged some memory leaks in wx and image module, fixed x,y args in
  contour, added latex symbol kappa, fixed a yticklabel problem under
  change in clim, fixed colorbar number of color bug, fixed
  set_clip_on bug, reverted pythoninspect in tkagg, fixed event
  handling bugs, fixed matlab-compatible load function, exposed vbox
  attr in FigureManagerGTK.


Downloads at http://matplotlib.sourceforge.net

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


Re: Browsing text ; Python the right tool?

2005-01-25 Thread beliavsky
Here is an elementary suggestion. It would not be difficult to write a
Python script to make a csv file from your text files, adding commas at
the appropriate places to separate fields. Then the csv file can be
browsed in Excel (or some other spreadsheet). A0 and C1 records could
be written to separate csv files.

There are Python programs to create Excel spreadsheets, and they could
be used to format the data in more sophisticated ways.

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


Re: Installer made with bdist_wininst segfaulting...

2005-01-25 Thread Fernando Perez
Thomas Heller wrote:

> There are a couple of known bugs in bdist_wininst, and you just reported
> another one.  All these bugs are related to using the
> post_install_script, and show up when either (thats what I currently
> remember):
> 
> - the installer is run from a readonly location,
> - the installer is run from a different drive (as you reported)
> - the installer installs for Python 2.4
> 
> I will fix these issues in Python 2.3.5, which will probably be out as a
> release candidate this week, and in Python 2.4.1.

One more small thing I just remembered...

In my testing, I noticed the installer, even when it succeeds, leaves little
temp files littering the root directory of the drive it was run from.  These
seem to be the files where stdout is captured, but they should be explicitly
removed at the end.

Cheers,

f

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


module for 'po' files

2005-01-25 Thread Sara Fwd
 Hi all
Is there a module for processing & handling  '.po'
files in python?



__ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050125 standard modules

2005-01-25 Thread Dan Perl
I was wrong.  He is just crossposting to the newsgroups without having them 
as members of the group.

I wish there was a good way like that to stop these daily postings!

Dan

"Dan Perl" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I sent the following feedback message to Yahoo! Groups about this abusive 
>use of their service.
>
> Feel free to also report this as an abuse of the Yahoo! Groups service 
> until the problem is resolved.
>
> Dan
>
> ---
> As the owner of the perl-python group, p0lyglut (aka Xah Lee), has added 
> two newsgroups to the mailing list of the group: comp.lang.perl.misc and 
> comp.lang.python.
>
> First of all, I don't think anyone could have given Xah Lee an 
> authorization on behalf of the newsgroups.  I am not sure, but that is 
> probably a violation of the Terms of Service in itself.  I will leave this 
> matter up to you to investigate.
>
> The daily messages of the perl-python group are unwanted by the two 
> newsgroups.  Just take a look at the follow-ups in the newsgroups that the 
> perl-python postings have generated.
>
> I hope that not only the newsgroups will be removed from the perl-python 
> group but that such an abuse will also be prevented in the future.
>
> Thanks,
>
> Dan Perl
> 


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


Help! Host is reluctant to install Python

2005-01-25 Thread Daniel Bickett
I've been trying to convince my host to install python/mod_python on
his server for a while now, however there are a number of reasons he
is reluctant to do so, which I will outline here:

1. His major reason is optimization. He uses Zend's optimization of
PHP as an example, and he has stated that python is rather resource
consuming.
2. Another one of his points is that he is unexperienced in installing
python, and he would not know how to do it securely. By 'securely',
I'm assuming he means disallowing a malicious (or ignorant) user from
harming the server

And, in light of point #1, I suggested that if there wasn't any
optimization immediately available, he could just enable it for my
account (thus lessening potential resource consumption at any given
time), to which he retorted "Do /you/ know how to do that?", and I
must say, he has me cornered ;-)

I have no experience with this sort of thing, so I'm asking a little
assistance in the direction of any documents or websites (or what have
you) I could show him in order to answer some of these questions, or
perhaps even some unspoken ones -- anything worth noting. (all I'm
really going to do is link him to this thread once it has accumulated
any answers)

Thank you all for your help :)

Wishing-to-be-liberated-from-the-clutches-of-PHP-ly y'rs,
Daniel Bickett
-- 
http://mail.python.org/mailman/listinfo/python-list


__deepcopy__ without recursive copies?

2005-01-25 Thread Bernie
#!/usr/bin/env python
import sys
import copy

'''
How to define __deepcopy__ with out causing recursive calls to copies
of self?

Bernie Day 01/25/05

I was using deepcopy on DeviceManager and this worked well.  When I
defined
__deepcopy__, so I could have a handle to the children of the Master
device Manager
I got into trouble.
I see that there is a method using a dic to limit this, but I can't
seem to get it to work.

This is not the code I was using but should represent it well.

Thanks!
'''


class DeviceManager:
def __init__(self,devFile):
DevFile = open(devFile)
devList = [Device(line) for line in DevFile]
#etc, etc...
def __deepcopy__(self):
miniMe = copy.deepcopy(self)
miniMe.devList = tuple(devList)
return miniMe
class Device:
def __init__(self,line):
self.copyies = []
#do something with line here
def __deepcopy__(self):
miniMe = copy.deepcopy(self)
self.copyies.append(miniMe)
return miniMe

DevMan1 = DeviceManager(devfile)
devMan2 = copy.deepcopy(DevMan1)

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


Re: module for 'po' files

2005-01-25 Thread Dennis Benzinger
Sara Fwd wrote:
>  Hi all
> Is there a module for processing & handling  '.po'
> files in python?
> [...]

I don't know if there is a module for processing them, but
Python comes with msgfmt.py (in Tools/i18n) which creates
.mo files out of your .po files.

So read the source and see if there's something in there
which you can use!


Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: I want update one record using ADO,but I can't ,why?

2005-01-25 Thread Robert Brewer
nightmarch wrote:
> I want update one record ,but I can't ,why?
> 
> code like following:
> 
> ##-
> import win32com.client as wc
> 
> def main():
> conn = wc.Dispatch(r'ADODB.Connection')
> rs = wc.Dispatch(r'ADODB.Recordset')
> connStr = "Provider=MSDAORA.1;Password=jmpower;User
> ID=jmpower;Data Source=jmgis_agps3;Persist Security Info=True"
> tblName = r'wjtmp'
> 
> conn.Open(connStr )
> 
> rs.Open( tblName, conn, wc.constants.adOpenKeyset,
> wc.constants.adLockOptimistic )
> 
> if rs.Supports( wc.constants.adUpdate ):
> rs.Fields.Item(0).Value = 11
> rs.Update()
> else:
> print "recordset can't update"
> 
> rs.Close()
> conn.Close()
> 
> if __name__ == '__main__':
> main()
> ##-

You almost give us enough information to help out ,but you don't quite
,why?

What happens when you run the above? Is there any output? Error message?

Does your update affect the membership of the record in the keyset?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/
htm/mdconkeysetcursors.asp

Why are you using keysets at all?


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


Re: [perl-python] 20050125 standard modules

2005-01-25 Thread Peter Nuttall
On Tuesday 25 Jan 2005 17:50, Dan Perl wrote:
> I was wrong.  He is just crossposting to the newsgroups without having
> them as members of the group.
>
> I wish there was a good way like that to stop these daily postings!
>

You can just filter on [perl-python]

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


Re: tkinter socket client ?

2005-01-25 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Tonino" <[EMAIL PROTECTED]> wrote:

>thanks for this info - I had to abandon the createfilehandler() method
>as it is not supported in windows and the GUI "might" be used there at
>some time ...
>
>So - I went the threading route - works well - for now - so I will
>stick to it ...
>
>BUT - the next question:
>In the Text() widget - why - when the text scrolls off the screen -
>does the window not follow it ?
>
>I have added a scrollbar to it :
>
>self.center_frame = Frame(self.top_frame, background="tan",
>relief=RIDGE)
>
>self.text=Text(self.center_frame,background='white')
>scroll=Scrollbar(self.center_frame)
>self.text.configure(yscrollcommand=scroll.set)
>
>self.text.pack(side=LEFT, fill=BOTH, expand=YES)
>scroll.pack(side=RIGHT,fill=Y)
>self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
>
>
>but the window does not scroll to follow the text ?
>Any ideas ?

That's just how it works. But when you append text you can easily tell 
the text widget to display it, e.g. using "see". Here is the code I use 
(from RO.Wdg.LogWdg.py), which has these useful features:
- auto-scrolls only if the user is already scrolled to the of text (so 
if a user is staring at some older data, it won't be jerked out from 
under them)
- deletes excess text.

def addOutput(self, astr, category=None):
"""Add a line of data to the log.

Inputs:
- astr: the string to append. If you want a newline, specify the \n 
yourself.
- category: name of category or None if no category
"""
# set auto-scroll flag true if scrollbar is at end
# there are two cases that indicate auto-scrolling is wanted:
# scrollPos[1] = 1.0: scrolled to end
# scrollPos[1] = scrollPos[0]: window has not yet been painted
scrollPos = self.yscroll.get()
doAutoScroll = scrollPos[1] == 1.0 or scrollPos[0] == scrollPos[1]
if category:
self.text.insert("end", astr, (category,))
else:
self.text.insert("end", astr)
extraLines = int(float(self.text.index("end")) - self.maxLineIndex)
if extraLines > 0:
self.text.delete("1.0", str(extraLines) + ".0")
if doAutoScroll:
self.text.see("end")

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


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Nick Craig-Wood
Steven Bethard <[EMAIL PROTECTED]> wrote:
>  Nick Craig-Wood wrote:
> > Thinking about this some more leads me to believe a general purpose
> > imerge taking any number of arguments will look neater, eg
> > 
> > def imerge(*generators):
> > values = [ g.next() for g in generators ]
> > while True:
> > x = min(values)
> > yield x
> > for i in range(len(values)):
> > if values[i] == x:
> > values[i] = generators[i].next()
> > 
> 
>  This kinda looks like it dies after the first generator is exhausted, 
>  but I'm not certain.

Yes it will stop iterating then (rather like zip() on lists of unequal
size). Not sure what the specification should be!  It works for the
hamming problem though.

>>> list(imerge(iter([1, 2]), iter([1, 2, 3]), iter([1, 2, 3, 4])))
[1, 2]

> An alternate version that doesn't search for 'i':
> 
>  py> def imerge(*iterables):
>  ... iters = [iter(i) for i in iterables]
>  ... values = [i.next() for i in iters]
>  ... while iters:
>  ... x, i = min((val, i) for i, val in enumerate(values))
>  ... yield x
>  ... try:
>  ... values[i] = iters[i].next()
>  ... except StopIteration:
>  ...  del iters[i]
>  ...  del values[i]
>  ...  
>  py> list(imerge([1, 4, 7], [2, 5, 8], [3, 6, 9]))
>  [1, 2, 3, 4, 5, 6, 7, 8, 9]
>  py> list(imerge([3, 6, 9], [1, 4, 7], [2, 5, 8]))
>  [1, 2, 3, 4, 5, 6, 7, 8, 9]
>  py> list(imerge([1, 4, 7], [3, 6, 9], [2, 5, 8]))
>  [1, 2, 3, 4, 5, 6, 7, 8, 9]

This isn't quite right...

>>> list(imerge([1, 2, 3], [1, 2, 3], [1, 2, 3]))
[1, 1, 1, 2, 2, 2, 3, 3, 3]

This should produce
[1, 2, 3]

So I'm afraid the searching *is* necessary - you've got to find all
the generators with the min value and move them on.

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


Re: [perl-python] 20050125 standard modules

2005-01-25 Thread Paul Lalli
"Xah Lee" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
--
> in perl, i don't think there is one way to
> list available modules.
>



I'm torn between knowing that I shouldn't feed trolls, and my hatred of
leaving faulty information about Perl unchecked, where some unsuspecting
newbie might stumble across it.

So to those newbies, you should know that just because this clown
doesn't think there's a way, does not in any way imply that there
actually isn't a way.

For a list of standard modules included in your distribution of Perl,
run the following command in your shell:
perldoc perlmodlib

To get a list of non-standard modules that have already been installed,
read the documentation for the ExtUtils::Installed module:
perldoc ExtUtils::Installed

To see what other modules are available to be downloaded, visit
http://www.cpan.org

Paul Lalli

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


Dr. Dobb's Python-URL! - weekly Python news and links (Jan 23)

2005-01-25 Thread Josiah Carlson
QOTW:  "XML with elementtree is what makes me never have [to] think about
XML again." -- Istvan Albert

"'Plays well with others' was a strong motivator for Python's design, and
that often means playing by others' rules." -- Tim Peters


Type mutability, and why some types are immutable.  This has been
discussed before, and should be a FAQ topic (if it isn't already):

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/f05c9cbb7e58db9b
http://www.python.org/tim_one/000195.html

Caching instances of classes for reuse:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/9178beed046956d2

Storing data in a persistant fashion.  One link discussing concurrency,
the other discussing data storage mechanisms.  A link to PyTables as a
way of storing and indexing large amounts of data, and the announcement
for Dejavu 1.3, which also stores persistant data:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/072e6da39a4e8760

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/7f2849d3099abfdc
http://pytables.sourceforge.net/html/WelcomePage.html

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/01a77dc70a55fc94

So, you want to use SFTP in Python?  Paramiko is the answer (or so I read):

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/e95e8482c023fe25
http://www.lag.net/paramiko/

Circular iteration, or any strange iteration tasks?  Try itertools!

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/42bd800632199d2a

What do PyChecker and Pylint have to do with each other?
Are they configurable?  And do *you* know a half-dozen 
distinct formats for printing a multi-line text?

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2ff633d4474e52e7/

Jeremy Bowers and Dan Stromberg know that some applications
should do the right thing, whether they happen to have a
bit-mapped user interface at run time or not:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/9ff27f0e5fea2045/

The Bangalore Python Meetup first convened on 22 January 2005:
http://python.meetup.com/158/events/?eventId=3974233&action=pastdetail

Why generator expressions sometimes don't beat list comprehensions, and
fitting Python to requirements.  Let not the anti-functional fashion
obscure that filter() still sometimes makes for better coding than the
comparable list comprehension:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/0155347dab27026d

http://groups-beta.google.com/group/comp.lang.python/msg/b15bab678ad9b2dc

Security is hard.  Even the narrow aspect of cryptography is
hard, if only for the complication state politics makes of the
mathematics and engineering involved.  Paul Rubin, Nick Craig-
Wood, and others present a few details:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/fcf8b0764d369cfa

No, really--Python does *that*, too.  Although many people
regard hardware interfacing, and its associated bit-twiddling,
as outside Python's purview, they're ... wrong.  See for 
yourself how Python makes for *clearer* codings than C or
Java or Assembler or ...:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/ea293235bef39473/


Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects refe

Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Steven Bethard
Nick Craig-Wood wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
Nick Craig-Wood wrote:
Thinking about this some more leads me to believe a general purpose
imerge taking any number of arguments will look neater, eg
def imerge(*generators):
   values = [ g.next() for g in generators ]
   while True:
   x = min(values)
   yield x
   for i in range(len(values)):
   if values[i] == x:
   values[i] = generators[i].next()
This kinda looks like it dies after the first generator is exhausted, 
but I'm not certain.

Yes it will stop iterating then (rather like zip() on lists of unequal
size). Not sure what the specification should be!  It works for the
hamming problem though.
Actually, it stops iterating on lists of equal size too:
py> def imerge(*iterators):
... iterators = [iter(i) for i in iterators]
... values = [i.next() for i in iterators]
... while True:
... x = min(values)
... yield x
... for i, val in enumerate(values):
... if val == x:
... values[i] = iterators[i].next()
...
py> list(imerge([1, 4, 7], [2, 5, 8], [3, 6, 9]))
[1, 2, 3, 4, 5, 6, 7]
Note that 8 and 9 are not in the list.
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: specifying constants for a function (WAS: generator expressions: performance anomaly?)

2005-01-25 Thread Steven Bethard
Bengt Richter wrote:
On Mon, 24 Jan 2005 20:35:09 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote:
from presets import presets, curry
@presets(verbose=True, a=1, b=2, deftime=__import__('time').ctime())
... def foo():
...print (a, b)
...print deftime
...
presets: -- "name(?)" means name may be unused
  a = 1
  b = 2
deftime = 'Mon Jan 24 12:16:07 2005'

foo()
(1, 2)
Mon Jan 24 12:16:07 2005
Not much reaction
Sorry, it's definitely cool -- I was just waiting for you to post the 
Cookbook link so I could see how you did it. ;)

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


Re: Import from database

2005-01-25 Thread Steve Holden
Kartic wrote:
Steve,
I believe you have to put ntpath, macpath and posixpath in the module
database for os.path to work.
I tried it with zipimporter builtin and I got the same traceback till I
added ntpath.py to my zip file. (Of course, I renamed the original
ntpath to _ntpath so that the original did not get imported)
Thanks,
--Kartic
I'm not sure I understand, as I am currently relying on the system 
implementations of any modules that happen to be loaded before my code 
picks up. As to what's in the database

SELECT *
FROM `module`
WHERE modName LIKE '%path%'
shows that I have macpathm macurlpath, ntpath, nturlpath, os2emxpath and 
posixpath all there (but, as I say, I've already executed the standard 
modules by the time anything of mine gets to run). If I alter my test 
program to:

import dbimp, sys
if __name__ == "__main__":
dbimp.install()
k = sys.modules.keys()
k.sort()
for kk in k:
print kk
#import bsddb.db
import a.b.c.d
import bsddb
then I get as output
MySQLdb
MySQLdb.MySQLdb
 ...
MySQLdb.types
UserDict
__builtin__
__main__
_codecs
_locale
_mysql
_mysql_exceptions
_sre
array
cPickle
codecs
copy
copy_reg
db
dbimp
 ...
mx.Misc
mx.Misc.LazyModule
new
nt
ntpath
os
os.path
re
 ...
zipimport
Accepted *db*
found a in db
load_module: a
a loaded:  pkg: 1
found a.b in db
load_module: a.b
a.b loaded:  pkg: 1
found a.b.c in db
load_module: a.b.c
a.b.c loaded:  pkg: 1
found a.b.c.d in db
load_module: a.b.c.d
a.b.c.d loaded:  pkg: 0
found bsddb in db
load_module: bsddb
found weakref in db
load_module: weakref
weakref loaded:  pkg: 0
Traceback (most recent call last):
  File "test.py", line 11, in ?
import bsddb
  File "/c/steve/Projects/Python/dbimp/dbimp.py", line 49, in load_module
exec code in module.__dict__
  File "db:bsddb", line 62, in ?
  File "/usr/lib/python2.4/os.py", line 133, in ?
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, 
altsep,
ImportError: No module named path

In other words, the os module is /already/ in sys.smodules, as is 
os.path, yet the interpreter is complaining (I presume) that os.path is 
not a module. I don't even know *why* os is being executed a second 
time. I can only assume it's being imported as some other name like 
"bsddb.os" and some element of the import system is actually doing an 
import rather than refusing to guess.

I presume I need to control the import process more closely to make sure 
that this import attempt is rejected, but I can't see how to do that.

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


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Michael Spencer
Nick Craig-Wood wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
Nick Craig-Wood wrote:
Thinking about this some more leads me to believe a general purpose
imerge taking any number of arguments will look neater, eg
def imerge(*generators):
   values = [ g.next() for g in generators ]
   while True:
   x = min(values)
   yield x
   for i in range(len(values)):
   if values[i] == x:
   values[i] = generators[i].next()
This kinda looks like it dies after the first generator is exhausted, 
but I'm not certain.

Yes it will stop iterating then (rather like zip() on lists of unequal
size). Not sure what the specification should be!  It works for the
hamming problem though.

list(imerge(iter([1, 2]), iter([1, 2, 3]), iter([1, 2, 3, 4])))
[1, 2]

An alternate version that doesn't search for 'i':
py> def imerge(*iterables):
... iters = [iter(i) for i in iterables]
... values = [i.next() for i in iters]
... while iters:
... x, i = min((val, i) for i, val in enumerate(values))
... yield x
... try:
... values[i] = iters[i].next()
... except StopIteration:
... del iters[i]
... del values[i]
... 
py> list(imerge([1, 4, 7], [2, 5, 8], [3, 6, 9]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
py> list(imerge([3, 6, 9], [1, 4, 7], [2, 5, 8]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
py> list(imerge([1, 4, 7], [3, 6, 9], [2, 5, 8]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]

This isn't quite right...

list(imerge([1, 2, 3], [1, 2, 3], [1, 2, 3]))
[1, 1, 1, 2, 2, 2, 3, 3, 3]
This should produce
[1, 2, 3]
So I'm afraid the searching *is* necessary - you've got to find all
the generators with the min value and move them on.
Here's a dict-based implementation: cute, but slow, at least for a small number 
of iterators

 >>> def imerge(*iterables):
 ... cache = {}
 ... iterators = map(iter,iterables)
 ... number = len(iterables)
 ... exhausted = 0
 ... while 1:
 ... for it in iterators:
 ... try:
 ... cache.setdefault(it.next(),[]).append(it)
 ... except StopIteration:
 ... exhausted += 1
 ... if exhausted == number:
 ... raise StopIteration
 ... val = min(cache)
 ... iterators = cache.pop(val)
 ... yield val
 >>> list(imerge([1, 2, 3, 6], [1, 2, 3, 7], [1, 2, 3, 4, 5]))
[1, 2, 3, 4, 5, 6, 7]
 >>>
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Steven Bethard
Toby Dickenson wrote:
I have a counterexample. Consider refactoring a class from
class B(A):
etc
into
class C(A):
etc
class B(C):
etc
Usage of some double-undescore attributes moved from B to the new intermediate 
base class C. Unit tests on B still passed, so that change is safe. right?

The problem occured because the double-underscore mangling uses the class 
name, but ignores module names. A related project already had a class named C 
derived from B  (same name - different module). My refactoring caused 
aliasing of some originally distinct double-underscore attributes.
Very interesting.  I hadn't ever really thought about it, but I guess 
this shows that even __-mangling won't solve all of the 
attribute-renaming problems...

A somewhat related problem is briefly discussed in Guido's autosuper 
example:
http://www.python.org/2.2.3/descrintro.html#metaclass_examples
where a base class derived from a class using autosuper but with the 
same name as the superclass might get the wrong self.__super.

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


Re: Help! Host is reluctant to install Python

2005-01-25 Thread fuzzylollipop
find a new host, if they can't handle simple tasks like this or simple
security tasks like limiting permissions, how can you be sure anything
else they do is secure or correct?

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


limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-25 Thread Steven Bethard
Fuzzyman wrote:
> Cameron Laird wrote:
> [snip..]
>
>>This is a serious issue.
>>
>>It's also one that brings Tcl, mentioned several
>>times in this thread, back into focus.  Tcl presents
>>the notion of "safe interpreter", that is, a sub-
>>ordinate virtual machine which can interpret only
>>specific commands.  It's a thrillingly powerful and
>>correct solution to the main problem Jeff and others
>>have described.
>
> A better (and of course *vastly* more powerful but unfortunately only
> a dream ;-) is a similarly limited python virutal machine.
Yeah, I think there are a lot of people out there who would like 
something like this, but it's not quite clear how to go about it.  If 
you search Google Groups, there are a lot of examples of how you can use 
Python's object introspection to retrieve "unsafe" functions.

I wish there was a way to, say, exec something with no builtins and with 
import disabled, so you would have to specify all the available 
bindings, e.g.:

exec user_code in dict(ClassA=ClassA, ClassB=ClassB)
but I suspect that even this wouldn't really solve the problem, because 
you can do things like:

py> class ClassA(object):
... pass
...
py> object, = ClassA.__bases__
py> object

py> int = object.__subclasses__()[2]
py> int

so you can retrieve a lot of the builtins.  I don't know how to retrieve 
 __import__ this way, but as soon as you figure that out, you can then 
do pretty much anything you want to.

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


Re: module for 'po' files

2005-01-25 Thread vincent wehren
Sara Fwd wrote:
 Hi all
Is there a module for processing & handling  '.po'
files in python?
Don't know exactly what you mean by "processing & handling". What do you 
want to do?

--
Vincent Wehren



		
__ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 
--
http://mail.python.org/mailman/listinfo/python-list


Re: add indexes on the fly to lists

2005-01-25 Thread Do Re Mi chel La Si Do
Hi !

If you want only "search and found" element, look dictionnary ; if you want
also to have the order, see the module set.

Good night
-- 
Michel Claveau


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


Re: Help! Host is reluctant to install Python

2005-01-25 Thread Thomas Bartkus
"Daniel Bickett" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I've been trying to convince my host to install python/mod_python on
> his server for a while now, however there are a number of reasons he
> is reluctant to do so, which I will outline here:


I'll second what you are already hearing.
Find a new hosting service because the one you have now is not qualified.

Thomas Bartkus


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


How to input one char at a time from stdin?

2005-01-25 Thread Brent W. Hughes
I'd like to get a character from stdin, perform some action, get another 
character, etc.  If I just use stdin.read(1), it waits until I finish typing 
a whole line before I can get the first character.  How do I deal with this?

Brent


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


Re: Classical FP problem in python : Hamming problem

2005-01-25 Thread Jeff Shannon
Bengt Richter wrote:
On 25 Jan 2005 08:30:03 GMT, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
If you are after readability, you might prefer this...
def hamming():
def _hamming():
  yield 1
  for n in imerge(imap(lambda h: 2*h, iter(hamming2)),
  imerge(imap(lambda h: 3*h, iter(hamming3)),
 imap(lambda h: 5*h, iter(hamming5:
yield n
hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
return result
Are the long words really that helpful?
def hamming():
  def _hamming():
yield 1
for n in imerge(imap(lambda h: 2*h, iter(hg2)),
imerge(imap(lambda h: 3*h, iter(hg3)),
   imap(lambda h: 5*h, iter(hg5:
  yield n
  hg2, hg3, hg5, result = tee(_hamming(), 4) # four hamming generators
  return result
Well, judging by the fact that shortening the identifiers made it so 
that you felt the need to add a comment indicating what they were 
identifying, I'd say that yes, the long words *are* helpful.  ;) 
Comments are good, but self-documenting code is even better.

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to input one char at a time from stdin?

2005-01-25 Thread Swaroop C H
On Tue, 25 Jan 2005 12:38:13 -0700, Brent W. Hughes
<[EMAIL PROTECTED]> wrote:
> I'd like to get a character from stdin, perform some action, get another
> character, etc.  If I just use stdin.read(1), it waits until I finish typing
> a whole line before I can get the first character.  How do I deal with this?

This is exactly what you need:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
Title: "getch()-like unbuffered character reading from stdin on both
Windows and Unix"

This recipe was a lifesaver for me once :-)

Regards,
-- 
Swaroop C H
Blog: http://www.swaroopch.info
Book: http://www.byteofpython.info
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Rocco Moretti
Bob Smith wrote:
Rocco Moretti wrote:
Python's also dangerous. Every time you do an "import module", you put 
your system at risk of crashing, having the hard-drive wiped
Have you been drinking again?
No, not really. The "every time" comment should be viewed in the same 
light as "Every time you step outside, you risk being hit by a bus."

"import module" executes Python code. As such it can do anything Python 
can do. Crash your system, wipe the hard drive, etc. And there is 
nothing the importing code can do to stop it. Now, if you limit yourself 
to known and trusted modules, that risk virtually disappears, just like 
staying on the sidewalk virtually eliminates the chances of getting hit 
by a bus. Not completely, mind you, since someone could have altered the 
standard library modules/changed the import path such that you're 
importing an unknown module. But most people would argue if someone has 
that power, they probably can do anything they want with your system 
without you doing "import module."

Bottom line: Don't exec or eval untrusted code. Don't import untrusted 
modules.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Rocco Moretti
Orlando Vazquez wrote:
Jeff Shannon wrote:
Because you cannot make Python secure against a malicious (or 
ignorant) user -- there's too much flexibility to be able to guard 
against every possible way in which user-code could harm the system. 
Parsing your own (limited) scripting language allows much better 
control over what user-code is capable of doing, and therefore allows 
(at least some measure of) security against malicious code.
I don't see how that would equate to something that the original 
programmer should be concerned about. You could include a bit in your 
licensing scheme that voids all support on code that has been modified 
in any way. You shouldn't be obligated and no one expects you to support 
something the end-user has mucked with.

You could trivially enforce this by keeping checksums of all the system 
files.
You're thinking of two different situations. My guess is that Jeff 
Shannon is not referring to situations where the end user makes 
modifications to existing code, but rather, where the end user write 
*completely new* scripts in your new scripting language. As such, you 
can't enforce checksums - the code hasn't been written yet.

The use cases probably are also different. You're thinking of delivering 
a completed application to an end-user's machine, but given the OP's 
user name ("Quest Master"), my guess is that he's looking for a 
server-side deployment like in an on-line game, where users script the 
game environment. Not only do you have a problem with a malicious user 
potentially crashing the game machine, but you also have issues where 
the user may be able to grab his "character object" and give himself 
infinite money or life, or whatever. Since it's a shared server, you 
can't just say "I'm not supporting it" when someone mucks with the server.

> In any case, there's nothing you can really do to "secure" your code.
> This is true of any language, C, C++, and especially scripting languages
> like Python. Anyone who has the determination get at and modify the code
> probably will.
Well, if you don't provide mechanisms for disk access, there is no way 
to overwrite files, short of a bug in the interpreter (or some extension 
interface to a general purpose programing language). Python is just to 
flexible to work like that. Even if you don't provide an open function 
to user code, and eliminate questionable modules, you can still get a 
file object, even if all you are provided with is an integer object. 
That's why restricted execution was eliminated from the standard library.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Terry Reedy

"Cameron Laird" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> The original poster wants to work in Python.  That's
> fine.  Several of us have suggested he further
> expose Python itself to his end-users as an extension
> language.  That certainly is feasible.  He needn't
> explain all of Python to those end-users--probably
> only a bit about "assignments", control structures,
> and maybe lists.
>
> That approach creates a sort of fragility, though.
> Python includes, along with much else, os.unlink().
> Suppose our original poster doesn't want end-users
> to be able to delete files (or directories ...).

I don't remember if the OP specified *where* the scripted application is to 
be run.  If on a server, then *any* language with loops is vulnerable to 
malicious users.  If on a person's own desktop machine, where one can run 
'diskformat' or the equivalent, or pick up and drop the machine, then 
worrying about Python security seems superfluous.  Why worry, for instance, 
about os.unlink when the user can just do the same much easier in a text or 
gui shell?

Terry J. Reedy



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


  1   2   3   >