Re: Less APIs or more encapsulation?

2009-09-10 Thread Bruno Desthuilliers

Tycho Andersen a écrit :

On Wed, Sep 9, 2009 at 10:08 AM, 一首诗 wrote:

But when C has many many methods to expose to outer user, 2nd choice
seems to be more reasonable I In the first design, B.newMethod did
nothing really useful.


Is there any reason you can't do something like the following?

class B(object):
  def __init__(self, c):
self.__c = c;


There are very few real use case for the name-mangling '__name' scheme, 
and this is probably not one. A single leading underscore should be enough.



  def __getattr__(self, name):
return self.__c.__getattribute__(name)


__magic_methods__ are implementation support for operators and 
operator-like generic functions (len() etc). The good practice is to use 
the operator or generic function, not to directly call the 
implementation __method__.


Also, since it's about encapsulation, it would be better to also hide 
the delegation:


   def __getattr__(self, name):
 try:
   return getattr(self._c, name)
 except AttributeError:
   msg = "'%s' object as no attribute '%s'"
   raise AttributeError(msg % (type(self), name)


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


Re: Less APIs or more encapsulation?

2009-09-10 Thread Bruno Desthuilliers

一首诗 a écrit :
2 class,  B contains C. 


Given your code snippet, I assume you meant that B instances have an 
instance of C as attribute.



 When user want to use some service of C,


s/C/instances of C/


Python's classes are objects by themselves, so it's really important to 
make clear whether you're talking about the class object or instances of 
the class.



there are two choice:

First, more encapsulation:

=
class B:
def newMethod(self):
self.c.newMethod()


Don't expose 'c' as part of the API if you're after "more 
encapsulation". Reminder : by convention (and it's a really strong 
convention), attribute names starting with an underscore are 
implementation ('private' if you want to stick to mainstream jargon).



class C:
def newMethod(self):

  #do something
pass

b.newMethod()



yeps, composition/delegation. Classic scheme.


Sencond : Call seice of f c directly:

(snip)

b.c.newMethod()



Generally, what I learned from books told me that 1st choice is
better.


I _usually_ is, unless it's B's responsability to provide access to a C 
instance. But then, it's usually written as:


b = B()
c = b.get_c()
c.some_method()

This scheme is usually found when there's a need to connect to an 
external resource. A canonical example can be found the DB API, where 
you first open a connection to the database, then ask the connection for 
 one (or more) cursor(s).



But when C has many many methods to expose to outer user, 2nd choice
seems to be more reasonable


Until you need to modify your implementation, or to have some code 
around the calls to methods of c, etc... The (potential) problem with 
the second scheme is that it may expose a bit too much of the 
implementation.


Hopefully, this may not be _that_ tragic with Python, since you can 
easily replace a direct attribute access with a computed one without 
impacting the client code - but not without paying some overhead (which 
FWIW you would have from the start using proper delegation).



I In the first design, B.newMethod did
nothing really useful.


Nope, or at least not directly. But then, why use the obj.method() 
syntax when C.method(c) would work too ?-)


More seriously: in lower-level, more static languages where you don't 
have the hand on attribute lookup, getting "proper encapsulation" right 
from the start is _really_ important. Python is more forgiving here 
since you have ways to customize attribute resolution. *But* it doesn't 
mean you should not pay attention to proper encapsulation.



ctaully, , there are D/E/F, etc. in B we methodhod has to be exposed
to user code,  which makes encapsulation more tedious.


In most languages, yeps. Good news, Python exposes enough of it's 
implementation to allow easy automation of the delegation. Read about 
the __getattr__ magic method.


Also and FWIW, writing dummy getters and setters for a dozen attributes 
is just as boring, and that's still the commonly accepted "best 
practice" in Java, C++ and most other mainstream "OO" languages.




In fact, these classes,  C/D/E/F all have different jobs, but they all
belongs to a real world object "B", B is only a container of C/D/E/F.


What is a "real world" object ?

And if B is only here to provide (almost direct) access to instances of 
C/D/E/F, do you really need B ? (open question - you may actually need 
this level of indirection for pretty good and legitimate reasons... but 
one can't tell without knowing way more about your concrete use case)



What do you think about it?


There are GoldenRules(tm) and BestPractices(tm). And then there's 
concrete application of all these things, and that's where the fun begin.


Blindly applying GoldenRules and BestPractices would border on cargo 
cult thinking. The real point behind GoldenRules etc is to draw your 
attention to known problems and the possible drawbacks of some 
conception/implementation choices, so you can make use of your own 
*informed* judgement wrt/ the concrete problem you're trying to solve.


IOW : there's no silver bullet, just a set of sound advices based on 
experience. Then it's up to you to decide which solution you think is 
the more appropriate here and now.

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


Re: Help with cumulative sum

2009-09-10 Thread Bruno Desthuilliers

Maggie a écrit :

(snip - lots of answers and sensible suggestions already)


   tmp_string = str(count) + '  ' + item


Mays I suggest you learn about string formatting ?




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


Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Hans Georg Schaathun
I wonder if someone knows of an API with the features I need...
random.Random and numpy.random each have only half of it...

My application includes an object to hold a pseudo-randomly
generated matrix too large to be kept in memory.  Hence I
try to store only the seed, and generate the numbers on the fly.

This can be done by giving the object an instance of random.Random.
As far as I can see, numpy.random has a global state, and thus 
cannot be used by several concurrent random-matrix objects.

My problem is that random.Random is much slower than numpy.random.
(Three times slower in a small test.) I believe this is because
numpy.random can return a row at a time, while random.Random only
return scalars (as far as I have seen).

Can anyone recommend a PRNG which supported multiple instances
with independent states, and that also can return numpy.array (or 
something similar) efficiently?

The distribution is currently Gaussian.

Thanks in advance,
:-- George
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lxml question

2009-09-10 Thread Diez B. Roggisch
mattia wrote:

> I would like to click on an image in a web page that I retrieve using
> urllib in order to trigger an event.
> Here is the piece of code with the image that I want to click:
>  onclick="return checkPhoneField(document.contactFrm, 'mobile');"
> alt="sms" src="images/button_sms.bmp" id="smsToMobile" name="smsToMobile"/
>>
> 
> I don't know how to do it (I'm trying using lxml, but any suggestion can
> help).

Install something like HTTP-live-headers or Firebug and analyze what the
actual HTTP-requests are. Then model these.


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


gaierror

2009-09-10 Thread vpr
Hi

I have a working python app that consumers SOAP services on a 32bit
platform. I've packaged it with cx_freeze and executed it on a 64bit
plaform. If I use the IP address as the hostname I have no problem, it
works as expected. However if I use a DNS name, which I can resolve
manuallty i.e. nslookup I get the following error.  The underlying
code uses httplib.

, gaierror(-2, 'Name or service not known')

Has anyone had a similar experience?

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


Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Vlastimil Brom
2009/9/10 Hans Georg Schaathun :
> I wonder if someone knows of an API with the features I need...
> random.Random and numpy.random each have only half of it...
>
> My application includes an object to hold a pseudo-randomly
> generated matrix too large to be kept in memory.  Hence I
> try to store only the seed, and generate the numbers on the fly.
>
> This can be done by giving the object an instance of random.Random.
> As far as I can see, numpy.random has a global state, and thus
> cannot be used by several concurrent random-matrix objects.
>
> My problem is that random.Random is much slower than numpy.random.
> (Three times slower in a small test.) I believe this is because
> numpy.random can return a row at a time, while random.Random only
> return scalars (as far as I have seen).
>
> Can anyone recommend a PRNG which supported multiple instances
> with independent states, and that also can return numpy.array (or
> something similar) efficiently?
>
> The distribution is currently Gaussian.
>
> Thanks in advance,
> :-- George
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Hi,
I didn't tested the specifications nor the efficiency anywhere near
your requirements, but maybe some suggestions to try anyway.

mpmath
http://code.google.com/p/mpmath/

and gmpy
http://code.google.com/p/gmpy/

both have the rand function,
the latter likely faster and more customizable; cf. the help text :
"""
Help on built-in function rand in module gmpy:
rand(...)
rand(opt[,arg]): expose various GMP random-number operations,
depending on value of parameter 'opt' (a string) -- arg is
normally an int or mpz (or else gets coerced to mpz), but
must be a Python mutable sequence when opt is 'shuf':
'init': initialize random-state to support arg bits of 'good
randomness', for arg between 1 and 128 (default 32).
May be called again to change this 'random-quality'.
'qual': returns the number-of-bits-of-good-randomness (0 if
the random-generator not yet initialized), arg ignored.
'seed': set/reset random-state's seed to arg.
'save': get random-state seed (for saving) - arg is ignored.
'next': get random mpz, 0 (included) to arg (excluded)
(default range is 0..2**31).
'floa': get random mpf, range 0<=x<1, with arg meaningful bits
(default, if arg missing or 0, is current 'random quality').
'shuf': random shuffle of Python list (or other mutable
sequence) 'arg'; shuffle is in-place, None returned.

"""
hth
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with cumulative sum

2009-09-10 Thread Steven D'Aprano
On Thu, 10 Sep 2009 09:55:29 +0200, Bruno Desthuilliers wrote:

> Maggie a écrit :
> 
> (snip - lots of answers and sensible suggestions already)
> 
>>tmp_string = str(count) + '   ' + item
> 
> Mays I suggest you learn about string formatting ?


Which is generally good advice, but for a once-off simple concatenation 
of three substrings, there's no great reason to prefer one over the 
other. There's no difference in length of code, little difference in 
readability, and concatenation is about 30% faster.


>>> from timeit import Timer
>>> Timer('str(count) + "" + item', 
... 'count = 2345; item = "abcde"').repeat()
[0.98372197151184082, 0.90344786643981934, 0.9030919075012207]
>>> 
>>> Timer('"%d%s" % (count, item)', 
... 'count = 2345; item = "abcde"').repeat()
[1.4281179904937744, 1.3027360439300537, 1.3032739162445068]



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


Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread sturlamolden
On 10 Sep, 10:50, Hans Georg Schaathun  wrote:

> Can anyone recommend a PRNG which supported multiple instances
> with independent states, and that also can return numpy.array (or
> something similar) efficiently?

numpy.random.RandomState

;-)

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


Re: [Tkinter] messed callbacks

2009-09-10 Thread Giacomo Boffi
Scott David Daniels  writes:

> Giacomo Boffi wrote:
>> Giacomo Boffi  writes:
> ...
>> | def create_cb(a,b):
>> | return lambda: output(a+'->'+b)
>> | | def doit(fr,lst):
>> |   for c1,c2 in zip(lst[::2], lst[1::2]):
>> | subframe=Frame(fr)
>> | Label(subframe,text=c1+' <-> 
>> '+c2).pack(side='left',expand=1,fill='both')
>> | Button(subframe,text='>',command=create_cb(c1,c2)).pack()
>> | Button(subframe,text='<',command=create_cb(c2,c1)).pack()
>> | subframe.pack(fill='x',expand=1)
> ...
>> works ok, now i have to fully understand my previous error
>
> This is really why functools.partial exists.

i take due note, tx

> Also note from Pep 8, spaces are cheap and make the code easier to
> read.

space-crunch was just for posting on usenet, 80 cols terminals etc.

grazie,
   g
-- 
Sarò un'ingenua ma continuo a pensarla come prima, anche se
probabilmente i fatti mi smentiscono.  -- Francy, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hanning python

2009-09-10 Thread pdpi
On Sep 9, 7:01 pm, sturlamolden  wrote:
> On 9 Sep, 16:57, pdpi  wrote:
>
> > Raising this to 1 million, rather than 100, nodes in the window, the
> > timing difference between your version and NumPy's is tiny (but numpy
> > still edges you out, but just barely), but they trounce my naive
> > version, being around 7 or 8 times faster the list comprehension I
> > suggested.
>
> "Premature optimization is the root of all evil in computer
> programming."
>
> Speed is not the issue here.

Sure it is. And safety. And practicality. And all the other reasons
why people use libraries rather than reinventing the wheel every time
they fire up their editors. Given the OP's question, a snarky "you're
not competent enough to do scientific computing" serves no purpose,
where pointing him to NumPy (and SciPy, I forgot to mention that bit)
serves him much better.
-- 
http://mail.python.org/mailman/listinfo/python-list


Urllib and login

2009-09-10 Thread Massi
Hi everyone, I'm trying to get data from an internet page which is
accessed from a login page. Looking at the html source code of the
login page I found that the name of the controls which handle username
and password are "login_un" and "login_pw". So I tried to write a
piece of code to access the data of the protected page:

import urllib2, urllib

opener = urllib2.build_opener()
login_data = urllib.urlencode({"login_un" : "my_un", "login_pw" :
"my_pw"})
opener.open('http://www.myprotectedsite.com/login_page', login_data)
resp = opener.open('http://www.myprotectedsite.com/hidden_page')
print resp.read()

But it doesn't work, since it prints the html code of the login page.
Can anyone point me out what I'm doing wrong?
Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-10 Thread Giacomo Boffi
John Posner  writes:

> def output(x,y,op):
>  if op == "<":
>print x, "<---", y
>  elif op == ">":
>print x, "--->", y
>  else:
>print "Operation argument error!"

uh, nice!, i'll adapt this to my real problem

thank you John,
g
-- 
anch'io la penso come me, ma -- SteO153, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Tkinter] messed callbacks

2009-09-10 Thread Giacomo Boffi
Terry Reedy  writes:

> Reedy's Lambda Rule: [detailed explanation omitted]

i'm beginning to _understand_ what's going on with my code

> Terry Jan Reedy

thanks, grazie 1000 Terry,
 g
-- 
"Lord, what fools these mortals be!"
-- 
http://mail.python.org/mailman/listinfo/python-list


[repost] Does standard python have BeautifulSoup (or something like it) ?

2009-09-10 Thread steve

Hi,

I had sent this question below a couple of months ago but didn't receive any 
replies. I forgot about it though, since I had moved on to using BeautifulSoup. 
Now however, I am wondering why something like this is not present in the 
standard lib. What is the accepted procedure to propose the inclusion of some 
module in our beloved 'batteries included' library ?


I'd like to see this module (or something similar) included.

regards,
- steve

 Original Message 
Subject: Does standard python have BeautifulSoup (or something like it) ?
Date: Tue, 14 Jul 2009 23:51:31 +0200
To: [email protected]

Hi,

After a long time, I decided to play with some web site scraping and realized 
that for all the batteries included approach, the standard python lib (still) 
does not have a simple to use html parser (ie: one which does not require one to 
implement a class just to extract the url of a image tag) ...or does it ?


I like BeautifulSoup, which I used once long ago, but would prefer to use 
something which is part of the standard lib. Is there a module that I completely 
 missed ? (btw, I'm using python-2.6. If not in 2.6 is there something in like 
BeautifulSoup in 3.0 ?)


regards,
- steve

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


Re: [Guppy-pe-list] An iteration idiom (Was: Re: loading files containing multiple dumps)

2009-09-10 Thread Sverker Nilsson
On Wed, 2009-09-09 at 13:47 +0100, Chris Withers wrote:
> Sverker Nilsson wrote:
> > As the enclosing class or frame is deallocated, so is its attribute h
> > itself. 
> 
> Right, but as long as the h hangs around, it hangs on to all the memory 
> it's used to build its stats, right? This caused me problems in my most 
> recent use of guppy...

If you just use heap(), and only want total memory not relative to a
reference point, you can just use hpy() directly. So rather than:

CASE 1:

h=hpy()
h.heap().dump(...)
#other code, the data internal to h is still around
h.heap().dump(...)

you'd do:

CASE 2:

hpy().heap().dump(...)
#other code. No data from Heapy is hanging around
hpy().heap().dump(...)

The difference is that in case 1, the second call to heap() could reuse
the internal data in h, whereas in case 2, it would have to be recreated
which would take longer time. (The data would be such things as the
dictionary owner map.)

However, if you measure memory relative to a reference point, you would
have to keep h around, as in case 1.

[snip]

> > Do you mean we should actually _remove_ features to create a new
> > standalone system?
> 
> Absolutely, why provide more than is used or needed?

How should we understand this? Should we have to support 2 or more
systems depending on what functionality you happen to need? Or do
you mean most functionality is actually _never_ used by
_anybody_ (and will not be in the future)? That would be quite gross
wouldn't it.

I'd be hard pressed to support several versions just for the sake
of some of them would have only the most common methods used in 
certain situations.

That's would be like to create an additional Python dialect that
contained say only the 10 % functionality that is used 90 % of the time.
Quite naturally this is not done anytime soon. Even though one could
perhaps argue it would be easier to use for children etc, the extra
work to support this has not been deemed meaningful.

> 
> > You are free to wrap functions as you find suitable; a minimal wrapper
> > module could be just like this:
> > 
> > # Module heapyheap
> > from guppy import hpy
> > h=hpy()
> > heap=heap()
> 
> I don't follow this.. did you mean heap = h.heap()? 

Actually I meant heap=h.heap

> If so, isn't that using all the gubbinz in Use, etc, anyway?

Depends on what you mean with 'using', but I would say no. 

>  Less minor rant: this applies to most things to do with heapy... Having 
>  __repr__ return the same as __str__ and having that be a long lump of 
>  text is rather annoying. If you really must, make __str__ return the big 
>  lump of text but have __repr__ return a simple, short, item containing 
>  the class, the id, and maybe the number of contained objects...
> >>> I thought it was cool to not have to use print but get the result
> >>> directly at the prompt.
> >> That's fine, that's what __str__ is for. __repr__ should be short.
> > 
> > No, it's the other way around: __repr__ is used when evaluating directly
> > at the prompt.
> 
> The docs give the idea:
> 
> http://docs.python.org/reference/datamodel.html?highlight=__repr__#object.__repr__
> 
> I believe you "big strings" would be classed as "informal" and so would 
> be computed by __str__.

Informal or not, they contain the information I thought was most useful
and are created by __str__, but also with __repr__ because that is used
when evaluated at the prompt.

According to the doc you linked to above, __repr__ should preferably be
a Python expression that could be used to recreate it. I think this has
been discussed and criticized before and in general there is no way to
create such an expression. For example, for the result of h.heap(),
there is no expression that can recreate it later (since the heap
changes) and the object returned is just an IdentitySet, which doesn't
know how it was created.

It also gives as an alternative, "If this is not possible, a string of
the form <...some useful description...> should be returned"

The __repr__ I use don't have the enclosing <>, granted, maybe I missed
this or it wasn't in the docs in 2005 or I didn't think it was important
(still don't) but was that really what the complain was about?

The docs also say that "it is important that the representation is
information-rich and unambiguous."

I thought it was more useful to actually get information of what was
contained in the object directly at the prompt, than try to show how to
recreate it which wasn't possible anyway.

[snip]

> The index (__getitem__) method was available so I
> > used it to take the subset of the i'ths row in the partition defined by
> > its equivalence order.
> 
> That should have another name... I don't know what a partition or 
> equivalence order are in the contexts you're using them, but I do know 
> that hijacking __getitem__ for this is wrong.

Opinions may differ, I'd say one can in principle never 'know' if such a
thing is 'right' or 'wrong', but that gets us into phil

Re: Q on explicitly calling file.close

2009-09-10 Thread David C . Ullrich
On Wed, 9 Sep 2009 15:13:49 -0700 (PDT), r  wrote:

>On Sep 9, 4:19 pm, Charles Yeomans  wrote:
>(snip:)
>> Unfortunately, both of these simple templates have the following  
>> problem -- if open fails, a NameError will be raised from the finally  
>> block.
>
>(snip)
>> I removed the except block because I prefer exceptions to error codes.
>
>how will the caller know an exception has occurred? What if logic
>depends on the validation that a file *had* or *had not* been written
>too, huh?
>
>> In addition to fixing the latent bug in the second simple template, I  
>> took the opportunity to correct your heinous violation of command-
>> query separation.
>>
>> Charles Yeomans
>
>Oh I see! But what happens if the filename does not exist? What then?
>"open" will blow chucks thats what! Here is a version for our paranoid-
>schizophrenic-sadomasochist out there...

Well first, we agree that putting the open() in the try part of a
try-finally is wrong. try-finally is supposed to ensure that
_allocated_ resources are cleaned up.

What you do below may work. But it's essentially throwing
out exception handling and using error codes instead. There
are plenty of reasons why exceptions are preferred. The
standard thing is this:

def UseResource(rname):
  r = get(rname)
  try:
r.use()
  finally
  r.cleanup()

Now if the get() fails, UseResource will indeed blow chunks.
That's what it _should_ do. Generally speaking, you should use
try-except very rarely, making certain you're catching the
exception at the appropriate level. Here for example in
_some_ uses of UseResource() you _want_ the application
to terminate if the get() fails. In that case you'd just call
UseResource() without any try-excpt. In some other
situation (maybe the user provided a filename that may
or may not exist) you want to trap the exception when
you _call_ UseResource():

try:
  UseResource(rname)
except WhateverError:
  print error message


>def egor_read_file(fname, mode='rb'):
>print 'yes, master'
>try:
>   f = open(fname, mode=mode)
>except IOError:
>return (0, 'But, the file no open master!')
>
>try:
>s = f.read()
>except NameError:
>return (0, 'the file still no open master!')
>
>try:
>f.close()
>except:
>print 'That file sure is tricky master!
>
>return (s, 'Whew! here is the file contents, master')

What's above seems simpler. More important, if you do
it this way then you _always_ have to check the return
value of egor_read_file and take appropriate action -
complicates the code everywhere the function is called
as well as making the function more complicated.
Doing it as in UseResource() above you don't need
to worry about whether UseResource() failed
_except_ in situations where you're certain that
that's the right level to catch the error.


>
>> MRAB wrote:
>> You should've used raw strings. :-)
>
>rats!, you got me on that one :-)

David C. Ullrich

"Understanding Godel isn't about following his formal proof. 
That would make a mockery of everything Godel was up to."
(John Jones, "My talk about Godel to the post-grads."
in sci.logic.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Using freeze.py's output and compiling in Windows

2009-09-10 Thread Di Biase, Paul A CIV NAVAIR, 4.4
I have learned python (and wxpython) over the past year and it has taken
over every other language in my work environment for almost every task
(langs: matlab, VBA, fortran...yes fortran, c++, more too...). 

My main concern has always been distribution of software over our
internal networked computers. Essentially, installing python on the
machines is not an option and I'd like another avenue besides using
py2exe as a bundling tool.

This lead me to looking at freeze.py (which is available through the
source files but NOT the binary installation). My understanding of
freeze.py is that it outputs C source code and a makefile (if it
works...) which can then be compiled using linux's make and make install
creating a binary.

Is it possible to take the output from freeze.py and compile the
resulting source code in a Windows environment, creating a "standalone"
windows executable?

If this method has been covered else where, please point me in that
direction and I'll do the grunt work. As far as I can tell, this exact
topic hasn't received any attention.

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


Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Joachim Strömbergson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Aloha!

Hans Georg Schaathun wrote:
> Can anyone recommend a PRNG which supported multiple instances
> with independent states, and that also can return numpy.array (or 
> something similar) efficiently?
> 
> The distribution is currently Gaussian.

Do the PRNG need to support Gaussian directly, or can you live with a
good uniform distribution? If uniform is ok then any good stream cipher
implementation should do the trick. Or a block cipher in a stream cipher
mode, for example AES in CTR mode.

If you need a pure Python implementation I have one such implementation
of the Snow stream cipher:

http://www.strombergson.com/files/snow.py.gz
http://en.wikipedia.org/wiki/SNOW

You can instantiate as many Snow objects as you need, each with their
own state. On my laptop I get about 300 kByte/s, is that too slow for
your application?

- --
Med vänlig hälsning, Yours

Joachim Strömbergson - Alltid i harmonisk svängning.

Kryptoblog - IT-säkerhet på svenska
http://www.strombergson.com/kryptoblog

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqo5PsACgkQZoPr8HT30QGQZgCgp3FcOJ1VbP03kGIMFVTkZgHb
el0AoO5bavQCfeyXX5RFlb7dVvWBOl2O
=s0eq
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [repost] Does standard python have BeautifulSoup (or something like it) ?

2009-09-10 Thread Stefan Behnel
steve wrote:
> I had sent this question below a couple of months ago but didn't receive
> any replies. I forgot about it though, since I had moved on to using
> BeautifulSoup. Now however, I am wondering why something like this is
> not present in the standard lib. What is the accepted procedure to
> propose the inclusion of some module in our beloved 'batteries included'
> library ?
> 
> I'd like to see this module (or something similar) included.

This has been proposed and discussed before and was rejected, IIRC, mainly
due to the lack of a maintainer. But there are also other reasons. For
stdlib inclusion, it's generally required for a module/package to be
best-of-breed. So, why BS instead of html5lib, which, supposedly, is a lot
more 'future proof' than BS. Or lxml, which is a lot faster and more memory
friendly? Or maybe others?

See, for example, the python-dev archives from 2009-03-02.

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


PYTHONPATH issue with sibling package names

2009-09-10 Thread Stuart Moffatt
Environment: Eclipse 3.4.2, Windows XP Pro SP2, Pydev 1.4.4, python
2.6

When I work in eclipse with java, I like to break up my client and
server packages, like this:

client-project/src/org/me/client

server-project/src/org/me/api
server-project/src/org/me/dao
server-project/src/org/me/entity
server-project/src/org/me/

Then, when I need to call API code from the client, I make sure the
API src is on the path.

I am trying setup pydev projects to do the same thing, but running
into an ImportError because my client code can't see the server src,
even though it is on the path.

Specifically, I am trying to import an entity from the server code
into the client, like this:

   from org.me.entity import MyEntity

If I do this from any module in the server project it is fine (because
the src path is in the same eclipse project). But if I do it from
anywhere in the client code I get the ImportError

>From what I can tell, python asks for the "closest" module path, which
is the current project. It finds org.me, but there is only the client
sub-package. The org.me.entity sibling is in another eclipse project,
but even though that path is on the PYTHONPATH, python stopped looking
after it found a similarly named parent package.

Is there a trusted way to make sure python looks through all paths for
sibling packages? Can I load 'org.me.client' from one path in
PYTHONPATH and 'org.me.*' from another path in PYTHONPATH? I imagine
if I try to force python to load the second package first that the
same thing will happen in reverse.
-- 
http://mail.python.org/mailman/listinfo/python-list


Site Scarpping with Beautiful Soup

2009-09-10 Thread aditya shukla
Hello Guys,


I would like to scrap a site  by using Beautiful Soup library.The site has
various options listed in a drop down menu.What I want to do is pass the
drop down option with the python script and scrap the result obtained for
each value.Let's say we have three values i the drop down menu man , gorilla
and ape .I can pass scrap.py man and with that I shoud be able to scrap to
all results that show up under the man category.Say african, asian ,
cacusian etc.

My issue is that I can scrap a single page wit Beautiful Soup but have no
idea of how to accomplish the above task.Please guide me in the right
direction.


Thanks

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


Re: "Rapid GUI Programming with Python and Qt" source code

2009-09-10 Thread Steven Woody
On Wed, Sep 9, 2009 at 9:33 PM, David Boddie  wrote:

> On Wed Sep 9 07:11:26 CEST 2009, Steven Woody wrote:
>
> > *I've searched google and cannot find a valid link for the source code of
> > the book "Rapid GUI Programming with Python and Qt". Could anyone please
> > give me a non-broken URL?*
>
> See this page for the links:
>
>  http://www.qtrac.eu/pyqtbook.html
>
>
but the URL is not reachable from here.  is there another URL? thanks.



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



-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke
public key at http://subkeys.pgp.net:11371 ([email protected])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Rapid GUI Programming with Python and Qt" source code

2009-09-10 Thread David Boddie
On Thursday 10 September 2009, Steven Woody wrote:
> On Wed, Sep 9, 2009 at 9:33 PM, David Boddie  wrote:

> > See this page for the links:
> >
> >  http://www.qtrac.eu/pyqtbook.html
>
> but the URL is not reachable from here.  is there another URL? thanks.

Can't you access anything from qtrac.eu from where you are? Here are two
links to archives for the Python 2.6 versions of the examples:

http://www.qtrac.eu/pyqtbook26.tar.gz
http://www.qtrac.eu/pyqtbook26.zip

If you can't reach those, maybe Mark will send you the examples directly.

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


Re: New Tkinter windows don't get focus on OS X

2009-09-10 Thread Kevin Walzer

On 9/10/09 1:27 AM, Joshua Bronson wrote:

If you try something like:

$ python -m Tkinter -c 'Tkinter._test()'

in Terminal on OS X, you'll notice that the window that is spawned
does not get focus, rather focus remains in Terminal. Furthermore, if
you hit Command+Tab to switch focus to the Python process, you'll
notice that for some reason Python has been placed last in the focus
order, even though it was just spawned by Terminal. This is
undesirable if you're e.g. making a game where stuff happens as soon
as the window is spawned and the player is expected to respond quickly
but can't until she Command+Tabs over or clicks in the unfocused
window. I've googled for this extensively and haven't found a way
around it, so I thought I'd ask here. If there is a more appropriate
place to ask, please let me know.

Thanks,
Josh



Yes, this is standard  behavior for OS X. Running an app in Terminal 
keeps focus in the Terminal unless you switch by clicking windows. The 
Command-Tab behavior is determined by the windowing system, not by a 
newly spawned process.


The way around this is to wrap your application up in a standard Mac app 
bundle using py2app. The average Mac user isn't going to launch a 
Python-based game from the command line.


Kevin



--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHONPATH issue with sibling package names

2009-09-10 Thread Diez B. Roggisch
Stuart Moffatt wrote:

> Environment: Eclipse 3.4.2, Windows XP Pro SP2, Pydev 1.4.4, python
> 2.6
> 
> When I work in eclipse with java, I like to break up my client and
> server packages, like this:
> 
> client-project/src/org/me/client
> 
> server-project/src/org/me/api
> server-project/src/org/me/dao
> server-project/src/org/me/entity
> server-project/src/org/me/
> 
> Then, when I need to call API code from the client, I make sure the
> API src is on the path.
> 
> I am trying setup pydev projects to do the same thing, but running
> into an ImportError because my client code can't see the server src,
> even though it is on the path.
> 
> Specifically, I am trying to import an entity from the server code
> into the client, like this:
> 
>from org.me.entity import MyEntity
> 
> If I do this from any module in the server project it is fine (because
> the src path is in the same eclipse project). But if I do it from
> anywhere in the client code I get the ImportError
> 
> From what I can tell, python asks for the "closest" module path, which
> is the current project. It finds org.me, but there is only the client
> sub-package. The org.me.entity sibling is in another eclipse project,
> but even though that path is on the PYTHONPATH, python stopped looking
> after it found a similarly named parent package.
> 
> Is there a trusted way to make sure python looks through all paths for
> sibling packages? Can I load 'org.me.client' from one path in
> PYTHONPATH and 'org.me.*' from another path in PYTHONPATH? I imagine
> if I try to force python to load the second package first that the
> same thing will happen in reverse.

The solution you are searching for is called "namespace packages", and you
can read more about it here:

  http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages


Do yourself a favor though, and don't use those several-steps-namespaces.
This is Python, not Java - two levels at *most*, normally a
project-namespace should be enough.

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


Re: python and openSSL

2009-09-10 Thread Luca Bel
I had already installed and tested M2Crypto.
My problem is that with this library I've not found a way to replicate the
operation that I can made with openssl.
As you can see, here:

openssl smime -decrypt -verify -inform DER -in ReadmeDiKe.pdf.p7m -noverify
-out ReadmeDike.pdf

No certificate is used. I can simply extract the contents of p7m and save it
on fs. And the extracted file is perfect.

following this how to, seems that a certificate is always needed, and I
don't have it.

can someone help me?


On Thu, Sep 10, 2009 at 3:56 AM,  wrote:

> On 9 Sep, 01:30 pm, [email protected] wrote:
>
>> Hi all.
>> I need a trick to do something like this:
>>
>> openssl smime -decrypt -verify -inform DER -in ReadmeDiKe.pdf.p7m
>> -noverify -out ReadmeDike.pdf
>>
>> To unwrap a p7m file and read his content.
>>
>> I know that I could use somthing like:
>>
>>> import os
> os.system('openssl ')
>

>> but i would use a python library to wrap openssl.
>>
>> I've already install pyOpenSSL, but I can not understand how to run the
>> same
>> command.
>>
>
> pyOpenSSL wraps the parts of OpenSSL which deal with S/MIME.  I think that
> M2Crypto does, though I haven't used those parts of it myself.
>
> Jean-Paul
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing: Correct usage of pool & queue?

2009-09-10 Thread Aahz
In article ,
Allen Fowler   wrote:
>
>1) Have a maximum of 20 "in-flight" tasks.  (thus worker processes?)

Good bet.

>3) Certain tasks in my list must be processed in the correct order.  (I
>guess the asignment logic must somehow tag those to by done by the same
>worker?)

The simpler way to do this would be to bundle these tasks into a single
queue object that contains a list of tasks.  Each worker iterates over
the list of tasks that it receives, which could be a single task.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Accessing objects at runtime.

2009-09-10 Thread jacopo
I have a  system comprising many objects cooperating with each others.
(For the time being, everything is running on the same machine, in the
same process but things might change in the future). The system starts
a infinite loop which keeps triggering operations from the
instantiated objects.

I would like to find a way to inspect the objects at run time.  In
other words I would like to check certain attributes in order to
understand in which status the object is. This of course without
having to stop the system and resume it after the checking is
finished.

I would be grateful to any suggestion.
Regads,
Jacopo
-- 
http://mail.python.org/mailman/listinfo/python-list


How to create an array which can be used also as a dictionary

2009-09-10 Thread Hans Müller

Hello,

I have a lot of items having a name and a given sequence.

To access these items fast in a sequence order they should be used as 
a list, but to be fetched fast by name they also should be in a 
dictionary.


Code could be something like this.

class item
def __init__(name, value1, value2, value3):
self.name = name
self.value1 = value1
self.value2 = value2

a = []
a.append(item("foo", "bar", "text1"))
a.append(item("xyz", "basd", "tsddsfxt1"))
a.append(item("aax", "hello", "dont care"))

in a, i have my objects in given order, fast accessible by index, e.g. 
a[2] to get the third one. Fine.


Now I'd like to have a dict with references to thes objects like this:

d = {}
for x in a:
d[a.name] = a   # do I get a copy of a here or a new reference ?!

In d i now have a dict, fast accessible by name.
But what happens if i modify
a[1].value1 = 1000
is
d["aax"].value1 now 1000 or still "hello" as in this example ?

Any ideas to get access to the SAME object by index (0..n-1) AND by key ?

Emphasis here is on speed.


Thanks a lot,

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


Accessing objects at runtime.

2009-09-10 Thread jacopo
I have a  system comprising many objects cooperating with each others.
(For the time being, everything is running on the same machine, in the
same process but things might change in the future). The system starts
a infinite loop which keeps triggering operations from the
instantiated objects.

I would like to find a way to inspect the objects at run time.  In
other words I would like to check certain attributes in order to
understand in which status the object is. This of course without
having to stop the system and resume it after the checking is
finished.

I would be grateful to any suggestion.
Regads,
Jacopo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing objects at runtime.

2009-09-10 Thread Jochen Schulz
jacopo:
> 
> I would like to find a way to inspect the objects at run time.  In
> other words I would like to check certain attributes in order to
> understand in which status the object is.

What exactly do you want to know? The names of existing attributes or
their content? The latter is probably obvious to you and the former is
easy, too. See hasattr, getattr and isinstance.

J.
-- 
I lust after strangers but only date people from the office.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing objects at runtime.

2009-09-10 Thread jacopo

>
> What exactly do you want to know? The names of existing attributes or
> their content? The latter is probably obvious to you and the former is
> easy, too. See hasattr, getattr and isinstance.

I want to know the value of the attributes.
What you suggest works when the program stops, objects are still in
memory and I could inspect all I want. BUT I don’t want to stop the
system. So even the shell would be blocked to type something.

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


[cmd] Uppercase H

2009-09-10 Thread cryzed
Hello, I'm currently using the "cmd" module with Python 2.6.2 on Ubuntu 
GNU/Linux 9.04 (Jaunty Jackalope) and have got a bit of a problem. How 
can I write an uppercase H into the input? If I try that it always 
starts to show all available commands (which is probably related to the 
use of the "readline" modul if available) and I don't want to completely 
turn it off by using raw_input.


Any ideas?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to create an array which can be used also as a dictionary

2009-09-10 Thread Diez B. Roggisch
Hans Müller wrote:

> Hello,
> 
> I have a lot of items having a name and a given sequence.
> 
> To access these items fast in a sequence order they should be used as
> a list, but to be fetched fast by name they also should be in a
> dictionary.
> 
> Code could be something like this.
> 
> class item
> def __init__(name, value1, value2, value3):
> self.name = name
> self.value1 = value1
> self.value2 = value2
> 
> a = []
> a.append(item("foo", "bar", "text1"))
> a.append(item("xyz", "basd", "tsddsfxt1"))
> a.append(item("aax", "hello", "dont care"))
> 
> in a, i have my objects in given order, fast accessible by index, e.g.
> a[2] to get the third one. Fine.
> 
> Now I'd like to have a dict with references to thes objects like this:
> 
> d = {}
> for x in a:
> d[a.name] = a # do I get a copy of a here or a new reference ?!

Only a reference.

> 
> In d i now have a dict, fast accessible by name.
> But what happens if i modify
> a[1].value1 = 1000
> is
> d["aax"].value1 now 1000 or still "hello" as in this example ?

It's changed. Didn't you try that? 

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


Simple Text Processing

2009-09-10 Thread AJAskey
New to Python.  I can solve the problem in perl by using "split()" to
an array.  Can't figure it out in Python.

I'm reading variable lines of text.  I want to use the first number I
find.  The problem is the lines are variable.

Input example:
  this is a number: 1
  here are some numbers 1 2 3 4

In both lines I am only interested in the "1".  I can't figure out how
to use "split()" as it appears to make me know how many space
separated "words" are in the line.  I do not know this.

I use:  a,b,c,e = split() to get the first line in the example.  The
second line causes a runtime exception.  Can I use "split" for this?
Is there another simple way to break the "words" into an array that I
can loop over?

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


Vectorized laziness inside

2009-09-10 Thread Bearophile
I've just seen this good Google Talk video from Jan 2008, "MonetDB/
X100: a (very) fast column-store", about a more efficient column-
oriented DBMS:
http://www.youtube.com/watch?v=yrLd-3lnZ58

The efficiency of this DBMS (something like 50 times faster) is
produced by few things:
- It's column-wise, this helps in several other successive
optimizations too (row-oriented DBMS have their purpose still, the
column-oriented are good if you want to perform statistics on most of
your data, certain kinds of data mining, etc).
- At 13.57 it shows that instead of yielding single tuples (or single
items, it's column-oriented), it yields arrays of about 100 tuples/
fields. This allows to create primitives that are much more efficient.
And the CPU can process them better, using SSE instruction too. Such
small arrays are designed to fit in the CPU cache (probably L2). Such
vectorized operations are also pipelined in some way.
- The filtering operations often don't produce new vectors, they just
mark the tuples as not present any more inside an array. This helps
avoid many copies of such arrays.
- Data is kept compressed on disk, the compression is column-wise, and
decompression is done only just-in-time to save data transfers. The
number compression takes in account that often data is sorted, so it's
delta-compressed, and then such delta is compressed only in a range of
the Gaussian-like residual distribution (outliers are encoded
directly). This compression also allows to keep large indexes in RAM,
that speeds up things more.
- They even shown vectorized hashing, but I have not understood how
they work.
- The reading from the disks is done in a merged way, to avoid reading
the same things many times for similar queries.

(The good thing is that it's not hard to understand most things shown
in this video. But I'd like to see the C code they use as "reference",
that's just 3 times faster than their DBMS).

DBMS inside work as the lazy operations that are getting more common
in Python code (see itertools), and common in Haskell.

So to reduce the Python interpreter overhead of lazy iterations it may
be used a vectorized strategy (that's meant to be almost transparent
for the Python programmer, so this is an implementation thing), so
items can be produced and moved in groups, inside arrays, like in that
video. (The DBMS too has an interpreter overhead, it's made of fast
primitives used by lazy interpreted code, it looks a lot like a Python/
Ruby :-) ). Beside CPython This idea can be useful also for Psyco/
Unladen Swallow.

Lazy filtering is a bit less common in Python code, so I don't know if
it can also be useful the idea of not copying new arrays but just
marking items as absent (for example with a bit array attached to the
items array).

As you may know I have introduced laziness in the D language, D2 now
has a standard library that contains several of the things present in
the itertools module. I'll do some experiments to see if the ideas of
such vectorized laziness can improve lazy generators in D. I may even
test the idea of keeping arrays with holes.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Text Processing

2009-09-10 Thread Benjamin Kaplan
On Thu, Sep 10, 2009 at 11:36 AM, AJAskey  wrote:

> New to Python.  I can solve the problem in perl by using "split()" to
> an array.  Can't figure it out in Python.
>
> I'm reading variable lines of text.  I want to use the first number I
> find.  The problem is the lines are variable.
>
> Input example:
>  this is a number: 1
>  here are some numbers 1 2 3 4
>
> In both lines I am only interested in the "1".  I can't figure out how
> to use "split()" as it appears to make me know how many space
> separated "words" are in the line.  I do not know this.
>
> I use:  a,b,c,e = split() to get the first line in the example.  The
> second line causes a runtime exception.  Can I use "split" for this?
> Is there another simple way to break the "words" into an array that I
> can loop over?
>
> >>> line = "here are some numbers 1 2 3 4"
>>> a = line.split()
>>> a
['here', 'are', 'some', 'numbers', '1', '2', '3', '4']
>>> #Python 3 only
... a,b,c,d,*e = line.split()
>>> e
['1', '2', '3', '4']




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


Re: Accessing objects at runtime.

2009-09-10 Thread Jochen Schulz
jacopo:
> 
>> What exactly do you want to know? The names of existing attributes or
>> their content? The latter is probably obvious to you and the former is
>> easy, too. See hasattr, getattr and isinstance.
> 
> I want to know the value of the attributes.
> What you suggest works when the program stops, objects are still in
> memory and I could inspect all I want. BUT I don’t want to stop the
> system. So even the shell would be blocked to type something.

Ah, now I get it: you want to attach to a running process and inspect it
interactively? -Sorry, then I cannot answer you question.

J.
-- 
When I get home from the supermarket I don't know what to do with all the
plastic.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Text Processing

2009-09-10 Thread AJAskey
Never mind.  I guess I had been trying to make it more difficult than
it is.  As a note, I can work on something for 10 hours and not figure
it out.  But the second I post to a group, then I immediately figure
it out myself. Strange snake this Python...

Example for anyone else interested:

line = "this is a line"
print line
a = line.split()
print a
print a[0]
print a[1]
print a[2]
print a[3]

--
OUTPUT:

this is a line
['this', 'is', 'a', 'line']
this
is
a
line



On Sep 10, 11:36 am, AJAskey  wrote:
> New to Python.  I can solve the problem in perl by using "split()" to
> an array.  Can't figure it out in Python.
>
> I'm reading variable lines of text.  I want to use the first number I
> find.  The problem is the lines are variable.
>
> Input example:
>   this is a number: 1
>   here are some numbers 1 2 3 4
>
> In both lines I am only interested in the "1".  I can't figure out how
> to use "split()" as it appears to make me know how many space
> separated "words" are in the line.  I do not know this.
>
> I use:  a,b,c,e = split() to get the first line in the example.  The
> second line causes a runtime exception.  Can I use "split" for this?
> Is there another simple way to break the "words" into an array that I
> can loop over?
>
> Thanks.
> Andy

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


Re: New Tkinter windows don't get focus on OS X

2009-09-10 Thread Joshua Bronson
Hey Kevin,

Thanks for your quick reply.

On Sep 10, 10:12 am, Kevin Walzer  wrote:
> On 9/10/09 1:27 AM, Joshua Bronson wrote:
> > If you try something like:
>
> > $ python -m Tkinter -c 'Tkinter._test()'
>
> > in Terminal on OS X, you'll notice that the window that is spawned
> > does not get focus, rather focus remains in Terminal. Furthermore, if
> > you hit Command+Tab to switch focus to the Python process, you'll
> > notice that for some reason Python has been placed last in the focus
> > order, even though it was just spawned by Terminal. This is
> > undesirable if you're e.g. making a game where stuff happens as soon
> > as the window is spawned and the player is expected to respond quickly
> > but can't until she Command+Tabs over or clicks in the unfocused
> > window. I've googled for this extensively and haven't found a way
> > around it, so I thought I'd ask here. If there is a more appropriate
> > place to ask, please let me know.
>
> > Thanks,
> > Josh
>
> Yes, this is standard  behavior for OS X. Running an app in Terminal
> keeps focus in the Terminal unless you switch by clicking windows.

At first I was puzzled by this, because if you run something like
"open -a TextEdit", TextEdit gets the focus. But then I realized this
must be because of the "open" command. Indeed, if you try running
something like "/Applications/MacPorts/Python\ 2.6/IDLE.app/Contents/
MacOS/IDLE" focus will remain in Terminal.

On the other hand, every other GUI toolkit I've used (e.g. wxPython,
PyQt4, pyglet) does not have this problem. (If you try the basic
example from http://www.wxpython.org/tut-part1.php you'll see what I
mean.) How are these other toolkits able to steal the focus? More
important, is it *possible* to have a Tkinter app steal the focus,
even if it's not the default behavior?

> The Command-Tab behavior is determined by the windowing system, not
> by a newly spawned process.

Sure, but I've always noticed a correspondence between the focus order
and the order in which an application was spawned. So the conclusion
is that there's just a system-wide inconsistency here in the case of
spawning GUI apps from Terminal.

> The way around this is to wrap your application up in a standard Mac app
> bundle using py2app. The average Mac user isn't going to launch a
> Python-based game from the command line.

True, but it'll still be a lot less painful for me to test my app if I
can get it to steal focus
when launched from the command line. If anyone knows how to do this in
Tkinter, help would be much appreciated.

Thanks,
Josh

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


[email protected]

2009-09-10 Thread opengis
Hello Python User,
I am using python in an openlayers application to access another 
server on my network via javascript.  The proxy script works fine 
when the application runs in Apache HTTP Server, but I get a 
"" error after moving 
the application to Tomcat.  The tomcat cgi configuration tested 
fine with a "hello world" python script.  I then boiled my proxy 
script down to the following:

#!c:/Program Files/Python25/python.exe -u

import urllib2
import cgi

fs = cgi.FieldStorage()
url = fs.getvalue('url', "http://www.openlayers.org";)
try:
y = urllib2.urlopen(url)
print y.read()

except Exception, E:
print "Status: 500 Unexpected Error"
print "Content-Type: text/plain"
print 
print "url: ", url
print 
print "Some unexpected error occurred. Error text was:", E

This script produces the "".  The openlayers homepage is expected.  My environment 
is Tomcat 6, Apache 2, Win XP, and Python 2.5.  I have my local 
firewall turned off.  Proxy support is enabled, and working, in 
Apache 2.0 (I get the error with Apache Server stopped). I seem to 
be missing something to facilitate the communication between 
python, my network and tomcat.  Any direction or solution is 
greatly appreciated.

Thank you,
Josh

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


Re: Download and save a picture - urllib

2009-09-10 Thread Diez B. Roggisch
mattia wrote:

> Hi all, in order to download an image. In order to correctly retrieve the
> image I need to set the referer and handle cookies.
> 
> opener = urllib.request.build_opener(urllib.request.HTTPRedirectHandler
> (), urllib.request.HTTPCookieProcessor())
> urllib.request.install_opener(opener)
> req = urllib.request.Request("http://myurl/image.jpg";)
> req.add_header("Referer", "http://myulr/referer.jsp";)
> r = urllib.request.urlopen(req)
> with open("image.jpg", "w" ) as fd:
> print(r.read(), file=fd)
> 
> I'm not able to correctly save the image. In fact it seems that it it
> saved in hex format. Any suggestion?

How do you come to the conclusion that it's saved as "hex"? It sure isn't -
either the request fails because the website doesn't allow it due to
missing cookies or similar stuff - or you get the binary data.

But you should be aware that in the interpreter, strings are printed out
with repr() - which will convert non-printable characters to their
hex-representation to prevent encoding/binary-data-on-teriminal-issues.

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


From Perl to Python

2009-09-10 Thread Raful CIV Mitchell H
General newbie type question...open ended.  I have been scripting in Perl for 8 
years for net management purposes.  Mostly interacting with SNMP and Cisco MIBS 
in general.  I would like to re-write these scripts in Python.  Any suggestions 
in how to get started in Python and , especially, needing an interface to SNMP 
would be appreciated.

 Thanks,

Mitch


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


Re: Instatiable Pseudo-Random Number Generator

2009-09-10 Thread Hans Georg Schaathun
On Thu, 10 Sep 2009 02:53:33 -0700 (PDT), sturlamolden
   wrote:
:  On 10 Sep, 10:50, Hans Georg Schaathun  wrote:
: 
: > Can anyone recommend a PRNG which supported multiple instances
: > with independent states, and that also can return numpy.array (or
: > something similar) efficiently?
: 
:  numpy.random.RandomState

Thanks.  Perfect solution.

I wish the doc string of numpy.random had mentioned it :-)

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


Re: Help with cumulative sum

2009-09-10 Thread Andreas Waldenburger
On Thu, 10 Sep 2009 17:48:32 +0200 Giacomo Boffi
 wrote:

> Maggie  writes:
> 
> > [...]
> > else:
> >print 'The loop is finito'
> 
> do you know of it.comp.lang.python?
> 

Neat! They use computers in IT now?

*flees, snickering*
/W

-- 
INVALID? DE!

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


Re: PYTHONPATH issue with sibling package names

2009-09-10 Thread Stuart Moffatt
On Sep 10, 10:12 am, "Diez B. Roggisch"  wrote:
> Stuart Moffatt wrote:
> > Environment: Eclipse 3.4.2, Windows XP Pro SP2, Pydev 1.4.4, python
> > 2.6
>
> > When I work in eclipse with java, I like to break up my client and
> > server packages, like this:
>
> > client-project/src/org/me/client
>
> > server-project/src/org/me/api
> > server-project/src/org/me/dao
> > server-project/src/org/me/entity
> > server-project/src/org/me/
>
> > Then, when I need to call API code from the client, I make sure the
> > API src is on the path.
>
> > I am trying setup pydev projects to do the same thing, but running
> > into an ImportError because my client code can't see the server src,
> > even though it is on the path.
>
> > Specifically, I am trying to import an entity from the server code
> > into the client, like this:
>
> >    from org.me.entity import MyEntity
>
> > If I do this from any module in the server project it is fine (because
> > the src path is in the same eclipse project). But if I do it from
> > anywhere in the client code I get the ImportError
>
> > From what I can tell, python asks for the "closest" module path, which
> > is the current project. It finds org.me, but there is only the client
> > sub-package. The org.me.entity sibling is in another eclipse project,
> > but even though that path is on the PYTHONPATH, python stopped looking
> > after it found a similarly named parent package.
>
> > Is there a trusted way to make sure python looks through all paths for
> > sibling packages? Can I load 'org.me.client' from one path in
> > PYTHONPATH and 'org.me.*' from another path in PYTHONPATH? I imagine
> > if I try to force python to load the second package first that the
> > same thing will happen in reverse.
>
> The solution you are searching for is called "namespace packages", and you
> can read more about it here:
>
>  http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
>
> Do yourself a favor though, and don't use those several-steps-namespaces.
> This is Python, not Java - two levels at *most*, normally a
> project-namespace should be enough.
>
> Diez


Diez,

Thanks for the tips re: namespace packages. Yeah, I know this is
python, but for very large projects (or multiple projects for very
large clients) it is just more flexible to stick to the reverse-dot
java notation of "domain.organization.project.namespace".

All I had to do was make sure that top- and mid-level folders had an
__init__.py with this line:

__import__('pkg_resources').declare_namespace(__name__)

in it (and nothing else).

So, for my example, I had:

client-project/src/org/__init__.py
client-project/src/org/me/__init__.py
server-project/src/org/__init__.py
server-project/src/org/me/__init__.py

...all with the special namespace declaration line above.

Note that the lowest level folders in the package:

client-project/src/org/me/client
server-project/src/org/me/api
server-project/src/org/me/

...all have __init__.py files with actual module code, and therefore
do NOT have the namespace declaration line.

To expose the server code (org.me.api, org.me.dao, etc) I have a
setup.py in the server-project/src folder with:

from setuptools import setup
setup(name='myserver',
version='1.0',
namespace_packages = ['org','org.me'],
packages=['org.me.api','org.me.dao','org.me.entity'],
)

A similar setup.py can be created for the client library too. Notice
that the setup has every level (except the last) in the
namespace_packages list argument. This is how it walks down the tree
and builds the namespace properly.

With this setup file I can make an .egg or .zip distribution using:

  cd server-project/src
  python setup.py bdist

  or

  python setup.py bdist_egg

For my dev environment in eclipse I also wanted the convenience of
editing server code AND have the latest code on the path for my client
project (without rebuilding a dist). To do this I just:

  cd server-project/src
  python setup.py develop

...which puts a symlink (even does it properly in Windows) in my
python/lib/site-packages folder. Now in my client code I can do a
regular import, even though the code lives in another project, and
though portions of the code base are at different PYTHONPATHs:

  from org.me.entity import MyEntity # from server-project/src
  from org.me.api import MyAPI # from server-project/src
  from org.me.client import MyClient # from client-project/src

When my code is complete, the myserver-1.0-py2.6.egg and myclient-1.0-
py2.6.egg can be included in other python modules by loading compiled
source from inside the egg with:

  from pkg_resources import require
  require("myserver>=1.0")
  require("myclient>=1.0")

and then:

  from org.me.entity import MyEntity # from compiled code in
myserver-1.0-py2.6.egg
  from org.me.api import MyAPI # from compiled code in myserver-1.0-
py2.6.egg
  from org.me.client import MyClient # from compiled code in
myclient-1.0-py2.6.egg


Again, it might seem like a headache to some python developers

From Perl to Python

2009-09-10 Thread Raful CIV Mitchell H
General newbie type question...open ended.  I have been scripting in Perl for 8 
years for net management purposes.  Mostly interacting with SNMP and Cisco MIBS 
in general.  I would like to re-write these scripts in Python.  Any suggestions 
in how to get started in Python and , especially, needing an interface to SNMP 
would be appreciated.

 Thanks,

Mitch


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


Re: Using freeze.py's output and compiling in Windows

2009-09-10 Thread Di Biase, Paul A CIV NAVAIR, 4.4
No one?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search term parsing like Google/Gmail

2009-09-10 Thread Robert Kern

On 2009-09-09 16:37 PM, Randy Syring wrote:

I am looking for a string parser that works kind of like Google's or
Gmail's advanced search capabilities. So it would turn something like this:

(subject:"hi there" from:[tim, tom, -fred]) or (subject:foobar from:sam)

into a python structure that could be used. I don't really care so much
about the search syntax except that easy and intuitive is best for
users. Does something like this exist?


The Whoosh search library uses pyparsing to parse its queries. It does not 
handle the [] brackets, but it handles the rest. I am sure that Matt Chaput 
would accept a contribution of such an enhancement, though.


  http://whoosh.ca/

In [9]: from whoosh import qparser

In [10]: p = qparser.QueryParser('body')

In [11]: p.parse(u'subject:"hi there" or (subject:foobar from:sam)')
Out[11]: Or([Phrase(u'subject', [u'hi', u'there']), And([Term(u'subject', 
u'foobar', boost=1.0), Term(u'from', u'sam', boost=1.0)])])


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: a question about numpy

2009-09-10 Thread Robert Kern

On 2009-09-09 20:46 PM, rechard wrote:

Robert Kern wrote:

On 2009-09-08 20:45 PM, hi_roger wrote:

hello, i want to ask a question about numpy.

i know how to select a submatrix using the slice object in numpy. But
how can i select a submatrix
A[i1,i2,i3;j1,j2,j3] (elements in A on line i1,i2,i3 and column
j1,j2,j3 , and i1,i2,i3,j1,j2,j3 are all arbitrary numbers )
The submatrix must share data memory with original matrix.

Any one help? thank you


Sturla is almost correct. What you really want is this:

i = [[i1], [i2], [i3]]
j = [[j1, j2, j3]]
B = A[i, j]

http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer

If you have more numpy questions, please ask on the numpy mailing list.

http://www.scipy.org/Mailing_Lists


wow..., thank you all :)
but it seems it is impossible to make the submatrix share data with the
original matrix in pure numpy code ?


That is correct.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: From Perl to Python

2009-09-10 Thread Ethan Furman

Raful CIV Mitchell H wrote:
General newbie type question…open ended.  I have been scripting in Perl 
for 8 years for net management purposes.  Mostly interacting with SNMP 
and Cisco MIBS in general.  I would like to re-write these scripts in 
Python.  Any suggestions in how to get started in Python and , 
especially, needing an interface to SNMP would be appreciated.


 Thanks,

Mitch



Inpatient, eh?  :-)

Dive into Python is an excellent get-you-going book that is also freely 
available (http://www.diveintopython.org/).


Another good one is How to Think Like a Computer Scientist, Learning 
with Python (http://openbookproject.net/thinkCSpy/).


As for SNMP, I have no direct experience, but a search of google shows 
several candidates, including http://pysnmp.sourceforge.net/.


Good luck!

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


Re: ANN: dh, the daemon helper

2009-09-10 Thread John Kelly
On Thu, 10 Sep 2009 06:38:20 + (UTC),
[email protected] wrote:

>John Kelly  wrote:
 
>> dh, the daemon helper

>> dh is its name; a natural companion to sh.
 
>A useful little program, but...
>this might be OT, but let me point out that the name collides 
>with Debian's debhelper (also invoked as dh)

Until now, I was unaware of debhelper.

It's hard to find a short name not already taken.  I decided that dh was
a good representation of its function, and I wanted a two character name
that's easy to use with minimal keystrokes.

I apologize to debhelper users, but I have no desire to change the name
of daemon helper now.

dh is its name; a natural companion to sh.


-- 
Webmail for Dialup Users
http://www.isp2dial.com/freeaccounts.html
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download and save a picture - urllib

2009-09-10 Thread mattia
You were right, the problem was with the print function, using a normal 
write everythong works fine.

Il Thu, 10 Sep 2009 18:56:07 +0200, Diez B. Roggisch ha scritto:

> mattia wrote:
> 
>> Hi all, in order to download an image. In order to correctly retrieve
>> the image I need to set the referer and handle cookies.
>> 
>> opener = urllib.request.build_opener(urllib.request.HTTPRedirectHandler
>> (), urllib.request.HTTPCookieProcessor())
>> urllib.request.install_opener(opener) req =
>> urllib.request.Request("http://myurl/image.jpg";)
>> req.add_header("Referer", "http://myulr/referer.jsp";) r =
>> urllib.request.urlopen(req)
>> with open("image.jpg", "w" ) as fd:
>> print(r.read(), file=fd)
>> 
>> I'm not able to correctly save the image. In fact it seems that it it
>> saved in hex format. Any suggestion?
> 
> How do you come to the conclusion that it's saved as "hex"? It sure
> isn't - either the request fails because the website doesn't allow it
> due to missing cookies or similar stuff - or you get the binary data.
> 
> But you should be aware that in the interpreter, strings are printed out
> with repr() - which will convert non-printable characters to their
> hex-representation to prevent encoding/binary-data-on-teriminal-issues.
> 
> Diez

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


AttributeError: 'module' object has no attribute 'pack'

2009-09-10 Thread Sampsa Riikonen
Dear List,

I have a freshly installed opensuse 11.2 and I am experiencing the following
problem with the module "subprocess":

sam...@linux-912g:~> python
Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/subprocess.py", line 404, in 
import pickle
  File "/usr/lib/python2.6/pickle.py", line 171, in 
class Pickler:
  File "/usr/lib/python2.6/pickle.py", line 250, in Pickler
def put(self, i, pack=struct.pack):
AttributeError: 'module' object has no attribute 'pack'

Any ideas how to fix this?

Kind Regards,

Sampsa

--
"Jos konsultti päästetään vapaasti touhuamaan ja ohjaamaan organisaatiota,
voi edessä olla uppoaminen suunnitelmien suohon, eksyminen hankehelvettiin 
ja dokumenttiviidakkoon."
   (Mielipideosasto, Helsingin Sanomat 14.5.2009)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: 'module' object has no attribute 'pack'

2009-09-10 Thread Albert Hopkins
On Thu, 2009-09-10 at 21:07 +0300, Sampsa Riikonen wrote:
> Dear List,
> 
> I have a freshly installed opensuse 11.2 and I am experiencing the following
> problem with the module "subprocess":
> 
> sam...@linux-912g:~> python
> Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
> [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import subprocess
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/subprocess.py", line 404, in 
> import pickle
>   File "/usr/lib/python2.6/pickle.py", line 171, in 
> class Pickler:
>   File "/usr/lib/python2.6/pickle.py", line 250, in Pickler
> def put(self, i, pack=struct.pack):
> AttributeError: 'module' object has no attribute 'pack'
> 
> Any ideas how to fix this?
> 
> Kind Regards,

Is there another struct module that is overriding the built-in one?

>>> import struct
>>> struct.__file__


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


Re: How to create an array which can be used also as a dictionary

2009-09-10 Thread Hans Müller
Diez B. Roggisch wrote:
> Hans Müller wrote:
> 
>> Hello,
>>
>> I have a lot of items having a name and a given sequence.
>>
>> To access these items fast in a sequence order they should be used as
>> a list, but to be fetched fast by name they also should be in a
>> dictionary.
>>
>> Code could be something like this.
>>
>> class item
>> def __init__(name, value1, value2, value3):
>> self.name = name
>> self.value1 = value1
>> self.value2 = value2
>>
>> a = []
>> a.append(item("foo", "bar", "text1"))
>> a.append(item("xyz", "basd", "tsddsfxt1"))
>> a.append(item("aax", "hello", "dont care"))
>>
>> in a, i have my objects in given order, fast accessible by index, e.g.
>> a[2] to get the third one. Fine.
>>
>> Now I'd like to have a dict with references to thes objects like this:
>>
>> d = {}
>> for x in a:
>> d[a.name] = a # do I get a copy of a here or a new reference ?!
> 
> Only a reference.
great, this is in my case what I'm looking for.
> 
>> In d i now have a dict, fast accessible by name.
>> But what happens if i modify
>> a[1].value1 = 1000
>> is
>> d["aax"].value1 now 1000 or still "hello" as in this example ?
> 
> It's changed. Didn't you try that? 
> 
> Diez
to be true, no - not in this direct context.

btw. how can I get a copy when I need it ?

Thanks a lot, Hans

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


Re: How to create an array which can be used also as a dictionary

2009-09-10 Thread Chris Rebert
On Thu, Sep 10, 2009 at 12:51 PM, Hans Müller  wrote:
> Diez B. Roggisch wrote:
>> Hans Müller wrote:

>>> But what happens if i modify
>>> a[1].value1 = 1000
>>> is
>>> d["aax"].value1 now 1000 or still "hello" as in this example ?
>>
>> It's changed. Didn't you try that?
>>
> to be true, no - not in this direct context.
>
> btw. how can I get a copy when I need it ?

The `copy` module:
http://docs.python.org/library/copy.html

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: 'module' object has no attribute 'pack'

2009-09-10 Thread Sampsa Riikonen
Hello,

I already solved this.. I had to set

PYTHONPATH=

After that the error msg disappeared.
Weird though.. I don't have any module called "subprocess"
in my personal python modules directory.

Anyway, thanks for the swift reply!

Regards,

Sampsa

On Thursday 10 September 2009 10:40:11 pm Albert Hopkins wrote:
> On Thu, 2009-09-10 at 21:07 +0300, Sampsa Riikonen wrote:
> > Dear List,
> >
> > I have a freshly installed opensuse 11.2 and I am experiencing the
> > following problem with the module "subprocess":
> >
> > sam...@linux-912g:~> python
> > Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
> > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> > >>> import subprocess
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File "/usr/lib/python2.6/subprocess.py", line 404, in 
> > import pickle
> >   File "/usr/lib/python2.6/pickle.py", line 171, in 
> > class Pickler:
> >   File "/usr/lib/python2.6/pickle.py", line 250, in Pickler
> > def put(self, i, pack=struct.pack):
> > AttributeError: 'module' object has no attribute 'pack'
> >
> > Any ideas how to fix this?
> >
> > Kind Regards,
>
> Is there another struct module that is overriding the built-in one?
>
> >>> import struct
> >>> struct.__file__


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


Re: logging sound / speech handler?

2009-09-10 Thread Matteo
On Sep 9, 6:02 pm, Tim Chase  wrote:
> > For an application in an industrial environment where the workers are
> > not always sitting in front of the monitor, but are within earshot of
> > the PC I would need an sound / speech handler for the standard logging
> > system. It should beep or better say the logging message. (with
> > standard filtering etc.)
> > I google search was not successfull.
> > Does anybode know of such a handler?
...
>
> On *nix, there's the Festival/Flite/Mbrola suite of TTS tools.
> You might be able to have one of their toolkit listen on a pipe
> to read whatever comes in, and then just log to that FIFO target
> as a file.
>
> -tkc

Also, in the unlikely event that you are using a Mac for industrial
applications, you can use the OS X "say" command in a similar manner,
using Popen. Or, for very infrequent messages, just os.system("say " +
log_text).

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


Re: AttributeError: 'module' object has no attribute 'pack'

2009-09-10 Thread Jerry Hill
On Thu, Sep 10, 2009 at 4:21 PM, Sampsa Riikonen  wrote:
> Hello,
>
> I already solved this.. I had to set
>
> PYTHONPATH=
>
> After that the error msg disappeared.
> Weird though.. I don't have any module called "subprocess"
> in my personal python modules directory.

You have a module named struct.py (or strucy.pyc) that is shadowing
the builtin struct module.

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


Re: Download and save a picture - urllib

2009-09-10 Thread MRAB

mattia wrote:
You were right, the problem was with the print function, using a normal 
write everythong works fine.



You should open the output file as binary (it doesn't matter on
Linux/Unix, but is a good idea anyway for portability).


Il Thu, 10 Sep 2009 18:56:07 +0200, Diez B. Roggisch ha scritto:


mattia wrote:


Hi all, in order to download an image. In order to correctly retrieve
the image I need to set the referer and handle cookies.

opener = urllib.request.build_opener(urllib.request.HTTPRedirectHandler
(), urllib.request.HTTPCookieProcessor())
urllib.request.install_opener(opener) req =
urllib.request.Request("http://myurl/image.jpg";)
req.add_header("Referer", "http://myulr/referer.jsp";) r =
urllib.request.urlopen(req)
with open("image.jpg", "w" ) as fd:
print(r.read(), file=fd)

I'm not able to correctly save the image. In fact it seems that it it
saved in hex format. Any suggestion?

How do you come to the conclusion that it's saved as "hex"? It sure
isn't - either the request fails because the website doesn't allow it
due to missing cookies or similar stuff - or you get the binary data.

But you should be aware that in the interpreter, strings are printed out
with repr() - which will convert non-printable characters to their
hex-representation to prevent encoding/binary-data-on-teriminal-issues.



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


Re: New Tkinter windows don't get focus on OS X

2009-09-10 Thread Kevin Walzer

Hi Joshua,


At first I was puzzled by this, because if you run something like
"open -a TextEdit", TextEdit gets the focus. But then I realized this
must be because of the "open" command. Indeed, if you try running
something like "/Applications/MacPorts/Python\ 2.6/IDLE.app/Contents/
MacOS/IDLE" focus will remain in Terminal.


OK...



On the other hand, every other GUI toolkit I've used (e.g. wxPython,
PyQt4, pyglet) does not have this problem. (If you try the basic
example from http://www.wxpython.org/tut-part1.php you'll see what I
mean.) How are these other toolkits able to steal the focus? More
important, is it *possible* to have a Tkinter app steal the focus,
even if it's not the default behavior?


I've confirmed this with wx...not sure why Tk behaves differently.




The way around this is to wrap your application up in a standard Mac app
bundle using py2app. The average Mac user isn't going to launch a
Python-based game from the command line.


True, but it'll still be a lot less painful for me to test my app if I
can get it to steal focus
when launched from the command line. If anyone knows how to do this in
Tkinter, help would be much appreciated.


I'm not sure there's a way to do this.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to create an array which can be used also as a dictionary

2009-09-10 Thread Terry Reedy

Hans Müller wrote:

Hello,

I have a lot of items having a name and a given sequence.

To access these items fast in a sequence order they should be used as a 
list, but to be fetched fast by name they also should be in a dictionary.


Have you looked at namedtuple or OrderedDict in collections module?

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


Re: s.index(x[, i[, j]]) will change the s ?

2009-09-10 Thread Terry Reedy

Chris Rebert wrote:

On Wed, Sep 9, 2009 at 10:00 PM, s7v7nislands wrote:

I known index() does not modify the sequence itself. my question is so
why the doc put the index() method in the mutable sequence types list?


Because once upon a time, only lists and not tuples had the method.


Ah, okay. Now I understand your question. I don't know really. I
suppose it could just as well go under the more general table for
"6.6. Sequence Types". I'd guess it's under Mutable Sequence Types for
convenience's sake since .remove() is mutable-only and makes reference
to the same footnote. You could file a documentation bug:
http://bugs.python.org


I already did.
http://bugs.python.org/issue4966

Producing an edited version of the doc text from my suggestions is on my 
todo list if no one beats me to it. I need to learn .rst better, though.


tjr

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


Question about unpickling dict subclass with custom __setstate__

2009-09-10 Thread Matthew Wilson
I subclassed the dict class and added a __setstate__ method because I
want to add some extra steps when I unpickle these entities.  This is a
toy example of what I am doing:

class Entity(dict):

def __setstate__(self, d):

log.debug("blah...")

Based on my experiments, the data in d *IS NOT* the data stored in my
instances when I do stuff like:

e = Entity()
e['a'] = 1

Instead, the stuff in d is the data stored when I do stuff like:

e.fibityfoo = 99

Here's my question:

Is there anything I have to do to make sure that my real dictionary data
is correctly reloaded during the unpickle phase?  In other words, should
I run super(Entity, self).__setstate__(d) or something like that?

TIA

Matt

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


Re: unicode + xml

2009-09-10 Thread Laurent Luce
Still doesn't work from Windows Japanese python (2.6.2) to Django Python 2.5.2. 
Works fine from Linux python 2.5.2 to Django Python 2.5.2.

Here is the flow:

- post xml utf-8 encoded data from Windows client to Django server
- On server: pass raw_post_data to minidom.parseString() ---> throws exception

Here is the code I use to post data:

url = mysite
req = urllib2.Request(url)
req.add_header('Content-Type', 'text/xml; charset=utf-8')
opener.open(req, data.encode('utf-8'))

data is the xml data
opener is a urllib2 opener I create when user logs in.

Here is the code I use to receive the data:

dom = minidom.parseString(request.raw_post_data)

default charset on django side is utf-8.

Please advise. Thanks.

Laurent



- Original Message 
From: Stefan Behnel 
To: [email protected]
Sent: Monday, September 7, 2009 11:50:28 PM
Subject: Re: unicode + xml

Laurent Luce wrote:
> Can someone confirm that the issue here is I need to encode the xml data 
> using:
> # encode as UTF-8
> utf8_string = xml.encode( 'utf-8' )
> and then post it to the server.

Well, since you declared it to be UTF-8, it must be UTF-8 encoded.

However, your question seems to imply that you generate the XML manually
using string concatenation, which is a rather bad idea. Python has great
XML tools like ElementTree that help in generating and serialising XML
correctly (besides parsing, searching and other things).

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

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


Re: Using freeze.py's output and compiling in Windows

2009-09-10 Thread Peter
On Sep 11, 3:24 am, "Di Biase, Paul A CIV NAVAIR, 4.4"
 wrote:
> No one?

What's wrong with py2exe? You don't have to stop there you know - I
distribute using py2exe and then use Inno Setup to create the Windows
Installer. Works a treat.

Note that if you are using Python 2.6 (not sure about 3.X) you will
need to include the Microsoft Visual C++ Feature Pack Redistributable
(vcredist_x86.exe) otherwise you will get a weird runtime error if the
PC you are installing too doesn't already have Python2.6 installed.

If you look in the py2exe samples/extending directory you will find a
setup.py that uses InnoSetup - I deleted the manifest stuff because I
couldn't understand it (not a Windows programmer - and proud of
it! :-)). In conjunction with the InnoSetup documentation I got it all
going and have distributed two applications thus far.

py2exe + InnoSetup = good combination! :-)

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


threading question

2009-09-10 Thread Mag Gam
Hello,

Currently, I am using a bash script to ssh into 400 servers and get an
output, ie check if a file exists on a local filesystem.  I am doing
this linearly, however I am interesting in doing this with threads and
more important using Python standard threading library.

My pseudo code would be something like this:

Have a list of the servers in a dictionary
Create the number of threads which correspond to servers.  ie 400 threads
Each thread will spawn ssh and execute the file test
Once all threads are completed, I send a signal saying "all is one",
and it will create some sort of output.


Is there a better way of doing this? My goal is to learn python and
threading, I know this is a silly example but its worth a try :-)

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


Re: AttributeError: 'module' object has no attribute 'pack'

2009-09-10 Thread Ben Kaplan



On Sep 10, 2009, at 4:21 PM, Sampsa Riikonen   
wrote:



Hello,

I already solved this.. I had to set

PYTHONPATH=

After that the error msg disappeared.
Weird though.. I don't have any module called "subprocess"
in my personal python modules directory.

Anyway, thanks for the swift reply!

Regards,

Sampsa



Acually, it looks like the offending module is struct which is called  
by pickle which is called by subprocess. Do you have a struct.py?



On Thursday 10 September 2009 10:40:11 pm Albert Hopkins wrote:

On Thu, 2009-09-10 at 21:07 +0300, Sampsa Riikonen wrote:

Dear List,

I have a freshly installed opensuse 11.2 and I am experiencing the
following problem with the module "subprocess":

sam...@linux-912g:~> python
Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more  
information.



import subprocess


Traceback (most recent call last):
 File "", line 1, in 
 File "/usr/lib/python2.6/subprocess.py", line 404, in 
   import pickle
 File "/usr/lib/python2.6/pickle.py", line 171, in 
   class Pickler:
 File "/usr/lib/python2.6/pickle.py", line 250, in Pickler
   def put(self, i, pack=struct.pack):
AttributeError: 'module' object has no attribute 'pack'

Any ideas how to fix this?

Kind Regards,


Is there another struct module that is overriding the built-in one?


import struct
struct.__file__



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

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


Re: Using freeze.py's output and compiling in Windows

2009-09-10 Thread John Yeung
On Sep 10, 7:53 am, "Di Biase, Paul A CIV NAVAIR, 4.4"
 wrote:
> I'd like another avenue besides using
> py2exe as a bundling tool.
>
> This lead me to looking at freeze.py.

Judging by the wiki page (http://wiki.python.org/moin/Freeze) and some
other miscellaneous Googling, it would seem freeze is merely *nix's
py2exe (or py2exe is Windows's freeze).  I think if you were to make
the necessary adjustments to freeze.py in order to make it generate
Windows executables, what you'd end up with is essentially your own
version of py2exe.  I would not be at all surprised if that is
actually how py2exe came into existence in the first place.

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


Re: threading question

2009-09-10 Thread MRAB

Mag Gam wrote:

Hello,

Currently, I am using a bash script to ssh into 400 servers and get an
output, ie check if a file exists on a local filesystem.  I am doing
this linearly, however I am interesting in doing this with threads and
more important using Python standard threading library.

My pseudo code would be something like this:

Have a list of the servers in a dictionary
Create the number of threads which correspond to servers.  ie 400 threads
Each thread will spawn ssh and execute the file test
Once all threads are completed, I send a signal saying "all is one",
and it will create some sort of output.


Is there a better way of doing this? My goal is to learn python and
threading, I know this is a silly example but its worth a try :-)


I wouldn't use that many threads. It's better to use a relatively small
number of them (not more than 10, perhaps?) and let each thread do
multiple jobs, one at a time.

Here some example code:


# For Python 2.5 and later

from threading import Thread
from Queue import Queue

class ThreadTask(object):
def __init__(self, task_queue):
self.task_queue = task_queue
def __call__(self):
while True:
task = self.task_queue.get()
if task is None:
# A None indicates that there are no more tasks.
break
self.process_task(task)
# Put back the None so that the next thread will also see it.
self.task_queue.put(None)
def process_task(self, task):
# Put your code here
...

MAX_RUNNING = 10

# Put the tasks into a queue, ending with a None.
task_queue = Queue()
for t in task_list:
task_queue.put(t)
task_queue.put(None)

# Start the threads to do the work.
thread_list = []
for i in range(MAX_RUNNING):
t = Thread(target=ThreadTask(task_queue))
t.start()
thread_list.append(t)

# The threads will finish when they see the None in the task queue.
for t in thread_list:
t.join()

# When you get here all the task will have finished.
--
http://mail.python.org/mailman/listinfo/python-list


Bringing schools into the present: Teachers, schools lagging behind students in tech savvy

2009-09-10 Thread bilawal samoon
It's been said that in the "real world" students are more
technologically advanced than their teachers because technology
surrounds most of their day's activities. Teachers of the baby boom
generation, on the other hand, having not grown up with computers, are
constantly learning from their students.
For more details www.technicaledu.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Got homework? Need help?

2009-09-10 Thread bilawal samoon
Students at Salina Central High School who are receiving much needed
help with their homework can perversely thank a racially motivated
shooting in Woodland Park in early 2008.
For more details www.technicaledu.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python server locks up

2009-09-10 Thread Zac Burns
On Wed, Sep 9, 2009 at 6:52 PM, David Stanek  wrote:
> On Wed, Sep 9, 2009 at 4:28 PM, Zac Burns wrote:
>>
>> How would you suggest to figure out what is the problem?
>>
>
> I don't think you said your OS so I'll assume Linux.
>
> Sometimes it is more noise than value, but stracing the process may
> shed light on what system calls are being made. This in turn may help
> you narrow your focus. I find strace helps me a ton in some really
> tough problems.
>
> Are you watching for swapping, CPU usage, etc.?
>
> --
> David
> blog: http://www.traceback.org
> twitter: http://twitter.com/dstanek
>

The OS is Windows Server 2003 x64.

CPU ranges from 0% to 1%, there is no disk IO, and it eats ram at ~1MB/2sec.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python SSH interface

2009-09-10 Thread Mag Gam
its not a google/bing issue. Its about getting opinions from the
community and hear their experiences. I wanted to hear opinions and
war stories of people who tried using ssh with python, thats all.



On Fri, Sep 4, 2009 at 8:43 AM, Diez B. Roggisch  wrote:
> Mag Gam wrote:
>
>> Is there something similar to NetSSH
>> (http://search.cpan.org/dist/Net-SSH-Perl/) for python?
>
> Google dead today? From the > 3.000.000 answers for python + ssh, I suggest
> paramiko, but there are more options.
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does python 3.1 support sybase module?

2009-09-10 Thread alex23
On Sep 10, 4:17 pm, "Michel Claveau -
MVP" wrote:
> What is this final comma?  

My guess without looking at the code is that the line occurs in a dict
definition:

PACKET_OF_VALUES = dict(
maintainer=u"Sebastien Sable",
version=3.0,
...
)

Either that or 'maintainer' is a tuple ;)

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


Re: An assessment of the Unicode standard

2009-09-10 Thread Jan Claeys
Op Sun, 30 Aug 2009 15:28:55 -0700, schreef r:

> I said it before and i will say it again. I DON"T CARE WHAT LANGUAGE WE
> USE AS LONG AS IT IS A MODERN LANGUAGE FOUNDED ON IDEALS OF
> SIMPLICITY

Maybe we should use a language that has a Turing-complete grammar, so 
that even computers can understand & speak it "easily"?

http://www.economicexpert.com/a/Panini:scholar.htm
(with thanks to Anna Ravenscroft for pointing me to this some time ago)

When used by everyone, it would allow us to write programs in the 
language all of us speak...  *Maybe*...  :P


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


Re: Python SSH interface

2009-09-10 Thread Sean DiZazzo
On Sep 10, 6:14 pm, Mag Gam  wrote:
> its not a google/bing issue. Its about getting opinions from the
> community and hear their experiences. I wanted to hear opinions and
> war stories of people who tried using ssh with python, thats all.
>

This question gets asked at least once a week.  It *is* a Google
issue.

The first hit mentions:

pyssh
paramiko
pexpect + pxssh

with opinions of each.

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