Re: New versions breaking extensions, etc.

2004-12-11 Thread Martin v. Löwis
Jive wrote:
Why won't extensions compiled to run with 2.3 also work with 2.4? 
I believe nobody has answered *this* question, yet:
Python extensions built for 2.3 link with python23.dll, Python
extensions build for 2.4 link with python24.dll.
pythonxy.dll has global variables, e.g. the pointers to True,
False, None, or the dict type object. If you have two copies
of the Python runtime, you get two copies of each local object.
This cannot work: we really need to rely on having only one
dict type, or else is comparisons with the dict type fail.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-11 Thread Bengt Richter
On 10 Dec 2004 15:03:01 -0800, [EMAIL PROTECTED] wrote:

Well, that could be a feature, depending on what your use case is.
Or you could make a method for adding methods, I suppose.
A perfectly transparent wrap of obj would be to do nothing ;-)
What do you actually want to do?

Actually, the very best would if only type(), isinstance() and the
is-keyword could an object and a wrapped version of it apart.

I've thought of using a weakdict instaed, problem is, it would be a
little bit too transparent for my purpose as the only way to tell an
object and a wrapped version of it apart would be by my own functions
which would do lookups in that dict. Secondly, it would only allow for
one comment per object dopy, which would fail horribly for e.g. numbers
(there are hundreds of uses of the number 1, which all needs different
comments for the number).


Here is a different approach, which I think will perform better than masses
of descriptors and delegations and individual classes, plus wrapping is
just a single assignment. See the W0, W1, W2 usage in the example below.

The idea is to clone the object's class as a subclass in a factory 
(wrapperclass)
function that takes an example object plus a second argument containing
new or overriding methods and/or class variables. This add-ins argument
is just a class, and everything except what comes in an empty class
(i.e., ['__dict__', '__module__', '__weakref__', '__doc__'] ) is copied
from the dict in to the wrapper class dict, which is initialized as
a clone of the object's class dict.


 wrapo.py -
# wrapo.py -- wrapperclass factory and usage examples
# 20041211 01:02:54 -- bokr
# Use at your own risk. Alpha.

def wrapperclass(obj, AddIns):

Create a (sub)class which may be assigned to obj.__class__
to change the obj instance's apparent available methods
and class variables, taking additions from a supplied
AddIns class serving as a container for methods and variables.

cdict = dict(type(obj).__dict__)
for name, value in AddIns.__dict__.items():
if name not in ['__dict__', '__module__', '__weakref__', '__doc__']:
cdict[name] = value
cname = 'Wrapped_%s_%s'%(AddIns.__name__, type(obj).__name__)
W = type(cname, (type(obj),), cdict)
return W

import time
class Wrap_one(object):
cvar = 'Wrap_one cvar'
def now(self): return 'W1: '+time.ctime()
def __repr__(self):
return 'Wrap_one %r repr:\n%s'%(self.kw, object.__repr__(self))
def __add__(self, other):
return '%r + %r'%(self,str(other))

class Wrap_two(object):
# let orig cvar alone
def now(self): return 'W2: '+time.ctime()
def __repr__(self):
return 'Wrap_two %r repr:\n%s'%(self.args, object.__repr__(self))
def __add__(self, other):
return '%r + %r'%(type(self).__name__, str(other))

def test():
class Foo(object):
cvar = 'orig Foo cvar ;-)'
def __init__(self, *args, **kw):
self.args = args
self.kw =kw
def now(self): return '(time n/a)'
def __str__(self):
return '%s %r\n  %s'%(self.now(), self.cvar, repr(self))
foo = Foo(1,2,3, x=111,y=222)
W0 = type(foo)
W1 = wrapperclass(foo, Wrap_one)
W2 = wrapperclass(foo, Wrap_two)
print '--- plain foo:\n', foo
for w in (W0, W1, W2, W0):
foo.__class__ = w
print '\n %s ' % type(foo).__name__
print foo
if w!=W0: print foo + ' a %s string.'%w.__name__
bar = Foo(22,33,bar='this is bar')
for w in (W0, W1, W2, W0):
bar.__class__ = w
print '\n %s ' % type(bar).__name__
print bar

if __name__ == '__main__':
test()
-

Result:

[ 1:16] C:\pywk\clp\wrapperwrapo.py
--- plain foo:
(time n/a) 'orig Foo cvar ;-)'
  __main__.Foo object at 0x00901630

 Foo 
(time n/a) 'orig Foo cvar ;-)'
  __main__.Foo object at 0x00901630

 Wrapped_Wrap_one_Foo 
W1: Sat Dec 11 01:16:40 2004 'Wrap_one cvar'
  Wrap_one {'y': 222, 'x': 111} repr:
__main__.Wrapped_Wrap_one_Foo object at 0x00901630
Wrap_one {'y': 222, 'x': 111} repr:
__main__.Wrapped_Wrap_one_Foo object at 0x00901630 + ' a 
Wrapped_Wrap_one_Foo string.'

 Wrapped_Wrap_two_Foo 
W2: Sat Dec 11 01:16:40 2004 'orig Foo cvar ;-)'
  Wrap_two (1, 2, 3) repr:
__main__.Wrapped_Wrap_two_Foo object at 0x00901630
'Wrapped_Wrap_two_Foo' + ' a Wrapped_Wrap_two_Foo string.'

 Foo 
(time n/a) 'orig Foo cvar ;-)'
  __main__.Foo object at 0x00901630

 Foo 
(time n/a) 'orig Foo cvar ;-)'
  __main__.Foo object at 0x00901390

 Wrapped_Wrap_one_Foo 
W1: Sat Dec 11 01:16:40 2004 'Wrap_one cvar'
  Wrap_one {'bar': 'this is bar'} repr:
__main__.Wrapped_Wrap_one_Foo object at 0x00901390

 Wrapped_Wrap_two_Foo 
W2: Sat Dec 11 01:16:40 2004 'orig Foo cvar ;-)'
  Wrap_two (22, 33) repr:
__main__

Re: GUIs: wxPython vs. Tkinter (and others)

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

 I don't know about wxPython, but PyQt includes it's own threading
 facility, plus hooks to talk to databases.

That would of course be a great argument if Python didn't already have
a threading facility, and a standard API for talking to databases with
implementations for all major players.

 It also has a widget for creating Windows wizards for walking
 through a set of options.

Besides the fact that wizards isn't really that great (read Cooper), if your
toolkit doesn't let you create a dialogue with a couple of buttons and a
swappable frame, it's not a very good toolkit.  (that's very easy, in both
Tkinter and wxPython.  You can probably find ready-made modules on
the net if you look around a little)

 o Is the general programming methodology pretty much the same between
 the two (e.g., the general program structure - using callbacks  Frames,
 etc. is the same, it's just a question of calling different widgets with
 their own arguments)?

 Not for Qt. It has the notion of SLOTs and SIGNALs. You connect a
 signal from an object to a slot or signal on another (or the same)
 object. You can, for example, connect a signal from a slider widget to
 a slot on a digital display widget, thus causing the display to change
 as you move the slider.

 At the python level, slots are just callable objects. At the
 C++ level, slots are magic methods of objects. Signals are usually
 associated with GUI events, but Python can emit them for whatever
 reason it wants. It's possible to connect C++ signals to C++
 slots/signals in Python, meaning that Python won't be involved when
 that signal is emitted.

That's would of course be a great argument if you didn't have Python.
(even if Python's slower than C++, it's a lot faster than a user).

If you want bind an event source (signal) to a slot (method) in one line,
use a lambda.  If you need to add more behaviour (you usually do), use
a function.

 PyQt provides a higher level of abstraction.

Whan what?  C++ plus a low level UI API, sure.  But Tkinter+Python?
wxPython+Python?  You gotta be kidding.

(or you're borrowing it from Trolltech's marketing material; I notice that
the phrase higher level of abstraction is very popular amont Qt fans, but
Trolltech themselves only seem to use it when they talk about lower-level
libraries like X/Xt/Motif and the native Win32 API)

 I've never tried doing animation in TkInter. Qt provides timer devices
 that you can use to drive animations. I suspect that doing the same in
 TkInter would be noticably more difficult.

Eh?  You don't know how to do a loop in Python?  Or register a callback?
wxPython contains both timers and a low-level graphics API; for Tkinter,
you the after facility and the Canvas; if you need lower-level drawing
with tighter Python intergration, use the WCK.

(for more advanced drawing, I'd recommend OpenGL, which is available
for them all)

/F 



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


Re: Howto Extract PNG from binary file @ 0x80?

2004-12-11 Thread Fredrik Lundh
flamesrock [EMAIL PROTECTED] wrote:

 As a newbie to the language, I have no idea where to start..please bare
 with me..

 The simcity 4 savegame file has a png image stored at the hex location
 0x80. What I want to extract it and create a file with the .png
 extension in that directory.

 Can somebody explain with a snippet of code how I would accomplish
 this? I've looked around but the information is too vague and I don't
 know how to start.

there are *many* ways to ignore the first 128 bytes when you read a file
(you can seek to the right location, you can read 128 bytes and throw them
a way, you can read one byte 128 times and throw each one of them away,
you can read all data and remove the first 128 bytes, etc).

here's a snippet that understands the structure of the PNG, and stops copying
when it reaches the end of the PNG:

import struct

def pngcopy(infile, outfile):

# copy header
header = infile.read(8)
if header != \211PNG\r\n\032\n:
raise IOError(not a valid PNG file)
outfile.write(header)

# copy chunks, until IEND
while 1:
chunk = infile.read(8)
size, cid = struct.unpack(!l4s, chunk)
outfile.write(chunk)
outfile.write(infile.read(size))
outfile.write(infile.read(4)) # checksum
if cid == IEND:
break

to use this, open the input file (the simcity file) and the output file
(the png file you want to create) in binary mode, use the seek
method to move to the right place in the simcity file, and call pngcopy
with the two file objects.

infile = open(mysimcityfile, rb)
infile.seek(0x80)
outfile = open(myimage.png, wb)
pngcopy(infile, outfile)
outfile.close()
infile.close()

hope this helps!

/F 



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


Re: New versions breaking extensions, etc.

2004-12-11 Thread Martin v. Löwis
Jive wrote:
The other
issue is that the interpreter and the extensions may be linked to
different versions of the Microsoft runtime.

Doesn't Microsoft have an answer for that?
Microsoft's answer to this question is: don't do that. Never
mix different versions of the CRT in a single application.
There are (at last count) nine skillion ActiveX
components in the wild.  Surely Microsoft didn't blast them into oblivion
with dot-net -- did it?
No, it didn't - but so what? The point is that ActiveX controls normally
don't use the CRT in dangerous ways, since they are constrained to use
Co* function calls only.
I remember having trouble with that last bit once.  But I seem to recall
there was an easy
answer.  Something to do with the main ap and the DLL using the same heap or
some
such thing.
Something like that, for sure.
[require that extensions be recompiled]
It would be a Good Thing to put a stop to that requirement, no?
No. The maintenance cost of such a new API would be significantly
higher, and Python would lose some of its attractiveness for C
developers.
No doubt.  I don't understand what the deal is with msvcr71 and all that,
You probably either need to learn what the deal is, or else you have to
trust others that there is no better way.
That would be good.   But is using VC++ 6.0 right out?  As it stands, I can
no longer build extensions that will run with a standard dot-net Python 
 2.4 release. Or at least I don't know how.
The most easy way to do this is to use VC7.1 (VS.NET 2003). That will
work out of the box (you need to box first, of course).
Thinking it over, I'm wondering why the Python crowd went with dot-NET in
the first place.
We did not go to .NET. Python 2.4 has nothing to do with .NET. It just
happens that the C compiler we use ships as part of a product that has
.NET in its name - the C compiler itself is Microsoft Visual C 7.1,
aka Microsoft C 13.10.
That compiler is now used because it has a number of improvements over
Microsoft C 12.00, and because VC6 is no longer commercially available.
Many developers have only VS .NET 2003 available, so if Python would
continue to be built with VC6, those people could not build
extensions for it - they could not even buy the compiler they needed,
anymore. OTOH, people who only have VC6 just need to buy VS.NET 2003,
which is still available. Or else they find out what alternative
compiler arrangements can be made.
Surely the world would be a better, happier place without MS jerking
everyone around.
It would surely be better if the operating system shipped with a
compiler, so anybody could rebuild things, and you wouldn't need
binary distributions in the first place :-)
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs: wxPython vs. Tkinter (and others)

