Re: Usable street address parser in Python?

2010-04-20 Thread John Yeung
My response is similar to John Roth's.  It's mainly just sympathy. ;)

I deal with addresses a lot, and I know that a really good parser is
both rare/expensive to find and difficult to write yourself.  We have
commercial, USPS-certified products where I work, and even with those
I've written a good deal of pre-processing and post-processing code,
consisting almost entirely of very silly-looking fixes for special
cases.

I don't have any experience whatsoever with pyparsing, but I will say
I agree that you should try to get the street type from the end of the
line.  Just be aware that it can be valid to leave off the street type
completely.  And of course it's a plus if you can handle suites that
are on the same line as the street (which is where the USPS prefers
them to be).

I would take the approach which John R. seems to be suggesting, which
is to tokenize and then write a whole bunch of very hairy, special-
case-laden logic. ;)  I'm almost positive this is what all the
commercial packages are doing, and I have a tough time imagining what
else you could do.  Addresses inherently have a high degree of
irregularity.

Good luck!

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


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-20 Thread Steven D'Aprano
On Mon, 19 Apr 2010 23:47:06 -0700, John Yeung wrote:

> On Apr 20, 1:23 am, Cameron Simpson  wrote:
>> On 19Apr2010 21:31, alex23  wrote: | Cameron Simpson
>>  wrote: | >   If items(), keys(), values(),
>> iteritems(), iterkeys(), and | >   itervalues() are called with no
>> intervening modifications to the | >   dictionary, the lists will
>> directly correspond. This allows the | >   creation of (value, key)
>> pairs using zip(): pairs = zip(d.values(), | >   d.keys()).
>> |
>> | I stand corrected. Thanks Cameron.
>>
>> Oh, I was all ready to say what you said, but decided to check the docs
>> myself first:-)
> 
> I am not too comfortable relying on it.  It feels fragile and
> "implementationy" to me, as I'm sure it does to many people (such as
> everyone in this thread so far! ;)

It is a language feature that is guaranteed to be true for every 
implementation of Python, as much of a promise as the guarantee that 
sorted([3,1,2]) will return [1,2,3] or that [1,2,3][42:142] will return 
[] rather than fail. It's not an implementation detail that 
implementations are free to change, it is a promised language feature.

If it ever fails, that is a bug that needs to be reported.

Defensive programming is good, but at the point that you don't believe 
the promises that the language makes, how can you trust anything? You 
suggested 

pairs = [(v, k) for (k, v) in d.iteritems()]

as an alternative, but if you don't trust the language to behave 
correctly in this case:

pairs = zip(d.values(), d.items())

what makes you think you can trust d.iteritems(), list comprehensions, or 
even tuple packing and unpacking?



> I do trust the docs on this issue,
> but every so often I forget that I read this bit of the docs, and am
> once again left with an insecure feeling about it.

*shrug*

This is no different to any other little-used feature. I personally never 
remember whether divmod(a,b) returns (a//b, a%b) or the other way around, 
but that doesn't mean that the behaviour of divmod is implementation 
dependent, or that I'm justified in feeling insecure about it. One 
behaviour is promised, and anything else would be a bug. It would be a 
waste of time and code for me to write

a//b, a%b

just because I can't remember what divmod() does.


> All in all, the
> alternative idiom for flipping keys and values (provided in the docs a
> couple of sentences down from your quote) is short enough for my taste,
> easy enough for me to read, and never makes me wonder if I should check
> the docs just to be sure:
> 
>   pairs = [(v, k) for (k, v) in d.iteritems()]

Yes, and if you can't remember whether or not ints are automatically 
promoted to longs, you will continue writing this long after it became 
unnecessary:

try:
result = a + b
except OverflowError:
result = long(a) + long(b)

and then other coders will laugh at you :)

(But of course if you need to still support older versions of Python, 
then it isn't silly at all.)




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


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-20 Thread Dave Angel

Menghan Zheng wrote:

Hello!

Is it assured the following statement is always True?
If it is always True, in which version, python2.x or python3.x?

  

a = dict()


...
  

assert(a.values == [a[k] for k in a.keys()])


--> ?


Menghan Zheng

  
No, it's never true.  The assert statement has no return value, neither 
True nor False.


But probably you're asking whether the assert statement will succeed 
quietly.  Again, the answer is no.  The first part of the expression is 
a built-in method, and the second part is a (possibly-empty) list.  So 
it'll always throw an AssertionError.


But probably you've got a typo, and meant to include the parentheses:
   


  assert(a.values() == [a[k] for k in a.keys()])

That, I believe, is guaranteed to not fire the assertion in 2.6.

In 2.6, the docs say:

"If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are 
called with no intervening modifications to the dictionary, the lists will 
directly correspond"


In 3.x it should fire an assertion error, for any dictionary, because values() 
does not return a list, but an iterator for one.  However, I don't have the 
docs for 3.x handy, I just tried it interactively to confirm my belief.

DaveA


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


Re: Tkinter scrollbar background color doesn't work

2010-04-20 Thread eb303
On Apr 19, 6:35 pm, KL  wrote:
> Tkinter scrollbar widget's "background" and "relief" options seem not
> work.
>
> The below is the codes I tried and the python/tk information:
> ===
>
> ActivePython 2.6.4.8 (ActiveState Software Inc.) based on
> Python 2.6.4 (r264:75706, Nov  3 2009, 13:23:17) [MSC v.1500 32 bit
> (Intel)] on
> win32>>> from Tkinter import *
> >>> r=Tk()
> >>> s=Scrollbar(r,bg="#000")
> >>> s.grid()
> >>> s['activebackground'] = "#000"
> >>> s['relief'] = "sunken"
>
> >>> TkVersion
> 8.5
> >>> import sys
> >>> sys.version
>
> '2.6.4 (r264:75706, Nov  3 2009, 13:23:17) [MSC v.1500 32 bit
> (Intel)]'

On Windows, tk scrollbars are actually native scrollbars. So if native
scrollbars don't allow changing their background or active background
color, tk won't allow it either. Your script works as expected on
Linux, but neither on Windows, nor on a Macintosh (where native
scrollbars are used too). This is just how tk/Tkinter works, so I
don't think there's any solution for it, except creating your own
scrollbar widget by yourself.

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


Re: any modules having a function to partition a list by predicate provided?

2010-04-20 Thread Bryan
knifenomad wrote:
> i know it's not very hard to get that solution.
> just by implementing simple function like below.
>
>       def partition(target, predicate):
>             """
>             split a list into two partitions with a predicate
> provided.
>             any better ideas? :)
>             """
>             true = []
>             false= []
>             for item in target:
>                 if predicates(item):
>                     true.append(item)
>                 else:
>                     false.append(item)
>             return true, false
>
> but i wonder if there's another way to do this with standard libraries
> or .. built-ins.
> if it's not, i'd like the list objects to have partition method


I've oft collected partitions in a dict, so I'll suggest the
generalization:

def partition(target, predicate):
result = {}
for item in target:
result.setdefault(predicate(item), []).append(item)
return result


> true, false = [1,2,3,4].partition(lambda x: x >1)
>
> print true, false
> [2,3,4]   [1]

With my version you'd get:
{False: [1], True: [2, 3, 4]}


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


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-20 Thread Carl Banks
On Apr 20, 1:13 am, Dave Angel  wrote:
> Menghan Zheng wrote:
> > Hello!
>
> > Is it assured the following statement is always True?
> > If it is always True, in which version, python2.x or python3.x?
>
>  a = dict()
>
> > ...
>
>  assert(a.values == [a[k] for k in a.keys()])
>
> > --> ?
>
> > Menghan Zheng
>
> No, it's never true.  The assert statement has no return value, neither
> True nor False.
>
> But probably you're asking whether the assert statement will succeed
> quietly.  Again, the answer is no.  The first part of the expression is
> a built-in method, and the second part is a (possibly-empty) list.  So
> it'll always throw an AssertionError.
>
> But probably you've got a typo, and meant to include the parentheses:
>
>    assert(a.values() == [a[k] for k in a.keys()])
>
> That, I believe, is guaranteed to not fire the assertion in 2.6.

Aye.

And in checking a corner case of this I discovered that in (C)Python
it's not possible to define an object that reliably does not equal
itself, because list (at least) is optimized to check identity first.

a = float('nan')
a == a  # returns False
[a] == [a]  # returns True

Considering that it's rare for an object to not equal itself and much
rarer for this behavior to be useful, and considering the potential
performance gains, it's probably a good trade off, but it's something
to be aware of.


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


Re: Usable street address parser in Python?

2010-04-20 Thread Iain King
On Apr 20, 8:24 am, John Yeung  wrote:
> My response is similar to John Roth's.  It's mainly just sympathy. ;)
>
> I deal with addresses a lot, and I know that a really good parser is
> both rare/expensive to find and difficult to write yourself.  We have
> commercial, USPS-certified products where I work, and even with those
> I've written a good deal of pre-processing and post-processing code,
> consisting almost entirely of very silly-looking fixes for special
> cases.
>
> I don't have any experience whatsoever with pyparsing, but I will say
> I agree that you should try to get the street type from the end of the
> line.  Just be aware that it can be valid to leave off the street type
> completely.  And of course it's a plus if you can handle suites that
> are on the same line as the street (which is where the USPS prefers
> them to be).
>
> I would take the approach which John R. seems to be suggesting, which
> is to tokenize and then write a whole bunch of very hairy, special-
> case-laden logic. ;)  I'm almost positive this is what all the
> commercial packages are doing, and I have a tough time imagining what
> else you could do.  Addresses inherently have a high degree of
> irregularity.
>
> Good luck!
>
> John Y.

Not sure on the volume of addresses you're working with, but as an
alternative you could try grabbing the zip code, looking up all
addresses in that zip code, and then finding whatever one of those
address strings most closely resembles your address string (smallest
Levenshtein distance?).

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


Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread Dodo

Hello,

I don't understand why this won't execute


import urllib.request as u
import socket
socket.setdefaulttimeout(10)

l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; # 
supposed to timeout

try:
h = u.urlretrieve(l)
except u.URLError, e: # I tried u.e too, no effect.
print(e)
except:
print("other error")

The error :

...\Python>err.py
  File "...\err.py", line 8
except u.URLError, e: # I tried u.e too, no effect.
 ^
SyntaxError: invalid syntax


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


Re: Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread MRAB

Dodo wrote:

Hello,

I don't understand why this won't execute


import urllib.request as u
import socket
socket.setdefaulttimeout(10)

l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; # 
supposed to timeout

try:
h = u.urlretrieve(l)
except u.URLError, e: # I tried u.e too, no effect.
print(e)
except:
print("other error")

The error :

...\Python>err.py
  File "...\err.py", line 8
except u.URLError, e: # I tried u.e too, no effect.
 ^
SyntaxError: invalid syntax


In Python 3 it's:

except u.URLError as e:

This a because in Python 2 people sometimes write:

except OSError, IOError:

