a question about my script

2006-08-29 Thread alper soyler
Hi all,I am trying to get some files from an ftp site by ftplib module and I wrote the below script. However I have a problem. With my script, I login to ftp.genome.jp site. then, I am changing the directory to pub/kegg/genomes/afm and I am downloading "a.fumigatus.pep"
file. However, what I want is to connect pub/kegg/genomes
directory and in this directory there are 3 letters name files e.g. 'afm' and in each of these 3 letters files there is a file with the extension of '.pep' like a.fumigatus.pep. I want to get these '.pep' files from the 3 letter named files. If you help me I will be very glad. Thanks you in advance.Regards,Alperfrom ftplib import FTP def handleDownload( block):    file.write(block)    print ".",ftp = FTP('ftp.genome. jp') print ftp.login() directory = 'pub/kegg/genomes/ afm' print 'Changing to ' + directoryftp.cwd(directory) ftp.retrlines( 'LIST') filename = 'a.fumigatus. pep' print 'Opening local file ' + filenamefile = open(filename, 'wb') print 'Getting ' + filenameftp.retrbinary( 'RETR ' + filename, handleDownload) print 'Closing file ' +
 filenamefile.close() print 'Closing FTP connection'print ftp.close()-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is this a good idea or a waste of time?

2006-08-29 Thread Simon Forman
Antoon Pardon wrote:
> On 2006-08-28, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> > Antoon Pardon wrote:
> >> On 2006-08-25, Simon Forman <[EMAIL PROTECTED]> wrote:
> >>> ...
> >>> Generally asserts should be used to "enforce" invariants of your code
> >>> (as opposed to typechecking), or to check certain things while
> >>> debugging.
> >>
> >> I don't understand this argument. Can't type checking be seen as
> >> enforcing a code invariant?
> >>
> > But it is practically never the "right" invariant.
>
> And who decides what is and what is not the "right" invariant?

Um, programmers' common sense.

I can't really describe it well in words, so I'll give you an example.

A long time ago, I wrote a simple interpreter that broke incoming
commands up on whitespace and ran the pieces one by one.  Then, for
reasons that are inconsequential to this post, I decided that instead
of using str.split(), I wanted to keep an index into the command string
and "parse" it using that.

It had been a long time since I had had to do this sort of
array/pointer style processing (thank you python, and Guido, et. al.,
too..) and I wasn't fully sure of myself and my code, so I used a bunch
of assert statement to allow myself to *be* sure.

Here's the relevant code (I added a few line continuations to try to
prevent mail/news formatting problems, but of course YMMV):


def interpret(self, command):
"""
Given a command string, break it into whitespace-delimited
commands and execute them one after another. Integers and
floats are pushed onto the stack.

This variant of the Interpreter class uses a simple pointer into
the command line string. It increments the 'pointer' and checks
against the set of chars in string.whitespace to break up the
command line.

It keeps track of the command line and the index so that Words it
executes (that have a reference to it) can perform manipulations
on them. This permits, for example, the "chomp" word, which takes
the next non-whitespace sequence of chars immediately following it
on the command line, makes a string of it, and puts it on the
stack.
"""
#Let's have a pointer or index.
i = 0

#Remember our command line
self.command = command

#Cache the length.
l = len(command)

while 0 <= i < l:

#Run through chars until we reach the end,
#or some non-whitespace.
while (i < l) and (command[i] in self.blankspace): i += 1

#If we've reached the end we're done.
if i == l: break

assert i < l, "If not, the line above should have break'd us."\
  "We should not have i > l ever."

#Remember our starting index for this word.
begin = i

assert command[begin] not in self.blankspace, "Just making
sure."

#Force at least one increment of i.
i += 1

#Run through until the end or some self.blankspace.
while (i < l) and (command[i] not in self.blankspace): i += 1

#At this point, we're either at the end of the command line
#or we're at a blank char delimiting a preceding word.
assert (i == l) or \
   ((begin < i < l) and (command[i] in self.blankspace))

#We've found a word.
word = command[begin:i]

#first, try making an integer..
try:
n = int(word)
self.stack.append(n)
except ValueError:

#if that didn't work, try making a float..
try:
f = float(word)
self.stack.append(f)
except ValueError:

#not a float or integer, eh? Let's try executing it..
try:
#Update our pointer in case the word wants it.
self.i = i

#try to lookup the command and execute it..
self.execute(word)

#Update our pointer in case the word changed it.
i = self.i
except:
ilog.exception('Error executing "%s"', word)

#propagate the Exception "upward"
raise


It's not the greatest code I've ever written, in fact it's kind of
naive.  (Nowadays I'd probably use re.finditer()...)  But notice that
the assert statements all act to verify that certain conditions are met
at certain places throughout the loop, and that if the code is
operating correctly, i.e. in the way that the programmer (Hi there!)
intended, that the assertions will always succeed.   *That's* the
"invariant" part.

Notice further that none of the asserts have any side effects, and
especially, that they could all be removed without changing the
operation of the code in any way.


This is the "proper" use of assertions, as I understand it.

(They are of course useful when you're trying to track down odd bugs,
but for a similar reason:  You put them into your code at those places
where you sus

Re: naive misuse? (of PyThreadState_SetAsyncExc)

2006-08-29 Thread Simon Forman

[EMAIL PROTECTED] wrote:
> [EMAIL PROTECTED] wrote:
> > The documentation for PyThreadState_SetAsyncExc says "To prevent naive
> > misuse, you must write your own C extension to call this". Anyone care
> > to list a few examples of such naive misuse?
>
> No? I'll take that then as proof that it's impossible to misuse the
> function.
>
> Thanks,
> Johan

I *was* going to say that if you didn't already know the answer to that
question then your use would almost certainly be naive.  But I thought
that'd be more nasty than funny, so I bit my tongue.

~Simon

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


Re: XML parsing and writing

2006-08-29 Thread Stefan Behnel
c00i90wn wrote:
> Stefan Behnel wrote:
>> c00i90wn wrote:
>>> Hey, I'm having a problem with the xml.dom.minidom package, I want to
>>> generate a simple xml for storing configuration variables, for that
>>> purpose I've written the following code, but before pasting it I'll
>>> tell you what my problem is. On first write of the xml everything goes
>>> as it should but on subsequent writes it starts to add more and more
>>> unneeded newlines to it making it hard to read and ugly.
>> Maybe you should try to get your code a little cleaner first, that usually
>> helps in finding these kinds of bugs. Try rewriting it with ElementTree or
>> lxml, that usually helps you in getting your work done.
>>
>> http://effbot.org/zone/element-index.htm
>> http://codespeak.net/lxml/
>
> Nice package ElementTree is but sadly it doesn't have a pretty print,
> well, guess I'll have to do it myself, if you have one already can you
> please give it to me? thanks :)

lxml's output functions all accept a "pretty_print" keyword argument.

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


Re: Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

2006-08-29 Thread Antoon Pardon
On 2006-08-27, Jacob Hallen <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> Patrick Maupin <[EMAIL PROTECTED]> wrote:
>
> Unfortunately there is a side effect to slots. They change the behaviour of
> the objects that have slots in a way that can be abused by control freaks
> and static typing weenies. This is bad, because the contol freaks should
> be abusing the metaclasses and the static typing weenies should be abusing
> decorators, since in Python,there should be only one obvious way of doing 
> something.

Your emphasis is wrong.

In Python there should be one obvious way of doing something. Preferably
this is the only obvious way. 

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


Re: Is this a good idea or a waste of time?

2006-08-29 Thread Jonathan Gardner

Simon Forman wrote:
>
> If you have a reason to restrict your code to using only ints (perhaps
> you're packing them into an array of some sort, or passing them to a C
> extension module) then yes, of course it's appropriate.

I politely disagree. Rather than an interface that demands an actual
int, demand something that can be typecast as an int.

For instance:

  def needsInt(i):
i = int(i)
... pass i to an internal c function that requires an int ...
# Or better yet, write your internal c function to take any Python
object and cast it into an int.

If you absolutely need a particular type of thing, then cast it into
that thing.

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


prob with tkinter

2006-08-29 Thread JyotiC
hi,
i am making a GUI using tkinter
i need to get lot of data from user, it's in form of a excel
sheets(many rows n columns)
what i am using is grid for foramating, frame is from Toplevel, data
collected from Entry widget
I can't see most of the columns. I am not able to add scroll bar, i
want it to be added horizontally and vertically. 

thanx 
Jyoti

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


prob with tkinter

2006-08-29 Thread JyotiC
hi,
i am making a GUI using tkinter
i need to get lot of data from user, it's in form of a excel
sheets(many rows n columns)
what i am using is grid for foramating, frame is from Toplevel, data
collected from Entry widget
I can't see most of the columns. I am not able to add scroll bar, i
want it to be added horizontally and vertically. 

thanx 
Jyoti

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


Re: a question about my script

2006-08-29 Thread Gabriel Genellina

At Tuesday 29/8/2006 03:55, alper soyler wrote:

I am trying to get some files from an ftp site by ftplib module and 
I wrote the below script. However I have a problem. With my script, 
I login to ftp.genome.jp site. then, I am changing the directory to 
pub/kegg/genomes/afm and I am downloading "a.fumigatus.pep" file. 
However, what I want is to connect pub/kegg/genomes directory and in 
this directory there are 3 letters name files


3 letters *files*? or 3 letters *directories*?

e.g. 'afm' and in each of these 3 letters files there is a file with 
the extension of '.pep' like a.fumigatus.pep. I want to get these 
'.pep' files from the 3 letter named files. If you help me I will be 
very glad. Thanks you in advance.


Do a cwd() starting one level above (that is, pub/kegg/genomes); 
using ftp.dir() you can get the subdirectories, then iterate over all 
of them, using another dir() to find the .pep files needed.



directory = 'pub/kegg/genomes/ afm'


Is that whitespace intentional?

(If you just want to download the files and don't need really a 
Python script, try wget...)




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Candygram

2006-08-29 Thread Salvatore
Hello,

I am using the following code to fetch URL
Is there a way to speed it. I cant't get rid of the time.sleep(1) for
every request !!!
Thank you for you advise

Regards

Salvatore


from candygram import cg

def fetchURL():
r = cg.Receiver()
r.addHandler(cg.Any,getURL,cg.Message)
for message in r:
item.append(message)

def getURL(name):
url = DServeur[name]['urladmin']
try:
s = urllib2.urlopen(url)
except:
return "\n%s : HS"%name
return "URL :%s"%name,s.read()[1:10]


socket.setdefaulttimeout(1)
serveurs = DServeur.keys()
serveurs.sort()
def go():
proc = cg.spawn(fetchURL)
for s in serveurs:
proc.send(s)
time.sleep(1)#How can I speed up this code ?

go()

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


The lib email parse problem...

2006-08-29 Thread 叮叮当当
hi, all

when a email body consist with multipart/alternative,  i must know when
the boundary ends to parse it,

but the email lib have not provide some function to indicate the
boundary end, how to solve it ?

thanks.

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


Re: Is this a good idea or a waste of time?

2006-08-29 Thread Antoon Pardon
On 2006-08-29, Jonathan Gardner <[EMAIL PROTECTED]> wrote:
>
> Simon Forman wrote:
>>
>> If you have a reason to restrict your code to using only ints (perhaps
>> you're packing them into an array of some sort, or passing them to a C
>> extension module) then yes, of course it's appropriate.
>
> I politely disagree. Rather than an interface that demands an actual
> int, demand something that can be typecast as an int.
>
> For instance:
>
>   def needsInt(i):
> i = int(i)
> ... pass i to an internal c function that requires an int ...
> # Or better yet, write your internal c function to take any Python
> object and cast it into an int.
>
> If you absolutely need a particular type of thing, then cast it into
> that thing.

The logical conclusion of this decision would be that one should write
sequence classes as follows:

  class Seq(object):

...

def __getitem__(self, index):
  index = int(index)
  ...

def __setitem__(self, index, value):
  index = int(index)
  ...

I don't know about you but I personally think this is overkill.
I would also prefer seq[2.5] to raise an exception instead
of returning seq[2]

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


Re: How ahead are you guys in the (Python) real world?

2006-08-29 Thread Fredrik Lundh
"Ray" wrote:

> Since I haven't used Python at work, I am using Python 2.5 right now.
> However I wonder, how fast are you guys moving from version to version
> at work?

fwiw, I work on systems that runs on 1.5.2, 2.1, 2.3 and "bleeding edge".

 



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


Re: How ahead are you guys in the (Python) real world?

2006-08-29 Thread Fredrik Lundh
Jorge Vargas wrote:

> for ones 2.5 is not consider production code yet so noone should be
> running anything on it. same with 1.6.

that's completely ignoring how Python's developed, though.  if you know what 
you're
doing, using stable (*) betas or release candidates can be an excellent idea.



*) where "stable" means "works well in your test environment". 



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


Re: Desktop Notification/Alerts In Python

2006-08-29 Thread alex23
Chaos wrote:
> I am looking for ways to have a Desktop Alert, like the one most IM
> Messengers have (MSN, AIM) at the lower right above the taskbar. Can
> anyone point me to the right resources to use?

Under Windows, they're called "balloon tips". Here's a thread from a
few years back asking for the exact same thing:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/f6f6083650b50f1d/f26db0efc52462f9#f26db0efc52462f9

There's even a working demo linked to at the end of the thread, and the
link is still live.

Thanks for prompting me to look, I've vaguely wanted something like
this for a while :)

-alex23

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


Re: The lib email parse problem...

2006-08-29 Thread Fredrik Lundh
"" wrote:

> when a email body consist with multipart/alternative,  i must know when
> the boundary ends to parse it,

or use a library that understands multipart messages.

> but the email lib have not provide some function to indicate the
> boundary end, how to solve it ?

http://docs.python.org/lib/module-email.Parser.html

 



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


Re: How ahead are you guys in the (Python) real world?

2006-08-29 Thread Bruno Desthuilliers
Ray wrote:
> Since I haven't used Python at work, I am using Python 2.5 right now.
> However I wonder, how fast are you guys moving from version to version
> at work? As an illustration my ex-company just moved to Java 5, which
> was released around... what, 2-3 years ago? (While I am running Java 6
> at home)
> 
> Is it the same in the Python world? What version of Python is used in,
> say, Google? Is it even 2.4 yet?
> 

I can't tell for Google, and we're certainly a much much smaller
company, but FWIW, we mostly use 2.4.3 (we still have a 2.3.x for
compatibility with some old zope install).


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML parsing and writing

2006-08-29 Thread Fredrik Lundh
someone wrote:

>> Nice package ElementTree is but sadly it doesn't have a pretty print,
>> well, guess I'll have to do it myself, if you have one already can you
>> please give it to me? thanks :)

http://effbot.python-hosting.com/file/stuff/sandbox/elementlib/indent.py

 



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


Re: The lib email parse problem...

2006-08-29 Thread John Machin
叮叮当当 wrote:
> hi, all
>
> when a email body consist with multipart/alternative,  i must know when
> the boundary ends to parse it,
>
> but the email lib have not provide some function to indicate the
> boundary end, how to solve it ?

By reading the manual.
http://docs.python.org/lib/module-email.Message.html

You don't need to concern yourself with boundaries -- a high-level
parser is provided.

Here's a simple example:

This script:

msg_text = """
[snip -- message is some plain text plus an attached file]
"""
import email
pmsg = email.message_from_string(msg_text)
for part in pmsg.walk():
print part.get_content_type(), part.get_filename("<>")

produced this output:

multipart/mixed <>
text/plain <>
application/octet-stream Extract.py

For a more comprehensive example, see
http://docs.python.org/lib/node597.html

HTH,
John

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

Re: Truly platform-independent DB access in Python?

2006-08-29 Thread Bruno Desthuilliers
Boris Dušek wrote:
> Bruno Desthuilliers wrote:
> 
>>> but what if the OS with server accessing the site that is on
>>> shared area changes?
>> And what if Python is not installed on it ?-)
>>
>> Seriously, do you think that hosting companies swap OS very often ?
> 
> No, I don't. But I was trying to find the best solution. :-)

Is there any reason to find a solution for a non-yet-existing problem ?



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unit test for a printing method

2006-08-29 Thread Fredrik Lundh
Marco Wahl wrote:

> Fredrik Lundh <[EMAIL PROTECTED]> writes:
>>
>> Scott David Daniels wrote:
>>
>>> For silly module myprog.py:
>>>  def A(s):
>>>  print '---'+s+'---'
>>> in test_myprog.py:
>>>  import unittest
>>>  from cStringIO import StringIO  # or  from StringIO ...
>>
>> why are you trying to reinvent doctest ?
>
> The OP asked for unit test.  This could be read that
> the OP wants to use module unittest.

http://docs.python.org/lib/doctest-unittest-api.html

 



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


Re: The lib email parse problem...

2006-08-29 Thread 叮叮当当
this is not enough.

when a part is mulitpart/alternative, i must find out which sub part i
need, not all the subparts. so i must know when the alternative is
ended.


John Machin 写道:

> 叮叮当当 wrote:
> > hi, all
> >
> > when a email body consist with multipart/alternative,  i must know when
> > the boundary ends to parse it,
> >
> > but the email lib have not provide some function to indicate the
> > boundary end, how to solve it ?
>
> By reading the manual.
> http://docs.python.org/lib/module-email.Message.html
>
> You don't need to concern yourself with boundaries -- a high-level
> parser is provided.
>
> Here's a simple example:
>
> This script:
>
> msg_text = """
> [snip -- message is some plain text plus an attached file]
> """
> import email
> pmsg = email.message_from_string(msg_text)
> for part in pmsg.walk():
> print part.get_content_type(), part.get_filename("<>")
>
> produced this output:
>
> multipart/mixed <>
> text/plain <>
> application/octet-stream Extract.py
>
> For a more comprehensive example, see
> http://docs.python.org/lib/node597.html
> 
> HTH,
> John

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

Re: The lib email parse problem...

2006-08-29 Thread Max M
叮叮当当 wrote:
> this is not enough.
> 
> when a part is mulitpart/alternative, i must find out which sub part i
> need, not all the subparts. so i must know when the alternative is
> ended.


Have you tried the email module at all?


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The lib email parse problem...

2006-08-29 Thread 叮叮当当
supose a email part like this:

Content-Type: Multipart/Alternative;
boundary="Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm"


--Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 7bit

   abcd.
--Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm
Content-Type: text/html; charset="gb2312"
Content-Transfer-Encoding: quoted-printable

.
--Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm--

the plain text is abcd, and the alternative content type is text/html,
i should prefer explain the html content, and i must not explaint the
two part ,so i want to get the boundary end.

thanks all.

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


Re: Pros/Cons of Turbogears/Rails?

2006-08-29 Thread Paul Boddie
[comp.lang.ruby snipped]

Ray wrote:
> Paul Boddie wrote:
> >
> > So actual maturity isn't important when using a technology: it's
> > "perceived maturity" that counts, right?
>
> Well depends on "counts" in what sense. Counts as in the managers up
> there perceive something as mature, despite proofs of the contrary,
> certainly "counts", because then we'll end up having to work with a
> probably immature technology (nothing about RoR here, I'm talking in
> general).

Yes, I saw this with Java several years ago. However, as someone
actually using the technology concerned, it's obviously vital to make
the distinction between actual and perceived maturity. My impression is
that we're seeing developers, not managers, failing to make that
distinction.

> Yet with more people using it, its actual maturity will
> inevitably rise as well, maybe eventually to a level near that of its
> perceived maturity.

This sentiment somehow reminds me of various Oracle products.

> "Counts" as in to us developers who are actually spending our lives
> doing this? Perhaps yes too. If you're well-versed in something that is
> widely perceived to be mature, you may find it easier to win bread for
> your family, even if you have a painful time using it.

Sure. Just get certified on whatever today's middle management are
advocating, spend a few years working with that stuff, then repeat the
process for the next generation of middle management - it can certainly
make money for people who don't seek any meaning in what they do.

[...]

> > If you only listen to Bruce Tate et al, I imagine you could have the
> > above impression, but I'd be interested to see hard facts to back up
> > those assertions.
>
> Yeah, see, the thing is that Python is not lacking luminaries endorsing
> it either, e.g.: Eric Raymond and Bruce Eckel. But for some reason this
> "Python is good" meme is not that viral. I wonder why...

Python has had its share of the spotlight: Eric Raymond's advocacy
dates back to the late 1990s; Bruce Eckel still advocates Python but
started doing so a few years ago. Perhaps the latest arrivals to the
party (celebrating dynamic languages in this case) are usually the
loudest, in order to make up for their sluggish realisation that Java
isn't the panacea they insisted it was while it was still the cool new
thing. Or perhaps a lot of these people do quite nicely out of surfing
whatever trend currently is the cool new thing.

> And, since when do hard facts matter anyway?

When certain individuals claim that more Java people know about Ruby
than they do about Python. I know that there are people out there who
know (about) Java but not about Jython, for example, but even in
circles where buzz and hype seem like everything (eg. marketing) the
hard facts or statistics are still critical because they actually help
those people do their job properly. Moreover, just stating something
doesn't make it true - the hard facts serve to prove or disprove such
assertions, and to anyone serious about understanding the underlying
phenomena, it's vital to seek those facts out.

> I've met a number of
> people who've told me they'd program in Eiffel if they could. And hey,
> perhaps in its day Eiffel *was* the best OO language out there.
> Certainly it looked cleaner than C++! :)

So why don't they? Management pressure? Why don't people write more
Python in their day job? Any suggestions?

Paul

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


Re: The lib email parse problem...

2006-08-29 Thread 叮叮当当
i just use email module lib.

Max M 写道:

> 叮叮当当 wrote:
> > this is not enough.
> >
> > when a part is mulitpart/alternative, i must find out which sub part i
> > need, not all the subparts. so i must know when the alternative is
> > ended.
>
>
> Have you tried the email module at all?
>
>
> --
>
> hilsen/regards Max M, Denmark
>
> http://www.mxm.dk/
> IT's Mad Science
> 
> Phone:  +45 66 11 84 94
> Mobile: +45 29 93 42 96

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

Re: How ahead are you guys in the (Python) real world?

2006-08-29 Thread Fuzzyman

Ray wrote:
> Since I haven't used Python at work, I am using Python 2.5 right now.
> However I wonder, how fast are you guys moving from version to version
> at work? As an illustration my ex-company just moved to Java 5, which
> was released around... what, 2-3 years ago? (While I am running Java 6
> at home)
>
> Is it the same in the Python world? What version of Python is used in,
> say, Google? Is it even 2.4 yet?

I'm lucky in that the company I work for are developing with
IronPython. That means I get to use Python 2.4. I'm appreciating the
joy of sets and decorators. :-)

I doubt we will move to 2.5 until that is the standard stable version
of IronPython.

For most of my own projects I try to maintain compatibility with 2.3,
as it is still very common. For CGI stuff I try to remain 2.2
compatible, because that is the default version of Python on many
web-hosts (and Linux distros).

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

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


Re: Is this a good idea or a waste of time?

2006-08-29 Thread Steve Holden
Antoon Pardon wrote:
> On 2006-08-29, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> 
>>At Tuesday 29/8/2006 02:45, Antoon Pardon wrote:
>>
>>
>That may be true. But one may wonder if this is a failing of the
>programmer or a failing of the language that doesn't support
>such things.

In any case, I don't see how this supports the original claim that
strict type checking input params is good practice.
>>>
>>>I'm not defending that claim. I'm just putting question marks
>>>with the claim that strict type checking input parameters is
>>>bad practice.
>>
>>I think others have shown enough examples of good things that can be 
>>done by *not* enforcing a specific type...
> 
> 
> That doesn't contradict that in other situations good things can be
> done by enforcing specific type or at least limiting to a subset
> of specific types.
> 
Indeed it doesn't, but perhaps in future we could leave others to work 
out the glaringly obvious for themselves rather than having to 
explicitly provide the counterargument to each single response to a posting?

crabbi-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: time.clock() going backwards??

2006-08-29 Thread Hendrik van Rooyen

 "Grant Edwards" <[EMAIL PROTECTED]> Wrote:

| On 2006-08-28, Grant Edwards <[EMAIL PROTECTED]> wrote:
|
| >>> For processors that run at (say) 2GHz, several million (say 10
| >>> million) represents a difference of 10e6/2e9 = 0.005 seconds
| >>> between when the processors were sufficiently powered up to
| >>> start counting cycles.
| >
| >> If it were so, than why can't the delta of time between the
| >> processors be set to exact zero?
| >
| > This is
|
| Oops.  Hit the wrong key.  I meant to say:

Thank god! - I know you are not an idiot - and for some minutes you had me
guessing - I was beginning to think that my brain had finally been destroyed by
drink - trying to figure out this enigmatic post...  :-)

- Hendrik

8<-


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


Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Hendrik van Rooyen

 "Claudio Grondi" <[EMAIL PROTECTED]> wrote:

8<-
| The test of the counter is what actually slows the loop down. Probably
| the test of time slows the loop even more down. Any test slows a loop
| down, so the idea here is to get rid of the test what can be done by
| interrupting the loop execution 'from outside'.
| Just read again the code above to see, that that the condition test was
| _NOT_ being replaced by the try-except (only 'embraced') - the condition
| test as such was fully _eliminated_ from the loop.
|
| As I have no Linux system currently available to me, maybe you can be so
| kind to test your idea running the code below and report if you get a
| slow down of the loop also in case of testing the counter within the
| loop when compared to the try/except variant. Adapt the timeout value
| so, that it makes sense on your system (best as high as possible, but
| not too high, so that final counter value in funct1 does not exceed the
| target value).
|
| 
| import signal, time
|
| def func1(timeout):
|
|  def callback(signum, frame):
|  raise EOFError # could use a custom exception instead
|  signal.signal(signal.SIGALRM, callback)
|  signal.alarm(timeout)
|
|  count = 0
|  try:
|  while 1:
|  count += 1
|  except EOFError:
|  while True:
|  count += 1
|  if count < 0x500:
|  break
|  print hex(count)
|
| def func2():
|
|  count = 0
|  while True:
|  count += 1
|  if count < 0x500:
|  break
|  print hex(count)
|
| print
| startTime = time.clock()
| funct1(10)
| print time.clock() - startTime
|
| print
| print
| startTime = time.clock()
| funct2()
| print time.clock() - startTime
|
| 
|
| Claudio Grondi

OK - copied this stuff over to my Linux box as a file junk.py in directory junk:
ran it, and I got:

> ls
junk.py
> python junk.py

Traceback (most recent call last):
  File "junk.py", line 32, in ?
funct1(10)
NameError: name 'funct1' is not defined

TUT - TUT!
so  fixed the names, ran it, and I got:

> python junk.py

0x1c142af
5.41


0x1
0.0
>

Not very helpful - so I changed the time.clock to time.time, ran it, and I got:

> python junk.py

0x1aa21ea
10.0033490658


0x1
0.000311851501465

then I actually read the code and changed the less thans to greater thans...

> python junk.py

0x501
66.8134140968


0x501
76.9292650223

so yup, it makes a difference
so then I messed with the timeout, setting it to 40 secs:

> python junk.py

0x5ecd34a
40.0047910213


0x501
89.4619050026

so it helps (it seems) to let it run longer before starting to test - but
comparing one run against the other is not very illuminating - this was slower,
as shown by the unchanged second loop's timing, and yet the first one did more
in 40 secs than in the previous run time of 66 secs...

Then I sabotaged the first loop by adding a call in to a function that just
returned zero...

> python junk.py

0x501
160.986829996


0x501
75.8728411198

the call is more expensive than the add...
so the more you do, the longer it takes (TradeMark)...

Here is the code as it is now:

import signal, time

def func1(timeout):

 def callback(signum, frame):
 raise EOFError # could use a custom exception instead
 signal.signal(signal.SIGALRM, callback)
 signal.alarm(timeout)

 count = 0
 try:
 while 1:
 count += 1
 error = func3()
 except EOFError:
 while True:
 count += 1
 error = func3()
 if count > 0x500:
 break
 print hex(count)

def func2():

 count = 0
 while True:
 count += 1
 if count > 0x500:
 break
 print hex(count)

def func3():
return 0

print
startTime = time.time()
func1(40)
print time.time() - startTime

print
print
startTime = time.time()
func2()
print time.time() - startTime


HTH

- Hendrik



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


Re: The lib email parse problem...

2006-08-29 Thread Fredrik Lundh
"" wrote:

> the plain text is abcd, and the alternative content type is text/html,
> i should prefer explain the html content, and i must not explaint the
> two part ,so i want to get the boundary end.

so use the email module:

import email

message_text = "..."

message = email.message_from_string(message_text)

for part in message.walk():
if part.get_content_type() == "text/html":
print "html is", repr(part.get_payload())

(the message instances either contains a payload or sequence of submessages;
use message.is_multipart() to see if it's a sequence or not.  the walk() method
used in this example loops over all submessages, in message order).

 



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


Re: The lib email parse problem...

2006-08-29 Thread Steve Holden
叮叮当当 wrote:
> supose a email part like this:
> 
> Content-Type: Multipart/Alternative;
> boundary="Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm"
> 
> 
> --Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm
> Content-Type: text/plain; charset="gb2312"
> Content-Transfer-Encoding: 7bit
> 
>abcd.
> --Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm
> Content-Type: text/html; charset="gb2312"
> Content-Transfer-Encoding: quoted-printable
> 
> ..
> --Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm--
> 
> the plain text is abcd, and the alternative content type is text/html,
> i should prefer explain the html content, and i must not explaint the
> two part ,so i want to get the boundary end.
> 
> thanks all.
> 
In other words, you *haven't* tried the email module.

email.Parser can cope with arbitrarily complex message structures, 
including oddities like attachments which are themselves email messages 
containing their own attachments.

Read the documentation and look for sample code, then get back to the 
list with questions about how to make email do what you want it to.

Please don't ask us to re-invent existing libraries. that's why the 
libraries are there.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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

Re: Starting up the server

2006-08-29 Thread alex23
john Perry wrote:
> how to solve these error
> ImportError: No module named pkg_resources

Hey John,

There's a TurboGears group that will be better suited to answering
TG-related questions:
http://groups.google.com/group/turbogears

It looks like this issue has come up before:
http://groups.google.com/group/turbogears/search?group=turbogears&q=%22No+module+named+pkg_resources%22&qt_g=1&searchnow=Search+this+group

In at least one case, the answer was: "install setuptools".

Hope this helps.

-alex23

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


Re: Pros/Cons of Turbogears/Rails?

2006-08-29 Thread Christophe
Paul Boddie a écrit :
> [comp.lang.ruby snipped]
> 
> Ray wrote:
>> I've met a number of
>> people who've told me they'd program in Eiffel if they could. And hey,
>> perhaps in its day Eiffel *was* the best OO language out there.
>> Certainly it looked cleaner than C++! :)
> 
> So why don't they? Management pressure? Why don't people write more
> Python in their day job? Any suggestions?


Probably because of the extreme Bondange And Disciplineness of Eiffel, 
the incredible cost of each user license, lack of generic programing ( 
you know, the thing easy to do in Python/Ruby but requires templates in 
C++ ) and the complete lack of a correct debugger.

By now, it seems that some of those problems have been fixed in various 
ways but we now have even better : incompatible implementations of the 
language!

Eiffel is for all purposes a niche language only used by some fanatics 
here and there :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The lib email parse problem...

2006-08-29 Thread 叮叮当当
this is just a temp solution for the simplest email format as my
example, and i cannot always only show the html part.

but in fact , there are many more difficult mail format

btw, i know how to use walk(), and the question is not this.

my code is as the following:

def mail_content(mail):
content =''
for part in mail.walk():
if part.is_multipart():
continue

ch =part.get_content_charset()
if ch:
content +=unicode(part.get_payload(decode =
True),ch).encode('utf-8')
else:
content +=part.get_payload(decode =
True).decode('gb2312').encode('utf-8')
return content

Fredrik Lundh 写道:

> "" wrote:
>
> > the plain text is abcd, and the alternative content type is text/html,
> > i should prefer explain the html content, and i must not explaint the
> > two part ,so i want to get the boundary end.
>
> so use the email module:
>
> import email
>
> message_text = "..."
>
> message = email.message_from_string(message_text)
>
> for part in message.walk():
> if part.get_content_type() == "text/html":
> print "html is", repr(part.get_payload())
>
> (the message instances either contains a payload or sequence of submessages;
> use message.is_multipart() to see if it's a sequence or not.  the walk() 
> method
> used in this example loops over all submessages, in message order).
> 
> 

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

Re: The lib email parse problem...

2006-08-29 Thread 叮叮当当
i know how to use email module lib.

the question is about how to handle the rfc 1521 mime
mulitpart/alternitave part .

i know emai can handle mulitpart , but the subpart  alternative is
special .



Steve Holden 写道:

> 叮叮当当 wrote:
> > supose a email part like this:
> >
> > Content-Type: Multipart/Alternative;
> > boundary="Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm"
> >
> >
> > --Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm
> > Content-Type: text/plain; charset="gb2312"
> > Content-Transfer-Encoding: 7bit
> >
> >abcd.
> > --Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm
> > Content-Type: text/html; charset="gb2312"
> > Content-Transfer-Encoding: quoted-printable
> >
> > ..
> > --Boundary-=_iTIraXJMjfQvFKkvZlqprUgHZWDm--
> >
> > the plain text is abcd, and the alternative content type is text/html,
> > i should prefer explain the html content, and i must not explaint the
> > two part ,so i want to get the boundary end.
> >
> > thanks all.
> >
> In other words, you *haven't* tried the email module.
>
> email.Parser can cope with arbitrarily complex message structures,
> including oddities like attachments which are themselves email messages
> containing their own attachments.
>
> Read the documentation and look for sample code, then get back to the
> list with questions about how to make email do what you want it to.
>
> Please don't ask us to re-invent existing libraries. that's why the
> libraries are there.
>
> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb   http://holdenweb.blogspot.com
> Recent Ramblings http://del.icio.us/steve.holden

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

Re: The lib email parse problem...

2006-08-29 Thread Fredrik Lundh
"" wrote:

> btw, i know how to use walk(), and the question is not this.

so what is the question?

 



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


Re: Is this a good idea or a waste of time?

2006-08-29 Thread Antoon Pardon
On 2006-08-29, Steve Holden <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>> On 2006-08-29, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>> 
>>>At Tuesday 29/8/2006 02:45, Antoon Pardon wrote:
>>>
>>>
>>That may be true. But one may wonder if this is a failing of the
>>programmer or a failing of the language that doesn't support
>>such things.
>
>In any case, I don't see how this supports the original claim that
>strict type checking input params is good practice.

I'm not defending that claim. I'm just putting question marks
with the claim that strict type checking input parameters is
bad practice.
>>>
>>>I think others have shown enough examples of good things that can be 
>>>done by *not* enforcing a specific type...
>> 
>> That doesn't contradict that in other situations good things can be
>> done by enforcing specific type or at least limiting to a subset
>> of specific types.
>> 
> Indeed it doesn't, but perhaps in future we could leave others to work 
> out the glaringly obvious for themselves rather than having to 
> explicitly provide the counterargument to each single response to a posting?

That Gabriel found it necessary to respond with that particular remark
suggest to me it wasn't glaringly obvious to him.

If we leave others to work out for themselves what is glaringly obvious
to us, I think a lot of newbee questions won't get answered.

> crabbi-ly y'rs  - steve

Sorry if I got on your nerves. But why don't you just skip my
articles if they irritate you or put me in a kill file if
you think of me as irratable in general?

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


Re: The lib email parse problem...

2006-08-29 Thread John Machin
叮叮当当 wrote:
> this is not enough.
>
> when a part is mulitpart/alternative, i must find out which sub part i
> need, not all the subparts. so i must know when the alternative is
> ended.
>

So you'll have to write your own tree-walker. It would seem that
is_multipart(), get_content_type() and get_payload() are the important
methods.

Here's a quickly lashed-up example:

def choose_one(part, html_ok=False):
last = None
for subpart in part.get_payload():
if html_ok or "html" not in subpart.get_content_type():
last = subpart
return last

def traverse(part, html_ok=False):
mp = part.is_multipart()
ty = part.get_content_type()
print "multi:%r type:%r file:%r" % (mp, ty,
part.get_filename("<>"))
if mp:
if ty == "multipart/alternative":
chosen = choose_one(part, html_ok=html_ok)
traverse(chosen, html_ok=html_ok)
else:
for subpart in part.get_payload():
traverse(subpart, html_ok=html_ok)

import email
pmsg = email.message_from_string(msg_text)
for toggle in (True, False):
print "--- html_ok is %r ---" % toggle
traverse(pmsg, html_ok=toggle)

With a suitable message, this produced:

--- html_ok is True ---
multi:True type:'multipart/alternative' file:'<>'
multi:False type:'text/html' file:'<>'
--- html_ok is False ---
multi:True type:'multipart/alternative' file:'<>'
multi:False type:'text/plain' file:'<>'

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

Re: about daemons and IPC

2006-08-29 Thread flupke
[EMAIL PROTECTED] schreef:
> Hey people!
> For the first time I'm doing a client/server application, and I'm
> really confused with IPC stuff.
> 
> I read the fastest method is shared memory, but I tryed mmap and found
> it tedious for the amount of data I'm handling (which is 30K at most,
> but mmap seems to get tedious for anything bigger than a boolean... am
> I missing something?)
> 
> Then I found many solutions for forked processes (like posh), but
> that's not what I need right now.
> 
> Any suggestions?
> 

You can also use RPC or even use a framework to do that for you like
Twisted. I like both approaches because they simplify communications.
For Twisted you have the initial investement in getting to know it but
it's also a lot more versatile
-- 
http://mail.python.org/mailman/listinfo/python-list


ntp in python

2006-08-29 Thread Janto Dreijer
I want to measure the packet delivery delays over various network
links. For this I need to synchronise the times of the sender and
receiver, either against NTP or eachother.

Unfortunately I won't necessarily have root priviledges to change the
PCs' clocks. So I'm looking for a way I can determine the offset and
simply correct my measurements from my Python code.

I doubt something like
http://www.nightsong.com/phr/python/setclock.py
would give me a resolution of less than 10ms - which is what I want.

Any Python module out there that uses a more sophisticated method?

btw I can do round-trip delivery and avoid the whole clock-mismatch
issue, but this would lose information on the network's asymmetry -
which would be really nice to have.

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


Re: unit test for a printing method

2006-08-29 Thread noro

Fredrik Lundh wrote:
> Scott David Daniels wrote:
>
> > For silly module myprog.py:
> >  def A(s):
> >  print '---'+s+'---'
> > in test_myprog.py:
> >  import unittest
> >  from cStringIO import StringIO  # or  from StringIO ...
>
> why are you trying to reinvent doctest ?
>
> 

it was my understanding that "doctest" is intented to test the little
examples in a function/class documention, do people use it for more
then that, i.e - do an extentive output testing for thier apps?

amit

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


Re: unit test for a printing method

2006-08-29 Thread Fredrik Lundh
"noro" wrote:

>> why are you trying to reinvent doctest ?
>
> it was my understanding that "doctest" is intented to test the little
> examples in a function/class documention, do people use it for more
> then that, i.e - do an extentive output testing for thier apps?

yes (by using doctest to test the test programs, rather than the individual
modules).

doctest is a lot more agile than traditional unittest development -- mostly
because instead of having to write both the test code and the expected
result, you just write good test code, run the tests, and verifies the output
manually before pasting it into your test script.  use your energy to come
up with good tests, not to deal with framework artifacts.

 



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


Re: NEED HELP

2006-08-29 Thread Rob Wolfe

[EMAIL PROTECTED] wrote:
> Below is my code, which is kind of virtual and with its help ill use it
> in my main project.
> Now what i am looking for is can anybody write all the code inside a
> class...so that I can reuse it. I am kind of novice...n kind of stuc
> with that.
>
> from Tkinter import *
>
> root = Tk()
>
> w = Label(root, text="Right-click to display menu", width=40,
> height=20)
> w.pack()
>
> # create a menu
> popup = Menu(root, tearoff=0)
> popup.add_radiobutton(label="SourceIP", command= hello) # ,
> command=next) etc...
> popup.add_radiobutton(label="DestIP", command= hello)
> popup.add_radiobutton(label="Reporter'sIP", command= hello)
> popup.add_radiobutton(label="Observer'sIP", command= hello)
> popup.add_separator()
> popup.add_radiobutton(label="Home")
>
> def do_popup(event):
> # display the popup menu
> try:
> popup.post(event.x_root, event.y_root)
> finally:
> # make sure to release the grab (Tk 8.0a1 only)
> popup.grab_release()
> def hello(event= None):
> print "hello"
>
> w.bind("", do_popup)
>
> b = Button(root, text="Quit", command=root.destroy)
> b.pack()
>
> mainloop()

Here's a great tutorial:

http://www.effbot.org/tkinterbook/tkinter-hello-again.htm

HTH,
Rob

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


Re: Pros/Cons of Turbogears/Rails?

2006-08-29 Thread Ray

Paul Boddie wrote:

> Sure. Just get certified on whatever today's middle management are
> advocating, spend a few years working with that stuff, then repeat the
> process for the next generation of middle management - it can certainly
> make money for people who don't seek any meaning in what they do.

It can certainly make money--true. "Don't seek any meaning in what they
do"?! You're just accusing a lot of honest hardworking people to be
mindless drones there. We have feelings too, you know :(

> > Yeah, see, the thing is that Python is not lacking luminaries endorsing
> > it either, e.g.: Eric Raymond and Bruce Eckel. But for some reason this
> > "Python is good" meme is not that viral. I wonder why...
>
> Python has had its share of the spotlight: Eric Raymond's advocacy
> dates back to the late 1990s; Bruce Eckel still advocates Python but
> started doing so a few years ago. Perhaps the latest arrivals to the
> party (celebrating dynamic languages in this case) are usually the
> loudest, in order to make up for their sluggish realisation that Java
> isn't the panacea they insisted it was while it was still the cool new
> thing. Or perhaps a lot of these people do quite nicely out of surfing
> whatever trend currently is the cool new thing.

Perhaps that is true. A pity though, personally I tried to learn Ruby
but it just doesn't go well with my brain.

> > And, since when do hard facts matter anyway?
>
> When certain individuals claim that more Java people know about Ruby
> than they do about Python.

First, that question was supposed to be rhetorical :) Second, my claim
is not that general. Certainly proving such a general claim is an
enormous undertaking. It just happens that most of Java developers I
know, and I know quite a lot since I've been doing this for years, they
know Ruby and Rails. Python, Django, Turbogears, make them go "huh?".
I've heard of one entrepreneurial guy starting an exclusively RoR shop
and doing quite well at it. I haven't heard a Django/Turbogears shop
yet.

> I know that there are people out there who
> know (about) Java but not about Jython, for example, but even in
> circles where buzz and hype seem like everything (eg. marketing) the
> hard facts or statistics are still critical because they actually help
> those people do their job properly. Moreover, just stating something
> doesn't make it true - the hard facts serve to prove or disprove such
> assertions, and to anyone serious about understanding the underlying
> phenomena, it's vital to seek those facts out.

True. But since when do hard facts matter? That is, it's not that I
haven't tried to make people know how great Python is. but I can talk
until I'm blue in the face and they just go, "nah". What I'm saying is
that people (and management) unfortunately are sold to not with hard
facts, but with whatever that X viral factor is. And for some reason
the RoR crowd has managed to make it quite viral.

> > I've met a number of
> > people who've told me they'd program in Eiffel if they could. And hey,
> > perhaps in its day Eiffel *was* the best OO language out there.
> > Certainly it looked cleaner than C++! :)
>
> So why don't they? Management pressure? Why don't people write more
> Python in their day job? Any suggestions?

Well, I posted in this group a few weeks ago because I was trying to
convince the managers to give Python a try and was looking for
additional ammo. In the end Django is out because of its lack of
support for Oracle. But it's a catch 22 isn't it? We're a Java shop so
our developers are trained in Java, Struts, Tomcat, etc. Any switch to
a dynamic language will be a huge change. However it baffles me that
they are open to at least a PoC in Rails. but when I suggested Python,
they went: "nah we're not interested in Python. Rails it is."

*shrugs* whatever it is, those guys are doing something right.

> Paul

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


Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-29 Thread Joachim Durchholz
Jim Gibson schrieb:
> 
> The problem addressed by what is know in Perl as the 'Schwartzian
> Transform' is that the compare operation can be an expensive one,
> regardless of the whether the comparison uses multiple keys. Since in
> comparison sorts, the compare operation will be executed N(logN) times,
> it is more efficient to pre-compute a set of keys, one for each object
> to be sorted. That need be done only N times.

Wikipedia says it's going from 2NlogN to N. If a sort is massively 
dominated by the comparison, that could give a speedup of up to 100% 
(approximately - dropping the logN factor is almost irrelevant, what 
counts is losing that factor of 2).

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


Extending the dict class

2006-08-29 Thread chosechu
Hello Pythoneers:

I need to pass a list of named arguments to a function in a given
order,
and make sure these named arguments are retrieved using keys() in the
same order they were given. Example:

keyargs={}
keyargs['one']=1
keyargs['two']=2
keyargs['three']=3

myfunc(**keyargs)
-> myfunc would retrieve key arguments with keys() in the same order
as they were set, i.e. keyargs.keys() == ['one', 'two', 'three']

To achieve that, I subclassed dict and added the required lines
in __init__(), __setitem__() and keys(). I then assigned dict to
my new class but only get the desired behaviour for dictionaries
created like:
d=dict()
but not for dictionaries created like:
d={}
or
myfunc(**keyargs)

Is it possible to force dictionary creation in these case to use
my own dict class instead of the default one?

I guess we can formulate this as a more generic question: if I
want to modify the behaviour of the dictionary class, is there
any way to do it interpreter-wide so that special dict constructors
like those mentioned above use the modified version?

Thanks for helping

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


Re: Extending the dict class

2006-08-29 Thread Duncan Booth
chosechu wrote:

> Is it possible to force dictionary creation in these case to use
> my own dict class instead of the default one?

No

> I guess we can formulate this as a more generic question: if I
> want to modify the behaviour of the dictionary class, is there
> any way to do it interpreter-wide so that special dict constructors
> like those mentioned above use the modified version?

Not without modifying and recompiling the interpreter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-29 Thread Paul Boddie
Ray wrote:
>
> It can certainly make money--true. "Don't seek any meaning in what they
> do"?! You're just accusing a lot of honest hardworking people to be
> mindless drones there. We have feelings too, you know :(

Well, I'm sorry for the unintentional insult. However, I've come to
believe that some people have the personality traits that let them
tolerate redoing the same work over and over again for no reason other
than management "furniture rearranging", whereas others start to resent
having their (working) life repeatedly flashed before their eyes, but
in slightly different colours, over a longer period of time. If there's
some kind of art that somehow increases tolerance of such things in a
humane way, I'd be interested to know what it is.

[...]

> Well, I posted in this group a few weeks ago because I was trying to
> convince the managers to give Python a try and was looking for
> additional ammo. In the end Django is out because of its lack of
> support for Oracle. But it's a catch 22 isn't it?

In the end, provided you have the time and energy (or money) for it,
you just have to make your own plan for bridging whatever gap there is
in the functionality of whatever open source project you intend to
employ professionally. I was once in a similar situation myself, with
Oracle products as well, where I had to put in the work myself to get
the necessary support needed for having my Python plus Oracle code
working in an environment that was Python-sceptical at best. I guess
the code was ultimately taken out of production, and everyone went over
to a pure Java strategy, but you can't always infuence people by
lobbying.

> We're a Java shop so
> our developers are trained in Java, Struts, Tomcat, etc. Any switch to
> a dynamic language will be a huge change. However it baffles me that
> they are open to at least a PoC in Rails. but when I suggested Python,
> they went: "nah we're not interested in Python. Rails it is."
>
> *shrugs* whatever it is, those guys are doing something right.

Making the Java people feel like they're doing something wrong, I
guess. And perhaps the Rails people realised that by giving those
people who lack direction, motivation, conviction or a sense of purpose
or control something to gravitate towards, some of them might feel
empowered enough to evangelise their discovery to the rest of the
group.

Paul

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


Re: Extending the dict class

2006-08-29 Thread chosechu

Duncan Booth wrote:
> > Is it possible to force dictionary creation in these case to use
> > my own dict class instead of the default one?
>
> No

Ouch. I was expecting something like that, thanks for confirming it.

If I may: this seems inconsistent to me. I have created an augmented
version of the class with no possibility to extend 2 of the 3 legal
constructors: {} and func(**d). While I agree changing base class
behaviour is a bad idea, since we have the possibility to re-assign
dict to another class we should be able to do it consistently, i.e.
re-assing the two special constructors too.

Just my 2c on the topic... I have found workarounds anyway.

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


Re: Extending the dict class

2006-08-29 Thread Bruno Desthuilliers
chosechu wrote:
> Hello Pythoneers:
> 
> I need to pass a list of named arguments to a function in a given
> order,
> and make sure these named arguments are retrieved using keys() in the
> same order they were given. Example:
> 
> keyargs={}
> keyargs['one']=1
> keyargs['two']=2
> keyargs['three']=3
> 
> myfunc(**keyargs)
> -> myfunc would retrieve key arguments with keys() in the same order
> as they were set, i.e. keyargs.keys() == ['one', 'two', 'three']

I'm not sure to understand why you want to do so - perhaps you could
tell more about your real use case ?

Anyway, and since it's not directly possible, a possible workaround
could be to pass a sequence of (key, value) tuples instead (possibly as
*args). This of course requires that you can modify the implementation
of myfunc().


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-08-29 Thread Bruno Desthuilliers
Paul Boddie wrote:
> Ray wrote:
(snip)
>> We're a Java shop so
>> our developers are trained in Java, Struts, Tomcat, etc. Any switch to
>> a dynamic language will be a huge change. However it baffles me that
>> they are open to at least a PoC in Rails. but when I suggested Python,
>> they went: "nah we're not interested in Python. Rails it is."
>>
>> *shrugs* whatever it is, those guys are doing something right.
> 
> Making the Java people feel like they're doing something wrong, I
> guess. And perhaps the Rails people realised that by giving those
> people who lack direction, motivation, conviction or a sense of purpose
> or control something to gravitate towards, some of them might feel
> empowered enough to evangelise their discovery to the rest of the
> group.
> 

FWIW, and while it's certainly not enough by itself to explain the
phenomenon, I think that Ruby's object model being much more
conventional than Python's may have some influence too on RoR's adoption
by the Java world.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and Prolog

2006-08-29 Thread rodmc
Can anyone recommend a library which will let me bridge between Python
and Prolog? I have looked around but as yet have had no luck. Either
the libraries are no longer being updated or the links do not work.
FYI: I am using Python 2.4 and SWI Prolog, I would also like to make
sure it can run on Mac, Linux and Windows - the latter being my main
development machine.

Thanks in advance for any help.

Kind regards,

rod

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


Re: Extending the dict class

2006-08-29 Thread chosechu

> I'm not sure to understand why you want to do so - perhaps you could
> tell more about your real use case ?

Without diving into too many details: I am calling SOAPpy to build
SOAP requests. When calling a proxy, named arguments are used
to build up the corresponding XML like:

proxy.call(alpha=1, beta=2, gamma=3)
would end up like:
1 2 3

Unfortunately, since the arguments as retrieved with **k
their order is lost in the call. The corresponding XML file
re-arranges the parameter order randomly and the final
XML request is unordered, which is not supported by a
number of braindead SOAP servers (including one produced
by a well-known software company I will not name here).

SOAPpy cannot know in advance the argument names since
they are server-dependent and SOAPpy is generic, so retrieving
named arguments with **k seems like the sensible thing to do.
Unfortunately this gets converted to a dict so looses all ordering
when being received. Extending the base dict class to support ordering
was one possible idea.

> Anyway, and since it's not directly possible, a possible workaround
> could be to pass a sequence of (key, value) tuples instead (possibly as
> *args). This of course requires that you can modify the implementation
> of myfunc().

Yes, if I could simply modify myfunc() I would have workarounds.
This would mean me modifying SOAPpy and specializing it for
my needs.

There are other ways to implement SOAP clients anyway so
no real need. Just wanted to try out some metaclass stuff.

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


subprocess woes

2006-08-29 Thread km
Hi all,

I have a strange question.
a program on shell looks as follows:
$cat test.fa |fasta34 -q @ s
where test.fa contains a protein sequence (alphabets); s is the
database to be searched and @
+indicates that the input is from stdin (ie., 'cat test.fa')
now instead of 'cat test.fa' i take that input into a varaible  and
want to feed it to the
+program.
I have  a sequence string in a variable named x, and use subprocess
module to wrap this:
##code start ##
import subprocess as sp
x = 'GSQIPSHYWKKNLWYYSHEIDGGCHNMW'
p0 = sp.Popen(["echo",x], stdout=sp.PIPE)
p1 = sp.Popen(["fasta34","-q","@",s],stdin=p0.stdout, stdout=sp.PIPE)
output = p1.communicate()[0]
print output
code end#

Output for this code doesnt give me the result as the program senses
the input as empty
let me know  where i am wrong.

The idea is to pipe-input the string to the program as a variable as
mentioned above.

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


Re: Extending the dict class

2006-08-29 Thread Fredrik Lundh
"chosechu" wrote:

> Yes, if I could simply modify myfunc() I would have workarounds.
> This would mean me modifying SOAPpy and specializing it for
> my needs.

maybe you could fake it:

class fakedict(dict):
def __init__(self, *data):
self.data = list(data)
for k, v in data:
self[k] = v
def items(self):
return self.data

d = fakedict(("a", 1), ("b", 2), ("c", 3))

print d => {'a': 1, 'c': 3, 'b': 2}
print d.items() => [('a', 1), ('b', 2), ('c', 3)]
print isinstance(d, dict) => True

(the exact set of methods you need to override depends on how SOAPpy
fetches the members).

 



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


Re: Extending the dict class

2006-08-29 Thread Duncan Booth
chosechu wrote:

> SOAPpy cannot know in advance the argument names since
> they are server-dependent and SOAPpy is generic, so retrieving
> named arguments with **k seems like the sensible thing to do.
> Unfortunately this gets converted to a dict so looses all ordering
> when being received. Extending the base dict class to support ordering
> was one possible idea.

If the order of the argument names matters, then it seems to me that should 
be handled by the SOAP library, not pushed onto the end user whoch should 
just be calling the function with the named arguments in the most 
convenient order.

Shouldn't SOAPpy be able to get this information out of the WSDL?

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


Re: Extending the dict class

2006-08-29 Thread chosechu

Duncan Booth wrote:
> If the order of the argument names matters, then it seems to me that should
> be handled by the SOAP library, not pushed onto the end user whoch should
> just be calling the function with the named arguments in the most
> convenient order.
>
> Shouldn't SOAPpy be able to get this information out of the WSDL?

Yes, SOAPpy could extract this from the WSDL specs.
SOAPpy could also find another way to pass call parameters, but I kinda
like
the named parameters (seems really Python-like). Microsoft could also
build SOAP services that parse XML without making ordering mandatory
where
nobody said it was.

... but we are living in a different dimension, one where I can extend
the Python dict class but not touch 2 of its 3 constructors (of course
the most
useful ones).

If you really want to know, I ended up at the socket level pushing
templatized
strings. Wish me luck with future server changes.

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


Re: How ahead are you guys in the (Python) real world?

2006-08-29 Thread A.M. Kuchling
On 28 Aug 2006 20:13:54 -0700, 
Ray <[EMAIL PROTECTED]> wrote:
> Since I haven't used Python at work, I am using Python 2.5 right now.
> However I wonder, how fast are you guys moving from version to version
> at work? 

At our company, we build a product on top of Debian (product line 1)
or Ubuntu (product line 2, not released yet), so we stick to what's
available in the Debian/Ubuntu versions we're using.  

That means 2.3 on Debian and 2.4 on Ubuntu.  2.5 will probably arrive
whenever we upgrade to the upcoming Ubuntu release, though I've
already tried manually upgrading a system to 2.5, and our code ran
without changes or apparent problems.

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


Re: ntp in python

2006-08-29 Thread Jeremy Sanders
Janto Dreijer wrote:

> I want to measure the packet delivery delays over various network
> links. For this I need to synchronise the times of the sender and
> receiver, either against NTP or eachother.

Couldn't you just use NTP itself to get the delivery delay? You can read the
delay out from the ntpdc console using dmpeers, or lopeers in ntpq. You
could have two peers either side of the link and measure the delay from
NTP.

You may also be able to query remote ntp servers to get their delays to
their peers.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending the dict class

2006-08-29 Thread chosechu

> (the exact set of methods you need to override depends on how SOAPpy
> fetches the members).

[fakedict class]
This I did. And checking out the source it seems SOAPpy retrieves named
parameters through keys(), which is the method I tried to overload.
Trouble is:
something happens to my fakedict object when getting through this:
d = fakedict(...)
SOAPmethod(**d)
I have the impression **d acts like a dict constructor, taking over my
fakedict class. I know I could find the answer by scrutinizing the
source,
call me lazy.

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


Re: Extending the dict class

2006-08-29 Thread Duncan Booth
chosechu wrote:

> 
> Duncan Booth wrote:
>> If the order of the argument names matters, then it seems to me that
>> should be handled by the SOAP library, not pushed onto the end user
>> whoch should just be calling the function with the named arguments in
>> the most convenient order.
>>
>> Shouldn't SOAPpy be able to get this information out of the WSDL?
> 
> Yes, SOAPpy could extract this from the WSDL specs.
> SOAPpy could also find another way to pass call parameters, but I
> kinda like
> the named parameters (seems really Python-like). Microsoft could also
> build SOAP services that parse XML without making ordering mandatory
> where
> nobody said it was.

Indeed, the spec says that parameterOrder is a hint and may be safely 
ignored.

> 
> ... but we are living in a different dimension, one where I can extend
> the Python dict class but not touch 2 of its 3 constructors (of course
> the most
> useful ones).

No, you weren't able to extend the builtin dict class nor touch any its 
constructor.

All you did was to create a subclass with its own constructor and hide the 
name for the builtin dictionary type. The original type was still unchanged 
as you can see since anything which constructed a dictionary without using 
the name you had overwritten still got the original type.

If you had looked at type(dict()) and type({}) after your subclassing, you 
would see that they are different types.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending the dict class

2006-08-29 Thread chosechu

Duncan Booth wrote:
> No, you weren't able to extend the builtin dict class nor touch any its
> constructor.

Yes, sorry. Forgot the negation.

> All you did was to create a subclass with its own constructor and hide the
> name for the builtin dictionary type. The original type was still unchanged
> as you can see since anything which constructed a dictionary without using
> the name you had overwritten still got the original type.
>
> If you had looked at type(dict()) and type({}) after your subclassing, you
> would see that they are different types.

... which prompted my question.

And prompts yet another one: seems like it
is not possible with Python to modify behaviour
for base classes without recompiling the
interpreter. Forgive me for asking what must
surely have been asked already, but are there
plans to implement something like that,
like Ruby?

I would not feel too safe navigating in a source
where base object behaviour might have been
re-defined, but it sure is a powerful way of
adding behaviour to third-party code which you
may not have possibility to modify.

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


Re: Extending the dict class

2006-08-29 Thread Tim N. van der Leeuw

Fredrik Lundh wrote:
> "chosechu" wrote:
>
> > Yes, if I could simply modify myfunc() I would have workarounds.
> > This would mean me modifying SOAPpy and specializing it for
> > my needs.
>
> maybe you could fake it:
>
No you cannot fake it, because the ** form of passing arguments
constructs a new dictionary (and that dictionary is the standard
built-in type of dictionary, not your own fake-dictionary).

Just did some tests, redefining the dict-type:

>>> native_dict = dict
>>> type({}) == native_dict
True
>>> class my_dict(native_dict):
... pass
...
>>> dict = my_dict
>>> type({}) == native_dict
True
>>> type(dict()) == native_dict
False
>>> def foo(**kwargs):
... print type(kwargs) == native_dict
...
>>> foo(x=1)
True
>>> foo(**dict())
True
>>>

(NB: I also tried changing __builtins__.dict, no effect)

As the OP said, when passing keyword-arguments, a new instance of a
built-in dict is always generated and not the dict type bound to the
dict-constructor.

I do actually think that it would be useful in many circumstances to be
able to replace the default-constructor of a particular so that custom
objects are created for that type.

OTOH, there are probably many more cases where doing so would be a very
bad idea, not a good idea, and we would begin seeing an overwhelming
number of cases of mis-use of such feature.

Cheers,

--Tim

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


Re: Extending the dict class

2006-08-29 Thread Tim N. van der Leeuw

chosechu wrote:
> Duncan Booth wrote:
> > If the order of the argument names matters, then it seems to me that should
> > be handled by the SOAP library, not pushed onto the end user whoch should
> > just be calling the function with the named arguments in the most
> > convenient order.
> >
> > Shouldn't SOAPpy be able to get this information out of the WSDL?
>
> Yes, SOAPpy could extract this from the WSDL specs.
> SOAPpy could also find another way to pass call parameters, but I kinda
> like
> the named parameters (seems really Python-like). Microsoft could also
> build SOAP services that parse XML without making ordering mandatory
> where
> nobody said it was.
>
Are you sure that the order is not defined in the WSDL still? I don't
know WSDL, but in XML Schema for instance, order is defined when using
'xsd:sequence' yet many parsers don't care for receiving elements in a
different order from what's defined in the XSD which they're supposed
to validate against (working perhaps with the axiom 'be liberal in what
yo except, but strict in what you send'). Many people don't actually
realize that 'xsd:sequence' dictates the order of elements and use it
just for 'any order is good enough'.

Might be a similar case with the WSDL: Order is defined, but due to
mis-interpretation of the spec it's not realized / enforced by all /
some of the components.
Anyways, modifiying SOAPpy might not be a bad idea: submit your changes
to the project, and you can write on your CV that you have contributed
to open-source projects! ;-)

I do hope for you that you will find something better to do than
pushing template-instances down a socket-hole.

Cheers,

--Tim

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


Re: Extending the dict class

2006-08-29 Thread Fredrik Lundh
Tim N. van der Leeuw wrote:

>> maybe you could fake it:
>>
> No you cannot fake it, because the ** form of passing arguments
> constructs a new dictionary (and that dictionary is the standard
> built-in type of dictionary, not your own fake-dictionary).

yeah, I thought he was passing a dictionary to a SOAPpy method.  passing
custom types through the argument handling layer doesn't work.

 



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


Re: Max OSX and Excel

2006-08-29 Thread Jorge Vargas
On 28 Aug 2006 15:50:57 -0700, John Machin <[EMAIL PROTECTED]> wrote:
> Jorge Vargas wrote:
> > On 8/28/06, Johanna Pfalz <[EMAIL PROTECTED]> wrote:
> > > To be more specific, I'm interested in reading in certain rows and columns
> > > from an excel spreadsheet directly without converting the information to a
> > > text file.  I'd also like to be able to write directly to an excel
> > > spreadsheet from python.
>
> AFAIK there is no Python tool that will let you "write directly to" an
> *existing* xls file -- apart of course from running Excel on Windows
> via COM.
>
> The Pyexcelerator package creates xls files.
>
> > ohh I found a nice tool for that a while ago but I haven't been able to 
> > test it.
>
> Because ?
>
nothing related to it, it's just that I haven't had the time to dive into it.
> >
> > http://groups.google.com/group/comp.lang.python.announce/browse_thread/thread/5d0828d7762e3586
> > http://cheeseshop.python.org/pypi/xlrd
> > http://www.lexicon.net/sjmachin/xlrd.htm
>
> The "rd" in "xlrd" is an abrv8n of "read" -- it doesn't write Excel
> spreadsheets.
>
oh no wonder why with my quick look at the API I didn't saw any write methods :)

do you have any plans of implementing wirte or at least read/write of xls docs?
> >
> > I'll love to read some feedback from you on it :)
>
> Perhaps I should post some user feedback on the package's "website" ;-)
>
that will be nice.
> Cheers,
> John
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


absolute imports (python-2.5)

2006-08-29 Thread [EMAIL PROTECTED]
Hello all

I just played around a bit with python 2.5 and relative imports.
Bit disappointed so far. Hoped to be able to use this new feature
to develop standalone libraries that can be just dropped into
any project without having to adjust any imports.

pkg/
pkg/__init__.py
pkg/main.py
pkg/string.py


"main.py" does:
from . import string

no problem if you import the whole package from another module:
import pkg

but if you execute "main.py" you get an error
"ValueError: Relative importpath too deep"

This is looks a nightmare come true for developing modules.
I read all available information regarding the "-m" switch and its
limitations when it comes to relative imports. Being impatient
and scarend of having to wait another (year!) for this feature to
become usable I wonder if anyone has any better information on
things ahead.

Juergen

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


Re: ntp in python

2006-08-29 Thread Sander Steffann
Hi,

> I want to measure the packet delivery delays over various network
> links. For this I need to synchronise the times of the sender and
> receiver, either against NTP or eachother.

Maybe you can contact RIPE. They have test-boxes for exactly these kind of 
tests. I know AMS-IX uses them to measure the quality of their switch 
platform.

See http://www.ripe.net/projects/ttm/index.html

- Sander



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


Re: Python daemon process

2006-08-29 Thread Thomas Dybdahl Ahle
I might not have made myself very clear, since you both got me wrong.
What I need, is not a method to terminate a process, but a way to
terminate a process when the main process dies.

>From the atexit module info:
Note: the functions registered via this module are not called when the
program is killed by a signal, when a Python fatal internal error is
detected, or when os._exit() is called.

I belive that there is noway you can be sure to get a piece of code run,
if the program crashes or something like that,
therefor I ask for a way to run gnuchess as a kind of subprocess, that can
only run when the parrentprocess is still running.

I know this is called a daemon thread in java.

> 2006/8/26, Thomas Dybdahl Ahle <[EMAIL PROTECTED]>:
>> Hi, I'm writing a program, using popen4(gnuchess),
>> The problem is, that gnuchess keeps running after program exit.
>>
>> I know about the atexit module, but in java, you could make a process a
>> daemon process, and it would only run as long as the real processes ran. I
>> think this is a better way to stop gnuchess, as you are 100% sure, that
>> it'll stop.
>>
>> Can you do this with popen?
>>
>> --
>> Thomas
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> You could send the quit (or close or wahtever) command to gnuchess
> when you want it to terminate. Supposing that gnuchess needs to do
> some stuff on exit, this is a better solution.
> 
> PAolo

-- 
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks of
Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.

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


Re: newbe question about removing items from one file to another file

2006-08-29 Thread Anthra Norell
Dexter,

I looked at the format specification. It contains an example:

---

;
  ; test.csd - a Csound structured data file


  -W -d -o tone.wav


;optional section
  Before 4.10  ;these two statements check for
  After 4.08   ;   Csound version 4.09



  ; originally tone.orc
  sr = 44100
  kr = 4410
  ksmps = 10
  nchnls = 1
  instr   1
  a1 oscil p4, p5, 1 ; simple oscillator
 out a1
endin



  ; originally tone.sco
  f1 0 8192 10 1
  i1 0 1 2 1000 ;play one second of one kHz tone
  e




-

If I understand correctly you want to write the instruments block to a file 
(from  to )? Right? Or
each block to its own file in case there are several?. You want your code to 
generate the file names? Can you confirm this or
explain it differently?

Regards

Frederic


- Original Message -
From: <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Monday, August 28, 2006 10:48 AM
Subject: Re: newbe question about removing items from one file to another file


>
> Anthra Norell wrote:
> > Eric,
> >Having played around with problems of this kind for quite some time I 
> > find them challenging even if I don't really have time
to
> > get sidetracked. Your description of the problem makes it all the more 
> > challenging, because its 'expressionist' quality adds the
> > challenge of guessing what you mean.
> >I'd like to take a look at your data, if you would post a segment on 
> > which to operate, the same data the way it should look
in
> > the end. In most cases this is pretty self-explanatory. Explain the points 
> > that might not be obvious to a reader who knows
nothing
> > about your mission.
> >
> > Frederic
> >
> > - Original Message -
> > From: <[EMAIL PROTECTED]>
> > Newsgroups: comp.lang.python
> > To: 
> > Sent: Sunday, August 27, 2006 11:35 PM
> > Subject: newbe question about removing items from one file to another file
> >
> >
> > > def simplecsdtoorc(filename):
> > > file = open(filename,"r")
> > > alllines = file.read_until("")
> > > pattern1 = re.compile(" > > orcfilename = filename[-3:] + "orc"
> > > for line in alllines:
> > > if not pattern1
> > >  print >>orcfilename, line
> > >
> > > I am pretty sure my code isn't close to what I want.  I need to be able
> > > to skip html like commands from  to  and to key on
> > > another word in adition to  to end the routine
> > >
> > > I was also looking at se 2.2 beta but didn't see any easy way to use it
> > > for this or for that matter search and replace where I could just add
> > > it as a menu item and not worry about it.
> > >
> > > thanks for any help in advance
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
>
> sorry about that this is a link to a discription of the format
> http://kevindumpscore.com/docs/csound-manual/commandunifile.html
> It is possible to have more than one instr defined in an .csd file so I
> would need to look for that string also if I want to seperate the
> instruments out.
>
> http://www.dexrow.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Extending the dict class

2006-08-29 Thread chosechu

Tim N. van der Leeuw wrote:
> Anyways, modifiying SOAPpy might not be a bad idea: submit your changes
> to the project, and you can write on your CV that you have contributed
> to open-source projects! ;-)

Been there, done that. Don't worry, my contributions
to open-source projects is largely positive (though under
different aliases).

About SOAPpy: the author mentions something about
ordering (or not) parameters in the XML request. Quoting:

  "There is an incompatibility with the way that Python and
  SOAP handle method arguments: SOAP requires that
  all arguments have names and that they are presented
  in the same order as the method signature. [...]"

See SOAPpy/docs/MethodParameterNaming.txt for more
details.

> I do hope for you that you will find something better to do than
> pushing template-instances down a socket-hole.

It is not the first time I end up implementing some kind of
support for ASCII-based protocols with templatized strings
You would be surprised how easy it is to maintain when
the emitter is required to be as stable as possible. Just
have to be aware that you have a potential maintenance
nightmare somewhere out there.

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


SOAPpy question

2006-08-29 Thread Yusnel Rojas
hello ,I'm wondering if SOAPpy doesn't have something to generate a wsdl for a specific application.Let's say, I wrote a web service with SOAPpy, is there any way to generate the wsdl for it.
If there aren't can someone give a little example of both.
thanks



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

refering to base classes

2006-08-29 Thread glenn
hi - Im quite new to python, wondering if anyone can help me understand
something about inheritance here. In this trivial example, how could I
modify the voice method of 'dog' to  call the base class 'creatures'
voice method from with in it?

class creature:
def __init__(self):
self.noise=""
def voice(self):
return "voice:" + self.noise

class dog(creature):
def __init__(self):
self.noise="bark"

def voice(self):
print "brace your self:"

thanks
glenn

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


Re: Python editor

2006-08-29 Thread John Salerno
Jerry Fleming wrote:
> Larry Bates wrote:
>> Jason Jiang wrote:
>>> Hi,
>>>
>>> Could someone recommend a good Python editor? Thanks.
>>>
>>> Jason
>>>
>>>
>> For just getting started use Idle that comes with Python.
>> If you are already a user or if you are looking for a more
>> powerful solution you can use Eclipse (with Python plug-in).
>> These represent both ends of the spectrum in editors.
>>
>> -Larry Bates
> 
> Vim (vim-python) or emacs (python.el) is always the best solution.

Is it possible to get vim-python for Windows, or is that just a Linux build?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-29 Thread xhoster
Joachim Durchholz <[EMAIL PROTECTED]> wrote:
> Jim Gibson schrieb:
> >
> > The problem addressed by what is know in Perl as the 'Schwartzian
> > Transform' is that the compare operation can be an expensive one,
> > regardless of the whether the comparison uses multiple keys. Since in
> > comparison sorts, the compare operation will be executed N(logN) times,
> > it is more efficient to pre-compute a set of keys, one for each object
> > to be sorted. That need be done only N times.
>
> Wikipedia says it's going from 2NlogN to N. If a sort is massively
> dominated by the comparison, that could give a speedup of up to 100%
> (approximately - dropping the logN factor is almost irrelevant, what
> counts is losing that factor of 2).

It seems to me that ln 1,000,000 is 13.8, and that 13.8 is quite a bit
greater than 2.

Cheers,

Xho

-- 
 http://NewsReader.Com/ 
Usenet Newsgroup Service$9.95/Month 30GB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: refering to base classes

2006-08-29 Thread Chaz Ginger
glenn wrote:
> hi - Im quite new to python, wondering if anyone can help me understand
> something about inheritance here. In this trivial example, how could I
> modify the voice method of 'dog' to  call the base class 'creatures'
> voice method from with in it?
> 
> class creature:
> def __init__(self):
> self.noise=""
> def voice(self):
> return "voice:" + self.noise
> 
> class dog(creature):
> def __init__(self):
> self.noise="bark"
> 
> def voice(self):
> print "brace your self:"
> 
> thanks
> glenn
> 
Try this:

class dog(creature):
.
def voice(self):
print "brace your self:"
creature.voice(self)

This should do it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: refering to base classes

2006-08-29 Thread Chaz Ginger
Chaz Ginger wrote:
> glenn wrote:
>> hi - Im quite new to python, wondering if anyone can help me understand
>> something about inheritance here. In this trivial example, how could I
>> modify the voice method of 'dog' to  call the base class 'creatures'
>> voice method from with in it?
>>
>> class creature:
>> def __init__(self):
>> self.noise=""
>> def voice(self):
>> return "voice:" + self.noise
>>
>> class dog(creature):
>> def __init__(self):
>> self.noise="bark"
>>
>> def voice(self):
>> print "brace your self:"
>>
>> thanks
>> glenn
>>
> Try this:
> 
> class dog(creature):
> .
> def voice(self):
> print "brace your self:"
> creature.voice(self)
> 
> This should do it.
I did forget to mention that in 'dog"s' __init__ you had better call 
creature's __init__. You might make it look like this:

def __init__(self):
self.noise = 'bark'
creature.__init__(self)

There is another approach - using Superclass - but I will leave that 
exercise to the reader.

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


Re: Extending the dict class

2006-08-29 Thread Bruno Desthuilliers
chosechu wrote:
> Duncan Booth wrote:
>> No, you weren't able to extend the builtin dict class nor touch any its
>> constructor.
> 
> Yes, sorry. Forgot the negation.
> 
>> All you did was to create a subclass with its own constructor and hide the
>> name for the builtin dictionary type. The original type was still unchanged
>> as you can see since anything which constructed a dictionary without using
>> the name you had overwritten still got the original type.
>>
>> If you had looked at type(dict()) and type({}) after your subclassing, you
>> would see that they are different types.
> 
> ... which prompted my question.
> 
> And prompts yet another one: seems like it
> is not possible with Python to modify behaviour
> for base classes without recompiling the
> interpreter. Forgive me for asking what must
> surely have been asked already, but are there
> plans to implement something like that,
> like Ruby?
>
> I would not feel too safe navigating in a source
> where base object behaviour might have been
> re-defined, but it sure is a powerful way of
> adding behaviour to third-party code which you
> may not have possibility to modify.

It's usually possible to modify third-parts classes behaviour on the fly
(googling for 'monkey-patching' should get you started). But true, this
doesn't work with builtins.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: refering to base classes

2006-08-29 Thread Roberto Bonvallet
glenn wrote:
> [...] In this trivial example, how could I modify the voice method of
> 'dog' to  call the base class 'creatures' voice method from with in it?
> 
> class creature:
>def __init__(self):
>self.noise=""
>def voice(self):
>return "voice:" + self.noise
> 
> class dog(creature):
>def __init__(self):
>self.noise="bark"
> 
>def voice(self):
>print "brace your self:"

If you want dog.voice() to just print "voice: bark", you just have to omit
the voice method for the dog class: it will be inherited from creature.

If you want dog.voice() to do something else, you can call superclass'
method like this:

def voice(self):
creature.voice(self)
print "brace your self"
any_other_magic()

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


Re: Python editor

2006-08-29 Thread [EMAIL PROTECTED]
John Salerno wrote:
> Is it possible to get vim-python for Windows, or is that just a Linux build?

It builds for windows.

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


Re: refering to base classes

2006-08-29 Thread Bruno Desthuilliers
glenn wrote:
> hi - Im quite new to python, wondering if anyone can help me understand
> something about inheritance here. In this trivial example, how could I
> modify the voice method of 'dog' to  call the base class 'creatures'
> voice method from with in it?
> 
> class creature:
> def __init__(self):
> self.noise=""
> def voice(self):
> return "voice:" + self.noise
>
> class dog(creature):
> def __init__(self):
> self.noise="bark"
>
> def voice(self):
> print "brace your self:"



It might be better to use newstyle classes if you can. Also, the
convention is to use CamelCase for classes names (unless you have a
strong reason to do otherwise).


Here you could use a class attribute to provide a default:

class Creature(object):
  noise = ""

  def voice(self):
return "voice:" + self.noise


class Dog(Creature):
  noise="bark"

  def voice(self):
print "brace your self:"
return Creature.voice(self)
# can also use this instead, cf the Fine Manual
return super(Dog, self).voice()

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module

2006-08-29 Thread Roman
It turns out false alarm.  It work.  I had other logic in the
expression involving punctuation marks and got all confused with the
escape characters.  It becomes a mess trying to keep track of  all the
reserved character as you are going from module to module.


tobiah wrote:
> Roman wrote:
> > I looked at a book called beginning python and it claims that <.*?> is
> > a non-greedy match.
>
> Yeah, I get that now, but why didn't it work for you in
> the first place?
> 
> -- 
> Posted via a free Usenet account from http://www.teranews.com

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


Re: Python editor

2006-08-29 Thread Andrew Robert
[EMAIL PROTECTED] wrote:
> John Salerno wrote:
>> Is it possible to get vim-python for Windows, or is that just a Linux build?
> 
> 
> It builds for windows.
> 
When installed, you may also want to consider the python add-on located at

http://www.vim.org/scripts/script.php?script_id=790

Enhanced version of the original (from vim6.1) python.vim for Python
programming language.

The changes since the original python.vim are:

- changed strings highlighting;
- enhanced special symbols highlighting inside strings;
- enhanced numbers highlighting;
- added optional highlighting for %-formatting inside strings;
- added highlighting for some error conditions (wrong symbols in source
file,
  mixing spaces and tabs, wrong number values,
  wrong %-formatting inside strings);
- added highlighting for magic comments: source code encoding
  and #! (executable) strings;
- added highlighting for new exceptions and builtins introduced in
python 2.3, 2.4 and 2.5;
- added highlighting for doctests;
- added highlighting for new @decorator syntax introduced in Python 2.4a2;
- added highlighting for trailing-space errors (triggered by new
  option: python_highlight_space_errors);
- added highlighting for variable name errors;
- added highlighting for hex number errors;
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python editor

2006-08-29 Thread Neil Cerutti
On 2006-08-29, John Salerno <[EMAIL PROTECTED]> wrote:
>> Vim (vim-python) or emacs (python.el) is always the best
>> solution.
>
> Is it possible to get vim-python for Windows, or is that just a
> Linux build?

The windows binary for the latest version, 7.0, includes the
Python commands (the version 6 binaries for windows did not).

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


Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-29 Thread Gabriel Genellina

At Tuesday 29/8/2006 07:50, Joachim Durchholz wrote:


Wikipedia says it's going from 2NlogN to N. If a sort is massively
dominated by the comparison, that could give a speedup of up to 100%
(approximately - dropping the logN factor is almost irrelevant, what
counts is losing that factor of 2).


In fact it's the other way - losing a factor of 2 is irrelevant, 
O(2N)=O(N). The logN factor is crucial here.




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-29 Thread Fredrik Lundh
alf wrote:

> ok, let me clarify, by M$ I meant Micro$oft.

http://www.catb.org/~esr/faqs/smart-questions.html#writewell



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


Re: refering to base classes

2006-08-29 Thread Jason
Chaz Ginger wrote:
> Chaz Ginger wrote:
> > glenn wrote:
> >> hi - Im quite new to python, wondering if anyone can help me understand
> >> something about inheritance here. In this trivial example, how could I
> >> modify the voice method of 'dog' to  call the base class 'creatures'
> >> voice method from with in it?
> >>
> >> class creature:
> >> def __init__(self):
> >> self.noise=""
> >> def voice(self):
> >> return "voice:" + self.noise
> >>
> >> class dog(creature):
> >> def __init__(self):
> >> self.noise="bark"
> >>
> >> def voice(self):
> >> print "brace your self:"
>
> I did forget to mention that in 'dog"s' __init__ you had better call
> creature's __init__. You might make it look like this:
>
> def __init__(self):
>   self.noise = 'bark'
>   creature.__init__(self)
>

There's a problem with Chaz's __init__() method.  Notice that the
creature class's __init__ sets self.noise to the empty string.  In this
case, the superclass's __init__() method should be called first:

class dog(creature):
def __init__(self):
creature.__init__(self)
self.noise = "bark"
def voice(self):
print "brace your self:"
creature.voice(self)

  --Jason

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


Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Hendrik van Rooyen
"Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:

8<-

Here are some more results, three runs without, and three with a comment in the
body of the interesting loop:
(a summary follows the detail)

> python junk.py

0x501
Loop 1 Elapsed time is: 31.2168951035
Loop 1 used   : 16.39
Time out used was : 28
comment removed from Loop 1

0x501
Loop 2 Elapsed time is: 75.8846828938
Loop 2 used   : 37.93

> python junk.py

0x501
Loop 1 Elapsed time is: 31.3769760132
Loop 1 used   : 16.1
Time out used was : 28
comment removed from Loop 1

0x501
Loop 2 Elapsed time is: 76.4928090572
Loop 2 used   : 38.23

> python junk.py

0x501
Loop 1 Elapsed time is: 34.8213500977
Loop 1 used   : 18.24
Time out used was : 28
comment removed from Loop 1

0x501
Loop 2 Elapsed time is: 82.6038169861
Loop 2 used   : 39.13

> python junk.py

0x501
Loop 1 Elapsed time is: 36.7637741566
Loop 1 used   : 18.81
Time out used was : 28
comment inserted into Loop 1

0x501
Loop 2 Elapsed time is: 77.6277718544
Loop 2 used   : 38.82

> python junk.py

0x501
Loop 1 Elapsed time is: 37.6858890057
Loop 1 used   : 19.71
Time out used was : 28
comment inserted into Loop 1

0x501
Loop 2 Elapsed time is: 76.0855400562
Loop 2 used   : 38.04

> python junk.py

0x501
Loop 1 Elapsed time is: 35.0458369255
Loop 1 used   : 18.32
Time out used was : 28
comment inserted into Loop 1

0x501
Loop 2 Elapsed time is: 75.850135088
Loop 2 used   : 37.9

Summary of results:

Without comment:
Average elapsed time calculated by hand:  32.47
Average clock.clock() time :16.91
With comment:
Average elapsed time calculated by hand:  36.39
Average clock.clock() time :18.95
Normal loop performance over 6 runs:
Average elapsed time calculated by hand:  77.42
Average clock.clock() time :38.34


Conclusion 1:  The lower level test for the signal is far more efficient than
the Python comparison. - these kind of shenanigans are well worth while if the
loop is known to be a long running one.
Conclusion 2:  The setting of the appropriate time out is a PITA... (any ideas?)
Conclusion 3:  Don't put comments in the body of long running loops...
Conclusion 4:  (from earlier in the thread) - using calls are expensive...
Conclusion 5:  I learnt something - Thank you all...

Off topic Question - I see that giving the signal.alarm a float instead of an
integer gives a deprecation warning - does anybody know why this was decided? (I
was trying to do a binary search...)

Here is Claudio's code as I have hacked it:

import signal, time

def func1(timeout):

 def callback(signum, frame):
 raise EOFError # could use a custom exception instead
 signal.signal(signal.SIGALRM, callback)
 signal.alarm(timeout)

 count = 0
 try:
 while 1:
# this is a comment in the body of the loop
 count += 1
 except EOFError:
 while True:
 count += 1
 if count > 0x500:
 break
 print hex(count)

def func2():

 count = 0
 while True:
 count += 1
 if count > 0x500:
 break
 print hex(count)

def func3():
return 0

timeout = 28
print
startTime = time.time()
start_use = time.clock()
func1(timeout)
eltime = time.time() - startTime
utime = time.clock() - start_use
print "Loop 1 Elapsed time is:", eltime
print "Loop 1 used   :", utime
print "Time out used was :", timeout
print "comment inserted into Loop 1"

print
startTime = time.time()
start_use = time.clock()
func2()
eltime = time.time() - startTime
utime = time.clock() - start_use
print "Loop 2 Elapsed time is:", eltime
print "Loop 2 used   :", utime
print

- Hendrik




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


Re: refering to base classes

2006-08-29 Thread Chaz Ginger
Jason wrote:
> Chaz Ginger wrote:
>> Chaz Ginger wrote:
>>> glenn wrote:
 hi - Im quite new to python, wondering if anyone can help me understand
 something about inheritance here. In this trivial example, how could I
 modify the voice method of 'dog' to  call the base class 'creatures'
 voice method from with in it?

 class creature:
 def __init__(self):
 self.noise=""
 def voice(self):
 return "voice:" + self.noise

 class dog(creature):
 def __init__(self):
 self.noise="bark"

 def voice(self):
 print "brace your self:"
>> I did forget to mention that in 'dog"s' __init__ you had better call
>> creature's __init__. You might make it look like this:
>>
>> def __init__(self):
>>  self.noise = 'bark'
>>  creature.__init__(self)
>>
> 
> There's a problem with Chaz's __init__() method.  Notice that the
> creature class's __init__ sets self.noise to the empty string.  In this
> case, the superclass's __init__() method should be called first:
> 
> class dog(creature):
> def __init__(self):
> creature.__init__(self)
> self.noise = "bark"
> def voice(self):
> print "brace your self:"
> creature.voice(self)
> 
>   --Jason
> 
Very trueI was showing him in "spirit only"...lol.


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


Re: M$ windows python libs installed in arbitrary directories forcustomized python distributions

2006-08-29 Thread DH
Fredrik Lundh wrote:
> alf wrote:
> 
>> ok, let me clarify, by M$ I meant Micro$oft.
> 
> http://www.catb.org/~esr/faqs/smart-questions.html#writewell
> 
> 
> 

And by /F, you mean fuck off?

http://www.libervis.com/blogs/15/Jastiv/eric_raymond_and_the_rtfm_jerks
http://www.codinghorror.com/blog/archives/000603.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to let a loop run for a while before checking for break condition?

2006-08-29 Thread Fredrik Lundh
Sorin Schwimmer wrote:

> I am thinking on something in the following form:
> 
> 
> import time
> import thread
> 
> delay=True
> 
> def fn()
>   global delay
>   time.sleep()
>   delay=False
> 
> thread.start_new_thread(fn,())
> 
> while delay:
>  
>  
>  ...

if the loop calls out to python functions at least occasionally, you can 
eliminate the flag by abusing the interpreter's stack check mechanism:

import time, thread, sys

def alarm():
 time.sleep(1.234)
 sys.setrecursionlimit(1)

thread.start_new_thread(alarm, ())

def do_some_work():
 pass

t0 = time.time()
try:
 while 1:
do_some_work()
except RuntimeError:
 pass
print time.time() - t0



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


distributing modules to machines

2006-08-29 Thread r1pp3r
I'm in the the process of designing a build system written in python.
It runs from a central server with various build machines hosting
server processes, written in Python. Pyro is the chosen RPC mechanism.
What I would like to do is have the system update itself on demand. In
other words, pass pickled objects (the code comprising the server) down
the pipeline to the server, have them copied to the right place, and
then restart the server which can then invoke the new code. Is this
feasible? Will there be any other issues involved?

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


SWIG wrapper/Python2.5c1 problem

2006-08-29 Thread andrew . gregory
If compiling a SWIG wrapper with MinGW 3.2.3 (Windows) get the
following compilation error:

pyprog_wrap.cxx: In function `int
SWIG_Python_ConvertFunctionPtr(PyObject*,
   void**, swig_type_info*)':
pyprog_wrap.cxx:2051: invalid conversion from `const char*' to `char*'

Extract from wrapper:

/* Convert a function ptr value */

SWIGRUNTIME int
SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr,
swig_type_info *ty) {
  if (!PyCFunction_Check(obj)) {
return SWIG_ConvertPtr(obj, ptr, ty, 0);
  } else {
void *vptr = 0;

/* here we get the method pointer for callbacks */
char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);  <--
error occurs here.

This must be caused by a change in Python.h, as there were no problems
with Python 2.3 or 2.4. SWIG version 1.3.29. Used -c++  and -shadow
options.

Can anyone reproduce this?

Andrew.

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


Re: How ahead are you guys in the (Python) real world?

2006-08-29 Thread [EMAIL PROTECTED]
Ray wrote:
> Since I haven't used Python at work, I am using Python 2.5 right now.
> However I wonder, how fast are you guys moving from version to version
> at work? As an illustration my ex-company just moved to Java 5, which
> was released around... what, 2-3 years ago? (While I am running Java 6
> at home)

We are using 2.2 most places, with 2.3 on a few dev boxes.  We're
planning an update to 2.4 in the next couple of months.

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


Re: ntp in python

2006-08-29 Thread Janto Dreijer
Jeremy Sanders wrote:
> Janto Dreijer wrote:
>
> > I want to measure the packet delivery delays over various network
> > links. For this I need to synchronise the times of the sender and
> > receiver, either against NTP or eachother.
>
> Couldn't you just use NTP itself to get the delivery delay? You can read the
> delay out from the ntpdc console using dmpeers, or lopeers in ntpq. You
> could have two peers either side of the link and measure the delay from
> NTP.
>
> You may also be able to query remote ntp servers to get their delays to
> their peers.

Unfortunately I don't think that would work for me. I need the delay of
a stream of packets. Not just a single delay number. More specifically:
I'm testing RTP (VoIP) packet speeds and would like to predict lag
(ignoring jitter...separate measurement).

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


Re: Desktop Notification/Alerts In Python

2006-08-29 Thread Chaos

alex23 wrote:
> Chaos wrote:
> > I am looking for ways to have a Desktop Alert, like the one most IM
> > Messengers have (MSN, AIM) at the lower right above the taskbar. Can
> > anyone point me to the right resources to use?
>
> Under Windows, they're called "balloon tips". Here's a thread from a
> few years back asking for the exact same thing:
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/f6f6083650b50f1d/f26db0efc52462f9#f26db0efc52462f9
>
> There's even a working demo linked to at the end of the thread, and the
> link is still live.
>
> Thanks for prompting me to look, I've vaguely wanted something like
> this for a while :)
>
> -alex23

Is there a way to make it a window, instead of a baloon time. One that
slides up from the  taskbar?

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


Re: distributing modules to machines

2006-08-29 Thread Fredrik Lundh
r1pp3r wrote:

> What I would like to do is have the system update itself on demand. In
> other words, pass pickled objects (the code comprising the server) down
> the pipeline to the server, have them copied to the right place, and
> then restart the server which can then invoke the new code.

should work (assuming you trust the various systems involved, and your 
own ability to avoid deploying broken code)

but using a custom protocol for this sounds like a slight overkill, 
though.  I would probably use rsync (over ssh) at regular intervals, or, 
if we're only talking about small amounts of code, a bootstrap script 
that fetches the current version over http(s) every time the server starts.

(in the http case, you can use etag/if-modified-since to avoid 
downloading things if they haven't changed, but if you're on a fast 
network, that probably won't matter much).



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


Re: about daemons and IPC

2006-08-29 Thread Irmen de Jong
[EMAIL PROTECTED] wrote:
> Hey people!
> For the first time I'm doing a client/server application, and I'm
> really confused with IPC stuff.
[...]
> Any suggestions?


http://pyro.sourceforge.net

depending on your needs

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


sys.argv[0] doesn't always contain the full path of running script.

2006-08-29 Thread gmax2006
Hi,

I use RedHat linux.

How can I find where exactly the current python script is running?

I use this code:

#test.py
import os,sys
print sys.argv
os.chdir(os.path.dirname(sys.argv[0]))


It doesn't work when I run this command from the directory that
test.py is located:

python test.py

That means sys.argv[0] doesn't always contain the full path of
running script.

Any help would be appreciated,
Max

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


  1   2   >