2004-12-11 Thread Jarek Zgoda
Fredrik Lundh wrote:
I don't know about wxPython, but PyQt includes it's own threading
facility, plus hooks to talk to databases.
That would of course be a great argument if Python didn't already have
a threading facility, and a standard API for talking to databases with
implementations for all major players.
Python threading is not perfect in many cases in GUI programming -- you 
have to implement your own notification mechanism (eg. using queue 
polling), as usually you can communicate with GUI only from main 
application's thread. While this is the case also for Qt, QThread 
instances have ability to post events to any arbitrary Qt objects, thus 
making life a bit easier.

Anyway, all of above mentioned toolkits have its own pros and cons and 
in most of cases choice is a matter of personal taste.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-11 Thread Nick Craig-Wood
Nick Craig-Wood [EMAIL PROTECTED] wrote:
  Robert Kern [EMAIL PROTECTED] wrote:
   Personally, I loathe writing at any length inside a Web browser and 
   prefer to use a real editor at all times.
 
  Me too!  You need mozex...
 
http://mozex.mozdev.org/

Here is a good page about Wikis (from the creators of spamassassin)
including stuff about Moin Moin (which is in Python) - lots of good
advice for anyone thinging about a Wiki.

  http://taint.org/2004/09/28/191712a.html

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


Raw Sockets vs. What?

2004-12-11 Thread Matt
Hi,

I'm new to Python (1 week), but I'm writing an out-of-process debugger
for a Python ide. I tried execFile first, but stuff leaked over from
the wx libraries we are using. And, anyway, the next code set is PHP so
this has to be tackled anyway.

So, the question: How to communicate between two instances of the
python interpreter? Specifically, I need to pass the api and objects
from bdb, the base class for the debugger. One interpreter runs the
ide, the other the debugger and client code. We were talking and just
opening a socket and doing the rest from there came up. This, to me,
(admitedly a java guy) seems like a lot of work. If it were just
setting breakppoints and stepping, well ok. But I also want to have
introspection on the debugger side objects.

I could use raw sockets and write a bunch of stuff.

Does anyone have a suggestion about some pythonesque way to tackle
this?

Many thanks in advance,
Matt

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


Re: Zip with a list comprehension

2004-12-11 Thread Raymond Hettinger
 This is probably so easy that I'll be embarrassed by the answer.   While
 enhancing and refactoring some old code, I was just changing some map()s to
 list comprehensions, but I couldn't see any easy way to change a zip() to a
 list comprehension.Should I just let those sleeping dogs lie?   (list
 comprehensions seem more readable than map(), but if the list comprehension
 that does the equivalent of zip() is less expressive than zip(), I'll stick
 with zip()).

Leave in zip(), enumerate(), and reversed().
They are meant to be used with listcomps and genexps.

If you want to go the extra distance, itertools.izip() can offer a performance
boost and better memory utilization than zip().  It can be used almost anywhere
as long as the app doesn't demand a real list.


Raymond Hettinger


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


Re: swig Python question

2004-12-11 Thread Keith Dart
It's me wrote:
It's me [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
I am playing around with SWING building a Python module using the no
brainer
example in http://www.swig.org/tutorial.html.   With that first example,

Oops!  Soapy fingers.   SWIG - not SWING.
--
It's me.
I have used SWIG before, and it's not always such a no-brainer. In 
fact, it rarely is except for trivial examples. But it can work. I think 
it is best suited for wrapping large libraries. For small stuff, it 
would be better to just do it manually using the Python C API.

Good luck.
--
It's not me.

--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart [EMAIL PROTECTED]
public key: ID: F3D288E4

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


Re: Civilization IV uses Python for scripting

2004-12-11 Thread Tim Jarman
In article [EMAIL PROTECTED],
 Carl Banks [EMAIL PROTECTED] wrote:

 
 Advancement: PYTHON
 Requires: Computers, Mythology
 Effect:
 * Increases revenue generated by capitalization by 300%
 * Makes two unhappy citizens happy
 * Renders all Wonders of the World in all other countries completely
 obsolete
 * Boosts production of Research Lab by 150%
 * Gives all military units a 200% increase in attack power, 100%
 increase in defense, and a tenfold increase in accuracy
 * Decreases corruption by 50% in every city.
 * Decreases the maintenance costs of the following buildings by 1:
 - Airport
 - Bank
 - Factory
 - Harbour
 - Hydro Plant
 - Mass Transit
 - Nuclear Plant
 - Power Plant
 - SDI Defense
 - Stock Exchange
 - University
 * Scientists' science output increased by 50%
 * Entertainers luxury output increased by 50%
 * Automatically decreases the morale in every city of all countries
 that have PERL advance but not PYTHON by 50%

And of course you can build the Google Wonder! ;)

-- 
Remove luncheon meat to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie questions

2004-12-11 Thread Roel Schroeven
houbahop wrote:
def RAZVarAnimesDuJour(self,oSortiesAnimeTitreLabel):
   for i in xrange(len(oSortiesAnimeTitreLabel)):
   del oSortiesAnimeTitreLabel[i]
it doesn't emty my var (i don't want to destroy the var, just make it like 
if it just have been created
Other posts are missing the point somewhat, I think. While they do 
recommend better ways of doing what you want to do, they don't say why 
your function doesn't work.

What exactly happens when you execute your code? When I try it, I get an 
exception:

 alist = range(5)
 def a(alist):
for i in xrange(len(alist)):
del alist[i]

 a(alist)
Traceback (most recent call last):
  File pyshell#22, line 1, in -toplevel-
a(alist)
  File pyshell#21, line 3, in a
del alist[i]
IndexError: list assignment index out of range
What happens is this: the first time, the first element is deleted. This 
causes all other elements to shift: the second element becomes the first 
one, the third becomes the second, and so on. Or:

0, 1, 2, 3, 4
becomes
1, 2, 3, 4
The list gets shorter each time. But you're still looping over the whole 
length of the list, which means after some time you're accessing 
elements that no longer exist.

One way to solve it is to loop backwards: first delete the last element, 
than the next to last, etc.

Apart from that, it's much easier and clearer to reset the list with just
alist = []
--
Codito ergo sum
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-11 Thread John Machin
Jive wrote:
 Martin v. Löwis [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  OTOH, people who only have VC6 just need to buy VS.NET 2003,
  which is still available.

 I don't even know how to do that! :-)  What's the difference between
VC++
 .net Standard and Visual Studio .net Pro?  (Besides $370?)  Is the
former
 C++ only, but with the IDE, and the later the whole shebang with
SourceSafe,
 VBASIC, and all that?

 OH NO!  I've gone seriously off-topic.  Please don't call the Spanish
 Inquisiton.  Allow me to re-phrase the question:  What do I need to
build
 (on-topic) Python extensions?

Short answer to Jive's question: (1) free non-MS C compiler (either
MinGW or Borland) (2) inner calm.

I really can't understand what all the screaming and yelling is about.
Windows Python is built using an MS compiler. Those extension
developers who can't/won't buy the MS compiler use either the free
MinGW compiler or the free Borland 5.5 compiler (or both!). Yes, you
have to be careful about mixing the runtimes. An extension that tries
to use a FILE * that was created by Python will crash. Using free() on
a pointer that was malloc()ed by the other party isn't a bright idea
either. There are adequate solutions to these problems, involving
Python-supplied higher-level functions instead of C runtime functions.
Otherwise, not a problem. Distutils has made the process of using MinGW
and bcpp a snap. The documentation is adequate. When a new version of
Python comes out, one rebuilds and tests one's extensions. So ... now
there are THREE compilers that can be used instead of the one that
Python's built with; what's the big deal?

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


Re: newbie questions

2004-12-11 Thread Steven Bethard
houbahop wrote:
Thank you everyone, but I still not understand why such a comon feature like 
passing parameters byref that is present in most serious programming
languages is not possible in a clean way,here in python.
I understand from this statement that Java is not a serious programming 
language? ;)

I have the habit to never use globals as far as possible and this involve 
that my main function is passing some parameters by reference to subs to 
allow them to modify the vars.
I don't see why lack of pass-by-reference would force you to use globals...
 class C(object):
... def __init__(self):
... self.list = []
... def fill(self, iterable):
... self.list.extend(iterable)
... def empty(self):
... self.list = []
...
 c = C()
 c.list
[]
 c.fill(pow(x, 3, 29) for x in range(10))
 c.list
[0, 1, 8, 27, 6, 9, 13, 24, 19, 4]
 c.empty()
 c.list
[]
Or by globals do you mean instance variables?  If you don't want any 
instance variables (which means you don't really want OO), you can still 
clear your list as long as you have any name bound to the list object:

 def clear(lst):
... while lst:
... lst.pop()
...
 x = [pow(x, 7, 19) for x in range(10)]
 x
[0, 1, 14, 2, 6, 16, 9, 7, 8, 4]
 clear(x)
 x
[]
or alternatively:
 def clear(lst):
... lst[:] = []
...
 x = [pow(x, 7, 19) for x in range(10)]
 x
[0, 1, 14, 2, 6, 16, 9, 7, 8, 4]
 clear(x)
 x
[]
Note that neither of these functions requires pass-by-reference; the lst 
local in the function is not the same name as the x local outside the 
function.  But since you're basically just passing a pointer by value, 
both variables still point to the same object (or in Python terms, 
both names are bound to the same object).  To apply an affect that 
is visible to all names bound to an object, you simply need to mutate 
the object.  In the cases above, this is just a matter of using the 
appropriate object method (list.pop or list.__setslice__ respectively 
above).

Is this so bad?
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie questions

2004-12-11 Thread Mel Wilson
In article [EMAIL PROTECTED],
houbahop d.lapasset[Remove me)@chello.fr wrote:
Thank you everyone, but I still not understand why such a comon feature like
passing parameters byref that is present in most serious programming
languages is not possible in a clean way,here in python.

I have the habit to never use globals as far as possible and this involve
that my main function is passing some parameters by reference to subs to
allow them to modify the vars.

I would be sad to break my structured programming scheme because a lack of
feature.

In others languages you can use things like pointers to strings or
Mysub(byref MyVar) 

and it does the trick :)

   It isn't a problem with passing by reference.  The
passing-by-reference part works just fine.  Putting in a
print statement to trace what's actually happening:


Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 a = [1,2,3,4,5]
 def X(s):
... for i in xrange (len (s)):
... del s[i]
... print 'X:', s
...
 X(a)
X: [2, 3, 4, 5]
X: [2, 4, 5]
X: [2, 4]
Traceback (most recent call last):
  File stdin, line 1, in ?
  File stdin, line 3, in X
IndexError: list assignment index out of range
 a
[2, 4]



   As the last line shows, lots of things got removed from
`a` .. but not everything.  Roel Schroeven explained why.

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


Re: Raw Sockets vs. What?

2004-12-11 Thread Fredrik Lundh
Matt wrote:

 So, the question: How to communicate between two instances of the
 python interpreter? Specifically, I need to pass the api and objects
 from bdb, the base class for the debugger. One interpreter runs the
 ide, the other the debugger and client code. We were talking and just
 opening a socket and doing the rest from there came up. This, to me,
 (admitedly a java guy) seems like a lot of work. If it were just
 setting breakppoints and stepping, well ok. But I also want to have
 introspection on the debugger side objects.

 I could use raw sockets and write a bunch of stuff.

 Does anyone have a suggestion about some pythonesque way to tackle
 this?

let the debugger listen to a randomly chosen local port, let the client wrapper
connect back to the debugger via that port, and use a suitable marshalling layer
to wrap commands and data for the introspection part.  This has been done many
times by many IDE developers (including yours truly).  Designing the RPC API
is the only tricky part here, and it doesn't have to be that tricky (some people
are known to use really simply stuff, such as XML-RPC, for this purpose).

Unless I'm completely mistaken, recent versions of IDLE have a remote debugger
designed and implemented by GvR himself.  Maybe you could use that code right
out of the box?

/F 



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


Re: UrlLib2 Proxy and Https

2004-12-11 Thread Sandeep
Check out the following link. It helped me achieve the same thing
(access a HTTPS site via a proxy).

http://groups.yahoo.com/group/linux-bangalore-programming/message/4208
Cheers,
Sandeep
http://sandeep.weblogs.us/

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


Re: Clarification of two concepts (or maybe one?)

2004-12-11 Thread Larry Bates
What you are looking for are 2 apps:
1) Something to freeze your application into something
that resembles an installation like what comes on commercial
applications.  On Windows a popular choice is py2exe.  All
dependent .py, .pyd, etc. files can be included in the
distribution.  It also includes necessary python .dlls.
2) Something to create a distribution.  On Windows a
popular choice seems to be Inno Installer.  It creates
a single setup.exe file that can be distributed and is
very flexible.
Hope info helps.
Larry Bates
Syscon, Inc.
Fredrik Lundh wrote:
Eddie Parker wrote:

What Im looking for, is a way to turn a python application, into a
stand-alone application. i.e., you dont need the Python interpreter,
libraries, etc, installed on your hard drive. (Im OK with .py files
existing  I just dont want to have to bother the user to install more then
just my app).

you cannot run Python without a Python interpreter -- but you can ship the
interpreter DLL and the necessary library components with your app, and
you can use bundling tools to reduce the number of files to a minimum:
http://effbot.org/zone/python-compile.htm
http://www.python.org/cgi-bin/moinmoin/DistributionUtilities
/F 


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


Re: ElementTree and XPATH

2004-12-11 Thread Martijn Faassen
Istvan Albert wrote:
[EMAIL PROTECTED] wrote:
it seems to be invalid syntax if I give /a/b[0] to the findall()
method. Does anyone know the correct syntax?

I think the proper mindset going in should be that
elementtree does not support xpath but that
there are some handy constructs that resemble
the location steps of xpath.
The lxml Pythonic wrapper of libxml2 which aims (among others) to build 
an elementtree API compatible interface will indeed extend that API and 
offer XPath support. Of course it's all not done yet. :)

http://codespeak.net/mailman/listinfo/lxml-dev
http://codespeak.net/svn/lxml/trunk/
Regards,
Martijn
--
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-11 Thread Peter Hansen
phil wrote:
Well its an anomaly.  I sent to bug list.
Probably never see it again.
I think some sort of semaphore thingy, which I know
nothing about, is sneaking in under unreproducible
conditions.  I'm moving on.
If you want to try one more thing, try mucking with
a call to sys.setcheckinterval().  This used to be
10 by default but is now 100.  In any case, changing
it will quite often significantly change the code's
behaviour in the presence of race conditions.  Try
values of 1 and 1000 and see if anything makes a
difference.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system() inside a thread problem

2004-12-11 Thread Fredrik Lundh
Daniel Bernhardt wrote:

 my thread calls a program with os.system().
 os.system(/usr/bin/wine /path/to/ultima/online.exe)

in the example you included, you use execv.  which one is it?

 Ultima Online is starting and i can enter commands and navigate through the
 game with my keyboard. If I move the mouse over the Ultima Online window
 Ultima Online crashes. (the mouse just need to overlap 1 pixel of the egde
 of the window. titlebar inlcuded)
 /usr/bin/wine: line 55: 11675 Segmentation fault
 Same with os.popen()

 If I run os.system() outside the thread everything is working like expected.
 Other programs (wine emulated and nativ) work inside and outside the thread.

 Can anyone tell me how I can fix this?

just curious: do you really have to use a thread?  why not just do

   os.system(command + )

/F 



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


Re: os.system() inside a thread problem

2004-12-11 Thread Daniel Bernhardt
Fredrik Lundh wrote:

 in the example you included, you use execv.  which one is it?

it should be system(). I just played a bit and forgot to change it back. 

 
 just curious: do you really have to use a thread?  why not just do
 
os.system(command + )
 

No, i don't need to use a thread. I just wanted learn something about it and
thought it would be a good start.
I will use os.system(command + ) as you said to solve the problem. 
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with Outlook and MAPI

2004-12-11 Thread Larry Bates
At the risk of beating a dead horse, but you really should consider
using SMTP instead if you are really going to be sending a lot
of messages.  I think you will find it more reliable and much faster.
It also eliminates the need for ANY email client to be on the machine
that is sending the messages.
http://motion.technolust.cx/related/send_jpg.py
Here is a link to a class that wraps everything up very nicely.  You
should be able to be sending SMTP emails with it in 10-15 minutes.
It supports binary attachments as well.
FYI,
Larry Bates
Chris wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it to 
work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My only 
problem is that when I call Resolve() and Send(), I get confirmation 
dialogs.  I will be sending out quite a few e-mails at a time, and would 
rather not have the user have to click yes for every single one.  Does 
anyone know a workaround?  I know about smtplib, but I would prefer to 
simply make what I have work.  Thanks.

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


Re: Tibia 0.1 DOM-based website editor

2004-12-11 Thread Fuzzyman
Interesting.

I couldn't get the demo to work either by the way. A 404 error on the
tba file.

This is *similar* t oa project I'm about to release, Jalopy. Jalopy is
a collaborative website tool - allowing a team of people to work on a
website together. It uses Kupu as an online WYSIWYG HTML editor. (I
assume tibia uses something similar ? if not you should integrate Kupu
!).

You can see a jalopy demo at
http://www.voidspace.org.uk/cgi-bin/jalopydemo/jalopy.py

I'm not *sure* if that is the latest version - but I think so. I've
nearly finished the docs and will do a release.

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

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


Re: your favorite quick reference? (was Python Docs. Hardcopy 2.4 Library Reference, interested?)

2004-12-11 Thread beliavsky
O'Reilly has CD bookshelves http://cdbookshelves.oreilly.com/ ,
combining their books on a topic into a CD, for various subjects,
including Perl, but not yet for Python. I own the paper copies of
several of their Python books. A single CD containing their books

Jython Essentials
Learning Python, 2nd Edition
Programming Python, 2nd Edition
Python  XML
Python Cookbook
Python in a Nutshell
Python Pocket Reference, 2nd Edition
Python Programming on Win32
Python Standard Library

would be a great purchase, especially if upgrade prices were available
when new editions of books like Python in a Nutshell were released,
to keep up with changes in the language. I wonder who at O'Reilly can
be contacted to lobby for this.

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


Re: building python extensions with .net sdk compiler?

2004-12-11 Thread Grumman
David Fraser wrote:
So using MinGW seems like the better option ... is it working for Python 
2.4?
Yes it does. :)  I haven't tried it, but probably.
The problem with the toolkit is that mscvccompiler.py in distutils is 
expecting VisualStudio to be installed, not the toolkit. So when it goes 
to lookup paths to the installed tools, it doesn't find them.

All that's actually needed to make it work (After installing all 4 
required packages) is to add several strings to your registry. You'll 
probably have to add all the keys below \Software\Microsoft as well.

Under : 
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\7.1\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directories

You need to add the strings:
Include Dirs(path to toolkit \include; path to platform sdk \include)
Library Dirs(path to toolkit \lib; path to platform sdk \lib)
Path Dirs (path to toolkit \bin; path to platform sdk \bin)
And it'll be happy.
Of course it'd be nice if msvccompiler.py just fell back to looking for 
the toolkit/sdk default dirs (or looked them up via environment vars, 
since the toolkit does include a vcvars32.bat that sets appropriate 
ones) if the VS lookup failed.

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


RE: Tibia 0.1 DOM-based website editor

2004-12-11 Thread Robert Brewer
Fuzzyman wrote:
 Interesting.
 
 I couldn't get the demo to work either by the way. A 404 error on the
 tba file.

Bah. You must've looked after I switched fom .tba to .py
Try http://www.aminus.org/rbre/tibia/demo/tibia.py

 This is *similar* t oa project I'm about to release, Jalopy. Jalopy is
 a collaborative website tool - allowing a team of people to work on a
 website together. It uses Kupu as an online WYSIWYG HTML editor. (I
 assume tibia uses something similar ? if not you should integrate Kupu
 !).

Similar, but with important differences. Although Tibia makes use of
Javascript to manipulate the DOM, its goals and audience are different.
Tibia:

1. ...is a single file, to reduce deployment cost: download (wget), edit
httpd.conf or IIS conf (if you're not already mapping .py to CGI), write
a tibia.conf if you don't want the defaults. Install PIL if desired,
which is a one-liner on Debian and an installer on Win*. So Kupu's right
out. So is the jalopy approach: login_tools, configobj, caseless,
listquote, dateutils, dataenc, pathutils and cgiutils is far too many
dependencies when you're shooting for zero/one ;).

2. ...combines *both* WYSIWYG and source code access, at the same time.
Your typing is performed in a plain-'ol textarea, which avoids all of
the where is my cursor? problems with WYSIWYG-only when used on
complex pages. However, as you type, your changes are reflected in real
time in the source document. I need an Undo button, though. /pops off
and adds a new feature request

3. ...handles complex, preexistent web pages produced by others. Have
your web page laid out by a pro, then give access to individual elements
to your content providers as needed. Using the web grabber and upload
tools, you can stop FTP'ing web pages to your colo completely. It
doesn't appear to me from the Kupu demos that they can handle anything
complex...but I could be wrong. I'd like to see a page like Plone's home
page being edited by Kupu. You can see it in Tibia at the demo:
http://www.aminus.org/rbre/tibia/demo/tibia.py?page=www.plone.org.html


 You can see a jalopy demo at
 http://www.voidspace.org.uk/cgi-bin/jalopydemo/jalopy.py
 
 I'm not *sure* if that is the latest version - but I think so. I've
 nearly finished the docs and will do a release.

It looks good! I like some of the tools Kupu provides (and in fact,
stole the idea for my simplistic B, I, U buttons after seeing Kupu for
the first time a few weeks ago). I'm a bit unclear on exactly where Kupu
stops and Jalopy starts, though. You might want to make that more clear
in the help file...maybe a one-liner like Kupu does X, Y, and Z, and
Jalopy adds A, B, and C.

I'm looking forward to your release (with uploads! ;).


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


Re: New versions breaking extensions, etc.

2004-12-11 Thread It's me
On the other hand, it can be annoying.

I can't use Python 2.4 right now because NumPy won't run.  So, I need to
wait for NumPy to get updated.

Of course, one would say: but NumPy is open source, go build it yourself.

My answer is simple: If there are more then 24 hours to a day, I definitely
would...

--
It's me


John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Jive wrote:
 Martin v. Löwis [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  OTOH, people who only have VC6 just need to buy VS.NET 2003,
  which is still available.

 I don't even know how to do that! :-)  What's the difference between
VC++
 .net Standard and Visual Studio .net Pro?  (Besides $370?)  Is the
former
 C++ only, but with the IDE, and the later the whole shebang with
SourceSafe,
 VBASIC, and all that?

 OH NO!  I've gone seriously off-topic.  Please don't call the Spanish
 Inquisiton.  Allow me to re-phrase the question:  What do I need to
build
 (on-topic) Python extensions?

Short answer to Jive's question: (1) free non-MS C compiler (either
MinGW or Borland) (2) inner calm.

I really can't understand what all the screaming and yelling is about.
Windows Python is built using an MS compiler. Those extension
developers who can't/won't buy the MS compiler use either the free
MinGW compiler or the free Borland 5.5 compiler (or both!). Yes, you
have to be careful about mixing the runtimes. An extension that tries
to use a FILE * that was created by Python will crash. Using free() on
a pointer that was malloc()ed by the other party isn't a bright idea
either. There are adequate solutions to these problems, involving
Python-supplied higher-level functions instead of C runtime functions.
Otherwise, not a problem. Distutils has made the process of using MinGW
and bcpp a snap. The documentation is adequate. When a new version of
Python comes out, one rebuilds and tests one's extensions. So ... now
there are THREE compilers that can be used instead of the one that
Python's built with; what's the big deal?


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


Re: GUIs: wxPython vs. Tkinter (and others)

2004-12-11 Thread Peter Hansen
Jarek Zgoda wrote:
Fredrik Lundh wrote:
I don't know about wxPython, but PyQt includes it's own threading
facility, plus hooks to talk to databases.
That would of course be a great argument if Python didn't already have
a threading facility, and a standard API for talking to databases with
implementations for all major players.
Python threading is not perfect in many cases in GUI programming -- you 
have to implement your own notification mechanism (eg. using queue 
polling), as usually you can communicate with GUI only from main 
application's thread. 
With wxPython, PostEvent (which is what CallAfter also uses) is
threadsafe and can be used from any thread, allowing you to
communicate (in this direction, at least) with the GUI thread
from any regular Python thread.  No need for special threads
provided by the framework and, in fact, even though wxWidgets
(on which wxPython is built) provides a wxThread class, it
is not exposed in wxPython because it is redundant there.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: building python extensions with .net sdk compiler?

2004-12-11 Thread Mike C. Fletcher
Grumman wrote:
David Fraser wrote:
So using MinGW seems like the better option ... is it working for 
Python 2.4?

...
Of course it'd be nice if msvccompiler.py just fell back to looking 
for the toolkit/sdk default dirs (or looked them up via environment 
vars, since the toolkit does include a vcvars32.bat that sets 
appropriate ones) if the VS lookup failed.
Which is what the patch here:
   http://www.vrplumber.com/programming/mstoolkit/
does.
Have fun,
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: newbie questions

2004-12-11 Thread Steven Bethard
houbahop wrote:
Passing a pointer by value appears to me as passing a var by reference.
Well, at least in the PL literature, there's a subtle difference.  If 
Python supported pass-by-reference, you could do something like:

 def clear(byref lst):
... lst = []
...
 x = [pow(x, 11, 17) for x in range(10)]
 clear(x)
 x
[]
Passing a variable by reference means that the *variable* in the 
function is the same *variable* as outside the function.  Notice that 
this is not the same thing as saying that the variable in the function 
is a pointer to the same object as the variable outside the function.

Python doesn't support pass-by-reference in this standard use of the 
term.  But Python is basically *only* passing pointers around; there is 
no way to do anything else.  So if passing a pointer by value is 
sufficient for your purposes then you won't have any problems with 
Python, because this is what it always does. =)