thinking that it will catch both OSError and IOError.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Write web apps in Python?

2010-04-20 Thread Bryan
Bruno Desthuilliers wrote:
> Gilles Ganault a écrit :
> > Apart from the ease of having the application run at all times, I'd be
> > curious to read about an application that was written in PHP and then
> > a long-running process and see if performance improved.
>
> I'm not sure there's a way to do such a thing in PHP, at least in a way
> that wouldn't make the whole benchmark totally meaningless.

I think you guys got some incorrect info about PHP. A variety of
execution options are available, such as FastCGI and in-server
modules. PHP frameworks generally allow and encourage application code
to be independent of the underlying plumbing. Many large,
sophisticated, high-volume web apps are in PHP.

We like Python 'round here, but PHP, Ruby, Perl, Java, and others are
viable languages for web apps. Each has its distinguishing features --
how efficiently a web app gets invoked is not among them. It's not a
language issue. What was the theory here? Did we think the PHP
community too stupid to understand FastCGI?


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


Re: Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread Dodo

Le 20/04/2010 13:06, MRAB a écrit :

Dodo wrote:

Hello,

I don't understand why this won't execute


import urllib.request as u
import socket
socket.setdefaulttimeout(10)

l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; #
supposed to timeout
try:
h = u.urlretrieve(l)
except u.URLError, e: # I tried u.e too, no effect.
print(e)
except:
print("other error")

The error :

...\Python>err.py
File "...\err.py", line 8
except u.URLError, e: # I tried u.e too, no effect.
^
SyntaxError: invalid syntax


In Python 3 it's:

except u.URLError as e:

This a because in Python 2 people sometimes write:

except OSError, IOError:

thinking that it will catch both OSError and IOError.


thanks =D
--
http://mail.python.org/mailman/listinfo/python-list


Re: Write web apps in Python?

2010-04-20 Thread Adam Tauno Williams
On Mon, 2010-04-19 at 15:15 +0200, Bruno Desthuilliers wrote:
> Gilles Ganault a écrit :
> > On Thu, 15 Apr 2010 12:41:56 +0200, Bruno Desthuilliers
> >  wrote:
> >> The PHP execution model (mostly based on CGI FWIW) tends to be a bit 
> >> unpractical for non-trivial applications since you have to rebuild the 
> >> whole world for each and any incoming request, while with a long-running 
> >> process, you load all your libs, parse your config etc only once.

There are numerous ways to efficiently retains state between page views
[session id + memcache or even just shared memory].

> > Apart from the ease of having the application run at all times, I'd be
> > curious to read about an application that was written in PHP and then
> > a long-running process and see if performance improved.
> I'm not sure there's a way to do such a thing in PHP,

There isn't.  [Speaking as an ~15 year administrator and developer].
Also PHP's memory management is *B*A*D*, so please don't try to create
long running processes in PHP.

But if you have intensive processing to do your web front end should
signal a backend to do the 'real' work;  keeping your front end thin and
svelt.  There are numerous ways to accomplish that.

> Now there are a couple Symfony / Django benchmarks around (Symfony being 
> probably the closest thing to Django in the PHP world). They are just as 
> reliable as most benchmarks (that is, at best a rough indicator once you 
> understand what's effectively being measured), but it seems that they 
> confirm the empirical evidence that PHP is not well suited for such 
> "heavy" OO frameworks.
> > Regardless, Python has an easier syntax, so AFAIC, that's already a
> > good enough reason to use this to write web apps.
> Indeed !-)


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


Python DXF import library?

2010-04-20 Thread Stodge
Is anyone aware of a Python DXF import library? I think I remember
seeing converters but so far I haven't found a library. I need to
write a tool that reads DXFs so I'm not yet sure if a converter would
be of any use. Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread Andrej Mitrovic
On Apr 20, 1:06 pm, MRAB  wrote:
> Dodo wrote:
> > Hello,
>
> > I don't understand why this won't execute
>
> > import urllib.request as u
> > import socket
> > socket.setdefaulttimeout(10)
>
> > l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; #
> > supposed to timeout
> > try:
> >     h = u.urlretrieve(l)
> > except u.URLError, e: # I tried u.e too, no effect.
> >     print(e)
> > except:
> >     print("other error")
>
> > The error :
>
> > ...\Python>err.py
> >   File "...\err.py", line 8
> >     except u.URLError, e: # I tried u.e too, no effect.
> >                      ^
> > SyntaxError: invalid syntax
>
> In Python 3 it's:
>
>      except u.URLError as e:
>
> This a because in Python 2 people sometimes write:
>
>      except OSError, IOError:
>
> thinking that it will catch both OSError and IOError.

except (OSError, IOError), e:  # Python 2.x

If you put them in a tuple, it will catch them, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this exception catch doesn't work?? (python 3)

2010-04-20 Thread MRAB

Andrej Mitrovic wrote:

On Apr 20, 1:06 pm, MRAB  wrote:

Dodo wrote:

Hello,
I don't understand why this won't execute
import urllib.request as u
import socket
socket.setdefaulttimeout(10)
l = "http://img144.imageshack.us/my.php?image=koumakandg8.jpg"; #
supposed to timeout
try:
h = u.urlretrieve(l)
except u.URLError, e: # I tried u.e too, no effect.
print(e)
except:
print("other error")
The error :
...\Python>err.py
  File "...\err.py", line 8
except u.URLError, e: # I tried u.e too, no effect.
 ^
SyntaxError: invalid syntax

In Python 3 it's:

 except u.URLError as e:

This a because in Python 2 people sometimes write:

 except OSError, IOError:

thinking that it will catch both OSError and IOError.


except (OSError, IOError), e:  # Python 2.x

If you put them in a tuple, it will catch them, right?


In Python 2.x:

except (OSError, IOError), e:

In Python 3.x (and also Python 2.6):

except (OSError, IOError) as e:
--
http://mail.python.org/mailman/listinfo/python-list


Code redundancy

2010-04-20 Thread Alan Harris-Reid

Hi,

During my Python (3.1) programming I often find myself having to repeat 
code such as...


class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat the 
class1 prefix?  Before Python my previous main language was Visual 
Foxpro, which had the syntax...


with class1
  .attr1 = 1
  .attr2 = 2
  .attr3 = 3
  .attr4 = 4
  etc.
endwith

Is there any equivalent to this in Python?

Any help would be appreciated.

Alan Harris-Reid
--
http://mail.python.org/mailman/listinfo/python-list


Re: Usable street address parser in Python?

2010-04-20 Thread Grant Edwards
On 2010-04-20, Tim Roberts  wrote:

> This is a very tricky problem.  Consider Salem, Oregon, which puts the
> direction after the street:
>
> 3340 Astoria Way NE
> Salem, OR 97303

In Minneapolis, the direction comes before the street in some
quadrants and after it in others.  I used to live on W 43rd Street.
Now I live on 24th Ave NE.  And just to be more inconsistent, only the
"NE" section uses two directions, everywhere else it's just W, S, N,
or E.

-- 
Grant Edwards   grant.b.edwardsYow! Is it NOUVELLE
  at   CUISINE when 3 olives are
  gmail.comstruggling with a scallop
   in a plate of SAUCE MORNAY?
-- 
http://mail.python.org/mailman/listinfo/python-list


python glibc crypt() function

2010-04-20 Thread luca72
Hello i have to do this :
glibc crypt() function, using salt $1$abcdefgh$

cryptPw = crypt(plainPw, "$1$abcdefgh$")

I can do it in python, with package i need?
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python glibc crypt() function

2010-04-20 Thread geremy condra
On Tue, Apr 20, 2010 at 9:54 AM, luca72  wrote:
> Hello i have to do this :
> glibc crypt() function, using salt $1$abcdefgh$
>
> cryptPw = crypt(plainPw, "$1$abcdefgh$")
>
> I can do it in python, with package i need?
> Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list
>

http://docs.python.org/py3k/library/crypt.html#module-crypt

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


Re: Code redundancy

2010-04-20 Thread Stefan Behnel

Alan Harris-Reid, 20.04.2010 15:43:

During my Python (3.1) programming I often find myself having to repeat
code such as...

class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat the
class1 prefix? Before Python my previous main language was Visual
Foxpro, which had the syntax...

with class1
.attr1 = 1
.attr2 = 2
.attr3 = 3
.attr4 = 4
etc.
endwith

Is there any equivalent to this in Python?


There's more than one way to do this, depending on your actual needs and 
the source of the attributes. I assume this is done in __init__?


This might work for you:

self.__dict__.update(attr1=1, attr2=2, attr3=3, attr4=4)

You should also think once more about the use of the code you presented 
above, having to set all those attributes may have a little smell. Maybe 
that's totally ok, but since you mention that you "often" find yourself 
doing the above, you may also have a mental design problem somewhere. We 
can't tell unless you provide a more concrete example than what you show above.


Stefan

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


Re: Code redundancy

2010-04-20 Thread Iain King
On Apr 20, 2:43 pm, Alan Harris-Reid 
wrote:
> Hi,
>
> During my Python (3.1) programming I often find myself having to repeat
> code such as...
>
> class1.attr1 = 1
> class1.attr2 = 2
> class1.attr3 = 3
> class1.attr4 = 4
> etc.
>
> Is there any way to achieve the same result without having to repeat the
> class1 prefix?  Before Python my previous main language was Visual
> Foxpro, which had the syntax...
>
> with class1
>    .attr1 = 1
>    .attr2 = 2
>    .attr3 = 3
>    .attr4 = 4
>    etc.
> endwith
>
> Is there any equivalent to this in Python?
>
> Any help would be appreciated.
>
> Alan Harris-Reid

The pythonic equivalent of VB 'with' is to assign to a short variable
name, for example '_':

_ = class1
_.attr1 = 1
_.attr2 = 2
_.attr3 = 3
_.attr4 = 4

alternatively, you could use the __setattr__ method:

for attr, value in (
('attr1', 1),
('attr2', 2),
('attr3', 3),
('attr4', 4)):
class1.__setattr__(attr, value)

and to get a bit crunchy, with this your specific example can be
written:

for i in xrange(1, 5):
class1.__setattr__('attr%d' % i, i)

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


Re: Write web apps in Python?

2010-04-20 Thread Bruno Desthuilliers

Bryan a écrit :

Bruno Desthuilliers wrote:

Gilles Ganault a écrit :

Apart from the ease of having the application run at all times, I'd be
curious to read about an application that was written in PHP and then
a long-running process and see if performance improved.

I'm not sure there's a way to do such a thing in PHP, at least in a way
that wouldn't make the whole benchmark totally meaningless.


I think you guys got some incorrect info about PHP. A variety of
execution options are available, such as FastCGI and in-server
modules. 


mod_php, yes, but that doesn't change anything to the fact that it has 
to rebuild the whole world on each and every request. Not the same as a 
true long-running process.


So, yes, you COULD write a cli PHP app, daemonize it, and add a mod_php 
/ FastCGI / whatever request handler to interface the cli app with the 
web server, but that would be kinda pointless, wouldn't it ? FWIW, 
that's what I was thinking about when asserting it would "make the whole 
benchmark totally meaningless".



