From g.franzkowiak at onlinehome.de Fri Sep 30 12:44:10 2005
From: g.franzkowiak at onlinehome.de (g.franzkowiak)
Date: Fri, 30 Sep 2005 18:44:10 +0200
Subject: PyWin SendMessage
In-Reply-To:
References: <7jczvrb5.fsf@python.net>
Message-ID:
Gonzalo Monz?n schrieb:
> g.franzkowiak escribi?:
>
>> Thomas Heller schrieb:
>>
>>
>>> "g.franzkowiak" writes:
>>>
>>>
>>>
>>>
>>>> Thomas Heller schrieb:
>>>>
>>>>
>>>>
>>>>> "g.franzkowiak" writes:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Hello everybody,
>>>>>>
>>>>>> I've tryed to use an interprocess communication via
>>>>>> SendMessage on Windows.
>>>>>> Unfortunately, nothing goes on
>>>>>>
>>>>>> #########################################################################
>>>>>>
>>>>>> #! /usr/bin/env python
>>>>>>
>>>>>> import win32api, win32ui, win32con
>>>>>> import struct, array
>>>>>>
>>>>>> """
>>>>>> typedef struct tagCOPYDATASTRUCT { // cds
>>>>>> DWORD dwData;
>>>>>> DWORD cbData;
>>>>>> PVOID lpData;
>>>>>> } COPYDATASTRUCT;
>>>>>> """
>>>>>>
>>>>>> def packCopyData(nNum, sString):
>>>>>> int_buffer = array.array("L",[nNum])
>>>>>> char_buffer = array.array('c', sString)
>>>>>> int_buffer_address = int_buffer.buffer_info()[0]
>>>>>> char_buffer_address = char_buffer.buffer_info()[0]
>>>>>> char_buffer_size = char_buffer.buffer_info()[1]
>>>>>> copy_struct = struct.pack("pLp", # dword*, dword, char*
>>>>>> int_buffer_address,
>>>>>> char_buffer_size,
>>>>>> char_buffer)
>>>>>> return copy_struct
>>>>>>
>>>>>
>>>>> After packCopyData(...) returns, the arrays are destroyed, which will
>>>>> probably void their contents. You must keep them alive until you
>>>>> don't
>>>>> need the COPYDATASTRUCT instance any longer. For this kind of stuff,
>>>>> ctypes may be easier to use than pywin32.
>>>>>
>>>>> Thomas
>>>>>
>>>>
>>>> Hmm, have read something in <>
>>>> and the script changed to this:
>>>>
>>>> #---------------------------------------------------------
>>>> #! /usr/bin/env python
>>>>
>>>> import win32api, win32ui, win32con, win32gui
>>>> import struct, array
>>>>
>>>> from ctypes import *
>>>
>>>
>>>
>>>> """
>>>> typedef struct tagCOPYDATASTRUCT { // cds
>>>> DWORD dwData;
>>>> DWORD cbData;
>>>> PVOID lpData;
>>>> } COPYDATASTRUCT;
>>>> """
>>>>
>>>> class COPYDATATYPE(Structure):
>>>> _fields_ = [("nNum", c_ulong),
>>>> ("szData", c_char_p)]
>>>>
>>>> class COPYDATASTRUCT(Structure):
>>>> _fields_ = [("dwData", c_ulong),
>>>> ("cbData", c_ulong),
>>>> ("lpData", POINTER(COPYDATATYPE))]
>>>>
>>>> # get the window handle
>>>> hwnd = win32ui.FindWindow(None, "target window")
>>>>
>>>> # print just for fun
>>>> # ##print hwnd
>>>>
>>>> # prepare copydata structure for sending data
>>>> cpyData = COPYDATATYPE(1, '1')
>>>> cds = COPYDATASTRUCT(c_ulong(1),
>>>> c_ulong(sizeof(cpyData)),
>>>> pointer(cpyData))
>>>>
>>>> # try to send a message
>>>> win32api.SendMessage(hwnd,
>>>> win32con.WM_COPYDATA,
>>>> 0,
>>>> pointer(cds))
>>>>
>>>> #---------------------------------------------------------
>>>> and the message for the last line is:
>>>> ==> TypeError: an integer is required"
>>>>
>>>> This message comes with "pointer(cds)" and with "addressof(cds)"
>>>>
>>>
>>> That error refers to the first argument - win32ui.FindWindow returns a
>>> PyCWnd object, which is not accepted by win32api.SendMessage.
>>> Changing this brings you one step further. win32api.SendMessage accepts
>>> an integer for the last element, so addressof(cds) should work now.
>>>
>>> win32gui.SendMessage is more tolerant in what it accepts as 4th
>>> argument, according to the error message you get when you try it it
>>> expects a string, a buffer, or an integer. So you could use addressof()
>>> or pointer(), what you like best.
>>>
>>> Thomas
>>>
>>
>>
>> Super, operates :-))
>>
>> My last answer must be in the Nirvana, strange ?
>>
>> Ok, only the version with 'addressof' generates a message and I must
>> play with the data types. The receiver becomes a wrong data formate.
>> Expect (int=1, char[256]='1\00'), but the int is 0x31 and the string
>> somewhat. Must play with my data.
>>
>> Thanks
>> gerd
>>
>>
>
> Hi Gerd,
>
> I'm not really sure of, but I think you must use a message value in
> range of WM_USER or WM_APP so this fact maybe let the receiver window
> getting bad data... have a look to this:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesmessages/wm_user.asp
>
>
> 0 through WM_USER
>
> 0x0400
> Messages reserved for use by the system.
> *WM_USER* through 0x7FFF Integer messages for use by private window
> classes.
> *WM_APP* through 0xBFFF Messages available for use by applications.
> 0xC000 through 0xFFFF String messages for use by applications.
> Greater than 0xFFFF Reserved by the system.
>
>
>
> I've done the same with PHP GTK and achieved random results sending low
> Msg values... until used WM_USER and above. Also, in my case only
> PostMessage work fine... try using both... but expect this doesn't
> happen with python,
>
> Hope it helps.
>
> Gonzalo
Hi Gonzalo,
thank you for your interest and for your tips.
With your links was it possible to learn something over messages in user
applications. I'm not the windows guru, like the open source scene.
My problem was not the message type and I think the WM_COPYDATA is the
right thing for interprocess communication between python and C++.
I've changed in my script the COPYDATATYPE field szData from c_char_p to
c_char * 256 and the memory is correct initialized. The first situation
was according to **data and in consequence the wrong content on the
receiver side.
Now is it a good thing :-)
gerd
From pink at odahoda.de Fri Sep 9 16:41:45 2005
From: pink at odahoda.de (Benjamin Niemann)
Date: Fri, 09 Sep 2005 22:41:45 +0200
Subject: how to get the return value of a thread?
References:
Message-ID:
Leo Jay wrote:
> Dear all,
>
> i would like to get the return value of all threads
>
> e.g.
> def foo(num):
> if num>10:
> return 1
> elif num>50:
> return 2
> else
> return 0
>
>
> after i invoked
> t = thread.start_new_thread(foo,(12,))
> how to get the return value of `foo'?
Take a look at the Queue module. Create a queue instance at let the 'foo
thread' put() its result into it:
fooResult = Queue.Queue()
def foo(num):
result = 0
if num>10:
result = 1
elif num>50:
result = 2
fooResult.put(result)
t = thread.start_new_thread(foo,(12,))
# do other stuff, foo is running in background
r = fooResult.get() # guaranteed to block until result is available
print r
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
From tjreedy at udel.edu Sat Sep 10 21:26:21 2005
From: tjreedy at udel.edu (Terry Reedy)
Date: Sat, 10 Sep 2005 21:26:21 -0400
Subject: Python versus Perl
References:
Message-ID:
"Roy Smith" wrote in message
news:roy-A55323.15113410092005 at reader1.panix.com...
> Dieter Vanderelst wrote:
>> 1 - How does the speed of execution of Perl compares to that of Python?
> To a first-order approximation, Perl and Python run at the same speed.
'Speed of execution' is a feature of an inplementation, not of languages
themselves. Different implementations of Python (for instance, CPython
versus CPython+Psyco) can vary in speed by more than a factor of 10 for
particular blocks of Python code.
(Yes, I know you are comparing the stock standard implementations, but my
point still stands.)
> They are both interpreted languages.
To be useful, every language has to be interpreted sometime by something.
In the narrow technical sense that I presume you mean, 'interpretation'
versus 'compilation' is again an implementation feature, not a language
feature. As far as I know, neither Perl nor Python has an implementation
that directly interprets in the way that Basic or tokenized Basic once was.
I am being picky because various people have claimed that Python suffers in
popularity because it is known as an 'interpreted language'. So maybe
advocates should be more careful than we have been to not reinforce the
misunderstanding.
Terry J. Reedy
From csubich.spamblock at subich.spam.com.block Wed Sep 21 14:46:23 2005
From: csubich.spamblock at subich.spam.com.block (Christopher Subich)
Date: Wed, 21 Sep 2005 14:46:23 -0400
Subject: Writing a parser the right way?
In-Reply-To: <1127323058.667034.43540@g49g2000cwa.googlegroups.com>
References: <1127300661.440587.287950@g47g2000cwa.googlegroups.com>
<1127306797.658461.264950@g44g2000cwa.googlegroups.com>
<1127323058.667034.43540@g49g2000cwa.googlegroups.com>
Message-ID:
beza1e1 wrote:
> Well, a declarative sentence is essentially subject-predicate-object,
> while a question is predicate-subject-object. This is important in
> further processing. So perhaps i should code this order into the
> classes? I need to think a little bit more about this.
A question is subject-predicate-object?
That was unknown by me.
Honestly, if you're trying a general English parser, good luck.
From timr at probo.com Fri Sep 30 02:41:39 2005
From: timr at probo.com (Tim Roberts)
Date: Fri, 30 Sep 2005 06:41:39 GMT
Subject: Straight line detection
References: <1127939495.032208.272230@z14g2000cwz.googlegroups.com>
Message-ID: <7enpj1paiadd4ourjttchtrrpdkq0krivg@4ax.com>
"PyPK" wrote:
>
>Does anyone know of a simple implementation of a straight line
>detection algorithm something like hough or anything simpler.So
>something like if we have a 2D arary of pixel elements representing a
>particular Image. How can we identify lines in this Image.
>for example:
>
>ary =
>[[1,1,1,1,1],
> [1,1,0,0,0],
> [1,0,1,0,0],
> [1,0,0,1,0],
> [1,0,0,0,1]]
>So if 'ary' represents pxl of an image which has a horizontal line(row
>0),a vertical line(col 0) and a diagonal line(diagonal of ary). then
>basically I want identify any horizontal or vertical or diagonal line
>anywhere in the pxl array.
If all you want is horizontal, vertical, or 45 degree diagonal, it's pretty
easy to do that just be checking all of the possibilities.
But what if your array is:
[[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1]]
Would you say there were 12 lines there?
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
From steve at holdenweb.com Wed Sep 7 13:02:38 2005
From: steve at holdenweb.com (Steve Holden)
Date: Wed, 07 Sep 2005 13:02:38 -0400
Subject: anaconda.real in RH7.1
In-Reply-To:
References:
Message-ID:
Allan Adler wrote:
> Allan Adler writes:
>
>
>>I'm trying to reinstall RedHat 7.1 Linux on a PC that was disabled when
>>I tried to upgrade from RH7.1 [....]
>>The file anaconda.real is invoked with the line
>>exec /usr/bin/anaconda.real -T "$@"
>>I don't know what effect the -T "$@" has.
>
>
> Tiny progress on this: in a shell script, "$@" apparently lets you refer
> to the output of a previous command. I don't know what output would be
> relevant, since the last few lines of the shell script anaconda that
> invokes anaconda.real are:
>
> cd /usr/sbin
> uncpio < sbin.cgz
> rm sbin.cgz
> cd /lib
> uncpio < libs.cgz
> rm libs.cgz
> cd /
> exec /usr/bin/anaconda.real -T "$@"
>
$@ doesn't refer to the output of a previous command. It refers to a
list of quoted arguments of the script it's a part of. It's supposed,
IIRC, to be equivalent to
exec /usr/bin/anaconda.real -T "$1" "$2" "$2" ...
as opposed to $*, which would be equivalent to
exec /usr/bin/anaconda.real -T $1 $2 $3 ...
> As for exec itself, the command line
> exec -T
> leads to a complaint that -T is an illegal option for exec, while
> python -T
> leads to a usage statement that doesn't list -T among the options for python.
> So, I still don't understand the statement that is used to call the python
> script anaconda.real.
>
What's supposed to happen is that anaconda.real is supposed to be
processed by the Python interpreter. You will probably find a "shebang"
line at the start of anaconda.real that reads something like
#!/usr/bin/python1.5.2
The -T argument is, I suspect, intended for anaconda.real - you could
check the source and verify that it looks at sys.argv.
> I also tried to execute in interactive session some of the commands in the
> file anaconda.real. E.g. the first command signal.signal(SIGINT,SIG_DFL)
>
> Python 1.5.2 (#1, Mar 3 2001, 01:35:43)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2 on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>
>>>>signal.signal(SIGINT,SIG_DFL)
>
> Traceback (innermost last):
> File "", line 1, in ?
> NameError: signal
>
>>>>import signal
>>>>signal.signal(SIGINT,SIG_DFL)
>
> Traceback (innermost last):
> File "", line 1, in ?
> NameError: SIGINT
>
>>>>import SIGINT
>
> Traceback (innermost last):
> File "", line 1, in ?
> ImportError: No module named SIGINT
>
> On the other hand, while looking at Kernighan and Pike, "The Unix programming
> environment" (1984), I fortuitously ran across a discussion of signals and
> interrupts on p.225, including the example
>
> #include
> signal(SIGINT,SIG_DFL)
>
> which restores default action for process termination. The resemblance to the
> first command in anaconda.real is so close that I think the intention in
> both must be the same. What is the right way to get python to do this?
>
SIGINT is defined in the signal module so you probably want
signal.signal(signal.SIGINT, signal.SIG_DFL)
> The file anaconda.real doesn't explicitly execute
> import signal
> but it still somehow knows what signal means (my example session above shows
> that it stops complaining about not knowing what signal means after I import
> signal). Presumably there is some way of invoking python that causes signal
> and other stuff to be imported automatically. What is it?
On that one you have me stumped. It's possible it imports some other
module that plays with the namespace in a magical way.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
From peter at engcorp.com Thu Sep 8 08:23:06 2005
From: peter at engcorp.com (Peter Hansen)
Date: Thu, 08 Sep 2005 08:23:06 -0400
Subject: Distutils question
In-Reply-To:
References:
Message-ID: <4tqdnchig9Qysb3eRVn-pw@powergate.ca>
Laszlo Zsolt Nagy wrote:
> How how can I install my .mo files from a distutil script into its
> default location?
>
> sys.prefix + os.sep + 'share' + os.sep + 'locale'
I can't answer the first question, but the latter should be written this
way instead
os.path.join(sys.prefix, 'share', 'locale')
for greater portability and maintainability.
-Peter
From lidenalex at yahoo.se Wed Sep 7 03:42:34 2005
From: lidenalex at yahoo.se (Alex)
Date: 7 Sep 2005 00:42:34 -0700
Subject: dict and __cmp__() question
Message-ID: <1126078954.485637.172070@g47g2000cwa.googlegroups.com>
Entering
>>> help(dict)
Help on class dict in module __builtin__:
class dict(object)
| dict() -> new empty dictionary.
| dict(mapping) -> new dictionary initialized from a mapping object's
| (key, value) pairs.
| dict(seq) -> new dictionary initialized as if via:
| d = {}
| for k, v in seq:
| d[k] = v
| dict(**kwargs) -> new dictionary initialized with the name=value
pairs
| in the keyword argument list. For example: dict(one=1, two=2)
|
| Methods defined here:
|
| __cmp__(...)
| x.__cmp__(y) <==> cmp(x,y)
|
| __contains__(...)
| D.__contains__(k) -> True if D has a key k, else False
snip
| update(...)
| D.update(E, **F) -> None. Update D from E and F: for k in E:
D[k] = E[k]
| (if E has keys else: for (k, v) in E: D[k] = v) then: for k in
F: D[k] = F[k]
|
| values(...)
| D.values() -> list of D's values
Now I understand methods like update(...) and values(...), for instance
>>> D={'a':1, 'b':2}
>>> D.values()
[1, 2]
>>>
But what are those with double underscore? For instance __cmp__(...)?
I tried
>>> D.cmp('a','b')
Traceback (most recent call last):
File "", line 1, in -toplevel-
D.cmp('a','b')
AttributeError: 'dict' object has no attribute 'cmp'
>>>
Alex
From iddw at hotmail.com Wed Sep 14 17:04:42 2005
From: iddw at hotmail.com (Dave Hansen)
Date: Wed, 14 Sep 2005 21:04:42 GMT
Subject: Unexpected Behavior Iterating over a Mutating Object
References: <432740ae.1301867062@news.ispnetbilling.com>
Message-ID: <432823e0.1360028812@news.ispnetbilling.com>
On Tue, 13 Sep 2005 21:28:21 GMT, iddw at hotmail.com (Dave Hansen)
wrote:
>OK, first, I don't often have the time to read this group, so
>apologies if this is a FAQ, though I couldn't find anything at
>python.org.
>
Thanks to everyone who responded. All is clear now. And I know I
need to look deeper into list comprehensions...
Regards,
-=Dave
--
Change is inevitable, progress is not.
From max at alcyone.com Tue Sep 6 06:05:16 2005
From: max at alcyone.com (Erik Max Francis)
Date: Tue, 06 Sep 2005 03:05:16 -0700
Subject: Job Offer in Paris, France : R&D Engineer (Plone)
In-Reply-To: <7x4q8y35lx.fsf@ruckus.brouhaha.com>
References:
<7xbr37u8ut.fsf@ruckus.brouhaha.com>
<7xpsrn3100.fsf@ruckus.brouhaha.com>
<7x4q8y35lx.fsf@ruckus.brouhaha.com>
Message-ID:
Paul Rubin wrote:
> If you still think this, I'd be interested in chatting a little
> further. Does the email address in the pdf go to you? If not, should
> I write you directly? Can I call on the phone (you can leave me a
> number at http://paulrubin.com)? Thanks.
Do you even realize you're having this conversation over the Python
mailing list/newsgroup, rather than by private email?
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Defeat is a school in which truth always grows strong.
-- Henry Ward Beecher
From markus_REMOVEwankusALL_CAPS at hotmail.com Fri Sep 30 08:53:00 2005
From: markus_REMOVEwankusALL_CAPS at hotmail.com (Markus Wankus)
Date: Fri, 30 Sep 2005 08:53:00 -0400
Subject: Zope3 Examples?
In-Reply-To:
References:
Message-ID:
Jean-Fran?ois Doyon wrote:
> Markus,
>
> Zope 3 is mature as a framework, but does not provide much "out of the
> box". It's a basis upon which to build applications like Plone ... If
> you are looking for something that provides Plone-like features on top
> of Zope 3, it doesn't exist (yet).
>
> Personally, I'm waiting for this: http://www.z3lab.org/
> But it'll be a while yet!
>
Yes - I was watching the screencasts (well, animations) on this and it
looks incredible! I can't wait to play with something like this.
> Zope 3 is brilliant, but complex, and quite the departure from Zope 2,
> so it'll take a while for the take up to occur.
>
> What might work better for you is to use Zope 2 + the CMF, without
> Plone. Plone can be fairly heavy and rigid, the CMF alone might give
> you the tools you need. I use Zope 2 with success and good performance
> on a hig traffic website, I wouldn't discount it just because of your
> first impression ... There are many tweaks available that will
> considerably improve performance for production systems.
>
> Cheers,
> J.F.
>
Thanks for the reply - maybe I'll give it another shot. I'm currently
demoing Snakelets. Quite a turn in the opposite direction, but small
and super-easy to get going with. I think once this project gets a few
good webapps under its belt (and maybe I can contribute there!) this
could be a nice solution for many people. At least a good starting
point for someone like me who knows a good deal about Python and nothing
about web frameworks.
Markus.
From steven.bethard at gmail.com Sun Sep 4 15:08:36 2005
From: steven.bethard at gmail.com (Steven Bethard)
Date: Sun, 04 Sep 2005 13:08:36 -0600
Subject: regular expression unicode character class trouble
In-Reply-To: <3o0n4bF3hmbaU1@uni-berlin.de>
References: <3o0n4bF3hmbaU1@uni-berlin.de>
Message-ID:
Diez B. Roggisch wrote:
> Hi,
>
> I need in a unicode-environment the character-class
>
> set("\w") - set("[0-9]")
>
> or aplha w/o num. Any ideas how to create that?
I'd use something like r"[^_\d\W]", that is, all things that are neither
underscores, digits or non-alphas. In action:
py> re.findall(r'[^_\d\W]+', '42badger100x__xxA1BC')
['badger', 'x', 'xxA', 'BC']
HTH,
STeVe
From eurleif at ecritters.biz Tue Sep 27 19:34:27 2005
From: eurleif at ecritters.biz (Leif K-Brooks)
Date: Tue, 27 Sep 2005 23:34:27 GMT
Subject: __call__ in module?
In-Reply-To: <1127855953.687066.235740@g43g2000cwa.googlegroups.com>
References: <1127855953.687066.235740@g43g2000cwa.googlegroups.com>
Message-ID: <7Gk_e.28$PA1.5188@monger.newsread.com>
ncf wrote:
> I have a feeling that this is highly unlikely, but does anyone in here
> know if it's possible to directly call a module, or will I have to wrap
> it up in a class?
You could use trickery with sys.modules to automatically wrap it in a class:
import sys
from types import ModuleType
class CallableModule(ModuleType):
def __call__(self):
print "You called me!"
mod = FooModule(__name__, __doc__)
mod.__dict__.update(globals())
sys.modules[__name__] = mod
From mensanator at aol.com Wed Sep 21 16:17:08 2005
From: mensanator at aol.com (mensanator at aol.com)
Date: 21 Sep 2005 13:17:08 -0700
Subject: unusual exponential formatting puzzle
In-Reply-To: <1127333251.055532.278540@g49g2000cwa.googlegroups.com>
References:
<1127333251.055532.278540@g49g2000cwa.googlegroups.com>
Message-ID: <1127333828.538525.235630@o13g2000cwo.googlegroups.com>
mensanator at aol.com wrote:
> Neal Becker wrote:
> > Like a puzzle? I need to interface python output to some strange old
> > program. It wants to see numbers formatted as:
> >
> > e.g.: 0.23456789E01
> >
> > That is, the leading digit is always 0, instead of the first significant
> > digit. It is fixed width. I can almost get it with '% 16.9E', but not
> > quite.
> >
> > My solution is to print to a string with the '% 16.9E' format, then parse it
> > with re to pick off the pieces and fix it up. Pretty ugly. Any better
> > ideas?
>
> If you have gmpy available...
>
> >>> import gmpy
>
> ...and your floats are mpf's...
>
> >>> s = gmpy.pi(64)
> >>> s
> mpf('3.14159265358979323846e0',64)
>
> ...you can use the fdigits function
>
> >>> t = gmpy.fdigits(s,10,8,0,0,2)
>
> ...to create a seperate digit string and exponent...
>
> >>> print t
> ('31415927', 1, 64)
>
> ...which can then be printed in the desired format.
>
> >>> print "0.%sE%02d" % (t[0],t[1])
> 0.31415927E01
Unless your numbers are negative.
>>> print "0.%sE%02d" % (t[0],t[1])
0.-31415927E03
Drat. Needs work.
And does the format permit large negative exponents (2 digits + sign)?
>>> print "0.%sE%02d" % (t[0],t[1])
0.31415927E-13
From trentm at ActiveState.com Thu Sep 29 22:05:55 2005
From: trentm at ActiveState.com (Trent Mick)
Date: Thu, 29 Sep 2005 19:05:55 -0700
Subject: RELEASED Python 2.4.2 (final)
In-Reply-To:
References:
Message-ID: <20050930020555.GA7371@ActiveState.com>
[Bugs wrote]
> I downloaded the 2.4.2 Windows Binary Installer from python.org but when
> I try to run python.exe I get the following in the console:
> --------------------
> ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on
> Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>>
> --------------------
> It says ActivePython 2.4.1 but I downloaded the 2.4.2 binary installer
> from python.org and the python.exe executable I'm running is timestamped
> 9/28/2005 12:41PM... Any ideas what I'm doing wrong?
It is possible that the python.org installer didn't overwrite the
"python24.dll" in the system directory (C:\WINDOWS\system32). Try doing
this:
- manually delete C:\WINDOWS\system32\python24.dll
- run the "repair" functionality of the python.org installer (you can
either do this from "Start | Settings | Control Panel | Add/Remove
Programs" or by just running the .msi file again
Then try running python again.
Trent
--
Trent Mick
TrentM at ActiveState.com
From donald.welch at hp.com Fri Sep 9 12:23:22 2005
From: donald.welch at hp.com (djw)
Date: Fri, 09 Sep 2005 09:23:22 -0700
Subject: Why do Pythoneers reinvent the wheel?
In-Reply-To:
References: <1126193090.613127.4480@z14g2000cwz.googlegroups.com>
Message-ID: <4321b75f$1@usenet01.boi.hp.com>
Stefano Masini wrote:
> I don't know what's the ultimate problem, but I think there are 3 main reasons:
> 1) poor communication inside the community (mhm... arguable)
> 2) lack of a rich standard library (I heard this more than once)
> 3) python is such an easy language that the "I'll do it myself" evil
> side lying hidden inside each one of us comes up a little too often,
> and prevents from spending more time on research of what's available.
>
I think, for me, this most important reason is that the stdlib version
of a module doesn't always completely fill the requirements of the
project being worked on. That's certainly why I wrote my own, much
simpler, logging module. In this case, its obvious that the original
author of the stdlib logging module had different ideas about how
straightforward and simple a logging module should be. To me, this just
demonstrates how difficult it is to write good library code - it has to
try and be everything to everybody without becoming overly general,
abstract, or bloated.
-Don
From g.horvath at gmx.at Thu Sep 29 02:15:11 2005
From: g.horvath at gmx.at (Gregor Horvath)
Date: Thu, 29 Sep 2005 08:15:11 +0200
Subject: Will python never intend to support private, protected and public?
In-Reply-To: <7xd5mstqab.fsf@ruckus.brouhaha.com>
References: <311b5ce105092800102da32267@mail.gmail.com>
<7xbr2dxqqq.fsf@ruckus.brouhaha.com>
<7xk6h0zxnm.fsf@ruckus.brouhaha.com>
<7x64skzvas.fsf@ruckus.brouhaha.com>
<7xd5mstqab.fsf@ruckus.brouhaha.com>
Message-ID:
Paul Rubin schrieb:
>
> Huh? If my car has a "feature" that lets someone blow it to
> smithereens from hundreds of miles away without even intending to,
> that's somehow an advantage?
I would not accept a car that does constraint my driving directions. I
want to drive for myself, because its fun.
>
> No problem, but any decision like that should be expressed in
> "writing", by re-declaring the variable so it's no longer private.
Remember, its Python not Java.
Tastes are different and so are programming languages, but please do not
make Python to a Java Clone.
I love python because of its simplicity, freedom, power and because its
fun to program.
One reason is that it does not restrict the programer to tight und has
genuine simple solutions, like the one with "private" instance variables.
--
Greg
From steve at holdenweb.com Sat Sep 3 02:09:35 2005
From: steve at holdenweb.com (Steve Holden)
Date: Sat, 03 Sep 2005 01:09:35 -0500
Subject: urllib.urlopen doesn't work
In-Reply-To: <004701c5b00b$06db4790$ce0221d5@familygroup>
References: <004701c5b00b$06db4790$ce0221d5@familygroup>
Message-ID:
Josef Cihal wrote:
> Hallo,
>
> i need a help with module URLLIB.
>
> I am trying to open url via:
> - urllib.urlopen
> ('http://brokerjet.ecetra.com/at/markets/stocks/indices.phtml?notation=92866')
>
>
> Problem is, that I am always redirecting to
> - LOGIN page (www.brokerjet.at ),
> and cannot get my page with "news", which I want to download.
>
> Can it be, that I forgot to pass all (hidden too) parameters to form by
> submit?
>
> Is it possible to get (ask) for all existing valid parameters, which I
> need to pass to form
> for getting requested page?
> Is action submit correct in my case?
>
>
> Thank you very much for all your help or ideas
>
I suspect that the problem is you are attempting to access a web
application in which every page checks for a valid login and, if this
isn't present, redirects you to the login page.
You might try a URL for the form
http://username:password at server/path/resource
as this is the easiest way to achieve basic authentication. Otherwise
there are other ways, which you can get back to us about.
Also you might try just starting a new browser session an entering the
URL that gave you problems in your code. If the browser displays the
page correctly then *either* it has cookies set that you aren't setting
when you call urllib.urlopen() *or* I'm wrong. :-)
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
From billiejoex at fastwebnet.it Sat Sep 10 13:06:52 2005
From: billiejoex at fastwebnet.it (billiejoex)
Date: Sat, 10 Sep 2005 19:06:52 +0200
Subject: execute commands and return output
References:
Message-ID:
Thanks for suggestions.
I'll try one of these solutions soon.
From lycka at carmen.se Fri Sep 16 06:06:17 2005
From: lycka at carmen.se (Magnus Lycka)
Date: Fri, 16 Sep 2005 12:06:17 +0200
Subject: MySQLdb UPDATE does nothing
In-Reply-To:
References: <4329633F.7060609@jmsd.co.uk>
Message-ID:
Steve Horsley wrote:
> Or, as I found out yesterday, cursor.execute('commit') afterwards.
The correct way to do it is to close the cursor object, and
then do "db.commit()". Don't rely on a cursor object to work
across transaction boundries!
See e.g. www.thinkware.se/epc2004db/epc04_mly_db.pdf and
http://www.thinkware.se/epc2004db/dbapitest.py
From tzot at sil-tec.gr Fri Sep 30 03:51:59 2005
From: tzot at sil-tec.gr (Christos Georgiou)
Date: Fri, 30 Sep 2005 10:51:59 +0300
Subject: 1 Million users.. I can't Scale!!
References: <1127924360.190081.155420@g14g2000cwa.googlegroups.com> <17210.62571.387969.713030@montanaro.dyndns.org> <433B0B38.7040406@bellsouth.net>
Message-ID:
On Wed, 28 Sep 2005 21:58:15 -0400, rumours say that Jeff Schwab
might have written:
>For many (most?) applications in need of
>serious scalability, multi-processor servers are preferable. IBM has
>eServers available with up to 64 processors each, and Sun sells E25Ks
>with 72 processors apiece.
SGI offers modular single-image Itanium2 servers of up to 512 CPU at the
moment:
http://www.sgi.com/products/servers/altix/configs.html
And NASA have clustered 20 of these machines to create a 10240 CPU
cluster...
>I like to work on those sorts of machine
>when possible. Of course, they're not right for every application,
>especially since they're so expensive.
And expensive they are :)
--
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
From abo at google.com Tue Sep 27 13:57:59 2005
From: abo at google.com (ABO)
Date: 27 Sep 2005 10:57:59 -0700
Subject: Self reordering list in Python
References:
<200509161058.48155.hancock@anansispaceworks.com>
<1127810493.378770.282050@z14g2000cwz.googlegroups.com>
Message-ID: <1127843879.245154.22300@g44g2000cwa.googlegroups.com>
Actually, after posting this I did some more work on the PQueue modules
I had, implementing both bisect and heapq versions. It turns out the
bisect version is heaps faster if you ever delete or re-set values in
the queue.
The problem is heapq is O(N) for finding a particular entry in the
Queue, and any time you change or remove something from it you need to
heapify it again, which is also O(N).
Andew Snare has a C PQueue extension module that is heaps faster from
all angles. It uses a fibonacci heap and gets O(lg N) deletes and
re-sets. I think it does this by using the dict to speed finding
entries it in the heap, and uses some properties of the heap to "assign
lower" efficiently.
The queue used in the lrucache will also suffer from the O(N) problem
when deleting or reseting values in the cache.
From fredrik at pythonware.com Wed Sep 14 12:57:23 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Wed, 14 Sep 2005 18:57:23 +0200
Subject: Python Search Engine app
References: <1126708775.608076.106850@g43g2000cwa.googlegroups.com>
Message-ID:
Harlin Seritt wrote:
> Is anyone aware of an available open-source/free search engine app
> (something similar to HTDig) written in Python that is out there?
> Googling has turned up nothing. Thought maybe I'd mine some of you
> guys' minds on this.
http://divmod.org/ has a couple of alternatives:
http://divmod.org/projects/lupy
http://divmod.org/projects/pyndex
http://divmod.org/projects/xapwrap
From gnb at itga.com.au Wed Sep 7 02:06:27 2005
From: gnb at itga.com.au (Gregory Bond)
Date: Wed, 07 Sep 2005 16:06:27 +1000
Subject: Ode to python
In-Reply-To: <1126062515.460542.95260@f14g2000cwb.googlegroups.com>
References: <1126062515.460542.95260@f14g2000cwb.googlegroups.com>
Message-ID: <510mfd.n08.ln@lightning.itga.com.au>
Hmmm... OK... you forced me into it.
Python uses whitespace
Where C++ uses a brace
New users fret,
But old pros forget -
it quickly all falls into place.
I could go on......
From theller at python.net Tue Sep 13 04:13:12 2005
From: theller at python.net (Thomas Heller)
Date: Tue, 13 Sep 2005 10:13:12 +0200
Subject: Using Python with COM to communicate with proprietary Windows
software
References:
<5bMhQyygYQbAxWGqorX8DcbkrRte@4ax.com>
Message-ID:
Andrew MacIntyre writes:
> On Fri, 09 Sep 2005 08:36:00 +0200, Thomas Heller
> wrote:
>
> {...}
>
>>(I have released and announced this 3 weeks ago, but haven't got a
>>single feedback. So it seems the need to access custom interfaces is
>>very low.)
>
> I have downloaded it and am trying to find the time to play with it
> (unsuccessfully so far).
>
> As someone working with a large, complex, COM library with minimal
> IDispatch support, I'm really looking forward to this.
>
> However, at the moment I'm limited to Python 2.2 and ctypes 0.6.3
> (which is allowing me to get the job done!!).
>
> Regardless, I thank you for what you have released!
I knew there are fans out there ;-)
Thomas
From fredrik at pythonware.com Thu Sep 15 03:49:47 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 15 Sep 2005 09:49:47 +0200
Subject: new in python
References:
Message-ID:
"blackfox505" wrote:
> I'm new in python and I would like to know what is the capabilleties
> of this language.Please let me know and how I can make a program in
> python exe
if you want to know how to make programs in python, start here:
http://wiki.python.org/moin/BeginnersGuide
if you want to know how to turn python program into exe files, this
page might help:
http://effbot.org/zone/python-compile.htm
From deets at nospam.web.de Mon Sep 26 08:45:09 2005
From: deets at nospam.web.de (Diez B. Roggisch)
Date: Mon, 26 Sep 2005 14:45:09 +0200
Subject: What is "self"?
In-Reply-To:
References: <43335c5f$1_4@alt.athenanews.com>
Message-ID: <3pq8qlFbncaaU1@uni-berlin.de>
> This still seems not quite right to me... Or more likely seems to be
> missing something still.
>
> (But it could be this migraine I've had the last couple of days
> preventing me from being able to concentrate on things with more than a
> few levels of complexity.)
>
> Playing around with the shell a bit gives the impression that calling a
> method in a instance gives the following (approximate) result...
>
> try:
> leader.__dict__["set_name"]("John")
> except:
> type(leader).__dict__["set_name"].__get__(leader, "John")
> # which results in...
> # Person.set_name(leader, "John")
> except:
> raise( AttributeError,
> "%s object has no attribute %s" \
> % (leader, "set_name") )
>
>
> Of course this wouldn't use the object names directly... I guess I'll
> need to look in the C object code to see exactly how it works. But the
> links you gave help.
I guess you mean to indent the whole part after the first except and put
a try beforehand?
Apart from that you seem to be right - there can very well be values in
the class dict that don't follow the descriptor-protocol. However my
playing around with this stuff indicates that the creation of bound
methods relies on the method being wrapped in a descriptor - otherwise,
you get the notorious TypeError
set_name() takes exactly 1 argument (0 given)
as the binding doesn't occur.
Regards,
Diez
From ptmcg at austin.rr._bogus_.com Thu Sep 22 16:20:01 2005
From: ptmcg at austin.rr._bogus_.com (Paul McGuire)
Date: Thu, 22 Sep 2005 20:20:01 GMT
Subject: Newbie regular expression and whitespace question
References: <1127419129.027712.252910@g47g2000cwa.googlegroups.com>
Message-ID:
"googleboy" wrote in message
news:1127419129.027712.252910 at g47g2000cwa.googlegroups.com...
> Hi.
>
> I am trying to collapse an html table into a single line. Basically,
> anytime I see ">" & "<" with nothing but whitespace between them, I'd
> like to remove all the whitespace, including newlines. I've read the
> how-to and I have tried a bunch of things, but nothing seems to work
> for me:
>
> --
>
> table = open(r'D:\path\to\tabletest.txt', 'rb')
> strTable = table.read()
>
> #Below find the different sort of things I have tried, one at a time:
>
> strTable = strTable.replace(">\s<", "><") #I got this from the module
> docs
>
> strTable = strTable.replace(">.<", "><")
>
> strTable = ">\s+<".join(strTable)
>
> strTable = ">\s<".join(strTable)
>
> print strTable
>
> --
>
> The table in question looks like this:
>
>
>
> |
> Introduction |
> 3 |
>
>
> |
>
>
> ONE |
> Childraising for Parrots |
> 11 |
>
>
>
>
>
> For extra kudos (and I confess I have been so stuck on the above
> problem I haven't put much thought into how to do this one) I'd like to
> be able to measure the number of characters between the &
> tags, and then insert a newline character at the end of the next word
> after an arbitrary number of characters..... I am reading in to a
> script a bunch of paragraphs formatted for a webpage, but they're all
> on one big long line and I would like to split them for readability.
>
> TIA
>
> Googleboy
>
If you're absolutely stuck on using RE's, then others will have to step
forward. Meanwhile, here's a pyparsing solution (get pyparsing at
http://pyparsing.sourceforge.net):
---------------
from pyparsing import *
LT = Literal("<")
GT = Literal(">")
collapsableSpace = GT + LT # matches with or without intervening
whitespace
collapsableSpace.setParseAction( replaceWith("><") )
print collapsableSpace.transformString(data)
---------------
The reason this works is that pyparsing implicitly skips over whitespace
while looking for matches of collapsable space (a '>' followed by a '<').
When found, the parse action is triggered, which in this case, replaces
whatever was matched with the string "><". Finally, the input data (in this
case your HTML table, stored in the string variable, data) is passed to
transformString, which scans for matches of the collapsableSpace expression,
runs the parse action when they are found, and returns the final transformed
string.
As for word wrapping within ...
tags, there are at least two recipes
in the Python Cookbook for word wrapping. Be careful, though, as many HTML
pages are very bad about omitting the trailing
tags.
-- Paul
From iddw at hotmail.com Fri Sep 30 18:04:29 2005
From: iddw at hotmail.com (Dave Hansen)
Date: Fri, 30 Sep 2005 22:04:29 GMT
Subject: New Python chess module
References: <433c066c$0$21931$db0fefd9@news.zen.co.uk>
<433d7fa0$0$4177$da0feed9@news.zen.co.uk>
Message-ID: <1128117924.237ac3772a24648083f429d57da23b12@teranews>
On Sat, 01 Oct 2005 06:27:01 +1000, Tim Churches
wrote:
>Will McGugan wrote:
>> There is a new version if anyone is interested...
>>
>> http://www.willmcgugan.com/chess.py
>>
>> It contains optimizations and bugfixes.
>>
>> Can anyone suggest a name for this module? pyChess is already taken...
>
>Pyawn???
As a play on "pawn?" that wasn't the way I first took it (ho-hum...)
How about pyTurk, after the first chess automaton? It seems to be
available.
Regards,
-=Dave
--
Change is inevitable, progress is not.
From salvatore.didio at wanadoo.fr Wed Sep 28 16:55:55 2005
From: salvatore.didio at wanadoo.fr (salvatore.didio at wanadoo.fr)
Date: 28 Sep 2005 13:55:55 -0700
Subject: Nufox : Simple Tree
Message-ID: <1127940955.116568.285180@g49g2000cwa.googlegroups.com>
Nufox allow XUL developement like you could do with any other GUI
library
If you want to see an example :
http://www.google.com/url?sa=D&q=http://www.freezope.org/Members/artyprog/programmation/lienspython/nufox/examples/sortedcolumns
Regards
Salvatore
From nil at dev.nul Wed Sep 14 10:10:57 2005
From: nil at dev.nul (Christian Stapfer)
Date: Wed, 14 Sep 2005 16:10:57 +0200
Subject: Removing duplicates from a list
References: <1126697915.879705.300450@g44g2000cwa.googlegroups.com>
<1126706415.609072.92570@o13g2000cwo.googlegroups.com>
Message-ID:
wrote in message
news:1126706415.609072.92570 at o13g2000cwo.googlegroups.com...
>I do this:
>
> def unique(keys):
> unique = []
> for i in keys:
> if i not in unique:unique.append(i)
> return unique
>
> I don't know what is faster at the moment.
This is quadratic, O(n^2), in the length n of the list
if all keys are unique.
Conversion to a set just might use a better sorting
algorithm than this (i.e. n*log(n)) and throwing out
duplicates (which, after sorting, are positioned
next to each other) is O(n). If conversion
to a set should turn out to be slower than O(n*log(n))
[depending on the implementation], then you are well
advised to sort the list first (n*log(n)) and then
throw out the duplicate keys with a single walk over
the list. In this case you know at least what to
expect for large n...
Regards,
Christian
From fredrik at pythonware.com Thu Sep 29 01:11:10 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 29 Sep 2005 07:11:10 +0200
Subject: Will python never intend to support private, protected and public?
References: <311b5ce105092800102da32267@mail.gmail.com><8c7f10c605092804053a6eadf4@mail.gmail.com><813D949A-554B-4801-BE07-13F652A218AD@ihug.co.nz><8c7f10c605092804552f1dac9@mail.gmail.com><00C39639-DDD6-41A7-BEA9-F78EFA3288A5@ihug.co.nz>
<0669A0A3-A514-4A58-A8C0-80594B56399E@ihug.co.nz>
Message-ID:
Tony Meyer wrote:
> That elaborates on the intent, it doesn't change it. The sentence
> clearly says that the intent is to easily define private variables,
> whereas Simon said that it the intent was not to provide a mechanism
> for making variables private.
Are you aware of the fact that computer terms might have slightly different
meanings in different languages, due to differences in language details and
semantics? Of course they're "private variables", but they're "private" in the
Python sense, and they were added to Python to solve problems that were
observed in Python, not because someone thought it was important to cater
to confused C++ or Java programmers.
And as Simon said, and the original thread showed, the problem they were
(and are) intended to address is accidental namespace collisions when sub-
classing.
If we'd really needed "true" private variables, don't you think we would have
been able to come up with a design that provided that? It just wasn't important,
because Python is Python.
From lasse at vkarlsen.no Tue Sep 27 14:07:58 2005
From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=)
Date: Tue, 27 Sep 2005 20:07:58 +0200
Subject: Documenting properties
Message-ID:
I notice that if I use this syntax:
def classname:
...
##
# closes the database connection and releases the resources.
def close(self):
....
##
# Returns a list of fields
fields = property(....)
then doing:
help (classname)
then the text is listed for the property and the method, whereas if I do
this:
classname.close.__doc__
then nothing is listed, and to get that I have to use the """.."""
syntax to document:
def close(self):
"""closes the datab..."""
....
then classname.close.__doc__ shows the text.
So, my question is, is there a way to get __doc__ support for
properties, in effect, use the """xxx""" syntax for documenting properties.
Is the preferred way to use """xxx""" or # to document ?
Whatever is preferred, what's the upside/downsides of the two beyond
what I just explained?
--
Lasse V?gs?ther Karlsen
http://usinglvkblog.blogspot.com/
mailto:lasse at vkarlsen.no
PGP KeyID: 0x2A42A1C2
From llothar at web.de Fri Sep 23 15:28:31 2005
From: llothar at web.de (llothar)
Date: 23 Sep 2005 12:28:31 -0700
Subject: Python Source Code for a HTTP Proxy
Message-ID: <1127503711.400381.259530@z14g2000cwz.googlegroups.com>
Hello,
i'm looking for a simple http proxy in python.
Does anybody know about something like this ?
From andreas.zwinkau at googlemail.com Wed Sep 21 07:04:21 2005
From: andreas.zwinkau at googlemail.com (beza1e1)
Date: 21 Sep 2005 04:04:21 -0700
Subject: Writing a parser the right way?
Message-ID: <1127300661.440587.287950@g47g2000cwa.googlegroups.com>
I'm writing a parser for english language. This is a simple function to
identify, what kind of sentence we have. Do you think, this class
wrapping is right to represent the result of the function? Further
parsing then checks isinstance(text, Declarative).
-------------------
class Sentence(str): pass
class Declarative(Sentence): pass
class Question(Sentence): pass
class Command(Sentence): pass
def identify_sentence(text):
text = text.strip()
if text[-1] == '.':
return Declarative(text)
elif text[-1] == '!':
return Command(text)
elif text[-1] == '?':
return Question(text)
return text
-------------------
At first i just returned the class, then i decided to derive Sentence
from str, so i can insert the text as well.
From this.address.is.fake at realh.co.uk Thu Sep 22 19:50:42 2005
From: this.address.is.fake at realh.co.uk (Tony Houghton)
Date: 22 Sep 2005 23:50:42 GMT
Subject: Finding where to store application data portably
References: <4330872a$0$1304$ed2619ec@ptn-nntp-reader02.plus.net>
<4332985d$0$15046$ed2619ec@ptn-nntp-reader02.plus.net>
Message-ID:
In ,
Ron Adam wrote:
> Tony Houghton wrote:
>
>> > This works on Win XP. Not sure if it will work on Linux.
>> >
>> > import os
>> >
>> > parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0]
>> > file = parent + os.sep + '.bombz'
>>
>> Ooh, no, I don't want saved data to go in the installation directory. In
>> general that practice encourages people to run with Admin access, and
>> it's about time Windows users were discouraged from that.
>
> Yes, it occurred to me you didn't want to do that after I posted.
>
> Looks like maybe the correct place would be as you suggested, but maybe
> doing it this way would be better.
>
> import os
> user = os.path.join( os.environ["USERPROFILE"],
> 'Application Data',
> 'Bombz' )
I like that, it's nice and simple. It doesn't look like it's supported
on Win 9x though, but on 9x using the installation directory would be
acceptable.
--
The address in the Reply-To is genuine and should not be edited.
See for more reliable contact addresses.
From fredrik at pythonware.com Fri Sep 9 12:13:06 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 9 Sep 2005 18:13:06 +0200
Subject: Where do .pyc files come from?
References: <1126279989.004437.270950@g49g2000cwa.googlegroups.com>
Message-ID:
Ernesto wrote:
>I noticed in a python distribution there were 5 python files (.py) and
> 5 other files with the same name, but with the extension .pyc . Is
> this some kind of compiled version of the .py files. Thanks,
http://www.python.org/doc/2.4.1/tut/node8.html#SECTION008120000000000000000
From python at rcn.com Tue Sep 13 19:42:39 2005
From: python at rcn.com (Raymond Hettinger)
Date: 13 Sep 2005 16:42:39 -0700
Subject: Unexpected Behavior Iterating over a Mutating Object
References: <432740ae.1301867062@news.ispnetbilling.com>
Message-ID: <1126654959.843540.165630@g47g2000cwa.googlegroups.com>
[Dave Hansen]
> It seems when an item is 'remove'd from data, the rest of the list
> 'shifts' over one, so what was 'next' now occupies the slot of the
> 'remove'd item. When the next 'item' is selected from 'data', the
> _desired_ 'next' item is skipped. So when 'data' has several
> consecutive items to be deleted, only every other one is 'remove'd.
Your analysis is dead-on. Instead of being the "desired" item, the
iterator fetches a[0], a[1], a[2], ... as determined by the state of
the list when the index is retrieved.
> Again, iterating over an item that is mutating seems like a Bad
> Idea(tm) to me.
Right.
> But I was curious: is this the intended behavior, or
> does this fall under what C programmers would call 'undefined
> behavior.'
It is intended. The behavior is defined as above (a series of indexed
lookups).
BTW, the usual ways to deal with this are to:
1. iterating from the right using: for item in reversed(data)
2. making a copy of the original list before iterating
3. creating a new result list: data = [x for x in data if 'DEL' not in
x]
Raymond
From fredrik at pythonware.com Thu Sep 8 14:39:01 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 8 Sep 2005 20:39:01 +0200
Subject: Help! Python either hangs or core dumps when calling C malloc
References: <1126198290.288644.247510@o13g2000cwo.googlegroups.com><1126199525.752904.254930@z14g2000cwz.googlegroups.com>
<1126203439.152057.78210@o13g2000cwo.googlegroups.com>
Message-ID:
Lil wrote:'
>I already double checked my C code. It runs perfectly fine in C without
> any errors. So in my python program, I added a pdb.set_trace()
> and step through the program and it did not dump. But when i took out
> the tracing, the core dump came back. "sigh"
so triple-check it.
if your code overwrites the malloc buffer, it's perfectly possible
that it appears to run fine when you run it standalone or under the
debugger, but that doesn't mean that your code is fine.
From jpopl at interia.pl Thu Sep 8 10:50:32 2005
From: jpopl at interia.pl (=?UTF-8?B?SmFjZWsgUG9wxYJhd3NraQ==?=)
Date: Thu, 08 Sep 2005 16:50:32 +0200
Subject: popen in thread on QNX
In-Reply-To:
References:
Message-ID:
Laszlo Zsolt Nagy wrote:
> - one of your worker threads wants to run a command
> - it creates the argument list and puts it into a message queue
> - woker thread starts to sleep
> - main thread processes the message queue -> it will run popen, put back
> the file descriptors into the message and wake up the worker thread
> - the worker thread starts to work with the files
Just like I wrote in previous thread ("killing thread after timeout") -
I am writting application which read command from socket and run it. I
need to be sure, that this command will not take too much time, so I
need some kind of timeout, and I need to see its stdout and stderr.
So I run command on separate thread, this thread calls
os.system(command), main thread takes care about timeout.
popen or fork/execve would be much better than os.system, but they both
fail on QNX, because os.fork() is not implemented in thread
From tismer at stackless.com Wed Sep 28 21:12:33 2005
From: tismer at stackless.com (Christian Tismer)
Date: Thu, 29 Sep 2005 03:12:33 +0200
Subject: Alternatives to Stackless Python?
In-Reply-To: <4333c642$0$25699$626a14ce@news.free.fr>
References: <1127231444.643628.197920@g49g2000cwa.googlegroups.com> <1127438841.532386.73410@g44g2000cwa.googlegroups.com>
<4333c642$0$25699$626a14ce@news.free.fr>
Message-ID: <433B3F81.2080706@stackless.com>
Christophe wrote:
...
> Not sure if greenlets support pickling yet. There are no info on that
> point and my tests weren't succesful.
Greenlets refine a concept of Stackless 2.0 which was orthogonal
to the Python implementation in a sense that they did not
conflict at all. This is less efficient than collaborative
task switching, but allows greenlets to exist without any
maintenance.
A Stackless subset based upon Greenlets is in discussion.
Platform independent Pickling support of running tasklets is
almost impossible without support from the Python implementation.
I see this as an entry point for people to try these ideas.
The switching speed is several times slower by principle.
ciao - chris
--
Christian Tismer :^)
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
From russandheather at gmail.com Tue Sep 27 18:40:22 2005
From: russandheather at gmail.com (Qopit)
Date: 27 Sep 2005 15:40:22 -0700
Subject: __call__ in module?
In-Reply-To: <1127855953.687066.235740@g43g2000cwa.googlegroups.com>
References: <1127855953.687066.235740@g43g2000cwa.googlegroups.com>
Message-ID: <1127860822.419544.248190@g44g2000cwa.googlegroups.com>
Nope - you can't even force it by binding a __call__ method to the
module.
For future reference, you can check to see what things *are* callable
with the built-in function 'callable'.
eg (with sys instead of MyApp):
>>> import sys
>>> callable(sys)
False
Also - a thing you can do to sort of do what you want (?) is wrap the
code to be executed by the module in a main() function. eg:
#-- Start of MyApp.py --
def main(foo):
print "My cat loves", foo
if __name__ == "__main__":
import sys
main(" ".join(sys.argv[1:]))
#-- EOF --
The main function then lets you either run your module from the command
line (MyApp.py Meow Mix) or have another module use it with:
import MyApp
MyApp.main("Meow Mix")
From apardon at forel.vub.ac.be Mon Sep 19 03:12:54 2005
From: apardon at forel.vub.ac.be (Antoon Pardon)
Date: 19 Sep 2005 07:12:54 GMT
Subject: Brute force sudoku cracker
References: <1126903524.482259.235970@g14g2000cwa.googlegroups.com>
<1126909078.589245.253390@g47g2000cwa.googlegroups.com>
Message-ID:
Op 2005-09-16, my.correo.basura at gmail.com schreef :
>
> Bas ha escrito:
>
>> Hi group,
>>
>> I came across some of these online sudoku games and thought after
>> playing a game or two that I'd better waste my time writing a solver
>> than play the game itself any longer. I managed to write a pretty dumb
>> brute force solver that can at least solve the easy cases pretty fast.
>>
>> It basically works by listing all 9 possible numbers for all 81 fields
>> and keeps on striking out possibilities until it is done.
>> [snip]
>
> This problem is desperately begging for backtracking.
I don't think so. I regularly solve one and I never needed
to try something out, to see if it worked or not except
when there were muliple solutions.
I think it is a beautifull problem, to make people think of
how they could code some of their thought processes, which
would be a more fruitfull experience as programming this
with backtracking.
--
Antoon Pardon
From simoninusa2001 at yahoo.co.uk Tue Sep 20 16:25:47 2005
From: simoninusa2001 at yahoo.co.uk (Simon John)
Date: 20 Sep 2005 13:25:47 -0700
Subject: Getting tired with py2exe
In-Reply-To:
References:
<1127241797.610338.201800@z14g2000cwz.googlegroups.com>
Message-ID: <1127247947.066480.219710@f14g2000cwb.googlegroups.com>
James Stroud wrote:
[snip]
> > http://pyinstaller.hpcf.upr.edu/pyinstaller
> That's one short "indefinitely":
>
> Not Found
> The requested URL /pyinstaller was not found on this server.
> Apache/2.0.53 (Fedora) Server at pyinstaller.hpcf.upr.edu Port 80
It seems that the URL is http://pyinstaller.hpcf.upr.edu
>From the website it seems this is a continuation of McMillan Installer,
which they claim is "far superior" to py2exe! Personally I gave up on
MMI, prefering py2exe on Windows and cx_Freeze on UNIX.
And if they want to use UPX, well that's up to them, but I've had some
problems with it and don't particularly like the thought of runtime
decompression and the two process thing. And when you can compress the
distributable using 7zip or whatever, why bother keeping it compressed
once downloaded?
Ah well, I wish you, whoever takes over py2exe and the PyInstaller guys
the best of luck!
From mtebeka at qualcomm.com Wed Sep 28 08:22:01 2005
From: mtebeka at qualcomm.com (Miki Tebeka)
Date: Wed, 28 Sep 2005 15:22:01 +0300
Subject: Telephony project
In-Reply-To: <1127758835.527555.217870@g47g2000cwa.googlegroups.com>
References: <1127758835.527555.217870@g47g2000cwa.googlegroups.com>
Message-ID: <20050928122201.GD2056@qualcomm.com>
Hello Roger,
> 1. Fetch phone number from my ASCII data.
Trivial in Python.
> 2. Dial (always a local number) phone (through USRobotics 56K? ).
Can't recall that.
> 3. Ask @3 questions to called phone number. Y/N Y/N Y/N
You can use flite (http://www.speech.cs.cmu.edu/flite/) for Text-To-Speech.
(e.g. system("flite -t 'how are you?'"))
> 4. Save answers to ASCII file.
You need to get the audio, maybe you can use portaudio
(http://www.portaudio.com/)
> 5. Say 'Thanks', hang up.
flit again.
> Repeat till eof()
Trivial.
HTH.
--
------------------------------------------------------------------------
Miki Tebeka
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 193 bytes
Desc: not available
URL:
From sybrenUSE at YOURthirdtower.com.imagination Sat Sep 10 04:23:15 2005
From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel)
Date: Sat, 10 Sep 2005 10:23:15 +0200
Subject: Create new instance of Python class in C
References:
Message-ID:
phil hunt enlightened us with:
> Why do you need to maske lots of copies?
The puzzles are stored in a NxN list of strings. The strings contain
all the numerals that that block can contain. So a 9x9 puzzle contains
81 strings "123456789" when it's "empty".
My creation function picks a block that isn't a given, and fixes it to
one of it's possible values. It then tries to solve the puzzle. If it
works, it's done creating the puzzle. If it doesn't work, it starts
over again in a recursive manner.
The solver solves the puzzle in-place. That means that if I want to
keep the original puzzle (the one that could be solved), I have to
make a copy.
> And when you say "lots of" what numbers do you mean? 100? 1000000?
That depends a lot. The parts "picks a block that isn't a given" and
"fixes it to one if it's possible values" are both randomized.
Sometimes it's 100, sometimes it's 50000.
> The reason I ask is I recently wrote a program to solve Sudoku
> puzzles, and IIRC it didn't make copies at all.
My solver doesn't create copies either. The creator does.
I think I'll change my algorithm to just solve the puzzle and don't
care about the original minimal puzzle that could be solved. I'll
create a fully solved puzzle, and then use another routine to remove
givens at random until the required number of givens is left. Of
course, still maintaining solvability.
That last part would require copying, but not as much as in the
current situation.
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
From olivier.dormond at hispeed.ch Fri Sep 23 08:07:42 2005
From: olivier.dormond at hispeed.ch (Olivier Dormond)
Date: Fri, 23 Sep 2005 14:07:42 +0200
Subject: Alternatives to Stackless Python?
In-Reply-To: <4333c642$0$25699$626a14ce@news.free.fr>
References: <1127231444.643628.197920@g49g2000cwa.googlegroups.com>
<1127438841.532386.73410@g44g2000cwa.googlegroups.com>
<4333c642$0$25699$626a14ce@news.free.fr>
Message-ID: <4333F00E.8010709@hispeed.ch>
Christophe wrote:
> simonwittber at gmail.com a ?crit :
>
>>> I found LGT http://lgt.berlios.de/ but it didn't seem as if the
>>> NanoThreads module had the same capabilites as stackless.
>>
>> What specific capabilities of Stackless are you looking for, that are
>> missing from NanoThreads?
>
> Capabilities of the different "threadlike" systems are somewhat muddy.
> What myself I like in stackless is :
> - you can put context switching instuctions anywhere in the callstack
> without having to explicitely chain the operation
> - pickle support
>
> Not sure if greenlets support pickling yet. There are no info on that
> point and my tests weren't succesful.
The greenlets play with the underlying CPU stack directly so I don't
think they could ever be pickled.
From jepler at unpythonic.net Thu Sep 15 12:23:27 2005
From: jepler at unpythonic.net (jepler at unpythonic.net)
Date: Thu, 15 Sep 2005 11:23:27 -0500
Subject: Tkinter add_cascade option_add
In-Reply-To:
References:
<8sCdnf5Vq94_1bXenZ2dnUVZ_sudnZ2d@nmt.edu>
Message-ID: <20050915162327.GD2861@unpythonic.net>
On Thu, Sep 15, 2005 at 06:11:18PM +0200, Mikael Olofsson wrote:
> Is this simply a Windows-issue that cannot easily be solved? Or is it
> possibly so that this just happens to be a problem on a few
> ill-configured computers? Or am I possibly blind?
Here's a section from the menu(n) manpage for Tcl.
It would appear that the font for the menubar is one of the things which
happens 'according to the interface guidelines of their platforms' on
win32-family systems.
MENUBARS
Any menu can be set as a menubar for a toplevel window (see toplevel
command for syntax). On the Macintosh, whenever the toplevel is in
front, this menu's cascade items will appear in the menubar across the
top of the main monitor. On Windows and Unix, this menu's items will be
displayed in a menubar accross the top of the window. These menus will
behave according to the interface guidelines of their platforms. For
every menu set as a menubar, a clone menu is made. See the CLONES sec-
tion for more information.
As noted, menubars may behave differently on different platforms. One
example of this concerns the handling of checkbuttons and radiobuttons
within the menu. While it is permitted to put these menu elements on
menubars, they may not be drawn with indicators on some platforms, due
to system restrictions.
On Windows, the font used for the menu can be ajusted by the user for all
applications (except those which go out of their way to ignore the user's
preferences) using the Display item in Control Panel.
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL:
From fredrik at pythonware.com Tue Sep 27 13:37:10 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 27 Sep 2005 19:37:10 +0200
Subject: Memory stats
References: <43386FE3.7060606@v.loewis.de>
<43396704.1030700@nuxeo.com>
Message-ID:
Tarek Ziad? wrote:
> > If you want a list of all objects (container or not), you have to
> > compile a debug build of Python.
>
> I am amazed not to find an existing implementation for this.
the debug build is an existing implementation, of course.
From sybrenUSE at YOURthirdtower.com.imagination Fri Sep 23 02:26:50 2005
From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel)
Date: Fri, 23 Sep 2005 08:26:50 +0200
Subject: How to use a timer in Python?
References:
Message-ID:
Nico Grubert enlightened us with:
> How can I use a timer that waits e.g. 10 seconds if 'transfer.lock'
> is present and then checks again if 'transfer.lock' is still there?
Make a while loop in which you sleep. Or use the threading module if
you want to go multi-threading.
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
From steve at holdenweb.com Wed Sep 7 13:10:54 2005
From: steve at holdenweb.com (Steve Holden)
Date: Wed, 07 Sep 2005 13:10:54 -0400
Subject: Question about concatenation error
In-Reply-To:
References:
Message-ID:
colonel wrote:
> On Wed, 07 Sep 2005 16:34:25 GMT, colonel
> wrote:
>
>
>>I am new to python and I am confused as to why when I try to
>>concatenate 3 strings, it isn't working properly.
>>
>>Here is the code:
>>
>>------------------------------------------------------------------------------------------
>>import string
>>import sys
>>import re
>>import urllib
>>
>>linkArray = []
>>srcArray = []
>>website = sys.argv[1]
>>
>>urllib.urlretrieve(website, 'getfile.txt')
>>
>>filename = "getfile.txt"
>>input = open(filename, 'r')
>>reg1 = re.compile('href=".*"')
>>reg3 = re.compile('".*?"')
>>reg4 = re.compile('http')
>>Line = input.readline()
>>
>>while Line:
>> searchstring1 = reg1.search(Line)
>> if searchstring1:
>> rawlink = searchstring1.group()
>> link = reg3.search(rawlink).group()
>> link2 = link.split('"')
>> cleanlink = link2[1:2]
>> fullink = reg4.search(str(cleanlink))
>> if fullink:
>> linkArray.append(cleanlink)
>> else:
>> cleanlink2 = str(website) + "/" + str(cleanlink)
>> linkArray.append(cleanlink2)
>> Line = input.readline()
>>
>>print linkArray
>>-----------------------------------------------------------------------------------------------
>>
>>I get this:
>>
>>["http://www.slugnuts.com/['index.html']",
>>"http://www.slugnuts.com/['movies.html']",
>>"http://www.slugnuts.com/['ramblings.html']",
>>"http://www.slugnuts.com/['sluggies.html']",
>>"http://www.slugnuts.com/['movies.html']"]
>>
>>instead of this:
>>
>>["http://www.slugnuts.com/index.html]",
>>"http://www.slugnuts.com/movies.html]",
>>"http://www.slugnuts.com/ramblings.html]",
>>"http://www.slugnuts.com/sluggies.html]",
>>"http://www.slugnuts.com/movies.html]"]
>>
>>The concatenation isn't working the way I expected it to. I suspect
>>that I am screwing up by mixing types, but I can't see where...
>>
>>I would appreciate any advice or pointers.
>>
>>Thanks.
>
>
>
> Okay. It works if I change:
>
> fullink = reg4.search(str(cleanlink))
> if fullink:
> linkArray.append(cleanlink)
> else:
> cleanlink2 = str(website) + "/" + str(cleanlink)
>
> to
>
> fullink = reg4.search(cleanlink[0])
> if fullink:
> linkArray.append(cleanlink[0])
> else:
> cleanlink2 = str(website) + "/" + cleanlink[0]
>
>
> so can anyone tell me why "cleanlink" gets coverted to a list? Is it
> during the slicing?
>
>
> Thanks.
The statement
cleanlink = link2[1:2]
results in a list of one element. If you want to accesss element one
(the second in the list) then use
cleanlink = link2[1]
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
From en.karpachov at ospaz.ru Fri Sep 30 01:11:26 2005
From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru)
Date: Fri, 30 Sep 2005 09:11:26 +0400
Subject: Will python never intend to support private, protected and
public?
In-Reply-To:
References: <311b5ce105092800102da32267@mail.gmail.com>
<7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com>
<7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com>
<7xzmpwuxd0.fsf@ruckus.brouhaha.com>
<20050930075313.67b9b6 76.jk@ospaz.ru>
Message-ID: <20050930091126.0c81580c.jk@ospaz.ru>
On Fri, 30 Sep 2005 06:31:44 +0200
Fredrik Lundh wrote:
> en.karpachov at ospaz.ru wrote:
>
> > Looks like you must know every one of the base classes of the NotSoSecret,
> > whether there is some base class named Secret? And, if so, you must also
> > know these classes _implementation_
>
> that information isn't hidden, so there's nothing "you must know". finding out
> is a matter of writing a very small program, or tinkering at the interactive prompt
> for a couple of seconds. are you even aware that you're posting to a Python
> group ?
So you have read every line of the python std library, I guess? (Not to
mention libc or kernel32.exe or whatever.)
--
jk
From roy at panix.com Sat Sep 10 15:11:34 2005
From: roy at panix.com (Roy Smith)
Date: Sat, 10 Sep 2005 15:11:34 -0400
Subject: Python versus Perl
References:
Message-ID:
Dieter Vanderelst wrote:
> 1 - How does the speed of execution of Perl compares to that of Python?
To a first-order approximation, Perl and Python run at the same speed.
They are both interpreted languages with roughly the same kind of control
flow and data structures. The two have wildly different kinds of syntax,
but the underlying machinery is fairly similar.
Don't make a decision on which to use based on execution speed. If you
feel compelled to ignore this advice, then don't make the decision until
you've coded your application in both languages and done careful
benchmarking with realistic data for your application domain.
> I have noticed that Regular Expressions are executed very fast in
> Python. Does anybody know whether Python executes RE faster than Perl
> does?
Same answer as above -- for a first cut, assume they are the same speed.
If you insist on a better answer, do measurements on real data.
The big advantage the Python has over Perl is speed of development and ease
of maintenance (i.e. a year from now, you can still understand what your
own code does).
From dimitri.pater at gmail.com Fri Sep 30 19:36:28 2005
From: dimitri.pater at gmail.com (dimitri pater)
Date: Sat, 1 Oct 2005 01:36:28 +0200
Subject: A Moronicity of Guido van Rossum
In-Reply-To:
References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com>
<1128013745.763757.144280@g44g2000cwa.googlegroups.com>
<1128015868.201617.153240@g14g2000cwa.googlegroups.com>
<0001HW.BF63479501083049F0407550@news.individual.de>
Message-ID:
>
>
>
> Yes, it would. Note that the word lunatic is derived from the Latin word
> luna, meaning moon.
so, he is a just another lunitac barking at the moon?
well, err barking at the python list...
greetz,
dimitri
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From pink at odahoda.de Thu Sep 1 13:13:37 2005
From: pink at odahoda.de (Benjamin Niemann)
Date: Thu, 01 Sep 2005 19:13:37 +0200
Subject: is there a better way to check an array?
References: <1125593752.264254.172970@g44g2000cwa.googlegroups.com>
Message-ID:
jdonnell wrote:
> I want to check if a value is in an array. I'm currently doing it as
> follows, but I just don't like this way of doing it. It seems
> unpythonic.
>
> fieldIsRequired = true
> try:
> notRequiredAry.index(k)
> fieldIsRequired = false
> except ValueError:
> pass
>
> # throw expception if field is required and is empty
> if(product[k] == '' and fieldIsRequired):
> raise GMError(k + ' is required')
if product[k] == '' and k in fieldIsRequired:
raise GMError(k + ' is required')
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
From bearophileHUGS at lycos.com Sat Sep 17 09:50:56 2005
From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com)
Date: 17 Sep 2005 06:50:56 -0700
Subject: sorting tuples...
In-Reply-To: <1126964468.444025.181180@g49g2000cwa.googlegroups.com>
References: <1126964468.444025.181180@g49g2000cwa.googlegroups.com>
Message-ID: <1126965056.689482.294690@g44g2000cwa.googlegroups.com>
Uhm, if the file is clean you can use something like this:
data = """\
200501221530
John
*** long string here ***
200504151625
Clyde
*** clyde's long string here ***
200503130935
Jeremy
*** jeremy string here ****"""
records = [rec.split("\n") for rec in data.split("\n\n")]
records.sort()
print records
If it's not clean, you have to put some more cheeks/cleanings.
Bye,
bearophile
From crankycoder at gmail.com Sun Sep 25 23:30:21 2005
From: crankycoder at gmail.com (Victor Ng)
Date: Sun, 25 Sep 2005 23:30:21 -0400
Subject: Metaclasses, decorators, and synchronization
In-Reply-To: <9c195fe6cc1bc873d9a90483f592e1f2@scl.ameslab.gov>
References: <9c195fe6cc1bc873d9a90483f592e1f2@scl.ameslab.gov>
Message-ID:
You could do it with a metaclass, but I think that's probably overkill.
It's not really efficient as it's doing test/set of an RLock all the
time, but hey - you didn't ask for efficient. :)
1 import threading
2
3 def synchronized(func):
4 def innerMethod(self, *args, **kwargs):
5 if not hasattr(self, '_sync_lock'):
6 self._sync_lock = threading.RLock()
7 self._sync_lock.acquire()
8 print 'acquired %r' % self._sync_lock
9 try:
10 return func(self, *args, **kwargs)
11 finally:
12 self._sync_lock.release()
13 print 'released %r' % self._sync_lock
14 return innerMethod
15
16 class Foo(object):
17 @synchronized
18 def mySyncMethod(self):
19 print "blah"
20
21
22 f = Foo()
23 f.mySyncMethod()
If you used a metaclass, you could save yourself the hassle of adding
a sync_lock in each instance, but you could also do that by just using
a plain old base class and making sure you call the base class's
__init__ to add in the sync lock.
vic
On 9/24/05, Michael Ekstrand wrote:
> I've been googling around for a bit trying to find some mechanism for
> doing in Python something like Java's synchronized methods. In the
> decorators PEP, I see examples using a hypothetical synchronized
> decorator, but haven't stumbled across any actual implementation of
> such a decorator. I've also found Synch.py, but that seems to use
> pre-2.2 metaclasses from what I have read.
>
> Basically, what I want to do is something like this:
>
> class MyClass:
> __metaclass__ = SynchronizedMeta
> @synchronized
> def my_sync_method():
> pass
>
> where SychronizedMeta is some metaclass that implements synchronization
> logic for classes bearing some synchronized decorator (probably also
> defined by the module defining SynchronizedMeta).
>
> After looking in the Cheeseshop, the Python source distribution, and
> Google, I have not been able to find anything that implements this
> functionality. If there isn't anything, that's fine, I'll just write it
> myself (and hopefully be able to put it in the cheeseshop), but I'd
> rather avoid duplicating effort solving previously solved problems...
> So, does anyone know of anything that alreaady does this? (or are there
> some serious problems with my design?)
>
> TIA,
> Michael
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
"Never attribute to malice that which can be adequately explained by
stupidity." - Hanlon's Razor
From theller at python.net Tue Sep 20 05:51:14 2005
From: theller at python.net (Thomas Heller)
Date: Tue, 20 Sep 2005 11:51:14 +0200
Subject: py2exe 0.6.2 version resources
References: <1127201535.064565.91670@g14g2000cwa.googlegroups.com>
Message-ID:
klaus.roedel at vipco.de writes:
> Hi @all,
>
> I've implementet a simple setup script for my application with py2exe.
> The setup.py works fine, but now I want to add version resources to my
> *.exe-file. But how can I do it?
> I've tested it with the setup.cfg, but that doesn't work. I alwayse
> became the errormessage:
> error: error in setup.cfg: command 'py2exe' has no such option
> 'version_legalcopyright'
> until I've deleted all options.
> I'm using python 2.4.1 and py2exe 0.6.2 on Windows XP SP2.
> Thanks for any help.
In py2exe 0.5 and 0.6 you can no longer specify the versionresource in
setup.cfg. The advanced sample in
lib\site-packages\py2exe\samples\advanced demonstrated how to do it.
> Greets,
> Klaus
Thomas
From steve at holdenweb.com Sun Sep 4 01:45:58 2005
From: steve at holdenweb.com (Steve Holden)
Date: Sun, 04 Sep 2005 00:45:58 -0500
Subject: how to do this?
In-Reply-To: <9cvSe.3820$3R1.2590@fe06.lga>
References: <9cvSe.3820$3R1.2590@fe06.lga>
Message-ID:
Justin Straube wrote:
> Greetings Pythonistas.
> Im looking for a way to write this but not sure where or how to begin.
> As the user enters or removes characters into/from sEnt I would like
> for set_info() to set infVar with the correct value. The same as how
> IDLE shows the line and column in the lower right corner.
>
First of all, it might have been better to provide a more meaningful
title like "Update display as text entry changes", but not to worry -
this is a matter of experience.
> #### Code Example ####
> from time import localtime
> from Tkinter import *
>
> def set_info():
> x = len(strVar.get())
> infVar.set('Length: %i' % (x))
>
> ROOT = Tk()
> strVar = StringVar()
> infVar = StringVar()
>
> sLab = Label(ROOT, text='String')
> sLab.grid(row=0, column=0)
> sEnt = Entry(ROOT, textvariable=strVar, width=15)
> sEnt.grid(row=0, column=1, columnspan=2)
> qBut = Button(ROOT, text='Quit', command=ROOT.quit)
> qBut.grid(row=1, column=2, pady=2, padx=2, sticky=E)
> iLab = Label(ROOT, textvariable=infVar, width=21,
> relief=SUNKEN, anchor=W)
> iLab.grid(row=2, column=0, columnspan=3)
>
> set_info() # example to show what will be displayed.
> ROOT.mainloop()
> #### End Example ####
>
> Can anyone point me in the right direction for how to do this?
>
The key here is to bind keystroke events to the routine to change the
display. The following program uses your set_info() function to update
the display every time a key is released (I chose this event because by
the time it is raised the keystroke has been processed by the Entry widget.
I don;t guarantee this code will work across several Entry widgets
without your keeping track of which one has focus when the event is
raised (it's late, and I'm about to turn in for the night), but at least
it will give you something to play with.
You'll note that set_info() has acquired an argument - Tkinter provides
an event as an argument when a callback is called. So the manual call
gets a bogus event of "None" just to avoid exceptions. Hope this gets
you started.
#### Code Example ####
from time import localtime
from Tkinter import *
def set_info(event):
x = len(strVar.get())
infVar.set('Length: %i' % (x))
ROOT = Tk()
strVar = StringVar()
infVar = StringVar()
sLab = Label(ROOT, text='String')
sLab.grid(row=0, column=0)
sEnt = Entry(ROOT, textvariable=strVar, width=15)
sEnt.grid(row=0, column=1, columnspan=2)
sEnt.bind("", set_info)
qBut = Button(ROOT, text='Quit', command=ROOT.quit)
qBut.grid(row=1, column=2, pady=2, padx=2, sticky=E)
iLab = Label(ROOT, textvariable=infVar, width=21,
relief=SUNKEN, anchor=W)
iLab.grid(row=2, column=0, columnspan=3)
set_info(None) # example to show what will be displayed.
ROOT.mainloop()
#### End Example ####
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
From renting at astron.nl Fri Sep 16 03:02:59 2005
From: renting at astron.nl (Adriaan Renting)
Date: Fri, 16 Sep 2005 09:02:59 +0200
Subject: read stdout/stderr without blocking
Message-ID:
Great reply,
I had just mixed Pexpect and subProcess code until I'd got something that worked, you can actually explain my code better a I can myself. I find it quite cumbersome to read stdout/strerr separately, and to be able to write to stdin in reaction to either of them, but at least on Linux you can get it to work. My NON_BLOCKing command might be unnecesary, I'll try without it.
The OP seemed interested on how to do this on Windows, but I've yet to see an answer on that one I think.
Thank you for the reply.
Adriaan Renting
|>>>Donn Cave 09/15/05 6:19 pm >>>
|In article ,
|Peter Hansen wrote:
|
|>Jacek Pop?awski wrote:
|>>Grant Edwards wrote:
|>>
|>>>On 2005-09-12, Jacek Pop?awski wrote:
|>>>
|>>>>> ready = select.select(tocheck, [], [], 0.25) ##continues
|>>>>>after 0.25s
|>>>>> for file in ready[0]:
|>>>>> try:
|>>>>> text = os.read(file, 1024)
|>>>>
|>>>>
|>>>>How do you know here, that you should read 1024 characters?
|>>>>What will happen when output is shorter?
|>>>
|>>>It will return however much data is available.
|>>
|>>My tests showed, that it will block.
|>
|>Not if you use non-blocking sockets, as I believe you are expected to
|>when using select().
|
|On the contrary, you need non-blocking sockets only if
|you don't use select. select waits until a read [write]
|would not block - it's like "if dict.has_key(x):" instead of
|"try: val = dict[x] ; except KeyError:". I suppose you
|knew that, but have read some obscure line of reasoning
|that makes non-blocking out to be necessary anyway.
|Who knows, but it certainly isn't in this case.
|
|I don't recall the beginning of this thread, so I'm not sure
|if this is the usual wretched exercise of trying to make this
|work on both UNIX and Windows, but there are strong signs
|of the usual confusion over os.read (a.k.a. posix.read), and
|file object read. Let's hopefully forget about Windows for
|the moment.
|
|The above program looks fine to me, but it will not work
|reliably if file object read() is substituted for os.read().
|In this case, C library buffering will read more than 1024
|bytes if it can, and then that data will not be visible to
|select(), so there's no guarantee it will return in a timely
|manner even though the next read() would return right
|away. Reading one byte at a time won't resolve this problem,
|obviously it will only make it worse. The only reason to
|read one byte at a time is for data-terminated read semantics,
|specifically readline(), in an unbuffered file. That's what
|happens -- at the system call level, where it's expensive --
|when you turn off stdio buffering and then call readline().
|
|In the C vs. Python example, read() is os.read(), and file
|object read() is fread(); so of course, C read() works
|where file object read() doesn't.
|
|Use select, and os.read (and UNIX) and you can avoid blocking
|on a pipe. That's essential if as I am reading it there are supposed
|to be two separate pipes from the same process, since if one is
|allowed to fill up, that process will block, causing a deadlock if
|the reading process blocks on the other pipe.
|
|Hope I'm not missing anything here. I just follow this group
|to answer this question over and over, so after a while it
|gets sort of automatic.
|
| Donn Cave, donn at u.washington.edu
From NutJob at gmx.net Mon Sep 19 07:46:10 2005
From: NutJob at gmx.net (antred)
Date: 19 Sep 2005 04:46:10 -0700
Subject: threads/sockets quick question.
In-Reply-To: <1127103181.088804.173820@g14g2000cwa.googlegroups.com>
References: <1127103181.088804.173820@g14g2000cwa.googlegroups.com>
Message-ID: <1127130369.929039.8380@z14g2000cwz.googlegroups.com>
This may be a really stupid question, but are you actually CALLING your
scan() function anywhere?
From fakeaddress at nowhere.org Wed Sep 7 04:29:52 2005
From: fakeaddress at nowhere.org (Bryan Olson)
Date: Wed, 07 Sep 2005 08:29:52 GMT
Subject: dict and __cmp__() question
In-Reply-To: <1126078954.485637.172070@g47g2000cwa.googlegroups.com>
References: <1126078954.485637.172070@g47g2000cwa.googlegroups.com>
Message-ID: <4yxTe.892$JN5.336@newssvr13.news.prodigy.com>
Alex wrote:
> But what are those with double underscore? For instance __cmp__(...)?
Those are these:
http://docs.python.org/ref/specialnames.html
--
--Bryan
From n00m at narod.ru Sun Sep 4 09:41:53 2005
From: n00m at narod.ru (n00m)
Date: 4 Sep 2005 06:41:53 -0700
Subject: Sockets: code works locally but fails over LAN
In-Reply-To:
References: <1125493380.805663.16800@g44g2000cwa.googlegroups.com>
<1125597092.323375.151570@g44g2000cwa.googlegroups.com>
<1125681663.710557.320340@f14g2000cwb.googlegroups.com>
<3m6ih1taaeo7kndnbuvfl5geed053ivunl@4ax.com>
<1125774529.074965.269720@g44g2000cwa.googlegroups.com>
<1125790986.012636.40050@o13g2000cwo.googlegroups.com>
Message-ID: <1125841313.297294.304690@o13g2000cwo.googlegroups.com>
Bryan Olson wrote:
> Ah, yes, I see. (In my defense, I had already fixed that bug in
> my second version.)
1.
Yes! I myself noticed that, but your 2nd version looks
a bit more verbose.
2.
This all means... what? ONLY send() vs sendall() matters?
Sometimes send() really sends ALL and my version works too!
I must give it a thorough testing!
3.
See how it looks in SQL Server Profiler (it's its utility for
tracing client/server events) WHEN I started 5 copies of .vbs.
http://free.7host02.com/n00b/SQL_Profiler.gif
Btw, without s2.shutdown(1) those vbs' do NOT disconnect from
the server (see DISCONNECT events on the gif).
The latest python version:
==============================
import socket, thread
sqls_host, sqls_port = '127.0.0.1', 1433
proxy_host, proxy_port = '127.0.0.1', 1434
# How I tested it:
# sqls_host, sqls_port = 'www.google.com', 80
def VB_SCRIPT(s2, cn):
while 1:
data = cn.recv(4096)
if not data:
s2.shutdown(1)
return
s2.sendall(data)
print 'VB_SCRIPT:' + data + '\n'
def SQL_SERVER(s2, cn):
while 1:
data = s2.recv(4096)
if not data: return
cn.sendall(data)
print 'SQL_SERVER:' + data + '\n'
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.bind((proxy_host, proxy_port))
s1.listen(5)
while 1:
cn, addr = s1.accept()
s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2.connect((sqls_host, sqls_port))
thread.start_new_thread(VB_SCRIPT,(s2, cn))
thread.start_new_thread(SQL_SERVER,(s2, cn))
The vbs text:
==============
Set cn = CreateObject("ADODB.Connection")
cn.Open _
"Provider=sqloledb;Data Source=127.0.0.1,1434;" & _
"Network Library=DBMSSOCN;Initial Catalog=pubs;" & _
"User ID=qwe;Password=asdasd;"
cn.Execute _
"select 'AAAAAAAAAAAAAAA';" & _
"waitfor delay '00:00:02'; raiserror('XXX',10,1) with nowait;" & _
"waitfor delay '00:00:02'; raiserror('YYY',10,1) with nowait;" & _
"waitfor delay '00:00:02'; raiserror('ZZZ',10,1) with nowait;" & _
"select 'BBBBBBBBBBBBBBB';"
cn.Close
Set cn = Nothing
From jstroud at mbi.ucla.edu Mon Sep 19 17:46:15 2005
From: jstroud at mbi.ucla.edu (James Stroud)
Date: Mon, 19 Sep 2005 14:46:15 -0700
Subject: Best Encryption for Python Client/Server
In-Reply-To:
References:
Message-ID: <200509191446.15240.jstroud@mbi.ucla.edu>
SSH can be used for functionality like this, through tunneling. You can even
tunnel interprocess communication through SSH. Its not exceptionally
complicated.
On Sunday 18 September 2005 13:36, Ed Hotchkiss wrote:
> Let us say that I am trying to create a very small and simple private
> network/connection between several scripts on different machines, to
> communicate instructions/data/files etc. to each other over the net. Is SSL
> the best method? Any recommendations of something to get started with?
> Thanks in advance.
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
From deets at nospam.web.de Fri Sep 2 09:38:13 2005
From: deets at nospam.web.de (Diez B. Roggisch)
Date: Fri, 02 Sep 2005 15:38:13 +0200
Subject: How to handle video & alpha channel
In-Reply-To:
References:
Message-ID: <3nr2u5F2sm47U1@uni-berlin.de>
Mic wrote:
> I'm looking for a way to build a little player (if possibile with
> python ) that could handle common video file formats (mpeg or other)
> with above an image with alpha channel (png or other)
>
> Is there a way to make this with python and available libs (PIL etc)?
Check out pymedia.
Regards,
Diez
From http Sat Sep 10 19:30:47 2005
From: http (Paul Rubin)
Date: 10 Sep 2005 16:30:47 -0700
Subject: encryption with python
References: <1126101629.243503.299310@g44g2000cwa.googlegroups.com>
<87k6hok51e.fsf@debian.kirkjobsluder.is-a-geek.net>
Message-ID: <7xhdcsfql4.fsf@ruckus.brouhaha.com>
James Stroud writes:
> Yes and no. Yes, you are theoretically correct. No, I don't think
> you have the OP's original needs in mind (though I am mostly
> guessing here). The OP was obviously a TA who needed to assign
> students a number so that they could "anonymously" check their
> publicly posted grades and also so that he could do some internal
> record keeping.
If that's all it's about, it's not a big deal. If it's for some central
administrative database that's more of a target, more care is warranted.
> The idea of combining ID information and encrypting it to create
The info to be combined was the student's birthdate. Why would the TA
have access to either that or the SSN?
> import sha
> def encrypt(x,y, password):
> def _dosha(v): return sha.new(str(v)+str(password)).hexdigest()
> return int(_dosha(_dosha(x)+_dosha(y))[5:13],16)
>
> So now what is the criticism? That its still a "secret algorithm"
> because the password is "secret"?
That's sort of reasonable as long as the password really is secret and
you don't mind a small chance of two students getting the same ID
number once in a while. If the password is something that a TA types
into a laptop when entering grades and which goes away after the
course ends, it's not such a big deal. If it's a long-term key that
has to stay resident in a 24/7 server through the students' entire
time at the university and beyond, then the algorithm is the trivial
part and keeping the key secret is a specialized problem in its own
right. For example, financial institutions use special, tamper
resistant hardware modules for the purpose.
Could the OP please say what the exact application is? That might get
more useful responses if the question still matters.
From tdelaney at avaya.com Thu Sep 29 21:12:37 2005
From: tdelaney at avaya.com (Delaney, Timothy (Tim))
Date: Fri, 30 Sep 2005 11:12:37 +1000
Subject: A Moronicity of Guido van Rossum
Message-ID: <2773CAC687FD5F4689F526998C7E4E5F4DB685@au3010avexu1.global.avaya.com>
Tony Meyer wrote:
> I expect that if you look at the clues for such messages, you'll find
> that any 'Xah Lee' clues are swamped by lots of 'c.l.p message'
> clues. A big problem with filtering mailing lists at the user end
> (rather than before the post is accepted) is that the mailing
> software adds so many strongly-correlated clues. It's made worse
> because he uses so many words that you'd expect to find in legitimate
> c.l.p messages.
It's this last bit that's the problem. I've got no problems filtering
other types of spam messages to the list, but XL adds so many non-spam
terms that the from field gets declared a statistical anomaly :(
Tim Delaney
From hancock at anansispaceworks.com Thu Sep 22 18:08:17 2005
From: hancock at anansispaceworks.com (Terry Hancock)
Date: Thu, 22 Sep 2005 17:08:17 -0500
Subject: Question About Logic In Python
In-Reply-To: <0PBYe.109568$p_1.45988@tornado.tampabay.rr.com>
References: <1127089204.462591.250950@g14g2000cwa.googlegroups.com>
<0PBYe.109568$p_1.45988@tornado.tampabay.rr.com>
Message-ID: <200509221708.17917.hancock@anansispaceworks.com>
On Thursday 22 September 2005 12:26 pm, Ron Adam wrote:
> Steve Holden wrote:
> > Ron Adam wrote:
> >> >>> True * True
> >> 1 # Why not return True here as well?
> >>
> > Why not return 42? Why not return a picture of a banana?
>
> My question still stands. Could it be helpful if bools were preserved
> in more cases than they are now?
No. "*" is "multiplication".
The multiplication operator is undefined for boolean values. It only
makes sense if they are interpreted as numbers. As it happens, both
can be coerced to 1, so the result is 1*1. This makes perfect sense
to me.
>>> True and True
True
Also makes sense (and this is indeed what happens).
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
From ajikoe at gmail.com Wed Sep 21 05:03:09 2005
From: ajikoe at gmail.com (ajikoe at gmail.com)
Date: 21 Sep 2005 02:03:09 -0700
Subject: spe stani collapse all method?
Message-ID: <1127293388.964632.303960@z14g2000cwz.googlegroups.com>
hello,
I wonder if anyone used spe stani, I'm looking for how to collapse all
code fold, but can't find.
pujo
From peter at engcorp.com Fri Sep 30 07:33:23 2005
From: peter at engcorp.com (Peter Hansen)
Date: Fri, 30 Sep 2005 07:33:23 -0400
Subject: RELEASED Python 2.4.2 (final)
In-Reply-To: <433CCF02.6060005@v.loewis.de>
References:
<433CCF02.6060005@v.loewis.de>
Message-ID:
Martin v. L?wis wrote:
> Trent Mick wrote:
>
>>It is possible that the python.org installer didn't overwrite the
>>"python24.dll" in the system directory (C:\WINDOWS\system32). Try doing
>>this:
>
>
> Even though this is apparently what happened, I'm puzzled as to why it
> happened: shouldn't the version number of python24.dll in the pydotorg
> installer be higher than the one in the ActivePython installer, and
> shouldn't then Windows Installer overwrite the DLL?
Couldn't it also happen if the first time someone did an "admin" install
which (I believe) puts the DLLs in the system folder, and the next time
did just a non-admin install which doesn't do that? (Or am I
misunderstanding the conditions under which c:\windows\system32 has
files written to it?)
-Peter
From http Wed Sep 28 18:23:07 2005
From: http (Paul Rubin)
Date: 28 Sep 2005 15:23:07 -0700
Subject: Will python never intend to support private, protected and public?
References: <311b5ce105092800102da32267@mail.gmail.com>
<7xbr2dxqqq.fsf@ruckus.brouhaha.com>
<7xk6h0zxnm.fsf@ruckus.brouhaha.com>
Message-ID: <7x64skzvas.fsf@ruckus.brouhaha.com>
Gregor Horvath writes:
> If its your code this is possible, but if not and the maintainer is
> not willing or able to change it, then you have a problem.
Perhaps the maintainer has good reason for not wanting to change it.
After all, he's maintaining the code and you're not. In the course of
that maintenance he might change the internal usage of the private
variable that messes up the way you use it. He's supposed to be
allowed to do that--that's why the variable is private. Is he
supposed to get your permission every time he wants to change how the
private variables in his class work?
> The fact that in other languages there are wired tricks to get to
> private instance variables is a strong indicator that there is a need
> for that.
Java has some JVM switches that open ways to get at private variables
so things like debuggers can work. In production code you'd turn that
stuff off. And it's certainly not intended for normal classes in an
application to get at the private variables of other classes.
> Guided freedom is better than enforced authority.
The obvious way to provide that guidance is to declare variables to be
private if other classes shouldn't mess with the variables. There is
still the freedom to change the declaration if necessary. Unless of
course you don't have the source code. Where there is no source code,
there is no freedom, no matter what features the language has.
From darkpaladin79 at hotmail.com Thu Sep 29 20:29:37 2005
From: darkpaladin79 at hotmail.com (Ivan Shevanski)
Date: Thu, 29 Sep 2005 20:29:37 -0400
Subject: Turning off syntax warnings?
Message-ID:
Here's a noob question for everyone which i can't seem to find the answer to
on google. . .Is there a way to turn off syntax warnings?
-Ivan
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
From jeffrey.schwab at rcn.com Thu Sep 29 09:22:12 2005
From: jeffrey.schwab at rcn.com (Jeff Schwab)
Date: Thu, 29 Sep 2005 09:22:12 -0400
Subject: A rather unpythonic way of doing things
In-Reply-To: <37ll1gci8v.fsf@chiark.greenend.org.uk>
References: <37ll1gci8v.fsf@chiark.greenend.org.uk>
Message-ID:
Peter Corbett wrote:
> One of my friends has recently taken up Python, and was griping a bit
> about the language (it's too "prescriptive" for his tastes). In
> particular, he didn't like the way that Python expressions were a bit
> crippled. So I delved a bit into the language, and found some sources
> of syntactic sugar that I could use, and this is the result:
>
> http://www.pick.ucam.org/~ptc24/yvfc.html
Yuma Valley Agricultural Center?
Yaak Valley Forest Council?
From email at christoph-haas.de Sun Sep 25 17:24:04 2005
From: email at christoph-haas.de (Christoph Haas)
Date: Sun, 25 Sep 2005 23:24:04 +0200
Subject: Best practices for dynamically loading plugins at startup
Message-ID: <20050925212404.GA6934@torf.workaround.org>
Dear coders...
I'm working on an application that is supposed to support "plugins".
The idea is to use the plugins as packages like this:
Plugins/
__init__.py
Plugin1.py
Plugin2.py
Plugin3.py
When the application starts up I want to have these modules loaded
dynamically. Users can put their own plugin modules into the
Plugins/ directory and the application should know about it.
Since I don't know which plugins have been put into that directory
I cannot just "import Plugin1, Plugin2, Plugin3" in the "__init__.py".
So I need to find out the *.py there and load them during startup.
I could do that with a "walk" over that directory.
Each plugin is supposed to be a class derived from a general
"Plugin" superclass. I just don't know how to 'register' every
plugin. The main application needs to know which plugin classes
there are. On IRC I was recommended walking through all objects
and finding out if the class is a subclass of "Plugin". Another
person recommended using metaclasses to automatically register
the plugin in a global list.
Since I have only little real-life Python knowledge I wonder what the
best practice for this kind of problem is.
I looked at the "supybot" IRC bot to get an idea how plugins are handled
there. Unfortunately it was still a bit over my (python) head.
Regards
Christoph
--
~
~
~
".signature" [Modified] 3 lines --100%-- 3,41 All
From grante at visi.com Thu Sep 15 18:13:52 2005
From: grante at visi.com (Grant Edwards)
Date: Thu, 15 Sep 2005 22:13:52 -0000
Subject: 2.3 -> 2.4: long int too large to convert to int
Message-ID: <11ijsh0h2dec0ed@corp.supernews.com>
I give up, how do I make this not fail under 2.4?
fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
I get an OverflowError: long int too large to convert to int
ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has
the high-order bit set. I'm assuming Python thinks it's a
signed value. How do I tell Python that 0xc0047a80 is an
unsigned 32-bit value?
--
Grant Edwards grante Yow! I demand IMPUNITY!
at
visi.com
From eghost at flashmail.com Sat Sep 24 15:32:37 2005
From: eghost at flashmail.com (Sam L.)
Date: 24 Sep 2005 12:32:37 -0700
Subject: Could this C extension be leaking memory?
Message-ID: <1127590357.126298.280260@g49g2000cwa.googlegroups.com>
I am trying this out, parts of it are direct from the Python 2.4
manual.
//----------- icallbk.c
#include "Python.h"
PyObject *fcallback = NULL;
static PyObject*
call_func(PyObject* self, PyObject* args)
{
PyObject *result;
PyObject *arglist;
int arg = 123;
arglist = Py_BuildValue("(i)", arg);
result = PyEval_CallObject(fcallback, arglist);
Py_DECREF(arglist);
Py_DECREF(result);
Py_RETURN_NONE;
}
static PyObject *
set_callback(PyObject *self, PyObject *args)
{
PyObject *result = NULL;
PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "parameter must be
callable");
return NULL;
}
Py_XINCREF(temp); /* Add a reference to new callback */
Py_XDECREF(fcallback); /* Dispose of previous callback */
fcallback = temp; /* Remember new callback */
/* Boilerplate to return "None" */
Py_INCREF(Py_None);
result = Py_None;
}
return result;
}
static PyMethodDef icallbk_methods[] = {
{ "call_func", call_func, METH_VARARGS, "call_func" },
{ "set_callback", set_callback, METH_VARARGS, "set_callback" },
{ 0,0,0,0 }
};
PyMODINIT_FUNC
initicallbk(void)
{
(void) Py_InitModule("icallbk", icallbk_methods);
}
"""
I use the following code to run the extension above.
"""
# cb.py: Code to run the extension above.
import icallbk as c
def f(a): print a
c.set_callback(f)
c.call_func()
"""
But when I run that for a hundred times, I think the system is losing
100KB or thereabouts that is no longer re-claimed. Can someone confirm
this, and if it so, kindly inform me what is wrong with the code?
Thanks
From rkern at ucsd.edu Wed Sep 7 18:33:25 2005
From: rkern at ucsd.edu (Robert Kern)
Date: Wed, 07 Sep 2005 15:33:25 -0700
Subject: Construct raw strings?
In-Reply-To: <1126130881.555483.296200@g47g2000cwa.googlegroups.com>
References: <1126130881.555483.296200@g47g2000cwa.googlegroups.com>
Message-ID:
Thomas W wrote:
> I got a stupid problem; on my WinXP-box I want to scan the filesystem
> and enter a path to scan like this :
>
> path_to_scan = 'd:\test_images'
path_to_scan = r'd:\test_images'
> This is used in a larger context and joined like
>
> real_path_after_scanning = os.path.join(path_to_scan, somepart, 'foo',
> 'bar', filename)
>
> Using os.path.exists(real_path_after_scanning) returns false. The
> problem is that some of the parts being joined contains escape
> characters, like \. If I take the seperate parts and join them using
> the interpreter, like :
>
>>>>f = r'd:\test_images\something\foo\bar\test.jpg'
>
> it works ok and os.path.exists(f) returns True, but I cannot the that
> r' in front using the os.path.join-method in my code.
There is no such thing as a "raw string." There are "raw string
literals" which, when evaluated as Python source, are interpreted with
slightly different rules than regular "string literals." After the
literal has been interpreted to yield a string object, there is no
difference between the two; they're both just string objects.
If you can, please post a small but complete example script that causes
errors (and the actual output of the error itself).
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
From dale at riverhall.nospam.co.uk Fri Sep 23 11:44:17 2005
From: dale at riverhall.nospam.co.uk (Dale Strickland-Clark)
Date: Fri, 23 Sep 2005 16:44:17 +0100
Subject: Config parser module
References: <1127489369.091513.206040@g49g2000cwa.googlegroups.com>
Message-ID: <8pVYe.60117$a86.1519@fe04.usenetserver.com>
The Config Parser module is for extracting data from and writing to a
specific format of file, generally known as a config file. As explained in
the documentation, a config file is in the same format as .ini files
frequently found on windows - especially used by older software.
It is a very handy file format for all sorts of jobs, more so on Linux these
days than Windows, probably. However, it isn't much use for your particular
need as described here.
qqcq6s59 at gmail.com wrote:
> Hi all
> I am a newbie and I just saw a ongoing thread on Fileprocessing which
> talks abt config parser.
> I have writen many pyhton program to parse many kind of text files by
> using string module and regex. But after reading that config parser
> thread I feel stunned.
>
> Can somebody tell me some intro info how to parse huge data (most of
> them are input data to application softwares like nastran, abaqus etc)
>
> Recently I saw a great work by John on Nastran file parser (i am still
> trying to understand the program,
> http://jrfonseca.dyndns.org/svn/phd/python/Data/Nastran/
>
> An example of dat may be like this, (part of)
> (say point id coordinateSysNo x,y,z ...)
> GRID 1 12478.0 0.0 256.75 1
> GRID 2 12357.25 0.0 256.75 1
> GRID 3 12357.25 0.0 199.0 1
> (say Elementtype id property point1 point 2 point3 point4 etc)
> CQUAD4 7231 21 5691 5700 5701 56920.0
>
> CQUAD4 7232 21 5692 5701 5702 56930.0
>
> CQUAD4 7233 21 5693 5702 5703 56940.0
>
> the data file is very complex if i consider all complexities)
>
> Is is possible to use config parser module insome way for this. I also
> have few perl parser (for some part for some particular tasks) and now
> changing them to python. (I feel perl regex combination is very easy to
> learn and very powerfull)
>
> Any information will be appreciated.
>
> -jiro
--
Dale Strickland-Clark
Riverhall Systems www.riverhall.co.uk
We're recruiting Python programmers. See web site.
From miki.tebeka at zoran.com Thu Sep 1 04:01:55 2005
From: miki.tebeka at zoran.com (Miki Tebeka)
Date: Thu, 1 Sep 2005 11:01:55 +0300
Subject: Epydoc - Documenting class members?
In-Reply-To: <200508311702.04363.hancock@anansispaceworks.com>
References: <20050831141106.GG2656@zoran.com>
<200508311702.04363.hancock@anansispaceworks.com>
Message-ID: <20050901080153.GJ2656@zoran.com>
Hello Terry,
[Miki]
>> Is there a way to document class members in Epydoc?
[Terry]
> Yes. See additions below:
>
> > Something like:
> >
> > class Point:
> """
> @ivar x: This is where you document x.
> @ivar y: This is where you document y.
> """
I don't like this, I want to document where I declare the variable below.
Doxygen (www.doxygen.org), for one example, knows how to do this.
> > def __init__(self, x, y):
> > '''Create new point
> > @param x: X coord
> > @param y: Y coord
> > '''
> > self.x = x # How do I document here?
> > self.y = y # How do I document here?
> All of the fields are documented on the http://epydoc.sf.net
> website, by the way.
I know.
Thanks.
--
------------------------------------------------------------------------
Miki Tebeka
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 193 bytes
Desc: not available
URL:
From mfranklin1 at gatwick.westerngeco.slb.com Thu Sep 8 05:29:19 2005
From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin)
Date: Thu, 08 Sep 2005 10:29:19 +0100
Subject: reading the last line of a file
In-Reply-To:
References: <1126087115.516061.50290@o13g2000cwo.googlegroups.com> <1126168591.395956.118840@z14g2000cwz.googlegroups.com>
Message-ID: <4320046F.1040606@gatwick.westerngeco.slb.com>
Martin Franklin wrote:
> Xah Lee wrote:
>
>>Martin Franklin wrote:
>>
>>
>>>import gzip
>>>log_file = gzip.open("access_log.4.gz")
>>>last_line = log_file.readlines()[-1]
>>>log_file.close()
>>
>>
>>does the
>>log_file.readlines()[-1]
>>actually read all the lines first?
>
>
>
> Yes I'm afraid it does.
>
>
>
>>i switched to system call with tail because originally i was using a
>>pure Python solution
>>
>> inF = gzip.GzipFile(ff, 'rb');
>> s=inF.readlines()
>> inF.close()
>> last_line=s[-1]
>>
>>and since the log file is 100 megabytes it takes a long time and hogs
>>massive memory.
>>
>
>
> Ok, in that case stick to your shell based solution, although 100
> megabytes does not sound that large to me I guess it is relative
> to the system you are running on :) (I have over a gig of memory here)
>
And just a few minutes after I sent that... this...
import gzip
logfile = gzip.open("access_log.4.BIG.gz")
## seek relative to the end of the file
logfile.seek(-500)
last_line = logfile.readlines()[-1]
logfile.close()
print last_line
Works quite fast on my machine...
Regards
Martin
From steven.bethard at gmail.com Mon Sep 19 11:50:43 2005
From: steven.bethard at gmail.com (Steven Bethard)
Date: Mon, 19 Sep 2005 09:50:43 -0600
Subject: C#3.0 and lambdas
In-Reply-To:
References: <1127049737.654113.84440@z14g2000cwz.googlegroups.com>
Message-ID:
Steven D'Aprano wrote:
> Consider this:
>
> def func(some_tuple):
>
> How many items should you pass in the tuple? If it takes variable
> arguments, then that works, but if you always expect a fixed number, then
>
> def func((x, y))
>
> is more explicit.
>
> The only problem I have is that once you unroll the tuple like that, it is
> hardly necessary to pass the argument as a tuple. Why not just pass x and
> y as two arguments?
>
> def func(x, y)
I generally agree with this (and follow the same guideline in my own
APIs), but sometimes you don't have this option. If I have a class that
I'd like to support an indexing operation like:
obj[x, y]
then the natural __getitem__ signature will look like:
def __getitem__(self, (x, y)):
...
STeVe
From bill.mill at gmail.com Mon Sep 19 15:40:44 2005
From: bill.mill at gmail.com (Bill Mill)
Date: Mon, 19 Sep 2005 15:40:44 -0400
Subject: C#3.0 and lambdas
In-Reply-To: <3p85r3F91u2eU1@uni-berlin.de>
References: <1127049737.654113.84440@z14g2000cwz.googlegroups.com>
<3p85r3F91u2eU1@uni-berlin.de>
Message-ID: <797fe3d405091912402a8cf1d6@mail.gmail.com>
On 9/19/05, Diez B. Roggisch wrote:
> > meanwhile, over in python-dev land:
> >
> > "Is anyone truly attached to nested tuple function parameters; 'def
> > fxn((a,b)): print a,b'? /.../
> >
> > Would anyone really throw a huge fit if they went away? I am willing
> > to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
> > people are up for it."
>
> I am - I think that feature is sort of an orthogonality which should be
> preserved. No doubt its not one of the most important ones - but if I
> can write
>
> a, (b ,c) = 1, (2,3)
>
> I'd like to write
>
> def foo(a, (b,c)):
> ...
>
> foo(1, (2,3))
>
Agreed. I discovered them when I wondered "wouldn't it be neat if
functions unpacked tuples just like regular code does?" And was
pleasantly surprised to find that they did.
+1 on keeping them.
Peace
Bill Mill
bill.mill at gmail.com
From http Fri Sep 30 06:09:33 2005
From: http (Paul Rubin)
Date: 30 Sep 2005 03:09:33 -0700
Subject: Self reordering list in Python
References:
<1128074048.552398.151950@z14g2000cwz.googlegroups.com>
Message-ID: <7xfyrmc1eq.fsf@ruckus.brouhaha.com>
"zooko" writes:
> I haven't benchmarked it against Evan Podromou's heap implementation
> yet, but obviously inserting and removing things from a heapq heap is
> O(N).
Good heavens, I should hope not. The whole point of heaps is that
those operations are O(log(N)).
From bokr at oz.net Thu Sep 15 00:23:00 2005
From: bokr at oz.net (Bengt Richter)
Date: Thu, 15 Sep 2005 04:23:00 GMT
Subject: Property and "fset" in Python 2.4
References:
Message-ID: <4328f635.1502254417@news.oz.net>
On Wed, 14 Sep 2005 18:12:44 -0700, "Rob Pawsner" wrote:
>With this setup --
>
> PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
>on win32.
>
>-- I'm seeing the old bug which made "fset" methods unusable with declared
>properties of a class. Even worse, this is happening with a
>fourth-generation descendent of the Object class, not an old-style class as
>in "python-Bugs-1207379",
>http://www.mail-archive.com/python-bugs-list at python.org/msg03434.html.
>
>Before I clog up the digest with details and code snippets, does this sound
>familiar to anyone?
>
A snippet demonstrating a real bug would be helpful.
A snippet demonstrating a misunderstanding could be helpful.
What's the problem? ;-)
Regards,
Bengt Richter
From bektek at gmail.com Fri Sep 30 14:09:00 2005
From: bektek at gmail.com (kimes)
Date: 30 Sep 2005 11:09:00 -0700
Subject: Duplicating Modules
In-Reply-To:
References:
Message-ID: <1128103740.931794.136610@o13g2000cwo.googlegroups.com>
Why don't you do like this..
import module
import mudule as module2
From sam at email-scan.com Wed Sep 21 19:23:33 2005
From: sam at email-scan.com (Sam)
Date: Wed, 21 Sep 2005 18:23:33 -0500
Subject: Threading, real or simulated?
Message-ID:
I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading
approach from pygtk's FAQ 20.6 - invoking "gtk.gdk.threads_init()", and
wrapping all gtk/gdk function calls with
gtk.threads_enter()/gtk.threads_leave()
I start a thread, via thread.Threading.start(). The thread then calls a
particularly time consuming C function, from an extension module. I find
that when the thread is running the C code, the GUI hangs even though I'm
not inside the threads_enter/threads_leave territory.
It looks like thread.Threading() only simulates threading, by having the
python interpreter multiplex between running threads. Is real threading
possible, so that I do something time-consuming in the thread, without
hanging the GUI?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL:
From jpopl at interia.pl Thu Sep 8 05:04:30 2005
From: jpopl at interia.pl (=?ISO-8859-2?Q?Jacek_Pop=B3awski?=)
Date: Thu, 08 Sep 2005 11:04:30 +0200
Subject: popen in thread on QNX
Message-ID:
I am still in the process of creating my script which will run command
received from socket.
My scripts works perfectly on Linux, but doesn't work on QNX!
File "/usr/lib/python2.4/popen2.py", line 108, in __init__
self.pid = os.fork()
OSError: [Errno 89] Function not implemented
When I try to use os.popen3 - it works. But when I try to use it in new
thread - I see that error message.
Do you see any solution?
This script must work on QNX, command must be on thread, because I need
to stop it after timeout. I need popen to see stdout and stderr.
Any ideas?
From rodwellm at REMOVEME.gmail.com Tue Sep 13 01:21:59 2005
From: rodwellm at REMOVEME.gmail.com (Rod W)
Date: Tue, 13 Sep 2005 05:21:59 GMT
Subject: PyGTK or wXPython?
Message-ID:
I'm just starting out on Python but my primary goal is to provide
applications with some user interface (GUI).
Can someone point me to a good comparison of whether I should use
wxPython (with wxGlade I assume) or PyGTK (with Glade I assume)?
I'd prefer open source (not necessarily GPL though) tools.
Rod
From ml.sven at subscience.de Mon Sep 12 14:14:18 2005
From: ml.sven at subscience.de (sven)
Date: Mon, 12 Sep 2005 20:14:18 +0200
Subject: defining __repr__
In-Reply-To: <1126546229.628365.242310@g49g2000cwa.googlegroups.com>
References: <3olkhcF6g6vaU1@individual.net>
<1126546229.628365.242310@g49g2000cwa.googlegroups.com>
Message-ID: <6.2.3.4.2.20050912200323.02800f68@post.strato.de>
hi list,
i'd like to define __repr__ in a class to return the standardrepr
a la "<__main__.A instance at 0x015B3DA0>"
plus additional information.
how would i have to do that?
how to get the standardrepr after i've defined __repr__?
sven.
From steve at REMOVETHIScyber.com.au Wed Sep 14 11:26:54 2005
From: steve at REMOVETHIScyber.com.au (Steven D'Aprano)
Date: Thu, 15 Sep 2005 01:26:54 +1000
Subject: Removing duplicates from a list
References: <1126697915.879705.300450@g44g2000cwa.googlegroups.com>
<4328178b$0$21147$db0fefd9@news.zen.co.uk>
Message-ID:
On Wed, 14 Sep 2005 13:28:58 +0100, Will McGugan wrote:
> Rubinho wrote:
>> I can't imagine one being much faster than the other except in the case
>> of a huge list and mine's going to typically have less than 1000
>> elements.
>
> I would imagine that 2 would be significantly faster.
Don't imagine, measure.
Resist the temptation to guess. Write some test functions and time the two
different methods. But first test that the functions do what you expect:
there is no point having a blindingly fast bug.
> Method 1 uses
> 'count' which must make a pass through every element of the list, which
> would be slower than the efficient hashing that set does.
But count passes through the list in C and is also very fast. Is that
faster or slower than the hashing code used by sets? I don't know, and
I'll bet you don't either.
--
Steven.
From g.franzkowiak at onlinehome.de Thu Sep 29 15:58:30 2005
From: g.franzkowiak at onlinehome.de (g.franzkowiak)
Date: Thu, 29 Sep 2005 21:58:30 +0200
Subject: PyWin SendMessage
In-Reply-To:
References: <7jczvrb5.fsf@python.net>
Message-ID:
Thomas Heller schrieb:
> "g.franzkowiak" writes:
>
>
>>Thomas Heller schrieb:
>>
>>>"g.franzkowiak" writes:
>>>
>>>
>>>
>>>>Hello everybody,
>>>>
>>>>I've tryed to use an interprocess communication via
>>>>SendMessage on Windows.
>>>>Unfortunately, nothing goes on
>>>>
>>>>#########################################################################
>>>>#! /usr/bin/env python
>>>>
>>>>import win32api, win32ui, win32con
>>>>import struct, array
>>>>
>>>>"""
>>>>typedef struct tagCOPYDATASTRUCT { // cds
>>>> DWORD dwData;
>>>> DWORD cbData;
>>>> PVOID lpData;
>>>>} COPYDATASTRUCT;
>>>>"""
>>>>
>>>>def packCopyData(nNum, sString):
>>>> int_buffer = array.array("L",[nNum])
>>>> char_buffer = array.array('c', sString)
>>>> int_buffer_address = int_buffer.buffer_info()[0]
>>>> char_buffer_address = char_buffer.buffer_info()[0]
>>>> char_buffer_size = char_buffer.buffer_info()[1]
>>>> copy_struct = struct.pack("pLp", # dword*, dword, char*
>>>> int_buffer_address,
>>>> char_buffer_size,
>>>> char_buffer)
>>>> return copy_struct
>>>
>>>
>>>After packCopyData(...) returns, the arrays are destroyed, which will
>>>probably void their contents. You must keep them alive until you don't
>>>need the COPYDATASTRUCT instance any longer. For this kind of stuff,
>>>ctypes may be easier to use than pywin32.
>>>
>>>Thomas
>>
>>Hmm, have read something in <>
>>and the script changed to this:
>>
>>#---------------------------------------------------------
>>#! /usr/bin/env python
>>
>>import win32api, win32ui, win32con, win32gui
>>import struct, array
>>from ctypes import *
>>
>>"""
>>typedef struct tagCOPYDATASTRUCT { // cds
>> DWORD dwData;
>> DWORD cbData;
>> PVOID lpData;
>>} COPYDATASTRUCT;
>>"""
>>
>>class COPYDATATYPE(Structure):
>> _fields_ = [("nNum", c_ulong),
>> ("szData", c_char_p)]
>>
>>class COPYDATASTRUCT(Structure):
>> _fields_ = [("dwData", c_ulong),
>> ("cbData", c_ulong),
>> ("lpData", POINTER(COPYDATATYPE))]
>>
>># get the window handle
>>hwnd = win32ui.FindWindow(None, "target window")
>>
>># print just for fun
>># ##print hwnd
>>
>># prepare copydata structure for sending data
>>cpyData = COPYDATATYPE(1, '1')
>>cds = COPYDATASTRUCT(c_ulong(1),
>> c_ulong(sizeof(cpyData)),
>> pointer(cpyData))
>>
>># try to send a message
>>win32api.SendMessage(hwnd,
>> win32con.WM_COPYDATA,
>> 0,
>> pointer(cds))
>>
>>#---------------------------------------------------------
>>and the message for the last line is:
>>==> TypeError: an integer is required"
>>
>>This message comes with "pointer(cds)" and with "addressof(cds)"
>
>
> That error refers to the first argument - win32ui.FindWindow returns a
> PyCWnd object, which is not accepted by win32api.SendMessage.
> Changing this brings you one step further. win32api.SendMessage accepts
> an integer for the last element, so addressof(cds) should work now.
>
> win32gui.SendMessage is more tolerant in what it accepts as 4th
> argument, according to the error message you get when you try it it
> expects a string, a buffer, or an integer. So you could use addressof()
> or pointer(), what you like best.
>
> Thomas
Super, operates :-))
My last answer must be in the Nirvana, strange ?
Ok, only the version with 'addressof' generates a message and I must
play with the data types. The receiver becomes a wrong data formate.
Expect (int=1, char[256]='1\00'), but the int is 0x31 and the string
somewhat. Must play with my data.
Thanks
gerd
From mwm at mired.org Thu Sep 8 01:54:57 2005
From: mwm at mired.org (Mike Meyer)
Date: Thu, 08 Sep 2005 01:54:57 -0400
Subject: Manging multiple Python installation
References:
<-YydnR5-VKJlPILeRVn-sw@comcast.com>
Message-ID: <86vf1ct87i.fsf@bhuda.mired.org>
Andy Leszczynski writes:
> Robert Kern wrote:
>> Andy Leszczynski wrote:
>>
>>>Jeremy Jones wrote:
>>>
>>>
>>>>Andy Leszczynski wrote:
>>>>
>>>>Download the source, untar, cd to the new directory, run:
>>>>
>>>>./configure --prefix=/opt/mypython
>>>>make
>>>>make install
>>>
>>>Is there any way to pass the prefix to the "make install"?
>> Is passing it to the configure script a problem?
>
> not really but seems to be a bit illogical to me that the build (set
> of executables and libraries) depends on the destination installation
> path.
It's not clear that the build depends on the destination. The
install does, though. The Makefile does the install, so it needs the
prefix. config builds the makefile, so it also needs the prefix.
> Under M$ Windows I was able to install Python in let's say C:\Program
> Files\python and then move/copy it frelly to whatever location I
> need. Only thing was the resetting PATH to the new location. I miss
> that under Linux.
Are you sure it doesn't work well enough for you to use on Linux? A
quick grep on the python binary and library files reveal that only
pydoc knows the prefix - and that points to files that don't exist on
my system. That leaves five things to worry about: unix avoids making
the user muck with the path by installing the binary in the path, so
you have to move the binaries and the libraries separately. The pydoc
executable uses the path to the python binary in it's #! line. If you
use the shared binary, you may have to muck with the load library
state information (not sure what to use to do this on your
Linux). Third party libraries may break. Oh yeah - tracebacks on .pyc
and .pyo files may be confused because the source files aren't where
they where when the file was generated, but that should be the same
as it is on Windows.
http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
From rkern at ucsd.edu Wed Sep 28 05:16:51 2005
From: rkern at ucsd.edu (Robert Kern)
Date: Wed, 28 Sep 2005 02:16:51 -0700
Subject: Human readable number formatting
In-Reply-To: <7xirwlbnvw.fsf@ruckus.brouhaha.com>
References: <1127862406.11827.2.camel@localhost.localdomain> <1127895464.345142.171030@g43g2000cwa.googlegroups.com>
<7xirwlbnvw.fsf@ruckus.brouhaha.com>
Message-ID:
Paul Rubin wrote:
> "MrJean1" writes:
>
>> Ocha O + 54 - o otro
>> Nena N + 57 - nk nekto
>> MInga MI + 60 - mk mikto
>> Luma L + 63 - l lunto
>
> Please tell me you're making this up.
No, but someone else is.
http://jimvb.home.mindspring.com/unitsystem.htm
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
From n00m at narod.ru Fri Sep 2 05:12:33 2005
From: n00m at narod.ru (n00m)
Date: 2 Sep 2005 02:12:33 -0700
Subject: Code run from IDLE but not via double-clicking on its *.py
In-Reply-To:
References:
<1125478316.530781.315540@g44g2000cwa.googlegroups.com>
<1125490472.670850.247240@g49g2000cwa.googlegroups.com>
<1125509322.964828.27510@o13g2000cwo.googlegroups.com>
<1125579678.705228.172970@f14g2000cwb.googlegroups.com>
<1125592608.894215.186670@g43g2000cwa.googlegroups.com>
Message-ID: <1125652353.850367.198180@g43g2000cwa.googlegroups.com>
LOL... seems it disappears only in Win98. In Win2k it goes like this:
C:\>d:
D:\>python23\python d:\python23\socket6.py
D:\>
> C:\> d:
> D:\> cd \python23
> D:\> python d:\python23\socket6.py > out.txt 2> err.txt
> Does anything appear in d:\python23\out.txt or d:\python23\err.txt?
NOTHING APPEARED IN THEM.
> n00m, can you post the vbs?
Set cn = CreateObject("ADODB.Connection")
cn.Open _
"Provider=sqloledb;Data Source=192.168.0.3,1434;" & _
"Network Library=DBMSSOCN;Initial Catalog=pubs;" & _
"User ID=qwe;Password=asdasd;"
cn.Execute "select top 1 * from authors;"
cn.Close
Set cn = Nothing
From gandalf at designaproduct.biz Tue Sep 27 08:19:22 2005
From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy)
Date: Tue, 27 Sep 2005 14:19:22 +0200
Subject: @staticmethod, backward compatibility?
In-Reply-To:
References:
Message-ID: <433938CA.3040305@designaproduct.biz>
Neal Becker wrote:
>How can I write code to take advantage of new decorator syntax, while
>allowing backward compatibility?
>
>I almost want a preprocessor.
>
>#if PYTHON_VERSION >= 2.4
>@staticmethod
>...
>
>
>Since python < 2.4 will just choke on @staticmethod, how can I do this?
>
>
Decorators are there because
class MyClass:
@staticmethod
def my_method(arg1, arg2, ...):
whatever
is nicer than
class MyClass:
def my_method(arg1, arg2, ...):
whatever
my_method = staticmethod(my_method)
I'm affraid, if you need to be 2.3 compatible then you need to use the
later form.
Les
From NutJob at gmx.net Thu Sep 1 04:43:31 2005
From: NutJob at gmx.net (NutJob at gmx.net)
Date: 1 Sep 2005 01:43:31 -0700
Subject: Well, Python is hard to learn...
In-Reply-To:
References:
Message-ID: <1125564211.750923.189790@g14g2000cwa.googlegroups.com>
Well, I reckon it all depends on how much experience you have with
programming languages in general. If you're completely new to
programming it's probably going to take a while to get to grips with it
all, regardless of which language you're picking up, although I'd wager
that Python is still one of the most intuitive and easiest to learn
languages around. Personally I learnt to code in C++ Python, and Perl
with a little bit of Java, Tcl and C# thrown in there as well and I
like Python and C++ the most.
Just be patient, mate, you'll get the hang of it before long.
From skip at pobox.com Wed Sep 7 23:32:28 2005
From: skip at pobox.com (skip at pobox.com)
Date: Wed, 7 Sep 2005 22:32:28 -0500
Subject: improvements for the logging package
In-Reply-To: <20050907171420.GB31649@ActiveState.com>
References: <1125935246.425351.260880@z14g2000cwz.googlegroups.com>
<20050906172418.GL4377@ActiveState.com>
<17182.22978.718108.100126@montanaro.dyndns.org>
<20050907171420.GB31649@ActiveState.com>
Message-ID: <17183.45260.647117.513372@montanaro.dyndns.org>
>> - It's a package, but contrary to any other package I've ever seen,
>> most of its functionality is implemented in __init__.py.
Trent> I'm not defending the implementation, but does this cause any
Trent> particular problems?
No, it just seems symptomatic of some potential organizational problems.
>> import logging
>> logging.info('hello world')
>>
>> ought to just work (implicitly add a stream handler connected to
>> stderr to the root logger).
Trent> Maybe. Unless that causes troubles for real use.
Maybe there's a bug then (or maybe the docs still need work). When I
executed (all of these examples were typed at an interactive prompt):
import logging
logging.info('hello world')
I get no output. Looking at the doc for the basicConfig() function, I see:
The functions debug(), info(), warning(), error() and critical() will
call basicConfig() automatically if no handlers are defined for the root
logger.
If I read that right, my "hello world" example ought to work. I tried:
import logging
logging.getLogger("main")
logging.info("hello world")
and
import logging
logging.basicConfig()
logging.info("hello world")
and
import logging
logging.basicConfig()
log = logging.getLogger("main")
log.info("hello world")
Shouldn't one of these have emitted a "hello world" to stderr? (Maybe not.
Maybe I need to explicitly add handlers to non-root loggers.)
Trent> Having lazy configuration like this means that it can be a subtle
Trent> thing for top-level application code to setup the proper logging
Trent> configuration.
Again, based on my reading of the basicConfig doc, it seems like the logging
package is supposed to already do that.
Trent> I think the usability of the logging module could be much
Trent> improved with a nicer introduction to it (i.e. docs). It's not
Trent> really a "hello world" type of tool. Its usefulness only really
Trent> shows in larger use cases.
I agree about the docs. Whatever the "hello world" example is (I clearly
haven't figured it out yet), it ought to be right at the top of the docs.
If logging isn't trivial to use, then many simple apps won't use logging.
Consequently, when they grow, logging has to be retrofitted.
>> - Its functionality is partitioned in sometimes odd ways. For
>> example, it has a handlers module, but what I presume would be the
>> most commonly used handler (StreamHandler) is not defined there.
>>
>> - It doesn't use PEP 8 style as far as naming is concerned, instead
>> doing some sort of Java or C++ or Perl camelCase thing.
Trent> Perhaps Vijay (who did all the implementation) can comment on
Trent> these. Unfortunately backwards-compat might restrict some
Trent> cleanups to the package, but perhaps not too much. I did a poor
Trent> job of keeping up with the package after I laid out an initial
Trent> design, er copied an initial design from Java's log4j package
Trent> (and I'm not even a Java guy). :(
It was probably the log4j roots that provided the non-PEP 8 naming. I
suspect the naming could be improved while providing backward compatibility
aliases and deprecating those names.
From nospam at jollans.com Thu Sep 15 15:39:46 2005
From: nospam at jollans.com (Thomas Jollans)
Date: Thu, 15 Sep 2005 21:39:46 +0200
Subject: IDE, widget library
Message-ID:
I guess questions like this come all the time here ... well:
I a looking for a python IDE for gnu/linux that :
- has decent sytax highlighting (based on scintilla would be neat)
- has basic name completition, at least for system-wide modules
- has an integrated debugger
- is open source, or at least free of charge
an integrated GUI designer would of course be cool, but cannot be
counted as a requirement.
With that I come to the second question:
What cross-platform GUI libraries are there ? cross-platform meaning
functional and free on (at least) X11 and Win32
PyQT obviously doesn't count because qt3 is not free on windows.
Tk is ugly. (how well) is Tile supported with python ?
does PyGTK/Glade work on win32 ?
From grante at visi.com Fri Sep 16 16:03:49 2005
From: grante at visi.com (Grant Edwards)
Date: Fri, 16 Sep 2005 20:03:49 -0000
Subject: 2.3 -> 2.4: long int too large to convert to int
References: <11ijsh0h2dec0ed@corp.supernews.com>
<11ilnab5b5vsue0@corp.supernews.com>
Message-ID: <11im995j4dcd72@corp.supernews.com>
On 2005-09-16, Terry Reedy wrote:
>> One of the nasty bits in a pure-python approach is that there's
>> no way to write a literal with a fixed length. For example,
>> instead of writing 0xf7 to get an 8-bit value and 0x12345789 to
>> get a 32-bit value, you have to instantiate a class like
>> Word8(0xf7) and Word32(0x12345678).
>>
>> That starts to make things pretty hard to read.
>
> This is no worse than having to write decimal(.53489384) or
> whatever to get a decimal float rather than a binary float, or
> indeed, than writing cname(init_data) to get an instance of
> all types/classes. There are many more possible classes than
> sensible literal formats. A few basic and general types have
> been blessed with literals that translate into inplicit type
> constructor calls. Indeed, some literals seem necessary to
> start the object construction process. However, most types
> and classes, including your particular special-use classes, do
> not have corresponding literals and never will in the general
> release.
Oh, I realize that. I was just fantasizing about features that
would make it easier to write the narrow set of applications
that I tend to write. I didn't mean that I thought the need
was widespread enough to seriously consider adding it to the
language.
--
Grant Edwards grante Yow! I'd like MY data-base
at JULIENNED and stir-fried!
visi.com
From peter at engcorp.com Fri Sep 23 08:22:37 2005
From: peter at engcorp.com (Peter Hansen)
Date: Fri, 23 Sep 2005 08:22:37 -0400
Subject: File processing
In-Reply-To: <1127477266.452792.150450@z14g2000cwz.googlegroups.com>
References: <1127477266.452792.150450@z14g2000cwz.googlegroups.com>
Message-ID: <0r6dnTXXqccRbq7eRVn-iQ@powergate.ca>
Gopal wrote:
> Hello,
>
> I'm Gopal. I'm looking for a solution to the following problem:
>
> I need to create a text file config.txt having some parameters. I'm
> thinking of going with this format by having "Param Name - value". Note
> that the value is a string/number; something like this:
>
> PROJECT_ID = "E4208506"
> SW_VERSION = "18d"
> HW_VERSION = "2"
>
> In my script, I need to parse this config file and extract the Values
> of the parameters.
>
> I'm very new to python as you can understand from the problem. However,
> I've some project dealines. So I need your help in arriving at a simple
> and ready-made solution.
Luckily, you're already done! Just make sure the above file has a .py
extension, say maybe "config.py", and then in code where you need to
"parse" it and extract the values you can just do this:
import config
print 'Project Id is', config.PROJECT_ID
-Peter
From jgrahn-nntq at algonet.se Tue Sep 6 13:56:37 2005
From: jgrahn-nntq at algonet.se (Jorgen Grahn)
Date: 6 Sep 2005 17:56:37 GMT
Subject: execute commands independantly
References: <1126012345.854708.314210@g14g2000cwa.googlegroups.com>
<1126015149.066715.107340@f14g2000cwb.googlegroups.com>
<1126019232.931087.23800@g43g2000cwa.googlegroups.com>
Message-ID:
On 6 Sep 2005 08:07:12 -0700, Eric McGraw wrote:
>
> If you want it to return when the program is finished then use
> os.system('app') but if you just want to start it and return right
> away, use os.startfile('app')
That one is Windows-only, though -- at least in 2.3 where I live. The
os.spawn* family of calls are more portable, but I'm not sure it's a good
idea to just spawn-and-forget a process.
/Jorgen
--
// Jorgen Grahn R'lyeh wgah'nagl fhtagn!
From rrr at ronadam.com Wed Sep 7 13:12:30 2005
From: rrr at ronadam.com (Ron Adam)
Date: Wed, 07 Sep 2005 17:12:30 GMT
Subject: Possible improvement to slice opperations.
In-Reply-To: <431e28c8.794365627@news.oz.net>
References: <0BZSe.13427$xl6.12703@tornado.tampabay.rr.com>
<9eeTe.14166$xl6.13552@tornado.tampabay.rr.com>
<431e28c8.794365627@news.oz.net>
Message-ID: <2cFTe.14786$p_1.473@tornado.tampabay.rr.com>
Bengt Richter wrote:
> Then the question is, do we need sugar for reversed(x.[a:b])
> or list(reversed(x.[a:b])) for the right hand side of a statement,
> and do we want to to use both kinds of intervals in slice assignment?
> (maybe and yes ;-)
Yes, I think this is the better way to do it, as this address's the
underlying causes instead of treating the symptoms.
> The reason for yes is that it solves the which-gap problem in assigning to [a:a]
> if you define [a, a) as an empty interval to the left of a and (a, a] as an empty
> interval to the right of a, sort of like +0 and -0 in half-open intervals ;-)
> Replacing the empty interval does the insertion on the side you want ;-)
>
> I am choosing the convention to stay compatible with python's current behaviour,
> even though I'm not sure what the math world says about a different-in-some-sense intervals. I guess the intervals as point sets are the same,
> but the interval definitions are different...
Not sure either. I think intervals is an important concept and enabling
python to work with them would be good if it could be done in a simple
and consistent way. This extends a lot further than just slice
operations because of the relationship between ...
for x in range() -> slice(range)
So defining an interval object that can be used as an iterator in a for
loop might be the beginning, and then finally slice with an alternate
syntax to an abbreviated form. So then you would have the relationship
of...
for x in interval() -> slice(interval)
> Other than the a:a distinction, in terms of integers and UIAM
> .[a:b]
> is just sugar for
> [a+1:b+1]
> but the sugar is nice, and the slice assignment to either side is nicer.
Wouldn't that be [a:b+1] ?
As sugar the index's are translated at compile time, it may run into the
current edge case indexing problems. So it will most likely need to be
an actual interval object, with an alternative syntax to use it.
> I'll deal with the subsetting another time ...
No hurry, this isn't a hack it out because "the boss wants it on his
desk Monday" situation. ;-)
> Regards,
> Bengt Richter
Cheers,
Ron
From tjreedy at udel.edu Sat Sep 3 17:37:52 2005
From: tjreedy at udel.edu (Terry Reedy)
Date: Sat, 3 Sep 2005 17:37:52 -0400
Subject: Submitting doc bug reports without SF registration
Message-ID:
In response to posts about the overhead of registering as SourceForge to
submit quick doc typo/bug reports, I sent an email to docs AT python.org
(== Fred Drake) about submitting via that address instead.
He responded that he really does not want specific action items sent there
because such email only goes to him and can get lost or not read for
awhile. Tracker reports, on the other hand, give immediate feedback of
reception and are immediately readable and possibly acted on by anyone who
reviews tracker items. Indeed, fixes sometimes happen within a day or two.
On the other hand, he can see that registration could be just enough
barrier to stop someone and does not want that either. He knows that the
docs 'need more attention and fresh eyes!' So he suggested two
possibilities:
1. A DocImprovement wiki. People could optionally sign up for update
reports on specific wiki pages.
2. A new SF tracker, only for doc bugs, that would accept anonymous
submissions. The other trackers require login because most items need
additional feedback from requestors. But reports like "On page x.y.x,
'seperate' should be 'separate'" do not require feedback unless the
requestor wants the 'fixed, thank you' comment emailed.
As an item reviewer, I prefer the second, but we are both curious as to the
preference of potential no-login reporters.
Terry J. Reedy
From news at NOwillmcguganSPAM.com Fri Sep 16 10:53:39 2005
From: news at NOwillmcguganSPAM.com (Will McGugan)
Date: Fri, 16 Sep 2005 15:53:39 +0100
Subject: Creating Pie Chart from Python
In-Reply-To:
References: <1126797017.338319.215400@z14g2000cwz.googlegroups.com>
<432990f9$0$21365$db0fefd9@news.zen.co.uk>
Message-ID: <432adc74$0$14348$db0fefd9@news.zen.co.uk>
Markus Weihs wrote:
> Hi!
>
> I tried your script and got the following error:
>
> Traceback (most recent call last):
> File "pie_chart.py", line 302, in OnPaint
> self.OnDraw()
> File "pie_chart.py", line 336, in OnDraw
> segment.Draw(self.angle, self.rot, self.explode)
> File "pie_chart.py", line 46, in Draw
> glPopMatrix()
> OpenGL.GL.GLerror: [Errno 1281] invalid value
>
> What am I doing wrong?
I'm not sure. Thats a strange place for it to fail. Do you have the
latest version of pyOpenGL / wxPython?
Its only been tested on Windows, but it just uses basic OpenGL so there
is not that much to go wrong..
Will McGugan
--
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in
"jvyy*jvyyzpthtna^pbz")
From larry.bates at websafe.com Thu Sep 15 12:05:34 2005
From: larry.bates at websafe.com (Larry Bates)
Date: Thu, 15 Sep 2005 11:05:34 -0500
Subject: Python CSV writer confusion.
In-Reply-To: <1126781787.649249.301330@o13g2000cwo.googlegroups.com>
References: <1126781787.649249.301330@o13g2000cwo.googlegroups.com>
Message-ID:
The someiterable should be something that has a .next
method. That would be a list or any object with such a
method. In your case it would be the images list.
The writer method will iterate over the list and write
everything out for you. Don't put it inside a loop
yourself. More like (not tested):
import csv
.
.
.
outfile=open(r'D:\path\to\filename_sort1.csv', 'w')
CSVwriter=csv.writer(outfile, dialect='excel', delimiter='|')
CSVwriter.writerows(images)
Larry Bates
>
>
> if __name__ == '__main__':
> images = read_images(r"D:\path\to\imagespipe.csv")
>
> def get_key(*attr_names):
> def key(image):
> return [getattr(image, name) for name in attr_names]
> return key
>
> images.sort(key = get_key("filename"))
>
> t = open(r'D:\path\to\filename_sort1.csv', 'w')
>
> for image in images:
> print book
> #t.write('%s\n' % book) %Before I needed | delimited, this
> worked
> #csv.writer(t, dialect='excel', delimiter='|')
> output = csv.writer(t, dialect='excel', delimiter='|')
> output.writerows()
> #output.writerows(image)
> #output.writerow(image)
>
> t.close()
-Larry Bates
googleboy wrote:
> Hi. I am trying to write out a csv file with | instead of comma,
> because I have a field that may have many commas in it. I read in a
> csv file, sort it, and want to write it out again.
>
> I read the example that says:
>
> import csv
> writer = csv.writer(open("some.csv", "wb"))
> writer.writerows(someiterable)
>
> The "someiterable" is what is confusing me.
>
>
>
> class Image(object):
> def __init__(self, title, date, genre, data, value, filename):
> params = locals()
> del params['self']
> self.__dict__.update(params)
> def __repr__(self):
> all_items = self.__dict__.items()
> return '%s,%s,%s,%s,%s, %s' % (self.title, self.date,
> self.genre, self.data, self.value, self.filename)
>
> def read_images(filename):
> csv_file = open(filename, "rb")
> reader = csv.reader(csv_file, dialect='excel', delimiter='|')
> images = [Image(*[field.strip() for field in row]) for row in
> reader]
> csv_file.close()
> return books
>
> def sort_images(filename, *attr_names):
> csv_file = open(filename, "rb")
> reader = csv.reader(csv_file, dialect='excel', delimiter='|')
>
>
> if __name__ == '__main__':
> images = read_images(r"D:\path\to\imagespipe.csv")
>
> def get_key(*attr_names):
> def key(image):
> return [getattr(image, name) for name in attr_names]
> return key
>
> images.sort(key = get_key("filename"))
>
> t = open(r'D:\path\to\filename_sort1.csv', 'w')
>
> for image in images:
> print book
> #t.write('%s\n' % book) %Before I needed | delimited, this
> worked
> #csv.writer(t, dialect='excel', delimiter='|')
> output = csv.writer(t, dialect='excel', delimiter='|')
> output.writerows()
> #output.writerows(image)
> #output.writerow(image)
>
> t.close()
>
>
>
> This returns an error that says "Error: sequence expected"
>
> My understanding of this is that I am creating a list of lists and I am
> iterating over it (for image in images), and that image is a list, and
> is therefore iterable...?
>
> I am a bit new at this, and would greatly appreciate any assistance.
>
> TIA
>
> googleboy
>
From zanesdad at bellsouth.net Wed Sep 28 18:55:35 2005
From: zanesdad at bellsouth.net (Jeremy Jones)
Date: Wed, 28 Sep 2005 18:55:35 -0400
Subject: 1 Million users.. I can't Scale!!
In-Reply-To: <17211.6223.874504.573767@montanaro.dyndns.org>
References: <1127924360.190081.155420@g14g2000cwa.googlegroups.com> <17210.62571.387969.713030@montanaro.dyndns.org> <433B0B38.7040406@bellsouth.net>
<17211.6223.874504.573767@montanaro.dyndns.org>
Message-ID: <433B1F67.4070208@bellsouth.net>
skip at pobox.com wrote:
> Damjan> Is there some python module that provides a multi process Queue?
>
> Skip> Not as cleanly encapsulated as Queue, but writing a class that
> Skip> does that shouldn't be all that difficult using a socket and the
> Skip> pickle module.
>
> Jeremy> What about bsddb? The example code below creates a multiprocess
> Jeremy> queue.
>
>I tend to think "multiple computers" when someone says "multi-process". I
>realize that's not always the case, but I think you need to consider that
>case (it's the only practical way for a multi-process application to scale
>beyond a few processors).
>
>Skip
>
>
Doh! I'll buy that. When I hear "multi-process", I tend to think of
folks overcoming the scaling issues that accompany the GIL. This, of
course, won't scale across computers without a networking interface.
- JMJ
From fredrik at pythonware.com Wed Sep 7 04:05:01 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Wed, 7 Sep 2005 10:05:01 +0200
Subject: ~ after script filename?
References: <1126065469.212137.264680@g49g2000cwa.googlegroups.com>
<1126067512.772173.141580@g47g2000cwa.googlegroups.com>
Message-ID:
"presentt" wrote:
> Huh, no ~ on other files when I edit them, but at least I don't have to
> worry about it. Thanks Aldo.
according to
http://www.gnome.org/projects/gedit/
gedit supports backup files, so to figure out how and when they're
created, and how to control their creation, you probably just have
to read the documentation (which doesn't seem to exist on the web;
look in the "help" menu for the bundled version)
From rschroev_nospam_ml at fastmail.fm Fri Sep 30 07:50:48 2005
From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven)
Date: Fri, 30 Sep 2005 11:50:48 GMT
Subject: Help with syntax warnings
In-Reply-To:
References:
Message-ID:
Ivan Shevanski schreef:
> Here's a noob question for everyone (I'm not sure if my first message
> got through, is had a "suspicious header" so sorry for double post is
> so), is there a way to turn off syntax warnings or just make them not
> visible?
Those warnings are something I have never seen and even have never heard
about, even though I now found out there's a section in the library
reference about them. It seems you can define filters to specify what
you want to do with the warnings; you can read all about it at
http://docs.python.org/lib/module-warnings.html
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
From fredrik at pythonware.com Fri Sep 23 14:41:51 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 23 Sep 2005 20:41:51 +0200
Subject: batch mkdir using a file list
References: <1127500054.273772.112470@g14g2000cwa.googlegroups.com>
Message-ID:
DataSmash wrote
> I think I've tried everything now and can't figure out how to do it.
> I want to read in a text list from the current directory,
> and for each line in the list, make a system directory for that name.
>
> My text file would look something like this:
> 1144
> 1145
> 1146
> 1147
>
> I simply want to create these 4 directories.
> It seems like something like the following
> code should work, but it doesn't.
>
> import os
>
> file = open("list.txt", "r")
> read = file.read()
> print "Creating directory " + str(read)
> os.mkdir(str(read))
read() returns *all* text in the file as a single string, but you
really want to process each line for itself. try this:
for name in open("list.txt"):
name = name.strip() # get rid of extra whitespace
os.mkdir(name)
From mwm at mired.org Thu Sep 22 11:42:28 2005
From: mwm at mired.org (Mike Meyer)
Date: Thu, 22 Sep 2005 11:42:28 -0400
Subject: Open PDF
References: <36141C39871E4D4DAE92F79D1838543601B176C8@itcnt14.itc.nl>
Message-ID: <8664sthzx7.fsf@bhuda.mired.org>
Dan writes:
> Under Linux you can probably use xpdf or gpdf:
>
> os.system("xpdf /path/to/file.pdf")
>
> Note that you should check the return code of "system" to see if the
> execution was successful. For example, the user might not have xpdf
> installed.
This is the problem that the "open" package was designed to
solve. The API for Python apps is still under development, but if you
do 'os.system("open /path/to/file.pdf")', open will use the users
preferred pdf viewer, and interact with the user to select one if they
don't have a prefernce on record.
http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
From xah at xahlee.org Thu Sep 1 04:56:03 2005
From: xah at xahlee.org (Xah Lee)
Date: 1 Sep 2005 01:56:03 -0700
Subject: OpenSource documentation problems
In-Reply-To:
References:
<43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net>
<200508312026.04152.hancock@anansispaceworks.com>
Message-ID: <1125564963.289130.307560@o13g2000cwo.googlegroups.com>
By the way, i have sent my criticisms to the proper python doc
maintainer or mailing list several months ago.
-------------
i'm very sorry to say, that the Python doc is one of the worst possible
in the industry. I'm very sick of Perl and its intentional obfuscation
and juvenile drivel style of its docs. I always wanted to learn Python
as a replacement of Perl, and this year i did. I thought Python is much
better. But now i know, that although the language is better, but its
documentation is effectively worse than Perl's.
The Perl docs, although lousy in the outset because its people immerse
in drivel. It is part of their unix culture. Nevertheless, one thing
Perl doc is not, is that it in particular do not presume a superficial
Computer Science stance. In fact, its culture sneer computer science
establishment. (which i caused major harm in the industry) There are
quite a lot things wrong with Perl docs. But at least it is not shy to
use examples, lots of them.
Now, i have thought that Python doc is entirely different. The Python
community in many ways are antithesis of Perl community. Python doesn't
start with a hacking mentality, and i presume it to have a community
who care about correctness and quality. Unfortunately, as i now know,
its doc is the worst and almost useless piece of shit. Several problems
lies at the core:
* its technical writing is extremely poor.
* its technical content clearly shows that the writers can't or didn't
think clearly. (one confused ball)
* its organization exhibits the worst abstruse insensibilities of tech
geekers.
------------
as i have expressed before (see
http://xahlee.org/Periodic_dosage_dir/t2/xlali_skami_cukta.html
), the python doc has huge number of problems. To remedy them, it needs
major overhaul if not complete rewrite.
Just about the only worthwhile part of the official doc set is the
Tutorial section. The ?Language Reference? section, Library
Reference, and The Global Module Index are totally crap and need to be
deleted entirely. (i haven't read much of the other sections, but i
don't assume they are much better)
-------------
I would like to see the Python doc gets a complete rewrite.
First of all, the doc system LaTex needs to go. (TeX itself is a
OpenSource crime, see this unedited rant
http://xahlee.org/Periodic_dosage_dir/t2/TeX_pestilence.html
)
Then, the doc needs to be written with a few principles.
* to communicate to programers how to use it. (as opposed to being a
compiling specification or inline with some computer sciency model)
* write with the goal of effective communication. In the writing, avoid
big Engish words, long sentences, and focus on precision. In content,
avoid philosophical outlook, jargon population, author masturbation,
arcane technicalities, gratuitous cautions, geek tips, juvenile
coolness ... etc.)
* document with consideration of tasks to be performed.
* document orient with the language's exhibited functionalities,
concrete behaviors. (as opposed to in some milieu of software
engineering methodology)
* give ample examples.
(for detail, study several of my Python criticisms from the link
mentioned above)
--------------
I have not been in the Python community long and have not delved into
it. Is there other documentation that can be a basis of a new python
doc? The one i know is the Quick Reference by Richard Gruet. However,
it is just a Quick Reference but can be a basis if we lack anything
else.
Also, i have happened to read the O'Reilly Python book years ago. That
book is crap. I have also read parts of the Python Cookbook. Probably
half of this book is also crap.
Of course, the other major hurdle in progress (for a new doc) is a
political one. It is, alas, always the biggest problem.
-----------
the python doc wiki given at
http://pydoc.amk.ca/frame.html
is a great idea. For this to work, there are two things needs to be
done, both are equally important:
1. for the official python site Python.org to point to the wiki as THE
official python doc.
2. given a authoritarian guide in the wiki on how to write the doc.
(the guide based on the principles i gave above. Of course, it needs to
be clarified and elaborated with many cases in point.)
Without (1), the wiki will never be prominent. Without (2), it will
remain a geek drivel. (in this respect, similar to how wikipedia's
texts drift into a form of academic esoterica whose educational value
are greatly reduced to the general public.)
--------
this post is archived at
http://xahlee.org/UnixResource_dir/writ/python_doc.html
Xah
xah at xahlee.org
? http://xahlee.org/
From vimakefile at yahoo.com Tue Sep 27 11:50:36 2005
From: vimakefile at yahoo.com (Mike)
Date: Tue, 27 Sep 2005 08:50:36 -0700
Subject: Telephony project
References: <1127758835.527555.217870@g47g2000cwa.googlegroups.com>
<7x64snbr0l.fsf@ruckus.brouhaha.com>
<1127816655.712927.289850@g14g2000cwa.googlegroups.com>
Message-ID:
I was able to do something like this in Python a while back. You'll need one
of:
(a) A telephone line dialer/monitor & DTMF I/O board that works through the
serial port, and a phone audio tap that mixes the soundcard I/O to the phone
(b) A TAPI-compliant modem that does everything you need
(c) A digital POTS phone that is controllable through serial, USB or your
LAN, or a TAPI interface.
(d) VOIP software and service than uses SIP, etc. (I found this I found
this:
http://softphones.globaliptel.com/(c50kru45yksjek55xr2b5g45)/_Pages/NoFrames/PageBuilder.aspx?content=4214134c0c4f416982e844bcd86b2955,
but am in no way endorsing it. Also check out http://www.sipfoundry.org/)
I used method (a) -- (b) tends to be a pain (as most OEM TAPI modems have
some fatal flaw or three...) and (c/d) may be more possible now that before.
I used voice reco on the input side rather then DTMF, but I was doing it
from local phone exensions on the same loop, not for outside calls, and not
for the elderly, so DTMF is probably better anyway. (If you need to know the
exact hardware I used, I can find out.)
The other option is to not have your own hardware at all and use a
service -- there are companies provide web services that let you
write/generate markup (VoiceXML or other) to make the calls, wait for DTMF
or voice input, etc. (Though I had trouble Googling one at the moment -
there were more a few years ago...)
m
"Roger" wrote in message
news:1127816655.712927.289850 at g14g2000cwa.googlegroups.com...
> "CheckOn" is the working name for my project. Our church
> community has many elderly who are at home but close to assisted living
> placements. Many do not have family and rely on volunteer caretakers
> and lunch providers for their socialization. We are trying to make
> phone contact with these members to check on their needs, wellbeing,
> and ability to take care of themselves. In sharing that information
> with other denominations in our city, we discovered that others were
> having identical issues. The numbers are larger than we anticipated.
> Thus the project. Thanks for your interest.
>
From merman at o2online.de Fri Sep 23 04:43:45 2005
From: merman at o2online.de (TK)
Date: Fri, 23 Sep 2005 10:43:45 +0200
Subject: idle
In-Reply-To:
References: <4332a386$0$13014$9b622d9e@news.freenet.de>
Message-ID: <4333bfae$0$15069$9b622d9e@news.freenet.de>
Hi Franz,
>>is there no IDLE in Python2.4?
>
> Sure,
> on Windows:
>
> C:\Python24\Lib\idlelib\idle.pyw
> You should have a shortcuts in your StartMenu
> und Python 2.4
What about with Suse 9.3 und Python 2.4?
o-o
Thomas
From randy at psg.com Thu Sep 1 13:01:05 2005
From: randy at psg.com (Randy Bush)
Date: Thu, 1 Sep 2005 07:01:05 -1000
Subject: OpenSource documentation problems
References:
<43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net>
<200508312026.04152.hancock@anansispaceworks.com>
<1125571915.715672.178840@g44g2000cwa.googlegroups.com>
Message-ID: <17175.13265.841555.117527@roam.psg.com>
> I'm very sorry to say, that the Python doc is one of the worst possible
> in the industry.
you are entitled to a full refund
From Make More With GreenZap (Better than PayPal)get $25.00/signing up + Sat Sep 10 17:30:29 2005
From: Make More With GreenZap (Better than PayPal)get $25.00/signing up + (Make More With GreenZap (Better than PayPal)get $25.00/signing up +)
Date: 10 Sep 2005 14:30:29 -0700
Subject: Make Even More $$$$$ with! GreenZap! Get $25.00 for signing up/$5 for
thoose u refer
Message-ID: <1126387829.256507.261420@g49g2000cwa.googlegroups.com>
Make $10,000 in 30 days with GreenZap|Get Paid $25.00/signin up!
& get paid $5.00/thoose you refer!!! Pay Automated!!!
This really does work and is also totally legal and free for anyone to
join.
Sign up now for free and get $25 instantly into your new account.
Why this works
Unlike the PayPal $5 programs, this doesn't even cost you $5 to join
in, just 2 minutes of your time.
Sign up at this link
www.greenzap.com/peso4sho
$25 will be put into your account for free.
Great, you've made $25 in just 2 minutes, not a bad start.
Why not turn it into $10,000 or more in just 30 days.
Believe me that's a very realistic target.
If you're still not convinced try it for the sole reason of proving
yourself right for thinking it won't work.
But I warn you now, don't start complaining to me with all the money
you're making to why I didn't let you know about this sooner.
Here's the reason why the're doing this.
Pay Pal is their biggest competitor worth $6-8 billion dollars.
Pay Pal has between 60-80 million members. In other words, each of
those members is worth about $100 to Pay Pal.
GreenZap understands this and is willing to pay for its members in
advance.
That's where the initial $25 comes in as well as the community
rewards of anywhere from $5-30 more dollars.
This is an ingenious way to quickly build a loyal community of
GreenZap members.
But remember the're not going to give out the $25 forever.
It's only for their pre-registration campaign, so act quickly.
They are cheaper to use than PayPal too.
$1.00 per transaction fee
Compare $1.00 to PayPal's [1.9%-2.9% + $0.30] transaction fees and its
easy to see who's focusing on offering value to their community and
who's not.
Is GreenZap Really Giving Away FREE Money?
Yes. Think of it this way; at $1.00/transaction, GreenZap will
eventually get their money back once you use your GreenZap account to
transact 25 times.
How Can You Profit From The Battle Of GreenZap and PayPal?
Get started now
1. GET AN EMAIL ACCOUNT....I ASSUME YOU ALREADY HAVE ONE...
2.GO TO www.greenzap.com/peso4sho
3. SIGN UP FOR AN ACCOUNT.
IT'S TOTALLY FREE AND THEY WILL FUND YOU $25
INSTANTLY INTO YOUR ACCOUNT JUST FOR SIGNING UP.
4. TAKE THAT $25 AND USE IT AS FOLLOWS: CLICK ON THE SEND MONEY TAB.
5.ENTER THE EMAIL ADDRESS IN THE NUMBER ONE POSITION.
Here's the current list:
1. eternally at winning.com
2. jon8421r at yahoo.co.uk
3. peso4sho at yahoo.com
SEND THE $25 DOLLARS TO THE FIRST NAME WITH A NOTE SAYING "ADD ME TO
YOUR MAILING LIST".
THEN SEND AN EMAIL TO THE NUMBER THREE POSITION SAYING "THANKS I'VE
JOINED."
THIS SECTION IS IMPORTANT SINCE THIS IS WHAT
MAKES THIS LEGAL.
YOU CAN SIGN UP FROM ANYWHERE IN THE WORLD AND ONLY ONE
ACCOUNT PER PERSON CAN BE OPENED WITH THE GREENZAP SYSTEM SO NO ONE IS
ABLE TO SIGN UP FOR LOADS OF ACCOUNTS AND SEND THE $25 TO THEMSELVES.
6. COPY/ PASTE THIS LETTER INTO A WORD PROCESSOR. TAKE THE #1 EMAIL
OFF AND PUT YOUR EMAIL YOU SIGNED UP WITH INTO THE #3 POSITION.
7. LOG ON TO GOOGLE OR YAHOO AND TYPE IN MONEY MAKING MESSAGE BOARD OR
BUSINESS OPPORTUNITY... ETC. POST THE NEW COPY OF THE LETTER WITH YOUR
NAME IN THE 3 SPOT TO LOADS OF MESSAGING BOARDS. THE MORE THE BETTER.
YOU CAN ALSO EMAIL THIS LETTER TO ANYONE YOU KNOW, HOW ABOUT SENDING
IT TO THE EMAIL ADDRESSES THAT SEND YOU OFFERS. IT'S SIMPLE....THE
MORE YOU SEND OUT THE MORE MONEY YOU WILL MAKE.
AIM TO SEND IT TO AT LEAST 40 PEOPLE.
PLEASE DO NOT TRY AND CHEAT BY PUTTING YOUR EMAIL AT THE TOP BECAUSE
YOU WILL NOT MAKE A LOT OF MONEY LIKE THAT. REMEMBER YOUR EMAIL ADDRESS
WILL BE DELETED FROM THE TOP BY THE NEXT PERSON WHO RECEIVES THIS
LETTER. BY STARING AT THE BOTTOM AND BEING MOVED UP WHEN IT'S EMAILED
TO OTHERS YOUR EMAIL ADDRESS IT'S EXPOSED TO MANY THOUSANDS MORE AT
THE
TOP THAN IF YOU CHEAT.
That the response rate to this is VERY HIGH goes without saying,
really
Who else would give you $25 for free and let you use it to make
thousands of dollars. You can maybe use the money you make from this
program
to start you own business or spend this weekend down at your local
auto
showroom and test drive some cars. Have fun however you spend it!
www.greenzap.com/peso4sho
Enjoy making lots and lots and lots of money!
If you don't try it you will never know.
Good fortunes to you and yours.
Peso, success & wealth!
peso4sho at yahoo.com *PLEASE ADD ME TO YOUR GreenZap LISTS*
GZAccepted_Badge2.gif
From dan at cellectivity.com Fri Sep 16 10:28:00 2005
From: dan at cellectivity.com (Dan)
Date: Fri, 16 Sep 2005 15:28:00 +0100
Subject: strptime() doesn't recognize BST as a valid timezone
Message-ID: <1126880880.7089.21.camel@localhost.localdomain>
> I get: "ValueError: time data did not match format: ..."
I'm running Linux in London, and I don't get that error.
Python 2.3.5 (#2, May 29 2005, 00:34:43)
[GCC 3.3.6 (Debian 1:3.3.6-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> date_str = "Wed Sep 14, 2005 5:07 PM BST"
>>> format = "%a %b %d, %Y %I:%M %p %Z"
>>> time.strptime(date_str, format)
(2005, 9, 14, 17, 7, 0, 2, 257, 1)
However, when I used another timezone (I tried EST and PST), I got the
same error you did.
I really don't know enough about how Python handles dates to tell you
anything more.
--
Diplomacy is saying "nice doggy" until you find a rock.
- submitted by Nancy Greer
to the CleanStuff mailing list
From ndbecker2 at gmail.com Wed Sep 21 15:27:23 2005
From: ndbecker2 at gmail.com (Neal Becker)
Date: Wed, 21 Sep 2005 15:27:23 -0400
Subject: unusual exponential formatting puzzle
Message-ID:
Like a puzzle? I need to interface python output to some strange old
program. It wants to see numbers formatted as:
e.g.: 0.23456789E01
That is, the leading digit is always 0, instead of the first significant
digit. It is fixed width. I can almost get it with '% 16.9E', but not
quite.
My solution is to print to a string with the '% 16.9E' format, then parse it
with re to pick off the pieces and fix it up. Pretty ugly. Any better
ideas?
From steve at holdenweb.com Tue Sep 20 17:25:28 2005
From: steve at holdenweb.com (Steve Holden)
Date: Tue, 20 Sep 2005 22:25:28 +0100
Subject: are variables local only to try/except blocks?
In-Reply-To:
References:
Message-ID: <43307E48.4080001@holdenweb.com>
Barry Searle wrote:
>
> in the case of nested try/except code generation,
> your suggestion could cause a problem:
> # 1) this is fine:
> doInitialStuff # With no exceptions
> excp = 0
> try:
> doLotsHere()
> except aParticularSetOfExceptions:
> excp = 1
> if excp:
> handleException()
> doLotsMoreStuff()
>
> # 2) nested code generation has problem:
> doInitialStuff # With no exceptions
> excp = 0
> try:
>
> doMOREInitialStuff # With no exceptions
> excp = 0
> try:
> doMORELotsHere()
> except aParticularSetOfExceptions:
> excp = 1 #### this causes the problem
> if excp:
> handleException()
> doMORELotsMoreStuff()
>
> doLotsHere()
> except aParticularSetOfExceptions:
> excp = 1
> #### excp=1 from inner nested code generation
> if excp:
> handleException()
> doLotsMoreStuff()
>
> # 3) Hence I return to my planned template code generation:
> excp = 0 #### Probaly need to do ONCE, to "bind" variable ?
Yes, but I am bothered that you appear to feel there is a need to 1)
record whether an exception occurred and then 2) handle the exception
only when you have finished recording whether exceptions occurred and
under what conditions.
> doInitialStuff # With no exceptions
> try:
>
> doMOREInitialStuff # With no exceptions
In which case you might as well put the
excp =0
here.
> try:
> doMORELotsHere()
> excp = 0 ##### always reset excp as last action
That doesn't make sense to me. If an exception isn't raised then excp
will have the value it's always had, which is to say zero, so I don't
see why you feel the need for this "resetting" to take place (unless
there's a chance that doMORELotsHere() changes excp's value).
> except aParticularSetOfExceptions:
> excp = 1
> if excp:
> handleException()
> doMORELotsMoreStuff()
>
> doLotsHere()
> excp = 0 ##### always reset excp as last action
> except aParticularSetOfExceptions:
> excp = 1
> if excp: #### should be fine
> handleException()
> doLotsMoreStuff()
>
>
[previous insanities deleted]
I don't believe there isn't a simpler way to do what you appear to want
to do.
Since you are talking about machine-generated code we can agree not to
care about ugly in terms of source, but I think we should be careful no
to throw the baby out with the bath water here.
Rather than casting your question as code it may prove helpful simply to
describe the problem in English, and then see if others on the group
can't help you structure your code better.
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org
From mwm at mired.org Mon Sep 26 14:39:29 2005
From: mwm at mired.org (Mike Meyer)
Date: Mon, 26 Sep 2005 14:39:29 -0400
Subject: ncurses programming
References:
<1127754862.781184.224480@z14g2000cwz.googlegroups.com>
<874q87pw5f.fsf@wilson.rwth-aachen.de>
Message-ID: <86wtl3wu5a.fsf@bhuda.mired.org>
Torsten Bronger writes:
> Hall?chen!
>
> "ncf" writes:
>
>> [...]
>>
>> Py Docs: http://docs.python.org/lib/module-curses.html
>
> This document suggests that Python+ncurses won't work on windows.
> What's the reason for this?
Could it be that ncurses doesn't work on Windows? At least, it didn't
last time I looked. There was a curses library for Windows, but
you'll have to google for it.
http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
From keithlackey at deegroup.com Wed Sep 21 02:12:12 2005
From: keithlackey at deegroup.com (keithlackey)
Date: Wed, 21 Sep 2005 14:12:12 +0800
Subject: What am I doing wrong?
In-Reply-To:
Message-ID:
I'm relatively new to python and I've run into this problem.
DECLARING CLASS
class structure:
def __init__(self, folders = []):
self.folders = folders
def add_folder(self, folder):
self.folders.append(tuple(folder))
Now I try to make an instance of this class
structure1 = structure()
structure1.add_folder([('foo'),])
print structure1.folders
This returns: [('foo',)]
This works fine. But when I try to make another instance of that class...
structure2 = structure()
print structure2.folders
This now also returns: [('foo',)]
Even though I haven't added any folders to this new instance
What am I doing wrong?
From theller at python.net Tue Sep 6 02:23:24 2005
From: theller at python.net (Thomas Heller)
Date: Tue, 06 Sep 2005 08:23:24 +0200
Subject: py2exe 0.6.1 released
References:
<431cf3eb.715296532@news.oz.net>
Message-ID: <3boisoir.fsf@python.net>
bokr at oz.net (Bengt Richter) writes:
> On Mon, 05 Sep 2005 21:55:19 +0200, Thomas Heller wrote:
>
>> * py2exe can now bundle binary extensions and dlls into the
>> library-archive or the executable itself. This allows to
>> finally build real single-file executables.
>>
>> The bundled dlls and pyds are loaded at runtime by some special
>> code that emulates the Windows LoadLibrary function - they are
>> never unpacked to the file system.
>
> So py2exe is windows-only (like exe ;-) or is there a py2elf or
> py2coff or such?
py2exe is windows only. But, there are also (in no particular order)
PyInstaller, cx_Freeze, py2app, exemaker, freeze.
>
>>
>> This part of the code is distributed under the MPL 1.1, so this
>> license is now pulled in by py2exe.
> Mozilla?
Has nothing to do with Mozilla directly, it is just that parts of the
code are licensed under the Mozilla Public License Version 1.1.
I'm not too happy with this, but I have other things to do than to
rewrite software relased under the MPL just to release it under a more
liberal license (although I have considered that, and I certainly would
not reject a contribution ;-).
Thomas
From gg63551 at hotmail.com Sun Sep 4 01:29:43 2005
From: gg63551 at hotmail.com (gerald gillespie)
Date: Sun, 04 Sep 2005 00:29:43 -0500
Subject: gmail access
Message-ID:
how do I access my new Gmail account gg63551 at hotmail.com
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
From rbt at athop1.ath.vt.edu Tue Sep 20 10:50:50 2005
From: rbt at athop1.ath.vt.edu (rbt)
Date: Tue, 20 Sep 2005 10:50:50 -0400
Subject: win32 service and time.sleep()
In-Reply-To: <1126711859.13054.8.camel@athop1.ath.vt.edu>
References:
<86zmqgxrps.fsf@bhuda.mired.org>
<1126711859.13054.8.camel@athop1.ath.vt.edu>
Message-ID: <1127227850.11591.14.camel@athop1.ath.vt.edu>
I have a win32 service written in Python. It works well. It sends a
report of the status of the machine via email periodically. The one
problem I have is this... while trying to send an email, the script
loops until a send happens and then it breaks. Should it be unable to
send, it sleeps for 10 minutes with time.sleep(600) and then wakes and
tries again. This is when the problem occurs. I can't stop the service
while the program is sleeping. When I try, it just hangs until a reboot.
Can some suggest how to fix this?
Thanks,
rbt
From jhu at metrigenix.com Mon Sep 26 11:11:45 2005
From: jhu at metrigenix.com (James Hu)
Date: Mon, 26 Sep 2005 11:11:45 -0400
Subject: how to implement propertyPage using wxPyhton?
Message-ID: <90DEA7ED93F71A4580CEDF76A02682EA03AC91@torexch.metrigenix.com>
Hi, gurus,
I would like to implement something like propertyPage (VC++ term)
Ie. There are a few tabs in the top, clicking any tab will display a
different panel.
I searched on the Internet, couldn't get any clue.
Thanks in advance.
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From sklass at pointcircle.com Tue Sep 20 19:56:58 2005
From: sklass at pointcircle.com (rh0dium)
Date: 20 Sep 2005 16:56:58 -0700
Subject: re.search experts needed on fqdn stripping..
Message-ID: <1127260618.929425.175440@g14g2000cwa.googlegroups.com>
Hi all,
Ok I have a list
hosts = [ "poundcake.fqdn.com", "scorpion.fqdn.com", "loghost",
"scorpian", "localhost", "lan", "lan.fpdn.com" ]
Assumptions:
scorpian.fqdn.com == scorpian
lan == lan.fqdn.com
I want pear this list down based on the following:
1. ignore loghost, localhost, timehost, mailhost
2. Use the first found name used reguardless if it is the fqdn or not
So what you would get back out is this..
hosts = [ "poundcake.fqdn.com", "scorpion.fqdn.com", "lan" ]
Now here is my code - and I have a problem with the splitting. I am
really looking for a cool ( but understandable ) way to simplify this..
e =[]
for host in hosts:
sn = re.split( "\.", host)
ig = 1
ignore = [ "localhost", "loghost", "timehost", "mailhost" ]
for i in ignore:
if i == sn[0]:
ig = 0
if ig:
print "%s not ignored" % sn[0]
found = 0
for n in e:
sm = re.split( "\.", n)
print "checking %s to %s" % (sm[0], sn[0])
if sm[0] == sn[0]:
print "match";
found = 1
if found == 0:
print "appending %s " % host
e.append(host)
print e
Which kicks out..
poundcake not ignored
appending poundcake.nsc.com
scorpion not ignored
checking poundcake to scorpion
appending scorpion.nsc.com
scorpian not ignored
checking poundcake to scorpian
checking scorpion to scorpian
appending scorpian
lan not ignored
checking poundcake to lan
checking scorpion to lan
checking scorpian to lan
appending lan
['poundcake.fpdn.com', 'scorpion.fpdn.com', 'scorpian', 'lan']
Crap still wrong..
From kbk at shore.net Thu Sep 8 00:31:14 2005
From: kbk at shore.net (Kurt B. Kaiser)
Date: Thu, 8 Sep 2005 00:31:14 -0400 (EDT)
Subject: Weekly Python Patch/Bug Summary
Message-ID: <200509080431.j884VEHG028517@bayview.thirdcreek.com>
Patch / Bug Summary
___________________
Patches : 342 open ( +3) / 2923 closed ( +1) / 3265 total ( +4)
Bugs : 908 open ( +5) / 5232 closed (+10) / 6140 total (+15)
RFE : 188 open ( +1) / 185 closed ( +1) / 373 total ( +2)
New / Reopened Patches
______________________
String formatting character for str.join (2005-09-04)
CLOSED http://python.org/sf/1281573 opened by Nick Coghlan
Speed up gzip.readline (~40%) (2005-09-04)
http://python.org/sf/1281707 opened by April King
Enable SSL for smtplib (2005-09-05)
http://python.org/sf/1282340 opened by Phil Underwood
AIX port from Elemental Security (2005-09-07)
http://python.org/sf/1284289 opened by Guido van Rossum
Patches Closed
______________
String formatting character for str.join (2005-09-04)
http://python.org/sf/1281573 closed by ncoghlan
New / Reopened Bugs
___________________
time.strptime() fails with unicode date string, de_DE locale (2005-09-01)
CLOSED http://python.org/sf/1280061 opened by Adam Monsen
tokenize module does not detect inconsistent dedents (2005-06-21)
http://python.org/sf/1224621 reopened by arigo
PyDateTime_Check references static object (2005-09-02)
CLOSED http://python.org/sf/1280924 opened by Skip Montanaro
xml.sax.expatreader doesn't pass encoding to ParserCreate (2005-09-02)
http://python.org/sf/1281032 opened by Samuel Bayer
Erroneous \url command in python.sty (2005-09-03)
http://python.org/sf/1281291 opened by Rory Yorke
array.arrays are not unpickleable (2005-09-03)
CLOSED http://python.org/sf/1281383 opened by Reinhold Birkenfeld
Py_BuildValue k format units don't work with big values (2005-09-04)
http://python.org/sf/1281408 opened by Adal Chiriliuc
exception when unpickling array.array objects (2005-09-04)
http://python.org/sf/1281556 opened by John Machin
urllib violates rfc 959 (2005-09-04)
http://python.org/sf/1281692 opened by Matthias Klose
logging.shutdown() not correct for chained handlers (2005-09-05)
http://python.org/sf/1282539 opened by Fons Dijkstra
socket.getaddrinfo() bug for IPv6 enabled platforms (2005-09-06)
http://python.org/sf/1282647 opened by Ganesan Rajagopal
PyArg_ParseTupleAndKeywords gives misleading error message (2005-09-06)
http://python.org/sf/1283289 opened by japierro
nit for builtin sum doc (2005-09-07)
http://python.org/sf/1283491 opened by daishi harada
os.path.abspath() / os.chdir() buggy with unicode paths (2005-09-07)
http://python.org/sf/1283895 opened by Antoine Pitrou
re nested conditional matching (?()) doesn't work (2005-09-07)
http://python.org/sf/1284341 opened by Erik Demaine
Bugs Closed
___________
codecs.StreamRecoder.next doesn't encode (2005-07-10)
http://python.org/sf/1235646 closed by doerwalter
time.strptime() fails with unicode date string, de_DE locale (2005-09-01)
http://python.org/sf/1280061 closed by bcannon
crash recursive __getattr__ (2005-08-24)
http://python.org/sf/1267884 closed by tjreedy
Lambda and deepcopy (2005-08-31)
http://python.org/sf/1277718 closed by tjreedy
logging module broken for multiple threads? (2005-09-01)
http://python.org/sf/1277903 closed by vsajip
PyDateTime_Check references static object (2005-09-02)
http://python.org/sf/1280924 closed by montanaro
bz2module.c compiler warning (2005-08-26)
http://python.org/sf/1274069 closed by birkenfeld
discrepancy between str.__cmp__ and unicode.__cmp__ (2005-08-29)
http://python.org/sf/1275719 closed by rhettinger
array.arrays are not unpickleable (2005-09-03)
http://python.org/sf/1281383 closed by rhettinger
SyntaxError raised on win32 for correct files (2005-05-12)
http://python.org/sf/1200686 closed by tim_one
New / Reopened RFE
__________________
non-sequence map() arguments for optimization (2005-09-02)
CLOSED http://python.org/sf/1281053 opened by Ecnassianer of the Green Storm
Give __len__() advice for "don't know" (2005-09-06)
http://python.org/sf/1283110 opened by Tim Peters
RFE Closed
__________
non-sequence map() arguments for optimization (2005-09-03)
http://python.org/sf/1281053 closed by birkenfeld
From amk at amk.ca Thu Sep 1 18:54:09 2005
From: amk at amk.ca (A.M. Kuchling)
Date: Thu, 01 Sep 2005 17:54:09 -0500
Subject: OpenSource documentation problems
References:
<43164595$0$97143$ed2619ec@ptn-nntp-reader03.plus.net>
<200508312026.04152.hancock@anansispaceworks.com>
Message-ID:
On Thu, 1 Sep 2005 17:09:27 +0200,
Fredrik Lundh wrote:
> the useredit approach I'm using over at the librarybook site works
> pretty well. for example, if you go to
That looks pleasantly simple.
I don't consider the pydoc.amk.ca experiment to have been really successful.
It was a half-hour hack that's usable with some pain, but the JavaScript and
frame display needs quite a bit of polishing to be usable by a random
newbie.
There's a Firefox extension (http://www.wikalong.org/) that allows wiki
annotation, but a browser-specific annotation tool doesn't solve the general
problem.
I suspect the best solution is something Python-doc-specific that runs the
generated HTML for the docs through a preprocessor that inserts comments and
an editing form. It would be a great topic for a user group sprint or
weekend project.
(If someone volunteers to do this: if you decide to use an RDBMS, please use
PostgreSQL, because it's already installed on one of the python.org
servers.)
--amk
From sybrenUSE at YOURthirdtower.com.imagination Tue Sep 13 09:57:03 2005
From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel)
Date: Tue, 13 Sep 2005 15:57:03 +0200
Subject: Python for ARM7?
References:
Message-ID:
Ken Seehart enlightened us with:
> 1. How do I know whether to use sharprom or modern?
If it works, use it.
> 2. What do I do with ipk files? I surfed around and found that in
> one example, the command is "ipkg install foo.ipk", but ipkg doesn't
> seem to exist on my hardware.
ipkg doesn't have anything to do with your hardware. It's just a shell
script. Anyway, an ipkg file is nothing more than a tarball with a
certain content.
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
From rubbishemail at web.de Thu Sep 8 07:37:33 2005
From: rubbishemail at web.de (rubbishemail at web.de)
Date: 8 Sep 2005 04:37:33 -0700
Subject: record sound to numarray/list
Message-ID: <1126179453.007330.116070@o13g2000cwo.googlegroups.com>
Hello,
do you know any way to record a sound from the soundcard on winXP to a
numarray?
many thanks
Daniel
From cmkleffner at gmx.de Wed Sep 7 10:55:17 2005
From: cmkleffner at gmx.de (cmkl)
Date: 7 Sep 2005 07:55:17 -0700
Subject: py2exe 0.6.1 released
References:
<1126021854.581774.261940@g43g2000cwa.googlegroups.com>
Message-ID: <1126104917.246314.231250@f14g2000cwb.googlegroups.com>
I removed conditional imports from visual and after that I works like a
charm. Now I've got a VPython application within a single 3 Mbyte
exe-file (Python-2.3).
That is really cool.
Thanks
Carl
From timo.linna at gmail.com Fri Sep 9 06:04:45 2005
From: timo.linna at gmail.com (Timo)
Date: 9 Sep 2005 03:04:45 -0700
Subject: Inconsistent reaction to extend
In-Reply-To:
References:
Message-ID: <1126260285.349597.274070@f14g2000cwb.googlegroups.com>
Jerzy Karczmarczuk kirjoitti:
> On the other hand, try
>
> p=range(4).extend([1,2])
>
> Then, p HAS NO VALUE (NoneType).
>
> With append the behaviour is similar. I didn't try other methods, but
> I suspect that it won't improve.
>
>
> WHY?
range(4) returns a list and Python's list.extend() returns None. Extend
is a in-place operation.
-- timo
From xah at xahlee.org Thu Sep 8 01:07:08 2005
From: xah at xahlee.org (Xah Lee)
Date: 7 Sep 2005 22:07:08 -0700
Subject: determine if os.system() is done
In-Reply-To: <1126087115.516061.50290@o13g2000cwo.googlegroups.com>
References: <1126087115.516061.50290@o13g2000cwo.googlegroups.com>
Message-ID: <1126156028.500117.323200@z14g2000cwz.googlegroups.com>
Thanks all.
I found the answer, rather easily.
To make a system call and wait for it, do:
subprocess.Popen([r"/sw/bin/gzip","-d","access_log.4.gz"]).wait();
------
this post is archived at:
http://xahlee.org/perl-python/system_calls.html
Xah
xah at xahlee.org
? http://xahlee.org/
Xah Lee wrote:
> suppose i'm calling two system processes, one to unzip, and one to
> ?tail? to get the last line. How can i determine when the first
> process is done?
>
> Example:
>
> subprocess.Popen([r"/sw/bin/gzip","-d","access_log.4.gz"]);
>
> last_line=subprocess.Popen([r"/usr/bin/tail","-n 1","access_log.4"],
> stdout=subprocess.PIPE).communicate()[0]
>
> of course, i can try workarounds something like os.system("gzip -d
> thiss.gz && tail thiss"), but i wish to know if there's non-hack way to
> determine when a system process is done.
>
> Xah
> xah at xahlee.org
> ? http://xahlee.org/
From jaydonnell at gmail.com Thu Sep 1 16:59:40 2005
From: jaydonnell at gmail.com (jdonnell)
Date: 1 Sep 2005 13:59:40 -0700
Subject: is there a better way to check an array?
In-Reply-To: <1125595376.858041.112430@g43g2000cwa.googlegroups.com>
References: <1125593752.264254.172970@g44g2000cwa.googlegroups.com>
<1125595376.858041.112430@g43g2000cwa.googlegroups.com>
Message-ID: <1125608380.573439.317040@g49g2000cwa.googlegroups.com>
Thanks for all the help everyone.
Steve, sets are perfect. I didn't even realize they existed. Somehow I
completely missed that part of the tutorial. Thanks :)
From tores at stud.cs.uit.no Wed Sep 21 10:58:47 2005
From: tores at stud.cs.uit.no (Tor Erik S�nvisen)
Date: Wed, 21 Sep 2005 16:58:47 +0200
Subject: using variable-value
Message-ID:
Hi
In php I can assign a value to a variable and use this varaible to access a
property in some object:
$var = 'property';
$object->{$var}
This will transelate to $object->property...
Is this possible in Python?
# Prints help on methods in Canvas-instance
for method in dir(self.canvas):
print method
print help(self.canvas.method)
gives me " AttributeError: Canvas instance has no attribute 'method' "...
regards tores
From rtconner at gmail.com Fri Sep 9 15:04:06 2005
From: rtconner at gmail.com (Rob Conner)
Date: 9 Sep 2005 12:04:06 -0700
Subject: Redundant code in multiple methods
Message-ID: <1126292646.472895.259480@g44g2000cwa.googlegroups.com>
No you don't need to know Zope to help me. The whole reason I'd even
want to do this is because of Zope though. I made a Zope product, and
now want to perfect it.
some simple example code...
class User:
def View(self):
# play with data here
myHtmlDoc = "pretend this is a uper profile"
return myHtmlDoc
index_html = View
def Edit(self):
# play with data here
myHtmlDoc = "editing the user"
return myHtmlDoc
So when visiting "website.com/User" zope will call User.index_html() or
when you visit "website.com/User/View" zope will call User.View() In
all of the testing/learning I've done on Zope I'm pretty sure that last
item (index_html or View) must be a method, but possible it only needs
to have an __doc__ attribute (otherwise Zope will Error)
The problem comes when I want to have code put into every method.
Perhaps a counter I want to increment on every visit to a User page.
I can do this..
def View(self):
incrementCounter()
# play with data here
myHtmlDoc = "pretend this is a uper profile"
return myHtmlDoc
index_html = View
def Edit(self):
incrementCounter()
# play with data here
myHtmlDoc = "editing the user"
return myHtmlDoc
... but in reality in my real code that one counter increment line ends
up being 20 lines long. An al lot of that "counter code" is actaully
setting up variables I'd like to access within the scope of the given
method. So if you follow me so far, I was wondering how I might change
things to only have one place where I have to maintain the "setup my
method" code, which is pretty much a lot of the same code typed over
and over into all of the methods.
(for a more real life example of things) -
def View(self):
REQUEST = self.REQUEST
SESSION = REQUEST.SESSION
dbConnection = self.getDBConnection()
logger = self.getLogger()
trackStatsHere()
# set up some local variables here
# change some global variables here
try:
myHtmlDoc = """make the htmldocument here using all
of the previous variables"""
# play with data here
return myHtmlDoc
except:
raise "handle the error here"
finally:
dbConnection.close()
index_html = View
def Edit(self):
REQUEST = self.REQUEST
SESSION = REQUEST.SESSION
dbConnection = self.getDBConnection()
logger = self.getLogger()
trackStatsHere()
# set up some local variables here
# change some global variables here
try:
myHtmlDoc = """make the htmldocument here using all
of the previous variables"""
# play with data here
return myHtmlDoc
except:
raise "handle the error here"
finally:
dbConnection.close()
I would ideally like to do something such as this this, or something
where I don't have all of that redundant code.
def __allmethods__(self, methodname):
"gets called when all methods are called"
REQUEST = self.REQUEST
SESSION = REQUEST.SESSION
dbConnection = self.getDBConnection()
logger = self.getLogger()
trackStatsHere()
# set up some local variables here
# change some global variables here
try:
methodname(localvariables)
except:
raise "handle the error here"
finally:
dbConnection.close()
def View(self, localvariables):
myHtmlDoc = """make the htmldocument here using all
of the previous variables"""
# play with data here
return myHtmlDoc
index_html = View
def Edit(self):
myHtmlDoc = """make the htmldocument here using all
of the previous variables"""
# play with data here
return myHtmlDoc
__getattr__ almost does the trick but not quite. So any suggestions on
how to streamline my code here and make it slightly more maintainable.
From andrea.valle at unito.it Sat Sep 17 09:50:20 2005
From: andrea.valle at unito.it (andrea valle)
Date: Sat, 17 Sep 2005 15:50:20 +0200
Subject: problem with setup.py
In-Reply-To:
References: <20050607150658.GB5985@ActiveState.com>
Message-ID: <856e627deed3989260ca9846ed603946@unito.it>
Thanks a lot.
I have bash as shell but I ignore what
> your ~/.bashrc
means.
Have I to edit a file?
Where should it be?
Thanks again
-a-
On 17 Sep 2005, at 12:46, Robert Kern wrote:
> andrea valle wrote:
>> Hi to all,
>> and sorry for cross-posting.
>>
>> I'm having troubles with installing packages.
>> I'm on macosx 10.3.8 and I have activestate python 2.4
>>
>> For example, pyrtf an pyx.
>> it is the first time I install packages so pardon me if it's obvious.
>>
>> I call python from terminal, I pass the absolute path of the setup.py
>> with command install, and results are always:
>> error: $MACOSX_DEPLOYMENT_TARGET mismatch: now "" but "10.3" during
>> configure
>>
>> For example with pyrtf:
>>
>> apples-Computer:~ apple$ python
>> /Users/apple/Desktop/PyRTF-0.45/setup.py installrunning install
>> error: $MACOSX_DEPLOYMENT_TARGET mismatch: now "" but "10.3" during
>> configure
>>
>> What should I do? I guess I have to hack some configuration, but don't
>> know which.
>
> Add the following line to your ~/.bashrc (assuming that you are using
> bash as your shell):
>
> export MACOSX_DEPLOYMENT_TARGET=10.3
>
> Then start a new Terminal.app window (the change doesn't take effect
> until a new shell is started).
>
> I haven't needed to do this with the official 2.4.1 build, so you
> should
> complain to ActiveState. Or use the official build.
>
> --
> Robert Kern
> rkern at ucsd.edu
>
> "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
>
>
Andrea Valle
Laboratorio multimediale "G. Quazza"
Facolt? di Scienze della Formazione
Universit? degli Studi di Torino
andrea.valle at unito.it
From steve at REMOVETHIScyber.com.au Mon Sep 19 10:13:20 2005
From: steve at REMOVETHIScyber.com.au (Steven D'Aprano)
Date: Tue, 20 Sep 2005 00:13:20 +1000
Subject: C#3.0 and lambdas
References: <1127049737.654113.84440@z14g2000cwz.googlegroups.com>
Message-ID:
On Mon, 19 Sep 2005 10:31:48 +0200, Fredrik Lundh wrote:
> meanwhile, over in python-dev land:
>
> "Is anyone truly attached to nested tuple function parameters; 'def
> fxn((a,b)): print a,b'? /.../
>
> Would anyone really throw a huge fit if they went away? I am willing
> to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
> people are up for it."
Consider this:
def func(some_tuple):
How many items should you pass in the tuple? If it takes variable
arguments, then that works, but if you always expect a fixed number, then
def func((x, y))
is more explicit.
The only problem I have is that once you unroll the tuple like that, it is
hardly necessary to pass the argument as a tuple. Why not just pass x and
y as two arguments?
def func(x, y)
I think tuple unrolling would work better if there was a way to refer to
the argument as both a tuple and by the components. Eg, making up a
hypothetical syntax for it:
def func(pt?(x,y)):
print "Tuple", pt
print "Items", x, y
Calling func((2,3)) prints:
"Tuple" (2, 3)
"Items" 2 3
Of course, this opens a can of worms, what happens if you pass a mutable
object like a list instead of a tuple or string?
Still, if Python is eventually to get something static types, it probably
makes sense to keep the def func((x,y)) idiom, because it will come in
handy for ensuring that your sequence arguments have the right number of
items.
--
Steven.
From larry.bates at websafe.com Thu Sep 8 13:01:24 2005
From: larry.bates at websafe.com (Larry Bates)
Date: Thu, 08 Sep 2005 12:01:24 -0500
Subject: job scheduling framework?
In-Reply-To: <1126194711.728965.86630@g43g2000cwa.googlegroups.com>
References: <1126194711.728965.86630@g43g2000cwa.googlegroups.com>
Message-ID: <5cOdnfriiORj8L3eRVn-vA@comcast.com>
Google turned up these links that might be of interest:
http://www.foretec.com/python/workshops/1998-11/demosession/hoegl/
http://www.webwareforpython.org/Webware/TaskKit/Docs/QuickStart.html
http://www.slac.stanford.edu/BFROOT/www/Computing/Distributed/Bookkeeping/SJM/SJMMain.htm
Larry Bates
Chris Curvey wrote:
> Has anyone seen a simple open source job-scheduling framework written
> in Python? I don't really want to reinvent the wheel. All I need is
> the ability to set up a series of atomic "jobs" as a "stream", then
> have the system execute the jobs in the stream one-at-a-time until all
> the jobs in the stream are complete or one of them reports an error.
>
> (If it tied into a really simple grid-style computing farm, that would
> be worth double points!)
>
> -Chris
>
From cmkleffner at gmx.de Tue Sep 6 11:50:54 2005
From: cmkleffner at gmx.de (cmkl)
Date: 6 Sep 2005 08:50:54 -0700
Subject: py2exe 0.6.1 released
References:
Message-ID: <1126021854.581774.261940@g43g2000cwa.googlegroups.com>
Hi,
I didnt succeed to bundle vpython-3.2.3 with py2exe-0.6.1 - regardless
if its build as single file or not:
"This application has requested the Runtime to terminate it in an
unusual way" and so on...
This error message seems not generated by py2exe. At least I could not
find a reference to it in the sources of py2exe.
Regards
Carl
From smadim2 at grads.ece.mcmaster.ca Tue Sep 20 13:15:55 2005
From: smadim2 at grads.ece.mcmaster.ca (M.N.A.Smadi)
Date: Tue, 20 Sep 2005 13:15:55 -0400
Subject: mailing from with python
Message-ID: <433043CB.8010608@grads.ece.mcmaster.ca>
hi;
if i want to send a mail message using the "mail" client on a machine
that has smtp protocol is there an easy way (i.e. like bash where you
would just type mail -s SUBJECT message RECIPIENT) to do it from a
python script?
thanks
moe smadi
From fredrik at pythonware.com Sun Sep 25 15:18:38 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Sun, 25 Sep 2005 21:18:38 +0200
Subject: cElementTree clear semantics
References:
Message-ID:
Igor V. Rafienko wrote:
> Finally, I thought about keeping track of when to clear and when not
> to by subscribing to start and end elements (so that I would collect
> the entire -subtree in memory and only than release it):
>
> from cElementTree import iterparse
> clear_flag = True
> for event, elem in iterparse("data.xml", ("start", "end")):
> if event == "start" and elem.tag == "schnappi":
> # start collecting elements
> clear_flag = False
> if event == "end" and elem.tag == "schnappi":
> clear_flag = True
> # do something with elem
> # unless we are collecting elements, clear()
> if clear_flag:
> elem.clear()
>
> This gave me the desired behaviour, but:
>
> * It looks *very* ugly
> * It's twice as slow as version which sees 'end'-events only.
>
> Now, there *has* to be a better way. What am I missing?
the iterparse/clear approach works best if your XML file has a
record-like structure. if you have toplevel records with lots of
schnappi records in them, iterate over the records and use find
(etc) to locate the subrecords you're interested in:
for event, elem in iterparse("data.xml"):
if event.tag == "record":
# deal with schnappi subrecords
for schappi in elem.findall(".//schnappi"):
process(schnappi)
elem.clear()
the collect flag approach isn't that bad ("twice as slow" doesn't
really say much: "raw" cElementTree is extremely fast compared
to the Python interpreter, so everything you end up doing in
Python will slow things down quite a bit).
to make your application code look a bit less convoluted, put the
logic in a generator function:
# in library
def process(filename, annoying_animal):
clear = True
start = "start"; end = "end"
for event, elem in iterparse(filename, (start, end)):
if elem.tag == annoying_animal:
if event is start:
clear = False
else:
yield elem
clear = True
if clear:
elem.clear()
# in application
for subelem in process(filename, "schnappi"):
# do something with subelem
(I've reorganized the code a bit to cut down on the operations.
also note the "is" trick; iterparse returns the event strings you
pass in, so comparing on object identities is safe)
an alternative is to use the lower-level XMLParser class (which
is similar to SAX, but faster), but that will most likely result in
more and tricker Python code...
From steve at holdenweb.com Fri Sep 30 06:37:40 2005
From: steve at holdenweb.com (Steve Holden)
Date: Fri, 30 Sep 2005 11:37:40 +0100
Subject: Will python never intend to support private, protected and public?
In-Reply-To:
References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com>
Message-ID:
Antoon Pardon wrote:
> Op 2005-09-30, Steve Holden schreef :
>
>>Antoon Pardon wrote:
>>
>>>Op 2005-09-29, Bill Mill schreef :
>>>
>>>
>>>>But, if your users can't figure out that they shouldn't be changing
>>>>the variable called t._test__i without expecting side effects, what do
>>>>you think of the users of your class?
>>>>
>>>>Python is for consenting adults.
>>>
>>>
>>>No it is not. Consenting means you had the choice. Python doesn't
>>>give you the choice not to consent. Unless of course you write
>>>it as a C-extension, then you can hide all you want.
>>>
>>
>>Good grief, the ultimate choice is to use Python because you like it, or
>>not to use it because you don't. Enough with the picking every available
>>nit, please. Consent or stop complaining :-)
>
>
> This is IMO not a nit. IMO people are redefining words. We are also
> talking within a certain context. When people use this slogan, they
> don't mean that people have the choice to not use python.
>
Quite true, but people do none the less have that choice. Some days I
wish a few more would exercise it.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
From peter at engcorp.com Thu Sep 15 06:06:56 2005
From: peter at engcorp.com (Peter Hansen)
Date: Thu, 15 Sep 2005 06:06:56 -0400
Subject: Newbie - instanciating classes from other files
In-Reply-To: <1126752450.458728.59050@g44g2000cwa.googlegroups.com>
References: <1126752450.458728.59050@g44g2000cwa.googlegroups.com>
Message-ID:
comanighttrain at gmail.com wrote:
> Hey guys, i just started learning python (i usually use java/C).
>
> this has got me stumped as its not mentioned in the documentation
> (unless im skimming it every time).
>
> How does one instanciate a class from another file
>
> i thought it would be
> -----------------------------------code---------------------------
> import file.py
>
> thisFile = ClassName()
> -------------------------------not code---------------------------
It's clear you haven't worked through the tutorial. It's short, easy,
and educational, so why not save yourself from embarrassment and whip
through it rather than trying to learn Python by guess-and-error?
-Peter
From fredrik at pythonware.com Fri Sep 30 10:17:46 2005
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 30 Sep 2005 16:17:46 +0200
Subject: Overloading __init__ & Function overloading
References:
<433D4714.9050808@websafe.com>
Message-ID:
Larry Bates wrote:
>I may be reading this question different than Fredrik.
it looks like you're using a non-standard definition of the word "overloading".
here are the usual definitions (quoting from a random google page):
"Overloading a method refers to having two methods which share the
same name but have different signatures."
"Overriding a method refers to having a new implementation of a method
with the same signature in a subclass."
From lycka at carmen.se Wed Sep 28 05:20:57 2005
From: lycka at carmen.se (Magnus Lycka)
Date: Wed, 28 Sep 2005 11:20:57 +0200
Subject: number of python users
In-Reply-To: <4337f0a5$1@nntp0.pdx.net>
References:
<4337f0a5$1@nntp0.pdx.net>
Message-ID:
Scott David Daniels wrote:
> * 2.3 was called Python-in-a-tie;
Nope, that's 2.2. See e.g.
http://lists.debian.org/debian-python/2002/08/msg00025.html
Sadly, it seems the Python Business Forum has died, or at least
fallen into some kind of coma, so I don't know if that's an
issue.
In corporate installations, there are still a lot of Red Hat
Enterprise Linux 3 installations, and they have 2.2. RH EL4
comes with 2.3.
From max at alcyone.com Fri Sep 30 16:53:19 2005
From: max at alcyone.com (Erik Max Francis)
Date: Fri, 30 Sep 2005 13:53:19 -0700
Subject: Google Not Universal Panacea [was: Re: Where to find python
c-sources]
In-Reply-To:
References:
Message-ID: