multi regexp analyzer ? or how to do...

2005-06-30 Thread joh12005
Hello,

here is a trouble that i had, i would like to resolve it with python,
even if i still have no clue on how to do it.

i had many small text files, so to speed up processes on them, i used
to copy them inside a huge one adding some king of xml separator :

file name=...
[content]
/file

content is tab separated data (columns) ; data are strings

now here come the tricky part for me :

i would like to be able to create some kind of matching rules, using
regular expressions, rules should match data on one line (the smallest
data unit for me) or a set of lines, say for example :

if on this line , match first column against this regexp and match
second column
and on following line match third column
- trigger something

so, here is how i had tried :

- having all the rules,
- build some kind of analyzer for each rule,
- keep size of longest one L,
- then read each line of the huge file one by one,
- inside a file, create all the subsets of length = L
- for each analyzer see if it matches any of the subsets
- if it occurs...

my trouble is here :

for each analyzer see if it matches any of the subset

it is really to slow, i had many many rules, and as it is for loop
inside for loop, and inside each rule also for loop on subsets lines
i need to speed up that, have you any idea ?

i am thinking of having only rules for one line and to keep traces of
if a rule is a ending one (to trigger something) , or a must
continue , but is still unclear to me for now...

a great thing could also have been some sort of dict with regexp
keys...

(and actually it would be great if i could also use some kind of regexp
operator to tell one can skip the content of 0 to n lines before
matching, just as if in the example i had changed following... by
skip at least 2 lines and match third column on next line - it would
be great, but i still have really no idea on how to even think about
that)

great thx to anybody who could help,

best

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


Re: need help with MySQLdb

2005-06-30 Thread Wolfram Kraus
[EMAIL PROTECTED] wrote:
 Hey there all,
 i have a question about how to point my python install to my sql
 database.
 
 when i enter this: db = MySQLdb.connect(user=user, passwd=pass,
 db=myDB)
 
 i get this:
 Traceback (most recent call last):
   File pyshell#1, line 1, in -toplevel-
 db = MySQLdb.connect(user=user, passwd=pass, db=MyDB)
   File /usr/lib/python2.4/site-packages/MySQLdb/__init__.py, line 66,
 in Connect
 return Connection(*args, **kwargs)
   File /usr/lib/python2.4/site-packages/MySQLdb/connections.py, line
 134, in __init__
 super(Connection, self).__init__(*args, **kwargs2)
 OperationalError: (1049, Unknown database 'MyDB')
 
 i am using the all in one package from lampp (now xampp) and i have
 tested a couple of python scripts from the cgi, but nothing that
 connects to the database.
 
 any ideas?
 
 thanks
 
Try the following from the shell (NOT the python shell):
mysql -u user -p
[Enter passwd]
mysql show databases;

If MyDB isn't in the list either something went wrong with the xampp 
installation or the database for xampp got a different name. (I am no 
xampp expert, so I can't help you any further)

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


Re: Favorite non-python language trick?

2005-06-30 Thread Paddy
Sadly, its not a solution that I'm after, but a particular toolkit that
can be used for solving that type of problem.

- Pad.

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


Re: some trouble with MySQLdb

2005-06-30 Thread dimitri pater
try:
db = MySQLdb.connect(host=localhost, user=user, passwd=pass,
db=myDB)
localhost can be a URL also (if MySQL is set up properly in the first place)
regards,
DimtiriOn 6/30/05, nephish [EMAIL PROTECTED] wrote:
Hey there all,i have a question about how to point my python install to my sql database.when i enter this: db = MySQLdb.connect(user=user, passwd=pass,db=myDB)i get this:
Traceback (most recent call last):File pyshell#1, line 1, in -toplevel-db = MySQLdb.connect(user=user, passwd=pass, db=MyDB)File /usr/lib/python2.4/site-packages/MySQLdb/__init__.py, line 66,
in Connectreturn Connection(*args, **kwargs)File /usr/lib/python2.4/site-packages/MySQLdb/connections.py, line134, in __init__super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, Unknown database 'MyDB')i am using the all in one package from lampp (now xampp) and i havetested a couple of python scripts from the cgi, but nothing thatconnects to the database.
any ideas?thanks--http://mail.python.org/mailman/listinfo/python-list-- Please visit dimitri's website: 
www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

python install settings...

2005-06-30 Thread jtan325
hi,

i am running Linux Ubuntu Hoary and am trying to build the Python
numarray package, v. 1.3.2 by hand since ubuntu's repos won't be
updated until breezy.

i have python 2.4, and gcc 3.3.5

after unpacking the tar, i run python setup.py install, as it says in
the installation instructions. i get the following:

[colfax 53] numarray-1.3.2  python setup.py install
Using EXTRA_COMPILE_ARGS = []
running install
running build
running build_py
copying Lib/numinclude.py - build/lib.linux-i686-2.4/numarray
running build_ext
Traceback (most recent call last):
  File setup.py, line 222, in ?
main()
  File setup.py, line 213, in main
setup(**p)
  File /usr/lib/python2.4/distutils/core.py, line 149, in setup
dist.run_commands()
  File /usr/lib/python2.4/distutils/dist.py, line 946, in
run_commands
self.run_command(cmd)
  File /usr/lib/python2.4/distutils/dist.py, line 966, in run_command
cmd_obj.run()
  File /usr/lib/python2.4/distutils/command/install.py, line 506, in
run
self.run_command('build')
  File /usr/lib/python2.4/distutils/cmd.py, line 333, in run_command
self.distribution.run_command(command)
  File /usr/lib/python2.4/distutils/dist.py, line 966, in run_command
cmd_obj.run()
  File /usr/lib/python2.4/distutils/command/build.py, line 112, in
run
self.run_command(cmd_name)
  File /usr/lib/python2.4/distutils/cmd.py, line 333, in run_command
self.distribution.run_command(command)
  File /usr/lib/python2.4/distutils/dist.py, line 966, in run_command
cmd_obj.run()
  File /usr/lib/python2.4/distutils/command/build_ext.py, line 254,
in run
customize_compiler(self.compiler)
  File /usr/lib/python2.4/distutils/sysconfig.py, line 174, in
customize_compiler
cc_cmd = cc + ' ' + opt
TypeError: cannot concatenate 'str' and 'NoneType' objects


I had a similiar (but different) error earlier, but then I learned I
had to set my CC environment variable. So I set that to gcc. i have
tried setting my OPT setting to something like -g 02 (no idea what
it means just found it somewhere, but it still didn't work.

upon closer inspection of Python's distutils sysconfig.py, is the error
being caused by the ' ' in cc_cmd = cc + ' ' + opt? Any ideas on this
new error? Are there packages/settings I need to take care of before i
can use Python's distutils to install stuff?

Thanks,
Jason

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


Re: aligning text with space-normalized text

2005-06-30 Thread Peter Otten
Steven Bethard wrote:

 I have a string with a bunch of whitespace in it, and a series of chunks
 of that string whose indices I need to find.  However, the chunks have
 been whitespace-normalized, so that multiple spaces and newlines have
 been converted to single spaces as if by ' '.join(chunk.split()).  Some

If you are willing to get your hands dirty with regexps:

import re
_reLump = re.compile(r\S+)

def indices(text, chunks):
lumps = _reLump.finditer(text)
for chunk in chunks:
lump = [lumps.next() for _ in chunk.split()]
yield lump[0].start(), lump[-1].end()


def main():
text = \
   aaa  bb ccc
dd eee.  fff 
hh   i.
   jjj kk.

chunks = ['aaa bb', 'ccc dd eee.', 'fff  hh i.', 'jjj', 'kk.']
assert list(indices(text, chunks)) == [(3, 10), (11, 22), (24, 40), (44,
47), (48, 51)]

if __name__ == __main__:
main()

Not tested beyond what you see.

Peter

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


Re: Inheriting from object

2005-06-30 Thread Fuzzyman
The reason I ask is that I often (well... a couple of times anyway) see
cryptic omments like :

and if you inherit from object you get all the benefits of new
style classes

Now I know about the advantages of inheriting from the built in types
(if that's what you want to do) -but am a bit fuzzier on the 'general
benefits'.

I'm vaguely aware of properties I'll have to explore them at some
point.

Best Regards,

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

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


twisted: not doing DNS resolutions?

2005-06-30 Thread Christopher Subich
I'm building an application that makes several user-specified internet 
connections; twisted meets my needs more or less perfectly.

I'm running into a problem, however, in that twisted is not allowing 
connections (reactor.connectTCP) by hostname, only IP address. [read: 
connections to IP addresses work fine, hostnames no]

 From what I can tell, the problem lies in that Twisted simply isn't 
performing the DNS resolutions.  From the connection factory's 
startedConnecting method, print connector.getDestination() results in:

IPv4Address(TCP, 'hostname', port)

That is to say, the port is correct, but the 'hostname' is completely 
unresolved.  Since 'hostname' is a really bad IP address, not being one 
at all, the connection of course fails.  A check via tcpdump on my 
gateway machine shows that the DNS resolution doesn't occur.

The API documentation for version 1.3 (I'm using 2.0.1, but a quick 
check of twisted source/docstrings shows this to be still true[1]) shows 
that connectTCP taks a host name, so by that (and the echo client 
example that connects to 'localhost') I presume there's supposed to be 
some sort of resolution going on.

I'm running twisted 2.0.1 on win32.  Is this a bug in twisted, or is 
there some configuration that I've gone and borked?

[1] -- is there some reason in particular that there's no API reference 
for twisted 2.0x? The documentation/tutorials are pretty sparse as-is, I 
think.
-- 
http://mail.python.org/mailman/listinfo/python-list


re:Open running processes

2005-06-30 Thread DeRRudi
Well i want a external app to maximize and minimize my app.
And later on i want the external one to send some data. Thought this
would be the most easy (and fast) way! 

Greetz

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


Re: Reading output from a child process non-blockingly

2005-06-30 Thread Adriaan Renting
I use the pty module, in combination with select.select.
Search for Pexpect for an elaborate example.
It basically goes something like this:


-
import os, select, pty

pid, fd = pty.fork()
fd_eof = 0
if pid == 0:
 os.execvp('ls',['ls']) # child process
else: # parent proces
 while not fd_eof:
   ready = select.select([fd], [], [], 0.25)
   if fd in ready[0]:
 text = os.read(fd, 1024)
 if text == '':
   fd_eof = 1
 else: print text
-
In 2.3.4 this exits with an exception OSError: [Errno 5] Input/output
error after showing the 'ls' output, I have a problem that this works in
2.3.4 but in 2.3.5 this just keeps running indefinately. In my own code
I handle the OSError by setting fd_eof=1. This onyl works on Unix.


Adriaan Renting| Email: [EMAIL PROTECTED]
ASTRON | Phone: +31 521 595 217
P.O. Box 2 | GSM:   +31 6 24 25 17 28
NL-7990 AA Dwingeloo   | FAX:   +31 521 597 332
The Netherlands| Web: http://www.astron.nl/~renting/
 Yuan HOng [EMAIL PROTECTED] 06/29/05 10:08 AM 
In my program I have to call an external program and parse its output.
For that I use the os.popen2 function, and then read the output
stream.

But the complexity is that the external program gives back its output
in a piecemeal manner, with long delays between the outputs. In the
main program I want to therefore read the output in a non-blocking
manner, to read as many bytes as the child process is spitting out.

The question is, how can I achieve that?

I tried use select.select on the output stream returned by os.popen2,
but it returns a readable file descriptor only after the whole child
process ends.

Here is a script simulating the external program:

test.py:
import sys, time
print 'hello\n'*500
sys.stdout.flush()
time.sleep(100)
print 'world\n'*500 

And here is what I am tring to do in the main program to read its
output:

import os, select
cmd = 'python test.py'
pin, pout = os.popen2(cmd)
while not select.select([pout], [], [], some_timeout)[0]:
  pass
pout.readline()

I hope to get the first return very soon, before the external program
sleeps, but instead only after the whole program exits do I get any
output.

Can anyone give me a hint?

-- 
Hong Yuan

 
www.homemaster.cn
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Re: MS Compiler to build Python 2.3 extension

2005-06-30 Thread woodsplitter
MS Visual C++ 6 is indeed the compiler that the python.org
distributions are built with, but MinGW works fine too.  In fact, the
code generated by MinGW-GCC 3.4.4 outpaces that generated by MSVC++ 6.0
by a considerable margin in some of my performance-critical extensions,
and the size of the binaries is often smaller.

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


Re: Favorite non-python language trick?

2005-06-30 Thread Brian Elmegaard
Joseph Garvin [EMAIL PROTECTED] writes:

 I'm curious -- what is everyone's favorite trick from a non-python
 language? 

Metapost solution of linear equations:
x1+9=x2-8=2;

 And -- why isn't it in Python?

I'd like to know too.

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Open running processes

2005-06-30 Thread Tim Golden
[DeRRudi]
| Well i want a external app to maximize and minimize my app.
| And later on i want the external one to send some data. Thought this
| would be the most easy (and fast) way! 
| 
| Greetz
| 

Rudi. I, at least, am reading this via the mailing list, not
via Usenet nor via Google. This means that if you don't put
any kind of context in what you post, I have to guess at what
you're responding to. (All I see is the exact text you typed,
nothing else).

Assuming that you're answering my question: why use mmap and
not just two events? I understand what your overall plan is,
and it looks like you have a way to solve it. It just seemed
that you might be able to achieve the same thing with two
events: one for maximize and one for minimize. Why would
this be better? Well, only because it seems to me slightly simpler
than one event and a separate mmap mechanism. But I've never
done what you're doing, so I may well be completely wrong.

TJG


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

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


Re: twisted: not doing DNS resolutions?

2005-06-30 Thread Christopher Subich
Christopher Subich wrote:
  From what I can tell, the problem lies in that Twisted simply isn't 
 performing the DNS resolutions.  From the connection factory's 
 startedConnecting method, print connector.getDestination() results in:
 
 IPv4Address(TCP, 'hostname', port)

Update: after doing some diving in the twisted source, it is supposed to 
do that.  My guess is that either it thinks the hostname is a valid ip 
address (unlikely), or a callback isn't actually getting called.  This 
confuses me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Acceptance test spike example

2005-06-30 Thread Steve Jorgensen
On Sun, 26 Jun 2005 16:10:05 -0700, Steve Jorgensen [EMAIL PROTECTED]
wrote:

I'm posting this message for 2 reasons.

First, I'm still pretty new and shakey to the whole Acceptance Testing thing,
and I'm hoping for some feedback on whether I'm on the right track.  Second,
although all the Agile literature talks about the importance of doing
Acceptance Testing, there's very little in any of the books or out on the Web
that helps with how to do it.  If I am on the right track, this will be one
more helpful item folks can find on a Google search.

The code below is basically a spike I wrote in a few hours last night to prove
to myself and my team that it would be feasible to quickly create a simple,
useful Acceptance Testing harness for our learning project.
...

Here's an updated script and code to process the script.  I made the script
syntax more friendly.


New example script...

==
Check  recipeListCount is 0

Do new
Check  name is New Recipe

Keyin  PBJ to name
Ch eck  name is PBJ

Do save
Do close
Check  recipeListCount is 1

Do goToListItem 1
Do openListItem
Check  name is PBJ
==


New Python code for test runner including skeleton of application model that
can be tested, but can't pass the tests...

==
import string


class RecipeOrgModel:
recipeListCount = 0
name = New Recipe

def new(self):
pass

def save(self):
pass

def close(self):
pass

def goToListItem(self,itemNum):
pass

def openListItem(self):
pass


class Action:
failMessage = 

def __init__(self, actionArgs):
pass

def tryAction(self, model):
return True


class NoAction (Action):
pass

class ActionDo (Action):
item  = 
args = 

def __init__(self, actionArgs):
delimPos = string.find(actionArgs,  )
self.args = 
if delimPos==-1:
self.item = actionArgs
else:
self.item = actionArgs[0:delimPos]
self.args = string.strip(actionArgs[delimPos+1:])

def tryAction(self, model):
methodCall = model. + self.item +( + self.args + )
exec(methodCall)
return True


class ActionKeyin (Action):
item  = 
value = 

def __init__(self, actionArgs):
delimPos = string.find(actionArgs,  to )
self.args = 
if delimPos==-1:
self.item = actionArgs
else:
self.value = eval( actionArgs[0:delimPos] )
self.item = string.strip(actionArgs[delimPos+len( to ):])

def tryAction(self, model):
setattr(model, self.item, self.value)
return True


class ActionCheck (Action):
item  = 
expectValue = 

def __init__(self, actionArgs):
delimPos = string.find(actionArgs,  is )
self.args = 
if delimPos==-1:
self.item = actionArgs
else:
self.item = actionArgs[0:delimPos]
self.expectValue = eval( string.strip(actionArgs[delimPos+len( is
):]) )

def tryAction(self, model):
valueIs = getattr(model, self.item)
if self.expectValue == valueIs:
return True
else:
self.failMessage = ( Expected  + str(self.expectValue) +
  but got  + str(valueIs) )
return False


class ActionUnknown (Action):
actionArgs = 

def __init__(self, actionArgs):
self.actionArgs = actionArgs

def tryAction(self, model):
self.failMessage = Test statement not understood:  + self.actionArgs
return False


def MakeTestAction(lineText):
delimPos = string.find(lineText,  )
commandArgs = 
if delimPos==-1:
commandType = lineText
else:
commandType = lineText[0:delimPos]
commandArgs = string.strip(lineText[delimPos+1:])

if commandType == Do:
return ActionDo(commandArgs)
elif commandType == Keyin:
return ActionKeyin(commandArgs)
elif commandType == Check:
return ActionCheck(commandArgs)
elif commandType == :
return NoAction(commandArgs)
else:
return ActionUnknown(commandType +   + commandArgs)


class TestSession:
fileName=
lines = None
model = RecipeOrgModel()

def __init__(self,fileName):
self.fileName = fileName

def run(self):
self.loadLines(self.fileName)

for line in self.lines:
print(line)
action = MakeTestAction(line)
actionOk = action.tryAction(self.model)
if not actionOk:
print( !!!  + action.failMessage)
break

def loadLines(self, fileName):
file = open(fileName)
lines = file.readlines()
file.close

lines = map(string.strip,lines)
self.lines = lines


session = TestSession(test1.txt)
session.run()
==


Ouptut of test runner using 

Re: When someone from Britain speaks, Americans hear a British accent...

2005-06-30 Thread Simon Brunning
On 29 Jun 2005 15:34:11 -0700, Luis M. Gonzalez [EMAIL PROTECTED] wrote:
 What's exactly the cockney accent?
 Is it related to some place or it's just a kind of slang?

A cockney is a *real* Londoner, that is, someone born within the City
of London, a.k.a The Square Mile. More specifically, it's someone born
within the sound of Bow Bells - i.e. close to St Mary le Bow, London
- http://maps.google.co.uk/maps?q=EC2V+6AU. This is within the
theoretical sound of Bow Bells, you understand - there have been
frequent and lengthy periods during which Bow Bells have not been rung
at all. There are in fact no longer any hospitals with maternity units
within the sound of Bow Bells, so there will be vanishingly few
cockneys born in future.

Strangely enough, this makes *me* a cockney, though I've never lived
in the square mile, and my accent is pretty close to received. I do
*work* in the City, though!

The cockney accent used to be pretty distinct, but these days it's
pretty much merged into the Estuary English accent common throughout
the South East of England.

 I'm not sure, but I think that I read somewhere that it is common in
 some parts of London, and that it is a sign of a particular social
 class, more than a regionalism. Is that true?

Cockney was London's working class accent, pretty much, thought it was
frequently affected by members of the middle classes. Estuary English
has taken over its position as the working class accent these days,
but with a much wider regional distribution.

How off topic is this? Marvellous!

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


Re: Thoughts on Guido's ITC audio interview

2005-06-30 Thread Stephen Kellett
In message [EMAIL PROTECTED], Markus Wankus 
[EMAIL PROTECTED] writes
just think it is silly not to benefit from them.

In which case you misunderstood me - I never said people should not use 
them, just that they should not be relied on for productivity 
improvements. They must factor in at a fraction of 1% of productivity. I 
don't really class improvements at that level as much to be shouted 
about :-)

Stephen
-- 
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE: Open running processes

2005-06-30 Thread DeRRudi
 Tim Goldenwrote:

 
 Rudi. I, at least, am reading this via the mailing list, not
 via Usenet nor via Google. This means that if you don't put
 any kind of context in what you post, I have to guess at what
 you're responding to. (All I see is the exact text you typed,
 nothing else).
 
 Assuming that you're answering my question: why use mmap and
 not just two events? I understand what your overall plan is,
 and it looks like you have a way to solve it. It just seemed
 that you might be able to achieve the same thing with two
 events: one for maximize and one for minimize. Why would
 this be better? Well, only because it seems to me slightly simpler
 than one event and a separate mmap mechanism. But I've never
 done what you're doing, so I may well be completely wrong.
 
 TJG
 

Hi Tim,

I'm sorry did not realize it! 
U are right! (i believe) at first i put in the minimize for testing.
I'm only using the maximize.
But it seemed handy to do it this way and beeing abled to send over
data from an other programm. That's what i want to use the mmap for.
Or am i missing something. because i'm not really seeing what your
point is. Because it is a complete different process what is calling
the maximize (or minimize) i can't just create an event and call it
(or can i?)

Greetz

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


RE: RE: Open running processes

2005-06-30 Thread Tim Golden
[DeRRudi]
|  Tim Goldenwrote:
| 
|  Assuming that you're answering my question: why use mmap and
|  not just two events? I understand what your overall plan is,
|  and it looks like you have a way to solve it. It just seemed
|  that you might be able to achieve the same thing with two
|  events: one for maximize and one for minimize. Why would
|  this be better? Well, only because it seems to me slightly simpler
|  than one event and a separate mmap mechanism. But I've never
|  done what you're doing, so I may well be completely wrong.
|  
|  TJG
|  
| 
| Hi Tim,
| 
| U are right! (i believe) at first i put in the minimize for testing.
| I'm only using the maximize.
| But it seemed handy to do it this way and beeing abled to send over
| data from an other programm. That's what i want to use the mmap for.
| Or am i missing something. because i'm not really seeing what your
| point is. Because it is a complete different process what is calling
| the maximize (or minimize) i can't just create an event and call it
| (or can i?)
| 
| Greetz

If you wanted to send over arbitrary data from another application,
then this is certainly a way to do it. (Another way might be to use a
Windows pipe, for example). My point was only that if you are signalling
an event as a wake-up call plus an atom of extra information saying 
max or min, and you weren't considering any expansion of this 
vocabulary to include other commands, then two distinct events might 
be simpler, one signalling maximize, the other minimize. 

Please don't take this as any criticism of your work: there's no one
right design decision here; I was merely curious as to the reasons
behind yours.

TJG


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

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


Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-30 Thread Antoon Pardon
Op 2005-06-29, Scott David Daniels schreef [EMAIL PROTECTED]:
 Roy Smith wrote:
 Andrew Durdin [EMAIL PROTECTED] wrote:
Corrected version:
result = [(lambda: expr0), lambda: expr1][bool(cond)]()
 Sorry, I thought cond was a standard boolean.
 Better is:
  result = [(lambda: true_expr), lambda: false_expr][not cond]()

How about the following:

  result = (cond and (lambda: true_expr) or (lambda: false_expr))()

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


Re: Favorite non-python language trick?

2005-06-30 Thread Terry Hancock
On Wednesday 29 June 2005 10:51 pm, Paddy wrote:
 Joseph Garvin wrote:
   'm curious -- what is everyone's favorite trick from a non-python
   language? And -- why isn't it in Python?
 
 I use constraints programming at work, Check out System Verilog  or
 OZ/Mozart.
 
 It would be great if this style of programming could be added to
 Python.

Check out:
http://www.logilab.org/projects/python-logic/

In short, it has been already.

This is something pretty new to me, so I can't comment on how well
it would meet your expectations, but I see now that the site does mention
OZ/Mozart as comparables.

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

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


Re:

2005-06-30 Thread Adriaan Renting
I do fundamentally not agree with you that IDE's and GUI design tools
are a waste of time.

I think that with a good IDE (graphical or not) the synergy between
editor, debugger, documentation, refactoring,
translations/internationalization, version control, software modelling,
profiling, metrics, can be very valuable.
Example: At my first employer we could do the same projects in 60% of
the time with Borland C++Builder, compared to MS VisualC++ 6. We would
put this into offerings to customers, esp. if they had a corporate
policy prefering VS 5 or 6.
Some features I realy line about some IDE's I've used:
- Automatic generation of UML diagrams from project code.
- Runtime expression evaluation/data inspection/editing.
- Pressing F1 will bring up the documentation of the class and method
your cursor is on.
- The debugger detects if an object is never deleted in C++, and put me
on the right line in the editor where it is created.
- Include trees.
- Code completion.
- Automatic management of versions in different languages.
- Comparison with older versions of the code.
- Wizards to generate often used dialogs.

If you have never tried Java with Eclipse, C++ with C++Builder or
VisualStudio.Net 2003, or even Python with the less elaborate
Eric3+QtDesigner, then I suggest you do.
Of all the Widget sets I've used (MFC, VCL, wxWindows, TVision, Athena,
Qt) I consider Qt the easiest, it's even available for free on Windows
now!

There is one danger in using IDE's to design GUI's, which is that you do
not properly separate your GUI code from the mechanics of the program.

I think that the natural way to design a GUI is with a WYSIWYG tool.
You have a valid point that you have to conform to the IDE generated
code to some extent. A good IDE will have a nonobtrusive way of handling
this.

--- Everything below here is Harry George's mail.
--
--- No the e-mail program I am forced to use does not support
quoting. -
 [EMAIL PROTECTED] 06/28/05 9:15 PM

#! rnews 2994
Newsgroups: comp.lang.python
Path:
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp
From: Harry George [EMAIL PROTECTED]
Subject: Re: Boss wants me to program
X-Nntp-Posting-Host: cola2.ca.boeing.com
Content-Type: text/plain; charset=us-ascii
Message-ID: [EMAIL PROTECTED]
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4
Lines: 57
Sender: [EMAIL PROTECTED]
Organization: The Boeing Company
References: [EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Mime-Version: 1.0
Date: Tue, 28 Jun 2005 18:58:08 GMT
Xref: news.xs4all.nl comp.lang.python:383798

phil [EMAIL PROTECTED] writes:

 
  You are quite correct to point out how much better it is to know
what is
  going on behind the scenes.  But heck, once you know how to extract
square
  roots - you need to let the computer do it!
  GUI interfaces should be the same deal!
  Thomas Bartkus
 
 I think I pretty much agree. I essentially code my own gui builder
 
 but in text files.
 
 I just think it is really important to emphasise the operative
 but once you know how in your comments.
 
 Then some would counter with oh, so we should code everthing
 in assembler?  Ouch. No, I will admit there is judgement
 required.  Everything should be done the easiest way, with the
 qualification that you need to understand how using someone
 else's shortcut leaves you vulnerable.


I agree with your comments on Python and java and IDEs.  I'd like to
expand on the code in assy complaint.

Compiled-to-assy-to-machine-to-execution is understood and
algorithmic.  Any one person may no know it al,l but every step of the
way has been thought out and optimized by someone who knew what he/she
was doing.  There are very few places where anyone has to dive down
into assy, much less microcode or VLSI layouts.

Therefore, we can trust the abstract model provided by the programming
language, and can stay in that model.

This is not the case for GUIs.  We can't safely stay in the abstract
GUI IDE.  In fact, most require you to dive into the generated code to
finish the task.  Bouncing up and down the abstraction ladder is hard
and made harder by being forced to live in the IDE's idea of generated
code.

Given that, GUI IDEs are still helpful if your base langauge is a pain
to write and debug (e.g., C++, Java).  But if your language is
actually easier to use than the GUI IDEs, then the equation shifts.
With Python, the clarity of thought and the opportunities for
higher-level programming (dynamic code genration et al) make GUI IDEs
just a waste of time or worse.

I also have moved to text-based inputs to my own GUI builders.  Maybe
there is a sourceforge project waiting to be borne here :-)

[snip]

-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 

Re: Reading files in /var/spool/rwho/whod.*

2005-06-30 Thread Fredrik Normann
Dennis Lee Bieber wrote:
 On Mon, 27 Jun 2005 13:26:12 +0200, Fredrik Normann [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:
 
 
Hello,

I'm trying to read the binary files under /var/spool/rwho/ so I'm wondering 
if 
anyone has done that before or could give me some clues on how to read those 
files. I've tried to use the binascii module without any luck.

 
   Have you looked at the struct module?
 

Thanks for the tip. A friend of mine helped me with making this small script:


#!/usr/bin/env python

whod file parser.

Made by: Igor V. Rafienko

This tiny script tries to grock whod files.



from struct import calcsize, unpack, pack
from socket import ntohl
import time





outmp_format = '8s8s4s'
whoent_format = '%ds4s' % calcsize(outmp_format)
almost_whod = 'cc2s4s4s32s12s4s'


def make_string(s):
 Stupid C. Chop the string off at the first '\0'.

 index = s.find('\0')
 if index != -1:
 return s[:index]
 # fi
# end make_string


def make_time(seconds):
 Convert from seconds since Epoch to ISO8601.

 return time.strftime(%Y-%m-%dT%H:%M:%S, time.localtime(seconds))
# end make_time


def make_int(binary):
 Convert binary from network representation to host int.

 assert len(binary) == 4, ints are 4 bytes long here

 if calcsize(i) == 4:
 return ntohl(unpack(i, binary)[0])
 elif calcsize(l) == 4:
 return ntohl(unpack(l, binary)[0])
 else:
 raise Dammit! no suitable integral type
 # fi
# end make_int


def parse_one_outmp(binary_data):
 Parse an outmp struct.

 out_line, out_name, out_time = unpack(outmp_format, binary_data)
 out_time = make_int(out_time)

 return out_line, out_name, out_time
# end parse_one_outmp


def parse_one_whoent(binary_data):
 Parse a whoent struct.

 outmp_part, we_idle = unpack(whoent_format, binary_data)

 we_idle = make_int(we_idle)
 out_line, out_name, out_time = parse_one_outmp(outmp_part)

 return out_line, out_name, out_time, we_idle
# end parse_one_whoent


def parse_one_file(binary_data):
 Parse the entire thing.

 # First we parse everything, except for the whoent-array
 prefix = unpack(almost_whod, binary_data[:calcsize(almost_whod)])

 print prefix has %d elemenets % len(prefix)
 print wd_vers:, ord(prefix[0])
 print wd_type:, ord(prefix[1])
 print wd_fill:, make_string(prefix[2])
 print wd_sendtime:, make_time(make_int(prefix[3]))
 print wd_recvtime:, make_time(make_int(prefix[4]))
 print wd_host: , make_string(prefix[5])
 load = prefix[6]
 print wd_load avg: %d, %d, %d % tuple([make_int(x) for x in
   (load[:4], load[4:8], load[8:])])
 print wd_boottime, make_time(make_int(prefix[7]))

 sz = calcsize(whoent_format)
 array_data = binary_data[calcsize(almost_whod):]
 assert len(array_data) % sz == 0, Aiee! corrupt chunk?
 whoent_chunks = [ array_data[sz*x:sz*(x+1)] for x in range(len(array_data) 
/ sz) ]
 print %d whoent chunks % len(whoent_chunks)

 for out_line, out_name, out_time, we_idle in [parse_one_whoent(x)
   for x in whoent_chunks]:
 print \tout_line:, make_string(out_line)
 print \tout_name:, make_string(out_name)
 print \tout_time:, make_time(out_time)
 print \twe_idle:, we_idle
 # od
# end parse_one_file
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Database recommendations for Windows app

2005-06-30 Thread Magnus Lycka
Thomas Bartkus wrote:
 I was thinking of Win32com which I expect lets you put a wrapper around ADO
 and work the ADO (or any other ActiveX) object model from within Python.

Sure, but since others have made wrappers around ADO for Python before,
you'd either reivent the wheel or or use e.g. 
http://www.ecp.cc/pyado.html or http://adodbapi.sourceforge.net/
and get another dependency besides the Win 32 libs.

Your milage may vary, but I prefer to use the DB-API compliant
interfaces. If mxODBC is ok from a licence point of view, I'm sure
it's an excellent product, but if you use it for .mdb I suspect you
need to deal with Jet oddities like quoting dates with # and
non-standard wildcard symbols. (* and ? instead of % and _). That
was the case last time I tried. :(

Maybe modern Jet versions have done away with those absurdities, but
then I guess you are in trouble if you install the program on a machine
with somwhat older Windows software.

If the limited SQL support in SQLite is enough, I think it's a very
simple and straight forward tool to use in Windows from Python.
Try it!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which kid's beginners programming - Python or Forth?

2005-06-30 Thread NickC
 Gentle folk of comp.lang.python, I heartily thank you all for your
 input.  I think I'm taking the boys through the door marked Logo.  We
 may be back this way, though.  We will likely need MORE in the nebulous
 future.  I am impressed with the outpouring of support here!

Before you commit totally to the LOGO idea, take a look at Guido van
Robot:
http://gvr.sourceforge.net/
http://gvr.sourceforge.net/about.php
http://gvr.sourceforge.net/lessons/rfrank/

Cheers,
Nick.

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


script fichiers binaires lecture écriture

2005-06-30 Thread Statesman
Je connais mal python et n'est pas trop le temps de m'y plonger bien
que cela semble être assez puissant...

import sys
import ixio
import os

M = ixio.getMAC(eth0)
S = %08X %08X % (M[0] | M[1]8 | M[2]16 | M[3]24, M[4] |
M[5]8)
K = Errorin:
if len(sys.argv)  3:
print Usage %s src-file dst-file % sys.argv[0]
else:
I = open(sys.argv[1],rb)#ouverture de tpsd.pre avec le flag rb
pour read in binary mode
O = open(sys.argv[2],wb)
while 1:
blk = I.read(113)
try:
i = blk.index(K)
blk = %sErrorin:%s%s \
  % (blk[:i],S,blk[i+len(K)+len(S):])
O.write(blk)
except ValueError:
O.write(blk)
if len(blk)113:
break
O.close()
I.close()

Voici l'erreur que j'obtiens en essayant d'exécuter ce script:

AttributeError: 'string' object has no attribute 'index'

D'après moi, index est une méthode de la classe string et non un
attribut...Je ne comprend donc pas... Enfin, je précise que je suis
malheureusement en version 1.5 de python... :(

Autre question: 113 est censé être une taille en octet: comment
cela se lit-t-il?

Merci d'avance de m'aclairer sur cette erreur et cette question.

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


RE: Debugger Confusion

2005-06-30 Thread Adriaan Renting
I use the debugger that comes with Eric3, but it is only free for Linux/
OS X, as it needs PyQt.
asside from setting  (conditional) breakpoints, one of it's features is
that it can show you a browsable tree of all your variables. something
like this:
class MyClass
|
L-- string 'username' - 'myuser'
|
L-- list
   L-[0] - 1
   L-[1] - 'some value'

You should know by now that I like this IDE ;-)

Adriaan Renting| Email: [EMAIL PROTECTED]
ASTRON | Phone: +31 521 595 217
P.O. Box 2 | GSM:   +31 6 24 25 17 28
NL-7990 AA Dwingeloo   | FAX:   +31 521 597 332
The Netherlands| Web: http://www.astron.nl/~renting/
 Robert Brewer [EMAIL PROTECTED] 06/28/05 11:02 PM 
Rex Eastbourne wrote:
 I'm a little confused about which debugging utilities do what, and
 which I should use for my Python code. I'd like to be able to step
 through my code, insert breakpoints, etc. I haven't been able to do
 this yet (I'm using Emacs on Windows). I have seen references to GDB,
 GUD, PDB, and others. Which ones do I need?

1. At the point you would like to start the debugger, insert the
following 2 lines:

import pdb
pdb.set_trace()

2. Run your script from the command line.
3. When your script executes the above lines, the pdb debugger will
start up, and give you a prompt. Type 'h' at the prompt (and hit
'enter'), and you'll be shown a list of pdb commands. 's' to step
through your code, 'c' to continue processing (and stop the debugger,
essentially). The prompt is interactive, so you can inspect program
variables as you like.

Start with that, and come back if you have any more questions. :)


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

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


JPype - suppressing JVM activity report

2005-06-30 Thread skn
Hello,

Is there any option to suppress the JVM activity report that gets displayed,
when you execute  Java APIs  from within Python using JPype.

E.g.,

JVM activity report :
classes loaded   : 26
JVM has been shutdown

I know I can do it by re-directing the std err to NUL.
But is there any other option?


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


Re: RE: RE: Open running processes

2005-06-30 Thread DeRRudi
 Tim Goldenwrote:

 If you wanted to send over arbitrary data from another application,
 then this is certainly a way to do it. (Another way might be to use
a
 Windows pipe, for example). My point was only that if you are
signalling
 an event as a wake-up call plus an atom of extra information saying

 max or min, and you weren't considering any expansion of this 
 vocabulary to include other commands, then two distinct events might

 be simpler, one signalling maximize, the other minimize. 
 
 Please don't take this as any criticism of your work: there's no
one
 right design decision here; I was merely curious as to the reasons
 behind yours.
 
 TJG
 

Thanx for thinking with me! It really helps to have some other
opinions! It might look simpeler to make two distinct events. But
reading out the mm is really easy to do. So i didn't make more events
for maximizing and minimizing. But further on i'm gonna use it. I
think by now i have all the thing's i need to solute my problems. 
Thnx 

Rudi

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


Re: Favorite non-python language trick?

2005-06-30 Thread NickC
Steven D'Aprano wrote:
 with colour do begin
 red := 0; blue := 255; green := 0;
 end;

 instead of:

 colour.red := 0; colour.blue := 255; colour.green := 0;

c = colour
c.red = 0; c.blue = 255; c.green = 0
del c # Not strictly needed, but limits the scope of c

When everything's a reference, the Pascal 'with' syntax doesn't gain
you anything over a single-letter variable name. As I recall, it's
handy in Pascal because record assignment has value semantics rather
than reference semantics.

Cheers,
Nick.

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


Re: script fichiers binaires lecture écriture

2005-06-30 Thread Statesman
In English:

I don't know much about python and I won't have much time to learn much
about it even if it seems powerful...

import sys
import ixio
import os

M = ixio.getMAC(eth0)
S = %08X %08X % (M[0] | M[1]8 | M[2]16 | M[3]24, M[4] |
M[5]8)
K = Errorin:
if len(sys.argv)  3:
print Usage %s src-file dst-file % sys.argv[0]
else:
I = open(sys.argv[1],rb)#ouverture de tpsd.pre avec le flag rb
pour read in binary mode
O = open(sys.argv[2],wb)
while 1:
blk = I.read(113)
try:
i = blk.index(K)
blk = %sErrorin:%s%s \
  % (blk[:i],S,blk[i+len(K)+len(S):])
O.write(blk)
except ValueError:
O.write(blk)
if len(blk)113:
break
O.close()
I.close()

Here is an error I get trying to run this script:

AttributeError: 'string' object has no attribute 'index'

According to me, index() is a method of the string class but not an
attribute. So I don't understand the error message. Be aware that I'm
using pyhton 1.5, unfortunately...

Another question: 113 is supposed to be a size in bytes but can you
explain to me how to read this?

Thanks for helping me understanding the error message and size thing!!

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


ANN: PyVISA 0.9 (first public release)

2005-06-30 Thread Torsten Bronger
Hallöchen!

At http://pyvisa.sourceforge.net you can find information about the
PyVISA package.  It realises Python bindings for the VISA library
functions, which enables you to control measurement devices via
Python.

Yesterday I released version 0.9.  I tried to provide it with good
documentation.  It works very nicely with the GPIB in our lab,
however, I haven't yet received feedback from others, so I leave it
in beta status and with a version number  1.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Modules for inclusion in standard library?

2005-06-30 Thread Simon Brunning
On 6/29/05, Thomas Heller [EMAIL PROTECTED] wrote:
 
 To me, this sounds that *at least* a PEP would be needed to convince
 Guido.  Or, to record the reasoning why it cannot be included.

I have a feeling that Guido won't allow ctypes into the standard
library since it can crash Python. I don't know about you, but that's
I interpret this -
http://mail.python.org/pipermail/python-dev/2004-January/041856.html.

I am prepared to be wrong, though. Only Tim can channel Guido! 

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


Re: MS Compiler to build Python 2.3 extension

2005-06-30 Thread Richie Hindle

[woodsplitter]
 MS Visual C++ 6 is indeed the compiler that the python.org
 distributions are built with

Just to add back some context for people not following the thread: this is
Python 2.3 we're talking about.  2.4 is built with Visual Studio.NET.

 but MinGW works fine too.  In fact, the
 code generated by MinGW-GCC 3.4.4 outpaces that generated by MSVC++ 6.0
 by a considerable margin in some of my performance-critical extensions,
 and the size of the binaries is often smaller.

Interesting!

-- 
Richie Hindle
[EMAIL PROTECTED]

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


Add methods to string objects.

2005-06-30 Thread Negroup
Hi all.
I'm writing a simple Python module containing functions to process
strings in various ways. Actually it works importing the module that
contains the function I'm interested in, and calling
my_module.my_function('mystring').

I was just asking if it is possible to extend string objects'
behaviour so that it becomes possible to invoke something like
'anystring'.my_method().

1) does the latter approach bring some advantages?
2) how is it possible to achieve this goal? 

Any pointer will be appreciated, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Control Printer Queue On Windows 2000/XP

2005-06-30 Thread binarystar
Hi folks,

I am writing a script to print a few thousand pdf documents and I need
to have some control over the number of jobs that are sent to the
printer queue at time ... something along the lines of

if number_jobs  MAX_JOBS:
time.sleep(10)
else:
#Print More Files


I have been investigating the win32print utility
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32print.html

... but can not see how to get print queue information eg the number of
jobs pending .. atleast my attempts are failing

any ideas??

thx in advance 

**

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


Re: script fichiers binaires lecture écriture

2005-06-30 Thread bruno modulix
Statesman wrote:
 In English:
 
 I don't know much about python and I won't have much time to learn much
 about it even if it seems powerful...
 
(snip code)

 Here is an error I get trying to run this script:
 
 AttributeError: 'string' object has no attribute 'index'
 
 According to me, index() is a method of the string class but not an
 attribute. So I don't understand the error message. 

In Python, functions are first class citizens (a function is an object
you can bind to a variable, pass as an argument, return from another
function etc...), so methods *are* actually attributes...

 Be aware that I'm
 using pyhton 1.5, 
Err... latest is 2.4.1, and the language has really, really changed. You
should consider upgrading...

 unfortunately...

BTW, in 1.5.x, you can use the String module instead of string class
methods:

import String
s = allo
String.index(s, a)

but really, consider upgrading to a newer version...

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


Store multiple dictionaries in a file

2005-06-30 Thread Philipp H. Mohr
Hello,

I would like to store multiple dictionaries in a file, if possible one per
line. My code currently produces a new dictionary every iteration and
passes it on to another peace of code. In order to be able to re-run some
experiments at a later date I would like to store every dictionary in the
same file.
I looked at pickel, but that seems to require a whole file for each
dictionary.

It would be great if some one could tell me how to do that.

Thank you,
Phil

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


Re: script fichiers binaires lecture écriture

2005-06-30 Thread bruno modulix
Statesman wrote in comp.lang.python:

en
Hi Statesman
comp.lang.python is the english-speaking Python forum. You may want to
try the french-speaking one at fr.comp.lang.python (xpost and fu2 set)
/en

 Je connais mal python et n'est pas trop le temps de m'y plonger bien
 que cela semble être assez puissant...

 import sys
 import ixio
 import os
 
 M = ixio.getMAC(eth0)
 S = %08X %08X % (M[0] | M[1]8 | M[2]16 | M[3]24, M[4] |
 M[5]8)
 K = Errorin:
 if len(sys.argv)  3:
 print Usage %s src-file dst-file % sys.argv[0]
 else:
 I = open(sys.argv[1],rb)#ouverture de tpsd.pre avec le flag rb
 pour read in binary mode
 O = open(sys.argv[2],wb)
 while 1:
 blk = I.read(113)
 try:
 i = blk.index(K)
 blk = %sErrorin:%s%s \
   % (blk[:i],S,blk[i+len(K)+len(S):])
 O.write(blk)
 except ValueError:
 O.write(blk)
 if len(blk)113:
 break
 O.close()
 I.close()
 
 Voici l'erreur que j'obtiens en essayant d'exécuter ce script:
 
 AttributeError: 'string' object has no attribute 'index'
 
 D'après moi, index est une méthode de la classe string et non un
 attribut...Je ne comprend donc pas... 

En Python, les fonctions sont des objets comme les autres. Donc les
methodes sont effectivement des attributs... (bon, dans le détail c'est
un poil plus compliqué que ça, mais là je te laisse consulter la doc...
si tu tiens vraiment à comprendre tous les détails d'implémentation)

 Enfin, je précise que je suis
 malheureusement en version 1.5 de python... :(

Euh... la dernière est la 2.4.1, il serait peut-être temps d'envisager
une mise à jour.

En attendant, dans la 1.5.x, tu peux utiliser le module String:
import String
s = allo
String.index(s, a)

(de mémoire, pas testé).


 Autre question: 113 est censé être une taille en octet: comment
 cela se lit-t-il?

opérateur de décalage de bits... 1  13 == 8192

 Merci d'avance de m'aclairer sur cette erreur et cette question.

HTH
-- 
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: Control Printer Queue On Windows 2000/XP

2005-06-30 Thread Tim Golden
[binarystar]
| Hi folks,
| 
| I am writing a script to print a few thousand pdf documents and I need
| to have some control over the number of jobs that are sent to the
| printer queue at time ... something along the lines of
| 
| if number_jobs  MAX_JOBS:
| time.sleep(10)
| else:
| #Print More Files
| 
| 
| I have been investigating the win32print utility
| http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32
| /win32print.html
| 
| ... but can not see how to get print queue information eg the 
| number of
| jobs pending .. atleast my attempts are failing

Assuming I understand the need, you can do something like
this with WMI:

code
import wmi

c = wmi.WMI ()
print len (c.Win32_PrintJob ())

/code

TJG


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

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


Re: Boss wants me to program

2005-06-30 Thread Magnus Lycka
I think Python works on fairly antique hardware, whatever
OS you use (as long as the OS works ok). You can get a DOS
version of Python 2.2 at http://www.caddit.net/ , but I don't
have any good suggestions for a UI then. This might work after
some tweaking: http://www.effbot.org/zone/console-index.htm

If you google for python curses you'll find info on that
route, and if you go for a GUI solution on Windows or Linux,
there are more routes than Tkinter. I'm not sure what to
suggest on really old hardware though. Perhaps pyFLTK or FxPy
are lighter than the typical alternatives. See also
http://wiki.python.org/moin/GuiProgramming

Unless we're talking about several installations, getting at
least a Pentium III is obviously much cheaper than to spend
several hours getting the program to work.

For a dirt cheap system with several users, curses and terminals
with a linux server is obviously hard to beat. A slightly more
modern approach would be a web based app.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multi regexp analyzer ? or how to do...

2005-06-30 Thread Paul McGuire
I'd propose a pyparsing implementation, but you don't give us many
specifics.  Is there any chance you could post some sample data, and
one or two of the regexps you are using for matching?

-- Paul

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


Re: Store multiple dictionaries in a file

2005-06-30 Thread Philipp H. Mohr

Thank you for you answer.

  I would like to store multiple dictionaries in a file, if possible one per
  line.

 Why one per line ?

I agree with you that it sounds like nasty code :-) but there is a good
reason for doing it this way - I think. My code collects data (attributes)
of its current environment, e.g. date, time, location, etc.
These values are put into a dictionary and passed to another program which
processes the data. The dictionary (or vector of attributes) is the only
interface between both progs. The one which creates the dictionary can
forget about it after it has passed it on. This is where the storing comes
into action. In order to be able to re-run an experiment I want to store
the dictionaries in a file. Also the program might not run continuasly,
therefore if I write all of them to a file, on after the other, I would be
able to re-run the experiment much easier.

Hope this makes sense.

Thank you,
Phil


 A pretty simple solution could be to store all the dicts in another
 container (list or dict, depending on how you need to retrieve'em, but
 from what you explain I'd say a list) and then pickle this container.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which kid's beginners programming - Python or Forth?

2005-06-30 Thread Nick Craig-Wood
Rocco Moretti [EMAIL PROTECTED] wrote:
  So for Math you'd do something like:
 
  y = b + mx + cx^2
 
  (Where ^2 is a superscript 2)
 
  For Python it would be:
 
  y = b + m*x + c*x**2
 
  IIRC, for Forth it would be something like (please excuse the mistakes 
  in operator notation):
 
  x 2 ^ c * m x * + b + 'y' setvar

In FORTH you don't generally use variables unless you really have to -
that is what the stack is for, so you'd write a word like this...

variable c 10 c !
variable m -2 m !
variable b 14 b !

: quad ( x -- b + m*x + c*x**2 )
  dup dup ( x x x )
  * c @ * swap ( cx**2 x )
  m @ * + ( m*x + c*x**2 )
  b @ + ( b + m*x + c*x**2 )
;

And now we test

  7 quad . 490  ok

Was that easy?  Not really! Compared to python...

 c = 10 
 m = -2
 b = 14
 def quad(x): return b + m*x + c*x**2
... 
 quad(7)
490

Was it fun?  Well yes it was! FORTH is much lower level than python
and you learn different things from it.  At each step you have to
worry about what is on the stack which attention to detail is
important for a programmer. Its a lot of work to do even the simple
stuff though.

Its much easier to understand how FORTH works, and even implement your
own from scratch.

I learnt FORTH a long time ago, and I haven't used it for many many
years! Its major pull back then was that it was fast, and easier to
write than assembler.  I don't think that really matters now though,
Python is just as fast thanks to the 3 GHz machine I'm running it on
(rather than the 4 MHz one I ran FORTH on then!)  I think FORTH would
be an interesting supplimentary language for anyone to learn though...

*However* I reckon Python would make a much better first language than
FORTH. The batteries included approach make a young programmers life
much, much more fun, rather than starting from almost nothing (in
modern terms) with FORTH.

And like FORTH, Python has the interactive console which is essential
when starting out.

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


sys.ps2

2005-06-30 Thread Xinyue Ye
when I type sys.ps2 after import sys,
I got the message like:
Traceback (most recent call last):
 File pyshell#10, line 1, in -toplevel-
   sys.ps2
AttributeError: 'module' object has no attribute 'ps2'
why does it happen?
-- 
http://mail.python.org/mailman/listinfo/python-list


POP3 and seen flag

2005-06-30 Thread Miki Tebeka
Hello All,

Is there a way to know in a POP session of a message was seen (old) or not
(new)?

Thanks.
--

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


pgpWyb2JkhMgP.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: aligning text with space-normalized text

2005-06-30 Thread John Machin
Steven Bethard wrote:
 John Machin wrote:
 
 If work is meant to detect *all* possibilities of 'chunks' not 
 having been derived from 'text' in the described manner, then it 
 doesn't work -- all information about the positions of the whitespace 
 is thrown away by your code.

 For example, text = 'foo bar', chunks = ['foobar']
 
 
 This doesn't match the (admittedly vague) spec

That is *exactly* my point -- it is not valid input, and you are not 
reporting all cases of invalid input; you have an exception where the 
non-spaces are impossible, but no exception where whitespaces are 
impossible.


which said that chunks
 are created as if by ' '.join(chunk.split()).  For the text:
 'foo bar'
 the possible chunk lists should be something like:
 ['foo bar']
 ['foo', 'bar']
 If it helps, you can think of chunks as lists of words, where the words 
 have been ' '.join()ed.

If it helps, you can re-read my message.

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


Re: sys.ps2

2005-06-30 Thread [EMAIL PROTECTED]
You should be in interactive mode to see those, otherwise you get the
error

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


Re: Inheriting from object

2005-06-30 Thread Sion Arrowsmith
Bruno Desthuilliers  [EMAIL PROTECTED] wrote:
Fuzzyman a écrit :
 *Should* I in fact write :
 
 class foo(object):
 def __init__(self, *args, **kwargs):
 object.__init__(self)
 
 ?
Nope.

And if you were to do so, surely:

class foo(object):
def __init__(self, *args, **kwargs):
super(foo, self).__init__(self)

would be the preferred way to go?

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

Re: Store multiple dictionaries in a file

2005-06-30 Thread Jeremy Sanders
Philipp H. Mohr wrote:

 I would like to store multiple dictionaries in a file, if possible one per
 line. My code currently produces a new dictionary every iteration and
 passes it on to another peace of code. In order to be able to re-run some
 experiments at a later date I would like to store every dictionary in the
 same file.
 I looked at pickel, but that seems to require a whole file for each
 dictionary.

If you're not worried about security, you could write the repr() of each
dict to the file and get the values back by using the eval() function.
repr() writes onto one line.

If you're storing types without repr() representations this will not work.

Jeremy

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


Re: How to compare two directories?

2005-06-30 Thread could ildg
I found dircmp compare only the direct dirs and files,
and it will not do anything to the sub-directories.

On 6/29/05, Michael Hoffman [EMAIL PROTECTED] wrote:
 could ildg wrote:
  I want to compare 2 directories,
  and find If all of theire sub-folders and files and sub-files are identical.
  If not the same, I want know which files or folders are not the same.
  I know filecmp moudle has cmpfiles function and a class named dircmp,
  they may help, but I wonder if there is a ready-to-use function in python 
  libs?
 
 That's a good start. Why doesn't dircmp work for you?
 --
 Michael Hoffman
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Add methods to string objects.

2005-06-30 Thread Roy Smith
[EMAIL PROTECTED] (Negroup) wrote:
 I was just asking if it is possible to extend string objects'
 behaviour so that it becomes possible to invoke something like
 'anystring'.my_method().

You can't quite do that, but you can get close.  You can define your own 
class which inherits from str, and then create objects of that class.  For 
example:

class myString (str):
def __init__ (self, value):
self.value = value

def plural (self):
if self.value[-1] in sz:
return self.value + es;
else:
return self.value + s;

foo = myString(foo)
bar = myString(bar)
baz = myString(baz)

print foo.plural(), bar.plural(), baz.plural()  # my defined method
print foo.capitalize()  # inherited from base class
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: POP3 and seen flag

2005-06-30 Thread Tim Williams (gmail)
 
 
 Hello All,
 
 Is there a way to know in a POP session of a message was seen (old) or not
 (new)?
 

You have to keep a persistant local list of viewed messages ,   UID
into a text file is often the simplest method.

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


Re: Favorite non-python language trick?

2005-06-30 Thread Benji York
Terry Hancock wrote:
 http://www.logilab.org/projects/python-logic/

 This is something pretty new to me, so I can't comment on how well
 it would meet your expectations, but I see now that the site does mention
 OZ/Mozart as comparables.

I've used both, the logilab stuff is cool, but no where near the
maturity (or speed) of OZ/Mozart.  OTOH, I can actually get things
done with the logilab code.  But that might say more about me than
Mozart. :)
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Store multiple dictionaries in a file

2005-06-30 Thread John Machin
bruno modulix wrote:
 Philipp H. Mohr wrote:

My code currently produces a new dictionary every iteration and
passes it on to another peace of code. 
 
 
 May this code rest in piece grin

Perhaps it's the piece of code that passeth all understanding?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Add methods to string objects.

2005-06-30 Thread [EMAIL PROTECTED]
You can even get closer, but it is NOT recommended

class foostr(str):
 def plural (self):
if self.value[-1] in sz:
return self.value + es
else:
return self.value + s


#ugly hack
setattr(__builtins__, str, foostr)

print str(apple).plural()

# this however does not work
# print apple.plural()

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


Re: POP3 and seen flag

2005-06-30 Thread Peter Hansen
Miki Tebeka wrote:
 Is there a way to know in a POP session of a message was seen (old) or not
 (new)?

Define seen.  It could be interpreted as either TOP or RETR having 
been executing for a message, or something like this client has seen 
this message before ... not sure what you mean.

In any case, the short answer is no.

The longer answer is that _some_ POP3 servers provide non-standard 
support for this by doing things like adding a special header to the 
message, things like X-Seen, which can be seen by using the TOP 
command.  This sort of thing is entirely non-standard and you can't rely 
on it in general, AFAIK.

A better approach would be to have your client software track the 
Message-ID header, but something tells me you are interpreting seen as 
meaning anyone has RETRed the message, so that won't work either.

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


Re: Which kid's beginners programming - Python or Forth?

2005-06-30 Thread Roy Smith
Nick Craig-Wood [EMAIL PROTECTED] wrote:
 In FORTH you don't generally use variables unless you really have to -
 that is what the stack is for

Exactly.  Every language has its natural way of doing things.  You can 
usually bludgeon a language into doing things some other way, and newcomers 
to a language usually try to do exactly that.  Eventually they catch on to 
the idioms.

Storing temporary values in variables in a stack language is like iterating 
through the items of a list in Python by incrementing an integer and using 
it as an index.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Store multiple dictionaries in a file

2005-06-30 Thread Tim Golden
[John Machin]   
| 
| bruno modulix wrote:
|  Philipp H. Mohr wrote:
| 
| My code currently produces a new dictionary every iteration and
| passes it on to another peace of code. 
|  
|  
|  May this code rest in piece grin
| 
| Perhaps it's the piece of code that passeth all understanding?

That's really rather funny. I'm tickled.

TJG


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

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


Re: map vs. list-comprehension

2005-06-30 Thread Mandus
Wed, 29 Jun 2005 08:33:58 -0700 skrev Scott David Daniels:
 Mandus wrote:
 29 Jun 2005 10:04:40 GMT skrev F. Petitjean:
 
Le Wed, 29 Jun 2005 09:46:15 + (UTC), Mandus a écrit :

res = [ bb+ii*dd for bb,ii,dd in zip(b,i,d) ]
 
 seem to be a tad slower than the map, but nothing serious. Guess it's
 the extra zip.
 You could try timing it using itertools.izip rather than zip.

jepp - faster, but still slower than the map.

100 iterations:
 zip+list-comprehension: 8.1s
 izip+list-comprehension: 7.5s
 map: 7.0s

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Add methods to string objects.

2005-06-30 Thread Roy Smith
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 You can even get closer, but it is NOT recommended
 
 class foostr(str):
  def plural (self):
 if self.value[-1] in sz:
 return self.value + es
 else:
 return self.value + s
 
 
 #ugly hack
 setattr(__builtins__, str, foostr)
 
 print str(apple).plural()
 
 # this however does not work
 # print apple.plural()

It's fascinating that the setattr() works (and I agree with you that it's a 
bad idea), but given that it does work, why doesn't it work with a string 
literal?
-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (Jun 29)

2005-06-30 Thread Simon Brunning
QOTW: And what defines a 'python activist' anyway?  Blowing up Perl
installations worldwide? - Ivan Van Laningham

Floating point is about nothing if not being usefully wrong. - Robert Kern


Sibylle Koczian needs to sort part of a list. His first attempt made
the natural mistake - sorting a *copy* of part of the list: 

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

Kevin Dangoor compares ZODB and pysqlite with SQLObject:
http://www.blueskyonmars.com/2005/06/18/zodb-vs-pysqlite-with-sqlobject/

Uwe Mayer needs a little convincing about consenting adults philosophy:

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

Zope 2.8.0 is released:
http://article.gmane.org/gmane.comp.web.zope.announce/987

Guido's ITC audio interview sparks off a discussion about the
advantages of static typing in terms of tool support:

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

Only c.l.py can go *this* far off topic without flames:

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

Is there any good stuff left that Python should steal from other
languages?

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

Peter Gengtsson reminds himself and us how useful the \b regular
expression special element is: 
http://www.peterbe.com/plog/slash_b

Are there any 3rd party modules that you'd like to see included in
the standard library?

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

Is Python a good language for teaching children to program?

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



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

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

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

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

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

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

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

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum further[s] the interests of companies
that base their business on ... Python.
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/


Re: Store multiple dictionaries in a file

2005-06-30 Thread Larry Bates
You might want to take a look at the shelve module.

-Larry

Philipp H. Mohr wrote:
 Hello,
 
 I would like to store multiple dictionaries in a file, if possible one per
 line. My code currently produces a new dictionary every iteration and
 passes it on to another peace of code. In order to be able to re-run some
 experiments at a later date I would like to store every dictionary in the
 same file.
 I looked at pickel, but that seems to require a whole file for each
 dictionary.
 
 It would be great if some one could tell me how to do that.
 
 Thank you,
 Phil
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Add methods to string objects.

2005-06-30 Thread Magnus Lycka
Negroup wrote:
 Hi all.
 I'm writing a simple Python module containing functions to process
 strings in various ways. Actually it works importing the module that
 contains the function I'm interested in, and calling
 my_module.my_function('mystring').
 
 I was just asking if it is possible to extend string objects'
 behaviour so that it becomes possible to invoke something like
 'anystring'.my_method().

The proper way is to extend the string type by subclassing it:

class S(str):
 def my_method(self):
 ...

Then you can do S('anystring').my_method() etc.

Example:

  class S(str):
... def lowers(self):
... return filter(lambda x:x!=x.upper(), self)
... def uppers(self):
... return filter(lambda x:x!=x.lower(), self)
...
  s = S('Hello World!')
  print s.uppers()
HW
  print s.lowers()
elloorld

This means that your additional behaviour isn't available to
plain string literals. You need to instanciate S objects. This
is much less confusing for other programmers who read your code
(or for yourself when you read it a few years from now).
-- 
http://mail.python.org/mailman/listinfo/python-list


if you please i want a help in running a nltk modules

2005-06-30 Thread enas khalil
if you please i want a help
im a beginner in using python 
i want to know how can i run a GUI module 
i installed python on windows platform 
thanks [EMAIL PROTECTED] wrote:
Send Python-list mailing list submissions topython-list@python.orgTo subscribe or unsubscribe via the World Wide Web, visithttp://mail.python.org/mailman/listinfo/python-listor, via email, send a message with subject or body 'help' to[EMAIL PROTECTED]You can reach the person managing the list at[EMAIL PROTECTED]When replying, please edit your Subject line so it is more specificthan "Re: Contents of Python-list digest..."Today's Topics:1. ANN: PyGaim released - Gaim Python plugin (Gerrit van Dyk)2. multi regexp analyzer ? or how to do... ([EMAIL PROTECTED])3. Re: need help with MySQLdb (Wolfram Kraus)4. Re: Favorite non-python language trick? (Paddy)5. Re: need help with MySQLdb (Dennis Lee Bieber)6. Re: some trouble with MySQLdb (dimitri pater)7. Re: need help with MySQ!
 Ldb
 (Dennis Lee Bieber)8. python install settings... (jtan325)9. Re: aligning text with space-normalized text (Peter Otten)10. Re: Inheriting from object (Fuzzyman)From: Gerrit van Dyk [EMAIL PROTECTED]To: python-list@python.orgDate: Thu, 30 Jun 2005 07:36:22 +0200Subject: ANN: PyGaim released - Gaim Python pluginPyGaim has been released.Summary: Gaim Python plug-in. The product provides developers with the capability to develop python plugins for GaimThis release is just a get it out there release and a lot of polishing still needs to be done.However, it does enable a python developer to develop gaim plugins using python as the programming language.The current packages is available from http://sourceforge.net/projects/pygaimToDo:Web pageCVSInstructions on installing and usingMore examplesA interface to the gaim gui using pygtkLots of other
 stuff.The mailing list should be up in the next 24 hoursFrom: [EMAIL PROTECTED]To: python-list@python.orgDate: 29 Jun 2005 23:19:50 -0700Subject: multi regexp analyzer ? or how to do...Hello,here is a trouble that i had, i would like to resolve it with python,even if i still have no clue on how to do it.i had many small "text" files, so to speed up processes on them, i usedto copy them inside a huge one adding some king of xml separator :[content]content is tab separated data (columns) ; data are stringsnow here come the tricky part for me :i would like to be able to create some kind of matching rules, usingregular expressions, rules should match data on one line (the smallestdata unit for me) or a set of lines, say for example :if on this line , match first column against this regexp and matchsecond columnand on following line !
 match
 third column- trigger somethingso, here is how i had tried :- having all the rules,- build some kind of analyzer for each rule,- keep size of longest one L,- then read each line of the huge file one by one,- inside a "file", create all the subsets of length = L- for each analyzer see if it matches any of the subsets- if it occurs...my trouble is here :"for each analyzer see if it matches any of the subset"it is really to slow, i had many many rules, and as it is "for loopinside for loop", and inside each rule also "for loop on subsets lines"i need to speed up that, have you any idea ?i am thinking of having "only rules for one line" and to keep traces ofif a rule is a "ending one" (to trigger something) , or a "mustcontinue" , but is still unclear to me for now...a great thing could also have been some sort of dict with regexpkeys...(and actually it would !
 be great
 if i could also use some kind of regexpoperator to tell one can skip the content of 0 to n lines beforematching, just as if in the example i had changed "following..." by"skip at least 2 lines and match third column on next line - it wouldbe great, but i still have really no idea on how to even think aboutthat)great thx to anybody who could help,bestFrom: Wolfram Kraus [EMAIL PROTECTED]To: python-list@python.orgDate: Thu, 30 Jun 2005 08:41:37 +0200Subject: Re: need help with MySQLdb[EMAIL PROTECTED] wrote: Hey there all, i have a question about how to point my python install to my sql database.  when i enter this: db = MySQLdb.connect(user="user", passwd="pass", db="myDB")  i get this: Traceback (most recent call last): File "", line 1, in -toplevel- db = MySQLdb.connect(user="user", passwd="pass",
 db="MyDB") File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66, in Connect return Connection(*args, **kwargs) File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 134, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (1049, "Unknown database 'MyDB'")  i am using the all in one package from lampp (now xampp) and i have tested a couple of python scripts from the cgi, but nothing that connects to the database.  any ideas?  thanks Try the following from the shell (NOT the python shell):mysql -u user -p[Enter passwd]mysql show databases;If MyDB isn't in the list 

Re: need help with MySQLdb

2005-06-30 Thread Wolfram Kraus
nephish wrote:
[...]

 Try the following from the shell (NOT the python shell):
 mysql -u user -p
 [Enter passwd]
 mysql show databases;

 If MyDB isn't in the list either something went wrong with the xampp 
 installation or the database for xampp got a different name. (I am no 
 xampp expert, so I can't help you any further)

 HTH,
 Wolfram


 after i entered the password it told me it cannot connect to mysql through
 socket /tmp/mysql.sock
 
 h.
 hope this helps

Please keep the discussion on the list

Try
mysql -u user -p -h 127.0.0.1

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


RE: COM problem .py versus .exe

2005-06-30 Thread Tim Golden
[Greg Miller]
| 
| Thanks for the information, I stumbled across that page yesterday.  It
| seems all the problems with this are solved.  The executable 
| works just
| like the Python version.  Now I have to come up with an algorithm to
| parse through the output data to come up with the version numbers.

Just in case you haven't managed it (and because I fancied 
the challenge), try the code below:
(most information from a post by Roger Upole)

code
import win32api

lo = win32api.LOWORD
hi = win32api.HIWORD

def get_version_number (filename):
  info = win32api.GetFileVersionInfo (filename, \\)
  ms = info['FileVersionMS']
  ls = info['FileVersionLS']
  return hi (ms), lo (ms), hi (ls), lo (ls)

if __name__ == '__main__':
  filename = c:/python24/python24.dll
  print ..join ([str (i) for i in get_version_number (filename)])

/code

TJG


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

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


Re: When someone from Britain speaks, Americans hear a British accent...

2005-06-30 Thread Luis M. Gonzalez
Well, yes, it is kinda off topic, but very interesting...
Being myself an argentine with spanish as mother tongue and a very bad 
English, it's hard foro me to tell the difference between accents. I can 
hardly tell an Irish from an English...
But what I did tell is the broad range of different accents within London 
when I visited the city in 2001.

Some people seemed to speak very clear to me, and others seemed to be 
speaking german!
And as far as I know, all these people were british, not immigrants (and 
very hard to find indeed...).

Cheers,
Luis

- Original Message - 
From: Simon Brunning [EMAIL PROTECTED]
To: Luis M. Gonzalez [EMAIL PROTECTED]
Cc: python-list@python.org
Sent: Thursday, June 30, 2005 5:20 AM
Subject: Re: When someone from Britain speaks, Americans hear a British 
accent...


On 29 Jun 2005 15:34:11 -0700, Luis M. Gonzalez [EMAIL PROTECTED] wrote:
 What's exactly the cockney accent?
 Is it related to some place or it's just a kind of slang?

A cockney is a *real* Londoner, that is, someone born within the City
of London, a.k.a The Square Mile. More specifically, it's someone born
within the sound of Bow Bells - i.e. close to St Mary le Bow, London
- http://maps.google.co.uk/maps?q=EC2V+6AU. This is within the
theoretical sound of Bow Bells, you understand - there have been
frequent and lengthy periods during which Bow Bells have not been rung
at all. There are in fact no longer any hospitals with maternity units
within the sound of Bow Bells, so there will be vanishingly few
cockneys born in future.

Strangely enough, this makes *me* a cockney, though I've never lived
in the square mile, and my accent is pretty close to received. I do
*work* in the City, though!

The cockney accent used to be pretty distinct, but these days it's
pretty much merged into the Estuary English accent common throughout
the South East of England.

 I'm not sure, but I think that I read somewhere that it is common in
 some parts of London, and that it is a sign of a particular social
 class, more than a regionalism. Is that true?

Cockney was London's working class accent, pretty much, thought it was
frequently affected by members of the middle classes. Estuary English
has taken over its position as the working class accent these days,
but with a much wider regional distribution.

How off topic is this? Marvellous!

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/ 

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


Re: Add methods to string objects.

2005-06-30 Thread Rocco Moretti
Roy Smith wrote:
 In article [EMAIL PROTECTED],
  [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
 
You can even get closer, but it is NOT recommended

class foostr(str):
 def plural (self):
if self.value[-1] in sz:
return self.value + es
else:
return self.value + s


#ugly hack
setattr(__builtins__, str, foostr)

print str(apple).plural()

# this however does not work
# print apple.plural()
 
 
 It's fascinating that the setattr() works (and I agree with you that it's a 
 bad idea), but given that it does work, why doesn't it work with a string 
 literal?

Because the string literal is the *actual* C-level builtin string type, 
not whatever type happens to be in __builtins__.str at the time. (At 
the time is also a tricky proposition - string literals are made into 
obects at compile time, before __builtins__ is twiddled with.)

BTW, on setattr():

'''
setattr( object, name, value)

This is the counterpart of getattr(). The arguments are an object, a 
string and an arbitrary value. The string may name an existing attribute 
or a new attribute. The function assigns the value to the attribute, 
provided the object allows it. For example, setattr(x, 'foobar', 123) is 
equivalent to x.foobar = 123.
'''

i.e. '''setattr(__builtins__, str, foostr)''' is the same as 
'''__builtins__.str = foostr''', but I would agree that the setattr 
gives more of a black magic warning.
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2005-06-30 Thread python-list-bounces+archive=mail-archive . com
#! rnews 2572
Newsgroups: comp.lang.python
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp
From: Harry George [EMAIL PROTECTED]
Subject: Re: Modules for inclusion in standard library?
X-Nntp-Posting-Host: cola2.ca.boeing.com
Content-Type: text/plain; charset=us-ascii
Message-ID: [EMAIL PROTECTED]
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4
Lines: 39
Sender: [EMAIL PROTECTED]
Organization: The Boeing Company
References: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL 
PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL 
PROTECTED]
Mime-Version: 1.0
Date: Thu, 30 Jun 2005 13:38:28 GMT
Xref: news.xs4all.nl comp.lang.python:384160