PHP frameworks generally allow and encourage application code
to be independent of the underlying plumbing.


This is debatable at best. PHP code (except cli PHP code of course) is 
written without any care for persistent global state, concurrency 
issues, race conditions etc - because it's written with the idea that 
the code serving a request will be runned in total isolation. CGI 
heritage here, obviously. And please note I'm not criticizing this 
design- just pointing one of it's consequences.



Many large,
sophisticated, high-volume web apps are in PHP.


Did anyone pretend otherwise ?


We like Python 'round here, but PHP, Ruby, Perl, Java, and others are
viable languages for web apps.


Did anyone pretend otherwise ?


Each has its distinguishing features --
how efficiently a web app gets invoked is not among them. It's not a
language issue.


Well, when it comes to PHP, yes, it's somehow built in the language - 
PHP was designed from the ground to be a server page language, and to 
have each request served in total isolation (cf above).



What was the theory here? Did we think the PHP
community too stupid to understand FastCGI?


Bryan, I'm afraid you're reacting to something that was nowhere written 
in this thread.


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


Re: Write web apps in Python?

2010-04-20 Thread Bruno Desthuilliers

Adam Tauno Williams a écrit :

On Mon, 2010-04-19 at 15:15 +0200, Bruno Desthuilliers wrote:

Gilles Ganault a écrit :

On Thu, 15 Apr 2010 12:41:56 +0200, Bruno Desthuilliers
 wrote:
The PHP execution model (mostly based on CGI FWIW) tends to be a bit 
unpractical for non-trivial applications since you have to rebuild the 
whole world for each and any incoming request, while with a long-running 
process, you load all your libs, parse your config etc only once.


There are numerous ways to efficiently retains state between page views
[session id + memcache or even just shared memory].


Never played with shared memory in PHP. Sessions will at best retains 
"state" (data), and it's not a free lunch neither (you'll still have to 
reload that state one way or another). And you'll still have to parse 
included .php files on each and every request.





Apart from the ease of having the application run at all times, I'd be
curious to read about an application that was written in PHP and then
a long-running process and see if performance improved.

I'm not sure there's a way to do such a thing in PHP,


There isn't.  [Speaking as an ~15 year administrator and developer].
Also PHP's memory management is *B*A*D*, so please don't try to create
long running processes in PHP.


Wasn't designed for such a thing anyway !-)


But if you have intensive processing to do your web front end should
signal a backend to do the 'real' work;  keeping your front end thin and
svelt.  There are numerous ways to accomplish that.



For which definition of "intensive processing" ? Building a web page 
with Drupal when you have a dozen modules hooked here and there can 
already imply some processing...

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


Re: Code redundancy

2010-04-20 Thread Peter Otten
Alan Harris-Reid wrote:

> Hi,
> 
> During my Python (3.1) programming I often find myself having to repeat
> code such as...
> 
> class1.attr1 = 1
> class1.attr2 = 2
> class1.attr3 = 3
> class1.attr4 = 4
> etc.
> 
> Is there any way to achieve the same result without having to repeat the
> class1 prefix?  Before Python my previous main language was Visual
> Foxpro, which had the syntax...
> 
> with class1
>.attr1 = 1
>.attr2 = 2
>.attr3 = 3
>.attr4 = 4
>etc.
> endwith
> 
> Is there any equivalent to this in Python?

No. You could write a helper function

>>> def update(obj, **kw):
... for k, v in kw.items():
... setattr(obj, k, v)
...

and then use keyword arguments:

>>> class A: pass
...
>>> a = A()
>>> update(a, foo=42, bar="yadda")
>>> a.foo, a.bar
(42, 'yadda')
>>>

But if you are doing that a lot and if the attributes are as uniform as 
their names suggest you should rather use a Python dict than a custom class.

>>> d = {}
>>> d.update(foo=42, bar="whatever")
>>> d
{'foo': 42, 'bar': 'whatever'}
>>> d["bar"]
'whatever'

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


Japanese (speaking) developer needed for a bit of regex magic

2010-04-20 Thread Sebastian
Hi all,

