Re: Wanted: Criticism of code for a Python module, plus a Mac tester

2012-02-16 Thread Arnaud Delobelle
On 16 February 2012 05:03, Ian Kelly  wrote:
> On Wed, Feb 15, 2012 at 6:11 PM, HoneyMonster  
> wrote:
>> As to your first suggestion though, I am having some difficulty. Note
>> that the vulnerability rotates; i.e. CONDITIONS[4] is not the same as
>> CONDITIONS[0].
>> Is there a better way of doing it than a simple list.append()?
>
> Ah, it's more complicated than I realized.  I believe this generates
> the correct result, although adding None to the dealers list is
> somewhat unsatisfactory:
>
> DEALERS = ["Dealer North", "Dealer East", "Dealer South", "Dealer West", None]
> VULNERABILITIES = [
>   "Neither vulnerable", "North-South vulnerable",
>   "East-West vulnerable", "Both vulnerable",
> ]
> CONDITIONS = [(d, v) for (d, v) in zip(DEALERS * 4, VULNERABILITIES * 5) if d]

You could also do:

DEALERS = ["Dealer North", "Dealer East", "Dealer South", "Dealer West"]
VULNERABILITIES = [
  "Neither vulnerable", "North-South vulnerable",
  "East-West vulnerable", "Both vulnerable",
]
CONDITIONS = [
(DEALERS[j], VULNERABILITIES[(i + j)%4])
for i in range(4) for j in range(4)
]

If you don't care about the order in which the conditions are listed,
you could use

CONDITIONS = itertools.product(DEALERS, VULNERABILITIES)

(But maybe you do, I haven't looked at the code)

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


Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Daniel Fetchinson
>> Hi folks, often times in science one expresses a value (say
>> 1.03789291) and its error (say 0.00089) in a short way by parentheses
>> like so: 1.0379(9)
>>
>> One can vary things a bit, but let's take the simplest case when we
>> only keep 1 digit of the error (and round it of course) and round the
>> value correspondingly. I've been searching around for a simple
>> function that would take 2 float arguments and would return a string
>> but didn't find anything although something tells me it's been done a
>> gazillion times.
>>
>> What would be the simplest such function?
>
> Well, this basically works:
>
 def format_error(value, error):
> ... precision = int(math.floor(math.log(error, 10)))
> ... format = "%%.%df(%%d)" % max(-precision, 0)
> ... return format % (round(value, -precision),
> ...  int(round(error / 10 ** precision)))
> ...
 format_error(1.03789291, 0.00089)
> '1.0379(9)'
>
> Note that "math.floor(math.log(error, 10))" may return the wrong
> decimal precision due to binary floating point rounding error, which
> could produce some strange results:
>
 format_error(10378929, 1000)
> '10378900(10)'
>
> So you'll probably want to use decimals instead:
>
> def format_error(value, error):
> value = decimal.Decimal(value)
> error = decimal.Decimal(error)
> value_scale = value.log10().to_integral(decimal.ROUND_FLOOR)
> error_scale = error.log10().to_integral(decimal.ROUND_FLOOR)
> precision = value_scale - error_scale
> if error_scale > 0:
> format = "%%.%dE" % max(precision, 0)
> else:
> format = "%%.%dG" % (max(precision, 0) + 1)
> value_str = format % value.quantize(decimal.Decimal("10") **
> error_scale)
> error_str = '(%d)' % error.scaleb(-error_scale).to_integral()
> if 'E' in value_str:
> index = value_str.index('E')
> return value_str[:index] + error_str + value_str[index:]
> else:
> return value_str + error_str
>
 format_error(1.03789291, 0.00089)
> '1.0379(9)'
 format_error(103789291, 1000)
> '1.03789(1)E+08'
>
> I haven't tested this thoroughly, so use at your own risk. :-)

Thanks a lot, this indeed mostly works, except for cases when the
error needs to be rounded up and becomes two digits:

>>> format_error( '1.34883', '0.0098' )
'1.349(10)'

But in this case I'd like to see 1.35(1)

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Beware, my computer was infected.

2012-02-16 Thread Jugurtha Hadjar

Hello gentlemen,

I'm writing these words to give you a heads up. My computer has recently 
been infected with "1.exe", and I am doing what I can to contain it. It 
spreads via mail and I fear it will send SPAM to lists I am subscribed to.


If you receive weird mails from my address, thank you to report it to 
me. I will not send you an executable, so if you receive one from me, 
please do not open it and it would be nice to report it.


I will  send an e-mail to this list once I think it is no longer in the 
system.


Thank you all.

--
~Jugurtha Hadjar,

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


Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-16 Thread Ian Kelly
On Wed, Feb 15, 2012 at 8:04 AM, Rick Johnson
 wrote:
> I have PROVEN that when people FIGHT back, they will NOT be subjects
> to tyranny; race has NOTHING to do with it. I gave one example in
> history where people would rather die than be subjected to tyranny,
> there are many more. "GIVE ME FREEDOM FOR GIVE ME DEATH!"
>
> The world is full of evil people who seek to force their fellow man
> into slavery. Those who refuse to fight for freedom will be victims,
> on the other hand, those who are willing to sacrifice ALL in the name
> of freedom will be free men.
>
> 300: "Go now! Run along and tell your Xerxes he faces free men here,
> not slaves! Do it quickly, before we decide to make our wall just a
> little bit bigger."

If you get all your history from Hollywood, then no wonder you are so
badly misinformed.  Braveheart and 300 are inspiring movies to be
sure, but they are also highly fictionalized.  In the real world, the
execution of William Wallace actually succeeded in quelling the
Scottish rebellion for a time -- when Robert the Bruce started it up
again half a year later, his motives were entirely political in nature
(he had murdered a rival in a church and been excommunicated; his
options were to place himself on the throne or become a fugitive), not
out of some noble sense of guilt or duty to Wallace or desire for
freedom as depicted in the film.

Your statement that the Africans brought to America allowed themselves
to be enslaved is simply false.  There were dozens of slave rebellions
in the United States prior to the Civil War.  Most of them failed and
ended in the executions of the rebels.  You won't see Hollywood making
too many movies about those, which is probably why you don't know
anything about them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Reading sub-string from a file

2012-02-16 Thread Smiley 4321
All,

I am a python newbie.

Let's say I have a filename (test.conf) as below -


int Apple(int, int);
void Jump_OnUnload(float, int);
int Jockey_Apple_cat_1KK(float, int, char, int);
int Jockey_Apple_cat_look(int, float, int, int);
int Jockey_Apple_cat_test_ki21es(int, int, int, int);
int Jockey_Apple_cat_tarLK12OU(void, int, int, int);
---

Here substring "Jockey_Apple_cat" is common from 3rd line onwards as a
function name. I wish to extract ONLY that function name which has
'Jockey_Apple_cat' as a substring and ignore remaining function names.

The program .py written is -

-
---
#!/usr/bin/python

def foo(filename):
try:
one = open(filename, 'r')
except:
print filename, 'cannot be open.'

AllLines = one.readline()

for eachLine in AllLines:
start = eachLine.find('Jockey_Apple_cat')
if start != -1:
finish = eachLine.find ('(')
print eachLine[start:finish]

handle.close()

set_foo("test.conf")
-

I did perform debugging using pdb, it only reads all the lines.

Plz help!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading sub-string from a file

2012-02-16 Thread Chris Rebert
On Thu, Feb 16, 2012 at 1:52 AM, Smiley 4321  wrote:
> All,
>
> I am a python newbie.
>
> Let's say I have a filename (test.conf) as below -
>
> 
> int Apple(int, int);
> void Jump_OnUnload(float, int);
> int Jockey_Apple_cat_1KK(float, int, char, int);
> int Jockey_Apple_cat_look(int, float, int, int);
> int Jockey_Apple_cat_test_ki21es(int, int, int, int);
> int Jockey_Apple_cat_tarLK12OU(void, int, int, int);
> ---
>
> Here substring "Jockey_Apple_cat" is common from 3rd line onwards as a
> function name. I wish to extract ONLY that function name which has
> 'Jockey_Apple_cat' as a substring and ignore remaining function names.
>
> The program .py written is -
>
> -
> ---
> #!/usr/bin/python
>
> def foo(filename):
>     try:
>     one = open(filename, 'r')
>     except:
>     print filename, 'cannot be open.'
>
>     AllLines = one.readline()
>
>     for eachLine in AllLines:
>     start = eachLine.find('Jockey_Apple_cat')
>     if start != -1:
>     finish = eachLine.find ('(')
>     print eachLine[start:finish]
>
>     handle.close()
>
> set_foo("test.conf")
> -
>
> I did perform debugging using pdb, it only reads all the lines.
>
> Plz help!!

Several oddities in the code you posted (e.g. you defined foo() but
instead call set_foo(); the `handle` variable comes out of nowhere)
suggest that it isn't your actual code; this greatly hinders us in
assisting you. Please post your /actual/ code verbatim (or as much of
it as you can with as few modifications as you can).
Also, avoid using "plz" in the future; it's gotten a reputation for
being associated with undesirable folk.

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


Re: Reading sub-string from a file

2012-02-16 Thread Peter Otten
Smiley 4321 wrote:

> I am a python newbie.

Welcome!
 
> Let's say I have a filename (test.conf) as below -
> 
> 
> int Apple(int, int);
> void Jump_OnUnload(float, int);
> int Jockey_Apple_cat_1KK(float, int, char, int);
> int Jockey_Apple_cat_look(int, float, int, int);
> int Jockey_Apple_cat_test_ki21es(int, int, int, int);
> int Jockey_Apple_cat_tarLK12OU(void, int, int, int);
> ---
> 
> Here substring "Jockey_Apple_cat" is common from 3rd line onwards as a
> function name. I wish to extract ONLY that function name which has
> 'Jockey_Apple_cat' as a substring and ignore remaining function names.
> 
> The program .py written is -
> 
> -
> ---
> #!/usr/bin/python
> 
> def foo(filename):
> try:
> one = open(filename, 'r')
> except:
> print filename, 'cannot be open.'
> 
> AllLines = one.readline()
> 
> for eachLine in AllLines:
> start = eachLine.find('Jockey_Apple_cat')
> if start != -1:
> finish = eachLine.find ('(')
> print eachLine[start:finish]
> 
> handle.close()
> 
> set_foo("test.conf")
> -
> 
> I did perform debugging using pdb, it only reads all the lines.

There are errors in the above that suggest that you retyped your actual 
code. Don't do that! Always use cut and paste for code snippets you are 
posting here.

As to what the problem in your actual code might be, here's a hint:
You could be iterating over the characters of the first line of the file 
instead of the lines. Change

> AllLines = one.readline()
> 
> for eachLine in AllLines:

to 

for eachLine in one:

to fix that.

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


Re: Reading sub-string from a file

2012-02-16 Thread Chris Angelico
On Thu, Feb 16, 2012 at 8:52 PM, Smiley 4321  wrote:
> int Jockey_Apple_cat_1KK(float, int, char, int);
> int Jockey_Apple_cat_look(int, float, int, int);
> int Jockey_Apple_cat_test_ki21es(int, int, int, int);
> int Jockey_Apple_cat_tarLK12OU(void, int, int, int);
> ---
>
> Here substring "Jockey_Apple_cat" is common from 3rd line onwards as a
> function name. I wish to extract ONLY that function name which has
> 'Jockey_Apple_cat' as a substring and ignore remaining function names.

Try this:

grep -o 'Jockey_Apple_cat[^(]*' test.conf

It's not Python, but it might serve you better than knocking something
together! But if you're using this to learn Python, Peter Otten's
solution is, I think, what you want.

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


Re: Is this the right list?

2012-02-16 Thread Rick Johnson
On Feb 15, 4:04 pm, Terry Reedy  wrote:
> On 2/15/2012 4:51 PM, Alan McKay wrote:
>
> > Is this the right list?

This is neither the "right" or "left" list, however, it may be either
the correct or incorrect depending on your question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread 88888 Dihedral
The law suites of JAVA Vitrtual Machine from Oracle
are famous now. But in 201X the JVM patents will be 
expired, thus it is not very urgent to chunk out a new jython now. Anyway just 
write codes that can be maintained and  ported to other languages and platforms
easily.

Then I personally prefer python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread Michael Torrie
On 02/16/2012 07:53 AM, 8 Dihedral wrote:
> The law suites of JAVA Vitrtual Machine from Oracle
> are famous now. But in 201X the JVM patents will be 
> expired, thus it is not very urgent to chunk out a new jython now. Anyway 
> just write codes that can be maintained and  ported to other languages and 
> platforms
> easily.

Umm what does this have to do with anything?

You claimed Jython is or will be available on Android. It's not and
Jython isn't being ported to Dalvik and it has nothing to do with
patents.  Android might use java a language, but the virtual machines
are very different.  And no expired patents are going to change that
fact.  Android simply isn't going to run the JVM anytime soon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread Benjamin Kaplan
On Feb 16, 2012 10:25 AM, "Michael Torrie"  wrote:
>
> On 02/16/2012 07:53 AM, 8 Dihedral wrote:
> > The law suites of JAVA Vitrtual Machine from Oracle
> > are famous now. But in 201X the JVM patents will be
> > expired, thus it is not very urgent to chunk out a new jython now.
Anyway just write codes that can be maintained and  ported to other
languages and platforms
> > easily.
>
> Umm what does this have to do with anything?
>
> You claimed Jython is or will be available on Android. It's not and
> Jython isn't being ported to Dalvik and it has nothing to do with
> patents.  Android might use java a language, but the virtual machines
> are very different.  And no expired patents are going to change that
> fact.  Android simply isn't going to run the JVM anytime soon.
> --

I believe the general consensus is that 8 is a bot. it makes lots of
posts that mention key words from the thread its replying to but don't
actually mean anything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this the right list?

2012-02-16 Thread Chris Angelico
On Fri, Feb 17, 2012 at 1:43 AM, Rick Johnson
 wrote:
> On Feb 15, 4:04 pm, Terry Reedy  wrote:
>> On 2/15/2012 4:51 PM, Alan McKay wrote:
>>
>> > Is this the right list?
>
> This is neither the "right" or "left" list, however, it may be either
> the correct or incorrect depending on your question.

There's also no "right" or "responsibility" list, but we'll answer
user questions here as much as we can anyway.

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


ANN: mock 0.8 final released

2012-02-16 Thread Fuzzyman
After more than six months development work mock 0.8 has been
released. 0.8 is a big release with many new features, general
improvements and bugfixes.

You can download mock 0.8.0 final from the PyPI page or install it
with:

pip install -U mock

mock is a library for testing in Python. It allows you to replace
parts of your system under test with mock objects.

http://pypi.python.org/pypi/mock
http://www.voidspace.org.uk/python/mock/
http://www.voidspace.org.uk/python/mock/changelog.html#version-0-8-0

The only changes in mock 0.8.0 final since 0.8rc2 are:

* Improved repr of `sentinel` objects
* `ANY` can be used for comparisons against call objects
* The return value of  `MagicMock.__iter__` can be set to any iterable
and isn't required to be an iterator

A longer version of this announcement, including the full changelog
since mock 0.7 and a couple of short examples of the most important
changes, can be found on my blog:

http://www.voidspace.org.uk/python/weblog/arch_d7_2012_02_11.shtml#e1234

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


Re: Is this the right list?

2012-02-16 Thread Andrew Berg
On 2/16/2012 9:33 AM, Chris Angelico wrote:
> On Fri, Feb 17, 2012 at 1:43 AM, Rick Johnson
>  wrote:
>> On Feb 15, 4:04 pm, Terry Reedy  wrote:
>>> On 2/15/2012 4:51 PM, Alan McKay wrote:
>>>
>>> > Is this the right list?
>>
>> This is neither the "right" or "left" list, however, it may be either
>> the correct or incorrect depending on your question.
> 
> There's also no "right" or "responsibility" list, but we'll answer
> user questions here as much as we can anyway.
Do we have "right" and "privilege" lists?

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this the right list?

2012-02-16 Thread Alan McKay
>
> Welcome to the list.  There are lots of friendly folks here who will try
> to help.
>
>

I noticed that already - thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this the right list?

2012-02-16 Thread Ethan Furman

On Fri, Feb 17, 2012 at 1:43 AM, Rick Johnson wrote:

On 2/15/2012 4:51 PM, Alan McKay wrote:

Is this the right list?

>>

This is neither the "right" or "left" list, however, it may be either
the correct or incorrect depending on your question.


Alan,

Welcome to the list.  There are lots of friendly folks here who will try 
to help.


Unfortunately there are also a couple well-known trolls, one of whom is 
Rick Johnson (aka Ranting Rick).  Please do not take his posts as 
representative of the community.


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


list of properties

2012-02-16 Thread Emmanuel Mayssat
Hello,

Is there a way to list 'properties' ?


from PyQt4.QtCore import *

class LObject(QObject):
def __init__(self, parent=None):
super(LObject, self).__init__(parent)
self.arg1 = 'toto'

def getArg2(self):
return self.arg1 + " <--"
arg2 = property(getArg2)

l = LObject()
print l.__dict__

returns only arg1


How can I find that arg2 is a 'virtual' attribute (i.e. property)?

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


Re: XSLT to Python script conversion?

2012-02-16 Thread Matej Cepl

On 15.2.2012 18:48, Tim Arnold wrote:

Just a note to encourage you to stick with XSLT. I also use lxml for
creating and postprocessing my DocBook documents and it is great. But I
use the DocBook XSL stylesheets to convert to html; if you're like me,
you got discouraged at the strangeness of the XSLT language.


No, the strangness is not that bad (well, it is bad ... almost anything 
feels bad comparing to Python, to be honest, but not the reason I would 
give up; after all I spent couple of years with Javascript).


The terrible debugging is one thing, and even worse, I just still cannot 
get over rules around spaces: whitespace just jumps at me randomly in 
random places and is erased in others.


Matěj
--
http://mail.python.org/mailman/listinfo/python-list


Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Ian Kelly
On Thu, Feb 16, 2012 at 1:36 AM, Daniel Fetchinson
 wrote:
>>> Hi folks, often times in science one expresses a value (say
>>> 1.03789291) and its error (say 0.00089) in a short way by parentheses
>>> like so: 1.0379(9)
>>>
>>> One can vary things a bit, but let's take the simplest case when we
>>> only keep 1 digit of the error (and round it of course) and round the
>>> value correspondingly. I've been searching around for a simple
>>> function that would take 2 float arguments and would return a string
>>> but didn't find anything although something tells me it's been done a
>>> gazillion times.
>>>
>>> What would be the simplest such function?
>>
>> Well, this basically works:
>>
> def format_error(value, error):
>> ...     precision = int(math.floor(math.log(error, 10)))
>> ...     format = "%%.%df(%%d)" % max(-precision, 0)
>> ...     return format % (round(value, -precision),
>> ...                      int(round(error / 10 ** precision)))
>> ...
> format_error(1.03789291, 0.00089)
>> '1.0379(9)'
>>
>> Note that "math.floor(math.log(error, 10))" may return the wrong
>> decimal precision due to binary floating point rounding error, which
>> could produce some strange results:
>>
> format_error(10378929, 1000)
>> '10378900(10)'
>>
>> So you'll probably want to use decimals instead:
>>
>> def format_error(value, error):
>>     value = decimal.Decimal(value)
>>     error = decimal.Decimal(error)
>>     value_scale = value.log10().to_integral(decimal.ROUND_FLOOR)
>>     error_scale = error.log10().to_integral(decimal.ROUND_FLOOR)
>>     precision = value_scale - error_scale
>>     if error_scale > 0:
>>         format = "%%.%dE" % max(precision, 0)
>>     else:
>>         format = "%%.%dG" % (max(precision, 0) + 1)
>>     value_str = format % value.quantize(decimal.Decimal("10") **
>> error_scale)
>>     error_str = '(%d)' % error.scaleb(-error_scale).to_integral()
>>     if 'E' in value_str:
>>         index = value_str.index('E')
>>         return value_str[:index] + error_str + value_str[index:]
>>     else:
>>         return value_str + error_str
>>
> format_error(1.03789291, 0.00089)
>> '1.0379(9)'
> format_error(103789291, 1000)
>> '1.03789(1)E+08'
>>
>> I haven't tested this thoroughly, so use at your own risk. :-)
>
> Thanks a lot, this indeed mostly works, except for cases when the
> error needs to be rounded up and becomes two digits:
>
 format_error( '1.34883', '0.0098' )
> '1.349(10)'
>
> But in this case I'd like to see 1.35(1)

A small adjustment to the scale fixes that.  Also tidied up the string
formatting part:

import decimal

def format_error(value, error):
value = decimal.Decimal(value)
error = decimal.Decimal(error)
error_scale = error.adjusted()
error_scale += error.scaleb(-error_scale).to_integral().adjusted()
value_str = str(value.quantize(decimal.Decimal("1E%d" % error_scale)))
error_str = '(%d)' % error.scaleb(-error_scale).to_integral()
if 'E' in value_str:
index = value_str.index('E')
return value_str[:index] + error_str + value_str[index:]
else:
return value_str + error_str

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


Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread Grant Edwards
On 2012-02-16, Michael Torrie  wrote:


> You claimed Jython is or will be available on Android. It's not and
> Jython isn't being ported to Dalvik and it has nothing to do with
> patents.  Android might use java a language, but the virtual machines
> are very different.  And no expired patents are going to change that
> fact.  Android simply isn't going to run the JVM anytime soon.

I got curious about Dalvik, and was looking at the Wikipedia page,
where it says that programs for Android are compiled into bytecode in
JVM compatible .class files.  Those files are then converted into .dex
files to run on Davlik.

I don't know much at all about Jython, but if it generates JVM byte
code, mightn't the same conversion to .dex be applicable?

-- 
Grant Edwards   grant.b.edwardsYow! What I want to find
  at   out is -- do parrots know
  gmail.commuch about Astro-Turf?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread Grant Edwards
On 2012-02-16, Grant Edwards  wrote:
> On 2012-02-16, Michael Torrie  wrote:
>
>> You claimed Jython is or will be available on Android. It's not and
>> Jython isn't being ported to Dalvik and it has nothing to do with
>> patents.  Android might use java a language, but the virtual machines
>> are very different.  And no expired patents are going to change that
>> fact.  Android simply isn't going to run the JVM anytime soon.
>
> I got curious about Dalvik, and was looking at the Wikipedia page,
> where it says that programs for Android are compiled into bytecode in
> JVM compatible .class files.  Those files are then converted into
> .dex files to run on Davlik.
>
> I don't know much at all about Jython, but if it generates JVM byte
> code, mightn't the same conversion to .dex be applicable?

Apparently there was a project to do just that:

  http://code.google.com/p/jythonroid/

But it's been abandonded in favor of SL4A, which offers a 
PythonForAndroid_r4.apk download.  There's a book about Python on
Android via SL4A called _Pro_Android_Python_with_SL4A_.

  http://www.apress.com/9781430235699

Interesting...
  
-- 
Grant Edwards   grant.b.edwardsYow! World War III?
  at   No thanks!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list of properties

2012-02-16 Thread Emile van Sebille

On 2/16/2012 9:19 AM Emmanuel Mayssat said...

Hello,

Is there a way to list 'properties' ?


dir(thingy)




from PyQt4.QtCore import *

class LObject(QObject):
 def __init__(self, parent=None):
 super(LObject, self).__init__(parent)
 self.arg1 = 'toto'

 def getArg2(self):
 return self.arg1 + " <--"
 arg2 = property(getArg2)

l = LObject()
print l.__dict__

returns only arg1


arg2 is defined at the class level and not the instance level. 
l.__dict__ returned the instance attributes. Look in LObject.__dict__ 
for arg2.


Emile





How can I find that arg2 is a 'virtual' attribute (i.e. property)?

Regards,
--
E





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


Python / Apache config issue

2012-02-16 Thread Alan McKay
OK, since you all said to send it, here it is :-)  Though I think it may be
an apache issue, I'll send it anyway.

