Re: Representation of floats (-> Mark Dickinson?)

2011-09-07 Thread Mark Dickinson
On Sep 7, 4:58 am, casevh  wrote:
> IIRC, Python
> 3.2 changed (for floats) __str__ to call __repr__.

Yes, exactly:  str and repr of a float are identical in Python 3.2 +

I'm also puzzled by the

2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
[...]
>>> 1.1 * 1.1
1.21

in jmf's message.  Cut-and-paste typo?

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


Re: Advice on how to get started with 2D-plotting ?

2011-09-07 Thread Weinhandl Herbert

Am 06.09.2011 20:27, schrieb Fred Pacquier:

Hi,

I'm a Python long-timer, but I've never had to use tools like Matplotlib&
others before.

Now, for my work, I would need to learn the basics fast, for a one-time
quick-n-dirty job.

This involves a graphic comparison of RFC1918 IP subnets allocation across
several networks.



maybe networkx
  http://pypi.python.org/pypi/networkx/1.5
  http://networkx.lanl.gov/
is a better solution for your problem
or
http://pypi.python.org/pypi/graphcanvas/4.0.0


The idea is to draw parallel lines, with segments (subnets) coloured green,
yellow or red depending on the conflicts between the networks.

What would be the simplest/fastest way of getting this done ?
(the graphic parts, the IP stuff I know how to handle)

Alternately, if someone knows of a ready-made and accessible tool that does
just that, I'm all ears :-)

TIA,
fp


hth

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


Prequisites required to learn Django frame work

2011-09-07 Thread Shambhu Rajak
Hi,
I have been doing python development since last year, I think I should learn 
the famous Django frame work.

Can any one suggest what are the perquisite required to setup django on my 
local home machine.
Please suggest something that does not require a separate server, as this is a 
personal interest of mine.

Thanks,
Shambhu

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


Re: Looking for open-source Python projects to help out with

2011-09-07 Thread Alec Taylor
Hi Tyler,

I'm currently working on building a new kind of social-network for
Users-Groups, Game-Clans & Student-Groups.

Building it using DJango with Pinax.

Detailed Feature-Set (planned):
• Event management
• Conference management (including ticketing with payment-gateway integration)
• Video+Audio Conferencing of event, with online interaction
possibilitiy (great for webinars)
• Join/create/delete/list groups
• Sitewide calendar
• Sitewide feed from non-private groups
• SSO integration (facebook, twitter & linkedin)
• Wall (+feed) for each group
• Listing of who's in which group
• PM group members

I will probably be releasing it under the New BSD license, although
I'm happy to consider others given a good argument.

Interested?

On Wed, Sep 7, 2011 at 12:19 PM, Littlefield, Tyler  wrote:
> Hello:
> I've got a bit of time on my hands, so I'm curious what sorts of projects
> there are that people needs help with. I'd like to choose something that
> doesn't have a ton of red tape, but is stable, which is why I ask here
> instead of just Googling open source projects. My main interests lie in
> accessibility, Utilities and security.
>
> --
>
> Take care,
> ~Ty
> Web: http://tds-solutions.net
>
> Sent from my toaster.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Representation of floats (-> Mark Dickinson?)

2011-09-07 Thread jmfauth
On 7 sep, 08:56, Mark Dickinson  wrote:
> On Sep 7, 4:58 am, casevh  wrote:
>
> > IIRC, Python
> > 3.2 changed (for floats) __str__ to call __repr__.
>
> Yes, exactly:  str and repr of a float are identical in Python 3.2 +
>
> I'm also puzzled by the
>
> 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
> [...]>>> 1.1 * 1.1
>
> 1.21
>
> in jmf's message.  Cut-and-paste typo?
>
> --
> Mark


No. But, it's *my* mistake. I'm using a modified sys.displayhook which
uses a print statement (mainly for language reason). If forgot to
reset to the initial/default state for these tests when working
with too many opened interactive interpreters.
Sorry for the noise.


>>> sys.version
'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
>>>
>>> 1.1 * 1.1
1.21
>>> 'éléphant'
éléphant
>>>
>>> sys.displayhook = sys.__displayhook__
>>> 1.1 * 1.1
1.2102
>>> 'éléphant'
'\xe9l\xe9phant'
>>> sys.version
'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
>>>

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


Re: Looking for open-source Python projects to help out with

2011-09-07 Thread Fayaz Yusuf Khan
On Wednesday, September 07, 2011 01:09:51 PM Alec Taylor wrote:
> Hi Tyler,
> 
> I'm currently working on building a new kind of social-network for
> Users-Groups, Game-Clans & Student-Groups.
> 
> Building it using DJango with Pinax.
> 
> Detailed Feature-Set (planned):
> • Event management
> • Conference management (including ticketing with payment-gateway
> integration) • Video+Audio Conferencing of event, with online interaction
> possibilitiy (great for webinars)
> • Join/create/delete/list groups
> • Sitewide calendar
> • Sitewide feed from non-private groups
> • SSO integration (facebook, twitter & linkedin)
> • Wall (+feed) for each group
> • Listing of who's in which group
> • PM group members
> 
> I will probably be releasing it under the New BSD license, although
> I'm happy to consider others given a good argument.
> 
> Interested?
The project page and mailing list?

-- 
Fayaz Yusuf Khan
Cloud developer and designer
Dexetra SS, Kochi, India
fayaz.yusuf.khan_AT_gmail_DOT_com
fayaz_AT_dexetra_DOT_com
+91-9746-830-823


signature.asc
Description: This is a digitally signed message part.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Relative seeks on string IO

2011-09-07 Thread Pierre Quentel
>
> Please post code without non-code indents, like so:
>
Sorry about that. After the line "Example :" I indented the next
block, out of habit ;-)
>
> What system are you using? Does it have a narrow or wide unicode build?
> (IE, what is the value of sys.maxunicode?)
>
I use Windows XP Pro, version 2002, SP3. sys.maxunicode is 65535

I have the same behaviour with 3.1.1 and with 2.7

I don't understand why variable sized code units would cause problems.
On text file objects, read(nb) reads nb characters, regardless of the
number of bytes used to encode them, and tell() returns a position in
the text stream just after the next (unicode) character read

As for SringIO, a wrapper around file objects simulates a correct
behaviour for relative seeks :


txt = "abcdef"
txt += "تخصيص هذه الطبعة"
txt += "머니투데이"
txt += "endof file"

out = open("test.txt","w",encoding="utf-8")
out.write(txt)
out.close()

fobj = open("test.txt",encoding="utf-8")
fobj.seek(3)
try:
fobj.seek(2,1)
except IOError:
print('raises IOError')

class _file:

def __init__(self,file_obj):
self.file_obj = file_obj

def read(self,nb=None):
if nb is None:
return self.file_obj.read()
else:
return self.file_obj.read(nb)

def seek(self,offset,whence=0):
if whence==0:
self.file_obj.seek(offset)
else:
if whence==2:
# read till EOF
while True:
buf = self.file_obj.read()
if not buf:
break
self.file_obj.seek(self.file_obj.tell()+offset)

fobj = _file(open("test.txt",encoding="utf-8"))
fobj.seek(3)
fobj.seek(2,1)
fobj.seek(-5,2)
print(fobj.read(3))
==

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


Re: Floating point multiplication in python

2011-09-07 Thread Gelonida N
On 09/07/2011 06:51 AM, Steven D'Aprano wrote:
11258999068426240
> 
> Error in float 1.1*1.1:
> 
 b = F(11, 10)**2
 y = F.from_float(1.1**2)
 f = y - b
 print f
> 21/112589990684262400
> 
> which is slightly more than double e above, and slightly less than our
> estimate of 2*a*e = 11/56294995342131200
> 
> So we can conclude that, at least for 1.1**2, Python floats are more
> accurate than we would expect from a simple application of the binomial
> theorem. (For implementations using IEEE doubles.)


The reason why the error is different from the 2*a*e is, that we
encounter two problems.

first problem is, that x = a + e
e exists because a float does have a limited number (let's call it N) of
digits and a has an infinite amount of non zero digits in the binary format.


second problem is, that the result of the multiplication is not

(a+e) * (a+e) but a 'rounded' version of it, because the floating point
representation of the result would require about 2*N digits, whereas
only N digits will be stored in the result.

depending on the rounding which happened (up or down) the error will be
bigger or smaller than the estimated one.

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


Re: Prequisites required to learn Django frame work

2011-09-07 Thread Gelonida N
Hi Shambhu,

On 09/07/2011 09:25 AM, Shambhu Rajak wrote:
> Hi,
> 
> I have been doing python development since last year, I think I should
> learn the famous Django frame work.
> 
>  
> 
> Can any one suggest what are the perquisite required to setup django on
> my local home machine.
> 

Just easyinstall django
This is enough for learning and midsize home grown projects not
requiring a very secure setup.

Django comes with a built in server, which is good enough for learning.
However It should not be used for deployment.

As database engine you can use sqlite3, which is also good enough for
learning.


My above mentioned setup will be working under windows and under linux.


If you want to have something with a better performance, then you have
two things to look at.

Change the data base engine to mysql or postgres.
  mysql / postgres should be installable under Windows

Use a real web server (apache / nginx with uwsgi plugins)
As an intermediate step you could instead of installing a 'real' web
server you could also use a python twisted server



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


Re: Looking for open-source Python projects to help out with

2011-09-07 Thread Alec Taylor
The project page is: http://SamuelMarks.GitHub.com/groupHub

/me is thinking a rename to "groupSwitch", thoughts?

The project is currently in planning stage. All help is appreciated.

On Wed, Sep 7, 2011 at 6:32 PM, Fayaz Yusuf Khan
 wrote:
> On Wednesday, September 07, 2011 01:09:51 PM Alec Taylor wrote:
>> Hi Tyler,
>>
>> I'm currently working on building a new kind of social-network for
>> Users-Groups, Game-Clans & Student-Groups.
>>
>> Building it using DJango with Pinax.
>>
>> Detailed Feature-Set (planned):
>> • Event management
>> • Conference management (including ticketing with payment-gateway
>> integration) • Video+Audio Conferencing of event, with online interaction
>> possibilitiy (great for webinars)
>> • Join/create/delete/list groups
>> • Sitewide calendar
>> • Sitewide feed from non-private groups
>> • SSO integration (facebook, twitter & linkedin)
>> • Wall (+feed) for each group
>> • Listing of who's in which group
>> • PM group members
>>
>> I will probably be releasing it under the New BSD license, although
>> I'm happy to consider others given a good argument.
>>
>> Interested?
> The project page and mailing list?
>
> --
> Fayaz Yusuf Khan
> Cloud developer and designer
> Dexetra SS, Kochi, India
> fayaz.yusuf.khan_AT_gmail_DOT_com
> fayaz_AT_dexetra_DOT_com
> +91-9746-830-823
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing WebDAV server

2011-09-07 Thread Fokke Nauta
"Dennis Lee Bieber"  wrote in message 
news:mailman.823.1315377607.27778.python-l...@python.org...
> On Tue, 6 Sep 2011 21:26:12 +0200, "Fokke Nauta"
>  declaimed the following in
> gmane.comp.python.general:
>



>> (here I try to login the WebDAV server with the local IE browser)
>>
>> INFO:fshandler :get_data: D:\Webdav not found
>
> At this point my best suggestion is to study the source code of
> fshandler to see what it is doing at this moment in time (offhand, is
> there any content IN the directory to be "served"?)

There is a file indeed, in d:\Webdav

>> server - - [06/Sep/2011 21:05:35] - Mozilla/4.0 (compatible; MSIE 8.0;
>> Windows N
>> T 5.1; Trident/4.0> - "GET / HTTP/1.1" 404 -
>> server - - [06/Sep/2011 21:05:35] - Mozilla/4.0 (compatible; MSIE 8.0;
>> Windows N
>> T 5.1; Trident/4.0> - "GET / HTTP/1.1" 404 -
>>
> That almost looks like something is trying to retrieve a default
> page for 404 (not found) page.
>
> To save you some time:
>
> -=-=-=-
>if os.path.exists(path):
>if os.path.isfile(path):
>file_size = os.path.getsize(path)
>if range == None:
> ## REST SNIPPED
>else:
># also raise an error for collections
># don't know what should happen then..
>log.info('get_data: %s not found' % path)

I have seen this part. Do I need to alter it?

> Note that at this point in the system, it is looking for a FILE, not
> a directory.
> -- 

I have re-installed Python and the setuptool, and tried the Python version 
of Active, but it did not make a difference.
So now I use the "old" Python 2.7 again. Used easy_install to install 
PyWebDAV. I now run davserver.exe from the Script directory. Still the same 
problem.
What I found, however, was that if I specify the directory from the command 
line (like davserver -D d:\Webdav -n) there is no error message as 
"INFO:fshandler :get_data: D:\Webdav not found". The browser shows still the 
404 error.
The error "INFO:fshandler :get_data: D:\Webdav not found" only occurs when I 
specify the "-c config.ini" in the command line.

I didn't expect it to be this so tricky. It looked easy to set up an 
experimental webdav server.

Fokke


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


Re: Floating point multiplication in python

2011-09-07 Thread Terry Reedy

On 9/7/2011 12:51 AM, Steven D'Aprano wrote:


So given a float x, when you square it you get this:

Exact values: a*a = a**2

Float values: x*x = (a+e)(a+e)
   = a**2 + 2*a*e + e**2

So the error term has increased from e to (2*a*e+e**2). It is usual to
assume that e**2 is small enough that it underflows to zero, so we have the
error term e increasing to 2*a*e as a fairly simple estimate of the new
error.


And the relative error, which is what is often important, increases from 
e/a to 2e/a.


--
Terry Jan Reedy

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


Re: Installing WebDAV server

2011-09-07 Thread becky_lewis
> I have re-installed Python and the setuptool, and tried the Python version
> of Active, but it did not make a difference.
> So now I use the "old" Python 2.7 again. Used easy_install to install
> PyWebDAV. I now run davserver.exe from the Script directory. Still the same
> problem.
> What I found, however, was that if I specify the directory from the command
> line (like davserver -D d:\Webdav -n) there is no error message as
> "INFO:fshandler :get_data: D:\Webdav not found". The browser shows still the
> 404 error.
> The error "INFO:fshandler :get_data: D:\Webdav not found" only occurs when I
> specify the "-c config.ini" in the command line.
>
> I didn't expect it to be this so tricky. It looked easy to set up an
> experimental webdav server.
>
> Fokke

How are you trying to access the webdav server? I've been hacking on
the server for several days now (unrelated reasons) and have found
that it's a little unforgiving when it comes to configuration errors.
You need to be accessing the webdav server via the correct port (I
think it's 8008 by default). If you're not doing this and something
else is running on port 80 (which is where a webdav client will go to
by default) then this would explain the 404 errors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable locale usage

2011-09-07 Thread ssegvic
On 6 ruj, 22:58, garabik-news-2005...@kassiopeia.juls.savba.sk wrote:
> Thomas Jollans  wrote:
> > It looks like you don't actually care about the encoding: in your first
> > example, you use the default system encoding, which you do not control,
> > and in your second example, you're using two different encodings on the
> > two platforms. So why do you care whether or not the default uses ISO
> > 8859-2 ?
>
> Maybe because using 8859-2 locale, (unicode) strings not representable in the
> encodings will be sorted - how?

Exactly.

Additionally, fonts supporting 8859-2 are scarce.
My favourite fonts were never available in 8859-2.

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


Re: Portable locale usage

2011-09-07 Thread ssegvic
On 6 ruj, 17:53, Thomas Jollans  wrote:
> On 06/09/11 16:46, ssegvic wrote:
>
> > For the moment, I only wish to properly sort a Croatian text file
> > both on Windows and Linux (I am a cautious guy, I like reachable
> > goals).
> > When the locale is properly set, sorting works like a charm
> > with mylist.sort(key=locale.strxfrm).
>
> The problem with that is of course that a Croatian locale has to be
> installed. Many Linux systems don't have locales that aren't used.

It appears we did not understand each other completely.

Python locales on Linux work as advertised,
I have no problems with locales on Linux whatsoever
(yes, the Croatian locale had to be manually installed).

On the other hand, it appears that
Python locales on Windows do not work as advertised.
Consider for instance my initial example:
  locale.setlocale(locale.LC_ALL, ('hr',
locale.getpreferredencoding()))
The code above does not work on Windows even though the fine manual
says:
http://docs.python.org/py3k/library/locale.html
'''
locale.setlocale(category, locale=None)
  ...
  If (the locale) is a tuple, it is converted to a string using the
locale aliasing engine.
  ...
'''
I do not believe my troubles could be solved by installing anything,
since the OS support for Croatian apperas to be present:
  locale.setlocale(locale.LC_ALL, 'Croatian_Croatia.1250')

To conclude, it seems to me that the Windows implementation
of the locale aliasing engine has some space for improvement.

All further comments shall be greatly appreciated :-)

Cheers,

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


Re: Portable locale usage

2011-09-07 Thread ssegvic
On 6 ruj, 17:53, Thomas Jollans  wrote:
> On 06/09/11 16:46, ssegvic wrote:
>
> > For the moment, I only wish to properly sort a Croatian text file
> > both on Windows and Linux (I am a cautious guy, I like reachable
> > goals).
> > When the locale is properly set, sorting works like a charm
> > with mylist.sort(key=locale.strxfrm).
>
> The problem with that is of course that a Croatian locale has to be
> installed. Many Linux systems don't have locales that aren't used.

I already concluded that on Linux there are no problems whatsoever
(the Croatian locale was kindly installed by the distribution setup).

Since my initial snippet does not work on Windows, I would conclude
that the locale aliasing engine on Windows should be improved.

Any opposing views will be appreciated :-)

For convenience, I repeat the snippet here:
import locale
locale.setlocale(locale.LC_ALL, ('hr', locale.getpreferredencoding()))

Cheers,

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


Re: Portable locale usage

2011-09-07 Thread Thomas Jollans
On 07/09/11 12:39, ssegvic wrote:
> On 6 ruj, 17:53, Thomas Jollans  wrote:
>> On 06/09/11 16:46, ssegvic wrote:
>>
>>> For the moment, I only wish to properly sort a Croatian text file
>>> both on Windows and Linux (I am a cautious guy, I like reachable
>>> goals).
>>> When the locale is properly set, sorting works like a charm
>>> with mylist.sort(key=locale.strxfrm).
>>
>> The problem with that is of course that a Croatian locale has to be
>> installed. Many Linux systems don't have locales that aren't used.
> 
> It appears we did not understand each other completely.

Yes we did. I was just pointing out that your code wouldn't be portable
to systems that don't have that specific locale.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for open-source Python projects to help out with

2011-09-07 Thread Thomas Jollans
On 07/09/11 04:19, Littlefield, Tyler wrote:
> Hello:
> I've got a bit of time on my hands, so I'm curious what sorts of
> projects there are that people needs help with. I'd like to choose
> something that doesn't have a ton of red tape, but is stable, which is
> why I ask here instead of just Googling open source projects. My main
> interests lie in accessibility, Utilities and security.
> 

How about Python itself? Much of the standard library is written in
Python, and there are almost certainly bugs that need fixing.

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


Re: Installing WebDAV server

2011-09-07 Thread Fokke Nauta
"becky_lewis"  wrote in message 
news:d26f81b2-f87e-46f1-bb4e-8ef1943df...@c29g2000yqd.googlegroups.com...
>> I have re-installed Python and the setuptool, and tried the Python 
>> version
>> of Active, but it did not make a difference.
>> So now I use the "old" Python 2.7 again. Used easy_install to install
>> PyWebDAV. I now run davserver.exe from the Script directory. Still the 
>> same
>> problem.
>> What I found, however, was that if I specify the directory from the 
>> command
>> line (like davserver -D d:\Webdav -n) there is no error message as
>> "INFO:fshandler :get_data: D:\Webdav not found". The browser shows still 
>> the
>> 404 error.
>> The error "INFO:fshandler :get_data: D:\Webdav not found" only occurs 
>> when I
>> specify the "-c config.ini" in the command line.
>>
>> I didn't expect it to be this so tricky. It looked easy to set up an
>> experimental webdav server.
>>
>> Fokke
>
> How are you trying to access the webdav server?

By IE 8 and Firefox, on the same system as well as on another system. 
Firefox doesn't show the 404 error but shows a blank screen.
I bound the davserver to the local adress of the system where it's on 
(10.0.0.140).
The port was 8081 but I changed it to 8008 as you said it's the default. No 
difference.

> I've been hacking on
> the server for several days now (unrelated reasons) and have found
> that it's a little unforgiving when it comes to configuration errors.
> You need to be accessing the webdav server via the correct port (I
> think it's 8008 by default). If you're not doing this and something
> else is running on port 80 (which is where a webdav client will go to
> by default) then this would explain the 404 errors.

I certainly use the correct IP address and port number.

Underneath is my command shell.
The 1st time I specified the config file (davserver.ini), the 2nd time I 
specified on the command line.
Here I logged in with Firefox from system XXX (replaced the name by XXX).

(Here I started the server with the the config file (davserver.ini)
D:Python27\Scripts>davserver -m -c davserver.ini
INFO:pywebdav:Starting up PyWebDAV server 
INFO:pywebdav:chunked_http_response feature ON
INFO:pywebdav:http_request_use_iterator feature OFF
INFO:pywebdav:http_response_use_iterator feature OFF
INFO:DAVServer.fshandler:Initialized with d:\webdav-http://10.0.0.140:8081/
WARNING:pywebdav:Authentication disabled!
INFO:pywebdav:Serving data from d:\webdav
Listening on 10.0.0.140 <8081>

(browser logging in)

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 -

^C
D:\Python27\Scripts>INFO:pywebdav:Killed by user

(Here I started the server with command line options)
davserver -D d:\webdav -H 10.0.0.140 -P 8081 -n
WARNING:pywebdav:Authentication disabled!
Listening on 10.0.0.140 <8081>
XXX --- [07/Sep/2011 11:58:49] - Mozilla/5.0  
Gecko/
20100101 Firefox/6.0.1 - "GET / HTTP/1.1" 404 -
XXX --- [07/Sep/2011 11:58:54] - Mozilla/5.0  
Gecko/
20100101 Firefox/6.0.1 - "GET / HTTP/1.1" 404 -

^C
D:\Python27\Scripts>INFO:pywebdav:Killed by user 


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


web2py

2011-09-07 Thread Vineet Deodhar
>>>--
Hi,
I have been doing python development since last year, I think I should learn 
the famous Django frame work.
Can any one suggest what are the perquisite required to setup django on my 
local home machine.
Please suggest something that does not require a separate server, as this is a 
personal interest of mine. 
Thanks,
Shambhu
I'm currently working on building a new kind of social-network for
Users-Groups, Game-Clans & Student-Groups.
Building it using DJango with Pinax.
Detailed Feature-Set (planned):
• Event management
• Conference management (including ticketing with payment-gateway integration)
• Video+Audio Conferencing of event, with online interaction
possibilitiy (great for webinars)
• Join/create/delete/list groups
• Sitewide calendar
• Sitewide feed from non-private groups
• SSO integration (facebook, twitter & linkedin)
• Wall (+feed) for each group
• Listing of who's in which group
• PM group members
>>>--

I don't want to undermine django. It is a good framework.
But still, my advise would be to go for 'web2py'.
http://web2py.com/
It is simple yet powerful. Full stack MVC framework.
Low learning curve; simple syntax.
Good docs & community.
Everything works out of the box (including web-server, DAL, sqlite, etc)
No dependencies; plug&play.
etc. etc.
---Vineet-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable locale usage

2011-09-07 Thread Laszlo Nagy



1. Is there a way for writing portable Python code dealing with
locales
 (as sketched in the beginning)?
I usually do this at the top of my main program, before importing other 
modules:


import locale
locale.setlocale(locale.LC_ALL, '')


This is absolutely portable. The above snippet works for different 
operating systems with different default encodings. You can always setup 
some environment variable before starting up the program if you really 
have to. And yes, that setting will be OS dependent, but your program 
will still be portable.


I have no access to Croatian Windows, but I bet that the above code 
would set the locale to the correct thing on both Linux and Windows.


It would be a bad idea to set the locale from anywhere else than your 
main program anyway. There are also some notes in the docs about this ( 
http://docs.python.org/library/locale.html#locale.setlocale ):


setlocale() 
 is not 
thread-safe on most systems. Applications typically start with a call of


import  locale
locale.setlocale(locale.LC_ALL,  '')

This sets the locale for all categories to the user's default setting 
(typically specified in the *LANG* environment variable). If the 
locale is not changed thereafter, using multithreading should not 
cause problems.




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

  L


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


Re: Looking for open-source Python projects to help out with

2011-09-07 Thread Eric Snow
On Tue, Sep 6, 2011 at 8:19 PM, Littlefield, Tyler  wrote:
> Hello:
> I've got a bit of time on my hands, so I'm curious what sorts of projects
> there are that people needs help with. I'd like to choose something that
> doesn't have a ton of red tape, but is stable, which is why I ask here
> instead of just Googling open source projects. My main interests lie in
> accessibility, Utilities and security.

An interesting one that I haven't had time to help on yet is the
"extensions for unittest" project:

https://code.google.com/p/unittest-ext/issues/list

Basically it's adding an extensions framework to the stdlib unittest
module.  I'm sure Michael Foord wouldn't mind the help.  Like I said,
a very interesting project, though not directly related to
accessibility or security.

-eric

>
> --
>
> Take care,
> ~Ty
> Web: http://tds-solutions.net
>
> Sent from my toaster.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


How to structure packages

2011-09-07 Thread bclark76
I'm learning python, and was playing with structuring packages.

Basically I want to have a package called mypackage that defines a
number of classes and functions.


so I create:

mypackage
__init__.py
myfunc.py
MyClass.py


my __init__.py is blank.

my MyClass.py looks like:

import blah

class MyClass(blahblah):
blah
blah
blah


then I have a run.py that looks like

from mypackage import MyClass


x = MyClass()


This doesn't work because MyClass is mypackage.MyClass.MyClass.
There's this MyClass module 'in the way'.


I'm trying to follow the rule that every file defines only one class.
I could define MyClass in __init__.py, but then what if I wanted to
define more classes in the mypackage package? My one class per file
rule goes out the window.

Is this rule wrongheaded, or is there another way to do this?


Thanks.

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


Re: Looking for open-source Python projects to help out with

2011-09-07 Thread Alec Taylor
Accessibility?

Hmm, you could look at
http://groups.google.com/group/django-users/browse_thread/thread/44a4dbf8771e0f4f
(https://groups.google.com/forum/#!topic/django-users/RKTb-HceD08)

On Thu, Sep 8, 2011 at 1:12 AM, Eric Snow  wrote:
> On Tue, Sep 6, 2011 at 8:19 PM, Littlefield, Tyler  
> wrote:
>> Hello:
>> I've got a bit of time on my hands, so I'm curious what sorts of projects
>> there are that people needs help with. I'd like to choose something that
>> doesn't have a ton of red tape, but is stable, which is why I ask here
>> instead of just Googling open source projects. My main interests lie in
>> accessibility, Utilities and security.
>
> An interesting one that I haven't had time to help on yet is the
> "extensions for unittest" project:
>
> https://code.google.com/p/unittest-ext/issues/list
>
> Basically it's adding an extensions framework to the stdlib unittest
> module.  I'm sure Michael Foord wouldn't mind the help.  Like I said,
> a very interesting project, though not directly related to
> accessibility or security.
>
> -eric
>
>>
>> --
>>
>> Take care,
>> ~Ty
>> Web: http://tds-solutions.net
>>
>> Sent from my toaster.
>>
>> --
>> 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: How to structure packages

2011-09-07 Thread John Gordon
In <2a4f542c-a8c1-46c7-9899-a3fad0940...@x11g2000yqc.googlegroups.com> bclark76 
 writes:

> mypackage
> __init__.py
> myfunc.py
> MyClass.py

> from mypackage import MyClass

Try this instead:

  from mypackage.MyClass import MyClass

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

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


Re: How to structure packages

2011-09-07 Thread Rafael Durán Castañeda

Check python pep8: http://www.python.org/dev/peps/pep-0008/

And you will see than you shouldn't named modules as you did, so you 
should do something like:


mypackage
__init__.py
mymodule
...

mypackage.mymodule.MyClass

On 07/09/11 18:11, John Gordon wrote:

In<2a4f542c-a8c1-46c7-9899-a3fad0940...@x11g2000yqc.googlegroups.com>  
bclark76  writes:


mypackage
 __init__.py
 myfunc.py
 MyClass.py
from mypackage import MyClass

Try this instead:

   from mypackage.MyClass import MyClass



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


Re: How to structure packages

2011-09-07 Thread Peter Otten
bclark76 wrote:

> I'm learning python, and was playing with structuring packages.

If you are coming from Jave you have to unlearn a thing or two.
 
> Basically I want to have a package called mypackage that defines a
> number of classes and functions.

> I'm trying to follow the rule that every file defines only one class.
> I could define MyClass in __init__.py, but then what if I wanted to
> define more classes in the mypackage package? My one class per file
> rule goes out the window.
> 
> Is this rule wrongheaded, 

Yes. 

> or is there another way to do this?

I recommend that you always start out with a module. Once that becomes 
unwieldy you can convert it into a package. Let's assume that

mystuff.py

contains a MyClass that you want to move into a separate file. You get the 
following files:

mystuff
__init__.py
descriptivename.py # MyClass here

Note that all filenames are lowercase. If you add the line

from .descriptivename import MyClass

to __init__.py you can continue to import and use MyClass with the statement

from mystuff import MyClass
m = MyClass()

or

import mystuff
m = mystuff.MyClass()

The disadvantage is of course that mystuff.descriptivename will always be 
imported, even if you don't need the part of the mystuff package defined 
there.

You may also have a look into unittest as an example of a module that was 
recently converted into a package. Classes and functions are grouped into 
submodules by their functionality rather than employing Java's mechanical 
one-class-per-file pattern.


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


Re: How to structure packages

2011-09-07 Thread rantingrick
On Sep 7, 10:56 am, bclark76  wrote:
> I'm learning python, and was playing with structuring packages.
>
> Basically I want to have a package called mypackage that defines a
> number of classes and functions.
>
> so I create:
>
> mypackage
>     __init__.py
>     myfunc.py
>     MyClass.py

Don't tell me you create a module called myfunc.py??? Stuff that
function in __init__! Also don't name modules MyClass either. Both the
spelling and grammar is incorrect. ALL modules use lowercase (and only
integrate underscores in the most dire of need!)

geom
   __init__.py
   vector3d.py
   point3d.py
   transformation.py

from geom.transformation import Transformation
from geom.vector3d import Vector3d
from geom.point3d import Point3d

or alternatively:

geom
   __init__.py
   from __vector3d import Vector3d
   from __point3d import Point3d
   from __transformation import Transformation
   __vector3d.py
   __point3d.py
   __transformation.py

from geom import Transformation
from geom import Vector3d
from geom import Point3d

Although this method can be brittle due to the fact that one buggy
module can break all the imported code in the __init__ module. I
usually opt for specifying the module in the import path.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to structure packages

2011-09-07 Thread Littlefield, Tyler

On 9/7/2011 9:56 AM, bclark76 wrote:

I'm learning python, and was playing with structuring packages.

Basically I want to have a package called mypackage that defines a
number of classes and functions.


so I create:

mypackage
 __init__.py
 myfunc.py
 MyClass.py


my __init__.py is blank.

my MyClass.py looks like:

import blah

class MyClass(blahblah):
 blah
 blah
 blah


then I have a run.py that looks like

from mypackage import MyClass


x = MyClass()


This doesn't work because MyClass is mypackage.MyClass.MyClass.
There's this MyClass module 'in the way'.


You can use the __init__.py to promote that class up. so:
from myclass import myclass
So that means that myclass will just be in mypackage.myclass, and thus 
your from mypackage import myclass would work perfectly. I'm not sure if 
this is how you're supposed to do it, but it works.



I'm trying to follow the rule that every file defines only one class.
I could define MyClass in __init__.py, but then what if I wanted to
define more classes in the mypackage package? My one class per file
rule goes out the window.

Is this rule wrongheaded, or is there another way to do this?


Thanks.




--

Take care,
Ty
Web: http://tds-solutions.net

Sent from my toaster.

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


Re: PEP 20 - Silly Question?

2011-09-07 Thread Emile van Sebille

On 9/6/2011 6:31 PM Joshua Miller said...

You sure it wasn't the invisible one? you know the one in the white
text that blends into the background?


Aah!  So _that's_ significant whitespace!

:)

Emile


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


Re: Advice on how to get started with 2D-plotting ?

2011-09-07 Thread Fred Pacquier
Wow, what an impressive turnout !

Thanks a lot, rantingrick, CM and Herbert, for the fast answers, useful 
tips and especially the sample code !

Beats starting from a blank page, with a big stick, and will certainly set 
me on my way much faster...

networkx does seem a bit over the top for my simple goal, but both the Tk 
(I always forget Tk !) and Matplotlib approaches seem to fit the KISS 
principle just fine... on to the tinkering now :-)

Again, thanks to all !
fp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Portable locale usage

2011-09-07 Thread Siniša Šegvić
> From: "Laszlo Nagy" 
> To: "ssegvic" , python-list@python.org
> Sent: Wednesday, September 7, 2011 4:51:20 PM
> Subject: Re: Portable locale usage
> > 1. Is there a way for writing portable Python code dealing with
> > locales (as sketched in the beginning)?
> I usually do this at the top of my main program, before importing
> other modules:
> 
> import locale
> locale.setlocale(locale.LC_ALL, '')

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')

Note that I would very much like 
to avoid changing the system locale
(this requires Administrator password and system restart).

Setting the locale for my program only would be interesting,
but AFAIK this can not be done on Windows (?).

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

Because I wish to be able to correctly sort Croatian names.

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).

Cheers,

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


Re: Adding a ranking based on two fields

2011-09-07 Thread noydb
On Aug 25, 4:53 pm, Chris Rebert  wrote:
> On Thu, Aug 25, 2011 at 1:38 PM, noydb  wrote:
> > Hello All,
>
> > Looking for some advice/ideas on how to implement arankingto a
> > 'scores' field I have.  So this scores field has values ranging from
> > 1.00-4.  There is also a count field.  I want to add a rank field such
> > that all the records have a uniqueranking, 1 through the number of
> > records (thousands).  The rank isbasedon the score first, the count
> > second.  So, a record with a score of 4 and a count of 385 is ranked
> > higher than a record with a score of 4 and a count of 213 AND higher
> > than record with a score of 3.25 with a count of 4640.
>
> > My thought was to add the unique score values to a list and loop thru
> > the list... sort records with score=listItem, addranking... not quite
> > sure how to do this!
>
> things = getListOfYourThings()
> things.sort(reverse=True, key=lambda item: (item.score, item.count))
> for i, thing in enumerate(things):
>     thing.rank = i + 1
>
> Cheers,
> Chris
> --http://rebertia.com

Thanks for this!

Someone passed this along, too - helpful
http://wiki.python.org/moin/HowTo/Sorting
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MIMEText encode error - Python 2.6.6

2011-09-07 Thread neubyr
On Tue, Sep 6, 2011 at 5:05 PM, MRAB  wrote:
> On 06/09/2011 22:52, neubyr wrote:
>>
>> I am trying to write a program which can email file's content using
>> smtplib. I am getting following error while using Python 2.6.6
>> version.
>>
>> {{{
>> File "./killed_jobs.py", line 88, in sendmail
>>    msg = MIMEText(ipfile.read, 'plain')
>>  File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/mime/text.py",
>> line 30, in __init__
>>    self.set_payload(_text, _charset)
>>  File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py",
>> line 224, in set_payload
>>    self.set_charset(charset)
>>  File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py",
>> line 266, in set_charset
>>    cte(self)
>>  File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/encoders.py",
>> line 73, in encode_7or8bit
>>    orig.encode('ascii')
>> AttributeError: 'builtin_function_or_method' object has no attribute
>> 'encode'
>>
>> }}}
>>
>>
>> I am referring to email examples on the doc site
>>
>> http://docs.python.org/release/2.6.6/library/email-examples.html#email-examples
>> . Following is the msg object part in my code:
>>
>> {{{
>> ...
>> ...
>> def sendmail(inputfile):
>>         ipfile = open(inputfile, 'r')
>>         msg = MIMEText(ipfile.read, 'plain')
>>         ipfile.close()
>>
>> ...
>> ...
>> }}}
>>
>> I have tried setting subtype and chartype separately as mentioned here
>> - http://docs.python.org/release/2.6.6/library/email.mime.html, but
>> the error remains same. Any help on what might be wrong here?
>>
> The docs say:
>
>    MIMEText(_text[, _subtype[, _charset]])
>
>    ... _text is the string for the payload ...
>
> You're passing ipfile.read, which is the read method of the file. You
> should be passing the string returned by calling ipfile.read, ie
> ipfile.read().
> --
>

thanks got pointing that..

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


Re: Portable locale usage

2011-09-07 Thread Thomas Jollans
On 07/09/11 20:33, Siniša Šegvić wrote:
> 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).

Are, on Windows, the default system region/language setting, and the
locale, distinct? (And, if so, why?!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to structure packages

2011-09-07 Thread Westley Martínez
First of all MyClass.py should be renamed to myclass.py.  Module names
should be lowercase.  Secondly, put this in __init__.py:

from .myclass import MyClass

and there you go.

On Wed, Sep 07, 2011 at 08:56:32AM -0700, bclark76 wrote:
> I'm learning python, and was playing with structuring packages.
> 
> Basically I want to have a package called mypackage that defines a
> number of classes and functions.
> 
> 
> so I create:
> 
> mypackage
> __init__.py
> myfunc.py
> MyClass.py
> 
> 
> my __init__.py is blank.
> 
> my MyClass.py looks like:
> 
> import blah
> 
> class MyClass(blahblah):
> blah
> blah
> blah
> 
> 
> then I have a run.py that looks like
> 
> from mypackage import MyClass
> 
> 
> x = MyClass()
> 
> 
> This doesn't work because MyClass is mypackage.MyClass.MyClass.
> There's this MyClass module 'in the way'.
> 
> 
> I'm trying to follow the rule that every file defines only one class.
> I could define MyClass in __init__.py, but then what if I wanted to
> define more classes in the mypackage package? My one class per file
> rule goes out the window.
> 
> Is this rule wrongheaded, or is there another way to do this?
> 
> 
> Thanks.
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-09-07 Thread Laurent
Hi there,

What is the simplest way to check that you are at the beginning or at the end 
of an iterable? I'm using enumerate with Python 3.2 (see below) but I'm 
wondering if there would be a better way.


l = ['a', 'b', 'a', 'c']

for pos, i in enumerate(l):
if pos == 0:
print("head =", i)
else:
print(i)


I know that Python is not exactly a functional language but wouldn't something 
like "ishead()" or "istail()" be useful?

-- 
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-07 Thread Cameron Simpson
On 07Sep2011 14:35, Laurent  wrote:
| What is the simplest way to check that you are at the beginning or at
| the end of an iterable? I'm using enumerate with Python 3.2 (see below)
| but I'm wondering if there would be a better way.
| 
| l = ['a', 'b', 'a', 'c']
| 
| for pos, i in enumerate(l):
| if pos == 0:
| print("head =", i)
| else:
| print(i)
| 
| I know that Python is not exactly a functional language but wouldn't
| something like "ishead()" or "istail()" be useful?

There are a few reasons these do not exist out of the box (quite aside
from how easy it is to do on the occasions you actually want it).
Tackling ishead and istail in turn...

The "ishead()" would need to be a top level function (like "len()")
because if it were an iterator method, every iterator would need to have
it implemented; currently the number of methods needed to roll your own
iterator is just two (iter and next). ishead() could be done as a top
level function, though it would need the storage cost of an additional
state value to every iterator (i.e. a "first" boolean or equivalent). So
you'd be proposing more memory cost and possibly a retrospective code
change for all the existing planetwide code, for a minor convenient. As
you note, enumerate gets you a pos value, and it is easy enough to write
a for loop like this:

  first = True
  for i in iterable_thing:
if first:
  print "head =", i
else:
  print i
first = False

Your istail() is much worse.

A generator would need to do lookahead to answer istail() in the general
case. Consider iterating over the lines in a file, or better still the
lines coming from a pipeline. Or iteraing over packets received on a
network connection. You can't answer "istail()" there until you have
seen the next line/packet (or EOF/connection close). And that may be an
arbitrary amount of time in the future. You're going to stall your whole
program for such a question?

You can do this easily enough for yourself as an itertools-like thing:
write a wrapper generator that answers ishead() and istail() for
arbitrary iterators. Completely untested example code:

  class BoundSensitiveIterator(object):
def __init__(self, subiter):
  self.sofar = 0
  self.subiter = subiter
  self.pending = ()
def iter(self):
  return self
def next(self):
  self.sofar += 1
  if self.pending is None:
raise StopIteration
  if self.pending:
nxt = self.pending[0]
self.pending = ()
return nxt
  return self.subiter.next()
def ishead(self):
  # maybe <= 1, depending on what you want it to mean
  return self.sofar == 1
def istail(self):
  if self.pending is None:
return True
  if self.pending:
return False
  try:
nxt = self.subiter.next()
  except StopIteration:
self.pending = None
return True
  else:
self.pending = (nxt,)
return False

  I = BoundSensitiveIterator(other_iterable)
  for n in I:
print n, "ishead =", I.ishead(), "istail =", I.istail()

You can see it adds some performance and storage overhead, and of course
may stall if you every ask istail() of an "on demand" iterable.

About the only time I do this is my personal "the()" convenience
function:

  def the(list, context=None):
''' Returns the first element of an iterable, but requires there to be
exactly one.
'''
icontext="expected exactly one value"
if context is not None:
  icontext=icontext+" for "+context

first=True
for elem in list:
  if first:
it=elem
first=False
  else:
raise IndexError, "%s: got more than one element (%s, %s, ...)" \
  % (icontext, it, elem)

if first:
  raise IndexError, "%s: got no elements" % icontext
  
return it

Which I use as a definite article in places where an iterable _should_
yield exactly one result (eg SQL SELECTs that _ought_ to get exactly
one hit). I can see I wrote that a long time ago - it could do with some
style fixes. And a code scan shows it sees little use:-)

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

Electronic cardboard blurs the line between printed objects and the virtual
world.  - overhead by WIRED at the Intelligent Printing conference Oct2006
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing WebDAV server

2011-09-07 Thread Piet van Oostrum
"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. 

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.

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.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


I am confused by

2011-09-07 Thread Martin Rixham
Hi all
I would appreciate some help understanding something. Basically I am
confused by the following:

>>> a = [[0, 0], [0, 0]]
>>> b = list(a)
>>> b[0][0] = 1
>>> a
[[1, 0], [0, 0]]

I expected the last line to be

[[0, 0], [0, 0]]

I hope that's clear enough.

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


Re: Why do class methods always need 'self' as the first parameter?

2011-09-07 Thread Piet van Oostrum
"Prasad, Ramit"  writes:

> It seems to me that if I add a function to the list of class attributes it 
> will automatically wrap with "self" but adding it to the object directly will 
> not wrap the function as a method. Can somebody explain why? I would have 
> thought that any function added to an object would be a method (unless 
> decorated as a class method). 

The special magic to transform a function into a method is only applied
for functions found as attributes of the class, not for instance
attributes. It is a matter of design.

> Hmm, or does the decoration just tell Python not to turn an object's function 
> into a method? I.e. Is the decorator basically just the syntactic sugar for 
> doing the above?

The classmethod decorator transforms the method (or actually the
function) into a different kind of object (a class method). 
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
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-07 Thread Laurent
I totally understand the performance issue that an hypothetical "istail" would 
bring, even if I think it would just be the programmer's responsibility not to 
use it when it's not certain that an end can be detected. 
But I don't see why *adding* something like "ishead" would be so bad (at worse 
by using a boolean somewhere as you mentioned).

Anyway I was just asking if there is something better than enumerate. So the 
answer is no? The fact that I have to create a tuple with an incrementing 
integer for something as simple as checking that I'm at the head just sounds 
awfully unpythonic to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing WebDAV server

2011-09-07 Thread Fokke Nauta
"Piet van Oostrum"  wrote in message 
news:m2zkigartn@cochabamba.vanoostrum.org...
> "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.

> 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.

Fokke 


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


Re: I am confused by

2011-09-07 Thread MRAB

On 07/09/2011 23:57, Martin Rixham wrote:

Hi all
I would appreciate some help understanding something. Basically I am
confused by the following:

 >>> a = [[0, 0], [0, 0]]
 >>> b = list(a)
 >>> b[0][0] = 1
 >>> a
[[1, 0], [0, 0]]

I expected the last line to be

[[0, 0], [0, 0]]

I hope that's clear enough.


What you were expecting is called a "deep copy".

You should remember that a list doesn't contain objects themselves, but
only _references_ to objects.

"list" will copy the list itself (a "shallow copy"), including the
references which are in it, but it won't copy the _actual_ objects to
which they refer.

Try using the "deepcopy" function from the "copy" module:

>>> from copy import deepcopy
>>> a = [[0, 0], [0, 0]]
>>> b = deepcopy(a)
>>> b[0][0] = 1
>>> a
[[0, 0], [0, 0]]
--
http://mail.python.org/mailman/listinfo/python-list


Re: I am confused by

2011-09-07 Thread Gary Herron

On 09/07/2011 03:57 PM, Martin Rixham wrote:

Hi all
I would appreciate some help understanding something. Basically I am 
confused by the following:


>>> a = [[0, 0], [0, 0]]
>>> b = list(a)
>>> b[0][0] = 1
>>> a
[[1, 0], [0, 0]]

I expected the last line to be

[[0, 0], [0, 0]]

I hope that's clear enough.

Martin


You were expecting the assignment to "b" to create a copy of the 
original list, and it does, but the copy is only one level deep.


So a and b are different lists, but a[i] and b[i] are the same objects 
for each i.


There is a "deepcopy" in the library which may do what you expect.

Gary Herron


--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

--
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-07 Thread Cameron Simpson
On 07Sep2011 16:22, Laurent  wrote:
| I totally understand the performance issue that an hypothetical
| "istail" would bring, even if I think it would just be the programmer's
| responsibility not to use it when it's not certain that an end can
| be detected.

The trouble with these things is that their presence leads to stallable
code, often in libraries. Let the programmer write code dependent on
istail() without thinking of the stall case (or even the gratuitous
execution case, as in a generator with side effects in calling .next())
and have that buried in a utilities function.

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()
...

that is it often thought that having offered the eof() function is a
design error. (Of course in the example above the usual python idiom
would win out from existing habit, but there are plenty of other
situations where is would just be _easy_ to rely of istail() in whatever
form.)

| But I don't see why *adding* something like "ishead" would be so bad
| (at worse by using a boolean somewhere as you mentioned).

It is not awful, but as remarked:
  - extra storage cost to _every_ iterable, for a rarely used facility
  - extra runtime cost to maintain the state
  - _retroactive_ burden on _every_ iterator implementation presently
existing; every iterator sudden needs to implement and offer this
extra facility to be generate purpose use
  - it is easy to provide the facility on the rare occasions when it is
needed

Personally, I think point 3 above is the killer and 1 and 2 are serious
counter arguments.

| Anyway I was just asking if there is something better than enumerate. So
| the answer is no? The fact that I have to create a tuple with an
| incrementing integer for something as simple as checking that I'm at
| the head just sounds awfully unpythonic to me.

You can just use a boolean if you like. I have plent of loops like:

  first = true
  for i in iterable:
if first:
  blah ...
...
first = False

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

Bye and bye, God caught his eye, - Epitaph for a waiter by David McCord
-- 
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-07 Thread Steven D'Aprano
Laurent wrote:

> Hi there,
> 
> What is the simplest way to check that you are at the beginning or at the
> end of an iterable?


I don't think this question is meaningful. There are basically two
fundamental types of iterables, sequences and iterators.

Sequences have random access and a length, so if the "start" and "end" of
the sequence is important to you, just use indexing:

beginning = sequence[0]
end = sequence[-1]
for i, x in enumerate(sequence):
if i == 0: print("at the beginning")
elif i == len(sequence)-1: print("at the end")
print(x)


Iterators don't have random access, and in general they don't have a
beginning or an end. There may not be any internal sequence to speak of:
the iterator might be getting data from a hardware device that provides
values continuously, or some other series of values without a well-defined
beginning or end. Example:

def time():
from time import asctime
while True:
yield asctime()

it = time()

What would it even mean to say that I am at the beginning or end of it?

Iterators have no memory, so in one sense you are *always* at the beginning
of the iterator: next() always returns the next item, and the previous item
is lost forever. So the answer to the question "Am I at the beginning of an
iterator?" is always "You are now".

For sequences, the question is best handled differently. For iterators, the
question doesn't make sense in general. If you need an iterator that can
report its internal state, write your own:

import random, time
class MyIter(object):
def __init__(self):
self.start = True
self.end = False
def __next__(self):
if self.start:
self.start = False
if self.end:
raise StopIteration
if random.random() < 0.01:
self.end = True
return time.asctime()
def __iter__(self):
return self



-- 
Steven

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


Re: How to structure packages

2011-09-07 Thread Steven D'Aprano
Peter Otten wrote:

> Classes and functions are grouped into
> submodules by their functionality rather than employing Java's mechanical
> one-class-per-file pattern.

Surely it's an anti-pattern?

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?

If "one class per file", why not "one method per class" too? Why is the
second rule any more silly than the first?



-- 
Steven

-- 
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-07 Thread Miki Tebeka
I guess enumerate is the best way to check for first argument. Note that if 
someone passes you the iterator as argument you have now way of checking if the 
consumed items from it.

istail can be implemented using itertools.chain, see 
https://gist.github.com/1202260
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating point multiplication in python

2011-09-07 Thread Christophe Chong
And then we learned in class what happens when you're calculating "0.1" with
different precision in the industry.

http://www.ima.umn.edu/~arnold/disasters/patriot.html

Beware.

On Tue, Sep 6, 2011 at 3:14 AM, Thomas Rachel <
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de> wrote:

> Am 06.09.2011 07:57 schrieb xyz:
>
>> hi all:
>>
>> As we know ,  1.1 * 1.1 is 1.21 .
>> But in python ,I got following :
>>
>>  1.1 * 1.1
>
 1.2102
>>
>> why python get wrong result? Who can tell me  where's the
>> 0.0002 from?
>>
>
> 1.1 does not fit in a binary floating point number. It is approximated - in
> binary! - as 1.000110011001100110011 ... (periodically).
>
> Note that, while in the decimal system we normally use, only numbers which
> have other components in the denominator than 2 or 5 are periodically, in
> the binary systems only components with 2 are allowed in order not to be
> periodically.
>
> Example: 3.453 is not periodically, because it is 3453/100 and 100 has only
> the factors 2 and 5, each twice.
>
> 1/3 = .333... is periodically, because it has the factor 3. The same
> applies to 1/6, which has 2 and 3 as factors. The latter destroys the
> non-periodical behaviour.
>
> As said, in the dual system, only the 2 is allowed.
>
> .5 (10) = 2** -1 = .1 (2).
> .25 (10) = 2 ** -2 = .01 (2).
> .75 (10) = their sum = .11 (2).
>
> But .1 (1/10) is more complicated, -2 would be as well.
>
> As the IEEE floating point representation is limited, there is a slight
> error value which makes the stored value differ from the intended one.
>
> Look here:
>
>
>
>  x=(1,0,0,0,1,1,0,0,1,1,0,0,1,**1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,**
 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,**0,1,1,0,0,1,1,0,0,1,1,0,0,1,1)
 a=0
 for n,i in enumerate(x): a += i*2**-n; print a, a-1.1, i*2**-n, a-olda

>>> ...
> 1 -0.1 1 1
> 1.0 -0.1 0.0 0.0
> 1.0 -0.1 0.0 0.0
> 1.0 -0.1 0.0 0.0
> 1.0625 -0.0375 0.0625 0.0625
> 1.09375 -0.00625 0.03125 0.03125
> 1.09375 -0.00625 0.0 0.0
> 1.09375 -0.00625 0.0 0.0
> 1.09765625 -0.00234375 0.00390625 0.00390625
> 1.099609375 -0.000390625 0.001953125 0.001953125
> 1.099609375 -0.000390625 0.0 0.0
> 1.099609375 -0.000390625 0.0 0.0
> 1.09985351562 -0.000146484375 0.000244140625 0.000244140625
> 1.09997558594 -2.44140625001e-05 0.0001220703125 0.0001220703125
> 1.09997558594 -2.44140625001e-05 0.0 0.0
> 1.09997558594 -2.44140625001e-05 0.0 0.0
> 1.0084473 -9.15527343759e-06 1.52587890625e-05 1.52587890625e-05
> 1.0847412 -1.52587890634e-06 7.62939453125e-06 7.62939453125e-06
> 1.0847412 -1.52587890634e-06 0.0 0.0
> 1.0847412 -1.52587890634e-06 0.0 0.0
> 1.094278 -5.72204589933e-07 9.53674316406e-07 9.53674316406e-07
> 1.0990463 -9.53674317294e-08 4.76837158203e-07 4.76837158203e-07
> 1.0990463 -9.53674317294e-08 0.0 0.0
> 1.0990463 -9.53674317294e-08 0.0 0.0
> 1.0996424 -3.57627869541e-08 5.96046447754e-08 5.96046447754e-08
> 1.0999404 -5.96046456636e-09 2.98023223877e-08 2.98023223877e-08
> 1.0999404 -5.96046456636e-09 0.0 0.0
> 1.0999404 -5.96046456636e-09 0.0 0.0
> 1.0999776 -2.23517426789e-09 3.72529029846e-09 3.72529029846e-09
> 1.063 -3.72529118664e-10 1.86264514923e-09 1.86264514923e-09
> 1.063 -3.72529118664e-10 0.0 0.0
> 1.063 -3.72529118664e-10 0.0 0.0
> 1.086 -1.3969847501e-10 2.32830643654e-10 2.32830643654e-10
> 1.098 -2.32831531832e-11 1.16415321827e-10 1.16415321827e-10
> 1.098 -2.32831531832e-11 0.0 0.0
> 1.098 -2.32831531832e-11 0.0 0.0
> 1.099 -8.73123795486e-12 1.45519152284e-11 1.45519152284e-11
> 1.1 -1.45528034068e-12 7.27595761418e-12 7.27595761418e-12
> 1.1 -1.45528034068e-12 0.0 0.0
> 1.1 -1.45528034068e-12 0.0 0.0
> 1.1 -5.45785638906e-13 9.09494701773e-13 9.09494701773e-13
> 1.1 -9.10382880193e-14 4.54747350886e-13 4.54747350886e-13
> 1.1 -9.10382880193e-14 0.0 0.0
> 1.1 -9.10382880193e-14 0.0 0.0
> 1.1 -3.41948691585e-14 5.68434188608e-14 5.68434188608e-14
> 1.1 -5.77315972805e-15 2.84217094304e-14 2.84217094304e-14
> 1.1 -5.77315972805e-15 0.0 0.0
> 1.1 -5.77315972805e-15 0.0 0.0
> 1.1 -2.22044604925e-15 3.5527136788e-15 3.5527136788e-15
> 1.1 -4.4408920985e-16 1.7763568394e-15 1.7763568394e-15
> 1.1 -4.4408920985e-16 0.0 0.0
> 1.1 -4.4408920985e-16 0.0 0.0
> 1.1 -2.22044604925e-16 2.22044604925e-16 2.22044604925e-16
> 1.1 0.0 1.11022302463e-16 2.22044604925e-16
> 1.1 0.0 0.0 0.0
> 1.1 0.0 0.0 0.0
> 1.1 0.0 1.38777878078e-17 0.0
> 1.1 0.0 6.93889390391e-18 0.0
>
> So here we have reached the point where the maximum precision is reached -
> a doesn't change anymore, although it should. The error is about 1E-16.
>
> Now if you multiply two values with an error, the error also propagates
> into the result - PLUs the result can have its own error source - in the
> same order of magnitude.
>
> (a+e) * (a+e) = a*a + 2*a*e + e*e. So your new error term is 2*a*e + e*e or
> (2*a + e) * e.
>
> --
> http://mail.python.org/**ma

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

2011-09-07 Thread Laurent
Yes of course the use of a boolean variable is obvious but I'm mixing python 
code with html using Mako templates. In Mako for code readability reasons I try 
to stick to simple "for" and "if" constructions, and I try to avoid variables 
declarations inside the html, that's all.  Thanks anyway.
-- 
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-07 Thread Tim Chase

On 09/07/11 18:22, Laurent wrote:

Anyway I was just asking if there is something better than
enumerate. So the answer is no? The fact that I have to create
a tuple with an incrementing integer for something as simple
as checking that I'm at the head just sounds awfully
unpythonic to me.


I've made various generators that are roughly (modulo 
edge-condition & error checking) something like


 def with_prev(it):
   prev = None
   for i in it:
 yield prev, i
 i = prev

 def with_next(it):
   prev = it.next()
   for i in it:
 yield prev, i
 prev = i
   yield prev, None

which can then be used something like your original

  for cur, next in with_next(iterable):
if next is None:
  do_something_with_last(cur)
else:
  do_regular_stuff_with_non_last(cur)

  for prev, cur in with_prev(iterable):
if prev is None:
  do_something_with_first(cur)
else:
  do_something_with_others(cur)

If your iterable can return None, you could create a custom 
object to signal the non-condition:


  NO_ITEM = object()

and then use NO_ITEM in place of "None" in the above code.

-tkc


--
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-07 Thread Terry Reedy

On 9/7/2011 8:23 PM, Cameron Simpson wrote:

On 07Sep2011 16:22, Laurent  wrote:
| I totally understand the performance issue that an hypothetical
| "istail" would bring, even if I think it would just be the programmer's
| responsibility not to use it when it's not certain that an end can
| be detected.

The trouble with these things is that their presence leads to stallable
code, often in libraries. Let the programmer write code dependent on
istail() without thinking of the stall case (or even the gratuitous
execution case, as in a generator with side effects in calling .next())
and have that buried in a utilities function.

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()
 ...

that is it often thought that having offered the eof() function is a
design error. (Of course in the example above the usual python idiom
would win out from existing habit, but there are plenty of other
situations where is would just be _easy_ to rely of istail() in whatever
form.)

| But I don't see why *adding* something like "ishead" would be so bad
| (at worse by using a boolean somewhere as you mentioned).

It is not awful, but as remarked:
   - extra storage cost to _every_ iterable, for a rarely used facility
   - extra runtime cost to maintain the state
   - _retroactive_ burden on _every_ iterator implementation presently
 existing; every iterator sudden needs to implement and offer this
 extra facility to be generate purpose use
   - it is easy to provide the facility on the rare occasions when it is
 needed

Personally, I think point 3 above is the killer and 1 and 2 are serious
counter arguments.


The iterator protocol is intentionally as simple as sensibly possible.


| Anyway I was just asking if there is something better than enumerate. So
| the answer is no? The fact that I have to create a tuple with an
| incrementing integer for something as simple as checking that I'm at
| the head just sounds awfully unpythonic to me.

You can just use a boolean if you like. I have plent of loops like:

   first = true
   for i in iterable:
 if first:
   blah ...
 ...
 first = False

Cheap and easy. Cheers,


Or grab and process the first item separately from the rest.

it = iter(iterable)
try:
  first = next(it)
  
except StopIteration:
  raise ValueError("Empty iterable not allowed")
for i in it:
  

--
Terry Jan Reedy

--
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-07 Thread Laurent
Yes, I was just hoping for something already included that I wouldn't know (i'm 
new to Python).
-- 
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-07 Thread Laurent
Interesting. I will check that yield functionality out. Thanks.
-- 
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-07 Thread Terry Reedy

On 9/7/2011 8:24 PM, Steven D'Aprano wrote:


I don't think this question is meaningful. There are basically two
fundamental types of iterables, sequences and iterators.


And non-sequence iterables like set and dict.


Sequences have random access and a length, so if the "start" and "end" of
the sequence is important to you, just use indexing:

beginning = sequence[0]
end = sequence[-1]
for i, x in enumerate(sequence):
 if i == 0: print("at the beginning")
 elif i == len(sequence)-1: print("at the end")
 print(x)


And finite non-sequences can be turned into sequences with list(iterable).

--
Terry Jan Reedy

--
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-07 Thread Laurent

> I don't think this question is meaningful. There are basically two
> fundamental types of iterables, sequences and iterators.
> 
> Sequences have random access and a length, so if the "start" and "end" of
> the sequence is important to you, just use indexing:
> 
> beginning = sequence[0]
> end = sequence[-1]
> for i, x in enumerate(sequence):
> if i == 0: print("at the beginning")
> elif i == len(sequence)-1: print("at the end")
> print(x)
> 
> 
> Iterators don't have random access, and in general they don't have a
> beginning or an end. There may not be any internal sequence to speak of:
> the iterator might be getting data from a hardware device that provides
> values continuously, or some other series of values without a well-defined
> beginning or end. 

Maybe I should have said "best way to check that you didn't start the iteration 
process yet" but you see what I mean.

Well I guess I have to unlearn my bad lisp/scheme habits...

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


how to make fxn argument work with setting a field value

2011-09-07 Thread noydb
What do I need to do to line 14 code below to get it to recognize the
field name and not the argument name?

I get this error with below code at line 13, the print row.rankFld
line
>RuntimeError: Row: Field rankFld does not exist
A field called rankFld does not, should not exist.  rankFld is
"RANKa" (in this first iteration), which does exist (gets added in
line 6, verified).
Line 14 fails too, if 13 is commented out.


##
import arcpy

fc = r"C:\test\scratch.gdb\sort_test1"

def rank(inFC, outFC, scoreFld, popFld, rankFld):
arcpy.AddField_management(inFC, rankFld, "LONG")
arcpy.management.Sort(inFC, outFC, [[scoreFld, "DESCENDING"],
[popFld, "DESCENDING"]])
i = 0
print rankFld # >RANKa
rows = arcpy.UpdateCursor(fc)
for row in rows:
i = i + 1
print row.rankFld
row.rankFld = i ## line 14
rows.updateRow(row)

return sortedFC
#

out1 = r"C:\test\scratch.gdb\rankfxn6"
out2 = r"C:\test\scratch.gdb\rankfxn7"

rank(fc, out1, "SCOREa", "COUNT1", "RANKa")
rank(out1, out2, "SCOREb", "COUNT2", "RANKb")
##
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running Python Demo on the Web?

2011-09-07 Thread Laurent
Neat. But I can see some "print(x)" and some "print x". What is the Python 
version?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-09-07 Thread MRAB

On 08/09/2011 02:32, noydb wrote:

What do I need to do to line 14 code below to get it to recognize the
field name and not the argument name?

I get this error with below code at line 13, the print row.rankFld
line

RuntimeError: Row: Field rankFld does not exist

A field called rankFld does not, should not exist.  rankFld is
"RANKa" (in this first iteration), which does exist (gets added in
line 6, verified).
Line 14 fails too, if 13 is commented out.


##
import arcpy

fc = r"C:\test\scratch.gdb\sort_test1"

def rank(inFC, outFC, scoreFld, popFld, rankFld):
 arcpy.AddField_management(inFC, rankFld, "LONG")
 arcpy.management.Sort(inFC, outFC, [[scoreFld, "DESCENDING"],
[popFld, "DESCENDING"]])
 i = 0
 print rankFld #>RANKa
 rows = arcpy.UpdateCursor(fc)
 for row in rows:
 i = i + 1
 print row.rankFld
 row.rankFld = i ## line 14
 rows.updateRow(row)

 return sortedFC
#

out1 = r"C:\test\scratch.gdb\rankfxn6"
out2 = r"C:\test\scratch.gdb\rankfxn7"

rank(fc, out1, "SCOREa", "COUNT1", "RANKa")
rank(out1, out2, "SCOREb", "COUNT2", "RANKb")
##

The documentation mentions "getValue" and "setValue":

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z001q00
--
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-07 Thread Chris Rebert
On Wed, Sep 7, 2011 at 5:24 PM, Miki Tebeka  wrote:
> I guess enumerate is the best way to check for first argument. Note that if 
> someone passes you the iterator as argument you have now way of checking if 
> the consumed items from it.
>
> istail can be implemented using itertools.chain, see 
> https://gist.github.com/1202260

For the archives, if Gist ever goes down:

from itertools import chain

def istail(it):
'''Check if iterator has one more element. Return True/False and
iterator.'''
try:
i = next(it)
except StopIteration:
return False, it

try:
j = next(it)
return False, chain([i, j], it)
except StopIteration:
return True, chain([i], it)


t, it = istail(iter([]))
print t, list(it)
t, it = istail(iter([1]))
print t, list(it)
t, it = istail(iter([1, 2]))
print t, list(it)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to structure packages

2011-09-07 Thread Chris Angelico
On Thu, Sep 8, 2011 at 10:29 AM, Steven D'Aprano
 wrote:
> Peter Otten wrote:
>
>> Classes and functions are grouped into
>> submodules by their functionality rather than employing Java's mechanical
>> one-class-per-file pattern.
>
> Surely it's an anti-pattern?

I don't think that's true; Java merely enforces one _public_ class per
source file. A file can have non-public classes, although one .class
file has only one class in it (so javac will sometimes make multiple
object files from one source file). I'm not wholly sure of the
significance of public classes, though, and whether or not it's
possible to do your logical grouping and just let them be non-public.

BTW, I am not a Java fan, and I don't have any defense prepared. I
haven't actually written any serious Java code for a number of years.
Used to use it back when IBM reckoned that Java would be the big thing
that sells OS/2.

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


Re: Running Python Demo on the Web?

2011-09-07 Thread Sahil Tandon
On Wed, 2011-09-07 at 18:40:23 -0700, Laurent wrote:

> Neat. But I can see some "print(x)" and some "print x". What is the
> Python version?

See:

 http://docs.python.org/release/3.2.2/whatsnew/3.0.html#print-is-a-function
 http://www.python.org/dev/peps/pep-3105/

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


my multi-download program can't finish

2011-09-07 Thread 守株待兔
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?-- 
http://mail.python.org/mailman/listinfo/python-list


multi-down in threading module

2011-09-07 Thread 守株待兔
i want to download data in  multiprocess ,i know the threading structure,but i 
can't finish it,
would you mind to revise it ?
any advice appreciated.
[code]
import urllib
import threading
URL = "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1t1v&e=.csv";
symbols = ('GGP', 'JPM', 'AIG', 'AMZN','GGP', 'JPM', 'AIG', 'AMZN')
url =[ URL % '+'.join(sym)  for sym in symbols]

num=rang(3)  

def  down(url):
print urllib.urlopen(url).read()
  
  
for i in num:   #these code  i can't finish 
t=threading.Thread(target=down,args=  )
threads.append(t)
  
  
for i in nmu:
threads[i].start()
  

for i in num:
 threads[i].join()

[/code]-- 
http://mail.python.org/mailman/listinfo/python-list


Re: my multi-download program can't finish

2011-09-07 Thread Steven D'Aprano
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