I'm working on Python bindings for the Amazon Product Advertising API
(http://pypi.python.org/pypi/python-amazon-product-api/) which
supports the different localised versions - among them a Japanese one
(for http://www.amazon.co.jp).

All locales return error messages in English. Only the Japanese uses
Japanese which my regular expressions cannot handle at the moment.

Is there anyone fluent enough in Japanese to give me a hand? The bit
of code that needed tweaking can be found here:
http://bitbucket.org/basti/python-amazon-product-api/src/tip/amazonproduct.py#cl-152

A simple diff would help me greatly.

Thanks for your effort!
Seb.

P.S. If you have questions, I've set up a mailing list at python-
amazon-product-api-de...@googlegroups.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Usable street address parser in Python?

2010-04-20 Thread John Nagle

Iain King wrote:

Not sure on the volume of addresses you're working with, but as an
alternative you could try grabbing the zip code, looking up all
addresses in that zip code, and then finding whatever one of those
address strings most closely resembles your address string (smallest
Levenshtein distance?).


   The parser doesn't have to be perfect, but it should
reliably reports when it fails.  Then I can run the hard cases through
one of the commercial online address standardizers.  I'd like to
be able to knock off the easy cases cheaply.

   What I want to do is to first extract the street number and
undecorated street name only, match that to a large database of US businesses
stored in MySQL, and then find the best match from the database
hits.  So I need reliable extraction of undecorated street name and number.  The
other fields are less important.

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


Re: Write web apps in Python?

2010-04-20 Thread Adam Tauno Williams
On Tue, 2010-04-20 at 17:05 +0200, Bruno Desthuilliers wrote:
> Adam Tauno Williams a écrit :
> > On Mon, 2010-04-19 at 15:15 +0200, Bruno Desthuilliers wrote:
> >> Gilles Ganault a écrit :
> >>> On Thu, 15 Apr 2010 12:41:56 +0200, Bruno Desthuilliers
> >>>  wrote:
>  The PHP execution model (mostly based on CGI FWIW) tends to be a bit 
>  unpractical for non-trivial applications since you have to rebuild the 
>  whole world for each and any incoming request, while with a long-running 
>  process, you load all your libs, parse your config etc only once.
> > There are numerous ways to efficiently retains state between page views
> > [session id + memcache or even just shared memory].
> Never played with shared memory in PHP. Sessions will at best retains 
> "state" (data), and it's not a free lunch neither (you'll still have to 
> reload that state one way or another). 

I'd prefer the term "access" over "reload".

> And you'll still have to parse included .php files on each and every request.

False.  Production sites [all?] use interpreter caches that maintain
'compiled' pages in shared memory.  This works *very* well.

> >>> Apart from the ease of having the application run at all times, I'd be
> >>> curious to read about an application that was written in PHP and then
> >>> a long-running process and see if performance improved.
> >> I'm not sure there's a way to do such a thing in PHP,
> > There isn't.  [Speaking as an ~15 year administrator and developer].
> > Also PHP's memory management is *B*A*D*, so please don't try to create
> > long running processes in PHP.
> Wasn't designed for such a thing anyway !-)

Exactly;  that never stops people from trying.

> > But if you have intensive processing to do your web front end should
> > signal a backend to do the 'real' work;  keeping your front end thin and
> > svelt.  There are numerous ways to accomplish that.
> For which definition of "intensive processing" ? Building a web page 
> with Drupal when you have a dozen modules hooked here and there can 
> already imply some processing...

Again, the compilation of the modules is cached.  The amount of
processing required for 'import...' declines to near zero.

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


Re: python glibc crypt() function

2010-04-20 Thread Peter Otten
luca72 wrote:

> Hello i have to do this :
> glibc crypt() function, using salt $1$abcdefgh$
> 
> cryptPw = crypt(plainPw, "$1$abcdefgh$")
> 
> I can do it in python, with package i need?
> Thanks

>>> import ctypes 
>>> lib = ctypes.CDLL("libcrypt.so.1")
>>> crypt = lib.crypt
>>> crypt.restype = ctypes.c_char_p
>>> crypt("password", "$1$abcdefgh$")
'$1$abcdefgh$G//4keteveJp0qb8z2DxG/' 

Is that what it's supposed to return?

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


Re: Code redundancy

2010-04-20 Thread Jean-Michel Pichavant

Alan Harris-Reid wrote:

Hi,

During my Python (3.1) programming I often find myself having to 
repeat code such as...


class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat 
the class1 prefix?  Before Python my previous main language was Visual 
Foxpro, which had the syntax...


with class1
  .attr1 = 1
  .attr2 = 2
  .attr3 = 3
  .attr4 = 4
  etc.
endwith

Is there any equivalent to this in Python?

Any help would be appreciated.

Alan Harris-Reid

Hello,

Use an effective text editor, repeating stuff should not be a problem. 
In a more general manner, avoid trying to speed your writing while you 
should care speeding the reading.
Most of the tricks you could use will confuse the reader (unless the 
reader is familiar with Visual foxpro).


Anyway,

for attrName, value in [
   ('attr1', 1),
   ('attr2', 2),
   ('attr3', 3),
   ]:
   setattr(class1, attrName, value)

or

class Foo:
   def __init__(self):
  self.attr1=None
  self.attr2=None
  self.attr3=None

   def set(self, *args, **kwargs):
  for k in kwargs:
 if hasattr(self, k):
 setattr(self, k, kwargs[k])
 else:
   raise AttributeError('%s instance has no attribute "%s"' % 
(self.__class__.__name__, k))


f = Foo()
f.set(attr1=25)
print f.__dict__
f.set(attr3=4, attr2=89)
print f.__dict__
f.set(bar= 8)

output:
{'attr2': None, 'attr3': None, 'attr1': 25}
{'attr2': 89, 'attr3': 4, 'attr1': 25}
AttributeError: Foo instance has no attribute "bar"


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


gnu readline licensing?

2010-04-20 Thread Brendan Miller
Python provides a GNU readline interface... since readline is a GPLv3
library, doesn't that make python subject to the GPL? I'm confused
because I thought python had a more BSD style license.

Also, I presume programs written with the readline interface would
still be subject to GPL... might want to put a warning about that in
the python library docs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gnu readline licensing?

2010-04-20 Thread Robert Kern

On 4/20/10 1:09 PM, Brendan Miller wrote:

Python provides a GNU readline interface... since readline is a GPLv3
library, doesn't that make python subject to the GPL? I'm confused
because I thought python had a more BSD style license.


The PSF License is more BSD-styled, yes. The readline module can also be 
built against the API-compatible, BSD-licensed libedit library. Python's 
source distribution (even the readline module source) does not have to 
be subject to the GPL, though it should be (and is) GPL-compatible.



Also, I presume programs written with the readline interface would
still be subject to GPL... might want to put a warning about that in
the python library docs.


*When* someone builds a binary of the Python readline module against the 
GNU readline library, then that binary module is subject to the terms of 
the GPL. Any programs that distribute with and use that binary are also 
subject to the terms of the GPL (though it can have a non-GPL, 
GPL-compatible license like the PSF License). This only applies when 
they are combined with the GNU readline library, not before. The program 
must have a GPL-compatible license in order to be distributed that way. 
It can also be distributed independently of GNU readline under any license.


--
Robert Kern

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

 an underlying truth."
  -- Umberto Eco

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


"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas j

2010-04-20 Thread saima81
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs
in texas houston" "jobs in texas city" "jobs in texas government"
"jobs in texas austin" "texas jobs" "texas jobs online" texas job
search"  http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN
TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston"
"jobs in texas city" "jobs in texas government" "jobs in texas austin"
"texas jobs" "texas jobs online" texas job search"  
http://jobsintexas-usa.blogspot.com/
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs 

Re: Building a GUI Toolkit

2010-04-20 Thread Lie Ryan
On 04/19/10 03:06, Martin P. Hellwig wrote:
> On 04/18/10 12:49, Tim Diels wrote:
>> Hi
>>
>> I was thinking of writing a GUI toolkit from scratch using a basic '2D
>> library'. I have already come across the Widget Construction Kit.
>>
>> My main question is: Could I build a GUI toolkit of reasonable
>> performance with the Widget Construction Kit, would it still feel more
>> or less lightweight? By reasonable I mean that the user wouldn't think
>> of the interface as being slow or unresponsive.
>>
>> I've also thought of using pyglet to build widgets with, but this would
>> seem to be overkill. As a side question: by using opengl, the work would
>> be delegated to the GPU rather than the CPU; is this always a good
>> thing, or does it have downsides as well (performance, power usage, ...)?
>>
>> Are there any other libraries that may be of interest to me?
>>
>> Thanks in advance
> 
> It probably depends on how low level you want to go, I have pondered
> about the possibility myself to have an all python(ic) gui toolkit,
> capable of writing a (x11) windowing manager itself with.
> But I decided that using tkinter and just live with its rough corners is
> more bang for the buck for me than to reimplement tkinter badly.
> 

Rather than writing a windowing toolkit from the low-level, I would
rather like to see some wrapper for existing windowing toolkit which
uses more pythonic idioms.

Most popular python GUI toolkit currently in use are only a simple thin
wrapper over the library they're wrapping and exposes a lot of the
design considerations of the language that the toolkit was originally
written in. Yes, even Tkinter that comes with the standard lib is a hack
on top of python and looks much more Tcl-ish than pythonic.

I have always had the idea of writing a windowing toolkit wrapper that
creatively uses python features for maximum expressiveness (e.g.
decorator, with-statement, for-each), but never got the time to write
anything like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python glibc crypt() function

2010-04-20 Thread geremy condra
On Tue, Apr 20, 2010 at 1:38 PM, Peter Otten <__pete...@web.de> wrote:
> luca72 wrote:
>
>> Hello i have to do this :
>> glibc crypt() function, using salt $1$abcdefgh$
>>
>> cryptPw = crypt(plainPw, "$1$abcdefgh$")
>>
>> I can do it in python, with package i need?
>> Thanks
>
 import ctypes
 lib = ctypes.CDLL("libcrypt.so.1")
 crypt = lib.crypt
 crypt.restype = ctypes.c_char_p
 crypt("password", "$1$abcdefgh$")
> '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
>
> Is that what it's supposed to return?
>
> Peter


Seems like my posts are dropping off of the net all of a sudden.
In case this didn't go through the first time...

http://docs.python.org/py3k/library/crypt.html#module-crypt

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


deleting objects present in a list

2010-04-20 Thread Sandy
Hi all,
I have large number of objects created and to handle them properly, I
store them in a list. How can I delete all of these objects (delete I
mean here is to remove the object from memory not just from list)? I
cannot use the list to iterate through the objects to delete them.
Because 'del' only reduces the reference count and as it is present in
the list it is not deleted. I cannot delete the list because I loose
control over the objects.

Can anyone give a nice solution for this?

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


Re: deleting objects present in a list

2010-04-20 Thread Chris Rebert
On Tue, Apr 20, 2010 at 12:21 PM, Sandy  wrote:
> Hi all,
> I have large number of objects created and to handle them properly, I
> store them in a list. How can I delete all of these objects (delete I
> mean here is to remove the object from memory not just from list)? I
> cannot use the list to iterate through the objects to delete them.
> Because 'del' only reduces the reference count and as it is present in
> the list it is not deleted. I cannot delete the list because I loose
> control over the objects.

And what exactly is supposed to happen to any other references to the
objects besides the references in the list?

If there are no such references, then deleting the objects from the
list will indeed delete them "for real" (although /exactly/ when the
unreferenced objects will be garbage-collected is
implementation-dependent; in CPython, it will be right then-and-there
due to its use of refcounting).

You might want to look at using weak references
(http://docs.python.org/library/weakref.html) for all references to
the objects other than the references in the list.

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


Re: deleting objects present in a list

2010-04-20 Thread Terry Reedy

On 4/20/2010 3:21 PM, Sandy wrote:

Hi all,
I have large number of objects created and to handle them properly, I
store them in a list. How can I delete all of these objects (delete I
mean here is to remove the object from memory not just from list)?
I cannot use the list to iterate through the objects to delete them.
Because 'del' only reduces the reference count and as it is present in
the list it is not deleted. I cannot delete the list because I loose
control over the objects.


Deleting the list is the best you can do. If that deletes the last 
reference, then the interpreter will delete the object when it feels 
like it. For *current* CPython, this will be immediately. For other 
implementations, whenever.



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


Re: python glibc crypt() function

2010-04-20 Thread Peter Otten
geremy condra wrote:

> On Tue, Apr 20, 2010 at 1:38 PM, Peter Otten <__pete...@web.de> wrote:
>> luca72 wrote:
>>
>>> Hello i have to do this :
>>> glibc crypt() function, using salt $1$abcdefgh$
>>>
>>> cryptPw = crypt(plainPw, "$1$abcdefgh$")
>>>
>>> I can do it in python, with package i need?
>>> Thanks
>>
> import ctypes
> lib = ctypes.CDLL("libcrypt.so.1")
> crypt = lib.crypt
> crypt.restype = ctypes.c_char_p
> crypt("password", "$1$abcdefgh$")
>> '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
>>
>> Is that what it's supposed to return?
>>
>> Peter
> 
> 
> Seems like my posts are dropping off of the net all of a sudden.
> In case this didn't go through the first time...
> 
> http://docs.python.org/py3k/library/crypt.html#module-crypt
> 
> Geremy Condra

This particular post did get get through, it is even marked as read over 
here.

Sorry for any confusion my pointless answer may have caused.

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


Re: Building a GUI Toolkit

2010-04-20 Thread Martin P. Hellwig

On 04/20/10 19:53, Lie Ryan wrote:



Rather than writing a windowing toolkit from the low-level, I would
rather like to see some wrapper for existing windowing toolkit which
uses more pythonic idioms.

Most popular python GUI toolkit currently in use are only a simple thin
wrapper over the library they're wrapping and exposes a lot of the
design considerations of the language that the toolkit was originally
written in. Yes, even Tkinter that comes with the standard lib is a hack
on top of python and looks much more Tcl-ish than pythonic.

I have always had the idea of writing a windowing toolkit wrapper that
creatively uses python features for maximum expressiveness (e.g.
decorator, with-statement, for-each), but never got the time to write
anything like that.


Well I suppose you could piggyback on tk for that and rewrapping tkinter 
to be more pythonic is probably more doable than rewriting it from scratch.


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


Re: gnu readline licensing?

2010-04-20 Thread Brendan Miller
On Tue, Apr 20, 2010 at 11:38 AM, Robert Kern  wrote:
> On 4/20/10 1:09 PM, Brendan Miller wrote:
>>
>> Python provides a GNU readline interface... since readline is a GPLv3
>> library, doesn't that make python subject to the GPL? I'm confused
>> because I thought python had a more BSD style license.
>
> The PSF License is more BSD-styled, yes. The readline module can also be
> built against the API-compatible, BSD-licensed libedit library. Python's
> source distribution (even the readline module source) does not have to be
> subject to the GPL, though it should be (and is) GPL-compatible.
>
>> Also, I presume programs written with the readline interface would
>> still be subject to GPL... might want to put a warning about that in
>> the python library docs.
>
> *When* someone builds a binary of the Python readline module against the GNU
> readline library, then that binary module is subject to the terms of the
> GPL. Any programs that distribute with and use that binary are also subject
> to the terms of the GPL (though it can have a non-GPL, GPL-compatible
> license like the PSF License). This only applies when they are combined with
> the GNU readline library, not before. The program must have a GPL-compatible
> license in order to be distributed that way. It can also be distributed
> independently of GNU readline under any license.
>

Hmm... So if I ship python to a customer with proprietary software
that runs on top of it, then I need to be careful to disable
libreadline? Is there a configure flag for this or something?

Since libreadline is the default for Linux systems, and Python's
license advertises itself as not being copyleft, and being embeddable
and shippable... It would be nice if this were made clear. Maybe a
note here about libreadline: http://python.org/psf/license/

It seems to me that the whole of the python distribution would be GPL
after being built with libreadline, so this would be an easy trap to
fall into if you didn't realize that python used libreadline.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Write web apps in Python?

2010-04-20 Thread Bryan
Bruno wrote:
> Bryan a écrit :
> > I think you guys got some incorrect info about PHP. A variety of
> > execution options are available, such as FastCGI and in-server
> > modules.
>
> mod_php, yes, but that doesn't change anything to the fact that it has
> to rebuild the whole world on each and every request. Not the same as a
> true long-running process.

> So, yes, you COULD write a cli PHP app, daemonize it, and add a mod_php
> / FastCGI / whatever request handler to interface the cli app with the
> web server, but that would be kinda pointless, wouldn't it ?

I think I see what you mean -- correct me if I'm wrong: You want to
keep complex application data structures around between requests. That
sounds appealing in terms of efficiency, but it's bad for scalability
and robustness.

> > PHP frameworks generally allow and encourage application code
> > to be independent of the underlying plumbing.
>
> This is debatable at best. PHP code (except cli PHP code of course) is
> written without any care for persistent global state, concurrency
> issues, race conditions etc - because it's written with the idea that
> the code serving a request will be runned in total isolation. CGI
> heritage here, obviously.

No, that's good web-app structure, regardless of language and server
interface. If we keep persistent global state in a shared database
rather than program variables, then we can run the app in multiple
processes and, if our service hits the big time, multiple hosts.


> And please note I'm not criticizing this
> design- just pointing one of it's consequences.
>
> > Many large,
> > sophisticated, high-volume web apps are in PHP.
>
> Did anyone pretend otherwise ?

How about this howler: "The PHP execution model (mostly based on CGI
FWIW) tends to be a bit unpractical for non-trivial applications".


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


Re: gnu readline licensing?

2010-04-20 Thread Robert Kern

On 4/20/10 3:49 PM, Brendan Miller wrote:

On Tue, Apr 20, 2010 at 11:38 AM, Robert Kern  wrote:

On 4/20/10 1:09 PM, Brendan Miller wrote:


Python provides a GNU readline interface... since readline is a GPLv3
library, doesn't that make python subject to the GPL? I'm confused
because I thought python had a more BSD style license.


The PSF License is more BSD-styled, yes. The readline module can also be
built against the API-compatible, BSD-licensed libedit library. Python's
source distribution (even the readline module source) does not have to be
subject to the GPL, though it should be (and is) GPL-compatible.


Also, I presume programs written with the readline interface would
still be subject to GPL... might want to put a warning about that in
the python library docs.


*When* someone builds a binary of the Python readline module against the GNU
readline library, then that binary module is subject to the terms of the
GPL. Any programs that distribute with and use that binary are also subject
to the terms of the GPL (though it can have a non-GPL, GPL-compatible
license like the PSF License). This only applies when they are combined with
the GNU readline library, not before. The program must have a GPL-compatible
license in order to be distributed that way. It can also be distributed
independently of GNU readline under any license.



Hmm... So if I ship python to a customer with proprietary software
that runs on top of it, then I need to be careful to disable
libreadline? Is there a configure flag for this or something?


Just don't ship the readline.so module. That's the only thing that links to 
libreadline.



Since libreadline is the default for Linux systems, and Python's
license advertises itself as not being copyleft, and being embeddable
and shippable... It would be nice if this were made clear. Maybe a
note here about libreadline: http://python.org/psf/license/


http://bugs.python.org


It seems to me that the whole of the python distribution would be GPL
after being built with libreadline, so this would be an easy trap to
fall into if you didn't realize that python used libreadline.


No, the whole Python distribution does not magically become GPLed because one 
optional module that you may or may not load is compiled against a GPLed library.


--
Robert Kern

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

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


Carol Newman

2010-04-20 Thread Zac Burns
http://www.ristorantealpirata.com/home.php

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


Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Jean-Michel Pichavant wrote:

Alan Harris-Reid wrote:

Hi,

During my Python (3.1) programming I often find myself having to 
repeat code such as...


class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat 
the class1 prefix?  Before Python my previous main language was 
Visual Foxpro, which had the syntax...


with class1
  .attr1 = 1
  .attr2 = 2
  .attr3 = 3
  .attr4 = 4
  etc.
endwith

Is there any equivalent to this in Python?

Any help would be appreciated.

Alan Harris-Reid

Hello,

Use an effective text editor, repeating stuff should not be a problem. 
In a more general manner, avoid trying to speed your writing while you 
should care speeding the reading.
Most of the tricks you could use will confuse the reader (unless the 
reader is familiar with Visual foxpro).


Anyway,

for attrName, value in [
   ('attr1', 1),
   ('attr2', 2),
   ('attr3', 3),
   ]:
   setattr(class1, attrName, value)

or

class Foo:
   def __init__(self):
  self.attr1=None
  self.attr2=None
  self.attr3=None

   def set(self, *args, **kwargs):
  for k in kwargs:
 if hasattr(self, k):
 setattr(self, k, kwargs[k])
 else:
   raise AttributeError('%s instance has no attribute "%s"' % 
(self.__class__.__name__, k))


f = Foo()
f.set(attr1=25)
print f.__dict__
f.set(attr3=4, attr2=89)
print f.__dict__
f.set(bar= 8)

output:
{'attr2': None, 'attr3': None, 'attr1': 25}
{'attr2': 89, 'attr3': 4, 'attr1': 25}
AttributeError: Foo instance has no attribute "bar"


JM


Hi Jean-Michel,

Interesting solutions, but I think for the effort involved (and 
readability) I'll stick to repeating the class.


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


Re: Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Peter Otten wrote:

Alan Harris-Reid wrote:

  

Hi,

During my Python (3.1) programming I often find myself having to repeat
code such as...

class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat the
class1 prefix?  Before Python my previous main language was Visual
Foxpro, which had the syntax...

with class1
   .attr1 = 1
   .attr2 = 2
   .attr3 = 3
   .attr4 = 4
   etc.
endwith

Is there any equivalent to this in Python?



No. You could write a helper function

  

def update(obj, **kw):


... for k, v in kw.items():
... setattr(obj, k, v)
...

and then use keyword arguments:

  

class A: pass


...
  

a = A()
update(a, foo=42, bar="yadda")
a.foo, a.bar


(42, 'yadda')
  

But if you are doing that a lot and if the attributes are as uniform as 
their names suggest you should rather use a Python dict than a custom class.


  

d = {}
d.update(foo=42, bar="whatever")
d


{'foo': 42, 'bar': 'whatever'}
  

d["bar"]


'whatever'

Peter

Hi Peter, thanks for the reply,

Interesting solution, but it looks as though it may be easier to repeat 
the class prefix a few times.


Alan

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


Re: Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Iain King wrote:

On Apr 20, 2:43 pm, Alan Harris-Reid 
wrote:
  

Hi,

During my Python (3.1) programming I often find myself having to repeat
code such as...

class1.attr1 =
class1.attr2 =
class1.attr3 =
class1.attr4 =
etc.

Is there any way to achieve the same result without having to repeat the
class1 prefix?  Before Python my previous main language was Visual
Foxpro, which had the syntax...

with class1
   .attr1 =
   .attr2 =
   .attr3 =
   .attr4 =
   etc.
endwith

Is there any equivalent to this in Python?

Any help would be appreciated.

Alan Harris-Reid



The pythonic equivalent of VB 'with' is to assign to a short variable
name, for example '_':

_ =lass1
_.attr1 =
_.attr2 =
_.attr3 =
_.attr4 =

alternatively, you could use the __setattr__ method:

for attr, value in (
('attr1', 1),
('attr2', 2),
('attr3', 3),
('attr4', 4)):
class1.__setattr__(attr, value)

and to get a bit crunchy, with this your specific example can be
written:

for i in xrange(1, 5):
class1.__setattr__('attr%d' % i, i)

Iain

Hi Iain, thanks for the reply,

Like the _. prefix idea - I didn't know _ could be used as a variable name.


for i in xrange(1, 5):
   class1.__setattr__('attr%d' % i, i)



Good solution if the values matched the attribute names, but 
unfortunately they don't.  That was just a (bad) example to illustrate 
my problem.


Regards,
Alan




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


Re: Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Stefan Behnel wrote:

Alan Harris-Reid, 20.04.2010 15:43:

During my Python (3.1) programming I often find myself having to repeat
code such as...

class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat the
class1 prefix? Before Python my previous main language was Visual
Foxpro, which had the syntax...

with class1
.attr1 = 1
.attr2 = 2
.attr3 = 3
.attr4 = 4
etc.
endwith

Is there any equivalent to this in Python?


There's more than one way to do this, depending on your actual needs 
and the source of the attributes. I assume this is done in __init__?


This might work for you:

self.__dict__.update(attr1=1, attr2=2, attr3=3, attr4=4)

You should also think once more about the use of the code you 
presented above, having to set all those attributes may have a little 
smell. Maybe that's totally ok, but since you mention that you "often" 
find yourself doing the above, you may also have a mental design 
problem somewhere. We can't tell unless you provide a more concrete 
example than what you show above.


Stefan

Hi Stefan, thanks for the reply.

The code is not usually in class.__init__ (otherwise I would have used 
the self. prefix), but I like your self.__dict__.update(...) solution 
and I'll try and remember it.


The code I was thinking of goes something like as follows (don't have a 
specific example to hand, but the principal is the same)...


NewClass = BaseClass()
NewClass.attr1 = value1
NewClass.attr2 = value2
NewClass.attr3 = value3
etc.

So if there are more than a couple of attributes to set for a class 
instance, how would you approach it (short of passing the values as 
parameters to BaseClass)?


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


Re: Re: Code redundancy

2010-04-20 Thread Xavier Ho
On Wed, Apr 21, 2010 at 7:59 AM, Alan Harris-Reid <
aharrisr...@googlemail.com> wrote:

> The code is not usually in class.__init__ (otherwise I would have used the
> self. prefix)


Alan, if your variables are not usually in __init__, what's preventing you
from using class variables like this:

>>> class Test():
... something = 1
... more = 2
...
>>> Test.more
2

What's your use case?

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


Re: deleting objects present in a list

2010-04-20 Thread Sandy
Thanks for the replies.

Terry,
What does 'immediately' mean? I did a small test and here are the
results.

import psutil

def testing():
class Object():
pass

l = {}
apm = psutil.avail_phymem()/(1024*1024)
print 'Before creating objs: ' + repr(apm)

for i in xrange(50):
l.update({Object():1})

apm = psutil.avail_phymem()/(1024*1024)
print 'After creating objs: ' + repr(apm)
return l

def hello():
myl = testing()

apm = psutil.avail_phymem()/(1024*1024)
print 'Before deleting: ' + repr(apm)

del myl

# Here I want to delete the objects in the list
# deleting myl doesn't seem to change the memory

apm = psutil.avail_phymem()/(1024*1024)
print 'After deleting: ' + repr(apm)


if __name__ == '__main__':
hello()

OUTPUT:
Before creating objs: 2516L
After creating objs: 2418L
Before deleting: 2418L
After deleting: 2430L

In my original case the memory is not getting released even after long
time.

- dksr


On Apr 20, 8:44 pm, Terry Reedy  wrote:
> On 4/20/2010 3:21 PM, Sandy wrote:
>
> > Hi all,
> > I have large number of objects created and to handle them properly, I
> > store them in a list. How can I delete all of these objects (delete I
> > mean here is to remove the object from memory not just from list)?
> > I cannot use the list to iterate through the objects to delete them.
> > Because 'del' only reduces the reference count and as it is present in
> > the list it is not deleted. I cannot delete the list because I loose
> > control over the objects.
>
> Deleting the list is the best you can do. If that deletes the last
> reference, then the interpreter will delete the object when it feels
> like it. For *current* CPython, this will be immediately. For other
> implementations, whenever.

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


Re: gnu readline licensing?

2010-04-20 Thread Irmen de Jong

On 20-4-2010 20:09, Brendan Miller wrote:

Python provides a GNU readline interface... since readline is a GPLv3
library, doesn't that make python subject to the GPL? I'm confused
because I thought python had a more BSD style license.

Also, I presume programs written with the readline interface would
still be subject to GPL... might want to put a warning about that in
the python library docs.


IANAL but I think because Python itself doesn't include the readline library as part of 
the distribution (it is installed on your system by other means), you have nothing to 
worry about. Only when you start to include it as part of your program, then you have to 
worry about the license(s) involved. But I can be wrong here.


-irmen


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


Re: [PyQt] Carol Newman

2010-04-20 Thread Nick Gaens
Please someone remove this address from the lists, because of spamming..

On Tue, Apr 20, 2010 at 11:13 PM, Zac Burns  wrote:

> http://www.ristorantealpirata.com/home.php
>
> --
> Zachary Burns
> (407)590-4814
> Aim - Zac256FL
> Production Engineer
> Zindagi Games
> ___
> PyQt mailing listp...@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



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


Re: deleting objects present in a list

2010-04-20 Thread Chris Rebert
> On Apr 20, 8:44 pm, Terry Reedy  wrote:
>> On 4/20/2010 3:21 PM, Sandy wrote:
>> > Hi all,
>> > I have large number of objects created and to handle them properly, I
>> > store them in a list. How can I delete all of these objects (delete I
>> > mean here is to remove the object from memory not just from list)?
>> > I cannot use the list to iterate through the objects to delete them.
>> > Because 'del' only reduces the reference count and as it is present in
>> > the list it is not deleted. I cannot delete the list because I loose
>> > control over the objects.
>>
>> Deleting the list is the best you can do. If that deletes the last
>> reference, then the interpreter will delete the object when it feels
>> like it. For *current* CPython, this will be immediately. For other
>> implementations, whenever.

On Tue, Apr 20, 2010 at 3:10 PM, Sandy  wrote:

> What does 'immediately' mean? I did a small test and here are the
> results.
>
> import psutil
>
> def testing():
>class Object():
>pass
>
>l = {}
>apm = psutil.avail_phymem()/(1024*1024)
>print 'Before creating objs: ' + repr(apm)
>
>for i in xrange(50):
>l.update({Object():1})
>
>apm = psutil.avail_phymem()/(1024*1024)
>print 'After creating objs: ' + repr(apm)
>return l
>
> def hello():
>myl = testing()
>
>apm = psutil.avail_phymem()/(1024*1024)
>print 'Before deleting: ' + repr(apm)
>
>del myl
>
># Here I want to delete the objects in the list
># deleting myl doesn't seem to change the memory
>
>apm = psutil.avail_phymem()/(1024*1024)
>print 'After deleting: ' + repr(apm)
>
>
> if __name__ == '__main__':
>hello()
>
> OUTPUT:
> Before creating objs: 2516L
> After creating objs: 2418L
> Before deleting: 2418L
> After deleting: 2430L
>
> In my original case the memory is not getting released even after long
> time.

Python does *delete* the objects, but makes no guarantees regarding
*returning memory* to the OS.
CPython holds onto the now-unused memory for a while so it's not
constantly thrashing and/or fragmenting memory by malloc()-ing some
and then free()-ing [some of] it right back.

I'm unsure if there's a way to force Python to actually free() unused
memory back to the OS.

Cheers,
Chris
--
Please don't top-post!
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Code redundancy

2010-04-20 Thread Chris Rebert
On Tue, Apr 20, 2010 at 2:59 PM, Alan Harris-Reid
 wrote:
> Stefan Behnel wrote:
>> Alan Harris-Reid, 20.04.2010 15:43:
>>> During my Python (3.1) programming I often find myself having to repeat
>>> code such as...
>>>
>>> class1.attr1 = 1
>>> class1.attr2 = 2
>>> class1.attr3 = 3
>>> class1.attr4 = 4
>>> etc.
>>>
>>> Is there any way to achieve the same result without having to repeat the
>>> class1 prefix? Before Python my previous main language was Visual
>>> Foxpro, which had the syntax...
>>>
>>> with class1
>>> .attr1 = 1
>>> .attr2 = 2
>>> .attr3 = 3
>>> .attr4 = 4
>>> etc.
>>> endwith
>>>
>>> Is there any equivalent to this in Python?
>>
>> There's more than one way to do this, depending on your actual needs and
>> the source of the attributes. I assume this is done in __init__?
>>
>> This might work for you:
>>
>>    self.__dict__.update(attr1=1, attr2=2, attr3=3, attr4=4)
>>
>> You should also think once more about the use of the code you presented
>> above, having to set all those attributes may have a little smell. Maybe
>> that's totally ok, but since you mention that you "often" find yourself
>> doing the above, you may also have a mental design problem somewhere. We
>> can't tell unless you provide a more concrete example than what you show
>> above.
>>
>> Stefan
>
> Hi Stefan, thanks for the reply.
>
> The code is not usually in class.__init__ (otherwise I would have used the
> self. prefix), but I like your self.__dict__.update(...) solution and I'll
> try and remember it.
>
> The code I was thinking of goes something like as follows (don't have a
> specific example to hand, but the principal is the same)...
>
> NewClass = BaseClass()
> NewClass.attr1 = value1
> NewClass.attr2 = value2
> NewClass.attr3 = value3
> etc.
>
> So if there are more than a couple of attributes to set for a class
> instance, how would you approach it (short of passing the values as
> parameters to BaseClass)?

Why are you against passing them as parameters?
If your constructor would have a lot of parameters, it may be a sign that:
(A) you have some Data Clumps
(http://martinfowler.com/bliki/DataClump.html) among the parameters
that ought to be made into full objects
(B) your class is doing too many things and needs to be split into
multiple classes
(http://www.refactoring.com/catalog/extractClass.html)

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


Re: [PyQt] Carol Newman

2010-04-20 Thread Chris Kaynor
There was a G-mail invasion earlier today that allowed e-mails to be sent
from any g-mail account without the owner's permission.

Chris


On Tue, Apr 20, 2010 at 3:06 PM, Nick Gaens  wrote:

> Please someone remove this address from the lists, because of spamming..
>
>
> --
> Nick Gaens
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code redundancy

2010-04-20 Thread Ethan Furman

Alan Harris-Reid wrote:
The code is not usually in class.__init__ (otherwise I would have used 
the self. prefix), but I like your self.__dict__.update(...) solution 
and I'll try and remember it.


The code I was thinking of goes something like as follows (don't have a 
specific example to hand, but the principal is the same)...


NewClass = BaseClass()
NewClass.attr1 = value1
NewClass.attr2 = value2
NewClass.attr3 = value3
etc.

So if there are more than a couple of attributes to set for a class 
instance, how would you approach it (short of passing the values as 
parameters to BaseClass)?


Unless I'm missing something (your use-case, perhaps? ;) in this example 
NewClass is *not* a class -- it's an instance of BaseClass, and you are 
dynamically adding attributes to it.


It's definitely a switch coming from FoxPro (me, too!), but it is well 
worth it once your brain starts working pythonically.


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


Re: [PyQt] Carol Newman

2010-04-20 Thread Zac Burns
Yes, please do not remove me. Sorry for the inconvenience!
--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer
Zindagi Games


On Tue, Apr 20, 2010 at 3:36 PM, Chris Kaynor wrote:

> There was a G-mail invasion earlier today that allowed e-mails to be sent
> from any g-mail account without the owner's permission.
>
> Chris
>
>
> On Tue, Apr 20, 2010 at 3:06 PM, Nick Gaens  wrote:
>
>> Please someone remove this address from the lists, because of spamming..
>>
>>
>> --
>> Nick Gaens
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Xavier Ho wrote:
On Wed, Apr 21, 2010 at 7:59 AM, Alan Harris-Reid 
mailto:aharrisr...@googlemail.com>> wrote:


The code is not usually in class.__init__ (otherwise I would have
used the self. prefix)


Alan, if your variables are not usually in __init__, what's preventing 
you from using class variables like this:


>>> class Test():
... something = 1
... more = 2
...
>>> Test.more

2

What's your use case?

Cheers,
Xav

Hi Xavier, thanks for the reply,

In this case I am setting attributes of an instantiated class, so the 
original class might go something like


class Test
   attr1 = some default value
   attr2 = another default value
   attr3 = yet another default value
   etc.

and the instantiated class might go something like

Test2 = Test()
Test2.attr1 = runtime value
Test2.attr2 = another runtime value
etc.

Regards,
Alan




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


Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Chris Rebert wrote:

On Tue, Apr 20, 2010 at 2:59 PM, Alan Harris-Reid
 wrote:
  

Stefan Behnel wrote:


Alan Harris-Reid, 20.04.2010 15:43:
  

During my Python (3.1) programming I often find myself having to repeat
code such as...

class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat the
class1 prefix? Before Python my previous main language was Visual
Foxpro, which had the syntax...

with class1
.attr1 = 1
.attr2 = 2
.attr3 = 3
.attr4 = 4
etc.
endwith

Is there any equivalent to this in Python?


There's more than one way to do this, depending on your actual needs and
the source of the attributes. I assume this is done in __init__?

This might work for you:

   self.__dict__.update(attr1=1, attr2=2, attr3=3, attr4=4)

You should also think once more about the use of the code you presented
above, having to set all those attributes may have a little smell. Maybe
that's totally ok, but since you mention that you "often" find yourself
doing the above, you may also have a mental design problem somewhere. We
can't tell unless you provide a more concrete example than what you show
above.

Stefan
  

Hi Stefan, thanks for the reply.

The code is not usually in class.__init__ (otherwise I would have used the
self. prefix), but I like your self.__dict__.update(...) solution and I'll
try and remember it.

The code I was thinking of goes something like as follows (don't have a
specific example to hand, but the principal is the same)...

NewClass = BaseClass()
NewClass.attr1 = value1
NewClass.attr2 = value2
NewClass.attr3 = value3
etc.

So if there are more than a couple of attributes to set for a class
instance, how would you approach it (short of passing the values as
parameters to BaseClass)?



Why are you against passing them as parameters?
If your constructor would have a lot of parameters, it may be a sign that:
(A) you have some Data Clumps
(http://martinfowler.com/bliki/DataClump.html) among the parameters
that ought to be made into full objects
(B) your class is doing too many things and needs to be split into
multiple classes
(http://www.refactoring.com/catalog/extractClass.html)

Cheers,
Chris
--
Yay Refactoring!
http://blog.rebertia.com


Hi Chris, thanks for the reply.

Nothing against passing the values as parameters, but it can start to 
look a bit ugly if there are too many of them.  Which brings me to your 
2nd point of maybe refactoring the passing/receiving of parameters so 
that I can use an object with attributes instead of individual variable 
values.


Thanks,
Alan

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


Re: Code redundancy

2010-04-20 Thread Alan Harris-Reid

Ethan Furman wrote:

Alan Harris-Reid wrote:
The code is not usually in class.__init__ (otherwise I would have 
used the self. prefix), but I like your self.__dict__.update(...) 
solution and I'll try and remember it.


The code I was thinking of goes something like as follows (don't have 
a specific example to hand, but the principal is the same)...


NewClass = BaseClass()
NewClass.attr1 = value1
NewClass.attr2 = value2
NewClass.attr3 = value3
etc.

So if there are more than a couple of attributes to set for a class 
instance, how would you approach it (short of passing the values as 
parameters to BaseClass)?


Unless I'm missing something (your use-case, perhaps? ;) in this 
example NewClass is *not* a class -- it's an instance of BaseClass, 
and you are dynamically adding attributes to it.


It's definitely a switch coming from FoxPro (me, too!), but it is well 
worth it once your brain starts working pythonically.


~Ethan~


Hi Ethan,
You are correct - NewClass is an instance of BaseClass and I chose a 
very bad class-name as an example.


Good to see ex-Fox people on this list.  I have recently got stuck-into 
learning Python after my last VFP contract finished last December - wish 
I had started years ago.  Really glad I went for Python, which I thought 
would be the easiest transition from Foxpro (I looked at other 
languages, but none came near to Python in terms of popularity and 
developer-friendly syntax).  What's your story?


Regards,
Alan

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


Re: Building a GUI Toolkit

2010-04-20 Thread Martin P. Hellwig

On 04/20/10 21:15, Martin P. Hellwig wrote:

On 04/20/10 19:53, Lie Ryan wrote:



Rather than writing a windowing toolkit from the low-level, I would
rather like to see some wrapper for existing windowing toolkit which
uses more pythonic idioms.

Most popular python GUI toolkit currently in use are only a simple thin
wrapper over the library they're wrapping and exposes a lot of the
design considerations of the language that the toolkit was originally
written in. Yes, even Tkinter that comes with the standard lib is a hack
on top of python and looks much more Tcl-ish than pythonic.

I have always had the idea of writing a windowing toolkit wrapper that
creatively uses python features for maximum expressiveness (e.g.
decorator, with-statement, for-each), but never got the time to write
anything like that.


Well I suppose you could piggyback on tk for that and rewrapping tkinter
to be more pythonic is probably more doable than rewriting it from scratch.



On second thought, if you would like borderless windows (for example to 
implement all widgets from scratch), you run into troubles, as 
overrideredirect also affects the keyboard focus, so you can't use the 
keyboard in any widget created. And also it would be ice to still have 
an iconify option.


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


Re: python wia and RegisterEvent

2010-04-20 Thread News123
Hi Roger,

Roger Upole wrote:
> gelonida wrote:
> ...
>> while True:
>> print "sleep"
>> time.sleep(10)
>>
>> When I plug / unplug a USB WIA device nothing shows up.
>> My C# implementation prints messages on wiaEventDeviceConnected /
>> wiaEventDeviceDisconnected events if I register them.
>>
>> What am I missing?
> 
> You need to be processing messages to receive COM events.
> Try replacing your sleep loop with pythoncom.PumpMessages().
> 

Thanks a lot

Indeed the only thing missing was a call to pythoncom.PumpMessages()

I fell over another tiny detail though, as I wanted to keep my main
application running ( the place holder was my sleep loop)

Tt seems, that PumpMessages() cannot be in another thread.


So I ended up with:

import win32com.client,pythoncom,time,threading

defaultNamedNotOptArg=pythoncom.Empty
wiaEventDeviceConnected =u'{A28BBADE-64B6-11D2-A231-00C04FA31809}'

class MgrHandlerClass:
def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg,
ItemID=defaultNamedNotOptArg):
print "Called back with ..."


mgrhndlr = MgrHandlerClass()
manager = win32com.client.DispatchWithEvents("WIA.DeviceManager",
MgrHandlerClass)
manager.RegisterEvent(EventID=wiaEventDeviceConnected,DeviceID=u'*')

def sleeploop():
while True:
print "sleep"
time.sleep(10)

thrd = threading.Thread(target=sleeploop)
thrd.start()
# doesn't work if pump is in another thread
pythoncom.PumpMessages()


bye



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


Re: Carol Newman -- SPAM

2010-04-20 Thread Paul Rubin
  [url snipped - forwards to viagra spam]
-- 
Zachary Burns
[phone number snipped]

A Joe job?  Poster had looked vaguely legitimate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python glibc crypt() function

2010-04-20 Thread Дамјан Георгиевски
>> Hello i have to do this :
>> glibc crypt() function, using salt $1$abcdefgh$
>> 
>> cryptPw = crypt(plainPw, "$1$abcdefgh$")
>> 
>> I can do it in python, with package i need?
>> Thanks
> 
 import ctypes
 lib = ctypes.CDLL("libcrypt.so.1")
 crypt = lib.crypt
 crypt.restype = ctypes.c_char_p
 crypt("password", "$1$abcdefgh$")
> '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
> 
> Is that what it's supposed to return?

seeing this I thought about using ctypes for AES (or similar) crypto 
function. A bit of google searching I've come to 
http://code.google.com/p/ctypescrypto/

just FYI


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

... knowledge is exactly like power - something 
to be distributed as widely as humanly possible,
for the betterment of all. -- jd

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


Re: Building a GUI Toolkit

2010-04-20 Thread Дамјан Георгиевски
> Rather than writing a windowing toolkit from the low-level, I would
> rather like to see some wrapper for existing windowing toolkit which
> uses more pythonic idioms.

Isn't PyGUI exactly that?
http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Spammers scratch here with a diamond to find my address:
|||

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


Re: python glibc crypt() function

2010-04-20 Thread geremy condra
2010/4/20 Дамјан Георгиевски :
>>> Hello i have to do this :
>>> glibc crypt() function, using salt $1$abcdefgh$
>>>
>>> cryptPw = crypt(plainPw, "$1$abcdefgh$")
>>>
>>> I can do it in python, with package i need?
>>> Thanks
>>
> import ctypes
> lib = ctypes.CDLL("libcrypt.so.1")
> crypt = lib.crypt
> crypt.restype = ctypes.c_char_p
> crypt("password", "$1$abcdefgh$")
>> '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
>>
>> Is that what it's supposed to return?
>
> seeing this I thought about using ctypes for AES (or similar) crypto
> function. A bit of google searching I've come to
> http://code.google.com/p/ctypescrypto/
>
> just FYI

ctypescrypto does not appear to be maintained, but I've started
a similar project called evpy (http://gitorious.org/evpy) that also
provides envelope encryption. Comments are welcome- we're
probably going to be doing our first release sometime towards
the middle of next month.

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


MAKE A SHITLOAD OF MONEY!!!

2010-04-20 Thread Krushbrook
A little while back, I was browsing these newsgroups, just like you

 are now, and came across an article similar to this that said you

 could make thousands of dollars within weeks with only an initial

 investment of $5.00 !  So I thought, "Yeah, right, this must be a

 scam", like most of us, but I was curious, like most of us, so I kept

 reading. Anyway, it said that you send $1.00 to each of the 5 names

 and address stated in the article. You then place your own name and

 address in the bottom of the list of #5, and post the article in at

 least 200 newsgroups.(There are thousands) No catch, that was it.



So after thinking it over, and talking to a few people first, I

thought about trying it. I figured what I have got to lose except 5

stamps and $5.00, right?



Like most of us I was a little skeptical and a little worried about

the legal aspects of it all. So I checked it out with U.S. Post

Office(1-800-725-2161) and they confirmed that it is indeed lega!

Then I invested the measly $5.00

\\

\Well GUESS WHAT! !. With in 7 days, I started getting money in

the mail! I was shocked! I still figured it end soon, and didn't give

it another thought. But the money just coming in. In my first week, I

made about $20.00 to $30.00 dollars. By the end of the second week I

had made total of over $1,000.00!!  In the third week I had over

$10,000.00 and it's still growing. This is now my fourth week and I

have made a total of just over $42,000.00 and it's still comming in

...  It's certainly worth $5.00, and 5 stamps, I spent more than

that on the lottery!!



Let me tell you how this works and most importantly, Why it works

also, make sure you print a copy of this article NOW, so you can get

the information of it as you need it. The process is very simple and

consists of 3 easy steps :



STEP 1 : Get 5 separate pieces of paper and write the following on

each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST." now get 5

$1.00 bills and place ONE inside EACH of the 5 pieces of paper so the

bill will not be seen through the envelopes to prevent thievery. Next,


place on paper in each of the 5 envelopes and seal them. You should

now have 5 sealed envelopes, each with a piece of paper stating the

above phrase and a $1.00 bill. What you are doing is creating a

service by this. THIS IS PERFECTLY LEGAL!



Mail the 5 envelopes to the following addresses :



#1  Occupant
  P.O. Box 54230
  Houston, Tx.
  77272-1193
  U.S.A.


#2  Kevin Michael
  1006 Abercorn Place
  Sherwood, AR 72120
  U.S.A.


#3   Chang
   P.O.Box 502651
   San Diego CA 92150-2651
   U.S.A.


#4   Belchior Mira
  R. Jose Dias Coelho, 7, 1 DT
  Bom-Sucesso, ALVERCA
  2615
  PORTUGAL


#5 Kylen Rushbrook
 P.O. Box 2
 Danforth IL, 60930
 U.S.A

STEP 2 : Now take the #1 name off the list that you see above, move

the other names up ( 5 becomes 4, 4 becomes 3, etc...) and add YOUR

Name as number 5 on the list.



STEP 3 : Change anything you need to, but try to keep this article as

close to original as possible. Now, post your mended article to at

least 200 newsgroups. (I think there are close to 18,000 groups) All

you need is 200, but remember, the more you post, the more money you

make! Don't know How post in the newsgroups? Well do exactly the

following :



FOR NETSCAPE USERS,


 1) Click on any newsgroups, like normal. Then click on "To News",


which is in the top left corner of the newsgroups page. This will

bring up a message box.


 2) Fill in the SUBJECT with a flashy title, like the one I used,

something to catch the eye!!!


 3) Now go to the message part of the box and retype this letter

exactly as it tis here, with exception of your few changes. (remember

to add your name to number 5 and move the rest up)


 4) When you're done typing in the WHOLE letter, click on 'FILE'

above the send button. Then, 'SAVE AS..' DO NOT SEND YOUR ARTICLE

UNTIL YOU SAVE IT. (so you don't have to type this 200 times :-)


 5) Now that you have saved the letter, go ahead and send your

first copy! (Click the 'SEND' button in the top left corner)


 6) This is where you post all 200! OK, go to ANY newsgroup

article and click the 'TO NEWS' button again. Type in your flashy

subject in the 'SUBJECT BOX', then go to the message and place your

cursor here. Now click on 'ATTACHMENT' which is right below the

'SUBJECT BOX'. Click on attach file then find your letter wherever you


saved it. Click once on your file then click 'OPEN' then click 'OK'.

If you did this right, you should see your filename in the 'ATTACHMENT


BOX' and it will be shaded.

 NOW POST AWAY!!




IF YOU'RE USING INTERNET EXPLORER :


 It's just as easy, holding down the left mouse button, highlight

this entire article, then press the 'CTRL' key and 'C' key at the same


time to copy this article. Then print the article for yo

Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-20 Thread John Yeung
alex23 wrote:
> > > > I stand corrected. Thanks Cameron.

Cameron Simpson wrote:
> > > Oh, I was all ready to say what you said, but decided
> > > to check the docs myself first:-)

John Yeung wrote:
> > I am not too comfortable relying on it.  It feels
> > fragile and "implementationy" to me, as I'm sure
> > it does to many people (such as everyone in this
> > thread so far! ;)

Steven D'Aprano wrote:
> It is a language feature that is guaranteed to be true
> for every implementation of Python

I never said it wasn't guaranteed to be true.  I said it *feels*
implementationy *to me*.

> Defensive programming is good, but at the point that you
> don't believe the promises that the language makes, how
> can you trust anything?

[Leave it to me to answer a rhetorical question.]  I *believe* all the
promises a language makes.  I don't *trust* (more like depend on) all
of them equally.  If I (that is, me personally, with all my
fallibility, insufficient knowledge of the language, etc.) feel that a
promise is one that the language absolutely cannot afford to break, I
will trust it not to break that promise.  I won't need some document
telling me "no, really and truly, we guarantee that".  Other promises
seem (to limited, fallible, subjective me) as though they would not be
the end of the world if the language broke them.  And so I am less
likely to rely on those promises, even as I steadfastly stake my life
on other promises.

> if you don't trust the language to behave
> correctly in this case:
>
> pairs = zip(d.values(), d.items())
>
> what makes you think you can trust d.iteritems(),
> list comprehensions, or even tuple packing and unpacking?

Not sure how often I'd want a list of value-item pairs, but anyway,
you don't have to trust that d.values() and d.items() have the same
order to use them individually, or to use the other stuff.  I do trust
that list comps work and that tuple packing and unpacking work.  And I
trust each individual key-value pair in a dictionary to have the
correct key associated with the correct value... because that is the
whole purpose of the dictionary.  Without it, dictionaries are just
useless.  But d.items(), d.keys(), and d.values() could all use
different orderings without rendering dictionaries (or zip) pointless,
and certainly without destroying the usefulness of the language.

