Re: Portable general timestamp format, not 2038-limited

2007-07-04 Thread Richard Heathfield
Peter J. Holzer said:


 
> It is possible that the observatory at Greenwich still keeps and
> announces GMT, but it has no practical importance anymore. Certainly
> what everybody (except specialists in the field) means when they talk
> about "GMT" is UTC.

I am not a specialist in the field. When I talk about GMT, I mean GMT, 
not UTC. Therefore, I am a counter-example to your claim.

-- 
Richard Heathfield 
Email: -www. +rjh@
Google users: 
"Usenet is a strange place" - dmr 29 July 1999
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable general timestamp format, not 2038-limited

2007-07-04 Thread Ben Finney
CBFalconer <[EMAIL PROTECTED]> writes:

> "Peter J. Holzer" wrote:
> > Hardly. That hasn't been in use for over 35 years (according to
> > Wikipedia).
>
> I am glad to see you depend on absolutely reliable sources.

Wikipedia is not an absolutely reliable source. I know of no
"absolutely resliable source". We work with imperfect human-provided
data all the time.

-- 
 \ "If you ever teach a yodeling class, probably the hardest thing |
  `\  is to keep the students from just trying to yodel right off. |
_o__)  You see, we build to that."  -- Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unbound Local error --???

2007-07-04 Thread Gabriel Genellina
(Please keep posting on the list - I don't read this
account too often)

At Friday 29/06/2007 22:03, you wrote:

> But what i am asking in particular is, how python
> interpretes when we initialize a variable with a 
> name same as a method name ? for ex:
> 
> def f(): 
> 
> ... x = g()
> ... g = 'sample'
> 

It's the same thing:
- First, the *compiler* determines (statically)
whether a variable name is local or not. If you assign
something to it, it IS local (unless you explicitely
use the global keyword). This is done when the code is
compiled, not when it is run.
- In your example, you assign something to g, so the
compiler knows that g is a local variable.
- When the function is run, there is an attempt to
reference a local variable g, but is still unassigned,
so you get an UnboundLocalError.

Python treats function names and variable names like
the same thing. That is, all names are just that...
names - pointing to objects.

-- 
Gabriel Genellina
Softlab SRL 


  __ 
Todo sobre la Copa América.
Mantenete actualizado con las últimas noticias sobre esta competencia en Yahoo! 
Deportes. http://ar.sports.yahoo.com/futbol/copaamerica/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unify els database

2007-07-04 Thread rbsharp
On Jul 3, 2:25 pm, luca72 <[EMAIL PROTECTED]> wrote:
> Hello and thanks for your answer, the unify db is on unix-sco and i
> need to connect with linux machine with python
>
> Regards
>
> Luca

Hello,
perhaps I introduced the confusion by using the word "connect"
ambiguously. What I do is to directly use the unify database. My
programs are then running on the sco machine and use the HLI-libraries
to operate directly on the unify database file. In that sense I do not
"connect" to the database. If your programs are running on the linux
machine and want to connect to the unify database on the sco machine,
then I suspect that you are talking about an ELS Server, probably
configured with the DBIntegrator. The DBIntegrator, as far as I
understand it since I don't use this route myself, offers the possibly
of ODBC and JDBC access to the database. There are windows ODBC drives
and a JDBC driver.

If this is your scenario, then the problem is a) how to get ODBC
access to the database under linux, a question I cannot answer, or b)
perhaps using Jython and the JDBC-Driver, which should work if this is
an option.

I hope to have been of some help. Greetings,

Richard Sharp

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


ignoring a part of returned tuples

2007-07-04 Thread noamtm
Hi,

Some functions, like os.walk(), return multiple items packed as a
tuple:

for (dirpath, dirnames, filenames) in os.walk(...):

Now, if you don't care about one of the tuple members, is there a
clean way to ignore it, in a way that no unused variable is being
created?

What I wanted is:
for (dirpath, , filenames) in os.walk(...):

But that doesn't work.

Thanks, Noam.

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


Re: ignoring a part of returned tuples

2007-07-04 Thread Justin Ezequiel
On Jul 4, 4:08 pm, noamtm <[EMAIL PROTECTED]> wrote:
> What I wanted is:
> for (dirpath, , filenames) in os.walk(...):
>
> But that doesn't work.

 for (dirpath, _, filenames) in os.walk(...):

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Paul Rubin
greg <[EMAIL PROTECTED]> writes:
> > E.g. your program might pass its test and run properly for years
> > before some weird piece of input data causes some regexp to not quite
> > work.
> 
> Then you get a bug report, you fix it, and you add a test
> for it so that particular bug can't happen again.

Why on earth would anyone prefer taking a failure in the field over
having a static type check make that particular failure impossible?

> > Once I got the function to work, I deployed it without writing
> > permanent tests for it.
> 
> That suggests you had a temporary test at some point.

I ran the function on real, dynamic data and made sure the results
were right.

> So, keep it and make it a permanent test. Even if it's just a small
> manually-created directory, it's still better than nothing, and you
> can add to it over time to cover any bugs that turn up.

That doesn't obviously fit into the doctest framework; such a test
would be considerably more complex than the function itself, and the
types of situations that I could imagine causing failures wouldn't be
included in a test like that.  Basically I had to get on to the next
thing.  Given the somewhat throwaway nature of this particular code,
nothing else really made sense.  But I think I'm going to look into
using dejagnu for more heavyweight testing of some other parts of the
program, so I guess some good came out of discussing this issue.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ignoring a part of returned tuples

2007-07-04 Thread Bruno Desthuilliers
noamtm a écrit :
> Hi,
> 
> Some functions, like os.walk(), return multiple items packed as a
> tuple:
> 
> for (dirpath, dirnames, filenames) in os.walk(...):
> 
> Now, if you don't care about one of the tuple members, is there a
> clean way to ignore it,

Yes : just ignore it !-)

> in a way that no unused variable is being
> created?

the term 'variable' in Python can be somewhat misleading. You have 
objects, and you have names bound to objects. In your case, whether you 
bind it to a name or not, the object will be created, so it wont make 
much differences.

> What I wanted is:
> for (dirpath, , filenames) in os.walk(...):
> 
> But that doesn't work.

A common idiom is to use '_' for unused values, ie:

for (dirpath, _, filenames) in os.walk(...):

You could also just bind the whole tuple to a ssinngle name then 
subscript it:

for infos in os.walk(...):
   # now dirpath is infos[0] and filenames is infos[2]

but this won't buy you much...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IRC bot using Twisted

2007-07-04 Thread ddtm
On 3, 20:08, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Tue, 03 Jul 2007 15:51:30 -, ddtm <[EMAIL PROTECTED]> wrote:
> >On 3, 17:55, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> >> On Tue, 03 Jul 2007 13:44:34 -, ddtm <[EMAIL PROTECTED]> wrote:
> >> >On 3, 16:01, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> >> > [snip]
>
> >> >Thank you very much! It's a very useful information. One more
> >> >question: can I cancel the DelayedCall using its ID (it is returned
> >> >from callLater(...)) from another function? In example bot there are
> >> >two functions:
> >> >def joined(self, channel):
> >> >  ...
> >> >def privmsg(self, user, channel, msg):
> >> >  ...
> >> >For example, I add callLater(...) to joined(...) function and I'd like
> >> >to cancel this in privmsg(...) function. What should I do?
>
> >> Yep.  The object callLater returns has a `cancel' method (some others, too)
> >> which will prevent the function from being called at the scheduled time.
>
> >> Jean-Paul
>
> >I know what you are talking about, but the question is: How can I
> >cancel scheduled task in function that differs from
> >function where I scheduled the task? Demo bot on Twisted website has a
> >class with a bunch of predefined functions joined(...), privmsg(...)
> >and so on. I can't see any method of communicating these functions.
> >I'm new to Python and to Twisted framework.
> >The task is:
> >to call callLater(...) in joined(...)
> >to cancel the task in privmsg(...) on special condition
>
> You need to preserve a reference to the object.  For example:
>
> class IRCBot(Whatever):
> def joined(...):
> self.announceJoinedCall = reactor.callLater(...)
>
> def privmsg(...):
> self.announceJoinedCall.cancel()
> self.announceJoinedCall = None
>
> This skips over a bunch of details (what happens on multiple calls to
> joined, what happens if privmsg is called after announceJoinedCall has
> run, etc) but I hope it demonstrates the basic idea.
>
> Jean-Paul

Thank you! Everything works great!

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


windows cetificates

2007-07-04 Thread m.banaouas
hi,

is there any way to decrypt an email (already read with poplib, so 
available on client side) with python using a window certificate (those 
we can see on ie/internet options/content/certificates) ?

the purpose is to decrypt an email sent and crypted by the sender with 
both his own certificate and the recipient one.

thanks for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is wrong with that r"\"

2007-07-04 Thread Nick Craig-Wood
Neil Cerutti <[EMAIL PROTECTED]> wrote:
>  From the Python Language Reference 2.4.1 String Literals:
> 
> When an "r" or "R" prefix is present, a character following a
> backslash is included in the string without change, and all
> backslashes are left in the string. For example, the string
> literal r"\n" consists of two characters: a backslash and a
> lowercase "n".

So far so good.

> String quotes can be escaped with a backslash,
> but the backslash remains in the string; for example, r"\"" is
> a valid string literal consisting of two characters: a
> backslash and a double quote;

a) That is weird!  Why would you ever want to do that - ie insert \"
into your string as a special case?  If I wanted a " in a raw string
then I'd use a r'' string or a triple quoted string.

> r"\" is not a valid string literal (even a raw string cannot end
> in an odd number of backslashes). Specifically, a raw string
> cannot end in a single backslash (since the backslash would
> escape the following quote character).

b) That is a logical consequence of a)

> Note also that a single backslash followed by a newline is
> interpreted as those two characters as part of the string, not
> as a line continuation.

As I'd expect.

If we removed a) then we could remove b) also and r"" strings would
work as everyone expects.

Does anyone know the justification for a)?  Maybe we should remove it
in py3k?

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


Re: what is wrong with that r"\"

2007-07-04 Thread Nick Craig-Wood
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>  On Jul 3, 7:15 am, alf <[EMAIL PROTECTED]> wrote:
> > question without words:
> >
> >  >>> r"\"
> >File "", line 1
> >  r"\"
> > ^
> > SyntaxError: EOL while scanning single-quoted string
> >  >>> r"\ "
> > '\\ '
> 
>  One slash escapes the following character, so the proper way of
>  writing it is either
> 
>  r"\\" or r"\""

I don't think so...

  >>> r"\\"
  ''
  >>> r"\""
  '\\"'

Indicating that all the \ in the above are inserted literally.

Maybe you meant

  >>> "\\"
  '\\'
  >>> "\""
  '"'

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Bruno Desthuilliers
Paul Rubin a écrit :
> greg <[EMAIL PROTECTED]> writes:
>>> E.g. your program might pass its test and run properly for years
>>> before some weird piece of input data causes some regexp to not quite
>>> work.
>> Then you get a bug report, you fix it, and you add a test
>> for it so that particular bug can't happen again.
> 
> Why on earth would anyone prefer taking a failure in the field over
> having a static type check make that particular failure impossible?

Because static type checks impose a lot of arbitrary restrictions, 
boilerplate code etc, which tends to make code more complicated than it 
needs to be, which is a good way of introducing bugs that wouldn't have 
existed without static type checks. Depending on the application domain 
and some technical and non-technical constraints and requirements, it 
(often) happens that it's better to have the application deployed now 
with an occasional error message than to have it next year...

And FWIW, when it comes to "weird piece of input data", statically typed 
languages are not specially better than dynamic ones...

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


Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Re: Which Python Version

2007-07-04 Thread Tim Golden
Robert Rawlins - Think Blue wrote:
> Is there a command I can run to confirm which version of python I'm running?

 From outside Python:

   python -V

(that's a capital V)

 From inside Python:

   import sys
   print sys.version

(and a couple of more easily parseable alternatives; look at the sys module 
docs)

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


RE: Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Thanks Tim,

Greatly appreciated, I've been having a few problems with one of my apps
recently crashing at all sorts of odd intervals without throwing an error or
anything like that, So I'm upgrading to 2.5 to see if they'll make life any
simpler.

Thanks mate,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 04 July 2007 11:36
Cc: python-list@python.org
Subject: Re: Which Python Version

Robert Rawlins - Think Blue wrote:
> Is there a command I can run to confirm which version of python I'm
running?

 From outside Python:

   python -V

(that's a capital V)

 From inside Python:

   import sys
   print sys.version

(and a couple of more easily parseable alternatives; look at the sys module
docs)

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

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


Re: what is wrong with that r"\"

2007-07-04 Thread Neil Cerutti
On 2007-07-04, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
>> String quotes can be escaped with a backslash, but the
>> backslash remains in the string; for example, r"\"" is a
>> valid string literal consisting of two characters: a
>> backslash and a double quote;
>
> a) That is weird!  Why would you ever want to do that - ie
> insert \" into your string as a special case?  If I wanted a "
> in a raw string then I'd use a r'' string or a triple quoted
> string.
>
> If we removed a) then we could remove b) also and r"" strings
> would work as everyone expects.
>
> Does anyone know the justification for a)?  Maybe we should
> remove it in py3k?

If the escaped quotes didn't function in raw strings, I'd be
unable to construct (with a single notation) a regex that
included both kinds of quotes at once.

  re.compile(r"'\"")

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


Generator for k-permutations without repetition

2007-07-04 Thread bullockbefriending bard
I was able to google a recipe for a k_permutations generator,  such
that i can write:

x = range(1, 4)  # (say)
[combi for combi in k_permutations(x, 3)] =>

[[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1, 2, 3], [1,
3, 1], [1, 3, 2], [1, 3, 3], [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 2,
1], [2, 2, 2], [2, 2, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3], [3, 1, 1],
[3, 1, 2], [3, 1, 3], [3, 2, 1], [3, 2, 2], [3, 2, 3], [3, 3, 1], [3,
3, 2], [3, 3, 3]]

but what i really want is the above without repetition, i.e.:

[combi for combi in k_permutations_without_repetitions(x, 3)] =>

[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

For smallish lists, it's no problem to generate the list as follows:

no_reps_combis = [combi for combi in k_permutations(x, 3) if \
 
len(set(combi)) == 3]

but i'm sure there must be a way to do this as a pure generator, just
that i wouldn't have a clue how to go about it.

Help please, Python Gods! :)

Apologies in advance if I have got my terminology wrong and have been
googling the wrong stuff and therefore coming up blank.

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


Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Re: what is wrong with that r"\"

2007-07-04 Thread Marc 'BlackJack' Rintsch
On Wed, 04 Jul 2007 11:21:14 +, Neil Cerutti wrote:

> If the escaped quotes didn't function in raw strings, I'd be
> unable to construct (with a single notation) a regex that
> included both kinds of quotes at once.
> 
>   re.compile(r"'\"")

Where's the problem!? ::

  re.compile(r"''')

Ah, I see -- readability is the problem.  :-)

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


issues with htmlparser.getpos

2007-07-04 Thread dysmas
Hi,


Im having an issue with HTMLParser, the getpos() funtion sometimes
returns things like :

(1, 1247)
(1, 2114)
(1, 2168)
(1, 2228)
(1, 2295)
(1, 2382)
(1, 2441)
(1, 2963)
(1, 3040)

i guess this is because the HTMLParser has not correctly parsed the
newline characters in the string fed to it... is there a workaround
for this, without checking the string every time i feed it some data?

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


Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

using subprocess for non-terminating command

2007-07-04 Thread Phoe6
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.

# code
>>>import subprocess
>>>process = subprocess.Popen('ping 127.0.0.1', shell=True, 
>>>stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

>>>print process.pid # returns pid
>>>print process.poll() # returns None!!! this is strange.
>>>print process.stdout.read()

# This hangs at this point.
How should I handle these kind of commands (ping 127.0.0.1) with
subprocess module. I am using subprocess, instead of os.system because
at anypoint in time, I need access to stdout and stderr of execution.

Thanks,
Senthil

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


Re: what is wrong with that r"\"

2007-07-04 Thread Duncan Booth
Nick Craig-Wood <[EMAIL PROTECTED]> wrote:

> Does anyone know the justification for a)?  Maybe we should remove it
> in py3k?
> 

I think at least part of the justification is that it keeps the grammar 
simple. The tokenising happens identically irrespective of any modifiers. 
The r modifier doesn't actually change the syntax of the string at all, 
just the interpretation of the token.

If you changed this then the grammar would become slightly more complex.
-- 
http://mail.python.org/mailman/listinfo/python-list


Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Re: Generator for k-permutations without repetition

2007-07-04 Thread Gerard Flanagan
On Jul 4, 1:22 pm, bullockbefriending bard <[EMAIL PROTECTED]>
wrote:
> I was able to google a recipe for a k_permutations generator,  such
> that i can write:
>
> x = range(1, 4)  # (say)
> [combi for combi in k_permutations(x, 3)] =>
>
> [[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1, 2, 3], [1,
> 3, 1], [1, 3, 2], [1, 3, 3], [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 2,
> 1], [2, 2, 2], [2, 2, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3], [3, 1, 1],
> [3, 1, 2], [3, 1, 3], [3, 2, 1], [3, 2, 2], [3, 2, 3], [3, 3, 1], [3,
> 3, 2], [3, 3, 3]]
>
> but what i really want is the above without repetition, i.e.:
>
> [combi for combi in k_permutations_without_repetitions(x, 3)] =>
>
> [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
>

See `kslice` function here:

http://gflanagan.net/site/python/utils/sequtils/

Regards

Gerard

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


Re: using subprocess for non-terminating command

2007-07-04 Thread zacherates
> How should I handle these kind of commands (ping 127.0.0.1) with
> subprocess module. I am using subprocess, instead of os.system because
> at anypoint in time, I need access to stdout and stderr of execution.

Ping, for one, allows you to set an upper bound on how long it runs
(the -c option).  This is probably the cleanest approach if it's
available.

You can also send the subprocess signals if you need it to exit
(although, this is a unix thing so I'm not sure how portable it is).
You could emulate having a timeout on child.stdout.read by registering
a callback with Timer to kill the child.

Cheers,
   Aaron

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


Re: Generator for k-permutations without repetition

2007-07-04 Thread Nis Jørgensen
bullockbefriending bard skrev:
> I was able to google a recipe for a k_permutations generator,  such
> that i can write:
> 
> x = range(1, 4)  # (say)
> [combi for combi in k_permutations(x, 3)] =>
> 
> [[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1, 2, 3], [1,
> 3, 1], [1, 3, 2], [1, 3, 3], [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 2,
> 1], [2, 2, 2], [2, 2, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3], [3, 1, 1],
> [3, 1, 2], [3, 1, 3], [3, 2, 1], [3, 2, 2], [3, 2, 3], [3, 3, 1], [3,
> 3, 2], [3, 3, 3]]
> 
> but what i really want is the above without repetition, i.e.:
> 
> [combi for combi in k_permutations_without_repetitions(x, 3)] =>
> 
> [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
> 
> For smallish lists, it's no problem to generate the list as follows:
> 
> no_reps_combis = [combi for combi in k_permutations(x, 3) if \
>  
> len(set(combi)) == 3]
> 
> but i'm sure there must be a way to do this as a pure generator, just
> that i wouldn't have a clue how to go about it.
> 
> Help please, Python Gods! :)

I was initially confused by your example, since the size of the
underlying set is the same as of the individual permutations. In this
case, you are just asking for all permutations of the set.

As far as I can tell from a quick googling, the relevant definition of
k-permutation is "an ordered list of k elements from the set". Thus your
first example does not really generate k_permutations.

A quick solution, not extensively tested

# base needs to be an of the python builtin  set

def k_perm(base,k): 
for e in base:  
if k == 1:
yield [e]   
else:
for perm in k_perm(base-set([e]),k-1):
yield [e] + perm

>>> list(k_perm(set([1,2,3,4]),3))
[[1, 2, 3], [1, 2, 4], [1, 3, 2], [1, 3, 4], [1, 4, 2], [1, 4, 3], [2,
1, 3], [2, 1, 4], [2, 3, 1], [2, 3, 4], [2, 4, 1], [2, 4, 3], [3, 1, 2],
[3, 1, 4], [3, 2, 1], [3, 2, 4], [3, 4, 1], [3, 4, 2], [4, 1, 2], [4, 1,
3], [4, 2, 1], [4, 2, 3], [4, 3, 1], [4, 3, 2]]


Much to my initial surprise, it "works" for k<1 as well:

>>> list(k_perm(set([1,2,3,4]),-1))
[]

Hope this helps

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


Re: what is wrong with that r"\"

2007-07-04 Thread Matthieu TC
May I suggest giving the possibility to use any delimiter for a raw string?  
just like in Vi or ruby.

Vi:
 %s_a_b_g  is valid and so is  %s/a/b/g

Ruby:
 %q{dj'\ks'a\'"}   or %q-dj'\ks'a\'"-

So as long as your regex does not use all the valid characters, readability is 
maintained.
-matt


- Original Message 
From: Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
To: python-list@python.org
Sent: Wednesday, July 4, 2007 9:27:46 PM
Subject: Re: what is wrong with that r"\"

On Wed, 04 Jul 2007 11:21:14 +, Neil Cerutti wrote:

> If the escaped quotes didn't function in raw strings, I'd be
> unable to construct (with a single notation) a regex that
> included both kinds of quotes at once.
> 
>   re.compile(r"'\"")

Where's the problem!? ::

  re.compile(r"''')

Ah, I see -- readability is the problem.  :-)

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



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


GObject and Python 2.5

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Guys,

 

Firstly I should apologise for all the mails that keep landing on the list,
my SMTP server (supplied by my ISP) seems to be playing silly buggers and
sending multiples.

 

I've just installed Python 2.5 on my Debian system and I'm trying to run my
application and I get 'ImportError: No module named gobject' thrown back at
me. I think I've successfully install the glib library using apt-get but the
problem still persists.

 

There is obviously a module I'm missing, any ideas what it might be?

 

Thanks guys,

 

Rob

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

Re: Debugging "broken pipe" (in telnetlib)

2007-07-04 Thread Samuel
Thanks for your comments, Jean-Paul.

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


Re: Generator for k-permutations without repetition

2007-07-04 Thread bullockbefriending bard
On Jul 4, 7:09 pm, Nis Jørgensen <[EMAIL PROTECTED]> wrote:
> bullockbefriending bard skrev:
>
>
>
> > I was able to google a recipe for a k_permutations generator,  such
> > that i can write:
>
> > x = range(1, 4)  # (say)
> > [combi for combi in k_permutations(x, 3)] =>
>
> > [[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1, 2, 3], [1,
> > 3, 1], [1, 3, 2], [1, 3, 3], [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 2,
> > 1], [2, 2, 2], [2, 2, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3], [3, 1, 1],
> > [3, 1, 2], [3, 1, 3], [3, 2, 1], [3, 2, 2], [3, 2, 3], [3, 3, 1], [3,
> > 3, 2], [3, 3, 3]]
>
> > but what i really want is the above without repetition, i.e.:
>
> > [combi for combi in k_permutations_without_repetitions(x, 3)] =>
>
> > [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
>
> > For smallish lists, it's no problem to generate the list as follows:
>
> > no_reps_combis = [combi for combi in k_permutations(x, 3) if \
>
> > len(set(combi)) == 3]
>
> > but i'm sure there must be a way to do this as a pure generator, just
> > that i wouldn't have a clue how to go about it.
>
> > Help please, Python Gods! :)
>
> I was initially confused by your example, since the size of the
> underlying set is the same as of the individual permutations. In this
> case, you are just asking for all permutations of the set.
>
> As far as I can tell from a quick googling, the relevant definition of
> k-permutation is "an ordered list of k elements from the set". Thus your
> first example does not really generate k_permutations.
>
> A quick solution, not extensively tested
>
> # base needs to be an of the python builtin  set
>
> def k_perm(base,k):
> for e in base:  
> if k == 1:
> yield [e]  
> else:
> for perm in k_perm(base-set([e]),k-1):
> yield [e] + perm
>
> >>> list(k_perm(set([1,2,3,4]),3))
>
> [[1, 2, 3], [1, 2, 4], [1, 3, 2], [1, 3, 4], [1, 4, 2], [1, 4, 3], [2,
> 1, 3], [2, 1, 4], [2, 3, 1], [2, 3, 4], [2, 4, 1], [2, 4, 3], [3, 1, 2],
> [3, 1, 4], [3, 2, 1], [3, 2, 4], [3, 4, 1], [3, 4, 2], [4, 1, 2], [4, 1,
> 3], [4, 2, 1], [4, 2, 3], [4, 3, 1], [4, 3, 2]]
>
> Much to my initial surprise, it "works" for k<1 as well:
>
> >>> list(k_perm(set([1,2,3,4]),-1))
>
> []
>
> Hope this helps
>
> Nis

thank you!. i'll give this a try. seems to do exactly what i need.
sorry about the ambiguity in my example. i chose 3 from 3 merely to
keep the size of the example case small, without thinking enough about
how it might cause confusion.

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

Re: ActivePython

2007-07-04 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Jul 4, 2:03 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
>> Frank Swarbrick <[EMAIL PROTECTED]> wrote:
>>> Why might one choose to use ActivePython instead of using the free CPython?
>> I believe ActivePython is also free, and it's packaged up differently
>> (with more 3rd party modules accompanying it than the standard Python
>> distribution), which might make it attractive to some.  Also, I believe
>> ActivePython is also available as a pre-built binary for some platforms
>> for which CPython is only distributed as sources (e.g., Solaris), and
>> again this difference may be seen as favorable by some.
>>
>> Alex
> 
> Well, Komodo is a nice enough IDE, so you might choose to use
> ActivePython for integration reasons, and maybe it's a little easier
> on Windows.
> 
> However, I would have thought that if you were planning to distribute
> an application, you would want to choose CPython for maximum
> interoperability with external packages.
> 
Not only that, but the last time I looked the ActivePython distribution 
doesn't allow redistribution at all (i.e. it's not technically open source).

> ActivePython claims to be ready to install across multiple platforms
> (as is CPython) so perhaps a little more work has gone into making a
> consistent experience across operating systems.
> 
> I have to say, I am just guessing and would love to hear from an
> expert in the area on this topic. The ActiveState web page doesn't
> really talk about their reasons very much.
> 
ActiveState do produce a convenient package for many purposes, and I 
have used it myself in the past, but if you want to redistribute then it 
isn't a permitted starting point.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: ignoring a part of returned tuples

2007-07-04 Thread noamtm
On Jul 4, 11:29 am, Bruno Desthuilliers  wrote:

> A common idiom is to use '_' for unused values, ie:
>
> for (dirpath, _, filenames) in os.walk(...):

That's what I need - this avoids PyLint telling me that I have an
unused variable, and also makes it clear that this value is not used.

Thanks!

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


Re: issues with htmlparser.getpos

2007-07-04 Thread Steve Holden
dysmas wrote:
> Hi,
> 
> 
> Im having an issue with HTMLParser, the getpos() funtion sometimes
> returns things like :
> 
> (1, 1247)
> (1, 2114)
> (1, 2168)
> (1, 2228)
> (1, 2295)
> (1, 2382)
> (1, 2441)
> (1, 2963)
> (1, 3040)
> 
> i guess this is because the HTMLParser has not correctly parsed the
> newline characters in the string fed to it... is there a workaround
> for this, without checking the string every time i feed it some data?
> 
Have you verified that these results aren't correct? There is no 
requirements for newlines in HTML, and some computer-generated pages 
don't bother to insert them.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: what is wrong with that r"\"

2007-07-04 Thread Steve Holden
Matthieu TC wrote:
> May I suggest giving the possibility to use any delimiter for a raw string?  
> just like in Vi or ruby.
> 
Of course you may. Thank you for your suggestion.

Now, on to other business.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: issues with htmlparser.getpos

2007-07-04 Thread rokadvertising
Steve,

thanks for reply

there are newlines present, it looks like the files in question are
from a mac, (my text editor tells me they are UTF8 & use CR for
marking newlines)

Cheers

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


CGI vs WSGI

2007-07-04 Thread tuom . larsen
Dear all,

what is the difference? Middleware?

I'm wondering because the only variables I ever needed were PATH_INFO,
REQUEST_METHOD, QUERY_STRING and maybe one more, all of which should
be available from CGI, too.

Thanks.

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


Re: Generator for k-permutations without repetition

2007-07-04 Thread Nis Jørgensen
bullockbefriending bard skrev:
> On Jul 4, 7:09 pm, Nis Jørgensen <[EMAIL PROTECTED]> wrote:
>> bullockbefriending bard skrev:
>> A quick solution, not extensively tested
>>
>> # base needs to be an of the python builtin  set
>>
>> def k_perm(base,k):
>> for e in base:  
>> if k == 1:
>> yield [e]  
>> else:
>> for perm in k_perm(base-set([e]),k-1):
>> yield [e] + perm
> 
> thank you!. i'll give this a try. seems to do exactly what i need.
> sorry about the ambiguity in my example. i chose 3 from 3 merely to
> keep the size of the example case small, without thinking enough about
> how it might cause confusion.

I managed to simplify it a little:

def k_perm(base,k):
if k == 0:
yield []
else:
for e in base:  
for perm in k_perm(base-set([e]),k-1):
yield [e] + perm



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


Re: CGI vs WSGI

2007-07-04 Thread Michele Simionato
On Jul 4, 2:49 pm, [EMAIL PROTECTED] wrote:
> Dear all,
>
> what is the difference? Middleware?

Yes, and also the fact that you have a large choice of WSGI web
frameworks to choose
from. CGI looks so much 20th century ... ;)


 Michele Simionato


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


Re: issues with htmlparser.getpos

2007-07-04 Thread rokadvertising
On Jul 4, 1:47 pm, [EMAIL PROTECTED] wrote:
> Steve,
>
> thanks for reply
>
> there are newlines present, it looks like the files in question are
> from a mac, (my text editor tells me they are UTF8 & use CR for
> marking newlines)
>
> Cheers

d0h,

f = open(this_file,"U")
  
\ this fixed it

cheers anyway ;)

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


Proposal: s1.intersects(s2)

2007-07-04 Thread David Abrahams

Here's an implementation of the functionality I propose, as a
free-standing function:

def intersects(s1,s2):
if len(s1) < len(s2):
for x in s1:
if x in s2: return True
else:
for x in s2:
if x in s1 return True
return False

Right now, the only convenient thing to do is 

  if s1 & s2 ...

but that builds a whole new set.  IMO that query should be available
as a method of set itself.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

The Astoria Seminar ==> http://www.astoriaseminar.com

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


Re: ignoring a part of returned tuples

2007-07-04 Thread Marc 'BlackJack' Rintsch
On Wed, 04 Jul 2007 05:25:01 -0700, noamtm wrote:

> On Jul 4, 11:29 am, Bruno Desthuilliers  [EMAIL PROTECTED]> wrote:
> 
>> A common idiom is to use '_' for unused values, ie:
>>
>> for (dirpath, _, filenames) in os.walk(...):
> 
> That's what I need - this avoids PyLint telling me that I have an
> unused variable, and also makes it clear that this value is not used.

Pylint also "allows" the name `dummy` without complaining.  That makes it
even clearer and doesn't clash with the meaning of `_` when `gettext` is
used.

It's possible to configure many checks in Pylint.  For this check it's
possible to give a regular expression for names you don't care if they are
unused.

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Roy Smith
greg <[EMAIL PROTECTED]> wrote:

> Paul Rubin wrote:
> > E.g. your program might pass its test and run properly for years
> > before some weird piece of input data causes some regexp to not quite
> > work.
> 
> Then you get a bug report, you fix it, and you add a test
> for it so that particular bug can't happen again.

The TDD zealots would tell you you've got the order wrong.  Instead of 
"fix, then write a test", it should be "write a failing test, then fix it".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5 from source without tcl/tk

2007-07-04 Thread Florian Demmer
ok... cannot get rid of the "INFO: Can't locate Tcl/Tk libs and/or
headers".

Now same thing but weirder with curses:
i do not have ncurses-devel installed. still make trys to compile the
curses module.
how do i prevent that?

imo the configure should have more with/without switches... or do i
just miss the point, where to tell it which modules to compile and
which not?

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


Re: Proposal: s1.intersects(s2)

2007-07-04 Thread Thomas Jollans
On Wednesday 04 July 2007, David Abrahams wrote:
> Here's an implementation of the functionality I propose, as a
> free-standing function:
>
> def intersects(s1,s2):
> if len(s1) < len(s2):
> for x in s1:
> if x in s2: return True
> else:
> for x in s2:
> if x in s1 return True
> return False
>
> Right now, the only convenient thing to do is
>
>   if s1 & s2 ...
>
> but that builds a whole new set.  IMO that query should be available
> as a method of set itself.

>>> s1 = set(xrange(5))
>>> s2 = set(xrange(3,9))
>>> s1
set([0, 1, 2, 3, 4])
>>> s2
set([3, 4, 5, 6, 7, 8])
>>> s1 | s2
set([0, 1, 2, 3, 4, 5, 6, 7, 8])
>>> s1 & s2
set([3, 4])
>>>

It's all in python already. And documented on the web too.

-- 
  Regards,   Thomas Jollans
GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
Hacker key :
v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list

[mostly OT] mod_python & doc file system layout

2007-07-04 Thread Jan Danielsson
Hello all,

   This is probably more of an apache question, but I'm guessing there
will be other mod_python-beginners who are wondering the same thing.


   Let's say I have a web app called MyApp. It uses the usual images and
style sheets. I keep it all in
~/projects/MyApp/{styles,images,index.py,.htaccess}. I configure up
apache to use virtual hosts, and point it to MyApp.

   Now when I access myapp.local (which points to 127.0.0.1, obviously),
my index.py is parsed properly. However, any access made to /images or
/styles end up being handled by mod_python, which isn't good, because it
won't load images or style sheets.

   I have solved this by moving index.py (and the associated .htaccess)
to a subdirectory "main".

   I guess one solution would be to make an access to / on the virtual
server redirect to main.

   Another solution, I guess, would be to make the python script load
the images and style sheets.. A solution which I find to be particularly
ugly. :-)

   Any mod_python users out there with any other solutions?

-- 
Kind regards,
Jan Danielsson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using subprocess for non-terminating command

2007-07-04 Thread O.R.Senthil Kumaran
* zacherates <[EMAIL PROTECTED]> [2007-07-04 12:09:03]:

> > How should I handle these kind of commands (ping 127.0.0.1) with
> > subprocess module. I am using subprocess, instead of os.system because
> > at anypoint in time, I need access to stdout and stderr of execution.
> 
> Ping, for one, allows you to set an upper bound on how long it runs
> (the -c option).  This is probably the cleanest approach if it's
> available.
> 

Yes, I am aware of the ping -c option. But again even that does not help.
try
process = subprocess.Popen('ping -c 10 127.0.0.1', stdin=subprocess.PIPE,
shell=True)
process.stdout.read()  # This will hang again.

I am not sure, why subprocess is behaving so.

> You can also send the subprocess signals if you need it to exit
> (although, this is a unix thing so I'm not sure how portable it is).

Yes, I have tried to kill and then get the standard output result.
But the result has been the same. I could not read the Popen returned file
object.

> You could emulate having a timeout on child.stdout.read by registering
> a callback with Timer to kill the child.

I dont know how to do this. I shall give it a try ( by looking around ) and
trying. 

-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal: s1.intersects(s2)

2007-07-04 Thread Marc 'BlackJack' Rintsch
On Wed, 04 Jul 2007 16:18:58 +0200, Thomas Jollans wrote:

> On Wednesday 04 July 2007, David Abrahams wrote:
>> Right now, the only convenient thing to do is
>>
>>   if s1 & s2 ...
>>
>> but that builds a whole new set.  IMO that query should be available
>> as a method of set itself.
> 
 s1 = set(xrange(5))
 s2 = set(xrange(3,9))
 s1
> set([0, 1, 2, 3, 4])
 s2
> set([3, 4, 5, 6, 7, 8])
 s1 | s2
> set([0, 1, 2, 3, 4, 5, 6, 7, 8])
 s1 & s2
> set([3, 4])

> 
> It's all in python already. And documented on the web too.

The OP already knows that but does not want to build a new `set`.  He just
wants to know efficiently if the sets intersect without actually *doing*
the intersection.

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


Re: Proposal: s1.intersects(s2)

2007-07-04 Thread Marc 'BlackJack' Rintsch
On Wed, 04 Jul 2007 09:59:24 -0400, David Abrahams wrote:

> Here's an implementation of the functionality I propose, as a
> free-standing function:
> 
> def intersects(s1,s2):
> if len(s1) < len(s2):
> for x in s1:
> if x in s2: return True
> else:
> for x in s2:
> if x in s1 return True
> return False

In Python 2.5 this can be written a bit more concise:

def intersects(set_a, set_b):
if len(set_a) < len(set_b):
set_a, set_b = set_b, set_a
return any(item in set_a for item in set_b)

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


reading email using django

2007-07-04 Thread filox
i've just installed django and it seems pretty cool. i've managed to send an 
email succesfully, but i didn't find any information on reading email. is 
that even possible with django (e.g. open my gmail inbox and read mail from 
it)?

-- 
You're never too young to have a Vietnam flashback 


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


Re: using subprocess for non-terminating command

2007-07-04 Thread Jerry Hill
On 7/4/07, O.R.Senthil Kumaran <[EMAIL PROTECTED]> wrote:
> Yes, I am aware of the ping -c option. But again even that does not help.
> try
> process = subprocess.Popen('ping -c 10 127.0.0.1', stdin=subprocess.PIPE,
> shell=True)
> process.stdout.read()  # This will hang again.

When I try that, it doesn't hang.  Instead, I get the output of the
ping command pruinted to the screen, then the following exception:

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'NoneType' object has no attribute 'read'

That's because you tied stdin to a pipe in your Popen call, but then
tried to read from stdout.  Try this instead:

>>> process = subprocess.Popen("ping -c 10 127.0.0.1",
stdout=subprocess.PIPE, shell=True)
>>> process.stdout.readlines()
['PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.\n', '64 bytes from
127.0.0.1: icmp_seq=1 ttl=64 time=0.049 ms\n', '64 bytes from
127.0.0.1: icmp_seq=2 ttl=64 time=0.033 ms\n', '64 bytes from
127.0.0.1: icmp_seq=3 ttl=64 time=0.040 ms\n', '64 bytes from
127.0.0.1: icmp_seq=4 ttl=64 time=0.033 ms\n', '64 bytes from
127.0.0.1: icmp_seq=5 ttl=64 time=0.033 ms\n', '64 bytes from
127.0.0.1: icmp_seq=6 ttl=64 time=0.030 ms\n', '64 bytes from
127.0.0.1: icmp_seq=7 ttl=64 time=0.032 ms\n', '64 bytes from
127.0.0.1: icmp_seq=8 ttl=64 time=0.028 ms\n', '64 bytes from
127.0.0.1: icmp_seq=9 ttl=64 time=0.030 ms\n', '64 bytes from
127.0.0.1: icmp_seq=10 ttl=64 time=0.039 ms\n', '\n', '--- 127.0.0.1
ping statistics ---\n', '10 packets transmitted, 10 received, 0%
packet loss, time 8991ms\n', 'rtt min/avg/max/mdev =
0.028/0.034/0.049/0.009 ms\n']

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


Re: Memory leak issue with complex data structure

2007-07-04 Thread Josiah Carlson
Alan Franzoni wrote:
> I have a root node which is not referenced by any other node. So, I
> created a "clear()" method which is called on all children (by calling
> their clear() method" and then clears the set with the references of the
> node itself.

Using the .clear() method on sets (or dictionaries) does not reduce the 
memory that the underlying hash tables use, it only removes references 
to the keys (and values) that the sets (and dictionaries) contain(s). 
If your sets used to be large, I could have sworn that you could force a 
resize down by adding some items to the set, but I seem to be mistaken:

 #memory use is 3440k
 s = set(xrange(100))
 #memory use is 31,864k
 s.clear()
 #memory use is 15,460k
 s.add(0)
 s.remove(0)
 #memory use is 15,460k

Then again, this may be an artifact of my operating system memory 
freeing semantics.

As is usually the case, read the C source from svn.python.org/view (or 
some other means) for more information.

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


Re: CGI vs WSGI

2007-07-04 Thread Josiah Carlson
[EMAIL PROTECTED] wrote:
> I'm wondering because the only variables I ever needed were PATH_INFO,
> REQUEST_METHOD, QUERY_STRING and maybe one more, all of which should
> be available from CGI, too.

CGI starts up a new process for every request, using stdin/stdout for 
passing information.  I believe WSGI can do that, but I believe it can 
also do in-process requests (think mod_python, only with a Python web 
server), external process requests (think FastCGI or LRWP), etc.

I could certainly be mistaken, it's been a while since I looked into any 
of it.

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-07-04 Thread Jorgen Grahn
On Fri, 29 Jun 2007 12:53:49 -0400, Douglas Alan <[EMAIL PROTECTED]> wrote:
> Steve Holden <[EMAIL PROTECTED]> writes:
>
>> "Python" doesn't *have* any refcounting semantics.
>
> I'm not convinced that Python has *any* semantics at all outside of
> specific implementations.  It has never been standardized to the rigor
> of your typical barely-readable language standards document.
>
>> If you rely on the behavior of CPython's memory allocation and
>> garbage collection you run the risk of producing programs that won't
>> port tp Jython, or IronPython, or PyPy, or ...
>
>> This is a trade-off that many users *are* willing to make.
>
> Yes, I have no interest at the moment in trying to make my code
> portable between every possible implementation of Python, since I have
> no idea what features such implementations may or may not support.
> When I code in Python, I'm coding for CPython.  In the future, I may
> do some stuff in Jython, but I wouldn't call it "Python" -- it'd call
> it "Jython".

Yeah, especially since Jython is currently (according to the Wikipedia
article) an implementation of Python 2.2 ... not even *I* use 
versions that are that old these days!

[I have, for a long time, been meaning to post here about refcounting
and relying on CPython's __del__ semantics, but I've never had the
energy to write clearly or handle the inevitable flame war. So I'll
just note that my view on this seems similar to Doug's.]

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Alex Martelli
Roy Smith <[EMAIL PROTECTED]> wrote:

> greg <[EMAIL PROTECTED]> wrote:
> 
> > Paul Rubin wrote:
> > > E.g. your program might pass its test and run properly for years
> > > before some weird piece of input data causes some regexp to not quite
> > > work.
> > 
> > Then you get a bug report, you fix it, and you add a test
> > for it so that particular bug can't happen again.
> 
> The TDD zealots would tell you you've got the order wrong.  Instead of
> "fix, then write a test", it should be "write a failing test, then fix it".

Incidentally, I was pretty surprised recently (re-reading Weinberg's
"Psychology of Computer Programming" classic from _1971_) to find out
Weinberg advocating "test-first coding" (not the same thing as
"test-driven design", but sharing the key insight that tests should be
written before the code they test) for psychological reasons. He's
discussing common practices of the '60s, with the same professional
writing both the code and the tests, and pointing out how often the
knowledge of the already-written code subconsciously influences the
programmer to write tests that don't really "challenge" the code enough
-- writing the tests "in advance" would avoid this problem.

Nihil sub sole novi...


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


Memory leak issue with complex data structure

2007-07-04 Thread Alan Franzoni
Hello,
I've got a complex data structure (graph-like). Each of my nodes may
reference zero or more other nodes, internally managed by a set() object.

I have a root node which is not referenced by any other node. So, I
created a "clear()" method which is called on all children (by calling
their clear() method" and then clears the set with the references of the
node itself.

I have a serious "leak" issue; even though I clear all those sets and I
delete all the references I can have to the current namespace, memory is
not freed.

I have tried the gc module and it couldn't help (I can't determine where
the references are) and I tried using weakref.ref as well to connect
object, but then I have problems (objects have no more references to
them beside their parents, hence they get deleted).

I understand it's impossibile to tell what's my problem without seeing
the actual code (which I can't post) but I'm asking if there's any
tool/debugger I could employ in order to track what's happening.

Thanks!

--
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using subprocess for non-terminating command

2007-07-04 Thread Steve Holden
O.R.Senthil Kumaran wrote:
> * zacherates <[EMAIL PROTECTED]> [2007-07-04 12:09:03]:
> 
>>> How should I handle these kind of commands (ping 127.0.0.1) with
>>> subprocess module. I am using subprocess, instead of os.system because
>>> at anypoint in time, I need access to stdout and stderr of execution.
>> Ping, for one, allows you to set an upper bound on how long it runs
>> (the -c option).  This is probably the cleanest approach if it's
>> available.
>>
> 
> Yes, I am aware of the ping -c option. But again even that does not help.
> try
> process = subprocess.Popen('ping -c 10 127.0.0.1', stdin=subprocess.PIPE,
> shell=True)
> process.stdout.read()  # This will hang again.
> 
> I am not sure, why subprocess is behaving so.
> 
>> You can also send the subprocess signals if you need it to exit
>> (although, this is a unix thing so I'm not sure how portable it is).
> 
> Yes, I have tried to kill and then get the standard output result.
> But the result has been the same. I could not read the Popen returned file
> object.
> 
>> You could emulate having a timeout on child.stdout.read by registering
>> a callback with Timer to kill the child.
> 
> I dont know how to do this. I shall give it a try ( by looking around ) and
> trying. 
> 

Is it possible your ping implementation outputs to stderr?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Reversing a string

2007-07-04 Thread Aahz
In article <[EMAIL PROTECTED]>,
Martin Durkin  <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] (Alex Martelli) wrote in
>news:[EMAIL PROTECTED]: 
>>
>> So, something like:
>> 
>> for c in reversed(x): print c
>> 
>> is mostly likely how I'd present the solution to the task. 
>
>This is an interesting point to me. I am just learning Python and
>I wonder how I would know that a built in function already exists?
>At what point do I stop searching for a ready made solution to a
>particular problem and start programming my own function?  Is it just a
>matter of reading *all* the documentation before I start coding?

You should at least know that you can do:

l = list(s)
l.reverse()
for c in l:
print c

This works in all versions of Python back to 1.5.2 IIRC.  reversed() is
a moderately new built-in function; I would agree with people who claim
that you should memorize most of the built-in functions (which is
precisely why there is a high barrier to adding more built-in functions).

But certainly if you're using a datatype you should make a point of
reading all its documentation, which would mean you'd know that list()
can convert any iterable type.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

I support the RKAB
-- 
http://mail.python.org/mailman/listinfo/python-list


Help search files

2007-07-04 Thread Alejandro Decchi

Hello Someone can help me how to search file in a directory. I need to do a
form where the user write the word to search and if the file was found the
user must could download the file making click in the link
Sorry my english
thz
Alex
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: what is wrong with that r"\"

2007-07-04 Thread Neil Cerutti
On 2007-07-04, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-07-04, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Wed, 04 Jul 2007 11:21:14 +, Neil Cerutti wrote:
>>
>>> If the escaped quotes didn't function in raw strings, I'd be
>>> unable to construct (with a single notation) a regex that
>>> included both kinds of quotes at once.
>>> 
>>>   re.compile(r"'\"")
>>
>> Where's the problem!? ::
>>
>>   re.compile(r"''')
>
> That incurs the problem that you can't end with a '. So you
> can't end with *something* either way.

I take that back. With good planning, you can end with whichever
you need by choosing the other delimiter.

Oh well. It seemed like a good explanation at first.

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Paul Rubin
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> Because static type checks impose a lot of arbitrary restrictions,
> boilerplate code etc, which tends to make code more complicated than
> it needs to be, which is a good way of introducing bugs that wouldn't
> have existed without static type checks. 

Why do you say that?  By metrics and anecdotal evidence, Haskell code
appears to be at least as compact as Python code.

> Depending on the application domain and some technical and
> non-technical constraints and requirements, it (often) happens that
> it's better to have the application deployed now with an occasional
> error message than to have it next year...

I suppose that includes the thing I'm currently working on.  For
some other stuff I've done, such errors would have caused huge hassles,
lost customer money, etc.  

> And FWIW, when it comes to "weird piece of input data", statically
> typed languages are not specially better than dynamic ones...

I know that ML gives compiler warning messages if you have a pattern
match (sort of a variant of a case statement, not a regexp match)
which is non-exhaustive.  And Haskell's Maybe monad is part of an
idiom that handles failing computations (like regexp matches) much
more gracefully than Python can.  Both of those would help this
situation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-07-04 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote:
   ...
> This works in all versions of Python back to 1.5.2 IIRC.  reversed() is
> a moderately new built-in function;

Yep: it came with Python 2.4, first alpha just 4 years ago, final
release about 3 years and 8 months ago.  "Moderately new" seems an
appropriate tag.

> I would agree with people who claim
> that you should memorize most of the built-in functions (which is
> precisely why there is a high barrier to adding more built-in functions).

I think the built-in functions and types a beginner is likely to need
are a "fuzzy subset" (the decision of whether to include or exclude
something being not really obvious:-) roughly including:

abs all any bool chr cmp dict dir enumerate float getattr help hex int
iter len list max min object open ord property raw_input reversed set
sorted str sum tuple unichr unicode xrange zip

all reasonably documented at
 .  Of course, as I
mentioned, most inclusions and exclusions may be debatable (why do I
think people need xrange and not necessarily range, set and not
necessarily frozenset, property rather than classmethod, hex more likely
than oct, probably not complex, etc etc).


> But certainly if you're using a datatype you should make a point of
> reading all its documentation, which would mean you'd know that list()
> can convert any iterable type.

Yes, and also the methods and operators of (out of the builtin types I
listed above):

dict float int list open[*] set str tuple unicode

[*] well really file, that's the name of the builtin type, but open is
what one should use as a factory function for it!-)

str and unicode have almost identical methods, save for the big crucial
difference on the semantics of method .translate; float and int also
have the same operators; and tuple has hardly anything, so the learning
task is nowhere as big as it may seem from here:-).


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


Re: what is wrong with that r"\"

2007-07-04 Thread Neil Cerutti
On 2007-07-04, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 04 Jul 2007 11:21:14 +, Neil Cerutti wrote:
>
>> If the escaped quotes didn't function in raw strings, I'd be
>> unable to construct (with a single notation) a regex that
>> included both kinds of quotes at once.
>> 
>>   re.compile(r"'\"")
>
> Where's the problem!? ::
>
>   re.compile(r"''')

That incurs the problem that you can't end with a '. So you can't
end with *something* either way.

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


Re: ActivePython

2007-07-04 Thread Trent Mick
Frank Swarbrick wrote:
> Why might one choose to use ActivePython instead of using the free CPython?

Expanding on what Alex already said, there are a few reasons:

1. On Windows, ActivePython also includes the PyWin32 [1] extensions 
which otherwise you'd have to install separately over a python.org install.

2. ActivePython includes ready-to-install packages for more platforms 
(some of which the python.org distros also cover, of course):
 * Windows/x86 and Windows/x64,
 * Mac OS X (Universal build),
 * Linux/x86 and Linux/x86_64,
 * Solaris SPARC and x86,
 * HP-UX, and
 * AIX.
For some of these platforms (e.g. Linux), a fair amount of work has been 
done to ensure you can use all of the core extensions (e.g. Tkinter, 
bsddb, bzip2, etc.) out of the box without running into dependency 
issues. ActivePython's installer on the Un*x platforms also makes it 
easy to install either in a shared location or in a user-specific location.

3. ActivePython includes a number of extra documentation sets that may 
prove useful to some. E.g. "Dive Into Python", a non-programmer's 
tutorial for Python, the Python HOWTOs, a snapshot of the Python PEPs, 
the Python FAQs, back copies of Andrew Kuchling's excellent "What's New 
in Python"



Some sometimes mentioned, but untrue reasons to avoid ActivePython:

- It doesn't include OpenSSL bindings.
   As of ActivePython 2.5.0.0, full SSL bindings are included.

- It isn't free.
   See my answer to Steve, below.

- It isn't compatible with python.org's Python distro.
   It is. If there is a case where this isn't the case, it is a serious bug.


Some more details here:
http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/whatsincluded.html


To answer some questions from others on this thread:

tleeuwenburg wrote:
 > Well, Komodo is a nice enough IDE, so you might choose to use
 > ActivePython for integration reasons, and maybe it's a little easier
 > on Windows.
 >
 > However, I would have thought that if you were planning to distribute
 > an application, you would want to choose CPython for maximum
 > interoperability with external packages.

Note that Komodo in no way, "prefers" ActivePython over a python.org 
installation. One of the primary requirements of ActivePython is to 
fully binary compatible with a python.org build of the same version -- 
if it isn't, it is a serious bug. As well, with Komodo we aren't *at 
all* interested in locking people in to our language distros. (BTW: I 
also work on Komodo.)


 > The ActiveState web page doesn't
 > really talk about their reasons very much.

As to reasons for ActivePython: ActiveState believes in the dynamic 
languages (all of the developers here are very passionate about that) 
and we are both happy to and view it as in our best interests to do what 
we can to ensure that the dynamic language communities are vibrant and 
competitive with the more corporate-backed languages and technologies.

Of course, it isn't pure altruism, but more of a symbiosis. ActiveState 
provides for-pay contracts for Perl, Python and Tcl distributions for 
things like specific support and builds (for example, some companies are 
happy to pay for the leg-work for an up-to-date Python installer for an 
old version of HP-UX that supports their C++ extensions).

Generally, any patches that we've worked on for these kinds of things 
are provided back to the language cores so that everyone benefits. As 
well, these contracts allow us to maintain a large number of build and 
test machines for the for-pay and free Active* distros -- and to buy 
food for developers such as myself.


Steve Holden wrote:
 > ...the last time I looked the ActivePython distribution
 > doesn't allow redistribution at all (i.e. it's not technically open
 > source).

Steve is correct that ActivePython isn't open source. It is free (as in 
beer), meaning that it is completely free for you to download, install 
and use on as many machines as you want.

As to redistribution: Yes, it is technically correct that you cannot 
fully redistribute ActivePython without our permission. However, 
ActivePython's license expressly *does* allow you to use the "freezing" 
utilities such as "py2exe" and "py2app" -- so you have no worries there. 
  For fully embedding Python in an application, in my experience [2] 
you'll want to be building your own Python anyway.


Sincerely,
Trent
Python Tech Lead at ActiveState
also, a Komodo developer


[1] PyWin32 is primarily a set of extensions that provide Python 
bindings to much of the Windows API and to Windows COM. It also includes 
an editor/IDE called PythonWin. 

[2] Komodo embeds its own Python build for doing a lot of the core 
logic. A custom Python build is generally necessary to avoid 
cross-talking between Komodo's Python and other possible Pythons on the 
system.


-- 
Trent Mick
trentm at activestate.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i change an Object type ?

2007-07-04 Thread kyosohma
On Jul 4, 12:40 am, Tim Roberts <[EMAIL PROTECTED]> wrote:
> KuhlmannSascha <[EMAIL PROTECTED]> wrote:
>
> >i tried now for several hours to read through a win32com API to access
> >Itunes and read out myplaylists.
>
> >First of all the Code:
> >...
> >The current Logic is to access first Itunes and then a Playlist
> >Collection.
> >This Playlist collection returns different kind of objects for
> >Playlists.
> >I am focussing on the Playlists of the object UserPlaylist.
> >(CodeLine:   if curPlaylist.Kind == 2:)
> >After that i should be sure to have a UserPlaylist, but Python stops
> >with an exception that the requested Attribute "Smart"  is not
> >available
> >Error MEssage:
> >AttributeError: ' >instance at 0x30216960>' object has no attribute 'Smart'
>
> Smart is part of IITUserPlaylist, not IITPlaylist.  You need to call
> curPlaylist.QueryInterface to get the IITUserPlaylist, but that means
> you'll need to know the GUID for IITUserPlaylist.  Perhaps Google will
> help.
> --
> Tim Roberts, [EMAIL PROTECTED]
> Providenza & Boekelheide, Inc.

These look like they could give you some pointers too:

http://www.brunningonline.net/simon/blog/archives/001627.html
http://lazycat.org/backburner.html
http://mail.python.org/pipermail/python-win32/2007-February/005506.html

Mike

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


Re: ActivePython

2007-07-04 Thread Steve Holden
Trent Mick wrote:
> Frank Swarbrick wrote:
[...]
> Steve Holden wrote:
>  > ...the last time I looked the ActivePython distribution
>  > doesn't allow redistribution at all (i.e. it's not technically open
>  > source).
> 
> Steve is correct that ActivePython isn't open source. It is free (as in 
> beer), meaning that it is completely free for you to download, install 
> and use on as many machines as you want.
> 
Indeed, and a jolly good system it is, too. Saves you loads of time 
integrating things that are already fully integrated in ActivePython.

> As to redistribution: Yes, it is technically correct that you cannot 
> fully redistribute ActivePython without our permission. However, 
> ActivePython's license expressly *does* allow you to use the "freezing" 
> utilities such as "py2exe" and "py2app" -- so you have no worries there. 

That's going to account for most people's uses for application 
distribution, I'd have thought, thanks for pointing that out.

>   For fully embedding Python in an application, in my experience [2] 
> you'll want to be building your own Python anyway.
> 
> 
Yup.

[...]
 > [2] Komodo embeds its own Python build for doing a lot of the core
 > logic. A custom Python build is generally necessary to avoid
 > cross-talking between Komodo's Python and other possible Pythons
 > on the system.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: Portable general timestamp format, not 2038-limited

2007-07-04 Thread James Harris
On 1 Jul, 15:11, "Peter J. Holzer" <[EMAIL PROTECTED]> wrote:
...
> Stick to unix timestamps but store them as a double precision floating
> point number. The 53 bit mantissa gives you currently a resolution of
> about 200 ns, slowly deteriorating (you will hit ms resolution in about
> 280,000 years, if I haven't miscalculated). Any language and database
> should be able to handle double-precision FP numbers, so that's as
> portable as it gets and conversion from/to system time should be
> trivial.
>
> If you need to represent milliseconds exactly, you can just multiply the
> timestamp with 1000 (and get java timestamps).

Interesting option. I think my choice is between separate day and sub-
day 32-bit unsigned integers, text, and this 64-bit float option.

I'm not clear, though. Did you mean to store double precision numbers
where the seconds are the units (I assume this) or where the days are
the units? And what do you think of the other option?

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


Does Python work with QuickBooks SDK?

2007-07-04 Thread walterbyrd
My guess is that it would, but I can find no mention of python in the
intuit developers site. I  can find some references to PHP and Perl,
but no Python.

I looks to me like Intuit develops have a strong preference for visual-
basic, then c/c++, then delphi.

I find it just a little bit surprising, since Python does work
with .Net and all.

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


Re: Interest in a one-day business conference for Python, Zope and Plone companies ?

2007-07-04 Thread Thomas Heller
eGenix Team: M.-A. Lemburg schrieb:
> Hello,
> 
> eGenix is looking into organizing a one day conference
> specifically for companies doing business with Python, Zope and
> Plone. The conference will likely be held in or close to
> Düsseldorf, Germany, which is lively medium-sized city, with good
> airport connections world-wide and specifically to all major
> European  cities, so it's easy getting there and ideal for a one
> day event.

I would be interested in such an event.  But: Am I the only one?

Thomas

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


Re: object references/memory access

2007-07-04 Thread John Nagle
Karthik Gurusamy wrote:
> On Jul 2, 10:57 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> 
>I have found the stop-and-go between two processes on the same machine
>leads to very poor throughput. By stop-and-go, I mean the producer and
>consumer are constantly getting on and off of the CPU since the pipe
>gets full (or empty for consumer). Note that a producer can't run at
>its top speed as the scheduler will pull it out since it's output pipe
>got filled up.
>>...
> If the problem does not require two way communication, which is
> typical of a producer-consumer, it is a lot faster to allow P to fully
> run before C is started.
> 
> If P and C are tied using a pipe, in most linux like OS (QNX may be
> doing something really smart as noted by John Nagle), there is a big
> cost of scheduler swapping P and C constantly to use the CPU. You may
> ask why? because the data flowing between P and C, has a small finite
> space (the buffer). Once P fills it; it will block -- the scheduler
> sees C is runnable and puts C on the CPU.

The killer case is where there's another thread or process other than C
already ready to run when P blocks.  The other thread, not C, usually
gets control, because it was ready to run first, and not until the other
thread runs out its time quantum does C get a turn.  Then C gets to
run briefly, drains out the pipe, and blocks.  P gets to run,
fills the pipe, and blocks.  The compute-bound thread gets to run,
runs for a full time quantum, and loses the CPU to C.  Wash,
rinse, repeat.

The effect is that pipe-like producer-consumer systems may get only a small
fraction of the available CPU time on a busy system.

When testing a producer-consumer system, put a busy loop in the
background and see if performance becomes terrible.  It ought to
drop by 50% against an equal-priority compute bound process; if
it drops by far more than that, you have the problem described here.

This problem is sometimes called "What you want is a subroutine call;
what the OS gives you is an I/O operation."  When you make a subroutine
call on top of an I/O operation, you get these scheduling problems.

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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Paul Boddie
Paul Rubin wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> > Because static type checks impose a lot of arbitrary restrictions,
> > boilerplate code etc, which tends to make code more complicated than
> > it needs to be, which is a good way of introducing bugs that wouldn't
> > have existed without static type checks.
>
> Why do you say that?  By metrics and anecdotal evidence, Haskell code
> appears to be at least as compact as Python code.

I think Bruno is referring to another class of languages here.
However, it's interesting to consider the work that sometimes needs to
go in to specify data structures in some languages - thinking of ML
and friends, as opposed to Java and friends. The campaign for optional
static typing in Python rapidly became bogged down in this matter,
fearing that any resulting specification for type information might
not be the right combination of flexible and powerful to fit in with
the rest of the language, and that's how we really ended up with PEP
3107: make the semantics vague and pretend it has nothing to do with
types, thus avoiding the issue completely.

Paul

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


Re: Portable general timestamp format, not 2038-limited

2007-07-04 Thread James Harris
On 3 Jul, 06:12, Scott David Daniels <[EMAIL PROTECTED]> wrote:
...
> Inspired format:
>  Days since a some standard date (the TAI date may be a good such
> date) expressed as fixed point 64-bit (32-bit day part, 32-bit
> day-fraction part) or floating point (using Intel's double-precision,
> for example, gives you 26 bits each for day and day-fraction, though
> the binary point moves for particular stamps).

This is close to or the same as my original suggestion. The break
between days and sub-days seems to make more sense than breaking the
fractional part elsewhere. It also gives a convenient point to hang
datestamps on rather than just timestamps.

FWIW I wonder if a 64-bit version of the above would cope with all
practical time needs. With that the time would range to +/- 9000
quintillion years (18 digits) and there would be over 200 trillion
ticks per second or 200 in a picosecond making, I think, each tick 5
femtoseconds.


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


ReSTedit ported to Linux?

2007-07-04 Thread Helmut Jarausch
Hi,
does anybody know if ReSTedit (originally for Mac OS X) has been ported to 
Linux?

Many thanks for a hint,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread John Nagle
Paul Boddie wrote:
> Paul Rubin wrote:
> 
> The campaign for optional
> static typing in Python rapidly became bogged down in this matter,
> fearing that any resulting specification for type information might
> not be the right combination of flexible and powerful to fit in with
> the rest of the language, and that's how we really ended up with PEP
> 3107: make the semantics vague and pretend it has nothing to do with
> types, thus avoiding the issue completely.

 Unfortunately, that may lead to the worst of both worlds.

 If you think enforced static typing is painful, try maintaining code with
non-enforced static typing.  You can't rely on the type information, and
inevitably some of it will be wrong.  You can't tell by looking which
is wrong, of course.

 This has been tried.  Original K&R C had non-enforced static typing.
All "struct" pointers were equivalent.  It wasn't pretty.

 It takes strict programmer discipline to make non-enforced static
typing work.  I've seen it work in an aerospace company, but the Python
crowd probably doesn't want that level of engineering discipline.
Non-enforced static typing requires a quality assurance group that
reads code and checks coding standards.

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


Re: using subprocess for non-terminating command

2007-07-04 Thread O.R.Senthil Kumaran
* Jerry Hill <[EMAIL PROTECTED]> [2007-07-04 11:23:33]:
> 
>  That's because you tied stdin to a pipe in your Popen call, but then
>  tried to read from stdout.  Try this instead:

My mistake. I had just 'typed' the command in the mail itself and forgot to
include the stdin, stdout, and stderr and mentioned it as hung based on some
recollection.

> 
> >>> process = subprocess.Popen("ping -c 10 127.0.0.1",
>  stdout=subprocess.PIPE, shell=True)
> >>> process.stdout.readlines()

I tried it again and found that giving the -c 10 returns a well defined
output. 
Only when the program has executed and the output available, subprocess can
read through PIPE's stdout it seems ( not at any other time). 
With killing, I loose the output.

>>> process = subprocess.Popen('ping 10 127.0.0.1', stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
>>> process.pid
3475
>>> import os
>>> import signal
>>> os.kill(process.pid,signal.SIGINT)
>>> process.stdout.read()
''
>>> # required output is lost!


-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help search files

2007-07-04 Thread Mariano Mara
Alejandro Decchi escribió:
> Hello Someone can help me how to search file in a directory. I need to 
> do a form where the user write the word to search and if the file was 
> found the user must could download the file making click in the link
> Sorry my english
> thz
> Alex
> 
You could try os.walk (search for "walk" here: 
http://docs.python.org/lib/os-file-dir.html) and then loop the results 
to find the file (sure there are some out of the box methods for this 
but right now I don't know any).
One thing I'm not sure if you want to search for a word within the file 
or if the submitted word matches the name of the file. My suggestion 
should work for the last option.

Good luck.



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


Re: Does Python work with QuickBooks SDK?

2007-07-04 Thread kyosohma
On Jul 4, 1:51 pm, walterbyrd <[EMAIL PROTECTED]> wrote:
> My guess is that it would, but I can find no mention of python in the
> intuit developers site. I  can find some references to PHP and Perl,
> but no Python.
>
> I looks to me like Intuit develops have a strong preference for visual-
> basic, then c/c++, then delphi.
>
> I find it just a little bit surprising, since Python does work
> with .Net and all.

I'm not seeing a Python wrapper for the SDK, but it looks like you can
access it with COM. This thread talks a little about doing just that:

http://mail.python.org/pipermail/python-win32/2004-May/001990.html

To learn more about Python and how to work with COM, check this site
out:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

I hope that helps you out.

Mike

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


Tkinter toggle a Label Widget based on checkbutton value

2007-07-04 Thread O.R.Senthil Kumaran
Following is a tk code, which will display a checkbutton, and when checkbox is
enabled, it will show the below present Label.

What I was trying is, when checkbox is enabled the Label should be shown and
when checkbox is disabled, the window should look like before.

But, I am finding that once enabled (shown), its not very-straightforward to
hide it from the window.

Any suggestions on  how can i make this checkbutton effect.
1) Press Enable IP, the Label IP should be shown.
2) Toggle Enable IP (So that its unset). the Label IP should not be shown.

#!/usr/bin/python
from Tkinter import *
root = Tk()
root.title('something')
x = StringVar()
def display():
if x.get():
ip = Label(root,text="IP:")
ip.grid(row=3,column=0)

proxy = Checkbutton(root, text="Enable IP:", variable = x,onvalue="proxy",
offvalue="",command=display)
proxy.grid(row=2,column=0)
root.mainloop()


-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Find This Module

2007-07-04 Thread [EMAIL PROTECTED]
I'm looking at the source for the module sre_compile.py and it does
this import:

import _sre

But I can't find a file related to _sre anywhere.  Where is it?  And
more generally, how does one find the location of a built in module?

Thanks,

Greg

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


Re: Tkinter toggle a Label Widget based on checkbutton value

2007-07-04 Thread Wojciech Muła
O.R.Senthil Kumaran wrote:
> Any suggestions on  how can i make this checkbutton effect.
> 1) Press Enable IP, the Label IP should be shown.
> 2) Toggle Enable IP (So that its unset). the Label IP should not be shown.
>
> #!/usr/bin/python
> from Tkinter import *
> root = Tk()
> root.title('something')
> x = StringVar()

ip = Label(root,text="IP:")
> def display():
  global ip
> if x.get():
> #ip = Label(root,text="IP:")
> ip.grid(row=3,column=0)
   else:
  ip.grid_forget()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using subprocess for non-terminating command

2007-07-04 Thread zacherates
> Only when the program has executed and the output available, subprocess can
> read through PIPE's stdout it seems ( not at any other time).
> With killing, I loose the output.

This is untrue.
>>> process.stdout.read() # Blocks until end of stream.
>>> process.stdout.read(1) # Reads one character, only blocks if that character 
>>> is unavailable.

As such you can read the needed chars from the child's STDOUT one at a
time. For example:

import os
import signal
import subprocess
import threading
import sys

stop = False
ping = subprocess.Popen('ping 127.0.0.1', shell = True, stdout =
subprocess.PIPE)

def kill():
global stop
stop = True
os.kill(ping.pid, signal.SIGTERM)

threading.Timer(5, kill).start()

while not stop:
 sys.stdout.write(ping.stdout.read(1))

This solution let's you read from the stdout of a program that may
never terminate and time out after a certain amount of time but it's
not pretty.  It's unix specific and introduces threads into a program
that doesn't need them.  I'd go with trying to limit the time the
child runs through command line options if at all possible.

Cheers,
   Aaron


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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Paul Rubin
John Nagle <[EMAIL PROTECTED]> writes:
>  This has been tried.  Original K&R C had non-enforced static typing.
> All "struct" pointers were equivalent.  It wasn't pretty.
> 
>  It takes strict programmer discipline to make non-enforced static
> typing work.  I've seen it work in an aerospace company, but the Python
> crowd probably doesn't want that level of engineering discipline.

I think even enforced static types wouldn't cure what I see as the
looseness in Python.  There is not enough composability of small
snippets of code.  For example, the "for" statement clobbers its index
variable and then leaks it to the outside of the loop.  That may be
more of a culprit than dynamic types.  Perl and C++ both fix this with
syntax like

for (my $i in ...) ...   (perl)  or
for (int i = 0; i < n; i++) ...  (C++, Java)

making a temporary scope for the index variable.  Python even leaks
the index variable of list comprehensions (I've mostly stopped using
them because of this), though that's a recognized wart and is due to
be fixed.

Python would be helped a lot by some way to introduce temporary
scopes.  We had some discussion of this recently, concluding that
there should be a compiler warning message if a variable in a
temporary scope shadows one from a surrounding scope.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI vs WSGI

2007-07-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Dear all,
> 
> what is the difference? Middleware?
> 
> I'm wondering because the only variables I ever needed were PATH_INFO,
> REQUEST_METHOD, QUERY_STRING and maybe one more, all of which should
> be available from CGI, too.
> 
> Thanks.
> 

WSGI is intented as a gateway between a web server and a long-running 
python application. Which means you don't have to launch a new Python 
interpreter, import libs, parse config, connect to the database etc etc 
for each and every request.

Also, it's (IMHO) much more usable than CGI.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python work with QuickBooks SDK?

2007-07-04 Thread [EMAIL PROTECTED]
On Jul 4, 2:51 pm, walterbyrd <[EMAIL PROTECTED]> wrote:
> My guess is that it would, but I can find no mention of python in the
> intuit developers site. I  can find some references to PHP and Perl,
> but no Python.
>
> I looks to me like Intuit develops have a strong preference for visual-
> basic, then c/c++, then delphi.
>
> I find it just a little bit surprising, since Python does work
> with .Net and all.

I've been using the QuickBooks SDK with Python for years.  There was
an example somewhere on Intuit's site to get you started.  I just
built off of that.  But now I can't locate that sample anywhere!

Basically you just access it via the COM interface.  Use the Python
win32 extentions.  Email me and I can probably help you more.

-Greg




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


Re: 15 Exercises to Know A Programming Language

2007-07-04 Thread Martin
On Jul 3, 1:47 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jul 3, 7:58 pm, Martin <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am trying to improve my Python skills through some exercises.
> > Currently I am working on Larry's "15 exercises to know a programming
> > language " (http://www.knowing.net/
> > PermaLink,guid,f3b9ba36-848e-43f8-9caa-232ec216192d.aspx). The first
> > exercise is this:
>
> > "Write a program that takes as its first argument one of the words
> > 'sum,' 'product,' 'mean,' or 'sqrt'  and for further arguments a
> > series of numbers. The program applies the appropriate function to
> > the series."
>
> > My solution so far is this:
>
> >http://dpaste.com/13469/
>
> > I would really like some feedback. Is this a good solution? is it
> > efficient? robust? what could be improved? any not looking for a
> > revised solution, hints on what to improve are also very welcome.
>
> > Martin
>
> sum is a builtin function in Python 2.3 and later. You could do
> something like this:
>
> try:
> sum
> except NameError:
> def sum(args):
> return reduce(operator.add, args)
>
> Tested with 2.5 back to 2.1, and 1.5.2 :-)

Thanks John and Daniel. My revised version now uses sum(). I have
started to implement some basic error checking and validation.

Martin

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


Re: Find This Module

2007-07-04 Thread Marc 'BlackJack' Rintsch
On Wed, 04 Jul 2007 20:00:07 +, [EMAIL PROTECTED] wrote:

> I'm looking at the source for the module sre_compile.py and it does
> this import:
> 
> import _sre
> 
> But I can't find a file related to _sre anywhere.  Where is it?  And
> more generally, how does one find the location of a built in module?

It's built into the interpreter executable.

In [85]: import _sre

In [86]: _sre
Out[86]: 

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


AIML, Python, Java

2007-07-04 Thread Boris Ozegovic
Hi

I have a chatterbot written in AIML.  I am using PyAIML, and HTTP server as
a mediator between user and PyAIML.  Server calls PyAIML, and sends the
result string to the sensor network which is written in Java; and in the
end, server returns value from Java method.  Can I somehow call Java
methods inside Python code, or I must use Jython?  Can I use PyAIML in
Jython?  

-- 
Ne dajte da nas lažljivac Bandić truje:
http://cnn.blog.hr/arhiva-2007-06.html#1622776372
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Bruno Desthuilliers
Paul Rubin a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> 
>>Because static type checks impose a lot of arbitrary restrictions,
>>boilerplate code etc, which tends to make code more complicated than
>>it needs to be, which is a good way of introducing bugs that wouldn't
>>have existed without static type checks. 
> 
> 
> Why do you say that?   By metrics and anecdotal evidence, Haskell code
> appears to be at least as compact as Python code.

Haskell - as other languages using type-inference like OCaml - are in a 
different category. Yes, I know, don't say it, they are statically typed 
- but it's mostly structural typing, not declarative typing. Which makes 
them much more usable IMHO. It's too bad they are not more widely adopted.

>>Depending on the application domain and some technical and
>>non-technical constraints and requirements, it (often) happens that
>>it's better to have the application deployed now with an occasional
>>error message than to have it next year...
> 
> 
> I suppose that includes the thing I'm currently working on.
 >
> For
> some other stuff I've done, such errors would have caused huge hassles,
> lost customer money, etc.  

Still, static typechecking is not a garantee against runtime errors. Nor 
against logical errors.

> 
>>And FWIW, when it comes to "weird piece of input data", statically
>>typed languages are not specially better than dynamic ones...
>  
> I know that ML gives compiler warning messages if you have a pattern
> match (sort of a variant of a case statement, not a regexp match)

I know what pattern matching is, I did play a bit with OCaml and Haskell.

> which is non-exhaustive.  And Haskell's Maybe monad is part of an
> idiom that handles failing computations (like regexp matches) much
> more gracefully than Python can.  Both of those would help this
> situation.

I'd have to see a concrete use case. And I'd need much more real-world 
experience with some ML variant, but this is not something I can expect 
to happen in a near future - it's difficult enough to convince PHBs that 
Python is fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python work with QuickBooks SDK?

2007-07-04 Thread walterbyrd
Thanks to Greg and Mike.

I am not looking for specifics right now. I was just wondering if
there was a practical way to do use python to integrate with intuit
apps.

Apparently, there is.

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


Re: using subprocess for non-terminating command

2007-07-04 Thread prikar20
On Jul 4, 12:29 pm, "O.R.Senthil Kumaran"
<[EMAIL PROTECTED]> wrote:
> * Jerry Hill <[EMAIL PROTECTED]> [2007-07-04 11:23:33]:
>
>
>
> >  That's because you tied stdin to a pipe in your Popen call, but then
> >  tried to read from stdout.  Try this instead:
>
> My mistake. I had just 'typed' the command in the mail itself and forgot to
> include the stdin, stdout, and stderr and mentioned it as hung based on some
> recollection.
>
>
>
> > >>> process = subprocess.Popen("ping -c 10 127.0.0.1",
> >  stdout=subprocess.PIPE, shell=True)
> > >>> process.stdout.readlines()
>
> I tried it again and found that giving the -c 10 returns a well defined
> output.
> Only when the program has executed and the output available, subprocess can
> read through PIPE's stdout it seems ( not at any other time).
> With killing, I loose the output.
>
> >>> process = subprocess.Popen('ping 10 127.0.0.1', stdin=subprocess.PIPE,
>
> stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)

I think you meant ping -c 10 (and not ping 10). If you pass first arg
as string, are you sure you didn't get an exception? I get one if I
use 'ping -c 10 ' -- because looks like subprocess is
searching for an executable named as "ping -c 10 ..." (not just
'ping').
So I sent in a sequence and it all worked as expected (I didn't have
shell=True, but it shouldn't matter in getting the required output).

Try the sequence as first arg.

>>> process = subprocess.Popen('ping -c 10 127.0.0.1', stdin=subprocess.PIPE, 
>>> stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Traceback (most recent call last):
  File "", line 1, in 
  File "/auto/xxxkarthikxxx/python251/lib/python2.5/subprocess.py",
line 593, in __init__
errread, errwrite)
  File "/auto/xxxkarthikxxx/python251/lib/python2.5/subprocess.py",
line 1079, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
>>> process = subprocess.Popen('ping -c 10 127.0.0.1'.split(), 
>>> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

>>> print process

>>> print process.pid
13435
>>> print process.stdout.read()
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.025 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.006 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.005 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.004 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.011 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.007 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.020 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.006 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.006 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.006 ms

--- 127.0.0.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9013ms
rtt min/avg/max/mdev = 0.004/0.009/0.025/0.007 ms, pipe 2

>>>

-- Karthik

>
> >>> process.pid
> 3475
> >>> import os
> >>> import signal
> >>> os.kill(process.pid,signal.SIGINT)
> >>> process.stdout.read()
> ''
> >>> # required output is lost!
>
> --
> O.R.Senthil Kumaranhttp://uthcode.sarovar.org


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


deleated bios?

2007-07-04 Thread acprkit
Hi

I have an ibm thinkpad x23, and shut it down about an hour ago. When I
went to
reboot , all the lights come on then they go off and only the light
with the z in a circle stays on. The screen stays blank and the hard
drive spins. Could I have deleated the bios when I added memory
(shocked the motherboard?)



Thanks for any help!

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


Re: Portable general timestamp format, not 2038-limited

2007-07-04 Thread Peter J. Holzer
On 2007-07-04 18:46, James Harris <[EMAIL PROTECTED]> wrote:
> On 1 Jul, 15:11, "Peter J. Holzer" <[EMAIL PROTECTED]> wrote:
> ...
>> Stick to unix timestamps but store them as a double precision floating
>> point number. The 53 bit mantissa gives you currently a resolution of
>> about 200 ns, slowly deteriorating (you will hit ms resolution in about
>> 280,000 years, if I haven't miscalculated). Any language and database
>> should be able to handle double-precision FP numbers, so that's as
>> portable as it gets and conversion from/to system time should be
>> trivial.
>>
>> If you need to represent milliseconds exactly, you can just multiply the
>> timestamp with 1000 (and get java timestamps).
>
> Interesting option. I think my choice is between separate day and sub-
> day 32-bit unsigned integers, text, and this 64-bit float option.
>
> I'm not clear, though. Did you mean to store double precision numbers
> where the seconds are the units (I assume this) or where the days are
> the units? And what do you think of the other option?

I was thinking about using the seconds as units (so
2007-07-04T23:02:04.123 CET is represented as 1183582924.123). 
It's a natural extension of the unix time stamp, so you can often just
pass the values to the normal date routines (especially in languages
like perl which don't really distinguish between integers and floating
point numbers).

But it really doesn't matter much. If you ignore leap seconds, using
days instead of seconds is just a constant factor (in fact, the unix
timestamp ignores leap seconds, too, so it's always a constant factor).
You can't represent a second exactly if the unit is one day (1/86400 is
not a multiple of a power of two), but that probably doesn't matter.


hp


-- 
   _  | Peter J. Holzer| I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR   | with an emu on his shoulder.
| |   | [EMAIL PROTECTED] |
__/   | http://www.hjp.at/ |-- Sam in "Freefall"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Paul Rubin
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> Haskell - as other languages using type-inference like OCaml - are in
> a different category. Yes, I know, don't say it, they are statically
> typed - but it's mostly structural typing, not declarative
> typing. Which makes them much more usable IMHO. 

Some users in fact recommend writing an explicit type signature for
every Haskell function, which functions sort of like a unit test.
That doesn't bloat the code up noticibly.  The conciseness of those
languages comes more from polymorphism and convenient ways of writing
and using higher-order functions, than from type inference.

> Still, static typechecking is not a garantee against runtime
> errors. Nor against logical errors.

Right, however the reality is it does seem to prevent a lot of
surprises.  There's even an intermediate language (a language
generated by a compiler as an intermediate step towards emitting
machine code) called Henk, in which EVERY value is type-annotated (and
in a very fancy type system too).  The author reports that the
annotations have been very helpful for noticing compiler bugs.

> I'd have to see a concrete use case. And I'd need much more real-world
> experience with some ML variant, but this is not something I can
> expect to happen in a near future - it's difficult enough to convince
> PHBs that Python is fine.

Monad Reader #7 has an article about some Wall street company using ML:

  http://www.haskell.org/sitewiki/images/0/03/TMR-Issue7.pdf

see the article by Yaron Minsky.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reversing a string

2007-07-04 Thread Jan Vorwerk
Martin Durkin a écrit , le 02.07.2007 06:38:
> This is an interesting point to me. I am just learning Python and I 
> wonder how I would know that a built in function already exists? 
> At what point do I stop searching for a ready made solution to a 
> particular problem and start programming my own function?
> Is it just a matter of reading *all* the documentation before I start 
> coding?

The answer from another beginner like me is: dir()

Try it out interactively (my example with Python 2.4):

---
 >>> dir()
['__builtins__', '__doc__', '__name__']

 >>> __builtins__


 >>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 
'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 
'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'IOError', 
'ImportError', 'IndentationError', 'IndexError', 'KeyError', 
'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 
'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 
'OverflowWarning', 'PendingDeprecationWarning', 'ReferenceError', 
'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 
'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 
'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 
'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 
'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', 
'__debug__', '__doc__', '__import__', '__name__', 'abs', 'apply', 
'basestring', 'bool', 'buffer', 'callable', 'chr', 'classmethod', 'cmp', 
'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 
'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 
'file', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 
'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 
'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 
'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 
'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 
'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 
'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']

 >>> reversed


 >>> dir(reversed)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', 
'__init__', '__iter__', '__len__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__str__', 'next']

 >>> print reversed.__doc__
reversed(sequence) -> reverse iterator over values of the sequence

Return a reverse iterator

---
Far from me the idea that manuals are useless, but this is a nice thing 
about Python that you can look at what is available interactively.

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


Re: using subprocess for non-terminating command

2007-07-04 Thread Karthik Gurusamy
On Jul 4, 4:38 am, Phoe6 <[EMAIL PROTECTED]> wrote:
> Hi all,
> Consider this scenario, where in I need to use subprocess to execute a
> command like 'ping 127.0.0.1' which will have a continuous non-
> terminating output in Linux.
>
> # code
>
> >>>import subprocess
> >>>process = subprocess.Popen('ping 127.0.0.1', shell=True, 
> >>>stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> >>>print process.pid # returns pid
> >>>print process.poll() # returns None!!! this is strange.

It's expected behavior. It means the child process is still running.

> >>>print process.stdout.read()
>
> # This hangs at this point.

This too is expected behavior. 'ping ' runs forever
generating continuous output. It doesn't stop by itself.

read() reads until there is data available in the file object. Thus it
doesn't ever finish since the child never stops generating data.

If you do read(n), then it reads n bytes and returns.


> How should I handle these kind of commands (ping 127.0.0.1) with
> subprocess module. I am using subprocess, instead of os.system because
> at anypoint in time, I need access to stdout and stderr of execution.
>

Using subprocess is good. Just ensure your child stops data generation
at some point. For ping, you can use '-c ' or some other
application, you can try closing it's stdin (e.g. cat, bc, gdb)

Thanks,
Karthik

> Thanks,
> Senthil


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


Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread Bruno Desthuilliers
Paul Rubin a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> 
>>Haskell - as other languages using type-inference like OCaml - are in
>>a different category. Yes, I know, don't say it, they are statically
>>typed - but it's mostly structural typing, not declarative
>>typing. Which makes them much more usable IMHO. 
> 
> 
> Some users in fact recommend writing an explicit type signature for
> every Haskell function, which functions sort of like a unit test.

Stop here. explicit type signature == declarative static typing != unit 
test.

> That doesn't bloat the code up noticibly.  The conciseness of those
> languages comes more from polymorphism and convenient ways of writing
> and using higher-order functions, than from type inference.

Type inference is certainly helpful for genericity.

> 
>>Still, static typechecking is not a garantee against runtime
>>errors. Nor against logical errors.
> 
> 
> Right, however the reality is it does seem to prevent a lot of
> surprises.  

I have few "surprises" with typing in Python. Very few. Compared to the 
flexibility and simplicity gained from a dynamism that couldn't work 
with static typing - even using type inference -, I don't see it a such 
a wonderful gain. At least in my day to day work.

> 
>>I'd have to see a concrete use case. And I'd need much more real-world
>>experience with some ML variant, but this is not something I can
>>expect to happen in a near future - it's difficult enough to convince
>>PHBs that Python is fine.
> 
> 
> Monad Reader #7 has an article about some Wall street company using ML:
> 
>   http://www.haskell.org/sitewiki/images/0/03/TMR-Issue7.pdf
> 
> see the article by Yaron Minsky.

Sorry, I don't live near Wall Street !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


MethodType/FunctionType and decorators

2007-07-04 Thread Alex Popescu
Hi all!

I am pretty new to Python, so please excuse me if I am missing
something. Lately, I've been playing with decorators and I am a bit
confused about some behavior. Here is the code that puzzles me:

in python shell:

def function():
  pass

class A(object):
  def method(self):
pass

from types import MethodType
from types import FunctionType

if type(function) is FunctionType:
  print "this is what I expect"

if type(A.method) is MethodType:
  print "this is what I expect"

so far so good... everything seems logical.

But if a decorator is declared things are becoming different:

def deco(function):
  if type(function) is MethodType:
print "MethodType"
  elif type(function) is FunctionType:
print "FunctionType"

@deco
def function2():
  pass

# ==> this prints out FunctionType (oke)

class A(object):
  @deco
  def method(self):
pass

# ==> this prints out FunctionType (???)

Can somebody shed some light on why I am seeing this?

(Using Python 2.5.1 on Win XP).

TIA,

./alex
--
.w( the_mindstorm )p.

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


Re: Portable general timestamp format, not 2038-limited

2007-07-04 Thread James Harris
On 4 Jul, 22:18, "Peter J. Holzer" <[EMAIL PROTECTED]> wrote:
...
> But it really doesn't matter much. If you ignore leap seconds, using
> days instead of seconds is just a constant factor (in fact, the unix
> timestamp ignores leap seconds, too, so it's always a constant factor).
> You can't represent a second exactly if the unit is one day (1/86400 is
> not a multiple of a power of two), but that probably doesn't matter.

Sure. However, the proposal was to define ticks as 25 microseconds.

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


  1   2   >