Re: problem with sorting

2008-03-28 Thread raj
To ankit:

Well, sort() doesn't return the sorted list. It returns None. Why not
this straightforward way?
dvals = dict.values()
dvals.sort()
print dvals
-- 
http://mail.python.org/mailman/listinfo/python-list


Plugins accessing parent state

2008-03-28 Thread [EMAIL PROTECTED]
Does anyone have some design ideas ( or can point me at the right
design pattern, because I can't find it. ) for having a plugin being
able to access a parent's state?

For example, let's say I have a class that receives some commands.
When it gets a command, it checks which of the registered plugins
deals with that command and passes the details of the command off to
that plugin.  So I'd end up with something like..

result = plugin.do(msg_details)

Now, I want to write a plugin called "help" that loops through all the
registered plugins and prints out their doc strings.  If all my plugin
is getting is the msg details, how is it supposed to get the list of
available plugins from the calling class?

Or, for instance, let's say my class loads a configuration file that
lists a set of admins who can enter commands.  I want the plugins, if
they so choose,  to be able to test if the msg came from an admin, but
again, I'm not passing the admin list into every plugin, it's just in
my calling class.  I could make the plugin specify an attribute for
itself, like "admin_only" and test for that before I pass the command
but what if certain parts of the plugin are to be restricted and
others aren't, based on the details of the command sent?

Is this as simple as just passing the instance of my class to each
plugin?  It doesn't seem like the proper thing to do, because now the
plugin class has the capability of accessing the whole bot's
interface.

I realize that this is all just theory but I'd appreciate any points
in the right direction.

Thanks.

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


Re: Plugins accessing parent state

2008-03-28 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Does anyone have some design ideas ( or can point me at the right
> design pattern, because I can't find it. ) for having a plugin being
> able to access a parent's state?
> 
> For example, let's say I have a class that receives some commands.
> When it gets a command, it checks which of the registered plugins
> deals with that command and passes the details of the command off to
> that plugin.  So I'd end up with something like..
> 
> result = plugin.do(msg_details)
> 
> Now, I want to write a plugin called "help" that loops through all the
> registered plugins and prints out their doc strings.  If all my plugin
> is getting is the msg details, how is it supposed to get the list of
> available plugins from the calling class?
> 
> Or, for instance, let's say my class loads a configuration file that
> lists a set of admins who can enter commands.  I want the plugins, if
> they so choose,  to be able to test if the msg came from an admin, but
> again, I'm not passing the admin list into every plugin, it's just in
> my calling class.  I could make the plugin specify an attribute for
> itself, like "admin_only" and test for that before I pass the command
> but what if certain parts of the plugin are to be restricted and
> others aren't, based on the details of the command sent?
> 
> Is this as simple as just passing the instance of my class to each
> plugin?  It doesn't seem like the proper thing to do, because now the
> plugin class has the capability of accessing the whole bot's
> interface.

Yes, it is simple as that. Of course you can choose *what* you pass, if 
you want to restrict that - nobody forces you to pass the whole 
plugin-manager, if that would expose properties/methods you wouldn't 
want ther.

But to be honest: you are thinking much to far there - after all, it's 
all *your* code, and inside one interpreter. A real isolation isn't 
available anyway.

So just do what fullfills the functional requirements.

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


Re: Getting back an Object

2008-03-28 Thread Bruno Desthuilliers
Gary Herron a écrit :
(snip)
> One other word of warning.  It is best to not use a variable named 
> "string" as Python has a builtin type of that name which would become 
> inaccessible if you redefine.

Good advice, except that the builtin string type is actually named 
'str', not 'string' !-)

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


chronic error with python on mac os/x 10.5

2008-03-28 Thread Tzury Bar Yochay
Although I am experiencing this problem using a specific domain
library (pjsip). Googling this issue show that it is happening to many
libraries in python on mac.

I was wondering whether anyone solved this or alike in the past and
might share what steps were taken.
Note: this python lib works fine on other platforms (posix, win, and
earlier versions of mac os x)

>>> import py_pjsua
Traceback (most recent call last):
  File "", line 1, in 
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/site-packages/py_pjsua.so, 2): Symbol not found:
___CFConstantStringClassReference
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/site-packages/py_pjsua.so
  Expected in: dynamic lookup
-- 
http://mail.python.org/mailman/listinfo/python-list


Eclipse and PyDev Package explorer

2008-03-28 Thread king kikapu
Hi,

i am trying to "fit" Eclipse/Pydev in my needs/preference, so i want
to ask this:

As it is now, i see all my projects in that TreeView (PyDev Package
Explorer). I would rather want this to behave like a more "normal" IDE
where you Open one project and if you want close it and Open another,
just one at a time and not a TreeView with ALL your projects loaded in
every time you open the IDE.

Is there a way to accomplish thiks in Eclipse/Pydev ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plugins accessing parent state

2008-03-28 Thread [EMAIL PROTECTED]
On Mar 28, 1:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
>
>
> > Does anyone have some design ideas ( or can point me at the right
> > design pattern, because I can't find it. ) for having a plugin being
> > able to access a parent's state?
>
> > For example, let's say I have a class that receives some commands.
> > When it gets a command, it checks which of the registered plugins
> > deals with that command and passes the details of the command off to
> > that plugin.  So I'd end up with something like..
>
> > result = plugin.do(msg_details)
>
> > Now, I want to write a plugin called "help" that loops through all the
> > registered plugins and prints out their doc strings.  If all my plugin
> > is getting is the msg details, how is it supposed to get the list of
> > available plugins from the calling class?
>
> > Or, for instance, let's say my class loads a configuration file that
> > lists a set of admins who can enter commands.  I want the plugins, if
> > they so choose,  to be able to test if the msg came from an admin, but
> > again, I'm not passing the admin list into every plugin, it's just in
> > my calling class.  I could make the plugin specify an attribute for
> > itself, like "admin_only" and test for that before I pass the command
> > but what if certain parts of the plugin are to be restricted and
> > others aren't, based on the details of the command sent?
>
> > Is this as simple as just passing the instance of my class to each
> > plugin?  It doesn't seem like the proper thing to do, because now the
> > plugin class has the capability of accessing the whole bot's
> > interface.
>
> Yes, it is simple as that. Of course you can choose *what* you pass, if
> you want to restrict that - nobody forces you to pass the whole
> plugin-manager, if that would expose properties/methods you wouldn't
> want ther.
>
> But to be honest: you are thinking much to far there - after all, it's
> all *your* code, and inside one interpreter. A real isolation isn't
> available anyway.
>
> So just do what fullfills the functional requirements.
>
> diez

Since I want to have a uniform call to all plugins, would it make
sense to split out the attributes that I do want to share to a
separate class and then simply create a new instance of that class and
store it in the main class?

For instance

...
self.utilities = Utilities(self)
...
plugin.do(msg,self.utilities)

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


Re: Eclipse and PyDev Package explorer

2008-03-28 Thread king kikapu
A, and another one: If i set a custom builder for a pydev project, is
there a way for this builder to automatically be "assigned" to every
(pydev) project i will create from now on or i have to re-define it
for every new one ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plugins accessing parent state

2008-03-28 Thread André
On Mar 28, 6:39 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Mar 28, 1:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
>
>
> > [EMAIL PROTECTED] schrieb:
>
> > > Does anyone have some design ideas ( or can point me at the right
> > > design pattern, because I can't find it. ) for having a plugin being
> > > able to access a parent's state?
>
> > > For example, let's say I have a class that receives some commands.
> > > When it gets a command, it checks which of the registered plugins
> > > deals with that command and passes the details of the command off to
> > > that plugin.  So I'd end up with something like..
>
> > > result = plugin.do(msg_details)
>
> > > Now, I want to write a plugin called "help" that loops through all the
> > > registered plugins and prints out their doc strings.  If all my plugin
> > > is getting is the msg details, how is it supposed to get the list of
> > > available plugins from the calling class?
>
> > > Or, for instance, let's say my class loads a configuration file that
> > > lists a set of admins who can enter commands.  I want the plugins, if
> > > they so choose,  to be able to test if the msg came from an admin, but
> > > again, I'm not passing the admin list into every plugin, it's just in
> > > my calling class.  I could make the plugin specify an attribute for
> > > itself, like "admin_only" and test for that before I pass the command
> > > but what if certain parts of the plugin are to be restricted and
> > > others aren't, based on the details of the command sent?
>
> > > Is this as simple as just passing the instance of my class to each
> > > plugin?  It doesn't seem like the proper thing to do, because now the
> > > plugin class has the capability of accessing the whole bot's
> > > interface.
>
> > Yes, it is simple as that. Of course you can choose *what* you pass, if
> > you want to restrict that - nobody forces you to pass the whole
> > plugin-manager, if that would expose properties/methods you wouldn't
> > want ther.
>
> > But to be honest: you are thinking much to far there - after all, it's
> > all *your* code, and inside one interpreter. A real isolation isn't
> > available anyway.
>
> > So just do what fullfills the functional requirements.
>
> > diez
>
> Since I want to have a uniform call to all plugins, would it make
> sense to split out the attributes that I do want to share to a
> separate class and then simply create a new instance of that class and
> store it in the main class?
>
> For instance
>
> ...
> self.utilities = Utilities(self)
> ...
> plugin.do(msg,self.utilities)

I would bypass the step of creating a new instance and write instead
plugin.do(msg, self)
thus having access to all properties/methods of the calling object.
Why restrict it?...

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


Re: any good g.a.'s?

2008-03-28 Thread castironpi
On Mar 25, 11:03 am, Tim Chase <[EMAIL PROTECTED]> wrote:
> > Any good genetic algorithms involving you-split, i-pick?
>
> I've always heard it as "you divide, I decide"...
>
> That said, I'm not sure how that applies in a GA world.  It's
> been a while since I've done any coding with GAs, but I don't
> recall any facets related to the You Divide, I Decide problem.
> It sounds like a simple optimization of "equality", which would
> be a normal use of a GA.  This would apply for both the division
> and the decision, depending on which side the GA is (the "you" or
> the "I") or two diff. GAs can be on either side of the process.
>
> -tkc

Tim, if you have any interest in the stuff:

You Divide I Decide YDID only works where resources are highly
divisible: Except if, do livelock or deadlock occur in real time?  If
I get in line for going to bars, I enter a decreased-expressivity (-
outlet) state, open up, close, and come sit down.  Now, what do I
generally yield?  A life's story.  I think I 'send' a request for
details in the form of a repetition, except it takes into account a
lot of computation, spef. my understading.  I also think I look for a
'random' generator to call 'send' on, but that could just be
prioritized by strength of pole, but here's the important part, -at- -
the- -time-.  Taking priority graph/queue to be a function of the
past, you can classify into spatial pole and cumulative pole; just the
sense mechanata 'say where': 'we favor X' progressively over time.

Back at the fork in the road, I was favoring a turn, not a path.  I
can make a dual, and for the sake of discussion, entertain I do.  Are
you a musician?  Is Heaven a noninterest market?  Electricity is a
uniform current, highly potent (can sterilize+neutralize), highly
uniform (verb regulize).  I don't like "discovering poles" "once on
the road (just to where)"; I think they're a net quality of life
decrease; I don't like poles; they make one answer, heavy questions.
Computers at least, can't come and answer; hypothetically,
analytically, their pulls can't either.  (Computers and their pulls,
doh.)  However, if I create pole by my actions, they're only part to
blame (yes, instead of entirely either or not).

Except but, how do I get home?  I don't get random homes, it's the
same one.  Neither does my home pull random people (is it a pole to).
It's weird: you can bury latent poles, though clearly time isn't the
fuse-length.  Contingently exclusive (upon?).  There's a layer of
discouragement for everything and around everyone else's; surprising
me at home is repulsive, lightly.  Eating is attractive, more and less
over time, sometimes crucial (oddly enough); it creates a junction by
outweighing discouragement.  (My kitchen is extremely unattractive but
not repulsive at all, any farther than the newcome stir, which will
come with me after that, though the process of dissipation is a little
mysterious-- LaPlace?)  There's no good framework for composing (draw
analogy to, analogee) the process of emancipation (w.c.) and
dissipation, so I lean to church, even though it's chalk-full of non-
mathematical (non-vicarous) remarks: "We come, and the vicar leaves.
He's just of no interest."  Interest might be mutual too, but only in
magnitude.  I don't like attraction wars.  Can I get a tongue
regressed (cf. kitchen sink regression)?  Are we in Economics?
There's money in it.  I have to go speak French.  Je dois aller.

http://www.westga.edu/~jhasbun/osp/Fourier.htm

If you receive a sign, do you just design it?  What if you have a more
clever way to spell a word, qua composite sign?  What if you spell it
the old way?  Consign, design, ensign, and resign.  The English tongue
is really 'pulling forward' quite fast.

Time is generational in facet.  (Is a phoneme a particle?  Phones are
not.)

I think time means 'generation', which you can do across space.  Ears
receive 1-D parametric impressions, Eyes receive 2-D.  I don't know of
much work in deparametrization, but method iteration ( f_i=
f( f_(i-1) ) ), representing space as time, creates generations of
something.  Problem is, iterations are chosen by somebody, what
function to call next in time, so there is a lot of money in choosing
functions to call in order, es. if it's refining parameters to other
functions.  Feedback on computers is lightning-fast, bringing billion-
baud guess-and-checking to hands.

If you were a tuple, what tuple would you be?  Encode, hash, and
echo?  Do you GOTO home or GOSUB home?  What if you limited call stack
depth to like five?
-- 
http://mail.python.org/mailman/listinfo/python-list


pygame handoff

2008-03-28 Thread castironpi
Can anyone do a simple pygame render of a rollercoaster in first-
person?  I'll do the generator.  Just for fun for free.  (Ha see
pythaagh.  He bothered to carve it.  Have a nice day.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic code problem

2008-03-28 Thread Simon Brunning
On Thu, Mar 27, 2008 at 4:13 PM,  <[EMAIL PROTECTED]> wrote:
> My dynamic code failed at this site http://playwide1.extra.hu/, need
>  some help thank you.



-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-28 Thread castironpi
On Mar 28, 1:57 am, raj <[EMAIL PROTECTED]> wrote:
> To ankit:
>
> Well, sort() doesn't return the sorted list. It returns None. Why not
> this straightforward way?
> dvals = dict.values()
> dvals.sort()
> print dvals

Why not sorted( dict.values() ).

Can it return the right things from the right things in order from the
givens?  ( dvals , values, sort, print ).decode()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic code problem

2008-03-28 Thread castironpi
On Mar 28, 5:14 am, "Simon Brunning" <[EMAIL PROTECTED]> wrote:
> On Thu, Mar 27, 2008 at 4:13 PM,  <[EMAIL PROTECTED]> wrote:
> > My dynamic code failed at this sitehttp://playwide1.extra.hu/, need
> >  some help thank you.
>
> 

I almost clicked on that *plonk*.  Plonk?  Plonk who?

Knock, knock.  Please don't pet the snake.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eclipse and PyDev Package explorer

2008-03-28 Thread olive
Hi,

normally you just have to select your top level project folder in the
Package
Explorer and then from the menu bar choose Project -> Close Project
(also accessible by the popup menu assigned to the right button of
your mouse).

HTH,

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


Re: problem with sorting

2008-03-28 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> On Mar 28, 1:57ÿam, raj <[EMAIL PROTECTED]> wrote:
>> To ankit:
>>
>> Well, sort() doesn't return the sorted list. It returns None. Why not
>> this straightforward way?
>> dvals = dict.values()
>> dvals.sort()
>> print dvals
> 
> Why not sorted( dict.values() ).
> 

If you are going to do it that way then it may be preferable to use 
itervalues:

   print sorted(dict.itervalues())

Both this and raj's suggestion create a single sorted list. Your suggestion 
creates two lists: the unsorted one and a separate sorted one. In most 
cases the difference is probably insignificant, but if you have a *lot* of 
values it might make a difference.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plugins accessing parent state

2008-03-28 Thread Bruno Desthuilliers
André a écrit :
> On Mar 28, 6:39 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> On Mar 28, 1:58 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
(snip)
>>> But to be honest: you are thinking much to far there - after all, it's
>>> all *your* code, and inside one interpreter. A real isolation isn't
>>> available anyway.
>>> So just do what fullfills the functional requirements.
 >>
>> Since I want to have a uniform call to all plugins, would it make
>> sense to split out the attributes that I do want to share to a
>> separate class and then simply create a new instance of that class and
>> store it in the main class?
>>
>> For instance
>>
>> ...
>> self.utilities = Utilities(self)
>> ...
>> plugin.do(msg,self.utilities)
> 
> I would bypass the step of creating a new instance and write instead
> plugin.do(msg, self)
> thus having access to all properties/methods of the calling object.
> Why restrict it?...

+1 on this.

And FWIW, *if* you later find out you *really* need to restrict access 
to the caller object's attribute (ie: 'self'), it will be as simple as 
wrapping it in a decorator (design pattern, not function decorator) 
object that will take care of this, ie (Q&D naive implementation):

class RestrictedSelf(object):
allowed_attributes = ('dothis', 'dothat')
def __init__(self, realself):
   self.realself = realself
def __getattr__(self, name):
   if name.startswith('_') or name not in self.allowed_attributes:
   raise AttributeError(
   'access to %s.%s is forbidden' % (self.realself, name)
   )
   return getattr(self.realself, name)


And in the call to the plugin:

 plugin.do(msg, RestrictedSelf(self))


But my bet is that YAGNI, so to make a long story short: start with the 
simplest thing that could possibly work !-)


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


Re: **************************************************************

2008-03-28 Thread Jetus
On Mar 28, 5:44 am, [EMAIL PROTECTED] wrote:
> **
> When you make a Web page available offline, you
> can read its content when your computer is not
> connected to the Internet. For example, you can
>  view Web pages on your laptop computer when you
>  don't have a network or Internet connection. Or
> you can read Web pages at home without tying up
> a phone line.
>
> You can specify how much content you want available,
> such as just a page, or a page and all its links, and
>  choose how you want to update that content on your computer.
>
> If you just want to view a Web page offline, and you don't
>  need to update the content, you can save the page on your
> computer. There are several ways you can save the Web page,
>  from just saving the text to saving all of the images and
> text needed to display that page as it appears on the Web.
> ***
> http:\\my profile6529.blogspot.com

Can't bring up your link..
 http:\\my profile6529.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


simple web-server

2008-03-28 Thread Pavol Murin
hello python users,

 could you point me to a very simple (single file is best) web-server?
I want to serve a few web-forms and run some shell scripts when the
forms are submitted. I might add Ajax later (this is not a
requirement, if it only supports forms it's OK).

 Longer story:

 I would like to provide a web-page for customization of an
application - it should run some shell commands as the user clicks
around in the page and at the end write a configuration file. I had a
look at the python wiki (http://wiki.python.org/moin/WebProgramming),
where various web servers and frameworks are listed. The frameworks
seem to heavy for such a simple task and BaseHTTPServer just seems to
be too light. So I took a look at the web-servers listed:
 httpy had the last release 1,5 years ago, Medusa more than 5 years,
Twisted seems to be able to do a lot, so probably not the simple thing
I'm looking for. CherryPy looks promising, however it is still 89
files (including some that can be removed).

 If CGIHTTPServer is a good answer, could you point me to a good
(nontrivial) example?

 thank you, muro
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chronic error with python on mac os/x 10.5

2008-03-28 Thread martin . laloux
I don't known pjsip but this problem generally occurs when the library
(dylib) on which the file (.so) depends is not the good one

> Googling this issue show that it is happening to many
> libraries in python on mac.

?? I am working in python on mac since a lot of time I seldom have
such problems. When you compile a .so file, it depends on a dylib
library and you must have the good one (version)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with sorting

2008-03-28 Thread bearophileHUGS
Duncan Booth:
> Both this and raj's suggestion create a single sorted list. Your suggestion
> creates two lists: the unsorted one and a separate sorted one. In most
> cases the difference is probably insignificant, but if you have a *lot* of
> values it might make a difference.

The good thing of Python 3.0 is that it forces you to do the right
thing here :-)

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


Re: PyQT / QDate / QTableWidget

2008-03-28 Thread David Boddie
On Wed Mar 26 15:13:09 CET 2008, wrightee wrote:

> My server gives me a string y[0]: "20080327", which I convert to a
> QDateTime object using:
> 
> x=QDateTime.fromString(y[0],"mmdd")
> 
> Printing x.toString("dd-mm-") gives me what I would expect -
> 27-03-2008

Strange. You should really be using "dd-MM-". Maybe this is why QDate
isn't behaving as you would expect - see below.

> What I'm trying to do though is add this to a QTableWidget item to
> create a date sortable column; I'm using this:
> 
> if type(y)==QDateTime:
> item=QTableWidgetItem()
> item.setData(Qt.DisplayRole,QVariant(y))

This should work fine.

> BUT.. I'm adding 90 dates going back from today and getting values
> that look like this:
> 
> 27/01/2007 00:12
> 28/01/2007 00:12
> 29/01/2007 00:12
> 30/01/2007 00:12
> 31/01/2007 00:12
> 01/01/2008 00:01
> 01/01/2008 00:02
> 01/01/2008 00:03
> 
> etc

Right. You can see the date and time because you're using a QDateTime object.

> I tried using QDate but couldn't seem to be able to get
> QDate.fromString to create an object at all.

This may have something to do with the format string you tried.

> Could someone please advise where I'm going wrong, the end result
> should be a column in my QTableWidget formatted dd/mm/ that can be
> sorted as dates, not strings, and originate from data formatted
> "MMDD"

Just use QDate objects instead of QDateTime objects and it should all just
work.

Good luck!

David
-- 
David Boddie
Lead Technical Writer, Trolltech ASA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple web-server

2008-03-28 Thread Larry Bates

On Fri, 2008-03-28 at 12:53 +0100, Pavol Murin wrote:
> hello python users,
> 
>  could you point me to a very simple (single file is best) web-server?
> I want to serve a few web-forms and run some shell scripts when the
> forms are submitted. I might add Ajax later (this is not a
> requirement, if it only supports forms it's OK).
> 
>  Longer story:
> 
>  I would like to provide a web-page for customization of an
> application - it should run some shell commands as the user clicks
> around in the page and at the end write a configuration file. I had a
> look at the python wiki (http://wiki.python.org/moin/WebProgramming),
> where various web servers and frameworks are listed. The frameworks
> seem to heavy for such a simple task and BaseHTTPServer just seems to
> be too light. So I took a look at the web-servers listed:
>  httpy had the last release 1,5 years ago, Medusa more than 5 years,
> Twisted seems to be able to do a lot, so probably not the simple thing
> I'm looking for. CherryPy looks promising, however it is still 89
> files (including some that can be removed).
> 
>  If CGIHTTPServer is a good answer, could you point me to a good
> (nontrivial) example?
> 
>  thank you, muro

Take a look at twisted web, it fits in between.

-Larry

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


Global variables in modules...

2008-03-28 Thread ttsiodras
With a.py containing this:

== a.py ===
#!/usr/bin/env python
import b

g = 0

def main():
global g
g = 1
b.callb()

if __name__ == "__main__":
main()
==

...and b.py containing...

= b.py =
import a, sys

def callb():
print a.g
==

...can someone explain why invoking a.py prints 0?
I would have thought that the global variable 'g' of module 'a' would
be set to 1...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv Parser Question - Handling of Double Quotes

2008-03-28 Thread Aaron Watters
On Mar 27, 6:00 pm, John Machin <[EMAIL PROTECTED]> wrote:
> ...The Python csv module emulates Excel in delivering garbage silently in
> cases when the expected serialisation protocol has (detectably) not
> been followed

Fine, but I'd say the heuristic adopted produces
bizarre and surprising results in the illustrated case.
It's a matter of taste of course...
  -- Aaron Watters

===
http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=mondo+bizarre
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic code problem

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 07:14:17 -0300, Simon Brunning  
<[EMAIL PROTECTED]> escribió:
> On Thu, Mar 27, 2008 at 4:13 PM,  <[EMAIL PROTECTED]> wrote:

>> My dynamic code failed at this site http:///, need
>>  some help thank you.
>
> 

I assumed it was just spam, not a question.

-- 
Gabriel Genellina

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


base64.urlsafe_b64encode and the equal character

2008-03-28 Thread Clodoaldo
I'm using a md5 hash encoded with base64.urlsafe_b64encode as a
parameter of a URL used to confirm a registration in a site. It has
been working great.

The url is like this:

http://example.com/ce?i=878&h=kTfWSUaby5sBu9bIfoR87Q==

Now i need to match that URL in a certain text and i realized that
urlsafe_b64encode uses the "=" character so i can't just use \w{24} to
match the parameter.

What i need to know is where can an equal char appear in a
urlsafe_b64encoded string?:

a)only at end;
b)both at the end and at the begginig;
c)anywhere in the string;

A sure answer will make my regexp safer.

In another point, does the "=" char make it urlunsafe? I guess not
because i believe it would only be unsafe if the equal appeared like
in "&var=" and since there are no "&" in the string than there is no
problem right? Or wrong?

Regards, Clodoaldo Pinto Neto
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I reconnect a disconnected socket?

2008-03-28 Thread Jason Kristoff
I'm trying to make something that once it is disconnected will 
automatically try to reconnect.  I'll add some more features in later so 
it doesn't hammer the server but right now I just want to keep it simple 
and get that part working.  The problem is that when I use sock.close I 
get an error message of
Bad File Descriptor
and if I either use shutdown or just go straight to reconnecting I get:
Transport endpoint is already connected

This is what I've got right now:

#! /usr/bin/env python
import socket, string
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def doconn():
 sock.connect(("localhost", 1234))
def dodiscon():
 sock.close()
 doconn()

doconn()

while (1):
 buffer = sock.recv(1024)
 if not buffer:
 dodiscon()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables in modules...

2008-03-28 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> With a.py containing this:
> 
> == a.py ===
> #!/usr/bin/env python
> import b
> 
> g = 0
> 
> def main():
> global g
> g = 1
> b.callb()
> 
> if __name__ == "__main__":
> main()
> ==
> 
> ...and b.py containing...
> 
> = b.py =
> import a, sys
> 
> def callb():
> print a.g
> ==
> 
> ...can someone explain why invoking a.py prints 0?
> I would have thought that the global variable 'g' of module 'a' would
> be set to 1...

When you run a.py as a script it is put into the sys.modules module cache
under the key "__main__" instead of "a". Thus, when you import a the cache
lookup fails and a.py is executed again. You end up with two distinct
copies of the script and its globals:

$ python -i a.py
0
>>> import __main__, a
>>> a.g
0
>>> __main__.g
1

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


Re: simple web-server

2008-03-28 Thread Thomas Guettler
Pavol Murin schrieb:
> hello python users,
> 
>  could you point me to a very simple (single file is best) web-server?
> I want to serve a few web-forms and run some shell scripts when the
> forms are submitted. I might add Ajax later (this is not a
> requirement, if it only supports forms it's OK).

If you want to run shell scripts, you might want to search for a web server 
written
in a shell script

Running shell scripts which process CGI input are very insecure. It may
be possible to write secure shell scripts, but I think it is not worth
the trouble.

Django contains a simple web server for testing. But it runs as a single
process. So if one request needs long, all other requests wait.
I don't think django is too heavy for a simple task.

You can use CGIHTTPServer and the cgi module of the standard library, too.
But it has drawbacks. One is, that CGIHTTPServer can't do a redirect. (HTTP
code 302).

I whish that there was a simple and small (not twisted) webserver written in 
Python which can
be used in production. But I think there is none.

   Thomas

BTW, use subprocess and not os.system() if you need to call other executables.

>  Longer story:
> 
>  I would like to provide a web-page for customization of an
> application - it should run some shell commands as the user clicks
> around in the page and at the end write a configuration file. I had a
> look at the python wiki (http://wiki.python.org/moin/WebProgramming),
> where various web servers and frameworks are listed. The frameworks
> seem to heavy for such a simple task and BaseHTTPServer just seems to
> be too light. So I took a look at the web-servers listed:
>  httpy had the last release 1,5 years ago, Medusa more than 5 years,
> Twisted seems to be able to do a lot, so probably not the simple thing
> I'm looking for. CherryPy looks promising, however it is still 89
> files (including some that can be removed).
> 
>  If CGIHTTPServer is a good answer, could you point me to a good
> (nontrivial) example?
> 
>  thank you, muro


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


Re: simple web-server

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 08:53:15 -0300, Pavol Murin <[EMAIL PROTECTED]>  
escribió:

> could you point me to a very simple (single file is best) web-server?
> I want to serve a few web-forms and run some shell scripts when the
> forms are submitted. I might add Ajax later (this is not a
> requirement, if it only supports forms it's OK).

Ajax is mostly a client thing, any server would work.

>  I would like to provide a web-page for customization of an
> application - it should run some shell commands as the user clicks
> around in the page and at the end write a configuration file. I had a
> look at the python wiki (http://wiki.python.org/moin/WebProgramming),
> where various web servers and frameworks are listed. The frameworks
> seem to heavy for such a simple task and BaseHTTPServer just seems to
> be too light.

How many requests/minute you expect to handle? From your description, not  
many, I think. So even CGI would be OK, and I'd choose the easiest server  
to configure and setup.
TinyWeb www.ritlabs.com is the smallest web server I know of (Windows  
only, unfortunately), and almost setup-free. Ensure that .py scripts are  
executable, place them in a cgi-bin subdirectory, start tiny.exe and  
you're done.

> So I took a look at the web-servers listed:
>  httpy had the last release 1,5 years ago, Medusa more than 5 years,
> Twisted seems to be able to do a lot, so probably not the simple thing
> I'm looking for. CherryPy looks promising, however it is still 89
> files (including some that can be removed)

Don't make the release dates fool you. The HTTP specs haven't changed in  
years, once you have a functional server, there is no need to keep  
changing it.

>  If CGIHTTPServer is a good answer, could you point me to a good
> (nontrivial) example?

Running CGIHTTPServer takes 3 or 5 lines of code, and that's all to it.  
You don't have to touch the server itself. You write cgi scripts and put  
them somewhere so the server can find and execute them when requested;  
that's all.
So you have to look for CGI examples, not server examples :)

-- 
Gabriel Genellina

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


Re: simple web-server

2008-03-28 Thread Bernard
Did you take a look at web.py? That one looks terribly small and
efficient :)

We use CherryPy coupled with compiled Cheetah Templates for
every web server based projects at my workplace and we've been really
satisfied with it so far.

On 28 mar, 07:53, "Pavol Murin" <[EMAIL PROTECTED]> wrote:
> hello python users,
>
>  could you point me to a very simple (single file is best) web-server?
> I want to serve a few web-forms and run some shell scripts when the
> forms are submitted. I might add Ajax later (this is not a
> requirement, if it only supports forms it's OK).
>
>  Longer story:
>
>  I would like to provide a web-page for customization of an
> application - it should run some shell commands as the user clicks
> around in the page and at the end write a configuration file. I had a
> look at the python wiki (http://wiki.python.org/moin/WebProgramming),
> where various web servers and frameworks are listed. The frameworks
> seem to heavy for such a simple task and BaseHTTPServer just seems to
> be too light. So I took a look at the web-servers listed:
>  httpy had the last release 1,5 years ago, Medusa more than 5 years,
> Twisted seems to be able to do a lot, so probably not the simple thing
> I'm looking for. CherryPy looks promising, however it is still 89
> files (including some that can be removed).
>
>  If CGIHTTPServer is a good answer, could you point me to a good
> (nontrivial) example?
>
>  thank you, muro

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


Summary of threading for experienced non-Python programmers?

2008-03-28 Thread skip
I'm having trouble explaining the benefits and tradeoffs of threads to my
coworkers and countering their misconceptions about Python's threading model
and facilities.  They all come from C++ and are used to thinking of
multithreading as a way to harness multiple CPU cores for compute-bound
processing.  I also encountered, "Python doesn't really do threads" today.
*sigh*

I don't need pointers to the relevant documentation sections.  A bit of
googling didn't turn up much about threading beyond tutorial introductions.
I'm looking for something which will explain the rationale for using threads
in Python to someone who is experienced with multithreading in other
languages (like C/C++).  Maybe a compare-and-contrast sort of document?

Thanks,

Skip

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


Re: Global variables in modules...

2008-03-28 Thread ttsiodras
That clears it up. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


threads and extension module initialization

2008-03-28 Thread pianomaestro

I have an extension module that gets initialized multiple
times because I am using threads.

How can this module access global state (not per-thread state) ?
It needs to create a singleton.

Simon.

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


Re: How do I reconnect a disconnected socket?

2008-03-28 Thread pianomaestro

Did you try just creating a new socket every time you do a connect ?

On Mar 28, 10:01 am, Jason Kristoff  wrote:
> I'm trying to make something that once it is disconnected will
> automatically try to reconnect.  I'll add some more features in later so
> it doesn't hammer the server but right now I just want to keep it simple
> and get that part working.  The problem is that when I use sock.close I
> get an error message of
> Bad File Descriptor
> and if I either use shutdown or just go straight to reconnecting I get:
> Transport endpoint is already connected
>
> This is what I've got right now:
>
> #! /usr/bin/env python
> import socket, string
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> def doconn():
>  sock.connect(("localhost", 1234))
> def dodiscon():
>  sock.close()
>  doconn()
>
> doconn()
>
> while (1):
>  buffer = sock.recv(1024)
>  if not buffer:
>  dodiscon()

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


Re: Global variables in modules...

2008-03-28 Thread Terry Jones
> "Peter" == Peter Otten <[EMAIL PROTECTED]> writes:
Peter> [EMAIL PROTECTED] wrote:
[snip]
>> ...can someone explain why invoking a.py prints 0?
>> I would have thought that the global variable 'g' of module 'a' would
>> be set to 1...

Peter> When you run a.py as a script it is put into the sys.modules module
Peter> cache under the key "__main__" instead of "a". Thus, when you import
Peter> a the cache lookup fails and a.py is executed again. You end up with
Peter> two distinct copies of the script and its globals
[snip]


Suggesting the following horribleness in a.py

g = 0

def main():
global g
import b
g = 1
b.callb()

if __name__ == "__main__":
import sys, __main__
sys.modules['a'] = __main__
main()


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


Re: How do I reconnect a disconnected socket?

2008-03-28 Thread Laszlo Nagy

> This is what I've got right now:
>
> #! /usr/bin/env python
> import socket, string
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> def doconn():
>  sock.connect(("localhost", 1234))
> def dodiscon():
>  sock.close()
>  doconn()
>
> doconn()
>
> while (1):
>  buffer = sock.recv(1024)
>  if not buffer:
>  dodiscon()
>   

sock.recv(1024) can return zero bytes of data indicating that no data 
arrived yet. It does not mean that you have been disconnected. This is 
especially true when you do nothing but recv, recv, recv() in an 
infinite loop.

I recommend that you use select.select to see if there is some data that 
can be read. Call socket.recv() only when you know that it will not fail.

Best,

   Laszlo

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


Setting the value of one cell in QTableWidget fills everything.

2008-03-28 Thread Constantly Distracted
I've just started PyQt programming and I've run into this little
problem. When I set the text of one cell in my table, all the other
cells fill with that value.

All I wanted to do was run a loop, printing in each cell the row and
column number.
Here's the code.

--

from PyQt4 import QtGui,QtCore
import sys

class mywindow(QtGui.QWidget):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.resize(700,700)
self.mytable=QtGui.QTableWidget(7,6,self)
self.mytable.resize(700,700)

def filltable(self):
items=QtGui.QTableWidgetItem()
for column in range(self.mytable.columnCount()):
for row in range(self.mytable.rowCount()):
items.setText("row: " + str(row) + " column: " +
str(column))
self.mytable.setItem(row,column,items)


app=QtGui.QApplication(sys.argv)
mainwin=mywindow()
mainwin.filltable()
qb.show()
app.exec_()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: base64.urlsafe_b64encode and the equal character

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 10:54:49 -0300, Clodoaldo <[EMAIL PROTECTED]>  
escribió:

> I'm using a md5 hash encoded with base64.urlsafe_b64encode as a
> parameter of a URL used to confirm a registration in a site. It has
> been working great.
>
> The url is like this:
>
> http://example.com/ce?i=878&h=kTfWSUaby5sBu9bIfoR87Q==
>
> Now i need to match that URL in a certain text and i realized that
> urlsafe_b64encode uses the "=" character so i can't just use \w{24} to
> match the parameter.
>
> What i need to know is where can an equal char appear in a
> urlsafe_b64encoded string?:
>
> a)only at end;
> b)both at the end and at the begginig;
> c)anywhere in the string;
>
> A sure answer will make my regexp safer.

Only at the end. The encoded string has 4*n chars when the input string  
has 3*n chars; when the input length is 3*n+1 or 3*n+2, the output has  
4*(n+1) chars right padded with 2 or 1 "=" chars.
If your input has 3n chars, the output won't have any "="

> In another point, does the "=" char make it urlunsafe? I guess not
> because i believe it would only be unsafe if the equal appeared like
> in "&var=" and since there are no "&" in the string than there is no
> problem right? Or wrong?

I guess not, but you should check the relevant RFCs. Or at least check  
that your server can always parse the request.

-- 
Gabriel Genellina

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


ANN: Leo 4.4.8 b3 released

2008-03-28 Thread Edward K Ream
Leo 4.4.8 beta 3 is available at:
http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106

This version features a new ipython plugin that provides a two-way bridge
between Leo and IPython.  See 
http://webpages.charter.net/edreamleo/IPythonBridge.html

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4.8:

- Leo's source code is now managed by bzr: see link below.
- Leo's discussion is now hosted by Google Groups: see link below.
- Arguments to g.es and g.es_print can be translated using gettext.
- Completed ILeo: a bridge between IPython and Leo.
  See http://webpages.charter.net/edreamleo/IPythonBridge.html
- Minibuffer commands may have arguments.
- @menu trees can now refer to commands created by
  @command and @button nodes.
- Added support for common @commands nodes in settings files.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Forum:http://groups.google.com/group/leo-editor
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
Bzr:  http://code.launchpad.net/leo-editor/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


class or inherited list ?

2008-03-28 Thread Stef Mientki
hello,

Passing all kinds of data between objects,
I'm looking for an elegant (and simple) way to pack the data.
Now it looks to me that both the class and the inherited list,
performs equally well.
Till now, the most elegant way (in my view) is the list inheritance,
mainly because you don't need brackets and no quotes.
What are others opinion about this ?

thanks,
Stef Mientki

class super_list(list):
pass

def kwadraat ( value ) :
return value * value

x={}
x['frequency']=33
x['functie']=kwadraat
print x['functie'](2)

y = super_list()
y.frequency = 33
y.functie = kwadraat
print y.functie(3)


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


Re: threads and extension module initialization

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 11:51:10 -0300, <[EMAIL PROTECTED]> escribió:

> I have an extension module that gets initialized multiple
> times because I am using threads.

And do you want thread local variables?

> How can this module access global state (not per-thread state) ?
> It needs to create a singleton.

C global variables are global, not per-thread.

-- 
Gabriel Genellina

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


Pexpect question.

2008-03-28 Thread Paul Lemelle
I am trying separate a script that users pexpect into
various functions within the same expect session.  The
problem is that the function does not return control
back Main.  Any insight into this issue would be
greatly appreciated.  Below is sample code of the
problem.  

Thanks, 
Paul 


import pexpect





def sshcon(user, password):

go = pexpect.spawn ('/usr/bin/ssh -l root %s '%
(user))

go.expect ('Password: ')

go.sendline (password)

go.interact()





#get node info for both clusters. 



C1_node = raw_input("Enter the ip address for node on
cluster 1: ")

C1_pass = raw_input("Enter the password for the node
on cluster 1: ")





sshcon(C1_node, C1_pass)



#go to the path

chk.expect('# ')

chk.sendline('ls')

#chk = pexpect.spawn('ls') # veriy that you are
connected

chk.interact()



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding euclidean distance,better code?

2008-03-28 Thread harryos
> The code is pretty legible as it is now. Anyway, using min() and a
> generator:
>
>

hi
is this calculated distance really Euclidean distance? When i checked
wikipedia http://en.wikipedia.org/wiki/Euclidean_distance
it shows a calculation involving sum of squares of the differences of
elements.Here in this code ,the sum of coordinates are used? is that a
different measure?

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


Re: Setting the value of one cell in QTableWidget fills everything.

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 12:01:01 -0300, Constantly Distracted  
<[EMAIL PROTECTED]> escribió:

> I've just started PyQt programming and I've run into this little
> problem. When I set the text of one cell in my table, all the other
> cells fill with that value.

> def filltable(self):
> items=QtGui.QTableWidgetItem()

Here you create a *single* object named item [why not "item" instead?]

> for column in range(self.mytable.columnCount()):
> for row in range(self.mytable.rowCount()):
> items.setText("row: " + str(row) + " column: " +
> str(column))
> self.mytable.setItem(row,column,items)

Here you set the *same* item all over the table.

-- 
Gabriel Genellina

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


Re: threads and extension module initialization

2008-03-28 Thread pianomaestro
On Mar 28, 11:14 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 28 Mar 2008 11:51:10 -0300, <[EMAIL PROTECTED]> escribió:
>
> > I have an extension module that gets initialized multiple
> > times because I am using threads.
>
> And do you want thread local variables?

no

>
> > How can this module access global state (not per-thread state) ?
> > It needs to create a singleton.
>
> C global variables are global, not per-thread.

Yes, but they get initialized once per-thread, therefore my singleton
gets
created multiple times.

Simon.

>
> --
> Gabriel Genellina

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


Re: class or inherited list ?

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 12:15:45 -0300, Stef Mientki <[EMAIL PROTECTED]>  
escribió:

> Passing all kinds of data between objects,
> I'm looking for an elegant (and simple) way to pack the data.
> Now it looks to me that both the class and the inherited list,
> performs equally well.
> Till now, the most elegant way (in my view) is the list inheritance,
> mainly because you don't need brackets and no quotes.
> What are others opinion about this ?
>
> class super_list(list):
> pass
>
> def kwadraat ( value ) :
> return value * value
>
> x={}
> x['frequency']=33
> x['functie']=kwadraat
> print x['functie'](2)
>
> y = super_list()
> y.frequency = 33
> y.functie = kwadraat
> print y.functie(3)

You don't use y as a list at all - you might as well inherit from object.  
And in that case you get a generic attribute container - as you said, like  
a dict but using attribute syntax (drawback: only valid names can be used  
as keys)
But I don't understand the "functie" usage - what's for? Perhaps if it  
used y.frequency - in that case a proper method would be better.

-- 
Gabriel Genellina

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


web application-level caching

2008-03-28 Thread Chris Gray
Is there a Python module comparable in functionality to the PEAR 
Cache_Lite package for PHP?

I've been doing some Googling to little avail.  I'm experimenting with 
Python CGI to learn various techniques at a low level and I'm adapting a 
model that uses PHP.

Any info about application-level caching (or pointers to where to find 
such info) would be highly appreciated.

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


problem with CGIHTTPServer

2008-03-28 Thread 7stud

1) I have this simple cgi server:


import CGIHTTPServer
import BaseHTTPServer

class MyRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ['/my_cgi_scripts']

server = BaseHTTPServer.HTTPServer(
('', 8111),
MyRequestHandler
)


server.serve_forever()


2) I have this simple python script:

test.py

#!/usr/bin/env python

import cgitb; cgitb.enable()
import cgi


print "Content-type: text/html"
print
print "hello"


3) I have this simple html page with a link that calls test.py:








http://localhost:8111/my_cgi_scripts/test.py";>click me






My directory structure looks like this:

../dir1
---myserver.py
---/my_cgi_scripts
test.py

After I start the server script, load the html page in my browser, and
click on the link, I get the desired output in my browser, but the
server script outputs the following in my terminal:

localhost - - [28/Mar/2008 08:51:22] "GET /my_cgi_scripts/test.py HTTP/
1.1" 200 -
localhost - - [28/Mar/2008 08:51:22] code 404, message File not found
localhost - - [28/Mar/2008 08:51:22] "GET /favicon.ico HTTP/1.1" 404 -


What are the error messages on lines two and three?

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


Re: threads and extension module initialization

2008-03-28 Thread pianomaestro
On Mar 28, 11:14 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:

> C global variables are global, not per-thread.

aha, a static pointer gets initialized to NULL, so I
can check if it's not NULL in the module initializer.

Thanks for jogging my brain,

Simon.

>
> --
> Gabriel Genellina

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-28 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>I'm having trouble explaining the benefits and tradeoffs of threads to my
>coworkers and countering their misconceptions about Python's threading model
>and facilities.  They all come from C++ and are used to thinking of
>multithreading as a way to harness multiple CPU cores for compute-bound
>processing.  I also encountered, "Python doesn't really do threads" today.
>*sigh*
>
>I don't need pointers to the relevant documentation sections.  A bit of
>googling didn't turn up much about threading beyond tutorial introductions.
>I'm looking for something which will explain the rationale for using threads
>in Python to someone who is experienced with multithreading in other
>languages (like C/C++).  Maybe a compare-and-contrast sort of document?

Maybe this will help?

http://www.pyzine.com/Issue001/Section_Articles/article_ThreadingGlobalInterpreter.html
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting the value of one cell in QTableWidget fills everything.

2008-03-28 Thread Phil Thompson
On Friday 28 March 2008, Constantly Distracted wrote:
> I've just started PyQt programming and I've run into this little
> problem. When I set the text of one cell in my table, all the other
> cells fill with that value.

...because you have only created a single QTableWidgetItem instance, rather 
than one for each cell.

> All I wanted to do was run a loop, printing in each cell the row and
> column number.
> Here's the code.
>
> --
>
> from PyQt4 import QtGui,QtCore
> import sys
>
> class mywindow(QtGui.QWidget):
> def __init__(self,parent=None):
> QtGui.QWidget.__init__(self,parent)
> self.resize(700,700)
> self.mytable=QtGui.QTableWidget(7,6,self)
> self.mytable.resize(700,700)
>
> def filltable(self):
> items=QtGui.QTableWidgetItem()
> for column in range(self.mytable.columnCount()):
> for row in range(self.mytable.rowCount()):
> items.setText("row: " + str(row) + " column: " +
> str(column))
> self.mytable.setItem(row,column,items)
>
>
> app=QtGui.QApplication(sys.argv)
> mainwin=mywindow()
> mainwin.filltable()
> qb.show()
> app.exec_()

Move the creation of the QTableWidgetItem() to the inner loop (and call 
it "item" rather than "items").

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


Re: finding euclidean distance,better code?

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 12:15:48 -0300, harryos <[EMAIL PROTECTED]>  
escribió:

>> The code is pretty legible as it is now. Anyway, using min() and a
>> generator:
>>
>>
>
> hi
> is this calculated distance really Euclidean distance? When i checked
> wikipedia http://en.wikipedia.org/wiki/Euclidean_distance
> it shows a calculation involving sum of squares of the differences of
> elements.Here in this code ,the sum of coordinates are used? is that a
> different measure?

(Thanks for trimming the irrelevant parts of the message, that's good; but  
you trimmed too much text, even attribution lines - the above quoted  
sentence was mine)

That's what I said in another paragraph. "sum of coordinates" is using a  
different distance definition; it's the way you measure distance in a city  
with square blocks. I don't know if the distance itself has a name, but  
the norm from which it is derived is called norm-1, or L1; the usual  
euclidean distance is derived from norm-2.
See http://mathworld.wolfram.com/VectorNorm.html

If you only want to see if two things are "close enough", this provides a  
faster measure than the euclidean distance.

-- 
Gabriel Genellina

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


Re: finding euclidean distance,better code?

2008-03-28 Thread Robert Bossy
Gabriel Genellina wrote:
> That's what I said in another paragraph. "sum of coordinates" is using a  
> different distance definition; it's the way you measure distance in a city  
> with square blocks. I don't know if the distance itself has a name, but 
I think it is called Manhattan distance in reference of the walking 
distance from one point to another in this city.

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


Re: threads and extension module initialization

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 12:25:55 -0300, <[EMAIL PROTECTED]> escribió:

> On Mar 28, 11:14 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
>> En Fri, 28 Mar 2008 11:51:10 -0300, <[EMAIL PROTECTED]> escribió:
>>
>> > How can this module access global state (not per-thread state) ?
>> > It needs to create a singleton.
>>
>> C global variables are global, not per-thread.
>
> Yes, but they get initialized once per-thread, therefore my singleton
> gets
> created multiple times.

Either don't call the initialization from every thread, or guard it with  
something like:

a_big_object my_object = NULL;
...

if (my_object!=NULL) {
...initialize object...
my_object = ...;
}

That's a pretty standard idiom I think.

-- 
Gabriel Genellina

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


Re: problem with CGIHTTPServer

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 12:38:45 -0300, 7stud <[EMAIL PROTECTED]>  
escribió:

> After I start the server script, load the html page in my browser, and
> click on the link, I get the desired output in my browser, but the
> server script outputs the following in my terminal:
>
> localhost - - [28/Mar/2008 08:51:22] "GET /my_cgi_scripts/test.py HTTP/
> 1.1" 200 -
> localhost - - [28/Mar/2008 08:51:22] code 404, message File not found
> localhost - - [28/Mar/2008 08:51:22] "GET /favicon.ico HTTP/1.1" 404 -
>
>
> What are the error messages on lines two and three?

Line 3 is your browser (IE, I presume?) asking for an icon for the site.
See http://en.wikipedia.org/wiki/Favicon
I don't know about line 2, maybe it's just a diagnostic message related to  
line 3. Try refreshing the page, or using an inexistent url to see if it  
still appears. Or put any icon as /favicon.ico to make your browser happy.

-- 
Gabriel Genellina

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


Re: class or inherited list ?

2008-03-28 Thread Stef Mientki
thanks Gabriel,

Gabriel Genellina wrote:
> En Fri, 28 Mar 2008 12:15:45 -0300, Stef Mientki <[EMAIL PROTECTED]>  
> escribió:
>
>   
>> Passing all kinds of data between objects,
>> I'm looking for an elegant (and simple) way to pack the data.
>> Now it looks to me that both the class and the inherited list,
>> performs equally well.
>> Till now, the most elegant way (in my view) is the list inheritance,
>> mainly because you don't need brackets and no quotes.
>> What are others opinion about this ?
>>
>> class super_list(list):
>> pass
>>
>> def kwadraat ( value ) :
>> return value * value
>>
>> x={}
>> x['frequency']=33
>> x['functie']=kwadraat
>> print x['functie'](2)
>>
>> y = super_list()
>> y.frequency = 33
>> y.functie = kwadraat
>> print y.functie(3)
>> 
>
> You don't use y as a list at all - you might as well inherit from object.
Good point, didn't notice that.
>   
> And in that case you get a generic attribute container - as you said, like  
> a dict but using attribute syntax (drawback: only valid names can be used  
> as keys)
>   
Perfect, I don't need invalid names.
> But I don't understand the "functie" usage - what's for? Perhaps if it  
> used y.frequency - in that case a proper method would be better.
>   
In my case the sender of the data determines the function ("functie" is 
the Dutch word for "function"),
assume this concept:
Sender:
- generates a huge array of data
Receiver:
- is a plot utility with interactive user interface
- the user can select a part of the huge dataset and wants to see the 
result of "function" on the selected part of the huge dataset
So by passing the function-name(s), I prevent that the functions(s) 
should be performed on all the data.
while they will never be used.

cheers,
Stef Mientki


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


Re: How do I reconnect a disconnected socket?

2008-03-28 Thread Grant Edwards
On 2008-03-28, Laszlo Nagy <[EMAIL PROTECTED]> wrote:

>> while (1):
>>  buffer = sock.recv(1024)
>>  if not buffer:
>>  dodiscon()
>>   
>
> sock.recv(1024) can return zero bytes of data indicating that no data 
> arrived yet.

No, it can't.

> It does not mean that you have been disconnected.

Yes, that is exactly what it means.

>From the recv() man page:

RETURN VALUE
   These  calls  return  the  number  of bytes received, or -1 if an error
   occurred.  The return value will be 0 when the peer  has performed  an
   orderly shutdown.

-- 
Grant

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


Re: threads and extension module initialization

2008-03-28 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> I have an extension module that gets initialized multiple
> times because I am using threads.
> 
> How can this module access global state (not per-thread state) ?
> It needs to create a singleton.

The question is very unclear.

If you are after *not* initializing your module concurrently, why don't 
you just do it *once* before the threads are started? alternatively, you 
need to govern the initialization-code with a mutex - or anything similar.

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


Re: base64.urlsafe_b64encode and the equal character

2008-03-28 Thread Clodoaldo
On Mar 28, 12:09 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 28 Mar 2008 10:54:49 -0300, Clodoaldo <[EMAIL PROTECTED]>
> escribió:
>
>
>
> > I'm using a md5 hash encoded with base64.urlsafe_b64encode as a
> > parameter of a URL used to confirm a registration in a site. It has
> > been working great.
>
> > The url is like this:
>
> >http://example.com/ce?i=878&h=kTfWSUaby5sBu9bIfoR87Q==
>
> > Now i need to match that URL in a certain text and i realized that
> > urlsafe_b64encode uses the "=" character so i can't just use \w{24} to
> > match the parameter.
>
> > What i need to know is where can an equal char appear in a
> > urlsafe_b64encoded string?:
>
> > a)only at end;
> > b)both at the end and at the begginig;
> > c)anywhere in the string;
>
> > A sure answer will make my regexp safer.
>
> Only at the end. The encoded string has 4*n chars when the input string
> has 3*n chars; when the input length is 3*n+1 or 3*n+2, the output has
> 4*(n+1) chars right padded with 2 or 1 "=" chars.
> If your input has 3n chars, the output won't have any "="

Thanks. But I'm not sure i get it. What is n?

A md5 digest will always be 16 bytes length. So if i understand it
correctly (not sure) the output will always be 22 chars plus two
trailing equal chars. Right?

Regards, Clodoaldo Pinto Neto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SoC project: Python-Haskell bridge - request for feedback

2008-03-28 Thread Michał Janeczek
On 27 Mar 2008 23:49:46 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Michaâ Janeczek" <[EMAIL PROTECTED]> writes:
>  > However, the type of embedding that I imagined would be mostly
>  > pure functions, since Python can deal with IO rather well. It'd also
>  > be applicable in situations where we want to add some functionality to
>  > to existing, large Python project, where the complete rewrite
>  > would be infeasible.
>
>  Of course I can't say what functions someone else would want to use,
>  but I'm not seeing very convincing applications of this myself.  There
>  aren't that many prewritten Haskell libraries (especially monomorphic
>  ones) that I could see using that way.  And if I'm skilled enough with
>  Haskell to write the functions myself, I'd probably rather embed
>  Python in a Haskell app than the other way around.

I was talking mostly about writing new components there, not just
using libraries. It'd apply to situations where there already exists
a large Python infrastructure.

>  > I didn't mention this in this first draft, but I don't know (yet)
>  > how to support those "fancy" types. The plan for now is to export
>  > monomorphic functions only.
>
>  This probably loses most of the interesting stuff: parser combinators,
>  functional data structures like zippers, etc.  Unless you mean to
>  use templates to make specialized versions?

That is true, but as you said before, using them directly from
Python would be unwieldy. In most cases writing a thin wrapper
in a language of the library that is going to be used is a much
more natural way (same might apply to calling Python from Haskell).

The plan for now is to start with monomorphic functions, then
add support for parametrically polymorphic functions
(that is ones that don't care about the type at all, i.e. List.length),
and then possibly extend this to some type classes that we
can reasonably expect to find on the Python side (Eq, Ord, etc.)

>  > As for GC, I think having the two systems involved is unavoidable if
>  > I want to have first class functions on both sides.
>
>  This just seems worse and worse the more I think about it.  Remember
>  that GHC uses a copying gc so there is no finalization and therefore
>  no way to notify python that a reference has been freed.  And you'd
>  probably have to put Haskell pointers into Python's heap objects so
>  that the Haskell gc wouldn't have to scan the whole Python heap.
>  Also, any low level GHC gc stuff (not sure if there would be any)
>  might have to be redone for GHC 6.10(?) which is getting a new
>  (parallel) gc.  Maybe I'm not thinking of this the right way though, I
>  haven't looked at the low level ghc code.

GHC does support finalization, at least for foreign pointers.
I don't think there is going to be any major change to the
foreign interface, either. Otherwise I wouldn't be bothering myself really ;)
The idea here is to have Haskell track most of Python objects
(I think that'll be much easier), and the other way around when
it's really necessary.

>  Keep in mind also that Python style tends to not use complex data
>  structures and fancy sharing of Haskell structures may not be in the
>  Python style.  Python uses extensible lists and mutable dictionaries
>  for just about everything, relying on the speed of the underlying C
>  functions to do list operations very fast (C-coded O(n) operation
>  faster than interpreted O(log n) operation for realistic n).  So maybe
>  this type of sharing won't be so useful.

Yes, but for now I think it is necessary for function callbacks
(Haskell calling Python giving it a higher order function). And if
we decide to support that, we might as well investigate other
use cases.

>  It may be simplest to just marshal data structures across a message
>  passing interface rather than really try to share values between the
>  two systems.
I agree that it'll be simplest, that's why I chose it as a first step :)

>  For fancy functional structures, from a Python
>  programmer's point of view, it is probably most useful to just pick a
>  few important ones and code them in C from scratch for direct use in
>  Python.  Hedgehog Lisp (google for it) has a nice C implementation of
>  functional maps that could probably port easily to the Python C API,
>  and I've been sort of wanting to do that.  It would be great if
>  you beat me to it.

Nice link about Hedgehog lisp :)
As for porting its data structures to Python, I don't think
it is a large enough project for SoC. And I also hope that
the Haskell<->Python can bring more benefits to the
users of both languages.

>  One thing I highly recommend is that you join the #haskell channel on
>  irc.freenode.net.  There are a lot of real experts there (I'm just
>  newbie) who can advise you better than I can, and you can talk to them
>  in real time.

Yes, I do drop by in there sometimes.. But what I'm after here
is an opinion of a Python programmer :)

Thanks again :)
Michal
-- 
http://

Re: How do I reconnect a disconnected socket?

2008-03-28 Thread Laszlo Nagy

> Yes, that is exactly what it means.
>
> >From the recv() man page:
>
> RETURN VALUE
>These  calls  return  the  number  of bytes received, or -1 if an error
>occurred.  The return value will be 0 when the peer  has performed  an
>orderly shutdown.
>
>   
Mea cupla. :-)

What about non-blocking sockets?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads and extension module initialization

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 13:17:44 -0300, Diez B. Roggisch <[EMAIL PROTECTED]>  
escribió:
> [EMAIL PROTECTED] schrieb:

>> I have an extension module that gets initialized multiple
>> times because I am using threads.
>>
>> How can this module access global state (not per-thread state) ?
>> It needs to create a singleton.
>
> The question is very unclear.
>
> If you are after *not* initializing your module concurrently, why don't
> you just do it *once* before the threads are started? alternatively, you
> need to govern the initialization-code with a mutex - or anything  
> similar.

Ouch... The simple "if (foo!=NULL)" I posted earlier is not thread safe  
and should not be used in this situation. Do as Diez said.

-- 
Gabriel Genellina

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-28 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes:

> I'm having trouble explaining the benefits and tradeoffs of threads
> to my coworkers and countering their misconceptions about Python's
> threading model and facilities.  They all come from C++ and are used
> to thinking of multithreading as a way to harness multiple CPU cores
> for compute-bound processing.  I also encountered, "Python doesn't
> really do threads" today.  *sigh*

Compute-bound processing pretty much excludes a Python-only solution,
so any performance considerations should take into account C
extensions.  Extensions are free to allow other threads to run during
CPU-extensive portions of their work, and many of them in fact do so.
As long as the extensions are correctly written, you can write your
"glue code" in Python and harness the multiple cores using threads,
exactly as expected by a C++ programmer.

The other use for threads is the case when dealing with blocking APIs
that don't support polling.  These typically include database APIs and
some network APIs (such as the portable host name lookup), but also
basic file input/output, if you take into account network file
systems.  (In theory, file input/output should also be available as
asynchronous code, but async IO is low-level and not available in
Python.)  While threads shouldn't be considered a replacement for
event-driven programming, they are certainly useful in such
situations.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I reconnect a disconnected socket?

2008-03-28 Thread Grant Edwards
On 2008-03-28, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>
>> Yes, that is exactly what it means.
>>
>> >From the recv() man page:
>>
>> RETURN VALUE
>>These  calls  return  the  number  of bytes received, or -1 if an 
>> error
>>occurred.  The return value will be 0 when the peer  has performed  an
>>orderly shutdown.
>>
>>   
> Mea cupla. :-)
>
> What about non-blocking sockets?

$ man recv
...
   If no messages are available at the socket, the receive
   calls wait for a message to arrive, unless the socket is
   non-blocking (see fcntl(2)), in which case the value -1
   is returned and the external variable errno set to
   EAGAIN.
...

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


Re: base64.urlsafe_b64encode and the equal character

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 13:22:06 -0300, Clodoaldo <[EMAIL PROTECTED]>  
escribió:
> On Mar 28, 12:09 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>> En Fri, 28 Mar 2008 10:54:49 -0300, Clodoaldo  
>> <[EMAIL PROTECTED]> escribió:
>>
>> > What i need to know is where can an equal char appear in a
>> > urlsafe_b64encoded string?:
>>
>> > a)only at end;
>> > b)both at the end and at the begginig;
>> > c)anywhere in the string;
>>
>> > A sure answer will make my regexp safer.
>>
>> Only at the end. The encoded string has 4*n chars when the input string
>> has 3*n chars; when the input length is 3*n+1 or 3*n+2, the output has
>> 4*(n+1) chars right padded with 2 or 1 "=" chars.
>> If your input has 3n chars, the output won't have any "="
>
> Thanks. But I'm not sure i get it. What is n?

(Any nonnegative integer...)
I mean: For base64 encoding, the length of the output depends solely of  
the length of the input. If the input string length is a multiple of 3,  
the output length is a multiple of 4, with no "=". If the input length is  
one more than a multiple of 3, the output has two "==" at the end. If the  
input length is two more than a multiple of 3, the output has only one "="  
at the end. In all cases, the output length is a multiple of 4.

[base64 uses 64=2**6 characters so it encodes 6 bits per character; to  
encode 3 bytes=3*8=24 bits one requires 24/6=4 characters]

> A md5 digest will always be 16 bytes length. So if i understand it
> correctly (not sure) the output will always be 22 chars plus two
> trailing equal chars. Right?

Exactly.

-- 
Gabriel Genellina

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


Re: Problem with write binary data to OLE field in Access

2008-03-28 Thread KingMax
On 3月27日, 下午7时22分, Tim Golden <[EMAIL PROTECTED]> wrote:
> lialie wrote:
>
> [... snip slightly confused indication that reading back a
> binary item using GetChunk appears to double its length ...]
>
> Well I don't know why this should be happening, but I do at
> least have a few suggestions:
>
> 1) Try using ADODB.Stream instead of GetChunk etc.
>
> 2) Try using the adodbapi dbapi-compliant wrapper
>
> 3) Try using ODBC (via PyODBC, CeODBC etc.)
>
> I've no idea if any of these will do any better but at
> least it gives you some possibilities :)
>
> TJG

Thanks!
I try using ADODB.Stream to implement it. But the situation is the
same.
At last, I try this, and it seems to work.
1) Save the image to the dist.
2) using ADODB.Stream.LoadFromFile
3) Save it into access
and then first step done.

when using it, I try this:
1) ADODB.Stream.Write(Record.Fields("xxx").Value)
2) ADODB.Stream.SaveToFile("test.jpg")
3) using wxImage to load it in.

a little stupid :(
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How do I reconnect a disconnected socket?

2008-03-28 Thread Mike
On Mar 28, 10:01 am, Jason Kristoff  wrote:
> I'm trying to make something that once it is disconnected will
> automatically try to reconnect.  I'll add some more features in later so
> it doesn't hammer the server but right now I just want to keep it simple
> and get that part working.  The problem is that when I use sock.close I
> get an error message of
> Bad File Descriptor
> and if I either use shutdown or just go straight to reconnecting I get:
> Transport endpoint is already connected
>
> This is what I've got right now:
>
> #! /usr/bin/env python
> import socket, string
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> def doconn():
>  sock.connect(("localhost", 1234))
> def dodiscon():
>  sock.close()
>  doconn()
>
> doconn()
>
> while (1):
>  buffer = sock.recv(1024)
>  if not buffer:
>  dodiscon()

I'd recommend to look at Twisted ReconnectingClientFactory -
http://twistedmatrix.com/trac/browser/trunk/twisted/internet/protocol.py#L198
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: base64.urlsafe_b64encode and the equal character

2008-03-28 Thread Clodoaldo
On Mar 28, 1:56 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 28 Mar 2008 13:22:06 -0300, Clodoaldo <[EMAIL PROTECTED]>
> escribió:
>
>
>
> > On Mar 28, 12:09 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> >> En Fri, 28 Mar 2008 10:54:49 -0300, Clodoaldo
> >> <[EMAIL PROTECTED]> escribió:
>
> >> > What i need to know is where can an equal char appear in a
> >> > urlsafe_b64encoded string?:
>
> >> > a)only at end;
> >> > b)both at the end and at the begginig;
> >> > c)anywhere in the string;
>
> >> > A sure answer will make my regexp safer.
>
> >> Only at the end. The encoded string has 4*n chars when the input string
> >> has 3*n chars; when the input length is 3*n+1 or 3*n+2, the output has
> >> 4*(n+1) chars right padded with 2 or 1 "=" chars.
> >> If your input has 3n chars, the output won't have any "="
>
> > Thanks. But I'm not sure i get it. What is n?
>
> (Any nonnegative integer...)
> I mean: For base64 encoding, the length of the output depends solely of
> the length of the input. If the input string length is a multiple of 3,
> the output length is a multiple of 4, with no "=". If the input length is
> one more than a multiple of 3, the output has two "==" at the end. If the
> input length is two more than a multiple of 3, the output has only one "="
> at the end. In all cases, the output length is a multiple of 4.
>
> [base64 uses 64=2**6 characters so it encodes 6 bits per character; to
> encode 3 bytes=3*8=24 bits one requires 24/6=4 characters]
>
> > A md5 digest will always be 16 bytes length. So if i understand it
> > correctly (not sure) the output will always be 22 chars plus two
> > trailing equal chars. Right?
>
> Exactly.

Thank you. That was great support!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Summary of threading for experienced non-Python programmers?

2008-03-28 Thread Diez B. Roggisch
> systems.  (In theory, file input/output should also be available as
> asynchronous code, but async IO is low-level and not available in
> Python.)  While threads shouldn't be considered a replacement for

I suggest you tell that the twisted-guys. And the ones from the built-in 
asyncore-module.

They will be surprised to hear that their years worth of working code 
will evaporate in a rosa cloud.

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-28 Thread sturlamolden
On 28 Mar, 15:52, [EMAIL PROTECTED] wrote:

> I'm having trouble explaining the benefits and tradeoffs of threads to my
> coworkers and countering their misconceptions about Python's threading model
> and facilities.  

Python's threading module is modelled on Java's thread model. There
are some minor differences, though. Whereas Python has special lock
objects, Java can lock (synchronize) on any object.


> They all come from C++ and are used to thinking of
> multithreading as a way to harness multiple CPU cores for compute-bound
> processing.  I also encountered, "Python doesn't really do threads" today.
> *sigh*


You can't use threads for that in CPython, due to the GIL (global
interpreter lock). The GIL resembles the BKL in earlier versions of
the Linux kernel. Due to the GIL, multiple threads cannot be
simultaneously in the Python interpreter. This e.g. means that I
cannot implement a parallel QuickSort in pure Python and get
performance gain from multiple CPUs.

Although common misbeliefs, this DOES NOT mean:

   * Python threads are not useful.
   * Python programs cannot utilize multiple CPUs or multi-core CPUs.

Here is the explanations:

The GIL can be released by extension modules, which are native
libraries of compiled C, C++ or Fortran. This is the key to the
usefulness of Python threads. For example:

   * Python file and socket objects are extension modules that release
the GIL. The GIL is released when a thread is waiting for i/o to
complete. This e.g. allows you to write multi-threaded server apps in
Python.

   * NumPy is an extension library that releases the GIL before
commencing on a time-consuming CPU-bound computations. If you have N
CPUs, NumPy allows you to do N FFTs or SVDs in parallel.

   * ctypes is an extension module that allows Python code to call
DLLs. ctypes releases the GIL before the foregin call on cdecl
functions (but not stdcall functions!), allowing you to call many
cdecl DLL functions in parallel.

   * Extension libraries that spawns multiple threads will utilize
mutiple CPUs, even if the GIL are not released.

There is also other reasons why threads are useful, that does not
depend on extension modules releasing the GIL. One example:
Multithreading is the key to responsive user interfaces, as only one
thread should process events. An event-handler should spawn a thread
before commencing on a time-consuming task.

IronPython and Jython are implemented without a GIL. (They run on
the .NET and Java VMs, respectively.)

Finally, remeber that pure Python often runs 200 times slower than
pure C on algoritmic code! If you need to do lengthy computational
tasks, a pure Python may not be what you want. With two dual-core
CPUs, nearly perfect load scheduling, a no-GIL implementation of
Python, a pure Python would still be more than 50 times solwer than a
single-threaded C solution. Hence, you would gain a lot more from
profiling, identifying the worst bottlenecks, and translating those
parts to C.






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


Re: class or inherited list ?

2008-03-28 Thread Stef Mientki

>>>
>>> class super_list(list):
>>> pass
>>>
>>> def kwadraat ( value ) :
>>> return value * value
>>>
>>> x={}
>>> x['frequency']=33
>>> x['functie']=kwadraat
>>> print x['functie'](2)
>>>
>>> y = super_list()
>>> y.frequency = 33
>>> y.functie = kwadraat
>>> print y.functie(3)
>>> 
>>
>> You don't use y as a list at all - you might as well inherit from 
>> object.
> Good point, didn't notice that.
Sorry, not a good point,
by deriving from a list, I get all the list methods for nothing.

cheers,
Stef Mientki

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


Re: Psyco alternative

2008-03-28 Thread Paul Boddie
On 27 Mar, 15:19, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>

[Psyco maintenance and further development]

> Nope, but I heard through the grapevine that while it won't be supported for
> all times to come, a new version is in the making.
>
> But ultimately, the author says that the approach is flawed, so at *some*
> point it will be discontinued. But that could be said about nearly
> everything, couldn't it?

>From what I've seen from browsing publicly accessible materials,
there's a certain commercial interest in seeing Psyco updated
somewhat. So, whether it gets discontinued depends on the usual
factors of satisfying a need and there being qualified and motivated
people to work on it.

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


Astronomy Fits format and gif.save(path)

2008-03-28 Thread W. Watson
In what library would I find gif.save(path), where path is the name and path 
  of a file, and the method would produce a file in a gif format?

Is there a fits.save(path) somewhere? fits is commonly used in astronomical 
work.
-- 
  Wayne Watson (Nevada City, CA)

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


Re: Instrumented web proxy

2008-03-28 Thread Andrew McLean
Paul Rubin wrote:
> Andrew McLean <[EMAIL PROTECTED]> writes:
>> I would like to write a web (http) proxy which I can instrument to
>> automatically extract information from certain web sites as I browse
>> them. Specifically, I would want to process URLs that match a
>> particular regexp. For those URLs I would have code that parsed the
>> content and logged some of it.
>>
>> Think of it as web scraping under manual control.
> 
> I've used Proxy 3 for this, a very cool program with powerful
> capabilities for on the fly html rewriting.
> 
> http://theory.stanford.edu/~amitp/proxy.html

This looks very useful. Unfortunately I can't seem to get it to run 
under Windows (specifically Vista) using Python 1.5.2, 2.2.3 or 2.5.2. 
I'll try Linux if I get a chance.

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-28 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

> > systems.  (In theory, file input/output should also be available as
> > asynchronous code, but async IO is low-level and not available in
> > Python.)  While threads shouldn't be considered a replacement for
> 
> I suggest you tell that the twisted-guys. And the ones from the built-in 
> asyncore-module.
> 
> They will be surprised to hear that their years worth of working code 
> will evaporate in a rosa cloud.
> 
> Diez

I appreciate the droll sense of humor, but do you mean to
assert that asyncore.py supports asynchronous disk file I/O?

What that means to me is, you queue a disk read, and there's
an event flag or something that you can wait for before you
come back to find the data in your buffer.  (That's how I
remember it from the old days, when it mattered a little,
though not enough that I ever remember actually doing it,
and 20 years later I guess the incentive is even less.)

I see MacOS supports an F_RDADVISE that might give you a head
start on reading into the system buffer, but that's 3rd rate
asynchrony because there's no way to know when the data is
ready, and 3rd rate I/O because afterwards you still have the
copying to do.  I don't see even this much in asyncore.py, but
I just gave it a glance.

thanks,
   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic code problem

2008-03-28 Thread castironpi
On Mar 28, 8:41 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 28 Mar 2008 07:14:17 -0300, Simon Brunning  
> <[EMAIL PROTECTED]> escribió:
>
> > On Thu, Mar 27, 2008 at 4:13 PM,  <[EMAIL PROTECTED]> wrote:
> >> My dynamic code failed at this site http:///, need
> >>  some help thank you.
>
> > 
>
> I assumed it was just spam, not a question.

To be or not to be, not a question?
-- 
http://mail.python.org/mailman/listinfo/python-list


Installing simplejson issues

2008-03-28 Thread blwatson
I am trying to install the twitter python wrapper...I got that
installed just fine, but am having serious troubles getting the
simplejson package to install.  I need help diagnosing where this is
failing.  I am trying to use:

http://pypi.python.org/pypi/simplejson

and I run "python setup.py build" and then "python setup.py install",
which both seem to work just fine.

I tried running with easy_install, but that too is not working.  I end
up with:

simplejson-1.8.1-py2.5-macosx-10.3-fat.egg

in my:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/

I am on Mac OS X 10.5.  Any help would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advantage of the array module over lists?

2008-03-28 Thread Piet Delport
On Mar 17, 1:49 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> I doubt that. AFAIK both arrays and lists are continuous memory-areas,
> that double (at least to a certain threshold or so) when reaching the
> capacity limit.

For what it's worth, lists over-allocate by ~1/8, and arrays by ~1/16.
(Details in listobject.c:list_resize and arraymodule.c:array_resize.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to capture screenshots of the active window in Python

2008-03-28 Thread Colin J. Williams
Gabriel Genellina wrote:
> En Thu, 27 Mar 2008 20:28:27 -0300, Praveena B 
> <[EMAIL PROTECTED]> escribió:
> 
>> Can anyone help me out??
> 
> Still lacking details... PIL has a ImageGrab module, Windows only.
> 
For Windows, Alt Prtscn usually copies 
the image to a clipboard.

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


Re: finding euclidean distance,better code?

2008-03-28 Thread castironpi
On Mar 28, 10:15 am, harryos <[EMAIL PROTECTED]> wrote:
> > The code is pretty legible as it is now. Anyway, using min() and a
> > generator:
>
> hi
> is this calculated distance really Euclidean distance? When i checked
> wikipediahttp://en.wikipedia.org/wiki/Euclidean_distance
> it shows a calculation involving sum of squares of the differences of
> elements.Here in this code ,the sum of coordinates are used? is that a
> different measure?

I want the angle into an array.  > < sign bit on distance to [zero
element/kernel].  Are you coming out in uni-pole and/or lensed/focused/
parabolaed?  Is that a yes-or-no question?
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding Full Path to Process EXE

2008-03-28 Thread misceverything
Hello,

I would like to write a script that would enumerate all running
processes and return the full path to the EXE of each running
process.  However, I can't seem to find any good info on how to do
this..any help is greatly appreciated.  Thanks.

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


Question regd downloading multipart mail using POP3

2008-03-28 Thread SPJ
I am facing a strange problem when I am trying to retrieve multipart mail from 
POP server with attachments.
The task is to write a script which will retrieve mail with specific 'from' 
field. Get the subject, body and attachments if any and reuse this info to send 
mail with different format to ticketing system.

The global variable values I am expecting is:
msgList = [[msg1_subject,msg1_body,0],[msg2_subject,msg2_body,1]] and so on
attachmentList=[['none'],['attachname.txt','filename.pl']]
where none is no attachments.

But the result I am getting is:
msgList = [[msg1_subject,msg1_body,0],[msg2_subject,msg2_body,1]] and so on
attachmentList=[[none],['none', 'attachname.txt', 'filename.pl']]

An extra 'none' in the attachment list except for plain/text mails without 
attachments.
I have tried a lot to figure out how to eliminate this but with no luck do far 
:(
I know that some part is getting excluded from the condition, but I am unable 
to figure out what is causing this. 

Following is the function I wrote:
I am not an expert programmer hence my code is not clean, so pl. bear with me. 

Thanks,
SPJ

--
import poplib, email, re, sys, os

msgList = [] # Global list that contains messages
PATH = Path to save file on disk
# path were attachements will be stored
attachmentName = [] # Name of attachements 

def popconnect():
# connect the pop server and send username and password
pconnect = poplib.POP3(server)
pconnect.user(user)
pconnect.pass_(passwd)
   
   # Give connection status, msg list and total msg size
status, msg_list, octets = pconnect.list()
if len(msg_list) == 0:
print "No messages in Mailbox"
pass
# regex for searching mails from [EMAIL PROTECTED]
soc = re.compile("[EMAIL PROTECTED]")

   # iterate over the number of new messages from counterpane and qppend the 
required fields
# to a list. 
for msg_number in [msg.split(' ')[0] for msg in msg_list]:
status, lines, octets = pconnect.retr(msg_number)
msg1 = email.message_from_string('\n'.join(lines))
tmpList = []
attachList = []
attachnumber = 0

check1 = msg1.get('From')
check2 = msg1.get('Subject')

if soc.match(check1):
subject = msg1.get('Subject') # Subject for only mails only after 
condition is true.

if msg1.is_multipart():
  
for part in msg1.walk():
# multipart/* are just containers
mptype = part.get_content_maintype()
body = part.get_payload(decode=True)

if mptype == "multipart": continue
filename = part.get_filename()

if filename: # Attached object with filename
print 'in file ' +part.get_content_type()
attachnumber += 1

tmpList[2] = attachnumber # number of attachments in 
message
attachList.append(PATH+filename) # path to attachment

# Copy the attachment to disk
f = open(PATH + filename,"wb")
f.write(part.get_payload(decode = True))
f.close()

else:
print part.get_content_type()

if part.get_content_type() != ("text/html" or 
"text/plain" or "multipart/alternative" or "multipart/mixed"):
tmpList.append(subject) # Subject from message
tmpList.append(body)  # Body from message
tmpList.append(0)# If no attachments
attachList.append('none')

else: # Not multipart, only body portion exists

print "Not Multipart\n"
body=msg1.get_payload(decode=True)
tmpList.append(subject) # Subject from message
tmpList.append(body)
tmpList.append(0)
attachList.append('none')

if len(tmpList) > 0:
msgList.append(tmpList)

if len(attachList) > 0:
attachmentName.append(attachList)

print msgList, attachmentName

pconnect.quit()

def main():
popconnect()

if __name__== '__main__':

main()



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with format string and unicode

2008-03-28 Thread Hans Martin
Hi,

this is probably a trivial problem, but a google search for "python"
and "unicode" and" format string" gives too many hits: If I specify
e.g. "%20s" in a format string and the string value contains UTF-8
stuff (differing number of bytes per character), the length of the
resulting string (in characters) varies. How can I fix this?

Many thanks in advance!

-- 
Pt! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.5 - Build Error on Windows because of SQLite3

2008-03-28 Thread llothar
Why does Python2.5 do not include the amalgamation source code of
sqlite3?

At the moment it is not possible to build the system out of the box
with the Visual Studio project.
I don't think this is good. The amalgamation version is exactly for
this purpose.

Is there a 2.5.3 release on the way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Astronomy Fits format and gif.save(path)

2008-03-28 Thread Gary Herron
W. Watson wrote:
> In what library would I find gif.save(path), where path is the name and path 
>   of a file, and the method would produce a file in a gif format?
>
> Is there a fits.save(path) somewhere? fits is commonly used in astronomical 
> work.
>   
You may want to install PIL (the Python Image Library) for this:

  http://www.pythonware.com/products/pil/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with format string and unicode

2008-03-28 Thread Marc 'BlackJack' Rintsch
On Fri, 28 Mar 2008 21:13:00 +0100, Hans Martin wrote:

> this is probably a trivial problem, but a google search for "python"
> and "unicode" and" format string" gives too many hits: If I specify
> e.g. "%20s" in a format string and the string value contains UTF-8
> stuff (differing number of bytes per character), the length of the
> resulting string (in characters) varies. How can I fix this?

Use unicode strings instead.

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


Re: Installing simplejson issues

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 16:14:07 -0300, <[EMAIL PROTECTED]> escribió:

> I am trying to install the twitter python wrapper...I got that
> installed just fine, but am having serious troubles getting the
> simplejson package to install.  I need help diagnosing where this is
> failing.  I am trying to use:
>
> http://pypi.python.org/pypi/simplejson
>
> and I run "python setup.py build" and then "python setup.py install",
> which both seem to work just fine.

I don't understand - if it worked fine, what's the problem?

> I tried running with easy_install, but that too is not working.  I end
> up with:
>
> simplejson-1.8.1-py2.5-macosx-10.3-fat.egg
>
> in my:
>
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> packages/
>
> I am on Mac OS X 10.5.  Any help would be greatly appreciated.

And then you import simplejson and it fails? Or what?

-- 
Gabriel Genellina

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


Tell ya' what:

2008-03-28 Thread castironpi
I want to regression a signal.  It's NN, not necessarily, sine wave.
What kind of numbers of harmonic simultaneous sounds are we looking
at?  How close to an A 440 can a human make?

I want recognition to alert me.  As a sine wave is coming in:

>>> for t in [ ( 200* sin( x*2 ), 200* cos( x*2 ) ) for x in range( 10 ) ]: 
>>> print( *t )
...
0.0 200.0
181.859485365 -83.2293673094
-151.360499062 -130.728724173
-55.8830996398 192.03405733
197.871649325 -29.167617
-108.804222178 -167.814305815
-107.3145836 168.770791746
198.121471139 27.3474436416
-57.58066 -191.531896065
-150.197449354 132.063341649

I want new feature characteristics to chain events.  Circuits on -not-
affected- external nodes can decouple clock tick.  Realistically, the
human brain uses a layer of several tens before anything is
recognizable (sure, this photoreceptor says red all the time).

Bring us the process of focus:  Think mushroom clouds.  Some of the
smoke cycles back to redirection newcome particles, formed later in
the blast.  Program some of the ops.  I feel like I'm asking if all
the senses stream in paralell.

Thing about rivers is, their current runs downstream: which does echo
the process of muscle control: multiple brain pathways combine at
confluences to generate a river: one muscle fiber microbundle (non
contiguous, but that was later evolution).  (Finely articulate ionic
grades in three dimensions.)  Input is other.  It's still downstream
for inputs, but the waves overlap at the 'deltas' with an
chemoelectric interference pattern in either brain or spine, and have
to agree on something (saw red, saw temperature, felt pressure).
Those, by the way, are triggered by molecule discharge on the scale of
1,000s of atoms: C1814H2725N423O477S25.  Recharge takes an electron.
(Get one!)  Humans: big brains.

In brains we have a dynamic structure: you don't ever 'notice' things
per se; they just reorganize brain (in particular trigger growth--
they decay themselves).  Given intermodality (say, verbo-tactile?),
varying circuit length (shortest and longest paths from a peripheral
sensory cell to a motor cell (somewhen the name), cumulative depth
(length) of iteration (generation) at which concepts form (Sartorius
muscle direct stimulation), and correlate factor length of concept,
children learn words based on exposure time (snooty kids know
'entrepreneur' (a between taker by the way, and 'revenue' come in
again)) and varieties of thingsthatleduptoit: things that led up to
it.  The deeper concepts don't even motivate you to move, hardly even
the tongue.

You could do a lot of refining on your electric-medium perceptions: no
boring stuff, no watered down, spam making, spam fighting, though with
a few extra generations of hardware.

Did everyone take the course on computer architecture?
-- 
http://mail.python.org/mailman/listinfo/python-list


How to insert multiple rows in SQLite Dbase

2008-03-28 Thread afandi
Hi,

Generally, it involves SQL statement such as
 follow

 INSERT INTO (field1,field2,...fieldn) VALUES
 ('abc','def'...)

 If I have data taken from Apache Server Log,let say 100 lines which
is printed output of 8 fields such
 as:

data 1
IP: 61.5.65.101
Date: 26/Sep/2007
Time: 20:43:25
GMT: +0900
Requestt: GET /index.php?option=com_content&task=view&id=55&Itemid=19
HTTP/1.1
ErrorCode: 200
Bytes: 6458
Referel:http://www.joomla.org/index.php?
option=com_content&task=view&id=35&Itemid=19
Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4)
Gecko/20070515 Firefox/2.0.0.4

data 2
IP: 21.5.65.101
Date: 26/Sep/2007
Time: 20:43:25
GMT: +0900
Requestt: GET /index.php?option=com_content&task=view&id=55&Itemid=19
HTTP/1.1
ErrorCode: 200
Bytes: 6458
Referel:http://www.joomla.org/index.php?
option=com_content&task=view&id=35&Itemid=19
Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4)
Gecko/20070515 Firefox/2.0.0.4
.
.
.
.
until the 100 data

How toI insert into SQLite database? by using SQL statement.TQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding euclidean distance,better code?

2008-03-28 Thread harryos

> the norm from which it is derived is called norm-1, or L1; the usual > 
> euclidean distance is derived from norm-2.

> If you only want to see if two things are "close enough", this provides a  
> faster measure than the euclidean distance.


thanks Gabriel for the detailed explanation..
if i were to calculate the euclidean distance in the above example how
should i go about it..?
should i replace
distance = abs(input_wk - weights[image, :])
with something else?
thanks again
oharry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5 - Build Error on Windows because of SQLite3

2008-03-28 Thread Gerhard Häring
llothar wrote:
> Why does Python2.5 do not include the amalgamation source code of
> sqlite3? [...]

First, at the time Python grew the sqlite3 module, there was no
amalgamation yet.

My reasoning:

So that Python doesn't need to release a security release, should a
security bug in SQLite be found. Users can then download the new DLL
from the SQLite homepage and place it into their Python's DLL folder.

Ok, in reality that's probably only true for x86 Windows, not IA64
and/or AMD64 ;-)

OTOH it would save me and the Python team some effort if we bundled a
specific SQLite amalgamation with Python. Bug reports about bit-rotten
SQLite 3.x versions would then not appear :-P

Nowadays we support SQLite 3.0.8 through the very latest one. That means
quite a few #ifdefs and friends in the C source code and also in the
unit tests.

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


Re: Tell ya' what:

2008-03-28 Thread Grant Edwards
On 2008-03-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Did everyone take the course on computer architecture?

No.

I personally know dozens of people who didn't.

And I know others who took a course on computer architecture
but not the course on computer architecture.

-- 
Grant Edwards   grante Yow! PEGGY FLEMMING is
  at   stealing BASKET BALLS to
   visi.comfeed the babies in VERMONT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Class or dictionary ? (was: class or inherited list ?)

2008-03-28 Thread Stef Mientki
Sorry,
although the code example was correct,
the question was wrong.

Stef Mientki

Stef Mientki wrote:
> hello,
>
> Passing all kinds of data between objects,
> I'm looking for an elegant (and simple) way to pack the data.
> Now it looks to me that both the class and the inherited list,
> performs equally well.
> Till now, the most elegant way (in my view) is the list inheritance,
> mainly because you don't need brackets and no quotes.
> What are others opinion about this ?
>
> thanks,
> Stef Mientki
>
> class super_list(list):
>pass
>
> def kwadraat ( value ) :
>return value * value
>
> x={}
> x['frequency']=33
> x['functie']=kwadraat
> print x['functie'](2)
>
> y = super_list()
> y.frequency = 33
> y.functie = kwadraat
> print y.functie(3)
>
>
>

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


Re: Finding Full Path to Process EXE

2008-03-28 Thread Tim Golden
[EMAIL PROTECTED] wrote:
> Hello,
> 
> I would like to write a script that would enumerate all running
> processes and return the full path to the EXE of each running
> process.  However, I can't seem to find any good info on how to do
> this..any help is greatly appreciated.  Thanks.

I have this strange feeling of deja vu. Try this:

http://timgolden.me.uk/python/wmi_cookbook.html#running_processes

(You want the .ExecutablePath or .CommandLine attributes I imagine)

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


Re: Tell ya' what:

2008-03-28 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Did everyone take the course on computer architecture?

Yow!  Does your SPEED QUEEN have CABLE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding Full Path to Process EXE

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 16:40:01 -0300, <[EMAIL PROTECTED]> escribió:

> I would like to write a script that would enumerate all running
> processes and return the full path to the EXE of each running
> process.  However, I can't seem to find any good info on how to do
> this..any help is greatly appreciated.  Thanks.

Use Tim Golden's WMI wrapper.
Searching for "python enumerate running processes" with Google returns a  
reference to his module on the *first* hit. Searching in this newsgroup  
only, returns tons of references.

-- 
Gabriel Genellina

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


Re: Tell ya' what:

2008-03-28 Thread Grant Edwards
On 2008-03-28, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
>> Did everyone take the course on computer architecture?
>
> Yow!  Does your SPEED QUEEN have CABLE?

Ya know, I was thinking about trying to find an updated file of
Zippy quotes for use in my .sig, but I decided that having all
of the pop culture references be 30-years out of date was part
of the charm.

-- 
Grant Edwards   grante Yow! I wonder if I ought
  at   to tell them about my
   visi.comPREVIOUS LIFE as a COMPLETE
   STRANGER?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question regd downloading multipart mail using POP3

2008-03-28 Thread Gabriel Genellina
En Fri, 28 Mar 2008 16:47:51 -0300, SPJ <[EMAIL PROTECTED]> escribió:

> I am facing a strange problem when I am trying to retrieve multipart  
> mail from POP server with attachments.
> The task is to write a script which will retrieve mail with specific  
> 'from' field. Get the subject, body and attachments if any and reuse  
> this info to send mail with different format to ticketing system.
>
> The global variable values I am expecting is:
> msgList = [[msg1_subject,msg1_body,0],[msg2_subject,msg2_body,1]] and so  
> on
> attachmentList=[['none'],['attachname.txt','filename.pl']]
> where none is no attachments.
>
> But the result I am getting is:
> msgList = [[msg1_subject,msg1_body,0],[msg2_subject,msg2_body,1]] and so  
> on
> attachmentList=[[none],['none', 'attachname.txt', 'filename.pl']]
>
> An extra 'none' in the attachment list except for plain/text mails  
> without attachments.

None is a special object in Python, 'none' is a string, and none is a name  
that may refer to anything. They're not the same thing.
I would remove *all* Nones and nones and "none"s. An empty list is enough  
indication that there are no attachments, ok?

> # regex for searching mails from [EMAIL PROTECTED]
> soc = re.compile("[EMAIL PROTECTED]")

This regex may be too slow. Use
soc = re.compile(r"[EMAIL PROTECTED]")
(note the r and the \. and lack of .* on both ends; also @ isn't a special  
character so it's not necesary to escape it)

> if soc.match(check1):
> subject = msg1.get('Subject') # Subject for only mails

With the above reg.exp., use:
if soc.search(check1): ...

>if part.get_content_type() != ("text/html" or  
> "text/plain" or "multipart/alternative" or "multipart/mixed"):

That's wrong. The () evaluate simply to "text/html". You surely want this:

content_type = part.get_content_type()
if content_type not in ["text/html", "text/plain",  
"multipart/alternative", "multipart/mixed"]: ...

-- 
Gabriel Genellina

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


  1   2   >