> It would be a waste of time and code for me to write
>
> a//b, a%b
>
> just because I can't remember what divmod() does.

That is your opinion, and it may well be the opinion of the Python
community at large.  Fine.  The version that doesn't use divmod is, to
me, short enough and easy enough to read.  I can easily imagine
someone spending enough time looking up the docs (even if only to type
help(divmod)) that it would be a net gain of time to simply avoid
divmod altogether and just type the code that comes naturally to them.

> > All in all, the alternative idiom for flipping keys
> > and values (provided in the docs a couple of sentences
> > down from your quote) is short enough for my taste,
> > easy enough for me to read, and never makes me wonder
> > if I should check the docs just to be sure:
>
> >   pairs = [(v, k) for (k, v) in d.iteritems()]
>
> Yes, and if you can't remember whether or not ints are
> automatically promoted to longs, you will continue writing
> this long after it became unnecessary:
>
> try:
>     result = a + b
> except OverflowError:
>     result = long(a) + long(b)
>
> and then other coders will laugh at you :)

Well, maybe there are coders out there who find that snippet short
enough and easy enough to read.  Maybe they are comfortable typing it
all the time and seeing it all over their code.  But if *I* can't
remember whether ints are automatically promoted to longs, then what
*I* will continue to write is actually just

result = long(a) + long(b)