Paul Rubin http://[EMAIL PROTECTED] writes:

 Rocco Moretti [EMAIL PROTECTED] writes:
  Except that (please correct me if I'm wrong) there is somewhat of a
  policy for not including interface code for third party programs which
  are not part of the operating system. (I.e. the modules in the
  standard libary should all be usable for anyone with a default OS +
  Python install.)
 
 I've never heard of Python having such a policy and I don't understand
 how such a stupid policy could be considered compatible with a
 proclaimed batteries included philosophy.  Why would Python
 advocates want to make Python deliberately uncompetitive with PHP,
 Java, and other languages that do include database modules?
 
  A notable exception is the dbm modules, but I seem to recall hearing
  that the official position is that it was a mistake. (Now only kept
  for backward compatability.)
 
 Ahem: Tkinter.  There's actually several more, looking in the lib docs.

I typically install dozens of python packages (on IRIX, Solaris, AIX,
Linux, Win2K).  21 are standalone enough to be considered for the std
library.  However I wouldn't necessarily want them in there, because:

a) They have their own release cycles, and coordinating would be too
painful.  We'd get a Python-1.2.3 with a package ABC-2.3.4 which is
(too late) discovered to have a bug.  So everyone would have to
download ABC-2.3.5 and install it anyway.

b) Installing distutils-aware python packages is trivial.  I'd rather
the energy which might go into a bigger std library go instead into
helping projects which don't have distutils-style builds.


-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules for inclusion in standard library?

2005-06-30 Thread Christopher Arndt
Simon Brunning schrieb:
 On 6/29/05, Christopher Arndt [EMAIL PROTECTED] wrote:
 
 
 Adding sqllite to the standard library has been discussed before:
 http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/fd150297c201f814

Yeah, but they didn't seem to have come to a conclusion then. Also, 
pysqlite 2.x has had a final release now and is still fairly DB-API 
compatible (at least is seems so by looking at the docs).

I might go to their mailing list and ask about the status.

Chris

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


[no subject]

2005-06-30 Thread python-list-bounces+archive=mail-archive . com
#! rnews 2218
Newsgroups: comp.lang.python
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp
From: Harry George [EMAIL PROTECTED]
Subject: Re: Boss wants me to program
X-Nntp-Posting-Host: cola2.ca.boeing.com
Content-Type: text/plain; charset=us-ascii
Message-ID: [EMAIL PROTECTED]
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4
Lines: 39
Sender: [EMAIL PROTECTED]
Organization: The Boeing Company
References: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]
Mime-Version: 1.0
Date: Thu, 30 Jun 2005 13:53:07 GMT
Xref: news.xs4all.nl comp.lang.python:384162

Peter Hansen [EMAIL PROTECTED] writes:

 Harry George wrote:
  Adriaan Renting [EMAIL PROTECTED] writes:
 Both VB and Python are easier to learn as the more powerful
 languages, the price is that they lack features that make it easier to
 manage large and complex projects.
  What is a large project, and what is Python missing that C++ and Java
  have for such tasks?
 
 But C++ and Java have features that *management* likes, thus making it
 easier to manage large projects.  (That says nothing about whether
 or not it makes it easier to produce quality code, successful
 projects, happy customers, large profits, or any such silly
 things... just that it's easier to manage. ;-)
 
 Less facetiously: I have managed a large Python project or three, and
 several large C++ projects (and, thankfully, no large Java projects)
 and found Python quite up to the task.  In fact, if anything the C++
 projects ended up more in danger of succumbing to the sheer weight of
 the code than did the Python projects.  But I attribute this more to
 the fact that we had evolved to using agile approaches with the Python
 projects than to any of those special features either present or
 lacking in C++.
 
 Ultimately, manageability of a project is far and away more about the
 people involved and the techniques used than it is about any single
 technology involved.
 
 -Peter

That's our experience too (and the reason I asked).  I wonder if the
OP will respond.


-- 
[EMAIL PROTECTED]
6-6M21 BCA CompArch Design Engineering
Phone: (425) 294-4718
-- 
http://mail.python.org/mailman/listinfo/python-list


Open the command line within a script

2005-06-30 Thread Ivan Shevanski
Hey this is probally a noob question but here goes. . .How could I open the 
command line inside of a python script?  Would I have to use COM?




-Ivan

_
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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

Re: Store multiple dictionaries in a file

2005-06-30 Thread Philipp H. Mohr

Hello,

this is the solution I went for, as I am indeed not concernt about
security and the implementation is straight forward.

Thank you,
Phil


 If you're not worried about security, you could write the repr() of each
 dict to the file and get the values back by using the eval() function.
 repr() writes onto one line.

 If you're storing types without repr() representations this will not work.

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


RE: Open the command line within a script

2005-06-30 Thread Tim Golden
[Ivan Shevanski]
| Hey this is probally a noob question but here goes. . .How 
| could I open the 
| command line inside of a python script?  Would I have to use COM?

(Assuming you're on Windows from your reference to COM).
Depending on exactly what you want to do with it, you could just do:

code
import os

shell = os.environ['COMSPEC']

os.system (shell)
# or 
os.startfile (shell)

/code

TJG


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

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


Re: When someone from Britain speaks, Americans hear a British accent...

2005-06-30 Thread Graham Fawcett
Steven D'Aprano wrote:
 Speaking as an Australia, ...
 [snip]
 But don't worry, there is one thing we all agree on throughout the
 English-speaking world: you Americans don't speak English.

And lest you feel Steven's observation don't bear much weight, keep in
mind that he is speaking as an entire continent. ;-)

But, speaking as Antarctica, I must disagree. I don't think the Keepers
of the Canon of the English Language(tm) would hold up either your
Strine or our Canadian regional accents as examples of Real English
Pronunciation(tm). But that's the kind of thing that canon-keepers
obsess about, while the rest of us just get along and communicate with
one another. (By us, I mean us people, not us continents -- I
stopped speaking as Antarctica a few lines back.)

keep-your-stick-on-the-ice'ly yours,

Graham

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


Re: When someone from Britain speaks, Americans hear a British accent...

2005-06-30 Thread Benji York
Graham Fawcett wrote:
 keep-your-stick-on-the-ice'ly yours,

Is that a Red Green reference?  Man, I didn't think this could get any 
more off-topic. :)

python-needs-more-duct-tape'ly yours,

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


Re: map vs. list-comprehension

2005-06-30 Thread Mike P.

Björn Lindström [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 F. Petitjean [EMAIL PROTECTED] writes:

  res = [ bb+ii*dd for bb,ii,dd in zip(b,i,d) ]
 
  Hoping that zip will not be deprecated.

 Nobody has suggested that. The ones that are planned to be removed are
 lambda, reduce, filter and map. Here's GvR's blog posting that explains
 the reasons:

 http://www.artima.com/weblogs/viewpost.jsp?thread=98196


That really sucks, I wasn't aware of these plans. Ok, I don't use reduce
much, but I use lambda, map and filter all the time. These are some of the
features of Python that I love the best. I can get some pretty compact and
easy to read code with them. And no, I'm not a Lisp programmer (never
programmed in Lisp). My background being largely C++, I discovered lambda,
apply, map and filter in Python, although I had seen similar stuff in other
functional languages like Miranda and Haskell.

Also, I don't necessarily think list comprehensions are necessarily easier
to read. I don't use them all that much to be honest.

IMHO I'm not particularly happy with the way Python is going language wise.
I mean, I don't think I'll ever use decorators, for example. Personally, in
terms of language features and capabilities I think the language is fine.
Not much (if anything needs to be added).

I think at this stage the Python community and Python programmers would be
better served by building a better, more standardised, cross platform, more
robust, better documented, and more extensive standard library. I would be
happy to contribute in this regard, rather than having debates about the
addition and removal of language features which don't improve my
productivity.

I would love it if modules like PyOpenGL, PyOSG (Open Scene Graph), PyQt, a
graph library etc, were all part of the standard python library, and that
worked out of the box on all major platforms -Windows, Unix, Linux, Mac. All
these modules which are C/C++ based are all at different versions and at
different stages, requiring different versions of Python working on
different operating systems.
It's not as transparent as it should be. For example, why aren't PIL,
Numeric and a host of other fairly mainstream Python modules not part of the
standard library? Compare that with the huge SDK that comes with Java.

Then there is always issues of performance, better standard development
tools, better documentation. There are lots of things to do, to make the
Python programmers life better without touching the actual features of the
language.

Sorry, I've probably gone way off topic, and probably stirred up political
issues which I'm not aware of, but, man when I hear stuff like the proposed
removal of reduce, lambda, filter and map, all I see ahead of me is a waste
of time as a programmer.

I don't program in Python for it's own sake. I program in Python because it
lets me get my job done quicker and it saves me time. The proposed removals
are going to waste my time. Why? Because my team and myself are going to
have to go through all our code and change stuff like maps to ugly looking
list comprehensions or whatever when Python 3000 comes out. Sure some of you
will say you don't have to update, just stick with Python 2.3/2.4 or
whatever. That is fine in theory, but in practice I'm going to have to use
some third party module which will require Python 3000 (this happened to me
recently with a module which had a serious bug with the Python 2.3 version,
but worked with the Python 2.4 version - I had to upgrade every single third
party module I was using - I was lucky the ones I was using had 2.4
versions, but there are still a lot of modules out there that don't).

Sorry for the OT long rant.

Mike


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

python commmand line params from c++

2005-06-30 Thread Wesley Henwood
What is the proper way to pass command line parameters to a python
script called from C++? I'm tryng this:

path = c:\\someDir\\someScript.py param1 param2 param3;
PyRun_SimpleFile(PyFile_AsFile( PyFile_FromString( path, r)),
someScript.py);

I'm getting a format error someScript.py, line 1 when the code is
executed.

Note: The strange appearannce of the 3 python function calls nested is
not a bug, but required to prevent a run-time error.

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


Re: When someone from Britain speaks, Americans hear a British accent...

2005-06-30 Thread Grant Edwards
On 2005-06-30, Luis M. Gonzalez [EMAIL PROTECTED] wrote:

 Well, yes, it is kinda off topic, but very interesting...
 Being myself an argentine with spanish as mother tongue and a
 very bad English, it's hard foro me to tell the difference
 between accents. I can hardly tell an Irish from an English...
 But what I did tell is the broad range of different accents
 within London when I visited the city in 2001.

 Some people seemed to speak very clear to me, and others
 seemed to be speaking german!

I'm an American who grew up watching plenty of BBC, and I run
into afew native Londoners whom I have hard time understanding.
I don't ever remember having troubly understanding people
outside the city.

-- 
Grant Edwards   grante Yow!  I KAISER ROLL?! What
  at   good is a Kaiser Roll
   visi.comwithout a little COLE SLAW
   on the SIDE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which kid's beginners programming - Python or Forth?

2005-06-30 Thread Roy Smith
There's a reprint this morning on slashdot of a 1984 review Byte did
on the brand-new Macintosh (executive summary: cool machine, needs
more memory).  The first four software packages available for the new
machine?

MacWrite/MacPaint (they seem to count this as one package)
Microsoft Multiplan
Microsoft BASIC
CSI MacForth

No mention of Python :-(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python commmand line params from c++

2005-06-30 Thread Denis S. Otkidach
On 30 Jun 2005 07:52:04 -0700
Wesley Henwood [EMAIL PROTECTED] wrote:

 What is the proper way to pass command line parameters to a python
 script called from C++? I'm tryng this:

Have you tried PySys_SetArgv?

 path = c:\\someDir\\someScript.py param1 param2 param3;
 PyRun_SimpleFile(PyFile_AsFile( PyFile_FromString( path, r)),
 someScript.py);

This code looks strange: you open file and create Python file object
from its descriptor (PyFile_FromString), then get descripto back
(PyFile_AsFile) to pass it to PyRun_SimpleFile.  Why don't you just use
C fopen function?

 I'm getting a format error someScript.py, line 1 when the code is
 executed.
 
 Note: The strange appearannce of the 3 python function calls nested is
 not a bug, but required to prevent a run-time error.

I believe it's due to PyFile_FromString failing to open non-existent
file.  You must check return value of it.

-- 
Denis S. Otkidach
http://www.python.ru/  [ru]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-30 Thread [EMAIL PROTECTED]
If I had to choose one feature, I would like to see better support for
nested lexical scopes.  However, I imagine this is no easy trick to
add to the language.

 I'm curious -- what is everyone's favorite trick from a non-python
 language? And -- why isn't it in Python?

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


I have a question.

2005-06-30 Thread Nathan Pinno


  Hi all,

  Does Python have a random function? If so, can you show me an example
using it?

  Thanks,
  Nathan Pinno
  http://www.npinnowebsite.ca/



-- 



 Posted via UsenetRevolution.com - Revolutionary Usenet
** HIGH RETENTION ** Specializing in Large Binaries Downloads **
 http://www.UsenetRevolution.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I have a question.

2005-06-30 Thread Benji York
Nathan Pinno wrote:
   Does Python have a random function? If so, can you show me an example
 using it?

http://docs.python.org/lib/module-random.html
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compare two directories?

2005-06-30 Thread Michael Hoffman
could ildg wrote:
 I found dircmp compare only the direct dirs and files,
 and it will not do anything to the sub-directories.

The documentation for dircmp.report_full_closure() disagrees with you.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I have a question.

2005-06-30 Thread Brian van den Broek
Nathan Pinno said unto the world upon 30/06/2005 11:22:
 
   Hi all,
 
   Does Python have a random function? If so, can you show me an example
 using it?
 
   Thanks,
   Nathan Pinno
   http://www.npinnowebsite.ca/

  import random
  print It took %s seconds to find the module named random by 
looking at the docs %random.random()
It took 0.31385101929 seconds to find the module named random by 
looking at the docs
 


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


Re: I have a question.

2005-06-30 Thread Jeremy Jones
Nathan Pinno wrote:

  Hi all,

  Does Python have a random function? If so, can you show me an example
using it?

  Thanks,
  Nathan Pinno
  http://www.npinnowebsite.ca/



  

Take your pick:

In [5]: import random

In [6]: random.choice(range(10))
Out[6]: 2

In [7]: random.choice(range(10))
Out[7]: 7

In [8]: random.choice(range(10))
Out[8]: 8

In [9]: random.choice(range(10))
Out[9]: 8


In [14]: random.random()
Out[14]: 0.56386154889489271

In [15]: random.random()
Out[15]: 0.47322827346926843

In [16]: random.random()
Out[16]: 0.39921336622176518

In [17]: random.random()
Out[17]: 0.65521407248459007

In [18]: random.random()
Out[18]: 0.74525381787627598
In [20]: r = range(10)

In [21]: random.shuffle(r)

In [22]: r
Out[22]: [6, 4, 9, 7, 2, 0, 8, 3, 5, 1]


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


Multi Threading embedded python

2005-06-30 Thread amit
Hello,

 I am embedding a python script in a C++ application. The script can be 
called simultaneously from multiple threads.

What is the correct way to implement this situation:

1) Have unique python interpreter instantiations ( Py_Initialize() ) for 
each thread.

2) Have one python interpreter, and implement a lock on it so it can't 
be called simultaneously by multiple threads?

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


Re: Inheriting from object

2005-06-30 Thread Scott David Daniels
Sion Arrowsmith wrote:
 ... And if you were to do so, surely:
 class foo(object):
 def __init__(self, *args, **kwargs):
   super(foo, self).__init__(self)
 
 would be the preferred way to go?
 
Or, perhaps:
 class foo(object):
 def __init__(self, *args, **kwargs):
 super(foo, self).__init__(self, *args, **kwargs)
 ...

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multi Threading embedded python

2005-06-30 Thread Pierre Barbier de Reuille
Well, depends on what you want to achieve :)

First, I don't think you can call Py_Initialize on many threads. You
have special function to initialise different interpreters on per-thread
basis.

However, the main problem is: do you want to share data across your
threads ? If the answer is 'no' then use one interpreter by thread, this
is, by far, the simplest solution (and the most efficient ?).

But if you *do* need to share data, then you are in big trouble man :)
As far as I tried it, multi-threading and Python don't go along very
well ! At least, not with system-threads. Basically, to run some Python
code, you have to hold the GIL (Global Interpreter Lock) and you cannot
*test* it, you have to try holding it, so be prepare to block your
threads that would want to access Python !

What I would recommend (and that's what I do in my own software) is to
use a single thread in which your Python interpreter is running. Then,
use a message system in C++ to send commands and get them evaluated and
sent back (if needed). By doing so, you'll avoid a lot of problems, and
you won't loose significantly performances (or if you care about that,
then Python is definitly not the language you need) nor parrallelism
(you wouldn't be able to run many Python threads at the same time anyways).

Well, I hope that help,

Pierre

amit a écrit :
 Hello,
 
 I am embedding a python script in a C++ application. The script can be
 called simultaneously from multiple threads.
 
 What is the correct way to implement this situation:
 
 1) Have unique python interpreter instantiations ( Py_Initialize() ) for
 each thread.
 
 2) Have one python interpreter, and implement a lock on it so it can't
 be called simultaneously by multiple threads?
 
 Thanks
   Amit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.4: tarfile tell() and seek() seem to be broeken

2005-06-30 Thread Lars Gustäbel
On Thu, 02 Jun 2005 19:52:24 +0200, N. Volbers wrote:

 Thanks for taking care of it ;-)

I submitted patch #1230446 today which ought to fix the problem.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

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


Re: Programmers Contest: Fit pictures on a page

2005-06-30 Thread Don
[EMAIL PROTECTED] wrote:

 
 
 Chung Leong wrote:
 Isn't that an NP-complete problem or am I crazy?
 
 That makes it a more realistic challange, doesn't it?
 
 Suppose it was something simple, like calculating a
 minimal spanning tree. Every program would produce the
 same output. What kind of contest would that be?

I was thinking maybe you could use a genetic algorithm, where the fitness
function would caluclate the amount of waste. I'm not very familar with how
to implement this sort of thing, though.

-Don

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


Re: Modules for inclusion in standard library?

2005-06-30 Thread Tom Anderson
On Wed, 29 Jun 2005, it was written:

 Rocco Moretti [EMAIL PROTECTED] writes:

 Except that (please correct me if I'm wrong) there is somewhat of a 
 policy for not including interface code for third party programs which 
 are not part of the operating system.

 I've never heard of Python having such a policy and I don't understand
 how such a stupid policy could be considered compatible with a
 proclaimed batteries included philosophy.

Agreed. If this is the policy, it should be reconsidered. It's silly.

tom

-- 
How did i get here?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Boss wants me to program

2005-06-30 Thread Tom Anderson
On Wed, 29 Jun 2005, phil wrote:

 Wow! How about a sextant? Simple device really. And a great practical 
 demonstration of trigonometry.

 Excellent idea, even found a few how to sites. We'll do it.
 Any others?

A ballista? For many years when i was a kid, my dad wanted to build a 
ballista; he collected loads of literature on it. There's a surprising 
amount of maths involved - the Greeks actually devised instruments for 
computing cube roots in order to do it!

Perhaps not an ideal project for schoolkids, though.

tom

-- 
How did i get here?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programmers Contest: Fit pictures on a page

2005-06-30 Thread Peter Hansen
Don wrote:
 I was thinking maybe you could use a genetic algorithm, where the fitness
 function would caluclate the amount of waste. I'm not very familar with how
 to implement this sort of thing, though.

This problem is well suited to the abilities of genetic algorithms, and 
this would probably be an excellent way to learn more about them, even 
if you don't get the best solution.

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


Seeking IDE

2005-06-30 Thread Nick Mountford
Hi,

Complete newb to Python and programming, looking for an open source
IDE to download. Any suggestions?

Thanks,

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


Re: map vs. list-comprehension

2005-06-30 Thread Tom Anderson

On Fri, 1 Jul 2005, Mike P. wrote:


Björn Lindström [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

F. Petitjean [EMAIL PROTECTED] writes:


res = [ bb+ii*dd for bb,ii,dd in zip(b,i,d) ]

Hoping that zip will not be deprecated.


Nobody has suggested that. The ones that are planned to be removed are
lambda, reduce, filter and map. Here's GvR's blog posting that explains
the reasons:

http://www.artima.com/weblogs/viewpost.jsp?thread=98196


That really sucks, I wasn't aware of these plans. Ok, I don't use reduce 
much, but I use lambda, map and filter all the time. These are some of 
the features of Python that I love the best. I can get some pretty 
compact and easy to read code with them.


Same here.

And no, I'm not a Lisp programmer (never programmed in Lisp). My 
background being largely C++, I discovered lambda, apply, map and filter 
in Python, although I had seen similar stuff in other functional 
languages like Miranda and Haskell.


Same here too!

Also, I don't necessarily think list comprehensions are necessarily 
easier to read. I don't use them all that much to be honest.


And here!

However, i also felt that way about generator functions - until the other 
day, when i realised one was the best solution to a problem i had. That 
made me realise that the same was probably true of list comprehensions.


That said, i do still think that map etc are better than list comps, 
because they involve less language. Once you have the idea of a function 
and a list, you can understand map as a function that operates on lists; 
list comprehensions provide a whole new splodge of arbitrary syntax to 
learn. I guess you could say the same about lambda, which is really an 
essential part of the whole map way of life, but i don't think that's fair 
- list comprehensions are a structure for doing just one thing, whereas 
lambda is a construct of enormous general power.


I'd be happy for the lambda syntax to be tidied up, though - perhaps it 
could be merged with def? Like:


def name(args): # traditional form
some_statements
return some_expression

def name(args): return some_expression # one-line form

def name(args): some_statements; return some_expression

def name(args) = some_expression # shorthand one-line form

Then an anonymous form, which is an expression rather than a statement:

def (args):
some_statements
return some_expression

def (args): return some_expression

def (args) = some_expression

The latter form is like a lambda; i'm not sure how the former forms would 
work inside enclosing expressions; i think it would look pretty sick:


surfaceAreaToVolumeRatios = map(def (radius):
area = 4.0 * math.pi * (radius ** 2)
volume = 4.0 / 3.0 * math.pi * (radius ** 2)
return area / volume
, radii)

It works, but i admit it's not hugely pretty. But then, i would't advise 
anyone to actually do this; it's just there for completeness.


You might also want to allow:

def name(args) = some_statements; some_expression

And the anonymous counterpart. But i'm not sure about that one. Multiple 
expressions inside lambdas would sometimes be useful, but you can get 
those with the shorthand form.


I think at this stage the Python community and Python programmers would 
be better served by building a better, more standardised, cross 
platform, more robust, better documented, and more extensive standard 
library. I would be happy to contribute in this regard, rather than 
having debates about the addition and removal of language features which 
don't improve my productivity.


Same here.

Sorry, I've probably gone way off topic, and probably stirred up 
political issues which I'm not aware of, but, man when I hear stuff like 
the proposed removal of reduce, lambda, filter and map, all I see ahead 
of me is a waste of time as a programmer.


Same here.


Sorry for the OT long rant.


Yeah, that was really off-topic for a python newsgroup. You didn't even 
mention regional accents once!


tom

--
How did i get here?-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Seeking IDE

2005-06-30 Thread Philippe C. Martin
Linux: Eric3
All: Eclipe: my choice (might be tough to get into)



Nick Mountford wrote:

 Hi,
 
 Complete newb to Python and programming, looking for an open source
 IDE to download. Any suggestions?
 
 Thanks,
 
 Nick

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


Re: Seeking IDE

2005-06-30 Thread Philippe C. Martin
oops: eclipse

Philippe C. Martin wrote:

 Linux: Eric3
 All: Eclipe: my choice (might be tough to get into)
 
 
 
 Nick Mountford wrote:
 
 Hi,
 
 Complete newb to Python and programming, looking for an open source
 IDE to download. Any suggestions?
 
 Thanks,
 
 Nick

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


  1   2   3   >