Thanks I will try all of that, but what does really means mutating in 
python? It's the first time I hear this word in programming :))
The term is used most commonly in the pair accessor/mutator, also known 
as getter/setter.  In general, a mutator is just a method of an object 
that changes that object's state.  In Python, assignment does not invoke 
a method of an object; it binds a name to an object.  For this reason, 
code like:

def clear(lst):
lst = [] # binds the name lst to a new value, []
 # ignoring previous value
will not change the list because it is not calling methods of the list 
object to change it.  It will instead rebind the local name lst to a 
new object, [].  This does not change the previous object that was 
associated with lst and so if you have another variable bound to the 
previous value (x in my examples), it will still retain the old, 
unchanged object.

So, while assignment does not invoke a method of an object, many other 
things in Python do, and all of these things will appropriately modify 
the state of the object.  For example:

def clear(lst):
lst[:] = [] # implicitly calls the setter/mutator list.__setslice__
def clear(lst):
while lst: # implicitly calls the getter/accessor len(lst)
lst.pop() # explicit call to setter/mutator list.pop
# don't use this; it's inefficient, I'm just using it as an example
# of using a different setter/mutator
def clear(lst):
while lst:# implicitly calls the getter/accessor len(lst)
last_item = lst[-1]   # implicitly calls the getter/accessor
  # list.__getitem__
lst.remove(last_item) # explicitly calls setter/mutator
  # list.remove
Note that all of these functions will successfully clear the list 
because they mutate the object itself, instead of simply rebinding a 
name that at one point had been associated with the object.

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


Re: MP3 - VBR - Frame length in time

2004-12-11 Thread Ivo Woltring

JanC [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Dmitry Borisov schreef:

  It has something to deal with the VBR tags( XING header ).

 *If* there is a VBR tag (it's a custom extension) and *if* that VBR tag
 contains a correct value.


 -- 
 JanC

 Be strict when sending and tolerant when receiving.
 RFC 1958 - Architectural Principles of the Internet - section 3.9

mmpython will help but not always.
Lets put it this way. I will ALWAYS read through the whole file. In that
order I don't mind evaluating each frame. The thing I don't seem to be able
to find is the timelength-constants for frames for the different mp3
versions, bitrates and layers. Can anybody help me?

Thnaks,
Ivo


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


Re: New versions breaking extensions, etc.

2004-12-11 Thread Steven Bethard
It's me wrote:
My answer is simple: If there are more then 24 hours to a day, I definitely
would...
Can we get a patch in for this?
 datetime.timedelta(hours=24) + datetime.timedelta(hours=1)
datetime.timedelta(1)
would be much preferable to the current:
 datetime.timedelta(hours=24) + datetime.timedelta(hours=1)
datetime.timedelta(1, 3600)
;)
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie questions

2004-12-11 Thread Steven Bethard
houbahop wrote:
Hello again everyone ,
var2[:]=[] has solved my problem, and I don't understand why it is 
programming by side effect.
I don't think it's bad, look at this, it's what I've done :

def Clear(lvar)
lvar[:]=[]
def main (starting class)
   var1=[]
   var1.append('a')
   Clear(var1)
From http://en.wikipedia.org/wiki/Side-effect_(computer_science)
In computer science, a side-effect is a property of a programming 
language function that it modifies some state other than its return value.

Given this definition, I think you're fine -- clearing the list isn't a 
side effect of the function; it is the purpose of the function.  Hence 
the function has no return value.[1]


Of course, in this simple case, I wouldn't be likely to write the clear 
function since the inline code is simpler and has less overhead:

def main()
var1 = []
var1.append('a')
var1[:] = []
or, since in this case, you only care about var1, you can just rebind it 
(and let Python garbage-collect the old list):

def main()
var1 = []
var1.append('a')
var1 = []
Steve
[1] Technically, all Python functions without a return statement return 
None, but for our purposes, we can consider a function like this to have 
no return value.
--
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-11 Thread Bengt Richter
On Fri, 10 Dec 2004 16:18:51 -0600, phil [EMAIL PROTECTED] wrote:

And sorry I got ticked, frustrating week

threading problems can do that ;-)

You are obviusly deeper into this than I can get from a cursory scan,
but I'll make some general debugging comments ;-)

 And I could help more, being fairly experienced with
 threading issues and race conditions and such, but
 as I tried to indicate in the first place, you've
 provided next to no useful (IMHO) information to
 let anyone help you more than this

This is about 5% of the code.
Uses no locks.
I am mystified, I have written probably 100,000 lines
of Python and never seen a thread just lock up and quit
running.  It happens on a Queue() statement so my suspicion
is a bug.  ??
Or a once-in-a-blue-moon resource access deadlock of some kind?


I have kludged around it by putting all the thread/queue stuff
in the main program and import the stuff I don't want to
distribute.  But mysteries haunt your dreams, sooo...
#!/usr/local/bin/python

# pnetx.py

from threading import *
from time import *
from Queue import Queue
from socket import *
Do you really need to import * ? Though the above should be safe import-wise
you are setting yourself up for name-clash problems by putting so many in
the same space. E.g., if something happened to match a misspelling typo in
your program, you wouldn't get a name error exception. Etc., etc.

One of the first rules of debugging is to eliminate the unnecessary ;-)
At least there doesn't seem to be name clashes between the above (except
starting with '_' which shouldn't get imported with *

  d = {}
  for imp in 'threading time Queue socket'.split():
 ...m = __import__(imp)
 ...for name in m.__dict__.keys():
 ...d.setdefault(name, []).append(imp)
 ...
  for k,v in d.items():
 ... if len(v)!=1: print k,v
 ...
 _sleep ['threading', 'Queue']
 __file__ ['threading', 'Queue', 'socket']
 __all__ ['threading', 'Queue', 'socket']
 __builtins__ ['threading', 'Queue', 'socket']
 __name__ ['threading', 'time', 'Queue', 'socket']
 _time ['threading', 'Queue']
 __doc__ ['threading', 'time', 'Queue', 'socket']

Just verifying an assumption ;-)
OTOH, do you really need (ignoring wid and name and the first content of dir()):

  dir()
 ['__builtins__', '__doc__', '__name__']
  from threading import *
  from time import *
  from Queue import *
  from socket import *
  wid = 0
  for name in dir():
 ... print repr(name),
 ... wid += len(repr(name))+1
 ... if wid60:
 ... print
 ... wid = 0
 ...
 'AF_APPLETALK' 'AF_INET' 'AF_IPX' 'AF_UNSPEC' 'AI_ADDRCONFIG'
 'AI_ALL' 'AI_CANONNAME' 'AI_DEFAULT' 'AI_MASK' 'AI_NUMERICHOST'
 'AI_PASSIVE' 'AI_V4MAPPED' 'AI_V4MAPPED_CFG' 'BoundedSemaphore'
 'CAPI' 'Condition' 'EAI_ADDRFAMILY' 'EAI_AGAIN' 'EAI_BADFLAGS'
 'EAI_BADHINTS' 'EAI_FAIL' 'EAI_FAMILY' 'EAI_MAX' 'EAI_MEMORY'
 'EAI_NODATA' 'EAI_NONAME' 'EAI_PROTOCOL' 'EAI_SERVICE' 'EAI_SOCKTYPE'
 'EAI_SYSTEM' 'Empty' 'Event' 'Full' 'INADDR_ALLHOSTS_GROUP' 'INADDR_ANY'
 'INADDR_BROADCAST' 'INADDR_LOOPBACK' 'INADDR_MAX_LOCAL_GROUP'
 'INADDR_NONE' 'INADDR_UNSPEC_GROUP' 'IPPORT_RESERVED' 'IPPORT_USERRESERVED'
 'IPPROTO_GGP' 'IPPROTO_ICMP' 'IPPROTO_IDP' 'IPPROTO_IGMP' 'IPPROTO_IP'
 'IPPROTO_MAX' 'IPPROTO_ND' 'IPPROTO_PUP' 'IPPROTO_RAW' 'IPPROTO_TCP'
 'IPPROTO_UDP' 'IP_ADD_MEMBERSHIP' 'IP_DEFAULT_MULTICAST_LOOP'
 'IP_DEFAULT_MULTICAST_TTL' 'IP_DROP_MEMBERSHIP' 'IP_MAX_MEMBERSHIPS'
 'IP_MULTICAST_IF' 'IP_MULTICAST_LOOP' 'IP_MULTICAST_TTL' 'IP_OPTIONS'
 'IP_TOS' 'IP_TTL' 'Lock' 'MSG_DONTROUTE' 'MSG_OOB' 'MSG_PEEK'
 'NI_DGRAM' 'NI_MAXHOST' 'NI_MAXSERV' 'NI_NAMEREQD' 'NI_NOFQDN'
 'NI_NUMERICHOST' 'NI_NUMERICSERV' 'Queue' 'RAND_add' 'RAND_egd'
 'RAND_status' 'RLock' 'SOCK_DGRAM' 'SOCK_RAW' 'SOCK_RDM' 'SOCK_SEQPACKET'
 'SOCK_STREAM' 'SOL_IP' 'SOL_SOCKET' 'SOL_TCP' 'SOL_UDP' 'SOMAXCONN'
 'SO_ACCEPTCONN' 'SO_BROADCAST' 'SO_DEBUG' 'SO_DONTROUTE' 'SO_ERROR'
 'SO_KEEPALIVE' 'SO_LINGER' 'SO_OOBINLINE' 'SO_RCVBUF' 'SO_RCVLOWAT'
 'SO_RCVTIMEO' 'SO_REUSEADDR' 'SO_SNDBUF' 'SO_SNDLOWAT' 'SO_SNDTIMEO'
 'SO_TYPE' 'SO_USELOOPBACK' 'SSLType' 'SSL_ERROR_EOF' 
'SSL_ERROR_INVALID_ERROR_CODE'
 'SSL_ERROR_SSL' 'SSL_ERROR_SYSCALL' 'SSL_ERROR_WANT_CONNECT'
 'SSL_ERROR_WANT_READ' 'SSL_ERROR_WANT_WRITE' 'SSL_ERROR_WANT_X509_LOOKUP'
 'SSL_ERROR_ZERO_RETURN' 'Semaphore' 'SocketType' 'TCP_NODELAY'
 'Thread' 'Timer' '__builtins__' '__doc__' '__name__' 'accept2dyear'
 'activeCount' 'altzone' 'asctime' 'clock' 'ctime' 'currentThread'
 'daylight' 'enumerate' 'error' 'errorTab' 'gaierror' 'getaddrinfo'
 'getdefaulttimeout' 'getfqdn' 'gethostbyaddr' 'gethostbyname'
 'gethostbyname_ex' 'gethostname' 'getnameinfo' 'getprotobyname'
 'getservbyname' 'gmtime' 'has_ipv6' 'herror' 'htonl' 'htons'
 'inet_aton' 'inet_ntoa' 'localtime' 'mktime' 'ntohl' 'ntohs'
 'setdefaulttimeout' 'setprofile' 'settrace' 'sleep' 'socket'
 'ssl' 'sslerror' 'strftime' 'strptime' 'struct_time' 'time' 'timeout'
 'timezone' 'tzname' 'wid'
 

 (Hm, should have pre-tested wid+len(current) to 

Re: New versions breaking extensions, etc.

2004-12-11 Thread Jeremy Bowers
On Sat, 11 Dec 2004 01:28:45 -0600, Mike Meyer wrote:
 Actually, there's a problem on Unix that may not exist on
 Windows. Python is installed in PREFIX/lib/pythonversion/. This
 lets us have multiple versions of Python installed at the same time,
 which is a good thing.
 ...
 The real solution is...

Interestingly, I saw you going somewhere else for this. I expected,

The real solution is, at least for the pure Python packages, a
system-wide directory for those, reserving site-packages for things that
are truly version specific.

I'm not sure I'm ready to propose this yet, but thoughts? Bad idea, good
idea? 

Obviously it isn't perfect, but it seems to me that reverse compatibility
has been good enough for a while now that the imperfections are minor in
impact...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie questions

2004-12-11 Thread houbahop d.lapasset
Thank you Steven,
The funny thing is that I have taken a look at wikipedia just before to be 
sure that I wasn't wrong :D
I agree with you about not making a clear function to just put what I've put 
in my sample, but
this sample was more simple that what I really need for explaining purpose.

In reality My clear function is cleaning a dozen of arrays and since I need 
to call it several time I have made a function of it.

 a few days ago I was trying python for the little script I'm working on and 
this language is more powerfull that I was thinking and very pleasant to 
code.
I believe I will use it more in the future.
Dominique.


Steven Bethard [EMAIL PROTECTED] a écrit dans le message de news: 
[EMAIL PROTECTED]
 houbahop wrote:
 Hello again everyone ,
 var2[:]=[] has solved my problem, and I don't understand why it is 
 programming by side effect.
 I don't think it's bad, look at this, it's what I've done :

 def Clear(lvar)
 lvar[:]=[]

 def main (starting class)
var1=[]
var1.append('a')
Clear(var1)

 From http://en.wikipedia.org/wiki/Side-effect_(computer_science)

 In computer science, a side-effect is a property of a programming language 
 function that it modifies some state other than its return value.

 Given this definition, I think you're fine -- clearing the list isn't a 
 side effect of the function; it is the purpose of the function.  Hence the 
 function has no return value.[1]



 Of course, in this simple case, I wouldn't be likely to write the clear 
 function since the inline code is simpler and has less overhead:

 def main()
 var1 = []
 var1.append('a')
 var1[:] = []

 or, since in this case, you only care about var1, you can just rebind it 
 (and let Python garbage-collect the old list):

 def main()
 var1 = []
 var1.append('a')
 var1 = []

 Steve

 [1] Technically, all Python functions without a return statement return 
 None, but for our purposes, we can consider a function like this to have 
 no return value. 


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


Re: How to remove packages - wxPython

2004-12-11 Thread Peter Hansen
Peter wrote:
Linux kernel 2.6.9
Slackware 10
Python version 2.3.4
wxPython version 2.4.2.4
I compiled and installed wxPython.
There is no uninstall script that I can find for the py components. The
library component has a make uninstall.
What is the proper way to uninstall packages? I searched everywhere, but
there seems to be no clearcut explanation.
Can I just remove the site-package directories it created? Or is there a
central config file for python?
Generally speaking, just removing the subfolder(s) from site-packages
will completely remove an extension.  Some few extensions will also
create a .pth file in the site-packages folder, so check for that
as well.  No doubt there are exceptions, but I believe this will
cover 95% of the cases.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with Outlook and MAPI

2004-12-11 Thread Roger Binns

Chris [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 My only  problem is that when I call Resolve() and Send(), I get confirmation 
 dialogs.  I will be sending out quite a few e-mails 
 at a time, and would rather not have the user have to click yes for every 
 single one.

Here is an simple workaround:

  http://www.contextmagic.com/express-clickyes/

If you have win32all installed, you can even use the programming API
they present to turn on and off the clickyes functionality.

Roger 


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


Re: Python vs. Perl

2004-12-11 Thread Michael McGarry
[EMAIL PROTECTED] wrote:
Christopher De Vries wrote:
Roy Smith already touched on regular expressions, but as far as
features go, I would say that the real difference between python and
perl is not in the features, but in the philosophy.

To help aid in this discussion, the following Python and Perl
philosophy links might be useful:
http://c2.com/cgi/wiki?PythonPhilosophy
http://www.maths.adelaide.edu.au/~cmc/tutorials/perlintro/x175.html
Now, so that I don't start another Python vs. Perl flamewar, I'd like
to inform everyone that I'm about to make a few generalizations based
on my experience.  As should be understood implicitly, one man's
experience is not the experience of everyone...
As a user of both languages, I've found that what Perl and Python
programmers have in common is that they were looking for a better tool
when they stumbled across their language of choice...  After all, one
can be productive in both languages.
What I've also noticed that people who use Perl tended to start using
it as a way to make either C or shell scripting tasks easier (after
all, this is Perl's original intended audience).  Many of these
developers have gone on to use Perl for bigger and better things, but
without a lot of discipline (use strict, and a lot of work with the
Exporter), Perl doesn't scale very well to large projects.  My belief
is that Perl's strength (TMTOWTDI) is also it's greatest weakness.
I've also noticed that Python programmers tend to be a more diverse
lot.  While Guido originally intended Python to be a second language
for C/C++ developers, it is also quite useful as a first language.
Python's philosophy is more that there should a clear understandable
way to do things, and that readability counts.  That is not to say you
can't perform tasks in multiple ways, it is just to say that Python
doesn't believe in TMTOWTDI as Perl does.
So the bottom line is this.  In choosing Perl or Python, the real
difference should be your mindset, and what you intend to use it for.
If you want a multiparadigm programming language that offers wonderful
OO support, is easy to learn, and in which you will naturally write
maintainable code, choose Python.
On the other hand, if you are looking for a language to text-processing
and to perform short quick shell scripting like tasks, choose Perl.
While both languages can be used to perform both sets of tasks, my
belief is that one should pair a language and a task by strengths
rather than what can be done in each language.
I hope this helps!
Michael Loritsch
Thank you all for your input. Please feel free to keep this discussion 
going.

I intend to use a scripting language for GUI development and front end 
code for my simulations in C. I want a language that can support SQL, 
Sockets, File I/O, and shell interaction.

I welcome any opinions on this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-11 Thread Peter Otten
phil wrote:

 And sorry I got ticked, frustrating week
 
  And I could help more, being fairly experienced with
  threading issues and race conditions and such, but
  as I tried to indicate in the first place, you've
  provided next to no useful (IMHO) information to
  let anyone help you more than this
 
 This is about 5% of the code.
 Uses no locks.

A lock is acquired in Queue.__init__().

 I am mystified, I have written probably 100,000 lines
 of Python and never seen a thread just lock up and quit
 running.  It happens on a Queue() statement so my suspicion
 is a bug.  ??
 
 I have kludged around it by putting all the thread/queue stuff
 in the main program and import the stuff I don't want to
 distribute.  But mysteries haunt your dreams, sooo...

What I believe to be a minimal example:

freeze.py
import Queue
import threading
import time

q = Queue.Queue(4)

def proc():
while True:
q.get(1)
Queue.Queue()
print YADDA

threading.Thread(target=proc).start()

while True:
print yadda
q.put(None)
time.sleep(1)
/freeze.py

freezemain.py
import freeze
/freezemain.py

Invoking freezemain.py produces

yadda
yadda
yadda
yadda
yadda
yadda

i. e. consistently q.maxsize + 2. One item about to be put, one already
taken before Queue.Queue(). Deferring execution of the module-level code
until after the import

nofreeze.py
import Queue
import threading
import time

q = Queue.Queue(4)

def proc():
while True:
q.get(1)
Queue.Queue()
print YADDA

def start():
threading.Thread(target=proc).start()

while True:
print yadda
q.put(None)
time.sleep(1)
/nofreeze.py

nofreezemain.py
import nofreeze
nofreeze.start()
/nofreezemain.py

and invoking nofreezemain.py produces
yadda
YADDA
yadda
YADDA
yadda
YADDA
yadda
YADDA

apparently ad infinitum. Conclusion? None so far, though you might welcome
the confirmation that this is not a once in a blue moon accident as Bengt
Richter surmised.

Import _is_ a sensitive phase...

As an experiment I moved

try:
import thread
except ImportError:
import dummy_thread as thread

from the Queue.Queue.__init__() method to the module body -- and now
freezemain.py seems to work, too. So that would be an easy remedy, but sure
there is a reason why that import statement is in such an unusual place?

Peter






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


Re: Fun with Outlook and MAPI

2004-12-11 Thread Roger Binns

Larry Bates [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 At the risk of beating a dead horse, but you really should consider
 using SMTP instead if you are really going to be sending a lot
 of messages.

The problem is that doesn't work in more complicated configurations
such as when authentication and/or SSL have to happen, not to mention
the issue of configuring servers and ports, that users have already
configured in their mail clients.  Additionally when you use MAPI,
messages that you send also end up in your sent items folder. (I
also have not had any issue sending lots of messages using MAPI).

Ultimately the utility of vanilla of pure SMTP will depend on
customer requirements and how simple the configuration is.

Roger 


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


Re: uptime for Win XP?

2004-12-11 Thread Greg Krohn
Tom Wesley wrote:
Esmail Bonakdarian wrote:
Hi,
Is there a way to display how long a Win XP system has been up?
Somewhat analogous to the *nix uptime command.
Thanks,
Esmail

I believe that uptime works from the console, but don't have a machine 
to check it with...
Doesn't work for me, but if you have win32all installed, you can get it 
from Python:

 import win32api
 print Uptime:, win32api.GetTickCount(), Milliseconds
Uptime: 148699875 Milliseconds
hth
greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie questions

2004-12-11 Thread houbahop d.lapasset

Dennis Lee Bieber [EMAIL PROTECTED] a écrit dans le message de news: 
[EMAIL PROTECTED]
 On Sat, 11 Dec 2004 12:43:01 GMT, houbahop d.lapasset[Remove
 me)@chello.fr declaimed the following in comp.lang.python:

 Thank you everyone, but I still not understand why such a comon feature 
 like
 passing parameters byref that is present in most serious programming
 languages is not possible in a clean way,here in python.

 Well, in C, everything is also passed by value. The programmer
 has to explicitly pass an address as the value instead of the actual
 value if they want to change the contents. And, of course, the function
 has to know that it is an address, and explicitly dereference the
 address to gain access to the actual content value.

 Using my overworked and not quite complete example...


Hello and thank you,

To be honnest I must take a moment and translate your example into french to 
really understand it (but I believe it's very well explained :) and I will 
understand)
I remember at school when an unix teacher was explaining what was an UID and 
a GID, like if the files were two persons talking and asking each other  
what's your UID?, we got the same, so, what is your GID ?, and I never had 
problems with UID and GID since that :D

I have thinked to try to return an array of values  like a function does 
(instead of passing many params to a sub) but didn't take the time to do it.

I believe that programming in python involves to learn a kind of new 
phillosophy, new words too. as an exemple of this, for me
a 'tuple' is related to database stuff. What I call an array seems to be 
called a list in python (C programmers use the word 'matrix' when talking of 
a two dimentionnal array, and 'vector' when talking of a one dimention 
array...sorry, a list :D ).

Regards,
Dominique.


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


Re: from vb6 to Python

2004-12-11 Thread houbahop d.lapasset
Hi,
I have used VB6 a lot too and Python appears to me as a good alternative to 
.net too, but
the thing that will do the difference is the GUI... I hope the ones for 
Python are beautifull enough as appearence is an important thing to me in 
softwares.
D.

MarcoL [EMAIL PROTECTED] a écrit dans le message de news: 
[EMAIL PROTECTED]
 Hello,
 I am a VB6 programmer and I would like to learn a new high level language 
 (instead of restarting from scratch with .NET), wich is opensource and 
 cross-platform, in order to develop cross-platform business applications
 I think Python is the most suitable language for the scope.
 My question are:

 - Which version of python is more suitable for creating cross-platform 
 GUI's? I've herard of PyGTK, wxPython, PyQT, tk, Anygui..

 - What is the best IDE/RAD for Python (written in Python and OpenSource)

 - Does exist a tool (written in Python and OpenSource) like Crystal Report 
 for creating business reports?

 - Does exist a tool (written in Python and OpenSource) for makeing tables, 
 view, querys, relation of a database and generate the SQL script?

 - Is it possible, from Python, to work with sqlite? And with MsAccess?

 Thanks for your patience and your help.


 Marco. 


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


Re: thread/queue bug

2004-12-11 Thread Tim Peters
[Peter Otten]
 What I believe to be a minimal example:

 freeze.py
 import Queue
 import threading
 import time
 
 q = Queue.Queue(4)
 
 def proc():
while True:
q.get(1)
Queue.Queue()
print YADDA
 
 threading.Thread(target=proc).start()
 
 while True:
print yadda
q.put(None)
time.sleep(1)
 /freeze.py
 
 freezemain.py
 import freeze
 /freezemain.py

CPython has an internal, reentrant import lock.  When a thread does an
import, it acquires this lock, and the lock remains held until that
import is complete.  As a consequence, no *other* thread can do an
import (it blocks waiting to obtain the internal import lock) until
the original import completes.  So until import freeze returns in
the main thread, no other thread can do an import.

Partly for that reason, it's generally a Horrible Idea to start a
thread as a side effect of importing a module.  That's what freeze.py
does, and you get the expected deadlock as a result.  The main thread
is hung waiting for import freeze to return, and the spawned thread
is hung at an import in Queue.__init__() waiting for the main thread
to release the import lock.

 Invoking freezemain.py produces

 yadda
 yadda
 yadda
 yadda
 yadda
 yadda
 
 i. e. consistently q.maxsize + 2. One item about to be put, one
 already taken before Queue.Queue(). Deferring execution of the
 module-level code until after the import

 nofreeze.py
 import Queue
 import threading
 import time
 
 q = Queue.Queue(4)
 
 def proc():
while True:
q.get(1)
Queue.Queue()
print YADDA
 
 def start():
threading.Thread(target=proc).start()
 
while True:
print yadda
q.put(None)
time.sleep(1)
 /nofreeze.py
 
 nofreezemain.py
 import nofreeze
 nofreeze.start()
 /nofreezemain.py
 
 and invoking nofreezemain.py produces
 yadda
 YADDA
 yadda
 YADDA
 yadda
 YADDA
 yadda
 YADDA
 
 apparently ad infinitum.

Right.  Note that this is the same reason threaded tests in Python's
standard regression suite define a 'test_main()' function, called by
the regrtest.py driver after import of the test's module completes. 
It's generally suicidal to start a thread as a side effect of an
import.

...

 Import _is_ a sensitive phase...

It's quite easy to avoid thread problems in imports:  never start a
thread as a side effect of importing, and you'll never get a deadlock
due to importing.

 As an experiment I moved
 
 try:
import thread
 except ImportError:
import dummy_thread as thread
 
 from the Queue.Queue.__init__() method to the module body --
 and now freezemain.py seems to work, too. So that would be an
 easy remedy, but sure there is a reason why that import
 statement is in such an unusual place?

I think you'd have to ask Brett (who did most of the work on
dummy_thread and dummy_threading).  It doesn't really matter, though: 
it's a general truth that starting a thread as a side effect of
importing is a recipe for deadlock, and hacking specific methods and
functions to avoid imports just moves the problem around.  It's not a
goal that anything in the standard Python library cater to bad thread
practice here (the bad thread practice being, again, starting a thread
as a side effect of importing).
-- 
http://mail.python.org/mailman/listinfo/python-list


character encoding conversion

2004-12-11 Thread Dylan

Here's what I'm trying to do:

- scrape some html content from various sources

The issue I'm running to:

- some of the sources have incorrectly encoded characters... for
example, cp1252 curly quotes that were likely the result of the author
copying and pasting content from Word

I've searched and read for many hours, but have not found a solution
for handling the case where the page author does not use the character
encoding that they have specified.

Things I have tried include encode()/decode(), and replacement lookup
tables (i.e. something like
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/116158ad706dc7c1/11991de6ced3406b?q=python+html+parser+cp1252_done=%2Fgroups%3Fq%3Dpython+html+parser+cp1252%26qt_s%3DSearch+Groups%26_doneTitle=Back+to+Searchd#11991de6ced3406b
) .  However, I am still unable to convert the characters to something
meaningful.  In the case of the lookup table, this failed as all of
the imporoperly encoded characters were returning as ? rather than
their original encoding.

I'm using urllib and htmllib to open, read, and parse the html
fragments, Python 2.3 on OS X 10.3 

Any ideas or pointers would be greatly appreciated.

-Dylan Schiemann
http://www.dylanschiemann.com/



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


Hashes

2004-12-11 Thread Michael McGarry
Hi,
Are there hashes in Python?
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: uptime for Win XP?

2004-12-11 Thread Peter Hansen
Tom Wesley wrote:
Esmail Bonakdarian wrote:
Is there a way to display how long a Win XP system has been up?
Somewhat analogous to the *nix uptime command.
I believe that uptime works from the console, but don't have a machine 
to check it with...
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
c:\uptime
'uptime' is not recognized as an internal or external command,
operable program or batch file.
Not here, at any rate.  Maybe it's part of the Productivity Kit
thingy?
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hashes

2004-12-11 Thread Peter Hansen
Michael McGarry wrote:
Are there hashes in Python?
Define hash.  Or look at Python's 'dict' type, or the hash()
function and decide for yourself if that's what you meant.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: building python extensions with .net sdk compiler?

2004-12-11 Thread Grumman
Mike C. Fletcher wrote:
Grumman wrote:
Of course it'd be nice if msvccompiler.py just fell back to looking 
for the toolkit/sdk default dirs (or looked them up via environment 
vars, since the toolkit does include a vcvars32.bat that sets 
appropriate ones) if the VS lookup failed.

Which is what the patch here:
   http://www.vrplumber.com/programming/mstoolkit/
does.
Looks like you beat me to it. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hashes

2004-12-11 Thread Michael McGarry
Peter Hansen wrote:
Michael McGarry wrote:
Are there hashes in Python?

Define hash.  Or look at Python's 'dict' type, or the hash()
function and decide for yourself if that's what you meant.
-Peter
Yes, I guess the dict type is what I am looking for.
Thank you,
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread Giovanni Bajo
Jive wrote:

 4) Buy a copy of the VC++ 7.1 and port Numeric myself. (I still don't
 know what to buy from Mr. Gates -- VC++ .net Standard?)


VC++ 7.1, the compiler/linker, is a free download. Google for VC toolkit. You
won't get the fancy IDE and stuff, but you have everything you need to build
your extensions. I saw patches floating around to build Python itself with the
free version (a couple of small nits).
-- 
Giovanni Bajo


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


Re: Upgrading Python Article

2004-12-11 Thread Tim Roberts
JanC [EMAIL PROTECTED] wrote:

Fuzzyman schreef:

 On the other hand the microsoft
 compiler is *better* than gcc anyway :-)

It's better at optimising, but it doesn't support standard C  C++.  ;-)

I don't think that's fair.  Visual C++ 7.1 is signficantly better at
compliance than their past compilers.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread John Machin

Jive wrote:
 Here's my sitch:

 I use gnuplot.py at work, platform Win32.  I want to upgrade to
Python 2.4.
 Gnuplot.py uses extension module Numeric.  Numeric is now
unsupported.
 The documentation says If you are new to Numerical Python, please
use
 Numarray..  It's not that easy, dangit.  The download page for numpy
does
 not contain a 2.4 version of Numeric, and I suspect they do not
intend to
 release one, because there IS a 2.4 version of Numarray.

 So here are my choices:

 1) Switch from gnuplot.py to some other plotting package.
 2) Convince, bribe, or cajole someone to implement gnuplot.py using
 Numarray.
 3) Hack on gnuplot.py myself.  (Learning curve alert!)
 4) Buy a copy of the VC++ 7.1 and port Numeric myself. (I still don't
know
 what to buy from Mr. Gates -- VC++ .net Standard?)
 5) Do something else I haven't thought of.

 Any suggestions would be welcome.

 Jive I speet on backwards incompatibility Dadson

Why do you want to upgrade to 2.4? What do you mean by upgrade to
2.4?

Choice (5a) Install Python 2.4 and use that for whatever while
continuing to use 2.3 for gnuplot.
Choice (5b) Ask politely of the Numeric camp when/if they will make a
2.4-compatible Windows release.
Choice (5c) Ask politely of the Python community if anyone else is
contemplating making a 2.4 Windows distribution of Numeric.
Choice (5d) Read replies to your fulminations in another thread -- in
particular the one that says you need no truck with Mr Gates; in fact
you can use free non-MS compilers to make Python extensions for
Windows.

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


Re: uptime for Win XP?

2004-12-11 Thread Jonel Rienton
IIRC, i think it's part of the powertools or IT Toolkit

Peter Hansen said:
 Tom Wesley wrote:
 Esmail Bonakdarian wrote:

 Is there a way to display how long a Win XP system has been up?
 Somewhat analogous to the *nix uptime command.

 I believe that uptime works from the console, but don't have a machine
 to check it with...

 Microsoft Windows XP [Version 5.1.2600]
 (C) Copyright 1985-2001 Microsoft Corp.

 c:\uptime
 'uptime' is not recognized as an internal or external command,
 operable program or batch file.


 Not here, at any rate.  Maybe it's part of the Productivity Kit
 thingy?

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



-- 

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


Re: GUIs: wxPython vs. Tkinter (and others)

2004-12-11 Thread Mike Meyer
Fredrik Lundh [EMAIL PROTECTED] writes:

 Mike Meyer wrote:
 It also has a widget for creating Windows wizards for walking
 through a set of options.
 Besides the fact that wizards isn't really that great (read Cooper), if your
 toolkit doesn't let you create a dialogue with a couple of buttons and a
 swappable frame, it's not a very good toolkit.  (that's very easy, in both
 Tkinter and wxPython.  You can probably find ready-made modules on
 the net if you look around a little)

While I'm not a big fan of wizards, for some applications they are
just the ticket, as you're walking down a tree of options. Presenting
the user the options at each node is exactly the way to go. Sure, it
may be easy to roll your own in TkInter, but in PyQt you don't have to.

 At the python level, slots are just callable objects. At the
 C++ level, slots are magic methods of objects. Signals are usually
 associated with GUI events, but Python can emit them for whatever
 reason it wants. It's possible to connect C++ signals to C++
 slots/signals in Python, meaning that Python won't be involved when
 that signal is emitted.

 That's would of course be a great argument if you didn't have Python.
 (even if Python's slower than C++, it's a lot faster than a user).

It's still nice to be able to let the C++ code handle it all. After
all, having the compiled layer do things for you is what makes for
fast python code.

 PyQt provides a higher level of abstraction.

 Whan what?  C++ plus a low level UI API, sure.  But Tkinter+Python?
 wxPython+Python?  You gotta be kidding.

No, I'm not kidding. I'm stating my general impression after having
done programming with both TkInter and PyQt. Note, that's *Py*Qt, not
Qt. 

 I've never tried doing animation in TkInter. Qt provides timer devices
 that you can use to drive animations. I suspect that doing the same in
 TkInter would be noticably more difficult.

 Eh?  You don't know how to do a loop in Python?  Or register a callback?
 wxPython contains both timers and a low-level graphics API; for Tkinter,
 you the after facility and the Canvas; if you need lower-level drawing
 with tighter Python intergration, use the WCK.

Sure, you can roll a loop together with a sleep and do animation. You
can throw in threading and queues so you can keep the GUI active while
you're doing it. With Qt, you tie the timer's signal to the
object-moving function, and you're done. Since you have to use the
threaded version to get the same functionality, I'd say noticably more
difficult isn't an overstatement.

  mike
-- 
Mike Meyer [EMAIL PROTECTED]  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: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread Jive

John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Why do you want to upgrade to 2.4? What do you mean by upgrade to 2.4?

Well, for one thing, when I previously installed and then uninstalled 2.4,
pythonwin broke, and neither I nor the win32 gurus can figure out what the
heck happened.


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


Re: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread Robert Kern
Jive wrote:
Here's my sitch:
I use gnuplot.py at work, platform Win32.  I want to upgrade to Python 2.4.
Gnuplot.py uses extension module Numeric.  Numeric is now unsupported.
The documentation says If you are new to Numerical Python, please use
Numarray..  It's not that easy, dangit.  The download page for numpy does
not contain a 2.4 version of Numeric, and I suspect they do not intend to
release one, because there IS a 2.4 version of Numarray.
I think they will as soon as someone steps up to compile it. The active 
maintainer uses Linux primarily, so it's not easy for him to do it 
himself. He's in a similar boat as you (except that he himself doesn't 
need a Windows binary. Natch.).

--
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


remove child in DOM??

2004-12-11 Thread Juliano Freitas
Hello!!


how can i remove a child in DOM ?

for example, i have thi xml below:
root
  user
 name juliano /name
  /user
root

and i want to remove the name element:
root
  user 
  /user
root


how can  i do this??

Juliano Freitas

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


Re: uptime for Win XP?

2004-12-11 Thread Nick Coghlan
Esmail Bonakdarian wrote:
Hi,
Is there a way to display how long a Win XP system has been up?
Somewhat analogous to the *nix uptime command.
Thanks,
Esmail
It's included in the output of the 'systeminfo' command. That command is fairly 
slow, though (since it displays a lot more than just the up time)

There's also info about the 'uptime' utility here:
http://support.microsoft.com/kb/q232243/
I don't know if that works for XP.
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-11 Thread Nick Coghlan
Jive wrote:
John Machin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Why do you want to upgrade to 2.4? What do you mean by upgrade to 2.4?

Well, for one thing, when I previously installed and then uninstalled 2.4,
pythonwin broke, and neither I nor the win32 gurus can figure out what the
heck happened.
And reinstallation of 2.3 and the Py2.3 win32all didn't fix it? Very 
strange. . .
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Error in msvc in building inheritance.obj to build hello.pyd

2004-12-11 Thread AIM
Error in msvc in building inheritance.obj to build hello.pyd

Hello,

I am trying to build the boost 1.31.0 sample extension hello.cpp.
I can not compile the file inheritance.cpp because the two
files containing some templates: adjacency_list.hpp and mem_fn.hpp can
not compile.

Does anyone have any solutions?
Instead of Visual C++ 6.0 should I use a different compiler?
Anyone have any success on any other compiler?

Did anyone manage to build a hello.pyd?

Thank you very much.
Here is my script below (with embedded results).

rem I have MSVC 6.0 Service Pack 5  on Windows 2000 Service Pack 3
default installs on F:
rem Python is located in F:\Python23
rem Boost is located in W:\boost_1_31_0
rem MSVC stlPort 4.6.2 installed, compiled and
rem VC studio include dirs and libraries dirs configured to use it.

rem build boost.jam (so I have a bjam.exe for all below)
W:
vcvars32.bat
cd W:\boost_1_31_0\tools\build\jam_src
rem below since I have multilple toolsets installed I will always be
specific.
.\build.bat msvc
rem result: 2 minutes later: NO WARN NO ERRORS
dir W:\boost_1_31_0\tools\build\jam_src\bin.ntx86\*
rem result: OK I have *jam*.exe executables: bjam.exe jam.exe
mkjambase.exe yyacc.exe


rem build boost (using boost.jam (bjam from above))
W:
vcvars32.bat
set PYTHON_ROOT=F:\Python23
set PYTHON_VERSION=2.3
set PATH=%PATH%;W:\boost_1_31_0\tools\build\jam_src\bin.ntx86
rem APPEND THE  BJAM PATH ABOVE TO THE SYSTEM ENVRONMENT VARIABLE PATH
cd W:\boost_1_31_0
rem below since I have multilple toolsets installed I will always be
specific.
bjam -sTOOLS=msvc install


rem about 90 minutes later ERROR RESULTS FOLLOW:
 errors.txt contents below 

cl  /Zm800 -nologo -GX -c  -DNDEBUG -DNDEBUG -DBOOST_PYTHON_DYNAMIC_LIB
-DBOOST_PYTHON_SOURCE  /Ogity /O2 /Gs /Ob2 /GX /GR /MD
-Ibin\boost\libs\python\build  -IW:\boost_1_31_0
-IF:\Python23\include -IF:\Program Files\Microsoft Visual
Studio\VC98\Include
-Fobin\boost\libs\python\build\boost_python.dll\msvc\release\inheritance.obj
-TpW:\boost_1_31_0\libs\python\build\../src/object/inheritance.cpp

rem error below results below ...

F:\Program Files\Microsoft Visual Studio\VC98\Bincl  /Zm800 -nologo
-GX -c  -DNDEBUG -DNDEBUG -DBOOST_PYTHON_DYNAMIC_LIB
-DBOOST_PYTHON_SOURCE  /Ogity /O2 /Gs /Ob2 /GX /GR /MD
-Ibin\boost\libs\python\build  -IW:\boost_1_31_0
-IF:\Python23\include
-IF:\Program Files\Microsoft Visual Studio\VC98\Include
-Fobin\boost\libs\python\build\boost_python.dll\msvc\release\inheritance.obj
-TpW:\boost_1_31_0\libs\python\build\../src/object/inheritance.cpp
inheritance.cpp
W:\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1055) : error
C2244: 'bidirectional_graph_helper_with_propertyConfig::remove_edge'
: unable to resolve function overload
W:\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1057) : error
C2954: template definitions cannot nest
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2039: 'dm' : is not a
member of '_mfi'
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2143: syntax error :
missing ';' before ''
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2501: 'dm' : missing
storage-class or type specifiers
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2059: syntax error : ';'
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2059: syntax error : ''
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2653: 'T' : is not a
class or namespace name
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2645: no qualified name
for pointer to member (found ':: *')
W:\boost_1_31_0\boost/mem_fn.hpp(320) : error C2143: syntax error :
missing ';' before '}'
W:\boost_1_31_0\boost/mem_fn.hpp(320) : fatal error C1506:
unrecoverable block scoping error

F:\Program Files\Microsoft Visual Studio\VC98\Bin

W:\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1055) : error
C2244: 'bidirectional_graph_helper_with_propertyConfig::remove_edge'
: unable to resolve function overload
W:\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1057) : error
C2954: template definitions cannot nest


rem the problem area in adjacency_list.hpp is here ...

template class Config
inline void

bidirectional_graph_helper_with_propertyConfig::remove_edge(typename
Config::edge_descriptor e)
{
typedef typename Config::graph_type graph_type;
graph_type g = static_castgraph_type(*this);
boost::remove_edge(source(e, g), target(e, g), *this);
}
// O(E/V) or O(log(E/V))
template class EdgeOrIter, class Config
inline void
remove_edge(EdgeOrIter e,
bidirectional_graph_helper_with_propertyConfig g_)
{
g_.remove_edge(e);
}


W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2039: 'dm' : is not a
member of '_mfi'
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2143: syntax error :
missing ';' before ''
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2501: 'dm' : missing
storage-class or type specifiers
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2059: syntax error : ';'
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2059: syntax error : ''
W:\boost_1_31_0\boost/mem_fn.hpp(315) : error C2653: 'T' : is not a

Re: PEP 338: Executing modules inside packages with '-m'

2004-12-11 Thread alia_khouri
A useful feature that is a logical extension of current '-m' behaviour.
(I'm actually surprised it was left out in the first place)

This will definitely allow me and other python programmers to package
our scripts better

Sounds Good to me. (-;

Thank you for the PEP

AK

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


Re: Error in msvc in building inheritance.obj to build hello.pyd

2004-12-11 Thread AIM
Donne Leen,

Thanks, thats a very good solution.  I am glad to hear that the later
solution works for you.

I will try to get the 1.32.0 source Monday.  I will try to compile
again next week.

Andre Mikulec
AIM

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


Re: PEP 338: Executing modules inside packages with '-m'

2004-12-11 Thread Nick Coghlan
[EMAIL PROTECTED] wrote:
A useful feature that is a logical extension of current '-m' behaviour.
(I'm actually surprised it was left out in the first place)
That seems to be a common reaction :)
It was dropped for 2.4 because I wasn't sure exactly how it should work, and 2.4 
was already in beta at the time. So I went with the cookbook recipe instead.

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


Howto Extract PNG from binary file @ 0x80?

2004-12-11 Thread flamesrock
Hi,

As a newbie to the language, I have no idea where to start..please bare
with me..

The simcity 4 savegame file has a png image stored at the hex location
0x80. What I want to extract it and create a file with the .png
extension in that directory.

Can somebody explain with a snippet of code how I would accomplish
this? I've looked around but the information is too vague and I don't
know how to start.

-thanks in advance

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


Re: High level SNMP

2004-12-11 Thread Keith Dart
Jeremy Sanders wrote:
Hi -
I'd like to write a program which basically does a few snmpgets. I haven't
been able to find a python package which gives you a nice high-level and
simple way of doing this (like PHP has). Everything appears to be
extremely low level. All I need is SNMPv1.
Does anyone know of a simple python package for doing this? I'd rather
have something written in pure python, so that it is easily cross-platform.
Jeremy
The pyNMS package at sourceforge has a complete SNMP (v1, v2c) 
implementation. In pure Python, and fairly self contained. See

http://sourceforge.net/projects/pynms
There are few docs, sorry. If you want to use it and have any questions 
then please let me know (I wrote it).

BTW, you can also read MIB files if you have libsmi installed. But the 
pyNMS package contains a utility called mib2py that converts MIB objects 
to Python, and the pyNMS package has most standard MIBS pre-compiled. 
So, you don't really need libsmi to use the standard MIBs.

The name means Python Network Management System, and will become a 
complete network management system with GUI and scriptability soon. ;-)

There is some support for creating XHTML reports, NMS web interface, 
SNMP get/set, SNMP trap receiver, Ping/ICMP module, process management, 
MIB browser, CLI construction kit, web protocols, easy email interface, 
and asyncio framework. Works well with Linux or FreeBSD.

(PS. It can also answer your phone and take a message)

--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart [EMAIL PROTECTED]
vcard: http://www.kdart.com/~kdart/kdart.vcf
public key: ID: F3D288E4   URL: http://www.kdart.com/~kdart/public.key

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


Re: Raw Sockets vs. What?

2004-12-11 Thread Diez B. Roggisch

 So, the question: How to communicate between two instances of the
 python interpreter? Specifically, I need to pass the api and objects
 from bdb, the base class for the debugger. One interpreter runs the
 ide, the other the debugger and client code. We were talking and just
 opening a socket and doing the rest from there came up. This, to me,
 (admitedly a java guy) seems like a lot of work. If it were just
 setting breakppoints and stepping, well ok. But I also want to have
 introspection on the debugger side objects.
 
 I could use raw sockets and write a bunch of stuff.
 
 Does anyone have a suggestion about some pythonesque way to tackle
 this?

I've found pyro useful for a similar task: I fork, create a pipe and in the
child  I create a pyro daemon to run a remote object. The uri of that then
is passed using the pipe, so that the parent can get a reference to the
remote object.

I do the whole exercise due to not killable threads in python - so that I
can terminate the subprocess.

The nice thing about pyro is that it is like corba without the declartive
stuff - just use it. 

You also migh check out the eric ide - it has an out-of-process debugger, so
Detlev must have found a solution :)
-- 
Regards,

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


How to remove packages - wxPython

2004-12-11 Thread Peter
Linux kernel 2.6.9
Slackware 10
Python version 2.3.4
wxPython version 2.4.2.4

I compiled and installed wxPython.

There is no uninstall script that I can find for the py components. The
library component has a make uninstall.

What is the proper way to uninstall packages? I searched everywhere, but
there seems to be no clearcut explanation.

Can I just remove the site-package directories it created? Or is there a
central config file for python?

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


your favorite quick reference? (was Python Docs. Hardcopy 2.4 Library Reference, interested?)

2004-12-11 Thread Esmail Bonakdarian
somewhat related .. is there a good quick reference for python?
o'reilly has a quick ref guide 2nd ed is a few years old, and
the ones i have found on-line seem a bit big. I am looking for
something relatively concise that I can carry with me ... not
sure such a thing exists?
thanks.
--
http://mail.python.org/mailman/listinfo/python-list


SocketServer class examples

2004-12-11 Thread Adil Hasan

Hello Fred,
   I just ran across your question. I think that the following
code will work:

- SERVER CODE --
import SocketServer
import time
class GreetingHandler(SocketServer.BaseRequestHandler):
'''Class to handle sending a greeting to a client
'''
def handle(self):
'''Method to actually handle the greeting
'''
print 'handling the request'
line = self.request.recv(bufsize)
name = 
if ('NAME:' in line):
   name = line.split('NAME:')[1]
self.request.sendall('hello there %s \n' % name)

def manageServer():
'''Function to manage the running of the server and handling of
requests
'''
servObj = SocketServer.TCPServer(('localhost',6099),GreetingHandler)
print 'Starting the server...'
servObj.serve_forever()

if __name__ == '__main__':
manageServer()

- CLIENT CODE -
#!/usr/bin/env python
import socket
def manageClient():
'''Function to manage the sending of request to the server
'''
server = 'localhost'
port   = 6099
servObj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
servObj.connect((server, port))
servObj.send('NAME: An Elephant\r\n')
resp = servObj.recv(8192)
print resp
servObj.close()

if __name__ == '__main__':
manageClient()



I think that the problem with the rfile and wfile methods in the
StreamRequestHandler class is that it's trying to send on the
same socket as it's reading data on so they are blocking each
other. I think that this is a problem in the StreamRequestHandler
class.

adil

-Original Message-
From: Frederick Grim [mailto:fgrim at norby.dyndns.org]
Sent: 18 July 2004 19:34
To: python-list at python.org
Subject: SocketServer class examples

Howdy group,
So I am in the middle of using the socketserver class from the std
library and have run into a problem that probably reveals my
misunderstanding of sockets.  I have a class defined like so:

class tcp_listener(SocketServer.ThreadingTCPServer):
def __init__(self, addr, port):
SocketServer.ThreadingTCPServer.__init__(self, \
(addr, port), Daemon.request_handler)

 Yes I realize the above is silly and redundant 

And a request handler in Daemon that has a handle function that works like
so:
def __req_handle(self, req):
 Do stuff with req and return a response afterwards 
