RE: a problem about "print"

2012-07-03 Thread Shambhu Rajak
You can use :
print "aList is "+repr([x,x,x,x,x,x,x,x,x])

-Shambhu

From: levi nie [mailto:levinie...@gmail.com]
Sent: 04/07/2012 9:43 AM
To: python-list@python.org
Subject: a problem about "print"

aList is a list.i want to get the output seem this "aList is 
[x,x,x,x,x,x,x,x,x]"
how can i get this?
it's wrong when i write this, print "aList is "+[x,x,x,x,x,x,x,x,x]

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


Re: code review

2012-07-03 Thread Littlefield, Tyler

On 7/3/2012 10:55 PM, Simon Cropper wrote:

Some questions to Tyler Littlefield, who started this thread.

Q1 -- Did you get any constructive feedback on your code?


I did get some, which I appreciated. someone mentioned using PyLint. 
From reading, I found it was really really pedantic, so I used PyFlakes 
instead.


Q2 -- Did you feel that the process of submitting your code for review 
met your expectation?


There wasn't much more to review, so yes. The info I got was helpful and 
farther than it was before I started.


Q3 -- Would you recommend others doing this either on this forum or 
other fora?


It appears to me - third party watching the ongoing dialog - that the 
tread has gone right off topic (some time ago) and someone should 
really start a new thread under a new title/subject. Most of what I 
have read does not appear to be discussing your code or how you could 
improve your code.


I basically just stopped after a while. It got into a my language is 
better than your language, so I didn't see much constructive info. I've 
started reading from the bottom though, where it looks like it's back, 
and I do appreciate the rest of the info given, as well. Thanks again 
for the feedback.


Following the last few posts, I was wondering whether some other 
off-list dialog is going on or whether I am missing something.





--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: code review

2012-07-03 Thread Simon Cropper

On 04/07/12 13:53, Chris Angelico wrote:

On Wed, Jul 4, 2012 at 12:57 PM,   wrote:

Well, if you waited until you had the password (however long) in a variable 
before you applied your maximum limits, the DoS ship has probably sailed 
already.


Only because data transfer is usually more expensive than hashing. But
I'd say that'll always be true.

ChrisA



Some questions to Tyler Littlefield, who started this thread.

Q1 -- Did you get any constructive feedback on your code?

Q2 -- Did you feel that the process of submitting your code for review 
met your expectation?


Q3 -- Would you recommend others doing this either on this forum or 
other fora?


It appears to me - third party watching the ongoing dialog - that the 
tread has gone right off topic (some time ago) and someone should really 
start a new thread under a new title/subject. Most of what I have read 
does not appear to be discussing your code or how you could improve your 
code.


Following the last few posts, I was wondering whether some other 
off-list dialog is going on or whether I am missing something.


--
Cheers Simon



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


Re: a problem about "print"

2012-07-03 Thread Harrison Morgan
On Wed, Jul 4, 2012 at 12:16 AM, levi nie  wrote:

> print "aList is "+string(aList) ?
>
>
> 2012/7/4 levi nie 
>
>> aList is a list.i want to get the output seem this "aList is
>> [x,x,x,x,x,x,x,x,x]"
>> how can i get this?
>> it's wrong when i write this, print "aList is "+[x,x,x,x,x,x,x,x,x]
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
Try this:

print "aList is", aList

That shows it like your example. The problem with how you were trying it
is, you have a string and a list and you're trying to combine (concatenate)
them. That doesn't work. One way to get around that is to change the list
into a string, like your second post (it would be str(aList), by the way).
By separating them with a comma instead of a plus, the print statement does
that for you, and also inserts a space in-between them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a problem about "print"

2012-07-03 Thread levi nie
print "aList is "+string(aList) ?

2012/7/4 levi nie 

> aList is a list.i want to get the output seem this "aList is
> [x,x,x,x,x,x,x,x,x]"
> how can i get this?
> it's wrong when i write this, print "aList is "+[x,x,x,x,x,x,x,x,x]
>
-- 
http://mail.python.org/mailman/listinfo/python-list


a problem about "print"

2012-07-03 Thread levi nie
aList is a list.i want to get the output seem this "aList is
[x,x,x,x,x,x,x,x,x]"
how can i get this?
it's wrong when i write this, print "aList is "+[x,x,x,x,x,x,x,x,x]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread Chris Angelico
On Wed, Jul 4, 2012 at 12:57 PM,   wrote:
> Well, if you waited until you had the password (however long) in a variable 
> before you applied your maximum limits, the DoS ship has probably sailed 
> already.

Only because data transfer is usually more expensive than hashing. But
I'd say that'll always be true.

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


Re: code review

2012-07-03 Thread kushal . kumaran+python
Ian Kelly  wrote:

>On Tue, Jul 3, 2012 at 11:53 AM, Kushal Kumaran
> wrote:
>> On Sat, Jun 30, 2012 at 3:34 PM, Alister 
>wrote:
>>> On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote:
>>>
 On 6/29/2012 1:31 AM, Steven D'Aprano wrote:
> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote:
>
>> On Jun 29, 12:57 pm, "Littlefield, Tyler" 
>wrote:
>>> I was curious if someone wouldn't mind poking at some code. The
>>> project page is at:http://code.google.com/p/pymud Any
>information is
>>> greatly appreciated.
>> I couldn't find any actual code at that site, the git repository
>is
>> currently empty.

 OOPS, sorry. Apparently I'm not as good with git as I thought.
 Everything's in the repo now.
>>>
>>> I think I may be on firmer grounds with the next few:
>>>
>>> isValidPassword can be simplified to
>>>
>>> def isValidPassword(password:
>>> count=len(password)
>>> return count>= mud.minpass and count<= mud.maxpass
>>>
>>
>> I haven't actually seen the rest of the code, but I would like to
>> point out that applications placing maximum length limits on
>passwords
>> are extremely annoying.
>
>They're annoying when the maximum length is unreasonably small, but
>you have to have a maximum length to close off one DoS attack vector.
>Without a limit, if a "user" presents a 1 GB password, then guess
>what?  Your system has to hash that GB of data before it can reject
>it.  And if you're serious about security then it will be a
>cryptographic hash, and that means slow.
>

Well, if you waited until you had the password (however long) in a variable 
before you applied your maximum limits, the DoS ship has probably sailed 
already. 

>To prevent that, the system needs to reject outright password attempts
>that are longer than some predetermined reasonable length, and if the
>system won't authenticate those passwords, then it can't allow the
>user to set them either.
>
>Cheers,
>Ian


-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exe made by py2exe do not run certain computer

2012-07-03 Thread Mark Hammond

On 4/07/2012 9:46 AM, Miki Tebeka wrote:

It works fine on my computer and some other computer don't have
python interpreter(it's Windows 7). But the same file also do not
work on another computer(it's Windows xp) why does it happen?

My *guess* is that you're missing some DLLs (probably some Visual
Studio runtime ones).

You can run http://www.dependencywalker.com/ on the generated exe and
see which DLLs it uses. If you do it on the machine with the
problems, these DLLs will be highlighted.


Another possibility is that py2exe is erroneously picking up *other* 
DLLs from the OS, which you are packaging and installing.  So check your 
distribution for *all* .dll files - most Python extension modules are 
.pyd, so the actual number of .dll files needed should be quite small 
and relatively stable across different py2exe invocations.


Mark


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


Re: exe made by py2exe do not run certain computer

2012-07-03 Thread Miki Tebeka
> It works fine on my computer and some other computer don't have python 
> interpreter(it's Windows 7).
> But the same file also do not work on another computer(it's Windows xp)
> why does it happen?
My *guess* is that you're missing some DLLs (probably some Visual Studio 
runtime ones).

You can run http://www.dependencywalker.com/ on the generated exe and see which 
DLLs it uses. If you do it on the machine with the problems, these DLLs will be 
highlighted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 5:06 PM, Ian Kelly  wrote:
> On Tue, Jul 3, 2012 at 4:38 PM, Dan Stromberg  wrote:
>>> Right now this all seems highly speculative to me.  I think it might
>>> be informative, either to you or to me, to do an actual timing test.
>>> Why don't you try setting up two side-by-side installations of Python,
>>> one with all the site-packages cruft, and one trimmed down to only
>>> what you think should be in there, and see if you can measure a real
>>> difference in startup time?
>>
>> In the original stackoverflow thread I mentioned, there's a speed
>> comparison.
>
> That's just comparing using -S against not using -S, though.  As I
> understand it, you don't want to use -S; you still want to import site
> but just want to pare down your site-packages for a speedup.

I ran a quick test where I copied my Python 2.5 installation on
Windows and cleared out the site-packages folder and ran the test from
the stackoverflow thread.

With crufty site-packages: 0.18s
With empty site-packages: 0.16s
With -S (either installation): 0.10s

So there does appear to be some improvement, but only a fraction of
what I get by using -S.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictless classes

2012-07-03 Thread Terry Reedy

On 7/3/2012 1:03 AM, Steven D'Aprano wrote:

You can create instances without a __dict__ by setting __slots__:


Each *instance* does not have its own dict because each would be equal, 
therefore only one hidden mapping is needed, somewhere. But attribute 
names must be mapped to objects somehow.



I wonder whether there is some metaclass magic one can do to create a
class without a __dict__?


If every 'class' instance of the metaclass has the same attributes, then 
it would not be necessary for each 'class' to have its individual dict. 
But would you call such things 'classes'?


> I don't have a use-case for this. But I have some code which assumes
> that every class will have a __dict__, and I wonder whether that is a
> safe assumption.

It depends what you mean by a class. A 'metaclass' is just a callable 
that accepts 3 args. The only constraint appears that its return must be 
callable (and accept at least one arg).


class M():
__slots__ = ()
def __init__(*args): pass
def __call__(*args): pass

class C(metaclass = M): pass

c=C()
print(type(C), C, c, hasattr(C, '__dict__'))

#
 <__main__.M object at 0x0220A1C0> None False

Is C a dictless class? Your choice ;-).

Actually, Python thinks not. If we add
class Mclassob(object): pass
and have __call__ return an instance thereof and try
c.__class__ = C
we get
TypeError: __class__ must be set to a class, not 'M' object

--
Terry Jan Reedy



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


Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 4:38 PM, Dan Stromberg  wrote:
>> Right now this all seems highly speculative to me.  I think it might
>> be informative, either to you or to me, to do an actual timing test.
>> Why don't you try setting up two side-by-side installations of Python,
>> one with all the site-packages cruft, and one trimmed down to only
>> what you think should be in there, and see if you can measure a real
>> difference in startup time?
>
> In the original stackoverflow thread I mentioned, there's a speed
> comparison.

That's just comparing using -S against not using -S, though.  As I
understand it, you don't want to use -S; you still want to import site
but just want to pare down your site-packages for a speedup.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why site-packages?

2012-07-03 Thread Dan Stromberg
On Tue, Jul 3, 2012 at 10:04 PM, Ian Kelly  wrote:

>
> >> The site module has to process any .pth files in the site-packages,
> >> but apart from that, I think the actual amount of stuff in
> >> site-packages should be irrelevant.
> >
> > Irrelevant to what?   More stuff in site slowing things down?  Are .pth's
> > not correlated with more stuff in site-packages?  Aren't they actually a
> > thing In site?
>
> Yes, but I just don't expect the .pth files to grow that fast.  I've
> got something like 30 packages in my site-packages and only 6 .pth
> files, and most of those are one-liners.
>
It's not the Lines of Code, it's the track to track seeks.


> Right now this all seems highly speculative to me.  I think it might
> be informative, either to you or to me, to do an actual timing test.
> Why don't you try setting up two side-by-side installations of Python,
> one with all the site-packages cruft, and one trimmed down to only
> what you think should be in there, and see if you can measure a real
> difference in startup time?
>
In the original stackoverflow thread I mentioned, there's a speed
comparison.

It's possible they were seeing a cache effect, though it didn't really
sound like it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 3:34 PM, Dan Stromberg  wrote:
> If it was intended to be reusable code, I'd think it -should- go in
> site-packages.
>
> But so much code in site-packages isn't intended to be reusable.

Can you give some examples?  Looking through my site-packages
directory, everything in there is either used by multiple applications
or at least has the potential to be.  Frankly, if you've installed a
third-party package and written your own code against it, even if only
in one little script, isn't that already reuse?

> And even for stuff that's reusable, there are advantages to just duplicating
> them for the purposes of each application, because you never know when one
> of them is going to need a different version from another.

Definitely a situation for virtualenv, IMO.

>> The site module has to process any .pth files in the site-packages,
>> but apart from that, I think the actual amount of stuff in
>> site-packages should be irrelevant.
>
> Irrelevant to what?   More stuff in site slowing things down?  Are .pth's
> not correlated with more stuff in site-packages?  Aren't they actually a
> thing In site?

Yes, but I just don't expect the .pth files to grow that fast.  I've
got something like 30 packages in my site-packages and only 6 .pth
files, and most of those are one-liners.

Right now this all seems highly speculative to me.  I think it might
be informative, either to you or to me, to do an actual timing test.
Why don't you try setting up two side-by-side installations of Python,
one with all the site-packages cruft, and one trimmed down to only
what you think should be in there, and see if you can measure a real
difference in startup time?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why site-packages?

2012-07-03 Thread Thomas Jollans
On 07/03/2012 11:34 PM, Dan Stromberg wrote:
> On Tue, Jul 3, 2012 at 9:04 PM, Ian Kelly  > wrote:
> 
> On Tue, Jul 3, 2012 at 2:40 PM, Dan Stromberg  > wrote:
> >
> > Why is it that so much 3rd party python code gets installed to
> > site-packages?
> 
> Because that's what site-packages is for?
> 
> 
> Agh.  But -why- is it because that's what it's for?
> 
> "Who made this rule"?

It's (reasonably) consistent with the way things are usually done on UNIX.

Libraries go in /usr/lib. That's all libraries, not just core system
libraries.

Similarly, Python modules go in /usr/lib/python. That's all Python
modules, not just the standard library. That means that you can use them
in scripts without faffing around because the interpreter will find
them, even if you're in a completely random directory.

The point of site-packages then is to make sure that user-installed
packages are cleanly separated from standard and distribution-installed
packages, similarly to the way /usr/local/ is used in general (and can
be used for Python packages, of course)

>  
> 
> > Even for things that are almost certainly going to be used by a single
> > application?
> >
> > Even for things you might only use once?
> >
> > Even for things that might require one version for one app, and
> another
> > version for another app?
> 
> For these types of uses, I suggest using virtualenv if you don't want
> to pollute your site-packages.  Or Python 3.3 with the new built-in
> virtual environment option.
> 
> Virtualenv is worth thinking about, but it kind of does the same thing,
> just less of it.
>  
> 
> > Why not stash an application's python modules in
> /usr/local/lib/[appname],
> > and stash a little frontend in /usr/local/bin that adds
> > /usr/local/lib/[appname] to sys.path?
> 
> What if you then write an application that you find needs two of these
> libraries?  You write yet another frontend that adds both of them to
> sys.path?
> 
> If it was intended to be reusable code, I'd think it -should- go in
> site-packages.
> 
> But so much code in site-packages isn't intended to be reusable.
> 
> And even for stuff that's reusable, there are advantages to just
> duplicating them for the purposes of each application, because you never
> know when one of them is going to need a different version from another.
> 
> If we weren't stashing so much stuff in site-packages, there probably
> wouldn't have been a desire for something like virtualenv.
>  
> 
> > Here's a thread on stackoverflow today asking why python starts up so
> > slowly, and making it clear that this is because so much stuff
> ends up in
> > site-packages:
> >
> 
> http://stackoverflow.com/questions/11318028/is-it-safe-to-use-pythons-s-option
> 
> I think you may be misunderstanding that thread.  They're saying that
> starting Python with the -S option (i.e. not automatically importing
> the site module) significantly cuts down on Python's startup time.
> 
> Yes...
>  
> 
> The site module has to process any .pth files in the site-packages,
> but apart from that, I think the actual amount of stuff in
> site-packages should be irrelevant.
> 
> Irrelevant to what?   More stuff in site slowing things down?  Are
> .pth's not correlated with more stuff in site-packages?  Aren't they
> actually a thing In site?
>  
> 
>  Nothing in site-packages is
> actually imported or otherwise processed until the application
> requests it.
> 
> Other than .pth's, apparently.
>  
> 
>  You could have a completely empty site-packages, or you
> could have 20 gigs of third-party packages, and the time to import
> site would be basically the same.
> 
> Well, I'd guess that a large directory would slow things down before
> causing filesystem complaints, but I see your point.
> 
> 
> 


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


Re: code review

2012-07-03 Thread Chris Angelico
On Wed, Jul 4, 2012 at 6:13 AM, Dave Angel  wrote:
> On 07/03/2012 12:05 PM, Mark Lawrence wrote:
>> If I go to the moon I will weigh 2st 10lb (if my sums are correct :)
>> but the equivalent Frenchman will still be 86kg. I hereby put this
>> forward as proof that the metric system is rubbish and we should
>> revert back to imperial goodies.
>>
>
> 86 kg is not a weight, it's a mass.  So it doesn't depend on the local
> gravity situation.

Indeed it is, as he says. But I believe he may be right in that
'stone' is a unit of weight. Hard to be sure, though, given that it's
not an SI unit (for instance, the Wikipedia article text refers to
weight, but its picture shows a man measuring mass).

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


Re: code review

2012-07-03 Thread Chris Angelico
On Wed, Jul 4, 2012 at 4:27 AM, Ian Kelly  wrote:
> On Tue, Jul 3, 2012 at 12:18 PM, John Gordon  wrote:
>> As a practical matter, doesn't there have to be *some* sort of limit?
>> For example if the (encrypted) password is stored in a database, you can't
>> exceed the table column width.
>
> Hopefully you're storing password hashes, not encrypted passwords
> (which can all too easily be DEcrypted), and the length of the hash is
> not dependent on the length of the password.  But yes, there are
> certainly practical concerns here.

With a hash length of N bits, there's not much use accepting passwords
longer than about N/4 or N/2 bytes. (It would be N/8 except that most
people don't invent passwords that use the entire available alphabet.
And of course, this ignores issues of encodings, but I'm pretty sure
all current crypto hashes work with bytes not characters anyway.) But
please, don't limit password lengths too much. Make your password
system XKCD 936 compliant:

http://xkcd.com/936/

Permit long passwords consisting of nothing but lowercase letters.
They really aren't as insecure as some people think!

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


Re: Why site-packages?

2012-07-03 Thread Dan Stromberg
On Tue, Jul 3, 2012 at 9:04 PM, Ian Kelly  wrote:

> On Tue, Jul 3, 2012 at 2:40 PM, Dan Stromberg  wrote:
> >
> > Why is it that so much 3rd party python code gets installed to
> > site-packages?
>
> Because that's what site-packages is for?
>

Agh.  But -why- is it because that's what it's for?

"Who made this rule"?


> > Even for things that are almost certainly going to be used by a single
> > application?
> >
> > Even for things you might only use once?
> >
> > Even for things that might require one version for one app, and another
> > version for another app?
>
> For these types of uses, I suggest using virtualenv if you don't want
> to pollute your site-packages.  Or Python 3.3 with the new built-in
> virtual environment option.
>
Virtualenv is worth thinking about, but it kind of does the same thing,
just less of it.


> > Why not stash an application's python modules in
> /usr/local/lib/[appname],
> > and stash a little frontend in /usr/local/bin that adds
> > /usr/local/lib/[appname] to sys.path?
>
> What if you then write an application that you find needs two of these
> libraries?  You write yet another frontend that adds both of them to
> sys.path?
>
If it was intended to be reusable code, I'd think it -should- go in
site-packages.

But so much code in site-packages isn't intended to be reusable.

And even for stuff that's reusable, there are advantages to just
duplicating them for the purposes of each application, because you never
know when one of them is going to need a different version from another.

If we weren't stashing so much stuff in site-packages, there probably
wouldn't have been a desire for something like virtualenv.


> > Here's a thread on stackoverflow today asking why python starts up so
> > slowly, and making it clear that this is because so much stuff ends up in
> > site-packages:
> >
> http://stackoverflow.com/questions/11318028/is-it-safe-to-use-pythons-s-option
>
> I think you may be misunderstanding that thread.  They're saying that
> starting Python with the -S option (i.e. not automatically importing
> the site module) significantly cuts down on Python's startup time.
>
Yes...


> The site module has to process any .pth files in the site-packages,
> but apart from that, I think the actual amount of stuff in
> site-packages should be irrelevant.

Irrelevant to what?   More stuff in site slowing things down?  Are .pth's
not correlated with more stuff in site-packages?  Aren't they actually a
thing In site?


>  Nothing in site-packages is
> actually imported or otherwise processed until the application
> requests it.

Other than .pth's, apparently.


>  You could have a completely empty site-packages, or you
> could have 20 gigs of third-party packages, and the time to import
> site would be basically the same.
>
Well, I'd guess that a large directory would slow things down before
causing filesystem complaints, but I see your point.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why site-packages?

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 2:40 PM, Dan Stromberg  wrote:
>
> Why is it that so much 3rd party python code gets installed to
> site-packages?

Because that's what site-packages is for?

> Even for things that are almost certainly going to be used by a single
> application?
>
> Even for things you might only use once?
>
> Even for things that might require one version for one app, and another
> version for another app?

For these types of uses, I suggest using virtualenv if you don't want
to pollute your site-packages.  Or Python 3.3 with the new built-in
virtual environment option.

> Why not stash an application's python modules in /usr/local/lib/[appname],
> and stash a little frontend in /usr/local/bin that adds
> /usr/local/lib/[appname] to sys.path?

What if you then write an application that you find needs two of these
libraries?  You write yet another frontend that adds both of them to
sys.path?

> Here's a thread on stackoverflow today asking why python starts up so
> slowly, and making it clear that this is because so much stuff ends up in
> site-packages:
> http://stackoverflow.com/questions/11318028/is-it-safe-to-use-pythons-s-option

I think you may be misunderstanding that thread.  They're saying that
starting Python with the -S option (i.e. not automatically importing
the site module) significantly cuts down on Python's startup time.
The site module has to process any .pth files in the site-packages,
but apart from that, I think the actual amount of stuff in
site-packages should be irrelevant.  Nothing in site-packages is
actually imported or otherwise processed until the application
requests it.  You could have a completely empty site-packages, or you
could have 20 gigs of third-party packages, and the time to import
site would be basically the same.
-- 
http://mail.python.org/mailman/listinfo/python-list


Why site-packages?

2012-07-03 Thread Dan Stromberg
Why is it that so much 3rd party python code gets installed to
site-packages?

Even for things that are almost certainly going to be used by a single
application?

Even for things you might only use once?

Even for things that might require one version for one app, and another
version for another app?

Why not stash an application's python modules in /usr/local/lib/[appname],
and stash a little frontend in /usr/local/bin that adds
/usr/local/lib/[appname] to sys.path?

Here's a thread on stackoverflow today asking why python starts up so
slowly, and making it clear that this is because so much stuff ends up in
site-packages:
http://stackoverflow.com/questions/11318028/is-it-safe-to-use-pythons-s-option

The response "Because that's where things are supposed to go" makes me ask
"Who made this decision and why?"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread Dave Angel
On 07/03/2012 12:05 PM, Mark Lawrence wrote:
> On 03/07/2012 16:53, Chris Angelico wrote:
>> On Wed, Jul 4, 2012 at 1:50 AM, Mark Lawrence
>>  wrote:
>>> On 03/07/2012 03:25, John O'Hagan wrote:

 On Tue, 3 Jul 2012 11:22:55 +1000

 I agree to some extent, but as a counter-example, when I was a
 child there
 a subject called "Weights and Measures" which is now redundant
 because of
 the
 Metric system. I don't miss hogsheads and fathoms at all.

 John

>>>
>>> I weigh 13st 8lb - does this make me redundant?
>>
>> Yes, because somewhere in the world is someone who weighs (... pulls
>> out calculator...) 86kg. After all, the French had a bloody revolution
>> to get us a new system without any of the old baggage. We don't want
>> to disappoint the French now, do we!
>>
>> ChrisA
>> lemme just dislodge my tongue from my cheek, it seems to be stuck...
>>
>
> If I go to the moon I will weigh 2st 10lb (if my sums are correct :)
> but the equivalent Frenchman will still be 86kg. I hereby put this
> forward as proof that the metric system is rubbish and we should
> revert back to imperial goodies.
>

86 kg is not a weight, it's a mass.  So it doesn't depend on the local
gravity situation.

DaveA


-- 

DaveA

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


Re: code review

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 12:18 PM, John Gordon  wrote:
> In  Kushal Kumaran 
>  writes:
>
>> I haven't actually seen the rest of the code, but I would like to
>> point out that applications placing maximum length limits on passwords
>> are extremely annoying.
>
> As a practical matter, doesn't there have to be *some* sort of limit?
> For example if the (encrypted) password is stored in a database, you can't
> exceed the table column width.

Hopefully you're storing password hashes, not encrypted passwords
(which can all too easily be DEcrypted), and the length of the hash is
not dependent on the length of the password.  But yes, there are
certainly practical concerns here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread John Gordon
In  Kushal Kumaran 
 writes:

> I haven't actually seen the rest of the code, but I would like to
> point out that applications placing maximum length limits on passwords
> are extremely annoying.

As a practical matter, doesn't there have to be *some* sort of limit?
For example if the (encrypted) password is stored in a database, you can't
exceed the table column width.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: code review

2012-07-03 Thread Ian Kelly
On Tue, Jul 3, 2012 at 11:53 AM, Kushal Kumaran
 wrote:
> On Sat, Jun 30, 2012 at 3:34 PM, Alister  wrote:
>> On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote:
>>
>>> On 6/29/2012 1:31 AM, Steven D'Aprano wrote:
 On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote:

> On Jun 29, 12:57 pm, "Littlefield, Tyler"  wrote:
>> I was curious if someone wouldn't mind poking at some code. The
>> project page is at:http://code.google.com/p/pymud Any information is
>> greatly appreciated.
> I couldn't find any actual code at that site, the git repository is
> currently empty.
>>>
>>> OOPS, sorry. Apparently I'm not as good with git as I thought.
>>> Everything's in the repo now.
>>
>> I think I may be on firmer grounds with the next few:
>>
>> isValidPassword can be simplified to
>>
>> def isValidPassword(password:
>> count=len(password)
>> return count>= mud.minpass and count<= mud.maxpass
>>
>
> I haven't actually seen the rest of the code, but I would like to
> point out that applications placing maximum length limits on passwords
> are extremely annoying.

They're annoying when the maximum length is unreasonably small, but
you have to have a maximum length to close off one DoS attack vector.
Without a limit, if a "user" presents a 1 GB password, then guess
what?  Your system has to hash that GB of data before it can reject
it.  And if you're serious about security then it will be a
cryptographic hash, and that means slow.

To prevent that, the system needs to reject outright password attempts
that are longer than some predetermined reasonable length, and if the
system won't authenticate those passwords, then it can't allow the
user to set them either.

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


Re: code review

2012-07-03 Thread Kushal Kumaran
On Sat, Jun 30, 2012 at 3:34 PM, Alister  wrote:
> On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote:
>
>> On 6/29/2012 1:31 AM, Steven D'Aprano wrote:
>>> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote:
>>>
 On Jun 29, 12:57 pm, "Littlefield, Tyler"  wrote:
> I was curious if someone wouldn't mind poking at some code. The
> project page is at:http://code.google.com/p/pymud Any information is
> greatly appreciated.
 I couldn't find any actual code at that site, the git repository is
 currently empty.
>>
>> OOPS, sorry. Apparently I'm not as good with git as I thought.
>> Everything's in the repo now.
>
> I think I may be on firmer grounds with the next few:
>
> isValidPassword can be simplified to
>
> def isValidPassword(password:
> count=len(password)
> return count>= mud.minpass and count<= mud.maxpass
>

I haven't actually seen the rest of the code, but I would like to
point out that applications placing maximum length limits on passwords
are extremely annoying.

> 

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best data structure for DFS on large graphs

2012-07-03 Thread Dan Stromberg
On Tue, Jul 3, 2012 at 3:08 PM, Miheer Dewaskar wrote:

> On Tue, Jul 3, 2012 at 8:10 PM, Tim Chase 
> wrote:
> I want it to be a generic Game solver.So the number of states depends
> on the game.
>

Keep in mind that it would probably be a generic game solver for games that
have simple board evaluation functions.  For something like Go, despite its
simple rules, much more is required.


> For a simple tic-tac-toe the upper bound is 3^9 states.But for more
> complex games it could be much larger.
> I would like to assume that the number of states can grow arbitrarily
> large.
>
> For example in the tic-tac-toe game the states can be a 3x3 box of integers
>
>  0 -> unoccupied
>  1 -> x
>  2-> o
>
> (  (2,0,1), o   -   x
>(1,1,0), -> x  x   -
>(2,0,0) )o  --
>

For just saving game board states to avoid re-traversal, I'd think a set
(if you require no ancillary information) or dict (if you do) would be
appropriate.  But perhaps consider Zobrist hashing:
http://en.wikipedia.org/wiki/Zobrist_hashing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread Mark Lawrence

On 03/07/2012 16:53, Chris Angelico wrote:

On Wed, Jul 4, 2012 at 1:50 AM, Mark Lawrence  wrote:

On 03/07/2012 03:25, John O'Hagan wrote:


On Tue, 3 Jul 2012 11:22:55 +1000

I agree to some extent, but as a counter-example, when I was a child there
a subject called "Weights and Measures" which is now redundant because of
the
Metric system. I don't miss hogsheads and fathoms at all.

John



I weigh 13st 8lb - does this make me redundant?


Yes, because somewhere in the world is someone who weighs (... pulls
out calculator...) 86kg. After all, the French had a bloody revolution
to get us a new system without any of the old baggage. We don't want
to disappoint the French now, do we!

ChrisA
lemme just dislodge my tongue from my cheek, it seems to be stuck...



If I go to the moon I will weigh 2st 10lb (if my sums are correct :) but 
the equivalent Frenchman will still be 86kg. I hereby put this forward 
as proof that the metric system is rubbish and we should revert back to 
imperial goodies.


--
Cheers.

Mark Lawrence.



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


Re: code review

2012-07-03 Thread Mark Lawrence

On 03/07/2012 07:09, Dennis Lee Bieber wrote:

On 03 Jul 2012 04:11:22 GMT, Steven D'Aprano
 declaimed the following in
gmane.comp.python.general:



One of my favourites is the league, which in the Middle Ages was actually
defined as the distance that a man, or a horse, could walk in an hour.


From the "Explanatory Supplement to the Astronomical Almanac" [1992
University Science Books], Table 15.15, the speed of light is

1.80261750E12 furlongs/fortnight



+1 most useless piece of information garnered this week.

--
Cheers.

Mark Lawrence.



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


Re: code review

2012-07-03 Thread Chris Angelico
On Wed, Jul 4, 2012 at 1:50 AM, Mark Lawrence  wrote:
> On 03/07/2012 03:25, John O'Hagan wrote:
>>
>> On Tue, 3 Jul 2012 11:22:55 +1000
>>
>> I agree to some extent, but as a counter-example, when I was a child there
>> a subject called "Weights and Measures" which is now redundant because of
>> the
>> Metric system. I don't miss hogsheads and fathoms at all.
>>
>> John
>>
>
> I weigh 13st 8lb - does this make me redundant?

Yes, because somewhere in the world is someone who weighs (... pulls
out calculator...) 86kg. After all, the French had a bloody revolution
to get us a new system without any of the old baggage. We don't want
to disappoint the French now, do we!

ChrisA
lemme just dislodge my tongue from my cheek, it seems to be stuck...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread Mark Lawrence

On 03/07/2012 03:25, John O'Hagan wrote:

On Tue, 3 Jul 2012 11:22:55 +1000

I agree to some extent, but as a counter-example, when I was a child there
a subject called "Weights and Measures" which is now redundant because of the
Metric system. I don't miss hogsheads and fathoms at all.

John



I weigh 13st 8lb - does this make me redundant?

--
Cheers.

Mark Lawrence.



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


Re: Best data structure for DFS on large graphs

2012-07-03 Thread Miheer Dewaskar
On Tue, Jul 3, 2012 at 8:10 PM, Tim Chase  wrote:
> On 07/03/12 08:39, Miheer Dewaskar wrote:
>> On Tue, Jul 3, 2012 at 4:53 PM, Stefan Behnel  wrote:
>>>
>>> Miheer Dewaskar, 03.07.2012 13:11:
 I am not sure,but if there are large number of states Dictionaries wont
 help much right?
>>>
>>> Dicts are fast for lookup, not for searching.
>>>
>> What do you mean by searching in the context of Dicts?
>
> It took me a while to parse Stefan's post, and I *think* he means
> that key-indexing (direct lookup) is fast O(1), and that by
> "searching" he means something like "find all keys/values matching
> property $FOO" such as between a range.
>
> One of the important things you omit is how you define "large".  Is
> this a couple thousand?  Hundreds of thousands?  Millions?

I want it to be a generic Game solver.So the number of states depends
on the game.
For a simple tic-tac-toe the upper bound is 3^9 states.But for more
complex games it could be much larger.
I would like to assume that the number of states can grow arbitrarily large.

> Also, what sort of information are you keeping in the state?  Just
> available transitions?  Or do you want additional metadata?  If it's
> just transition mappings (A->B) rather than complex objects, I'd try
> using a dict first, and if it's too large, I'd reach for the
> "anydbm" module to store them to disk.

The state just has 'state data'.The transitions are obtained by
functions analyzing the state.
So that I should not be able to identify between two same states that
have been reached by different means.

For example in the tic-tac-toe game the states can be a 3x3 box of integers

 0 -> unoccupied
 1 -> x
 2-> o

(  (2,0,1), o   -   x
   (1,1,0), -> x  x   -
   (2,0,0) )o  --



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


Re: Best data structure for DFS on large graphs

2012-07-03 Thread Tim Chase
On 07/03/12 08:39, Miheer Dewaskar wrote:
> On Tue, Jul 3, 2012 at 4:53 PM, Stefan Behnel  wrote:
>>
>> Miheer Dewaskar, 03.07.2012 13:11:
>>> I am not sure,but if there are large number of states Dictionaries wont
>>> help much right?
>>
>> Dicts are fast for lookup, not for searching.
>>
> What do you mean by searching in the context of Dicts?

It took me a while to parse Stefan's post, and I *think* he means
that key-indexing (direct lookup) is fast O(1), and that by
"searching" he means something like "find all keys/values matching
property $FOO" such as between a range.

One of the important things you omit is how you define "large".  Is
this a couple thousand?  Hundreds of thousands?  Millions?

Also, what sort of information are you keeping in the state?  Just
available transitions?  Or do you want additional metadata?  If it's
just transition mappings (A->B) rather than complex objects, I'd try
using a dict first, and if it's too large, I'd reach for the
"anydbm" module to store them to disk.

-tkc



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


Re: code review

2012-07-03 Thread John O'Hagan
On Mon, 2 Jul 2012 22:10:00 -0700 (PDT)
rusi  wrote:

> On Jul 3, 7:25 am, John O'Hagan  wrote:
> >
> > I agree to some extent, but as a counter-example, when I was a child there
> > a subject called "Weights and Measures" which is now redundant because of
> > the Metric system. I don't miss hogsheads and fathoms at all.
> >
> > Music is another field which could do with a "metrification": I get tired of
> > explaining to beginners why there's no B#, except when it's C. Check
> > outhttp://musicnotation.org
> 
> You assume that equal temperament is the only way to have music.
> Apart from the fact that there are non-tempered musics all over the
> world, even Bach Mozart and Beethoven did not write for/to equal
> temperament. In a pure/untempered C-scale A-flat is almost half a
> semitone sharper than G-sharp -- 8/5 vs 25/16.
> 
[...]

I don't assume that at all :) If you didn't already, have look at the
link.  I was talking about notation of the normal everyday contemporary
tempered system where there is no pitch difference between Ab and G#. But even
in a just system, any difference between them depends on the system itself,
the key, and whether you choose to call them that. I've never heard anyone claim
that C is sharper than B#, although in the key of E the relationship would be
the same. 

AIUI there is any number of whole number ratios which fall between seven and
nine tempered semitones above the fundamental (to take your example), and in
C, any one of them could be called either Ab or G# depending on the key
signature or other context. IMHO, that's the aspect that could benefit from a
simplified representation.

To the OP, I'm deeply sorry!

--

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


Re: Best data structure for DFS on large graphs

2012-07-03 Thread Miheer Dewaskar
On Tue, Jul 3, 2012 at 4:53 PM, Stefan Behnel  wrote:
>
> Miheer Dewaskar, 03.07.2012 13:11:
> > I am not sure,but if there are large number of states Dictionaries wont
> > help much right?
>
> Dicts are fast for lookup, not for searching.
>
What do you mean by searching in the context of Dicts?

> > Anyway, does python have a built-in BST like data-structure ?
>
> It has lists and bisect:
>
> http://docs.python.org/library/bisect.html

But insertion and deletion in a list is o(n):

http://wiki.python.org/moin/TimeComplexity/#list




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


Re: How can i do python form post request?

2012-07-03 Thread Thomas Jollans
On 07/03/2012 02:32 PM, gmspro wrote:
> @Thomas,
> 
>>First, you need to tell the web server to execute your Python script.
> What you do next depends on how you've done that.
> 
>>The simplest way is probably to pub p.py in your cgi-bin directory. This
> could be in /var/www/cgi-bin or elsewhere, like /usr/lib/cgi-bin. You
> may need to enable CGI, check the relevant documentation (or with the
> admin).
> 
>>When you've made sure the script is executed as a CGI script, you can
> use the cgi module to get all the information you need.
> http://docs.python.org/library/cgi.html
> 
>>A better way to write web applications in Python is with WSGI. You can
> run WSGI scripts in a number of ways, including CGI and other, more
> efficient ways that integrate with the web server. Maybe somebody else
> knows of a good tutorial on WSGI that they'll link here, otherwise, I'm
> sure Google is your friend.
> 
> I don't want to use CGI, i followed this example, this works fine,
> http://webpython.codepoint.net/wsgi_request_parsing_post
> 
> But the html is embeded there. But i want html form as a seperate file.
> How can i do it?

That makes absolutely no difference. Have you been able to run that
example script? They're using wsgi.simple_server, of course, but you
could start by removing that part and configuring mod_wsgi to run your
WSGI script. http://ubuntuforums.org/showthread.php?t=833766 could be
helpful, search the web for howtos on mod_wsgi to get started.

Once you have your web server running the WSGI code, the rest should be
trivial.

> 
> form.html:
> 
>  
>  
> 
> 
> Typing text when i click the submit button, browser prompts me to
> download the p.py file.
> That's not what i want. I want to execute the p.py file after click. Is
> it possible in WSGI.
> 
> I have installed: libapache2-mod-wsgi
> 
> Any answer will be highly appreciate.
> Thanks in advanced.
> 
> 
> 
> 


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


Re: WxSlider Mouse Wheel Resolution

2012-07-03 Thread Wanderer
On Monday, July 2, 2012 6:53:36 PM UTC-4, Dennis Lee Bieber wrote:
> On Mon, 2 Jul 2012 08:45:49 -0700 (PDT), Wanderer
>  declaimed the following in
> gmane.comp.python.general:
> 
> > Is there a way to set the mouse wheel resolution for the wxPython
> > wx.Slider? I would like to use the graphic slider for coarse control
> > and the mouse wheel for fine control. Right now the mouse wheel makes
> > the slider jump ten counts and I would like it to be a single count.
> >
>   Isn't that a condition of the OS Mouse driver?
> 
>   My LogiTech driver (WinXP) has "scroller: 1, 3, 6 lines"
> 
> -- 
>   Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

Maybe there are some system settings but I believe they can be overridden by 
the application. Check out the Firefox options for the mouse wheel.

http://www.pcworld.com/article/163639/change_the_speed_of_mousewheel_scrolling_in_firefox.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> On 03 Jul 2012 04:11:22 GMT, Steven D'Aprano
>  declaimed the following in
> gmane.comp.python.general:
> 
> 
> > One of my favourites is the league, which in the Middle Ages was actually 
> > defined as the distance that a man, or a horse, could walk in an hour.
> 
>   From the "Explanatory Supplement to the Astronomical Almanac" [1992
> University Science Books], Table 15.15, the speed of light is
> 
>   1.80261750E12 furlongs/fortnight

And sure enough, that's what units says:

$ units
500 units, 54 prefixes
You have: c
You want: furlongs/fortnight
   * 1.8026175e+12
   / 5.5474886e-13
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i do python form post request?

2012-07-03 Thread gmspro
@Thomas,

>First, you need to tell the web server to execute your Python script.
What you do next depends on how you've done that.

>The simplest way is probably to pub p.py in your cgi-bin directory. This
could be in /var/www/cgi-bin or elsewhere, like /usr/lib/cgi-bin. You
may need to enable CGI, check the relevant documentation (or with the
admin).

>When you've made sure the script is executed as a CGI script, you can
use the cgi module to get all the information you need.
http://docs.python.org/library/cgi.html

>A better way to write web applications in Python is with WSGI. You can
run WSGI scripts in a number of ways, including CGI and other, more
efficient ways that integrate with the web server. Maybe somebody else
knows of a good tutorial on WSGI that they'll link here, otherwise, I'm
sure Google is your friend.

I don't want to use CGI, i followed this example, this works fine, 
http://webpython.codepoint.net/wsgi_request_parsing_post

But the html is embeded there. But i want html form as a seperate file. How can 
i do it?
form.html:

 
 


Typing text when i click the submit button, browser prompts me to download the 
p.py file.
That's not what i want. I want to execute the p.py file after click. Is it 
possible in WSGI.

I have installed: libapache2-mod-wsgi

Any answer will be highly appreciate.
Thanks in advanced.

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


Re: Dictless classes

2012-07-03 Thread Roy Smith
In article ,
 Duncan Booth  wrote:

> Also you cannot create a subclass of 'type' with non-empty slots (it throws 
> a type error "nonempty __slots__ not supported for subtype of 'type'"). 
> However I don't think that's really relevant as even if they did allow you 
> to use __slots__ it wouldn't prevent the creation of a __dict__ for the 
> 'type' base class.

I played around a bit trying to write a metaclass which implemented:

def __getattribute__(self, name):
   if name == "__dict__":
  raise AttributeError

but didn't get very far.  Maybe somebody with stronger metaclass-fu than 
I have could run with this idea?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code review

2012-07-03 Thread Neil Cerutti
On 2012-07-02, Chris Angelico  wrote:
> On Tue, Jul 3, 2012 at 1:57 AM, Rick Johnson
> wrote:
>> Poor Chris. That's because you've been brainwashed into believing you
>> must spoon feed your interpreter to get your code working correctly.
>> Stop applying these naive assumptions to Python code. Python knows
>> when you reach the end of a statement, no need for redundant
>> semicolons! Python knows when its reached the end of block and needs
>> to drop back one level, no need for redundant road signs.  Python
>> knows Chris; Python KNOWS!
>
> Why "poor", Ralph?
>
> I am poor in the essence of ignorance's bliss, rich only in the
> never-ending thirst for knowledge and more languages. In me there meet
> a combination of antithetical elements which are at eternal war with
> one another... I hope I make myself clear, lady?

His simple eloquence goes to my very heart!

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


Re: Best data structure for DFS on large graphs

2012-07-03 Thread Stefan Behnel
Miheer Dewaskar, 03.07.2012 13:11:
> I want to make a combinatorial game solver in python.The algorithm is to
> perform Depth First Search (DFS) on the states of the game.
> For DFS I,would need to keep a record of the visited states.What is the
> best data structure for it,keeping in mind that the number of states could
> be large?
> 
> I was thinking about using Dictionary or a Binary Search Tree (BST)
> ,assuming that the states can be made hashable and totally ordered
> respectively.
> I am not sure,but if there are large number of states Dictionaries wont
> help much right?

Dicts are fast for lookup, not for searching.


> Anyway, does python have a built-in BST like data-structure ?

It has lists and bisect:

http://docs.python.org/library/bisect.html

Stefan

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


Best data structure for DFS on large graphs

2012-07-03 Thread Miheer Dewaskar
I want to make a combinatorial game solver in python.The algorithm is to
perform Depth First Search (DFS) on the states of the game.
For DFS I,would need to keep a record of the visited states.What is the
best data structure for it,keeping in mind that the number of states could
be large?

I was thinking about using Dictionary or a Binary Search Tree (BST)
,assuming that the states can be made hashable and totally ordered
respectively.
I am not sure,but if there are large number of states Dictionaries wont
help much right?

Anyway, does python have a built-in BST like data-structure ?

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


Re: Dictless classes

2012-07-03 Thread Duncan Booth
Steven D'Aprano  wrote:

> You can create instances without a __dict__ by setting __slots__:

That is a necessary but not a sufficient condition. An instance of a class 
can be created without a dict only if (either you set __slots__ or you 
implement it in C without a __dict__ attribute) AND none of its base 
classes require a dict.

Setting __slots__ when a base class requires that its instances have a 
__dict__ doesn't prevent creation of the __dict__.

> 
> But the class itself still has a __dict__:

The class is an instance of 'type'. Instances of 'type' require a dict 
therefore every class requires a dict. Except of course for old style 
classes in Python 2.x but they have a __dict__ too.

Also you cannot create a subclass of 'type' with non-empty slots (it throws 
a type error "nonempty __slots__ not supported for subtype of 'type'"). 
However I don't think that's really relevant as even if they did allow you 
to use __slots__ it wouldn't prevent the creation of a __dict__ for the 
'type' base class.

> I don't have a use-case for this. But I have some code which assumes
> that every class will have a __dict__, and I wonder whether that is a
> safe assumption.

I believe so.

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


Re: How can i do python form post request?

2012-07-03 Thread Thomas Jollans
On 07/03/2012 07:08 AM, gmspro wrote:
> 
> form.html:
> 
>  
>  
> 
> 
> p.py:
> #!/usr/bin/python
> 
> #what to write here...
> 
> Both files are put in /var/www/ , now from http://localhost/form.html,
> if i click the submit button would i execute the p.py  and how can i get
> the value of textbox?
> 
> Any answer will be highly appreciated.
> Thanks in advanced.

First, you need to tell the web server to execute your Python script.
What you do next depends on how you've done that.

The simplest way is probably to pub p.py in your cgi-bin directory. This
could be in /var/www/cgi-bin or elsewhere, like /usr/lib/cgi-bin. You
may need to enable CGI, check the relevant documentation (or with the
admin).

When you've made sure the script is executed as a CGI script, you can
use the cgi module to get all the information you need.
http://docs.python.org/library/cgi.html

A better way to write web applications in Python is with WSGI. You can
run WSGI scripts in a number of ways, including CGI and other, more
efficient ways that integrate with the web server. Maybe somebody else
knows of a good tutorial on WSGI that they'll link here, otherwise, I'm
sure Google is your friend.

Thomas

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


Evolution (was: code review)

2012-07-03 Thread Ian Kelly
On Mon, Jul 2, 2012 at 1:35 PM, Rick Johnson
 wrote:
> I am reminded of a story: A few years back a very nice old woman
> offered to give me her typewriter. She said: "i might need to type a
> letter one day and it would good to have around". It was a nice
> typewriter for 1956, but she had no idea her little "machine" was
> reduced to no less than a paper weight thanks to something called the
> PC. Her machine had been extinct for decades. Effectually, SHE had
> been extinct for decades.

It's called "retirement", not "extinction", and there's nothing at all
wrong with typing out letters; it's just slower.  If we ever have a
nuclear war or even just get hit by a large enough coronal mass
ejection, you might find yourself wishing you had that typewriter
instead of your suddenly useless laptop -- just as the dinosaurs (had
they been sentient) might have found themselves wishing they had not
evolved to be so darn *large* 65 million years ago.

> When i hear people like Chris evangelizing about slavish syntax, i am
> reminded of the nice old lady. Her intentions where virtuous, however
> her logic was flawed. She is still clinging to old technology. Like
> the Luddites she refuses to see the importance technological
> advancements. And by harboring this nostalgia she is actually
> undermining the future evolution of an entire species.

That's not nostalgia; that's lack of necessity.  There is nothing so
"important" about technological advancement that it must be thrust
upon nice old ladies who have set habits and no good reason to change
them.  And I can't see for the life of me how people failing to jump
on the email bandwagon have anything at all to do with evolution.

> Lifespans are limited for a very important evolutionary reason!

If that is true, then when your singularity finally arrives and we all
become immortal, will that not interfere with evolution?

All kidding aside, evolution is a natural process, not a purpose.  The
ultimate point of evolution will occur when the universe is no longer
entropically able to support life in any form, transcended or
otherwise, and we will all finally be extinct.  Then what?  The
universe just carries on without us, and goes through a whole series
of cosmological epochs that will be observed by nobody at all, for far
longer than the entirety of our brief, chaotic existence.  It's often
suggested that the Big Bang is the cause of our existence, but the Big
Bang is much bigger than us.  The Big Bang is like a rock thrown into
a still pond.  First there is a big splash, then there are some
ripples, and after a short time the pond becomes boringly still again.
 We aren't really part of the pond; we're just riding the ripples, and
when they vanish, so do we.

You made the claim once in another thread that individuals are not
important in the grand scheme of things (I disagree; from our limited
societal vantage point, individuals *are* the grand scheme of things).
 I am trying here to demonstrate the point that the universe doesn't
care one whit about evolution either.  Hopefully I succeeded, because
I don't want to get sucked into another huge, completely off-topic
thread, and so I won't be posting on this again.
-- 
http://mail.python.org/mailman/listinfo/python-list