Re: Atoms, Identifiers, and Primaries

2013-04-18 Thread rusi
On Apr 18, 4:40 am, Mark Janssen  wrote:
> On Tue, Apr 16, 2013 at 8:55 PM, rusi  wrote:
> > Circular just means recursive and recursion is the bedrock for
> > language-design.
>
> Rercursion the "bedrock" of language-design.  I don't think so.

Imperative programmers may be forgiven for not understanding how
pervasive the idea of recursion is in CS.
For example most C programmers dont understand that the standard
definition of linked list is not just recursive, its mutually
recursive:
pointer  struct
struct  pointer

I have a collection of some of the variety of the uses of recursion in
CS here:
http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html

Or see the first line of http://en.wikipedia.org/wiki/Recursion_theory
recursion theory is by definition the same subject as computation
theory
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding NaN in JSON

2013-04-18 Thread Roland Koebler
On Thu, Apr 18, 2013 at 11:46:37AM +1000, Chris Angelico wrote:
> Wait... you can do that? It's internal to iterencode, at least in
> Python 3.3 and 2.7 that I'm looking at here.
In Python 2.6 it wasn't internal to iterencode; in Python 2.7 and 3.x
you probably would have to monkey-patch iterencode. (In addition, patching
floatstr alone wouldn't be enough in 3.x and probably 2.7, since you also
have to make sure that the C-extension is not used here.)

BUT: Keep in mind that monkey-patches are problematic, and should be
avoided (or used very carefully) in production code. So, better
replace the complete encoder.py or use your own patched version
of the complete json-module.

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


Re: Novice Issue

2013-04-18 Thread Wolfgang Maier
Bradley Wright  gmail.com> writes:

> 
> Good Day all, currently writing a script that ask the user for three things;
> 1.Name
> 2.Number
> 3.Description
> I've gotten it to do this hurah!
> 
> print "Type \"q\" or \"quit\" to quit"
> while raw_input != "quit" or "q":
> 
> print ""
> name = str(raw_input("Name: "))
> number = str(raw_input("Number: "))
> description = str(raw_input("Description: "))
> 
> but here a few things, can anyone help me on figuring out how to at the
users whim print out all of the names,
> numbers and descriptions. this is sort of an information logger.
> 
> additionally, minor issue with getting script to stop when q or quit is typed

your minor issue here is your "or" test, which is not doing what you think
it does.
You're testing here for either of the following to conditions:
1) raw_input != "quit"
2) "q" (Python can't know that you want raw_input != "q" here!!)
Now any non-empty string in Python tests True, so your while loop never stops.
There are two solutions for that:
the obvious: while not (raw_input == "quit" or raw_input == "q")
or the pythonic way: while raw_input not in ("quit", "q")
The second form definitely is preferable over the first when you have to
test for more than two conditions.
For your other questions see Chris' answers.

Best,
Wolfgang



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


Re: Novice Issue

2013-04-18 Thread Chris Angelico
On Thu, Apr 18, 2013 at 6:58 PM, Wolfgang Maier
 wrote:
> There are two solutions for that:
> the obvious: while not (raw_input == "quit" or raw_input == "q")

That has another problem: Once that's changed to raw_input() so it
actually requests input, it will do so twice, compare the first line
against "quit" and the second against "q", and proceed on that basis.
The membership test raw_input() in ("quit","q") is going to be far
better.

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


Good python testing book

2013-04-18 Thread BhanuKumarRamappa
Hi All,

Greetings..
can anyone please suggest me good python automation testing book . to
develop automation tests.

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


Re: Good python testing book

2013-04-18 Thread xiaohanyu1988
On Thursday, April 18, 2013 4:46:16 PM UTC+8, BhanuKumarRamappa wrote:
> Hi All,
> 
> 
> Greetings..
> can anyone please suggest me good python automation testing book . to 
> develop automation tests.
> 
> 
> Thanks,
> 
> -Bhanu

Maybe you can try "Python Testing Cookbook" for a basic testing in Python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Novice Issue

2013-04-18 Thread Mark Lawrence

On 18/04/2013 05:06, Bradley Wright wrote:

Good Day all, currently writing a script that ask the user for three things;
1.Name
2.Number
3.Description
I've gotten it to do this hurah!

print "Type \"q\" or \"quit\" to quit"


You've had a couple of answers already so I'll just point out that the 
above line could be.


print 'Type "q" or "quit" to quit'

Looks prettier if nothing else :)


while raw_input != "quit" or "q":

 print ""
 name = str(raw_input("Name: "))
 number = str(raw_input("Number: "))
 description = str(raw_input("Description: "))

but here a few things, can anyone help me on figuring out how to at the users 
whim print out all of the names, numbers and descriptions. this is sort of an 
information logger.

additionally, minor issue with getting script to stop when q or quit is typed

any help would be greatly appreciated



--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Parsing soap result

2013-04-18 Thread Ombongi Moraa Fe
Hi Burak, Team,

Your solution worked perfectly thanks.

Could you share the logic of this solution?

Saludos

Ombongi Moraa Faith


On 18 April 2013 00:41, Burak Arslan  wrote:

>  On 04/17/13 16:50, Ombongi Moraa Fe wrote:
>
>  My
>
> client.service.gere(ri)
>
> method call logs the below soap response in my log file.
>
> http://schemas.xmlsoap.org/soap/envelope/"; xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance";> xmlns:ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local
> ">254727DeliveredToNetwork
>
>
>  If I assign the client.service.gere(ri) to a variable, i get the output
> on my screen:
>
> result=client.service.gere(ri)
>
> output:
> [(DeliveryInformation){
>address = "254727"
>deliveryStatus = "DeliveredToNetwork"
>  }]
>
>  string functions replace() and strip don't work.
>
> how do I use xml.etree.ElementTree to print the parameters address and
> deliveryStatus? Or is there a better python method?
>
>
> hi,
>
> try:
>
> result[0].deliveryStatus
>
> or
>
> result[0].DeliveryInformation.deliveryStatus
>
>
> and let us know.
>
> best,
> burak
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing soap result

2013-04-18 Thread Burak Arslan


Hi,

On 04/18/13 13:46, Ombongi Moraa Fe wrote:

Hi Burak, Team,



Apparently I was too deep in answering support questions for my company 
:) This is python-list, so It's just me here :)



Your solution worked perfectly thanks.

Could you share the logic of this solution?



You're using suds. Let's have a look at what you see:

[(DeliveryInformation){
   address = "254727"
   deliveryStatus = "DeliveredToNetwork"
 }]

You have it in square brackets, so it's an array. You apparently want 
the first element, so it's result[0]. It's of type DeliveryInformation 
with two fields, they are what you see there. Depending on the which 
soap mode (rpc/document) your server uses, you should either use 
result[0].deliveryStatus or result[0].DeliveryInformation.deliveryStatus.


I guess I got too much experience doing SOAP with python :) (I maintain 
spyne, see: http://spyne.io)


I'm glad it worked.

Best,
Burak

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


Re: Novice Issue

2013-04-18 Thread Bradley Wright
On Thursday, April 18, 2013 12:06:59 AM UTC-4, Bradley Wright wrote:
> Good Day all, currently writing a script that ask the user for three things;
> 
> 1.Name
> 
> 2.Number
> 
> 3.Description
> 
> I've gotten it to do this hurah!
> 
> 
> 
> print "Type \"q\" or \"quit\" to quit"
> 
> while raw_input != "quit" or "q":
> 
> 
> 
> print ""
> 
> name = str(raw_input("Name: "))
> 
> number = str(raw_input("Number: "))
> 
> description = str(raw_input("Description: "))
> 
> 
> 
> but here a few things, can anyone help me on figuring out how to at the users 
> whim print out all of the names, numbers and descriptions. this is sort of an 
> information logger.
> 
> 
> 
> additionally, minor issue with getting script to stop when q or quit is typed
> 
> 
> 
> any help would be greatly appreciated

Joining this group has been the smartest decision since birth 

Firstly, thanks Chris - str() [REMOVED]
and yes i would like to retain them until the end of the loop simply for 
printing or viewing purposes. [I'll DO MORE RESEARCH ON LISTS] 

Secondly, thanks Wolfgang
while raw_input not in ("quit", "q") - genius, i get your point clearly

Thirdly, thanks mark
went through the link you provided, insightful

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


Re: Novice Issue

2013-04-18 Thread Dave Angel

On 04/18/2013 08:18 AM, Bradley Wright wrote:


   





Secondly, thanks Wolfgang
while raw_input not in ("quit", "q") - genius, i get your point clearly


But you have to combine his point with Chris's, don't forget the parens 
on the call to raw_input.  And if it were I, I'd also put a prompt 
string in the call.


   while raw_input("q to quit") not in ("quit", "q"):





If you've got a list, and each time through you want to add some item(s) 
to a list, you can use the following idiom:


result = [] #empty list
for   whatever in something:
value = another
result.append(value)

Then when you finish the list, you can examine the whole list.

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


Re: Novice Issue

2013-04-18 Thread Bradley Wright
On Thursday, April 18, 2013 12:06:59 AM UTC-4, Bradley Wright wrote:
> Good Day all, currently writing a script that ask the user for three things;
> 
> 1.Name
> 
> 2.Number
> 
> 3.Description
> 
> I've gotten it to do this hurah!
> 
> 
> 
> print "Type \"q\" or \"quit\" to quit"
> 
> while raw_input != "quit" or "q":
> 
> 
> 
> print ""
> 
> name = str(raw_input("Name: "))
> 
> number = str(raw_input("Number: "))
> 
> description = str(raw_input("Description: "))
> 
> 
> 
> but here a few things, can anyone help me on figuring out how to at the users 
> whim print out all of the names, numbers and descriptions. this is sort of an 
> information logger.
> 
> 
> 
> additionally, minor issue with getting script to stop when q or quit is typed
> 
> 
> 
> any help would be greatly appreciated

Thanks Dave quite helpful as well,
now i have a clear road to go on, with regards the lists portion of my script
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic forms generation

2013-04-18 Thread Wayne Werner

On Tue, 16 Apr 2013, andrea crotti wrote:


This is not really scalable, and we want to make the whole thing more
generic.

So ideally there could be a DSL (YAML or something else) that we could
define to then generate the forms, but the problem is that I'm quite
sure that this DSL would soon become too complex and inadeguate, so I'm
not sure if it's worth since noone should write forms by hands anyway.

Between the things that we should be able to do there are:
- dependent fields
- validation (both server and client side, better if client-side
  auto-generated)
- following DRY as much as possible

Any suggestions of possible designs or things I can look at?


I would highly recommend a look at Flask, and Flask-WTF in particular. 
It's fairly easy to write forms, and with only a bit of setup you can end 
out with some fairly generic systems.


I don't think that by default it does any client-side validation 
generation, but as the HTML for the forms are completely generated, 
extending the form and adding validation logic to the output wouldn't be 
too difficult.


Example:

# form.py

from flask.ext.wtf import Form, TextField, Required

class MyBasicForm(Form):
some_text = TextField("Put some text here:", validators=[Required()])


# View/HTML

{% extends 'base.html' %}
{{ form.some_text.label() }}{{ form.some_text(size=40) }}


# Server code

@app.route("/basic_form", methods=['GET', 'POST'])
def basic():
form = MyBasicForm()
if form.validate_on_submit():
do_the_needful(form.some_text.data)
return redirect(url_for('main'))

return render_template('basic_form.html', form=form)



Obviously a really basic example. Check out Flask here:
http://flask.pocoo.org/

And Flask WTF here:
http://pythonhosted.org/Flask-WTF/


HTH,
Wayne-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a couple of things I don't understand wrt lists

2013-04-18 Thread aaB
Hello,

I am still in the process of writing preliminary code for my CA project.
I am now running into a behavior that I can't explain.

Here is a script which, at least on my system, shows the issue (python2.7 on a
linux system).
The final project will be wrapping these functions (and others) into a class
which will be in a module which can be imported into a script.

#!/usr/bin/python2

import sys
import random

def get_rule(rulenum):
  bitpattern = bin(rulenum)[2:]
  return [0]*(8-len(bitpattern)) + [int(bit) for bit in bitpattern]

def populate(n):
  random.seed()
  return [random.randint(0,1) for i in range(n)]

def get_index(thisgen, i):
  n = len(thisgen)-1
  cell = thisgen[i]
  if i is 0:
print "i==0"
prev, next = thisgen[n], thisgen[i+1]
  elif i is n:
print "i==%d" % n
prev, next = thisgen[i-1], thisgen[0]
  else:
prev, next = thisgen[i-1], thisgen[i+1]
  return prev*4 + cell*2 + next

def get_nextgen(thisgen, rule):
  return [rule[get_index(thisgen, i)] for i in range(len(thisgen))]


if len(sys.argv) == 2:
  n = int(sys.argv[1])
else:
  n = 257

rule = get_rule(145)
thisgen = populate(n)
nextgen = get_nextgen(thisgen, rule)
print "done for n == 257"

n = 258
thisgen = populate(n)
nextgen = get_nextgen(thisgen, rule)


My issue is that when n == 257, the script runs as expected, but if n >= 258, I
get an "IndexError: list index out of range".
The script is also attached to the email in case someone would like to try it on
their machine.
The print statements in the get_index() function's branching show me that, when 
I
get the "out of range" error, the program doesn't enter the "elif i is n"
condition, although it does for lower values of n.
I'm sorry, but I still haven't found a way to copy/paste from the terminal to
vim.
This behaviour occurred previously and had stopped when I used an other version
of the get_index() function. At that time, get_index() wasn't a function and was
just conditional branching inside get_nextgen, I wanted to use the list
comprehension syntax to build nextgen, and this got me into seperating the
get_index() routine. 
#!/usr/bin/python2

import sys
import random

def get_rule(rulenum):
  bitpattern = bin(rulenum)[2:]
  return [0]*(8-len(bitpattern)) + [int(bit) for bit in bitpattern]

def populate(n):
  random.seed()
  return [random.randint(0,1) for i in range(n)]

def get_index(thisgen, i):
  n = len(thisgen)-1
  cell = thisgen[i]
  if i is 0:
print "i==0"
prev, next = thisgen[n], thisgen[i+1]
  elif i is n:
print "i==%d" % n
prev, next = thisgen[i-1], thisgen[0]
  else:
prev, next = thisgen[i-1], thisgen[i+1]
  return prev*4 + cell*2 + next

def get_nextgen(thisgen, rule):
  return [rule[get_index(thisgen, i)] for i in range(len(thisgen))]


if len(sys.argv) == 2:
  n = int(sys.argv[1])
else:
  n = 257

rule = get_rule(145)
thisgen = populate(n)
nextgen = get_nextgen(thisgen, rule)
print "done for n == 257"

n = 258
thisgen = populate(n)
nextgen = get_nextgen(thisgen, rule)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a couple of things I don't understand wrt lists

2013-04-18 Thread Dave Angel

On 04/18/2013 09:01 AM, aaB wrote:

Hello,

I am still in the process of writing preliminary code for my CA project.
I am now running into a behavior that I can't explain.

Here is a script which, at least on my system, shows the issue (python2.7 on a
linux system).
The final project will be wrapping these functions (and others) into a class
which will be in a module which can be imported into a script.

#!/usr/bin/python2

import sys
import random

def get_rule(rulenum):
   bitpattern = bin(rulenum)[2:]
   return [0]*(8-len(bitpattern)) + [int(bit) for bit in bitpattern]

def populate(n):
   random.seed()
   return [random.randint(0,1) for i in range(n)]

def get_index(thisgen, i):
   n = len(thisgen)-1
   cell = thisgen[i]
   if i is 0:
 print "i==0"
 prev, next = thisgen[n], thisgen[i+1]
   elif i is n:


Don't use 'is' here and above.  You're not looking for a matching 
object, you're looking for the same value.



 print "i==%d" % n
 prev, next = thisgen[i-1], thisgen[0]
   else:
 prev, next = thisgen[i-1], thisgen[i+1]
   return prev*4 + cell*2 + next

def get_nextgen(thisgen, rule):
   return [rule[get_index(thisgen, i)] for i in range(len(thisgen))]


if len(sys.argv) == 2:
   n = int(sys.argv[1])
else:
   n = 257

rule = get_rule(145)
thisgen = populate(n)
nextgen = get_nextgen(thisgen, rule)
print "done for n == 257"

n = 258
thisgen = populate(n)
nextgen = get_nextgen(thisgen, rule)


My issue is that when n == 257, the script runs as expected, but if n >= 258, I
get an "IndexError: list index out of range".


No, you get an exception traceback.  Please paste in the whole traceback 
instead of making everyone guess where in the code it might be getting 
the exception.


My *guess* is that somewhere you're assuming that 8 bits is enough to 
encode 258 possibilities.  I'd have expected that to fail at 256 and 
larger, but it's a place to look.


The second guess, more likely, is that you're using "is" to compare 
numbers, and that's never a safe idea.  It might happen to work for 
small numbers, but you should be using ==.


   if i == 0:
   elf i == n:



The script is also attached to the email


Attachments aren't necessarily visible to everyone reading the mailing 
list.  Just make sure you post in text mode (which you did), and that 
should take care of spurious indentation bugs.




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


Re: anyone know pandas ? Don't understand error: NotImplementedError...

2013-04-18 Thread Wayne Werner

On Wed, 17 Apr 2013, someone wrote:

 File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line 214, in 
rule_code

   raise NotImplementedError
NotImplementedError


Can anyone tell why this error appears and how to fix it?


I don't know anything about pandas, but my recommendation?

  $ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py

(or nano or emacs - whatever editor you're comfortable with).

Go to line 214, and take a look-see at what you find. My guess is it will 
be something like:


def rule_code():
raise NotImplementedError()



Which is terribly unhelpful.

HTH,
Wayne
--
http://mail.python.org/mailman/listinfo/python-list


Re: a couple of things I don't understand wrt lists

2013-04-18 Thread aaB
> The second guess, more likely, is that you're using "is" to compare
> numbers, and that's never a safe idea.  It might happen to work for
> small numbers, but you should be using ==.
The second guess was right, changing "is" for "==" solved it, thanks.
I still have a lot to learn about python semantics.

The 8 bit pattern is used to store the rule, not the cells.
To compute the next cell, I index the rule list, based on the values of that 
cell
and it's two immediate neighbours in the previous generation.
This probably isn't the simplest way.
Since I am using only 3 cells to compute 1 cell, the biggest index would be
2**3 - 1, hence the 8bit pattern for the rule.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding NaN in JSON

2013-04-18 Thread Wayne Werner

On Wed, 17 Apr 2013, Miki Tebeka wrote:


I'm trying to find a way to have json emit float('NaN') as 'N/A'.

No.  There is no way to represent NaN in JSON.  It's simply not part of the
specification.

I know that. I'm trying to emit the *string* 'N/A' for every NaN.


Why not use `null` instead? It seems to be semantically more similar...

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


Working with lists within Dictionaries

2013-04-18 Thread inshu chauhan
Hello Everyone,

I am trying to work with lists and dictionaries together.
In the following code I have to access pixels in a segmented image through
a dictionary. But the problem is when I am trying to update the list
through dict it is giving me this error of tuple, ofcourse because list
indices should be integer.

THE CODE IS :
import cv
def access_segments(segimage, data):
print segimage
segments = {}
for y in xrange(0, segimage.height):
for x in xrange(0, segimage.width):
if segimage[y,x] == (0.0, 0.0, 0.0):
continue
else:
seg_color = segimage[y,x]
blue = int(seg_color[0])
green = int(seg_color[1])
red = int(seg_color[2])
reg_num = blue + 256 * green + 65536 * red
point = data[y,x]
segments.setdefault(reg_num, [])[point] += point

for p in sorted(segments.iterkeys()):
points = (segments[p])
print len(points)
print points

if __name__== "__main__":
data = cv.Load(r"C:\Users\inshu\Desktop\Masters
Thesis\data\xyz_0.yml")
segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters
Thesis\Segmentation\segmentation_numbers_0.tif",
cv.CV_LOAD_IMAGE_UNCHANGED)
access_segments(segimage, data)


THE ERROR IS:



Traceback (most recent call last):
  File "C:\Users\inshu\Desktop\test_reading .py", line 27, in 
access_segments(segimage, data)
  File "C:\Users\inshu\Desktop\test_reading .py", line 16, in
access_segments
segments.setdefault(reg_num, [])[point] += point
TypeError: list indices must be integers, not tuple

How can I access the data without getting this error ? the points have x,
y, z co-ordinates.

Thanks In Advance for your suggestions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: anyone know pandas ? Don't understand error: NotImplementedError...

2013-04-18 Thread Neil Cerutti
On 2013-04-18, Wayne Werner  wrote:
> On Wed, 17 Apr 2013, someone wrote:
>
>>  File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line 214, in 
>> rule_code
>>raise NotImplementedError
>> NotImplementedError
>> 
>>
>> Can anyone tell why this error appears and how to fix it?
>
> I don't know anything about pandas, but my recommendation?
>
>$ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py
>
> (or nano or emacs - whatever editor you're comfortable with).
>
> Go to line 214, and take a look-see at what you find. My guess is it will 
> be something like:
>
> def rule_code():
>  raise NotImplementedError()
>
> Which is terribly unhelpful.

It most likely means that the program is instantiating an
abstract base class when it should be using one of its subclasses
instead, e.g., BusinessDay, MonthEnd, MonthBegin,
BusinessMonthEnd, etc.

http://pandas.pydata.org/pandas-docs/dev/timeseries.html

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


Re: Novice Issue

2013-04-18 Thread John Gordon
In <0fa050c1-3a00-4c17-9fa6-b79a22485...@googlegroups.com> Bradley Wright 
 writes:

> while raw_input != "quit" or "q":

Others have pointed out flaws in this statement.  However, even if you
had written the loop the 'correct' way:

user_input = raw_input()
while user_input != "quit" or user_input != "q":

There is still a logic bug.  This loop will execute forever, because no
matter what the user enters, it will be unequal to "q" or unequal to "quit".
Use 'and' instead of 'or'.

Of course in this specific situation, as others have suggested, 'in' is
better still.

-- 
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: a couple of things I don't understand wrt lists

2013-04-18 Thread Chris Angelico
On Thu, Apr 18, 2013 at 11:01 PM, aaB  wrote:
> def get_index(thisgen, i):
>   n = len(thisgen)-1
>   cell = thisgen[i]
>   if i is 0:
> print "i==0"
> prev, next = thisgen[n], thisgen[i+1]
>   elif i is n:
> print "i==%d" % n
> prev, next = thisgen[i-1], thisgen[0]
>   else:
> prev, next = thisgen[i-1], thisgen[i+1]
>   return prev*4 + cell*2 + next

Without seeing the exception traceback I can't be sure, but here's
what I think might be happening:

When n == 258, your "i is n" check never happens. Since your
protective check for the end of the list doesn't fire, you therefore
go into the 'else' clause, and attempt to index thisgen[i+1], which
doesn't work.

CPython precreates and caches a certain subset of integers, for
performance. The exact set depends on the CPython version, but it's
low integers only. Within that set, equality is always matched by
identity:

i = 3
j = i+1
k = j-1
print(i is k)

This will most likely print "True" on CPython. But change i to, say,
1000, and you may find the opposite result.

So you can sometimes get away with the dangerous option of testing
integers for identity, but the right thing to do is to test for
equality. (You even get that right in your debugging messages, using
"==" there.)

A couple of other tips:

>   n = len(thisgen)-1
>   if i is 0:
> prev, next = thisgen[n], thisgen[i+1]

You can reference thisgen[-1] instead of thisgen[n] - so you can fold
this one into the default case. So all you need to do is deal with the
one possibility that i==len(thisgen)-1 and everything else is in the
else.

> def populate(n):
>   random.seed()
>   return [random.randint(0,1) for i in range(n)]

Don't reseed your RNG every call; just seed it once and let it run.
Seeding the RNG (without using a specific value, which you're not
doing here) is done in one of two ways: either from an OS-supplied
source of randomness (eg /dev/random), or from the time of day.
Reseeding repeatedly from /dev/random is unnecessary and might impact
other processes (forcing them to block for lack of available entropy);
reseeding from the time of day could mean that every call to
populate() returns the exact same sequence of numbers.

Have fun!

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


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread James Jong
Thanks so much Chris. This is part of a super computer and I am afraid I
don't have access to a machine with sudo permissions and similar
architecture & OS.

Is there any way to active higher level of verbosity during the build
process to identify what is failing? Or anything specifically I should
watch for?

James,





On Wed, Apr 17, 2013 at 9:59 PM, Chris Angelico  wrote:

> On Thu, Apr 18, 2013 at 8:39 AM, James Jong 
> wrote:
> > I managed to compile sqlite with:
> >
> > CPPFLAGS='-I/path_to_sqlite-3.7.16.2/include -I/path_to_tk8.6.0/include'
> >
> > DFLAGS='-L/path_to_sqlite-3.7.16.2/lib -L/path_to_tk8.6.0/lib/'
> >
> > ./configure --prefix=/path_to_python-2.7.4 --enable-shared
> >
> > However, _tkinter is still failing. I don't know what else to try. Any
> > thoughts?
>
> Can you build Python on a different system (to which you have admin
> rights), then deploy the binary to the one where you don't? Then you
> could do a much more standard compilation process. As long as the two
> systems are broadly similar, it should work.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working with lists within Dictionaries

2013-04-18 Thread Chris Angelico
On Thu, Apr 18, 2013 at 11:58 PM, inshu chauhan  wrote:
> segments.setdefault(reg_num, [])[point] += point

Not sure what your desired structure is. This is seeking to add the
point to something indexed by the point; perhaps you simply want to
append to the list itself?

segments.setdefault(reg_num, []).append(point)

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


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread Chris Angelico
On Fri, Apr 19, 2013 at 12:37 AM, James Jong  wrote:
> Thanks so much Chris. This is part of a super computer and I am afraid I
> don't have access to a machine with sudo permissions and similar
> architecture & OS.

Do you know what the OS is, at least? Can you, for instance, create a
virtual machine on your home system that matches the OS? As long as
it's broadly the same CPU architecture, chances are it'll run (maybe
it won't be completely optimal, but it'd be a start); in any case,
it's another possibility to try.

(Is the supercomputer doing something with DNA, and that's why you
picked your email address?)

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


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread Jason Swails
On Thu, Apr 18, 2013 at 10:37 AM, James Jong  wrote:

> Thanks so much Chris. This is part of a super computer and I am afraid I
> don't have access to a machine with sudo permissions and similar
> architecture & OS.
>
> Is there any way to active higher level of verbosity during the build
> process to identify what is failing? Or anything specifically I should
> watch for?
>

Most supercomputers I'm familiar with have some variant of Linux running
(e.g., SUSE or Red Hat are quite common).  Some of these machines only have
barebone kernels on the compute nodes, though, and have a fully-fledged
Linux OS only on the login nodes... This info is typically on the website
for that supercomputer (if it has one), or any other available
documentation.

That said, there are other options available that are probably less of a
hassle for you:

1) Skip tkinter unless you _know_ you really need it.  Do you plan on doing
X-forwarding when you log in?  Can you run the GUI app on your local
machine before uploading the files you need for computation?  Running GUIs
locally rather than over the network is typically much faster, anyway.

2) Submit a ticket to the supercomputer staff requesting that they install
the software you need.  There may be other 'gotchas' associated with
installing certain software on supercomputers that the staff would know
best.

Good luck,
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread James Jong
Thanks Jason. I have pinpointed the location of the error to a very
specific gcc line. I am reproducing the error below (very easy to read):

I run:

==
export CPPFLAGS='-I/opt/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
 -I/opt/tcl8.6.0/include/'

export LDFLAGS='-L/opt/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/
 -L/opt/tcl8.6.0/lib/  ./configure --prefix=/path_to_python-2.7.4
--enable-shared
==

and then I run make and I got  the following:

==

building '_tkinter' extension

gcc -pthread -fPIC -fno-strict-aliasing
-g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1
-I/usr/X11/include -I. -IInclude -I./Include
-I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
-I/opt/tcl8.6.0/include -I/usr/local/include
-I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c
/opt/python/src/Python-2.7.4/Modules/_tkinter.c -o
build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o

gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3
-Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I. -IInclude
-I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
-I/opt/tcl8.6.0/include -I/usr/local/include
-I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c
/opt/python/src/Python-2.7.4/Modules/tkappinit.c -o
build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o

gcc -pthread -shared -L/opt/sqlite/sqlite-3.7.16.2/lib
-L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/opt/sqlite/sqlite-3.7.16.2/lib
-L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -I. -IInclude -I./Include
-I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
-I/opt/tcl8.6.0/include
build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o
build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o
-L/usr/X11/lib -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/
-L/opt/tcl8.6.0/lib/ -L/usr/local/lib -L. -ltk8.6 -ltcl8.6 -lX11
-lpython2.7 -o build/lib.linux-x86_64-2.7/_tkinter.so

*** WARNING: renaming "_tkinter" since importing it failed: libtk8.6.so:
cannot open shared object file: No such file or directory
...
==

The odd thing is that I can see `libtk8.6.so` under /opt/tcl8.6.0/lib,  as
I specified with `LDFLAGS`:

==
cd /opt/tcl8.6.0/lib
ls
.
../
pkgconfig
tk8.6
libtkstub8.6.a
tkConfig.sh
libtk8.6.so
==

The file libtk8.6.so  has 1.5M and is definitely there.

So why did that compilation fail?

James



On Thu, Apr 18, 2013 at 11:05 AM, Jason Swails wrote:

>
>
>
> On Thu, Apr 18, 2013 at 10:37 AM, James Jong wrote:
>
>> Thanks so much Chris. This is part of a super computer and I am afraid I
>> don't have access to a machine with sudo permissions and similar
>> architecture & OS.
>>
>> Is there any way to active higher level of verbosity during the build
>> process to identify what is failing? Or anything specifically I should
>> watch for?
>>
>
> Most supercomputers I'm familiar with have some variant of Linux running
> (e.g., SUSE or Red Hat are quite common).  Some of these machines only have
> barebone kernels on the compute nodes, though, and have a fully-fledged
> Linux OS only on the login nodes... This info is typically on the website
> for that supercomputer (if it has one), or any other available
> documentation.
>
> That said, there are other options available that are probably less of a
> hassle for you:
>
> 1) Skip tkinter unless you _know_ you really need it.  Do you plan on
> doing X-forwarding when you log in?  Can you run the GUI app on your local
> machine before uploading the files you need for computation?  Running GUIs
> locally rather than over the network is typically much faster, anyway.
>
> 2) Submit a ticket to the supercomputer staff requesting that they install
> the software you need.  There may be other 'gotchas' associated with
> installing certain software on supercomputers that the staff would know
> best.
>
> Good luck,
> Jason
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Michael Torrie
On 04/16/2013 04:38 PM, Mark Janssen wrote:
>   (Note this contrasts starkly with Java(script), which doesn't seem
> to be based on anything -- can anyone clarify where Java actually
> comes from?)

Java is not equal in any way with JavaScript.  The only thing they share
are semicolons and braces.  Naming EMCAScript JavaScript was a very
unfortunate thing indeed.

For the record, JavaScript is what they call a "prototype-based
language."  http://en.wikipedia.org/wiki/Prototype-based_programming.
You can emulate an OOP system with a prototype-based language.

I highly recommend you read a book on formal programming language theory
and concepts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Atoms, Identifiers, and Primaries

2013-04-18 Thread rusi
On Apr 17, 11:43 pm, Steven D'Aprano  wrote:
>
> You won't gain that from the *grammar* of the language. Grammar is only part
> of the story, and in some ways, the least important part. If I tell you
> that the grammar of English includes:
>
> ADJECTIVE NOUN
>
> that alone is not going to help you understand the differences between
> a "wise man" and a "wise guy", or "peanut oil" and "baby oil".

Heh!! Cute example. [I'll remember it when I am teaching]


> > My question:  what did the interpreter
> > have to do to evaluate the expression x and y and return a value of
> > zero? I know the lexical analyzer has to parse the stream of characters
> > into tokens.  I presume this parsing generates the toxens x, y, and, and
> > a NEWLINE.
>
> Well, yes, but you're being awfully reductionist here. I'm the first to be
> in favour of curiosity for curiosity's sake, but I'm not sure that getting
> bogged down at such a low level this early in your Python learning
> experience is a good idea. *shrug* No skin off my nose though.
>

Good to be reductionist sometime (and stop being reductionist rest of
the time)

That is to say good to know the general lay of the land for what
happens inside a language implementation.
Broadly speaking it goes like this:
1. Lexical analysis -- separating into tokens/lexemes, removing
comments, (special for python, making sense of the indentation
structure)
2. Syntax analysis -- building the parse tree (at least in principle)
for the program that accords with the grammar
Convert the (concrete) parse tree into an abstract syntax tree (AST)
3. Semantic analysis (Type-checking): Not much of typechecking in
python just things like checking Name error
In a more usual (statically typed) language like C/java etc the AST
gets 'decorated' with type information
Once you are here, the undesirable cases have been weeded out and the
program (if correct) has been annotated well enough (decorated AST)
for…
4. Code generation/Interpretation using a straightforward recursive
walk down the decorated AST
5. An optimizing compiler may do more with the output of 4 (also
between 3 and 4)

Languages like C put the above 1-5 into a box called 'compiler-proper'
and stick a preprocessor before and assembler and linker after.
So while it is good to ask about the lexer, it is also the most boring
and irrelevant part of the system (to paraphrase Steven)
-- 
http://mail.python.org/mailman/listinfo/python-list


equivalent to C pointer

2013-04-18 Thread abdelkader belahcene
Hi everybody,

I am new to python  and I am discovering it.
I know C well,
and want to know if python knows how to manage Pointers
like pointer to function  here is a C example how to write it in python
Intergration with trapeze method

When we write Trapeze   ( at the compilation level) we don't know which
functions
Fonc  to handle.  Here for example we use  sin and a user defined  F1
The program is attached too

#include 
#include 

double F1 (double x){
return x*x;
}
double Trapeze(double Fonc(double ),
double left, double right, double step){
  double X1, X0, Y0, Y1, Z = 0;
  for(X0=left; X0 < right ; X0 = X0 + step) {
X1 = X0 + step;
Y1 = Fonc(X1);Y0 = Fonc(X0);
Z  += (Y1 + Y0) * step * 0.5;
  }
   return Z;
}
int  main(){
  double y;
  y=Trapeze(sin, -2.5, 3.2, 0.1);
  printf("\n\tValue for sin  is : \t %8.3lf ", y);
  y=Trapeze(F1, 0, 3, 0.1);
  printf("\n\tValue for F1 is : \t %8.3lf ", y);
  return 0;
}
/**
Value for sin  is : 0.197
Value for F1 is :  9.005
*/
thanks a lot
#include 
#include 
 
double F1 (double x){ 
		return x*x; 
}
double Trapeze(double Fonc(double ), 
double left, double right, double step){
  double X1, X0, Y0, Y1, Z = 0;
  for(X0=left; X0 < right ; X0 = X0 + step) {
X1 = X0 + step;
Y1 = Fonc(X1);Y0 = Fonc(X0);
Z  += (Y1 + Y0) * step * 0.5;
  }
   return Z;
}
int  main(){ 
  double y;
  y=Trapeze(sin, -2.5, 3.2, 0.1);
  printf("\n\tValue for sin  is : \t %8.3lf ", y);
  y=Trapeze(F1, 0, 3, 0.1);
  printf("\n\tValue for F1 is : \t %8.3lf ", y);
  return 0;
} 
/**
	Value for sin  is : 	0.197 
	Value for F1 is : 	 9.005
	*/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent to C pointer

2013-04-18 Thread Karim


Hello,

There is no such notion in python.
But the closest are iterators and generator functions.

Cheers
Karim

On 18/04/2013 19:06, abdelkader belahcene wrote:

Hi everybody,

I am new to python  and I am discovering it.
I know C well,
and want to know if python knows how to manage Pointers
like pointer to function  here is a C example how to write it in python
Intergration with trapeze method

When we write Trapeze   ( at the compilation level) we don't know 
which functions

Fonc  to handle.  Here for example we use  sin and a user defined  F1
The program is attached too

#include 
#include 

double F1 (double x){
return x*x;
}
double Trapeze(double Fonc(double ),
double left, double right, double step){
  double X1, X0, Y0, Y1, Z = 0;
  for(X0=left; X0 < right ; X0 = X0 + step) {
X1 = X0 + step;
Y1 = Fonc(X1);Y0 = Fonc(X0);
Z  += (Y1 + Y0) * step * 0.5;
  }
   return Z;
}
int  main(){
  double y;
  y=Trapeze(sin, -2.5, 3.2, 0.1);
  printf("\n\tValue for sin  is : \t %8.3lf ", y);
  y=Trapeze(F1, 0, 3, 0.1);
  printf("\n\tValue for F1 is : \t %8.3lf ", y);
  return 0;
}
/**
Value for sin  is : 0.197
Value for F1 is :  9.005
*/
thanks a lot




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


Re: equivalent to C pointer

2013-04-18 Thread Chris Kaynor
While Python does not have pointers, Python functions are objects, and they
may be passed like any other object:

def F1(x):
return x * x

def Trapeze(Fonc, left, right, step):
...code...
Y1 = Fonc(X1)
...code...

def main():
   ...code...
   y = Trapeze(F1, -2.5, 3.2, 0.1)
   ...code...


Chris


On Thu, Apr 18, 2013 at 10:06 AM, abdelkader belahcene  wrote:

> Hi everybody,
>
> I am new to python  and I am discovering it.
> I know C well,
> and want to know if python knows how to manage Pointers
> like pointer to function  here is a C example how to write it in python
> Intergration with trapeze method
>
> When we write Trapeze   ( at the compilation level) we don't know which
> functions
> Fonc  to handle.  Here for example we use  sin and a user defined  F1
> The program is attached too
>
> #include 
> #include 
>
> double F1 (double x){
> return x*x;
> }
> double Trapeze(double Fonc(double ),
> double left, double right, double step){
>   double X1, X0, Y0, Y1, Z = 0;
>   for(X0=left; X0 < right ; X0 = X0 + step) {
> X1 = X0 + step;
> Y1 = Fonc(X1);Y0 = Fonc(X0);
> Z  += (Y1 + Y0) * step * 0.5;
>   }
>return Z;
> }
> int  main(){
>   double y;
>   y=Trapeze(sin, -2.5, 3.2, 0.1);
>   printf("\n\tValue for sin  is : \t %8.3lf ", y);
>   y=Trapeze(F1, 0, 3, 0.1);
>   printf("\n\tValue for F1 is : \t %8.3lf ", y);
>   return 0;
> }
> /**
> Value for sin  is : 0.197
> Value for F1 is :  9.005
> */
> thanks a lot
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent to C pointer

2013-04-18 Thread abdelkader belahcene
Thanks for answer,
but with C  we can compile the trapeze function and put it in librairy,
If we try to save the trapeze alone in  package to import it later,  I
think, I am not sure
it will be refused because F1 and sin are not define !!! this is the
power of the C pointers !!!
the link is dynamic

thanks



On Thu, Apr 18, 2013 at 6:17 PM, Karim  wrote:

>
> Hello,
>
> There is no such notion in python.
> But the closest are iterators and generator functions.
>
> Cheers
> Karim
>
>
> On 18/04/2013 19:06, abdelkader belahcene wrote:
>
> Hi everybody,
>
>  I am new to python  and I am discovering it.
>  I know C well,
>  and want to know if python knows how to manage Pointers
>  like pointer to function  here is a C example how to write it in python
>  Intergration with trapeze method
>
>  When we write Trapeze   ( at the compilation level) we don't know which
> functions
>  Fonc  to handle.  Here for example we use  sin and a user defined  F1
>  The program is attached too
>
> #include 
> #include 
>
> double F1 (double x){
> return x*x;
> }
> double Trapeze(double Fonc(double ),
> double left, double right, double step){
>   double X1, X0, Y0, Y1, Z = 0;
>   for(X0=left; X0 < right ; X0 = X0 + step) {
> X1 = X0 + step;
> Y1 = Fonc(X1);Y0 = Fonc(X0);
> Z  += (Y1 + Y0) * step * 0.5;
>   }
>return Z;
> }
> int  main(){
>   double y;
>   y=Trapeze(sin, -2.5, 3.2, 0.1);
>   printf("\n\tValue for sin  is : \t %8.3lf ", y);
>   y=Trapeze(F1, 0, 3, 0.1);
>   printf("\n\tValue for F1 is : \t %8.3lf ", y);
>   return 0;
> }
> /**
> Value for sin  is : 0.197
> Value for F1 is :  9.005
> */
>  thanks a lot
>
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Neil Cerutti
On 2013-04-18, Michael Torrie  wrote:
> On 04/16/2013 04:38 PM, Mark Janssen wrote:
>>   (Note this contrasts starkly with Java(script), which doesn't seem
>> to be based on anything -- can anyone clarify where Java
>> actually comes from?)
>
> Java is not equal in any way with JavaScript.  The only thing
> they share are semicolons and braces.  Naming EMCAScript
> JavaScript was a very unfortunate thing indeed.
>
> For the record, JavaScript is what they call a "prototype-based
> language."  http://en.wikipedia.org/wiki/Prototype-based_programming.
> You can emulate an OOP system with a prototype-based language.
>
> I highly recommend you read a book on formal programming
> language theory and concepts.

Let me recommend Concepts, Techniques and Models of Computer
Programming, Van Roy and Haridi.

http://www.info.ucl.ac.be/~pvr/book.html

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


Re: equivalent to C pointer

2013-04-18 Thread David Robinow
On Thu, Apr 18, 2013 at 1:06 PM, abdelkader belahcene
wrote:

> Hi everybody,
>
> I am new to python  and I am discovering it.
> I know C well,
> and want to know if python knows how to manage Pointers
> like pointer to function  here is a C example how to write it in python
> Intergration with trapeze method
>
> When we write Trapeze   ( at the compilation level) we don't know which
> functions
> Fonc  to handle.  Here for example we use  sin and a user defined  F1
> The program is attached too
>
> #include 
> #include 
>
> double F1 (double x){
> return x*x;
> }
> double Trapeze(double Fonc(double ),
> double left, double right, double step){
>   double X1, X0, Y0, Y1, Z = 0;
>   for(X0=left; X0 < right ; X0 = X0 + step) {
> X1 = X0 + step;
> Y1 = Fonc(X1);Y0 = Fonc(X0);
> Z  += (Y1 + Y0) * step * 0.5;
>   }
>return Z;
> }
> int  main(){
>   double y;
>   y=Trapeze(sin, -2.5, 3.2, 0.1);
>   printf("\n\tValue for sin  is : \t %8.3lf ", y);
>   y=Trapeze(F1, 0, 3, 0.1);
>   printf("\n\tValue for F1 is : \t %8.3lf ", y);
>   return 0;
> }
> /**
> Value for sin  is : 0.197
> Value for F1 is :  9.005
> */
>
> Python doesn't have pointers, but don't let that bother you.
A python version is actually a lot simpler.
See below (I didn't bother with getting the print formats just right)
--
import math
def F1(x):
return x*x

def Trapeze(f, left, right, step):
X0 = left
Z = 0.0
while (X0 < right):
X1 = X0 + step
Y1 = f(X1)
Y0 = f(X0)
Z += (Y1 + Y0) * step * 0.5
X0 = X1
return Z

def main():
y = Trapeze(math.sin, -2.5, 3.2, 0.1)
print("Value for sin is:{0} ".format(y))
y = Trapeze(F1, 0, 3, 0.1)
print("Value for F1 is {0} ".format(y))

if __name__ == "__main__":
main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread James Jong
All

I finally solved the problem. The problem was that setup.py tests loading
the dynamic library libtk (this I don't understand, since I though Python
would statically link against TCL, TK and SQLITE.

Either way, I have updated the thread at StackOverflow with the answer:
http://stackoverflow.com/questions/16026348/preparing-tkinter-and-sqlite3-for-python-installation-no-admin-rights/16090051#16090051

but basically the answer was:

Add the following include paths through `CPPFLAGS`

* /path_to/sqlite3/include
* /path_to/tcl/include
* /path_to/tk/include

the following lib paths through `LDFLAGS`

* /path_to/sqlite3/lib
* /path_to/tcl/lib
* /path_to/tk/lib

and the following lib paths through `LD_LIBRARY_PATH`:

* /path_to/sqlite/lib
* /path_to/tcl/lib
* /path_to/tk/lib

Thanks,

James


On Thu, Apr 18, 2013 at 12:24 PM, James Jong  wrote:

> Thanks Jason. I have pinpointed the location of the error to a very
> specific gcc line. I am reproducing the error below (very easy to read):
>
> I run:
>
> ==
> export CPPFLAGS='-I/opt/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
>  -I/opt/tcl8.6.0/include/'
>
> export LDFLAGS='-L/opt/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/
>  -L/opt/tcl8.6.0/lib/  ./configure --prefix=/path_to_python-2.7.4
> --enable-shared
> ==
>
> and then I run make and I got  the following:
>
> ==
> 
> building '_tkinter' extension
>
> gcc -pthread -fPIC -fno-strict-aliasing
> -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1
> -I/usr/X11/include -I. -IInclude -I./Include
> -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
> -I/opt/tcl8.6.0/include -I/usr/local/include
> -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c
> /opt/python/src/Python-2.7.4/Modules/_tkinter.c -o
> build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o
>
> gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3
> -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I.
> -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include
> -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include -I/usr/local/include
> -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c
> /opt/python/src/Python-2.7.4/Modules/tkappinit.c -o
> build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o
>
> gcc -pthread -shared -L/opt/sqlite/sqlite-3.7.16.2/lib
> -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/opt/sqlite/sqlite-3.7.16.2/lib
> -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -I. -IInclude -I./Include
> -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include
> -I/opt/tcl8.6.0/include
> build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o
> build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o
> -L/usr/X11/lib -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/
> -L/opt/tcl8.6.0/lib/ -L/usr/local/lib -L. -ltk8.6 -ltcl8.6 -lX11
> -lpython2.7 -o build/lib.linux-x86_64-2.7/_tkinter.so
>
> *** WARNING: renaming "_tkinter" since importing it failed: libtk8.6.so:
> cannot open shared object file: No such file or directory
> ...
> ==
>
> The odd thing is that I can see `libtk8.6.so` under /opt/tcl8.6.0/lib,
>  as I specified with `LDFLAGS`:
>
> ==
> cd /opt/tcl8.6.0/lib
> ls
> .
> ../
> pkgconfig
> tk8.6
> libtkstub8.6.a
> tkConfig.sh
> libtk8.6.so
> ==
>
> The file libtk8.6.so  has 1.5M and is definitely there.
>
> So why did that compilation fail?
>
> James
>
>
>
> On Thu, Apr 18, 2013 at 11:05 AM, Jason Swails wrote:
>
>>
>>
>>
>> On Thu, Apr 18, 2013 at 10:37 AM, James Jong wrote:
>>
>>> Thanks so much Chris. This is part of a super computer and I am afraid I
>>> don't have access to a machine with sudo permissions and similar
>>> architecture & OS.
>>>
>>> Is there any way to active higher level of verbosity during the build
>>> process to identify what is failing? Or anything specifically I should
>>> watch for?
>>>
>>
>> Most supercomputers I'm familiar with have some variant of Linux running
>> (e.g., SUSE or Red Hat are quite common).  Some of these machines only have
>> barebone kernels on the compute nodes, though, and have a fully-fledged
>> Linux OS only on the login nodes... This info is typically on the website
>> for that supercomputer (if it has one), or any other available
>> documentation.
>>
>> That said, there are other options available that are probably less of a
>> hassle for you:
>>
>> 1) Skip tkinter unless you _know_ you really need it.  Do you plan on
>> doing X-forwarding when you log in?  Can you run the GUI app on your local
>> machine before uploading the fil

Re: equivalent to C pointer

2013-04-18 Thread Neil Cerutti
On 2013-04-18, abdelkader belahcene  wrote:
> Thanks for answer,
> but with C  we can compile the trapeze function and put it in
> librairy, If we try to save the trapeze alone in  package to
> import it later,  I think, I am not sure it will be refused
> because F1 and sin are not define !!! this is the power of
> the C pointers !!! the link is dynamic

There's no linking stage in Python. Everything you use must be
defined before you use it.

In Python you can put trapeze in a library, and it will be able
to accept any old function under the sun when you call it, as
long as that function is defined.

in trapeze.py:

  def trapeze(func, left, right, step):
  return sum((func(x) + func(x + step)) * step * 0.5
 for x in range(left, right, step))
   
in file1.py:

  import trapeze
  
  def square(x):
  return x*x
  
  print(trapeze.trapeze(square, 0, 3, 2.5))


if file2.py:

  import trapeze
  import math
  
  print(trapeze.trapeze(math.sin, 1.3, 2.5, 1.0))

The functions square and sin are both defined before you pass
them to trapeze, so all is well. Trapeze doesn't know or care about
the signature of those functions until it actually tries to call
them. At that time, if either one isn't defined properly Python
will raise an exception.

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


Re: equivalent to C pointer

2013-04-18 Thread David Robinow
On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene
wrote:

> Thanks for answer,
> but with C  we can compile the trapeze function and put it in librairy,
> If we try to save the trapeze alone in  package to import it later,  I
> think, I am not sure
> it will be refused because F1 and sin are not define !!! this is the
> power of the C pointers !!!
> the link is dynamic
>
You don't need C pointers.  The design below is demonstrative, not ideal.

# file  MyFuncs.py
def F1(x):
return x*x

def Trapeze(f, left, right, step):
X0 = left
Z = 0.0
while (X0 < right):
X1 = X0 + step
Y1 = f(X1)
Y0 = f(X0)
Z += (Y1 + Y0) * step * 0.5
X0 = X1
return Z



# file UseMyFuncs.py
import math
import MyFuncs

def main():
y = MyFuncs.Trapeze(math.sin, -2.5, 3.2, 0.1)
print("Value for sin is:{0} ".format(y))
y = MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1)
print("Value for F1 is {0} ".format(y))

if __name__ == "__main__":
main()

###
#python3 UseMyFuncs.py
###
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent to C pointer

2013-04-18 Thread Ian Kelly
On Thu, Apr 18, 2013 at 11:50 AM, abdelkader belahcene
 wrote:
> Thanks for answer,
> but with C  we can compile the trapeze function and put it in librairy,
> If we try to save the trapeze alone in  package to import it later,  I
> think, I am not sure
> it will be refused because F1 and sin are not define !!! this is the
> power of the C pointers !!!
> the link is dynamic

The Python equivalent of a dynamically linked library is a module.
You can certainly pass functions defined in one module as arguments to
functions defined in another, completely unrelated module.  In fact,
Python doesn't care where they were defined or even whether they are
functions; they're just objects, no different in that regard from
strings or ints or class instances.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: anyone know pandas ? Don't understand error: NotImplementedError...

2013-04-18 Thread someone

On 04/18/2013 03:44 PM, Wayne Werner wrote:

On Wed, 17 Apr 2013, someone wrote:


 File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line
214, in rule_code
   raise NotImplementedError
NotImplementedError


Can anyone tell why this error appears and how to fix it?


I don't know anything about pandas, but my recommendation?

   $ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py

(or nano or emacs - whatever editor you're comfortable with).

Go to line 214, and take a look-see at what you find. My guess is it
will be something like:

def rule_code():
 raise NotImplementedError()



Which is terribly unhelpful.


Oh, yes - you're completely right:

   # line 211 (empty line)
@property # line 212
def rule_code(self): # line 213
raise NotImplementedError # line 214
   # line 215 (empty line)

Below and above this "rule_code" is code belonging to some other 
functions... hmmm... I also tried to look in:


/usr/lib/pymodules/python2.7/pandas/tools/plotting.py

But I'm very unfamiliar with pandas, so everything looks "correct" to me 
- because I don't understand the data structure, I think I cannot see 
what is wrong...




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


Re: equivalent to C pointer

2013-04-18 Thread Tim Chase
On 2013-04-18 18:07, Neil Cerutti wrote:
> There's no linking stage in Python. Everything you use must be
> defined before you use it.

"must be defined", only if you don't want an error.  But in python,
it isn't even REQUIRED that it be defined:

  some_undefined_function("args go here")

will bomb out your program, but Python graciously allows you to do so:

  >>> try:
  ... hello(42)
  ... except NameError:
  ... print "You had me at hello"
  ... 
  You had me at hello

-tkc



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


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Jason Wilkins
Warning, this is a bit of a rant.

That paragraph from Wikipedia seems to be confused.  It gives the fourth
paradigm as "declarative" but then says "first order logic for logic
programming".  It seems somebody did an incomplete replacement of
"declarative" for "logic".  Wikipedia is often schizophrenic like that.

Personally, I think that object oriented and logical programming only
became official paradigms because there was a certain level of hype for
them in the 1980s and nobody has thought to strike them off the list after
the hype died down.

Object-oriented, as constituted today, is just a layer of abstraction over
imperative programming (or imperative style programming in functional
languages, because objects require side-effects).  What "object-oriented"
language actually in use now isn't just an imperative language with fancy
abstraction mechanisms?

The problem with having declarative languages as a paradigm (which logical
languages would be a part) is that it feels like it should be a
"miscellaneous" category.  Being declarative doesn't tell you much except
that some machine is going to turn your descriptions of something into some
kind of action.  In logical programming it is a set of predicates, but it
could just as easily be almost anything else.  In a way all languages are
"declarative", it is just that we have some standard interpretations of
what is declared that are very common (imperative and functional).

My wish is that the idea of there being four paradigms would be abandoned
the same we the idea of four food groups has been abandoned (which may
surprise some of you).  We have more than four different modes of thinking
when programming and some are much more important than others and some are
subsets of others.  We should teach students a more sophisticated view.

Ironically Wikipedia also shows us this complexity.  The
programming language paradigm side bar actually reveals the wealth
of different styles that are available.  There is simply no clean and
useful way to overlay the four paradigms over what we see there, so it
should be abandoned because it gives students a false idea.


On Wed, Apr 17, 2013 at 9:42 AM, Andreas Abel wrote:

> [ The Types Forum, http://lists.seas.upenn.edu/**
> mailman/listinfo/types-list]
>
> On 17.04.2013 11:30, Uday S Reddy wrote:
>
>> Mark Janssen writes:
>>
>>  From:  en.wikipedia.org: Programming_paradigm:
>>>
>>> "A programming paradigm is a fundamental style of computer
>>> programming. There are four main paradigms: object-oriented,
>>> imperative, functional and declarative. Their foundations are distinct
>>> models of computation: Turing machine for object-oriented and
>>> imperative programming, lambda calculus for functional programming,
>>> and first order logic for logic programming."
>>>
>>
> I removed the second sentence relating paradigms to computation models
> and put it on the talk page instead.  It does not make sense to connect
> imperative programming to Turing machines like functional programming to
> lambda calculus.  A better match would be random access machines, but the
> whole idea of a connection between a programming paradigm and a computation
> model is misleading.
>
>
>  While I understand the interest in purely theoretical models, I wonder
>>> two things:  1)  Are these distinct models of computation valid?  And,
>>> 2) If so, shouldn't a theory of types announce what model of
>>> computation they are working from?
>>>
>>
>> These distinctions are not fully valid.
>>
>> - Functional programming, logic programming and imperative programming are
>> three different *computational mechanisms*.
>>
>> - Object-orientation and abstract data types are two different ways of
>> building higher-level *abstractions*.
>>
>> The authors of this paragraph did not understand that computational
>> mechanisms and higher-level abstractions are separate, orthogonal
>> dimensions
>> in programming language design.  All six combinations, obtained by
>> picking a
>> computational mechanism from the first bullet and an abstraction mechanism
>> from the second bullet, are possible.  It is a mistake to put
>> object-orientation in the first bullet.  Their idea of "paradigm" is vague
>> and ill-defined.
>>
>> Cheers,
>> Uday Reddy
>>
>>
>
> --
> Andreas Abel  <><  Du bist der geliebte Mensch.
>
> Theoretical Computer Science, University of Munich
> Oettingenstr. 67, D-80538 Munich, GERMANY
>
> andreas.a...@ifi.lmu.de
> http://www2.tcs.ifi.lmu.de/~**abel/ 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread Terry Jan Reedy

On 4/18/2013 12:24 PM, James Jong wrote:

After compiling, you might want to run the test suite.


libtk8.6.so 


I do not know that Python/_tkinter/tkinter has been very well tested, 
certainly not on all systems, with the newish tcl/tk 8.6, as opposed to 
8.5.z used for several years. There are 4 test/test_xxx files to be 
concerned about: something like test_tcl, test_tkinter, test_ttkxxx.


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


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread James Jong
Thanks Terry. I run the tcl tests and passed them all. There was only one
tk test that I think I didn't  pass.

One thing I don't understand is that I thought that Python would statically
link against sqlite and tcl/tk (I presume that this is the reason why you
said I could build it in a similar system and copy it to the
supercomputer). But this thread shows that, at least, setup.py tries to
load libtk.so (a dynamic shared library).

Does Python then load dynamic libraries from sqlite, tcl, tk when using the
respective modules?

James


On Thu, Apr 18, 2013 at 3:10 PM, Terry Jan Reedy  wrote:

> On 4/18/2013 12:24 PM, James Jong wrote:
>
> After compiling, you might want to run the test suite.
>
>  libtk8.6.so 
>>
>
> I do not know that Python/_tkinter/tkinter has been very well tested,
> certainly not on all systems, with the newish tcl/tk 8.6, as opposed to
> 8.5.z used for several years. There are 4 test/test_xxx files to be
> concerned about: something like test_tcl, test_tkinter, test_ttkxxx.
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: anyone know pandas ? Don't understand error: NotImplementedError...

2013-04-18 Thread someone

On 04/18/2013 04:07 PM, Neil Cerutti wrote:

On 2013-04-18, Wayne Werner  wrote:

On Wed, 17 Apr 2013, someone wrote:




Go to line 214, and take a look-see at what you find. My guess is it will
be something like:

def rule_code():
  raise NotImplementedError()

Which is terribly unhelpful.


It most likely means that the program is instantiating an
abstract base class when it should be using one of its subclasses
instead, e.g., BusinessDay, MonthEnd, MonthBegin,
BusinessMonthEnd, etc.

http://pandas.pydata.org/pandas-docs/dev/timeseries.html


Hi Neil and Wayne,

Thank you very much for your suggestions... I now found out something: 
In the function:


def convertListPairToTimeSeries(dList, cList):
...
...
#  create the timeseries
ts = pandas.Series(cListL, index=indx)
# fill in missing days
#ts = ts.asfreq(pandas.datetools.DateOffset())
return ts

I had to out-comment the last line before the return-statement (not sure 
what that line is supposed to do, in the first case)...


Now the program runs, but no plot is seen. Then I found out that I had 
to add:


import matplotlib.pyplot as plt

in the top of the program and add the following in the bottom of the 
program:


plt.show()


Final program:
==
#!/usr/bin/python

import pandas
import datetime
import numpy
import ipdb
import matplotlib.pyplot as plt

datesList = [datetime.date(2011,12,1), \
 datetime.date(2011,12,2), \
 datetime.date(2011,12,3), \
 datetime.date(2011,12,10)]

countsList = numpy.random.randn(len(datesList))
startData = datetime.datetime(2011,12,3)
endData = datetime.datetime(2011,12,8)

def convertListPairToTimeSeries(dList, cList):
# my dateList had date objects, so convert back to datetime objects
dListDT = [datetime.datetime.combine(x, datetime.time()) for x in 
dList]

# found that NaN didn't work if the cList contained int data
cListL = [float(x) for x in cList]
#  create the index from the datestimes list
indx = pandas.Index(dListDT)
#  create the timeseries
ts = pandas.Series(cListL, index=indx)
# fill in missing days
#ts = ts.asfreq(pandas.datetools.DateOffset())
return ts

print "\nOriginal datesList list:\n", datesList
tSeries = convertListPairToTimeSeries(datesList, countsList)
print "\nPandas timeseries:\n", tSeries

# use slicing to change length of data
tSeriesSlice = tSeries.ix[startData:endData]
print "\nPandas timeseries sliced between", startData.date(), \
  "and", endData.date(), ":\n", tSeriesSlice

# use truncate instead of slicing to change length of data
tSeriesTruncate = tSeries.truncate(before=startData, after=endData)
print "\nPandas timeseries truncated between", startData.date(), \
  "and", endData.date(), ":\n", tSeriesTruncate

# my data had lots of gaps that were actually 0 values, not missing data
# So I used this to fix the NaN outside the known outage
startOutage = datetime.datetime(2011,12,7)
endOutage = datetime.datetime(2011,12,8)
tsFilled = tSeries.fillna(0)
# set the known outage values back to NAN
tsFilled.ix[startOutage:endOutage] = numpy.NAN
print "\nPandas timeseries NaN reset to 0 outside known outage between", \
  startOutage.date(), "and", endOutage.date(), ":\n", tsFilled

print "\nPandas series.tail(1) and series.head(1) are handy for " +\
  "checking ends of list:\n", tsFilled.head(1), tsFilled.tail(1)
print
tsFilled.plot()
plt.show()
==

This seem to work, although I don't fully understand it, as I'm pretty 
new to pandas...



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


Re: equivalent to C pointer

2013-04-18 Thread abdelkader belahcene
Thanks a lot, I think this does the task

cheers


On Thu, Apr 18, 2013 at 7:14 PM, David Robinow  wrote:

> On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene <
> abelahc...@gmail.com> wrote:
>
>> Thanks for answer,
>> but with C  we can compile the trapeze function and put it in librairy,
>> If we try to save the trapeze alone in  package to import it later,  I
>> think, I am not sure
>> it will be refused because F1 and sin are not define !!! this is the
>> power of the C pointers !!!
>> the link is dynamic
>>
> You don't need C pointers.  The design below is demonstrative, not ideal.
>
> # file  MyFuncs.py
>
> def F1(x):
> return x*x
>
> def Trapeze(f, left, right, step):
> X0 = left
> Z = 0.0
> while (X0 < right):
> X1 = X0 + step
> Y1 = f(X1)
> Y0 = f(X0)
>
> Z += (Y1 + Y0) * step * 0.5
> X0 = X1
> return Z
>
>
>
> # file UseMyFuncs.py
> import math
> import MyFuncs
>
> def main():
> y = MyFuncs.Trapeze(math.sin, -2.5, 3.2, 0.1)
>
> print("Value for sin is:{0} ".format(y))
> y = MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1)
>
> print("Value for F1 is {0} ".format(y))
>
> if __name__ == "__main__":
> main()
>
> ###
> #python3 UseMyFuncs.py
> ###
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange behavior for a 2D list

2013-04-18 Thread Robrecht W. Uyttenhove
Hello,

I tried out the following code:
y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)]
>>> y
[[0, 1, 2, 3, 4, 5, 6],
 [7, 8, 9, 10, 11, 12, 13],
 [14, 15, 16, 17, 18, 19, 20],
 [21, 22, 23, 24, 25, 26, 27],
 [28, 29, 30, 31, 32, 33, 34]]

>>> y[1:5:2][::3]
[[7, 8, 9, 10, 11, 12, 13]]

I expected the 2D list:
[[ 7, 10, 13],
 [21, 24, 27]]

Any ideas?

Thanks,

Rob

PS: I used Python 2.7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange behavior for a 2D list

2013-04-18 Thread Peter Otten
Robrecht W. Uyttenhove wrote:

> Hello,
> 
> I tried out the following code:
> y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)]
 y
> [[0, 1, 2, 3, 4, 5, 6],
>  [7, 8, 9, 10, 11, 12, 13],
>  [14, 15, 16, 17, 18, 19, 20],
>  [21, 22, 23, 24, 25, 26, 27],
>  [28, 29, 30, 31, 32, 33, 34]]
> 
 y[1:5:2][::3]
> [[7, 8, 9, 10, 11, 12, 13]]
> 
> I expected the 2D list:
> [[ 7, 10, 13],
>  [21, 24, 27]]
> 
> Any ideas?

It is not really a 2D list; rather a list of lists. You cannot see the two 
slices together, the slicing happens in two separate steps.

y[1:5:2] is a list containing two items (that happen to be lists)

>>> x = y[1:5:2]
>>> x
[[7, 8, 9, 10, 11, 12, 13], [21, 22, 23, 24, 25, 26, 27]]

x[::3] then operates on the outer list

>>> x[::3]
[[7, 8, 9, 10, 11, 12, 13]]

By the way, numpy offers the behaviour you expected:

>>> import numpy
>>> a = numpy.array(y)
>>> a
array([[ 0,  1,  2,  3,  4,  5,  6],
   [ 7,  8,  9, 10, 11, 12, 13],
   [14, 15, 16, 17, 18, 19, 20],
   [21, 22, 23, 24, 25, 26, 27],
   [28, 29, 30, 31, 32, 33, 34]])
>>> a[1:5:2,::3]
array([[ 7, 10, 13],
   [21, 24, 27]])

Note that both slices are passed in the same a[...] operation.

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


Re: Strange behavior for a 2D list

2013-04-18 Thread John Gordon
In  "Robrecht W. 
Uyttenhove"  writes:

> I tried out the following code:
> y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)]
> >>> y
> [[0, 1, 2, 3, 4, 5, 6],
>  [7, 8, 9, 10, 11, 12, 13],
>  [14, 15, 16, 17, 18, 19, 20],
>  [21, 22, 23, 24, 25, 26, 27],
>  [28, 29, 30, 31, 32, 33, 34]]

> >>> y[1:5:2][::3]
> [[7, 8, 9, 10, 11, 12, 13]]

> I expected the 2D list:
> [[ 7, 10, 13],
>  [21, 24, 27]]

> Any ideas?

y is just a list.  It happens to be a list of lists, but that doesn't make
it a "2D" list.  It's an important distinction.

y[1:5:2] is the contents of y, starting at the second element and selecting
every second element after that:

[[7, 8, 9, 10, 11, 12, 13], [21, 22, 23, 24, 25, 26, 27]]

y[1:5:2][::3] is the contents of y[1:5:2], starting at the first element and
selecting every third element after that (and there are only two elements,
so it stops after the first one):

[[7, 8, 9, 10, 11, 12, 13]]

Why were you expecting the other result?

-- 
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: Strange behavior for a 2D list

2013-04-18 Thread Wolfgang Maier
Robrecht W. Uyttenhove  gmail.com> writes:

> 
> Hello,
> I tried out the following
code:y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)]
> >>> y[[0, 1, 2, 3, 4, 5, 6],  [7, 8, 9, 10, 11, 12, 13], 
>   [14, 15, 16, 17, 18, 19, 20],  [21, 22, 23, 24, 25, 26, 27],  [28, >
   29, 30, 31, 32, 33, 34]]
> >>> y[1:5:2][::3]
> [[7, 8, 9, 10, 11, 12, 13]]
> I expected the 2D list:[[ 7, 10, 13],
>  [21, 24, 27]]
> 
> Any ideas?
> 
> Thanks,
> Rob
> PS: I used Python 2.7.3
> 

The explanation is rather simple, just break up your complex slicing into
its parts:
y[1:5:2] => [[7, 8, 9, 10, 11, 12, 13],[21, 22, 23, 24, 25, 26, 27]]
and [::3] is asking for the first,4th,7th,... element from this list.
Obviously, only the first one's existing, so [7, 8, 9, 10, 11, 12, 13]

What you expected is kind of vertical slicing through the rows. I don't
think you can achieve this with slicing alone in standard Python, but it's
possible with numpy arrays.
In Python you will have to combine slicing with a comprehension, like this:
[x[::3] for x in y[1:5:2]]

Best,
Wolfgang

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


How to set my gui?

2013-04-18 Thread Tracubik

Hi all!
I'm trying to make a simple program that essentially do this:

1) open a html file (extracted epub file)
2) search for occurrences like "ita-ly"
3) put them on a simple GUI: 1 text field and two buttons: keepy it and 
correct it (i.e. it will become italy)


now this is quite simple but how can i do it properly?
i suppose i've to first generate the window and than populate it, but 
where i've to put the "search for occurences" code? I don't think init() 
is the right place..


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


Re: How to set my gui?

2013-04-18 Thread John Gordon
In <5170648d$0$1368$4fafb...@reader2.news.tin.it> Tracubik 
 writes:

> i suppose i've to first generate the window and than populate it, but 
> where i've to put the "search for occurences" code? I don't think init() 
> is the right place..

What GUI library are you using?

-- 
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: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Robert Harper
In short, there is no such thing as a "paradigm".  I agree fully.  This term is 
a holdover from the days when people spent time and space trying to build 
taxonomies based on ill-defined superficialities.  See Steve Gould's essay 
"What, If Anything, Is A Zebra?".  You'll enjoy learning that there is, in 
fact, no such thing as a zebra---there are, rather, three different striped 
horse-like mammals, two of which are genetically related, and one of which is 
not.  The propensity to be striped, like the propensity to have five things 
(fingers, segments, whatever) is a deeply embedded genetic artifact that 
expresses itself in various ways.

Bob Harper

On Apr 18, 2013, at 2:48 PM, Jason Wilkins wrote:

> [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ]
> 
> Warning, this is a bit of a rant.
> 
> That paragraph from Wikipedia seems to be confused.  It gives the fourth
> paradigm as "declarative" but then says "first order logic for logic
> programming".  It seems somebody did an incomplete replacement of
> "declarative" for "logic".  Wikipedia is often schizophrenic like that.
> 
> Personally, I think that object oriented and logical programming only
> became official paradigms because there was a certain level of hype for
> them in the 1980s and nobody has thought to strike them off the list after
> the hype died down.
> 
> Object-oriented, as constituted today, is just a layer of abstraction over
> imperative programming (or imperative style programming in functional
> languages, because objects require side-effects).  What "object-oriented"
> language actually in use now isn't just an imperative language with fancy
> abstraction mechanisms?
> 
> The problem with having declarative languages as a paradigm (which logical
> languages would be a part) is that it feels like it should be a
> "miscellaneous" category.  Being declarative doesn't tell you much except
> that some machine is going to turn your descriptions of something into some
> kind of action.  In logical programming it is a set of predicates, but it
> could just as easily be almost anything else.  In a way all languages are
> "declarative", it is just that we have some standard interpretations of
> what is declared that are very common (imperative and functional).
> 
> My wish is that the idea of there being four paradigms would be abandoned
> the same we the idea of four food groups has been abandoned (which may
> surprise some of you).  We have more than four different modes of thinking
> when programming and some are much more important than others and some are
> subsets of others.  We should teach students a more sophisticated view.
> 
> Ironically Wikipedia also shows us this complexity.  The
> programming language paradigm side bar actually reveals the wealth
> of different styles that are available.  There is simply no clean and
> useful way to overlay the four paradigms over what we see there, so it
> should be abandoned because it gives students a false idea.
> 
> 
> On Wed, Apr 17, 2013 at 9:42 AM, Andreas Abel wrote:
> 
>> [ The Types Forum, http://lists.seas.upenn.edu/**
>> mailman/listinfo/types-list]
>> 
>> On 17.04.2013 11:30, Uday S Reddy wrote:
>> 
>>> Mark Janssen writes:
>>> 
>>> From:  en.wikipedia.org: Programming_paradigm:
 
 "A programming paradigm is a fundamental style of computer
 programming. There are four main paradigms: object-oriented,
 imperative, functional and declarative. Their foundations are distinct
 models of computation: Turing machine for object-oriented and
 imperative programming, lambda calculus for functional programming,
 and first order logic for logic programming."
 
>>> 
>> I removed the second sentence relating paradigms to computation models
>> and put it on the talk page instead.  It does not make sense to connect
>> imperative programming to Turing machines like functional programming to
>> lambda calculus.  A better match would be random access machines, but the
>> whole idea of a connection between a programming paradigm and a computation
>> model is misleading.
>> 
>> 
>> While I understand the interest in purely theoretical models, I wonder
 two things:  1)  Are these distinct models of computation valid?  And,
 2) If so, shouldn't a theory of types announce what model of
 computation they are working from?
 
>>> 
>>> These distinctions are not fully valid.
>>> 
>>> - Functional programming, logic programming and imperative programming are
>>> three different *computational mechanisms*.
>>> 
>>> - Object-orientation and abstract data types are two different ways of
>>> building higher-level *abstractions*.
>>> 
>>> The authors of this paragraph did not understand that computational
>>> mechanisms and higher-level abstractions are separate, orthogonal
>>> dimensions
>>> in programming language design.  All six combinations, obtained by
>>> picking a
>>> comp

Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Robert Harper
The term "declarative" never meant a damn thing, but was often used, absurdly, 
to somehow lump together functional programming with logic programming, and 
separate it from imperative programming.  It never made a lick of sense; it's 
just a marketing term.

Bob Harper

On Apr 18, 2013, at 2:48 PM, Jason Wilkins wrote:

> [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ]
> 
> Warning, this is a bit of a rant.
> 
> That paragraph from Wikipedia seems to be confused.  It gives the fourth
> paradigm as "declarative" but then says "first order logic for logic
> programming".  It seems somebody did an incomplete replacement of
> "declarative" for "logic".  Wikipedia is often schizophrenic like that.
> 
> Personally, I think that object oriented and logical programming only
> became official paradigms because there was a certain level of hype for
> them in the 1980s and nobody has thought to strike them off the list after
> the hype died down.
> 
> Object-oriented, as constituted today, is just a layer of abstraction over
> imperative programming (or imperative style programming in functional
> languages, because objects require side-effects).  What "object-oriented"
> language actually in use now isn't just an imperative language with fancy
> abstraction mechanisms?
> 
> The problem with having declarative languages as a paradigm (which logical
> languages would be a part) is that it feels like it should be a
> "miscellaneous" category.  Being declarative doesn't tell you much except
> that some machine is going to turn your descriptions of something into some
> kind of action.  In logical programming it is a set of predicates, but it
> could just as easily be almost anything else.  In a way all languages are
> "declarative", it is just that we have some standard interpretations of
> what is declared that are very common (imperative and functional).
> 
> My wish is that the idea of there being four paradigms would be abandoned
> the same we the idea of four food groups has been abandoned (which may
> surprise some of you).  We have more than four different modes of thinking
> when programming and some are much more important than others and some are
> subsets of others.  We should teach students a more sophisticated view.
> 
> Ironically Wikipedia also shows us this complexity.  The
> programming language paradigm side bar actually reveals the wealth
> of different styles that are available.  There is simply no clean and
> useful way to overlay the four paradigms over what we see there, so it
> should be abandoned because it gives students a false idea.
> 
> 
> On Wed, Apr 17, 2013 at 9:42 AM, Andreas Abel wrote:
> 
>> [ The Types Forum, http://lists.seas.upenn.edu/**
>> mailman/listinfo/types-list]
>> 
>> On 17.04.2013 11:30, Uday S Reddy wrote:
>> 
>>> Mark Janssen writes:
>>> 
>>> From:  en.wikipedia.org: Programming_paradigm:
 
 "A programming paradigm is a fundamental style of computer
 programming. There are four main paradigms: object-oriented,
 imperative, functional and declarative. Their foundations are distinct
 models of computation: Turing machine for object-oriented and
 imperative programming, lambda calculus for functional programming,
 and first order logic for logic programming."
 
>>> 
>> I removed the second sentence relating paradigms to computation models
>> and put it on the talk page instead.  It does not make sense to connect
>> imperative programming to Turing machines like functional programming to
>> lambda calculus.  A better match would be random access machines, but the
>> whole idea of a connection between a programming paradigm and a computation
>> model is misleading.
>> 
>> 
>> While I understand the interest in purely theoretical models, I wonder
 two things:  1)  Are these distinct models of computation valid?  And,
 2) If so, shouldn't a theory of types announce what model of
 computation they are working from?
 
>>> 
>>> These distinctions are not fully valid.
>>> 
>>> - Functional programming, logic programming and imperative programming are
>>> three different *computational mechanisms*.
>>> 
>>> - Object-orientation and abstract data types are two different ways of
>>> building higher-level *abstractions*.
>>> 
>>> The authors of this paragraph did not understand that computational
>>> mechanisms and higher-level abstractions are separate, orthogonal
>>> dimensions
>>> in programming language design.  All six combinations, obtained by
>>> picking a
>>> computational mechanism from the first bullet and an abstraction mechanism
>>> from the second bullet, are possible.  It is a mistake to put
>>> object-orientation in the first bullet.  Their idea of "paradigm" is vague
>>> and ill-defined.
>>> 
>>> Cheers,
>>> Uday Reddy
>>> 
>>> 
>> 
>> --
>> Andreas Abel  <><  Du bist der geliebte Mensch.
>> 
>> Theoretical Computer Science, Universit

Re: Strange behavior for a 2D list

2013-04-18 Thread Wim R. Cardoen
Thank you all for your replies.
I had the matrix concept in mind such as
explained in the numpy example.

Rob



On Thu, Apr 18, 2013 at 3:19 PM, Wolfgang Maier <
wolfgang.ma...@biologie.uni-freiburg.de> wrote:

> Robrecht W. Uyttenhove  gmail.com> writes:
>
> >
> > Hello,
> > I tried out the following
> code:y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)]
> > >>> y[[0, 1, 2, 3, 4, 5, 6],  [7, 8, 9, 10, 11, 12, 13],
> >   [14, 15, 16, 17, 18, 19, 20],  [21, 22, 23, 24, 25, 26, 27],  [28,
> >
>29, 30, 31, 32, 33, 34]]
> > >>> y[1:5:2][::3]
> > [[7, 8, 9, 10, 11, 12, 13]]
> > I expected the 2D list:[[ 7, 10, 13],
> >  [21, 24, 27]]
> >
> > Any ideas?
> >
> > Thanks,
> > Rob
> > PS: I used Python 2.7.3
> >
>
> The explanation is rather simple, just break up your complex slicing into
> its parts:
> y[1:5:2] => [[7, 8, 9, 10, 11, 12, 13],[21, 22, 23, 24, 25, 26, 27]]
> and [::3] is asking for the first,4th,7th,... element from this list.
> Obviously, only the first one's existing, so [7, 8, 9, 10, 11, 12, 13]
>
> What you expected is kind of vertical slicing through the rows. I don't
> think you can achieve this with slicing alone in standard Python, but it's
> possible with numpy arrays.
> In Python you will have to combine slicing with a comprehension, like this:
> [x[::3] for x in y[1:5:2]]
>
> Best,
> Wolfgang
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
---
Wim R. Cardoen, PhD
Staff Scientist,
Center for High Performance Computing
University of Utah
(801)971-4184

*μὴ μου τοὺς κύκλους τάραττε! (Ἀρχιμήδης)*
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread Terry Reedy

On 4/18/2013 3:21 PM, James Jong wrote:
Thanks Terry. I run the tcl tests and passed them all. There was only 
one tk test that I think I didn't  pass.


One thing I don't understand is that I thought that Python would 
statically link against sqlite and tcl/tk (I presume that this is the 
reason why you said I could build it in a similar system and copy it 
to the supercomputer).


I am not the one who said that. i presume whoever did meant to copy the 
necessary .sos, but I am not using *nix.


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


Re: How to set my gui?

2013-04-18 Thread Tracubik

On 18/04/2013 23:27, John Gordon wrote:

In <5170648d$0$1368$4fafb...@reader2.news.tin.it> Tracubik 
 writes:


i suppose i've to first generate the window and than populate it, but
where i've to put the "search for occurences" code? I don't think init()
is the right place..


What GUI library are you using?



Gtk3 via Glade, anyway the problem is referred to all gui toolkit, isn't 
it?


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


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-18 Thread Chris Angelico
On Fri, Apr 19, 2013 at 6:34 AM, Terry Reedy  wrote:
> On 4/18/2013 3:21 PM, James Jong wrote:
>>
>> Thanks Terry. I run the tcl tests and passed them all. There was only one
>> tk test that I think I didn't  pass.
>>
>> One thing I don't understand is that I thought that Python would
>> statically link against sqlite and tcl/tk (I presume that this is the reason
>> why you said I could build it in a similar system and copy it to the
>> supercomputer).
>
>
> I am not the one who said that. i presume whoever did meant to copy the
> necessary .sos, but I am not using *nix.

I'm the one who was talking about the build/copy. You could manually
copy a bunch of .so, but there's a reasonable chance you wouldn't need
to - in many Linux systems, you have the binary packages for heaps of
things that you don't have the dev libraries (headers, .a files,
whatever) for. At work, we have just one computer on which we build
from C source (which happens to be my personal dev unit as well); all
the other computers - other devs' laptops, staging servers, production
servers - just get binaries deployed directly. There aren't very many
libraries to install on them, as they're fully-functional Linux boxes
already (we use Debian).

It may, of course, be different on your setup, but I figured it was worth a try.

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


Re: How to set my gui?

2013-04-18 Thread Chris Angelico
On Fri, Apr 19, 2013 at 7:36 AM, Tracubik  wrote:
> On 18/04/2013 23:27, John Gordon wrote:
>>
>> In <5170648d$0$1368$4fafb...@reader2.news.tin.it> Tracubik
>>  writes:
>>
>>> i suppose i've to first generate the window and than populate it, but
>>> where i've to put the "search for occurences" code? I don't think init()
>>> is the right place..
>>
>>
>> What GUI library are you using?
>>
>
> Gtk3 via Glade, anyway the problem is referred to all gui toolkit, isn't it?

You're looking here for fairly broad and general advice on GUI code
layout. Unfortunately that's so broad that all I can say is "there are
many ways to do it". :)

Back in the 1990s, I used to (mostly) treat GUI programming as
somewhat different from console programming. I'd use a window-builder,
I'd structure my code in an event loop instead of top-down imperative,
I'd use an IDE rather than simply coding in a text editor. But 1
Corinthians 13:11. These days, GUI programming is to me just
programming and calling on certain libraries/modules. There are many
ways to lay out code, and treating the GUI framework/boilerplate as
the most important is only one of them.

One thing you may want to consider is using your main thread for the
UI, and spinning off another thread to do your search. But do that
ONLY if you know you understand threads, and threading in Python.
Otherwise you'll make your life unnecessarily hard. :)

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


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Mark Janssen
On Mon, Apr 15, 2013 at 2:53 AM, Moez AbdelGawad  wrote:
>> I'm not quite sure I understand your question, but I'll give it a shot.
>> :-)
>
> I'm in this same camp too :)

I am very thankful for the references given by everyone.
Unfortunately my library does not have the titles and it will be some
time before I can acquire them.  I hope it not too intrusive to offer
a few points that I've garnered from this conversation until I can
study the history further.

The main thing that I notice is that there is a heavy "bias" in
academia towards mathematical models.  I understand that Turing
Machines, for example, were originally abstract computational concepts
before there was an implementation in hardware, so I have some
sympathies with that view, yet, should not the "Science" of "Computer
Science" concern itself with how to map these abstract computational
concepts into actual computational hardware?  Otherwise, why not keep
the field within mathematics and philosophy (where Logic traditionally
has been)?   I find it remarkable, for example, that the simple
continued application of And/Or/Not gates can perform all the
computation that C.S. concerns itself with and these form the basis
for computer science in my mind, along with Boolean logic.  (The
implementation of digital logic into physical hardware is where C.S.
stops and Engineering begins, I would argue.)

But still, it seems that there are two ends, two poles, to the whole
computer science enterprise that haven't been sufficiently *separated*
so that they can be appreciated:  logic gates vs. logical "calculus"
and symbols.   There is very little crossover as I can see.  Perhaps
the problem is the common use of the Greek root "logikos"; in the
former, it pertains to binary arithmetic, where in the latter, it
retains it's original Greek pertaining to *speech* and symbols,
"logos").  Further, one can notice that in the former, the progression
has been towards more sophisticated Data Structures (hence the
evolution towards Object-Orientation), where in the latter (I'm
guessing, since it's not my area of expertise) the progression has
been towards function sophistication (where recursion seems to be
paramount).

In any case, I look forward to diving into the books and references
you've all offered so generously so that I can appreciate the field
and its history better.

Mark Janssen
Pacific Lutheran University
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set my gui?

2013-04-18 Thread Walter Hurry
On Fri, 19 Apr 2013 08:00:11 +1000, Chris Angelico wrote:

> But 1 Corinthians 13:11

You are grown up now, I surmise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set my gui?

2013-04-18 Thread Chris Angelico
On Fri, Apr 19, 2013 at 8:57 AM, Walter Hurry  wrote:
> On Fri, 19 Apr 2013 08:00:11 +1000, Chris Angelico wrote:
>
>> But 1 Corinthians 13:11
>
> You are grown up now, I surmise.

:) Born in 1984, so that'll give you some idea where I was in the 1990s.

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


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Ian Kelly
On Thu, Apr 18, 2013 at 4:53 PM, Mark Janssen  wrote:
> The main thing that I notice is that there is a heavy "bias" in
> academia towards mathematical models.  I understand that Turing
> Machines, for example, were originally abstract computational concepts
> before there was an implementation in hardware, so I have some
> sympathies with that view, yet, should not the "Science" of "Computer
> Science" concern itself with how to map these abstract computational
> concepts into actual computational hardware?

Why?  You seem to have a notion that theoretical computer science is
ultimately about programming.  It's not, any more than theoretical
physics is ultimately about how to build skyscrapers.  Theoreticians
don't discuss complicated languages like Python because it would be
difficult to prove anything about computation using them.  Programmers
don't use constructs like Turing machines because they're not
practical or useful for doing actual programming with.  We're talking
about two different groups of people who use different tools because
they have very different objectives.

> Otherwise, why not keep
> the field within mathematics and philosophy (where Logic traditionally
> has been)?

Well now, that's an age-old debate.  Ultimately what we call "computer
science" does not encompass one single discipline.  But I think they
are generally kept under one academic umbrella because they are
closely related, and there is value in working with colleagues in
separate sub-fields.  Certainly there is value in being passingly
familiar with the theory side of things if one is going to be
designing languages and writing parsers.  Less so if one is primarily
occupied with building inventory systems.

> But still, it seems that there are two ends, two poles, to the whole
> computer science enterprise that haven't been sufficiently *separated*
> so that they can be appreciated:  logic gates vs. logical "calculus"
> and symbols.   There is very little crossover as I can see.  Perhaps
> the problem is the common use of the Greek root "logikos"; in the
> former, it pertains to binary arithmetic, where in the latter, it
> retains it's original Greek pertaining to *speech* and symbols,
> "logos").  Further, one can notice that in the former, the progression
> has been towards more sophisticated Data Structures (hence the
> evolution towards Object-Orientation), where in the latter (I'm
> guessing, since it's not my area of expertise) the progression has
> been towards function sophistication (where recursion seems to be
> paramount).

Okay, you've lost me again.  What do logic gates have to do with data
structures and OOP?  What does symbolic logic have to do with
functional programming?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Steven D'Aprano
On Thu, 18 Apr 2013 10:37:17 -0600, Michael Torrie wrote:

> For the record, JavaScript is what they call a "prototype-based
> language."  http://en.wikipedia.org/wiki/Prototype-based_programming.
> You can emulate an OOP system with a prototype-based language.

Prototype languages *are* OOP. Note that it is called OBJECT oriented 
programming, not class oriented, and prototype-based languages are based 
on objects just as much as class-based languages. They are merely two 
distinct models for OOP.




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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Roy Smith
In article <51709740$0$29977$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> On Thu, 18 Apr 2013 10:37:17 -0600, Michael Torrie wrote:
> 
> > For the record, JavaScript is what they call a "prototype-based
> > language."  http://en.wikipedia.org/wiki/Prototype-based_programming.
> > You can emulate an OOP system with a prototype-based language.
> 
> Prototype languages *are* OOP. Note that it is called OBJECT oriented 
> programming, not class oriented, and prototype-based languages are based 
> on objects just as much as class-based languages. They are merely two 
> distinct models for OOP.

One of the nice things about OOP is it means so many different things to 
different people.  All of whom believe with religious fervor that they 
know the true answer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Mark Janssen
> One of the nice things about OOP is it means so many different things to
> different people.  All of whom believe with religious fervor that they
> know the true answer.

Here's a simple rule to resolve the ambiguity.   Whoever publishes
first, gets to claim origin of a word and its usage, kind of like a
BDFL.  The rest can adapt around that, make up their own word, or be
corrected as the community requires.

-- 
MarkJ
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Ned Batchelder

On 4/18/2013 9:24 PM, Mark Janssen wrote:

One of the nice things about OOP is it means so many different things to
different people.  All of whom believe with religious fervor that they
know the true answer.

Here's a simple rule to resolve the ambiguity.   Whoever publishes
first, gets to claim origin of a word and its usage, kind of like a
BDFL.  The rest can adapt around that, make up their own word, or be
corrected as the community requires.



You won't solve the problem of confusing, ambiguous, or conflicting 
terminology by making up a rule.  "Object-oriented" means subtly 
different things to different people.  It turns out that computing is a 
complex field with subtle concepts that don't always fit neatly into a 
categorization.  Python, Java, Javascript, Ruby, Smalltalk, Self, PHP, 
C#, Objective-C, and C++ are all "object-oriented", but they also all 
have differences between them.  That's OK.  We aren't going to make up a 
dozen words as alternatives to "object-oriented", one for each language.


You seem to want to squeeze all of computer science and programming into 
a tidy hierarchy.  It won't work, it's not tidy. I strongly suggest you 
read more about computer science before forming more opinions.  You have 
a lot to learn ahead of you.


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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Mark Janssen
On Thu, Apr 18, 2013 at 7:10 PM, Ned Batchelder  wrote:
> You won't solve the problem of confusing, ambiguous, or conflicting
> terminology by making up a rule.  "Object-oriented" means subtly different
> things to different people.

That's a problem, not a solution.

>  It turns out that computing is a complex field
> with subtle concepts that don't always fit neatly into a categorization.

But that is the point of having a *field*.

> Python, Java, Javascript, Ruby, Smalltalk, Self, PHP, C#, Objective-C, and
> C++ are all "object-oriented", but they also all have differences between
> them.  That's OK.  We aren't going to make up a dozen words as alternatives
> to "object-oriented", one for each language.

Well, you won't, but other people *in the field* already have,
fortunately.  They have names like dynamically-typed,
statically-typed, etc.

> You seem to want to squeeze all of computer science and programming into a
> tidy hierarchy.

No on "squeeze" and "tidy".  Maybe on "hierarchy".

> It won't work, it's not tidy. I strongly suggest you read
> more about computer science before forming more opinions.  You have a lot to
> learn ahead of you.

Okay, professor is it, master?  What is your provenance anyway?

> --Ned.

-- :)



-- 
MarkJ
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Ned Batchelder

On 4/18/2013 10:30 PM, Mark Janssen wrote:

Okay, professor is it, master?  What is your provenance anyway?


I'm not a professor, I'm a software engineer.  I'm just trying to help.  
You've made statements that strike me as half-informed. You're trying to 
unify concepts that perhaps can't or shouldn't be unified.  You've 
posted now to three different mailing lists about your thoughts on the 
nature of programming languages and object-orientation, and have 
apparently had little success in interesting people in them.  A number 
of people have suggested that you study more about the topics you're 
interested in, and I agree with them.


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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Steven D'Aprano
On Thu, 18 Apr 2013 19:30:39 -0700, Mark Janssen wrote:

> On Thu, Apr 18, 2013 at 7:10 PM, Ned Batchelder 
> wrote:
>> You won't solve the problem of confusing, ambiguous, or conflicting
>> terminology by making up a rule.  "Object-oriented" means subtly
>> different things to different people.
> 
> That's a problem, not a solution.

It's a fact, not necessarily a problem.

"Sandwich" means subtly different things to different people in different 
places, but human beings manage to cope, and very few people accidentally 
eat a sandwich of differently doped silicon crystals (i.e. a transistor) 
when they intended to eat a sandwich of bread and cheese.

So long as people recognise the existence and nature of these subtle 
differences, it's all good. Java's OOP model is different from Python's, 
which is different from Lua's, which is different from Smalltalk's. 
That's all grand, they all have their strengths and weaknesses, and if 
all programming languages were the same, there would only be one. (And it 
would probably be PHP.) 


>>  It turns out that computing is a complex field
>> with subtle concepts that don't always fit neatly into a
>> categorization.
> 
> But that is the point of having a *field*.

Reality is the way it is. However we would like fields of knowledge to 
neatly fit inside pigeonholes, they don't.

 
>> Python, Java, Javascript, Ruby, Smalltalk, Self, PHP, C#, Objective-C,
>> and C++ are all "object-oriented", but they also all have differences
>> between them.  That's OK.  We aren't going to make up a dozen words as
>> alternatives to "object-oriented", one for each language.
> 
> Well, you won't, but other people *in the field* already have,
> fortunately.  They have names like dynamically-typed, statically-typed,
> etc.

They are not names for variations of OOP. They are independent of whether 
a language is OOP or not. For example:


Java is statically typed AND object oriented.
Haskell is statically typed but NOT object oriented.

Python is dynamically typed AND object oriented.
Scheme is dynamically typed but NOT object oriented.



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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread rusi
On Apr 19, 3:53 am, Mark Janssen  wrote:
> On Mon, Apr 15, 2013 at 2:53 AM, Moez AbdelGawad  wrote:
> >> I'm not quite sure I understand your question, but I'll give it a shot.
> >> :-)
>
> > I'm in this same camp too :)
>
> I am very thankful for the references given by everyone.
> Unfortunately my library does not have the titles and it will be some
> time before I can acquire them.  I hope it not too intrusive to offer
> a few points that I've garnered from this conversation until I can
> study the history further.


You may want to see this: http://www.infoq.com/presentations/Functional-Thinking


>
> The main thing that I notice is that there is a heavy "bias" in
> academia towards mathematical models.

Yeah wonderful observation. Lets clean up!

If I have a loop:

 while i < len(a) and a[i] != x:
   i++

I need to understand that at the end of the loop:
i >= len(a) or a[i] == x
and not
i >= len(a) and a[i] == x
nor
i == len(a) or a[i] == x  # What if I forgot to initialize i?

Now why bother to teach students such a silly thing (and silly name)
as deMorgan?

So all hail to your project of cleaning up the useless math from CS.
And to whet your appetite for the grandeur and glory of your
visionings why not start with making music schools enroll tone-deaf
students?  Why wasn't Beethoven deaf?

>  I understand that Turing
> Machines, for example, were originally abstract computational concepts
> before there was an implementation in hardware, so I have some
> sympathies with that view, yet, should not the "Science" of "Computer
> Science" concern itself with how to map these abstract computational
> concepts into actual computational hardware?  Otherwise, why not keep
> the field within mathematics and philosophy (where Logic traditionally
> has been)?   I find it remarkable, for example, that the simple
> continued application of And/Or/Not gates can perform all the
> computation that C.S. concerns itself with and these form the basis
> for computer science in my mind, along with Boolean logic.  (The
> implementation of digital logic into physical hardware is where C.S.
> stops and Engineering begins, I would argue.)

You need to study some history (or is that irrelevant like math?)
The Turing who invented the Turing machine in 1936 led the code-
cracking efforts of the allies a couple of years later.
Do you allow for the fact that he may have had abilities that were
common to both aka 'math' 'theory' etc?
Or do you believe that winning wars is a theoretical and irrelevant
exercise?

>
> But still, it seems that there are two ends, two poles, to the whole
> computer science enterprise that haven't been sufficiently *separated*
> so that they can be appreciated:  logic gates vs. logical "calculus"
> and symbols.   There is very little crossover as I can see.  Perhaps
> the problem is the common use of the Greek root "logikos"; in the
> former, it pertains to binary arithmetic, where in the latter, it
> retains it's original Greek pertaining to *speech* and symbols,
> "logos").


Yes there is some truth in what you say.  Just call it logic as object-
language (what you call logic-gates) and logic as meta-language ie
logic for reasoning
[the above line is not sarcastic]



> Further, one can notice that in the former, the progression
> has been towards more sophisticated Data Structures (hence the
> evolution towards Object-Orientation), where in the latter (I'm
> guessing, since it's not my area of expertise) the progression has
> been towards function sophistication (where recursion seems to be
> paramount).

Also good to study the views of one of the doyens of OOP:
http://en.wikipedia.org/wiki/Alexander_Stepanov#Criticism_of_OOP
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Mark Janssen
>> The main thing that I notice is that there is a heavy "bias" in
>> academia towards mathematical models.
>
> Yeah wonderful observation. Lets clean up!
>
> If I have a loop:
>
>  while i < len(a) and a[i] != x:
>i++
>
> I need to understand that at the end of the loop:
> i >= len(a) or a[i] == x
> and not
> i >= len(a) and a[i] == x
> nor
> i == len(a) or a[i] == x  # What if I forgot to initialize i?

You know in my world, we have what's called Input/Output, rather than
punchcards or switchbanks where you come from.  Why not:  "print
i,a[i]".  Done!

> Now why bother to teach students such a silly thing (and silly name)
> as deMorgan?

Well deMorgan falls into BooleanLogic which I'm arguing is distinct
from the the mathematical realm where the lambda calculus wizards come
from.  So that's my camp, thanks.

> So all hail to your project of cleaning up the useless math from CS.

Yes, on useless math, no on *useful* math.  Thanks.

> And to whet your appetite for the grandeur and glory of your
> visionings why not start with making music schools enroll tone-deaf
> students?  Why wasn't Beethoven deaf?

Beethoven was deaf.

> You need to study some history (or is that irrelevant like math?)
> The Turing who invented the Turing machine in 1936 led the code-
> cracking efforts of the allies a couple of years later.
> Do you allow for the fact that he may have had abilities that were
> common to both aka 'math' 'theory' etc?
> Or do you believe that winning wars is a theoretical and irrelevant
> exercise?

Please, I don't dismiss math anymore than a number theorist might
dismiss the realm of complex numbers.

> Yes there is some truth in what you say.  Just call it logic as object-
> language (what you call logic-gates) and logic as meta-language ie
> logic for reasoning

Right, and I'm arguing that there hasn't been enough conceptual
separation between the two.  So why are you arguing?

> Also good to study the views of one of the doyens of OOP:
> http://en.wikipedia.org/wiki/Alexander_Stepanov#Criticism_of_OOP

That's a very good reference.  It voices some of my points that are in
criticism of python's object architecture.
-- 
MarkJ
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding NaN in JSON

2013-04-18 Thread Tim Roberts
Miki Tebeka  wrote:
>
>>> I'm trying to find a way to have json emit float('NaN') as 'N/A'.
>> No.  There is no way to represent NaN in JSON.  It's simply not part of the
>> specification.
>
>I know that. I'm trying to emit the *string* 'N/A' for every NaN.

You understand that this will result in a chunk of text that is not JSON?
Other JSON readers won't be able to read it.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Moez AbdelGawad





> Date: Thu, 18 Apr 2013 15:53:15 -0700
> From: dreamingforw...@gmail.com
> To: types-l...@lists.seas.upenn.edu
> Subject: Re: [TYPES] The type/object distinction and possible synthesis of 
> OOP and imperative programming languages


> 
> I am very thankful for the references given by everyone.
> Unfortunately my library does not have the titles and it will be some
> time before I can acquire them.

The official version of my PhD thesis is available at 
https://scholarship.rice.edu/handle/1911/70199
(A version more suitable for electronic browsing and online distribution is 
available at http://sdrv.ms/15qsJ5x )
-Moez
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding NaN in JSON

2013-04-18 Thread Robert Kern

On 2013-04-19 10:34, Tim Roberts wrote:

Miki Tebeka  wrote:



I'm trying to find a way to have json emit float('NaN') as 'N/A'.

No.  There is no way to represent NaN in JSON.  It's simply not part of the
specification.


I know that. I'm trying to emit the *string* 'N/A' for every NaN.


You understand that this will result in a chunk of text that is not JSON?
Other JSON readers won't be able to read it.


I think he means something like this:

>>> json.dumps([float('nan')])
'["N/A"]'

Not

'[N/A]'

--
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: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-18 Thread Jason Wilkins
I don't quite think I understand what you are saying.  Are you saying that
mathematical models are not a good foundation for computer science because
computers are really made out of electronic gates?

All I need to do is show that my model reduces to some basic physical
implementation (with perhaps some allowances for infinity) and then I can
promptly forget about that messy business and proceed to use my
clean mathematical model.

The reason any model of computation exists is that it is easier to think
about a problem in some terms than in others.  By showing how to transform
one model to another you make it possible to choose exactly how you wish to
solve a problem.

The reason we do not work directly in what are called "von Neumann
machines" is that they are not convenient for all kinds of problems.
 However we can build a compiler to translate anything to anything else so
we I don't see why anybody would care.


On Thu, Apr 18, 2013 at 5:53 PM, Mark Janssen wrote:

> [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list]
>
> On Mon, Apr 15, 2013 at 2:53 AM, Moez AbdelGawad 
> wrote:
> >> I'm not quite sure I understand your question, but I'll give it a shot.
> >> :-)
> >
> > I'm in this same camp too :)
>
> I am very thankful for the references given by everyone.
> Unfortunately my library does not have the titles and it will be some
> time before I can acquire them.  I hope it not too intrusive to offer
> a few points that I've garnered from this conversation until I can
> study the history further.
>
> The main thing that I notice is that there is a heavy "bias" in
> academia towards mathematical models.  I understand that Turing
> Machines, for example, were originally abstract computational concepts
> before there was an implementation in hardware, so I have some
> sympathies with that view, yet, should not the "Science" of "Computer
> Science" concern itself with how to map these abstract computational
> concepts into actual computational hardware?  Otherwise, why not keep
> the field within mathematics and philosophy (where Logic traditionally
> has been)?   I find it remarkable, for example, that the simple
> continued application of And/Or/Not gates can perform all the
> computation that C.S. concerns itself with and these form the basis
> for computer science in my mind, along with Boolean logic.  (The
> implementation of digital logic into physical hardware is where C.S.
> stops and Engineering begins, I would argue.)
>
> But still, it seems that there are two ends, two poles, to the whole
> computer science enterprise that haven't been sufficiently *separated*
> so that they can be appreciated:  logic gates vs. logical "calculus"
> and symbols.   There is very little crossover as I can see.  Perhaps
> the problem is the common use of the Greek root "logikos"; in the
> former, it pertains to binary arithmetic, where in the latter, it
> retains it's original Greek pertaining to *speech* and symbols,
> "logos").  Further, one can notice that in the former, the progression
> has been towards more sophisticated Data Structures (hence the
> evolution towards Object-Orientation), where in the latter (I'm
> guessing, since it's not my area of expertise) the progression has
> been towards function sophistication (where recursion seems to be
> paramount).
>
> In any case, I look forward to diving into the books and references
> you've all offered so generously so that I can appreciate the field
> and its history better.
>
> Mark Janssen
> Pacific Lutheran University
> Tacoma, Washington
>
-- 
http://mail.python.org/mailman/listinfo/python-list