return response

def handle(self);
while True:
input = self.rfile.readline()
request = input
while input and not re.search('EOF$', input):
input = self.rfile.readline()
request += input

self.wfile.write(self.__req_handle(request))

The client end looks almost identical to the example in the python docs.
So
the problem here is that this code doesn't work.  Using tcpdump I can tell
that the client is sending to the server properly but the server is never
responding.  Or when it tries to respond it gets stuck in the write.
What's
going on here.  I can't seem to find a single example of how to use this
class on the client and server side and I don't want to use twisted
(because
I should understand how this works instead of relying on canned software).
Does anyone know where I can find an example of a functioning SocketServer
and client? Google seems to help nought here.
Thanks,
Fred






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


Re: Python vs. Perl

2004-12-11 Thread Christopher De Vries
Roy Smith already touched on regular expressions, but as far as
features go, I would say that the real difference between python and
perl is not in the features, but in the philosophy. It seems to me that
any program you can write in python could also be written in perl. What
it comes down to for me was which language most fit the way I tend to
think. I decided python was that language, and I found everything very
intuitive. I have a good friend who thinks in perl and is very
productive using it.

Other people might disagree, but when I was looking at perl and python
I borrowed recent copies of Learning Perl and Learning Python  from
the O'Reilly series and after reading each, decided I preferred python.
You can find out about most of the features in those books.

Chris

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


Re: swig Python question

2004-12-11 Thread It's me
Whether SWIG will work in a no brainer way or not depends on the original
code, I think.  If the original code uses a very convoluted design, of
course things will get hairy.   If the package uses a very clean structure,
I think you will find SWIG works out very nicely.

The intriguing things is, however, once you structure the package to a form
SWIG would work, it opens up the door to support multiple script languages
(and they have a long list of supported script languages).

If you hand crafted it to run the Python-C API, then you can only use Python
as script.

--
It's me


Keith Dart [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 It's me wrote:
  It's me [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 I am playing around with SWING building a Python module using the no
 
  brainer
 
 example in http://www.swig.org/tutorial.html.   With that first example,
 
 
 
  Oops!  Soapy fingers.   SWIG - not SWING.
 
  --
  It's me.

 I have used SWIG before, and it's not always such a no-brainer. In
 fact, it rarely is except for trivial examples. But it can work. I think
 it is best suited for wrapping large libraries. For small stuff, it
 would be better to just do it manually using the Python C API.


 Good luck.

 --
 It's not me.




 -- 
 \/ \/
 (O O)
 -- oOOo~(_)~oOOo--
--
 Keith Dart [EMAIL PROTECTED]
 public key: ID: F3D288E4




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


Re: newbie questions

2004-12-11 Thread houbahop d.lapasset
Hello again everyone ,
var2[:]=[] has solved my problem, and I don't understand why it is 
programming by side effect.
I don't think it's bad, look at this, it's what I've done :

def Clear(lvar)
lvar[:]=[]

def main (starting class)
   var1=[]
   var1.append('a')
   Clear(var1)

var1 can only be modified by  Clean(), so, if I need to debug var1, I 
quickly know that I must look in Clean()


For me programming by side effect is that :

def Clear(lvar)
var1=[]

def main (starting class)
   global var1=[]
   var2=[]
   var1.append('a')
   Something(var2)


I am wrong?
Dominique. 


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


Re: How to remove packages - wxPython

2004-12-11 Thread Peter
Peter Hansen wrote:

 Peter wrote:
 Linux kernel 2.6.9
 Slackware 10
 Python version 2.3.4
 wxPython version 2.4.2.4
 
 I compiled and installed wxPython.
 
 There is no uninstall script that I can find for the py components. The
 library component has a make uninstall.
 
 What is the proper way to uninstall packages? I searched everywhere, but
 there seems to be no clearcut explanation.
 
 Can I just remove the site-package directories it created? Or is there a
 central config file for python?
 
 Generally speaking, just removing the subfolder(s) from site-packages
 will completely remove an extension.  Some few extensions will also
 create a .pth file in the site-packages folder, so check for that
 as well.  No doubt there are exceptions, but I believe this will
 cover 95% of the cases.
 
 -Peter

That's what I thought. Just wanted to be sure. I think this program actually
created two separate site-packages folder, wxPython and wx. I need to check
the install script and see what was doing.

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


handy stacktrace class

2004-12-11 Thread Will Ware
I was fooling with some Python code, and starting to miss the
Exception.printStackTrace() feature in Java. Here is a stab at
something roughly analogous, which puts together a stacktrace
as an XML document.

import xml.dom.minidom

class Stacktrace(xml.dom.minidom.Document):
def __init__(self):
import sys
xml.dom.minidom.Document.__init__(self)
stacktrace = self.createElement(stacktrace)
self.appendChild(stacktrace)
try:
raise Exception
except:
tb = sys.exc_traceback
x = tb.tb_frame.f_back
while x != None:
f = x.f_code
frame = self.createElement(frame)
frame.setAttribute(func, f.co_name)
frame.setAttribute(file, f.co_filename)
frame.setAttribute(line, repr(f.co_firstlineno))
stacktrace.appendChild(frame)
x = x.f_back
def __repr__(self):
import xml.dom.ext
class MyStream:
def __init__(self):
self.str = 
def write(self, x):
self.str += x
stream = MyStream()
xml.dom.ext.PrettyPrint(self, stream)
return stream.str[:-1]   # trim trailing newline

The rational for doing this as an XML document was, uh, gee, I
thought I had a good reason at the time. I think I've seen XML
sequences of stacktraces elsewhere and it looked like a good idea.
My brief time of muddling about with xml.dom.minidom makes me
think that elements are inherently tied to a particular document
and can't just be lifted and moved to another document, as one
might want to do to, say, build a sequence of stacktraces while
debugging something. But I'm sure there's some kind of workaround
for that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Overriding properties

2004-12-11 Thread Nick Patavalis
Why does the following print 0 0 instead of 0 1? What is the
canonical way to rewrite it in order to get what I obviously expect?

  class C(object):
  __val = 0
  def set_value(self, val):
  if val  0 : self.__val = 0
  else : self.__val = val
  def get_value(self):
  return self.__val
  value = property(get_value, set_value)
  
  class CC(C):
  def set_value(self, val):
  if val  0: self.__val = 1
  else : self.__val = val
  
  c = C()
  cc = CC()
  c.value = -1
  cc.value = -1
  print c.value, cc.value

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


Re: from vb6 to Python

2004-12-11 Thread Martijn Faassen
Luis M. Gonzalez wrote:
MarcoL wrote:
Hello,
I am a VB6 programmer and I would like to learn a new high level
language (instead of restarting from scratch with .NET...

I'd like to add that by going with Python, you'll also be able to
develop for .NET. Check this out: www.ironpython.com .
Since the development of Ironpython is now being funded by Microsoft,
you'll get the best of both worlds: An already excellent
cross-platform, object oriented language and a fully compliant .NET
language for Windows and Linux (through Mono and DotGnu).
Unfortunately this is currently not near production use, and whether 
Microsoft is funding IronPython development is up in the air:

One IronPython fan noted a disconcerting silence in IronPython development:
http://usefulinc.com/edd/blog/contents/2004/12/09-jvm/read
Of course it'll all resolve itself one way or another eventually, just 
wanted to correct the impression that IronPython is ready to go already.

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


PEP 338: Executing modules inside packages with '-m'

2004-12-11 Thread Nick Coghlan
Python 2.4's -m command line switch only works for modules directly on sys.path. 
Trying to use it with modules inside packages will fail with a Module not 
found error. This PEP aims to fix that for Python 2.5.

Previously, posting of a draft version of the PEP to python-dev and python-list 
didn't actually generate any responses. I'm not sure if that's an indication 
that people don't see the restriction to top-level modules as a problem (and 
hence think the PEP is unecessary), or think the extension to handle packages is 
obvious (and hence see no need to comment).

Or, it could just be a sign that Python 2.4 hasn't been out long enough for 
anyone to care what I'm yabbering on about :)

Anyway, all comments are appreciated (even a simple Sounds good to me).
Cheers,
Nick.
***
PEP: 338
Title: Executing modules inside packages with '-m'
Version: $Revision: 1.2 $
Last-Modified: $Date: 2004/12/11 20:31:10 $
Author: Nick Coghlan [EMAIL PROTECTED]
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Created: 16-Oct-2004
Python-Version: 2.5
Post-History: 8-Nov-2004
Abstract

This PEP defines semantics for executing modules inside packages as
scripts with the ``-m`` command line switch.
The proposed semantics are that the containing package be imported
prior to execution of the script.
Rationale
=
Python 2.4 adds the command line switch ``-m`` to allow modules to be
located using the Python module namespace for execution as scripts.
The motivating examples were standard library modules such as ``pdb``
and ``profile``.
A number of users and developers have requested extension of the
feature to also support running modules located inside packages.  One
example provided is pychecker's ``pychecker.checker`` module.  This
capability was left out of the Python 2.4 implementation because the
appropriate semantics were not entirely clear.
The opinion on python-dev was that it was better to postpone the
extension to Python 2.5, and go through the PEP process to help make
sure we got it right.
Scope of this proposal
==
In Python 2.4, a module located using ``-m`` is executed just as if
its filename had been provided on the command line.  The goal of this
PEP is to get as close as possible to making that statement also hold
true for modules inside packages.
Prior discussions suggest it should be noted that this PEP is **not**
about any of the following:
- changing the idiom for making Python modules also useful as scripts
  (see PEP 299 [1]_).
- lifting the restriction of ``-m`` to modules of type PY_SOURCE or
  PY_COMPILED (i.e. ``.py``, ``.pyc``, ``.pyo``, ``.pyw``).
- addressing the problem of ``-m`` not understanding zip imports or
  Python's sys.metapath.
The issues listed above are considered orthogonal to the specific
feature addressed by this PEP.
Current Behaviour
=
Before describing the new semantics, it's worth covering the existing
semantics for Python 2.4 (as they are currently defined only by the
source code).
When ``-m`` is used on the command line, it immediately terminates the
option list (like ``-c``).  The argument is interpreted as the name of
a top-level Python module (i.e. one which can be found on
``sys.path``).
If the module is found, and is of type ``PY_SOURCE`` or
``PY_COMPILED``, then the command line is effectively reinterpreted
from ``python options -m module args`` to ``python options
filename args``.  This includes setting ``sys.argv[0]`` correctly
(some scripts rely on this - Python's own ``regrtest.py`` is one
example).
If the module is not found, or is not of the correct type, an error
is printed.
Proposed Semantics
==
The semantics proposed are fairly simple: if ``-m`` is used to execute
a module inside a package as a script, then the containing package is
imported before executing the module in accordance with the semantics
for a top-level module.
This is necessary due to the way Python's import machinery locates
modules inside packages.  A package may modify its own __path__
variable during initialisation.  In addition, paths may affected by
``*.pth`` files.  Accordingly, the only way for Python to reliably
locate the module is by importing the containing package and
inspecting its __path__ variable.
Note that the package is *not* imported into the ``__main__`` module's
namespace.  The effects of these semantics that will be visible to the
executed module are:
- the containing package will be in sys.modules
- any external effects of the package initialisation (e.g. installed
  import hooks, loggers, atexit handlers, etc.)
Reference Implementation

A reference implementation is available on SourceForge [2]_.  In this
implementation, if the ``-m`` switch fails to locate the requested
module at the top level, it effectively reinterprets the command from
``python -m script`` to ``python -m execmodule script``.  (There

problem with embbed boost.python in multi-interpreter and multi-thread HELP please

2004-12-11 Thread Donnie Leen
I wrote a program embbed boost.python, each thread running a sub-interpreter, i 
made a module implement by boost.python, and i wish this module imported in 
each sub-interpreter, i find that the module could initialize only once, 
otherwise the boost.python will throw a exception said that something already 
registered; second conversion method ignored.

So I try another way, initialize and import the module in one interpreter such 
as the main interpreter, and I hope to import the module in any 
sub-interpreter, because I found the python document said:
Extension modules are shared between (sub-)interpreters as follows: the first 
time a particular extension is imported, it is initialized normally, and a 
(shallow) copy of its module's dictionary is squirreled away. When the same 
extension is imported by another (sub-)interpreter, a new module is initialized 
and filled with the contents of this copy; the extension's init function is not 
called. 
but when i try this way i found that the program throw an 
exception:ImportError: No module named mym, (mym is the module name). This 
happens even i wrote the module in Python/C API without boost.python.

Could somebody tell me why this happened or how to deal with it, thanks for any 
suggestion.

Donnie Leen


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