I'm using the software called "Open Freezer" which is used to track
reagents and other chemicals in research labs.

I also posted this here on their discussion forums but have not heard
anything yet.  In general their install and config instructions are pretty
incomplete and even asking the authors direct questions sometimes does not
get very good answers

https://sourceforge.net/p/openfreezer/discussion/openfreezer/thread/789d5cdb/

It was working fine on Ubuntu 11.04 and RHEL 5.7 but I'm having issues on
Ubuntu 11.11 - in all cases the versions of python that come with the
respective OS

In the working version on Ubuntu 11.04 the entire apache instance was
dedicated to this app - something I cannot do on the RHEL and Ubuntu 11.11
machines

---snip---

The specific problem I am having is that I go to "Search Projects", and
then select a project and hit "Go", and it does not execute the python. In
one configuration, it downloads the .py script instead of executing it. In
the other configuration it tells me 404 cannot find it. I had this working
fine on RHEL 5.7 but now it is broken on Ubuntu (with the same config file)

Details below.

I had the basic CGI functions working fine on RHEL but had to move to the
latest version of Ubuntu server and am having trouble. One different aspect
of both my RHEL and Ubuntu setups is that I cannot dedicate the entire
Apache instance to Open Freezer, so my URL is not
http://MYIP/
it
is 
http://MYIP/openfreezer/
 .

On RHEL my openfreezer.conf file looks like this. Note there is no
VirtualHost because as mentioned I cannot dedicate this apache instance to
just open freezer, and I also do not have control over DNS so I cannot
assign a 2nd DNS name to this server.

Alias"/openfreezer""/var/www/OpenFreezer"
Alias"/openfreezercgi""/var/www/OpenFreezer/cgi"

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
#AddHandler python26-mod_python .py
#AddHandler mod_python .py
PythonDebug On
#PythonHandler mod_python.publisher

AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler mod_python .py
#PythonDebug On
PythonHandler mod_python.cgihandler
PythonPath "['/var/www/OpenFreezer/cgi'] + sys.path"


This works fine on RHEL 5.7 with apache 2.2.3 . I select a project, hit
"Go" and it executes cgi/project_request_handler.py as it should. But with
the exact same config file on Ubuntu it instead tries to download the .py
instead of execute it. But I also try putting a couple of test programs in
my CGI directory. This first one tries to download as well with the above
config :

test.py
def index(req):
return "Test successful";


But this second one executes correctly :

testcgi.py
#!/usr/bin/python
print "Content-type: text/html"
print
print ""
print "
Hello!"
print ""

So I talk to the other guy here who started out working on this for us,
because he had it running on Ubuntu as well (a slightly older version -
11.04 versus my 11.11). He has apache 2.2.16 and I have 2.2.20

His config file looks like this - note that he does have the entire apache
server dedicated to Open Freezer so his URL is
http://HISIP/


ServerAdmin webmaster@localhost
ServerName localhost

DocumentRoot /var/www/OpenFreezer/

Options FollowSymLinks
AllowOverride All


Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
AddHandler mod_python .py
PythonDebug On
#PythonHandler mod_python.publisher




AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
#AddHandler mod_python .py
#PythonDebug On
#PythonHandler mod_python.cgihandler


#
#
#

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.1/255.0.0.0 ::1/128



If I strip out the two Directory sections from that and make mine look the
same, then instead of trying to download the .py file what I get is this
error :

Not Found
The requested URL /openfreezer/cgi/project_request_handler.py was not
found on this server

and checking the apache error.log tha

Re: python file synchronization

2012-02-16 Thread Sherif Shehab Aldin
Hi Cameron,

First sorry for my very very late reply, has been overloaded at work last
week :(
Anyways... I will reply inline this time ;)

On Wed, Feb 8, 2012 at 11:59 AM, Cameron Simpson  wrote:

> [ Please reply inline; it makes the discussion read like a converation,
>  with context. - Cameron
> ]
>
> On 08Feb2012 08:57, Sherif Shehab Aldin  wrote:
> | Thanks a lot for your help, I just forgot to state that the FTP server is
> | not under my command, I can't control how the file grow, or how the
> records
> | are added, I can only login to It, copy the whole file.
>
> Oh. That's a pity.
>
> | The reason why I am parsing the file and trying to get the diffs between
> | the new file and the old one, and copy it to new_file.time_stamp is that
> I
> | need to cut down the file size so when server (C) grabs the file, It
> grabs
> | only new data, also to cut down the network bandwidth.
>
> Can a simple byte count help here? Copy the whole file with FTP. From
> the new copy, extract the bytes from the last byte count offset onward.
> Then parse the smaller file, extracting whole records for use by (C).
> That way you can just keep the unparsed tail (partial record I imagine)
> around for the next fetch.
>
> Looking at RFC959 (the FTP protocol):
>
>  http://www.w3.org/Protocols/rfc959/4_FileTransfer.html
>
> it looks like you can do a partial file fetch, also, by issuing a REST
> (restart) command to set a file offset and then issuing a RETR (retrieve)
> command to get the rest of the file. These all need to be in binary mode
> of course.
>
> So in principle you could track the byte offset of what you have fetched
> with FTP so far, and fetch only what is new.
>

 I am actually grabbing the file from ftp with a bash script using lftp, It
seemed a simple task for python at the beginning and then I noticed the
many problems. I have checked lftp and did not know how to continue
downloading a file. Do I have to use ftp library, may be in python so I can
use that feature?

>
> | One of my problems was after mounting server (B) diffs_dir into Server
> (A)
> | throw NFS, I used to create filename.lock first into server (B) local
> file
> | then start copy filename to server (B) then remove filename.lock, so when
> | the daemon running on server (C) parses the files in the local_diffs dir,
> | ignores the files that are still being copied,
> |
> | After searching more yesterday, I found that local mv is atomic, so
> instead
> | of creating the lock files, I will copy the new diffs to tmp dir, and
> after
> | the copy is over, mv it to actual diffs dir, that will avoid reading It
> | while It's still being copied.
>
> Yes, this sounds good. Provided the mv is on the same filesystem.
>
> For example: "mv /tmp/foo /home/username/foo" is actually a copy and not
> a rename because /tmp is normally a different filesystem from /home.
>
> Yes they are in same file system, I am making sure of that ;)


> | Sorry if the above is bit confusing, the system is bit complex.
>
> Complex systems often need fiddly solutions.
>
> | Also there is one more factor that confuses me, I am so bad in testing,
> and
> | I am trying to start actually implement unit testing to test my code,
> what
> | I find hard is how to test code like the one that do the copy, mv and so,
> | also the code that fetch data from the web.
>
> Ha. I used to be very bad at testing, now I am improving and am merely
> weak.
>
> One approach to testing is to make a mock up of the other half of the
> system, and test against the mockup.
>
> For example, you have code to FTP new data and then feed it to (C). You
> don't control the server side of the FTP. So you might make a small mock
> up program that writes valid (but fictitious) data records progressively
> to a local data file (write record, flush, pause briefly, etc). If you
> can FTP to your own test machine you could then treat _that_ growing
> file as the remote server's data file.
>
> Then you could copy it progressively using a byte count to keep track of
> the bits you have seen to skip them, and the the
>
> If you can't FTP to your test system, you could abstract out the "fetch
> part of this file by FTP" into its own function. Write an equivalent
> function that fetches part of a local file just by opening it.
>
> Then you could use the local file version in a test that doesn't
> actually do the FTP, but could exercise the rest of it.
>
> It is also useful to make simple tests of small pieces of the code.
> So make the code to get part of the data a simple function, and write
> tests to execute it in a few ways (no new data, part of a record,
> several records etc).
>
> You are right, my problem is that I don't care about testing until my code
grows badly and then I notice what I got myself into :)
But ur suggestion is cool. I will try to implement that once I get back to
that project again... As I got some problems with another project currently
so I had to go fix them first.. and then the customer wante

RE: Python to Combine Multiple Excel Worksheets into One Worksheet

