Re: unicode question

2006-02-25 Thread Tim Roberts
Edward Loper [EMAIL PROTECTED] wrote:

I would like to convert an 8-bit string (i.e., a str) into unicode,
treating chars \x00-\x7f as ascii, and converting any chars \x80-xff
into a backslashed escape sequences.  I.e., I want something like this:

  decode_with_backslashreplace('abc \xff\xe8 def')
u'abc \\xff\\xe8 def'

The best I could come up with was:

   def decode_with_backslashreplace(s):
   str - unicode
   return (s.decode('latin1')
.encode('ascii', 'backslashreplace')
.decode('ascii'))

Surely there's a better way than converting back and forth 3 times?

I didn't check whether this was faster, although I rather suspect it is
not:

  cvt = lambda x: ord(x)0x80 and x or '\\x'+hex(ord(x))
  def decode_with_backslashreplace(s):
  return ''.join(map(cvt,s))
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception not raised

2006-02-25 Thread Michele Petrazzo
Diez B. Roggisch wrote:
 This code are inside a method into class that have no try/except. 
 And called from a method inside a wx.Frame derivate. The other 
 strange thing is that if I try the same code just before the 
 caller to that method, it raise an exception:
 
 So maybe the C-layer of wx in-between doesn't propagate the exception
  for whatever reason?

Can be, but only that exception aren't raised, all the other, in the
same point of code, yes.

 Fact is: pythons exception-handling is core part of the language and 
 an error in there _extremely_ improbable .

I think the same, and this is one of the reason that push me to use python.

 So I suggest you cut down your example until it is self-contained 
 with only a few dozen lines and still produces your observed 
 behavior. Otherwise no one will be able to help you.

Into my 100 line code, that exception (and all the others) are raised! I
don't able, into all my tries, to reproduce that error on a small code...

I can publish my code, if someone has one hour of spare time and  a
postgresql where test the code. I'm make some instruction to reproduce it.

 
 Diez

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


Multiple threaded download streams?

2006-02-25 Thread gjzusenet
Hello.
Though Python supports threading, I think it is limited to python code
- as soon as you issue a command that uses an external (C?) module, all
of your python threads hang until this command returns.
Is that true?
I'm using urllib2 to download many files, and I have a double problem:
1. downloading all of them is painfully slow since it's serial - one
has to finish before the next request gets sent.
2. my GUI becomes non responsive during the downloads - major problem!

Is there any way to work around that?
I want to run multiple download streams, in parallel, and while keeping
my program responsive.
Are there alternative modules that I can use for that?

Any ideas?
Thanks a lot!

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


Re: How to send an email with non-ascii characters in Python

2006-02-25 Thread Sybren Stuvel
Lad enlightened us with:
 Body='Rídících Márinka a Školák Kája
 Marík'.decode('utf8').encode('windows-1250')# I use the text written
 in my editor with utf-8 coding, so first I decode and then encode to
 windows-1250

Why would you do that? What's the advantage of windows-1250?

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Import in a separate thread

2006-02-25 Thread cyberco
I want to import a long list of modules in a separate thread to speed
things up. How can I make the modules imported in that separate thread
accessible outside the method?

===
import os

# import rest in a separate thread
def importRest():
import audio
import socket
thread.start_new_thread(importRest,())

# audio.somemethod()  would fail here
===

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


Re: Import in a separate thread

2006-02-25 Thread Paul Rubin
cyberco [EMAIL PROTECTED] writes:
 I want to import a long list of modules in a separate thread to speed
 things up. How can I make the modules imported in that separate thread
 accessible outside the method?

It won't speed things up unless the main thread is waiting for user
input during those imports, or something like that.  Threads in Python
don't really run in parallel.

 # import rest in a separate thread
 def importRest():
 import audio
 import socket
 thread.start_new_thread(importRest,())
 
 # audio.somemethod()  would fail here

Here's one way:

def importRest():
   global audio
   import audio as local_audio
   audio = local_audio
   # etc. 

There's surely other ways that are better.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import in a separate thread

2006-02-25 Thread Peter Hansen
cyberco wrote:
 I want to import a long list of modules in a separate thread to speed
 things up. How can I make the modules imported in that separate thread
 accessible outside the method?

Sounds like premature optimization.  Speed things up?  What things? 
How long is it taking now to load the modules you are loading?  Even the 
wxPython demo takes only a few seconds to load on a decent machine, and 
that's loading a *heck* of a lot of stuff.  (And it takes the 
conventional approach to this issue too, which is to display a splash 
screen while things load.)

-Peter

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


Re: python-list/python-dev quoting style

2006-02-25 Thread Grant Edwards
On 2006-02-25, Michael Hoffman [EMAIL PROTECTED] wrote:

 And who is me, anyway?

 It's hard to believe that you don't understand who me is in
 a conversation between two people,

Since when is a Usenet news group a conversation between two
people?

 one of whom is identified as Aahz and is attributed words
 you yourself wrote.


-- 
Grant Edwards   grante Yow!  Not SENSUOUS... only
  at   FROLICSOME... and in
   visi.comneed of DENTAL WORK... in
   PAIN!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple threaded download streams?

2006-02-25 Thread Grant Edwards
On 2006-02-25, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Though Python supports threading, I think it is limited to
 python code - as soon as you issue a command that uses an
 external (C?) module, all of your python threads hang until
 this command returns. Is that true?

No.  Not unless the C modules is broken.

 I'm using urllib2 to download many files, and I have a double
 problem:

 1. downloading all of them is painfully slow since it's serial
- one has to finish before the next request gets sent.

Then don't do it that way.

 2. my GUI becomes non responsive during the downloads - major
problem!

Use a separate thread for downloading.

 Is there any way to work around that?

Yes.  Use threads.

 I want to run multiple download streams, in parallel, and while keeping
 my program responsive.

Then do it that way.

 Are there alternative modules that I can use for that?

And what, exactly, didn't work right when you tried the
threading module?

-- 
Grant Edwards   grante Yow!  I demand IMPUNITY!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple threaded download streams?

2006-02-25 Thread Diez B. Roggisch
 Use a separate thread for downloading.

Or the twisted select-reactor. No threads needed.

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


Re: graph display(please help)

2006-02-25 Thread Mladen Adamovic
questions? wrote:
 I heard from my friend who used to program in JAVA, it is really easy
 to do graph display in JAVA.
 Thanks for any suggestions!!!


Jython


-- 
Mladen Adamovic
home page: http://home.blic.net/adamm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import in a separate thread

2006-02-25 Thread Paul Rubin
Peter Hansen [EMAIL PROTECTED] writes:
 Sounds like premature optimization.  Speed things up?  What things?
 How long is it taking now to load the modules you are loading?  Even
 the wxPython demo takes only a few seconds to load on a decent
 machine, and that's loading a *heck* of a lot of stuff.  

I know that whenever I start IDLE and it's not already cached, it
takes a significant amount of time, and that doesn't even use
wxPython.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using ElementTree to tidy up an XML string to my liking

2006-02-25 Thread Richard Townsend
On Fri, 24 Feb 2006 18:21:59 +0100, Magnus Lycka wrote:

 Concerning element names, it's your coice of course, but I agree
 more and more with Guido and PEP008 that camelCase is ugly. (Not
 that ALLCAPS is better...)

I can see in PEP008 where it says Capitalized_Words_With_Underscores is
ugly, but I can't see where it says pure camelCase is ugly ?

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


Problem with Property

2006-02-25 Thread none
I'm trying to implement a simple repeateable property mechansism so I 
don't have to write accessors for every single instance variable I have.

classMyObject:
 def __init__ (self):
 self.initialize()

 def initialize(self):
 self._value=None


 def _setProperty (self, name, value):
 print set property
 setattr (self, name, value)

 def _getProperty (self, name):
 print get property
 return getattr (self, name)

 #properties
 value = property (lambda self: self._getProperty(_value),
  lambda self, value: self._setProperty(_value, 
value))


def testObject():
 o = MyObject()
 print o.__dict__
 print o.value
 o.value = 123
 print o.value
 print o.__dict__

if __name__ == __main__:
 testObject()
-

The outout looks like this

{'_value': None}
get property
None
123
{'_value': None, 'value': 123}
---
As you can see, the _getProperty() method gets called properly when I do 
  'o.value'  but 'o.value = 123' does not seem to use the property 
stucture.   I can't figure out why 'o.value=123' does not call 
_setProperty()

Any ideas?

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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-02-25 Thread dananrg
Thanks Olivier and Jonathan.

Do either of you, or anyone else, know of a good open source data
modeling / ER-diagram / CASE tools? I'd like to be able to build
relatively simple schemas in one open source tool and be able to create
a database on different platforms as needed (e.g. MySQL, PostgreSQL,
Oracle, etc).

Just wondering what's out there.

Thanks.

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


Re: Module written in C does not repond to Ctrl-C interruption.

2006-02-25 Thread Daniel Dittmar
Bo Peng wrote:
 Daniel Dittmar wrote:
 

 You could set up your own signal handler when entering the C 
 extension. This should abort the extension (tricky) and call the 
 Python signal handler.
 
 
 This can be done under linux using things in signal.h but I am not
 sure whether or not there is a portable way to do it (max, win32).
 Does anybody know a quick way under windows?


SetConsoleCtrlHandler:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolectrlhandler.asp

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


Re: PyUNO with different Python

2006-02-25 Thread M�ta-MCI
h...

I can run OK hello_world.py. But only with Python-core-2.3

Python 2.4 don't run  (conflict-version, or windows error).
And, it's not possible to install extensions (like PyWin) to Python-core-2.3 
(this destroy the same extensions in my normal Python 2.4)

I had let down these aspects of OOo.

*sorry for my bad english*

MCI





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


Re: [Python-de] PyUNO with different Python

2006-02-25 Thread M�ta-MCI
Bonjour !

J'ai des problèmes/besoins similaires.
Mais, désolé, je ne parle pas allemand...

@-salutations

Michel Claveau



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

A bit off topic, but good web hosting for PostgreSQL/Python?

2006-02-25 Thread dananrg
Seems like most web hosting providers support MySQL, but not
PostgreSQL. I need a web hosting account that supports PostgreSQL for a
particular personal project I'm working on (as well as Python, natch),
since PostGIS runs only on PostgreSQL. PostGIS is a nice open source
spatial database extension to PostgreSQL that allows you to store
geometry in the database.

Couldn't find a good PostgreSQL newsgroup so I thought I'd ask here.
Did find one weird one named Mailing something or other, but that may
be a gateway to a e-mail distribution list.

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


Re: python-list/python-dev quoting style

2006-02-25 Thread Michael Hoffman
[Aahz]
And who is me, anyway?

[me]
It's hard to believe that you don't understand who me is in
a conversation between two people,

[Grant Edwards]
 Since when is a Usenet news group a conversation between two
 people?

Now there are three. At that time only two people had participated in 
this thread.

Is there really confusion about who me is? I find that mystifying.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Problem with Property

2006-02-25 Thread André Malo
* none wrote:

 classMyObject:
[...]

 As you can see, the _getProperty() method gets called properly when I do
   'o.value'  but 'o.value = 123' does not seem to use the property
 stucture.   I can't figure out why 'o.value=123' does not call
 _setProperty()
 
 Any ideas?

property only works as intended with new style classes.

nd
-- 
 Muschelflucht-Zusatzeinrichtung.
 Shell-Escape ist ja noch klar, aber `Zusatzeinrichtung'?
 extension?
Feature.  -- gefunden in de.org.ccc
-- 
http://mail.python.org/mailman/listinfo/python-list


Is Python a Zen language?

2006-02-25 Thread John Coleman
Greetings,
   I have a rough classification of languages into 2 classes: Zen
languages and tool languages. A tool language is a language that is,
well, a *tool* for programming a computer. C is the prototypical tool
language. Most languages in the Algol family are tool languages. Visual
Basic and Java are also tool languages. On the other hand, a Zen
language is a language which is purported to transform your way of
thinking about programming. Lisp, Scheme, Forth, Smalltalk and (maybe)
C++ are Zen languages. Disciples acknowledge that it is difficult to
pick up these languages but claim that, if you persevere, you sooner or
later reach a state of computational satori in which it all makes
sense. Interestingly enough, these languages often have books which
approach scriptural status  e.g. SICP for Scheme.

So (assuming my classification makes sense)  which is Python? The
emphasis on simplicity and the beginner-friendly nature of it seems to
put it in the tool category. On the other hand, the emphasis on the ONE
TRUE WAY to accomplish most tasks and the tendency for participants in
this newsgroup to criticize one another's code as being unpythonic
seems to move it towards the Zen category. Of course, even tool
languages have their idioms which the novice needs to pick up, so maybe
this isn't decisive, but I detect an element of zeal in this newsgroup
that I don't detect in (say) Excel VBA programming newsgroups.

No value judgement is intended by my classification. There is no
denying that Zen languages are often very powerful tools (for those who
have reached satori) and that there is a Zen to really mastering, say,
C. Personally, I have never been able to master any Zen language but
can pick up tool languages fairly quickly, so I prefer tool languages.
This is probably because I am not a programmer (I'm a mathematician who
likes to program as a hobby and for numerical simulations) and so don't
have the time to invest in picking up a Zen language. Hard-core hackers
might presumably lean towards the Zen languages.

Just curious

-John Coleman

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


Re: Multiple threaded download streams?

2006-02-25 Thread Peter Hansen
Diez B. Roggisch wrote:
Use a separate thread for downloading.
 
 Or the twisted select-reactor. No threads needed.

Although depending on what the GUI is like, and what platform is 
involved, one might still want at least a second thread for the reactor 
itself.

-Peter

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


Re: Problem with Property

2006-02-25 Thread Steve Holden
none @bag.python.org wrote:
 I'm trying to implement a simple repeateable property mechansism so I 
 don't have to write accessors for every single instance variable I have.

Please don't do that. The Python way is to use direct access to instance 
variables unless there's a good reason not to.

Is there some reason why you want to run get/set code for every instance 
variable access, or are you just experimenting to see whether it can be 
done?

It seems particularly odd to want to put getters and setters behind 
property access. What does the extra layer buy you?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Problem with Property

2006-02-25 Thread none
André Malo wrote:
 * none wrote:
 
 
classMyObject:
 
 [...]
 
 
As you can see, the _getProperty() method gets called properly when I do
  'o.value'  but 'o.value = 123' does not seem to use the property
stucture.   I can't figure out why 'o.value=123' does not call
_setProperty()

Any ideas?
 
 
 property only works as intended with new style classes.

duh.. I changed that to
class MyObject(object):
and it worked fine

Thanks

Take care,
Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Property

2006-02-25 Thread none
André Malo wrote:
 * none wrote:
 
 
classMyObject:
 
 [...]
 
 
As you can see, the _getProperty() method gets called properly when I do
  'o.value'  but 'o.value = 123' does not seem to use the property
stucture.   I can't figure out why 'o.value=123' does not call
_setProperty()

Any ideas?
 
 
 property only works as intended with new style classes.

duh.. I changed that to
class MyObject(object):
and it worked fine

Thanks

Take care,
Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Property

2006-02-25 Thread Felipe Almeida Lessa
Em Sáb, 2006-02-25 às 09:14 -0500, Steve Holden escreveu:
 It seems particularly odd to want to put getters and setters behind 
 property access. What does the extra layer buy you?

I can only think of some kind of debugging. Maybe?

 regards
   Steve

Cya,
Felipe.

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: Problem with Property

2006-02-25 Thread Peter Hansen
none @bag.python.org wrote:
 I'm trying to implement a simple repeateable property mechansism so I 
 don't have to write accessors for every single instance variable I have.
...

 Any ideas?

Yes, don't write accessors for every single instance variable you have. 
  In some languages that might be appropriate, or considered good style. 
  In Python, it's entirely unnecessary and you should just access 
instance variables directly when you want to, and in the odd case where 
you want to do something more than set/get/del them you can resort to 
properties (when a nice clear method wouldn't fit).

(Sorry not to answer the question directly.  If you feel you really need 
to use accessors then go ahead, but I just wanted you to know that many 
Python programmers feel quite differently about them than, say, C++ or 
Java programmers might.)

-Peter

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


Re: Is Python a Zen language?

2006-02-25 Thread Ron Stephens
Actually, Python has the distinction of being both a great tool
language *and* a great Zen language. That's what makes Python so cool
;-)))

Ron Stephens
Python411
www.awaretek.com/python/index.html

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


Re: Problem with Property

2006-02-25 Thread none
Steve Holden wrote:
 none @bag.python.org wrote:

 It seems particularly odd to want to put getters and setters behind 
 property access. What does the extra layer buy you?

The purpose is that there is more to the accessors then I posted.

The setters do some 'mark dirty' bookeeping whenever the object state 
changes. (I had coded something similar in a prior project but had 
forgotten a bit of my own work...in that project the setters also did 
some event signaling as the objects were part of an Observer-Observable 
pattern)

The getters also have some code in them for dealing with default values 
if the given variable behind the property does not exist (which happened 
when I was pickling objects and the class structure changed over time; 
it was helpful to be able to have the getter be able to check if the 
variable existed and, if not, provide a default value...a way of 
migrating objects to new class definitions)

So, the use of properties allowed me let clients of the class to use 
direct access syntax...  o.value versues o.value() or o.value = 123 
versus o.value(123) ...but still allow me to do the bookkeeping needed 
for my object state.  The use of the _getProperty() and _setProperty() 
and using lambdas in the actual property definition allowed me to have a 
default setter/getter of sorts so I didn't need to write a seperate 
getter and setter method for each variable

Take care,
Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pure python implementation of string-like class

2006-02-25 Thread and-google
Akihiro KAYAMA wrote:
 As the character set is wider than UTF-16(U+10), I can't use
 Python's native unicode string class.

Have you tried using Python compiled in Wide Unicode mode
(--enable-unicode=ucs4)? You get native UTF-32/UCS-4 strings then,
which should be enough for most purposes.

-- 
And Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

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


Re: Is Python a Zen language?

2006-02-25 Thread Alex Martelli
Mu.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a Zen language?

2006-02-25 Thread John Coleman

Ron Stephens wrote:
 Actually, Python has the distinction of being both a great tool
 language *and* a great Zen language. That's what makes Python so cool
 ;-)))

 Ron Stephens
 Python411
 www.awaretek.com/python/index.html

This would explain why the question is so hard to answer. It is a
slam-dunk that Lisp is Zen and VBA is tool - but python really is a bit
hard to classify. This is somewhat similar to the way that python seems
to straddle the gap between imperative and functional languages. It has
something from each worlds (whether it has the *best* from each world
is a separate question)

-John Coleman

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


Re: python-list/python-dev quoting style

2006-02-25 Thread Steve Holden
Some lurker calling himself me wrote:
 [Aahz]
 
And who is me, anyway?
 
 
 [me]
 
It's hard to believe that you don't understand who me is in
a conversation between two people,
 
 
 [Grant Edwards]
 
Since when is a Usenet news group a conversation between two
people?
 
 
 Now there are three. At that time only two people had participated in 
 this thread.
 
 Is there really confusion about who me is? I find that mystifying.

Well, *I* know who me is. That makes you an impostor.

see-how-nobody-knows-who-you-are-now-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Pure python implementation of string-like class

2006-02-25 Thread Steve Holden
Akihiro KAYAMA wrote:
 Hi all.
 
 I would like to ask how I can implement string-like class using tuple
 or list. Does anyone know about some example codes of pure python
 implementation of string-like class?
 
 Because I am trying to use Python for a text processing which is
 composed of a large character set. As the character set is wider than
 UTF-16(U+10), I can't use Python's native unicode string class.
 
Wider than UTF-16 doesn't make sense.

 So I want to prepare my own string class, which provides convenience
 string methods such as split, join, find and others like usual string
 class, but it uses a sequence of integer as a internal representation
 instead of a native string.  Obviously, subclassing of str doesn't
 help.
 
 The implementation of each string methods in the Python source
 tree(stringobject.c) is far from python code, so I have started from
 scratch, like below:
 
 def startswith(self, prefix, start=-1, end=-1):
 assert start  0, not implemented
 assert end  0, not implemented
 if isinstance(prefix, (str, unicode)):
 prefix = MyString(prefix)
 n = len(prefix)
 return self[0:n] == prefix
 
 but I found it's not a trivial task for myself to achive correctness
 and completeness. It smells reinventing the wheel also, though I
 can't find any hints in google and/or Python cookbook.
 
 I don't care efficiency as a starting point. Any comments are welcome.
 Thanks.
 
The UTF-16 encoding is capable of representing the whole of Unicode. 
There should be no need to do anything special to use UTF-16.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Import in a separate thread

2006-02-25 Thread cyberco
Well, it is for the python implementation for Nokia Series 60 phones,
and loading lots of modules in such constrained environments can
certainly slow things down. The splashscreen idea is what I want to do,
but that requires the loading to continue in a background thread.

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


Re: Multiple threaded download streams?

2006-02-25 Thread Bryan Olson
Diez B. Roggisch wrote:
 Use a separate thread for downloading.
 
 Or the twisted select-reactor. No threads needed.

He's using urllib2, which does not use Twisted's select-reactor.

Fortunately urllib2 downloads run fine in their own threads; no
rewrite-all-the-code-as-Twisted-state-machines needed.


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


Re: Is Python a Zen language?

2006-02-25 Thread [EMAIL PROTECTED]
GEB perhaps?

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


Re: python-list/python-dev quoting style

2006-02-25 Thread Grant Edwards
On 2006-02-25, Steve Holden [EMAIL PROTECTED] wrote:

 [Aahz]
 
And who is me, anyway?
 
 [me]
 
It's hard to believe that you don't understand who me is in
a conversation between two people,
 
 [Grant Edwards]
 
Since when is a Usenet news group a conversation between two
people?
 
 Now there are three. At that time only two people had participated in 
 this thread.
 
 Is there really confusion about who me is? I find that
 mystifying.

 Well, *I* know who me is. That makes you an impostor.

 see-how-nobody-knows-who-you-are-now-ly y'rs  - steve

And now none of us have any way to know who the [me] above is.

-- 
Grant Edwards   grante Yow!  Hmmm... a CRIPPLED
  at   ACCOUNTANT with a FALAFEL
   visi.comsandwich is HIT by a
   TROLLEY-CAR...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode question

2006-02-25 Thread Kent Johnson
Edward Loper wrote:
 I would like to convert an 8-bit string (i.e., a str) into unicode,
 treating chars \x00-\x7f as ascii, and converting any chars \x80-xff
 into a backslashed escape sequences.  I.e., I want something like this:
 
   decode_with_backslashreplace('abc \xff\xe8 def')
 u'abc \\xff\\xe8 def'

   s='abc \xff\xe8 def'
   s.encode('string_escape')
'abc \\xff\\xe8 def'
   unicode(s.encode('string_escape'))
u'abc \\xff\\xe8 def'

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


Re: Import in a separate thread

2006-02-25 Thread Kent Johnson
cyberco wrote:
 I want to import a long list of modules in a separate thread to speed
 things up. How can I make the modules imported in that separate thread
 accessible outside the method?
 
 ===
 import os
 
 # import rest in a separate thread
 def importRest():
 import audio
 import socket
 thread.start_new_thread(importRest,())
 
 # audio.somemethod()  would fail here
 ===
 

Just import the modules again when you need to use them - modules are 
cached, only the initial import is expensive.

Of course this won't help if you don't have something else to do (like 
wait for the user) while the threaded imports happen.

Another helpful technique is to put imports inside the functions that 
need them. If every module imports the modules it needs at global scope, 
then when the first module loads it will trigger importing of the whole 
program and all needed library modules. If this is expensive, you can 
break up the loads by putting key imports into functions instead of at 
global scope.

Note to the doubters - I have used these techniques in Jython programs, 
where importing java packages can be noticably slow.

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


Re: Multiple threaded download streams?

2006-02-25 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Hello.
 Though Python supports threading, I think it is limited to python code
 - as soon as you issue a command that uses an external (C?) module, all
 of your python threads hang until this command returns.
 Is that true?
 I'm using urllib2 to download many files, and I have a double problem:
 1. downloading all of them is painfully slow since it's serial - one
 has to finish before the next request gets sent.
 2. my GUI becomes non responsive during the downloads - major problem!
 
 Is there any way to work around that?
 I want to run multiple download streams, in parallel, and while keeping
 my program responsive.
 Are there alternative modules that I can use for that?
 
 Any ideas?
 Thanks a lot!
 
Others have spoken to the specifics of threads, etc.  What I wanted
to ask was why you think that parallel downloads will be faster?
Unless you are downloading from multiple and different sites and
your Internet download bandwidth is much greater than any individual
site you wish to download from, you won't speed things up.  If you
wish to download several files from the SAME site, I doubt that
threading is going to help.  Most likely you are limited by the
upload bandwidth of that site.  Now if the site you are downloading
from has some throttling turned on to limit the speed of an
individual download, you could gain some benefit.  You can't push
bits through the pipes faster than their upper bandwidth.

Just some thoughts to consider.

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


Re: Is Python a Zen language?

2006-02-25 Thread Max Erickson
Given that python code is often described in terms of being 'pythonic' or 
not, and that pythonic is a term that is apparently well agreed upon yet 
seemingly impossible to define for someone who does not already understand 
the word, python is probably a zen language.

max 


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


Re: Is Python a Zen language?

2006-02-25 Thread Kent Johnson
John Coleman wrote:
 Greetings,
I have a rough classification of languages into 2 classes: Zen
 languages and tool languages. A tool language is a language that is,
 well, a *tool* for programming a computer. C is the prototypical tool
 language. Most languages in the Algol family are tool languages. Visual
 Basic and Java are also tool languages. On the other hand, a Zen
 language is a language which is purported to transform your way of
 thinking about programming. Lisp, Scheme, Forth, Smalltalk and (maybe)
 C++ are Zen languages. Disciples acknowledge that it is difficult to
 pick up these languages but claim that, if you persevere, you sooner or
 later reach a state of computational satori in which it all makes
 sense. Interestingly enough, these languages often have books which
 approach scriptural status  e.g. SICP for Scheme.
 
 So (assuming my classification makes sense)  which is Python?

Expanding on what Alex said :-)

Python is an excellent tool language, it is very pragmatic and powerful 
and makes it (relatively) easy to just get stuff done.

Python has one of your 'zen' aspects - using Python has definitely 
expanded the way I think about programming. Powerful built-in support 
for lists and dicts, first-class functions and easy introspection enable 
a style of programming that is difficult or impossible in Java and C++.

But Python is not difficult to pick up - it is notably easy - and I 
don't think anyone claims it leads to computational satori - it's more 
an attitude of try it, you'll like it!. Using Python does seem to 
spoil people - I for one hate to code in Java now. Maybe bliss is a 
better word for it than satori.

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


Can optparse do dependencies?

2006-02-25 Thread Bob
I'd like to setup command line switches that are dependent on other
switches, similar to what rpm does listed below. From the grammar below
we see that the query-options are dependent on the query switch,
{-q|--query}. Can optparse do this or do I have to code my own
thing? Thanks.

QUERYING AND VERIFYING PACKAGES:
   rpm {-q|--query} [select-options] [query-options]
...
   query-options
[--changelog] [-c,--configfiles] [-d,--docfiles] [--dump]
[--filesbypkg] [-i,--info] [--last] [-l,--list]
[--provides] [--qf,--queryformat QUERYFMT]
[-R,--requires] [--scripts] [-s,--state]
[--triggers,--triggerscripts]

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


Re: Pure python implementation of string-like class

2006-02-25 Thread Akihiro KAYAMA
Hi bearophile.

In article [EMAIL PROTECTED],
[EMAIL PROTECTED] writes:

bearophileHUGS Maybe you can create your class using an array of 'L' with the 
array
bearophileHUGS standard module.

Thanks for your suggestion. I'm currently using an usual list as a
internal representation. According to my understanding, as compared to
list, array module offers efficiency but no convenient function to
implement various string methods. As Python's list is already enough
fast, I want to speed up my coding work first.

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


Re: Pure python implementation of string-like class

2006-02-25 Thread Akihiro KAYAMA
Hi And.

In article [EMAIL PROTECTED],
[EMAIL PROTECTED] writes:

and-google Akihiro KAYAMA wrote:
and-google  As the character set is wider than UTF-16(U+10), I can't use
and-google  Python's native unicode string class.
and-google 
and-google Have you tried using Python compiled in Wide Unicode mode
and-google (--enable-unicode=ucs4)? You get native UTF-32/UCS-4 strings then,
and-google which should be enough for most purposes.

From my quick survey, Python's Unicode support is restricted to
UTF-16 range(U+...U+10) intentionally, regardless of
--enable-unicode=ucs4 option. 

 Python 2.4.1 (#2, Sep  3 2005, 22:35:47) 
 [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
 Type help, copyright, credits or license for more information.
  u\U0010
 u'\U0010'
  len(u\U0010)
 1
  u\U0011
 UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 0-9: 
 illegal Unicode character

Simple patch to unicodeobject.c which disables unicode range checking
could solve this, but I don't want to maintenance specialized Python
binary for my project.

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


Re: Is Python a Zen language?

2006-02-25 Thread Twig
What is zen?

Is it something eatible (I'm hungry now)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a Zen language?

2006-02-25 Thread Twig
Kent Johnson wrote:
 
 Expanding on what Alex said :-)
*snip*
 
 Python is an excellent tool language, it is very pragmatic and powerful 
*snip*
 
 Kent

It's a good axe, Muddy waters said about his guitar when asked by some 
heavy-mega guitar hero.

Python is practical tool for practical problems. But if problem isn't 
practical, it is misdefined.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a Zen language?

2006-02-25 Thread Terry Reedy

John Coleman [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

an interesting statement and question.
...
 So (assuming my classification makes sense)  which is Python? The
 emphasis on simplicity and the beginner-friendly nature of it seems to
 put it in the tool category. On the other hand, the emphasis on the ONE
 TRUE WAY to accomplish most tasks and the tendency for participants in
 this newsgroup to criticize one another's code as being unpythonic
 seems to move it towards the Zen category.
,,,

An 'emphasis on the ONE TRUE WAY' would not be pythonic ;-)
Sorry you got that misimpression.

For the Zen of Python, type 'import this' at an interactive prompt.
One of the lines is

'There should be one-- and preferably only one --obvious way to do it.'

This is intentionally more nuanced, and practical, than your paraphrase.

I agree with the 'both' answer.

Terry Jan Reedy



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


Re: Is Python a Zen language?

2006-02-25 Thread Luis M. González
I don't know if python is Zend.
It's quite minimalistic and it flows very well, so I guess it is a...
Feng-shui language?

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


Re: A bit off topic, but good web hosting for PostgreSQL/Python?

2006-02-25 Thread Francisco Reyes
[EMAIL PROTECTED] writes:

 Seems like most web hosting providers support MySQL, but not
 PostgreSQL.

There are actually many.

Two that I personally have experience with:
http://hub.org
http://bizintegrators.com

They both support PostgreSQL.

Not sure on their python support, but I believe they likely already have it
or would do mod_python for you.

 Couldn't find a good PostgreSQL newsgroup so I thought I'd ask here.

The postgresql mailing lists are both active and very helpfull. Just check
the postgresql site for mailing list subscription info.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pure python implementation of string-like class

2006-02-25 Thread Ross Ridge

Steve Holden wrote:
 Wider than UTF-16 doesn't make sense.

It makes perfect sense.

  Ross
Ridge

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


Grabbing a object from the current code block using a callable statement?

2006-02-25 Thread ChaosKCW
Hi

Is it possible to grab get an object returned from a string and a
callable ? e.g

I pass in a key value pair:

def somemethod(adict = {'new name for object': 'code to reutrn
obejct'}):

object = .

for key, value in adict.items():
if callable(value):
somedict[key] = value()
else:
somedict[key] = value

such that

somedict  = {'new name for object': object} 

??

Thanks,

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


Re: Is Python a Zen language?

2006-02-25 Thread Bryan Olson
John Coleman wrote:
I have a rough classification of languages into 2 classes: Zen
 languages and tool languages. A tool language is a language that is,
 well, a *tool* for programming a computer. C is the prototypical tool
 language. Most languages in the Algol family are tool languages. Visual
 Basic and Java are also tool languages. On the other hand, a Zen
 language is a language which is purported to transform your way of
 thinking about programming. Lisp, Scheme, Forth, Smalltalk and (maybe)
 C++ are Zen languages.

I think that's a horrible classification. Every language is both.
Transform your way of thinking from what? There is no
distinguished canonical view of what a programming language looks
like, from which all others must be strange and wondrous
transformations.

Lisp and Forth are not tools for programming a computer? Of course
they are. Algol and Java don't transform people's thinking about
programming? Nonsense.


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


Re: python-list/python-dev quoting style

2006-02-25 Thread Michael Hoffman
Grant Edwards wrote:
 On 2006-02-25, Steve Holden [EMAIL PROTECTED] wrote:
[me]
It's hard to believe that you don't understand who me is in
a conversation between two people,

[me]
Is there really confusion about who me is? I find that
mystifying.

[Grant Edwards]
 And now none of us have any way to know who the [me] above is.

I see.
-- 
me
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK + Glade = weird problem

2006-02-25 Thread sapo
Finally solved this stuff, the problem wasnt with glade, the problem
was that i was using the destroy event in glade, i just changed the
destroy to delete-event and it worked like a charm.

thanx :)

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


Re: Path (graph) shower utility

2006-02-25 Thread Jorgen Grahn
On Wed, 22 Feb 2006 11:31:15 +0100, Durumdara [EMAIL PROTECTED] wrote:
 Hi !

 I need to create a program that read eml file headers, analyze the 
   
You mean email. Took me some time to figure out.

 receive tags and create a path database. I finished with this program 
  
You mean the Recieved: headers. Also took some time to figure out.

 section.

 But I want to show a graphical summary about the paths.

 This is (what I want to show) like a graph - show ways, stations, etc, 
 and I want to show the strength of lines (how many of mails use this way).

 Can anyone known about a freeware tool, software, or python module that 
 can show graphs with best alignments ?

Sure. You want graphviz:

  http://www.research.att.com/sw/tools/graphviz/

It's primarily a tool for rendering a graph (in Postscript, PNG etc) from a
text representation, but IIRC there are Python bindings for it as well. Lots
of people use it for purposes similar to yours.

/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org  R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Path (graph) shower utility

2006-02-25 Thread bearophileHUGS
Thank you Jorgen, now I understand the question, and the answer isn't
difficult :-)

Graphviz is good enough for this purpose.

but IIRC there are Python bindings for it as well.

Durumdara can use an email module to extract data, then a graph library
to create the graph, and then save the result in dot format for
Graphviz.
My Graph is probably enough:
http://sourceforge.net/projects/pynetwork/
Otherwise NetworkX is good:
https://networkx.lanl.gov/
There are other libs around, I have seen a new one quite recently.

Bye,
bearophile

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


Re: Is Python a Zen language?

2006-02-25 Thread Jorgen Grahn
On Sat, 25 Feb 2006 18:31:33 GMT, Bryan Olson [EMAIL PROTECTED] wrote:
...
 I think that's a horrible classification. Every language is both.

I agree; it's horrible as a classification.

But it's interesting concepts. One might use them to discuss the design of
various languages, and how the users treat them -- as long as one doesn't
get carried away.

Too bad Larry Wall doesn't post to this group.

/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org  R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a Zen language?

2006-02-25 Thread John Coleman

Bryan Olson wrote:
 John Coleman wrote:
 I have a rough classification of languages into 2 classes: Zen
  languages and tool languages. A tool language is a language that is,
  well, a *tool* for programming a computer. C is the prototypical tool
  language. Most languages in the Algol family are tool languages. Visual
  Basic and Java are also tool languages. On the other hand, a Zen
  language is a language which is purported to transform your way of
  thinking about programming. Lisp, Scheme, Forth, Smalltalk and (maybe)
  C++ are Zen languages.

 I think that's a horrible classification. Every language is both.
 Transform your way of thinking from what? There is no
 distinguished canonical view of what a programming language looks
 like, from which all others must be strange and wondrous
 transformations.

 Lisp and Forth are not tools for programming a computer? Of course
 they are. Algol and Java don't transform people's thinking about
 programming? Nonsense.


 --
 --Bryan

You seem to have completly overlooked both the hedge word rough in my
first sentence and the qualifications in my third paragraph. I probably
was not sufficiently clear that I was describing some fairly sunjective
impressions.  It is a simple observation that devotees of the Scheme
language view their language as more than *just* a tool for programming
computers. To quote from the introduction to the first edition of SICP:

we want to establish the idea that a computer language is not just a
way of getting a computer to perform operations but rather that it is a
novel formal medium for expressing ideas about methodology
(http://mitpress.mit.edu/sicp/full-text/book/book.html).
It is also a simple observation that experts in VBScript *don't* walk
around talking like that. Scheme and VBScript are of course both Turing
complete, but they seem to have radically different cultures. Do you
disagree? Or, if you agree that there is a difference but don't like
the words Zen vs. tool to describe it, how would you articulate the
difference?

Again, just curious.

-John Coleman

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


Re: spaces at ends of filenames or directory names on Win32

2006-02-25 Thread drobinow
For example... tell windows to move a file named ' XXX ' (one space
before and one space after the filename). Windows will complain that
file 'XXX' does not exist. It's correct of course, 'XXX' does not
exist,
but ' XXX ' does indeed exist.

Can anyone rescue me from this madness :(
-
 Please post your Python code.  I don't see the problem you're
describing.

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


Re: remote module importing (urlimport)

2006-02-25 Thread EP
ajones wrote:

What plans do you have for security in this? I would think that in
order to trust this over the network you would at least need a
certificate identifying the server as well as some method of verifying
package contents.

Either way, cool stuff.

  

I think this is an interesting project.

What if every module could be registered (at Python.org, for example) 
with a unique URI, a hash digest, and optionally a list of one or more 
source code sources (URLs)?  Each module registered would have to have a 
unique name, but that is probably a good thing anyway.

Then before loading a module the urlimport code could query something like

http://Python.org/cheeseshop/moduleNS/%s; %moduleName

 From whence would be returned a short text file, something like:

ThisModuleName
HashNumber
[http://source1/ThisModuleName.txt;, 
http://source2/funnydirectory/structure/ThisModuleName.txt;...]

urlimport could then query the sources given, or any other known 
repositories, until it found a module of matching digest.


What if you needed to use a certain version of a module for 
compatibility?  Then would module names like ThisModuleName_2.71 
become necessary?

I wonder if the ripples of setting something like this up offend 
Pythonic thinking... and if the utility of having this sort of 
functionality would be worth risking some offense.

I guess this stuff has all been done before and Python has good reasons 
for not pursuing it, but I wonder what those reasons are.


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


Editable lists in pygtk - Editing wrong cell

2006-02-25 Thread sapo
Hi all, i m trying to make an editable list with a toggle button, it
shows up and i can edit the list.. but its editing the wrong cell!

If i click on the toggle button on the first cell it sets FALSE on the
last cell of that row, if i change the text of the last cell if changes
another cell text... here is my code:

tree = self.principal.get_widget(file_list)
list = gtk.ListStore(str, str)
#Permite selecionar os arquivos
toggle = gtk.CellRendererToggle()
toggle.set_property('activatable', True)
tree.insert_column_with_attributes(-1, Convert?, toggle)
toggle.connect('toggled', self.Select, tree)
#permite editar a lista
renderer = gtk.CellRendererText()
renderer.set_property( 'editable', True )
renderer.connect('edited', self.Edit, list)
tree.insert_column_with_attributes(-1, Artist, renderer, text=0)
tree.insert_column_with_attributes(-1, Song, renderer, text=1)
tree.set_model(list)

  def Select(self,cell,path,model):
model[path][1] = not model[path][1]
return
  def Edit(self, cell, path, new_text, model):
model[path][0] = new_text

What's wrong with it? i m following this example:
http://pygtk.org/pygtk2tutorial/sec-CellRenderers.html#EditableTextCells

thanx in advance

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


Re: Can optparse do dependencies?

2006-02-25 Thread Raymond Hettinger
[Bob]
 I'd like to setup command line switches that are dependent on other
 switches, similar to what rpm does listed below. From the grammar below
 we see that the query-options are dependent on the query switch,
 {-q|--query}. Can optparse do this or do I have to code my own
 thing? Thanks.

 QUERYING AND VERIFYING PACKAGES:
rpm {-q|--query} [select-options] [query-options]
 ...
query-options
 [--changelog] [-c,--configfiles] [-d,--docfiles] [--dump]
 [--filesbypkg] [-i,--info] [--last] [-l,--list]
 [--provides] [--qf,--queryformat QUERYFMT]
 [-R,--requires] [--scripts] [-s,--state]
 [--triggers,--triggerscripts]

The optparse module doesn't have native support for switch
dependencies; however, it could likely be done with multiple passes.
The parse_args() takes an args list as an argument.  Make first pass
that captures your main query switches, then run another parser on a
slice of the args list.

For example, capture the main switches on a first pass over the full
argument list (catching all possible main switches and treating
everything else as a catchall).  Given, args=['-ql', '--changelog',
'-d', '-c'], parse out the --changelog and then call another parser
with args=['-d', '-c'].

This functionality seems useful enough to build into the tool directly,
so do consider putting a feature request on SourceForge (and assign to
Greg Ward).


Raymond

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


Re: Optimize flag question

2006-02-25 Thread Raymond Hettinger
[Olivier Langlois]
  So my question is: what are the 'optimizations' that the Python
  interpreter is doing when you specify the optimize flag and is there
  anything I should be cautious about when using it?

Currently, -O provides no optimizations other than eliminating
assertions.


Raymond

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


Re: Pure python implementation of string-like class

2006-02-25 Thread Ross Ridge
Steve Holden wrote:
Wider than UTF-16 doesn't make sense.

Ross Ridge wrote
 It makes perfect sense.

Alan Kennedy wrote:
 UTF-16 is a Unicode Transcription Format, meaning that it is a
 mechanism for representing all unicode code points, even the ones with
 ordinals greater than 0x, using series of 16-bit values.

It's an encoding format that only supports encoding 1,112,064 different
characters making it a little more than 20-bits wide.   While this
enough to encode all code points currently assigned by Unicode, it's
not sufficient to encode the private use area of ISO 10646-1 that
Akihiro Kayama wants to use.

   Ross Ridge

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


Re: Grabbing a object from the current code block using a callable statement?

2006-02-25 Thread Larry Bates
ChaosKCW wrote:
 Hi
 
 Is it possible to grab get an object returned from a string and a
 callable ? e.g
 
 I pass in a key value pair:
 
 def somemethod(adict = {'new name for object': 'code to reutrn
 obejct'}):
 
 object = .
 
 for key, value in adict.items():
 if callable(value):
 somedict[key] = value()
 else:
 somedict[key] = value
 
 such that
 
 somedict  = {'new name for object': object} 
 
 ??
 
 Thanks,
 

If you are asking if an object instance can be stored in a dictionary
the answer is yes.

example:

 class foo:
... def method(self):
... print in foo.method
... return
... 
 adict={'fooclass': foo()}
 adict['fooclass'].method()
in foo.method


Instances of classes are just like any other data you might put into
a list or a dictionary.  I hope that is what you were asking.

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


Re: Is Python a Zen language?

2006-02-25 Thread Kay Schluehr

John Coleman wrote:
 Ron Stephens wrote:
  Actually, Python has the distinction of being both a great tool
  language *and* a great Zen language. That's what makes Python so cool
  ;-)))
 
  Ron Stephens
  Python411
  www.awaretek.com/python/index.html

 This would explain why the question is so hard to answer. It is a
 slam-dunk that Lisp is Zen and VBA is tool - but python really is a bit
 hard to classify. This is somewhat similar to the way that python seems
 to straddle the gap between imperative and functional languages. It has
 something from each worlds (whether it has the *best* from each world
 is a separate question)

 -John Coleman

There is something that worries me about Lisp. If you are interested in
the history of Lisp and some non-technical aspects of its culture I can
recommend the writings of Richard Gabriel, who was one of the leaders
of the CL standardisation commitee and founder of the Lisp company
Lucid in the mid 80s that gone down a few years later. As it turned out
that time Lisp was not capable to survive in what we call today a
heterogenous environment. It was strongly too self-centered. So I
would actually invert you categories and say that a good tool achieves
to have a non-dual nature instead of a strong I. With Lisp you might be
a god but according to the Zen philosophy a god is a subordinated
character that preserves the illusion of self-identity. A fine thing
about a tool in this context is that you have to define its identity by
a relationship to something that it is not.

I have at times the impression that many people who talk about Zen
philosophy confuse it with some home brewn mixture of platonism with
its transgressive move towards the true reality, a stoic hedonism of
contemplation and the taoistic being-in-doing. Zen on the other side is
more radical: if you erase yourself there is no-one who is in the
flow but chances are that you and the computer over there are the same
thing.

Kay

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


Re: Concantenation and string slicing

2006-02-25 Thread Larry Bates
Dennis Lee Bieber wrote:
 On Thu, 23 Feb 2006 18:06:46 -0600, Larry Bates
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:
 
 
 Better was is:

 message = raw_input(Enter a message:  )
 print message[::-1]

 
   I sometimes get the feeling a lot of responses to newbies, lately,
 fail to explain what was wrong in the original code in favor of showing
 off the tricks that Python is capable of...

Several others had already pointed out what was wrong (which
of course the OP would have know if he had done a tutorial).
I merely wanted to post a solution that IMHO was a much
better way to accomplish the task.  The OP is free to choose
among the posted solutions.  If others had not yet posted the
solution, I would have posted both.

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


Re: Optimize flag question

2006-02-25 Thread Steve Holden
[copied to python-list]

Olivier Langlois wrote:
 Hi Steve!
 
Could you outline the code that needs to be in to make the program
 
 work,
 
so we can assess the errors for ourselves?

 
 
 There is nothing unfixable. There are some instances where the code is
 checking a function return value like:
 
 assert(Somefunc())
 
 which could fix with
 
 res = Somefunc()
 assert(res)
 
So what you are saying is that Somefunc() needs to be executed, 
presumably because it has side-effects?

Yes, it would be much better to recast it, but ...

 Some other functions rely on the AssertionError exception to indicate to
 the user that something went wrong instead of using a user defined
 exception.
 

The real problem here is that you appear to be using AssertionError in 
an inappropriate way. If some caller passes an incorrect argument to 
your function, raise a ValueError. If you are passed the wrong type of 
data, raise a TypeError. And so on. Or, as you imply you thought about, 
raise a user-defined error.

Generally speaking you should reserve assert for circumstances where you 
expect some invariant condition to be true. Otherwise use an if 
statement and raise some other exception if the condition is True.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: spaces at ends of filenames or directory names on Win32

2006-02-25 Thread Larry Bates
Jeffrey Schwab wrote:
 Larry Bates wrote:
 
 IMHO leading and/or trailing spaces in filenames is asking for
 incompatibilities with cross-platform file access.
 
 With what platforms specifically?
 
 Much like
 using single-quote in filenames which are perfectly legal in
 DOS/Windows, but Linux doesn't like much.
 
 Uh...  What Linux are you using?  And what FS?
 
 $ touch '  ls
 '
 $ rm '
 $

I stand corrected if you put double quotes around filenames
it does work.  That to me means that single quotes
in filenames are somehow different than other characters.
You must handle these filenames differently (at least from
the command line).  Thanks for pointing this out.

-Larry Bates

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


Re: spaces at ends of filenames or directory names on Win32

2006-02-25 Thread Larry Bates
Steven D'Aprano wrote:
 On Thu, 23 Feb 2006 17:49:31 -0600, Larry Bates wrote:
 
 Steven D'Aprano wrote:
 On Thu, 23 Feb 2006 14:30:22 -0600, Larry Bates wrote:

 How about not naming files with leading and trailing spaces on
 the Mac?  Seems like a bad habit that needs breaking ;-).
 Why is it a bad habit? Because *Windows* is primitive enough that it can't
 cope with leading and trailing spaces? I don't see why Windows' lack is
 Mac users' problem.


 It is a problem because the poster says it is a problem for him.
 
 Absolutely.
 
 Now read my statement again. Why is it a problem for the Mac _users_?
 
 I use Linux, Windows and Mac, in varying amounts. I'm fully aware of the
 problems of transferring files from one platform to another. When it
 affects _me_, I may choose to dumb down to the lowest common denominator
 so as to save _me_ problems. But wearing my user hat, if a developer came
 to me telling me I had to avoid using features on my platform of choice in
 order to make his life easier, I'd say to him So why exactly are we
 paying you the big bucks? That's your problem, you solve it.
 
 
 
I understand you completely, but its a problem for the Mac users because
their company needs to do something with their files that is making it
hard.  I see no difference than if some user chose to use some obscure
spreadsheet or wordprocessing program that works extremely well for them
but is completely incompatible with all other users in the organization.
Why is it their problem?  Because it makes it difficult for others to
work with their data.  I don't believe for a minute you would tell them
It is ok to keep using your wordprocessing software, if we can't read
the files that's our problem, we will write something to convert them
to a more usable format.  It will only take about 500/1000/2000 hours
to fix for you Mr. _user_.

Funny how we got here.  I just made a suggestion as to how the user can
make the problem go away altogether and my suggestion that it was a bad
habit did have a smiley ;-) as you will note.

-Larry Bates


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


Re: Is Python a Zen language?

2006-02-25 Thread none
John Coleman wrote:
 Bryan Olson wrote:
 
John Coleman wrote:

   I have a rough classification of languages into 2 classes: Zen
languages and tool languages. A tool language is a language that is,
well, a *tool* for programming a computer. C is the prototypical tool
language. Most languages in the Algol family are tool languages. Visual
Basic and Java are also tool languages. On the other hand, a Zen
language is a language which is purported to transform your way of
thinking about programming. Lisp, Scheme, Forth, Smalltalk and (maybe)
C++ are Zen languages.

I think that's a horrible classification. Every language is both.
Transform your way of thinking from what? There is no
distinguished canonical view of what a programming language looks
like, from which all others must be strange and wondrous
transformations.

Lisp and Forth are not tools for programming a computer? Of course
they are. Algol and Java don't transform people's thinking about
programming? Nonsense.


--
--Bryan
 
 
 You seem to have completly overlooked both the hedge word rough in my
 first sentence and the qualifications in my third paragraph. I probably
 was not sufficiently clear that I was describing some fairly sunjective
 impressions.  It is a simple observation that devotees of the Scheme
 language view their language as more than *just* a tool for programming
 computers. To quote from the introduction to the first edition of SICP:
 
 we want to establish the idea that a computer language is not just a
 way of getting a computer to perform operations but rather that it is a
 novel formal medium for expressing ideas about methodology
 (http://mitpress.mit.edu/sicp/full-text/book/book.html).
 It is also a simple observation that experts in VBScript *don't* walk
 around talking like that. Scheme and VBScript are of course both Turing
 complete, but they seem to have radically different cultures. Do you
 disagree? Or, if you agree that there is a difference but don't like
 the words Zen vs. tool to describe it, how would you articulate the
 difference?
 
 Again, just curious.

It's a metter of perspective.  Python didn't change my thinking about 
programming.  Smalltalk changed my way of thinking about programming 
very radically.  All Python changed my thinking about was how to better 
program in Python.  Python to me just happened to be a very pragmmatic 
and productive tool for getting the job done.  It happens to be 
comfrotable because large parts of it already fit into my way of 
thinking from long use in Smalltalk, but my description of Pythong would 
be 'cleanly practical' not 'zen'
-- 
http://mail.python.org/mailman/listinfo/python-list


looking for a simpe plotting module

2006-02-25 Thread MARK LEEDS



i'm pretty much 
a python beginner so can anyone recommend a plooting package in python ( simple 
foating numbers that makes lines or dots with a yaxis and an an 
xaxis.i don't need fancy drawings ) that is a built in module in 
python ? i am using python 2.4 in linux if that matters. 
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-25 Thread Paul Rubin
Kay Schluehr [EMAIL PROTECTED] writes:
 I have at times the impression that many people who talk about Zen
 philosophy confuse it with some home brewn mixture of platonism with
 its transgressive move towards the true reality, a stoic hedonism of
 contemplation and the taoistic being-in-doing. Zen on the other side is
 more radical: if you erase yourself there is no-one who is in the
 flow but chances are that you and the computer over there are the same
 thing.

QOTW or something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a simpe plotting module

2006-02-25 Thread Henrique Ferreiro
matplotlib is an excellent library which uses the syntax of matlab
plots.

http://matplotlib.sourceforge.net

O Sáb, 25-02-2006 ás 15:01 -0800, MARK LEEDS escribiu:
 i'm pretty much a python beginner so can anyone recommend a plooting
 package in python ( simple foating  numbers 
 that makes lines or dots with a yaxis and an an xaxis. i don't need
 fancy drawings ) that is a built in module 
 in python ?  i am using python 2.4 in linux if that matters. thanks.
 
 
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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

Re: How to send an email with non-ascii characters in Python

2006-02-25 Thread Gabriel B.
2006/2/25, Sybren Stuvel [EMAIL PROTECTED]:
 Lad enlightened us with:
  Body='Rídících Márinka a Školák Kája
  Marík'.decode('utf8').encode('windows-1250')# I use the text written
  in my editor with utf-8 coding, so first I decode and then encode to
  windows-1250

what does a string became when it's decoded?

I mean, it must be encoded in something, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Modify the local scope inside a function

2006-02-25 Thread Sandra-24
Is there a way in python to add the items of a dictionary to the local
function scope? i.e. var_foo = dict['var_foo']. I don't know how many
items are in this dictionary, or what they are until runtime.

exec statements are difficult for debuggers to deal with, so as a
workaround I built my code into a function and saved it in a .py file.
The I load the .py file as a module and call the function instead. This
works great, and it has the added advantage of precompiled versions of
the code being saved as .pyc and .pyo files. (faster repeated
execution)

The only trouble was I execed inside a specially created scope
dictionary containing various variables and functions that the code
requires. I can't seem to figure out how to get this same effect inside
the function. Right now I'm passing the dict as an argument to the
function, but I can't modify locals() so it doesn't help me.

Thanks,
-Sandra

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


Re: Can optparse do dependencies?

2006-02-25 Thread Giovanni Bajo
Raymond Hettinger wrote:

 I'd like to setup command line switches that are dependent on other
 switches, similar to what rpm does listed below. From the grammar
 below we see that the query-options are dependent on the query
 switch, {-q|--query}. Can optparse do this or do I have to code my
 own thing? Thanks.

 QUERYING AND VERIFYING PACKAGES:
rpm {-q|--query} [select-options] [query-options]
 ...
query-options
 [--changelog] [-c,--configfiles] [-d,--docfiles] [--dump]
 [--filesbypkg] [-i,--info] [--last] [-l,--list]
 [--provides] [--qf,--queryformat QUERYFMT]
 [-R,--requires] [--scripts] [-s,--state]
 [--triggers,--triggerscripts]

 The optparse module doesn't have native support for switch
 dependencies; however, it could likely be done with multiple passes.
 The parse_args() takes an args list as an argument.  Make first pass
 that captures your main query switches, then run another parser on a
 slice of the args list.

 For example, capture the main switches on a first pass over the full
 argument list (catching all possible main switches and treating
 everything else as a catchall).  Given, args=['-ql', '--changelog',
 '-d', '-c'], parse out the --changelog and then call another parser
 with args=['-d', '-c'].

 This functionality seems useful enough to build into the tool
 directly, so do consider putting a feature request on SourceForge
 (and assign to Greg Ward).

In fact, if we were to request an addition to optparse in this direction, I
think it should add standardized support for the subcommand pattern, that is
the same command line arrangement that CVS, SVN and other programs uses. rpm
doesn't use it and I consider this an error in UI design (it should really have
been rpm query --changelog and similar).
-- 
Giovanni Bajo


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


Re: Pure python implementation of string-like class

2006-02-25 Thread Xavier Morel
Akihiro KAYAMA wrote:
 Sorry for my terrible English. I am living in Japan, and we have a
 large number of characters called Kanji. UTF-16(U+...U+10) is
 enough for practical use in this country also, but for academic
 purpose, I need a large codespace over 20-bits. I wish I could use
 unicode's private space (U+6000...U+7FFF) in Python.
 
 -- kayama

I think the Kanji are part of the Han script as far as Unicode is 
concerned, you should check it (CJK unified ideograms and CJK unified 
ideograms extension A), they may not all be there, but the 27502 
characters from these two tables should be enough for most uses.

Oh, by the way, the Unicode code space only goes up to 10, while 
UCS-4's encoding allows code values up to and including 7FFF the 
upper Unicode private space is Plane Sixteen (10–10), the other 
private spaces being a part of the Basic Multilingual Plane 
(U+E000–U+F8FF) and Plane Fifteen (U+F–U+F) and even UTF-32 
doesn't go beyond 10.

Since the Dai Kan-Wa jiten only lists about 50,000 kanji (even though 
it probably isn't perfectly complete) it fits with ease in both plane 
fifteen and sixteen (65535 code points each).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pure python implementation of string-like class

2006-02-25 Thread Xavier Morel
Ross Ridge wrote:
 Steve Holden wrote:
 Wider than UTF-16 doesn't make sense.
 
 It makes perfect sense.
 
   Ross
 Ridge
 

Not if you're still within Unicode / Universal Character Set code space. 
While UCS-4 technically goes beyond any Unicode Transformation Format 
(UTF-7, 8, 16 and 32 stop at 10) it also goes beyond the range of 
the UCS itself (0-10). UTF-32 is the limitation of UCS-4 to the 
Unicode standard.

While it could be argued that Unicode/UCS limit of 10 was chosen 
_because_ of the limitations of UTF-16, It's probably irrelevant to the 
discussion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: groupwise send mail

2006-02-25 Thread Max M
[EMAIL PROTECTED] wrote:
 Can someone give me an idea as to why this is not working?  The
 Recipients.Add line doesnt cause an error, but my recipients arent
 being used.  The email never gets sent because there is no recipeients.
 
 Thanks,
 Eric
 
 
 import win32com.client
 gwApp = win32com.client.Dispatch('NovellGroupWareSession')
 acct1 = gwApp.Login(NDS:\\Tree_Name,user.context, )
 oMail = acct1.MailBox.Messages.Add (GW.Message.Mail, Draft)
 oMail.fromtext = Python Hazmat Script
 oMail.Recipients.Add([EMAIL PROTECTED])
 oMail.Subject.PlainText = Script error
 oMail.BodyText.PlainText = The Python Hazmat script failed
 oMail.send
 gwApp.quit
 

Methods must allways have a () in Python to be called

  oMail.send()
  gwApp.quit()


Otherwise you are just adressing the objects

eg. this is perfectly ok:

send = oMail.send
send()

or

q = gwApp.quit
q()

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spaces at ends of filenames or directory names on Win32

2006-02-25 Thread Jeffrey Schwab
Larry Bates wrote:
 Jeffrey Schwab wrote:
 
Larry Bates wrote:


IMHO leading and/or trailing spaces in filenames is asking for
incompatibilities with cross-platform file access.

With what platforms specifically?


Much like
using single-quote in filenames which are perfectly legal in
DOS/Windows, but Linux doesn't like much.

Uh...  What Linux are you using?  And what FS?

$ touch '  ls
'
$ rm '
$
 
 
 I stand corrected if you put double quotes around filenames
 it does work.  That to me means that single quotes
 in filenames are somehow different than other characters.
 You must handle these filenames differently (at least from
 the command line).  Thanks for pointing this out.

Sure, no problem.  FYI, the quotes are to keep my shell, which happens 
to be bash, from trying to interpret the quote.  If I were renaming a 
file by clicking the icon in a Windows-like GUI, or using a file 
manager, there would be no need for the quote.
-- 
http://mail.python.org/mailman/listinfo/python-list


xslt queries in xml to SQL queries

2006-02-25 Thread Ian Roddis

Hello,

  I want to embed SQL type queries within an XML data record. The XML
looks something like this:
DISPLAYPAGE
FIELD NAME=SERVER TYPE=DROPDOWN
OPTION1OPTION
OPTION2OPTION
OPTION3OPTION
/FIELD
/DISPLAYPAGE

  I want to populate the drop down options from a database. The table
looks like this (example):
CREATE TABLE options_table (
id  int primary key,
namevarchar(255),
field   varchar(255)
)


  I read an article that would allow me to embed an SQL query using XSLT
like this (in place of OPTIONS):
xslt:template match=options_table[field='SERVER']
OPTIONxslt:value-of select=name/text()//OPTION
/xslt:template

  Which would be equivalent of:

SELECT name FROM options_table WHERE field='SERVER';

  Does anyone else have experience of describing SQL queries in XML or
parsing XSLT in python?
-- 
To mail remove REMOVEME. from address.

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


Re: Pure python implementation of string-like class

2006-02-25 Thread Ross Ridge

Xavier Morel wrote:
 Not if you're still within Unicode / Universal Character Set code space.

Akihiro Kayama in his original post made it clear that he wanted to use
a character set larger than entire Unicode code space.

  Ross Ridge

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


ImportError in Unpickle

2006-02-25 Thread [EMAIL PROTECTED]
Hi,

I have a python script that pickles and unpickles a give object. It
works without any problems on windows (the data was pickled on windows
first). But when I try to run the script on Linux, I get the following
error:

mydbinfo = pickle.Unpickler(f).load()
  File /usr/lib/python2.3/pickle.py, line 872, in load
dispatch[key](self)
  File /usr/lib/python2.3/pickle.py, line 1083, in load_inst
klass = self.find_class(module, name)
  File /usr/lib/python2.3/pickle.py, line 1138, in find_class
__import__(module)
ImportError: No module named __main__

Even running the script with cygwin's python results in same error. It
looks me to be some problem with path setting for finding modules. Can
someone shed more light?

Thanks in advance,
Raghu.

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


Re: Optimize flag question

2006-02-25 Thread bonono

Steve Holden wrote:
  Some other functions rely on the AssertionError exception to indicate to
  the user that something went wrong instead of using a user defined
  exception.
 

 The real problem here is that you appear to be using AssertionError in
 an inappropriate way. If some caller passes an incorrect argument to
 your function, raise a ValueError. If you are passed the wrong type of
 data, raise a TypeError. And so on. Or, as you imply you thought about,
 raise a user-defined error.

 Generally speaking you should reserve assert for circumstances where you
 expect some invariant condition to be true. Otherwise use an if
 statement and raise some other exception if the condition is True.

What would be the occasion that AssertionError be the right exception
to raise then ?

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


How to Mount/Unmount Drives on Windows?

2006-02-25 Thread dpickles
Hello,

I am creating a simple application that will reside in the Windows
system tray. The purpose of the program is to mount or unmount external
hard drives or flash memory devices, and to set their default states
(ie mounted or unmounted) at startup.

I do not know how to mount or unmount drives on Windows. I think that
it could possibly be done with a DOS command (using os.system()).

Thank you for any information you may have.

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


Pythonic exceptionalism (was: A C-like if statement)

2006-02-25 Thread Cameron Laird
In article [EMAIL PROTECTED],
Steven D'Aprano  [EMAIL PROTECTED] wrote:
On Thu, 23 Feb 2006 12:04:38 -0700, Bob Greschke wrote:

 try:
i = a.find(3)
print It's here: , i
 except NotFound:
print No 3's here
 
 Nuts.  I guess you're right.  It wouldn't be proper.  Things are added or 
 proposed every day for Python that I can't even pronounce, but a simple 'if 
 (I = a.find(3)) != -1' isn't allowed.  Huh.  It might be time to go back 
 to BASIC. :)

There are *reasons* why Python discourages functions with side-effects.
Side-effects make your code hard to test and harder to debug.

 I think your way would work if .find() were replaced with .index().  I'm 
 just trying to clean up an if/elif tree a bit, so using try would make 
 things bigger.

Then write a function! Instead of calling the try..except block in every
branch directly, pull it out into a function:

def test(s,what):
try:
i = s.index(what)
print It's here: , i
except ValueError:
print No 3's here
.
.
.
A recent piece by Collin Park URL:
http://www.linuxjournal.com/article/8794 
illustrates how a user-defined exception
arises so naturally in a tiny toy example
that it occurs to a teenager first program-
ming.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Mount/Unmount Drives on Windows?

2006-02-25 Thread shearichard
This looks like it might help you ...

http://support.microsoft.com/?kbid=311272

...  although the blurb does say DevCon is not redistributable. It is
provided for use as a debugging and development tool.

There is an article about it at ...

http://tinyurl.com/4kb8m

regards

richard.

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


Re: Temporary Variable

2006-02-25 Thread Steven D'Aprano
On Fri, 24 Feb 2006 14:08:22 -0800, darthbob88 wrote:

 Reply to all: I realize that naming a variable spam is not entirely
 kosherized. It was originally named secret, but I renamed it in a fit
 of whimsy. The language is named after Monty Python's Flying Circus, is
 it not? Remember the Spam Sketch.
 http://en.wikipedia.org/wiki/Spam_sketch

Absolutely!

And it is a fine thing to use Monty Python references as generic variables
in Python, instead of foo, bar, baz and so forth. 

All up, I'm surprised at the fuss made over a throw-away line.

 I thank you for finding the problem; I thought it might involve string
 v int comparisons when Comrade D'Eprano's code went wonky. 

My code went wonky?

 Many thanks, and good luck to you.
 PS: As for the inappropriate naming, the Swedes tried to sell their
 vacuums under the motto Nothing sucks like an Electrolux.

Which is a wonderful, deliberately ironic advertising line. I love it!!!


-- 
Steven.

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


Re: Temporary Variable

2006-02-25 Thread Terry Hancock
On 24 Feb 2006 14:08:22 -0800
[EMAIL PROTECTED] wrote:
 Reply to all: I realize that naming a variable spam is
 not entirely kosherized.

In fact this is untrue:  It is an official rule straight
from the BDFL himself that example programs should contain
words like spam, ham, eggs from the spam sketch. 
Other Monty Python sketch variables are acceptable as well.

This in contrast to longstanding programmer practice to use
the names foo and bar etc.

Ironically, in introducing Python 2.5 features in his key
note, he consistently used foo and bar himself.

My faith is so shaken. ;-)

Cheers,
Terry Hancock

 -- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Re: Optimize flag question

2006-02-25 Thread Steven D'Aprano
On Sat, 25 Feb 2006 17:56:42 -0800, bonono wrote:

 
 Steve Holden wrote:
  Some other functions rely on the AssertionError exception to indicate to
  the user that something went wrong instead of using a user defined
  exception.
 

 The real problem here is that you appear to be using AssertionError in
 an inappropriate way. If some caller passes an incorrect argument to
 your function, raise a ValueError. If you are passed the wrong type of
 data, raise a TypeError. And so on. Or, as you imply you thought about,
 raise a user-defined error.

 Generally speaking you should reserve assert for circumstances where you
 expect some invariant condition to be true. Otherwise use an if
 statement and raise some other exception if the condition is True.

 What would be the occasion that AssertionError be the right exception
 to raise then ?

Surely that would be when an assert statement fails?

I don't think AssertionError should be called by hand. At least, I
wouldn't do so.


-- 
Steven.

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


Re: Is Python a Zen language?

2006-02-25 Thread Steven D'Aprano
On Sat, 25 Feb 2006 06:09:16 -0800, John Coleman wrote:

 Greetings,
I have a rough classification of languages into 2 classes: Zen
 languages and tool languages. A tool language is a language that is,
 well, a *tool* for programming a computer. C is the prototypical tool
 language. Most languages in the Algol family are tool languages. Visual
 Basic and Java are also tool languages. On the other hand, a Zen
 language is a language which is purported to transform your way of
 thinking about programming. Lisp, Scheme, Forth, Smalltalk and (maybe)
 C++ are Zen languages. Disciples acknowledge that it is difficult to
 pick up these languages but claim that, if you persevere, you sooner or
 later reach a state of computational satori in which it all makes
 sense. Interestingly enough, these languages often have books which
 approach scriptural status  e.g. SICP for Scheme.
 
 So (assuming my classification makes sense)  which is Python?

Why can't it be both? Why do you think Zen and tool are two different
*kinds* of language, rather than just two extremes of a single continuum?

There are two kinds of people: those who divide the world into false
dichotomies, and those who don't. *wink*


 This is probably because I am not a programmer (I'm a mathematician who
 likes to program as a hobby and for numerical simulations) and so don't
 have the time to invest in picking up a Zen language. Hard-core hackers
 might presumably lean towards the Zen languages.

Regardless of whether Python is a Zen or tool language, or both, or
something else, it is incredibly easy to pick up. Just remember, and this
goes for *any* new language you are trying to learn, Python is not
C/Java/VB/Fortran/Lisp/Ada/whatever language you already know.



-- 
Steven.

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


Re: How to send an email with non-ascii characters in Python

2006-02-25 Thread Kent Johnson
Gabriel B. wrote:
 what does a string became when it's decoded?
 
 I mean, it must be encoded in something, right?

Unicode, for encodings like latin-1 or utf-8. A few special cases like 
str.decode('string_escape') yield byte strings again.

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


Re: Modify the local scope inside a function

2006-02-25 Thread Crutcher
Here you go. Unfortunate that you can't modify locals() easily, but
there are other options.

def foo(d):
  for k in d:
exec '%s = %s' % (k, repr(d[k]))
  print a + b

foo({'a':1, 'b':2})

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


Re: Is Python a Zen language?

2006-02-25 Thread The Eternal Squire

Kay Schluehr wrote:
 John Coleman wrote:
  Ron Stephens wrote:
   Actually, Python has the distinction of being both a great tool
   language *and* a great Zen language. That's what makes Python so cool
   ;-)))
  
   Ron Stephens
   Python411
   www.awaretek.com/python/index.html
 
  This would explain why the question is so hard to answer. It is a
  slam-dunk that Lisp is Zen and VBA is tool - but python really is a bit
  hard to classify. This is somewhat similar to the way that python seems
  to straddle the gap between imperative and functional languages. It has
  something from each worlds (whether it has the *best* from each world
  is a separate question)
 
  -John Coleman

 There is something that worries me about Lisp. If you are interested in
 the history of Lisp and some non-technical aspects of its culture I can
 recommend the writings of Richard Gabriel, who was one of the leaders
 of the CL standardisation commitee and founder of the Lisp company
 Lucid in the mid 80s that gone down a few years later. As it turned out
 that time Lisp was not capable to survive in what we call today a
 heterogenous environment. It was strongly too self-centered. So I
 would actually invert you categories and say that a good tool achieves
 to have a non-dual nature instead of a strong I. With Lisp you might be
 a god but according to the Zen philosophy a god is a subordinated
 character that preserves the illusion of self-identity. A fine thing
 about a tool in this context is that you have to define its identity by
 a relationship to something that it is not.

 I have at times the impression that many people who talk about Zen
 philosophy confuse it with some home brewn mixture of platonism with
 its transgressive move towards the true reality, a stoic hedonism of
 contemplation and the taoistic being-in-doing. Zen on the other side is
 more radical: if you erase yourself there is no-one who is in the
 flow but chances are that you and the computer over there are the same
 thing.

 Kay

Too right.  If programming language was Zen there would be no
keyboards, just a telepathic interface.

But I have to admit I enjoy a solidly platonic relationship with
Python.  I prefer to
write things in the most beautiful way rather than in the most
efficient.  Its cost me a couple jobs, but the integrity of the product
always remains intact.

The Eternal Squire

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


Looking a device up in the Running Object Table

2006-02-25 Thread Lunchtimemama
I'm looking to disable Windows autoplay for a particular device.
There's a registry key
(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\CancelAutoplay\CLSID)
that will turn off autoplay for listed devices, but one must provide
the device's CLSID as it appears in the ROT.

I use the wmi module (http://tgolden.sc.sabren.com/python/wmi.html) to
discover the device's GUID, but I don't know enough about COM to look
it up in the ROT. Is there a difference between the GUID and the CLSID
in the ROT, or am I just not using the registry correctly?

Thanks.

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


Re: Modify the local scope inside a function

2006-02-25 Thread Jason Mobarak
Sandra-24 wrote:
 Is there a way in python to add the items of a dictionary to the local
 function scope? i.e. var_foo = dict['var_foo']. I don't know how many
 items are in this dictionary, or what they are until runtime.

Why do you want to do this?  Exec and eval should -not- be used for
this unless you are specifically creating a system allows arbitrary
code execution.  What's wrong with using a dictionary?  It's much safer
than allowing arbitrary names to be injected into a namespace.

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


  1   2   >