Re: Yet another Python textbook

2012-11-20 Thread Pavel Solin
Hi Ian,
  thank you for your comments.


On Mon, Nov 19, 2012 at 11:46 PM, Ian Kelly  wrote:

> On Sun, Nov 18, 2012 at 10:30 PM, Pavel Solin 
> wrote:
> > I would like to introduce a new Python textbook
> > aimed at high school students:
> >
> > http://femhub.com/textbook-python/.
> >
> > The textbook is open source and its public Git
> > repository is located at Github:
> >
> > g...@github.com:femhub/nclab-textbook-python.git
> >
> > Feedback and contributions are very much
> > welcome, every contributor becomes automatically
> > a co-author.
>
> First impression: I'm opening up the book and reading the
> introduction, and I get to section 1.6, and the very first code
> example given is:
>
> >>> print "Hello, World!"
>

:)


>
> A fine tradition to be sure, but I have to say that I'm a little
> disappointed that a new textbook on Python being written in 2012 is
> focused squarely on Python 2, especially when I just read on the
> previous page that Python 3 was released in 2008.  Is there any work
> underway get Python 3 into NCLab?
>

There is an ongoing discussion but we are not sure.
Are there any reasons except for the print () command
and division of integers?


>
> The issue comes up again four pages later in section 2.4, when
> division is being demoed, and the text takes a page-and-a-half detour
> to caution about the use of floor division for expressions like:
>
> >>> 33 / 6
>
> If the book were teaching Python 3, then this warning would be
> unnecessary, since division in Python 3 is *automatically* true
> division, unless you go out of your way to invoke floor division by
> using the special // operator.  I think that the earliness and
> frequency that these differences arise underscore the point that it
> would be best if the book could simply be teaching Python 3 to start
> with.
>

Perhaps you are right. Is there any statistics of how many Python
programmers are using 2.7 vs. 3? Most of people I know use 2.7.


>
> Getting off that soapbox and moving along, I notice that on pages
> 20-22 there are some examples by way of comparison that are written in
> C, which makes me wonder what audience this textbook is really
> intended for.  The previous pages and references to Karel have given
> me the impression that this is geared toward beginning programmers,
> who most likely are not familiar with C.


That's exactly right.

Unfortunately, many high school teachers are using C++
to teach programming to complete beginners. This
comment is for them.  It can be removed, you can do it
if you like. The code is on Github.


> The most troublesome is the
> last of these examples, which is led up to with this text:
>
> The asterisks in the code below are pointers, an additional
> programming concept that one needs to learn and utilize here:
>
> This seems to suggest that the reader should stop reading here and do
> a Google search on pointers, in order to understand the example.
> Since this is not a textbook on C, and Python has no concept of
> pointers at all, doing this would be a complete waste of the reader's
> time.
>
> Skimming through a few more chapters, I don't see anything else that
> sets my spidey sense tingling.  I hope that what I've written above
> gives you some things to consider, though.
>

Thank you once more for the comments.

Pavel


>
> Cheers,
> Ian
>



-- 
Pavel Solin
Associate Professor
Applied and Computational Mathematics
University of Nevada, Reno
http://hpfem.org/~pavel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another Python textbook

2012-11-20 Thread Chris Angelico
On Tue, Nov 20, 2012 at 7:02 PM, Pavel Solin  wrote:
> Perhaps you are right. Is there any statistics of how many Python
> programmers are using 2.7 vs. 3? Most of people I know use 2.7.

If you're teaching Python, the stats are probably about zero for zero.
Start them off on Py3 and help move the world forward.

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


Re: Yet another Python textbook

2012-11-20 Thread Steven D'Aprano
On Mon, 19 Nov 2012 17:58:55 +0100, Kwpolska wrote:

> On Mon, Nov 19, 2012 at 6:30 AM, Pavel Solin 
> wrote:
>> I would like to introduce a new Python textbook aimed at high school
>> students:
>>
>> http://femhub.com/textbook-python/.
>>
>> The textbook is open source and its public Git repository is located at
>> Github:
>>
>> g...@github.com:femhub/nclab-textbook-python.git
> 
> URL for humans: https://github.com/femhub/nclab-textbook-python
> 
> 
>> Feedback and contributions are very much welcome, every contributor
>> becomes automatically a co-author.
>>
>> Best regards,
>>
>> Pavel
>>
>>
> You are writing it for something called “NCLab”, not for the general
> public, and that sucks.

I don't see why you say that it sucks. Why do you care if a free, useful 
Python text book drives some eyeballs to a website?




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


Re: Getting a seeded value from a list

2012-11-20 Thread Nobody
On Mon, 19 Nov 2012 21:45:55 -0800, frednotbob wrote:

> What I'm trying to do is set a persistent state for the levels generated
> by make_map(), so the player can move between floors without generating a
> totally new randomized floor each time.

You need to distinguish between immutable data (e.g. walls) and mutable
data (monsters, treasure). The former can be generated from the seed each
time you enter the level; the latter must be generated the first time then
stored.

If the number of levels is reasonable, you can use a PRNG to generate a
list of random numbers at game start, which are the seeds used to generate
each level.

Alternatively, you can generate a single random "game id" at game start
then generate the seed for each level from a hash of the level number and
the game id.

When it comes to random level generation, a single sequential PRNG isn't
always the best option, as it requires that you always use all of the
generated numbers in the same order, even if you only want a subset of the
level's data. This is particularly significant for large levels.

It's sometimes better to use a hierarchy of PRNGs, where the values
generated by higher-level PRNGs are used as seeds for the lower-level
PRNGs. This way, if you need to generate a subset of the data, you only
need to run the PRNGs for the specific subset, and their ancestors.

E.g. if you want a 256x256 grid of random numbers, you could just generate
65536 random numbers and use them in top-to-bottom, left-to-right order.
But if you only want the bottom-right tile, you still need to generate all
of the preceding numbers to ensure that you get the correct value.

A hierarchical approach would generate 4 numbers which are used as the
seeds for the 4 128x128 quarters. Each quarter uses its seed to generate 4
more numbers for the 4 64x64 quarters. And so on until you get down to a
2x2 region, at which point the 4 numbers generated are the actual values
used.

This way, calculating a single cell only requires 4*log(n) (e.g. 4*8=32)
values, while generating the entire grid only requires 33% more numbers
for the higher levels (1 + 1/4 + 1/16 + 1/64 + ... = 1+1/3).

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


Re: Python Interview Questions

2012-11-20 Thread Jean-Michel Pichavant


- Original Message -
> Use a set when you want to represent a collection of items and the
> order
> is not important:

An important feature of sets is that their items are unique.
set(list(...)) is a good shortcut to remove duplicate in a list.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Call of Papers - FOSDEM 2013 - Python Devroom

2012-11-20 Thread Stéphane Wirtel
Hi all,

This is the official call for sessions for the FOSDEM 2013 [1] python devroom.

This year, Python will be represented by its Community. If you want to discuss
with a lot of Python Users, it's the place to be in February !

Like every year, FOSDEM [1] will take place the first week-end of February in
Brussels (Belgium).

We will have a room in the K building (80 seats). This dev room will be open all
day Sunday, February 3rd.

If you want to hold a session in the Python devroom, please fill this survey [2]

Call for Papers is open until December 21st

This year, the submissions will be reviewed by a committee:

* Tarek Ziade - https://twitter.com/tarek_ziade (Mozilla)
* Ludovic Gasc - https://twitter.com/GMLudo (Eyepea)
* Christophe Simonis - https://twitter.com/KangOl (OpenERP)
* Stephane Wirtel - https://twitter.com/matrixise (OpenERP)

Thank you for submitting your sessions and see you soon in Brussels to talk
Python and/or have some nice Belgian Beers.

[1] http://fosdem.org/2013/
[2] 
https://docs.google.com/spreadsheet/viewform?formkey=dDJUWjhEYW1CRzVrSERVSmVlYkJFbnc6MQ

Here is the link of this announce: 
http://wirtel.be/posts/en/2012/11/20/call_of_papers_fosdem_2013/

Please, could you share this information, thank you

Best regards,

Stephane Wirtel (@matrixise)
-- 
http://mail.python.org/mailman/listinfo/python-list


Call of Papers - FOSDEM 2013 - Python Devroom

2012-11-20 Thread Stéphane Wirtel
Hi all,

This is the official call for sessions for the FOSDEM 2013 [1] python devroom.

This year, Python will be represented by its Community. If you want to discuss
with a lot of Python Users, it's the place to be in February !

Like every year, FOSDEM [1] will take place the first week-end of February in
Brussels (Belgium).

We will have a room in the K building (80 seats). This dev room will be open all
day Sunday, February 3rd.

If you want to hold a session in the Python devroom, please fill this survey [2]

Call for Papers is open until December 21st

This year, the submissions will be reviewed by a committee:

* Tarek Ziade - https://twitter.com/tarek_ziade (Mozilla)
* Ludovic Gasc - https://twitter.com/GMLudo (Eyepea)
* Christophe Simonis - https://twitter.com/KangOl (OpenERP)
* Stephane Wirtel - https://twitter.com/matrixise (OpenERP)

Thank you for submitting your sessions and see you soon in Brussels to talk
Python and/or have some nice Belgian Beers.

[1] http://fosdem.org/2013/
[2] 
https://docs.google.com/spreadsheet/viewform?formkey=dDJUWjhEYW1CRzVrSERVSmVlYkJFbnc6MQ

Please, could you share this information, thank you

Best regards,

Stephane Wirtel (@matrixise)
-- 
http://mail.python.org/mailman/listinfo/python-list


Using cntlm as proxy

2012-11-20 Thread jorge2
Hi everyone. I'm using cntlm locally and I want my Python scripts to 
connect to some web, parse some data and come back with results all 
across my local proxy.
I've tried a lot of example code but I still don't find what I need. I 
think I don't understand how urllib2 manages proxy.


Help will be really appreciated.

10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error

2012-11-20 Thread inshu chauhan
thanx ..I understand the problem now..


On Wed, Nov 14, 2012 at 7:48 PM, MRAB  wrote:

> On 2012-11-14 15:18, inshu chauhan wrote:
>
>>
>> for this code m getting this error :
>>
>> CODE :
>> def ComputeClasses(data):
>>  radius = .5
>>  points = []
>>  for cy in xrange(0, data.height):
>>  for cx in xrange(0, data.width):
>>  if data[cy,cx] != (0.0,0.0,0.0):
>>  centre = data[cy, cx]
>>  points.append(centre)
>>
>>
>>  Look at this line:
>
>   change = True
>>
>>  It's indented the same as the preceding 'if' statement, which means
> that it's executed even if the body of the 'if' statement wasn't
> executed and it hasn't assigned to 'centre'.
>
> So 'change' has been set to True, the 'while' loop is entered, and
> subsequently an attempt is made to get 'centre', which hasn't been set.
>
>
>   while change:
>>
>>  for ring_number in xrange(1, 1000):
>>  change = False
>>  new_indices = GenerateRing(cx, cy, ring_number)
>>
>>
>>  for idx in new_indices:
>>  point = data[idx[0], idx[1]]
>>
>>  if point == (0.0, 0.0, 0.0 ):
>>continue
>>  else:
>>  dist = distance(centre, point)
>>  if  dist < radius :
>>  print point
>>  points.append(point)
>>  change = True
>>  print change
>>
>>
>>  The indentation of this line looks wrong to me:
>
>   break
>>
>

But If I change the indentation of break towards inside, its going into
infinite loop.. ???

>
>>  It'll affect the 'for cx' loop at the end of its first iteration, every
> time.
>
>
>> ERROR :
>> Traceback (most recent call last):
>>File "Z:\modules\classification2.**py", line 74, in 
>>  ComputeClasses(data)
>>File "Z:\modules\classification2.**py", line 56, in ComputeClasses
>>  dist = distance(centre, point)
>> UnboundLocalError: local variable 'centre' referenced before assignment
>>
>> And i am unable to understand .. WHY ?
>>
>>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Greedy parsing of argparse/positional arguments

2012-11-20 Thread Johannes Bauer
Hi list,

I have a problem with Python3.2's argparse module. The following sample:

parser = argparse.ArgumentParser(prog = sys.argv[0])
parser.add_argument("-enc", metavar = "enc", nargs = "+", type = str,
default = [ "utf-8" ])
parser.add_argument("pattern", metavar = "pattern", type = str, nargs = 1)
parser.add_argument("filename", metavar = "filename", type = str, nargs = 1)
args = parser.parse_args(sys.argv[1:])

illustrates the problem: I want to be able to specify an encoding one or
more times (multiple encodings possible), have a pattern and a filename
as the last two arguments.

This works as long as I don't specify '-enc' on the command line. If I
do, for example

./foo -enc myencoding mypattern myfile

The "-enc" greedy parser seems to capture ["myencoding", "mypattern",
"myfile"], leaving nothing for "pattern" and "filename", yielding an error:

./foo: error: too few arguments

How can I force positional arguments to take precedence over optional
arguments? I could exclude them from the parsing altogether, but that
would make them not appear in the help page (which I'd like to avoid).

Best regards,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa 
-- 
http://mail.python.org/mailman/listinfo/python-list


Call of Papers - FOSDEM 2013 - Python Devroom

2012-11-20 Thread Stéphane Wirtel
Hi all,

This is the official call for sessions for the FOSDEM 2013 [1] python devroom.

This year, Python will be represented by its Community. If you want to discuss
with a lot of Python Users, it's the place to be in February !

Like every year, FOSDEM [1] will take place the first week-end of February in
Brussels (Belgium).

We will have a room in the K building (80 seats). This dev room will be open all
day Sunday, February 3rd.

If you want to hold a session in the Python devroom, please fill this survey [2]

Call for Papers is open until December 21st

This year, the submissions will be reviewed by a committee:

* Tarek Ziade - https://twitter.com/tarek_ziade (Mozilla)
* Ludovic Gasc - https://twitter.com/GMLudo (Eyepea)
* Christophe Simonis - https://twitter.com/KangOl (OpenERP)
* Stephane Wirtel - https://twitter.com/matrixise (OpenERP)

Thank you for submitting your sessions and see you soon in Brussels to talk
Python and/or have some nice Belgian Beers.

[1] http://fosdem.org/2013/
[2] 
https://docs.google.com/spreadsheet/viewform?formkey=dDJUWjhEYW1CRzVrSERVSmVlYkJFbnc6MQ

Here is the link of this announce: 
http://wirtel.be/posts/en/2012/11/20/call_of_papers_fosdem_2013/

Please, could you share this information, thank you

Best regards,

Stephane Wirtel (@matrixise)

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


RE: Python Web Routing Benchmark

2012-11-20 Thread Andriy Kornatskyy

Web Routing Benchmark has been updated with latest version of various web 
frameworks. 

http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html

Note, wheezy.web seo routing benchmark has been improved by approximately 40%.

Thanks.

Andriy Kornatskyy



> From: andriy.kornats...@live.com
> To: python-list@python.org
> Subject: Python Web Routing Benchmark
> Date: Wed, 10 Oct 2012 17:05:08 +0300
>
>
> How fast web frameworks process routing (URL dispatch)?
>
> Here is a benchmark for various web frameworks (bottle, django, flask, 
> pyramid, tornado and wheezy.web) running the following routing: static, 
> dynamic, SEO and missing... with a trivial 'hello world' application (all 
> routes are pointing to the same handler).
>
> http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html
>
> Benchmark is executed in isolated environment using CPython 2.7. Source is 
> here:
>
> https://bitbucket.org/akorn/helloworld/src/tip/02-routing
>
> Comments or suggestions are welcome.
>
> Thanks.
>
> Andriy Kornatskyy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


10 sec poll - please reply!

2012-11-20 Thread Michael Herrmann
Hi, 

I'm developing a GUI Automation library (http://www.getautoma.com) and am 
having difficulty picking a name for the function that simulates key strokes. I 
currently have it as 'type' but that clashes with the built-in function. 
Example uses of 'type': 

type(ENTER)

type("Hello World!")

type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?

Here are my thoughts so far: I could call it 'press' but then our GUI 
automation tool also allows you to click things and then "press" might be 
mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
but that is rather long and doesn't read as well, for instance in 
type_keys(ENTER).

Thank you very much!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10 sec poll - please reply!

2012-11-20 Thread Chris Angelico
On Tue, Nov 20, 2012 at 11:18 PM, Michael Herrmann
 wrote:
> Hi,
>
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type':
>
> type(ENTER)
>
> type("Hello World!")
>
> type(CTRL + 'a')
>
> What, in your view, would be the most intuitive alternative name?

I've done similar things under names like "send_keys".

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


Re: Error

2012-11-20 Thread inshu chauhan
I did the following changes in this part of my programme.. now the
refereence error is removed but its showing me another error :

def ComputeClasses(data):
radius = .5
points = []
for cy in xrange(0, data.height):
for cx in xrange(0, data.width):

if data[cy,cx] == (0.0,0.0,0.0):
continue
else :
centre = data[cy, cx]
print centre
points.append(centre)


change = True

while change:

for ring_number in xrange(1, 1000):
change = False
new_indices = GenerateRing(cx, cy, ring_number)

for idx in new_indices:
point = data[idx[0], idx[1]]

if point == (0.0, 0.0, 0.0 ):
  continue
else:

dist = distance(centre, point)
if  dist < radius :
print point
points.append(point)
change = True
print change


break


print points


ERROR :

Traceback (most recent call last):
  File "Z:/modules/classification1.py", line 71, in 
ComputeClasses(data)
  File "Z:/modules/classification1.py", line 47, in ComputeClasses
point = data[idx[0], idx[1]]
error: index is out of range

What is meant by this statement ' Index out of range ' ? Does it mean that
my range 1, 1000 is exceeded ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error

2012-11-20 Thread Dave Angel
On 11/20/2012 07:31 AM, inshu chauhan wrote:
> I did the following changes in this part of my programme.. now the
> refereence error is removed but its showing me another error :
>
> def ComputeClasses(data):
> radius = .5
> points = []
> for cy in xrange(0, data.height):
> for cx in xrange(0, data.width):
>
> if data[cy,cx] == (0.0,0.0,0.0):
> continue
> else :
> centre = data[cy, cx]
> print centre
> points.append(centre)
>
>
> change = True
>
> while change:
>
> for ring_number in xrange(1, 1000):
> change = False
> new_indices = GenerateRing(cx, cy, ring_number)
>
> for idx in new_indices:
> point = data[idx[0], idx[1]]
>
> if point == (0.0, 0.0, 0.0 ):
>   continue
> else:
>
> dist = distance(centre, point)
> if  dist < radius :
> print point
> points.append(point)
> change = True
> print change
>
>
> break
>
>
> print points
>
>
> ERROR :
>
> Traceback (most recent call last):
>   File "Z:/modules/classification1.py", line 71, in 
> ComputeClasses(data)
>   File "Z:/modules/classification1.py", line 47, in ComputeClasses
> point = data[idx[0], idx[1]]
> error: index is out of range
>
> What is meant by this statement ' Index out of range ' ? Does it mean that
> my range 1, 1000 is exceeded ??
>
>

When you're using custom classes that mimic the standard ones, the error
can mean most anything.  But assuming the design was to keep as close as
possible, it simply means that you're subscripting a list with an index
that's too large or too small.  So if idx is a list that has only one
element, element number zero, then idx[1] would be out of range.  On the
same line, if data is acting kind of like a two-dimensional list, then
it has limits on each dimension, and either idx[0] is too big/small for
the first dimension, or idx[1] is too big or small for the second.

First thing is to figure out which part of this expression is causing
the exception.  So do a separate pair of assignments,
dummy0 = idx[0]
dummy1 = idx[1]

and then  point = data[dummy0, dummy1]

Incidentally, if idx is a tuple or a list, of exactly two items, then
you could just say
   point = data[*idx]

Anyway, if that still doesn't make things clear, then print dummy0 and
dummy1 before the point= line.  That way you can see the last value, the
one it dies on, just before the stack trace.  Naturally, you could also
print the size attributes of the data item as well.


-- 

DaveA

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
You know, you would probably get more responses if you picked a 
descriptive subject line that didn't look like spam. I only read your 
post because I accidentally clicked on it.

On Tue, 20 Nov 2012 04:18:38 -0800, Michael Herrmann wrote:

> I'm developing a GUI Automation library (http://www.getautoma.com) and

By the way, your website is down.


> am having difficulty picking a name for the function that simulates key
> strokes. I currently have it as 'type' but that clashes with the
> built-in function. Example uses of 'type':
> 
> type(ENTER)
> type("Hello World!")
> type(CTRL + 'a')
> 
> What, in your view, would be the most intuitive alternative name?


I'd keep the name as "type". It exists in a different namespace to the 
builtin, so people have a choice: they can refer to the fully-qualified 
name, or not, as they prefer. I don't know the name of your module, since 
your website is down, but let's say it's called "automata":

# Option 1
import automata
automata.type("Hello World")


# Option 2
from automata import type
type("Hello World"
import builtins  # in Python 2 use __builtin__ instead
builtins.type([])



So the name clash doesn't matter.



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


Re: Error

2012-11-20 Thread Mark Lawrence

On 20/11/2012 12:31, inshu chauhan wrote:

I did the following changes in this part of my programme.. now the
refereence error is removed but its showing me another error :

def ComputeClasses(data):
 radius = .5
 points = []
 for cy in xrange(0, data.height):
 for cx in xrange(0, data.width):

 if data[cy,cx] == (0.0,0.0,0.0):
 continue
 else :
 centre = data[cy, cx]
 print centre
 points.append(centre)


 change = True

 while change:

 for ring_number in xrange(1, 1000):
 change = False
 new_indices = GenerateRing(cx, cy, ring_number)

 for idx in new_indices:
 point = data[idx[0], idx[1]]

 if point == (0.0, 0.0, 0.0 ):
   continue
 else:

 dist = distance(centre, point)
 if  dist < radius :
 print point
 points.append(point)
 change = True
 print change


 break


 print points


ERROR :

Traceback (most recent call last):
   File "Z:/modules/classification1.py", line 71, in 
 ComputeClasses(data)
   File "Z:/modules/classification1.py", line 47, in ComputeClasses
 point = data[idx[0], idx[1]]
error: index is out of range

What is meant by this statement ' Index out of range ' ? Does it mean that
my range 1, 1000 is exceeded ??




What makes you think the error applies to the value from the xrange 
call?  The traceback tells you that the error has occurred at line 47. 
Looking at that and the lines above, I'd guess your problem lies in the 
return values from the GenerateRing function.


--
Cheers.

Mark Lawrence.

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Michael Herrmann
Hi,

thank you for your replies. So far two people said 'send_keys' and one person 
said 'type'. 

Steven, thanks for your reply. Sorry if the message title disturbed you. My 
personal feelings aren't too strongly against 'type' either, but then I'm 
afraid it might bother more experienced Python programmers who are used to a 
very different meaning of 'type'. Do you think that could be a problem?

Thanks again to all who have replied,
Michael

On Tuesday, November 20, 2012 1:18:38 PM UTC+1, Michael Herrmann wrote:
> Hi, 
> 
> 
> 
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type': 
> 
> 
> 
> type(ENTER)
> 
> 
> 
> type("Hello World!")
> 
> 
> 
> type(CTRL + 'a')
> 
> 
> 
> What, in your view, would be the most intuitive alternative name?
> 
> 
> 
> Here are my thoughts so far: I could call it 'press' but then our GUI 
> automation tool also allows you to click things and then "press" might be 
> mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
> but that is rather long and doesn't read as well, for instance in 
> type_keys(ENTER).
> 
> 
> 
> Thank you very much!

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


Re: Error

2012-11-20 Thread Dave Angel
On 11/20/2012 08:19 AM, inshu chauhan wrote:
> Yes you are rightI figured that out after posting to python list.. actually
> my index is reaching the last point.. and my prog is not doing what I
> want.. I am wondering why it is reaching the last point in my list .. its
> never stopping in between ???
> 
(Please don't top-post)

If this is intended as a non-rhetorical question, a bit more specific
wording is needed.  Which index is reaching what last point?  And in
what loop is it skipping in-between values?


-- 

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Michael Herrmann
P.S.: The website is back online; our hosting provider was having technical 
problems...

On Tuesday, November 20, 2012 1:18:38 PM UTC+1, Michael Herrmann wrote:
> Hi, 
> 
> 
> 
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type': 
> 
> 
> 
> type(ENTER)
> 
> 
> 
> type("Hello World!")
> 
> 
> 
> type(CTRL + 'a')
> 
> 
> 
> What, in your view, would be the most intuitive alternative name?
> 
> 
> 
> Here are my thoughts so far: I could call it 'press' but then our GUI 
> automation tool also allows you to click things and then "press" might be 
> mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
> but that is rather long and doesn't read as well, for instance in 
> type_keys(ENTER).
> 
> 
> 
> Thank you very much!

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


Re: Error

2012-11-20 Thread inshu chauhan
Yes you are rightI figured that out after posting to python list.. actually
my index is reaching the last point.. and my prog is not doing what I
want.. I am wondering why it is reaching the last point in my list .. its
never stopping in between ???


On Tue, Nov 20, 2012 at 2:01 PM, Dave Angel  wrote:

> On 11/20/2012 07:31 AM, inshu chauhan wrote:
> > I did the following changes in this part of my programme.. now the
> > refereence error is removed but its showing me another error :
> >
> > def ComputeClasses(data):
> > radius = .5
> > points = []
> > for cy in xrange(0, data.height):
> > for cx in xrange(0, data.width):
> >
> > if data[cy,cx] == (0.0,0.0,0.0):
> > continue
> > else :
> > centre = data[cy, cx]
> > print centre
> > points.append(centre)
> >
> >
> > change = True
> >
> > while change:
> >
> > for ring_number in xrange(1, 1000):
> > change = False
> > new_indices = GenerateRing(cx, cy, ring_number)
> >
> > for idx in new_indices:
> > point = data[idx[0], idx[1]]
> >
> > if point == (0.0, 0.0, 0.0 ):
> >   continue
> > else:
> >
> > dist = distance(centre, point)
> > if  dist < radius :
> > print point
> > points.append(point)
> > change = True
> > print change
> >
> >
> > break
> >
> >
> > print points
> >
> >
> > ERROR :
> >
> > Traceback (most recent call last):
> >   File "Z:/modules/classification1.py", line 71, in 
> > ComputeClasses(data)
> >   File "Z:/modules/classification1.py", line 47, in ComputeClasses
> > point = data[idx[0], idx[1]]
> > error: index is out of range
> >
> > What is meant by this statement ' Index out of range ' ? Does it mean
> that
> > my range 1, 1000 is exceeded ??
> >
> >
>
> When you're using custom classes that mimic the standard ones, the error
> can mean most anything.  But assuming the design was to keep as close as
> possible, it simply means that you're subscripting a list with an index
> that's too large or too small.  So if idx is a list that has only one
> element, element number zero, then idx[1] would be out of range.  On the
> same line, if data is acting kind of like a two-dimensional list, then
> it has limits on each dimension, and either idx[0] is too big/small for
> the first dimension, or idx[1] is too big or small for the second.
>
> First thing is to figure out which part of this expression is causing
> the exception.  So do a separate pair of assignments,
> dummy0 = idx[0]
> dummy1 = idx[1]
>
> and then  point = data[dummy0, dummy1]
>
> Incidentally, if idx is a tuple or a list, of exactly two items, then
> you could just say
>point = data[*idx]
>
> Anyway, if that still doesn't make things clear, then print dummy0 and
> dummy1 before the point= line.  That way you can see the last value, the
> one it dies on, just before the stack trace.  Naturally, you could also
> print the size attributes of the data item as well.
>
>
> --
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with module PyVisa

2012-11-20 Thread Jean Dubois
On 11 nov, 20:30, Jean Dubois  wrote:
> On 9 nov, 22:14, w...@mac.com wrote:
>
>
>
> > On Nov 9, 2012, at 3:43 PM, Jean Dubois  wrote:
>
> > > The error may be obvious but finding this file and how to install it
> > > is not unfortunately.
> > > It seems I have to install it from the National Instruments site but
> > > Debian Linux doesn't seem to be supported...
> > > and I doubt whether just copying this file will be sufficient to make
> > > PyVisa work.
> > > I wonder whether there might be another way to communicate via USB
> > > with a Keithley programmable power supply using Python.
>
> > > best regards,
> > > Jean
>
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > I've been using pyserial quite successfully to control a USB-to-serial 
> > converter.
>
> > That is, controlling a couple of RS232 serial devices via the USB port 
> > through a KeySpan USB-to-Serial converter.
>
> > Pyserial seems to make communication through the USB port quite 
> > transparent, at least on my OS-X system.
>
> > -Bill
>
> Well, in fact I do have some working scripts using pyserial to control
> an older (and more expensive) Keithley sourcemeter in combination with
> a USB-to-serial converter.
> But the trouble started when buying a cheaper and newer Keithley model
> which does not have rs232 but only USB. I noticed they have put an
> extra layer above USB called USBTMC
> which complicates things further. I followed the instructions 
> athttp://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&l...outline
> and compiled and loaded the usbtmc-driver but I still can't
> communicate with the Keithley, hence I started looking for an
> alternative using PyVisa...and now I'm stuck
>
> jean

I finally got it working without PyVisa as follows:
#!/usr/bin/python
#sample program for Keithley 2200 USB
#first compile and load module usbtmc
import os
usbkeith = open('/dev/usbtmc1','r+')
#next commando is very important
#without it you can fetch data but not SET data
usbkeith.write("SYST:REM" + "\n")
usbkeith.write("*IDN?\n")
identification=usbkeith.readline()
print 'Found: ',identification
usbkeith.write("SOUR:CURR 0.2A\n")
usbkeith.write("SOUR:OUTP:STAT ON\n")
usbkeith.write("MEAS:VOLT?\n")
measurement=usbkeith.readline()
print 'Measured voltage: ',measurement

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Dave Angel
On 11/20/2012 07:18 AM, Michael Herrmann wrote:
> Hi, 
>
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type': 
>
> type(ENTER)
>
> type("Hello World!")
>
> type(CTRL + 'a')
>
> What, in your view, would be the most intuitive alternative name?
>
> Here are my thoughts so far: I could call it 'press' but then our GUI 
> automation tool also allows you to click things and then "press" might be 
> mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
> but that is rather long and doesn't read as well, for instance in 
> type_keys(ENTER).
>
> Thank you very much!

I also vote for send_keys(), even before I saw Chris' reply.

'type' is too overloaded a word.  For example, in Windows, it's the
command to display the contents of a file - it types it to the screen.


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


Index Error

2012-11-20 Thread inshu chauhan
def distance(c, p):
dist = sqrt(
((c[0]-p[0])**2) +
((c[1]-p[1])**2) +
((c[2]-p[2])**2)
)
return dist


def GenerateRing(x,y, N): Generates square rings around a point in data
which has 300 columns(x) and 3000 rows(y)
indices = []
for i in xrange(-N, N):
indices.append((x+i, y-N))
indices.append((x+N, y+i))
indices.append((x-i, y+N))
indices.append((x-N, y-i))
return indices


def ComputeClasses(data):
radius = .5
points = []
for cy in xrange(0, data.height):
for cx in xrange(0, data.width):

if data[cy,cx] == (0.0,0.0,0.0):
continue
else :
centre = data[cy, cx]
points.append(centre)


change = True

while change:

for ring_number in xrange(1, 100):
change = False
new_indices = GenerateRing(cx, cy, ring_number)
print new_indices
for idx in new_indices:
 I need help in this part as I am unable to device a method in
which if the
points are out of index,it should stop and
if idx[0] >= 300 and idx[1] >= 3000:   go
to next centre and start generating rings from there.. and again if the
index is out of range .. this should repeat
continue
else :
point = data[idx[0], idx[1]]
if point == (0.0, 0.0, 0.0 ):
print point
continue
else:
dist = distance(centre, point)
print dist
if  dist < radius :   and rings
should be added only when this condition is satisfied
print point
points.append(point)
change = True
print change


break


print points


ERROR now :

data loaded
[(296, 403), (298, 403), (298, 405), (296, 405), (297, 403), (298, 404),
(297, 405), (296, 404)] ... I am printing Indices to know what index it
dies out..

Traceback (most recent call last):
  File "Z:/modules/Classify.py", line 73, in 
ComputeClasses(data)
  File "Z:/modules/Classify.py", line 49, in ComputeClasses
point = data[idx[0], idx[1]]
error: index is out of range
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Index Error

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 12:43 AM, inshu chauhan  wrote:
> I need help in this part as I am unable to device a method in which if the
> points are out of index,it should stop.
>
> Traceback (most recent call last):
>   File "Z:/modules/Classify.py", line 73, in 
> ComputeClasses(data)
>   File "Z:/modules/Classify.py", line 49, in ComputeClasses
> point = data[idx[0], idx[1]]
> error: index is out of range
>

When Python throws an exception, you can catch it and handle it as you
please. In this instance, it seems to me you want to break out of one
loop (if I've read your comments correctly), so just bracket that loop
with try... except. Start here:

http://docs.python.org/3.3/tutorial/errors.html

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


Re: Index Error

2012-11-20 Thread inshu chauhan
I am using python 2.7.3 , so can it be done in that ?


On Tue, Nov 20, 2012 at 2:48 PM, Chris Angelico  wrote:

> On Wed, Nov 21, 2012 at 12:43 AM, inshu chauhan 
> wrote:
> > I need help in this part as I am unable to device a method in which if
> the
> > points are out of index,it should stop.
> >
> > Traceback (most recent call last):
> >   File "Z:/modules/Classify.py", line 73, in 
> > ComputeClasses(data)
> >   File "Z:/modules/Classify.py", line 49, in ComputeClasses
> > point = data[idx[0], idx[1]]
> > error: index is out of range
> >
>
> When Python throws an exception, you can catch it and handle it as you
> please. In this instance, it seems to me you want to break out of one
> loop (if I've read your comments correctly), so just bracket that loop
> with try... except. Start here:
>
> http://docs.python.org/3.3/tutorial/errors.html
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with list.remove() method

2012-11-20 Thread Alvaro Combo
Hi All,

I'm relatively new to Python... but I have found something I cannot explain... 
and  I'm sure you can help me.

I have the following function that serves for removing the duplicates from a 
list... It's a simple and (almost) trivial task.

I'm using WingIDE as editor/debugger and have Python 2.7.3.

When running this I have an error when trying to remove cpy_lst[4]... and ONLY 
THAT!!! Even in interactive mode!!!

Any suggestion is MOST welcome.

Best Regards

ACombo

...And the code:

def remove_dup_5_10():
"""
Remove the duplicates of a given list. The original list MUST be kept.
"""

# Set the original list
lst = ['a', 1, 10.0, 2, 'd', 'b', 'b', 'b', 1, 2, 'b' ]

# NEED to create a copy... See dicussion on Problem 5.6 and issue #2
cpy_lst = list(lst)

# Perform an infinite loop... explained later
i=0 # initialize the index
while i != len(cpy_lst):
if cpy_lst.count(cpy_lst[i]) != 1:
cpy_lst.remove(i)
else:
i += 1

print "The original List: ", lst
print "List with NO duplicates: ", cpy_lst

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


Re: Linux compatibility

2012-11-20 Thread EDI Support
On Monday, November 19, 2012 11:44:37 AM UTC-5, EDI Support wrote:
> Hi All, I would like know if Python 2.4.3 will be compatible with Linux RHEL 
> 5.5 or 6.1? Thanks Tony

Thanks everyone for your replies. To clarify, We would like to run a Proof of 
concept - that our current version 2.4.3 will run without any application or OS 
issues on RHEL 6.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Index Error

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 12:57 AM, inshu chauhan  wrote:
> I am using python 2.7.3 , so can it be done in that ?

(Please don't top-post; just delete the couple of blank lines that
gmail oh so kindly provides, and type your response at the bottom. You
may also want to consider trimming the quoted text to just what you
actually need.)

Yes, it certainly can. Go to the docs page I linked to, then up the
top left you'll see this:

 Python » 3.3.0  Documentation

with the "3.3.0" part a drop-down list. Drop it down and select 2.7,
and you'll see the equivalent page for version 2.7.3.

Have fun!

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


Re: Index Error

2012-11-20 Thread Dave Angel
On 11/20/2012 08:43 AM, inshu chauhan wrote:
> def distance(c, p):
> dist = sqrt(
> ((c[0]-p[0])**2) +
> ((c[1]-p[1])**2) +
> ((c[2]-p[2])**2)
> )
> return dist
> 
> 
> def GenerateRing(x,y, N): Generates square rings around a point in data
> which has 300 columns(x) and 3000 rows(y)
> indices = []
> for i in xrange(-N, N):
> indices.append((x+i, y-N))
> indices.append((x+N, y+i))
> indices.append((x-i, y+N))
> indices.append((x-N, y-i))
> return indices
> 
Is it possible that N is greater than either x or y ?  Are negative
subscripts permissible?

You should consider doing the clipping logic in this function, perhaps
by passing xlimit and ylimit in as arguments.



> 
> def ComputeClasses(data):
> radius = .5
> points = []
> for cy in xrange(0, data.height):
> for cx in xrange(0, data.width):
> 
> if data[cy,cx] == (0.0,0.0,0.0):
> continue
> else :
> centre = data[cy, cx]
> points.append(centre)
> 
> 
> change = True
> 
> while change:
> 
> for ring_number in xrange(1, 100):
> change = False
> new_indices = GenerateRing(cx, cy, ring_number)
> print new_indices
> for idx in new_indices:
>  I need help in this part as I am unable to device a method in
> which if the
> points are out of index,it should stop and
> if idx[0] >= 300 and idx[1] >= 3000:   go
> to next centre and start generating rings from there.. and again if the
> index is out of range .. this should repeat

This is where you're trying to clip the values that may be outside of
the total matrix.

You do not want "and" in that expression.  The way you've coded it,
it'll only skip items in which both indices are out of range.  Change it to
  if idx[0] >= data.width or idx[1] >= data.height:

and depending on your answer to my earlier query, you may want to also
check if either subscript is negative.

> continue
> else :
> point = data[idx[0], idx[1]]
> if point == (0.0, 0.0, 0.0 ):
> print point
> continue
> else:
> dist = distance(centre, point)
> print dist
> if  dist < radius :   and rings
> should be added only when this condition is satisfied
> print point
> points.append(point)
> change = True
> print change
> 
> 
> break

Why do you want to terminate the loop after only iteration?

> 
> 
> print points
> 
> 
> ERROR now :
> 
> data loaded
> [(296, 403), (298, 403), (298, 405), (296, 405), (297, 403), (298, 404),
> (297, 405), (296, 404)] ... I am printing Indices to know what index it
> dies out..
> 
> Traceback (most recent call last):
>   File "Z:/modules/Classify.py", line 73, in 
> ComputeClasses(data)
>   File "Z:/modules/Classify.py", line 49, in ComputeClasses
> point = data[idx[0], idx[1]]
> error: index is out of range
> 


-- 

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


Re: Index Error

2012-11-20 Thread inshu chauhan
On Tue, Nov 20, 2012 at 3:00 PM, Chris Angelico  wrote:

> On Wed, Nov 21, 2012 at 12:57 AM, inshu chauhan 
> wrote:
> > I am using python 2.7.3 , so can it be done in that ?
>
> (Please don't top-post; just delete the couple of blank lines that
> gmail oh so kindly provides, and type your response at the bottom. You
> may also want to consider trimming the quoted text to just what you
> actually need.)
>
> Yes, it certainly can. Go to the docs page I linked to, then up the
> top left you'll see this:
>
>  Python » 3.3.0  Documentation
>
> with the "3.3.0" part a drop-down list. Drop it down and select 2.7,
> and you'll see the equivalent page for version 2.7.3.
>
> Have fun!
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Ok.. Thanks a ton ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with list.remove() method

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 12:56 AM, Alvaro Combo  wrote:
> Hi All,
>
> I'm relatively new to Python... but I have found something I cannot 
> explain... and  I'm sure you can help me.
>
> I have the following function that serves for removing the duplicates from a 
> list... It's a simple and (almost) trivial task.
>
> I'm using WingIDE as editor/debugger and have Python 2.7.3.
>
> When running this I have an error when trying to remove cpy_lst[4]... and 
> ONLY THAT!!! Even in interactive mode!!!

Several points here. You've written a beautiful O(N^2) duplicates
remover... Python has a really fast way of doing it, if you don't mind
losing order:

cpy_lst = list(set(lst))

But let's assume you're doing this for the exercise. Your technique is
fine, if inefficient on large lists, but the remove() method looks for
the first occurrence of an element by its value - what you want is:

del cpy_lst[i]

which will remove one element by index.

With that change, you'll have a slightly odd duplicate remover that
keeps the *last* of any given element. That's rather unusual. Instead,
you may want to consider maintaining a set of "items I've already
seen", and keeping all elements that aren't in that set. I won't give
you all the code, but here's the basic set operations:

sighted = set()
sighted.add(some_element)
if some_element in sighted:   # condition is True if you've already
seen this element

Hope that helps!

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


Re: Index Error

2012-11-20 Thread inshu chauhan
> def GenerateRing(x,y, N): Generates square rings around a point in data
> > which has 300 columns(x) and 3000 rows(y)
> > indices = []
> > for i in xrange(-N, N):
> > indices.append((x+i, y-N))
> > indices.append((x+N, y+i))
> > indices.append((x-i, y+N))
> > indices.append((x-N, y-i))
> > return indices
> >
> Is it possible that N is greater than either x or y ?  Are negative
> subscripts permissible?
>
> You should consider doing the clipping logic in this function, perhaps
> by passing xlimit and ylimit in as arguments.>
>


Yes N cannot be greater than x and y and it cant be negative too...

>  I need help in this part as I am unable to device a method in
> which if the
> points are out of index,it should stop and
> if idx[0] >= 300 and idx[1] >= 3000:   go
> to next centre and start generating rings from there.. and again if the
> index is out of range .. this should repeat

This is where you're trying to clip the values that may be outside of
> the total matrix.
>

Yes I am trying to clip the values here but its not working actually , I
mean not at all working

>
> You do not want "and" in that expression.  The way you've coded it,
> it'll only skip items in which both indices are out of range.  Change it to
>   if idx[0] >= data.width or idx[1] >= data.height:
>
> and depending on your answer to my earlier query, you may want to also
> check if either subscript is negative.
>
> > continue
> > else :
> > point = data[idx[0], idx[1]]
> > if point == (0.0, 0.0, 0.0 ):
> > print point
> > continue
> > else:
> > dist = distance(centre, point)
> > print dist
> > if  dist < radius :   and
> rings
> > should be added only when this condition is satisfied
> > print point
> > points.append(point)
> > change = True
> > print change
> >
> >
> > break
>
> Why do you want to terminate the loop after only iteration?
>

I dint get your question ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with list.remove() method

2012-11-20 Thread Alvaro Combo
Dear Chris,

Thank you very much for you reply... 
For a newcomer to Python the Hell is in the details... :-).

You are absolutely right... and I just used the index instead of the value.

Regarding you other (most relevant) comments, I absolutely agree... BUT in 
those cases... I was aware :-). But since it is in fact an exercise... and 
having N^2 operations... is not important. Still your comments are quite 
pertinent.

Once again, Thank you and best regards

ACombo

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


Re: Index Error

2012-11-20 Thread Dave Angel
On 11/20/2012 09:11 AM, inshu chauhan wrote:
> On Tue, Nov 20, 2012 at 3:00 PM, Chris Angelico  wrote:
>
>> On Wed, Nov 21, 2012 at 12:57 AM, inshu chauhan 
>> wrote:
>>> I am using python 2.7.3 , so can it be done in that ?
>> (Please don't top-post; just delete the couple of blank lines that
>> gmail oh so kindly provides, and type your response at the bottom. You
>> may also want to consider trimming the quoted text to just what you
>> actually need.)
>>
>> Yes, it certainly can. Go to the docs page I linked to, then up the
>> top left you'll see this:
>>
>>  Python » 3.3.0  Documentation
>>
>> with the "3.3.0" part a drop-down list. Drop it down and select 2.7,
>> and you'll see the equivalent page for version 2.7.3.
>>
>> Have fun!
>>
>> ChrisA
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> Ok.. Thanks a ton ...
>
>
>

The catch to the approach suggested by Chris is that you DON'T want to
break out of the whole loop when one value is out of range.  You only
want to skip that one point.



-- 

DaveA

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Neil Cerutti
On 2012-11-20, Dave Angel  wrote:
> I also vote for send_keys(), even before I saw Chris' reply.
>
> 'type' is too overloaded a word.  For example, in Windows, it's
> the command to display the contents of a file - it types it to
> the screen.

type is a nice verb, but since it's also a well-used noun it's
perhaps not quite as good as send.

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


Re: Index Error

2012-11-20 Thread Dave Angel
On 11/20/2012 09:26 AM, inshu chauhan wrote:
>> def GenerateRing(x,y, N): Generates square rings around a point in data
>>> which has 300 columns(x) and 3000 rows(y)
>>> indices = []
>>> for i in xrange(-N, N):
>>> indices.append((x+i, y-N))
>>> indices.append((x+N, y+i))
>>> indices.append((x-i, y+N))
>>> indices.append((x-N, y-i))
>>> return indices
>>>
>> Is it possible that N is greater than either x or y ?  Are negative
>> subscripts permissible?
>>
>> You should consider doing the clipping logic in this function, perhaps
>> by passing xlimit and ylimit in as arguments.>
>>
> 
> 
> Yes N cannot be greater than x and y and it cant be negative too...
> 
>>  I need help in this part as I am unable to device a method in
>> which if the
>> points are out of index,it should stop and
>> if idx[0] >= 300 and idx[1] >= 3000:   go
>> to next centre and start generating rings from there.. and again if the
>> index is out of range .. this should repeat
> 
> This is where you're trying to clip the values that may be outside of
>> the total matrix.
>>
> 
> Yes I am trying to clip the values here but its not working actually , I
> mean not at all working
> 

So did you read the following paragraphs?  You should not be using "and"
in that expression.

>>
>> You do not want "and" in that expression.  The way you've coded it,
>> it'll only skip items in which both indices are out of range.  Change it to
>>   if idx[0] >= data.width or idx[1] >= data.height:
>>
>> and depending on your answer to my earlier query, you may want to also
>> check if either subscript is negative.
>>
>>> continue
>>> else :
>>> point = data[idx[0], idx[1]]
>>> if point == (0.0, 0.0, 0.0 ):
>>> print point
>>> continue
>>> else:
>>> dist = distance(centre, point)
>>> print dist
>>> if  dist < radius :   and
>> rings
>>> should be added only when this condition is satisfied
>>> print point
>>> points.append(point)
>>> change = True
>>> print change
>>>
>>>
>>> break
>>
>> Why do you want to terminate the loop after only iteration?
>>
> 
> I dint get your question ??
> 

You have a break there.  What's it for?  It'll make sure you only
process one of the idx values from new_indices.  i doubt that's what you
intended.


-- 

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


proxy??

2012-11-20 Thread Jorge Alberto Diaz Orozco

Hi there.
Does anyone knows how to manage headers using a simple proxy???
I'm doing this but It gives me problems In some pages.

import SocketServer
import SimpleHTTPServer
import urllib2

PORT = 

class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
try:
print self.path
self.copyfile(urllib2.urlopen(self.path), self.wfile)
except:
print 'error',self.path

httpd = SocketServer.ForkingTCPServer(('127.0.0.1', PORT), Proxy)
print "serving at port", PORT
httpd.serve_forever()

10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci
--
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another Python textbook

2012-11-20 Thread wxjmfauth
Le mardi 20 novembre 2012 09:09:50 UTC+1, Chris Angelico a écrit :
> On Tue, Nov 20, 2012 at 7:02 PM, Pavel Solin  wrote:
> 
> > Perhaps you are right. Is there any statistics of how many Python
> 
> > programmers are using 2.7 vs. 3? Most of people I know use 2.7.
> 
> 
> 
> If you're teaching Python, the stats are probably about zero for zero.
> 
> Start them off on Py3 and help move the world forward.
> 
> 
> 
> ChrisA



Do not count with me.

The absurd flexible string representation has practically
borrowed the idea to propose once Python has a teaching tool.

jmf

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


Re: Index Error

2012-11-20 Thread inshu chauhan
>
>
> So did you read the following paragraphs?  You should not be using "and"
> in that expression.



> Yes i tried "or" also but no use .
>
> >>
> >> You do not want "and" in that expression.  The way you've coded it,
> >> it'll only skip items in which both indices are out of range.  Change
> it to
> >>   if idx[0] >= data.width or idx[1] >= data.height:
> >>
> >> and depending on your answer to my earlier query, you may want to also
> >> check if either subscript is negative.
> >>
> >>> continue
> >>> else :
> >>> point = data[idx[0], idx[1]]
> >>> if point == (0.0, 0.0, 0.0 ):
> >>> print point
> >>> continue
> >>> else:
> >>> dist = distance(centre, point)
> >>> print dist
> >>> if  dist < radius :   and
> >> rings
> >>> should be added only when this condition is satisfied
> >>> print point
> >>> points.append(point)
> >>> change = True
> >>> print change
> >>>
> >>>
> >>> break
> >>
> >> Why do you want to terminate the loop after only iteration?
> >>
> >
> > I dint get your question ??
> >
>
> You have a break there.  What's it for?  It'll make sure you only
> process one of the idx values from new_indices.  i doubt that's what you
> intended.
>
The idea here is if no more point is added to the list of points i.e. all
points surrounding the centre is zero.. I want to break the loop and go to
the next point..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems on these two questions

2012-11-20 Thread Neil Cerutti
On 2012-11-19, Dennis Lee Bieber  wrote:
> On Sun, 18 Nov 2012 17:52:35 -0800 (PST), su29090
> <129k...@gmail.com> declaimed the following in
> gmane.comp.python.general:
>
>> 
>> I all of the other problems but I have issues with these:
>> 
>> 1.Given a positive integer  n , assign True to  is_prime if  n
>> has no factors other than  1 and itself. (Remember,  m is a
>> factor of  n if  m divides  n evenly.) 
>>
>   Google: Sieve of Eratosthenes (might be mis-spelled)

The sieve is a nice simple and fast algorithm, provided there's a
bound on the highest n you need to check. It's much less simple
and less fast if n is unbounded or the bound is unknown.

Python's standard library isn't equipped with the an obvious
collection to use to implement it either.

>> 2.An  arithmetic progression is a sequence of numbers in which
>> the distance (or difference) between any two successive
>> numbers if the same. This in the sequence  1, 3, 5, 7, ... ,
>> the distance is 2 while in the sequence  6, 12, 18, 24, ... ,
>> the distance is 6. 
>> 
>>  Given the positive integer  distance and the positive integer
>>  n , associate the variable  sum with the sum of the elements
>>  of the arithmetic progression from  1 to  n with distance
>>  distance . For example, if  distance is 2 and  n is  10 ,
>>  then  sum would be associated with  26 because  1+3+5+7+9 =
>>  25 . 
>
> So, what have you tried?
>
> Consider: you have a "sum", you have a sequence of "elements"
> (based upon a spacing "distance"), and you have an upper bound
> "n"
>
> You need to generate a sequence of "elements" starting at "1",
> using "distance" as the spacing, until you exceed "n", and you
> want to produce a "sum" of all those elements...

This one's sort of a trick question, depending on your definition
of "trick". The most obvious implementation is pretty good.

In both cases a web search and a little high-density reading
provides insights and examples for the OP.

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


Re: Index Error

2012-11-20 Thread inshu chauhan
The catch to the approach suggested by Chris is that you DON'T want to
> break out of the whole loop when one value is out of range.  You only
> want to skip that one point.
>
>
> Yes I want to skip only that one point (centre)  but try and expect seems
to be the last option.. I would like to try other ways first..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10 sec poll - please reply!

2012-11-20 Thread Michael Herrmann
Thanks again for your further replies. So far, it's 4 votes for 'send_keys' and 
1 vote for 'type'. 

Regarding 'send_keys': To me personally it makes sense to send keys _to_ 
something. However, in our API, send_keys would not be called on an object or 
with a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')

Does that change your preference for 'send_keys'?

Thanks a lot!!!

On Tuesday, November 20, 2012 1:18:38 PM UTC+1, Michael Herrmann wrote:
> Hi, 
> 
> 
> 
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type': 
> 
> 
> 
> type(ENTER)
> 
> 
> 
> type("Hello World!")
> 
> 
> 
> type(CTRL + 'a')
> 
> 
> 
> What, in your view, would be the most intuitive alternative name?
> 
> 
> 
> Here are my thoughts so far: I could call it 'press' but then our GUI 
> automation tool also allows you to click things and then "press" might be 
> mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
> but that is rather long and doesn't read as well, for instance in 
> type_keys(ENTER).
> 
> 
> 
> Thank you very much!

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


Re: Index Error

2012-11-20 Thread inshu chauhan
I dont want error actually to come.  With try nd except , the error will
come but without affecting my prog...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 10 sec poll - please reply!

2012-11-20 Thread MRAB

On 2012-11-20 15:18, Michael Herrmann wrote:

Thanks again for your further replies. So far, it's 4 votes for 'send_keys' and 
1 vote for 'type'.

Regarding 'send_keys': To me personally it makes sense to send keys _to_ 
something. However, in our API, send_keys would not be called on an object or 
with a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')

Does that change your preference for 'send_keys'?


Calling it "send_keys" does have precedent.

There's a module called SendKeys which uses the SendKeys system call in
Windows. Unfortunately, the last version was for Python 2.6.

When I wanted the functionality for Python 3.3 I had to write my own.
--
http://mail.python.org/mailman/listinfo/python-list


Path Browser seems to be broken

2012-11-20 Thread Daniel Klein
If you try to expand any of the paths in the Path Browser (by clicking the
+ sign) then it not only closes the Path Browser but it also closes all
other windows that were opened in IDLE, including the IDLE interpreter
itself.

A Google search doesn't look like this been reported. If this is truly a
bug then can you point me in the right direction for issuing a bug report?

I'm running...

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64
bit (AMD64)] on win32

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


Re: 10 sec poll - please reply!

2012-11-20 Thread John Gordon
In <3d71f175-164e-494c-a521-2eaa5679b...@googlegroups.com> Michael Herrmann 
 writes:

> What, in your view, would be the most intuitive alternative name?

keyboard_input().

-- 
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: Index Error

2012-11-20 Thread Dave Angel
On 11/20/2012 10:01 AM, inshu chauhan wrote:
>>
>>
>> So did you read the following paragraphs?  You should not be using "and"
>> in that expression.
> 
> 
> 
>> Yes i tried "or" also but no use .

Explain "no use".  If you mean you still fail, then what else did you
try?  For example, did you try interchanging the two subscripts?  I've
suspected all along that the meanings of row and column, x and y, [0]
and [1], height and width are possibly confused.  Perhaps it'd be better
if you used a similar terminology everywhere.

Or perhaps you should simply make a class called Point, with attributes
x and y.  And use instances of that class rather than tuples.  And start
the function by defining  xmax and ymax, from  data.height and
data.width (in whatever order matches the docs of that library you're using)


>>

 You do not want "and" in that expression.  The way you've coded it,
 it'll only skip items in which both indices are out of range.  Change
>> it to
   if idx[0] >= data.width or idx[1] >= data.height:

 and depending on your answer to my earlier query, you may want to also
 check if either subscript is negative.

> continue
> else :
> point = data[idx[0], idx[1]]
> if point == (0.0, 0.0, 0.0 ):
> print point
> continue
> else:
> dist = distance(centre, point)
> print dist
> if  dist < radius :   and
 rings
> should be added only when this condition is satisfied
> print point
> points.append(point)
> change = True
> print change
>
>
> break

 Why do you want to terminate the loop after only iteration?

>>>   
> The idea here is if no more point is added to the list of points i.e. all
> points surrounding the centre is zero.. I want to break the loop and go to
> the next point..
> 
That's not at all what the break does.  But it's probably not what you
meant to say anyway.
> 
I think what you're saying is that you want to append at most one of the
points from the ring.  In that case, the break is appropriate, but it'd
be much clearer if it were inside the clause that triggers it, the place
where you say points.append(point).  (naturally, it'd be at the end of
that clause, following print change.)  In other words indent it to line
up with print change.

Back to an earlier comment.  I asked if N was ever bigger than x or
bigger than y, and you said never.  But your ComputeClasses will have
such a case the very first time around, when cx==0, cy==0, and
ring_number == 1.

Have you actually tested a trivial nested loop:

   for cy in xrange(0, data.height):
for cx in xrange(0, data.width):
point = data[cy, cx]

to see whether it blows up.  And if it does, whether reversing cy and cx
will change it?


Your comment in the line:
 if  dist < radius :and rings should be added
   only when this condition is satisfied

is confusing to me.  How can you make the call to GenerateRing() after
this test, when this test is measuring something about one of the values
returned by GenerateRing ?

I must confess I have no idea what data represents.  When you're doing
rings, you use deltas on the cx and cy values.  But when you're
computing radius, you use the 3d coordinates returned by  data[cx, cy].
 So is data some kind of transformation, like a projection from a 3d
object into a plane ?



-- 

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Dave Angel
On 11/20/2012 11:09 AM, John Gordon wrote:
> In <3d71f175-164e-494c-a521-2eaa5679b...@googlegroups.com> Michael Herrmann 
>  writes:
>
>> What, in your view, would be the most intuitive alternative name?
> keyboard_input().
>

Well, since Python already has input() and raw_input(), it would then be
clear that keyboard_input() would take some kind of data from the
keyboard, not send it.



-- 

DaveA

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


Re: 10 sec poll - please reply!

2012-11-20 Thread emile

On 11/20/2012 04:18 AM, Michael Herrmann wrote:

Hi,

I'm developing a GUI Automation library (http://www.getautoma.com) and am 
having difficulty picking a name for the function that simulates key strokes. I 
currently have it as 'type' but that clashes with the built-in function. 
Example uses of 'type':

type(ENTER)

type("Hello World!")

type(CTRL + 'a')

What, in your view, would be the most intuitive alternative name?

Here are my thoughts so far: I could call it 'press'


I have several tools that distinguish between press and release for 
this.  You may want to consider having both.


Emile

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Mark Lawrence

On 20/11/2012 15:18, Michael Herrmann wrote:

Thanks again for your further replies. So far, it's 4 votes for 'send_keys' and 
1 vote for 'type'.

Regarding 'send_keys': To me personally it makes sense to send keys _to_ 
something. However, in our API, send_keys would not be called on an object or 
with a parameter indicating the target. It would just be

send_keys(ENTER)
send_keys("Hello World!")
send_keys(CTRL + 'a')


In that case I'd just call it keys, that shouldn't cause too much 
confusion :)  Though keys_pressed comes to mind as an alternative.




Does that change your preference for 'send_keys'?

Thanks a lot!!!



--
Cheers.

Mark Lawrence.

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Steven D'Aprano
On Tue, 20 Nov 2012 07:18:42 -0800, Michael Herrmann wrote:

> Thanks again for your further replies. So far, it's 4 votes for
> 'send_keys' and 1 vote for 'type'.
> 
> Regarding 'send_keys': To me personally it makes sense to send keys _to_
> something. However, in our API, send_keys would not be called on an
> object or with a parameter indicating the target. It would just be
> 
> send_keys(ENTER)
> send_keys("Hello World!")
> send_keys(CTRL + 'a')


"send_keys" is wrong, because you aren't sending keys. You're sending 
strings, except you aren't actually sending strings either, because 
"send" does not make sense without a target. You're automating the typing 
of strings, including control characters.

I believe that your initial instinct for the name of this function was 
correct. It automates typing, so you should call it "type" or (for those 
paranoid about shadowing the built-in, "type_str".



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


Re: 10 sec poll - please reply!

2012-11-20 Thread mherrmann . at
That's a very good suggestion Emile!! So I might eventually need both 'press' 
and 'release' (or press_key/release_key). Thanks for this!

To everyone else who has been so kind to reply thus far: What do you think of 
generate_keystrokes? It's a bit long but describes exactly what the function 
would be doing. 

All of you are a great help and I really appreciate it. Thank you!

Michael

On Tuesday, 20 November 2012 17:21:38 UTC+1, emile  wrote:
> On 11/20/2012 04:18 AM, Michael Herrmann wrote:
> 
> > Hi,
> 
> >
> 
> > I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> > having difficulty picking a name for the function that simulates key 
> > strokes. I currently have it as 'type' but that clashes with the built-in 
> > function. Example uses of 'type':
> 
> >
> 
> > type(ENTER)
> 
> >
> 
> > type("Hello World!")
> 
> >
> 
> > type(CTRL + 'a')
> 
> >
> 
> > What, in your view, would be the most intuitive alternative name?
> 
> >
> 
> > Here are my thoughts so far: I could call it 'press'
> 
> 
> 
> I have several tools that distinguish between press and release for 
> 
> this.  You may want to consider having both.
> 
> 
> 
> Emile

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


Re: Yet another Python textbook

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 1:02 AM, Pavel Solin  wrote:
> There is an ongoing discussion but we are not sure.
> Are there any reasons except for the print () command
> and division of integers?

The big one is that Python 3 holds the future of Python development.
There are no more feature releases planned for the 2.x series, only
maintenance releases.  Eventually, Python 2.7 is going to start
looking pretty old.

You might look through the whatsnew documents at:

http://docs.python.org/3/whatsnew/index.html

to get an idea of what features have been added in Python 3.  Many of
these have been backported to Python 2.6 or 2.7, possibly requiring a
__future__ import, but most have not.  One change that comes to my
mind that might be of interest for NCLab is that in Python 3.3, the
decimal module has been rewritten in C for a major speed-up.
-- 
http://mail.python.org/mailman/listinfo/python-list


The type.__call__() method manages the calls to __new__ and __init__?

2012-11-20 Thread Marco

Looking at the documentation of Py3.3:

http://docs.python.org/3.3/reference/datamodel.html#object.__new__

I saw the method `__new__()` is called automatically when I create an 
istance. After the call to __new__(), if it returns an instance `self` 
then `self.__init__()` is called.


Because when I call an instance the __call__ method is called, and 
because the classes are instances of type, I thought when I call a Foo 
class this imply the call type.__call__(Foo), and so this one manages 
the Foo.__new__ and Foo.__init__ calls:


>>> class Foo:
... def __new__(cls):
... print('Foo.__new__()')
... return super().__new__(cls)
... def __init__(self):
... print('Foo.__init__(self)')
...
>>> f = type.__call__(Foo)
Foo.__new__()
Foo.__init__(self)

Is that right? Thanks in advance


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


Web Frameworks Excessive Complexity

2012-11-20 Thread Andriy Kornatskyy

Cyclomatic (or conditional) complexity is a metric used to indicate the 
complexity of a source code. Excessive complexity is something that is beyond 
recommended 
level of 10 (threshold that points to the fact the source code is too 
complex and refactoring is suggested). Here is a list of web frameworks 
examined: bottle, cherrypy, circuits, 
django, flask, pyramid, pysi, tornado, turbogears, web.py, web2py and 
wheezy.web.

You can read more here:

http://mindref.blogspot.com/2012/11/python-web-excessive-complexity.html

Thanks.

Comments or suggestions are welcome.

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


Re: How to use the python to do the unit test

2012-11-20 Thread emile

On 11/20/2012 09:40 AM, yujian4newsgr...@gmail.com wrote:

I write a mfc application, then I want to use the python to test this 
application. just as user  click that button.  Please tell me how to write the 
python application?


I currently use MacroScheduler (http://www.mjtnet.com/) then write 
macros from within python and run them using the commands module to  test.


Emile

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


Re: Path Browser seems to be broken

2012-11-20 Thread Peter Otten
Daniel Klein wrote:

> If you try to expand any of the paths in the Path Browser (by clicking the
> + sign) then it not only closes the Path Browser but it also closes all
> other windows that were opened in IDLE, including the IDLE interpreter
> itself.
> 
> A Google search doesn't look like this been reported. If this is truly a
> bug 

It is.

> then can you point me in the right direction for issuing a bug report?

 is the place to go...

 
> I'm running...
> 
> Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64
> bit (AMD64)] on win32


but this bug has already been reported:



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


Re: Printing time in "at" format?

2012-11-20 Thread Roy Smith
On Nov 20, 2012, at 1:16 PM, Tim Chase wrote:

> Your statement can be ambiguously parsed as "I need to merely
> *generate* time specifications that 'at' can parse", or it can be
> parsed as "I need to generate *and consume* time specifications the
> same way as 'at' does"
> 
> If it's the former, it's pretty easy--'at' accepts a wide variety of
> formats.

Fortunately, it's the former.

Since posting my original query, I have discovered by experimentation that the 
API also accepts a string of digits as a unix timestamp, so this turns out to 
be trivial.

---
Roy Smith
r...@panix.com



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


Re: Stack_overflow error

2012-11-20 Thread Dieter Maurer
Aung Thet Naing  writes:

> I'm having Stack_overflow exception in _ctypes_callproc (callproc.c). The 
> error actually come from the:
>
>  cleanup:
> for (i = 0; i < argcount; ++i)
> Py_XDECREF(args[i].keep);
>
> when args[i].keep->ob_refCnt == 1

Really a stack overflow or a general segmentation violation?
Under *nix, both are not easy to distinguish -- but maybe, you are
working with Windows?

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


Re: re.search when used within an if/else fails

2012-11-20 Thread Kevin T
On Monday, November 19, 2012 7:29:20 PM UTC-6, Steven D'Aprano wrote:
> On Tue, 20 Nov 2012 01:24:54 +, Steven D'Aprano wrote:
> 
> 
> 
> - use "if something is None", not == None.
> 
> 
> Steven

i will not include line #'s in the future, point taken
i will change ==/!= to is/is not as most people pointed out.

there is no else because it doesn't work.

i used eclipse in debug mode and a command line execution of the code, both 
behave the same way

#if re.search( "rsrvd", sigName ) :   #version a
#if re.search( "rsrvd", sigName ) == None :   #version b
if re.search( "rsrvd", sigName ) is None :   #version bb
   print sigName 
   newVal = "%s%s" % ('1'*signal['bits'] , newVal ) 
#else: #version c
if re.search( "rsrvd", sigName ) != None :   #version d
   print sigName 
   newVal = "%s%s" % ( '0'*signal['bits'],> newVal ) 

i can use either version a/b the else clause (version c) will not execute.
fortunately,  with version bb, the else clause will execute!!  

thanks for the input all..

kevin

Now if i change
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type.__call__() method manages the calls to __new__ and __init__?

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 10:29 AM, Marco  wrote:
> Because when I call an instance the __call__ method is called, and because
> the classes are instances of type, I thought when I call a Foo class this
> imply the call type.__call__(Foo), and so this one manages the Foo.__new__
> and Foo.__init__ calls:

Yes, that's right.  Observe:

>>> class MetaFoo(type):
... def __call__(cls):
... print("before")
... self = super().__call__()
... print("after", self)
... return self
...
>>> class Foo(metaclass=MetaFoo):
... def __new__(cls):
... print("__new__")
... return super().__new__(cls)
... def __init__(self):
... print("__init__")
...
>>> f = Foo()
before
__new__
__init__
after <__main__.Foo object at 0x00C55410>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web Frameworks Excessive Complexity

2012-11-20 Thread Robert Kern

On 20/11/2012 17:41, Andriy Kornatskyy wrote:


Cyclomatic (or conditional) complexity is a metric used to indicate the 
complexity of a source code. Excessive complexity is something that is beyond 
recommended
level of 10 (threshold that points to the fact the source code is too
complex and refactoring is suggested). Here is a list of web frameworks 
examined: bottle, cherrypy, circuits,
django, flask, pyramid, pysi, tornado, turbogears, web.py, web2py and
wheezy.web.


Cyclomatic complexity tells you nothing that counting lines of code doesn't 
already.

  http://www.scirp.org/Journal/PaperInformation.aspx?paperID=779

--
Robert Kern

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

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


Re: re.search when used within an if/else fails

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 12:09 PM, Kevin T  wrote:
> #if re.search( "rsrvd", sigName ) :   #version a
> #if re.search( "rsrvd", sigName ) == None :   #version b
> if re.search( "rsrvd", sigName ) is None :   #version bb
>print sigName
>newVal = "%s%s" % ('1'*signal['bits'] , newVal )
> #else: #version c
> if re.search( "rsrvd", sigName ) != None :   #version d
>print sigName
>newVal = "%s%s" % ( '0'*signal['bits'],> newVal )
>
> i can use either version a/b the else clause (version c) will not execute.
> fortunately,  with version bb, the else clause will execute!!

There must be some other difference in your testing.  I don't have
Python 2.4 available, but I tried your version a in both Python 2.3
and 2.5 using made-up values for sigName, and the else clause is
executed in both.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.search when used within an if/else fails

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 12:37 PM, Ian Kelly  wrote:
> On Tue, Nov 20, 2012 at 12:09 PM, Kevin T  wrote:
>> #if re.search( "rsrvd", sigName ) :   #version a
>> #if re.search( "rsrvd", sigName ) == None :   #version b
>> if re.search( "rsrvd", sigName ) is None :   #version bb
>>print sigName
>>newVal = "%s%s" % ('1'*signal['bits'] , newVal )
>> #else: #version c
>> if re.search( "rsrvd", sigName ) != None :   #version d
>>print sigName
>>newVal = "%s%s" % ( '0'*signal['bits'],> newVal )
>>
>> i can use either version a/b the else clause (version c) will not execute.
>> fortunately,  with version bb, the else clause will execute!!
>
> There must be some other difference in your testing.  I don't have
> Python 2.4 available, but I tried your version a in both Python 2.3
> and 2.5 using made-up values for sigName, and the else clause is
> executed in both.

It should be noted, however, that version a is the logical *inverse*
of both b and bb.  With version a, you're testing for the logical
truth of the re.search result; it will be true if it is *not* None.
With the other two you are testing that the result *is* None.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Web Frameworks Excessive Complexity

2012-11-20 Thread Andriy Kornatskyy

Robert,

Thank you for the comment. I do not try relate CC with LOC. Instead pointing to 
excessive complexity, something that is beyond recommended threshold, a subject 
to refactoring in respective web frameworks. Those areas are likely to be 
potential source of bugs (e.g. due to low code coverage with unit tests) thus 
have certain degree of interest to both: end users and framework developers.

Thanks.

Andriy Kornatskyy



> To: python-list@python.org
> From: robert.k...@gmail.com
> Subject: Re: Web Frameworks Excessive Complexity
> Date: Tue, 20 Nov 2012 19:32:31 +
>
> On 20/11/2012 17:41, Andriy Kornatskyy wrote:
> >
> > Cyclomatic (or conditional) complexity is a metric used to indicate the 
> > complexity of a source code. Excessive complexity is something that is 
> > beyond recommended
> > level of 10 (threshold that points to the fact the source code is too
> > complex and refactoring is suggested). Here is a list of web frameworks 
> > examined: bottle, cherrypy, circuits,
> > django, flask, pyramid, pysi, tornado, turbogears, web.py, web2py and
> > wheezy.web.
>
> Cyclomatic complexity tells you nothing that counting lines of code doesn't 
> already.
>
> http://www.scirp.org/Journal/PaperInformation.aspx?paperID=779
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
> that is made terrible by our own mad attempt to interpret it as though it had
> an underlying truth."
> -- Umberto Eco
>
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web Frameworks Excessive Complexity

2012-11-20 Thread Robert Kern

On 20/11/2012 19:46, Andriy Kornatskyy wrote:


Robert,

Thank you for the comment. I do not try relate CC with LOC. Instead pointing to 
excessive complexity, something that is beyond recommended threshold, a subject 
to refactoring in respective web frameworks. Those areas are likely to be 
potential source of bugs (e.g. due to low code coverage with unit tests) thus 
have certain degree of interest to both: end users and framework developers.


Did you read the paper? I'm not suggesting that you compare CC with LoC; I'm 
suggesting that you don't use CC as a metric at all. The research is fairly 
conclusive that CC doesn't measure what you think it measures. The source of 
bugs is not excessive complexity in a method, just excessive lines of code. LoC 
is much simpler, easier to understand, and easier to correct than CC.


--
Robert Kern

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

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


Re: Path Browser seems to be broken

2012-11-20 Thread Terry Reedy

On 11/20/2012 1:23 PM, Peter Otten wrote:

Daniel Klein wrote:


If you try to expand any of the paths in the Path Browser (by clicking the
+ sign) then it not only closes the Path Browser but it also closes all
other windows that were opened in IDLE, including the IDLE interpreter
itself.

A Google search doesn't look like this been reported. If this is truly a
bug


It is.


then can you point me in the right direction for issuing a bug report?


 is the place to go...



I'm running...

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64
bit (AMD64)] on win32



but this bug has already been reported:




I would not expect Google to index the dynamic tracker form pages, 
certainly not all of them, as it would have to know which issue numbers 
are currently valid in the template 'http:/bugs/python.org/isue#', where 
# is up to 7 digits.


The tracker has a search function. I found this issue by searching the 
tracker for 'all text: path browser', 'components: IDLE', and 'status: 
don't care' and then looking at the 8 responses.


Path browser works in 2.7 and 3.2. It was broken in 3.3.0 and has been 
fixed for 3.3.1 and 3.4.0. The issue status is 'closed', so one must 
change the search status field from the default of 'open' to find it.


--
Terry Jan Reedy

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Joshua Landau
On 20 November 2012 16:19, Dave Angel  wrote:

> On 11/20/2012 11:09 AM, John Gordon wrote:
> > In <3d71f175-164e-494c-a521-2eaa5679b...@googlegroups.com> Michael
> Herrmann  writes:
> >
> >> What, in your view, would be the most intuitive alternative name?
> > keyboard_input().
> >
>
> Well, since Python already has input() and raw_input(), it would then be
> clear that keyboard_input() would take some kind of data from the
> keyboard, not send it.


keyboard_output()
output_keys()
?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Web Frameworks Excessive Complexity

2012-11-20 Thread Andriy Kornatskyy

Robert,

I respect your point of view and it definitely make sense to me. I personally 
do not have a problem to understand CC but agree, method LoC is easier to 
understand. Regardless the path your choose in your next refactoring (based on 
method CC, LoC) it gives your better product.

Andriy


> To: python-list@python.org
> From: robert.k...@gmail.com
> Subject: Re: Web Frameworks Excessive Complexity
> Date: Tue, 20 Nov 2012 20:07:54 +
>
> On 20/11/2012 19:46, Andriy Kornatskyy wrote:
> >
> > Robert,
> >
> > Thank you for the comment. I do not try relate CC with LOC. Instead 
> > pointing to excessive complexity, something that is beyond recommended 
> > threshold, a subject to refactoring in respective web frameworks. Those 
> > areas are likely to be potential source of bugs (e.g. due to low code 
> > coverage with unit tests) thus have certain degree of interest to both: end 
> > users and framework developers.
>
> Did you read the paper? I'm not suggesting that you compare CC with LoC; I'm
> suggesting that you don't use CC as a metric at all. The research is fairly
> conclusive that CC doesn't measure what you think it measures. The source of
> bugs is not excessive complexity in a method, just excessive lines of code. 
> LoC
> is much simpler, easier to understand, and easier to correct than CC.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
> that is made terrible by our own mad attempt to interpret it as though it had
> an underlying truth."
> -- Umberto Eco
>
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proxy??

2012-11-20 Thread Joshua Landau
On 20 November 2012 14:48, Jorge Alberto Diaz Orozco <
jaoro...@estudiantes.uci.cu> wrote:

> Hi there.
> Does anyone knows how to manage headers using a simple proxy???
> I'm doing this but It gives me problems In some pages.
>

I don't know the answer, but I do know you'd get more favour if you
explained what"problems" and "In some pages" refer to.


> import SocketServer
> import SimpleHTTPServer
> import urllib2
>
> PORT = 
>
> class Proxy(SimpleHTTPServer.**SimpleHTTPRequestHandler):
> def do_GET(self):
> try:
> print self.path
> self.copyfile(urllib2.urlopen(**self.path), self.wfile)
> except:
> print 'error',self.path
>
> httpd = SocketServer.ForkingTCPServer(**('127.0.0.1', PORT), Proxy)
> print "serving at port", PORT
> httpd.serve_forever()
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with list.remove() method

2012-11-20 Thread Terry Reedy

On 11/20/2012 9:14 AM, Chris Angelico wrote:

On Wed, Nov 21, 2012 at 12:56 AM, Alvaro Combo  wrote:

Hi All,

I'm relatively new to Python... but I have found something I cannot explain... 
and  I'm sure you can help me.

I have the following function that serves for removing the duplicates from a 
list... It's a simple and (almost) trivial task.

I'm using WingIDE as editor/debugger and have Python 2.7.3.

When running this I have an error when trying to remove cpy_lst[4]... and ONLY 
THAT!!! Even in interactive mode!!!


Several points here. You've written a beautiful O(N^2) duplicates
remover... Python has a really fast way of doing it, if you don't mind
losing order:

cpy_lst = list(set(lst))

But let's assume you're doing this for the exercise. Your technique is
fine, if inefficient on large lists, but the remove() method looks for
the first occurrence of an element by its value - what you want is:

del cpy_lst[i]

which will remove one element by index.

With that change, you'll have a slightly odd duplicate remover that
keeps the *last* of any given element. That's rather unusual. Instead,
you may want to consider maintaining a set of "items I've already
seen", and keeping all elements that aren't in that set. I won't give
you all the code, but here's the basic set operations:

sighted = set()
sighted.add(some_element)
if some_element in sighted:   # condition is True if you've already
seen this element


The itertools doc, in the last section, has a recipe for this problem 
that uses the above approach.



--
Terry Jan Reedy

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


[Python 3.3/Windows] Path Browser seems to be broken

2012-11-20 Thread Daniel Klein
If you try to expand any of the paths in the Path Browser (by clicking the +
sign) then it not only closes the Path Browser but it also closes all other
windows that were opened in IDLE, including the IDLE interpreter itself.
 
I did a Google search and it doesn't look like this been reported. If this
is truly a bug then can you point me in the right direction for issuing a
bug report?
 
I'm running...
 
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit
(AMD64)] on win32
 
Dan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web Frameworks Excessive Complexity

2012-11-20 Thread Robert Kern

On 20/11/2012 20:22, Andriy Kornatskyy wrote:


Robert,

I respect your point of view and it definitely make sense to me. I personally 
do not have a problem to understand CC but agree, method LoC is easier to 
understand. Regardless the path your choose in your next refactoring (based on 
method CC, LoC) it gives your better product.


No, refactoring based on CC does not give you a better product, except by 
accident.

--
Robert Kern

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

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


Re: Problem with list.remove() method

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 1:37 AM, Alvaro Combo  wrote:
> Dear Chris,
>
> Thank you very much for you reply...
> For a newcomer to Python the Hell is in the details... :-).

You're most welcome! As Adam Savage of Mythbusters is fond of saying
(with an exaggerated accent), "It's all a learning experience".

> Regarding you other (most relevant) comments, I absolutely agree... BUT in 
> those cases... I was aware :-). But since it is in fact an exercise... and 
> having N^2 operations... is not important. Still your comments are quite 
> pertinent.

Yep. O(N^2) isn't inherently a problem, it just means that the
technique will scale poorly to large numbers of list elements. With
small lists, it'll be "fast enough" - for all intents and purposes,
the bulk of Python code executes in zero time, despite being in an oh
so slow interpreted language and using ridiculously inefficient (but
beautifully readable) code. That's the beauty of modern hardware :)

However, I do think that people should be aware when they're writing
non-scaleable code. That's not just algorithmic complexity; if you're
making a system that won't handle more than one request a second
(because, for instance, it uses seconds-since-1970 as a request
identifier), that's something worth being aware of, even if it's
unlikely ever to be a problem. Just know, so that if a problem ever
_does_ occur, you know where it is!

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


Re: [Python 3.3/Windows] Path Browser seems to be broken

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 7:58 AM, Daniel Klein  wrote:
> If you try to expand any of the paths in the Path Browser (by clicking the +
> sign) then it not only closes the Path Browser but it also closes all other
> windows that were opened in IDLE, including the IDLE interpreter itself.
>
> I did a Google search and it doesn't look like this been reported. If this
> is truly a bug then can you point me in the right direction for issuing a
> bug report?

Already reported and fixed here:

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


Re: 10 sec poll - please reply!

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 3:21 AM, Steven D'Aprano
 wrote:
> On Tue, 20 Nov 2012 07:18:42 -0800, Michael Herrmann wrote:
>
>> Thanks again for your further replies. So far, it's 4 votes for
>> 'send_keys' and 1 vote for 'type'.
>>
>> Regarding 'send_keys': To me personally it makes sense to send keys _to_
>> something. However, in our API, send_keys would not be called on an
>> object or with a parameter indicating the target. It would just be
>>
>> send_keys(ENTER)
>> send_keys("Hello World!")
>> send_keys(CTRL + 'a')
>
>
> "send_keys" is wrong, because you aren't sending keys. You're sending
> strings, except you aren't actually sending strings either, because
> "send" does not make sense without a target. You're automating the typing
> of strings, including control characters.

That depends on what the function actually does. If it sends a single
command to blat a string, including control characters, to the target,
then yes, it's sending a string. But if, as my reading of the OP tells
me, the last one is "send press-Ctrl, send press-a, send release-a,
send release-Ctrl", then it's sending keys, and the name should say
so. And it's this method that the key-sender in the Yosemite project
uses (though, for hysterical raisins, its function is called "dokey" -
which I am NOT recommending).

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


Re: Yet another Python textbook

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 1:57 AM,   wrote:
> Le mardi 20 novembre 2012 09:09:50 UTC+1, Chris Angelico a écrit :
>> On Tue, Nov 20, 2012 at 7:02 PM, Pavel Solin  wrote:
>>
>> > Perhaps you are right. Is there any statistics of how many Python
>>
>> > programmers are using 2.7 vs. 3? Most of people I know use 2.7.
>>
>>
>>
>> If you're teaching Python, the stats are probably about zero for zero.
>>
>> Start them off on Py3 and help move the world forward.
>>
>>
>>
>> ChrisA
>
> 
>
> Do not count with me.
>
> The absurd flexible string representation has practically
> borrowed the idea to propose once Python has a teaching tool.

To the OP: jmf has an unnatural hatred of Python 3.3 and PEP 393
strings. Take no notice; the rest of the world sees this as a huge
advantage. Python is now in a VERY small group of languages (I'm aware
of just one other) that have absolutely proper Unicode handling *and*
efficient string handling.

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


RE: Index Error

2012-11-20 Thread Prasad, Ramit
Can you please post in plain text and stop top-posting? Thanks. 

inshu chauhan wrote:
> 
> def distance(c, p):
>     dist = sqrt(
>     ((c[0]-p[0])**2) +
>     ((c[1]-p[1])**2) +
>     ((c[2]-p[2])**2)
>     )
>     return dist
> 
> 
> def GenerateRing(x,y, N): Generates square rings around a point in data which 
> has 300 columns(x) and 3000
> rows(y)
>     indices = []
>     for i in xrange(-N, N):
>     indices.append((x+i, y-N))
>     indices.append((x+N, y+i))
>     indices.append((x-i, y+N))
>     indices.append((x-N, y-i))
>     return indices

No, this creates a one dimensional list with 2N elements of where each element 
is a two item tuple.


> 
> 
> def ComputeClasses(data):
>     radius = .5
>     points = []
>     for cy in xrange(0, data.height):
>     for cx in xrange(0, data.width):
> 
>     if data[cy,cx] == (0.0,0.0,0.0):
>     continue
>     else :
>     centre = data[cy, cx]
>     points.append(centre)
> 
> 
>     change = True
> 
>     while change:
> 
>     for ring_number in xrange(1, 100):
>     change = False
>     new_indices = GenerateRing(cx, cy, ring_number)
>     print new_indices
>     for idx in new_indices:  
> I need help in this part as I am
> unable to device a method in which if the points are out of index,it should 
> stop and
>     if idx[0] >= 300 and idx[1] >= 3000:   go to 
> next centre and start generating
> rings from there.. and again if the index is out of range .. this should 
> repeat
>     continue
>     else :
>     point = data[idx[0], idx[1]]

You can use a few different methods. This is just one example.

for idx, temp_point in enumerate(new_indices):
try:
temp_point[0]
temp_point[1]
except Exception: #Should be IndexError I think.
print 'idx: {0}\ntemp_point:{1}'.format(idx, temp_point) 
# Possibly add a break or exit so you do not have to
# keep going once you hit a failure.
point = data[temp_point[0], temp_point[1]] 


What is `data`? I have not seen any built-in structure that takes
a tuple in this manner...unless it is a dictionary. Or from numpy.
Given my lack of knowledge of what `data`, it could be the
problem is there. That is one reason I accessed `temp_point[0]` and
`temp_point[1]` separately.


>     if point == (0.0, 0.0, 0.0 ):
>     print point
>     continue
>     else:
>     dist = distance(centre, point)
>     print dist
>     if  dist < radius :   and rings 
> should be added only when this
> condition is satisfied
>     print point
>     points.append(point)
>     change = True
>     print change
> 
> 
>     break
> 
> 
>     print points
> 
> 
> ERROR now :
> 
> data loaded
> [(296, 403), (298, 403), (298, 405), (296, 405), (297, 403), (298, 404), 
> (297, 405), (296, 404)] ... I am
> printing Indices to know what index it dies out..
> 
> Traceback (most recent call last):
>   File "Z:/modules/Classify.py", line 73, in 
>     ComputeClasses(data)
>   File "Z:/modules/Classify.py", line 49, in ComputeClasses
>     point = data[idx[0], idx[1]]
> error: index is out of range
> 

Is that the actual error? If so, then the problem is not `idx` or 
`temp_point` but instead `data`. If it is not the exact error, please 
copy and paste the error message *exactly* as given.

>>> [1][2]
IndexError: list index out of range
>>> (1,2)[3]
IndexError: tuple index out of range


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Problem with list.remove() method

2012-11-20 Thread Prasad, Ramit
Alvaro Combo wrote:
> 
> Hi All,
> 
> I'm relatively new to Python... but I have found something I cannot 
> explain... and  I'm sure you can help me.
> 
> I have the following function that serves for removing the duplicates from a 
> list... It's a simple and (almost)
> trivial task.
> 
> I'm using WingIDE as editor/debugger and have Python 2.7.3.
> 
> When running this I have an error when trying to remove cpy_lst[4]... and 
> ONLY THAT!!! Even in interactive
> mode!!!
> 
> Any suggestion is MOST welcome.
> 
> Best Regards
> 
> ACombo
> 
> ...And the code:
> 
> def remove_dup_5_10():
> """
> Remove the duplicates of a given list. The original list MUST be kept.
> """
> 
> # Set the original list
> lst = ['a', 1, 10.0, 2, 'd', 'b', 'b', 'b', 1, 2, 'b' ]
> 
> # NEED to create a copy... See dicussion on Problem 5.6 and issue #2
> cpy_lst = list(lst)
> 
> # Perform an infinite loop... explained later
> i=0 # initialize the index
> while i != len(cpy_lst):
> if cpy_lst.count(cpy_lst[i]) != 1:
> cpy_lst.remove(i)
> else:
> i += 1
> 
> print "The original List: ", lst
> print "List with NO duplicates: ", cpy_lst
> 
> return True
> --

Remove looks for the *value* not the *index* of the value.

>>> help([].remove)
Help on built-in function remove:

remove(...)
L.remove(value) -- remove first occurrence of value.
Raises ValueError if the value is not present.

Change ` cpy_lst.remove(i)` to `cpy_lst.remove(cpy_lst[i])`.

~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread brintoul
Hello:

I have a multihomed machine that I would like to run the Python imaplib's IMAP4 
client on.  I would like to be able to specify which interface the underlying 
socket will bind to as its source address.  How could I best do this?

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


Re: 10 sec poll - please reply!

2012-11-20 Thread xDog Walker
On Tuesday 2012 November 20 08:29, mherrmann...@gmail.com wrote:
> To everyone else who has been so kind to reply thus far: What do you think
> of generate_keystrokes? It's a bit long but describes exactly what the
> function would be doing.

If not already offered and rejected,
how about enter() ?

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

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


Re: Yet another Python textbook

2012-11-20 Thread Terry Reedy

On 11/20/2012 3:02 AM, Pavel Solin wrote:


previous page that Python 3 was released in 2008.  Is there any work
underway get Python 3 into NCLab?


There is an ongoing discussion but we are not sure.
Are there any reasons except for the print () command
and division of integers?


(In addition to Ian's answer, which points to an already long list of 
new features...)


There are two separate questions.
First, which versions of Python should NCLab support? I would say both 
2.7 and 3.x+. Since Py3 support does not exist now, starting with 3.3+ 
might work best.


Second, if NCLab supported both, which to teach in the book? I would say 
3.3+. Python 3 has many improvements from a teaching standpoint.


For instance, old-style classes are gone, so class statements produce 
modern-style classes by default. You can just say that the headers


class C:
class C(object):

have the same effect and never mention that there was once a separate 
user-class system.


Py 3 used unicode for text, and 3.3 now has a correct and portable 
unicode implementation. While non-ascii and even non-latin1 characters 
are not needed for interfacing with ascii-only instruments, scientific 
text uses lots of them.


...

Perhaps you are right. Is there any statistics of how many Python
programmers are using 2.7 vs. 3? Most of people I know use 2.7.


Experienced Python programmers are not the target of your book. Many 
school/university classes have moved to Py3, and more will in the future.


Many people who want to move to Py3 cannot because they *have to use* a 
Py2-only library.


--
Terry Jan Reedy

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


RE: 10 sec poll - please reply!

2012-11-20 Thread Prasad, Ramit
Steven D'Aprano wrote:
> 
> On Tue, 20 Nov 2012 07:18:42 -0800, Michael Herrmann wrote:
> 
> > Thanks again for your further replies. So far, it's 4 votes for
> > 'send_keys' and 1 vote for 'type'.
> >
> > Regarding 'send_keys': To me personally it makes sense to send keys _to_
> > something. However, in our API, send_keys would not be called on an
> > object or with a parameter indicating the target. It would just be
> >
> > send_keys(ENTER)
> > send_keys("Hello World!")
> > send_keys(CTRL + 'a')
> 
> 
> "send_keys" is wrong, because you aren't sending keys. You're sending
> strings, except you aren't actually sending strings either, because
> "send" does not make sense without a target. You're automating the typing
> of strings, including control characters.

simulate_keypress
simulate_key(s)_down
send_kb_press
fake_typing
send_char(s)

> 
> I believe that your initial instinct for the name of this function was
> correct. It automates typing, so you should call it "type" or (for those
> paranoid about shadowing the built-in, "type_str".
> 

I can too easily see somebody doing from module import *  
OR from module import type.


~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 8:14 AM,   wrote:
> Hello:
>
> I have a multihomed machine that I would like to run the Python imaplib's 
> IMAP4 client on.  I would like to be able to specify which interface the 
> underlying socket will bind to as its source address.  How could I best do 
> this?

You're referring to this function?

http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4

The docs suggest that you can simply pass it a parameter to specify
the address to bind to. (Note that you bind to addresses, not
interfaces. Figuring out which interface has which address is a
separate issue.)

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


Encoding conundrum

2012-11-20 Thread Daniel Klein
With the assistance of this group I am understanding unicode encoding
issues much better; especially when handling special characters that are
outside of the ASCII range. I've got my application working perfectly now
:-)

However, I am still confused as to why I can only use one specific encoding.

I've done some research and it appears that I should be able to use any of
the following codecs with codepoints '\xfc' (chr(252)) '\xfd' (chr(253))
and '\xfe' (chr(254)) :

ISO-8859-1   [ note that I'm using this codec on my Linux box ]
cp1252
cp437
latin1
utf-8

If I'm not mistaken, all of these codecs can handle the complete 8bit
character set.

However, on Windows 7, I am only able to use 'cp437' to display (print)
data with those characters in Python. If I use any other encoding, Windows
laughs at me with this error message:

  File "C:\Python33\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\xfd' in
position 3: character maps to 

Furthermore I get this from IDLE:

>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'cp1252')

I also get 'cp1252' when running the same script from a Windows command
prompt.

So there is a contradiction between the error message and the default
encoding.

Why am I restricted from using just that one codec? Is this a Windows or
Python restriction? Please enlighten me.

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


Re: Yet another Python textbook

2012-11-20 Thread Mark Lawrence

On 20/11/2012 21:00, Chris Angelico wrote:


To the OP: jmf has an unnatural hatred of Python 3.3 and PEP 393
strings. Take no notice; the rest of the world sees this as a huge
advantage. Python is now in a VERY small group of languages (I'm aware
of just one other) that have absolutely proper Unicode handling *and*
efficient string handling.

ChrisA



Rather more polite than the response I've had sitting in my drafts 
folder for several hours.  I'm so pleased I didn't send it, I can now 
happily delete it and move on :)


--
Cheers.

Mark Lawrence.

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


RE: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Prasad, Ramit
brint...@controlledthinking.com wrote:
> 
> Hello:
> 
> I have a multihomed machine that I would like to run the Python imaplib's 
> IMAP4 client on.  I would like to be
> able to specify which interface the underlying socket will bind to as its 
> source address.  How could I best do
> this?

One assumes by programming.

> 
> Thanks for any help...

You are quite welcome. :)

On a less flippant note, maybe some links would help you 
get started.

http://www.doughellmann.com/PyMOTW/imaplib/
http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/ 
http://docs.python.org/2/library/imaplib.html


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread brintoul
On Tuesday, November 20, 2012 1:48:46 PM UTC-8, Chris Angelico wrote:
> On Wed, Nov 21, 2012 at 8:14 AM,   wrote:
> 
> > Hello:
> 
> >
> 
> > I have a multihomed machine that I would like to run the Python imaplib's 
> > IMAP4 client on.  I would like to be able to specify which interface the 
> > underlying socket will bind to as its source address.  How could I best do 
> > this?
> 
> 
> 
> You're referring to this function?
> 
> 
> 
> http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4
> 
> 
> 
> The docs suggest that you can simply pass it a parameter to specify
> 
> the address to bind to. (Note that you bind to addresses, not
> 
> interfaces. Figuring out which interface has which address is a
> 
> separate issue.)
> 
> 
> 
> ChrisA

Unless I'm reading that wrong, that's specifying the address/host to connect to 
(the destination address) not the source address...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use the python to do the unit test

2012-11-20 Thread Mark Lawrence

On 20/11/2012 17:40, yujian4newsgr...@gmail.com wrote:

I write a mfc application, then I want to use the python to test this 
application. just as user  click that button.  Please tell me how to write the 
python application?



Easy, open your favourite editor and start typing, what's the problem?

--
Cheers.

Mark Lawrence.

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


