回复: my multi-download program can't finish

2011-09-08 Thread 守株待兔
sometimes,the output is:
error: [Errno 104] Connection reset by peer 
-- 原始邮件 --
发件人: "Steven D'Aprano";
发送时间: 2011年9月8日(星期四) 中午1:08
收件人: "python-list"; 

主题: Re: my  multi-download program can't finish

 
On Thu, 8 Sep 2011 02:24 pm 守株待兔 wrote:

[...]
>  try:
>  url = jobs.get()
>  hx = httplib2.Http()
>  resp, content = hx.request(url, headers=headers)
>  jobs.task_done()
>  except:
>  print  "wrong" , url

> when it run ,it can download someting ,
> it is strang:there is wrong output ,some web can't get,but  the program
> can't stop,it stay ,run ,can't fininsh, i don't know why?

If you read the helpful error messages that Python provides, instead of
hiding them and printing a useless message "wrong", you might find out why
the failures are happening.

Get rid of the try...except and see what exceptions you get. Then you will
be in a better situation to decide which exceptions should be caught, and
which are bugs that need to be fixed, and which should be allowed through.



-- 
Steven

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


Re: how to make fxn argument work with setting a field value

2011-09-08 Thread noydb
> The documentation mentions "getValue" and "setValue":
>
> http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00...- 
> Hide quoted text -
>
> - Show quoted text -

I have tried row.setValue(rankFld) = i for line 14.  Get syntax error
- cant assign to function call
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable locale usage

2011-09-08 Thread Laszlo Nagy



I have set the system-wide locale to Croatian (Croatia)
on my development system as instructed by:
http://windows.microsoft.com/en-US/windows-vista/Change-the-system-locale

Nevertheless, your proposal produces:
('English_United States','1252')

This is what I see on my Hungarian Windows:


C:\Users\User>python
Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit 
(AMD64)] on

win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'Hungarian_Hungary.1250'
>>> locale.getlocale()
('Hungarian_Hungary', '1250')
>>>

So I'm 100% sure that the problem is with your system locale settings, 
not Python.



Note that I would very much like
to avoid changing the system locale
(this requires Administrator password and system restart).
All right. But you understand, that Croatian ISO8859-2 is not supported 
on windows? So you will not be able to sort names with that under a 
windows system? (And it is not a limitation of Python.)

Why are you trying to force a specific locale to your program anyway?

Because I wish to be able to correctly sort Croatian names.
Well, all right. If you want to sort Croatian names from a program that 
runs on an English (or whatever) system, then you will have to check the 
platform and use a locale that is supported by the platform. (But again, 
this is not Python's limitation. Python doesn't know what encodings are 
supported, in advance, and you cannot use a locale that is not supported...)

I expect that most of my Windows users will not care
to configure their computers with the national locale
(and besides, that does not seem to work, anyway).
Croatian users will most likely use a Croatian Windows, out of the box. 
And on those systems, using locale.setlocale(locale.LC_ALL, '') will 
work perfectly. I'm not sure why it doesn't work on an English Windows 
with locale changed... I'm not a big fan of Windows, but I remember once 
I had to install a language pack for Windows before I could use a 
localized program. This might be what you need?


Best,

   Laszlo

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


Re: How to structure packages

2011-09-08 Thread Dan Sommers
On Thu, 08 Sep 2011 10:29:26 +1000, Steven D'Aprano wrote:

> I suppose "one class per file" might be useful for those using an editor
> with no search functionality. Other than that, is there any
> justification for this rule? Any Java fans want to defend this?

Back in the dark ages known as the 1980s, we had a one-C-function-per-
file rule on a project with tens of thousands of C functions.  The big 
benefit was that we always knew which source file contained which 
function.  Computers could search a directory tree much more quickly than 
that much source code.  (The exception was the so-called Information 
Cluster, a collection of functions surrounding a data store, the 
predecessor to the modern day object-with-state and/or closure).

Not a Java fan'ly yours,
Dan

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


DRY and class variables

2011-09-08 Thread egbert
My classes correspond to sql tables.
In these classes I want to have several class variables
that refer to data that are common to all instances.

The assignment statements for the class variables are the same
in all classes, except that of these instructions needs the name
of the class itself. That name is used to read a file with meta-data.

So what I have now is something like this (simplified):

class TableOne(object):
m = Metadata('TableOne')
m.do_something()
def __init__(self):
etc

class TableTwo(object):
m = Metadata('TableTwo')
m.do_something()
def __init__(self):
etc

I have tried:
- to eliminate the class name argument, but in this phase of the
  object creation __class__ and __name__ are not available
- to move the two statements to a superclass, but the class variables
  come in the superclass namespace, not in the subclass namespace.

Any ideas ?
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


Re: DRY and class variables

2011-09-08 Thread Thomas Jollans
On 08/09/11 11:55, egbert wrote:
> My classes correspond to sql tables.
> In these classes I want to have several class variables
> that refer to data that are common to all instances.
> 
> The assignment statements for the class variables are the same
> in all classes, except that of these instructions needs the name
> of the class itself. That name is used to read a file with meta-data.
> 
> So what I have now is something like this (simplified):
> 
> class TableOne(object):
> m = Metadata('TableOne')
> m.do_something()
> def __init__(self):
> etc
> 
> class TableTwo(object):
> m = Metadata('TableTwo')
> m.do_something()
> def __init__(self):
> etc
> 
> I have tried:
> - to eliminate the class name argument, but in this phase of the
>   object creation __class__ and __name__ are not available
> - to move the two statements to a superclass, but the class variables
>   come in the superclass namespace, not in the subclass namespace.
> 
> Any ideas ?

You should be able to do this with a metaclass (almost certainly
overkill), or with a class decorator (Python 2.6+):

def with_metadata (cls):
cls.m = Metadata (cls.__name__)
cls.m.do_something ()
return cls

@with_metadata
class TableOne:
   # foo
   pass

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


Re: How to structure packages

2011-09-08 Thread Jonathan Hartley
On Thursday, September 8, 2011 1:29:26 AM UTC+1, Steven D'Aprano wrote:
> Steven D'Aprano wrote:
> 
> Other than that, is there any justification
> for this rule? Any Java fans want to defend this?
>
> If "one class per file", why not "one method per class" too? Why is the
> second rule any more silly than the first?


Hey. I'm not a Java fan but I'll give it a go.

One method per class is not a good idea because a class is a bunch of code that 
forms a coherent conceptual bundle of functionality. Often, to provide such a 
bundle, it requires more than one method. To split these methods across several 
classes would be splitting up a single coherent entity, which makes it harder 
to understand the purpose and identity of the entity, and more fiddly to 
delineate the boundary between one such entity and the next.

On the other hand, IMHO one class per file is often a good idea. Since a class 
is a single coherent bundle, then the natural way to split a program into files 
is often to divide it into these same coherent bundles. Sometimes you have two 
or more classes that are conceptually very tightly coupled, and it makes sense 
to gather them up into a single file. However, for me, this is the exception 
rather than the rule, so in the general case, I usually end up with code that 
has one class per file. It's only a rule-of-thumb though, and should be broken 
whenever it seems appropriate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] relaxing keyword usage restrictions

2011-09-08 Thread Adam Jorgensen
About the only keyword I can think of this being even slightly useful for
would be class and even then I think that clazz is a pretty acceptable
substitute.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with simple OOP Python question

2011-09-08 Thread Piet van Oostrum
Terry Reedy  writes:

> Indexing objects by their internal id is usually useless. 

obj.id is not the internal id. 
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing WebDAV server

2011-09-08 Thread Piet van Oostrum
"Fokke Nauta"  writes:

> "Piet van Oostrum"  wrote in message 
> news:[email protected]...
>> "Fokke Nauta"  writes:
>>
>>
>>> INFO:DAVServer.fshandler:get_data: d:\webdav not found
>>> XXX --- [07/Sep/2011 11:57:48] - Mozilla/5.0 UJindows NT 5.1; rv:6.0.1>
>>> Gecko/
>>> 20100101 Firefox/6.0.1 - "GET / HTTP/1.1" 404 -
>>> XXX --- [07/Sep/2011 11:57:52] - Mozilla/5.0 
>>> Gecko/
>>> 20100101 Firefox/6.0.1 - "GET / HTTP/1.1" 404 -
>>>
>> From the log it looks like you are trying to access the server with the
>> url:
>>
>> http://localhost:8008/ or something similar.
>
> Yes, I do.
>
>> This won't work as you would try to access the root of your webdav
>> directory in this way (i.e. D:/webdav). The webdav server can only serve
>> files, not directories, so you would have to access
>> http://localhost:8008/somefile.txt where somefile.txt is a file in
>> D:/webdav.
>
> OK, thanks. I am not familiar to WebDAV.
> I tried. Got something different (at least something happened):
> "Setuptools version 0.6c9 or greater has been installed.
> (Run "ez_setup.py -U setuptools" to reinstall or upgrade.)"
>
> Wasn't able to find ez_setup.py yet.
>
Google for it and install.

But I don't understand. You already had WebDav installed, so why do you
need ez_setup.py?

>> This only applies to acces using a browser. If you access the server
>> through a webdav-aware client (for example the Finder on Mac OS X, or
>> probably the Windows Explorer) it can serve the contents of the directory.
>> -- 
>
> Thanks. I am just trying to use a calendar with a webdav server. I don't 
> have any experience with that.
> Simply using my browser to try it out.

Did you try the calendar with the WebDav server running?
Dit you put a file in D:\webdav and try to get it with the browser?

-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lfun and such

2011-09-08 Thread Chris Angelico
On Thu, Sep 8, 2011 at 10:09 PM, Marc Dirix  wrote:
> scratch that.
>
> Silly me.
>

Heh. I'm curious now as to what was wrong, but am glad it's all
working! I just switched back from my test run where I made a minimal
class implementing `[]() and `[]=() to see if there was something
weirdly wrong.

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


Create an index from a webpage

2011-09-08 Thread Simon Cropper

Hi,

I am getting dizzy on google.

I am after a way of pointing a python routine to my website and have it 
create a tree, represented as a hierarchical HTML list in a webpage, of 
all the pages in that website (recursive list of internal links to HTML 
documents; ignore images, etc.).


It is essentially a contents page or sitemap for the site.

Interestingly, despite trying quite a few keyword combinations, I was 
unable to find such a script.


Anyone have any ideas?

--
Cheers Simon

   Simon Cropper - Open Content Creator / Website Administrator

   Free and Open Source Software Workflow Guides
   
   Introduction   http://www.fossworkflowguides.com
   GIS Packages   http://gis.fossworkflowguides.com
   bash / Pythonhttp://scripting.fossworkflowguides.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Create an index from a webpage

2011-09-08 Thread Thomas 'PointedEars' Lahn
Simon Cropper wrote:

> I am after a way of pointing a python routine to my website and have it
> create a tree, represented as a hierarchical HTML list in a webpage, of
> all the pages in that website (recursive list of internal links to HTML
> documents; ignore images, etc.).
> 
> It is essentially a contents page or sitemap for the site.



If all else fails, use markup parsers like 

- 
- 

and write it yourself.  It is not hard to do.

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing WebDAV server

2011-09-08 Thread Fokke Nauta
"Piet van Oostrum"  wrote in message 
news:[email protected]...
> "Fokke Nauta"  writes:
>
>> "Piet van Oostrum"  wrote in message
>> news:[email protected]...
>>> "Fokke Nauta"  writes:
>>>
>>>
 INFO:DAVServer.fshandler:get_data: d:\webdav not found
 XXX --- [07/Sep/2011 11:57:48] - Mozilla/5.0 UJindows NT 5.1; rv:6.0.1>
 Gecko/
 20100101 Firefox/6.0.1 - "GET / HTTP/1.1" 404 -
 XXX --- [07/Sep/2011 11:57:52] - Mozilla/5.0 
 Gecko/
 20100101 Firefox/6.0.1 - "GET / HTTP/1.1" 404 -

>>> From the log it looks like you are trying to access the server with the
>>> url:
>>>
>>> http://localhost:8008/ or something similar.
>>
>> Yes, I do.
>>
>>> This won't work as you would try to access the root of your webdav
>>> directory in this way (i.e. D:/webdav). The webdav server can only serve
>>> files, not directories, so you would have to access
>>> http://localhost:8008/somefile.txt where somefile.txt is a file in
>>> D:/webdav.
>>
>> OK, thanks. I am not familiar to WebDAV.
>> I tried. Got something different (at least something happened):
>> "Setuptools version 0.6c9 or greater has been installed.
>> (Run "ez_setup.py -U setuptools" to reinstall or upgrade.)"
>>
>> Wasn't able to find ez_setup.py yet.
>>
> Google for it and install.

I did.

> But I don't understand. You already had WebDav installed, so why do you
> need ez_setup.py?

Well, that was my mistake. I entered in the browser 
http://10.0.0.140:8081/a.txt (one of the textfiles in the directory 
d:\webdav on the server) and got the message:
"Setuptools version 0.6c9 or greater has been installed.
(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)"

At first I thought this came from the webdav server. That's why I searched 
for the ez_setup.py script. Once it was there, I ran it.
It took me some time before I realized it was the actual content of the 
document a.txt on the webdav server what I saw. So it worked! Different that 
I expected, but it works.

>>> This only applies to acces using a browser. If you access the server
>>> through a webdav-aware client (for example the Finder on Mac OS X, or
>>> probably the Windows Explorer) it can serve the contents of the 
>>> directory.
>>> -- 
>>
>> Thanks. I am just trying to use a calendar with a webdav server. I don't
>> have any experience with that.
>> Simply using my browser to try it out.
>
> Did you try the calendar with the WebDav server running?

Not yet. The next step is the calendar.

> Dit you put a file in D:\webdav and try to get it with the browser?

Yes, and that worked! I am able to see the contents of text files.
In my unfamiliarity with WebDAV I expected to open the directory and see the 
files in there.

Many thanks for your help.

Fokke


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


wrap the queue to multiprocess download

2011-09-08 Thread alias
here is my part of program,you can see main structure,i want to wrap it in 
class ,
class   webdata(object):
def  __init__(self,arg):
jobs = Queue.Queue()
for  x  in  name:
jobs.put(self.url)


  
def download(self):
while not self.jobs.empty():
url = self.jobs.get()
hx = httplib2.Http()
resp, content = hx.request(url, headers=headers).read()
self.jobs.task_done()


def  myrun(self):
for i in range(30):
  threading.Thread(target=self.download).start()
self.jobs.join()

if  __name__=="__main__":

s=webdata('quote')
s.myrun()

when it run ,the output is  :
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
  File "/home/pengtao/workspace/try.py", line 75, in download
resp, content = hx.request(url, headers=headers).read()
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 
1288, in request
(scheme, authority, request_uri, defrag_uri) = urlnorm(uri)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 201, 
in urlnorm
(scheme, authority, path, query, fragment) = parse_uri(uri)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 197, 
in parse_uri
groups = URI.match(uri).groups()
TypeError: expected string or buffer


when i use the same  structrue, don't   wrap it ,it can run .-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Anyone here familiar with installing Open Watcom F77?

2011-09-08 Thread W. eWatson

On 9/5/2011 9:36 AM, Colin J. Williams wrote:

On 05-Sep-11 12:22 PM, Dan Nagle wrote:

Hello,

On 2011-09-05 16:15:20 +, W. eWatson said:


On 9/5/2011 8:24 AM, Chris Angelico wrote:

On Tue, Sep 6, 2011 at 1:15 AM, W. eWatson
wrote:

See Subject.





To what extent "familiar"? I have it installed on several computers,

but only because it comes with Open Wat C/C++.

With something off-topic like this,





sierra_mtnview @ sbcglobal.net

Here's the story.

As far as I can tell F77 1.8 is not available. I've Googled quite a
bit for it. My source for 1.9 is
. It gives me:
open-watcom-f77-win32-1.9.exe.


On Usenet, comp.lang.fortran might be the best source of help for this.
There's a good chance one of the regulars there can answer you
within one or two posts. (I'll not cross-post, you can choose for
yourself.)

HTH



You might get in touch with someone at Waterloo University, which is
located in Kitchener/Waterloo.

This could have come from the 60's or 70's.

Good luck.

Colin W.

Left a message on Tuesday. No return call. I'm starting to make progress 
on this.

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


Re: Installing WebDAV server

2011-09-08 Thread Fokke Nauta
"Fokke Nauta"  wrote in message 
news:[email protected]...
> Hi all,
>
> I am completely new to Python, but I'm confronted with a problem I can't 
> solve.
> This is my question:
>
> I'm running a PC with XP Pro32, which acts as a file server/print 
> server/FTP server and web server. The web server is facilitated by the 
> Aprelium Abyss X2 server, and has Perl and PHP support on http and https. 
> It all works fine.
> To do some research with some calender systems and to share the Outlook 
> calendar I need a WebDAV server. After googling I found the Python WebDAV 
> server.
> I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. 
> Now I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 
> and PyXML-0.8.4. In the PyWebDAV README it says:
>
> Installation and setup of server can be as easy as follows:
>
> $ easy_install PyWebDAV
> $ davserver -D /tmp -n -J
>
> But of course it doesn't work like that. When I start up Python GUI I see 
> the ">>>" prompt instead of the "$" prompt. But where do I place the two 
> directories? And there is no easy_install script in the PyXML-0.8.4 
> directory, only a setup.py and ez_setup.py script. I guess the latter is 
> the one to use. But how?
>
> How do I proceed next?
>
> Any help will be appreciated.
> Thanks in advance.
>
> With regards,
> Fokke Nauta
>

I have my webdav server up and running.

Many thanks for all who contributed to solving this problem.

With regards,
Fokke Nauta 


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


Re: Best way to check that you are at the beginning (the end) of an iterable?

2011-09-08 Thread Chris Torek
In article 
Cameron Simpson   wrote:
>Facilities like feof() in C and eof in Pascal already lead to lots of
>code that runs happily with flat files and behaves badly in interactive
>or piped input. It is _so_ easy to adopt a style like:
>
>  while not eof(filehandle):
>line = filehandle.nextline()
>...

Minor but important point here: eof() in Pascal is predictive (uses
a "crystal ball" to peer into the future to see whether EOF is is
about to occur -- which really means, reads ahead, causing that
interactivity problem you mentioned), but feof() in C is "post-dictive".
The feof(stream) function returns a false value if the stream has
not yet encountered an EOF, but your very next attempt to read from
it may (or may not) immediately encounter that EOF.

Thus, feof() in C is sort of (but not really) useless.  (The actual
use cases are to distinguish between "EOF" and "error" after a
failed read from a stream -- since C lacks exceptions, getc() just
returns EOF to indicate "failed to get a character due to end of
file or error" -- or in some more obscure cases, such as the
nonstandard getw(), to distinguish between a valid -1 value and
having encountered an EOF.  The companion ferror() function tells
you whether an earlier EOF value was due to an error.)
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wrap the queue to multiprocess download

2011-09-08 Thread Chris Angelico
On Fri, Sep 9, 2011 at 12:12 AM, alias <[email protected]> wrote:
>     def  __init__(self,arg):
>     for  x  in  name:
>
>     s=webdata('quote')

What you're doing here is iterating over the letters in the string
'quote'. It's adding one job for each letter. Is that your intention?

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


Re: how to make fxn argument work with setting a field value

2011-09-08 Thread MRAB

On 08/09/2011 08:59, noydb wrote:

The documentation mentions "getValue" and "setValue":

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00...- Hide 
quoted text -

- Show quoted text -


I have tried row.setValue(rankFld) = i for line 14.  Get syntax error
- cant assign to function call


Of course you can't assign to a function call!

It's:

row.setValue(rankFld, value)

and:

value = row.getValue(rankFld)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Create an index from a webpage

2011-09-08 Thread Steven D'Aprano
Thomas 'PointedEars' Lahn wrote:

> 

[climbs up on the soapbox and begins rant]

Please don't use lmgtfy. The joke, such as it is, stopped being funny about
three years ago. It's just annoying, and besides, it doesn't even work
without Javascript. Kids today have no respect, get off my lawn, grump
grump grump...

It's no harder to put the search terms into a google URL, which still gets
the point across without being a dick about it:

www.google.com/search?q=python+sitemap

[ends rant, climbs back down off soapbox]

Or better still, use a search engine that doesn't track and bubble your
searches:

https://duckduckgo.com/html/?q=python+sitemap

You can even LMDDGTFY if you insist.

http://lmddgtfy.com/


Completely-undermining-my-own-message-ly y'rs, 


-- 
Steven

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


Re: my multi-download program can't finish

2011-09-08 Thread MRAB

On 08/09/2011 05:24, 守株待兔 wrote:

here is the program,

# basic structure,omit something
import Queue
import httplib2
import threading
jobs = Queue.Queue()
name=something   #omit ,it is a web list to download
for  x  in  name:
  jobs.put(x)

def download():
while not jobs.empty():
try:
url = jobs.get()
hx = httplib2.Http()
resp, content = hx.request(url, headers=headers)
jobs.task_done()
except:
print  "wrong" , url

if __name__ == '__main__':

for i in range(10):
  threading.Thread(target=download).start()
jobs.join()

when it run ,it can download someting ,
it is strang:there is wrong output ,some web can't get,but  the 
program can't stop,it stay ,run ,can't fininsh,

i don't know why?


The line:

jobs.join()

will wait until every job has been marked as done by:

jobs.task_done()

In function "download", if there's an exception, it will go to the 
exception handler and print a message, but there's no:


jobs.task_done()

there to tell the queue that the job has been done.

You need to tell it when a job has been processed. It doesn't care 
whether a job succeeded or failed, only whether it has been processed.

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


Re: Portable locale usage

2011-09-08 Thread Siniša Šegvić
> From: "Laszlo Nagy" 
> To: "Siniša Šegvić" , [email protected]
> Sent: Thursday, September 8, 2011 10:41:22 AM
> Subject: Re: Portable locale usage
> > I have set the system-wide locale to Croatian (Croatia)
> > on my development system as instructed by:
> > http://windows.microsoft.com/en-US/windows-vista/Change-the-system-locale
> >
> > Nevertheless, your proposal produces:
> > ('English_United States','1252')
> This is what I see on my Hungarian Windows:
> 
> 
> C:\Users\User>python
> Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit
> (AMD64)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import locale
> >>> locale.setlocale(locale.LC_ALL, '')
> 'Hungarian_Hungary.1250'
> >>> locale.getlocale()
> ('Hungarian_Hungary', '1250')
> >>>
> 
> So I'm 100% sure that the problem is with your system locale settings,
> not Python.

I've just found out how to set the user locale on Windows.

One has to go to Control panel -> Regional and language options,
then select the tab named Formats, and finally 
set the box Current format to the desired language, 
which is in my case Croatian (Croatia).

The whole tab says nothing about locales, I found this by try and test.
This recipe is not affected by the system locale (which I was setting before)!

Now locale.setlocale(locale.LC_ALL, '') sets the Croatian locale.

> > I expect that most of my Windows users will not care
> > to configure their computers with the national locale
> > (and besides, that does not seem to work, anyway).
> Croatian users will most likely use a Croatian Windows, out of the
> box.
> And on those systems, using locale.setlocale(locale.LC_ALL, '') will
> work perfectly. 

Yes it's true, you were right, I was setting 
the Croatian language at the wrong place
(I am not a Windows fan neither, I normally work on Linux).

However, I am not completely happy with this.
OK, no need for system restart, but still,
it would be nice if Python program could
manage around this by itself, 
of course, provided that the required locale is installed.

> > Note that I would very much like
> > to avoid changing the system locale
> > (this requires Administrator password and system restart).
> All right. But you understand, that Croatian ISO8859-2 is not
> supported on windows? 

Yes I do understand that.

I have commented that the Python's locale aliasing engine
should not propose iso8859-2 on Windows systems,
exactly for the reason you mention.


> >> Why are you trying to force a specific locale to your program
> >> anyway?
> > Because I wish to be able to correctly sort Croatian names.
> Well, all right. If you want to sort Croatian names from a program that
> runs on an English (or whatever) system, then you will have to check the
> platform and use a locale that is supported by the platform. (But again,
> this is not Python's limitation. Python doesn't know what encodings are
> supported, in advance, and you cannot use a locale that is not supported...)

I fully agree.

I commented that, if a proper locale is installed,
the following should work on any system:

locale.setlocale(locale.LC_ALL, ('hr', locale.getpreferredencoding())) 

Currently the above does not work on Windows,
and that is because the locale_alias for 'hr'
is bound to 'hr_HR.ISO8859-2'.
Check the source: .../Python-3.2.2/Lib/locale.py, line 537

I was arguing that, on a Windows system, 
the locale_alias for 'hr' should be bound 
to 'Croatian_Croatia.1250'.

Cheers,

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


Re: DRY and class variables

2011-09-08 Thread Eric Snow
On Thu, Sep 8, 2011 at 3:55 AM, egbert  wrote:
> My classes correspond to sql tables.
> In these classes I want to have several class variables
> that refer to data that are common to all instances.
>
> The assignment statements for the class variables are the same
> in all classes, except that of these instructions needs the name
> of the class itself. That name is used to read a file with meta-data.
>
> So what I have now is something like this (simplified):
>
> class TableOne(object):
>    m = Metadata('TableOne')
>    m.do_something()
>    def __init__(self):
>        etc
>
> class TableTwo(object):
>    m = Metadata('TableTwo')
>    m.do_something()
>    def __init__(self):
>        etc
>
> I have tried:
> - to eliminate the class name argument, but in this phase of the
>  object creation __class__ and __name__ are not available
> - to move the two statements to a superclass, but the class variables
>  come in the superclass namespace, not in the subclass namespace.
>
> Any ideas ?

Definitely an interesting problem I've run into before.  Here are two solutions:

1. in Python 3, use the metaclass __prepare__()  (see
http://code.activestate.com/recipes/577813/);
2. in Python 2 or 3, use a descriptor to defer creating your Metadata
objects until after the class object is available (see
http://code.activestate.com/recipes/577745/).

HTH

-eric

> e
> --
> Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


replace random matches of regexp

2011-09-08 Thread gry
[Python 2.7]
I have a body of text (~1MB) that I need to modify.   I need to look
for matches of a regular expression and replace a random selection of
those matches with a new string.  There may be several matches on any
line, and a random selection of them should be replaced.  The
probability of replacement should be adjustable.  Performance is not
an issue.  E.g: if I have:

SELECT max(PUBLIC.TT.I) AS SEL_0 FROM (SCHM.T RIGHT OUTER JOIN
PUBLIC.TT ON (SCHM.T.I IS NULL)) WHERE (NOT(NOT((power(PUBLIC.TT.F,
PUBLIC.TT.F) = cast(ceil(( SELECT 22 AS SEL_0FROM
(PUBLIC.TT AS PUBLIC_TT_0 JOIN PUBLIC.TT AS PUBLIC_TT_1 ON (ceil(0.46)
=sin(PUBLIC_TT_1.F)))WHERE ((zeroifnull(PUBLIC_TT_0.I) =
sqrt((0.02 + PUBLIC_TT_1.F))) OR

I might want to replace '(max|min|cos|sqrt|ceil' with "public.\1", but
only with probability 0.7.  I looked and looked for some computed
thing in re's that I could stick and expression, but could not find
such(for good reasons, I know).
Any ideas how to do this?  I would go for simple, even if it's wildly
inefficient, though elegance is always admired...
-- 
http://mail.python.org/mailman/listinfo/python-list


Symposium “Experimental and Computational Bio-Imaging and Visualization” within ICEM15 – Announce & Call for Papers

2011-09-08 Thread [email protected]
Dear Colleague,

Within the 15th International Conference on Experimental Mechanics
(ICEM15), to be held in Faculty of Engineering, University of Porto,
Porto, Portugal, in July 22-27, 2012, (www.fe.up.pt/clme/icem15/
index.htm), we are organizing a Symposium on “Experimental and
Computational Bio-Imaging and Visualization”.
The main goal of the Symposium “Experimental and Computational Bio-
Imaging and Visualization” is to bring together researchers,
developers and clinicians involved in the related fields of Bio-
Imaging and Visualization, including Biomechanics, Experimental
Biomechanics, Image Processing and Analysis, Medical Imaging,
Mechanobiology, Tissues Engineering, Scientific Visualization and
Software and Hardware Development, in order to set the major lines of
development for the near future and establish a bridge between them.

INSTRUCTIONS & SUBMISSION:

- For instructions and submission, please access to the conference
website at:
www.fe.up.pt/clme/icem15/index.htm;
- Please, note that, when submitting your work, you should indicate
the Symposium “Experimental and Computational Bio-Imaging and
Visualization”.

IMPORTANT DATES:

- Submission of abstracts: 30 November, 2011;
- Notification of acceptance: 13 January, 2012;
- Submission of full-papers: 16 March, 2012.

Kind regards,

João Manuel R. S. Tavares (University of Porto, Portugal,
[email protected])
Yongjie Zhang (Carnegie Mellon University, USA,
[email protected])
(Symposium organizers)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replace random matches of regexp

2011-09-08 Thread MRAB

On 08/09/2011 20:51, gry wrote:

[Python 2.7]
I have a body of text (~1MB) that I need to modify.   I need to look
for matches of a regular expression and replace a random selection of
those matches with a new string.  There may be several matches on any
line, and a random selection of them should be replaced.  The
probability of replacement should be adjustable.  Performance is not
an issue.  E.g: if I have:

SELECT max(PUBLIC.TT.I) AS SEL_0 FROM (SCHM.T RIGHT OUTER JOIN
PUBLIC.TT ON (SCHM.T.I IS NULL)) WHERE (NOT(NOT((power(PUBLIC.TT.F,
PUBLIC.TT.F) = cast(ceil(( SELECT 22 AS SEL_0FROM
(PUBLIC.TT AS PUBLIC_TT_0 JOIN PUBLIC.TT AS PUBLIC_TT_1 ON (ceil(0.46)
=sin(PUBLIC_TT_1.F)))WHERE ((zeroifnull(PUBLIC_TT_0.I) =
sqrt((0.02 + PUBLIC_TT_1.F))) OR

I might want to replace '(max|min|cos|sqrt|ceil' with "public.\1", but
only with probability 0.7.  I looked and looked for some computed
thing in re's that I could stick and expression, but could not find
such(for good reasons, I know).
Any ideas how to do this?  I would go for simple, even if it's wildly
inefficient, though elegance is always admired...


re.sub can accept a function as the replacement. It'll call the
function when it finds a match, and the string returned by that
function will be the replacement.

You could write a function which returns either the original substring
which was found or a different substring.
--
http://mail.python.org/mailman/listinfo/python-list


Re: replace random matches of regexp

2011-09-08 Thread André Malo
* gry wrote:

> I might want to replace '(max|min|cos|sqrt|ceil' with "public.\1", but
> only with probability 0.7.  I looked and looked for some computed
> thing in re's that I could stick and expression, but could not find
> such(for good reasons, I know).
> Any ideas how to do this?  I would go for simple, even if it's wildly
> inefficient, though elegance is always admired...

You can run a re.sub() with a function as replacement value. This function
then either returns the replacement or the original match based on a
weighted random value.

nd
-- 
"Umfassendes Werk (auch fuer Umsteiger vom Apache 1.3)"
  -- aus einer Rezension


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


Re: replace random matches of regexp

2011-09-08 Thread Peter Otten
gry wrote:

> [Python 2.7]
> I have a body of text (~1MB) that I need to modify.   I need to look
> for matches of a regular expression and replace a random selection of
> those matches with a new string.  There may be several matches on any
> line, and a random selection of them should be replaced.  The
> probability of replacement should be adjustable.  Performance is not
> an issue.  E.g: if I have:
> 
> SELECT max(PUBLIC.TT.I) AS SEL_0 FROM (SCHM.T RIGHT OUTER JOIN
> PUBLIC.TT ON (SCHM.T.I IS NULL)) WHERE (NOT(NOT((power(PUBLIC.TT.F,
> PUBLIC.TT.F) = cast(ceil(( SELECT 22 AS SEL_0FROM
> (PUBLIC.TT AS PUBLIC_TT_0 JOIN PUBLIC.TT AS PUBLIC_TT_1 ON (ceil(0.46)
> =sin(PUBLIC_TT_1.F)))WHERE ((zeroifnull(PUBLIC_TT_0.I) =
> sqrt((0.02 + PUBLIC_TT_1.F))) OR
> 
> I might want to replace '(max|min|cos|sqrt|ceil' with "public.\1", but
> only with probability 0.7.  I looked and looked for some computed
> thing in re's that I could stick and expression, but could not find
> such(for good reasons, I know).
> Any ideas how to do this?  I would go for simple, even if it's wildly
> inefficient, though elegance is always admired...

def make_sub(text, probability):
def sub(match):
if random.random() < probability:
return text + match.group(1)
return match.group(1)
return sub

print re.compile("(max|min|cos|sqrt|ceil)").sub(make_sub(r"public.", .7), 
sample)

or even

def make_sub(text, probability):
def sub(match):
if random.random() < probability:
def group_sub(m):
return match.group(int(m.group(1)))
return re.compile(r"[\\](\d+)").sub(group_sub, text)
return match.group(0)
return sub

print re.compile("(max|min|cos|sqrt|ceil)").sub(make_sub(r"public.\1", .7), 
sample)


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


Re: DRY and class variables

2011-09-08 Thread egbert
On Thu, Sep 08, 2011 at 12:22:33PM +0200, Thomas Jollans wrote:
> You should be able to do this with a metaclass (almost certainly
> overkill), or with a class decorator (Python 2.6+):
> 
> def with_metadata (cls):
> cls.m = Metadata (cls.__name__)
> cls.m.do_something ()
> return cls
> 
> @with_metadata
> class TableOne:
># foo
>pass
Overnight I have become a decorator fan.
I can postpone the study of metaclasses.
Thanks.
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

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


Re: replace random matches of regexp

2011-09-08 Thread gry
On Sep 8, 3:51 pm, gry  wrote:
To elaborate(always give example of desired output...) I would hope to
get something like:

SELECT public.max(PUBLIC.TT.I) AS SEL_0 FROM (SCHM.T RIGHT OUTER JOIN
PUBLIC.TT ON (SCHM.T.I IS NULL)) WHERE (NOT(NOT((power(PUBLIC.TT.F,
PUBLIC.TT.F) = cast(ceil(( SELECT 22 AS SEL_0FROM
(PUBLIC.TT AS PUBLIC_TT_0 JOIN PUBLIC.TT AS PUBLIC_TT_1 ON
(public.ceil(0.46)
=public.sin(PUBLIC_TT_1.F)))WHERE ((zeroifnull(PUBLIC_TT_0.I)
=
public.sqrt((0.02 + PUBLIC_TT_1.F))) OR

notice the 'ceil' on the third line did not get changed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Django or web2py

2011-09-08 Thread Paul Watson

I have read some of the talk around these two frameworks.

Would you say that web2py is more geared toward the enterprise?

Which one do you believe will be on Python 3 more quickly?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to check that you are at the beginning (the end) of an iterable?

2011-09-08 Thread Cameron Simpson
On 08Sep2011 14:21, Chris Torek  wrote:
| In article 
| Cameron Simpson   wrote:
| >Facilities like feof() in C and eof in Pascal already lead to lots of
| >code that runs happily with flat files and behaves badly in interactive
| >or piped input. It is _so_ easy to adopt a style like:
| >
| >  while not eof(filehandle):
| >line = filehandle.nextline()
| >...
| 
| Minor but important point here: eof() in Pascal is predictive (uses
| a "crystal ball" to peer into the future to see whether EOF is is
| about to occur -- which really means, reads ahead, causing that
| interactivity problem you mentioned), but feof() in C is "post-dictive".
| The feof(stream) function returns a false value if the stream has
| not yet encountered an EOF, but your very next attempt to read from
| it may (or may not) immediately encounter that EOF.

Thanks. I had forgotten this nuance. Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

  "Where am I?"
"In the Village."
   "What do you want?"
 "Information."
"Whose side are you on?"
"That would be telling. We want information. Information. Information!"
   "You won't get it!"
 "By hook or by crook, we will."
 "Who are you?"
   "The new number 2."
   "Who is number 1?"
   "You are number 6."
  "I am not a number, I am a free man!"
   [Laughter]
-- 
http://mail.python.org/mailman/listinfo/python-list


Processing a file using multithreads

2011-09-08 Thread Abhishek Pratap
Hi Guys

My experience with python is 2 days and I am looking for a slick way
to use multi-threading to process a file. Here is what I would like to
do which is somewhat similar to MapReduce in concept.

# test case

1. My input file is 10 GB.
2. I want to open 10 file handles each handling 1 GB of the file
3. Each file handle is processed in by an individual thread using the
same function ( so total 10 cores are assumed to be available on the
machine)
4. There will be 10 different output files
5. once the 10 jobs are complete a reduce kind of function will
combine the output.

Could you give some ideas ?

So given a file I would like to read it in #N chunks through #N file
handles and process each of them separately.

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


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Simon Cropper

On 09/09/11 01:11, Steven D'Aprano wrote:

[SNIP]
It's no harder to put the search terms into a google URL, which still gets
the point across without being a dick about it:

> [SNIP]

[RANT]

OK I was not going to say anything but...

1. Being told to google-it when I explicitly stated in my initial post 
that I had been doing this and had not been able to find anything is 
just plain rude. It is unconstructive and irritating.


2. I presume that python-list is a mail list for python users - 
beginners, intermediate and advanced. If it is not then tell me and I 
will go somewhere else.


3. Some searches, particularly for common terms throw millions of hits. 
'Python' returns 147,000,000 results on google, 'Sitemap' returns 
1,410,000,000 results. Even 'Python AND Sitemap' still returns 5,020 
results. Working through these links takes you round and round with no 
clear solutions. Asking for help on the primary python mail list -- 
after conducting a preliminary investigation for tools, libraries, code 
snippets seemed legitimate.


4. AND YES, I could write a program but why recreate code when there is 
a strong likelihood that code already exists. One of the advantages of 
python is that a lot of code is redistributed under licences that 
promote reuse. So why reinvent the wheel when their is a library full of 
code. Sometimes you just need help finding the door.


4. If someone is willing to help me, rather than lecture me (or poke me 
to see if they get a response), I would appreciate it.


[END RANT]

For people that are willing to help. My original request was...

I am after a way of pointing a python routine to my website and have it
create a tree, represented as a hierarchical HTML list in a webpage, of
all the pages in that website (recursive list of internal links to HTML
documents; ignore images, etc.).

In subsequent notes to Thomas 'PointedEars'...

I pointed to an example of the desired output here 
http://lxml.de/sitemap.html


--
Cheers Simon

   Simon Cropper - Open Content Creator / Website Administrator

   Free and Open Source Software Workflow Guides
   
   Introduction   http://www.fossworkflowguides.com
   GIS Packages   http://gis.fossworkflowguides.com
   bash / Pythonhttp://scripting.fossworkflowguides.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: killing a script

2011-09-08 Thread Cameron Simpson
On 30Aug2011 14:13, Steven D'Aprano  
wrote:
| On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote:
| >> Yes, but if I am not mistaken, that will require me to put a line or
| >> two after each os.system call. That's almost like whack-a-mole at the
| >> code level rather than the Control-C level. OK, not a huge deal for
| >> one script, but I was hoping for something simpler. I was hoping I
| >> could put one line at the top of the script and be done with it.
| > 
| > Write a function!  That's what they're for after all :)
| 
| I'm not sure that this is actually as simple as that, especially using
| os.system.
| 
| As I understand it, the scenario is this:
| 
| The main script looks something like this:
| 
| for x in whatever:
| os.system('something.py x')
| 
| Each time through the loop, a new Python process is started. Each process
| runs in the foreground, capturing standard input, and so hitting Ctrl-C
| kills *that* process, not the main script. Unless, by chance, the Ctrl-C
| happens after the system call returns, but before the next one starts, it
| is completely invisible to the parent process (the main script). Wrapping
| os.system in a function does nothing to fix that.

Presuming you're talking about UNIX, this is not correct.

Ctrl-C at the terminal delivers SIGINT to _every_ process in the controlling
process group for the terminal. It also has _nothing_ to do with the standard
input.

When you run a script, yea even a Python script, thus:

  myscript ...

then job control capable shells (all of them, these days) put the python
process running "myscript" in its own process group as the leader
(being, initially, the only process in the group). If myscript forks
other processes, as happens in os.system(), they are _also_ in that
process group. _ALL_ of them receive the SIGINT from your Ctrl-C.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

DRM: the functionality of refusing to function. - Richard Stallman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Processing a file using multithreads

2011-09-08 Thread Gregory Ewing

Abhishek Pratap wrote:


3. Each file handle is processed in by an individual thread using the
same function ( so total 10 cores are assumed to be available on the
machine)


Are you expecting the processing to be CPU bound or
I/O bound?

If it's I/O bound, multiple cores won't help you, and
neither will threading, because it's the disk doing the
work, not the CPU.

If it's CPU bound, multiple threads in one Python process
won't help, because of the GIL. You'll have to fork
multiple OS processes in order to get Python code running
in parallel on different cores.

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


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Rhodri James
On Fri, 09 Sep 2011 00:40:42 +0100, Simon Cropper  
 wrote:



On 09/09/11 01:11, Steven D'Aprano wrote:

[SNIP]
It's no harder to put the search terms into a google URL, which still  
gets

the point across without being a dick about it:

 > [SNIP]

[RANT]

OK I was not going to say anything but...


Ahem.  You should expect a certain amount of ribbing after admitting that  
your Google-fu is weak.  So is mine, but hey.


4. If someone is willing to help me, rather than lecture me (or poke me  
to see if they get a response), I would appreciate it.


The Google Python Sitemap Generator  
(http://www.smart-it-consulting.com/article.htm?node=166&page=128, fourth  
offering when you google "map a website with Python") looks like a  
promising start.  At least it produces something in XML -- filtering that  
and turning it into HTML should be fairly straightforward.



--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to structure packages

2011-09-08 Thread Nobody
On Thu, 08 Sep 2011 10:29:26 +1000, Steven D'Aprano wrote:

> I suppose "one class per file" might be useful for those using an editor
> with no search functionality. Other than that, is there any justification
> for this rule? Any Java fans want to defend this?

Not a Java fan, but:

The Java compiler also acts as a "make" program. If it doesn't find
a .class file for a needed class, it will search for the corresponding
.java file and compile that. So to compile a complex program, you only
need to compile the top-level file (e.g. HelloWorld.java), and it will
compile everything which is required. No Makefile is needed, as the
relationship between classes, object files and source files is fixed.

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


Python: Deleting specific words from a file.

2011-09-08 Thread papu
Hello, I have a data file (un-structed messy file) from which I have
to scrub specific list of words (delete words).

Here is what I am doing but with no result:

infile = "messy_data_file.txt"
outfile = "cleaned_file.txt"

delete_list = ["word_1","word_2","word_n"]
new_file = []
fin=open(infile,"")
fout = open(outfile,"w+")
for line in fin:
for word in delete_list:
line.replace(word, "")
fout.write(line)
fin.close()
fout.close()

I have put the code above in a file. When I execute it, I dont see the
result file. I am not sure what the error is. Please let me know what
I am doing wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python: Deleting specific words from a file.

2011-09-08 Thread MRAB

On 09/09/2011 02:09, papu wrote:

Hello, I have a data file (un-structed messy file) from which I have
to scrub specific list of words (delete words).

Here is what I am doing but with no result:

infile = "messy_data_file.txt"
outfile = "cleaned_file.txt"

delete_list = ["word_1","word_2","word_n"]
new_file = []
fin=open(infile,"")
fout = open(outfile,"w+")
for line in fin:
 for word in delete_list:
 line.replace(word, "")
 fout.write(line)
fin.close()
fout.close()

I have put the code above in a file. When I execute it, I dont see the
result file. I am not sure what the error is. Please let me know what
I am doing wrong.


The .replace method _returns_ its result.

Strings are immutable, they can't be changed in-place.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Processing a file using multithreads

2011-09-08 Thread Dave Angel

On 01/-10/-28163 02:59 PM, Abhishek Pratap wrote:

Hi Guys

My experience with python is 2 days and I am looking for a slick way
to use multi-threading to process a file. Here is what I would like to
do which is somewhat similar to MapReduce in concept.

# test case

1. My input file is 10 GB.
2. I want to open 10 file handles each handling 1 GB of the file
3. Each file handle is processed in by an individual thread using the
same function ( so total 10 cores are assumed to be available on the
machine)
4. There will be 10 different output files
5. once the 10 jobs are complete a reduce kind of function will
combine the output.

Could you give some ideas ?

So given a file I would like to read it in #N chunks through #N file
handles and process each of them separately.

Best,
-Abhi

You should probably forget threads, and simply do them as 10 separate 
processes, all launched by a single parent.  Since they don't share any 
state, there's no need to get the inefficiency of threads.


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


Re: How to structure packages

2011-09-08 Thread Chris Angelico
On Fri, Sep 9, 2011 at 10:45 AM, Nobody  wrote:
> The Java compiler also acts as a "make" program. If it doesn't find
> a .class file for a needed class, it will search for the corresponding
> .java file and compile that. So to compile a complex program, you only
> need to compile the top-level file (e.g. HelloWorld.java), and it will
> compile everything which is required. No Makefile is needed, as the
> relationship between classes, object files and source files is fixed.
>

If that's the entire benefit, then I think this is a rather hefty
price to pay for the elimination of a makefile. Oh wow, I can type
"javac MyClass.java" and it picks up all the others! If you're
dividing a project into multiple files already, is it that hard to
have one more that defines the relationships between the others?

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


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Simon Cropper

On 09/09/11 10:32, Rhodri James wrote:

On Fri, 09 Sep 2011 00:40:42 +0100, Simon Cropper

Ahem. You should expect a certain amount of ribbing after admitting that
your Google-fu is weak. So is mine, but hey.


I did not admit anything. I consider my ability to find this quite good 
actually. Others assumed that my "Google-fu is weak".





4. If someone is willing to help me, rather than lecture me (or poke
me to see if they get a response), I would appreciate it.


The Google Python Sitemap Generator
(http://www.smart-it-consulting.com/article.htm?node=166&page=128,
fourth offering when you google "map a website with Python") looks like
a promising start. At least it produces something in XML -- filtering
that and turning it into HTML should be fairly straightforward.



I saw this in my original search. My conclusions were..

1. The last update was in 2005. That is 6 years ago. In that time we 
have had numerous upgrades to HTML, Logs, etc.
2. The script expects to run on the webserver. I don't have the ability 
to run python on my webserver.
3. There are also a number of dead-links and redirects to Google 
Webmaster Central / Tools, which then request you submit a sitemap (as I 
alluded we get into a circular confusing cross-referencing situation)
4. The ultimate product - if you can get the package to work - would be 
a XML file you would need to massage to extract what you needed.


To me this seems like overkill.

I assume you could import the parent html file, scrap all the links on 
the same domain, dump these to a hierarchical list and represent this in 
HTML using BeautifulSoup or something similar. Certainly doable but 
considering the shear commonality of this task I don't understand why a 
simple script does not already exist - hence my original request for 
assistance.


It would appear from the feedback so far this 'forum' is not the most 
appropriate to ask this question. Consequently, I will take your advice 
and keep looking... and if I don't find something within a reasonable 
time frame, just write something myself.


--
Cheers Simon

   Simon Cropper - Open Content Creator / Website Administrator

   Free and Open Source Software Workflow Guides
   
   Introduction   http://www.fossworkflowguides.com
   GIS Packages   http://gis.fossworkflowguides.com
   bash / Pythonhttp://scripting.fossworkflowguides.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Steven D'Aprano
Simon Cropper wrote:

> 1. Being told to google-it when I explicitly stated in my initial post
> that I had been doing this and had not been able to find anything is
> just plain rude. It is unconstructive and irritating.

Why so you did. Even though I wasn't the one who told you to google it, I'll
apologise too because I was thinking the same thing. Sorry about that.


> 3. Some searches, particularly for common terms throw millions of hits.
> 'Python' returns 147,000,000 results on google, 'Sitemap' returns
> 1,410,000,000 results. Even 'Python AND Sitemap' still returns 5,020
> results. 

How about "python generate a site map"? The very first link on DuckDuckGo is
this:

http://www.conversationmarketing.com/2010/08/python-sitemap-crawler-1.htm

Despite the domain, there is actual Python code on the page. Unfortunately
it looks like crappy code with broken formatting and a mix of <\br> tags,
but it's a start.

Searching for "site map" on PyPI returns a page full of hits:

http://pypi.python.org/pypi?%3Aaction=search&term=site+map&submit=search

Most of them seem to rely on a framework like Django etc, but you might find
something useful.


> 4. AND YES, I could write a program but why recreate code when there is
> a strong likelihood that code already exists.

"Strong" likelihood? Given how hard it is to find an appropriate sitemap
generator written in Python, I'd say there is a strong likelihood that one
that meets your needs and is publicly available under an appropriate
licence is vanishingly small.

If you do decide to write your own, please consider uploading it to PyPI
under a FOSS licence.



-- 
Steven

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


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Steven D'Aprano
Simon Cropper wrote:

> Certainly doable but
> considering the shear commonality of this task I don't understand why a
> simple script does not already exist

Perhaps it isn't as common or as simple as you believe.



-- 
Steven

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


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Simon Cropper

On 09/09/11 12:14, Steven D'Aprano wrote:

If you do decide to write your own, please consider uploading it to PyPI
under a FOSS licence.


At present I am definitely getting the impression that my assumption 
that something like this' must out there', is wrong.


I am following people's links and suggestions (as well as my own; I have 
spent 1-2 hours looking) but have not found anything that is able to be 
used with only minor adjustments.


I have found a XML-Sitemaps Generator at http://www.xml-sitemaps.com,
this page allows you to create the XML files that can be uploaded to 
google. But as stated I don't actually want what people now call 
'sitemaps' I want a automatically updated 'index / contents page' to my 
website. For example, if I add a tutorial or update any of my links I 
want the 'global contents page' to be updated when the python script is run.


I am now considering how I might address this requirement. If I create a 
python script I will post it on PyPI. As with all my work it will be 
released under the GPLv3 licence.


Thanks for your help.

--
Cheers Simon

   Simon Cropper - Open Content Creator / Website Administrator

   Free and Open Source Software Workflow Guides
   
   Introduction   http://www.fossworkflowguides.com
   GIS Packages   http://gis.fossworkflowguides.com
   bash / Pythonhttp://scripting.fossworkflowguides.com
--
http://mail.python.org/mailman/listinfo/python-list


Using web2py and deck.js to make HTML5 presentation

2011-09-08 Thread chinakr
web2py is one of the most popular Web Frameworks. web2py has MVC
architecture, offering us excellent development efficiency and
extensibility. web2py is very suitable for Web application
development.

deck.js is a JavaScript library for making HTML5 presentation. It
supports keyboard navigation, themes switching and extensions. With
deck.js, making HTML5 presentation becomes easy, beautiful and
convinient.

SEO Brief Guide is a HTML5 presentation developing with web2py and
deck.js, wich is free and open source.

Demo:
http://openclass.vstudy.cn/seo/training

Source code:
http://vstudy.htexam.net/soft/download/web2py.app.openclass.w2p
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Chris Angelico
On Fri, Sep 9, 2011 at 12:43 PM, Simon Cropper
 wrote:
> At present I am definitely getting the impression that my assumption that
> something like this' must out there', is wrong.
>
> I have found a XML-Sitemaps Generator at http://www.xml-sitemaps.com,
> this page allows you to create the XML files that can be uploaded to google.
> But as stated I don't actually want what people now call 'sitemaps' I want a
> automatically updated 'index / contents page' to my website. For example, if
> I add a tutorial or update any of my links I want the 'global contents page'
> to be updated when the python script is run.

What you're looking at may be closer to autogenerated documentation
than to a classic site map. There are a variety of tools that generate
HTML pages on the basis of *certain information found in* all the
files in a directory (as opposed to the entire content of those
files). What you're trying to do may be sufficiently specific that it
doesn't already exist, but it might be worth having a quick look at
autodoc/doxygen - at least for some ideas.

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


buffer() as argument to ctypes function which expects c_void_p?

2011-09-08 Thread Jack Bates
How do you pass a Python buffer() value as an argument to a ctypes
function, which expects a c_void_p argument? I keep getting TypeError:

ctypes.ArgumentError: argument 2: : wrong type
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Simon Cropper

On 09/09/11 12:59, Chris Angelico wrote:

On Fri, Sep 9, 2011 at 12:43 PM, Simon Cropper
  wrote:

At present I am definitely getting the impression that my assumption that
something like this' must out there', is wrong.

I have found a XML-Sitemaps Generator at http://www.xml-sitemaps.com,
this page allows you to create the XML files that can be uploaded to google.
But as stated I don't actually want what people now call 'sitemaps' I want a
automatically updated 'index / contents page' to my website. For example, if
I add a tutorial or update any of my links I want the 'global contents page'
to be updated when the python script is run.


What you're looking at may be closer to autogenerated documentation
than to a classic site map. There are a variety of tools that generate
HTML pages on the basis of *certain information found in* all the
files in a directory (as opposed to the entire content of those
files). What you're trying to do may be sufficiently specific that it
doesn't already exist, but it might be worth having a quick look at
autodoc/doxygen - at least for some ideas.

Chris Angelico


Chris,

You assessment is correct. Working through the PyPI I am having better 
luck with using different terms than the old-term 'sitemap'.


I have found a link to funnelweb which uses the transmogrify library 
(yeah, as if I would have typed this term into google!) that is 
described as "Crawl and parse static sites and import to Plone".


http://pypi.python.org/pypi/funnelweb/1.0

As funnelweb is modular, using a variety of the transmogrify tools, 
maybe I could modify this to create a 'non-plone' version.


--
Cheers Simon

   Simon Cropper - Open Content Creator / Website Administrator

   Free and Open Source Software Workflow Guides
   
   Introduction   http://www.fossworkflowguides.com
   GIS Packages   http://gis.fossworkflowguides.com
   bash / Pythonhttp://scripting.fossworkflowguides.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python: Deleting specific words from a file.

2011-09-08 Thread John Gordon
In <30f9b718-bb3c-4c92-8a03-0f760c993...@a12g2000yqi.googlegroups.com> papu 
 writes:

> Hello, I have a data file (un-structed messy file) from which I have
> to scrub specific list of words (delete words).

> Here is what I am doing but with no result:

> infile = "messy_data_file.txt"
> outfile = "cleaned_file.txt"

> delete_list = ["word_1","word_2","word_n"]
> new_file = []

What does new_file do?  I don't see it used anywhere.

> fin=open(infile,"")

There should be an "r" inside those quotes.  In fact this is an error
and it will stop your program from running.

> fout = open(outfile,"w+")

What is the "+" supposed to do?

> for line in fin:
> for word in delete_list:
> line.replace(word, "")

replace() returns the modified string; it does not alter the existing
string.

Do this instead:

  line = line.replace(word, "")

> fout.write(line)
> fin.close()
> fout.close()

> I have put the code above in a file. When I execute it, I dont see the
> result file. I am not sure what the error is. Please let me know what
> I am doing wrong.

When you say you don't see the result file, do you mean it doesn't get
created at all?

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Create an index from a webpage [RANT, DNFTT]

2011-09-08 Thread Chris Angelico
On Fri, Sep 9, 2011 at 1:20 PM, Simon Cropper
 wrote:
> Chris,
>
> You assessment is correct. Working through the PyPI I am having better luck
> with using different terms than the old-term 'sitemap'.
>
> I have found a link to funnelweb which uses the transmogrify library (yeah,
> as if I would have typed this term into google!) that is described as "Crawl
> and parse static sites and import to Plone".
>

And once again, python-list has turned a rant into a useful,
informative, and productive thread :)

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


Re: Processing a file using multithreads

2011-09-08 Thread aspineux
On Sep 9, 12:49 am, Abhishek Pratap  wrote:
> Hi Guys
>
> My experience with python is 2 days and I am looking for a slick way
> to use multi-threading to process a file. Here is what I would like to
> do which is somewhat similar to MapReduce in concept.
>
> # test case
>
> 1. My input file is 10 GB.
> 2. I want to open 10 file handles each handling 1 GB of the file
> 3. Each file handle is processed in by an individual thread using the
> same function ( so total 10 cores are assumed to be available on the
> machine)
> 4. There will be 10 different output files
> 5. once the 10 jobs are complete a reduce kind of function will
> combine the output.
>
> Could you give some ideas ?

You can use "multiprocessing" module instead of thread to bypass the
GIL limitation.

First cut your file in 10 "equal" parts. If it is line based search
for the first line
close to the cut. Be sure to have "start" and "end" for each parts,
start is the address of the
first character of the first line and end is one line too much (==
start of the next block)

Then use this function to handle each part .

def handle(filename, start, end)
  f=open(filename)
  f.seek(start)
  for l in f:
start+=len(l)
if start>=end:
  break
# handle line l here
print l

Do it first in a single process/thread to be sure this is ok (easier
to debug) then split in multi processes


>
> So given a file I would like to read it in #N chunks through #N file
> handles and process each of them separately.
>
> Best,
> -Abhi

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


wholesale all brand(UGGBOOTS, SHOES, CLOTHES, HANDBAG, WATCH, JEANS, JERSEY, T-SHIRT, SHIRTS, HOODY, EYEGLASS, CAP, SHAWL, WALLT) and so on.

2011-09-08 Thread amy
wholesale all brand shoes(NIKE,ADIDAS,LV,GUCCI,CHANEL,PRADA,POLO,UGG
BOOTS,D&G,DIOR )and so on.
paypal payment wholesale all brand clothing(T-
SHIRT,JEANS,JERSEY,HOODIES,JACKETS,HARDY,SWEATER,SHIRTS )and so on .
http://www.24hour-buy.com/
paypal payment all brand
watch(ROLEX,OMEGA,CHANEL,LV,CARTIER,IWC,GUCCI,RADO )and so on.
paypal payment all brand
handbag(LV,GUCCI,CHANEL,PRADA,POLO,COACH,FENDI,CHLOE,BUBERRY,JUICY)
and so on.
paypal payment brand CAP,SHAWL,BELT,WALLET,UNDER WEAR)and so on.

More detail land,address:  http://www.24hour-buy.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django or web2py

2011-09-08 Thread Vineet
On Sep 9, 3:29 am, Paul Watson  wrote:
> I have read some of the talk around these two frameworks.
>
> Would you say that web2py is more geared toward the enterprise?
>
> Which one do you believe will be on Python 3 more quickly?

Both Django & web2py are good frameworks.
I have tried both of them + others & then chosen a hybrid of web2py +
DABO bizobj for my work.
(DABO is a desktop app framework; so I have chosen only the BizObj
layer from it, which can do its job in any other python web or desktop
framework).

Typically, my apps are data-centric business apps.
web2py wins in simplycity yet powerfullness, no install, no
dependencies, good docs & community, low learning curve, etc.

DABO BizObj excels in managing the business logic aspect (including
managing multiple tables insert/update/delete, rollback, before
insert, after save, ... the list is quite long)

http://web2py.com
www.web2pyclices.com
http://thewinecellarbook.com/daboDocTestAlt/dabo.lib.datanav.Bizobj.Bizobj.html
http://dabodev.com/

Also, there are threads in stackoverflow.com which discuss in-depth
the +1 & -1 for these frameworks.
Contributors to these threads include the lead developers including
Massimo himself.

Hope this helps.

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


TypeError: object.__init__() takes no parameters

2011-09-08 Thread Oliver
Hello together,

let me be honest with you, I am a poor programmer who can only do
Perl.
I tried to code a program in Perl, but found that another guy already
finished this job in Python.
Unlucky for me, this guy is now CEO of a company, not really
interested in supporting his old code.

If I want to run shapes.py I receive this error message:

=== error message ===

C:\Documents and Settings\mhg\Desktop\palcalc>shapes.py
EE...
==
ERROR: test_fits (__main__.containerTests)
--
Traceback (most recent call last):
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
265, in test_fits
cont = Container()
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
90, in __init__
super(Container, self).__init__(xsize, ysize)
TypeError: object.__init__() takes no parameters

==
ERROR: test_place_bin (__main__.containerTests)
--
Traceback (most recent call last):
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
257, in test_place_bin
cont = Container()
  File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
90, in __init__
super(Container, self).__init__(xsize, ysize)
TypeError: object.__init__() takes no parameters

--
Ran 5 tests in 0.032s

FAILED (errors=2)

=== end of error message ===

Snippets of source code:

Line 264 - 268

def test_fits(self):
cont = Container()
cont.place_bin(0, 0, 210, 280)
self.assertEqual(False, cont.fits(Rectangle(0, 210, 280,
420)))
self.assertEqual(True, cont.fits(Rectangle(0, 280, 280, 490)))

Line 87 - 93

class Container(object):
"""Container to store  a number of non-overlapping rectangles."""
def __init__(self, xsize=1200, ysize=800):
super(Container, self).__init__(xsize, ysize)
self.rect = Rectangle(0, 0, xsize, ysize)
self.boxes = []
self.last_placement_strategy = 0

Line 254 - 262

class containerTests(unittest.TestCase):
"""Tests for container objects."""
def test_place_bin(self):
cont = Container()
cont.place_bin(0, 0, 40, 40)
self.failUnlessRaises(RuntimeError, cont.place_bin, 0, 0, 40,
40)
cont = Container()
cont.place_bin(0, 0, 210, 280)
self.failUnlessRaises(RuntimeError, cont.place_bin, 0, 210,
280, 420)

I think this is the main function:

if __name__ == '__main__':
unittest.main()

I do not know if I posted what you need to help me, it just would ease
my life a lot. If you need more information please let me know - if
you want you can even be unfriendly to me :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python: Deleting specific words from a file.

2011-09-08 Thread Terry Reedy

On 9/8/2011 9:09 PM, papu wrote:

Hello, I have a data file (un-structed messy file) from which I have
to scrub specific list of words (delete words).

Here is what I am doing but with no result:

infile = "messy_data_file.txt"
outfile = "cleaned_file.txt"

delete_list = ["word_1","word_2","word_n"]
new_file = []
fin=open(infile,"")
fout = open(outfile,"w+")
for line in fin:
 for word in delete_list:
 line.replace(word, "")
 fout.write(line)
fin.close()
fout.close()


If you have very many words (and you will need all possible forms of 
each word if you do exact matches), The following (untested and 
incomplete) should run faster.


delete_set = {"word_1","word_2","word_n"}
...
for line in fin:
for word in line.split()
if word not in delete_set:
fout.write(word) # also write space and nl.


Depending on what your file is like, you might be better with 
re.split('(\W+)', line). An example from the manual:

>>> re.split('(\W+)', '...words, words...')
['', '...', 'words', ', ', 'words', '...', '']

so all non-word separator sequences are preserved and written back out 
(as they will not match delete set).


--
Terry Jan Reedy

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


Re: TypeError: object.__init__() takes no parameters

2011-09-08 Thread Ben Finney
Oliver  writes:

> let me be honest with you, I am a poor programmer who can only do
> Perl.

I strongly suspect you could do more than that.

Welcome to the Python discussion forum.

> I tried to code a program in Perl, but found that another guy already
> finished this job in Python. Unlucky for me, this guy is now CEO of a
> company, not really interested in supporting his old code.

Then he can hardly complain if someone else re-writes it in their
language of choice, can he? :-)

> C:\Documents and Settings\mhg\Desktop\palcalc>shapes.py
> EE...

This, and the rest of your output, is from the call to ‘unittest.main’,
Python's standard-library module for unit testing.

>   File "C:\Documents and Settings\mhg\Desktop\palcalc\shapes.py", line
> 90, in __init__
> super(Container, self).__init__(xsize, ysize)
> TypeError: object.__init__() takes no parameters

The ‘super(Container, self)’ call asks for a ‘super’ object representing
the (next) superclass of the type of ‘self’.

In this case, as the error message indicates, the next superclass type
is ‘object’ – the base type of all objects. Also as the error message
indicates, the initialiser for ‘object’ doesn't accept the parameters
being passed.

> class Container(object):
> """Container to store  a number of non-overlapping rectangles."""
> def __init__(self, xsize=1200, ysize=800):
> super(Container, self).__init__(xsize, ysize)
> self.rect = Rectangle(0, 0, xsize, ysize)
> self.boxes = []
> self.last_placement_strategy = 0

So, there's no sense in calling the superclass's ‘__init__’ method with
parameters which won't be accepted because of the function signature.


The next thing to do is to ask about the design of these classes (what
is the intention of this initialiser?). But you say you're entirely new
to it, and that the designer has no interest in it. What are your
options for getting their interest and participating in this thread?

-- 
 \ “I cannot conceive that anybody will require multiplications at |
  `\   the rate of 40,000 or even 4,000 per hour …” —F. H. Wales, 1936 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list