;)

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


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-20 Thread alex23
Steven D'Aprano  wrote:
> if you don't trust the language to behave
> correctly in this case:
>
> pairs = zip(d.values(), d.items())
>
> what makes you think you can trust d.iteritems(), list comprehensions, or
> even tuple packing and unpacking?

Because .iteritems() is an atomic operation while the .values/.items
approach is two independent calls. That the former binds the two
together in its implementation makes sense, that two _independent_
methods are bound feels far more like magic.


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


Re: Japanese (speaking) developer needed for a bit of regex magic

2010-04-20 Thread Ben Finney
Sebastian  writes:

> All locales return error messages in English. Only the Japanese uses
> Japanese which my regular expressions cannot handle at the moment.

What exactly are you expecting to happen, and what exactly happens
instead?

General advice with character sets in Python apply: always explicitly
declare the encoding of input, then decode to Unicode interally as early
as possible, and process all text that way. Only fix into an encoding
when it's time to output.

-- 
 \  “I find the whole business of religion profoundly interesting. |
  `\ But it does mystify me that otherwise intelligent people take |
_o__)it seriously.” —Douglas Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib2 times out accessing SSL URL on OS X

2010-04-20 Thread Martin Aspeli
Hi,

I am trying to connect to an HTTPS URL using urllib2.urlopen() (in
fact, the Suds SOAP client, which internally uses urlopen) on Mac OS X
Snow Leopard, with Python 2.6 built from source.

The website has a certificate (for *.domain.com), issued by Go Daddy
Secure Certification Authority. It is definitely valid.

I can open the web page in Firefox and Safari (but not in Chrome,
interestingly). However, urllib2 just times out trying to access it,
with not obvious error message (I get URLError: )

On SuSE linux (our server), it works just fine. I didn't have to do
any fiddling at the OS level.

I've exported the certificate from Firefox and tried to add it to the
System keychain in Keychain Access in OS X, and set it as trusted, but
nothing seems to work.

Any hints would be appreciated!

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


HOW TO build object graph or get superclasses list for self.__class__ ?

2010-04-20 Thread Dmitry Ponyatov
Hello

Help please with such problem:

I need to build program object graph (data structure) with additional
parameters for nodes and edges:

include nxgraph # data structure module allowes any py objects for
node/edge id
# (nxgraph ignores 2+ node/edge adding thus no checking need at node/
edge adding)

OBJ_TREE = nxgraph.DiGraph() # directed graph

OBJ_TREE.add_node(object,color='red') # root object

class A(object):
def __init__(self):
object.__init__(self) # (1) maybe map(lambda
s:s.__init__(self), self.__super__) better if I have __super__
OBJ_TREE.add_node(self.__class__,color='red') # (2) add self
class as new node
for SUP in self.__super__:
OBJ_TREE.add_edge(SUP,self.__class__,color='red') # (3)
add super class
  # to self class red arrow (directed
edge)
OBJ_TREE.add_node(self,color='blue') # (4) add self object
instance node
OBJ_TREE.add_edge(self.__class__,self,color='blue') # (5) add
object producing from class edge
OBJ_TREE.plot(sys.argv[0]+'.objtree.png') # dump obj tree as
picture to .png file

class B(A):
pass

class C(A):
pass

Using Python 2.5 I can't realize line (3) in A class, but lines 2) (4)
(5) works well
How can I realize some function get_super(self) giving list of
superclasses for self.__class__ ?
Preferable using py2.5

How days I must reimplement __init__ by dumb copy from parent class to
child class like

class B(A):
def __init__(self):
A.__init__(self)
OBJ_TREE.add_node(A,B) ; OBJ_TREE.plot('OBJ_TREE.png')

class C(A):
def __init__(self):
A.__init__(self)
OBJ_TREE.add_node(A,C) ; OBJ_TREE.plot('OBJ_TREE.png')

class D(B,C):
def __init__(self):
B.__init__(self) ; OBJ_TREE.add_node(B,D)
C.__init__(self) ; OBJ_TREE.add_node(C,D)
OBJ_TREE.plot('OBJ_TREE.png')

This is not good -- a lot of dumb code with chance to make mistakes



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


Re: HOW TO build object graph or get superclasses list for self.__class__ ?

2010-04-20 Thread James Mills
On Wed, Apr 21, 2010 at 3:35 PM, Dmitry Ponyatov  wrote:
> Hello
>
> Help please with such problem:
>
> I need to build program object graph (data structure) with additional
> parameters for nodes and edges:
>
> include nxgraph # data structure module allowes any py objects for
> node/edge id
> # (nxgraph ignores 2+ node/edge adding thus no checking need at node/
> edge adding)
>
> OBJ_TREE = nxgraph.DiGraph() # directed graph
>
> OBJ_TREE.add_node(object,color='red') # root object
>
> class A(object):
>    def __init__(self):
>        object.__init__(self) # (1) maybe map(lambda
> s:s.__init__(self), self.__super__) better if I have __super__
>        OBJ_TREE.add_node(self.__class__,color='red') # (2) add self
> class as new node
>        for SUP in self.__super__:
>            OBJ_TREE.add_edge(SUP,self.__class__,color='red') # (3)
> add super class
>                                  # to self class red arrow (directed
> edge)
>        OBJ_TREE.add_node(self,color='blue') # (4) add self object
> instance node
>        OBJ_TREE.add_edge(self.__class__,self,color='blue') # (5) add
> object producing from class edge
>        OBJ_TREE.plot(sys.argv[0]+'.objtree.png') # dump obj tree as
> picture to .png file
>
> class B(A):
>    pass
>
> class C(A):
>    pass
>
> Using Python 2.5 I can't realize line (3) in A class, but lines 2) (4)
> (5) works well
> How can I realize some function get_super(self) giving list of
> superclasses for self.__class__ ?
> Preferable using py2.5
>
> How days I must reimplement __init__ by dumb copy from parent class to
> child class like
>
> class B(A):
>    def __init__(self):
>        A.__init__(self)
>        OBJ_TREE.add_node(A,B) ; OBJ_TREE.plot('OBJ_TREE.png')
>
> class C(A):
>    def __init__(self):
>        A.__init__(self)
>        OBJ_TREE.add_node(A,C) ; OBJ_TREE.plot('OBJ_TREE.png')
>
> class D(B,C):
>    def __init__(self):
>        B.__init__(self) ; OBJ_TREE.add_node(B,D)
>        C.__init__(self) ; OBJ_TREE.add_node(C,D)
>        OBJ_TREE.plot('OBJ_TREE.png')
>
> This is not good -- a lot of dumb code with chance to make mistakes

Why not make things simple and just write a function
that computes the edges of a class tree ? Something like this:

http://codepad.org/xWKDlS52

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


Re: python glibc crypt() function

2010-04-20 Thread luca72
On 20 Apr, 19:38, Peter Otten <__pete...@web.de> wrote:
> luca72 wrote:
> > Hello i have to do this :
> > glibc crypt() function, using salt $1$abcdefgh$
>
> > cryptPw = crypt(plainPw, "$1$abcdefgh$")
Thanks
The result is correct i obtain the same with ctypes and crypt module,
so i think that is better to use the crypt module is correct?

Luca

>
> > I can do it in python, with package i need?
> > Thanks
> >>> import ctypes                                                    
> >>> lib = ctypes.CDLL("libcrypt.so.1")                                
> >>> crypt = lib.crypt
> >>> crypt.restype = ctypes.c_char_p
> >>> crypt("password", "$1$abcdefgh$")
>
> '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
>
> Is that what it's supposed to return?
>
> Peter

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


Re: Python DXF import library?

2010-04-20 Thread Justin Ezequiel
On Apr 20, 9:19 pm, Stodge  wrote:
> Is anyone aware of a Python DXF import library? I think I remember
> seeing converters but so far I haven't found a library. I need to
> write a tool that reads DXFs so I'm not yet sure if a converter would
> be of any use. Thanks

http://lmgtfy.com/?q=Python+DXF

3rd hit is a reader hosted on Google
-- 
http://mail.python.org/mailman/listinfo/python-list