Getting number of hits from Google

2011-05-01 Thread neocortex
Hello!
For quite some time, I am looking for a solution to the problem of
getting number of hits for a list of, let say, 200-300 words, from a
search engine. I would prefer Google, but this seems not possible. I
tried with the PyGoogle (from http://code.google.com/p/pygoogle/), but
it stops delivering number of hits after 20-50 words.
Please, can anyone help me with this. I am starting to be desperate.

Sincerely,
PM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fibonacci series recursion error

2011-05-01 Thread Hans Georg Schaathun
On Sat, 30 Apr 2011 15:40:24 +0100, Paul Rudin
   wrote:
:  Anytime you have enough data... there are plenty of things that are natural 
to
:  represent as recursive data structures, and often you don't know in
:  advance how much data your code is going to have to deal with.

Sure, but one would think that if you can fit the data in memory,
then you can also fit the call stack.  I can also /imagine/ that one
might run into a limit, but I cannot see any concrete examples where
it is likely.

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


What other languages use the same data model as Python?

2011-05-01 Thread Steven D'Aprano
Python uses a data model of "name binding" and "call by object" (also 
known as "call by sharing"). I trust I don't need to define my terms, but 
just in case:

http://effbot.org/zone/call-by-object.htm
http://effbot.org/zone/python-objects.htm


Now, this is different from languages like C and Pascal, which is based 
on variables, or Forth, which explicitly manipulates a stack. Quite 
often, when people want to impress upon others that Python is not C, they 
will say:

"Python's data model is different from other languages"

which is perfectly correct, if you think of C as "other languages". But 
it's equally correct to say that Python's data model is the same as other 
languages. As I understand it, Python and Ruby have the same data model. 
So does Java, so long as you only consider objects and ignore unboxed 
native values. I believe (but could be wrong) that another language of 
about the same vintage as Python, Emerald, also uses the same model. 
That's not surprising, because I believe that Emerald (just like Python) 
was strongly influenced by CLU.

What other languages use the same, or mostly similar, data model as 
Python?



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


Re: Deditor

2011-05-01 Thread Alec Taylor
Maybe I'm missing something, but I downloaded the zip file and ran
each .py and .pyc file in turn, but none brought up the nice deditor
GUI I've seen screenshots of...

On the other subject, did you have a preference to what installer I
should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python competitions and learnings

2011-05-01 Thread Thomas 'PointedEars' Lahn
harrismh777 wrote:

> Terry Reedy wrote:
>>> And Im looking for feedback from peoples who best in python. Here I
>>> make some video tutorial about this service http://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 agree on all points, as well I would offer the suggestion to have
> parallel examples (in some cases) to help those trying to merge over to
> Python3.
> 
> But the most important point is that new users should start with 3.x,
> and should be encouraged to in that direction alone. I am finding it
> very frustrating trying to make all of the details changes solid in my
> mind for 3.x because there are so many of them for one, and for another
> because the details are so similar all at the same time. *Do not*
> confuse new learners with 2.x unless there is a point to it... for
> instance in our previous discussion of iterables-- noting that next() is
> the same for both versions, but in 2.x next(N) means N.next() and in
> version 3.x next(N) means N.__next__().
> 
> Otherwise, have new students hit 3.x running and never look back.

A more down-to-earth recommendation can be found at 



The bottom line of this for me is that while Python 3 has its advantages, at 
this point not only you cannot use Py3 everywhere, but also you still cannot 
do everything in Py3 that you can do in Py2 (most notably, you cannot create 
or process images, as PIL¹ is not yet Py3-ready).  Meaning that it would be 
a mistake to exclude Python 2 from education at this point.

_
¹ 

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-05-01 Thread Alec Taylor
I think ruby does

On Sun, May 1, 2011 at 6:45 PM, Steven D'Aprano
 wrote:
> Python uses a data model of "name binding" and "call by object" (also
> known as "call by sharing"). I trust I don't need to define my terms, but
> just in case:
>
> http://effbot.org/zone/call-by-object.htm
> http://effbot.org/zone/python-objects.htm
>
>
> Now, this is different from languages like C and Pascal, which is based
> on variables, or Forth, which explicitly manipulates a stack. Quite
> often, when people want to impress upon others that Python is not C, they
> will say:
>
> "Python's data model is different from other languages"
>
> which is perfectly correct, if you think of C as "other languages". But
> it's equally correct to say that Python's data model is the same as other
> languages. As I understand it, Python and Ruby have the same data model.
> So does Java, so long as you only consider objects and ignore unboxed
> native values. I believe (but could be wrong) that another language of
> about the same vintage as Python, Emerald, also uses the same model.
> That's not surprising, because I believe that Emerald (just like Python)
> was strongly influenced by CLU.
>
> What other languages use the same, or mostly similar, data model as
> Python?
>
>
>
> --
> Steven
> --
> 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-01 Thread Chris Rebert
On Sun, May 1, 2011 at 1:45 AM, Steven D'Aprano
 wrote:
> Python uses a data model of "name binding" and "call by object" (also
> known as "call by sharing").

> As I understand it, Python and Ruby have the same data model.
> So does Java, so long as you only consider objects and ignore unboxed
> native values. I believe (but could be wrong) that another language of
> about the same vintage as Python, Emerald, also uses the same model.
> That's not surprising, because I believe that Emerald (just like Python)
> was strongly influenced by CLU.
>
> What other languages use the same, or mostly similar, data model as
> Python?

According to http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing
, besides those you already listed:
Scheme, OCaml, AppleScript, and possibly VB, among "many other languages".

I can't personally vouch for the accuracy of this.

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


Re: Fibonacci series recursion error

2011-05-01 Thread Steven D'Aprano
On Sun, 01 May 2011 09:18:36 +0100, Hans Georg Schaathun wrote:

> On Sat, 30 Apr 2011 15:40:24 +0100, Paul Rudin
>wrote:
> :  Anytime you have enough data... there are plenty of things that are
> natural to :  represent as recursive data structures, and often you
> don't know in :  advance how much data your code is going to have to
> deal with.
> 
> Sure, but one would think that if you can fit the data in memory, then
> you can also fit the call stack.  I can also /imagine/ that one might
> run into a limit, but I cannot see any concrete examples where it is
> likely.


Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call 
stack allocated. The call stack can't grow indefinitely. If it does, you 
get a stack overflow:

http://www.ehow.com/list_6572027_reasons-stack-overflow.html

which, if you're lucky, will just crash the process. If you're unlucky, 
it will lead to an exploit that malware can use to compromise your 
machine.

In Python, the virtual machine protects you against stack overflow. 
Before the stack overflows, Python raises RecursionError. You can 
experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but 
be careful, if you increase the limit too high, a deeply recursive 
function will overflow the stack.


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


Re: Fibonacci series recursion error

2011-05-01 Thread Hans Georg Schaathun
On 01 May 2011 09:04:27 GMT, Steven D'Aprano
   wrote:
:  Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call 
:  stack allocated. The call stack can't grow indefinitely. If it does, you 
:  get a stack overflow:

Of course you do, but you are still only saying that there might be 
an application where this might happen because of excessive although
logically correct recursion.  You have not given a single example where 
it actually happened.

:  In Python, the virtual machine protects you against stack overflow. 
:  Before the stack overflows, Python raises RecursionError. You can 
:  experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but 
:  be careful, if you increase the limit too high, a deeply recursive 
:  function will overflow the stack.

But the recursion limit is mainly there to protect you against faulty
base cases.  Obviously, since it measures the number of items on the
stack and not their size.

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


JSONBOT 0.7 RELEASED

2011-05-01 Thread Bart Thate
0.7 RELEASE NOTES
=

Hello world, greetings to all and everybody on this little planet ;]

Today I am releasing version 0.7 of JSONBOT, hope you like it.

I want to dedicate this release to Annemiek, Kirsten, Danny and
Doscha, i would not have a live without you.

changes in this release
---

* we got jsonbot.org running .. see http://jsonbot.org ;]
* convore support
* refactored core
* reloadable config files
* revamped web console
* resource files (contain commands the bot can execute)
* file change detection for myplugs plugins
* rebooting is fixed
* fixed relaying in jabber conference rooms
* added color.py plugin to color certain words
* added geo.py, googletranslate.py and imdb.py (thnx melmoth)
* chatlog plugin now uses the logging module .. log file rotates every
day
* many other bugfixes

If you have programmed your own plugin see
http://jsonbot.org/handbook/UPGRADE.html for upgrade notes.

Todo


1) fix runtime setting of loglevel
2) add flood control
3) docs docs docs docs docs
4) fix bugs

see http://code.google.com/p/jsonbot/issues/list

Source
--

* tarball - http://jsonbot.googlecode.com
* mercurial - http://jsonbot.googlecode.com/hg
* github - https://github.com/jsonbot

Demo


* webconsole - http://jsonbot.appspot.com
* xmpp - json...@jsonbot.org (shell) and json...@appspot.com (GAE)
* IRC - jsonbot on irc.freenode.net
* Convore - https://convore.com/convore-8/welcome-to-convore/ relaying
with #convore on irc.freenode.net

Docs


* new jsonbot.org site .. http://jsonbot.org
* GAE backup docs .. http://jsonbot.appspot.com/docs

Contact
---

* twitter: https://twitter.com/#!/jsonbot
* facebook: http://tinyurl.com/jsonbot
* email: bth...@gmail.com
* IRC: dunker in channel #dunkbots / irc.freenode.net* xmpp:
bth...@gmail.com and b...@jsonbot.org

About
-

JSONBOT is a remote event-driven framework for building bots that talk
JSON
to each other over XMPP.

This distribution provides bots built on this framework for console,
IRC,
XMPP and Convore for the shell and WWW and XMPP for the Google
Application engine.

JSONBOT is all of the following:

* a shell console bot
* a shell IRC bot
* a shell XMPP bot
* a shell Convore bot
* a Web bot running on Google Application Engine
* a XMPP bot running on Google Application Engine
* a Google Wave bot running op Google Application Engine
* the XMPP bots are used to communicate between bots
* plugin infrastructure to write your own functionality
* event driven framework by the use of callbacks

Install
---

You dont need to run the bot on GAE when you just want to use the
shell bots of JSONBOT. JSONBOT can best be run from the bot dir, the
bot is self contained and has all the dependancies that are needed:

* "hg clone http://jsonbot.googlecode.com/hg mybot" or download and
untar the tarball.
* cd into the bot dir and run "./bin/jsb" .. if the bot is working
correctly you will get the console version of JSONBOT
* same can be done for "./bin/jsb-xmpp", "./bin/jsb-convore" etc. ..
check the bin dir for programs you can start
* try the --help option to a program to see what command line options
are available.
* you DONT need root for this

Ofcourse you can always run "python setup.py install" or "easy_install
-U jsb" when you do want to install the bot globaly.
Debian packages are on their way, but might still take time as the
ftpmeisters need to approve ;]

Thats it ! hope you enjoy this version of JSONBOT ;]

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


Re: Fibonacci series recursion error

2011-05-01 Thread Steven D'Aprano
On Sun, 01 May 2011 10:27:14 +0100, Hans Georg Schaathun wrote:

> On 01 May 2011 09:04:27 GMT, Steven D'Aprano
>wrote:
> :  Why? You might have 4000 MB of main memory, and only 2 MB (say?) of
> call :  stack allocated. The call stack can't grow indefinitely. If it
> does, you :  get a stack overflow:
> 
> Of course you do, but you are still only saying that there might be an
> application where this might happen because of excessive although
> logically correct recursion.  You have not given a single example where
> it actually happened.

Just google on "stack overflow crash".


> :  In Python, the virtual machine protects you against stack overflow. :
>  Before the stack overflows, Python raises RecursionError. You can : 
> experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but
> :  be careful, if you increase the limit too high, a deeply recursive : 
> function will overflow the stack.
> 
> But the recursion limit is mainly there to protect you against faulty
> base cases.  Obviously, since it measures the number of items on the
> stack and not their size.

The Python virtual machine knows how big each entry on the stack needs to 
be. (I don't, but it's got to be at least the size of a pointer.) So 
"number of items" is just a multiplication away from "size of the items".

In practice the main reason that stacks overflow is because of faulty 
base cases in recursion. That's obvious. But in principle, any 
sufficiently large number of function calls could overflow the stack. If 
the call stack is (say) 1 MB (chosen only to make the maths easier), and 
each function call requires (say) a single four-byte entry on the stack, 
then you can have a maximum of 25 function calls before overflowing 
the stack.

If you don't like my numbers -- and you probably shouldn't, since I made 
them up -- choose your own. But whatever numbers you choose, there *must* 
be a maximum number of function calls before the stack overflows.

Not necessarily recursive function calls either: any nested function call 
will do. However, it's generally only in recursion that you have more 
than a few hundred calls on the stack.

So even if the base case is correct, you can overflow the stack. Given 
the naive recursive factorial function:

def fact(n):
if n <= 1: return 1
return n*fact(n-1)

and the theoretical limit above, then fact(250001) will overflow the 
stack even though the base case is correct.


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


Re: minimal python27.dll?

2011-05-01 Thread Martin v. Loewis
> I have vague recollections that pythonXY.dll could not be statically
> linked on Windows, or that doing so causes some serious loss of
> functionality.  Was this ever true, and is it still?

You'll have to rebuild Python to make use of static linkage, of course,
but then: it is certainly possible. The main functionality that you
lose is the ability to load extension modules (.pyd files). Whether
that's a serious loss or not depends on your application - in cases
where you want static linkage, you can often accept not being able
to do dynamic linkage.

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


Re: minimal python27.dll?

2011-05-01 Thread Martin v. Loewis
> On the CJK issue, why python ship its own codec, not using OS builtin?

The OS doesn't provide all the codecs that Python provides. For the one
it does provide, it behaves semantically different in border cases from
the ones that come with Python.

> If I don't need the full Unicode5.1 can I just map python's unicode
> functions to some Win32 unicode API?

That should be possible - but I doubt it's a matter of "just".

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


Re: Fibonacci series recursion error

2011-05-01 Thread Hans Georg Schaathun
On 01 May 2011 11:56:57 GMT, Steven D'Aprano
   wrote:
:  Just google on "stack overflow crash".

And I get loads of examples of stack overflows, but I could not see
anybody linking this to logically correct recursion.  Wikipedia, for
instance, mentions two common causes, neither of which has anything
to do with logically correct recursion.  

:  The Python virtual machine knows how big each entry on the stack needs to 
:  be. (I don't, but it's got to be at least the size of a pointer.) So 
:  "number of items" is just a multiplication away from "size of the items".

Does it?  In a conventional stack you need to store all the local
variables for the function as well.  Thus, there is no limit to how
much space a single element on the stack may require.

:   But in principle, any 
:  sufficiently large number of function calls could overflow the stack.
:  (...)
:  If you don't like my numbers -- and you probably shouldn't, since I made 
:  them up -- choose your own. But whatever numbers you choose, there *must* 
:  be a maximum number of function calls before the stack overflows.

But all of this is in principle, and does not constitute any valid
reason to avoid recursion in practice.  If you want to argue that
recursion is a bad thing in /practice/ you need a /practical/ argument.

There is also a limit to how far you can usefully recurse over a limited
data structure.

:  def fact(n):
:  if n <= 1: return 1
:  return n*fact(n-1)
: 
:  and the theoretical limit above, then fact(250001) will overflow the 
:  stack even though the base case is correct.

Of course that will overflow, but you are now trying to calculate an
integer of several /million/ bits.  Please suggest me a current-day
application where you would want to have and also be able to use such
a number.

There are many ways to crash a system if you want to.

But if you don't deliberately try to crash it, you are much more
likely to crash it because you allocate to much memory in each step
than because the recursion gets to deep.  Consequently, because recursion
is usually a clearer form of expression than iterative loops, recursion
may actually be /less/ dangerous.


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


skipping one unittest assertion?

2011-05-01 Thread Roy Smith
Is there any way to skip a single assertion in a unittest test method?  
I know I can @skip or @expectedFailure the method, but I'm looking for 
something finer-grain than that.

There's one particular assertion in a test method which depends on 
production code that hasn't been written yet.  I could factor that out 
into its own test methods and @skip that, but it would be cleaner to be 
able to mark the particular assertion.

(using python 2.6, but importing unittest2 from 2.7)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: skipping one unittest assertion?

2011-05-01 Thread Ben Finney
Roy Smith  writes:

> There's one particular assertion in a test method which depends on 
> production code that hasn't been written yet.  I could factor that out 
> into its own test methods and @skip that, but it would be cleaner to be 
> able to mark the particular assertion.

I think that's backward. If there are multiple conditions to assert,
then it's much cleaner to put them in distinct test case methods.

Each test case should be testing one thing: if it fails, it should be
for exactly one reason.

-- 
 \ “When people believe that they have absolute knowledge, with no |
  `\ test in reality, this [the Auschwitz crematorium] is how they |
_o__) behave.” —Jacob Bronowski, _The Ascent of Man_, 1973 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deditor

2011-05-01 Thread Kruptein
On 1 mei, 10:59, Alec Taylor  wrote:
> Maybe I'm missing something, but I downloaded the zip file and ran
> each .py and .pyc file in turn, but none brought up the nice deditor
> GUI I've seen screenshots of...
>
> On the other subject, did you have a preference to what installer I
> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi)

not a msi, for the rest it doesn't matter :),  on my windows if you
run deditor.py   it should launch however you need to have the
wxpython-2.8 package installed,   what happens if you run deditor.py
from console?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: skipping one unittest assertion?

2011-05-01 Thread Michael Kent
I agree that each test should test only one 'thing', but it's also true that 
testing one 'thing' sometimes/often involves multiple assertions.  But in the 
OP's case, it does sound like the assertion he wants to skip should be broken 
out into its own test.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE/text-editor

2011-05-01 Thread Yico Gaga
  foolDE :)!!!

2011/4/29 Alec Taylor 

> Your probably right.
>
> I suppose I'll just wait till I finish my fooIDE project
>
> > On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst
> >  wrote:
> >> In article ,
> >> Alec Taylor   wrote:
> >>>Geany I've tried in the past, it's really buggy on my home computer
> >>>and at Uni... however from my phone it works wonderfully! (Use it for
> >>>C++ projects on Rhobuntu)
> >>>
> >>>Eric 4 was suggested to me on the #python channel on Freenode...
> >>>however I've never been able to get it compiled/working. Too many
> >>>dependencies I'm guessing...
> >>>
> >>>PTK looks great, and does everything I want (from screenshots).
> >>>Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1
> >>>x64, WxPython 2.8 x64. Install ran as admin.
> >>>
> >>>Emacs and vim still seem like good alternatives, when I get the time.
> >>>However, currently have 3 assignments to start and finish so would
> >>>like a simple Notepad2 with python interpreter attached (and keyboard
> >>>shortcut to run script) type program.
> >>>
> >>>Please continue recommending
> >>>
> >>>Thanks,
> >>>
> >>>Alec Taylor
> >>
> >> You will never be satisfied, until you've written something yourself.
> >> Start writing now. A friend of mine started writing in 1983,
> >> and since 1985 I'm a happy user. The only language that is a candidate
> >> to write in is C, however.
> >>
> >> Groetjes Albert
> >>
> >> --
> >> --
> >> Albert van der Horst, UTRECHT,THE NETHERLANDS
> >> Economic growth -- being exponential -- ultimately falters.
> >> albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
> >>
> >> --
> >> 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: Python IDE/text-editor

2011-05-01 Thread Alec Taylor
!!!

=]

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

Contact me if you'd like to join the project :D

On Mon, May 2, 2011 at 1:39 AM, Yico Gaga  wrote:
>   foolDE :)!!!
>
> 2011/4/29 Alec Taylor 
>>
>> Your probably right.
>>
>> I suppose I'll just wait till I finish my fooIDE project
>>
>> > On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst
>> >  wrote:
>> >> In article ,
>> >> Alec Taylor   wrote:
>> >>>Geany I've tried in the past, it's really buggy on my home computer
>> >>>and at Uni... however from my phone it works wonderfully! (Use it for
>> >>>C++ projects on Rhobuntu)
>> >>>
>> >>>Eric 4 was suggested to me on the #python channel on Freenode...
>> >>>however I've never been able to get it compiled/working. Too many
>> >>>dependencies I'm guessing...
>> >>>
>> >>>PTK looks great, and does everything I want (from screenshots).
>> >>>Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1
>> >>>x64, WxPython 2.8 x64. Install ran as admin.
>> >>>
>> >>>Emacs and vim still seem like good alternatives, when I get the time.
>> >>>However, currently have 3 assignments to start and finish so would
>> >>>like a simple Notepad2 with python interpreter attached (and keyboard
>> >>>shortcut to run script) type program.
>> >>>
>> >>>Please continue recommending
>> >>>
>> >>>Thanks,
>> >>>
>> >>>Alec Taylor
>> >>
>> >> You will never be satisfied, until you've written something yourself.
>> >> Start writing now. A friend of mine started writing in 1983,
>> >> and since 1985 I'm a happy user. The only language that is a candidate
>> >> to write in is C, however.
>> >>
>> >> Groetjes Albert
>> >>
>> >> --
>> >> --
>> >> Albert van der Horst, UTRECHT,THE NETHERLANDS
>> >> Economic growth -- being exponential -- ultimately falters.
>> >> albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
>> >>
>> >> --
>> >> 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: Deditor

2011-05-01 Thread Alec Taylor
Traceback (most recent call last):
 File "O:\deditor\deditor\deditor.py", line 7, in 
   import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel
 File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4
5, in 
   from wx._core import *
 File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i
n 
   import _core_
ImportError: DLL load failed: %1 is not a valid Win32 application.

On Mon, May 2, 2011 at 12:33 AM, Kruptein  wrote:
> On 1 mei, 10:59, Alec Taylor  wrote:
>> Maybe I'm missing something, but I downloaded the zip file and ran
>> each .py and .pyc file in turn, but none brought up the nice deditor
>> GUI I've seen screenshots of...
>>
>> On the other subject, did you have a preference to what installer I
>> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi)
>
> not a msi, for the rest it doesn't matter :),  on my windows if you
> run deditor.py   it should launch however you need to have the
> wxpython-2.8 package installed,   what happens if you run deditor.py
> from console?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: skipping one unittest assertion?

2011-05-01 Thread Roy Smith
In article <87wriah4qg@benfinney.id.au>,
 Ben Finney  wrote:

> Roy Smith  writes:
> 
> > There's one particular assertion in a test method which depends on 
> > production code that hasn't been written yet.  I could factor that out 
> > into its own test methods and @skip that, but it would be cleaner to be 
> > able to mark the particular assertion.
> 
> I think that's backward. If there are multiple conditions to assert,
> then it's much cleaner to put them in distinct test case methods.
> 
> Each test case should be testing one thing: if it fails, it should be
> for exactly one reason.

Well, yeah, that's certainly the XP/unit-test doctrine.  In practice 
however, tests often get written as "do a bunch of stuff to get some 
result, then make a bunch of assertions about that result".

Sure, you could make each of those assertions a distinct method, and 
factor the "do a bunch of stuff" into setUp().  Which probably means 
factoring those methods out into a new TestCase subclass.  At some 
point, however practicality trumps doctrine.

I notice the Python internal tests adopt exactly the same attitude.  
Here's an example from 3.2's test_urllib.py:

def test_fileno(self):
file_num = self.returned_obj.fileno()
self.assertIsInstance(file_num,
  int,
 "fileno() did not return an int")
self.assertEqual(os.read(file_num, len(self.text)),
   self.text,
   "Reading on the file descriptor returned by fileno() "
   "did not return the expected text")

I've got a remote API which at some point returns a URL (wrapped up in a 
larger JSON-ized object).  I want to make several assertions about the 
object.  It should be valid JSON.  It should unpack to yield an object 
(well, dict in python) with certain attributes.  Those values of those 
attributes should be of the correct types, etc.  So:

self.assertIsInstance(station['id'], int)
self.assertIsInstance(station['name'], unicode)
self.assertIsInstance(station['cover_url'], unicode)

The next assertion (the one that I know will fail because the server 
code hasn't been written yet) is that cover_url refers to a get-able 
jpeg image.  It would be convenient and useful to write the assertion 
now and mark that I expect it to fail until the server code catches up.

Breaking all this up into distinct test methods would be silly.  In 
fact, it would be wrong.  If they were different methods, they would not 
be making multiple assertions against one object retrieved from the 
external service, they would be making a series of assertions against a 
series of different objects.  And, unlike pure unit-test doctrine would 
like to believe, external services have state.  And per-interaction cost 
(in our case, real cost; some queries result in us paying a few 
mili-cents to a third-party data provider :-))

I guess I'll just mark the whole method @expectedFailure and let it go 
at that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deditor

2011-05-01 Thread Kruptein
On 1 mei, 17:50, Alec Taylor  wrote:
> Traceback (most recent call last):
>  File "O:\deditor\deditor\deditor.py", line 7, in  e>
>    import wx, os, datetime, sys, ConfigParser, wx.aui, wx.lib.scrolledpanel
>  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 
> 4
> 5, in 
>    from wx._core import *
>  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, 
> i
> n 
>    import _core_
> ImportError: DLL load failed: %1 is not a valid Win32 application.
>
>
>
> On Mon, May 2, 2011 at 12:33 AM, Kruptein  wrote:
> > On 1 mei, 10:59, Alec Taylor  wrote:
> >> Maybe I'm missing something, but I downloaded the zip file and ran
> >> each .py and .pyc file in turn, but none brought up the nicededitor
> >> GUI I've seen screenshots of...
>
> >> On the other subject, did you have a preference to what installer I
> >> should code for it? - InnoSetup (exe), NSIS (exe) or MSI (.msi)
>
> > not a msi, for the rest it doesn't matter :),  on my windows if you
> > rundeditor.py   it should launch however you need to have the
> > wxpython-2.8 package installed,   what happens if you rundeditor.py
> > from console?
> > --
> >http://mail.python.org/mailman/listinfo/python-list

that looks like you have installed the wxpython module wrongly.  Have
you downloaded the version that matches your python version?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python competitions and learnings

2011-05-01 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

thanks for your translation. It's already published on site. And I
will wait for your mail
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Development tools and practices for Pythonistas

2011-05-01 Thread Dietmar Schwertberger

Am 01.05.2011 02:47, schrieb Shawn Milochik:

Look at the big two sites for open-source repositories -- github and
bitbucket. One's git, the other Mercurial. I don't think you can go
wrong picking either one.


Can any of those be used from Python as a library, i.e. something like
import Hg
r = Hg.open(path)

When I had a look at Mercurial, which is implemented in Python,
it was implemented in a way that I could not do that. It was implemented
as rather monolithic program which could be used from os.system(...)
only.
With a good API, I could easily have integrated it into my development
flow. I have a codebase which is shared between different projects and
there are many small changes on many different PCs.
In theory a distributed VCS is good at supporting that, but in practice
I went back to my lightweight synchronization scripts and file storage
again. With the API, I could have best of both worlds.


Regards,

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


Re: Python competitions and learnings

2011-05-01 Thread Alexander Lyabah
On May 1, 3:26 am, harrismh777  wrote:
> Alexander Lyabah wrote:
> > What do you think about it?
>
> > I'm also have a not a very good English, so I need help with it too,
>
> Alexander, your site is very interesting. I spent some time this
> afternoon appreciating your work. Nice job.
>
> Be encouraged, your English is much better than my Russian! I also
> looked over the orphanage site and I appreciate how much you are doing
> there in Ukraine for the children. Keep up the good work.
>
> I too am a little disappointed that Python3 is not being used. I want to
> encourage you to work in that direction as well. I may have some time to
> volunteer to checkio.org; for help with the English, and maybe with some
> help as a tester. We'll see... I have a lot of my own fish to fry here,
> as we say in America.
>
> Blessings on your work, friend.
>
> m harris

I spend a lot of time to make a almost full support of python 2.7 from
sandbox.

If somebody help me this sandboxed python 3.* i will add support of it
on checkio.org with big pleasure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python competitions and learnings

2011-05-01 Thread Alexander Lyabah
And what do you think about Score Games and competitions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: skipping one unittest assertion?

2011-05-01 Thread OKB (not okblacke)
Roy Smith wrote:

> Is there any way to skip a single assertion in a unittest test
> method?  I know I can @skip or @expectedFailure the method, but I'm
> looking for something finer-grain than that.
> 
> There's one particular assertion in a test method which depends on 
> production code that hasn't been written yet.  I could factor that
> out into its own test methods and @skip that, but it would be
> cleaner to be able to mark the particular assertion.
> 
> (using python 2.6, but importing unittest2 from 2.7)

Can't you just comment out that line?

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
--author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: skipping one unittest assertion?

2011-05-01 Thread Roy Smith
In article ,
 "OKB (not okblacke)"  wrote:

> Roy Smith wrote:
> 
> > Is there any way to skip a single assertion in a unittest test
> > method?  I know I can @skip or @expectedFailure the method, but I'm
> > looking for something finer-grain than that.
> > 
> > There's one particular assertion in a test method which depends on 
> > production code that hasn't been written yet.  I could factor that
> > out into its own test methods and @skip that, but it would be
> > cleaner to be able to mark the particular assertion.
> > 
> > (using python 2.6, but importing unittest2 from 2.7)
> 
>   Can't you just comment out that line?

Sure, but the point of @skip and @expectFailure is that they leave a 
visible trail in the test output that you need to go back and fix 
something.
-- 
http://mail.python.org/mailman/listinfo/python-list


wxGrid, PyGridTableBase, strange SWIG error message!

2011-05-01 Thread Laszlo Nagy
I'm trying to create a special widget that is a wx.Grid and also a 
PyGridTableBase. In my special case of application, I really need to 
have a grid that uses itself for getting cell data and cell attributes.


Here is a test program, demonstrating my problem:

import wx
from wx.grid import Grid,PyGridTableBase

class SpecialGrid(Grid,PyGridTableBase):
def __init__(self,*args,**kwargs):
PyGridTableBase.__init__(self)
Grid.__init__(self,*args,**kwargs)
self.SetTable(self)

def SetTable(self,table):
if table is not self:
raise Exception("Grid must be its own table!")
else:
PyGridTableBase.SetTable(self,self,takeOwnership=False)

app=wx.App(redirect=None)
frame=wx.Frame(None)
g = SpecialGrid(parent=frame)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(g,1,wx.EXPAND)
frame.SetSizer(sizer)
frame.Show()
frame.Maximize()
app.MainLoop()


This program throws:

Traceback (most recent call last):
  File "test.py", line 18, in 
g = SpecialGrid(parent=frame)
  File "test.py", line 6, in __init__
PyGridTableBase.__init__(self)
  File 
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line 
910, in __init__
self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self, 
PyGridTableBase)
  File 
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 
3886, in _setOORInfo

val = _core_.EvtHandler__setOORInfo(*args, **kwargs)
TypeError: in method 'EvtHandler__setOORInfo', expected argument 1 of 
type 'wxEvtHandler *'


This makes no sense to me. If I swap the constructor calls:

def __init__(self,*args,**kwargs):
Grid.__init__(self,*args,**kwargs)
PyGridTableBase.__init__(self)
self.SetTable(self)

Then I get this:

Traceback (most recent call last):
  File "test.py", line 18, in 
g = SpecialGrid(parent=frame)
  File "test.py", line 7, in __init__
PyGridTableBase.__init__(self)
  File 
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/grid.py", line 
910, in __init__
self._setOORInfo(self);PyGridTableBase._setCallbackInfo(self, self, 
PyGridTableBase)
  File 
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 
3887, in _setOORInfo

args[0].this.own(False)
  File 
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 
14586, in __getattr__

raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the SpecialGrid object has 
been deleted, attribute access no longer allowed.


What the heck?

Thanks,

   Laszlo

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


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

2011-05-01 Thread Terry Reedy

On 5/1/2011 4:45 AM, Steven D'Aprano wrote:

Python uses a data model of "name binding" and "call by object"
(also known as "call by sharing"). I trust I don't need to define my
terms, but just in case:

http://effbot.org/zone/call-by-object.htm
http://effbot.org/zone/python-objects.htm


Now, this is different from languages like C and Pascal, which is
based on variables,


Or Fortran or Basic (and I suspect, but do not know, Algol) and other
descendents: Ada?, PL/1?). In statistical languages, user-defined names
typically refer to typed data columns (eash a set of storage locations) 
or user-defined functions.



"Python's data model is different from other languages"

which is perfectly correct, if you think of C as "other languages".
But it's equally correct to say that Python's data model is the same
as other languages.


You defined Python's 'data model' as having two aspects: 'name binding' 
and 'call by object'. A language could match one but not the other. I 
believe Lisps have name-binding, but I know not all only have 
call-object. Macro calls (and earlier predecessors) are call-by-code-text.


 As I understand it, Python and Ruby have the same

data model. So does Java, so long as you only consider objects and
ignore unboxed native values. I believe (but could be wrong) that
another language of about the same vintage as Python, Emerald, also
uses the same model. That's not surprising, because I believe that
Emerald (just like Python) was strongly influenced by CLU.


While Guido does not, that I know of, credit CLU as Python's direct 
inspiration, I think it (and Barbara Liskov) as the originator of 
Python's data model. I believe she thought of the call-by-object 
semantics as something of an innovation.



What other languages use the same, or mostly similar, data model as
Python?


Natural languages. That is why I think it is better to think of Python 
as an algorithm language or information-object manipulation language 
rather than as just a linear-memory machine language. A linear memory 
with bytes addressed from 0 to max-int or max-long is an explicit part 
of the definition of assembly languages and C. It is no part of the 
definition of Python.


Nice begin-a-thread post.

--
Terry Jan Reedy

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


Re: [OT] VCS for non-text (was Development tools and practices for Pythonistas)

2011-05-01 Thread Martin Schöön
On 2011-04-30, Tim Chase  wrote:
> On 04/30/2011 04:15 AM, Martin Schöön wrote:
>> You guys are very code focused, which is natural given where we are.
>>
>> Having absorbed what I have seen here, looked a little at Mercurial,
>> read a little on the webs of Fossil and Bazaar I start to think there
>> is great merit in all this VCS stuff for other types of projects.
>>
>> At work my projects contain very little coding (some Python, some
>> matlab/scilab perhaps) but a fair amount of CAD/CAE, written
>> reports, presentations (OpenOffice and that other Office),
>> spread sheets etc etc. A mixture of ascii-files and various
>> proprietary formats most of which is stored in binary form.
>> Some of the CAE-work generate pretty big files stored
>> in dynamically created subdirectories.
>
> For non-text blobs, it takes a little bit of insight to get the 
> most out of them.  For OpenDocument (Open/Libre Office 
> documents), they're zipped files containing text/XML which can be 
> diff'ed with more meaning.  Usually there are custom filters for 
> git[1], Mercurial[2] and Bazaar[3] which will unpack the zipped 
> file contents before committing and give you more sensible diffs. 
>   Likewise, for images (gif/jpg/tiff/raw/etc), there are 
> particular image-diff programs which make it easier to tell what 
> happened, as the textual diff of binary files is pretty useless. 
>   However some images (such as .svg files) are XML/text inside, 
> and diff pretty nicely without extra effort.
>
> I can't speak to CAD/CAE, but it would have to be addressed on a 
> per-format basis in your given VCS.  That said, you *can* store 
> the binary blobs in each, it's just not as useful without 
> meaningful comparisons.
>
> -tkc
>
> [1]
> http://kerneltrap.org/mailarchive/git/2008/9/15/3305014
>
> [2]
> http://mercurial.selenic.com/wiki/HandlingOpenDocumentFiles
>
> [3]
> http://doc.bazaar.canonical.com/plugins/en/oodiff.html
>
All very useful information. Thank you for that Tim.

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


Re: Py_INCREF() incomprehension

2011-05-01 Thread Hegedüs Ervin
hello,

On Wed, Apr 27, 2011 at 11:58:18AM +0200, Thomas Rachel wrote:
> Am 26.04.2011 20:44, schrieb Hegedüs Ervin:
> 
> >and (maybe) final question: :)
> >
> >I defined many exceptions:
> >
> >static PyObject *cibcrypt_error_nokey;
> >static PyObject *cibcrypt_error_nofile;
> >static PyObject *cibcrypt_error_badpad;
> >...
> >
> >void handle_err(int errcode) {
> > switch(errcode) {
> > case -1:PyErr_SetString(cibcrypt_error_nokey, "Can't find 
> > key.");
> > break;
> >...
> >}
> >...
> > cibcrypt_error_nokey = PyErr_NewException("cibcrypt.error_nokey", NULL, 
> > NULL);
> >...
> > PyModule_AddObject(o, "error", cibcrypt_error_nokey);
> 
> Then I would not use the name "error" here, but maybe "error_nokey"
> or even better "NoKeyException".
> 
> Oops: there is an inconsistency in the docu: on the one hand, it says
> 
>   There are exactly two important exceptions to this rule:
>   PyTuple_SetItem() and PyList_SetItem().
> 
> stating these are the only ones who take over ownership.
> 
> But PyModule_AddObject() claims to "steal" a reference as well...
> 
> 
> >I am right, here also no need any Py_INCREF()/Py_DECREF() action,
> >based on this doc:
> >http://docs.python.org/c-api/arg.html
> 
> I'm not sure: On one hand, you pass ownership of the error objects
> to the module. There - one could think - they are until the module
> is unloaded.
> 
> But what if someone does "del module.NoKeyException"? In this case,
> the object could have been destroyed, and you are using it -> BANG.
> 
> On the other hand, if you keep one instance internally, it is not
> possible any longer to unload the module without a memory leak...
> 
> 
> As already stated - you might want to have a look at some other C
> modules and mimic their behaviour... (and hope they are doing it
> right...)

so, I've checked it - there wasn't any Py_INCREF(), I just calmed
down.

But. :)

My module contains just 4 functions (in C), which translate 3rd
party lib to Python. The name would be _mycrypt.so example.

I wrapped it a pure Python module, its name is mycrypt.py.

Then, I've import pure Python module in a main program, like
this:

=%=
mycrypt.py:

import _mycrypt
...
=%=

=%=
userapp.py:

import mycrypt
...
=%=

I've missed out something, and then I didn't get exception,
instead there were a segfault. :(


I've put it a Py_INCREF() after every PyModule_AddObject(), eg.:

PyModule_AddObject(o, "error", cibcrypt_error_nokey);
Py_INCREF(cibcrypt_error_nokey);

and now if there is some expected exception, I get it.


Any explanation?


Thanks:


a.


ps: this is just for my passion, but I would like to understand
it very-very much :)

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


Compile 32bit C-lib on 64 bit

2011-05-01 Thread Hegedüs Ervin
Hello,

this is not a "clear" Python question - I've wrote a module in C,
which uses a 3rd-party lib - it's a closed source, I just get the
.so, .a and a header file.

Looks like it works on 32bit (on my desktop), but it must be run
on 64bit servers.


When I'm compiling it on 64bit, gcc says:

/usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching 
for -l3rdpartyCrypt

There _is_ the .so in /lib32 directory:

ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV),
dynamically linked, stripped


What is the correct solution?


thank you:


a.

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


Re: Fibonacci series recursion error

2011-05-01 Thread Chris Angelico
On Sun, May 1, 2011 at 11:15 PM, Hans Georg Schaathun  
wrote:
> :  The Python virtual machine knows how big each entry on the stack needs to
> :  be. (I don't, but it's got to be at least the size of a pointer.) So
> :  "number of items" is just a multiplication away from "size of the items".
>
> Does it?  In a conventional stack you need to store all the local
> variables for the function as well.  Thus, there is no limit to how
> much space a single element on the stack may require.

In anything less than a useless and trivial demo of recursion, there's
going to be some kind of local state for each call (in the case of a
fibonacci or factorial, that would be the number(s) being multiplied).
Whether they go on the stack or elsewhere, that's additional storage
that gets multiplied out.

> There is also a limit to how far you can usefully recurse over a limited
> data structure.

Sure. Serialize this Python object in a way that can be given to, say, PHP:
foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo]
Recurse from self into the list, recurse from there into a
dictionary... Okay, that's a rather naive recursion and fraught with
risk, but there are more complex examples. And watching for cyclic
references would be O(N*N) as you'd need to maintain a full list of
every PyObject* that you've sighted (talking here from the C API, but
the same consideration applies whichever way you do it).

> There are many ways to crash a system if you want to.
>
> But if you don't deliberately try to crash it, you are much more
> likely to crash it because you allocate to much memory in each step
> than because the recursion gets to deep.  Consequently, because recursion
> is usually a clearer form of expression than iterative loops, recursion
> may actually be /less/ dangerous.

I'm not sure that recursion is clearer. Recursion is a way of
expressing the two rules:

1! = 1
n! = n * (n-1)!

But iteration is a way of expressing this equivalent rule:

n! = 1 * 2 * 3 * ... * n-1 * n

It really depends what you're trying to say.

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


Re: skipping one unittest assertion?

2011-05-01 Thread Chris Angelico
On Mon, May 2, 2011 at 4:16 AM, Roy Smith  wrote:
>>       Can't you just comment out that line?
>
> Sure, but the point of @skip and @expectFailure is that they leave a
> visible trail in the test output that you need to go back and fix
> something.

Comment it out and add a line of output manually?

Make everything as simple as possible (but no simpler).

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


PIL Question

2011-05-01 Thread PyNewbie
Hi,

I'm new with Python and PIL. I have a very simple question regarding an image 
capture function I'm attempting. 

Here is the code:


>>> from PIL import ImageGrab
>>> ImageGrab.grab().save("screen_capture.jpg", "JPEG")

Question: I can't seem to find the captured image, where does it go?  The 
python Shell IDE does not display an error, and the code appears to have been 
processed. 

Additional Info: I'm using Python 2.6, and PIL 1.1.7 for Python 2.6 Windows. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Development tools and practices for Pythonistas

2011-05-01 Thread Jason Earl
On Sun, May 01 2011, Dietmar Schwertberger wrote:

> Am 01.05.2011 02:47, schrieb Shawn Milochik:
>> Look at the big two sites for open-source repositories -- github and
>> bitbucket. One's git, the other Mercurial. I don't think you can go
>> wrong picking either one.
>
> Can any of those be used from Python as a library, i.e. something like
> import Hg
> r = Hg.open(path)
>
> When I had a look at Mercurial, which is implemented in Python, it was
> implemented in a way that I could not do that. It was implemented as
> rather monolithic program which could be used from os.system(...)
> only.
> 
> With a good API, I could easily have integrated it into my development
> flow. I have a codebase which is shared between different projects and
> there are many small changes on many different PCs.  In theory a
> distributed VCS is good at supporting that, but in practice I went
> back to my lightweight synchronization scripts and file storage
> again. With the API, I could have best of both worlds.

You should take a look at Bazaar.  I found it fairly easy to use bzrlib
from my own Python scripts.

http://people.canonical.com/~mwh/bzrlibapi/

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


Re: skipping one unittest assertion?

2011-05-01 Thread Ben Finney
Roy Smith  writes:

>  Ben Finney  wrote:
>
> > Each test case should be testing one thing: if it fails, it should be
> > for exactly one reason.
>
> Well, yeah, that's certainly the XP/unit-test doctrine. In practice
> however, tests often get written as "do a bunch of stuff to get some
> result, then make a bunch of assertions about that result".

And the result is an increasingly-difficult maintenance burden for the
test suite, as you've discovered.

> Sure, you could make each of those assertions a distinct method, and 
> factor the "do a bunch of stuff" into setUp().  Which probably means 
> factoring those methods out into a new TestCase subclass.  At some 
> point, however practicality trumps doctrine.

Yet practicality, i.e. making your test cases manageable, is exactly
what you don't have with your current approach. I'm not quoting doctrine
at you; I'm saying that *because of problems like you're encountering*,
you should refactor your test cases to do one test per case.

-- 
 \“Absurdity, n. A statement or belief manifestly inconsistent |
  `\with one's own opinion.” —Ambrose Bierce, _The Devil's |
_o__)Dictionary_, 1906 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Development tools and practices for Pythonistas

2011-05-01 Thread Ben Finney
Dietmar Schwertberger  writes:

> Am 01.05.2011 02:47, schrieb Shawn Milochik:
> > Look at the big two sites for open-source repositories -- github and
> > bitbucket.

Note that there are three: Launchpad (backed by Bazaar) is the other
“big site” for free-software project hosting.

> Can any of those be used from Python as a library, i.e. something like
> import Hg
> r = Hg.open(path)

I haven't used it, but Launchpad (the Canonical project hosting which
uses Bazaar for the VCS) is of course well-supported in the Bazaar
libraries. Access to the hosting site is eminently programmable with a
good API, by all accounts.

-- 
 \“It is seldom that liberty of any kind is lost all at once.” |
  `\   —David Hume |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fibonacci series recursion error

2011-05-01 Thread Terry Reedy

On 5/1/2011 5:27 AM, Hans Georg Schaathun wrote:


Of course you do, but you are still only saying that there might be
an application where this might happen because of excessive although
logically correct recursion.  You have not given a single example where
it actually happened.


I will. Stack overflow *can* happen with a bad base case. It *will* 
happen with correct linear recursion* applied to a large enough 
collection on a finite-memory machine (as opposed to an 'infinite' 
memory Turing machine).


def count_popable_collection(pop_col):
try:
pop_col.pop()
return count_popable_collection(pop_col) + 1
except (KeyError,IndexError):
return 0

print(count_popable_collection({1,2,3}))
print(count_popable_collection([1,2,3]))

Both calls correctly print 3, but will fail for large enough sets or 
lists. I call the above body recursion*. A tail-recursive version


def count_popable_collection2(pop_col, cnt=0):
try:
pop_col.pop()
return count_popable_collection2(pop_col, cnt + 1)
except (KeyError,IndexError):
return cnt

print(count_popable_collection2({1,2,3}))
print(count_popable_collection2([1,2,3]))

is less clear to most people, I think, and, executed as written, fails 
at the same point with the same memory error. Try either of the above 
with list(range(bignum)) (I am using 3.2).


This does not make linear recursion 'bad', just impractical for general 
use on finite-memory machines. While I consider it very useful for 
learning, it is unnecessary because it is easy to write an iterative 
version. So called tail-recursion optimization saves memory by REMOVING 
RECURSION and replacing it with iteration.


def count_popable_collection3(pop_col):
  cnt = 0
  while True:
try:
pop_col.pop()
cnt += 1
except (KeyError,IndexError):
return cnt

print(count_popable_collection3({1,2,3}))
print(count_popable_collection3([1,2,3]))

Python does not do this automatically because 1) it can be a semantic 
change under some circumstances; 2) one who wants the iterative version 
can just as easily write it directly; and 3) Python has a better way to 
process collections that removes essentially all the boilerplate in the 
recursive-call and while-loop versions:


def count_popable_collection4(pop_col):
cnt = 0
for item in pop_col:
cnt += 1
return cnt

print(count_popable_collection4({1,2,3}))
print(count_popable_collection4([1,2,3]))


Binary recursion* is a different case because the exponential growth in 
leaf number and hence time limits the useful depth of recursion to well 
below the default of 1000.


* linear recursion: usually and at most one recursive call per call
* binary recursion: usually and at most two recursive calls per call
  Fib is the best known example.
* tail recursion: base cases return completed calculations
* body recursion: base cases return starting values, often constants

--

Terry Jan Reedy

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


Re: Python competitions and learnings

2011-05-01 Thread Terry Reedy

On 5/1/2011 12:49 PM, Alexander Lyabah wrote:

And what do you think about Score Games and competitions?


The rules of the first score game were not clear to me. I could not 
figure out how to play it interactively myself so I could see how it 
actually played.


--
Terry Jan Reedy

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


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

2011-05-01 Thread Gregory Ewing

Steven D'Aprano wrote:

Python uses a data model of "name binding" and "call by object" (also 
known as "call by sharing").


It can be summed up in a less jargony way by saying that all
data is stored in heap-allocated objects, and variables refer
to objects rather than containing them directly. Everything
else follows from that.

What other languages use the same, or mostly similar, data model as 
Python?


Pretty much any dynamically-typed language: Lisp, Scheme,
Smalltalk, Snobol, Icon, Postscript, Ruby, Lua, ...

Some languages have it for some data types but not others.
Java, VB, Objective-C come to mind.

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


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

2011-05-01 Thread Gregory Ewing

Terry Reedy wrote:

While Guido does not, that I know of, credit CLU as Python's direct 
inspiration, I think it (and Barbara Liskov) as the originator of 
Python's data model. I believe she thought of the call-by-object 
semantics as something of an innovation.


I don't think she can claim credit for that, seeing as as Lisp
was built around it. She may have invented the *term* "call by
object" (unnecessarily, in my opinion) but the idea wasn't new.

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


Re: Py_INCREF() incomprehension

2011-05-01 Thread Gregory Ewing

Hegedüs Ervin wrote:


I've put it a Py_INCREF() after every PyModule_AddObject(), eg.:

PyModule_AddObject(o, "error", cibcrypt_error_nokey);
Py_INCREF(cibcrypt_error_nokey);


That looks correct, because PyModule_AddObject is documented as
stealing a reference to the object.

By the way, it probably doesn't make a difference here, but
it's better style to do the Py_INCREF *before* calling
a function that steals a reference, to be sure that the
object can't get spuriously deallocated.

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


Re: Fibonacci series recursion error

2011-05-01 Thread BartC

"Steven D'Aprano"  wrote in message
news:4dbbb7b6$0$29991$c3e8da3$54964...@news.astraweb.com...

On Sat, 30 Apr 2011 08:32:55 +0200, Peter Otten wrote:


harrismh777 wrote:


Ian Kelly wrote:

since the fact is that if
the function were properly coded, the call stack for fib(20) would
never be more than 20 entries deep at any one time.



Not so much... and much more !


...  because each recursion level 'return' calls fib() twice, and each
of those calls fib() twice, and you get the point...


I don't understand what you are trying to say -- but it's wrong ;)



I don't know what M Harris thinks he is trying to say either, but the
*naive* Fibonacci recursive algorithm is particularly badly performing
and should be avoided. It's ironic that of the two classic algorithms
used for teaching beginner programmers about recursion, neither is useful
in practice.


Yes, it generates lots of calls.

About 22000 for fib(20), and 330 million for fib(40).

That's why it's popular for benchmarks that measure performance of function
calls. Using an iterative algorithm wouldn't work quite so well...

--
Bartc 


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


Re: Development tools and practices for Pythonistas

2011-05-01 Thread David Boddie
On Sunday 01 May 2011 18:11, Dietmar Schwertberger wrote:

> Am 01.05.2011 02:47, schrieb Shawn Milochik:
>> Look at the big two sites for open-source repositories -- github and
>> bitbucket. One's git, the other Mercurial. I don't think you can go
>> wrong picking either one.
> 
> Can any of those be used from Python as a library, i.e. something like
> import Hg
> r = Hg.open(path)
> 
> When I had a look at Mercurial, which is implemented in Python,
> it was implemented in a way that I could not do that. It was implemented
> as rather monolithic program which could be used from os.system(...)
> only.

After noting the warnings it contains, see the following page for a
description of the Python API for Mercurial:

  http://mercurial.selenic.com/wiki/MercurialApi

Git also has a Python API, which is fairly reasonable to use, though a bit
different to the Mercurial one:

  http://www.samba.org/~jelmer/dulwich/

I've used both with some success.

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


Re: PIL Question

2011-05-01 Thread Chris Rebert
On Sun, May 1, 2011 at 1:50 PM, PyNewbie  wrote:
> Hi,
>
> I'm new with Python and PIL. I have a very simple question regarding an image 
> capture function I'm attempting.
>
> Here is the code:
>
>
 from PIL import ImageGrab
 ImageGrab.grab().save("screen_capture.jpg", "JPEG")
>
> Question: I can't seem to find the captured image, where does it go?  The 
> python Shell IDE does not display an error, and the code appears to have been 
> processed.
>
> Additional Info: I'm using Python 2.6, and PIL 1.1.7 for Python 2.6 Windows.

I would think to a file named "screen_capture.jpg" in the current
working directory. What that is for IDLE, I don't know. You can
determine what folder that is by running this in your Python shell:

from os import getcwd
print(getcwd())

Also, I would suggest using absolute file paths in the future, rather
than relative ones; e.g. "C:/Documents and Settings/Your
username/Desktop/screen_capture.jpg" rather than just
"screen_capture.jpg".

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


Re: Py_INCREF() incomprehension

2011-05-01 Thread Thomas Rachel

Am 01.05.2011 22:00, schrieb Hegedüs Ervin:


My module contains just 4 functions (in C), which translate 3rd
party lib to Python. The name would be _mycrypt.so example.

I wrapped it a pure Python module, its name is mycrypt.py.

Then, I've import pure Python module in a main program, like
this:

=%=
mycrypt.py:

import _mycrypt
...
=%=

=%=
userapp.py:

import mycrypt
...
=%=


AFAICS, it looks ok.



I've missed out something, and then I didn't get exception,
instead there were a segfault. :(


I guess this is the point where yo should start printf programing.

* What happens during module initialization?
* What happens n the functions?
* Where does the stuff fail?
* What are the reference counts of the involved objects?

etc.



I've put it a Py_INCREF() after every PyModule_AddObject(), eg.:

 PyModule_AddObject(o, "error", cibcrypt_error_nokey);
 Py_INCREF(cibcrypt_error_nokey);

and now if there is some expected exception, I get it.



Any explanation?


I don't have one - I would think that if the module object exists for 
all the time, it would be enough to have one reference there.


But obviously it is not enough - did you at any time del something 
related to here? The module or one of its attributes?


Anyway, it seems safer to do INCREF here - so do it. (As Gregory already 
stated - it looks cleaner if you do INCREF before AddObject.)




ps: this is just for my passion, but I would like to understand
it very-very much :)


Understandable. That's that the printf debugging of the refcounts can be 
good for - even if you don't really have a problem.



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


Re: Fibonacci series recursion error

2011-05-01 Thread Steven D'Aprano
On Sun, 01 May 2011 14:15:35 +0100, Hans Georg Schaathun wrote:

> On 01 May 2011 11:56:57 GMT, Steven D'Aprano
>wrote:
> :  Just google on "stack overflow crash".
> 
> And I get loads of examples of stack overflows, but I could not see
> anybody linking this to logically correct recursion.  Wikipedia, for
> instance, mentions two common causes, neither of which has anything to
> do with logically correct recursion.

Ah, I see where you're coming from now! You think I'm arguing *against* 
the use of recursion. Not at all. Earlier in this thread, I said:

"Consequently, the naive recursive function is ridiculously slow and 
memory-hungry.

This seems to have give rise to a myth that recursion should be avoided. 
What needs to be avoided is *badly thought out* recursion."

[Emphasis in original.]




> :  The Python virtual machine knows how big each entry on the stack
> needs to :  be. (I don't, but it's got to be at least the size of a
> pointer.) So :  "number of items" is just a multiplication away from
> "size of the items".
> 
> Does it?  In a conventional stack you need to store all the local
> variables for the function as well.  Thus, there is no limit to how much
> space a single element on the stack may require.

To be honest, I don't know what Python does with local variables. But I 
*guess* it uses a constant-sized record which points to the locals, 
because that's how I'd do it :)

I do know that objects in CPython all live in the heap, not on the stack, 
so even if local variables are placed directly on the stack, that's only 
a pointer to the object, not the entire object.


[...]
> But all of this is in principle, and does not constitute any valid
> reason to avoid recursion in practice.  If you want to argue that
> recursion is a bad thing in /practice/ you need a /practical/ argument.

Okay. In *practice*, all else being equal, recursion is less efficient 
than iteration, especially in Python which doesn't optimize tail-
recursion. So if you have a choice between two algorithms which are 
equally simple and clear, and one is recursive and the other uses 
iteration, the one with iteration will be more efficient.

However, and equally in practice, it's unusual to have two equally simple 
algorithms. Usually one or the other will be much simpler than the other, 
and you should avoid "optimizing" code based on hypothetical 
considerations and instead prefer simple code over complicated, unless 
absolutely necessary.

Given a choice between a complicated iterative algorithm and a simple 
recursive version, there's no prima facie reason to expect the recursive 
version to *necessarily* be slower than iteration in Python *merely* 
because it uses recursion. As always, if speed is an issue, profile and 
identify the bottlenecks before deciding how to fix them.



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


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

2011-05-01 Thread Terry Reedy

On 5/1/2011 6:33 PM, Gregory Ewing wrote:

Steven D'Aprano wrote:


Python uses a data model of "name binding" and "call by object" (also
known as "call by sharing").


It can be summed up in a less jargony way by saying that all
data is stored in heap-allocated objects,


This is incomprehensible jargon to some; is only (partly) true of 
(typical) machine-implementations; and seems not to be true of all 
objects. I believe that for CPython, builtin objects, including the 
fixed arrray of ints from -5 to 256, are allocated in another data 
segment (more CS jargon, which is irrelavant to human interpreters).


Evidence 1:
>>> id(int)
505285072
>>> id(str)
505233232
>>> id(1)
505493792
>>> id(-5)
505493696

This appears to be initialized data segment. (Someone else could take a 
white box approach and look at the source. ;-)


>>> id(33)
16512288
>>> id('a')
11227616

This is heap.

Evidence 2:
Some error messages use 'heap type' to mean 'Python-coded class'

>>> 1 .__class__ = str
Traceback (most recent call last):
  File "", line 1, in 
1 .__class__ = str
TypeError: __class__ assignment: only for heap types

http://bugs.python.org/issue4600

> and variables refer  to objects rather than containing them directly.
> Everything else follows from that.

Would you say 'names refer to objects rather than containing them 
directly'? Surely not. Using 'name' rather than the hugely overloaded 
tern 'variable' automatically avoids certain misunderstandings.


A good summary might be "Python manipulates objects that are accessed 
through literals, names, and expressions."

--
Terry Jan Reedy

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


Re: Compile 32bit C-lib on 64 bit

2011-05-01 Thread Benjamin Kaplan
On Sun, May 1, 2011 at 4:14 PM, Hegedüs Ervin  wrote:
> Hello,
>
> this is not a "clear" Python question - I've wrote a module in C,
> which uses a 3rd-party lib - it's a closed source, I just get the
> .so, .a and a header file.
>
> Looks like it works on 32bit (on my desktop), but it must be run
> on 64bit servers.
>
>
> When I'm compiling it on 64bit, gcc says:
>
> /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when searching 
> for -l3rdpartyCrypt
>
> There _is_ the .so in /lib32 directory:
>
> ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV),
> dynamically linked, stripped
>
>
> What is the correct solution?
>
>
> thank you:
>
>
> a.


You cannot link a 64-bit binary against a 32- bit library. It just
won't work. If you can't get a 64-bit copy of that library, you'll
have to compile everything (including Python and all its dependencies)
as 32-bit.

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


Re: Compile 32bit C-lib on 64 bit

2011-05-01 Thread Nobody
On Sun, 01 May 2011 22:14:14 +0200, Hegedüs Ervin wrote:

> When I'm compiling it on 64bit, gcc says:
> 
> /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when
> searching for -l3rdpartyCrypt
> 
> There _is_ the .so in /lib32 directory:
> 
> ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically
> linked, stripped
> 
> 
> What is the correct solution?

You need to build your module for a 32-bit version of Python.

On a 64-bit system, each process is either 32-bit or 64-bit process. You
can't mix 32-bit code and 64-bit code in a single process. If you have to
use that library and you only have a 32-bit version of it, then everything
else must also be 32-bit: the Python interpreter, your binary module, and
all of the libraries which it uses.

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


Re: Fibonacci series recursion error

2011-05-01 Thread Terry Reedy

On 5/1/2011 7:16 PM, BartC wrote:


Yes, it generates lots of calls.

About 22000 for fib(20), and 330 million for fib(40).


Using the standard double recursion implementation of fib, ncf(n) 
(number of calls to fib() for fib(n)) requires ncf(n-2) + ncf(n+1) + 1 
calls. The +1 is for the call to fib(n) itself). So it grows a bit 
faster than fib(n).


Fib(n) is actually calculated as the sum of fib(n) 1s: 1+1+1+1 
fib(n) times as 1 is the only non-0 base case and there is nothing else 
added or multiplied in non-base cases. To put it another way, there are 
fib(n) leaf nodes labeled 1 in the unbalanced tree generated by the 
recursion.


--
Terry Jan Reedy

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


Re: Development tools and practices for Pythonistas

2011-05-01 Thread Paul Rubin
>> > Look at the big two sites for open-source repositories -- github and
>> > bitbucket.
> Note that there are three: Launchpad (backed by Bazaar) is the other
> “big site” for free-software project hosting.

There is also patch-tag.com (using darcs) though it is smaller.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL Question

2011-05-01 Thread Terry Reedy

On 5/1/2011 9:00 PM, Chris Rebert wrote:


I would think to a file named "screen_capture.jpg" in the current
working directory. What that is for IDLE, I don't know.


At least on windows with 3.2, if one just starts up the shell, it is in 
the Pythonxy directory. If one runs a file from an edit window, it 
changes to the directory of the file, so it operates much as if one had 
run with the command python -i file.py in the directory of file.py.



You can
determine what folder that is by running this in your Python shell:

from os import getcwd; print(getcwd())


Yes, this gives two different answers in the two cases noted above.

--
Terry Jan Reedy

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


Re: Development tools and practices for Pythonistas

2011-05-01 Thread rusi
On Apr 30, 8:21 am, CM  wrote:
> > A lone developer using such a VCS reaps the benefits of this by getting
> > good merging support.
>
> While we're on the topic, when should a lone developer bother to start
> using a VCS?  At what point in the complexity of a project (say a hobby
> project, but > a somewhat seriousish one, around ~5-9k LOC) is the added
> complexity of bringing a VCS into it worth it?

When you hit your first bug?
Ok seriously, when you hit your first serious bug maybe?

I am a bit surprised that no one has mentioned rcs so far
Not an option if you are not on a *ix system and not something I am
specifically recommending.
[I grew up on rcs 15 years ago but not used it much of late]
You may want to look at rcs if you are in the space where you want:
-- something better than tarballs
-- no pretensions beyond single-user, single-machine, (almost)single-
file usage (ie small scale)
-- something that integrates nicely with emacs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Development tools and practices for Pythonistas

2011-05-01 Thread Ben Finney
rusi  writes:

> You may want to look at rcs if you are in the space where you want:
> -- something better than tarballs
> -- no pretensions beyond single-user, single-machine, (almost)single-
> file usage (ie small scale)
> -- something that integrates nicely with emacs

I might have agreed ten years ago; compared to CVS or Subversion, RCS is
simpler to use and set up and had lower workflow overhead.

But today, Bazaar or Mercurial fill that role just as well: quick simple
set up, good tool support (yes, even in Emacs using VC mode), and easy
to use for easy things.

I really don't see any benefit to using RCS for even a lone hacker
tracking files; Bazaar or Mercurial fill that role just as well, and
continue to work well as your needs grow.

-- 
 \   “Philosophy is questions that may never be answered. Religion |
  `\  is answers that may never be questioned.” —anonymous |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Development tools and practices for Pythonistas

2011-05-01 Thread rusi
On May 2, 8:22 am, Ben Finney  wrote:
> rusi  writes:
> > You may want to look at rcs if you are in the space where you want:
> > -- something better than tarballs
> > -- no pretensions beyond single-user, single-machine, (almost)single-
> > file usage (ie small scale)
> > -- something that integrates nicely with emacs
>
> I might have agreed ten years ago; compared to CVS or Subversion, RCS is
> simpler to use and set up and had lower workflow overhead.
>
> But today, Bazaar or Mercurial fill that role just as well: quick simple
> set up, good tool support (yes, even in Emacs using VC mode), and easy
> to use for easy things.
>
> I really don't see any benefit to using RCS for even a lone hacker
> tracking files; Bazaar or Mercurial fill that role just as well, and
> continue to work well as your needs grow.

In a word: single files.
If you have a directory with a number of short unrelated scripts --
python, shell etc --
the philosophy: vcs-manages-projects-not-files is a nuisance not a
help.

And which is why things like zit http://git.oblomov.eu/zit have
arisen: the need to go back from bzr/git/hg to (something like) rcs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile 32bit C-lib on 64 bit

2011-05-01 Thread Dan Stromberg
On Sun, May 1, 2011 at 1:14 PM, Hegedüs Ervin  wrote:

> Hello,
>
> this is not a "clear" Python question - I've wrote a module in C,
> which uses a 3rd-party lib - it's a closed source, I just get the
> .so, .a and a header file.
>
> Looks like it works on 32bit (on my desktop), but it must be run
> on 64bit servers.
>
>
> When I'm compiling it on 64bit, gcc says:
>
> /usr/bin/ld: skipping incompatible /lib32/lib3rdpartyCrypt.so when
> searching for -l3rdpartyCrypt
>
> There _is_ the .so in /lib32 directory:
>
> ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV),
> dynamically linked, stripped
>
>
> What is the correct solution?
>

The best solution is to not use a closed source, binary-only, single-sourced
(?) security library, especially if it has not been vetted by others from
outside the organization from which it was obtained.  It costs quite a bit
for a company to get such software under enough eyeballs to make it mostly
trustworthy, and it puts you at their mercy with regard to an upgrade path.
The best security-related algorithms are published and studied by many
researchers, and will have multiple interoperating implementations.

Rebuilding everything as 32 bit on your 64 bit system (if it's one of those
64 bit systems that can also conveniently run 32 bit binaries - most, but
not all, can) may be one of your better options.  This of course carries a
memory penalty, as you may end up with two copies of your python interpreter
and relevant .so's in virtual memory, and hence experience a greater
tendency to page.

