Re: Python-list Digest, Vol 92, Issue 40

2011-05-05 Thread Nico Grubert



PIL will compile and install if you don't have some development
libraries and then simply not work or not work up to full steam when
used.

To avoid this, you need to install the appropriate libraries, among
which are:

libjpeg-devel
freetype-devel
libpng-devel


Dear Albert

Thank you for your reply.
I did install all these libraries.
Testing it with yum shows:

$ yum install libpng-devel
Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and 
latest version
Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and 
latest version


$ yum install libjpeg-devel
Package libjpeg-devel-6b-37.x86_64 already installed and latest version
Package libjpeg-devel-6b-37.i386 already installed and latest version

$ yum install libpng-devel
Package 2:libpng-devel-1.2.10-7.1.el5_5.3.x86_64 already installed and 
latest version
Package 2:libpng-devel-1.2.10-7.1.el5_5.3.i386 already installed and 
latest version



Re-Compiling PIL shows:

$ python setup.py build_ext -i


*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available


However, running the selftest still fails:
$ python selftest.py
*** The _imaging C module is not installed

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


checking if a list is empty

2011-05-05 Thread Jabba Laci
Hi,

If I want to check if a list is empty, which is the more pythonic way?

li = []

(1) if len(li) == 0:
...
or
(2) if not li:
...

Thanks,

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


Re: 回复: Re: BeautifulSoup import error

2011-05-05 Thread James Mills
On Fri, May 6, 2011 at 3:57 PM, Stefan Behnel  wrote:
> No. While this has been suggested, it will not become part of the stdlib in
> the foreseeable future. It's readily available as a separate package on
> PyPI, though.

Opps I meant xml.etree :/
My bad!

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 回复: Re: BeautifulSoup import error

2011-05-05 Thread Stefan Behnel

1011_wxy, 06.05.2011 04:29:

发件人: James Mills

On Fri, May 6, 2011 at 11:37 AM, 1011_wxy wrote:

I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 .
Is there any differences between Python 3.2 and other version? This is my
first time to use Python3.2 .
And the error message will be as below.


Judging from your tracebacks, it would appear
that BeuituflSoup has not yet been ported to
and/or fixed for Python 3 compatibility.


BeautifulSoup does not work well with Python3.2 .


You can try to convert it using 2to3, though.



I might suggest you take a look at using lxml instead


... which works with all Python versions from 2.3 through 3.2.



which ships with the standard library.


No. While this has been suggested, it will not become part of the stdlib in 
the foreseeable future. It's readily available as a separate package on 
PyPI, though.


Stefan

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


Re: Python IDE/text-editor

2011-05-05 Thread JussiJ
On Apr 16, 1:20 pm, Alec Taylor  wrote:

> I'm looking for an IDE which offers syntax-highlighting,
> code-completion, tabs,

The Zeus editor does offers all these features:

http://www.zeusedit.com/

Zeus is also scriptable and Zeus scripts can be written in Python.

Zeus also does Python smart indenting and code folding.

> an embedded interpreter and which is portable

Zeus does not have an embedded Python interpreter, but by using
something like tee.exe it should be possible to emulate this:

http://www.zeusedit.com/zforum/viewtopic.php?t=3156

> (for running from USB on Windows).

Zeus is a Windows editor but it is not a Protable application.

NOTE: Zeus is shareware.

Jussi Jumppanen
Author: Zeus for Windows
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python's library as zip file

2011-05-05 Thread Miki Tebeka
I used py2exe in the past for that, see 
http://www.py2exe.org/index.cgi/ShippingEmbedded
-- 
http://mail.python.org/mailman/listinfo/python-list


回复: Re: BeautifulSoup import error

2011-05-05 Thread 1011_wxy
Dear JM:

Thank you very much.
BeautifulSoup does not work well with Python3.2 .



2011-05-06



Kerry



发件人: James Mills 
发送时间: 2011-05-06 09:47
主 题: Re: BeautifulSoup import error
收件人: python list 



On Fri, May 6, 2011 at 11:37 AM, 1011_wxy <1011_...@163.com> wrote: 
> I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . 
> Is there any differences between Python 3.2 and other version? This is my 
> first time to use Python3.2 . 
> And the error message will be as below. 

Judging from your tracebacks, it would appear 
that BeuituflSoup has not yet been ported to 
and/or fixed for Python 3 compatibility. 

Maybe there's a later version of BeauitifulSOup 
or a development version that does support Python 3? 

There are several Syntax differences between 
Python 2.x and Python 3.x - notably: 

except Exception, e: # Python 2.x 

except Exception as e: # Python 3.x 

I might suggest you take a look at using lxml instead 
which ships with the standard library. 

[ ... ] 

cheers 
James 

--  
-- James Mills 
-- 
-- "Problems are solved by method" 
--  
http://mail.python.org/mailman/listinfo/python-list -- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL: The _imaging C module is not installed

2011-05-05 Thread Albert Hopkins
On Fri, 2011-05-06 at 01:45 +0200, Michel Claveau - MVP wrote:
> Hi!
> 
> > you need to install the appropriate libraries, among which are:
> > libjpeg-devel
> > freetype-devel
> > libpng-devel
> 
> OK, but where can I find it?  I want use PIL with Python under Windows,
> and I can't compile C's sources.
> Should I replace PIL by ImageMagick?

The OP was about CentOS.  I have no idea about Windows.

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


Re: BeautifulSoup import error

2011-05-05 Thread James Mills
On Fri, May 6, 2011 at 11:37 AM, 1011_wxy <1011_...@163.com> wrote:
> I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 .
> Is there any differences between Python 3.2 and other version? This is my
> first time to use Python3.2 .
> And the error message will be as below.

Judging from your tracebacks, it would appear
that BeuituflSoup has not yet been ported to
and/or fixed for Python 3 compatibility.

Maybe there's a later version of BeauitifulSOup
or a development version that does support Python 3?

There are several Syntax differences between
Python 2.x and Python 3.x - notably:

except Exception, e: # Python 2.x

except Exception as e: # Python 3.x

I might suggest you take a look at using lxml instead
which ships with the standard library.

[ ... ]

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


BeautifulSoup import error

2011-05-05 Thread 1011_wxy
Dear friends:

I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 .
Is there any differences between Python 3.2 and other version? This is my first 
time to use Python3.2 .
And the error message will be as below.


>>> from BeautifulSoup import BeautifulSoup
Traceback (most recent call last):
  File "", line 1, in 
from BeautifulSoup import BeautifulSoup
  File "C:\Python32\BeautifulSoup.py", line 448
raise AttributeError, "'%s' object has no attribute '%s'" % 
(self.__class__.__name__, attr)
^
SyntaxError: invalid syntax



And the error place point to BeautifulSoup

class NavigableString(unicode, PageElement):
def __new__(cls, value):
"""Create a new NavigableString.
When unpickling a NavigableString, this method is called with
the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be
passed in to the superclass's __new__ or the superclass won't know
how to handle non-ASCII characters.
"""
if isinstance(value, unicode):
return unicode.__new__(cls, value)
return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)
def __getnewargs__(self):
return (NavigableString.__str__(self),)
def __getattr__(self, attr):
"""text.string gives you text. This is for backwards
compatibility for Navigable*String, but for CData* it lets you
get the string without the CData wrapper."""
if attr == 'string':
return self
else:
raise AttributeError, "'%s' object has no attribute '%s'" % 
(self.__class__.__name__, attr)
def __unicode__(self):
return str(self).decode(DEFAULT_OUTPUT_ENCODING)
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
if encoding:
return self.encode(encoding)
else:
return self


Did I make any mistake?
How can I do this correctly?



2011-05-06



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


Re: Py_XDECREF/Py_DECREF evaluating its argument more than once

2011-05-05 Thread Chris Rebert
On Thu, May 5, 2011 at 5:59 PM, Chris Angelico  wrote:

> Since inline functions are a part of C99 as well as C++, would it be
> possible to have configure.sh detect its availability and optionally
> use that instead of preprocessor macros, or would this run the risk of
> encouraging trickily unportable code?

PEP 7 explicitly says to use C89...

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


Re: Py_XDECREF/Py_DECREF evaluating its argument more than once

2011-05-05 Thread Chris Angelico
Clarification: This IS stated in the source - in object.h are the
following sage words:

---
*** WARNING*** The Py_DECREF macro must have a side-effect-free argument
since it may evaluate its argument multiple times.  (The alternative
would be to mace it a proper function or assign it to a global temporary
variable first, both of which are slower; and in a multi-threaded
environment the global variable trick is not safe.)
---

(I assume that should be "make" not "mace", unless the implication is
that turning a macro into a function involves pounding it into
submission...)

Since inline functions are a part of C99 as well as C++, would it be
possible to have configure.sh detect its availability and optionally
use that instead of preprocessor macros, or would this run the risk of
encouraging trickily unportable code?

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


Py_XDECREF/Py_DECREF evaluating its argument more than once

2011-05-05 Thread Chris Angelico
Okay, this is mainly a tale of a stupid C++ programmer who forgot the
rules of C...

I simplified a whole lot of code recently, cut out some temporary
variables, did some general tidying-up, and then found that my program
was segfaulting occasionally. Sure that I hadn't made any substantive
changes, I went tinkering, and pinned it down to this change:

Old code:
PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0);
if (v) Py_DECREF(v);

New code:

Py_XDECREF(PyRun_StringFlags(code,Py_file_input,py_globals,locals,0));

It's the same, right? Py_XDECREF is just Py_DECREF with a check
against null? No and whoops. DEC and XDEC are both implemented as
*macros* and they evaluate their arguments more than once. (I'm not
entirely sure of the cause of the segfault, but I'm guessing that the
two runs of the code produced different results, or something. Not
significant.)

Would it be possible at some point to have them implemented as inline
functions instead? At the top of my code, I just forced it thus:

#undef Py_XDECREF
inline void Py_XDECREF(PyObject *ob) {if (ob) Py_DECREF(ob);}

Failing that, a warning note on the docs would be nice, but I'm
guessing that idiots like me wouldn't think to read it. (Or if "idiot"
is too strong, try "guy who's been spoiled by C++'s luxury".)

Fortunately for my career, solving this self-created problem didn't
take long, and my boss didn't even know about it till I'd solved it.
*whoops*

Just figured it might be worth mentioning, in case someone else is
tempted to take a shortcut!

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


Re: PIL: The _imaging C module is not installed

2011-05-05 Thread Michel Claveau - MVP
Re!

And why the problem no exist with PIL 1.1.6?  (only 1.1.7)
Is that the version 1.1.6 does not use these libraries?

@+
-- 
Michel Claveau 

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


Re: PIL: The _imaging C module is not installed

2011-05-05 Thread Michel Claveau - MVP
Hi!

> you need to install the appropriate libraries, among which are:
> libjpeg-devel
> freetype-devel
> libpng-devel

OK, but where can I find it?  I want use PIL with Python under Windows,
and I can't compile C's sources.
Should I replace PIL by ImageMagick?

@-salutations
-- 
Michel Claveau 

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


Re: avro slow?

2011-05-05 Thread Stefan Behnel

Dan Stromberg, 06.05.2011 00:36:

Python is often more about programmer efficiency than
machine efficiency.  With cost per MIPS going down and the price of
programmer time going up, it seems a good idea.


Especially when you also count the MIPS improvement during the time it 
takes to write the code.


Stefan

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


Re: avro slow?

2011-05-05 Thread Dan Stromberg
On Thu, May 5, 2011 at 2:12 PM, Miki Tebeka  wrote:

> Greetings,
>
> I'm reading some data from avro file using the avro library. It takes about
> a minute to load 33K objects from the file. This seem very slow to me,
> specially with the Java version reading the same file in about 1sec.
>

You might want to try an apache mailing list, like at
http://avro.apache.org/mailing_lists.html , as I suspect most Python people
use Python's native pickle support instead.

It looks like the Python version of Avro is doing single-byte-at-a-time I/O
for some types, which is almost guaranteed to perform poorly.  If you're
decoding an 8 byte integer, its much faster to at least read 8 bytes and
then chop that up, and better still is to read a buffer at a time and chop
that up too.

Even in C, the performance of byte-at-a-time I/O is not going to be stellar,
especially if you use read() rather than fread().

A related note: Python is often more about programmer efficiency than
machine efficiency.  With cost per MIPS going down and the price of
programmer time going up, it seems a good idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access to some text string in PDFs

2011-05-05 Thread Chris Rebert
On Thu, May 5, 2011 at 2:26 PM, Robert Pazur  wrote:
> Dear all,
> i would like to access some text and count the occurrence as follows >
> I got a lots of pdf with some scientific articles and i want to preview
>  which words are usually related with for example "determinants"
> as an example in the article is a sentence > elevation is the most
> important determinant
> how can i acquire the "elevation" string?
> of course i dont know where the sententence in article is located or which
> particular word could there be
> any suggestions?

Extract the text using PDFMiner[1], pyPdf[2], or PageCatcher[3]. Then
use something similar to n-grams on the extracted text, filtering out
those that don't contain "determinant(s)". Then just keep a word
frequency table for the remaining n-grams.

Not-quite-pseudo-code:
from collections import defaultdict, deque
N = 7 # length of n-grams to consider; tune as needed
buf = deque(maxlen=N)
targets = frozenset(("determinant", "determinants"))
steps_until_gone = 0
word2freq = defaultdict(int)
for word in words_from_pdf:
if word in targets:
steps_until_gone = N
buf.append(word)
if steps_until_gone:
for related_word in buf:
if related_word not in targets:
word2freq[related_word] += 1
steps_until_gone -= 1
for count, word in sorted((v,k) for k,v in word2freq.iteritems()):
print(word, ':', count)

Making this more efficient and less naive is left as an exercise to the reader.
There may very well already be something similar but more
sophisticated in NLTK[4]; I've never used it, so I dunno.

[1]: http://www.unixuser.org/~euske/python/pdfminer/index.html
[2]: http://pybrary.net/pyPdf/
[3]: http://www.reportlab.com/software/#pagecatcher
[4]: http://www.nltk.org/

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Chris Angelico
On Fri, May 6, 2011 at 1:29 AM, Roy Smith  wrote:
> "Hey, let's override operator,() and have some fun"

Destroying sanity, for fun and profit.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Chris Angelico
On Fri, May 6, 2011 at 2:27 AM, Andreas Tawn  wrote:
> If True and False:
>    waveFunction.collapse(cat)
>
>
> That's going to be fun ;o)

If a process crashes and init isn't there to hear it, does it produce
a core dump?

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


Re: Embedding Python's library as zip file

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 2:34 PM, Wojtek Mamrak  wrote:
> Maybe I am missing the point, but I think I am not able to do this.
> When I remove the "Lib" folder and try to run Python.exe, the python
> console window closes rapidly, so that it is hard to read any message
> displayed in it and obvioulsy I can't run any python command. Could
> you clarify this please?

Darn, it worked for me in Python 2.5:

C:\Python25>python
'import site' failed; use -v for traceback
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append(r'C:\Python25\lib.zip')
>>> import site

Although I am also seeing the issue with sys.prefix not getting set
and site-packages not getting added.

But in Python 2.7 I just get:

C:\Python27>python
ImportError: No module named site

C:\Python27>

And in Python 3.2 it causes a full-on crash:

C:\Python32>python
Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

>> What if you put the zip file in your
>> PYTHONPATH environment variable?
>
> I don't have it defined. Maybe it is because I have 2 different Python
> interpreters installed.
> After adding the PYTHONPATH, the Python.exe seems to run normally.
> Unfortunately I am not able to import Image module (I am using it),
> which is installed in site-packages/PIL.
> This happens, because for some reason the site-packages directory is
> not present in sys.path. After reading the site module description I
> checked the sys.prefix and sys.exec_prefix, which are both empty, when
> the Lib folder is loaded from the zip archive. Thats why site-packages
> is not added to sys.path.
> Of course I can add site-packages directory to the sys.path by myself
> (yet I don't know why sys.prefix and sys.exec_prefix are empty),
> however how to deal with the PYTHONPATH, which is required to load
> site.py and hence has to be defined at the very beginning?

Are you calling Py_SetProgramName?  That may help to set sys.prefix
and sys.exec_prefix.  However, looking at site.py, it appears that
it's only looking for proper directories.  I don't think it will be
able to add a site-packages inside a zip archive at all; you will just
have to add that yourself.
-- 
http://mail.python.org/mailman/listinfo/python-list


access to some text string in PDFs

2011-05-05 Thread Robert Pazur
Dear all,
i would like to access some text and count the occurrence as follows >
I got a lots of pdf with some scientific articles and i want to preview
 which words are usually related with for example "determinants"
as an example in the article is a sentence > elevation is the most
important determinant
how can i acquire the "elevation" string?
of course i dont know where the sententence in article is located or which
particular word could there be
any suggestions?
Maybe its easy to solve, but its just one day since I subscribe to this
forum (although i got some Python experience) so i really appreciate any
help!

Kind regards,
Robert.

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


avro slow?

2011-05-05 Thread Miki Tebeka
Greetings,

I'm reading some data from avro file using the avro library. It takes about a 
minute to load 33K objects from the file. This seem very slow to me, specially 
with the Java version reading the same file in about 1sec.

Here is the code, am I doing something wrong?

import avro.datafile
import avro.io
from time import time

def load(filename):
fo = open(filename, "rb")
reader = avro.datafile.DataFileReader(fo, avro.io.DatumReader())
for i, record in enumerate(reader):
pass

return i + 1

def main(argv=None):
import sys
from argparse import ArgumentParser

argv = argv or sys.argv

parser = ArgumentParser(description="Read avro file")


start = time()
num_records = load("events.avro")
end = time()

print("{0} records in {1} seconds".format(num_records, end - start))

if __name__ == "__main__":
main()

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


Re: Embedding Python's library as zip file

2011-05-05 Thread Wojtek Mamrak
> That means it's not finding it.  After startup, try adding the zip
> file to your sys.path and then do "import site" at the command line,
> and it should work.

Maybe I am missing the point, but I think I am not able to do this.
When I remove the "Lib" folder and try to run Python.exe, the python
console window closes rapidly, so that it is hard to read any message
displayed in it and obvioulsy I can't run any python command. Could
you clarify this please?


> What if you put the zip file in your
> PYTHONPATH environment variable?

I don't have it defined. Maybe it is because I have 2 different Python
interpreters installed.
After adding the PYTHONPATH, the Python.exe seems to run normally.
Unfortunately I am not able to import Image module (I am using it),
which is installed in site-packages/PIL.
This happens, because for some reason the site-packages directory is
not present in sys.path. After reading the site module description I
checked the sys.prefix and sys.exec_prefix, which are both empty, when
the Lib folder is loaded from the zip archive. Thats why site-packages
is not added to sys.path.
Of course I can add site-packages directory to the sys.path by myself
(yet I don't know why sys.prefix and sys.exec_prefix are empty),
however how to deal with the PYTHONPATH, which is required to load
site.py and hence has to be defined at the very beginning?


thanks for your help


2011/5/5 Ian Kelly :
> On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak  wrote:
>> Thanks for the reply!
>>
>>> Can you import from zip files when running the Python.exe interpreter?
>> When I zip the folder "Lib" into Python27.zip and later rename it and
>> try to run the python.exe, I receive an error:
>> "Import error: no module named site"
>
> That means it's not finding it.  After startup, try adding the zip
> file to your sys.path and then do "import site" at the command line,
> and it should work.
>
>>> Are you getting any sort of error message?
>> When I run my app, it crashes while calling Py_Initialize(). The
>> console closes suddenly.
>
> Hm, that definitely seems odd.  What if you put the zip file in your
> PYTHONPATH environment variable?
>
>> Is it necessary to create zip archive using zipfile.PyZipFile?
>
> It shouldn't be.  It works for me (at least with Python.exe) creating
> the zip archive using 7-Zip.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Ian Kelly wrote:

On the other hand, the @ syntax is analogous to declaring reference
types in C++ (e.g. "int&" as opposed to "int *").  In both cases you
have to tell the interpreter / compiler that you want to use the
decoration / pass-by-reference feature, and the actual work is done
for you automatically.


[ @Ian, Neil ]

:)... uh, it was worth a shot...

No, I see your point... with the slight small push-back that 
dereferencing a pointer with '*' can't really be called 'work' can it?



( I know, you'll say yes, because the 'compiler' didn't do it ! )


:))



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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 10:58 AM, harrismh777  wrote:
> Grant Edwards wrote:
>>
>> That's what I was trying to say, but probably not as clearly.  The "&"
>> operatore returnas a_value_  that the OP passes_by_value_  to a
>> function.  That function then uses the "*" operator to use that value
>> to access some data.
>
> I'm gonna try a D'Aprano-style bogus argument for a moment...
>
> ... saying that 'C' does not support pass-by-reference because you have to
> direct the compiler with the '&' and '*' characters is a little like saying
> that
>
>     Python does not support decorations ! ...
>
>
> ...  because you have to direct the interpreter with some
>
>
> @ bogus-decorator-syntax
>
>
>     I want Python to support decorations automatically !

It seems to me that manually referencing and dereferencing in C is
more akin to decorating functions like this:

def foo(x):
do_stuff()

foo = decorate(foo)

On the other hand, the @ syntax is analogous to declaring reference
types in C++ (e.g. "int &" as opposed to "int *").  In both cases you
have to tell the interpreter / compiler that you want to use the
decoration / pass-by-reference feature, and the actual work is done
for you automatically.
-- 
http://mail.python.org/mailman/listinfo/python-list


Employment Opportunity in Chicago

2011-05-05 Thread Wok-Thee-Recruiter
Python Developer

Looking for a candidate with hands on Python development experience to
work for a fast growing company that provides in-flight broadband
services.

•   This person will be working on portal development and optimizing
plane systems.
•   Help integrate third party products such as video and other products
pertaining to aviation.
•   Candidate should have a minimum of 5-7 years of experience.
•   Position reports directly into the CTO


Requirements
•   5-7 years of full software development lifecycle experience
•   2-3 years of Python development
•   2-3 years of SQL experience
•   MySQL
•   Database configuration

Send emails to jba...@pt-corp.com or call Joaquin direct at
312-643-2010
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Terry Reedy

On 5/5/2011 9:19 AM, Neil Cerutti wrote:

On 2011-05-04, John Nagle  wrote:

That's a quirk of CPython's boxed number implementation.   All
integers are boxed, but there's a set of canned objects for
small integers.  CPython's range for this is -5 to +256,
incidentally.  That's visible through the "is" operator.
Arguably, it should not be.


But that's the sole purpose of the is operator. You either expose
those details, or you don't have an is operator at all.


Which is to say, the CPython testsuite has a CPython-specific 
implementation test that uses 'is' to test that implementation detail.


--
Terry Jan Reedy

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Neil Cerutti
On 2011-05-05, harrismh777  wrote:
> ... saying that 'C' does not support pass-by-reference because
> you have to direct the compiler with the '&' and '*' characters
> is a little like saying that
>
>   Python does not support decorations ! ...
>
>
> ...  because you have to direct the interpreter with some
>
>
> @ bogus-decorator-syntax
>
>
>   I want Python to support decorations automatically !

You do have to declare decorators when defining them, but they
are called automatically when you call the decorated function,
with no special syntax required. C pointers don't automatically
dereference themselves.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Ethan Furman wrote:

PS
My thanks to those who kept explaining in various ways about the
difference between language supported features and programmer constructs
-- I hadn't realized before this thread that call-by-reference was not a
language feature of C, but rather a programmer-implemented feature using
the C operators.


   You are most welcome.   :)



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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Ethan Furman

harrismh777 wrote:

Grant Edwards wrote:

I give up.  You don't seem to understand the C language defintion or
what is commonly meant by "pass by reference".



ah, don't give up... here is a link that might help to clarify some of 
these semantics...   me thinks:


http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value


Indeed it does (emphasis added):

"In call-by-reference evaluation (also referred to as 
pass-by-reference), a function receives an *implicit* reference to a 
variable used as argument"


In C the the reference is explicit, which the article states in the next 
paragraph:


"Even among languages that don't exactly support call-by-reference, 
many, including C and ML, support explicit references (objects that 
refer to other objects), such as pointers"


~Ethan~

PS
My thanks to those who kept explaining in various ways about the 
difference between language supported features and programmer constructs 
-- I hadn't realized before this thread that call-by-reference was not a 
language feature of C, but rather a programmer-implemented feature using 
the C operators.

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


Re: Need to solve the "Stateless HTTP" problem

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 8:22 AM, Gnarlodious  wrote:
> My scripting has grown to the point where the Apache server is a
> problem. My Python websites run and quit, which means I need to save
> data and recreate everything next page load. Bulky and slow. What is
> the simplest solution?
>
> I am running Py3 on OSX Server with Apache 2. Essentially I want
> certain objects to be a "constantly running process" that may timeout
> after some disuse. I suspect there are already systems for it. Please
> advise in simple terms, I am not a professional.

It sounds to me like you're currently running your Python scripts as
CGIs?  You should look into running your scripts via mod_wsgi in
daemon mode, which will do exactly what you are asking.  See here:

http://code.google.com/p/modwsgi/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Grant Edwards wrote:

No, that's_not_  automatic if you have to do it yourself.  It's
automatic when it happens without user-intervention.

Now I think you're trolling...


... no, I was only kidding... :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Grant Edwards wrote:

That's what I was trying to say, but probably not as clearly.  The "&"
operatore returnas a_value_  that the OP passes_by_value_  to a
function.  That function then uses the "*" operator to use that value
to access some data.


I'm gonna try a D'Aprano-style bogus argument for a moment...

... saying that 'C' does not support pass-by-reference because you have 
to direct the compiler with the '&' and '*' characters is a little like 
saying that


 Python does not support decorations ! ...


...  because you have to direct the interpreter with some


@ bogus-decorator-syntax


 I want Python to support decorations automatically !


;-)




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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Neil Cerutti  wrote:
> On 2011-05-05, Roy Smith  wrote:
>> Of course, C++ lets you go off the deep end with abominations
>> like references to pointers.  Come to think of it, C++ let's
>> you go off the deep end in so many ways...
>
> But you can do some really cool stuff in the deep end.

Until you get pulled under and drowned by some flailing goof who
oughtn't be there.

-- 
Grant Edwards   grant.b.edwardsYow! Zippy's brain cells
  at   are straining to bridge
  gmail.comsynapses ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Roy Smith  wrote:
> In article ,
>  Grant Edwards  wrote:
>
>> That's what I was trying to say, but probably not as clearly.  The "&"
>> operatore returnas a _value_ that the OP passes _by_value_ to a
>> function.  That function then uses the "*" operator to use that value
>> to access some data.
>
> Then, of course, there's references in C++.  I think it's fair to call 
> the following "call by reference" in the sense we're talking about it 
> here.
>
> void f(int& i) {
>i = 5;
> }
> int i = 42;
> f(i);

If after the call to f(i) the caller sees that i == 5, then that's
call by reference.  But, we were talking about C.

> Of course, C++ lets you go off the deep end with abominations like 
> references to pointers.  Come to think of it, C++ let's you go off
> the deep end in so many ways...

:)

-- 
Grant Edwards   grant.b.edwardsYow! Is this sexual
  at   intercourse yet??  Is it,
  gmail.comhuh, is it??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, harrismh777  wrote:
> Steven D'Aprano wrote:
>> In fairness, he's not the only one. M Harris has twice now linked to an
>> IBM site that describes pass-by-reference in C in terms of passing a
>> pointer to the argument you want as the argument. Admittedly, doing so
>> gives you almost the same behaviour, except that you have to dereference
>> the pointers yourself.
>>
>> That's a pretty big difference though, and gets to the core of the
>> argument: it's a bit like arguing that manual cars are fitted with
>> exactly the same automatic transmission as auto cars, it's just that you
>> have to engage the clutch and shift gears yourself.
>
>
> ... and actually, if you feel it just right and you have just the
> right synchro-mesh setup, you can slide from 3rd into 4th without
> every touching the clutch peddle...

That's possible on pretty much any modern automotive or small-truck
transmission, and it's not really that hard to do.  I can go from 1st
up to 5th and back down to 1st without touching the clutch.  I don't
as a habit do it, because it puts unnecessary wear on the syncros (and
I've had cars with pretty weak syncros -- Alfa-Romeo Spyders were
famous for the 2nd gear syncro wearing out).

> and if that isn't automatic, I don't know what is

No, that's _not_ automatic if you have to do it yourself.  It's
automatic when it happens without user-intervention.

Now I think you're trolling...

-- 
Grant Edwards   grant.b.edwardsYow! I want to dress you
  at   up as TALLULAH BANKHEAD and
  gmail.comcover you with VASELINE and
   WHEAT THINS ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Steven D'Aprano  wrote:
> On Thu, 05 May 2011 14:14:22 +, Grant Edwards wrote:
>
>> On 2011-05-05, harrismh777  wrote:
>>> Grant Edwards wrote:
 The "pass by value" and "pass by reference" parameter passing
 mechanisms are pretty well defined, and C uses "pass by value".
>>>
>>> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that
>>> helped define them
>> 
>> I give up.  You don't seem to understand the C language defintion or
>> what is commonly meant by "pass by reference".
>
>
> In fairness, he's not the only one. M Harris has twice now linked to an 
> IBM site that describes pass-by-reference in C in terms of passing a 
> pointer to the argument you want as the argument. Admittedly, doing so 
> gives you almost the same behaviour, except that you have to dereference 
> the pointers yourself.
>
> That's a pretty big difference though, and gets to the core of the 
> argument: it's a bit like arguing that manual cars are fitted with 
> exactly the same automatic transmission as auto cars, it's just that
> you have to engage the clutch and shift gears yourself.

I like that analogy.

   "My car has an automatic transmission except you have to shift
gears yourself with that lever and that it has a clutch operated
by that pedal instead of a hydrostatic torque converter."

-- 
Grant Edwards   grant.b.edwardsYow! ... bleakness
  at   ... desolation ... plastic
  gmail.comforks ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 9:41 AM, John Nagle  wrote:
> On 5/5/2011 3:06 AM, Gregory Ewing wrote:
>>
>> John Nagle wrote:
>>
>>> A reasonable compromise would be that "is" is treated as "==" on
>>> immutable objects.
>>
>> That wouldn't work for tuples, which can contain references
>> to other objects that are not immutable.
>
>    Such tuples are still identical, even if they
> contain identical references to immutable objects.

>>> a = (1, 2, [3, 4, 5])
>>> b = (1, 2, [3, 4, 5])
>>> a == b
True
>>> a is b  # Using the proposed definition
True
>>> a[0] is b[0]
True
>>> a[1] is b[1]
True
>>> a[2] is b[2]
False
>>> a[2].append(6)
>>> a
(1, 2, [3, 4, 5, 6])
>>> b
(1, 2, [3, 4, 5])
>>> a == b
False
>>> a is b
False

Thus a and b cannot be used interchangeably even though "a is b"
originally returned True.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: What other languages use the same data model as Python?

2011-05-05 Thread Andreas Tawn
> Steven D'Aprano wrote:
> 
> > Some day, we'll be using quantum computers without memory addresses,
> [ ...
> ] it will still be possible to
> > represent data indirectly via *some* mechanism.
> 
> :)  Cool!  Pass-by-coincidence!  And Python 3 already has dibs on the
> 'nonlocal' keyword!
> 
>   Mel.
> 

If True and False:
waveFunction.collapse(cat)


That's going to be fun ;o)

Cheers,

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


Re: Need to solve the "Stateless HTTP" problem

2011-05-05 Thread Miki Tebeka
> Essentially I want
> certain objects to be a "constantly running process" that may timeout
> after some disuse.
memcached?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Grant Edwards wrote:

I give up.  You don't seem to understand the C language defintion or
what is commonly meant by "pass by reference".



ah, don't give up... here is a link that might help to clarify some of 
these semantics...   me thinks:


http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_value




kind regards,
m harris

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


Re: [OT] From svn to something else?

2011-05-05 Thread buck
This is what made me choose Mercurial in my recent search.

http://www.python.org/dev/peps/pep-0374/

There is a tremendous amount of detail there. In summary, hg and git are both 
very good, and essentially equal in features. The only salient difference is 
that  hg is implemented in python, so they went with that. I did the same, and 
I'm quite happy. It's basically svn with the shiny new distributed features 
added.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Steven D'Aprano wrote:

In fairness, he's not the only one. M Harris has twice now linked to an
IBM site that describes pass-by-reference in C in terms of passing a
pointer to the argument you want as the argument. Admittedly, doing so
gives you almost the same behaviour, except that you have to dereference
the pointers yourself.

That's a pretty big difference though, and gets to the core of the
argument: it's a bit like arguing that manual cars are fitted with
exactly the same automatic transmission as auto cars, it's just that you
have to engage the clutch and shift gears yourself.



... and actually, if you feel it just right and you have just the right 
synchro-mesh setup, you can slide from 3rd into 4th without every 
touching the clutch peddle... and if that isn't automatic, I don't know 
what is   man those were the days... now I just press a button that 
says, "Auto 4-wheel Lock", set the gps, and take a nap...



:)


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


Re: Development tools and practices for Pythonistas

2011-05-05 Thread buck
I use hg for even 50-line standalone python scripts. It's very well suited to 
these small environments, and scales up nicely.


cd /my/working/dir
hg init
hg add myscript.py
hg ci -m 'added myscript'

It's that simple, and now hyou can go back if you make a terrible mistake, and 
you can post it to bitbucket and share with the world if you like, almost as 
easily.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread John Nagle

On 5/5/2011 6:59 AM, Steven D'Aprano wrote:

On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote:


On Thu, May 5, 2011 at 9:44 PM, Mel  wrote:

John Nagle wrote:

On 5/4/2011 5:46 PM, harrismh777 wrote:

Or, as stated earlier, Python should not allow 'is' on immutable
objects.


 A reasonable compromise would be that "is" is treated as "==" on
immutable objects.


I foresee trouble testing among float(5), int(5), Decimal(5) ...


Define 'x is y' as 'type(x)==type(y) and
isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then.


   That's close to the right answer.


`is` is supposed to be a *fast* operator, not even slower than equality
testing.


   That's an implementation problem.  Those are cheap tests at the
machine code level.  An efficient test looks like this:

def istest(a, b) :
if id(a) == id(b) : # the cheap address test
return(True)
if type(x) != type(y) : # cheap binary comparison
return(False)
if mutable(x) : # the interpreter knows this
return(False)
return(x == y)  # equality test for mutables

Probably about 12 machine instructions, and the full "==" test
is only reached for cases in which "is" now produces wrong answers.

It's encouraging that a Google code search finds no matches of

if .* is \"
or
if .* is 1

in Python code.

John Nagle




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


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Mel wrote:

represent data indirectly via*some*  mechanism.

:)   Cool!  Pass-by-coincidence!  And Python 3 already has dibs on the
'nonlocal' keyword!



I was thinking pass-by-osmosis   :)


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Thu, 05 May 2011 07:43:59 +1000, Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> Given the following statement of Python code:
>>
>> >>> x = "spam"
>>
>> what is the value of the variable x?
> 
> Mu (無).
> 
> ‘x’ is a name. Names are bound to values. Talk of “variable” only
> confuses the issue because of the baggage carried with that term.

Yes, good point. Consider me chastised, because I actually knew that. 
It's just that the term "variable" is so useful and so familiar that it's 
easy to use it even for languages that don't have variables in the C/
Pascal/Fortran/etc sense.


> But the data model of Python doesn't fit well with the ideas that the
> term “variable” connotes for most programmers: a box, perhaps of a rigid
> shape (data type) or not, which is labelled ‘x’ and nothing else. For
> another variable to have an equal value, that value needs to be copied
> and put in a separate box; or perhaps some special reference to the
> original needs to be made and placed in a box.
> 
> Saying “variable” and “has the value” just invites baggage needlessly,
> and creates many assumptions about Python's data model which has to be
> un-done, often after much false mental scaffolding has been built on
> them by the newbie and needs to be dismantled carefully.

I've quoted your two paragraphs because I think they're very important, 
not because I intend arguing. Possibly a first for me :)

However 

> Python isn't pass by anything. Nothing gets copied, nothing gets passed;
> when a function is called with an object as a parameter, the object
> stays put, and simply gets a new temporary name bound to it for the
> function's use.

This, however, is incorrect. "Passing" in this sense refers to calling 
the function with an argument, hence "pass by..." and "call by..." are 
synonyms. The mechanics of how the compiler or interpreter makes 
arguments available to functions has real consequences at the language 
level: the calling strategy used by the compiler effects the language 
semantics.


>> > Whatever, a rose by any other name...)
>>
>> Do you really think that roses would be the symbol of romantic love if
>> they were called "disgusting stink-weeds of perversion and death"?
> 
> Juliet's point stands, though: they would still smell as sweet, and the
> term you describe would be unlikely to catch on since it doesn't
> describe them well at all.

Perhaps a counter-example is that of the tomato, which never took off as 
a food in Europe until people stopped calling them "love apples", and 
thinking that they were deadly poison.

Or Chinese Gooseberries, better known by the name thought up by a 
marketing firm, "kiwi fruit".


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread John Nagle

On 5/5/2011 3:06 AM, Gregory Ewing wrote:

John Nagle wrote:


A reasonable compromise would be that "is" is treated as "==" on
immutable objects.


That wouldn't work for tuples, which can contain references
to other objects that are not immutable.


Such tuples are still identical, even if they
contain identical references to immutable objects.

John Nagle


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


Re: Embedding Python's library as zip file

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak  wrote:
> Thanks for the reply!
>
>> Can you import from zip files when running the Python.exe interpreter?
> When I zip the folder "Lib" into Python27.zip and later rename it and
> try to run the python.exe, I receive an error:
> "Import error: no module named site"

That means it's not finding it.  After startup, try adding the zip
file to your sys.path and then do "import site" at the command line,
and it should work.

>> Are you getting any sort of error message?
> When I run my app, it crashes while calling Py_Initialize(). The
> console closes suddenly.

Hm, that definitely seems odd.  What if you put the zip file in your
PYTHONPATH environment variable?

> Is it necessary to create zip archive using zipfile.PyZipFile?

It shouldn't be.  It works for me (at least with Python.exe) creating
the zip archive using 7-Zip.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Mel
Steven D'Aprano wrote:

> Some day, we'll be using quantum computers without memory addresses, [ ... 
] it will still be possible to
> represent data indirectly via *some* mechanism.

:)  Cool!  Pass-by-coincidence!  And Python 3 already has dibs on the 
'nonlocal' keyword!

Mel.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Roy Smith
In article <92fsvjfkg...@mid.individual.net>,
 Neil Cerutti  wrote:

> On 2011-05-05, Roy Smith  wrote:
> > Of course, C++ lets you go off the deep end with abominations
> > like references to pointers.  Come to think of it, C++ let's
> > you go off the deep end in so many ways...
> 
> But you can do some really cool stuff in the deep end.

"Hey, let's override operator,() and have some fun"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Wed, 04 May 2011 09:18:56 -0700, Devin Jeanpierre wrote:

> On May 4, 9:44 am, Hans Georg Schaathun  wrote:
>> :   The only twist is that you never get to dereference : 
>> pointers in Python, but you can in C. Not much of a twist if you ask : 
>> me, but then again, I've been thinking in thismodelfor years. Maybe : 
>> I'm brainwashed. :)
>>
>> You are.  You explain Python in terms of C.  That's useful when you
>> talk to other speakers of C.
>>
>> If you want to explain the language to a broader audience, you should
>> use terminology from the language's own level of abstraction.
> 
> No, I explained Python in terms of pointers/reference.

Python has no pointers or references unless you simulate them yourself 
using other data types.

They exist as implementation details of the Python virtual machine, which 
is at least two levels below that of Python code. The first is the byte 
code which runs in the virtual machine; the second is the code in the VM.



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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Thu, 05 May 2011 14:14:22 +, Grant Edwards wrote:

> On 2011-05-05, harrismh777  wrote:
>> Grant Edwards wrote:
>>> The "pass by value" and "pass by reference" parameter passing
>>> mechanisms are pretty well defined, and C uses "pass by value".
>>
>> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that
>> helped define them
> 
> I give up.  You don't seem to understand the C language defintion or
> what is commonly meant by "pass by reference".


In fairness, he's not the only one. M Harris has twice now linked to an 
IBM site that describes pass-by-reference in C in terms of passing a 
pointer to the argument you want as the argument. Admittedly, doing so 
gives you almost the same behaviour, except that you have to dereference 
the pointers yourself.

That's a pretty big difference though, and gets to the core of the 
argument: it's a bit like arguing that manual cars are fitted with 
exactly the same automatic transmission as auto cars, it's just that you 
have to engage the clutch and shift gears yourself.


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Neil Cerutti
On 2011-05-05, Roy Smith  wrote:
> Of course, C++ lets you go off the deep end with abominations
> like references to pointers.  Come to think of it, C++ let's
> you go off the deep end in so many ways...

But you can do some really cool stuff in the deep end.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Wed, 04 May 2011 16:22:42 -0600, Ian Kelly wrote:

> However, I hope we can all agree that pass-by-pointer shares certain
> features with both pass-by-value and pass-by-reference, and there are
> perfectly reasonable arguments for lumping it in either category, yes?

*cries*

Please don't invent another "pass by foo" term

Seriously though, "pass by foo" refers to what the compiler or 
interpreter does when you, the coder, call a function with some variable, 
say, x:

f(x)

It is not referring to what you, the coder, does when you want to pass an 
indirect reference of some sort to a chunk of data to some function. In 
many languages, you would use a pointer, and write the function call 
something like this:

f(^x)

(using Pascal's up-arrow notation for "pointer to").

Such "pass by pointer" is a tactic used by the coder, as opposed to a 
language feature.

I believe this distinction between what the compiler does, and what the 
coder does, is at the heart of much confusion. Pointers that are passed 
as arguments are themselves data, just as much as ints or floats, or (in 
languages that have first-class functions) functions.



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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Wed, 04 May 2011 14:58:38 -0500, harrismh777 wrote:

> Benjamin Kaplan wrote:
>> CPython is implemented in C because that's the language chosen. Python
>> is also implemented in Java, C#, Python, and several other languages.
> 
>  True enough. If I used Jython, I would want to take a look at those
> sources... as well as the Java sources... which were wrtten in, um,  C.

No, Java sources are written in Java. That's why they're *Java* sources.

Perhaps you mean that the Java compiler is written in C? Highly unlikely: 
Java compilers have been self-hosting for many years now.

http://en.wikipedia.org/wiki/Self-hosting




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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Roy Smith
In article <4dc29cdd$0$29991$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> C is better described as a high-level assembler, or a low-level language. 
> It is too close to the hardware to describe it as high-level, it has no 
> memory management, few data abstractions, and little protection.

+1

I (and most people who really know C and the specific hardware 
architecture they're working on) should be able to look at a C program 
and (modulo optimization) pretty much be able to write down the 
generated assembler by hand.  In fact, I used to do exactly that.  I was 
once working on M-6800 hardware (8/16-bit microprocessor).  I used to 
write out procedures in C, then hand-compile it into assembler code (and 
leave the C code as a comment).  I wasn't a true masochist, however.  I 
did let an assembler convert it to hex for me before I keyed it in :-)

On the other hand, trying to do that for something like C++ is damn near 
impossible.  There's too much stuff that happens by magic.  Creation 
(and destruction) of temporary objects.  Exception handling.  RTTI.  Not 
to mention truly black magic like template expansion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to solve the "Stateless HTTP" problem

2011-05-05 Thread Chris Angelico
On Fri, May 6, 2011 at 12:22 AM, Gnarlodious  wrote:
> My scripting has grown to the point where the Apache server is a
> problem. My Python websites run and quit, which means I need to save
> data and recreate everything next page load. Bulky and slow. What is
> the simplest solution?
>
> I am running Py3 on OSX Server with Apache 2. Essentially I want
> certain objects to be a "constantly running process" that may timeout
> after some disuse. I suspect there are already systems for it. Please
> advise in simple terms, I am not a professional.

Depending on how much of Apache's featureset you're using, it may be
easiest to set it aside altogether and just run a Python HTTP server.
Then you can maintain as much state as you like.

But if you're currently hosting multiple sites and distinguishing
between them using Host: headers (using NameVirtualHost), then you'd
have to change them all, which probably wouldn't be worthwhile.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread harrismh777

Steven D'Aprano wrote:

You should read Paul Graham on the Blub Paradox:

http://www.paulgraham.com/avg.html



Excellent-!   ... thanks, fun article.


...  where is that lisp manual anyway?  ... oh, yeah, emacs!



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


Re: Need to solve the "Stateless HTTP" problem

2011-05-05 Thread garabik-news-2005-05
Gnarlodious  wrote:
> My scripting has grown to the point where the Apache server is a
> problem. My Python websites run and quit, which means I need to save
> data and recreate everything next page load. Bulky and slow. What is
> the simplest solution?

Karrigell?
-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Today's fun and educational Python recipe

2011-05-05 Thread nn
On May 4, 2:17 pm, Raymond Hettinger  wrote:
> Here's a 22-line beauty for a classic and amazing 
> algorithm:http://bit.ly/bloom_filter
>
> The wiki article on the algorithm is brief and 
> well-written:http://en.wikipedia.org/wiki/Bloom_filter
>
> It turns out that people in the 1970's were pretty smart :-)
>
> Raymond
>
> ---
> follow my other python tips and recipes on twitter:  @raymondh

Very cool! Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Steven D'Aprano  wrote:
> On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote:
>
>> Here is the thing that everyone forgets... all we have to work with
>> is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc).
>
> Actually, this is incorrect. Most processors these days are hybrids 
> between that and either the Harvard or Modified Harvard architecture:
>
> http://en.wikipedia.org/wiki/Modified_Harvard_architecture
> http://en.wikipedia.org/wiki/Harvard_architecture
> http://en.wikipedia.org/wiki/Von_Neumann_architecture

And a lot of the are still full-up Harvard architecture (e.g. the
entire Atmel AVR family and Intel 8051 family for example).

-- 
Grant Edwards   grant.b.edwardsYow! When this load is
  at   DONE I think I'll wash it
  gmail.comAGAIN ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Roy Smith
In article ,
 Grant Edwards  wrote:

> That's what I was trying to say, but probably not as clearly.  The "&"
> operatore returnas a _value_ that the OP passes _by_value_ to a
> function.  That function then uses the "*" operator to use that value
> to access some data.

Then, of course, there's references in C++.  I think it's fair to call 
the following "call by reference" in the sense we're talking about it 
here.

void f(int& i) {
   i = 5;
}
int i = 42;
f(i);

Of course, C++ lets you go off the deep end with abominations like 
references to pointers.  Come to think of it, C++ let's you go off the 
deep end in so many ways...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Gregory Ewing  wrote:
> harrismh777 wrote:
>> 'C'  is still the best high-level language on that processor.
>
> Some would argue that C is actually better than assembler these
> days, because modern architectures are so freaking complicated
> that it takes a computer to figure out the best instruction
> sequence. :-(

Been there, done that.

Many years ago, it took me more than a week (and required the help of
an ARM instruction set guru) to come up with an assembly language IP
checksum routine for the ARM that out-performed the somewhat naive
NetBSD "C" version.  When we switched to the FreeBSD stack (and a
newer compiler) a few years later, my assembly code got tossed out
because was no longer any faster than the C version.

-- 
Grant Edwards   grant.b.edwardsYow! Half a mind is a
  at   terrible thing to waste!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, harrismh777  wrote:
> Dennis Lee Bieber wrote:
>>> >  We do not consider passing a pointer as*by value*  because its an
>>> >  address; by definition, that is pass-by-reference. We are not passing
>>  To most of the world, pass-by-reference means the COMPILER, not the
>> PROGRAMMER is obtaining and passing the address, and the compiler also
>> always dereferences the passed "value"... The programmer has no control
>> over whether to operate on the address or the data referenced by the
>> address.
>
> Who is "most of the world" ?

Pretty much everybody except you.


Please see:

> http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr233.htm

Yea, I read that.  It doesn't support your argument.  It agrees with
the rest of the world.

-- 
Grant Edwards   grant.b.edwardsYow! I need to discuss
  at   BUY-BACK PROVISIONS
  gmail.comwith at least six studio
   SLEAZEBALLS!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Gregory Ewing  wrote:
> Hans Georg Schaathun wrote:
>> Is transmission by name the same as call by object?
>
> No, it's not. With call-by-name, the caller passes a
> small function (known as a "thunk") that calculates the
> address of the parameter. Every time the callee needs to
> refer to the parameter, it evaluates this function.
>
> This allows some neat tricks, but it's massive overkill for most
> uses.

It also is a very good source of surprising bugs.

-- 
Grant Edwards   grant.b.edwardsYow! I feel like I'm
  at   in a Toilet Bowl with a
  gmail.comthumbtack in my forehead!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Need to solve the "Stateless HTTP" problem

2011-05-05 Thread Gnarlodious
My scripting has grown to the point where the Apache server is a
problem. My Python websites run and quit, which means I need to save
data and recreate everything next page load. Bulky and slow. What is
the simplest solution?

I am running Py3 on OSX Server with Apache 2. Essentially I want
certain objects to be a "constantly running process" that may timeout
after some disuse. I suspect there are already systems for it. Please
advise in simple terms, I am not a professional.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, harrismh777  wrote:
> Tim Roberts wrote:
>> The fact that the parameter "a"
>> in BumpMe happens to be an address is completely irrelevent to the
>> definition of the parameter passing mechanism.
>>
>> C has pass-by-value, exclusively.  End of story.
>
> Yeah, Tim, I know... but that's my entire point in a nut-shell... 
> whether the language is pass-by-value or pass-by-reference has less to 
> do with how it is 'defined' (its mechanism--- indirection and stack)

No, whether the _language_ is pass by value or pass-by-reference has 
_entirely_ to do with it's definition.

> and more to do with how it is routinely used with the standard
> features it provides--- in this case memory indirection--- as
> pointers.

Now you're talking about how you can implement higher level constructs
using a language that doesn't directly implement such constructs.  You
might as well say that C is a linked-list language like Lisp since you
can write a linked list implementation in C.  If you said that you'd
be just as wrong as saying that C uses call-by-reference.

-- 
Grant Edwards   grant.b.edwardsYow! I want another
  at   RE-WRITE on my CEASAR
  gmail.comSALAD!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL: The _imaging C module is not installed

2011-05-05 Thread Albert Hopkins
Oh I forgot to say, after installing these libraries, you will need to
re-compile (install) PIL.

-a


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, Gregory Ewing  wrote:
> harrismh777 wrote:
>> 'C' does provide for pointers which are used by all 'C' 
>> programmers to firmly provide pass-by-reference in their coding
>
> Yes, but when they do that, they're building an abstraction
> of their own on top of the facilities provided by the C
> language.

I've pointed that out to him.  He's talking about what _he_ does in
his program.  We're talking about the C language definition and what
the compiler does.

> C itself has no notion of pass-by-reference.

Exactly.  C is pass by value.

> If it did, the programmer would be able to use it directly
> instead of having to insert & and * operators himself.

That's what I was trying to say, but probably not as clearly.  The "&"
operatore returnas a _value_ that the OP passes _by_value_ to a
function.  That function then uses the "*" operator to use that value
to access some data.

-- 
Grant Edwards   grant.b.edwardsYow! DIDI ... is that a
  at   MARTIAN name, or, are we
  gmail.comin ISRAEL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL: The _imaging C module is not installed

2011-05-05 Thread Albert Hopkins
On Thu, 2011-05-05 at 15:35 +0200, Nico Grubert wrote:
> Hi there
> 
> I am having trouble to install PIL 1.1.7 on CentOS.
> 
> I read and followed the instructions from
> http://effbot.org/zone/pil-imaging-not-installed.htm
> 
> However, I still get the "The _imaging C module is not installed" error 
> if I run the selftest:
> 
> $ python selftest.py
> *** The _imaging C module is not installed
> 
> 
> Here is what I have tested so far:
> 
> 1.)
> 
> $ python -v
> ...
>  >>> import Image
> ...
> dlopen("/usr/local/lib/python2.4/site-packages/PIL/_imaging.so", 2);
> import _imaging # dynamically loaded from 
> /usr/local/lib/python2.4/site-packages/PIL/_imaging.so
> ...

I had this problem earlier this week.

Assuming that you pip-installed or similar.

PIL will compile and install if you don't have some development
libraries and then simply not work or not work up to full steam when
used.

To avoid this, you need to install the appropriate libraries, among
which are:

libjpeg-devel
freetype-devel
libpng-devel

Probably others as well.

HTH,
-a


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Grant Edwards
On 2011-05-05, harrismh777  wrote:
> Grant Edwards wrote:
>> The "pass by value" and "pass by reference" parameter passing
>> mechanisms are pretty well defined, and C uses "pass by value".
>
> Yeah, that's kind-a funny, cause I'm one of the guys (old farts) that 
> helped define them

I give up.  You don't seem to understand the C language defintion or
what is commonly meant by "pass by reference".

-- 
Grant Edwards   grant.b.edwardsYow! Inside, I'm already
  at   SOBBING!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Wed, 04 May 2011 20:11:02 -0500, harrismh777 wrote:

> These definitions go all the way back before the 8080, or the 6502, 8 
> bit processors. Pass by reference has 'always' meant pass by using a 
> memory address (indirect addressing);  a reference has always been a 
> memory pointer.

That's not a definition. That's an implementation.

Some day, we'll be using quantum computers without memory addresses, or 
DNA computers, or some version of Babbage's Difference Engine (perhaps a 
trillion of them in the volume of a match-head, tiny nano computing 
devices... who knows?). Whatever it is, whether or not it has concepts of 
"memory address" or "memory pointer", it will still be possible to 
represent data indirectly via *some* mechanism.


> If I call a function in C, and pass-by-value, the data's 'value' is 
> placed on the stack in a stack-frame, as a 'value' parm... its a copy
> of the actual data in memory.

Correct.

> If I call a function in C, and pass-by-reference, the data's 'address' 

C doesn't do pass by reference. There is no way to declare a parameter to 
a function as a by-reference parameter. You can only simulate it by hand, 
by passing a pointer as data, pointing to what you *really* want as data, 
and dereferencing it yourself. But the pointer itself is passed by value: 
the address is copied onto the stack, just like any other piece of data 
would be.

(The Python equivalent is to pass a list containing the object. If you 
want call-by-reference behaviour without the convenience of language 
support for it, you can have it.)

Pascal, on the other hand, does do pass by reference. If you declare a 
"var" parameter, you then call the function with the variable you intend, 
and the compiler handles everything:

function foo(x: int, var y: int): int;
  begin
foo := x + y;
y := 0;
x := 0;
  end;

a := 1;
b := 2;
c := foo(a, b);

After calling foo, the variable a remains 1, but the variable b is now 0. 
The compiler is smart enough to figure out what to do behind the scenes 
to make it all work.

We're not discussing what you, the coder, can do. Given any Turing-
complete language, you can (with sufficient cleverness and hard-work) do 
anything any other Turing-complete language can do. We're discussing what 
the compiler does, and for C, that is purely call by value.

Let me put it this way... old, unstructured BASIC has GOTOs and line 
numbers, correct? And Python doesn't, correct? But you could write a 
BASIC interpreter in Python, and call that interpreter from your Python 
code... therefore Python has line numbers and GOTOs, no?

No. Of course not. We're discussing *language features*, and GOTO is not 
a language feature of Python. Neither is call by reference a language 
feature of C, or Python either for that matter, but it is a language 
feature of VB and Pascal. 

The only difference between the two scenarios is that writing a BASIC 
interpreter is a tad harder than dereferencing a pointer, but that's just 
a matter of degree, not of kind.



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


Re: Embedding Python's library as zip file

2011-05-05 Thread Alec Taylor
ZIP is the wrong format.

Use UPX with LZMA

On Thu, May 5, 2011 at 8:55 PM, Wojtek Mamrak  wrote:
> Thanks for the reply!
>
>> Can you import from zip files when running the Python.exe interpreter?
> When I zip the folder "Lib" into Python27.zip and later rename it and
> try to run the python.exe, I receive an error:
> "Import error: no module named site"
>
>> Is the zip file included in sys.path?  You might need to add this
>> yourself after callying Py_Initialize().
> Before renaming the "Lib" folder, the path to the python27.zip exists
> in sys.path.
>
>> Is there a top-level directory in the zip file that may be throwing
>> the importer off?
> I am testing all the cases so this is not the issue.
>
>> Are you getting any sort of error message?
> When I run my app, it crashes while calling Py_Initialize(). The
> console closes suddenly.
>
> Is it necessary to create zip archive using zipfile.PyZipFile?
>
> regards
>
>
> 2011/5/5 Ian Kelly 
>>
>> On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak  wrote:
>> > Hello,
>> >
>> > I spent a lot of time googling for a solution of this problem, with no
>> > result.
>> >
>> > I have a C++ application, in which I would like to embed Python 
>> > interpreter.
>> > I don't want to rely on an interpreter being installed on user machine,
>> > instead I would like to distribute all the necessary files with my app.
>> >
>> > As far as I understand, beside of my executable and Python.dll (I am using
>> > Python27), I need to provide two folders:
>> >  - DLLs,
>> >  - Lib
>> >
>> > If I place the Lib folder and the contents of the DLLs folder in a 
>> > directory
>> > of my executable, then everything seems to work.
>> > However I would like to use a zipped Lib folder. Hence I made an archive
>> > (which contains contents of Lib folder) called Python27.zip. Unfortunately
>> > the app crashes during execution.
>> > I assume the reason might be lack of zlib.pyd. Is that assumption correct?
>> > If so, how to obtain it? If not, what am I doing wrong?
>>
>> I believe zlib.pyd is statically linked into python27.dll nowadays.
>> Some things to check:
>>
>> Can you import from zip files when running the Python.exe interpreter?
>> Is the zip file included in sys.path?  You might need to add this
>> yourself after callying Py_Initialize().
>> Is there a top-level directory in the zip file that may be throwing
>> the importer off?
>> Are you getting any sort of error message?
>> --
>> http://mail.python.org/mailman/listinfo/python-list
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Thu, 05 May 2011 21:48:20 +1000, Chris Angelico wrote:

> On Thu, May 5, 2011 at 9:44 PM, Mel  wrote:
>> John Nagle wrote:
>>> On 5/4/2011 5:46 PM, harrismh777 wrote:
 Or, as stated earlier, Python should not allow 'is' on immutable
 objects.
>>>
>>>     A reasonable compromise would be that "is" is treated as "==" on
>>> immutable objects.
>>
>> I foresee trouble testing among float(5), int(5), Decimal(5) ...
> 
> Define 'x is y' as 'type(x)==type(y) and
> isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then.

`is` is supposed to be a *fast* operator, not even slower than equality 
testing.



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


PIL: The _imaging C module is not installed

2011-05-05 Thread Nico Grubert

Hi there

I am having trouble to install PIL 1.1.7 on CentOS.

I read and followed the instructions from
http://effbot.org/zone/pil-imaging-not-installed.htm

However, I still get the "The _imaging C module is not installed" error 
if I run the selftest:


$ python selftest.py
*** The _imaging C module is not installed


Here is what I have tested so far:

1.)

$ python -v
...
>>> import Image
...
dlopen("/usr/local/lib/python2.4/site-packages/PIL/_imaging.so", 2);
import _imaging # dynamically loaded from 
/usr/local/lib/python2.4/site-packages/PIL/_imaging.so

...

2.)

$ python
...
>>> import _imaging
...success imported!


Any idea what might be wrong?

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Neil Cerutti
On 2011-05-04, John Nagle  wrote:
> That's a quirk of CPython's boxed number implementation.   All
> integers are boxed, but there's a set of canned objects for
> small integers.  CPython's range for this is -5 to +256,
> incidentally.  That's visible through the "is" operator.
> Arguably, it should not be.

But that's the sole purpose of the is operator. You either expose
those details, or you don't have an is operator at all.

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


Re: : PiCloud - really cool!

2011-05-05 Thread Asdrúbal Iván Suárez Rivera
On May 4, 8:13 pm, James Mills  wrote:
> If anyone hasn't seen this yet, I encourage you to!
> (I stumbled upon it with some random thoughts and Gooogling)
>
> http://www.picloud.com/
>
> Here's a quick test I wrote up that works locally using the simulator
> and live (I did run it live):
>
> #!/usr/bin/env python
>
> import cloud
>
> def fib(n):
>     a, b, = 1, 1
>     while n > 1:
>         a, b = b, a + b
>         n -= 1
>     return b
>
> #cloud.start_simulator()
>
> jobs = cloud.map(fib, range(100))
>
> print [cloud.result(job) for job in jobs]
>
> Enjoy! :)
>
> cheers
> James
>
> --
> -- James Mills
> --
> -- "Problems are solved by method"

It looks interesting but unfortunately is not free software :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Wed, 04 May 2011 14:22:38 -0500, harrismh777 wrote:

> Here is the thing that everyone forgets... all we have to work with
> is a von Neumann processor. (same as EDVAC, ENIAC, the VIC20, etc).

Actually, this is incorrect. Most processors these days are hybrids 
between that and either the Harvard or Modified Harvard architecture:

http://en.wikipedia.org/wiki/Modified_Harvard_architecture
http://en.wikipedia.org/wiki/Harvard_architecture
http://en.wikipedia.org/wiki/Von_Neumann_architecture


> Assembler is still the best language on that processor.

Assembly is not "a" language, it is a generic term for dozens or hundreds 
of different languages. But in any case, it's not clear what you mean by 
"best language".


> 'C'  is still the best high-level language on that processor.

C is better described as a high-level assembler, or a low-level language. 
It is too close to the hardware to describe it as high-level, it has no 
memory management, few data abstractions, and little protection.


> Its silly to claim that one high-level language or another is better
> suited to complex data abstraction... don't go there.

Surely you can't possibly mean that?

Surely you don't mean to tell us that the 1957 version of FORTRAN, or 
unstructured BASIC, or early COBOL, are just as well suited to data 
abstraction as (say) Haskell?

Many implementations of unstructured BASIC didn't even have arrays, only 
character strings and integers.

Or (one of my personal favourites), Apple's Hypertalk? *Everything* is a 
string in Hypertalk. I love Hypertalk, but good for data abstraction? 
Don't make me laugh.

You should read Paul Graham on the Blub Paradox:

http://www.paulgraham.com/avg.html




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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Chris Angelico
On Thu, May 5, 2011 at 10:14 PM, Steven D'Aprano
 wrote:
> More importantly, Python need not be implemented at all. If you're stuck
> on a desert island without electricity, you could simulate the effect of
> running any arbitrary Python code merely by understanding the semantics
> of high-level Python code...

http://xkcd.com/505/

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Steven D'Aprano
On Wed, 04 May 2011 15:46:07 -0400, Benjamin Kaplan wrote:

> On Wed, May 4, 2011 at 3:22 PM, harrismh777 
> wrote:

[...]
>>> Digging down into C should be unnecessary to explain Python.
>>
>>
>>   huh?   You have to be kidding. Why do you suppose we want it to be
>> open-sourced?   Use the force Luke, read the source.   If you really
>> want to know how Python is working you *must* dig down into the C code
>> which implements it.  The folks who document Python should be able to
>> tell us enough to know how to use the language, but to really 'know'
>> you need the implementation source.
>>
>>
> Reading the CPython sources will show you how CPython works under the
> hood, but it has nothing to do with how Python works. There are lots of
> things that CPython does that "Python" does not. For instance, the GIL
> is not a part of Python. Reference counting is not a part of Python.
> Caching small integers and strings is not a part of Python. Why not read
> the Jython sources instead of the CPython? It's the same language, after
> all.

More importantly, Python need not be implemented at all. If you're stuck 
on a desert island without electricity, you could simulate the effect of 
running any arbitrary Python code merely by understanding the semantics 
of high-level Python code, without caring the slightest about pointers at 
the C implementation level, or bit flipping at the hardware level, or von 
Neumann machines, or ref counting, or garbage collection, or any of a 
million other implementation details. All you need understand is the 
declared semantics of the language.

Surely I can't be the only one who sometimes tries to work out a tricky 
bit of Python code by hand-simulating it on pencil and paper?


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Mel
Tim Roberts wrote:
> That is not an instance of passing an "int" by reference.  That is an
> instance of passing an "int *" by value.  The fact that the parameter "a"
> in BumpMe happens to be an address is completely irrelevent to the
> definition of the parameter passing mechanism.
> 
> C has pass-by-value, exclusively.  End of story.

Trouble with Turing-complete languages.  If it can be done, you can convince 
a Turing-complete language to do it -- somehow.

PL/I was the converse.  All parameters were passed by reference, so with

some_proc (rocks);

the code in some_proc would be working with the address of rocks.  If you 
wanted pass-by-value you wrote

some_proc ((rocks));

whereupon the compiler would pass in by reference an unnamed temporary 
variable whose value was the expression `(rocks)`.  I suspect the compiler I 
used avoided FORTRAN's troubles the same way.  Your function could corrupt 
*a* 4, but it wouldn't corrupt the *only* 4.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Chris Angelico
On Thu, May 5, 2011 at 9:44 PM, Mel  wrote:
> John Nagle wrote:
>> On 5/4/2011 5:46 PM, harrismh777 wrote:
>>> Or, as stated earlier, Python should not allow 'is' on immutable objects.
>>
>>     A reasonable compromise would be that "is" is treated as "==" on
>> immutable objects.
>
> I foresee trouble testing among float(5), int(5), Decimal(5) ...

Define 'x is y' as 'type(x)==type(y) and
isinstance(x,(int,float,tuple,etc,etc,etc)) and x==y' then.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Mel
John Nagle wrote:
> On 5/4/2011 5:46 PM, harrismh777 wrote:
>> Or, as stated earlier, Python should not allow 'is' on immutable objects.
> 
> A reasonable compromise would be that "is" is treated as "==" on
> immutable objects.

I foresee trouble testing among float(5), int(5), Decimal(5) ...

Mel.

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


Re: Embedding Python's library as zip file

2011-05-05 Thread Wojtek Mamrak
Thanks for the reply!

> Can you import from zip files when running the Python.exe interpreter?
When I zip the folder "Lib" into Python27.zip and later rename it and
try to run the python.exe, I receive an error:
"Import error: no module named site"

> Is the zip file included in sys.path?  You might need to add this
> yourself after callying Py_Initialize().
Before renaming the "Lib" folder, the path to the python27.zip exists
in sys.path.

> Is there a top-level directory in the zip file that may be throwing
> the importer off?
I am testing all the cases so this is not the issue.

> Are you getting any sort of error message?
When I run my app, it crashes while calling Py_Initialize(). The
console closes suddenly.

Is it necessary to create zip archive using zipfile.PyZipFile?

regards


2011/5/5 Ian Kelly 
>
> On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak  wrote:
> > Hello,
> >
> > I spent a lot of time googling for a solution of this problem, with no
> > result.
> >
> > I have a C++ application, in which I would like to embed Python interpreter.
> > I don't want to rely on an interpreter being installed on user machine,
> > instead I would like to distribute all the necessary files with my app.
> >
> > As far as I understand, beside of my executable and Python.dll (I am using
> > Python27), I need to provide two folders:
> >  - DLLs,
> >  - Lib
> >
> > If I place the Lib folder and the contents of the DLLs folder in a directory
> > of my executable, then everything seems to work.
> > However I would like to use a zipped Lib folder. Hence I made an archive
> > (which contains contents of Lib folder) called Python27.zip. Unfortunately
> > the app crashes during execution.
> > I assume the reason might be lack of zlib.pyd. Is that assumption correct?
> > If so, how to obtain it? If not, what am I doing wrong?
>
> I believe zlib.pyd is statically linked into python27.dll nowadays.
> Some things to check:
>
> Can you import from zip files when running the Python.exe interpreter?
> Is the zip file included in sys.path?  You might need to add this
> yourself after callying Py_Initialize().
> Is there a top-level directory in the zip file that may be throwing
> the importer off?
> Are you getting any sort of error message?
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What other languages use the same data model as Python?

2011-05-05 Thread Hans Georg Schaathun
On Thu, 05 May 2011 20:55:36 +1200, Gregory Ewing
   wrote:
:  It's not clear to me that references are any more abstract
:  than objects, or to put it another way, that objects are
:  any less abstract than references.
: 
:  After all, in normal Python usage you never actually
:  *see* an object 

Sure, but you can refer directly to objects, pass objects around,
and refer to individual objects.  This is abstract in the sense
that it is far removed from the memory representation.  However,
the concept of a reference appears only when you explain how objects
are handled (semantics).  You cannot reference nor manipulate a 
reference in python, and that IMHO makes them more abstract.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing

harrismh777 wrote:
'C' does provide for pointers which are used by all 'C' 
programmers to firmly provide pass-by-reference in their coding


Yes, but when they do that, they're building an abstraction
of their own on top of the facilities provided by the C
language. C itself has no notion of pass-by-reference. If
it did, the programmer would be able to use it directly
instead of having to insert & and * operators himself.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing

John Nagle wrote:


   A reasonable compromise would be that "is" is treated as "==" on
immutable objects.


That wouldn't work for tuples, which can contain references
to other objects that are not immutable.

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


Re: Python competitions and learnings

2011-05-05 Thread Alexander Lyabah
On May 1, 12:29 am, Terry Reedy  wrote:
> On 4/30/2011 3:22 PM, Alexander Lyabah wrote:
>
> > I spend a lot of time in writing a new service checkio.org
>
> > It's all about python, learn python, find the best solution in
> > python.
>
> > And Im looking for feedback from peoples who best in python. Here I
> > make some video tutorial about this servicehttp://checkio.blip.tv/
>
> > What do you think about it?
>
> Pretty impressive. My main disappointment is that you are using 2.7
> instead of 3.2, as I feel that beginners should learn Py 3 now. Also,
> that is what I routinely use ;-).
>
> In any case, the home page should say Python 2.7, not just Python, I had
> to think to click Console Learn in order to find out what would be legal
> when I tried out one of the tasks.
>
> You might consider offering 3.2 as an alternative. Solutions will be
> similar, but details differ. For instance, I noticed that one solution
> to 'string split' *depends* on the 2.x leaking of listcomp loop variables.
>
> > I'm also have a not a very good English, so I need help with it too,
> > because some parts of checkio.org  not in very well English
>
> Home page: "In the descriptions of this tasks there is always
> information from manuals and tutorials," 'these tasks'
>
> "game.Choice a game " => "game. Choose a game "
> "users. Choice a game" => again, 'Choose'
>
> "and fall into the top " I think you mean "and climb into the top "
>
> "programs on arena. " => "program in the arena. "
>
> "By the result of competition formed top of the game. "
> This is unclear. perhaps "The best will be chosen by the result of the
> competition."
>
> I see a mailto: link at the bottom of the page, so I will report
> anything else I see later.
>
> --
> Terry Jan Reedy

Terry, Hi, sent a mail to you, couple days ago. From
alexan...@lyabah.com

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing

harrismh777 wrote:
That is the $10,000,000 dollar problem... how to 
extricate ourselves from the von Neumann processor. *Everthing* comes 
down to that...  its hilarious to hear folks talk about lambda the 
ultimate (especially those guys on Lambda the Ultimate) when there is no 
such thing until such time as we have lambda the hardware architecture.


I think there are fundamental problems that go beyond the
issue of hardware design. It's easy to reason about a program
that does things one step at a time, much harder when lots
of things are happening at once. Whether you express the
program using lambda calculus or a Turing machine doesn't
change that fact.

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Chris Angelico
On Thu, May 5, 2011 at 7:08 PM, Gregory Ewing
 wrote:
> harrismh777 wrote:
>>
>> 'C'  is still the best high-level language on that processor.
>
> Some would argue that C is actually better than assembler these
> days, because modern architectures are so freaking complicated
> that it takes a computer to figure out the best instruction
> sequence. :-(

I use C to hint to the compiler as to what I'd like it to write a
program to do. It does all the writing, I just make some vague
suggestions - which it's free to ignore if it chooses. GCC and me, we
get along jess fine...

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing

harrismh777 wrote:

'C'  is still the best high-level language on that processor.


Some would argue that C is actually better than assembler these
days, because modern architectures are so freaking complicated
that it takes a computer to figure out the best instruction
sequence. :-(

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Gregory Ewing

Hans Georg Schaathun wrote:

With the references being
purely abstract entities and not data objects,


It's not clear to me that references are any more abstract
than objects, or to put it another way, that objects are
any less abstract than references.

After all, in normal Python usage you never actually
*see* an object -- at best you see some string of characters
resulting from the str() or repr() of an object. The
object is a mental construct we use to make sense of the
behaviour we're seeing, as are references.

If you were to look inside the interpreter closely enough
to see the concrete representations of objects -- the
bit patterns in memory making them up -- then you would
also be able to see the bit patterns making up the
references.

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


Re: python on iPad (PyPad)

2011-05-05 Thread Drew
On Apr 10, 1:48 am, Matt Schinckel  wrote:
> On Apr 9, 2:13 pm, Jon Dowdall  wrote:
>
> > Hi All,
>
> > Sorry for the blatant advertising but hope some of you may be interested
> > to know that I've created an iPad application containing the python
> > interpreter and a simple execution environment. It's available in iTunes
> > athttp://itunes.apple.com/us/app/pypad/id428928902?mt=8#
>
> > I wanted to have python available 'on the go' without carrying a laptop.
> > The current implementation is based on my need to test simple python
> > functions in an isolated environment. I hope to add more iOS specific
> > capabilities if there is enough interest.
>
> > Enjoy...
>
> > Jon Dowdall
>
> I know this sound shallow, but you really need a nicer icon.
>
> Otherwise, I'm quite excited about this. It will certainly be better
> than my current workflow of connecting via ssh to a server just to run
> python code.
>
> Matt.

There's a Pypad on SourceForge, but it is flagged as no longer under
active development.  Dead or just sleeping?   Is this Pypad distinct
from that old one on SourceForge?  Or a revival?  OpenSource?

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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Hans Georg Schaathun
On Wed, 04 May 2011 20:11:02 -0500, harrismh777
   wrote:
:  A reference is a pointer (an address).
: 
:  A value is memory (not an address).

Sure, and pointers (from a hardware or C perspective) are memory,
hence pointers are values.  


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


Re: What other languages use the same data model as Python?

2011-05-05 Thread Hans Georg Schaathun
On Wed, 04 May 2011 16:49:25 -0500, harrismh777
   wrote:
:  Folks seem to think that because they are doing abstraction at a 
:  high-level (well, they never maybe programmed at a lower level) that 
:  abstraction somehow 'requires' a high level language.  (not true)

I never said 'requires', but when you do high-level modelling,
low-level detail is a distraction.  Using a low-level language
for abstract modelling is therefore harder than it needs to be.

:  Today, high-level languages like Python (and others) allow programmers 
:  to place some of their abstraction into their source code directly. This 
:  does not make the high-level language any more 'suited' to abstraction 
:  than any other lower-level language; because the abstraction is a mental 
:  process not a language feature. It all ends up in assembly and machine 
:  code.

Indeed, except for the contradiction.  The fact that you can 
put more of your abstraction into the source code means that it is
better suited to abstraction.

Mental processes depend on language; at least when you need to
communicate the output.  That language does not have to be
computer readable (as is the case for your float charts etc).
We may very well use a stack of languages and models at different
levels of abstraction, but when you move down the stack you are
moving away from abstraction and into implementation.

C is very rarely suitable at the top of this stack.  When I say that
C is ill-suited for abstraction, I am not implying that it is ill-suited
for implementing according to an abstract model.  If you need human
input in the lower layers of abstraction, C is a good choice. 

Using manual work to move down the layers of abstraction is possible,
and given sufficient man-power should give the better result, but
relying on human input when the work can be automated is ridiculously
expensive.

Now, python is only one level above C in abstraction, but that's a 
different matter.

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