2012-02-16 Thread Prasad, Ramit
>I have one single Excel file with many separate worksheets, and for work I 
>need to combine all these separate worksheets into one single worksheet (I am 
>not worried about formatting, as the format is the same in each sheet, nor am 
>I worried about Excel's row limit).
>Essentially, I am looking for a way to append the data in one sheet to the 
>bottom of the sheet that proceeds it.

>What would be the best way to do this, and how would I go about doing it? Can 
>it be done simply with the xlwt, xlrd, and xutils modules, or (as I was 
>thinking) do I need to convert the sheets to separate csv files, then append 
>the separate csv files, and then write the completed file back into .xls 
>format? >Or perhaps something else?

>As I am really only a Python beginner, any and all help is very much 
>appreciated. Thank you in advance!!

Read the data from the different worksheets using xlrd and then use xlwt to 
write to a single worksheet in a new excel file. The csv option is probably not 
useful since it will just add an intermediary step unless you are converting 
outside of python (i.e. manually).

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

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


RE: TEST AN EXECUTABLE PYTHON SCRIPT SPEED UNDER A PYTHON SHELL

2012-02-16 Thread Prasad, Ramit
>> When you reply to a known bot, please include some indication of the 
>> fact, so we know your message can be ignored as well.

>Sometimes I wonder about 8. Is there a real person there, as well as the 
>bot? A lot of his/its 
posts look too intelligent to be computer-generated - or maybe I'm 
underestimating the quality of AI.

I was wondering the exact same thing.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

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


Re: TEST AN EXECUTABLE PYTHON SCRIPT SPEED UNDER A PYTHON SHELL

2012-02-16 Thread Arnaud Delobelle
On 16 February 2012 21:10, Prasad, Ramit  wrote:
>>> When you reply to a known bot, please include some indication of the
>>> fact, so we know your message can be ignored as well.
>
>>Sometimes I wonder about 8. Is there a real person there, as well as the 
>>bot? A lot of his/its
> posts look too intelligent to be computer-generated - or maybe I'm 
> underestimating the quality of AI.
>
> I was wondering the exact same thing.

I think it may be that what you are underestimating is your ability,
as a human being, to create meaning where there is none.

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


Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Daniel Fetchinson
On 2/16/12, Ian Kelly  wrote:
> On Thu, Feb 16, 2012 at 1:36 AM, Daniel Fetchinson
>  wrote:
 Hi folks, often times in science one expresses a value (say
 1.03789291) and its error (say 0.00089) in a short way by parentheses
 like so: 1.0379(9)

 One can vary things a bit, but let's take the simplest case when we
 only keep 1 digit of the error (and round it of course) and round the
 value correspondingly. I've been searching around for a simple
 function that would take 2 float arguments and would return a string
 but didn't find anything although something tells me it's been done a
 gazillion times.

 What would be the simplest such function?
>>>
>>> Well, this basically works:
>>>
>> def format_error(value, error):
>>> ... precision = int(math.floor(math.log(error, 10)))
>>> ... format = "%%.%df(%%d)" % max(-precision, 0)
>>> ... return format % (round(value, -precision),
>>> ...  int(round(error / 10 ** precision)))
>>> ...
>> format_error(1.03789291, 0.00089)
>>> '1.0379(9)'
>>>
>>> Note that "math.floor(math.log(error, 10))" may return the wrong
>>> decimal precision due to binary floating point rounding error, which
>>> could produce some strange results:
>>>
>> format_error(10378929, 1000)
>>> '10378900(10)'
>>>
>>> So you'll probably want to use decimals instead:
>>>
>>> def format_error(value, error):
>>> value = decimal.Decimal(value)
>>> error = decimal.Decimal(error)
>>> value_scale = value.log10().to_integral(decimal.ROUND_FLOOR)
>>> error_scale = error.log10().to_integral(decimal.ROUND_FLOOR)
>>> precision = value_scale - error_scale
>>> if error_scale > 0:
>>> format = "%%.%dE" % max(precision, 0)
>>> else:
>>> format = "%%.%dG" % (max(precision, 0) + 1)
>>> value_str = format % value.quantize(decimal.Decimal("10") **
>>> error_scale)
>>> error_str = '(%d)' % error.scaleb(-error_scale).to_integral()
>>> if 'E' in value_str:
>>> index = value_str.index('E')
>>> return value_str[:index] + error_str + value_str[index:]
>>> else:
>>> return value_str + error_str
>>>
>> format_error(1.03789291, 0.00089)
>>> '1.0379(9)'
>> format_error(103789291, 1000)
>>> '1.03789(1)E+08'
>>>
>>> I haven't tested this thoroughly, so use at your own risk. :-)
>>
>> Thanks a lot, this indeed mostly works, except for cases when the
>> error needs to be rounded up and becomes two digits:
>>
> format_error( '1.34883', '0.0098' )
>> '1.349(10)'
>>
>> But in this case I'd like to see 1.35(1)
>
> A small adjustment to the scale fixes that.  Also tidied up the string
> formatting part:
>
> import decimal
>
> def format_error(value, error):
> value = decimal.Decimal(value)
> error = decimal.Decimal(error)
> error_scale = error.adjusted()
> error_scale += error.scaleb(-error_scale).to_integral().adjusted()
> value_str = str(value.quantize(decimal.Decimal("1E%d" % error_scale)))
> error_str = '(%d)' % error.scaleb(-error_scale).to_integral()
> if 'E' in value_str:
> index = value_str.index('E')
> return value_str[:index] + error_str + value_str[index:]
> else:
> return value_str + error_str
>
> Cheers,
> Ian

Thanks, it's simpler indeed, but gives me an error for value=1.267, error=0.08:

Traceback (most recent call last):
  File "/home/fetchinson/bin/format_error", line 26, in 
print format_error( sys.argv[1], sys.argv[2] )
  File "/home/fetchinson/bin/format_error", line 9, in format_error
error_scale += error.scaleb( -error_scale ).to_integral(  ).adjusted(  )
  File "/usr/lib64/python2.6/decimal.py", line 3398, in scaleb
ans = self._check_nans(other, context)
  File "/usr/lib64/python2.6/decimal.py", line 699, in _check_nans
other_is_nan = other._isnan()
AttributeError: 'int' object has no attribute '_isnan'

Which version of python are you using?

Cheers,
Daniel



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Undoing character read from file

2012-02-16 Thread Emeka
Hello All,

I know about seek and tell while using readline. What about if I am using
read, and I want to undo the last character I just read(to return it back
to the stream). How do I achieve this?

Regards, \Emeka
*Satajanus  Nig. Ltd


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


Re: Undoing character read from file

2012-02-16 Thread MRAB

On 16/02/2012 23:10, Emeka wrote:

Hello All,

I know about seek and tell while using readline. What about if I am
using read, and I want to undo the last character I just read(to return
it back to the stream). How do I achieve this?


Try:

f.seek(-1, 1)

It seeks -1 relative to the current position (the second argument
defaults to 0 for relative to start of file).
--
http://mail.python.org/mailman/listinfo/python-list


Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Ian Kelly
On Thu, Feb 16, 2012 at 3:21 PM, Daniel Fetchinson
 wrote:
> Thanks, it's simpler indeed, but gives me an error for value=1.267, 
> error=0.08:
>
> Traceback (most recent call last):
>  File "/home/fetchinson/bin/format_error", line 26, in 
>    print format_error( sys.argv[1], sys.argv[2] )
>  File "/home/fetchinson/bin/format_error", line 9, in format_error
>    error_scale += error.scaleb( -error_scale ).to_integral(  ).adjusted(  )
>  File "/usr/lib64/python2.6/decimal.py", line 3398, in scaleb
>    ans = self._check_nans(other, context)
>  File "/usr/lib64/python2.6/decimal.py", line 699, in _check_nans
>    other_is_nan = other._isnan()
> AttributeError: 'int' object has no attribute '_isnan'
>
> Which version of python are you using?

2.7.1.  At a guess, it's failing because scaleb() (which was new in
2.6) is buggily expecting a decimal argument, but adjusted() returns an int.
Convert the results of the two adjusted() calls to decimals, and I
think it should be fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file synchronization

2012-02-16 Thread Cameron Simpson
On 16Feb2012 22:11, Sherif Shehab Aldin  wrote:
| First sorry for my very very late reply, has been overloaded at work last
| week :(

Me too.

There's no hurry at my end, take your time.

[...]
| > Can a simple byte count help here? Copy the whole file with FTP. From
| > the new copy, extract the bytes from the last byte count offset onward.
| > Then parse the smaller file, extracting whole records for use by (C).
| > That way you can just keep the unparsed tail (partial record I imagine)
| > around for the next fetch.
| >
| > Looking at RFC959 (the FTP protocol):
| >
| >  http://www.w3.org/Protocols/rfc959/4_FileTransfer.html
| >
| > it looks like you can do a partial file fetch, also, by issuing a REST
| > (restart) command to set a file offset and then issuing a RETR (retrieve)
| > command to get the rest of the file. These all need to be in binary mode
| > of course.
| >
| > So in principle you could track the byte offset of what you have fetched
| > with FTP so far, and fetch only what is new.
| 
|  I am actually grabbing the file from ftp with a bash script using lftp, It
| seemed a simple task for python at the beginning and then I noticed the
| many problems. I have checked lftp and did not know how to continue
| downloading a file. Do I have to use ftp library, may be in python so I can
| use that feature?

Looking at "man lftp" I see that the "get" command has a "-c" option
(for "continue"). That probably does it for you. Should be easy to test:

  - make big file on FTP server
  - fetch with lftp (interactively - this is all just to check)
  - append a little data to the file on the server
 date >> the-big-file
  - refetch:
  get -c the-big-file

and see how much data gets copied. Hopefully just the new bytes.

[...]
| > | After searching more yesterday, I found that local mv is atomic, so
| > instead
| > | of creating the lock files, I will copy the new diffs to tmp dir, and
| > after
| > | the copy is over, mv it to actual diffs dir, that will avoid reading It
| > | while It's still being copied.
| >
| > Yes, this sounds good. Provided the mv is on the same filesystem.
[...]
| > Yes they are in same file system, I am making sure of that ;)

Good.

BTW, when replying inline try to make sure your new text has clean blank
lines above and below and has not kept the indentation quote markers.
See above that your "Yes they are in same file system" seems to be at
the same indentation as my earlier sentence above? That made your reply
look like part of the quote instead of a reply, and I nearly missed it.

[...]
| > It is also useful to make simple tests of small pieces of the code.
| > So make the code to get part of the data a simple function, and write
| > tests to execute it in a few ways (no new data, part of a record,
| > several records etc).
| >
| > You are right, my problem is that I don't care about testing until my code
| grows badly and then I notice what I got myself into :)

(Again, see the quoting level?)

One approach to get into testing slowly is to make a test for your bug.
Suppose something is not working. Write a small function that exhibits
the bug, as small as possible. That is now a test function! When you fix
the bug, the test function will pass. Keep it around!

Some projects have tests for every bug report that gets fixed.

Another approach to growing a test suite is to write out a good docstring
for somthing, describing with precision what the function arranges
i.e. not the internal mechanisms, but what the caller can rely on being
true after the function has been called. Then write a test function that
calls the main function and then checks each thing the docstring says
should be true. Each check is a test.

Trite example:

  def double(x):
''' Return double the value of `x`.
The return value will be twice `x`.
The return value will be even.
'''
return x * 2

  class Tests(unitest.TestCase):
def test_double(self):
  for x in 0, 3, 17, 100:   # test a few different values
x2 = double(x)
self.assertEqual(x2, x + x) # test doubling
self.assertEqual(x2 % 2, 0) # test evenness

You can see that writing out the guarentees in the docstring assists in
writing some tests.

| > I really appreciate your help. I am trying to learn from the mailing list,
| I noticed many interesting posts in the list already. I wish I could read
| the python-list same way.. but unfortunately the mail digest they send is
| quiet annoying :(

I do not use digests - I have my subscription set to individual emails.
Just arrange that your mailer files then in a "python" mail folder when
they arrive so they do not clutter your inbox.

| Many thanks to you, and I will keep you posted if I got other ideas. :)

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

Q: How does a hacker fix a function which doesn't work for all of the elements 
in its domain?
A: He changes the domain.
-- 
http://mai

Generating class definitions at runtime in memory from XSD or JSON

2012-02-16 Thread Stodge
Does anyone know of a library to generate class definitions in memory,
at runtime, from XSD or JSON? I know about PyXB, generateDS and some
others, but they all rely on generating python source files at the
command line, and then using those to parse XML.

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


Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread Michael Torrie
On 02/16/2012 10:38 AM, Grant Edwards wrote:
> I got curious about Dalvik, and was looking at the Wikipedia page,
> where it says that programs for Android are compiled into bytecode in
> JVM compatible .class files.  Those files are then converted into .dex
> files to run on Davlik.
> 
> I don't know much at all about Jython, but if it generates JVM byte
> code, mightn't the same conversion to .dex be applicable?

I think it has to do with the fact that Jython does dynamic class
generation and loading.  Similarly I don't think JBoss or Tomcat could
be ported easily to Dalvik without making lots of changes to the class
loading stuff.  But I know nothing about Java, so I could be way wrong here.


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


Re: TEST AN EXECUTABLE PYTHON SCRIPT SPEED UNDER A PYTHON SHELL

2012-02-16 Thread gene heskett
On Thursday, February 16, 2012 08:40:04 PM Arnaud Delobelle did opine:

> On 16 February 2012 21:10, Prasad, Ramit  
wrote:
> >>> When you reply to a known bot, please include some indication of the
> >>> fact, so we know your message can be ignored as well.
> >>
> >>Sometimes I wonder about 8. Is there a real person there, as well
> >>as the bot? A lot of his/its
> >>
> > posts look too intelligent to be computer-generated - or maybe I'm
> > underestimating the quality of AI.
> > 
> > I was wondering the exact same thing.
> 
> I think it may be that what you are underestimating is your ability,
> as a human being, to create meaning where there is none.

Ouch!

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: 
Why do seagulls live near the sea?  'Cause if they lived near the bay,
they'd be called baygulls.
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter.Toplevel

2012-02-16 Thread yves


With a tkinter.Toplevel, how can I "disable" the parent windown and all its 
widget, in the same fashion as tkinter.messagebox?




--
Yves.  http://www.SollerS.ca/
   http://ipv6.SollerS.ca
   http://blog.zioup.org/
--
http://mail.python.org/mailman/listinfo/python-list


ANN: pyTenjin 1.1.0 - a high-speed and full-featured template engine

2012-02-16 Thread Makoto Kuwata
I released pyTenjin 1.1.0.
http://pypi.python.org/pypi/Tenjin/
http://www.kuwata-lab.com/tenjin/


Overview of pyTenjin


* Very fast: about 10 times faster than Django template engine
* Easy to learn: no need to learn template-original language
* Full-featured: nestable layout template, partial template, preprocessing, etc.
* Lightweight: only 2000 lines of code and very fast to import.
* Google App Engine supported


Documents
-

* User's Guide
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html
* Examples
  http://www.kuwata-lab.com/tenjin/pytenjin-examples.html
* CHANGES
  http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt


Install
---

$ sudo easy_install Tenjin

Or:

$ wget http://pypi.python.org/packages/source/T/Tenjin/Tenjin-1.1.0.tar.gz
$ tar xzf Tenjin-1.1.0.tar.gz
$ cd Tenjin-1.1.0/
$ sudo python setup.py install


Example
---

## views/example.pyhtml

${title}

  
  
  
${item}
  
  


## main.py
import tenjin
#tenjin.set_template_encoding('utf-8')  # optional (default 'utf-8')
from tenjin.helpers import *
from tenjin.html import *
engine = tenjin.Engine(path=['views'])
context = {'title': 'Example', 'items': ['Haruhi', 'Mikuru', 'Yuki'] }
output = engine.render('example.pyhtml', context)
print(output)

## output
$ python main.py
Example

  
Haruhi
  
  
Mikuru
  
  
Yuki
  



Enhancements and Changes in this release


(See http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt for details.)

* [Change] !! IMPORTANT!! Default cache file format is changed from
  marshal format to text format.
  You should remove all cache files to use this release.

* [Enhance] Embedded pattern '${}' and '#{}' can contain pair of '{' and '}'. ::

  ${foo({'x':1})}  # OK
  ${foo({}+{}+{})} # OK
  ${foo({'x':{'y':1}})}# NG

* [Enhance] New preprocessing mechanism. You can specify your own preprocessor
  class by 'pp' parameter.

* [Enhance] Add 'TrimPreprocessor' which removes spaces ad the
beginning of lines.
  You can reduce size of output by it.

* [Enhance] Add 'PrefixedLinePreprocessor' which converts ':: ...'
into ''.
  You may like ':: ...' because it is simpler than ''.

* [Enhance] Add 'JavaScriptPreprocessor' class which enables you to embed
  client-side javascript template code into server-side template.

  For example::

  


  
  
#{i}
${items[i]}
  
  


  
  #{tenjin.JS_FUNC}
  
var html = render_table(["Haruhi", "Mikuru", "Yuki"]);
document.getElementById('placehodler').innerHTML = html;
  

  will be converted into::

  
function render_table(items){var _buf='';
  _buf+='  \n';
   for (var i = 0, n = items.length; i < n; i++) {
  _buf+='\n\
\n\
\n\
  \n';
   }
  _buf+='  
'+_S(i)+''+_E(items[i])+'
\n'; return _buf;}; #{tenjin.JS_FUNC} var html = render_table(["Haruhi", "Mikuru", "Yuki"]); document.getElementById('placehodler').innerHTML = html; by JavaScriptPreprocessor. Notice that you should embed 'tenjin.JS_FUNC' to run client-side code. How to use it:: pp = [ tenjin.JavaScriptPreprocessor() ] engine = tenjin.Engine(pp=pp) output = engine.render('example.pyhtml', {}) print(html) * [Enhance] Now supports Jython 2.5.2. (thanks to Lars Hupfeldt Nielsen) * [Enhance] Now supports PyPy 1.7 or later officially. * [Change] Template#convert() now converts "\r\n" into "\\r\n". This is necessary to follow change of language specification on Python 2.7 and 3.2. Have fun! -- makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list

Re: [semi OT]: Smartphones and Python?

2012-02-16 Thread 88888 Dihedral
在 2012年2月16日星期四UTC+8下午11时22分44秒,Michael Torrie写道:
> On 02/16/2012 07:53 AM, 8 Dihedral wrote:
> > The law suites of JAVA Vitrtual Machine from Oracle
> > are famous now. But in 201X the JVM patents will be 
> > expired, thus it is not very urgent to chunk out a new jython now. Anyway 
> > just write codes that can be maintained and  ported to other languages and 
> > platforms
> > easily.
> 
> Umm what does this have to do with anything?
> 
> You claimed Jython is or will be available on Android. It's not and
> Jython isn't being ported to Dalvik and it has nothing to do with
> patents.  Android might use java a language, but the virtual machines
> are very different.  And no expired patents are going to change that
> fact.  Android simply isn't going to run the JVM anytime soon.

Android is a customized linux OS used in mobile phones.
I don't think any linux systm has to be locked by JAVA or any JVM to run 
applications.

The memory systems in mobile phones are different from
PCs. This is the current situation in the consumer
electronics sector.

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


Re: Numerical Linear Algebra in arbitrary precision

2012-02-16 Thread Tim Roberts
Ken  wrote:
>
>Brand new Python user and a bit overwhelmed with the variety of
>packages available.  Any recommendation for performing numerical
>linear algebra (specifically least squares and generalized least
>squares using QR or SVD) in arbitrary precision?  I've been looking at
>mpmath but can't seem to find much info on built in functions except
>for LU decomposition/solve.

It is been my experience that numpy is the best place to start with
requests like this, although I don't know whether it will actually solve
your specific tasks:

http://docs.scipy.org/doc/numpy/reference/routines.linalg.html
-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


question about function pointer

2012-02-16 Thread Zheng Li
def method1(a = None):
print a

i can call it by
method1(*(), **{'a' : 1})

I am just curious why it works and how it works?
and what do *() and **{'a' : 1} mean?

when I type *() in python shell, error below happens

  File "", line 1
*()
^
SyntaxError: invalid syntax

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