Re: lies about OOP

2004-12-15 Thread Fredrik Lundh
Mike Meyer wrote:

>> If OOP is so beneficial for large projects, why are the Linux kernel,
>> the interpreters for Perl and Python, and most compilers I know written
>> in C rather than C++?
>
> Because C++ combines the worst features of C and OO programming. It
> also makes some defaults go the wrong way, and forces decisions onto
> the programmer that are best left up to the compiler, as the
> programmer is liable to get them wrong.

that's a nice rant about C++, but it's not the right answer to the question.  
the
Python core developers are perfectly capable of writing working C++ code,
and both the core and most extensions would benefit from C++ features (just
look at Boost and other C++ layers).

but C++ wasn't a serious contender back when CPython development was
started, and nobody's going to convert the existing codebase...

 



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


Re: thread/queue bug

2004-12-15 Thread Antoon Pardon
Op 2004-12-14, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Op 2004-12-13, Tim Peters schreef <[EMAIL PROTECTED]>:
>> 
>>>[Antoon Pardon]
>>>
I don't see why starting a thread as a side effect of importing is
bad thread practice. Sure python doesn't cater for it, but IMO
that seems to be python failing.
>>>
>>>Obviously, it's bad practice in Python because it can lead to
>>>deadlocks in Python.
>> 
>> 
>> By that argument any use of locks is bad practice because it
>> can lead to deadlock.
>> 
> Not at all. You mentioned locks, not Tim.

That is beside the point. The argument was that starting a thread
as a side effect of importing is bad practice because it can lead to
deadlock. This suggest that a general condition for something
to be bad practice is if that something can lead to deadlock.
Locks are in that case.

>>>It's nearly tautological.  Import is an
>>>executable statement in Python, not, e.g., as in many other languages,
>>>a declaration directed at the system linker.  With that power comes
>>>opportunities to shoot yourself, although they're generally easy to
>>>avoid.  Come up with a practical design that doesn't have this
>>>limitation, and then perhaps your characterization of the current
>>>design as "a failing" would be both credible and constructive.
>> 
>> 
>> If a car model has cranky brakes, I think I can call that a failing
>> even without having the ability to come up with a pratical design
>> that doesn's has those limitations.
>> 
> But in fact your situation is more closely analogous to a customer who's 
> bought a car that can be stopped by pressing on the brake pedal now 
> complaining that sideways pressure on the brake pedal doesn;t affect the 
> car's motion.

You will have to explain how you come by that analogy.

>> I judge a language by what it can and cannot do, not by my ability
>> to correct the things I perceive as failings. For all I know python
>> may have taken some design decisions that might have seen perfectly
>> logical but now prohibit a a practical design that doesn't have this
>> limitation. I don't see why something like that would make this
>> any less a failing then when a practical design was easy in the
>> current implemenation.
>> 
> All that Tim was suggesting is that it's MORE SENSIBLE to start a thread 
> as the result of a specific call to programmed functionality rather than 
> as the side effect of an import. The reason for this is due to the 
> semantics of the import statement. If you perceive that as a failing 
> then you'd be better rewarded by an attempt to modify your perceptions.

> I've always found "don't argue with Tim about Python" to be a useful 
> rule of thumb. He's wrong much less often than I am. I suspect he's also 
> wrong much less often than you ;-)

With all respect I find that lousy advise. I don't mind that it will turn
out I'll be wrong most of the time. But I'll probably will have gained
a better understanding by the responses to my argument than by merely
accepting the word of Tim.

[ ... ]

>>>Note that the OP's example had a module that, upon the first attempt
>>>to import it, ran an infinite loop (even if it hadn't deadlocked), and
>>>it's clearly severe abuse of import's purpose.to write a module M such
>>>that "import M" *never* returns.  Indeed, that's the other half of how
>>>deadlock occurs:  not only that the imported module spawn a thread as
>>>a side effect of importing, but also that the imported module refuse
>>>to allow the import to complete.
>> 
>> 
>> Well I'll agree here. An import that has as a side effect that the
>> import doesn't return is bad practice.
>> 
> But that's precisely the risk you run when starting up threads!

Now you are confusing me. Is it a problem of an import that doesn't
return of is it a case of a race condition where the import has to
return in a timely fashion?

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


Re: RegEx: find all occurances of a single character in a string

2004-12-15 Thread Franz Steinhaeusler
On Tue, 14 Dec 2004 14:05:38 +0100, Franz Steinhaeusler
<[EMAIL PROTECTED]> wrote:

>given a string:
>
>st="abcdatraataza"
>^   ^ ^ ^ (these should be found)
>I want to get the positions of all single 'a' characters.
>(Without another 'a' neighbour)
>[...]

Thank you again, Pádraig and Steve,
your solution looks still more compact.

There are several regular expression, that this could 
almost justify an own newsgroup.

Or is there another group, where these questions are more
appropriate?

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


Re: Help need with converting Hex string to IEEE format float

2004-12-15 Thread TZOTZIOY
On Tue, 14 Dec 2004 16:57:02 +0100, rumours say that "Fredrik Lundh"
<[EMAIL PROTECTED]> might have written:

>how about:
>
># convert to byte string
>import struct
>s = "".join([chr(int(c, 16)) for c in x])
>v = struct.unpack("!f", s)

I think that the third line in the snippet above could also be:

s = "".join(x).decode("hex")

I am not sure I remember in which version of Python the hex codec was
added, but it is handy.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-15 Thread Gerrit


binL9yPfo4Fv5.bin
Description: application/pgp-encrypted


msg.asc
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: while 1 vs while True

2004-12-15 Thread Nick Coghlan
Paul Rubin wrote:
Nick Coghlan <[EMAIL PROTECTED]> writes:
Until this code:
.>>> import pdb
.>>> pdb.True = 0
.>>> pdb.x = "Darn writeable module dictionaries"
.>>> from pdb import True
.>>> True
0
.>>> from pdb import x
.>>> x
'Darn writeable module dictionaries'

If Python really does behave that way, that bug should be fixed immediately.
I tried it out in the 2.4 interpreter before posting it - it certainly does 
behave that way.

And some test frameworks do make use of the capability to inject behaviour into 
the module under test (e.g. the one mentioned here: 
http://mail.python.org/pipermail/python-list/2003-April/156301.html).

This is behaviour which has been around for a while - and breaking such expected 
behaviour gratuitously isn't acceptable.

PEP 267 discusses a way of speeding access to globals/builtins without giving up 
the external binding of names.

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


Re: logging in omniORB for python

2004-12-15 Thread f
Birgit Rahm wrote:
Hello newsgroup,
Hello Birgit,
I haven't found any way to do logging in a standard way.
The solution i've implemented is to decorate each method you want to log 
the call, using the logging module (included in python since 2.3)

For example :
import logging
def loggedmethod(method):
logger = logging.getLogger('mylogger')
def _loggedmethod(self, *args, **kw):
logger.debug('## %s was called ##' % method.func_name)
return method(self, *args, **kw)
return _loggedmethod
# imagine A is your corba object
class A:
def foo(self):
return 'foo'
foo = loggedmethod(foo)
if __name__ == '__main__':
logger = logging.getLogger("mylogger")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
a = A()
print a.foo()

when running :
bash-2.05b$ python plop.py
## foo was called ##
foo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-15 Thread Antoon Pardon
Op 2004-12-13, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> "jfj" wrote:
>
>> Why can't we __setitem__ for tuples?
>
> http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types
>
>> The way I see it is that if we enable __setitem__ for tuples there
>> doesn't seem to be any performance penalty if the users don't use it
>> (aka, python performance independent of tuple mutability).
>
> how would you implement a dictionary where the keys could change, without
> any performance penalty compared to the current implementation?

The performace gained by using tuples as keys in dictionaries is
entirely illusional.

Sure the fact that you use a tuple which is immutable, makes that
you can put the key directly in the dictionary instead of a copy
and that will gain you some performance.

But this performance gain can be more than offset by other code
in the program.

Suppose you need a list/tuple as a key and most opperation you
will do on those keys will be appends and pops. You now have the
itwo choices

  1) Always convert your lists to tuples on key entries
  and keys accesses, which will mean more copying than when a 
  copy of a key would have been made on key entry.

  2) Simulate appends and pops by tuple operations which can also
  require more copying than was gained by using tuples as key.


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


Re: RegEx: find all occurances of a single character in a string

2004-12-15 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> r=re.compile("a+")
> [m.start() for m in r.finditer(s) if len(m.group()) == 1]
>
< Mine runs 100K iterations of 'abcdatraataza','a' in 1.4s
> whereas Fredrik's does the same in 1.9s

sure, but how long did it take you to come up with a working RE?  and how
many casual RE users will understand what the heck that RE is doing?

(insert obligatory remark about premature optimization, etc).

 



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


Re: Why are tuples immutable?

2004-12-15 Thread Fuzzyman
Wasn't part of the point, that function call returns ought to be
immuntable. Otherwise you can accidentally end up modifying objects
that are referenced in other places ?

Obviously tuples aren't the *whole* answer... but they help.

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


ANN: Python Test Environment

2004-12-15 Thread Fuzzyman
Well sort of... Highly experimental - I'm interested in ways of
improving this.

http://www.voidspace.org.uk/atlantibots/pythonutils.html#testenv

I've created a script that will build a 'test environment'. Windoze(tm)
only as it uses py2exe.

It scans your Python\Lib folder (configurable) and builds a script that
*fakes* an import of every module (along with some boilerplate). This,
more or less, amounts to everything in the standard lib. There is then
a normal setup.py to turn this into a python executable.

The result is an executable that will run any python script. It gives
sensible values for sys.path, sys.argv and __file__.

This is useful for various purposes :

1) Easily have test environments for multiple versions of python - to
test your scripts.
2) Run any python script on a machine without python installed.
3) Deploying several scripts using py2exe - one build fits all.

Usage :

testenv  arg1 arg2...

Which should be the equivalent of :
python  arg1 arg2...


Sample output :
(Built with Python 2.4 - then 2.3 - prints sys.version first)




D:\New Folder\testenv>testenv test.py arg1 arg2 arg3
2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]

sys.path = ['D:\\New Folder\\testenv\\library.zip', 'D:\\New
Folder\\testenv', '
D:\\New Folder\\testenv']

sys.argv = ['D:\\New Folder\\testenv\\test.py', 'arg1', 'arg2', 'arg3']

import Tkinter # succeeded

import dummylibrary # succeeded

D:\New Folder\testenv>


##

D:\Python Projects\modules in progress\py2exe-testenv\dist>testenv
test.py arg1
arg2
2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]

sys.path = ['D:\\Python Projects\\modules in
progress\\py2exe-testenv\\dist\\lib
\\shared.zip', 'D:\\Python Projects\\modules in
progress\\py2exe-testenv\\dist',
'D:\\Python Projects\\modules in progress\\py2exe-testenv\\dist']

sys.argv = ['D:\\Python Projects\\modules in
progress\\py2exe-testenv\\dist\\tes
t.py', 'arg1', 'arg2']

import Tkinter # succeeded

import dummylibrary # succeeded

D:\Python Projects\modules in progress\py2exe-testenv\dist>

~~~

I'm sure this can be improved in lots of ways. Comments and suggestions
for improvements welcomed. Thanks already to Bruno Thooreens for his
help. 

Regards,


Fuzzy

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


Thanks (Re: gather information from various files efficiently)

2004-12-15 Thread Klaus Neuner
Hello,

(Sorry for beginning a new thread. Google does not allow me to reply
to my own posting. And I cannot use a newsreader at the moment.)

Thanks to all who participated in the thread.

I tried the try- and the if-solution. The setdefault-solution didn't
work in my program.

With the try-solution the process took 37 seconds. With the
if-solution the process took so much time that I didn't bother to
wait.

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


import wx

2004-12-15 Thread km
Hi all,

Has anyone tried building wxPython-2.5.3 with python2.4 ? after building and 
setting paths stuff, i have trouble importing wx - the error says :
"ImportError : No module named _core_"
can someone shed light on this ? 
regards,
KM

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


Re: lies about OOP

2004-12-15 Thread Martijn Faassen
Paul McGuire wrote:
"Martijn Faassen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Paul McGuire wrote:
[snip]
I would characterize the 80's as the transitional decade from structured
programming (which really started to hit its stride when Djikstra
published
"Use of GOTO Considered Harmful") to OOP, and that OOP wasn't really
"joyful" until the early-to-mid 90's.
IMMEDIATE NOTICE TO ALL PYTHON SECRET UNDERGROUND MEMBERS.
Classified. Any disclosure to non-PSU members prohibited. Offenders will
be apprehended and removed from the time stream, permanently.
 


Yikes!  (or better, "Jikes!" or even "Yijkes!"?) - my bad.
And he was on faculty at UT right here in Austin, too.
It's a very common mistake I've seen so often that for a while I 
wondered whether his name really *was* Djikstra, but I knew he was Dutch 
and that it couldn't be so. That the PSU picked you for its disclosure 
is just a random coincidence, I'm sure.. :)

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


Re: Why are tuples immutable?

2004-12-15 Thread Fredrik Lundh
Antoon Pardon wrote:

>> how would you implement a dictionary where the keys could change, without
>> any performance penalty compared to the current implementation?
>
> The performace gained by using tuples as keys in dictionaries is
> entirely illusional.
>
> Sure the fact that you use a tuple which is immutable, makes that
> you can put the key directly in the dictionary instead of a copy
> and that will gain you some performance.
>
> But this performance gain can be more than offset by other code
> in the program.
>
> Suppose you need a list/tuple as a key and most opperation you
> will do on those keys will be appends and pops. You now have the
> itwo choices
>
>   1) Always convert your lists to tuples on key entries
>   and keys accesses, which will mean more copying than when a
>   copy of a key would have been made on key entry.
>
>   2) Simulate appends and pops by tuple operations which can also
>   require more copying than was gained by using tuples as key

sorry, but I don't understand your reply at all.  are you saying that 
dictionaries
could support mutable keys (e.g lists) by making a copy of the key?  how would
such a dictionary pick up changes to the original key object?  (I'm talking 
about
the key stored in the dictionary, not the key you're using to look things up).

 



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


Re: do you master list comprehensions?

2004-12-15 Thread Nick Coghlan
Will Stuyvesant wrote:
Here is a question about list comprehensions [lc].  The
question is dumb because I can do without [lc]; but I am
posing the question because I am curious.
This:

data = [['foo','bar','baz'],['my','your'],['holy','grail']]
result = []
for d in data:
... for w in d:
...result.append(w)
print result
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']
puts all the words in a list, like I want.
There's a way to avoid generating the intermediate list if you don't actually 
need it (e.g. you want to feed the sequence to another method):

.>>> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
.>>> from itertools import chain
.>>> result = "".join(chain(*data))
'foobarbazmyyourholygrail'
Some timing with integers:
C:\>python -m timeit -s "data = [range(x) for x in range(1000)]" "L= []; map(L.e
xtend, data); max(L)"
10 loops, best of 3: 78.5 msec per loop
C:\>python -m timeit -s "data = [range(x) for x in range(1000)]; from Tkinter im
port _flatten" "max(_flatten(data))"
10 loops, best of 3: 58.4 msec per loop
C:\>python -m timeit -s "data = [range(x) for x in range(1000)]; from itertools
import chain" "max(chain(*data))"
10 loops, best of 3: 43 msec per loop
And with strings:
C:\>python -m timeit -s "data = [map(str, range(x)) for x in range(1000)]" "L= [
]; map(L.extend, data); ''.join(L)"
10 loops, best of 3: 106 msec per loop
C:\>python -m timeit -s "data = [map(str, range(x)) for x in range(1000)]; from
Tkinter import _flatten" "''.join(_flatten(data))"
10 loops, best of 3: 85.4 msec per loop
C:\>python -m timeit -s "data = [map(str, range(x)) for x in range(1000)]; from
itertools import chain" "''.join(chain(*data))"
10 loops, best of 3: 1.2 sec per loop ** OUCH!!
C:\>python -m timeit -s "data = [map(str, range(x)) for x in range(1000)]; from
itertools import chain" "''.join(list(chain(*data)))"
10 loops, best of 3: 107 msec per loop
Yikes - looks like chain() really sucks for str.join. However, the addition of 
the 'list' call makes a big difference. Maybe PySequence_Fast should be called 
PySequence_SlowAsADeadDingo() in this case ;)

(FYI, I filed bug report #1085744 on SF about this)
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: jython and concatenation of strings

2004-12-15 Thread Nick Coghlan
Jan Gregor wrote:
StringBuffer class from java was right solution - yours looses encoding,
and in jython I was unable to get it back - in python it worked fine.
If you mean that Jython returned a string, when the inputs were unicode, then 
that can probably be fixed with:

result = u''.join(string_list)
(Python switches to the unicode version automatically if it finds any unicode 
strings in the supplied sequence. Jython may not do that - I'm not a Jython user 
though, so I'm not sure).

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


ANN: Python Test Environment

2004-12-15 Thread Michael Foord
Well sort of... Highly experimental - I'm interested in ways of
improving this.
http://www.voidspace.org.uk/atlantibots/pythonutils.html#testenv
I've created a script that will build a 'test environment'. Windoze(tm)
only as it uses py2exe.
It scans your Python\Lib folder (configurable) and builds a script that
*fakes* an import of every module (along with some boilerplate). This,
more or less, amounts to everything in the standard lib. There is then a
normal setup.py to turn this into a python executable.
The result, is an executable that will run any python script. It gives
sensible values for sys.path, sys.argv and __file__.
This is useful for various purposes :
1) Easily have test environments for multiple versions of python - to
test your scripts.
2) Run any python script on a machine without python installed.
3) Deploying several scripts using py2exe - one build fits all.
Usage :
testenv  arg1 arg2...
Which should be the equivalent of :
python  arg1 arg2...
Sample output :
(Built with Python 2.4 - then 2.3 - prints sys.version first)

D:\New Folder\testenv>testenv test.py arg1 arg2 arg3
2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]
sys.path = ['D:\\New Folder\\testenv\\library.zip', 'D:\\New
Folder\\testenv', '
D:\\New Folder\\testenv']
sys.argv = ['D:\\New Folder\\testenv\\test.py', 'arg1', 'arg2', 'arg3']
import Tkinter # succeeded
import dummylibrary # succeeded
D:\New Folder\testenv>
##
D:\Python Projects\modules in progress\py2exe-testenv\dist>testenv
test.py arg1
arg2
2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
sys.path = ['D:\\Python Projects\\modules in
progress\\py2exe-testenv\\dist\\lib
\\shared.zip', 'D:\\Python Projects\\modules in
progress\\py2exe-testenv\\dist',
'D:\\Python Projects\\modules in progress\\py2exe-testenv\\dist']
sys.argv = ['D:\\Python Projects\\modules in
progress\\py2exe-testenv\\dist\\tes
t.py', 'arg1', 'arg2']
import Tkinter # succeeded
import dummylibrary # succeeded
D:\Python Projects\modules in progress\py2exe-testenv\dist>
~~~
I'm sure this can be improved in lots of ways - but already useful to
me. Comments and suggestions for improvements welcomed. Thanks go to
Bruno Thoorens for his suggestions so far.
Currently has issues collecting 'sub-packages', but I *think* only the
same issues that py2exe has. Extra modules can just be included
somewhere on sys.path.
Regards,
Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html
--
http://mail.python.org/mailman/listinfo/python-list


Step by step: Compiling extensions with MS Visual C++ Toolkit 2003 - msvccompiler-patch.txt (0/1)

2004-12-15 Thread Martin Bless
The good news:

Along with Python-2.4 comes really good news to Windows users. Yes,
you now CAN build extension modules yourself using the SAME C++
compiler and linker Python is built with itself. Everything you need
is available at no costs (except download hassle and installation
time). Once your system is set up properly its just a matter of
running 'python setup.py build'. No longer waiting for someone else to
build binaries and a relief to those who kindly used to provide those
binaries.


The bad news: 

It's not easy to get there! Gathering information and packages and
finding out about all the little steps and stumbling blocks may be
very time consuming.


Relax:

Here's (much of) what you need to know. With this document I'm trying
to provide the information I would have needed. It's sort of a step by
step instruction and contains some details. Goal: Compile Python-2.4
extensions with the freely available "Microsoft Visual C++ Toolkit
2003". This document DOES NOT address the issue of compiling Python
itself.

The example chosen to build is the "MySQLdb" module with its
_mysql.pyd extension.

Go and check out Mike Fletcher's page first at

   http://www.vrplumber.com/programming/mstoolkit/

It's his work (and the need to get a working MySQLdb for Python-2.4 of
course ;-) that motivated me to start and spend some hours. Without
Mike's page I wouldn't even have tried. Thank you so much! Now I'm
prepared.

Two things first - not to forget:

(1) In contrast to what Mike writes I had to use a different registry
key (see step 9)

(2) I don't now what people mean when talking about "msvcr71.lib".
There's no such file on my machine. BUT there IS a "msvcrt.lib" a
directory "C:\Programme\Microsoft Visual Studio .NET 2003\Vc7\lib". I
guess the ".\Vc7\." indicates we are talking of the expected lib.
Correct? I don't know.

Attention - long lines:
Watch out for long lines that may have gotten split in this posting!

See if you've got something already. These are important directories
we're looking for. When "echo %ProgramFiles%" gives "C:\Programme"
there should be:

  C:\Programme\Microsoft Platform SDK for Windows XP SP2\Include
  C:\Programme\Microsoft Platform SDK for Windows XP SP2\Lib
  C:\Programme\Microsoft Visual C++ Toolkit 2003\bin
  C:\Programme\Microsoft Visual Studio .NET 2003\Vc7\lib
  C:\Programme\Microsoft.NET\SDK\v1.1\include
  C:\Programme\Microsoft.NET\SDK\v1.1\Lib


Step By Step


1. Set up a Windows machine
1.1 Install Windows XP (Prof. or Home doesn't matter)
1.2 Apply Service Pack 2 (WinXP SP2)
1.3 Perform a Windows update at
   http://windowsupdate.microsoft.com
to get the latest patches.


2. Get some tools

This is optional - you don't have to. But it may be instructive and
helpful. And - I would say - fun.

2.1 Get "Windows Resource Kits"
Brings some useful tools like "CMD Prompt Here" to the windows
explorer context menu or "robocopy.exe" - a copy tools really worth to
look at. Seems MS developers need good tools too ...

   http://www.microsoft.com/windows/reskits/default.asp

The website says:
"""
Windows Server 2003 Resource Kit Tools
The Resource Kit Tools are a set of software tools for network
administrators, developers, and power users to manage TCP/IP,
networks, the registry, security, remote administration,
configuration, batch files, and many other areas of the Windows Server
2003 operating system. To install the tools, download and run
Rktools.exe.
"""
(rktools.exe, 12.337.752 bytes).



2.2 Add some Unix to Windows. Goto 

   http://unxutils.sourceforge.net/

and get UnxUtils.zip (4.125 kB)
"""
Here are some ports of common GNU utilities to native Win32. In this
context, native means the executables do only depend on the Microsoft
C-runtime (msvcrt.dll) and not an emulation layer like that provided
by Cygwin tools.
"""
For example, this gives you "diff.exe" and "patch.exe".



3. Get and install the the .NET Framework 1.1.

It's available at no costs from the MicroSoft website. Use Google to
find the download page.

3.1 Install the ".NET Framework 1.1 runtime" first (dotnetfx.exe,
24.277.024 bytes)

3.2 Install the .NET Framework 1.1 SDK" second. (setup(sdk1.1).exe,
117.062.664 bytes).

Attention, observation:

This step should indeed create the badly needed 

   C:\Programme\Microsoft Visual Studio .NET 2003\Vc7\lib

folder. It didn't on my machine until I first completely deinstalled
on existing installation of .NET Framework 1.1 runtime AND .NET
Framework 1.1 SDK and then resumed with steps 3.1 and 3.2. Only
Redmond will know why - and I doubt it.

3.3 Perform a Windows update at
   http://windowsupdate.microsoft.com
to get the latest patches of the .NET Framework.



4. Platform SDK

Get and install the platform SDK "Windows XP SP2 SDK" (about
266.000.00 bytes) from
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm

You better download the whole stuff (several .CAB-files) first instead
of trying to install online. This may be

Re: Why are tuples immutable?

2004-12-15 Thread Antoon Pardon
Op 2004-12-15, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>>> how would you implement a dictionary where the keys could change, without
>>> any performance penalty compared to the current implementation?
>>
>> The performace gained by using tuples as keys in dictionaries is
>> entirely illusional.
>>
>> Sure the fact that you use a tuple which is immutable, makes that
>> you can put the key directly in the dictionary instead of a copy
>> and that will gain you some performance.
>>
>> But this performance gain can be more than offset by other code
>> in the program.
>>
>> Suppose you need a list/tuple as a key and most opperation you
>> will do on those keys will be appends and pops. You now have the
>> itwo choices
>>
>>   1) Always convert your lists to tuples on key entries
>>   and keys accesses, which will mean more copying than when a
>>   copy of a key would have been made on key entry.
>>
>>   2) Simulate appends and pops by tuple operations which can also
>>   require more copying than was gained by using tuples as key
>
> sorry, but I don't understand your reply at all.  are you saying that 
> dictionaries
> could support mutable keys (e.g lists) by making a copy of the key?  how would
> such a dictionary pick up changes to the original key object?  (I'm talking 
> about
> the key stored in the dictionary, not the key you're using to look things up).

You want to mutate a key that is within a dictionary?

That sounds as bad as mutating an element in a sorted list.

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


KeyError

2004-12-15 Thread rootshell
Hello.
Maybe someone will help me with this KeyError:

Traceback (most recent call last):
 File "C:\Python\tabla.py", line 929, in -toplevel-
   tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
 File "C:\Python23\lib\os.py", line 417, in __getitem__
   return self.data[key.upper()]
KeyError: 'REMOTE_ADDR'
.. 

Thanks for reading this.
R.

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


Re: subprocess vs. proctools

2004-12-15 Thread Nick Craig-Wood
Keith Dart <[EMAIL PROTECTED]> wrote:
>  Nick Craig-Wood wrote:
> > This sounds rather like the new subprocess module...
> > 
> import subprocess
> rc = subprocess.call(["ls", "-l"])
> > 
> > total 381896
> > -rw-r--r--1 ncw ncw  1542 Oct 12 17:55 1
> > [snip]
> > -rw-r--r--1 ncw ncw   713 Nov 16 08:18 z~
> > 
> print rc
> > 
> > 0
> 
>  But this evaluates to False in Python, but True in a shell.

There are many ways for a program to fail (non-zero exit codes) but
only one way for it to succeed (zero exit code).  Therefore rc should
be 0 for success.

IMHO Shell semantics are nuts (0 is True - yeah!) - they hurt my head
every time I have to use them ;-)

>  It also requires an extra check for normal exit, or exit by a
>  signal.

>>> import subprocess
>>> subprocess.call(["sleep", "60"])
-11
>>> 
# I killed the sleep process with a SEGV here from another xterm

>>> subprocess.call(["sleep", "asdfasdf"])
sleep: invalid time interval `asdfasdf'
Try `sleep --help' for more information.
1
>>>

Signals are -ve, exit codes are +ve which seems perfect.  Exit codes
can only be from 0..255 under linux.  Signals go from -1 to -64.

>  The proctools ExitStatus object avaluates to True only on a normal
>  exit, period. Thus it follows a shell semantics for clarity. You
>  cannot do this with the subprocess module:
> 
>  if rc:
>   print "exited normally"

Actually I think

if rc == 0:
 print "exited normally"

is exactly equivalent!

[snip]
>  It does not work with MS Windows

I like python because I can write stuff on linux and it works on
windows without too much effort, and in general I try not to use
modules which don't work on both platforms.

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


Re: KeyError

2004-12-15 Thread Frans Englich
On Wednesday 15 December 2004 13:33, [EMAIL PROTECTED] wrote:
> Hello.
> Maybe someone will help me with this KeyError:
>
> 
> Traceback (most recent call last):
>   File "C:\Python\tabla.py", line 929, in -toplevel-
> tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
>   File "C:\Python23\lib\os.py", line 417, in __getitem__
> return self.data[key.upper()]
> KeyError: 'REMOTE_ADDR'
> ..

What trouble do you have? AFAICT, The key REMOVE_ADDR wasn't in the 
dictionary, meaning that the environment variable doesn't exist.


Cheers,

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


Re: Import trouble

2004-12-15 Thread Craig Ringer
On Wed, 2004-12-15 at 21:45, Frans Englich wrote:

> 2) I use Python modules which are not usually installed(libxml2/libxslt) and 
> want to fail gracefully in case the modules aren't available; print an 
> informative message. Since these imports are done in several related 
> programs, I don't want to duplicate the code, but instead centralize it. The 
> problem is that when I put the module imports/exception code in a function, 
> it is as if it wasn't imported, even though there was no exceptions. I 
> suspect this is because the import is only done into the current namespace: 
> the function scope(instead of file scope as I want). Is there any solution to 
> my problem? Or should I solve it in another way?

def import_xml:
   try:   
   import libxml
   except ImportError,err:
   # handle the error
   return libxml

libxml = import_xml()


--
Craig Ringer

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


RE: KeyError

2004-12-15 Thread Doran_Dermot
Hi "R",

The only explanation I can give is that the environment varialbe REMOTE_ADDR
does not exist!  Wrap your high-level code with try and except. Example:
try:
 tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
except KeyError:
  # Code to  handle the fact tht REMOT_ADDR does not exist. 

Hope that this helps and is not just another infamous "Dermot Didn't Get It"
posting!

Cheers!!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 15 December 2004 13:34
To: [EMAIL PROTECTED]
Subject: KeyError

Hello.
Maybe someone will help me with this KeyError:


Traceback (most recent call last):
  File "C:\Python\tabla.py", line 929, in -toplevel-
tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
  File "C:\Python23\lib\os.py", line 417, in __getitem__
return self.data[key.upper()]
KeyError: 'REMOTE_ADDR'
.. 


Thanks for reading this.
R.



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


Re: Import trouble

2004-12-15 Thread Craig Ringer
On Wed, 2004-12-15 at 21:44, Craig Ringer wrote:

> def import_xml:
>try:   
>import libxml
>except ImportError,err:
># handle the error
>return libxml
> 
> libxml = import_xml()

Though my personal approach would actually be:

try:
import libxml
except ImportError,err:
   handle_import_error("libxml", err)

--
Craig Ringer

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


Re: Import trouble

2004-12-15 Thread Frans Englich
On Wednesday 15 December 2004 13:44, Craig Ringer wrote:
> On Wed, 2004-12-15 at 21:45, Frans Englich wrote:
> > 2) I use Python modules which are not usually installed(libxml2/libxslt)
> > and want to fail gracefully in case the modules aren't available; print
> > an informative message. Since these imports are done in several related
> > programs, I don't want to duplicate the code, but instead centralize it.
> > The problem is that when I put the module imports/exception code in a
> > function, it is as if it wasn't imported, even though there was no
> > exceptions. I suspect this is because the import is only done into the
> > current namespace: the function scope(instead of file scope as I want).
> > Is there any solution to my problem? Or should I solve it in another way?
>
> def import_xml:
>try:
>import libxml
>except ImportError,err:
># handle the error
>return libxml
>
> libxml = import_xml()

Ah thanks. When will one stop to take the limits of Python's introspection for 
granted?


Cheers,

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


Re: Python IDE

2004-12-15 Thread Chris
Try WingIDE if you have some money (about 35 E/$ for the personal
version) to spend, it's worth every (euro)cent. But please try SPE
first, maybe that's enough for you.
SPE?
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2004-12-15 Thread Frans Englich
On Wednesday 15 December 2004 13:59, Chris wrote:
> > Try WingIDE if you have some money (about 35 E/$ for the personal
> > version) to spend, it's worth every (euro)cent. But please try SPE
> > first, maybe that's enough for you.
>
> SPE?

After googling for "python spe", my guess is "SPE - Stani's Python Editor": 
http://spe.pycs.net/


Cheers,

Frans

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


Re: Import trouble

2004-12-15 Thread Steve Holden
Frans Englich wrote:
Hello all,
I have a couple of questions related to module importing.
1) When I start my Python program with `python foo.py` instead of simply 
adding a interpreter comment on the first line and do `./foo.py`, some 
"local" imports fails, I guess because current working directory is 
different. Is CWD the only difference between running `python foo.py` and 
`./foo.py`? What is the recommended way? (I guess security is one aspect that 
can be argued)
You should post the exact error message together with a snippet of the 
code around the error. One possibility is that the "shebang" line 
(#!...) in your script is invoking a different Python than when you 
enter "python" and the shell locates it on your path.
2) I use Python modules which are not usually installed(libxml2/libxslt) and 
want to fail gracefully in case the modules aren't available; print an 
informative message. Since these imports are done in several related 
programs, I don't want to duplicate the code, but instead centralize it. The 
problem is that when I put the module imports/exception code in a function, 
it is as if it wasn't imported, even though there was no exceptions. I 
suspect this is because the import is only done into the current namespace: 
the function scope(instead of file scope as I want). Is there any solution to 
my problem? Or should I solve it in another way?

Craig Ringer has already answered this question.
3) And the last -- but funniest -- import problem: sometimes imports of 
modules in "xml." fails, sometimes it works. For example, this code:
from xml.dom.minidom import getDOMImplementation
impl = getDOMImpmentation() #NameError: name 'getDOMImpmentation' is not 
defined

fails as shown, and other times it works. When running pydoc as local web 
server, it also sometimes fails, although I haven't been able to reproduce 
for a error message. I have recent versions of PyXML and 4suite installed. 

What is wrong? Any idea what that could be wrong with my setup, which could 
cause this?

Again you should post a little more detail. In your example it looks 
like you made a simple spelling error: getDOMImpmentation instead of 
getDOMImplementation.

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


Re: KeyError

2004-12-15 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Hello.
> Maybe someone will help me with this KeyError:
> 
> 
> Traceback (most recent call last):
>   File "C:\Python\tabla.py", line 929, in -toplevel-
> tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
>   File "C:\Python23\lib\os.py", line 417, in __getitem__
> return self.data[key.upper()]
> KeyError: 'REMOTE_ADDR'
> ..

That tabla.py of yours is certainly to be executed in a CGI environment. So
call it that way - or provide the neccessary environment by stuffing values
to os.environ


-- 
Regards,

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


Import trouble

2004-12-15 Thread Frans Englich

Hello all,

I have a couple of questions related to module importing.

1) When I start my Python program with `python foo.py` instead of simply 
adding a interpreter comment on the first line and do `./foo.py`, some 
"local" imports fails, I guess because current working directory is 
different. Is CWD the only difference between running `python foo.py` and 
`./foo.py`? What is the recommended way? (I guess security is one aspect that 
can be argued)

2) I use Python modules which are not usually installed(libxml2/libxslt) and 
want to fail gracefully in case the modules aren't available; print an 
informative message. Since these imports are done in several related 
programs, I don't want to duplicate the code, but instead centralize it. The 
problem is that when I put the module imports/exception code in a function, 
it is as if it wasn't imported, even though there was no exceptions. I 
suspect this is because the import is only done into the current namespace: 
the function scope(instead of file scope as I want). Is there any solution to 
my problem? Or should I solve it in another way?

3) And the last -- but funniest -- import problem: sometimes imports of 
modules in "xml." fails, sometimes it works. For example, this code:
from xml.dom.minidom import getDOMImplementation
impl = getDOMImpmentation() #NameError: name 'getDOMImpmentation' is not 
defined

fails as shown, and other times it works. When running pydoc as local web 
server, it also sometimes fails, although I haven't been able to reproduce 
for a error message. I have recent versions of PyXML and 4suite installed. 

What is wrong? Any idea what that could be wrong with my setup, which could 
cause this?


Cheers,

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


Re: getopt: Make argument mandatory

2004-12-15 Thread Fredrik Lundh
Frans Englich wrote:

> In my use of getopt.getopt, I would like to make a certain parameter
> mandatory.

but you just did:

>if configurationFile == "":
>print "You must pass an URL/path to a configuration file, see
> --help."
>sys.exit(common.exitCodes["parameter"])

> Is it possible?

afaik, getopt doesn't have any built-in validation features; Python's got
more than enough of them already...

 



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


Re: Why are tuples immutable?

2004-12-15 Thread Roel Schroeven
Antoon Pardon wrote:
Op 2004-12-15, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
sorry, but I don't understand your reply at all.  are you saying that 
dictionaries
could support mutable keys (e.g lists) by making a copy of the key?  how would
such a dictionary pick up changes to the original key object?  (I'm talking 
about
the key stored in the dictionary, not the key you're using to look things up).

You want to mutate a key that is within a dictionary?
No, we don't want to mutate it; as far as I know, that is exactly the 
reason why dictionaries don't support mutable keys.

--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: gather information from various files efficiently

2004-12-15 Thread Paul McGuire
"Klaus Neuner" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> I need to gather information that is contained in various files.
>
> Like so:
>
> file1:
> =
> foo : 1 2
> bar : 2 4
> baz : 3
> =
>
> file2:
> =
> foo : 5
> bar : 6
> baz : 7
> =
>
> file3:
> =
> foo : 4 18
> bar : 8
> =
>
>
> The straightforward way to solve this problem is to create a
> dictionary. Like so:
>
>
> [...]
>
> a, b = get_information(line)
> if a in dict.keys():
> dict[a].append(b)
> else:
> dict[a] = [b]
>
>
> Yet, I have got 43 such files. Together they are 4,1M
> large. In the future, they will probably become much larger.
> At the moment, the process takes several hours. As it is a process
> that I have to run very often, I would like it to be faster.
>
> How could the problem be solved more efficiently?
>
>
> Klaus

You have gotten a number of suggestions on the relative improvements for
updating your global dictionary of values.  My business partner likens code
optimization to lowering the water in a river.  Performance bottlenecks
stick out like rocks sticking out of a river.  Once you resolve one problem
(remove the rock), you lower the water level, and the next rock/bottleneck
appears.  Have you looked at what is happening in your get_information
method?  If you are still taking long periods of time to scan through these
files, you should look into what get_information is doing.  In working with
my pyparsing module, I've seen people scan multimegabyte files in seconds,
so taking hours to sift through 4Mb of data sounds like there may be other
problems going on.

With this clean a code input, something like:

def get_information(line):
return map(str.strip, line.split(":",1))

should do the trick.  For that matter, you could get rid of the function
call (calls are expensive in Python), and just inline this to :

a,b = map(str.strip, line.split(":",1))
if a in dct:
dct[a] += b.split()
else:
dct[a] = b.split()

(I'm guessing you want to convert b values that have multiple numbers to a
list, based on your "dict[a] = [b]" source line.)
I also renamed dict to dct, per Fernando Perez's suggestion.

-- Paul


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


RE: Import trouble

2004-12-15 Thread Doran_Dermot
Hi Craig,

How about creating your own module that does this in  __init__.py.

You could create a directory (Eg craig_init) and in that directory create
the file __init__.py containing the following code:

try: import libxml
except: 
  # Blah, blah, blah. A clever bit of code goes here!

WARNING: I haven't checked this myself, but it appears to be the way that
the Zope Database python code has been written.  If you have the ZODB
package installed take a look at "Lib\site-packages\Btrees\__init__.py".
I'm sure there must be other examples of this as well. 

Cheers!!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Craig Ringer
Sent: 15 December 2004 13:45
To: Frans Englich
Cc: Python mailing list
Subject: Re: Import trouble

On Wed, 2004-12-15 at 21:45, Frans Englich wrote:

> 2) I use Python modules which are not usually installed(libxml2/libxslt)
and 
> want to fail gracefully in case the modules aren't available; print an 
> informative message. Since these imports are done in several related 
> programs, I don't want to duplicate the code, but instead centralize it.
The 
> problem is that when I put the module imports/exception code in a
function, 
> it is as if it wasn't imported, even though there was no exceptions. I 
> suspect this is because the import is only done into the current
namespace: 
> the function scope(instead of file scope as I want). Is there any solution
to 
> my problem? Or should I solve it in another way?

def import_xml:
   try:   
   import libxml
   except ImportError,err:
   # handle the error
   return libxml

libxml = import_xml()


--
Craig Ringer

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


Re: Small Problem P 2.4 (line>2048 Bytes)

2004-12-15 Thread Walter Dörwald
>> [...]
>> After search, I had found that the problem come from a "long line" (more
>> than 2048 caracters), with begin :
>> mappingcharmaj = { chr(97):'A', chr(98):'B', chr(99):'C', ...
>> 
>> And, if I "break" in multiples lines, the problem is solved.

This sounds like bug http://www.python.org/sf/1076985
"Incorrect behaviour of StreamReader.readline leads to crash".

Are you using a PEP 263 coding header for your script?

Bye,
   Walter Dörwald
   

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


Re: flex/bison like module in Python?

2004-12-15 Thread Fredrik Lundh
Jerry Sievers wrote:

> Curious if there exists in Python package(s) for use as lexer/parser
> for implementation of language grammars?

(s) indeed:

http://www.nedbatchelder.com/text/python-parsers.html

 



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


Re: ANN: Python Test Environment

2004-12-15 Thread Fuzzyman
Sorry they're not reaching google groups, which is what I'm posting
from. From http://groups-beta.google.com/group/comp.lang.python posts
usually show up within a few minutes. The thing is, when I posted by
email it showed up in seconds...

Anyway - sorry about that and thanks for letting me know.

Regards,
Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


Re: Why are tuples immutable?

2004-12-15 Thread Antoon Pardon
Op 2004-12-15, Roel Schroeven schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Op 2004-12-15, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
>>>sorry, but I don't understand your reply at all.  are you saying that 
>>>dictionaries
>>>could support mutable keys (e.g lists) by making a copy of the key?  how 
>>>would
>>>such a dictionary pick up changes to the original key object?  (I'm talking 
>>>about
>>>the key stored in the dictionary, not the key you're using to look things 
>>>up).
>> 
>> 
>> You want to mutate a key that is within a dictionary?
>
> No, we don't want to mutate it; as far as I know, that is exactly the 
> reason why dictionaries don't support mutable keys.

And I think that is a stupid reason. There are enough other situations
were people work with mutable objects but don't wish to mutate specific
objects.  Like objects in a sorted sequence you want to keep that way
or objects in a heapqueue etc.

Demanding that users of dictioanaries somehow turn their mutable objects
into tuples when used as a key and back again when you retrieve the keys
and need the object can IMO ibe a bigger support nightmare than the
possibility that code mutates a key in a dictionary.

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


Re: Flow based programming & python coding style

2004-12-15 Thread Jp Calderone


On Wed, 15 Dec 2004 12:30:07 -0200, Carlos Ribeiro <[EMAIL PROTECTED]> wrote:
>Hi,
> 
> A friend of mine passed me some links about a great concept (not new
> in fact, only new to me):
> 
> -- http://www.jpaulmorrison.com/fbp/
> -- http://c2.com/cgi/wiki?FlowBasedProgramming
> 
> I found many of the explanations and examples strangely familiar. The
> C2 Wiki contains a good discussion that draws parallels between FBP
> and functional programming, although Paul Morrison is quick to point
> ou the differences. It also strikes me how much of this "paradigm
> shift" can be readily embodied in Python by using generators.

  Continuations provide a better conceptual fit.  Generators 
are extremely inconvenient to nest (not to mention the numerous
difficulties with them, such as poor toolchain support).  While 
they are certainly handy here and there, their limitations become 
apparent in almost any non-trivial application.  Other languages 
(and other implementations of Python) go a lot further towards 
making "flow based programming" natural.

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


Re: getopt: Make argument mandatory

2004-12-15 Thread Diez B. Roggisch
> In my use of getopt.getopt, I would like to make a certain parameter
> mandatory. I know how to specify such that a parameter must have a value
> if it's specified, but I also want to make the parameter itself
> mandatory(combined with a mandatory value, the result is that the user
> must specify a value).


Use optparse - in the examples section you'll find what you need.

-- 
Regards,

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


Re: lies about OOP

2004-12-15 Thread Peter Hansen
Martijn Faassen wrote:
Paul McGuire wrote:
"Martijn Faassen" <[EMAIL PROTECTED]> wrote in message

Yikes!  (or better, "Jikes!" or even "Yijkes!"?) - my bad.
And he was on faculty at UT right here in Austin, too.
It's a very common mistake I've seen so often that for a while I 
wondered whether his name really *was* Djikstra, but I knew he was Dutch 
and that it couldn't be so. That the PSU picked you for its disclosure 
is just a random coincidence, I'm sure.. :)
Well, in any case, thanks for setting the record straight, Martjin.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression

2004-12-15 Thread Michael McGarry
Philippe C. Martin wrote:
I'm struggling myself and have bought:
"Mastering Regular Expressions"
2nd Edition,
O'REILLY
Jeffrey E. F. Friedl
I covers the reg exp concepts + applications in various languages (mostly PERL 
but some Python also)


Thank you everyone for the tips!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why are tuples immutable?

2004-12-15 Thread Jp Calderone


On Wed, 15 Dec 2004 14:18:21 GMT, Roel Schroeven <[EMAIL PROTECTED]> wrote:
>Antoon Pardon wrote:
> > Op 2004-12-15, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
> >>sorry, but I don't understand your reply at all.  are you saying that 
> >>dictionaries
> >>could support mutable keys (e.g lists) by making a copy of the key?  how 
> >>would
> >>such a dictionary pick up changes to the original key object?  (I'm talking 
> >>about
> >>the key stored in the dictionary, not the key you're using to look things 
> >>up).
> > 
> > 
> > You want to mutate a key that is within a dictionary?
> 
> No, we don't want to mutate it; as far as I know, that is exactly the 
> reason why dictionaries don't support mutable keys.

  Dictionaries support mutable keys just find.  What they don't 
support is unhashable keys.  

  For some objects, this is an important distinction: lists are 
mutable but not hashable.

  For other objects, it is not: instances of user defined classes 
are mutable and hashable.  This is handy since the default hash is 
based on identity instead of the values of attributes.

  Mutating an object in a dictionary is completely reasonable.  What
is unreasonable is wanting to make a change that would change its
hash value.

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


Re: flex/bison like module in Python?

2004-12-15 Thread wolfgang haefelinger
You may checkout

 www.antlr.org

around Xmas - a extension for Python will be released.

Regards,
Wolfgang.

"Jerry Sievers" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Dear Pythonists;
>
> Curious if there exists in Python package(s) for use as lexer/parser
> for implementation of language grammars?
>
> Already using cmd.py from the standard distro for it's basic features
> but wishing for much more advanced capability.  As such, I refer to
> flex/bison because though complex they are general purpose and very
> useful.
>
> I am trying to avoid having to do the lexer/parser part in C if
> possible.
>
> Thanks.
>
> -- 
> ---
> Jerry Sievers   305 854-3001 (home) WWW ECommerce Consultant
>305 321-1144 (mobile http://www.JerrySievers.com/ 


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


Re: Help need with converting Hex string to IEEE format float

2004-12-15 Thread Peter Hansen
Christos TZOTZIOY Georgiou wrote:
s = "".join(x).decode("hex")
I am not sure I remember in which version of Python the hex codec was
added, but it is handy.
Of course, binascii could do this since 2.0 or so, but not
having to import another module *is* nice:
>>> 'ff12'.decode('hex')
'\xff\x12'
>>> import binascii
>>> binascii.unhexlify('ff12')
'\xff\x12'
Thanks for pointing it out, Christos.
--
http://mail.python.org/mailman/listinfo/python-list


Efficient grep using Python?

2004-12-15 Thread sf
Just started thinking about learning python.

Is there any place where I can get some free examples, especially for
following kind of problem ( it must be trivial for those using python)

I have files A, and B each containing say 100,000 lines (each line=one
string without any space)

I want to do

"  A  - (A intersection B)  "

Essentially, want to do efficient grep, i..e from A remove those lines which
are also present in file B.


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


Data problem

2004-12-15 Thread Jeffrey Maitland








Hello all,

I am using the MySQLdb module and I am writing to a MySQL
database. 

My write statement is something like.

cursor.execute(“INSERT INTO Data(Name, X, Y, Z, Data) 

  
VALUES('%s', '%s', '%s', '%f', '%f', '%f', '%s')""" % 

  
(name, high_x, high_y, high_z, data))

 

I can write the data to a file as a check and all 
variables are showing correctly. However when I extract the data from the
database the X, Y are not coming out with the same number that “should be
going” into the database but the Z is.  Any Ideas?

 

Example data going in and out.

IN.

Name = test

X = 34.523

Y = -123.2432

Z =  -123.2346

Data = "" is test data”

 

OUT

Name = test

X = 34.0

Y = -123.0

Z =  -123.2346

Data = "" is test data”

 

That’s is what is going in and coming out. 

*Note this is an example of the data not actual data or code
(Although the difference is the amount of data being input)”

 

Thanks for any and all help/comments.

 

Jeff

 

 






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

Re: Why are tuples immutable?

2004-12-15 Thread Steve Holden
Antoon Pardon wrote:
Op 2004-12-15, Roel Schroeven schreef <[EMAIL PROTECTED]>:
Antoon Pardon wrote:
Op 2004-12-15, Fredrik Lundh schreef <[EMAIL PROTECTED]>:
sorry, but I don't understand your reply at all.  are you saying that 
dictionaries
could support mutable keys (e.g lists) by making a copy of the key?  how would
such a dictionary pick up changes to the original key object?  (I'm talking 
about
the key stored in the dictionary, not the key you're using to look things up).

You want to mutate a key that is within a dictionary?
No, we don't want to mutate it; as far as I know, that is exactly the 
reason why dictionaries don't support mutable keys.

And I think that is a stupid reason. There are enough other situations
were people work with mutable objects but don't wish to mutate specific
objects.  Like objects in a sorted sequence you want to keep that way
or objects in a heapqueue etc.
Demanding that users of dictioanaries somehow turn their mutable objects
into tuples when used as a key and back again when you retrieve the keys
and need the object can IMO ibe a bigger support nightmare than the
possibility that code mutates a key in a dictionary.
So provide your objects with a __hash__ method, and you can use them as 
dictionary keys.

Sheesh, learn Python already. What a troll. [Plonk]
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient grep using Python?

2004-12-15 Thread Fredrik Lundh
"sf" <[EMAIL PROTECTED]> wrote:

> I have files A, and B each containing say 100,000 lines (each line=one
> string without any space)
>
> I want to do
>
> "  A  - (A intersection B)  "
>
> Essentially, want to do efficient grep, i..e from A remove those lines which
> are also present in file B.

that's an unusual definition of "grep", but the following seems to
do what you want:

afile = "a.txt"
bfile = "b.txt"

bdict = dict.fromkeys(open(bfile).readlines())

for line in open(afile):
if line not in bdict:
print line,

 



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


Re: while 1 vs while True

2004-12-15 Thread Peter Hansen
Paul Rubin wrote:
Nick Coghlan <[EMAIL PROTECTED]> writes:
Until this code:
.>>> import pdb
.>>> pdb.True = 0
.>>> pdb.x = "Darn writeable module dictionaries"
.>>> from pdb import True
.>>> True
0
.>>> from pdb import x
.>>> x
'Darn writeable module dictionaries'

If Python really does behave that way, that bug should be fixed immediately.
(My ISP's news server seems to be dropping messages, so I didn't
see Nick's original message above, nor perhaps the message he
was replying to.  I hope that doesn't matter to my reply...)
Paul, what is wrong with the above behaviour, that you believe it
to indicate a bug?
As Nick showed in his following reply, there are certainly
people who make use of this behaviour, and I don't believe
it could be duplicated with any other existing feature of
Python.  Removing it would, for but one example, cripple
my ability to do effective automated testing in my field
of work.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient grep using Python?

2004-12-15 Thread P
sf wrote:
Just started thinking about learning python.
Is there any place where I can get some free examples, especially for
following kind of problem ( it must be trivial for those using python)
I have files A, and B each containing say 100,000 lines (each line=one
string without any space)
I want to do
"  A  - (A intersection B)  "
Essentially, want to do efficient grep, i..e from A remove those lines which
are also present in file B.
You could implement elegantly using the new sets feature
For reference here is the unix way to do it:
sort a b b | uniq -u
--
Pádraig Brady - http://www.pixelbeat.org
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: flex/bison like module in Python?

2004-12-15 Thread Jean Brouwers

For command line parsing, take a look at the shlex module, also in the
standard distro.  It may fit your requirements for additional
functionality beyond cmd.

/Jean Brouwers

PS) We use SimpleParse/mxTextTools for parsing large log files, both
are listed on the web page mentioned below.  In addition, check out
David Mertz' web pages 'Text Processing in Python' at





In article <[EMAIL PROTECTED]>,
Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> Jerry Sievers wrote:
> 
> > Curious if there exists in Python package(s) for use as lexer/parser
> > for implementation of language grammars?
> 
> (s) indeed:
> 
> http://www.nedbatchelder.com/text/python-parsers.html
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient grep using Python?

2004-12-15 Thread Tim Peters
["sf" <[EMAIL PROTECTED]>]
>> I have files A, and B each containing say 100,000 lines (each
>> line=one string without any space)
>>
>> I want to do
>>
>> "  A  - (A intersection B)  "
>>
>> Essentially, want to do efficient grep, i..e from A remove those
>> lines which are also present in file B.

[Fredrik Lundh]
> that's an unusual definition of "grep", but the following seems to
> do what you want:
>
> afile = "a.txt"
> bfile = "b.txt"
>
> bdict = dict.fromkeys(open(bfile).readlines())
>
> for line in open(afile):
>if line not in bdict:
>print line,
> 
>  

Note that an open file is an iterable object, yielding the lines in
the file.  The "for" loop exploited that above, but fromkeys() can
also exploit it.  That is,

bdict = dict.fromkeys(open(bfile))

is good enough (there's no need for the .readlines()).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data problem

2004-12-15 Thread Aaron Bingham
Jeffrey Maitland wrote:
I am using the MySQLdb module and I am writing to a MySQL database.
My write statement is something like.
cursor.execute(“INSERT INTO Data(Name, X, Y, Z, Data)
   VALUES('%s', '%s', '%s', '%f', '%f', '%f', 
'%s')""" %

   (name, high_x, high_y, high_z, data))
This is not causing your problem, but why not take advantage of the 
DB-API value substitution support, e.g.:

cursor.execute("""INSERT INTO Data(Name, X, Y, Z, Data)
   VALUES(%s, %f, %f, %f, %s)""",
   (name, high_x, high_y, high_z, data))
This will take care of correctly escaping and quoting strings and 
formatting floats for you automatically.

I can write the data to a file as a check and all  variables are showing 
correctly. However when I extract the data from the database the X, Y 
are not coming out with the same number that “should be going” into the 
database but the Z is.  Any Ideas?
My first guess would be that the X and Y fields in the DB are actually 
defined as integers, not floats, but you probably already checked that.

Regards,
--

Aaron Bingham
Application Developer
Cenix BioScience GmbH

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


Re: Efficient grep using Python?

2004-12-15 Thread John Hunter
> "sf" == sf  <[EMAIL PROTECTED]> writes:

sf> Just started thinking about learning python.  Is there any
sf> place where I can get some free examples, especially for
sf> following kind of problem ( it must be trivial for those using
sf> python)

sf> I have files A, and B each containing say 100,000 lines (each
sf> line=one string without any space)

sf> I want to do

sf> " A - (A intersection B) "

sf> Essentially, want to do efficient grep, i..e from A remove
sf> those lines which are also present in file B.

If you're only talking about 100K lines or so, and you have a
reasonably modern computer, you can do this all in memory.  If order
doesn't matter (it probably does) you can use a set to get all the
lines in file B that are not in A

from sets import Set
A = Set(file('test1.dat').readlines())
B = Set(file('test2.dat').readlines())
print B-A

To preserve order, you should use a dictionary that maps lines to line
numbers.  You can later use these numbers to sort

A = dict([(line, num) for num,line in enumerate(file('test1.dat'))])
B = dict([(line, num) for num,line in enumerate(file('test2.dat'))])

keep = [(num, line) for line,num in B.items() if not A.has_key(line)]
keep.sort()
for num, line in keep:
   print line,

Now someone else will come along and tell you all this functionality
is already in the standard library.  But it's always fun to hack this
out yourself once because python makes such things so damned easy.

JDH

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


Re: Flow based programming & python coding style

2004-12-15 Thread Carlos Ribeiro
On Wed, 15 Dec 2004 15:16:44 GMT, Jp Calderone <[EMAIL PROTECTED]> wrote:
> 
> 
> On Wed, 15 Dec 2004 12:30:07 -0200, Carlos Ribeiro <[EMAIL PROTECTED]> wrote:
> >Hi,
> >
> > A friend of mine passed me some links about a great concept (not new
> > in fact, only new to me):
> >
> > -- http://www.jpaulmorrison.com/fbp/
> > -- http://c2.com/cgi/wiki?FlowBasedProgramming
> >
> > I found many of the explanations and examples strangely familiar. The
> > C2 Wiki contains a good discussion that draws parallels between FBP
> > and functional programming, although Paul Morrison is quick to point
> > ou the differences. It also strikes me how much of this "paradigm
> > shift" can be readily embodied in Python by using generators.
> 
>   Continuations provide a better conceptual fit.  Generators
> are extremely inconvenient to nest (not to mention the numerous
> difficulties with them, such as poor toolchain support).  While
> they are certainly handy here and there, their limitations become
> apparent in almost any non-trivial application.  Other languages
> (and other implementations of Python) go a lot further towards
> making "flow based programming" natural.

I think that generators are just one more step in the process towards
a not-so-far in the future "Stackless-like" Python. I sincerely
believe that Stackless (with support for continuations & related
features) is one of the great driving factors behind many of the
improvements in this arena (the other being functional programming in
general).

In this regard, Python comes up surprisingly well armed. It already
supports several styles: imperative, functional, procedural,
object-oriented, and now, some idioms for data-centric programming.
The language managed to cover it all in a surprisingly clear & concise
environment.  I believe that the native support of flow-based friendly
techniques is a good step; and more than this, I believe that it will
change the way Python code is written. But that's really just my
opinion, and everyone is entitled one, right?

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fill a Server

2004-12-15 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> Also, my first attempt at this did a recursive copy creating subdirs in
> dirs as it copied. It would crash everytime it went 85 subdirs deep.
> This is an NTFS filesystem. Would this limitation be in the filesystem
> or Python?

see the "Max File Name Length" on this page (random google link)
for an explanation:

http://www.ntfs.com/ntfs_vs_fat.htm

(assuming that "crash" meant "raise an exception", that is)

 



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


Re: Fill a Server

2004-12-15 Thread Fredrik Lundh

>> Also, my first attempt at this did a recursive copy creating subdirs in
>> dirs as it copied. It would crash everytime it went 85 subdirs deep.
>> This is an NTFS filesystem. Would this limitation be in the filesystem
>> or Python?
>
> see the "Max File Name Length" on this page (random google link)
> for an explanation:
>
>http://www.ntfs.com/ntfs_vs_fat.htm

also:

print len(os.path.join("c:\\scratch", *map(str, range(85

 



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


Re: Fill a Server

2004-12-15 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
[snip code involving copyfile:]
shutil.copyfile(os.path.join(root, f),

The problem with this is that it only copies about 35 GB/hour. I would
like to copy at least 100 GB/hour... more if possible. I have tried to
copy from the IDE CD drive to the SATA array with the same results. I
understand the throughput on SATA to be roughly 60MB/sec which comes
out to 3.6 GB/min which should be 216 GB/hour. Can someone show me how
I might do this faster? Is shutil the problem?
Have you tried doing this from some kind of batch file, or
manually, measuring the results?  Have you got any way to
achieve this throughput, or is it only a theory?  I see
no reason to try to optimize something if there's no real
evidence that it *can* be optimized.
Also, my first attempt at this did a recursive copy creating subdirs in
dirs as it copied. It would crash everytime it went 85 subdirs deep.
This is an NTFS filesystem. Would this limitation be in the filesystem
or Python?
In general, when faced with the question "Is this a limitation
of Python or of this program X of Microsoft origin?", the answer
should be obvious... ;-)
More practically, perhaps: use your script to create one of those
massively nested folders.  Wait for it to crash.  Now go in
"manually" (with CD or your choice of fancy graphical browser)
to the lowest level folder and attempt to create a subfolder
with the same name the Python script was trying to use.  Report
back here on your success, if any. ;-)
(Alternatively, describe your failure in terms other than "crash".
Python code rarely crashes.  It does, sometimes, fail and print
out an exception traceback.  These are printed for a very good
reason: they are more descriptive than the word "crash".)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fill a Server

2004-12-15 Thread [EMAIL PROTECTED]
You are correct Peter, the exception read something like this:

"Folder 85 not found."

I am paraphrasing, but that is the crux of the error. It takes about an
hour to produce the error so if you want an exact quote from the
exception, let me know and give me awhile. I looked through the nested
dirs several times after the crash and they always went from 0 - 84...
sure enough, directory 85 had not been created... why I do not know.
Doesn't really matter now as the script I posted achieves similar
results witout crashing... still slow though.

As far as drive throughput, it's my understanding that SATA is
theorhetically capable of 150 MB/sec (google for it). However, in
practice, one can normally expect a sustained throughput of 60 to 70
MB/sec. The drives are 7,200 RPM... not the more expensive 10,000 RPM
drives. I have no idea how RAID 5 might impact performance either. It's
hardware RAID on a top-of-the-line DELL server. I am not a hardware
expert so I don't understand how *sustained* drive throughput, RPM and
RAID together fator into this scenario.

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


Multithreading tkinter question

2004-12-15 Thread Mark English
Is there a safe way to run tkinter in a multithreaded app where the
mainloop runs in a background thread ?
Here's some test code demonstrating the problem. I'm running Python2.4
under Windows 2000.


Code snip starts-
from Tkinter import *

def GetTkinterThread():
import threading
def TestTkinter():
def greeting():
print "Hello stdout world !"

win = Frame()
win.pack()
Label(win, text="Hello container world").pack(side=TOP)
Button(win, text="Hello", command=greeting).pack(side=TOP)
Button(win, text="Quit", command=win.quit).pack(side=RIGHT)

win.mainloop()
#Run the mainloop in another thread
t = threading.Thread(None, TestTkinter, 'Test Tkinter Thread')
t.setDaemon(1)   #Keep going
t.start()
print 'Hi'
return t

t = GetTkinterThread() #This works fine

#Now press the "Hello" button on the Tkinter window
#Now press the return key at the python prompt

Code snip ends-
With a debug build the call stack looks like this:
python24_d.dll!Py_FatalError(const char * msg=0x1e23ca14)  Line
1513C
python24_d.dll!PyThreadState_Swap(_ts * new=0x0098d0b8)  Line
293 + 0xa   C
python24_d.dll!PyEval_RestoreThread(_ts * tstate=0x0098d0b8)
Line 309 + 0x9  C
_tkinter_d.pyd!EventHook()  Line 2969 + 0xc C
python24_d.dll!my_fgets(char * buf=0x009ef3e8, int len=100,
_iobuf * fp=0x1027c838)  Line 46C
python24_d.dll!PyOS_StdioReadline(_iobuf * sys_stdin=0x1027c838,
_iobuf * sys_stdout=0x1027c858, char * prompt=0x0087f974)  Line 125 +
0x11C
python24_d.dll!PyOS_Readline(_iobuf * sys_stdin=0x1027c838,
_iobuf * sys_stdout=0x1027c858, char * prompt=0x0087f974)  Line 205 +
0x12C

Is this because of access to sys.stdout ? Or some deeper darker problem
? Is there a right way to achieve this ? Basically I want to be able to
call a function from the Python prompt which creates a Tkinter window
(not necessarily interactive apart from a close button) to display some
data, but leaves the Python prompt active so I can carry on from there.

Haven't found anything about this yet. All sample multithreaded Tkinter
code I've seen uses the main thread as the GUI thread. Also, should I be
posting this to another newsgroup ?

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


change windows system path from cygwin python?

2004-12-15 Thread gry
[Windows XP Pro, cygwin python 2.4, *nix hacker, windows newbie]

I want to write some kind of install script for my python app that
will add c:\cygwin\usr\bin to the system path.  I don't want
to walk around to 50 PC's and twiddle through the GUI to:

My Computer --> Control Panel --> System --> Advanced --> Environment


How can a python, or even a .bat script modify the system PATH?
It doesn't appear to be in the registry.

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


Re: change windows system path from cygwin python?

2004-12-15 Thread Harlin Seritt
[EMAIL PROTECTED] wrote:

> [Windows XP Pro, cygwin python 2.4, *nix hacker, windows newbie]
> 
> I want to write some kind of install script for my python app that
> will add c:\cygwin\usr\bin to the system path.  I don't want
> to walk around to 50 PC's and twiddle through the GUI to:
> 
> My Computer --> Control Panel --> System --> Advanced --> Environment
> 
> 
> How can a python, or even a .bat script modify the system PATH?
> It doesn't appear to be in the registry.

If you're just wanting to add a path to the system environments you can do:

"set path=c:\path\to\whatever" # As a line in a Batch file 


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


Re: change windows system path from cygwin python?

2004-12-15 Thread Jeff Lindholm
>
> I want to write some kind of install script for my python app that
> will add c:\cygwin\usr\bin to the system path.  I don't want
> to walk around to 50 PC's and twiddle through the GUI to:
>
> My Computer --> Control Panel --> System --> Advanced --> Environment
>
>
> How can a python, or even a .bat script modify the system PATH?
> It doesn't appear to be in the registry.
>
It is in the registry
All users = local machine - "System\CurrentControlSet\Control\Session 
Manager\Environment"
Current User = Current User - Environment

The only issue with this is you will have to reboot for it take effect.


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


Re: Efficient grep using Python?

2004-12-15 Thread Tim Peters
[Fredrik Lundh]
>>> bdict = dict.fromkeys(open(bfile).readlines())
>>>
>>> for line in open(afile):
>>>if line not in bdict:
>>>print line,
>>>
>>> 

[Tim Peters]
>> Note that an open file is an iterable object, yielding the lines in
>> the file.  The "for" loop exploited that above, but fromkeys() can
>> also exploit it.  That is,
>>
>> bdict = dict.fromkeys(open(bfile))
>>
>> is good enough (there's no need for the .readlines()).

[/F] 
> (sigh.  my brain knows that, but my fingers keep forgetting)
> 
> and yes, for this purpose, "dict.fromkeys" can be replaced
> with "set".
>
>bdict = set(open(bfile))
>
> (and then you can save a few more bytes by renaming the
> variable...)

Except the latter two are just shallow spelling changes.  Switching
from fromkeys(open(f).readlines()) to fromkeys(open(f)) is much more
interesting, since it can allow major reduction in memory use.  Even
if all the lines in the file are pairwise distinct, not materializing
them into a giant list can be a significant win.  I wouldn't have
bothered replying if the only point were that you can save a couple
bytes of typing .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-15 Thread H. S. Lahman
Responding to Beliavsky...
Les Hatton "Does OO sync with the way we think?", IEEE Software, 15(3),
p.46-54
"This paper argues from real data that OO based systems written in C++
appear to increase the cost of fixing defects significantly when
compared with systems written in either C or Pascal. It goes on to
suggest that at least some aspects of OO, for example inheritance, do
not fit well with the way we make mistakes."
Try and find and experienced OO developer who would advocate that large, 
complex generalizations are a good practice.  You can write lousy 
programs in any paradigm.  The likelihood increases when you use the 
most technically deficient of all the OOPLs.  (If those developers had 
used Smalltalk, I'll bet their defect rates would have been 
substantially lower even if they weren't very good OO developers.)

His comments under "invited feedback" are amusing and confirm my
impression that OOP is partly (but perhaps not entirely) hype:
"I should not that this paper because it criticised OO had an unusually
turbulent review period. 2 reviewers said they would cut their throats
if it was published and 3 said the opposite. The paper was only
published if the OO community could publish a rebuttal. I found this
very amusing as my paper contains significant data. The rebuttal had
none. This sort of thing is normal in software engineering which mostly
operates in a measurement-free zone."
Part of that criticism was that his experiments were uncontrolled. 
There was no attempt made to ensure that the programs under either 
paradigm were of high quality for the paradigm.  There were other 
experimental issues, such as the scale of the programs, that make the 
data anecdotal at best and a stacked deck at worst.

What papers have scientific evidence for OOP?
I don't know of any large, controlled studies but there must be some 
buried in PhD theses somewhere.  There is substantial anecdotal evidence 
to the contrary, though.  For example, where I worked before retiring we 
ran a number of experiments to determine whether we should adopt OO 
development.  One experiment was for exactly the same MLOC application 
(originally written in BLISS) that was rewritten in C and then in C++ 
using good OOA/D.  The same developers, who were domain experts, were 
used.  Both C and C++ were new languages for most of them.  [While they 
were proficient at procedural development, OO was OJT.  However, 
extensive OOA/D training was provided.]

The initial development times were about the same, probably due to the 
OO learning curve.  The released defect rates for the OO version were 
about 1/2 those of the C version.  The big difference, though, was in 
maintenance time, which was nearly an order of magnitude less for the OO 
version.  One of the first major rounds we estimated to take 6 
engineering months using the established techniques we used for 
procedural development (which were accurate to -5/+15%).  Three people 
turned the changes on the OO version in a week -- to the amazement of 
everyone, including ourselves.  Besides hard comparative data on time 
spent, the permanent maintenance staff for the application dropped from 
8 full-timers for the C version to one guy half-time for the OO version.

While this is anecdotal (among other things, it is dependent on the 
OOA/D methodology employed), it was done with a whole lot more control 
than Hatton's experiments.  [We were a very process-oriented shop that 
insisted on hard experimental data before instituting any process 
change.  We also collected data religiously.  Not a lot of shops can 
tell you immediately how much time the average developer spends in 
meetings or the average time it takes to diagnose a memory over-write 
problem.  B-)]

Paul Graham's skeptical comments on OOP are at
http://www.paulgraham.com/noop.html .
If OOP is so beneficial for large projects, why are the Linux kernel,
the interpreters for Perl and Python, and most compilers I know written
in C rather than C++?
The main reason is performance.  All those examples are very performance 
sensitive.  C will be ~twice as fast as C++ and C++'s design compromises 
were made specifically to enhance its performance!  In addition, 
physical coupling is a much bigger problem in the OOPLs than in 
procedural languages, so build time can become an issue for larger 
applications.

[The OO translation-based approaches that do full code generation from 
OOA models usually target straight C as the implementation language for 
performance sensitive situations in R-T/E.  (Also, translation code 
generators can usually generate OOPL source code faster than it can be 
compiled, but that is usually not true for C.)]

*
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
[EMAIL PROTECTED]
Pathfinder Solutions  -- Put MDA to Work
http://www.pathfindermda.com
blog (under constr): http://pathfinderpeople.blogs.com/hslahman
(888)-OOA-PATH

--
http://mail.python.or

Re: Python IDE

2004-12-15 Thread fuzzylollipop
TruStudio for Eclipse is nice for those everything must be free
socialists.
ActiveState Komodo is probably the best commerical Python IDE
and the ActiveState Python plugin for Visual Studio is great for those
that do VS.

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


Re: getopt: Make argument mandatory

2004-12-15 Thread Frans Englich
On Wednesday 15 December 2004 20:12, Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, Frans Englich
>
> wrote:
> > Hello,
> >
> > In my use of getopt.getopt, I would like to make a certain parameter
> > mandatory.
>
> Isn't a *mandatory option* a contradiction?  Why don't you turn it into an
> argument?  You already called it argument in the subject of your post.

I probably used an inconsisten wording; option equals argument. My point is to 
make an option/parameter/argument/call-it-what-you-like mandatory. When that 
particular option/argument then also has a value(instead of a simple toggle), 
that means a user specified value must always be specified.


Cheers,

Frans

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


A beginner's problem...

2004-12-15 Thread Amir Dekel
Hello everyone,
First, I have to say that Python is one of the coolest programing 
languages I have seen.
And now for the problem (must be a silly one):
When I import a module I have wrote, and then I find bugs, it seems that 
I can't import it again after a fix it. It always shows the same 
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?
Amir
--
http://mail.python.org/mailman/listinfo/python-list


Re: A beginner's problem...

2004-12-15 Thread Robert P. J. Day
On Wed, 15 Dec 2004, Amir Dekel wrote:

> Hello everyone,
>
> First, I have to say that Python is one of the coolest programing languages I
> have seen.
> And now for the problem (must be a silly one):
> When I import a module I have wrote, and then I find bugs, it seems that I
> can't import it again after a fix it. It always shows the same problem. I try
> del module but it doesn't work.
> (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
>
> Solution anyone?

reload?

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


Module question

2004-12-15 Thread Bill Turczyn
Does python have a module similiar to the perl Spreadsheet::WriteExcel
Thanks,
Bill

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


Re: A beginner's problem...

2004-12-15 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Amir Dekel wrote:

> When I import a module I have wrote, and then I find bugs, it seems that 
> I can't import it again after a fix it. It always shows the same 
> problem. I try del module but it doesn't work.
> (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
> 
> Solution anyone?

Yes -> help(reload)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-15 Thread David Bolen
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:

> Can you elaborate? To me, that problem only originates from
> the OS lack of support for deleting open files. If you could
> delete a shared libary that is still in use (as you can on
> Unix), the put the new version of the DLL in the place, (...)

Note that at least on NT-based systems, you can at least rename the
existing file out of the way while it is in use in order to install a
new version.

I do think however, that until more recent changes (not sure whether
in 2K versus XP) in how DLL searches work (e.g., permitting local
versions), even with that operation, if a named DLL was available
loaded into memory, it would be used by a subsequent process
attempting to reference it regardless of the state of the filesystem.

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


Re: Step by step: Compiling extensions with MS Visual C++ Toolkit 2003 - msvccompiler-patch.txt (0/1)

2004-12-15 Thread Mike C. Fletcher
Martin Bless wrote:
...
Two things first - not to forget:
(1) In contrast to what Mike writes I had to use a different registry
key (see step 9)
 

Which is expected (even noted on the page), particularly if you have a 
different version of the SDKs.  The keys in the patch were extracted 
from an English Win2K Platform SDK.  Don't know of any *good* way to 
figure out the keys in a version-agnostic manner.  Suggestions welcome...

(2) I don't now what people mean when talking about "msvcr71.lib".
There's no such file on my machine. BUT there IS a "msvcrt.lib" a
directory "C:\Programme\Microsoft Visual Studio .NET 2003\Vc7\lib". I
guess the ".\Vc7\." indicates we are talking of the expected lib.
Correct? I don't know.
 

This was sloppy on my part.  msvcr71.dll is the DLL used for Visual 
Studio 7.1, we want the .lib for that version of the DLL, but as you 
note, it is actually named msvcrt.lib (same as the one for Visual Studio 
6.0).

Get and install the platform SDK "Windows XP SP2 SDK" (about
 

...
It is
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs\B44C7E10-89BD-4A32-A3BF-D9D0BC4C9A05
and it is not
...\63DADB24-DC99-45EB-A748-EC93AB8A7497.
Find out about the correct key in your case and adjust the crucial
line 133 in msvccompiler.py: 

freeSDK=r"SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs\B44C7E10-89BD-4A32-A3BF-D9D0BC4C9A05"
 

...
Will have to figure out how to make this work across SDK versions somehow.
Thanks for the report,
Mike

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-15 Thread Mark Asbach
Hi Lucas,

> No,the reason that you see 2 times as many processors as really are 
> installed is the hyperthreading feature of the Xeon (see 
> http://www.infoworld.com/infoworld/article/02/02/25/020225plxeon_1.html)
> 
> I turned it off (in the BIOS). The machine I tested on has 2 (pysical)
> processors installed. Turning on or off does not influence the pystone
> number significantly..

Sorry for the confusion - that was what I wanted to say: from my
perspective it is unlikely that the performance decrease seen on your
dual processor CPU is related to having two processors. Because python
thinks it has two processors on my machine, too (because of
hyperthreading) and should exhibit the same decrease then (IF it would
be coupled to two processors).

Yours,

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


Re: while 1 vs while True

2004-12-15 Thread Terry Reedy

> >>> import pdb
> >>> pdb.x = "Darn writeable module dictionaries"
> >>> from pdb import x
> >>> x
> >>>'Darn writeable module dictionaries'

> If Python really does behave that way, that bug should be fixed 
> immediately.

The fact that the attributes of Python modules, like those of classes (and 
functions and instances) are externally mutable is a design feature, not a 
bug.  (Call Python's dynamicity a design bug if you will, but that is 
different from a plain 'bug'.)

This allows, for instance, programs to have an in-memory blackboard module 
with across-module variables that all other modules can write to as well as 
read.  This design has been recommended several times on this list.  We 
would, of course, all agree that having modules arbitrarily poking each 
others attributes is a bad idea.  Indeed, that is the rationale for 
isolating all such pokes into a single blackboard module.

Terry J. Reedy



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


Re: lies about OOP

2004-12-15 Thread Martijn Faassen
Peter Hansen wrote:
Martijn Faassen wrote:
Paul McGuire wrote:
"Martijn Faassen" <[EMAIL PROTECTED]> wrote in message

Yikes!  (or better, "Jikes!" or even "Yijkes!"?) - my bad.
And he was on faculty at UT right here in Austin, too.
It's a very common mistake I've seen so often that for a while I 
wondered whether his name really *was* Djikstra, but I knew he was 
Dutch and that it couldn't be so. That the PSU picked you for its 
disclosure is just a random coincidence, I'm sure.. :)
Well, in any case, thanks for setting the record straight, Martjin.
That of course also happens to me once every while. I can take care of 
myself though -- Dijkstra however needs an advocate for the correct 
spelling of his name in this earthly realm.

Imagine, for instance, what if he wants to egosurf, google for his own 
name and finds nothing because everybody was saying Djikstra all the 
time? That'd be terrible! What, they don't have google in the eternal 
realm? How can it be valhalla without google? Impossible.

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


Re: NO REALLY

2004-12-15 Thread Martijn Faassen
Jive wrote:
Isn't there a comp.lang.flame or something?
I've doublechecked, but I didn't see any significant flaming in this 
article (and I'm generally not very tolerant of it). My PSU posting was 
certainly not intended as a flame, in case that was misinterpreted.

What'd I miss?
Regards,
Martijn
--
http://mail.python.org/mailman/listinfo/python-list


Re: from string to raw string

2004-12-15 Thread Scott David Daniels
Dan Perl wrote:
Is there a way to convert a regular string to a raw string so that one could 
get from '\bblah' to r'\bblah' other than parsing the string and modifying 
the escapes?
Assuming you might mean something else, that something else might be:
   s = r'no_tab_\t_here'
   len(s.split()) == 1
   len(s.decode('string_escape').split()) == 2
   s = 'tab_\t_here'
   len(s.split()) == 2
   len(s.encode('string_escape').split()) == 1
-Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-15 Thread Peter Hansen
Martijn Faassen wrote:
Peter Hansen wrote:
Well, in any case, thanks for setting the record straight, Martjin.
That of course also happens to me once every while. I can take care of 
myself though -- Dijkstra however needs an advocate for the correct 
spelling of his name in this earthly realm.
Then there's us Danes, with "sen" instead of "son" (as many people
think it ought to be).  And I can't even claim the wrong form
sounds noticably different, making any defense seem petty.
(Darn those Norwegians, influencing people's ideas of how a
name like Hansen ought to be spelled, grumble, grumble.
If they'd just invent a cell phone that used Python, as the
Swedish have, they might deserve all that extra attention.)
;-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: NO REALLY

2004-12-15 Thread Peter Hansen
Martijn Faassen wrote:
Jive wrote:
Isn't there a comp.lang.flame or something?
I've doublechecked, but I didn't see any significant flaming in this 
article (and I'm generally not very tolerant of it). My PSU posting was 
certainly not intended as a flame, in case that was misinterpreted.

What'd I miss?
Has the PSU checked on the whereabouts of the time machine lately?
Maybe Jive took it.  I did hear it had gone missing.
I could easily see this thread descending into a flame war in,
oh, about another ten posts.  That would be so freaky...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module question

2004-12-15 Thread elbertlev

Goggle: keyword pyXLWriter - ported from Perl. Does not support newer
exel files. F.e. if you create a table and write headers (names) they
will be in the table as row 0. But it is fast and it works. Has a lot
of examples.

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


Dejavu 1.2.6, a Python ORM

2004-12-15 Thread Robert Brewer
The Dejavu Object-Relational Mapper (version 1.2.6) is now available and
in the public domain. Get it at svn://casadeamor.com/dejavu/trunk.

Dejavu is an Object-Relational Mapper for Python applications. It is
designed to provide the "Model" third of an MVC application. Dejavu
avoids making decisions in the framework which are better left to
developers, and avoids forcing developers to make decisions which are
better left to deployers. In particular, deployers are allowed to mix
and match storage mechanisms, including how and when to cache objects in
memory, making it easier for deployers to tune applications to their
particular environment.

Dejavu provides:

MODELING LAYER
1. A subclassable Unit class for persisting objects to storage.
2. A base Unit Property class for declaring persistent object
attributes.
3. ID Sequencers.
4. Associations between Unit classes.
5. Unit Engines, Rules, and Collections.
6. Aggregation and analysis tools.

APPLICATION LAYER
1. Expressions: pure Python Unit queries. This is perhaps the most
appealing feature of Dejavu. However, since it uses bytecode hacks,
Dejavu only runs on CPython.
2. Sandboxes, which serve as Identity Maps and per-connection caches.
Unit objects are "memorized" and "recalled" from a Sandbox, using
Expressions.
3. An Arena class for application-level data.

STORAGE LAYER
1. A subclassable StorageManager class and specification. Unlike many
ORMs, Dejavu does not require you to have complete control of your back
end.
2. Specific StorageManagers for:
   a. Microsoft SQL Server via ADO.
   b. Microsoft Access (Jet) via ADO.
   c. ODBC databases (not complete = broken)
   d. Shelve to dbm.
   e. Future versions of Dejavu will support PostgreSQL, MySQL, and
SQLite. Others are being considered.

Dejavu welcomes your use and feedback as an application developer.

Dejavu also welcomes framework developers. New code for additional
Storage Managers, analysis tools, will be gladly reviewed for inclusion
in future releases. Drop me an email if you feel so inclined.


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


Re: Module question

2004-12-15 Thread Mike Meyer
Grumman <[EMAIL PROTECTED]> writes:

> Bill Turczyn wrote:
>> Does python have a module similiar to the perl Spreadsheet::WriteExcel
>> Thanks,
>> Bill
>>
> In a pinch, you can output an HTML table, give the file an .xls
> extension, and Excel will read it just fine.

Welll, someone pointed out a third party package to do the job. I want
to point out  the csv module included in the standard
distribution. That should work as well as an HTML table, with less
clutter in the file.

 http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I convert characters into integers?

2004-12-15 Thread Scott David Daniels
Markus Zeindl wrote:
Hello,
I want to write a simple encrypter, but I've got a problem:
How can I convert characters into integers?

Check this out, you'll like it even more than ord/chr:
import array
def mangle(message):
a = array.array('B')
a.fromstring(message)
for i in range(len(a)):
a[i] += 1
return a.tostring()
print mangle('Hello, Harry')
-Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: A beginner's problem...

2004-12-15 Thread DogWalker
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> said:

>In <[EMAIL PROTECTED]>, Amir Dekel wrote:
>
>> When I import a module I have wrote, and then I find bugs, it seems that 
>> I can't import it again after a fix it. It always shows the same 
>> problem. I try del module but it doesn't work.
>> (I use Python 2.4 with the ActivePython pack (PythonWin IDE)
>> 
>> Solution anyone?
>
>Yes -> help(reload)
>
>Ciao,
>   Marc 'BlackJack' Rintsch

First, save the file using the check option (Ctl+Shift+C, iirc);
Second, Fix any errors (attend to Status Bar);
Third, press Reload button in Toolbar (or type command from File Menu).
Four, assure that Status Bar indicates reload was successful.
If still doesn't load correctly, quit PythonWin and start it again.
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is Python good for graphics?

2004-12-15 Thread Esmail Bonakdarian
Fredrik Lundh wrote:
how about:
http://vpython.org/
hi,
thanks, I didn't know about that.
do you (or anyone else) have a recommendation for 2D type
graphics?
Thanks,
Esmail
--
http://mail.python.org/mailman/listinfo/python-list


Unpacking Binary Data - not using struct module

2004-12-15 Thread Geoffrey
I am working on a file conversion project that reads data from a one
file format, reformats in and writes in out to another.  The data is
records of informations - names address, account number,statistics.

The numeric values in the original file are stored in what appears to
be a "packed" data format,using a structure that does not use any of
the more standard "C" formats, so I can't use the "struct" module.

As an example, the number "1130" is store using 3 bytes.  The HEX
values of the 3 bytes would be  0x01,0x13,0x0F.In other words, the
hex value value "01130f" is unpacked to become "1130".

I believe the original program is written in a version of "Basic" that
dates from the early 90's if that helps.

Currently, I have no problem reading the data.  I read the three bytes
and use the binascii.hexilify() function convert the hex values to
their corresponding ASCII values, and then slice off the trailing "f".
 In other words;

unpackednumber = int(binascii.hexlify(0x1130f)[:-1])

My questions ...
1) Does anyone recognize this numeric format ?
2) Is there a more efficient module/function I can use, or is the
above the best method?
3) I think that the trailing "f" is sometimes used to indicate the
sign of the number and perhaps even the number of decimal places ...
but am not sure.

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


Re: NO REALLY

2004-12-15 Thread Peter Hansen
Brian van den Broek wrote:
Peter Hansen said unto the world upon 2004-12-15 17:39:
I could easily see this thread descending into a flame war in,
oh, about another ten posts.  That would be so freaky...
Without a doubt that is the most ignorant and small-minded thought that 
ever has been, and ever could be, committed to words!
And you, sir, must be, like, one of those Nazi type people,
like that guy, uh, what was his name? er.. Godwood, Goodwin, something
like that, anyway.  (Hey, Jive, you happy yet?)
(My research project to build a super-cooled ultra-efficient time 
machine goes poorly. To save the funding, I'm driven to fudging the 
data. ;-)
Mm fudge
Brian, with the two paragraphs of yours that I've quoted above,
I'm happy to say that this is the first time I've ever been
completely justified in calling someone a "flaming lunatic".
;-)
--
http://mail.python.org/mailman/listinfo/python-list


spawn* or exec* and fork, what should I use and how ?

2004-12-15 Thread Lingyun Yang
Hi,
  I want to use python as a "shell like" program,
and execute an external program in it( such as mv, cp, tar, gnuplot)
I tried:
os.execv("/bin/bash",("/usr/bin/gnuplot",'-c "gnuplot < plot.tmp"'))
since it's in a for-loop, it should be executed many times, but
It exits after the first time running.
so I have to use spawn* like this:
os.spawnlp(os.P_WAIT, 'gnuplot', 'gnuplot', 'plot.tmp')
It works very well.
My question is,
1. why my exec(..) command doesn't work?
2. exec* must be with fork ?
3. In what situation, we choose one over another ?
Thank you!
regards,
Lingyun
--
http://mail.python.org/mailman/listinfo/python-list


Re: spawn* or exec* and fork, what should I use and how ?

2004-12-15 Thread Binu K S
exec calls will replace the script process with the new process.

>From the execv documentation:
"These functions all execute a new program, replacing the current
process; they do not return. On Unix, the new executable is loaded
into the current process, and will have the same process ID as the
caller. Errors will be reported as OSError exceptions."

As Peter suggested, use the subprocess module in Python 2.4.

On Thu, 16 Dec 2004 03:00:45 GMT, Lingyun Yang <[EMAIL PROTECTED]> wrote:
> Hi,
> 
>I want to use python as a "shell like" program,
> and execute an external program in it( such as mv, cp, tar, gnuplot)
> I tried:
> 
> os.execv("/bin/bash",("/usr/bin/gnuplot",'-c "gnuplot < plot.tmp"'))
> 
> since it's in a for-loop, it should be executed many times, but
> It exits after the first time running.
> 
> so I have to use spawn* like this:
> 
> os.spawnlp(os.P_WAIT, 'gnuplot', 'gnuplot', 'plot.tmp')
> 
> It works very well.
> 
> My question is,
> 
> 1. why my exec(..) command doesn't work?
> 2. exec* must be with fork ?
> 3. In what situation, we choose one over another ?
> 
> Thank you!
> 
> regards,
> Lingyun
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spawn* or exec* and fork, what should I use and how ?

2004-12-15 Thread Lingyun Yang
Peter Hansen wrote:
Lingyun Yang wrote:
  I want to use python as a "shell like" program,
and execute an external program in it( such as mv, cp, tar, gnuplot)
os.execv("/bin/bash",("/usr/bin/gnuplot",'-c "gnuplot < plot.tmp"'))

I would suggest checking out the "subprocess" module,
new in Python 2.4.  It subsumes the functionality
of most of the alternative methods such as execv and
spawn and os.system(), and provides an arguably cleaner
interface.
-Peter
Thank you!
I got the document about subprocess,
http://www.python.org/dev/doc/devel/lib/module-subprocess.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: ftp

2004-12-15 Thread Binu K S
Try retrbinary instead of retrlines in the original script (the one
without write('\n')).
retrlines fetches the file in ASCII mode and that must be altering the
line terminations.

On 15 Dec 2004 15:49:31 -0800, hawkmoon269 <[EMAIL PROTECTED]> wrote:
> I would like to write a small ftp script that I could use in place of
> DOS.  So far I have this --
> 
> from ftplib import FTP
> 
> server = 'xxx'
> username = 'xxx'
> password = 'xxx'
> file = 'xxx'
> 
> ftp = FTP(server)
> ftp.login(username, password)
> ftp.retrlines('RETR ' + file, open('C:\My Documents\' + file,
> 'w').write
> 
> but this just writes the source files contents into a giant string in
> the output file.  The source file is comma-delimited with a
> fixed-length of 80 chars per line.  I need the same format for the
> output file.  I've tried this --
> 
> ftp.retrlines('RETR ' + file, open('C:\My Documents\' + file,
> 'w').write('\n')
> 
> and that gives the correct output format...but it writes the output to
> the IDE interpreter command line and not the file.  What am I doing
> wrong?
> 
> hawk
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from string to raw string

2004-12-15 Thread Dan Perl
This is not what I meant.  My posting was a judgement error.  You are right 
though that my intuition was leading me to something like this.  However, I 
didn't realize that it was not necessary for what I was doing.  But this is 
very educational too.  It made me look up string decode, encode, and codecs 
in the library reference and I found out more about them.  I'm sure it's 
going to be useful.  Thanks!

Dan

"Scott David Daniels" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Dan Perl wrote:
>> Is there a way to convert a regular string to a raw string so that one 
>> could get from '\bblah' to r'\bblah' other than parsing the string and 
>> modifying the escapes?
>
> Assuming you might mean something else, that something else might be:
>
>s = r'no_tab_\t_here'
>len(s.split()) == 1
>len(s.decode('string_escape').split()) == 2
>s = 'tab_\t_here'
>len(s.split()) == 2
>len(s.encode('string_escape').split()) == 1
>
> -Scott David Daniels
> [EMAIL PROTECTED] 


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


Re: lies about OOP

2004-12-15 Thread Andrew Dalke
Peter Hansen:
> (Darn those Norwegians, influencing people's ideas of how a
> name like Hansen ought to be spelled, grumble, grumble.

And then there's my sister, a Nelson, who drove with friends
of their's, the Olsons, to visit our aunt and uncle, the Larsons,
and my grandmother, born a Hanson.  Scandinavian heritage?
Det vet jag inte.  :)

Sadly, none of them know Python.  And my g'grandfather was
German in case you were wondering.

Andrew Dalke
[EMAIL PROTECTED]

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


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-15 Thread Dan
Skip Montanaro wrote:
Dan> I also see an 8-10% speed decrease in 2.4 (I built) from 2.3.3
Dan> (shipped w/Fedora2) in the program I'm writing (best of 3 trials
Dan> each).  Memory use seems to be about the same.
How do you how the compiler flags were the same if you didn't compile both
versions yourself?
I don't, and I also don't know if the Redhat folks modified the sources 
in some way.  That's why I mentioned the difference in builds.  But I 
suppose that makes this as good as no data.

/Dan
--
dedded att verizon dott net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zope side-by-side with Python 2.4

2004-12-15 Thread Terry Hancock
On Friday 03 December 2004 02:04 pm, Robert wrote:
> If I have Python 2.4 installed and I want to install the latest stable
> Zope, will Zope have problems or does Zope looks to its own setup and
> not my install of Python 2.4?

The latest version of Zope (2.7 or later) runs fine with Python 2.3
and should run with Python 2.4 unless you know something about it
that I don't.

It is possible to have multiple versions of python installed at once, however,
so long as you explicitly call, e.g. "python2.3" when you want that version.

The detailed instructions for how to do the latter will depend on the OS
you are running.

Cheers,
Terry

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

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


Re: Is Python good for graphics?

2004-12-15 Thread Robert Kern
Esmail Bonakdarian wrote:
Fredrik Lundh wrote:
how about:
http://vpython.org/

hi,
thanks, I didn't know about that.
do you (or anyone else) have a recommendation for 2D type
graphics?
I like Kiva (but then, I also help develop it). The best place to get it 
right now is the SVN repository, but it's fairly stable.

http://svn.enthought.com/svn/enthought/branches/converge/kiva/
--
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


  1   2   >