There is no theoretical reason why you cannot use a 32 bit library in a 64
bit application, however it is unlikely to be simple.  You could experiment
with accessing your 32 bit library via ctypes from a 64 bit interpreter and
carefully converting pointers and integers to/from 32 bit and 64 bit (with a
significant decrease in usable address space, and the possibility of 64 bit
addresses that simply aren't convertible, especially, but not necessarily
only, once your process gets large), if you find a way of setting up an
appropriate 32 bit stack.  You could also emulate a 32 bit CPU in your 64
bit process - this too, is perhaps mostly theoretical - see qemu for an
example of something that can, EG, run x86 binaries on a sparc CPU.  In
short: "You probably could, but it might well be more trouble than it's
worth".

Another option would be to link your library into a small, 32 bit C program,
and then establish some sort of protocol for it to communicate with your 64
bit python interpreter - via a pipe or socket, as examples.  Without
adequate vendor cooperation, and if you're truly locked in, this may
actually be one of your better options for the medium term.

Ultimately though, using something like KeyCzar or OpenSSL is probably your
best bet.  They've been scrutinized copiously, and have very low snake oil
factors.  That is, assuming KeyCzar or OpenSSL and your binary-only library
have overlapping purposes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile 32bit C-lib on 64 bit

2011-05-01 Thread Chris Angelico
On Mon, May 2, 2011 at 2:34 PM, Dan Stromberg  wrote:
> Another option would be to link your library into a small, 32 bit C program,
> and then establish some sort of protocol for it to communicate with your 64
> bit python interpreter - via a pipe or socket, as examples.

This is what I would recommend. A Unix socket or pipe or other pure
memory IPC mechanism can give some pretty high bandwidth, and it keeps
two processes happily isolated, plus it lets the OS handle any
conversions necessary (as opposed to your glue code, which is what
would happen if you link the 32-bit library to  your 64-bit app). Let
the operating system do my work for me? Don't mind if I do...

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


Re: Fibonacci series recursion error

2011-05-01 Thread Hans Georg Schaathun
On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico
   wrote:
:  Sure. Serialize this Python object in a way that can be given to, say, PHP:
:  foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo]
:  Recurse from self into the list, recurse from there into a
:  dictionary... Okay, that's a rather naive recursion and fraught with
:  risk, but there are more complex examples. And watching for cyclic
:  references would be O(N*N) as you'd need to maintain a full list of
:  every PyObject* that you've sighted (talking here from the C API, but
:  the same consideration applies whichever way you do it).

Wouldn't cyclic references give infinite recursion?  And remain
infinitive if you recode it iteratively?

:  I'm not sure that recursion is clearer. Recursion is a way of
:  expressing the two rules:
: 
:  1! = 1
:  n! = n * (n-1)!
: 
:  But iteration is a way of expressing this equivalent rule:
: 
:  n! = 1 * 2 * 3 * ... * n-1 * n
: 
:  It really depends what you're trying to say.

True.  There is a place for everything.  However, in the example
above, you can map the recursive definition directly into python
without further ado.  In order to express the one-liner in python,
as iteration, you need to introduce additional elements, namely
a state (index variable).  Hence, recursion is clearer by being
close to the language you would normally use to describe the
problem.

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


Re: Fibonacci series recursion error

2011-05-01 Thread Chris Angelico
On Mon, May 2, 2011 at 3:36 PM, Hans Georg Schaathun  wrote:
> On Mon, 2 May 2011 06:49:41 +1000, Chris Angelico
>   wrote:
> :  Sure. Serialize this Python object in a way that can be given to, say, PHP:
> :  foo={"asdf":"qwer","zxcv":"1234"}; foo["self"]=[1,2,3,foo]
>
> Wouldn't cyclic references give infinite recursion?  And remain
> infinitive if you recode it iteratively?

Well, I don't know of a decent non-recursive way to process a
recursive structure. Incidentally, this example is almost directly
from some working code of ours; I have a C function that recurses over
a Python dictionary and aborts as soon as it's found "too much" data
(for a fairly arbitrary definition of "too much", but one that's
deliberately designed to prevent infinite recursion). Since every
element in the dictionary can be a list/dict, and every element of
those can be too, there's no non-recursive way to do it, other than by
doing the recursion yourself:

# partly pseudocode
searchme=[foo]
while len(searchme):
  cur=get_next_elem(searchme[-1])
  if cur==end_of_list: searchme[-1:]=[]
  else: if can_be_recursed_into(cur): searchme.append(cur)
  else: output(cur)

This would work, more or less, but it merely trades "true" recursion
for the searchme[] stack. Yes, it's iterative. No, it hasn't abolished
recursion.

> True.  There is a place for everything.  However, in the example
> above, you can map the recursive definition directly into python
> without further ado.  In order to express the one-liner in python,
> as iteration, you need to introduce additional elements, namely
> a state (index variable).  Hence, recursion is clearer by being
> close to the language you would normally use to describe the
> problem.

True, and you could abolish a lot of temporary variables by turning
them into parameters to recursive calls. But you've abolished nothing.

The recursive factorial is very similar to:
reduce(`*,range(1,n+1))
The iterative is very similar to:
reduce(`*,xrange(1,n+1))
One of 'em stacks up all the numbers and the other gets 'em as it
needs 'em. Fundamentally, there's really not a lot of difference. By
piling up the numbers on your stack, you just change the format of
your saved state, you don't actually save anything.

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


Re: Fibonacci series recursion error

2011-05-01 Thread Chris Angelico
On Mon, May 2, 2011 at 4:28 PM, Chris Angelico  wrote:
> reduce(`*,range(1,n+1))
> reduce(`*,xrange(1,n+1))

Whoops, forgot which language I was using. Back-tick functions not
being available, these need to be:

reduce(operator.mul,range(1,n+1))
reduce(operator.mul,xrange(1,n+1))

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


Re: Py_INCREF() incomprehension

2011-05-01 Thread Hegedüs , Ervin
hello,

Thomas, Gregory,

thank you for your ansrwers,

> I guess this is the point where yo should start printf programing.


oh', already done :)
 
> * What happens during module initialization?
successfully initialized,

> * What happens n the functions?
> * Where does the stuff fail?
> * What are the reference counts of the involved objects?

sorry for the dumb question: how can I controll number of
reference in C?
 
> > PyModule_AddObject(o, "error", cibcrypt_error_nokey);
> > Py_INCREF(cibcrypt_error_nokey);
> >
> >and now if there is some expected exception, I get it.
> 
> >Any explanation?
> 
> I don't have one - I would think that if the module object exists
> for all the time, it would be enough to have one reference there.
> 
> But obviously it is not enough - did you at any time del something
> related to here? The module or one of its attributes?
> 
> Anyway, it seems safer to do INCREF here - so do it. (As Gregory
> already stated - it looks cleaner if you do INCREF before
> AddObject.)

ok,
 
> 
> >ps: this is just for my passion, but I would like to understand
> >it very-very much :)
> 
> Understandable. That's that the printf debugging of the refcounts
> can be good for - even if you don't really have a problem.

thanks, I'll go to read the docs :)

bye:

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


Re: Compile 32bit C-lib on 64 bit

2011-05-01 Thread Hegedüs , Ervin
Hello,

thanks for all reply,

On Mon, May 02, 2011 at 03:20:40AM +0100, Nobody wrote:
> You need to build your module for a 32-bit version of Python.

ok, I believed it, I was hoping there is another solution,

> On a 64-bit system, each process is either 32-bit or 64-bit process. You
> can't mix 32-bit code and 64-bit code in a single process. If you have to
> use that library and you only have a 32-bit version of it, then everything
> else must also be 32-bit: the Python interpreter, your binary module, and
> all of the libraries which it uses.

ok, thank you,


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