Re: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread brintoul
On Tuesday, November 20, 2012 1:59:34 PM UTC-8, Prasad, Ramit wrote:
> brintoul at controlledthinking.com wrote:
> 
> > 
> 
> > Hello:
> 
> > 
> 
> > I have a multihomed machine that I would like to run the Python imaplib's 
> > IMAP4 client on.  I would like to be
> 
> > able to specify which interface the underlying socket will bind to as its 
> > source address.  How could I best do
> 
> > this?
> 
> 
> 
> One assumes by programming.
> 
> 
> 
> > 
> 
> > Thanks for any help...
> 
> 
> 
> You are quite welcome. :)
> 
> 
> 
> On a less flippant note, maybe some links would help you 
> 
> get started.
> 
> 
> 
> http://www.doughellmann.com/PyMOTW/imaplib/
> 
> http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/ 
> 
> http://docs.python.org/2/library/imaplib.html
> 
> 
> 
> 
> 
> ~Ramit
> 
> 
> 
> 
> 
> This email is confidential and subject to important disclaimers and
> 
> conditions including on offers for the purchase or sale of
> 
> securities, accuracy and completeness of information, viruses,
> 
> confidentiality, legal privilege, and legal entity disclaimers,
> 
> available at http://www.jpmorgan.com/pages/disclosures/email.

While I appreciate your attempt at humor, this is not information which helps 
me.  Perhaps you are not familiar with the basics of socket programming. This 
is all fine and dandy, and it is good to "know what you don't know".  If you're 
interested, look at the third argument to "create_connection": 
http://docs.python.org/2/library/socket.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Managing multiple packages

2012-11-20 Thread Evan Driscoll
I have perhaps a bit of a silly question, but I'm interested in what
people do for workflow when actively developing multiple Python modules
at once (for a single project).

Suppose I have packages A-C. In addition to being modules in the Python
sense, they are logically distinct, probably sit in different
repositories, etc., so there's a directory layout like

  my_project/
  +-- moduleA/
  |   +-- setup.py
  |   +-- src/
  |   |   +-- A/
  |   |   +-- __init__.py
  |   +-- doc/
  |   +-- how_to_be_awesome.md
  +-- moduleB/
  |   +-- setup.py
  |   +-- src/
  |   +-- B/
  |   +-- __init__.py
  +-- moduleC/
  +-- setup.py
  +-- src/
  +-- C/
  +-- __init__.py

Finally, suppose that you're changing between editing all three modules.


How do you deal with this? Do you set
PYTHONPATH=my_project/moduleA/src:my_project/moduleB/src:my_project/moduleC/src,
adding a new entry to PYTHONPATH for each module you need to use?
Install all of the modules to some central location (e.g.
my_project/install) and just point PYTHONPATH to there? Put symlinks in
some central location and point them at the module directories? Mess
with sys.path at the beginning of any scripts you want to run? Some
other trick I don't know of?

I've sort of tended to do the my_project/install thing, but it's pretty
easy to forget to re-install a module after changing something, and
possible to accidentally edit the copy of the file in the install
directory (which will just be overwritten).

Evan






signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another Python textbook

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 8:55 AM, Mark Lawrence  wrote:
> On 20/11/2012 21:00, Chris Angelico wrote:
>>
>>
>> To the OP: jmf has an unnatural hatred of Python 3.3 and PEP 393
>> strings. Take no notice; the rest of the world sees this as a huge
>> advantage. Python is now in a VERY small group of languages (I'm aware
>> of just one other) that have absolutely proper Unicode handling *and*
>> efficient string handling.
>>
>> ChrisA
>>
>
> Rather more polite than the response I've had sitting in my drafts folder
> for several hours.  I'm so pleased I didn't send it, I can now happily
> delete it and move on :)

Polite is good :)

Incidentally, if anyone else knows of a language that fits the
description above, I'd be most curious. Maybe we're going to see a
revolution in language design - with everyone adopting this sort of
string handling - or in language usage - with everyone adopting Python
or Pike. Hmm. We're having major security issues with Joomla, I wonder
how hard it'd be to convince our webmaster to switch to a Python-based
web framework...

Dreaming-ly yours,

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


Re: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Chris Angelico
On Wed, Nov 21, 2012 at 9:00 AM,   wrote:
> On Tuesday, November 20, 2012 1:48:46 PM UTC-8, Chris Angelico wrote:
>> On Wed, Nov 21, 2012 at 8:14 AM,   wrote:
>>
>> > I have a multihomed machine that I would like to run the Python imaplib's 
>> > IMAP4 client on.  I would like to be able to specify which interface the 
>> > underlying socket will bind to as its source address.  How could I best do 
>> > this?
>>
>> You're referring to this function?
>>
>> http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4
>>
>> The docs suggest that you can simply pass it a parameter to specify
>> the address to bind to. (Note that you bind to addresses, not
>> interfaces. Figuring out which interface has which address is a
>> separate issue.)
>>
>
> Unless I'm reading that wrong, that's specifying the address/host to connect 
> to (the destination address) not the source address...

Ah, whoops! My bad. For some reason I was thinking that was creating a
server socket. Sorry!

Poking around in the source (imaplib.py) shows that it creates a socket here:

class IMAP4:
def _create_socket(self):
return socket.create_connection((self.host, self.port))

Adding a third parameter to create_connection would do what you want.
(Note that this is currently getting one parameter, not two.)

http://docs.python.org/3.3/library/socket.html#socket.create_connection

My recommendation: Subclass IMAP4 and override this one function.

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


RE: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Prasad, Ramit
brint...@controlledthinking.com wrote:
> > > I have a multihomed machine that I would like to run the Python imaplib's 
> > > IMAP4 client on.  I would like to be
> > > able to specify which interface the underlying socket will bind to as its 
> > > source address.  How could I best do
> > > this?
[snip]

> While I appreciate your attempt at humor, this is not information which helps 
> me.  Perhaps you are not familiar
> with the basics of socket programming. This is all fine and dandy, and it is 
> good to "know what you don't know".
> If you're interested, look at the third argument to "create_connection":
> http://docs.python.org/2/library/socket.html

Apologies, I misread your question. 

According to the imaplib docs, you can subclass IMAP4 and override 
`IMAP4.open` to create the socket and bind it to the desired interface.
You could also connect using IMAP4 and then close/reopen the socket
inside the IMAP4 connection object. 


I hope that is more help,
Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding conundrum

2012-11-20 Thread Dave Angel
On 11/20/2012 04:49 PM, Daniel Klein wrote:
> With the assistance of this group I am understanding unicode encoding
> issues much better; especially when handling special characters that are
> outside of the ASCII range. I've got my application working perfectly now
> :-)
>
> However, I am still confused as to why I can only use one specific encoding.

Who says you can only use one?  You need to use the right encoding for
the device or file you're talking with, and if different devices want
different encodings, then you must use multiple ones.  Only one can be
the default, however, and that's where some problems come about.

>
> I've done some research and it appears that I should be able to use any of
> the following codecs with codepoints '\xfc' (chr(252)) '\xfd' (chr(253))
> and '\xfe' (chr(254)) :
>
> ISO-8859-1   [ note that I'm using this codec on my Linux box ]
> cp1252
> cp437
> latin1
> utf-8
>
> If I'm not mistaken, all of these codecs can handle the complete 8bit
> character set.

What 8 bit character set?  This is a nonsense statement.  If you mean
all of them can convert an 8 bit byte to SOME unicode character, then
fine.  But they won't convert each such byte to the SAME unicode
character, or they'd be the same encoding.


> However, on Windows 7, I am only able to use 'cp437' to display (print)
> data with those characters in Python. If I use any other encoding, Windows
> laughs at me with this error message:
>
>   File "C:\Python33\lib\encodings\cp437.py", line 19, in encode
> return codecs.charmap_encode(input,self.errors,encoding_map)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\xfd' in
> position 3: character maps to 
>
> Furthermore I get this from IDLE:
>
 import locale
 locale.getdefaultlocale()
> ('en_US', 'cp1252')
>
> I also get 'cp1252' when running the same script from a Windows command
> prompt.
>
> So there is a contradiction between the error message and the default
> encoding.
>
> Why am I restricted from using just that one codec? Is this a Windows or
> Python restriction? Please enlighten me.
>
>
>
I don't know much about Windows quirks anymore.  I haven't had to use it
much for years.

-- 

DaveA

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


Re: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread brintoul
On Tuesday, November 20, 2012 2:41:58 PM UTC-8, Prasad, Ramit wrote:
> brintoul at controlledthinking.com wrote:
> 
> Apologies, I misread your question. 
> 
> 
> 
> According to the imaplib docs, you can subclass IMAP4 and override 
> 
> `IMAP4.open` to create the socket and bind it to the desired interface.
> 
> You could also connect using IMAP4 and then close/reopen the socket
> 
> inside the IMAP4 connection object. 
> 
> I hope that is more help,
> 
> Ramit
> 

Thanks, yes, that helps!  Just out of curiosity, can you give me a quick link 
to the docs you are looking at?  I'm not seeing anything which gets very 
specific in the docs for Python 2.7 at docs.python.org ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding conundrum

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 2:49 PM, Daniel Klein  wrote:
> With the assistance of this group I am understanding unicode encoding issues
> much better; especially when handling special characters that are outside of
> the ASCII range. I've got my application working perfectly now :-)
>
> However, I am still confused as to why I can only use one specific encoding.
>
> I've done some research and it appears that I should be able to use any of
> the following codecs with codepoints '\xfc' (chr(252)) '\xfd' (chr(253)) and
> '\xfe' (chr(254)) :

These refer to the characters with *Unicode* codepoints 252, 253, and 254:

>>> unicodedata.name('\xfc')
'LATIN SMALL LETTER U WITH DIAERESIS'
>>> unicodedata.name('\xfd')
'LATIN SMALL LETTER Y WITH ACUTE'
>>> unicodedata.name('\xfe')
'LATIN SMALL LETTER THORN'

> ISO-8859-1   [ note that I'm using this codec on my Linux box ]

For ISO 8859-1, these characters happen to exist and even correspond
to the same ordinals: 252, 253, and 254 (this is by design); so there
is no problem encoding them, and the resulting bytes even happen to
match the codepoints of the characters.

> cp1252

cp1252 is designed after ISO 8859-1 and also has those same three characters:

>>> for char in b'\xfc\xfd\xfe'.decode('cp1252'):
... print(unicodedata.name(char))
...
LATIN SMALL LETTER U WITH DIAERESIS
LATIN SMALL LETTER Y WITH ACUTE
LATIN SMALL LETTER THORN

> latin1

Latin-1 is just another name for ISO 8859-1.

> utf-8

UTF-8 is a *multi-byte* encoding.  It can encode any Unicode
characters, so you can represent those three characters in UTF-8, but
with a different (and longer) byte sequence:

>>> print('\xfc\xfd\xfd'.encode('utf8'))
b'\xc3\xbc\xc3\xbd\xc3\xbd'

> cp437

cp437 is another 8-bit encoding, but it maps entirely different
characters to those three bytes:

>>> for char in b'\xfc\xfd\xfe'.decode('cp437'):
... print(unicodedata.name(char))
...
SUPERSCRIPT LATIN SMALL LETTER N
SUPERSCRIPT TWO
BLACK SQUARE

As it happens, the character at codepoint 252 (that's LATIN SMALL
LETTER U WITH DIAERESIS) does exist in cp437.  It maps to the byte
0x81:

>>> '\xfc'.encode('cp437')
b'\x81'

The other two Unicode characters, at codepoints 253 and 254, do not
exist at all in cp437 and cannot be encoded.

> If I'm not mistaken, all of these codecs can handle the complete 8bit
> character set.

There is no "complete 8bit character set".  cp1252, Latin1, and cp437
are all 8-bit character sets, but they're *different* 8-bit character
sets with only partial overlap.

> However, on Windows 7, I am only able to use 'cp437' to display (print) data
> with those characters in Python. If I use any other encoding, Windows laughs
> at me with this error message:
>
>   File "C:\Python33\lib\encodings\cp437.py", line 19, in encode
> return codecs.charmap_encode(input,self.errors,encoding_map)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\xfd' in
> position 3: character maps to 

It would be helpful to see the code you're running that causes this error.

> Furthermore I get this from IDLE:
>
 import locale
 locale.getdefaultlocale()
> ('en_US', 'cp1252')
>
> I also get 'cp1252' when running the same script from a Windows command
> prompt.
>
> So there is a contradiction between the error message and the default
> encoding.

If you're printing to stdout, it's going to use the encoding
associated with stdout, which does not necessarily have anything to do
with the default locale.  Use this to determine what character set you
need to be working in if you want your data to be printable:

>>> import sys
>>> sys.stdout.encoding
'cp437'

> Why am I restricted from using just that one codec? Is this a Windows or
> Python restriction? Please enlighten me.

In Linux, your terminal encoding is probably either UTF-8 or Latin-1,
and either way it has no problems encoding that data for output.  In a
Windows cmd terminal, the default terminal encoding is cp437, which
can't support two of the three characters you mentioned above.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Choosing Source Address to Bind Socket to in IMAP Client

2012-11-20 Thread Prasad, Ramit
brint...@controlledthinking.com wrote:
> 
> On Tuesday, November 20, 2012 2:41:58 PM UTC-8, Prasad, Ramit wrote:
> > brintoul at controlledthinking.com wrote:
> >
> > Apologies, I misread your question.
> >
> > According to the imaplib docs, you can subclass IMAP4 and override
> > `IMAP4.open` to create the socket and bind it to the desired interface.
> > You could also connect using IMAP4 and then close/reopen the socket
> > inside the IMAP4 connection object.
> >
> > I hope that is more help,
> > Ramit
> >
> 
> Thanks, yes, that helps!  Just out of curiosity, can you give me a quick link 
> to the docs you are looking at?
> I'm not seeing anything which gets very specific in the docs for Python 2.7 
> at docs.python.org ...


It is not very specific or helpful but here is the text in question.

'''
IMAP4.open(host, port)
Opens socket to port at host. This method is implicitly called by the IMAP4 
constructor. The connection objects established by this method will be used in 
the read, readline, send, and shutdown methods. You may override this method.
'''
http://docs.python.org/2.7/library/imaplib.html#imaplib.IMAP4.open


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >