ANN: Hypy 0.8.2 (minor bugfixes)

2009-01-21 Thread Cory Dodt
Hypy is a fulltext search interface for Python applications. Use it to index
and search your documents from Python code. Hypy is based on the
estraiernative bindings by Yusuke Yoshida.

* Fast, scalable
* Perfect recall ratio by N-gram method
* High precision by hybrid mechanism of N-gram and morphological analyzer
* Phrase search, regular expressions, attribute search (including
numeric and date comparisons), and similarity search
* Simple and powerful API

Homepage, downloads, everything, etc.: http://goonmill.org/hypy/

This is of course on pypi and can be installed with easy_install or
pip.  You will need Hyper Estraier installed to use it.

Release Version 0.8.2 (2009-01-20)
~~

* I was unconditionally importing ez_setup in my setup.py and that makes it
  hard to easy_install.  Don't do that.
* No library functionality change, but now more users can install it.
--
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Nonblocking keyboard input in python Idle windows

2009-01-21 Thread AON LAZIO
Hi,
  I want to solve the problem like this running on Idle python windows

The problem:
   the program continue printing 1,2,3,4,5 until it receives the
input 'enter' from keyboard then it stops printing

this could be done using msvcrt.kbhit() and msvcrt.getch() on command prompt
windows
However, those methods could not work in Python Idle windows.
  Any of you guys know the methods to solve this problem?

  Thanks in advance.

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


Start Python at client side from web app

2009-01-21 Thread Thomas Guettler
Hi,

I want to start Python at the client side from a web application. The
app is an intranet application, and all client PCs are under our control (we
can install software on them).

But I don't want to update the installation too often. Here is my idea:

We create a custom mime-type and register it on the client PC. The web 
application
can send signed python code to the client PC. If the signature is correct,
the code will be executed at the client. The signature prevents others from 
executing
code.

Has someone seen or done something like this before?

I can code this myself, but prefer to use some open source project, if it 
exists.


Thanks in advance,
  Thomas Güttler

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-21 Thread Steven D'Aprano
On Tue, 20 Jan 2009 11:58:46 -0700, Joe Strout wrote:

 Aaron Brady wrote:
 
 I think it would be a good step if you could make some sensible
 interpretation of a typical statement without its parentheses.
 
 f abc 123
 --
 f( abc, 123 )
 
 It would be just the thing in a couple of situations...
 
 Such a language is possible -- take a look at REALbasic sometime.  RB
 certainly has its problems (mainly bugs), but the language syntax is
 beautiful.  To your point, parentheses are not required around any
 method call that (1) has no return value, or (2) requires no parameters.
   Example:
 
   LogError Walk has gotten too silly, CurrentTime
 
 Here, LogError is a method call that takes two arguments, and
 CurrentTime is a method call that takes none.

That seems ambiguous to me. As a non-RealBasic programmer, I can see at 
least four meanings it could have. Translated into Python, they are:

LogError(Walk has gotten too silly, CurrentTime)
LogError(Walk has gotten too silly), CurrentTime
LogError(Walk has gotten too silly, CurrentTime())
LogError(Walk has gotten too silly), CurrentTime()


Of course this assumes that RealBasic has an equivalent of tuples, and 
treats functions as first class objects.

But even if RB doesn't have these things, I question that the syntax is 
beautiful. Consider some arbitrary method Foo. If you see this:

Foo

Is that legal RB syntax? Maybe yes, maybe no. It all depends on what Foo 
does. If it returns no result, then it's legal. If it returns a result, 
it isn't. So the question of whether syntax is legal depends, not on the 
syntactic elements involved, but on the *semantics* of the method 
(whether or not it returns a result).



 Eliminating unnecessary parentheses does a lot to improve the
 readability of the code IMHO.

But they're not unnecessary, at least not in Python, they're useful for 
distinguishing between calling the function and the function itself. 



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


Re: Start Python at client side from web app

2009-01-21 Thread Lars Behrens
Thomas Guettler wrote:

 But I don't want to update the installation too often. Here is my idea:
 
 We create a custom mime-type and register it on the client PC. The web
 application can send signed python code to the client PC. If the signature
 is correct, the code will be executed at the client. The signature
 prevents others from executing code.

My first thought was: Wouldn't it be much easier to start the script via
ssh?

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


Re: English-like Python

2009-01-21 Thread Aaron Brady
On Jan 20, 9:16 pm, MRAB goo...@mrabarnett.plus.com wrote:
 Terry Reedy wrote:
  Joe Strout wrote:
  Aaron Brady wrote:

  I think it would be a good step if you could make some sensible
  interpretation of a typical statement without its parentheses.

  f abc 123
  --
  f( abc, 123 )

  How would you differentiate

  f 'abc' + 'def'
  as
  f('abc') + 'def'
  versus
  f('abc' + 'def')

  Such a language is possible -- take a look at REALbasic sometime.  RB
  certainly has its problems (mainly bugs), but the language syntax is
  beautiful.  To your point, parentheses are not required around any
  method call that (1) has no return value, or (2) requires no
  parameters.  Example:

   LogError Walk has gotten too silly, CurrentTime

  LogError('walk', Time) # versus
  LogError('walk'), Time

  Perhaps RB does not have tuple literals.

 Parentheses wouldn't be required if it's a procedure call (I'm not sure
 about a function that's called as a procedure) or if there are no
 parameters to pass. Thus:

      f 'abc' + 'def'

 does:

      f('abc' + 'def')

Where functions are first-class objects, a bare function object isn't
distinguishable either from its call.  I'm granting that it's useful
to return values a lot.  For example:

a= f

could mean either, 'a= f' or 'a= f()'.  Once again the return values
save the day.

In the case of Terry's example, it's covered by Joe's caveat that
functions can't return values without parentheses, since '+' is a
function.  However, order of precedence could help.

Python and C of course allow string concatenation by adjacency, so
there's further ambiguity there.  It might fall under Terry's case.

You can look at English to get started, and try to see how native
speakers resolve the ambiguities.  It doesn't just happen with verbs,
either.  Firstly, Python lacks the notion of determiners (denoting
phrases) per se.  That is, there's no way to say 'the black dog'.
Here's an approximation though.

The black dog and the cat walked to the store.

walked( ( dogs( color= black ), cat ), store )

Secondly, Python is entirely imperative, something I was alluding to
in another post, which was about a relation object.  English declares
the event, while Python commands it:

( dog, cat ).walk( store )

It addresses the subjects, and gives them orders.  On a tangent, I
think the 'join' method on threads is a little counter-intuitive,
since the entity you're giving the instruction to is actually the
caller, not the object.  The verb is a little counter-intuitive,
though, since if I say 'Team, join us!', it actually just means, 'Us,
wait for the team'.  It's not like 'join' causes the target to break
early or hustle or anything.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get first/last day of the previous month?

2009-01-21 Thread M.-A. Lemburg
On 2009-01-20 15:54, Mike Driscoll wrote:
 On Jan 20, 8:19 am, Hussein B hubaghd...@gmail.com wrote:
 Hey,
 I'm creating a report that is supposed to harvest the data for the
 previous month.
 So I need a way to get the first day and the last day of the previous
 month.
 Would you please tell me how to do this?
 Thanks in advance.
 
 I recommend the dateutil module:
 
 http://labix.org/python-dateutil
 
 I think it may also be possible to use the datetime module, but it's
 easier to just use dateutil.

Or use mxDateTime on which all this was based:

http://www.egenix.com/products/python/mxBase/mxDateTime/

 from mx.DateTime import now, Date, RelativeDateTime

 def prev_month():
... t = now()
... return (
... t + RelativeDateTime(months=-1, day=1, hour=0, minute=0, second=0),
... t + RelativeDateTime(months=-1, day=-1, hour=0, minute=0, second=0))
...
 print prev_month()
(mx.DateTime.DateTime object for '2008-12-01 00:00:00.00' at 2b13fe0e7978,
mx.DateTime.DateTime object for '2008-12-31 00:00:00.00' at 2b13fe0e79d0)


-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 21 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-21 Thread Aaron Brady
On Jan 21, 2:36 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 20 Jan 2009 11:58:46 -0700, Joe Strout wrote:
  Aaron Brady wrote:

  I think it would be a good step if you could make some sensible
  interpretation of a typical statement without its parentheses.

  f abc 123
  --
  f( abc, 123 )

  It would be just the thing in a couple of situations...

  Such a language is possible -- take a look at REALbasic sometime.  RB
  certainly has its problems (mainly bugs), but the language syntax is
  beautiful.  To your point, parentheses are not required around any
  method call that (1) has no return value, or (2) requires no parameters.
    Example:

    LogError Walk has gotten too silly, CurrentTime

  Here, LogError is a method call that takes two arguments, and
  CurrentTime is a method call that takes none.

 That seems ambiguous to me. As a non-RealBasic programmer, I can see at
 least four meanings it could have. Translated into Python, they are:

 LogError(Walk has gotten too silly, CurrentTime)
 LogError(Walk has gotten too silly), CurrentTime
 LogError(Walk has gotten too silly, CurrentTime())
 LogError(Walk has gotten too silly), CurrentTime()

 Of course this assumes that RealBasic has an equivalent of tuples, and
 treats functions as first class objects.

 But even if RB doesn't have these things, I question that the syntax is
 beautiful. Consider some arbitrary method Foo. If you see this:

     Foo

 Is that legal RB syntax? Maybe yes, maybe no. It all depends on what Foo
 does. If it returns no result, then it's legal. If it returns a result,
 it isn't. So the question of whether syntax is legal depends, not on the
 syntactic elements involved, but on the *semantics* of the method
 (whether or not it returns a result).

If you could deduce the semantics of a function from the syntax
always, you could follow Erik's observation about Logo.  Then
expressions would have unique interpretations, except where a function
takes no arguments and functions are first class objects.  In other
words,

g f abc 123

would have an exact meaning, since f would just get the innermost n
arguments, that since 'n' would be a known quantity.  (Order of
precedence would handle 'g f abc + 123'.)

  Eliminating unnecessary parentheses does a lot to improve the
  readability of the code IMHO.

 But they're not unnecessary, at least not in Python, they're useful for
 distinguishing between calling the function and the function itself.

Natural language doesn't have the equivalent of parentheses, which
goes back to Steven's point about a beautiful math structure vs. a
beautiful NL sentence.  Did anyone have to diagram sentences in
grammar school?  It's not like the essentials for communication
involve deeply nested sentences; you can get by with a few simple
declarations, so you and your company will reject anything higher-
order.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Aaron Brady
On Jan 17, 11:28 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Sat, 17 Jan 2009 20:49:38 +0100, Bruno Desthuilliers wrote:
  Russ P. a écrit :
  On Jan 15, 12:21 pm, Bruno Desthuilliers
  bdesth.quelquech...@free.quelquepart.fr wrote:

  Once again, the important point is that there's a *clear* distinction
  between interface and implementation, and that you *shouldn't* mess
  with implementation.

  If you *shouldn't* mess with the implementation, then what is wrong
  with enforcing that shouldn't in the language itself?

 Russ: There are SHOULD NOTs and there are MUST NOTs.
snip
  class Parrot:

 ...     _private = 'spam'
 ... p = Parrot()
  p._private = 'ham'  # allowed by default
  from protection import lock
  lock(p)._private
  p._private = 'spam'

 Traceback (most recent call last):
   File stdin, line 1, in module
 ProtectionError: attribute is read-only from outside of class Parrot

 Would that be so bad? I don't think so.

Sorry, I didn't see the last part originally.  I don't think 'outside
of class Parrot' is well-defined in Python.  Does '_private' have to
be a member of 'Parrot', an instance of 'Parrot', or the calling
instance of 'Parrot', before entering the calling scope, or at the
time the call is made?  Since many of these can change on the fly,
there's more than one consistent interpretation to the syntax.
--
http://mail.python.org/mailman/listinfo/python-list


Locking blockl to a people on a similar group / naming locks

2009-01-21 Thread reyjexter
Hello!

Is there a way to lock a certain block to a people on similar group?
In java this is done by like this:

synchronize (myGroup) {
}

but how do I do this in python? how can I name the lock that will be
used by the thread?



-rey

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


Re: Start Python at client side from web app

2009-01-21 Thread Paul Rubin
Thomas Guettler h...@tbz-pariv.de writes:
 I want to start Python at the client side from a web
 application. The app is an intranet application, and all client PCs
 are under our control (we can install software on them).

Is it supposed to be OS independent?  If not, is it for a specific OS?
Which one?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Locking blockl to a people on a similar group / naming locks

2009-01-21 Thread Paul Rubin
reyjexter reyjex...@gmail.com writes:
 synchronize (myGroup) {
 }
 
 but how do I do this in python? how can I name the lock that will be
 used by the thread?

You have to do it explicitly, for example with RLock:

myInstance.lock = RLock()
...
myInstance.lock.acquire()
  ... critical section ...
myInstance.lock.release()

It's often possible to write in a style that avoids this mess.
The preferred way is usually to write isolated threads that
communicate by passing objects through queues (Queue.Queue).
This gets rid of a lot of locking hazards.
--
http://mail.python.org/mailman/listinfo/python-list


Re: reading file to list

2009-01-21 Thread Xah Lee
Rhodri James wrote:
 I recommend spending less time being certain that you are correct
 without seeking evidence

I don't concur.

For instance, when you are talking to a bunch of kids, you have to be
sure of yourself, else they run all over you, even if they didn't mean
to be rude.

Also, one's demeanor must commensurate one's knowledge. If i pamper
you, you might think i'm a whimp, and run on with your opinions and
thoughts unbridled, which, can be considered as a miscommunication on
my part.

  Xah
∑ http://xahlee.org/

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


Re: reading file to list

2009-01-21 Thread Lars Behrens
Rhodri James wrote:

 I *was* thinking of code produced in the real world, and I don't buy
 your assertion.  I'm not an academic, and I wouldn't hesitate to lay
 down a line of code like that.  As I said before, it fits into English
 language idioms naturally, and as a result is pretty self-descriptive.

As a non-native speaker and non-academic, I don't understand the fittine
into English language idioms naturally which is mentioned here in the
different subthreads. Could you try to explain that for me?

TIA

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


Re: reading file to list

2009-01-21 Thread Lars Behrens
Lars Behrens wrote:

 As a non-native speaker and non-academic, I don't understand the fittine
   fitting, I meant. Sorry ^^  

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


Re: smtplib.SMTP throw : 'Socket error: 10053 software caused connection abort'

2009-01-21 Thread aberry


aberry wrote:
 
 I am using 'smtplib' module to send an email but getting exception...
 
 smtplib.SMTP(nailservernam throw error :
 
 here is trace back snippet :-
 
smtp = smtplib.SMTP(self.server)
  File D:\Python24\lib\smtplib.py, line 244, in __init__
(code, msg) = self.connect(host, port)
  File D:\Python24\lib\smtplib.py, line 306, in connect
raise socket.error, msg
 socket.error: (10053, 'Software caused connection abort')
 
 thanks in adv,
 aberry
 
 

problem resolved :) ... culprit was Anti Virus  running on my Win XP
machine...
I disabled AV On Access scan... no Error and email sent

rgds,
aberry
-- 
View this message in context: 
http://www.nabble.com/smtplib.SMTP-throw-%3A-%27Socket-error%3A-10053-software-caused-connection-abort%27-tp21565011p21579963.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Locking blockl to a people on a similar group / naming locks

2009-01-21 Thread Diez B. Roggisch
Paul Rubin wrote:

 reyjexter reyjex...@gmail.com writes:
 synchronize (myGroup) {
 }
 
 but how do I do this in python? how can I name the lock that will be
 used by the thread?
 
 You have to do it explicitly, for example with RLock:
 
 myInstance.lock = RLock()
 ...
 myInstance.lock.acquire()
   ... critical section ...
 myInstance.lock.release()

In python 2.5 and upwards, you can write this safer

from __future__ import with_statement # only needed for py2.5

with myInstance.lock:
   ... critical section

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


Re: Logging help

2009-01-21 Thread Vinay Sajip
On Jan 20, 10:11 am, koranthala koranth...@gmail.com wrote:

 The doRollover method does not append to the earlier file. Rather, it
 creates a new file with the same name.

Err... that's what rollover means - switching to a new log file (and
renaming the old ones). If it just appended to the old one, why would
it be called doRollover ? ;-)

Regards,

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


Re: Start Python at client side from web app

2009-01-21 Thread 7stud
On Jan 21, 1:10 am, Thomas Guettler h...@tbz-pariv.de wrote:
 Hi,

 I want to start Python at the client side from a web application. The
 app is an intranet application, and all client PCs are under our control (we
 can install software on them).

 But I don't want to update the installation too often. Here is my idea:

 We create a custom mime-type and register it on the client PC. The web 
 application
 can send signed python code to the client PC. If the signature is correct,
 the code will be executed at the client.

How does a web application on the client execute python code?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Locking blockl to a people on a similar group / naming locks

2009-01-21 Thread Paul Rubin
Diez B. Roggisch de...@nospam.web.de writes:
 In python 2.5 and upwards, you can write this safer
 from __future__ import with_statement # only needed for py2.5
 with myInstance.lock:
... critical section

Good point!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Start Python at client side from web app

2009-01-21 Thread James Stroud

Thomas Guettler wrote:

Hi,

I want to start Python at the client side from a web application. The
app is an intranet application, and all client PCs are under our control (we
can install software on them).

But I don't want to update the installation too often. Here is my idea:

We create a custom mime-type and register it on the client PC. The web 
application
can send signed python code to the client PC. If the signature is correct,
the code will be executed at the client. The signature prevents others from 
executing
code.

Has someone seen or done something like this before?

I can code this myself, but prefer to use some open source project, if it 
exists.


Thanks in advance,
  Thomas Güttler



You are better off using a cron job (or similar) on the client side, 
getting the client to hit the web server for the code at regular 
intervals, and if code is ready, execute. If code isn't ready, wait for 
the next interval. Use https for security and have a shared secret 
message to identify legitimate clients.


If you try to push code the other way, you will need a perpetual socket 
open on the client side, making the client the server.


James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Start Python at client side from web app

2009-01-21 Thread Diez B. Roggisch
James Stroud wrote:

 Thomas Guettler wrote:
 Hi,
 
 I want to start Python at the client side from a web application. The
 app is an intranet application, and all client PCs are under our control
 (we can install software on them).
 
 But I don't want to update the installation too often. Here is my idea:
 
 We create a custom mime-type and register it on the client PC. The web
 application can send signed python code to the client PC. If the
 signature is correct, the code will be executed at the client. The
 signature prevents others from executing code.
 
 Has someone seen or done something like this before?
 
 I can code this myself, but prefer to use some open source project, if it
 exists.
 
 
 Thanks in advance,
   Thomas Güttler
 
 
 You are better off using a cron job (or similar) on the client side,
 getting the client to hit the web server for the code at regular
 intervals, and if code is ready, execute. If code isn't ready, wait for
 the next interval. Use https for security and have a shared secret
 message to identify legitimate clients.
 
 If you try to push code the other way, you will need a perpetual socket
 open on the client side, making the client the server.

If the OP finds a method to trigger the execution of his program, the
question of who's client and who not is moot. If he wants, he can make the
software query a server via HTTP (he's got that up  reachable from the PC
anyway) for it's new code. All he needs is some session-key being passed on
invocation.

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


Re: what's the point of rpython?

2009-01-21 Thread Paul Rubin
Brendan Miller catph...@catphive.net writes:
 I'm curious about that. I've been looking around for timing
 information on the lock signal, but am having some trouble finding
 them. Intuitively, given that the processor is much faster than the
 bus, and you are just waiting for processor to complete an addition or
 comparison before put the new memory value on the bus, it seems like
 there should be very little additional bus contention vs a normal add
 instruction.

The bus is slow compared with the L1 cache.  I just looked for figures
and couldn't find any either, but I remember seeing some for the Core
2 saying around 100 cycles, and something similar for the Athlon.  I
just came across something saying the Core i7 is considerably better
than the Core 2 at this.

The real solution is to not use so much bus locking.  Get rid of the
ref counts and use a real gc, if not in CPython then in PyPy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Start Python at client side from web app

2009-01-21 Thread Thomas Guettler
Sorry, I described my problem not well. Here is more information:

The main application is the intranet web application used with IE (ms windows 
client).
But some action needs to be done on the client since you can't do it with html 
or javascript.

1. The user pushes a button in the web app.
2. Webserver sends signed python code to the client with own mime type
3. IE sends code to the python application.
4. Signature gets checked, Python code on the client gets executed.
5. Maybe send some data to the server with http.

 Thomas

Server runs Linux with Django and Postgres.

Thomas Guettler schrieb:
 Hi,
 
 I want to start Python at the client side from a web application. The
 app is an intranet application, and all client PCs are under our control (we
 can install software on them).
 
 But I don't want to update the installation too often. Here is my idea:
 
 We create a custom mime-type and register it on the client PC. The web 
 application
 can send signed python code to the client PC. If the signature is correct,
 the code will be executed at the client. The signature prevents others from 
 executing
 code.
 
 Has someone seen or done something like this before?
 
 I can code this myself, but prefer to use some open source project, if it 
 exists.
 
 
 Thanks in advance,
   Thomas Güttler
 


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Re: Start Python at client side from web app

2009-01-21 Thread Diez B. Roggisch
Thomas Guettler wrote:

 Sorry, I described my problem not well. Here is more information:
 
 The main application is the intranet web application used with IE (ms
 windows client). But some action needs to be done on the client since you
 can't do it with html or javascript.
 
 1. The user pushes a button in the web app.
 2. Webserver sends signed python code to the client with own mime type
 3. IE sends code to the python application.
 4. Signature gets checked, Python code on the client gets executed.
 5. Maybe send some data to the server with http.

As I already told you on the german python NG (why do you post on *two*
lists?), I'd rather go for a custom network protocol.

This is supported by the various OSses, and browsers just hook into it.
Then, when the user presses a myprotocol://some/parameters-link (or get's
redirected there through JS), the registered application will be fired up
to handle the url.

You then simply use the passed parameters to make a call to your webserver
to fetch the new code.

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


Re: what's the point of rpython?

2009-01-21 Thread skip

Brendan Intuitively, given that the processor is much
Brendan faster than the bus, and you are just waiting for processor to
Brendan complete an addition or comparison before put the new memory
Brendan value on the bus...

I think in Python's case the reference count will often be in the
processor's local cache.  (Presumably, if the current thread is going to
Py_DECREF the object it's been working with the object's state recently.)
The stuff I read suggested that simply locking the local cache would be
significantly faster than having to lock the memory bus.

-- 
Skip Montanaro - s...@pobox.com - http://smontanaro.dyndns.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: frequency analysis without numpy

2009-01-21 Thread sturlamolden
On Jan 21, 12:13 am, sturlamolden sturlamol...@yahoo.no wrote:

 Apart from that, an FFT in pure python is going to be atrociously slow
 for anything but the shortest signals. I cannot imagine why you want
 to do this.

Just to elaborate on this:

The whole purpose of using FFT is speed. That pretty much excludes the
use of Python.

If you don't care about speed, you could just as well compute the DFT
directly. The FFT is just a O(n lon n) algorithm for computing the
DFT. Here is a DFT with O(N**2) behavior:


from math import sin, cos, pi

def real_dft(x):
   ''' DFT for a real valued sequence x '''
   r = []
   N = len(x)
   M = N//2 + 1 if N%2 else N//2
   for n in range(M):
  s = 0j
  for k in range(N):
 tmp = 2*pi*k*n/N
 s += x[k] * (cos(tmp) - 1j*sin(tmp))
  r.append(s)
   return r



S.M.






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


os.path.getmtime on windows, error: 206 - path or extension too long

2009-01-21 Thread mynthon
I have very long path on windows and i get error when try to get
modification time. So i tried do chdir path and then get file. It now
gives me error that file doesn't exists

# code
def getmtimeWIN32(p):
mycwd = os.getcwd()

if p.startswith('?\\'):
p = p.replace('?\\', '', 1)

p = os.path.splitdrive(p)
r = p[0] # root - dir name
p = p[1]
p = os.path.split(p)
f = p[1] # filename
d = p[0]
l = d.split('\\');

if r != '': # if root is not empty change to root (it not works
when script is on other partition than file)
os.chdir('/')

for i in l:
if i != '':
os.chdir(i)
#print i
print os.getcwd()
os.path.getmtime(f)
os.chdir(mycwd)
# /code

it works for other files so i suppose it is not my fault. I know there
is a win32 module but i can't find any documentation for it (what is
the purpose to create app without docs?). Any idea?

I searched google but there where only 2 options. Use chdir (not
working) or use win32api (where is no documentation).

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Bruno Desthuilliers

Russ P. a écrit :
(snip)

In any case, I have suggested that Python should perhaps get a new
keyword, private or priv.


And quite a few people - most of them using Python daily - answered they 
didn't wan't it.

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Bruno Desthuilliers

Russ P. a écrit :
(snip)

Since when is no one is allowed to suggest a potential improvement to
a product unless they are willing to implement it themselves? Imagine
what the world would be like if such a rule applied to all products.


There are two points here. The first one is whether what you suggest is 
seen as a potential improvement, by the language's designers and by 
the majority of the language's users. The answer here is obviously no. 
The second point is about your vision of Python as a product. It is 
not - at least, not in the sense of a commercial product. It's a FOSS 
project, and this effectively means that if you really want to get 
something done, specially when almost no one seems interested, you *do* 
have to DoItYourself(tm). But I *really* doubt it'll make it Python anyway.


IOW : if you want access restrictions in Python, fork the project and do 
what you want with your fork (as long as you respect the Python licence 
of course).




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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Bruno Desthuilliers

Russ P. a écrit :
(snip)

Your mistake for being a moron. But it seems to happen regularly,
doesn't it. How much more of my time are you going to waste, loser?


Calling people names is certainly not the best way to defend your 
opinions here. Adios, Mr. P.

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Tim Rowe
2009/1/21 Paul Rubin http://phr.cx@nospam.invalid:

 I have no direct experience with it but have read a little about it.
 It looks to be a fairly vanilla block structured imperative language
 like Pascal with some concurrency stuff added.  The sense I have is
 that it's not especially harder to program in than C or C++, but the
 programs come out much more reliable.

It is rather more than that, in that it's particularly strict (and it
has a particularly powerful arithmetic model), but its roots are
certainly there. At a conference on the safe subset, SPARK Ada, one of
the SPARK developers pointed out that the SPARK Ada subset was
effectively Modula2.

Programs done in Ada are, by objective measures, more reliable than
those done in C and C++ (the very best released C++ programs are about
as good as the worst released Ada programs), although I've always
wondered how much of that is because of language differences and how
much is because Ada tends to be used on critical projects that also
tend to get a lot more attention to development standards.

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Bruno Desthuilliers

Paul Rubin a écrit :

Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid writes:

Zope is about 375 KLOC[1],

How many LOCS would it require if it was written in ADA ?


No idea.  Ada is a lot more verbose than Python, but I'm baffled at
what the heck Zope is actually doing with all that code.


Zope also has 275 open bugs, 6 of which are critical.

None of which are going to *kill* anyone FWIW. Now how many of these
bugs would have language-enforced access restriction prevented ?


I'm not about to audit 375 KLOC of code to find out.  Regardless of
whether access restriction actually prevents bugs though, it certainly
makes auditing easier.


pylint is your friend.


 And auditing does find bugs.


[2] The Space Shuttle avionics (written in the 1980's!) are 2 MLOC

of a hi-level dynamic language ? Hm, I guess not.


I think written in some forerunner of Ada.


Yeps, probably something like this. Not specially hi level nor dynamic, 
is it ?



Given the difference in LOCS count between a low-level static language
and a hi-level dynamic language for the implementation of a same given
features set, you cannot just define large by the # of LOCS. Not
that I'm going to compare Zope with Space shuttle's stuff.


I don't think static vs dynamic makes much difference in the amount of
LOCS to accomplish some function.


My own experience is that it does make a huge difference - talking about 
imperative languages, of course.



 In my limited experience with
Haskell (statically typed but very high level),


dynamic and static were not meant to concern typing here (or at 
least not only typing).


Haskell and MLs are indeed statically typed, but with a powerfull type 
inference system, which gives great support for genericity ot(hmmm... 
is that the appropriate word ?)/ot


Now these are functional languages, so the notion of access 
restriction is just moot in this context !-)



it takes around the
same amount of Haskell code as Python code (sometimes more, sometimes
less) to do a given task.


Not exactly my own experience, but I confess I'm much more fluent with 
Python than with Haskell !-)



 More important for concise code is features
like higher-level functions and types (e.g. it's easy in Python or
Haskell, but a huge pain in Java or C, to write down a value that is a
list of dictionaries whose keys are tuples and whose values are more
lists of dictionaries, to code something list a listcomp, etc).


Yes, indeed. So you agree that Haskell is not exactly a low level 
language, do you ?-)


Ok, I should probably have made clear I was thinking of a hi-level 
dynamic _imperative_ language vs a low-level static _imperative_ 
language. FP is quite another world.

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Mark Wooding
Russ P. russ.paie...@gmail.com writes:

 Which is why I was hoping that Python might get enforced data hiding
 as well as optional static type declarations that can actually be used
 for static verification. But maybe that's all just a pipe dream on my
 part -- or onanism.

I think that, if you want static assurances, Python -- or any dynamic
language, for that matter -- just isn't for you.  Please feel free to
use Java, C#, C++, or more interesting languages like ML variants or
Haskell -- or even Ada dialects, which (I should have mentioned) do seem
to have some very impressive proof-maintenance tools available for them.

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Mark Wooding
Russ P. russ.paie...@gmail.com writes:

 I'm not sure what you mean by conflating module and class systems.
 Are you referring to the fact that Java requires each class to be in
 its own file of the same name (I don't use Java, but that's what I've
 heard)? If so, I agree that is a bad idea.

No.  I mean that using classes as a unit of access control is wrong.  A
class is a unit of behaviour, but that behaviour can (and often should)
come from a number of places.

Common Lisp gets this right.  Classes define slots for their instances;
slots are named by symbols.  If you can write the symbol, you can access
the slot.  But symbols are managed by packages: packages can export some
symbols and keep others internal; and they can import symbols from other
packages.  The same mechanism works for functions, variables, classes,
types, macros, and all the other random namespaces that Lisp (like most
languages) has.

Python keeps access control separate from classes.  And I think I'd like
it to stay that way.

(Lisp's package system also solves the problem that a class's -- and its
superclasses' -- attributes and methods form a namespace which isn't
well-managed in many languages.  Since CL uses symbols for these, and
symbols belong to packages, MDW::MUMBLE isn't the same symbol as
RUSS-P::MUMBLE and so they name different slots.)

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getmtime on windows, error: 206 - path or extension too long

2009-01-21 Thread mynthon
On Jan 21, 11:50 am, mynthon mynth...@gmail.com wrote:
 I have very long path on windows and i get error when try to get
 modification time. So i tried do chdir path and then get file. It now
 gives me error that file doesn't exists

 # code
 def getmtimeWIN32(p):
     mycwd = os.getcwd()

     if p.startswith('?\\'):
         p = p.replace('?\\', '', 1)

     p = os.path.splitdrive(p)
     r = p[0] # root - dir name
     p = p[1]
     p = os.path.split(p)
     f = p[1] # filename
     d = p[0]
     l = d.split('\\');

     if r != '': # if root is not empty change to root (it not works
 when script is on other partition than file)
         os.chdir('/')

     for i in l:
         if i != '':
             os.chdir(i)
             #print i
     print os.getcwd()
     os.path.getmtime(f)
     os.chdir(mycwd)
 # /code

 it works for other files so i suppose it is not my fault. I know there
 is a win32 module but i can't find any documentation for it (what is
 the purpose to create app without docs?). Any idea?

 I searched google but there where only 2 options. Use chdir (not
 working) or use win32api (where is no documentation).

 (python 2.5)


ok, what ive found:

os.chdir('very_long_path')
# works

os.listdir('very_long_path')
# gives:
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: listdir() argument 1 must be (buffer overflow), not str

os.chdir('very_long_path')
os.listdir('.')
#works

os.chdir('very_long_path')
os.path.getmtime(os.listdir('.')[0])
#throws exception (path not exists)

os.chdir('very_long_path')
open(os.listdir('.')[0])
#throws exception (path not exists)






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


Re: How to print lambda result ?

2009-01-21 Thread Steve Holden
Because your print statement defines the lambda without calling it.

regards
 Steve

Barak, Ron wrote:
 Thanks Tino: your solutions without the lambda work nicely.
 What I still don't understand is why the print does not execute the lambda 
 and prints the result, instead of printing the lambda's object description.
 Bye,
 Ron.
 
 
 -Original Message-
 From: Tino Wildenhain [mailto:t...@wildenhain.de]
 Sent: Tuesday, January 20, 2009 14:22
 To: Barak, Ron
 Cc: python-list@python.org
 Subject: Re: How to print lambda result ?
 
 Hi,
 
 Barak, Ron wrote:
 Hi,

 Wanting to print the correct plural after numbers, I did the following:

 for num in range(1,4):
 string_ = %d event%s % (num,lambda num: num  1 and s or )
 print string_

 However, instead of getting the expected output:

 1 event
 2 events
 3 events

 I get:

 1 eventfunction lambda at 0x00AFE670
 2 eventfunction lambda at 0x00AFE670
 3 eventfunction lambda at 0x00AFE6B0
 
 lambda creates a function so this is the result you are seeing. You would 
 need to call the function to get your result.
 
 (num,(lambda n: n 1 and s or )(num))
 
 which is just a quite useless application of lambda :-)
 
 (num,num 1 and s or )
 
 or even
 
 (num,s if num 1 else )
 
 in python  2.5
 
 or in python 3.0:
 
 (num,s*(num 1))
 
 :-)
 
 HTH
 Tino
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Problem with 3.0 Install on Windows

2009-01-21 Thread Steve Holden
Saul Spatz wrote:
 I'm running python 2.5.x on Windows XP, and I installed 3.0, just to get
 familiar with it.  I have a directory with all my python projects in my
 PYTHONPATH variable.  When I try to run python 3.0, it detects a syntax
 error (a print statement) in the first file in this directory, and
 crashes.  I don't want to convert the files to 3.0 syntax, because I
 plan to keep using 2.5, at least for a while.
 
What's the name of that file? Does it clash with some system module that
the interpreter is trying to load? In circumstances like this a
traceback printout is always more helpful than a verbal description of
the behavior.

 I don't know exactly why this translation is happening.  Is there a way
 to turn it off?
 
Translation?

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: How to write a simple shell loop in python?

2009-01-21 Thread Steve Holden
Dietrich Bollmann wrote:
 Hi,
 
 I am trying to write a simple shell loop in Python.
 
 My simple approach works fine - but the first output line after entering
 something is always indented by one blank.  
 
 Is there any logic explanation for this?  
 How can I get rid of the blank?
 Is there a smarter way to write a simple shell loop which would work
 better?
 
 Thanks, Dietrich
 
 
 Here my approach:
 
 $ python
 Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26) 
 [GCC 4.3.2] on linux2
 Type help, copyright, credits or license for more information.
 import sys
 while (1):
 ... print $ ,
 ... input = sys.stdin.readline()
Just replace the lines above with

input = raw_input($ )

and you'll be fine. The , in the print statement causes the
interpreter to set a flag to emit a space before the next output unless
it has just printed a newline. The newline, of course, is provided by
the input, so the next print emits a space since it *hasn't* just
emitted a newline.

regards
 Steve

 ... input = input.strip()
 ... print input
 ... print input
 ... print input
 ... 
 $ one
  one
 one
 one
 $ two
  two
 two
 two
 $ three
  three
 three
 three
 $ 
 Traceback (most recent call last):
   File stdin, line 3, in module
 KeyboardInterrupt
 
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: reading file to list

2009-01-21 Thread Steve Holden
Xah Lee wrote:
 On Jan 19, 11:17 pm, alex23 wuwe...@gmail.com wrote:
 ...
[...]
 sure. In a political context, many criticism or description of the
 situation from one party can be seen as ad hominem attack. I feel that
 that many old emacs users, which includes significant portion of emacs
 developers (if not majority), are so exteremly bottled up and turn
 down any possibility of advancing. They are killing emacs. (similar
 feelings for most regular posters here in comp.lang.lisp )
 
This might have been relevant if you had not been too stupid to observe
that you are (sigh, yet again) posting irrelevant drivel to
comp.lang.python. Please stop.

[...]
 Your input will be highly valued. Though, forgive me to say, that i
 think my opinion on this is beyond any computer scientist of any
 standing can try to tell me otherwise. If they disagree (which i think
 most of them won't), i think their knowledge and experience in the
 area of computer languages and syntax and notations, IQ, are inferior
 to me.
 
How very comforting for you. Closed mind hardly begins to describe
that attitude.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: os.path.getmtime on windows, error: 206 - path or extension too long

2009-01-21 Thread mynthon
On Jan 21, 2:13 pm, mynthon mynth...@gmail.com wrote:
 On Jan 21, 11:50 am, mynthon mynth...@gmail.com wrote:



  I have very long path on windows and i get error when try to get
  modification time. So i tried do chdir path and then get file. It now
  gives me error that file doesn't exists

  # code
  def getmtimeWIN32(p):
      mycwd = os.getcwd()

      if p.startswith('?\\'):
          p = p.replace('?\\', '', 1)

      p = os.path.splitdrive(p)
      r = p[0] # root - dir name
      p = p[1]
      p = os.path.split(p)
      f = p[1] # filename
      d = p[0]
      l = d.split('\\');

      if r != '': # if root is not empty change to root (it not works
  when script is on other partition than file)
          os.chdir('/')

      for i in l:
          if i != '':
              os.chdir(i)
              #print i
      print os.getcwd()
      os.path.getmtime(f)
      os.chdir(mycwd)
  # /code

  it works for other files so i suppose it is not my fault. I know there
  is a win32 module but i can't find any documentation for it (what is
  the purpose to create app without docs?). Any idea?

  I searched google but there where only 2 options. Use chdir (not
  working) or use win32api (where is no documentation).

  (python 2.5)

 ok, what ive found:

 os.chdir('very_long_path')
 # works

 os.listdir('very_long_path')
 # gives:
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: listdir() argument 1 must be (buffer overflow), not str

 os.chdir('very_long_path')
 os.listdir('.')
 #works

 os.chdir('very_long_path')
 os.path.getmtime(os.listdir('.')[0])
 #throws exception (path not exists)

 os.chdir('very_long_path')
 open(os.listdir('.')[0])
 #throws exception (path not exists)

i dont have a solution but workaround.
I can map long path as drive:

longPath = c:\\documents and settings\\usermth\\my documents\
\..blablablabla

# map path as drive b: (notice  around path to avoid problems with
spaces)
os.system('subst b: %s' % longPath)

longPath = 'b:\\'
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getmtime on windows, error: 206 - path or extension too long

2009-01-21 Thread mynthon
On Jan 21, 2:58 pm, mynthon mynth...@gmail.com wrote:
 On Jan 21, 2:13 pm, mynthon mynth...@gmail.com wrote:



  On Jan 21, 11:50 am, mynthon mynth...@gmail.com wrote:

   I have very long path on windows and i get error when try to get
   modification time. So i tried do chdir path and then get file. It now
   gives me error that file doesn't exists

   # code
   def getmtimeWIN32(p):
       mycwd = os.getcwd()

       if p.startswith('?\\'):
           p = p.replace('?\\', '', 1)

       p = os.path.splitdrive(p)
       r = p[0] # root - dir name
       p = p[1]
       p = os.path.split(p)
       f = p[1] # filename
       d = p[0]
       l = d.split('\\');

       if r != '': # if root is not empty change to root (it not works
   when script is on other partition than file)
           os.chdir('/')

       for i in l:
           if i != '':
               os.chdir(i)
               #print i
       print os.getcwd()
       os.path.getmtime(f)
       os.chdir(mycwd)
   # /code

   it works for other files so i suppose it is not my fault. I know there
   is a win32 module but i can't find any documentation for it (what is
   the purpose to create app without docs?). Any idea?

   I searched google but there where only 2 options. Use chdir (not
   working) or use win32api (where is no documentation).

   (python 2.5)

  ok, what ive found:

  os.chdir('very_long_path')
  # works

  os.listdir('very_long_path')
  # gives:
  Traceback (most recent call last):
    File stdin, line 1, in module
  TypeError: listdir() argument 1 must be (buffer overflow), not str

  os.chdir('very_long_path')
  os.listdir('.')
  #works

  os.chdir('very_long_path')
  os.path.getmtime(os.listdir('.')[0])
  #throws exception (path not exists)

  os.chdir('very_long_path')
  open(os.listdir('.')[0])
  #throws exception (path not exists)

 i dont have a solution but workaround.
 I can map long path as drive:

 longPath = c:\\documents and settings\\usermth\\my documents\
 \..blablablabla

 # map path as drive b: (notice  around path to avoid problems with
 spaces)
 os.system('subst b: %s' % longPath)

 longPath = 'b:\\'

you can also use \\?\ prefix but ONLY FOR unicode strings


os.path.getmtime(?\\c:\\very lon path\\blablabla) #will not work
os.path.getmtime(u?\\c:\\very lon path\\blablabla) #will work
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Duncan Booth
Terry Reedy tjre...@udel.edu wrote:

 Delaney, Timothy (Tim) wrote:
 Terry Reedy wrote:
 
 The compiled code differs.
 I *strongly* doubt that.  Properties are designed to be transparent 
to
 user code that access atrributes through the usual dotted name
 notation precisely so that class code can be changed from
x = ob
 to
x = property(get_x, set_x, del_x)
 without changing user code.
 
 He was talking about C# with that statement. In C#, the compiled code
 differs depending on whether you use a property or an attribute. Or 
at
 least that's how I interpreted it.
 
 Checking back, I see now that Luis Z. went from Python
 It boggles me when I see python code with properties that only set 
and
 get the attribute, or even worse, getters and setters for that
 purpose.  to C#, and that Duncan was seemingly responding to the C# 
 part.  If C# is like that, how inconvenient.

It's a long enough thread that I can't see anyone faulting you for 
falling asleep half way through my post.

C# forces you to spend a lot of time writing trivial getters and 
setters. They've 'improved' it in the more recent versions: you no 
longer have to write any body at all for a trivial getter or setter and 
the compiler will generate one for you provided you have declared the 
property with a leading capital letter and a private attribute with the 
same name but a lowercase letter. Ick.

 
 You are of course correct as to how Python does it.
 
 I guess I am spoiled ;-).
 
That's why we're all here.



-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-21 Thread Joe Strout

Steven D'Aprano wrote:


  LogError Walk has gotten too silly, CurrentTime

Here, LogError is a method call that takes two arguments, and
CurrentTime is a method call that takes none.


That seems ambiguous to me. As a non-RealBasic programmer, I can see at 
least four meanings it could have. Translated into Python, they are:


LogError(Walk has gotten too silly, CurrentTime)
LogError(Walk has gotten too silly), CurrentTime
LogError(Walk has gotten too silly, CurrentTime())
LogError(Walk has gotten too silly), CurrentTime()


It's not ambiguous because RB doesn't have a tuple syntax that looks the 
same as arguments to a function call.  You also can't get a reference to 
a method simply by naming it; naming it invokes it (when you want a 
reference to it instead, you use the AddressOf keyword).  So, the 
first and third of your lines above mean the same thing, and are the 
correct (and only possible) interpretation.  The second and fourth are 
also equivalent, but would require the parentheses around the LogError 
parameter since in that case it is a function (i.e. returns a result).


As I said before, I'm not sure how you would apply this to Python, where 
other syntax choices (tuples, function references, etc.) get in the way 
of this idea.  I'm merely pointing out that what Aaron asked for is 
possible without ambiguity, and actually used in at least one real-world 
language.


But even if RB doesn't have these things, I question that the syntax is 
beautiful. Consider some arbitrary method Foo. If you see this:


Foo

Is that legal RB syntax?


You betcha!  For example, the built-in method to play the standard 
system alert sound is:


Beep

Doesn't get much more readable and syntax-free than that.  Suppose now 
that a beep isn't eloquent enough, and you want the computer to speak 
something out loud instead.  Also easy:


Speak Spam, spam, spam, baked beans and spam.

If you're writing a console app, then there's a built in Print 
subroutine that puts a string to stdout.  Its usage is:


Print Spam, spam, spam, baked beans and spam.

Note that this syntax is exactly like Python's print syntax prior to 
3.0, but in RB, it's not a special case -- it's just another method 
call, and you can define your own methods that you invoke exactly the 
same way.


Maybe yes, maybe no. It all depends on what Foo 
does. If it returns no result, then it's legal. If it returns a result, 
it isn't.


Right.  In other words, you can tell just by looking at the call that it 
doesn't return a result.  This is often handy.


So the question of whether syntax is legal depends, not on the 
syntactic elements involved, but on the *semantics* of the method 
(whether or not it returns a result).


But of course.  Any method call is legal only if the form of the call 
matches the method prototype -- if you try to call a function that 
requires 4 parameters, and give it only 3, that's an error too.  I don't 
see how this is different in any important way.



Eliminating unnecessary parentheses does a lot to improve the
readability of the code IMHO.


But they're not unnecessary, at least not in Python, they're useful for 
distinguishing between calling the function and the function itself. 


Yes, quite true in Python.  If there were some other way to distinguish 
between those -- and if tuple syntax didn't look the same as method call 
arguments -- THEN they would be unnecessary.  But those would be very 
substantial changes to Python syntax, and I'm not seriously proposing them.


Best,
- Joe

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


Re: Python 3.0 urllib.parse.parse_qs results in TypeError

2009-01-21 Thread Aahz
In article 313a27f9-c655-4fc4-a8e3-568a4283b...@f40g2000pri.googlegroups.com,
ag73  andygrov...@gmail.com wrote:

   form = urllib.parse.parse_qs(qs, keep_blank_values=1)

However, the last line of code that calls parse_qs causes the
following exception to be thrown:

class 'TypeError'
Type str doesn't support the buffer API

One of the key features of Python 3.0 is the fact that it now
distinguishes between bytes and strings.  Unfortunately, there are a lot
of ambiguous areas where the correct handling is not clear; for example,
nobody has yet agreed whether URLs are strings or bytes.  As you
discovered, forced conversion to string seems to work here and I suggest
you make that your workaround.  You could also file a bug on
bugs.python.org (first checking to see whether someone else has already
done so).
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'Import sys' succeeds in C++ embedded code, but module is not fully visible

2009-01-21 Thread Aahz
In article b11e6e8a-98a6-43d1-b311-652fedbe7...@h5g2000yqh.googlegroups.com,
Ben Sizer  kylo...@gmail.com wrote:

I have the following C++ code and am attempting to embed Python 2.5,
but although the import sys statement works, attempting to reference
sys.path from inside a function after that point fails. It's as if
it's not treating it as a normal module but as any other global
variable which I'd have to explicitly qualify.

After skimming the thread and seeing a lack of answer, I suggest you try
capi-...@python.org
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread MRAB

Russ P. wrote:

On Jan 20, 10:02 pm, alex23 wuwe...@gmail.com wrote:


Can I comprehend that you don't even have an immediate need and are
instead actively engaging in online onanism? Absolutely.


So anyone thinking beyond an immediate need is engaging in online
onanism?


That doesn't mean what you think it means.


Let's see. How long ago did the Python community start thinking about
Python 3?

So I guess they're all a bunch of jerkoffs, eh?



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


Re: English-like Python

2009-01-21 Thread Joe Strout

Aaron Brady wrote:


Where functions are first-class objects, a bare function object isn't
distinguishable either from its call.


That depends not on whether functions are first-class objects, but on 
the *syntax* of function invocation vs. function reference.  It just so 
happens than in Python, the syntax for the latter is the bare function 
identifier.  But it wouldn't have to be -- you could use @foo or 
{foo} or ref foo or (as in RB) AddressOf foo or any number of 
other alternatives to accomplish the same thing, and functions would 
still be first-class objects.


I'll grant that having any such syntax makes them *odd* first-class 
objects, since all other objects are referred to with a naked 
identifier, and invoked (if they are callable) with some other syntax. 
It'd be weird and inconsistent to have functions turn that around.  But, 
despite being inconsistent, it might still be sensible, based on the 
observation that we generally need to invoke methods a lot more often 
than we need to get a reference to them.


 I'm granting that it's useful

to return values a lot.  For example:

a= f

could mean either, 'a= f' or 'a= f()'.  Once again the return values
save the day.


I think I agree (if I follow you correctly).  But then some other syntax 
would be needed for when you really mean a=f (i.e., make 'a' refer to 
the same function as 'f').


Best,
- Joe

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


is this pythonic?

2009-01-21 Thread TP
Hi,

Is the following code pythonic:

 l=[{title:to, value:2},{title:ti,value:coucou}]
 dict = [ dict for dict in l if dict['title']=='ti']
 l.remove(*dict)
 l
[{'title': 'to', 'value': 2}]

Precision: I have stored data in the list of dictionaries l, because in my
application I am sure that title is unique for each record. But perhaps
it is better to imagine that someday it will not be anymore the case? And
rather use a data storage as the following?

l = { '001':{title:to, value:2}, '002'
{title:ti,value:coucou}}

The problem with this storage is that it implies to manipulate some ids
that have not any meaning for a humain being (001, 002, etc).

Thanks a lot for you opinion,

-- 
python -c print ''.join([chr(154 - ord(c)) for c in '*9(9(18%.\
91+,\'Z4(55l4('])

When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong. (first law of AC Clarke)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules

2009-01-21 Thread Mudcat
This is something I've wondered about for a while. I know that
theoretically Python is supposed to auto-recognize duplicate imports;
however I've run into problems in the past if I didn't arrange the
imports in a certain way across multiple files. As a result, I worry
about conflicts that arise because something has been imported twice.
So...I'm not sure if Python *always* gets this correct.

