Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Douglas Alan
On Aug 10, 2:03 am, Steven D'Aprano
 wrote:

> On Sun, 09 Aug 2009 17:56:55 -0700, Douglas Alan wrote:

> > Because in Python, if my friend sees the string "foo\xbar\n", he has no
> > idea whether the "\x" is an escape sequence, or if it is just the
> > characters "\x", unless he looks it up in the manual, or tries it out in
> > the REPL, or what have you.
>
> Fair enough, but isn't that just another way of saying that if you look
> at a piece of code and don't know what it does, you don't know what it
> does unless you look it up or try it out?

Not really. It's more like saying that easy things should be easy, and
hard things should possible. But in this case, Python is making
something that should be really easy, a bit harder and more error
prone than it should be.

In C++, if I know that the code I'm looking at compiles, then I never
need worry that I've misinterpreted what a string literal means. At
least not if it doesn't have any escape characters in it that I'm not
familiar with. But in Python, if I see, "\f\o\o\b\a\z", I'm not really
sure what I'm seeing, as I surely don't have committed to memory some
of the more obscure escape sequences. If I saw this in C++, and I knew
that it was in code that compiled, then I'd at least know that there
are some strange escape codes that I have to look up. Unlike with
Python, it would never be the case in C++ code that the programmer who
wrote the code was just too lazy to type in "\\f\\o\\o\\b\\a\\z"
instead.

> > My friend is adamant that it would be better
> > if he could just look at the string literal and know. He doesn't want to
> > be bothered to have to store stuff like that in his head. He wants to be
> > able to figure out programs just by looking at them, to the maximum
> > degree that that is feasible.
>
> I actually sympathize strongly with that attitude. But, honestly, your
> friend is a programmer (or at least pretends to be one *wink*).

Actually, he's probably written more code than you, me, and ten other
random decent programmers put together. As he can slap out massive
amounts of code very quickly, he'd prefer not to have crap getting in
his way. In the time it takes him to look something up, he might have
written another page of code.

He's perfectly capable of dealing with crap, as years of writing large
programs in Perl and PHP quickly proves, but his whole reason for
learning Python, I take it, is so that he will be bothered with less
crap and therefore write code even faster.

> You can't be a programmer without memorizing stuff: syntax, function
> calls, modules to import, quoting rules, blah blah blah. Take C as
> an example -- there's absolutely nothing about () that says "group
> expressions or call a function" and {} that says "group a code
> block".

I don't really think that this is a good analogy. It's like the
difference between remembering rules of grammar and remembering
English spelling. As a kid, I was the best in my school at grammar,
and one of the worst at speling.

> You just have to memorize it. If you don't know what a backslash
> escape is going to do, why would you use it?

(1) You're looking at code that someone else wrote, or (2) you forget
to type "\\" instead of "\" in your code (or get lazy sometimes), as
that is okay most of the time, and you inadvertently get a subtle bug.

> This is especially important when reading (as opposed to writing) code.
> You read somebody else's code, and see "foo\xbar\n". Let's say you know
> it compiles without warning. Big deal -- you don't know what the escape
> codes do unless you've memorized them. What does \n resolve to? chr(13)
> or chr(97) or chr(0)? Who knows?

It *is* a big deal. Or at least a non-trivial deal. It means that you
can tell just by looking at the code that there are funny characters
in the string, and not just a backslashes. You don't have to go
running for the manual every time you see code with backslashes, where
the upshot might be that the programmer was merely saving themselves
some typing.

> > In comparison to Python, in C++, he can just look "foo\xbar\n" and know
> > that "\x" is a special character. (As long as it compiles without
> > warnings under g++.)
>
> So what you mean is, he can just look at "foo\xbar\n" AND COMPILE IT
> USING g++, and know whether or not \x is a special character.

I'm not sure that your comments are paying due diligence to full
life-cycle software development issues that involve multiple
programmers (or even just your own program that you wrote a year ago,
and you don't remember all the details of what you did) combined with
maintaining and modifying existing code, etc.

> Aside:
> \x isn't a special character:
>
> >>> "\x"
>
> ValueError: invalid \x escape

I think that this all just goes to prove my friend's point! Here I've
been programming in Python for more than a decade (not full time, mind
you, as I also program in other languages, like C++), and even I
didn't know that "\xba" was an escape sequence, and I inadvert

Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Carl Banks
On Aug 9, 11:10 pm, Steven D'Aprano
 wrote:
> On Sun, 09 Aug 2009 18:34:14 -0700, Carl Banks wrote:
> >> Why should a backslash in a string literal be an error?
>
> > Because the behavior of \ in a string is context-dependent, which means
> > a reader can't know if \ is a literal character or escape character
> > without knowing the context, and it means an innocuous change in context
> > can cause a rather significant change in \.
>
> *Any* change in context is significant with escapes.
>
> "this \nhas two lines"
>
> If you change the \n to a \t you get a significant difference. If you
> change the \n to a \y you get a significant difference. Why is the first
> one acceptable but the second not?

Because when you change \n to \t, you've haven't changed the meaning
of the \ character; but when you change \n to \y, you have, and you
did so without even touching the backslash.


> > IOW it's an error-prone mess.
>
> I've never had any errors caused by this.

Thank you for your anecdotal evidence.  Here's mine: This has gotten
me at least twice, and a compiler complaint would have reduced my bug-
hunting time from tens of minutes to ones of seconds.  [Aside: it was
when I was using Python on Windows for the first time]


> I've never seen anyone write to
> this newsgroup confused over escape behaviour, or asking for help with an
> error caused by it, and until this thread, never seen anyone complain
> about it either.

More anecdotal evidence.  Here's mine: I have.


> Excuse my cynicism, but I believe that you are using "error-prone" to
> mean "I don't like this behaviour" rather than "it causes lots of errors".

No, I'm using error-prone to mean error-prone.

Someone (obviously not you because you're have perfect knowledge of
the language and 100% situation awareness at all times) might have a
string like "abcd\stuv"  and change it to "abcd\tuvw" without even
thinking about the fact that the s comes after the backslash.

Worst of all: they might not even notice the error, because the repr
of this string is:

'abcd\tuwv'

They might not notice that the backslash is single, because (unlike
you) mortal fallible human beings don't always register tiny details
like a backslash being single when it should be double.

Point is, this is a very bad inconsistency.  It makes the behavior of
\ impossible to learn by analogy, now you have to memorize a list of
situations where it behaves one way or another.


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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Douglas Alan
On Aug 10, 2:10 am, Steven D'Aprano

> I've never had any errors caused by this.

But you've seen an error caused by this, in this very discussion.
I.e., "foo\xbar".

"\xba" isn't an escape sequence in any other language that I've used,
which is one reason I made this error... Oh, wait a minute -- it *is*
an escape sequence in JavaScript. But in JavaScript, while "\xba" is a
special character, "\xb" is synonymous with "xb".

The fact that every language seems to treat these things similarly but
differently, is yet another reason why they should just be treated
utterly consistently by all of the languages: I.e., escape sequences
that don't have a special meaning should be an error!

> I've never seen anyone write to
> this newsgroup confused over escape behaviour,

My friend objects strongly the claim that he is "confused" by it, so I
guess you are right that no one is confused. He just thinks that it
violates the beautiful sense of aesthetics that he was sworn over and
over again Python to have.

But aesthetics is a non-negligible issue with practical ramifications.
(Not that anything can be done about this wart at this point,
however.)

> or asking for help with an error caused by it, and until
> this thread, never seen anyone complain about it either.

Oh, this bothered me too when I first learned Python, and I thought it
was stupid. It just didn't bother me enough to complain publicly.

Besides, the vast majority of Python noobs don't come here, despite
appearance sometimes, and by the time most people get here, they've
probably got bigger fish to fry.

|>ouglas


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


Re: Monkeypatching an object to become callable

2009-08-10 Thread Bruno Desthuilliers

7stud a écrit :
(snip)

class Wrapper(object):
def __init__(self, obj, func):
self.obj = obj
self.func = func

def __call__(self, *args):
return self.func(*args)

def __getattr__(self, name):
return object.__getattribute__(self.obj, name)


This should be

  return getattr(self.obj, name)

directly calling object.__getattribute__ might skip redefinition of 
__getattribute__ in self.obj.__class__ or it's mro.


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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Steven D'Aprano
On Mon, 10 Aug 2009 00:37:33 -0700, Carl Banks wrote:

> On Aug 9, 11:10 pm, Steven D'Aprano
>  wrote:
>> On Sun, 09 Aug 2009 18:34:14 -0700, Carl Banks wrote:
>> >> Why should a backslash in a string literal be an error?
>>
>> > Because the behavior of \ in a string is context-dependent, which
>> > means a reader can't know if \ is a literal character or escape
>> > character without knowing the context, and it means an innocuous
>> > change in context can cause a rather significant change in \.
>>
>> *Any* change in context is significant with escapes.
>>
>> "this \nhas two lines"
>>
>> If you change the \n to a \t you get a significant difference. If you
>> change the \n to a \y you get a significant difference. Why is the
>> first one acceptable but the second not?
> 
> Because when you change \n to \t, you've haven't changed the meaning of
> the \ character; 

I assume you mean the \ character in the literal, not the (non-existent) 
\ character in the string.


> but when you change \n to \y, you have, and you did so
> without even touching the backslash.

Not at all.

'\n' maps to the string chr(10).
'\y' maps to the string chr(92) + chr(121).

In both cases the backslash in the literal have the same meaning: grab 
the next token (usually a single character, but not always), look it up 
in a mapping somewhere, and insert the result in the string object being 
built.

(I don't know if the *implementation* is precisely as described, but 
that's irrelevant. It's still functionally a mapping.) 



>> > IOW it's an error-prone mess.
>>
>> I've never had any errors caused by this.
> 
> Thank you for your anecdotal evidence.  Here's mine: This has gotten me
> at least twice, and a compiler complaint would have reduced my bug-
> hunting time from tens of minutes to ones of seconds.  [Aside: it was
> when I was using Python on Windows for the first time]

Okay, that's twice in, how many years have you been programming?

I've mistyped "xrange" as "xrnage" two or three times. Does that make 
xrange() "an error-prone mess" too? Probably not. Why is my mistake my 
mistake, but your mistake the language's fault?


[...]

Oh, wait, no, I tell I lie -- I *have* seen people reporting "bugs" here 
caused by backslashes. They're invariably Windows programmers writing 
pathnames using backslashes, so I'll give you that one: if you don't know 
that Python treats backslashes as special in string literals, you will 
screw up your Windows pathnames.

Interestingly, the problem there is not that \y resolves to literal 
backslash followed by y, but that \t DOESN'T resolve to the expected 
backslash-t. So it seems to me that the problem for Windows coders is not 
that \y doesn't raise an error, but the mere existence of backslash 
escapes.



> Someone (obviously not you because you're have perfect knowledge of the
> language and 100% situation awareness at all times) might have a string
> like "abcd\stuv"  and change it to "abcd\tuvw" without even thinking
> about the fact that the s comes after the backslash.

Deary me. And they might type "4+15" instead of "4*51", and now 
arithmetic is an "error-prone mess" too. If you know of a programming 
language which can prevent you making semantic errors, please let us all 
know what it is.

If you edit code without thinking, you will be burnt, and you get *zero* 
sympathy from me.


> Worst of all: they might not even notice the error, because the repr of
> this string is:
> 
> 'abcd\tuwv'
> 
> They might not notice that the backslash is single, because (unlike you)
> mortal fallible human beings don't always register tiny details like a
> backslash being single when it should be double.

"Help help, 123145 looks too similar to 1231145, and now I calculated my 
taxes wrong and will go to jail!!!"


> Point is, this is a very bad inconsistency.  It makes the behavior of \
> impossible to learn by analogy, now you have to memorize a list of
> situations where it behaves one way or another.

No, you don't "have" to memorize anything, you can go right ahead and 
escape every backslash, as I did for years. Your code will still work 
fine.

You already have to memorize what escape codes return special characters. 
The only difference is whether you learn "...and everything else raises 
an exception" or "...and everything else is returned unchanged". 

There is at least one good reason for preferring an error, namely that it 
allows Python to introduce new escape codes without going through a long, 
slow process. But the rest of these complaints are terribly unconvincing.



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


install tarball package Python on Debian, necessary modules not found

2009-08-10 Thread Frédéric Léger
I use Debian Lenny and I tried to install the tarball packaging of the lastest 
python realease (http://www.python.org/download/, release 3.1). After read 
README file I launch standard Makefile commands. But at the end of "make" 
command, I have got this message:

"...
Python build finished, but the necessary bits to build these modules were not 
found:
_curses_curses_panel  _dbm
_gdbm  _hashlib   _sqlite3
_ssl   _tkinter   bz2
readline
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.
..."

Solution:

So I installed these Debian packages to correct the problem:

_curses, _curses_panel = libncurses-dev
zlib = libbz2-dev
bz2 = libzip-dev
_dbm, _gdbm = libgdbm-dev 
_hashlib, _ssl = libssl-dev 
_sqlite3 = libsqlite3-dev 
_tkinter = tk8.4-dev 
readline = libreadline5-dev 

I use on command line "apt-get install libncurses-dev libbz2-dev ..."
After that, I retry to compile python "make clean ; make ...". And all modules 
are good.

Good work with Python 3.1 ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Steven D'Aprano
On Mon, 10 Aug 2009 00:57:18 -0700, Douglas Alan wrote:

> On Aug 10, 2:10 am, Steven D'Aprano
> 
>> I've never had any errors caused by this.
> 
> But you've seen an error caused by this, in this very discussion. I.e.,
> "foo\xbar".


Your complaint is that "invalid" escapes like \y resolve to a literal 
backslash-y instead of raising an error. But \xbar doesn't contain an 
invalid escape, it contains a valid hex escape. Your ignorance that \xHH 
is a valid hex escape (for suitable hex digits) isn't an example of an 
error caused by "invalid" escapes like \y.



> "\xba" isn't an escape sequence in any other language that I've used,
> which is one reason I made this error... Oh, wait a minute -- it *is* an
> escape sequence in JavaScript. But in JavaScript, while "\xba" is a
> special character, "\xb" is synonymous with "xb".
> 
> The fact that every language seems to treat these things similarly but
> differently, is yet another reason why they should just be treated
> utterly consistently by all of the languages: I.e., escape sequences
> that don't have a special meaning should be an error!

Perhaps all the other languages should follow Python's lead instead?

Or perhaps they should follow bash's lead, and map \C to C for every 
character. If there were no special escapes at all, Windows programmers 
wouldn't keep getting burnt when they write "C:\\Documents\today\foo" and 
end up with something completely unexpected.

Oh wait, no, that still wouldn't work, because they'd end up with 
C:\Documentstodayfoo. So copying bash doesn't work.

But copying C will upset the bash coders, because they'll write 
"some\ file\ with\ spaces" and suddenly their code won't even compile!!!

Seems like no matter what you do, you're going to upset *somebody*.



>> I've never seen anyone write to
>> this newsgroup confused over escape behaviour,
> 
> My friend objects strongly the claim that he is "confused" by it, so I
> guess you are right that no one is confused. He just thinks that it
> violates the beautiful sense of aesthetics that he was sworn over and
> over again Python to have.

Fair enough.



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


Re: resume upload wsgi script

2009-08-10 Thread Diez B. Roggisch


250KB :)


So why do you bother?


Its just HTTP1.1 has everything for making ftp like file transfers
possible.
When I write it to a file then I am back at square one because I still
need to load it completely to get it into a blob.


Well, the blob is nothing but datat in the file-system. If you are 
*really* concerned about that, then don't use the db, but use the 
filesystem, appending to the file until it's finished - and storing a 
reference to it to the DB. We do that as well, because otherwise the db 
will become unmanagable anyway (dumping, backups).



So there is no way to concatenate BLOB's without loading it completely
into memory ?


In theory, the DB might offer special stream-based methods for these 
kinds of tasks, but the db-api lacks them. Some DB-adapters might offer 
some non-standard-extensions, but I don't think sqlite does.


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


Re: Problem with join in__str__() in class (newbie)

2009-08-10 Thread Fencer

Piet van Oostrum wrote:
[snip]

Thanks for your detailed reply!

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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Duncan Booth
Douglas Alan  wrote:

> "\xba" isn't an escape sequence in any other language that I've used,
> which is one reason I made this error... Oh, wait a minute -- it *is*
> an escape sequence in JavaScript. But in JavaScript, while "\xba" is a
> special character, "\xb" is synonymous with "xb".
> 

"\xba" is an escape sequence in c, c++, c#, python, javascript, perl and 
probably many others.

"\xb" is an escape sequence in c, c++, c# but not in Python, Javascript, or 
Perl. Python will throw ValueError if you try to use "\xb" in a string, 
Javascript simply ignores the backslash.

> The fact that every language seems to treat these things similarly but
> differently, is yet another reason why they should just be treated
> utterly consistently by all of the languages: I.e., escape sequences
> that don't have a special meaning should be an error!

It would be nice if these things were treated consistently, but they aren't 
and it seems unlikely to change.



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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Duncan Booth
Steven D'Aprano  wrote:

> Or perhaps they should follow bash's lead, and map \C to C for every 
> character. If there were no special escapes at all, Windows
> programmers wouldn't keep getting burnt when they write
> "C:\\Documents\today\foo" and end up with something completely
> unexpected. 
> 
> Oh wait, no, that still wouldn't work, because they'd end up with 
> C:\Documentstodayfoo. So copying bash doesn't work.
> 

There is of course no problem at all so long as you stick to writing your 
paths as MS intended them to be written: 8.3 and UPPERCASE

>>> "C:\DOCUME~1\TODAY\FOO"
'C:\\DOCUME~1\\TODAY\\FOO'

:^)


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


Re: install tarball package Python on Debian, necessary modules not found

2009-08-10 Thread garabik-news-2005-05
Frédéric Léger  wrote:

> I use Debian Lenny and I tried to install the tarball packaging of the
> lastest python realease (http://www.python.org/download/, release
> 3.1). After read README file I launch standard Makefile commands. But
> at the end of "make" command, I have got this message:
> 

Maybe you know, but there is python3.1 deb in experimental. Works with
testing like a charm. It is also possible to install ubuntu's 3.X into
debian.

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in installing PyGreSQL

2009-08-10 Thread Thangappan.M
Here I attached the setup.py and setup.cfg file.This is for your reference.
I have changed the exception line.
Even though I got the following error while running the python setup.py
build
running build
running build_py
running build_ext
error: No such file or directory

===

On Fri, Aug 7, 2009 at 7:38 PM, Scott David Daniels
wrote:

> Dennis Lee Bieber wrote:
>
>> On Thu, 6 Aug 2009 16:00:15 +0530, "Thangappan.M"
>>  declaimed the following in
>> gmane.comp.python.general:
>>
>>>  File "./setup.py", line 219, in finalize_options
>>>except (Warning, w):
>>> NameError: global name 'w' is not defined
>>>
>>> What would be the solution?
>>> Otherwise can you tell how to install DB-API in debian machine.
>>>
>>Sorry... 1) I run on WinXP; 2) I don't build packages, relying on
>> pre-built binaries; 3) I run MySQL.
>>
>>However, based upon the examples in the Tutorial, that line should
>> not have the (, ). A parenthesised (tuple) is suppose to contain a list
>> of exceptions, and the parameter to catch the exception specifics has to
>> be outside the list.
>>
>>Best I can suggest is editing that particular line and removing the
>> (, ) -- then try rebuilding.
>>
>>I'll also re-ask: All you are installing is the Python adapter to
>> the database. DO YOU HAVE A RUNNING PostgreSQL server that you can
>> connect to?
>>
>
> Just to be a bit more explict:
> Change file setup.py's line 219 from:
> >> except (Warning, w):
> to either (OK in Python 2.6 and greater):
>   except Warning as w:
> or (works for Python 2.X):
>   except Warning, w:
>
>
> --Scott David Daniels
> [email protected]
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards,
Thangappan.M


setup.cfg
Description: Binary data
# setup.py - distutils packaging
#
# Copyright (C) 2003-2004 Federico Di Gregorio  
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

"""Python-PostgreSQL Database Adapter

psycopg is a PostgreSQL database adapter for the Python programming
language. This is version 2, a complete rewrite of the original code to
provide new-style classes for connection and cursor objects and other sweet
candies. Like the original, psycopg 2 was written with the aim of being
very small and fast, and stable as a rock.

psycopg is different from the other database adapter because it was
designed for heavily multi-threaded applications that create and destroy
lots of cursors and make a conspicuous number of concurrent INSERTs or
UPDATEs. psycopg 2 also provide full asycronous operations for the really
brave programmer.
"""

classifiers = """\
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License (GPL)
License :: OSI Approved :: Zope Public License
Programming Language :: Python
Programming Language :: C
Programming Language :: SQL
Topic :: Database
Topic :: Database :: Front-Ends
Topic :: Software Development
Topic :: Software Development :: Libraries :: Python Modules
Operating System :: Microsoft :: Windows
Operating System :: Unix
"""

import os
import os.path
import sys
import subprocess
import ConfigParser
from distutils.core import setup, Extension
from distutils.errors import DistutilsFileError
from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc
from distutils.ccompiler import get_default_compiler

PSYCOPG_VERSION = '2.0.10'
version_flags   = ['dt', 'dec']

PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')

def get_pg_config(kind, pg_config="pg_config"):
p = subprocess.Popen([pg_config, "--" + kind],
 stdin=subprocess.PIPE,
 stdout=subprocess.PIPE,
 stderr=subprocess.PIPE)
p.stdin.close()
r = p.stdout.readline().strip()
if not r:
raise Warning(p.stderr.readline())
return r

class psycopg_build_ext(build_ext):
"""Conditionally complement the setup.cfg options file.

This class configures the include_dirs, libray_dirs, libraries
options as required by the system. Most of the configuration happens
in finalize_options() method.

If you want to set up the build step for a peculiar platform, add a
method finalize_PLAT(), where PLAT matches your sys.platform.
"""
user_options = build_ext.user_options[:]
user_options.extend([
('use-pydatetime', None,
 "Use Python datatime objects for date and time representation."),
('pg-config=', None,
  

Re: exec("dir()",d)

2009-08-10 Thread Emanuele D'Arrigo
Thank you both for the explanation.

As a matter of fact RTFM doesn't -always- help. Sometimes I'm just
thick and I can read the manual 10 times and still not understand, as
it happened on this particular matter. Your contribution focused my
attention on the right bit of the manual which I somehow didn't manage
to ingest before. Now I understand.

Thank you.

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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Steven D'Aprano
On Mon, 10 Aug 2009 00:32:30 -0700, Douglas Alan wrote:

> In C++, if I know that the code I'm looking at compiles, then I never
> need worry that I've misinterpreted what a string literal means.

If you don't know what your string literals are, you don't know what your 
program does. You can't expect the compiler to save you from semantic 
errors. Adding escape codes into the string literal doesn't change this 
basic truth.

Semantics matters, and unlike syntax, the compiler can't check it. 
There's a difference between a program that does the equivalent of:

os.system("cp myfile myfile~")

and one which does this

os.system("rm myfile myfile~")


The compiler can't save you from typing 1234 instead of 11234, or 31.45 
instead of 3.145, or "My darling Ho" instead of "My darling Jo", so why 
do you expect it to save you from typing "abc\d" instead of "abc\\d"?

Perhaps it can catch *some* errors of that type, but only at the cost of 
extra effort required to defeat the compiler (forcing the programmer to 
type \\d to prevent the compiler complaining about \d). I don't think the 
benefit is worth the cost. You and your friend do. Who is to say you're 
right?



> At
> least not if it doesn't have any escape characters in it that I'm not
> familiar with. But in Python, if I see, "\f\o\o\b\a\z", I'm not really
> sure what I'm seeing, as I surely don't have committed to memory some of
> the more obscure escape sequences. If I saw this in C++, and I knew that
> it was in code that compiled, then I'd at least know that there are some
> strange escape codes that I have to look up. 

And if you saw that in Python, you'd also know that there are some 
strange escape codes that you have to look up. Fortunately, in Python, 
that's really simple:

>>> "\f\o\o\b\a\z"
'\x0c\\o\\o\x08\x07\\z'

Immediately you can see that the \o and \z sequences resolve to 
themselves, and the \f \b and \a don't.



> Unlike with Python, it
> would never be the case in C++ code that the programmer who wrote the
> code was just too lazy to type in "\\f\\o\\o\\b\\a\\z" instead.

But if you see "abc\n", you can't be sure whether the lazy programmer 
intended "abc"+newline, or "abc"+backslash+"n". Either way, the compiler 
won't complain.


 
>> You just have to memorize it. If you don't know what a backslash escape
>> is going to do, why would you use it?
> 
> (1) You're looking at code that someone else wrote, or (2) you forget to
> type "\\" instead of "\" in your code (or get lazy sometimes), as that
> is okay most of the time, and you inadvertently get a subtle bug.

The same error can occur in C++, if you intend \\n but type \n by 
mistake. Or vice versa. The compiler won't save you from that.



>> This is especially important when reading (as opposed to writing) code.
>> You read somebody else's code, and see "foo\xbar\n". Let's say you know
>> it compiles without warning. Big deal -- you don't know what the escape
>> codes do unless you've memorized them. What does \n resolve to? chr(13)
>> or chr(97) or chr(0)? Who knows?
> 
> It *is* a big deal. Or at least a non-trivial deal. It means that you
> can tell just by looking at the code that there are funny characters in
> the string, and not just a backslashes. 

I'm not entirely sure why you think that's a big deal. Strictly speaking, 
there are no "funny characters", not even \0, in Python. They're all just 
characters. Perhaps the closest is newline (which is pretty obvious).



> You don't have to go running for
> the manual every time you see code with backslashes, where the upshot
> might be that the programmer was merely saving themselves some typing.

Why do you care if there are "funny characters"?

In C++, if you see an escape you don't recognize, do you care? Do you go 
running for the manual? If the answer is No, then why do it in Python?

And if the answer is Yes, then how is Python worse than C++?


[...]
> Also, it seems that Python is being inconsistent here. Python knows that
> the string "\x" doesn't contain a full escape sequence, so why doesn't
> it
> treat the string "\x" the same way that it treats the string "\z"?
[...]
> I.e., "\z" is not a legal escape sequence, so it gets left as "\\z".

No. \z *is* a legal escape sequence, it just happens to map to \z.

If you stop thinking of \z as an illegal escape sequence that Python 
refuses to raise an error for, the problem goes away. It's a legal escape 
sequence that maps to backslash + z.



> "\x" is not a legal escape sequence. Shouldn't it also get left as
> "\\x"?

No, because it actually is an illegal escape sequence.



>> > He's particularly annoyed too, that if he types "foo\xbar" at the
>> > REPL, it echoes back as "foo\\xbar". He finds that to be some sort of
>> > annoying DWIM feature, and if Python is going to have DWIM features,
>> > then it should, for example, figure out what he means by "\" and not
>> > bother him with a syntax error in that case.
>>
>> Now your friend is confused. This is 

Re: Cython + setuptools not working with .pyx,only with .c-files

2009-08-10 Thread Diez B. Roggisch
Stefan Behnel wrote:

> Diez B. Roggisch wrote:
>> I'm trying to build a Cython-extension as Egg.
>> 
>> However, this doesn't work - I can either use distutils to build the
>> extension, creating a myextension.c-file on the way.
>> 
>> If that's there, I can use setuptools to build the egg.
>> 
>> But when I remove the .c-file, the .pyx-file isn't used to re-generate
>> it.
> 
> setuptools monkeypatch into distutils to support Pyrex if it's installed,
> but most non-bleeding-edge versions do not know about Cython and thus
> break the Cython distutils support when Pyrex isn't there as well.
> 
> What helps is to put a fake Pyrex installation into your sys.path, like
> 
> http://codespeak.net/svn/lxml/trunk/fake_pyrex/
> 
> as done at the top of
> 
> http://codespeak.net/svn/lxml/trunk/setup.py

Thanks, that did the trick for us.

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


Problem Regarding Handling of Unicode string

2009-08-10 Thread joy99
Dear Group,

I am using Python26 on WindowsXP with service pack2. My GUI is IDLE.
I am using Hindi resources and get nice output like:
एक
where I can use all the re functions and other functions without doing
any transliteration,etc.
I was trying to use Bengali but it is giving me output like:
'\xef\xbb\xbf\xe0\xa6\x85\xe0\xa6\xa8\xe0\xa7\x87\xe0\xa6\x95'
I wanted to see Bengali output as
অনেক
and I like to use all functions including re.
If any one can help me on that.
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem when fetching page using urllib2.urlopen

2009-08-10 Thread jitu
Hi,

A html page  contains 'anchor' elements with 'href' attribute  having
a semicolon  in the url , while fetching the page using
urllib2.urlopen, all such href's  containing  'semicolons' are
truncated.


For example the href 
http://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt=AlWSqpkpqhICp1lMgChtJkCdGWoL
get truncated to 
http://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i

The page I am talking about can be fetched from
http://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_ylc=X3oDMTFka28zOGNuBF9TAzI3NjY2NzkEX3MDOTY5NTUzMjUEc2VjA3NzcC1kZXN0BHNsawN0aXRsZQ--

Thanks a Lot
Regards
jitu

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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread MRAB

Steven D'Aprano wrote:

On Sun, 09 Aug 2009 17:56:55 -0700, Douglas Alan wrote:


[snip]

My point of view is that
every language has *some* warts; Python just has a bit fewer than most.
It would have been nice, I should think, if this wart had been "fixed"
in Python 3, as I do consider it to be a minor wart.


And if anyone had cared enough to raise it a couple of years back, it 
possibly might have been.



My preference would've been that a backslash followed by A-Z, a-z, or
0-9 is special, but a backslash followed by any other character is just
the character, except for backslash followed by a newline, which
suppresses the newline.

I would also have preferred a backslash in a raw string to always be a
literal.

Ah well, something for Python 4.x. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Regarding Handling of Unicode string

2009-08-10 Thread Ulrich Eckhardt
joy99 wrote:
> [...] it is giving me output like:
> '\xef\xbb\xbf\xe0\xa6\x85\xe0\xa6\xa8\xe0\xa7\x87\xe0\xa6\x95'
   

These three bytes encode the byte-order marker (BOM, Unicode uFEFF) as
UTF-8, followed by codepoint u09a8 (look it up on unicode.org what that
is).

In any case, if this is produced as output, there is some missing
encoding/decoding going on. You mentioned that it works in one case but
doesn't in another. Since you didn't provide any information how to
reproduce what you saw, any further help is at most guesswork.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Problem when fetching page using urllib2.urlopen

2009-08-10 Thread jitu
On Aug 10, 4:39 pm, jitu  wrote:
> Hi,
>
> A html page  contains 'anchor' elements with 'href' attribute  having
> a semicolon  in the url , while fetching the page using
> urllib2.urlopen, all such href's  containing  'semicolons' are
> truncated.
>
> For example the 
> hrefhttp://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt...
> get truncated 
> tohttp://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i
>
> The page I am talking about can be fetched 
> fromhttp://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_...
>
> Thanks a Lot
> Regards
> jitu

Hi

   Sorry, the question what I wanted to ask was, whether is this the
correct behaviour or a bug ?


Thanks A Lot.
Regards
jitu
-- 
http://mail.python.org/mailman/listinfo/python-list


[Errno 9] Bad file descriptor

2009-08-10 Thread Mehndi, Sibtey
Hi
I am trying to create a COM object of picalo functionalities so that I can use 
it into my VB application but I am getting the following error "[Errno 9] bad 
file descriptor".
Can you please suggest me what is supposed to do to avoid this problem?

This is my code

class Test(object):
_reg_progid_ = "test"
_reg_clsid_ = "{D2EFAAC0-797A-471A-AA07-ECEACFE33A08}"
_public_methods_ = ['dbconnect']


def dbconnect(self, dbName, dbUserName, dbPWD, dbHost, dbPort):
try:
self.conn = Database.MySQLConnection(dbName, username=dbUserName, 
password=dbPWD, host=dbHost, port=dbPort)
self.table = self.conn.table( "SELECT * FROM test_flag_data")
return  "connected"
except Exception,e:
return str(e)

Thanks,
Sibty



This e-mail (and any attachments), is confidential and may be privileged. It 
may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and 
disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended 
recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or 
disclosing it to a third person.

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


Re: www.python.org website is down?

2009-08-10 Thread Christopher
On Aug 8, 5:50 pm, Pouya Khankhanian  wrote:
> On Aug 8, 11:49 am, Sharath  wrote:
>
>
>
> > On Aug 8, 11:33 am, Pouya Khankhanian  wrote:
>
> > > On Aug 8, 11:17 am, "Martin v. Löwis"  wrote:
>
> > > > > This is probably a stupid question, but Is there going to be any data
> > > > > loss if it turns out that the disk has died completely? I assume there
> > > > > are backups of the repo that are geographically distributed.
>
> > > > Yes, we have backups, and are restoring them at the moment. However,
> > > > we still haven't given up on the original disks: they are (probably)
> > > > fine; it's just the RAID controller that has failed (and we can't buy a
> > > > replacement before Monday).
>
> > > > Regards,
> > > > Martin
>
> > > Is there a mirror site to download the latest python installer? Every
> > > mirror I have found on the web redirects me to python.org.
> > > Best
> > > Peter
>
> > Python FTP mirror sites also have the same problem. They are not being
> > mirrored for some require a password. Is there any other way to get a
> > copy?
>
> > Sharath Venkatesha
>
> Website is back up! Thanks for all the hard work

Actually, it appears to be down again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing Remote Registry

2009-08-10 Thread Kevin Holleran
On Fri, Aug 7, 2009 at 2:08 PM, Tim Golden  wrote:

> Kevin Holleran wrote:
>
>> Long story short, I am using _winreg to do this.
>>
>> hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
>> value,type = _winreg.QueryValueEx(hKey, item)
>> if (value == wrongValue):
>>   _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)
>>
>>
>> When I do this I receive the error:
>>
>> _winreg.SetValue WindowsError: [Error 5] Access Denied
>>
>
> As an alternative, try using WMI instead. You'll have to look up the docs
> a bit, but to get you started:
>
> 
> import wmi
>
> reg = wmi.WMI ("remote-machine", namespace="default").StdRegProv
>
> print reg.methods.keys ()
>
> 
>
> TJG
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Thank you for your response.

I actually started with the WMI wrapper but isn't that just a wrapper that
utilizes (in this case) the _winreg module?

I guess my question is will Windows let me change the registry remotely?
The error is a Windows permission error on the KEY_SET_VALUE.  I am running
this as a domain admin on a machine on the domain.  Does the connection
inherit the credentials I am running it under or will I need to pass those
in?  Or does Windows simply not let me change the registry?

To me its not worth too much trouble.  If I can change it in place it saves
me just a little bit of work because I have to touch each machine anyway for
other reasons.  The big difference is that I can change all the machines I
have to touch right now and get them fixed up or these folks are just going
to have to wait until I get to each one.

Thanks for all your help and support.

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


compression level with tarfile (w:gz) ?

2009-08-10 Thread Esmail

Hello,

I was wondering if it possible to specify a compression level when I
tar/gzip a file in Python using the tarfile module. I would like to
specify the highest (9) compression level for gzip.

Ideally:

   t = tarfile.open(tar_file_name+'.tar.gz', mode='w:gz:9')

When I create a simple tar and then gzip it 'manually' with compression
level 9, I get a smaller archive than when I have this code execute with
the w:gz option.

Is the only way to accomplish the higher rate to create a tar file
and then use a different module to gzip it (assuming I can specify
the compression level there)?

Thanks,
Esmail

-
My current code:
-

def tar_it_up(target_dir_name, tar_file_name=None):
'''
tar up target_dir_name directory and create a
tar/zip file with base name tar_file_name

appends a date/timestamp to tar_file_name
'''

time_string = time.strftime("_%b_%d_%Y_%a_%H_%M")

if tar_file_name is None:
tar_file_name = target_dir_name

tar_file_name += time_string

print ('Creating archive of %s ...' % target_dir_name),

t = tarfile.open(tar_file_name+'.tar.gz', mode='w:gz')
#   t = tarfile.open(tar_file_name+'.tar', mode='w')
t.add(target_dir_name)
t.close()

print ('saved to %s.tar.gz' % tar_file_name)

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


Re: www.python.org website is down?

2009-08-10 Thread Xavier Ho
On Mon, Aug 10, 2009 at 10:41 PM, Christopher wrote:

>
> Actually, it appears to be down again.
>

Nope, works for me, just a little slow.

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


Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Benjamin Kaplan
On Mon, Aug 10, 2009 at 8:50 AM, Esmail wrote:
> Hello,
>
> I was wondering if it possible to specify a compression level when I
> tar/gzip a file in Python using the tarfile module. I would like to
> specify the highest (9) compression level for gzip.
>
> Ideally:
>
>   t = tarfile.open(tar_file_name+'.tar.gz', mode='w:gz:9')
>
> When I create a simple tar and then gzip it 'manually' with compression
> level 9, I get a smaller archive than when I have this code execute with
> the w:gz option.
>

Looking at the tarfile docs, it seems that there are tarfile.gzopen
and tarfile.bz2open functions that have a compresslevel parameter that
defaults to 9. You can't append using those functions but you can read
and write.

> Is the only way to accomplish the higher rate to create a tar file
> and then use a different module to gzip it (assuming I can specify
> the compression level there)?
>
> Thanks,
> Esmail
>
> -
> My current code:
> -
>
> def tar_it_up(target_dir_name, tar_file_name=None):
>    '''
>    tar up target_dir_name directory and create a
>    tar/zip file with base name tar_file_name
>
>    appends a date/timestamp to tar_file_name
>    '''
>
>    time_string = time.strftime("_%b_%d_%Y_%a_%H_%M")
>
>    if tar_file_name is None:
>        tar_file_name = target_dir_name
>
>    tar_file_name += time_string
>
>    print ('Creating archive of %s ...' % target_dir_name),
>
>    t = tarfile.open(tar_file_name+'.tar.gz', mode='w:gz')
> #   t = tarfile.open(tar_file_name+'.tar', mode='w')
>    t.add(target_dir_name)
>    t.close()
>
>    print ('saved to %s.tar.gz' % tar_file_name)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Esmail

Benjamin Kaplan wrote:

On Mon, Aug 10, 2009 at 8:50 AM, Esmail wrote:


I was wondering if it possible to specify a compression level when I
tar/gzip a file in Python using the tarfile module. I would like to
specify the highest (9) compression level for gzip.

Ideally:

  t = tarfile.open(tar_file_name+'.tar.gz', mode='w:gz:9')

<..>


Looking at the tarfile docs, it seems that there are tarfile.gzopen
and tarfile.bz2open functions that have a compresslevel parameter that
defaults to 9. You can't append using those functions but you can read
and write.


Hi Benjamin,

I can't find tarfile.gzopen  in the tarfile docs, I'm looking here:

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

Am I looking at the wrong page?

Thanks,

Esmail

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


Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Benjamin Kaplan
On Mon, Aug 10, 2009 at 9:37 AM, Esmail wrote:
> Benjamin Kaplan wrote:
>>
>> On Mon, Aug 10, 2009 at 8:50 AM, Esmail wrote:
>>>
>>> I was wondering if it possible to specify a compression level when I
>>> tar/gzip a file in Python using the tarfile module. I would like to
>>> specify the highest (9) compression level for gzip.
>>>
>>> Ideally:
>>>
>>>  t = tarfile.open(tar_file_name+'.tar.gz', mode='w:gz:9')
>
> <..>
>>
>> Looking at the tarfile docs, it seems that there are tarfile.gzopen
>> and tarfile.bz2open functions that have a compresslevel parameter that
>> defaults to 9. You can't append using those functions but you can read
>> and write.
>
> Hi Benjamin,
>
> I can't find tarfile.gzopen  in the tarfile docs, I'm looking here:
>
>    http://docs.python.org/library/tarfile.html
>
> Am I looking at the wrong page?
>

My mistake. It isn't a function of the tarfile module, it's a class
method of tarfile.TarFile. I was looking at the help in the
interactive interpreter. It doesn't seem to be in the official docs,
but you can use pydoc to view the docstrings.

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


Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Lars Gustäbel
On Mon, Aug 10, 2009 at 08:50:21AM -0400, Esmail wrote:
> I was wondering if it possible to specify a compression level when I
> tar/gzip a file in Python using the tarfile module. I would like to
> specify the highest (9) compression level for gzip.

tarfile uses gzip.GzipFile() internally, GzipFile()'s default compression level
is 9.

> When I create a simple tar and then gzip it 'manually' with compression
> level 9, I get a smaller archive than when I have this code execute with
> the w:gz option.

How much smaller is it? I did a test with a recent Linux kernel source tree
which made an archive of 337MB. Command-line gzip was ahead of Python's
GzipFile() by just 20200 bytes(!) with an archive of about 74MB.

> Is the only way to accomplish the higher rate to create a tar file
> and then use a different module to gzip it (assuming I can specify
> the compression level there)?

If you need the disk space that badly, the alternative would be to pipe
tarfile's output to command-line gzip somehow:

fobj = open("result.tar.gz", "w")
proc = subprocess.Popen(["gzip", "-9"], stdin=subprocess.PIPE, stdout=fobj)
tar = tarfile.open(fileobj=proc.stdin, mode="w|")
tar.add(...)
tar.close()
proc.stdin.close()
fobj.close()

Cheers,

-- 
Lars Gustäbel
[email protected]

A physicist is an atom's way of knowing about atoms.
(George Wald)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: www.python.org website is down?

2009-08-10 Thread r
On Aug 8, 8:48 am, MRAB  wrote:
...(snip)
> Bothwww.python.organd svn.python.org are down.  They're hosted on
> the same machine, and it seems to have run into disk problems and
> hasn't rebooted even after power-cycling.  Thomas Wouters will be
> visiting the machine physically tomorrow to try to diagnose the
> problem.

Oh stop lying MRAB, everybody knows Guido hosts Python.org from his
attic on an old Linux box :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-10 Thread rurpy
On Aug 9, 10:02 pm, David Lyon  wrote:
...
> Before you do that, you should clearly work out in your own mind
> how you think things need to improve. It's not good enough just
> saying this or that is bad without having specific ideas on what
> needs to change.
'''

He did.  Did you read, for example, the critique of the gzip
docs for which he gave the url

   http://xahlee.org/perl-python/python_doc_gzip.html

There were some things I might not completely agree with
there, but basically, I thought it was right on, including
his suggestions on how to improve it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: www.python.org website is down?

2009-08-10 Thread MRAB

r wrote:

On Aug 8, 8:48 am, MRAB  wrote:
...(snip)

Bothwww.python.organd svn.python.org are down.  They're hosted on
the same machine, and it seems to have run into disk problems and
hasn't rebooted even after power-cycling.  Thomas Wouters will be
visiting the machine physically tomorrow to try to diagnose the
problem.


Oh stop lying MRAB, everybody knows Guido hosts Python.org from his
attic on an old Linux box :-)


That was a quote from A.M. Kuchling.

It's actually hosted on a matchbox-sized multi-core multi-terabyte
wifi-enabled Linux machine that Guido brought back from 2050.
Unfortunately, the dog ate it, so he's had to go and buy another one!
:-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Douglas Alan
On Aug 10, 4:37 am, Steven D'Aprano

> There is at least one good reason for preferring an error, namely that it
> allows Python to introduce new escape codes without going through a long,
> slow process. But the rest of these complaints are terribly unconvincing.


What about:

   o Beautiful is better than ugly
   o Explicit is better than implicit
   o Simple is better than complex
   o Readability counts
   o Special cases aren't special enough to break the rules
   o Errors should never pass silently

?

And most importantly:

   o In the face of ambiguity, refuse the temptation to guess.
   o There should be one -- and preferably only one -- obvious way to
do it.

?

So, what's the one obvious right way to express "foo\zbar"? Is it

   "foo\zbar"

or

   "foo\\zbar"

And if it's the latter, what possible benefit is there in allowing the
former?  And if it's the former, why does Python echo the latter?

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


Re: syntax checker in python

2009-08-10 Thread nn
On Aug 7, 4:39 pm, horos11  wrote:
> ps - I just realized that it isn't enough to do:
>
> python -c 'import /path/to/script'
>
> since that actually executes any statement inside of the script
> (wheras all I want to do is check syntax)
>
> So - let me reprhase that - exactly how can you do a syntax check in
> python? Something like perl's -c:
>
>      perl -c script_name.p
>
> Ed

You might want to check PyFlakes; it doesn't execute scripts unlike
the others.

http://www.divmod.org/trac/wiki/DivmodPyflakes
-- 
http://mail.python.org/mailman/listinfo/python-list


With or without leading underscore...

2009-08-10 Thread Ulrich Eckhardt
...that is the question!

I have a module which exports a type. It also exports a function that
returns instances of that type. Now, the reason for my question is that
while users will directly use instances of the type, they will not create
instances of the type themselves.

So, the type is a part of the public API, but its constructor is not. Should
I mark the type as private (with a leading underscore) or not?

Thanks!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Python configuration question when python scripts are executed using Appweb as web server.

2009-08-10 Thread IronyOfLife
Hi Gabriel

Thanks for the detailed and useful reply.


On Aug 7, 1:37 am, "Gabriel Genellina"  wrote:
> En Thu, 06 Aug 2009 12:49:30 -0300, IronyOfLife   
> escribió:
>
>
>
>
>
> > On Aug 5, 4:18 pm, "Gabriel Genellina"  wrote:
> >> En Tue, 04 Aug 2009 10:15:24 -0300, IronyOfLife 
> >> escribió:
> >> > On Aug 3, 8:42 pm, "Gabriel Genellina"  wrote:
> >> >> En Mon, 03 Aug 2009 11:04:07 -0300, IronyOfLife  
> >>   
> >> >> escribió:
>
> >> >> > I have installed python 2.6.2 in windows xp professional machine. I
> >> >> > have set the following environment variables -- PYTHONPATH. It  
> >> points
> >> >> > to following windows folders: python root folder, the lib folder  
> >> and
> >> >> > lib-tk folder.
>
> >> >> Why? Did you read it somewhere? Usually there is no need to set the  
> >> >> PYTHONPATH variable at all; remove it.
>
> >> > Setting PYTHONPATH environment variables is mentioned in Python docs.
>
> >> Could you provide a link please? Setting PYTHONPATH should not be
>
> > Here are couple of links that discusses setting PYTHONPATH environment
> > variable.
> >http://docs.python.org/using/windows.html
>
> Ouch, that document should be reworked and updated!
>
> >http://www.daimi.au.dk/~chili/PBI/pythonpath.html
>
> That's mostly obsolete for current versions. Since PEP370 [0] was  
> implemented, a per-user private directory is already in sys.path now, so  
> there is no need to play with PYTHONPATH.

Thanks for the clarification on PYTHONPATH.
>
> > I understand your concerns regarding setting of PYTHONPATH while
> > multiple versions of Python are installed on the same machine. My fix
> > however does not use PYTHONPATH. The GNUTLS wrapper module for PYTHON
> > loads the GNUTLS dll's and it was not able to find them. Using FileMon
> > (win tool) I found out the paths that are scanned and I copied the
> > dlls to one of such paths. I still do not like this fix. This is a
> > temporary solution.
>
> Note that this cannot be fixed from inside Python. When you import a  
> module, the interpreter scans the directories in ITS search path  
> (sys.path) looking for a matching module. Once the module is found:
> - if it is a Python file, it's executed
> - if it is an extension module (a .pyd file, in fact a .dll renamed) it's  
> loaded using LoadLibraryEx (a Windows function), and finally its  
> initialization routine is executed.
>
> For LoadLibrary to successfully load the module, all its external  
> references must be resolved. That is, Windows must locate and load all  
> other DLLs that this module depends on, using its own search strategy [1],  
> taking into account the PATH environment variable and many other places.
>
> It is at this stage that you get the error: when the gnutls wrapper  
> attempts to load the gnutls DLL. That search is done by Windows, not by  
> Python, and PYTHONPATH has nothing to do with it.
>
> Why different results in IIS and appweb? Note that there exist several  
> search strategies, they depend on the application home directory, the  
> location of the .exe, whether SetDllDirectory was called or not, whether  
> the application has a manifest or not, a .local file or not... Hard to  
> tell with so many variables.

This is fairly easy to explain. When I configured IIS to execute
python scripts, as per the documentation I pass two command line
arguments. Appweb works this way. It opens up a new command process
and in the function parameter for environment it sets only SYSTEMROOT.
It does not set the PATH variable (A BUG IN APPWEB which I have passed
on to them. They have not commented or provided any work around) for
Windows platform.

So while loading the gnutls client script is loaded, the following
path is searched
1. gnutls\library
2. C:\windows
3. C:\WIndows\system
4. C:\WIndows\system32
5. Folder where pyhton.exe is present.

And when I use IIS, the PATH variable is also set. So in this case all
the folders in the PATH are also searched and LoadLibrary is able to
successfully find the GNUTLS related Dlls without any issues.

You were mentioning about .local file or manifest file to specify the
path. I used the python's build command to build the wrapper. Is there
a way to mention in setup.py to generate the .manifest file? I wold
very much appreciate if you can help me with that.

I will also look for answers for how to modify setup.py to generate
manifest file or .local file etc..

>
> > Can you explain maybe with some sample how to set .pth files? Maybe
> > this will resolve my issue.
>
> Yes, but I don't think this will actually help with your issue.
>
> pth files are described here [2]. Suppose you want to add c:\foo\bar to  
> sys.path, then write a file whatever.pth containing this single line:
>
> c:\foo\bar
>
> and place it on c:\your_python_installation\lib\site-packages
> When the interpreter starts, it will find the .pth file, read it, and add  
> any directory it finds (that actually exists) to sys.path
>
> Note that another Python installation w

Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Esmail

Benjamin Kaplan wrote:



I can't find tarfile.gzopen  in the tarfile docs, I'm looking here:

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

Am I looking at the wrong page?



My mistake. It isn't a function of the tarfile module, it's a class
method of tarfile.TarFile. I was looking at the help in the
interactive interpreter. It doesn't seem to be in the official docs,
but you can use pydoc to view the docstrings.


Thanks for the additional information,

Esmail

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


Re: Need help in configuration for TimedRotatingFileHandler

2009-08-10 Thread Dave Angel

Lokesh Maremalla wrote:


Code:
mlogger = logging.getLogger("simpleExample")
def a_view(request):
mlogger.debug("a_view called")
if request.method== "POST" :
mlogger.debug("post function")
else:
mlogger.debug("serve function")

Execution:
step1: Executed the code and got the log file with the information
step2: Modified the system time from current day to next day
step3: End up with the error and the error is pasted below

Traceback (most recent call last):
  File "c:\Python25\lib\logging\handlers.py", line 74, in emit
self.doRollover()
  File "c:\Python25\lib\logging\handlers.py", line 274, in doRollover
os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] The process cannot access the file because it is
being used by another process

Python version - 2.5.4

I guess my output should be like this for the next day
-a new log file rotate_test. should generate in the respective
location

Please correct me if I am wrong.


Thanks for your time.

Regards,
Lokesh

  
Generally speaking, this error on os.rename() will occur if you haven't 
properly closed the file first, and if I recall correctly, Unix would 
have permitted a rename on an open file.  You're on Windows.  However, I 
don't know how that works with the logging package.  If the program has 
terminated, and you run it a second time on the following day (or after 
changing the system time), then I'd expect no trouble.  But I'm guessing 
your program is still running, and you just want to change from logging 
to yesterday's file to logging to today's file.


If I had to guess, I'd say that you have two instances of the logger 
running, and the second one is still holding the handle open.  But 
that's just a wild guess.


Could someone else who is familiar with logging, and with 
TimedRotatingFileHandler in particular, jump in here?  Preferably a 
Windows person?


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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Scott David Daniels

Douglas Alan wrote:

So, what's the one obvious right way to express "foo\zbar"? Is it
   "foo\zbar"
or
   "foo\\zbar"
And if it's the latter, what possible benefit is there in allowing the
former?  And if it's the former, why does Python echo the latter?


Actually, if we were designing from fresh (with no C behind us), I might
advocate for "\s" to be the escape sequence for a backslash.  I don't
particularly like that it is hard to see if the following string
contains a tab:   "abc\table".  The string rules reflect C's
rules, and I see little excuse for trying to change them now.

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: With or without leading underscore...

2009-08-10 Thread Jan Kaliszewski

10-08-2009 Ulrich Eckhardt  wrote:

So, the type is a part of the public API, but its constructor is not.  
Should

I mark the type as private (with a leading underscore) or not?


IMHO you shouldn't (i.e. name should be marked "public") because of
possible usage of e.g. "isinstance(foo, YourType)".

Cheers,
*j

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Processes not exiting

2009-08-10 Thread ma3mju
On 7 Aug, 16:02, MRAB  wrote:
> ma3mju wrote:
> > On 3 Aug, 09:36, ma3mju  wrote:
> >> On 2 Aug, 21:49, Piet van Oostrum  wrote:
>
>  MRAB  (M) wrote:
>  M> I wonder whether one of the workers is raising an exception, perhaps 
>  due
>  M> to lack of memory, when there are large number of jobs to process.
> >>> But that wouldn't prevent the join. And you would probably get an
> >>> exception traceback printed.
> >>> I wonder if something fishy is happening in the multiprocessing
> >>> infrastructure. Or maybe the Fortran code goes wrong because it has no
> >>> protection against buffer overruns and similar problems, I think.
> >>> --
> >>> Piet van Oostrum 
> >>> URL:http://pietvanoostrum.com[PGP8DAE142BE17999C4]
> >>> Private email: [email protected]
> >> I don't think it's a memory problem, the reason for the hard and easy
> >> queue is because for larger examples it uses far more RAM. If I run
> >> all of workers with harder problems I do begin to run out of RAM and
> >> end up spending all my time switching in and out of swap so I limit
> >> the number of harder problems I run at the same time. I've watched it
> >> run to the end (a very boring couple of hours) and it stays out of my
> >> swap space and everything appears to be staying in RAM. Just hangs
> >> after all "poison" has been printed for each process.
>
> >> The other thing is that I get the message "here" telling me I broke
> >> out of the loop after seeing the poison pill in the process and I get
> >> all the things queued listed as output surely if I were to run out of
> >> memory I wouldn't expect all of the jobs to be listed as output.
>
> >> I have a serial script that works fine so I know individually for each
> >> example the fortran code works.
>
> >> Thanks
>
> >> Matt
>
> > Any ideas for a solution?
>
> A workaround is to do them in small batches.
>
> You could put each job in a queue with a flag to say whether it's hard
> or easy, then:
>
>      while have more jobs:
>          move up to BATCH_SIZE jobs into worker queues
>          create and start workers
>          wait for workers to finish
>          discard workers

Yeah, I was hoping for something with a bit more finesse. In the end I
used pool instead with a callback function and that has solved the
problem. I did today find this snippet;

Joining processes that use queues

Bear in mind that a process that has put items in a queue will
wait before terminating until all the buffered items are fed by the
“feeder” thread to the underlying pipe. (The child process can call
the Queue.cancel_join_thread() method of the queue to avoid this
behaviour.)

This means that whenever you use a queue you need to make sure
that all items which have been put on the queue will eventually be
removed before the process is joined. Otherwise you cannot be sure
that processes which have put items on the queue will terminate.
Remember also that non-daemonic processes will be automatically be
joined.


I don't know (not a computer scientist) but could it have been the
pipe getting full?

In case anyway else is effected by this I've attached the new code to
see the changes I made to fix it.

Thanks for all your help

Matt


parallel.py

import GaussianProcessRegression as GP
import numpy as np
import networkx as nx
import pickle
from multiprocessing import Pool

global result

def cb(r):
global result
print r
result[r[0]] = r[1]



# Things You Can Change

#savefiles
savefile = "powerlaw"
graphfile = "powerlawgraph"
#sample sizes
num_graphs = 5
num_sets_of_data = 10
#other things...
intervals = np.ceil(np.logspace(-2,1,50)*500)
noise = [np.sqrt(0.1),np.sqrt(0.01),np.sqrt(0.001),np.sqrt(0.0001)]
num_hard_workers = 5
hard_work_threshold = 4000

#generate graphs
graphs  = []
for i in range(0,num_graphs):
graphs.append(nx.powerlaw_cluster_graph(500,0.1,0.05))
#save them for later reference
filehandler = open(graphfile,'w')
pickle.dump(graphs,filehandler,-1)
filehandler.close()

#queues
easy_work = []
hard_work = []

#construct the items in the hard queue
l=0
for j in range(0,len(intervals)):
for i in range(0,len(noise)):
for k in range(0,num_graphs):
if int(intervals[j]) <=hard_work_threshold:
easy_work.append({'datapt': l,'graph': graphs
[k],'noise': noise[i],'number_of_sets_of_data':
num_sets_of_data,'number_of_data_points':int(intervals[j])})
else:
hard_work.append({'data

wxpython question

2009-08-10 Thread azrael
Is there maybe a method bounded to the class SpinCtrl() that could
hide the widget. One that is maybe also implemented in any other
control.

self.spcKvadDo = wx.SpinCtrl(id=-1, initial=0, max=100, min=0,
name='spcKvadDo', parent=self.pnlFilteri, pos=wx.Point(10, 10),
size=wx.Size(118, 21), style=wx.SP_ARROW_KEYS)

self.spcKvadOd.XXX()

I tried it with the SetTransparent() method but it did not work. Has
anyone any Idea?
-- 
http://mail.python.org/mailman/listinfo/python-list


Florida Python training in October

2009-08-10 Thread Mark Lutz
We're pleased to announce a new venue for our Python classes.
Python author and trainer Mark Lutz will be teaching a 3-day
Python class on October 20-22, in Sarasota, Florida.  Come
spend 3 days mastering Python, and enjoy all that Florida and
its Gulf Coast have to offer while you're here.

This is a public training session open to individual enrollments,
and covers the same topics and hands-on lab work as the over 200
onsite sessions that Mark has taught.  The class provides an
in-depth introduction to both Python and its common applications,
and parallels the instructor's best-selling Python books.

This class is also newly retooled to cover recent changes in
both Python 2.6 and 3.1.  Whether you're using 2.X, using 3.X,
or stuck somewhere between them, you'll find that our class is
aimed at your needs.  For more information on this session,
please visit its web page:

http://home.earthlink.net/~python-training/2009-public-classes.htm

For additional background on the class itself, as well as a
preview of our 2010 Florida class schedule, see our home page:

http://home.earthlink.net/~python-training

Thanks for your interest,
--Mark Lutz's Python Training Services
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compression level with tarfile (w:gz) ?

2009-08-10 Thread Esmail

Hi Lars,

Lars Gustäbel wrote:


How much smaller is it? I did a test with a recent Linux kernel source tree
which made an archive of 337MB. Command-line gzip was ahead of Python's
GzipFile() by just 20200 bytes(!) with an archive of about 74MB.


Is the only way to accomplish the higher rate to create a tar file
and then use a different module to gzip it (assuming I can specify
the compression level there)?


If you need the disk space that badly, the alternative would be to pipe
tarfile's output to command-line gzip somehow:


Thanks for the additional info and the workaround. I was mostly just
curious if there was a way to specify the compression level, so far
I'm ok with the generated file sizes, but it's good to know that there
are other options to specify my own compression level.

Thanks again,

Esmail

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


Re: reloading the module imported as 'from ... import ...'

2009-08-10 Thread Piet van Oostrum
> Steven D'Aprano  (SD) wrote:

>SD> On Sun, 09 Aug 2009 22:48:31 -0700, AlF wrote:
>>> Steven D'Aprano wrote:
 On Sun, 09 Aug 2009 20:43:41 -0700, AlF wrote:
 
> Hi,
> 
> what is the best way to reload the module imported using 'from ...
> import ...'
 
 
 Have you tried "from ... import ..." again?
 
 
>>> I have not because of an assumption that "import" imports the module
>>> just once. 

>SD> Ah, of course the cached module will still reflect the older version. 
>SD> Sorry, I was thinking about solving a different problem:

If you do a reload in between the cached version is replaced by the new
version. However, objects from the old module that have references
before the reload will still lie around. This could cause very subtle
bugs.

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import testmod
>>> from testmod import TestClass
>>> a = TestClass()
>>> b = TestClass()
>>> a.__class__ is b.__class__
True
>>> reload(testmod)

>>> c = TestClass()
>>> c.__class__ is a.__class__
True
>>> from testmod import TestClass
>>> d = TestClass()
>>> d.__class__ is a.__class__
False

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


variable & scoping question.

2009-08-10 Thread Cornelius Keller
Hi,

I'm a quite fresh python programmer, (6 Month python experience).
Today I found something I absolotly don'nt understand:

given the following function:

def test_effect(class_id=None,class_ids=[]):
if class_id is not None:
if class_id not in class_ids:
class_ids.append(int(class_id))

print class_ids

I observe that the class_ids array is growing when it is called with
different class id's.

I expected class_ids to be [] if the keyword argument is not set, but
it seems to beahve like a static variable if not set.

example:


In [3]: test.test_effect(class_id=1)
[1]

In [4]: test.test_effect(class_id=1)
[1]

In [5]: test.test_effect(class_id=2)
[1, 2]

In [6]: test.test_effect(class_id=2)
[1, 2]

In [7]: test.test_effect(class_id=3)
[1, 2, 3]

Is this an intended python beahviour?

sincerly
- Cornelius




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


Re: variable & scoping question.

2009-08-10 Thread Diez B. Roggisch
Cornelius Keller wrote:

> Hi,
> 
> I'm a quite fresh python programmer, (6 Month python experience).
> Today I found something I absolotly don'nt understand:
> 
> given the following function:
> 
> def test_effect(class_id=None,class_ids=[]):
>     if class_id is not None:
>         if class_id not in class_ids:
>             class_ids.append(int(class_id))
> 
>     print class_ids
> 
> I observe that the class_ids array is growing when it is called with
> different class id's.
> 
> I expected class_ids to be [] if the keyword argument is not set, but
> it seems to beahve like a static variable if not set.

http://effbot.org/zone/default-values.htm

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


Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-10 Thread r
On Aug 9, 11:02 pm, David Lyon  wrote:
> Since you're talking about documentation, which is a part of python,
> don't you think you should be discussing it on python-dev ?

Yea, them's be a friendly bunch to noob ideas ;). Hey i got a better
idea, lets go to the IRS and see if we can persuade them to stop
taxing us...

> That's where discussions about the documentation should be held.
> haha - I'm just curious to see how long it will for them to
> shut the discussion down.

Yea, probably not long at all, of course not before the troll calling,
bulling, defamation of character, etc, has lost it's fun.

> Before you do that, you should clearly work out in your own mind
> how you think things need to improve. It's not good enough just
> saying this or that is bad without having specific ideas on what
> needs to change.

see links that xah posted, and there is more he did not post.

> Good luck fellow sinner and blasphemer...
> How dare you suggest that things could be improved...

how dare YOU suggest they NOT be improved!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Douglas Alan
On Aug 10, 10:58 am, Scott David Daniels 
wrote:

> The string rules reflect C's rules, and I see little
> excuse for trying to change them now.

No they don't. Or at least not C++'s rules. C++ behaves exactly as I
should like.

(Or at least g++ does. Or rather *almost* as I would like, as by
default it generates a warning for "foo\zbar", while I think that an
error would be somewhat preferable.)

But you're right, it's too late to change this now.

|>ouglas

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


Re: setting Referer for urllib.urlretrieve

2009-08-10 Thread samwyse
On Aug 9, 9:41 am, Steven D'Aprano  wrote:
> On Sun, 09 Aug 2009 06:13:38 -0700,samwysewrote:
> > Here's what I have so far:
>
> > import urllib
>
> > class AppURLopener(urllib.FancyURLopener):
> >     version = "App/1.7"
> >     referrer = None
> >     def __init__(self, *args):
> >         urllib.FancyURLopener.__init__(self, *args)
> >         if self.referrer:
> >             addheader('Referer', self.referrer)
>
> > urllib._urlopener = AppURLopener()
>
> > Unfortunately, the 'Referer' header potentially varies for each url that
> > I retrieve, and the way the module is written, I can't change the calls
> > to __init__ or open. The best idea I've had is to assign a new value to
> > my class variable just before calling urllib.urlretrieve(), but that
> > just seems ugly.  Any ideas?  Thanks.
>
> [Aside: an int variable is an int. A str variable is a str. A list
> variable is a list. A class variable is a class. You probably mean a
> class attribute, not a variable. If other languages want to call it a
> variable, or a sausage, that's their problem.]
>
> If you're prepared for a bit of extra work, you could take over all the
> URL handling instead of relying on automatic openers. This will give you
> much finer control, but it will also require more effort on your part.
> The basic idea is, instead of installing openers, and then ask the urllib
> module to handle the connection, you handle the connection yourself:
>
> make a Request object using urllib2.Request
> make an Opener object using urllib2.build_opener
> call opener.open(request) to connect to the server
> deal with the connection (retry, fail or read)
>
> Essentially, you use the Request object instead of a URL, and you would
> add the appropriate referer header to the Request object.
>
> Another approach, perhaps a more minimal change than the above, would be
> something like this:
>
> # untested
> class AppURLopener(urllib.FancyURLopener):
>     version = "App/1.7"
>     def __init__(self, *args):
>         urllib.FancyURLopener.__init__(self, *args)
>     def add_referrer(self, url=None):
>         if url:
>             addheader('Referer', url)
>
> urllib._urlopener = AppURLopener()
> urllib._urlopener.add_referrer("http://example.com/";)

Thanks for the ideas.  I'd briefly considered something similar to
your first idea, implementing my own version of urlretrieve to accept
a Request object, but it does seem like a good bit of work.  Maybe
over Labor Day.  :)

The second idea is pretty much what I'm going to go with for now.  The
program that I'm writing is almost a clone of wget, but it fixes some
personal dislikes with the way recursive retrievals are done.  (Or
maybe I just don't understand wget's full array of options well
enough.)  This means that my referrer changes as I bounce up and down
the hierarchy, which makes this less convenient.  Still, it does seem
more convenient that re-writing the module from scratch.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processes not exiting

2009-08-10 Thread MRAB

ma3mju wrote:

On 7 Aug, 16:02, MRAB  wrote:

ma3mju wrote:

On 3 Aug, 09:36, ma3mju  wrote:

On 2 Aug, 21:49, Piet van Oostrum  wrote:

MRAB  (M) wrote:

M> I wonder whether one of the workers is raising an exception, perhaps due
M> to lack of memory, when there are large number of jobs to process.

But that wouldn't prevent the join. And you would probably get an
exception traceback printed.
I wonder if something fishy is happening in the multiprocessing
infrastructure. Or maybe the Fortran code goes wrong because it has no
protection against buffer overruns and similar problems, I think.
--
Piet van Oostrum 
URL:http://pietvanoostrum.com[PGP8DAE142BE17999C4]
Private email: [email protected]

I don't think it's a memory problem, the reason for the hard and easy
queue is because for larger examples it uses far more RAM. If I run
all of workers with harder problems I do begin to run out of RAM and
end up spending all my time switching in and out of swap so I limit
the number of harder problems I run at the same time. I've watched it
run to the end (a very boring couple of hours) and it stays out of my
swap space and everything appears to be staying in RAM. Just hangs
after all "poison" has been printed for each process.
The other thing is that I get the message "here" telling me I broke
out of the loop after seeing the poison pill in the process and I get
all the things queued listed as output surely if I were to run out of
memory I wouldn't expect all of the jobs to be listed as output.
I have a serial script that works fine so I know individually for each
example the fortran code works.
Thanks
Matt

Any ideas for a solution?

A workaround is to do them in small batches.

You could put each job in a queue with a flag to say whether it's hard
or easy, then:

 while have more jobs:
 move up to BATCH_SIZE jobs into worker queues
 create and start workers
 wait for workers to finish
 discard workers


Yeah, I was hoping for something with a bit more finesse. In the end I
used pool instead with a callback function and that has solved the
problem. I did today find this snippet;

Joining processes that use queues

Bear in mind that a process that has put items in a queue will
wait before terminating until all the buffered items are fed by the
“feeder” thread to the underlying pipe. (The child process can call
the Queue.cancel_join_thread() method of the queue to avoid this
behaviour.)

This means that whenever you use a queue you need to make sure
that all items which have been put on the queue will eventually be
removed before the process is joined. Otherwise you cannot be sure
that processes which have put items on the queue will terminate.
Remember also that non-daemonic processes will be automatically be
joined.


I don't know (not a computer scientist) but could it have been the
pipe getting full?

In case anyway else is effected by this I've attached the new code to
see the changes I made to fix it.


[snip]
Maybe the reason is this:

Threads share an address space, so putting data into a queue simply
involves putting a reference there, but processes don't share an address
space, so a sender must continue to exist until the data itself has been
copied into the pipe that connects the processes. This pipe has a
limited capacity.

In your code you were waiting for the easy workers to terminate and you
weren't reading from the queue, and maybe, therefore, the pipe either,
so with a large number of jobs the pipe was becoming full.

In summary: the worker didn't terminate because the pipe was full; the
pipe was full because you weren't reading the results; you weren't
reading the results because the worker hadn't terminated.
--
http://mail.python.org/mailman/listinfo/python-list


Re: variable & scoping question.

2009-08-10 Thread Francesco Bochicchio
On Aug 10, 5:12 pm, "Diez B. Roggisch"  wrote:
> Cornelius Keller wrote:
> > Hi,
>
> > I'm a quite fresh python programmer, (6 Month python experience).
> > Today I found something I absolotly don'nt understand:
>
> > given the following function:
>
> > def test_effect(class_id=None,class_ids=[]):
> >     if class_id is not None:
> >         if class_id not in class_ids:
> >             class_ids.append(int(class_id))
>
> >     print class_ids
>
> > I observe that the class_ids array is growing when it is called with
> > different class id's.
>
> > I expected class_ids to be [] if the keyword argument is not set, but
> > it seems to beahve like a static variable if not set.
>
> http://effbot.org/zone/default-values.htm
>
> Diez

Maybe on the first page of python.org there should be a 'python
gotchas' link to a page listing these few
non-intuituive peculiarities of our beloved snake ... same goes for
the official python tutorial ...

Ciao
-
FB

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


Re: variable & scoping question.

2009-08-10 Thread Cornelius Keller
On 10 Aug., 17:12, "Diez B. Roggisch"  wrote:
> Cornelius Keller wrote:
[snip]
>
> http://effbot.org/zone/default-values.htm
>
> Diez

Ok thank you.
I' understand now why.
I still think this is very confusing, because default values don't
behave like most people would expect without reading the docs.

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


Re: M2Crypto: How to generate subjectKeyIdentifier / authorityKeyIdentifier

2009-08-10 Thread Matthias Güntert
Now I have this patch applied to the M2Crypto SVN branch 


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


Re: Problem Regarding Handling of Unicode string

2009-08-10 Thread Piet van Oostrum
> joy99  (j) wrote:

>j> Dear Group,
>j> I am using Python26 on WindowsXP with service pack2. My GUI is IDLE.
>j> I am using Hindi resources and get nice output like:
>j> एक
>j> where I can use all the re functions and other functions without doing
>j> any transliteration,etc.
>j> I was trying to use Bengali but it is giving me output like:
>j> '\xef\xbb\xbf\xe0\xa6\x85\xe0\xa6\xa8\xe0\xa7\x87\xe0\xa6\x95'
>j> I wanted to see Bengali output as
>j> অনেক
>j> and I like to use all functions including re.
>j> If any one can help me on that.
>j> Best Regards,
>j> Subhabrata.

Make sure your stdout (in case you use print) has utf-8 encoding. This
might be problematic on Windows, however.

>>> print '\xef\xbb\xbf\xe0\xa6\x85\xe0\xa6\xa8\xe0\xa7\x87\xe0\xa6\x95'
অনেক

Or if you write to a file, open it with utf-8 encoding.

I take utf-8 because in general this is the preferred encoding for
non-ASCII text. It could be that Bengali has a different preferred encoding.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client/Server based on SocketServer and Windows

2009-08-10 Thread Dave Angel

Kiki wrote:

Thank you Dennis

I'm using 2 differents editor, which may be the cause of such a mess
in the indentation.

I must admitt that I lazily rely on those (not so bad indeed) editors.

"If indentation whas bad they would have tell me"

Too bad am i

Won't post misindeted code anymore.

  
No problem using multiple editors.  But you need to configure each one 
to *never* put tabs in the file (it should use spaces exclusively).  If 
you can't do that in one of the editors, then use the other editor 
exclusively.


Other useful but not mandatory features -
   - when tab is pressed, it should indent using spaces, to a multiple 
of 4 columns.
   - by default, indent a new line the same as the previous, or even 
based on the previous plus some syntax rules.
   - make tabs and/or spaces visible, so you can tell if the file has a 
mixture.


DaveA
 
--

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


Re: www.python.org website is down?

2009-08-10 Thread r
On Aug 10, 9:13 am, MRAB  wrote:
> r wrote:
> > On Aug 8, 8:48 am, MRAB  wrote:
> > ...(snip)
> >> Bothwww.python.organdsvn.python.org are down.  They're hosted on
> >> the same machine, and it seems to have run into disk problems and
> >> hasn't rebooted even after power-cycling.  Thomas Wouters will be
> >> visiting the machine physically tomorrow to try to diagnose the
> >> problem.
>
> > Oh stop lying MRAB, everybody knows Guido hosts Python.org from his
> > attic on an old Linux box :-)
>
> That was a quote from A.M. Kuchling.
>
> It's actually hosted on a matchbox-sized multi-core multi-terabyte
> wifi-enabled Linux machine that Guido brought back from 2050.
> Unfortunately, the dog ate it, so he's had to go and buy another one!
> :-)

i just hope he gets one that has supported wifi drivers available! :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: M2Crypto: How to generate subjectKeyIdentifier / authorityKeyIdentifier

2009-08-10 Thread Matthias Güntert
Hello once again

Now I have the extension-patch [0] applied to the M2Crypto SVN branch
(revision 704). Creating a root and an subRoot CA certificate now works
great including the SKID/AKID extensions. 

I am also able to verify those created certificates using:

$ openssl verify -CAfile rootCA.crt rootCA.crt 
rootCA.crt: OK

$ openssl verify -CAfile rootCA.crt subRootCA.crt 
subRootCA.crt: OK

But having a closer look onto the generated key ID's shows that there is
either something wrong in the way I am adding the subjectKeyIdentifier
extension or the way the hash gets calculated in the background. 

This are the hashes:

__rootCA__  
SKID F4:EF:64:5F:7A:A2:2A:14:14:F9:AE:6E:DB:04:78:0A:8C:6E:02:9F -: A
--> OKAY
AKID F4:EF:64:5F:7A:A2:2A:14:14:F9:AE:6E:DB:04:78:0A:8C:6E:02:9F -: A
--> OKAY

__subRootCA (signed by rootCA)__
SKID DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09 -: B
--> OKAY
AKID F4:EF:64:5F:7A:A2:2A:14:14:F9:AE:6E:DB:04:78:0A:8C:6E:02:9F -: A
--> OKAY

__client (signed by rootCA)__
SKID DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09 -: B
--> NOT OKAY, should be different from RootCA
AKID F4:EF:64:5F:7A:A2:2A:14:14:F9:AE:6E:DB:04:78:0A:8C:6E:02:9F -: A
--> OKAY

__client (signed by subRootCA)__
SKID DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09 -: B
--> NOT OKAY, should be different from subRootCA
AKID DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09 -: B
--> OKAY

I really would be happy if someone could have a look at my code [1] as
this extensions are important for verifying the trust chain. Please let
me know if there is anything I can do with my limited knowledge about
OpenSSL to get this working... 

Regards, Matthias 

[0] https://bugzilla.osafoundation.org/attachment.cgi?id=5106
[1] http://code.google.com/p/webca/source/browse/trunk/src/ca.py


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


Re: Problem when fetching page using urllib2.urlopen

2009-08-10 Thread dorzey
"geturl - this returns the real URL of the page fetched. This is
useful because urlopen (or the opener object used) may have followed a
redirect. The URL of the page fetched may not be the same as the URL
requested." from 
http://www.voidspace.org.uk/python/articles/urllib2.shtml#info-and-geturl

It might be worth checking that you are actually getting the page you
want; I seem to remember that semicolons need to be encoded, similar
to '&'.

Dorzey

On Aug 10, 12:43 pm, jitu  wrote:
> On Aug 10, 4:39 pm, jitu  wrote:
>
> > Hi,
>
> > A html page  contains 'anchor' elements with 'href' attribute  having
> > a semicolon  in the url , while fetching the page using
> > urllib2.urlopen, all such href's  containing  'semicolons' are
> > truncated.
>
> > For example the 
> > hrefhttp://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt...
> > get truncated 
> > tohttp://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i
>
> > The page I am talking about can be fetched 
> > fromhttp://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_...
>
> > Thanks a Lot
> > Regards
> > jitu
>
> Hi
>
>    Sorry, the question what I wanted to ask was, whether is this the
> correct behaviour or a bug ?
>
> Thanks A Lot.
> Regards
> jitu

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


Re: variable & scoping question.

2009-08-10 Thread MRAB

Francesco Bochicchio wrote:

On Aug 10, 5:12 pm, "Diez B. Roggisch"  wrote:

Cornelius Keller wrote:

Hi,
I'm a quite fresh python programmer, (6 Month python experience).
Today I found something I absolotly don'nt understand:
given the following function:
def test_effect(class_id=None,class_ids=[]):
if class_id is not None:
if class_id not in class_ids:
class_ids.append(int(class_id))
print class_ids
I observe that the class_ids array is growing when it is called with
different class id's.
I expected class_ids to be [] if the keyword argument is not set, but
it seems to beahve like a static variable if not set.

http://effbot.org/zone/default-values.htm

Diez


Maybe on the first page of python.org there should be a 'python
gotchas' link to a page listing these few
non-intuituive peculiarities of our beloved snake ... same goes for
the official python tutorial ...


Should they be called 'snake bites'? Well, pythons are constrictors, not
biters, but if Python is being non-intuitive... :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: resume upload wsgi script

2009-08-10 Thread gert
On Aug 10, 10:39 am, "Diez B. Roggisch"  wrote:
> > 250KB :)
>
> So why do you bother?
>
> > Its just HTTP1.1 has everything for making ftp like file transfers
> > possible.
> > When I write it to a file then I am back at square one because I still
> > need to load it completely to get it into a blob.
>
> Well, the blob is nothing but datat in the file-system. If you are
> *really* concerned about that, then don't use the db, but use the
> filesystem, appending to the file until it's finished - and storing a
> reference to it to the DB. We do that as well, because otherwise the db
> will become unmanagable anyway (dumping, backups).
>

I also hate debugging sql that contains blob data. So if using files
how do you clean the http post stuff?
(b+r'.*?Content-Type: application/octet-stream\r\n\r\n(.*?)\r
\n--'+b,file,DOTALL)
using as litlle memory as possible ?
I can not use PUT upload only because flash does not support PUT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variable & scoping question.

2009-08-10 Thread Ethan Furman

Cornelius Keller wrote:
[snip]


I still think this is very confusing, because default values don't
behave like most people would expect without reading the docs.

- Cornelius


Why would you expect to become a good programmer of _any_ language 
without reading its docs?


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


Re: reloading the module imported as 'from ... import ...'

2009-08-10 Thread William
What about using the reimport library?

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

Cheers,
William




From: AlF 
To: [email protected]
Sent: Monday, August 10, 2009 1:48:31 AM
Subject: Re: reloading the module imported as 'from ... import ...'

Steven D'Aprano wrote:
> On Sun, 09 Aug 2009 20:43:41 -0700, AlF wrote:
> 
>> Hi,
>> 
>> what is the best way to reload the module imported using 'from ...
>> import ...'
> 
> 
> Have you tried "from ... import ..." again?
> 

I have not because of an assumption that "import" imports the module just once. 
In fact this still works that way:

here is a terminal 1:

$ cat > a.py
a=1
$ cat > a.py
a=2
$


and terminal 2:

>>> from a import a
>>> a
1
>>> a
1
>>> from a import a
>>> a
1
>>>

In spite of changing a.py in fly, the imported a is still 1


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



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


Re: With or without leading underscore...

2009-08-10 Thread Carl Banks
On Aug 10, 7:37 am, Ulrich Eckhardt  wrote:
> ...that is the question!
>
> I have a module which exports a type. It also exports a function that
> returns instances of that type. Now, the reason for my question is that
> while users will directly use instances of the type, they will not create
> instances of the type themselves.
>
> So, the type is a part of the public API, but its constructor is not. Should
> I mark the type as private (with a leading underscore) or not?


I would not use the underscore.

If the initializer is private you might consider dispensing with
__init__ (have it raise TypeError), and initialize it from a "private"
method or classmethod, or even directly from the factory function.
And if you're wondering how the hell you're going to create the object
of type A when you've disabled __init__, see the example classmethod
below.


class A(object):
def __init__(self,*args,**kwargs):
raise TypeError('Type not callable; use factory function
instead')

@classmethod
def _create_object(cls,initial_value):
self = object.__new__(cls) # avoid __init__
self.value = initial_value



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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Carl Banks
On Aug 10, 4:41 am, MRAB  wrote:
> Steven D'Aprano wrote:
> > On Sun, 09 Aug 2009 17:56:55 -0700, Douglas Alan wrote:
>
> [snip]
> >> My point of view is that
> >> every language has *some* warts; Python just has a bit fewer than most.
> >> It would have been nice, I should think, if this wart had been "fixed"
> >> in Python 3, as I do consider it to be a minor wart.
>
> > And if anyone had cared enough to raise it a couple of years back, it
> > possibly might have been.
>
> My preference would've been that a backslash followed by A-Z, a-z, or
> 0-9 is special, but a backslash followed by any other character is just
> the character, except for backslash followed by a newline, which
> suppresses the newline.

That would be reasonable; it'd match the behavior of regexps.


Carl Banks

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


how to use "exec" stmt to get input from user

2009-08-10 Thread Rick King
I have a cmd.py-derived program (with a wxPython GUI) and want to 
execute python statements for lines that are not my own special commands.


So basically it's either:

   def do_somecommand(self,arg):
   ...

or

   def default(self,arg):
   exec arg in globals(),self.cmdlocals

(where cmdlocals is a my local dictionary)

in default() I'd like to be able to execute any python statement 
including something like


   "x = raw_input('>')"

when I do this though it goes to the command window and so any user of 
the program would be confused, which also means I have to have a command 
window.


If I add this:

   self.stdin = self.edt_console_input   (where self.edt_console_input 
is a wxPython text control)


it just gets an EOF right away.

Is there any way to do what I want to do? This might be better posted on 
the wxpython list.


Thanks for any help!

Rick King
Southfield MI


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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Carl Banks
On Aug 10, 1:37 am, Steven D'Aprano
 wrote:
> On Mon, 10 Aug 2009 00:37:33 -0700, Carl Banks wrote:
> > On Aug 9, 11:10 pm, Steven D'Aprano
> >  wrote:
> >> On Sun, 09 Aug 2009 18:34:14 -0700, Carl Banks wrote:
> >> >> Why should a backslash in a string literal be an error?
>
> >> > Because the behavior of \ in a string is context-dependent, which
> >> > means a reader can't know if \ is a literal character or escape
> >> > character without knowing the context, and it means an innocuous
> >> > change in context can cause a rather significant change in \.
>
> >> *Any* change in context is significant with escapes.
>
> >> "this \nhas two lines"
>
> >> If you change the \n to a \t you get a significant difference. If you
> >> change the \n to a \y you get a significant difference. Why is the
> >> first one acceptable but the second not?
>
> > Because when you change \n to \t, you've haven't changed the meaning of
> > the \ character;
>
> I assume you mean the \ character in the literal, not the (non-existent)
> \ character in the string.
>
> > but when you change \n to \y, you have, and you did so
> > without even touching the backslash.
>
> Not at all.
>
> '\n' maps to the string chr(10).
> '\y' maps to the string chr(92) + chr(121).
>
> In both cases the backslash in the literal have the same meaning: grab
> the next token (usually a single character, but not always), look it up
> in a mapping somewhere, and insert the result in the string object being
> built.

That is a ridiculous rationalization.  Nobody sees "\y" in a string
and thinks "it's an escape sequence that returns the bytes '\y'".


[snip rest, because an argument in favor inconsistent, context-
dependent behavior doesn't need any further refutation than to point
out that it is an argument in favor of inconsistent, context-dependent
behavior]


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


Python documentation servers

2009-08-10 Thread Roy Hyunjin Han
Are there issues with the python documentation servers?
http://docs.python.org/
The site has been really slow to respond all weekend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython question

2009-08-10 Thread David
Il Mon, 10 Aug 2009 07:55:42 -0700 (PDT), azrael ha scritto:

> Is there maybe a method bounded to the class SpinCtrl() that could
> hide the widget. One that is maybe also implemented in any other
> control.

AFAIK, any widget can be made invisibile calling the .Show(False) method of
the container sizer.
http://docs.wxwidgets.org/stable/wx_wxsizer.html#wxsizershow

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


Re: how to use "exec" stmt to get input from user

2009-08-10 Thread David C Ullrich
What you're trying to do and what's not working isn't 
entirely clear to me.

But if I had a wxPython application and I wanted to
execute user input (note the _if_) I'd just pop up a window
(I forget how "ShowModal" is spelled in wx right now)
with a text box and an Execute button and a Cancel
button - if the user hits the Execute button I'd
attempt to execute what he'd typed in the box.

There are reasons you want to be very careful about
this...

On Mon, 10 Aug 2009 13:44:17 -0400, Rick King wrote:

> I have a cmd.py-derived program (with a wxPython GUI) and want to
> execute python statements for lines that are not my own special
> commands.
> 
> So basically it's either:
> 
> def do_somecommand(self,arg):
> ...
> 
> or
> 
> def default(self,arg):
> exec arg in globals(),self.cmdlocals
> 
> (where cmdlocals is a my local dictionary)
> 
> in default() I'd like to be able to execute any python statement
> including something like
> 
> "x = raw_input('>')"
> 
> when I do this though it goes to the command window and so any user of
> the program would be confused, which also means I have to have a command
> window.
> 
> If I add this:
> 
> self.stdin = self.edt_console_input   (where self.edt_console_input
> is a wxPython text control)
> 
> it just gets an EOF right away.
> 
> Is there any way to do what I want to do? This might be better posted on
> the wxpython list.
> 
> Thanks for any help!
> 
> Rick King
> Southfield MI

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


Re: pybotwar-0.5

2009-08-10 Thread r
On Aug 9, 9:46 pm, Mensanator  wrote:
> On Aug 9, 3:26 pm, Lee Harr  wrote:
>
> > pybotwar is a fun and educational game where players
> > create computer programs to control simulated robots
> > to compete in a battle arena.
>
> >http://pybotwar.googlecode.com/
>
> Why is the doc folder empty?
>
> Shouldn't you supply some hint on how the games works
> and at least a rudimentary guide to robot design?
>
> What version to you expect that will be in? 1.0? 10.0?
>
> Could you inform us when you have something worth looking
> at and not before so we don't have to waste our time?

What a bombastically stupid thing to say even for you "Menstrual
cycle". Sure, there is no documentation but maybe the creator meant
for this module to be used only by experienced Python programmers and
not script kiddies like yourself who need a four page tut just to code
up a hello world.py. If you are anything more than an amateur the
source code should be all the documentation you need to use this
module. If not, get on with your pathetic life!

Next time before you open your mouth, try to use those two brain cells
you have left up there and put together a reasonable and responsible
response that is more than just a cowardly put down. Now run along
little spam bot, i am sure one of the other thousands of groups you
post to can't wait for your triumphant return!

r "slayer of the galactic-ly stupid!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: variable & scoping question.

2009-08-10 Thread J. Cliff Dyer
On Mon, 2009-08-10 at 08:46 -0700, Cornelius Keller wrote:
> On 10 Aug., 17:12, "Diez B. Roggisch"  wrote:
> > Cornelius Keller wrote:
> [snip]
> >
> > http://effbot.org/zone/default-values.htm
> >
> > Diez
> 
> Ok thank you.
> I' understand now why.
> I still think this is very confusing, because default values don't
> behave like most people would expect without reading the docs.
> 
> - Cornelius

You are correct.  This is confusing at first blush.  The important thing
to remember is: *don't do that.*  Learn the pythonic workaround of using
None in your parameters whenever you want a default empty list, and
don't let it bother you too much.  Overall, python is a remarkably well
designed language.  This is one of the relatively rare warts that crept
in because it enables a broader cleanliness of design.

Cheers,
Cliff


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


Re: pybotwar-0.5

2009-08-10 Thread Mark Lawrence

[snip]

r "slayer of the galactic-ly stupid!"
Can I assume from this that you intend killing yourself, on the grounds 
that some 10 days ago you couldn't successfully use a windows compiled 
help file?

--
Kindest regards.

Mark Lawrence.

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


Re: Python documentation servers

2009-08-10 Thread r
On Aug 10, 12:53 pm, Roy Hyunjin Han
 wrote:
> Are there issues with the python documentation servers?http://docs.python.org/
> The site has been really slow to respond all weekend.

try this thread
http://groups.google.com/group/comp.lang.python/browse_thread/thread/052368a71f2a8ad2/929bd74bd203c6e8?hl=en&lnk=raot8

PS Just ignore the OT humor near the bottom ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem when fetching page using urllib2.urlopen

2009-08-10 Thread Piet van Oostrum
> jitu  (j) wrote:

>j> Hi,
>j> A html page  contains 'anchor' elements with 'href' attribute  having
>j> a semicolon  in the url , while fetching the page using
>j> urllib2.urlopen, all such href's  containing  'semicolons' are
>j> truncated.


>j> For example the href 
>http://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt=AlWSqpkpqhICp1lMgChtJkCdGWoL
>j> get truncated to 
>http://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i

>j> The page I am talking about can be fetched from
>j> 
>http://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_ylc=X3oDMTFka28zOGNuBF9TAzI3NjY2NzkEX3MDOTY5NTUzMjUEc2VjA3NzcC1kZXN0BHNsawN0aXRsZQ--

It's not python that causes this. It is the server that sends you the
URLs without these parameters (that's what they are).

To get them you have to tell the server that you are a respectable
browser. E.g.

import urllib2

url = 
'http://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt=AlWSqpkpqhICp1lMgChtJkCdGWoL'

url = 
'http://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_ylc=X3oDMTFka28zOGNuBF9TAzI3NjY2NzkEX3MDOTY5NTUzMjUEc2VjA3NzcC1kZXN0BHNsawN0aXRsZQ--'

hdrs = {'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13',
   'Accept': 'image/*'}

request = urllib2.Request(url = url, headers = hdrs)
page = urllib2.urlopen(request).read()

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: www.python.org website is down?

2009-08-10 Thread Piet van Oostrum
> MRAB  (M) wrote:

>M> r wrote:
>>> On Aug 8, 8:48 am, MRAB  wrote:
>>> ...(snip)
 Bothwww.python.organd svn.python.org are down.  They're hosted on
 the same machine, and it seems to have run into disk problems and
 hasn't rebooted even after power-cycling.  Thomas Wouters will be
 visiting the machine physically tomorrow to try to diagnose the
 problem.
>>> 
>>> Oh stop lying MRAB, everybody knows Guido hosts Python.org from his
>>> attic on an old Linux box :-)

>M> That was a quote from A.M. Kuchling.

>M> It's actually hosted on a matchbox-sized multi-core multi-terabyte
>M> wifi-enabled Linux machine that Guido brought back from 2050.
>M> Unfortunately, the dog ate it, so he's had to go and buy another one!

The 2050 models can run on the internal heat of a dog !!
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-10 Thread Ethan Furman

Kee Nethery wrote:
As someone trying to learn the language I want to say that the tone on  
this list towards people who are trying to learn Python  feels like it  
has become anti-newbies.


Learning a new language is difficult enough without seeing other  
newbies getting shamed for not knowing everything there is to know  
about Python before asking their questions.


For example, the guy who was looking for Python sample code for the  
Google Map API, calling him a troll was harsh. Suggesting he broach  the 
question to Google was a reasonable answer. By the same token, his  
asking this list about the missing Python examples seems reasonable  
also. Seems to me that people on a Python list might have some  
background knowledge or even samples of the Google Python code that  was 
no longer on the Google web site.


There seems to be a general consensus among the newbies that other  
languages have a user contributions resource tied to the main official  
docs to allow newbies to teach each other what they have learned. The  
desire is for python.org to have the same kind of support resource so  
that us newbies can self support each other.


Kee Nethery


As someone who is (hopefully!) leaving newbieness I can say I have had 
no problem with the helpfullness of this list.  I will also say that 
before I ever posted any questions I had devoured Dive Into Python and 
How To Think Like a Computer Scientist Using Python (both excellent), 
and I try to put as much detail into my questions as I can so nobody has 
to guess what I'm trying to do.


As someone who relies heavily on the docs I will also say that the idea 
of giving the ability to modify the official documentation to somebody 
who is /learning/ the language is, quite frankly, terrifying.  I have no 
issues with a seperate system, some of which have been suggested, but 
good reference documentation is crucial.  If you find examples lacking, 
there are plenty of web-sites, or even (dare I say it?) actual hard-copy 
books!  ;)  My bookshelf currently has Learning Python, Programming 
Python, Python Cookbook, Python Programming on Win32, and Regular 
Expressions.  All great books, and not too pricey if you can get them used.


My $0.02.

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


Re: Python docs disappointing - group effort to hire writers?

2009-08-10 Thread r
On Aug 10, 11:13 am, Ethan Furman  wrote:
(snip)
> As someone who relies heavily on the docs I will also say that the idea
> of giving the ability to modify the official documentation to somebody
> who is /learning/ the language is, quite frankly, terrifying.
(snip)

Ethan,
I think what you and a few others seem to miss is ... Of course nobody
wants Joe-Noob writing the Python docs -- thats lunacy, would you give
your 12 year old the keys to a shiny new corvette? -- No! What people
are asking for is the ability for a noobs input on the official docs,
and for that input to be taken seriously. Sure some of the suggestions
will be nothing more than "helpful ignoramuses" with unhelpful
suggestions as some have said, but the input channels need to be
there. Currently Python dev seems to be more output than input,
however i could be wrong? We some real I/O going on here.

Also the Python tut is full of fluff (sorry Guido) and it contributes
to late learning of the language. Luckily however Python has many
users who really love the language and have taken the time to write
beautiful tutorials that start at various levels of entry. Read xah's
take on the official tutorial, it's spot on baby!

A little note for tutorial writers:
==

Dear Expert,
Whilst writing any tutorial on any subject matter please remember, you
may be an expert, but mostly *non-experts* will be reading your
material... pssft, this may come as a surprise, but tutorials are
meant for *NON-EXPERTS*!

Please refrain from stroking your own ego by obstrufcation of the very
ideas you wish to convey to these influential minds. Sure exposing
your huge intelligence to the world may give you warm-fuzzies-in-your-
tummy, but believe me your poor students will be rendered as helpless
as Paris Hilton at a "panties required" spelling bee.

Please try, and i know this is a lot to ask, to use the most simple
explanation to convey the point -- and *only* the point at hand! Take
for example the introduction of functions. You could go with your gut
instinct, "shoot from the hip" and pop off something like this that
prints a Fibonacci series up to n...

def fib(n):
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b

>>> fib(2000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597

And all you would have accomplished was to blow holes thru the
students mind! Now like the next guy, i love calculating series of
numbers all day, but this is a piss poor example of functions for the
new student, or anybody for that matter!  While your student is
racking his brain trying to figure out what "a" and "b" stand for,
much less n, and not to mention what the heck a "Fibonacci" series is
in the first place (Google can help though) , he (the student) has
forgotten that this example is simply how to write and call a
function. A much better example would be the following...

def add(x, y):
print x+y

>>> add(1, 2)
3

WOW,  with that small piece of code you have just transported three
main principals of a function in a very simple and strait forward way
smack-dab into the cerebral cortex of the student, and your fingers
did not even break a sweat!

 1. function names should describe exactly what they do
 2. functions take arguments
 3. functions do something with those arguments(like mini programs!)

You could followup with this fine example that extents on the
first...

def add(x, y=2)
return x+y

>>> add(1,2)

>>> print add(1, 2)
3
>>> print add(1)
3
>>> print add(100, 5.5)
100.5
>>> print add()
error...


However Ethan (and Co.),  not everybody who downloads Python the first
time knows about this. Also the Python website is filled to the brim
with a hodgepodge of "links-here" "links-there", "links-every-freaking-
where" (are we getting paid by the link people?) causing most noobs
brain to start blowing chunks just while tring to find a good
alternative to the official tut!

Really, it's bloat on a proportion that only elephant sized bloat
wares like M$, M$-Office, Adobe-PDF, and the like, can hold a candle
to. Python really needs and enema, and thats no joke!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pybotwar-0.5

2009-08-10 Thread Mensanator
On Aug 10, 1:35 pm, r  wrote:
>
> Sure, there is no documentation

http://www.mensanator.com/mensanator/PythonTurtle/paper.htm

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


Re: how to use "exec" stmt to get input from user

2009-08-10 Thread Rick King

Thanks for your comment.

The purpose of the application is to automate the manipulation of large 
numbers of files. For automation I want to be able to have scripts that 
I can use for various purposes.


On input, cmd.py handles calling "do_" methods for known commands; 
for the rest I want to "exec" the lines with my own dictionary. This 
allows me to use python statements, so I can do things like 
concatenating variables to form directory names, and so on. I'd like to 
be able to use any python statement, including "x=raw_input('>')", but 
this currently brings everything to a halt.


One thing this app does is execute processes using wxPythons wx.Process 
object and wx.Execute function. wxPython makes it easy to redirect stdin 
and stdout. I'm trying to do a similar thing for individual python 
statements. I'm not sure that makes sense.


I hope that's clear.

Rick


David C Ullrich wrote:
What you're trying to do and what's not working isn't 
entirely clear to me.


But if I had a wxPython application and I wanted to
execute user input (note the _if_) I'd just pop up a window
(I forget how "ShowModal" is spelled in wx right now)
with a text box and an Execute button and a Cancel
button - if the user hits the Execute button I'd
attempt to execute what he'd typed in the box.

There are reasons you want to be very careful about
this...

On Mon, 10 Aug 2009 13:44:17 -0400, Rick King wrote:

  

I have a cmd.py-derived program (with a wxPython GUI) and want to
execute python statements for lines that are not my own special
commands.

So basically it's either:

def do_somecommand(self,arg):
...

or

def default(self,arg):
exec arg in globals(),self.cmdlocals

(where cmdlocals is a my local dictionary)

in default() I'd like to be able to execute any python statement
including something like

"x = raw_input('>')"

when I do this though it goes to the command window and so any user of
the program would be confused, which also means I have to have a command
window.

If I add this:

self.stdin = self.edt_console_input   (where self.edt_console_input
is a wxPython text control)

it just gets an EOF right away.

Is there any way to do what I want to do? This might be better posted on
the wxpython list.

Thanks for any help!

Rick King
Southfield MI



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


numpy array merge

2009-08-10 Thread Nathan
Is there an easy way to merge two numpy arrays with different rank
sizes (terminology?).  I want to make a single array by concatenating
two arrays along a given direction and filling the excess cells with a
dummy variable.  numpy concatenate works well as long as the two
arrays have the same dimension, but I want to do this on two array
with a matching dimension size.  An example:

import numpy as np
a = np.array([[1,2,3],[4,5,6]])
b = np.array([[1,2],[3,4],[5,6]])
np.concatenate((a,a),axis=1)  #This works fine, but isn't what I need.
Out:  array([[1, 2, 3, 1, 2, 3],
   [4, 5, 6, 4, 5, 6]])
np.concatenate((a,b),axis=1)  #This doesn't work, but this is what I
need.

I want to fill the third row of array "a" with a dummy variable (9
or NaN) and concatenate with "b" to make:
[1,2,3,1,2]
[4,5,6,4,5]
[9,9,9,5,6]

This just seems like it would be relatively common.  So I thought I'd
check if I'm missing something before I go write the logic.  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to find out in which module an instance of a class is created?

2009-08-10 Thread Johannes Janssen

Christian Heimes schrieb:

Johannes Janssen wrote:

 > class A(object):
 > def __init__(self, mod=__name__):
 > self.mod = mod

 won't work. In this case mod would always be "foo".


You have to inspect the stack in order to get the module of the 
caller. The implementation of warnings.warn() gives you some examples 
how to get the module name.


Christian

Thanks for the quick and very helpful reply. Basically just copying from 
warnings.warn(), I came up with this:


import sys

class A(object):
   def __init__(self, mod=None):
   if mod is None:
   self.mod = sys._getframe(1).f_globals['__name__']
   else:
   self.mod = mod

In warnings.warn() they used try around sys._getframe(1). As far as I 
understand what is done in warnings, there it is not sure what object 
caused the warning and therefore it is not sure whether you can or 
cannot use sys._getframe(1). Though in my case it should be quite clear. 
Can I be sure that my code will always work?


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


Re: help with threads

2009-08-10 Thread Aahz
In article <[email protected]>,
Michael Mossey   wrote:
>
>I have a simple application that needs one thread to manage networking
>in addition to the main "thread" that does the main job. It's not
>working right. I know hardly anything about threads, so I was hoping
>someone could point me in the right direction to research this.

You might also consider the multiprocessing module.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz
-- 
http://mail.python.org/mailman/listinfo/python-list


fastPATX (a new and simple web browser)

2009-08-10 Thread patx
There was a new release of fastPATX today. However the code and the program
itself will not be available to the public untill Tuesday the 11th. This is
due to me not having the proper tools I need to publish it (I am not at my
"main comp."). This is a bit of an over statement it will probably be
published near midnight Florida time. There are many different places you
can get fastPATX. I will cover them below:
http://bitbucket.org/patx/fastpatx/
http://patx44.appspot.com/
http://www.hawkee.com/snippet/6429/

More places may be out there (mirrors) but I do not know, they are NOT
official but I do 100% support them, and encourage many to mirror fastPATX.

fastPATX official wiki - http://bitbucket.org/patx/fastpatx

JJTComputing have given a great review of fastPATX and it has been linked to
on many site (Tuxmachines). I strongly wish that if you use fastPATX to blog
or tweet (include an @h_erd ???) about, even if you did not like it! Also if
you do like it please follow the project on bitbucket.org >>
http://bitbucket.org/patx/fastpatx/follow/

If you have any questions or suggestions please email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Douglas Alan
From: Steven D'Aprano  wrote:

> On Mon, 10 Aug 2009 00:32:30 -0700, Douglas Alan wrote:

> > In C++, if I know that the code I'm looking at compiles,
> > then I never need worry that I've misinterpreted what a
> > string literal means.

> If you don't know what your string literals are, you don't
> know what your program does. You can't expect the compiler
> to save you from semantic errors. Adding escape codes into
> the string literal doesn't change this basic truth.

I grow weary of these semantic debates. The bottom line is
that C++'s strategy here catches bugs early on that Python's
approach doesn't. It does so at no additional cost.

>From a purely practical point of view, why would any
language not want to adopt a zero-cost approach to catching
bugs, even if they are relatively rare, as early as
possible?

(Other than the reason that adopting it *now* is sadly too
late.)

Furthermore, Python's strategy here is SPECIFICALLY
DESIGNED, according to the reference manual to catch bugs.
I.e., from the original posting on this issue:

 Unlike Standard C, all unrecognized escape sequences
 are left in the string unchanged, i.e., the backslash
 is left in the string. (This behavior is useful when
 debugging: if an escape sequence is mistyped, the
 resulting output is more easily recognized as broken.)

If this "feature" is designed to catch bugs, why be
half-assed about it? Especially since there seems to be
little valid use case for allowing programmers to be lazy in
their typing here.

> The compiler can't save you from typing 1234 instead of
> 11234, or 31.45 instead of 3.145, or "My darling Ho"
> instead of "My darling Jo", so why do you expect it to
> save you from typing "abc\d" instead of "abc\\d"?

Because in the former cases it can't catch the the bug, and
in the latter case, it can.

> Perhaps it can catch *some* errors of that type, but only
> at the cost of extra effort required to defeat the
> compiler (forcing the programmer to type \\d to prevent
> the compiler complaining about \d). I don't think the
> benefit is worth the cost. You and your friend do. Who is
> to say you're right?

Well, Bjarne Stroustrup, for one.

All of these are value judgments, of course, but I truly
doubt that anyone would have been bothered if Python from
day one had behaved the way that C++ does. Additionally, I
expect that if Python had always behaved the way that C++
does, and then today someone came along and proposed the
behavior that Python currently implements, so that the
programmer could sometimes get away with typing a bit less,
such a person would be chided for not understanding the Zen
of Python.

> > You don't have to go running for the manual every time
> > you see code with backslashes, where the upshot might be
> > that the programmer was merely saving themselves some
> > typing.

> Why do you care if there are "funny characters"?

Because, of course, "funny characters" often have
interesting consequences when output. Furthermore, their
consequences aren't always immediately obvious from looking
at the source code, unless you are intimately familiar with
the function of the special characters in question.

For instance, sometimes in the wrong combination, they wedge
your xterm. Etc.

I'm surprised that this needs to be spelled out.

> In C++, if you see an escape you don't recognize, do you
> care?

Yes, of course I do. If I need to know what the program
does.

> Do you go running for the manual? If the answer is No,
> then why do it in Python?

The answer is that I do in both cases.

> No. \z *is* a legal escape sequence, it just happens to map to \z.

> If you stop thinking of \z as an illegal escape sequence
> that Python refuses to raise an error for, the problem
> goes away. It's a legal escape sequence that maps to
> backslash + z.

(1) I already used that argument on my friend, and he wasn't
buying it. (Personally, I find the argument technically
valid, but commonsensically invalid. It's a language-lawyer
kind of argument, rather than one that appeals to any notion
of real aesthetics.)

(2) That argument disagrees with the Python reference
manual, which explicitly states that "unrecognized escape
sequences are left in the string unchanged", and that the
purpose for doing so is because it "is useful when
debugging".

> > "\x" is not a legal escape sequence. Shouldn't it also
> > get left as "\\x"?
>
> No, because it actually is an illegal escape sequence.

What makes it "illegal". As far as I can tell, it's just
another "unrecognized escape sequence". JavaScript treats it
that way. Are you going to be the one to tell all the
JavaScript programmers that their language can't tell a
legal escape sequence from an illegal one?

> > Well, I think he's more annoyed that if Python is going
> > to be so helpful as to put in the missing "\" for you in
> > "foo\zbar", then it should put in the missing "\" for
> > you in "\". He considers this to be an inconsistency.
>
> (1) There is no 

Re: illegal geld machen , schnell geld verdienen in , schnell geld im internet , geld 2.0 geld verdienen im web 2.0 , novoline american poker online spielen , sofort geld im internet , mehr geld ver

2009-08-10 Thread bernd
On 25 Jul., 00:50, [email protected] wrote:
> On 7 Jun., 19:48, [email protected] wrote:
> , schnell geld verdienenwww.novocasinos.de
> http://www.novocasinos.de
> http://casino-pirat.de
> www.casino-pirat.de
> www.novocasinos.de
> http://www.novocasinos.de
> > *www.novocasinos.de
> > *http://www.novocasinos.de
> > *
> > +++ SOFORT GEWINN +++ REICH WERDEN +++
> > *http://WWW.novolinecasinos.de
> > *http://www.novocasinos.de
> > *www.casino-pirat.de
> > *www.novocasinos.de
>
> > geld im internet verdienen mit geld verdienen mit online umfragen
> > damit geld machen blog geld verdienen
> > schnell geld verdiehnen geld sparen leicht
> > jetzt sofort schnelles geld drakensang geld verdienen
> > www schnell geld im internet verdienen forum
> > geld sparen leicht gemacht ebook geld verdienen im internet
> > wie kann ich online geld verdienen man schnell geld machen
> > gewinn24 jetzt sofort reunion schnell geld
> > wo kann ich geld gewinn online spielen und geld
> > schnell geld zu verdienen einfach und schnell geld
> > viel geld verdienen im internet online poker echtes geld
> > geld seite geld verdienen mit internet
> > ich schnelles geld machen geld im internet verdienen ohne
> > internet geld vedienen geld machen von
> > internet geld verdient geld online gewinnen
> > schnell zu geld man online geld verdienen
> > geld machen wenn geld verdienen mit web
> > http://novocasinos.de
> > geld verdienen mit homepage geld verdienen durch online- Zitierten Text 
> > ausblenden -
>
> - Zitierten Text anzeigen -

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


Re: wxpython question

2009-08-10 Thread David Lyon

is there a method/property called Show/Shown ?

On Mon, 10 Aug 2009 07:55:42 -0700 (PDT), azrael 
wrote:
> Is there maybe a method bounded to the class SpinCtrl() that could
> hide the widget. One that is maybe also implemented in any other
> control.
> 
> self.spcKvadDo = wx.SpinCtrl(id=-1, initial=0, max=100, min=0,
> name='spcKvadDo', parent=self.pnlFilteri, pos=wx.Point(10, 10),
> size=wx.Size(118, 21), style=wx.SP_ARROW_KEYS)
> 
> self.spcKvadOd.XXX()
> 
> I tried it with the SetTransparent() method but it did not work. Has
> anyone any Idea?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-10 Thread David Lyon
On Mon, 10 Aug 2009 09:13:34 -0700, Ethan Furman 
wrote:
> As someone who relies heavily on the docs I will also say that the idea 
> of giving the ability to modify the official documentation to somebody 
> who is /learning/ the language is, quite frankly, terrifying.  

What is more terrifying is the way feedback from newbies is handled.

Your statement implies that the only way feedback can be handled is
to throw the keys down in discust and walk away. That's primative
behaviour. And misleading, because that isn't going to happen.

> My bookshelf currently has Learning Python, Programming 
> Python, Python Cookbook, Python Programming on Win32, and Regular 
> Expressions.  All great books, and not too pricey if you can get them
used.

So, what you're advocating is let things stay how they are...

Ignore feedback... tell people to freak off...


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


Re: Python docs disappointing - group effort to hire writers?

2009-08-10 Thread Paul Rubin
r  writes:
> Whilst writing any tutorial on any subject matter please remember, you
> may be an expert, but mostly *non-experts* will be reading your
> material... pssft, this may come as a surprise, but tutorials are
> meant for *NON-EXPERTS*!

I think the Python tutorial is aimed at users who are newbies to
Python but not newbies to programming.  Writing a tutorial for total
newbies is a completely different problem, that would result in a much
different document that's less useful to the existing tutorial's
intended audience.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python configuration question when python scripts are executed using Appweb as web server.

2009-08-10 Thread Gabriel Genellina

En Mon, 10 Aug 2009 11:48:31 -0300, IronyOfLife 
escribió:


Why different results in IIS and appweb? [...]

This is fairly easy to explain. When I configured IIS to execute
python scripts, as per the documentation I pass two command line
arguments. Appweb works this way. It opens up a new command process
and in the function parameter for environment it sets only SYSTEMROOT.
It does not set the PATH variable (A BUG IN APPWEB which I have passed
on to them. They have not commented or provided any work around) for
Windows platform.


Perhaps you could configure appweb to call a .bat file like this, instead
of directly invoking python?

set path=%path%;other;directories;added
c:\path\to\python.exe %*

(this is slightly off topic now...)


You were mentioning about .local file or manifest file to specify the
path. I used the python's build command to build the wrapper. Is there
a way to mention in setup.py to generate the .manifest file? I wold
very much appreciate if you can help me with that.

I will also look for answers for how to modify setup.py to generate
manifest file or .local file etc..


The last part is easy: foo.exe.local is just an empty file in the same
directory as foo.exe - when it exists, DLLs are searched first on the
directory containing the application [1]

With manifest files I can't help. I suggest you create a new thread with
that question, perhaps in the distutils-SIG mailing list [2]

[1] http://msdn.microsoft.com/en-us/library/ms682600(VS.85).aspx
[2] http://mail.python.org/mailman/listinfo/distutils-sig

--
Gabriel Genellina

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


dictionary help

2009-08-10 Thread Krishna Pacifici
Hi,
kind of a newbie here, but I have two questions that are probably pretty simple.

1.  I need to get rid of duplicate values that are associated with different 
keys in a dictionary.  For example I have the following code.
s={}
s[0]=[10,2,3]
 s[10]=[22,23,24]
 s[20]=[45,5]
s[30]=[2,4]
s[40]=[6,7,8]

Now I want to be able to loop through the primary keys and get rid of 
duplicates (both in keys and values) so that I would have either a new 
dictionary or the same dictionary but with the following values:

s[0]=[3]
 s[10]=[22,23,24]
 s[20]=[45,5]
s[30]=[2,4]
s[40]=[6,7,8]

It doesn't matter which value gets removed as long as there is only one 
remaining, so in this example it doesn't matter that 2 got removed from s[0] or 
from s[30] as long as there is only one 2 in the dictionary.

2.  I need to be able to loop over the values in the dictionary when there are 
multiple values assigned to each key like above and assign new values to those 
values.  Taking the above example I would want to assign a new value so that 
when you called s[0] it would equal [3,4] say if 4 was the new value.  I think 
this should be as simple as adding a value, but I kept on having difficulty.

Any suggestions would be greatly appreciated.

Thank you very much,
Krishna

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


Re: dictionary help

2009-08-10 Thread J. Cliff Dyer
On Mon, 2009-08-10 at 22:11 -0400, Krishna Pacifici wrote:
> Hi,
> kind of a newbie here, but I have two questions that are probably
> pretty simple.
> 
> 1.  I need to get rid of duplicate values that are associated with
> different keys in a dictionary.  For example I have the following
> code.
> s={}
> s[0]=[10,2,3]
> s[10]=[22,23,24]
> s[20]=[45,5]
> s[30]=[2,4]
> s[40]=[6,7,8]
> 
> Now I want to be able to loop through the primary keys and get rid of
> duplicates (both in keys and values) so that I would have either a new
> dictionary or the same dictionary but with the following values:
> 
> s[0]=[3]
> s[10]=[22,23,24]
> s[20]=[45,5]
> s[30]=[2,4]
> s[40]=[6,7,8]
> 
> It doesn't matter which value gets removed as long as there is only
> one remaining, so in this example it doesn't matter that 2 got removed
> from s[0] or from s[30] as long as there is only one 2 in the
> dictionary.
> 
So if the number is a key, you want to keep the key, and delete all
matching values, and if the number is not a key, you want to keep one
(any one) instance of that number?  I'm not sure that what you are
looking for is best represented by a dict.  You might want to consider
creating your own class and overriding __getitem__.


> 2.  I need to be able to loop over the values in the dictionary when
> there are multiple values assigned to each key like above and assign
> new values to those values.  Taking the above example I would want to
> assign a new value so that when you called s[0] it would equal [3,4]
> say if 4 was the new value.  I think this should be as simple as
> adding a value, but I kept on having difficulty.
> 
Here you might want to either use the append() method on the lists of
each entry.

> Any suggestions would be greatly appreciated.
> 
I'm not sure what you are doing maps cleanly to currently existing
datastructures, which means that there might not be a quick shortcut for
you.  Hammer out the specs of what you want your class to be able to do,
and what the API will be for performing each of those functions.  Then
you should be able to begin implementing it, or at least come up with
some more specific questions.



> Thank you very much,
> Krishna

Cheers,
Cliff


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


Re: Unrecognized escape sequences in string literals

2009-08-10 Thread Steven D'Aprano
On Mon, 10 Aug 2009 08:21:03 -0700, Douglas Alan wrote:

> But you're right, it's too late to change this now.

Not really. There is a procedure for making non-backwards compatible 
changes. If you care deeply enough about this, you could agitate for 
Python 3.2 to raise a PendingDepreciation warning for "unexpected" escape 
sequences like \z, Python 3.3 to raise a Depreciation warning, and Python 
3.4 to treat it as an error.

It may even be possible to skip the PendingDepreciation warning and go 
straight for Depreciation warning in 3.2.


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


Re: With or without leading underscore...

2009-08-10 Thread Steven D'Aprano
On Mon, 10 Aug 2009 16:37:25 +0200, Ulrich Eckhardt wrote:

> ...that is the question!
> 
> I have a module which exports a type. It also exports a function that
> returns instances of that type. Now, the reason for my question is that
> while users will directly use instances of the type, they will not
> create instances of the type themselves.
> 
> So, the type is a part of the public API, but its constructor is not.
> Should I mark the type as private (with a leading underscore) or not?

My opinion is that if you have to ask the question "Should this class be 
private?", then the answer is No.

Only make objects private if you have specific reasons for doing so. I 
know this goes against the advice given by other languages (namely, make 
everything private unless you need it to be public) but Python encourages 
openness and transparency.



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


ANN: M2Crypto 0.20

2009-08-10 Thread Heikki Toivonen
I am please to announce the M2Crypto 0.20 release, which was in
development for over nine months. Over 30 bugs fixed by more than ten
people. Download links and bug filing instructions on the homepage at
http://chandlerproject.org/Projects/MeTooCrypto.

M2Crypto is the most complete Python wrapper for OpenSSL featuring RSA,
DSA, DH, HMACs, message digests, symmetric ciphers (including AES); SSL
functionality to implement clients and servers; HTTPS extensions to
Python's httplib, urllib, and xmlrpclib; unforgeable HMAC'ing
AuthCookies for web session management; FTP/TLS client and server;
S/MIME; ZServerSSL: A HTTPS server for Zope and ZSmime: An S/MIME
messenger for Zope. Smartcards supported with the Engine interface.

Changelog:

- Deprecated M2Crypto.PGP subpackage since nobody seems to be using it
nor is it being maintained (if you do use it, please let me know)
- Added fedora_setup.sh to help work around differences on Fedora Core
-based distributions (RedHat, CentOS, ...); thanks to Miloslav Trmac
- Added X509.load_request_bio and load_request_string, by Hartmut Goebel
and Pavel Shramov
- Added alias X509.Request.set_subject for set_subject_name to match
X509.X509, by Pavel Shramov
- OBJ_* wrappers did not work properly with OpenSSL 0.9.8a and earlier,
fix by Pavel Shramov
- Added ASN1_UTCTIME.get_datetime and set_datetime, by Pavel Shramov
- Fixed obj_obj2txt, which returned nonsense, fix by Barney Stratford
- m2urllib did not close sockets properly, fix by Miloslav Trmac
- Allow SSL peer certificate to have subjectAltName without dNSName and
use commonName for hostname check, fix by Miloslav Trmac
- threading_locking_callback did not block on a lock when the lock
  was held by another thread, by Miloslav Trmac
- Allow more blocking OpenSSL functions to run without GIL, by Miloslav
Trmac
- Fixed httpslib to send only the path+query+fragment part of the URL
when using CONNECT proxy, by James Bowes
- SSLServer.__init__ now takes optional bind_and_activate parameter and
  initializes by calling SocketServer.BaseServer.__init__, which
  are Python 2.6 compatibility fixes, by Christian
- ftpslib now works with Python 2.6, by Theodore A. Roth
- httpslib.ProxyHTTPSConnection needs to cast port into integer,
  by John M. Schanck
- Added support for RSASSA-PSS signing and verifying, by Chris Collis
- Added support for disabling padding when using RSA encryption,
  by Chris Collis
- ASN1_INTEGERs can now be larger than fits in an int, for example to
support X509 certificates with large serial numbers, patch by Mikhail
Vorozhtsov and testcase by Barry G.
- Reverted a change done in 0.17 to m2urllib2 which changed urls to
include host when it should stay as it was
- httpslib no longer uses urllib; instead it uses urlparse for url parsing
- SMIME.text_crlf and text_crlf_bio were always raising TypeError; fixed
- EVP.load_key and load_key_bio fixed to raise EVP.EVPError and
BIO.BIOError instead of str (str exceptions not allowed in Python 2.6
and later)
- SSL.Session.load_session fixed to raise SSL.SSLError instead of str
- SMIME.load_pkcs7, load_pkcs7_bio, smime_load_pkcs7,
smime_load_pkcs7_bio, text_crlf, text_crlf_bio fixed to raise
BIO.BIOError, SMIME.PKCS7_Error and SMIME.SMIME_Error as appropriate
instead of str
- Added FIPS mode to unit tests, and used FIPS-compliant key sizes in
other tests, by Miloslav Trmac. Note that tests run much slower because
of this!
- Unit tests cover 80% of the code

-- 
  Heikki Toivonen - http://heikkitoivonen.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy array merge

2009-08-10 Thread Robert Kern

On 2009-08-10 17:38, Nathan wrote:

Is there an easy way to merge two numpy arrays with different rank
sizes (terminology?).


You will want to ask numpy questions on the numpy mailing list.

  http://www.scipy.org/Mailing_Lists

I believe that "shape" is the term you are looking for.


I want to make a single array by concatenating
two arrays along a given direction and filling the excess cells with a
dummy variable.  numpy concatenate works well as long as the two
arrays have the same dimension, but I want to do this on two array
with a matching dimension size.  An example:

import numpy as np
a = np.array([[1,2,3],[4,5,6]])
b = np.array([[1,2],[3,4],[5,6]])
np.concatenate((a,a),axis=1)  #This works fine, but isn't what I need.
Out:  array([[1, 2, 3, 1, 2, 3],
[4, 5, 6, 4, 5, 6]])
np.concatenate((a,b),axis=1)  #This doesn't work, but this is what I
need.

I want to fill the third row of array "a" with a dummy variable (9
or NaN) and concatenate with "b" to make:
[1,2,3,1,2]
[4,5,6,4,5]
[9,9,9,5,6]

This just seems like it would be relatively common.  So I thought I'd
check if I'm missing something before I go write the logic.  Thanks!


I don't believe there is anything that does what you want out-of-box. You will 
probably want to determine the appropriate shape for the final array, use 
empty() to create it, use .fill(nan) (or whatever) to supply the default value, 
then assign the input arrays into the appropriate locations.


--
Robert Kern

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

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


Re: Problem when fetching page using urllib2.urlopen

2009-08-10 Thread jitu

Yes Piet you were right this works. But seems does not work on google
app engine, since  it appends it own agent info as seen below

'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13 AppEngine-Google;
(+http://code.google.com/appengine)'

Any way Thanks . Good to know about the User-Agent field.

Jitu


On Aug 11, 12:36 am, Piet van Oostrum  wrote:
> > jitu  (j) wrote:
> >j> Hi,
> >j> A html page  contains 'anchor' elements with 'href' attribute  having
> >j> a semicolon  in the url , while fetching the page using
> >j> urllib2.urlopen, all such href's  containing  'semicolons' are
> >j> truncated.
> >j> For example the 
> >hrefhttp://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt...
> >j> get truncated 
> >tohttp://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i
> >j> The page I am talking about can be fetched from
> >j>http://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_...
>
> It's not python that causes this. It is the server that sends you the
> URLs without these parameters (that's what they are).
>
> To get them you have to tell the server that you are a respectable
> browser. E.g.
>
> import urllib2
>
> url = 
> 'http://travel.yahoo.com/p-travelguide-6901959-pune_restaurants-i;_ylt...
>
> url = 
> 'http://travel.yahoo.com/p-travelguide-485468-pune_india_vacations-i;_...
>
> hdrs = {'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
> rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13',
>        'Accept': 'image/*'}
>
> request = urllib2.Request(url = url, headers = hdrs)
> page = urllib2.urlopen(request).read()
>
> --
> Piet van Oostrum 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: [email protected]

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


Nltk with python

2009-08-10 Thread ArshaKrishna
How can I resolve scope ambiguity using nltk toolkit with python
-- 
http://mail.python.org/mailman/listinfo/python-list


ElementTree - Howto access text within XML tag element...

2009-08-10 Thread cmalmqui
Hi,

I am writing on a small XML parser and are currently stuck as I am not
able to get the whole element name in ElementTree.

Please see the below example where "print root[0][0]" returns
""

Is there a way to get hold of the "Running" string in the tag using
elementTree?



  2009-07-10T14:48:00Z
  
  .

For those of you that know how to program XML I have another
question:
I am currently "hardcoding" my XML parser using brackets, is this a
good approach or should I build it using a "search on tag" approach.

Thank you for any answers!
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >