Re: Proxy authentication required

2011-03-22 Thread gervaz
On 22 Mar, 00:02, Chris Rebert  wrote:
> On Mon, Mar 21, 2011 at 2:38 AM, gervaz  wrote:
> > Hi all,
> > I've got to download some web pages but I'm behind a proxy. So far
> > this is what I've used without any successful result receiving the
> > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
> > Required ( The ISA Server requires auth
> > orization to fulfill the request. Access to the Web Proxy filter is
> > denied.  )":
>
> > hc = urllib.request.HTTPCookieProcessor()
> > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
> > "username": "domain\username", "password": "password"})
>
> Remember that backslash is used for string escapes in Python; so that
> should be "domain\\username" in order to get 1 literal backslash. I
> suspect this is the cause of your proxy authentication problem.
>
> > opener = urllib.request.build_opener(hc, hp)
>
> Are you sure that's the right order for the handlers? (I don't know myself.)
>
> > urllib.request.urlopen("http://www.google.it/";)
>
> Cheers,
> Chris
> --
> Windows, Y U use backslash for stuff!?http://blog.rebertia.com

Hi Cris,
I had already tested the solution with the '\\' but the result is the
same. As per the arguments order, build_opener thakes *handlers as
argument so no problem.

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


Re: Free Software University - Python Certificate

2011-03-22 Thread News123
Hi Juan,


On 03/22/2011 04:54 AM, Giovani wrote:
> Hi all, my name is Juan and I suscribed to this website called "Free
> Software University", opened recently. One of the goals of this
> website is making some free high quality courses, one of them about
> Python.
> 
> I want to say this message is not SPAM, is a call for every one who
> can and wants help us to make several good courses about Python, those
> will be in english and spanish languages (and any other translation if
> is aviable). We're allways open to new suggets, changes, contents,
> etc...
> 

I don't know whether this site is useful or not.

Assuming this site is serious:
If you are already subscribed you might be able to give some feedback.

One can't even see the list of courses without regsitering.
This is very unprofessional and might indicate, that they just want to
reap contact information.

One can't even see a date or a time line without registering. So one
doesn't even know whether the whole project is already dead for several
years or really active.

To me all this does not look professional for somebody who want to
attract students / instructors


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


Re: Decorator Syntax

2011-03-22 Thread Laurent Claessens

And I'm willing to bet that there are plenty of
scripts out there that use "dec" as a name for Decimal objects.


You won. I owe you a beer ;)

Laurent

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


Re: Proxy authentication required

2011-03-22 Thread gervaz
On 22 Mar, 09:34, gervaz  wrote:
> On 22 Mar, 00:02, Chris Rebert  wrote:
>
>
>
>
>
> > On Mon, Mar 21, 2011 at 2:38 AM, gervaz  wrote:
> > > Hi all,
> > > I've got to download some web pages but I'm behind a proxy. So far
> > > this is what I've used without any successful result receiving the
> > > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
> > > Required ( The ISA Server requires auth
> > > orization to fulfill the request. Access to the Web Proxy filter is
> > > denied.  )":
>
> > > hc = urllib.request.HTTPCookieProcessor()
> > > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
> > > "username": "domain\username", "password": "password"})
>
> > Remember that backslash is used for string escapes in Python; so that
> > should be "domain\\username" in order to get 1 literal backslash. I
> > suspect this is the cause of your proxy authentication problem.
>
> > > opener = urllib.request.build_opener(hc, hp)
>
> > Are you sure that's the right order for the handlers? (I don't know myself.)
>
> > > urllib.request.urlopen("http://www.google.it/";)
>
> > Cheers,
> > Chris
> > --
> > Windows, Y U use backslash for stuff!?http://blog.rebertia.com
>
> Hi Cris,
> I had already tested the solution with the '\\' but the result is the
> same. As per the arguments order, build_opener thakes *handlers as
> argument so no problem.
>
> Mattia- Nascondi testo citato
>
> - Mostra testo citato -

Further investigating the issue the proxy needs NTLM authentication,
for that reason no solution so far works. I'm using py3.

Thanks,

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


Re: Free Software University - Python Certificate

2011-03-22 Thread Giovani
> I don't know whether this site is useful or not.
>
> Assuming this site is serious:
> If you are already subscribed you might be able to give some feedback.
>
> One can't even see the list of courses without regsitering.
> This is very unprofessional and might indicate, that they just want to
> reap contact information.

I'm not the admin of the site, when the course finish will be aviable
throgh the main website (I think).

>
> One can't even see a date or a time line without registering. So one
> doesn't even know whether the whole project is already dead for several
> years or really active.
>

I really active, there more than 100 users registered and lots of them
are working to make several course certificates (PHP, Python, Java,
JavaScript, FreeNAS, etc..).

> To me all this does not look professional for somebody who want to
> attract students / instructors

The finally is make professional contents, but this project is already
in a early stage.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator Syntax

2011-03-22 Thread Rafe Kettler
On Mar 21, 8:59 pm, Mike Patterson  wrote:
> In my Python class the other day, the professor was going over
> decorators and he briefly mentioned that there had been this huge
> debate about the syntax and using the @ sign to signify decorators.
>
> I read about the alternative forms proposed here 
> (http://www.python.org/dev/peps/pep-0318/#syntax-alternatives).
>
> Has anyone thought about just using dec to declare a decorator?
>
> For example:
> dec dec2
> dec dec1
> def func(arg1, arg2, ...):
>     pass

I personally love the @ syntax for two reasons:
 1. It makes it very, very obvious that a decorator is being used
 2. It feels closely tied to the function or class that it's
decorating
The 'dec' syntax isn't quite as good in those regards, IMO. It
basically looks like any other statement, which makes it less visible,
and it doesn't seem as closely tied syntactically.

Of course, that's all opinion. But what's done is done; it's doubtful
that the decorator syntax will ever change significantly.

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


argparse and filetypes

2011-03-22 Thread Bradley Hintze
Hi,

I just started with argparse. I want to simply check the extension of
the file that the user passes to the program. I get a ''file' object
has no attribute 'rfind'' error when I use
os.path.splitext(args.infile).  Here is my code.

import argparse, sys, os

des = 'Get restraint definitions from probe.'
parser = argparse.ArgumentParser(description=des)
parser.add_argument('infile', nargs='?', type=argparse.FileType('r'))
# parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
   # default=sys.stdout)

args = parser.parse_args()
# print args.infile.readlines()
print basename, extension = os.path.splitext(args.infile)

There may be a better way to check extensions using argparse.

Any help will be appreciated.
Thanks,
Bradley

-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
-- 
http://mail.python.org/mailman/listinfo/python-list


Separating design from code

2011-03-22 Thread Νικόλαος Κούρας
Hello, in this page http://www.superhost.gr/hosting.html at the bottom
end i decided to create a textarea for the user to enter some comments
related to the page that i want to submit to a mysql database table.

Now i have seperated the design from the code:

http://www.superhost.gr/hosting.html is the design
http://www.superhost.gr/cgi-bin/counter.py is the python script

Every request to any html page due to mod rewrite is passed to the
above python script.

Its my first time tryign to do this so i need to ask:

a) When the user hits submit after entering comments in the
hosting.html

http://superhost.gr/cgi-bin/counter.py";>

Σχολιάστε ή ρωτήστε με σχετικά




What should the action be? The file itself or to the python code
script
As i have it now i am getting an error
Just try to enter something and hit sumbit you will see an error page.

#relevant counter.py code
# get some enviromental values
form = cgi.FieldStorage()
page = form.getvalue('page')

# try to open the page
f = open( '../' + page )

Why when the user submits the form error is created?

I need help passing an html form to my python script.

Please ask me if i need to provide more information about anything.

the mod rewrite rule is:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?page=$1 [L,PT,QSA]

so for every html request to be handled by counter.py script
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.stat bug?

2011-03-22 Thread Laszlo Nagy

I guess that the code

is running in kernel mode. I think this because I can send a KILL signal
to it and the state changes to the following:

What's your operating system and file system? A better file system or
system setting may increase your performance a lot. XFS or ext3 / ext4
with hashed directory index increases the file lookup part from O(n) to
O(1).
FreeBSD 8.1 and UFS2 + soft updates. Dirhash memory already set to a 
high value:


vfs.ufs.dirhash_maxmem: 134217728



It's mostly likely a problem with the OS, hardware and/or your
configuration. Python doesn't come with its own stat() implementation.
os.stat() just wraps the libc's stat() function. The heavy lifting is
done inside libc and the kernel.

Great, so the I should ask the BSD list about this.

I'll first try to rewrite the code and replace that some million files 
with a very big hash database (gdbm). I guess that will be faster.


Thanks.

   Laszlo

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


Re: argparse and filetypes

2011-03-22 Thread Alex Willmer
On Mar 22, 2:06 pm, Bradley Hintze 
wrote:
> I just started with argparse. I want to simply check the extension of
> the file that the user passes to the program. I get a ''file' object
> has no attribute 'rfind'' error when I use
> os.path.splitext(args.infile).  Here is my code.
>
> import argparse, sys, os
>
> des = 'Get restraint definitions from probe.'
> parser = argparse.ArgumentParser(description=des)
> parser.add_argument('infile', nargs='?', type=argparse.FileType('r'))
> # parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
>                    # default=sys.stdout)
>
> args = parser.parse_args()
> # print args.infile.readlines()
> print basename, extension = os.path.splitext(args.infile)

Because you specified type=argparse.FileType('r') argparse has created
args.infile as a file object (e.g. open('/some/path/data.dat', 'r')),
not as a string containing the path. So type(args.infile) ==
type(file) and args.infile.readlines() returns the contents of that
file.

If you wish to check the file extension of the path in question I
suggest you remove type=argparse.FileType('r'), argparse will create
args.infile as a string containing that path. To open the file call
open(args.infile, 'r'), this will return the file object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: puzzle about file Object.readlines()

2011-03-22 Thread Gabriel Genellina
On 19 mar, 16:05, Dave Angel  wrote:
> On 01/-10/-28163 02:59 PM, MRAB wrote:
> > On 19/03/2011 13:15, 林桦 wrote:
> >> i use python 2.5. os is window 7.
> >> the puzzle is :python don't read the leave text when meet character:
> >> chr(26)
> >> the code is:
> >> /fileObject=open('d:\\temp\\1.txt','w')
> >> fileObject.write('22\r\n')
> >> fileObject.write(chr(26)+'\r\n')
> >> fileObject.write('33')
> >> fileObject.close()
> >> fileObject=open('d:\\temp\\1.txt','r')
> >> i=0
> >> for line in fileObject:
> >> i+=1
> >> print str(i)+'**'+line
> >> fileObject.close()/
>
> >> the output only print:
> >> />>>
> >> 1**22/
>
> >> but can't print next line text:/'33'' 。who tell me why?
> >> /
>
> > chr(26) can sometimes be used in text files to indicate the end of the text.
>
> > In Microsoft Windows it dates from MS-DOS, which borrowed from CP/M, an
> > operating
> > system which stored the file size as the number of 128-byte records.
> > chr(26) was used to
> > indicate where the text ended in the last record.
>
> On Win a ctrl-z is end of file.  So if you want to read beyond the end
> of a text file, you have to pretend it's binary.  Open it with  "rb"
> instead of "r"

Using mode "rU" may be more convenient, because it still translates \r
\n into \n but disregards chr(26) as a special marker.

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


Re: How to build and upload eggs to pypi?

2011-03-22 Thread Gabriel Genellina
On 21 mar, 08:53, morphex  wrote:
> Hi,
>
> I have a couple of project which are on PyPi, and now I'd like to
> update some of them.  Is there a good howto somewhere, showing how to
> add new versions (instead of updating one that's already there) etc?

There is a tutorial: http://wiki.python.org/moin/CheeseShopTutorial
To add a new version, simply increment the version number, and then
"python setup.py upload" should be enough.

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


os.stat UnicodeEncodeError:

2011-03-22 Thread Sandy Oz

Hello everyone,


I'm running into a problem with file names containing 
Unicode chars.


Here is the error that I get when calling os.path.isfile:

  File "/usr/lib/python2.6/genericpath.py", line 29, in isfile
st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in 
position 38-41: ordinal not in range(128)



I'm working with python2.6, Ubuntu 10.10 running Gnome.

The interesting thing is that I do not get this error when 
running the command in the python interpreter (with the same 
filename).


Only when I do it through the application I developed. 
Shouldn't os module not be using the system locale in both 
cases?


I tried setting the locale to en_US.UTF-8 but to no avail.


Thank you,

Sandy

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


problem installing a module

2011-03-22 Thread luca72
Hello i try to install pyvisa under winxp sp3
i get this error:
home_dir =os.environ['HOME']
return self.data[key.upper()]
key error : 'HOME'

i have installed a lot of tyme pyvisa and this is the first time that
i get this error.
Thanks

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


Re: argparse and filetypes

2011-03-22 Thread Alex Willmer
On Mar 22, 2:06 pm, Bradley Hintze 
wrote:
> Hi,
>
> I just started with argparse. I want to simply check the extension of
> the file that the user passes to the program. I get a ''file' object
> has no attribute 'rfind'' error when I use
> os.path.splitext(args.infile).

Addendum, some file objects have a name attribute (which I hadn't
noticed until today):

file.name
If the file object was created using open(), the name of the file.
Otherwise, some string that indicates the source of the file object,
of the form <...>. This is a read-only attribute and may not be
present on all file-like objects.

http://docs.python.org/library/stdtypes.html#file-objects
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free Software University - Python Certificate

2011-03-22 Thread Noah Hall
On Tue, Mar 22, 2011 at 11:30 AM, Giovani  wrote:
>> I don't know whether this site is useful or not.
>>
>> Assuming this site is serious:
>> If you are already subscribed you might be able to give some feedback.
>>
>> One can't even see the list of courses without regsitering.
>> This is very unprofessional and might indicate, that they just want to
>> reap contact information.
>
> I'm not the admin of the site, when the course finish will be aviable
> throgh the main website (I think).
>
>>
>> One can't even see a date or a time line without registering. So one
>> doesn't even know whether the whole project is already dead for several
>> years or really active.
>>
>
> I really active, there more than 100 users registered and lots of them
> are working to make several course certificates (PHP, Python, Java,
> JavaScript, FreeNAS, etc..).
>
>> To me all this does not look professional for somebody who want to
>> attract students / instructors
>
> The finally is make professional contents, but this project is already
> in a early stage.


I've been following this project for a while, since it was annouced on
the Ubuntu forums. I can't say that I've been at all impressed by
anything they have to offer.
-- 
http://mail.python.org/mailman/listinfo/python-list


SQLObject 0.15.1

2011-03-22 Thread Oleg Broytman
Hello!

I'm pleased to announce version 0.15.1, a bugfix release of branch 0.15
of SQLObject.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.15.1

News and changes:
http://sqlobject.org/News.html


What's New
==

* A bug was fixed in MSSQLConnection.

* A minor bug was fixed in sqlbuilder.Union.

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmanhttp://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with keyboard up/down arrows in Python 2.4 interpreter

2011-03-22 Thread Sridhar Ratnakumar
On Monday, March 21, 2011 at 11:37 PM, Benjamin Kaplan wrote:
On Tue, Mar 22, 2011 at 2:27 AM, Julien  wrote:
> > Hi,
> > 
> > I'm having problems when typing the up/down arrows in the Python 2.4
> > interpreter (exact version: Python 2.4.6 (#1, Mar 3 2011, 15:45:53)
> > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin).
> > 
> > When I press the up arrow it outputs "^[[A" and when I press the down
> > arrow it outputs "^[[B".
> > 
> > I've google it and it looks like it might be an issue with the
> > readline not being installed or configured properly. Is that correct?
> > If so, how can I fix this issue?
You need to install this module:
http://pypi.python.org/pypi/readline/

Out of curiosity, which distribution of Python are you using? ActivePython, 
MacPorts, python.org or homebrew?

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


Re: Switching between Python releases under Windows

2011-03-22 Thread Sridhar Ratnakumar
On Tue, Mar 8, 2011 at 8:03 AM, Tim Golden  wrote:
> On 08/03/2011 15:58, Tim Golden wrote:
>>
>> On 08/03/2011 14:55, Edward Diener wrote:
>>>
>>> I have multiple versions of Python installed under Vista. Is there any
>>> easy way of switching between them so that invoking python and file
>>> associations for Python extensions files work automatically ?
>>
>> Well, the answer depends a bit on how au fait you are with fiddling
>> with env vars etc
>
> But essentially involves:
>
> * Adding c:\pythonxy and c:\pythonxy\script to PATH

FWIW, ActivePython automatically does this. As it includes versioned
binaries as well, one can type (just like on Unix) `python2.7.exe` or
`python3.2.exe` in the Command Prompt.

> * assoc .py=python.file [probably already done]
>
> * python.file="C:\Pythonxy\python.exe" "%1" %*

I suppose I should soon implement Windows support in pythonselect,
https://github.com/Activestate/pythonselect

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


Re: problem installing a module

2011-03-22 Thread Emile van Sebille

On 3/22/2011 8:19 AM luca72 said...

Hello i try to install pyvisa under winxp sp3
i get this error:
home_dir =os.environ['HOME']


Installation is clearly expecting a HOME environment variable that isn't 
there.  You'll need to set it then install.


HTH,


Emile




return self.data[key.upper()]
key error : 'HOME'

i have installed a lot of tyme pyvisa and this is the first time that
i get this error.
Thanks

Luca



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


Re: interrupted system call w/ Queue.get

2011-03-22 Thread Philip Winston
On Feb 18, 10:23 am, Jean-Paul Calderone
 wrote:
> The exception is caused by a syscall returning EINTR.  A syscall will
> return EINTR when a signal arrives and interrupts whatever that
> syscall
> was trying to do.  Typically a signal won't interrupt the syscall
> unless you've installed a signal handler for that signal.  However,
> you can avoid the interruption by using `signal.siginterrupt` to
> disable interruption on that signal after you've installed the
> handler.
>
> As for the other questions - I don't know, it depends how and why it
> happens, and whether it prevents your application from working
> properly.

We did not try "signal.siginterrupt" because we were not installing
any signals, perhaps some library code is doing it without us knowing
about it.  Plus I still don't know what signal was causing the
problem.

Instead based on Dan Stromberg's reply (http://code.activestate.com/
lists/python-list/595310/) I wrote a drop-in replacement for Queue
called RetryQueue which fixes the problem for us:

from multiprocessing.queues import Queue
import errno

def retry_on_eintr(function, *args, **kw):
while True:
try:
return function(*args, **kw)
except IOError, e:
if e.errno == errno.EINTR:
continue
else:
raise

class RetryQueue(Queue):
"""Queue which will retry if interrupted with EINTR."""
def get(self, block=True, timeout=None):
return retry_on_eintr(Queue.get, self, block, timeout)

As to whether this is a bug or just our own malignant signal-related
settings I'm not sure. Certainly it's not desirable to have your
blocking waits interrupted. I did see several EINTR issues in Python
but none obviously about Queue exactly:
http://bugs.python.org/issue1068268
http://bugs.python.org/issue1628205
http://bugs.python.org/issue10956

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


Problem with re module

2011-03-22 Thread John Harrington
I'm trying to use the following substitution,

 lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
\2',lineList[i])

I intend this to match any string "\begin{document}" that doesn't end
in a line ending.  If there's no line ending, then, I want to place
two carriage returns between the string and the non-line end
character.

However, this places carriage returns even when the string is followed
directly after with a line ending.  Can someone explain to me why this
match is not behaving as I intend it to, especially the ([^$])?

Also, how can I write a regex that matches what I wish to match, as
described above?

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


Re: argparse and filetypes

2011-03-22 Thread Robert Kern

On 3/22/11 9:06 AM, Bradley Hintze wrote:

Hi,

I just started with argparse. I want to simply check the extension of
the file that the user passes to the program. I get a ''file' object
has no attribute 'rfind'' error when I use
os.path.splitext(args.infile).  Here is my code.

import argparse, sys, os

des = 'Get restraint definitions from probe.'
parser = argparse.ArgumentParser(description=des)
parser.add_argument('infile', nargs='?', type=argparse.FileType('r'))
# parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
# default=sys.stdout)

args = parser.parse_args()
# print args.infile.readlines()
print basename, extension = os.path.splitext(args.infile)

There may be a better way to check extensions using argparse.


The type= argument should be a callable that either coerces the string to an 
appropriate object or raises a ValueError if the string is unacceptable. 
FileType() is a convenient callable for opening readable or writable files; when 
called, it returns a regular file object, not the filename, as you saw from the 
exception you got. It does not do any validation.


You can add validation very easily:

class TxtFile(argparse.FileType):
def __call__(self, string):
base, ext = os.path.splitext(string)
if ext != '.txt':
raise ValueError('%s should have a .txt extension' % string)
return super(TxtFile, self).__call__(string)

...
parser.add_argument('infile', type=TxtFile('r'))

--
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 with re module

2011-03-22 Thread John Bokma
John Harrington  writes:

> I'm trying to use the following substitution,
>
>  lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
> \2',lineList[i])
>
> I intend this to match any string "\begin{document}" that doesn't end
> in a line ending.  If there's no line ending, then, I want to place
> two carriage returns between the string and the non-line end
> character.
>
> However, this places carriage returns even when the string is followed
> directly after with a line ending.  Can someone explain to me why this
> match is not behaving as I intend it to, especially the ([^$])?

[^$] matches: not a $ character

You might want [^\n]

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


best practice to resolve module dependency within a reusable application

2011-03-22 Thread Marc Aymerich
Hi,
I'm developing a reusable app splited into modules. The end user
chooses what modules wants to keep installed.
Most of this modules are quite independent from each other, but I have
one of them (called moduleP) with a pretty strong dependency with
another another(called moduleBase). So I need to change some of the
moduleBase behaviour whenever moduleP is installed.

What is the best practice to resolve this dependency in a reusable
scenario?
Where should the specific moduleP code for moduleBase live? in moduleP
or in moduleBase?

I thought in two possible solutions:

1) moduleP specific code lives in moduleBase an it is called if "is
moduleP installed":

   class moduleBase(otherClass):
 def method(self):
   super(moduleBase, self).method()
   # moduleBase stuff
   .
   .
   if 'moduleP' in INSTALLED_MODULES:
# moduleP stuff
.
.

2) moduleP code lives in moduleP and it swaps moduleBase method with
their own, like this:

   # backup moduleBase method
   moduleBase.back_methodBase = moduleBase.method

   def Pmethod(self):
# calls moduleBase.method
self.back_methodBase_method
# moduleP stuff
.
.

   # swap moduleP Pmethod
   moduleBase.method = Pmethod


I'm missing some other mechanism to achieve this? Which one do you
think is best?
Many thanks!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with re module

2011-03-22 Thread Peter Otten
John Harrington wrote:

> I'm trying to use the following substitution,
> 
>  lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
> \2',lineList[i])
> 
> I intend this to match any string "\begin{document}" that doesn't end
> in a line ending.  If there's no line ending, then, I want to place
> two carriage returns between the string and the non-line end
> character.
> 
> However, this places carriage returns even when the string is followed
> directly after with a line ending.  Can someone explain to me why this
> match is not behaving as I intend it to, especially the ([^$])?

Quoting http://docs.python.org/library/re.html:
"""
Special characters are not active inside sets. For example, [akm$] will 
match any of the characters 'a', 'k', 'm', or '$';
"""
>
> Also, how can I write a regex that matches what I wish to match, as
> described above?

I think you want a "negative lookahead assertion", (?!...):

>>> print re.compile("(xxx)(?!$)", re.MULTILINE).sub(r"\1**", "aaa bbb 
xxx\naaa xxx bbb\nxxx")
aaa bbb xxx
aaa xxx** bbb
xxx


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


Re: Problem with re module

2011-03-22 Thread John Harrington
On Mar 22, 11:16 am, John Bokma  wrote:
> John Harrington  writes:
> > I'm trying to use the following substitution,
>
> >      lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
> > \2',lineList[i])
>
> > I intend this to match any string "\begin{document}" that doesn't end
> > in a line ending.  If there's no line ending, then, I want to place
> > two carriage returns between the string and the non-line end
> > character.
>
> > However, this places carriage returns even when the string is followed
> > directly after with a line ending.  Can someone explain to me why this
> > match is not behaving as I intend it to, especially the ([^$])?
>
> [^$] matches: not a $ character
>
> You might want [^\n]

Thank you, John.

I thought that when you use "r" before the regex, $ matches an end of
line.  But, in any case, if I use "[^\n]" as you suggest I get the
same result.

Here's a script that illustrates the problem.  Any help would be
appreciated!:

#BEGIN SCRIPT
import re

outlist = []
myfile  = "raw.tex"

fin = open(myfile, "r")
lineList = fin.readlines()
fin.close()

for i in range(0,len(lineList)):

 lineList[i]=re.sub(r'(\\begin{document})([^\n])',r'\1\n\n
\2',lineList[i])

 outlist.append(lineList[i])

fou = open(myfile, "w")
for i in range(len(outlist)):
   fou.write(outlist[i])
fou.close
#END SCRIPT

And the file raw.tex:

%BEGIN TeX FILE
\begin{document}
This line should remain right after the above line in the output, but
doesn't

\begin{document}Extra stuff here should appear below the begin line
and does in the output.
%END TeX FILE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Calling C++ Modules in Python

2011-03-22 Thread zxpatric
Dan,

Recently I am trying out both the SWIG and BOOST, maybe Cython later.
However, I didn't get lucky with the combination of the latest SWIGwin 2.0.2
and Python3.2. No matter I build _example.pyd, example.pyd or _example.dll,
or example.dll, it just doesn't get imported as said in the instruction. Is
the combination similar to what you are using right now?

Cheers
-Patrick

On Fri, Mar 11, 2011 at 5:37 PM, Dan Stromberg  wrote:

>
> I've not tried Boost, but I don't think SWIG or Cython require modified
> libraries.  You just compile your wrapper, and then import it.
>
> On Fri, Mar 11, 2011 at 2:16 PM,  wrote:
>
>> Dan,
>>
>> Thanks for the info. Really I was hoping for a "non-intrusive" way to
>> expose existing C++ libraries to python. However, both solutions (BOOST,
>> SWIG) listed here require the recompilation of libraries?! Seems Cython is
>> doing the similar way? It is ok for small applications but will be hard for
>> big software from big companies. The reason is that even companies are
>> willing to rebuild their own libraries with those wrappers or decorations
>> added(though needs approves from all sorts of departments :)), they can't
>> force their 3rd-party developers/users.
>> Correct me if I am wrong.
>>
>> Rg,
>> -Patrick
>>
>> On Mar 11, 2011 4:59pm, Dan Stromberg  wrote:
>> >
>> > On Fri, Mar 11, 2011 at 1:15 PM, Patrick zxpat...@gmail.com> wrote:
>> >
>> >
>> > Hi,
>> >
>> >
>> >
>> >
>> >
>> > I saw in the Beginner document that "•Is easily extended by adding new
>> >
>> >
>> > modules implemented in a compiled language such as C or C++. ".
>> >
>> >
>> >
>> >
>> >
>> > While to my investigation, it seems not that easy or did I miss
>> >
>> >
>> > something?
>> >
>> >
>> >
>> >
>> >
>> > boost python (C++ libraries need to be re-compiled with written
>> >
>> >
>> > wrappers again?).
>> >
>> >
>> > SWIG  (It works by taking the declarations found in C/C++ header and
>> >
>> >
>> > using them to generate the wrapper code that scripting languages need
>> >
>> >
>> > to access the underlying C/C++ code).
>> >
>> > I guess it should be asked: "easy for who"?  "easy" is always relative
>> to some context.
>> >
>> > If you're planning to stay with CPython and C++ forevermore, then Cython
>> is a nice way of gluing the two.   Cython looks like Python code, but it
>> gives you access to C and C++ code and data as well as CPython code and
>> data.
>> >
>> >
>> >
>> > If you're planning to support your C++ code with more languages than
>> CPython, you might be better off with SWIG.
>> >
>> > If you really do want to do the task the old way, you're probably best
>> off copying some preexisting module with a maximize-the-developers-rights
>> license (like Apache, MIT or 3 clause BSD), and modifying that.
>> >
>> >
>> >
>> > If you want to be able to move easily to pypy, I might suggest coming up
>> with a C wrapper for your C++ code, and then accessing the C code using
>> ctypes.  That should work in CPython and pypy, and it looks like jython
>> might support this soon as well.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with re module

2011-03-22 Thread Benjamin Kaplan
On Tue, Mar 22, 2011 at 2:40 PM, John Harrington
 wrote:
> On Mar 22, 11:16 am, John Bokma  wrote:
>> John Harrington  writes:
>> > I'm trying to use the following substitution,
>>
>> >      lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
>> > \2',lineList[i])
>>
>> > I intend this to match any string "\begin{document}" that doesn't end
>> > in a line ending.  If there's no line ending, then, I want to place
>> > two carriage returns between the string and the non-line end
>> > character.
>>
>> > However, this places carriage returns even when the string is followed
>> > directly after with a line ending.  Can someone explain to me why this
>> > match is not behaving as I intend it to, especially the ([^$])?
>>
>> [^$] matches: not a $ character
>>
>> You might want [^\n]
>
> Thank you, John.
>
> I thought that when you use "r" before the regex, $ matches an end of
> line.  But, in any case, if I use "[^\n]" as you suggest I get the
> same result.
>


r before a string has nothing to do with regexes. It signals a raw
string- escape sequences wont' be escaped.
>>> print 'a\tb'
a   b
>>> print r'a\tb'
a\tb

We use raw strings for regexes because otherwise, you'd have to
remember double up all your backslashes. And double up your doubled up
backslashes when you really want a backslash.

> Here's a script that illustrates the problem.  Any help would be
> appreciated!:
>
> #BEGIN SCRIPT
> import re
>
> outlist = []
> myfile  = "raw.tex"
>
> fin = open(myfile, "r")
> lineList = fin.readlines()
> fin.close()
>
> for i in range(0,len(lineList)):
>
>     lineList[i]=re.sub(r'(\\begin{document})([^\n])',r'\1\n\n
> \2',lineList[i])
>
>     outlist.append(lineList[i])
>
> fou = open(myfile, "w")
> for i in range(len(outlist)):
>   fou.write(outlist[i])
> fou.close
> #END SCRIPT
>
> And the file raw.tex:
>
> %BEGIN TeX FILE
> \begin{document}
> This line should remain right after the above line in the output, but
> doesn't
>
> \begin{document}Extra stuff here should appear below the begin line
> and does in the output.
> %END TeX FILE

Works for me. Do you have a space after the \begin{document} or
something? Because that get moved. You might want to check for
non-whitespace characters in the reges instead of just non-newlines.

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


help porting an open source toolkit to Mac and Windows/Cygwin

2011-03-22 Thread bobicanprogram
I am the facilitator for the SIMPL open source project (http://
www.icanprogram.com/simpl).  The SIMPL toolkit project started over 10
years ago as a way to bring Send/Receive/Reply (QNX style) messaging
to Linux.   A SIMPL application consists of two or more interacting
SIMPL modules.  Those modules can be written in any number of
languages including Python, C, C++, JAVA, Tcl/Tk and soon PHP.
Modules written in different languages can be mixed in a SIMPL
application (some Python and C examples are here
http://www.icanprogram.com/06py/lesson1/lesson1.html).  SIMPL modules
can be distributed on a single node or spread across a network often
without even a recompile.   Until now a SIMPL network had to contain
at least one Linux node.

This is about to change.   Recently work (http://icanprogram.ca/simpl/
simpl.self.html) has allowed the SIMPL core library to be successfully
compiled and run on a Mac.   We'd love to do the same with Windows/
Cygwin.

Over the years the Python-SIMPL webpages have always been amongst the
top for web hits on the SIMPL website every month.  So despite its
limitations Python-SIMPL is apparently very popular in the Python
community.  We'd love to extend the Mac work to include the Python-
SIMPL library and thereby make the Mac a full Python-SIMPL citizen.
If the work with Windows/Cygwin progresses along a similar path to the
Mac effort,  we'd love to do the same with the Python-SIMPL library
there.   Our goal is to have three fully functional Python-SIMPL
libraries:  Linux, Mac and Windows.  We are looking for Python
volunteers to help make this happen.

If you are interested don't hesitate to contact me offlist or make
contact on the SIMPL project mailing list.

Thanks.

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


Re: Problem with re module

2011-03-22 Thread John Harrington
On Mar 22, 12:07 pm, Benjamin Kaplan  wrote:
> On Tue, Mar 22, 2011 at 2:40 PM, John Harrington
>
>
>
>  wrote:
> > On Mar 22, 11:16 am, John Bokma  wrote:
> >> John Harrington  writes:
> >> > I'm trying to use the following substitution,
>
> >> >      lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n
> >> > \2',lineList[i])
>
> >> > I intend this to match any string "\begin{document}" that doesn't end
> >> > in a line ending.  If there's no line ending, then, I want to place
> >> > two carriage returns between the string and the non-line end
> >> > character.
>
> >> > However, this places carriage returns even when the string is followed
> >> > directly after with a line ending.  Can someone explain to me why this
> >> > match is not behaving as I intend it to, especially the ([^$])?
>
> >> [^$] matches: not a $ character
>
> >> You might want [^\n]
>
> > Thank you, John.
>
> > I thought that when you use "r" before the regex, $ matches an end of
> > line.  But, in any case, if I use "[^\n]" as you suggest I get the
> > same result.
>
> r before a string has nothing to do with regexes. It signals a raw
> string- escape sequences wont' be escaped.>>> print 'a\tb'
> a       b
> >>> print r'a\tb'
>
> a\tb
>
> We use raw strings for regexes because otherwise, you'd have to
> remember double up all your backslashes. And double up your doubled up
> backslashes when you really want a backslash.
>
>
>
> > Here's a script that illustrates the problem.  Any help would be
> > appreciated!:
>
> > #BEGIN SCRIPT
> > import re
>
> > outlist = []
> > myfile  = "raw.tex"
>
> > fin = open(myfile, "r")
> > lineList = fin.readlines()
> > fin.close()
>
> > for i in range(0,len(lineList)):
>
> >     lineList[i]=re.sub(r'(\\begin{document})([^\n])',r'\1\n\n
> > \2',lineList[i])
>
> >     outlist.append(lineList[i])
>
> > fou = open(myfile, "w")
> > for i in range(len(outlist)):
> >   fou.write(outlist[i])
> > fou.close
> > #END SCRIPT
>
> > And the file raw.tex:
>
> > %BEGIN TeX FILE
> > \begin{document}
> > This line should remain right after the above line in the output, but
> > doesn't
>
> > \begin{document}Extra stuff here should appear below the begin line
> > and does in the output.
> > %END TeX FILE
>
> Works for me. Do you have a space after the \begin{document} or
> something? Because that get moved. You might want to check for
> non-whitespace characters in the reges instead of just non-newlines.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

Matching the non-whitespace works, but I'm troubled I can't match a
non-end-of-line.  No, there was no space after the string.

Thank you for your help, Ben

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


Re: os.utime

2011-03-22 Thread Dan Stromberg
On Mon, Mar 21, 2011 at 2:43 AM, Christian Heimes  wrote:

> I'm sorry if I offended you in any way. I had to clarify the meaning of
> st_ctime many times in the past because people confused it for the
> creation ts of the file.
>
Apologies if I got too defensive.  I agree that it was worth pointing out.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python 3.2 Debug build

2011-03-22 Thread Willis Cheung
Thanks for your answers. Just to make sure I do it correctly, is it the CPython 
package on http://hg.python.org the one which I should be downloading? Thanks 
again

 

Willis

 

From: Santoso Wijaya [mailto:santoso.wij...@gmail.com] 
Sent: Thursday, March 17, 2011 6:05 PM
To: Willis Cheung
Cc: python-list@python.org
Subject: Re: Python 3.2 Debug build

 

Looks like something tripped over whitespaces in path names for svn tools. Try 
checking out a working copy from the hg repository?


 

~/santa



On Thu, Mar 17, 2011 at 3:54 PM, Willis Cheung  wrote:

Hi all,

I'm trying to build the debug version of Python 3.2. I downloaded the py3k 
folder from the python SVN. Then I opened the pcbuild.sln and tried to build 
the "python" project. However the build failed when I got an error from the 
project "pythoncore" which I think "python" depends on? The error is:

Cannot open source file: 'C:\Program 
Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c': No such file 
or directory.



The log also mentioned the following couple lines before:

 

5>"C:\Program Files\TortoiseSVN\bin\subwcrev.exe" .. ..\Modules\getbuildinfo.c 
"C:\Program Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c"
5>'C:\Program' is not recognized as an internal or external command,


I did get the debug build of python 2.7.1 and 3.1.3 to work successfully so I'm 
not quite sure if I'm supposed to do anything different for Python 3.2. Can 
anyone guide me on this? Thank you.


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

 

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


Re: Calling C++ Modules in Python

2011-03-22 Thread Stefan Behnel

zxpat...@gmail.com, 11.03.2011 23:16:

On Mar 11, 2011 4:59pm, Dan Stromberg wrote:


On Fri, Mar 11, 2011 at 1:15 PM, Patrick wrote:
I saw in the Beginner document that "•Is easily extended by adding new
modules implemented in a compiled language such as C or C++. ".
While to my investigation, it seems not that easy or did I miss
something?
boost python (C++ libraries need to be re-compiled with written
wrappers again?).

SWIG (It works by taking the declarations found in C/C++ header and
using them to generate the wrapper code that scripting languages need
to access the underlying C/C++ code).

I guess it should be asked: "easy for who"? "easy" is always relative to
some context.



If you're planning to stay with CPython and C++ forevermore, then Cython
is a nice way of gluing the two. Cython looks like Python code, but it
gives you access to C and C++ code and data as well as CPython code and
data.


Thanks for the info. Really I was hoping for a "non-intrusive" way to
expose existing C++ libraries to python. However, both solutions (BOOST,
SWIG) listed here require the recompilation of libraries?! Seems Cython is
doing the similar way?


Neither of the three requires the *re*compilation of libraries, but they 
all require you to compile wrapper code. As Dan pointed out, Cython has 
likely the lowest entry bar while giving you all freedom to design a 
suitable wrapper. It's also the fastest of the three.




It is ok for small applications but will be hard for
big software from big companies. The reason is that even companies are
willing to rebuild their own libraries with those wrappers or decorations
added(though needs approves from all sorts of departments :)), they can't
force their 3rd-party developers/users.
Correct me if I am wrong.


You can use the libraries as they are shipped, no need to change them.

Stefan

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


PyCObject_FromVoidPtr etc.

2011-03-22 Thread Fons Adriaensen
Hello all,

Upgrading to 3.2 has provided some sort of cold shower.

I have hundreds of extensions that fail to install due to
PyCObject_FromVoidPtr() and PyCObject_AsVoidPtr() not longer
being available, and I'm looking for a (hopefully) simple
solution.

In all cases, these are extensions that create an instance
of a C++ class which is purely a 'slave' to the corresponding
instance of a Python class.

They all follow a pattern illustrated by the following code:


---
#include "class_XX.h"


extern "C" void destroy (void *object)
{
Class_XX *C;

C = (Class_XX *) object;
delete P;
}


extern "C" PyObject* create (PyObject *self, PyObject *args)
{
Class_XX *C;
PyObject *P;
int a, b;

if (! PyArg_ParseTuple(args, "(Oii)", &P, &a, &b)) return NULL;
C = new Class_XX (P, a, b);
return PyCObject_FromVoidPtr((void *) C, destroy);
}


extern "C" PyObject* method_1 (PyObject *self, PyObject *args)
{
Class_XX *J;
PyObject *P;
int x, y;

if (! PyArg_ParseTuple(args, "(Oii)", &P, &x, &y)) return NULL;
C = (Class_XX *) PyCObject_AsVoidPtr(P);
P = Py_BuildValue ("(i)", C->method_1 (x, y));
Py_INCREF (P);
return P;
}

...

--


The C++ object stores a pointer to its Python equivalent (not needed
in most cases, only if there would be callbacks) and the Python object
stores a PyCObject corresponding to its C++ slave and uses this to call
its methods.

In no case there is any need of the C++ objects being visible anywhere
else, let alone in other extensions.

Is there a way to keep things (almost) as simple as this using the
'Capsules' ?? I do understand the advantage of having such a mechanism,
but in this case it's sort of overkill...

TIA,

-- 
FA






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


May I discuss here issues on Machine Learning?

2011-03-22 Thread joy99
Dear Group,

My apology to pose this non python question in this forum. I am trying
to develop one Naive Bayes Classifier and one HMM with Python. But my
question is not related to Python, rather to these two models, whether
I am choosing right parameters, etc for these models.

Python is a chosen language for machine learning and as I come here
pretty often I found this room is filled with very nice people. I
thought if some one would be interested to discuss the issues.

If any one wants to discuss personally if he/she can post his/her
name, I would discuss with him/her.

Sincerely sorry if I have broken norms of the room.

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


Re: Problem with re module

2011-03-22 Thread Ethan Furman

John Harrington wrote:

Here's a script that illustrates the problem.  Any help would be
appreciated!:

#BEGIN SCRIPT
import re

outlist = []
myfile  = "raw.tex"

fin = open(myfile, "r")
lineList = fin.readlines()
fin.close()

for i in range(0,len(lineList)):

 lineList[i]=re.sub(r'(\\begin{document})([^\n])',r'\1\n\n
\2',lineList[i])

 outlist.append(lineList[i])

fou = open(myfile, "w")
for i in range(len(outlist)):
   fou.write(outlist[i])
fou.close
#END SCRIPT

And the file raw.tex:

%BEGIN TeX FILE
\begin{document}
This line should remain right after the above line in the output, but
doesn't

\begin{document}Extra stuff here should appear below the begin line
and does in the output.
%END TeX FILE


Here's the important tidbit:

re.sub(r'(\\begin{document})(.+)', r'\1\n\n\2', line)

From the docs:
'.'
(Dot.) In the default mode, this matches any character except a newline. 
If the DOTALL flag has been specified, this matches any character 
including a newline.


'+'
Causes the resulting RE to match 1 or more repetitions of the preceding 
RE. ab+ will match ‘a’ followed by any non-zero number of ‘b’s; it will 
not match just ‘a’.



And here's the entire program, a bit more pythonically:

8<---
import re

outlist = []
myfile  = "raw.tex"

fin = open(myfile, "r")
lineList = fin.readlines()
fin.close()

for line in lineList:
 line = re.sub(r'(\\begin{document})(.+)', r'\1\n\n\2', line)
 outlist.append(line)

fou = open(myfile, "w")
for line in outlist:
   fou.write(line)
fou.close
8<---

Hope this helps!

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


Re: os.stat bug?

2011-03-22 Thread Dan Stromberg
On Mon, Mar 21, 2011 at 1:32 AM, Laszlo Nagy  wrote:

>
>  Hi All,
>
> I have a Python program that goes up to 100% CPU. Just like this (top):
>
>  PID USERNAME   THR PRI NICE   SIZERES STATE   C   TIME   WCPU
> COMMAND
> 80212 user1   2  440 70520K 16212K select  1   0:30 100.00%
> /usr/local/bin/python process_updates_ss_od.py -l 10
>
> I have added extra logs and it turns out that there are two threads. One
> thread is calling "time.sleep()" and the other is calling "os.stat" call.
> (Actually it is calling os.path.isfile, but I hunted down the last link in
> the chain.) The most interesting thing is that the process is in "SELECT"
> state. As far as I know, CPU load should be 0% because "select" state should
> block program execution until the I/O completes.
>
> I must also tell you that the os.stat call is taking long because this
> system has about 7 million files on a slow disk. It would be normal for an
> os.stat call to return after 10 seconds. I have no problem with that. But I
> think that the 100% CPU is not acceptable. I guess that the code is running
> in kernel mode. I think this because I can send a KILL signal to it and the
> state changes to the following:
>
>
>  PID USERNAME   THR PRI NICE   SIZERES STATE   C   TIME   WCPU
> COMMAND
> 80212 user1   2  440 70520K 15256K STOP5   1:27 100.00%
> /usr/local/bin/python process_updates_ss_od.py -l 10
>
> So the state of the process changes to "STOP", but the program does not
> stop until the os.stat call returns back (sometimes for 30 seconds).
>
> Could it be a problem with the operation system? Is it possible that an
> os.stat call requires 100% CPU power from the OS? Or is it a problem with
> the Python implementation?
>
> (Unfortunately I cannot give you an example program. Giving an example
> would require giving you a slow I/O device with millions of files on it.)
>
> OS version: FreeBSD 8.1-STABLE amd64
> Python version: 2.6.6
>
> Thanks,
>
>   Laszlo 


1) Run it under the "time" command, to break down the CPU use like the
following (on Ubuntu in this example, but your results may resemble these).
User time is from userspace (the python interpreter: time spent on your
code, including the Python standard library and C library), sys is the time
spent in the kernel related to your process.  Real is the wall-clock time.
If the kernel time is high, look into using a database or using a filesystem
(tweak) that supports large directories well.  If the userspace time is
high, scrutinize the code in more detail:

$ time python -c 'for i in xrange(10): pass'
cmd started 2011 Tue Mar 22 04:26:20 PM

real0m0.132s
user0m0.012s
sys 0m0.004s

2) Does FreeBSD's top command have an option to report on distinct threads
of a process individually?  Some top's do, but I'm not confident all of them
do.

3) Does the code run on Pypy?  If it does, it might be a lot faster.  The
difference can be pretty dramatic sometimes.

4) Profile it using something like profile or cProfile.  Sometimes the
issues so identified can be surprising.  This should tell you which part of
the code is consuming the most time.

5) If the process is staying in select state, then it's probably making
heavy use of the select syscall - conceivably more use of select than stat.
If there's a select in the code with a small timeout inside a loop, you
might check that over.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 Debug build

2011-03-22 Thread Benjamin Kaplan
On Tue, Mar 22, 2011 at 6:25 PM, Willis Cheung  wrote:
> Thanks for your answers. Just to make sure I do it correctly, is it the
> CPython package on http://hg.python.org the one which I should be
> downloading? Thanks again
>
>
>
> Wilis
>

If you want to compile your own copy of Python 3.2, you should
download one of the Python 3.2 source tar balls from
http://python.org/download/releases/3.2/

I suppose you could get the Python 3.2 source from Mercurial, but if
you don't know how Mercurial works, you'll probably end up downloading
the wrong commit- you'll get the latest commit instead of the stable
3.2 release.

>
>
> From: Santoso Wijaya [mailto:santoso.wij...@gmail.com]
> Sent: Thursday, March 17, 2011 6:05 PM
> To: Willis Cheung
> Cc: python-list@python.org
> Subject: Re: Python 3.2 Debug build
>
>
>
> Looks like something tripped over whitespaces in path names for svn tools.
> Try checking out a working copy from the hg repository?
>
>
>
> ~/santa
>
> On Thu, Mar 17, 2011 at 3:54 PM, Willis Cheung  wrote:
>
> Hi all,
>
> I'm trying to build the debug version of Python 3.2. I downloaded the py3k
> folder from the python SVN. Then I opened the pcbuild.sln and tried to build
> the "python" project. However the build failed when I got an error from the
> project "pythoncore" which I think "python" depends on? The error is:
>
> Cannot open source file: 'C:\Program
> Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c': No such
> file or directory.
>
> The log also mentioned the following couple lines before:
>
>
>
> 5>"C:\Program Files\TortoiseSVN\bin\subwcrev.exe" ..
> ..\Modules\getbuildinfo.c "C:\Program
> Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c"
> 5>'C:\Program' is not recognized as an internal or external command,
>
> I did get the debug build of python 2.7.1 and 3.1.3 to work successfully so
> I'm not quite sure if I'm supposed to do anything different for Python 3.2.
> Can anyone guide me on this? Thank you.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proxy authentication required

2011-03-22 Thread Chris Rebert
On Tue, Mar 22, 2011 at 3:57 AM, gervaz  wrote:
> On 22 Mar, 09:34, gervaz  wrote:
>> On 22 Mar, 00:02, Chris Rebert  wrote:
>> > On Mon, Mar 21, 2011 at 2:38 AM, gervaz  wrote:
>> > > Hi all,
>> > > I've got to download some web pages but I'm behind a proxy. So far
>> > > this is what I've used without any successful result receiving the
>> > > error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication
>> > > Required ( The ISA Server requires auth
>> > > orization to fulfill the request. Access to the Web Proxy filter is
>> > > denied.  )":
>>
>> > > hc = urllib.request.HTTPCookieProcessor()
>> > > hp = urllib.request.ProxyHandler({"http": "10.242.38.251:80",
>> > > "username": "domain\username", "password": "password"})

> Further investigating the issue the proxy needs NTLM authentication,
> for that reason no solution so far works. I'm using py3.

pycurl apparently supports NTLM proxies, but it's not Python 3-compatible:
http://pycurl.sourceforge.net/

python-ntlm seems to be Python 3-compatible, but I don't know whether
it handles proxying:
http://code.google.com/p/python-ntlm/

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


Re: PyCObject_FromVoidPtr etc.

2011-03-22 Thread Martin v. Loewis
> Is there a way to keep things (almost) as simple as this using the
> 'Capsules' ?? 

Most certainly. Instead of PyCObject_FromVoidPtr, use PyCapsule_New.
Either pass NULL as a name, or the class name for additional
type-safety. Instead of PyCObject_AsVoidPtr, use PyCapsule_GetPointer.
The only difference will be a change to the destructor function:
it gets the capsule now, rather than the embedded pointer.

> I do understand the advantage of having such a mechanism,
> but in this case it's sort of overkill...

It's the very same mechanism. The only difference is that capsules
are type-safe where CObjects were not. I.e. you can crash the
interpreter by passing in a bad CObject (one for a different type);
with capsules, this can be detected and a Python exception be raised.

Because of the additional type-safety, additional parameters are
needed, and because of that, a new name is needed. Nothing else
has changed.

In fact, you can do:

#if Python-version >= 3.2 (proper test left to the reader)
#define  PyCObject_FromVoidPtr(C, ignored_destroy)
   PyCapsule_New(C, "mymod.Class_XX", destroy_32)
#define PyCObject_AsVoidPtr(P) PyCapsule_GetPointer(P, "mymod.Class_XX")
extern "C" void destroy_32(PyObject *P){
  destroy(PyCapsule_GetPointer(P, "mymod.Class_XX"));
}
#endif

This wouldn't do proper type-checking yet - all callers
of PyCObject_AsVoidPtr then should add

   if (C == NULL) return NULL;

which still should be backwards-compatible with 3.1 and earlier
(in which versions you actually also should check for NULL, since
 even PyCObject_AsVoidPointer can fail, esp. if you are passing
 something that isn't a PyCObject).

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


file print extra spaces

2011-03-22 Thread monkeys paw

When i open a file in python, and then print the
contents line by line, the printout has an extra blank
line between each printed line (shown below):

>>> f=open('authors.py')
>>> i=0
>>> for line in f:
print(line)
i=i+1
if i > 14:
break


author_list = {

  '829337' : {

'author_name' : 'Carter, John',

'count' : 49,

'c2' : '0.102040816326531',

How can i print the file out without having an extra newline between
printed lines?

Thanks for the help all.
--
http://mail.python.org/mailman/listinfo/python-list


Re: file print extra spaces

2011-03-22 Thread bruce bushby
Run your script and "pipe" the output to "| od -c"  the octal dumper will
show you what characters you're printing.I'm guessing python's "print"
is adding one and each line in your file contains another.

You can also use a "," in python I forget the exact syntax, something
like "print(line),"  to prevent the carriage return from "print", but
ideally you should clean up the line if it's contaminated without unexpected
characters.


Bruce



On Wed, Mar 23, 2011 at 1:33 AM, monkeys paw  wrote:

> When i open a file in python, and then print the
> contents line by line, the printout has an extra blank
> line between each printed line (shown below):
>
> >>> f=open('authors.py')
> >>> i=0
> >>> for line in f:
>print(line)
>i=i+1
>if i > 14:
>break
>
>
> author_list = {
>
>  '829337' : {
>
>'author_name' : 'Carter, John',
>
>'count' : 49,
>
>'c2' : '0.102040816326531',
>
> How can i print the file out without having an extra newline between
> printed lines?
>
> Thanks for the help all.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file print extra spaces

2011-03-22 Thread Alex Willmer
On Mar 23, 1:33 am, monkeys paw  wrote:
> When i open a file in python, and then print the
> contents line by line, the printout has an extra blank
> line between each printed line (shown below):
>
>  >>> f=open('authors.py')
>  >>> i=0
>  >>> for line in f:
>         print(line)
>         i=i+1
>         if i > 14:
>                 break
>
> author_list = {
>
>                    '829337' : {
>
>                                  'author_name' : 'Carter, John',
>
>                                  'count' : 49,
>
>                                  'c2' : '0.102040816326531',
>
> How can i print the file out without having an extra newline between
> printed lines?
>
> Thanks for the help all.

What you are seeing is 1 newline from the original file, and a second
newline from the print() function. To resolve this use either
print(line, end='') or sys.stdout.write(line).

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


Re: file print extra spaces

2011-03-22 Thread Thomas L. Shinnick

At 08:33 PM 3/22/2011, monkeys paw wrote:

When i open a file in python, and then print the
contents line by line, the printout has an extra blank
line between each printed line (shown below):

>>> f=open('authors.py')
>>> i=0
>>> for line in f:
print(line)
i=i+1
if i > 14:
break


Try
print(line.rstrip())

Your 'line' text value must still have line endings in it.  .rstrip() 
will remove trailing whitespace on the right.  print() will then do 
its own line ending.


Answer I don't know: why are the line endings still in the text values?



author_list = {

  '829337' : {

'author_name' : 'Carter, John',

'count' : 49,

'c2' : '0.102040816326531',

How can i print the file out without having an extra newline between
printed lines?

Thanks for the help all.
--
http://mail.python.org/mailman/listinfo/python-list


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


Re: file print extra spaces

2011-03-22 Thread MRAB

On 23/03/2011 01:33, monkeys paw wrote:

When i open a file in python, and then print the
contents line by line, the printout has an extra blank
line between each printed line (shown below):

 >>> f=open('authors.py')
 >>> i=0
 >>> for line in f:
print(line)
i=i+1
if i > 14:
break


author_list = {

'829337' : {

'author_name' : 'Carter, John',

'count' : 49,

'c2' : '0.102040816326531',

How can i print the file out without having an extra newline between
printed lines?

Thanks for the help all.


Each line read from the file still includes its line ending, and
'print' normally prints a newline at the end, which is why you're
getting a blank line.

You could stop the print from printing its newline:

print(line, end="") # Python 3

or:

print line, # Python 2

or you could strip the newline off what you're printing:

print(line.rstrip('\n'))
--
http://mail.python.org/mailman/listinfo/python-list


Re: file print extra spaces

2011-03-22 Thread MRAB

On 23/03/2011 01:54, Thomas L. Shinnick wrote:

At 08:33 PM 3/22/2011, monkeys paw wrote:

When i open a file in python, and then print the
contents line by line, the printout has an extra blank
line between each printed line (shown below):

>>> f=open('authors.py')
>>> i=0
>>> for line in f:
print(line)
i=i+1
if i > 14:
break


Try
print(line.rstrip())

Your 'line' text value must still have line endings in it. .rstrip()
will remove trailing whitespace on the right. print() will then do its
own line ending.

Answer I don't know: why are the line endings still in the text values?


[snip]

Because they are in the file.

Iterating over the file yields a line at a time (like file.readline()).
All but the last line will have a line ending; the last line may.

You might want to know what is actually in the file, including whether
the last line has a line ending or not, so you don't always want to
drop it, if present.
--
http://mail.python.org/mailman/listinfo/python-list


Re: May I discuss here issues on Machine Learning?

2011-03-22 Thread Ben Finney
joy99  writes:

> My apology to pose this non python question in this forum. I am trying
> to develop one Naive Bayes Classifier and one HMM with Python. But my
> question is not related to Python, rather to these two models, whether
> I am choosing right parameters, etc for these models.
>
> Python is a chosen language for machine learning and as I come here
> pretty often I found this room is filled with very nice people. I
> thought if some one would be interested to discuss the issues.

It would be much better to use a forum dedicated to that topic.

One reason why people in this forum remain nice is because discussions
tend to stay on-topic and therefore widely useful :-)

> Sincerely sorry if I have broken norms of the room.

Not yet, and thank you for checking first.

-- 
 \“Spam will be a thing of the past in two years' time.” —Bill |
  `\ Gates, 2004-01-24 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: having both dynamic and static variables

2011-03-22 Thread John Ladasky
On Mar 5, 9:44 pm, John Nagle  wrote:

>     All functions in Python can be replaced dynamically. While they're
> running. From another thread.  Really.

Indeed, and I find this feature VERY useful when coding.  Two places
I've used it are:

1) in GUI coding (say, when I have a panel of buttons, and each one
has its own associated function in my code -- but that function's name
is not part of the object definition itself) and

2) when profiling code, and I'm trying out various versions of a
function. For example, I'll write:

   for func in (func1, func2, func3):
   # do something with func()
-- 
http://mail.python.org/mailman/listinfo/python-list


All types of Management careers.

2011-03-22 Thread gaurav
Rush for Perfect computer part time online home jobs to earn
unlimited.
http://rojgars1.webs.com/gov.htmhttp://rojgars.webs.com/bankingjobs.htm

Management careers to earn extra.
Employments in Management careers.
http://managementjobs.webs.com/pm.htm http://jobshunter.webs.com/index.htm
-- 
http://mail.python.org/mailman/listinfo/python-list