Also, I understand what you're saying about the organization of files
based on modules and maybe regrouping based on use. However I like the
organization of my files to be a grouping of logical components in my
application. This makes it easy to keep things separated and keeps
files from getting to long (which takes longer to program because
you're always bouncing up and down large files). As a result, if I
have to worry about grouping by shared modules then it makes that more
difficult.

I think it would great to have access to a file (like the __init__.py
file for packages) which all the files in the same directory would
have access to for common imports. That way you could push out the
repeated imports and also clean up the look a little bit as well.


On Jan 7, 11:53 am, Paul McGuire pt...@austin.rr.com wrote:
 ...and don't worry about a possible performance issue of importing os
 (or any other module) multiple times - the Pythonimportmanager is
 smart enough to recognize previously importedmodules, and wontimport
 them again.

 If a module uses the os module, then it shouldimportit - that's just
 it.

 Another consideration might be that you are breaking up your own
 programmodulestoo much.  For instance, if I had a program in which I
 were importing urllib in lots ofmodules, it might indicate that I
 still have some regrouping to do, and that I could probably gather all
 of my urllib dependent code into a single place.

 -- Paul

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


quick beginners List comprehension question

2009-01-21 Thread Dr Mephesto
Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.

Say I have a class Foo with a property called bar:

class Foo:
def __init__(self):
self.bar = random.randint(1,100)

and then I make a list of these objects:

Newlist = []
for x in range(10):
Newlist.append(Foo())

Now, suppose I wanted to triple the value of 'bar', I could always do:

for x in range(10):
Newlist[x].bar = Newlist[x].bar * 3

but can I do this using list comprehension?  Thanks in Advance!



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


Re: quick beginners List comprehension question

2009-01-21 Thread Diez B. Roggisch
Dr Mephesto wrote:

 Hi,
 Im new to python, and OOP, and am trying to get a handle on list
 comprehension.
 
 Say I have a class Foo with a property called bar:
 
 class Foo:
 def __init__(self):
 self.bar = random.randint(1,100)
 
 and then I make a list of these objects:
 
 Newlist = []
 for x in range(10):
 Newlist.append(Foo())
 
 Now, suppose I wanted to triple the value of 'bar', I could always do:
 
 for x in range(10):
 Newlist[x].bar = Newlist[x].bar * 3
 
 but can I do this using list comprehension?  Thanks in Advance!

No, as such, because list-comprehensions require you to have an *expression*
in front of the iteration:

resultlist = [expr for variable(s) in iterable]

Now what you of course can do is this:

def multiply(item):
item.bar = item.bar * 3

[multiply(i) for i in items]

However, doing this will make python produce a list of None-references -
which is a waste. It's up to you if you care about that, but generally it
is frowned upon because of that, and the fact that the conciseness of the
list-comp here isn't really helping with the readability.

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


Re: quick beginners List comprehension question

2009-01-21 Thread MRAB

Dr Mephesto wrote:

Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.

Say I have a class Foo with a property called bar:

class Foo:
def __init__(self):
self.bar = random.randint(1,100)

and then I make a list of these objects:

Newlist = []
for x in range(10):
Newlist.append(Foo())

Now, suppose I wanted to triple the value of 'bar', I could always do:

for x in range(10):
Newlist[x].bar = Newlist[x].bar * 3

but can I do this using list comprehension?  Thanks in Advance!


You could reduce that to:

for x in Newlist:
x.bar *= 3

but I don't think you could do it with list comprehension.
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick beginners List comprehension question

2009-01-21 Thread Philip Semanchuk


On Jan 21, 2009, at 10:52 AM, Dr Mephesto wrote:


Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.

Say I have a class Foo with a property called bar:

class Foo:
   def __init__(self):
   self.bar = random.randint(1,100)

and then I make a list of these objects:

Newlist = []
for x in range(10):
   Newlist.append(Foo())

Now, suppose I wanted to triple the value of 'bar', I could always do:

for x in range(10):
Newlist[x].bar = Newlist[x].bar * 3

but can I do this using list comprehension?  Thanks in Advance!


Other answers have been good; to them I'll add the comment that list  
comprehensions are for *constructing* lists, not manipulating the  
elements thereof.


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


Re: what's the point of rpython?

2009-01-21 Thread Scott David Daniels

Brendan Miller wrote:

On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin
http://phr.cx@nospam.invalid wrote:

  Of course I'm aware of the LOCK prefix but it slows
down the instruction enormously compared with a non-locked instruction.


I'm curious about that. I've been looking around for timing
information on the lock signal, but am having some trouble finding
them. Intuitively, given that the processor is much faster than the
bus, and you are just waiting for processor to complete an addition or
comparison before put the new memory value on the bus, it seems like
there should be very little additional bus contention vs a normal add
instruction.

The opcode cannot simply talk to its cache, it must either go directly
to off-chip memory or communicate to other processors that it (and it
alone) owns the increment target.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules

2009-01-21 Thread Marco Mariani

Mudcat wrote:


This is something I've wondered about for a while. I know that
theoretically Python is supposed to auto-recognize duplicate imports;
however I've run into problems in the past if I didn't arrange the
imports in a certain way across multiple files.


I think you've probably had issues with circular imports (i.e. mutual 
dependencies), unless you can precisely remember what you were doing and 
what went wrong.



As a result, I worry about conflicts that arise because something has been 
imported twice.
So...I'm not sure if Python *always* gets this correct.


It doesn't import twice, and never did.


Also, I understand what you're saying about the organization of files
based on modules and maybe regrouping based on use. However I like the
organization of my files to be a grouping of logical components in my
application.


I can make up three or four different logical groupings in my 
applications... so what is 'logical' could not be the same for everyone, 
or from every point of view.


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


Re: is this pythonic?

2009-01-21 Thread Peter Pearson
On Wed, 21 Jan 2009 16:16:32 +0100, TP wrote:

 Is the following code pythonic:

 l=[{title:to, value:2},{title:ti,value:coucou}]
 dict = [ dict for dict in l if dict['title']=='ti']
 l.remove(*dict)
 l
 [{'title': 'to', 'value': 2}]

 Precision: I have stored data in the list of dictionaries l, because in my
 application I am sure that title is unique for each record. But perhaps
 it is better to imagine that someday it will not be anymore the case?
[snip]

1. You probably don't want to use the name dict.

2. I believe this code will fail if the number of dictionaries
   with title=ti is not exactly 1.  It that your intention?
   (You probably answered this question in the last paragraph
   quoted above, but I can't make it out.)

-- 
To email me, substitute nowhere-spamcop, invalid-net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick beginners List comprehension question

2009-01-21 Thread MRAB

Diez B. Roggisch wrote:

Dr Mephesto wrote:


Hi,
Im new to python, and OOP, and am trying to get a handle on list
comprehension.

Say I have a class Foo with a property called bar:

class Foo:
def __init__(self):
self.bar = random.randint(1,100)

and then I make a list of these objects:

Newlist = []
for x in range(10):
Newlist.append(Foo())

Now, suppose I wanted to triple the value of 'bar', I could always do:

for x in range(10):
Newlist[x].bar = Newlist[x].bar * 3

but can I do this using list comprehension?  Thanks in Advance!


No, as such, because list-comprehensions require you to have an *expression*
in front of the iteration:

resultlist = [expr for variable(s) in iterable]

Now what you of course can do is this:

def multiply(item):
item.bar = item.bar * 3

[multiply(i) for i in items]

However, doing this will make python produce a list of None-references -
which is a waste. It's up to you if you care about that, but generally it
is frowned upon because of that, and the fact that the conciseness of the
list-comp here isn't really helping with the readability.


If you had:

def multiply(item):
item.bar = item.bar * 3
return item

then:

[multiply(i) for i in items]

would return items. Still a bad idea, though, because you're using a 
list comprehension for its side-effect.

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


Re: How to write a simple shell loop in python?

2009-01-21 Thread Scott David Daniels

Dietrich Bollmann wrote:

I am trying to write a simple shell loop in Python.

My simple approach works fine - but the first output line after entering
something is always indented by one blank.  
Is there any logic explanation for this?  

Yes

How can I get rid of the blank?

By not asking for it with the comma.



while (1):

... print $ ,
... input = sys.stdin.readline()
... input = input.strip()
... print input
... print input
... print input
... 
$ one

The one and \n above are from stdin, not stdout.  So stdout thinks
it is still on the same line as the $.

 one

The space separates the 'one' from the '$ ' that it output to stdout
above.

one
one


--Scott David Daniels
scott.dani...@acm.org


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


Beating a Timeout

2009-01-21 Thread K-Dawg
Hi,

I am trying to write a python script that I can run to prevent a timeout of
webpage.  I have to use a system at work that keeps track of issues.  I use
this a couple of time an hour and it times out after 10 minutes.  The system
is really crummy and it rejects your username and password about 30-40 times
before it takes it.  It is supposed to integrate with Active Directory and I
don't think it does it very well.

So I have this open in Internet Explorer (its all in asp.net so it does not
work in any other browser).  I was hoping to have something simple like:

#c:\Python25\python

import urllib
import urllib2
import time

while True:
 result = urllib.urlopen(the_URLhttp://sdeprod.brunswick.com/SDE/blank.aspx
)
 print Retrieved Page
 time.sleep(300)
But this is not working  The code on the page uses a hidden iFrame that
has a javascript file that monitors the time and intiates the timeout.  The
src of the hidden iFrame is what I keep trying to grab.

It is still timing out in IE.  Once it times out in IE I get an error in my
script saying:

IOError:  [Errno socket error] (10060, 'Operation timed out')

The system is terrible but I am stuck with it.  If it doesn't kick me out,
at least its bearable...

Thanks for any help you can provide.

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


Re: quick beginners List comprehension question

2009-01-21 Thread Lou Pecora
In article mailman.7691.1232554737.3487.python-l...@python.org,
 Philip Semanchuk phi...@semanchuk.com wrote:

 
 Other answers have been good; to them I'll add the comment that list  
 comprehensions are for *constructing* lists, not manipulating the  
 elements thereof.
 
 HTH
 Philip


Well this seems to work just fine.  What am I missing:

   A=[1,2,3]
   print A
   A=[2*a for a in A]
   print A

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


Re: frequency analysis without numpy

2009-01-21 Thread philbru
On Jan 20, 3:13 pm, sturlamolden sturlamol...@yahoo.no wrote:
 Consider using Thompson's multitaper method, autoregression (maximum
 entropy), or Welch method for your frequency estimates. Blackman-
 Tuckey is also a possibility, but I see no reason to prefer that to
 Welch. Multitaper and AR tends to be the better options though, but
 they are not as fast as Welch' method.
There is a fortran program named rainbow that has some dozen of these
methods to compare with. Rainbow is located at
http://www.digitalCalculus.com/demo/rainbow.html. I recommend Burg's
method or AutoCorrelation but its data dependent for best choice.

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


Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 1:16 am, TP tribulati...@paralleles.invalid wrote:
 Is the following code pythonic:
  l=[{title:to, value:2},{title:ti,value:coucou}]
  dict = [ dict for dict in l if dict['title']=='ti']
  l.remove(*dict)
  l
 [{'title': 'to', 'value': 2}]

Try not to use 'dict' or the name of any of the other built-in types
as labels.

You're stepping through an entire list just to pass another list to
l.remove to step through and remove items from...in fact, given that
list.remove deletes the -first- occurance of the item, you're asking
it to loop through -again- to find the matching element which you've -
already- detected. A better and cleaner approach would be to step
through the list -once- and remove the item when you find it:

for index, record in enumerate(l):
if record['title'] == 'ti':
l.pop(index)

Or you could just use a list comprehension:

l = [d for d in l if d['title'] == 'ti']

 Precision: I have stored data in the list of dictionaries l, because in my
 application I am sure that title is unique for each record. But perhaps
 it is better to imagine that someday it will not be anymore the case?

It's always better to design for what you know you need, not what you
may possibly need in the future. You say that you are sure that record
titles are unique, so why not use them as the dictionary keys, with
the values as the values:

  records = {'ti': 1, 'to': 2}

This way your code can be replaced with:

  value = records.pop('ti') # if you want to know the value
  del records['ti'] # if you just want to delete the entry

It's a lot simpler to work with and extend.
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick beginners List comprehension question

2009-01-21 Thread Steve Holden
Lou Pecora wrote:
 In article mailman.7691.1232554737.3487.python-l...@python.org,
  Philip Semanchuk phi...@semanchuk.com wrote:
 
 Other answers have been good; to them I'll add the comment that list  
 comprehensions are for *constructing* lists, not manipulating the  
 elements thereof.

 HTH
 Philip
 
 
 Well this seems to work just fine.  What am I missing:
 
A=[1,2,3]
print A
A=[2*a for a in A]
print A
 
The fact that the lists to be multiplied are attributes of a list of
objects, and therefore aren't themselves a list. Look more closely at
the original poster's question.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Beating a Timeout

2009-01-21 Thread K-Dawg
Also, the actual JS code that does this simply uses a

window.location.reload()

to keep the session active.  So I guess the only thing could be that eash
urllib.urlopen call is seen as a new session?  How can I make it part of the
same session I am using in IE?  Or am I a hundred miles off?

Thanks for any help.

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


Re: quick beginners List comprehension question

2009-01-21 Thread Philip Semanchuk


On Jan 21, 2009, at 11:52 AM, Lou Pecora wrote:


In article mailman.7691.1232554737.3487.python-l...@python.org,
Philip Semanchuk phi...@semanchuk.com wrote:



Other answers have been good; to them I'll add the comment that list
comprehensions are for *constructing* lists, not manipulating the
elements thereof.

HTH
Philip



Well this seems to work just fine.  What am I missing:

  A=[1,2,3]
  print A
  A=[2*a for a in A]
  print A


You haven't manipulated the list A, you've simply overwritten it with  
a new list. 
--

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


Re: is this pythonic?

2009-01-21 Thread MRAB

alex23 wrote:

On Jan 22, 1:16 am, TP tribulati...@paralleles.invalid wrote:

Is the following code pythonic:

l=[{title:to, value:2},{title:ti,value:coucou}]
dict = [ dict for dict in l if dict['title']=='ti']
l.remove(*dict)
l

[{'title': 'to', 'value': 2}]


Try not to use 'dict' or the name of any of the other built-in types
as labels.

You're stepping through an entire list just to pass another list to
l.remove to step through and remove items from...in fact, given that
list.remove deletes the -first- occurance of the item, you're asking
it to loop through -again- to find the matching element which you've -
already- detected. A better and cleaner approach would be to step
through the list -once- and remove the item when you find it:

for index, record in enumerate(l):
if record['title'] == 'ti':
l.pop(index)


[snip]
FYI, you shouldn't modify a list you're iterating over.


Or you could just use a list comprehension:

l = [d for d in l if d['title'] == 'ti']

The for-loop was removing the item where there's a match, so the list 
comprehension in this case should keep the item where there _isn't_ a match:


l = [d for d in l if d['title'] != 'ti']

[remainder snipped]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beating a Timeout

2009-01-21 Thread MRAB

K-Dawg wrote:

Hi,

I am trying to write a python script that I can run to prevent a timeout 
of webpage.  I have to use a system at work that keeps track of issues.  
I use this a couple of time an hour and it times out after 10 minutes.  
The system is really crummy and it rejects your username and password 
about 30-40 times before it takes it.  It is supposed to integrate with 
Active Directory and I don't think it does it very well.


So I have this open in Internet Explorer (its all in asp.net 
http://asp.net so it does not work in any other browser).  I was 
hoping to have something simple like:


#c:\Python25\python

import urllib
import urllib2
import time

while True:
 result = urllib.urlopen(the_URL 
http://sdeprod.brunswick.com/SDE/blank.aspx)

 print Retrieved Page
 time.sleep(300)

But this is not working  The code on the page uses a hidden iFrame 
that has a javascript file that monitors the time and intiates the 
timeout.  The src of the hidden iFrame is what I keep trying to grab.


It is still timing out in IE.  Once it times out in IE I get an error in 
my script saying:


IOError:  [Errno socket error] (10060, 'Operation timed out')

The system is terrible but I am stuck with it.  If it doesn't kick me 
out, at least its bearable...


Thanks for any help you can provide.


Have you looked at mechanize?

http://wwwsearch.sourceforge.net/mechanize/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules

2009-01-21 Thread alex23
On Jan 22, 1:45 am, Mudcat mnati...@gmail.com wrote:
 This is something I've wondered about for a while. I know that
 theoretically Python is supposed to auto-recognize duplicate imports;
 however I've run into problems in the past if I didn't arrange the
 imports in a certain way across multiple files. As a result, I worry
 about conflicts that arise because something has been imported twice.
 So...I'm not sure if Python *always* gets this correct.

Python -will- only import something once. Every time you import a
module, Python looks up its module dictionary to see if it contains a
module of that name. If not, it imports it, adds a new module object
and binds the name to that object in the calling namespace. If it does
exist, it retrieves the module object from the dict, and then binds
the name to that object in the calling namespace.

Its best to view each Python module as a completely independent
namespace. If you need to use something from another module within
that namespace, you need to import it. If I have a function 'f' in
module 'm' that uses 'math.pow', I can't just import 'f' into a module
that has imported 'math', I need to import 'math' into 'm'. Regardless
of where the function (or class) ends up being used, where it is
defined -must- have all of the imports that function needs to run.

If you're having to set up your imports in a specific order, odds are
you have either a circular dependency or are overusing 'from module
import *'. You should -never- (IMO) do something like 'from some
library import x, y, z' in module 'a' and then 'from a import *' in
module 'b'. If 'b' uses x, y  z, it should import them itself. If you
-must- use 'import *', specify exactly what should be exported via
'__all__'...in most cases, it should be restricted to only objects
defined within that module.

 I think it would great to have access to a file (like the __init__.py
 file for packages) which all the files in the same directory would
 have access to for common imports. That way you could push out the
 repeated imports and also clean up the look a little bit as well.

Well, you can always stick those imports into a 'common.py' and do
'from common import *' in each file that uses them. But doing so can
be a pain to maintain and debug for anything more than the most simple
of applications. Being able to see a module's dependencies clearly
listed at the top of the file is exceptionally handy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: is this pythonic?

2009-01-21 Thread TP
alex23 wrote:

 Try not to use 'dict' or the name of any of the other built-in types
 as labels.

Ops... Moreover I know it...

 You're stepping through an entire list just to pass another list to
 l.remove to step through and remove items from...in fact, given that
 list.remove deletes the -first- occurance of the item, you're asking
 it to loop through -again- to find the matching element which you've -
 already- detected. A better and cleaner approach would be to step
 through the list -once- and remove the item when you find it:
 
 for index, record in enumerate(l):
 if record['title'] == 'ti':
 l.pop(index)

Ok, I will use this solution. But it is less pythonic than list
comprehensions.

 Or you could just use a list comprehension:
 
 l = [d for d in l if d['title'] == 'ti']

Perhaps you mean rather:

l = [d for d in l if d['title'] != 'ti']
?

In fact, I cannot use this solution, because I want to get back the
dictionary with title 'ti', for another use (in fact, to add it to another
list, see below).

 Precision: I have stored data in the list of dictionaries l, because in
 my application I am sure that title is unique for each record. But
 perhaps it is better to imagine that someday it will not be anymore the
 case?
 
 It's always better to design for what you know you need, not what you
 may possibly need in the future. You say that you are sure that record
 titles are unique, so why not use them as the dictionary keys, with
 the values as the values:
 
   records = {'ti': 1, 'to': 2}
 
 This way your code can be replaced with:
 
   value = records.pop('ti') # if you want to know the value
   del records['ti'] # if you just want to delete the entry
 
 It's a lot simpler to work with and extend.

In fact, in my case, in cannot use this simple solution, because there are
other fields in each dictionary, not only 2. I was not clear in my post.
So my list is rather:
l=[{title:to, color:blue, value:2}
{title:ti, color:red, value:coucou}]

So, I will rather use your solution:

for index, record in enumerate(l):
if record['title'] == 'ti':
to_add_in_another_list = l.pop(index)
another_list.append(to_add_in_another_list )

 It's always better to design for what you know you need, not what you
 may possibly need in the future.

Ok. Do all the programmers agree with this principle?

-- 
python -c print ''.join([chr(154 - ord(c)) for c in '*9(9(18%.\
91+,\'Z4(55l4('])

When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong. (first law of AC Clarke)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Luis Zarrabeitia
On Wednesday 21 January 2009 02:30:54 am Russ P. wrote:

 That could work. As long as it's well-engineered (not a hack), well-
 supported (part of the standard library), and does the job, that's
 probably all that matters.

But you keep failing to explay why do you need it to be _part of the standard_ 
library (or whatever).

If you need it in your project, _use_ it. If you don't, then don't use it. If 
_you_ need that thing you call security, just use it already and quit 
complaining that we don't use it. Is there a policy in your project that you 
can't use any external?

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beating a Timeout

2009-01-21 Thread K-Dawg
Sorry about the last mesasge, I accidentally replied directly to the
poster.  So I now have:


br = mechanize.Browser()
br.open(theURL)
while True:
 result = br.reload()
 print result
 print Retrieved Page
 time.sleep(300)

But it still does not appear to be working...  Shortly after I got the Your
session is about to expire pop up.  I will continue to monitor though.

Is mechanize starting another session separate from my IE?  Is there anyway
to get my python to interact with the IE session if so?

Thanks.

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


Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 3:27 am, MRAB goo...@mrabarnett.plus.com wrote:
 FYI, you shouldn't modify a list you're iterating over.

But I'm not. I'm building a new list and binding it to the same name
as the original, which works perfectly fine (unless I'm missing
something):

 l = range(100)
 l = [d for d in l if not d % 5]
 l
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85,
90, 95]

 The for-loop was removing the item where there's a match, so the list
 comprehension in this case should keep the item where there _isn't_ a match:

 l = [d for d in l if d['title'] != 'ti']

Now that's a mistake. Cheers for the catch.
--
http://mail.python.org/mailman/listinfo/python-list


Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread Gaurav Veda
Hi,

I am trying to put some webpages into a mysql database using python
(after some processing on the text). If I use Python 2.4.2, it works
without a fuss. However, on Python 2.5, I get the following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
4357: ordinal not in range(128)

Before sending the (insert) query to the mysql server, I do the
following which I think should've taken care of this problem:
 sqlStr = sqlStr.replace('\\', '')

(where sqlStr is the query).

Any suggestions?

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Luis Zarrabeitia
On Tuesday 20 January 2009 09:52:01 pm Paul Rubin wrote:
 Luis Zarrabeitia ky...@uh.cu writes:
   Whaat?  Assuming a program is perfect unless a failure is proven
   is not at all a sane approach to getting reliable software.  It is
   the person claiming perfection who has to prove the absence of failure.
 
  No, no. I meant that if pylint works as its specification says it would.

 Oh, I see.  Well, that would be ok, except Pylint is not specified as
 detecting the types of access that Russ is concerned with.  It can't,
 for example, flag uses of setattr that might affect a particular
 class.  That would take something a lot fancier.

True.
And I doubt that the C++ compiler will flag the pointers running wildly 
pointing to random memory addresses and accessing the data in there. I doubt 
that pointer will 'respect' the 'private' keyword. I also doubt that the C# 
or Java _compiler_ will prevent you from using reflection somehow to access 
that data.

But somehow the discussion shifted from an optional requirement (giving you 
the chance to explicitly use 'from lock import unlock; o = unlock(obj)') 
to it can't be done _ever_ (using setattr/getattr is as explicit as your  
analogous 'unlock' function).

Btw, the correctness of a program (on a turing-complete language) cannot be 
statically proven. Ask Turing about it.

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


Re: is this pythonic?

2009-01-21 Thread MRAB

alex23 wrote:

On Jan 22, 3:27 am, MRAB goo...@mrabarnett.plus.com wrote:

FYI, you shouldn't modify a list you're iterating over.


But I'm not. I'm building a new list and binding it to the same name
as the original, which works perfectly fine (unless I'm missing
something):


[snip]
I was referring to the code:

for index, record in enumerate(l):
if record['title'] == 'ti':
l.pop(index)

where you are enumerating and iterating over 'l', but also modifying 'l' 
with 'l.pop(index)'.

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


Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 3:34 am, TP tribulati...@paralleles.invalid wrote:
      for index, record in enumerate(l):
          if record['title'] == 'ti':
              l.pop(index)

 Ok, I will use this solution. But it is less pythonic than list
 comprehensions.

Are you asking if it's less pythonic, or asserting? Because you'll
find a lot of disagreement here: list comprehensions are used for
constructing lists, not manipulating them.

 Perhaps you mean rather:

 l = [d for d in l if d['title'] != 'ti']
 ?

You are correct. I should never post past 3am :)

 In fact, in my case, in cannot use this simple solution, because there are
 other fields in each dictionary, not only 2. I was not clear in my post.
 So my list is rather:
 l=[{title:to, color:blue, value:2}
 {title:ti, color:red, value:coucou}]

I still find this a lot simpler:

  records = {'to': {'color': 'blue', 'value': '2'}, 'ti': {'color':
'red', 'value': 'coucou'}}

  It's always better to design for what you know you need, not what you
  may possibly need in the future.

 Ok. Do all the programmers agree with this principle?

Have you seen the size of some of the threads here? It's hard to get
two programmers to agree on variable names... :) But it's a practice
that has served me well and it even has a catchy name[1]. Getting what
you -need- to work is effort enough, if you don't have a definite use
case for a feature then how do you know you've implemented it
correctly? Write it when you need it.

1: http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It
--
http://mail.python.org/mailman/listinfo/python-list


Re: pep 8 constants

2009-01-21 Thread Aahz
In article mailman.7174.1231915778.3487.python-l...@python.org,
Brendan Miller catph...@catphive.net wrote:

PEP 8 doesn't mention anything about using all caps to indicate a constant.

Is all caps meaning don't reassign this var a strong enough
convention to not be considered violating good python style? I see a
lot of people using it, but I also see a lot of people writing
non-pythonic code... so I thought I'd see what the consensus is.

I've posted to python-dev requesting clarification; you may want to
subscribe to follow the discussion yourself.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules

2009-01-21 Thread Mudcat
 I think you've probably had issues with circular imports (i.e. mutual
 dependencies), unless you can precisely remember what you were doing and
 what went wrong.

That's possible, but circular imports become more of a hazard if you
have to import in several locations. Unify that to one file, and those
problems are much easier to avoid.

And I don't remember exactly what the problem was, but I think it had
to do with calling Tkinter in two different files. Somehow I was
getting an error in one of the files and removing Tkinter from
importing in one of the files solved it.

 I can make up three or four different logical groupings in my
 applications... so what is 'logical' could not be the same for everyone,
 or from every point of view.

That's not the point. The point is that multiple imports can be a
limiting factor if the module imports don't happen to align with the
model they'd like to use for their file layout.

However playing around with the files, I guess it is possible to
create a file that just does imports and then reference them all just
like you would any other extension of the namespace. I created a file
called imports and was able to access the sys module within it by
importing all from imports and calling sys. That way at least all you
have to do is import the one file each time.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematica 7 compares to other languages

2009-01-21 Thread soul.mirr...@gmail.com
On Dec 4 2008, 5:11 am, Andreas Waldenburger geekm...@usenot.de
wrote:
 On Wed, 03 Dec 2008 20:38:44 -0500 Lew no...@lewscanon.com wrote:

  Xah Lee wrote:
   enough babble ...

  Good point.  Plonk.  Guun dun!

 I vaguely remember you plonking the guy before. Did you unplonk him in
 the meantime? Or was that just a figure of speech?

 teasingly yours,
 /W

Andreas Waldenburger, I hold up a mirror to your soul!

A couple of years ago you started posting to the newsgroup
comp.lang.java.programmer. Unlike most newbies, instead of lurking for
a while and then contributing on-topic posts about Java, you jumped
into the nearest available flamewar and immediately got in up to your
neck. Then, on November 13, 2007, you stooped to intentionally
misquoting one of your opponents. When he wrote

http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e90afa4a20?dmode=source

you quoted him thusly:
http://groups.google.com/group/comp.lang.java.programmer/msg/0386cc91ce75a3c6?dmode=source

A few days later, you did it again, misquoting this post

http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d413549f499?dmode=source

in this one:

http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b23537c1b?dmode=source

In both cases, you publicly portrayed this poor man as a pervert, even
though, whatever his other faults, that is clearly not one of them.

Since that date, you have continued to participate on and off in a
flamewar with many of the same participants, including the one you so
mistreated that November. In fact, it seems that the very SAME
flamewar is still in progress, in another newsgroup, fourteen whole
months later, and you are still in it up to your neck.

Repeatedly you have claimed to be primarily motivated by finding the
disrupting of newsgroups to be entertaining. This is tantamount to
admitting to being a troll.

If you have an excuse for your behavior, please speak now, and give
your apology before the witnesses gathered here.

If you do not, then know that your soul is forever tainted!
--
http://mail.python.org/mailman/listinfo/python-list


Re: is this pythonic?

2009-01-21 Thread alex23
On Jan 22, 3:56 am, MRAB goo...@mrabarnett.plus.com wrote:
 I was referring to the code:

      for index, record in enumerate(l):
          if record['title'] == 'ti':
              l.pop(index)

 where you are enumerating and iterating over 'l', but also modifying 'l'
 with 'l.pop(index)'.

Ack, you're absolutely correct.

TP: my mistake, the for loop won't work at all. I'd really recommend
using the dictionary-based solution.

Apologies all around.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Importing modules

2009-01-21 Thread Mudcat
On Jan 21, 11:29 am, alex23 wuwe...@gmail.com wrote:

 Well, you can always stick those imports into a 'common.py' and do
 'from common import *' in each file that uses them. But doing so can
 be a pain to maintain and debug for anything more than the most simple
 of applications. Being able to see a module's dependencies clearly
 listed at the top of the file is exceptionally handy.

I x-posted the same thing but am curious why you think it's such a
problem to maintain. Having dependencies at the top is handy only
because it's usually quicker to get to the top of a file than it is to
open up another one. However if you have your common file open in your
IDE you can have it open in a split window where it's viewable all the
time. As long as you don't go crazy with import * in your common
file then you shouldn't get into trouble with duplicated namespaces.
As I mentioned before it should also cut down on the circular
imports.

So just preference aside, is there any problems with the actual
execution of the code if it's done this way? To me it simply compares
to putting an __init__ file in a package, except it applies to only
one directory.

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


[ANN] Python FTP Server library (pyftpdlib) 0.5.1 released

2009-01-21 Thread Giampaolo Rodola'
Hi,
I'm pleased to announce release 0.5.1 of Python FTP Server library
(pyftpdlib).
http://code.google.com/p/pyftpdlib

=== About ===

Python FTP server library provides an high-level portable interface to
easily write asynchronous FTP servers with Python.
Based on asyncore framework pyftpdlib is currently the most complete
RFC-959 FTP server implementation available for Python programming
language.

=== Major enhancements ===

This new version, aside from fixing some bugs, includes the following
major enhancements:

* A new script implementing FTPS (FTP over SSL/TLS) has been added in
the demo directory.

* File transfers are now 40% faster thanks to the re-dimensioned
application buffer sizes.

* ASCII data transfers on Windows are now 200% faster.

* Preliminary support for SITE command has been added.

* Two new callback methods to handle file received and file sent
events have been added.

A complete list of changes including enhancements and bug fixes is
available here:
http://code.google.com/p/pyftpdlib/wiki/ReleaseNotes05

=== More links ===

* Source tarball: http://pyftpdlib.googlecode.com/files/pyftpdlib-0.5.1.tar.gz
* Online docs: http://code.google.com/p/pyftpdlib/wiki/Tutorial
* FAQs: http://code.google.com/p/pyftpdlib/wiki/FAQ
* RFCs compliance paper: http://code.google.com/p/pyftpdlib/wiki/RFCsCompliance
* Issue tracker: http://code.google.com/p/pyftpdlib/issues/list
* Mailing list: http://groups.google.com/group/pyftpdlib


Thanks,


--- Giampaolo Rodola'   g.rodola [at] gmail [dot] com 

http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-21 Thread Brendan Miller
On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels
scott.dani...@acm.org wrote:
 Brendan Miller wrote:

 On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin
 http://phr.cx@nospam.invalid wrote:

   Of course I'm aware of the LOCK prefix but it slows
 down the instruction enormously compared with a non-locked instruction.

 I'm curious about that. I've been looking around for timing
 information on the lock signal, but am having some trouble finding
 them. Intuitively, given that the processor is much faster than the
 bus, and you are just waiting for processor to complete an addition or
 comparison before put the new memory value on the bus, it seems like
 there should be very little additional bus contention vs a normal add
 instruction.

 The opcode cannot simply talk to its cache, it must either go directly
 to off-chip memory or communicate to other processors that it (and it
 alone) owns the increment target.

Oh, right. *light bulb goes on* I wasn't thinking about cache at all.
--
http://mail.python.org/mailman/listinfo/python-list


Trouble writing txt

2009-01-21 Thread bilgin arslan
Hello,
I am trying to write a list of words to into a text file as two
colons: word (tab) len(word)
such as

standart8

I have no trouble writing the words but I couldn't write integers. I
always get strange characters, such as:

GUN
㐊娀䄀䴀䄀一ഀ਀5COCUK
㐊䬀䄀䐀䤀一ഀ਀5EV
...
㜊夀䄀䴀䄀ഀ਀4YATSI
㔊娀䤀䰀䜀䤀吀ഀ਀�

(the integers also seem to be incorrect)
I use the following form inside a loop to produce this
current = unicode(word)++str(len(word))
ofile.write(current)

I know about struct and I tried to used it but somehow I always got a
blank character instead of an int.

import struct
format = i
data = struct.pack(format, 24)
print data

Any ideas?
I use macosx and eclipse. The code also uses unicode encoding
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Paul Rubin
Luis Zarrabeitia ky...@uh.cu writes:
 But somehow the discussion shifted from an optional requirement (giving you 
 the chance to explicitly use 'from lock import unlock; o = unlock(obj)') 
 to it can't be done _ever_ (using setattr/getattr is as explicit as your  
 analogous 'unlock' function).

The idea was the lock would be on the class, not on instances of the
class.  So setattr/getattr would work on instances of unlocked classes
but not locked ones.  If you wanted an unlocked instance of a locked
class, you could do it by making an unlocked subclass.

 Btw, the correctness of a program (on a turing-complete language) cannot be 
 statically proven. Ask Turing about it.

That's an irrelevant red herring, even if you're after provability.
It just means that there exist some correct programs that cannot be
proven correct.  What you care about is whether there is a provable
program for some particular computing task, which there almost always
is.  It doesn't matter if there are also some unprovable ones.

That is just common sense.  When you write a program you presumably
write it using some reasoning that lets you convince yourself that the
program should always work, and that's an informal proof.  (The idea of static
verification is to find the small gaps of reasoning that humans make
all the time, but once found these gaps are usually easily fixed).  

I guess one occasionally writes programs that rely on unproven and
maybe unprovable mathematical conjectures, but that is pretty rare,
especially in traditional programming where you only care about
getting correct values out.  Even in areas which do rely on unproven
conjectures (e.g. in cryptography, we rely on the conjecture that
certain functions are difficult to invert), it's usually possible to
explicitly state the conjectures that you depend on, and prove that
if this conjecture is true then the program is correct.
--
http://mail.python.org/mailman/listinfo/python-list


Re: is this pythonic?

2009-01-21 Thread pruebauno
On Jan 21, 12:34 pm, TP tribulati...@paralleles.invalid wrote:
 alex23 wrote:
  Try not to use 'dict' or the name of any of the other built-in types

 So my list is rather:
 l=[{title:to, color:blue, value:2}
 {title:ti, color:red, value:coucou}]

 So, I will rather use your solution:

 for index, record in enumerate(l):
     if record['title'] == 'ti':
         to_add_in_another_list = l.pop(index)
 another_list.append(to_add_in_another_list )

If you have duplicates this will not work. You will have to do
something like this instead:

 o=[]
 i=0
 ln=len(l)
 while iln:
if l[i]['title']=='ti':
o.append(l.pop(i))
ln-=1
else:
i+=1



If you don't have duplicates you can extract the one and exit early:

 for index, record in enumerate(l):
if record['title'] == 'ti':
to_add_in_another_list = l.pop(index)
break

I don't know if these are more pythonic, they should be more efficient
for longer lists though.
--
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server

2009-01-21 Thread ak
On Jan 20, 1:14 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Mon, 19 Jan 2009 13:00:44 -0800, ak wrote:
  Hi everyone,

  I have a problem with urllib2 on this particular url, hosted on an
  Oracle HTTP Server

 http://www.orange.sk/eshop/sk/portal/catalog.html?

 type=postsubtype=phonenull



  which gets 302 redirected to
 https://www.orange.sk/eshop/sk/catalog/post/phones.html, after setting a
  cookie through the Set-Cookie header field in the 302 reply. This works
  fin with firefox.

  However, with urllib2 and the following code snippet, it doesn't work

 Looking at the BadStatusLine exception raised, the server response line
 is empty. Looking at the source for httpllib suggests to me that the
 server closed the connection early. Perhaps it doesn't like connections
 from urllib2?

 I ran a test pretending to be IE using this code:

 cookiejar = cookielib.LWPCookieJar()
 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
 url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?'\
     'type=postsubtype=phonenull'
 agent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;  \
     NeosBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
 headers = {'User-Agent': agent}
 req = urllib2.Request(url, data=None, headers=headers)
 try:
     s=opener.open(req)
 except httplib.BadStatusLine, e:
     print e, e.line
 else:
     print Success

 but it failed. So the problem is not as simple as changing the user-agent
 string.

 Other than that, I'm stumped.

 --
 Steven

Thanks a lot for confirming this. I also tried with different headers,
including putting *exactly* the same headers as firefox (including
Connection:keep-alive by modifying httplib), it still doesn't work.
The only possible explanation for me is that python's httplib doesn't
handle SSL/TLS 'properly' (not necessarly in the sense of the TLS
spec, but in the sense that every other browser can connect properly
to this website and httplib can't)

If anyone knows an Oracle HTTPS server to confirm this on another
server, it would be nice...
--
http://mail.python.org/mailman/listinfo/python-list


progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80

2009-01-21 Thread Luke Kenneth Casson Leighton
this is a progress report on compiling python using entirely free
software tools, no proprietary compilers or operating systems
involved, yet still linking and successfully running with msvcr80
assemblies.  manifests and rc files, which are compiled to internal
resources, have been added.
various sections which are uniquely identifed by _MSC_VER = 1400 etc
have had to be enabled with corresponding MSVCRT_VERSION = 0x0800 -
in particular, signal handling (PyOS_getsig()).

currently, under wine with msvcr80, there looks like there is a bug
with a common theme related to threads, but here's a short list:
test_array.py is blocking, test_bz2.py is hanging and test_cmd_line.py
causes a segfault; test_ctypes is _still_ a bundle of fun. for those
people who use native win32 platforms who are compiling up this code,
you should have better luck.

significantly, the wine developers have been absolutely fantastic, and
have fixed several bugs in wine, sometimes within hours, that were
found as a result of running the extremely comprehensive python
regression tests.

the python regression tests are a credit to the collaborative
incremental improvement process of free software development.

i look forward to seeing the same incremental improvement applied to
the development of python, evidence of which would be clearly seen by
the acceptance of one of the following patches, one of which is dated
2003:
http://bugs.python.org/issue3754
http://bugs.python.org/issue841454
http://bugs.python.org/issue3871
http://bugs.python.org/issue4954
http://bugs.python.org/issue5010

for those people wishing to track and contribute to the development of
python for win32 using entirely free software tools, either under wine
or native windows, there is a git repository, here, slightly
illogically named pythonwine because that's where i started from
(cross-compiling python under wine, so i could get at the wine
registry from python).  obviously, since then, things have... moved on
:)

http://github.com/lkcl/pythonwine/tree/python_2.5.2_wine

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


Re: what's the point of rpython?

2009-01-21 Thread MRAB

Brendan Miller wrote:

On Wed, Jan 21, 2009 at 8:19 AM, Scott David Daniels
scott.dani...@acm.org wrote:

Brendan Miller wrote:

On Tue, Jan 20, 2009 at 10:03 PM, Paul Rubin
http://phr.cx@nospam.invalid wrote:

  Of course I'm aware of the LOCK prefix but it slows
down the instruction enormously compared with a non-locked instruction.

I'm curious about that. I've been looking around for timing
information on the lock signal, but am having some trouble finding
them. Intuitively, given that the processor is much faster than the
bus, and you are just waiting for processor to complete an addition or
comparison before put the new memory value on the bus, it seems like
there should be very little additional bus contention vs a normal add
instruction.

The opcode cannot simply talk to its cache, it must either go directly
to off-chip memory or communicate to other processors that it (and it
alone) owns the increment target.


Oh, right. *light bulb goes on* I wasn't thinking about cache at all.

I'm not sure whether multicore processors share a cache or, if not, have 
some other on-chip mechanism. Multiprocessor machines, however, are a 
different matter...

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


Re: progress: compiling python2.5 under msys (specifically but not exclusively under wine) with msvcr80

2009-01-21 Thread Luke Kenneth Casson Leighton
 http://bugs.python.org/issue5010

correction: that's http://bugs.python.org/issue5026 apologies for the mix-up.

also,for the msvcrt80 build, it is _essential_ that you use a patched
version of mingw32-runtime, see:
https://sourceforge.net/tracker/index.php?func=detailaid=2134161group_id=2435atid=352435
libmsvcr80.a mistakenly thinks that _fstat exists (it doesn't - only
_fstat32 does, and many more).
it's quite straightforward to rebuild - just remember to run
./configure --prefix=/mingw and if you want to revert just reinstall
mingw runtime .exe

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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Luis Zarrabeitia
On Wednesday 21 January 2009 02:03:07 pm Paul Rubin wrote:
 Luis Zarrabeitia ky...@uh.cu writes:
  But somehow the discussion shifted from an optional requirement (giving
  you the chance to explicitly use 'from lock import unlock; o =
  unlock(obj)') to it can't be done _ever_ (using setattr/getattr is as
  explicit as your analogous 'unlock' function).

 The idea was the lock would be on the class, not on instances of the
 class.  So setattr/getattr would work on instances of unlocked classes
 but not locked ones.  If you wanted an unlocked instance of a locked
 class, you could do it by making an unlocked subclass.

Well, then, go change pylint to do that. But don't try to force it on _me_: If 
I want to access an attribute for an object on my program (from wherever it 
came from), I don't want _you_ or anyone else saying no, its private. 

Even better. Realize that you are trying to use a tool made for debugging, 
documenting, and catching some obvious errors (private/public) 
for security. Go fix Bastion, that would be your best bet. It was yanked 
out of python because it was insecure, but if someone were to fix it, I'm 
sure the changes would be welcomed. And then, it would be my choice whether 
to let you lock your instances in _my_ program, and it would be yours to lock 
all of mine in yours (and way more).

Btw, when I was programming in .Net (long time ago), I found a little library 
that I wanted to use. The catch: it wasn't opensource, it had a gratis 
version, and a full, payed version... The difference? The full one had some 
attributes public that were private on the free one. Well, I didn't wanted 
code on my app from someone who didn't know the meaning of the 'private' 
keyword anyway. You (well, Russ more than you) almost seem to be trying 
something like that.

  Btw, the correctness of a program (on a turing-complete language) cannot
  be statically proven. Ask Turing about it.

 That's an irrelevant red herring,

True, my bad.

But I don't think it is _fully_ irrelevant. See, a thread that begun with 
saying that a piece of code was hard to read has evolved to changing the 
language so we could have tools to statically proving certain things with 
the code. And each time a suggestion appears (from people that, at least at 
the time of suggesting it, were genuinely interested on helping) that doesn't 
fulfill your [plural, including russ] goal of having static typing and data 
hiding in the official python, you shoot it down because some other it 
cannot be proven statically reason. Sure, it is always a very well 
defined certain thing and not correctness in general, but that certain 
thing changes as soon as a suggestion is made to amend it.

I'm obviously growing tired of that pattern.

Have pylint check if someone uses getattr in your code, at all. If pylint 
doesn't do it, just grep for it and don't run that code. Simple.

Btw, this may put and end to this discussion:

import gc
gc.get_objects()

No amount of metaclasses, pylints, decorator, etc, will stop someone from 
using that to get access to _all_ objects of the program. If you need to keep 
a secret, don't put it on the same memory space that the untrusted code in 
python (actually, don't do it on any language). If you need static proofs, 
use a less dynamic subset of python, and use or develop tools to check if you 
tried to get out, ever (because if you get out once, you will not be able to 
track the results). Or, don't use python. (and certainly don't use C++, for 
that matter, even if C++ has a 'private' keyword).

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


date format

2009-01-21 Thread Ahmed, Shakir
I am grabbing few fields from a table and one of the columns is in date
format. The output which I am getting is Wed Feb 09 00:00:00 2005 but
the data in that column is 02/09/2005 and I need the same format
output to insert those recodes into another table.

print my_service_DATE
Wed Feb 09 00:00:00 2005

Any help is highly appreciated.

sk

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


Re: date format

2009-01-21 Thread Tim Chase

Ahmed, Shakir wrote:

I am grabbing few fields from a table and one of the columns is in date
format. The output which I am getting is Wed Feb 09 00:00:00 2005 but
the data in that column is 02/09/2005 and I need the same format
output to insert those recodes into another table.

print my_service_DATE
Wed Feb 09 00:00:00 2005


if you are getting actual date/datetime objects, just use the 
strftime() method to format as you so desire.


If you're getting back a *string*, then you should use 
time.strptime() to parse the string into a time-object, and then 
use the constituent parts to reformat as you see fit.


-tkc


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


Re: Does Python really follow its philosophy of Readability counts?

2009-01-21 Thread Scott David Daniels

Mark Wooding wrote:

Russ P. russ.paie...@gmail.com writes:


Actually, in addition to the enforcement of private, you also need
the enforcement of protected.


Oh, heavens.  If you want C++ or any of its progeny, you know where to
find them.  Besides, those languages have a horrific design mistake
because they conflate the class system (which manages the units of
behaviour) with the module system (which deals with the units of
implementation)


Nowhere in this discussion is a point that I find telling:  Python's
policy of accessibility to the full data structure allows simple
implementation of debugging software, rather than the black arcana
that is the normal fare of trying to weld debuggers into the compilers.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble writing txt

2009-01-21 Thread Benjamin Kaplan
On Wed, Jan 21, 2009 at 1:59 PM, bilgin arslan a.bilgi...@gmail.com wrote:

 Hello,
 I am trying to write a list of words to into a text file as two
 colons: word (tab) len(word)
 such as

 standart8

 I have no trouble writing the words but I couldn't write integers. I
 always get strange characters, such as:

 GUN
 㐊娀䄀䴀䄀一ഀ਀5COCUK
 㐊䬀䄀䐀䤀一ഀ਀5EV
 ...
 㜊夀䄀䴀䄀ഀ਀4YATSI
 㔊娀䤀䰀䜀䤀吀ഀ਀�



Looks like an encoding problem to me.


 (the integers also seem to be incorrect)
 I use the following form inside a loop to produce this
current = unicode(word)++str(len(word))
ofile.write(current)



 I know about struct and I tried to used it but somehow I always got a
 blank character instead of an int.

 import struct
 format = i
 data = struct.pack(format, 24)
 print data



Struct encodes the data as a string. 24 encoded as a byte string is
represented as 18 00 00 00 (these are hex). All of these values are
unprintable, so you get a blank instead. You're original idea should work
once you get the encoding problem fixed.



 Any ideas?
 I use macosx and eclipse. The code also uses unicode encoding


Unicode is NOT an encoding. It is a standard. You're probably thinking of
the UTF-8 encoding, one of the 5 different unicode encodings. This page
does a great job of explaining what Unicode actually is.

http://www.joelonsoftware.com/articles/Unicode.html

Try using ofile.write(current.encode(UTF-8)) and see if that helps.
--
http://mail.python.org/mailman/listinfo/python-list


Re: English-like Python

2009-01-21 Thread Scott David Daniels

Benjamin J. Racine wrote:

I think it would be a good step if you could make some sensible interpretation 
of a typical statement without its parentheses.

f abc 123
--
f( abc, 123 )

It would be just the thing in a couple of situations... though it does conflict with raw-string 
literals as stated: rabc... which if you left open, would be susceptible to a local 
definition of r!.  Maybe you could put it after, like numeric literals: 123L, abcr, 
which is not bad.


Surely this would require that
  f( abc, 123 )
  --
  f((abc, 123))
Or would you require that tuple-formation is special?

--Scott David Daniels
scott.dani...@acm.org

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


Re: Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread John Machin
On Jan 22, 4:49 am, Gaurav Veda vedagau...@gmail.com wrote:
 Hi,

 I am trying to put some webpages into a mysql database using python
 (after some processing on the text). If I use Python 2.4.2, it works
 without a fuss. However, on Python 2.5, I get the following error:

 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
 4357: ordinal not in range(128)

 Before sending the (insert) query to the mysql server, I do the
 following which I think should've taken care of this problem:
  sqlStr = sqlStr.replace('\\', '')

 (where sqlStr is the query).

 Any suggestions?

The 0xc2 strongly suggests that you are feeding the beast data encoded
in UTF-8 while giving it no reason to believe that it is in fact not
encoded in ASCII. Curiously the first errant byte is a long way (4KB)
into your data. Consider doing
print repr(data)
to see what you've actually got there.

I'm a little skeptical about the 2.4 works, 2.5 doesn't notion --
different versions of mysql, perhaps?

Show at the very least the full traceback that you get. Try to write a
short script that demonstrates the problem with 2.5 and no problem
with 2.4, so that (a) it is apparent what you are doing (b) the
problem can be reproduced if necessary by someone with access to
mysql.

You might like to explain why you think that doubling backslashes in
your SQL is a good idea, and amplify some processing on the text.

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


Re: Start Python at client side from web app

2009-01-21 Thread James Stroud

Thomas Guettler wrote:

Sorry, I described my problem not well. Here is more information:

The main application is the intranet web application used with IE (ms windows 
client).
But some action needs to be done on the client since you can't do it with html 
or javascript.

1. The user pushes a button in the web app.
2. Webserver sends signed python code to the client with own mime type
3. IE sends code to the python application.
4. Signature gets checked, Python code on the client gets executed.
5. Maybe send some data to the server with http.


You need to write an IE plugin for this, otherwise you can't get out of 
the browser sandbox to execute anything on the client side.


In fact, if you just make your IE application a plugin, you can take 
advantage of updating facilities that IE should have for plugins. If IE 
doesn't have updating facilities, then just write a firefox plugin, 
which does have these facilities.

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


Re: Trouble writing txt

2009-01-21 Thread Jeff McNeil
On Jan 21, 1:59 pm, bilgin arslan a.bilgi...@gmail.com wrote:
 Hello,
 I am trying to write a list of words to into a text file as two
 colons: word (tab) len(word)
 such as

 standart8

 I have no trouble writing the words but I couldn't write integers. I
 always get strange characters, such as:

 GUN
 㐊娀䄀䴀䄀一ഀ਀5COCUK
 㐊䬀䄀䐀䤀一ഀ਀5EV
 ...
 㜊夀䄀䴀䄀ഀ਀4YATSI
 㔊娀䤀䰀䜀䤀吀ഀ਀

 (the integers also seem to be incorrect)
 I use the following form inside a loop to produce this
 current = unicode(word)++str(len(word))
 ofile.write(current)

 I know about struct and I tried to used it but somehow I always got a
 blank character instead of an int.

 import struct
 format = i
 data = struct.pack(format, 24)
 print data

 Any ideas?
 I use macosx and eclipse. The code also uses unicode encoding

I don't have a Mac in front of me, but I'll take a stab at it.  You
shouldn't need to bother with the struct module if you're simply
trying to print out an integer's string value. What are you using to
open 'ofile?' Can you post all of the relevant code?

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


  1   2   3   >